2
0

0001-usb-host-fotg2-add-Gemini-specific-handling.patch 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. From ff887de2f7af17d6264eb946f6b336e6e1521222 Mon Sep 17 00:00:00 2001
  2. From: Linus Walleij <[email protected]>
  3. Date: Fri, 21 Apr 2017 22:19:00 +0200
  4. Subject: [PATCH 1/2] usb: host: fotg2: add Gemini-specific handling
  5. The Cortina Systems Gemini has bolted on a PHY inside the
  6. silicon that can be handled by six bits in a MISC register in
  7. the system controller.
  8. If we are running on Gemini, look up a syscon regmap through
  9. a phandle and enable VBUS and optionally the Mini-B connector.
  10. If the device is flagged as "wakeup-source" using the standard
  11. DT bindings, we also enable this in the global controller for
  12. respective port.
  13. Signed-off-by: Linus Walleij <[email protected]>
  14. ---
  15. drivers/usb/host/Kconfig | 1 +
  16. drivers/usb/host/fotg210-hcd.c | 76 ++++++++++++++++++++++++++++++++++
  17. 2 files changed, 77 insertions(+)
  18. --- a/drivers/usb/host/Kconfig
  19. +++ b/drivers/usb/host/Kconfig
  20. @@ -381,6 +381,7 @@ config USB_ISP1362_HCD
  21. config USB_FOTG210_HCD
  22. tristate "FOTG210 HCD support"
  23. depends on USB && HAS_DMA && HAS_IOMEM
  24. + select MFD_SYSCON
  25. help
  26. Faraday FOTG210 is an OTG controller which can be configured as
  27. an USB2.0 host. It is designed to meet USB2.0 EHCI specification
  28. --- a/drivers/usb/host/fotg210-hcd.c
  29. +++ b/drivers/usb/host/fotg210-hcd.c
  30. @@ -34,6 +34,10 @@
  31. #include <linux/io.h>
  32. #include <linux/iopoll.h>
  33. #include <linux/clk.h>
  34. +#include <linux/bitops.h>
  35. +/* For Cortina Gemini */
  36. +#include <linux/mfd/syscon.h>
  37. +#include <linux/regmap.h>
  38. #include <asm/byteorder.h>
  39. #include <asm/irq.h>
  40. @@ -5557,6 +5561,72 @@ static void fotg210_init(struct fotg210_
  41. }
  42. /*
  43. + * Gemini-specific initialization function, only executed on the
  44. + * Gemini SoC using the global misc control register.
  45. + */
  46. +#define GEMINI_GLOBAL_MISC_CTRL 0x30
  47. +#define GEMINI_MISC_USB0_WAKEUP BIT(14)
  48. +#define GEMINI_MISC_USB1_WAKEUP BIT(15)
  49. +#define GEMINI_MISC_USB0_VBUS_ON BIT(22)
  50. +#define GEMINI_MISC_USB1_VBUS_ON BIT(23)
  51. +#define GEMINI_MISC_USB0_MINI_B BIT(29)
  52. +#define GEMINI_MISC_USB1_MINI_B BIT(30)
  53. +
  54. +static int fotg210_gemini_init(struct device *dev, struct usb_hcd *hcd)
  55. +{
  56. + struct device_node *np = dev->of_node;
  57. + struct regmap *map;
  58. + bool mini_b;
  59. + bool wakeup;
  60. + u32 mask, val;
  61. + int ret;
  62. +
  63. + map = syscon_regmap_lookup_by_phandle(np, "syscon");
  64. + if (IS_ERR(map)) {
  65. + dev_err(dev, "no syscon\n");
  66. + return PTR_ERR(map);
  67. + }
  68. + mini_b = of_property_read_bool(np, "cortina,gemini-mini-b");
  69. + wakeup = of_property_read_bool(np, "wakeup-source");
  70. +
  71. + /*
  72. + * Figure out if this is USB0 or USB1 by simply checking the
  73. + * physical base address.
  74. + */
  75. + mask = 0;
  76. + if (hcd->rsrc_start == 0x69000000) {
  77. + val = GEMINI_MISC_USB1_VBUS_ON;
  78. + if (mini_b)
  79. + val |= GEMINI_MISC_USB1_MINI_B;
  80. + else
  81. + mask |= GEMINI_MISC_USB1_MINI_B;
  82. + if (wakeup)
  83. + val |= GEMINI_MISC_USB1_WAKEUP;
  84. + else
  85. + mask |= GEMINI_MISC_USB1_WAKEUP;
  86. + } else {
  87. + val = GEMINI_MISC_USB0_VBUS_ON;
  88. + if (mini_b)
  89. + val |= GEMINI_MISC_USB0_MINI_B;
  90. + else
  91. + mask |= GEMINI_MISC_USB0_MINI_B;
  92. + if (wakeup)
  93. + val |= GEMINI_MISC_USB0_WAKEUP;
  94. + else
  95. + mask |= GEMINI_MISC_USB0_WAKEUP;
  96. + }
  97. +
  98. + ret = regmap_update_bits(map, GEMINI_GLOBAL_MISC_CTRL, mask, val);
  99. + if (ret) {
  100. + dev_err(dev, "failed to initialize Gemini PHY\n");
  101. + return ret;
  102. + }
  103. +
  104. + dev_info(dev, "initialized Gemini PHY\n");
  105. + return 0;
  106. +}
  107. +
  108. +/**
  109. * fotg210_hcd_probe - initialize faraday FOTG210 HCDs
  110. *
  111. * Allocates basic resources for this USB host controller, and
  112. @@ -5633,6 +5703,12 @@ static int fotg210_hcd_probe(struct plat
  113. fotg210_init(fotg210);
  114. + if (of_device_is_compatible(dev->of_node, "cortina,gemini-usb")) {
  115. + retval = fotg210_gemini_init(dev, hcd);
  116. + if (retval)
  117. + goto failed_dis_clk;
  118. + }
  119. +
  120. retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
  121. if (retval) {
  122. dev_err(dev, "failed to add hcd with err %d\n", retval);