From 1543e317f1da31b75942316931e8f491a8920811 Mon Sep 17 00:00:00 2001
From: hc <hc@nodka.com>
Date: Thu, 04 Jan 2024 10:08:02 +0000
Subject: [PATCH] disable FB

---
 kernel/drivers/media/platform/rockchip/isp/isp_params_v3x.c |  125 ++++++++++++++++++-----------------------
 1 files changed, 55 insertions(+), 70 deletions(-)

diff --git a/kernel/drivers/media/platform/rockchip/isp/isp_params_v3x.c b/kernel/drivers/media/platform/rockchip/isp/isp_params_v3x.c
index 87db6aa..0491cc9 100644
--- a/kernel/drivers/media/platform/rockchip/isp/isp_params_v3x.c
+++ b/kernel/drivers/media/platform/rockchip/isp/isp_params_v3x.c
@@ -591,7 +591,7 @@
 	struct isp3x_isp_params_cfg *params = params_vdev->isp3x_params;
 
 	isp_lsc_matrix_cfg_sram(params_vdev, &params->others.lsc_cfg, true, 0);
-	if (params_vdev->dev->hw_dev->is_unite) {
+	if (params_vdev->dev->hw_dev->unite) {
 		params++;
 		isp_lsc_matrix_cfg_sram(params_vdev, &params->others.lsc_cfg, true, 1);
 	}
@@ -1223,7 +1223,7 @@
 
 	block_hsize = arg->win.h_size / ae_wnd_num[wnd_num_idx];
 	value = block_hsize * ae_wnd_num[wnd_num_idx] + arg->win.h_offs;
-	if (ispdev->hw_dev->is_unite)
+	if (ispdev->hw_dev->unite)
 		width = width / 2 + RKMOUDLE_UNITE_EXTEND_PIXEL;
 	if (value + 1 > width)
 		block_hsize -= 1;
@@ -1291,6 +1291,12 @@
 	value &= ISP3X_RAWAE_BIG_EN;
 
 	wnd_num_idx = arg->wnd_num;
+	if (wnd_num_idx >= ARRAY_SIZE(ae_wnd_num)) {
+		wnd_num_idx = ARRAY_SIZE(ae_wnd_num) - 1;
+		dev_err(params_vdev->dev->dev,
+			"%s invalid wnd_num:%d, set to %d\n",
+			__func__, arg->wnd_num, wnd_num_idx);
+	}
 	value |= ISP3X_RAWAE_BIG_WND0_NUM(wnd_num_idx);
 
 	if (arg->subwin_en[0])
@@ -1310,7 +1316,7 @@
 
 	block_hsize = arg->win.h_size / ae_wnd_num[wnd_num_idx];
 	value = block_hsize * ae_wnd_num[wnd_num_idx] + arg->win.h_offs;
-	if (ispdev->hw_dev->is_unite)
+	if (ispdev->hw_dev->unite)
 		width = width / 2 + RKMOUDLE_UNITE_EXTEND_PIXEL;
 	if (value + 1 > width)
 		block_hsize -= 1;
@@ -1430,13 +1436,12 @@
 		return;
 
 	for (i = 0; i < ISP3X_RAWAWB_WEIGHT_NUM / 5; i++) {
-		isp3_param_write(params_vdev,
-				 (arg->sw_rawawb_wp_blk_wei_w[5 * i] & 0x3f) << 0 |
-				 (arg->sw_rawawb_wp_blk_wei_w[5 * i + 1] & 0x3f) << 6 |
-				 (arg->sw_rawawb_wp_blk_wei_w[5 * i + 2] & 0x3f) << 12 |
-				 (arg->sw_rawawb_wp_blk_wei_w[5 * i + 3] & 0x3f) << 18 |
-				 (arg->sw_rawawb_wp_blk_wei_w[5 * i + 4] & 0x3f) << 24,
-				 ISP3X_RAWAWB_WRAM_DATA_BASE, id);
+		val = (arg->sw_rawawb_wp_blk_wei_w[5 * i] & 0x3f) << 0 |
+		      (arg->sw_rawawb_wp_blk_wei_w[5 * i + 1] & 0x3f) << 6 |
+		      (arg->sw_rawawb_wp_blk_wei_w[5 * i + 2] & 0x3f) << 12 |
+		      (arg->sw_rawawb_wp_blk_wei_w[5 * i + 3] & 0x3f) << 18 |
+		      (arg->sw_rawawb_wp_blk_wei_w[5 * i + 4] & 0x3f) << 24;
+		isp3_param_write_direct(params_vdev, val, ISP3X_RAWAWB_WRAM_DATA_BASE, id);
 	}
 }
 
