USB: cp2101.c fix sparse signedness mismatch warnings
[safe/jmp/linux-2.6] / drivers / usb / host / ohci-pxa27x.c
index c165d1e..127b157 100644 (file)
 #include <linux/device.h>
 #include <linux/signal.h>
 #include <linux/platform_device.h>
+#include <linux/clk.h>
 
 #include <asm/mach-types.h>
 #include <asm/hardware.h>
 #include <asm/arch/pxa-regs.h>
+#include <asm/arch/pxa2xx-regs.h> /* FIXME: for PSSR */
 #include <asm/arch/ohci.h>
 
 #define PXA_UHC_MAX_PORTNUM    3
 
 #define UHCRHPS(x)              __REG2( 0x4C000050, (x)<<2 )
 
+static struct clk *usb_clk;
+
 /*
   PMM_NPS_MODE -- PMM Non-power switching mode
       Ports are powered continuously.
@@ -47,7 +51,7 @@ static int pxa27x_ohci_select_pmm( int mode )
        switch ( mode ) {
        case PMM_NPS_MODE:
                UHCRHDA |= RH_A_NPS;
-               break; 
+               break;
        case PMM_GLOBAL_MODE:
                UHCRHDA &= ~(RH_A_NPS & RH_A_PSM);
                break;
@@ -60,7 +64,7 @@ static int pxa27x_ohci_select_pmm( int mode )
                break;
        default:
                printk( KERN_ERR
-                       "Invalid mode %d, set to non-power switch mode.\n", 
+                       "Invalid mode %d, set to non-power switch mode.\n",
                        mode );
 
                UHCRHDA |= RH_A_NPS;
@@ -80,7 +84,7 @@ static int pxa27x_start_hc(struct device *dev)
 
        inf = dev->platform_data;
 
-       pxa_set_cken(CKEN10_USBHOST, 1);
+       clk_enable(usb_clk);
 
        UHCHR |= UHCHR_FHR;
        udelay(11);
@@ -101,7 +105,7 @@ static int pxa27x_start_hc(struct device *dev)
        UHCHIE = (UHCHIE_UPRIE | UHCHIE_RWIE);
 
        /* Clear any OTG Pin Hold */
-       if (PSSR & PSSR_OTGPH)
+       if (cpu_is_pxa27x() && (PSSR & PSSR_OTGPH))
                PSSR |= PSSR_OTGPH;
 
        return 0;
@@ -123,7 +127,7 @@ static void pxa27x_stop_hc(struct device *dev)
        UHCCOMS |= 1;
        udelay(10);
 
-       pxa_set_cken(CKEN10_USBHOST, 0);
+       clk_disable(usb_clk);
 }
 
 
@@ -158,6 +162,10 @@ int usb_hcd_pxa27x_probe (const struct hc_driver *driver, struct platform_device
                return -ENOMEM;
        }
 
+       usb_clk = clk_get(&pdev->dev, "USBCLK");
+       if (IS_ERR(usb_clk))
+               return PTR_ERR(usb_clk);
+
        hcd = usb_create_hcd (driver, &pdev->dev, "pxa27x");
        if (!hcd)
                return -ENOMEM;
@@ -185,9 +193,12 @@ int usb_hcd_pxa27x_probe (const struct hc_driver *driver, struct platform_device
        /* Select Power Management Mode */
        pxa27x_ohci_select_pmm(inf->port_mode);
 
+       if (inf->power_budget)
+               hcd->power_budget = inf->power_budget;
+
        ohci_hcd_init(hcd_to_ohci(hcd));
 
-       retval = usb_add_hcd(hcd, pdev->resource[1].start, SA_INTERRUPT);
+       retval = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_DISABLED);
        if (retval == 0)
                return retval;
 
@@ -198,6 +209,7 @@ int usb_hcd_pxa27x_probe (const struct hc_driver *driver, struct platform_device
        release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  err1:
        usb_put_hcd(hcd);
+       clk_put(usb_clk);
        return retval;
 }
 
@@ -222,6 +234,7 @@ void usb_hcd_pxa27x_remove (struct usb_hcd *hcd, struct platform_device *pdev)
        iounmap(hcd->regs);
        release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
        usb_put_hcd(hcd);
