Skip to content

Commit 5954a10

Browse files
Chunfeng Yunkishon
authored andcommitted
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>
1 parent 30dbc04 commit 5954a10

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,11 @@
9696

9797
#define U3P_U2PHYDTM1 0x06C
9898
#define P2C_RG_UART_EN BIT(16)
99+
#define P2C_FORCE_IDDIG BIT(9)
99100
#define P2C_RG_VBUSVALID BIT(5)
100101
#define P2C_RG_SESSEND BIT(4)
101102
#define P2C_RG_AVALID BIT(2)
103+
#define P2C_RG_IDDIG BIT(1)
102104

103105
#define U3P_U3_CHIP_GPIO_CTLD 0x0c
104106
#define P3C_REG_IP_SW_RST BIT(31)
@@ -585,6 +587,31 @@ static void u2_phy_instance_exit(struct mtk_tphy *tphy,
585587
}
586588
}
587589

590+
static void u2_phy_instance_set_mode(struct mtk_tphy *tphy,
591+
struct mtk_phy_instance *instance,
592+
enum phy_mode mode)
593+
{
594+
struct u2phy_banks *u2_banks = &instance->u2_banks;
595+
u32 tmp;
596+
597+
tmp = readl(u2_banks->com + U3P_U2PHYDTM1);
598+
switch (mode) {
599+
case PHY_MODE_USB_DEVICE:
600+
tmp |= P2C_FORCE_IDDIG | P2C_RG_IDDIG;
601+
break;
602+
case PHY_MODE_USB_HOST:
603+
tmp |= P2C_FORCE_IDDIG;
604+
tmp &= ~P2C_RG_IDDIG;
605+
break;
606+
case PHY_MODE_USB_OTG:
607+
tmp &= ~(P2C_FORCE_IDDIG | P2C_RG_IDDIG);
608+
break;
609+
default:
610+
return;
611+
}
612+
writel(tmp, u2_banks->com + U3P_U2PHYDTM1);
613+
}
614+
588615
static void pcie_phy_instance_init(struct mtk_tphy *tphy,
589616
struct mtk_phy_instance *instance)
590617
{
@@ -881,6 +908,17 @@ static int mtk_phy_exit(struct phy *phy)
881908
return 0;
882909
}
883910

911+
static int mtk_phy_set_mode(struct phy *phy, enum phy_mode mode)
912+
{
913+
struct mtk_phy_instance *instance = phy_get_drvdata(phy);
914+
struct mtk_tphy *tphy = dev_get_drvdata(phy->dev.parent);
915+
916+
if (instance->type == PHY_TYPE_USB2)
917+
u2_phy_instance_set_mode(tphy, instance, mode);
918+
919+
return 0;
920+
}
921+
884922
static struct phy *mtk_phy_xlate(struct device *dev,
885923
struct of_phandle_args *args)
886924
{
@@ -931,6 +969,7 @@ static const struct phy_ops mtk_tphy_ops = {
931969
.exit = mtk_phy_exit,
932970
.power_on = mtk_phy_power_on,
933971
.power_off = mtk_phy_power_off,
972+
.set_mode = mtk_phy_set_mode,
934973
.owner = THIS_MODULE,
935974
};
936975

0 commit comments

Comments
 (0)