Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

clk: ti: dpll: convert from round_rate() to determine_rate()

The round_rate() clk ops is deprecated, so migrate this driver from
round_rate() to determine_rate(). Part of these changes were done
using the Coccinelle semantic patch on the cover letter of this
series, and the rest of the changes were manually done.

omap4_dpll_regm4xen_round_rate() is now only called by
omap4_dpll_regm4xen_determine_rate(), so let's merge that functionality
into one function. This is needed for another cleanup to completely
remove the round_rate() clk ops from the clk core.

Tested-by: Anddreas Kemnade <andreas@kemnade.info> # OMAP3 GTA04, OMAP4 Panda
Reviewed-by: Kevin Hilman <khilman@baylibre.com>
Tested-by: Kevin Hilman <khilman@baylibre.com>
Signed-off-by: Brian Masney <bmasney@redhat.com>

+57 -85
+14 -14
drivers/clk/ti/clkt_dpll.c
··· 268 268 /* DPLL rate rounding code */ 269 269 270 270 /** 271 - * omap2_dpll_round_rate - round a target rate for an OMAP DPLL 271 + * omap2_dpll_determine_rate - round a target rate for an OMAP DPLL 272 272 * @hw: struct clk_hw containing the struct clk * for a DPLL 273 - * @target_rate: desired DPLL clock rate 274 - * @parent_rate: parent's DPLL clock rate 273 + * @req: rate request 275 274 * 276 275 * Given a DPLL and a desired target rate, round the target rate to a 277 276 * possible, programmable rate for this DPLL. Attempts to select the ··· 279 280 * (expensive) function again. Returns -EINVAL if the target rate 280 281 * cannot be rounded, or the rounded rate upon success. 281 282 */ 282 - long omap2_dpll_round_rate(struct clk_hw *hw, unsigned long target_rate, 283 - unsigned long *parent_rate) 283 + int omap2_dpll_determine_rate(struct clk_hw *hw, struct clk_rate_request *req) 284 284 { 285 285 struct clk_hw_omap *clk = to_clk_hw_omap(hw); 286 286 int m, n, r, scaled_max_m; ··· 297 299 298 300 dd = clk->dpll_data; 299 301 300 - if (dd->max_rate && target_rate > dd->max_rate) 301 - target_rate = dd->max_rate; 302 + if (dd->max_rate && req->rate > dd->max_rate) 303 + req->rate = dd->max_rate; 302 304 303 305 ref_rate = clk_hw_get_rate(dd->clk_ref); 304 306 clk_name = clk_hw_get_name(hw); 305 307 pr_debug("clock: %s: starting DPLL round_rate, target rate %lu\n", 306 - clk_name, target_rate); 308 + clk_name, req->rate); 307 309 308 - scaled_rt_rp = target_rate / (ref_rate / DPLL_SCALE_FACTOR); 310 + scaled_rt_rp = req->rate / (ref_rate / DPLL_SCALE_FACTOR); 309 311 scaled_max_m = dd->max_multiplier * DPLL_SCALE_FACTOR; 310 312 311 313 dd->last_rounded_rate = 0; ··· 330 332 if (m > scaled_max_m) 331 333 break; 332 334 333 - r = _dpll_test_mult(&m, n, &new_rate, target_rate, 335 + r = _dpll_test_mult(&m, n, &new_rate, req->rate, 334 336 ref_rate); 335 337 336 338 /* m can't be set low enough for this n - try with a larger n */ ··· 338 340 continue; 339 341 340 342 /* skip rates above our target rate */ 341 - delta = target_rate - new_rate; 343 + delta = req->rate - new_rate; 342 344 if (delta < 0) 343 345 continue; 344 346 ··· 357 359 358 360 if (prev_min_delta == LONG_MAX) { 359 361 pr_debug("clock: %s: cannot round to rate %lu\n", 360 - clk_name, target_rate); 362 + clk_name, req->rate); 361 363 return -EINVAL; 362 364 } 363 365 364 366 dd->last_rounded_m = min_delta_m; 365 367 dd->last_rounded_n = min_delta_n; 366 - dd->last_rounded_rate = target_rate - prev_min_delta; 368 + dd->last_rounded_rate = req->rate - prev_min_delta; 367 369 368 - return dd->last_rounded_rate; 370 + req->rate = dd->last_rounded_rate; 371 + 372 + return 0; 369 373 }
+1 -5
drivers/clk/ti/clock.h
··· 273 273 u8 index); 274 274 int omap3_noncore_dpll_determine_rate(struct clk_hw *hw, 275 275 struct clk_rate_request *req); 276 - long omap2_dpll_round_rate(struct clk_hw *hw, unsigned long target_rate, 277 - unsigned long *parent_rate); 276 + int omap2_dpll_determine_rate(struct clk_hw *hw, struct clk_rate_request *req); 278 277 unsigned long omap3_clkoutx2_recalc(struct clk_hw *hw, 279 278 unsigned long parent_rate); 280 279 ··· 295 296 296 297 unsigned long omap4_dpll_regm4xen_recalc(struct clk_hw *hw, 297 298 unsigned long parent_rate); 298 - long omap4_dpll_regm4xen_round_rate(struct clk_hw *hw, 299 - unsigned long target_rate, 300 - unsigned long *parent_rate); 301 299 int omap4_dpll_regm4xen_determine_rate(struct clk_hw *hw, 302 300 struct clk_rate_request *req); 303 301 int omap2_clk_for_each(int (*fn)(struct clk_hw_omap *hw));
+2 -2
drivers/clk/ti/dpll.c
··· 77 77 static const struct clk_ops omap2_dpll_core_ck_ops = { 78 78 .get_parent = &omap2_init_dpll_parent, 79 79 .recalc_rate = &omap2_dpllcore_recalc, 80 - .round_rate = &omap2_dpll_round_rate, 80 + .determine_rate = &omap2_dpll_determine_rate, 81 81 .set_rate = &omap2_reprogram_dpllcore, 82 82 }; 83 83 #else ··· 88 88 static const struct clk_ops omap3_dpll_core_ck_ops = { 89 89 .get_parent = &omap2_init_dpll_parent, 90 90 .recalc_rate = &omap3_dpll_recalc, 91 - .round_rate = &omap2_dpll_round_rate, 91 + .determine_rate = &omap2_dpll_determine_rate, 92 92 }; 93 93 94 94 static const struct clk_ops omap3_dpll_ck_ops = {
+5 -2
drivers/clk/ti/dpll3xxx.c
··· 587 587 { 588 588 struct clk_hw_omap *clk = to_clk_hw_omap(hw); 589 589 struct dpll_data *dd; 590 + int ret; 590 591 591 592 if (!req->rate) 592 593 return -EINVAL; ··· 600 599 (dd->modes & (1 << DPLL_LOW_POWER_BYPASS))) { 601 600 req->best_parent_hw = dd->clk_bypass; 602 601 } else { 603 - req->rate = omap2_dpll_round_rate(hw, req->rate, 604 - &req->best_parent_rate); 602 + ret = omap2_dpll_determine_rate(hw, req); 603 + if (ret != 0) 604 + return ret; 605 + 605 606 req->best_parent_hw = dd->clk_ref; 606 607 } 607 608
+31 -58
drivers/clk/ti/dpll44xx.c
··· 134 134 } 135 135 136 136 /** 137 - * omap4_dpll_regm4xen_round_rate - round DPLL rate, considering REGM4XEN bit 138 - * @hw: struct hw_clk containing the struct clk * of the DPLL to round a rate for 139 - * @target_rate: the desired rate of the DPLL 140 - * @parent_rate: clock rate of the DPLL parent 141 - * 142 - * Compute the rate that would be programmed into the DPLL hardware 143 - * for @clk if set_rate() were to be provided with the rate 144 - * @target_rate. Takes the REGM4XEN bit into consideration, which is 145 - * needed for the OMAP4 ABE DPLL. Returns the rounded rate (before 146 - * M-dividers) upon success, -EINVAL if @clk is null or not a DPLL, or 147 - * ~0 if an error occurred in omap2_dpll_round_rate(). 148 - */ 149 - long omap4_dpll_regm4xen_round_rate(struct clk_hw *hw, 150 - unsigned long target_rate, 151 - unsigned long *parent_rate) 152 - { 153 - struct clk_hw_omap *clk = to_clk_hw_omap(hw); 154 - struct dpll_data *dd; 155 - long r; 156 - 157 - if (!clk || !clk->dpll_data) 158 - return -EINVAL; 159 - 160 - dd = clk->dpll_data; 161 - 162 - dd->last_rounded_m4xen = 0; 163 - 164 - /* 165 - * First try to compute the DPLL configuration for 166 - * target rate without using the 4X multiplier. 167 - */ 168 - r = omap2_dpll_round_rate(hw, target_rate, NULL); 169 - if (r != ~0) 170 - goto out; 171 - 172 - /* 173 - * If we did not find a valid DPLL configuration, try again, but 174 - * this time see if using the 4X multiplier can help. Enabling the 175 - * 4X multiplier is equivalent to dividing the target rate by 4. 176 - */ 177 - r = omap2_dpll_round_rate(hw, target_rate / OMAP4430_REGM4XEN_MULT, 178 - NULL); 179 - if (r == ~0) 180 - return r; 181 - 182 - dd->last_rounded_rate *= OMAP4430_REGM4XEN_MULT; 183 - dd->last_rounded_m4xen = 1; 184 - 185 - out: 186 - omap4_dpll_lpmode_recalc(dd); 187 - 188 - return dd->last_rounded_rate; 189 - } 190 - 191 - /** 192 137 * omap4_dpll_regm4xen_determine_rate - determine rate for a DPLL 193 138 * @hw: pointer to the clock to determine rate for 194 139 * @req: target rate request 195 140 * 196 141 * Determines which DPLL mode to use for reaching a desired rate. 197 142 * Checks whether the DPLL shall be in bypass or locked mode, and if 198 - * locked, calculates the M,N values for the DPLL via round-rate. 143 + * locked, calculates the M,N values for the DPLL. 199 144 * Returns 0 on success and a negative error value otherwise. 200 145 */ 201 146 int omap4_dpll_regm4xen_determine_rate(struct clk_hw *hw, ··· 160 215 (dd->modes & (1 << DPLL_LOW_POWER_BYPASS))) { 161 216 req->best_parent_hw = dd->clk_bypass; 162 217 } else { 163 - req->rate = omap4_dpll_regm4xen_round_rate(hw, req->rate, 164 - &req->best_parent_rate); 218 + struct clk_rate_request tmp_req; 219 + long r; 220 + 221 + clk_hw_init_rate_request(hw, &tmp_req, req->rate); 222 + dd->last_rounded_m4xen = 0; 223 + 224 + /* 225 + * First try to compute the DPLL configuration for 226 + * target rate without using the 4X multiplier. 227 + */ 228 + 229 + r = omap2_dpll_determine_rate(hw, &tmp_req); 230 + if (r < 0) { 231 + /* 232 + * If we did not find a valid DPLL configuration, try again, but 233 + * this time see if using the 4X multiplier can help. Enabling the 234 + * 4X multiplier is equivalent to dividing the target rate by 4. 235 + */ 236 + tmp_req.rate /= OMAP4430_REGM4XEN_MULT; 237 + r = omap2_dpll_determine_rate(hw, &tmp_req); 238 + if (r < 0) 239 + return r; 240 + 241 + dd->last_rounded_rate *= OMAP4430_REGM4XEN_MULT; 242 + dd->last_rounded_m4xen = 1; 243 + } 244 + 245 + omap4_dpll_lpmode_recalc(dd); 246 + 247 + req->rate = dd->last_rounded_rate; 165 248 req->best_parent_hw = dd->clk_ref; 166 249 } 167 250
+4 -4
include/linux/clk/ti.h
··· 34 34 * @clk_ref: struct clk_hw pointer to the clock's reference clock input 35 35 * @control_reg: register containing the DPLL mode bitfield 36 36 * @enable_mask: mask of the DPLL mode bitfield in @control_reg 37 - * @last_rounded_rate: cache of the last rate result of omap2_dpll_round_rate() 38 - * @last_rounded_m: cache of the last M result of omap2_dpll_round_rate() 37 + * @last_rounded_rate: cache of the last rate result of omap2_dpll_determine_rate() 38 + * @last_rounded_m: cache of the last M result of omap2_dpll_determine_rate() 39 39 * @last_rounded_m4xen: cache of the last M4X result of 40 - * omap4_dpll_regm4xen_round_rate() 40 + * omap4_dpll_regm4xen_determine_rate() 41 41 * @last_rounded_lpmode: cache of the last lpmode result of 42 42 * omap4_dpll_lpmode_recalc() 43 43 * @max_multiplier: maximum valid non-bypass multiplier value (actual) 44 - * @last_rounded_n: cache of the last N result of omap2_dpll_round_rate() 44 + * @last_rounded_n: cache of the last N result of omap2_dpll_determine_rate() 45 45 * @min_divider: minimum valid non-bypass divider value (actual) 46 46 * @max_divider: maximum valid non-bypass divider value (actual) 47 47 * @max_rate: maximum clock rate for the DPLL