clk.h 19 KB

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