linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] regmap: regmap-irq: Remove default irq type setting from core
@ 2018-12-18 10:58 Matti Vaittinen
  2018-12-18 13:08 ` Bartosz Golaszewski
  0 siblings, 1 reply; 3+ messages in thread
From: Matti Vaittinen @ 2018-12-18 10:58 UTC (permalink / raw)
  To: matti.vaittinen, mazziesaccount
  Cc: broonie, gregkh, rafael, ldewangan, linux-kernel

The common code should not set IRQ type. Read HW defaults to the
cache at startup instead of forcing type to EDGE_BOTH. If
default setting is needed this should be done via normal
mechanisms or by chip specific code if normal mechanisms are not
suitable for some reason. Common regmap-irq code should not have
defaults hard-coded but keep the HW/boot defaults untouched.

Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
---
So let's try removing the hard-coded default setting from generic
regmap-irq code as discussed with Mark here:
https://lore.kernel.org/lkml/20181217180722.GG27909@sirena.org.uk/

Core code should not care about the default trigger level - such
settings should be done by code which knows the target
platform/board.

I was not able to test this change as I have no max77620 which seems to
be the only user of regmap-irq type-setting in tree as of now.

The patch was created on top of the regulator-next tree, with
"regmap: irq: handle HW using separate rising/falling edge interrupts"
from Bartosz Golaszewski cherry-picked. This should still cleanly apply
on regmap-tree.

 drivers/base/regmap/regmap-irq.c | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/drivers/base/regmap/regmap-irq.c b/drivers/base/regmap/regmap-irq.c
index 603b1554f81c..8b216b2e2c19 100644
--- a/drivers/base/regmap/regmap-irq.c
+++ b/drivers/base/regmap/regmap-irq.c
@@ -625,26 +625,20 @@ int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
 	}
 
 	if (chip->num_type_reg && !chip->type_in_mask) {
-		for (i = 0; i < chip->num_irqs; i++) {
-			reg = chip->irqs[i].type_reg_offset / map->reg_stride;
-			d->type_buf_def[reg] |= chip->irqs[i].type_rising_mask |
-					chip->irqs[i].type_falling_mask;
-		}
 		for (i = 0; i < chip->num_type_reg; ++i) {
 			if (!d->type_buf_def[i])
 				continue;
 
 			reg = chip->type_base +
 				(i * map->reg_stride * d->type_reg_stride);
-			if (chip->type_invert)
-				ret = regmap_irq_update_bits(d, reg,
-					d->type_buf_def[i], 0xFF);
-			else
-				ret = regmap_irq_update_bits(d, reg,
-					d->type_buf_def[i], 0x0);
-			if (ret != 0) {
-				dev_err(map->dev,
-					"Failed to set type in 0x%x: %x\n",
+
+			ret = regmap_read(map, reg, &d->type_buf_def[i]);
+
+			if (d->chip->type_invert)
+				d->type_buf_def[i] = ~d->type_buf_def[i];
+
+			if (ret) {
+				dev_err(map->dev, "Failed to get type defaults at 0x%x: %d\n",
 					reg, ret);
 				goto err_alloc;
 			}
-- 
2.14.3


-- 
Matti Vaittinen
ROHM Semiconductors

~~~ "I don't think so," said Rene Descartes.  Just then, he vanished ~~~

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

* Re: [PATCH] regmap: regmap-irq: Remove default irq type setting from core
  2018-12-18 10:58 [PATCH] regmap: regmap-irq: Remove default irq type setting from core Matti Vaittinen
@ 2018-12-18 13:08 ` Bartosz Golaszewski
  2018-12-18 13:15   ` Matti Vaittinen
  0 siblings, 1 reply; 3+ messages in thread
From: Bartosz Golaszewski @ 2018-12-18 13:08 UTC (permalink / raw)
  To: Matti Vaittinen
  Cc: mazziesaccount, Mark Brown, Greg Kroah-Hartman,
	Rafael J . Wysocki, ldewangan, Linux Kernel Mailing List

wt., 18 gru 2018 o 11:58 Matti Vaittinen
<matti.vaittinen@fi.rohmeurope.com> napisał(a):
>
> The common code should not set IRQ type. Read HW defaults to the
> cache at startup instead of forcing type to EDGE_BOTH. If
> default setting is needed this should be done via normal
> mechanisms or by chip specific code if normal mechanisms are not
> suitable for some reason. Common regmap-irq code should not have
> defaults hard-coded but keep the HW/boot defaults untouched.
>
> Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
> ---
> So let's try removing the hard-coded default setting from generic
> regmap-irq code as discussed with Mark here:
> https://lore.kernel.org/lkml/20181217180722.GG27909@sirena.org.uk/
>
> Core code should not care about the default trigger level - such
> settings should be done by code which knows the target
> platform/board.
>
> I was not able to test this change as I have no max77620 which seems to
> be the only user of regmap-irq type-setting in tree as of now.
>
> The patch was created on top of the regulator-next tree, with
> "regmap: irq: handle HW using separate rising/falling edge interrupts"
> from Bartosz Golaszewski cherry-picked. This should still cleanly apply
> on regmap-tree.
>
>  drivers/base/regmap/regmap-irq.c | 22 ++++++++--------------
>  1 file changed, 8 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/base/regmap/regmap-irq.c b/drivers/base/regmap/regmap-irq.c
> index 603b1554f81c..8b216b2e2c19 100644
> --- a/drivers/base/regmap/regmap-irq.c
> +++ b/drivers/base/regmap/regmap-irq.c
> @@ -625,26 +625,20 @@ int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
>         }
>
>         if (chip->num_type_reg && !chip->type_in_mask) {
> -               for (i = 0; i < chip->num_irqs; i++) {
> -                       reg = chip->irqs[i].type_reg_offset / map->reg_stride;
> -                       d->type_buf_def[reg] |= chip->irqs[i].type_rising_mask |
> -                                       chip->irqs[i].type_falling_mask;
> -               }
>                 for (i = 0; i < chip->num_type_reg; ++i) {
>                         if (!d->type_buf_def[i])
>                                 continue;
>
>                         reg = chip->type_base +
>                                 (i * map->reg_stride * d->type_reg_stride);
> -                       if (chip->type_invert)
> -                               ret = regmap_irq_update_bits(d, reg,
> -                                       d->type_buf_def[i], 0xFF);
> -                       else
> -                               ret = regmap_irq_update_bits(d, reg,
> -                                       d->type_buf_def[i], 0x0);
> -                       if (ret != 0) {
> -                               dev_err(map->dev,
> -                                       "Failed to set type in 0x%x: %x\n",
> +
> +                       ret = regmap_read(map, reg, &d->type_buf_def[i]);
> +
> +                       if (d->chip->type_invert)
> +                               d->type_buf_def[i] = ~d->type_buf_def[i];
> +
> +                       if (ret) {
> +                               dev_err(map->dev, "Failed to get type defaults at 0x%x: %d\n",
>                                         reg, ret);
>                                 goto err_alloc;
>                         }
> --
> 2.14.3
>
>
> --
> Matti Vaittinen
> ROHM Semiconductors
>
> ~~~ "I don't think so," said Rene Descartes.  Just then, he vanished ~~~

Works with my work-in-progress max77650 driver that uses the new
type_in_mask flag.

Tested-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>

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

* Re: [PATCH] regmap: regmap-irq: Remove default irq type setting from core
  2018-12-18 13:08 ` Bartosz Golaszewski
