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 | 84c36ff | 2012-02-29 22:18:19 +0900 | [diff] [blame] | 21 | struct sh_clk_ops { |
Paul Mundt | 549015c | 2010-11-15 18:48:25 +0900 | [diff] [blame] | 22 | #ifdef CONFIG_SH_CLK_CPG_LEGACY |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 23 | void (*init)(struct clk *clk); |
Paul Mundt | 549015c | 2010-11-15 18:48:25 +0900 | [diff] [blame] | 24 | #endif |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 25 | int (*enable)(struct clk *clk); |
| 26 | void (*disable)(struct clk *clk); |
| 27 | unsigned long (*recalc)(struct clk *clk); |
Paul Mundt | 35a96c7 | 2010-11-15 18:18:32 +0900 | [diff] [blame] | 28 | int (*set_rate)(struct clk *clk, unsigned long rate); |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 29 | int (*set_parent)(struct clk *clk, struct clk *parent); |
| 30 | long (*round_rate)(struct clk *clk, unsigned long rate); |
| 31 | }; |
| 32 | |
Paul Mundt | 1111cc1 | 2012-05-25 15:21:43 +0900 | [diff] [blame] | 33 | #define SH_CLK_DIV_MSK(div) ((1 << (div)) - 1) |
| 34 | #define SH_CLK_DIV4_MSK SH_CLK_DIV_MSK(4) |
| 35 | #define SH_CLK_DIV6_MSK SH_CLK_DIV_MSK(6) |
| 36 | |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 37 | struct clk { |
| 38 | struct list_head node; |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 39 | struct clk *parent; |
Guennadi Liakhovetski | b5272b50 | 2010-07-21 10:13:06 +0000 | [diff] [blame] | 40 | struct clk **parent_table; /* list of parents to */ |
| 41 | unsigned short parent_num; /* choose between */ |
| 42 | unsigned char src_shift; /* source clock field in the */ |
| 43 | unsigned char src_width; /* configuration register */ |
Magnus Damm | 84c36ff | 2012-02-29 22:18:19 +0900 | [diff] [blame] | 44 | struct sh_clk_ops *ops; |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 45 | |
| 46 | struct list_head children; |
| 47 | struct list_head sibling; /* node for children */ |
| 48 | |
| 49 | int usecount; |
| 50 | |
| 51 | unsigned long rate; |
| 52 | unsigned long flags; |
| 53 | |
| 54 | void __iomem *enable_reg; |
Guennadi Liakhovetski | a028c6d | 2013-12-14 16:23:51 +0100 | [diff] [blame^] | 55 | void __iomem *status_reg; |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 56 | unsigned int enable_bit; |
Magnus Damm | eda2030 | 2011-12-08 22:58:54 +0900 | [diff] [blame] | 57 | void __iomem *mapped_reg; |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 58 | |
Paul Mundt | 1111cc1 | 2012-05-25 15:21:43 +0900 | [diff] [blame] | 59 | unsigned int div_mask; |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 60 | unsigned long arch_flags; |
| 61 | void *priv; |
Paul Mundt | 28085bc | 2010-10-15 16:46:37 +0900 | [diff] [blame] | 62 | struct clk_mapping *mapping; |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 63 | struct cpufreq_frequency_table *freq_table; |
Paul Mundt | f586903 | 2010-10-15 18:17:35 +0900 | [diff] [blame] | 64 | unsigned int nr_freqs; |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 65 | }; |
| 66 | |
Paul Mundt | 4d6ddb0 | 2012-04-11 12:05:50 +0900 | [diff] [blame] | 67 | #define CLK_ENABLE_ON_INIT BIT(0) |
| 68 | |
| 69 | #define CLK_ENABLE_REG_32BIT BIT(1) /* default access size */ |
| 70 | #define CLK_ENABLE_REG_16BIT BIT(2) |
| 71 | #define CLK_ENABLE_REG_8BIT BIT(3) |
| 72 | |
Paul Mundt | 764f4e4 | 2012-05-25 16:34:48 +0900 | [diff] [blame] | 73 | #define CLK_MASK_DIV_ON_DISABLE BIT(4) |
| 74 | |
Paul Mundt | 4d6ddb0 | 2012-04-11 12:05:50 +0900 | [diff] [blame] | 75 | #define CLK_ENABLE_REG_MASK (CLK_ENABLE_REG_32BIT | \ |
| 76 | CLK_ENABLE_REG_16BIT | \ |
| 77 | CLK_ENABLE_REG_8BIT) |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 78 | |
Paul Mundt | a71ba09 | 2010-05-13 18:42:25 +0900 | [diff] [blame] | 79 | /* drivers/sh/clk.c */ |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 80 | unsigned long followparent_recalc(struct clk *); |
| 81 | void recalculate_root_clocks(void); |
| 82 | void propagate_rate(struct clk *); |
| 83 | int clk_reparent(struct clk *child, struct clk *parent); |
| 84 | int clk_register(struct clk *); |
| 85 | void clk_unregister(struct clk *); |
Magnus Damm | 8b5ee11 | 2010-05-11 13:29:25 +0000 | [diff] [blame] | 86 | void clk_enable_init_clocks(void); |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 87 | |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 88 | struct clk_div_mult_table { |
| 89 | unsigned int *divisors; |
| 90 | unsigned int nr_divisors; |
| 91 | unsigned int *multipliers; |
| 92 | unsigned int nr_multipliers; |
| 93 | }; |
| 94 | |
| 95 | struct cpufreq_frequency_table; |
| 96 | void clk_rate_table_build(struct clk *clk, |
| 97 | struct cpufreq_frequency_table *freq_table, |
| 98 | int nr_freqs, |
| 99 | struct clk_div_mult_table *src_table, |
| 100 | unsigned long *bitmap); |
| 101 | |
| 102 | long clk_rate_table_round(struct clk *clk, |
| 103 | struct cpufreq_frequency_table *freq_table, |
| 104 | unsigned long rate); |
| 105 | |
| 106 | int clk_rate_table_find(struct clk *clk, |
| 107 | struct cpufreq_frequency_table *freq_table, |
| 108 | unsigned long rate); |
| 109 | |
Paul Mundt | 8e122db | 2010-10-15 18:33:24 +0900 | [diff] [blame] | 110 | long clk_rate_div_range_round(struct clk *clk, unsigned int div_min, |
| 111 | unsigned int div_max, unsigned long rate); |
| 112 | |
Kuninori Morimoto | dd2c0ca | 2011-09-19 18:51:13 -0700 | [diff] [blame] | 113 | long clk_rate_mult_range_round(struct clk *clk, unsigned int mult_min, |
| 114 | unsigned int mult_max, unsigned long rate); |
| 115 | |
Guennadi Liakhovetski | 6af26c6 | 2010-11-02 11:27:24 +0000 | [diff] [blame] | 116 | long clk_round_parent(struct clk *clk, unsigned long target, |
| 117 | unsigned long *best_freq, unsigned long *parent_freq, |
| 118 | unsigned int div_min, unsigned int div_max); |
| 119 | |
Guennadi Liakhovetski | a028c6d | 2013-12-14 16:23:51 +0100 | [diff] [blame^] | 120 | #define SH_CLK_MSTP(_parent, _enable_reg, _enable_bit, _status_reg, _flags) \ |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 121 | { \ |
| 122 | .parent = _parent, \ |
| 123 | .enable_reg = (void __iomem *)_enable_reg, \ |
| 124 | .enable_bit = _enable_bit, \ |
Guennadi Liakhovetski | a028c6d | 2013-12-14 16:23:51 +0100 | [diff] [blame^] | 125 | .status_reg = _status_reg, \ |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 126 | .flags = _flags, \ |
| 127 | } |
| 128 | |
Guennadi Liakhovetski | a028c6d | 2013-12-14 16:23:51 +0100 | [diff] [blame^] | 129 | #define SH_CLK_MSTP32(_p, _r, _b, _f) \ |
| 130 | SH_CLK_MSTP(_p, _r, _b, 0, _f | CLK_ENABLE_REG_32BIT) |
Paul Mundt | 4d6ddb0 | 2012-04-11 12:05:50 +0900 | [diff] [blame] | 131 | |
Guennadi Liakhovetski | a028c6d | 2013-12-14 16:23:51 +0100 | [diff] [blame^] | 132 | #define SH_CLK_MSTP32_STS(_p, _r, _b, _s, _f) \ |
| 133 | SH_CLK_MSTP(_p, _r, _b, _s, _f | CLK_ENABLE_REG_32BIT) |
Paul Mundt | 4d6ddb0 | 2012-04-11 12:05:50 +0900 | [diff] [blame] | 134 | |
Guennadi Liakhovetski | a028c6d | 2013-12-14 16:23:51 +0100 | [diff] [blame^] | 135 | #define SH_CLK_MSTP16(_p, _r, _b, _f) \ |
| 136 | SH_CLK_MSTP(_p, _r, _b, 0, _f | CLK_ENABLE_REG_16BIT) |
| 137 | |
| 138 | #define SH_CLK_MSTP8(_p, _r, _b, _f) \ |
| 139 | SH_CLK_MSTP(_p, _r, _b, 0, _f | CLK_ENABLE_REG_8BIT) |
Paul Mundt | 4d6ddb0 | 2012-04-11 12:05:50 +0900 | [diff] [blame] | 140 | |
| 141 | int sh_clk_mstp_register(struct clk *clks, int nr); |
| 142 | |
| 143 | /* |
| 144 | * MSTP registration never really cared about access size, despite the |
| 145 | * original enable/disable pairs assuming a 32-bit access. Clocks are |
| 146 | * responsible for defining their access sizes either directly or via the |
| 147 | * clock definition wrappers. |
| 148 | */ |
| 149 | static inline int __deprecated sh_clk_mstp32_register(struct clk *clks, int nr) |
| 150 | { |
| 151 | return sh_clk_mstp_register(clks, nr); |
| 152 | } |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 153 | |
| 154 | #define SH_CLK_DIV4(_parent, _reg, _shift, _div_bitmap, _flags) \ |
| 155 | { \ |
| 156 | .parent = _parent, \ |
| 157 | .enable_reg = (void __iomem *)_reg, \ |
| 158 | .enable_bit = _shift, \ |
| 159 | .arch_flags = _div_bitmap, \ |
Paul Mundt | 1111cc1 | 2012-05-25 15:21:43 +0900 | [diff] [blame] | 160 | .div_mask = SH_CLK_DIV4_MSK, \ |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 161 | .flags = _flags, \ |
| 162 | } |
| 163 | |
Paul Mundt | a60977a | 2012-05-25 14:59:26 +0900 | [diff] [blame] | 164 | struct clk_div_table { |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 165 | struct clk_div_mult_table *div_mult_table; |
| 166 | void (*kick)(struct clk *clk); |
| 167 | }; |
| 168 | |
Paul Mundt | a60977a | 2012-05-25 14:59:26 +0900 | [diff] [blame] | 169 | #define clk_div4_table clk_div_table |
| 170 | |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 171 | int sh_clk_div4_register(struct clk *clks, int nr, |
| 172 | struct clk_div4_table *table); |
| 173 | int sh_clk_div4_enable_register(struct clk *clks, int nr, |
| 174 | struct clk_div4_table *table); |
| 175 | int sh_clk_div4_reparent_register(struct clk *clks, int nr, |
| 176 | struct clk_div4_table *table); |
| 177 | |
Kuninori Morimoto | 56242a1 | 2011-11-21 21:33:18 -0800 | [diff] [blame] | 178 | #define SH_CLK_DIV6_EXT(_reg, _flags, _parents, \ |
Guennadi Liakhovetski | b3dd51a | 2010-07-21 10:13:10 +0000 | [diff] [blame] | 179 | _num_parents, _src_shift, _src_width) \ |
| 180 | { \ |
Guennadi Liakhovetski | b3dd51a | 2010-07-21 10:13:10 +0000 | [diff] [blame] | 181 | .enable_reg = (void __iomem *)_reg, \ |
Paul Mundt | 75f5f8a | 2012-05-25 15:26:01 +0900 | [diff] [blame] | 182 | .enable_bit = 0, /* unused */ \ |
Paul Mundt | 764f4e4 | 2012-05-25 16:34:48 +0900 | [diff] [blame] | 183 | .flags = _flags | CLK_MASK_DIV_ON_DISABLE, \ |
Paul Mundt | 1111cc1 | 2012-05-25 15:21:43 +0900 | [diff] [blame] | 184 | .div_mask = SH_CLK_DIV6_MSK, \ |
Guennadi Liakhovetski | b3dd51a | 2010-07-21 10:13:10 +0000 | [diff] [blame] | 185 | .parent_table = _parents, \ |
| 186 | .parent_num = _num_parents, \ |
| 187 | .src_shift = _src_shift, \ |
| 188 | .src_width = _src_width, \ |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 189 | } |
| 190 | |
Guennadi Liakhovetski | b3dd51a | 2010-07-21 10:13:10 +0000 | [diff] [blame] | 191 | #define SH_CLK_DIV6(_parent, _reg, _flags) \ |
Kuninori Morimoto | 56242a1 | 2011-11-21 21:33:18 -0800 | [diff] [blame] | 192 | { \ |
| 193 | .parent = _parent, \ |
| 194 | .enable_reg = (void __iomem *)_reg, \ |
Paul Mundt | 75f5f8a | 2012-05-25 15:26:01 +0900 | [diff] [blame] | 195 | .enable_bit = 0, /* unused */ \ |
Paul Mundt | 1111cc1 | 2012-05-25 15:21:43 +0900 | [diff] [blame] | 196 | .div_mask = SH_CLK_DIV6_MSK, \ |
Paul Mundt | 764f4e4 | 2012-05-25 16:34:48 +0900 | [diff] [blame] | 197 | .flags = _flags | CLK_MASK_DIV_ON_DISABLE, \ |
Kuninori Morimoto | 56242a1 | 2011-11-21 21:33:18 -0800 | [diff] [blame] | 198 | } |
Guennadi Liakhovetski | b3dd51a | 2010-07-21 10:13:10 +0000 | [diff] [blame] | 199 | |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 200 | int sh_clk_div6_register(struct clk *clks, int nr); |
Guennadi Liakhovetski | b3dd51a | 2010-07-21 10:13:10 +0000 | [diff] [blame] | 201 | int sh_clk_div6_reparent_register(struct clk *clks, int nr); |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 202 | |
Kuninori Morimoto | 1522043 | 2011-07-06 02:54:11 +0000 | [diff] [blame] | 203 | #define CLKDEV_CON_ID(_id, _clk) { .con_id = _id, .clk = _clk } |
| 204 | #define CLKDEV_DEV_ID(_id, _clk) { .dev_id = _id, .clk = _clk } |
| 205 | #define CLKDEV_ICK_ID(_cid, _did, _clk) { .con_id = _cid, .dev_id = _did, .clk = _clk } |
| 206 | |
Kuninori Morimoto | 9d626ec | 2012-10-30 20:06:55 -0700 | [diff] [blame] | 207 | /* .enable_reg will be updated to .mapping on sh_clk_fsidiv_register() */ |
| 208 | #define SH_CLK_FSIDIV(_reg, _parent) \ |
| 209 | { \ |
| 210 | .enable_reg = (void __iomem *)_reg, \ |
| 211 | .parent = _parent, \ |
| 212 | } |
| 213 | |
| 214 | int sh_clk_fsidiv_register(struct clk *clks, int nr); |
| 215 | |
Magnus Damm | d28bdf0 | 2010-05-11 13:29:17 +0000 | [diff] [blame] | 216 | #endif /* __SH_CLOCK_H */ |