1 // SPDX-License-Identifier: GPL-2.0+
7 * Based on Linux driver
14 #include <usb/ehci-ci.h>
19 #include <linux/compat.h>
22 struct msm_ehci_priv {
23 struct ehci_ctrl ctrl; /* Needed by EHCI */
24 struct usb_ehci *ehci; /* Start of IP core*/
25 struct ulpi_viewport ulpi_vp; /* ULPI Viewport */
29 static int msm_init_after_reset(struct ehci_ctrl *dev)
31 struct msm_ehci_priv *p = container_of(dev, struct msm_ehci_priv, ctrl);
32 struct usb_ehci *ehci = p->ehci;
34 generic_phy_reset(&p->phy);
36 /* set mode to host controller */
37 writel(CM_HOST, &ehci->usbmode);
42 static const struct ehci_ops msm_ehci_ops = {
43 .init_after_reset = msm_init_after_reset
46 static int ehci_usb_probe(struct udevice *dev)
48 struct msm_ehci_priv *p = dev_get_priv(dev);
49 struct usb_ehci *ehci = p->ehci;
50 struct usb_platdata *plat = dev_get_platdata(dev);
51 struct ehci_hccr *hccr;
52 struct ehci_hcor *hcor;
55 hccr = (struct ehci_hccr *)((phys_addr_t)&ehci->caplength);
56 hcor = (struct ehci_hcor *)((phys_addr_t)hccr +
57 HC_LENGTH(ehci_readl(&(hccr)->cr_capbase)));
59 ret = ehci_setup_phy(dev, &p->phy, 0);
63 ret = board_usb_init(0, plat->init_type);
67 return ehci_register(dev, hccr, hcor, &msm_ehci_ops, 0,
71 static int ehci_usb_remove(struct udevice *dev)
73 struct msm_ehci_priv *p = dev_get_priv(dev);
74 struct usb_ehci *ehci = p->ehci;
77 ret = ehci_deregister(dev);
81 /* Stop controller. */
82 clrbits_le32(&ehci->usbcmd, CMD_RUN);
84 ret = ehci_shutdown_phy(dev, &p->phy);
88 ret = board_usb_init(0, USB_INIT_DEVICE); /* Board specific hook */
92 /* Reset controller */
93 setbits_le32(&ehci->usbcmd, CMD_RESET);
96 if (wait_for_bit_le32(&ehci->usbcmd, CMD_RESET, false, 30, false)) {
97 printf("Stuck on USB reset.\n");
104 static int ehci_usb_ofdata_to_platdata(struct udevice *dev)
106 struct msm_ehci_priv *priv = dev_get_priv(dev);
108 priv->ulpi_vp.port_num = 0;
109 priv->ehci = dev_read_addr_ptr(dev);
111 if (priv->ehci == (void *)FDT_ADDR_T_NONE)
114 /* Warning: this will not work if viewport address is > 64 bit due to
117 priv->ulpi_vp.viewport_addr = (phys_addr_t)&priv->ehci->ulpi_viewpoint;
122 #if defined(CONFIG_CI_UDC)
123 /* Little quirk that MSM needs with Chipidea controller
124 * Must reinit phy after reset
126 void ci_init_after_reset(struct ehci_ctrl *ctrl)
128 struct msm_ehci_priv *p = ctrl->priv;
130 generic_phy_reset(&p->phy);
134 static const struct udevice_id ehci_usb_ids[] = {
135 { .compatible = "qcom,ehci-host", },
139 U_BOOT_DRIVER(usb_ehci) = {
142 .of_match = ehci_usb_ids,
143 .ofdata_to_platdata = ehci_usb_ofdata_to_platdata,
144 .probe = ehci_usb_probe,
145 .remove = ehci_usb_remove,
146 .ops = &ehci_usb_ops,
147 .priv_auto = sizeof(struct msm_ehci_priv),
148 .platdata_auto = sizeof(struct usb_platdata),
149 .flags = DM_FLAG_ALLOC_PRIV_DMA,