diff mbox series

[1/2] spi: dt-bindings: spi-controller: add wakeup-source and interrupts

Message ID 20191112055412.192675-2-dmitry.torokhov@gmail.com (mailing list archive)
State New, archived
Headers show
Series spi: add wakeup handling to SPI core | expand

Commit Message

Dmitry Torokhov Nov. 12, 2019, 5:54 a.m. UTC
This change adds bindings for wakeup-source and
interrupts/interrupt-names properties that can be used to configure
device as wakeup source on the system.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

---

 .../bindings/spi/spi-controller.yaml          | 23 +++++++++++++++++++
 1 file changed, 23 insertions(+)

Comments

Mark Brown Nov. 12, 2019, 12:03 p.m. UTC | #1
On Mon, Nov 11, 2019 at 09:54:10PM -0800, Dmitry Torokhov wrote:

> +      interrupts:
> +        items:
> +          - description: main interrupt (attention) line.
> +          - description: dedicated wakeup interrupt.
> +        minItems: 1 # The wakeup interrupt is optional.
> +        description:
> +          Specifies interrupt lines a device is connected to. Typically a
> +          device is wired to a single interrupt line that is used as
> +          "attention" signal and also to wake up system when device is
> +          set up as wakeup source. However on some systems a dedicated
> +          wakeup line might be used.

> +      interrupt-names:
> +        items:
> +          - const: irq
> +          - const: wakeup
> +        minItems: 1

How will this interact with a SPI device that defines interrupts at the
device level, possibly more than one of them?  Especially if the device
has its own idea what the interrupts should be called.
Dmitry Torokhov Nov. 12, 2019, 7:03 p.m. UTC | #2
On Tue, Nov 12, 2019 at 12:03:07PM +0000, Mark Brown wrote:
> On Mon, Nov 11, 2019 at 09:54:10PM -0800, Dmitry Torokhov wrote:
> 
> > +      interrupts:
> > +        items:
> > +          - description: main interrupt (attention) line.
> > +          - description: dedicated wakeup interrupt.
> > +        minItems: 1 # The wakeup interrupt is optional.
> > +        description:
> > +          Specifies interrupt lines a device is connected to. Typically a
> > +          device is wired to a single interrupt line that is used as
> > +          "attention" signal and also to wake up system when device is
> > +          set up as wakeup source. However on some systems a dedicated
> > +          wakeup line might be used.
> 
> > +      interrupt-names:
> > +        items:
> > +          - const: irq
> > +          - const: wakeup
> > +        minItems: 1
> 
> How will this interact with a SPI device that defines interrupts at the
> device level, possibly more than one of them?  Especially if the device
> has its own idea what the interrupts should be called.

My understanding that individual drivers should be able to override
whatever the default behavior core has configured, and the device can
establish their own mapping. We have this in I2C and I believe this
works well.

Is the concern about the device tree scheme or SPI core handling?

Thanks.
Mark Brown Nov. 12, 2019, 7:15 p.m. UTC | #3
On Tue, Nov 12, 2019 at 11:03:28AM -0800, Dmitry Torokhov wrote:
> On Tue, Nov 12, 2019 at 12:03:07PM +0000, Mark Brown wrote:
> > On Mon, Nov 11, 2019 at 09:54:10PM -0800, Dmitry Torokhov wrote:

> > > +      interrupts:
> > > +        items:
> > > +          - description: main interrupt (attention) line.
> > > +          - description: dedicated wakeup interrupt.
> > > +        minItems: 1 # The wakeup interrupt is optional.

> > > +      interrupt-names:
> > > +        items:
> > > +          - const: irq
> > > +          - const: wakeup
> > > +        minItems: 1

> > How will this interact with a SPI device that defines interrupts at the
> > device level, possibly more than one of them?  Especially if the device
> > has its own idea what the interrupts should be called.

> My understanding that individual drivers should be able to override
> whatever the default behavior core has configured, and the device can
> establish their own mapping. We have this in I2C and I believe this
> works well.

> Is the concern about the device tree scheme or SPI core handling?

