1 // SPDX-License-Identifier: GPL-1.0+
3 * OHCI HCD (Host Controller Driver) for USB.
5 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
6 * (C) Copyright 2000-2005 David Brownell
7 * (C) Copyright 2002 Hewlett-Packard Company
8 * (C) Copyright 2008 Magnus Damm
10 * SM501 Bus Glue - based on ohci-omap.c
12 * This file is licenced under the GPL.
15 #include <linux/interrupt.h>
16 #include <linux/jiffies.h>
17 #include <linux/platform_device.h>
18 #include <linux/dma-mapping.h>
19 #include <linux/sm501.h>
20 #include <linux/sm501-regs.h>
22 static int ohci_sm501_init(struct usb_hcd
*hcd
)
24 return ohci_init(hcd_to_ohci(hcd
));
27 static int ohci_sm501_start(struct usb_hcd
*hcd
)
29 struct device
*dev
= hcd
->self
.controller
;
32 ret
= ohci_run(hcd_to_ohci(hcd
));
34 dev_err(dev
, "can't start %s", hcd
->self
.bus_name
);
41 /*-------------------------------------------------------------------------*/
43 static const struct hc_driver ohci_sm501_hc_driver
= {
44 .description
= hcd_name
,
45 .product_desc
= "SM501 OHCI",
46 .hcd_priv_size
= sizeof(struct ohci_hcd
),
49 * generic hardware linkage
52 .flags
= HCD_USB11
| HCD_MEMORY
,
55 * basic lifecycle operations
57 .reset
= ohci_sm501_init
,
58 .start
= ohci_sm501_start
,
60 .shutdown
= ohci_shutdown
,
63 * managing i/o requests and associated device resources
65 .urb_enqueue
= ohci_urb_enqueue
,
66 .urb_dequeue
= ohci_urb_dequeue
,
67 .endpoint_disable
= ohci_endpoint_disable
,
72 .get_frame_number
= ohci_get_frame
,
77 .hub_status_data
= ohci_hub_status_data
,
78 .hub_control
= ohci_hub_control
,
80 .bus_suspend
= ohci_bus_suspend
,
81 .bus_resume
= ohci_bus_resume
,
83 .start_port_reset
= ohci_start_port_reset
,
86 /*-------------------------------------------------------------------------*/
88 static int ohci_hcd_sm501_drv_probe(struct platform_device
*pdev
)
90 const struct hc_driver
*driver
= &ohci_sm501_hc_driver
;
91 struct device
*dev
= &pdev
->dev
;
92 struct resource
*res
, *mem
;
94 struct usb_hcd
*hcd
= NULL
;
96 irq
= retval
= platform_get_irq(pdev
, 0);
100 mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
102 dev_err(dev
, "no resource definition for memory\n");
107 if (!request_mem_region(mem
->start
, resource_size(mem
), pdev
->name
)) {
108 dev_err(dev
, "request_mem_region failed\n");
113 /* allocate, reserve and remap resources for registers */
114 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
116 dev_err(dev
, "no resource definition for registers\n");
121 hcd
= usb_create_hcd(driver
, &pdev
->dev
, dev_name(&pdev
->dev
));
127 hcd
->rsrc_start
= res
->start
;
128 hcd
->rsrc_len
= resource_size(res
);
130 if (!request_mem_region(hcd
->rsrc_start
, hcd
->rsrc_len
, pdev
->name
)) {
131 dev_err(dev
, "request_mem_region failed\n");
136 hcd
->regs
= ioremap(hcd
->rsrc_start
, hcd
->rsrc_len
);
137 if (hcd
->regs
== NULL
) {
138 dev_err(dev
, "cannot remap registers\n");
143 ohci_hcd_init(hcd_to_ohci(hcd
));
145 /* The sm501 chip is equipped with local memory that may be used
146 * by on-chip devices such as the video controller and the usb host.
147 * This driver uses genalloc so that usb allocations with
148 * gen_pool_dma_alloc() allocate from this local memory. The dma_handle
149 * returned by gen_pool_dma_alloc() will be an offset starting from 0
150 * for the first local memory byte.
152 * So as long as data is allocated using gen_pool_dma_alloc() all is
153 * fine. This is however not always the case - buffers may be allocated
154 * using kmalloc() - so the usb core needs to be told that it must copy
155 * data into our local memory if the buffers happen to be placed in
156 * regular memory. A non-null hcd->localmem_pool initialized by the
157 * the call to usb_hcd_setup_local_mem() below does just that.
160 retval
= usb_hcd_setup_local_mem(hcd
, mem
->start
,
161 mem
->start
- mem
->parent
->start
,
165 retval
= usb_add_hcd(hcd
, irq
, IRQF_SHARED
);
168 device_wakeup_enable(hcd
->self
.controller
);
170 /* enable power and unmask interrupts */
172 sm501_unit_power(dev
->parent
, SM501_GATE_USB_HOST
, 1);
173 sm501_modify_reg(dev
->parent
, SM501_IRQ_MASK
, 1 << 6, 0);
179 release_mem_region(hcd
->rsrc_start
, hcd
->rsrc_len
);
183 release_mem_region(mem
->start
, resource_size(mem
));
188 static int ohci_hcd_sm501_drv_remove(struct platform_device
*pdev
)
190 struct usb_hcd
*hcd
= platform_get_drvdata(pdev
);
191 struct resource
*mem
;
195 release_mem_region(hcd
->rsrc_start
, hcd
->rsrc_len
);
197 mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
199 release_mem_region(mem
->start
, resource_size(mem
));
201 /* mask interrupts and disable power */
203 sm501_modify_reg(pdev
->dev
.parent
, SM501_IRQ_MASK
, 0, 1 << 6);
204 sm501_unit_power(pdev
->dev
.parent
, SM501_GATE_USB_HOST
, 0);
209 /*-------------------------------------------------------------------------*/
212 static int ohci_sm501_suspend(struct platform_device
*pdev
, pm_message_t msg
)
214 struct device
*dev
= &pdev
->dev
;
215 struct usb_hcd
*hcd
= platform_get_drvdata(pdev
);
216 struct ohci_hcd
*ohci
= hcd_to_ohci(hcd
);
217 bool do_wakeup
= device_may_wakeup(dev
);
220 if (time_before(jiffies
, ohci
->next_statechange
))
222 ohci
->next_statechange
= jiffies
;
224 ret
= ohci_suspend(hcd
, do_wakeup
);
228 sm501_unit_power(dev
->parent
, SM501_GATE_USB_HOST
, 0);
232 static int ohci_sm501_resume(struct platform_device
*pdev
)
234 struct device
*dev
= &pdev
->dev
;
235 struct usb_hcd
*hcd
= platform_get_drvdata(pdev
);
236 struct ohci_hcd
*ohci
= hcd_to_ohci(hcd
);
238 if (time_before(jiffies
, ohci
->next_statechange
))
240 ohci
->next_statechange
= jiffies
;
242 sm501_unit_power(dev
->parent
, SM501_GATE_USB_HOST
, 1);
243 ohci_resume(hcd
, false);
247 #define ohci_sm501_suspend NULL
248 #define ohci_sm501_resume NULL
251 /*-------------------------------------------------------------------------*/
254 * Driver definition to register with the SM501 bus
256 static struct platform_driver ohci_hcd_sm501_driver
= {
257 .probe
= ohci_hcd_sm501_drv_probe
,
258 .remove
= ohci_hcd_sm501_drv_remove
,
259 .shutdown
= usb_hcd_platform_shutdown
,
260 .suspend
= ohci_sm501_suspend
,
261 .resume
= ohci_sm501_resume
,
266 MODULE_ALIAS("platform:sm501-usb");