clk.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. /*
  2. * Copyright (c) 2014 MundoReader S.L.
  3. * Author: Heiko Stuebner <heiko@sntech.de>
  4. *
  5. * Copyright (c) 2015 Rockchip Electronics Co. Ltd.
  6. * Author: Xing Zheng <zhengxing@rock-chips.com>
  7. *
  8. * based on
  9. *
  10. * samsung/clk.h
  11. * Copyright (c) 2013 Samsung Electronics Co., Ltd.
  12. * Copyright (c) 2013 Linaro Ltd.
  13. * Author: Thomas Abraham <thomas.ab@samsung.com>
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 2 of the License, or
  18. * (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. */
  25. #ifndef CLK_ROCKCHIP_CLK_H
  26. #define CLK_ROCKCHIP_CLK_H
  27. #include <linux/io.h>
  28. #include <linux/clk-provider.h>
  29. struct clk;
  30. #define HIWORD_UPDATE(val, mask, shift) \
  31. ((val) << (shift) | (mask) << ((shift) + 16))
  32. #define RK2928_PLL_CON(x) ((x) * 0x4)
  33. #define RK2928_MODE_CON 0x40
  34. #define RK2928_CLKSEL_CON(x) ((x) * 0x4 + 0x44)
  35. #define RK2928_CLKGATE_CON(x) ((x) * 0x4 + 0xd0)
  36. #define RK2928_GLB_SRST_FST 0x100
  37. #define RK2928_GLB_SRST_SND 0x104
  38. #define RK2928_SOFTRST_CON(x) ((x) * 0x4 + 0x110)
  39. #define RK2928_MISC_CON 0x134
  40. #define RK3036_SDMMC_CON0 0x144
  41. #define RK3036_SDMMC_CON1 0x148
  42. #define RK3036_SDIO_CON0 0x14c
  43. #define RK3036_SDIO_CON1 0x150
  44. #define RK3036_EMMC_CON0 0x154
  45. #define RK3036_EMMC_CON1 0x158
  46. #define RK3228_GLB_SRST_FST 0x1f0
  47. #define RK3228_GLB_SRST_SND 0x1f4
  48. #define RK3228_SDMMC_CON0 0x1c0
  49. #define RK3228_SDMMC_CON1 0x1c4
  50. #define RK3228_SDIO_CON0 0x1c8
  51. #define RK3228_SDIO_CON1 0x1cc
  52. #define RK3228_EMMC_CON0 0x1d8
  53. #define RK3228_EMMC_CON1 0x1dc
  54. #define RK3288_PLL_CON(x) RK2928_PLL_CON(x)
  55. #define RK3288_MODE_CON 0x50
  56. #define RK3288_CLKSEL_CON(x) ((x) * 0x4 + 0x60)
  57. #define RK3288_CLKGATE_CON(x) ((x) * 0x4 + 0x160)
  58. #define RK3288_GLB_SRST_FST 0x1b0
  59. #define RK3288_GLB_SRST_SND 0x1b4
  60. #define RK3288_SOFTRST_CON(x) ((x) * 0x4 + 0x1b8)
  61. #define RK3288_MISC_CON 0x1e8
  62. #define RK3288_SDMMC_CON0 0x200
  63. #define RK3288_SDMMC_CON1 0x204
  64. #define RK3288_SDIO0_CON0 0x208
  65. #define RK3288_SDIO0_CON1 0x20c
  66. #define RK3288_SDIO1_CON0 0x210
  67. #define RK3288_SDIO1_CON1 0x214
  68. #define RK3288_EMMC_CON0 0x218
  69. #define RK3288_EMMC_CON1 0x21c
  70. #define RK3368_PLL_CON(x) RK2928_PLL_CON(x)
  71. #define RK3368_CLKSEL_CON(x) ((x) * 0x4 + 0x100)
  72. #define RK3368_CLKGATE_CON(x) ((x) * 0x4 + 0x200)
  73. #define RK3368_GLB_SRST_FST 0x280
  74. #define RK3368_GLB_SRST_SND 0x284
  75. #define RK3368_SOFTRST_CON(x) ((x) * 0x4 + 0x300)
  76. #define RK3368_MISC_CON 0x380
  77. #define RK3368_SDMMC_CON0 0x400
  78. #define RK3368_SDMMC_CON1 0x404
  79. #define RK3368_SDIO0_CON0 0x408
  80. #define RK3368_SDIO0_CON1 0x40c
  81. #define RK3368_SDIO1_CON0 0x410
  82. #define RK3368_SDIO1_CON1 0x414
  83. #define RK3368_EMMC_CON0 0x418
  84. #define RK3368_EMMC_CON1 0x41c
  85. #define RK3399_PLL_CON(x) RK2928_PLL_CON(x)
  86. #define RK3399_CLKSEL_CON(x) ((x) * 0x4 + 0x100)
  87. #define RK3399_CLKGATE_CON(x) ((x) * 0x4 + 0x300)
  88. #define RK3399_SOFTRST_CON(x) ((x) * 0x4 + 0x400)
  89. #define RK3399_GLB_SRST_FST 0x500
  90. #define RK3399_GLB_SRST_SND 0x504
  91. #define RK3399_GLB_CNT_TH 0x508
  92. #define RK3399_MISC_CON 0x50c
  93. #define RK3399_RST_CON 0x510
  94. #define RK3399_RST_ST 0x514
  95. #define RK3399_SDMMC_CON0 0x580
  96. #define RK3399_SDMMC_CON1 0x584
  97. #define RK3399_SDIO_CON0 0x588
  98. #define RK3399_SDIO_CON1 0x58c
  99. #define RK3399_PMU_PLL_CON(x) RK2928_PLL_CON(x)
  100. #define RK3399_PMU_CLKSEL_CON(x) ((x) * 0x4 + 0x80)
  101. #define RK3399_PMU_CLKGATE_CON(x) ((x) * 0x4 + 0x100)
  102. #define RK3399_PMU_SOFTRST_CON(x) ((x) * 0x4 + 0x110)
  103. enum rockchip_pll_type {
  104. pll_rk3036,
  105. pll_rk3066,
  106. pll_rk3399,
  107. };
  108. #define RK3036_PLL_RATE(_rate, _refdiv, _fbdiv, _postdiv1, \
  109. _postdiv2, _dsmpd, _frac) \
  110. { \
  111. .rate = _rate##U, \
  112. .fbdiv = _fbdiv, \
  113. .postdiv1 = _postdiv1, \
  114. .refdiv = _refdiv, \
  115. .postdiv2 = _postdiv2, \
  116. .dsmpd = _dsmpd, \
  117. .frac = _frac, \
  118. }
  119. #define RK3066_PLL_RATE(_rate, _nr, _nf, _no) \
  120. { \
  121. .rate = _rate##U, \
  122. .nr = _nr, \
  123. .nf = _nf, \
  124. .no = _no, \
  125. .nb = ((_nf) < 2) ? 1 : (_nf) >> 1, \
  126. }
  127. #define RK3066_PLL_RATE_NB(_rate, _nr, _nf, _no, _nb) \
  128. { \
  129. .rate = _rate##U, \
  130. .nr = _nr, \
  131. .nf = _nf, \
  132. .no = _no, \
  133. .nb = _nb, \
  134. }
  135. /**
  136. * struct rockchip_clk_provider - information about clock provider
  137. * @reg_base: virtual address for the register base.
  138. * @clk_data: holds clock related data like clk* and number of clocks.
  139. * @cru_node: device-node of the clock-provider
  140. * @grf: regmap of the general-register-files syscon
  141. * @lock: maintains exclusion between callbacks for a given clock-provider.
  142. */
  143. struct rockchip_clk_provider {
  144. void __iomem *reg_base;
  145. struct clk_onecell_data clk_data;
  146. struct device_node *cru_node;
  147. struct regmap *grf;
  148. spinlock_t lock;
  149. };
  150. struct rockchip_pll_rate_table {
  151. unsigned long rate;
  152. unsigned int nr;
  153. unsigned int nf;
  154. unsigned int no;
  155. unsigned int nb;
  156. /* for RK3036/RK3399 */
  157. unsigned int fbdiv;
  158. unsigned int postdiv1;
  159. unsigned int refdiv;
  160. unsigned int postdiv2;
  161. unsigned int dsmpd;
  162. unsigned int frac;
  163. };
  164. /**
  165. * struct rockchip_pll_clock - information about pll clock
  166. * @id: platform specific id of the clock.
  167. * @name: name of this pll clock.
  168. * @parent_names: name of the parent clock.
  169. * @num_parents: number of parents
  170. * @flags: optional flags for basic clock.
  171. * @con_offset: offset of the register for configuring the PLL.
  172. * @mode_offset: offset of the register for configuring the PLL-mode.
  173. * @mode_shift: offset inside the mode-register for the mode of this pll.
  174. * @lock_shift: offset inside the lock register for the lock status.
  175. * @type: Type of PLL to be registered.
  176. * @pll_flags: hardware-specific flags
  177. * @rate_table: Table of usable pll rates
  178. *
  179. * Flags:
  180. * ROCKCHIP_PLL_SYNC_RATE - check rate parameters to match against the
  181. * rate_table parameters and ajust them if necessary.
  182. */
  183. struct rockchip_pll_clock {
  184. unsigned int id;
  185. const char *name;
  186. const char *const *parent_names;
  187. u8 num_parents;
  188. unsigned long flags;
  189. int con_offset;
  190. int mode_offset;
  191. int mode_shift;
  192. int lock_shift;
  193. enum rockchip_pll_type type;
  194. u8 pll_flags;
  195. struct rockchip_pll_rate_table *rate_table;
  196. };
  197. #define ROCKCHIP_PLL_SYNC_RATE BIT(0)
  198. #define PLL(_type, _id, _name, _pnames, _flags, _con, _mode, _mshift, \
  199. _lshift, _pflags, _rtable) \
  200. { \
  201. .id = _id, \
  202. .type = _type, \
  203. .name = _name, \
  204. .parent_names = _pnames, \
  205. .num_parents = ARRAY_SIZE(_pnames), \
  206. .flags = CLK_GET_RATE_NOCACHE | _flags, \
  207. .con_offset = _con, \
  208. .mode_offset = _mode, \
  209. .mode_shift = _mshift, \
  210. .lock_shift = _lshift, \
  211. .pll_flags = _pflags, \
  212. .rate_table = _rtable, \
  213. }
  214. struct clk *rockchip_clk_register_pll(struct rockchip_clk_provider *ctx,
  215. enum rockchip_pll_type pll_type,
  216. const char *name, const char *const *parent_names,
  217. u8 num_parents, int con_offset, int grf_lock_offset,
  218. int lock_shift, int mode_offset, int mode_shift,
  219. struct rockchip_pll_rate_table *rate_table,
  220. unsigned long flags, u8 clk_pll_flags);
  221. struct rockchip_cpuclk_clksel {
  222. int reg;
  223. u32 val;
  224. };
  225. #define ROCKCHIP_CPUCLK_NUM_DIVIDERS 2
  226. struct rockchip_cpuclk_rate_table {
  227. unsigned long prate;
  228. struct rockchip_cpuclk_clksel divs[ROCKCHIP_CPUCLK_NUM_DIVIDERS];
  229. };
  230. /**
  231. * struct rockchip_cpuclk_reg_data - register offsets and masks of the cpuclock
  232. * @core_reg: register offset of the core settings register
  233. * @div_core_shift: core divider offset used to divide the pll value
  234. * @div_core_mask: core divider mask
  235. * @mux_core_alt: mux value to select alternate parent
  236. * @mux_core_main: mux value to select main parent of core
  237. * @mux_core_shift: offset of the core multiplexer
  238. * @mux_core_mask: core multiplexer mask
  239. */
  240. struct rockchip_cpuclk_reg_data {
  241. int core_reg;
  242. u8 div_core_shift;
  243. u32 div_core_mask;
  244. u8 mux_core_alt;
  245. u8 mux_core_main;
  246. u8 mux_core_shift;
  247. u32 mux_core_mask;
  248. };
  249. struct clk *rockchip_clk_register_cpuclk(const char *name,
  250. const char *const *parent_names, u8 num_parents,
  251. const struct rockchip_cpuclk_reg_data *reg_data,
  252. const struct rockchip_cpuclk_rate_table *rates,
  253. int nrates, void __iomem *reg_base, spinlock_t *lock);
  254. struct clk *rockchip_clk_register_mmc(const char *name,
  255. const char *const *parent_names, u8 num_parents,
  256. void __iomem *reg, int shift);
  257. /*
  258. * DDRCLK flags, including method of setting the rate
  259. * ROCKCHIP_DDRCLK_SIP: use SIP call to bl31 to change ddrclk rate.
  260. */
  261. #define ROCKCHIP_DDRCLK_SIP BIT(0)
  262. struct clk *rockchip_clk_register_ddrclk(const char *name, int flags,
  263. const char *const *parent_names,
  264. u8 num_parents, int mux_offset,
  265. int mux_shift, int mux_width,
  266. int div_shift, int div_width,
  267. int ddr_flags, void __iomem *reg_base,
  268. spinlock_t *lock);
  269. #define ROCKCHIP_INVERTER_HIWORD_MASK BIT(0)
  270. struct clk *rockchip_clk_register_inverter(const char *name,
  271. const char *const *parent_names, u8 num_parents,
  272. void __iomem *reg, int shift, int flags,
  273. spinlock_t *lock);
  274. #define PNAME(x) static const char *const x[] __initconst
  275. enum rockchip_clk_branch_type {
  276. branch_composite,
  277. branch_mux,
  278. branch_divider,
  279. branch_fraction_divider,
  280. branch_gate,
  281. branch_mmc,
  282. branch_inverter,
  283. branch_factor,
  284. branch_ddrclk,
  285. };
  286. struct rockchip_clk_branch {
  287. unsigned int id;
  288. enum rockchip_clk_branch_type branch_type;
  289. const char *name;
  290. const char *const *parent_names;
  291. u8 num_parents;
  292. unsigned long flags;
  293. int muxdiv_offset;
  294. u8 mux_shift;
  295. u8 mux_width;
  296. u8 mux_flags;
  297. u8 div_shift;
  298. u8 div_width;
  299. u8 div_flags;
  300. struct clk_div_table *div_table;
  301. int gate_offset;
  302. u8 gate_shift;
  303. u8 gate_flags;
  304. struct rockchip_clk_branch *child;
  305. };
  306. #define COMPOSITE(_id, cname, pnames, f, mo, ms, mw, mf, ds, dw,\
  307. df, go, gs, gf) \
  308. { \
  309. .id = _id, \
  310. .branch_type = branch_composite, \
  311. .name = cname, \
  312. .parent_names = pnames, \
  313. .num_parents = ARRAY_SIZE(pnames), \
  314. .flags = f, \
  315. .muxdiv_offset = mo, \
  316. .mux_shift = ms, \
  317. .mux_width = mw, \
  318. .mux_flags = mf, \
  319. .div_shift = ds, \
  320. .div_width = dw, \
  321. .div_flags = df, \
  322. .gate_offset = go, \
  323. .gate_shift = gs, \
  324. .gate_flags = gf, \
  325. }
  326. #define COMPOSITE_NOMUX(_id, cname, pname, f, mo, ds, dw, df, \
  327. go, gs, gf) \
  328. { \
  329. .id = _id, \
  330. .branch_type = branch_composite, \
  331. .name = cname, \
  332. .parent_names = (const char *[]){ pname }, \
  333. .num_parents = 1, \
  334. .flags = f, \
  335. .muxdiv_offset = mo, \
  336. .div_shift = ds, \
  337. .div_width = dw, \
  338. .div_flags = df, \
  339. .gate_offset = go, \
  340. .gate_shift = gs, \
  341. .gate_flags = gf, \
  342. }
  343. #define COMPOSITE_NOMUX_DIVTBL(_id, cname, pname, f, mo, ds, dw,\
  344. df, dt, go, gs, gf) \
  345. { \
  346. .id = _id, \
  347. .branch_type = branch_composite, \
  348. .name = cname, \
  349. .parent_names = (const char *[]){ pname }, \
  350. .num_parents = 1, \
  351. .flags = f, \
  352. .muxdiv_offset = mo, \
  353. .div_shift = ds, \
  354. .div_width = dw, \
  355. .div_flags = df, \
  356. .div_table = dt, \
  357. .gate_offset = go, \
  358. .gate_shift = gs, \
  359. .gate_flags = gf, \
  360. }
  361. #define COMPOSITE_NODIV(_id, cname, pnames, f, mo, ms, mw, mf, \
  362. go, gs, gf) \
  363. { \
  364. .id = _id, \
  365. .branch_type = branch_composite, \
  366. .name = cname, \
  367. .parent_names = pnames, \
  368. .num_parents = ARRAY_SIZE(pnames), \
  369. .flags = f, \
  370. .muxdiv_offset = mo, \
  371. .mux_shift = ms, \
  372. .mux_width = mw, \
  373. .mux_flags = mf, \
  374. .gate_offset = go, \
  375. .gate_shift = gs, \
  376. .gate_flags = gf, \
  377. }
  378. #define COMPOSITE_NOGATE(_id, cname, pnames, f, mo, ms, mw, mf, \
  379. ds, dw, df) \
  380. { \
  381. .id = _id, \
  382. .branch_type = branch_composite, \
  383. .name = cname, \
  384. .parent_names = pnames, \
  385. .num_parents = ARRAY_SIZE(pnames), \
  386. .flags = f, \
  387. .muxdiv_offset = mo, \
  388. .mux_shift = ms, \
  389. .mux_width = mw, \
  390. .mux_flags = mf, \
  391. .div_shift = ds, \
  392. .div_width = dw, \
  393. .div_flags = df, \
  394. .gate_offset = -1, \
  395. }
  396. #define COMPOSITE_NOGATE_DIVTBL(_id, cname, pnames, f, mo, ms, \
  397. mw, mf, ds, dw, df, dt) \
  398. { \
  399. .id = _id, \
  400. .branch_type = branch_composite, \
  401. .name = cname, \
  402. .parent_names = pnames, \
  403. .num_parents = ARRAY_SIZE(pnames), \
  404. .flags = f, \
  405. .muxdiv_offset = mo, \
  406. .mux_shift = ms, \
  407. .mux_width = mw, \
  408. .mux_flags = mf, \
  409. .div_shift = ds, \
  410. .div_width = dw, \
  411. .div_flags = df, \
  412. .div_table = dt, \
  413. .gate_offset = -1, \
  414. }
  415. #define COMPOSITE_FRAC(_id, cname, pname, f, mo, df, go, gs, gf)\
  416. { \
  417. .id = _id, \
  418. .branch_type = branch_fraction_divider, \
  419. .name = cname, \
  420. .parent_names = (const char *[]){ pname }, \
  421. .num_parents = 1, \
  422. .flags = f, \
  423. .muxdiv_offset = mo, \
  424. .div_shift = 16, \
  425. .div_width = 16, \
  426. .div_flags = df, \
  427. .gate_offset = go, \
  428. .gate_shift = gs, \
  429. .gate_flags = gf, \
  430. }
  431. #define COMPOSITE_FRACMUX(_id, cname, pname, f, mo, df, go, gs, gf, ch) \
  432. { \
  433. .id = _id, \
  434. .branch_type = branch_fraction_divider, \
  435. .name = cname, \
  436. .parent_names = (const char *[]){ pname }, \
  437. .num_parents = 1, \
  438. .flags = f, \
  439. .muxdiv_offset = mo, \
  440. .div_shift = 16, \
  441. .div_width = 16, \
  442. .div_flags = df, \
  443. .gate_offset = go, \
  444. .gate_shift = gs, \
  445. .gate_flags = gf, \
  446. .child = ch, \
  447. }
  448. #define COMPOSITE_FRACMUX_NOGATE(_id, cname, pname, f, mo, df, ch) \
  449. { \
  450. .id = _id, \
  451. .branch_type = branch_fraction_divider, \
  452. .name = cname, \
  453. .parent_names = (const char *[]){ pname }, \
  454. .num_parents = 1, \
  455. .flags = f, \
  456. .muxdiv_offset = mo, \
  457. .div_shift = 16, \
  458. .div_width = 16, \
  459. .div_flags = df, \
  460. .gate_offset = -1, \
  461. .child = ch, \
  462. }
  463. #define COMPOSITE_DDRCLK(_id, cname, pnames, f, mo, ms, mw, \
  464. ds, dw, df) \
  465. { \
  466. .id = _id, \
  467. .branch_type = branch_ddrclk, \
  468. .name = cname, \
  469. .parent_names = pnames, \
  470. .num_parents = ARRAY_SIZE(pnames), \
  471. .flags = f, \
  472. .muxdiv_offset = mo, \
  473. .mux_shift = ms, \
  474. .mux_width = mw, \
  475. .div_shift = ds, \
  476. .div_width = dw, \
  477. .div_flags = df, \
  478. .gate_offset = -1, \
  479. }
  480. #define MUX(_id, cname, pnames, f, o, s, w, mf) \
  481. { \
  482. .id = _id, \
  483. .branch_type = branch_mux, \
  484. .name = cname, \
  485. .parent_names = pnames, \
  486. .num_parents = ARRAY_SIZE(pnames), \
  487. .flags = f, \
  488. .muxdiv_offset = o, \
  489. .mux_shift = s, \
  490. .mux_width = w, \
  491. .mux_flags = mf, \
  492. .gate_offset = -1, \
  493. }
  494. #define DIV(_id, cname, pname, f, o, s, w, df) \
  495. { \
  496. .id = _id, \
  497. .branch_type = branch_divider, \
  498. .name = cname, \
  499. .parent_names = (const char *[]){ pname }, \
  500. .num_parents = 1, \
  501. .flags = f, \
  502. .muxdiv_offset = o, \
  503. .div_shift = s, \
  504. .div_width = w, \
  505. .div_flags = df, \
  506. .gate_offset = -1, \
  507. }
  508. #define DIVTBL(_id, cname, pname, f, o, s, w, df, dt) \
  509. { \
  510. .id = _id, \
  511. .branch_type = branch_divider, \
  512. .name = cname, \
  513. .parent_names = (const char *[]){ pname }, \
  514. .num_parents = 1, \
  515. .flags = f, \
  516. .muxdiv_offset = o, \
  517. .div_shift = s, \
  518. .div_width = w, \
  519. .div_flags = df, \
  520. .div_table = dt, \
  521. }
  522. #define GATE(_id, cname, pname, f, o, b, gf) \
  523. { \
  524. .id = _id, \
  525. .branch_type = branch_gate, \
  526. .name = cname, \
  527. .parent_names = (const char *[]){ pname }, \
  528. .num_parents = 1, \
  529. .flags = f, \
  530. .gate_offset = o, \
  531. .gate_shift = b, \
  532. .gate_flags = gf, \
  533. }
  534. #define MMC(_id, cname, pname, offset, shift) \
  535. { \
  536. .id = _id, \
  537. .branch_type = branch_mmc, \
  538. .name = cname, \
  539. .parent_names = (const char *[]){ pname }, \
  540. .num_parents = 1, \
  541. .muxdiv_offset = offset, \
  542. .div_shift = shift, \
  543. }
  544. #define INVERTER(_id, cname, pname, io, is, if) \
  545. { \
  546. .id = _id, \
  547. .branch_type = branch_inverter, \
  548. .name = cname, \
  549. .parent_names = (const char *[]){ pname }, \
  550. .num_parents = 1, \
  551. .muxdiv_offset = io, \
  552. .div_shift = is, \
  553. .div_flags = if, \
  554. }
  555. #define FACTOR(_id, cname, pname, f, fm, fd) \
  556. { \
  557. .id = _id, \
  558. .branch_type = branch_factor, \
  559. .name = cname, \
  560. .parent_names = (const char *[]){ pname }, \
  561. .num_parents = 1, \
  562. .flags = f, \
  563. .div_shift = fm, \
  564. .div_width = fd, \
  565. }
  566. #define FACTOR_GATE(_id, cname, pname, f, fm, fd, go, gb, gf) \
  567. { \
  568. .id = _id, \
  569. .branch_type = branch_factor, \
  570. .name = cname, \
  571. .parent_names = (const char *[]){ pname }, \
  572. .num_parents = 1, \
  573. .flags = f, \
  574. .div_shift = fm, \
  575. .div_width = fd, \
  576. .gate_offset = go, \
  577. .gate_shift = gb, \
  578. .gate_flags = gf, \
  579. }
  580. struct rockchip_clk_provider *rockchip_clk_init(struct device_node *np,
  581. void __iomem *base, unsigned long nr_clks);
  582. void rockchip_clk_of_add_provider(struct device_node *np,
  583. struct rockchip_clk_provider *ctx);
  584. void rockchip_clk_add_lookup(struct rockchip_clk_provider *ctx,
  585. struct clk *clk, unsigned int id);
  586. void rockchip_clk_register_branches(struct rockchip_clk_provider *ctx,
  587. struct rockchip_clk_branch *list,
  588. unsigned int nr_clk);
  589. void rockchip_clk_register_plls(struct rockchip_clk_provider *ctx,
  590. struct rockchip_pll_clock *pll_list,
  591. unsigned int nr_pll, int grf_lock_offset);
  592. void rockchip_clk_register_armclk(struct rockchip_clk_provider *ctx,
  593. unsigned int lookup_id, const char *name,
  594. const char *const *parent_names, u8 num_parents,
  595. const struct rockchip_cpuclk_reg_data *reg_data,
  596. const struct rockchip_cpuclk_rate_table *rates,
  597. int nrates);
  598. void rockchip_clk_protect_critical(const char *const clocks[], int nclocks);
  599. void rockchip_register_restart_notifier(struct rockchip_clk_provider *ctx,
  600. unsigned int reg, void (*cb)(void));
  601. #define ROCKCHIP_SOFTRST_HIWORD_MASK BIT(0)
  602. #ifdef CONFIG_RESET_CONTROLLER
  603. void rockchip_register_softrst(struct device_node *np,
  604. unsigned int num_regs,
  605. void __iomem *base, u8 flags);
  606. #else
  607. static inline void rockchip_register_softrst(struct device_node *np,
  608. unsigned int num_regs,
  609. void __iomem *base, u8 flags)
  610. {
  611. }
  612. #endif
  613. #endif