Rajeshwari Shinde | 9b4ae50 | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 1 | /* |
Rajeshwari Shinde | dad39d4 | 2012-05-21 16:38:03 +0530 | [diff] [blame] | 2 | * SAMSUNG EXYNOS USB HOST EHCI Controller |
Rajeshwari Shinde | 9b4ae50 | 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 | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 7 | * SPDX-License-Identifier: GPL-2.0+ |
Rajeshwari Shinde | 9b4ae50 | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
Rajeshwari Shinde | 23fbde5 | 2013-01-07 23:35:03 +0000 | [diff] [blame] | 11 | #include <fdtdec.h> |
| 12 | #include <libfdt.h> |
| 13 | #include <malloc.h> |
Rajeshwari Shinde | 9b4ae50 | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 14 | #include <usb.h> |
| 15 | #include <asm/arch/cpu.h> |
Rajeshwari Shinde | dad39d4 | 2012-05-21 16:38:03 +0530 | [diff] [blame] | 16 | #include <asm/arch/ehci.h> |
Rajeshwari Shinde | 8444807 | 2012-05-14 05:52:02 +0000 | [diff] [blame] | 17 | #include <asm/arch/system.h> |
Rajeshwari Shinde | 21965ac | 2012-05-14 05:52:03 +0000 | [diff] [blame] | 18 | #include <asm/arch/power.h> |
Rajeshwari Shinde | 23fbde5 | 2013-01-07 23:35:03 +0000 | [diff] [blame] | 19 | #include <asm-generic/errno.h> |
| 20 | #include <linux/compat.h> |
Rajeshwari Shinde | 9b4ae50 | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 21 | #include "ehci.h" |
Rajeshwari Shinde | 9b4ae50 | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 22 | |
Rajeshwari Shinde | 23fbde5 | 2013-01-07 23:35:03 +0000 | [diff] [blame] | 23 | /* Declare global data pointer */ |
| 24 | DECLARE_GLOBAL_DATA_PTR; |
| 25 | |
| 26 | /** |
| 27 | * Contains pointers to register base addresses |
| 28 | * for the usb controller. |
| 29 | */ |
| 30 | struct exynos_ehci { |
| 31 | struct exynos_usb_phy *usb; |
Vivek Gautam | bab686c | 2013-03-06 14:18:32 +0530 | [diff] [blame] | 32 | struct ehci_hccr *hcd; |
Rajeshwari Shinde | 23fbde5 | 2013-01-07 23:35:03 +0000 | [diff] [blame] | 33 | }; |
| 34 | |
Vivek Gautam | bab686c | 2013-03-06 14:18:32 +0530 | [diff] [blame] | 35 | static struct exynos_ehci exynos; |
| 36 | |
Vivek Gautam | fac8a76 | 2013-03-06 14:18:33 +0530 | [diff] [blame] | 37 | #ifdef CONFIG_OF_CONTROL |
Rajeshwari Shinde | 23fbde5 | 2013-01-07 23:35:03 +0000 | [diff] [blame] | 38 | static int exynos_usb_parse_dt(const void *blob, struct exynos_ehci *exynos) |
| 39 | { |
Vivek Gautam | bab686c | 2013-03-06 14:18:32 +0530 | [diff] [blame] | 40 | fdt_addr_t addr; |
Rajeshwari Shinde | 23fbde5 | 2013-01-07 23:35:03 +0000 | [diff] [blame] | 41 | unsigned int node; |
| 42 | int depth; |
| 43 | |
| 44 | node = fdtdec_next_compatible(blob, 0, COMPAT_SAMSUNG_EXYNOS_EHCI); |
| 45 | if (node <= 0) { |
| 46 | debug("EHCI: Can't get device node for ehci\n"); |
| 47 | return -ENODEV; |
| 48 | } |
| 49 | |
| 50 | /* |
| 51 | * Get the base address for EHCI controller from the device node |
| 52 | */ |
Vivek Gautam | bab686c | 2013-03-06 14:18:32 +0530 | [diff] [blame] | 53 | addr = fdtdec_get_addr(blob, node, "reg"); |
| 54 | if (addr == FDT_ADDR_T_NONE) { |
Rajeshwari Shinde | 23fbde5 | 2013-01-07 23:35:03 +0000 | [diff] [blame] | 55 | debug("Can't get the EHCI register address\n"); |
| 56 | return -ENXIO; |
| 57 | } |
| 58 | |
Vivek Gautam | bab686c | 2013-03-06 14:18:32 +0530 | [diff] [blame] | 59 | exynos->hcd = (struct ehci_hccr *)addr; |
| 60 | |
Rajeshwari Shinde | 23fbde5 | 2013-01-07 23:35:03 +0000 | [diff] [blame] | 61 | depth = 0; |
| 62 | node = fdtdec_next_compatible_subnode(blob, node, |
| 63 | COMPAT_SAMSUNG_EXYNOS_USB_PHY, &depth); |
| 64 | if (node <= 0) { |
| 65 | debug("EHCI: Can't get device node for usb-phy controller\n"); |
| 66 | return -ENODEV; |
| 67 | } |
| 68 | |
| 69 | /* |
| 70 | * Get the base address for usbphy from the device node |
| 71 | */ |
| 72 | exynos->usb = (struct exynos_usb_phy *)fdtdec_get_addr(blob, node, |
| 73 | "reg"); |
| 74 | if (exynos->usb == NULL) { |
| 75 | debug("Can't get the usbphy register address\n"); |
| 76 | return -ENXIO; |
| 77 | } |
| 78 | |
| 79 | return 0; |
| 80 | } |
Vivek Gautam | fac8a76 | 2013-03-06 14:18:33 +0530 | [diff] [blame] | 81 | #endif |
Rajeshwari Shinde | 23fbde5 | 2013-01-07 23:35:03 +0000 | [diff] [blame] | 82 | |
Rajeshwari Shinde | 9b4ae50 | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 83 | /* Setup the EHCI host controller. */ |
Rajeshwari Shinde | dad39d4 | 2012-05-21 16:38:03 +0530 | [diff] [blame] | 84 | static void setup_usb_phy(struct exynos_usb_phy *usb) |
Rajeshwari Shinde | 9b4ae50 | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 85 | { |
Rajeshwari Shinde | 8444807 | 2012-05-14 05:52:02 +0000 | [diff] [blame] | 86 | set_usbhost_mode(USB20_PHY_CFG_HOST_LINK_EN); |
| 87 | |
Rajeshwari Shinde | 21965ac | 2012-05-14 05:52:03 +0000 | [diff] [blame] | 88 | set_usbhost_phy_ctrl(POWER_USB_HOST_PHY_CTRL_EN); |
| 89 | |
Rajeshwari Shinde | 9b4ae50 | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 90 | clrbits_le32(&usb->usbphyctrl0, |
| 91 | HOST_CTRL0_FSEL_MASK | |
| 92 | HOST_CTRL0_COMMONON_N | |
| 93 | /* HOST Phy setting */ |
| 94 | HOST_CTRL0_PHYSWRST | |
| 95 | HOST_CTRL0_PHYSWRSTALL | |
| 96 | HOST_CTRL0_SIDDQ | |
| 97 | HOST_CTRL0_FORCESUSPEND | |
| 98 | HOST_CTRL0_FORCESLEEP); |
| 99 | |
| 100 | setbits_le32(&usb->usbphyctrl0, |
| 101 | /* Setting up the ref freq */ |
| 102 | (CLK_24MHZ << 16) | |
| 103 | /* HOST Phy setting */ |
| 104 | HOST_CTRL0_LINKSWRST | |
| 105 | HOST_CTRL0_UTMISWRST); |
| 106 | udelay(10); |
| 107 | clrbits_le32(&usb->usbphyctrl0, |
| 108 | HOST_CTRL0_LINKSWRST | |
| 109 | HOST_CTRL0_UTMISWRST); |
| 110 | udelay(20); |
| 111 | |
| 112 | /* EHCI Ctrl setting */ |
| 113 | setbits_le32(&usb->ehcictrl, |
| 114 | EHCICTRL_ENAINCRXALIGN | |
| 115 | EHCICTRL_ENAINCR4 | |
| 116 | EHCICTRL_ENAINCR8 | |
| 117 | EHCICTRL_ENAINCR16); |
| 118 | } |
| 119 | |
| 120 | /* Reset the EHCI host controller. */ |
Rajeshwari Shinde | dad39d4 | 2012-05-21 16:38:03 +0530 | [diff] [blame] | 121 | static void reset_usb_phy(struct exynos_usb_phy *usb) |
Rajeshwari Shinde | 9b4ae50 | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 122 | { |
| 123 | /* HOST_PHY reset */ |
| 124 | setbits_le32(&usb->usbphyctrl0, |
| 125 | HOST_CTRL0_PHYSWRST | |
| 126 | HOST_CTRL0_PHYSWRSTALL | |
| 127 | HOST_CTRL0_SIDDQ | |
| 128 | HOST_CTRL0_FORCESUSPEND | |
| 129 | HOST_CTRL0_FORCESLEEP); |
Rajeshwari Shinde | 21965ac | 2012-05-14 05:52:03 +0000 | [diff] [blame] | 130 | |
| 131 | set_usbhost_phy_ctrl(POWER_USB_HOST_PHY_CTRL_DISABLE); |
Rajeshwari Shinde | 9b4ae50 | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | /* |
| 135 | * EHCI-initialization |
| 136 | * Create the appropriate control structures to manage |
| 137 | * a new EHCI host controller. |
| 138 | */ |
Lucas Stach | 3494a4c | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 139 | int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor) |
Rajeshwari Shinde | 9b4ae50 | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 140 | { |
Vivek Gautam | bab686c | 2013-03-06 14:18:32 +0530 | [diff] [blame] | 141 | struct exynos_ehci *ctx = &exynos; |
Rajeshwari Shinde | 23fbde5 | 2013-01-07 23:35:03 +0000 | [diff] [blame] | 142 | |
Vivek Gautam | fac8a76 | 2013-03-06 14:18:33 +0530 | [diff] [blame] | 143 | #ifdef CONFIG_OF_CONTROL |
Vivek Gautam | bab686c | 2013-03-06 14:18:32 +0530 | [diff] [blame] | 144 | if (exynos_usb_parse_dt(gd->fdt_blob, ctx)) { |
| 145 | debug("Unable to parse device tree for ehci-exynos\n"); |
| 146 | return -ENODEV; |
Rajeshwari Shinde | 23fbde5 | 2013-01-07 23:35:03 +0000 | [diff] [blame] | 147 | } |
Vivek Gautam | fac8a76 | 2013-03-06 14:18:33 +0530 | [diff] [blame] | 148 | #else |
| 149 | ctx->usb = (struct exynos_usb_phy *)samsung_get_base_usb_phy(); |
| 150 | ctx->hcd = (struct ehci_hccr *)samsung_get_base_usb_ehci(); |
| 151 | #endif |
Rajeshwari Shinde | 23fbde5 | 2013-01-07 23:35:03 +0000 | [diff] [blame] | 152 | |
Vivek Gautam | bab686c | 2013-03-06 14:18:32 +0530 | [diff] [blame] | 153 | setup_usb_phy(ctx->usb); |
Rajeshwari Shinde | 9b4ae50 | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 154 | |
Vivek Gautam | bab686c | 2013-03-06 14:18:32 +0530 | [diff] [blame] | 155 | *hccr = ctx->hcd; |
Lucas Stach | 3494a4c | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 156 | *hcor = (struct ehci_hcor *)((uint32_t) *hccr |
| 157 | + HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase))); |
Rajeshwari Shinde | 9b4ae50 | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 158 | |
| 159 | debug("Exynos5-ehci: init hccr %x and hcor %x hc_length %d\n", |
Lucas Stach | 3494a4c | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 160 | (uint32_t)*hccr, (uint32_t)*hcor, |
| 161 | (uint32_t)HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase))); |
Rajeshwari Shinde | 9b4ae50 | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 162 | |
| 163 | return 0; |
| 164 | } |
| 165 | |
| 166 | /* |
| 167 | * Destroy the appropriate control structures corresponding |
| 168 | * the EHCI host controller. |
| 169 | */ |
Lucas Stach | 3494a4c | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 170 | int ehci_hcd_stop(int index) |
Rajeshwari Shinde | 9b4ae50 | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 171 | { |
Vivek Gautam | bab686c | 2013-03-06 14:18:32 +0530 | [diff] [blame] | 172 | struct exynos_ehci *ctx = &exynos; |
Rajeshwari Shinde | 9b4ae50 | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 173 | |
Vivek Gautam | bab686c | 2013-03-06 14:18:32 +0530 | [diff] [blame] | 174 | reset_usb_phy(ctx->usb); |
Rajeshwari Shinde | 9b4ae50 | 2012-05-02 19:18:51 +0530 | [diff] [blame] | 175 | |
| 176 | return 0; |
| 177 | } |