clk.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. /*
  2. * Copyright (c) 2013 Samsung Electronics Co., Ltd.
  3. * Copyright (c) 2013 Linaro Ltd.
  4. * Author: Thomas Abraham <thomas.ab@samsung.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * Common Clock Framework support for all Samsung platforms
  11. */
  12. #ifndef __SAMSUNG_CLK_H
  13. #define __SAMSUNG_CLK_H
  14. #include <linux/clk-provider.h>
  15. #include "clk-pll.h"
  16. struct clk;
  17. /**
  18. * struct samsung_clk_provider: information about clock provider
  19. * @reg_base: virtual address for the register base.
  20. * @clk_data: holds clock related data like clk* and number of clocks.
  21. * @lock: maintains exclusion between callbacks for a given clock-provider.
  22. */
  23. struct samsung_clk_provider {
  24. void __iomem *reg_base;
  25. struct clk_onecell_data clk_data;
  26. spinlock_t lock;
  27. };
  28. /**
  29. * struct samsung_clock_alias: information about mux clock
  30. * @id: platform specific id of the clock.
  31. * @dev_name: name of the device to which this clock belongs.
  32. * @alias: optional clock alias name to be assigned to this clock.
  33. */
  34. struct samsung_clock_alias {
  35. unsigned int id;
  36. const char *dev_name;
  37. const char *alias;
  38. };
  39. #define ALIAS(_id, dname, a) \
  40. { \
  41. .id = _id, \
  42. .dev_name = dname, \
  43. .alias = a, \
  44. }
  45. #define MHZ (1000 * 1000)
  46. /**
  47. * struct samsung_fixed_rate_clock: information about fixed-rate clock
  48. * @id: platform specific id of the clock.
  49. * @name: name of this fixed-rate clock.
  50. * @parent_name: optional parent clock name.
  51. * @flags: optional fixed-rate clock flags.
  52. * @fixed-rate: fixed clock rate of this clock.
  53. */
  54. struct samsung_fixed_rate_clock {
  55. unsigned int id;
  56. char *name;
  57. const char *parent_name;
  58. unsigned long flags;
  59. unsigned long fixed_rate;
  60. };
  61. #define FRATE(_id, cname, pname, f, frate) \
  62. { \
  63. .id = _id, \
  64. .name = cname, \
  65. .parent_name = pname, \
  66. .flags = f, \
  67. .fixed_rate = frate, \
  68. }
  69. /*
  70. * struct samsung_fixed_factor_clock: information about fixed-factor clock
  71. * @id: platform specific id of the clock.
  72. * @name: name of this fixed-factor clock.
  73. * @parent_name: parent clock name.
  74. * @mult: fixed multiplication factor.
  75. * @div: fixed division factor.
  76. * @flags: optional fixed-factor clock flags.
  77. */
  78. struct samsung_fixed_factor_clock {
  79. unsigned int id;
  80. char *name;
  81. const char *parent_name;
  82. unsigned long mult;
  83. unsigned long div;
  84. unsigned long flags;
  85. };
  86. #define FFACTOR(_id, cname, pname, m, d, f) \
  87. { \
  88. .id = _id, \
  89. .name = cname, \
  90. .parent_name = pname, \
  91. .mult = m, \
  92. .div = d, \
  93. .flags = f, \
  94. }
  95. /**
  96. * struct samsung_mux_clock: information about mux clock
  97. * @id: platform specific id of the clock.
  98. * @dev_name: name of the device to which this clock belongs.
  99. * @name: name of this mux clock.
  100. * @parent_names: array of pointer to parent clock names.
  101. * @num_parents: number of parents listed in @parent_names.
  102. * @flags: optional flags for basic clock.
  103. * @offset: offset of the register for configuring the mux.
  104. * @shift: starting bit location of the mux control bit-field in @reg.
  105. * @width: width of the mux control bit-field in @reg.
  106. * @mux_flags: flags for mux-type clock.
  107. * @alias: optional clock alias name to be assigned to this clock.
  108. */
  109. struct samsung_mux_clock {
  110. unsigned int id;
  111. const char *dev_name;
  112. const char *name;
  113. const char *const *parent_names;
  114. u8 num_parents;
  115. unsigned long flags;
  116. unsigned long offset;
  117. u8 shift;
  118. u8 width;
  119. u8 mux_flags;
  120. const char *alias;
  121. };
  122. #define __MUX(_id, dname, cname, pnames, o, s, w, f, mf, a) \
  123. { \
  124. .id = _id, \
  125. .dev_name = dname, \
  126. .name = cname, \
  127. .parent_names = pnames, \
  128. .num_parents = ARRAY_SIZE(pnames), \
  129. .flags = (f) | CLK_SET_RATE_NO_REPARENT, \
  130. .offset = o, \
  131. .shift = s, \
  132. .width = w, \
  133. .mux_flags = mf, \
  134. .alias = a, \
  135. }
  136. #define MUX(_id, cname, pnames, o, s, w) \
  137. __MUX(_id, NULL, cname, pnames, o, s, w, 0, 0, NULL)
  138. #define MUX_A(_id, cname, pnames, o, s, w, a) \
  139. __MUX(_id, NULL, cname, pnames, o, s, w, 0, 0, a)
  140. #define MUX_F(_id, cname, pnames, o, s, w, f, mf) \
  141. __MUX(_id, NULL, cname, pnames, o, s, w, f, mf, NULL)
  142. #define MUX_FA(_id, cname, pnames, o, s, w, f, mf, a) \
  143. __MUX(_id, NULL, cname, pnames, o, s, w, f, mf, a)
  144. /**
  145. * @id: platform specific id of the clock.
  146. * struct samsung_div_clock: information about div clock
  147. * @dev_name: name of the device to which this clock belongs.
  148. * @name: name of this div clock.
  149. * @parent_name: name of the parent clock.
  150. * @flags: optional flags for basic clock.
  151. * @offset: offset of the register for configuring the div.
  152. * @shift: starting bit location of the div control bit-field in @reg.
  153. * @div_flags: flags for div-type clock.
  154. * @alias: optional clock alias name to be assigned to this clock.
  155. */
  156. struct samsung_div_clock {
  157. unsigned int id;
  158. const char *dev_name;
  159. const char *name;
  160. const char *parent_name;
  161. unsigned long flags;
  162. unsigned long offset;
  163. u8 shift;
  164. u8 width;
  165. u8 div_flags;
  166. const char *alias;
  167. struct clk_div_table *table;
  168. };
  169. #define __DIV(_id, dname, cname, pname, o, s, w, f, df, a, t) \
  170. { \
  171. .id = _id, \
  172. .dev_name = dname, \
  173. .name = cname, \
  174. .parent_name = pname, \
  175. .flags = f, \
  176. .offset = o, \
  177. .shift = s, \
  178. .width = w, \
  179. .div_flags = df, \
  180. .alias = a, \
  181. .table = t, \
  182. }
  183. #define DIV(_id, cname, pname, o, s, w) \
  184. __DIV(_id, NULL, cname, pname, o, s, w, 0, 0, NULL, NULL)
  185. #define DIV_A(_id, cname, pname, o, s, w, a) \
  186. __DIV(_id, NULL, cname, pname, o, s, w, 0, 0, a, NULL)
  187. #define DIV_F(_id, cname, pname, o, s, w, f, df) \
  188. __DIV(_id, NULL, cname, pname, o, s, w, f, df, NULL, NULL)
  189. #define DIV_T(_id, cname, pname, o, s, w, t) \
  190. __DIV(_id, NULL, cname, pname, o, s, w, 0, 0, NULL, t)
  191. /**
  192. * struct samsung_gate_clock: information about gate clock
  193. * @id: platform specific id of the clock.
  194. * @dev_name: name of the device to which this clock belongs.
  195. * @name: name of this gate clock.
  196. * @parent_name: name of the parent clock.
  197. * @flags: optional flags for basic clock.
  198. * @offset: offset of the register for configuring the gate.
  199. * @bit_idx: bit index of the gate control bit-field in @reg.
  200. * @gate_flags: flags for gate-type clock.
  201. * @alias: optional clock alias name to be assigned to this clock.
  202. */
  203. struct samsung_gate_clock {
  204. unsigned int id;
  205. const char *dev_name;
  206. const char *name;
  207. const char *parent_name;
  208. unsigned long flags;
  209. unsigned long offset;
  210. u8 bit_idx;
  211. u8 gate_flags;
  212. const char *alias;
  213. };
  214. #define __GATE(_id, dname, cname, pname, o, b, f, gf, a) \
  215. { \
  216. .id = _id, \
  217. .dev_name = dname, \
  218. .name = cname, \
  219. .parent_name = pname, \
  220. .flags = f, \
  221. .offset = o, \
  222. .bit_idx = b, \
  223. .gate_flags = gf, \
  224. .alias = a, \
  225. }
  226. #define GATE(_id, cname, pname, o, b, f, gf) \
  227. __GATE(_id, NULL, cname, pname, o, b, f, gf, NULL)
  228. #define GATE_A(_id, cname, pname, o, b, f, gf, a) \
  229. __GATE(_id, NULL, cname, pname, o, b, f, gf, a)
  230. #define GATE_D(_id, dname, cname, pname, o, b, f, gf) \
  231. __GATE(_id, dname, cname, pname, o, b, f, gf, NULL)
  232. #define GATE_DA(_id, dname, cname, pname, o, b, f, gf, a) \
  233. __GATE(_id, dname, cname, pname, o, b, f, gf, a)
  234. #define PNAME(x) static const char * const x[] __initconst
  235. /**
  236. * struct samsung_clk_reg_dump: register dump of clock controller registers.
  237. * @offset: clock register offset from the controller base address.
  238. * @value: the value to be register at offset.
  239. */
  240. struct samsung_clk_reg_dump {
  241. u32 offset;
  242. u32 value;
  243. };
  244. /**
  245. * struct samsung_pll_clock: information about pll clock
  246. * @id: platform specific id of the clock.
  247. * @dev_name: name of the device to which this clock belongs.
  248. * @name: name of this pll clock.
  249. * @parent_name: name of the parent clock.
  250. * @flags: optional flags for basic clock.
  251. * @con_offset: offset of the register for configuring the PLL.
  252. * @lock_offset: offset of the register for locking the PLL.
  253. * @type: Type of PLL to be registered.
  254. * @alias: optional clock alias name to be assigned to this clock.
  255. */
  256. struct samsung_pll_clock {
  257. unsigned int id;
  258. const char *dev_name;
  259. const char *name;
  260. const char *parent_name;
  261. unsigned long flags;
  262. int con_offset;
  263. int lock_offset;
  264. enum samsung_pll_type type;
  265. const struct samsung_pll_rate_table *rate_table;
  266. const char *alias;
  267. };
  268. #define __PLL(_typ, _id, _dname, _name, _pname, _flags, _lock, _con, \
  269. _rtable, _alias) \
  270. { \
  271. .id = _id, \
  272. .type = _typ, \
  273. .dev_name = _dname, \
  274. .name = _name, \
  275. .parent_name = _pname, \
  276. .flags = CLK_GET_RATE_NOCACHE, \
  277. .con_offset = _con, \
  278. .lock_offset = _lock, \
  279. .rate_table = _rtable, \
  280. .alias = _alias, \
  281. }
  282. #define PLL(_typ, _id, _name, _pname, _lock, _con, _rtable) \
  283. __PLL(_typ, _id, NULL, _name, _pname, CLK_GET_RATE_NOCACHE, \
  284. _lock, _con, _rtable, _name)
  285. #define PLL_A(_typ, _id, _name, _pname, _lock, _con, _alias, _rtable) \
  286. __PLL(_typ, _id, NULL, _name, _pname, CLK_GET_RATE_NOCACHE, \
  287. _lock, _con, _rtable, _alias)
  288. struct samsung_clock_reg_cache {
  289. struct list_head node;
  290. void __iomem *reg_base;
  291. struct samsung_clk_reg_dump *rdump;
  292. unsigned int rd_num;
  293. };
  294. struct samsung_cmu_info {
  295. /* list of pll clocks and respective count */
  296. const struct samsung_pll_clock *pll_clks;
  297. unsigned int nr_pll_clks;
  298. /* list of mux clocks and respective count */
  299. const struct samsung_mux_clock *mux_clks;
  300. unsigned int nr_mux_clks;
  301. /* list of div clocks and respective count */
  302. const struct samsung_div_clock *div_clks;
  303. unsigned int nr_div_clks;
  304. /* list of gate clocks and respective count */
  305. const struct samsung_gate_clock *gate_clks;
  306. unsigned int nr_gate_clks;
  307. /* list of fixed clocks and respective count */
  308. const struct samsung_fixed_rate_clock *fixed_clks;
  309. unsigned int nr_fixed_clks;
  310. /* list of fixed factor clocks and respective count */
  311. const struct samsung_fixed_factor_clock *fixed_factor_clks;
  312. unsigned int nr_fixed_factor_clks;
  313. /* total number of clocks with IDs assigned*/
  314. unsigned int nr_clk_ids;
  315. /* list and number of clocks registers */
  316. const unsigned long *clk_regs;
  317. unsigned int nr_clk_regs;
  318. };
  319. extern struct samsung_clk_provider *__init samsung_clk_init(
  320. struct device_node *np, void __iomem *base,
  321. unsigned long nr_clks);
  322. extern void __init samsung_clk_of_add_provider(struct device_node *np,
  323. struct samsung_clk_provider *ctx);
  324. extern void __init samsung_clk_of_register_fixed_ext(
  325. struct samsung_clk_provider *ctx,
  326. struct samsung_fixed_rate_clock *fixed_rate_clk,
  327. unsigned int nr_fixed_rate_clk,
  328. const struct of_device_id *clk_matches);
  329. extern void samsung_clk_add_lookup(struct samsung_clk_provider *ctx,
  330. struct clk *clk, unsigned int id);
  331. extern void __init samsung_clk_register_alias(struct samsung_clk_provider *ctx,
  332. const struct samsung_clock_alias *list,
  333. unsigned int nr_clk);
  334. extern void __init samsung_clk_register_fixed_rate(
  335. struct samsung_clk_provider *ctx,
  336. const struct samsung_fixed_rate_clock *clk_list,
  337. unsigned int nr_clk);
  338. extern void __init samsung_clk_register_fixed_factor(
  339. struct samsung_clk_provider *ctx,
  340. const struct samsung_fixed_factor_clock *list,
  341. unsigned int nr_clk);
  342. extern void __init samsung_clk_register_mux(struct samsung_clk_provider *ctx,
  343. const struct samsung_mux_clock *clk_list,
  344. unsigned int nr_clk);
  345. extern void __init samsung_clk_register_div(struct samsung_clk_provider *ctx,
  346. const struct samsung_div_clock *clk_list,
  347. unsigned int nr_clk);
  348. extern void __init samsung_clk_register_gate(struct samsung_clk_provider *ctx,
  349. const struct samsung_gate_clock *clk_list,
  350. unsigned int nr_clk);
  351. extern void __init samsung_clk_register_pll(struct samsung_clk_provider *ctx,
  352. const struct samsung_pll_clock *pll_list,
  353. unsigned int nr_clk, void __iomem *base);
  354. extern struct samsung_clk_provider __init *samsung_cmu_register_one(
  355. struct device_node *,
  356. const struct samsung_cmu_info *);
  357. extern unsigned long _get_rate(const char *clk_name);
  358. extern void samsung_clk_sleep_init(void __iomem *reg_base,
  359. const unsigned long *rdump,
  360. unsigned long nr_rdump);
  361. extern void samsung_clk_save(void __iomem *base,
  362. struct samsung_clk_reg_dump *rd,
  363. unsigned int num_regs);
  364. extern void samsung_clk_restore(void __iomem *base,
  365. const struct samsung_clk_reg_dump *rd,
  366. unsigned int num_regs);
  367. extern struct samsung_clk_reg_dump *samsung_clk_alloc_reg_dump(
  368. const unsigned long *rdump,
  369. unsigned long nr_rdump);
  370. #endif /* __SAMSUNG_CLK_H */