octeon-usb.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. /*
  2. * XHCI HCD glue for Cavium Octeon III SOCs.
  3. *
  4. * Copyright (C) 2010-2017 Cavium Networks
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file "COPYING" in the main directory of this archive
  8. * for more details.
  9. */
  10. #include <linux/module.h>
  11. #include <linux/device.h>
  12. #include <linux/mutex.h>
  13. #include <linux/delay.h>
  14. #include <linux/of_platform.h>
  15. #include <linux/io.h>
  16. #include <asm/octeon/octeon.h>
  17. /* USB Control Register */
  18. union cvm_usbdrd_uctl_ctl {
  19. uint64_t u64;
  20. struct cvm_usbdrd_uctl_ctl_s {
  21. /* 1 = BIST and set all USB RAMs to 0x0, 0 = BIST */
  22. __BITFIELD_FIELD(uint64_t clear_bist:1,
  23. /* 1 = Start BIST and cleared by hardware */
  24. __BITFIELD_FIELD(uint64_t start_bist:1,
  25. /* Reference clock select for SuperSpeed and HighSpeed PLLs:
  26. * 0x0 = Both PLLs use DLMC_REF_CLK0 for reference clock
  27. * 0x1 = Both PLLs use DLMC_REF_CLK1 for reference clock
  28. * 0x2 = SuperSpeed PLL uses DLMC_REF_CLK0 for reference clock &
  29. * HighSpeed PLL uses PLL_REF_CLK for reference clck
  30. * 0x3 = SuperSpeed PLL uses DLMC_REF_CLK1 for reference clock &
  31. * HighSpeed PLL uses PLL_REF_CLK for reference clck
  32. */
  33. __BITFIELD_FIELD(uint64_t ref_clk_sel:2,
  34. /* 1 = Spread-spectrum clock enable, 0 = SS clock disable */
  35. __BITFIELD_FIELD(uint64_t ssc_en:1,
  36. /* Spread-spectrum clock modulation range:
  37. * 0x0 = -4980 ppm downspread
  38. * 0x1 = -4492 ppm downspread
  39. * 0x2 = -4003 ppm downspread
  40. * 0x3 - 0x7 = Reserved
  41. */
  42. __BITFIELD_FIELD(uint64_t ssc_range:3,
  43. /* Enable non-standard oscillator frequencies:
  44. * [55:53] = modules -1
  45. * [52:47] = 2's complement push amount, 0 = Feature disabled
  46. */
  47. __BITFIELD_FIELD(uint64_t ssc_ref_clk_sel:9,
  48. /* Reference clock multiplier for non-standard frequencies:
  49. * 0x19 = 100MHz on DLMC_REF_CLK* if REF_CLK_SEL = 0x0 or 0x1
  50. * 0x28 = 125MHz on DLMC_REF_CLK* if REF_CLK_SEL = 0x0 or 0x1
  51. * 0x32 = 50MHz on DLMC_REF_CLK* if REF_CLK_SEL = 0x0 or 0x1
  52. * Other Values = Reserved
  53. */
  54. __BITFIELD_FIELD(uint64_t mpll_multiplier:7,
  55. /* Enable reference clock to prescaler for SuperSpeed functionality.
  56. * Should always be set to "1"
  57. */
  58. __BITFIELD_FIELD(uint64_t ref_ssp_en:1,
  59. /* Divide the reference clock by 2 before entering the
  60. * REF_CLK_FSEL divider:
  61. * If REF_CLK_SEL = 0x0 or 0x1, then only 0x0 is legal
  62. * If REF_CLK_SEL = 0x2 or 0x3, then:
  63. * 0x1 = DLMC_REF_CLK* is 125MHz
  64. * 0x0 = DLMC_REF_CLK* is another supported frequency
  65. */
  66. __BITFIELD_FIELD(uint64_t ref_clk_div2:1,
  67. /* Select reference clock freqnuency for both PLL blocks:
  68. * 0x27 = REF_CLK_SEL is 0x0 or 0x1
  69. * 0x07 = REF_CLK_SEL is 0x2 or 0x3
  70. */
  71. __BITFIELD_FIELD(uint64_t ref_clk_fsel:6,
  72. /* Reserved */
  73. __BITFIELD_FIELD(uint64_t reserved_31_31:1,
  74. /* Controller clock enable. */
  75. __BITFIELD_FIELD(uint64_t h_clk_en:1,
  76. /* Select bypass input to controller clock divider:
  77. * 0x0 = Use divided coprocessor clock from H_CLKDIV
  78. * 0x1 = Use clock from GPIO pins
  79. */
  80. __BITFIELD_FIELD(uint64_t h_clk_byp_sel:1,
  81. /* Reset controller clock divider. */
  82. __BITFIELD_FIELD(uint64_t h_clkdiv_rst:1,
  83. /* Reserved */
  84. __BITFIELD_FIELD(uint64_t reserved_27_27:1,
  85. /* Clock divider select:
  86. * 0x0 = divide by 1
  87. * 0x1 = divide by 2
  88. * 0x2 = divide by 4
  89. * 0x3 = divide by 6
  90. * 0x4 = divide by 8
  91. * 0x5 = divide by 16
  92. * 0x6 = divide by 24
  93. * 0x7 = divide by 32
  94. */
  95. __BITFIELD_FIELD(uint64_t h_clkdiv_sel:3,
  96. /* Reserved */
  97. __BITFIELD_FIELD(uint64_t reserved_22_23:2,
  98. /* USB3 port permanently attached: 0x0 = No, 0x1 = Yes */
  99. __BITFIELD_FIELD(uint64_t usb3_port_perm_attach:1,
  100. /* USB2 port permanently attached: 0x0 = No, 0x1 = Yes */
  101. __BITFIELD_FIELD(uint64_t usb2_port_perm_attach:1,
  102. /* Reserved */
  103. __BITFIELD_FIELD(uint64_t reserved_19_19:1,
  104. /* Disable SuperSpeed PHY: 0x0 = No, 0x1 = Yes */
  105. __BITFIELD_FIELD(uint64_t usb3_port_disable:1,
  106. /* Reserved */
  107. __BITFIELD_FIELD(uint64_t reserved_17_17:1,
  108. /* Disable HighSpeed PHY: 0x0 = No, 0x1 = Yes */
  109. __BITFIELD_FIELD(uint64_t usb2_port_disable:1,
  110. /* Reserved */
  111. __BITFIELD_FIELD(uint64_t reserved_15_15:1,
  112. /* Enable PHY SuperSpeed block power: 0x0 = No, 0x1 = Yes */
  113. __BITFIELD_FIELD(uint64_t ss_power_en:1,
  114. /* Reserved */
  115. __BITFIELD_FIELD(uint64_t reserved_13_13:1,
  116. /* Enable PHY HighSpeed block power: 0x0 = No, 0x1 = Yes */
  117. __BITFIELD_FIELD(uint64_t hs_power_en:1,
  118. /* Reserved */
  119. __BITFIELD_FIELD(uint64_t reserved_5_11:7,
  120. /* Enable USB UCTL interface clock: 0xx = No, 0x1 = Yes */
  121. __BITFIELD_FIELD(uint64_t csclk_en:1,
  122. /* Controller mode: 0x0 = Host, 0x1 = Device */
  123. __BITFIELD_FIELD(uint64_t drd_mode:1,
  124. /* PHY reset */
  125. __BITFIELD_FIELD(uint64_t uphy_rst:1,
  126. /* Software reset UAHC */
  127. __BITFIELD_FIELD(uint64_t uahc_rst:1,
  128. /* Software resets UCTL */
  129. __BITFIELD_FIELD(uint64_t uctl_rst:1,
  130. ;)))))))))))))))))))))))))))))))))
  131. } s;
  132. };
  133. /* UAHC Configuration Register */
  134. union cvm_usbdrd_uctl_host_cfg {
  135. uint64_t u64;
  136. struct cvm_usbdrd_uctl_host_cfg_s {
  137. /* Reserved */
  138. __BITFIELD_FIELD(uint64_t reserved_60_63:4,
  139. /* Indicates minimum value of all received BELT values */
  140. __BITFIELD_FIELD(uint64_t host_current_belt:12,
  141. /* Reserved */
  142. __BITFIELD_FIELD(uint64_t reserved_38_47:10,
  143. /* HS jitter adjustment */
  144. __BITFIELD_FIELD(uint64_t fla:6,
  145. /* Reserved */
  146. __BITFIELD_FIELD(uint64_t reserved_29_31:3,
  147. /* Bus-master enable: 0x0 = Disabled (stall DMAs), 0x1 = enabled */
  148. __BITFIELD_FIELD(uint64_t bme:1,
  149. /* Overcurrent protection enable: 0x0 = unavailable, 0x1 = available */
  150. __BITFIELD_FIELD(uint64_t oci_en:1,
  151. /* Overcurrent sene selection:
  152. * 0x0 = Overcurrent indication from off-chip is active-low
  153. * 0x1 = Overcurrent indication from off-chip is active-high
  154. */
  155. __BITFIELD_FIELD(uint64_t oci_active_high_en:1,
  156. /* Port power control enable: 0x0 = unavailable, 0x1 = available */
  157. __BITFIELD_FIELD(uint64_t ppc_en:1,
  158. /* Port power control sense selection:
  159. * 0x0 = Port power to off-chip is active-low
  160. * 0x1 = Port power to off-chip is active-high
  161. */
  162. __BITFIELD_FIELD(uint64_t ppc_active_high_en:1,
  163. /* Reserved */
  164. __BITFIELD_FIELD(uint64_t reserved_0_23:24,
  165. ;)))))))))))
  166. } s;
  167. };
  168. /* UCTL Shim Features Register */
  169. union cvm_usbdrd_uctl_shim_cfg {
  170. uint64_t u64;
  171. struct cvm_usbdrd_uctl_shim_cfg_s {
  172. /* Out-of-bound UAHC register access: 0 = read, 1 = write */
  173. __BITFIELD_FIELD(uint64_t xs_ncb_oob_wrn:1,
  174. /* Reserved */
  175. __BITFIELD_FIELD(uint64_t reserved_60_62:3,
  176. /* SRCID error log for out-of-bound UAHC register access:
  177. * [59:58] = chipID
  178. * [57] = Request source: 0 = core, 1 = NCB-device
  179. * [56:51] = Core/NCB-device number, [56] always 0 for NCB devices
  180. * [50:48] = SubID
  181. */
  182. __BITFIELD_FIELD(uint64_t xs_ncb_oob_osrc:12,
  183. /* Error log for bad UAHC DMA access: 0 = Read log, 1 = Write log */
  184. __BITFIELD_FIELD(uint64_t xm_bad_dma_wrn:1,
  185. /* Reserved */
  186. __BITFIELD_FIELD(uint64_t reserved_44_46:3,
  187. /* Encoded error type for bad UAHC DMA */
  188. __BITFIELD_FIELD(uint64_t xm_bad_dma_type:4,
  189. /* Reserved */
  190. __BITFIELD_FIELD(uint64_t reserved_13_39:27,
  191. /* Select the IOI read command used by DMA accesses */
  192. __BITFIELD_FIELD(uint64_t dma_read_cmd:1,
  193. /* Reserved */
  194. __BITFIELD_FIELD(uint64_t reserved_10_11:2,
  195. /* Select endian format for DMA accesses to the L2c:
  196. * 0x0 = Little endian
  197. *` 0x1 = Big endian
  198. * 0x2 = Reserved
  199. * 0x3 = Reserved
  200. */
  201. __BITFIELD_FIELD(uint64_t dma_endian_mode:2,
  202. /* Reserved */
  203. __BITFIELD_FIELD(uint64_t reserved_2_7:6,
  204. /* Select endian format for IOI CSR access to UAHC:
  205. * 0x0 = Little endian
  206. *` 0x1 = Big endian
  207. * 0x2 = Reserved
  208. * 0x3 = Reserved
  209. */
  210. __BITFIELD_FIELD(uint64_t csr_endian_mode:2,
  211. ;))))))))))))
  212. } s;
  213. };
  214. #define OCTEON_H_CLKDIV_SEL 8
  215. #define OCTEON_MIN_H_CLK_RATE 150000000
  216. #define OCTEON_MAX_H_CLK_RATE 300000000
  217. static DEFINE_MUTEX(dwc3_octeon_clocks_mutex);
  218. static uint8_t clk_div[OCTEON_H_CLKDIV_SEL] = {1, 2, 4, 6, 8, 16, 24, 32};
  219. static int dwc3_octeon_config_power(struct device *dev, u64 base)
  220. {
  221. #define UCTL_HOST_CFG 0xe0
  222. union cvm_usbdrd_uctl_host_cfg uctl_host_cfg;
  223. union cvmx_gpio_bit_cfgx gpio_bit;
  224. uint32_t gpio_pwr[3];
  225. int gpio, len, power_active_low;
  226. struct device_node *node = dev->of_node;
  227. int index = (base >> 24) & 1;
  228. if (of_find_property(node, "power", &len) != NULL) {
  229. if (len == 12) {
  230. of_property_read_u32_array(node, "power", gpio_pwr, 3);
  231. power_active_low = gpio_pwr[2] & 0x01;
  232. gpio = gpio_pwr[1];
  233. } else if (len == 8) {
  234. of_property_read_u32_array(node, "power", gpio_pwr, 2);
  235. power_active_low = 0;
  236. gpio = gpio_pwr[1];
  237. } else {
  238. dev_err(dev, "dwc3 controller clock init failure.\n");
  239. return -EINVAL;
  240. }
  241. if ((OCTEON_IS_MODEL(OCTEON_CN73XX) ||
  242. OCTEON_IS_MODEL(OCTEON_CNF75XX))
  243. && gpio <= 31) {
  244. gpio_bit.u64 = cvmx_read_csr(CVMX_GPIO_BIT_CFGX(gpio));
  245. gpio_bit.s.tx_oe = 1;
  246. gpio_bit.s.output_sel = (index == 0 ? 0x14 : 0x15);
  247. cvmx_write_csr(CVMX_GPIO_BIT_CFGX(gpio), gpio_bit.u64);
  248. } else if (gpio <= 15) {
  249. gpio_bit.u64 = cvmx_read_csr(CVMX_GPIO_BIT_CFGX(gpio));
  250. gpio_bit.s.tx_oe = 1;
  251. gpio_bit.s.output_sel = (index == 0 ? 0x14 : 0x19);
  252. cvmx_write_csr(CVMX_GPIO_BIT_CFGX(gpio), gpio_bit.u64);
  253. } else {
  254. gpio_bit.u64 = cvmx_read_csr(CVMX_GPIO_XBIT_CFGX(gpio));
  255. gpio_bit.s.tx_oe = 1;
  256. gpio_bit.s.output_sel = (index == 0 ? 0x14 : 0x19);
  257. cvmx_write_csr(CVMX_GPIO_XBIT_CFGX(gpio), gpio_bit.u64);
  258. }
  259. /* Enable XHCI power control and set if active high or low. */
  260. uctl_host_cfg.u64 = cvmx_read_csr(base + UCTL_HOST_CFG);
  261. uctl_host_cfg.s.ppc_en = 1;
  262. uctl_host_cfg.s.ppc_active_high_en = !power_active_low;
  263. cvmx_write_csr(base + UCTL_HOST_CFG, uctl_host_cfg.u64);
  264. } else {
  265. /* Disable XHCI power control and set if active high. */
  266. uctl_host_cfg.u64 = cvmx_read_csr(base + UCTL_HOST_CFG);
  267. uctl_host_cfg.s.ppc_en = 0;
  268. uctl_host_cfg.s.ppc_active_high_en = 0;
  269. cvmx_write_csr(base + UCTL_HOST_CFG, uctl_host_cfg.u64);
  270. dev_warn(dev, "dwc3 controller clock init failure.\n");
  271. }
  272. return 0;
  273. }
  274. static int dwc3_octeon_clocks_start(struct device *dev, u64 base)
  275. {
  276. union cvm_usbdrd_uctl_ctl uctl_ctl;
  277. int ref_clk_sel = 2;
  278. u64 div;
  279. u32 clock_rate;
  280. int mpll_mul;
  281. int i;
  282. u64 h_clk_rate;
  283. u64 uctl_ctl_reg = base;
  284. if (dev->of_node) {
  285. const char *ss_clock_type;
  286. const char *hs_clock_type;
  287. i = of_property_read_u32(dev->of_node,
  288. "refclk-frequency", &clock_rate);
  289. if (i) {
  290. pr_err("No UCTL \"refclk-frequency\"\n");
  291. return -EINVAL;
  292. }
  293. i = of_property_read_string(dev->of_node,
  294. "refclk-type-ss", &ss_clock_type);
  295. if (i) {
  296. pr_err("No UCTL \"refclk-type-ss\"\n");
  297. return -EINVAL;
  298. }
  299. i = of_property_read_string(dev->of_node,
  300. "refclk-type-hs", &hs_clock_type);
  301. if (i) {
  302. pr_err("No UCTL \"refclk-type-hs\"\n");
  303. return -EINVAL;
  304. }
  305. if (strcmp("dlmc_ref_clk0", ss_clock_type) == 0) {
  306. if (strcmp(hs_clock_type, "dlmc_ref_clk0") == 0)
  307. ref_clk_sel = 0;
  308. else if (strcmp(hs_clock_type, "pll_ref_clk") == 0)
  309. ref_clk_sel = 2;
  310. else
  311. pr_err("Invalid HS clock type %s, using pll_ref_clk instead\n",
  312. hs_clock_type);
  313. } else if (strcmp(ss_clock_type, "dlmc_ref_clk1") == 0) {
  314. if (strcmp(hs_clock_type, "dlmc_ref_clk1") == 0)
  315. ref_clk_sel = 1;
  316. else if (strcmp(hs_clock_type, "pll_ref_clk") == 0)
  317. ref_clk_sel = 3;
  318. else {
  319. pr_err("Invalid HS clock type %s, using pll_ref_clk instead\n",
  320. hs_clock_type);
  321. ref_clk_sel = 3;
  322. }
  323. } else
  324. pr_err("Invalid SS clock type %s, using dlmc_ref_clk0 instead\n",
  325. ss_clock_type);
  326. if ((ref_clk_sel == 0 || ref_clk_sel == 1) &&
  327. (clock_rate != 100000000))
  328. pr_err("Invalid UCTL clock rate of %u, using 100000000 instead\n",
  329. clock_rate);
  330. } else {
  331. pr_err("No USB UCTL device node\n");
  332. return -EINVAL;
  333. }
  334. /*
  335. * Step 1: Wait for all voltages to be stable...that surely
  336. * happened before starting the kernel. SKIP
  337. */
  338. /* Step 2: Select GPIO for overcurrent indication, if desired. SKIP */
  339. /* Step 3: Assert all resets. */
  340. uctl_ctl.u64 = cvmx_read_csr(uctl_ctl_reg);
  341. uctl_ctl.s.uphy_rst = 1;
  342. uctl_ctl.s.uahc_rst = 1;
  343. uctl_ctl.s.uctl_rst = 1;
  344. cvmx_write_csr(uctl_ctl_reg, uctl_ctl.u64);
  345. /* Step 4a: Reset the clock dividers. */
  346. uctl_ctl.u64 = cvmx_read_csr(uctl_ctl_reg);
  347. uctl_ctl.s.h_clkdiv_rst = 1;
  348. cvmx_write_csr(uctl_ctl_reg, uctl_ctl.u64);
  349. /* Step 4b: Select controller clock frequency. */
  350. for (div = 0; div < OCTEON_H_CLKDIV_SEL; div++) {
  351. h_clk_rate = octeon_get_io_clock_rate() / clk_div[div];
  352. if (h_clk_rate <= OCTEON_MAX_H_CLK_RATE &&
  353. h_clk_rate >= OCTEON_MIN_H_CLK_RATE)
  354. break;
  355. }
  356. uctl_ctl.u64 = cvmx_read_csr(uctl_ctl_reg);
  357. uctl_ctl.s.h_clkdiv_sel = div;
  358. uctl_ctl.s.h_clk_en = 1;
  359. cvmx_write_csr(uctl_ctl_reg, uctl_ctl.u64);
  360. uctl_ctl.u64 = cvmx_read_csr(uctl_ctl_reg);
  361. if ((div != uctl_ctl.s.h_clkdiv_sel) || (!uctl_ctl.s.h_clk_en)) {
  362. dev_err(dev, "dwc3 controller clock init failure.\n");
  363. return -EINVAL;
  364. }
  365. /* Step 4c: Deassert the controller clock divider reset. */
  366. uctl_ctl.u64 = cvmx_read_csr(uctl_ctl_reg);
  367. uctl_ctl.s.h_clkdiv_rst = 0;
  368. cvmx_write_csr(uctl_ctl_reg, uctl_ctl.u64);
  369. /* Step 5a: Reference clock configuration. */
  370. uctl_ctl.u64 = cvmx_read_csr(uctl_ctl_reg);
  371. uctl_ctl.s.ref_clk_sel = ref_clk_sel;
  372. uctl_ctl.s.ref_clk_fsel = 0x07;
  373. uctl_ctl.s.ref_clk_div2 = 0;
  374. switch (clock_rate) {
  375. default:
  376. dev_err(dev, "Invalid ref_clk %u, using 100000000 instead\n",
  377. clock_rate);
  378. fallthrough;
  379. case 100000000:
  380. mpll_mul = 0x19;
  381. if (ref_clk_sel < 2)
  382. uctl_ctl.s.ref_clk_fsel = 0x27;
  383. break;
  384. case 50000000:
  385. mpll_mul = 0x32;
  386. break;
  387. case 125000000:
  388. mpll_mul = 0x28;
  389. break;
  390. }
  391. uctl_ctl.s.mpll_multiplier = mpll_mul;
  392. /* Step 5b: Configure and enable spread-spectrum for SuperSpeed. */
  393. uctl_ctl.s.ssc_en = 1;
  394. /* Step 5c: Enable SuperSpeed. */
  395. uctl_ctl.s.ref_ssp_en = 1;
  396. /* Step 5d: Configure PHYs. SKIP */
  397. /* Step 6a & 6b: Power up PHYs. */
  398. uctl_ctl.s.hs_power_en = 1;
  399. uctl_ctl.s.ss_power_en = 1;
  400. cvmx_write_csr(uctl_ctl_reg, uctl_ctl.u64);
  401. /* Step 7: Wait 10 controller-clock cycles to take effect. */
  402. udelay(10);
  403. /* Step 8a: Deassert UCTL reset signal. */
  404. uctl_ctl.u64 = cvmx_read_csr(uctl_ctl_reg);
  405. uctl_ctl.s.uctl_rst = 0;
  406. cvmx_write_csr(uctl_ctl_reg, uctl_ctl.u64);
  407. /* Step 8b: Wait 10 controller-clock cycles. */
  408. udelay(10);
  409. /* Steo 8c: Setup power-power control. */
  410. if (dwc3_octeon_config_power(dev, base)) {
  411. dev_err(dev, "Error configuring power.\n");
  412. return -EINVAL;
  413. }
  414. /* Step 8d: Deassert UAHC reset signal. */
  415. uctl_ctl.u64 = cvmx_read_csr(uctl_ctl_reg);
  416. uctl_ctl.s.uahc_rst = 0;
  417. cvmx_write_csr(uctl_ctl_reg, uctl_ctl.u64);
  418. /* Step 8e: Wait 10 controller-clock cycles. */
  419. udelay(10);
  420. /* Step 9: Enable conditional coprocessor clock of UCTL. */
  421. uctl_ctl.u64 = cvmx_read_csr(uctl_ctl_reg);
  422. uctl_ctl.s.csclk_en = 1;
  423. cvmx_write_csr(uctl_ctl_reg, uctl_ctl.u64);
  424. /*Step 10: Set for host mode only. */
  425. uctl_ctl.u64 = cvmx_read_csr(uctl_ctl_reg);
  426. uctl_ctl.s.drd_mode = 0;
  427. cvmx_write_csr(uctl_ctl_reg, uctl_ctl.u64);
  428. return 0;
  429. }
  430. static void __init dwc3_octeon_set_endian_mode(u64 base)
  431. {
  432. #define UCTL_SHIM_CFG 0xe8
  433. union cvm_usbdrd_uctl_shim_cfg shim_cfg;
  434. shim_cfg.u64 = cvmx_read_csr(base + UCTL_SHIM_CFG);
  435. #ifdef __BIG_ENDIAN
  436. shim_cfg.s.dma_endian_mode = 1;
  437. shim_cfg.s.csr_endian_mode = 1;
  438. #else
  439. shim_cfg.s.dma_endian_mode = 0;
  440. shim_cfg.s.csr_endian_mode = 0;
  441. #endif
  442. cvmx_write_csr(base + UCTL_SHIM_CFG, shim_cfg.u64);
  443. }
  444. #define CVMX_USBDRDX_UCTL_CTL(index) \
  445. (CVMX_ADD_IO_SEG(0x0001180068000000ull) + \
  446. ((index & 1) * 0x1000000ull))
  447. static void __init dwc3_octeon_phy_reset(u64 base)
  448. {
  449. union cvm_usbdrd_uctl_ctl uctl_ctl;
  450. int index = (base >> 24) & 1;
  451. uctl_ctl.u64 = cvmx_read_csr(CVMX_USBDRDX_UCTL_CTL(index));
  452. uctl_ctl.s.uphy_rst = 0;
  453. cvmx_write_csr(CVMX_USBDRDX_UCTL_CTL(index), uctl_ctl.u64);
  454. }
  455. static int __init dwc3_octeon_device_init(void)
  456. {
  457. const char compat_node_name[] = "cavium,octeon-7130-usb-uctl";
  458. struct platform_device *pdev;
  459. struct device_node *node;
  460. struct resource *res;
  461. void __iomem *base;
  462. /*
  463. * There should only be three universal controllers, "uctl"
  464. * in the device tree. Two USB and a SATA, which we ignore.
  465. */
  466. node = NULL;
  467. do {
  468. node = of_find_node_by_name(node, "uctl");
  469. if (!node)
  470. return -ENODEV;
  471. if (of_device_is_compatible(node, compat_node_name)) {
  472. pdev = of_find_device_by_node(node);
  473. if (!pdev)
  474. return -ENODEV;
  475. /*
  476. * The code below maps in the registers necessary for
  477. * setting up the clocks and reseting PHYs. We must
  478. * release the resources so the dwc3 subsystem doesn't
  479. * know the difference.
  480. */
  481. base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
  482. if (IS_ERR(base)) {
  483. put_device(&pdev->dev);
  484. return PTR_ERR(base);
  485. }
  486. mutex_lock(&dwc3_octeon_clocks_mutex);
  487. dwc3_octeon_clocks_start(&pdev->dev, (u64)base);
  488. dwc3_octeon_set_endian_mode((u64)base);
  489. dwc3_octeon_phy_reset((u64)base);
  490. dev_info(&pdev->dev, "clocks initialized.\n");
  491. mutex_unlock(&dwc3_octeon_clocks_mutex);
  492. devm_iounmap(&pdev->dev, base);
  493. devm_release_mem_region(&pdev->dev, res->start,
  494. resource_size(res));
  495. put_device(&pdev->dev);
  496. }
  497. } while (node != NULL);
  498. return 0;
  499. }
  500. device_initcall(dwc3_octeon_device_init);
  501. MODULE_AUTHOR("David Daney <[email protected]>");
  502. MODULE_LICENSE("GPL");
  503. MODULE_DESCRIPTION("USB driver for OCTEON III SoC");