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 | e348282 | 2012-02-29 22:16:13 +0900 | [diff] [blame] | 21 | |
Magnus Damm | 84c36ff | 2012-02-29 22:18:19 +0900 | [diff] [blame] | 22 | struct sh_clk_ops { |
Paul Mundt | 549015c | 2010-11-15 18:48:25 +0900 | [diff] [blame] | 23 | #ifdef CONFIG_SH_CLK_CPG_LEGACY |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 24 | void (*init)(struct clk *clk); |
Paul Mundt | 549015c | 2010-11-15 18:48:25 +0900 | [diff] [blame] | 25 | #endif |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 26 | int (*enable)(struct clk *clk); |
| 27 | void (*disable)(struct clk *clk); |
| 28 | unsigned long (*recalc)(struct clk *clk); |
Paul Mundt | 35a96c7 | 2010-11-15 18:18:32 +0900 | [diff] [blame] | 29 | int (*set_rate)(struct clk *clk, unsigned long rate); |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 30 | int (*set_parent)(struct clk *clk, struct clk *parent); |
| 31 | long (*round_rate)(struct clk *clk, unsigned long rate); |
| 32 | }; |
| 33 | |
| 34 | struct clk { |
| 35 | struct list_head node; |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 36 | struct clk *parent; |
Guennadi Liakhovetski | b5272b50 | 2010-07-21 10:13:06 +0000 | [diff] [blame] | 37 | struct clk **parent_table; /* list of parents to */ |
| 38 | unsigned short parent_num; /* choose between */ |
| 39 | unsigned char src_shift; /* source clock field in the */ |
| 40 | unsigned char src_width; /* configuration register */ |
Magnus Damm | 84c36ff | 2012-02-29 22:18:19 +0900 | [diff] [blame] | 41 | struct sh_clk_ops *ops; |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 42 | |
| 43 | struct list_head children; |
| 44 | struct list_head sibling; /* node for children */ |
| 45 | |
| 46 | int usecount; |
| 47 | |
| 48 | unsigned long rate; |
| 49 | unsigned long flags; |
| 50 | |
| 51 | void __iomem *enable_reg; |
| 52 | unsigned int enable_bit; |
Magnus Damm | eda2030 | 2011-12-08 22:58:54 +0900 | [diff] [blame] | 53 | void __iomem *mapped_reg; |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 54 | |
| 55 | unsigned long arch_flags; |
| 56 | void *priv; |
Paul Mundt | 28085bc | 2010-10-15 16:46:37 +0900 | [diff] [blame] | 57 | struct clk_mapping *mapping; |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 58 | struct cpufreq_frequency_table *freq_table; |
Paul Mundt | f586903 | 2010-10-15 18:17:35 +0900 | [diff] [blame] | 59 | unsigned int nr_freqs; |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | #define CLK_ENABLE_ON_INIT (1 << 0) |
| 63 | |
Paul Mundt | a71ba09 | 2010-05-13 18:42:25 +0900 | [diff] [blame] | 64 | /* drivers/sh/clk.c */ |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 65 | unsigned long followparent_recalc(struct clk *); |
| 66 | void recalculate_root_clocks(void); |
| 67 | void propagate_rate(struct clk *); |
| 68 | int clk_reparent(struct clk *child, struct clk *parent); |
| 69 | int clk_register(struct clk *); |
| 70 | void clk_unregister(struct clk *); |
Magnus Damm | 8b5ee11 | 2010-05-11 13:29:25 +0000 | [diff] [blame] | 71 | void clk_enable_init_clocks(void); |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 72 | |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 73 | struct clk_div_mult_table { |
| 74 | unsigned int *divisors; |
| 75 | unsigned int nr_divisors; |
| 76 | unsigned int *multipliers; |
| 77 | unsigned int nr_multipliers; |
| 78 | }; |
| 79 | |
| 80 | struct cpufreq_frequency_table; |
| 81 | void clk_rate_table_build(struct clk *clk, |
| 82 | struct cpufreq_frequency_table *freq_table, |
| 83 | int nr_freqs, |
| 84 | struct clk_div_mult_table *src_table, |
| 85 | unsigned long *bitmap); |
| 86 | |
| 87 | long clk_rate_table_round(struct clk *clk, |
| 88 | struct cpufreq_frequency_table *freq_table, |
| 89 | unsigned long rate); |
| 90 | |
| 91 | int clk_rate_table_find(struct clk *clk, |
| 92 | struct cpufreq_frequency_table *freq_table, |
| 93 | unsigned long rate); |
| 94 | |
Paul Mundt | 8e122db | 2010-10-15 18:33:24 +0900 | [diff] [blame] | 95 | long clk_rate_div_range_round(struct clk *clk, unsigned int div_min, |
| 96 | unsigned int div_max, unsigned long rate); |
| 97 | |
Kuninori Morimoto | dd2c0ca | 2011-09-19 18:51:13 -0700 | [diff] [blame] | 98 | long clk_rate_mult_range_round(struct clk *clk, unsigned int mult_min, |
| 99 | unsigned int mult_max, unsigned long rate); |
| 100 | |
Guennadi Liakhovetski | 6af26c6 | 2010-11-02 11:27:24 +0000 | [diff] [blame] | 101 | long clk_round_parent(struct clk *clk, unsigned long target, |
| 102 | unsigned long *best_freq, unsigned long *parent_freq, |
| 103 | unsigned int div_min, unsigned int div_max); |
| 104 | |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 105 | #define SH_CLK_MSTP32(_parent, _enable_reg, _enable_bit, _flags) \ |
| 106 | { \ |
| 107 | .parent = _parent, \ |
| 108 | .enable_reg = (void __iomem *)_enable_reg, \ |
| 109 | .enable_bit = _enable_bit, \ |
| 110 | .flags = _flags, \ |
| 111 | } |
| 112 | |
| 113 | int sh_clk_mstp32_register(struct clk *clks, int nr); |
| 114 | |
| 115 | #define SH_CLK_DIV4(_parent, _reg, _shift, _div_bitmap, _flags) \ |
| 116 | { \ |
| 117 | .parent = _parent, \ |
| 118 | .enable_reg = (void __iomem *)_reg, \ |
| 119 | .enable_bit = _shift, \ |
| 120 | .arch_flags = _div_bitmap, \ |
| 121 | .flags = _flags, \ |
| 122 | } |
| 123 | |
| 124 | struct clk_div4_table { |
| 125 | struct clk_div_mult_table *div_mult_table; |
| 126 | void (*kick)(struct clk *clk); |
| 127 | }; |
| 128 | |
| 129 | int sh_clk_div4_register(struct clk *clks, int nr, |
| 130 | struct clk_div4_table *table); |
| 131 | int sh_clk_div4_enable_register(struct clk *clks, int nr, |
| 132 | struct clk_div4_table *table); |
| 133 | int sh_clk_div4_reparent_register(struct clk *clks, int nr, |
| 134 | struct clk_div4_table *table); |
| 135 | |
Kuninori Morimoto | 56242a1 | 2011-11-21 21:33:18 -0800 | [diff] [blame] | 136 | #define SH_CLK_DIV6_EXT(_reg, _flags, _parents, \ |
Guennadi Liakhovetski | b3dd51a | 2010-07-21 10:13:10 +0000 | [diff] [blame] | 137 | _num_parents, _src_shift, _src_width) \ |
| 138 | { \ |
Guennadi Liakhovetski | b3dd51a | 2010-07-21 10:13:10 +0000 | [diff] [blame] | 139 | .enable_reg = (void __iomem *)_reg, \ |
| 140 | .flags = _flags, \ |
| 141 | .parent_table = _parents, \ |
| 142 | .parent_num = _num_parents, \ |
| 143 | .src_shift = _src_shift, \ |
| 144 | .src_width = _src_width, \ |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 145 | } |
| 146 | |
Guennadi Liakhovetski | b3dd51a | 2010-07-21 10:13:10 +0000 | [diff] [blame] | 147 | #define SH_CLK_DIV6(_parent, _reg, _flags) \ |
Kuninori Morimoto | 56242a1 | 2011-11-21 21:33:18 -0800 | [diff] [blame] | 148 | { \ |
| 149 | .parent = _parent, \ |
| 150 | .enable_reg = (void __iomem *)_reg, \ |
| 151 | .flags = _flags, \ |
| 152 | } |
Guennadi Liakhovetski | b3dd51a | 2010-07-21 10:13:10 +0000 | [diff] [blame] | 153 | |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 154 | int sh_clk_div6_register(struct clk *clks, int nr); |
Guennadi Liakhovetski | b3dd51a | 2010-07-21 10:13:10 +0000 | [diff] [blame] | 155 | int sh_clk_div6_reparent_register(struct clk *clks, int nr); |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 156 | |
Kuninori Morimoto | 1522043 | 2011-07-06 02:54:11 +0000 | [diff] [blame] | 157 | #define CLKDEV_CON_ID(_id, _clk) { .con_id = _id, .clk = _clk } |
| 158 | #define CLKDEV_DEV_ID(_id, _clk) { .dev_id = _id, .clk = _clk } |
| 159 | #define CLKDEV_ICK_ID(_cid, _did, _clk) { .con_id = _cid, .dev_id = _did, .clk = _clk } |
| 160 | |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 161 | #endif /* __SH_CLOCK_H */ |