4 * (C) Copyright 2015 Mateusz Kulikowski <mateusz.kulikowski@gmail.com>
6 * Based on Linux driver
8 * SPDX-License-Identifier: GPL-2.0+
17 #include <usb/ehci-ci.h>
22 #include <linux/compat.h>
25 /* PHY viewport regs */
26 #define ULPI_MISC_A_READ 0x96
27 #define ULPI_MISC_A_SET 0x97
28 #define ULPI_MISC_A_CLEAR 0x98
29 #define ULPI_MISC_A_VBUSVLDEXTSEL (1 << 1)
30 #define ULPI_MISC_A_VBUSVLDEXT (1 << 0)
32 #define GEN2_SESS_VLD_CTRL_EN (1 << 7)
34 #define SESS_VLD_CTRL (1 << 25)
36 struct msm_ehci_priv {
37 struct ehci_ctrl ctrl; /* Needed by EHCI */
38 struct usb_ehci *ehci; /* Start of IP core*/
39 struct ulpi_viewport ulpi_vp; /* ULPI Viewport */
42 int __weak board_prepare_usb(enum usb_init_type type)
47 static void setup_usb_phy(struct msm_ehci_priv *priv)
49 /* Select and enable external configuration with USB PHY */
50 ulpi_write(&priv->ulpi_vp, (u8 *)ULPI_MISC_A_SET,
51 ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT);
54 static void reset_usb_phy(struct msm_ehci_priv *priv)
56 /* Disable VBUS mimicing in the controller. */
57 ulpi_write(&priv->ulpi_vp, (u8 *)ULPI_MISC_A_CLEAR,
58 ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT);
62 static int msm_init_after_reset(struct ehci_ctrl *dev)
64 struct msm_ehci_priv *p = container_of(dev, struct msm_ehci_priv, ctrl);
65 struct usb_ehci *ehci = p->ehci;
68 writel(PORT_PTS_ULPI, &ehci->portsc);
72 setbits_le32(&ehci->genconfig2, GEN2_SESS_VLD_CTRL_EN);
74 /* Enable external vbus configuration in the LINK */
75 setbits_le32(&ehci->usbcmd, SESS_VLD_CTRL);
77 /* USB_OTG_HS_AHB_BURST */
78 writel(0x0, &ehci->sbuscfg);
80 /* USB_OTG_HS_AHB_MODE: HPROT_MODE */
81 /* Bus access related config. */
82 writel(0x08, &ehci->sbusmode);
84 /* set mode to host controller */
85 writel(CM_HOST, &ehci->usbmode);
90 static const struct ehci_ops msm_ehci_ops = {
91 .init_after_reset = msm_init_after_reset
94 static int ehci_usb_probe(struct udevice *dev)
96 struct msm_ehci_priv *p = dev_get_priv(dev);
97 struct usb_ehci *ehci = p->ehci;
98 struct ehci_hccr *hccr;
99 struct ehci_hcor *hcor;
102 hccr = (struct ehci_hccr *)((phys_addr_t)&ehci->caplength);
103 hcor = (struct ehci_hcor *)((phys_addr_t)hccr +
104 HC_LENGTH(ehci_readl(&(hccr)->cr_capbase)));
106 ret = board_prepare_usb(USB_INIT_HOST);
110 return ehci_register(dev, hccr, hcor, &msm_ehci_ops, 0, USB_INIT_HOST);
113 static int ehci_usb_remove(struct udevice *dev)
115 struct msm_ehci_priv *p = dev_get_priv(dev);
116 struct usb_ehci *ehci = p->ehci;
119 ret = ehci_deregister(dev);
123 /* Stop controller. */
124 clrbits_le32(&ehci->usbcmd, CMD_RUN);
128 ret = board_prepare_usb(USB_INIT_DEVICE); /* Board specific hook */
132 /* Reset controller */
133 setbits_le32(&ehci->usbcmd, CMD_RESET);
136 if (wait_for_bit(__func__, &ehci->usbcmd, CMD_RESET, false, 30,
138 printf("Stuck on USB reset.\n");
145 static int ehci_usb_ofdata_to_platdata(struct udevice *dev)
147 struct msm_ehci_priv *priv = dev_get_priv(dev);
149 priv->ulpi_vp.port_num = 0;
150 priv->ehci = (void *)dev_get_addr(dev);
152 if (priv->ehci == (void *)FDT_ADDR_T_NONE)
155 /* Warning: this will not work if viewport address is > 64 bit due to
158 priv->ulpi_vp.viewport_addr = (phys_addr_t)&priv->ehci->ulpi_viewpoint;
163 static const struct udevice_id ehci_usb_ids[] = {
164 { .compatible = "qcom,ehci-host", },
168 U_BOOT_DRIVER(usb_ehci) = {
171 .of_match = ehci_usb_ids,
172 .ofdata_to_platdata = ehci_usb_ofdata_to_platdata,
173 .probe = ehci_usb_probe,
174 .remove = ehci_usb_remove,
175 .ops = &ehci_usb_ops,
176 .priv_auto_alloc_size = sizeof(struct msm_ehci_priv),
177 .flags = DM_FLAG_ALLOC_PRIV_DMA,