Both really.
Dmitry Torokhov Nov. 12, 2019, 7:36 p.m. UTC | #4
On Tue, Nov 12, 2019 at 07:15:47PM +0000, Mark Brown wrote:
> On Tue, Nov 12, 2019 at 11:03:28AM -0800, Dmitry Torokhov wrote:
> > On Tue, Nov 12, 2019 at 12:03:07PM +0000, Mark Brown wrote:
> > > On Mon, Nov 11, 2019 at 09:54:10PM -0800, Dmitry Torokhov wrote:
> 
> > > > +      interrupts:
> > > > +        items:
> > > > +          - description: main interrupt (attention) line.
> > > > +          - description: dedicated wakeup interrupt.
> > > > +        minItems: 1 # The wakeup interrupt is optional.
> 
> > > > +      interrupt-names:
> > > > +        items:
> > > > +          - const: irq
> > > > +          - const: wakeup
> > > > +        minItems: 1
> 
> > > How will this interact with a SPI device that defines interrupts at the
> > > device level, possibly more than one of them?  Especially if the device
> > > has its own idea what the interrupts should be called.
> 
> > My understanding that individual drivers should be able to override
> > whatever the default behavior core has configured, and the device can
> > establish their own mapping. We have this in I2C and I believe this
> > works well.
> 
> > Is the concern about the device tree scheme or SPI core handling?
> 
> Both really.

So as I mentioned, the driver is not forced to use the interrupt
supplied by the SPI core, and the worst thing is that the core
configures the main IRQ as wakeirq and driver would need to call
dev_pm_clear_wake_irq() before switching to correct one. I expect there
will be just a few drivers needing that and many more would benefit from
the default behavior and not needing to repeat the same boilerplate
code.

As far as scheme goes - I hope that Rob could confirm that we can
override number of interrupts and names in consumers of the binding, as
needed.
Mark Brown Nov. 12, 2019, 7:42 p.m. UTC | #5
On Tue, Nov 12, 2019 at 11:36:53AM -0800, Dmitry Torokhov wrote:

> As far as scheme goes - I hope that Rob could confirm that we can
> override number of interrupts and names in consumers of the binding, as
> needed.

Yes, I think that's the main worry here - if there's issue with the
framework bit we should be able to sort that.
Rob Herring Nov. 14, 2019, 10:26 p.m. UTC | #6
On Tue, Nov 12, 2019 at 11:36:53AM -0800, Dmitry Torokhov wrote:
> On Tue, Nov 12, 2019 at 07:15:47PM +0000, Mark Brown wrote:
> > On Tue, Nov 12, 2019 at 11:03:28AM -0800, Dmitry Torokhov wrote:
> > > On Tue, Nov 12, 2019 at 12:03:07PM +0000, Mark Brown wrote:
> > > > On Mon, Nov 11, 2019 at 09:54:10PM -0800, Dmitry Torokhov wrote:
> > 
> > > > > +      interrupts:
> > > > > +        items:
> > > > > +          - description: main interrupt (attention) line.
> > > > > +          - description: dedicated wakeup interrupt.
> > > > > +        minItems: 1 # The wakeup interrupt is optional.
> > 
> > > > > +      interrupt-names:
> > > > > +        items:
> > > > > +          - const: irq
> > > > > +          - const: wakeup
> > > > > +        minItems: 1
> > 
> > > > How will this interact with a SPI device that defines interrupts at the
> > > > device level, possibly more than one of them?  Especially if the device
> > > > has its own idea what the interrupts should be called.
> > 
> > > My understanding that individual drivers should be able to override
> > > whatever the default behavior core has configured, and the device can
> > > establish their own mapping. We have this in I2C and I believe this
> > > works well.
> > 
> > > Is the concern about the device tree scheme or SPI core handling?
> > 
> > Both really.
> 
> So as I mentioned, the driver is not forced to use the interrupt
> supplied by the SPI core, and the worst thing is that the core
> configures the main IRQ as wakeirq and driver would need to call
> dev_pm_clear_wake_irq() before switching to correct one. I expect there
> will be just a few drivers needing that and many more would benefit from
> the default behavior and not needing to repeat the same boilerplate
> code.
> 
> As far as scheme goes - I hope that Rob could confirm that we can
> override number of interrupts and names in consumers of the binding, as
> needed.

This won't work. A device schema doesn't override what's defined here, 
but just further constrains this schema.

You could define a "spi irq" schema which devices can include if they 
want to, but I don't think this pattern is that common to SPI devices. 
There's not any spec behind compared to say alert irq for SMBus. 

The 'wakeup' irq name is standardized (for DT), but that's not SPI 
specific. About all we could define there is 'wakeup-source' is boolean 
and if there is more than one interrupt, one should be named 'wakeup'.

