sh_clk.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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 clk_ops {
  18. void (*init)(struct clk *clk);
  19. int (*enable)(struct clk *clk);
  20. void (*disable)(struct clk *clk);
  21. unsigned long (*recalc)(struct clk *clk);
  22. int (*set_rate)(struct clk *clk, unsigned long rate, int algo_id);
  23. int (*set_parent)(struct clk *clk, struct clk *parent);
  24. long (*round_rate)(struct clk *clk, unsigned long rate);
  25. };
  26. struct clk {
  27. struct list_head node;
  28. struct clk *parent;
  29. struct clk **parent_table; /* list of parents to */
  30. unsigned short parent_num; /* choose between */
  31. unsigned char src_shift; /* source clock field in the */
  32. unsigned char src_width; /* configuration register */
  33. struct clk_ops *ops;
  34. struct list_head children;
  35. struct list_head sibling; /* node for children */
  36. int usecount;
  37. unsigned long rate;
  38. unsigned long flags;
  39. void __iomem *enable_reg;
  40. unsigned int enable_bit;
  41. unsigned long arch_flags;
  42. void *priv;
  43. struct dentry *dentry;
  44. struct clk_mapping *mapping;
  45. struct cpufreq_frequency_table *freq_table;
  46. unsigned int nr_freqs;
  47. };
  48. #define CLK_ENABLE_ON_INIT (1 << 0)
  49. /* drivers/sh/clk.c */
  50. unsigned long followparent_recalc(struct clk *);
  51. void recalculate_root_clocks(void);
  52. void propagate_rate(struct clk *);
  53. int clk_reparent(struct clk *child, struct clk *parent);
  54. int clk_register(struct clk *);
  55. void clk_unregister(struct clk *);
  56. void clk_enable_init_clocks(void);
  57. /**
  58. * clk_set_rate_ex - set the clock rate for a clock source, with additional parameter
  59. * @clk: clock source
  60. * @rate: desired clock rate in Hz
  61. * @algo_id: algorithm id to be passed down to ops->set_rate
  62. *
  63. * Returns success (0) or negative errno.
  64. */
  65. int clk_set_rate_ex(struct clk *clk, unsigned long rate, int algo_id);
  66. enum clk_sh_algo_id {
  67. NO_CHANGE = 0,
  68. IUS_N1_N1,
  69. IUS_322,
  70. IUS_522,
  71. IUS_N11,
  72. SB_N1,
  73. SB3_N1,
  74. SB3_32,
  75. SB3_43,
  76. SB3_54,
  77. BP_N1,
  78. IP_N1,
  79. };
  80. struct clk_div_mult_table {
  81. unsigned int *divisors;
  82. unsigned int nr_divisors;
  83. unsigned int *multipliers;
  84. unsigned int nr_multipliers;
  85. };
  86. struct cpufreq_frequency_table;
  87. void clk_rate_table_build(struct clk *clk,
  88. struct cpufreq_frequency_table *freq_table,
  89. int nr_freqs,
  90. struct clk_div_mult_table *src_table,
  91. unsigned long *bitmap);
  92. long clk_rate_table_round(struct clk *clk,
  93. struct cpufreq_frequency_table *freq_table,
  94. unsigned long rate);
  95. int clk_rate_table_find(struct clk *clk,
  96. struct cpufreq_frequency_table *freq_table,
  97. unsigned long rate);
  98. long clk_rate_div_range_round(struct clk *clk, unsigned int div_min,
  99. unsigned int div_max, unsigned long rate);
  100. long clk_round_parent(struct clk *clk, unsigned long target,
  101. unsigned long *best_freq, unsigned long *parent_freq,
  102. unsigned int div_min, unsigned int div_max);
  103. #define SH_CLK_MSTP32(_parent, _enable_reg, _enable_bit, _flags) \
  104. { \
  105. .parent = _parent, \
  106. .enable_reg = (void __iomem *)_enable_reg, \
  107. .enable_bit = _enable_bit, \
  108. .flags = _flags, \
  109. }
  110. int sh_clk_mstp32_register(struct clk *clks, int nr);
  111. #define SH_CLK_DIV4(_parent, _reg, _shift, _div_bitmap, _flags) \
  112. { \
  113. .parent = _parent, \
  114. .enable_reg = (void __iomem *)_reg, \
  115. .enable_bit = _shift, \
  116. .arch_flags = _div_bitmap, \
  117. .flags = _flags, \
  118. }
  119. struct clk_div4_table {
  120. struct clk_div_mult_table *div_mult_table;
  121. void (*kick)(struct clk *clk);
  122. };
  123. int sh_clk_div4_register(struct clk *clks, int nr,
  124. struct clk_div4_table *table);
  125. int sh_clk_div4_enable_register(struct clk *clks, int nr,
  126. struct clk_div4_table *table);
  127. int sh_clk_div4_reparent_register(struct clk *clks, int nr,
  128. struct clk_div4_table *table);
  129. #define SH_CLK_DIV6_EXT(_parent, _reg, _flags, _parents, \
  130. _num_parents, _src_shift, _src_width) \
  131. { \
  132. .parent = _parent, \
  133. .enable_reg = (void __iomem *)_reg, \
  134. .flags = _flags, \
  135. .parent_table = _parents, \
  136. .parent_num = _num_parents, \
  137. .src_shift = _src_shift, \
  138. .src_width = _src_width, \
  139. }
  140. #define SH_CLK_DIV6(_parent, _reg, _flags) \
  141. SH_CLK_DIV6_EXT(_parent, _reg, _flags, NULL, 0, 0, 0)
  142. int sh_clk_div6_register(struct clk *clks, int nr);
  143. int sh_clk_div6_reparent_register(struct clk *clks, int nr);
  144. #endif /* __SH_CLOCK_H */