clk.h 7.5 KB

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