virtio_blk: don't bounce highmem requests
[linux-2.6/mini2440.git] / drivers / usb / host / ehci-au1xxx.c
blob5c25b1a1d2c503fc5587968f7be1adaecbd7747e
1 /*
2 * EHCI HCD (Host Controller Driver) for USB.
4 * Bus Glue for AMD Alchemy Au1xxx
6 * Based on "ohci-au1xxx.c" by Matt Porter <mporter@kernel.crashing.org>
8 * Modified for AMD Alchemy Au1200 EHC
9 * by K.Boge <karsten.boge@amd.com>
11 * This file is licenced under the GPL.
14 #include <linux/platform_device.h>
15 #include <asm/mach-au1x00/au1000.h>
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)
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)
38 #define USBH_DISABLE (USB_MCFG_EBMEN | USB_MCFG_EMEMEN)
40 extern int usb_disabled(void);
42 static void au1xxx_start_ehc(void)
44 /* enable clock to EHCI block and HS PHY PLL*/
45 au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_CE, USB_HOST_CONFIG);
46 au_sync();
47 udelay(1000);
49 /* enable EHCI mmio */
50 au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_INIT, USB_HOST_CONFIG);
51 au_sync();
52 udelay(1000);
55 static void au1xxx_stop_ehc(void)
57 unsigned long c;
59 /* Disable mem */
60 au_writel(au_readl(USB_HOST_CONFIG) & ~USBH_DISABLE, USB_HOST_CONFIG);
61 au_sync();
62 udelay(1000);
64 /* Disable EHC clock. If the HS PHY is unused disable it too. */
65 c = au_readl(USB_HOST_CONFIG) & ~USB_MCFG_EHCCLKEN;
66 if (!(c & USB_MCFG_UCECLKEN)) /* UDC disabled? */
67 c &= ~USB_MCFG_PHYPLLEN; /* yes: disable HS PHY PLL */
68 au_writel(c, USB_HOST_CONFIG);
69 au_sync();
72 static 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),
78 * generic hardware linkage
80 .irq = ehci_irq,
81 .flags = HCD_MEMORY | HCD_USB2,
84 * basic lifecycle operations
86 * FIXME -- ehci_init() doesn't do enough here.
87 * See ehci-ppc-soc for a complete implementation.
89 .reset = ehci_init,
90 .start = ehci_run,
91 .stop = ehci_stop,
92 .shutdown = ehci_shutdown,
95 * managing i/o requests and associated device resources
97 .urb_enqueue = ehci_urb_enqueue,
98 .urb_dequeue = ehci_urb_dequeue,
99 .endpoint_disable = ehci_endpoint_disable,
102 * scheduling support
104 .get_frame_number = ehci_get_frame,
107 * root hub support
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,
116 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
119 static int ehci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
121 struct usb_hcd *hcd;
122 struct ehci_hcd *ehci;
123 int ret;
125 if (usb_disabled())
126 return -ENODEV;
128 #if defined(CONFIG_SOC_AU1200) && defined(CONFIG_DMA_COHERENT)
129 /* Au1200 AB USB does not support coherent memory */
130 if (!(read_c0_prid() & 0xff)) {
131 printk(KERN_INFO "%s: this is chip revision AB!\n", pdev->name);
132 printk(KERN_INFO "%s: update your board or re-configure"
133 " the kernel\n", pdev->name);
134 return -ENODEV;
136 #endif
138 if (pdev->resource[1].flags != IORESOURCE_IRQ) {
139 pr_debug("resource[1] is not IORESOURCE_IRQ");
140 return -ENOMEM;
142 hcd = usb_create_hcd(&ehci_au1xxx_hc_driver, &pdev->dev, "Au1xxx");
143 if (!hcd)
144 return -ENOMEM;
146 hcd->rsrc_start = pdev->resource[0].start;
147 hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
149 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
150 pr_debug("request_mem_region failed");
151 ret = -EBUSY;
152 goto err1;
155 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
156 if (!hcd->regs) {
157 pr_debug("ioremap failed");
158 ret = -ENOMEM;
159 goto err2;
162 au1xxx_start_ehc();
164 ehci = hcd_to_ehci(hcd);
165 ehci->caps = hcd->regs;
166 ehci->regs = hcd->regs + HC_LENGTH(readl(&ehci->caps->hc_capbase));
167 /* cache this readonly data; minimize chip reads */
168 ehci->hcs_params = readl(&ehci->caps->hcs_params);
170 ret = usb_add_hcd(hcd, pdev->resource[1].start,
171 IRQF_DISABLED | IRQF_SHARED);
172 if (ret == 0) {
173 platform_set_drvdata(pdev, hcd);
174 return ret;
177 au1xxx_stop_ehc();
178 iounmap(hcd->regs);
179 err2:
180 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
181 err1:
182 usb_put_hcd(hcd);
183 return ret;
186 static int ehci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
188 struct usb_hcd *hcd = platform_get_drvdata(pdev);
190 usb_remove_hcd(hcd);
191 iounmap(hcd->regs);
192 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
193 usb_put_hcd(hcd);
194 au1xxx_stop_ehc();
195 platform_set_drvdata(pdev, NULL);
197 return 0;
200 #ifdef CONFIG_PM
201 static int ehci_hcd_au1xxx_drv_suspend(struct platform_device *pdev,
202 pm_message_t message)
204 struct usb_hcd *hcd = platform_get_drvdata(pdev);
205 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
206 unsigned long flags;
207 int rc;
209 return 0;
210 rc = 0;
212 if (time_before(jiffies, ehci->next_statechange))
213 msleep(10);
215 /* Root hub was already suspended. Disable irq emission and
216 * mark HW unaccessible, bail out if RH has been resumed. Use
217 * the spinlock to properly synchronize with possible pending
218 * RH suspend or resume activity.
220 * This is still racy as hcd->state is manipulated outside of
221 * any locks =P But that will be a different fix.
223 spin_lock_irqsave(&ehci->lock, flags);
224 if (hcd->state != HC_STATE_SUSPENDED) {
225 rc = -EINVAL;
226 goto bail;
228 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
229 (void)ehci_readl(ehci, &ehci->regs->intr_enable);
231 /* make sure snapshot being resumed re-enumerates everything */
232 if (message.event == PM_EVENT_PRETHAW) {
233 ehci_halt(ehci);
234 ehci_reset(ehci);
237 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
239 au1xxx_stop_ehc();
241 bail:
242 spin_unlock_irqrestore(&ehci->lock, flags);
244 // could save FLADJ in case of Vaux power loss
245 // ... we'd only use it to handle clock skew
247 return rc;
251 static int ehci_hcd_au1xxx_drv_resume(struct platform_device *pdev)
253 struct usb_hcd *hcd = platform_get_drvdata(pdev);
254 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
256 au1xxx_start_ehc();
258 // maybe restore FLADJ
260 if (time_before(jiffies, ehci->next_statechange))
261 msleep(100);
263 /* Mark hardware accessible again as we are out of D3 state by now */
264 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
266 /* If CF is still set, we maintained PCI Vaux power.
267 * Just undo the effect of ehci_pci_suspend().
269 if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF) {
270 int mask = INTR_MASK;
272 if (!hcd->self.root_hub->do_remote_wakeup)
273 mask &= ~STS_PCD;
274 ehci_writel(ehci, mask, &ehci->regs->intr_enable);
275 ehci_readl(ehci, &ehci->regs->intr_enable);
276 return 0;
279 ehci_dbg(ehci, "lost power, restarting\n");
280 usb_root_hub_lost_power(hcd->self.root_hub);
282 /* Else reset, to cope with power loss or flush-to-storage
283 * style "resume" having let BIOS kick in during reboot.
285 (void) ehci_halt(ehci);
286 (void) ehci_reset(ehci);
288 /* emptying the schedule aborts any urbs */
289 spin_lock_irq(&ehci->lock);
290 if (ehci->reclaim)
291 end_unlink_async(ehci);
292 ehci_work(ehci);
293 spin_unlock_irq(&ehci->lock);
295 ehci_writel(ehci, ehci->command, &ehci->regs->command);
296 ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
297 ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
299 /* here we "know" root ports should always stay powered */
300 ehci_port_power(ehci, 1);
302 hcd->state = HC_STATE_SUSPENDED;
304 return 0;
307 #else
308 #define ehci_hcd_au1xxx_drv_suspend NULL
309 #define ehci_hcd_au1xxx_drv_resume NULL
310 #endif
312 static struct platform_driver ehci_hcd_au1xxx_driver = {
313 .probe = ehci_hcd_au1xxx_drv_probe,
314 .remove = ehci_hcd_au1xxx_drv_remove,
315 .shutdown = usb_hcd_platform_shutdown,
316 .suspend = ehci_hcd_au1xxx_drv_suspend,
317 .resume = ehci_hcd_au1xxx_drv_resume,
318 .driver = {
319 .name = "au1xxx-ehci",
320 .owner = THIS_MODULE,
324 MODULE_ALIAS("platform:au1xxx-ehci");