From: Raul E Rangel <hidden> Date: 2022-09-12 22:13:54
Today, i2c drivers are making the assumption that their IRQs can also
be used as wake IRQs. This isn't always the case and it can lead to
spurious wakes. This has recently started to affect AMD Chromebooks.
With the introduction of
d62bd5ce12d7 ("pinctrl: amd: Implement irq_set_wake"), the AMD GPIO
controller gained the capability to set the wake bit on each GPIO. The
ACPI specification defines two ways to inform the system if a device is
wake capable:
1) The _PRW object defines the GPE that can be used to wake the system.
2) Setting ExclusiveAndWake or SharedAndWake in the _CRS GpioInt.
Currently only the first method is supported. The i2c drivers don't have
any indication that the IRQ is wake capable, so they guess. This causes
spurious interrupts, for example:
* We have an ACPI HID device that has `_PR0` and `_PR3`. It doesn't have
`_PRW` or `ExclusiveAndWake` so that means the device can't wake the
system.
* The IRQ line is active level low for this device and is pulled up by
the power resource defined in `_PR0`/`_PR3`.
* The i2c driver will (incorrectly) arm the GPIO for wake by calling
`enable_irq_wake` as part of its suspend hook.
* ACPI will power down the device since it doesn't have a wake GPE
associated with it.
* When the device is powered down, the IRQ line will drop, and it will
trigger a wake event.
See the following debug log:
[ 42.335804] PM: Suspending system (s2idle)
[ 42.340186] amd_gpio AMD0030:00: RX: Setting wake for pin 89 to enable
[ 42.467736] power-0416 __acpi_power_off : Power resource [PR00] turned off
[ 42.467739] device_pm-0280 device_set_power : Device [H05D] transitioned to D3cold
[ 42.475210] PM: pm_system_irq_wakeup: 11 triggered pinctrl_amd
[ 42.535293] PM: Wakeup unrelated to ACPI SCI
[ 42.535294] PM: resume from suspend-to-idle
In order to fix this, we need to take into account the wake capable bit
defined on the Interrupt/GpioInt. This is accomplished by:
* Migrating some of the i2c drivers over to using the PM subsystem to
manage the wake IRQ.
* Expose the wake_capable bit from the ACPI Interrupt/GpioInt resource
to the i2c core.
* Use the wake_capable bit in the i2c core to call
`dev_pm_set_wake_irq`. This reuses the existing device tree flow.
* Make the i2c drivers stop calling `dev_pm_set_wake_irq` since it's now
handled by the i2c core.
* Make the ACPI device PM system aware of the wake_irq. This is
necessary so the device doesn't incorrectly get powered down when a
wake_irq is enabled.
I've tested this code with various combinations of having _PRW,
ExclusiveAndWake and power resources all defined or not defined, but it
would be great if others could test this out on their hardware.
I'm sure this will surface some devices where the IRQs were not
correctly marked as wake capable. Ideally the firmware can be fixed, but
if not we can work around this in the kernel by providing a board
specific `struct i2c_board_info` with the `I2C_CLIENT_WAKE` flag set.
See `chromeos_laptop.c` for an example of matching DMI properties and
setting the `I2C_CLIENT_WAKE` override.
Thanks,
Raul
Changes in v2:
- Added elants_i2c to series
- Added raydium_ts_i2c to series
- Fixed call site in mlxbf_gige_probe
- Added ability to extract wake bit from Interrupt/IRQ resources
- Look at wake_cabple bit for IRQ/Interrupt resources
- I chose not to keep the legacy code around since systems without DT or ACPI should be rare.
Raul E Rangel (13):
HID: i2c-hid: Use PM subsystem to manage wake irq
Input: elan_i2c - Use PM subsystem to manage wake irq
Input: elants_i2c - Use PM subsystem to manage wake irq
Input: raydium_ts_i2c - Use PM subsystem to manage wake irq
gpiolib: acpi: Add wake_capable parameter to acpi_dev_gpio_irq_get_by
ACPI: resources: Add wake_capable parameter to acpi_dev_irq_flags
i2c: acpi: Use ACPI wake capability bit to set wake_irq
ACPI: PM: Take wake IRQ into consideration when entering
suspend-to-idle
HID: i2c-hid: acpi: Stop setting wakeup_capable
HID: i2c-hid: Don't set wake_capable and wake_irq
Input: elan_i2c - Don't set wake_capable and wake_irq
Input: elants_i2c - Don't set wake_capable and wake_irq
Input: raydium_ts_i2c - Don't set wake_capable and wake_irq
drivers/acpi/device_pm.c | 19 +++++++++-
drivers/acpi/irq.c | 11 ++++--
drivers/acpi/resource.c | 24 ++++++++----
drivers/gpio/gpio-pca953x.c | 3 +-
drivers/gpio/gpiolib-acpi.c | 11 +++++-
drivers/gpio/gpiolib-acpi.h | 2 +
drivers/hid/i2c-hid/i2c-hid-acpi.c | 5 ---
drivers/hid/i2c-hid/i2c-hid-core.c | 24 ++----------
drivers/i2c/i2c-core-acpi.c | 37 ++++++++++++++-----
drivers/i2c/i2c-core-base.c | 6 ++-
drivers/i2c/i2c-core.h | 4 +-
drivers/input/mouse/elan_i2c_core.c | 15 +-------
drivers/input/touchscreen/elants_i2c.c | 13 +------
drivers/input/touchscreen/raydium_i2c_ts.c | 7 +---
.../mellanox/mlxbf_gige/mlxbf_gige_main.c | 3 +-
drivers/pnp/pnpacpi/rsparser.c | 9 +++--
include/linux/acpi.h | 17 +++++++--
include/linux/ioport.h | 3 +-
18 files changed, 121 insertions(+), 92 deletions(-)
--
2.37.2.789.g6183377224-goog
From: Raul E Rangel <hidden> Date: 2022-09-12 22:14:00
The I2C hid driver is currently manually managing the wake
IRQ. This change removes the explicit enable_irq_wake/disable_irq_wake
and instead relies on the PM subsystem. This is done by calling
dev_pm_set_wake_irq.
i2c_device_probe already calls dev_pm_set_wake_irq when using device
tree, and i2c_device_remove also already calls dev_pm_clear_wake_irq.
There could be some device tree systems that have incorrectly declared
`wake` capabilities, so this change will set the wake irq if one is
missing. This matches the previous behavior.
I tested this on an ACPI system that has a HID touchscreen and verified
the IRQ was armed for wake on suspend.
Signed-off-by: Raul E Rangel <redacted>
---
Changes in v2:
- Set the wake_irq when not configured by the i2c-core. This is
different than v1, where the wake_irq was only set for non DT systems.
drivers/hid/i2c-hid/i2c-hid-core.c | 33 +++++++++++-------------------
1 file changed, 12 insertions(+), 21 deletions(-)
From: Raul E Rangel <hidden> Date: 2022-09-12 22:14:08
The Elan I2C touchpad driver is currently manually managing the wake
IRQ. This change removes the explicit enable_irq_wake/disable_irq_wake
and instead relies on the PM subsystem. This is done by calling
dev_pm_set_wake_irq.
i2c_device_probe already calls dev_pm_set_wake_irq when using device
tree, and i2c_device_remove also already calls dev_pm_clear_wake_irq.
There could be some device tree systems that have incorrectly declared
`wake` capabilities, so this change will set the wake irq if one is
missing. This matches the previous behavior.
I tested this on an ACPI system where the touchpad doesn't have _PRW
defined. I verified I can still wake the system and that the wake source
was the touchpad IRQ GPIO.
Signed-off-by: Raul E Rangel <redacted>
---
Changes in v2:
- Set the wake_irq when not configured by the i2c-core. This is
different than v1, where the wake_irq was only set for non DT systems.
drivers/input/mouse/elan_i2c_core.c | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
@@ -1340,6 +1339,15 @@ static int elan_probe(struct i2c_client *client,if(!dev->of_node)device_init_wakeup(dev,true);+/*+*ThewakeIRQshouldbedeclaredviadevicetreeinsteadofassuming+*theIRQcanwakethesystem.Thisishereforlegacyreasonsand+*willberemovedoncethei2c-coresupportsqueryingACPIforwake+*capabilities.+*/+if(!dev->power.wakeirq)+dev_pm_set_wake_irq(dev,client->irq);+return0;}
@@ -1362,8 +1370,6 @@ static int __maybe_unused elan_suspend(struct device *dev)if(device_may_wakeup(dev)){ret=elan_sleep(data);-/* Enable wake from IRQ */-data->irq_wake=(enable_irq_wake(client->irq)==0);}else{ret=elan_set_power(data,false);if(ret)
From: Raul E Rangel <hidden> Date: 2022-09-12 22:14:13
The Elan I2C touchscreen driver is currently manually managing the wake
IRQ. This change removes the explicit enable_irq_wake/disable_irq_wake
and instead relies on the PM subsystem. This is done by calling
dev_pm_set_wake_irq.
i2c_device_probe already calls dev_pm_set_wake_irq when using device
tree, and i2c_device_remove also already calls dev_pm_clear_wake_irq.
There could be some device tree systems that have incorrectly declared
`wake` capabilities, so this change will set the wake irq if one is
missing. This matches the previous behavior.
Signed-off-by: Raul E Rangel <redacted>
---
Changes in v2:
- Added elants_i2c to series
drivers/input/touchscreen/elants_i2c.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
@@ -180,7 +181,6 @@ struct elants_data {u8cmd_resp[HEADER_SIZE];structcompletioncmd_done;-boolwake_irq_enabled;boolkeep_power_in_suspend;/* Must be last to be used for DMA operations */
@@ -1582,6 +1582,15 @@ static int elants_i2c_probe(struct i2c_client *client)if(!client->dev.of_node)device_init_wakeup(&client->dev,true);+/*+*ThewakeIRQshouldbedeclaredviadevicetreeinsteadofassuming+*theIRQcanwakethesystem.Thisishereforlegacyreasonsand+*willberemovedoncethei2c-coresupportsqueryingACPIforwake+*capabilities.+*/+if(!client->dev.power.wakeirq)+dev_pm_set_wake_irq(&client->dev,client->irq);+error=devm_device_add_group(&client->dev,&elants_attribute_group);if(error){dev_err(&client->dev,"failed to create sysfs attributes: %d\n",
@@ -1626,7 +1635,7 @@ static int __maybe_unused elants_i2c_suspend(struct device *dev)*Thedevicewillautomaticallyenteridlemode*thathasreducedpowerconsumption.*/-ts->wake_irq_enabled=(enable_irq_wake(client->irq)==0);+return0;}elseif(ts->keep_power_in_suspend){for(retry_cnt=0;retry_cnt<MAX_RETRIES;retry_cnt++){error=elants_i2c_send(client,set_sleep_cmd,
@@ -1655,8 +1664,6 @@ static int __maybe_unused elants_i2c_resume(struct device *dev)interror;if(device_may_wakeup(dev)){-if(ts->wake_irq_enabled)-disable_irq_wake(client->irq);elants_i2c_sw_reset(client);}elseif(ts->keep_power_in_suspend){for(retry_cnt=0;retry_cnt<MAX_RETRIES;retry_cnt++){
From: Raul E Rangel <hidden> Date: 2022-09-12 22:14:31
The ACPI spec defines the SharedAndWake and ExclusiveAndWake share type
keywords. This is an indication that the GPIO IRQ can also be used as a
wake source. This change exposes the wake_capable bit so drivers can
correctly enable wake functionality instead of making an assumption.
Signed-off-by: Raul E Rangel <redacted>
---
Changes in v2:
- Fixed call site in mlxbf_gige_probe
drivers/gpio/gpio-pca953x.c | 3 ++-
drivers/gpio/gpiolib-acpi.c | 11 ++++++++++-
drivers/gpio/gpiolib-acpi.h | 2 ++
.../ethernet/mellanox/mlxbf_gige/mlxbf_gige_main.c | 3 ++-
include/linux/acpi.h | 14 +++++++++++---
5 files changed, 27 insertions(+), 6 deletions(-)
From: Raul E Rangel <hidden> Date: 2022-09-12 22:14:47
The raydium I2C touchscreen driver is currently manually managing the
wake IRQ. This change removes the explicit enable_irq_wake /
disable_irq_wake and instead relies on the PM subsystem. This is done by
calling dev_pm_set_wake_irq.
i2c_device_probe already calls dev_pm_set_wake_irq when using device
tree, and i2c_device_remove also already calls dev_pm_clear_wake_irq.
There could be some device tree systems that have incorrectly declared
`wake` capabilities, so this change will set the wake irq if one is
missing. This matches the previous behavior.
Signed-off-by: Raul E Rangel <redacted>
---
Changes in v2:
- Added raydium_ts_i2c to series
drivers/input/touchscreen/raydium_i2c_ts.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
From: Raul E Rangel <hidden> Date: 2022-09-12 22:14:51
ACPI IRQ/Interrupt resources contain a bit that describes if the
interrupt should wake the system. This change exposes that bit via
a new IORESOURCE_IRQ_WAKECAPABLE flag. Drivers should check this flag
before arming an IRQ to wake the system.
Signed-off-by: Raul E Rangel <redacted>
---
Changes in v2:
- Added ability to extract wake bit from Interrupt/IRQ resources
drivers/acpi/irq.c | 11 ++++++++---
drivers/acpi/resource.c | 24 +++++++++++++++++-------
drivers/pnp/pnpacpi/rsparser.c | 9 ++++++---
include/linux/acpi.h | 3 ++-
include/linux/ioport.h | 3 ++-
5 files changed, 35 insertions(+), 15 deletions(-)
From: Raul E Rangel <hidden> Date: 2022-09-12 22:15:07
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 the
ACPI interrupt 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 wakes the system. For this reason we should
respect the board designers wishes and honor the wake bit defined on the
interrupt.
Signed-off-by: Raul E Rangel <redacted>
---
Changes in v2:
- Look at wake_cabple bit for IRQ/Interrupt resources
drivers/i2c/i2c-core-acpi.c | 37 ++++++++++++++++++++++++++++---------
drivers/i2c/i2c-core-base.c | 6 +++++-
drivers/i2c/i2c-core.h | 4 ++--
3 files changed, 35 insertions(+), 12 deletions(-)
@@ -170,11 +175,14 @@ static int i2c_acpi_do_lookup(struct acpi_device *adev,staticinti2c_acpi_add_resource(structacpi_resource*ares,void*data){-int*irq=data;+structi2c_acpi_irq_context*irq_ctx=data;structresourcer;-if(*irq<=0&&acpi_dev_resource_interrupt(ares,0,&r))-*irq=i2c_dev_irq_from_resources(&r,1);+if(irq_ctx->irq<=0&&acpi_dev_resource_interrupt(ares,0,&r)){+irq_ctx->irq=i2c_dev_irq_from_resources(&r,1);+irq_ctx->wake_capable=+r.flags&IORESOURCE_IRQ_WAKECAPABLE?1:0;+}return1;/* No need to add resource to the list */}
From: Raul E Rangel <hidden> Date: 2022-09-12 22:15:11
This change adds support for ACPI devices that use ExclusiveAndWake or
SharedAndWake in their _CRS GpioInt definition (instead of using _PRW),
and also provide power resources. Previously the ACPI subsystem had no
idea if the device had a wake capable interrupt armed. This resulted
in the ACPI device PM system placing the device into D3Cold, and thus
cutting power to the device. With this change we will now query the
_S0W method to figure out the appropriate wake capable D-state.
Signed-off-by: Raul E Rangel <redacted>
---
(no changes since v1)
drivers/acpi/device_pm.c | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
From: Raul E Rangel <hidden> Date: 2022-09-12 22:15:19
This is now handled by the i2c-core driver.
Signed-off-by: Raul E Rangel <redacted>
---
(no changes since v1)
drivers/hid/i2c-hid/i2c-hid-acpi.c | 5 -----
1 file changed, 5 deletions(-)
From: Raul E Rangel <hidden> Date: 2022-09-12 22:15:40
The i2c-core will now handle setting the wake_irq for DT and ACPI
systems.
Signed-off-by: Raul E Rangel <redacted>
---
(no changes since v1)
drivers/hid/i2c-hid/i2c-hid-core.c | 9 ---------
1 file changed, 9 deletions(-)
From: Raul E Rangel <hidden> Date: 2022-09-12 22:15:52
The i2c-core will now handle setting the wake_irq and wake capability
for DT and ACPI systems.
Signed-off-by: Raul E Rangel <redacted>
---
Changes in v2:
- I chose not to keep the legacy code around since systems without DT or ACPI should be rare.
drivers/input/mouse/elan_i2c_core.c | 16 ----------------
1 file changed, 16 deletions(-)
From: Raul E Rangel <hidden> Date: 2022-09-12 22:16:00
The i2c-core will now handle setting the wake_irq and wake capability
for DT and ACPI systems.
Signed-off-by: Raul E Rangel <redacted>
---
(no changes since v1)
drivers/input/touchscreen/elants_i2c.c | 16 ----------------
1 file changed, 16 deletions(-)
From: Raul E Rangel <hidden> Date: 2022-09-12 22:16:19
The i2c-core will now handle setting the wake_irq and wake capability
for DT and ACPI systems.
Signed-off-by: Raul E Rangel <redacted>
---
(no changes since v1)
drivers/input/touchscreen/raydium_i2c_ts.c | 9 ---------
1 file changed, 9 deletions(-)
From: Wolfram Sang <wsa@kernel.org> Date: 2022-09-13 07:28:16
On Mon, Sep 12, 2022 at 04:13:11PM -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 the
ACPI interrupt 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 wakes the system. For this reason we should
respect the board designers wishes and honor the wake bit defined on the
interrupt.
I'll let the I2C ACPI maintainers deal with the technical details
because they are the experts here, yet one minor thing hits my eye:
On Tue, Sep 13, 2022 at 1:28 AM Wolfram Sang [off-list ref] wrote:
On Mon, Sep 12, 2022 at 04:13:11PM -0600, Raul E Rangel wrote:
quoted
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 the
ACPI interrupt 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 wakes the system. For this reason we should
respect the board designers wishes and honor the wake bit defined on the
interrupt.
I'll let the I2C ACPI maintainers deal with the technical details
because they are the experts here, yet one minor thing hits my eye:
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Date: 2022-09-13 18:07:40
On Mon, Sep 12, 2022 at 04:13:09PM -0600, Raul E Rangel wrote:
The ACPI spec defines the SharedAndWake and ExclusiveAndWake share type
keywords. This is an indication that the GPIO IRQ can also be used as a
wake source. This change exposes the wake_capable bit so drivers can
correctly enable wake functionality instead of making an assumption.
...
- ret = acpi_dev_gpio_irq_get_by(ACPI_COMPANION(dev), "irq-gpios", 0);
+ ret = acpi_dev_gpio_irq_get_by(ACPI_COMPANION(dev), "irq-gpios", 0,
+ NULL);
if (ret < 0)
return ret;
Looking at these changes, can't we first introduce
int acpi_dev_gpio_irq_get_by_name(struct acpi_device *adev, const char *name);
convert users, and then add wake stuff to the basic function.
In such case you will make less invasive main part of the idea.
--
With Best Regards,
Andy Shevchenko
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Date: 2022-09-13 18:14:25
On Mon, Sep 12, 2022 at 04:13:10PM -0600, Raul E Rangel wrote:
ACPI IRQ/Interrupt resources contain a bit that describes if the
interrupt should wake the system. This change exposes that bit via
a new IORESOURCE_IRQ_WAKECAPABLE flag. Drivers should check this flag
before arming an IRQ to wake the system.
This function is used only in scope of a single C-file. Why instead not
converting it to use some internal structure and acpi_irq_parse_one_cb()
becomes like:
struct internal_struct s;
switch (ares->type) {
case ACPI_RESOURCE_TYPE_IRQ:
...fill internal_struct...
break;
case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
...fill internal_struct...
break;
default:
return AE_OK;
acpi_irq_parse_one_match(&s);
return AE_CTRL_TERMINATE;
?
...
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Date: 2022-09-13 18:17:26
On Mon, Sep 12, 2022 at 04:13:11PM -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 the
ACPI interrupt 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 wakes the system. For this reason we should
respect the board designers wishes and honor the wake bit defined on the
interrupt.
On Tue, Sep 13, 2022 at 11:26 AM Andy Shevchenko
[off-list ref] wrote:
On Mon, Sep 12, 2022 at 04:13:11PM -0600, Raul E Rangel wrote:
quoted
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 the
ACPI interrupt 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 wakes the system. For this reason we should
respect the board designers wishes and honor the wake bit defined on the
interrupt.
Why do we need a parameter and can't simply set this flag inside the callee?
Are you suggesting `i2c_acpi_get_irq` modify the `client->flags`? IMO
that's a little surprising since the I wouldn't expect a `get`
function to modify it's parameters. I'm fine implementing it if others
agree though.
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Date: 2022-09-13 18:51:48
On Tue, Sep 13, 2022 at 12:07:53PM -0600, Raul Rangel wrote:
On Tue, Sep 13, 2022 at 11:26 AM Andy Shevchenko
[off-list ref] wrote:
quoted
On Mon, Sep 12, 2022 at 04:13:11PM -0600, Raul E Rangel wrote:
quoted
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 the
ACPI interrupt 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 wakes the system. For this reason we should
respect the board designers wishes and honor the wake bit defined on the
interrupt.
Why do we need a parameter and can't simply set this flag inside the callee?
Are you suggesting `i2c_acpi_get_irq` modify the `client->flags`? IMO
that's a little surprising since the I wouldn't expect a `get`
function to modify it's parameters. I'm fine implementing it if others
agree though.
This is similar to what of_i2c_get_board_info() does, no?
Note: _get_ there.
--
With Best Regards,
Andy Shevchenko
On Tue, Sep 13, 2022 at 12:33 PM Andy Shevchenko
[off-list ref] wrote:
On Tue, Sep 13, 2022 at 12:07:53PM -0600, Raul Rangel wrote:
quoted
On Tue, Sep 13, 2022 at 11:26 AM Andy Shevchenko
[off-list ref] wrote:
quoted
On Mon, Sep 12, 2022 at 04:13:11PM -0600, Raul E Rangel wrote:
quoted
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 the
ACPI interrupt 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 wakes the system. For this reason we should
respect the board designers wishes and honor the wake bit defined on the
interrupt.
Why do we need a parameter and can't simply set this flag inside the callee?
Are you suggesting `i2c_acpi_get_irq` modify the `client->flags`? IMO
that's a little surprising since the I wouldn't expect a `get`
function to modify it's parameters. I'm fine implementing it if others
agree though.
This is similar to what of_i2c_get_board_info() does, no?
Note: _get_ there.
`*info` is an out parameter in that case. Ideally I would have
`i2c_acpi_get_irq`, `acpi_dev_gpio_irq_get_wake`,
`platform_get_irq_optional`, and `i2c_dev_irq_from_resources` all
return a `struct irq_info {int irq; bool wake_capable;}`. This would
be a larger change though.
From: Mika Westerberg <mika.westerberg@linux.intel.com> Date: 2022-09-14 05:54:26
Hi,
On Mon, Sep 12, 2022 at 04:13:11PM -0600, Raul E Rangel wrote:
quoted hunk
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 the
ACPI interrupt 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 wakes the system. For this reason we should
respect the board designers wishes and honor the wake bit defined on the
interrupt.
Signed-off-by: Raul E Rangel <redacted>
---
Changes in v2:
- Look at wake_cabple bit for IRQ/Interrupt resources
drivers/i2c/i2c-core-acpi.c | 37 ++++++++++++++++++++++++++++---------
drivers/i2c/i2c-core-base.c | 6 +++++-
drivers/i2c/i2c-core.h | 4 ++--
3 files changed, 35 insertions(+), 12 deletions(-)
Then you can just do this:
irq_ctx->wakeable = r.flags & IORESOURCE_IRQ_WAKECAPABLE;
quoted hunk
+ }
return 1; /* No need to add resource to the list */
}
@@ -182,31 +190,42 @@ 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)
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Date: 2022-09-14 09:43:00
On Tue, Sep 13, 2022 at 12:56:37PM -0600, Raul Rangel wrote:
On Tue, Sep 13, 2022 at 12:33 PM Andy Shevchenko
[off-list ref] wrote:
quoted
On Tue, Sep 13, 2022 at 12:07:53PM -0600, Raul Rangel wrote:
...
quoted
This is similar to what of_i2c_get_board_info() does, no?
Note: _get_ there.
`*info` is an out parameter in that case. Ideally I would have
`i2c_acpi_get_irq`, `acpi_dev_gpio_irq_get_wake`,
`platform_get_irq_optional`, and `i2c_dev_irq_from_resources` all
return a `struct irq_info {int irq; bool wake_capable;}`. This would
be a larger change though.
Seems the ACPI analogue is i2c_acpi_fill_info(). Can we do it there?
--
With Best Regards,
Andy Shevchenko
On Tue, Sep 13, 2022 at 11:55 PM Mika Westerberg
[off-list ref] wrote:
Hi,
On Mon, Sep 12, 2022 at 04:13:09PM -0600, Raul E Rangel wrote:
quoted
+int acpi_dev_gpio_irq_get_by(struct acpi_device *adev, const char *name,
+ int index, int *wake_capable)
Here too bool.
I've incorporated both of your suggestions. I instead added
`acpi_dev_gpio_irq_wake_get_by` as the basic function and left
`acpi_dev_gpio_irq_get_by` the same. THis way I don't have to update
any of the callers.
This is similar to what of_i2c_get_board_info() does, no?
Note: _get_ there.
`*info` is an out parameter in that case. Ideally I would have
`i2c_acpi_get_irq`, `acpi_dev_gpio_irq_get_wake`,
`platform_get_irq_optional`, and `i2c_dev_irq_from_resources` all
return a `struct irq_info {int irq; bool wake_capable;}`. This would
be a larger change though.
Seems the ACPI analogue is i2c_acpi_fill_info(). Can we do it there?
So I originally had that thought, but decided against it to avoid
changing too many things,
but since you brought it up, I thought I would try it.
So I moved the GPIO lookup into `i2c_acpi_do_lookup`, but it failed
spectacularly.
I've linked some logs of both cases. grep for `RX:` to see my logging messages.
* https://0paste.com/393416 - Logs with IRQ lookup happening in
`i2c_acpi_do_lookup`
* We can see that `i2c_acpi_do_lookup` gets called in three cases
1) Early on from i2c_acpi_notify when the I2C ACPI nodes are
first created
2) From `i2c_dw_adjust_bus_speed` as part of `dw_i2c_plat_probe`
3) From `i2c_register_adapter` as part of `i2c_dw_probe_master`.
* What happens is that all of these calls happen before the GPIO
chip has been registered.
This means that `acpi_dev_gpio_irq_get` will return `-EPROBE_DEFER`. This
messes something up in the i2c init sequence and the devices are never
probed again.
* You can see the `amd gpio driver loaded` message after all the
i2c probing.
* https://0paste.com/393420 - Logs of a normal boot
* Here we can see the GPIO controller registers early
* We can see the i2c devices being probed by `__driver_attach_async_helper`.
I'm guessing the device was enqueued as part of `i2c_acpi_register_device`
early on and it gets probed later.
I could try moving the gpio lookup into `i2c_acpi_get_info`, but I
think that suffers from the
same problem, the stack can't handle a PROBE_DEFER. So I think we need to keep
the lookup in `i2c_device_probe` for the PROBE_DEFER logic to work correctly.
From: Raul E Rangel <hidden> Date: 2022-09-14 20:49:52
On Tue, Sep 13, 2022 at 08:21:15PM +0300, Andy Shevchenko wrote:
On Mon, Sep 12, 2022 at 04:13:10PM -0600, Raul E Rangel wrote:
quoted
ACPI IRQ/Interrupt resources contain a bit that describes if the
interrupt should wake the system. This change exposes that bit via
a new IORESOURCE_IRQ_WAKECAPABLE flag. Drivers should check this flag
before arming an IRQ to wake the system.
This function is used only in scope of a single C-file. Why instead not
converting it to use some internal structure and acpi_irq_parse_one_cb()
becomes like:
struct internal_struct s;
switch (ares->type) {
case ACPI_RESOURCE_TYPE_IRQ:
...fill internal_struct...
break;
case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
...fill internal_struct...
break;
default:
return AE_OK;
acpi_irq_parse_one_match(&s);
return AE_CTRL_TERMINATE;
?
...
Ditto.
Actually it can be shared structure for these too.
I tried your suggestion, but I honestly think it hurts readability. It's
also a little scary because the compiler doesn't guarantee all the
members of the struct are filled out, unlike having the explicit
parameters. Here is the patch:
On Tue, Sep 13, 2022 at 11:54 PM Mika Westerberg
[off-list ref] wrote:
Hi,
On Mon, Sep 12, 2022 at 04:13:11PM -0600, Raul E Rangel wrote:
quoted
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 the
ACPI interrupt 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 wakes the system. For this reason we should
respect the board designers wishes and honor the wake bit defined on the
interrupt.
Signed-off-by: Raul E Rangel <redacted>
---
Changes in v2:
- Look at wake_cabple bit for IRQ/Interrupt resources
drivers/i2c/i2c-core-acpi.c | 37 ++++++++++++++++++++++++++++---------
drivers/i2c/i2c-core-base.c | 6 +++++-
drivers/i2c/i2c-core.h | 4 ++--
3 files changed, 35 insertions(+), 12 deletions(-)
Then you can just do this:
irq_ctx->wakeable = r.flags & IORESOURCE_IRQ_WAKECAPABLE;
quoted
+ }
return 1; /* No need to add resource to the list */
}
@@ -182,31 +190,42 @@ 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)