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>
 
   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."
 
  27 /* interface and function clocks; sometimes also an AHB clock */
 
  28 static struct clk *iclk, *fclk, *hclk;
 
  31 extern int usb_disabled(void);
 
  33 /*-------------------------------------------------------------------------*/
 
  35 static void at91_start_clock(void)
 
  37         if (cpu_is_at91sam9261())
 
  44 static void at91_stop_clock(void)
 
  48         if (cpu_is_at91sam9261())
 
  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.
 
  66          * The USB host controller must remain in reset.
 
  68         writel(0, ®s->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, ®s->control);
 
  84          * Stop the USB clocks.
 
  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 */
 
  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)
 
 110         struct usb_hcd *hcd = NULL;
 
 112         if (pdev->num_resources != 2) {
 
 113                 pr_debug("hcd probe: invalid num_resources");
 
 117         if ((pdev->resource[0].flags != IORESOURCE_MEM)
 
 118                         || (pdev->resource[1].flags != IORESOURCE_IRQ)) {
 
 119                 pr_debug("hcd probe: invalid resource type\n");
 
 123         hcd = usb_create_hcd(driver, &pdev->dev, "at91");
 
 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");
 
 135         hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
 
 137                 pr_debug("ioremap failed\n");
 
 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");
 
 148         ohci_hcd_init(hcd_to_ohci(hcd));
 
 150         retval = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_DISABLED);
 
 157         if (cpu_is_at91sam9261())
 
 165         release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
 
 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)
 
 191         release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
 
 193         if (cpu_is_at91sam9261())
 
 197         fclk = iclk = hclk = NULL;
 
 199         dev_set_drvdata(&pdev->dev, NULL);
 
 203 /*-------------------------------------------------------------------------*/
 
 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);
 
 212         if ((ret = ohci_init(ohci)) < 0)
 
 215         ohci->num_ports = board->ports;
 
 217         if ((ret = ohci_run(ohci)) < 0) {
 
 218                 err("can't start %s", hcd->self.bus_name);
 
 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
 
 236         .flags =                HCD_USB11 | HCD_MEMORY,
 
 239          * basic lifecycle operations
 
 241         .start =                ohci_at91_start,
 
 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,
 
 255         .get_frame_number =     ohci_get_frame,
 
 260         .hub_status_data =      ohci_hub_status_data,
 
 261         .hub_control =          ohci_hub_control,
 
 262         .hub_irq_enable =       ohci_rhsc_enable,
 
 264         .bus_suspend =          ohci_bus_suspend,
 
 265         .bus_resume =           ohci_bus_resume,
 
 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);
 
 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);
 
 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);
 
 323 #define ohci_hcd_at91_drv_suspend NULL
 
 324 #define ohci_hcd_at91_drv_resume  NULL
 
 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,
 
 337                 .owner  = THIS_MODULE,