@@ -2288,10 +2293,9 @@
 
 	if (params_vdev->dev->hw_dev->is_single)
 		isp_rawawb_cfg_sram(params_vdev, arg, false, id);
-	else
-		memcpy(arg_rec->sw_rawawb_wp_blk_wei_w,
-		       arg->sw_rawawb_wp_blk_wei_w,
-		       ISP3X_RAWAWB_WEIGHT_NUM);
+	memcpy(arg_rec->sw_rawawb_wp_blk_wei_w,
+	       arg->sw_rawawb_wp_blk_wei_w,
+	       ISP3X_RAWAWB_WEIGHT_NUM);
 
 	/* avoid to override the old enable value */
 	value = isp3_param_read(params_vdev, ISP3X_RAWAWB_CTRL, id);
@@ -2426,6 +2430,12 @@
 		return;
 
 	wnd_num_idx = arg->wnd_num;
+	if (wnd_num_idx >= ARRAY_SIZE(hist_wnd_num)) {
+		wnd_num_idx = ARRAY_SIZE(hist_wnd_num) - 1;
+		dev_err(params_vdev->dev->dev,
+			"%s invalid wnd_num:%d, set to %d\n",
+			__func__, arg->wnd_num, wnd_num_idx);
+	}
 	memset(weight15x15, 0, sizeof(weight15x15));
 	for (i = 0; i < hist_wnd_num[wnd_num_idx]; i++) {
 		for (j = 0; j < hist_wnd_num[wnd_num_idx]; j++) {
@@ -2473,6 +2483,12 @@
 	}
 
 	wnd_num_idx = arg->wnd_num;
+	if (wnd_num_idx >= ARRAY_SIZE(hist_wnd_num)) {
+		wnd_num_idx = ARRAY_SIZE(hist_wnd_num) - 1;
+		dev_err(params_vdev->dev->dev,
+			"%s invalid wnd_num:%d, set to %d\n",
+			__func__, arg->wnd_num, wnd_num_idx);
+	}
 	/* avoid to override the old enable value */
 	hist_ctrl = isp3_param_read(params_vdev, addr + ISP3X_RAWHIST_BIG_CTRL, id);
 	hist_ctrl &= ISP3X_RAWHIST_EN;
@@ -2502,8 +2518,7 @@
 
 	if (dev->hw_dev->is_single)
 		isp_rawhstbig_cfg_sram(params_vdev, arg, blk_no, false, id);
-	else
-		*arg_rec = *arg;
+	*arg_rec = *arg;
 }
 
 static void
@@ -2887,7 +2902,7 @@
 	value = ISP_PACK_2SHORT(arg->sigma_lut[i * 2], 0);
 	isp3_param_write(params_vdev, value, ISP3X_DHAZ_GAIN_LUT0 + i * 4, id);
 
-	if (dev->hw_dev->is_unite &&
+	if (dev->hw_dev->unite &&
 	    dev->hw_dev->is_single &&
 	    ctrl & ISP3X_DHAZ_ENMUX)
 		ctrl |= ISP3X_SELF_FORCE_UPD;
@@ -4095,22 +4110,6 @@
 		ops->rawawb_enable(params_vdev, !!(module_ens & ISP3X_MODULE_RAWAWB), id);
 }
 
