1 /* SPDX-License-Identifier: GPL-2.0 */ << 2 #ifndef __SH_CLOCK_H 1 #ifndef __SH_CLOCK_H 3 #define __SH_CLOCK_H 2 #define __SH_CLOCK_H 4 3 5 #include <linux/list.h> 4 #include <linux/list.h> 6 #include <linux/seq_file.h> 5 #include <linux/seq_file.h> 7 #include <linux/cpufreq.h> 6 #include <linux/cpufreq.h> 8 #include <linux/types.h> 7 #include <linux/types.h> 9 #include <linux/kref.h> 8 #include <linux/kref.h> 10 #include <linux/clk.h> 9 #include <linux/clk.h> 11 #include <linux/err.h> 10 #include <linux/err.h> 12 11 13 struct clk; 12 struct clk; 14 13 15 struct clk_mapping { 14 struct clk_mapping { 16 phys_addr_t phys; 15 phys_addr_t phys; 17 void __iomem *base; 16 void __iomem *base; 18 unsigned long len; 17 unsigned long len; 19 struct kref ref; 18 struct kref ref; 20 }; 19 }; 21 20 22 struct sh_clk_ops { 21 struct sh_clk_ops { 23 #ifdef CONFIG_SH_CLK_CPG_LEGACY 22 #ifdef CONFIG_SH_CLK_CPG_LEGACY 24 void (*init)(struct clk *clk); 23 void (*init)(struct clk *clk); 25 #endif 24 #endif 26 int (*enable)(struct clk *clk); 25 int (*enable)(struct clk *clk); 27 void (*disable)(struct clk *clk); 26 void (*disable)(struct clk *clk); 28 unsigned long (*recalc)(struct clk *cl 27 unsigned long (*recalc)(struct clk *clk); 29 int (*set_rate)(struct clk *clk, unsig 28 int (*set_rate)(struct clk *clk, unsigned long rate); 30 int (*set_parent)(struct clk *clk, str 29 int (*set_parent)(struct clk *clk, struct clk *parent); 31 long (*round_rate)(struct clk *clk, un 30 long (*round_rate)(struct clk *clk, unsigned long rate); 32 }; 31 }; 33 32 34 #define SH_CLK_DIV_MSK(div) ((1 << (div)) 33 #define SH_CLK_DIV_MSK(div) ((1 << (div)) - 1) 35 #define SH_CLK_DIV4_MSK SH_CLK_DIV_MSK 34 #define SH_CLK_DIV4_MSK SH_CLK_DIV_MSK(4) 36 #define SH_CLK_DIV6_MSK SH_CLK_DIV_MSK 35 #define SH_CLK_DIV6_MSK SH_CLK_DIV_MSK(6) 37 36 38 struct clk { 37 struct clk { 39 struct list_head node; 38 struct list_head node; 40 struct clk *parent; 39 struct clk *parent; 41 struct clk **parent_table 40 struct clk **parent_table; /* list of parents to */ 42 unsigned short parent_num; 41 unsigned short parent_num; /* choose between */ 43 unsigned char src_shift; 42 unsigned char src_shift; /* source clock field in the */ 44 unsigned char src_width; 43 unsigned char src_width; /* configuration register */ 45 struct sh_clk_ops *ops; 44 struct sh_clk_ops *ops; 46 45 47 struct list_head children; 46 struct list_head children; 48 struct list_head sibling; 47 struct list_head sibling; /* node for children */ 49 48 50 int usecount; 49 int usecount; 51 50 52 unsigned long rate; 51 unsigned long rate; 53 unsigned long flags; 52 unsigned long flags; 54 53 55 void __iomem *enable_reg; 54 void __iomem *enable_reg; 56 void __iomem *status_reg; 55 void __iomem *status_reg; 57 unsigned int enable_bit; 56 unsigned int enable_bit; 58 void __iomem *mapped_reg; 57 void __iomem *mapped_reg; 59 58 60 unsigned int div_mask; 59 unsigned int div_mask; 61 unsigned long arch_flags; 60 unsigned long arch_flags; 62 void *priv; 61 void *priv; 63 struct clk_mapping *mapping; 62 struct clk_mapping *mapping; 64 struct cpufreq_frequency_table *freq_t 63 struct cpufreq_frequency_table *freq_table; 65 unsigned int nr_freqs; 64 unsigned int nr_freqs; 66 }; 65 }; 67 66 68 #define CLK_ENABLE_ON_INIT BIT(0) 67 #define CLK_ENABLE_ON_INIT BIT(0) 69 68 70 #define CLK_ENABLE_REG_32BIT BIT(1) /* def 69 #define CLK_ENABLE_REG_32BIT BIT(1) /* default access size */ 71 #define CLK_ENABLE_REG_16BIT BIT(2) 70 #define CLK_ENABLE_REG_16BIT BIT(2) 72 #define CLK_ENABLE_REG_8BIT BIT(3) 71 #define CLK_ENABLE_REG_8BIT BIT(3) 73 72 74 #define CLK_MASK_DIV_ON_DISABLE BIT(4) 73 #define CLK_MASK_DIV_ON_DISABLE BIT(4) 75 74 76 #define CLK_ENABLE_REG_MASK (CLK_ENABLE_RE 75 #define CLK_ENABLE_REG_MASK (CLK_ENABLE_REG_32BIT | \ 77 CLK_ENABLE_RE 76 CLK_ENABLE_REG_16BIT | \ 78 CLK_ENABLE_RE 77 CLK_ENABLE_REG_8BIT) 79 78 80 /* drivers/sh/clk.c */ 79 /* drivers/sh/clk.c */ 81 unsigned long followparent_recalc(struct clk * 80 unsigned long followparent_recalc(struct clk *); 82 void recalculate_root_clocks(void); 81 void recalculate_root_clocks(void); 83 void propagate_rate(struct clk *); 82 void propagate_rate(struct clk *); 84 int clk_reparent(struct clk *child, struct clk 83 int clk_reparent(struct clk *child, struct clk *parent); 85 int clk_register(struct clk *); 84 int clk_register(struct clk *); 86 void clk_unregister(struct clk *); 85 void clk_unregister(struct clk *); 87 void clk_enable_init_clocks(void); 86 void clk_enable_init_clocks(void); 88 87 89 struct clk_div_mult_table { 88 struct clk_div_mult_table { 90 unsigned int *divisors; 89 unsigned int *divisors; 91 unsigned int nr_divisors; 90 unsigned int nr_divisors; 92 unsigned int *multipliers; 91 unsigned int *multipliers; 93 unsigned int nr_multipliers; 92 unsigned int nr_multipliers; 94 }; 93 }; 95 94 96 struct cpufreq_frequency_table; 95 struct cpufreq_frequency_table; 97 void clk_rate_table_build(struct clk *clk, 96 void clk_rate_table_build(struct clk *clk, 98 struct cpufreq_frequ 97 struct cpufreq_frequency_table *freq_table, 99 int nr_freqs, 98 int nr_freqs, 100 struct clk_div_mult_ 99 struct clk_div_mult_table *src_table, 101 unsigned long *bitma 100 unsigned long *bitmap); 102 101 103 long clk_rate_table_round(struct clk *clk, 102 long clk_rate_table_round(struct clk *clk, 104 struct cpufreq_frequ 103 struct cpufreq_frequency_table *freq_table, 105 unsigned long rate); 104 unsigned long rate); 106 105 107 int clk_rate_table_find(struct clk *clk, 106 int clk_rate_table_find(struct clk *clk, 108 struct cpufreq_frequen 107 struct cpufreq_frequency_table *freq_table, 109 unsigned long rate); 108 unsigned long rate); 110 109 111 long clk_rate_div_range_round(struct clk *clk, 110 long clk_rate_div_range_round(struct clk *clk, unsigned int div_min, 112 unsigned int div 111 unsigned int div_max, unsigned long rate); 113 112 114 long clk_rate_mult_range_round(struct clk *clk 113 long clk_rate_mult_range_round(struct clk *clk, unsigned int mult_min, 115 unsigned int mu 114 unsigned int mult_max, unsigned long rate); 116 115 117 #define SH_CLK_MSTP(_parent, _enable_reg, _ena 116 #define SH_CLK_MSTP(_parent, _enable_reg, _enable_bit, _status_reg, _flags) \ 118 { 117 { \ 119 .parent = _parent, 118 .parent = _parent, \ 120 .enable_reg = (void __iomem *)_ena 119 .enable_reg = (void __iomem *)_enable_reg, \ 121 .enable_bit = _enable_bit, 120 .enable_bit = _enable_bit, \ 122 .status_reg = _status_reg, 121 .status_reg = _status_reg, \ 123 .flags = _flags, 122 .flags = _flags, \ 124 } 123 } 125 124 126 #define SH_CLK_MSTP32(_p, _r, _b, _f) 125 #define SH_CLK_MSTP32(_p, _r, _b, _f) \ 127 SH_CLK_MSTP(_p, _r, _b, 0, _f | CLK_EN 126 SH_CLK_MSTP(_p, _r, _b, 0, _f | CLK_ENABLE_REG_32BIT) 128 127 129 #define SH_CLK_MSTP32_STS(_p, _r, _b, _s, _f) 128 #define SH_CLK_MSTP32_STS(_p, _r, _b, _s, _f) \ 130 SH_CLK_MSTP(_p, _r, _b, _s, _f | CLK_E 129 SH_CLK_MSTP(_p, _r, _b, _s, _f | CLK_ENABLE_REG_32BIT) 131 130 132 #define SH_CLK_MSTP16(_p, _r, _b, _f) 131 #define SH_CLK_MSTP16(_p, _r, _b, _f) \ 133 SH_CLK_MSTP(_p, _r, _b, 0, _f | CLK_EN 132 SH_CLK_MSTP(_p, _r, _b, 0, _f | CLK_ENABLE_REG_16BIT) 134 133 135 #define SH_CLK_MSTP8(_p, _r, _b, _f) 134 #define SH_CLK_MSTP8(_p, _r, _b, _f) \ 136 SH_CLK_MSTP(_p, _r, _b, 0, _f | CLK_EN 135 SH_CLK_MSTP(_p, _r, _b, 0, _f | CLK_ENABLE_REG_8BIT) 137 136 138 int sh_clk_mstp_register(struct clk *clks, int 137 int sh_clk_mstp_register(struct clk *clks, int nr); 139 138 140 /* 139 /* 141 * MSTP registration never really cared about 140 * MSTP registration never really cared about access size, despite the 142 * original enable/disable pairs assuming a 32 141 * original enable/disable pairs assuming a 32-bit access. Clocks are 143 * responsible for defining their access sizes 142 * responsible for defining their access sizes either directly or via the 144 * clock definition wrappers. 143 * clock definition wrappers. 145 */ 144 */ 146 static inline int __deprecated sh_clk_mstp32_r 145 static inline int __deprecated sh_clk_mstp32_register(struct clk *clks, int nr) 147 { 146 { 148 return sh_clk_mstp_register(clks, nr); 147 return sh_clk_mstp_register(clks, nr); 149 } 148 } 150 149 151 #define SH_CLK_DIV4(_parent, _reg, _shift, _di 150 #define SH_CLK_DIV4(_parent, _reg, _shift, _div_bitmap, _flags) \ 152 { 151 { \ 153 .parent = _parent, 152 .parent = _parent, \ 154 .enable_reg = (void __iomem *)_reg, 153 .enable_reg = (void __iomem *)_reg, \ 155 .enable_bit = _shift, 154 .enable_bit = _shift, \ 156 .arch_flags = _div_bitmap, 155 .arch_flags = _div_bitmap, \ 157 .div_mask = SH_CLK_DIV4_MSK, 156 .div_mask = SH_CLK_DIV4_MSK, \ 158 .flags = _flags, 157 .flags = _flags, \ 159 } 158 } 160 159 161 struct clk_div_table { 160 struct clk_div_table { 162 struct clk_div_mult_table *div_mult_ta 161 struct clk_div_mult_table *div_mult_table; 163 void (*kick)(struct clk *clk); 162 void (*kick)(struct clk *clk); 164 }; 163 }; 165 164 166 #define clk_div4_table clk_div_table 165 #define clk_div4_table clk_div_table 167 166 168 int sh_clk_div4_register(struct clk *clks, int 167 int sh_clk_div4_register(struct clk *clks, int nr, 169 struct clk_div4_table 168 struct clk_div4_table *table); 170 int sh_clk_div4_enable_register(struct clk *cl 169 int sh_clk_div4_enable_register(struct clk *clks, int nr, 171 struct clk_div4_table 170 struct clk_div4_table *table); 172 int sh_clk_div4_reparent_register(struct clk * 171 int sh_clk_div4_reparent_register(struct clk *clks, int nr, 173 struct clk_div4_table 172 struct clk_div4_table *table); 174 173 175 #define SH_CLK_DIV6_EXT(_reg, _flags, _parents 174 #define SH_CLK_DIV6_EXT(_reg, _flags, _parents, \ 176 _num_parents, _src_shi 175 _num_parents, _src_shift, _src_width) \ 177 { 176 { \ 178 .enable_reg = (void __iomem *)_reg, 177 .enable_reg = (void __iomem *)_reg, \ 179 .enable_bit = 0, /* unused */ 178 .enable_bit = 0, /* unused */ \ 180 .flags = _flags | CLK_MASK_DIV_ON_DISA 179 .flags = _flags | CLK_MASK_DIV_ON_DISABLE, \ 181 .div_mask = SH_CLK_DIV6_MSK, 180 .div_mask = SH_CLK_DIV6_MSK, \ 182 .parent_table = _parents, 181 .parent_table = _parents, \ 183 .parent_num = _num_parents, 182 .parent_num = _num_parents, \ 184 .src_shift = _src_shift, 183 .src_shift = _src_shift, \ 185 .src_width = _src_width, 184 .src_width = _src_width, \ 186 } 185 } 187 186 188 #define SH_CLK_DIV6(_parent, _reg, _flags) 187 #define SH_CLK_DIV6(_parent, _reg, _flags) \ 189 { 188 { \ 190 .parent = _parent, 189 .parent = _parent, \ 191 .enable_reg = (void __iomem *)_reg 190 .enable_reg = (void __iomem *)_reg, \ 192 .enable_bit = 0, /* unused */ 191 .enable_bit = 0, /* unused */ \ 193 .div_mask = SH_CLK_DIV6_MSK, 192 .div_mask = SH_CLK_DIV6_MSK, \ 194 .flags = _flags | CLK_MASK_DI 193 .flags = _flags | CLK_MASK_DIV_ON_DISABLE, \ 195 } 194 } 196 195 197 int sh_clk_div6_register(struct clk *clks, int 196 int sh_clk_div6_register(struct clk *clks, int nr); 198 int sh_clk_div6_reparent_register(struct clk * 197 int sh_clk_div6_reparent_register(struct clk *clks, int nr); 199 198 200 #define CLKDEV_CON_ID(_id, _clk) { .con_id = _ 199 #define CLKDEV_CON_ID(_id, _clk) { .con_id = _id, .clk = _clk } 201 #define CLKDEV_DEV_ID(_id, _clk) { .dev_id = _ 200 #define CLKDEV_DEV_ID(_id, _clk) { .dev_id = _id, .clk = _clk } 202 #define CLKDEV_ICK_ID(_cid, _did, _clk) { .con 201 #define CLKDEV_ICK_ID(_cid, _did, _clk) { .con_id = _cid, .dev_id = _did, .clk = _clk } 203 202 204 /* .enable_reg will be updated to .mapping on 203 /* .enable_reg will be updated to .mapping on sh_clk_fsidiv_register() */ 205 #define SH_CLK_FSIDIV(_reg, _parent) 204 #define SH_CLK_FSIDIV(_reg, _parent) \ 206 { 205 { \ 207 .enable_reg = (void __iomem *)_reg, 206 .enable_reg = (void __iomem *)_reg, \ 208 .parent = _parent, 207 .parent = _parent, \ 209 } 208 } 210 209 211 int sh_clk_fsidiv_register(struct clk *clks, i 210 int sh_clk_fsidiv_register(struct clk *clks, int nr); 212 211 213 #endif /* __SH_CLOCK_H */ 212 #endif /* __SH_CLOCK_H */ 214 213
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.