Remove nid_lock from alloc_fresh_huge_page
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / usb / host / ohci-at91.c
blobd849c809acbdca97394fa7b8dcd8225733a91f5a
1 /*
2 * OHCI HCD (Host Controller Driver) for USB.
4 * Copyright (C) 2004 SAN People (Pty) Ltd.
5 * Copyright (C) 2005 Thibaut VARENE <varenet@parisc-linux.org>
7 * AT91 Bus Glue
9 * Based on fragments of 2.4 driver by Rick Bronson.
10 * Based on ohci-omap.c
12 * This file is licenced under the GPL.
15 #include <linux/clk.h>
16 #include <linux/platform_device.h>
18 #include <asm/mach-types.h>
19 #include <asm/hardware.h>
20 #include <asm/arch/board.h>
21 #include <asm/arch/cpu.h>
23 #ifndef CONFIG_ARCH_AT91
24 #error "CONFIG_ARCH_AT91 must be defined."
25 #endif
27 /* interface and function clocks; sometimes also an AHB clock */
28 static struct clk *iclk, *fclk, *hclk;
29 static int clocked;
31 extern int usb_disabled(void);
33 /*-------------------------------------------------------------------------*/
35 static void at91_start_clock(void)
37 if (cpu_is_at91sam9261())
38 clk_enable(hclk);
39 clk_enable(iclk);
40 clk_enable(fclk);
41 clocked = 1;
44 static void at91_stop_clock(void)
46 clk_disable(fclk);
47 clk_disable(iclk);
48 if (cpu_is_at91sam9261())
49 clk_disable(hclk);
50 clocked = 0;
53 static void at91_start_hc(struct platform_device *pdev)
55 struct usb_hcd *hcd = platform_get_drvdata(pdev);
56 struct ohci_regs __iomem *regs = hcd->regs;
58 dev_dbg(&pdev->dev, "start\n");
61 * Start the USB clocks.
63 at91_start_clock();
66 * The USB host controller must remain in reset.
68 writel(0, &regs->control);
71 static void at91_stop_hc(struct platform_device *pdev)
73 struct usb_hcd *hcd = platform_get_drvdata(pdev);
74 struct ohci_regs __iomem *regs = hcd->regs;
76 dev_dbg(&pdev->dev, "stop\n");
79 * Put the USB host controller into reset.
81 writel(0, &regs->control);
84 * Stop the USB clocks.
86 at91_stop_clock();
90 /*-------------------------------------------------------------------------*/
92 static int usb_hcd_at91_remove (struct usb_hcd *, struct platform_device *);
94 /* configure so an HC device and id are always provided */
95 /* always called with process context; sleeping is OK */
98 /**
99 * usb_hcd_at91_probe - initialize AT91-based HCDs
100 * Context: !in_interrupt()
102 * Allocates basic resources for this USB host controller, and
103 * then invokes the start() method for the HCD associated with it
104 * through the hotplug entry's driver_data.
106 static int usb_hcd_at91_probe(const struct hc_driver *driver,
107 struct platform_device *pdev)
109 int retval;
110 struct usb_hcd *hcd = NULL;
112 if (pdev->num_resources != 2) {
113 pr_debug("hcd probe: invalid num_resources");
114 return -ENODEV;
117 if ((pdev->resource[0].flags != IORESOURCE_MEM)
118 || (pdev->resource[1].flags != IORESOURCE_IRQ)) {
119 pr_debug("hcd probe: invalid resource type\n");
120 return -ENODEV;
123 hcd = usb_create_hcd(driver, &pdev->dev, "at91");
124 if (!hcd)
125 return -ENOMEM;
126 hcd->rsrc_start = pdev->resource[0].start;
127 hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
129 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
130 pr_debug("request_mem_region failed\n");
131 retval = -EBUSY;
132 goto err1;
135 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
136 if (!hcd->regs) {
137 pr_debug("ioremap failed\n");
138 retval = -EIO;
139 goto err2;
142 iclk = clk_get(&pdev->dev, "ohci_clk");
143 fclk = clk_get(&pdev->dev, "uhpck");
144 if (cpu_is_at91sam9261())
145 hclk = clk_get(&pdev->dev, "hck0");
147 at91_start_hc(pdev);
148 ohci_hcd_init(hcd_to_ohci(hcd));
150 retval = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_DISABLED);
151 if (retval == 0)
152 return retval;
154 /* Error handling */
155 at91_stop_hc(pdev);
157 if (cpu_is_at91sam9261())
158 clk_put(hclk);
159 clk_put(fclk);
160 clk_put(iclk);
162 iounmap(hcd->regs);
164 err2:
165 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
167 err1:
168 usb_put_hcd(hcd);
169 return retval;
173 /* may be called with controller, bus, and devices active */
176 * usb_hcd_at91_remove - shutdown processing for AT91-based HCDs
177 * @dev: USB Host Controller being removed
178 * Context: !in_interrupt()
180 * Reverses the effect of usb_hcd_at91_probe(), first invoking
181 * the HCD's stop() method. It is always called from a thread
182 * context, "rmmod" or something similar.
185 static int usb_hcd_at91_remove(struct usb_hcd *hcd,
186 struct platform_device *pdev)
188 usb_remove_hcd(hcd);
189 at91_stop_hc(pdev);
190 iounmap(hcd->regs);
191 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
193 if (cpu_is_at91sam9261())
194 clk_put(hclk);
195 clk_put(fclk);
196 clk_put(iclk);
197 fclk = iclk = hclk = NULL;
199 dev_set_drvdata(&pdev->dev, NULL);
200 return 0;
203 /*-------------------------------------------------------------------------*/
205 static int __devinit
206 ohci_at91_start (struct usb_hcd *hcd)
208 struct at91_usbh_data *board = hcd->self.controller->platform_data;
209 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
210 int ret;
212 if ((ret = ohci_init(ohci)) < 0)
213 return ret;
215 ohci->num_ports = board->ports;
217 if ((ret = ohci_run(ohci)) < 0) {
218 err("can't start %s", hcd->self.bus_name);
219 ohci_stop(hcd);
220 return ret;
222 return 0;
225 /*-------------------------------------------------------------------------*/
227 static const struct hc_driver ohci_at91_hc_driver = {
228 .description = hcd_name,
229 .product_desc = "AT91 OHCI",
230 .hcd_priv_size = sizeof(struct ohci_hcd),
233 * generic hardware linkage
235 .irq = ohci_irq,
236 .flags = HCD_USB11 | HCD_MEMORY,
239 * basic lifecycle operations
241 .start = ohci_at91_start,
242 .stop = ohci_stop,
243 .shutdown = ohci_shutdown,
246 * managing i/o requests and associated device resources
248 .urb_enqueue = ohci_urb_enqueue,
249 .urb_dequeue = ohci_urb_dequeue,
250 .endpoint_disable = ohci_endpoint_disable,
253 * scheduling support
255 .get_frame_number = ohci_get_frame,
258 * root hub support
260 .hub_status_data = ohci_hub_status_data,
261 .hub_control = ohci_hub_control,
262 .hub_irq_enable = ohci_rhsc_enable,
263 #ifdef CONFIG_PM
264 .bus_suspend = ohci_bus_suspend,
265 .bus_resume = ohci_bus_resume,
266 #endif
267 .start_port_reset = ohci_start_port_reset,
270 /*-------------------------------------------------------------------------*/
272 static int ohci_hcd_at91_drv_probe(struct platform_device *pdev)
274 device_init_wakeup(&pdev->dev, 1);
275 return usb_hcd_at91_probe(&ohci_at91_hc_driver, pdev);
278 static int ohci_hcd_at91_drv_remove(struct platform_device *pdev)
280 device_init_wakeup(&pdev->dev, 0);
281 return usb_hcd_at91_remove(platform_get_drvdata(pdev), pdev);
284 #ifdef CONFIG_PM
286 static int
287 ohci_hcd_at91_drv_suspend(struct platform_device *pdev, pm_message_t mesg)
289 struct usb_hcd *hcd = platform_get_drvdata(pdev);
290 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
292 if (device_may_wakeup(&pdev->dev))
293 enable_irq_wake(hcd->irq);
296 * The integrated transceivers seem unable to notice disconnect,
297 * reconnect, or wakeup without the 48 MHz clock active. so for
298 * correctness, always discard connection state (using reset).
300 * REVISIT: some boards will be able to turn VBUS off...
302 if (at91_suspend_entering_slow_clock()) {
303 ohci_usb_reset (ohci);
304 at91_stop_clock();
307 return 0;
310 static int ohci_hcd_at91_drv_resume(struct platform_device *pdev)
312 struct usb_hcd *hcd = platform_get_drvdata(pdev);
314 if (device_may_wakeup(&pdev->dev))
315 disable_irq_wake(hcd->irq);
317 if (!clocked)
318 at91_start_clock();
320 return 0;
322 #else
323 #define ohci_hcd_at91_drv_suspend NULL
324 #define ohci_hcd_at91_drv_resume NULL
325 #endif
327 MODULE_ALIAS("at91_ohci");
329 static struct platform_driver ohci_hcd_at91_driver = {
330 .probe = ohci_hcd_at91_drv_probe,
331 .remove = ohci_hcd_at91_drv_remove,
332 .shutdown = usb_hcd_platform_shutdown,
333 .suspend = ohci_hcd_at91_drv_suspend,
334 .resume = ohci_hcd_at91_drv_resume,
335 .driver = {
336 .name = "at91_ohci",
337 .owner = THIS_MODULE,