All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 0/3] pinctrl: mcp32s08: add open drain config for irq
@ 2018-02-19  9:25 Phil Reid
  2018-02-19  9:25 ` [PATCH v4 1/3] pinctrl: mcp23s08: fix probing of mcp23s18 Phil Reid
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Phil Reid @ 2018-02-19  9:25 UTC (permalink / raw)
  To: linus.walleij, robh+dt, mark.rutland, sre, preid, linux-gpio,
	devicetree, jan.kundrat

This is a continuation of patch 2/3 from my previous version
The patches related to irq polarity dropped for the moment as that needs 
more work.

Changes from v3:
- Add a fix for probing mcp23s18
- Add reviewed-by and acked-by
- Rebased on pinctrl/for-next

Changes from v2:
- Use standard 'drive-open-drain' for irq output configuration


Phil Reid (3):
  pinctrl: mcp23s08: fix probing of mcp23s18
  dt-bindings: pinctrl: mcp23s08: add documentation for drive-open-drain
  pinctrl: mcp23s08: add open drain configuration for irq output

 Documentation/devicetree/bindings/pinctrl/pinctrl-mcp23s08.txt | 2 ++
 drivers/pinctrl/pinctrl-mcp23s08.c                             | 9 ++++++---
 2 files changed, 8 insertions(+), 3 deletions(-)

-- 
1.8.3.1

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

* [PATCH v4 1/3] pinctrl: mcp23s08: fix probing of mcp23s18
  2018-02-19  9:25 [PATCH v4 0/3] pinctrl: mcp32s08: add open drain config for irq Phil Reid
@ 2018-02-19  9:25 ` Phil Reid
  2018-02-19 21:24   ` Jan Kundrát
  2018-02-22 15:05   ` Linus Walleij
  2018-02-19  9:25 ` [PATCH v4 2/3] dt-bindings: pinctrl: mcp23s08: add documentation for drive-open-drain Phil Reid
  2018-02-19  9:25 ` [PATCH v4 3/3] pinctrl: mcp23s08: add open drain configuration for irq output Phil Reid
  2 siblings, 2 replies; 15+ messages in thread
From: Phil Reid @ 2018-02-19  9:25 UTC (permalink / raw)
  To: linus.walleij, robh+dt, mark.rutland, sre, preid, linux-gpio,
	devicetree, jan.kundrat

one_regmap_config is always null if mcp type is MCP_TYPE_S18.
Remove the null check so that the mcp23s18 will probe.

