rcar2.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. #include <linux/gpio.h>
  8. #include <linux/of_gpio.h>
  9. #include <linux/phy/phy.h>
  10. #include "common.h"
  11. #include "rcar2.h"
  12. static int usbhs_rcar2_hardware_init(struct platform_device *pdev)
  13. {
  14. struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
  15. if (IS_ENABLED(CONFIG_GENERIC_PHY)) {
  16. struct phy *phy = phy_get(&pdev->dev, "usb");
  17. if (IS_ERR(phy))
  18. return PTR_ERR(phy);
  19. priv->phy = phy;
  20. return 0;
  21. }
  22. return -ENXIO;
  23. }
  24. static int usbhs_rcar2_hardware_exit(struct platform_device *pdev)
  25. {
  26. struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
  27. if (priv->phy) {
  28. phy_put(priv->phy);
  29. priv->phy = NULL;
  30. }
  31. return 0;
  32. }
  33. static int usbhs_rcar2_power_ctrl(struct platform_device *pdev,
  34. void __iomem *base, int enable)
  35. {
  36. struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
  37. int retval = -ENODEV;
  38. if (priv->phy) {
  39. if (enable) {
  40. retval = phy_init(priv->phy);
  41. if (!retval)
  42. retval = phy_power_on(priv->phy);
  43. } else {
  44. phy_power_off(priv->phy);
  45. phy_exit(priv->phy);
  46. retval = 0;
  47. }
  48. }
  49. return retval;
  50. }
  51. static int usbhs_rcar2_get_id(struct platform_device *pdev)
  52. {
  53. return USBHS_GADGET;
  54. }
  55. const struct renesas_usbhs_platform_callback usbhs_rcar2_ops = {
  56. .hardware_init = usbhs_rcar2_hardware_init,
  57. .hardware_exit = usbhs_rcar2_hardware_exit,
  58. .power_ctrl = usbhs_rcar2_power_ctrl,
  59. .get_id = usbhs_rcar2_get_id,
  60. };