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

phy: phy-mtk-tphy: add set_mode callback

This is used to force PHY with USB OTG function to enter a specific
mode, and override OTG IDPIN(or IDDIG) signal.

Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>

authored by

Chunfeng Yun and committed by
Kishon Vijay Abraham I
5954a10e 30dbc041

+39
+39
drivers/phy/mediatek/phy-mtk-tphy.c
··· 96 96 97 97 #define U3P_U2PHYDTM1 0x06C 98 98 #define P2C_RG_UART_EN BIT(16) 99 + #define P2C_FORCE_IDDIG BIT(9) 99 100 #define P2C_RG_VBUSVALID BIT(5) 100 101 #define P2C_RG_SESSEND BIT(4) 101 102 #define P2C_RG_AVALID BIT(2) 103 + #define P2C_RG_IDDIG BIT(1) 102 104 103 105 #define U3P_U3_CHIP_GPIO_CTLD 0x0c 104 106 #define P3C_REG_IP_SW_RST BIT(31) ··· 587 585 } 588 586 } 589 587 588 + static void u2_phy_instance_set_mode(struct mtk_tphy *tphy, 589 + struct mtk_phy_instance *instance, 590 + enum phy_mode mode) 591 + { 592 + struct u2phy_banks *u2_banks = &instance->u2_banks; 593 + u32 tmp; 594 + 595 + tmp = readl(u2_banks->com + U3P_U2PHYDTM1); 596 + switch (mode) { 597 + case PHY_MODE_USB_DEVICE: 598 + tmp |= P2C_FORCE_IDDIG | P2C_RG_IDDIG; 599 + break; 600 + case PHY_MODE_USB_HOST: 601 + tmp |= P2C_FORCE_IDDIG; 602 + tmp &= ~P2C_RG_IDDIG; 603 + break; 604 + case PHY_MODE_USB_OTG: 605 + tmp &= ~(P2C_FORCE_IDDIG | P2C_RG_IDDIG); 606 + break; 607 + default: 608 + return; 609 + } 610 + writel(tmp, u2_banks->com + U3P_U2PHYDTM1); 611 + } 612 + 590 613 static void pcie_phy_instance_init(struct mtk_tphy *tphy, 591 614 struct mtk_phy_instance *instance) 592 615 { ··· 908 881 return 0; 909 882 } 910 883 884 + static int mtk_phy_set_mode(struct phy *phy, enum phy_mode mode) 885 + { 886 + struct mtk_phy_instance *instance = phy_get_drvdata(phy); 887 + struct mtk_tphy *tphy = dev_get_drvdata(phy->dev.parent); 888 + 889 + if (instance->type == PHY_TYPE_USB2) 890 + u2_phy_instance_set_mode(tphy, instance, mode); 891 + 892 + return 0; 893 + } 894 + 911 895 static struct phy *mtk_phy_xlate(struct device *dev, 912 896 struct of_phandle_args *args) 913 897 { ··· 969 931 .exit = mtk_phy_exit, 970 932 .power_on = mtk_phy_power_on, 971 933 .power_off = mtk_phy_power_off, 934 + .set_mode = mtk_phy_set_mode, 972 935 .owner = THIS_MODULE, 973 936 }; 974 937