clk.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. /**
  134. * @id: platform specific id of the clock.
  135. * struct samsung_div_clock: information about div clock
  136. * @dev_name: name of the device to which this clock belongs.
  137. * @name: name of this div clock.
  138. * @parent_name: name of the parent clock.
  139. * @flags: optional flags for basic clock.
  140. * @offset: offset of the register for configuring the div.
  141. * @shift: starting bit location of the div control bit-field in @reg.
  142. * @div_flags: flags for div-type clock.
  143. * @alias: optional clock alias name to be assigned to this clock.
  144. */
  145. struct samsung_div_clock {
  146. unsigned int id;
  147. const char *dev_name;
  148. const char *name;
  149. const char *parent_name;
  150. unsigned long flags;
  151. unsigned long offset;
  152. u8 shift;
  153. u8 width;
  154. u8 div_flags;
  155. const char *alias;
  156. struct clk_div_table *table;
  157. };
  158. #define __DIV(_id, dname, cname, pname, o, s, w, f, df, a, t) \
  159. { \
  160. .id = _id, \
  161. .dev_name = dname, \
  162. .name = cname, \
  163. .parent_name = pname, \
  164. .flags = f, \
  165. .offset = o, \
  166. .shift = s, \
  167. .width = w, \
  168. .div_flags = df, \
  169. .alias = a, \
  170. .table = t, \
  171. }
  172. #define DIV(_id, cname, pname, o, s, w) \
  173. __DIV(_id, NULL, cname, pname, o, s, w, 0, 0, NULL, NULL)
  174. #define DIV_A(_id, cname, pname, o, s, w, a) \
  175. __DIV(_id, NULL, cname, pname, o, s, w, 0, 0, a, NULL)
  176. #define DIV_F(_id, cname, pname, o, s, w, f, df) \
  177. __DIV(_id, NULL, cname, pname, o, s, w, f, df, NULL, NULL)
  178. #define DIV_T(_id, cname, pname, o, s, w, t) \
  179. __DIV(_id, NULL, cname, pname, o, s, w, 0, 0, NULL, t)
  180. /**
  181. * struct samsung_gate_clock: information about gate clock
  182. * @id: platform specific id of the clock.
  183. * @dev_name: name of the device to which this clock belongs.
  184. * @name: name of this gate clock.
  185. * @parent_name: name of the parent clock.
  186. * @flags: optional flags for basic clock.
  187. * @offset: offset of the register for configuring the gate.
  188. * @bit_idx: bit index of the gate control bit-field in @reg.
  189. * @gate_flags: flags for gate-type clock.
  190. * @alias: optional clock alias name to be assigned to this clock.
  191. */
  192. struct samsung_gate_clock {
  193. unsigned int id;
  194. const char *dev_name;
  195. const char *name;
  196. const char *parent_name;
  197. unsigned long flags;
  198. unsigned long offset;
  199. u8 bit_idx;
  200. u8 gate_flags;
  201. const char *alias;
  202. };
  203. #define __GATE(_id, dname, cname, pname, o, b, f, gf, a) \
  204. { \
  205. .id = _id, \
  206. .dev_name = dname, \
  207. .name = cname, \
  208. .parent_name = pname, \
  209. .flags = f, \
  210. .offset = o, \
  211. .bit_idx = b, \
  212. .gate_flags = gf, \
  213. .alias = a, \
  214. }
  215. #define GATE(_id, cname, pname, o, b, f, gf) \
  216. __GATE(_id, NULL, cname, pname, o, b, f, gf, NULL)
  217. #define GATE_A(_id, cname, pname, o, b, f, gf, a) \
  218. __GATE(_id, NULL, cname, pname, o, b, f, gf, a)
  219. #define GATE_D(_id, dname, cname, pname, o, b, f, gf) \
  220. __GATE(_id, dname, cname, pname, o, b, f, gf, NULL)
  221. #define GATE_DA(_id, dname, cname, pname, o, b, f, gf, a) \
  222. __GATE(_id, dname, cname, pname, o, b, f, gf, a)
  223. #define PNAME(x) static const char *x[] __initdata
  224. /**
  225. * struct samsung_clk_reg_dump: register dump of clock controller registers.
  226. * @offset: clock register offset from the controller base address.
  227. * @value: the value to be register at offset.
  228. */
  229. struct samsung_clk_reg_dump {
  230. u32 offset;
  231. u32 value;
  232. };
  233. extern void __init samsung_clk_init(struct device_node *np, void __iomem *base,
  234. unsigned long nr_clks, unsigned long *rdump,
  235. unsigned long nr_rdump, unsigned long *soc_rdump,
  236. unsigned long nr_soc_rdump);
  237. extern void __init samsung_clk_of_register_fixed_ext(
  238. struct samsung_fixed_rate_clock *fixed_rate_clk,
  239. unsigned int nr_fixed_rate_clk,
  240. struct of_device_id *clk_matches);
  241. extern void samsung_clk_add_lookup(struct clk *clk, unsigned int id);
  242. extern void samsung_clk_register_alias(struct samsung_clock_alias *list,
  243. unsigned int nr_clk);
  244. extern void __init samsung_clk_register_fixed_rate(
  245. struct samsung_fixed_rate_clock *clk_list, unsigned int nr_clk);
  246. extern void __init samsung_clk_register_fixed_factor(
  247. struct samsung_fixed_factor_clock *list, unsigned int nr_clk);
  248. extern void __init samsung_clk_register_mux(struct samsung_mux_clock *clk_list,
  249. unsigned int nr_clk);
  250. extern void __init samsung_clk_register_div(struct samsung_div_clock *clk_list,
  251. unsigned int nr_clk);
  252. extern void __init samsung_clk_register_gate(
  253. struct samsung_gate_clock *clk_list, unsigned int nr_clk);
  254. extern unsigned long _get_rate(const char *clk_name);
  255. #endif /* __SAMSUNG_CLK_H */