Rajeshwari Shinde | 5f0ffea | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 1 | /* |
Rajeshwari Shinde | 7590d3c | 2012-05-21 16:38:03 +0530 | [diff] [blame] | 2 | * SAMSUNG EXYNOS USB HOST EHCI Controller |
Rajeshwari Shinde | 5f0ffea | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2012 Samsung Electronics Co.Ltd |
| 5 | * Vivek Gautam <gautam.vivek@samsung.com> |
| 6 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 7 | * SPDX-License-Identifier: GPL-2.0+ |
Rajeshwari Shinde | 5f0ffea | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
Rajeshwari Shinde | e18bf1f | 2013-01-07 23:35:03 +0000 | [diff] [blame] | 11 | #include <fdtdec.h> |
| 12 | #include <libfdt.h> |
| 13 | #include <malloc.h> |
Rajeshwari Shinde | 5f0ffea | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 14 | #include <usb.h> |
| 15 | #include <asm/arch/cpu.h> |
Rajeshwari Shinde | 7590d3c | 2012-05-21 16:38:03 +0530 | [diff] [blame] | 16 | #include <asm/arch/ehci.h> |
Rajeshwari Shinde | 71045da | 2012-05-14 05:52:02 +0000 | [diff] [blame] | 17 | #include <asm/arch/system.h> |
Rajeshwari Shinde | c48ac11 | 2012-05-14 05:52:03 +0000 | [diff] [blame] | 18 | #include <asm/arch/power.h> |
Julius Werner | 4a271cb | 2013-09-14 14:02:52 +0530 | [diff] [blame] | 19 | #include <asm/gpio.h> |
Rajeshwari Shinde | e18bf1f | 2013-01-07 23:35:03 +0000 | [diff] [blame] | 20 | #include <asm-generic/errno.h> |
| 21 | #include <linux/compat.h> |
Rajeshwari Shinde | 5f0ffea | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 22 | #include "ehci.h" |
Rajeshwari Shinde | 5f0ffea | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 23 | |
Rajeshwari Shinde | e18bf1f | 2013-01-07 23:35:03 +0000 | [diff] [blame] | 24 | /* Declare global data pointer */ |
| 25 | DECLARE_GLOBAL_DATA_PTR; |
| 26 | |
| 27 | /** |
| 28 | * Contains pointers to register base addresses |
| 29 | * for the usb controller. |
| 30 | */ |
| 31 | struct exynos_ehci { |
| 32 | struct exynos_usb_phy *usb; |
Vivek Gautam | 24a4775 | 2013-03-06 14:18:32 +0530 | [diff] [blame] | 33 | struct ehci_hccr *hcd; |
Julius Werner | 4a271cb | 2013-09-14 14:02:52 +0530 | [diff] [blame] | 34 | struct fdt_gpio_state vbus_gpio; |
Rajeshwari Shinde | e18bf1f | 2013-01-07 23:35:03 +0000 | [diff] [blame] | 35 | }; |
| 36 | |
Vivek Gautam | 24a4775 | 2013-03-06 14:18:32 +0530 | [diff] [blame] | 37 | static struct exynos_ehci exynos; |
| 38 | |
Vivek Gautam | c74b011 | 2013-03-06 14:18:33 +0530 | [diff] [blame] | 39 | #ifdef CONFIG_OF_CONTROL |
Rajeshwari Shinde | e18bf1f | 2013-01-07 23:35:03 +0000 | [diff] [blame] | 40 | static int exynos_usb_parse_dt(const void *blob, struct exynos_ehci *exynos) |
| 41 | { |
Vivek Gautam | 24a4775 | 2013-03-06 14:18:32 +0530 | [diff] [blame] | 42 | fdt_addr_t addr; |
Rajeshwari Shinde | e18bf1f | 2013-01-07 23:35:03 +0000 | [diff] [blame] | 43 | unsigned int node; |
| 44 | int depth; |
| 45 | |
| 46 | node = fdtdec_next_compatible(blob, 0, COMPAT_SAMSUNG_EXYNOS_EHCI); |
| 47 | if (node <= 0) { |
| 48 | debug("EHCI: Can't get device node for ehci\n"); |
| 49 | return -ENODEV; |
| 50 | } |
| 51 | |
| 52 | /* |
| 53 | * Get the base address for EHCI controller from the device node |
| 54 | */ |
Vivek Gautam | 24a4775 | 2013-03-06 14:18:32 +0530 | [diff] [blame] | 55 | addr = fdtdec_get_addr(blob, node, "reg"); |
| 56 | if (addr == FDT_ADDR_T_NONE) { |
Rajeshwari Shinde | e18bf1f | 2013-01-07 23:35:03 +0000 | [diff] [blame] | 57 | debug("Can't get the EHCI register address\n"); |
| 58 | return -ENXIO; |
| 59 | } |
| 60 | |
Vivek Gautam | 24a4775 | 2013-03-06 14:18:32 +0530 | [diff] [blame] | 61 | exynos->hcd = (struct ehci_hccr *)addr; |
| 62 | |
Julius Werner | 4a271cb | 2013-09-14 14:02:52 +0530 | [diff] [blame] | 63 | /* Vbus gpio */ |
| 64 | fdtdec_decode_gpio(blob, node, "samsung,vbus-gpio", &exynos->vbus_gpio); |
| 65 | |
Rajeshwari Shinde | e18bf1f | 2013-01-07 23:35:03 +0000 | [diff] [blame] | 66 | depth = 0; |
| 67 | node = fdtdec_next_compatible_subnode(blob, node, |
| 68 | COMPAT_SAMSUNG_EXYNOS_USB_PHY, &depth); |
| 69 | if (node <= 0) { |
| 70 | debug("EHCI: Can't get device node for usb-phy controller\n"); |
| 71 | return -ENODEV; |
| 72 | } |
| 73 | |
| 74 | /* |
| 75 | * Get the base address for usbphy from the device node |
| 76 | */ |
| 77 | exynos->usb = (struct exynos_usb_phy *)fdtdec_get_addr(blob, node, |
| 78 | "reg"); |
| 79 | if (exynos->usb == NULL) { |
| 80 | debug("Can't get the usbphy register address\n"); |
| 81 | return -ENXIO; |
| 82 | } |
| 83 | |
| 84 | return 0; |
| 85 | } |
Vivek Gautam | c74b011 | 2013-03-06 14:18:33 +0530 | [diff] [blame] | 86 | #endif |
Rajeshwari Shinde | e18bf1f | 2013-01-07 23:35:03 +0000 | [diff] [blame] | 87 | |
Rajeshwari Shinde | 5f0ffea | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 88 | /* Setup the EHCI host controller. */ |
Rajeshwari Shinde | 7590d3c | 2012-05-21 16:38:03 +0530 | [diff] [blame] | 89 | static void setup_usb_phy(struct exynos_usb_phy *usb) |
Rajeshwari Shinde | 5f0ffea | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 90 | { |
Inderpal Singh | 16f9480 | 2014-01-08 09:19:56 +0530 | [diff] [blame] | 91 | u32 hsic_ctrl; |
| 92 | |
Rajeshwari Shinde | 71045da | 2012-05-14 05:52:02 +0000 | [diff] [blame] | 93 | set_usbhost_mode(USB20_PHY_CFG_HOST_LINK_EN); |
| 94 | |
Rajeshwari Shinde | c48ac11 | 2012-05-14 05:52:03 +0000 | [diff] [blame] | 95 | set_usbhost_phy_ctrl(POWER_USB_HOST_PHY_CTRL_EN); |
| 96 | |
Rajeshwari Shinde | 5f0ffea | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 97 | clrbits_le32(&usb->usbphyctrl0, |
| 98 | HOST_CTRL0_FSEL_MASK | |
| 99 | HOST_CTRL0_COMMONON_N | |
| 100 | /* HOST Phy setting */ |
| 101 | HOST_CTRL0_PHYSWRST | |
| 102 | HOST_CTRL0_PHYSWRSTALL | |
| 103 | HOST_CTRL0_SIDDQ | |
| 104 | HOST_CTRL0_FORCESUSPEND | |
| 105 | HOST_CTRL0_FORCESLEEP); |
| 106 | |
| 107 | setbits_le32(&usb->usbphyctrl0, |
| 108 | /* Setting up the ref freq */ |
| 109 | (CLK_24MHZ << 16) | |
| 110 | /* HOST Phy setting */ |
| 111 | HOST_CTRL0_LINKSWRST | |
| 112 | HOST_CTRL0_UTMISWRST); |
| 113 | udelay(10); |
| 114 | clrbits_le32(&usb->usbphyctrl0, |
| 115 | HOST_CTRL0_LINKSWRST | |
| 116 | HOST_CTRL0_UTMISWRST); |
Inderpal Singh | 16f9480 | 2014-01-08 09:19:56 +0530 | [diff] [blame] | 117 | |
| 118 | /* HSIC Phy Setting */ |
| 119 | hsic_ctrl = (HSIC_CTRL_FORCESUSPEND | |
| 120 | HSIC_CTRL_FORCESLEEP | |
| 121 | HSIC_CTRL_SIDDQ); |
| 122 | |
| 123 | clrbits_le32(&usb->hsicphyctrl1, hsic_ctrl); |
| 124 | clrbits_le32(&usb->hsicphyctrl2, hsic_ctrl); |
| 125 | |
| 126 | hsic_ctrl = (((HSIC_CTRL_REFCLKDIV_12 & HSIC_CTRL_REFCLKDIV_MASK) |
| 127 | << HSIC_CTRL_REFCLKDIV_SHIFT) |
| 128 | | ((HSIC_CTRL_REFCLKSEL & HSIC_CTRL_REFCLKSEL_MASK) |
| 129 | << HSIC_CTRL_REFCLKSEL_SHIFT) |
| 130 | | HSIC_CTRL_UTMISWRST); |
| 131 | |
| 132 | setbits_le32(&usb->hsicphyctrl1, hsic_ctrl); |
| 133 | setbits_le32(&usb->hsicphyctrl2, hsic_ctrl); |
| 134 | |
| 135 | udelay(10); |
| 136 | |
| 137 | clrbits_le32(&usb->hsicphyctrl1, HSIC_CTRL_PHYSWRST | |
| 138 | HSIC_CTRL_UTMISWRST); |
| 139 | |
| 140 | clrbits_le32(&usb->hsicphyctrl2, HSIC_CTRL_PHYSWRST | |
| 141 | HSIC_CTRL_UTMISWRST); |
| 142 | |
Rajeshwari Shinde | 5f0ffea | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 143 | udelay(20); |
| 144 | |
| 145 | /* EHCI Ctrl setting */ |
| 146 | setbits_le32(&usb->ehcictrl, |
| 147 | EHCICTRL_ENAINCRXALIGN | |
| 148 | EHCICTRL_ENAINCR4 | |
| 149 | EHCICTRL_ENAINCR8 | |
| 150 | EHCICTRL_ENAINCR16); |
| 151 | } |
| 152 | |
| 153 | /* Reset the EHCI host controller. */ |
Rajeshwari Shinde | 7590d3c | 2012-05-21 16:38:03 +0530 | [diff] [blame] | 154 | static void reset_usb_phy(struct exynos_usb_phy *usb) |
Rajeshwari Shinde | 5f0ffea | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 155 | { |
Inderpal Singh | 16f9480 | 2014-01-08 09:19:56 +0530 | [diff] [blame] | 156 | u32 hsic_ctrl; |
| 157 | |
Rajeshwari Shinde | 5f0ffea | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 158 | /* HOST_PHY reset */ |
| 159 | setbits_le32(&usb->usbphyctrl0, |
| 160 | HOST_CTRL0_PHYSWRST | |
| 161 | HOST_CTRL0_PHYSWRSTALL | |
| 162 | HOST_CTRL0_SIDDQ | |
| 163 | HOST_CTRL0_FORCESUSPEND | |
| 164 | HOST_CTRL0_FORCESLEEP); |
Rajeshwari Shinde | c48ac11 | 2012-05-14 05:52:03 +0000 | [diff] [blame] | 165 | |
Inderpal Singh | 16f9480 | 2014-01-08 09:19:56 +0530 | [diff] [blame] | 166 | /* HSIC Phy reset */ |
| 167 | hsic_ctrl = (HSIC_CTRL_FORCESUSPEND | |
| 168 | HSIC_CTRL_FORCESLEEP | |
| 169 | HSIC_CTRL_SIDDQ | |
| 170 | HSIC_CTRL_PHYSWRST); |
| 171 | |
| 172 | setbits_le32(&usb->hsicphyctrl1, hsic_ctrl); |
| 173 | setbits_le32(&usb->hsicphyctrl2, hsic_ctrl); |
| 174 | |
Rajeshwari Shinde | c48ac11 | 2012-05-14 05:52:03 +0000 | [diff] [blame] | 175 | set_usbhost_phy_ctrl(POWER_USB_HOST_PHY_CTRL_DISABLE); |
Rajeshwari Shinde | 5f0ffea | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | /* |
| 179 | * EHCI-initialization |
| 180 | * Create the appropriate control structures to manage |
| 181 | * a new EHCI host controller. |
| 182 | */ |
Troy Kisky | 127efc4 | 2013-10-10 15:27:57 -0700 | [diff] [blame] | 183 | int ehci_hcd_init(int index, enum usb_init_type init, |
| 184 | struct ehci_hccr **hccr, struct ehci_hcor **hcor) |
Rajeshwari Shinde | 5f0ffea | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 185 | { |
Vivek Gautam | 24a4775 | 2013-03-06 14:18:32 +0530 | [diff] [blame] | 186 | struct exynos_ehci *ctx = &exynos; |
Rajeshwari Shinde | 5f0ffea | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 187 | |
Vivek Gautam | c74b011 | 2013-03-06 14:18:33 +0530 | [diff] [blame] | 188 | #ifdef CONFIG_OF_CONTROL |
Vivek Gautam | 24a4775 | 2013-03-06 14:18:32 +0530 | [diff] [blame] | 189 | if (exynos_usb_parse_dt(gd->fdt_blob, ctx)) { |
| 190 | debug("Unable to parse device tree for ehci-exynos\n"); |
| 191 | return -ENODEV; |
Rajeshwari Shinde | e18bf1f | 2013-01-07 23:35:03 +0000 | [diff] [blame] | 192 | } |
Vivek Gautam | c74b011 | 2013-03-06 14:18:33 +0530 | [diff] [blame] | 193 | #else |
| 194 | ctx->usb = (struct exynos_usb_phy *)samsung_get_base_usb_phy(); |
| 195 | ctx->hcd = (struct ehci_hccr *)samsung_get_base_usb_ehci(); |
| 196 | #endif |
Rajeshwari Shinde | 5f0ffea | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 197 | |
Julius Werner | 4a271cb | 2013-09-14 14:02:52 +0530 | [diff] [blame] | 198 | #ifdef CONFIG_OF_CONTROL |
| 199 | /* setup the Vbus gpio here */ |
andrey.konovalov@linaro.org | e6e493f | 2014-04-22 21:23:49 +0400 | [diff] [blame] | 200 | if (fdt_gpio_isvalid(&ctx->vbus_gpio) && |
| 201 | !fdtdec_setup_gpio(&ctx->vbus_gpio)) |
Julius Werner | 4a271cb | 2013-09-14 14:02:52 +0530 | [diff] [blame] | 202 | gpio_direction_output(ctx->vbus_gpio.gpio, 1); |
| 203 | #endif |
| 204 | |
Vivek Gautam | 24a4775 | 2013-03-06 14:18:32 +0530 | [diff] [blame] | 205 | setup_usb_phy(ctx->usb); |
Rajeshwari Shinde | e18bf1f | 2013-01-07 23:35:03 +0000 | [diff] [blame] | 206 | |
Inderpal Singh | 7da7651 | 2014-01-08 09:19:57 +0530 | [diff] [blame] | 207 | board_usb_init(index, init); |
| 208 | |
Vivek Gautam | 24a4775 | 2013-03-06 14:18:32 +0530 | [diff] [blame] | 209 | *hccr = ctx->hcd; |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 210 | *hcor = (struct ehci_hcor *)((uint32_t) *hccr |
| 211 | + HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase))); |
Rajeshwari Shinde | 5f0ffea | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 212 | |
| 213 | debug("Exynos5-ehci: init hccr %x and hcor %x hc_length %d\n", |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 214 | (uint32_t)*hccr, (uint32_t)*hcor, |
| 215 | (uint32_t)HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase))); |
Rajeshwari Shinde | 5f0ffea | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 216 | |
| 217 | return 0; |
| 218 | } |
| 219 | |
| 220 | /* |
| 221 | * Destroy the appropriate control structures corresponding |
| 222 | * the EHCI host controller. |
| 223 | */ |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 224 | int ehci_hcd_stop(int index) |
Rajeshwari Shinde | 5f0ffea | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 225 | { |
Vivek Gautam | 24a4775 | 2013-03-06 14:18:32 +0530 | [diff] [blame] | 226 | struct exynos_ehci *ctx = &exynos; |
Rajeshwari Shinde | 5f0ffea | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 227 | |
Vivek Gautam | 24a4775 | 2013-03-06 14:18:32 +0530 | [diff] [blame] | 228 | reset_usb_phy(ctx->usb); |
Rajeshwari Shinde | 5f0ffea | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 229 | |
| 230 | return 0; |
| 231 | } |