2 * OHCI HCD(Host Controller Driver) for USB.
4 *(C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 *(C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
6 *(C) Copyright 2002 Hewlett-Packard Company
8 * Bus glue for Toshiba Mobile IO(TMIO) Controller's OHCI core
9 * (C) Copyright 2005 Chris Humbert <mahadri-usb@drigon.com>
10 * (C) Copyright 2007, 2008 Dmitry Baryshkov <dbaryshkov@gmail.com>
12 * This is known to work with the following variants:
13 * TC6393XB revision 3 (32kB SRAM)
15 * The TMIO's OHCI core DMAs through a small internal buffer that
16 * is directly addressable by the CPU.
18 * Written from sparse documentation from Toshiba and Sharp's driver
20 * usb-ohci-tc6393.c(C) Copyright 2004 Lineo Solutions, Inc.
22 * This program is free software; you can redistribute it and/or modify
23 * it under the terms of the GNU General Public License version 2 as
24 * published by the Free Software Foundation.
27 /*#include <linux/fs.h>
28 #include <linux/mount.h>
29 #include <linux/pagemap.h>
30 #include <linux/namei.h>
31 #include <linux/sched.h>*/
32 #include <linux/platform_device.h>
33 #include <linux/mfd/core.h>
34 #include <linux/mfd/tmio.h>
35 #include <linux/dma-mapping.h>
37 /*-------------------------------------------------------------------------*/
40 * USB Host Controller Configuration Register
42 #define CCR_REVID 0x08 /* b Revision ID */
43 #define CCR_BASE 0x10 /* l USB Control Register Base Address Low */
44 #define CCR_ILME 0x40 /* b Internal Local Memory Enable */
45 #define CCR_PM 0x4c /* w Power Management */
46 #define CCR_INTC 0x50 /* b INT Control */
47 #define CCR_LMW1L 0x54 /* w Local Memory Window 1 LMADRS Low */
48 #define CCR_LMW1H 0x56 /* w Local Memory Window 1 LMADRS High */
49 #define CCR_LMW1BL 0x58 /* w Local Memory Window 1 Base Address Low */
50 #define CCR_LMW1BH 0x5A /* w Local Memory Window 1 Base Address High */
51 #define CCR_LMW2L 0x5C /* w Local Memory Window 2 LMADRS Low */
52 #define CCR_LMW2H 0x5E /* w Local Memory Window 2 LMADRS High */
53 #define CCR_LMW2BL 0x60 /* w Local Memory Window 2 Base Address Low */
54 #define CCR_LMW2BH 0x62 /* w Local Memory Window 2 Base Address High */
55 #define CCR_MISC 0xFC /* b MISC */
57 #define CCR_PM_GKEN 0x0001
58 #define CCR_PM_CKRNEN 0x0002
59 #define CCR_PM_USBPW1 0x0004
60 #define CCR_PM_USBPW2 0x0008
61 #define CCR_PM_USBPW3 0x0010
62 #define CCR_PM_PMEE 0x0100
63 #define CCR_PM_PMES 0x8000
65 /*-------------------------------------------------------------------------*/
69 spinlock_t lock; /* protects RMW cycles */
72 #define hcd_to_tmio(hcd) ((struct tmio_hcd *)(hcd_to_ohci(hcd) + 1))
74 /*-------------------------------------------------------------------------*/
76 static void tmio_write_pm(struct platform_device *dev)
78 struct usb_hcd *hcd = platform_get_drvdata(dev);
79 struct tmio_hcd *tmio = hcd_to_tmio(hcd);
83 spin_lock_irqsave(&tmio->lock, flags);
85 pm = CCR_PM_GKEN | CCR_PM_CKRNEN |
86 CCR_PM_PMEE | CCR_PM_PMES;
88 tmio_iowrite16(pm, tmio->ccr + CCR_PM);
89 spin_unlock_irqrestore(&tmio->lock, flags);
92 static void tmio_stop_hc(struct platform_device *dev)
94 struct usb_hcd *hcd = platform_get_drvdata(dev);
95 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
96 struct tmio_hcd *tmio = hcd_to_tmio(hcd);
99 pm = CCR_PM_GKEN | CCR_PM_CKRNEN;
100 switch (ohci->num_ports) {
102 dev_err(&dev->dev, "Unsupported amount of ports: %d\n", ohci->num_ports);
110 tmio_iowrite8(0, tmio->ccr + CCR_INTC);
111 tmio_iowrite8(0, tmio->ccr + CCR_ILME);
112 tmio_iowrite16(0, tmio->ccr + CCR_BASE);
113 tmio_iowrite16(0, tmio->ccr + CCR_BASE + 2);
114 tmio_iowrite16(pm, tmio->ccr + CCR_PM);
117 static void tmio_start_hc(struct platform_device *dev)
119 struct usb_hcd *hcd = platform_get_drvdata(dev);
120 struct tmio_hcd *tmio = hcd_to_tmio(hcd);
121 unsigned long base = hcd->rsrc_start;
124 tmio_iowrite16(base, tmio->ccr + CCR_BASE);
125 tmio_iowrite16(base >> 16, tmio->ccr + CCR_BASE + 2);
126 tmio_iowrite8(1, tmio->ccr + CCR_ILME);
127 tmio_iowrite8(2, tmio->ccr + CCR_INTC);
129 dev_info(&dev->dev, "revision %d @ 0x%08llx, irq %d\n",
130 tmio_ioread8(tmio->ccr + CCR_REVID),
131 (u64) hcd->rsrc_start, hcd->irq);
134 static int ohci_tmio_start(struct usb_hcd *hcd)
136 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
139 if ((ret = ohci_init(ohci)) < 0)
142 if ((ret = ohci_run(ohci)) < 0) {
143 dev_err(hcd->self.controller, "can't start %s\n",
152 static const struct hc_driver ohci_tmio_hc_driver = {
153 .description = hcd_name,
154 .product_desc = "TMIO OHCI USB Host Controller",
155 .hcd_priv_size = sizeof(struct ohci_hcd) + sizeof (struct tmio_hcd),
157 /* generic hardware linkage */
159 .flags = HCD_USB11 | HCD_MEMORY | HCD_LOCAL_MEM,
161 /* basic lifecycle operations */
162 .start = ohci_tmio_start,
164 .shutdown = ohci_shutdown,
166 /* managing i/o requests and associated device resources */
167 .urb_enqueue = ohci_urb_enqueue,
168 .urb_dequeue = ohci_urb_dequeue,
169 .endpoint_disable = ohci_endpoint_disable,
171 /* scheduling support */
172 .get_frame_number = ohci_get_frame,
174 /* root hub support */
175 .hub_status_data = ohci_hub_status_data,
176 .hub_control = ohci_hub_control,
178 .bus_suspend = ohci_bus_suspend,
179 .bus_resume = ohci_bus_resume,
181 .start_port_reset = ohci_start_port_reset,
184 /*-------------------------------------------------------------------------*/
185 static struct platform_driver ohci_hcd_tmio_driver;
187 static int ohci_hcd_tmio_drv_probe(struct platform_device *dev)
189 const struct mfd_cell *cell = mfd_get_cell(dev);
190 struct resource *regs = platform_get_resource(dev, IORESOURCE_MEM, 0);
191 struct resource *config = platform_get_resource(dev, IORESOURCE_MEM, 1);
192 struct resource *sram = platform_get_resource(dev, IORESOURCE_MEM, 2);
193 int irq = platform_get_irq(dev, 0);
194 struct tmio_hcd *tmio;
195 struct ohci_hcd *ohci;
202 if (!cell || !regs || !config || !sram)
208 hcd = usb_create_hcd(&ohci_tmio_hc_driver, &dev->dev, dev_name(&dev->dev));
211 goto err_usb_create_hcd;
214 hcd->rsrc_start = regs->start;
215 hcd->rsrc_len = resource_size(regs);
217 tmio = hcd_to_tmio(hcd);
219 spin_lock_init(&tmio->lock);
221 tmio->ccr = ioremap(config->start, resource_size(config));
224 goto err_ioremap_ccr;
227 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
230 goto err_ioremap_regs;
233 if (!dma_declare_coherent_memory(&dev->dev, sram->start,
236 DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE)) {
238 goto err_dma_declare;
242 ret = cell->enable(dev);
248 ohci = hcd_to_ohci(hcd);
251 ret = usb_add_hcd(hcd, irq, 0);
255 device_wakeup_enable(hcd->self.controller);
266 dma_release_declared_memory(&dev->dev);
278 static int ohci_hcd_tmio_drv_remove(struct platform_device *dev)
280 struct usb_hcd *hcd = platform_get_drvdata(dev);
281 struct tmio_hcd *tmio = hcd_to_tmio(hcd);
282 const struct mfd_cell *cell = mfd_get_cell(dev);
288 dma_release_declared_memory(&dev->dev);
297 static int ohci_hcd_tmio_drv_suspend(struct platform_device *dev, pm_message_t state)
299 const struct mfd_cell *cell = mfd_get_cell(dev);
300 struct usb_hcd *hcd = platform_get_drvdata(dev);
301 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
302 struct tmio_hcd *tmio = hcd_to_tmio(hcd);
307 if (time_before(jiffies, ohci->next_statechange))
309 ohci->next_statechange = jiffies;
311 spin_lock_irqsave(&tmio->lock, flags);
313 misc = tmio_ioread8(tmio->ccr + CCR_MISC);
314 misc |= 1 << 3; /* USSUSP */
315 tmio_iowrite8(misc, tmio->ccr + CCR_MISC);
317 spin_unlock_irqrestore(&tmio->lock, flags);
320 ret = cell->suspend(dev);
327 static int ohci_hcd_tmio_drv_resume(struct platform_device *dev)
329 const struct mfd_cell *cell = mfd_get_cell(dev);
330 struct usb_hcd *hcd = platform_get_drvdata(dev);
331 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
332 struct tmio_hcd *tmio = hcd_to_tmio(hcd);
337 if (time_before(jiffies, ohci->next_statechange))
339 ohci->next_statechange = jiffies;
342 ret = cell->resume(dev);
349 spin_lock_irqsave(&tmio->lock, flags);
351 misc = tmio_ioread8(tmio->ccr + CCR_MISC);
352 misc &= ~(1 << 3); /* USSUSP */
353 tmio_iowrite8(misc, tmio->ccr + CCR_MISC);
355 spin_unlock_irqrestore(&tmio->lock, flags);
357 ohci_resume(hcd, false);
362 #define ohci_hcd_tmio_drv_suspend NULL
363 #define ohci_hcd_tmio_drv_resume NULL
366 static struct platform_driver ohci_hcd_tmio_driver = {
367 .probe = ohci_hcd_tmio_drv_probe,
368 .remove = ohci_hcd_tmio_drv_remove,
369 .shutdown = usb_hcd_platform_shutdown,
370 .suspend = ohci_hcd_tmio_drv_suspend,
371 .resume = ohci_hcd_tmio_drv_resume,