0065-MIPS-lantiq-improve-USB-initialization.patch 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. From 14909c4e4e836925668e74fc6e0e85ba0283cbf9 Mon Sep 17 00:00:00 2001
  2. From: Hauke Mehrtens <hauke@hauke-m.de>
  3. Date: Fri, 6 Jan 2017 17:40:12 +0100
  4. Subject: [PATCH 2/2] MIPS: lantiq: improve USB initialization
  5. This adds code to initialize the USB controller and PHY also on Danube,
  6. Amazon SE and AR10. This code is based on the Vendor driver from
  7. different UGW versions and compared to the hardware documentation.
  8. Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
  9. ---
  10. arch/mips/lantiq/xway/reset.c | 120 ++++++++++++++++++++++++++++++----------
  11. arch/mips/lantiq/xway/sysctrl.c | 20 +++++++
  12. 2 files changed, 110 insertions(+), 30 deletions(-)
  13. --- a/arch/mips/lantiq/xway/reset.c
  14. +++ b/arch/mips/lantiq/xway/reset.c
  15. @@ -72,6 +72,8 @@
  16. #define RCU_USBCFG_HDSEL_BIT BIT(11)
  17. #define RCU_USBCFG_HOST_END_BIT BIT(10)
  18. #define RCU_USBCFG_SLV_END_BIT BIT(9)
  19. +#define RCU_USBCFG_SLV_END_BIT_AR9 BIT(17)
  20. +
  21. /* USB reset bits */
  22. #define RCU_USBRESET 0x0010
  23. @@ -85,6 +87,8 @@
  24. #define RCU_CFG1A 0x0038
  25. #define RCU_CFG1B 0x003C
  26. +#define RCU_CFG1_TX_PEE BIT(0)
  27. +#define RCU_CFG1_DIS_THR_SHIFT 15 /* Disconnect Threshold */
  28. /* USB PMU devices */
  29. #define PMU_AHBM BIT(15)
  30. @@ -306,38 +310,91 @@ static void ltq_usb_init(void)
  31. /* Power for USB cores 1 & 2 */
  32. ltq_pmu_enable(PMU_AHBM);
  33. ltq_pmu_enable(PMU_USB0);
  34. - ltq_pmu_enable(PMU_USB1);
  35. - ltq_rcu_w32(ltq_rcu_r32(RCU_CFG1A) | BIT(0), RCU_CFG1A);
  36. - ltq_rcu_w32(ltq_rcu_r32(RCU_CFG1B) | BIT(0), RCU_CFG1B);
  37. + if (of_machine_is_compatible("lantiq,ar10") ||
  38. + of_machine_is_compatible("lantiq,grx390") ||
  39. + of_machine_is_compatible("lantiq,ar9") ||
  40. + of_machine_is_compatible("lantiq,vr9"))
  41. + ltq_pmu_enable(PMU_USB1);
  42. +
  43. + if (of_machine_is_compatible("lantiq,vr9") ||
  44. + of_machine_is_compatible("lantiq,ar10")) {
  45. + ltq_rcu_w32(ltq_rcu_r32(RCU_CFG1A) | RCU_CFG1_TX_PEE |
  46. + 7 << RCU_CFG1_DIS_THR_SHIFT, RCU_CFG1A);
  47. + ltq_rcu_w32(ltq_rcu_r32(RCU_CFG1B) | RCU_CFG1_TX_PEE |
  48. + 7 << RCU_CFG1_DIS_THR_SHIFT, RCU_CFG1B);
  49. + }
  50. /* Enable USB PHY power for cores 1 & 2 */
  51. ltq_pmu_enable(PMU_USB0_P);
  52. - ltq_pmu_enable(PMU_USB1_P);
  53. + if (of_machine_is_compatible("lantiq,ar10") ||
  54. + of_machine_is_compatible("lantiq,grx390") ||
  55. + of_machine_is_compatible("lantiq,ar9") ||
  56. + of_machine_is_compatible("lantiq,vr9"))
  57. + ltq_pmu_enable(PMU_USB1_P);
  58. +
  59. + if (of_machine_is_compatible("lantiq,ase") ||
  60. + of_machine_is_compatible("lantiq,danube")) {
  61. + /* Configure cores to host mode */
  62. + ltq_rcu_w32(ltq_rcu_r32(RCU_USB1CFG) & ~RCU_USBCFG_HDSEL_BIT,
  63. + RCU_USB1CFG);
  64. +
  65. + /* Select DMA endianness (Host-endian: big-endian) */
  66. + ltq_rcu_w32((ltq_rcu_r32(RCU_USB1CFG) & ~RCU_USBCFG_SLV_END_BIT)
  67. + | RCU_USBCFG_HOST_END_BIT, RCU_USB1CFG);
  68. + }
  69. +
  70. + if (of_machine_is_compatible("lantiq,ar9")) {
  71. + /* Configure cores to host mode */
  72. + ltq_rcu_w32(ltq_rcu_r32(RCU_USB1CFG) & ~RCU_USBCFG_HDSEL_BIT,
  73. + RCU_USB1CFG);
  74. + ltq_rcu_w32(ltq_rcu_r32(RCU_USB2CFG) & ~RCU_USBCFG_HDSEL_BIT,
  75. + RCU_USB2CFG);
  76. +
  77. + /* Select DMA endianness (Host-endian: big-endian) */
  78. + ltq_rcu_w32((ltq_rcu_r32(RCU_USB1CFG) & ~RCU_USBCFG_SLV_END_BIT_AR9)
  79. + | RCU_USBCFG_HOST_END_BIT, RCU_USB1CFG);
  80. + ltq_rcu_w32(ltq_rcu_r32((RCU_USB2CFG) & ~RCU_USBCFG_SLV_END_BIT_AR9)
  81. + | RCU_USBCFG_HOST_END_BIT, RCU_USB2CFG);
  82. + }
  83. +
  84. + if (of_machine_is_compatible("lantiq,vr9") ||
  85. + of_machine_is_compatible("lantiq,ar10")) {
  86. + /* Configure cores to host mode */
  87. + ltq_rcu_w32(ltq_rcu_r32(RCU_USB1CFG) & ~RCU_USBCFG_HDSEL_BIT,
  88. + RCU_USB1CFG);
  89. + ltq_rcu_w32(ltq_rcu_r32(RCU_USB2CFG) & ~RCU_USBCFG_HDSEL_BIT,
  90. + RCU_USB2CFG);
  91. +
  92. + /* Select DMA endianness (Host-endian: big-endian) */
  93. + ltq_rcu_w32((ltq_rcu_r32(RCU_USB1CFG) & ~RCU_USBCFG_SLV_END_BIT)
  94. + | RCU_USBCFG_HOST_END_BIT, RCU_USB1CFG);
  95. + ltq_rcu_w32(ltq_rcu_r32((RCU_USB2CFG) & ~RCU_USBCFG_SLV_END_BIT)
  96. + | RCU_USBCFG_HOST_END_BIT, RCU_USB2CFG);
  97. + }
  98. +
  99. + if (of_machine_is_compatible("lantiq,ar9")) {
  100. + /* Hard reset USB state machines */
  101. + ltq_rcu_w32(ltq_rcu_r32(RCU_USBRESET)
  102. + | USBRESET_BIT | BIT(28), RCU_USBRESET);
  103. + udelay(50 * 1000);
  104. + ltq_rcu_w32(ltq_rcu_r32(RCU_USBRESET)
  105. + & ~(USBRESET_BIT | BIT(28)), RCU_USBRESET);
  106. + } else {
  107. + /* Hard reset USB state machines */
  108. + ltq_rcu_w32(ltq_rcu_r32(RCU_USBRESET) | USBRESET_BIT, RCU_USBRESET);
  109. + udelay(50 * 1000);
  110. + ltq_rcu_w32(ltq_rcu_r32(RCU_USBRESET) & ~USBRESET_BIT, RCU_USBRESET);
  111. + }
  112. - /* Configure cores to host mode */
  113. - ltq_rcu_w32(ltq_rcu_r32(RCU_USB1CFG) & ~RCU_USBCFG_HDSEL_BIT,
  114. - RCU_USB1CFG);
  115. - ltq_rcu_w32(ltq_rcu_r32(RCU_USB2CFG) & ~RCU_USBCFG_HDSEL_BIT,
  116. - RCU_USB2CFG);
  117. -
  118. - /* Select DMA endianness (Host-endian: big-endian) */
  119. - ltq_rcu_w32((ltq_rcu_r32(RCU_USB1CFG) & ~RCU_USBCFG_SLV_END_BIT)
  120. - | RCU_USBCFG_HOST_END_BIT, RCU_USB1CFG);
  121. - ltq_rcu_w32(ltq_rcu_r32((RCU_USB2CFG) & ~RCU_USBCFG_SLV_END_BIT)
  122. - | RCU_USBCFG_HOST_END_BIT, RCU_USB2CFG);
  123. -
  124. - /* Hard reset USB state machines */
  125. - ltq_rcu_w32(ltq_rcu_r32(RCU_USBRESET) | USBRESET_BIT, RCU_USBRESET);
  126. - udelay(50 * 1000);
  127. - ltq_rcu_w32(ltq_rcu_r32(RCU_USBRESET) & ~USBRESET_BIT, RCU_USBRESET);
  128. -
  129. - /* Soft reset USB state machines */
  130. - ltq_rcu_w32(ltq_rcu_r32(RCU_USBRESET2)
  131. - | USB1RESET_BIT | USB2RESET_BIT, RCU_USBRESET2);
  132. - udelay(50 * 1000);
  133. - ltq_rcu_w32(ltq_rcu_r32(RCU_USBRESET2)
  134. - & ~(USB1RESET_BIT | USB2RESET_BIT), RCU_USBRESET2);
  135. + if (of_machine_is_compatible("lantiq,vr9")) {
  136. + /* Soft reset USB state machines */
  137. + ltq_rcu_w32(ltq_rcu_r32(RCU_USBRESET2)
  138. + | USB1RESET_BIT | USB2RESET_BIT, RCU_USBRESET2);
  139. + udelay(50 * 1000);
  140. + ltq_rcu_w32(ltq_rcu_r32(RCU_USBRESET2)
  141. + & ~(USB1RESET_BIT | USB2RESET_BIT), RCU_USBRESET2);
  142. + }
  143. }
  144. static int __init mips_reboot_setup(void)
  145. @@ -363,8 +420,11 @@ static int __init mips_reboot_setup(void
  146. if (!ltq_rcu_membase)
  147. panic("Failed to remap core memory");
  148. - if (of_machine_is_compatible("lantiq,ar9") ||
  149. - of_machine_is_compatible("lantiq,vr9"))
  150. + if (of_machine_is_compatible("lantiq,danube") ||
  151. + of_machine_is_compatible("lantiq,ase") ||
  152. + of_machine_is_compatible("lantiq,ar9") ||
  153. + of_machine_is_compatible("lantiq,vr9") ||
  154. + of_machine_is_compatible("lantiq,ar10"))
  155. ltq_usb_init();
  156. if (of_machine_is_compatible("lantiq,vr9"))
  157. --- a/arch/mips/lantiq/xway/sysctrl.c
  158. +++ b/arch/mips/lantiq/xway/sysctrl.c
  159. @@ -254,6 +254,25 @@ static void pmu_disable(struct clk *clk)
  160. pr_warn("deactivating PMU module failed!");
  161. }
  162. +static void usb_set_clock(void)
  163. +{
  164. + unsigned int val = ltq_cgu_r32(ifccr);
  165. +
  166. + if (of_machine_is_compatible("lantiq,ar10") ||
  167. + of_machine_is_compatible("lantiq,grx390")) {
  168. + val &= ~0x03; /* XTAL divided by 3 */
  169. + } else if (of_machine_is_compatible("lantiq,ar9") ||
  170. + of_machine_is_compatible("lantiq,vr9")) {
  171. + /* TODO: this depends on the XTAL frequency */
  172. + val |= 0x03; /* XTAL divided by 3 */
  173. + } else if (of_machine_is_compatible("lantiq,ase")) {
  174. + val |= 0x20; /* from XTAL */
  175. + } else if (of_machine_is_compatible("lantiq,danube")) {
  176. + val |= 0x30; /* 12 MHz, generated from 36 MHz */
  177. + }
  178. + ltq_cgu_w32(val, ifccr);
  179. +}
  180. +
  181. /* the pci enable helper */
  182. static int pci_enable(struct clk *clk)
  183. {
  184. @@ -608,4 +627,5 @@ void __init ltq_soc_init(void)
  185. if (of_machine_is_compatible("lantiq,vr9"))
  186. xbar_fpi_burst_disable();
  187. + usb_set_clock();
  188. }