Skip to content

Commit

Permalink
clk: Add devm_clk_bulk_get_optional() function
Browse files Browse the repository at this point in the history
Add managed version of the clk_bulk_get_optional() helper function.

Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
[sboyd@kernel.org: Mark __devm_clk_bulk_get() static]
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
  • Loading branch information
Sylwester Nawrocki authored and Stephen Boyd committed Jun 25, 2019
1 parent 2f25528 commit 9bd5ef0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
22 changes: 19 additions & 3 deletions drivers/clk/clk-devres.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ static void devm_clk_bulk_release(struct device *dev, void *res)
clk_bulk_put(devres->num_clks, devres->clks);
}

int __must_check devm_clk_bulk_get(struct device *dev, int num_clks,
struct clk_bulk_data *clks)
static int __devm_clk_bulk_get(struct device *dev, int num_clks,
struct clk_bulk_data *clks, bool optional)
{
struct clk_bulk_devres *devres;
int ret;
Expand All @@ -63,7 +63,10 @@ int __must_check devm_clk_bulk_get(struct device *dev, int num_clks,
if (!devres)
return -ENOMEM;

ret = clk_bulk_get(dev, num_clks, clks);
if (optional)
ret = clk_bulk_get_optional(dev, num_clks, clks);
else
ret = clk_bulk_get(dev, num_clks, clks);
if (!ret) {
devres->clks = clks;
devres->num_clks = num_clks;
Expand All @@ -74,8 +77,21 @@ int __must_check devm_clk_bulk_get(struct device *dev, int num_clks,

return ret;
}

int __must_check devm_clk_bulk_get(struct device *dev, int num_clks,
struct clk_bulk_data *clks)
{
return __devm_clk_bulk_get(dev, num_clks, clks, false);
}
EXPORT_SYMBOL_GPL(devm_clk_bulk_get);

int __must_check devm_clk_bulk_get_optional(struct device *dev, int num_clks,
struct clk_bulk_data *clks)
{
return __devm_clk_bulk_get(dev, num_clks, clks, true);
}
EXPORT_SYMBOL_GPL(devm_clk_bulk_get_optional);

int __must_check devm_clk_bulk_get_all(struct device *dev,
struct clk_bulk_data **clks)
{
Expand Down
28 changes: 28 additions & 0 deletions include/linux/clk.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,28 @@ int __must_check clk_bulk_get_optional(struct device *dev, int num_clks,
*/
int __must_check devm_clk_bulk_get(struct device *dev, int num_clks,
struct clk_bulk_data *clks);
/**
* devm_clk_bulk_get_optional - managed get multiple optional consumer clocks
* @dev: device for clock "consumer"
* @clks: pointer to the clk_bulk_data table of consumer
*
* Behaves the same as devm_clk_bulk_get() except where there is no clock
* producer. In this case, instead of returning -ENOENT, the function returns
* NULL for given clk. It is assumed all clocks in clk_bulk_data are optional.
*
* Returns 0 if all clocks specified in clk_bulk_data table are obtained
* successfully or for any clk there was no clk provider available, otherwise
* returns valid IS_ERR() condition containing errno.
* The implementation uses @dev and @clk_bulk_data.id to determine the
* clock consumer, and thereby the clock producer.
* The clock returned is stored in each @clk_bulk_data.clk field.
*
* Drivers must assume that the clock source is not enabled.
*
* clk_bulk_get should not be called from within interrupt context.
*/
int __must_check devm_clk_bulk_get_optional(struct device *dev, int num_clks,
struct clk_bulk_data *clks);
/**
* devm_clk_bulk_get_all - managed get multiple clk consumers
* @dev: device for clock "consumer"
Expand Down Expand Up @@ -760,6 +782,12 @@ static inline int __must_check devm_clk_bulk_get(struct device *dev, int num_clk
return 0;
}

static inline int __must_check devm_clk_bulk_get_optional(struct device *dev,
int num_clks, struct clk_bulk_data *clks)
{
return 0;
}

static inline int __must_check devm_clk_bulk_get_all(struct device *dev,
struct clk_bulk_data **clks)
{
Expand Down

0 comments on commit 9bd5ef0

Please sign in to comment.