Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

phy: mediatek: tphy: add support force phy mode switch

this is used to be compatible with old SoCs, such as mt8195, which shares
t-phy between usb3 and pcie controller, usually, it's default mode is pcie
rc mode, and could use force mode to switch into usb3 mode, because pericfg
layer doesn't provide mode switch, also no efuse or jumper can be used;
Currently, only support switch from default pcie mode to usb3;
Note: don't use this way on new SoCs, use pericfg layer's mode switch
instead (by perperty "mediatek,syscon-type").

Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
Link: https://lore.kernel.org/r/20231211025624.28991-2-chunfeng.yun@mediatek.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>

authored by

Chunfeng Yun and committed by
Vinod Koul
9b273030 cc230a4c

+25
+25
drivers/phy/mediatek/phy-mtk-tphy.c
··· 185 185 #define P3D_RG_CDR_BIR_LTD1 GENMASK(28, 24) 186 186 #define P3D_RG_CDR_BIR_LTD0 GENMASK(12, 8) 187 187 188 + #define U3P_U3_PHYD_TOP1 0x100 189 + #define P3D_RG_PHY_MODE GENMASK(2, 1) 190 + #define P3D_RG_FORCE_PHY_MODE BIT(0) 191 + 188 192 #define U3P_U3_PHYD_RXDET1 0x128 189 193 #define P3D_RG_RXDET_STB2_SET GENMASK(17, 9) 190 194 ··· 331 327 int discth; 332 328 int pre_emphasis; 333 329 bool bc12_en; 330 + bool type_force_mode; 334 331 }; 335 332 336 333 struct mtk_tphy { ··· 773 768 void __iomem *phya = u3_banks->phya; 774 769 void __iomem *phyd = u3_banks->phyd; 775 770 771 + if (instance->type_force_mode) { 772 + /* force phy as usb mode, default is pcie rc mode */ 773 + mtk_phy_update_field(phyd + U3P_U3_PHYD_TOP1, P3D_RG_PHY_MODE, 1); 774 + mtk_phy_set_bits(phyd + U3P_U3_PHYD_TOP1, P3D_RG_FORCE_PHY_MODE); 775 + /* power down phy by ip and pipe reset */ 776 + mtk_phy_set_bits(u3_banks->chip + U3P_U3_CHIP_GPIO_CTLD, 777 + P3C_FORCE_IP_SW_RST | P3C_MCU_BUS_CK_GATE_EN); 778 + mtk_phy_set_bits(u3_banks->chip + U3P_U3_CHIP_GPIO_CTLE, 779 + P3C_RG_SWRST_U3_PHYD | P3C_RG_SWRST_U3_PHYD_FORCE_EN); 780 + udelay(10); 781 + /* power on phy again */ 782 + mtk_phy_clear_bits(u3_banks->chip + U3P_U3_CHIP_GPIO_CTLD, 783 + P3C_FORCE_IP_SW_RST | P3C_MCU_BUS_CK_GATE_EN); 784 + mtk_phy_clear_bits(u3_banks->chip + U3P_U3_CHIP_GPIO_CTLE, 785 + P3C_RG_SWRST_U3_PHYD | P3C_RG_SWRST_U3_PHYD_FORCE_EN); 786 + } 787 + 776 788 /* gating PCIe Analog XTAL clock */ 777 789 mtk_phy_set_bits(u3_banks->spllc + U3P_SPLLC_XTALCTL3, 778 790 XC3_RG_U3_XTAL_RX_PWD | XC3_RG_U3_FRC_XTAL_RX_PWD); ··· 1141 1119 struct mtk_phy_instance *instance) 1142 1120 { 1143 1121 struct device *dev = &instance->phy->dev; 1122 + 1123 + if (instance->type == PHY_TYPE_USB3) 1124 + instance->type_force_mode = device_property_read_bool(dev, "mediatek,force-mode"); 1144 1125 1145 1126 if (instance->type != PHY_TYPE_USB2) 1146 1127 return;