rza2.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Renesas USB driver RZ/A2 initialization and power control
  4. *
  5. * Copyright (C) 2019 Chris Brandt
  6. * Copyright (C) 2019 Renesas Electronics Corporation
  7. */
  8. #include <linux/delay.h>
  9. #include <linux/io.h>
  10. #include <linux/of_device.h>
  11. #include <linux/phy/phy.h>
  12. #include "common.h"
  13. #include "rza.h"
  14. static int usbhs_rza2_hardware_init(struct platform_device *pdev)
  15. {
  16. struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
  17. struct phy *phy = phy_get(&pdev->dev, "usb");
  18. if (IS_ERR(phy))
  19. return PTR_ERR(phy);
  20. priv->phy = phy;
  21. return 0;
  22. }
  23. static int usbhs_rza2_hardware_exit(struct platform_device *pdev)
  24. {
  25. struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
  26. phy_put(&pdev->dev, priv->phy);
  27. priv->phy = NULL;
  28. return 0;
  29. }
  30. static int usbhs_rza2_power_ctrl(struct platform_device *pdev,
  31. void __iomem *base, int enable)
  32. {
  33. struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
  34. int retval = 0;
  35. if (!priv->phy)
  36. return -ENODEV;
  37. if (enable) {
  38. retval = phy_init(priv->phy);
  39. usbhs_bset(priv, SUSPMODE, SUSPM, SUSPM);
  40. udelay(100); /* Wait for PLL to become stable */
  41. if (!retval)
  42. retval = phy_power_on(priv->phy);
  43. } else {
  44. usbhs_bset(priv, SUSPMODE, SUSPM, 0);
  45. phy_power_off(priv->phy);
  46. phy_exit(priv->phy);
  47. }
  48. return retval;
  49. }
  50. const struct renesas_usbhs_platform_info usbhs_rza2_plat_info = {
  51. .platform_callback = {
  52. .hardware_init = usbhs_rza2_hardware_init,
  53. .hardware_exit = usbhs_rza2_hardware_exit,
  54. .power_ctrl = usbhs_rza2_power_ctrl,
  55. .get_id = usbhs_get_id_as_gadget,
  56. },
  57. .driver_param = {
  58. .has_cnen = 1,
  59. .cfifo_byte_addr = 1,
  60. .has_new_pipe_configs = 1,
  61. },
  62. };