Message ID | 20220830171332.4.I8af4282adc72eb9f247adcd03676a43893a020a6@changeid |
---|---|
State | New |
Headers | show |
Series | acpi: i2c: Use SharedAndWake and ExclusiveAndWake to enable wake irq | expand |
On Tue, Aug 30, 2022 at 05:15:37PM -0600, Raul E Rangel wrote: > Device tree already has a mechanism to pass the wake_irq. It does this > by looking for the wakeup-source property and setting the > I2C_CLIENT_WAKE flag. This CL adds the ACPI equivalent. It uses at the > ACPI GpioInt wake flag to determine if the interrupt can be used to wake > the system. Previously the i2c drivers had to make assumptions and > blindly enable the wake IRQ. This can cause spurious wake events. e.g., > If there is a device with an Active Low interrupt and the device gets > powered off while suspending, the interrupt line will go low since it's > no longer powered and wake the system. For this reason we should respect > the board designers wishes and honor the wake bit defined on the > GpioInt. > > This change does not cover the ACPI Interrupt or IRQ resources. > > Signed-off-by: Raul E Rangel <rrangel@chromium.org> > --- > > drivers/i2c/i2c-core-acpi.c | 8 ++++++-- > drivers/i2c/i2c-core-base.c | 17 +++++++++++------ > drivers/i2c/i2c-core.h | 4 ++-- > 3 files changed, 19 insertions(+), 10 deletions(-) > > diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c > index c762a879c4cc6b..cfe82a6ba3ef28 100644 > --- a/drivers/i2c/i2c-core-acpi.c > +++ b/drivers/i2c/i2c-core-acpi.c > @@ -182,12 +182,13 @@ static int i2c_acpi_add_resource(struct acpi_resource *ares, void *data) > /** > * i2c_acpi_get_irq - get device IRQ number from ACPI > * @client: Pointer to the I2C client device > + * @wake_capable: Set to 1 if the IRQ is wake capable > * > * Find the IRQ number used by a specific client device. > * > * Return: The IRQ number or an error code. > */ > -int i2c_acpi_get_irq(struct i2c_client *client) > +int i2c_acpi_get_irq(struct i2c_client *client, int *wake_capable) > { > struct acpi_device *adev = ACPI_COMPANION(&client->dev); > struct list_head resource_list; > @@ -196,6 +197,9 @@ int i2c_acpi_get_irq(struct i2c_client *client) > > INIT_LIST_HEAD(&resource_list); > > + if (wake_capable) > + *wake_capable = 0; > + > ret = acpi_dev_get_resources(adev, &resource_list, > i2c_acpi_add_resource, &irq); You also need to handle "Interrupt(..., ...AndWake)" case here. I would look into maybe defining #define IORESOURCE_IRQ_WAKECAPABLE (1<<6) in include/linux/ioport.h and plumbing it through from ACPI layer. Thanks.
On Tue, Sep 6, 2022 at 7:00 PM Dmitry Torokhov <dmitry.torokhov@gmail.com> wrote: > > On Tue, Aug 30, 2022 at 05:15:37PM -0600, Raul E Rangel wrote: > > Device tree already has a mechanism to pass the wake_irq. It does this > > by looking for the wakeup-source property and setting the > > I2C_CLIENT_WAKE flag. This CL adds the ACPI equivalent. It uses at the > > ACPI GpioInt wake flag to determine if the interrupt can be used to wake > > the system. Previously the i2c drivers had to make assumptions and > > blindly enable the wake IRQ. This can cause spurious wake events. e.g., > > If there is a device with an Active Low interrupt and the device gets > > powered off while suspending, the interrupt line will go low since it's > > no longer powered and wake the system. For this reason we should respect > > the board designers wishes and honor the wake bit defined on the > > GpioInt. > > > > This change does not cover the ACPI Interrupt or IRQ resources. > > > > Signed-off-by: Raul E Rangel <rrangel@chromium.org> > > --- > > > > drivers/i2c/i2c-core-acpi.c | 8 ++++++-- > > drivers/i2c/i2c-core-base.c | 17 +++++++++++------ > > drivers/i2c/i2c-core.h | 4 ++-- > > 3 files changed, 19 insertions(+), 10 deletions(-) > > > > diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c > > index c762a879c4cc6b..cfe82a6ba3ef28 100644 > > --- a/drivers/i2c/i2c-core-acpi.c > > +++ b/drivers/i2c/i2c-core-acpi.c > > @@ -182,12 +182,13 @@ static int i2c_acpi_add_resource(struct acpi_resource *ares, void *data) > > /** > > * i2c_acpi_get_irq - get device IRQ number from ACPI > > * @client: Pointer to the I2C client device > > + * @wake_capable: Set to 1 if the IRQ is wake capable > > * > > * Find the IRQ number used by a specific client device. > > * > > * Return: The IRQ number or an error code. > > */ > > -int i2c_acpi_get_irq(struct i2c_client *client) > > +int i2c_acpi_get_irq(struct i2c_client *client, int *wake_capable) > > { > > struct acpi_device *adev = ACPI_COMPANION(&client->dev); > > struct list_head resource_list; > > @@ -196,6 +197,9 @@ int i2c_acpi_get_irq(struct i2c_client *client) > > > > INIT_LIST_HEAD(&resource_list); > > > > + if (wake_capable) > > + *wake_capable = 0; > > + > > ret = acpi_dev_get_resources(adev, &resource_list, > > i2c_acpi_add_resource, &irq); > > You also need to handle "Interrupt(..., ...AndWake)" case here. I would > look into maybe defining > > #define IORESOURCE_IRQ_WAKECAPABLE (1<<6) > > in include/linux/ioport.h and plumbing it through from ACPI layer. > > Thanks. AFAIK the Intel (Not 100% certain) and AMD IO-APIC's can't actually wake a system from suspend/suspend-to-idle. It requires either a GPE or GPIO controller to wake the system. This is the reason I haven't pushed patches to handle the Interrupt/IRQ resource. Can anyone confirm? Thanks > > -- > Dmitry
On Tue, Sep 06, 2022 at 08:00:00PM -0600, Raul Rangel wrote: > On Tue, Sep 6, 2022 at 7:00 PM Dmitry Torokhov > <dmitry.torokhov@gmail.com> wrote: > > > > On Tue, Aug 30, 2022 at 05:15:37PM -0600, Raul E Rangel wrote: > > > Device tree already has a mechanism to pass the wake_irq. It does this > > > by looking for the wakeup-source property and setting the > > > I2C_CLIENT_WAKE flag. This CL adds the ACPI equivalent. It uses at the > > > ACPI GpioInt wake flag to determine if the interrupt can be used to wake > > > the system. Previously the i2c drivers had to make assumptions and > > > blindly enable the wake IRQ. This can cause spurious wake events. e.g., > > > If there is a device with an Active Low interrupt and the device gets > > > powered off while suspending, the interrupt line will go low since it's > > > no longer powered and wake the system. For this reason we should respect > > > the board designers wishes and honor the wake bit defined on the > > > GpioInt. > > > > > > This change does not cover the ACPI Interrupt or IRQ resources. > > > > > > Signed-off-by: Raul E Rangel <rrangel@chromium.org> > > > --- > > > > > > drivers/i2c/i2c-core-acpi.c | 8 ++++++-- > > > drivers/i2c/i2c-core-base.c | 17 +++++++++++------ > > > drivers/i2c/i2c-core.h | 4 ++-- > > > 3 files changed, 19 insertions(+), 10 deletions(-) > > > > > > diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c > > > index c762a879c4cc6b..cfe82a6ba3ef28 100644 > > > --- a/drivers/i2c/i2c-core-acpi.c > > > +++ b/drivers/i2c/i2c-core-acpi.c > > > @@ -182,12 +182,13 @@ static int i2c_acpi_add_resource(struct acpi_resource *ares, void *data) > > > /** > > > * i2c_acpi_get_irq - get device IRQ number from ACPI > > > * @client: Pointer to the I2C client device > > > + * @wake_capable: Set to 1 if the IRQ is wake capable > > > * > > > * Find the IRQ number used by a specific client device. > > > * > > > * Return: The IRQ number or an error code. > > > */ > > > -int i2c_acpi_get_irq(struct i2c_client *client) > > > +int i2c_acpi_get_irq(struct i2c_client *client, int *wake_capable) > > > { > > > struct acpi_device *adev = ACPI_COMPANION(&client->dev); > > > struct list_head resource_list; > > > @@ -196,6 +197,9 @@ int i2c_acpi_get_irq(struct i2c_client *client) > > > > > > INIT_LIST_HEAD(&resource_list); > > > > > > + if (wake_capable) > > > + *wake_capable = 0; > > > + > > > ret = acpi_dev_get_resources(adev, &resource_list, > > > i2c_acpi_add_resource, &irq); > > > > > > You also need to handle "Interrupt(..., ...AndWake)" case here. I would > > look into maybe defining > > > > #define IORESOURCE_IRQ_WAKECAPABLE (1<<6) > > > > in include/linux/ioport.h and plumbing it through from ACPI layer. > > > > Thanks. > > AFAIK the Intel (Not 100% certain) and AMD IO-APIC's can't actually > wake a system from suspend/suspend-to-idle. It requires either a GPE > or GPIO controller to wake the system. This is the reason I haven't > pushed patches to handle the Interrupt/IRQ resource. Can anyone > confirm? I've heard there are ARM ACPI systems... Thanks.
Hi, On 9/7/22 04:00, Raul Rangel wrote: > On Tue, Sep 6, 2022 at 7:00 PM Dmitry Torokhov > <dmitry.torokhov@gmail.com> wrote: >> >> On Tue, Aug 30, 2022 at 05:15:37PM -0600, Raul E Rangel wrote: >>> Device tree already has a mechanism to pass the wake_irq. It does this >>> by looking for the wakeup-source property and setting the >>> I2C_CLIENT_WAKE flag. This CL adds the ACPI equivalent. It uses at the >>> ACPI GpioInt wake flag to determine if the interrupt can be used to wake >>> the system. Previously the i2c drivers had to make assumptions and >>> blindly enable the wake IRQ. This can cause spurious wake events. e.g., >>> If there is a device with an Active Low interrupt and the device gets >>> powered off while suspending, the interrupt line will go low since it's >>> no longer powered and wake the system. For this reason we should respect >>> the board designers wishes and honor the wake bit defined on the >>> GpioInt. >>> >>> This change does not cover the ACPI Interrupt or IRQ resources. >>> >>> Signed-off-by: Raul E Rangel <rrangel@chromium.org> >>> --- >>> >>> drivers/i2c/i2c-core-acpi.c | 8 ++++++-- >>> drivers/i2c/i2c-core-base.c | 17 +++++++++++------ >>> drivers/i2c/i2c-core.h | 4 ++-- >>> 3 files changed, 19 insertions(+), 10 deletions(-) >>> >>> diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c >>> index c762a879c4cc6b..cfe82a6ba3ef28 100644 >>> --- a/drivers/i2c/i2c-core-acpi.c >>> +++ b/drivers/i2c/i2c-core-acpi.c >>> @@ -182,12 +182,13 @@ static int i2c_acpi_add_resource(struct acpi_resource *ares, void *data) >>> /** >>> * i2c_acpi_get_irq - get device IRQ number from ACPI >>> * @client: Pointer to the I2C client device >>> + * @wake_capable: Set to 1 if the IRQ is wake capable >>> * >>> * Find the IRQ number used by a specific client device. >>> * >>> * Return: The IRQ number or an error code. >>> */ >>> -int i2c_acpi_get_irq(struct i2c_client *client) >>> +int i2c_acpi_get_irq(struct i2c_client *client, int *wake_capable) >>> { >>> struct acpi_device *adev = ACPI_COMPANION(&client->dev); >>> struct list_head resource_list; >>> @@ -196,6 +197,9 @@ int i2c_acpi_get_irq(struct i2c_client *client) >>> >>> INIT_LIST_HEAD(&resource_list); >>> >>> + if (wake_capable) >>> + *wake_capable = 0; >>> + >>> ret = acpi_dev_get_resources(adev, &resource_list, >>> i2c_acpi_add_resource, &irq); >> > > >> You also need to handle "Interrupt(..., ...AndWake)" case here. I would >> look into maybe defining >> >> #define IORESOURCE_IRQ_WAKECAPABLE (1<<6) >> >> in include/linux/ioport.h and plumbing it through from ACPI layer. >> >> Thanks. > > AFAIK the Intel (Not 100% certain) and AMD IO-APIC's can't actually > wake a system from suspend/suspend-to-idle. That may be true for S3 suspend (it sounds about right) there certainly is no way to "arm for wakeup" on the APIC, but with s2idle all IRQs which are not explicitly disabled by the OS still function normally so there any IRQ can be a wakeup source (AFAIK). And even with S3 suspend I think some IRQs can act as wakeup, but that is configured by the BIOS then and not something which linux can enable/disable. E.g IIRC the parent IRQ of the GPIO controllers on x86 is an APIC IRQ ... Regards, Hans
On Wed, Sep 7, 2022 at 2:12 AM Hans de Goede <hdegoede@redhat.com> wrote: > > Hi, > > On 9/7/22 04:00, Raul Rangel wrote: > > On Tue, Sep 6, 2022 at 7:00 PM Dmitry Torokhov > > <dmitry.torokhov@gmail.com> wrote: > >> > >> On Tue, Aug 30, 2022 at 05:15:37PM -0600, Raul E Rangel wrote: > >>> Device tree already has a mechanism to pass the wake_irq. It does this > >>> by looking for the wakeup-source property and setting the > >>> I2C_CLIENT_WAKE flag. This CL adds the ACPI equivalent. It uses at the > >>> ACPI GpioInt wake flag to determine if the interrupt can be used to wake > >>> the system. Previously the i2c drivers had to make assumptions and > >>> blindly enable the wake IRQ. This can cause spurious wake events. e.g., > >>> If there is a device with an Active Low interrupt and the device gets > >>> powered off while suspending, the interrupt line will go low since it's > >>> no longer powered and wake the system. For this reason we should respect > >>> the board designers wishes and honor the wake bit defined on the > >>> GpioInt. > >>> > >>> This change does not cover the ACPI Interrupt or IRQ resources. > >>> > >>> Signed-off-by: Raul E Rangel <rrangel@chromium.org> > >>> --- > >>> > >>> drivers/i2c/i2c-core-acpi.c | 8 ++++++-- > >>> drivers/i2c/i2c-core-base.c | 17 +++++++++++------ > >>> drivers/i2c/i2c-core.h | 4 ++-- > >>> 3 files changed, 19 insertions(+), 10 deletions(-) > >>> > >>> diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c > >>> index c762a879c4cc6b..cfe82a6ba3ef28 100644 > >>> --- a/drivers/i2c/i2c-core-acpi.c > >>> +++ b/drivers/i2c/i2c-core-acpi.c > >>> @@ -182,12 +182,13 @@ static int i2c_acpi_add_resource(struct acpi_resource *ares, void *data) > >>> /** > >>> * i2c_acpi_get_irq - get device IRQ number from ACPI > >>> * @client: Pointer to the I2C client device > >>> + * @wake_capable: Set to 1 if the IRQ is wake capable > >>> * > >>> * Find the IRQ number used by a specific client device. > >>> * > >>> * Return: The IRQ number or an error code. > >>> */ > >>> -int i2c_acpi_get_irq(struct i2c_client *client) > >>> +int i2c_acpi_get_irq(struct i2c_client *client, int *wake_capable) > >>> { > >>> struct acpi_device *adev = ACPI_COMPANION(&client->dev); > >>> struct list_head resource_list; > >>> @@ -196,6 +197,9 @@ int i2c_acpi_get_irq(struct i2c_client *client) > >>> > >>> INIT_LIST_HEAD(&resource_list); > >>> > >>> + if (wake_capable) > >>> + *wake_capable = 0; > >>> + > >>> ret = acpi_dev_get_resources(adev, &resource_list, > >>> i2c_acpi_add_resource, &irq); > >> > > > > > >> You also need to handle "Interrupt(..., ...AndWake)" case here. I would > >> look into maybe defining > >> > >> #define IORESOURCE_IRQ_WAKECAPABLE (1<<6) > >> > >> in include/linux/ioport.h and plumbing it through from ACPI layer. > >> > >> Thanks. > > > > AFAIK the Intel (Not 100% certain) and AMD IO-APIC's can't actually > > wake a system from suspend/suspend-to-idle. > > That may be true for S3 suspend (it sounds about right) there > certainly is no way to "arm for wakeup" on the APIC, but with > s2idle all IRQs which are not explicitly disabled by the OS > still function normally so there any IRQ can be a wakeup > source (AFAIK). > > And even with S3 suspend I think some IRQs can act as wakeup, > but that is configured by the BIOS then and not something which > linux can enable/disable. E.g IIRC the parent IRQ of the GPIO > controllers on x86 is an APIC IRQ ... > > Regards, > > Hans > SGTM. I wanted to make sure there was interest before I invested the time in adding the functionality. Hopefully I can push up a new patch set tomorrow.
On Thu, Sep 8, 2022 at 4:40 PM Raul Rangel <rrangel@chromium.org> wrote: > > On Wed, Sep 7, 2022 at 2:12 AM Hans de Goede <hdegoede@redhat.com> wrote: > > > > Hi, > > > > On 9/7/22 04:00, Raul Rangel wrote: > > > On Tue, Sep 6, 2022 at 7:00 PM Dmitry Torokhov > > > <dmitry.torokhov@gmail.com> wrote: > > >> > > >> On Tue, Aug 30, 2022 at 05:15:37PM -0600, Raul E Rangel wrote: > > >>> Device tree already has a mechanism to pass the wake_irq. It does this > > >>> by looking for the wakeup-source property and setting the > > >>> I2C_CLIENT_WAKE flag. This CL adds the ACPI equivalent. It uses at the > > >>> ACPI GpioInt wake flag to determine if the interrupt can be used to wake > > >>> the system. Previously the i2c drivers had to make assumptions and > > >>> blindly enable the wake IRQ. This can cause spurious wake events. e.g., > > >>> If there is a device with an Active Low interrupt and the device gets > > >>> powered off while suspending, the interrupt line will go low since it's > > >>> no longer powered and wake the system. For this reason we should respect > > >>> the board designers wishes and honor the wake bit defined on the > > >>> GpioInt. > > >>> > > >>> This change does not cover the ACPI Interrupt or IRQ resources. > > >>> > > >>> Signed-off-by: Raul E Rangel <rrangel@chromium.org> > > >>> --- > > >>> > > >>> drivers/i2c/i2c-core-acpi.c | 8 ++++++-- > > >>> drivers/i2c/i2c-core-base.c | 17 +++++++++++------ > > >>> drivers/i2c/i2c-core.h | 4 ++-- > > >>> 3 files changed, 19 insertions(+), 10 deletions(-) > > >>> > > >>> diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c > > >>> index c762a879c4cc6b..cfe82a6ba3ef28 100644 > > >>> --- a/drivers/i2c/i2c-core-acpi.c > > >>> +++ b/drivers/i2c/i2c-core-acpi.c > > >>> @@ -182,12 +182,13 @@ static int i2c_acpi_add_resource(struct acpi_resource *ares, void *data) > > >>> /** > > >>> * i2c_acpi_get_irq - get device IRQ number from ACPI > > >>> * @client: Pointer to the I2C client device > > >>> + * @wake_capable: Set to 1 if the IRQ is wake capable > > >>> * > > >>> * Find the IRQ number used by a specific client device. > > >>> * > > >>> * Return: The IRQ number or an error code. > > >>> */ > > >>> -int i2c_acpi_get_irq(struct i2c_client *client) > > >>> +int i2c_acpi_get_irq(struct i2c_client *client, int *wake_capable) > > >>> { > > >>> struct acpi_device *adev = ACPI_COMPANION(&client->dev); > > >>> struct list_head resource_list; > > >>> @@ -196,6 +197,9 @@ int i2c_acpi_get_irq(struct i2c_client *client) > > >>> > > >>> INIT_LIST_HEAD(&resource_list); > > >>> > > >>> + if (wake_capable) > > >>> + *wake_capable = 0; > > >>> + > > >>> ret = acpi_dev_get_resources(adev, &resource_list, > > >>> i2c_acpi_add_resource, &irq); > > >> > > > > > > > > >> You also need to handle "Interrupt(..., ...AndWake)" case here. I would > > >> look into maybe defining > > >> > > >> #define IORESOURCE_IRQ_WAKECAPABLE (1<<6) > > >> > > >> in include/linux/ioport.h and plumbing it through from ACPI layer. > > >> > > >> Thanks. > > > > > > AFAIK the Intel (Not 100% certain) and AMD IO-APIC's can't actually > > > wake a system from suspend/suspend-to-idle. > > > > That may be true for S3 suspend (it sounds about right) there > > certainly is no way to "arm for wakeup" on the APIC, but with > > s2idle all IRQs which are not explicitly disabled by the OS > > still function normally so there any IRQ can be a wakeup > > source (AFAIK). That's true. Moreover, even for S3 there are transitions into it and there may be wakeup interrupts taking place during those transitions. Those may be any IRQs too. > > And even with S3 suspend I think some IRQs can act as wakeup, > > but that is configured by the BIOS then and not something which > > linux can enable/disable. E.g IIRC the parent IRQ of the GPIO > > controllers on x86 is an APIC IRQ ... It's more about how the system is wired up AFAICS. Basically, in order to wake up the system from S3, the given IRQ needs to be physically attached to an input that will trigger the platform wakeup logic while in S3. > > > > SGTM. I wanted to make sure there was interest before I invested the > time in adding the functionality. Hopefully I can push up a new patch > set tomorrow. Sounds good. :-)
It looks like `i2c_acpi_get_irq` and `platform_get_irq_optional` are doing pretty much the same thing. Can we replace `i2c_acpi_get_irq` and switch over to `platform_get_irq_optional`? Is it possible to get a `platform_device` from an `i2c_client`? On Thu, Sep 8, 2022 at 9:23 AM Rafael J. Wysocki <rafael@kernel.org> wrote: > > On Thu, Sep 8, 2022 at 4:40 PM Raul Rangel <rrangel@chromium.org> wrote: > > > > On Wed, Sep 7, 2022 at 2:12 AM Hans de Goede <hdegoede@redhat.com> wrote: > > > > > > Hi, > > > > > > On 9/7/22 04:00, Raul Rangel wrote: > > > > On Tue, Sep 6, 2022 at 7:00 PM Dmitry Torokhov > > > > <dmitry.torokhov@gmail.com> wrote: > > > >> > > > >> On Tue, Aug 30, 2022 at 05:15:37PM -0600, Raul E Rangel wrote: > > > >>> Device tree already has a mechanism to pass the wake_irq. It does this > > > >>> by looking for the wakeup-source property and setting the > > > >>> I2C_CLIENT_WAKE flag. This CL adds the ACPI equivalent. It uses at the > > > >>> ACPI GpioInt wake flag to determine if the interrupt can be used to wake > > > >>> the system. Previously the i2c drivers had to make assumptions and > > > >>> blindly enable the wake IRQ. This can cause spurious wake events. e.g., > > > >>> If there is a device with an Active Low interrupt and the device gets > > > >>> powered off while suspending, the interrupt line will go low since it's > > > >>> no longer powered and wake the system. For this reason we should respect > > > >>> the board designers wishes and honor the wake bit defined on the > > > >>> GpioInt. > > > >>> > > > >>> This change does not cover the ACPI Interrupt or IRQ resources. > > > >>> > > > >>> Signed-off-by: Raul E Rangel <rrangel@chromium.org> > > > >>> --- > > > >>> > > > >>> drivers/i2c/i2c-core-acpi.c | 8 ++++++-- > > > >>> drivers/i2c/i2c-core-base.c | 17 +++++++++++------ > > > >>> drivers/i2c/i2c-core.h | 4 ++-- > > > >>> 3 files changed, 19 insertions(+), 10 deletions(-) > > > >>> > > > >>> diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c > > > >>> index c762a879c4cc6b..cfe82a6ba3ef28 100644 > > > >>> --- a/drivers/i2c/i2c-core-acpi.c > > > >>> +++ b/drivers/i2c/i2c-core-acpi.c > > > >>> @@ -182,12 +182,13 @@ static int i2c_acpi_add_resource(struct acpi_resource *ares, void *data) > > > >>> /** > > > >>> * i2c_acpi_get_irq - get device IRQ number from ACPI > > > >>> * @client: Pointer to the I2C client device > > > >>> + * @wake_capable: Set to 1 if the IRQ is wake capable > > > >>> * > > > >>> * Find the IRQ number used by a specific client device. > > > >>> * > > > >>> * Return: The IRQ number or an error code. > > > >>> */ > > > >>> -int i2c_acpi_get_irq(struct i2c_client *client) > > > >>> +int i2c_acpi_get_irq(struct i2c_client *client, int *wake_capable) > > > >>> { > > > >>> struct acpi_device *adev = ACPI_COMPANION(&client->dev); > > > >>> struct list_head resource_list; > > > >>> @@ -196,6 +197,9 @@ int i2c_acpi_get_irq(struct i2c_client *client) > > > >>> > > > >>> INIT_LIST_HEAD(&resource_list); > > > >>> > > > >>> + if (wake_capable) > > > >>> + *wake_capable = 0; > > > >>> + > > > >>> ret = acpi_dev_get_resources(adev, &resource_list, > > > >>> i2c_acpi_add_resource, &irq); > > > >> > > > > > > > > > > > >> You also need to handle "Interrupt(..., ...AndWake)" case here. I would > > > >> look into maybe defining > > > >> > > > >> #define IORESOURCE_IRQ_WAKECAPABLE (1<<6) > > > >> > > > >> in include/linux/ioport.h and plumbing it through from ACPI layer. > > > >> > > > >> Thanks. > > > > > > > > AFAIK the Intel (Not 100% certain) and AMD IO-APIC's can't actually > > > > wake a system from suspend/suspend-to-idle. > > > > > > That may be true for S3 suspend (it sounds about right) there > > > certainly is no way to "arm for wakeup" on the APIC, but with > > > s2idle all IRQs which are not explicitly disabled by the OS > > > still function normally so there any IRQ can be a wakeup > > > source (AFAIK). > > That's true. > > Moreover, even for S3 there are transitions into it and there may be > wakeup interrupts taking place during those transitions. Those may be > any IRQs too. > > > > And even with S3 suspend I think some IRQs can act as wakeup, > > > but that is configured by the BIOS then and not something which > > > linux can enable/disable. E.g IIRC the parent IRQ of the GPIO > > > controllers on x86 is an APIC IRQ ... > > It's more about how the system is wired up AFAICS. Basically, in > order to wake up the system from S3, the given IRQ needs to be > physically attached to an input that will trigger the platform wakeup > logic while in S3. > > > > > > > > SGTM. I wanted to make sure there was interest before I invested the > > time in adding the functionality. Hopefully I can push up a new patch > > set tomorrow. > > Sounds good. :-)
On Fri, Sep 09, 2022 at 12:47:11PM -0600, Raul Rangel wrote: > It looks like `i2c_acpi_get_irq` and `platform_get_irq_optional` are > doing pretty much the same thing. Can we replace `i2c_acpi_get_irq` > and switch over to `platform_get_irq_optional`? Is it possible to get > a `platform_device` from an `i2c_client`? No, they are completely different objects. struct device / | \ platform_device i2c_client spi_device ... Also, please no top-posting on kernel mailing lists. Thanks.
diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c index c762a879c4cc6b..cfe82a6ba3ef28 100644 --- a/drivers/i2c/i2c-core-acpi.c +++ b/drivers/i2c/i2c-core-acpi.c @@ -182,12 +182,13 @@ static int i2c_acpi_add_resource(struct acpi_resource *ares, void *data) /** * i2c_acpi_get_irq - get device IRQ number from ACPI * @client: Pointer to the I2C client device + * @wake_capable: Set to 1 if the IRQ is wake capable * * Find the IRQ number used by a specific client device. * * Return: The IRQ number or an error code. */ -int i2c_acpi_get_irq(struct i2c_client *client) +int i2c_acpi_get_irq(struct i2c_client *client, int *wake_capable) { struct acpi_device *adev = ACPI_COMPANION(&client->dev); struct list_head resource_list; @@ -196,6 +197,9 @@ int i2c_acpi_get_irq(struct i2c_client *client) INIT_LIST_HEAD(&resource_list); + if (wake_capable) + *wake_capable = 0; + ret = acpi_dev_get_resources(adev, &resource_list, i2c_acpi_add_resource, &irq); if (ret < 0) @@ -204,7 +208,7 @@ int i2c_acpi_get_irq(struct i2c_client *client) acpi_dev_free_resource_list(&resource_list); if (irq == -ENOENT) - irq = acpi_dev_gpio_irq_get(adev, 0); + irq = acpi_dev_gpio_irq_get_wake(adev, 0, wake_capable); return irq; } diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index 91007558bcb260..88f4ef76235f4e 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -468,6 +468,7 @@ static int i2c_device_probe(struct device *dev) struct i2c_client *client = i2c_verify_client(dev); struct i2c_driver *driver; int status; + int acpi_wake_capable = 0; if (!client) return 0; @@ -487,7 +488,7 @@ static int i2c_device_probe(struct device *dev) if (irq == -EINVAL || irq == -ENODATA) irq = of_irq_get(dev->of_node, 0); } else if (ACPI_COMPANION(dev)) { - irq = i2c_acpi_get_irq(client); + irq = i2c_acpi_get_irq(client, &acpi_wake_capable); } if (irq == -EPROBE_DEFER) { status = irq; @@ -513,13 +514,17 @@ static int i2c_device_probe(struct device *dev) goto put_sync_adapter; } - if (client->flags & I2C_CLIENT_WAKE) { + if (client->flags & I2C_CLIENT_WAKE || acpi_wake_capable) { int wakeirq; - wakeirq = of_irq_get_byname(dev->of_node, "wakeup"); - if (wakeirq == -EPROBE_DEFER) { - status = wakeirq; - goto put_sync_adapter; + if (acpi_wake_capable) { + wakeirq = client->irq; + } else { + wakeirq = of_irq_get_byname(dev->of_node, "wakeup"); + if (wakeirq == -EPROBE_DEFER) { + status = wakeirq; + goto put_sync_adapter; + } } device_init_wakeup(&client->dev, true); diff --git a/drivers/i2c/i2c-core.h b/drivers/i2c/i2c-core.h index 87e2c914f1c57b..8e336638a0cd2e 100644 --- a/drivers/i2c/i2c-core.h +++ b/drivers/i2c/i2c-core.h @@ -61,11 +61,11 @@ static inline int __i2c_check_suspended(struct i2c_adapter *adap) #ifdef CONFIG_ACPI void i2c_acpi_register_devices(struct i2c_adapter *adap); -int i2c_acpi_get_irq(struct i2c_client *client); +int i2c_acpi_get_irq(struct i2c_client *client, int *wake_capable); #else /* CONFIG_ACPI */ static inline void i2c_acpi_register_devices(struct i2c_adapter *adap) { } -static inline int i2c_acpi_get_irq(struct i2c_client *client) +static inline int i2c_acpi_get_irq(struct i2c_client *client, int *wake_capable) { return 0; }
Device tree already has a mechanism to pass the wake_irq. It does this by looking for the wakeup-source property and setting the I2C_CLIENT_WAKE flag. This CL adds the ACPI equivalent. It uses at the ACPI GpioInt wake flag to determine if the interrupt can be used to wake the system. Previously the i2c drivers had to make assumptions and blindly enable the wake IRQ. This can cause spurious wake events. e.g., If there is a device with an Active Low interrupt and the device gets powered off while suspending, the interrupt line will go low since it's no longer powered and wake the system. For this reason we should respect the board designers wishes and honor the wake bit defined on the GpioInt. This change does not cover the ACPI Interrupt or IRQ resources. Signed-off-by: Raul E Rangel <rrangel@chromium.org> --- drivers/i2c/i2c-core-acpi.c | 8 ++++++-- drivers/i2c/i2c-core-base.c | 17 +++++++++++------ drivers/i2c/i2c-core.h | 4 ++-- 3 files changed, 19 insertions(+), 10 deletions(-)