clk.c 17 KB

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