blob: e84ca6cc1fd3c81210caca530be3b2b569c40ad5 [file] [log] [blame]
developer8cdcb262022-10-27 14:36:15 +08001From 355e7f114a47819c3c6545a97ad308d627da5d1a Mon Sep 17 00:00:00 2001
developer44e1bbf2022-01-28 17:20:00 +08002From: Zhanyong Wang <zhanyong.wang@mediatek.com>
3Date: Tue, 25 Jan 2022 19:03:34 +0800
developer8cdcb262022-10-27 14:36:15 +08004Subject: [PATCH 4/8] phy: phy-mtk-tphy: add auto-load-valid check mechanism
developer44e1bbf2022-01-28 17:20:00 +08005 support
6
7add auto-load-valid check mechanism support
8
9Signed-off-by: Zhanyong Wang <zhanyong.wang@mediatek.com>
10---
11 drivers/phy/mediatek/phy-mtk-tphy.c | 67 +++++++++++++++++++++++++++--
12 1 file changed, 64 insertions(+), 3 deletions(-)
13
14diff --git a/drivers/phy/mediatek/phy-mtk-tphy.c b/drivers/phy/mediatek/phy-mtk-tphy.c
developer8cdcb262022-10-27 14:36:15 +080015index b855e759b0da..a5b17a1aed5c 100644
developer44e1bbf2022-01-28 17:20:00 +080016--- a/drivers/phy/mediatek/phy-mtk-tphy.c
17+++ b/drivers/phy/mediatek/phy-mtk-tphy.c
developer8cdcb262022-10-27 14:36:15 +080018@@ -354,9 +354,13 @@ struct mtk_phy_instance {
developer44e1bbf2022-01-28 17:20:00 +080019 };
20 struct clk *ref_clk; /* reference clock of anolog phy */
21 u32 efuse_sw_en;
22+ bool efuse_alv_en;
23+ u32 efuse_autoloadvalid;
24 u32 efuse_intr;
25 u32 efuse_tx_imp;
26 u32 efuse_rx_imp;
27+ bool efuse_alv_ln1_en;
28+ u32 efuse_ln1_autoloadvalid;
29 u32 efuse_intr_ln1;
30 u32 efuse_tx_imp_ln1;
31 u32 efuse_rx_imp_ln1;
developer8cdcb262022-10-27 14:36:15 +080032@@ -1050,6 +1054,7 @@ static int phy_efuse_get(struct mtk_tphy *tphy, struct mtk_phy_instance *instanc
developer44e1bbf2022-01-28 17:20:00 +080033 {
34 struct device *dev = &instance->phy->dev;
35 int ret = 0;
36+ bool alv = false;
37
38 dev_err(dev, "try to get sw efuse\n");
39
developer8cdcb262022-10-27 14:36:15 +080040@@ -1068,6 +1073,20 @@ static int phy_efuse_get(struct mtk_tphy *tphy, struct mtk_phy_instance *instanc
developer44e1bbf2022-01-28 17:20:00 +080041
42 switch (instance->type) {
43 case PHY_TYPE_USB2:
44+ alv = of_property_read_bool(dev->of_node, "auto_load_valid");
45+ if (alv) {
46+ instance->efuse_alv_en = alv;
47+ ret = nvmem_cell_read_variable_le_u32(dev, "auto_load_valid",
48+ &instance->efuse_autoloadvalid);
49+ if (ret) {
50+ dev_err(dev, "fail to get u2 alv efuse, %d\n", ret);
51+ break;
52+ }
53+ dev_info(dev,
54+ "u2 auto load valid efuse: ENABLE with value: %u\n",
55+ instance->efuse_autoloadvalid);
56+ }
57+
58 ret = nvmem_cell_read_variable_le_u32(dev, "intr", &instance->efuse_intr);
59 if (ret) {
60 dev_err(dev, "fail to get u2 intr efuse, %d\n", ret);
developer8cdcb262022-10-27 14:36:15 +080061@@ -1085,6 +1104,20 @@ static int phy_efuse_get(struct mtk_tphy *tphy, struct mtk_phy_instance *instanc
developer44e1bbf2022-01-28 17:20:00 +080062 break;
63 case PHY_TYPE_USB3:
64 case PHY_TYPE_PCIE:
65+ alv = of_property_read_bool(dev->of_node, "auto_load_valid");
66+ if (alv) {
67+ instance->efuse_alv_en = alv;
68+ ret = nvmem_cell_read_variable_le_u32(dev, "auto_load_valid",
69+ &instance->efuse_autoloadvalid);
70+ if (ret) {
71+ dev_err(dev, "fail to get u3(pcei) alv efuse, %d\n", ret);
72+ break;
73+ }
74+ dev_info(dev,
75+ "u3 auto load valid efuse: ENABLE with value: %u\n",
76+ instance->efuse_autoloadvalid);
77+ }
78+
79 ret = nvmem_cell_read_variable_le_u32(dev, "intr", &instance->efuse_intr);
80 if (ret) {
81 dev_err(dev, "fail to get u3 intr efuse, %d\n", ret);
developer8cdcb262022-10-27 14:36:15 +080082@@ -1119,6 +1152,20 @@ static int phy_efuse_get(struct mtk_tphy *tphy, struct mtk_phy_instance *instanc
developer44e1bbf2022-01-28 17:20:00 +080083 if (tphy->pdata->version != MTK_PHY_V4)
84 break;
85
86+ alv = of_property_read_bool(dev->of_node, "auto_load_valid_ln1");
87+ if (alv) {
88+ instance->efuse_alv_ln1_en = alv;
89+ ret = nvmem_cell_read_variable_le_u32(dev, "auto_load_valid_ln1",
90+ &instance->efuse_ln1_autoloadvalid);
91+ if (ret) {
92+ dev_err(dev, "fail to get pcie auto_load_valid efuse, %d\n", ret);
93+ break;
94+ }
95+ dev_info(dev,
96+ "pcie auto load valid efuse: ENABLE with value: %u\n",
97+ instance->efuse_ln1_autoloadvalid);
98+ }
99+
100 ret = nvmem_cell_read_variable_le_u32(dev, "intr_ln1", &instance->efuse_intr_ln1);
101 if (ret) {
102 dev_err(dev, "fail to get u3 lane1 intr efuse, %d\n", ret);
developer8cdcb262022-10-27 14:36:15 +0800103@@ -1170,6 +1217,10 @@ static void phy_efuse_set(struct mtk_phy_instance *instance)
developer44e1bbf2022-01-28 17:20:00 +0800104
105 switch (instance->type) {
106 case PHY_TYPE_USB2:
107+ if (instance->efuse_alv_en &&
108+ instance->efuse_autoloadvalid == 1)
109+ break;
110+
111 tmp = readl(u2_banks->misc + U3P_MISC_REG1);
112 tmp |= MR1_EFUSE_AUTO_LOAD_DIS;
113 writel(tmp, u2_banks->misc + U3P_MISC_REG1);
developer8cdcb262022-10-27 14:36:15 +0800114@@ -1182,6 +1233,10 @@ static void phy_efuse_set(struct mtk_phy_instance *instance)
developer44e1bbf2022-01-28 17:20:00 +0800115
116 break;
117 case PHY_TYPE_USB3:
118+ if (instance->efuse_alv_en &&
119+ instance->efuse_autoloadvalid == 1)
120+ break;
121+
122 tmp = readl(u3_banks->phyd + U3P_U3_PHYD_RSV);
123 tmp |= P3D_RG_EFUSE_AUTO_LOAD_DIS;
124 writel(tmp, u3_banks->phyd + U3P_U3_PHYD_RSV);
developer8cdcb262022-10-27 14:36:15 +0800125@@ -1208,6 +1263,10 @@ static void phy_efuse_set(struct mtk_phy_instance *instance)
developer44e1bbf2022-01-28 17:20:00 +0800126
127 break;
128 case PHY_TYPE_PCIE:
129+ if (instance->efuse_alv_en &&
130+ instance->efuse_autoloadvalid == 1)
131+ break;
132+
133 tmp = readl(u3_banks->phyd + U3P_U3_PHYD_RSV);
134 tmp |= P3D_RG_EFUSE_AUTO_LOAD_DIS;
135 writel(tmp, u3_banks->phyd + U3P_U3_PHYD_RSV);
developer8cdcb262022-10-27 14:36:15 +0800136@@ -1232,9 +1291,11 @@ static void phy_efuse_set(struct mtk_phy_instance *instance)
developer44e1bbf2022-01-28 17:20:00 +0800137 __func__, instance->efuse_tx_imp,
138 instance->efuse_rx_imp, instance->efuse_intr);
139
140- if (!instance->efuse_intr_ln1 &&
141- !instance->efuse_rx_imp_ln1 &&
142- !instance->efuse_tx_imp_ln1)
143+ if ((!instance->efuse_intr_ln1 &&
144+ !instance->efuse_rx_imp_ln1 &&
145+ !instance->efuse_tx_imp_ln1) ||
146+ (instance->efuse_alv_ln1_en &&
147+ instance->efuse_ln1_autoloadvalid == 1))
148 break;
149
150 tmp = readl(u3_banks->phyd + SSUSB_LN1_OFFSET + U3P_U3_PHYD_RSV);
151--
1522.18.0
153