rcar3.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Renesas USB driver R-Car Gen. 3 initialization and power control
  3. *
  4. * Copyright (C) 2016 Renesas Electronics Corporation
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. */
  11. #include <linux/delay.h>
  12. #include <linux/io.h>
  13. #include "common.h"
  14. #include "rcar3.h"
  15. #define LPSTS 0x102
  16. #define UGCTRL2 0x184 /* 32-bit register */
  17. /* Low Power Status register (LPSTS) */
  18. #define LPSTS_SUSPM 0x4000
  19. /*
  20. * USB General control register 2 (UGCTRL2)
  21. * Remarks: bit[31:11] and bit[9:6] should be 0
  22. */
  23. #define UGCTRL2_RESERVED_3 0x00000001 /* bit[3:0] should be B'0001 */
  24. #define UGCTRL2_USB0SEL_OTG 0x00000030
  25. #define UGCTRL2_VBUSSEL 0x00000400
  26. static void usbhs_write32(struct usbhs_priv *priv, u32 reg, u32 data)
  27. {
  28. iowrite32(data, priv->base + reg);
  29. }
  30. static int usbhs_rcar3_power_ctrl(struct platform_device *pdev,
  31. void __iomem *base, int enable)
  32. {
  33. struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
  34. usbhs_write32(priv, UGCTRL2, UGCTRL2_RESERVED_3 | UGCTRL2_USB0SEL_OTG |
  35. UGCTRL2_VBUSSEL);
  36. if (enable) {
  37. usbhs_bset(priv, LPSTS, LPSTS_SUSPM, LPSTS_SUSPM);
  38. /* The controller on R-Car Gen3 needs to wait up to 45 usec */
  39. udelay(45);
  40. } else {
  41. usbhs_bset(priv, LPSTS, LPSTS_SUSPM, 0);
  42. }
  43. return 0;
  44. }
  45. static int usbhs_rcar3_get_id(struct platform_device *pdev)
  46. {
  47. return USBHS_GADGET;
  48. }
  49. const struct renesas_usbhs_platform_callback usbhs_rcar3_ops = {
  50. .power_ctrl = usbhs_rcar3_power_ctrl,
  51. .get_id = usbhs_rcar3_get_id,
  52. };