clk.h 9.8 KB

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