sh_clk.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. #ifndef __SH_CLOCK_H
  2. #define __SH_CLOCK_H
  3. #include <linux/list.h>
  4. #include <linux/seq_file.h>
  5. #include <linux/cpufreq.h>
  6. #include <linux/types.h>
  7. #include <linux/kref.h>
  8. #include <linux/clk.h>
  9. #include <linux/err.h>
  10. struct clk;
  11. struct clk_mapping {
  12. phys_addr_t phys;
  13. void __iomem *base;
  14. unsigned long len;
  15. struct kref ref;
  16. };
  17. struct sh_clk_ops {
  18. #ifdef CONFIG_SH_CLK_CPG_LEGACY
  19. void (*init)(struct clk *clk);
  20. #endif
  21. int (*enable)(struct clk *clk);
  22. void (*disable)(struct clk *clk);
  23. unsigned long (*recalc)(struct clk *clk);
  24. int (*set_rate)(struct clk *clk, unsigned long rate);
  25. int (*set_parent)(struct clk *clk, struct clk *parent);
  26. long (*round_rate)(struct clk *clk, unsigned long rate);
  27. };
  28. #define SH_CLK_DIV_MSK(div) ((1 << (div)) - 1)
  29. #define SH_CLK_DIV4_MSK SH_CLK_DIV_MSK(4)
  30. #define SH_CLK_DIV6_MSK SH_CLK_DIV_MSK(6)
  31. struct clk {
  32. struct list_head node;
  33. struct clk *parent;
  34. struct clk **parent_table; /* list of parents to */
  35. unsigned short parent_num; /* choose between */
  36. unsigned char src_shift; /* source clock field in the */
  37. unsigned char src_width; /* configuration register */
  38. struct sh_clk_ops *ops;
  39. struct list_head children;
  40. struct list_head sibling; /* node for children */
  41. int usecount;
  42. unsigned long rate;
  43. unsigned long flags;
  44. void __iomem *enable_reg;
  45. void __iomem *status_reg;
  46. unsigned int enable_bit;
  47. void __iomem *mapped_reg;
  48. unsigned int div_mask;
  49. unsigned long arch_flags;
  50. void *priv;
  51. struct clk_mapping *mapping;
  52. struct cpufreq_frequency_table *freq_table;
  53. unsigned int nr_freqs;
  54. };
  55. #define CLK_ENABLE_ON_INIT BIT(0)
  56. #define CLK_ENABLE_REG_32BIT BIT(1) /* default access size */
  57. #define CLK_ENABLE_REG_16BIT BIT(2)
  58. #define CLK_ENABLE_REG_8BIT BIT(3)
  59. #define CLK_MASK_DIV_ON_DISABLE BIT(4)
  60. #define CLK_ENABLE_REG_MASK (CLK_ENABLE_REG_32BIT | \
  61. CLK_ENABLE_REG_16BIT | \
  62. CLK_ENABLE_REG_8BIT)
  63. /* drivers/sh/clk.c */
  64. unsigned long followparent_recalc(struct clk *);
  65. void recalculate_root_clocks(void);
  66. void propagate_rate(struct clk *);
  67. int clk_reparent(struct clk *child, struct clk *parent);
  68. int clk_register(struct clk *);
  69. void clk_unregister(struct clk *);
  70. void clk_enable_init_clocks(void);
  71. struct clk_div_mult_table {
  72. unsigned int *divisors;
  73. unsigned int nr_divisors;
  74. unsigned int *multipliers;
  75. unsigned int nr_multipliers;
  76. };
  77. struct cpufreq_frequency_table;
  78. void clk_rate_table_build(struct clk *clk,
  79. struct cpufreq_frequency_table *freq_table,
  80. int nr_freqs,
  81. struct clk_div_mult_table *src_table,
  82. unsigned long *bitmap);
  83. long clk_rate_table_round(struct clk *clk,
  84. struct cpufreq_frequency_table *freq_table,
  85. unsigned long rate);
  86. int clk_rate_table_find(struct clk *clk,
  87. struct cpufreq_frequency_table *freq_table,
  88. unsigned long rate);
  89. long clk_rate_div_range_round(struct clk *clk, unsigned int div_min,
  90. unsigned int div_max, unsigned long rate);
  91. long clk_rate_mult_range_round(struct clk *clk, unsigned int mult_min,
  92. unsigned int mult_max, unsigned long rate);
  93. long clk_round_parent(struct clk *clk, unsigned long target,
  94. unsigned long *best_freq, unsigned long *parent_freq,
  95. unsigned int div_min, unsigned int div_max);
  96. #define SH_CLK_MSTP(_parent, _enable_reg, _enable_bit, _status_reg, _flags) \
  97. { \
  98. .parent = _parent, \
  99. .enable_reg = (void __iomem *)_enable_reg, \
  100. .enable_bit = _enable_bit, \
  101. .status_reg = _status_reg, \
  102. .flags = _flags, \
  103. }
  104. #define SH_CLK_MSTP32(_p, _r, _b, _f) \
  105. SH_CLK_MSTP(_p, _r, _b, 0, _f | CLK_ENABLE_REG_32BIT)
  106. #define SH_CLK_MSTP32_STS(_p, _r, _b, _s, _f) \
  107. SH_CLK_MSTP(_p, _r, _b, _s, _f | CLK_ENABLE_REG_32BIT)
  108. #define SH_CLK_MSTP16(_p, _r, _b, _f) \
  109. SH_CLK_MSTP(_p, _r, _b, 0, _f | CLK_ENABLE_REG_16BIT)
  110. #define SH_CLK_MSTP8(_p, _r, _b, _f) \
  111. SH_CLK_MSTP(_p, _r, _b, 0, _f | CLK_ENABLE_REG_8BIT)
  112. int sh_clk_mstp_register(struct clk *clks, int nr);
  113. /*
  114. * MSTP registration never really cared about access size, despite the
  115. * original enable/disable pairs assuming a 32-bit access. Clocks are
  116. * responsible for defining their access sizes either directly or via the
  117. * clock definition wrappers.
  118. */
  119. static inline int __deprecated sh_clk_mstp32_register(struct clk *clks, int nr)
  120. {
  121. return sh_clk_mstp_register(clks, nr);
  122. }
  123. #define SH_CLK_DIV4(_parent, _reg, _shift, _div_bitmap, _flags) \
  124. { \
  125. .parent = _parent, \
  126. .enable_reg = (void __iomem *)_reg, \
  127. .enable_bit = _shift, \
  128. .arch_flags = _div_bitmap, \
  129. .div_mask = SH_CLK_DIV4_MSK, \
  130. .flags = _flags, \
  131. }
  132. struct clk_div_table {
  133. struct clk_div_mult_table *div_mult_table;
  134. void (*kick)(struct clk *clk);
  135. };
  136. #define clk_div4_table clk_div_table
  137. int sh_clk_div4_register(struct clk *clks, int nr,
  138. struct clk_div4_table *table);
  139. int sh_clk_div4_enable_register(struct clk *clks, int nr,
  140. struct clk_div4_table *table);
  141. int sh_clk_div4_reparent_register(struct clk *clks, int nr,
  142. struct clk_div4_table *table);
  143. #define SH_CLK_DIV6_EXT(_reg, _flags, _parents, \
  144. _num_parents, _src_shift, _src_width) \
  145. { \
  146. .enable_reg = (void __iomem *)_reg, \
  147. .enable_bit = 0, /* unused */ \
  148. .flags = _flags | CLK_MASK_DIV_ON_DISABLE, \
  149. .div_mask = SH_CLK_DIV6_MSK, \
  150. .parent_table = _parents, \
  151. .parent_num = _num_parents, \
  152. .src_shift = _src_shift, \
  153. .src_width = _src_width, \
  154. }
  155. #define SH_CLK_DIV6(_parent, _reg, _flags) \
  156. { \
  157. .parent = _parent, \
  158. .enable_reg = (void __iomem *)_reg, \
  159. .enable_bit = 0, /* unused */ \
  160. .div_mask = SH_CLK_DIV6_MSK, \
  161. .flags = _flags | CLK_MASK_DIV_ON_DISABLE, \
  162. }
  163. int sh_clk_div6_register(struct clk *clks, int nr);
  164. int sh_clk_div6_reparent_register(struct clk *clks, int nr);
  165. #define CLKDEV_CON_ID(_id, _clk) { .con_id = _id, .clk = _clk }
  166. #define CLKDEV_DEV_ID(_id, _clk) { .dev_id = _id, .clk = _clk }
  167. #define CLKDEV_ICK_ID(_cid, _did, _clk) { .con_id = _cid, .dev_id = _did, .clk = _clk }
  168. /* .enable_reg will be updated to .mapping on sh_clk_fsidiv_register() */
  169. #define SH_CLK_FSIDIV(_reg, _parent) \
  170. { \
  171. .enable_reg = (void __iomem *)_reg, \
  172. .parent = _parent, \
  173. }
  174. int sh_clk_fsidiv_register(struct clk *clks, int nr);
  175. #endif /* __SH_CLOCK_H */