rcar2.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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/platform_data/gpio-rcar.h>
  16. #include <linux/usb/phy.h>
  17. #include "common.h"
  18. #include "rcar2.h"
  19. static int usbhs_rcar2_hardware_init(struct platform_device *pdev)
  20. {
  21. struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
  22. if (IS_ENABLED(CONFIG_GENERIC_PHY)) {
  23. struct phy *phy = phy_get(&pdev->dev, "usb");
  24. if (IS_ERR(phy))
  25. return PTR_ERR(phy);
  26. priv->phy = phy;
  27. return 0;
  28. }
  29. if (IS_ENABLED(CONFIG_USB_PHY)) {
  30. struct usb_phy *usb_phy = usb_get_phy_dev(&pdev->dev, 0);
  31. if (IS_ERR(usb_phy))
  32. return PTR_ERR(usb_phy);
  33. priv->usb_phy = usb_phy;
  34. return 0;
  35. }
  36. return -ENXIO;
  37. }
  38. static int usbhs_rcar2_hardware_exit(struct platform_device *pdev)
  39. {
  40. struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
  41. if (priv->phy) {
  42. phy_put(priv->phy);
  43. priv->phy = NULL;
  44. }
  45. if (priv->usb_phy) {
  46. usb_put_phy(priv->usb_phy);
  47. priv->usb_phy = NULL;
  48. }
  49. return 0;
  50. }
  51. static int usbhs_rcar2_power_ctrl(struct platform_device *pdev,
  52. void __iomem *base, int enable)
  53. {
  54. struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
  55. int retval = -ENODEV;
  56. if (priv->phy) {
  57. if (enable) {
  58. retval = phy_init(priv->phy);
  59. if (!retval)
  60. retval = phy_power_on(priv->phy);
  61. } else {
  62. phy_power_off(priv->phy);
  63. phy_exit(priv->phy);
  64. retval = 0;
  65. }
  66. }
  67. if (priv->usb_phy) {
  68. if (enable) {
  69. retval = usb_phy_init(priv->usb_phy);
  70. if (!retval)
  71. retval = usb_phy_set_suspend(priv->usb_phy, 0);
  72. } else {
  73. usb_phy_set_suspend(priv->usb_phy, 1);
  74. usb_phy_shutdown(priv->usb_phy);
  75. retval = 0;
  76. }
  77. }
  78. return retval;
  79. }
  80. static int usbhs_rcar2_get_id(struct platform_device *pdev)
  81. {
  82. return USBHS_GADGET;
  83. }
  84. const struct renesas_usbhs_platform_callback usbhs_rcar2_ops = {
  85. .hardware_init = usbhs_rcar2_hardware_init,
  86. .hardware_exit = usbhs_rcar2_hardware_exit,
  87. .power_ctrl = usbhs_rcar2_power_ctrl,
  88. .get_id = usbhs_rcar2_get_id,
  89. };