clk.h 11 KB

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