rcar2.c 1.5 KB

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