diff mbox series

[1/8] hwspinlock: Add one new API to support getting a specific hwlock by the name

Message ID c23ed23d6d355e80401abce6242523f32ce480fd.1529654288.git.baolin.wang@linaro.org
State Accepted
Commit 5560f70cad996e7d90d1c141bcbca0df214eefc9
Headers show
Series [1/8] hwspinlock: Add one new API to support getting a specific hwlock by the name | expand

Commit Message

(Exiting) Baolin Wang June 22, 2018, 8:08 a.m. UTC
The hardware spinlock binding already supplied the 'hwlock-names' property
to match and get a specific hwlock, but did not supply one API for users
to get a specific hwlock by the hwlock name. So this patch introduces one
API to support this requirement.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>

---
 drivers/hwspinlock/hwspinlock_core.c |   29 +++++++++++++++++++++++++++++
 include/linux/hwspinlock.h           |    7 +++++++
 2 files changed, 36 insertions(+)

-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Bjorn Andersson June 26, 2018, 8:51 p.m. UTC | #1
On Fri 22 Jun 01:09 PDT 2018, Baolin Wang wrote:

> Use devm_hwspin_lock_register() to register the hwlock controller to

> avoid unregistering the device explicitly.

> 

> Signed-off-by: Baolin Wang <baolin.wang@linaro.org>

> ---

>  drivers/hwspinlock/sprd_hwspinlock.c |    6 +++---

>  1 file changed, 3 insertions(+), 3 deletions(-)

> 

> diff --git a/drivers/hwspinlock/sprd_hwspinlock.c b/drivers/hwspinlock/sprd_hwspinlock.c

> index dc42bf5..ba5daf6 100644

> --- a/drivers/hwspinlock/sprd_hwspinlock.c

> +++ b/drivers/hwspinlock/sprd_hwspinlock.c

> @@ -120,8 +120,9 @@ static int sprd_hwspinlock_probe(struct platform_device *pdev)

>  	platform_set_drvdata(pdev, sprd_hwlock);

>  	pm_runtime_enable(&pdev->dev);

>  

> -	ret = hwspin_lock_register(&sprd_hwlock->bank, &pdev->dev,

> -				   &sprd_hwspinlock_ops, 0, SPRD_HWLOCKS_NUM);

> +	ret = devm_hwspin_lock_register(&pdev->dev, &sprd_hwlock->bank,

> +					&sprd_hwspinlock_ops, 0,

> +					SPRD_HWLOCKS_NUM);

