2 * OHCI HCD (Host Controller Driver) for USB.
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2005 David Brownell
6 * (C) Copyright 2002 Hewlett-Packard Company
7 * (C) Copyright 2008 Magnus Damm
9 * SM501 Bus Glue - based on ohci-omap.c
11 * This file is licenced under the GPL.
14 #include <linux/interrupt.h>
15 #include <linux/jiffies.h>
16 #include <linux/platform_device.h>
17 #include <linux/dma-mapping.h>
18 #include <linux/sm501.h>
19 #include <linux/sm501-regs.h>
21 static int ohci_sm501_init(struct usb_hcd
*hcd
)
23 return ohci_init(hcd_to_ohci(hcd
));
26 static int ohci_sm501_start(struct usb_hcd
*hcd
)
28 struct device
*dev
= hcd
->self
.controller
;
31 ret
= ohci_run(hcd_to_ohci(hcd
));
33 dev_err(dev
, "can't start %s", hcd
->self
.bus_name
);
40 /*-------------------------------------------------------------------------*/
42 static const struct hc_driver ohci_sm501_hc_driver
= {
43 .description
= hcd_name
,
44 .product_desc
= "SM501 OHCI",
45 .hcd_priv_size
= sizeof(struct ohci_hcd
),
48 * generic hardware linkage
51 .flags
= HCD_USB11
| HCD_MEMORY
| HCD_LOCAL_MEM
,
54 * basic lifecycle operations
56 .reset
= ohci_sm501_init
,
57 .start
= ohci_sm501_start
,
59 .shutdown
= ohci_shutdown
,
62 * managing i/o requests and associated device resources
64 .urb_enqueue
= ohci_urb_enqueue
,
65 .urb_dequeue
= ohci_urb_dequeue
,
66 .endpoint_disable
= ohci_endpoint_disable
,
71 .get_frame_number
= ohci_get_frame
,
76 .hub_status_data
= ohci_hub_status_data
,
77 .hub_control
= ohci_hub_control
,
79 .bus_suspend
= ohci_bus_suspend
,
80 .bus_resume
= ohci_bus_resume
,
82 .start_port_reset
= ohci_start_port_reset
,
85 /*-------------------------------------------------------------------------*/
87 static int ohci_hcd_sm501_drv_probe(struct platform_device
*pdev
)
89 const struct hc_driver
*driver
= &ohci_sm501_hc_driver
;
90 struct device
*dev
= &pdev
->dev
;
91 struct resource
*res
, *mem
;
93 struct usb_hcd
*hcd
= NULL
;
95 irq
= retval
= platform_get_irq(pdev
, 0);
99 mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
101 dev_err(dev
, "no resource definition for memory\n");
106 if (!request_mem_region(mem
->start
, mem
->end
- mem
->start
+ 1,
108 dev_err(dev
, "request_mem_region failed\n");
113 /* The sm501 chip is equipped with local memory that may be used
114 * by on-chip devices such as the video controller and the usb host.
115 * This driver uses dma_declare_coherent_memory() to make sure
116 * usb allocations with dma_alloc_coherent() allocate from
117 * this local memory. The dma_handle returned by dma_alloc_coherent()
118 * will be an offset starting from 0 for the first local memory byte.
120 * So as long as data is allocated using dma_alloc_coherent() all is
121 * fine. This is however not always the case - buffers may be allocated
122 * using kmalloc() - so the usb core needs to be told that it must copy
123 * data into our local memory if the buffers happen to be placed in
124 * regular memory. The HCD_LOCAL_MEM flag does just that.
127 if (!dma_declare_coherent_memory(dev
, mem
->start
,
128 mem
->start
- mem
->parent
->start
,
129 (mem
->end
- mem
->start
) + 1,
131 DMA_MEMORY_EXCLUSIVE
)) {
132 dev_err(dev
, "cannot declare coherent memory\n");
137 /* allocate, reserve and remap resources for registers */
138 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
140 dev_err(dev
, "no resource definition for registers\n");
145 hcd
= usb_create_hcd(driver
, &pdev
->dev
, pdev
->dev
.bus_id
);
151 hcd
->rsrc_start
= res
->start
;
152 hcd
->rsrc_len
= res
->end
- res
->start
+ 1;
154 if (!request_mem_region(hcd
->rsrc_start
, hcd
->rsrc_len
, pdev
->name
)) {
155 dev_err(dev
, "request_mem_region failed\n");
160 hcd
->regs
= ioremap(hcd
->rsrc_start
, hcd
->rsrc_len
);
161 if (hcd
->regs
== NULL
) {
162 dev_err(dev
, "cannot remap registers\n");
167 ohci_hcd_init(hcd_to_ohci(hcd
));
169 retval
= usb_add_hcd(hcd
, irq
, IRQF_DISABLED
| IRQF_SHARED
);
173 /* enable power and unmask interrupts */
175 sm501_unit_power(dev
->parent
, SM501_GATE_USB_HOST
, 1);
176 sm501_modify_reg(dev
->parent
, SM501_IRQ_MASK
, 1 << 6, 0);
180 release_mem_region(hcd
->rsrc_start
, hcd
->rsrc_len
);
184 dma_release_declared_memory(dev
);
186 release_mem_region(mem
->start
, mem
->end
- mem
->start
+ 1);
191 static int ohci_hcd_sm501_drv_remove(struct platform_device
*pdev
)
193 struct usb_hcd
*hcd
= platform_get_drvdata(pdev
);
194 struct resource
*mem
;
197 release_mem_region(hcd
->rsrc_start
, hcd
->rsrc_len
);
199 dma_release_declared_memory(&pdev
->dev
);
200 mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
202 release_mem_region(mem
->start
, mem
->end
- mem
->start
+ 1);
204 /* mask interrupts and disable power */
206 sm501_modify_reg(pdev
->dev
.parent
, SM501_IRQ_MASK
, 0, 1 << 6);
207 sm501_unit_power(pdev
->dev
.parent
, SM501_GATE_USB_HOST
, 0);
209 platform_set_drvdata(pdev
, NULL
);
213 /*-------------------------------------------------------------------------*/
216 static int ohci_sm501_suspend(struct platform_device
*pdev
, pm_message_t msg
)
218 struct device
*dev
= &pdev
->dev
;
219 struct ohci_hcd
*ohci
= hcd_to_ohci(platform_get_drvdata(pdev
));
221 if (time_before(jiffies
, ohci
->next_statechange
))
223 ohci
->next_statechange
= jiffies
;
225 sm501_unit_power(dev
->parent
, SM501_GATE_USB_HOST
, 0);
226 ohci_to_hcd(ohci
)->state
= HC_STATE_SUSPENDED
;
230 static int ohci_sm501_resume(struct platform_device
*pdev
)
232 struct device
*dev
= &pdev
->dev
;
233 struct usb_hcd
*hcd
= platform_get_drvdata(pdev
);
234 struct ohci_hcd
*ohci
= hcd_to_ohci(hcd
);
236 if (time_before(jiffies
, ohci
->next_statechange
))
238 ohci
->next_statechange
= jiffies
;
240 sm501_unit_power(dev
->parent
, SM501_GATE_USB_HOST
, 1);
241 ohci_finish_controller_resume(hcd
);
245 #define ohci_sm501_suspend NULL
246 #define ohci_sm501_resume NULL
249 /*-------------------------------------------------------------------------*/
252 * Driver definition to register with the SM501 bus
254 static struct platform_driver ohci_hcd_sm501_driver
= {
255 .probe
= ohci_hcd_sm501_drv_probe
,
256 .remove
= ohci_hcd_sm501_drv_remove
,
257 .shutdown
= usb_hcd_platform_shutdown
,
258 .suspend
= ohci_sm501_suspend
,
259 .resume
= ohci_sm501_resume
,
261 .owner
= THIS_MODULE
,
265 MODULE_ALIAS("platform:sm501-usb");