sh_clk.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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);
  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. struct clk_div_mult_table {
  58. unsigned int *divisors;
  59. unsigned int nr_divisors;
  60. unsigned int *multipliers;
  61. unsigned int nr_multipliers;
  62. };
  63. struct cpufreq_frequency_table;
  64. void clk_rate_table_build(struct clk *clk,
  65. struct cpufreq_frequency_table *freq_table,
  66. int nr_freqs,
  67. struct clk_div_mult_table *src_table,
  68. unsigned long *bitmap);
  69. long clk_rate_table_round(struct clk *clk,
  70. struct cpufreq_frequency_table *freq_table,
  71. unsigned long rate);
  72. int clk_rate_table_find(struct clk *clk,
  73. struct cpufreq_frequency_table *freq_table,
  74. unsigned long rate);
  75. long clk_rate_div_range_round(struct clk *clk, unsigned int div_min,
  76. unsigned int div_max, unsigned long rate);
  77. long clk_round_parent(struct clk *clk, unsigned long target,
  78. unsigned long *best_freq, unsigned long *parent_freq,
  79. unsigned int div_min, unsigned int div_max);
  80. #define SH_CLK_MSTP32(_parent, _enable_reg, _enable_bit, _flags) \
  81. { \
  82. .parent = _parent, \
  83. .enable_reg = (void __iomem *)_enable_reg, \
  84. .enable_bit = _enable_bit, \
  85. .flags = _flags, \
  86. }
  87. int sh_clk_mstp32_register(struct clk *clks, int nr);
  88. #define SH_CLK_DIV4(_parent, _reg, _shift, _div_bitmap, _flags) \
  89. { \
  90. .parent = _parent, \
  91. .enable_reg = (void __iomem *)_reg, \
  92. .enable_bit = _shift, \
  93. .arch_flags = _div_bitmap, \
  94. .flags = _flags, \
  95. }
  96. struct clk_div4_table {
  97. struct clk_div_mult_table *div_mult_table;
  98. void (*kick)(struct clk *clk);
  99. };
  100. int sh_clk_div4_register(struct clk *clks, int nr,
  101. struct clk_div4_table *table);
  102. int sh_clk_div4_enable_register(struct clk *clks, int nr,
  103. struct clk_div4_table *table);
  104. int sh_clk_div4_reparent_register(struct clk *clks, int nr,
  105. struct clk_div4_table *table);
  106. #define SH_CLK_DIV6_EXT(_parent, _reg, _flags, _parents, \
  107. _num_parents, _src_shift, _src_width) \
  108. { \
  109. .parent = _parent, \
  110. .enable_reg = (void __iomem *)_reg, \
  111. .flags = _flags, \
  112. .parent_table = _parents, \
  113. .parent_num = _num_parents, \
  114. .src_shift = _src_shift, \
  115. .src_width = _src_width, \
  116. }
  117. #define SH_CLK_DIV6(_parent, _reg, _flags) \
  118. SH_CLK_DIV6_EXT(_parent, _reg, _flags, NULL, 0, 0, 0)
  119. int sh_clk_div6_register(struct clk *clks, int nr);
  120. int sh_clk_div6_reparent_register(struct clk *clks, int nr);
  121. #endif /* __SH_CLOCK_H */