linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] regmap: Add can_sleep configuration option
@ 2020-09-02 14:18 ` Dmitry Osipenko
  2020-09-02 14:53   ` Marek Szyprowski
  2020-09-02 18:54   ` Mark Brown
  0 siblings, 2 replies; 4+ messages in thread
From: Dmitry Osipenko @ 2020-09-02 14:18 UTC (permalink / raw)
  To: Marek Szyprowski, Mark Brown; +Cc: linux-kernel

Regmap can't sleep if spinlock is used for the locking protection.
This patch fixes regression caused by a previous commit that switched
regmap to use fsleep() and this broke Amlogic S922X platform.

This patch adds new configuration option for regmap users, allowing to
specify whether regmap operations can sleep and assuming that sleep is
allowed if mutex is used for the regmap locking protection.

Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
Fixes: 2b32d2f7ce0a ("regmap: Use flexible sleep")
Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/base/regmap/internal.h |  3 +++
 drivers/base/regmap/regmap.c   | 19 +++++++++++++++----
 include/linux/regmap.h         |  3 +++
 3 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/drivers/base/regmap/internal.h b/drivers/base/regmap/internal.h
index 3d80c4b43f72..8a59359e145f 100644
--- a/drivers/base/regmap/internal.h
+++ b/drivers/base/regmap/internal.h
@@ -161,6 +161,9 @@ struct regmap {
 	void *selector_work_buf;	/* Scratch buffer used for selector */
 
 	struct hwspinlock *hwlock;
+
+	/* if set, the regmap core can sleep */
+	bool can_sleep;
 };
 
 struct regcache_ops {
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index a417cb1a11dc..2807e544658e 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -697,11 +697,13 @@ struct regmap *__regmap_init(struct device *dev,
 
 	if (config->disable_locking) {
 		map->lock = map->unlock = regmap_lock_unlock_none;
+		map->can_sleep = config->can_sleep;
 		regmap_debugfs_disable(map);
 	} else if (config->lock && config->unlock) {
 		map->lock = config->lock;
 		map->unlock = config->unlock;
 		map->lock_arg = config->lock_arg;
+		map->can_sleep = config->can_sleep;
 	} else if (config->use_hwlock) {
 		map->hwlock = hwspin_lock_request_specific(config->hwlock_id);
 		if (!map->hwlock) {
@@ -737,6 +739,7 @@ struct regmap *__regmap_init(struct device *dev,
 			mutex_init(&map->mutex);
 			map->lock = regmap_lock_mutex;
 			map->unlock = regmap_unlock_mutex;
+			map->can_sleep = true;
 			lockdep_set_class_and_name(&map->mutex,
 						   lock_key, lock_name);
 		}
@@ -2230,8 +2233,12 @@ static int _regmap_range_multi_paged_reg_write(struct regmap *map,
 				if (ret != 0)
 					return ret;
 
-				if (regs[i].delay_us)
-					fsleep(regs[i].delay_us);
+				if (regs[i].delay_us) {
+					if (map->can_sleep)
+						fsleep(regs[i].delay_us);
+					else
+						udelay(regs[i].delay_us);
+				}
 
 				base += n;
 				n = 0;
@@ -2267,8 +2274,12 @@ static int _regmap_multi_reg_write(struct regmap *map,
 			if (ret != 0)
 				return ret;
 
-			if (regs[i].delay_us)
-				fsleep(regs[i].delay_us);
+			if (regs[i].delay_us) {
+				if (map->can_sleep)
+					fsleep(regs[i].delay_us);
+				else
+					udelay(regs[i].delay_us);
+			}
 		}
 		return 0;
 	}
diff --git a/include/linux/regmap.h b/include/linux/regmap.h
index d865d8fea535..0c49d59168b5 100644
--- a/include/linux/regmap.h
+++ b/include/linux/regmap.h
@@ -342,6 +342,7 @@ typedef void (*regmap_unlock)(void *);
  * @hwlock_id: Specify the hardware spinlock id.
  * @hwlock_mode: The hardware spinlock mode, should be HWLOCK_IRQSTATE,
  *		 HWLOCK_IRQ or 0.
+ * @can_sleep: Optional, specifies whether regmap operations can sleep.
  */
 struct regmap_config {
 	const char *name;
@@ -398,6 +399,8 @@ struct regmap_config {
 	bool use_hwlock;
 	unsigned int hwlock_id;
 	unsigned int hwlock_mode;
+
+	bool can_sleep;
 };
 
 /**
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v1] regmap: Add can_sleep configuration option
  2020-09-02 14:18 ` [PATCH v1] regmap: Add can_sleep configuration option Dmitry Osipenko
