Ulrich Hecht | 8ecef00 | 2014-07-10 09:53:59 +0200 | [diff] [blame] | 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); |
Ulrich Hecht | 8ecef00 | 2014-07-10 09:53:59 +0200 | [diff] [blame] | 23 | |
Yoshihiro Shimoda | 5f6aea3 | 2014-10-07 12:43:05 +0900 | [diff] [blame^] | 24 | if (IS_ENABLED(CONFIG_USB_PHY)) { |
| 25 | struct usb_phy *usb_phy = usb_get_phy_dev(&pdev->dev, 0); |
Ulrich Hecht | 8ecef00 | 2014-07-10 09:53:59 +0200 | [diff] [blame] | 26 | |
Yoshihiro Shimoda | 5f6aea3 | 2014-10-07 12:43:05 +0900 | [diff] [blame^] | 27 | if (IS_ERR(usb_phy)) |
| 28 | return PTR_ERR(usb_phy); |
| 29 | |
| 30 | priv->usb_phy = usb_phy; |
| 31 | return 0; |
| 32 | } |
| 33 | |
| 34 | return -ENXIO; |
Ulrich Hecht | 8ecef00 | 2014-07-10 09:53:59 +0200 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | static int usbhs_rcar2_hardware_exit(struct platform_device *pdev) |
| 38 | { |
| 39 | struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev); |
| 40 | |
Yoshihiro Shimoda | 5f6aea3 | 2014-10-07 12:43:05 +0900 | [diff] [blame^] | 41 | if (priv->usb_phy) { |
| 42 | usb_put_phy(priv->usb_phy); |
| 43 | priv->usb_phy = NULL; |
| 44 | } |
Ulrich Hecht | 8ecef00 | 2014-07-10 09:53:59 +0200 | [diff] [blame] | 45 | |
| 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | static int usbhs_rcar2_power_ctrl(struct platform_device *pdev, |
| 50 | void __iomem *base, int enable) |
| 51 | { |
| 52 | struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev); |
Yoshihiro Shimoda | 5f6aea3 | 2014-10-07 12:43:05 +0900 | [diff] [blame^] | 53 | int retval = -ENODEV; |
Ulrich Hecht | 8ecef00 | 2014-07-10 09:53:59 +0200 | [diff] [blame] | 54 | |
Yoshihiro Shimoda | 5f6aea3 | 2014-10-07 12:43:05 +0900 | [diff] [blame^] | 55 | if (priv->usb_phy) { |
| 56 | if (enable) { |
| 57 | retval = usb_phy_init(priv->usb_phy); |
Ulrich Hecht | 8ecef00 | 2014-07-10 09:53:59 +0200 | [diff] [blame] | 58 | |
Yoshihiro Shimoda | 5f6aea3 | 2014-10-07 12:43:05 +0900 | [diff] [blame^] | 59 | if (!retval) |
| 60 | retval = usb_phy_set_suspend(priv->usb_phy, 0); |
| 61 | } else { |
| 62 | usb_phy_set_suspend(priv->usb_phy, 1); |
| 63 | usb_phy_shutdown(priv->usb_phy); |
| 64 | retval = 0; |
| 65 | } |
Ulrich Hecht | 8ecef00 | 2014-07-10 09:53:59 +0200 | [diff] [blame] | 66 | } |
| 67 | |
Yoshihiro Shimoda | 5f6aea3 | 2014-10-07 12:43:05 +0900 | [diff] [blame^] | 68 | return retval; |
Ulrich Hecht | 8ecef00 | 2014-07-10 09:53:59 +0200 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | static int usbhs_rcar2_get_id(struct platform_device *pdev) |
| 72 | { |
| 73 | return USBHS_GADGET; |
| 74 | } |
| 75 | |
| 76 | const struct renesas_usbhs_platform_callback usbhs_rcar2_ops = { |
| 77 | .hardware_init = usbhs_rcar2_hardware_init, |
| 78 | .hardware_exit = usbhs_rcar2_hardware_exit, |
| 79 | .power_ctrl = usbhs_rcar2_power_ctrl, |
| 80 | .get_id = usbhs_rcar2_get_id, |
| 81 | }; |