1 /* 2 * Renesas USB driver R-Car Gen. 2 initialization and power control 3 * 4 * Copyright (C) 2014 Ulrich Hecht 5 * 6 * This program is distributed in the hope that it will be useful, 7 * but WITHOUT ANY WARRANTY; without even the implied warranty of 8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 9 * GNU General Public License for more details. 10 * 11 */ 12 13 #include <linux/gpio.h> 14 #include <linux/of_gpio.h> 15 #include <linux/platform_data/gpio-rcar.h> 16 #include <linux/usb/phy.h> 17 #include "common.h" 18 #include "rcar2.h" 19 20 static int usbhs_rcar2_hardware_init(struct platform_device *pdev) 21 { 22 struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev); 23 struct usb_phy *phy; 24 25 phy = usb_get_phy_dev(&pdev->dev, 0); 26 if (IS_ERR(phy)) 27 return PTR_ERR(phy); 28 29 priv->phy = phy; 30 return 0; 31 } 32 33 static int usbhs_rcar2_hardware_exit(struct platform_device *pdev) 34 { 35 struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev); 36 37 if (!priv->phy) 38 return 0; 39 40 usb_put_phy(priv->phy); 41 priv->phy = NULL; 42 43 return 0; 44 } 45 46 static int usbhs_rcar2_power_ctrl(struct platform_device *pdev, 47 void __iomem *base, int enable) 48 { 49 struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev); 50 51 if (!priv->phy) 52 return -ENODEV; 53 54 if (enable) { 55 int retval = usb_phy_init(priv->phy); 56 57 if (!retval) 58 retval = usb_phy_set_suspend(priv->phy, 0); 59 return retval; 60 } 61 62 usb_phy_set_suspend(priv->phy, 1); 63 usb_phy_shutdown(priv->phy); 64 return 0; 65 } 66 67 static int usbhs_rcar2_get_id(struct platform_device *pdev) 68 { 69 return USBHS_GADGET; 70 } 71 72 const struct renesas_usbhs_platform_callback usbhs_rcar2_ops = { 73 .hardware_init = usbhs_rcar2_hardware_init, 74 .hardware_exit = usbhs_rcar2_hardware_exit, 75 .power_ctrl = usbhs_rcar2_power_ctrl, 76 .get_id = usbhs_rcar2_get_id, 77 }; 78