1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2018 Ramon Fried <ramon.fried@gmail.com>
8 #include <generic-phy.h>
9 #include <linux/bitops.h>
10 #include <usb/ehci-ci.h>
14 /* PHY viewport regs */
15 #define ULPI_MISC_A_READ 0x96
16 #define ULPI_MISC_A_SET 0x97
17 #define ULPI_MISC_A_CLEAR 0x98
18 #define ULPI_MISC_A_VBUSVLDEXT BIT(0)
19 #define ULPI_MISC_A_VBUSVLDEXTSEL BIT(1)
20 #define GEN2_SESS_VLD_CTRL_EN BIT(7)
21 #define SESS_VLD_CTRL BIT(25)
25 struct usb_ehci *ehci; /* Start of IP core*/
26 struct ulpi_viewport ulpi_vp; /* ULPI Viewport */
29 static int msm_phy_power_on(struct phy *phy)
31 struct msm_phy_priv *priv = dev_get_priv(phy->dev);
33 /* Select and enable external configuration with USB PHY */
34 ulpi_write(&priv->ulpi_vp, (u8 *)ULPI_MISC_A_SET,
35 ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT);
40 static int msm_phy_power_off(struct phy *phy)
42 struct msm_phy_priv *priv = dev_get_priv(phy->dev);
44 /* Disable VBUS mimicing in the controller. */
45 ulpi_write(&priv->ulpi_vp, (u8 *)ULPI_MISC_A_CLEAR,
46 ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT);
50 static int msm_phy_reset(struct phy *phy)
52 struct msm_phy_priv *p = dev_get_priv(phy->dev);
55 writel(PORT_PTS_ULPI, &p->ehci->portsc);
58 setbits_le32(&p->ehci->genconfig2, GEN2_SESS_VLD_CTRL_EN);
60 /* Enable external vbus configuration in the LINK */
61 setbits_le32(&p->ehci->usbcmd, SESS_VLD_CTRL);
63 /* USB_OTG_HS_AHB_BURST */
64 writel(0x0, &p->ehci->sbuscfg);
66 /* USB_OTG_HS_AHB_MODE: HPROT_MODE */
67 /* Bus access related config. */
68 writel(0x08, &p->ehci->sbusmode);
73 static int msm_phy_probe(struct udevice *dev)
75 struct msm_phy_priv *priv = dev_get_priv(dev);
77 priv->regs = dev_remap_addr(dev);
81 priv->ehci = (struct usb_ehci *)priv->regs;
82 priv->ulpi_vp.port_num = 0;
84 /* Warning: this will not work if viewport address is > 64 bit due to
87 priv->ulpi_vp.viewport_addr = (phys_addr_t)&priv->ehci->ulpi_viewpoint;
92 static struct phy_ops msm_phy_ops = {
93 .power_on = msm_phy_power_on,
94 .power_off = msm_phy_power_off,
95 .reset = msm_phy_reset,
98 static const struct udevice_id msm_phy_ids[] = {
99 { .compatible = "qcom,apq8016-usbphy" },
103 U_BOOT_DRIVER(msm8916_usbphy) = {
104 .name = "msm8916_usbphy",
106 .of_match = msm_phy_ids,
108 .probe = msm_phy_probe,
109 .priv_auto = sizeof(struct msm_phy_priv),