Fixes: 1781af563aef66c2eb7cda ("pinctrl: mcp23s08: spi: Fix
duplicate pinctrl debugfs entries")

Signed-off-by: Phil Reid <preid@electromag.com.au>
---
 drivers/pinctrl/pinctrl-mcp23s08.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-mcp23s08.c b/drivers/pinctrl/pinctrl-mcp23s08.c
index f3f9f19..83277570 100644
--- a/drivers/pinctrl/pinctrl-mcp23s08.c
+++ b/drivers/pinctrl/pinctrl-mcp23s08.c
@@ -823,8 +823,6 @@ static int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev,
 		break;
 
 	case MCP_TYPE_S18:
-		if (!one_regmap_config)
-			return -ENOMEM;
 		mcp->regmap = devm_regmap_init(dev, &mcp23sxx_spi_regmap, mcp,
 					       &mcp23x17_regmap);
 		mcp->reg_shift = 1;
-- 
1.8.3.1

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

* [PATCH v4 2/3] dt-bindings: pinctrl: mcp23s08: add documentation for drive-open-drain
  2018-02-19  9:25 [PATCH v4 0/3] pinctrl: mcp32s08: add open drain config for irq Phil Reid
  2018-02-19  9:25 ` [PATCH v4 1/3] pinctrl: mcp23s08: fix probing of mcp23s18 Phil Reid
@ 2018-02-19  9:25 ` Phil Reid
  2018-02-22 15:06   ` Linus Walleij
  2018-02-19  9:25 ` [PATCH v4 3/3] pinctrl: mcp23s08: add open drain configuration for irq output Phil Reid
  2 siblings, 1 reply; 15+ messages in thread
From: Phil Reid @ 2018-02-19  9:25 UTC (permalink / raw)
  To: linus.walleij, robh+dt, mark.rutland, sre, preid, linux-gpio,
	devicetree, jan.kundrat

This flag set the mcp23s08 device irq type to open drain active low.

Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Phil Reid <preid@electromag.com.au>
---
 Documentation/devicetree/bindings/pinctrl/pinctrl-mcp23s08.txt | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/pinctrl/pinctrl-mcp23s08.txt b/Documentation/devicetree/bindings/pinctrl/pinctrl-mcp23s08.txt
index 7d262e9..72bac30 100644
--- a/Documentation/devicetree/bindings/pinctrl/pinctrl-mcp23s08.txt
+++ b/Documentation/devicetree/bindings/pinctrl/pinctrl-mcp23s08.txt
@@ -45,6 +45,8 @@ Optional properties:
   - first cell is the pin number
   - second cell is used to specify flags.
 - interrupt-controller: Marks the device node as a interrupt controller.
+- drive-open-drain: Sets the ODR flag in the IOCON register. This configures
+        the IRQ output as open drain active low.
 
 Optional device specific properties:
 - microchip,irq-mirror: Sets the mirror flag in the IOCON register. Devices
-- 
1.8.3.1

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

* [PATCH v4 3/3] pinctrl: mcp23s08: add open drain configuration for irq output
  2018-02-19  9:25 [PATCH v4 0/3] pinctrl: mcp32s08: add open drain config for irq Phil Reid
  2018-02-19  9:25 ` [PATCH v4 1/3] pinctrl: mcp23s08: fix probing of mcp23s18 Phil Reid
  2018-02-19  9:25 ` [PATCH v4 2/3] dt-bindings: pinctrl: mcp23s08: add documentation for drive-open-drain Phil Reid
@ 2018-02-19  9:25 ` Phil Reid
  2018-02-19 21:43   ` Jan Kundrát
  2018-02-22 15:10   ` Linus Walleij
  2 siblings, 2 replies; 15+ messages in thread
From: Phil Reid @ 2018-02-19  9:25 UTC (permalink / raw)
  To: linus.walleij, robh+dt, mark.rutland, sre, preid, linux-gpio,
	devicetree, jan.kundrat

The mcp23s08 series device can be configured for wired and interrupts
using an external pull-up and open drain output via the IOCON_ODR bit.
And "drive-open-drain" property to enable this.

Reviewed-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
Signed-off-by: Phil Reid <preid@electromag.com.au>
---
 drivers/pinctrl/pinctrl-mcp23s08.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/pinctrl/pinctrl-mcp23s08.c b/drivers/pinctrl/pinctrl-mcp23s08.c
index 83277570..022307d 100644
--- a/drivers/pinctrl/pinctrl-mcp23s08.c
+++ b/drivers/pinctrl/pinctrl-mcp23s08.c
@@ -771,6 +771,7 @@ static int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev,
 {
 	int status, ret;
 	bool mirror = false;
+	bool open_drain = false;
 	struct regmap_config *one_regmap_config = NULL;
 	int raw_chip_address = (addr & ~0x40) >> 1;
 
@@ -883,10 +884,11 @@ static int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev,
 					      "microchip,irq-active-high");
 
 		mirror = device_property_read_bool(dev, "microchip,irq-mirror");
+		open_drain = device_property_read_bool(dev, "drive-open-drain");
 	}
 
 	if ((status & IOCON_SEQOP) || !(status & IOCON_HAEN) || mirror ||
-	     mcp->irq_active_high) {
+	     mcp->irq_active_high || open_drain) {
 		/* mcp23s17 has IOCON twice, make sure they are in sync */
 		status &= ~(IOCON_SEQOP | (IOCON_SEQOP << 8));
 		status |= IOCON_HAEN | (IOCON_HAEN << 8);
@@ -898,6 +900,9 @@ static int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev,
 		if (mirror)
 			status |= IOCON_MIRROR | (IOCON_MIRROR << 8);
 
+		if (open_drain)
+			status |= IOCON_ODR | (IOCON_ODR << 8);
+
 		if (type == MCP_TYPE_S18 || type == MCP_TYPE_018)
 			status |= IOCON_INTCC | (IOCON_INTCC << 8);
 
-- 
1.8.3.1

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

* Re: [PATCH v4 1/3] pinctrl: mcp23s08: fix probing of mcp23s18
  2018-02-19  9:25 ` [PATCH v4 1/3] pinctrl: mcp23s08: fix probing of mcp23s18 Phil Reid
@ 2018-02-19 21:24   ` Jan Kundrát
  2018-02-22 15:05   ` Linus Walleij
  1 sibling, 0 replies; 15+ messages in thread
From: Jan Kundrát @ 2018-02-19 21:24 UTC (permalink / raw)
  To: Phil Reid
  Cc: linus.walleij, robh+dt, mark.rutland, sre, linux-gpio, devicetree

On pondělí 19. února 2018 10:25:18 CET, Phil Reid wrote:
> one_regmap_config is always null if mcp type is MCP_TYPE_S18.
> Remove the null check so that the mcp23s18 will probe.
>
> Fixes: 1781af563aef66c2eb7cda ("pinctrl: mcp23s08: spi: Fix
> duplicate pinctrl debugfs entries")
>
> Signed-off-by: Phil Reid <preid@electromag.com.au>

Thanks, and sorry for this mistake.

Reviewed-by: Jan Kundrát <jan.kundrat@cesnet.cz>
Fixes: 9b3e4207661e ("pinctrl: mcp23s08: spi: Fix regmap debugfs entries")

> ---
>  drivers/pinctrl/pinctrl-mcp23s08.c | 2 --
>  1 file changed, 2 deletions(-)
>
> diff --git a/drivers/pinctrl/pinctrl-mcp23s08.c 
> b/drivers/pinctrl/pinctrl-mcp23s08.c
> index f3f9f19..83277570 100644
> --- a/drivers/pinctrl/pinctrl-mcp23s08.c
> +++ b/drivers/pinctrl/pinctrl-mcp23s08.c
> @@ -823,8 +823,6 @@ static int mcp23s08_probe_one(struct 
> mcp23s08 *mcp, struct device *dev,
>  		break;
>  
>  	case MCP_TYPE_S18:
> -		if (!one_regmap_config)
> -			return -ENOMEM;
>  		mcp->regmap = devm_regmap_init(dev, &mcp23sxx_spi_regmap, mcp,
>  					       &mcp23x17_regmap);
>  		mcp->reg_shift = 1;


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

* Re: [PATCH v4 3/3] pinctrl: mcp23s08: add open drain configuration for irq output
  2018-02-19  9:25 ` [PATCH v4 3/3] pinctrl: mcp23s08: add open drain configuration for irq output Phil Reid
@ 2018-02-19 21:43   ` Jan Kundrát
  2018-02-20  1:12     ` Phil Reid
  2018-02-22 15:10   ` Linus Walleij
  1 sibling, 1 reply; 15+ messages in thread
From: Jan Kundrát @ 2018-02-19 21:43 UTC (permalink / raw)
  To: Phil Reid
  Cc: linus.walleij, robh+dt, mark.rutland, sre, linux-gpio, devicetree

Thanks for looking into this.

Is there a reason why the DT documentation is updated in a separate commit?

>  	if ((status & IOCON_SEQOP) || !(status & IOCON_HAEN) || mirror ||
> -	     mcp->irq_active_high) {
> +	     mcp->irq_active_high || open_drain) {

This `if` is getting quite complex. I don't think that saving one SPI write 
transaction is worth the effort here. What about just setting the chip to a 
known-good state unconditionally by removing that `if`?

The condition also looks wrong to me (as-is in the kernel now). If the chip 
is somehow configured to use active-high IRQ and the DT does not ask for 
either active-high or open-drain IRQ, then the reconfiguration gets skipped 
and the chip runs with wrong settings.

>  		/* mcp23s17 has IOCON twice, make sure they are in sync */
>  		status &= ~(IOCON_SEQOP | (IOCON_SEQOP << 8));
>  		status |= IOCON_HAEN | (IOCON_HAEN << 8);
> @@ -898,6 +900,9 @@ static int mcp23s08_probe_one(struct 
> mcp23s08 *mcp, struct device *dev,
>  		if (mirror)
>  			status |= IOCON_MIRROR | (IOCON_MIRROR << 8);
>  
> +		if (open_drain)
> +			status |= IOCON_ODR | (IOCON_ODR << 8);
> +
>  		if (type == MCP_TYPE_S18 || type == MCP_TYPE_018)
>  			status |= IOCON_INTCC | (IOCON_INTCC << 8);

I think that it would be better to explicitly error out if irq_active_high 
and open_drain are both set. When I sent my attempt at this, I did it like 
this:

+		if (irq_active_high && irq_open_drain) {
+			dev_err(dev, "microchip,irq-open-drain and "
+				"drive-active-high are mutually exclusive\n");
+			ret = -EINVAL;
+			goto fail;
+		} else if (irq_active_high) {
+			...
+		} else if (irq_open_drain) {
+			...
+		}

But anyway, even as-is, the patch is a net improvement, so:

Reviewed-by: Jan Kundrát <jan.kundrat@cesnet.cz>

With kind regards,
Jan

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

* Re: [PATCH v4 3/3] pinctrl: mcp23s08: add open drain configuration for irq output
  2018-02-19 21:43   ` Jan Kundrát
@ 2018-02-20  1:12     ` Phil Reid
  2018-02-20 17:15       ` Jan Kundrát
  0 siblings, 1 reply; 15+ messages in thread
From: Phil Reid @ 2018-02-20  1:12 UTC (permalink / raw)
  To: Jan Kundrát
  Cc: linus.walleij, robh+dt, mark.rutland, sre, linux-gpio, devicetree

On 20/02/2018 05:43, Jan Kundrát wrote:
> Thanks for looking into this.
> 
> Is there a reason why the DT documentation is updated in a separate commit?
> 
>>      if ((status & IOCON_SEQOP) || !(status & IOCON_HAEN) || mirror ||
>> -         mcp->irq_active_high) {
>> +         mcp->irq_active_high || open_drain) {
> 
> This `if` is getting quite complex. I don't think that saving one SPI write transaction is worth the effort here. What about just setting the chip to a 
> known-good state unconditionally by removing that `if`?
> 
> The condition also looks wrong to me (as-is in the kernel now). If the chip is somehow configured to use active-high IRQ and the DT does not ask for either 
> active-high or open-drain IRQ, then the reconfiguration gets skipped and the chip runs with wrong settings.

I agree, I don't think we should be preserving any of the bits in the chip config.
But I think we need that as a separate patch for people to mull over.

> 
>>          /* mcp23s17 has IOCON twice, make sure they are in sync */
>>          status &= ~(IOCON_SEQOP | (IOCON_SEQOP << 8));
>>          status |= IOCON_HAEN | (IOCON_HAEN << 8);
>> @@ -898,6 +900,9 @@ static int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev,
>>          if (mirror)
>>              status |= IOCON_MIRROR | (IOCON_MIRROR << 8);
>>
>> +        if (open_drain)
>> +            status |= IOCON_ODR | (IOCON_ODR << 8);
>> +
>>          if (type == MCP_TYPE_S18 || type == MCP_TYPE_018)
>>              status |= IOCON_INTCC | (IOCON_INTCC << 8);
> 
> I think that it would be better to explicitly error out if irq_active_high and open_drain are both set. When I sent my attempt at this, I did it like this:

Which is something I want to do. As I've got a inverter in between :)
For the mcp the open-drain config bit takes precedence over active-high.
Really needs to be fixed by fixing up the irq request, but I still haven't got a good
fix for the irq request polarity based on active-high in this driver.
I can't see how to fix it without breaking existing dt interface.


> 
> +        if (irq_active_high && irq_open_drain) {
> +            dev_err(dev, "microchip,irq-open-drain and "
> +                "drive-active-high are mutually exclusive\n");
> +            ret = -EINVAL;
> +            goto fail;
> +        } else if (irq_active_high) {
> +            ...
> +        } else if (irq_open_drain) {
> +            ...
> +        }
> 
> But anyway, even as-is, the patch is a net improvement, so:
> 
> Reviewed-by: Jan Kundrát <jan.kundrat@cesnet.cz>
> 
> With kind regards,
> Jan
> 
> 


-- 
Regards
Phil Reid

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

* Re: [PATCH v4 3/3] pinctrl: mcp23s08: add open drain configuration for irq output
  2018-02-20  1:12     ` Phil Reid
@ 2018-02-20 17:15       ` Jan Kundrát
  2018-02-21  0:51         ` Phil Reid
  2018-02-21  7:11         ` Alexander Stein
  0 siblings, 2 replies; 15+ messages in thread
From: Jan Kundrát @ 2018-02-20 17:15 UTC (permalink / raw)
  To: Phil Reid
  Cc: linus.walleij, robh+dt, mark.rutland, sre, linux-gpio,
	devicetree, Alexander Stein

>> I think that it would be better to explicitly error out if 
>> irq_active_high and open_drain are both set. When I sent my 
>> attempt at this, I did it like this:
>
> Which is something I want to do. As I've got a inverter in between :)
> For the mcp the open-drain config bit takes precedence over active-high.
> Really needs to be fixed by fixing up the irq request, but I 
> still haven't got a good
> fix for the irq request polarity based on active-high in this driver.
> I can't see how to fix it without breaking existing dt interface.

I was told that the appropriate way forward are device drivers which do not 
specify the IRQ polarity. Apparently, people are supposed to do that in 
their DT.

So, in this context:

- pinctrl-mcp23s08.c should only specify IRQF_ONESHOT | IRQF_SHARED
- the DT should use an appropriate IRQ_TYPE_LEVEL_LOW or 
IRQ_TYPE_LEVEL_HIGH based on what the CPU expects to see on its IRQ pins
- the DT must also set a property to configure the MCP23xxx device to 
*generate* an IRQ by the active-high flag, or another flag for an 
open-drain active-low IRQ output suitable for connecting directly to an 
interrupt line which gets shared by several open-drain IRQ producers
- whoever supplies the DT must now check that their settings "make sense"

Yes, this means that people might have to update their DTs. To me, that 
makes sense. If you ask me, the DT is already sort-of broken because it's 
using IRQF_SHARED with a push-pull IRQ output. Yes, one can fix that with 
extra transistors, but that sounds quite ugly, doesn't it. The current 
heuristics only work for some users, and they don't work for you and me.

I dug a bit and found some reasoning [1] for why it was done like that back 
in 2014. Adding Alexander Stein to Cc as he wrote that code.

Phil, is that approach something that you agree with? Are you going to 
submit a patch for this? Or should I do that?

With kind regards,
Jan

[1] https://www.spinics.net/lists/devicetree/msg60203.html

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

* Re: [PATCH v4 3/3] pinctrl: mcp23s08: add open drain configuration for irq output
  2018-02-20 17:15       ` Jan Kundrát
@ 2018-02-21  0:51         ` Phil Reid
  2018-02-21  7:11         ` Alexander Stein
  1 sibling, 0 replies; 15+ messages in thread
From: Phil Reid @ 2018-02-21  0:51 UTC (permalink / raw)
  To: Jan Kundrát
  Cc: linus.walleij, robh+dt, mark.rutland, sre, linux-gpio,
	devicetree, Alexander Stein

On 21/02/2018 01:15, Jan Kundrát wrote:
>>> I think that it would be better to explicitly error out if irq_active_high and open_drain are both set. When I sent my attempt at this, I did it like this:
>>
>> Which is something I want to do. As I've got a inverter in between :)
>> For the mcp the open-drain config bit takes precedence over active-high.
>> Really needs to be fixed by fixing up the irq request, but I still haven't got a good
>> fix for the irq request polarity based on active-high in this driver.
>> I can't see how to fix it without breaking existing dt interface.
> 
> I was told that the appropriate way forward are device drivers which do not specify the IRQ polarity. Apparently, people are supposed to do that in their DT.
yes, That's what I've been told as well
> 
> So, in this context:
> 
> - pinctrl-mcp23s08.c should only specify IRQF_ONESHOT | IRQF_SHARED
yeap.
> - the DT should use an appropriate IRQ_TYPE_LEVEL_LOW or IRQ_TYPE_LEVEL_HIGH based on what the CPU expects to see on its IRQ pins
yeap
> - the DT must also set a property to configure the MCP23xxx device to *generate* an IRQ by the active-high flag, or another flag for an open-drain active-low 
> IRQ output suitable for connecting directly to an interrupt line which gets shared by several open-drain IRQ producers
> - whoever supplies the DT must now check that their settings "make sense"
> 
> Yes, this means that people might have to update their DTs. To me, that makes sense. If you ask me, the DT is already sort-of broken because it's using 
> IRQF_SHARED with a push-pull IRQ output. Yes, one can fix that with extra transistors, but that sounds quite ugly, doesn't it. The current heuristics only work 
> for some users, and they don't work for you and me.
I think IRQF_SHARED is fine as a push pull irq output can be shared via and AND / OR gate.
The only reason not to IRQF_SHARED is when you can't determine if the IRQ is from this device.
ie: There's no register to read in the potential source to see if the IRQ is asserted.

> 
> I dug a bit and found some reasoning [1] for why it was done like that back in 2014. Adding Alexander Stein to Cc as he wrote that code.
> 
> Phil, is that approach something that you agree with? Are you going to submit a patch for this? Or should I do that?
Yes, It'd be nice to remove the IO_CON read in probe and explicitly set the  IO_CON register purely on the DT.

> 
> With kind regards,
> Jan
> 
> [1] https://www.spinics.net/lists/devicetree/msg60203.html
> 
> 

Hmm, the description in the patch is what I want the driver to do.

On Thu, Nov 27, 2014 at 3:36 PM, Alexander Stein
> What I need to do, is to change the interrupt polarity (to active high) at MCP23S17 while retaining the interrupt polarity on the controller as active-low.

But that's not what it does. As irqflags is set to match the chip output polarity in irq_setup
(Well it certainly doesn't for me).

Problem with changing the DT behaviour is, I believe it's consider an ABI and shouldn't be changed.


-- 
Regards
Phil Reid


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

* Re: [PATCH v4 3/3] pinctrl: mcp23s08: add open drain configuration for irq output
  2018-02-20 17:15       ` Jan Kundrát
  2018-02-21  0:51         ` Phil Reid
@ 2018-02-21  7:11         ` Alexander Stein
  2018-02-21  8:19           ` Phil Reid
  2018-02-21 11:55           ` Jan Kundrát
  1 sibling, 2 replies; 15+ messages in thread
From: Alexander Stein @ 2018-02-21  7:11 UTC (permalink / raw)
  To: Jan Kundrát
  Cc: Phil Reid, linus.walleij, robh+dt, mark.rutland, sre, linux-gpio,
	devicetree

On Tuesday, February 20, 2018, 6:15:46 PM CET Jan Kundrát wrote:
> I was told that the appropriate way forward are device drivers which do not
> specify the IRQ polarity. Apparently, people are supposed to do that in
> their DT.
> 
> So, in this context:
> 
> - pinctrl-mcp23s08.c should only specify IRQF_ONESHOT | IRQF_SHARED
> - the DT should use an appropriate IRQ_TYPE_LEVEL_LOW or
> IRQ_TYPE_LEVEL_HIGH based on what the CPU expects to see on its IRQ pins
> - the DT must also set a property to configure the MCP23xxx device to
> *generate* an IRQ by the active-high flag, or another flag for an
> open-drain active-low IRQ output suitable for connecting directly to an
> interrupt line which gets shared by several open-drain IRQ producers
> - whoever supplies the DT must now check that their settings "make sense"
> 
> Yes, this means that people might have to update their DTs. To me, that
> makes sense. If you ask me, the DT is already sort-of broken because it's
> using IRQF_SHARED with a push-pull IRQ output. Yes, one can fix that with
> extra transistors, but that sounds quite ugly, doesn't it. 

Well, that is the exact situation on the board I had to deal with. The MCP was 
attached to a transisitor inverting the signal. The output on MCP has to be 
push-pull as there was no pull-up oder -down. But the line connecting the 
inverter to the CPU was an open-drain one and this line was actually a shared 
IRQ line. So of course the line bewteen MCP and inverter cannot be shared, but 
the IRQ used on CPU is actually shared. How can this be respresented in DT?

Best reagrds,
Alexander

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

* Re: [PATCH v4 3/3] pinctrl: mcp23s08: add open drain configuration for irq output
  2018-02-21  7:11         ` Alexander Stein
@ 2018-02-21  8:19           ` Phil Reid
  2018-02-21 11:55           ` Jan Kundrát
  1 sibling, 0 replies; 15+ messages in thread
From: Phil Reid @ 2018-02-21  8:19 UTC (permalink / raw)
  To: Alexander Stein, Jan Kundrát
  Cc: linus.walleij, robh+dt, mark.rutland, sre, linux-gpio, devicetree

On 21/02/2018 15:11, Alexander Stein wrote:
> On Tuesday, February 20, 2018, 6:15:46 PM CET Jan Kundrát wrote:
>> I was told that the appropriate way forward are device drivers which do not
>> specify the IRQ polarity. Apparently, people are supposed to do that in
>> their DT.
>>
>> So, in this context:
>>
>> - pinctrl-mcp23s08.c should only specify IRQF_ONESHOT | IRQF_SHARED
>> - the DT should use an appropriate IRQ_TYPE_LEVEL_LOW or
>> IRQ_TYPE_LEVEL_HIGH based on what the CPU expects to see on its IRQ pins
>> - the DT must also set a property to configure the MCP23xxx device to
>> *generate* an IRQ by the active-high flag, or another flag for an
>> open-drain active-low IRQ output suitable for connecting directly to an
>> interrupt line which gets shared by several open-drain IRQ producers
>> - whoever supplies the DT must now check that their settings "make sense"
>>
>> Yes, this means that people might have to update their DTs. To me, that
>> makes sense. If you ask me, the DT is already sort-of broken because it's
>> using IRQF_SHARED with a push-pull IRQ output. Yes, one can fix that with
>> extra transistors, but that sounds quite ugly, doesn't it.
> 
> Well, that is the exact situation on the board I had to deal with. The MCP was
> attached to a transisitor inverting the signal. The output on MCP has to be
> push-pull as there was no pull-up oder -down. But the line connecting the
> inverter to the CPU was an open-drain one and this line was actually a shared
> IRQ line. So of course the line bewteen MCP and inverter cannot be shared, but
> the IRQ used on CPU is actually shared. How can this be respresented in DT?
> 
G'day Alexandar,
It can't at the moment. Linux W. proposed modelling a inverter. Basically a irqchip driver
that flips the polarity of the interrupt. I was going to give it a go when I found time.
But it's not a high priority for me.

In your patch at: https://www.spinics.net/lists/devicetree/msg58208.html
This bit in mcp23s08_irq_setup
+	if (mcp->irq_active_high)
+		irqflags |= IRQF_TRIGGER_HIGH;
+	else
+		irqflags |= IRQF_TRIGGER_LOW;

is causing me problems.

It overrides the setting from the dt for me.
Probably due to this bit in __setup_irq:
	/*
	 * If the trigger type is not specified by the caller,
	 * then use the default for this interrupt.
	 */
	if (!(new->flags & IRQF_TRIGGER_MASK))
		new->flags |= irqd_get_trigger_type(&desc->irq_data);


Based on your description I would have thought the same.
With a transisitor inverting the line you'd want to register irq active_low,
while driving active_high to turn the transitor on.
Was this the case?


-- 
Regards
Phil Reid


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

* Re: [PATCH v4 3/3] pinctrl: mcp23s08: add open drain configuration for irq output
  2018-02-21  7:11         ` Alexander Stein
  2018-02-21  8:19           ` Phil Reid
@ 2018-02-21 11:55           ` Jan Kundrát
  1 sibling, 0 replies; 15+ messages in thread
From: Jan Kundrát @ 2018-02-21 11:55 UTC (permalink / raw)
  To: Alexander Stein
  Cc: Phil Reid, linus.walleij, robh+dt, mark.rutland, sre, linux-gpio,
	devicetree

On středa 21. února 2018 8:11:25 CET, Alexander Stein wrote:
> Well, that is the exact situation on the board I had to deal 
> with. The MCP was 
> attached to a transisitor inverting the signal. The output on MCP has to be 
> push-pull as there was no pull-up oder -down. But the line connecting the 
> inverter to the CPU was an open-drain one and this line was 
> actually a shared 
> IRQ line. So of course the line bewteen MCP and inverter cannot 
> be shared, but 
> the IRQ used on CPU is actually shared. How can this be respresented in DT?

What I propose is to have it like this:

	gpio@1 {
		compatible = "microchip,mcp23s17";
		irq-active-high;
		interrupt-parent = <&gpio0>;
		interrupts = <123 IRQ_TYPE_LEVEL_LOW>;
		// ...
	};

In other words, the "interrupt-parent" and "interrupts" DT statements 
specify how the upstream interrupt controller should be set up, while other 
properties define settings of the IRQ source.

But as Phil points out, such a change would break the DT ABI. This means 
that we should preserve the semantics of any existing DT. We can do that by 
introducing another property. Here's a rough sketch:

#define MCP23S08_IRQ_OPEN_DRAIN 1
#define MCP23S08_IRQ_PUSH_PULL_ACTIVE_LOW 2
#define MCP23S08_IRQ_PUSH_PULL_ACTIVE_HIGH 3

	irqflags = IRQF_SHARED | IRQF_ONESHOT;

	if (new_irq_mode != -1) {
		/* irqflags are only set to IRQF_SHARED | IRQF_ONESHOT,
		nothing else */
	} else if (irq_active_high) {
		/* an existing property */
		irqflags |= IRQF_ACTIVE_HIGH;
	} else {
		irqflags |= IRQF_ACTIVE_LOW;
	}

A "new-style" DT then should look like this for your scenario with an 
electrical invertor:

	gpio@1 {
		compatible = "microchip,mcp23s17";
		irq-mode = MCP23S08_IRQ_PUSH_PULL_ACTIVE_HIGH;
		interrupt-parent = <&gpio0>;
		interrupts = <123 IRQ_TYPE_LEVEL_LOW>;
		// ...
	};

A downside of this approach is that it's using a custom enum, not a 
standard property like drive-open-drain. Pick your poison.

Cheers,
Jan

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

* Re: [PATCH v4 1/3] pinctrl: mcp23s08: fix probing of mcp23s18
  2018-02-19  9:25 ` [PATCH v4 1/3] pinctrl: mcp23s08: fix probing of mcp23s18 Phil Reid
  2018-02-19 21:24   ` Jan Kundrát
@ 2018-02-22 15:05   ` Linus Walleij
  1 sibling, 0 replies; 15+ messages in thread
From: Linus Walleij @ 2018-02-22 15:05 UTC (permalink / raw)
  To: Phil Reid
  Cc: Rob Herring, Mark Rutland, Sebastian Reichel,
	open list:GPIO SUBSYSTEM,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	Jan Kundrát

On Mon, Feb 19, 2018 at 10:25 AM, Phil Reid <preid@electromag.com.au> wrote:

> one_regmap_config is always null if mcp type is MCP_TYPE_S18.
> Remove the null check so that the mcp23s18 will probe.
>
> Fixes: 1781af563aef66c2eb7cda ("pinctrl: mcp23s08: spi: Fix
> duplicate pinctrl debugfs entries")
>
> Signed-off-by: Phil Reid <preid@electromag.com.au>

Patch applied with Jan's ACK.

Yours,
Linus Walleij

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

* Re: [PATCH v4 2/3] dt-bindings: pinctrl: mcp23s08: add documentation for drive-open-drain
  2018-02-19  9:25 ` [PATCH v4 2/3] dt-bindings: pinctrl: mcp23s08: add documentation for drive-open-drain Phil Reid
@ 2018-02-22 15:06   ` Linus Walleij
  0 siblings, 0 replies; 15+ messages in thread
From: Linus Walleij @ 2018-02-22 15:06 UTC (permalink / raw)
  To: Phil Reid
  Cc: Rob Herring, Mark Rutland, Sebastian Reichel,
	open list:GPIO SUBSYSTEM,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	Jan Kundrát

On Mon, Feb 19, 2018 at 10:25 AM, Phil Reid <preid@electromag.com.au> wrote:

> This flag set the mcp23s08 device irq type to open drain active low.
>
> Acked-by: Rob Herring <robh@kernel.org>
> Signed-off-by: Phil Reid <preid@electromag.com.au>

Patch applied.

Yours,
Linus Walleij

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

* Re: [PATCH v4 3/3] pinctrl: mcp23s08: add open drain configuration for irq output
  2018-02-19  9:25 ` [PATCH v4 3/3] pinctrl: mcp23s08: add open drain configuration for irq output Phil Reid
  2018-02-19 21:43   ` Jan Kundrát
@ 2018-02-22 15:10   ` Linus Walleij
  1 sibling, 0 replies; 15+ messages in thread
From: Linus Walleij @ 2018-02-22 15:10 UTC (permalink / raw)
  To: Phil Reid
  Cc: Rob Herring, Mark Rutland, Sebastian Reichel,
	open list:GPIO SUBSYSTEM,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	Jan Kundrát

On Mon, Feb 19, 2018 at 10:25 AM, Phil Reid <preid@electromag.com.au> wrote:

> The mcp23s08 series device can be configured for wired and interrupts
> using an external pull-up and open drain output via the IOCON_ODR bit.
> And "drive-open-drain" property to enable this.
>
> Reviewed-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
> Signed-off-by: Phil Reid <preid@electromag.com.au>

Patch applied with Jan's review tag as it is (as he says)
a net improvement.

But as the discussion shows, maybe we need more patching
on top of this.

Anyways nice to get this in so we can have some base to
work from.

Yours,
Linus Walleij

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

end of thread, other threads:[~2018-02-22 15:10 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-19  9:25 [PATCH v4 0/3] pinctrl: mcp32s08: add open drain config for irq Phil Reid
2018-02-19  9:25 ` [PATCH v4 1/3] pinctrl: mcp23s08: fix probing of mcp23s18 Phil Reid
2018-02-19 21:24   ` Jan Kundrát
2018-02-22 15:05   ` Linus Walleij
2018-02-19  9:25 ` [PATCH v4 2/3] dt-bindings: pinctrl: mcp23s08: add documentation for drive-open-drain Phil Reid
2018-02-22 15:06   ` Linus Walleij
2018-02-19  9:25 ` [PATCH v4 3/3] pinctrl: mcp23s08: add open drain configuration for irq output Phil Reid
2018-02-19 21:43   ` Jan Kundrát
2018-02-20  1:12     ` Phil Reid
2018-02-20 17:15       ` Jan Kundrát
2018-02-21  0:51         ` Phil Reid
2018-02-21  7:11         ` Alexander Stein
2018-02-21  8:19           ` Phil Reid
2018-02-21 11:55           ` Jan Kundrát
2018-02-22 15:10   ` Linus Walleij

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.