clock.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /*
  2. * arch/arm/plat-spear/include/plat/clock.h
  3. *
  4. * Clock framework definitions for SPEAr platform
  5. *
  6. * Copyright (C) 2009 ST Microelectronics
  7. * Viresh Kumar<viresh.kumar@st.com>
  8. *
  9. * This file is licensed under the terms of the GNU General Public
  10. * License version 2. This program is licensed "as is" without any
  11. * warranty of any kind, whether express or implied.
  12. */
  13. #ifndef __PLAT_CLOCK_H
  14. #define __PLAT_CLOCK_H
  15. #include <linux/list.h>
  16. #include <linux/clkdev.h>
  17. #include <linux/types.h>
  18. /* clk structure flags */
  19. #define ALWAYS_ENABLED (1 << 0) /* clock always enabled */
  20. #define RESET_TO_ENABLE (1 << 1) /* reset register bit to enable clk */
  21. #define ENABLED_ON_INIT (1 << 2) /* clocks enabled at init */
  22. /**
  23. * struct clkops - clock operations
  24. * @enable: pointer to clock enable function
  25. * @disable: pointer to clock disable function
  26. */
  27. struct clkops {
  28. int (*enable) (struct clk *);
  29. void (*disable) (struct clk *);
  30. };
  31. /**
  32. * struct pclk_info - parents info
  33. * @pclk: pointer to parent clk
  34. * @pclk_val: value to be written for selecting this parent
  35. */
  36. struct pclk_info {
  37. struct clk *pclk;
  38. u8 pclk_val;
  39. };
  40. /**
  41. * struct pclk_sel - parents selection configuration
  42. * @pclk_info: pointer to array of parent clock info
  43. * @pclk_count: number of parents
  44. * @pclk_sel_reg: register for selecting a parent
  45. * @pclk_sel_mask: mask for selecting parent (can be used to clear bits also)
  46. */
  47. struct pclk_sel {
  48. struct pclk_info *pclk_info;
  49. u8 pclk_count;
  50. void __iomem *pclk_sel_reg;
  51. unsigned int pclk_sel_mask;
  52. };
  53. /**
  54. * struct rate_config - clk rate configurations
  55. * @tbls: array of device specific clk rate tables, in ascending order of rates
  56. * @count: size of tbls array
  57. * @default_index: default setting when originally disabled
  58. */
  59. struct rate_config {
  60. void *tbls;
  61. u8 count;
  62. u8 default_index;
  63. };
  64. /**
  65. * struct clk - clock structure
  66. * @usage_count: num of users who enabled this clock
  67. * @flags: flags for clock properties
  68. * @rate: programmed clock rate in Hz
  69. * @en_reg: clk enable/disable reg
  70. * @en_reg_bit: clk enable/disable bit
  71. * @ops: clk enable/disable ops - generic_clkops selected if NULL
  72. * @recalc: pointer to clock rate recalculate function
  73. * @set_rate: pointer to clock set rate function
  74. * @calc_rate: pointer to clock get rate function for index
  75. * @rate_config: rate configuration information, used by set_rate
  76. * @div_factor: division factor to parent clock.
  77. * @pclk: current parent clk
  78. * @pclk_sel: pointer to parent selection structure
  79. * @pclk_sel_shift: register shift for selecting parent of this clock
  80. * @children: list for childrens or this clock
  81. * @sibling: node for list of clocks having same parents
  82. * @private_data: clock specific private data
  83. */
  84. struct clk {
  85. unsigned int usage_count;
  86. unsigned int flags;
  87. unsigned long rate;
  88. void __iomem *en_reg;
  89. u8 en_reg_bit;
  90. const struct clkops *ops;
  91. int (*recalc) (struct clk *);
  92. int (*set_rate) (struct clk *, unsigned long rate);
  93. unsigned long (*calc_rate)(struct clk *, int index);
  94. struct rate_config rate_config;
  95. unsigned int div_factor;
  96. struct clk *pclk;
  97. struct pclk_sel *pclk_sel;
  98. unsigned int pclk_sel_shift;
  99. struct list_head children;
  100. struct list_head sibling;
  101. void *private_data;
  102. };
  103. /* pll configuration structure */
  104. struct pll_clk_masks {
  105. u32 mode_mask;
  106. u32 mode_shift;
  107. u32 norm_fdbk_m_mask;
  108. u32 norm_fdbk_m_shift;
  109. u32 dith_fdbk_m_mask;
  110. u32 dith_fdbk_m_shift;
  111. u32 div_p_mask;
  112. u32 div_p_shift;
  113. u32 div_n_mask;
  114. u32 div_n_shift;
  115. };
  116. struct pll_clk_config {
  117. void __iomem *mode_reg;
  118. void __iomem *cfg_reg;
  119. struct pll_clk_masks *masks;
  120. };
  121. /* pll clk rate config structure */
  122. struct pll_rate_tbl {
  123. u8 mode;
  124. u16 m;
  125. u8 n;
  126. u8 p;
  127. };
  128. /* ahb and apb bus configuration structure */
  129. struct bus_clk_masks {
  130. u32 mask;
  131. u32 shift;
  132. };
  133. struct bus_clk_config {
  134. void __iomem *reg;
  135. struct bus_clk_masks *masks;
  136. };
  137. /* ahb and apb clk bus rate config structure */
  138. struct bus_rate_tbl {
  139. u8 div;
  140. };
  141. /* Aux clk configuration structure: applicable to UART and FIRDA */
  142. struct aux_clk_masks {
  143. u32 eq_sel_mask;
  144. u32 eq_sel_shift;
  145. u32 eq1_mask;
  146. u32 eq2_mask;
  147. u32 xscale_sel_mask;
  148. u32 xscale_sel_shift;
  149. u32 yscale_sel_mask;
  150. u32 yscale_sel_shift;
  151. };
  152. struct aux_clk_config {
  153. void __iomem *synth_reg;
  154. struct aux_clk_masks *masks;
  155. };
  156. /* aux clk rate config structure */
  157. struct aux_rate_tbl {
  158. u16 xscale;
  159. u16 yscale;
  160. u8 eq;
  161. };
  162. /* GPT clk configuration structure */
  163. struct gpt_clk_masks {
  164. u32 mscale_sel_mask;
  165. u32 mscale_sel_shift;
  166. u32 nscale_sel_mask;
  167. u32 nscale_sel_shift;
  168. };
  169. struct gpt_clk_config {
  170. void __iomem *synth_reg;
  171. struct gpt_clk_masks *masks;
  172. };
  173. /* gpt clk rate config structure */
  174. struct gpt_rate_tbl {
  175. u16 mscale;
  176. u16 nscale;
  177. };
  178. /* clcd clk configuration structure */
  179. struct clcd_synth_masks {
  180. u32 div_factor_mask;
  181. u32 div_factor_shift;
  182. };
  183. struct clcd_clk_config {
  184. void __iomem *synth_reg;
  185. struct clcd_synth_masks *masks;
  186. };
  187. /* clcd clk rate config structure */
  188. struct clcd_rate_tbl {
  189. u16 div;
  190. };
  191. /* platform specific clock functions */
  192. void clk_register(struct clk_lookup *cl);
  193. void recalc_root_clocks(void);
  194. /* clock recalc & set rate functions */
  195. int follow_parent(struct clk *clk);
  196. unsigned long pll_calc_rate(struct clk *clk, int index);
  197. int pll_clk_recalc(struct clk *clk);
  198. int pll_clk_set_rate(struct clk *clk, unsigned long desired_rate);
  199. unsigned long bus_calc_rate(struct clk *clk, int index);
  200. int bus_clk_recalc(struct clk *clk);
  201. int bus_clk_set_rate(struct clk *clk, unsigned long desired_rate);
  202. unsigned long gpt_calc_rate(struct clk *clk, int index);
  203. int gpt_clk_recalc(struct clk *clk);
  204. int gpt_clk_set_rate(struct clk *clk, unsigned long desired_rate);
  205. unsigned long aux_calc_rate(struct clk *clk, int index);
  206. int aux_clk_recalc(struct clk *clk);
  207. int aux_clk_set_rate(struct clk *clk, unsigned long desired_rate);
  208. unsigned long clcd_calc_rate(struct clk *clk, int index);
  209. int clcd_clk_recalc(struct clk *clk);
  210. int clcd_clk_set_rate(struct clk *clk, unsigned long desired_rate);
  211. #endif /* __PLAT_CLOCK_H */