Skip to content

Commit 9b27303

Browse files
Chunfeng Yunvinodkoul
authored andcommitted
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>
1 parent cc230a4 commit 9b27303

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

drivers/phy/mediatek/phy-mtk-tphy.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@
185185
#define P3D_RG_CDR_BIR_LTD1 GENMASK(28, 24)
186186
#define P3D_RG_CDR_BIR_LTD0 GENMASK(12, 8)
187187

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+
188192
#define U3P_U3_PHYD_RXDET1 0x128
189193
#define P3D_RG_RXDET_STB2_SET GENMASK(17, 9)
190194

@@ -327,6 +331,7 @@ struct mtk_phy_instance {
327331
int discth;
328332
int pre_emphasis;
329333
bool bc12_en;
334+
bool type_force_mode;
330335
};
331336

332337
struct mtk_tphy {
@@ -768,6 +773,23 @@ static void u3_phy_instance_init(struct mtk_tphy *tphy,
768773
void __iomem *phya = u3_banks->phya;
769774
void __iomem *phyd = u3_banks->phyd;
770775

776+
if (instance->type_force_mode) {
777+
/* force phy as usb mode, default is pcie rc mode */
778+
mtk_phy_update_field(phyd + U3P_U3_PHYD_TOP1, P3D_RG_PHY_MODE, 1);
779+
mtk_phy_set_bits(phyd + U3P_U3_PHYD_TOP1, P3D_RG_FORCE_PHY_MODE);
780+
/* power down phy by ip and pipe reset */
781+
mtk_phy_set_bits(u3_banks->chip + U3P_U3_CHIP_GPIO_CTLD,
782+
P3C_FORCE_IP_SW_RST | P3C_MCU_BUS_CK_GATE_EN);
783+
mtk_phy_set_bits(u3_banks->chip + U3P_U3_CHIP_GPIO_CTLE,
784+
P3C_RG_SWRST_U3_PHYD | P3C_RG_SWRST_U3_PHYD_FORCE_EN);
785+
udelay(10);
786+
/* power on phy again */
787+
mtk_phy_clear_bits(u3_banks->chip + U3P_U3_CHIP_GPIO_CTLD,
788+
P3C_FORCE_IP_SW_RST | P3C_MCU_BUS_CK_GATE_EN);
789+
mtk_phy_clear_bits(u3_banks->chip + U3P_U3_CHIP_GPIO_CTLE,
790+
P3C_RG_SWRST_U3_PHYD | P3C_RG_SWRST_U3_PHYD_FORCE_EN);
791+
}
792+
771793
/* gating PCIe Analog XTAL clock */
772794
mtk_phy_set_bits(u3_banks->spllc + U3P_SPLLC_XTALCTL3,
773795
XC3_RG_U3_XTAL_RX_PWD | XC3_RG_U3_FRC_XTAL_RX_PWD);
@@ -1120,6 +1142,9 @@ static void phy_parse_property(struct mtk_tphy *tphy,
11201142
{
11211143
struct device *dev = &instance->phy->dev;
11221144

1145+
if (instance->type == PHY_TYPE_USB3)
1146+
instance->type_force_mode = device_property_read_bool(dev, "mediatek,force-mode");
1147+
11231148
if (instance->type != PHY_TYPE_USB2)
11241149
return;
11251150

0 commit comments

Comments
 (0)