rcar2.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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/platform_data/gpio-rcar.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. struct usb_phy *phy;
  22. phy = usb_get_phy_dev(&pdev->dev, 0);
  23. if (IS_ERR(phy))
  24. return PTR_ERR(phy);
  25. priv->phy = phy;
  26. return 0;
  27. }
  28. static int usbhs_rcar2_hardware_exit(struct platform_device *pdev)
  29. {
  30. struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
  31. if (!priv->phy)
  32. return 0;
  33. usb_put_phy(priv->phy);
  34. priv->phy = NULL;
  35. return 0;
  36. }
  37. static int usbhs_rcar2_power_ctrl(struct platform_device *pdev,
  38. void __iomem *base, int enable)
  39. {
  40. struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
  41. if (!priv->phy)
  42. return -ENODEV;
  43. if (enable) {
  44. int retval = usb_phy_init(priv->phy);
  45. if (!retval)
  46. retval = usb_phy_set_suspend(priv->phy, 0);
  47. return retval;
  48. }
  49. usb_phy_set_suspend(priv->phy, 1);
  50. usb_phy_shutdown(priv->phy);
  51. return 0;
  52. }
  53. static int usbhs_rcar2_get_id(struct platform_device *pdev)
  54. {
  55. return USBHS_GADGET;
  56. }
  57. const struct renesas_usbhs_platform_callback usbhs_rcar2_ops = {
  58. .hardware_init = usbhs_rcar2_hardware_init,
  59. .hardware_exit = usbhs_rcar2_hardware_exit,
  60. .power_ctrl = usbhs_rcar2_power_ctrl,
  61. .get_id = usbhs_rcar2_get_id,
  62. };