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

clk: Provide managed helper to get and enable bulk clocks

Provide a managed devm_clk_bulk* wrapper to get and enable all
bulk clocks in order to simplify drivers that keeps all clocks
enabled for the time of driver operation.

Suggested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Reviewed-by: Alim Akhtar <alim.akhtar@samsung.com>
Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Shradha Todi <shradha.t@samsung.com>
Link: https://lore.kernel.org/r/20240220084046.23786-2-shradha.t@samsung.com
Signed-off-by: Stephen Boyd <sboyd@kernel.org>

authored by

Shradha Todi and committed by
Stephen Boyd
265b07df 6613476e

+62
+40
drivers/clk/clk-devres.c
··· 182 182 } 183 183 EXPORT_SYMBOL_GPL(devm_clk_bulk_get_all); 184 184 185 + static void devm_clk_bulk_release_all_enable(struct device *dev, void *res) 186 + { 187 + struct clk_bulk_devres *devres = res; 188 + 189 + clk_bulk_disable_unprepare(devres->num_clks, devres->clks); 190 + clk_bulk_put_all(devres->num_clks, devres->clks); 191 + } 192 + 193 + int __must_check devm_clk_bulk_get_all_enable(struct device *dev, 194 + struct clk_bulk_data **clks) 195 + { 196 + struct clk_bulk_devres *devres; 197 + int ret; 198 + 199 + devres = devres_alloc(devm_clk_bulk_release_all_enable, 200 + sizeof(*devres), GFP_KERNEL); 201 + if (!devres) 202 + return -ENOMEM; 203 + 204 + ret = clk_bulk_get_all(dev, &devres->clks); 205 + if (ret > 0) { 206 + *clks = devres->clks; 207 + devres->num_clks = ret; 208 + } else { 209 + devres_free(devres); 210 + return ret; 211 + } 212 + 213 + ret = clk_bulk_prepare_enable(devres->num_clks, *clks); 214 + if (!ret) { 215 + devres_add(dev, devres); 216 + } else { 217 + clk_bulk_put_all(devres->num_clks, devres->clks); 218 + devres_free(devres); 219 + } 220 + 221 + return ret; 222 + } 223 + EXPORT_SYMBOL_GPL(devm_clk_bulk_get_all_enable); 224 + 185 225 static int devm_clk_match(struct device *dev, void *res, void *data) 186 226 { 187 227 struct clk **c = res;
+22
include/linux/clk.h
··· 479 479 struct clk_bulk_data **clks); 480 480 481 481 /** 482 + * devm_clk_bulk_get_all_enable - Get and enable all clocks of the consumer (managed) 483 + * @dev: device for clock "consumer" 484 + * @clks: pointer to the clk_bulk_data table of consumer 485 + * 486 + * Returns success (0) or negative errno. 487 + * 488 + * This helper function allows drivers to get all clocks of the 489 + * consumer and enables them in one operation with management. 490 + * The clks will automatically be disabled and freed when the device 491 + * is unbound. 492 + */ 493 + 494 + int __must_check devm_clk_bulk_get_all_enable(struct device *dev, 495 + struct clk_bulk_data **clks); 496 + 497 + /** 482 498 * devm_clk_get - lookup and obtain a managed reference to a clock producer. 483 499 * @dev: device for clock "consumer" 484 500 * @id: clock consumer ID ··· 981 965 struct clk_bulk_data **clks) 982 966 { 983 967 968 + return 0; 969 + } 970 + 971 + static inline int __must_check devm_clk_bulk_get_all_enable(struct device *dev, 972 + struct clk_bulk_data **clks) 973 + { 984 974 return 0; 985 975 } 986 976