developer | 8cdcb26 | 2022-10-27 14:36:15 +0800 | [diff] [blame] | 1 | From 355e7f114a47819c3c6545a97ad308d627da5d1a Mon Sep 17 00:00:00 2001 |
developer | 44e1bbf | 2022-01-28 17:20:00 +0800 | [diff] [blame] | 2 | From: Zhanyong Wang <zhanyong.wang@mediatek.com> |
| 3 | Date: Tue, 25 Jan 2022 19:03:34 +0800 |
developer | 8cdcb26 | 2022-10-27 14:36:15 +0800 | [diff] [blame] | 4 | Subject: [PATCH 4/8] phy: phy-mtk-tphy: add auto-load-valid check mechanism |
developer | 44e1bbf | 2022-01-28 17:20:00 +0800 | [diff] [blame] | 5 | support |
| 6 | |
| 7 | add auto-load-valid check mechanism support |
| 8 | |
| 9 | Signed-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 | |
| 14 | diff --git a/drivers/phy/mediatek/phy-mtk-tphy.c b/drivers/phy/mediatek/phy-mtk-tphy.c |
developer | 8cdcb26 | 2022-10-27 14:36:15 +0800 | [diff] [blame] | 15 | index b855e759b0da..a5b17a1aed5c 100644 |
developer | 44e1bbf | 2022-01-28 17:20:00 +0800 | [diff] [blame] | 16 | --- a/drivers/phy/mediatek/phy-mtk-tphy.c |
| 17 | +++ b/drivers/phy/mediatek/phy-mtk-tphy.c |
developer | 8cdcb26 | 2022-10-27 14:36:15 +0800 | [diff] [blame] | 18 | @@ -354,9 +354,13 @@ struct mtk_phy_instance { |
developer | 44e1bbf | 2022-01-28 17:20:00 +0800 | [diff] [blame] | 19 | }; |
| 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; |
developer | 8cdcb26 | 2022-10-27 14:36:15 +0800 | [diff] [blame] | 32 | @@ -1050,6 +1054,7 @@ static int phy_efuse_get(struct mtk_tphy *tphy, struct mtk_phy_instance *instanc |
developer | 44e1bbf | 2022-01-28 17:20:00 +0800 | [diff] [blame] | 33 | { |
| 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 | |
developer | 8cdcb26 | 2022-10-27 14:36:15 +0800 | [diff] [blame] | 40 | @@ -1068,6 +1073,20 @@ static int phy_efuse_get(struct mtk_tphy *tphy, struct mtk_phy_instance *instanc |
developer | 44e1bbf | 2022-01-28 17:20:00 +0800 | [diff] [blame] | 41 | |
| 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); |
developer | 8cdcb26 | 2022-10-27 14:36:15 +0800 | [diff] [blame] | 61 | @@ -1085,6 +1104,20 @@ static int phy_efuse_get(struct mtk_tphy *tphy, struct mtk_phy_instance *instanc |
developer | 44e1bbf | 2022-01-28 17:20:00 +0800 | [diff] [blame] | 62 | 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); |
developer | 8cdcb26 | 2022-10-27 14:36:15 +0800 | [diff] [blame] | 82 | @@ -1119,6 +1152,20 @@ static int phy_efuse_get(struct mtk_tphy *tphy, struct mtk_phy_instance *instanc |
developer | 44e1bbf | 2022-01-28 17:20:00 +0800 | [diff] [blame] | 83 | 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); |
developer | 8cdcb26 | 2022-10-27 14:36:15 +0800 | [diff] [blame] | 103 | @@ -1170,6 +1217,10 @@ static void phy_efuse_set(struct mtk_phy_instance *instance) |
developer | 44e1bbf | 2022-01-28 17:20:00 +0800 | [diff] [blame] | 104 | |
| 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); |
developer | 8cdcb26 | 2022-10-27 14:36:15 +0800 | [diff] [blame] | 114 | @@ -1182,6 +1233,10 @@ static void phy_efuse_set(struct mtk_phy_instance *instance) |
developer | 44e1bbf | 2022-01-28 17:20:00 +0800 | [diff] [blame] | 115 | |
| 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); |
developer | 8cdcb26 | 2022-10-27 14:36:15 +0800 | [diff] [blame] | 125 | @@ -1208,6 +1263,10 @@ static void phy_efuse_set(struct mtk_phy_instance *instance) |
developer | 44e1bbf | 2022-01-28 17:20:00 +0800 | [diff] [blame] | 126 | |
| 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); |
developer | 8cdcb26 | 2022-10-27 14:36:15 +0800 | [diff] [blame] | 136 | @@ -1232,9 +1291,11 @@ static void phy_efuse_set(struct mtk_phy_instance *instance) |
developer | 44e1bbf | 2022-01-28 17:20:00 +0800 | [diff] [blame] | 137 | __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 | -- |
| 152 | 2.18.0 |
| 153 | |