Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-1.0+ |
| 2 | /* |
| 3 | * Renesas USB driver R-Car Gen. 2 initialization and power control |
| 4 | * |
| 5 | * Copyright (C) 2014 Ulrich Hecht |
| 6 | */ |
| 7 | |
| 8 | #include <linux/gpio.h> |
| 9 | #include <linux/of_gpio.h> |
| 10 | #include <linux/phy/phy.h> |
| 11 | #include "common.h" |
| 12 | #include "rcar2.h" |
| 13 | |
| 14 | static int usbhs_rcar2_hardware_init(struct platform_device *pdev) |
| 15 | { |
| 16 | struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev); |
| 17 | |
| 18 | if (IS_ENABLED(CONFIG_GENERIC_PHY)) { |
| 19 | struct phy *phy = phy_get(&pdev->dev, "usb"); |
| 20 | |
| 21 | if (IS_ERR(phy)) |
| 22 | return PTR_ERR(phy); |
| 23 | |
| 24 | priv->phy = phy; |
| 25 | return 0; |
| 26 | } |
| 27 | |
| 28 | return -ENXIO; |
| 29 | } |
| 30 | |
| 31 | static int usbhs_rcar2_hardware_exit(struct platform_device *pdev) |
| 32 | { |
| 33 | struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev); |
| 34 | |
| 35 | if (priv->phy) { |
| 36 | phy_put(priv->phy); |
| 37 | priv->phy = NULL; |
| 38 | } |
| 39 | |
| 40 | return 0; |
| 41 | } |
| 42 | |
| 43 | static int usbhs_rcar2_power_ctrl(struct platform_device *pdev, |
| 44 | void __iomem *base, int enable) |
| 45 | { |
| 46 | struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev); |
| 47 | int retval = -ENODEV; |
| 48 | |
| 49 | if (priv->phy) { |
| 50 | if (enable) { |
| 51 | retval = phy_init(priv->phy); |
| 52 | |
| 53 | if (!retval) |
| 54 | retval = phy_power_on(priv->phy); |
| 55 | } else { |
| 56 | phy_power_off(priv->phy); |
| 57 | phy_exit(priv->phy); |
| 58 | retval = 0; |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | return retval; |
| 63 | } |
| 64 | |
| 65 | static int usbhs_rcar2_get_id(struct platform_device *pdev) |
| 66 | { |
| 67 | return USBHS_GADGET; |
| 68 | } |
| 69 | |
| 70 | const struct renesas_usbhs_platform_callback usbhs_rcar2_ops = { |
| 71 | .hardware_init = usbhs_rcar2_hardware_init, |
| 72 | .hardware_exit = usbhs_rcar2_hardware_exit, |
| 73 | .power_ctrl = usbhs_rcar2_power_ctrl, |
| 74 | .get_id = usbhs_rcar2_get_id, |
| 75 | }; |