From d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d Mon Sep 17 00:00:00 2001
From: hc <hc@nodka.com>
Date: Mon, 11 Dec 2023 02:45:28 +0000
Subject: [PATCH] add boot partition  size

---
 kernel/drivers/media/i2c/lt7911d.c |  131 +++++++++++++++----------------------------
 1 files changed, 47 insertions(+), 84 deletions(-)

diff --git a/kernel/drivers/media/i2c/lt7911d.c b/kernel/drivers/media/i2c/lt7911d.c
index 30bf0b2..f8d3c5b 100644
--- a/kernel/drivers/media/i2c/lt7911d.c
+++ b/kernel/drivers/media/i2c/lt7911d.c
@@ -49,6 +49,12 @@
 #define LT7911D_LINK_FREQ	400000000
 #define LT7911D_PIXEL_RATE	400000000
 
+#ifdef LT7911D_OUT_RGB
+#define LT7911D_MEDIA_BUS_FMT		MEDIA_BUS_FMT_BGR888_1X24
+#else
+#define LT7911D_MEDIA_BUS_FMT		MEDIA_BUS_FMT_UYVY8_2X8
+#endif
+
 #define LT7911D_NAME			"LT7911D"
 
 static const s64 link_freq_menu_items[] = {
@@ -73,7 +79,6 @@
 	struct clk *xvclk;
 	struct gpio_desc *reset_gpio;
 	struct gpio_desc *plugin_det_gpio;
-	struct gpio_desc *hpd_ctl_gpio;
 	struct gpio_desc *power_gpio;
 	struct work_struct work_i2c_poll;
 	struct timer_list timer;
@@ -472,22 +477,6 @@
 	return 0;
 }
 
-static void lt7911d_config_hpd(struct v4l2_subdev *sd)
-{
-	struct lt7911d_state *lt7911d = to_state(sd);
-	bool plugin;
-
-	plugin = tx_5v_power_present(sd);
-	v4l2_dbg(2, debug, sd, "%s: plugin: %d\n", __func__, plugin);
-
-	if (plugin) {
-		gpiod_set_value(lt7911d->hpd_ctl_gpio, 1);
-	} else {
-		lt7911d->nosignal = true;
-		gpiod_set_value(lt7911d->hpd_ctl_gpio, 0);
-	}
-}
-
 static void lt7911d_delayed_work_enable_hotplug(struct work_struct *work)
 {
 	struct delayed_work *dwork = to_delayed_work(work);
@@ -495,7 +484,7 @@
 			struct lt7911d_state, delayed_work_enable_hotplug);
 	struct v4l2_subdev *sd = &lt7911d->sd;
 
-	lt7911d_config_hpd(sd);
+	v4l2_ctrl_s_ctrl(lt7911d->detect_tx_5v_ctrl, tx_5v_power_present(sd));
 }
 
 static void lt7911d_delayed_work_res_change(struct work_struct *work)
@@ -577,21 +566,6 @@
 		v4l2_subdev_notify_event(sd, &lt7911d_ev_fmt);
 }
 
