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
101
102
103
104 .get_frame_number = ehci_get_frame,
105
106
107
108
109 .hub_status_data = ehci_hub_status_data,
110 .hub_control = ehci_hub_control,
111 .bus_suspend = ehci_bus_suspend,
112 .bus_resume = ehci_bus_resume,
113 .relinquish_port = ehci_relinquish_port,
114 .port_handed_over = ehci_port_handed_over,
115};
116
117static int ehci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
118{
119 struct usb_hcd *hcd;
120 struct ehci_hcd *ehci;
121 int ret;
122
123 if (usb_disabled())
124 return -ENODEV;
125
126#if defined(CONFIG_SOC_AU1200) && defined(CONFIG_DMA_COHERENT)
127
128 if (!(read_c0_prid() & 0xff)) {
129 printk(KERN_INFO "%s: this is chip revision AB!\n", pdev->name);
130 printk(KERN_INFO "%s: update your board or re-configure"
131 " the kernel\n", pdev->name);
132 return -ENODEV;
133 }
134#endif
135
136 if (pdev->resource[1].flags != IORESOURCE_IRQ) {
137 pr_debug("resource[1] is not IORESOURCE_IRQ");
138 return -ENOMEM;
139 }
140 hcd = usb_create_hcd(&ehci_au1xxx_hc_driver, &pdev->dev, "Au1xxx");
141 if (!hcd)
142 return -ENOMEM;
143
144 hcd->rsrc_start = pdev->resource[0].start;
145 hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
146
147 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
148 pr_debug("request_mem_region failed");
149 ret = -EBUSY;
150 goto err1;
151 }
152
153 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
154 if (!hcd->regs) {
155 pr_debug("ioremap failed");
156 ret = -ENOMEM;
157 goto err2;
158 }
159
160 au1xxx_start_ehc();
161
162 ehci = hcd_to_ehci(hcd);
163 ehci->caps = hcd->regs;
164 ehci->regs = hcd->regs + HC_LENGTH(readl(&ehci->caps->hc_capbase));
165
166 ehci->hcs_params = readl(&ehci->caps->hcs_params);
167
168 ret = usb_add_hcd(hcd, pdev->resource[1].start,
169 IRQF_DISABLED | IRQF_SHARED);
170 if (ret == 0) {
171 platform_set_drvdata(pdev, hcd);
172 return ret;
173 }
174
175 au1xxx_stop_ehc();
176 iounmap(hcd->regs);
177err2:
178 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
179err1:
180 usb_put_hcd(hcd);
181 return ret;
182}
183
184static int ehci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
185{
186 struct usb_hcd *hcd = platform_get_drvdata(pdev);
187
188 usb_remove_hcd(hcd);
189 iounmap(hcd->regs);
190 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
191 usb_put_hcd(hcd);
192 au1xxx_stop_ehc();
193 platform_set_drvdata(pdev, NULL);
194
195 return 0;
196}
197
198#ifdef CONFIG_PM
199static int ehci_hcd_au1xxx_drv_suspend(struct platform_device *pdev,
200 pm_message_t message)
201{
202 struct usb_hcd *hcd = platform_get_drvdata(pdev);
203 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
204 unsigned long flags;
205 int rc;
206
207 return 0;
208 rc = 0;
209
210 if (time_before(jiffies, ehci->next_statechange))
211 msleep(10);
212
213
214
215
216
217
218
219
220
221 spin_lock_irqsave(&ehci->lock, flags);
222 if (hcd->state != HC_STATE_SUSPENDED) {
223 rc = -EINVAL;
224 goto bail;
225 }
226 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
227 (void)ehci_readl(ehci, &ehci->regs->intr_enable);
228
229
230 if (message.event == PM_EVENT_PRETHAW) {
231 ehci_halt(ehci);
232 ehci_reset(ehci);
233 }
234
235 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
236
237 au1xxx_stop_ehc();
238
239bail:
240 spin_unlock_irqrestore(&ehci->lock, flags);
241
242
243
244
245 return rc;
246}
247
248
249static int ehci_hcd_au1xxx_drv_resume(struct platform_device *pdev)
250{
251 struct usb_hcd *hcd = platform_get_drvdata(pdev);
252 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
253
254 au1xxx_start_ehc();
255
256
257
258 if (time_before(jiffies, ehci->next_statechange))
259 msleep(100);
260
261
262 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
263
264
265
266
267 if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF) {
268 int mask = INTR_MASK;
269
270 if (!hcd->self.root_hub->do_remote_wakeup)
271 mask &= ~STS_PCD;
272 ehci_writel(ehci, mask, &ehci->regs->intr_enable);
273 ehci_readl(ehci, &ehci->regs->intr_enable);
274 return 0;
275 }
276
277 ehci_dbg(ehci, "lost power, restarting\n");
278 usb_root_hub_lost_power(hcd->self.root_hub);
279
280
281
282
283 (void) ehci_halt(ehci);
284 (void) ehci_reset(ehci);
285
286
287 spin_lock_irq(&ehci->lock);
288 if (ehci->reclaim)
289 end_unlink_async(ehci);
290 ehci_work(ehci);
291 spin_unlock_irq(&ehci->lock);
292
293 ehci_writel(ehci, ehci->command, &ehci->regs->command);
294 ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
295 ehci_readl(ehci, &ehci->regs->command);
296
297
298 ehci_port_power(ehci, 1);
299
300 hcd->state = HC_STATE_SUSPENDED;
301
302 return 0;
303}
304
305#else
306#define ehci_hcd_au1xxx_drv_suspend NULL
307#define ehci_hcd_au1xxx_drv_resume NULL
308#endif
309
310static struct platform_driver ehci_hcd_au1xxx_driver = {
311 .probe = ehci_hcd_au1xxx_drv_probe,
312 .remove = ehci_hcd_au1xxx_drv_remove,
313 .shutdown = usb_hcd_platform_shutdown,
314 .suspend = ehci_hcd_au1xxx_drv_suspend,
315 .resume = ehci_hcd_au1xxx_drv_resume,
316 .driver = {
317 .name = "au1xxx-ehci",
318 .owner = THIS_MODULE,
319 }
320};
321
322MODULE_ALIAS("platform:au1xxx-ehci");
323