sifive-prci.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2020 SiFive, Inc.
  4. * Copyright (C) 2020 Zong Li
  5. */
  6. #include <linux/clkdev.h>
  7. #include <linux/delay.h>
  8. #include <linux/io.h>
  9. #include <linux/of_device.h>
  10. #include "sifive-prci.h"
  11. #include "fu540-prci.h"
  12. #include "fu740-prci.h"
  13. /*
  14. * Private functions
  15. */
  16. /**
  17. * __prci_readl() - read from a PRCI register
  18. * @pd: PRCI context
  19. * @offs: register offset to read from (in bytes, from PRCI base address)
  20. *
  21. * Read the register located at offset @offs from the base virtual
  22. * address of the PRCI register target described by @pd, and return
  23. * the value to the caller.
  24. *
  25. * Context: Any context.
  26. *
  27. * Return: the contents of the register described by @pd and @offs.
  28. */
  29. static u32 __prci_readl(struct __prci_data *pd, u32 offs)
  30. {
  31. return readl_relaxed(pd->va + offs);
  32. }
  33. static void __prci_writel(u32 v, u32 offs, struct __prci_data *pd)
  34. {
  35. writel_relaxed(v, pd->va + offs);
  36. }
  37. /* WRPLL-related private functions */
  38. /**
  39. * __prci_wrpll_unpack() - unpack WRPLL configuration registers into parameters
  40. * @c: ptr to a struct wrpll_cfg record to write config into
  41. * @r: value read from the PRCI PLL configuration register
  42. *
  43. * Given a value @r read from an FU740 PRCI PLL configuration register,
  44. * split it into fields and populate it into the WRPLL configuration record
  45. * pointed to by @c.
  46. *
  47. * The COREPLLCFG0 macros are used below, but the other *PLLCFG0 macros
  48. * have the same register layout.
  49. *
  50. * Context: Any context.
  51. */
  52. static void __prci_wrpll_unpack(struct wrpll_cfg *c, u32 r)
  53. {
  54. u32 v;
  55. v = r & PRCI_COREPLLCFG0_DIVR_MASK;
  56. v >>= PRCI_COREPLLCFG0_DIVR_SHIFT;
  57. c->divr = v;
  58. v = r & PRCI_COREPLLCFG0_DIVF_MASK;
  59. v >>= PRCI_COREPLLCFG0_DIVF_SHIFT;
  60. c->divf = v;
  61. v = r & PRCI_COREPLLCFG0_DIVQ_MASK;
  62. v >>= PRCI_COREPLLCFG0_DIVQ_SHIFT;
  63. c->divq = v;
  64. v = r & PRCI_COREPLLCFG0_RANGE_MASK;
  65. v >>= PRCI_COREPLLCFG0_RANGE_SHIFT;
  66. c->range = v;
  67. c->flags &=
  68. (WRPLL_FLAGS_INT_FEEDBACK_MASK | WRPLL_FLAGS_EXT_FEEDBACK_MASK);
  69. /* external feedback mode not supported */
  70. c->flags |= WRPLL_FLAGS_INT_FEEDBACK_MASK;
  71. }
  72. /**
  73. * __prci_wrpll_pack() - pack PLL configuration parameters into a register value
  74. * @c: pointer to a struct wrpll_cfg record containing the PLL's cfg
  75. *
  76. * Using a set of WRPLL configuration values pointed to by @c,
  77. * assemble a PRCI PLL configuration register value, and return it to
  78. * the caller.
  79. *
  80. * Context: Any context. Caller must ensure that the contents of the
  81. * record pointed to by @c do not change during the execution
  82. * of this function.
  83. *
  84. * Returns: a value suitable for writing into a PRCI PLL configuration
  85. * register
  86. */
  87. static u32 __prci_wrpll_pack(const struct wrpll_cfg *c)
  88. {
  89. u32 r = 0;
  90. r |= c->divr << PRCI_COREPLLCFG0_DIVR_SHIFT;
  91. r |= c->divf << PRCI_COREPLLCFG0_DIVF_SHIFT;
  92. r |= c->divq << PRCI_COREPLLCFG0_DIVQ_SHIFT;
  93. r |= c->range << PRCI_COREPLLCFG0_RANGE_SHIFT;
  94. /* external feedback mode not supported */
  95. r |= PRCI_COREPLLCFG0_FSE_MASK;
  96. return r;
  97. }
  98. /**
  99. * __prci_wrpll_read_cfg0() - read the WRPLL configuration from the PRCI
  100. * @pd: PRCI context
  101. * @pwd: PRCI WRPLL metadata
  102. *
  103. * Read the current configuration of the PLL identified by @pwd from
  104. * the PRCI identified by @pd, and store it into the local configuration
  105. * cache in @pwd.
  106. *
  107. * Context: Any context. Caller must prevent the records pointed to by
  108. * @pd and @pwd from changing during execution.
  109. */
  110. static void __prci_wrpll_read_cfg0(struct __prci_data *pd,
  111. struct __prci_wrpll_data *pwd)
  112. {
  113. __prci_wrpll_unpack(&pwd->c, __prci_readl(pd, pwd->cfg0_offs));
  114. }
  115. /**
  116. * __prci_wrpll_write_cfg0() - write WRPLL configuration into the PRCI
  117. * @pd: PRCI context
  118. * @pwd: PRCI WRPLL metadata
  119. * @c: WRPLL configuration record to write
  120. *
  121. * Write the WRPLL configuration described by @c into the WRPLL
  122. * configuration register identified by @pwd in the PRCI instance
  123. * described by @c. Make a cached copy of the WRPLL's current
  124. * configuration so it can be used by other code.
  125. *
  126. * Context: Any context. Caller must prevent the records pointed to by
  127. * @pd and @pwd from changing during execution.
  128. */
  129. static void __prci_wrpll_write_cfg0(struct __prci_data *pd,
  130. struct __prci_wrpll_data *pwd,
  131. struct wrpll_cfg *c)
  132. {
  133. __prci_writel(__prci_wrpll_pack(c), pwd->cfg0_offs, pd);
  134. memcpy(&pwd->c, c, sizeof(*c));
  135. }
  136. /**
  137. * __prci_wrpll_write_cfg1() - write Clock enable/disable configuration
  138. * into the PRCI
  139. * @pd: PRCI context
  140. * @pwd: PRCI WRPLL metadata
  141. * @enable: Clock enable or disable value
  142. */
  143. static void __prci_wrpll_write_cfg1(struct __prci_data *pd,
  144. struct __prci_wrpll_data *pwd,
  145. u32 enable)
  146. {
  147. __prci_writel(enable, pwd->cfg1_offs, pd);
  148. }
  149. /*
  150. * Linux clock framework integration
  151. *
  152. * See the Linux clock framework documentation for more information on
  153. * these functions.
  154. */
  155. unsigned long sifive_prci_wrpll_recalc_rate(struct clk_hw *hw,
  156. unsigned long parent_rate)
  157. {
  158. struct __prci_clock *pc = clk_hw_to_prci_clock(hw);
  159. struct __prci_wrpll_data *pwd = pc->pwd;
  160. return wrpll_calc_output_rate(&pwd->c, parent_rate);
  161. }
  162. long sifive_prci_wrpll_round_rate(struct clk_hw *hw,
  163. unsigned long rate,
  164. unsigned long *parent_rate)
  165. {
  166. struct __prci_clock *pc = clk_hw_to_prci_clock(hw);
  167. struct __prci_wrpll_data *pwd = pc->pwd;
  168. struct wrpll_cfg c;
  169. memcpy(&c, &pwd->c, sizeof(c));
  170. wrpll_configure_for_rate(&c, rate, *parent_rate);
  171. return wrpll_calc_output_rate(&c, *parent_rate);
  172. }
  173. int sifive_prci_wrpll_set_rate(struct clk_hw *hw,
  174. unsigned long rate, unsigned long parent_rate)
  175. {
  176. struct __prci_clock *pc = clk_hw_to_prci_clock(hw);
  177. struct __prci_wrpll_data *pwd = pc->pwd;
  178. struct __prci_data *pd = pc->pd;
  179. int r;
  180. r = wrpll_configure_for_rate(&pwd->c, rate, parent_rate);
  181. if (r)
  182. return r;
  183. if (pwd->enable_bypass)
  184. pwd->enable_bypass(pd);
  185. __prci_wrpll_write_cfg0(pd, pwd, &pwd->c);
  186. udelay(wrpll_calc_max_lock_us(&pwd->c));
  187. return 0;
  188. }
  189. int sifive_clk_is_enabled(struct clk_hw *hw)
  190. {
  191. struct __prci_clock *pc = clk_hw_to_prci_clock(hw);
  192. struct __prci_wrpll_data *pwd = pc->pwd;
  193. struct __prci_data *pd = pc->pd;
  194. u32 r;
  195. r = __prci_readl(pd, pwd->cfg1_offs);
  196. if (r & PRCI_COREPLLCFG1_CKE_MASK)
  197. return 1;
  198. else
  199. return 0;
  200. }
  201. int sifive_prci_clock_enable(struct clk_hw *hw)
  202. {
  203. struct __prci_clock *pc = clk_hw_to_prci_clock(hw);
  204. struct __prci_wrpll_data *pwd = pc->pwd;
  205. struct __prci_data *pd = pc->pd;
  206. if (sifive_clk_is_enabled(hw))
  207. return 0;
  208. __prci_wrpll_write_cfg1(pd, pwd, PRCI_COREPLLCFG1_CKE_MASK);
  209. if (pwd->disable_bypass)
  210. pwd->disable_bypass(pd);
  211. return 0;
  212. }
  213. void sifive_prci_clock_disable(struct clk_hw *hw)
  214. {
  215. struct __prci_clock *pc = clk_hw_to_prci_clock(hw);
  216. struct __prci_wrpll_data *pwd = pc->pwd;
  217. struct __prci_data *pd = pc->pd;
  218. u32 r;
  219. if (pwd->enable_bypass)
  220. pwd->enable_bypass(pd);
  221. r = __prci_readl(pd, pwd->cfg1_offs);
  222. r &= ~PRCI_COREPLLCFG1_CKE_MASK;
  223. __prci_wrpll_write_cfg1(pd, pwd, r);
  224. }
  225. /* TLCLKSEL clock integration */
  226. unsigned long sifive_prci_tlclksel_recalc_rate(struct clk_hw *hw,
  227. unsigned long parent_rate)
  228. {
  229. struct __prci_clock *pc = clk_hw_to_prci_clock(hw);
  230. struct __prci_data *pd = pc->pd;
  231. u32 v;
  232. u8 div;
  233. v = __prci_readl(pd, PRCI_CLKMUXSTATUSREG_OFFSET);
  234. v &= PRCI_CLKMUXSTATUSREG_TLCLKSEL_STATUS_MASK;
  235. div = v ? 1 : 2;
  236. return div_u64(parent_rate, div);
  237. }
  238. /* HFPCLK clock integration */
  239. unsigned long sifive_prci_hfpclkplldiv_recalc_rate(struct clk_hw *hw,
  240. unsigned long parent_rate)
  241. {
  242. struct __prci_clock *pc = clk_hw_to_prci_clock(hw);
  243. struct __prci_data *pd = pc->pd;
  244. u32 div = __prci_readl(pd, PRCI_HFPCLKPLLDIV_OFFSET);
  245. return div_u64(parent_rate, div + 2);
  246. }
  247. /*
  248. * Core clock mux control
  249. */
  250. /**
  251. * sifive_prci_coreclksel_use_hfclk() - switch the CORECLK mux to output HFCLK
  252. * @pd: struct __prci_data * for the PRCI containing the CORECLK mux reg
  253. *
  254. * Switch the CORECLK mux to the HFCLK input source; return once complete.
  255. *
  256. * Context: Any context. Caller must prevent concurrent changes to the
  257. * PRCI_CORECLKSEL_OFFSET register.
  258. */
  259. void sifive_prci_coreclksel_use_hfclk(struct __prci_data *pd)
  260. {
  261. u32 r;
  262. r = __prci_readl(pd, PRCI_CORECLKSEL_OFFSET);
  263. r |= PRCI_CORECLKSEL_CORECLKSEL_MASK;
  264. __prci_writel(r, PRCI_CORECLKSEL_OFFSET, pd);
  265. r = __prci_readl(pd, PRCI_CORECLKSEL_OFFSET); /* barrier */
  266. }
  267. /**
  268. * sifive_prci_coreclksel_use_corepll() - switch the CORECLK mux to output
  269. * COREPLL
  270. * @pd: struct __prci_data * for the PRCI containing the CORECLK mux reg
  271. *
  272. * Switch the CORECLK mux to the COREPLL output clock; return once complete.
  273. *
  274. * Context: Any context. Caller must prevent concurrent changes to the
  275. * PRCI_CORECLKSEL_OFFSET register.
  276. */
  277. void sifive_prci_coreclksel_use_corepll(struct __prci_data *pd)
  278. {
  279. u32 r;
  280. r = __prci_readl(pd, PRCI_CORECLKSEL_OFFSET);
  281. r &= ~PRCI_CORECLKSEL_CORECLKSEL_MASK;
  282. __prci_writel(r, PRCI_CORECLKSEL_OFFSET, pd);
  283. r = __prci_readl(pd, PRCI_CORECLKSEL_OFFSET); /* barrier */
  284. }
  285. /**
  286. * sifive_prci_coreclksel_use_final_corepll() - switch the CORECLK mux to output
  287. * FINAL_COREPLL
  288. * @pd: struct __prci_data * for the PRCI containing the CORECLK mux reg
  289. *
  290. * Switch the CORECLK mux to the final COREPLL output clock; return once
  291. * complete.
  292. *
  293. * Context: Any context. Caller must prevent concurrent changes to the
  294. * PRCI_CORECLKSEL_OFFSET register.
  295. */
  296. void sifive_prci_coreclksel_use_final_corepll(struct __prci_data *pd)
  297. {
  298. u32 r;
  299. r = __prci_readl(pd, PRCI_CORECLKSEL_OFFSET);
  300. r &= ~PRCI_CORECLKSEL_CORECLKSEL_MASK;
  301. __prci_writel(r, PRCI_CORECLKSEL_OFFSET, pd);
  302. r = __prci_readl(pd, PRCI_CORECLKSEL_OFFSET); /* barrier */
  303. }
  304. /**
  305. * sifive_prci_corepllsel_use_dvfscorepll() - switch the COREPLL mux to
  306. * output DVFS_COREPLL
  307. * @pd: struct __prci_data * for the PRCI containing the COREPLL mux reg
  308. *
  309. * Switch the COREPLL mux to the DVFSCOREPLL output clock; return once complete.
  310. *
  311. * Context: Any context. Caller must prevent concurrent changes to the
  312. * PRCI_COREPLLSEL_OFFSET register.
  313. */
  314. void sifive_prci_corepllsel_use_dvfscorepll(struct __prci_data *pd)
  315. {
  316. u32 r;
  317. r = __prci_readl(pd, PRCI_COREPLLSEL_OFFSET);
  318. r |= PRCI_COREPLLSEL_COREPLLSEL_MASK;
  319. __prci_writel(r, PRCI_COREPLLSEL_OFFSET, pd);
  320. r = __prci_readl(pd, PRCI_COREPLLSEL_OFFSET); /* barrier */
  321. }
  322. /**
  323. * sifive_prci_corepllsel_use_corepll() - switch the COREPLL mux to
  324. * output COREPLL
  325. * @pd: struct __prci_data * for the PRCI containing the COREPLL mux reg
  326. *
  327. * Switch the COREPLL mux to the COREPLL output clock; return once complete.
  328. *
  329. * Context: Any context. Caller must prevent concurrent changes to the
  330. * PRCI_COREPLLSEL_OFFSET register.
  331. */
  332. void sifive_prci_corepllsel_use_corepll(struct __prci_data *pd)
  333. {
  334. u32 r;
  335. r = __prci_readl(pd, PRCI_COREPLLSEL_OFFSET);
  336. r &= ~PRCI_COREPLLSEL_COREPLLSEL_MASK;
  337. __prci_writel(r, PRCI_COREPLLSEL_OFFSET, pd);
  338. r = __prci_readl(pd, PRCI_COREPLLSEL_OFFSET); /* barrier */
  339. }
  340. /**
  341. * sifive_prci_hfpclkpllsel_use_hfclk() - switch the HFPCLKPLL mux to
  342. * output HFCLK
  343. * @pd: struct __prci_data * for the PRCI containing the HFPCLKPLL mux reg
  344. *
  345. * Switch the HFPCLKPLL mux to the HFCLK input source; return once complete.
  346. *
  347. * Context: Any context. Caller must prevent concurrent changes to the
  348. * PRCI_HFPCLKPLLSEL_OFFSET register.
  349. */
  350. void sifive_prci_hfpclkpllsel_use_hfclk(struct __prci_data *pd)
  351. {
  352. u32 r;
  353. r = __prci_readl(pd, PRCI_HFPCLKPLLSEL_OFFSET);
  354. r |= PRCI_HFPCLKPLLSEL_HFPCLKPLLSEL_MASK;
  355. __prci_writel(r, PRCI_HFPCLKPLLSEL_OFFSET, pd);
  356. r = __prci_readl(pd, PRCI_HFPCLKPLLSEL_OFFSET); /* barrier */
  357. }
  358. /**
  359. * sifive_prci_hfpclkpllsel_use_hfpclkpll() - switch the HFPCLKPLL mux to
  360. * output HFPCLKPLL
  361. * @pd: struct __prci_data * for the PRCI containing the HFPCLKPLL mux reg
  362. *
  363. * Switch the HFPCLKPLL mux to the HFPCLKPLL output clock; return once complete.
  364. *
  365. * Context: Any context. Caller must prevent concurrent changes to the
  366. * PRCI_HFPCLKPLLSEL_OFFSET register.
  367. */
  368. void sifive_prci_hfpclkpllsel_use_hfpclkpll(struct __prci_data *pd)
  369. {
  370. u32 r;
  371. r = __prci_readl(pd, PRCI_HFPCLKPLLSEL_OFFSET);
  372. r &= ~PRCI_HFPCLKPLLSEL_HFPCLKPLLSEL_MASK;
  373. __prci_writel(r, PRCI_HFPCLKPLLSEL_OFFSET, pd);
  374. r = __prci_readl(pd, PRCI_HFPCLKPLLSEL_OFFSET); /* barrier */
  375. }
  376. /* PCIE AUX clock APIs for enable, disable. */
  377. int sifive_prci_pcie_aux_clock_is_enabled(struct clk_hw *hw)
  378. {
  379. struct __prci_clock *pc = clk_hw_to_prci_clock(hw);
  380. struct __prci_data *pd = pc->pd;
  381. u32 r;
  382. r = __prci_readl(pd, PRCI_PCIE_AUX_OFFSET);
  383. if (r & PRCI_PCIE_AUX_EN_MASK)
  384. return 1;
  385. else
  386. return 0;
  387. }
  388. int sifive_prci_pcie_aux_clock_enable(struct clk_hw *hw)
  389. {
  390. struct __prci_clock *pc = clk_hw_to_prci_clock(hw);
  391. struct __prci_data *pd = pc->pd;
  392. u32 r __maybe_unused;
  393. if (sifive_prci_pcie_aux_clock_is_enabled(hw))
  394. return 0;
  395. __prci_writel(1, PRCI_PCIE_AUX_OFFSET, pd);
  396. r = __prci_readl(pd, PRCI_PCIE_AUX_OFFSET); /* barrier */
  397. return 0;
  398. }
  399. void sifive_prci_pcie_aux_clock_disable(struct clk_hw *hw)
  400. {
  401. struct __prci_clock *pc = clk_hw_to_prci_clock(hw);
  402. struct __prci_data *pd = pc->pd;
  403. u32 r __maybe_unused;
  404. __prci_writel(0, PRCI_PCIE_AUX_OFFSET, pd);
  405. r = __prci_readl(pd, PRCI_PCIE_AUX_OFFSET); /* barrier */
  406. }
  407. /**
  408. * __prci_register_clocks() - register clock controls in the PRCI
  409. * @dev: Linux struct device
  410. * @pd: The pointer for PRCI per-device instance data
  411. * @desc: The pointer for the information of clocks of each SoCs
  412. *
  413. * Register the list of clock controls described in __prci_init_clocks[] with
  414. * the Linux clock framework.
  415. *
  416. * Return: 0 upon success or a negative error code upon failure.
  417. */
  418. static int __prci_register_clocks(struct device *dev, struct __prci_data *pd,
  419. const struct prci_clk_desc *desc)
  420. {
  421. struct clk_init_data init = { };
  422. struct __prci_clock *pic;
  423. int parent_count, i, r;
  424. parent_count = of_clk_get_parent_count(dev->of_node);
  425. if (parent_count != EXPECTED_CLK_PARENT_COUNT) {
  426. dev_err(dev, "expected only two parent clocks, found %d\n",
  427. parent_count);
  428. return -EINVAL;
  429. }
  430. /* Register PLLs */
  431. for (i = 0; i < desc->num_clks; ++i) {
  432. pic = &(desc->clks[i]);
  433. init.name = pic->name;
  434. init.parent_names = &pic->parent_name;
  435. init.num_parents = 1;
  436. init.ops = pic->ops;
  437. pic->hw.init = &init;
  438. pic->pd = pd;
  439. if (pic->pwd)
  440. __prci_wrpll_read_cfg0(pd, pic->pwd);
  441. r = devm_clk_hw_register(dev, &pic->hw);
  442. if (r) {
  443. dev_warn(dev, "Failed to register clock %s: %d\n",
  444. init.name, r);
  445. return r;
  446. }
  447. r = clk_hw_register_clkdev(&pic->hw, pic->name, dev_name(dev));
  448. if (r) {
  449. dev_warn(dev, "Failed to register clkdev for %s: %d\n",
  450. init.name, r);
  451. return r;
  452. }
  453. pd->hw_clks.hws[i] = &pic->hw;
  454. }
  455. pd->hw_clks.num = i;
  456. r = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
  457. &pd->hw_clks);
  458. if (r) {
  459. dev_err(dev, "could not add hw_provider: %d\n", r);
  460. return r;
  461. }
  462. return 0;
  463. }
  464. /**
  465. * sifive_prci_probe() - initialize prci data and check parent count
  466. * @pdev: platform device pointer for the prci
  467. *
  468. * Return: 0 upon success or a negative error code upon failure.
  469. */
  470. static int sifive_prci_probe(struct platform_device *pdev)
  471. {
  472. struct device *dev = &pdev->dev;
  473. struct resource *res;
  474. struct __prci_data *pd;
  475. const struct prci_clk_desc *desc;
  476. int r;
  477. desc = of_device_get_match_data(&pdev->dev);
  478. pd = devm_kzalloc(dev, struct_size(pd, hw_clks.hws, desc->num_clks), GFP_KERNEL);
  479. if (!pd)
  480. return -ENOMEM;
  481. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  482. pd->va = devm_ioremap_resource(dev, res);
  483. if (IS_ERR(pd->va))
  484. return PTR_ERR(pd->va);
  485. pd->reset.rcdev.owner = THIS_MODULE;
  486. pd->reset.rcdev.nr_resets = PRCI_RST_NR;
  487. pd->reset.rcdev.ops = &reset_simple_ops;
  488. pd->reset.rcdev.of_node = pdev->dev.of_node;
  489. pd->reset.active_low = true;
  490. pd->reset.membase = pd->va + PRCI_DEVICESRESETREG_OFFSET;
  491. spin_lock_init(&pd->reset.lock);
  492. r = devm_reset_controller_register(&pdev->dev, &pd->reset.rcdev);
  493. if (r) {
  494. dev_err(dev, "could not register reset controller: %d\n", r);
  495. return r;
  496. }
  497. r = __prci_register_clocks(dev, pd, desc);
  498. if (r) {
  499. dev_err(dev, "could not register clocks: %d\n", r);
  500. return r;
  501. }
  502. dev_dbg(dev, "SiFive PRCI probed\n");
  503. return 0;
  504. }
  505. static const struct of_device_id sifive_prci_of_match[] = {
  506. {.compatible = "sifive,fu540-c000-prci", .data = &prci_clk_fu540},
  507. {.compatible = "sifive,fu740-c000-prci", .data = &prci_clk_fu740},
  508. {}
  509. };
  510. static struct platform_driver sifive_prci_driver = {
  511. .driver = {
  512. .name = "sifive-clk-prci",
  513. .of_match_table = sifive_prci_of_match,
  514. },
  515. .probe = sifive_prci_probe,
  516. };
  517. static int __init sifive_prci_init(void)
  518. {
  519. return platform_driver_register(&sifive_prci_driver);
  520. }
  521. core_initcall(sifive_prci_init);