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

sh: clkfwk: Consolidate div clk registration helper.

This consolidates the div6/4 versions of the clk registration wrapper.
The existing wrappers with their own sh_clk_ops are maintained for API
compatability, though in the future it should be possible to be rid of
them entirely.

Signed-off-by: Paul Mundt <lethal@linux-sh.org>

+75 -107
+75 -107
drivers/sh/clk/cpg.c
··· 162 162 .disable = sh_clk_div_disable, 163 163 }; 164 164 165 + static int __init sh_clk_init_parent(struct clk *clk) 166 + { 167 + u32 val; 168 + 169 + if (clk->parent) 170 + return 0; 171 + 172 + if (!clk->parent_table || !clk->parent_num) 173 + return 0; 174 + 175 + if (!clk->src_width) { 176 + pr_err("sh_clk_init_parent: cannot select parent clock\n"); 177 + return -EINVAL; 178 + } 179 + 180 + val = (sh_clk_read(clk) >> clk->src_shift); 181 + val &= (1 << clk->src_width) - 1; 182 + 183 + if (val >= clk->parent_num) { 184 + pr_err("sh_clk_init_parent: parent table size failed\n"); 185 + return -EINVAL; 186 + } 187 + 188 + clk_reparent(clk, clk->parent_table[val]); 189 + if (!clk->parent) { 190 + pr_err("sh_clk_init_parent: unable to set parent"); 191 + return -EINVAL; 192 + } 193 + 194 + return 0; 195 + } 196 + 197 + static int __init sh_clk_div_register_ops(struct clk *clks, int nr, 198 + struct clk_div_table *table, struct sh_clk_ops *ops) 199 + { 200 + struct clk *clkp; 201 + void *freq_table; 202 + int nr_divs = table->div_mult_table->nr_divisors; 203 + int freq_table_size = sizeof(struct cpufreq_frequency_table); 204 + int ret = 0; 205 + int k; 206 + 207 + freq_table_size *= (nr_divs + 1); 208 + freq_table = kzalloc(freq_table_size * nr, GFP_KERNEL); 209 + if (!freq_table) { 210 + pr_err("%s: unable to alloc memory\n", __func__); 211 + return -ENOMEM; 212 + } 213 + 214 + for (k = 0; !ret && (k < nr); k++) { 215 + clkp = clks + k; 216 + 217 + clkp->ops = ops; 218 + clkp->priv = table; 219 + 220 + clkp->freq_table = freq_table + (k * freq_table_size); 221 + clkp->freq_table[nr_divs].frequency = CPUFREQ_TABLE_END; 222 + 223 + ret = clk_register(clkp); 224 + if (ret == 0) 225 + ret = sh_clk_init_parent(clkp); 226 + } 227 + 228 + return ret; 229 + } 230 + 165 231 /* 166 232 * div6 support 167 233 */ ··· 289 223 .set_parent = sh_clk_div6_set_parent, 290 224 }; 291 225 292 - static int __init sh_clk_init_parent(struct clk *clk) 293 - { 294 - u32 val; 295 - 296 - if (clk->parent) 297 - return 0; 298 - 299 - if (!clk->parent_table || !clk->parent_num) 300 - return 0; 301 - 302 - if (!clk->src_width) { 303 - pr_err("sh_clk_init_parent: cannot select parent clock\n"); 304 - return -EINVAL; 305 - } 306 - 307 - val = (sh_clk_read(clk) >> clk->src_shift); 308 - val &= (1 << clk->src_width) - 1; 309 - 310 - if (val >= clk->parent_num) { 311 - pr_err("sh_clk_init_parent: parent table size failed\n"); 312 - return -EINVAL; 313 - } 314 - 315 - clk_reparent(clk, clk->parent_table[val]); 316 - if (!clk->parent) { 317 - pr_err("sh_clk_init_parent: unable to set parent"); 318 - return -EINVAL; 319 - } 320 - 321 - return 0; 322 - } 323 - 324 - static int __init sh_clk_div6_register_ops(struct clk *clks, int nr, 325 - struct sh_clk_ops *ops) 326 - { 327 - struct clk *clkp; 328 - void *freq_table; 329 - struct clk_div_table *table = &sh_clk_div6_table; 330 - int nr_divs = table->div_mult_table->nr_divisors; 331 - int freq_table_size = sizeof(struct cpufreq_frequency_table); 332 - int ret = 0; 333 - int k; 334 - 335 - freq_table_size *= (nr_divs + 1); 336 - freq_table = kzalloc(freq_table_size * nr, GFP_KERNEL); 337 - if (!freq_table) { 338 - pr_err("sh_clk_div6_register: unable to alloc memory\n"); 339 - return -ENOMEM; 340 - } 341 - 342 - for (k = 0; !ret && (k < nr); k++) { 343 - clkp = clks + k; 344 - 345 - clkp->ops = ops; 346 - clkp->priv = table; 347 - clkp->freq_table = freq_table + (k * freq_table_size); 348 - clkp->freq_table[nr_divs].frequency = CPUFREQ_TABLE_END; 349 - ret = clk_register(clkp); 350 - if (ret < 0) 351 - break; 352 - 353 - ret = sh_clk_init_parent(clkp); 354 - } 355 - 356 - return ret; 357 - } 358 - 359 226 int __init sh_clk_div6_register(struct clk *clks, int nr) 360 227 { 361 - return sh_clk_div6_register_ops(clks, nr, &sh_clk_div_enable_clk_ops); 228 + return sh_clk_div_register_ops(clks, nr, &sh_clk_div6_table, 229 + &sh_clk_div_enable_clk_ops); 362 230 } 363 231 364 232 int __init sh_clk_div6_reparent_register(struct clk *clks, int nr) 365 233 { 366 - return sh_clk_div6_register_ops(clks, nr, 367 - &sh_clk_div6_reparent_clk_ops); 234 + return sh_clk_div_register_ops(clks, nr, &sh_clk_div6_table, 235 + &sh_clk_div6_reparent_clk_ops); 368 236 } 369 237 370 238 /* ··· 342 342 .set_parent = sh_clk_div4_set_parent, 343 343 }; 344 344 345 - static int __init sh_clk_div4_register_ops(struct clk *clks, int nr, 346 - struct clk_div4_table *table, struct sh_clk_ops *ops) 347 - { 348 - struct clk *clkp; 349 - void *freq_table; 350 - int nr_divs = table->div_mult_table->nr_divisors; 351 - int freq_table_size = sizeof(struct cpufreq_frequency_table); 352 - int ret = 0; 353 - int k; 354 - 355 - freq_table_size *= (nr_divs + 1); 356 - freq_table = kzalloc(freq_table_size * nr, GFP_KERNEL); 357 - if (!freq_table) { 358 - pr_err("sh_clk_div4_register: unable to alloc memory\n"); 359 - return -ENOMEM; 360 - } 361 - 362 - for (k = 0; !ret && (k < nr); k++) { 363 - clkp = clks + k; 364 - 365 - clkp->ops = ops; 366 - clkp->priv = table; 367 - 368 - clkp->freq_table = freq_table + (k * freq_table_size); 369 - clkp->freq_table[nr_divs].frequency = CPUFREQ_TABLE_END; 370 - 371 - ret = clk_register(clkp); 372 - } 373 - 374 - return ret; 375 - } 376 - 377 345 int __init sh_clk_div4_register(struct clk *clks, int nr, 378 346 struct clk_div4_table *table) 379 347 { 380 - return sh_clk_div4_register_ops(clks, nr, table, &sh_clk_div_clk_ops); 348 + return sh_clk_div_register_ops(clks, nr, table, &sh_clk_div_clk_ops); 381 349 } 382 350 383 351 int __init sh_clk_div4_enable_register(struct clk *clks, int nr, 384 352 struct clk_div4_table *table) 385 353 { 386 - return sh_clk_div4_register_ops(clks, nr, table, 387 - &sh_clk_div_enable_clk_ops); 354 + return sh_clk_div_register_ops(clks, nr, table, 355 + &sh_clk_div_enable_clk_ops); 388 356 } 389 357 390 358 int __init sh_clk_div4_reparent_register(struct clk *clks, int nr, 391 359 struct clk_div4_table *table) 392 360 { 393 - return sh_clk_div4_register_ops(clks, nr, table, 394 - &sh_clk_div4_reparent_clk_ops); 361 + return sh_clk_div_register_ops(clks, nr, table, 362 + &sh_clk_div4_reparent_clk_ops); 395 363 }