2017-09-01 23:16:46

by Stephen Boyd

[permalink] [raw]
Subject: [PATCH 0/2] Add a devm_of_clk_add_hw_provider() API

This cleans up some open-coded versions of this API and makes it official.
It's also another carrot to convert drivers to use the clk hw registration
APIs instead of the clk registration APIs.

Stephen Boyd (2):
clk: Add devm_of_clk_add_hw_provider()/del_provider() APIs
clk: qcom: common: Migrate to devm_* APIs for resets and clk providers

Documentation/driver-model/devres.txt | 1 +
drivers/clk/clk.c | 52 +++++++++++++++++++++++++++++++++++
drivers/clk/qcom/common.c | 26 ++----------------
include/linux/clk-provider.h | 13 +++++++++
4 files changed, 68 insertions(+), 24 deletions(-)

--
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


2017-09-01 23:16:48

by Stephen Boyd

[permalink] [raw]
Subject: [PATCH 2/2] clk: qcom: common: Migrate to devm_* APIs for resets and clk providers

Now that we have devm APIs for the reset controller and of clk hw
provider APIs we can remove the custom code here.

Signed-off-by: Stephen Boyd <[email protected]>
---
drivers/clk/qcom/common.c | 26 ++------------------------
1 file changed, 2 insertions(+), 24 deletions(-)

diff --git a/drivers/clk/qcom/common.c b/drivers/clk/qcom/common.c
index d523991c945f..b35564c0493f 100644
--- a/drivers/clk/qcom/common.c
+++ b/drivers/clk/qcom/common.c
@@ -111,16 +111,6 @@ qcom_pll_set_fsm_mode(struct regmap *map, u32 reg, u8 bias_count, u8 lock_count)
}
EXPORT_SYMBOL_GPL(qcom_pll_set_fsm_mode);

