dwc3-octeon.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * DWC3 glue for Cavium Octeon III SOCs.
  4. *
  5. * Copyright (C) 2010-2017 Cavium Networks
  6. * Copyright (C) 2023 RACOM s.r.o.
  7. */
  8. #include <linux/bitfield.h>
  9. #include <linux/bits.h>
  10. #include <linux/device.h>
  11. #include <linux/delay.h>
  12. #include <linux/io.h>
  13. #include <linux/module.h>
  14. #include <linux/mutex.h>
  15. #include <linux/of.h>
  16. #include <linux/of_platform.h>
  17. #include <linux/platform_device.h>
  18. /*
  19. * USB Control Register
  20. */
  21. #define USBDRD_UCTL_CTL 0x00
  22. /* BIST fast-clear mode select. A BIST run with this bit set
  23. * clears all entries in USBH RAMs to 0x0.
  24. */
  25. # define USBDRD_UCTL_CTL_CLEAR_BIST BIT_ULL(63)
  26. /* 1 = Start BIST and cleared by hardware */
  27. # define USBDRD_UCTL_CTL_START_BIST BIT_ULL(62)
  28. /* Reference clock select for SuperSpeed and HighSpeed PLLs:
  29. * 0x0 = Both PLLs use DLMC_REF_CLK0 for reference clock
  30. * 0x1 = Both PLLs use DLMC_REF_CLK1 for reference clock
  31. * 0x2 = SuperSpeed PLL uses DLMC_REF_CLK0 for reference clock &
  32. * HighSpeed PLL uses PLL_REF_CLK for reference clck
  33. * 0x3 = SuperSpeed PLL uses DLMC_REF_CLK1 for reference clock &
  34. * HighSpeed PLL uses PLL_REF_CLK for reference clck
  35. */
  36. # define USBDRD_UCTL_CTL_REF_CLK_SEL GENMASK_ULL(61, 60)
  37. /* 1 = Spread-spectrum clock enable, 0 = SS clock disable */
  38. # define USBDRD_UCTL_CTL_SSC_EN BIT_ULL(59)
  39. /* Spread-spectrum clock modulation range:
  40. * 0x0 = -4980 ppm downspread
  41. * 0x1 = -4492 ppm downspread
  42. * 0x2 = -4003 ppm downspread
  43. * 0x3 - 0x7 = Reserved
  44. */
  45. # define USBDRD_UCTL_CTL_SSC_RANGE GENMASK_ULL(58, 56)
  46. /* Enable non-standard oscillator frequencies:
  47. * [55:53] = modules -1
  48. * [52:47] = 2's complement push amount, 0 = Feature disabled
  49. */
  50. # define USBDRD_UCTL_CTL_SSC_REF_CLK_SEL GENMASK_ULL(55, 47)
  51. /* Reference clock multiplier for non-standard frequencies:
  52. * 0x19 = 100MHz on DLMC_REF_CLK* if REF_CLK_SEL = 0x0 or 0x1
  53. * 0x28 = 125MHz on DLMC_REF_CLK* if REF_CLK_SEL = 0x0 or 0x1
  54. * 0x32 = 50MHz on DLMC_REF_CLK* if REF_CLK_SEL = 0x0 or 0x1
  55. * Other Values = Reserved
  56. */
  57. # define USBDRD_UCTL_CTL_MPLL_MULTIPLIER GENMASK_ULL(46, 40)
  58. /* Enable reference clock to prescaler for SuperSpeed functionality.
  59. * Should always be set to "1"
  60. */
  61. # define USBDRD_UCTL_CTL_REF_SSP_EN BIT_ULL(39)
  62. /* Divide the reference clock by 2 before entering the
  63. * REF_CLK_FSEL divider:
  64. * If REF_CLK_SEL = 0x0 or 0x1, then only 0x0 is legal
  65. * If REF_CLK_SEL = 0x2 or 0x3, then:
  66. * 0x1 = DLMC_REF_CLK* is 125MHz
  67. * 0x0 = DLMC_REF_CLK* is another supported frequency
  68. */
  69. # define USBDRD_UCTL_CTL_REF_CLK_DIV2 BIT_ULL(38)
  70. /* Select reference clock freqnuency for both PLL blocks:
  71. * 0x27 = REF_CLK_SEL is 0x0 or 0x1
  72. * 0x07 = REF_CLK_SEL is 0x2 or 0x3
  73. */
  74. # define USBDRD_UCTL_CTL_REF_CLK_FSEL GENMASK_ULL(37, 32)
  75. /* Controller clock enable. */
  76. # define USBDRD_UCTL_CTL_H_CLK_EN BIT_ULL(30)
  77. /* Select bypass input to controller clock divider:
  78. * 0x0 = Use divided coprocessor clock from H_CLKDIV
  79. * 0x1 = Use clock from GPIO pins
  80. */
  81. # define USBDRD_UCTL_CTL_H_CLK_BYP_SEL BIT_ULL(29)
  82. /* Reset controller clock divider. */
  83. # define USBDRD_UCTL_CTL_H_CLKDIV_RST BIT_ULL(28)
  84. /* Clock divider select:
  85. * 0x0 = divide by 1
  86. * 0x1 = divide by 2
  87. * 0x2 = divide by 4
  88. * 0x3 = divide by 6
  89. * 0x4 = divide by 8
  90. * 0x5 = divide by 16
  91. * 0x6 = divide by 24
  92. * 0x7 = divide by 32
  93. */
  94. # define USBDRD_UCTL_CTL_H_CLKDIV_SEL GENMASK_ULL(26, 24)
  95. /* USB3 port permanently attached: 0x0 = No, 0x1 = Yes */
  96. # define USBDRD_UCTL_CTL_USB3_PORT_PERM_ATTACH BIT_ULL(21)
  97. /* USB2 port permanently attached: 0x0 = No, 0x1 = Yes */
  98. # define USBDRD_UCTL_CTL_USB2_PORT_PERM_ATTACH BIT_ULL(20)
  99. /* Disable SuperSpeed PHY: 0x0 = No, 0x1 = Yes */
  100. # define USBDRD_UCTL_CTL_USB3_PORT_DISABLE BIT_ULL(18)
  101. /* Disable HighSpeed PHY: 0x0 = No, 0x1 = Yes */
  102. # define USBDRD_UCTL_CTL_USB2_PORT_DISABLE BIT_ULL(16)
  103. /* Enable PHY SuperSpeed block power: 0x0 = No, 0x1 = Yes */
  104. # define USBDRD_UCTL_CTL_SS_POWER_EN BIT_ULL(14)
  105. /* Enable PHY HighSpeed block power: 0x0 = No, 0x1 = Yes */
  106. # define USBDRD_UCTL_CTL_HS_POWER_EN BIT_ULL(12)
  107. /* Enable USB UCTL interface clock: 0xx = No, 0x1 = Yes */
  108. # define USBDRD_UCTL_CTL_CSCLK_EN BIT_ULL(4)
  109. /* Controller mode: 0x0 = Host, 0x1 = Device */
  110. # define USBDRD_UCTL_CTL_DRD_MODE BIT_ULL(3)
  111. /* PHY reset */
  112. # define USBDRD_UCTL_CTL_UPHY_RST BIT_ULL(2)
  113. /* Software reset UAHC */
  114. # define USBDRD_UCTL_CTL_UAHC_RST BIT_ULL(1)
  115. /* Software resets UCTL */
  116. # define USBDRD_UCTL_CTL_UCTL_RST BIT_ULL(0)
  117. #define USBDRD_UCTL_BIST_STATUS 0x08
  118. #define USBDRD_UCTL_SPARE0 0x10
  119. #define USBDRD_UCTL_INTSTAT 0x30
  120. #define USBDRD_UCTL_PORT_CFG_HS(port) (0x40 + (0x20 * port))
  121. #define USBDRD_UCTL_PORT_CFG_SS(port) (0x48 + (0x20 * port))
  122. #define USBDRD_UCTL_PORT_CR_DBG_CFG(port) (0x50 + (0x20 * port))
  123. #define USBDRD_UCTL_PORT_CR_DBG_STATUS(port) (0x58 + (0x20 * port))
  124. /*
  125. * UCTL Configuration Register
  126. */
  127. #define USBDRD_UCTL_HOST_CFG 0xe0
  128. /* Indicates minimum value of all received BELT values */
  129. # define USBDRD_UCTL_HOST_CFG_HOST_CURRENT_BELT GENMASK_ULL(59, 48)
  130. /* HS jitter adjustment */
  131. # define USBDRD_UCTL_HOST_CFG_FLA GENMASK_ULL(37, 32)
  132. /* Bus-master enable: 0x0 = Disabled (stall DMAs), 0x1 = enabled */
  133. # define USBDRD_UCTL_HOST_CFG_BME BIT_ULL(28)
  134. /* Overcurrent protection enable: 0x0 = unavailable, 0x1 = available */
  135. # define USBDRD_UCTL_HOST_OCI_EN BIT_ULL(27)
  136. /* Overcurrent sene selection:
  137. * 0x0 = Overcurrent indication from off-chip is active-low
  138. * 0x1 = Overcurrent indication from off-chip is active-high
  139. */
  140. # define USBDRD_UCTL_HOST_OCI_ACTIVE_HIGH_EN BIT_ULL(26)
  141. /* Port power control enable: 0x0 = unavailable, 0x1 = available */
  142. # define USBDRD_UCTL_HOST_PPC_EN BIT_ULL(25)
  143. /* Port power control sense selection:
  144. * 0x0 = Port power to off-chip is active-low
  145. * 0x1 = Port power to off-chip is active-high
  146. */
  147. # define USBDRD_UCTL_HOST_PPC_ACTIVE_HIGH_EN BIT_ULL(24)
  148. /*
  149. * UCTL Shim Features Register
  150. */
  151. #define USBDRD_UCTL_SHIM_CFG 0xe8
  152. /* Out-of-bound UAHC register access: 0 = read, 1 = write */
  153. # define USBDRD_UCTL_SHIM_CFG_XS_NCB_OOB_WRN BIT_ULL(63)
  154. /* SRCID error log for out-of-bound UAHC register access:
  155. * [59:58] = chipID
  156. * [57] = Request source: 0 = core, 1 = NCB-device
  157. * [56:51] = Core/NCB-device number, [56] always 0 for NCB devices
  158. * [50:48] = SubID
  159. */
  160. # define USBDRD_UCTL_SHIM_CFG_XS_NCB_OOB_OSRC GENMASK_ULL(59, 48)
  161. /* Error log for bad UAHC DMA access: 0 = Read log, 1 = Write log */
  162. # define USBDRD_UCTL_SHIM_CFG_XM_BAD_DMA_WRN BIT_ULL(47)
  163. /* Encoded error type for bad UAHC DMA */
  164. # define USBDRD_UCTL_SHIM_CFG_XM_BAD_DMA_TYPE GENMASK_ULL(43, 40)
  165. /* Select the IOI read command used by DMA accesses */
  166. # define USBDRD_UCTL_SHIM_CFG_DMA_READ_CMD BIT_ULL(12)
  167. /* Select endian format for DMA accesses to the L2C:
  168. * 0x0 = Little endian
  169. * 0x1 = Big endian
  170. * 0x2 = Reserved
  171. * 0x3 = Reserved
  172. */
  173. # define USBDRD_UCTL_SHIM_CFG_DMA_ENDIAN_MODE GENMASK_ULL(9, 8)
  174. /* Select endian format for IOI CSR access to UAHC:
  175. * 0x0 = Little endian
  176. * 0x1 = Big endian
  177. * 0x2 = Reserved
  178. * 0x3 = Reserved
  179. */
  180. # define USBDRD_UCTL_SHIM_CFG_CSR_ENDIAN_MODE GENMASK_ULL(1, 0)
  181. #define USBDRD_UCTL_ECC 0xf0
  182. #define USBDRD_UCTL_SPARE1 0xf8
  183. struct dwc3_octeon {
  184. struct device *dev;
  185. void __iomem *base;
  186. };
  187. #define DWC3_GPIO_POWER_NONE (-1)
  188. #ifdef CONFIG_CAVIUM_OCTEON_SOC
  189. #include <asm/octeon/octeon.h>
  190. static inline uint64_t dwc3_octeon_readq(void __iomem *addr)
  191. {
  192. return cvmx_readq_csr(addr);
  193. }
  194. static inline void dwc3_octeon_writeq(void __iomem *base, uint64_t val)
  195. {
  196. cvmx_writeq_csr(base, val);
  197. }
  198. static void dwc3_octeon_config_gpio(int index, int gpio)
  199. {
  200. union cvmx_gpio_bit_cfgx gpio_bit;
  201. if ((OCTEON_IS_MODEL(OCTEON_CN73XX) ||
  202. OCTEON_IS_MODEL(OCTEON_CNF75XX))
  203. && gpio <= 31) {
  204. gpio_bit.u64 = cvmx_read_csr(CVMX_GPIO_BIT_CFGX(gpio));
  205. gpio_bit.s.tx_oe = 1;
  206. gpio_bit.s.output_sel = (index == 0 ? 0x14 : 0x15);
  207. cvmx_write_csr(CVMX_GPIO_BIT_CFGX(gpio), gpio_bit.u64);
  208. } else if (gpio <= 15) {
  209. gpio_bit.u64 = cvmx_read_csr(CVMX_GPIO_BIT_CFGX(gpio));
  210. gpio_bit.s.tx_oe = 1;
  211. gpio_bit.s.output_sel = (index == 0 ? 0x14 : 0x19);
  212. cvmx_write_csr(CVMX_GPIO_BIT_CFGX(gpio), gpio_bit.u64);
  213. } else {
  214. gpio_bit.u64 = cvmx_read_csr(CVMX_GPIO_XBIT_CFGX(gpio));
  215. gpio_bit.s.tx_oe = 1;
  216. gpio_bit.s.output_sel = (index == 0 ? 0x14 : 0x19);
  217. cvmx_write_csr(CVMX_GPIO_XBIT_CFGX(gpio), gpio_bit.u64);
  218. }
  219. }
  220. #else
  221. static inline uint64_t dwc3_octeon_readq(void __iomem *addr)
  222. {
  223. return 0;
  224. }
  225. static inline void dwc3_octeon_writeq(void __iomem *base, uint64_t val) { }
  226. static inline void dwc3_octeon_config_gpio(int index, int gpio) { }
  227. static uint64_t octeon_get_io_clock_rate(void)
  228. {
  229. return 150000000;
  230. }
  231. #endif
  232. static int dwc3_octeon_get_divider(void)
  233. {
  234. static const uint8_t clk_div[] = { 1, 2, 4, 6, 8, 16, 24, 32 };
  235. int div = 0;
  236. while (div < ARRAY_SIZE(clk_div)) {
  237. uint64_t rate = octeon_get_io_clock_rate() / clk_div[div];
  238. if (rate <= 300000000 && rate >= 150000000)
  239. return div;
  240. div++;
  241. }
  242. return -EINVAL;
  243. }
  244. static int dwc3_octeon_setup(struct dwc3_octeon *octeon,
  245. int ref_clk_sel, int ref_clk_fsel, int mpll_mul,
  246. int power_gpio, int power_active_low)
  247. {
  248. u64 val;
  249. int div;
  250. struct device *dev = octeon->dev;
  251. void __iomem *uctl_ctl_reg = octeon->base + USBDRD_UCTL_CTL;
  252. void __iomem *uctl_host_cfg_reg = octeon->base + USBDRD_UCTL_HOST_CFG;
  253. /*
  254. * Step 1: Wait for all voltages to be stable...that surely
  255. * happened before starting the kernel. SKIP
  256. */
  257. /* Step 2: Select GPIO for overcurrent indication, if desired. SKIP */
  258. /* Step 3: Assert all resets. */
  259. val = dwc3_octeon_readq(uctl_ctl_reg);
  260. val |= USBDRD_UCTL_CTL_UPHY_RST |
  261. USBDRD_UCTL_CTL_UAHC_RST |
  262. USBDRD_UCTL_CTL_UCTL_RST;
  263. dwc3_octeon_writeq(uctl_ctl_reg, val);
  264. /* Step 4a: Reset the clock dividers. */
  265. val = dwc3_octeon_readq(uctl_ctl_reg);
  266. val |= USBDRD_UCTL_CTL_H_CLKDIV_RST;
  267. dwc3_octeon_writeq(uctl_ctl_reg, val);
  268. /* Step 4b: Select controller clock frequency. */
  269. div = dwc3_octeon_get_divider();
  270. if (div < 0) {
  271. dev_err(dev, "clock divider invalid\n");
  272. return div;
  273. }
  274. val = dwc3_octeon_readq(uctl_ctl_reg);
  275. val &= ~USBDRD_UCTL_CTL_H_CLKDIV_SEL;
  276. val |= FIELD_PREP(USBDRD_UCTL_CTL_H_CLKDIV_SEL, div);
  277. val |= USBDRD_UCTL_CTL_H_CLK_EN;
  278. dwc3_octeon_writeq(uctl_ctl_reg, val);
  279. val = dwc3_octeon_readq(uctl_ctl_reg);
  280. if ((div != FIELD_GET(USBDRD_UCTL_CTL_H_CLKDIV_SEL, val)) ||
  281. (!(FIELD_GET(USBDRD_UCTL_CTL_H_CLK_EN, val)))) {
  282. dev_err(dev, "clock init failure (UCTL_CTL=%016llx)\n", val);
  283. return -EINVAL;
  284. }
  285. /* Step 4c: Deassert the controller clock divider reset. */
  286. val &= ~USBDRD_UCTL_CTL_H_CLKDIV_RST;
  287. dwc3_octeon_writeq(uctl_ctl_reg, val);
  288. /* Step 5a: Reference clock configuration. */
  289. val = dwc3_octeon_readq(uctl_ctl_reg);
  290. val &= ~USBDRD_UCTL_CTL_REF_CLK_DIV2;
  291. val &= ~USBDRD_UCTL_CTL_REF_CLK_SEL;
  292. val |= FIELD_PREP(USBDRD_UCTL_CTL_REF_CLK_SEL, ref_clk_sel);
  293. val &= ~USBDRD_UCTL_CTL_REF_CLK_FSEL;
  294. val |= FIELD_PREP(USBDRD_UCTL_CTL_REF_CLK_FSEL, ref_clk_fsel);
  295. val &= ~USBDRD_UCTL_CTL_MPLL_MULTIPLIER;
  296. val |= FIELD_PREP(USBDRD_UCTL_CTL_MPLL_MULTIPLIER, mpll_mul);
  297. /* Step 5b: Configure and enable spread-spectrum for SuperSpeed. */
  298. val |= USBDRD_UCTL_CTL_SSC_EN;
  299. /* Step 5c: Enable SuperSpeed. */
  300. val |= USBDRD_UCTL_CTL_REF_SSP_EN;
  301. /* Step 5d: Configure PHYs. SKIP */
  302. /* Step 6a & 6b: Power up PHYs. */
  303. val |= USBDRD_UCTL_CTL_HS_POWER_EN;
  304. val |= USBDRD_UCTL_CTL_SS_POWER_EN;
  305. dwc3_octeon_writeq(uctl_ctl_reg, val);
  306. /* Step 7: Wait 10 controller-clock cycles to take effect. */
  307. udelay(10);
  308. /* Step 8a: Deassert UCTL reset signal. */
  309. val = dwc3_octeon_readq(uctl_ctl_reg);
  310. val &= ~USBDRD_UCTL_CTL_UCTL_RST;
  311. dwc3_octeon_writeq(uctl_ctl_reg, val);
  312. /* Step 8b: Wait 10 controller-clock cycles. */
  313. udelay(10);
  314. /* Step 8c: Setup power control. */
  315. val = dwc3_octeon_readq(uctl_host_cfg_reg);
  316. val |= USBDRD_UCTL_HOST_PPC_EN;
  317. if (power_gpio == DWC3_GPIO_POWER_NONE) {
  318. val &= ~USBDRD_UCTL_HOST_PPC_EN;
  319. } else {
  320. val |= USBDRD_UCTL_HOST_PPC_EN;
  321. dwc3_octeon_config_gpio(((__force uintptr_t)octeon->base >> 24) & 1,
  322. power_gpio);
  323. dev_dbg(dev, "power control is using gpio%d\n", power_gpio);
  324. }
  325. if (power_active_low)
  326. val &= ~USBDRD_UCTL_HOST_PPC_ACTIVE_HIGH_EN;
  327. else
  328. val |= USBDRD_UCTL_HOST_PPC_ACTIVE_HIGH_EN;
  329. dwc3_octeon_writeq(uctl_host_cfg_reg, val);
  330. /* Step 8d: Deassert UAHC reset signal. */
  331. val = dwc3_octeon_readq(uctl_ctl_reg);
  332. val &= ~USBDRD_UCTL_CTL_UAHC_RST;
  333. dwc3_octeon_writeq(uctl_ctl_reg, val);
  334. /* Step 8e: Wait 10 controller-clock cycles. */
  335. udelay(10);
  336. /* Step 9: Enable conditional coprocessor clock of UCTL. */
  337. val = dwc3_octeon_readq(uctl_ctl_reg);
  338. val |= USBDRD_UCTL_CTL_CSCLK_EN;
  339. dwc3_octeon_writeq(uctl_ctl_reg, val);
  340. /*Step 10: Set for host mode only. */
  341. val = dwc3_octeon_readq(uctl_ctl_reg);
  342. val &= ~USBDRD_UCTL_CTL_DRD_MODE;
  343. dwc3_octeon_writeq(uctl_ctl_reg, val);
  344. return 0;
  345. }
  346. static void dwc3_octeon_set_endian_mode(struct dwc3_octeon *octeon)
  347. {
  348. u64 val;
  349. void __iomem *uctl_shim_cfg_reg = octeon->base + USBDRD_UCTL_SHIM_CFG;
  350. val = dwc3_octeon_readq(uctl_shim_cfg_reg);
  351. val &= ~USBDRD_UCTL_SHIM_CFG_DMA_ENDIAN_MODE;
  352. val &= ~USBDRD_UCTL_SHIM_CFG_CSR_ENDIAN_MODE;
  353. #ifdef __BIG_ENDIAN
  354. val |= FIELD_PREP(USBDRD_UCTL_SHIM_CFG_DMA_ENDIAN_MODE, 1);
  355. val |= FIELD_PREP(USBDRD_UCTL_SHIM_CFG_CSR_ENDIAN_MODE, 1);
  356. #endif
  357. dwc3_octeon_writeq(uctl_shim_cfg_reg, val);
  358. }
  359. static void dwc3_octeon_phy_reset(struct dwc3_octeon *octeon)
  360. {
  361. u64 val;
  362. void __iomem *uctl_ctl_reg = octeon->base + USBDRD_UCTL_CTL;
  363. val = dwc3_octeon_readq(uctl_ctl_reg);
  364. val &= ~USBDRD_UCTL_CTL_UPHY_RST;
  365. dwc3_octeon_writeq(uctl_ctl_reg, val);
  366. }
  367. static int dwc3_octeon_probe(struct platform_device *pdev)
  368. {
  369. struct device *dev = &pdev->dev;
  370. struct device_node *node = dev->of_node;
  371. struct dwc3_octeon *octeon;
  372. const char *hs_clock_type, *ss_clock_type;
  373. int ref_clk_sel, ref_clk_fsel, mpll_mul;
  374. int power_active_low, power_gpio;
  375. int err, len;
  376. u32 clock_rate, gpio_pwr[3];
  377. if (of_property_read_u32(node, "refclk-frequency", &clock_rate)) {
  378. dev_err(dev, "No UCTL \"refclk-frequency\"\n");
  379. return -EINVAL;
  380. }
  381. if (of_property_read_string(node, "refclk-type-ss", &ss_clock_type)) {
  382. dev_err(dev, "No UCTL \"refclk-type-ss\"\n");
  383. return -EINVAL;
  384. }
  385. if (of_property_read_string(node, "refclk-type-hs", &hs_clock_type)) {
  386. dev_err(dev, "No UCTL \"refclk-type-hs\"\n");
  387. return -EINVAL;
  388. }
  389. ref_clk_sel = 2;
  390. if (strcmp("dlmc_ref_clk0", ss_clock_type) == 0) {
  391. if (strcmp(hs_clock_type, "dlmc_ref_clk0") == 0)
  392. ref_clk_sel = 0;
  393. else if (strcmp(hs_clock_type, "pll_ref_clk"))
  394. dev_warn(dev, "Invalid HS clock type %s, using pll_ref_clk instead\n",
  395. hs_clock_type);
  396. } else if (strcmp(ss_clock_type, "dlmc_ref_clk1") == 0) {
  397. if (strcmp(hs_clock_type, "dlmc_ref_clk1") == 0) {
  398. ref_clk_sel = 1;
  399. } else {
  400. ref_clk_sel = 3;
  401. if (strcmp(hs_clock_type, "pll_ref_clk"))
  402. dev_warn(dev, "Invalid HS clock type %s, using pll_ref_clk instead\n",
  403. hs_clock_type);
  404. }
  405. } else {
  406. dev_warn(dev, "Invalid SS clock type %s, using dlmc_ref_clk0 instead\n",
  407. ss_clock_type);
  408. }
  409. ref_clk_fsel = 0x07;
  410. switch (clock_rate) {
  411. default:
  412. dev_warn(dev, "Invalid ref_clk %u, using 100000000 instead\n",
  413. clock_rate);
  414. fallthrough;
  415. case 100000000:
  416. mpll_mul = 0x19;
  417. if (ref_clk_sel < 2)
  418. ref_clk_fsel = 0x27;
  419. break;
  420. case 50000000:
  421. mpll_mul = 0x32;
  422. break;
  423. case 125000000:
  424. mpll_mul = 0x28;
  425. break;
  426. }
  427. power_gpio = DWC3_GPIO_POWER_NONE;
  428. power_active_low = 0;
  429. len = of_property_read_variable_u32_array(node, "power", gpio_pwr, 2, 3);
  430. if (len > 0) {
  431. if (len == 3)
  432. power_active_low = gpio_pwr[2] & 0x01;
  433. power_gpio = gpio_pwr[1];
  434. }
  435. octeon = devm_kzalloc(dev, sizeof(*octeon), GFP_KERNEL);
  436. if (!octeon)
  437. return -ENOMEM;
  438. octeon->dev = dev;
  439. octeon->base = devm_platform_ioremap_resource(pdev, 0);
  440. if (IS_ERR(octeon->base))
  441. return PTR_ERR(octeon->base);
  442. err = dwc3_octeon_setup(octeon, ref_clk_sel, ref_clk_fsel, mpll_mul,
  443. power_gpio, power_active_low);
  444. if (err)
  445. return err;
  446. dwc3_octeon_set_endian_mode(octeon);
  447. dwc3_octeon_phy_reset(octeon);
  448. platform_set_drvdata(pdev, octeon);
  449. return of_platform_populate(node, NULL, NULL, dev);
  450. }
  451. static void dwc3_octeon_remove(struct platform_device *pdev)
  452. {
  453. struct dwc3_octeon *octeon = platform_get_drvdata(pdev);
  454. of_platform_depopulate(octeon->dev);
  455. }
  456. static const struct of_device_id dwc3_octeon_of_match[] = {
  457. { .compatible = "cavium,octeon-7130-usb-uctl" },
  458. { },
  459. };
  460. MODULE_DEVICE_TABLE(of, dwc3_octeon_of_match);
  461. static struct platform_driver dwc3_octeon_driver = {
  462. .probe = dwc3_octeon_probe,
  463. .remove_new = dwc3_octeon_remove,
  464. .driver = {
  465. .name = "dwc3-octeon",
  466. .of_match_table = dwc3_octeon_of_match,
  467. },
  468. };
  469. module_platform_driver(dwc3_octeon_driver);
  470. MODULE_ALIAS("platform:dwc3-octeon");
  471. MODULE_AUTHOR("Ladislav Michl <ladis@linux-mips.org>");
  472. MODULE_LICENSE("GPL");
  473. MODULE_DESCRIPTION("DesignWare USB3 OCTEON III Glue Layer");