1
2
3
4
5
6#include <common.h>
7#include <dm.h>
8#include <generic-phy.h>
9#include <usb/ehci-ci.h>
10#include <usb/ulpi.h>
11#include <asm/io.h>
12
13
14#define ULPI_MISC_A_READ 0x96
15#define ULPI_MISC_A_SET 0x97
16#define ULPI_MISC_A_CLEAR 0x98
17#define ULPI_MISC_A_VBUSVLDEXT BIT(0)
18#define ULPI_MISC_A_VBUSVLDEXTSEL BIT(1)
19#define GEN2_SESS_VLD_CTRL_EN BIT(7)
20#define SESS_VLD_CTRL BIT(25)
21
22struct msm_phy_priv {
23 void __iomem *regs;
24 struct usb_ehci *ehci;
25 struct ulpi_viewport ulpi_vp;
26};
27
28static int msm_phy_power_on(struct phy *phy)
29{
30 struct msm_phy_priv *priv = dev_get_priv(phy->dev);
31
32
33 ulpi_write(&priv->ulpi_vp, (u8 *)ULPI_MISC_A_SET,
34 ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT);
35
36 return 0;
37}
38
39static int msm_phy_power_off(struct phy *phy)
40{
41 struct msm_phy_priv *priv = dev_get_priv(phy->dev);
42
43
44 ulpi_write(&priv->ulpi_vp, (u8 *)ULPI_MISC_A_CLEAR,
45 ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT);
46 return 0;
47}
48
49static int msm_phy_reset(struct phy *phy)
50{
51 struct msm_phy_priv *p = dev_get_priv(phy->dev);
52
53
54 writel(PORT_PTS_ULPI, &p->ehci->portsc);
55
56
57 setbits_le32(&p->ehci->genconfig2, GEN2_SESS_VLD_CTRL_EN);
58
59
60 setbits_le32(&p->ehci->usbcmd, SESS_VLD_CTRL);
61
62
63 writel(0x0, &p->ehci->sbuscfg);
64
65
66
67 writel(0x08, &p->ehci->sbusmode);
68
69 return 0;
70}
71
72static int msm_phy_probe(struct udevice *dev)
73{
74 struct msm_phy_priv *priv = dev_get_priv(dev);
75
76 priv->regs = dev_remap_addr(dev);
77 if (!priv->regs)
78 return -EINVAL;
79
80 priv->ehci = (struct usb_ehci *)priv->regs;
81 priv->ulpi_vp.port_num = 0;
82
83
84
85
86 priv->ulpi_vp.viewport_addr = (phys_addr_t)&priv->ehci->ulpi_viewpoint;
87
88 return 0;
89}
90
91static struct phy_ops msm_phy_ops = {
92 .power_on = msm_phy_power_on,
93 .power_off = msm_phy_power_off,
94 .reset = msm_phy_reset,
95};
96
97static const struct udevice_id msm_phy_ids[] = {
98 { .compatible = "qcom,apq8016-usbphy" },
99 { }
100};
101
102U_BOOT_DRIVER(msm8916_usbphy) = {
103 .name = "msm8916_usbphy",
104 .id = UCLASS_PHY,
105 .of_match = msm_phy_ids,
106 .ops = &msm_phy_ops,
107 .probe = msm_phy_probe,
108 .priv_auto_alloc_size = sizeof(struct msm_phy_priv),
109};
110