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

Configure Feed

Select the types of activity you want to include in your feed.

phy: fsl-imx8mq-usb: add tca function driver for imx95

The i.MX95 USB3 phy has a Type-C Assist block (TCA). This block consists
two functional blocks (XBar assist and VBus assist) and one system
access interface using APB.

The primary functionality of XBar assist is:
- switching lane for flip
- moving unused lanes into lower power states.

This info can be get from:
i.MX95 RM Chapter 163.3.8 Type-C assist (TCA) block.

This will add support for TCA block to achieve lane switching and tca
lower power functionality.

Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
Reviewed-by: Jun Li <jun.li@nxp.com>
Link: https://lore.kernel.org/r/20241204050907.1081781-1-xu.yang_2@nxp.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>

authored by

Xu Yang and committed by
Vinod Koul
b58f0f86 d2317767

+241
+1
drivers/phy/freescale/Kconfig
··· 5 5 config PHY_FSL_IMX8MQ_USB 6 6 tristate "Freescale i.MX8M USB3 PHY" 7 7 depends on OF && HAS_IOMEM 8 + depends on TYPEC || TYPEC=n 8 9 select GENERIC_PHY 9 10 default ARCH_MXC && ARM64 10 11
+240
drivers/phy/freescale/phy-fsl-imx8mq-usb.c
··· 10 10 #include <linux/phy/phy.h> 11 11 #include <linux/platform_device.h> 12 12 #include <linux/regulator/consumer.h> 13 + #include <linux/usb/typec_mux.h> 13 14 14 15 #define PHY_CTRL0 0x0 15 16 #define PHY_CTRL0_REF_SSP_EN BIT(2) ··· 51 50 52 51 #define PHY_TUNE_DEFAULT 0xffffffff 53 52 53 + #define TCA_CLK_RST 0x00 54 + #define TCA_CLK_RST_SW BIT(9) 55 + #define TCA_CLK_RST_REF_CLK_EN BIT(1) 56 + #define TCA_CLK_RST_SUSPEND_CLK_EN BIT(0) 57 + 58 + #define TCA_INTR_EN 0x04 59 + #define TCA_INTR_STS 0x08 60 + 61 + #define TCA_GCFG 0x10 62 + #define TCA_GCFG_ROLE_HSTDEV BIT(4) 63 + #define TCA_GCFG_OP_MODE GENMASK(1, 0) 64 + #define TCA_GCFG_OP_MODE_SYSMODE 0 65 + #define TCA_GCFG_OP_MODE_SYNCMODE 1 66 + 67 + #define TCA_TCPC 0x14 68 + #define TCA_TCPC_VALID BIT(4) 69 + #define TCA_TCPC_LOW_POWER_EN BIT(3) 70 + #define TCA_TCPC_ORIENTATION_NORMAL BIT(2) 71 + #define TCA_TCPC_MUX_CONTRL GENMASK(1, 0) 72 + #define TCA_TCPC_MUX_CONTRL_NO_CONN 0 73 + #define TCA_TCPC_MUX_CONTRL_USB_CONN 1 74 + 75 + #define TCA_SYSMODE_CFG 0x18 76 + #define TCA_SYSMODE_TCPC_DISABLE BIT(3) 77 + #define TCA_SYSMODE_TCPC_FLIP BIT(2) 78 + 79 + #define TCA_CTRLSYNCMODE_CFG0 0x20 80 + #define TCA_CTRLSYNCMODE_CFG1 0x20 81 + 82 + #define TCA_PSTATE 0x30 83 + #define TCA_PSTATE_CM_STS BIT(4) 84 + #define TCA_PSTATE_TX_STS BIT(3) 85 + #define TCA_PSTATE_RX_PLL_STS BIT(2) 86 + #define TCA_PSTATE_PIPE0_POWER_DOWN GENMASK(1, 0) 87 + 88 + #define TCA_GEN_STATUS 0x34 89 + #define TCA_GEN_DEV_POR BIT(12) 90 + #define TCA_GEN_REF_CLK_SEL BIT(8) 91 + #define TCA_GEN_TYPEC_FLIP_INVERT BIT(4) 92 + #define TCA_GEN_PHY_TYPEC_DISABLE BIT(3) 93 + #define TCA_GEN_PHY_TYPEC_FLIP BIT(2) 94 + 95 + #define TCA_VBUS_CTRL 0x40 96 + #define TCA_VBUS_STATUS 0x44 97 + 98 + #define TCA_INFO 0xfc 99 + 100 + struct tca_blk { 101 + struct typec_switch_dev *sw; 102 + void __iomem *base; 103 + struct mutex mutex; 104 + enum typec_orientation orientation; 105 + }; 106 + 54 107 struct imx8mq_usb_phy { 55 108 struct phy *phy; 56 109 struct clk *clk; 57 110 void __iomem *base; 58 111 struct regulator *vbus; 112 + struct tca_blk *tca; 59 113 u32 pcs_tx_swing_full; 60 114 u32 pcs_tx_deemph_3p5db; 61 115 u32 tx_vref_tune; ··· 119 63 u32 tx_vboost_level; 120 64 u32 comp_dis_tune; 121 65 }; 66 + 67 + 68 + static void tca_blk_orientation_set(struct tca_blk *tca, 69 + enum typec_orientation orientation); 70 + 71 + #ifdef CONFIG_TYPEC 72 + 73 + static int tca_blk_typec_switch_set(struct typec_switch_dev *sw, 74 + enum typec_orientation orientation) 75 + { 76 + struct imx8mq_usb_phy *imx_phy = typec_switch_get_drvdata(sw); 77 + struct tca_blk *tca = imx_phy->tca; 78 + int ret; 79 + 80 + if (tca->orientation == orientation) 81 + return 0; 82 + 83 + ret = clk_prepare_enable(imx_phy->clk); 84 + if (ret) 85 + return ret; 86 + 87 + tca_blk_orientation_set(tca, orientation); 88 + clk_disable_unprepare(imx_phy->clk); 89 + 90 + return 0; 91 + } 92 + 93 + static struct typec_switch_dev *tca_blk_get_typec_switch(struct platform_device *pdev, 94 + struct imx8mq_usb_phy *imx_phy) 95 + { 96 + struct device *dev = &pdev->dev; 97 + struct typec_switch_dev *sw; 98 + struct typec_switch_desc sw_desc = { }; 99 + 100 + sw_desc.drvdata = imx_phy; 101 + sw_desc.fwnode = dev->fwnode; 102 + sw_desc.set = tca_blk_typec_switch_set; 103 + sw_desc.name = NULL; 104 + 105 + sw = typec_switch_register(dev, &sw_desc); 106 + if (IS_ERR(sw)) { 107 + dev_err(dev, "Error register tca orientation switch: %ld", 108 + PTR_ERR(sw)); 109 + return NULL; 110 + } 111 + 112 + return sw; 113 + } 114 + 115 + static void tca_blk_put_typec_switch(struct typec_switch_dev *sw) 116 + { 117 + typec_switch_unregister(sw); 118 + } 119 + 120 + #else 121 + 122 + static struct typec_switch_dev *tca_blk_get_typec_switch(struct platform_device *pdev, 123 + struct imx8mq_usb_phy *imx_phy) 124 + { 125 + return NULL; 126 + } 127 + 128 + static void tca_blk_put_typec_switch(struct typec_switch_dev *sw) {} 129 + 130 + #endif /* CONFIG_TYPEC */ 131 + 132 + static void tca_blk_orientation_set(struct tca_blk *tca, 133 + enum typec_orientation orientation) 134 + { 135 + u32 val; 136 + 137 + mutex_lock(&tca->mutex); 138 + 139 + if (orientation == TYPEC_ORIENTATION_NONE) { 140 + /* 141 + * use Controller Synced Mode for TCA low power enable and 142 + * put PHY to USB safe state. 143 + */ 144 + val = FIELD_PREP(TCA_GCFG_OP_MODE, TCA_GCFG_OP_MODE_SYNCMODE); 145 + writel(val, tca->base + TCA_GCFG); 146 + 147 + val = TCA_TCPC_VALID | TCA_TCPC_LOW_POWER_EN; 148 + writel(val, tca->base + TCA_TCPC); 149 + 150 + goto out; 151 + } 152 + 153 + /* use System Configuration Mode for TCA mux control. */ 154 + val = FIELD_PREP(TCA_GCFG_OP_MODE, TCA_GCFG_OP_MODE_SYSMODE); 155 + writel(val, tca->base + TCA_GCFG); 156 + 157 + /* Disable TCA module */ 158 + val = readl(tca->base + TCA_SYSMODE_CFG); 159 + val |= TCA_SYSMODE_TCPC_DISABLE; 160 + writel(val, tca->base + TCA_SYSMODE_CFG); 161 + 162 + if (orientation == TYPEC_ORIENTATION_REVERSE) 163 + val |= TCA_SYSMODE_TCPC_FLIP; 164 + else if (orientation == TYPEC_ORIENTATION_NORMAL) 165 + val &= ~TCA_SYSMODE_TCPC_FLIP; 166 + 167 + writel(val, tca->base + TCA_SYSMODE_CFG); 168 + 169 + /* Enable TCA module */ 170 + val &= ~TCA_SYSMODE_TCPC_DISABLE; 171 + writel(val, tca->base + TCA_SYSMODE_CFG); 172 + 173 + out: 174 + tca->orientation = orientation; 175 + mutex_unlock(&tca->mutex); 176 + } 177 + 178 + static void tca_blk_init(struct tca_blk *tca) 179 + { 180 + u32 val; 181 + 182 + /* reset XBar block */ 183 + val = readl(tca->base + TCA_CLK_RST); 184 + val &= ~TCA_CLK_RST_SW; 185 + writel(val, tca->base + TCA_CLK_RST); 186 + 187 + udelay(100); 188 + 189 + /* clear reset */ 190 + val |= TCA_CLK_RST_SW; 191 + writel(val, tca->base + TCA_CLK_RST); 192 + 193 + tca_blk_orientation_set(tca, tca->orientation); 194 + } 195 + 196 + static struct tca_blk *imx95_usb_phy_get_tca(struct platform_device *pdev, 197 + struct imx8mq_usb_phy *imx_phy) 198 + { 199 + struct device *dev = &pdev->dev; 200 + struct resource *res; 201 + struct tca_blk *tca; 202 + 203 + res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 204 + if (!res) 205 + return NULL; 206 + 207 + tca = devm_kzalloc(dev, sizeof(*tca), GFP_KERNEL); 208 + if (!tca) 209 + return ERR_PTR(-ENOMEM); 210 + 211 + tca->base = devm_ioremap_resource(&pdev->dev, res); 212 + if (IS_ERR(tca->base)) 213 + return ERR_CAST(tca->base); 214 + 215 + mutex_init(&tca->mutex); 216 + 217 + tca->orientation = TYPEC_ORIENTATION_NORMAL; 218 + tca->sw = tca_blk_get_typec_switch(pdev, imx_phy); 219 + 220 + return tca; 221 + } 222 + 223 + static void imx95_usb_phy_put_tca(struct imx8mq_usb_phy *imx_phy) 224 + { 225 + struct tca_blk *tca = imx_phy->tca; 226 + 227 + if (!tca) 228 + return; 229 + 230 + tca_blk_put_typec_switch(tca->sw); 231 + } 122 232 123 233 static u32 phy_tx_vref_tune_from_property(u32 percent) 124 234 { ··· 537 315 538 316 imx8m_phy_tune(imx_phy); 539 317 318 + if (imx_phy->tca) 319 + tca_blk_init(imx_phy->tca); 320 + 540 321 return 0; 541 322 } 542 323 ··· 584 359 .data = &imx8mq_usb_phy_ops,}, 585 360 {.compatible = "fsl,imx8mp-usb-phy", 586 361 .data = &imx8mp_usb_phy_ops,}, 362 + {.compatible = "fsl,imx95-usb-phy", 363 + .data = &imx8mp_usb_phy_ops,}, 587 364 { } 588 365 }; 589 366 MODULE_DEVICE_TABLE(of, imx8mq_usb_phy_of_match); ··· 625 398 626 399 phy_set_drvdata(imx_phy->phy, imx_phy); 627 400 401 + imx_phy->tca = imx95_usb_phy_get_tca(pdev, imx_phy); 402 + if (IS_ERR(imx_phy->tca)) 403 + return dev_err_probe(dev, PTR_ERR(imx_phy->tca), 404 + "failed to get tca\n"); 405 + 628 406 imx8m_get_phy_tuning_data(imx_phy); 629 407 630 408 phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); ··· 637 405 return PTR_ERR_OR_ZERO(phy_provider); 638 406 } 639 407 408 + static void imx8mq_usb_phy_remove(struct platform_device *pdev) 409 + { 410 + struct imx8mq_usb_phy *imx_phy = platform_get_drvdata(pdev); 411 + 412 + imx95_usb_phy_put_tca(imx_phy); 413 + } 414 + 640 415 static struct platform_driver imx8mq_usb_phy_driver = { 641 416 .probe = imx8mq_usb_phy_probe, 417 + .remove = imx8mq_usb_phy_remove, 642 418 .driver = { 643 419 .name = "imx8mq-usb-phy", 644 420 .of_match_table = imx8mq_usb_phy_of_match,