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

Merge branches 'clk-tegra' and 'clk-bulk-get-all' into clk-next

- Nvidia Tegra clk driver MBIST workaround fix
- clk_bulk_get_all() API and friends to get all the clks for a device

* clk-tegra:
clk: tegra210: Include size.h for compilation ease
clk: tegra: Fixes for MBIST work around
clk: tegra: probe deferral error reporting

* clk-bulk-get-all:
clk: add managed version of clk_bulk_get_all
clk: add new APIs to operate on all available clocks
clk: bulk: add of_clk_bulk_get()

+178 -6
+80
drivers/clk/clk-bulk.c
··· 17 17 */ 18 18 19 19 #include <linux/clk.h> 20 + #include <linux/clk-provider.h> 20 21 #include <linux/device.h> 21 22 #include <linux/export.h> 23 + #include <linux/of.h> 24 + #include <linux/slab.h> 25 + 26 + static int __must_check of_clk_bulk_get(struct device_node *np, int num_clks, 27 + struct clk_bulk_data *clks) 28 + { 29 + int ret; 30 + int i; 31 + 32 + for (i = 0; i < num_clks; i++) 33 + clks[i].clk = NULL; 34 + 35 + for (i = 0; i < num_clks; i++) { 36 + clks[i].clk = of_clk_get(np, i); 37 + if (IS_ERR(clks[i].clk)) { 38 + ret = PTR_ERR(clks[i].clk); 39 + pr_err("%pOF: Failed to get clk index: %d ret: %d\n", 40 + np, i, ret); 41 + clks[i].clk = NULL; 42 + goto err; 43 + } 44 + } 45 + 46 + return 0; 47 + 48 + err: 49 + clk_bulk_put(i, clks); 50 + 51 + return ret; 52 + } 53 + 54 + static int __must_check of_clk_bulk_get_all(struct device_node *np, 55 + struct clk_bulk_data **clks) 56 + { 57 + struct clk_bulk_data *clk_bulk; 58 + int num_clks; 59 + int ret; 60 + 61 + num_clks = of_clk_get_parent_count(np); 62 + if (!num_clks) 63 + return 0; 64 + 65 + clk_bulk = kmalloc_array(num_clks, sizeof(*clk_bulk), GFP_KERNEL); 66 + if (!clk_bulk) 67 + return -ENOMEM; 68 + 69 + ret = of_clk_bulk_get(np, num_clks, clk_bulk); 70 + if (ret) { 71 + kfree(clk_bulk); 72 + return ret; 73 + } 74 + 75 + *clks = clk_bulk; 76 + 77 + return num_clks; 78 + } 22 79 23 80 void clk_bulk_put(int num_clks, struct clk_bulk_data *clks) 24 81 { ··· 115 58 return ret; 116 59 } 117 60 EXPORT_SYMBOL(clk_bulk_get); 61 + 62 + void clk_bulk_put_all(int num_clks, struct clk_bulk_data *clks) 63 + { 64 + if (IS_ERR_OR_NULL(clks)) 65 + return; 66 + 67 + clk_bulk_put(num_clks, clks); 68 + 69 + kfree(clks); 70 + } 71 + EXPORT_SYMBOL(clk_bulk_put_all); 72 + 73 + int __must_check clk_bulk_get_all(struct device *dev, 74 + struct clk_bulk_data **clks) 75 + { 76 + struct device_node *np = dev_of_node(dev); 77 + 78 + if (!np) 79 + return 0; 80 + 81 + return of_clk_bulk_get_all(np, clks); 82 + } 83 + EXPORT_SYMBOL(clk_bulk_get_all); 118 84 119 85 #ifdef CONFIG_HAVE_CLK_PREPARE 120 86
+24
drivers/clk/clk-devres.c
··· 70 70 } 71 71 EXPORT_SYMBOL_GPL(devm_clk_bulk_get); 72 72 73 + int __must_check devm_clk_bulk_get_all(struct device *dev, 74 + struct clk_bulk_data **clks) 75 + { 76 + struct clk_bulk_devres *devres; 77 + int ret; 78 + 79 + devres = devres_alloc(devm_clk_bulk_release, 80 + sizeof(*devres), GFP_KERNEL); 81 + if (!devres) 82 + return -ENOMEM; 83 + 84 + ret = clk_bulk_get_all(dev, &devres->clks); 85 + if (ret > 0) { 86 + *clks = devres->clks; 87 + devres->num_clks = ret; 88 + devres_add(dev, devres); 89 + } else { 90 + devres_free(devres); 91 + } 92 + 93 + return ret; 94 + } 95 + EXPORT_SYMBOL_GPL(devm_clk_bulk_get_all); 96 + 73 97 static int devm_clk_match(struct device *dev, void *res, void *data) 74 98 { 75 99 struct clk **c = res;
+6 -2
drivers/clk/tegra/clk-dfll.c
··· 1609 1609 1610 1610 td->vdd_reg = devm_regulator_get(td->dev, "vdd-cpu"); 1611 1611 if (IS_ERR(td->vdd_reg)) { 1612 - dev_err(td->dev, "couldn't get vdd_cpu regulator\n"); 1613 - return PTR_ERR(td->vdd_reg); 1612 + ret = PTR_ERR(td->vdd_reg); 1613 + if (ret != -EPROBE_DEFER) 1614 + dev_err(td->dev, "couldn't get vdd_cpu regulator: %d\n", 1615 + ret); 1616 + 1617 + return ret; 1614 1618 } 1615 1619 1616 1620 td->dvco_rst = devm_reset_control_get(td->dev, "dvco");
+4 -3
drivers/clk/tegra/clk-tegra210.c
··· 27 27 #include <dt-bindings/clock/tegra210-car.h> 28 28 #include <dt-bindings/reset/tegra210-car.h> 29 29 #include <linux/iopoll.h> 30 + #include <linux/sizes.h> 30 31 #include <soc/tegra/pmc.h> 31 32 32 33 #include "clk.h" ··· 2604 2603 [TEGRA_POWERGATE_MPE] = { 2605 2604 .handle_lvl2_ovr = tegra210_generic_mbist_war, 2606 2605 .lvl2_offset = LVL2_CLK_GATE_OVRE, 2607 - .lvl2_mask = BIT(2), 2606 + .lvl2_mask = BIT(29), 2608 2607 }, 2609 2608 [TEGRA_POWERGATE_SOR] = { 2610 2609 .handle_lvl2_ovr = tegra210_generic_mbist_war, ··· 2655 2654 .num_clks = ARRAY_SIZE(nvdec_slcg_clkids), 2656 2655 .clk_init_data = nvdec_slcg_clkids, 2657 2656 .handle_lvl2_ovr = tegra210_generic_mbist_war, 2658 - .lvl2_offset = LVL2_CLK_GATE_OVRC, 2657 + .lvl2_offset = LVL2_CLK_GATE_OVRE, 2659 2658 .lvl2_mask = BIT(9) | BIT(31), 2660 2659 }, 2661 2660 [TEGRA_POWERGATE_NVJPG] = { 2662 2661 .num_clks = ARRAY_SIZE(nvjpg_slcg_clkids), 2663 2662 .clk_init_data = nvjpg_slcg_clkids, 2664 2663 .handle_lvl2_ovr = tegra210_generic_mbist_war, 2665 - .lvl2_offset = LVL2_CLK_GATE_OVRC, 2664 + .lvl2_offset = LVL2_CLK_GATE_OVRE, 2666 2665 .lvl2_mask = BIT(9) | BIT(31), 2667 2666 }, 2668 2667 [TEGRA_POWERGATE_AUD] = {
+64 -1
include/linux/clk.h
··· 312 312 */ 313 313 int __must_check clk_bulk_get(struct device *dev, int num_clks, 314 314 struct clk_bulk_data *clks); 315 - 315 + /** 316 + * clk_bulk_get_all - lookup and obtain all available references to clock 317 + * producer. 318 + * @dev: device for clock "consumer" 319 + * @clks: pointer to the clk_bulk_data table of consumer 320 + * 321 + * This helper function allows drivers to get all clk consumers in one 322 + * operation. If any of the clk cannot be acquired then any clks 323 + * that were obtained will be freed before returning to the caller. 324 + * 325 + * Returns a positive value for the number of clocks obtained while the 326 + * clock references are stored in the clk_bulk_data table in @clks field. 327 + * Returns 0 if there're none and a negative value if something failed. 328 + * 329 + * Drivers must assume that the clock source is not enabled. 330 + * 331 + * clk_bulk_get should not be called from within interrupt context. 332 + */ 333 + int __must_check clk_bulk_get_all(struct device *dev, 334 + struct clk_bulk_data **clks); 316 335 /** 317 336 * devm_clk_bulk_get - managed get multiple clk consumers 318 337 * @dev: device for clock "consumer" ··· 346 327 */ 347 328 int __must_check devm_clk_bulk_get(struct device *dev, int num_clks, 348 329 struct clk_bulk_data *clks); 330 + /** 331 + * devm_clk_bulk_get_all - managed get multiple clk consumers 332 + * @dev: device for clock "consumer" 333 + * @clks: pointer to the clk_bulk_data table of consumer 334 + * 335 + * Returns a positive value for the number of clocks obtained while the 336 + * clock references are stored in the clk_bulk_data table in @clks field. 337 + * Returns 0 if there're none and a negative value if something failed. 338 + * 339 + * This helper function allows drivers to get several clk 340 + * consumers in one operation with management, the clks will 341 + * automatically be freed when the device is unbound. 342 + */ 343 + 344 + int __must_check devm_clk_bulk_get_all(struct device *dev, 345 + struct clk_bulk_data **clks); 349 346 350 347 /** 351 348 * devm_clk_get - lookup and obtain a managed reference to a clock producer. ··· 521 486 * clk_bulk_put should not be called from within interrupt context. 522 487 */ 523 488 void clk_bulk_put(int num_clks, struct clk_bulk_data *clks); 489 + 490 + /** 491 + * clk_bulk_put_all - "free" all the clock source 492 + * @num_clks: the number of clk_bulk_data 493 + * @clks: the clk_bulk_data table of consumer 494 + * 495 + * Note: drivers must ensure that all clk_bulk_enable calls made on this 496 + * clock source are balanced by clk_bulk_disable calls prior to calling 497 + * this function. 498 + * 499 + * clk_bulk_put_all should not be called from within interrupt context. 500 + */ 501 + void clk_bulk_put_all(int num_clks, struct clk_bulk_data *clks); 524 502 525 503 /** 526 504 * devm_clk_put - "free" a managed clock source ··· 707 659 return 0; 708 660 } 709 661 662 + static inline int __must_check clk_bulk_get_all(struct device *dev, 663 + struct clk_bulk_data **clks) 664 + { 665 + return 0; 666 + } 667 + 710 668 static inline struct clk *devm_clk_get(struct device *dev, const char *id) 711 669 { 712 670 return NULL; ··· 721 667 static inline int __must_check devm_clk_bulk_get(struct device *dev, int num_clks, 722 668 struct clk_bulk_data *clks) 723 669 { 670 + return 0; 671 + } 672 + 673 + static inline int __must_check devm_clk_bulk_get_all(struct device *dev, 674 + struct clk_bulk_data **clks) 675 + { 676 + 724 677 return 0; 725 678 } 726 679 ··· 740 679 static inline void clk_put(struct clk *clk) {} 741 680 742 681 static inline void clk_bulk_put(int num_clks, struct clk_bulk_data *clks) {} 682 + 683 + static inline void clk_bulk_put_all(int num_clks, struct clk_bulk_data *clks) {} 743 684 744 685 static inline void devm_clk_put(struct device *dev, struct clk *clk) {} 745 686