Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 1 | #ifndef __SH_CLOCK_H |
| 2 | #define __SH_CLOCK_H |
| 3 | |
| 4 | #include <linux/list.h> |
| 5 | #include <linux/seq_file.h> |
| 6 | #include <linux/cpufreq.h> |
Paul Mundt | 28085bc | 2010-10-15 16:46:37 +0900 | [diff] [blame] | 7 | #include <linux/types.h> |
| 8 | #include <linux/kref.h> |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 9 | #include <linux/clk.h> |
| 10 | #include <linux/err.h> |
| 11 | |
| 12 | struct clk; |
| 13 | |
Paul Mundt | 28085bc | 2010-10-15 16:46:37 +0900 | [diff] [blame] | 14 | struct clk_mapping { |
| 15 | phys_addr_t phys; |
| 16 | void __iomem *base; |
| 17 | unsigned long len; |
| 18 | struct kref ref; |
| 19 | }; |
| 20 | |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 21 | struct clk_ops { |
| 22 | void (*init)(struct clk *clk); |
| 23 | int (*enable)(struct clk *clk); |
| 24 | void (*disable)(struct clk *clk); |
| 25 | unsigned long (*recalc)(struct clk *clk); |
| 26 | int (*set_rate)(struct clk *clk, unsigned long rate, int algo_id); |
| 27 | int (*set_parent)(struct clk *clk, struct clk *parent); |
| 28 | long (*round_rate)(struct clk *clk, unsigned long rate); |
| 29 | }; |
| 30 | |
| 31 | struct clk { |
| 32 | struct list_head node; |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 33 | struct clk *parent; |
Guennadi Liakhovetski | b5272b50 | 2010-07-21 10:13:06 +0000 | [diff] [blame] | 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 */ |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 38 | struct clk_ops *ops; |
| 39 | |
| 40 | struct list_head children; |
| 41 | struct list_head sibling; /* node for children */ |
| 42 | |
| 43 | int usecount; |
| 44 | |
| 45 | unsigned long rate; |
| 46 | unsigned long flags; |
| 47 | |
| 48 | void __iomem *enable_reg; |
| 49 | unsigned int enable_bit; |
| 50 | |
| 51 | unsigned long arch_flags; |
| 52 | void *priv; |
| 53 | struct dentry *dentry; |
Paul Mundt | 28085bc | 2010-10-15 16:46:37 +0900 | [diff] [blame] | 54 | struct clk_mapping *mapping; |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 55 | struct cpufreq_frequency_table *freq_table; |
Paul Mundt | f586903 | 2010-10-15 18:17:35 +0900 | [diff] [blame^] | 56 | unsigned int nr_freqs; |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | #define CLK_ENABLE_ON_INIT (1 << 0) |
| 60 | |
Paul Mundt | a71ba09 | 2010-05-13 18:42:25 +0900 | [diff] [blame] | 61 | /* drivers/sh/clk.c */ |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 62 | unsigned long followparent_recalc(struct clk *); |
| 63 | void recalculate_root_clocks(void); |
| 64 | void propagate_rate(struct clk *); |
| 65 | int clk_reparent(struct clk *child, struct clk *parent); |
| 66 | int clk_register(struct clk *); |
| 67 | void clk_unregister(struct clk *); |
Magnus Damm | 8b5ee11 | 2010-05-11 13:29:25 +0000 | [diff] [blame] | 68 | void clk_enable_init_clocks(void); |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 69 | |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 70 | /** |
| 71 | * clk_set_rate_ex - set the clock rate for a clock source, with additional parameter |
| 72 | * @clk: clock source |
| 73 | * @rate: desired clock rate in Hz |
| 74 | * @algo_id: algorithm id to be passed down to ops->set_rate |
| 75 | * |
| 76 | * Returns success (0) or negative errno. |
| 77 | */ |
| 78 | int clk_set_rate_ex(struct clk *clk, unsigned long rate, int algo_id); |
| 79 | |
| 80 | enum clk_sh_algo_id { |
| 81 | NO_CHANGE = 0, |
| 82 | |
| 83 | IUS_N1_N1, |
| 84 | IUS_322, |
| 85 | IUS_522, |
| 86 | IUS_N11, |
| 87 | |
| 88 | SB_N1, |
| 89 | |
| 90 | SB3_N1, |
| 91 | SB3_32, |
| 92 | SB3_43, |
| 93 | SB3_54, |
| 94 | |
| 95 | BP_N1, |
| 96 | |
| 97 | IP_N1, |
| 98 | }; |
| 99 | |
| 100 | struct clk_div_mult_table { |
| 101 | unsigned int *divisors; |
| 102 | unsigned int nr_divisors; |
| 103 | unsigned int *multipliers; |
| 104 | unsigned int nr_multipliers; |
| 105 | }; |
| 106 | |
| 107 | struct cpufreq_frequency_table; |
| 108 | void clk_rate_table_build(struct clk *clk, |
| 109 | struct cpufreq_frequency_table *freq_table, |
| 110 | int nr_freqs, |
| 111 | struct clk_div_mult_table *src_table, |
| 112 | unsigned long *bitmap); |
| 113 | |
| 114 | long clk_rate_table_round(struct clk *clk, |
| 115 | struct cpufreq_frequency_table *freq_table, |
| 116 | unsigned long rate); |
| 117 | |
| 118 | int clk_rate_table_find(struct clk *clk, |
| 119 | struct cpufreq_frequency_table *freq_table, |
| 120 | unsigned long rate); |
| 121 | |
| 122 | #define SH_CLK_MSTP32(_parent, _enable_reg, _enable_bit, _flags) \ |
| 123 | { \ |
| 124 | .parent = _parent, \ |
| 125 | .enable_reg = (void __iomem *)_enable_reg, \ |
| 126 | .enable_bit = _enable_bit, \ |
| 127 | .flags = _flags, \ |
| 128 | } |
| 129 | |
| 130 | int sh_clk_mstp32_register(struct clk *clks, int nr); |
| 131 | |
| 132 | #define SH_CLK_DIV4(_parent, _reg, _shift, _div_bitmap, _flags) \ |
| 133 | { \ |
| 134 | .parent = _parent, \ |
| 135 | .enable_reg = (void __iomem *)_reg, \ |
| 136 | .enable_bit = _shift, \ |
| 137 | .arch_flags = _div_bitmap, \ |
| 138 | .flags = _flags, \ |
| 139 | } |
| 140 | |
| 141 | struct clk_div4_table { |
| 142 | struct clk_div_mult_table *div_mult_table; |
| 143 | void (*kick)(struct clk *clk); |
| 144 | }; |
| 145 | |
| 146 | int sh_clk_div4_register(struct clk *clks, int nr, |
| 147 | struct clk_div4_table *table); |
| 148 | int sh_clk_div4_enable_register(struct clk *clks, int nr, |
| 149 | struct clk_div4_table *table); |
| 150 | int sh_clk_div4_reparent_register(struct clk *clks, int nr, |
| 151 | struct clk_div4_table *table); |
| 152 | |
Guennadi Liakhovetski | b3dd51a | 2010-07-21 10:13:10 +0000 | [diff] [blame] | 153 | #define SH_CLK_DIV6_EXT(_parent, _reg, _flags, _parents, \ |
| 154 | _num_parents, _src_shift, _src_width) \ |
| 155 | { \ |
| 156 | .parent = _parent, \ |
| 157 | .enable_reg = (void __iomem *)_reg, \ |
| 158 | .flags = _flags, \ |
| 159 | .parent_table = _parents, \ |
| 160 | .parent_num = _num_parents, \ |
| 161 | .src_shift = _src_shift, \ |
| 162 | .src_width = _src_width, \ |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 163 | } |
| 164 | |
Guennadi Liakhovetski | b3dd51a | 2010-07-21 10:13:10 +0000 | [diff] [blame] | 165 | #define SH_CLK_DIV6(_parent, _reg, _flags) \ |
| 166 | SH_CLK_DIV6_EXT(_parent, _reg, _flags, NULL, 0, 0, 0) |
| 167 | |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 168 | int sh_clk_div6_register(struct clk *clks, int nr); |
Guennadi Liakhovetski | b3dd51a | 2010-07-21 10:13:10 +0000 | [diff] [blame] | 169 | int sh_clk_div6_reparent_register(struct clk *clks, int nr); |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 170 | |
| 171 | #endif /* __SH_CLOCK_H */ |