-static void qcom_cc_del_clk_provider(void *data)
-{
- of_clk_del_provider(data);
-}
-
-static void qcom_cc_reset_unregister(void *data)
-{
- reset_controller_unregister(data);
-}
-
static void qcom_cc_gdsc_unregister(void *data)
{
gdsc_unregister(data);
@@ -248,13 +238,7 @@ int qcom_cc_really_probe(struct platform_device *pdev,
return ret;
}

- ret = of_clk_add_hw_provider(dev->of_node, qcom_cc_clk_hw_get, cc);
- if (ret)
- return ret;
-
- ret = devm_add_action_or_reset(dev, qcom_cc_del_clk_provider,
- pdev->dev.of_node);
-
+ ret = devm_of_clk_add_hw_provider(dev, qcom_cc_clk_hw_get, cc);
if (ret)
return ret;

@@ -266,13 +250,7 @@ int qcom_cc_really_probe(struct platform_device *pdev,
reset->regmap = regmap;
reset->reset_map = desc->resets;

- ret = reset_controller_register(&reset->rcdev);
- if (ret)
- return ret;
-
- ret = devm_add_action_or_reset(dev, qcom_cc_reset_unregister,
- &reset->rcdev);
-
+ ret = devm_reset_controller_register(dev, &reset->rcdev);
if (ret)
return ret;

--
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

2017-09-01 23:16:47

by Stephen Boyd

[permalink] [raw]
Subject: [PATCH 1/2] clk: Add devm_of_clk_add_hw_provider()/del_provider() APIs

Sometimes we only have one of_clk_del_provider() call in driver
error and remove paths, because we're missing a
devm_of_clk_add_hw_provider() API. Introduce the API so we can
convert drivers to use this and potentially reduce the amount of
code needed to remove providers in drivers.

Signed-off-by: Stephen Boyd <[email protected]>
---
Documentation/driver-model/devres.txt | 1 +
drivers/clk/clk.c | 52 +++++++++++++++++++++++++++++++++++
include/linux/clk-provider.h | 13 +++++++++
3 files changed, 66 insertions(+)

diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt
index 30e04f7a690d..6b5e5e642b49 100644
--- a/Documentation/driver-model/devres.txt
+++ b/Documentation/driver-model/devres.txt
@@ -237,6 +237,7 @@ CLOCK
devm_clk_get()
devm_clk_put()
devm_clk_hw_register()
+ devm_of_clk_add_hw_provider()

DMA
dmam_alloc_coherent()
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index c8d83acda006..d50398a79cbc 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -3177,6 +3177,37 @@ int of_clk_add_hw_provider(struct device_node *np,
}
EXPORT_SYMBOL_GPL(of_clk_add_hw_provider);

+static void devm_of_clk_release_provider(struct device *dev, void *res)
+{
+ of_clk_del_provider(*(struct device_node **)res);
+}
+
+int devm_of_clk_add_hw_provider(struct device *dev,
+ struct clk_hw *(*get)(struct of_phandle_args *clkspec,
+ void *data),
+ void *data)
+{
+ struct device_node **ptr, *np;
+ int ret;
+
+ ptr = devres_alloc(devm_of_clk_release_provider, sizeof(*ptr),
+ GFP_KERNEL);
+ if (!ptr)
+ return -ENOMEM;
+
+ np = dev->of_node;
+ ret = of_clk_add_hw_provider(np, get, data);
+ if (!ret) {
+ *ptr = np;
+ devres_add(dev, ptr);
+ } else {
+ devres_free(ptr);
+ }
+
+ return ret;;
+}
+EXPORT_SYMBOL_GPL(devm_of_clk_add_hw_provider);
+
/**
* of_clk_del_provider() - Remove a previously registered clock provider
* @np: Device node pointer associated with clock provider
@@ -3198,6 +3229,27 @@ void of_clk_del_provider(struct device_node *np)
}
EXPORT_SYMBOL_GPL(of_clk_del_provider);

+static int devm_clk_provider_match(struct device *dev, void *res, void *data)
+{
+ struct device_node **np = res;
+
+ if (WARN_ON(!np || !*np))
+ return 0;
+
+ return *np == data;
+}
+
+void devm_of_clk_del_provider(struct device *dev)
+{
+ int ret;
+
+ ret = devres_release(dev, devm_of_clk_release_provider,
+ devm_clk_provider_match, dev->of_node);
+
+ WARN_ON(ret);
+}
+EXPORT_SYMBOL(devm_of_clk_del_provider);
+
static struct clk_hw *
__of_clk_get_hw_from_provider(struct of_clk_provider *provider,
struct of_phandle_args *clkspec)
diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
index 1fc113fbf955..5a002e64999b 100644
--- a/include/linux/clk-provider.h
+++ b/include/linux/clk-provider.h
@@ -814,7 +814,12 @@ int of_clk_add_hw_provider(struct device_node *np,
struct clk_hw *(*get)(struct of_phandle_args *clkspec,
void *data),
void *data);
+int devm_of_clk_add_hw_provider(struct device *dev,
+ struct clk_hw *(*get)(struct of_phandle_args *clkspec,
+ void *data),
+ void *data);
void of_clk_del_provider(struct device_node *np);
+void devm_of_clk_del_provider(struct device *dev);
struct clk *of_clk_src_simple_get(struct of_phandle_args *clkspec,
void *data);
struct clk_hw *of_clk_hw_simple_get(struct of_phandle_args *clkspec,
@@ -846,7 +851,15 @@ static inline int of_clk_add_hw_provider(struct device_node *np,
{
return 0;
}
+static inline int devm_of_clk_add_hw_provider(struct device *dev,
+ struct clk_hw *(*get)(struct of_phandle_args *clkspec,
+ void *data),
+ void *data)
+{
+ return 0;
+}
static inline void of_clk_del_provider(struct device_node *np) {}
+static inline void devm_of_clk_del_provider(struct device *dev) {}
static inline struct clk *of_clk_src_simple_get(
struct of_phandle_args *clkspec, void *data)
{
--
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

2017-11-02 06:40:32

by Stephen Boyd

[permalink] [raw]
Subject: Re: [PATCH 2/2] clk: qcom: common: Migrate to devm_* APIs for resets and clk providers

On 09/01, Stephen Boyd wrote:
> Now that we have devm APIs for the reset controller and of clk hw
> provider APIs we can remove the custom code here.
>
> Signed-off-by: Stephen Boyd <[email protected]>
> ---

Applied to clk-next

--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

From 1577381136398024633@xxx Fri Sep 01 23:17:56 +0000 2017
X-GM-THRID: 1577381136398024633
X-Gmail-Labels: Inbox,Category Forums

2017-11-02 06:40:30

by Stephen Boyd

[permalink] [raw]
Subject: Re: [PATCH 1/2] clk: Add devm_of_clk_add_hw_provider()/del_provider() APIs

On 09/01, Stephen Boyd wrote:
> Sometimes we only have one of_clk_del_provider() call in driver
> error and remove paths, because we're missing a
> devm_of_clk_add_hw_provider() API. Introduce the API so we can
> convert drivers to use this and potentially reduce the amount of
> code needed to remove providers in drivers.
>
> Signed-off-by: Stephen Boyd <[email protected]>
> ---

Applied to clk-next

--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

From 1577381144785993626@xxx Fri Sep 01 23:18:04 +0000 2017
X-GM-THRID: 1577381144785993626
X-Gmail-Labels: Inbox,Category Forums