hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/media/i2c/maxim4c/maxim4c_drv.c
....@@ -22,6 +22,26 @@
2222 * 5. power control: local by pwdn gpio, remote by pocen gpio
2323 * 6. local pwdn on/off enable depend on MAXIM4C_LOCAL_DES_ON_OFF_EN
2424 *
25
+ * V2.02.00
26
+ * 1. Force all MIPI clocks running Setting in csi out enable.
27
+ * 2. Pattern mode force_clock_out_en default enable.
28
+ *
29
+ * V2.03.00
30
+ * 1. remote device add the maxim4c prefix to driver name.
31
+ *
32
+ * V2.04.04
33
+ * 1. Add regulator supplier dependencies.
34
+ * 2. Add config ssc-ratio property
35
+ * 3. Add debugfs entry to change MIPI timing
36
+ * 4. Use PM runtime autosuspend feature
37
+ * 5. Fix unbalanced disabling for PoC regulator
38
+ * 6. MIPI VC count does not affected by data lane count
39
+ *
40
+ * V2.05.00
41
+ * 1. local device power on add some delay for i2c normal access.
42
+ * 2. enable hot plug detect for partial links are locked.
43
+ * 3. remote device hot plug init disable lock irq.
44
+ *
2545 */
2646 #include <linux/clk.h>
2747 #include <linux/i2c.h>
....@@ -51,9 +71,14 @@
5171
5272 #include "maxim4c_api.h"
5373
54
-#define DRIVER_VERSION KERNEL_VERSION(2, 0x01, 0x00)
74
+#define DRIVER_VERSION KERNEL_VERSION(2, 0x05, 0x00)
5575
5676 #define MAXIM4C_XVCLK_FREQ 25000000
77
+
78
+static const char *const maxim4c_supply_names[MAXIM4C_NUM_SUPPLIES] = {
79
+ "vcc1v2",
80
+ "vcc1v8",
81
+};
5782
5883 static int maxim4c_check_local_chipid(maxim4c_t *maxim4c)
5984 {
....@@ -83,8 +108,8 @@
83108 return 0;
84109 }
85110 } else {
111
+ // if chipid is unexpected, retry
86112 dev_err(dev, "Unexpected maxim chipid = %02x\n", chipid);
87
- return -ENODEV;
88113 }
89114 }
90115 }
....@@ -115,7 +140,7 @@
115140
116141 queue_delayed_work(maxim4c->hot_plug_work.state_check_wq,
117142 &maxim4c->hot_plug_work.state_d_work,
118
- msecs_to_jiffies(50));
143
+ msecs_to_jiffies(100));
119144 }
120145 mutex_unlock(&maxim4c->mutex);
121146
....@@ -189,7 +214,13 @@
189214 if (curr_lock_state & MAXIM4C_LINK_MASK_A) {
190215 dev_info(dev, "Link A plug in\n");
191216
217
+ if (maxim4c->hot_plug_irq > 0)
218
+ disable_irq(maxim4c->hot_plug_irq);
219
+
192220 maxim4c_remote_devices_init(maxim4c, MAXIM4C_LINK_MASK_A);
221
+
222
+ if (maxim4c->hot_plug_irq > 0)
223
+ enable_irq(maxim4c->hot_plug_irq);
193224
194225 maxim4c_video_pipe_linkid_enable(maxim4c, link_id, true);
195226 } else {
....@@ -205,7 +236,13 @@
205236 if (curr_lock_state & MAXIM4C_LINK_MASK_B) {
206237 dev_info(dev, "Link B plug in\n");
207238
239
+ if (maxim4c->hot_plug_irq > 0)
240
+ disable_irq(maxim4c->hot_plug_irq);
241
+
208242 maxim4c_remote_devices_init(maxim4c, MAXIM4C_LINK_MASK_B);
243
+
244
+ if (maxim4c->hot_plug_irq > 0)
245
+ enable_irq(maxim4c->hot_plug_irq);
209246
210247 maxim4c_video_pipe_linkid_enable(maxim4c, link_id, true);
211248 } else {
....@@ -221,7 +258,13 @@
221258 if (curr_lock_state & MAXIM4C_LINK_MASK_C) {
222259 dev_info(dev, "Link C plug in\n");
223260
261
+ if (maxim4c->hot_plug_irq > 0)
262
+ disable_irq(maxim4c->hot_plug_irq);
263
+
224264 maxim4c_remote_devices_init(maxim4c, MAXIM4C_LINK_MASK_C);
265
+
266
+ if (maxim4c->hot_plug_irq > 0)
267
+ enable_irq(maxim4c->hot_plug_irq);
225268
226269 maxim4c_video_pipe_linkid_enable(maxim4c, link_id, true);
227270 } else {
....@@ -237,7 +280,13 @@
237280 if (curr_lock_state & MAXIM4C_LINK_MASK_D) {
238281 dev_info(dev, "Link D plug in\n");
239282
283
+ if (maxim4c->hot_plug_irq > 0)
284
+ disable_irq(maxim4c->hot_plug_irq);
285
+
240286 maxim4c_remote_devices_init(maxim4c, MAXIM4C_LINK_MASK_D);
287
+
288
+ if (maxim4c->hot_plug_irq > 0)
289
+ enable_irq(maxim4c->hot_plug_irq);
241290
242291 maxim4c_video_pipe_linkid_enable(maxim4c, link_id, true);
243292 } else {
....@@ -253,10 +302,32 @@
253302 } else {
254303 queue_delayed_work(maxim4c->hot_plug_work.state_check_wq,
255304 &maxim4c->hot_plug_work.state_d_work,
256
- msecs_to_jiffies(100));
305
+ msecs_to_jiffies(200));
257306 }
258307
259308 mutex_unlock(&maxim4c->mutex);
309
+}
310
+
311
+int maxim4c_hot_plug_detect_work_start(maxim4c_t *maxim4c)
312
+{
313
+ struct device *dev = &maxim4c->client->dev;
314
+ u8 link_lock_state = 0, link_enable_mask = 0;
315
+
316
+ link_lock_state = maxim4c->link_lock_state;
317
+ link_enable_mask = maxim4c->gmsl_link.link_enable_mask;
318
+
319
+ if (link_lock_state != link_enable_mask) {
320
+ dev_info(dev, "%s: link_lock = 0x%02x, link_mask = 0x%02x\n",
321
+ __func__, link_lock_state, link_enable_mask);
322
+
323
+ maxim4c->hot_plug_state = MAXIM4C_HOT_PLUG_OUT;
324
+
325
+ queue_delayed_work(maxim4c->hot_plug_work.state_check_wq,
326
+ &maxim4c->hot_plug_work.state_d_work,
327
+ msecs_to_jiffies(200));
328
+ }
329
+
330
+ return 0;
260331 }
261332
262333 static int maxim4c_lock_state_work_init(maxim4c_t *maxim4c)
....@@ -295,13 +366,20 @@
295366 static int maxim4c_local_device_power_on(maxim4c_t *maxim4c)
296367 {
297368 struct device *dev = &maxim4c->client->dev;
369
+ int ret;
370
+
371
+ ret = regulator_bulk_enable(MAXIM4C_NUM_SUPPLIES, maxim4c->supplies);
372
+ if (ret < 0) {
373
+ dev_err(dev, "Failed to enable regulators\n");
374
+ return -EINVAL;
375
+ }
298376
299377 if (!IS_ERR(maxim4c->pwdn_gpio)) {
300378 dev_info(dev, "local device pwdn gpio on\n");
301379
302380 gpiod_set_value_cansleep(maxim4c->pwdn_gpio, 1);
303381
304
- usleep_range(5000, 10000);
382
+ usleep_range(10000, 11000);
305383 }
306384
307385 return 0;
....@@ -310,24 +388,30 @@
310388 static void maxim4c_local_device_power_off(maxim4c_t *maxim4c)
311389 {
312390 struct device *dev = &maxim4c->client->dev;
391
+ int ret;
313392
314393 if (!IS_ERR(maxim4c->pwdn_gpio)) {
315394 dev_info(dev, "local device pwdn gpio off\n");
316395
317396 gpiod_set_value_cansleep(maxim4c->pwdn_gpio, 0);
318397 }
398
+
399
+ ret = regulator_bulk_disable(MAXIM4C_NUM_SUPPLIES, maxim4c->supplies);
400
+ if (ret < 0) {
401
+ dev_warn(dev, "Failed to disable regulators\n");
402
+ }
319403 }
320404
321405 static int maxim4c_remote_device_power_on(maxim4c_t *maxim4c)
322406 {
323407 struct device *dev = &maxim4c->client->dev;
408
+ int ret;
324409
325
- // remote PoC enable
326
- if (!IS_ERR(maxim4c->pocen_gpio)) {
327
- dev_info(dev, "remote device pocen gpio on\n");
328
-
329
- gpiod_set_value_cansleep(maxim4c->pocen_gpio, 1);
330
- usleep_range(5000, 10000);
410
+ dev_dbg(dev, "Turn PoC on\n");
411
+ ret = regulator_enable(maxim4c->poc_regulator);
412
+ if (ret < 0) {
413
+ dev_err(dev, "Unable to turn PoC on\n");
414
+ return ret;
331415 }
332416
333417 return 0;
....@@ -336,13 +420,12 @@
336420 static int maxim4c_remote_device_power_off(maxim4c_t *maxim4c)
337421 {
338422 struct device *dev = &maxim4c->client->dev;
423
+ int ret;
339424
340
- // remote PoC enable
341
- if (!IS_ERR(maxim4c->pocen_gpio)) {
342
- dev_info(dev, "remote device pocen gpio off\n");
343
-
344
- gpiod_set_value_cansleep(maxim4c->pocen_gpio, 0);
345
- }
425
+ dev_dbg(dev, "Turn PoC off\n");
426
+ ret = regulator_disable(maxim4c->poc_regulator);
427
+ if (ret < 0)
428
+ dev_warn(dev, "Unable to turn PoC off\n");
346429
347430 return 0;
348431 }
....@@ -574,6 +657,7 @@
574657 maxim4c_t *maxim4c = NULL;
575658 u32 chip_id;
576659 int ret = 0;
660
+ unsigned int i;
577661
578662 dev_info(dev, "driver version: %02x.%02x.%02x", DRIVER_VERSION >> 16,
579663 (DRIVER_VERSION & 0xff00) >> 8, DRIVER_VERSION & 0x00ff);
....@@ -613,20 +697,53 @@
613697 maxim4c->pwdn_gpio = devm_gpiod_get(dev, "pwdn", GPIOD_OUT_LOW);
614698 if (IS_ERR(maxim4c->pwdn_gpio))
615699 dev_warn(dev, "Failed to get pwdn-gpios, maybe no use\n");
616
-
617
- maxim4c->pocen_gpio = devm_gpiod_get(dev, "pocen", GPIOD_OUT_LOW);
618
- if (IS_ERR(maxim4c->pocen_gpio))
619
- dev_warn(dev, "Failed to get pocen-gpios\n");
700
+ else
701
+ usleep_range(1000, 1100);
620702
621703 maxim4c->lock_gpio = devm_gpiod_get(dev, "lock", GPIOD_IN);
622704 if (IS_ERR(maxim4c->lock_gpio))
623705 dev_warn(dev, "Failed to get lock-gpios\n");
706
+
707
+ for (i = 0; i < MAXIM4C_NUM_SUPPLIES; i++)
708
+ maxim4c->supplies[i].supply = maxim4c_supply_names[i];
709
+
710
+ ret = devm_regulator_bulk_get(dev, MAXIM4C_NUM_SUPPLIES,
711
+ maxim4c->supplies);
712
+ if (ret < 0) {
713
+ if (ret != -EPROBE_DEFER)
714
+ dev_err(dev, "Unable to get supply regulators\n");
715
+ else
716
+ dev_warn(dev, "Get PoC regulator deferred\n");
717
+ return ret;
718
+ }
719
+
720
+ maxim4c->poc_regulator = devm_regulator_get(dev, "poc");
721
+ if (IS_ERR(maxim4c->poc_regulator)) {
722
+ if (PTR_ERR(maxim4c->poc_regulator) != -EPROBE_DEFER)
723
+ dev_err(dev, "Unable to get PoC regulator (%ld)\n",
724
+ PTR_ERR(maxim4c->poc_regulator));
725
+ else
726
+ dev_err(dev, "Get PoC regulator deferred\n");
727
+
728
+ ret = PTR_ERR(maxim4c->poc_regulator);
729
+#if !MAXIM4C_TEST_PATTERN
730
+ return ret;
731
+#endif
732
+ }
624733
625734 mutex_init(&maxim4c->mutex);
626735
627736 ret = maxim4c_local_device_power_on(maxim4c);
628737 if (ret)
629738 goto err_destroy_mutex;
739
+
740
+ ret = maxim4c_remote_device_power_on(maxim4c);
741
+ if (ret)
742
+ dev_warn(dev, "Power on PoC regulator failed\n");
743
+
744
+ pm_runtime_set_active(dev);
745
+ pm_runtime_get_noresume(dev);
746
+ pm_runtime_enable(dev);
630747
631748 ret = maxim4c_check_local_chipid(maxim4c);
632749 if (ret)
....@@ -651,9 +768,10 @@
651768 goto err_power_off;
652769 #endif /* MAXIM4C_LOCAL_DES_ON_OFF_EN */
653770
654
- pm_runtime_set_active(dev);
655
- pm_runtime_enable(dev);
656
- pm_runtime_idle(dev);
771
+ pm_runtime_set_autosuspend_delay(dev, 1000);
772
+ pm_runtime_use_autosuspend(dev);
773
+ pm_runtime_mark_last_busy(dev);
774
+ pm_runtime_put_autosuspend(dev);
657775
658776 return 0;
659777 #endif /* MAXIM4C_TEST_PATTERN */
....@@ -661,28 +779,38 @@
661779 maxim4c_module_data_init(maxim4c);
662780 maxim4c_module_parse_dt(maxim4c);
663781
782
+ ret = maxim4c_dbgfs_init(maxim4c);
783
+ if (ret)
784
+ goto err_subdev_deinit;
785
+
664786 #if (MAXIM4C_LOCAL_DES_ON_OFF_EN == 0)
665787 ret = maxim4c_module_hw_init(maxim4c);
666788 if (ret)
667
- goto err_subdev_deinit;
789
+ goto err_dbgfs_deinit;
668790 #endif /* MAXIM4C_LOCAL_DES_ON_OFF_EN */
669791
670792 ret = maxim4c_remote_mfd_add_devices(maxim4c);
671793 if (ret)
672
- goto err_subdev_deinit;
794
+ goto err_dbgfs_deinit;
673795
674796 maxim4c_lock_irq_init(maxim4c);
675797 maxim4c_lock_state_work_init(maxim4c);
676798
677
- pm_runtime_set_active(dev);
678
- pm_runtime_enable(dev);
679
- pm_runtime_idle(dev);
799
+ pm_runtime_set_autosuspend_delay(dev, 1000);
800
+ pm_runtime_use_autosuspend(dev);
801
+ pm_runtime_mark_last_busy(dev);
802
+ pm_runtime_put_autosuspend(dev);
680803
681804 return 0;
682805
806
+err_dbgfs_deinit:
807
+ maxim4c_dbgfs_deinit(maxim4c);
683808 err_subdev_deinit:
684809 maxim4c_v4l2_subdev_deinit(maxim4c);
685810 err_power_off:
811
+ pm_runtime_disable(dev);
812
+ pm_runtime_put_noidle(dev);
813
+ maxim4c_remote_device_power_off(maxim4c);
686814 maxim4c_local_device_power_off(maxim4c);
687815 err_destroy_mutex:
688816 mutex_destroy(&maxim4c->mutex);
....@@ -696,6 +824,8 @@
696824
697825 maxim4c_lock_state_work_deinit(maxim4c);
698826
827
+ maxim4c_dbgfs_deinit(maxim4c);
828
+
699829 maxim4c_v4l2_subdev_deinit(maxim4c);
700830
701831 mutex_destroy(&maxim4c->mutex);