1
2
3
4
5
6
7
8
9
10
11
12
13
14#include <linux/platform_device.h>
15#include <asm/mach-au1x00/au1000.h>
16
17#define USB_HOST_CONFIG (USB_MSR_BASE + USB_MSR_MCFG)
18#define USB_MCFG_PFEN (1<<31)
19#define USB_MCFG_RDCOMB (1<<30)
20#define USB_MCFG_SSDEN (1<<23)
21#define USB_MCFG_PHYPLLEN (1<<19)
22#define USB_MCFG_UCECLKEN (1<<18)
23#define USB_MCFG_EHCCLKEN (1<<17)
24#ifdef CONFIG_DMA_COHERENT
25#define USB_MCFG_UCAM (1<<7)
26#else
27#define USB_MCFG_UCAM (0)
28#endif
29#define USB_MCFG_EBMEN (1<<3)
30#define USB_MCFG_EMEMEN (1<<2)
31
32#define USBH_ENABLE_CE (USB_MCFG_PHYPLLEN | USB_MCFG_EHCCLKEN)
33#define USBH_ENABLE_INIT (USB_MCFG_PFEN | USB_MCFG_RDCOMB | \
34 USBH_ENABLE_CE | USB_MCFG_SSDEN | \
35 USB_MCFG_UCAM | USB_MCFG_EBMEN | \
36 USB_MCFG_EMEMEN)
37
38#define USBH_DISABLE (USB_MCFG_EBMEN | USB_MCFG_EMEMEN)
39
40extern int usb_disabled(void);
41
42static void au1xxx_start_ehc(void)
43{
44
45 au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_CE, USB_HOST_CONFIG);
46 au_sync();
47 udelay(1000);
48
49
50 au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_INIT, USB_HOST_CONFIG);
51 au_sync();
52 udelay(1000);
53}
54
55static void au1xxx_stop_ehc(void)
56{
57 unsigned long c;
58
59
60 au_writel(au_readl(USB_HOST_CONFIG) & ~USBH_DISABLE, USB_HOST_CONFIG);
61 au_sync();
62 udelay(1000);
63
64
65 c = au_readl(USB_HOST_CONFIG) & ~USB_MCFG_EHCCLKEN;
66 if (!(c & USB_MCFG_UCECLKEN))
67 c &= ~USB_MCFG_PHYPLLEN;
68 au_writel(c, USB_HOST_CONFIG);
69 au_sync();
70}
71
72static const struct hc_driver ehci_au1xxx_hc_driver = {
73 .description = hcd_name,
74 .product_desc = "Au1xxx EHCI",
75 .hcd_priv_size = sizeof(struct ehci_hcd),
76
77
78
79
80 .irq = ehci_irq,
81 .flags = HCD_MEMORY | HCD_USB2,
82
83
84
85
86
87
88
89 .reset = ehci_init,
90 .start = ehci_run,
91 .stop = ehci_stop,
92 .shutdown = ehci_shutdown,
93
94
95
96
97 .urb_enqueue = ehci_urb_enqueue,
98 .urb_dequeue = ehci_urb_dequeue,
99 .endpoint_disable = ehci_endpoint_disable,
100 .endpoint_reset = ehci_endpoint_reset,
101
102
103
104
105 .get_frame_number = ehci_get_frame,
106
107
108
109
110 .hub_status_data = ehci_hub_status_data,
111 .hub_control = ehci_hub_control,
112 .bus_suspend = ehci_bus_suspend,
113 .bus_resume = ehci_bus_resume,
114 .relinquish_port = ehci_relinquish_port,
115 .port_handed_over = ehci_port_handed_over,
116
117 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
118};
119
120static int ehci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
121{
122 struct usb_hcd *hcd;
123 struct ehci_hcd *ehci;
124 int ret;
125
126 if (usb_disabled())
127 return -ENODEV;
128
129#if defined(CONFIG_SOC_AU1200) && defined(CONFIG_DMA_COHERENT)
130
131 if (!(read_c0_prid() & 0xff)) {
132 printk(KERN_INFO "%s: this is chip revision AB!\n", pdev->name);
133 printk(KERN_INFO "%s: update your board or re-configure"
134 " the kernel\n", pdev->name);
135 return -ENODEV;
136 }
137#endif
138
139 if (pdev->resource[1].flags != IORESOURCE_IRQ) {
140 pr_debug("resource[1] is not IORESOURCE_IRQ");
141 return -ENOMEM;
142 }
143 hcd = usb_create_hcd(&ehci_au1xxx_hc_driver, &pdev->dev, "Au1xxx");
144 if (!hcd)
145 return -ENOMEM;
146
147 hcd->rsrc_start = pdev->resource[0].start;
148 hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
149
150 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
151 pr_debug("request_mem_region failed");
152 ret = -EBUSY;
153 goto err1;
154 }
155
156 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
157 if (!hcd->regs) {
158 pr_debug("ioremap failed");
159 ret = -ENOMEM;
160 goto err2;
161 }
162
163 au1xxx_start_ehc();
164
165 ehci = hcd_to_ehci(hcd);
166 ehci->caps = hcd->regs;
167 ehci->regs = hcd->regs + HC_LENGTH(readl(&ehci->caps->hc_capbase));
168
169 ehci->hcs_params = readl(&ehci->caps->hcs_params);
170
171 ret = usb_add_hcd(hcd, pdev->resource[1].start,
172 IRQF_DISABLED | IRQF_SHARED);
173 if (ret == 0) {
174 platform_set_drvdata(pdev, hcd);
175 return ret;
176 }
177
178 au1xxx_stop_ehc();
179 iounmap(hcd->regs);
180err2:
181 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
182err1:
183 usb_put_hcd(hcd);
184 return ret;
185}
186
187static int ehci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
188{
189 struct usb_hcd *hcd = platform_get_drvdata(pdev);
190
191 usb_remove_hcd(hcd);
192 iounmap(hcd->regs);
193 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
194 usb_put_hcd(hcd);
195 au1xxx_stop_ehc();
196 platform_set_drvdata(pdev, NULL);
197
198 return 0;
199}
200
201#ifdef CONFIG_PM
202static int ehci_hcd_au1xxx_drv_suspend(struct device *dev)
203{
204 struct usb_hcd *hcd = dev_get_drvdata(dev);
205 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
206 unsigned long flags;
207 int rc;
208
209 return 0;
210 rc = 0;
211
212 if (time_before(jiffies, ehci->next_statechange))
213 msleep(10);
214
215
216
217
218
219
220
221
222
223 spin_lock_irqsave(&ehci->lock, flags);
224 if (hcd->state != HC_STATE_SUSPENDED) {
225 rc = -EINVAL;
226 goto bail;
227 }
228 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
229 (void)ehci_readl(ehci, &ehci->regs->intr_enable);
230
231 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
232
233 au1xxx_stop_ehc();
234
235bail:
236 spin_unlock_irqrestore(&ehci->lock, flags);
237
238
239
240
241 return rc;
242}
243
244static int ehci_hcd_au1xxx_drv_resume(struct device *dev)
245{
246 struct usb_hcd *hcd = dev_get_drvdata(dev);
247 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
248
249 au1xxx_start_ehc();
250
251
252
253 if (time_before(jiffies, ehci->next_statechange))
254 msleep(100);
255
256
257 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
258
259
260
261
262 if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF) {
263 int mask = INTR_MASK;
264
265 if (!hcd->self.root_hub->do_remote_wakeup)
266 mask &= ~STS_PCD;
267 ehci_writel(ehci, mask, &ehci->regs->intr_enable);
268 ehci_readl(ehci, &ehci->regs->intr_enable);
269 return 0;
270 }
271
272 ehci_dbg(ehci, "lost power, restarting\n");
273 usb_root_hub_lost_power(hcd->self.root_hub);
274
275
276
277
278 (void) ehci_halt(ehci);
279 (void) ehci_reset(ehci);
280
281
282 spin_lock_irq(&ehci->lock);
283 if (ehci->reclaim)
284 end_unlink_async(ehci);
285 ehci_work(ehci);
286 spin_unlock_irq(&ehci->lock);
287
288 ehci_writel(ehci, ehci->command, &ehci->regs->command);
289 ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
290 ehci_readl(ehci, &ehci->regs->command);
291
292
293 ehci_port_power(ehci, 1);
294
295 hcd->state = HC_STATE_SUSPENDED;
296
297 return 0;
298}
299
300static struct dev_pm_ops au1xxx_ehci_pmops = {
301 .suspend = ehci_hcd_au1xxx_drv_suspend,
302 .resume = ehci_hcd_au1xxx_drv_resume,
303};
304
305#define AU1XXX_EHCI_PMOPS &au1xxx_ehci_pmops
306
307#else
308#define AU1XXX_EHCI_PMOPS NULL
309#endif
310
311static struct platform_driver ehci_hcd_au1xxx_driver = {
312 .probe = ehci_hcd_au1xxx_drv_probe,
313 .remove = ehci_hcd_au1xxx_drv_remove,
314 .shutdown = usb_hcd_platform_shutdown,
315 .driver = {
316 .name = "au1xxx-ehci",
317 .owner = THIS_MODULE,
318 .pm = AU1XXX_EHCI_PMOPS,
319 }
320};
321
322MODULE_ALIAS("platform:au1xxx-ehci");
323