clk.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (c) 2014 MundoReader S.L.
  4. * Author: Heiko Stuebner <heiko@sntech.de>
  5. *
  6. * Copyright (c) 2016 Rockchip Electronics Co. Ltd.
  7. * Author: Xing Zheng <zhengxing@rock-chips.com>
  8. *
  9. * based on
  10. *
  11. * samsung/clk.c
  12. * Copyright (c) 2013 Samsung Electronics Co., Ltd.
  13. * Copyright (c) 2013 Linaro Ltd.
  14. * Author: Thomas Abraham <thomas.ab@samsung.com>
  15. */
  16. #include <linux/slab.h>
  17. #include <linux/clk.h>
  18. #include <linux/clk-provider.h>
  19. #include <linux/io.h>
  20. #include <linux/mfd/syscon.h>
  21. #include <linux/regmap.h>
  22. #include <linux/reboot.h>
  23. #include "../clk-fractional-divider.h"
  24. #include "clk.h"
  25. /*
  26. * Register a clock branch.
  27. * Most clock branches have a form like
  28. *
  29. * src1 --|--\
  30. * |M |--[GATE]-[DIV]-
  31. * src2 --|--/
  32. *
  33. * sometimes without one of those components.
  34. */
  35. static struct clk *rockchip_clk_register_branch(const char *name,
  36. const char *const *parent_names, u8 num_parents,
  37. void __iomem *base,
  38. int muxdiv_offset, u8 mux_shift, u8 mux_width, u8 mux_flags,
  39. u32 *mux_table,
  40. int div_offset, u8 div_shift, u8 div_width, u8 div_flags,
  41. struct clk_div_table *div_table, int gate_offset,
  42. u8 gate_shift, u8 gate_flags, unsigned long flags,
  43. spinlock_t *lock)
  44. {
  45. struct clk_hw *hw;
  46. struct clk_mux *mux = NULL;
  47. struct clk_gate *gate = NULL;
  48. struct clk_divider *div = NULL;
  49. const struct clk_ops *mux_ops = NULL, *div_ops = NULL,
  50. *gate_ops = NULL;
  51. int ret;
  52. if (num_parents > 1) {
  53. mux = kzalloc(sizeof(*mux), GFP_KERNEL);
  54. if (!mux)
  55. return ERR_PTR(-ENOMEM);
  56. mux->reg = base + muxdiv_offset;
  57. mux->shift = mux_shift;
  58. mux->mask = BIT(mux_width) - 1;
  59. mux->flags = mux_flags;
  60. mux->table = mux_table;
  61. mux->lock = lock;
  62. mux_ops = (mux_flags & CLK_MUX_READ_ONLY) ? &clk_mux_ro_ops
  63. : &clk_mux_ops;
  64. }
  65. if (gate_offset >= 0) {
  66. gate = kzalloc(sizeof(*gate), GFP_KERNEL);
  67. if (!gate) {
  68. ret = -ENOMEM;
  69. goto err_gate;
  70. }
  71. gate->flags = gate_flags;
  72. gate->reg = base + gate_offset;
  73. gate->bit_idx = gate_shift;
  74. gate->lock = lock;
  75. gate_ops = &clk_gate_ops;
  76. }
  77. if (div_width > 0) {
  78. div = kzalloc(sizeof(*div), GFP_KERNEL);
  79. if (!div) {
  80. ret = -ENOMEM;
  81. goto err_div;
  82. }
  83. div->flags = div_flags;
  84. if (div_offset)
  85. div->reg = base + div_offset;
  86. else
  87. div->reg = base + muxdiv_offset;
  88. div->shift = div_shift;
  89. div->width = div_width;
  90. div->lock = lock;
  91. div->table = div_table;
  92. div_ops = (div_flags & CLK_DIVIDER_READ_ONLY)
  93. ? &clk_divider_ro_ops
  94. : &clk_divider_ops;
  95. }
  96. hw = clk_hw_register_composite(NULL, name, parent_names, num_parents,
  97. mux ? &mux->hw : NULL, mux_ops,
  98. div ? &div->hw : NULL, div_ops,
  99. gate ? &gate->hw : NULL, gate_ops,
  100. flags);
  101. if (IS_ERR(hw)) {
  102. kfree(div);
  103. kfree(gate);
  104. return ERR_CAST(hw);
  105. }
  106. return hw->clk;
  107. err_div:
  108. kfree(gate);
  109. err_gate:
  110. kfree(mux);
  111. return ERR_PTR(ret);
  112. }
  113. struct rockchip_clk_frac {
  114. struct notifier_block clk_nb;
  115. struct clk_fractional_divider div;
  116. struct clk_gate gate;
  117. struct clk_mux mux;
  118. const struct clk_ops *mux_ops;
  119. int mux_frac_idx;
  120. bool rate_change_remuxed;
  121. int rate_change_idx;
  122. };
  123. #define to_rockchip_clk_frac_nb(nb) \
  124. container_of(nb, struct rockchip_clk_frac, clk_nb)
  125. static int rockchip_clk_frac_notifier_cb(struct notifier_block *nb,
  126. unsigned long event, void *data)
  127. {
  128. struct clk_notifier_data *ndata = data;
  129. struct rockchip_clk_frac *frac = to_rockchip_clk_frac_nb(nb);
  130. struct clk_mux *frac_mux = &frac->mux;
  131. int ret = 0;
  132. pr_debug("%s: event %lu, old_rate %lu, new_rate: %lu\n",
  133. __func__, event, ndata->old_rate, ndata->new_rate);
  134. if (event == PRE_RATE_CHANGE) {
  135. frac->rate_change_idx =
  136. frac->mux_ops->get_parent(&frac_mux->hw);
  137. if (frac->rate_change_idx != frac->mux_frac_idx) {
  138. frac->mux_ops->set_parent(&frac_mux->hw,
  139. frac->mux_frac_idx);
  140. frac->rate_change_remuxed = 1;
  141. }
  142. } else if (event == POST_RATE_CHANGE) {
  143. /*
  144. * The POST_RATE_CHANGE notifier runs directly after the
  145. * divider clock is set in clk_change_rate, so we'll have
  146. * remuxed back to the original parent before clk_change_rate
  147. * reaches the mux itself.
  148. */
  149. if (frac->rate_change_remuxed) {
  150. frac->mux_ops->set_parent(&frac_mux->hw,
  151. frac->rate_change_idx);
  152. frac->rate_change_remuxed = 0;
  153. }
  154. }
  155. return notifier_from_errno(ret);
  156. }
  157. /*
  158. * fractional divider must set that denominator is 20 times larger than
  159. * numerator to generate precise clock frequency.
  160. */
  161. static void rockchip_fractional_approximation(struct clk_hw *hw,
  162. unsigned long rate, unsigned long *parent_rate,
  163. unsigned long *m, unsigned long *n)
  164. {
  165. struct clk_fractional_divider *fd = to_clk_fd(hw);
  166. unsigned long p_rate, p_parent_rate;
  167. struct clk_hw *p_parent;
  168. p_rate = clk_hw_get_rate(clk_hw_get_parent(hw));
  169. if ((rate * 20 > p_rate) && (p_rate % rate != 0)) {
  170. p_parent = clk_hw_get_parent(clk_hw_get_parent(hw));
  171. p_parent_rate = clk_hw_get_rate(p_parent);
  172. *parent_rate = p_parent_rate;
  173. }
  174. fd->flags |= CLK_FRAC_DIVIDER_POWER_OF_TWO_PS;
  175. clk_fractional_divider_general_approximation(hw, rate, parent_rate, m, n);
  176. }
  177. static void rockchip_clk_add_lookup(struct rockchip_clk_provider *ctx,
  178. struct clk *clk, unsigned int id)
  179. {
  180. ctx->clk_data.clks[id] = clk;
  181. }
  182. static struct clk *rockchip_clk_register_frac_branch(
  183. struct rockchip_clk_provider *ctx, const char *name,
  184. const char *const *parent_names, u8 num_parents,
  185. void __iomem *base, int muxdiv_offset, u8 div_flags,
  186. int gate_offset, u8 gate_shift, u8 gate_flags,
  187. unsigned long flags, struct rockchip_clk_branch *child,
  188. spinlock_t *lock)
  189. {
  190. struct clk_hw *hw;
  191. struct rockchip_clk_frac *frac;
  192. struct clk_gate *gate = NULL;
  193. struct clk_fractional_divider *div = NULL;
  194. const struct clk_ops *div_ops = NULL, *gate_ops = NULL;
  195. if (muxdiv_offset < 0)
  196. return ERR_PTR(-EINVAL);
  197. if (child && child->branch_type != branch_mux) {
  198. pr_err("%s: fractional child clock for %s can only be a mux\n",
  199. __func__, name);
  200. return ERR_PTR(-EINVAL);
  201. }
  202. frac = kzalloc(sizeof(*frac), GFP_KERNEL);
  203. if (!frac)
  204. return ERR_PTR(-ENOMEM);
  205. if (gate_offset >= 0) {
  206. gate = &frac->gate;
  207. gate->flags = gate_flags;
  208. gate->reg = base + gate_offset;
  209. gate->bit_idx = gate_shift;
  210. gate->lock = lock;
  211. gate_ops = &clk_gate_ops;
  212. }
  213. div = &frac->div;
  214. div->flags = div_flags;
  215. div->reg = base + muxdiv_offset;
  216. div->mshift = 16;
  217. div->mwidth = 16;
  218. div->nshift = 0;
  219. div->nwidth = 16;
  220. div->lock = lock;
  221. div->approximation = rockchip_fractional_approximation;
  222. div_ops = &clk_fractional_divider_ops;
  223. hw = clk_hw_register_composite(NULL, name, parent_names, num_parents,
  224. NULL, NULL,
  225. &div->hw, div_ops,
  226. gate ? &gate->hw : NULL, gate_ops,
  227. flags | CLK_SET_RATE_UNGATE);
  228. if (IS_ERR(hw)) {
  229. kfree(frac);
  230. return ERR_CAST(hw);
  231. }
  232. if (child) {
  233. struct clk_mux *frac_mux = &frac->mux;
  234. struct clk_init_data init;
  235. struct clk *mux_clk;
  236. int ret;
  237. frac->mux_frac_idx = match_string(child->parent_names,
  238. child->num_parents, name);
  239. frac->mux_ops = &clk_mux_ops;
  240. frac->clk_nb.notifier_call = rockchip_clk_frac_notifier_cb;
  241. frac_mux->reg = base + child->muxdiv_offset;
  242. frac_mux->shift = child->mux_shift;
  243. frac_mux->mask = BIT(child->mux_width) - 1;
  244. frac_mux->flags = child->mux_flags;
  245. if (child->mux_table)
  246. frac_mux->table = child->mux_table;
  247. frac_mux->lock = lock;
  248. frac_mux->hw.init = &init;
  249. init.name = child->name;
  250. init.flags = child->flags | CLK_SET_RATE_PARENT;
  251. init.ops = frac->mux_ops;
  252. init.parent_names = child->parent_names;
  253. init.num_parents = child->num_parents;
  254. mux_clk = clk_register(NULL, &frac_mux->hw);
  255. if (IS_ERR(mux_clk)) {
  256. kfree(frac);
  257. return mux_clk;
  258. }
  259. rockchip_clk_add_lookup(ctx, mux_clk, child->id);
  260. /* notifier on the fraction divider to catch rate changes */
  261. if (frac->mux_frac_idx >= 0) {
  262. pr_debug("%s: found fractional parent in mux at pos %d\n",
  263. __func__, frac->mux_frac_idx);
  264. ret = clk_notifier_register(hw->clk, &frac->clk_nb);
  265. if (ret)
  266. pr_err("%s: failed to register clock notifier for %s\n",
  267. __func__, name);
  268. } else {
  269. pr_warn("%s: could not find %s as parent of %s, rate changes may not work\n",
  270. __func__, name, child->name);
  271. }
  272. }
  273. return hw->clk;
  274. }
  275. static struct clk *rockchip_clk_register_factor_branch(const char *name,
  276. const char *const *parent_names, u8 num_parents,
  277. void __iomem *base, unsigned int mult, unsigned int div,
  278. int gate_offset, u8 gate_shift, u8 gate_flags,
  279. unsigned long flags, spinlock_t *lock)
  280. {
  281. struct clk_hw *hw;
  282. struct clk_gate *gate = NULL;
  283. struct clk_fixed_factor *fix = NULL;
  284. /* without gate, register a simple factor clock */
  285. if (gate_offset == 0) {
  286. return clk_register_fixed_factor(NULL, name,
  287. parent_names[0], flags, mult,
  288. div);
  289. }
  290. gate = kzalloc(sizeof(*gate), GFP_KERNEL);
  291. if (!gate)
  292. return ERR_PTR(-ENOMEM);
  293. gate->flags = gate_flags;
  294. gate->reg = base + gate_offset;
  295. gate->bit_idx = gate_shift;
  296. gate->lock = lock;
  297. fix = kzalloc(sizeof(*fix), GFP_KERNEL);
  298. if (!fix) {
  299. kfree(gate);
  300. return ERR_PTR(-ENOMEM);
  301. }
  302. fix->mult = mult;
  303. fix->div = div;
  304. hw = clk_hw_register_composite(NULL, name, parent_names, num_parents,
  305. NULL, NULL,
  306. &fix->hw, &clk_fixed_factor_ops,
  307. &gate->hw, &clk_gate_ops, flags);
  308. if (IS_ERR(hw)) {
  309. kfree(fix);
  310. kfree(gate);
  311. return ERR_CAST(hw);
  312. }
  313. return hw->clk;
  314. }
  315. struct rockchip_clk_provider *rockchip_clk_init(struct device_node *np,
  316. void __iomem *base,
  317. unsigned long nr_clks)
  318. {
  319. struct rockchip_clk_provider *ctx;
  320. struct clk **clk_table;
  321. int i;
  322. ctx = kzalloc(sizeof(struct rockchip_clk_provider), GFP_KERNEL);
  323. if (!ctx)
  324. return ERR_PTR(-ENOMEM);
  325. clk_table = kcalloc(nr_clks, sizeof(struct clk *), GFP_KERNEL);
  326. if (!clk_table)
  327. goto err_free;
  328. for (i = 0; i < nr_clks; ++i)
  329. clk_table[i] = ERR_PTR(-ENOENT);
  330. ctx->reg_base = base;
  331. ctx->clk_data.clks = clk_table;
  332. ctx->clk_data.clk_num = nr_clks;
  333. ctx->cru_node = np;
  334. spin_lock_init(&ctx->lock);
  335. ctx->grf = syscon_regmap_lookup_by_phandle(ctx->cru_node,
  336. "rockchip,grf");
  337. return ctx;
  338. err_free:
  339. kfree(ctx);
  340. return ERR_PTR(-ENOMEM);
  341. }
  342. EXPORT_SYMBOL_GPL(rockchip_clk_init);
  343. void rockchip_clk_of_add_provider(struct device_node *np,
  344. struct rockchip_clk_provider *ctx)
  345. {
  346. if (of_clk_add_provider(np, of_clk_src_onecell_get,
  347. &ctx->clk_data))
  348. pr_err("%s: could not register clk provider\n", __func__);
  349. }
  350. EXPORT_SYMBOL_GPL(rockchip_clk_of_add_provider);
  351. void rockchip_clk_register_plls(struct rockchip_clk_provider *ctx,
  352. struct rockchip_pll_clock *list,
  353. unsigned int nr_pll, int grf_lock_offset)
  354. {
  355. struct clk *clk;
  356. int idx;
  357. for (idx = 0; idx < nr_pll; idx++, list++) {
  358. clk = rockchip_clk_register_pll(ctx, list->type, list->name,
  359. list->parent_names, list->num_parents,
  360. list->con_offset, grf_lock_offset,
  361. list->lock_shift, list->mode_offset,
  362. list->mode_shift, list->rate_table,
  363. list->flags, list->pll_flags);
  364. if (IS_ERR(clk)) {
  365. pr_err("%s: failed to register clock %s\n", __func__,
  366. list->name);
  367. continue;
  368. }
  369. rockchip_clk_add_lookup(ctx, clk, list->id);
  370. }
  371. }
  372. EXPORT_SYMBOL_GPL(rockchip_clk_register_plls);
  373. unsigned long rockchip_clk_find_max_clk_id(struct rockchip_clk_branch *list,
  374. unsigned int nr_clk)
  375. {
  376. unsigned long max = 0;
  377. unsigned int idx;
  378. for (idx = 0; idx < nr_clk; idx++, list++) {
  379. if (list->id > max)
  380. max = list->id;
  381. if (list->child && list->child->id > max)
  382. max = list->child->id;
  383. }
  384. return max;
  385. }
  386. EXPORT_SYMBOL_GPL(rockchip_clk_find_max_clk_id);
  387. void rockchip_clk_register_branches(struct rockchip_clk_provider *ctx,
  388. struct rockchip_clk_branch *list,
  389. unsigned int nr_clk)
  390. {
  391. struct clk *clk;
  392. unsigned int idx;
  393. unsigned long flags;
  394. for (idx = 0; idx < nr_clk; idx++, list++) {
  395. flags = list->flags;
  396. clk = NULL;
  397. /* catch simple muxes */
  398. switch (list->branch_type) {
  399. case branch_mux:
  400. if (list->mux_table)
  401. clk = clk_register_mux_table(NULL, list->name,
  402. list->parent_names, list->num_parents,
  403. flags,
  404. ctx->reg_base + list->muxdiv_offset,
  405. list->mux_shift, list->mux_width,
  406. list->mux_flags, list->mux_table,
  407. &ctx->lock);
  408. else
  409. clk = clk_register_mux(NULL, list->name,
  410. list->parent_names, list->num_parents,
  411. flags,
  412. ctx->reg_base + list->muxdiv_offset,
  413. list->mux_shift, list->mux_width,
  414. list->mux_flags, &ctx->lock);
  415. break;
  416. case branch_muxgrf:
  417. clk = rockchip_clk_register_muxgrf(list->name,
  418. list->parent_names, list->num_parents,
  419. flags, ctx->grf, list->muxdiv_offset,
  420. list->mux_shift, list->mux_width,
  421. list->mux_flags);
  422. break;
  423. case branch_divider:
  424. if (list->div_table)
  425. clk = clk_register_divider_table(NULL,
  426. list->name, list->parent_names[0],
  427. flags,
  428. ctx->reg_base + list->muxdiv_offset,
  429. list->div_shift, list->div_width,
  430. list->div_flags, list->div_table,
  431. &ctx->lock);
  432. else
  433. clk = clk_register_divider(NULL, list->name,
  434. list->parent_names[0], flags,
  435. ctx->reg_base + list->muxdiv_offset,
  436. list->div_shift, list->div_width,
  437. list->div_flags, &ctx->lock);
  438. break;
  439. case branch_fraction_divider:
  440. clk = rockchip_clk_register_frac_branch(ctx, list->name,
  441. list->parent_names, list->num_parents,
  442. ctx->reg_base, list->muxdiv_offset,
  443. list->div_flags,
  444. list->gate_offset, list->gate_shift,
  445. list->gate_flags, flags, list->child,
  446. &ctx->lock);
  447. break;
  448. case branch_half_divider:
  449. clk = rockchip_clk_register_halfdiv(list->name,
  450. list->parent_names, list->num_parents,
  451. ctx->reg_base, list->muxdiv_offset,
  452. list->mux_shift, list->mux_width,
  453. list->mux_flags, list->div_shift,
  454. list->div_width, list->div_flags,
  455. list->gate_offset, list->gate_shift,
  456. list->gate_flags, flags, &ctx->lock);
  457. break;
  458. case branch_gate:
  459. flags |= CLK_SET_RATE_PARENT;
  460. clk = clk_register_gate(NULL, list->name,
  461. list->parent_names[0], flags,
  462. ctx->reg_base + list->gate_offset,
  463. list->gate_shift, list->gate_flags, &ctx->lock);
  464. break;
  465. case branch_composite:
  466. clk = rockchip_clk_register_branch(list->name,
  467. list->parent_names, list->num_parents,
  468. ctx->reg_base, list->muxdiv_offset,
  469. list->mux_shift,
  470. list->mux_width, list->mux_flags,
  471. list->mux_table, list->div_offset,
  472. list->div_shift, list->div_width,
  473. list->div_flags, list->div_table,
  474. list->gate_offset, list->gate_shift,
  475. list->gate_flags, flags, &ctx->lock);
  476. break;
  477. case branch_mmc:
  478. clk = rockchip_clk_register_mmc(
  479. list->name,
  480. list->parent_names, list->num_parents,
  481. ctx->reg_base + list->muxdiv_offset,
  482. list->div_shift
  483. );
  484. break;
  485. case branch_inverter:
  486. clk = rockchip_clk_register_inverter(
  487. list->name, list->parent_names,
  488. list->num_parents,
  489. ctx->reg_base + list->muxdiv_offset,
  490. list->div_shift, list->div_flags, &ctx->lock);
  491. break;
  492. case branch_factor:
  493. clk = rockchip_clk_register_factor_branch(
  494. list->name, list->parent_names,
  495. list->num_parents, ctx->reg_base,
  496. list->div_shift, list->div_width,
  497. list->gate_offset, list->gate_shift,
  498. list->gate_flags, flags, &ctx->lock);
  499. break;
  500. case branch_ddrclk:
  501. clk = rockchip_clk_register_ddrclk(
  502. list->name, list->flags,
  503. list->parent_names, list->num_parents,
  504. list->muxdiv_offset, list->mux_shift,
  505. list->mux_width, list->div_shift,
  506. list->div_width, list->div_flags,
  507. ctx->reg_base, &ctx->lock);
  508. break;
  509. }
  510. /* none of the cases above matched */
  511. if (!clk) {
  512. pr_err("%s: unknown clock type %d\n",
  513. __func__, list->branch_type);
  514. continue;
  515. }
  516. if (IS_ERR(clk)) {
  517. pr_err("%s: failed to register clock %s: %ld\n",
  518. __func__, list->name, PTR_ERR(clk));
  519. continue;
  520. }
  521. rockchip_clk_add_lookup(ctx, clk, list->id);
  522. }
  523. }
  524. EXPORT_SYMBOL_GPL(rockchip_clk_register_branches);
  525. void rockchip_clk_register_armclk(struct rockchip_clk_provider *ctx,
  526. unsigned int lookup_id,
  527. const char *name, const char *const *parent_names,
  528. u8 num_parents,
  529. const struct rockchip_cpuclk_reg_data *reg_data,
  530. const struct rockchip_cpuclk_rate_table *rates,
  531. int nrates)
  532. {
  533. struct clk *clk;
  534. clk = rockchip_clk_register_cpuclk(name, parent_names, num_parents,
  535. reg_data, rates, nrates,
  536. ctx->reg_base, &ctx->lock);
  537. if (IS_ERR(clk)) {
  538. pr_err("%s: failed to register clock %s: %ld\n",
  539. __func__, name, PTR_ERR(clk));
  540. return;
  541. }
  542. rockchip_clk_add_lookup(ctx, clk, lookup_id);
  543. }
  544. EXPORT_SYMBOL_GPL(rockchip_clk_register_armclk);
  545. void rockchip_clk_protect_critical(const char *const clocks[],
  546. int nclocks)
  547. {
  548. int i;
  549. /* Protect the clocks that needs to stay on */
  550. for (i = 0; i < nclocks; i++) {
  551. struct clk *clk = __clk_lookup(clocks[i]);
  552. clk_prepare_enable(clk);
  553. }
  554. }
  555. EXPORT_SYMBOL_GPL(rockchip_clk_protect_critical);
  556. static void __iomem *rst_base;
  557. static unsigned int reg_restart;
  558. static void (*cb_restart)(void);
  559. static int rockchip_restart_notify(struct notifier_block *this,
  560. unsigned long mode, void *cmd)
  561. {
  562. if (cb_restart)
  563. cb_restart();
  564. writel(0xfdb9, rst_base + reg_restart);
  565. return NOTIFY_DONE;
  566. }
  567. static struct notifier_block rockchip_restart_handler = {
  568. .notifier_call = rockchip_restart_notify,
  569. .priority = 128,
  570. };
  571. void
  572. rockchip_register_restart_notifier(struct rockchip_clk_provider *ctx,
  573. unsigned int reg,
  574. void (*cb)(void))
  575. {
  576. int ret;
  577. rst_base = ctx->reg_base;
  578. reg_restart = reg;
  579. cb_restart = cb;
  580. ret = register_restart_handler(&rockchip_restart_handler);
  581. if (ret)
  582. pr_err("%s: cannot register restart handler, %d\n",
  583. __func__, ret);
  584. }
  585. EXPORT_SYMBOL_GPL(rockchip_register_restart_notifier);