ARM: shmobile: r8a7778: add usb phy power control function
authorKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Mon, 5 Aug 2013 00:43:01 +0000 (17:43 -0700)
committerSimon Horman <horms+renesas@verge.net.au>
Mon, 30 Sep 2013 07:11:23 +0000 (16:11 +0900)
USB phy initialisation function is needed from not only
USB Host but also USB Function too.
This patch adds usb phy common control function.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Simon Horman <horms+renesas@verge.net.au>
arch/arm/mach-shmobile/include/mach/r8a7778.h
arch/arm/mach-shmobile/setup-r8a7778.c

index adfcf51..ea1dca6 100644 (file)
@@ -35,4 +35,6 @@ extern void r8a7778_clock_init(void);
 extern void r8a7778_init_irq_extpin(int irlm);
 extern void r8a7778_pinmux_init(void);
 
+extern int r8a7778_usb_phy_power(bool enable);
+
 #endif /* __ASM_R8A7778_H__ */
index 6a2657e..e484d14 100644 (file)
@@ -95,29 +95,46 @@ static struct sh_timer_config sh_tmu1_platform_data __initdata = {
                &sh_tmu##idx##_platform_data,           \
                sizeof(sh_tmu##idx##_platform_data))
 
-/* USB */
-static struct usb_phy *phy;
+int r8a7778_usb_phy_power(bool enable)
+{
+       static struct usb_phy *phy = NULL;
+       int ret = 0;
+
+       if (!phy)
+               phy = usb_get_phy(USB_PHY_TYPE_USB2);
+
+       if (IS_ERR(phy)) {
+               pr_err("kernel doesn't have usb phy driver\n");
+               return PTR_ERR(phy);
+       }
+
+       if (enable)
+               ret = usb_phy_init(phy);
+       else
+               usb_phy_shutdown(phy);
 
+       return ret;
+}
+
+/* USB */
 static int usb_power_on(struct platform_device *pdev)
 {
-       if (IS_ERR(phy))
-               return PTR_ERR(phy);
+       int ret = r8a7778_usb_phy_power(true);
+
+       if (ret)
+               return ret;
 
        pm_runtime_enable(&pdev->dev);
        pm_runtime_get_sync(&pdev->dev);
 
-       usb_phy_init(phy);
-
        return 0;
 }
 
 static void usb_power_off(struct platform_device *pdev)
 {
-       if (IS_ERR(phy))
+       if (r8a7778_usb_phy_power(false))
                return;
 
-       usb_phy_shutdown(phy);
-
        pm_runtime_put_sync(&pdev->dev);
        pm_runtime_disable(&pdev->dev);
 }
@@ -353,8 +370,6 @@ void __init r8a7778_add_standard_devices(void)
 
 void __init r8a7778_init_late(void)
 {
-       phy = usb_get_phy(USB_PHY_TYPE_USB2);
-
        platform_device_register_full(&ehci_info);
        platform_device_register_full(&ohci_info);
 }