1 // SPDX-License-Identifier: GPL-2.0+
5 * (C) Copyright 2015 Mateusz Kulikowski <mateusz.kulikowski@gmail.com>
7 * Based on Linux driver
14 #include <linux/libfdt.h>
16 #include <usb/ehci-ci.h>
21 #include <linux/compat.h>
24 /* PHY viewport regs */
25 #define ULPI_MISC_A_READ 0x96
26 #define ULPI_MISC_A_SET 0x97
27 #define ULPI_MISC_A_CLEAR 0x98
28 #define ULPI_MISC_A_VBUSVLDEXTSEL (1 << 1)
29 #define ULPI_MISC_A_VBUSVLDEXT (1 << 0)
31 #define GEN2_SESS_VLD_CTRL_EN (1 << 7)
33 #define SESS_VLD_CTRL (1 << 25)
35 struct msm_ehci_priv {
36 struct ehci_ctrl ctrl; /* Needed by EHCI */
37 struct usb_ehci *ehci; /* Start of IP core*/
38 struct ulpi_viewport ulpi_vp; /* ULPI Viewport */
41 static void setup_usb_phy(struct msm_ehci_priv *priv)
43 /* Select and enable external configuration with USB PHY */
44 ulpi_write(&priv->ulpi_vp, (u8 *)ULPI_MISC_A_SET,
45 ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT);
48 static void reset_usb_phy(struct msm_ehci_priv *priv)
50 /* Disable VBUS mimicing in the controller. */
51 ulpi_write(&priv->ulpi_vp, (u8 *)ULPI_MISC_A_CLEAR,
52 ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT);
56 static int msm_init_after_reset(struct ehci_ctrl *dev)
58 struct msm_ehci_priv *p = container_of(dev, struct msm_ehci_priv, ctrl);
59 struct usb_ehci *ehci = p->ehci;
62 writel(PORT_PTS_ULPI, &ehci->portsc);
66 setbits_le32(&ehci->genconfig2, GEN2_SESS_VLD_CTRL_EN);
68 /* Enable external vbus configuration in the LINK */
69 setbits_le32(&ehci->usbcmd, SESS_VLD_CTRL);
71 /* USB_OTG_HS_AHB_BURST */
72 writel(0x0, &ehci->sbuscfg);
74 /* USB_OTG_HS_AHB_MODE: HPROT_MODE */
75 /* Bus access related config. */
76 writel(0x08, &ehci->sbusmode);
78 /* set mode to host controller */
79 writel(CM_HOST, &ehci->usbmode);
84 static const struct ehci_ops msm_ehci_ops = {
85 .init_after_reset = msm_init_after_reset
88 static int ehci_usb_probe(struct udevice *dev)
90 struct msm_ehci_priv *p = dev_get_priv(dev);
91 struct usb_ehci *ehci = p->ehci;
92 struct ehci_hccr *hccr;
93 struct ehci_hcor *hcor;
96 hccr = (struct ehci_hccr *)((phys_addr_t)&ehci->caplength);
97 hcor = (struct ehci_hcor *)((phys_addr_t)hccr +
98 HC_LENGTH(ehci_readl(&(hccr)->cr_capbase)));
100 ret = board_usb_init(0, USB_INIT_HOST);
104 return ehci_register(dev, hccr, hcor, &msm_ehci_ops, 0, USB_INIT_HOST);
107 static int ehci_usb_remove(struct udevice *dev)
109 struct msm_ehci_priv *p = dev_get_priv(dev);
110 struct usb_ehci *ehci = p->ehci;
113 ret = ehci_deregister(dev);
117 /* Stop controller. */
118 clrbits_le32(&ehci->usbcmd, CMD_RUN);
122 ret = board_usb_init(0, USB_INIT_DEVICE); /* Board specific hook */
126 /* Reset controller */
127 setbits_le32(&ehci->usbcmd, CMD_RESET);
130 if (wait_for_bit_le32(&ehci->usbcmd, CMD_RESET, false, 30, false)) {
131 printf("Stuck on USB reset.\n");
138 static int ehci_usb_ofdata_to_platdata(struct udevice *dev)
140 struct msm_ehci_priv *priv = dev_get_priv(dev);
142 priv->ulpi_vp.port_num = 0;
143 priv->ehci = (void *)devfdt_get_addr(dev);
145 if (priv->ehci == (void *)FDT_ADDR_T_NONE)
148 /* Warning: this will not work if viewport address is > 64 bit due to
151 priv->ulpi_vp.viewport_addr = (phys_addr_t)&priv->ehci->ulpi_viewpoint;
156 static const struct udevice_id ehci_usb_ids[] = {
157 { .compatible = "qcom,ehci-host", },
161 U_BOOT_DRIVER(usb_ehci) = {
164 .of_match = ehci_usb_ids,
165 .ofdata_to_platdata = ehci_usb_ofdata_to_platdata,
166 .probe = ehci_usb_probe,
167 .remove = ehci_usb_remove,
168 .ops = &ehci_usb_ops,
169 .priv_auto_alloc_size = sizeof(struct msm_ehci_priv),
170 .platdata_auto_alloc_size = sizeof(struct usb_platdata),
171 .flags = DM_FLAG_ALLOC_PRIV_DMA,