clk-mtmips.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * MTMIPS SoCs Clock Driver
  4. * Author: Sergio Paracuellos <sergio.paracuellos@gmail.com>
  5. */
  6. #include <linux/bitops.h>
  7. #include <linux/clk-provider.h>
  8. #include <linux/mfd/syscon.h>
  9. #include <linux/platform_device.h>
  10. #include <linux/regmap.h>
  11. #include <linux/reset-controller.h>
  12. #include <linux/slab.h>
  13. /* Configuration registers */
  14. #define SYSC_REG_SYSTEM_CONFIG 0x10
  15. #define SYSC_REG_CLKCFG0 0x2c
  16. #define SYSC_REG_RESET_CTRL 0x34
  17. #define SYSC_REG_CPU_SYS_CLKCFG 0x3c
  18. #define SYSC_REG_CPLL_CONFIG0 0x54
  19. #define SYSC_REG_CPLL_CONFIG1 0x58
  20. /* RT2880 SoC */
  21. #define RT2880_CONFIG_CPUCLK_SHIFT 20
  22. #define RT2880_CONFIG_CPUCLK_MASK 0x3
  23. #define RT2880_CONFIG_CPUCLK_250 0x0
  24. #define RT2880_CONFIG_CPUCLK_266 0x1
  25. #define RT2880_CONFIG_CPUCLK_280 0x2
  26. #define RT2880_CONFIG_CPUCLK_300 0x3
  27. /* RT305X SoC */
  28. #define RT305X_SYSCFG_CPUCLK_SHIFT 18
  29. #define RT305X_SYSCFG_CPUCLK_MASK 0x1
  30. #define RT305X_SYSCFG_CPUCLK_LOW 0x0
  31. #define RT305X_SYSCFG_CPUCLK_HIGH 0x1
  32. /* RT3352 SoC */
  33. #define RT3352_SYSCFG0_CPUCLK_SHIFT 8
  34. #define RT3352_SYSCFG0_CPUCLK_MASK 0x1
  35. #define RT3352_SYSCFG0_CPUCLK_LOW 0x0
  36. #define RT3352_SYSCFG0_CPUCLK_HIGH 0x1
  37. /* RT3383 SoC */
  38. #define RT3883_SYSCFG0_DRAM_TYPE_DDR2 BIT(17)
  39. #define RT3883_SYSCFG0_CPUCLK_SHIFT 8
  40. #define RT3883_SYSCFG0_CPUCLK_MASK 0x3
  41. #define RT3883_SYSCFG0_CPUCLK_250 0x0
  42. #define RT3883_SYSCFG0_CPUCLK_384 0x1
  43. #define RT3883_SYSCFG0_CPUCLK_480 0x2
  44. #define RT3883_SYSCFG0_CPUCLK_500 0x3
  45. /* RT5350 SoC */
  46. #define RT5350_CLKCFG0_XTAL_SEL BIT(20)
  47. #define RT5350_SYSCFG0_CPUCLK_SHIFT 8
  48. #define RT5350_SYSCFG0_CPUCLK_MASK 0x3
  49. #define RT5350_SYSCFG0_CPUCLK_360 0x0
  50. #define RT5350_SYSCFG0_CPUCLK_320 0x2
  51. #define RT5350_SYSCFG0_CPUCLK_300 0x3
  52. /* MT7620 and MT76x8 SoCs */
  53. #define MT7620_XTAL_FREQ_SEL BIT(6)
  54. #define CPLL_CFG0_SW_CFG BIT(31)
  55. #define CPLL_CFG0_PLL_MULT_RATIO_SHIFT 16
  56. #define CPLL_CFG0_PLL_MULT_RATIO_MASK 0x7
  57. #define CPLL_CFG0_LC_CURFCK BIT(15)
  58. #define CPLL_CFG0_BYPASS_REF_CLK BIT(14)
  59. #define CPLL_CFG0_PLL_DIV_RATIO_SHIFT 10
  60. #define CPLL_CFG0_PLL_DIV_RATIO_MASK 0x3
  61. #define CPLL_CFG1_CPU_AUX1 BIT(25)
  62. #define CPLL_CFG1_CPU_AUX0 BIT(24)
  63. #define CLKCFG0_PERI_CLK_SEL BIT(4)
  64. #define CPU_SYS_CLKCFG_OCP_RATIO_SHIFT 16
  65. #define CPU_SYS_CLKCFG_OCP_RATIO_MASK 0xf
  66. #define CPU_SYS_CLKCFG_OCP_RATIO_1 0 /* 1:1 (Reserved) */
  67. #define CPU_SYS_CLKCFG_OCP_RATIO_1_5 1 /* 1:1.5 (Reserved) */
  68. #define CPU_SYS_CLKCFG_OCP_RATIO_2 2 /* 1:2 */
  69. #define CPU_SYS_CLKCFG_OCP_RATIO_2_5 3 /* 1:2.5 (Reserved) */
  70. #define CPU_SYS_CLKCFG_OCP_RATIO_3 4 /* 1:3 */
  71. #define CPU_SYS_CLKCFG_OCP_RATIO_3_5 5 /* 1:3.5 (Reserved) */
  72. #define CPU_SYS_CLKCFG_OCP_RATIO_4 6 /* 1:4 */
  73. #define CPU_SYS_CLKCFG_OCP_RATIO_5 7 /* 1:5 */
  74. #define CPU_SYS_CLKCFG_OCP_RATIO_10 8 /* 1:10 */
  75. #define CPU_SYS_CLKCFG_CPU_FDIV_SHIFT 8
  76. #define CPU_SYS_CLKCFG_CPU_FDIV_MASK 0x1f
  77. #define CPU_SYS_CLKCFG_CPU_FFRAC_SHIFT 0
  78. #define CPU_SYS_CLKCFG_CPU_FFRAC_MASK 0x1f
  79. /* clock scaling */
  80. #define CLKCFG_FDIV_MASK 0x1f00
  81. #define CLKCFG_FDIV_USB_VAL 0x0300
  82. #define CLKCFG_FFRAC_MASK 0x001f
  83. #define CLKCFG_FFRAC_USB_VAL 0x0003
  84. struct mtmips_clk;
  85. struct mtmips_clk_fixed;
  86. struct mtmips_clk_factor;
  87. struct mtmips_clk_data {
  88. struct mtmips_clk *clk_base;
  89. size_t num_clk_base;
  90. struct mtmips_clk_fixed *clk_fixed;
  91. size_t num_clk_fixed;
  92. struct mtmips_clk_factor *clk_factor;
  93. size_t num_clk_factor;
  94. struct mtmips_clk *clk_periph;
  95. size_t num_clk_periph;
  96. };
  97. struct mtmips_clk_priv {
  98. struct regmap *sysc;
  99. const struct mtmips_clk_data *data;
  100. };
  101. struct mtmips_clk {
  102. struct clk_hw hw;
  103. struct mtmips_clk_priv *priv;
  104. };
  105. struct mtmips_clk_fixed {
  106. const char *name;
  107. const char *parent;
  108. unsigned long rate;
  109. struct clk_hw *hw;
  110. };
  111. struct mtmips_clk_factor {
  112. const char *name;
  113. const char *parent;
  114. int mult;
  115. int div;
  116. unsigned long flags;
  117. struct clk_hw *hw;
  118. };
  119. static unsigned long mtmips_pherip_clk_rate(struct clk_hw *hw,
  120. unsigned long parent_rate)
  121. {
  122. return parent_rate;
  123. }
  124. static const struct clk_ops mtmips_periph_clk_ops = {
  125. .recalc_rate = mtmips_pherip_clk_rate,
  126. };
  127. #define CLK_PERIPH(_name, _parent) { \
  128. .init = &(const struct clk_init_data) { \
  129. .name = _name, \
  130. .ops = &mtmips_periph_clk_ops, \
  131. .parent_data = &(const struct clk_parent_data) {\
  132. .name = _parent, \
  133. .fw_name = _parent \
  134. }, \
  135. .num_parents = 1, \
  136. /* \
  137. * There are drivers for these SoCs that are \
  138. * older than clock driver and are not prepared \
  139. * for the clock. We don't want the kernel to \
  140. * disable anything so we add CLK_IS_CRITICAL \
  141. * flag here. \
  142. */ \
  143. .flags = CLK_SET_RATE_PARENT | CLK_IS_CRITICAL \
  144. }, \
  145. }
  146. static struct mtmips_clk rt2880_pherip_clks[] = {
  147. { CLK_PERIPH("300100.timer", "bus") },
  148. { CLK_PERIPH("300120.watchdog", "bus") },
  149. { CLK_PERIPH("300500.uart", "bus") },
  150. { CLK_PERIPH("300900.i2c", "bus") },
  151. { CLK_PERIPH("300c00.uartlite", "bus") },
  152. { CLK_PERIPH("400000.ethernet", "bus") },
  153. { CLK_PERIPH("480000.wmac", "xtal") }
  154. };
  155. static struct mtmips_clk rt305x_pherip_clks[] = {
  156. { CLK_PERIPH("10000100.timer", "bus") },
  157. { CLK_PERIPH("10000120.watchdog", "bus") },
  158. { CLK_PERIPH("10000500.uart", "bus") },
  159. { CLK_PERIPH("10000900.i2c", "bus") },
  160. { CLK_PERIPH("10000a00.i2s", "bus") },
  161. { CLK_PERIPH("10000b00.spi", "bus") },
  162. { CLK_PERIPH("10000b40.spi", "bus") },
  163. { CLK_PERIPH("10000c00.uartlite", "bus") },
  164. { CLK_PERIPH("10100000.ethernet", "bus") },
  165. { CLK_PERIPH("10180000.wmac", "xtal") }
  166. };
  167. static struct mtmips_clk rt5350_pherip_clks[] = {
  168. { CLK_PERIPH("10000100.timer", "bus") },
  169. { CLK_PERIPH("10000120.watchdog", "bus") },
  170. { CLK_PERIPH("10000500.uart", "periph") },
  171. { CLK_PERIPH("10000900.i2c", "periph") },
  172. { CLK_PERIPH("10000a00.i2s", "periph") },
  173. { CLK_PERIPH("10000b00.spi", "bus") },
  174. { CLK_PERIPH("10000b40.spi", "bus") },
  175. { CLK_PERIPH("10000c00.uartlite", "periph") },
  176. { CLK_PERIPH("10100000.ethernet", "bus") },
  177. { CLK_PERIPH("10180000.wmac", "xtal") }
  178. };
  179. static struct mtmips_clk mt7620_pherip_clks[] = {
  180. { CLK_PERIPH("10000100.timer", "periph") },
  181. { CLK_PERIPH("10000120.watchdog", "periph") },
  182. { CLK_PERIPH("10000500.uart", "periph") },
  183. { CLK_PERIPH("10000900.i2c", "periph") },
  184. { CLK_PERIPH("10000a00.i2s", "periph") },
  185. { CLK_PERIPH("10000b00.spi", "bus") },
  186. { CLK_PERIPH("10000b40.spi", "bus") },
  187. { CLK_PERIPH("10000c00.uartlite", "periph") },
  188. { CLK_PERIPH("10130000.mmc", "sdhc") },
  189. { CLK_PERIPH("10180000.wmac", "xtal") }
  190. };
  191. static struct mtmips_clk mt76x8_pherip_clks[] = {
  192. { CLK_PERIPH("10000100.timer", "periph") },
  193. { CLK_PERIPH("10000120.watchdog", "periph") },
  194. { CLK_PERIPH("10000900.i2c", "periph") },
  195. { CLK_PERIPH("10000a00.i2s", "pcmi2s") },
  196. { CLK_PERIPH("10000b00.spi", "bus") },
  197. { CLK_PERIPH("10000b40.spi", "bus") },
  198. { CLK_PERIPH("10000c00.uart0", "periph") },
  199. { CLK_PERIPH("10000d00.uart1", "periph") },
  200. { CLK_PERIPH("10000e00.uart2", "periph") },
  201. { CLK_PERIPH("10130000.mmc", "sdhc") },
  202. { CLK_PERIPH("10300000.wmac", "xtal") }
  203. };
  204. static int mtmips_register_pherip_clocks(struct device_node *np,
  205. struct clk_hw_onecell_data *clk_data,
  206. struct mtmips_clk_priv *priv)
  207. {
  208. struct clk_hw **hws = clk_data->hws;
  209. struct mtmips_clk *sclk;
  210. size_t idx_start = priv->data->num_clk_base + priv->data->num_clk_fixed +
  211. priv->data->num_clk_factor;
  212. int ret, i;
  213. for (i = 0; i < priv->data->num_clk_periph; i++) {
  214. int idx = idx_start + i;
  215. sclk = &priv->data->clk_periph[i];
  216. ret = of_clk_hw_register(np, &sclk->hw);
  217. if (ret) {
  218. pr_err("Couldn't register peripheral clock %d\n", idx);
  219. goto err_clk_unreg;
  220. }
  221. hws[idx] = &sclk->hw;
  222. }
  223. return 0;
  224. err_clk_unreg:
  225. while (--i >= 0) {
  226. sclk = &priv->data->clk_periph[i];
  227. clk_hw_unregister(&sclk->hw);
  228. }
  229. return ret;
  230. }
  231. #define CLK_FIXED(_name, _parent, _rate) \
  232. { \
  233. .name = _name, \
  234. .parent = _parent, \
  235. .rate = _rate \
  236. }
  237. static struct mtmips_clk_fixed rt3883_fixed_clocks[] = {
  238. CLK_FIXED("periph", "xtal", 40000000)
  239. };
  240. static struct mtmips_clk_fixed rt3352_fixed_clocks[] = {
  241. CLK_FIXED("periph", "xtal", 40000000)
  242. };
  243. static struct mtmips_clk_fixed mt7620_fixed_clocks[] = {
  244. CLK_FIXED("bbppll", "xtal", 480000000)
  245. };
  246. static struct mtmips_clk_fixed mt76x8_fixed_clocks[] = {
  247. CLK_FIXED("bbppll", "xtal", 480000000),
  248. CLK_FIXED("pcmi2s", "bbppll", 480000000),
  249. CLK_FIXED("periph", "xtal", 40000000)
  250. };
  251. static int mtmips_register_fixed_clocks(struct clk_hw_onecell_data *clk_data,
  252. struct mtmips_clk_priv *priv)
  253. {
  254. struct clk_hw **hws = clk_data->hws;
  255. struct mtmips_clk_fixed *sclk;
  256. size_t idx_start = priv->data->num_clk_base;
  257. int ret, i;
  258. for (i = 0; i < priv->data->num_clk_fixed; i++) {
  259. int idx = idx_start + i;
  260. sclk = &priv->data->clk_fixed[i];
  261. sclk->hw = clk_hw_register_fixed_rate(NULL, sclk->name,
  262. sclk->parent, 0,
  263. sclk->rate);
  264. if (IS_ERR(sclk->hw)) {
  265. ret = PTR_ERR(sclk->hw);
  266. pr_err("Couldn't register fixed clock %d\n", idx);
  267. goto err_clk_unreg;
  268. }
  269. hws[idx] = sclk->hw;
  270. }
  271. return 0;
  272. err_clk_unreg:
  273. while (--i >= 0) {
  274. sclk = &priv->data->clk_fixed[i];
  275. clk_hw_unregister_fixed_rate(sclk->hw);
  276. }
  277. return ret;
  278. }
  279. #define CLK_FACTOR(_name, _parent, _mult, _div) \
  280. { \
  281. .name = _name, \
  282. .parent = _parent, \
  283. .mult = _mult, \
  284. .div = _div, \
  285. .flags = CLK_SET_RATE_PARENT \
  286. }
  287. static struct mtmips_clk_factor rt2880_factor_clocks[] = {
  288. CLK_FACTOR("bus", "cpu", 1, 2)
  289. };
  290. static struct mtmips_clk_factor rt305x_factor_clocks[] = {
  291. CLK_FACTOR("bus", "cpu", 1, 3)
  292. };
  293. static struct mtmips_clk_factor mt7620_factor_clocks[] = {
  294. CLK_FACTOR("sdhc", "bbppll", 1, 10)
  295. };
  296. static struct mtmips_clk_factor mt76x8_factor_clocks[] = {
  297. CLK_FACTOR("bus", "cpu", 1, 3),
  298. CLK_FACTOR("sdhc", "bbppll", 1, 10)
  299. };
  300. static int mtmips_register_factor_clocks(struct clk_hw_onecell_data *clk_data,
  301. struct mtmips_clk_priv *priv)
  302. {
  303. struct clk_hw **hws = clk_data->hws;
  304. struct mtmips_clk_factor *sclk;
  305. size_t idx_start = priv->data->num_clk_base + priv->data->num_clk_fixed;
  306. int ret, i;
  307. for (i = 0; i < priv->data->num_clk_factor; i++) {
  308. int idx = idx_start + i;
  309. sclk = &priv->data->clk_factor[i];
  310. sclk->hw = clk_hw_register_fixed_factor(NULL, sclk->name,
  311. sclk->parent, sclk->flags,
  312. sclk->mult, sclk->div);
  313. if (IS_ERR(sclk->hw)) {
  314. ret = PTR_ERR(sclk->hw);
  315. pr_err("Couldn't register factor clock %d\n", idx);
  316. goto err_clk_unreg;
  317. }
  318. hws[idx] = sclk->hw;
  319. }
  320. return 0;
  321. err_clk_unreg:
  322. while (--i >= 0) {
  323. sclk = &priv->data->clk_factor[i];
  324. clk_hw_unregister_fixed_factor(sclk->hw);
  325. }
  326. return ret;
  327. }
  328. static inline struct mtmips_clk *to_mtmips_clk(struct clk_hw *hw)
  329. {
  330. return container_of(hw, struct mtmips_clk, hw);
  331. }
  332. static unsigned long rt2880_xtal_recalc_rate(struct clk_hw *hw,
  333. unsigned long parent_rate)
  334. {
  335. return 40000000;
  336. }
  337. static unsigned long rt5350_xtal_recalc_rate(struct clk_hw *hw,
  338. unsigned long parent_rate)
  339. {
  340. struct mtmips_clk *clk = to_mtmips_clk(hw);
  341. struct regmap *sysc = clk->priv->sysc;
  342. u32 val;
  343. regmap_read(sysc, SYSC_REG_SYSTEM_CONFIG, &val);
  344. if (!(val & RT5350_CLKCFG0_XTAL_SEL))
  345. return 20000000;
  346. return 40000000;
  347. }
  348. static unsigned long rt5350_cpu_recalc_rate(struct clk_hw *hw,
  349. unsigned long xtal_clk)
  350. {
  351. struct mtmips_clk *clk = to_mtmips_clk(hw);
  352. struct regmap *sysc = clk->priv->sysc;
  353. u32 t;
  354. regmap_read(sysc, SYSC_REG_SYSTEM_CONFIG, &t);
  355. t = (t >> RT5350_SYSCFG0_CPUCLK_SHIFT) & RT5350_SYSCFG0_CPUCLK_MASK;
  356. switch (t) {
  357. case RT5350_SYSCFG0_CPUCLK_360:
  358. return 360000000;
  359. case RT5350_SYSCFG0_CPUCLK_320:
  360. return 320000000;
  361. case RT5350_SYSCFG0_CPUCLK_300:
  362. return 300000000;
  363. default:
  364. BUG();
  365. }
  366. }
  367. static unsigned long rt5350_bus_recalc_rate(struct clk_hw *hw,
  368. unsigned long parent_rate)
  369. {
  370. if (parent_rate == 320000000)
  371. return parent_rate / 4;
  372. return parent_rate / 3;
  373. }
  374. static unsigned long rt3352_cpu_recalc_rate(struct clk_hw *hw,
  375. unsigned long xtal_clk)
  376. {
  377. struct mtmips_clk *clk = to_mtmips_clk(hw);
  378. struct regmap *sysc = clk->priv->sysc;
  379. u32 t;
  380. regmap_read(sysc, SYSC_REG_SYSTEM_CONFIG, &t);
  381. t = (t >> RT3352_SYSCFG0_CPUCLK_SHIFT) & RT3352_SYSCFG0_CPUCLK_MASK;
  382. switch (t) {
  383. case RT3352_SYSCFG0_CPUCLK_LOW:
  384. return 384000000;
  385. case RT3352_SYSCFG0_CPUCLK_HIGH:
  386. return 400000000;
  387. default:
  388. BUG();
  389. }
  390. }
  391. static unsigned long rt305x_cpu_recalc_rate(struct clk_hw *hw,
  392. unsigned long xtal_clk)
  393. {
  394. struct mtmips_clk *clk = to_mtmips_clk(hw);
  395. struct regmap *sysc = clk->priv->sysc;
  396. u32 t;
  397. regmap_read(sysc, SYSC_REG_SYSTEM_CONFIG, &t);
  398. t = (t >> RT305X_SYSCFG_CPUCLK_SHIFT) & RT305X_SYSCFG_CPUCLK_MASK;
  399. switch (t) {
  400. case RT305X_SYSCFG_CPUCLK_LOW:
  401. return 320000000;
  402. case RT305X_SYSCFG_CPUCLK_HIGH:
  403. return 384000000;
  404. default:
  405. BUG();
  406. }
  407. }
  408. static unsigned long rt3883_cpu_recalc_rate(struct clk_hw *hw,
  409. unsigned long xtal_clk)
  410. {
  411. struct mtmips_clk *clk = to_mtmips_clk(hw);
  412. struct regmap *sysc = clk->priv->sysc;
  413. u32 t;
  414. regmap_read(sysc, SYSC_REG_SYSTEM_CONFIG, &t);
  415. t = (t >> RT3883_SYSCFG0_CPUCLK_SHIFT) & RT3883_SYSCFG0_CPUCLK_MASK;
  416. switch (t) {
  417. case RT3883_SYSCFG0_CPUCLK_250:
  418. return 250000000;
  419. case RT3883_SYSCFG0_CPUCLK_384:
  420. return 384000000;
  421. case RT3883_SYSCFG0_CPUCLK_480:
  422. return 480000000;
  423. case RT3883_SYSCFG0_CPUCLK_500:
  424. return 500000000;
  425. default:
  426. BUG();
  427. }
  428. }
  429. static unsigned long rt3883_bus_recalc_rate(struct clk_hw *hw,
  430. unsigned long parent_rate)
  431. {
  432. struct mtmips_clk *clk = to_mtmips_clk(hw);
  433. struct regmap *sysc = clk->priv->sysc;
  434. u32 ddr2;
  435. u32 t;
  436. regmap_read(sysc, SYSC_REG_SYSTEM_CONFIG, &t);
  437. ddr2 = t & RT3883_SYSCFG0_DRAM_TYPE_DDR2;
  438. switch (parent_rate) {
  439. case 250000000:
  440. return (ddr2) ? 125000000 : 83000000;
  441. case 384000000:
  442. return (ddr2) ? 128000000 : 96000000;
  443. case 480000000:
  444. return (ddr2) ? 160000000 : 120000000;
  445. case 500000000:
  446. return (ddr2) ? 166000000 : 125000000;
  447. default:
  448. WARN_ON_ONCE(parent_rate == 0);
  449. return parent_rate / 4;
  450. }
  451. }
  452. static unsigned long rt2880_cpu_recalc_rate(struct clk_hw *hw,
  453. unsigned long xtal_clk)
  454. {
  455. struct mtmips_clk *clk = to_mtmips_clk(hw);
  456. struct regmap *sysc = clk->priv->sysc;
  457. u32 t;
  458. regmap_read(sysc, SYSC_REG_SYSTEM_CONFIG, &t);
  459. t = (t >> RT2880_CONFIG_CPUCLK_SHIFT) & RT2880_CONFIG_CPUCLK_MASK;
  460. switch (t) {
  461. case RT2880_CONFIG_CPUCLK_250:
  462. return 250000000;
  463. case RT2880_CONFIG_CPUCLK_266:
  464. return 266000000;
  465. case RT2880_CONFIG_CPUCLK_280:
  466. return 280000000;
  467. case RT2880_CONFIG_CPUCLK_300:
  468. return 300000000;
  469. default:
  470. BUG();
  471. }
  472. }
  473. static u32 mt7620_calc_rate(u32 ref_rate, u32 mul, u32 div)
  474. {
  475. u64 t;
  476. t = ref_rate;
  477. t *= mul;
  478. t = div_u64(t, div);
  479. return t;
  480. }
  481. static unsigned long mt7620_pll_recalc_rate(struct clk_hw *hw,
  482. unsigned long parent_rate)
  483. {
  484. static const u32 clk_divider[] = { 2, 3, 4, 8 };
  485. struct mtmips_clk *clk = to_mtmips_clk(hw);
  486. struct regmap *sysc = clk->priv->sysc;
  487. unsigned long cpu_pll;
  488. u32 t;
  489. u32 mul;
  490. u32 div;
  491. regmap_read(sysc, SYSC_REG_CPLL_CONFIG0, &t);
  492. if (t & CPLL_CFG0_BYPASS_REF_CLK) {
  493. cpu_pll = parent_rate;
  494. } else if ((t & CPLL_CFG0_SW_CFG) == 0) {
  495. cpu_pll = 600000000;
  496. } else {
  497. mul = (t >> CPLL_CFG0_PLL_MULT_RATIO_SHIFT) &
  498. CPLL_CFG0_PLL_MULT_RATIO_MASK;
  499. mul += 24;
  500. if (t & CPLL_CFG0_LC_CURFCK)
  501. mul *= 2;
  502. div = (t >> CPLL_CFG0_PLL_DIV_RATIO_SHIFT) &
  503. CPLL_CFG0_PLL_DIV_RATIO_MASK;
  504. WARN_ON_ONCE(div >= ARRAY_SIZE(clk_divider));
  505. cpu_pll = mt7620_calc_rate(parent_rate, mul, clk_divider[div]);
  506. }
  507. regmap_read(sysc, SYSC_REG_CPLL_CONFIG1, &t);
  508. if (t & CPLL_CFG1_CPU_AUX1)
  509. return parent_rate;
  510. if (t & CPLL_CFG1_CPU_AUX0)
  511. return 480000000;
  512. return cpu_pll;
  513. }
  514. static unsigned long mt7620_cpu_recalc_rate(struct clk_hw *hw,
  515. unsigned long parent_rate)
  516. {
  517. struct mtmips_clk *clk = to_mtmips_clk(hw);
  518. struct regmap *sysc = clk->priv->sysc;
  519. u32 t;
  520. u32 mul;
  521. u32 div;
  522. regmap_read(sysc, SYSC_REG_CPU_SYS_CLKCFG, &t);
  523. mul = t & CPU_SYS_CLKCFG_CPU_FFRAC_MASK;
  524. div = (t >> CPU_SYS_CLKCFG_CPU_FDIV_SHIFT) &
  525. CPU_SYS_CLKCFG_CPU_FDIV_MASK;
  526. return mt7620_calc_rate(parent_rate, mul, div);
  527. }
  528. static unsigned long mt7620_bus_recalc_rate(struct clk_hw *hw,
  529. unsigned long parent_rate)
  530. {
  531. static const u32 ocp_dividers[16] = {
  532. [CPU_SYS_CLKCFG_OCP_RATIO_2] = 2,
  533. [CPU_SYS_CLKCFG_OCP_RATIO_3] = 3,
  534. [CPU_SYS_CLKCFG_OCP_RATIO_4] = 4,
  535. [CPU_SYS_CLKCFG_OCP_RATIO_5] = 5,
  536. [CPU_SYS_CLKCFG_OCP_RATIO_10] = 10,
  537. };
  538. struct mtmips_clk *clk = to_mtmips_clk(hw);
  539. struct regmap *sysc = clk->priv->sysc;
  540. u32 t;
  541. u32 ocp_ratio;
  542. u32 div;
  543. regmap_read(sysc, SYSC_REG_CPU_SYS_CLKCFG, &t);
  544. ocp_ratio = (t >> CPU_SYS_CLKCFG_OCP_RATIO_SHIFT) &
  545. CPU_SYS_CLKCFG_OCP_RATIO_MASK;
  546. if (WARN_ON_ONCE(ocp_ratio >= ARRAY_SIZE(ocp_dividers)))
  547. return parent_rate;
  548. div = ocp_dividers[ocp_ratio];
  549. if (WARN(!div, "invalid divider for OCP ratio %u", ocp_ratio))
  550. return parent_rate;
  551. return parent_rate / div;
  552. }
  553. static unsigned long mt7620_periph_recalc_rate(struct clk_hw *hw,
  554. unsigned long parent_rate)
  555. {
  556. struct mtmips_clk *clk = to_mtmips_clk(hw);
  557. struct regmap *sysc = clk->priv->sysc;
  558. u32 t;
  559. regmap_read(sysc, SYSC_REG_CLKCFG0, &t);
  560. if (t & CLKCFG0_PERI_CLK_SEL)
  561. return parent_rate;
  562. return 40000000;
  563. }
  564. static unsigned long mt76x8_xtal_recalc_rate(struct clk_hw *hw,
  565. unsigned long parent_rate)
  566. {
  567. struct mtmips_clk *clk = to_mtmips_clk(hw);
  568. struct regmap *sysc = clk->priv->sysc;
  569. u32 t;
  570. regmap_read(sysc, SYSC_REG_SYSTEM_CONFIG, &t);
  571. if (t & MT7620_XTAL_FREQ_SEL)
  572. return 40000000;
  573. return 20000000;
  574. }
  575. static unsigned long mt76x8_cpu_recalc_rate(struct clk_hw *hw,
  576. unsigned long xtal_clk)
  577. {
  578. if (xtal_clk == 40000000)
  579. return 580000000;
  580. return 575000000;
  581. }
  582. #define CLK_BASE(_name, _parent, _recalc) { \
  583. .init = &(const struct clk_init_data) { \
  584. .name = _name, \
  585. .ops = &(const struct clk_ops) { \
  586. .recalc_rate = _recalc, \
  587. }, \
  588. .parent_data = &(const struct clk_parent_data) { \
  589. .name = _parent, \
  590. .fw_name = _parent \
  591. }, \
  592. .num_parents = _parent ? 1 : 0 \
  593. }, \
  594. }
  595. static struct mtmips_clk rt2880_clks_base[] = {
  596. { CLK_BASE("xtal", NULL, rt2880_xtal_recalc_rate) },
  597. { CLK_BASE("cpu", "xtal", rt2880_cpu_recalc_rate) }
  598. };
  599. static struct mtmips_clk rt305x_clks_base[] = {
  600. { CLK_BASE("xtal", NULL, rt2880_xtal_recalc_rate) },
  601. { CLK_BASE("cpu", "xtal", rt305x_cpu_recalc_rate) }
  602. };
  603. static struct mtmips_clk rt3352_clks_base[] = {
  604. { CLK_BASE("xtal", NULL, rt5350_xtal_recalc_rate) },
  605. { CLK_BASE("cpu", "xtal", rt3352_cpu_recalc_rate) }
  606. };
  607. static struct mtmips_clk rt3883_clks_base[] = {
  608. { CLK_BASE("xtal", NULL, rt2880_xtal_recalc_rate) },
  609. { CLK_BASE("cpu", "xtal", rt3883_cpu_recalc_rate) },
  610. { CLK_BASE("bus", "cpu", rt3883_bus_recalc_rate) }
  611. };
  612. static struct mtmips_clk rt5350_clks_base[] = {
  613. { CLK_BASE("xtal", NULL, rt5350_xtal_recalc_rate) },
  614. { CLK_BASE("cpu", "xtal", rt5350_cpu_recalc_rate) },
  615. { CLK_BASE("bus", "cpu", rt5350_bus_recalc_rate) }
  616. };
  617. static struct mtmips_clk mt7620_clks_base[] = {
  618. { CLK_BASE("xtal", NULL, mt76x8_xtal_recalc_rate) },
  619. { CLK_BASE("pll", "xtal", mt7620_pll_recalc_rate) },
  620. { CLK_BASE("cpu", "pll", mt7620_cpu_recalc_rate) },
  621. { CLK_BASE("periph", "xtal", mt7620_periph_recalc_rate) },
  622. { CLK_BASE("bus", "cpu", mt7620_bus_recalc_rate) }
  623. };
  624. static struct mtmips_clk mt76x8_clks_base[] = {
  625. { CLK_BASE("xtal", NULL, mt76x8_xtal_recalc_rate) },
  626. { CLK_BASE("cpu", "xtal", mt76x8_cpu_recalc_rate) }
  627. };
  628. static int mtmips_register_clocks(struct device_node *np,
  629. struct clk_hw_onecell_data *clk_data,
  630. struct mtmips_clk_priv *priv)
  631. {
  632. struct clk_hw **hws = clk_data->hws;
  633. struct mtmips_clk *sclk;
  634. int ret, i;
  635. for (i = 0; i < priv->data->num_clk_base; i++) {
  636. sclk = &priv->data->clk_base[i];
  637. sclk->priv = priv;
  638. ret = of_clk_hw_register(np, &sclk->hw);
  639. if (ret) {
  640. pr_err("Couldn't register top clock %i\n", i);
  641. goto err_clk_unreg;
  642. }
  643. hws[i] = &sclk->hw;
  644. }
  645. return 0;
  646. err_clk_unreg:
  647. while (--i >= 0) {
  648. sclk = &priv->data->clk_base[i];
  649. clk_hw_unregister(&sclk->hw);
  650. }
  651. return ret;
  652. }
  653. static const struct mtmips_clk_data rt2880_clk_data = {
  654. .clk_base = rt2880_clks_base,
  655. .num_clk_base = ARRAY_SIZE(rt2880_clks_base),
  656. .clk_fixed = NULL,
  657. .num_clk_fixed = 0,
  658. .clk_factor = rt2880_factor_clocks,
  659. .num_clk_factor = ARRAY_SIZE(rt2880_factor_clocks),
  660. .clk_periph = rt2880_pherip_clks,
  661. .num_clk_periph = ARRAY_SIZE(rt2880_pherip_clks),
  662. };
  663. static const struct mtmips_clk_data rt305x_clk_data = {
  664. .clk_base = rt305x_clks_base,
  665. .num_clk_base = ARRAY_SIZE(rt305x_clks_base),
  666. .clk_fixed = NULL,
  667. .num_clk_fixed = 0,
  668. .clk_factor = rt305x_factor_clocks,
  669. .num_clk_factor = ARRAY_SIZE(rt305x_factor_clocks),
  670. .clk_periph = rt305x_pherip_clks,
  671. .num_clk_periph = ARRAY_SIZE(rt305x_pherip_clks),
  672. };
  673. static const struct mtmips_clk_data rt3352_clk_data = {
  674. .clk_base = rt3352_clks_base,
  675. .num_clk_base = ARRAY_SIZE(rt3352_clks_base),
  676. .clk_fixed = rt3352_fixed_clocks,
  677. .num_clk_fixed = ARRAY_SIZE(rt3352_fixed_clocks),
  678. .clk_factor = rt305x_factor_clocks,
  679. .num_clk_factor = ARRAY_SIZE(rt305x_factor_clocks),
  680. .clk_periph = rt5350_pherip_clks,
  681. .num_clk_periph = ARRAY_SIZE(rt5350_pherip_clks),
  682. };
  683. static const struct mtmips_clk_data rt3883_clk_data = {
  684. .clk_base = rt3883_clks_base,
  685. .num_clk_base = ARRAY_SIZE(rt3883_clks_base),
  686. .clk_fixed = rt3883_fixed_clocks,
  687. .num_clk_fixed = ARRAY_SIZE(rt3883_fixed_clocks),
  688. .clk_factor = NULL,
  689. .num_clk_factor = 0,
  690. .clk_periph = rt5350_pherip_clks,
  691. .num_clk_periph = ARRAY_SIZE(rt5350_pherip_clks),
  692. };
  693. static const struct mtmips_clk_data rt5350_clk_data = {
  694. .clk_base = rt5350_clks_base,
  695. .num_clk_base = ARRAY_SIZE(rt5350_clks_base),
  696. .clk_fixed = rt3352_fixed_clocks,
  697. .num_clk_fixed = ARRAY_SIZE(rt3352_fixed_clocks),
  698. .clk_factor = NULL,
  699. .num_clk_factor = 0,
  700. .clk_periph = rt5350_pherip_clks,
  701. .num_clk_periph = ARRAY_SIZE(rt5350_pherip_clks),
  702. };
  703. static const struct mtmips_clk_data mt7620_clk_data = {
  704. .clk_base = mt7620_clks_base,
  705. .num_clk_base = ARRAY_SIZE(mt7620_clks_base),
  706. .clk_fixed = mt7620_fixed_clocks,
  707. .num_clk_fixed = ARRAY_SIZE(mt7620_fixed_clocks),
  708. .clk_factor = mt7620_factor_clocks,
  709. .num_clk_factor = ARRAY_SIZE(mt7620_factor_clocks),
  710. .clk_periph = mt7620_pherip_clks,
  711. .num_clk_periph = ARRAY_SIZE(mt7620_pherip_clks),
  712. };
  713. static const struct mtmips_clk_data mt76x8_clk_data = {
  714. .clk_base = mt76x8_clks_base,
  715. .num_clk_base = ARRAY_SIZE(mt76x8_clks_base),
  716. .clk_fixed = mt76x8_fixed_clocks,
  717. .num_clk_fixed = ARRAY_SIZE(mt76x8_fixed_clocks),
  718. .clk_factor = mt76x8_factor_clocks,
  719. .num_clk_factor = ARRAY_SIZE(mt76x8_factor_clocks),
  720. .clk_periph = mt76x8_pherip_clks,
  721. .num_clk_periph = ARRAY_SIZE(mt76x8_pherip_clks),
  722. };
  723. static const struct of_device_id mtmips_of_match[] = {
  724. {
  725. .compatible = "ralink,rt2880-reset",
  726. .data = NULL,
  727. },
  728. {
  729. .compatible = "ralink,rt2880-sysc",
  730. .data = &rt2880_clk_data,
  731. },
  732. {
  733. .compatible = "ralink,rt3050-sysc",
  734. .data = &rt305x_clk_data,
  735. },
  736. {
  737. .compatible = "ralink,rt3052-sysc",
  738. .data = &rt305x_clk_data,
  739. },
  740. {
  741. .compatible = "ralink,rt3352-sysc",
  742. .data = &rt3352_clk_data,
  743. },
  744. {
  745. .compatible = "ralink,rt3883-sysc",
  746. .data = &rt3883_clk_data,
  747. },
  748. {
  749. .compatible = "ralink,rt5350-sysc",
  750. .data = &rt5350_clk_data,
  751. },
  752. {
  753. .compatible = "ralink,mt7620-sysc",
  754. .data = &mt7620_clk_data,
  755. },
  756. {
  757. .compatible = "ralink,mt7628-sysc",
  758. .data = &mt76x8_clk_data,
  759. },
  760. {
  761. .compatible = "ralink,mt7688-sysc",
  762. .data = &mt76x8_clk_data,
  763. },
  764. {}
  765. };
  766. static void __init mtmips_clk_regs_init(struct device_node *node,
  767. struct mtmips_clk_priv *priv)
  768. {
  769. u32 t;
  770. if (!of_device_is_compatible(node, "ralink,mt7620-sysc"))
  771. return;
  772. /*
  773. * When the CPU goes into sleep mode, the BUS
  774. * clock will be too low for USB to function properly.
  775. * Adjust the busses fractional divider to fix this
  776. */
  777. regmap_read(priv->sysc, SYSC_REG_CPU_SYS_CLKCFG, &t);
  778. t &= ~(CLKCFG_FDIV_MASK | CLKCFG_FFRAC_MASK);
  779. t |= CLKCFG_FDIV_USB_VAL | CLKCFG_FFRAC_USB_VAL;
  780. regmap_write(priv->sysc, SYSC_REG_CPU_SYS_CLKCFG, t);
  781. }
  782. static void __init mtmips_clk_init(struct device_node *node)
  783. {
  784. const struct of_device_id *match;
  785. const struct mtmips_clk_data *data;
  786. struct mtmips_clk_priv *priv;
  787. struct clk_hw_onecell_data *clk_data;
  788. int ret, i, count;
  789. priv = kzalloc_obj(*priv);
  790. if (!priv)
  791. return;
  792. priv->sysc = syscon_node_to_regmap(node);
  793. if (IS_ERR(priv->sysc)) {
  794. pr_err("Could not get sysc syscon regmap\n");
  795. goto free_clk_priv;
  796. }
  797. mtmips_clk_regs_init(node, priv);
  798. match = of_match_node(mtmips_of_match, node);
  799. if (WARN_ON(!match))
  800. return;
  801. data = match->data;
  802. priv->data = data;
  803. count = priv->data->num_clk_base + priv->data->num_clk_fixed +
  804. priv->data->num_clk_factor + priv->data->num_clk_periph;
  805. clk_data = kzalloc_flex(*clk_data, hws, count);
  806. if (!clk_data)
  807. goto free_clk_priv;
  808. ret = mtmips_register_clocks(node, clk_data, priv);
  809. if (ret) {
  810. pr_err("Couldn't register top clocks\n");
  811. goto free_clk_data;
  812. }
  813. ret = mtmips_register_fixed_clocks(clk_data, priv);
  814. if (ret) {
  815. pr_err("Couldn't register fixed clocks\n");
  816. goto unreg_clk_top;
  817. }
  818. ret = mtmips_register_factor_clocks(clk_data, priv);
  819. if (ret) {
  820. pr_err("Couldn't register factor clocks\n");
  821. goto unreg_clk_fixed;
  822. }
  823. ret = mtmips_register_pherip_clocks(node, clk_data, priv);
  824. if (ret) {
  825. pr_err("Couldn't register peripheral clocks\n");
  826. goto unreg_clk_factor;
  827. }
  828. clk_data->num = count;
  829. ret = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  830. if (ret) {
  831. pr_err("Couldn't add clk hw provider\n");
  832. goto unreg_clk_periph;
  833. }
  834. return;
  835. unreg_clk_periph:
  836. for (i = 0; i < priv->data->num_clk_periph; i++) {
  837. struct mtmips_clk *sclk = &priv->data->clk_periph[i];
  838. clk_hw_unregister(&sclk->hw);
  839. }
  840. unreg_clk_factor:
  841. for (i = 0; i < priv->data->num_clk_factor; i++) {
  842. struct mtmips_clk_factor *sclk = &priv->data->clk_factor[i];
  843. clk_hw_unregister_fixed_factor(sclk->hw);
  844. }
  845. unreg_clk_fixed:
  846. for (i = 0; i < priv->data->num_clk_fixed; i++) {
  847. struct mtmips_clk_fixed *sclk = &priv->data->clk_fixed[i];
  848. clk_hw_unregister_fixed_rate(sclk->hw);
  849. }
  850. unreg_clk_top:
  851. for (i = 0; i < priv->data->num_clk_base; i++) {
  852. struct mtmips_clk *sclk = &priv->data->clk_base[i];
  853. clk_hw_unregister(&sclk->hw);
  854. }
  855. free_clk_data:
  856. kfree(clk_data);
  857. free_clk_priv:
  858. kfree(priv);
  859. }
  860. CLK_OF_DECLARE_DRIVER(rt2880_clk, "ralink,rt2880-sysc", mtmips_clk_init);
  861. CLK_OF_DECLARE_DRIVER(rt3050_clk, "ralink,rt3050-sysc", mtmips_clk_init);
  862. CLK_OF_DECLARE_DRIVER(rt3052_clk, "ralink,rt3052-sysc", mtmips_clk_init);
  863. CLK_OF_DECLARE_DRIVER(rt3352_clk, "ralink,rt3352-sysc", mtmips_clk_init);
  864. CLK_OF_DECLARE_DRIVER(rt3883_clk, "ralink,rt3883-sysc", mtmips_clk_init);
  865. CLK_OF_DECLARE_DRIVER(rt5350_clk, "ralink,rt5350-sysc", mtmips_clk_init);
  866. CLK_OF_DECLARE_DRIVER(mt7620_clk, "ralink,mt7620-sysc", mtmips_clk_init);
  867. CLK_OF_DECLARE_DRIVER(mt7628_clk, "ralink,mt7628-sysc", mtmips_clk_init);
  868. CLK_OF_DECLARE_DRIVER(mt7688_clk, "ralink,mt7688-sysc", mtmips_clk_init);
  869. struct mtmips_rst {
  870. struct reset_controller_dev rcdev;
  871. struct regmap *sysc;
  872. };
  873. static struct mtmips_rst *to_mtmips_rst(struct reset_controller_dev *dev)
  874. {
  875. return container_of(dev, struct mtmips_rst, rcdev);
  876. }
  877. static int mtmips_assert_device(struct reset_controller_dev *rcdev,
  878. unsigned long id)
  879. {
  880. struct mtmips_rst *data = to_mtmips_rst(rcdev);
  881. struct regmap *sysc = data->sysc;
  882. return regmap_update_bits(sysc, SYSC_REG_RESET_CTRL, BIT(id), BIT(id));
  883. }
  884. static int mtmips_deassert_device(struct reset_controller_dev *rcdev,
  885. unsigned long id)
  886. {
  887. struct mtmips_rst *data = to_mtmips_rst(rcdev);
  888. struct regmap *sysc = data->sysc;
  889. return regmap_update_bits(sysc, SYSC_REG_RESET_CTRL, BIT(id), 0);
  890. }
  891. static int mtmips_reset_device(struct reset_controller_dev *rcdev,
  892. unsigned long id)
  893. {
  894. int ret;
  895. ret = mtmips_assert_device(rcdev, id);
  896. if (ret < 0)
  897. return ret;
  898. return mtmips_deassert_device(rcdev, id);
  899. }
  900. static int mtmips_rst_xlate(struct reset_controller_dev *rcdev,
  901. const struct of_phandle_args *reset_spec)
  902. {
  903. unsigned long id = reset_spec->args[0];
  904. if (id == 0 || id >= rcdev->nr_resets)
  905. return -EINVAL;
  906. return id;
  907. }
  908. static const struct reset_control_ops reset_ops = {
  909. .reset = mtmips_reset_device,
  910. .assert = mtmips_assert_device,
  911. .deassert = mtmips_deassert_device
  912. };
  913. static int mtmips_reset_init(struct device *dev, struct regmap *sysc)
  914. {
  915. struct mtmips_rst *rst_data;
  916. rst_data = devm_kzalloc(dev, sizeof(*rst_data), GFP_KERNEL);
  917. if (!rst_data)
  918. return -ENOMEM;
  919. rst_data->sysc = sysc;
  920. rst_data->rcdev.ops = &reset_ops;
  921. rst_data->rcdev.owner = THIS_MODULE;
  922. rst_data->rcdev.nr_resets = 32;
  923. rst_data->rcdev.of_reset_n_cells = 1;
  924. rst_data->rcdev.of_xlate = mtmips_rst_xlate;
  925. rst_data->rcdev.of_node = dev_of_node(dev);
  926. return devm_reset_controller_register(dev, &rst_data->rcdev);
  927. }
  928. static int mtmips_clk_probe(struct platform_device *pdev)
  929. {
  930. struct device_node *np = pdev->dev.of_node;
  931. struct device *dev = &pdev->dev;
  932. struct mtmips_clk_priv *priv;
  933. int ret;
  934. priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
  935. if (!priv)
  936. return -ENOMEM;
  937. priv->sysc = syscon_node_to_regmap(np);
  938. if (IS_ERR(priv->sysc))
  939. return dev_err_probe(dev, PTR_ERR(priv->sysc),
  940. "Could not get sysc syscon regmap\n");
  941. ret = mtmips_reset_init(dev, priv->sysc);
  942. if (ret)
  943. return dev_err_probe(dev, ret, "Could not init reset controller\n");
  944. return 0;
  945. }
  946. static struct platform_driver mtmips_clk_driver = {
  947. .probe = mtmips_clk_probe,
  948. .driver = {
  949. .name = "mtmips-clk",
  950. .of_match_table = mtmips_of_match,
  951. },
  952. };
  953. static int __init mtmips_clk_reset_init(void)
  954. {
  955. return platform_driver_register(&mtmips_clk_driver);
  956. }
  957. arch_initcall(mtmips_clk_reset_init);