Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de> |
| 3 | * Copyright (C) 2011 Richard Zhao, Linaro <richard.zhao@linaro.org> |
| 4 | * Copyright (C) 2011-2012 Mike Turquette, Linaro Ltd <mturquette@linaro.org> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | * Adjustable divider clock implementation |
| 11 | */ |
| 12 | |
| 13 | #include <linux/clk-provider.h> |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/slab.h> |
| 16 | #include <linux/io.h> |
| 17 | #include <linux/err.h> |
| 18 | #include <linux/string.h> |
James Hogan | 1a3cd18 | 2013-01-15 10:28:05 +0000 | [diff] [blame] | 19 | #include <linux/log2.h> |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 20 | |
| 21 | /* |
| 22 | * DOC: basic adjustable divider clock that cannot gate |
| 23 | * |
| 24 | * Traits of this clock: |
| 25 | * prepare - clk_prepare only ensures that parents are prepared |
| 26 | * enable - clk_enable only ensures that parents are enabled |
Brian Norris | 9556f9d | 2015-04-13 16:03:21 -0700 | [diff] [blame] | 27 | * rate - rate is adjustable. clk->rate = ceiling(parent->rate / divisor) |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 28 | * parent - fixed parent. No clk_set_parent support |
| 29 | */ |
| 30 | |
Stephen Boyd | fab88ca | 2015-11-30 17:31:38 -0800 | [diff] [blame] | 31 | static unsigned int _get_table_maxdiv(const struct clk_div_table *table, |
| 32 | u8 width) |
Rajendra Nayak | 357c3f0 | 2012-06-29 19:06:32 +0530 | [diff] [blame] | 33 | { |
Jerome Brunet | e6d3cc7 | 2018-02-14 14:43:33 +0100 | [diff] [blame] | 34 | unsigned int maxdiv = 0, mask = clk_div_mask(width); |
Rajendra Nayak | 357c3f0 | 2012-06-29 19:06:32 +0530 | [diff] [blame] | 35 | const struct clk_div_table *clkt; |
| 36 | |
| 37 | for (clkt = table; clkt->div; clkt++) |
Stephen Boyd | fab88ca | 2015-11-30 17:31:38 -0800 | [diff] [blame] | 38 | if (clkt->div > maxdiv && clkt->val <= mask) |
Rajendra Nayak | 357c3f0 | 2012-06-29 19:06:32 +0530 | [diff] [blame] | 39 | maxdiv = clkt->div; |
| 40 | return maxdiv; |
| 41 | } |
| 42 | |
Maxime COQUELIN | 774b514 | 2014-01-29 17:24:07 +0100 | [diff] [blame] | 43 | static unsigned int _get_table_mindiv(const struct clk_div_table *table) |
| 44 | { |
| 45 | unsigned int mindiv = UINT_MAX; |
| 46 | const struct clk_div_table *clkt; |
| 47 | |
| 48 | for (clkt = table; clkt->div; clkt++) |
| 49 | if (clkt->div < mindiv) |
| 50 | mindiv = clkt->div; |
| 51 | return mindiv; |
| 52 | } |
| 53 | |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 54 | static unsigned int _get_maxdiv(const struct clk_div_table *table, u8 width, |
| 55 | unsigned long flags) |
Rajendra Nayak | 6d9252b | 2012-05-17 15:52:13 +0530 | [diff] [blame] | 56 | { |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 57 | if (flags & CLK_DIVIDER_ONE_BASED) |
Jerome Brunet | e6d3cc7 | 2018-02-14 14:43:33 +0100 | [diff] [blame] | 58 | return clk_div_mask(width); |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 59 | if (flags & CLK_DIVIDER_POWER_OF_TWO) |
Jerome Brunet | e6d3cc7 | 2018-02-14 14:43:33 +0100 | [diff] [blame] | 60 | return 1 << clk_div_mask(width); |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 61 | if (table) |
Stephen Boyd | fab88ca | 2015-11-30 17:31:38 -0800 | [diff] [blame] | 62 | return _get_table_maxdiv(table, width); |
Jerome Brunet | e6d3cc7 | 2018-02-14 14:43:33 +0100 | [diff] [blame] | 63 | return clk_div_mask(width) + 1; |
Rajendra Nayak | 6d9252b | 2012-05-17 15:52:13 +0530 | [diff] [blame] | 64 | } |
| 65 | |
Rajendra Nayak | 357c3f0 | 2012-06-29 19:06:32 +0530 | [diff] [blame] | 66 | static unsigned int _get_table_div(const struct clk_div_table *table, |
| 67 | unsigned int val) |
| 68 | { |
| 69 | const struct clk_div_table *clkt; |
| 70 | |
| 71 | for (clkt = table; clkt->div; clkt++) |
| 72 | if (clkt->val == val) |
| 73 | return clkt->div; |
| 74 | return 0; |
| 75 | } |
| 76 | |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 77 | static unsigned int _get_div(const struct clk_div_table *table, |
Jim Quinlan | afe76c8f | 2015-05-15 15:45:47 -0400 | [diff] [blame] | 78 | unsigned int val, unsigned long flags, u8 width) |
Rajendra Nayak | 6d9252b | 2012-05-17 15:52:13 +0530 | [diff] [blame] | 79 | { |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 80 | if (flags & CLK_DIVIDER_ONE_BASED) |
Rajendra Nayak | 6d9252b | 2012-05-17 15:52:13 +0530 | [diff] [blame] | 81 | return val; |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 82 | if (flags & CLK_DIVIDER_POWER_OF_TWO) |
Rajendra Nayak | 6d9252b | 2012-05-17 15:52:13 +0530 | [diff] [blame] | 83 | return 1 << val; |
Jim Quinlan | afe76c8f | 2015-05-15 15:45:47 -0400 | [diff] [blame] | 84 | if (flags & CLK_DIVIDER_MAX_AT_ZERO) |
Jerome Brunet | e6d3cc7 | 2018-02-14 14:43:33 +0100 | [diff] [blame] | 85 | return val ? val : clk_div_mask(width) + 1; |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 86 | if (table) |
| 87 | return _get_table_div(table, val); |
Rajendra Nayak | 6d9252b | 2012-05-17 15:52:13 +0530 | [diff] [blame] | 88 | return val + 1; |
| 89 | } |
| 90 | |
Rajendra Nayak | 357c3f0 | 2012-06-29 19:06:32 +0530 | [diff] [blame] | 91 | static unsigned int _get_table_val(const struct clk_div_table *table, |
| 92 | unsigned int div) |
| 93 | { |
| 94 | const struct clk_div_table *clkt; |
| 95 | |
| 96 | for (clkt = table; clkt->div; clkt++) |
| 97 | if (clkt->div == div) |
| 98 | return clkt->val; |
| 99 | return 0; |
| 100 | } |
| 101 | |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 102 | static unsigned int _get_val(const struct clk_div_table *table, |
Jim Quinlan | afe76c8f | 2015-05-15 15:45:47 -0400 | [diff] [blame] | 103 | unsigned int div, unsigned long flags, u8 width) |
Rajendra Nayak | 6d9252b | 2012-05-17 15:52:13 +0530 | [diff] [blame] | 104 | { |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 105 | if (flags & CLK_DIVIDER_ONE_BASED) |
Rajendra Nayak | 6d9252b | 2012-05-17 15:52:13 +0530 | [diff] [blame] | 106 | return div; |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 107 | if (flags & CLK_DIVIDER_POWER_OF_TWO) |
Rajendra Nayak | 6d9252b | 2012-05-17 15:52:13 +0530 | [diff] [blame] | 108 | return __ffs(div); |
Jim Quinlan | afe76c8f | 2015-05-15 15:45:47 -0400 | [diff] [blame] | 109 | if (flags & CLK_DIVIDER_MAX_AT_ZERO) |
Jerome Brunet | e6d3cc7 | 2018-02-14 14:43:33 +0100 | [diff] [blame] | 110 | return (div == clk_div_mask(width) + 1) ? 0 : div; |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 111 | if (table) |
| 112 | return _get_table_val(table, div); |
Rajendra Nayak | 6d9252b | 2012-05-17 15:52:13 +0530 | [diff] [blame] | 113 | return div - 1; |
| 114 | } |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 115 | |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 116 | unsigned long divider_recalc_rate(struct clk_hw *hw, unsigned long parent_rate, |
| 117 | unsigned int val, |
| 118 | const struct clk_div_table *table, |
Jerome Brunet | 12a26c2 | 2017-12-21 17:30:54 +0100 | [diff] [blame] | 119 | unsigned long flags, unsigned long width) |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 120 | { |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 121 | unsigned int div; |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 122 | |
Jerome Brunet | 12a26c2 | 2017-12-21 17:30:54 +0100 | [diff] [blame] | 123 | div = _get_div(table, val, flags, width); |
Rajendra Nayak | 6d9252b | 2012-05-17 15:52:13 +0530 | [diff] [blame] | 124 | if (!div) { |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 125 | WARN(!(flags & CLK_DIVIDER_ALLOW_ZERO), |
Soren Brinkmann | 056b2053 | 2013-04-02 15:36:56 -0700 | [diff] [blame] | 126 | "%s: Zero divisor and CLK_DIVIDER_ALLOW_ZERO not set\n", |
Stephen Boyd | 2f508a9 | 2015-07-30 17:20:57 -0700 | [diff] [blame] | 127 | clk_hw_get_name(hw)); |
Rajendra Nayak | 6d9252b | 2012-05-17 15:52:13 +0530 | [diff] [blame] | 128 | return parent_rate; |
| 129 | } |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 130 | |
Brian Norris | 9556f9d | 2015-04-13 16:03:21 -0700 | [diff] [blame] | 131 | return DIV_ROUND_UP_ULL((u64)parent_rate, div); |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 132 | } |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 133 | EXPORT_SYMBOL_GPL(divider_recalc_rate); |
| 134 | |
| 135 | static unsigned long clk_divider_recalc_rate(struct clk_hw *hw, |
| 136 | unsigned long parent_rate) |
| 137 | { |
| 138 | struct clk_divider *divider = to_clk_divider(hw); |
| 139 | unsigned int val; |
| 140 | |
| 141 | val = clk_readl(divider->reg) >> divider->shift; |
Jerome Brunet | e6d3cc7 | 2018-02-14 14:43:33 +0100 | [diff] [blame] | 142 | val &= clk_div_mask(divider->width); |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 143 | |
| 144 | return divider_recalc_rate(hw, parent_rate, val, divider->table, |
Jerome Brunet | 12a26c2 | 2017-12-21 17:30:54 +0100 | [diff] [blame] | 145 | divider->flags, divider->width); |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 146 | } |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 147 | |
Rajendra Nayak | 357c3f0 | 2012-06-29 19:06:32 +0530 | [diff] [blame] | 148 | static bool _is_valid_table_div(const struct clk_div_table *table, |
| 149 | unsigned int div) |
| 150 | { |
| 151 | const struct clk_div_table *clkt; |
| 152 | |
| 153 | for (clkt = table; clkt->div; clkt++) |
| 154 | if (clkt->div == div) |
| 155 | return true; |
| 156 | return false; |
| 157 | } |
| 158 | |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 159 | static bool _is_valid_div(const struct clk_div_table *table, unsigned int div, |
| 160 | unsigned long flags) |
Rajendra Nayak | 357c3f0 | 2012-06-29 19:06:32 +0530 | [diff] [blame] | 161 | { |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 162 | if (flags & CLK_DIVIDER_POWER_OF_TWO) |
James Hogan | 1a3cd18 | 2013-01-15 10:28:05 +0000 | [diff] [blame] | 163 | return is_power_of_2(div); |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 164 | if (table) |
| 165 | return _is_valid_table_div(table, div); |
Rajendra Nayak | 357c3f0 | 2012-06-29 19:06:32 +0530 | [diff] [blame] | 166 | return true; |
| 167 | } |
| 168 | |
Maxime COQUELIN | dd23c2c | 2014-01-29 17:24:06 +0100 | [diff] [blame] | 169 | static int _round_up_table(const struct clk_div_table *table, int div) |
| 170 | { |
| 171 | const struct clk_div_table *clkt; |
Maxime COQUELIN | fe52e75 | 2014-05-07 18:48:52 +0200 | [diff] [blame] | 172 | int up = INT_MAX; |
Maxime COQUELIN | dd23c2c | 2014-01-29 17:24:06 +0100 | [diff] [blame] | 173 | |
| 174 | for (clkt = table; clkt->div; clkt++) { |
| 175 | if (clkt->div == div) |
| 176 | return clkt->div; |
| 177 | else if (clkt->div < div) |
| 178 | continue; |
| 179 | |
| 180 | if ((clkt->div - div) < (up - div)) |
| 181 | up = clkt->div; |
| 182 | } |
| 183 | |
| 184 | return up; |
| 185 | } |
| 186 | |
Maxime COQUELIN | 774b514 | 2014-01-29 17:24:07 +0100 | [diff] [blame] | 187 | static int _round_down_table(const struct clk_div_table *table, int div) |
| 188 | { |
| 189 | const struct clk_div_table *clkt; |
| 190 | int down = _get_table_mindiv(table); |
| 191 | |
| 192 | for (clkt = table; clkt->div; clkt++) { |
| 193 | if (clkt->div == div) |
| 194 | return clkt->div; |
| 195 | else if (clkt->div > div) |
| 196 | continue; |
| 197 | |
| 198 | if ((div - clkt->div) < (div - down)) |
| 199 | down = clkt->div; |
| 200 | } |
| 201 | |
| 202 | return down; |
| 203 | } |
| 204 | |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 205 | static int _div_round_up(const struct clk_div_table *table, |
| 206 | unsigned long parent_rate, unsigned long rate, |
| 207 | unsigned long flags) |
Maxime COQUELIN | dd23c2c | 2014-01-29 17:24:06 +0100 | [diff] [blame] | 208 | { |
Brian Norris | 9556f9d | 2015-04-13 16:03:21 -0700 | [diff] [blame] | 209 | int div = DIV_ROUND_UP_ULL((u64)parent_rate, rate); |
Maxime COQUELIN | dd23c2c | 2014-01-29 17:24:06 +0100 | [diff] [blame] | 210 | |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 211 | if (flags & CLK_DIVIDER_POWER_OF_TWO) |
Maxime COQUELIN | dd23c2c | 2014-01-29 17:24:06 +0100 | [diff] [blame] | 212 | div = __roundup_pow_of_two(div); |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 213 | if (table) |
| 214 | div = _round_up_table(table, div); |
Maxime COQUELIN | dd23c2c | 2014-01-29 17:24:06 +0100 | [diff] [blame] | 215 | |
| 216 | return div; |
| 217 | } |
| 218 | |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 219 | static int _div_round_closest(const struct clk_div_table *table, |
| 220 | unsigned long parent_rate, unsigned long rate, |
| 221 | unsigned long flags) |
Maxime COQUELIN | 774b514 | 2014-01-29 17:24:07 +0100 | [diff] [blame] | 222 | { |
Uwe Kleine-König | 9315514 | 2015-02-21 11:40:25 +0100 | [diff] [blame] | 223 | int up, down; |
Uwe Kleine-König | 26bac95 | 2015-02-21 11:40:24 +0100 | [diff] [blame] | 224 | unsigned long up_rate, down_rate; |
Maxime COQUELIN | 774b514 | 2014-01-29 17:24:07 +0100 | [diff] [blame] | 225 | |
Brian Norris | 9556f9d | 2015-04-13 16:03:21 -0700 | [diff] [blame] | 226 | up = DIV_ROUND_UP_ULL((u64)parent_rate, rate); |
Uwe Kleine-König | 9315514 | 2015-02-21 11:40:25 +0100 | [diff] [blame] | 227 | down = parent_rate / rate; |
Maxime COQUELIN | 774b514 | 2014-01-29 17:24:07 +0100 | [diff] [blame] | 228 | |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 229 | if (flags & CLK_DIVIDER_POWER_OF_TWO) { |
Uwe Kleine-König | 9315514 | 2015-02-21 11:40:25 +0100 | [diff] [blame] | 230 | up = __roundup_pow_of_two(up); |
| 231 | down = __rounddown_pow_of_two(down); |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 232 | } else if (table) { |
Uwe Kleine-König | 9315514 | 2015-02-21 11:40:25 +0100 | [diff] [blame] | 233 | up = _round_up_table(table, up); |
| 234 | down = _round_down_table(table, down); |
Maxime COQUELIN | 774b514 | 2014-01-29 17:24:07 +0100 | [diff] [blame] | 235 | } |
| 236 | |
Brian Norris | 9556f9d | 2015-04-13 16:03:21 -0700 | [diff] [blame] | 237 | up_rate = DIV_ROUND_UP_ULL((u64)parent_rate, up); |
| 238 | down_rate = DIV_ROUND_UP_ULL((u64)parent_rate, down); |
Uwe Kleine-König | 26bac95 | 2015-02-21 11:40:24 +0100 | [diff] [blame] | 239 | |
| 240 | return (rate - up_rate) <= (down_rate - rate) ? up : down; |
Maxime COQUELIN | 774b514 | 2014-01-29 17:24:07 +0100 | [diff] [blame] | 241 | } |
| 242 | |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 243 | static int _div_round(const struct clk_div_table *table, |
| 244 | unsigned long parent_rate, unsigned long rate, |
| 245 | unsigned long flags) |
Maxime COQUELIN | 774b514 | 2014-01-29 17:24:07 +0100 | [diff] [blame] | 246 | { |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 247 | if (flags & CLK_DIVIDER_ROUND_CLOSEST) |
| 248 | return _div_round_closest(table, parent_rate, rate, flags); |
Maxime COQUELIN | 774b514 | 2014-01-29 17:24:07 +0100 | [diff] [blame] | 249 | |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 250 | return _div_round_up(table, parent_rate, rate, flags); |
Maxime COQUELIN | 774b514 | 2014-01-29 17:24:07 +0100 | [diff] [blame] | 251 | } |
| 252 | |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 253 | static bool _is_best_div(unsigned long rate, unsigned long now, |
| 254 | unsigned long best, unsigned long flags) |
Maxime COQUELIN | 774b514 | 2014-01-29 17:24:07 +0100 | [diff] [blame] | 255 | { |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 256 | if (flags & CLK_DIVIDER_ROUND_CLOSEST) |
Maxime COQUELIN | 774b514 | 2014-01-29 17:24:07 +0100 | [diff] [blame] | 257 | return abs(rate - now) < abs(rate - best); |
| 258 | |
| 259 | return now <= rate && now > best; |
| 260 | } |
| 261 | |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 262 | static int _next_div(const struct clk_div_table *table, int div, |
| 263 | unsigned long flags) |
Maxime COQUELIN | 0e2de78 | 2014-01-29 17:24:08 +0100 | [diff] [blame] | 264 | { |
| 265 | div++; |
| 266 | |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 267 | if (flags & CLK_DIVIDER_POWER_OF_TWO) |
Maxime COQUELIN | 0e2de78 | 2014-01-29 17:24:08 +0100 | [diff] [blame] | 268 | return __roundup_pow_of_two(div); |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 269 | if (table) |
| 270 | return _round_up_table(table, div); |
Maxime COQUELIN | 0e2de78 | 2014-01-29 17:24:08 +0100 | [diff] [blame] | 271 | |
| 272 | return div; |
| 273 | } |
| 274 | |
Maxime Ripard | 22833a9 | 2017-05-17 09:40:30 +0200 | [diff] [blame] | 275 | static int clk_divider_bestdiv(struct clk_hw *hw, struct clk_hw *parent, |
| 276 | unsigned long rate, |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 277 | unsigned long *best_parent_rate, |
| 278 | const struct clk_div_table *table, u8 width, |
| 279 | unsigned long flags) |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 280 | { |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 281 | int i, bestdiv = 0; |
| 282 | unsigned long parent_rate, best = 0, now, maxdiv; |
Shawn Guo | 081c902 | 2013-06-02 22:20:55 +0800 | [diff] [blame] | 283 | unsigned long parent_rate_saved = *best_parent_rate; |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 284 | |
| 285 | if (!rate) |
| 286 | rate = 1; |
| 287 | |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 288 | maxdiv = _get_maxdiv(table, width, flags); |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 289 | |
Stephen Boyd | 98d8a60 | 2015-06-29 16:56:30 -0700 | [diff] [blame] | 290 | if (!(clk_hw_get_flags(hw) & CLK_SET_RATE_PARENT)) { |
Shawn Guo | 81536e0 | 2012-04-12 20:50:17 +0800 | [diff] [blame] | 291 | parent_rate = *best_parent_rate; |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 292 | bestdiv = _div_round(table, parent_rate, rate, flags); |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 293 | bestdiv = bestdiv == 0 ? 1 : bestdiv; |
| 294 | bestdiv = bestdiv > maxdiv ? maxdiv : bestdiv; |
| 295 | return bestdiv; |
| 296 | } |
| 297 | |
| 298 | /* |
| 299 | * The maximum divider we can use without overflowing |
| 300 | * unsigned long in rate * i below |
| 301 | */ |
| 302 | maxdiv = min(ULONG_MAX / rate, maxdiv); |
| 303 | |
Masahiro Yamada | 653d145 | 2016-01-05 12:43:41 +0900 | [diff] [blame] | 304 | for (i = _next_div(table, 0, flags); i <= maxdiv; |
| 305 | i = _next_div(table, i, flags)) { |
Shawn Guo | 081c902 | 2013-06-02 22:20:55 +0800 | [diff] [blame] | 306 | if (rate * i == parent_rate_saved) { |
| 307 | /* |
| 308 | * It's the most ideal case if the requested rate can be |
| 309 | * divided from parent clock without needing to change |
| 310 | * parent rate, so return the divider immediately. |
| 311 | */ |
| 312 | *best_parent_rate = parent_rate_saved; |
| 313 | return i; |
| 314 | } |
Maxime Ripard | 22833a9 | 2017-05-17 09:40:30 +0200 | [diff] [blame] | 315 | parent_rate = clk_hw_round_rate(parent, rate * i); |
Brian Norris | 9556f9d | 2015-04-13 16:03:21 -0700 | [diff] [blame] | 316 | now = DIV_ROUND_UP_ULL((u64)parent_rate, i); |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 317 | if (_is_best_div(rate, now, best, flags)) { |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 318 | bestdiv = i; |
| 319 | best = now; |
| 320 | *best_parent_rate = parent_rate; |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | if (!bestdiv) { |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 325 | bestdiv = _get_maxdiv(table, width, flags); |
Maxime Ripard | 22833a9 | 2017-05-17 09:40:30 +0200 | [diff] [blame] | 326 | *best_parent_rate = clk_hw_round_rate(parent, 1); |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | return bestdiv; |
| 330 | } |
| 331 | |
Maxime Ripard | 22833a9 | 2017-05-17 09:40:30 +0200 | [diff] [blame] | 332 | long divider_round_rate_parent(struct clk_hw *hw, struct clk_hw *parent, |
| 333 | unsigned long rate, unsigned long *prate, |
| 334 | const struct clk_div_table *table, |
| 335 | u8 width, unsigned long flags) |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 336 | { |
| 337 | int div; |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 338 | |
Maxime Ripard | 22833a9 | 2017-05-17 09:40:30 +0200 | [diff] [blame] | 339 | div = clk_divider_bestdiv(hw, parent, rate, prate, table, width, flags); |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 340 | |
Brian Norris | 9556f9d | 2015-04-13 16:03:21 -0700 | [diff] [blame] | 341 | return DIV_ROUND_UP_ULL((u64)*prate, div); |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 342 | } |
Maxime Ripard | 22833a9 | 2017-05-17 09:40:30 +0200 | [diff] [blame] | 343 | EXPORT_SYMBOL_GPL(divider_round_rate_parent); |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 344 | |
Jerome Brunet | b15ee49 | 2018-02-14 14:43:39 +0100 | [diff] [blame^] | 345 | long divider_ro_round_rate_parent(struct clk_hw *hw, struct clk_hw *parent, |
| 346 | unsigned long rate, unsigned long *prate, |
| 347 | const struct clk_div_table *table, u8 width, |
| 348 | unsigned long flags, unsigned int val) |
| 349 | { |
| 350 | int div; |
| 351 | |
| 352 | div = _get_div(table, val, flags, width); |
| 353 | |
| 354 | /* Even a read-only clock can propagate a rate change */ |
| 355 | if (clk_hw_get_flags(hw) & CLK_SET_RATE_PARENT) { |
| 356 | if (!parent) |
| 357 | return -EINVAL; |
| 358 | |
| 359 | *prate = clk_hw_round_rate(parent, rate * div); |
| 360 | } |
| 361 | |
| 362 | return DIV_ROUND_UP_ULL((u64)*prate, div); |
| 363 | } |
| 364 | EXPORT_SYMBOL_GPL(divider_ro_round_rate_parent); |
| 365 | |
| 366 | |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 367 | static long clk_divider_round_rate(struct clk_hw *hw, unsigned long rate, |
| 368 | unsigned long *prate) |
| 369 | { |
| 370 | struct clk_divider *divider = to_clk_divider(hw); |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 371 | |
| 372 | /* if read only, just return current value */ |
| 373 | if (divider->flags & CLK_DIVIDER_READ_ONLY) { |
Jerome Brunet | b15ee49 | 2018-02-14 14:43:39 +0100 | [diff] [blame^] | 374 | u32 val; |
| 375 | |
| 376 | val = clk_readl(divider->reg) >> divider->shift; |
| 377 | val &= clk_div_mask(divider->width); |
| 378 | |
| 379 | return divider_ro_round_rate(hw, rate, prate, divider->table, |
| 380 | divider->width, divider->flags, |
| 381 | val); |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | return divider_round_rate(hw, rate, prate, divider->table, |
| 385 | divider->width, divider->flags); |
| 386 | } |
| 387 | |
| 388 | int divider_get_val(unsigned long rate, unsigned long parent_rate, |
| 389 | const struct clk_div_table *table, u8 width, |
| 390 | unsigned long flags) |
| 391 | { |
| 392 | unsigned int div, value; |
| 393 | |
Brian Norris | 9556f9d | 2015-04-13 16:03:21 -0700 | [diff] [blame] | 394 | div = DIV_ROUND_UP_ULL((u64)parent_rate, rate); |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 395 | |
| 396 | if (!_is_valid_div(table, div, flags)) |
| 397 | return -EINVAL; |
| 398 | |
Jim Quinlan | afe76c8f | 2015-05-15 15:45:47 -0400 | [diff] [blame] | 399 | value = _get_val(table, div, flags, width); |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 400 | |
Jerome Brunet | e6d3cc7 | 2018-02-14 14:43:33 +0100 | [diff] [blame] | 401 | return min_t(unsigned int, value, clk_div_mask(width)); |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 402 | } |
| 403 | EXPORT_SYMBOL_GPL(divider_get_val); |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 404 | |
Shawn Guo | 1c0035d | 2012-04-12 20:50:18 +0800 | [diff] [blame] | 405 | static int clk_divider_set_rate(struct clk_hw *hw, unsigned long rate, |
| 406 | unsigned long parent_rate) |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 407 | { |
| 408 | struct clk_divider *divider = to_clk_divider(hw); |
Alex Frid | 2316a7a | 2017-07-25 13:18:40 +0300 | [diff] [blame] | 409 | int value; |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 410 | unsigned long flags = 0; |
| 411 | u32 val; |
| 412 | |
Stephen Boyd | bca9690 | 2015-01-19 18:05:29 -0800 | [diff] [blame] | 413 | value = divider_get_val(rate, parent_rate, divider->table, |
| 414 | divider->width, divider->flags); |
Alex Frid | 2316a7a | 2017-07-25 13:18:40 +0300 | [diff] [blame] | 415 | if (value < 0) |
| 416 | return value; |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 417 | |
| 418 | if (divider->lock) |
| 419 | spin_lock_irqsave(divider->lock, flags); |
Stephen Boyd | 661e218 | 2015-07-24 12:21:12 -0700 | [diff] [blame] | 420 | else |
| 421 | __acquire(divider->lock); |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 422 | |
Haojian Zhuang | d57dfe7 | 2013-06-08 22:47:18 +0800 | [diff] [blame] | 423 | if (divider->flags & CLK_DIVIDER_HIWORD_MASK) { |
Jerome Brunet | e6d3cc7 | 2018-02-14 14:43:33 +0100 | [diff] [blame] | 424 | val = clk_div_mask(divider->width) << (divider->shift + 16); |
Haojian Zhuang | d57dfe7 | 2013-06-08 22:47:18 +0800 | [diff] [blame] | 425 | } else { |
Gerhard Sittig | aa514ce | 2013-07-22 14:14:40 +0200 | [diff] [blame] | 426 | val = clk_readl(divider->reg); |
Jerome Brunet | e6d3cc7 | 2018-02-14 14:43:33 +0100 | [diff] [blame] | 427 | val &= ~(clk_div_mask(divider->width) << divider->shift); |
Haojian Zhuang | d57dfe7 | 2013-06-08 22:47:18 +0800 | [diff] [blame] | 428 | } |
Alex Frid | 2316a7a | 2017-07-25 13:18:40 +0300 | [diff] [blame] | 429 | val |= (u32)value << divider->shift; |
Gerhard Sittig | aa514ce | 2013-07-22 14:14:40 +0200 | [diff] [blame] | 430 | clk_writel(val, divider->reg); |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 431 | |
| 432 | if (divider->lock) |
| 433 | spin_unlock_irqrestore(divider->lock, flags); |
Stephen Boyd | 661e218 | 2015-07-24 12:21:12 -0700 | [diff] [blame] | 434 | else |
| 435 | __release(divider->lock); |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 436 | |
| 437 | return 0; |
| 438 | } |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 439 | |
Shawn Guo | 822c250 | 2012-03-27 15:23:22 +0800 | [diff] [blame] | 440 | const struct clk_ops clk_divider_ops = { |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 441 | .recalc_rate = clk_divider_recalc_rate, |
| 442 | .round_rate = clk_divider_round_rate, |
| 443 | .set_rate = clk_divider_set_rate, |
| 444 | }; |
| 445 | EXPORT_SYMBOL_GPL(clk_divider_ops); |
| 446 | |
Heiko Stuebner | 5035981 | 2016-01-21 21:53:09 +0100 | [diff] [blame] | 447 | const struct clk_ops clk_divider_ro_ops = { |
| 448 | .recalc_rate = clk_divider_recalc_rate, |
| 449 | .round_rate = clk_divider_round_rate, |
| 450 | }; |
| 451 | EXPORT_SYMBOL_GPL(clk_divider_ro_ops); |
| 452 | |
Stephen Boyd | eb7d264 | 2016-02-06 23:26:37 -0800 | [diff] [blame] | 453 | static struct clk_hw *_register_divider(struct device *dev, const char *name, |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 454 | const char *parent_name, unsigned long flags, |
| 455 | void __iomem *reg, u8 shift, u8 width, |
Rajendra Nayak | 357c3f0 | 2012-06-29 19:06:32 +0530 | [diff] [blame] | 456 | u8 clk_divider_flags, const struct clk_div_table *table, |
| 457 | spinlock_t *lock) |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 458 | { |
| 459 | struct clk_divider *div; |
Stephen Boyd | eb7d264 | 2016-02-06 23:26:37 -0800 | [diff] [blame] | 460 | struct clk_hw *hw; |
Saravana Kannan | 0197b3e | 2012-04-25 22:58:56 -0700 | [diff] [blame] | 461 | struct clk_init_data init; |
Stephen Boyd | eb7d264 | 2016-02-06 23:26:37 -0800 | [diff] [blame] | 462 | int ret; |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 463 | |
Haojian Zhuang | d57dfe7 | 2013-06-08 22:47:18 +0800 | [diff] [blame] | 464 | if (clk_divider_flags & CLK_DIVIDER_HIWORD_MASK) { |
| 465 | if (width + shift > 16) { |
| 466 | pr_warn("divider value exceeds LOWORD field\n"); |
| 467 | return ERR_PTR(-EINVAL); |
| 468 | } |
| 469 | } |
| 470 | |
Mike Turquette | 27d5459 | 2012-03-26 17:51:03 -0700 | [diff] [blame] | 471 | /* allocate the divider */ |
Stephen Boyd | d122db7 | 2015-05-14 16:47:10 -0700 | [diff] [blame] | 472 | div = kzalloc(sizeof(*div), GFP_KERNEL); |
| 473 | if (!div) |
Mike Turquette | 27d5459 | 2012-03-26 17:51:03 -0700 | [diff] [blame] | 474 | return ERR_PTR(-ENOMEM); |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 475 | |
Saravana Kannan | 0197b3e | 2012-04-25 22:58:56 -0700 | [diff] [blame] | 476 | init.name = name; |
Heiko Stuebner | 5035981 | 2016-01-21 21:53:09 +0100 | [diff] [blame] | 477 | if (clk_divider_flags & CLK_DIVIDER_READ_ONLY) |
| 478 | init.ops = &clk_divider_ro_ops; |
| 479 | else |
| 480 | init.ops = &clk_divider_ops; |
Rajendra Nayak | f7d8caa | 2012-06-01 14:02:47 +0530 | [diff] [blame] | 481 | init.flags = flags | CLK_IS_BASIC; |
Saravana Kannan | 0197b3e | 2012-04-25 22:58:56 -0700 | [diff] [blame] | 482 | init.parent_names = (parent_name ? &parent_name: NULL); |
| 483 | init.num_parents = (parent_name ? 1 : 0); |
| 484 | |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 485 | /* struct clk_divider assignments */ |
| 486 | div->reg = reg; |
| 487 | div->shift = shift; |
| 488 | div->width = width; |
| 489 | div->flags = clk_divider_flags; |
| 490 | div->lock = lock; |
Saravana Kannan | 0197b3e | 2012-04-25 22:58:56 -0700 | [diff] [blame] | 491 | div->hw.init = &init; |
Rajendra Nayak | 357c3f0 | 2012-06-29 19:06:32 +0530 | [diff] [blame] | 492 | div->table = table; |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 493 | |
Mike Turquette | 27d5459 | 2012-03-26 17:51:03 -0700 | [diff] [blame] | 494 | /* register the clock */ |
Stephen Boyd | eb7d264 | 2016-02-06 23:26:37 -0800 | [diff] [blame] | 495 | hw = &div->hw; |
| 496 | ret = clk_hw_register(dev, hw); |
| 497 | if (ret) { |
Mike Turquette | 27d5459 | 2012-03-26 17:51:03 -0700 | [diff] [blame] | 498 | kfree(div); |
Stephen Boyd | eb7d264 | 2016-02-06 23:26:37 -0800 | [diff] [blame] | 499 | hw = ERR_PTR(ret); |
| 500 | } |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 501 | |
Stephen Boyd | eb7d264 | 2016-02-06 23:26:37 -0800 | [diff] [blame] | 502 | return hw; |
Mike Turquette | 9d9f78e | 2012-03-15 23:11:20 -0700 | [diff] [blame] | 503 | } |
Rajendra Nayak | 357c3f0 | 2012-06-29 19:06:32 +0530 | [diff] [blame] | 504 | |
| 505 | /** |
| 506 | * clk_register_divider - register a divider clock with the clock framework |
| 507 | * @dev: device registering this clock |
| 508 | * @name: name of this clock |
| 509 | * @parent_name: name of clock's parent |
| 510 | * @flags: framework-specific flags |
| 511 | * @reg: register address to adjust divider |
| 512 | * @shift: number of bits to shift the bitfield |
| 513 | * @width: width of the bitfield |
| 514 | * @clk_divider_flags: divider-specific flags for this clock |
| 515 | * @lock: shared register lock for this clock |
| 516 | */ |
| 517 | struct clk *clk_register_divider(struct device *dev, const char *name, |
| 518 | const char *parent_name, unsigned long flags, |
| 519 | void __iomem *reg, u8 shift, u8 width, |
| 520 | u8 clk_divider_flags, spinlock_t *lock) |
| 521 | { |
Stephen Boyd | eb7d264 | 2016-02-06 23:26:37 -0800 | [diff] [blame] | 522 | struct clk_hw *hw; |
| 523 | |
| 524 | hw = _register_divider(dev, name, parent_name, flags, reg, shift, |
| 525 | width, clk_divider_flags, NULL, lock); |
| 526 | if (IS_ERR(hw)) |
| 527 | return ERR_CAST(hw); |
| 528 | return hw->clk; |
| 529 | } |
| 530 | EXPORT_SYMBOL_GPL(clk_register_divider); |
| 531 | |
| 532 | /** |
| 533 | * clk_hw_register_divider - register a divider clock with the clock framework |
| 534 | * @dev: device registering this clock |
| 535 | * @name: name of this clock |
| 536 | * @parent_name: name of clock's parent |
| 537 | * @flags: framework-specific flags |
| 538 | * @reg: register address to adjust divider |
| 539 | * @shift: number of bits to shift the bitfield |
| 540 | * @width: width of the bitfield |
| 541 | * @clk_divider_flags: divider-specific flags for this clock |
| 542 | * @lock: shared register lock for this clock |
| 543 | */ |
| 544 | struct clk_hw *clk_hw_register_divider(struct device *dev, const char *name, |
| 545 | const char *parent_name, unsigned long flags, |
| 546 | void __iomem *reg, u8 shift, u8 width, |
| 547 | u8 clk_divider_flags, spinlock_t *lock) |
| 548 | { |
Rajendra Nayak | 357c3f0 | 2012-06-29 19:06:32 +0530 | [diff] [blame] | 549 | return _register_divider(dev, name, parent_name, flags, reg, shift, |
| 550 | width, clk_divider_flags, NULL, lock); |
| 551 | } |
Stephen Boyd | eb7d264 | 2016-02-06 23:26:37 -0800 | [diff] [blame] | 552 | EXPORT_SYMBOL_GPL(clk_hw_register_divider); |
Rajendra Nayak | 357c3f0 | 2012-06-29 19:06:32 +0530 | [diff] [blame] | 553 | |
| 554 | /** |
| 555 | * clk_register_divider_table - register a table based divider clock with |
| 556 | * the clock framework |
| 557 | * @dev: device registering this clock |
| 558 | * @name: name of this clock |
| 559 | * @parent_name: name of clock's parent |
| 560 | * @flags: framework-specific flags |
| 561 | * @reg: register address to adjust divider |
| 562 | * @shift: number of bits to shift the bitfield |
| 563 | * @width: width of the bitfield |
| 564 | * @clk_divider_flags: divider-specific flags for this clock |
| 565 | * @table: array of divider/value pairs ending with a div set to 0 |
| 566 | * @lock: shared register lock for this clock |
| 567 | */ |
| 568 | struct clk *clk_register_divider_table(struct device *dev, const char *name, |
| 569 | const char *parent_name, unsigned long flags, |
| 570 | void __iomem *reg, u8 shift, u8 width, |
| 571 | u8 clk_divider_flags, const struct clk_div_table *table, |
| 572 | spinlock_t *lock) |
| 573 | { |
Stephen Boyd | eb7d264 | 2016-02-06 23:26:37 -0800 | [diff] [blame] | 574 | struct clk_hw *hw; |
| 575 | |
| 576 | hw = _register_divider(dev, name, parent_name, flags, reg, shift, |
| 577 | width, clk_divider_flags, table, lock); |
| 578 | if (IS_ERR(hw)) |
| 579 | return ERR_CAST(hw); |
| 580 | return hw->clk; |
| 581 | } |
| 582 | EXPORT_SYMBOL_GPL(clk_register_divider_table); |
| 583 | |
| 584 | /** |
| 585 | * clk_hw_register_divider_table - register a table based divider clock with |
| 586 | * the clock framework |
| 587 | * @dev: device registering this clock |
| 588 | * @name: name of this clock |
| 589 | * @parent_name: name of clock's parent |
| 590 | * @flags: framework-specific flags |
| 591 | * @reg: register address to adjust divider |
| 592 | * @shift: number of bits to shift the bitfield |
| 593 | * @width: width of the bitfield |
| 594 | * @clk_divider_flags: divider-specific flags for this clock |
| 595 | * @table: array of divider/value pairs ending with a div set to 0 |
| 596 | * @lock: shared register lock for this clock |
| 597 | */ |
| 598 | struct clk_hw *clk_hw_register_divider_table(struct device *dev, |
| 599 | const char *name, const char *parent_name, unsigned long flags, |
| 600 | void __iomem *reg, u8 shift, u8 width, |
| 601 | u8 clk_divider_flags, const struct clk_div_table *table, |
| 602 | spinlock_t *lock) |
| 603 | { |
Rajendra Nayak | 357c3f0 | 2012-06-29 19:06:32 +0530 | [diff] [blame] | 604 | return _register_divider(dev, name, parent_name, flags, reg, shift, |
| 605 | width, clk_divider_flags, table, lock); |
| 606 | } |
Stephen Boyd | eb7d264 | 2016-02-06 23:26:37 -0800 | [diff] [blame] | 607 | EXPORT_SYMBOL_GPL(clk_hw_register_divider_table); |
Krzysztof Kozlowski | 4e3c021 | 2015-01-05 10:52:40 +0100 | [diff] [blame] | 608 | |
| 609 | void clk_unregister_divider(struct clk *clk) |
| 610 | { |
| 611 | struct clk_divider *div; |
| 612 | struct clk_hw *hw; |
| 613 | |
| 614 | hw = __clk_get_hw(clk); |
| 615 | if (!hw) |
| 616 | return; |
| 617 | |
| 618 | div = to_clk_divider(hw); |
| 619 | |
| 620 | clk_unregister(clk); |
| 621 | kfree(div); |
| 622 | } |
| 623 | EXPORT_SYMBOL_GPL(clk_unregister_divider); |
Stephen Boyd | eb7d264 | 2016-02-06 23:26:37 -0800 | [diff] [blame] | 624 | |
| 625 | /** |
| 626 | * clk_hw_unregister_divider - unregister a clk divider |
| 627 | * @hw: hardware-specific clock data to unregister |
| 628 | */ |
| 629 | void clk_hw_unregister_divider(struct clk_hw *hw) |
| 630 | { |
| 631 | struct clk_divider *div; |
| 632 | |
| 633 | div = to_clk_divider(hw); |
| 634 | |
| 635 | clk_hw_unregister(hw); |
| 636 | kfree(div); |
| 637 | } |
| 638 | EXPORT_SYMBOL_GPL(clk_hw_unregister_divider); |