clk.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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.h>
  15. #include <linux/clkdev.h>
  16. #include <linux/io.h>
  17. #include <linux/clk-provider.h>
  18. #include <linux/of.h>
  19. #include <linux/of_address.h>
  20. /**
  21. * struct samsung_clock_alias: information about mux clock
  22. * @id: platform specific id of the clock.
  23. * @dev_name: name of the device to which this clock belongs.
  24. * @alias: optional clock alias name to be assigned to this clock.
  25. */
  26. struct samsung_clock_alias {
  27. unsigned int id;
  28. const char *dev_name;
  29. const char *alias;
  30. };
  31. #define ALIAS(_id, dname, a) \
  32. { \
  33. .id = _id, \
  34. .dev_name = dname, \
  35. .alias = a, \
  36. }
  37. /**
  38. * struct samsung_fixed_rate_clock: information about fixed-rate clock
  39. * @id: platform specific id of the clock.
  40. * @name: name of this fixed-rate clock.
  41. * @parent_name: optional parent clock name.
  42. * @flags: optional fixed-rate clock flags.
  43. * @fixed-rate: fixed clock rate of this clock.
  44. */
  45. struct samsung_fixed_rate_clock {
  46. unsigned int id;
  47. char *name;
  48. const char *parent_name;
  49. unsigned long flags;
  50. unsigned long fixed_rate;
  51. };
  52. #define FRATE(_id, cname, pname, f, frate) \
  53. { \
  54. .id = _id, \
  55. .name = cname, \
  56. .parent_name = pname, \
  57. .flags = f, \
  58. .fixed_rate = frate, \
  59. }
  60. /*
  61. * struct samsung_fixed_factor_clock: information about fixed-factor clock
  62. * @id: platform specific id of the clock.
  63. * @name: name of this fixed-factor clock.
  64. * @parent_name: parent clock name.
  65. * @mult: fixed multiplication factor.
  66. * @div: fixed division factor.
  67. * @flags: optional fixed-factor clock flags.
  68. */
  69. struct samsung_fixed_factor_clock {
  70. unsigned int id;
  71. char *name;
  72. const char *parent_name;
  73. unsigned long mult;
  74. unsigned long div;
  75. unsigned long flags;
  76. };
  77. #define FFACTOR(_id, cname, pname, m, d, f) \
  78. { \
  79. .id = _id, \
  80. .name = cname, \
  81. .parent_name = pname, \
  82. .mult = m, \
  83. .div = d, \
  84. .flags = f, \
  85. }
  86. /**
  87. * struct samsung_mux_clock: information about mux clock
  88. * @id: platform specific id of the clock.
  89. * @dev_name: name of the device to which this clock belongs.
  90. * @name: name of this mux clock.
  91. * @parent_names: array of pointer to parent clock names.
  92. * @num_parents: number of parents listed in @parent_names.
  93. * @flags: optional flags for basic clock.
  94. * @offset: offset of the register for configuring the mux.
  95. * @shift: starting bit location of the mux control bit-field in @reg.
  96. * @width: width of the mux control bit-field in @reg.
  97. * @mux_flags: flags for mux-type clock.
  98. * @alias: optional clock alias name to be assigned to this clock.
  99. */
  100. struct samsung_mux_clock {
  101. unsigned int id;
  102. const char *dev_name;
  103. const char *name;
  104. const char **parent_names;
  105. u8 num_parents;
  106. unsigned long flags;
  107. unsigned long offset;
  108. u8 shift;
  109. u8 width;
  110. u8 mux_flags;
  111. const char *alias;
  112. };
  113. #define __MUX(_id, dname, cname, pnames, o, s, w, f, mf, a) \
  114. { \
  115. .id = _id, \
  116. .dev_name = dname, \
  117. .name = cname, \
  118. .parent_names = pnames, \
  119. .num_parents = ARRAY_SIZE(pnames), \
  120. .flags = f, \
  121. .offset = o, \
  122. .shift = s, \
  123. .width = w, \
  124. .mux_flags = mf, \
  125. .alias = a, \
  126. }
  127. #define MUX(_id, cname, pnames, o, s, w) \
  128. __MUX(_id, NULL, cname, pnames, o, s, w, 0, 0, NULL)
  129. #define MUX_A(_id, cname, pnames, o, s, w, a) \
  130. __MUX(_id, NULL, cname, pnames, o, s, w, 0, 0, a)
  131. #define MUX_F(_id, cname, pnames, o, s, w, f, mf) \
  132. __MUX(_id, NULL, cname, pnames, o, s, w, f, mf, NULL)
  133. #define MUX_FA(_id, cname, pnames, o, s, w, f, mf, a) \
  134. __MUX(_id, NULL, cname, pnames, o, s, w, f, mf, a)
  135. /**
  136. * @id: platform specific id of the clock.
  137. * struct samsung_div_clock: information about div clock
  138. * @dev_name: name of the device to which this clock belongs.
  139. * @name: name of this div clock.
  140. * @parent_name: name of the parent clock.
  141. * @flags: optional flags for basic clock.
  142. * @offset: offset of the register for configuring the div.
  143. * @shift: starting bit location of the div control bit-field in @reg.
  144. * @div_flags: flags for div-type clock.
  145. * @alias: optional clock alias name to be assigned to this clock.
  146. */
  147. struct samsung_div_clock {
  148. unsigned int id;
  149. const char *dev_name;
  150. const char *name;
  151. const char *parent_name;
  152. unsigned long flags;
  153. unsigned long offset;
  154. u8 shift;
  155. u8 width;
  156. u8 div_flags;
  157. const char *alias;
  158. struct clk_div_table *table;
  159. };
  160. #define __DIV(_id, dname, cname, pname, o, s, w, f, df, a, t) \
  161. { \
  162. .id = _id, \
  163. .dev_name = dname, \
  164. .name = cname, \
  165. .parent_name = pname, \
  166. .flags = f, \
  167. .offset = o, \
  168. .shift = s, \
  169. .width = w, \
  170. .div_flags = df, \
  171. .alias = a, \
  172. .table = t, \
  173. }
  174. #define DIV(_id, cname, pname, o, s, w) \
  175. __DIV(_id, NULL, cname, pname, o, s, w, 0, 0, NULL, NULL)
  176. #define DIV_A(_id, cname, pname, o, s, w, a) \
  177. __DIV(_id, NULL, cname, pname, o, s, w, 0, 0, a, NULL)
  178. #define DIV_F(_id, cname, pname, o, s, w, f, df) \
  179. __DIV(_id, NULL, cname, pname, o, s, w, f, df, NULL, NULL)
  180. #define DIV_T(_id, cname, pname, o, s, w, t) \
  181. __DIV(_id, NULL, cname, pname, o, s, w, 0, 0, NULL, t)
  182. /**
  183. * struct samsung_gate_clock: information about gate clock
  184. * @id: platform specific id of the clock.
  185. * @dev_name: name of the device to which this clock belongs.
  186. * @name: name of this gate clock.
  187. * @parent_name: name of the parent clock.
  188. * @flags: optional flags for basic clock.
  189. * @offset: offset of the register for configuring the gate.
  190. * @bit_idx: bit index of the gate control bit-field in @reg.
  191. * @gate_flags: flags for gate-type clock.
  192. * @alias: optional clock alias name to be assigned to this clock.
  193. */
  194. struct samsung_gate_clock {
  195. unsigned int id;
  196. const char *dev_name;
  197. const char *name;
  198. const char *parent_name;
  199. unsigned long flags;
  200. unsigned long offset;
  201. u8 bit_idx;
  202. u8 gate_flags;
  203. const char *alias;
  204. };
  205. #define __GATE(_id, dname, cname, pname, o, b, f, gf, a) \
  206. { \
  207. .id = _id, \
  208. .dev_name = dname, \
  209. .name = cname, \
  210. .parent_name = pname, \
  211. .flags = f, \
  212. .offset = o, \
  213. .bit_idx = b, \
  214. .gate_flags = gf, \
  215. .alias = a, \
  216. }
  217. #define GATE(_id, cname, pname, o, b, f, gf) \
  218. __GATE(_id, NULL, cname, pname, o, b, f, gf, NULL)
  219. #define GATE_A(_id, cname, pname, o, b, f, gf, a) \
  220. __GATE(_id, NULL, cname, pname, o, b, f, gf, a)
  221. #define GATE_D(_id, dname, cname, pname, o, b, f, gf) \
  222. __GATE(_id, dname, cname, pname, o, b, f, gf, NULL)
  223. #define GATE_DA(_id, dname, cname, pname, o, b, f, gf, a) \
  224. __GATE(_id, dname, cname, pname, o, b, f, gf, a)
  225. #define PNAME(x) static const char *x[] __initdata
  226. /**
  227. * struct samsung_clk_reg_dump: register dump of clock controller registers.
  228. * @offset: clock register offset from the controller base address.
  229. * @value: the value to be register at offset.
  230. */
  231. struct samsung_clk_reg_dump {
  232. u32 offset;
  233. u32 value;
  234. };
  235. extern void __init samsung_clk_init(struct device_node *np, void __iomem *base,
  236. unsigned long nr_clks, unsigned long *rdump,
  237. unsigned long nr_rdump, unsigned long *soc_rdump,
  238. unsigned long nr_soc_rdump);
  239. extern void __init samsung_clk_of_register_fixed_ext(
  240. struct samsung_fixed_rate_clock *fixed_rate_clk,
  241. unsigned int nr_fixed_rate_clk,
  242. struct of_device_id *clk_matches);
  243. extern void samsung_clk_add_lookup(struct clk *clk, unsigned int id);
  244. extern void samsung_clk_register_alias(struct samsung_clock_alias *list,
  245. unsigned int nr_clk);
  246. extern void __init samsung_clk_register_fixed_rate(
  247. struct samsung_fixed_rate_clock *clk_list, unsigned int nr_clk);
  248. extern void __init samsung_clk_register_fixed_factor(
  249. struct samsung_fixed_factor_clock *list, unsigned int nr_clk);
  250. extern void __init samsung_clk_register_mux(struct samsung_mux_clock *clk_list,
  251. unsigned int nr_clk);
  252. extern void __init samsung_clk_register_div(struct samsung_div_clock *clk_list,
  253. unsigned int nr_clk);
  254. extern void __init samsung_clk_register_gate(
  255. struct samsung_gate_clock *clk_list, unsigned int nr_clk);
  256. extern unsigned long _get_rate(const char *clk_name);
  257. #endif /* __SAMSUNG_CLK_H */