Rob
Dmitry Torokhov Nov. 14, 2019, 11:08 p.m. UTC | #7
On Thu, Nov 14, 2019 at 2:26 PM Rob Herring <robh@kernel.org> wrote:
>
> On Tue, Nov 12, 2019 at 11:36:53AM -0800, Dmitry Torokhov wrote:
> > On Tue, Nov 12, 2019 at 07:15:47PM +0000, Mark Brown wrote:
> > > On Tue, Nov 12, 2019 at 11:03:28AM -0800, Dmitry Torokhov wrote:
> > > > On Tue, Nov 12, 2019 at 12:03:07PM +0000, Mark Brown wrote:
> > > > > On Mon, Nov 11, 2019 at 09:54:10PM -0800, Dmitry Torokhov wrote:
> > >
> > > > > > +      interrupts:
> > > > > > +        items:
> > > > > > +          - description: main interrupt (attention) line.
> > > > > > +          - description: dedicated wakeup interrupt.
> > > > > > +        minItems: 1 # The wakeup interrupt is optional.
> > >
> > > > > > +      interrupt-names:
> > > > > > +        items:
> > > > > > +          - const: irq
> > > > > > +          - const: wakeup
> > > > > > +        minItems: 1
> > >
> > > > > How will this interact with a SPI device that defines interrupts at the
> > > > > device level, possibly more than one of them?  Especially if the device
> > > > > has its own idea what the interrupts should be called.
> > >
> > > > My understanding that individual drivers should be able to override
> > > > whatever the default behavior core has configured, and the device can
> > > > establish their own mapping. We have this in I2C and I believe this
> > > > works well.
> > >
> > > > Is the concern about the device tree scheme or SPI core handling?
> > >
> > > Both really.
> >
> > So as I mentioned, the driver is not forced to use the interrupt
> > supplied by the SPI core, and the worst thing is that the core
> > configures the main IRQ as wakeirq and driver would need to call
> > dev_pm_clear_wake_irq() before switching to correct one. I expect there
> > will be just a few drivers needing that and many more would benefit from
> > the default behavior and not needing to repeat the same boilerplate
> > code.
> >
> > As far as scheme goes - I hope that Rob could confirm that we can
> > override number of interrupts and names in consumers of the binding, as
> > needed.
>
> This won't work. A device schema doesn't override what's defined here,
> but just further constrains this schema.
>
> You could define a "spi irq" schema which devices can include if they
> want to, but I don't think this pattern is that common to SPI devices.
> There's not any spec behind compared to say alert irq for SMBus.
>
> The 'wakeup' irq name is standardized (for DT), but that's not SPI
> specific. About all we could define there is 'wakeup-source' is boolean
> and if there is more than one interrupt, one should be named 'wakeup'.

OK, so what I am hearing is "interrupt"/"interrupt-names" properties
should be defined in individual device's bindings, and wakeup-source
can stay in spi-controller.yaml, right?

And as far as SPI core goes, we can still do what I proposed, because
we already handle "first" interrupt as the default one and the drivers
can override as needed anyway...

Thanks.
Rob Herring Nov. 15, 2019, 1:52 p.m. UTC | #8
On Thu, Nov 14, 2019 at 5:09 PM Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
>
> On Thu, Nov 14, 2019 at 2:26 PM Rob Herring <robh@kernel.org> wrote:
> >
> > On Tue, Nov 12, 2019 at 11:36:53AM -0800, Dmitry Torokhov wrote:
> > > On Tue, Nov 12, 2019 at 07:15:47PM +0000, Mark Brown wrote:
> > > > On Tue, Nov 12, 2019 at 11:03:28AM -0800, Dmitry Torokhov wrote:
> > > > > On Tue, Nov 12, 2019 at 12:03:07PM +0000, Mark Brown wrote:
> > > > > > On Mon, Nov 11, 2019 at 09:54:10PM -0800, Dmitry Torokhov wrote:
> > > >
> > > > > > > +      interrupts:
> > > > > > > +        items:
> > > > > > > +          - description: main interrupt (attention) line.
> > > > > > > +          - description: dedicated wakeup interrupt.
> > > > > > > +        minItems: 1 # The wakeup interrupt is optional.
> > > >
> > > > > > > +      interrupt-names:
> > > > > > > +        items:
> > > > > > > +          - const: irq
> > > > > > > +          - const: wakeup
> > > > > > > +        minItems: 1
> > > >
> > > > > > How will this interact with a SPI device that defines interrupts at the
> > > > > > device level, possibly more than one of them?  Especially if the device
> > > > > > has its own idea what the interrupts should be called.
> > > >
> > > > > My understanding that individual drivers should be able to override
> > > > > whatever the default behavior core has configured, and the device can
> > > > > establish their own mapping. We have this in I2C and I believe this
> > > > > works well.
> > > >
> > > > > Is the concern about the device tree scheme or SPI core handling?
> > > >
> > > > Both really.
> > >
> > > So as I mentioned, the driver is not forced to use the interrupt
> > > supplied by the SPI core, and the worst thing is that the core
> > > configures the main IRQ as wakeirq and driver would need to call
> > > dev_pm_clear_wake_irq() before switching to correct one. I expect there
> > > will be just a few drivers needing that and many more would benefit from
> > > the default behavior and not needing to repeat the same boilerplate
> > > code.
> > >
> > > As far as scheme goes - I hope that Rob could confirm that we can
> > > override number of interrupts and names in consumers of the binding, as
> > > needed.
> >
> > This won't work. A device schema doesn't override what's defined here,
> > but just further constrains this schema.
> >
> > You could define a "spi irq" schema which devices can include if they
> > want to, but I don't think this pattern is that common to SPI devices.
> > There's not any spec behind compared to say alert irq for SMBus.
> >
> > The 'wakeup' irq name is standardized (for DT), but that's not SPI
> > specific. About all we could define there is 'wakeup-source' is boolean
> > and if there is more than one interrupt, one should be named 'wakeup'.
>
> OK, so what I am hearing is "interrupt"/"interrupt-names" properties
> should be defined in individual device's bindings, and wakeup-source
> can stay in spi-controller.yaml, right?

