cgu.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /*
  2. * Ingenic SoC CGU driver
  3. *
  4. * Copyright (c) 2013-2015 Imagination Technologies
  5. * Author: Paul Burton <paul.burton@imgtec.com>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. */
  17. #ifndef __DRIVERS_CLK_INGENIC_CGU_H__
  18. #define __DRIVERS_CLK_INGENIC_CGU_H__
  19. #include <linux/bitops.h>
  20. #include <linux/of.h>
  21. #include <linux/spinlock.h>
  22. /**
  23. * struct ingenic_cgu_pll_info - information about a PLL
  24. * @reg: the offset of the PLL's control register within the CGU
  25. * @m_shift: the number of bits to shift the multiplier value by (ie. the
  26. * index of the lowest bit of the multiplier value in the PLL's
  27. * control register)
  28. * @m_bits: the size of the multiplier field in bits
  29. * @m_offset: the multiplier value which encodes to 0 in the PLL's control
  30. * register
  31. * @n_shift: the number of bits to shift the divider value by (ie. the
  32. * index of the lowest bit of the divider value in the PLL's
  33. * control register)
  34. * @n_bits: the size of the divider field in bits
  35. * @n_offset: the divider value which encodes to 0 in the PLL's control
  36. * register
  37. * @od_shift: the number of bits to shift the post-VCO divider value by (ie.
  38. * the index of the lowest bit of the post-VCO divider value in
  39. * the PLL's control register)
  40. * @od_bits: the size of the post-VCO divider field in bits
  41. * @od_max: the maximum post-VCO divider value
  42. * @od_encoding: a pointer to an array mapping post-VCO divider values to
  43. * their encoded values in the PLL control register, or -1 for
  44. * unsupported values
  45. * @bypass_bit: the index of the bypass bit in the PLL control register
  46. * @enable_bit: the index of the enable bit in the PLL control register
  47. * @stable_bit: the index of the stable bit in the PLL control register
  48. */
  49. struct ingenic_cgu_pll_info {
  50. unsigned reg;
  51. const s8 *od_encoding;
  52. u8 m_shift, m_bits, m_offset;
  53. u8 n_shift, n_bits, n_offset;
  54. u8 od_shift, od_bits, od_max;
  55. u8 bypass_bit;
  56. u8 enable_bit;
  57. u8 stable_bit;
  58. };
  59. /**
  60. * struct ingenic_cgu_mux_info - information about a clock mux
  61. * @reg: offset of the mux control register within the CGU
  62. * @shift: number of bits to shift the mux value by (ie. the index of
  63. * the lowest bit of the mux value within its control register)
  64. * @bits: the size of the mux value in bits
  65. */
  66. struct ingenic_cgu_mux_info {
  67. unsigned reg;
  68. u8 shift;
  69. u8 bits;
  70. };
  71. /**
  72. * struct ingenic_cgu_div_info - information about a divider
  73. * @reg: offset of the divider control register within the CGU
  74. * @shift: number of bits to left shift the divide value by (ie. the index of
  75. * the lowest bit of the divide value within its control register)
  76. * @div: number of bits to divide the divider value by (i.e. if the
  77. * effective divider value is the value written to the register
  78. * multiplied by some constant)
  79. * @bits: the size of the divide value in bits
  80. * @ce_bit: the index of the change enable bit within reg, or -1 if there
  81. * isn't one
  82. * @busy_bit: the index of the busy bit within reg, or -1 if there isn't one
  83. * @stop_bit: the index of the stop bit within reg, or -1 if there isn't one
  84. */
  85. struct ingenic_cgu_div_info {
  86. unsigned reg;
  87. u8 shift;
  88. u8 div;
  89. u8 bits;
  90. s8 ce_bit;
  91. s8 busy_bit;
  92. s8 stop_bit;
  93. };
  94. /**
  95. * struct ingenic_cgu_fixdiv_info - information about a fixed divider
  96. * @div: the divider applied to the parent clock
  97. */
  98. struct ingenic_cgu_fixdiv_info {
  99. unsigned div;
  100. };
  101. /**
  102. * struct ingenic_cgu_gate_info - information about a clock gate
  103. * @reg: offset of the gate control register within the CGU
  104. * @bit: offset of the bit in the register that controls the gate
  105. */
  106. struct ingenic_cgu_gate_info {
  107. unsigned reg;
  108. u8 bit;
  109. };
  110. /**
  111. * struct ingenic_cgu_custom_info - information about a custom (SoC) clock
  112. * @clk_ops: custom clock operation callbacks
  113. */
  114. struct ingenic_cgu_custom_info {
  115. struct clk_ops *clk_ops;
  116. };
  117. /**
  118. * struct ingenic_cgu_clk_info - information about a clock
  119. * @name: name of the clock
  120. * @type: a bitmask formed from CGU_CLK_* values
  121. * @parents: an array of the indices of potential parents of this clock
  122. * within the clock_info array of the CGU, or -1 in entries
  123. * which correspond to no valid parent
  124. * @pll: information valid if type includes CGU_CLK_PLL
  125. * @gate: information valid if type includes CGU_CLK_GATE
  126. * @mux: information valid if type includes CGU_CLK_MUX
  127. * @div: information valid if type includes CGU_CLK_DIV
  128. * @fixdiv: information valid if type includes CGU_CLK_FIXDIV
  129. * @custom: information valid if type includes CGU_CLK_CUSTOM
  130. */
  131. struct ingenic_cgu_clk_info {
  132. const char *name;
  133. enum {
  134. CGU_CLK_NONE = 0,
  135. CGU_CLK_EXT = BIT(0),
  136. CGU_CLK_PLL = BIT(1),
  137. CGU_CLK_GATE = BIT(2),
  138. CGU_CLK_MUX = BIT(3),
  139. CGU_CLK_MUX_GLITCHFREE = BIT(4),
  140. CGU_CLK_DIV = BIT(5),
  141. CGU_CLK_FIXDIV = BIT(6),
  142. CGU_CLK_CUSTOM = BIT(7),
  143. } type;
  144. int parents[4];
  145. union {
  146. struct ingenic_cgu_pll_info pll;
  147. struct {
  148. struct ingenic_cgu_gate_info gate;
  149. struct ingenic_cgu_mux_info mux;
  150. struct ingenic_cgu_div_info div;
  151. struct ingenic_cgu_fixdiv_info fixdiv;
  152. };
  153. struct ingenic_cgu_custom_info custom;
  154. };
  155. };
  156. /**
  157. * struct ingenic_cgu - data about the CGU
  158. * @np: the device tree node that caused the CGU to be probed
  159. * @base: the ioremap'ed base address of the CGU registers
  160. * @clock_info: an array containing information about implemented clocks
  161. * @clocks: used to provide clocks to DT, allows lookup of struct clk*
  162. * @lock: lock to be held whilst manipulating CGU registers
  163. */
  164. struct ingenic_cgu {
  165. struct device_node *np;
  166. void __iomem *base;
  167. const struct ingenic_cgu_clk_info *clock_info;
  168. struct clk_onecell_data clocks;
  169. spinlock_t lock;
  170. };
  171. /**
  172. * struct ingenic_clk - private data for a clock
  173. * @hw: see Documentation/clk.txt
  174. * @cgu: a pointer to the CGU data
  175. * @idx: the index of this clock in cgu->clock_info
  176. */
  177. struct ingenic_clk {
  178. struct clk_hw hw;
  179. struct ingenic_cgu *cgu;
  180. unsigned idx;
  181. };
  182. #define to_ingenic_clk(_hw) container_of(_hw, struct ingenic_clk, hw)
  183. /**
  184. * ingenic_cgu_new() - create a new CGU instance
  185. * @clock_info: an array of clock information structures describing the clocks
  186. * which are implemented by the CGU
  187. * @num_clocks: the number of entries in clock_info
  188. * @np: the device tree node which causes this CGU to be probed
  189. *
  190. * Return: a pointer to the CGU instance if initialisation is successful,
  191. * otherwise NULL.
  192. */
  193. struct ingenic_cgu *
  194. ingenic_cgu_new(const struct ingenic_cgu_clk_info *clock_info,
  195. unsigned num_clocks, struct device_node *np);
  196. /**
  197. * ingenic_cgu_register_clocks() - Registers the clocks
  198. * @cgu: pointer to cgu data
  199. *
  200. * Register the clocks described by the CGU with the common clock framework.
  201. *
  202. * Return: 0 on success or -errno if unsuccesful.
  203. */
  204. int ingenic_cgu_register_clocks(struct ingenic_cgu *cgu);
  205. #endif /* __DRIVERS_CLK_INGENIC_CGU_H__ */