clock.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. * @node: list to maintain clocks linearly
  84. * @cl: clocklook up assoicated with this clock
  85. * @dent: object for debugfs
  86. */
  87. struct clk {
  88. unsigned int usage_count;
  89. unsigned int flags;
  90. unsigned long rate;
  91. void __iomem *en_reg;
  92. u8 en_reg_bit;
  93. const struct clkops *ops;
  94. int (*recalc) (struct clk *);
  95. int (*set_rate) (struct clk *, unsigned long rate);
  96. unsigned long (*calc_rate)(struct clk *, int index);
  97. struct rate_config rate_config;
  98. unsigned int div_factor;
  99. struct clk *pclk;
  100. struct pclk_sel *pclk_sel;
  101. unsigned int pclk_sel_shift;
  102. struct list_head children;
  103. struct list_head sibling;
  104. void *private_data;
  105. #ifdef CONFIG_DEBUG_FS
  106. struct list_head node;
  107. struct clk_lookup *cl;
  108. struct dentry *dent;
  109. #endif
  110. };
  111. /* pll configuration structure */
  112. struct pll_clk_masks {
  113. u32 mode_mask;
  114. u32 mode_shift;
  115. u32 norm_fdbk_m_mask;
  116. u32 norm_fdbk_m_shift;
  117. u32 dith_fdbk_m_mask;
  118. u32 dith_fdbk_m_shift;
  119. u32 div_p_mask;
  120. u32 div_p_shift;
  121. u32 div_n_mask;
  122. u32 div_n_shift;
  123. };
  124. struct pll_clk_config {
  125. void __iomem *mode_reg;
  126. void __iomem *cfg_reg;
  127. struct pll_clk_masks *masks;
  128. };
  129. /* pll clk rate config structure */
  130. struct pll_rate_tbl {
  131. u8 mode;
  132. u16 m;
  133. u8 n;
  134. u8 p;
  135. };
  136. /* ahb and apb bus configuration structure */
  137. struct bus_clk_masks {
  138. u32 mask;
  139. u32 shift;
  140. };
  141. struct bus_clk_config {
  142. void __iomem *reg;
  143. struct bus_clk_masks *masks;
  144. };
  145. /* ahb and apb clk bus rate config structure */
  146. struct bus_rate_tbl {
  147. u8 div;
  148. };
  149. /* Aux clk configuration structure: applicable to UART and FIRDA */
  150. struct aux_clk_masks {
  151. u32 eq_sel_mask;
  152. u32 eq_sel_shift;
  153. u32 eq1_mask;
  154. u32 eq2_mask;
  155. u32 xscale_sel_mask;
  156. u32 xscale_sel_shift;
  157. u32 yscale_sel_mask;
  158. u32 yscale_sel_shift;
  159. };
  160. struct aux_clk_config {
  161. void __iomem *synth_reg;
  162. struct aux_clk_masks *masks;
  163. };
  164. /* aux clk rate config structure */
  165. struct aux_rate_tbl {
  166. u16 xscale;
  167. u16 yscale;
  168. u8 eq;
  169. };
  170. /* GPT clk configuration structure */
  171. struct gpt_clk_masks {
  172. u32 mscale_sel_mask;
  173. u32 mscale_sel_shift;
  174. u32 nscale_sel_mask;
  175. u32 nscale_sel_shift;
  176. };
  177. struct gpt_clk_config {
  178. void __iomem *synth_reg;
  179. struct gpt_clk_masks *masks;
  180. };
  181. /* gpt clk rate config structure */
  182. struct gpt_rate_tbl {
  183. u16 mscale;
  184. u16 nscale;
  185. };
  186. /* clcd clk configuration structure */
  187. struct clcd_synth_masks {
  188. u32 div_factor_mask;
  189. u32 div_factor_shift;
  190. };
  191. struct clcd_clk_config {
  192. void __iomem *synth_reg;
  193. struct clcd_synth_masks *masks;
  194. };
  195. /* clcd clk rate config structure */
  196. struct clcd_rate_tbl {
  197. u16 div;
  198. };
  199. /* platform specific clock functions */
  200. void clk_register(struct clk_lookup *cl);
  201. void recalc_root_clocks(void);
  202. /* clock recalc & set rate functions */
  203. int follow_parent(struct clk *clk);
  204. unsigned long pll_calc_rate(struct clk *clk, int index);
  205. int pll_clk_recalc(struct clk *clk);
  206. int pll_clk_set_rate(struct clk *clk, unsigned long desired_rate);
  207. unsigned long bus_calc_rate(struct clk *clk, int index);
  208. int bus_clk_recalc(struct clk *clk);
  209. int bus_clk_set_rate(struct clk *clk, unsigned long desired_rate);
  210. unsigned long gpt_calc_rate(struct clk *clk, int index);
  211. int gpt_clk_recalc(struct clk *clk);
  212. int gpt_clk_set_rate(struct clk *clk, unsigned long desired_rate);
  213. unsigned long aux_calc_rate(struct clk *clk, int index);
  214. int aux_clk_recalc(struct clk *clk);
  215. int aux_clk_set_rate(struct clk *clk, unsigned long desired_rate);
  216. unsigned long clcd_calc_rate(struct clk *clk, int index);
  217. int clcd_clk_recalc(struct clk *clk);
  218. int clcd_clk_set_rate(struct clk *clk, unsigned long desired_rate);
  219. #endif /* __PLAT_CLOCK_H */