rza2.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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/phy/phy.h>
  11. #include "common.h"
  12. #include "rza.h"
  13. static int usbhs_rza2_hardware_init(struct platform_device *pdev)
  14. {
  15. struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
  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. static int usbhs_rza2_hardware_exit(struct platform_device *pdev)
  23. {
  24. struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
  25. phy_put(&pdev->dev, priv->phy);
  26. priv->phy = NULL;
  27. return 0;
  28. }
  29. static int usbhs_rza2_power_ctrl(struct platform_device *pdev,
  30. void __iomem *base, int enable)
  31. {
  32. struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
  33. int retval = 0;
  34. if (!priv->phy)
  35. return -ENODEV;
  36. if (enable) {
  37. retval = phy_init(priv->phy);
  38. usbhs_bset(priv, SUSPMODE, SUSPM, SUSPM);
  39. udelay(100); /* Wait for PLL to become stable */
  40. if (!retval)
  41. retval = phy_power_on(priv->phy);
  42. } else {
  43. usbhs_bset(priv, SUSPMODE, SUSPM, 0);
  44. phy_power_off(priv->phy);
  45. phy_exit(priv->phy);
  46. }
  47. return retval;
  48. }
  49. const struct renesas_usbhs_platform_info usbhs_rza2_plat_info = {
  50. .platform_callback = {
  51. .hardware_init = usbhs_rza2_hardware_init,
  52. .hardware_exit = usbhs_rza2_hardware_exit,
  53. .power_ctrl = usbhs_rza2_power_ctrl,
  54. .get_id = usbhs_get_id_as_gadget,
  55. },
  56. .driver_param = {
  57. .has_cnen = 1,
  58. .cfifo_byte_addr = 1,
  59. .has_new_pipe_configs = 1,
  60. },
  61. };
  62. const struct renesas_usbhs_platform_info usbhs_rzg2l_plat_info = {
  63. .platform_callback = {
  64. .hardware_init = usbhs_rza2_hardware_init,
  65. .hardware_exit = usbhs_rza2_hardware_exit,
  66. .power_ctrl = usbhs_rza2_power_ctrl,
  67. .get_id = usbhs_get_id_as_gadget,
  68. },
  69. .driver_param = {
  70. .has_cnen = 1,
  71. .cfifo_byte_addr = 1,
  72. },
  73. };