1
2
3
4
5
6
7
8
9
10
11
12
13
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>
20
21static int ohci_sm501_init(struct usb_hcd *hcd)
22{
23 return ohci_init(hcd_to_ohci(hcd));
24}
25
26static int ohci_sm501_start(struct usb_hcd *hcd)
27{
28 struct device *dev = hcd->self.controller;
29 int ret;
30
31 ret = ohci_run(hcd_to_ohci(hcd));
32 if (ret < 0) {
33 dev_err(dev, "can't start %s", hcd->self.bus_name);
34 ohci_stop(hcd);
35 }
36
37 return ret;
38}
39
40
41
42static 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),
46
47
48
49
50 .irq = ohci_irq,
51 .flags = HCD_USB11 | HCD_MEMORY | HCD_LOCAL_MEM,
52
53
54
55
56 .reset = ohci_sm501_init,
57 .start = ohci_sm501_start,
58 .stop = ohci_stop,
59 .shutdown = ohci_shutdown,
60
61
62
63
64 .urb_enqueue = ohci_urb_enqueue,
65 .urb_dequeue = ohci_urb_dequeue,
66 .endpoint_disable = ohci_endpoint_disable,
67
68
69
70
71 .get_frame_number = ohci_get_frame,
72
73
74
75
76 .hub_status_data = ohci_hub_status_data,
77 .hub_control = ohci_hub_control,
78#ifdef CONFIG_PM
79 .bus_suspend = ohci_bus_suspend,
80 .bus_resume = ohci_bus_resume,
81#endif
82 .start_port_reset = ohci_start_port_reset,
83};
84
85
86
87static int ohci_hcd_sm501_drv_probe(struct platform_device *pdev)
88{
89 const struct hc_driver *driver = &ohci_sm501_hc_driver;
90 struct device *dev = &pdev->dev;
91 struct resource *res, *mem;
92 int retval, irq;
93 struct usb_hcd *hcd = NULL;
94
95 irq = retval = platform_get_irq(pdev, 0);
96 if (retval < 0)
97 goto err0;
98
99 mem = platform_get_resource(pdev, IORESOURCE_MEM, 1);
100 if (mem == NULL) {
101 dev_err(dev, "no resource definition for memory\n");
102 retval = -ENOENT;
103 goto err0;
104 }
105
106 if (!request_mem_region(mem->start, mem->end - mem->start + 1,
107 pdev->name)) {
108 dev_err(dev, "request_mem_region failed\n");
109 retval = -EBUSY;
110 goto err0;
111 }
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127 if (!dma_declare_coherent_memory(dev, mem->start,
128 mem->start - mem->parent->start,
129 (mem->end - mem->start) + 1,
130 DMA_MEMORY_MAP |
131 DMA_MEMORY_EXCLUSIVE)) {
132 dev_err(dev, "cannot declare coherent memory\n");
133 retval = -ENXIO;
134 goto err1;
135 }
136
137
138 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
139 if (res == NULL) {
140 dev_err(dev, "no resource definition for registers\n");
141 retval = -ENOENT;
142 goto err2;
143 }
144
145 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
146 if (!hcd) {
147 retval = -ENOMEM;
148 goto err2;
149 }
150
151 hcd->rsrc_start = res->start;
152 hcd->rsrc_len = res->end - res->start + 1;
153
154 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, pdev->name)) {
155 dev_err(dev, "request_mem_region failed\n");
156 retval = -EBUSY;
157 goto err3;
158 }
159
160 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
161 if (hcd->regs == NULL) {
162 dev_err(dev, "cannot remap registers\n");
163 retval = -ENXIO;
164 goto err4;
165 }
166
167 ohci_hcd_init(hcd_to_ohci(hcd));
168
169 retval = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
170 if (retval)
171 goto err5;
172
173
174
175 sm501_unit_power(dev->parent, SM501_GATE_USB_HOST, 1);
176 sm501_modify_reg(dev->parent, SM501_IRQ_MASK, 1 << 6, 0);
177
178 return 0;
179err5:
180 iounmap(hcd->regs);
181err4:
182 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
183err3:
184 usb_put_hcd(hcd);
185err2:
186 dma_release_declared_memory(dev);
187err1:
188 release_mem_region(mem->start, mem->end - mem->start + 1);
189err0:
190 return retval;
191}
192
193static int ohci_hcd_sm501_drv_remove(struct platform_device *pdev)
194{
195 struct usb_hcd *hcd = platform_get_drvdata(pdev);
196 struct resource *mem;
197
198 usb_remove_hcd(hcd);
199 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
200 usb_put_hcd(hcd);
201 dma_release_declared_memory(&pdev->dev);
202 mem = platform_get_resource(pdev, IORESOURCE_MEM, 1);
203 if (mem)
204 release_mem_region(mem->start, mem->end - mem->start + 1);
205
206
207
208 sm501_modify_reg(pdev->dev.parent, SM501_IRQ_MASK, 0, 1 << 6);
209 sm501_unit_power(pdev->dev.parent, SM501_GATE_USB_HOST, 0);
210
211 platform_set_drvdata(pdev, NULL);
212 return 0;
213}
214
215
216
217#ifdef CONFIG_PM
218static int ohci_sm501_suspend(struct platform_device *pdev, pm_message_t msg)
219{
220 struct device *dev = &pdev->dev;
221 struct ohci_hcd *ohci = hcd_to_ohci(platform_get_drvdata(pdev));
222
223 if (time_before(jiffies, ohci->next_statechange))
224 msleep(5);
225 ohci->next_statechange = jiffies;
226
227 sm501_unit_power(dev->parent, SM501_GATE_USB_HOST, 0);
228 ohci_to_hcd(ohci)->state = HC_STATE_SUSPENDED;
229 return 0;
230}
231
232static int ohci_sm501_resume(struct platform_device *pdev)
233{
234 struct device *dev = &pdev->dev;
235 struct usb_hcd *hcd = platform_get_drvdata(pdev);
236 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
237
238 if (time_before(jiffies, ohci->next_statechange))
239 msleep(5);
240 ohci->next_statechange = jiffies;
241
242 sm501_unit_power(dev->parent, SM501_GATE_USB_HOST, 1);
243 ohci_finish_controller_resume(hcd);
244 return 0;
245}
246#else
247#define ohci_sm501_suspend NULL
248#define ohci_sm501_resume NULL
249#endif
250
251
252
253
254
255
256static 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,
262 .driver = {
263 .owner = THIS_MODULE,
264 .name = "sm501-usb",
265 },
266};
267MODULE_ALIAS("platform:sm501-usb");
268