Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Rajeshwari Shinde | 9b4ae50 | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 2 | /* |
Rajeshwari Shinde | dad39d4 | 2012-05-21 16:38:03 +0530 | [diff] [blame] | 3 | * SAMSUNG EXYNOS USB HOST EHCI Controller |
Rajeshwari Shinde | 9b4ae50 | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 4 | * |
| 5 | * Copyright (C) 2012 Samsung Electronics Co.Ltd |
| 6 | * Vivek Gautam <gautam.vivek@samsung.com> |
Rajeshwari Shinde | 9b4ae50 | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
Simon Glass | 2b8ceec | 2015-03-25 12:22:44 -0600 | [diff] [blame] | 10 | #include <dm.h> |
Rajeshwari Shinde | 23fbde5 | 2013-01-07 23:35:03 +0000 | [diff] [blame] | 11 | #include <fdtdec.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 12 | #include <log.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 13 | #include <asm/global_data.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 14 | #include <linux/delay.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 15 | #include <linux/libfdt.h> |
Rajeshwari Shinde | 23fbde5 | 2013-01-07 23:35:03 +0000 | [diff] [blame] | 16 | #include <malloc.h> |
Rajeshwari Shinde | 9b4ae50 | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 17 | #include <usb.h> |
| 18 | #include <asm/arch/cpu.h> |
Rajeshwari Shinde | dad39d4 | 2012-05-21 16:38:03 +0530 | [diff] [blame] | 19 | #include <asm/arch/ehci.h> |
Rajeshwari Shinde | 8444807 | 2012-05-14 05:52:02 +0000 | [diff] [blame] | 20 | #include <asm/arch/system.h> |
Rajeshwari Shinde | 21965ac | 2012-05-14 05:52:03 +0000 | [diff] [blame] | 21 | #include <asm/arch/power.h> |
Julius Werner | ddcb9bd | 2013-09-14 14:02:52 +0530 | [diff] [blame] | 22 | #include <asm/gpio.h> |
Masahiro Yamada | 64e4f7f | 2016-09-21 11:28:57 +0900 | [diff] [blame] | 23 | #include <linux/errno.h> |
Rajeshwari Shinde | 23fbde5 | 2013-01-07 23:35:03 +0000 | [diff] [blame] | 24 | #include <linux/compat.h> |
Rajeshwari Shinde | 9b4ae50 | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 25 | #include "ehci.h" |
Rajeshwari Shinde | 9b4ae50 | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 26 | |
Rajeshwari Shinde | 23fbde5 | 2013-01-07 23:35:03 +0000 | [diff] [blame] | 27 | /* Declare global data pointer */ |
| 28 | DECLARE_GLOBAL_DATA_PTR; |
| 29 | |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 30 | struct exynos_ehci_plat { |
| 31 | struct usb_plat usb_plat; |
Simon Glass | 2b8ceec | 2015-03-25 12:22:44 -0600 | [diff] [blame] | 32 | fdt_addr_t hcd_base; |
| 33 | fdt_addr_t phy_base; |
| 34 | struct gpio_desc vbus_gpio; |
| 35 | }; |
Simon Glass | 2b8ceec | 2015-03-25 12:22:44 -0600 | [diff] [blame] | 36 | |
Rajeshwari Shinde | 23fbde5 | 2013-01-07 23:35:03 +0000 | [diff] [blame] | 37 | /** |
| 38 | * Contains pointers to register base addresses |
| 39 | * for the usb controller. |
| 40 | */ |
| 41 | struct exynos_ehci { |
Simon Glass | 2b8ceec | 2015-03-25 12:22:44 -0600 | [diff] [blame] | 42 | struct ehci_ctrl ctrl; |
Rajeshwari Shinde | 23fbde5 | 2013-01-07 23:35:03 +0000 | [diff] [blame] | 43 | struct exynos_usb_phy *usb; |
Vivek Gautam | bab686c | 2013-03-06 14:18:32 +0530 | [diff] [blame] | 44 | struct ehci_hccr *hcd; |
Rajeshwari Shinde | 23fbde5 | 2013-01-07 23:35:03 +0000 | [diff] [blame] | 45 | }; |
| 46 | |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 47 | static int ehci_usb_of_to_plat(struct udevice *dev) |
Simon Glass | 2b8ceec | 2015-03-25 12:22:44 -0600 | [diff] [blame] | 48 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 49 | struct exynos_ehci_plat *plat = dev_get_plat(dev); |
Simon Glass | 2b8ceec | 2015-03-25 12:22:44 -0600 | [diff] [blame] | 50 | const void *blob = gd->fdt_blob; |
| 51 | unsigned int node; |
| 52 | int depth; |
| 53 | |
| 54 | /* |
| 55 | * Get the base address for XHCI controller from the device node |
| 56 | */ |
Masahiro Yamada | a89b4de | 2020-07-17 14:36:48 +0900 | [diff] [blame] | 57 | plat->hcd_base = dev_read_addr(dev); |
Simon Glass | 2b8ceec | 2015-03-25 12:22:44 -0600 | [diff] [blame] | 58 | if (plat->hcd_base == FDT_ADDR_T_NONE) { |
| 59 | debug("Can't get the XHCI register base address\n"); |
| 60 | return -ENXIO; |
| 61 | } |
| 62 | |
| 63 | depth = 0; |
Simon Glass | dd79d6e | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 64 | node = fdtdec_next_compatible_subnode(blob, dev_of_offset(dev), |
Simon Glass | 2b8ceec | 2015-03-25 12:22:44 -0600 | [diff] [blame] | 65 | COMPAT_SAMSUNG_EXYNOS_USB_PHY, &depth); |
| 66 | if (node <= 0) { |
| 67 | debug("XHCI: Can't get device node for usb3-phy controller\n"); |
| 68 | return -ENODEV; |
| 69 | } |
| 70 | |
| 71 | /* |
| 72 | * Get the base address for usbphy from the device node |
| 73 | */ |
| 74 | plat->phy_base = fdtdec_get_addr(blob, node, "reg"); |
| 75 | if (plat->phy_base == FDT_ADDR_T_NONE) { |
| 76 | debug("Can't get the usbphy register address\n"); |
| 77 | return -ENXIO; |
| 78 | } |
| 79 | |
| 80 | /* Vbus gpio */ |
| 81 | gpio_request_by_name(dev, "samsung,vbus-gpio", 0, |
| 82 | &plat->vbus_gpio, GPIOD_IS_OUT); |
| 83 | |
| 84 | return 0; |
| 85 | } |
Rajeshwari Shinde | 23fbde5 | 2013-01-07 23:35:03 +0000 | [diff] [blame] | 86 | |
Suriyan Ramasami | 97f4ef6 | 2014-10-29 09:22:43 -0700 | [diff] [blame] | 87 | static void exynos5_setup_usb_phy(struct exynos_usb_phy *usb) |
Rajeshwari Shinde | 9b4ae50 | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 88 | { |
Inderpal Singh | 2eb6561 | 2014-01-08 09:19:56 +0530 | [diff] [blame] | 89 | u32 hsic_ctrl; |
| 90 | |
Rajeshwari Shinde | 9b4ae50 | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 91 | clrbits_le32(&usb->usbphyctrl0, |
| 92 | HOST_CTRL0_FSEL_MASK | |
| 93 | HOST_CTRL0_COMMONON_N | |
| 94 | /* HOST Phy setting */ |
| 95 | HOST_CTRL0_PHYSWRST | |
| 96 | HOST_CTRL0_PHYSWRSTALL | |
| 97 | HOST_CTRL0_SIDDQ | |
| 98 | HOST_CTRL0_FORCESUSPEND | |
| 99 | HOST_CTRL0_FORCESLEEP); |
| 100 | |
| 101 | setbits_le32(&usb->usbphyctrl0, |
| 102 | /* Setting up the ref freq */ |
| 103 | (CLK_24MHZ << 16) | |
| 104 | /* HOST Phy setting */ |
| 105 | HOST_CTRL0_LINKSWRST | |
| 106 | HOST_CTRL0_UTMISWRST); |
| 107 | udelay(10); |
| 108 | clrbits_le32(&usb->usbphyctrl0, |
| 109 | HOST_CTRL0_LINKSWRST | |
| 110 | HOST_CTRL0_UTMISWRST); |
Inderpal Singh | 2eb6561 | 2014-01-08 09:19:56 +0530 | [diff] [blame] | 111 | |
| 112 | /* HSIC Phy Setting */ |
| 113 | hsic_ctrl = (HSIC_CTRL_FORCESUSPEND | |
| 114 | HSIC_CTRL_FORCESLEEP | |
| 115 | HSIC_CTRL_SIDDQ); |
| 116 | |
| 117 | clrbits_le32(&usb->hsicphyctrl1, hsic_ctrl); |
| 118 | clrbits_le32(&usb->hsicphyctrl2, hsic_ctrl); |
| 119 | |
| 120 | hsic_ctrl = (((HSIC_CTRL_REFCLKDIV_12 & HSIC_CTRL_REFCLKDIV_MASK) |
| 121 | << HSIC_CTRL_REFCLKDIV_SHIFT) |
| 122 | | ((HSIC_CTRL_REFCLKSEL & HSIC_CTRL_REFCLKSEL_MASK) |
| 123 | << HSIC_CTRL_REFCLKSEL_SHIFT) |
| 124 | | HSIC_CTRL_UTMISWRST); |
| 125 | |
| 126 | setbits_le32(&usb->hsicphyctrl1, hsic_ctrl); |
| 127 | setbits_le32(&usb->hsicphyctrl2, hsic_ctrl); |
| 128 | |
| 129 | udelay(10); |
| 130 | |
| 131 | clrbits_le32(&usb->hsicphyctrl1, HSIC_CTRL_PHYSWRST | |
| 132 | HSIC_CTRL_UTMISWRST); |
| 133 | |
| 134 | clrbits_le32(&usb->hsicphyctrl2, HSIC_CTRL_PHYSWRST | |
| 135 | HSIC_CTRL_UTMISWRST); |
| 136 | |
Rajeshwari Shinde | 9b4ae50 | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 137 | udelay(20); |
| 138 | |
| 139 | /* EHCI Ctrl setting */ |
| 140 | setbits_le32(&usb->ehcictrl, |
| 141 | EHCICTRL_ENAINCRXALIGN | |
| 142 | EHCICTRL_ENAINCR4 | |
| 143 | EHCICTRL_ENAINCR8 | |
| 144 | EHCICTRL_ENAINCR16); |
| 145 | } |
| 146 | |
Suriyan Ramasami | 97f4ef6 | 2014-10-29 09:22:43 -0700 | [diff] [blame] | 147 | static void exynos4412_setup_usb_phy(struct exynos4412_usb_phy *usb) |
| 148 | { |
| 149 | writel(CLK_24MHZ, &usb->usbphyclk); |
| 150 | |
| 151 | clrbits_le32(&usb->usbphyctrl, (PHYPWR_NORMAL_MASK_HSIC0 | |
| 152 | PHYPWR_NORMAL_MASK_HSIC1 | PHYPWR_NORMAL_MASK_PHY1 | |
| 153 | PHYPWR_NORMAL_MASK_PHY0)); |
| 154 | |
| 155 | setbits_le32(&usb->usbphyrstcon, (RSTCON_HOSTPHY_SWRST | RSTCON_SWRST)); |
| 156 | udelay(10); |
| 157 | clrbits_le32(&usb->usbphyrstcon, (RSTCON_HOSTPHY_SWRST | RSTCON_SWRST)); |
| 158 | } |
| 159 | |
| 160 | static void setup_usb_phy(struct exynos_usb_phy *usb) |
| 161 | { |
| 162 | set_usbhost_mode(USB20_PHY_CFG_HOST_LINK_EN); |
| 163 | |
| 164 | set_usbhost_phy_ctrl(POWER_USB_HOST_PHY_CTRL_EN); |
| 165 | |
| 166 | if (cpu_is_exynos5()) |
| 167 | exynos5_setup_usb_phy(usb); |
| 168 | else if (cpu_is_exynos4()) |
| 169 | if (proid_is_exynos4412()) |
| 170 | exynos4412_setup_usb_phy((struct exynos4412_usb_phy *) |
| 171 | usb); |
| 172 | } |
| 173 | |
| 174 | static void exynos5_reset_usb_phy(struct exynos_usb_phy *usb) |
Rajeshwari Shinde | 9b4ae50 | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 175 | { |
Inderpal Singh | 2eb6561 | 2014-01-08 09:19:56 +0530 | [diff] [blame] | 176 | u32 hsic_ctrl; |
| 177 | |
Rajeshwari Shinde | 9b4ae50 | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 178 | /* HOST_PHY reset */ |
| 179 | setbits_le32(&usb->usbphyctrl0, |
| 180 | HOST_CTRL0_PHYSWRST | |
| 181 | HOST_CTRL0_PHYSWRSTALL | |
| 182 | HOST_CTRL0_SIDDQ | |
| 183 | HOST_CTRL0_FORCESUSPEND | |
| 184 | HOST_CTRL0_FORCESLEEP); |
Rajeshwari Shinde | 21965ac | 2012-05-14 05:52:03 +0000 | [diff] [blame] | 185 | |
Inderpal Singh | 2eb6561 | 2014-01-08 09:19:56 +0530 | [diff] [blame] | 186 | /* HSIC Phy reset */ |
| 187 | hsic_ctrl = (HSIC_CTRL_FORCESUSPEND | |
| 188 | HSIC_CTRL_FORCESLEEP | |
| 189 | HSIC_CTRL_SIDDQ | |
| 190 | HSIC_CTRL_PHYSWRST); |
| 191 | |
| 192 | setbits_le32(&usb->hsicphyctrl1, hsic_ctrl); |
| 193 | setbits_le32(&usb->hsicphyctrl2, hsic_ctrl); |
Suriyan Ramasami | 97f4ef6 | 2014-10-29 09:22:43 -0700 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | static void exynos4412_reset_usb_phy(struct exynos4412_usb_phy *usb) |
| 197 | { |
| 198 | setbits_le32(&usb->usbphyctrl, (PHYPWR_NORMAL_MASK_HSIC0 | |
| 199 | PHYPWR_NORMAL_MASK_HSIC1 | PHYPWR_NORMAL_MASK_PHY1 | |
| 200 | PHYPWR_NORMAL_MASK_PHY0)); |
| 201 | } |
| 202 | |
| 203 | /* Reset the EHCI host controller. */ |
| 204 | static void reset_usb_phy(struct exynos_usb_phy *usb) |
| 205 | { |
| 206 | if (cpu_is_exynos5()) |
| 207 | exynos5_reset_usb_phy(usb); |
| 208 | else if (cpu_is_exynos4()) |
| 209 | if (proid_is_exynos4412()) |
| 210 | exynos4412_reset_usb_phy((struct exynos4412_usb_phy *) |
| 211 | usb); |
Inderpal Singh | 2eb6561 | 2014-01-08 09:19:56 +0530 | [diff] [blame] | 212 | |
Rajeshwari Shinde | 21965ac | 2012-05-14 05:52:03 +0000 | [diff] [blame] | 213 | set_usbhost_phy_ctrl(POWER_USB_HOST_PHY_CTRL_DISABLE); |
Rajeshwari Shinde | 9b4ae50 | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 214 | } |
Simon Glass | 2b8ceec | 2015-03-25 12:22:44 -0600 | [diff] [blame] | 215 | |
Simon Glass | 2b8ceec | 2015-03-25 12:22:44 -0600 | [diff] [blame] | 216 | static int ehci_usb_probe(struct udevice *dev) |
| 217 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 218 | struct exynos_ehci_plat *plat = dev_get_plat(dev); |
Simon Glass | 2b8ceec | 2015-03-25 12:22:44 -0600 | [diff] [blame] | 219 | struct exynos_ehci *ctx = dev_get_priv(dev); |
| 220 | struct ehci_hcor *hcor; |
| 221 | |
| 222 | ctx->hcd = (struct ehci_hccr *)plat->hcd_base; |
| 223 | ctx->usb = (struct exynos_usb_phy *)plat->phy_base; |
Simon Glass | 2b8ceec | 2015-03-25 12:22:44 -0600 | [diff] [blame] | 224 | |
| 225 | /* setup the Vbus gpio here */ |
| 226 | if (dm_gpio_is_valid(&plat->vbus_gpio)) |
| 227 | dm_gpio_set_value(&plat->vbus_gpio, 1); |
| 228 | |
| 229 | setup_usb_phy(ctx->usb); |
Lukasz Majewski | a9f74bb | 2015-12-10 16:32:25 +0100 | [diff] [blame] | 230 | hcor = (struct ehci_hcor *)((uint32_t)ctx->hcd + |
| 231 | HC_LENGTH(ehci_readl(&ctx->hcd->cr_capbase))); |
Simon Glass | 2b8ceec | 2015-03-25 12:22:44 -0600 | [diff] [blame] | 232 | |
| 233 | return ehci_register(dev, ctx->hcd, hcor, NULL, 0, USB_INIT_HOST); |
| 234 | } |
| 235 | |
| 236 | static int ehci_usb_remove(struct udevice *dev) |
| 237 | { |
| 238 | struct exynos_ehci *ctx = dev_get_priv(dev); |
| 239 | int ret; |
| 240 | |
| 241 | ret = ehci_deregister(dev); |
| 242 | if (ret) |
| 243 | return ret; |
| 244 | reset_usb_phy(ctx->usb); |
| 245 | |
| 246 | return 0; |
| 247 | } |
| 248 | |
| 249 | static const struct udevice_id ehci_usb_ids[] = { |
| 250 | { .compatible = "samsung,exynos-ehci" }, |
| 251 | { } |
| 252 | }; |
| 253 | |
| 254 | U_BOOT_DRIVER(usb_ehci) = { |
| 255 | .name = "ehci_exynos", |
| 256 | .id = UCLASS_USB, |
| 257 | .of_match = ehci_usb_ids, |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 258 | .of_to_plat = ehci_usb_of_to_plat, |
Simon Glass | 2b8ceec | 2015-03-25 12:22:44 -0600 | [diff] [blame] | 259 | .probe = ehci_usb_probe, |
| 260 | .remove = ehci_usb_remove, |
| 261 | .ops = &ehci_usb_ops, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 262 | .priv_auto = sizeof(struct exynos_ehci), |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 263 | .plat_auto = sizeof(struct exynos_ehci_plat), |
Simon Glass | 2b8ceec | 2015-03-25 12:22:44 -0600 | [diff] [blame] | 264 | .flags = DM_FLAG_ALLOC_PRIV_DMA, |
| 265 | }; |