It could, but it's not SPI specific. I think we should convert
bindings/power/wakeup-source.txt instead. Something like this:

select: true

properties:
  wakeup-source:
    type: boolean
    description: ...

if:
  properties:
    interrupt-names:
      contains:
        const: wakeup
  required:
    - interrupt-names
then:
  required:
    - wakeup-source

dependencies:
  wakeup-source: [ interrupts ]


Rob

> And as far as SPI core goes, we can still do what I proposed, because
> we already handle "first" interrupt as the default one and the drivers
> can override as needed anyway...
>
> Thanks.
>
> --
> Dmitry
Mark Brown Nov. 15, 2019, 3:22 p.m. UTC | #9
On Fri, Nov 15, 2019 at 07:52:22AM -0600, Rob Herring wrote:

> if:
>   properties:
>     interrupt-names:
>       contains:
>         const: wakeup
>   required:
>     - interrupt-names
> then:
>   required:
>     - wakeup-source

That seems to say that if we have a device that has an interrupt called
"wakeup" then it must be a wakeup source.  Is that desirable?  Being
able to wake the system is partly a property of the system as a whole
(the wakeup signal needs to be wired somewhere where it can wake things)
and a device might have a signal that could be used to wake the system,
may even be called "wakeup" by the device but for some reason isn't
wired suitably in a given system.
Rob Herring Nov. 15, 2019, 7:43 p.m. UTC | #10
On Fri, Nov 15, 2019 at 9:22 AM Mark Brown <broonie@kernel.org> wrote:
>
> On Fri, Nov 15, 2019 at 07:52:22AM -0600, Rob Herring wrote:
>
> > if:
> >   properties:
> >     interrupt-names:
> >       contains:
> >         const: wakeup
> >   required:
> >     - interrupt-names
> > then:
> >   required:
> >     - wakeup-source
>
> That seems to say that if we have a device that has an interrupt called
> "wakeup" then it must be a wakeup source.  Is that desirable?  Being
> able to wake the system is partly a property of the system as a whole
> (the wakeup signal needs to be wired somewhere where it can wake things)
> and a device might have a signal that could be used to wake the system,
> may even be called "wakeup" by the device but for some reason isn't
> wired suitably in a given system.

Perhaps it is too strict. It would be useful as a "Did you forget
wakeup-source?" message, but we don't have a way to distinguish that.

Rob
diff mbox series

Patch

diff --git a/Documentation/devicetree/bindings/spi/spi-controller.yaml b/Documentation/devicetree/bindings/spi/spi-controller.yaml
index 732339275848c..4e31a4bf6851c 100644
--- a/Documentation/devicetree/bindings/spi/spi-controller.yaml
+++ b/Documentation/devicetree/bindings/spi/spi-controller.yaml
@@ -78,6 +78,29 @@  patternProperties:
         description:
           Chip select used by the device.
 
+      interrupts:
+        items:
+          - description: main interrupt (attention) line.
+          - description: dedicated wakeup interrupt.
+        minItems: 1 # The wakeup interrupt is optional.
+        description:
+          Specifies interrupt lines a device is connected to. Typically a
+          device is wired to a single interrupt line that is used as
+          "attention" signal and also to wake up system when device is
+          set up as wakeup source. However on some systems a dedicated
+          wakeup line might be used.
+
+      interrupt-names:
+        items:
+          - const: irq
+          - const: wakeup
+        minItems: 1
+
+      wakeup-source:
+        description:
+          Device is capable of waking up the system.
+        type: boolean
+
       spi-3wire:
         $ref: /schemas/types.yaml#/definitions/flag
         description: