clk.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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. /**
  17. * struct samsung_clk_provider: information about clock provider
  18. * @reg_base: virtual address for the register base.
  19. * @lock: maintains exclusion between callbacks for a given clock-provider.
  20. * @clk_data: holds clock related data like clk_hw* and number of clocks.
  21. */
  22. struct samsung_clk_provider {
  23. void __iomem *reg_base;
  24. struct device *dev;
  25. spinlock_t lock;
  26. /* clk_data must be the last entry due to variable lenght 'hws' array */
  27. struct clk_hw_onecell_data clk_data;
  28. };
  29. /**
  30. * struct samsung_clock_alias: information about mux clock
  31. * @id: platform specific id of the clock.
  32. * @dev_name: name of the device to which this clock belongs.
  33. * @alias: optional clock alias name to be assigned to this clock.
  34. */
  35. struct samsung_clock_alias {
  36. unsigned int id;
  37. const char *dev_name;
  38. const char *alias;
  39. };
  40. #define ALIAS(_id, dname, a) \
  41. { \
  42. .id = _id, \
  43. .dev_name = dname, \
  44. .alias = a, \
  45. }
  46. #define MHZ (1000 * 1000)
  47. /**
  48. * struct samsung_fixed_rate_clock: information about fixed-rate clock
  49. * @id: platform specific id of the clock.
  50. * @name: name of this fixed-rate clock.
  51. * @parent_name: optional parent clock name.
  52. * @flags: optional fixed-rate clock flags.
  53. * @fixed-rate: fixed clock rate of this clock.
  54. */
  55. struct samsung_fixed_rate_clock {
  56. unsigned int id;
  57. char *name;
  58. const char *parent_name;
  59. unsigned long flags;
  60. unsigned long fixed_rate;
  61. };
  62. #define FRATE(_id, cname, pname, f, frate) \
  63. { \
  64. .id = _id, \
  65. .name = cname, \
  66. .parent_name = pname, \
  67. .flags = f, \
  68. .fixed_rate = frate, \
  69. }
  70. /*
  71. * struct samsung_fixed_factor_clock: information about fixed-factor clock
  72. * @id: platform specific id of the clock.
  73. * @name: name of this fixed-factor clock.
  74. * @parent_name: parent clock name.
  75. * @mult: fixed multiplication factor.
  76. * @div: fixed division factor.
  77. * @flags: optional fixed-factor clock flags.
  78. */
  79. struct samsung_fixed_factor_clock {
  80. unsigned int id;
  81. char *name;
  82. const char *parent_name;
  83. unsigned long mult;
  84. unsigned long div;
  85. unsigned long flags;
  86. };
  87. #define FFACTOR(_id, cname, pname, m, d, f) \
  88. { \
  89. .id = _id, \
  90. .name = cname, \
  91. .parent_name = pname, \
  92. .mult = m, \
  93. .div = d, \
  94. .flags = f, \
  95. }
  96. /**
  97. * struct samsung_mux_clock: information about mux clock
  98. * @id: platform specific id of the clock.
  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. */
  108. struct samsung_mux_clock {
  109. unsigned int id;
  110. const char *name;
  111. const char *const *parent_names;
  112. u8 num_parents;
  113. unsigned long flags;
  114. unsigned long offset;
  115. u8 shift;
  116. u8 width;
  117. u8 mux_flags;
  118. };
  119. #define __MUX(_id, cname, pnames, o, s, w, f, mf) \
  120. { \
  121. .id = _id, \
  122. .name = cname, \
  123. .parent_names = pnames, \
  124. .num_parents = ARRAY_SIZE(pnames), \
  125. .flags = (f) | CLK_SET_RATE_NO_REPARENT, \
  126. .offset = o, \
  127. .shift = s, \
  128. .width = w, \
  129. .mux_flags = mf, \
  130. }
  131. #define MUX(_id, cname, pnames, o, s, w) \
  132. __MUX(_id, cname, pnames, o, s, w, 0, 0)
  133. #define MUX_F(_id, cname, pnames, o, s, w, f, mf) \
  134. __MUX(_id, cname, pnames, o, s, w, f, mf)
  135. /**
  136. * @id: platform specific id of the clock.
  137. * struct samsung_div_clock: information about div clock
  138. * @name: name of this div clock.
  139. * @parent_name: name of the parent clock.
  140. * @flags: optional flags for basic clock.
  141. * @offset: offset of the register for configuring the div.
  142. * @shift: starting bit location of the div control bit-field in @reg.
  143. * @div_flags: flags for div-type clock.
  144. */
  145. struct samsung_div_clock {
  146. unsigned int id;
  147. const char *name;
  148. const char *parent_name;
  149. unsigned long flags;
  150. unsigned long offset;
  151. u8 shift;
  152. u8 width;
  153. u8 div_flags;
  154. struct clk_div_table *table;
  155. };
  156. #define __DIV(_id, cname, pname, o, s, w, f, df, t) \
  157. { \
  158. .id = _id, \
  159. .name = cname, \
  160. .parent_name = pname, \
  161. .flags = f, \
  162. .offset = o, \
  163. .shift = s, \
  164. .width = w, \
  165. .div_flags = df, \
  166. .table = t, \
  167. }
  168. #define DIV(_id, cname, pname, o, s, w) \
  169. __DIV(_id, cname, pname, o, s, w, 0, 0, NULL)
  170. #define DIV_F(_id, cname, pname, o, s, w, f, df) \
  171. __DIV(_id, cname, pname, o, s, w, f, df, NULL)
  172. #define DIV_T(_id, cname, pname, o, s, w, t) \
  173. __DIV(_id, cname, pname, o, s, w, 0, 0, t)
  174. /**
  175. * struct samsung_gate_clock: information about gate clock
  176. * @id: platform specific id of the clock.
  177. * @name: name of this gate clock.
  178. * @parent_name: name of the parent clock.
  179. * @flags: optional flags for basic clock.
  180. * @offset: offset of the register for configuring the gate.
  181. * @bit_idx: bit index of the gate control bit-field in @reg.
  182. * @gate_flags: flags for gate-type clock.
  183. */
  184. struct samsung_gate_clock {
  185. unsigned int id;
  186. const char *name;
  187. const char *parent_name;
  188. unsigned long flags;
  189. unsigned long offset;
  190. u8 bit_idx;
  191. u8 gate_flags;
  192. };
  193. #define __GATE(_id, cname, pname, o, b, f, gf) \
  194. { \
  195. .id = _id, \
  196. .name = cname, \
  197. .parent_name = pname, \
  198. .flags = f, \
  199. .offset = o, \
  200. .bit_idx = b, \
  201. .gate_flags = gf, \
  202. }
  203. #define GATE(_id, cname, pname, o, b, f, gf) \
  204. __GATE(_id, cname, pname, o, b, f, gf)
  205. #define PNAME(x) static const char * const x[] __initconst
  206. /**
  207. * struct samsung_clk_reg_dump: register dump of clock controller registers.
  208. * @offset: clock register offset from the controller base address.
  209. * @value: the value to be register at offset.
  210. */
  211. struct samsung_clk_reg_dump {
  212. u32 offset;
  213. u32 value;
  214. };
  215. /**
  216. * struct samsung_pll_clock: information about pll clock
  217. * @id: platform specific id of the clock.
  218. * @name: name of this pll clock.
  219. * @parent_name: name of the parent clock.
  220. * @flags: optional flags for basic clock.
  221. * @con_offset: offset of the register for configuring the PLL.
  222. * @lock_offset: offset of the register for locking the PLL.
  223. * @type: Type of PLL to be registered.
  224. */
  225. struct samsung_pll_clock {
  226. unsigned int id;
  227. const char *name;
  228. const char *parent_name;
  229. unsigned long flags;
  230. int con_offset;
  231. int lock_offset;
  232. enum samsung_pll_type type;
  233. const struct samsung_pll_rate_table *rate_table;
  234. };
  235. #define __PLL(_typ, _id, _name, _pname, _flags, _lock, _con, _rtable) \
  236. { \
  237. .id = _id, \
  238. .type = _typ, \
  239. .name = _name, \
  240. .parent_name = _pname, \
  241. .flags = _flags, \
  242. .con_offset = _con, \
  243. .lock_offset = _lock, \
  244. .rate_table = _rtable, \
  245. }
  246. #define PLL(_typ, _id, _name, _pname, _lock, _con, _rtable) \
  247. __PLL(_typ, _id, _name, _pname, CLK_GET_RATE_NOCACHE, _lock, \
  248. _con, _rtable)
  249. struct samsung_clock_reg_cache {
  250. struct list_head node;
  251. void __iomem *reg_base;
  252. struct samsung_clk_reg_dump *rdump;
  253. unsigned int rd_num;
  254. };
  255. struct samsung_cmu_info {
  256. /* list of pll clocks and respective count */
  257. const struct samsung_pll_clock *pll_clks;
  258. unsigned int nr_pll_clks;
  259. /* list of mux clocks and respective count */
  260. const struct samsung_mux_clock *mux_clks;
  261. unsigned int nr_mux_clks;
  262. /* list of div clocks and respective count */
  263. const struct samsung_div_clock *div_clks;
  264. unsigned int nr_div_clks;
  265. /* list of gate clocks and respective count */
  266. const struct samsung_gate_clock *gate_clks;
  267. unsigned int nr_gate_clks;
  268. /* list of fixed clocks and respective count */
  269. const struct samsung_fixed_rate_clock *fixed_clks;
  270. unsigned int nr_fixed_clks;
  271. /* list of fixed factor clocks and respective count */
  272. const struct samsung_fixed_factor_clock *fixed_factor_clks;
  273. unsigned int nr_fixed_factor_clks;
  274. /* total number of clocks with IDs assigned*/
  275. unsigned int nr_clk_ids;
  276. /* list and number of clocks registers */
  277. const unsigned long *clk_regs;
  278. unsigned int nr_clk_regs;
  279. /* list and number of clocks registers to set before suspend */
  280. const struct samsung_clk_reg_dump *suspend_regs;
  281. unsigned int nr_suspend_regs;
  282. /* name of the parent clock needed for CMU register access */
  283. const char *clk_name;
  284. };
  285. extern struct samsung_clk_provider *__init samsung_clk_init(
  286. struct device_node *np, void __iomem *base,
  287. unsigned long nr_clks);
  288. extern void __init samsung_clk_of_add_provider(struct device_node *np,
  289. struct samsung_clk_provider *ctx);
  290. extern void __init samsung_clk_of_register_fixed_ext(
  291. struct samsung_clk_provider *ctx,
  292. struct samsung_fixed_rate_clock *fixed_rate_clk,
  293. unsigned int nr_fixed_rate_clk,
  294. const struct of_device_id *clk_matches);
  295. extern void samsung_clk_add_lookup(struct samsung_clk_provider *ctx,
  296. struct clk_hw *clk_hw, unsigned int id);
  297. extern void __init samsung_clk_register_alias(struct samsung_clk_provider *ctx,
  298. const struct samsung_clock_alias *list,
  299. unsigned int nr_clk);
  300. extern void __init samsung_clk_register_fixed_rate(
  301. struct samsung_clk_provider *ctx,
  302. const struct samsung_fixed_rate_clock *clk_list,
  303. unsigned int nr_clk);
  304. extern void __init samsung_clk_register_fixed_factor(
  305. struct samsung_clk_provider *ctx,
  306. const struct samsung_fixed_factor_clock *list,
  307. unsigned int nr_clk);
  308. extern void __init samsung_clk_register_mux(struct samsung_clk_provider *ctx,
  309. const struct samsung_mux_clock *clk_list,
  310. unsigned int nr_clk);
  311. extern void __init samsung_clk_register_div(struct samsung_clk_provider *ctx,
  312. const struct samsung_div_clock *clk_list,
  313. unsigned int nr_clk);
  314. extern void __init samsung_clk_register_gate(struct samsung_clk_provider *ctx,
  315. const struct samsung_gate_clock *clk_list,
  316. unsigned int nr_clk);
  317. extern void __init samsung_clk_register_pll(struct samsung_clk_provider *ctx,
  318. const struct samsung_pll_clock *pll_list,
  319. unsigned int nr_clk, void __iomem *base);
  320. extern struct samsung_clk_provider __init *samsung_cmu_register_one(
  321. struct device_node *,
  322. const struct samsung_cmu_info *);
  323. extern unsigned long _get_rate(const char *clk_name);
  324. extern void samsung_clk_sleep_init(void __iomem *reg_base,
  325. const unsigned long *rdump,
  326. unsigned long nr_rdump);
  327. extern void samsung_clk_save(void __iomem *base,
  328. struct samsung_clk_reg_dump *rd,
  329. unsigned int num_regs);
  330. extern void samsung_clk_restore(void __iomem *base,
  331. const struct samsung_clk_reg_dump *rd,
  332. unsigned int num_regs);
  333. extern struct samsung_clk_reg_dump *samsung_clk_alloc_reg_dump(
  334. const unsigned long *rdump,
  335. unsigned long nr_rdump);
  336. #endif /* __SAMSUNG_CLK_H */