mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/2] regmap: regmap-irq: Move handle_post_irq to before pm_runtime_put
@ 2023-06-01 10:10 Charles Keepax
  2023-06-01 10:10 ` [PATCH 2/2] regmap: Add missing cache_only checks Charles Keepax
  2023-06-01 13:40 ` [PATCH 1/2] regmap: regmap-irq: Move handle_post_irq to before pm_runtime_put Mark Brown
  0 siblings, 2 replies; 3+ messages in thread
From: Charles Keepax @ 2023-06-01 10:10 UTC (permalink / raw)
  To: broonie; +Cc: gregkh, rafael, patches, linux-kernel

Typically handle_post_irq is going to be used to manage some
additional chip specific hardware operations required on each IRQ,
these are very likely to want the chip to be resumed. For example the
current in tree user max77620 uses this to toggle a global mask bit,
which would obviously want the device resumed. It is worth noting this
device does not specify the runtime_pm flag in regmap_irq_chip, so
there is no actual issue.

Move the callback to before the pm_runtime_put, so it will be called
whilst the device is still resumed.

Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---
 drivers/base/regmap/regmap-irq.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/base/regmap/regmap-irq.c b/drivers/base/regmap/regmap-irq.c
index 330da5d6c8c3a..ced0dcf86e0bf 100644
--- a/drivers/base/regmap/regmap-irq.c
+++ b/drivers/base/regmap/regmap-irq.c
@@ -502,12 +502,12 @@ static irqreturn_t regmap_irq_thread(int irq, void *d)
 	}
 
 exit:
-	if (chip->runtime_pm)
-		pm_runtime_put(map->dev);
-
 	if (chip->handle_post_irq)
 		chip->handle_post_irq(chip->irq_drv_data);
 
+	if (chip->runtime_pm)
+		pm_runtime_put(map->dev);
+
 	if (handled)
 		return IRQ_HANDLED;
 	else
-- 
2.30.2


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

* [PATCH 2/2] regmap: Add missing cache_only checks
  2023-06-01 10:10 [PATCH 1/2] regmap: regmap-irq: Move handle_post_irq to before pm_runtime_put Charles Keepax
@ 2023-06-01 10:10 ` Charles Keepax
  2023-06-01 13:40 ` [PATCH 1/2] regmap: regmap-irq: Move handle_post_irq to before pm_runtime_put Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Charles Keepax @ 2023-06-01 10:10 UTC (permalink / raw)
  To: broonie; +Cc: gregkh, rafael, patches, linux-kernel

The current behaviour around cache_only is slightly inconsistent,
most paths will only check cache_only if cache_bypass is false,
and will return -EBUSY if a read attempts to go to the hardware
whilst cache_only is true. However, a couple of paths will not check
cache_only at all.  The most notable of these being regmap_raw_read
which will check cache_only in the case it processes the transaction
one register at a time, but not in the case it handles them as a
block. In the typical case a device has been put into cache_only
whilst powered down this can cause physical reads to happen whilst the
device is unavailable.

Add a check in regmap_raw_read and move the check in regmap_noinc_read,
adding a check for cache_bypass, such that all paths are covered and
consistent.

Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---
 drivers/base/regmap/regmap.c | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index fa2d3fba6ac9d..627a767fa0470 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -2983,6 +2983,11 @@ int regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
 		size_t chunk_count, chunk_bytes;
 		size_t chunk_regs = val_count;
 
+		if (!map->cache_bypass && map->cache_only) {
+			ret = -EBUSY;
+			goto out;
+		}
+
 		if (!map->read) {
 			ret = -ENOTSUPP;
 			goto out;
@@ -3078,18 +3083,19 @@ int regmap_noinc_read(struct regmap *map, unsigned int reg,
 		goto out_unlock;
 	}
 
+	/*
+	 * We have not defined the FIFO semantics for cache, as the
+	 * cache is just one value deep. Should we return the last
+	 * written value? Just avoid this by always reading the FIFO
+	 * even when using cache. Cache only will not work.
+	 */
+	if (!map->cache_bypass && map->cache_only) {
+		ret = -EBUSY;
+		goto out_unlock;
+	}
+
 	/* Use the accelerated operation if we can */
 	if (map->bus->reg_noinc_read) {
-		/*
-		 * We have not defined the FIFO semantics for cache, as the
-		 * cache is just one value deep. Should we return the last
-		 * written value? Just avoid this by always reading the FIFO
-		 * even when using cache. Cache only will not work.
-		 */
-		if (map->cache_only) {
-			ret = -EBUSY;
-			goto out_unlock;
-		}
 		ret = regmap_noinc_readwrite(map, reg, val, val_len, false);
 		goto out_unlock;
 	}
-- 
2.30.2


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

* Re: [PATCH 1/2] regmap: regmap-irq: Move handle_post_irq to before pm_runtime_put
  2023-06-01 10:10 [PATCH 1/2] regmap: regmap-irq: Move handle_post_irq to before pm_runtime_put Charles Keepax
  2023-06-01 10:10 ` [PATCH 2/2] regmap: Add missing cache_only checks Charles Keepax
@ 2023-06-01 13:40 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2023-06-01 13:40 UTC (permalink / raw)
  To: Charles Keepax; +Cc: gregkh, rafael, patches, linux-kernel

On Thu, 01 Jun 2023 11:10:35 +0100, Charles Keepax wrote:
> Typically handle_post_irq is going to be used to manage some
> additional chip specific hardware operations required on each IRQ,
> these are very likely to want the chip to be resumed. For example the
> current in tree user max77620 uses this to toggle a global mask bit,
> which would obviously want the device resumed. It is worth noting this
> device does not specify the runtime_pm flag in regmap_irq_chip, so
> there is no actual issue.
> 
> [...]

Applied to

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

Thanks!

[1/2] regmap: regmap-irq: Move handle_post_irq to before pm_runtime_put
      commit: 02534c8e967b51940ae7c0cd99befe216f1c2c8d
[2/2] regmap: Add missing cache_only checks
      commit: 99e8dd39f34333d745e6c220be5d166e85214e6c

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] 3+ messages in thread

end of thread, other threads:[~2023-06-01 13:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-01 10:10 [PATCH 1/2] regmap: regmap-irq: Move handle_post_irq to before pm_runtime_put Charles Keepax
2023-06-01 10:10 ` [PATCH 2/2] regmap: Add missing cache_only checks Charles Keepax
2023-06-01 13:40 ` [PATCH 1/2] regmap: regmap-irq: Move handle_post_irq to before pm_runtime_put Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®