Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Mateusz Kulikowski | dc38117 | 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 | dc38117 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 8 | */ |
| 9 | |
Tom Rini | abb9a04 | 2024-05-18 20:20:43 -0600 | [diff] [blame] | 10 | #include <common.h> |
Mateusz Kulikowski | dc38117 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 11 | #include <dm.h> |
Caleb Connolly | 154ed1d | 2024-02-26 17:26:21 +0000 | [diff] [blame] | 12 | #include <dm/lists.h> |
Mateusz Kulikowski | dc38117 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 13 | #include <errno.h> |
Mateusz Kulikowski | dc38117 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 14 | #include <usb.h> |
| 15 | #include <usb/ehci-ci.h> |
| 16 | #include <usb/ulpi.h> |
| 17 | #include <wait_bit.h> |
| 18 | #include <asm/gpio.h> |
| 19 | #include <asm/io.h> |
| 20 | #include <linux/compat.h> |
| 21 | #include "ehci.h" |
| 22 | |
Mateusz Kulikowski | dc38117 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 23 | struct msm_ehci_priv { |
| 24 | struct ehci_ctrl ctrl; /* Needed by EHCI */ |
| 25 | struct usb_ehci *ehci; /* Start of IP core*/ |
| 26 | struct ulpi_viewport ulpi_vp; /* ULPI Viewport */ |
Ramon Fried | 7e36596 | 2018-09-21 13:35:50 +0300 | [diff] [blame] | 27 | struct phy phy; |
Mateusz Kulikowski | dc38117 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 28 | }; |
| 29 | |
Mateusz Kulikowski | dc38117 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 30 | static int msm_init_after_reset(struct ehci_ctrl *dev) |
| 31 | { |
| 32 | struct msm_ehci_priv *p = container_of(dev, struct msm_ehci_priv, ctrl); |
| 33 | struct usb_ehci *ehci = p->ehci; |
| 34 | |
Ramon Fried | 7e36596 | 2018-09-21 13:35:50 +0300 | [diff] [blame] | 35 | generic_phy_reset(&p->phy); |
Mateusz Kulikowski | dc38117 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 36 | |
| 37 | /* set mode to host controller */ |
| 38 | writel(CM_HOST, &ehci->usbmode); |
| 39 | |
| 40 | return 0; |
| 41 | } |
| 42 | |
| 43 | static const struct ehci_ops msm_ehci_ops = { |
| 44 | .init_after_reset = msm_init_after_reset |
| 45 | }; |
| 46 | |
| 47 | static int ehci_usb_probe(struct udevice *dev) |
| 48 | { |
| 49 | struct msm_ehci_priv *p = dev_get_priv(dev); |
| 50 | struct usb_ehci *ehci = p->ehci; |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 51 | struct usb_plat *plat = dev_get_plat(dev); |
Mateusz Kulikowski | dc38117 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 52 | struct ehci_hccr *hccr; |
| 53 | struct ehci_hcor *hcor; |
| 54 | int ret; |
| 55 | |
| 56 | hccr = (struct ehci_hccr *)((phys_addr_t)&ehci->caplength); |
| 57 | hcor = (struct ehci_hcor *)((phys_addr_t)hccr + |
| 58 | HC_LENGTH(ehci_readl(&(hccr)->cr_capbase))); |
| 59 | |
Patrice Chotard | 343ff75 | 2022-09-06 08:15:28 +0200 | [diff] [blame] | 60 | ret = generic_setup_phy(dev, &p->phy, 0); |
Ramon Fried | 7e36596 | 2018-09-21 13:35:50 +0300 | [diff] [blame] | 61 | if (ret) |
| 62 | return ret; |
| 63 | |
Ramon Fried | 7b0334f | 2018-09-21 13:35:51 +0300 | [diff] [blame] | 64 | ret = board_usb_init(0, plat->init_type); |
Mateusz Kulikowski | dc38117 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 65 | if (ret < 0) |
| 66 | return ret; |
| 67 | |
Ramon Fried | 7b0334f | 2018-09-21 13:35:51 +0300 | [diff] [blame] | 68 | return ehci_register(dev, hccr, hcor, &msm_ehci_ops, 0, |
| 69 | plat->init_type); |
Mateusz Kulikowski | dc38117 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | static int ehci_usb_remove(struct udevice *dev) |
| 73 | { |
| 74 | struct msm_ehci_priv *p = dev_get_priv(dev); |
| 75 | struct usb_ehci *ehci = p->ehci; |
| 76 | int ret; |
| 77 | |
| 78 | ret = ehci_deregister(dev); |
| 79 | if (ret) |
| 80 | return ret; |
| 81 | |
| 82 | /* Stop controller. */ |
| 83 | clrbits_le32(&ehci->usbcmd, CMD_RUN); |
| 84 | |
Patrice Chotard | 343ff75 | 2022-09-06 08:15:28 +0200 | [diff] [blame] | 85 | ret = generic_shutdown_phy(&p->phy); |
Ramon Fried | 7e36596 | 2018-09-21 13:35:50 +0300 | [diff] [blame] | 86 | if (ret) |
| 87 | return ret; |
Mateusz Kulikowski | dc38117 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 88 | |
Ramon Fried | bc866cc8 | 2018-09-21 13:35:43 +0300 | [diff] [blame] | 89 | ret = board_usb_init(0, USB_INIT_DEVICE); /* Board specific hook */ |
Mateusz Kulikowski | dc38117 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 90 | if (ret < 0) |
| 91 | return ret; |
| 92 | |
| 93 | /* Reset controller */ |
| 94 | setbits_le32(&ehci->usbcmd, CMD_RESET); |
| 95 | |
| 96 | /* Wait for reset */ |
Álvaro Fernández Rojas | 918de03 | 2018-01-23 17:14:55 +0100 | [diff] [blame] | 97 | if (wait_for_bit_le32(&ehci->usbcmd, CMD_RESET, false, 30, false)) { |
Mateusz Kulikowski | dc38117 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 98 | printf("Stuck on USB reset.\n"); |
| 99 | return -ETIMEDOUT; |
| 100 | } |
| 101 | |
| 102 | return 0; |
| 103 | } |
| 104 | |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 105 | static int ehci_usb_of_to_plat(struct udevice *dev) |
Mateusz Kulikowski | dc38117 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 106 | { |
| 107 | struct msm_ehci_priv *priv = dev_get_priv(dev); |
| 108 | |
| 109 | priv->ulpi_vp.port_num = 0; |
Kever Yang | d24b154 | 2020-03-04 08:59:49 +0800 | [diff] [blame] | 110 | priv->ehci = dev_read_addr_ptr(dev); |
Mateusz Kulikowski | dc38117 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 111 | |
| 112 | if (priv->ehci == (void *)FDT_ADDR_T_NONE) |
| 113 | return -EINVAL; |
| 114 | |
| 115 | /* Warning: this will not work if viewport address is > 64 bit due to |
| 116 | * ULPI design. |
| 117 | */ |
| 118 | priv->ulpi_vp.viewport_addr = (phys_addr_t)&priv->ehci->ulpi_viewpoint; |
| 119 | |
| 120 | return 0; |
| 121 | } |
| 122 | |
Caleb Connolly | 154ed1d | 2024-02-26 17:26:21 +0000 | [diff] [blame] | 123 | static int ehci_usb_of_bind(struct udevice *dev) |
| 124 | { |
| 125 | ofnode ulpi_node = ofnode_first_subnode(dev_ofnode(dev)); |
| 126 | ofnode phy_node; |
| 127 | |
| 128 | if (!ofnode_valid(ulpi_node)) |
| 129 | return 0; |
| 130 | |
| 131 | phy_node = ofnode_first_subnode(ulpi_node); |
| 132 | if (!ofnode_valid(phy_node)) { |
| 133 | printf("%s: ulpi subnode with no phy\n", __func__); |
| 134 | return -ENOENT; |
| 135 | } |
| 136 | |
| 137 | return device_bind_driver_to_node(dev, "msm8916_usbphy", "msm8916_usbphy", |
| 138 | phy_node, NULL); |
| 139 | } |
| 140 | |
Ramon Fried | cbee908 | 2018-09-21 13:35:53 +0300 | [diff] [blame] | 141 | #if defined(CONFIG_CI_UDC) |
| 142 | /* Little quirk that MSM needs with Chipidea controller |
| 143 | * Must reinit phy after reset |
| 144 | */ |
| 145 | void ci_init_after_reset(struct ehci_ctrl *ctrl) |
| 146 | { |
| 147 | struct msm_ehci_priv *p = ctrl->priv; |
| 148 | |
| 149 | generic_phy_reset(&p->phy); |
| 150 | } |
| 151 | #endif |
| 152 | |
Mateusz Kulikowski | dc38117 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 153 | static const struct udevice_id ehci_usb_ids[] = { |
Caleb Connolly | 154ed1d | 2024-02-26 17:26:21 +0000 | [diff] [blame] | 154 | { .compatible = "qcom,ci-hdrc", }, |
Mateusz Kulikowski | dc38117 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 155 | { } |
| 156 | }; |
| 157 | |
| 158 | U_BOOT_DRIVER(usb_ehci) = { |
| 159 | .name = "ehci_msm", |
| 160 | .id = UCLASS_USB, |
| 161 | .of_match = ehci_usb_ids, |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 162 | .of_to_plat = ehci_usb_of_to_plat, |
Caleb Connolly | 154ed1d | 2024-02-26 17:26:21 +0000 | [diff] [blame] | 163 | .bind = ehci_usb_of_bind, |
Mateusz Kulikowski | dc38117 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 164 | .probe = ehci_usb_probe, |
| 165 | .remove = ehci_usb_remove, |
| 166 | .ops = &ehci_usb_ops, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 167 | .priv_auto = sizeof(struct msm_ehci_priv), |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 168 | .plat_auto = sizeof(struct usb_plat), |
Mateusz Kulikowski | dc38117 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 169 | .flags = DM_FLAG_ALLOC_PRIV_DMA, |
| 170 | }; |