blob: 1d924d1533c02756124dffe1262e4333ed9b6b5f [file] [log] [blame]
Keshava Munegowda17cdd292011-03-01 20:08:17 +05301/**
2 * omap-usb-host.c - The USBHS core driver for OMAP EHCI & OHCI
3 *
Roger Quadros03a8f432013-04-09 11:39:18 +03004 * Copyright (C) 2011-2013 Texas Instruments Incorporated - http://www.ti.com
Keshava Munegowda17cdd292011-03-01 20:08:17 +05305 * Author: Keshava Munegowda <keshava_mgowda@ti.com>
Roger Quadros03a8f432013-04-09 11:39:18 +03006 * Author: Roger Quadros <rogerq@ti.com>
Keshava Munegowda17cdd292011-03-01 20:08:17 +05307 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 of
10 * the License as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20#include <linux/kernel.h>
Ming Lei417e2062011-08-19 16:57:54 +080021#include <linux/module.h>
Keshava Munegowda17cdd292011-03-01 20:08:17 +053022#include <linux/types.h>
23#include <linux/slab.h>
24#include <linux/delay.h>
Keshava Munegowda17cdd292011-03-01 20:08:17 +053025#include <linux/clk.h>
26#include <linux/dma-mapping.h>
Russ Dillc05995c2012-06-14 09:24:21 -070027#include <linux/gpio.h>
Felipe Balbie8c4a7a2012-10-24 14:26:19 -070028#include <linux/platform_device.h>
29#include <linux/platform_data/usb-omap.h>
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +053030#include <linux/pm_runtime.h>
Roger Quadros03a8f432013-04-09 11:39:18 +030031#include <linux/of.h>
32#include <linux/of_platform.h>
Sachin Kamatd011c452013-04-09 16:16:36 +053033#include <linux/err.h>
Keshava Munegowda17cdd292011-03-01 20:08:17 +053034
Felipe Balbie8c4a7a2012-10-24 14:26:19 -070035#include "omap-usb.h"
36
Keshava Munegowdaa6d3a662011-10-11 13:21:51 +053037#define USBHS_DRIVER_NAME "usbhs_omap"
Keshava Munegowda17cdd292011-03-01 20:08:17 +053038#define OMAP_EHCI_DEVICE "ehci-omap"
39#define OMAP_OHCI_DEVICE "ohci-omap3"
40
41/* OMAP USBHOST Register addresses */
42
Keshava Munegowda17cdd292011-03-01 20:08:17 +053043/* UHH Register Set */
44#define OMAP_UHH_REVISION (0x00)
45#define OMAP_UHH_SYSCONFIG (0x10)
46#define OMAP_UHH_SYSCONFIG_MIDLEMODE (1 << 12)
47#define OMAP_UHH_SYSCONFIG_CACTIVITY (1 << 8)
48#define OMAP_UHH_SYSCONFIG_SIDLEMODE (1 << 3)
49#define OMAP_UHH_SYSCONFIG_ENAWAKEUP (1 << 2)
50#define OMAP_UHH_SYSCONFIG_SOFTRESET (1 << 1)
51#define OMAP_UHH_SYSCONFIG_AUTOIDLE (1 << 0)
52
53#define OMAP_UHH_SYSSTATUS (0x14)
54#define OMAP_UHH_HOSTCONFIG (0x40)
55#define OMAP_UHH_HOSTCONFIG_ULPI_BYPASS (1 << 0)
56#define OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS (1 << 0)
57#define OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS (1 << 11)
58#define OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS (1 << 12)
59#define OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN (1 << 2)
60#define OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN (1 << 3)
61#define OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN (1 << 4)
62#define OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN (1 << 5)
63#define OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS (1 << 8)
64#define OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS (1 << 9)
65#define OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS (1 << 10)
66#define OMAP4_UHH_HOSTCONFIG_APP_START_CLK (1 << 31)
67
68/* OMAP4-specific defines */
69#define OMAP4_UHH_SYSCONFIG_IDLEMODE_CLEAR (3 << 2)
70#define OMAP4_UHH_SYSCONFIG_NOIDLE (1 << 2)
71#define OMAP4_UHH_SYSCONFIG_STDBYMODE_CLEAR (3 << 4)
72#define OMAP4_UHH_SYSCONFIG_NOSTDBY (1 << 4)
73#define OMAP4_UHH_SYSCONFIG_SOFTRESET (1 << 0)
74
75#define OMAP4_P1_MODE_CLEAR (3 << 16)
76#define OMAP4_P1_MODE_TLL (1 << 16)
77#define OMAP4_P1_MODE_HSIC (3 << 16)
78#define OMAP4_P2_MODE_CLEAR (3 << 18)
79#define OMAP4_P2_MODE_TLL (1 << 18)
80#define OMAP4_P2_MODE_HSIC (3 << 18)
81
Keshava Munegowda17cdd292011-03-01 20:08:17 +053082#define OMAP_UHH_DEBUG_CSR (0x44)
83
84/* Values of UHH_REVISION - Note: these are not given in the TRM */
85#define OMAP_USBHS_REV1 0x00000010 /* OMAP3 */
86#define OMAP_USBHS_REV2 0x50700100 /* OMAP4 */
87
88#define is_omap_usbhs_rev1(x) (x->usbhs_rev == OMAP_USBHS_REV1)
89#define is_omap_usbhs_rev2(x) (x->usbhs_rev == OMAP_USBHS_REV2)
90
91#define is_ehci_phy_mode(x) (x == OMAP_EHCI_PORT_MODE_PHY)
92#define is_ehci_tll_mode(x) (x == OMAP_EHCI_PORT_MODE_TLL)
93#define is_ehci_hsic_mode(x) (x == OMAP_EHCI_PORT_MODE_HSIC)
94
95
96struct usbhs_hcd_omap {
Roger Quadrosd7eaf862012-11-08 18:04:26 +020097 int nports;
Roger Quadros06ba7dc2012-11-08 17:40:25 +020098 struct clk **utmi_clk;
Roger Quadros340c64e2012-11-12 16:53:16 +020099 struct clk **hsic60m_clk;
100 struct clk **hsic480m_clk;
Roger Quadrosd7eaf862012-11-08 18:04:26 +0200101
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530102 struct clk *xclk60mhsp1_ck;
103 struct clk *xclk60mhsp2_ck;
Roger Quadros06ba7dc2012-11-08 17:40:25 +0200104 struct clk *utmi_p1_gfclk;
105 struct clk *utmi_p2_gfclk;
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530106 struct clk *init_60m_fclk;
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530107 struct clk *ehci_logic_fck;
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530108
109 void __iomem *uhh_base;
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530110
Roger Quadros9d9c6ae2013-02-13 13:16:25 +0200111 struct usbhs_omap_platform_data *pdata;
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530112
113 u32 usbhs_rev;
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530114};
115/*-------------------------------------------------------------------------*/
116
Sachin Kamat7844b982013-08-23 16:42:58 +0530117static const char usbhs_driver_name[] = USBHS_DRIVER_NAME;
Govindraj.Rcbb8c222012-02-15 12:27:50 +0530118static u64 usbhs_dmamask = DMA_BIT_MASK(32);
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530119
120/*-------------------------------------------------------------------------*/
121
122static inline void usbhs_write(void __iomem *base, u32 reg, u32 val)
123{
Victor Kamensky9981a312013-11-16 02:01:14 +0200124 writel_relaxed(val, base + reg);
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530125}
126
127static inline u32 usbhs_read(void __iomem *base, u32 reg)
128{
Victor Kamensky9981a312013-11-16 02:01:14 +0200129 return readl_relaxed(base + reg);
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530130}
131
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530132/*-------------------------------------------------------------------------*/
133
Roger Quadros03a8f432013-04-09 11:39:18 +0300134/**
135 * Map 'enum usbhs_omap_port_mode' found in <linux/platform_data/usb-omap.h>
136 * to the device tree binding portN-mode found in
137 * 'Documentation/devicetree/bindings/mfd/omap-usb-host.txt'
138 */
139static const char * const port_modes[] = {
140 [OMAP_USBHS_PORT_MODE_UNUSED] = "",
141 [OMAP_EHCI_PORT_MODE_PHY] = "ehci-phy",
142 [OMAP_EHCI_PORT_MODE_TLL] = "ehci-tll",
143 [OMAP_EHCI_PORT_MODE_HSIC] = "ehci-hsic",
144 [OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0] = "ohci-phy-6pin-datse0",
145 [OMAP_OHCI_PORT_MODE_PHY_6PIN_DPDM] = "ohci-phy-6pin-dpdm",
146 [OMAP_OHCI_PORT_MODE_PHY_3PIN_DATSE0] = "ohci-phy-3pin-datse0",
147 [OMAP_OHCI_PORT_MODE_PHY_4PIN_DPDM] = "ohci-phy-4pin-dpdm",
148 [OMAP_OHCI_PORT_MODE_TLL_6PIN_DATSE0] = "ohci-tll-6pin-datse0",
149 [OMAP_OHCI_PORT_MODE_TLL_6PIN_DPDM] = "ohci-tll-6pin-dpdm",
150 [OMAP_OHCI_PORT_MODE_TLL_3PIN_DATSE0] = "ohci-tll-3pin-datse0",
151 [OMAP_OHCI_PORT_MODE_TLL_4PIN_DPDM] = "ohci-tll-4pin-dpdm",
152 [OMAP_OHCI_PORT_MODE_TLL_2PIN_DATSE0] = "ohci-tll-2pin-datse0",
153 [OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM] = "ohci-tll-2pin-dpdm",
154};
155
156/**
157 * omap_usbhs_get_dt_port_mode - Get the 'enum usbhs_omap_port_mode'
158 * from the port mode string.
159 * @mode: The port mode string, usually obtained from device tree.
160 *
161 * The function returns the 'enum usbhs_omap_port_mode' that matches the
162 * provided port mode string as per the port_modes table.
163 * If no match is found it returns -ENODEV
164 */
165static const int omap_usbhs_get_dt_port_mode(const char *mode)
166{
167 int i;
168
169 for (i = 0; i < ARRAY_SIZE(port_modes); i++) {
170 if (!strcmp(mode, port_modes[i]))
171 return i;
172 }
173
174 return -ENODEV;
175}
176
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530177static struct platform_device *omap_usbhs_alloc_child(const char *name,
178 struct resource *res, int num_resources, void *pdata,
179 size_t pdata_size, struct device *dev)
180{
181 struct platform_device *child;
182 int ret;
183
184 child = platform_device_alloc(name, 0);
185
186 if (!child) {
187 dev_err(dev, "platform_device_alloc %s failed\n", name);
188 goto err_end;
189 }
190
191 ret = platform_device_add_resources(child, res, num_resources);
192 if (ret) {
193 dev_err(dev, "platform_device_add_resources failed\n");
194 goto err_alloc;
195 }
196
197 ret = platform_device_add_data(child, pdata, pdata_size);
198 if (ret) {
199 dev_err(dev, "platform_device_add_data failed\n");
200 goto err_alloc;
201 }
202
203 child->dev.dma_mask = &usbhs_dmamask;
Govindraj.Rcbb8c222012-02-15 12:27:50 +0530204 dma_set_coherent_mask(&child->dev, DMA_BIT_MASK(32));
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530205 child->dev.parent = dev;
206
207 ret = platform_device_add(child);
208 if (ret) {
209 dev_err(dev, "platform_device_add failed\n");
210 goto err_alloc;
211 }
212
213 return child;
214
215err_alloc:
216 platform_device_put(child);
217
218err_end:
219 return NULL;
220}
221
222static int omap_usbhs_alloc_children(struct platform_device *pdev)
223{
224 struct device *dev = &pdev->dev;
Jingoo Han334a41c2013-07-30 17:10:05 +0900225 struct usbhs_omap_platform_data *pdata = dev_get_platdata(dev);
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530226 struct platform_device *ehci;
227 struct platform_device *ohci;
228 struct resource *res;
229 struct resource resources[2];
230 int ret;
231
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530232 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ehci");
233 if (!res) {
234 dev_err(dev, "EHCI get resource IORESOURCE_MEM failed\n");
235 ret = -ENODEV;
236 goto err_end;
237 }
238 resources[0] = *res;
239
240 res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "ehci-irq");
241 if (!res) {
242 dev_err(dev, " EHCI get resource IORESOURCE_IRQ failed\n");
243 ret = -ENODEV;
244 goto err_end;
245 }
246 resources[1] = *res;
247
Roger Quadros9d9c6ae2013-02-13 13:16:25 +0200248 ehci = omap_usbhs_alloc_child(OMAP_EHCI_DEVICE, resources, 2, pdata,
249 sizeof(*pdata), dev);
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530250
251 if (!ehci) {
252 dev_err(dev, "omap_usbhs_alloc_child failed\n");
Axel Lind9107742011-05-14 14:15:36 +0800253 ret = -ENOMEM;
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530254 goto err_end;
255 }
256
257 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ohci");
258 if (!res) {
259 dev_err(dev, "OHCI get resource IORESOURCE_MEM failed\n");
260 ret = -ENODEV;
261 goto err_ehci;
262 }
263 resources[0] = *res;
264
265 res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "ohci-irq");
266 if (!res) {
267 dev_err(dev, "OHCI get resource IORESOURCE_IRQ failed\n");
268 ret = -ENODEV;
269 goto err_ehci;
270 }
271 resources[1] = *res;
272
Roger Quadros9d9c6ae2013-02-13 13:16:25 +0200273 ohci = omap_usbhs_alloc_child(OMAP_OHCI_DEVICE, resources, 2, pdata,
274 sizeof(*pdata), dev);
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530275 if (!ohci) {
276 dev_err(dev, "omap_usbhs_alloc_child failed\n");
Axel Lind9107742011-05-14 14:15:36 +0800277 ret = -ENOMEM;
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530278 goto err_ehci;
279 }
280
281 return 0;
282
283err_ehci:
Axel Lind9107742011-05-14 14:15:36 +0800284 platform_device_unregister(ehci);
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530285
286err_end:
287 return ret;
288}
289
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530290static bool is_ohci_port(enum usbhs_omap_port_mode pmode)
291{
292 switch (pmode) {
293 case OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0:
294 case OMAP_OHCI_PORT_MODE_PHY_6PIN_DPDM:
295 case OMAP_OHCI_PORT_MODE_PHY_3PIN_DATSE0:
296 case OMAP_OHCI_PORT_MODE_PHY_4PIN_DPDM:
297 case OMAP_OHCI_PORT_MODE_TLL_6PIN_DATSE0:
298 case OMAP_OHCI_PORT_MODE_TLL_6PIN_DPDM:
299 case OMAP_OHCI_PORT_MODE_TLL_3PIN_DATSE0:
300 case OMAP_OHCI_PORT_MODE_TLL_4PIN_DPDM:
301 case OMAP_OHCI_PORT_MODE_TLL_2PIN_DATSE0:
302 case OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM:
303 return true;
304
305 default:
306 return false;
307 }
308}
309
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530310static int usbhs_runtime_resume(struct device *dev)
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530311{
312 struct usbhs_hcd_omap *omap = dev_get_drvdata(dev);
Roger Quadros9d9c6ae2013-02-13 13:16:25 +0200313 struct usbhs_omap_platform_data *pdata = omap->pdata;
Roger Quadros06ba7dc2012-11-08 17:40:25 +0200314 int i, r;
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530315
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530316 dev_dbg(dev, "usbhs_runtime_resume\n");
317
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200318 omap_tll_enable(pdata);
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530319
Roger Quadros06ba7dc2012-11-08 17:40:25 +0200320 if (!IS_ERR(omap->ehci_logic_fck))
Roger Quadrosb0e59922013-10-15 15:30:34 +0300321 clk_prepare_enable(omap->ehci_logic_fck);
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530322
Roger Quadros06ba7dc2012-11-08 17:40:25 +0200323 for (i = 0; i < omap->nports; i++) {
Roger Quadros340c64e2012-11-12 16:53:16 +0200324 switch (pdata->port_mode[i]) {
325 case OMAP_EHCI_PORT_MODE_HSIC:
326 if (!IS_ERR(omap->hsic60m_clk[i])) {
Roger Quadrosb0e59922013-10-15 15:30:34 +0300327 r = clk_prepare_enable(omap->hsic60m_clk[i]);
Roger Quadros340c64e2012-11-12 16:53:16 +0200328 if (r) {
329 dev_err(dev,
330 "Can't enable port %d hsic60m clk:%d\n",
331 i, r);
332 }
333 }
Keshava Munegowda760189b2012-07-16 19:01:10 +0530334
Roger Quadros340c64e2012-11-12 16:53:16 +0200335 if (!IS_ERR(omap->hsic480m_clk[i])) {
Roger Quadrosb0e59922013-10-15 15:30:34 +0300336 r = clk_prepare_enable(omap->hsic480m_clk[i]);
Roger Quadros340c64e2012-11-12 16:53:16 +0200337 if (r) {
338 dev_err(dev,
339 "Can't enable port %d hsic480m clk:%d\n",
340 i, r);
341 }
342 }
343 /* Fall through as HSIC mode needs utmi_clk */
344
345 case OMAP_EHCI_PORT_MODE_TLL:
346 if (!IS_ERR(omap->utmi_clk[i])) {
Roger Quadrosb0e59922013-10-15 15:30:34 +0300347 r = clk_prepare_enable(omap->utmi_clk[i]);
Roger Quadros340c64e2012-11-12 16:53:16 +0200348 if (r) {
349 dev_err(dev,
350 "Can't enable port %d clk : %d\n",
351 i, r);
352 }
353 }
354 break;
355 default:
356 break;
357 }
Roger Quadros06ba7dc2012-11-08 17:40:25 +0200358 }
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530359
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530360 return 0;
361}
362
363static int usbhs_runtime_suspend(struct device *dev)
364{
365 struct usbhs_hcd_omap *omap = dev_get_drvdata(dev);
Roger Quadros9d9c6ae2013-02-13 13:16:25 +0200366 struct usbhs_omap_platform_data *pdata = omap->pdata;
Roger Quadros06ba7dc2012-11-08 17:40:25 +0200367 int i;
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530368
369 dev_dbg(dev, "usbhs_runtime_suspend\n");
370
Roger Quadros06ba7dc2012-11-08 17:40:25 +0200371 for (i = 0; i < omap->nports; i++) {
Roger Quadros340c64e2012-11-12 16:53:16 +0200372 switch (pdata->port_mode[i]) {
373 case OMAP_EHCI_PORT_MODE_HSIC:
374 if (!IS_ERR(omap->hsic60m_clk[i]))
Roger Quadrosb0e59922013-10-15 15:30:34 +0300375 clk_disable_unprepare(omap->hsic60m_clk[i]);
Roger Quadros340c64e2012-11-12 16:53:16 +0200376
377 if (!IS_ERR(omap->hsic480m_clk[i]))
Roger Quadrosb0e59922013-10-15 15:30:34 +0300378 clk_disable_unprepare(omap->hsic480m_clk[i]);
Roger Quadros340c64e2012-11-12 16:53:16 +0200379 /* Fall through as utmi_clks were used in HSIC mode */
380
381 case OMAP_EHCI_PORT_MODE_TLL:
382 if (!IS_ERR(omap->utmi_clk[i]))
Roger Quadrosb0e59922013-10-15 15:30:34 +0300383 clk_disable_unprepare(omap->utmi_clk[i]);
Roger Quadros340c64e2012-11-12 16:53:16 +0200384 break;
385 default:
386 break;
387 }
Roger Quadros06ba7dc2012-11-08 17:40:25 +0200388 }
Keshava Munegowda760189b2012-07-16 19:01:10 +0530389
Roger Quadros06ba7dc2012-11-08 17:40:25 +0200390 if (!IS_ERR(omap->ehci_logic_fck))
Roger Quadrosb0e59922013-10-15 15:30:34 +0300391 clk_disable_unprepare(omap->ehci_logic_fck);
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530392
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200393 omap_tll_disable(pdata);
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530394
395 return 0;
396}
397
Roger Quadrosc4df00a2012-11-12 16:32:01 +0200398static unsigned omap_usbhs_rev1_hostconfig(struct usbhs_hcd_omap *omap,
399 unsigned reg)
400{
401 struct usbhs_omap_platform_data *pdata = omap->pdata;
402 int i;
403
404 for (i = 0; i < omap->nports; i++) {
405 switch (pdata->port_mode[i]) {
406 case OMAP_USBHS_PORT_MODE_UNUSED:
407 reg &= ~(OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS << i);
408 break;
409 case OMAP_EHCI_PORT_MODE_PHY:
410 if (pdata->single_ulpi_bypass)
411 break;
412
413 if (i == 0)
414 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
415 else
416 reg &= ~(OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS
417 << (i-1));
418 break;
419 default:
420 if (pdata->single_ulpi_bypass)
421 break;
422
423 if (i == 0)
424 reg |= OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
425 else
426 reg |= OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS
427 << (i-1);
428 break;
429 }
430 }
431
432 if (pdata->single_ulpi_bypass) {
433 /* bypass ULPI only if none of the ports use PHY mode */
434 reg |= OMAP_UHH_HOSTCONFIG_ULPI_BYPASS;
435
436 for (i = 0; i < omap->nports; i++) {
437 if (is_ehci_phy_mode(pdata->port_mode[i])) {
Michael Welling46de8ff2014-07-28 18:01:04 -0500438 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_BYPASS;
Roger Quadrosc4df00a2012-11-12 16:32:01 +0200439 break;
440 }
441 }
442 }
443
444 return reg;
445}
446
447static unsigned omap_usbhs_rev2_hostconfig(struct usbhs_hcd_omap *omap,
448 unsigned reg)
449{
450 struct usbhs_omap_platform_data *pdata = omap->pdata;
451 int i;
452
453 for (i = 0; i < omap->nports; i++) {
454 /* Clear port mode fields for PHY mode */
455 reg &= ~(OMAP4_P1_MODE_CLEAR << 2 * i);
456
457 if (is_ehci_tll_mode(pdata->port_mode[i]) ||
458 (is_ohci_port(pdata->port_mode[i])))
459 reg |= OMAP4_P1_MODE_TLL << 2 * i;
460 else if (is_ehci_hsic_mode(pdata->port_mode[i]))
461 reg |= OMAP4_P1_MODE_HSIC << 2 * i;
462 }
463
464 return reg;
465}
466
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530467static void omap_usbhs_init(struct device *dev)
468{
469 struct usbhs_hcd_omap *omap = dev_get_drvdata(dev);
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530470 unsigned reg;
471
472 dev_dbg(dev, "starting TI HSUSB Controller\n");
473
Keshava Munegowda760189b2012-07-16 19:01:10 +0530474 pm_runtime_get_sync(dev);
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530475
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530476 reg = usbhs_read(omap->uhh_base, OMAP_UHH_HOSTCONFIG);
477 /* setup ULPI bypass and burst configurations */
478 reg |= (OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN
479 | OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN
480 | OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN);
481 reg |= OMAP4_UHH_HOSTCONFIG_APP_START_CLK;
482 reg &= ~OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN;
483
Roger Quadrosc4df00a2012-11-12 16:32:01 +0200484 switch (omap->usbhs_rev) {
485 case OMAP_USBHS_REV1:
Roger Quadros26bacba2013-02-27 15:19:24 +0200486 reg = omap_usbhs_rev1_hostconfig(omap, reg);
Roger Quadrosc4df00a2012-11-12 16:32:01 +0200487 break;
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530488
Roger Quadrosc4df00a2012-11-12 16:32:01 +0200489 case OMAP_USBHS_REV2:
Roger Quadros26bacba2013-02-27 15:19:24 +0200490 reg = omap_usbhs_rev2_hostconfig(omap, reg);
Roger Quadrosc4df00a2012-11-12 16:32:01 +0200491 break;
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530492
Roger Quadrosc4df00a2012-11-12 16:32:01 +0200493 default: /* newer revisions */
Roger Quadros26bacba2013-02-27 15:19:24 +0200494 reg = omap_usbhs_rev2_hostconfig(omap, reg);
Roger Quadrosc4df00a2012-11-12 16:32:01 +0200495 break;
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530496 }
497
498 usbhs_write(omap->uhh_base, OMAP_UHH_HOSTCONFIG, reg);
499 dev_dbg(dev, "UHH setup done, uhh_hostconfig=%x\n", reg);
500
Keshava Munegowda760189b2012-07-16 19:01:10 +0530501 pm_runtime_put_sync(dev);
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530502}
503
Roger Quadros03a8f432013-04-09 11:39:18 +0300504static int usbhs_omap_get_dt_pdata(struct device *dev,
505 struct usbhs_omap_platform_data *pdata)
506{
507 int ret, i;
508 struct device_node *node = dev->of_node;
509
510 ret = of_property_read_u32(node, "num-ports", &pdata->nports);
511 if (ret)
512 pdata->nports = 0;
513
514 if (pdata->nports > OMAP3_HS_USB_PORTS) {
515 dev_warn(dev, "Too many num_ports <%d> in device tree. Max %d\n",
516 pdata->nports, OMAP3_HS_USB_PORTS);
517 return -ENODEV;
518 }
519
520 /* get port modes */
521 for (i = 0; i < OMAP3_HS_USB_PORTS; i++) {
522 char prop[11];
523 const char *mode;
524
525 pdata->port_mode[i] = OMAP_USBHS_PORT_MODE_UNUSED;
526
527 snprintf(prop, sizeof(prop), "port%d-mode", i + 1);
528 ret = of_property_read_string(node, prop, &mode);
529 if (ret < 0)
530 continue;
531
532 ret = omap_usbhs_get_dt_port_mode(mode);
533 if (ret < 0) {
534 dev_warn(dev, "Invalid port%d-mode \"%s\" in device tree\n",
535 i, mode);
536 return -ENODEV;
537 }
538
539 dev_dbg(dev, "port%d-mode: %s -> %d\n", i, mode, ret);
540 pdata->port_mode[i] = ret;
541 }
542
543 /* get flags */
544 pdata->single_ulpi_bypass = of_property_read_bool(node,
545 "single-ulpi-bypass");
546
547 return 0;
548}
549
Krzysztof Kozlowskia7cfee82014-05-13 12:58:47 +0200550static const struct of_device_id usbhs_child_match_table[] = {
Roger Quadros03a8f432013-04-09 11:39:18 +0300551 { .compatible = "ti,omap-ehci", },
552 { .compatible = "ti,omap-ohci", },
553 { }
554};
555
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530556/**
557 * usbhs_omap_probe - initialize TI-based HCDs
558 *
559 * Allocates basic resources for this USB host controller.
560 */
Bill Pembertonf791be42012-11-19 13:23:04 -0500561static int usbhs_omap_probe(struct platform_device *pdev)
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530562{
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530563 struct device *dev = &pdev->dev;
Jingoo Han334a41c2013-07-30 17:10:05 +0900564 struct usbhs_omap_platform_data *pdata = dev_get_platdata(dev);
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530565 struct usbhs_hcd_omap *omap;
566 struct resource *res;
567 int ret = 0;
568 int i;
Roger Quadros06ba7dc2012-11-08 17:40:25 +0200569 bool need_logic_fck;
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530570
Roger Quadros03a8f432013-04-09 11:39:18 +0300571 if (dev->of_node) {
572 /* For DT boot we populate platform data from OF node */
573 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
574 if (!pdata)
575 return -ENOMEM;
576
577 ret = usbhs_omap_get_dt_pdata(dev, pdata);
578 if (ret)
579 return ret;
580
581 dev->platform_data = pdata;
582 }
583
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530584 if (!pdata) {
585 dev_err(dev, "Missing platform data\n");
Roger Quadros27d4f2c2012-11-26 17:59:22 +0200586 return -ENODEV;
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530587 }
588
Roger Quadros03a8f432013-04-09 11:39:18 +0300589 if (pdata->nports > OMAP3_HS_USB_PORTS) {
590 dev_info(dev, "Too many num_ports <%d> in platform_data. Max %d\n",
591 pdata->nports, OMAP3_HS_USB_PORTS);
592 return -ENODEV;
593 }
594
Roger Quadros27d4f2c2012-11-26 17:59:22 +0200595 omap = devm_kzalloc(dev, sizeof(*omap), GFP_KERNEL);
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530596 if (!omap) {
597 dev_err(dev, "Memory allocation failed\n");
Roger Quadros27d4f2c2012-11-26 17:59:22 +0200598 return -ENOMEM;
599 }
600
Roger Quadros03a8f432013-04-09 11:39:18 +0300601 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Sachin Kamatd011c452013-04-09 16:16:36 +0530602 omap->uhh_base = devm_ioremap_resource(dev, res);
603 if (IS_ERR(omap->uhh_base))
604 return PTR_ERR(omap->uhh_base);
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530605
Roger Quadros9d9c6ae2013-02-13 13:16:25 +0200606 omap->pdata = pdata;
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530607
Roger Quadros9f4a3ec2013-01-29 15:00:03 +0200608 /* Initialize the TLL subsystem */
609 omap_tll_init(pdata);
610
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530611 pm_runtime_enable(dev);
612
Roger Quadrosd7eaf862012-11-08 18:04:26 +0200613 platform_set_drvdata(pdev, omap);
614 pm_runtime_get_sync(dev);
615
616 omap->usbhs_rev = usbhs_read(omap->uhh_base, OMAP_UHH_REVISION);
617
618 /* we need to call runtime suspend before we update omap->nports
619 * to prevent unbalanced clk_disable()
620 */
621 pm_runtime_put_sync(dev);
622
Roger Quadrosccac71a2012-11-08 19:18:08 +0200623 /*
624 * If platform data contains nports then use that
625 * else make out number of ports from USBHS revision
626 */
627 if (pdata->nports) {
628 omap->nports = pdata->nports;
629 } else {
630 switch (omap->usbhs_rev) {
631 case OMAP_USBHS_REV1:
632 omap->nports = 3;
633 break;
634 case OMAP_USBHS_REV2:
635 omap->nports = 2;
636 break;
637 default:
638 omap->nports = OMAP3_HS_USB_PORTS;
639 dev_dbg(dev,
Hans Wennborgddde06b2014-08-03 17:19:27 -0700640 "USB HOST Rev:0x%x not recognized, assuming %d ports\n",
Roger Quadrosccac71a2012-11-08 19:18:08 +0200641 omap->usbhs_rev, omap->nports);
642 break;
643 }
Roger Quadros662e4692013-01-08 16:01:52 +0200644 pdata->nports = omap->nports;
Roger Quadrosd7eaf862012-11-08 18:04:26 +0200645 }
646
Roger Quadros06ba7dc2012-11-08 17:40:25 +0200647 i = sizeof(struct clk *) * omap->nports;
648 omap->utmi_clk = devm_kzalloc(dev, i, GFP_KERNEL);
Roger Quadros340c64e2012-11-12 16:53:16 +0200649 omap->hsic480m_clk = devm_kzalloc(dev, i, GFP_KERNEL);
650 omap->hsic60m_clk = devm_kzalloc(dev, i, GFP_KERNEL);
651
652 if (!omap->utmi_clk || !omap->hsic480m_clk || !omap->hsic60m_clk) {
Roger Quadros06ba7dc2012-11-08 17:40:25 +0200653 dev_err(dev, "Memory allocation failed\n");
654 ret = -ENOMEM;
655 goto err_mem;
656 }
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530657
Roger Quadros3aca4462014-02-27 16:18:23 +0200658 /* Set all clocks as invalid to begin with */
659 omap->ehci_logic_fck = ERR_PTR(-ENODEV);
660 omap->init_60m_fclk = ERR_PTR(-ENODEV);
661 omap->utmi_p1_gfclk = ERR_PTR(-ENODEV);
662 omap->utmi_p2_gfclk = ERR_PTR(-ENODEV);
663 omap->xclk60mhsp1_ck = ERR_PTR(-ENODEV);
664 omap->xclk60mhsp2_ck = ERR_PTR(-ENODEV);
665
Roger Quadros06ba7dc2012-11-08 17:40:25 +0200666 for (i = 0; i < omap->nports; i++) {
Roger Quadros3aca4462014-02-27 16:18:23 +0200667 omap->utmi_clk[i] = ERR_PTR(-ENODEV);
668 omap->hsic480m_clk[i] = ERR_PTR(-ENODEV);
669 omap->hsic60m_clk[i] = ERR_PTR(-ENODEV);
670 }
671
672 /* for OMAP3 i.e. USBHS REV1 */
673 if (omap->usbhs_rev == OMAP_USBHS_REV1) {
674 need_logic_fck = false;
675 for (i = 0; i < omap->nports; i++) {
676 if (is_ehci_phy_mode(pdata->port_mode[i]) ||
677 is_ehci_tll_mode(pdata->port_mode[i]) ||
678 is_ehci_hsic_mode(pdata->port_mode[i]))
679
Roger Quadros06ba7dc2012-11-08 17:40:25 +0200680 need_logic_fck |= true;
Roger Quadros06ba7dc2012-11-08 17:40:25 +0200681 }
Roger Quadros3aca4462014-02-27 16:18:23 +0200682
683 if (need_logic_fck) {
684 omap->ehci_logic_fck = devm_clk_get(dev,
Roger Quadros775bb072014-02-27 16:18:25 +0200685 "usbhost_120m_fck");
Roger Quadros3aca4462014-02-27 16:18:23 +0200686 if (IS_ERR(omap->ehci_logic_fck)) {
687 ret = PTR_ERR(omap->ehci_logic_fck);
Roger Quadros775bb072014-02-27 16:18:25 +0200688 dev_err(dev, "usbhost_120m_fck failed:%d\n",
689 ret);
Roger Quadrosfedb2e72014-02-27 16:18:24 +0200690 goto err_mem;
Roger Quadros3aca4462014-02-27 16:18:23 +0200691 }
692 }
693 goto initialize;
Roger Quadros06ba7dc2012-11-08 17:40:25 +0200694 }
695
Roger Quadros3aca4462014-02-27 16:18:23 +0200696 /* for OMAP4+ i.e. USBHS REV2+ */
Roger Quadros61b70252014-02-12 12:18:42 +0200697 omap->utmi_p1_gfclk = devm_clk_get(dev, "utmi_p1_gfclk");
Roger Quadros06ba7dc2012-11-08 17:40:25 +0200698 if (IS_ERR(omap->utmi_p1_gfclk)) {
699 ret = PTR_ERR(omap->utmi_p1_gfclk);
700 dev_err(dev, "utmi_p1_gfclk failed error:%d\n", ret);
Roger Quadros61b70252014-02-12 12:18:42 +0200701 goto err_mem;
Roger Quadros06ba7dc2012-11-08 17:40:25 +0200702 }
703
Roger Quadros61b70252014-02-12 12:18:42 +0200704 omap->utmi_p2_gfclk = devm_clk_get(dev, "utmi_p2_gfclk");
Roger Quadros06ba7dc2012-11-08 17:40:25 +0200705 if (IS_ERR(omap->utmi_p2_gfclk)) {
706 ret = PTR_ERR(omap->utmi_p2_gfclk);
707 dev_err(dev, "utmi_p2_gfclk failed error:%d\n", ret);
Roger Quadros61b70252014-02-12 12:18:42 +0200708 goto err_mem;
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530709 }
710
Roger Quadros051fc062014-02-27 16:18:26 +0200711 omap->xclk60mhsp1_ck = devm_clk_get(dev, "refclk_60m_ext_p1");
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530712 if (IS_ERR(omap->xclk60mhsp1_ck)) {
713 ret = PTR_ERR(omap->xclk60mhsp1_ck);
Roger Quadros051fc062014-02-27 16:18:26 +0200714 dev_err(dev, "refclk_60m_ext_p1 failed error:%d\n", ret);
Roger Quadros61b70252014-02-12 12:18:42 +0200715 goto err_mem;
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530716 }
717
Roger Quadros051fc062014-02-27 16:18:26 +0200718 omap->xclk60mhsp2_ck = devm_clk_get(dev, "refclk_60m_ext_p2");
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530719 if (IS_ERR(omap->xclk60mhsp2_ck)) {
720 ret = PTR_ERR(omap->xclk60mhsp2_ck);
Roger Quadros051fc062014-02-27 16:18:26 +0200721 dev_err(dev, "refclk_60m_ext_p2 failed error:%d\n", ret);
Roger Quadros61b70252014-02-12 12:18:42 +0200722 goto err_mem;
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530723 }
724
Roger Quadros051fc062014-02-27 16:18:26 +0200725 omap->init_60m_fclk = devm_clk_get(dev, "refclk_60m_int");
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530726 if (IS_ERR(omap->init_60m_fclk)) {
727 ret = PTR_ERR(omap->init_60m_fclk);
Roger Quadros051fc062014-02-27 16:18:26 +0200728 dev_err(dev, "refclk_60m_int failed error:%d\n", ret);
Roger Quadros61b70252014-02-12 12:18:42 +0200729 goto err_mem;
Roger Quadros06ba7dc2012-11-08 17:40:25 +0200730 }
731
732 for (i = 0; i < omap->nports; i++) {
Roger Quadros340c64e2012-11-12 16:53:16 +0200733 char clkname[30];
Roger Quadros06ba7dc2012-11-08 17:40:25 +0200734
735 /* clock names are indexed from 1*/
736 snprintf(clkname, sizeof(clkname),
737 "usb_host_hs_utmi_p%d_clk", i + 1);
738
739 /* If a clock is not found we won't bail out as not all
740 * platforms have all clocks and we can function without
741 * them
742 */
Roger Quadros61b70252014-02-12 12:18:42 +0200743 omap->utmi_clk[i] = devm_clk_get(dev, clkname);
Roger Quadrosfedb2e72014-02-27 16:18:24 +0200744 if (IS_ERR(omap->utmi_clk[i])) {
745 ret = PTR_ERR(omap->utmi_clk[i]);
746 dev_err(dev, "Failed to get clock : %s : %d\n",
747 clkname, ret);
748 goto err_mem;
749 }
Roger Quadros340c64e2012-11-12 16:53:16 +0200750
751 snprintf(clkname, sizeof(clkname),
752 "usb_host_hs_hsic480m_p%d_clk", i + 1);
Roger Quadros61b70252014-02-12 12:18:42 +0200753 omap->hsic480m_clk[i] = devm_clk_get(dev, clkname);
Roger Quadrosfedb2e72014-02-27 16:18:24 +0200754 if (IS_ERR(omap->hsic480m_clk[i])) {
755 ret = PTR_ERR(omap->hsic480m_clk[i]);
756 dev_err(dev, "Failed to get clock : %s : %d\n",
757 clkname, ret);
758 goto err_mem;
759 }
Roger Quadros340c64e2012-11-12 16:53:16 +0200760
761 snprintf(clkname, sizeof(clkname),
762 "usb_host_hs_hsic60m_p%d_clk", i + 1);
Roger Quadros61b70252014-02-12 12:18:42 +0200763 omap->hsic60m_clk[i] = devm_clk_get(dev, clkname);
Roger Quadrosfedb2e72014-02-27 16:18:24 +0200764 if (IS_ERR(omap->hsic60m_clk[i])) {
765 ret = PTR_ERR(omap->hsic60m_clk[i]);
766 dev_err(dev, "Failed to get clock : %s : %d\n",
767 clkname, ret);
768 goto err_mem;
769 }
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530770 }
771
772 if (is_ehci_phy_mode(pdata->port_mode[0])) {
Roger Quadros06ba7dc2012-11-08 17:40:25 +0200773 ret = clk_set_parent(omap->utmi_p1_gfclk,
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530774 omap->xclk60mhsp1_ck);
Roger Quadrosfedb2e72014-02-27 16:18:24 +0200775 if (ret != 0) {
776 dev_err(dev, "xclk60mhsp1_ck set parent failed: %d\n",
777 ret);
778 goto err_mem;
779 }
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530780 } else if (is_ehci_tll_mode(pdata->port_mode[0])) {
Roger Quadros06ba7dc2012-11-08 17:40:25 +0200781 ret = clk_set_parent(omap->utmi_p1_gfclk,
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530782 omap->init_60m_fclk);
Roger Quadrosfedb2e72014-02-27 16:18:24 +0200783 if (ret != 0) {
784 dev_err(dev, "P0 init_60m_fclk set parent failed: %d\n",
785 ret);
786 goto err_mem;
787 }
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530788 }
789
790 if (is_ehci_phy_mode(pdata->port_mode[1])) {
Roger Quadros06ba7dc2012-11-08 17:40:25 +0200791 ret = clk_set_parent(omap->utmi_p2_gfclk,
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530792 omap->xclk60mhsp2_ck);
Roger Quadrosfedb2e72014-02-27 16:18:24 +0200793 if (ret != 0) {
794 dev_err(dev, "xclk60mhsp2_ck set parent failed: %d\n",
795 ret);
796 goto err_mem;
797 }
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530798 } else if (is_ehci_tll_mode(pdata->port_mode[1])) {
Roger Quadros06ba7dc2012-11-08 17:40:25 +0200799 ret = clk_set_parent(omap->utmi_p2_gfclk,
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530800 omap->init_60m_fclk);
Roger Quadrosfedb2e72014-02-27 16:18:24 +0200801 if (ret != 0) {
802 dev_err(dev, "P1 init_60m_fclk set parent failed: %d\n",
803 ret);
804 goto err_mem;
805 }
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530806 }
807
Roger Quadros3aca4462014-02-27 16:18:23 +0200808initialize:
Govindraj.Rf0447a62012-02-15 15:53:34 +0530809 omap_usbhs_init(dev);
Roger Quadros03a8f432013-04-09 11:39:18 +0300810
811 if (dev->of_node) {
812 ret = of_platform_populate(dev->of_node,
813 usbhs_child_match_table, NULL, dev);
814
815 if (ret) {
816 dev_err(dev, "Failed to create DT children: %d\n", ret);
Roger Quadros61b70252014-02-12 12:18:42 +0200817 goto err_mem;
Roger Quadros03a8f432013-04-09 11:39:18 +0300818 }
819
820 } else {
821 ret = omap_usbhs_alloc_children(pdev);
822 if (ret) {
823 dev_err(dev, "omap_usbhs_alloc_children failed: %d\n",
824 ret);
Roger Quadros61b70252014-02-12 12:18:42 +0200825 goto err_mem;
Roger Quadros03a8f432013-04-09 11:39:18 +0300826 }
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530827 }
828
Roger Quadros27d4f2c2012-11-26 17:59:22 +0200829 return 0;
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530830
Roger Quadros06ba7dc2012-11-08 17:40:25 +0200831err_mem:
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530832 pm_runtime_disable(dev);
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530833
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530834 return ret;
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530835}
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530836
Roger Quadros03a8f432013-04-09 11:39:18 +0300837static int usbhs_omap_remove_child(struct device *dev, void *data)
838{
839 dev_info(dev, "unregistering\n");
840 platform_device_unregister(to_platform_device(dev));
841 return 0;
842}
843
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530844/**
845 * usbhs_omap_remove - shutdown processing for UHH & TLL HCDs
846 * @pdev: USB Host Controller being removed
847 *
848 * Reverses the effect of usbhs_omap_probe().
849 */
Bill Pemberton4740f732012-11-19 13:26:01 -0500850static int usbhs_omap_remove(struct platform_device *pdev)
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530851{
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530852 pm_runtime_disable(&pdev->dev);
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530853
Roger Quadros03a8f432013-04-09 11:39:18 +0300854 /* remove children */
855 device_for_each_child(&pdev->dev, NULL, usbhs_omap_remove_child);
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530856 return 0;
857}
858
859static const struct dev_pm_ops usbhsomap_dev_pm_ops = {
860 .runtime_suspend = usbhs_runtime_suspend,
861 .runtime_resume = usbhs_runtime_resume,
862};
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530863
Roger Quadros03a8f432013-04-09 11:39:18 +0300864static const struct of_device_id usbhs_omap_dt_ids[] = {
865 { .compatible = "ti,usbhs-host" },
866 { }
867};
868
869MODULE_DEVICE_TABLE(of, usbhs_omap_dt_ids);
870
871
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530872static struct platform_driver usbhs_omap_driver = {
873 .driver = {
874 .name = (char *)usbhs_driver_name,
Keshava Munegowda1e7fe1a2011-10-11 13:23:29 +0530875 .pm = &usbhsomap_dev_pm_ops,
Sachin Kamat0f54e1e2013-10-15 09:18:50 +0530876 .of_match_table = usbhs_omap_dt_ids,
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530877 },
Roger Quadrosab3f2a82013-01-02 15:59:28 +0200878 .remove = usbhs_omap_remove,
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530879};
880
881MODULE_AUTHOR("Keshava Munegowda <keshava_mgowda@ti.com>");
Roger Quadros03a8f432013-04-09 11:39:18 +0300882MODULE_AUTHOR("Roger Quadros <rogerq@ti.com>");
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530883MODULE_ALIAS("platform:" USBHS_DRIVER_NAME);
884MODULE_LICENSE("GPL v2");
885MODULE_DESCRIPTION("usb host common core driver for omap EHCI and OHCI");
886
887static int __init omap_usbhs_drvinit(void)
888{
889 return platform_driver_probe(&usbhs_omap_driver, usbhs_omap_probe);
890}
891
892/*
893 * init before ehci and ohci drivers;
894 * The usbhs core driver should be initialized much before
895 * the omap ehci and ohci probe functions are called.
Keshava Munegowda4dc2cce2012-07-16 19:01:09 +0530896 * This usbhs core driver should be initialized after
897 * usb tll driver
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530898 */
Keshava Munegowda4dc2cce2012-07-16 19:01:09 +0530899fs_initcall_sync(omap_usbhs_drvinit);
Keshava Munegowda17cdd292011-03-01 20:08:17 +0530900
901static void __exit omap_usbhs_drvexit(void)
902{
903 platform_driver_unregister(&usbhs_omap_driver);
904}
905module_exit(omap_usbhs_drvexit);