clk.h 20 KB

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