diff options
author | Peng Fan <peng.fan@nxp.com> | 2022-07-03 12:11:25 +0300 |
---|---|---|
committer | Georgi Djakov <djakov@kernel.org> | 2022-07-04 16:14:29 +0300 |
commit | 2fcfa72fc13f0203bb676bd1ec30ec85e17855be (patch) | |
tree | ce95940724ff07c5b90d161b3a21425c4bd609fb /drivers/interconnect/bulk.c | |
parent | e2a4a0eeb0cd308bb96d168f90c225da2084d4dc (diff) | |
download | linux-2fcfa72fc13f0203bb676bd1ec30ec85e17855be.tar.xz |
interconnect: add device managed bulk API
Add device managed bulk API to simplify driver.
Signed-off-by: Peng Fan <peng.fan@nxp.com>
Link: https://lore.kernel.org/r/20220703091132.1412063-4-peng.fan@oss.nxp.com
Signed-off-by: Georgi Djakov <djakov@kernel.org>
Diffstat (limited to 'drivers/interconnect/bulk.c')
-rw-r--r-- | drivers/interconnect/bulk.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/drivers/interconnect/bulk.c b/drivers/interconnect/bulk.c index 448cc536aa79..8b1d8a412464 100644 --- a/drivers/interconnect/bulk.c +++ b/drivers/interconnect/bulk.c @@ -115,3 +115,45 @@ void icc_bulk_disable(int num_paths, const struct icc_bulk_data *paths) icc_disable(paths[num_paths].path); } EXPORT_SYMBOL_GPL(icc_bulk_disable); + +struct icc_bulk_devres { + struct icc_bulk_data *paths; + int num_paths; +}; + +static void devm_icc_bulk_release(struct device *dev, void *res) +{ + struct icc_bulk_devres *devres = res; + + icc_bulk_put(devres->num_paths, devres->paths); +} + +/** + * devm_of_icc_bulk_get() - resource managed of_icc_bulk_get + * @dev: the device requesting the path + * @num_paths: the number of icc_bulk_data + * @paths: the table with the paths we want to get + * + * Returns 0 on success or negative errno otherwise. + */ +int devm_of_icc_bulk_get(struct device *dev, int num_paths, struct icc_bulk_data *paths) +{ + struct icc_bulk_devres *devres; + int ret; + + devres = devres_alloc(devm_icc_bulk_release, sizeof(*devres), GFP_KERNEL); + if (!devres) + return -ENOMEM; + + ret = of_icc_bulk_get(dev, num_paths, paths); + if (!ret) { + devres->paths = paths; + devres->num_paths = num_paths; + devres_add(dev, devres); + } else { + devres_free(devres); + } + + return ret; +} +EXPORT_SYMBOL_GPL(devm_of_icc_bulk_get); |