Lines Matching +full:ipq806x +full:- +full:usb +full:- +full:phy +full:- +full:ss

1 // SPDX-License-Identifier: GPL-2.0-only
8 #include <linux/phy/phy.h>
15 /* USB QSCRATCH Hardware registers */
36 /* USB QSCRATCH Hardware registers */
54 /* SSPHY control registers - Does this need 0x30? */
109 /* SS CAP register bits */
134 * usb_phy_write_readback() - Write register and read back masked value to
137 * @phy_dwc3: QCOM DWC3 phy context
146 u32 write_val, tmp = readl(phy_dwc3->base + offset); in usb_phy_write_readback()
151 writel(write_val, phy_dwc3->base + offset); in usb_phy_write_readback()
154 tmp = readl(phy_dwc3->base + offset); in usb_phy_write_readback()
158 dev_err(phy_dwc3->dev, "write: %x to QSCRATCH: %x FAILED\n", val, offset); in usb_phy_write_readback()
169 * usb_ss_write_phycreg() - Write SSPHY register
171 * @phy_dwc3: QCOM DWC3 phy context
180 writel(addr, phy_dwc3->base + CR_PROTOCOL_DATA_IN_REG); in usb_ss_write_phycreg()
182 phy_dwc3->base + CR_PROTOCOL_CAP_ADDR_REG); in usb_ss_write_phycreg()
184 ret = wait_for_latch(phy_dwc3->base + CR_PROTOCOL_CAP_ADDR_REG); in usb_ss_write_phycreg()
188 writel(val, phy_dwc3->base + CR_PROTOCOL_DATA_IN_REG); in usb_ss_write_phycreg()
190 phy_dwc3->base + CR_PROTOCOL_CAP_DATA_REG); in usb_ss_write_phycreg()
192 ret = wait_for_latch(phy_dwc3->base + CR_PROTOCOL_CAP_DATA_REG); in usb_ss_write_phycreg()
196 writel(SS_CR_WRITE_REG, phy_dwc3->base + CR_PROTOCOL_WRITE_REG); in usb_ss_write_phycreg()
198 ret = wait_for_latch(phy_dwc3->base + CR_PROTOCOL_WRITE_REG); in usb_ss_write_phycreg()
202 dev_err(phy_dwc3->dev, "timeout waiting for latch\n"); in usb_ss_write_phycreg()
207 * usb_ss_read_phycreg() - Read SSPHY register.
209 * @phy_dwc3: QCOM DWC3 phy context
218 writel(addr, phy_dwc3->base + CR_PROTOCOL_DATA_IN_REG); in usb_ss_read_phycreg()
220 phy_dwc3->base + CR_PROTOCOL_CAP_ADDR_REG); in usb_ss_read_phycreg()
222 ret = wait_for_latch(phy_dwc3->base + CR_PROTOCOL_CAP_ADDR_REG); in usb_ss_read_phycreg()
231 writel(SS_CR_READ_REG, phy_dwc3->base + CR_PROTOCOL_READ_REG); in usb_ss_read_phycreg()
233 ret = wait_for_latch(phy_dwc3->base + CR_PROTOCOL_READ_REG); in usb_ss_read_phycreg()
238 readl(phy_dwc3->base + CR_PROTOCOL_DATA_OUT_REG); in usb_ss_read_phycreg()
240 writel(SS_CR_READ_REG, phy_dwc3->base + CR_PROTOCOL_READ_REG); in usb_ss_read_phycreg()
242 ret = wait_for_latch(phy_dwc3->base + CR_PROTOCOL_READ_REG); in usb_ss_read_phycreg()
246 *val = readl(phy_dwc3->base + CR_PROTOCOL_DATA_OUT_REG); in usb_ss_read_phycreg()
252 static int qcom_ipq806x_usb_hs_phy_init(struct phy *phy) in qcom_ipq806x_usb_hs_phy_init() argument
254 struct usb_phy *phy_dwc3 = phy_get_drvdata(phy); in qcom_ipq806x_usb_hs_phy_init()
258 ret = clk_prepare_enable(phy_dwc3->xo_clk); in qcom_ipq806x_usb_hs_phy_init()
262 ret = clk_prepare_enable(phy_dwc3->ref_clk); in qcom_ipq806x_usb_hs_phy_init()
264 clk_disable_unprepare(phy_dwc3->xo_clk); in qcom_ipq806x_usb_hs_phy_init()
270 * enable clamping, and disable RETENTION (power-on default is ENABLED) in qcom_ipq806x_usb_hs_phy_init()
279 if (!phy_dwc3->xo_clk) in qcom_ipq806x_usb_hs_phy_init()
282 writel(val, phy_dwc3->base + HSUSB_PHY_CTRL_REG); in qcom_ipq806x_usb_hs_phy_init()
286 writel(HSUSB_GCFG_XHCI_REV, phy_dwc3->base + QSCRATCH_GENERAL_CFG); in qcom_ipq806x_usb_hs_phy_init()
291 static int qcom_ipq806x_usb_hs_phy_exit(struct phy *phy) in qcom_ipq806x_usb_hs_phy_exit() argument
293 struct usb_phy *phy_dwc3 = phy_get_drvdata(phy); in qcom_ipq806x_usb_hs_phy_exit()
295 clk_disable_unprepare(phy_dwc3->ref_clk); in qcom_ipq806x_usb_hs_phy_exit()
296 clk_disable_unprepare(phy_dwc3->xo_clk); in qcom_ipq806x_usb_hs_phy_exit()
301 static int qcom_ipq806x_usb_ss_phy_init(struct phy *phy) in qcom_ipq806x_usb_ss_phy_init() argument
303 struct usb_phy *phy_dwc3 = phy_get_drvdata(phy); in qcom_ipq806x_usb_ss_phy_init()
307 ret = clk_prepare_enable(phy_dwc3->xo_clk); in qcom_ipq806x_usb_ss_phy_init()
311 ret = clk_prepare_enable(phy_dwc3->ref_clk); in qcom_ipq806x_usb_ss_phy_init()
313 clk_disable_unprepare(phy_dwc3->xo_clk); in qcom_ipq806x_usb_ss_phy_init()
317 /* reset phy */ in qcom_ipq806x_usb_ss_phy_init()
318 data = readl(phy_dwc3->base + SSUSB_PHY_CTRL_REG); in qcom_ipq806x_usb_ss_phy_init()
320 phy_dwc3->base + SSUSB_PHY_CTRL_REG); in qcom_ipq806x_usb_ss_phy_init()
322 writel(data, phy_dwc3->base + SSUSB_PHY_CTRL_REG); in qcom_ipq806x_usb_ss_phy_init()
325 if (!phy_dwc3->xo_clk) in qcom_ipq806x_usb_ss_phy_init()
330 writel(data, phy_dwc3->base + SSUSB_PHY_CTRL_REG); in qcom_ipq806x_usb_ss_phy_init()
336 writel(data, phy_dwc3->base + SSUSB_PHY_CTRL_REG); in qcom_ipq806x_usb_ss_phy_init()
339 * WORKAROUND: There is SSPHY suspend bug due to which USB enumerates in qcom_ipq806x_usb_ss_phy_init()
340 * in HS mode instead of SS mode. Workaround it by asserting in qcom_ipq806x_usb_ss_phy_init()
376 data |= RX_OVRD_IN_HI_RX_EQ(phy_dwc3->rx_eq); in qcom_ipq806x_usb_ss_phy_init()
395 data |= TX_OVRD_DRV_LO_PREEMPH(phy_dwc3->tx_deamp_3_5db); in qcom_ipq806x_usb_ss_phy_init()
406 data |= SSPHY_MPLL(phy_dwc3->mpll); in qcom_ipq806x_usb_ss_phy_init()
416 data = readl(phy_dwc3->base + SSUSB_PHY_PARAM_CTRL_1); in qcom_ipq806x_usb_ss_phy_init()
422 PHY_PARAM_CTRL1_TX_DEEMPH_3_5DB(phy_dwc3->tx_deamp_3_5db) | in qcom_ipq806x_usb_ss_phy_init()
432 static int qcom_ipq806x_usb_ss_phy_exit(struct phy *phy) in qcom_ipq806x_usb_ss_phy_exit() argument
434 struct usb_phy *phy_dwc3 = phy_get_drvdata(phy); in qcom_ipq806x_usb_ss_phy_exit()
439 * 3. Set TEST_POWERED_DOWN in PHY_CTRL_REG to enable PHY retention in qcom_ipq806x_usb_ss_phy_exit()
448 clk_disable_unprepare(phy_dwc3->ref_clk); in qcom_ipq806x_usb_ss_phy_exit()
449 clk_disable_unprepare(phy_dwc3->xo_clk); in qcom_ipq806x_usb_ss_phy_exit()
473 { .compatible = "qcom,ipq806x-usb-phy-hs",
475 { .compatible = "qcom,ipq806x-usb-phy-ss",
485 struct phy *generic_phy; in qcom_ipq806x_usb_phy_probe()
490 phy_dwc3 = devm_kzalloc(&pdev->dev, sizeof(*phy_dwc3), GFP_KERNEL); in qcom_ipq806x_usb_phy_probe()
492 return -ENOMEM; in qcom_ipq806x_usb_phy_probe()
494 data = of_device_get_match_data(&pdev->dev); in qcom_ipq806x_usb_phy_probe()
496 phy_dwc3->dev = &pdev->dev; in qcom_ipq806x_usb_phy_probe()
500 return -EINVAL; in qcom_ipq806x_usb_phy_probe()
502 phy_dwc3->base = devm_ioremap(phy_dwc3->dev, res->start, size); in qcom_ipq806x_usb_phy_probe()
504 if (!phy_dwc3->base) { in qcom_ipq806x_usb_phy_probe()
505 dev_err(phy_dwc3->dev, "failed to map reg\n"); in qcom_ipq806x_usb_phy_probe()
506 return -ENOMEM; in qcom_ipq806x_usb_phy_probe()
509 phy_dwc3->ref_clk = devm_clk_get(phy_dwc3->dev, "ref"); in qcom_ipq806x_usb_phy_probe()
510 if (IS_ERR(phy_dwc3->ref_clk)) { in qcom_ipq806x_usb_phy_probe()
511 dev_dbg(phy_dwc3->dev, "cannot get reference clock\n"); in qcom_ipq806x_usb_phy_probe()
512 return PTR_ERR(phy_dwc3->ref_clk); in qcom_ipq806x_usb_phy_probe()
515 clk_set_rate(phy_dwc3->ref_clk, data->clk_rate); in qcom_ipq806x_usb_phy_probe()
517 phy_dwc3->xo_clk = devm_clk_get(phy_dwc3->dev, "xo"); in qcom_ipq806x_usb_phy_probe()
518 if (IS_ERR(phy_dwc3->xo_clk)) { in qcom_ipq806x_usb_phy_probe()
519 dev_dbg(phy_dwc3->dev, "cannot get TCXO clock\n"); in qcom_ipq806x_usb_phy_probe()
520 phy_dwc3->xo_clk = NULL; in qcom_ipq806x_usb_phy_probe()
524 if (device_property_read_u32(&pdev->dev, "qcom,rx-eq", in qcom_ipq806x_usb_phy_probe()
525 &phy_dwc3->rx_eq)) in qcom_ipq806x_usb_phy_probe()
526 phy_dwc3->rx_eq = SSPHY_RX_EQ_VALUE; in qcom_ipq806x_usb_phy_probe()
528 if (device_property_read_u32(&pdev->dev, "qcom,tx-deamp_3_5db", in qcom_ipq806x_usb_phy_probe()
529 &phy_dwc3->tx_deamp_3_5db)) in qcom_ipq806x_usb_phy_probe()
530 phy_dwc3->tx_deamp_3_5db = SSPHY_TX_DEEMPH_3_5DB; in qcom_ipq806x_usb_phy_probe()
532 if (device_property_read_u32(&pdev->dev, "qcom,mpll", &phy_dwc3->mpll)) in qcom_ipq806x_usb_phy_probe()
533 phy_dwc3->mpll = SSPHY_MPLL_VALUE; in qcom_ipq806x_usb_phy_probe()
535 generic_phy = devm_phy_create(phy_dwc3->dev, pdev->dev.of_node, &data->ops); in qcom_ipq806x_usb_phy_probe()
543 phy_provider = devm_of_phy_provider_register(phy_dwc3->dev, in qcom_ipq806x_usb_phy_probe()
555 .name = "qcom-ipq806x-usb-phy",
562 MODULE_ALIAS("platform:phy-qcom-ipq806x-usb");
565 MODULE_AUTHOR("Ivan T. Ivanov <iivanov@mm-sol.com>");
566 MODULE_DESCRIPTION("DesignWare USB3 QCOM PHY driver");