@ 2018-12-18 13:15   ` Matti Vaittinen
  0 siblings, 0 replies; 3+ messages in thread
From: Matti Vaittinen @ 2018-12-18 13:15 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: mazziesaccount, Mark Brown, Greg Kroah-Hartman,
	Rafael J . Wysocki, ldewangan, Linux Kernel Mailing List

On Tue, Dec 18, 2018 at 02:08:41PM +0100, Bartosz Golaszewski wrote:
> wt., 18 gru 2018 o 11:58 Matti Vaittinen
> <matti.vaittinen@fi.rohmeurope.com> napisał(a):
> >
> > The common code should not set IRQ type. Read HW defaults to the
> > cache at startup instead of forcing type to EDGE_BOTH. If
> > default setting is needed this should be done via normal
> > mechanisms or by chip specific code if normal mechanisms are not
> > suitable for some reason. Common regmap-irq code should not have
> > defaults hard-coded but keep the HW/boot defaults untouched.
> >
> > Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
> > ---
> > I was not able to test this change as I have no max77620 which seems to
> > be the only user of regmap-irq type-setting in tree as of now.
> >
> 
> Works with my work-in-progress max77650 driver that uses the new
> type_in_mask flag.
> 
> Tested-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>

Thanks a bunch for testing Bartosz :) Highly appreciated!

-- 
Matti Vaittinen
ROHM Semiconductors

~~~ "I don't think so," said Rene Descartes.  Just then, he vanished ~~~

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

end of thread, other threads:[~2018-12-18 13:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-18 10:58 [PATCH] regmap: regmap-irq: Remove default irq type setting from core Matti Vaittinen
2018-12-18 13:08 ` Bartosz Golaszewski
2018-12-18 13:15   ` Matti Vaittinen

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).