0016-usb-host-fotg2-add-Gemini-specific-handling.patch 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. From b331ae758123ba20ba41199e007ac33fc0f242e3 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 16/18] 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. diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
  19. index 1a4ea98cac2a..308d514c9a2a 100644
  20. --- a/drivers/usb/host/Kconfig
  21. +++ b/drivers/usb/host/Kconfig
  22. @@ -372,6 +372,7 @@ config USB_ISP1362_HCD
  23. config USB_FOTG210_HCD
  24. tristate "FOTG210 HCD support"
  25. depends on USB && HAS_DMA && HAS_IOMEM
  26. + select MFD_SYSCON
  27. ---help---
  28. Faraday FOTG210 is an OTG controller which can be configured as
  29. an USB2.0 host. It is designed to meet USB2.0 EHCI specification
  30. diff --git a/drivers/usb/host/fotg210-hcd.c b/drivers/usb/host/fotg210-hcd.c
  31. index 6e4b40cd5916..5abb07f4136f 100644
  32. --- a/drivers/usb/host/fotg210-hcd.c
  33. +++ b/drivers/usb/host/fotg210-hcd.c
  34. @@ -33,6 +33,10 @@
  35. #include <linux/platform_device.h>
  36. #include <linux/io.h>
  37. #include <linux/clk.h>
  38. +#include <linux/bitops.h>
  39. +/* For Cortina Gemini */
  40. +#include <linux/mfd/syscon.h>
  41. +#include <linux/regmap.h>
  42. #include <asm/byteorder.h>
  43. #include <asm/irq.h>
  44. @@ -5554,6 +5558,72 @@ static void fotg210_init(struct fotg210_hcd *fotg210)
  45. iowrite32(value, &fotg210->regs->otgcsr);
  46. }
  47. +/*
  48. + * Gemini-specific initialization function, only executed on the
  49. + * Gemini SoC using the global misc control register.
  50. + */
  51. +#define GEMINI_GLOBAL_MISC_CTRL 0x30
  52. +#define GEMINI_MISC_USB0_WAKEUP BIT(14)
  53. +#define GEMINI_MISC_USB1_WAKEUP BIT(15)
  54. +#define GEMINI_MISC_USB0_VBUS_ON BIT(22)
  55. +#define GEMINI_MISC_USB1_VBUS_ON BIT(23)
  56. +#define GEMINI_MISC_USB0_MINI_B BIT(29)
  57. +#define GEMINI_MISC_USB1_MINI_B BIT(30)
  58. +
  59. +static int fotg210_gemini_init(struct device *dev, struct usb_hcd *hcd)
  60. +{
  61. + struct device_node *np = dev->of_node;
  62. + struct regmap *map;
  63. + bool mini_b;
  64. + bool wakeup;
  65. + u32 mask, val;
  66. + int ret;
  67. +
  68. + map = syscon_regmap_lookup_by_phandle(np, "syscon");
  69. + if (IS_ERR(map)) {
  70. + dev_err(dev, "no syscon\n");
  71. + return PTR_ERR(map);
  72. + }
  73. + mini_b = of_property_read_bool(np, "cortina,gemini-mini-b");
  74. + wakeup = of_property_read_bool(np, "wakeup-source");
  75. +
  76. + /*
  77. + * Figure out if this is USB0 or USB1 by simply checking the
  78. + * physical base address.
  79. + */
  80. + mask = 0;
  81. + if (hcd->rsrc_start == 0x69000000) {
  82. + val = GEMINI_MISC_USB1_VBUS_ON;
  83. + if (mini_b)
  84. + val |= GEMINI_MISC_USB1_MINI_B;
  85. + else
  86. + mask |= GEMINI_MISC_USB1_MINI_B;
  87. + if (wakeup)
  88. + val |= GEMINI_MISC_USB1_WAKEUP;
  89. + else
  90. + mask |= GEMINI_MISC_USB1_WAKEUP;
  91. + } else {
  92. + val = GEMINI_MISC_USB0_VBUS_ON;
  93. + if (mini_b)
  94. + val |= GEMINI_MISC_USB0_MINI_B;
  95. + else
  96. + mask |= GEMINI_MISC_USB0_MINI_B;
  97. + if (wakeup)
  98. + val |= GEMINI_MISC_USB0_WAKEUP;
  99. + else
  100. + mask |= GEMINI_MISC_USB0_WAKEUP;
  101. + }
  102. +
  103. + ret = regmap_update_bits(map, GEMINI_GLOBAL_MISC_CTRL, mask, val);
  104. + if (ret) {
  105. + dev_err(dev, "failed to initialize Gemini PHY\n");
  106. + return ret;
  107. + }
  108. +
  109. + dev_info(dev, "initialized Gemini PHY\n");
  110. + return 0;
  111. +}
  112. +
  113. /**
  114. * fotg210_hcd_probe - initialize faraday FOTG210 HCDs
  115. *
  116. @@ -5631,6 +5701,12 @@ static int fotg210_hcd_probe(struct platform_device *pdev)
  117. fotg210_init(fotg210);
  118. + if (of_device_is_compatible(dev->of_node, "cortina,gemini-usb")) {
  119. + retval = fotg210_gemini_init(dev, hcd);
  120. + if (retval)
  121. + goto failed_dis_clk;
  122. + }
  123. +
  124. retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
  125. if (retval) {
  126. dev_err(dev, "failed to add hcd with err %d\n", retval);
  127. --
  128. 2.19.2