hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c
....@@ -1,24 +1,24 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Analog Devices ADV7511 HDMI transmitter driver
34 *
45 * Copyright 2012 Analog Devices Inc.
5
- *
6
- * Licensed under the GPL-2.
76 */
87
8
+#include <linux/clk.h>
99 #include <linux/device.h>
1010 #include <linux/gpio/consumer.h>
1111 #include <linux/module.h>
1212 #include <linux/of_device.h>
1313 #include <linux/slab.h>
14
-#include <linux/clk.h>
1514
16
-#include <drm/drmP.h>
15
+#include <media/cec.h>
16
+
1717 #include <drm/drm_atomic.h>
1818 #include <drm/drm_atomic_helper.h>
1919 #include <drm/drm_edid.h>
20
-
21
-#include <media/cec.h>
20
+#include <drm/drm_print.h>
21
+#include <drm/drm_probe_helper.h>
2222
2323 #include "adv7511.h"
2424
....@@ -351,11 +351,20 @@
351351 * from standby or are enabled. When the HPD goes low the adv7511 is
352352 * reset and the outputs are disabled which might cause the monitor to
353353 * go to standby again. To avoid this we ignore the HPD pin for the
354
- * first few seconds after enabling the output.
354
+ * first few seconds after enabling the output. On the other hand
355
+ * adv7535 require to enable HPD Override bit for proper HPD.
355356 */
356
- regmap_update_bits(adv7511->regmap, ADV7511_REG_POWER2,
357
- ADV7511_REG_POWER2_HPD_SRC_MASK,
358
- ADV7511_REG_POWER2_HPD_SRC_NONE);
357
+ if (adv7511->type == ADV7535)
358
+ regmap_update_bits(adv7511->regmap, ADV7511_REG_POWER2,
359
+ ADV7535_REG_POWER2_HPD_OVERRIDE,
360
+ ADV7535_REG_POWER2_HPD_OVERRIDE);
361
+ else
362
+ regmap_update_bits(adv7511->regmap, ADV7511_REG_POWER2,
363
+ ADV7511_REG_POWER2_HPD_SRC_MASK,
364
+ ADV7511_REG_POWER2_HPD_SRC_NONE);
365
+
366
+ /* HACK: If we don't delay here edid probing doesn't work properly */
367
+ msleep(200);
359368 }
360369
361370 static void adv7511_power_on(struct adv7511 *adv7511)
....@@ -367,7 +376,7 @@
367376 */
368377 regcache_sync(adv7511->regmap);
369378
370
- if (adv7511->type == ADV7533)
379
+ if (adv7511->type == ADV7533 || adv7511->type == ADV7535)
371380 adv7533_dsi_power_on(adv7511);
372381 adv7511->powered = true;
373382 }
....@@ -375,6 +384,10 @@
375384 static void __adv7511_power_off(struct adv7511 *adv7511)
376385 {
377386 /* TODO: setup additional power down modes */
387
+ if (adv7511->type == ADV7535)
388
+ regmap_update_bits(adv7511->regmap, ADV7511_REG_POWER2,
389
+ ADV7535_REG_POWER2_HPD_OVERRIDE, 0);
390
+
378391 regmap_update_bits(adv7511->regmap, ADV7511_REG_POWER,
379392 ADV7511_POWER_POWER_DOWN,
380393 ADV7511_POWER_POWER_DOWN);
....@@ -387,7 +400,7 @@
387400 static void adv7511_power_off(struct adv7511 *adv7511)
388401 {
389402 __adv7511_power_off(adv7511);
390
- if (adv7511->type == ADV7533)
403
+ if (adv7511->type == ADV7533 || adv7511->type == ADV7535)
391404 adv7533_dsi_power_off(adv7511);
392405 adv7511->powered = false;
393406 }
....@@ -443,9 +456,14 @@
443456
444457 if (adv7511->connector.status != status) {
445458 adv7511->connector.status = status;
446
- if (status == connector_status_disconnected)
447
- cec_phys_addr_invalidate(adv7511->cec_adap);
448
- drm_kms_helper_hotplug_event(adv7511->connector.dev);
459
+
460
+ if (adv7511->connector.dev) {
461
+ if (status == connector_status_disconnected)
462
+ cec_phys_addr_invalidate(adv7511->cec_adap);
463
+ drm_kms_helper_hotplug_event(adv7511->connector.dev);
464
+ } else {
465
+ drm_bridge_hpd_notify(&adv7511->bridge, status);
466
+ }
449467 }
450468 }
451469
....@@ -589,11 +607,10 @@
589607 * ADV75xx helpers
590608 */
591609
592
-static int adv7511_get_modes(struct adv7511 *adv7511,
593
- struct drm_connector *connector)
610
+static struct edid *adv7511_get_edid(struct adv7511 *adv7511,
611
+ struct drm_connector *connector)
594612 {
595613 struct edid *edid;
596
- unsigned int count;
597614
598615 /* Reading the EDID only works if the device is powered */
599616 if (!adv7511->powered) {
....@@ -612,14 +629,24 @@
612629 if (!adv7511->powered)
613630 __adv7511_power_off(adv7511);
614631
615
-
616
- drm_connector_update_edid_property(connector, edid);
617
- count = drm_add_edid_modes(connector, edid);
618
-
619632 adv7511_set_config_csc(adv7511, connector, adv7511->rgb,
620633 drm_detect_hdmi_monitor(edid));
621634
622635 cec_s_phys_addr_from_edid(adv7511->cec_adap, edid);
636
+
637
+ return edid;
638
+}
639
+
640
+static int adv7511_get_modes(struct adv7511 *adv7511,
641
+ struct drm_connector *connector)
642
+{
643
+ struct edid *edid;
644
+ unsigned int count;
645
+
646
+ edid = adv7511_get_edid(adv7511, connector);
647
+
648
+ drm_connector_update_edid_property(connector, edid);
649
+ count = drm_add_edid_modes(connector, edid);
623650
624651 kfree(edid);
625652
....@@ -652,14 +679,20 @@
652679 if (status == connector_status_connected && hpd && adv7511->powered) {
653680 regcache_mark_dirty(adv7511->regmap);
654681 adv7511_power_on(adv7511);
655
- adv7511_get_modes(adv7511, connector);
682
+ if (connector)
683
+ adv7511_get_modes(adv7511, connector);
656684 if (adv7511->status == connector_status_connected)
657685 status = connector_status_disconnected;
658686 } else {
659687 /* Renable HPD sensing */
660
- regmap_update_bits(adv7511->regmap, ADV7511_REG_POWER2,
661
- ADV7511_REG_POWER2_HPD_SRC_MASK,
662
- ADV7511_REG_POWER2_HPD_SRC_BOTH);
688
+ if (adv7511->type == ADV7535)
689
+ regmap_update_bits(adv7511->regmap, ADV7511_REG_POWER2,
690
+ ADV7535_REG_POWER2_HPD_OVERRIDE,
691
+ ADV7535_REG_POWER2_HPD_OVERRIDE);
692
+ else
693
+ regmap_update_bits(adv7511->regmap, ADV7511_REG_POWER2,
694
+ ADV7511_REG_POWER2_HPD_SRC_MASK,
695
+ ADV7511_REG_POWER2_HPD_SRC_BOTH);
663696 }
664697
665698 adv7511->status = status;
....@@ -667,7 +700,7 @@
667700 }
668701
669702 static enum drm_mode_status adv7511_mode_valid(struct adv7511 *adv7511,
670
- struct drm_display_mode *mode)
703
+ const struct drm_display_mode *mode)
671704 {
672705 if (mode->clock > 165000)
673706 return MODE_CLOCK_HIGH;
....@@ -676,8 +709,8 @@
676709 }
677710
678711 static void adv7511_mode_set(struct adv7511 *adv7511,
679
- struct drm_display_mode *mode,
680
- struct drm_display_mode *adj_mode)
712
+ const struct drm_display_mode *mode,
713
+ const struct drm_display_mode *adj_mode)
681714 {
682715 unsigned int low_refresh_rate;
683716 unsigned int hsync_polarity = 0;
....@@ -756,13 +789,15 @@
756789 else
757790 low_refresh_rate = ADV7511_LOW_REFRESH_RATE_NONE;
758791
759
- regmap_update_bits(adv7511->regmap, 0xfb,
760
- 0x6, low_refresh_rate << 1);
792
+ if (adv7511->type == ADV7511)
793
+ regmap_update_bits(adv7511->regmap, 0xfb,
794
+ 0x6, low_refresh_rate << 1);
795
+ else
796
+ regmap_update_bits(adv7511->regmap, 0x4a,
797
+ 0xc, low_refresh_rate << 2);
798
+
761799 regmap_update_bits(adv7511->regmap, 0x17,
762800 0x60, (vsync_polarity << 6) | (hsync_polarity << 5));
763
-
764
- if (adv7511->type == ADV7533)
765
- adv7533_mode_set(adv7511, adj_mode);
766801
767802 drm_mode_copy(&adv7511->curr_mode, adj_mode);
768803
....@@ -774,7 +809,10 @@
774809 adv7511->f_tmds = mode->clock;
775810 }
776811
777
-/* Connector funcs */
812
+/* -----------------------------------------------------------------------------
813
+ * DRM Connector Operations
814
+ */
815
+
778816 static struct adv7511 *connector_to_adv7511(struct drm_connector *connector)
779817 {
780818 return container_of(connector, struct adv7511, connector);
....@@ -818,7 +856,40 @@
818856 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
819857 };
820858
821
-/* Bridge funcs */
859
+static int adv7511_connector_init(struct adv7511 *adv)
860
+{
861
+ struct drm_bridge *bridge = &adv->bridge;
862
+ int ret;
863
+
864
+ if (!bridge->encoder) {
865
+ DRM_ERROR("Parent encoder object not found");
866
+ return -ENODEV;
867
+ }
868
+
869
+ if (adv->i2c_main->irq)
870
+ adv->connector.polled = DRM_CONNECTOR_POLL_HPD;
871
+ else
872
+ adv->connector.polled = DRM_CONNECTOR_POLL_CONNECT |
873
+ DRM_CONNECTOR_POLL_DISCONNECT;
874
+
875
+ ret = drm_connector_init(bridge->dev, &adv->connector,
876
+ &adv7511_connector_funcs,
877
+ DRM_MODE_CONNECTOR_HDMIA);
878
+ if (ret < 0) {
879
+ DRM_ERROR("Failed to initialize connector with drm\n");
880
+ return ret;
881
+ }
882
+ drm_connector_helper_add(&adv->connector,
883
+ &adv7511_connector_helper_funcs);
884
+ drm_connector_attach_encoder(&adv->connector, bridge->encoder);
885
+
886
+ return 0;
887
+}
888
+
889
+/* -----------------------------------------------------------------------------
890
+ * DRM Bridge Operations
891
+ */
892
+
822893 static struct adv7511 *bridge_to_adv7511(struct drm_bridge *bridge)
823894 {
824895 return container_of(bridge, struct adv7511, bridge);
....@@ -839,42 +910,39 @@
839910 }
840911
841912 static void adv7511_bridge_mode_set(struct drm_bridge *bridge,
842
- struct drm_display_mode *mode,
843
- struct drm_display_mode *adj_mode)
913
+ const struct drm_display_mode *mode,
914
+ const struct drm_display_mode *adj_mode)
844915 {
845916 struct adv7511 *adv = bridge_to_adv7511(bridge);
846917
847918 adv7511_mode_set(adv, mode, adj_mode);
848919 }
849920
850
-static int adv7511_bridge_attach(struct drm_bridge *bridge)
921
+static enum drm_mode_status adv7511_bridge_mode_valid(struct drm_bridge *bridge,
922
+ const struct drm_display_info *info,
923
+ const struct drm_display_mode *mode)
851924 {
852925 struct adv7511 *adv = bridge_to_adv7511(bridge);
853
- int ret;
854926
855
- if (!bridge->encoder) {
856
- DRM_ERROR("Parent encoder object not found");
857
- return -ENODEV;
858
- }
859
-
860
- if (adv->i2c_main->irq)
861
- adv->connector.polled = DRM_CONNECTOR_POLL_HPD;
927
+ if (adv->type == ADV7533 || adv->type == ADV7535)
928
+ return adv7533_mode_valid(adv, mode);
862929 else
863
- adv->connector.polled = DRM_CONNECTOR_POLL_CONNECT |
864
- DRM_CONNECTOR_POLL_DISCONNECT;
930
+ return adv7511_mode_valid(adv, mode);
931
+}
865932
866
- ret = drm_connector_init(bridge->dev, &adv->connector,
867
- &adv7511_connector_funcs,
868
- DRM_MODE_CONNECTOR_HDMIA);
869
- if (ret) {
870
- DRM_ERROR("Failed to initialize connector with drm\n");
871
- return ret;
933
+static int adv7511_bridge_attach(struct drm_bridge *bridge,
934
+ enum drm_bridge_attach_flags flags)
935
+{
936
+ struct adv7511 *adv = bridge_to_adv7511(bridge);
937
+ int ret = 0;
938
+
939
+ if (!(flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR)) {
940
+ ret = adv7511_connector_init(adv);
941
+ if (ret < 0)
942
+ return ret;
872943 }
873
- drm_connector_helper_add(&adv->connector,
874
- &adv7511_connector_helper_funcs);
875
- drm_connector_attach_encoder(&adv->connector, bridge->encoder);
876944
877
- if (adv->type == ADV7533)
945
+ if (adv->type == ADV7533 || adv->type == ADV7535)
878946 ret = adv7533_attach_dsi(adv);
879947
880948 if (adv->i2c_main->irq)
....@@ -884,11 +952,39 @@
884952 return ret;
885953 }
886954
955
+static enum drm_connector_status adv7511_bridge_detect(struct drm_bridge *bridge)
956
+{
957
+ struct adv7511 *adv = bridge_to_adv7511(bridge);
958
+
959
+ return adv7511_detect(adv, NULL);
960
+}
961
+
962
+static struct edid *adv7511_bridge_get_edid(struct drm_bridge *bridge,
963
+ struct drm_connector *connector)
964
+{
965
+ struct adv7511 *adv = bridge_to_adv7511(bridge);
966
+
967
+ return adv7511_get_edid(adv, connector);
968
+}
969
+
970
+static void adv7511_bridge_hpd_notify(struct drm_bridge *bridge,
971
+ enum drm_connector_status status)
972
+{
973
+ struct adv7511 *adv = bridge_to_adv7511(bridge);
974
+
975
+ if (status == connector_status_disconnected)
976
+ cec_phys_addr_invalidate(adv->cec_adap);
977
+}
978
+
887979 static const struct drm_bridge_funcs adv7511_bridge_funcs = {
888980 .enable = adv7511_bridge_enable,
889981 .disable = adv7511_bridge_disable,
890982 .mode_set = adv7511_bridge_mode_set,
983
+ .mode_valid = adv7511_bridge_mode_valid,
891984 .attach = adv7511_bridge_attach,
985
+ .detect = adv7511_bridge_detect,
986
+ .get_edid = adv7511_bridge_get_edid,
987
+ .hpd_notify = adv7511_bridge_hpd_notify,
892988 };
893989
894990 /* -----------------------------------------------------------------------------
....@@ -952,7 +1048,7 @@
9521048 struct i2c_client *i2c = to_i2c_client(dev);
9531049 struct adv7511 *adv7511 = i2c_get_clientdata(i2c);
9541050
955
- if (adv7511->type == ADV7533)
1051
+ if (adv7511->type == ADV7533 || adv7511->type == ADV7535)
9561052 reg -= ADV7533_REG_CEC_OFFSET;
9571053
9581054 switch (reg) {
....@@ -981,10 +1077,14 @@
9811077 {
9821078 int ret;
9831079
984
- adv->i2c_cec = i2c_new_secondary_device(adv->i2c_main, "cec",
1080
+ adv->i2c_cec = i2c_new_ancillary_device(adv->i2c_main, "cec",
9851081 ADV7511_CEC_I2C_ADDR_DEFAULT);
986
- if (!adv->i2c_cec)
987
- return -EINVAL;
1082
+ if (IS_ERR(adv->i2c_cec))
1083
+ return PTR_ERR(adv->i2c_cec);
1084
+
1085
+ regmap_write(adv->regmap, ADV7511_REG_CEC_I2C_ADDR,
1086
+ adv->i2c_cec->addr << 1);
1087
+
9881088 i2c_set_clientdata(adv->i2c_cec, adv);
9891089
9901090 adv->regmap_cec = devm_regmap_init_i2c(adv->i2c_cec,
....@@ -994,7 +1094,7 @@
9941094 goto err;
9951095 }
9961096
997
- if (adv->type == ADV7533) {
1097
+ if (adv->type == ADV7533 || adv->type == ADV7535) {
9981098 ret = adv7533_patch_cec_registers(adv);
9991099 if (ret)
10001100 goto err;
....@@ -1165,20 +1265,20 @@
11651265
11661266 adv7511_packet_disable(adv7511, 0xffff);
11671267
1168
- adv7511->i2c_edid = i2c_new_secondary_device(i2c, "edid",
1268
+ adv7511->i2c_edid = i2c_new_ancillary_device(i2c, "edid",
11691269 ADV7511_EDID_I2C_ADDR_DEFAULT);
1170
- if (!adv7511->i2c_edid) {
1171
- ret = -EINVAL;
1270
+ if (IS_ERR(adv7511->i2c_edid)) {
1271
+ ret = PTR_ERR(adv7511->i2c_edid);
11721272 goto uninit_regulators;
11731273 }
11741274
11751275 regmap_write(adv7511->regmap, ADV7511_REG_EDID_I2C_ADDR,
11761276 adv7511->i2c_edid->addr << 1);
11771277
1178
- adv7511->i2c_packet = i2c_new_secondary_device(i2c, "packet",
1278
+ adv7511->i2c_packet = i2c_new_ancillary_device(i2c, "packet",
11791279 ADV7511_PACKET_I2C_ADDR_DEFAULT);
1180
- if (!adv7511->i2c_packet) {
1181
- ret = -EINVAL;
1280
+ if (IS_ERR(adv7511->i2c_packet)) {
1281
+ ret = PTR_ERR(adv7511->i2c_packet);
11821282 goto err_i2c_unregister_edid;
11831283 }
11841284
....@@ -1188,9 +1288,6 @@
11881288 ret = adv7511_init_cec_regmap(adv7511);
11891289 if (ret)
11901290 goto err_i2c_unregister_packet;
1191
-
1192
- regmap_write(adv7511->regmap, ADV7511_REG_CEC_I2C_ADDR,
1193
- adv7511->i2c_cec->addr << 1);
11941291
11951292 INIT_WORK(&adv7511->hpd_work, adv7511_hpd_work);
11961293
....@@ -1217,7 +1314,10 @@
12171314 goto err_unregister_cec;
12181315
12191316 adv7511->bridge.funcs = &adv7511_bridge_funcs;
1317
+ adv7511->bridge.ops = DRM_BRIDGE_OP_DETECT | DRM_BRIDGE_OP_EDID
1318
+ | DRM_BRIDGE_OP_HPD;
12201319 adv7511->bridge.of_node = dev->of_node;
1320
+ adv7511->bridge.type = DRM_MODE_CONNECTOR_HDMIA;
12211321
12221322 drm_bridge_add(&adv7511->bridge);
12231323
....@@ -1225,6 +1325,7 @@
12251325 return 0;
12261326
12271327 err_unregister_cec:
1328
+ cec_unregister_adapter(adv7511->cec_adap);
12281329 i2c_unregister_device(adv7511->i2c_cec);
12291330 if (adv7511->cec_clk)
12301331 clk_disable_unprepare(adv7511->cec_clk);
....@@ -1242,7 +1343,7 @@
12421343 {
12431344 struct adv7511 *adv7511 = i2c_get_clientdata(i2c);
12441345
1245
- if (adv7511->type == ADV7533)
1346
+ if (adv7511->type == ADV7533 || adv7511->type == ADV7535)
12461347 adv7533_detach_dsi(adv7511);
12471348 i2c_unregister_device(adv7511->i2c_cec);
12481349 if (adv7511->cec_clk)
....@@ -1266,9 +1367,8 @@
12661367 { "adv7511", ADV7511 },
12671368 { "adv7511w", ADV7511 },
12681369 { "adv7513", ADV7511 },
1269
-#ifdef CONFIG_DRM_I2C_ADV7533
12701370 { "adv7533", ADV7533 },
1271
-#endif
1371
+ { "adv7535", ADV7535 },
12721372 { }
12731373 };
12741374 MODULE_DEVICE_TABLE(i2c, adv7511_i2c_ids);
....@@ -1277,9 +1377,8 @@
12771377 { .compatible = "adi,adv7511", .data = (void *)ADV7511 },
12781378 { .compatible = "adi,adv7511w", .data = (void *)ADV7511 },
12791379 { .compatible = "adi,adv7513", .data = (void *)ADV7511 },
1280
-#ifdef CONFIG_DRM_I2C_ADV7533
12811380 { .compatible = "adi,adv7533", .data = (void *)ADV7533 },
1282
-#endif
1381
+ { .compatible = "adi,adv7535", .data = (void *)ADV7535 },
12831382 { }
12841383 };
12851384 MODULE_DEVICE_TABLE(of, adv7511_of_ids);
....@@ -1300,10 +1399,21 @@
13001399
13011400 static int __init adv7511_init(void)
13021401 {
1303
- if (IS_ENABLED(CONFIG_DRM_MIPI_DSI))
1304
- mipi_dsi_driver_register(&adv7533_dsi_driver);
1402
+ int ret;
13051403
1306
- return i2c_add_driver(&adv7511_driver);
1404
+ if (IS_ENABLED(CONFIG_DRM_MIPI_DSI)) {
1405
+ ret = mipi_dsi_driver_register(&adv7533_dsi_driver);
1406
+ if (ret)
1407
+ return ret;
1408
+ }
1409
+
1410
+ ret = i2c_add_driver(&adv7511_driver);
1411
+ if (ret) {
1412
+ if (IS_ENABLED(CONFIG_DRM_MIPI_DSI))
1413
+ mipi_dsi_driver_unregister(&adv7533_dsi_driver);
1414
+ }
1415
+
1416
+ return ret;
13071417 }
13081418 module_init(adv7511_init);
13091419