Paul Mundt | 36ddf31 | 2006-01-16 22:14:17 -0800 | [diff] [blame] | 1 | #ifndef __ASM_SH_CLOCK_H |
| 2 | #define __ASM_SH_CLOCK_H |
| 3 | |
Paul Mundt | 36ddf31 | 2006-01-16 22:14:17 -0800 | [diff] [blame] | 4 | #include <linux/list.h> |
| 5 | #include <linux/seq_file.h> |
Magnus Damm | a1153e2 | 2009-05-28 13:11:31 +0000 | [diff] [blame] | 6 | #include <linux/cpufreq.h> |
Paul Mundt | 1d11856 | 2006-12-01 13:15:14 +0900 | [diff] [blame] | 7 | #include <linux/clk.h> |
Magnus Damm | de92542 | 2008-07-17 19:09:51 +0900 | [diff] [blame] | 8 | #include <linux/err.h> |
Paul Mundt | 36ddf31 | 2006-01-16 22:14:17 -0800 | [diff] [blame] | 9 | |
| 10 | struct clk; |
| 11 | |
| 12 | struct clk_ops { |
| 13 | void (*init)(struct clk *clk); |
Paul Mundt | ae891a4 | 2009-05-12 05:30:10 +0900 | [diff] [blame] | 14 | int (*enable)(struct clk *clk); |
Paul Mundt | 36ddf31 | 2006-01-16 22:14:17 -0800 | [diff] [blame] | 15 | void (*disable)(struct clk *clk); |
Paul Mundt | b68d8201 | 2009-05-12 03:45:08 +0900 | [diff] [blame] | 16 | unsigned long (*recalc)(struct clk *clk); |
dmitry pervushin | 1929cb3 | 2007-04-24 13:39:09 +0900 | [diff] [blame] | 17 | int (*set_rate)(struct clk *clk, unsigned long rate, int algo_id); |
Francesco VIRLINZI | d680c76 | 2009-03-11 07:40:54 +0000 | [diff] [blame] | 18 | int (*set_parent)(struct clk *clk, struct clk *parent); |
Paul Mundt | f6991b0 | 2007-07-20 13:29:09 +0900 | [diff] [blame] | 19 | long (*round_rate)(struct clk *clk, unsigned long rate); |
Paul Mundt | 36ddf31 | 2006-01-16 22:14:17 -0800 | [diff] [blame] | 20 | }; |
| 21 | |
| 22 | struct clk { |
| 23 | struct list_head node; |
| 24 | const char *name; |
Paul Mundt | 1d11856 | 2006-12-01 13:15:14 +0900 | [diff] [blame] | 25 | int id; |
Paul Mundt | 36ddf31 | 2006-01-16 22:14:17 -0800 | [diff] [blame] | 26 | struct module *owner; |
| 27 | |
| 28 | struct clk *parent; |
| 29 | struct clk_ops *ops; |
| 30 | |
Paul Mundt | b1f6cfe | 2009-05-12 04:27:43 +0900 | [diff] [blame] | 31 | struct list_head children; |
| 32 | struct list_head sibling; /* node for children */ |
| 33 | |
Magnus Damm | 4f5ecaa | 2009-05-08 08:23:29 +0000 | [diff] [blame] | 34 | int usecount; |
Paul Mundt | 36ddf31 | 2006-01-16 22:14:17 -0800 | [diff] [blame] | 35 | |
| 36 | unsigned long rate; |
| 37 | unsigned long flags; |
Paul Mundt | a77b5ac | 2009-05-13 17:55:00 +0900 | [diff] [blame] | 38 | |
Paul Mundt | 549b5e3 | 2009-05-14 17:38:46 +0900 | [diff] [blame] | 39 | void __iomem *enable_reg; |
| 40 | unsigned int enable_bit; |
| 41 | |
Magnus Damm | 5c8f9d9 | 2008-07-17 18:48:57 +0900 | [diff] [blame] | 42 | unsigned long arch_flags; |
Paul Mundt | a77b5ac | 2009-05-13 17:55:00 +0900 | [diff] [blame] | 43 | void *priv; |
Paul Mundt | cedcf33 | 2009-05-13 21:51:28 +0900 | [diff] [blame] | 44 | struct dentry *dentry; |
Magnus Damm | a1153e2 | 2009-05-28 13:11:31 +0000 | [diff] [blame] | 45 | struct cpufreq_frequency_table *freq_table; |
Paul Mundt | 36ddf31 | 2006-01-16 22:14:17 -0800 | [diff] [blame] | 46 | }; |
| 47 | |
Paul Mundt | 4ff29ff | 2009-05-12 05:14:53 +0900 | [diff] [blame] | 48 | #define CLK_ENABLE_ON_INIT (1 << 0) |
Paul Mundt | 36ddf31 | 2006-01-16 22:14:17 -0800 | [diff] [blame] | 49 | |
| 50 | /* Should be defined by processor-specific code */ |
Paul Mundt | 253b088 | 2009-05-13 17:38:11 +0900 | [diff] [blame] | 51 | void __deprecated arch_init_clk_ops(struct clk_ops **, int type); |
Paul Mundt | fa43972 | 2008-09-04 18:53:58 +0900 | [diff] [blame] | 52 | int __init arch_clk_init(void); |
Paul Mundt | 36ddf31 | 2006-01-16 22:14:17 -0800 | [diff] [blame] | 53 | |
| 54 | /* arch/sh/kernel/cpu/clock.c */ |
| 55 | int clk_init(void); |
Paul Mundt | b1f6cfe | 2009-05-12 04:27:43 +0900 | [diff] [blame] | 56 | unsigned long followparent_recalc(struct clk *); |
| 57 | void recalculate_root_clocks(void); |
| 58 | void propagate_rate(struct clk *); |
Paul Mundt | aa87aa3 | 2009-05-12 05:51:05 +0900 | [diff] [blame] | 59 | int clk_reparent(struct clk *child, struct clk *parent); |
Paul Mundt | 36ddf31 | 2006-01-16 22:14:17 -0800 | [diff] [blame] | 60 | int clk_register(struct clk *); |
| 61 | void clk_unregister(struct clk *); |
| 62 | |
Paul Mundt | 253b088 | 2009-05-13 17:38:11 +0900 | [diff] [blame] | 63 | /* arch/sh/kernel/cpu/clock-cpg.c */ |
| 64 | int __init __deprecated cpg_clk_init(void); |
| 65 | |
dmitry pervushin | 1929cb3 | 2007-04-24 13:39:09 +0900 | [diff] [blame] | 66 | /* the exported API, in addition to clk_set_rate */ |
| 67 | /** |
| 68 | * clk_set_rate_ex - set the clock rate for a clock source, with additional parameter |
| 69 | * @clk: clock source |
| 70 | * @rate: desired clock rate in Hz |
| 71 | * @algo_id: algorithm id to be passed down to ops->set_rate |
| 72 | * |
| 73 | * Returns success (0) or negative errno. |
| 74 | */ |
| 75 | int clk_set_rate_ex(struct clk *clk, unsigned long rate, int algo_id); |
| 76 | |
| 77 | enum clk_sh_algo_id { |
| 78 | NO_CHANGE = 0, |
| 79 | |
| 80 | IUS_N1_N1, |
| 81 | IUS_322, |
| 82 | IUS_522, |
| 83 | IUS_N11, |
| 84 | |
| 85 | SB_N1, |
| 86 | |
| 87 | SB3_N1, |
| 88 | SB3_32, |
| 89 | SB3_43, |
| 90 | SB3_54, |
| 91 | |
| 92 | BP_N1, |
| 93 | |
| 94 | IP_N1, |
| 95 | }; |
Paul Mundt | b68d8201 | 2009-05-12 03:45:08 +0900 | [diff] [blame] | 96 | |
Magnus Damm | c94a857 | 2009-05-25 08:10:28 +0000 | [diff] [blame] | 97 | struct clk_div_mult_table { |
| 98 | unsigned int *divisors; |
| 99 | unsigned int nr_divisors; |
| 100 | unsigned int *multipliers; |
| 101 | unsigned int nr_multipliers; |
| 102 | }; |
| 103 | |
| 104 | struct cpufreq_frequency_table; |
| 105 | void clk_rate_table_build(struct clk *clk, |
| 106 | struct cpufreq_frequency_table *freq_table, |
| 107 | int nr_freqs, |
| 108 | struct clk_div_mult_table *src_table, |
| 109 | unsigned long *bitmap); |
| 110 | |
| 111 | long clk_rate_table_round(struct clk *clk, |
| 112 | struct cpufreq_frequency_table *freq_table, |
| 113 | unsigned long rate); |
| 114 | |
Magnus Damm | 098dee9 | 2009-06-04 05:31:41 +0000 | [diff] [blame] | 115 | int clk_rate_table_find(struct clk *clk, |
| 116 | struct cpufreq_frequency_table *freq_table, |
| 117 | unsigned long rate); |
| 118 | |
Magnus Damm | c77a9c3 | 2010-05-11 05:00:47 +0000 | [diff] [blame] | 119 | #define SH_CLK_MSTP32(_parent, _enable_reg, _enable_bit, _flags) \ |
| 120 | { \ |
| 121 | .parent = _parent, \ |
| 122 | .enable_reg = (void __iomem *)_enable_reg, \ |
| 123 | .enable_bit = _enable_bit, \ |
| 124 | .flags = _flags, \ |
Magnus Damm | 6881e8b | 2009-05-28 12:52:29 +0000 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | int sh_clk_mstp32_register(struct clk *clks, int nr); |
| 128 | |
Magnus Damm | 914ebf0 | 2010-05-11 07:06:13 +0000 | [diff] [blame^] | 129 | #define SH_CLK_DIV4(_parent, _reg, _shift, _div_bitmap, _flags) \ |
| 130 | { \ |
| 131 | .parent = _parent, \ |
| 132 | .enable_reg = (void __iomem *)_reg, \ |
| 133 | .enable_bit = _shift, \ |
| 134 | .arch_flags = _div_bitmap, \ |
| 135 | .flags = _flags, \ |
Magnus Damm | a1153e2 | 2009-05-28 13:11:31 +0000 | [diff] [blame] | 136 | } |
| 137 | |
Magnus Damm | 0a5f337 | 2010-02-19 09:22:25 +0000 | [diff] [blame] | 138 | struct clk_div4_table { |
| 139 | struct clk_div_mult_table *div_mult_table; |
Magnus Damm | 7be85c6 | 2010-02-19 09:26:56 +0000 | [diff] [blame] | 140 | void (*kick)(struct clk *clk); |
Magnus Damm | 0a5f337 | 2010-02-19 09:22:25 +0000 | [diff] [blame] | 141 | }; |
| 142 | |
Magnus Damm | a1153e2 | 2009-05-28 13:11:31 +0000 | [diff] [blame] | 143 | int sh_clk_div4_register(struct clk *clks, int nr, |
Magnus Damm | 0a5f337 | 2010-02-19 09:22:25 +0000 | [diff] [blame] | 144 | struct clk_div4_table *table); |
Guennadi Liakhovetski | 31c3af5 | 2010-01-19 11:14:31 +0000 | [diff] [blame] | 145 | int sh_clk_div4_enable_register(struct clk *clks, int nr, |
Magnus Damm | 0a5f337 | 2010-02-19 09:22:25 +0000 | [diff] [blame] | 146 | struct clk_div4_table *table); |
Guennadi Liakhovetski | 31c3af5 | 2010-01-19 11:14:31 +0000 | [diff] [blame] | 147 | int sh_clk_div4_reparent_register(struct clk *clks, int nr, |
Magnus Damm | 0a5f337 | 2010-02-19 09:22:25 +0000 | [diff] [blame] | 148 | struct clk_div4_table *table); |
Magnus Damm | a1153e2 | 2009-05-28 13:11:31 +0000 | [diff] [blame] | 149 | |
Magnus Damm | 9e1985e | 2010-05-10 14:02:09 +0000 | [diff] [blame] | 150 | #define SH_CLK_DIV6(_parent, _reg, _flags) \ |
| 151 | { \ |
| 152 | .parent = _parent, \ |
| 153 | .enable_reg = (void __iomem *)_reg, \ |
| 154 | .flags = _flags, \ |
Magnus Damm | 2693e27 | 2009-06-02 08:53:54 +0000 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | int sh_clk_div6_register(struct clk *clks, int nr); |
| 158 | |
Paul Mundt | 36ddf31 | 2006-01-16 22:14:17 -0800 | [diff] [blame] | 159 | #endif /* __ASM_SH_CLOCK_H */ |