@ 2020-09-02 14:53   ` Marek Szyprowski
  2020-09-02 15:04     ` Dmitry Osipenko
  2020-09-02 18:54   ` Mark Brown
  1 sibling, 1 reply; 4+ messages in thread
From: Marek Szyprowski @ 2020-09-02 14:53 UTC (permalink / raw)
  To: Dmitry Osipenko, Mark Brown; +Cc: linux-kernel

Hi Dmitry,

On 02.09.2020 16:18, Dmitry Osipenko wrote:
> Regmap can't sleep if spinlock is used for the locking protection.
> This patch fixes regression caused by a previous commit that switched
> regmap to use fsleep() and this broke Amlogic S922X platform.
>
> This patch adds new configuration option for regmap users, allowing to
> specify whether regmap operations can sleep and assuming that sleep is
> allowed if mutex is used for the regmap locking protection.
>
> Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
> Fixes: 2b32d2f7ce0a ("regmap: Use flexible sleep")
> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>

This fixes the issue I've reported. Thanks!

Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>

> ---
>   drivers/base/regmap/internal.h |  3 +++
>   drivers/base/regmap/regmap.c   | 19 +++++++++++++++----
>   include/linux/regmap.h         |  3 +++
>   3 files changed, 21 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/base/regmap/internal.h b/drivers/base/regmap/internal.h
> index 3d80c4b43f72..8a59359e145f 100644
> --- a/drivers/base/regmap/internal.h
> +++ b/drivers/base/regmap/internal.h
> @@ -161,6 +161,9 @@ struct regmap {
>   	void *selector_work_buf;	/* Scratch buffer used for selector */
>   
>   	struct hwspinlock *hwlock;
> +
> +	/* if set, the regmap core can sleep */
> +	bool can_sleep;
>   };
>   
>   struct regcache_ops {
> diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
> index a417cb1a11dc..2807e544658e 100644
> --- a/drivers/base/regmap/regmap.c
> +++ b/drivers/base/regmap/regmap.c
> @@ -697,11 +697,13 @@ struct regmap *__regmap_init(struct device *dev,
>   
>   	if (config->disable_locking) {
>   		map->lock = map->unlock = regmap_lock_unlock_none;
> +		map->can_sleep = config->can_sleep;
>   		regmap_debugfs_disable(map);
>   	} else if (config->lock && config->unlock) {
>   		map->lock = config->lock;
>   		map->unlock = config->unlock;
>   		map->lock_arg = config->lock_arg;
> +		map->can_sleep = config->can_sleep;
>   	} else if (config->use_hwlock) {
>   		map->hwlock = hwspin_lock_request_specific(config->hwlock_id);
>   		if (!map->hwlock) {
> @@ -737,6 +739,7 @@ struct regmap *__regmap_init(struct device *dev,
>   			mutex_init(&map->mutex);
>   			map->lock = regmap_lock_mutex;
>   			map->unlock = regmap_unlock_mutex;
> +			map->can_sleep = true;
>   			lockdep_set_class_and_name(&map->mutex,
>   						   lock_key, lock_name);
>   		}
> @@ -2230,8 +2233,12 @@ static int _regmap_range_multi_paged_reg_write(struct regmap *map,
>   				if (ret != 0)
>   					return ret;
>   
> -				if (regs[i].delay_us)
> -					fsleep(regs[i].delay_us);
> +				if (regs[i].delay_us) {
> +					if (map->can_sleep)
> +						fsleep(regs[i].delay_us);
> +					else
> +						udelay(regs[i].delay_us);
> +				}
>   
>   				base += n;
>   				n = 0;
> @@ -2267,8 +2274,12 @@ static int _regmap_multi_reg_write(struct regmap *map,
>   			if (ret != 0)
>   				return ret;
>   
> -			if (regs[i].delay_us)
> -				fsleep(regs[i].delay_us);
> +			if (regs[i].delay_us) {
> +				if (map->can_sleep)
> +					fsleep(regs[i].delay_us);
> +				else
> +					udelay(regs[i].delay_us);
> +			}
>   		}
>   		return 0;
>   	}
> diff --git a/include/linux/regmap.h b/include/linux/regmap.h
> index d865d8fea535..0c49d59168b5 100644
> --- a/include/linux/regmap.h
> +++ b/include/linux/regmap.h
> @@ -342,6 +342,7 @@ typedef void (*regmap_unlock)(void *);
>    * @hwlock_id: Specify the hardware spinlock id.
>    * @hwlock_mode: The hardware spinlock mode, should be HWLOCK_IRQSTATE,
>    *		 HWLOCK_IRQ or 0.
> + * @can_sleep: Optional, specifies whether regmap operations can sleep.
>    */
>   struct regmap_config {
>   	const char *name;
> @@ -398,6 +399,8 @@ struct regmap_config {
>   	bool use_hwlock;
>   	unsigned int hwlock_id;
>   	unsigned int hwlock_mode;
> +
> +	bool can_sleep;
>   };
>   
>   /**

Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v1] regmap: Add can_sleep configuration option
  2020-09-02 14:53   ` Marek Szyprowski
