Merge tag 'v3.14.26' into backport/v3.14.24-ltsi-rc1+v3.14.26/snapshot-merge.wip
[platform/adaptation/renesas_rcar/renesas_kernel.git] / drivers / usb / host / xhci-plat.c
index 5cb5de1..bf09ffb 100644 (file)
@@ -21,6 +21,9 @@
 
 #include "xhci.h"
 #include "xhci-mvebu.h"
+#include "xhci-rcar.h"
+
+static struct hc_driver __read_mostly xhci_plat_hc_driver;
 
 static void xhci_plat_quirks(struct device *dev, struct xhci_hcd *xhci)
 {
@@ -35,66 +38,29 @@ static void xhci_plat_quirks(struct device *dev, struct xhci_hcd *xhci)
 /* called during probe() after chip reset completes */
 static int xhci_plat_setup(struct usb_hcd *hcd)
 {
+       struct device_node *of_node = hcd->self.controller->of_node;
+       int ret;
+
+       if (of_device_is_compatible(of_node, "renesas,xhci-r8a7790") ||
+           of_device_is_compatible(of_node, "renesas,xhci-r8a7791")) {
+               ret = xhci_rcar_init_quirk(hcd);
+               if (ret)
+                       return ret;
+       }
+
        return xhci_gen_setup(hcd, xhci_plat_quirks);
 }
 
 static int xhci_plat_start(struct usb_hcd *hcd)
 {
-       return xhci_run(hcd);
-}
-
-static const struct hc_driver xhci_plat_xhci_driver = {
-       .description =          "xhci-hcd",
-       .product_desc =         "xHCI Host Controller",
-       .hcd_priv_size =        sizeof(struct xhci_hcd *),
-
-       /*
-        * generic hardware linkage
-        */
-       .irq =                  xhci_irq,
-       .flags =                HCD_MEMORY | HCD_USB3 | HCD_SHARED,
-
-       /*
-        * basic lifecycle operations
-        */
-       .reset =                xhci_plat_setup,
-       .start =                xhci_plat_start,
-       .stop =                 xhci_stop,
-       .shutdown =             xhci_shutdown,
+       struct device_node *of_node = hcd->self.controller->of_node;
 
-       /*
-        * managing i/o requests and associated device resources
-        */
-       .urb_enqueue =          xhci_urb_enqueue,
-       .urb_dequeue =          xhci_urb_dequeue,
-       .alloc_dev =            xhci_alloc_dev,
-       .free_dev =             xhci_free_dev,
-       .alloc_streams =        xhci_alloc_streams,
-       .free_streams =         xhci_free_streams,
-       .add_endpoint =         xhci_add_endpoint,
-       .drop_endpoint =        xhci_drop_endpoint,
-       .endpoint_reset =       xhci_endpoint_reset,
-       .check_bandwidth =      xhci_check_bandwidth,
-       .reset_bandwidth =      xhci_reset_bandwidth,
-       .address_device =       xhci_address_device,
-       .enable_device =        xhci_enable_device,
-       .update_hub_device =    xhci_update_hub_device,
-       .reset_device =         xhci_discover_or_reset_device,
-
-       /*
-        * scheduling support
-        */
-       .get_frame_number =     xhci_get_frame,
+       if (of_device_is_compatible(of_node, "renesas,xhci-r8a7790") ||
+           of_device_is_compatible(of_node, "renesas,xhci-r8a7791"))
+               xhci_rcar_start(hcd);
 
-       /* Root hub support */
-       .hub_control =          xhci_hub_control,
-       .hub_status_data =      xhci_hub_status_data,
-       .bus_suspend =          xhci_bus_suspend,
-       .bus_resume =           xhci_bus_resume,
-
-       .enable_usb3_lpm_timeout =      xhci_enable_usb3_lpm_timeout,
-       .disable_usb3_lpm_timeout =     xhci_disable_usb3_lpm_timeout,
-};
+       return xhci_run(hcd);
+}
 
 static int xhci_plat_probe(struct platform_device *pdev)
 {
@@ -111,7 +77,7 @@ static int xhci_plat_probe(struct platform_device *pdev)
        if (usb_disabled())
                return -ENODEV;
 
-       driver = &xhci_plat_xhci_driver;
+       driver = &xhci_plat_hc_driver;
 
        irq = platform_get_irq(pdev, 0);
        if (irq < 0)
@@ -235,7 +201,15 @@ static int xhci_plat_suspend(struct device *dev)
        struct usb_hcd  *hcd = dev_get_drvdata(dev);
        struct xhci_hcd *xhci = hcd_to_xhci(hcd);
 
-       return xhci_suspend(xhci);
+       /*
+        * xhci_suspend() needs `do_wakeup` to know whether host is allowed
+        * to do wakeup during suspend. Since xhci_plat_suspend is currently
+        * only designed for system suspend, device_may_wakeup() is enough
+        * to dertermine whether host is allowed to do wakeup. Need to
+        * reconsider this when xhci_plat_suspend enlarges its scope, e.g.,
+        * also applies to runtime suspend.
+        */
+       return xhci_suspend(xhci, device_may_wakeup(dev));
 }
 
 static int xhci_plat_resume(struct device *dev)
@@ -260,6 +234,8 @@ static const struct of_device_id usb_xhci_of_match[] = {
        { .compatible = "xhci-platform" },
        { .compatible = "marvell,armada-375-xhci"},
        { .compatible = "marvell,armada-380-xhci"},
+       { .compatible = "renesas,xhci-r8a7790"},
+       { .compatible = "renesas,xhci-r8a7791"},
        { },
 };
 MODULE_DEVICE_TABLE(of, usb_xhci_of_match);
@@ -278,6 +254,8 @@ MODULE_ALIAS("platform:xhci-hcd");
 
 int xhci_register_plat(void)
 {
+       xhci_init_driver(&xhci_plat_hc_driver, xhci_plat_setup);
+       xhci_plat_hc_driver.start = xhci_plat_start;
        return platform_driver_register(&usb_xhci_driver);
 }