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

clk: davinci: pll: allow dev == NULL

This modifies the TI Davinci PLL clock driver to allow for the case
when dev == NULL. On some (most) SoCs that use this driver, the PLL
clock needs to be registered during early boot because it is used
for clocksource/clkevent and there will be no platform device available.

Signed-off-by: David Lechner <david@lechnology.com>
Reviewed-by: Sekhar Nori <nsekhar@ti.com>
Signed-off-by: Michael Turquette <mturquette@baylibre.com>
Link: lkml.kernel.org/r/20180525181150.17873-7-david@lechnology.com

authored by

David Lechner and committed by
Michael Turquette
76c9dd9d 9c39fc1f

+259 -137
+3 -2
drivers/clk/davinci/pll-da830.c
··· 6 6 */ 7 7 8 8 #include <linux/clkdev.h> 9 + #include <linux/clk/davinci.h> 9 10 #include <linux/bitops.h> 10 11 #include <linux/init.h> 11 12 #include <linux/types.h> ··· 37 36 SYSCLK(6, pll0_sysclk6, pll0_pllen, 5, SYSCLK_FIXED_DIV); 38 37 SYSCLK(7, pll0_sysclk7, pll0_pllen, 5, 0); 39 38 40 - int da830_pll_init(struct device *dev, void __iomem *base) 39 + int da830_pll_init(struct device *dev, void __iomem *base, struct regmap *cfgchip) 41 40 { 42 41 struct clk *clk; 43 42 44 - davinci_pll_clk_register(dev, &da830_pll_info, "ref_clk", base); 43 + davinci_pll_clk_register(dev, &da830_pll_info, "ref_clk", base, cfgchip); 45 44 46 45 clk = davinci_pll_sysclk_register(dev, &pll0_sysclk2, base); 47 46 clk_register_clkdev(clk, "pll0_sysclk2", "da830-psc0");
+12 -10
drivers/clk/davinci/pll-da850.c
··· 7 7 8 8 #include <linux/bitops.h> 9 9 #include <linux/clk-provider.h> 10 + #include <linux/clk/davinci.h> 10 11 #include <linux/clkdev.h> 12 + #include <linux/device.h> 11 13 #include <linux/init.h> 12 14 #include <linux/kernel.h> 13 15 #include <linux/mfd/da8xx-cfgchip.h> ··· 83 81 .ocsrc_mask = GENMASK(4, 0), 84 82 }; 85 83 86 - int da850_pll0_init(struct device *dev, void __iomem *base) 84 + int da850_pll0_init(struct device *dev, void __iomem *base, struct regmap *cfgchip) 87 85 { 88 86 struct clk *clk; 89 87 90 - davinci_pll_clk_register(dev, &da850_pll0_info, "ref_clk", base); 88 + davinci_pll_clk_register(dev, &da850_pll0_info, "ref_clk", base, cfgchip); 91 89 92 90 clk = davinci_pll_sysclk_register(dev, &pll0_sysclk1, base); 93 91 clk_register_clkdev(clk, "pll0_sysclk1", "da850-psc0"); ··· 136 134 NULL 137 135 }; 138 136 139 - int of_da850_pll0_init(struct device *dev, void __iomem *base) 137 + int of_da850_pll0_init(struct device *dev, void __iomem *base, struct regmap *cfgchip) 140 138 { 141 - return of_davinci_pll_init(dev, &da850_pll0_info, 139 + return of_davinci_pll_init(dev, dev->of_node, &da850_pll0_info, 142 140 &da850_pll0_obsclk_info, 143 - da850_pll0_sysclk_info, 7, base); 141 + da850_pll0_sysclk_info, 7, base, cfgchip); 144 142 } 145 143 146 144 static const struct davinci_pll_clk_info da850_pll1_info = { ··· 181 179 .ocsrc_mask = GENMASK(4, 0), 182 180 }; 183 181 184 - int da850_pll1_init(struct device *dev, void __iomem *base) 182 + int da850_pll1_init(struct device *dev, void __iomem *base, struct regmap *cfgchip) 185 183 { 186 184 struct clk *clk; 187 185 188 - davinci_pll_clk_register(dev, &da850_pll1_info, "oscin", base); 186 + davinci_pll_clk_register(dev, &da850_pll1_info, "oscin", base, cfgchip); 189 187 190 188 davinci_pll_sysclk_register(dev, &pll1_sysclk1, base); 191 189 ··· 206 204 NULL 207 205 }; 208 206 209 - int of_da850_pll1_init(struct device *dev, void __iomem *base) 207 + int of_da850_pll1_init(struct device *dev, void __iomem *base, struct regmap *cfgchip) 210 208 { 211 - return of_davinci_pll_init(dev, &da850_pll1_info, 209 + return of_davinci_pll_init(dev, dev->of_node, &da850_pll1_info, 212 210 &da850_pll1_obsclk_info, 213 - da850_pll1_sysclk_info, 3, base); 211 + da850_pll1_sysclk_info, 3, base, cfgchip); 214 212 }
+5 -4
drivers/clk/davinci/pll-dm355.c
··· 6 6 */ 7 7 8 8 #include <linux/bitops.h> 9 + #include <linux/clk/davinci.h> 9 10 #include <linux/clkdev.h> 10 11 #include <linux/init.h> 11 12 #include <linux/types.h> ··· 28 27 SYSCLK(3, pll1_sysclk3, pll1_pllen, 5, SYSCLK_ALWAYS_ENABLED); 29 28 SYSCLK(4, pll1_sysclk4, pll1_pllen, 5, SYSCLK_ALWAYS_ENABLED); 30 29 31 - int dm355_pll1_init(struct device *dev, void __iomem *base) 30 + int dm355_pll1_init(struct device *dev, void __iomem *base, struct regmap *cfgchip) 32 31 { 33 32 struct clk *clk; 34 33 35 - davinci_pll_clk_register(dev, &dm355_pll1_info, "ref_clk", base); 34 + davinci_pll_clk_register(dev, &dm355_pll1_info, "ref_clk", base, cfgchip); 36 35 37 36 clk = davinci_pll_sysclk_register(dev, &pll1_sysclk1, base); 38 37 clk_register_clkdev(clk, "pll1_sysclk1", "dm355-psc"); ··· 65 64 66 65 SYSCLK(1, pll2_sysclk1, pll2_pllen, 5, SYSCLK_FIXED_DIV | SYSCLK_ALWAYS_ENABLED); 67 66 68 - int dm355_pll2_init(struct device *dev, void __iomem *base) 67 + int dm355_pll2_init(struct device *dev, void __iomem *base, struct regmap *cfgchip) 69 68 { 70 - davinci_pll_clk_register(dev, &dm355_pll2_info, "oscin", base); 69 + davinci_pll_clk_register(dev, &dm355_pll2_info, "oscin", base, cfgchip); 71 70 72 71 davinci_pll_sysclk_register(dev, &pll2_sysclk1, base); 73 72
+5 -4
drivers/clk/davinci/pll-dm365.c
··· 7 7 8 8 #include <linux/bitops.h> 9 9 #include <linux/clkdev.h> 10 + #include <linux/clk/davinci.h> 10 11 #include <linux/init.h> 11 12 #include <linux/kernel.h> 12 13 #include <linux/types.h> ··· 57 56 .ocsrc_mask = BIT(4), 58 57 }; 59 58 60 - int dm365_pll1_init(struct device *dev, void __iomem *base) 59 + int dm365_pll1_init(struct device *dev, void __iomem *base, struct regmap *cfgchip) 61 60 { 62 61 struct clk *clk; 63 62 64 - davinci_pll_clk_register(dev, &dm365_pll1_info, "ref_clk", base); 63 + davinci_pll_clk_register(dev, &dm365_pll1_info, "ref_clk", base, cfgchip); 65 64 66 65 clk = davinci_pll_sysclk_register(dev, &pll1_sysclk1, base); 67 66 clk_register_clkdev(clk, "pll1_sysclk1", "dm365-psc"); ··· 120 119 .ocsrc_mask = BIT(4), 121 120 }; 122 121 123 - int dm365_pll2_init(struct device *dev, void __iomem *base) 122 + int dm365_pll2_init(struct device *dev, void __iomem *base, struct regmap *cfgchip) 124 123 { 125 124 struct clk *clk; 126 125 127 - davinci_pll_clk_register(dev, &dm365_pll2_info, "oscin", base); 126 + davinci_pll_clk_register(dev, &dm365_pll2_info, "oscin", base, cfgchip); 128 127 129 128 davinci_pll_sysclk_register(dev, &pll2_sysclk1, base); 130 129
+5 -4
drivers/clk/davinci/pll-dm644x.c
··· 6 6 */ 7 7 8 8 #include <linux/bitops.h> 9 + #include <linux/clk/davinci.h> 9 10 #include <linux/clkdev.h> 10 11 #include <linux/init.h> 11 12 #include <linux/types.h> ··· 28 27 SYSCLK(3, pll1_sysclk3, pll1_pllen, 4, SYSCLK_FIXED_DIV); 29 28 SYSCLK(5, pll1_sysclk5, pll1_pllen, 4, SYSCLK_FIXED_DIV); 30 29 31 - int dm644x_pll1_init(struct device *dev, void __iomem *base) 30 + int dm644x_pll1_init(struct device *dev, void __iomem *base, struct regmap *cfgchip) 32 31 { 33 32 struct clk *clk; 34 33 35 - davinci_pll_clk_register(dev, &dm644x_pll1_info, "ref_clk", base); 34 + davinci_pll_clk_register(dev, &dm644x_pll1_info, "ref_clk", base, cfgchip); 36 35 37 36 clk = davinci_pll_sysclk_register(dev, &pll1_sysclk1, base); 38 37 clk_register_clkdev(clk, "pll1_sysclk1", "dm644x-psc"); ··· 67 66 SYSCLK(1, pll2_sysclk1, pll2_pllen, 4, 0); 68 67 SYSCLK(2, pll2_sysclk2, pll2_pllen, 4, 0); 69 68 70 - int dm644x_pll2_init(struct device *dev, void __iomem *base) 69 + int dm644x_pll2_init(struct device *dev, void __iomem *base, struct regmap *cfgchip) 71 70 { 72 - davinci_pll_clk_register(dev, &dm644x_pll2_info, "oscin", base); 71 + davinci_pll_clk_register(dev, &dm644x_pll2_info, "oscin", base, cfgchip); 73 72 74 73 davinci_pll_sysclk_register(dev, &pll2_sysclk1, base); 75 74
+5 -4
drivers/clk/davinci/pll-dm646x.c
··· 6 6 */ 7 7 8 8 #include <linux/clk-provider.h> 9 + #include <linux/clk/davinci.h> 9 10 #include <linux/clkdev.h> 10 11 #include <linux/init.h> 11 12 #include <linux/types.h> ··· 30 29 SYSCLK(8, pll1_sysclk8, pll1_pllen, 4, 0); 31 30 SYSCLK(9, pll1_sysclk9, pll1_pllen, 4, 0); 32 31 33 - int dm646x_pll1_init(struct device *dev, void __iomem *base) 32 + int dm646x_pll1_init(struct device *dev, void __iomem *base, struct regmap *cfgchip) 34 33 { 35 34 struct clk *clk; 36 35 37 - davinci_pll_clk_register(dev, &dm646x_pll1_info, "ref_clk", base); 36 + davinci_pll_clk_register(dev, &dm646x_pll1_info, "ref_clk", base, cfgchip); 38 37 39 38 clk = davinci_pll_sysclk_register(dev, &pll1_sysclk1, base); 40 39 clk_register_clkdev(clk, "pll1_sysclk1", "dm646x-psc"); ··· 75 74 76 75 SYSCLK(1, pll2_sysclk1, pll2_pllen, 4, SYSCLK_ALWAYS_ENABLED); 77 76 78 - int dm646x_pll2_init(struct device *dev, void __iomem *base) 77 + int dm646x_pll2_init(struct device *dev, void __iomem *base, struct regmap *cfgchip) 79 78 { 80 - davinci_pll_clk_register(dev, &dm646x_pll2_info, "oscin", base); 79 + davinci_pll_clk_register(dev, &dm646x_pll2_info, "oscin", base, cfgchip); 81 80 82 81 davinci_pll_sysclk_register(dev, &pll2_sysclk1, base); 83 82
+188 -91
drivers/clk/davinci/pll.c
··· 11 11 12 12 #include <linux/clk-provider.h> 13 13 #include <linux/clk.h> 14 + #include <linux/clk/davinci.h> 14 15 #include <linux/delay.h> 15 16 #include <linux/err.h> 16 17 #include <linux/io.h> ··· 224 223 225 224 /** 226 225 * davinci_pll_div_register - common *DIV clock implementation 226 + * @dev: The PLL platform device or NULL 227 227 * @name: the clock name 228 228 * @parent_name: the parent clock name 229 229 * @reg: the *DIV register ··· 242 240 const struct clk_ops *divider_ops = &clk_divider_ops; 243 241 struct clk_gate *gate; 244 242 struct clk_divider *divider; 243 + struct clk *clk; 244 + int ret; 245 245 246 - gate = devm_kzalloc(dev, sizeof(*gate), GFP_KERNEL); 246 + gate = kzalloc(sizeof(*gate), GFP_KERNEL); 247 247 if (!gate) 248 248 return ERR_PTR(-ENOMEM); 249 249 250 250 gate->reg = reg; 251 251 gate->bit_idx = DIV_ENABLE_SHIFT; 252 252 253 - divider = devm_kzalloc(dev, sizeof(*divider), GFP_KERNEL); 254 - if (!divider) 255 - return ERR_PTR(-ENOMEM); 253 + divider = kzalloc(sizeof(*divider), GFP_KERNEL); 254 + if (!divider) { 255 + ret = -ENOMEM; 256 + goto err_free_gate; 257 + } 256 258 257 259 divider->reg = reg; 258 260 divider->shift = DIV_RATIO_SHIFT; ··· 267 261 divider_ops = &clk_divider_ro_ops; 268 262 } 269 263 270 - return clk_register_composite(dev, name, parent_names, num_parents, 271 - NULL, NULL, &divider->hw, divider_ops, 272 - &gate->hw, &clk_gate_ops, flags); 264 + clk = clk_register_composite(dev, name, parent_names, num_parents, 265 + NULL, NULL, &divider->hw, divider_ops, 266 + &gate->hw, &clk_gate_ops, flags); 267 + if (IS_ERR(clk)) { 268 + ret = PTR_ERR(clk); 269 + goto err_free_divider; 270 + } 271 + 272 + return clk; 273 + 274 + err_free_divider: 275 + kfree(divider); 276 + err_free_gate: 277 + kfree(gate); 278 + 279 + return ERR_PTR(ret); 273 280 } 274 281 275 282 struct davinci_pllen_clk { ··· 340 321 return NOTIFY_OK; 341 322 } 342 323 343 - static struct davinci_pll_platform_data *davinci_pll_get_pdata(struct device *dev) 344 - { 345 - struct davinci_pll_platform_data *pdata = dev_get_platdata(dev); 346 - 347 - /* 348 - * Platform data is optional, so allocate a new struct if one was not 349 - * provided. For device tree, this will always be the case. 350 - */ 351 - if (!pdata) 352 - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); 353 - if (!pdata) 354 - return NULL; 355 - 356 - /* for device tree, we need to fill in the struct */ 357 - if (dev->of_node) 358 - pdata->cfgchip = 359 - syscon_regmap_lookup_by_compatible("ti,da830-cfgchip"); 360 - 361 - return pdata; 362 - } 363 - 364 324 static struct notifier_block davinci_pllen_notifier = { 365 325 .notifier_call = davinci_pllen_rate_change, 366 326 }; 367 327 368 328 /** 369 329 * davinci_pll_clk_register - Register a PLL clock 330 + * @dev: The PLL platform device or NULL 370 331 * @info: The device-specific clock info 371 332 * @parent_name: The parent clock name 372 333 * @base: The PLL's memory region 334 + * @cfgchip: CFGCHIP syscon regmap for info->unlock_reg or NULL 373 335 * 374 336 * This creates a series of clocks that represent the PLL. 375 337 * ··· 366 366 struct clk *davinci_pll_clk_register(struct device *dev, 367 367 const struct davinci_pll_clk_info *info, 368 368 const char *parent_name, 369 - void __iomem *base) 369 + void __iomem *base, 370 + struct regmap *cfgchip) 370 371 { 371 - struct davinci_pll_platform_data *pdata; 372 372 char prediv_name[MAX_NAME_SIZE]; 373 373 char pllout_name[MAX_NAME_SIZE]; 374 374 char postdiv_name[MAX_NAME_SIZE]; ··· 376 376 struct clk_init_data init; 377 377 struct davinci_pll_clk *pllout; 378 378 struct davinci_pllen_clk *pllen; 379 - struct clk *pllout_clk, *clk; 380 - 381 - pdata = davinci_pll_get_pdata(dev); 382 - if (!pdata) 383 - return ERR_PTR(-ENOMEM); 379 + struct clk *oscin_clk = NULL; 380 + struct clk *prediv_clk = NULL; 381 + struct clk *pllout_clk; 382 + struct clk *postdiv_clk = NULL; 383 + struct clk *pllen_clk; 384 + int ret; 384 385 385 386 if (info->flags & PLL_HAS_CLKMODE) { 386 387 /* ··· 393 392 * a number of different things. In this driver we use it to 394 393 * mean the signal after the PLLCTL[CLKMODE] switch. 395 394 */ 396 - clk = clk_register_fixed_factor(dev, OSCIN_CLK_NAME, 397 - parent_name, 0, 1, 1); 398 - if (IS_ERR(clk)) 399 - return clk; 395 + oscin_clk = clk_register_fixed_factor(dev, OSCIN_CLK_NAME, 396 + parent_name, 0, 1, 1); 397 + if (IS_ERR(oscin_clk)) 398 + return oscin_clk; 400 399 401 400 parent_name = OSCIN_CLK_NAME; 402 401 } ··· 412 411 413 412 /* Some? DM355 chips don't correctly report the PREDIV value */ 414 413 if (info->flags & PLL_PREDIV_FIXED8) 415 - clk = clk_register_fixed_factor(dev, prediv_name, 416 - parent_name, flags, 1, 8); 414 + prediv_clk = clk_register_fixed_factor(dev, prediv_name, 415 + parent_name, flags, 1, 8); 417 416 else 418 - clk = davinci_pll_div_register(dev, prediv_name, 417 + prediv_clk = davinci_pll_div_register(dev, prediv_name, 419 418 parent_name, base + PREDIV, fixed, flags); 420 - if (IS_ERR(clk)) 421 - return clk; 419 + if (IS_ERR(prediv_clk)) { 420 + ret = PTR_ERR(prediv_clk); 421 + goto err_unregister_oscin; 422 + } 422 423 423 424 parent_name = prediv_name; 424 425 } 425 426 426 427 /* Unlock writing to PLL registers */ 427 428 if (info->unlock_reg) { 428 - if (IS_ERR_OR_NULL(pdata->cfgchip)) 429 + if (IS_ERR_OR_NULL(cfgchip)) 429 430 dev_warn(dev, "Failed to get CFGCHIP (%ld)\n", 430 - PTR_ERR(pdata->cfgchip)); 431 + PTR_ERR(cfgchip)); 431 432 else 432 - regmap_write_bits(pdata->cfgchip, info->unlock_reg, 433 + regmap_write_bits(cfgchip, info->unlock_reg, 433 434 info->unlock_mask, 0); 434 435 } 435 436 436 - pllout = devm_kzalloc(dev, sizeof(*pllout), GFP_KERNEL); 437 - if (!pllout) 438 - return ERR_PTR(-ENOMEM); 437 + pllout = kzalloc(sizeof(*pllout), GFP_KERNEL); 438 + if (!pllout) { 439 + ret = -ENOMEM; 440 + goto err_unregister_prediv; 441 + } 439 442 440 443 snprintf(pllout_name, MAX_NAME_SIZE, "%s_pllout", info->name); 441 444 ··· 461 456 pllout->pllm_min = info->pllm_min; 462 457 pllout->pllm_max = info->pllm_max; 463 458 464 - pllout_clk = devm_clk_register(dev, &pllout->hw); 465 - if (IS_ERR(pllout_clk)) 466 - return pllout_clk; 459 + pllout_clk = clk_register(dev, &pllout->hw); 460 + if (IS_ERR(pllout_clk)) { 461 + ret = PTR_ERR(pllout_clk); 462 + goto err_free_pllout; 463 + } 467 464 468 465 clk_hw_set_rate_range(&pllout->hw, info->pllout_min_rate, 469 466 info->pllout_max_rate); ··· 481 474 if (info->flags & PLL_POSTDIV_ALWAYS_ENABLED) 482 475 flags |= CLK_IS_CRITICAL; 483 476 484 - clk = davinci_pll_div_register(dev, postdiv_name, parent_name, 485 - base + POSTDIV, fixed, flags); 486 - if (IS_ERR(clk)) 487 - return clk; 477 + postdiv_clk = davinci_pll_div_register(dev, postdiv_name, 478 + parent_name, base + POSTDIV, fixed, flags); 479 + if (IS_ERR(postdiv_clk)) { 480 + ret = PTR_ERR(postdiv_clk); 481 + goto err_unregister_pllout; 482 + } 488 483 489 484 parent_name = postdiv_name; 490 485 } 491 486 492 - pllen = devm_kzalloc(dev, sizeof(*pllout), GFP_KERNEL); 493 - if (!pllen) 494 - return ERR_PTR(-ENOMEM); 487 + pllen = kzalloc(sizeof(*pllout), GFP_KERNEL); 488 + if (!pllen) { 489 + ret = -ENOMEM; 490 + goto err_unregister_postdiv; 491 + } 495 492 496 493 snprintf(pllen_name, MAX_NAME_SIZE, "%s_pllen", info->name); 497 494 ··· 508 497 pllen->hw.init = &init; 509 498 pllen->base = base; 510 499 511 - clk = devm_clk_register(dev, &pllen->hw); 512 - if (IS_ERR(clk)) 513 - return clk; 500 + pllen_clk = clk_register(dev, &pllen->hw); 501 + if (IS_ERR(pllen_clk)) { 502 + ret = PTR_ERR(pllen_clk); 503 + goto err_free_pllen; 504 + } 514 505 515 - clk_notifier_register(clk, &davinci_pllen_notifier); 506 + clk_notifier_register(pllen_clk, &davinci_pllen_notifier); 516 507 517 508 return pllout_clk; 509 + 510 + err_free_pllen: 511 + kfree(pllen); 512 + err_unregister_postdiv: 513 + clk_unregister(postdiv_clk); 514 + err_unregister_pllout: 515 + clk_unregister(pllout_clk); 516 + err_free_pllout: 517 + kfree(pllout); 518 + err_unregister_prediv: 519 + clk_unregister(prediv_clk); 520 + err_unregister_oscin: 521 + clk_unregister(oscin_clk); 522 + 523 + return ERR_PTR(ret); 518 524 } 519 525 520 526 /** 521 527 * davinci_pll_auxclk_register - Register bypass clock (AUXCLK) 528 + * @dev: The PLL platform device or NULL 522 529 * @name: The clock name 523 530 * @base: The PLL memory region 524 531 */ ··· 550 521 551 522 /** 552 523 * davinci_pll_sysclkbp_clk_register - Register bypass divider clock (SYSCLKBP) 524 + * @dev: The PLL platform device or NULL 553 525 * @name: The clock name 554 526 * @base: The PLL memory region 555 527 */ ··· 565 535 566 536 /** 567 537 * davinci_pll_obsclk_register - Register oscillator divider clock (OBSCLK) 538 + * @dev: The PLL platform device or NULL 568 539 * @info: The clock info 569 540 * @base: The PLL memory region 570 541 */ ··· 577 546 struct clk_mux *mux; 578 547 struct clk_gate *gate; 579 548 struct clk_divider *divider; 549 + struct clk *clk; 580 550 u32 oscdiv; 551 + int ret; 581 552 582 - mux = devm_kzalloc(dev, sizeof(*mux), GFP_KERNEL); 553 + mux = kzalloc(sizeof(*mux), GFP_KERNEL); 583 554 if (!mux) 584 555 return ERR_PTR(-ENOMEM); 585 556 ··· 589 556 mux->table = info->table; 590 557 mux->mask = info->ocsrc_mask; 591 558 592 - gate = devm_kzalloc(dev, sizeof(*gate), GFP_KERNEL); 593 - if (!gate) 594 - return ERR_PTR(-ENOMEM); 559 + gate = kzalloc(sizeof(*gate), GFP_KERNEL); 560 + if (!gate) { 561 + ret = -ENOMEM; 562 + goto err_free_mux; 563 + } 595 564 596 565 gate->reg = base + CKEN; 597 566 gate->bit_idx = CKEN_OBSCLK_SHIFT; 598 567 599 - divider = devm_kzalloc(dev, sizeof(*divider), GFP_KERNEL); 600 - if (!divider) 601 - return ERR_PTR(-ENOMEM); 568 + divider = kzalloc(sizeof(*divider), GFP_KERNEL); 569 + if (!divider) { 570 + ret = -ENOMEM; 571 + goto err_free_gate; 572 + } 602 573 603 574 divider->reg = base + OSCDIV; 604 575 divider->shift = DIV_RATIO_SHIFT; ··· 613 576 oscdiv |= BIT(DIV_ENABLE_SHIFT); 614 577 writel(oscdiv, base + OSCDIV); 615 578 616 - return clk_register_composite(dev, info->name, info->parent_names, 617 - info->num_parents, 618 - &mux->hw, &clk_mux_ops, 619 - &divider->hw, &clk_divider_ops, 620 - &gate->hw, &clk_gate_ops, 0); 579 + clk = clk_register_composite(dev, info->name, info->parent_names, 580 + info->num_parents, 581 + &mux->hw, &clk_mux_ops, 582 + &divider->hw, &clk_divider_ops, 583 + &gate->hw, &clk_gate_ops, 0); 584 + 585 + if (IS_ERR(clk)) { 586 + ret = PTR_ERR(clk); 587 + goto err_free_divider; 588 + } 589 + 590 + return clk; 591 + 592 + err_free_divider: 593 + kfree(divider); 594 + err_free_gate: 595 + kfree(gate); 596 + err_free_mux: 597 + kfree(mux); 598 + 599 + return ERR_PTR(ret); 621 600 } 622 601 623 602 /* The PLL SYSCLKn clocks have a mechanism for synchronizing rate changes. */ ··· 669 616 670 617 /** 671 618 * davinci_pll_sysclk_register - Register divider clocks (SYSCLKn) 619 + * @dev: The PLL platform device or NULL 672 620 * @info: The clock info 673 621 * @base: The PLL memory region 674 622 */ ··· 684 630 struct clk *clk; 685 631 u32 reg; 686 632 u32 flags = 0; 633 + int ret; 687 634 688 635 /* PLLDIVn registers are not entirely consecutive */ 689 636 if (info->id < 4) ··· 692 637 else 693 638 reg = PLLDIV4 + 4 * (info->id - 4); 694 639 695 - gate = devm_kzalloc(dev, sizeof(*gate), GFP_KERNEL); 640 + gate = kzalloc(sizeof(*gate), GFP_KERNEL); 696 641 if (!gate) 697 642 return ERR_PTR(-ENOMEM); 698 643 699 644 gate->reg = base + reg; 700 645 gate->bit_idx = DIV_ENABLE_SHIFT; 701 646 702 - divider = devm_kzalloc(dev, sizeof(*divider), GFP_KERNEL); 703 - if (!divider) 704 - return ERR_PTR(-ENOMEM); 647 + divider = kzalloc(sizeof(*divider), GFP_KERNEL); 648 + if (!divider) { 649 + ret = -ENOMEM; 650 + goto err_free_gate; 651 + } 705 652 706 653 divider->reg = base + reg; 707 654 divider->shift = DIV_RATIO_SHIFT; ··· 725 668 clk = clk_register_composite(dev, info->name, &info->parent_name, 1, 726 669 NULL, NULL, &divider->hw, divider_ops, 727 670 &gate->hw, &clk_gate_ops, flags); 728 - if (IS_ERR(clk)) 729 - return clk; 671 + if (IS_ERR(clk)) { 672 + ret = PTR_ERR(clk); 673 + goto err_free_divider; 674 + } 730 675 731 676 clk_notifier_register(clk, &davinci_pll_sysclk_notifier); 732 677 733 678 return clk; 679 + 680 + err_free_divider: 681 + kfree(divider); 682 + err_free_gate: 683 + kfree(gate); 684 + 685 + return ERR_PTR(ret); 734 686 } 735 687 736 - int of_davinci_pll_init(struct device *dev, 688 + int of_davinci_pll_init(struct device *dev, struct device_node *node, 737 689 const struct davinci_pll_clk_info *info, 738 690 const struct davinci_pll_obsclk_info *obsclk_info, 739 691 const struct davinci_pll_sysclk_info **div_info, 740 692 u8 max_sysclk_id, 741 - void __iomem *base) 693 + void __iomem *base, 694 + struct regmap *cfgchip) 742 695 { 743 - struct device_node *node = dev->of_node; 744 696 struct device_node *child; 745 697 const char *parent_name; 746 698 struct clk *clk; ··· 759 693 else 760 694 parent_name = OSCIN_CLK_NAME; 761 695 762 - clk = davinci_pll_clk_register(dev, info, parent_name, base); 696 + clk = davinci_pll_clk_register(dev, info, parent_name, base, cfgchip); 763 697 if (IS_ERR(clk)) { 764 698 dev_err(dev, "failed to register %s\n", info->name); 765 699 return PTR_ERR(clk); ··· 777 711 int n_clks = max_sysclk_id + 1; 778 712 int i; 779 713 780 - clk_data = devm_kzalloc(dev, sizeof(*clk_data), GFP_KERNEL); 714 + clk_data = kzalloc(sizeof(*clk_data), GFP_KERNEL); 781 715 if (!clk_data) 782 716 return -ENOMEM; 783 717 784 - clks = devm_kmalloc_array(dev, n_clks, sizeof(*clks), GFP_KERNEL); 785 - if (!clks) 718 + clks = kmalloc_array(n_clks, sizeof(*clks), GFP_KERNEL); 719 + if (!clks) { 720 + kfree(clk_data); 786 721 return -ENOMEM; 722 + } 787 723 788 724 clk_data->clks = clks; 789 725 clk_data->clk_num = n_clks; ··· 838 770 return 0; 839 771 } 840 772 773 + static struct davinci_pll_platform_data *davinci_pll_get_pdata(struct device *dev) 774 + { 775 + struct davinci_pll_platform_data *pdata = dev_get_platdata(dev); 776 + 777 + /* 778 + * Platform data is optional, so allocate a new struct if one was not 779 + * provided. For device tree, this will always be the case. 780 + */ 781 + if (!pdata) 782 + pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); 783 + if (!pdata) 784 + return NULL; 785 + 786 + /* for device tree, we need to fill in the struct */ 787 + if (dev->of_node) 788 + pdata->cfgchip = 789 + syscon_regmap_lookup_by_compatible("ti,da830-cfgchip"); 790 + 791 + return pdata; 792 + } 793 + 841 794 static const struct of_device_id davinci_pll_of_match[] = { 842 795 { .compatible = "ti,da850-pll0", .data = of_da850_pll0_init }, 843 796 { .compatible = "ti,da850-pll1", .data = of_da850_pll1_init }, ··· 880 791 { } 881 792 }; 882 793 883 - typedef int (*davinci_pll_init)(struct device *dev, void __iomem *base); 794 + typedef int (*davinci_pll_init)(struct device *dev, void __iomem *base, 795 + struct regmap *cfgchip); 884 796 885 797 static int davinci_pll_probe(struct platform_device *pdev) 886 798 { 887 799 struct device *dev = &pdev->dev; 800 + struct davinci_pll_platform_data *pdata; 888 801 const struct of_device_id *of_id; 889 802 davinci_pll_init pll_init = NULL; 890 803 struct resource *res; ··· 903 812 return -EINVAL; 904 813 } 905 814 815 + pdata = davinci_pll_get_pdata(dev); 816 + if (!pdata) { 817 + dev_err(dev, "missing platform data\n"); 818 + return -EINVAL; 819 + } 820 + 906 821 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 907 822 base = devm_ioremap_resource(dev, res); 908 823 if (IS_ERR(base)) 909 824 return PTR_ERR(base); 910 825 911 - return pll_init(dev, base); 826 + return pll_init(dev, base, pdata->cfgchip); 912 827 } 913 828 914 829 static struct platform_driver davinci_pll_driver = {
+12 -18
drivers/clk/davinci/pll.h
··· 11 11 #include <linux/bitops.h> 12 12 #include <linux/clk-provider.h> 13 13 #include <linux/of.h> 14 + #include <linux/regmap.h> 14 15 #include <linux/types.h> 15 16 16 17 #define PLL_HAS_CLKMODE BIT(0) /* PLL has PLLCTL[CLKMODE] */ ··· 95 94 struct clk *davinci_pll_clk_register(struct device *dev, 96 95 const struct davinci_pll_clk_info *info, 97 96 const char *parent_name, 98 - void __iomem *base); 97 + void __iomem *base, 98 + struct regmap *cfgchip); 99 99 struct clk *davinci_pll_auxclk_register(struct device *dev, 100 100 const char *name, 101 101 void __iomem *base); ··· 112 110 const struct davinci_pll_sysclk_info *info, 113 111 void __iomem *base); 114 112 115 - int of_davinci_pll_init(struct device *dev, 113 + int of_davinci_pll_init(struct device *dev, struct device_node *node, 116 114 const struct davinci_pll_clk_info *info, 117 115 const struct davinci_pll_obsclk_info *obsclk_info, 118 116 const struct davinci_pll_sysclk_info **div_info, 119 117 u8 max_sysclk_id, 120 - void __iomem *base); 118 + void __iomem *base, 119 + struct regmap *cfgchip); 121 120 122 121 /* Platform-specific callbacks */ 123 122 124 - int da830_pll_init(struct device *dev, void __iomem *base); 123 + int da850_pll1_init(struct device *dev, void __iomem *base, struct regmap *cfgchip); 124 + int of_da850_pll0_init(struct device *dev, void __iomem *base, struct regmap *cfgchip); 125 + int of_da850_pll1_init(struct device *dev, void __iomem *base, struct regmap *cfgchip); 125 126 126 - int da850_pll0_init(struct device *dev, void __iomem *base); 127 - int da850_pll1_init(struct device *dev, void __iomem *base); 128 - int of_da850_pll0_init(struct device *dev, void __iomem *base); 129 - int of_da850_pll1_init(struct device *dev, void __iomem *base); 127 + int dm355_pll2_init(struct device *dev, void __iomem *base, struct regmap *cfgchip); 130 128 131 - int dm355_pll1_init(struct device *dev, void __iomem *base); 132 - int dm355_pll2_init(struct device *dev, void __iomem *base); 129 + int dm644x_pll2_init(struct device *dev, void __iomem *base, struct regmap *cfgchip); 133 130 134 - int dm365_pll1_init(struct device *dev, void __iomem *base); 135 - int dm365_pll2_init(struct device *dev, void __iomem *base); 136 - 137 - int dm644x_pll1_init(struct device *dev, void __iomem *base); 138 - int dm644x_pll2_init(struct device *dev, void __iomem *base); 139 - 140 - int dm646x_pll1_init(struct device *dev, void __iomem *base); 141 - int dm646x_pll2_init(struct device *dev, void __iomem *base); 131 + int dm646x_pll2_init(struct device *dev, void __iomem *base, struct regmap *cfgchip); 142 132 143 133 #endif /* __CLK_DAVINCI_PLL_H___ */
+24
include/linux/clk/davinci.h
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Clock drivers for TI DaVinci PLL and PSC controllers 4 + * 5 + * Copyright (C) 2018 David Lechner <david@lechnology.com> 6 + */ 7 + 8 + #ifndef __LINUX_CLK_DAVINCI_PLL_H___ 9 + #define __LINUX_CLK_DAVINCI_PLL_H___ 10 + 11 + #include <linux/device.h> 12 + #include <linux/regmap.h> 13 + 14 + /* function for registering clocks in early boot */ 15 + 16 + int da830_pll_init(struct device *dev, void __iomem *base, struct regmap *cfgchip); 17 + int da850_pll0_init(struct device *dev, void __iomem *base, struct regmap *cfgchip); 18 + int dm355_pll1_init(struct device *dev, void __iomem *base, struct regmap *cfgchip); 19 + int dm365_pll1_init(struct device *dev, void __iomem *base, struct regmap *cfgchip); 20 + int dm365_pll2_init(struct device *dev, void __iomem *base, struct regmap *cfgchip); 21 + int dm644x_pll1_init(struct device *dev, void __iomem *base, struct regmap *cfgchip); 22 + int dm646x_pll1_init(struct device *dev, void __iomem *base, struct regmap *cfgchip); 23 + 24 + #endif /* __LINUX_CLK_DAVINCI_PLL_H___ */