+       clk_put(usb_clk);
 }
 
 /*-------------------------------------------------------------------------*/
@@ -267,6 +280,7 @@ static const struct hc_driver ohci_pxa27x_hc_driver = {
         */
        .start =                ohci_pxa27x_start,
        .stop =                 ohci_stop,
+       .shutdown =             ohci_shutdown,
 
        /*
         * managing i/o requests and associated device resources
@@ -285,6 +299,7 @@ static const struct hc_driver ohci_pxa27x_hc_driver = {
         */
        .hub_status_data =      ohci_hub_status_data,
        .hub_control =          ohci_hub_control,
+       .hub_irq_enable =       ohci_rhsc_enable,
 #ifdef  CONFIG_PM
        .bus_suspend =          ohci_bus_suspend,
        .bus_resume =           ohci_bus_resume,
@@ -309,49 +324,58 @@ static int ohci_hcd_pxa27x_drv_remove(struct platform_device *pdev)
        struct usb_hcd *hcd = platform_get_drvdata(pdev);
 
        usb_hcd_pxa27x_remove(hcd, pdev);
+       platform_set_drvdata(pdev, NULL);
        return 0;
 }
 
-static int ohci_hcd_pxa27x_drv_suspend(struct platform_device *dev, pm_message_t state)
+#ifdef CONFIG_PM
+static int ohci_hcd_pxa27x_drv_suspend(struct platform_device *pdev, pm_message_t state)
 {
-//     struct usb_hcd *hcd = platform_get_drvdata(dev);
-       printk("%s: not implemented yet\n", __FUNCTION__);
+       struct usb_hcd *hcd = platform_get_drvdata(pdev);
+       struct ohci_hcd *ohci = hcd_to_ohci(hcd);
+
+       if (time_before(jiffies, ohci->next_statechange))
+               msleep(5);
+       ohci->next_statechange = jiffies;
+
+       pxa27x_stop_hc(&pdev->dev);
+       hcd->state = HC_STATE_SUSPENDED;
 
        return 0;
 }
 
-static int ohci_hcd_pxa27x_drv_resume(struct platform_device *dev)
+static int ohci_hcd_pxa27x_drv_resume(struct platform_device *pdev)
 {
-//     struct usb_hcd *hcd = platform_get_drvdata(dev);
-       printk("%s: not implemented yet\n", __FUNCTION__);
+       struct usb_hcd *hcd = platform_get_drvdata(pdev);
+       struct ohci_hcd *ohci = hcd_to_ohci(hcd);
+       int status;
+
+       if (time_before(jiffies, ohci->next_statechange))
+               msleep(5);
+       ohci->next_statechange = jiffies;
 
+       if ((status = pxa27x_start_hc(&pdev->dev)) < 0)
+               return status;
+
+       ohci_finish_controller_resume(hcd);
        return 0;
 }
+#endif
 
+/* work with hotplug and coldplug */
+MODULE_ALIAS("platform:pxa27x-ohci");
 
 static struct platform_driver ohci_hcd_pxa27x_driver = {
        .probe          = ohci_hcd_pxa27x_drv_probe,
        .remove         = ohci_hcd_pxa27x_drv_remove,
-       .suspend        = ohci_hcd_pxa27x_drv_suspend, 
+       .shutdown       = usb_hcd_platform_shutdown,
+#ifdef CONFIG_PM
+       .suspend        = ohci_hcd_pxa27x_drv_suspend,
        .resume         = ohci_hcd_pxa27x_drv_resume,
+#endif
        .driver         = {
                .name   = "pxa27x-ohci",
+               .owner  = THIS_MODULE,
        },
 };
 
-static int __init ohci_hcd_pxa27x_init (void)
-{
-       pr_debug (DRIVER_INFO " (pxa27x)");
-       pr_debug ("block sizes: ed %d td %d\n",
-               sizeof (struct ed), sizeof (struct td));
-
-       return platform_driver_register(&ohci_hcd_pxa27x_driver);
-}
-
-static void __exit ohci_hcd_pxa27x_cleanup (void)
-{
-       platform_driver_unregister(&ohci_hcd_pxa27x_driver);
-}
-
-module_init (ohci_hcd_pxa27x_init);
-module_exit (ohci_hcd_pxa27x_cleanup);