Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Mateusz Kulikowski | 5a82211 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Qualcomm EHCI driver |
| 4 | * |
| 5 | * (C) Copyright 2015 Mateusz Kulikowski <mateusz.kulikowski@gmail.com> |
| 6 | * |
| 7 | * Based on Linux driver |
Mateusz Kulikowski | 5a82211 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
| 11 | #include <dm.h> |
| 12 | #include <errno.h> |
Mateusz Kulikowski | 5a82211 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 13 | #include <usb.h> |
| 14 | #include <usb/ehci-ci.h> |
| 15 | #include <usb/ulpi.h> |
| 16 | #include <wait_bit.h> |
| 17 | #include <asm/gpio.h> |
| 18 | #include <asm/io.h> |
| 19 | #include <linux/compat.h> |
| 20 | #include "ehci.h" |
| 21 | |
Mateusz Kulikowski | 5a82211 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 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 */ |
Ramon Fried | 0ac0b6e | 2018-09-21 13:35:50 +0300 | [diff] [blame] | 26 | struct phy phy; |
Mateusz Kulikowski | 5a82211 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 27 | }; |
| 28 | |
Mateusz Kulikowski | 5a82211 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 29 | static int msm_init_after_reset(struct ehci_ctrl *dev) |
| 30 | { |
| 31 | struct msm_ehci_priv *p = container_of(dev, struct msm_ehci_priv, ctrl); |
| 32 | struct usb_ehci *ehci = p->ehci; |
| 33 | |
Ramon Fried | 0ac0b6e | 2018-09-21 13:35:50 +0300 | [diff] [blame] | 34 | generic_phy_reset(&p->phy); |
Mateusz Kulikowski | 5a82211 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 35 | |
| 36 | /* set mode to host controller */ |
| 37 | writel(CM_HOST, &ehci->usbmode); |
| 38 | |
| 39 | return 0; |
| 40 | } |
| 41 | |
| 42 | static const struct ehci_ops msm_ehci_ops = { |
| 43 | .init_after_reset = msm_init_after_reset |
| 44 | }; |
| 45 | |
| 46 | static int ehci_usb_probe(struct udevice *dev) |
| 47 | { |
| 48 | struct msm_ehci_priv *p = dev_get_priv(dev); |
| 49 | struct usb_ehci *ehci = p->ehci; |
Ramon Fried | 0683b27 | 2018-09-21 13:35:51 +0300 | [diff] [blame] | 50 | struct usb_platdata *plat = dev_get_platdata(dev); |
Mateusz Kulikowski | 5a82211 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 51 | struct ehci_hccr *hccr; |
| 52 | struct ehci_hcor *hcor; |
| 53 | int ret; |
| 54 | |
| 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))); |
| 58 | |
Ramon Fried | 0ac0b6e | 2018-09-21 13:35:50 +0300 | [diff] [blame] | 59 | ret = ehci_setup_phy(dev, &p->phy, 0); |
| 60 | if (ret) |
| 61 | return ret; |
| 62 | |
Ramon Fried | 0683b27 | 2018-09-21 13:35:51 +0300 | [diff] [blame] | 63 | ret = board_usb_init(0, plat->init_type); |
Mateusz Kulikowski | 5a82211 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 64 | if (ret < 0) |
| 65 | return ret; |
| 66 | |
Ramon Fried | 0683b27 | 2018-09-21 13:35:51 +0300 | [diff] [blame] | 67 | return ehci_register(dev, hccr, hcor, &msm_ehci_ops, 0, |
| 68 | plat->init_type); |
Mateusz Kulikowski | 5a82211 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | static int ehci_usb_remove(struct udevice *dev) |
| 72 | { |
| 73 | struct msm_ehci_priv *p = dev_get_priv(dev); |
| 74 | struct usb_ehci *ehci = p->ehci; |
| 75 | int ret; |
| 76 | |
| 77 | ret = ehci_deregister(dev); |
| 78 | if (ret) |
| 79 | return ret; |
| 80 | |
| 81 | /* Stop controller. */ |
| 82 | clrbits_le32(&ehci->usbcmd, CMD_RUN); |
| 83 | |
Ramon Fried | 0ac0b6e | 2018-09-21 13:35:50 +0300 | [diff] [blame] | 84 | ret = ehci_shutdown_phy(dev, &p->phy); |
| 85 | if (ret) |
| 86 | return ret; |
Mateusz Kulikowski | 5a82211 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 87 | |
Ramon Fried | cd8c3ae | 2018-09-21 13:35:43 +0300 | [diff] [blame] | 88 | ret = board_usb_init(0, USB_INIT_DEVICE); /* Board specific hook */ |
Mateusz Kulikowski | 5a82211 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 89 | if (ret < 0) |
| 90 | return ret; |
| 91 | |
| 92 | /* Reset controller */ |
| 93 | setbits_le32(&ehci->usbcmd, CMD_RESET); |
| 94 | |
| 95 | /* Wait for reset */ |
Álvaro Fernández Rojas | 4826350 | 2018-01-23 17:14:55 +0100 | [diff] [blame] | 96 | if (wait_for_bit_le32(&ehci->usbcmd, CMD_RESET, false, 30, false)) { |
Mateusz Kulikowski | 5a82211 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 97 | printf("Stuck on USB reset.\n"); |
| 98 | return -ETIMEDOUT; |
| 99 | } |
| 100 | |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | static int ehci_usb_ofdata_to_platdata(struct udevice *dev) |
| 105 | { |
| 106 | struct msm_ehci_priv *priv = dev_get_priv(dev); |
| 107 | |
| 108 | priv->ulpi_vp.port_num = 0; |
Kever Yang | 2be1130 | 2020-03-04 08:59:49 +0800 | [diff] [blame] | 109 | priv->ehci = dev_read_addr_ptr(dev); |
Mateusz Kulikowski | 5a82211 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 110 | |
| 111 | if (priv->ehci == (void *)FDT_ADDR_T_NONE) |
| 112 | return -EINVAL; |
| 113 | |
| 114 | /* Warning: this will not work if viewport address is > 64 bit due to |
| 115 | * ULPI design. |
| 116 | */ |
| 117 | priv->ulpi_vp.viewport_addr = (phys_addr_t)&priv->ehci->ulpi_viewpoint; |
| 118 | |
| 119 | return 0; |
| 120 | } |
| 121 | |
Ramon Fried | 2466704 | 2018-09-21 13:35:53 +0300 | [diff] [blame] | 122 | #if defined(CONFIG_CI_UDC) |
| 123 | /* Little quirk that MSM needs with Chipidea controller |
| 124 | * Must reinit phy after reset |
| 125 | */ |
| 126 | void ci_init_after_reset(struct ehci_ctrl *ctrl) |
| 127 | { |
| 128 | struct msm_ehci_priv *p = ctrl->priv; |
| 129 | |
| 130 | generic_phy_reset(&p->phy); |
| 131 | } |
| 132 | #endif |
| 133 | |
Mateusz Kulikowski | 5a82211 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 134 | static const struct udevice_id ehci_usb_ids[] = { |
| 135 | { .compatible = "qcom,ehci-host", }, |
| 136 | { } |
| 137 | }; |
| 138 | |
| 139 | U_BOOT_DRIVER(usb_ehci) = { |
| 140 | .name = "ehci_msm", |
| 141 | .id = UCLASS_USB, |
| 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_alloc_size = sizeof(struct msm_ehci_priv), |
Ramon Fried | 2df4923 | 2018-09-21 13:35:44 +0300 | [diff] [blame] | 148 | .platdata_auto_alloc_size = sizeof(struct usb_platdata), |
Mateusz Kulikowski | 5a82211 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 149 | .flags = DM_FLAG_ALLOC_PRIV_DMA, |
| 150 | }; |