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> |
| 13 | #include <fdtdec.h> |
Masahiro Yamada | b08c8c4 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 14 | #include <linux/libfdt.h> |
Mateusz Kulikowski | 5a82211 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 15 | #include <usb.h> |
| 16 | #include <usb/ehci-ci.h> |
| 17 | #include <usb/ulpi.h> |
| 18 | #include <wait_bit.h> |
| 19 | #include <asm/gpio.h> |
| 20 | #include <asm/io.h> |
| 21 | #include <linux/compat.h> |
| 22 | #include "ehci.h" |
| 23 | |
Mateusz Kulikowski | 5a82211 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 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 */ |
Ramon Fried | 0ac0b6e | 2018-09-21 13:35:50 +0300 | [diff] [blame] | 28 | struct phy phy; |
Mateusz Kulikowski | 5a82211 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 29 | }; |
| 30 | |
Mateusz Kulikowski | 5a82211 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 31 | static int msm_init_after_reset(struct ehci_ctrl *dev) |
| 32 | { |
| 33 | struct msm_ehci_priv *p = container_of(dev, struct msm_ehci_priv, ctrl); |
| 34 | struct usb_ehci *ehci = p->ehci; |
| 35 | |
Ramon Fried | 0ac0b6e | 2018-09-21 13:35:50 +0300 | [diff] [blame] | 36 | generic_phy_reset(&p->phy); |
Mateusz Kulikowski | 5a82211 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 37 | |
| 38 | /* set mode to host controller */ |
| 39 | writel(CM_HOST, &ehci->usbmode); |
| 40 | |
| 41 | return 0; |
| 42 | } |
| 43 | |
| 44 | static const struct ehci_ops msm_ehci_ops = { |
| 45 | .init_after_reset = msm_init_after_reset |
| 46 | }; |
| 47 | |
| 48 | static int ehci_usb_probe(struct udevice *dev) |
| 49 | { |
| 50 | struct msm_ehci_priv *p = dev_get_priv(dev); |
| 51 | struct usb_ehci *ehci = p->ehci; |
Ramon Fried | 0683b27 | 2018-09-21 13:35:51 +0300 | [diff] [blame^] | 52 | struct usb_platdata *plat = dev_get_platdata(dev); |
Mateusz Kulikowski | 5a82211 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 53 | struct ehci_hccr *hccr; |
| 54 | struct ehci_hcor *hcor; |
| 55 | int ret; |
| 56 | |
| 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))); |
| 60 | |
Ramon Fried | 0ac0b6e | 2018-09-21 13:35:50 +0300 | [diff] [blame] | 61 | ret = ehci_setup_phy(dev, &p->phy, 0); |
| 62 | if (ret) |
| 63 | return ret; |
| 64 | |
Ramon Fried | 0683b27 | 2018-09-21 13:35:51 +0300 | [diff] [blame^] | 65 | ret = board_usb_init(0, plat->init_type); |
Mateusz Kulikowski | 5a82211 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 66 | if (ret < 0) |
| 67 | return ret; |
| 68 | |
Ramon Fried | 0683b27 | 2018-09-21 13:35:51 +0300 | [diff] [blame^] | 69 | return ehci_register(dev, hccr, hcor, &msm_ehci_ops, 0, |
| 70 | plat->init_type); |
Mateusz Kulikowski | 5a82211 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | static int ehci_usb_remove(struct udevice *dev) |
| 74 | { |
| 75 | struct msm_ehci_priv *p = dev_get_priv(dev); |
| 76 | struct usb_ehci *ehci = p->ehci; |
| 77 | int ret; |
| 78 | |
| 79 | ret = ehci_deregister(dev); |
| 80 | if (ret) |
| 81 | return ret; |
| 82 | |
| 83 | /* Stop controller. */ |
| 84 | clrbits_le32(&ehci->usbcmd, CMD_RUN); |
| 85 | |
Ramon Fried | 0ac0b6e | 2018-09-21 13:35:50 +0300 | [diff] [blame] | 86 | ret = ehci_shutdown_phy(dev, &p->phy); |
| 87 | if (ret) |
| 88 | return ret; |
Mateusz Kulikowski | 5a82211 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 89 | |
Ramon Fried | cd8c3ae | 2018-09-21 13:35:43 +0300 | [diff] [blame] | 90 | ret = board_usb_init(0, USB_INIT_DEVICE); /* Board specific hook */ |
Mateusz Kulikowski | 5a82211 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 91 | if (ret < 0) |
| 92 | return ret; |
| 93 | |
| 94 | /* Reset controller */ |
| 95 | setbits_le32(&ehci->usbcmd, CMD_RESET); |
| 96 | |
| 97 | /* Wait for reset */ |
Álvaro Fernández Rojas | 4826350 | 2018-01-23 17:14:55 +0100 | [diff] [blame] | 98 | if (wait_for_bit_le32(&ehci->usbcmd, CMD_RESET, false, 30, false)) { |
Mateusz Kulikowski | 5a82211 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 99 | printf("Stuck on USB reset.\n"); |
| 100 | return -ETIMEDOUT; |
| 101 | } |
| 102 | |
| 103 | return 0; |
| 104 | } |
| 105 | |
| 106 | static int ehci_usb_ofdata_to_platdata(struct udevice *dev) |
| 107 | { |
| 108 | struct msm_ehci_priv *priv = dev_get_priv(dev); |
| 109 | |
| 110 | priv->ulpi_vp.port_num = 0; |
Simon Glass | a821c4a | 2017-05-17 17:18:05 -0600 | [diff] [blame] | 111 | priv->ehci = (void *)devfdt_get_addr(dev); |
Mateusz Kulikowski | 5a82211 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 112 | |
| 113 | if (priv->ehci == (void *)FDT_ADDR_T_NONE) |
| 114 | return -EINVAL; |
| 115 | |
| 116 | /* Warning: this will not work if viewport address is > 64 bit due to |
| 117 | * ULPI design. |
| 118 | */ |
| 119 | priv->ulpi_vp.viewport_addr = (phys_addr_t)&priv->ehci->ulpi_viewpoint; |
| 120 | |
| 121 | return 0; |
| 122 | } |
| 123 | |
| 124 | static const struct udevice_id ehci_usb_ids[] = { |
| 125 | { .compatible = "qcom,ehci-host", }, |
| 126 | { } |
| 127 | }; |
| 128 | |
| 129 | U_BOOT_DRIVER(usb_ehci) = { |
| 130 | .name = "ehci_msm", |
| 131 | .id = UCLASS_USB, |
| 132 | .of_match = ehci_usb_ids, |
| 133 | .ofdata_to_platdata = ehci_usb_ofdata_to_platdata, |
| 134 | .probe = ehci_usb_probe, |
| 135 | .remove = ehci_usb_remove, |
| 136 | .ops = &ehci_usb_ops, |
| 137 | .priv_auto_alloc_size = sizeof(struct msm_ehci_priv), |
Ramon Fried | 2df4923 | 2018-09-21 13:35:44 +0300 | [diff] [blame] | 138 | .platdata_auto_alloc_size = sizeof(struct usb_platdata), |
Mateusz Kulikowski | 5a82211 | 2016-03-31 23:12:26 +0200 | [diff] [blame] | 139 | .flags = DM_FLAG_ALLOC_PRIV_DMA, |
| 140 | }; |