2023-05-16 16:59:32

by Matthias Kaehlcke

[permalink] [raw]
Subject: [PATCH] SoC: rt5682: Disable jack detection interrupt during suspend

The rt5682 driver switches its regmap to cache-only when the
device suspends and back to regular mode on resume. When the
jack detect interrupt fires rt5682_irq() schedules the jack
detect work. This can result in invalid reads from the regmap
in cache-only mode if the work runs before the device has
resumed:

[ 56.245502] rt5682 9-001a: ASoC: error at soc_component_read_no_lock on rt5682.9-001a for register: [0x000000f0] -16

Disable the jack detection interrupt during suspend and
re-enable it on resume. The driver already schedules the
jack detection work on resume, so any state change during
suspend is still handled.

This is essentially the same as commit f7d00a9be147 ("SoC:
rt5682s: Disable jack detection interrupt during suspend")
for the rt5682s.

Cc: [email protected]
Signed-off-by: Matthias Kaehlcke <[email protected]>
---

sound/soc/codecs/rt5682-i2c.c | 4 +++-
sound/soc/codecs/rt5682.c | 6 ++++++
sound/soc/codecs/rt5682.h | 1 +
3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/sound/soc/codecs/rt5682-i2c.c b/sound/soc/codecs/rt5682-i2c.c
index 2935c1bb81f3..5bc46b041786 100644
--- a/sound/soc/codecs/rt5682-i2c.c
+++ b/sound/soc/codecs/rt5682-i2c.c
@@ -267,7 +267,9 @@ static int rt5682_i2c_probe(struct i2c_client *i2c)
ret = devm_request_threaded_irq(&i2c->dev, i2c->irq, NULL,
rt5682_irq, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING
| IRQF_ONESHOT, "rt5682", rt5682);
- if (ret)
+ if (!ret)
+ rt5682->irq = i2c->irq;
+ else
dev_err(&i2c->dev, "Failed to reguest IRQ: %d\n", ret);
}

diff --git a/sound/soc/codecs/rt5682.c b/sound/soc/codecs/rt5682.c
index f6c798b65c08..5d992543b791 100644
--- a/sound/soc/codecs/rt5682.c
+++ b/sound/soc/codecs/rt5682.c
@@ -2959,6 +2959,9 @@ static int rt5682_suspend(struct snd_soc_component *component)
if (rt5682->is_sdw)
return 0;

+ if (rt5682->irq)
+ disable_irq(rt5682->irq);
+
cancel_delayed_work_sync(&rt5682->jack_detect_work);
cancel_delayed_work_sync(&rt5682->jd_check_work);
if (rt5682->hs_jack && (rt5682->jack_type & SND_JACK_HEADSET) == SND_JACK_HEADSET) {
@@ -3027,6 +3030,9 @@ static int rt5682_resume(struct snd_soc_component *component)
mod_delayed_work(system_power_efficient_wq,
&rt5682->jack_detect_work, msecs_to_jiffies(0));

+ if (rt5682->irq)
+ enable_irq(rt5682->irq);
+
return 0;
}
#else
diff --git a/sound/soc/codecs/rt5682.h b/sound/soc/codecs/rt5682.h
index d568c6993c33..e8efd8a84a6c 100644
--- a/sound/soc/codecs/rt5682.h
+++ b/sound/soc/codecs/rt5682.h
@@ -1462,6 +1462,7 @@ struct rt5682_priv {
int pll_out[RT5682_PLLS];

int jack_type;
+ int irq;
int irq_work_delay_time;
};

--
2.40.1.606.ga4b1b128d6-goog



2023-05-16 23:15:07

by Doug Anderson

[permalink] [raw]
Subject: Re: [PATCH] SoC: rt5682: Disable jack detection interrupt during suspend

Hi,