@ 2020-09-02 15:04     ` Dmitry Osipenko
  0 siblings, 0 replies; 4+ messages in thread
From: Dmitry Osipenko @ 2020-09-02 15:04 UTC (permalink / raw)
  To: Marek Szyprowski, Mark Brown; +Cc: linux-kernel

02.09.2020 17:53, Marek Szyprowski пишет:
> Hi Dmitry,
> 
> On 02.09.2020 16:18, Dmitry Osipenko wrote:
>> Regmap can't sleep if spinlock is used for the locking protection.
>> This patch fixes regression caused by a previous commit that switched
>> regmap to use fsleep() and this broke Amlogic S922X platform.
>>
>> This patch adds new configuration option for regmap users, allowing to
>> specify whether regmap operations can sleep and assuming that sleep is
>> allowed if mutex is used for the regmap locking protection.
>>
>> Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
>> Fixes: 2b32d2f7ce0a ("regmap: Use flexible sleep")
>> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
> 
> This fixes the issue I've reported. Thanks!
> 
> Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>

Awesome! Thank you!

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v1] regmap: Add can_sleep configuration option
  2020-09-02 14:18 ` [PATCH v1] regmap: Add can_sleep configuration option Dmitry Osipenko
  2020-09-02 14:53   ` Marek Szyprowski
@ 2020-09-02 18:54   ` Mark Brown
  1 sibling, 0 replies; 4+ messages in thread
From: Mark Brown @ 2020-09-02 18:54 UTC (permalink / raw)
  To: Marek Szyprowski, Dmitry Osipenko; +Cc: linux-kernel

On Wed, 2 Sep 2020 17:18:43 +0300, Dmitry Osipenko wrote:
> Regmap can't sleep if spinlock is used for the locking protection.
> This patch fixes regression caused by a previous commit that switched
> regmap to use fsleep() and this broke Amlogic S922X platform.
> 
> This patch adds new configuration option for regmap users, allowing to
> specify whether regmap operations can sleep and assuming that sleep is
> allowed if mutex is used for the regmap locking protection.

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git for-next

Thanks!

[1/1] regmap: Add can_sleep configuration option
      commit: 21f8e4828c44da39b0670c5d99d5728b739542a1

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-09-02 18:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20200902142057eucas1p245e94459d5adcd9cc4c38617da1abfc8@eucas1p2.samsung.com>
2020-09-02 14:18 ` [PATCH v1] regmap: Add can_sleep configuration option Dmitry Osipenko
2020-09-02 14:53   ` Marek Szyprowski
2020-09-02 15:04     ` Dmitry Osipenko
2020-09-02 18:54   ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).