clock.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #ifndef __ASM_SH_CLOCK_H
  2. #define __ASM_SH_CLOCK_H
  3. #include <linux/list.h>
  4. #include <linux/seq_file.h>
  5. #include <linux/cpufreq.h>
  6. #include <linux/clk.h>
  7. #include <linux/err.h>
  8. struct clk;
  9. struct clk_ops {
  10. void (*init)(struct clk *clk);
  11. int (*enable)(struct clk *clk);
  12. void (*disable)(struct clk *clk);
  13. unsigned long (*recalc)(struct clk *clk);
  14. int (*set_rate)(struct clk *clk, unsigned long rate, int algo_id);
  15. int (*set_parent)(struct clk *clk, struct clk *parent);
  16. long (*round_rate)(struct clk *clk, unsigned long rate);
  17. };
  18. struct clk {
  19. struct list_head node;
  20. const char *name;
  21. int id;
  22. struct module *owner;
  23. struct clk *parent;
  24. struct clk_ops *ops;
  25. struct list_head children;
  26. struct list_head sibling; /* node for children */
  27. int usecount;
  28. unsigned long rate;
  29. unsigned long flags;
  30. void __iomem *enable_reg;
  31. unsigned int enable_bit;
  32. unsigned long arch_flags;
  33. void *priv;
  34. struct dentry *dentry;
  35. struct cpufreq_frequency_table *freq_table;
  36. };
  37. #define CLK_ENABLE_ON_INIT (1 << 0)
  38. /* Should be defined by processor-specific code */
  39. void __deprecated arch_init_clk_ops(struct clk_ops **, int type);
  40. int __init arch_clk_init(void);
  41. /* arch/sh/kernel/cpu/clock.c */
  42. int clk_init(void);
  43. unsigned long followparent_recalc(struct clk *);
  44. void recalculate_root_clocks(void);
  45. void propagate_rate(struct clk *);
  46. int clk_reparent(struct clk *child, struct clk *parent);
  47. int clk_register(struct clk *);
  48. void clk_unregister(struct clk *);
  49. /* arch/sh/kernel/cpu/clock-cpg.c */
  50. int __init __deprecated cpg_clk_init(void);
  51. /* the exported API, in addition to clk_set_rate */
  52. /**
  53. * clk_set_rate_ex - set the clock rate for a clock source, with additional parameter
  54. * @clk: clock source
  55. * @rate: desired clock rate in Hz
  56. * @algo_id: algorithm id to be passed down to ops->set_rate
  57. *
  58. * Returns success (0) or negative errno.
  59. */
  60. int clk_set_rate_ex(struct clk *clk, unsigned long rate, int algo_id);
  61. enum clk_sh_algo_id {
  62. NO_CHANGE = 0,
  63. IUS_N1_N1,
  64. IUS_322,
  65. IUS_522,
  66. IUS_N11,
  67. SB_N1,
  68. SB3_N1,
  69. SB3_32,
  70. SB3_43,
  71. SB3_54,
  72. BP_N1,
  73. IP_N1,
  74. };
  75. struct clk_div_mult_table {
  76. unsigned int *divisors;
  77. unsigned int nr_divisors;
  78. unsigned int *multipliers;
  79. unsigned int nr_multipliers;
  80. };
  81. struct cpufreq_frequency_table;
  82. void clk_rate_table_build(struct clk *clk,
  83. struct cpufreq_frequency_table *freq_table,
  84. int nr_freqs,
  85. struct clk_div_mult_table *src_table,
  86. unsigned long *bitmap);
  87. long clk_rate_table_round(struct clk *clk,
  88. struct cpufreq_frequency_table *freq_table,
  89. unsigned long rate);
  90. int clk_rate_table_find(struct clk *clk,
  91. struct cpufreq_frequency_table *freq_table,
  92. unsigned long rate);
  93. #define SH_CLK_MSTP32(_name, _id, _parent, _enable_reg, \
  94. _enable_bit, _flags) \
  95. { \
  96. .name = _name, \
  97. .id = _id, \
  98. .parent = _parent, \
  99. .enable_reg = (void __iomem *)_enable_reg, \
  100. .enable_bit = _enable_bit, \
  101. .flags = _flags, \
  102. }
  103. int sh_clk_mstp32_register(struct clk *clks, int nr);
  104. #define SH_CLK_DIV4(_name, _parent, _reg, _shift, _div_bitmap, _flags) \
  105. { \
  106. .name = _name, \
  107. .parent = _parent, \
  108. .enable_reg = (void __iomem *)_reg, \
  109. .enable_bit = _shift, \
  110. .arch_flags = _div_bitmap, \
  111. .flags = _flags, \
  112. }
  113. struct clk_div4_table {
  114. struct clk_div_mult_table *div_mult_table;
  115. void (*kick)(struct clk *clk);
  116. };
  117. int sh_clk_div4_register(struct clk *clks, int nr,
  118. struct clk_div4_table *table);
  119. int sh_clk_div4_enable_register(struct clk *clks, int nr,
  120. struct clk_div4_table *table);
  121. int sh_clk_div4_reparent_register(struct clk *clks, int nr,
  122. struct clk_div4_table *table);
  123. #define SH_CLK_DIV6(_name, _parent, _reg, _flags) \
  124. { \
  125. .name = _name, \
  126. .parent = _parent, \
  127. .enable_reg = (void __iomem *)_reg, \
  128. .flags = _flags, \
  129. }
  130. int sh_clk_div6_register(struct clk *clks, int nr);
  131. #endif /* __ASM_SH_CLOCK_H */