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 struct msm_ehci_priv {
25 struct ehci_ctrl ctrl; /* Needed by EHCI */
26 struct usb_ehci *ehci; /* Start of IP core*/
27 struct ulpi_viewport ulpi_vp; /* ULPI Viewport */
31 static int msm_init_after_reset(struct ehci_ctrl *dev)
33 struct msm_ehci_priv *p = container_of(dev, struct msm_ehci_priv, ctrl);
34 struct usb_ehci *ehci = p->ehci;
36 generic_phy_reset(&p->phy);
38 /* set mode to host controller */
39 writel(CM_HOST, &ehci->usbmode);
44 static const struct ehci_ops msm_ehci_ops = {
45 .init_after_reset = msm_init_after_reset
48 static int ehci_usb_probe(struct udevice *dev)
50 struct msm_ehci_priv *p = dev_get_priv(dev);
51 struct usb_ehci *ehci = p->ehci;
52 struct usb_platdata *plat = dev_get_platdata(dev);
53 struct ehci_hccr *hccr;
54 struct ehci_hcor *hcor;
57 hccr = (struct ehci_hccr *)((phys_addr_t)&ehci->caplength);
58 hcor = (struct ehci_hcor *)((phys_addr_t)hccr +
59 HC_LENGTH(ehci_readl(&(hccr)->cr_capbase)));
61 ret = ehci_setup_phy(dev, &p->phy, 0);
65 ret = board_usb_init(0, plat->init_type);
69 return ehci_register(dev, hccr, hcor, &msm_ehci_ops, 0,
73 static int ehci_usb_remove(struct udevice *dev)
75 struct msm_ehci_priv *p = dev_get_priv(dev);
76 struct usb_ehci *ehci = p->ehci;
79 ret = ehci_deregister(dev);
83 /* Stop controller. */
84 clrbits_le32(&ehci->usbcmd, CMD_RUN);
86 ret = ehci_shutdown_phy(dev, &p->phy);
90 ret = board_usb_init(0, USB_INIT_DEVICE); /* Board specific hook */
94 /* Reset controller */
95 setbits_le32(&ehci->usbcmd, CMD_RESET);
98 if (wait_for_bit_le32(&ehci->usbcmd, CMD_RESET, false, 30, false)) {
99 printf("Stuck on USB reset.\n");
106 static int ehci_usb_ofdata_to_platdata(struct udevice *dev)
108 struct msm_ehci_priv *priv = dev_get_priv(dev);
110 priv->ulpi_vp.port_num = 0;
111 priv->ehci = (void *)devfdt_get_addr(dev);
113 if (priv->ehci == (void *)FDT_ADDR_T_NONE)
116 /* Warning: this will not work if viewport address is > 64 bit due to
119 priv->ulpi_vp.viewport_addr = (phys_addr_t)&priv->ehci->ulpi_viewpoint;
124 #if defined(CONFIG_CI_UDC)
125 /* Little quirk that MSM needs with Chipidea controller
126 * Must reinit phy after reset
128 void ci_init_after_reset(struct ehci_ctrl *ctrl)
130 struct msm_ehci_priv *p = ctrl->priv;
132 generic_phy_reset(&p->phy);
136 static const struct udevice_id ehci_usb_ids[] = {
137 { .compatible = "qcom,ehci-host", },
141 U_BOOT_DRIVER(usb_ehci) = {
144 .of_match = ehci_usb_ids,
145 .ofdata_to_platdata = ehci_usb_ofdata_to_platdata,
146 .probe = ehci_usb_probe,
147 .remove = ehci_usb_remove,
148 .ops = &ehci_usb_ops,
149 .priv_auto_alloc_size = sizeof(struct msm_ehci_priv),
150 .platdata_auto_alloc_size = sizeof(struct usb_platdata),
151 .flags = DM_FLAG_ALLOC_PRIV_DMA,