-static __maybe_unused
-void __isp_config_hdrshd(struct rkisp_isp_params_vdev *params_vdev)
-{
-	struct rkisp_isp_params_ops_v3x *ops =
-		(struct rkisp_isp_params_ops_v3x *)params_vdev->priv_ops;
-	struct rkisp_isp_params_val_v3x *priv_val =
-		(struct rkisp_isp_params_val_v3x *)params_vdev->priv_val;
-
-	if (params_vdev->dev->hw_dev->is_unite) {
-		ops->hdrmge_config(params_vdev, &priv_val->last_hdrmge, RKISP_PARAMS_SHD, 1);
-		ops->hdrdrc_config(params_vdev, &priv_val->last_hdrdrc, RKISP_PARAMS_SHD, 1);
-	}
-	ops->hdrmge_config(params_vdev, &priv_val->last_hdrmge, RKISP_PARAMS_SHD, 0);
-	ops->hdrdrc_config(params_vdev, &priv_val->last_hdrdrc, RKISP_PARAMS_SHD, 0);
-}
-
 static
 void rkisp_params_cfgsram_v3x(struct rkisp_isp_params_vdev *params_vdev)
 {
@@ -4121,7 +4120,7 @@
 	isp_rawhstbig_cfg_sram(params_vdev, &params->meas.rawhist2, 2, true, 0);
 	isp_rawhstbig_cfg_sram(params_vdev, &params->meas.rawhist3, 0, true, 0);
 	isp_rawawb_cfg_sram(params_vdev, &params->meas.rawawb, true, 0);
-	if (params_vdev->dev->hw_dev->is_unite) {
+	if (params_vdev->dev->hw_dev->unite) {
 		params++;
 		isp_lsc_matrix_cfg_sram(params_vdev, &params->others.lsc_cfg, true, 1);
 		isp_rawhstbig_cfg_sram(params_vdev, &params->meas.rawhist1, 1, true, 1);
@@ -4145,7 +4144,7 @@
 	module_en_update = new_params->module_en_update;
 	module_ens = new_params->module_ens;
 
-	for (id = 0; id <= ispdev->hw_dev->is_unite; id++) {
+	for (id = 0; id <= !!ispdev->hw_dev->unite; id++) {
 		priv_val->buf_3dlut_idx[id] = 0;
 		for (i = 0; i < ISP3X_3DLUT_BUF_NUM; i++) {
 			priv_val->buf_3dlut[id][i].is_need_vaddr = true;
@@ -4162,10 +4161,10 @@
 	    (module_ens & ISP3X_MODULE_BAY3D)) {
 		w = ALIGN(isp_sdev->in_crop.width, 16);
 		h = ALIGN(isp_sdev->in_crop.height, 16);
-		if (ispdev->hw_dev->is_unite)
+		if (ispdev->hw_dev->unite)
 			w = ALIGN(isp_sdev->in_crop.width / 2 + RKMOUDLE_UNITE_EXTEND_PIXEL, 16);
 
-		for (id = 0; id <= ispdev->hw_dev->is_unite; id++) {
+		for (id = 0; id <= !!ispdev->hw_dev->unite; id++) {
 			size = ALIGN((w + w / 8) * h * 2, 16);
 
 			priv_val->buf_3dnr_iir[id].size = size;
@@ -4201,7 +4200,7 @@
 		rkisp_free_buffer(ispdev, &priv_val->buf_3dnr_cur[id]);
 		rkisp_free_buffer(ispdev, &priv_val->buf_3dnr_ds[id]);
 	}
-	id = ispdev->hw_dev->is_unite ? 1 : 0;
+	id = ispdev->hw_dev->unite ? 1 : 0;
 	i = ISP3X_3DLUT_BUF_NUM;
 err_3dlut:
 	for (; id >= 0; id--) {
@@ -4256,7 +4255,7 @@
 				continue;
 			dev_warn(dev, "isp%d %dx%d over four vir isp max:%dx1536\n",
 				 i, hw->isp_size[i].w, hw->isp_size[i].h,
-				 hw->is_unite ? (2560 - RKMOUDLE_UNITE_EXTEND_PIXEL) * 2 : 2560);
+				 hw->unite ? (2560 - RKMOUDLE_UNITE_EXTEND_PIXEL) * 2 : 2560);
 			hw->is_multi_overflow = true;
 			goto multi_overflow;
 		}
@@ -4298,7 +4297,7 @@
 			    (hw->isp_size[idx1[0]].size > ISP3X_VIR2_MAX_SIZE)) {
 				dev_warn(dev, "isp%d %dx%d over three vir isp max:%dx1536\n",
 					 idx1[0], hw->isp_size[idx1[0]].w, hw->isp_size[idx1[0]].h,
-					 hw->is_unite ? (2560 - RKMOUDLE_UNITE_EXTEND_PIXEL) * 2 : 2560);
+					 hw->unite ? (2560 - RKMOUDLE_UNITE_EXTEND_PIXEL) * 2 : 2560);
 				hw->is_multi_overflow = true;
 				goto multi_overflow;
 			} else {
@@ -4357,7 +4356,7 @@
 			    hw->isp_size[idx1[k - 1]].size > (ISP3X_VIR4_MAX_SIZE + ISP3X_VIR2_MAX_SIZE)) {
 				dev_warn(dev, "isp%d %dx%d over two vir isp max:%dx2160\n",
 					 idx1[k - 1], hw->isp_size[idx1[k - 1]].w, hw->isp_size[idx1[k - 1]].h,
-					 hw->is_unite ? (3840 - RKMOUDLE_UNITE_EXTEND_PIXEL) * 2 : 3840);
+					 hw->unite ? (3840 - RKMOUDLE_UNITE_EXTEND_PIXEL) * 2 : 3840);
 				hw->is_multi_overflow = true;
 				goto multi_overflow;
 			} else {
@@ -4379,7 +4378,7 @@
 		ispdev->multi_mode = 0;
 		ispdev->multi_index = 0;
 		width = crop->width;
-		if (hw->is_unite)
+		if (hw->unite)
 			width = width / 2 + RKMOUDLE_UNITE_EXTEND_PIXEL;
 		height = crop->height;
 		size = width * height;
@@ -4416,7 +4415,7 @@
 	priv_val->lsc_en = 0;
 	priv_val->mge_en = 0;
 	priv_val->lut3d_en = 0;
-	if (hw->is_unite) {
+	if (hw->unite) {
 		if (dev->is_bigmode)
 			rkisp_next_set_bits(params_vdev->dev, ISP3X_ISP_CTRL1, 0,
 					    ISP3X_BIGMODE_MANUAL | ISP3X_BIGMODE_FORCE_EN, false);
@@ -4432,11 +4431,6 @@
 	__isp_isr_other_config(params_vdev, params_vdev->isp3x_params, RKISP_PARAMS_ALL, 0);
 	__isp_isr_other_en(params_vdev, params_vdev->isp3x_params, RKISP_PARAMS_ALL, 0);
 	__isp_isr_meas_en(params_vdev, params_vdev->isp3x_params, RKISP_PARAMS_ALL, 0);
-
-	priv_val->cur_hdrmge = params_vdev->isp3x_params->others.hdrmge_cfg;
-	priv_val->cur_hdrdrc = params_vdev->isp3x_params->others.drc_cfg;
-	priv_val->last_hdrmge = priv_val->cur_hdrmge;
-	priv_val->last_hdrdrc = priv_val->cur_hdrdrc;
 	spin_unlock(&params_vdev->config_lock);
 }
 
@@ -4452,7 +4446,7 @@
 
 static void rkisp_clear_first_param_v3x(struct rkisp_isp_params_vdev *params_vdev)
 {
-	u32 mult = params_vdev->dev->hw_dev->is_unite ? ISP3_UNITE_MAX : 1;
+	u32 mult = params_vdev->dev->hw_dev->unite ? ISP3_UNITE_MAX : 1;
 	u32 size = sizeof(struct isp3x_isp_params_cfg) * mult;
 
 	memset(params_vdev->isp3x_params, 0, size);
@@ -4551,7 +4545,7 @@
 rkisp_get_param_size_v3x(struct rkisp_isp_params_vdev *params_vdev,
 			 unsigned int sizes[])
 {
-	u32 mult = params_vdev->dev->hw_dev->is_unite ? ISP3_UNITE_MAX : 1;
+	u32 mult = params_vdev->dev->hw_dev->unite ? ISP3_UNITE_MAX : 1;
 
 	sizes[0] = sizeof(struct isp3x_isp_params_cfg) * mult;
 }
@@ -4596,7 +4590,7 @@
 {
 	struct rkisp_meshbuf_size *meshsize = size;
 
-	if (!params_vdev->dev->hw_dev->is_unite)
+	if (!params_vdev->dev->hw_dev->unite)
 		meshsize->unite_isp_id = 0;
 	rkisp_deinit_mesh_buf(params_vdev, meshsize->module_id, meshsize->unite_isp_id);
 	return rkisp_init_mesh_buf(params_vdev, meshsize);
@@ -4608,7 +4602,7 @@
 {
 	int id;
 
-	for (id = 0; id <= params_vdev->dev->hw_dev->is_unite; id++)
+	for (id = 0; id <= !!params_vdev->dev->hw_dev->unite; id++)
 		rkisp_deinit_mesh_buf(params_vdev, module_id, id);
 }
 
@@ -4621,7 +4615,7 @@
 
 	priv_val = (struct rkisp_isp_params_val_v3x *)params_vdev->priv_val;
 	tasklet_disable(&priv_val->lsc_tasklet);
-	for (id = 0; id <= ispdev->hw_dev->is_unite; id++) {
+	for (id = 0; id <= !!ispdev->hw_dev->unite; id++) {
 		rkisp_free_buffer(ispdev, &priv_val->buf_3dnr_iir[id]);
 		rkisp_free_buffer(ispdev, &priv_val->buf_3dnr_cur[id]);
 		rkisp_free_buffer(ispdev, &priv_val->buf_3dnr_ds[id]);
@@ -4637,7 +4631,7 @@
 {
 	int id;
 
-	for (id = 0; id <= params_vdev->dev->hw_dev->is_unite; id++) {
+	for (id = 0; id <= !!params_vdev->dev->hw_dev->unite; id++) {
 		rkisp_deinit_mesh_buf(params_vdev, ISP3X_MODULE_LDCH, id);
 		rkisp_deinit_mesh_buf(params_vdev, ISP3X_MODULE_CAC, id);
 	}
@@ -4652,7 +4646,7 @@
 
 	__isp_isr_other_en(params_vdev, params_vdev->isp3x_params, RKISP_PARAMS_ALL, 0);
 	__isp_isr_meas_en(params_vdev, params_vdev->isp3x_params, RKISP_PARAMS_ALL, 0);
-	if (params_vdev->dev->hw_dev->is_unite) {
+	if (params_vdev->dev->hw_dev->unite) {
 		__isp_isr_other_en(params_vdev, params_vdev->isp3x_params, RKISP_PARAMS_ALL, 1);
 		__isp_isr_meas_en(params_vdev, params_vdev->isp3x_params, RKISP_PARAMS_ALL, 1);
 	}
@@ -4725,7 +4719,7 @@
 				__isp_isr_other_en(params_vdev, new_params, type, 0);
 				__isp_isr_meas_en(params_vdev, new_params, type, 0);
 				new_params->module_cfg_update = 0;
-				if (hw_dev->is_unite) {
+				if (hw_dev->unite) {
 					struct isp3x_isp_params_cfg *params = new_params + 1;
 
 					__isp_isr_meas_config(params_vdev, params, type, 1);
@@ -4738,7 +4732,7 @@
 			if (new_params->module_cfg_update &
 			    (ISP3X_MODULE_LDCH | ISP3X_MODULE_CAC)) {
 				module_data_abandon(params_vdev, new_params, 0);
-				if (hw_dev->is_unite)
+				if (hw_dev->unite)
 					module_data_abandon(params_vdev, new_params, 1);
 			}
 			vb2_buffer_done(&cur_buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
@@ -4756,7 +4750,7 @@
 		goto unlock;
 
 	new_params = (struct isp3x_isp_params_cfg *)(cur_buf->vaddr[0]);
-	if (hw_dev->is_unite) {
+	if (hw_dev->unite) {
 		__isp_isr_meas_config(params_vdev, new_params + 1, type, 1);
 		__isp_isr_other_config(params_vdev, new_params + 1, type, 1);
 		__isp_isr_other_en(params_vdev, new_params + 1, type, 1);
@@ -4766,19 +4760,10 @@
 	__isp_isr_other_config(params_vdev, new_params, type, 0);
 	__isp_isr_other_en(params_vdev, new_params, type, 0);
 	__isp_isr_meas_en(params_vdev, new_params, type, 0);
-	if (!hw_dev->is_single && type != RKISP_PARAMS_SHD)
-		__isp_config_hdrshd(params_vdev);
 
 	if (type != RKISP_PARAMS_IMD) {
-		struct rkisp_isp_params_val_v3x *priv_val =
-			(struct rkisp_isp_params_val_v3x *)params_vdev->priv_val;
-
-		priv_val->last_hdrmge = priv_val->cur_hdrmge;
-		priv_val->last_hdrdrc = priv_val->cur_hdrdrc;
-		priv_val->cur_hdrmge = new_params->others.hdrmge_cfg;
-		priv_val->cur_hdrdrc = new_params->others.drc_cfg;
 		new_params->module_cfg_update = 0;
-		if (hw_dev->is_unite)
+		if (hw_dev->unite)
 			(new_params++)->module_cfg_update = 0;
 		vb2_buffer_done(&cur_buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
 		cur_buf = NULL;
@@ -4812,7 +4797,7 @@
 	if (value & ISP3X_RAW3D_FST_FRAME)
 		rkisp_clear_bits(params_vdev->dev, ISP3X_ISP_CTRL1,
 				 ISP3X_RAW3D_FST_FRAME, false);
-	if (hw_dev->is_unite) {
+	if (hw_dev->unite) {
 		value = rkisp_next_read(dev, ISP3X_ISP_CTRL1, false);
 		if (value & ISP3X_YNR_FST_FRAME)
 			rkisp_next_clear_bits(params_vdev->dev, ISP3X_ISP_CTRL1,
@@ -4887,7 +4872,7 @@
 		return -ENOMEM;
 
 	size = sizeof(struct isp3x_isp_params_cfg);
-	if (ispdev->hw_dev->is_unite)
+	if (ispdev->hw_dev->unite)
 		size *= 2;
 	params_vdev->isp3x_params = vmalloc(size);
 	if (!params_vdev->isp3x_params) {

--
Gitblit v1.6.2