>  	if (ret) {

>  		pm_runtime_disable(&pdev->dev);

>  		clk_disable_unprepare(sprd_hwlock->clk);

> @@ -135,7 +136,6 @@ static int sprd_hwspinlock_remove(struct platform_device *pdev)

>  {

>  	struct sprd_hwspinlock_dev *sprd_hwlock = platform_get_drvdata(pdev);

>  

> -	hwspin_lock_unregister(&sprd_hwlock->bank);


Until the hwspinlock is unregistered it's possible for clients to issue
operations on it, so disabling power and clocks before that seems bad.

Regards,
Bjorn

>  	pm_runtime_disable(&pdev->dev);

>  	clk_disable_unprepare(sprd_hwlock->clk);

>  	return 0;

> -- 

> 1.7.9.5

> 

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
(Exiting) Baolin Wang June 27, 2018, 2:17 a.m. UTC | #2
On 27 June 2018 at 04:51, Bjorn Andersson <bjorn.andersson@linaro.org> wrote:
> On Fri 22 Jun 01:09 PDT 2018, Baolin Wang wrote:

>

>> Use devm_hwspin_lock_register() to register the hwlock controller to

>> avoid unregistering the device explicitly.

>>

>> Signed-off-by: Baolin Wang <baolin.wang@linaro.org>

>> ---

>>  drivers/hwspinlock/sprd_hwspinlock.c |    6 +++---

>>  1 file changed, 3 insertions(+), 3 deletions(-)

>>

>> diff --git a/drivers/hwspinlock/sprd_hwspinlock.c b/drivers/hwspinlock/sprd_hwspinlock.c

>> index dc42bf5..ba5daf6 100644

>> --- a/drivers/hwspinlock/sprd_hwspinlock.c

>> +++ b/drivers/hwspinlock/sprd_hwspinlock.c

>> @@ -120,8 +120,9 @@ static int sprd_hwspinlock_probe(struct platform_device *pdev)

>>       platform_set_drvdata(pdev, sprd_hwlock);

>>       pm_runtime_enable(&pdev->dev);

>>

>> -     ret = hwspin_lock_register(&sprd_hwlock->bank, &pdev->dev,

>> -                                &sprd_hwspinlock_ops, 0, SPRD_HWLOCKS_NUM);

>> +     ret = devm_hwspin_lock_register(&pdev->dev, &sprd_hwlock->bank,

>> +                                     &sprd_hwspinlock_ops, 0,

>> +                                     SPRD_HWLOCKS_NUM);

>>       if (ret) {

>>               pm_runtime_disable(&pdev->dev);

>>               clk_disable_unprepare(sprd_hwlock->clk);

>> @@ -135,7 +136,6 @@ static int sprd_hwspinlock_remove(struct platform_device *pdev)

>>  {

>>       struct sprd_hwspinlock_dev *sprd_hwlock = platform_get_drvdata(pdev);

>>

>> -     hwspin_lock_unregister(&sprd_hwlock->bank);

>

> Until the hwspinlock is unregistered it's possible for clients to issue

> operations on it, so disabling power and clocks before that seems bad.


Yes, you are right. So may be register some additional actions with devm
core to call the clock disable as appropriate. Thanks.

-- 
Baolin.wang
Best Regards
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
(Exiting) Baolin Wang June 27, 2018, 2:18 a.m. UTC | #3
On 27 June 2018 at 04:54, Bjorn Andersson <bjorn.andersson@linaro.org> wrote:
> On Fri 22 Jun 01:08 PDT 2018, Baolin Wang wrote:

>

>> The hardware spinlock binding already supplied the 'hwlock-names' property

>> to match and get a specific hwlock, but did not supply one API for users

>> to get a specific hwlock by the hwlock name. So this patch introduces one

>> API to support this requirement.

>>

>> Signed-off-by: Baolin Wang <baolin.wang@linaro.org>

>

> Thanks Baolin,

>

> Picked up all but patch 6 from the series; including 7 and 8 with Mark's

> ack.


OK. Thanks Bjorn and Mark.

-- 
Baolin.wang
Best Regards
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox series

Patch

diff --git a/drivers/hwspinlock/hwspinlock_core.c b/drivers/hwspinlock/hwspinlock_core.c
index d16e6a3..bea3586 100644
--- a/drivers/hwspinlock/hwspinlock_core.c
+++ b/drivers/hwspinlock/hwspinlock_core.c
@@ -367,6 +367,35 @@  int of_hwspin_lock_get_id(struct device_node *np, int index)
 }
 EXPORT_SYMBOL_GPL(of_hwspin_lock_get_id);
 
+/**
+ * of_hwspin_lock_get_id_byname() - get lock id for an specified hwlock name
+ * @np: device node from which to request the specific hwlock
+ * @name: hwlock name
+ *
+ * This function provides a means for DT users of the hwspinlock module to
+ * get the global lock id of a specific hwspinlock using the specified name of
+ * the hwspinlock device, so that it can be requested using the normal
+ * hwspin_lock_request_specific() API.
+ *
+ * Returns the global lock id number on success, -EPROBE_DEFER if the hwspinlock
+ * device is not yet registered, -EINVAL on invalid args specifier value or an
+ * appropriate error as returned from the OF parsing of the DT client node.
+ */
+int of_hwspin_lock_get_id_byname(struct device_node *np, const char *name)
+{
+	int index;
+
+	if (!name)
+		return -EINVAL;
+
+	index = of_property_match_string(np, "hwlock-names", name);
+	if (index < 0)
+		return index;
+
+	return of_hwspin_lock_get_id(np, index);
+}
+EXPORT_SYMBOL_GPL(of_hwspin_lock_get_id_byname);
+
 static int hwspin_lock_register_single(struct hwspinlock *hwlock, int id)
 {
 	struct hwspinlock *tmp;
diff --git a/include/linux/hwspinlock.h b/include/linux/hwspinlock.h
index 57537e6..2b6f389 100644
--- a/include/linux/hwspinlock.h
+++ b/include/linux/hwspinlock.h
@@ -66,6 +66,7 @@  int __hwspin_lock_timeout(struct hwspinlock *, unsigned int, int,
 							unsigned long *);
 int __hwspin_trylock(struct hwspinlock *, int, unsigned long *);
 void __hwspin_unlock(struct hwspinlock *, int, unsigned long *);
+int of_hwspin_lock_get_id_byname(struct device_node *np, const char *name);
 
 #else /* !CONFIG_HWSPINLOCK */
 
@@ -125,6 +126,12 @@  static inline int hwspin_lock_get_id(struct hwspinlock *hwlock)
 	return 0;
 }
 
+static inline
+int of_hwspin_lock_get_id_byname(struct device_node *np, const char *name)
+{
+	return 0;
+}
+
 #endif /* !CONFIG_HWSPINLOCK */
 
 /**