On Tue, May 16, 2023 at 9:47 AM Matthias Kaehlcke <[email protected]> wrote:
>
> The rt5682 driver switches its regmap to cache-only when the
> device suspends and back to regular mode on resume. When the
> jack detect interrupt fires rt5682_irq() schedules the jack
> detect work. This can result in invalid reads from the regmap
> in cache-only mode if the work runs before the device has
> resumed:
>
> [ 56.245502] rt5682 9-001a: ASoC: error at soc_component_read_no_lock on rt5682.9-001a for register: [0x000000f0] -16
>
> Disable the jack detection interrupt during suspend and
> re-enable it on resume. The driver already schedules the
> jack detection work on resume, so any state change during
> suspend is still handled.
>
> This is essentially the same as commit f7d00a9be147 ("SoC:
> rt5682s: Disable jack detection interrupt during suspend")
> for the rt5682s.
>
> Cc: [email protected]
> Signed-off-by: Matthias Kaehlcke <[email protected]>

Reviewed-by: Douglas Anderson <[email protected]>

2023-05-17 01:10:06

by Stephen Boyd

[permalink] [raw]
Subject: Re: [PATCH] SoC: rt5682: Disable jack detection interrupt during suspend

Quoting Matthias Kaehlcke (2023-05-16 09:46:30)
> The rt5682 driver switches its regmap to cache-only when the
> device suspends and back to regular mode on resume. When the
> jack detect interrupt fires rt5682_irq() schedules the jack
> detect work. This can result in invalid reads from the regmap
> in cache-only mode if the work runs before the device has
> resumed:

I was wondering why we can't resume the device before device irqs are
enabled (and similarly suspend it after irqs are disabled). It looks
like snd_soc_component_driver is not an actual 'struct driver' instance
so it reimplements PM hooks like suspend and resume for the components
and the suspend hooks run from snd_soc_suspend() at the struct
dev_pm_ops::suspend() path. Adding a noirq variant looks like it isn't
worth it.

>
> [ 56.245502] rt5682 9-001a: ASoC: error at soc_component_read_no_lock on rt5682.9-001a for register: [0x000000f0] -16
>
> Disable the jack detection interrupt during suspend and
> re-enable it on resume. The driver already schedules the
> jack detection work on resume, so any state change during
> suspend is still handled.
>
> This is essentially the same as commit f7d00a9be147 ("SoC:
> rt5682s: Disable jack detection interrupt during suspend")
> for the rt5682s.
>
> Cc: [email protected]
> Signed-off-by: Matthias Kaehlcke <[email protected]>
> ---

Reviewed-by: Stephen Boyd <[email protected]>

> diff --git a/sound/soc/codecs/rt5682-i2c.c b/sound/soc/codecs/rt5682-i2c.c
> index 2935c1bb81f3..5bc46b041786 100644
> --- a/sound/soc/codecs/rt5682-i2c.c
> +++ b/sound/soc/codecs/rt5682-i2c.c
> @@ -267,7 +267,9 @@ static int rt5682_i2c_probe(struct i2c_client *i2c)
> ret = devm_request_threaded_irq(&i2c->dev, i2c->irq, NULL,
> rt5682_irq, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING
> | IRQF_ONESHOT, "rt5682", rt5682);
> - if (ret)
> + if (!ret)
> + rt5682->irq = i2c->irq;
> + else
> dev_err(&i2c->dev, "Failed to reguest IRQ: %d\n", ret);

Not in this patch, but

s/reguest/request/

2023-05-17 02:13:36

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH] SoC: rt5682: Disable jack detection interrupt during suspend

On Tue, May 16, 2023 at 04:46:30PM +0000, Matthias Kaehlcke wrote:
> The rt5682 driver switches its regmap to cache-only when the
> device suspends and back to regular mode on resume. When the
> jack detect interrupt fires rt5682_irq() schedules the jack
> detect work. This can result in invalid reads from the regmap

Please submit patches using subject lines reflecting the style for the
subsystem, this makes it easier for people to identify relevant patches.
Look at what existing commits in the area you're changing are doing and
make sure your subject lines visually resemble what they're doing.
There's no need to resubmit to fix this alone.


Attachments:
(No filename) (661.00 B)
signature.asc (499.00 B)
Download all attachments

2023-05-18 17:33:30

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH] SoC: rt5682: Disable jack detection interrupt during suspend

On Tue, 16 May 2023 16:46:30 +0000, Matthias Kaehlcke wrote:
> The rt5682 driver switches its regmap to cache-only when the
> device suspends and back to regular mode on resume. When the
> jack detect interrupt fires rt5682_irq() schedules the jack
> detect work. This can result in invalid reads from the regmap
> in cache-only mode if the work runs before the device has
> resumed:
>
> [...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/1] SoC: rt5682: Disable jack detection interrupt during suspend
commit: 8b271370e963370703819bd9795a54d658071bed

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark