rcar2.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Renesas USB driver R-Car Gen. 2 initialization and power control
  3. *
  4. * Copyright (C) 2014 Ulrich Hecht
  5. *
  6. * This program is distributed in the hope that it will be useful,
  7. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. * GNU General Public License for more details.
  10. *
  11. */
  12. #include <linux/gpio.h>
  13. #include <linux/of_gpio.h>
  14. #include <linux/phy/phy.h>
  15. #include <linux/usb/phy.h>
  16. #include "common.h"
  17. #include "rcar2.h"
  18. static int usbhs_rcar2_hardware_init(struct platform_device *pdev)
  19. {
  20. struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
  21. if (IS_ENABLED(CONFIG_GENERIC_PHY)) {
  22. struct phy *phy = phy_get(&pdev->dev, "usb");
  23. if (IS_ERR(phy))
  24. return PTR_ERR(phy);
  25. priv->phy = phy;
  26. return 0;
  27. }
  28. if (IS_ENABLED(CONFIG_USB_PHY)) {
  29. struct usb_phy *usb_phy = usb_get_phy_dev(&pdev->dev, 0);
  30. if (IS_ERR(usb_phy))
  31. return PTR_ERR(usb_phy);
  32. priv->usb_phy = usb_phy;
  33. return 0;
  34. }
  35. return -ENXIO;
  36. }
  37. static int usbhs_rcar2_hardware_exit(struct platform_device *pdev)
  38. {
  39. struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
  40. if (priv->phy) {
  41. phy_put(priv->phy);
  42. priv->phy = NULL;
  43. }
  44. if (priv->usb_phy) {
  45. usb_put_phy(priv->usb_phy);
  46. priv->usb_phy = NULL;
  47. }
  48. return 0;
  49. }
  50. static int usbhs_rcar2_power_ctrl(struct platform_device *pdev,
  51. void __iomem *base, int enable)
  52. {
  53. struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
  54. int retval = -ENODEV;
  55. if (priv->phy) {
  56. if (enable) {
  57. retval = phy_init(priv->phy);
  58. if (!retval)
  59. retval = phy_power_on(priv->phy);
  60. } else {
  61. phy_power_off(priv->phy);
  62. phy_exit(priv->phy);
  63. retval = 0;
  64. }
  65. }
  66. if (priv->usb_phy) {
  67. if (enable) {
  68. retval = usb_phy_init(priv->usb_phy);
  69. if (!retval)
  70. retval = usb_phy_set_suspend(priv->usb_phy, 0);
  71. } else {
  72. usb_phy_set_suspend(priv->usb_phy, 1);
  73. usb_phy_shutdown(priv->usb_phy);
  74. retval = 0;
  75. }
  76. }
  77. return retval;
  78. }
  79. static int usbhs_rcar2_get_id(struct platform_device *pdev)
  80. {
  81. return USBHS_GADGET;
  82. }
  83. const struct renesas_usbhs_platform_callback usbhs_rcar2_ops = {
  84. .hardware_init = usbhs_rcar2_hardware_init,
  85. .hardware_exit = usbhs_rcar2_hardware_exit,
  86. .power_ctrl = usbhs_rcar2_power_ctrl,
  87. .get_id = usbhs_rcar2_get_id,
  88. };