hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
kernel/drivers/gpu/drm/bridge/analogix/analogix-anx78xx.c
....@@ -1,39 +1,30 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright(c) 2016, Analogix Semiconductor.
34 *
4
- * This program is free software; you can redistribute it and/or modify
5
- * it under the terms of the GNU General Public License version 2 and
6
- * only version 2 as published by the Free Software Foundation.
7
- *
8
- * This program is distributed in the hope that it will be useful,
9
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
- * GNU General Public License for more details.
12
- *
135 * Based on anx7808 driver obtained from chromeos with copyright:
146 * Copyright(c) 2013, Google Inc.
15
- *
167 */
178 #include <linux/delay.h>
189 #include <linux/err.h>
19
-#include <linux/interrupt.h>
10
+#include <linux/gpio/consumer.h>
2011 #include <linux/i2c.h>
12
+#include <linux/interrupt.h>
2113 #include <linux/kernel.h>
2214 #include <linux/module.h>
23
-#include <linux/of_gpio.h>
2415 #include <linux/of_irq.h>
2516 #include <linux/of_platform.h>
2617 #include <linux/regmap.h>
27
-#include <linux/types.h>
28
-#include <linux/gpio/consumer.h>
2918 #include <linux/regulator/consumer.h>
19
+#include <linux/types.h>
3020
31
-#include <drm/drmP.h>
3221 #include <drm/drm_atomic_helper.h>
22
+#include <drm/drm_bridge.h>
3323 #include <drm/drm_crtc.h>
34
-#include <drm/drm_crtc_helper.h>
3524 #include <drm/drm_dp_helper.h>
3625 #include <drm/drm_edid.h>
26
+#include <drm/drm_print.h>
27
+#include <drm/drm_probe_helper.h>
3728
3829 #include "analogix-anx78xx.h"
3930
....@@ -46,12 +37,20 @@
4637
4738 #define XTAL_CLK 270 /* 27M */
4839
49
-static const u8 anx78xx_i2c_addresses[] = {
50
- [I2C_IDX_TX_P0] = TX_P0,
51
- [I2C_IDX_TX_P1] = TX_P1,
52
- [I2C_IDX_TX_P2] = TX_P2,
53
- [I2C_IDX_RX_P0] = RX_P0,
54
- [I2C_IDX_RX_P1] = RX_P1,
40
+static const u8 anx7808_i2c_addresses[] = {
41
+ [I2C_IDX_TX_P0] = 0x78,
42
+ [I2C_IDX_TX_P1] = 0x7a,
43
+ [I2C_IDX_TX_P2] = 0x72,
44
+ [I2C_IDX_RX_P0] = 0x7e,
45
+ [I2C_IDX_RX_P1] = 0x80,
46
+};
47
+
48
+static const u8 anx781x_i2c_addresses[] = {
49
+ [I2C_IDX_TX_P0] = 0x70,
50
+ [I2C_IDX_TX_P1] = 0x7a,
51
+ [I2C_IDX_TX_P2] = 0x72,
52
+ [I2C_IDX_RX_P0] = 0x7e,
53
+ [I2C_IDX_RX_P1] = 0x80,
5554 };
5655
5756 struct anx78xx_platform_data {
....@@ -70,7 +69,6 @@
7069 struct i2c_client *client;
7170 struct edid *edid;
7271 struct drm_connector connector;
73
- struct drm_dp_link link;
7472 struct anx78xx_platform_data pdata;
7573 struct mutex lock;
7674
....@@ -111,7 +109,7 @@
111109 struct drm_dp_aux_msg *msg)
112110 {
113111 struct anx78xx *anx78xx = container_of(aux, struct anx78xx, aux);
114
- return anx_aux_transfer(anx78xx->map[I2C_IDX_TX_P0], msg);
112
+ return anx_dp_aux_transfer(anx78xx->map[I2C_IDX_TX_P0], msg);
115113 }
116114
117115 static int anx78xx_set_hpd(struct anx78xx *anx78xx)
....@@ -581,7 +579,9 @@
581579 /* 1.0V digital core power regulator */
582580 pdata->dvdd10 = devm_regulator_get(dev, "dvdd10");
583581 if (IS_ERR(pdata->dvdd10)) {
584
- DRM_ERROR("DVDD10 regulator not found\n");
582
+ if (PTR_ERR(pdata->dvdd10) != -EPROBE_DEFER)
583
+ DRM_ERROR("DVDD10 regulator not found\n");
584
+
585585 return PTR_ERR(pdata->dvdd10);
586586 }
587587
....@@ -603,7 +603,7 @@
603603
604604 static int anx78xx_dp_link_training(struct anx78xx *anx78xx)
605605 {
606
- u8 dp_bw, value;
606
+ u8 dp_bw, dpcd[2];
607607 int err;
608608
609609 err = regmap_write(anx78xx->map[I2C_IDX_RX_P0], SP_HDMI_MUTE_CTRL_REG,
....@@ -656,18 +656,34 @@
656656 if (err)
657657 return err;
658658
659
- /* Check link capabilities */
660
- err = drm_dp_link_probe(&anx78xx->aux, &anx78xx->link);
661
- if (err < 0) {
662
- DRM_ERROR("Failed to probe link capabilities: %d\n", err);
663
- return err;
664
- }
659
+ /*
660
+ * Power up the sink (DP_SET_POWER register is only available on DPCD
661
+ * v1.1 and later).
662
+ */
663
+ if (anx78xx->dpcd[DP_DPCD_REV] >= 0x11) {
664
+ err = drm_dp_dpcd_readb(&anx78xx->aux, DP_SET_POWER, &dpcd[0]);
665
+ if (err < 0) {
666
+ DRM_ERROR("Failed to read DP_SET_POWER register: %d\n",
667
+ err);
668
+ return err;
669
+ }
665670
666
- /* Power up the sink */
667
- err = drm_dp_link_power_up(&anx78xx->aux, &anx78xx->link);
668
- if (err < 0) {
669
- DRM_ERROR("Failed to power up DisplayPort link: %d\n", err);
670
- return err;
671
+ dpcd[0] &= ~DP_SET_POWER_MASK;
672
+ dpcd[0] |= DP_SET_POWER_D0;
673
+
674
+ err = drm_dp_dpcd_writeb(&anx78xx->aux, DP_SET_POWER, dpcd[0]);
675
+ if (err < 0) {
676
+ DRM_ERROR("Failed to power up DisplayPort link: %d\n",
677
+ err);
678
+ return err;
679
+ }
680
+
681
+ /*
682
+ * According to the DP 1.1 specification, a "Sink Device must
683
+ * exit the power saving state within 1 ms" (Section 2.5.3.1,
684
+ * Table 5-52, "Sink Control Field" (register 0x600).
685
+ */
686
+ usleep_range(1000, 2000);
671687 }
672688
673689 /* Possibly enable downspread on the sink */
....@@ -706,15 +722,21 @@
706722 if (err)
707723 return err;
708724
709
- value = drm_dp_link_rate_to_bw_code(anx78xx->link.rate);
710725 err = regmap_write(anx78xx->map[I2C_IDX_TX_P0],
711
- SP_DP_MAIN_LINK_BW_SET_REG, value);
726
+ SP_DP_MAIN_LINK_BW_SET_REG,
727
+ anx78xx->dpcd[DP_MAX_LINK_RATE]);
712728 if (err)
713729 return err;
714730
715
- err = drm_dp_link_configure(&anx78xx->aux, &anx78xx->link);
731
+ dpcd[1] = drm_dp_max_lane_count(anx78xx->dpcd);
732
+
733
+ if (drm_dp_enhanced_frame_cap(anx78xx->dpcd))
734
+ dpcd[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN;
735
+
736
+ err = drm_dp_dpcd_write(&anx78xx->aux, DP_LINK_BW_SET, dpcd,
737
+ sizeof(dpcd));
716738 if (err < 0) {
717
- DRM_ERROR("Failed to configure DisplayPort link: %d\n", err);
739
+ DRM_ERROR("Failed to configure link: %d\n", err);
718740 return err;
719741 }
720742
....@@ -825,16 +847,14 @@
825847 goto unlock;
826848 }
827849
828
- err = drm_mode_connector_update_edid_property(connector,
829
- anx78xx->edid);
850
+ err = drm_connector_update_edid_property(connector,
851
+ anx78xx->edid);
830852 if (err) {
831853 DRM_ERROR("Failed to update EDID property: %d\n", err);
832854 goto unlock;
833855 }
834856
835857 num_modes = drm_add_edid_modes(connector, anx78xx->edid);
836
- /* Store the ELD */
837
- drm_edid_to_eld(connector, anx78xx->edid);
838858
839859 unlock:
840860 mutex_unlock(&anx78xx->lock);
....@@ -857,25 +877,25 @@
857877 return connector_status_connected;
858878 }
859879
860
-static void anx78xx_connector_destroy(struct drm_connector *connector)
861
-{
862
- drm_connector_cleanup(connector);
863
-}
864
-
865880 static const struct drm_connector_funcs anx78xx_connector_funcs = {
866
- .dpms = drm_atomic_helper_connector_dpms,
867881 .fill_modes = drm_helper_probe_single_connector_modes,
868882 .detect = anx78xx_detect,
869
- .destroy = anx78xx_connector_destroy,
883
+ .destroy = drm_connector_cleanup,
870884 .reset = drm_atomic_helper_connector_reset,
871885 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
872886 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
873887 };
874888
875
-static int anx78xx_bridge_attach(struct drm_bridge *bridge)
889
+static int anx78xx_bridge_attach(struct drm_bridge *bridge,
890
+ enum drm_bridge_attach_flags flags)
876891 {
877892 struct anx78xx *anx78xx = bridge_to_anx78xx(bridge);
878893 int err;
894
+
895
+ if (flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR) {
896
+ DRM_ERROR("Fix bridge driver to make connector optional!");
897
+ return -EINVAL;
898
+ }
879899
880900 if (!bridge->encoder) {
881901 DRM_ERROR("Parent encoder object not found");
....@@ -912,8 +932,8 @@
912932
913933 anx78xx->connector.polled = DRM_CONNECTOR_POLL_HPD;
914934
915
- err = drm_mode_connector_attach_encoder(&anx78xx->connector,
916
- bridge->encoder);
935
+ err = drm_connector_attach_encoder(&anx78xx->connector,
936
+ bridge->encoder);
917937 if (err) {
918938 DRM_ERROR("Failed to link up connector to encoder: %d\n", err);
919939 return err;
....@@ -924,6 +944,7 @@
924944
925945 static enum drm_mode_status
926946 anx78xx_bridge_mode_valid(struct drm_bridge *bridge,
947
+ const struct drm_display_info *info,
927948 const struct drm_display_mode *mode)
928949 {
929950 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
....@@ -946,8 +967,8 @@
946967 }
947968
948969 static void anx78xx_bridge_mode_set(struct drm_bridge *bridge,
949
- struct drm_display_mode *mode,
950
- struct drm_display_mode *adjusted_mode)
970
+ const struct drm_display_mode *mode,
971
+ const struct drm_display_mode *adjusted_mode)
951972 {
952973 struct anx78xx *anx78xx = bridge_to_anx78xx(bridge);
953974 struct hdmi_avi_infoframe frame;
....@@ -958,7 +979,9 @@
958979
959980 mutex_lock(&anx78xx->lock);
960981
961
- err = drm_hdmi_avi_infoframe_from_display_mode(&frame, adjusted_mode);
982
+ err = drm_hdmi_avi_infoframe_from_display_mode(&frame,
983
+ &anx78xx->connector,
984
+ adjusted_mode);
962985 if (err) {
963986 DRM_ERROR("Failed to setup AVI infoframe: %d\n", err);
964987 goto unlock;
....@@ -1173,6 +1196,7 @@
11731196 };
11741197
11751198 static const u16 anx78xx_chipid_list[] = {
1199
+ 0x7808,
11761200 0x7812,
11771201 0x7814,
11781202 0x7818,
....@@ -1184,6 +1208,7 @@
11841208 struct anx78xx *anx78xx;
11851209 struct anx78xx_platform_data *pdata;
11861210 unsigned int i, idl, idh, version;
1211
+ const u8 *i2c_addresses;
11871212 bool found = false;
11881213 int err;
11891214
....@@ -1204,7 +1229,9 @@
12041229
12051230 err = anx78xx_init_pdata(anx78xx);
12061231 if (err) {
1207
- DRM_ERROR("Failed to initialize pdata: %d\n", err);
1232
+ if (err != -EPROBE_DEFER)
1233
+ DRM_ERROR("Failed to initialize pdata: %d\n", err);
1234
+
12081235 return err;
12091236 }
12101237
....@@ -1221,22 +1248,26 @@
12211248 }
12221249
12231250 /* Map slave addresses of ANX7814 */
1251
+ i2c_addresses = device_get_match_data(&client->dev);
12241252 for (i = 0; i < I2C_NUM_ADDRESSES; i++) {
1225
- anx78xx->i2c_dummy[i] = i2c_new_dummy(client->adapter,
1226
- anx78xx_i2c_addresses[i] >> 1);
1227
- if (!anx78xx->i2c_dummy[i]) {
1228
- err = -ENOMEM;
1229
- DRM_ERROR("Failed to reserve I2C bus %02x\n",
1230
- anx78xx_i2c_addresses[i]);
1253
+ struct i2c_client *i2c_dummy;
1254
+
1255
+ i2c_dummy = i2c_new_dummy_device(client->adapter,
1256
+ i2c_addresses[i] >> 1);
1257
+ if (IS_ERR(i2c_dummy)) {
1258
+ err = PTR_ERR(i2c_dummy);
1259
+ DRM_ERROR("Failed to reserve I2C bus %02x: %d\n",
1260
+ i2c_addresses[i], err);
12311261 goto err_unregister_i2c;
12321262 }
12331263
1264
+ anx78xx->i2c_dummy[i] = i2c_dummy;
12341265 anx78xx->map[i] = devm_regmap_init_i2c(anx78xx->i2c_dummy[i],
12351266 &anx78xx_regmap_config);
12361267 if (IS_ERR(anx78xx->map[i])) {
12371268 err = PTR_ERR(anx78xx->map[i]);
12381269 DRM_ERROR("Failed regmap initialization %02x\n",
1239
- anx78xx_i2c_addresses[i]);
1270
+ i2c_addresses[i]);
12401271 goto err_unregister_i2c;
12411272 }
12421273 }
....@@ -1335,7 +1366,10 @@
13351366
13361367 #if IS_ENABLED(CONFIG_OF)
13371368 static const struct of_device_id anx78xx_match_table[] = {
1338
- { .compatible = "analogix,anx7814", },
1369
+ { .compatible = "analogix,anx7808", .data = anx7808_i2c_addresses },
1370
+ { .compatible = "analogix,anx7812", .data = anx781x_i2c_addresses },
1371
+ { .compatible = "analogix,anx7814", .data = anx781x_i2c_addresses },
1372
+ { .compatible = "analogix,anx7818", .data = anx781x_i2c_addresses },
13391373 { /* sentinel */ },
13401374 };
13411375 MODULE_DEVICE_TABLE(of, anx78xx_match_table);