-static int lt7911d_get_ctrl(struct v4l2_ctrl *ctrl)
-{
-	int ret = -1;
-	struct lt7911d_state *lt7911d = container_of(ctrl->handler,
-			struct lt7911d_state, hdl);
-	struct v4l2_subdev *sd = &(lt7911d->sd);
-
-	if (ctrl->id == V4L2_CID_DV_RX_POWER_PRESENT) {
-		ret = tx_5v_power_present(sd);
-		*ctrl->p_new.p_s32 = ret;
-	}
-
-	return ret;
-}
-
 static int lt7911d_isr(struct v4l2_subdev *sd, u32 status, bool *handled)
 {
 	struct lt7911d_state *lt7911d = to_state(sd);
@@ -615,12 +589,10 @@
 static irqreturn_t plugin_detect_irq_handler(int irq, void *dev_id)
 {
 	struct lt7911d_state *lt7911d = dev_id;
-	struct v4l2_subdev *sd = &lt7911d->sd;
 
 	/* control hpd output level after 25ms */
 	schedule_delayed_work(&lt7911d->delayed_work_enable_hotplug,
 			HZ / 40);
-	tx_5v_power_present(sd);
 
 	return IRQ_HANDLED;
 }
@@ -748,11 +720,11 @@
 }
 
 static int lt7911d_g_mbus_config(struct v4l2_subdev *sd,
-				struct v4l2_mbus_config *cfg)
+			unsigned int pad, struct v4l2_mbus_config *cfg)
 {
 	struct lt7911d_state *lt7911d = to_state(sd);
 
-	cfg->type = V4L2_MBUS_CSI2;
+	cfg->type = V4L2_MBUS_CSI2_DPHY;
 	cfg->flags = V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK |
 			V4L2_MBUS_CSI2_CHANNEL_0;
 
@@ -790,7 +762,7 @@
 {
 	switch (code->index) {
 	case 0:
-		code->code = MEDIA_BUS_FMT_UYVY8_2X8;
+		code->code = LT7911D_MEDIA_BUS_FMT;
 		break;
 
 	default:
@@ -807,7 +779,7 @@
 	if (fse->index >= ARRAY_SIZE(supported_modes))
 		return -EINVAL;
 
-	if (fse->code != MEDIA_BUS_FMT_UYVY8_2X8)
+	if (fse->code != LT7911D_MEDIA_BUS_FMT)
 		return -EINVAL;
 
 	fse->min_width  = supported_modes[fse->index].width;
@@ -848,8 +820,7 @@
 	if (fie->index >= ARRAY_SIZE(supported_modes))
 		return -EINVAL;
 
-	if (fie->code != MEDIA_BUS_FMT_UYVY8_2X8)
-		return -EINVAL;
+	fie->code = LT7911D_MEDIA_BUS_FMT;
 
 	fie->width = supported_modes[fie->index].width;
 	fie->height = supported_modes[fie->index].height;
@@ -902,7 +873,7 @@
 		return ret;
 
 	switch (code) {
-	case MEDIA_BUS_FMT_UYVY8_2X8:
+	case LT7911D_MEDIA_BUS_FMT:
 		break;
 
 	default:
@@ -951,6 +922,9 @@
 	case RKMODULE_GET_MODULE_INFO:
 		lt7911d_get_module_inf(lt7911d, (struct rkmodule_inf *)arg);
 		break;
+	case RKMODULE_GET_HDMI_MODE:
+		*(int *)arg = RKMODULE_HDMIIN_MODE;
+		break;
 	default:
 		ret = -ENOIOCTLCMD;
 		break;
@@ -966,6 +940,7 @@
 	void __user *up = compat_ptr(arg);
 	struct rkmodule_inf *inf;
 	long ret;
+	int *seq;
 
 	switch (cmd) {
 	case RKMODULE_GET_MODULE_INFO:
@@ -983,7 +958,21 @@
 		}
 		kfree(inf);
 		break;
+	case RKMODULE_GET_HDMI_MODE:
+		seq = kzalloc(sizeof(*seq), GFP_KERNEL);
+		if (!seq) {
+			ret = -ENOMEM;
+			return ret;
+		}
 
+		ret = lt7911d_ioctl(sd, cmd, seq);
+		if (!ret) {
+			ret = copy_to_user(up, seq, sizeof(*seq));
+			if (ret)
+				ret = -EFAULT;
+		}
+		kfree(seq);
+		break;
 	default:
 		ret = -ENOIOCTLCMD;
 		break;
@@ -992,10 +981,6 @@
 	return ret;
 }
 #endif
-
-static const struct v4l2_ctrl_ops lt7911d_ctrl_ops = {
-	.g_volatile_ctrl = lt7911d_get_ctrl,
-};
 
 static const struct v4l2_subdev_core_ops lt7911d_core_ops = {
 	.interrupt_service_routine = lt7911d_isr,
@@ -1012,7 +997,6 @@
 	.s_dv_timings = lt7911d_s_dv_timings,
 	.g_dv_timings = lt7911d_g_dv_timings,
 	.query_dv_timings = lt7911d_query_dv_timings,
-	.g_mbus_config = lt7911d_g_mbus_config,
 	.s_stream = lt7911d_s_stream,
 	.g_frame_interval = lt7911d_g_frame_interval,
 };
@@ -1025,6 +1009,7 @@
 	.get_fmt = lt7911d_get_fmt,
 	.enum_dv_timings = lt7911d_enum_dv_timings,
 	.dv_timings_cap = lt7911d_dv_timings_cap,
+	.get_mbus_config = lt7911d_g_mbus_config,
 };
 
 static const struct v4l2_subdev_ops lt7911d_ops = {
@@ -1055,16 +1040,6 @@
 	.flags = V4L2_CTRL_FLAG_READ_ONLY,
 };
 
-static void lt7911d_reset(struct lt7911d_state *lt7911d)
-{
-	gpiod_set_value(lt7911d->reset_gpio, 0);
-	usleep_range(2000, 2100);
-	gpiod_set_value(lt7911d->reset_gpio, 1);
-	usleep_range(120*1000, 121*1000);
-	gpiod_set_value(lt7911d->reset_gpio, 0);
-	usleep_range(300*1000, 310*1000);
-}
-
 static int lt7911d_init_v4l2_ctrls(struct lt7911d_state *lt7911d)
 {
 	struct v4l2_subdev *sd;
@@ -1084,10 +1059,8 @@
 			0, LT7911D_PIXEL_RATE, 1, LT7911D_PIXEL_RATE);
 
 	lt7911d->detect_tx_5v_ctrl = v4l2_ctrl_new_std(&lt7911d->hdl,
-			&lt7911d_ctrl_ops, V4L2_CID_DV_RX_POWER_PRESENT,
+			NULL, V4L2_CID_DV_RX_POWER_PRESENT,
 			0, 1, 0, 0);
-	if (lt7911d->detect_tx_5v_ctrl)
-		lt7911d->detect_tx_5v_ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
 
 	lt7911d->audio_sampling_rate_ctrl =
 		v4l2_ctrl_new_custom(&lt7911d->hdl,
@@ -1119,7 +1092,7 @@
 {
 	struct device *dev = &lt7911d->i2c_client->dev;
 	struct device_node *node = dev->of_node;
-	struct v4l2_fwnode_endpoint *endpoint;
+	struct v4l2_fwnode_endpoint endpoint = { .bus_type = 0 };
 	struct device_node *ep;
 	int ret;
 
@@ -1160,29 +1133,20 @@
 		return ret;
 	}
 
-	lt7911d->hpd_ctl_gpio = devm_gpiod_get_optional(dev, "hpd-ctl",
-			GPIOD_OUT_HIGH);
-	if (IS_ERR(lt7911d->hpd_ctl_gpio)) {
-		dev_err(dev, "failed to get hpd ctl gpio\n");
-		ret = PTR_ERR(lt7911d->hpd_ctl_gpio);
-		return ret;
-	}
-
 	ep = of_graph_get_next_endpoint(dev->of_node, NULL);
 	if (!ep) {
 		dev_err(dev, "missing endpoint node\n");
 		return -EINVAL;
 	}
 
-	endpoint = v4l2_fwnode_endpoint_alloc_parse(of_fwnode_handle(ep));
-	if (IS_ERR(endpoint)) {
+	ret = v4l2_fwnode_endpoint_alloc_parse(of_fwnode_handle(ep), &endpoint);
+	if (ret) {
 		dev_err(dev, "failed to parse endpoint\n");
-		ret = PTR_ERR(endpoint);
-		return ret;
+		goto put_node;
 	}
 
-	if (endpoint->bus_type != V4L2_MBUS_CSI2 ||
-			endpoint->bus.mipi_csi2.num_data_lanes == 0) {
+	if (endpoint.bus_type != V4L2_MBUS_CSI2_DPHY ||
+			endpoint.bus.mipi_csi2.num_data_lanes == 0) {
 		dev_err(dev, "missing CSI-2 properties in endpoint\n");
 		ret = -EINVAL;
 		goto free_endpoint;
@@ -1201,18 +1165,20 @@
 		goto free_endpoint;
 	}
 
-	lt7911d->csi_lanes_in_use = endpoint->bus.mipi_csi2.num_data_lanes;
-	lt7911d->bus = endpoint->bus.mipi_csi2;
+	lt7911d->csi_lanes_in_use = endpoint.bus.mipi_csi2.num_data_lanes;
+	lt7911d->bus = endpoint.bus.mipi_csi2;
 	lt7911d->enable_hdcp = false;
 
-	gpiod_set_value(lt7911d->hpd_ctl_gpio, 0);
 	gpiod_set_value(lt7911d->power_gpio, 1);
-	lt7911d_reset(lt7911d);
+	usleep_range(2000, 3000);
+	gpiod_set_value(lt7911d->reset_gpio, 0);
 
 	ret = 0;
 
 free_endpoint:
-	v4l2_fwnode_endpoint_free(endpoint);
+	v4l2_fwnode_endpoint_free(&endpoint);
+put_node:
+	of_node_put(ep);
 	return ret;
 }
 #else
@@ -1266,7 +1232,7 @@
 	sd = &lt7911d->sd;
 	lt7911d->i2c_client = client;
 	lt7911d->cur_mode = &supported_modes[0];
-	lt7911d->mbus_fmt_code = MEDIA_BUS_FMT_UYVY8_2X8;
+	lt7911d->mbus_fmt_code = LT7911D_MEDIA_BUS_FMT;
 
 	err = lt7911d_probe_of(lt7911d);
 	if (err) {
@@ -1277,8 +1243,6 @@
 	err = lt7911d_check_chip_id(lt7911d);
 	if (err < 0)
 		return err;
-
-	lt7911d_reset(lt7911d);
 
 	mutex_init(&lt7911d->confctl_mutex);
 	err = lt7911d_init_v4l2_ctrls(lt7911d);
@@ -1357,7 +1321,6 @@
 		goto err_work_queues;
 	}
 
-	lt7911d_config_hpd(sd);
 	v4l2_info(sd, "%s found @ 0x%x (%s)\n", client->name,
 			client->addr << 1, client->adapter->name);
 

--
Gitblit v1.6.2