forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/media/i2c/lt6911uxc.c
....@@ -3,6 +3,9 @@
33 * Copyright (c) 2021 Rockchip Electronics Co. Ltd.
44 *
55 * Author: Dingxian Wen <shawn.wen@rock-chips.com>
6
+ * V0.0X01.0X00 first version.
7
+ * V0.0X01.0X01 fix if plugin_gpio was not used.
8
+ * V0.0X01.0X02 modify driver init level to late_initcall.
69 */
710
811 #include <linux/clk.h>
....@@ -21,6 +24,7 @@
2124 #include <linux/version.h>
2225 #include <linux/videodev2.h>
2326 #include <linux/workqueue.h>
27
+#include <linux/compat.h>
2428 #include <media/v4l2-controls_rockchip.h>
2529 #include <media/v4l2-ctrls.h>
2630 #include <media/v4l2-device.h>
....@@ -29,7 +33,7 @@
2933 #include <media/v4l2-fwnode.h>
3034 #include "lt6911uxc.h"
3135
32
-#define DRIVER_VERSION KERNEL_VERSION(0, 0x01, 0x0)
36
+#define DRIVER_VERSION KERNEL_VERSION(0, 0x01, 0x2)
3337 #define LT6911UXC_NAME "LT6911UXC"
3438
3539 #define LT6911UXC_LINK_FREQ_HIGH 400000000
....@@ -37,6 +41,12 @@
3741 #define LT6911UXC_PIXEL_RATE 400000000
3842
3943 #define I2C_MAX_XFER_SIZE 128
44
+
45
+#ifdef LT6911UXC_OUT_RGB
46
+#define LT6911UXC_MEDIA_BUS_FMT MEDIA_BUS_FMT_BGR888_1X24
47
+#else
48
+#define LT6911UXC_MEDIA_BUS_FMT MEDIA_BUS_FMT_UYVY8_2X8
49
+#endif
4050
4151 static int debug;
4252 module_param(debug, int, 0644);
....@@ -286,14 +296,27 @@
286296
287297 static inline bool tx_5v_power_present(struct v4l2_subdev *sd)
288298 {
289
- int val;
299
+ bool ret;
300
+ int val, i, cnt;
290301 struct lt6911uxc *lt6911uxc = to_state(sd);
291302
292
- val = gpiod_get_value(lt6911uxc->plugin_det_gpio);
293
- v4l2_dbg(1, debug, sd, "%s plug det: %s!\n", __func__,
294
- (val > 0) ? "int" : "out");
303
+ /* if not use plugin det gpio */
304
+ if (!lt6911uxc->plugin_det_gpio)
305
+ return true;
295306
296
- return (val > 0);
307
+ cnt = 0;
308
+ for (i = 0; i < 5; i++) {
309
+ val = gpiod_get_value(lt6911uxc->plugin_det_gpio);
310
+
311
+ if (val > 0)
312
+ cnt++;
313
+ usleep_range(500, 600);
314
+ }
315
+
316
+ ret = (cnt >= 3) ? true : false;
317
+ v4l2_dbg(1, debug, sd, "%s: %d\n", __func__, ret);
318
+
319
+ return ret;
297320 }
298321
299322 static inline bool no_signal(struct v4l2_subdev *sd)
....@@ -505,6 +528,8 @@
505528 struct v4l2_subdev *sd = &lt6911uxc->sd;
506529
507530 v4l2_dbg(2, debug, sd, "%s:\n", __func__);
531
+
532
+ v4l2_ctrl_s_ctrl(lt6911uxc->detect_tx_5v_ctrl, tx_5v_power_present(sd));
508533 lt6911uxc_config_hpd(sd);
509534 }
510535
....@@ -587,21 +612,6 @@
587612
588613 if (sd->devnode)
589614 v4l2_subdev_notify_event(sd, &lt6911uxc_ev_fmt);
590
-}
591
-
592
-static int lt6911uxc_get_ctrl(struct v4l2_ctrl *ctrl)
593
-{
594
- int ret = -1;
595
- struct lt6911uxc *lt6911uxc = container_of(ctrl->handler,
596
- struct lt6911uxc, hdl);
597
- struct v4l2_subdev *sd = &(lt6911uxc->sd);
598
-
599
- if (ctrl->id == V4L2_CID_DV_RX_POWER_PRESENT) {
600
- ret = tx_5v_power_present(sd);
601
- *ctrl->p_new.p_s32 = ret;
602
- }
603
-
604
- return ret;
605615 }
606616
607617 static int lt6911uxc_isr(struct v4l2_subdev *sd, u32 status, bool *handled)
....@@ -738,12 +748,12 @@
738748 return 0;
739749 }
740750
741
-static int lt6911uxc_g_mbus_config(struct v4l2_subdev *sd,
751
+static int lt6911uxc_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad,
742752 struct v4l2_mbus_config *cfg)
743753 {
744754 struct lt6911uxc *lt6911uxc = to_state(sd);
745755
746
- cfg->type = V4L2_MBUS_CSI2;
756
+ cfg->type = V4L2_MBUS_CSI2_DPHY;
747757 cfg->flags = V4L2_MBUS_CSI2_CONTINUOUS_CLOCK | V4L2_MBUS_CSI2_CHANNEL_0;
748758
749759 switch (lt6911uxc->csi_lanes_in_use) {
....@@ -780,7 +790,7 @@
780790 {
781791 switch (code->index) {
782792 case 0:
783
- code->code = MEDIA_BUS_FMT_UYVY8_2X8;
793
+ code->code = LT6911UXC_MEDIA_BUS_FMT;
784794 break;
785795
786796 default:
....@@ -797,7 +807,7 @@
797807 if (fse->index >= ARRAY_SIZE(supported_modes))
798808 return -EINVAL;
799809
800
- if (fse->code != MEDIA_BUS_FMT_UYVY8_2X8)
810
+ if (fse->code != LT6911UXC_MEDIA_BUS_FMT)
801811 return -EINVAL;
802812
803813 fse->min_width = supported_modes[fse->index].width;
....@@ -815,8 +825,7 @@
815825 if (fie->index >= ARRAY_SIZE(supported_modes))
816826 return -EINVAL;
817827
818
- if (fie->code != MEDIA_BUS_FMT_UYVY8_2X8)
819
- return -EINVAL;
828
+ fie->code = LT6911UXC_MEDIA_BUS_FMT;
820829
821830 fie->width = supported_modes[fie->index].width;
822831 fie->height = supported_modes[fie->index].height;
....@@ -893,7 +902,7 @@
893902 return ret;
894903
895904 switch (code) {
896
- case MEDIA_BUS_FMT_UYVY8_2X8:
905
+ case LT6911UXC_MEDIA_BUS_FMT:
897906 break;
898907
899908 default:
....@@ -952,6 +961,9 @@
952961 case RKMODULE_GET_MODULE_INFO:
953962 lt6911uxc_get_module_inf(lt6911uxc, (struct rkmodule_inf *)arg);
954963 break;
964
+ case RKMODULE_GET_HDMI_MODE:
965
+ *(int *)arg = RKMODULE_HDMIIN_MODE;
966
+ break;
955967 default:
956968 ret = -ENOIOCTLCMD;
957969 break;
....@@ -967,6 +979,7 @@
967979 void __user *up = compat_ptr(arg);
968980 struct rkmodule_inf *inf;
969981 long ret;
982
+ int *seq;
970983
971984 switch (cmd) {
972985 case RKMODULE_GET_MODULE_INFO:
....@@ -984,7 +997,21 @@
984997 }
985998 kfree(inf);
986999 break;
1000
+ case RKMODULE_GET_HDMI_MODE:
1001
+ seq = kzalloc(sizeof(*seq), GFP_KERNEL);
1002
+ if (!seq) {
1003
+ ret = -ENOMEM;
1004
+ return ret;
1005
+ }
9871006
1007
+ ret = lt6911uxc_ioctl(sd, cmd, seq);
1008
+ if (!ret) {
1009
+ ret = copy_to_user(up, seq, sizeof(*seq));
1010
+ if (ret)
1011
+ ret = -EFAULT;
1012
+ }
1013
+ kfree(seq);
1014
+ break;
9881015 default:
9891016 ret = -ENOIOCTLCMD;
9901017 break;
....@@ -993,10 +1020,6 @@
9931020 return ret;
9941021 }
9951022 #endif
996
-
997
-static const struct v4l2_ctrl_ops lt6911uxc_ctrl_ops = {
998
- .g_volatile_ctrl = lt6911uxc_get_ctrl,
999
-};
10001023
10011024 static const struct v4l2_subdev_core_ops lt6911uxc_core_ops = {
10021025 .interrupt_service_routine = lt6911uxc_isr,
....@@ -1013,7 +1036,6 @@
10131036 .s_dv_timings = lt6911uxc_s_dv_timings,
10141037 .g_dv_timings = lt6911uxc_g_dv_timings,
10151038 .query_dv_timings = lt6911uxc_query_dv_timings,
1016
- .g_mbus_config = lt6911uxc_g_mbus_config,
10171039 .s_stream = lt6911uxc_s_stream,
10181040 .g_frame_interval = lt6911uxc_g_frame_interval,
10191041 };
....@@ -1026,6 +1048,7 @@
10261048 .get_fmt = lt6911uxc_get_fmt,
10271049 .enum_dv_timings = lt6911uxc_enum_dv_timings,
10281050 .dv_timings_cap = lt6911uxc_dv_timings_cap,
1051
+ .get_mbus_config = lt6911uxc_g_mbus_config,
10291052 };
10301053
10311054 static const struct v4l2_subdev_ops lt6911uxc_ops = {
....@@ -1084,10 +1107,8 @@
10841107 0, LT6911UXC_PIXEL_RATE, 1, LT6911UXC_PIXEL_RATE);
10851108
10861109 lt6911uxc->detect_tx_5v_ctrl = v4l2_ctrl_new_std(&lt6911uxc->hdl,
1087
- &lt6911uxc_ctrl_ops, V4L2_CID_DV_RX_POWER_PRESENT,
1110
+ NULL, V4L2_CID_DV_RX_POWER_PRESENT,
10881111 0, 1, 0, 0);
1089
- if (lt6911uxc->detect_tx_5v_ctrl)
1090
- lt6911uxc->detect_tx_5v_ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
10911112
10921113 lt6911uxc->audio_sampling_rate_ctrl =
10931114 v4l2_ctrl_new_custom(&lt6911uxc->hdl,
....@@ -1153,7 +1174,7 @@
11531174 {
11541175 struct device *dev = &lt6911uxc->i2c_client->dev;
11551176 struct device_node *node = dev->of_node;
1156
- struct v4l2_fwnode_endpoint *endpoint;
1177
+ struct v4l2_fwnode_endpoint endpoint = { .bus_type = 0 };
11571178 struct device_node *ep;
11581179 int ret;
11591180
....@@ -1209,15 +1230,14 @@
12091230 return ret;
12101231 }
12111232
1212
- endpoint = v4l2_fwnode_endpoint_alloc_parse(of_fwnode_handle(ep));
1213
- if (IS_ERR(endpoint)) {
1233
+ ret = v4l2_fwnode_endpoint_alloc_parse(of_fwnode_handle(ep), &endpoint);
1234
+ if (ret) {
12141235 dev_err(dev, "failed to parse endpoint\n");
1215
- ret = PTR_ERR(endpoint);
1216
- return ret;
1236
+ goto put_node;
12171237 }
12181238
1219
- if (endpoint->bus_type != V4L2_MBUS_CSI2 ||
1220
- endpoint->bus.mipi_csi2.num_data_lanes == 0) {
1239
+ if (endpoint.bus_type != V4L2_MBUS_CSI2_DPHY ||
1240
+ endpoint.bus.mipi_csi2.num_data_lanes == 0) {
12211241 dev_err(dev, "missing CSI-2 properties in endpoint\n");
12221242 ret = -EINVAL;
12231243 goto free_endpoint;
....@@ -1236,8 +1256,8 @@
12361256 goto free_endpoint;
12371257 }
12381258
1239
- lt6911uxc->csi_lanes_in_use = endpoint->bus.mipi_csi2.num_data_lanes;
1240
- lt6911uxc->bus = endpoint->bus.mipi_csi2;
1259
+ lt6911uxc->csi_lanes_in_use = endpoint.bus.mipi_csi2.num_data_lanes;
1260
+ lt6911uxc->bus = endpoint.bus.mipi_csi2;
12411261 lt6911uxc->enable_hdcp = false;
12421262
12431263 gpiod_set_value(lt6911uxc->hpd_ctl_gpio, 0);
....@@ -1247,7 +1267,9 @@
12471267 ret = 0;
12481268
12491269 free_endpoint:
1250
- v4l2_fwnode_endpoint_free(endpoint);
1270
+ v4l2_fwnode_endpoint_free(&endpoint);
1271
+put_node:
1272
+ of_node_put(ep);
12511273 return ret;
12521274 }
12531275 #else
....@@ -1260,6 +1282,8 @@
12601282 static int lt6911uxc_probe(struct i2c_client *client,
12611283 const struct i2c_device_id *id)
12621284 {
1285
+ struct v4l2_dv_timings default_timing =
1286
+ V4L2_DV_BT_CEA_640X480P59_94;
12631287 struct lt6911uxc *lt6911uxc;
12641288 struct v4l2_subdev *sd;
12651289 struct device *dev = &client->dev;
....@@ -1277,8 +1301,9 @@
12771301
12781302 sd = &lt6911uxc->sd;
12791303 lt6911uxc->i2c_client = client;
1304
+ lt6911uxc->timings = default_timing;
12801305 lt6911uxc->cur_mode = &supported_modes[0];
1281
- lt6911uxc->mbus_fmt_code = MEDIA_BUS_FMT_UYVY8_2X8;
1306
+ lt6911uxc->mbus_fmt_code = LT6911UXC_MEDIA_BUS_FMT;
12821307
12831308 err = lt6911uxc_parse_of(lt6911uxc);
12841309 if (err) {
....@@ -1353,20 +1378,15 @@
13531378 }
13541379
13551380 lt6911uxc->plugin_irq = gpiod_to_irq(lt6911uxc->plugin_det_gpio);
1356
- if (lt6911uxc->plugin_irq < 0) {
1357
- dev_err(dev, "failed to get plugin det irq\n");
1358
- err = lt6911uxc->plugin_irq;
1359
- goto err_work_queues;
1360
- }
1381
+ if (lt6911uxc->plugin_irq < 0)
1382
+ dev_err(dev, "failed to get plugin det irq, maybe no use\n");
13611383
13621384 err = devm_request_threaded_irq(dev, lt6911uxc->plugin_irq, NULL,
13631385 plugin_detect_irq_handler, IRQF_TRIGGER_FALLING |
13641386 IRQF_TRIGGER_RISING | IRQF_ONESHOT, "lt6911uxc",
13651387 lt6911uxc);
1366
- if (err) {
1367
- dev_err(dev, "failed to register plugin det irq (%d)\n", err);
1368
- goto err_work_queues;
1369
- }
1388
+ if (err)
1389
+ dev_err(dev, "failed to register plugin det irq (%d), maybe no use\n", err);
13701390
13711391 err = v4l2_ctrl_handler_setup(sd->ctrl_handler);
13721392 if (err) {
....@@ -1439,7 +1459,7 @@
14391459 i2c_del_driver(&lt6911uxc_driver);
14401460 }
14411461
1442
-device_initcall_sync(lt6911uxc_driver_init);
1462
+late_initcall(lt6911uxc_driver_init);
14431463 module_exit(lt6911uxc_driver_exit);
14441464
14451465 MODULE_DESCRIPTION("Lontium LT6911UXC HDMI to MIPI CSI-2 bridge driver");