Thomas Gleixner | 6b1baef | 2019-05-29 16:57:55 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 2 | /** |
| 3 | * omap-usb-host.c - The USBHS core driver for OMAP EHCI & OHCI |
| 4 | * |
Alexander A. Klimov | 4f4ed454 | 2020-07-22 21:24:54 +0200 | [diff] [blame] | 5 | * Copyright (C) 2011-2013 Texas Instruments Incorporated - https://www.ti.com |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 6 | * Author: Keshava Munegowda <keshava_mgowda@ti.com> |
Roger Quadros | 03a8f43 | 2013-04-09 11:39:18 +0300 | [diff] [blame] | 7 | * Author: Roger Quadros <rogerq@ti.com> |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 8 | */ |
| 9 | #include <linux/kernel.h> |
Ming Lei | 417e206 | 2011-08-19 16:57:54 +0800 | [diff] [blame] | 10 | #include <linux/module.h> |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 11 | #include <linux/types.h> |
| 12 | #include <linux/slab.h> |
| 13 | #include <linux/delay.h> |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 14 | #include <linux/clk.h> |
| 15 | #include <linux/dma-mapping.h> |
Russ Dill | c05995c | 2012-06-14 09:24:21 -0700 | [diff] [blame] | 16 | #include <linux/gpio.h> |
Felipe Balbi | e8c4a7a | 2012-10-24 14:26:19 -0700 | [diff] [blame] | 17 | #include <linux/platform_device.h> |
| 18 | #include <linux/platform_data/usb-omap.h> |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 19 | #include <linux/pm_runtime.h> |
Roger Quadros | 03a8f43 | 2013-04-09 11:39:18 +0300 | [diff] [blame] | 20 | #include <linux/of.h> |
| 21 | #include <linux/of_platform.h> |
Sachin Kamat | d011c45 | 2013-04-09 16:16:36 +0530 | [diff] [blame] | 22 | #include <linux/err.h> |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 23 | |
Felipe Balbi | e8c4a7a | 2012-10-24 14:26:19 -0700 | [diff] [blame] | 24 | #include "omap-usb.h" |
| 25 | |
Keshava Munegowda | a6d3a66 | 2011-10-11 13:21:51 +0530 | [diff] [blame] | 26 | #define USBHS_DRIVER_NAME "usbhs_omap" |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 27 | #define OMAP_EHCI_DEVICE "ehci-omap" |
| 28 | #define OMAP_OHCI_DEVICE "ohci-omap3" |
| 29 | |
| 30 | /* OMAP USBHOST Register addresses */ |
| 31 | |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 32 | /* UHH Register Set */ |
| 33 | #define OMAP_UHH_REVISION (0x00) |
| 34 | #define OMAP_UHH_SYSCONFIG (0x10) |
| 35 | #define OMAP_UHH_SYSCONFIG_MIDLEMODE (1 << 12) |
| 36 | #define OMAP_UHH_SYSCONFIG_CACTIVITY (1 << 8) |
| 37 | #define OMAP_UHH_SYSCONFIG_SIDLEMODE (1 << 3) |
| 38 | #define OMAP_UHH_SYSCONFIG_ENAWAKEUP (1 << 2) |
| 39 | #define OMAP_UHH_SYSCONFIG_SOFTRESET (1 << 1) |
| 40 | #define OMAP_UHH_SYSCONFIG_AUTOIDLE (1 << 0) |
| 41 | |
| 42 | #define OMAP_UHH_SYSSTATUS (0x14) |
| 43 | #define OMAP_UHH_HOSTCONFIG (0x40) |
| 44 | #define OMAP_UHH_HOSTCONFIG_ULPI_BYPASS (1 << 0) |
| 45 | #define OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS (1 << 0) |
| 46 | #define OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS (1 << 11) |
| 47 | #define OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS (1 << 12) |
| 48 | #define OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN (1 << 2) |
| 49 | #define OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN (1 << 3) |
| 50 | #define OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN (1 << 4) |
| 51 | #define OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN (1 << 5) |
| 52 | #define OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS (1 << 8) |
| 53 | #define OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS (1 << 9) |
| 54 | #define OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS (1 << 10) |
| 55 | #define OMAP4_UHH_HOSTCONFIG_APP_START_CLK (1 << 31) |
| 56 | |
| 57 | /* OMAP4-specific defines */ |
| 58 | #define OMAP4_UHH_SYSCONFIG_IDLEMODE_CLEAR (3 << 2) |
| 59 | #define OMAP4_UHH_SYSCONFIG_NOIDLE (1 << 2) |
| 60 | #define OMAP4_UHH_SYSCONFIG_STDBYMODE_CLEAR (3 << 4) |
| 61 | #define OMAP4_UHH_SYSCONFIG_NOSTDBY (1 << 4) |
| 62 | #define OMAP4_UHH_SYSCONFIG_SOFTRESET (1 << 0) |
| 63 | |
| 64 | #define OMAP4_P1_MODE_CLEAR (3 << 16) |
| 65 | #define OMAP4_P1_MODE_TLL (1 << 16) |
| 66 | #define OMAP4_P1_MODE_HSIC (3 << 16) |
| 67 | #define OMAP4_P2_MODE_CLEAR (3 << 18) |
| 68 | #define OMAP4_P2_MODE_TLL (1 << 18) |
| 69 | #define OMAP4_P2_MODE_HSIC (3 << 18) |
| 70 | |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 71 | #define OMAP_UHH_DEBUG_CSR (0x44) |
| 72 | |
| 73 | /* Values of UHH_REVISION - Note: these are not given in the TRM */ |
| 74 | #define OMAP_USBHS_REV1 0x00000010 /* OMAP3 */ |
| 75 | #define OMAP_USBHS_REV2 0x50700100 /* OMAP4 */ |
| 76 | |
| 77 | #define is_omap_usbhs_rev1(x) (x->usbhs_rev == OMAP_USBHS_REV1) |
| 78 | #define is_omap_usbhs_rev2(x) (x->usbhs_rev == OMAP_USBHS_REV2) |
| 79 | |
| 80 | #define is_ehci_phy_mode(x) (x == OMAP_EHCI_PORT_MODE_PHY) |
| 81 | #define is_ehci_tll_mode(x) (x == OMAP_EHCI_PORT_MODE_TLL) |
| 82 | #define is_ehci_hsic_mode(x) (x == OMAP_EHCI_PORT_MODE_HSIC) |
| 83 | |
| 84 | |
| 85 | struct usbhs_hcd_omap { |
Roger Quadros | d7eaf86 | 2012-11-08 18:04:26 +0200 | [diff] [blame] | 86 | int nports; |
Roger Quadros | 06ba7dc | 2012-11-08 17:40:25 +0200 | [diff] [blame] | 87 | struct clk **utmi_clk; |
Roger Quadros | 340c64e | 2012-11-12 16:53:16 +0200 | [diff] [blame] | 88 | struct clk **hsic60m_clk; |
| 89 | struct clk **hsic480m_clk; |
Roger Quadros | d7eaf86 | 2012-11-08 18:04:26 +0200 | [diff] [blame] | 90 | |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 91 | struct clk *xclk60mhsp1_ck; |
| 92 | struct clk *xclk60mhsp2_ck; |
Roger Quadros | 06ba7dc | 2012-11-08 17:40:25 +0200 | [diff] [blame] | 93 | struct clk *utmi_p1_gfclk; |
| 94 | struct clk *utmi_p2_gfclk; |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 95 | struct clk *init_60m_fclk; |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 96 | struct clk *ehci_logic_fck; |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 97 | |
| 98 | void __iomem *uhh_base; |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 99 | |
Roger Quadros | 9d9c6ae | 2013-02-13 13:16:25 +0200 | [diff] [blame] | 100 | struct usbhs_omap_platform_data *pdata; |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 101 | |
| 102 | u32 usbhs_rev; |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 103 | }; |
| 104 | /*-------------------------------------------------------------------------*/ |
| 105 | |
Sachin Kamat | 7844b98 | 2013-08-23 16:42:58 +0530 | [diff] [blame] | 106 | static const char usbhs_driver_name[] = USBHS_DRIVER_NAME; |
Govindraj.R | cbb8c22 | 2012-02-15 12:27:50 +0530 | [diff] [blame] | 107 | static u64 usbhs_dmamask = DMA_BIT_MASK(32); |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 108 | |
| 109 | /*-------------------------------------------------------------------------*/ |
| 110 | |
| 111 | static inline void usbhs_write(void __iomem *base, u32 reg, u32 val) |
| 112 | { |
Victor Kamensky | 9981a31 | 2013-11-16 02:01:14 +0200 | [diff] [blame] | 113 | writel_relaxed(val, base + reg); |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | static inline u32 usbhs_read(void __iomem *base, u32 reg) |
| 117 | { |
Victor Kamensky | 9981a31 | 2013-11-16 02:01:14 +0200 | [diff] [blame] | 118 | return readl_relaxed(base + reg); |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 119 | } |
| 120 | |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 121 | /*-------------------------------------------------------------------------*/ |
| 122 | |
Lee Jones | 5d36df7 | 2020-06-24 09:42:33 +0100 | [diff] [blame] | 123 | /* |
Roger Quadros | 03a8f43 | 2013-04-09 11:39:18 +0300 | [diff] [blame] | 124 | * Map 'enum usbhs_omap_port_mode' found in <linux/platform_data/usb-omap.h> |
| 125 | * to the device tree binding portN-mode found in |
| 126 | * 'Documentation/devicetree/bindings/mfd/omap-usb-host.txt' |
| 127 | */ |
| 128 | static const char * const port_modes[] = { |
| 129 | [OMAP_USBHS_PORT_MODE_UNUSED] = "", |
| 130 | [OMAP_EHCI_PORT_MODE_PHY] = "ehci-phy", |
| 131 | [OMAP_EHCI_PORT_MODE_TLL] = "ehci-tll", |
| 132 | [OMAP_EHCI_PORT_MODE_HSIC] = "ehci-hsic", |
| 133 | [OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0] = "ohci-phy-6pin-datse0", |
| 134 | [OMAP_OHCI_PORT_MODE_PHY_6PIN_DPDM] = "ohci-phy-6pin-dpdm", |
| 135 | [OMAP_OHCI_PORT_MODE_PHY_3PIN_DATSE0] = "ohci-phy-3pin-datse0", |
| 136 | [OMAP_OHCI_PORT_MODE_PHY_4PIN_DPDM] = "ohci-phy-4pin-dpdm", |
| 137 | [OMAP_OHCI_PORT_MODE_TLL_6PIN_DATSE0] = "ohci-tll-6pin-datse0", |
| 138 | [OMAP_OHCI_PORT_MODE_TLL_6PIN_DPDM] = "ohci-tll-6pin-dpdm", |
| 139 | [OMAP_OHCI_PORT_MODE_TLL_3PIN_DATSE0] = "ohci-tll-3pin-datse0", |
| 140 | [OMAP_OHCI_PORT_MODE_TLL_4PIN_DPDM] = "ohci-tll-4pin-dpdm", |
| 141 | [OMAP_OHCI_PORT_MODE_TLL_2PIN_DATSE0] = "ohci-tll-2pin-datse0", |
| 142 | [OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM] = "ohci-tll-2pin-dpdm", |
| 143 | }; |
| 144 | |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 145 | static struct platform_device *omap_usbhs_alloc_child(const char *name, |
| 146 | struct resource *res, int num_resources, void *pdata, |
| 147 | size_t pdata_size, struct device *dev) |
| 148 | { |
| 149 | struct platform_device *child; |
| 150 | int ret; |
| 151 | |
| 152 | child = platform_device_alloc(name, 0); |
| 153 | |
| 154 | if (!child) { |
| 155 | dev_err(dev, "platform_device_alloc %s failed\n", name); |
| 156 | goto err_end; |
| 157 | } |
| 158 | |
| 159 | ret = platform_device_add_resources(child, res, num_resources); |
| 160 | if (ret) { |
| 161 | dev_err(dev, "platform_device_add_resources failed\n"); |
| 162 | goto err_alloc; |
| 163 | } |
| 164 | |
| 165 | ret = platform_device_add_data(child, pdata, pdata_size); |
| 166 | if (ret) { |
| 167 | dev_err(dev, "platform_device_add_data failed\n"); |
| 168 | goto err_alloc; |
| 169 | } |
| 170 | |
| 171 | child->dev.dma_mask = &usbhs_dmamask; |
Govindraj.R | cbb8c22 | 2012-02-15 12:27:50 +0530 | [diff] [blame] | 172 | dma_set_coherent_mask(&child->dev, DMA_BIT_MASK(32)); |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 173 | child->dev.parent = dev; |
| 174 | |
| 175 | ret = platform_device_add(child); |
| 176 | if (ret) { |
| 177 | dev_err(dev, "platform_device_add failed\n"); |
| 178 | goto err_alloc; |
| 179 | } |
| 180 | |
| 181 | return child; |
| 182 | |
| 183 | err_alloc: |
| 184 | platform_device_put(child); |
| 185 | |
| 186 | err_end: |
| 187 | return NULL; |
| 188 | } |
| 189 | |
| 190 | static int omap_usbhs_alloc_children(struct platform_device *pdev) |
| 191 | { |
| 192 | struct device *dev = &pdev->dev; |
Jingoo Han | 334a41ce | 2013-07-30 17:10:05 +0900 | [diff] [blame] | 193 | struct usbhs_omap_platform_data *pdata = dev_get_platdata(dev); |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 194 | struct platform_device *ehci; |
| 195 | struct platform_device *ohci; |
| 196 | struct resource *res; |
| 197 | struct resource resources[2]; |
| 198 | int ret; |
| 199 | |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 200 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ehci"); |
| 201 | if (!res) { |
| 202 | dev_err(dev, "EHCI get resource IORESOURCE_MEM failed\n"); |
| 203 | ret = -ENODEV; |
| 204 | goto err_end; |
| 205 | } |
| 206 | resources[0] = *res; |
| 207 | |
| 208 | res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "ehci-irq"); |
| 209 | if (!res) { |
| 210 | dev_err(dev, " EHCI get resource IORESOURCE_IRQ failed\n"); |
| 211 | ret = -ENODEV; |
| 212 | goto err_end; |
| 213 | } |
| 214 | resources[1] = *res; |
| 215 | |
Roger Quadros | 9d9c6ae | 2013-02-13 13:16:25 +0200 | [diff] [blame] | 216 | ehci = omap_usbhs_alloc_child(OMAP_EHCI_DEVICE, resources, 2, pdata, |
| 217 | sizeof(*pdata), dev); |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 218 | |
| 219 | if (!ehci) { |
| 220 | dev_err(dev, "omap_usbhs_alloc_child failed\n"); |
Axel Lin | d910774 | 2011-05-14 14:15:36 +0800 | [diff] [blame] | 221 | ret = -ENOMEM; |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 222 | goto err_end; |
| 223 | } |
| 224 | |
| 225 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ohci"); |
| 226 | if (!res) { |
| 227 | dev_err(dev, "OHCI get resource IORESOURCE_MEM failed\n"); |
| 228 | ret = -ENODEV; |
| 229 | goto err_ehci; |
| 230 | } |
| 231 | resources[0] = *res; |
| 232 | |
| 233 | res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "ohci-irq"); |
| 234 | if (!res) { |
| 235 | dev_err(dev, "OHCI get resource IORESOURCE_IRQ failed\n"); |
| 236 | ret = -ENODEV; |
| 237 | goto err_ehci; |
| 238 | } |
| 239 | resources[1] = *res; |
| 240 | |
Roger Quadros | 9d9c6ae | 2013-02-13 13:16:25 +0200 | [diff] [blame] | 241 | ohci = omap_usbhs_alloc_child(OMAP_OHCI_DEVICE, resources, 2, pdata, |
| 242 | sizeof(*pdata), dev); |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 243 | if (!ohci) { |
| 244 | dev_err(dev, "omap_usbhs_alloc_child failed\n"); |
Axel Lin | d910774 | 2011-05-14 14:15:36 +0800 | [diff] [blame] | 245 | ret = -ENOMEM; |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 246 | goto err_ehci; |
| 247 | } |
| 248 | |
| 249 | return 0; |
| 250 | |
| 251 | err_ehci: |
Axel Lin | d910774 | 2011-05-14 14:15:36 +0800 | [diff] [blame] | 252 | platform_device_unregister(ehci); |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 253 | |
| 254 | err_end: |
| 255 | return ret; |
| 256 | } |
| 257 | |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 258 | static bool is_ohci_port(enum usbhs_omap_port_mode pmode) |
| 259 | { |
| 260 | switch (pmode) { |
| 261 | case OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0: |
| 262 | case OMAP_OHCI_PORT_MODE_PHY_6PIN_DPDM: |
| 263 | case OMAP_OHCI_PORT_MODE_PHY_3PIN_DATSE0: |
| 264 | case OMAP_OHCI_PORT_MODE_PHY_4PIN_DPDM: |
| 265 | case OMAP_OHCI_PORT_MODE_TLL_6PIN_DATSE0: |
| 266 | case OMAP_OHCI_PORT_MODE_TLL_6PIN_DPDM: |
| 267 | case OMAP_OHCI_PORT_MODE_TLL_3PIN_DATSE0: |
| 268 | case OMAP_OHCI_PORT_MODE_TLL_4PIN_DPDM: |
| 269 | case OMAP_OHCI_PORT_MODE_TLL_2PIN_DATSE0: |
| 270 | case OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM: |
| 271 | return true; |
| 272 | |
| 273 | default: |
| 274 | return false; |
| 275 | } |
| 276 | } |
| 277 | |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 278 | static int usbhs_runtime_resume(struct device *dev) |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 279 | { |
| 280 | struct usbhs_hcd_omap *omap = dev_get_drvdata(dev); |
Roger Quadros | 9d9c6ae | 2013-02-13 13:16:25 +0200 | [diff] [blame] | 281 | struct usbhs_omap_platform_data *pdata = omap->pdata; |
Roger Quadros | 06ba7dc | 2012-11-08 17:40:25 +0200 | [diff] [blame] | 282 | int i, r; |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 283 | |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 284 | dev_dbg(dev, "usbhs_runtime_resume\n"); |
| 285 | |
Roger Quadros | 9f4a3ec | 2013-01-29 15:00:03 +0200 | [diff] [blame] | 286 | omap_tll_enable(pdata); |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 287 | |
Roger Quadros | 06ba7dc | 2012-11-08 17:40:25 +0200 | [diff] [blame] | 288 | if (!IS_ERR(omap->ehci_logic_fck)) |
Roger Quadros | b0e5992 | 2013-10-15 15:30:34 +0300 | [diff] [blame] | 289 | clk_prepare_enable(omap->ehci_logic_fck); |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 290 | |
Roger Quadros | 06ba7dc | 2012-11-08 17:40:25 +0200 | [diff] [blame] | 291 | for (i = 0; i < omap->nports; i++) { |
Roger Quadros | 340c64e | 2012-11-12 16:53:16 +0200 | [diff] [blame] | 292 | switch (pdata->port_mode[i]) { |
| 293 | case OMAP_EHCI_PORT_MODE_HSIC: |
| 294 | if (!IS_ERR(omap->hsic60m_clk[i])) { |
Roger Quadros | b0e5992 | 2013-10-15 15:30:34 +0300 | [diff] [blame] | 295 | r = clk_prepare_enable(omap->hsic60m_clk[i]); |
Roger Quadros | 340c64e | 2012-11-12 16:53:16 +0200 | [diff] [blame] | 296 | if (r) { |
| 297 | dev_err(dev, |
| 298 | "Can't enable port %d hsic60m clk:%d\n", |
| 299 | i, r); |
| 300 | } |
| 301 | } |
Keshava Munegowda | 760189b | 2012-07-16 19:01:10 +0530 | [diff] [blame] | 302 | |
Roger Quadros | 340c64e | 2012-11-12 16:53:16 +0200 | [diff] [blame] | 303 | if (!IS_ERR(omap->hsic480m_clk[i])) { |
Roger Quadros | b0e5992 | 2013-10-15 15:30:34 +0300 | [diff] [blame] | 304 | r = clk_prepare_enable(omap->hsic480m_clk[i]); |
Roger Quadros | 340c64e | 2012-11-12 16:53:16 +0200 | [diff] [blame] | 305 | if (r) { |
| 306 | dev_err(dev, |
| 307 | "Can't enable port %d hsic480m clk:%d\n", |
| 308 | i, r); |
| 309 | } |
| 310 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 311 | fallthrough; /* as HSIC mode needs utmi_clk */ |
Roger Quadros | 340c64e | 2012-11-12 16:53:16 +0200 | [diff] [blame] | 312 | |
| 313 | case OMAP_EHCI_PORT_MODE_TLL: |
| 314 | if (!IS_ERR(omap->utmi_clk[i])) { |
Roger Quadros | b0e5992 | 2013-10-15 15:30:34 +0300 | [diff] [blame] | 315 | r = clk_prepare_enable(omap->utmi_clk[i]); |
Roger Quadros | 340c64e | 2012-11-12 16:53:16 +0200 | [diff] [blame] | 316 | if (r) { |
| 317 | dev_err(dev, |
| 318 | "Can't enable port %d clk : %d\n", |
| 319 | i, r); |
| 320 | } |
| 321 | } |
| 322 | break; |
| 323 | default: |
| 324 | break; |
| 325 | } |
Roger Quadros | 06ba7dc | 2012-11-08 17:40:25 +0200 | [diff] [blame] | 326 | } |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 327 | |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 328 | return 0; |
| 329 | } |
| 330 | |
| 331 | static int usbhs_runtime_suspend(struct device *dev) |
| 332 | { |
| 333 | struct usbhs_hcd_omap *omap = dev_get_drvdata(dev); |
Roger Quadros | 9d9c6ae | 2013-02-13 13:16:25 +0200 | [diff] [blame] | 334 | struct usbhs_omap_platform_data *pdata = omap->pdata; |
Roger Quadros | 06ba7dc | 2012-11-08 17:40:25 +0200 | [diff] [blame] | 335 | int i; |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 336 | |
| 337 | dev_dbg(dev, "usbhs_runtime_suspend\n"); |
| 338 | |
Roger Quadros | 06ba7dc | 2012-11-08 17:40:25 +0200 | [diff] [blame] | 339 | for (i = 0; i < omap->nports; i++) { |
Roger Quadros | 340c64e | 2012-11-12 16:53:16 +0200 | [diff] [blame] | 340 | switch (pdata->port_mode[i]) { |
| 341 | case OMAP_EHCI_PORT_MODE_HSIC: |
| 342 | if (!IS_ERR(omap->hsic60m_clk[i])) |
Roger Quadros | b0e5992 | 2013-10-15 15:30:34 +0300 | [diff] [blame] | 343 | clk_disable_unprepare(omap->hsic60m_clk[i]); |
Roger Quadros | 340c64e | 2012-11-12 16:53:16 +0200 | [diff] [blame] | 344 | |
| 345 | if (!IS_ERR(omap->hsic480m_clk[i])) |
Roger Quadros | b0e5992 | 2013-10-15 15:30:34 +0300 | [diff] [blame] | 346 | clk_disable_unprepare(omap->hsic480m_clk[i]); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 347 | fallthrough; /* as utmi_clks were used in HSIC mode */ |
Roger Quadros | 340c64e | 2012-11-12 16:53:16 +0200 | [diff] [blame] | 348 | |
| 349 | case OMAP_EHCI_PORT_MODE_TLL: |
| 350 | if (!IS_ERR(omap->utmi_clk[i])) |
Roger Quadros | b0e5992 | 2013-10-15 15:30:34 +0300 | [diff] [blame] | 351 | clk_disable_unprepare(omap->utmi_clk[i]); |
Roger Quadros | 340c64e | 2012-11-12 16:53:16 +0200 | [diff] [blame] | 352 | break; |
| 353 | default: |
| 354 | break; |
| 355 | } |
Roger Quadros | 06ba7dc | 2012-11-08 17:40:25 +0200 | [diff] [blame] | 356 | } |
Keshava Munegowda | 760189b | 2012-07-16 19:01:10 +0530 | [diff] [blame] | 357 | |
Roger Quadros | 06ba7dc | 2012-11-08 17:40:25 +0200 | [diff] [blame] | 358 | if (!IS_ERR(omap->ehci_logic_fck)) |
Roger Quadros | b0e5992 | 2013-10-15 15:30:34 +0300 | [diff] [blame] | 359 | clk_disable_unprepare(omap->ehci_logic_fck); |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 360 | |
Roger Quadros | 9f4a3ec | 2013-01-29 15:00:03 +0200 | [diff] [blame] | 361 | omap_tll_disable(pdata); |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 362 | |
| 363 | return 0; |
| 364 | } |
| 365 | |
Roger Quadros | c4df00a | 2012-11-12 16:32:01 +0200 | [diff] [blame] | 366 | static unsigned omap_usbhs_rev1_hostconfig(struct usbhs_hcd_omap *omap, |
| 367 | unsigned reg) |
| 368 | { |
| 369 | struct usbhs_omap_platform_data *pdata = omap->pdata; |
| 370 | int i; |
| 371 | |
| 372 | for (i = 0; i < omap->nports; i++) { |
| 373 | switch (pdata->port_mode[i]) { |
| 374 | case OMAP_USBHS_PORT_MODE_UNUSED: |
| 375 | reg &= ~(OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS << i); |
| 376 | break; |
| 377 | case OMAP_EHCI_PORT_MODE_PHY: |
| 378 | if (pdata->single_ulpi_bypass) |
| 379 | break; |
| 380 | |
| 381 | if (i == 0) |
| 382 | reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS; |
| 383 | else |
| 384 | reg &= ~(OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS |
| 385 | << (i-1)); |
| 386 | break; |
| 387 | default: |
| 388 | if (pdata->single_ulpi_bypass) |
| 389 | break; |
| 390 | |
| 391 | if (i == 0) |
| 392 | reg |= OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS; |
| 393 | else |
| 394 | reg |= OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS |
| 395 | << (i-1); |
| 396 | break; |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | if (pdata->single_ulpi_bypass) { |
| 401 | /* bypass ULPI only if none of the ports use PHY mode */ |
| 402 | reg |= OMAP_UHH_HOSTCONFIG_ULPI_BYPASS; |
| 403 | |
| 404 | for (i = 0; i < omap->nports; i++) { |
| 405 | if (is_ehci_phy_mode(pdata->port_mode[i])) { |
Michael Welling | 46de8ff | 2014-07-28 18:01:04 -0500 | [diff] [blame] | 406 | reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_BYPASS; |
Roger Quadros | c4df00a | 2012-11-12 16:32:01 +0200 | [diff] [blame] | 407 | break; |
| 408 | } |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | return reg; |
| 413 | } |
| 414 | |
| 415 | static unsigned omap_usbhs_rev2_hostconfig(struct usbhs_hcd_omap *omap, |
| 416 | unsigned reg) |
| 417 | { |
| 418 | struct usbhs_omap_platform_data *pdata = omap->pdata; |
| 419 | int i; |
| 420 | |
| 421 | for (i = 0; i < omap->nports; i++) { |
| 422 | /* Clear port mode fields for PHY mode */ |
| 423 | reg &= ~(OMAP4_P1_MODE_CLEAR << 2 * i); |
| 424 | |
| 425 | if (is_ehci_tll_mode(pdata->port_mode[i]) || |
| 426 | (is_ohci_port(pdata->port_mode[i]))) |
| 427 | reg |= OMAP4_P1_MODE_TLL << 2 * i; |
| 428 | else if (is_ehci_hsic_mode(pdata->port_mode[i])) |
| 429 | reg |= OMAP4_P1_MODE_HSIC << 2 * i; |
| 430 | } |
| 431 | |
| 432 | return reg; |
| 433 | } |
| 434 | |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 435 | static void omap_usbhs_init(struct device *dev) |
| 436 | { |
| 437 | struct usbhs_hcd_omap *omap = dev_get_drvdata(dev); |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 438 | unsigned reg; |
| 439 | |
| 440 | dev_dbg(dev, "starting TI HSUSB Controller\n"); |
| 441 | |
Keshava Munegowda | 760189b | 2012-07-16 19:01:10 +0530 | [diff] [blame] | 442 | pm_runtime_get_sync(dev); |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 443 | |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 444 | reg = usbhs_read(omap->uhh_base, OMAP_UHH_HOSTCONFIG); |
| 445 | /* setup ULPI bypass and burst configurations */ |
| 446 | reg |= (OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN |
| 447 | | OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN |
| 448 | | OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN); |
| 449 | reg |= OMAP4_UHH_HOSTCONFIG_APP_START_CLK; |
| 450 | reg &= ~OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN; |
| 451 | |
Roger Quadros | c4df00a | 2012-11-12 16:32:01 +0200 | [diff] [blame] | 452 | switch (omap->usbhs_rev) { |
| 453 | case OMAP_USBHS_REV1: |
Roger Quadros | 26bacba | 2013-02-27 15:19:24 +0200 | [diff] [blame] | 454 | reg = omap_usbhs_rev1_hostconfig(omap, reg); |
Roger Quadros | c4df00a | 2012-11-12 16:32:01 +0200 | [diff] [blame] | 455 | break; |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 456 | |
Roger Quadros | c4df00a | 2012-11-12 16:32:01 +0200 | [diff] [blame] | 457 | case OMAP_USBHS_REV2: |
Roger Quadros | 26bacba | 2013-02-27 15:19:24 +0200 | [diff] [blame] | 458 | reg = omap_usbhs_rev2_hostconfig(omap, reg); |
Roger Quadros | c4df00a | 2012-11-12 16:32:01 +0200 | [diff] [blame] | 459 | break; |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 460 | |
Roger Quadros | c4df00a | 2012-11-12 16:32:01 +0200 | [diff] [blame] | 461 | default: /* newer revisions */ |
Roger Quadros | 26bacba | 2013-02-27 15:19:24 +0200 | [diff] [blame] | 462 | reg = omap_usbhs_rev2_hostconfig(omap, reg); |
Roger Quadros | c4df00a | 2012-11-12 16:32:01 +0200 | [diff] [blame] | 463 | break; |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | usbhs_write(omap->uhh_base, OMAP_UHH_HOSTCONFIG, reg); |
| 467 | dev_dbg(dev, "UHH setup done, uhh_hostconfig=%x\n", reg); |
| 468 | |
Keshava Munegowda | 760189b | 2012-07-16 19:01:10 +0530 | [diff] [blame] | 469 | pm_runtime_put_sync(dev); |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 470 | } |
| 471 | |
Roger Quadros | 03a8f43 | 2013-04-09 11:39:18 +0300 | [diff] [blame] | 472 | static int usbhs_omap_get_dt_pdata(struct device *dev, |
| 473 | struct usbhs_omap_platform_data *pdata) |
| 474 | { |
| 475 | int ret, i; |
| 476 | struct device_node *node = dev->of_node; |
| 477 | |
| 478 | ret = of_property_read_u32(node, "num-ports", &pdata->nports); |
| 479 | if (ret) |
| 480 | pdata->nports = 0; |
| 481 | |
| 482 | if (pdata->nports > OMAP3_HS_USB_PORTS) { |
| 483 | dev_warn(dev, "Too many num_ports <%d> in device tree. Max %d\n", |
| 484 | pdata->nports, OMAP3_HS_USB_PORTS); |
| 485 | return -ENODEV; |
| 486 | } |
| 487 | |
| 488 | /* get port modes */ |
| 489 | for (i = 0; i < OMAP3_HS_USB_PORTS; i++) { |
| 490 | char prop[11]; |
| 491 | const char *mode; |
| 492 | |
| 493 | pdata->port_mode[i] = OMAP_USBHS_PORT_MODE_UNUSED; |
| 494 | |
| 495 | snprintf(prop, sizeof(prop), "port%d-mode", i + 1); |
| 496 | ret = of_property_read_string(node, prop, &mode); |
| 497 | if (ret < 0) |
| 498 | continue; |
| 499 | |
Yisheng Xie | 4c74a1f | 2018-05-21 19:57:39 +0800 | [diff] [blame] | 500 | /* get 'enum usbhs_omap_port_mode' from port mode string */ |
| 501 | ret = match_string(port_modes, ARRAY_SIZE(port_modes), mode); |
Roger Quadros | 03a8f43 | 2013-04-09 11:39:18 +0300 | [diff] [blame] | 502 | if (ret < 0) { |
| 503 | dev_warn(dev, "Invalid port%d-mode \"%s\" in device tree\n", |
| 504 | i, mode); |
| 505 | return -ENODEV; |
| 506 | } |
| 507 | |
| 508 | dev_dbg(dev, "port%d-mode: %s -> %d\n", i, mode, ret); |
| 509 | pdata->port_mode[i] = ret; |
| 510 | } |
| 511 | |
| 512 | /* get flags */ |
| 513 | pdata->single_ulpi_bypass = of_property_read_bool(node, |
| 514 | "single-ulpi-bypass"); |
| 515 | |
| 516 | return 0; |
| 517 | } |
| 518 | |
Krzysztof Kozlowski | a7cfee8 | 2014-05-13 12:58:47 +0200 | [diff] [blame] | 519 | static const struct of_device_id usbhs_child_match_table[] = { |
Tony Lindgren | 10492ee | 2018-04-25 07:29:22 -0700 | [diff] [blame] | 520 | { .compatible = "ti,ehci-omap", }, |
| 521 | { .compatible = "ti,ohci-omap3", }, |
Roger Quadros | 03a8f43 | 2013-04-09 11:39:18 +0300 | [diff] [blame] | 522 | { } |
| 523 | }; |
| 524 | |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 525 | /** |
| 526 | * usbhs_omap_probe - initialize TI-based HCDs |
| 527 | * |
| 528 | * Allocates basic resources for this USB host controller. |
Lee Jones | 3fc6562 | 2020-06-24 09:45:56 +0100 | [diff] [blame] | 529 | * |
| 530 | * @pdev: Pointer to this device's platform device structure |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 531 | */ |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 532 | static int usbhs_omap_probe(struct platform_device *pdev) |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 533 | { |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 534 | struct device *dev = &pdev->dev; |
Jingoo Han | 334a41ce | 2013-07-30 17:10:05 +0900 | [diff] [blame] | 535 | struct usbhs_omap_platform_data *pdata = dev_get_platdata(dev); |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 536 | struct usbhs_hcd_omap *omap; |
| 537 | struct resource *res; |
| 538 | int ret = 0; |
| 539 | int i; |
Roger Quadros | 06ba7dc | 2012-11-08 17:40:25 +0200 | [diff] [blame] | 540 | bool need_logic_fck; |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 541 | |
Roger Quadros | 03a8f43 | 2013-04-09 11:39:18 +0300 | [diff] [blame] | 542 | if (dev->of_node) { |
| 543 | /* For DT boot we populate platform data from OF node */ |
| 544 | pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); |
| 545 | if (!pdata) |
| 546 | return -ENOMEM; |
| 547 | |
| 548 | ret = usbhs_omap_get_dt_pdata(dev, pdata); |
| 549 | if (ret) |
| 550 | return ret; |
| 551 | |
| 552 | dev->platform_data = pdata; |
| 553 | } |
| 554 | |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 555 | if (!pdata) { |
| 556 | dev_err(dev, "Missing platform data\n"); |
Roger Quadros | 27d4f2c | 2012-11-26 17:59:22 +0200 | [diff] [blame] | 557 | return -ENODEV; |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 558 | } |
| 559 | |
Roger Quadros | 03a8f43 | 2013-04-09 11:39:18 +0300 | [diff] [blame] | 560 | if (pdata->nports > OMAP3_HS_USB_PORTS) { |
| 561 | dev_info(dev, "Too many num_ports <%d> in platform_data. Max %d\n", |
| 562 | pdata->nports, OMAP3_HS_USB_PORTS); |
| 563 | return -ENODEV; |
| 564 | } |
| 565 | |
Roger Quadros | 27d4f2c | 2012-11-26 17:59:22 +0200 | [diff] [blame] | 566 | omap = devm_kzalloc(dev, sizeof(*omap), GFP_KERNEL); |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 567 | if (!omap) { |
| 568 | dev_err(dev, "Memory allocation failed\n"); |
Roger Quadros | 27d4f2c | 2012-11-26 17:59:22 +0200 | [diff] [blame] | 569 | return -ENOMEM; |
| 570 | } |
| 571 | |
Roger Quadros | 03a8f43 | 2013-04-09 11:39:18 +0300 | [diff] [blame] | 572 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Sachin Kamat | d011c45 | 2013-04-09 16:16:36 +0530 | [diff] [blame] | 573 | omap->uhh_base = devm_ioremap_resource(dev, res); |
| 574 | if (IS_ERR(omap->uhh_base)) |
| 575 | return PTR_ERR(omap->uhh_base); |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 576 | |
Roger Quadros | 9d9c6ae | 2013-02-13 13:16:25 +0200 | [diff] [blame] | 577 | omap->pdata = pdata; |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 578 | |
Roger Quadros | 9f4a3ec | 2013-01-29 15:00:03 +0200 | [diff] [blame] | 579 | /* Initialize the TLL subsystem */ |
| 580 | omap_tll_init(pdata); |
| 581 | |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 582 | pm_runtime_enable(dev); |
| 583 | |
Roger Quadros | d7eaf86 | 2012-11-08 18:04:26 +0200 | [diff] [blame] | 584 | platform_set_drvdata(pdev, omap); |
| 585 | pm_runtime_get_sync(dev); |
| 586 | |
| 587 | omap->usbhs_rev = usbhs_read(omap->uhh_base, OMAP_UHH_REVISION); |
| 588 | |
| 589 | /* we need to call runtime suspend before we update omap->nports |
| 590 | * to prevent unbalanced clk_disable() |
| 591 | */ |
| 592 | pm_runtime_put_sync(dev); |
| 593 | |
Roger Quadros | ccac71a | 2012-11-08 19:18:08 +0200 | [diff] [blame] | 594 | /* |
| 595 | * If platform data contains nports then use that |
| 596 | * else make out number of ports from USBHS revision |
| 597 | */ |
| 598 | if (pdata->nports) { |
| 599 | omap->nports = pdata->nports; |
| 600 | } else { |
| 601 | switch (omap->usbhs_rev) { |
| 602 | case OMAP_USBHS_REV1: |
| 603 | omap->nports = 3; |
| 604 | break; |
| 605 | case OMAP_USBHS_REV2: |
| 606 | omap->nports = 2; |
| 607 | break; |
| 608 | default: |
| 609 | omap->nports = OMAP3_HS_USB_PORTS; |
| 610 | dev_dbg(dev, |
Hans Wennborg | ddde06b | 2014-08-03 17:19:27 -0700 | [diff] [blame] | 611 | "USB HOST Rev:0x%x not recognized, assuming %d ports\n", |
Roger Quadros | ccac71a | 2012-11-08 19:18:08 +0200 | [diff] [blame] | 612 | omap->usbhs_rev, omap->nports); |
| 613 | break; |
| 614 | } |
Roger Quadros | 662e469 | 2013-01-08 16:01:52 +0200 | [diff] [blame] | 615 | pdata->nports = omap->nports; |
Roger Quadros | d7eaf86 | 2012-11-08 18:04:26 +0200 | [diff] [blame] | 616 | } |
| 617 | |
Roger Quadros | 06ba7dc | 2012-11-08 17:40:25 +0200 | [diff] [blame] | 618 | i = sizeof(struct clk *) * omap->nports; |
| 619 | omap->utmi_clk = devm_kzalloc(dev, i, GFP_KERNEL); |
Roger Quadros | 340c64e | 2012-11-12 16:53:16 +0200 | [diff] [blame] | 620 | omap->hsic480m_clk = devm_kzalloc(dev, i, GFP_KERNEL); |
| 621 | omap->hsic60m_clk = devm_kzalloc(dev, i, GFP_KERNEL); |
| 622 | |
| 623 | if (!omap->utmi_clk || !omap->hsic480m_clk || !omap->hsic60m_clk) { |
Roger Quadros | 06ba7dc | 2012-11-08 17:40:25 +0200 | [diff] [blame] | 624 | dev_err(dev, "Memory allocation failed\n"); |
| 625 | ret = -ENOMEM; |
| 626 | goto err_mem; |
| 627 | } |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 628 | |
Roger Quadros | 3aca446 | 2014-02-27 16:18:23 +0200 | [diff] [blame] | 629 | /* Set all clocks as invalid to begin with */ |
| 630 | omap->ehci_logic_fck = ERR_PTR(-ENODEV); |
| 631 | omap->init_60m_fclk = ERR_PTR(-ENODEV); |
| 632 | omap->utmi_p1_gfclk = ERR_PTR(-ENODEV); |
| 633 | omap->utmi_p2_gfclk = ERR_PTR(-ENODEV); |
| 634 | omap->xclk60mhsp1_ck = ERR_PTR(-ENODEV); |
| 635 | omap->xclk60mhsp2_ck = ERR_PTR(-ENODEV); |
| 636 | |
Roger Quadros | 06ba7dc | 2012-11-08 17:40:25 +0200 | [diff] [blame] | 637 | for (i = 0; i < omap->nports; i++) { |
Roger Quadros | 3aca446 | 2014-02-27 16:18:23 +0200 | [diff] [blame] | 638 | omap->utmi_clk[i] = ERR_PTR(-ENODEV); |
| 639 | omap->hsic480m_clk[i] = ERR_PTR(-ENODEV); |
| 640 | omap->hsic60m_clk[i] = ERR_PTR(-ENODEV); |
| 641 | } |
| 642 | |
| 643 | /* for OMAP3 i.e. USBHS REV1 */ |
| 644 | if (omap->usbhs_rev == OMAP_USBHS_REV1) { |
| 645 | need_logic_fck = false; |
| 646 | for (i = 0; i < omap->nports; i++) { |
| 647 | if (is_ehci_phy_mode(pdata->port_mode[i]) || |
| 648 | is_ehci_tll_mode(pdata->port_mode[i]) || |
| 649 | is_ehci_hsic_mode(pdata->port_mode[i])) |
| 650 | |
Roger Quadros | 06ba7dc | 2012-11-08 17:40:25 +0200 | [diff] [blame] | 651 | need_logic_fck |= true; |
Roger Quadros | 06ba7dc | 2012-11-08 17:40:25 +0200 | [diff] [blame] | 652 | } |
Roger Quadros | 3aca446 | 2014-02-27 16:18:23 +0200 | [diff] [blame] | 653 | |
| 654 | if (need_logic_fck) { |
| 655 | omap->ehci_logic_fck = devm_clk_get(dev, |
Roger Quadros | 775bb07 | 2014-02-27 16:18:25 +0200 | [diff] [blame] | 656 | "usbhost_120m_fck"); |
Roger Quadros | 3aca446 | 2014-02-27 16:18:23 +0200 | [diff] [blame] | 657 | if (IS_ERR(omap->ehci_logic_fck)) { |
| 658 | ret = PTR_ERR(omap->ehci_logic_fck); |
Roger Quadros | 775bb07 | 2014-02-27 16:18:25 +0200 | [diff] [blame] | 659 | dev_err(dev, "usbhost_120m_fck failed:%d\n", |
| 660 | ret); |
Roger Quadros | fedb2e7 | 2014-02-27 16:18:24 +0200 | [diff] [blame] | 661 | goto err_mem; |
Roger Quadros | 3aca446 | 2014-02-27 16:18:23 +0200 | [diff] [blame] | 662 | } |
| 663 | } |
| 664 | goto initialize; |
Roger Quadros | 06ba7dc | 2012-11-08 17:40:25 +0200 | [diff] [blame] | 665 | } |
| 666 | |
Roger Quadros | 3aca446 | 2014-02-27 16:18:23 +0200 | [diff] [blame] | 667 | /* for OMAP4+ i.e. USBHS REV2+ */ |
Roger Quadros | 61b7025 | 2014-02-12 12:18:42 +0200 | [diff] [blame] | 668 | omap->utmi_p1_gfclk = devm_clk_get(dev, "utmi_p1_gfclk"); |
Roger Quadros | 06ba7dc | 2012-11-08 17:40:25 +0200 | [diff] [blame] | 669 | if (IS_ERR(omap->utmi_p1_gfclk)) { |
| 670 | ret = PTR_ERR(omap->utmi_p1_gfclk); |
| 671 | dev_err(dev, "utmi_p1_gfclk failed error:%d\n", ret); |
Roger Quadros | 61b7025 | 2014-02-12 12:18:42 +0200 | [diff] [blame] | 672 | goto err_mem; |
Roger Quadros | 06ba7dc | 2012-11-08 17:40:25 +0200 | [diff] [blame] | 673 | } |
| 674 | |
Roger Quadros | 61b7025 | 2014-02-12 12:18:42 +0200 | [diff] [blame] | 675 | omap->utmi_p2_gfclk = devm_clk_get(dev, "utmi_p2_gfclk"); |
Roger Quadros | 06ba7dc | 2012-11-08 17:40:25 +0200 | [diff] [blame] | 676 | if (IS_ERR(omap->utmi_p2_gfclk)) { |
| 677 | ret = PTR_ERR(omap->utmi_p2_gfclk); |
| 678 | dev_err(dev, "utmi_p2_gfclk failed error:%d\n", ret); |
Roger Quadros | 61b7025 | 2014-02-12 12:18:42 +0200 | [diff] [blame] | 679 | goto err_mem; |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 680 | } |
| 681 | |
Roger Quadros | 051fc06 | 2014-02-27 16:18:26 +0200 | [diff] [blame] | 682 | omap->xclk60mhsp1_ck = devm_clk_get(dev, "refclk_60m_ext_p1"); |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 683 | if (IS_ERR(omap->xclk60mhsp1_ck)) { |
| 684 | ret = PTR_ERR(omap->xclk60mhsp1_ck); |
Roger Quadros | 051fc06 | 2014-02-27 16:18:26 +0200 | [diff] [blame] | 685 | dev_err(dev, "refclk_60m_ext_p1 failed error:%d\n", ret); |
Roger Quadros | 61b7025 | 2014-02-12 12:18:42 +0200 | [diff] [blame] | 686 | goto err_mem; |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 687 | } |
| 688 | |
Roger Quadros | 051fc06 | 2014-02-27 16:18:26 +0200 | [diff] [blame] | 689 | omap->xclk60mhsp2_ck = devm_clk_get(dev, "refclk_60m_ext_p2"); |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 690 | if (IS_ERR(omap->xclk60mhsp2_ck)) { |
| 691 | ret = PTR_ERR(omap->xclk60mhsp2_ck); |
Roger Quadros | 051fc06 | 2014-02-27 16:18:26 +0200 | [diff] [blame] | 692 | dev_err(dev, "refclk_60m_ext_p2 failed error:%d\n", ret); |
Roger Quadros | 61b7025 | 2014-02-12 12:18:42 +0200 | [diff] [blame] | 693 | goto err_mem; |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 694 | } |
| 695 | |
Roger Quadros | 051fc06 | 2014-02-27 16:18:26 +0200 | [diff] [blame] | 696 | omap->init_60m_fclk = devm_clk_get(dev, "refclk_60m_int"); |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 697 | if (IS_ERR(omap->init_60m_fclk)) { |
| 698 | ret = PTR_ERR(omap->init_60m_fclk); |
Roger Quadros | 051fc06 | 2014-02-27 16:18:26 +0200 | [diff] [blame] | 699 | dev_err(dev, "refclk_60m_int failed error:%d\n", ret); |
Roger Quadros | 61b7025 | 2014-02-12 12:18:42 +0200 | [diff] [blame] | 700 | goto err_mem; |
Roger Quadros | 06ba7dc | 2012-11-08 17:40:25 +0200 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | for (i = 0; i < omap->nports; i++) { |
Roger Quadros | 340c64e | 2012-11-12 16:53:16 +0200 | [diff] [blame] | 704 | char clkname[30]; |
Roger Quadros | 06ba7dc | 2012-11-08 17:40:25 +0200 | [diff] [blame] | 705 | |
| 706 | /* clock names are indexed from 1*/ |
| 707 | snprintf(clkname, sizeof(clkname), |
| 708 | "usb_host_hs_utmi_p%d_clk", i + 1); |
| 709 | |
| 710 | /* If a clock is not found we won't bail out as not all |
| 711 | * platforms have all clocks and we can function without |
| 712 | * them |
| 713 | */ |
Roger Quadros | 61b7025 | 2014-02-12 12:18:42 +0200 | [diff] [blame] | 714 | omap->utmi_clk[i] = devm_clk_get(dev, clkname); |
Roger Quadros | fedb2e7 | 2014-02-27 16:18:24 +0200 | [diff] [blame] | 715 | if (IS_ERR(omap->utmi_clk[i])) { |
| 716 | ret = PTR_ERR(omap->utmi_clk[i]); |
| 717 | dev_err(dev, "Failed to get clock : %s : %d\n", |
| 718 | clkname, ret); |
| 719 | goto err_mem; |
| 720 | } |
Roger Quadros | 340c64e | 2012-11-12 16:53:16 +0200 | [diff] [blame] | 721 | |
| 722 | snprintf(clkname, sizeof(clkname), |
| 723 | "usb_host_hs_hsic480m_p%d_clk", i + 1); |
Roger Quadros | 61b7025 | 2014-02-12 12:18:42 +0200 | [diff] [blame] | 724 | omap->hsic480m_clk[i] = devm_clk_get(dev, clkname); |
Roger Quadros | fedb2e7 | 2014-02-27 16:18:24 +0200 | [diff] [blame] | 725 | if (IS_ERR(omap->hsic480m_clk[i])) { |
| 726 | ret = PTR_ERR(omap->hsic480m_clk[i]); |
| 727 | dev_err(dev, "Failed to get clock : %s : %d\n", |
| 728 | clkname, ret); |
| 729 | goto err_mem; |
| 730 | } |
Roger Quadros | 340c64e | 2012-11-12 16:53:16 +0200 | [diff] [blame] | 731 | |
| 732 | snprintf(clkname, sizeof(clkname), |
| 733 | "usb_host_hs_hsic60m_p%d_clk", i + 1); |
Roger Quadros | 61b7025 | 2014-02-12 12:18:42 +0200 | [diff] [blame] | 734 | omap->hsic60m_clk[i] = devm_clk_get(dev, clkname); |
Roger Quadros | fedb2e7 | 2014-02-27 16:18:24 +0200 | [diff] [blame] | 735 | if (IS_ERR(omap->hsic60m_clk[i])) { |
| 736 | ret = PTR_ERR(omap->hsic60m_clk[i]); |
| 737 | dev_err(dev, "Failed to get clock : %s : %d\n", |
| 738 | clkname, ret); |
| 739 | goto err_mem; |
| 740 | } |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | if (is_ehci_phy_mode(pdata->port_mode[0])) { |
Roger Quadros | 06ba7dc | 2012-11-08 17:40:25 +0200 | [diff] [blame] | 744 | ret = clk_set_parent(omap->utmi_p1_gfclk, |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 745 | omap->xclk60mhsp1_ck); |
Roger Quadros | fedb2e7 | 2014-02-27 16:18:24 +0200 | [diff] [blame] | 746 | if (ret != 0) { |
| 747 | dev_err(dev, "xclk60mhsp1_ck set parent failed: %d\n", |
| 748 | ret); |
| 749 | goto err_mem; |
| 750 | } |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 751 | } else if (is_ehci_tll_mode(pdata->port_mode[0])) { |
Roger Quadros | 06ba7dc | 2012-11-08 17:40:25 +0200 | [diff] [blame] | 752 | ret = clk_set_parent(omap->utmi_p1_gfclk, |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 753 | omap->init_60m_fclk); |
Roger Quadros | fedb2e7 | 2014-02-27 16:18:24 +0200 | [diff] [blame] | 754 | if (ret != 0) { |
| 755 | dev_err(dev, "P0 init_60m_fclk set parent failed: %d\n", |
| 756 | ret); |
| 757 | goto err_mem; |
| 758 | } |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | if (is_ehci_phy_mode(pdata->port_mode[1])) { |
Roger Quadros | 06ba7dc | 2012-11-08 17:40:25 +0200 | [diff] [blame] | 762 | ret = clk_set_parent(omap->utmi_p2_gfclk, |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 763 | omap->xclk60mhsp2_ck); |
Roger Quadros | fedb2e7 | 2014-02-27 16:18:24 +0200 | [diff] [blame] | 764 | if (ret != 0) { |
| 765 | dev_err(dev, "xclk60mhsp2_ck set parent failed: %d\n", |
| 766 | ret); |
| 767 | goto err_mem; |
| 768 | } |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 769 | } else if (is_ehci_tll_mode(pdata->port_mode[1])) { |
Roger Quadros | 06ba7dc | 2012-11-08 17:40:25 +0200 | [diff] [blame] | 770 | ret = clk_set_parent(omap->utmi_p2_gfclk, |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 771 | omap->init_60m_fclk); |
Roger Quadros | fedb2e7 | 2014-02-27 16:18:24 +0200 | [diff] [blame] | 772 | if (ret != 0) { |
| 773 | dev_err(dev, "P1 init_60m_fclk set parent failed: %d\n", |
| 774 | ret); |
| 775 | goto err_mem; |
| 776 | } |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 777 | } |
| 778 | |
Roger Quadros | 3aca446 | 2014-02-27 16:18:23 +0200 | [diff] [blame] | 779 | initialize: |
Govindraj.R | f0447a6 | 2012-02-15 15:53:34 +0530 | [diff] [blame] | 780 | omap_usbhs_init(dev); |
Roger Quadros | 03a8f43 | 2013-04-09 11:39:18 +0300 | [diff] [blame] | 781 | |
| 782 | if (dev->of_node) { |
| 783 | ret = of_platform_populate(dev->of_node, |
| 784 | usbhs_child_match_table, NULL, dev); |
| 785 | |
| 786 | if (ret) { |
| 787 | dev_err(dev, "Failed to create DT children: %d\n", ret); |
Roger Quadros | 61b7025 | 2014-02-12 12:18:42 +0200 | [diff] [blame] | 788 | goto err_mem; |
Roger Quadros | 03a8f43 | 2013-04-09 11:39:18 +0300 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | } else { |
| 792 | ret = omap_usbhs_alloc_children(pdev); |
| 793 | if (ret) { |
| 794 | dev_err(dev, "omap_usbhs_alloc_children failed: %d\n", |
| 795 | ret); |
Roger Quadros | 61b7025 | 2014-02-12 12:18:42 +0200 | [diff] [blame] | 796 | goto err_mem; |
Roger Quadros | 03a8f43 | 2013-04-09 11:39:18 +0300 | [diff] [blame] | 797 | } |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 798 | } |
| 799 | |
Roger Quadros | 27d4f2c | 2012-11-26 17:59:22 +0200 | [diff] [blame] | 800 | return 0; |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 801 | |
Roger Quadros | 06ba7dc | 2012-11-08 17:40:25 +0200 | [diff] [blame] | 802 | err_mem: |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 803 | pm_runtime_disable(dev); |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 804 | |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 805 | return ret; |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 806 | } |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 807 | |
Roger Quadros | 03a8f43 | 2013-04-09 11:39:18 +0300 | [diff] [blame] | 808 | static int usbhs_omap_remove_child(struct device *dev, void *data) |
| 809 | { |
| 810 | dev_info(dev, "unregistering\n"); |
| 811 | platform_device_unregister(to_platform_device(dev)); |
| 812 | return 0; |
| 813 | } |
| 814 | |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 815 | /** |
| 816 | * usbhs_omap_remove - shutdown processing for UHH & TLL HCDs |
| 817 | * @pdev: USB Host Controller being removed |
| 818 | * |
| 819 | * Reverses the effect of usbhs_omap_probe(). |
| 820 | */ |
Bill Pemberton | 4740f73 | 2012-11-19 13:26:01 -0500 | [diff] [blame] | 821 | static int usbhs_omap_remove(struct platform_device *pdev) |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 822 | { |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 823 | pm_runtime_disable(&pdev->dev); |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 824 | |
Roger Quadros | 03a8f43 | 2013-04-09 11:39:18 +0300 | [diff] [blame] | 825 | /* remove children */ |
| 826 | device_for_each_child(&pdev->dev, NULL, usbhs_omap_remove_child); |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 827 | return 0; |
| 828 | } |
| 829 | |
| 830 | static const struct dev_pm_ops usbhsomap_dev_pm_ops = { |
| 831 | .runtime_suspend = usbhs_runtime_suspend, |
| 832 | .runtime_resume = usbhs_runtime_resume, |
| 833 | }; |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 834 | |
Roger Quadros | 03a8f43 | 2013-04-09 11:39:18 +0300 | [diff] [blame] | 835 | static const struct of_device_id usbhs_omap_dt_ids[] = { |
| 836 | { .compatible = "ti,usbhs-host" }, |
| 837 | { } |
| 838 | }; |
| 839 | |
| 840 | MODULE_DEVICE_TABLE(of, usbhs_omap_dt_ids); |
| 841 | |
| 842 | |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 843 | static struct platform_driver usbhs_omap_driver = { |
| 844 | .driver = { |
Corentin Labbe | 9a153b0 | 2020-02-18 20:09:01 +0000 | [diff] [blame] | 845 | .name = usbhs_driver_name, |
Keshava Munegowda | 1e7fe1a | 2011-10-11 13:23:29 +0530 | [diff] [blame] | 846 | .pm = &usbhsomap_dev_pm_ops, |
Sachin Kamat | 0f54e1e | 2013-10-15 09:18:50 +0530 | [diff] [blame] | 847 | .of_match_table = usbhs_omap_dt_ids, |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 848 | }, |
Tony Lindgren | 10492ee | 2018-04-25 07:29:22 -0700 | [diff] [blame] | 849 | .probe = usbhs_omap_probe, |
Roger Quadros | ab3f2a8 | 2013-01-02 15:59:28 +0200 | [diff] [blame] | 850 | .remove = usbhs_omap_remove, |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 851 | }; |
| 852 | |
| 853 | MODULE_AUTHOR("Keshava Munegowda <keshava_mgowda@ti.com>"); |
Roger Quadros | 03a8f43 | 2013-04-09 11:39:18 +0300 | [diff] [blame] | 854 | MODULE_AUTHOR("Roger Quadros <rogerq@ti.com>"); |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 855 | MODULE_ALIAS("platform:" USBHS_DRIVER_NAME); |
| 856 | MODULE_LICENSE("GPL v2"); |
| 857 | MODULE_DESCRIPTION("usb host common core driver for omap EHCI and OHCI"); |
| 858 | |
Tony Lindgren | 10492ee | 2018-04-25 07:29:22 -0700 | [diff] [blame] | 859 | static int omap_usbhs_drvinit(void) |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 860 | { |
Tony Lindgren | 10492ee | 2018-04-25 07:29:22 -0700 | [diff] [blame] | 861 | return platform_driver_register(&usbhs_omap_driver); |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 862 | } |
| 863 | |
| 864 | /* |
| 865 | * init before ehci and ohci drivers; |
| 866 | * The usbhs core driver should be initialized much before |
| 867 | * the omap ehci and ohci probe functions are called. |
Keshava Munegowda | 4dc2cce | 2012-07-16 19:01:09 +0530 | [diff] [blame] | 868 | * This usbhs core driver should be initialized after |
| 869 | * usb tll driver |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 870 | */ |
Keshava Munegowda | 4dc2cce | 2012-07-16 19:01:09 +0530 | [diff] [blame] | 871 | fs_initcall_sync(omap_usbhs_drvinit); |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 872 | |
Tony Lindgren | 10492ee | 2018-04-25 07:29:22 -0700 | [diff] [blame] | 873 | static void omap_usbhs_drvexit(void) |
Keshava Munegowda | 17cdd29 | 2011-03-01 20:08:17 +0530 | [diff] [blame] | 874 | { |
| 875 | platform_driver_unregister(&usbhs_omap_driver); |
| 876 | } |
| 877 | module_exit(omap_usbhs_drvexit); |