sh_clk.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. #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. struct clk {
  29. struct list_head node;
  30. struct clk *parent;
  31. struct clk **parent_table; /* list of parents to */
  32. unsigned short parent_num; /* choose between */
  33. unsigned char src_shift; /* source clock field in the */
  34. unsigned char src_width; /* configuration register */
  35. struct clk_ops *ops;
  36. struct list_head children;
  37. struct list_head sibling; /* node for children */
  38. int usecount;
  39. unsigned long rate;
  40. unsigned long flags;
  41. void __iomem *enable_reg;
  42. unsigned int enable_bit;
  43. unsigned long arch_flags;
  44. void *priv;
  45. struct clk_mapping *mapping;
  46. struct cpufreq_frequency_table *freq_table;
  47. unsigned int nr_freqs;
  48. };
  49. #define CLK_ENABLE_ON_INIT (1 << 0)
  50. /* drivers/sh/clk.c */
  51. unsigned long followparent_recalc(struct clk *);
  52. void recalculate_root_clocks(void);
  53. void propagate_rate(struct clk *);
  54. int clk_reparent(struct clk *child, struct clk *parent);
  55. int clk_register(struct clk *);
  56. void clk_unregister(struct clk *);
  57. void clk_enable_init_clocks(void);
  58. struct clk_div_mult_table {
  59. unsigned int *divisors;
  60. unsigned int nr_divisors;
  61. unsigned int *multipliers;
  62. unsigned int nr_multipliers;
  63. };
  64. struct cpufreq_frequency_table;
  65. void clk_rate_table_build(struct clk *clk,
  66. struct cpufreq_frequency_table *freq_table,
  67. int nr_freqs,
  68. struct clk_div_mult_table *src_table,
  69. unsigned long *bitmap);
  70. long clk_rate_table_round(struct clk *clk,
  71. struct cpufreq_frequency_table *freq_table,
  72. unsigned long rate);
  73. int clk_rate_table_find(struct clk *clk,
  74. struct cpufreq_frequency_table *freq_table,
  75. unsigned long rate);
  76. long clk_rate_div_range_round(struct clk *clk, unsigned int div_min,
  77. unsigned int div_max, unsigned long rate);
  78. long clk_rate_mult_range_round(struct clk *clk, unsigned int mult_min,
  79. unsigned int mult_max, unsigned long rate);
  80. long clk_round_parent(struct clk *clk, unsigned long target,
  81. unsigned long *best_freq, unsigned long *parent_freq,
  82. unsigned int div_min, unsigned int div_max);
  83. #define SH_CLK_MSTP32(_parent, _enable_reg, _enable_bit, _flags) \
  84. { \
  85. .parent = _parent, \
  86. .enable_reg = (void __iomem *)_enable_reg, \
  87. .enable_bit = _enable_bit, \
  88. .flags = _flags, \
  89. }
  90. int sh_clk_mstp32_register(struct clk *clks, int nr);
  91. #define SH_CLK_DIV4(_parent, _reg, _shift, _div_bitmap, _flags) \
  92. { \
  93. .parent = _parent, \
  94. .enable_reg = (void __iomem *)_reg, \
  95. .enable_bit = _shift, \
  96. .arch_flags = _div_bitmap, \
  97. .flags = _flags, \
  98. }
  99. struct clk_div4_table {
  100. struct clk_div_mult_table *div_mult_table;
  101. void (*kick)(struct clk *clk);
  102. };
  103. int sh_clk_div4_register(struct clk *clks, int nr,
  104. struct clk_div4_table *table);
  105. int sh_clk_div4_enable_register(struct clk *clks, int nr,
  106. struct clk_div4_table *table);
  107. int sh_clk_div4_reparent_register(struct clk *clks, int nr,
  108. struct clk_div4_table *table);
  109. #define SH_CLK_DIV6_EXT(_parent, _reg, _flags, _parents, \
  110. _num_parents, _src_shift, _src_width) \
  111. { \
  112. .parent = _parent, \
  113. .enable_reg = (void __iomem *)_reg, \
  114. .flags = _flags, \
  115. .parent_table = _parents, \
  116. .parent_num = _num_parents, \
  117. .src_shift = _src_shift, \
  118. .src_width = _src_width, \
  119. }
  120. #define SH_CLK_DIV6(_parent, _reg, _flags) \
  121. SH_CLK_DIV6_EXT(_parent, _reg, _flags, NULL, 0, 0, 0)
  122. int sh_clk_div6_register(struct clk *clks, int nr);
  123. int sh_clk_div6_reparent_register(struct clk *clks, int nr);
  124. #define CLKDEV_CON_ID(_id, _clk) { .con_id = _id, .clk = _clk }
  125. #define CLKDEV_DEV_ID(_id, _clk) { .dev_id = _id, .clk = _clk }
  126. #define CLKDEV_ICK_ID(_cid, _did, _clk) { .con_id = _cid, .dev_id = _did, .clk = _clk }
  127. #endif /* __SH_CLOCK_H */