ASoC: cs35l56: Series to stop writing ASP registers the driver doesn't own
Subsystems (3)
Richard Fitzgerald
maintainercover ASoC: cs35l56: Series to stop writing ASP registers the driver doesn't own
The driver was writing to the ASP registers on systems where it didn't own control of those registers. These two patches prevent that.
There is more detail in the commit messages of why this problem exists, but the summary is that these registers are usually owned by the firmware and/or a secondary (or tertiary) host using the I2C/SPI control interfaces.
Richard Fitzgerald (2):
ASoC: cs35l56: Only write ASP1TXn registers when widget is powered-up
ASoC: cs35l56: Fix unwanted writes to ASP config registers
include/sound/cs35l56.h | 2 +- sound/soc/codecs/cs35l56-shared.c | 38 +------- sound/soc/codecs/cs35l56.c | 147 ++++++++++++++++++++++++------ sound/soc/codecs/cs35l56.h | 1 + 4 files changed, 124 insertions(+), 64 deletions(-)
Signature · 1 line
2.47.3
Richard Fitzgerald
maintainerPATCH 1/2 ASoC: cs35l56: Only write ASP1TXn registers when widget is powered-up
Cache the value written to the "ASP1 TXn Source" controls and write them to registers only when the widget is powered-up. Remove them from the regmap defaults table so regmap won't write them during a regcache_sync().
The ASP registers have multiple ownership, depending on the hardware design. They can be owned by the firmware, or by a MCU on a secondary control interface, or by the driver. If the driver doesn't own control of the ASP it must not overwrite the registers.
ALSA control read/write now goes to cached values in struct cs35l56_private. The values are written out if the widget powers up, which can only happen if the machine driver has connected the ASP DAI in a DAIlink. If the control value is changed while the widget is powered the change will be deferred until the next widget power-up. Changing the hardware mux on-the-fly while active is not supported.
--- sound/soc/codecs/cs35l56-shared.c | 12 ---- sound/soc/codecs/cs35l56.c | 104 ++++++++++++++++++++++++------ sound/soc/codecs/cs35l56.h | 1 + 3 files changed, 86 insertions(+), 31 deletions(-)
sound/soc/codecs/cs35l56-shared.c +0 -12
@@ -39,10 +39,6 @@ static const struct reg_sequence cs35l56_asp_patch[] = { { CS35L56_ASP1_FRAME_CONTROL5, 0x00020100 }, { CS35L56_ASP1_DATA_CONTROL1, 0x00000018 }, { CS35L56_ASP1_DATA_CONTROL5, 0x00000018 }, - { CS35L56_ASP1TX1_INPUT, 0x00000000 }, - { CS35L56_ASP1TX2_INPUT, 0x00000000 }, - { CS35L56_ASP1TX3_INPUT, 0x00000000 }, - { CS35L56_ASP1TX4_INPUT, 0x00000000 }, };int cs35l56_set_asp_patch (struct cs35l56_base *cs35l56_base)
@@ -117,10 +113,6 @@ static const struct reg_default cs35l56_reg_defaults[] = { { CS35L56_ASP1_FRAME_CONTROL5, 0x00020100 }, { CS35L56_ASP1_DATA_CONTROL1, 0x00000018 }, { CS35L56_ASP1_DATA_CONTROL5, 0x00000018 }, - { CS35L56_ASP1TX1_INPUT, 0x00000000 }, - { CS35L56_ASP1TX2_INPUT, 0x00000000 }, - { CS35L56_ASP1TX3_INPUT, 0x00000000 }, - { CS35L56_ASP1TX4_INPUT, 0x00000000 }, { CS35L56_SWIRE_DP3_CH1_INPUT, 0x00000018 }, { CS35L56_SWIRE_DP3_CH2_INPUT, 0x00000019 }, { CS35L56_SWIRE_DP3_CH3_INPUT, 0x00000029 },
@@ -145,10 +137,6 @@ static const struct reg_default cs35l63_reg_defaults[] = { { CS35L56_ASP1_FRAME_CONTROL5, 0x00020100 }, { CS35L56_ASP1_DATA_CONTROL1, 0x00000018 }, { CS35L56_ASP1_DATA_CONTROL5, 0x00000018 }, - { CS35L56_ASP1TX1_INPUT, 0x00000000 }, - { CS35L56_ASP1TX2_INPUT, 0x00000000 }, - { CS35L56_ASP1TX3_INPUT, 0x00000000 }, - { CS35L56_ASP1TX4_INPUT, 0x00000000 }, { CS35L56_SWIRE_DP3_CH1_INPUT, 0x00000018 }, { CS35L56_SWIRE_DP3_CH2_INPUT, 0x00000019 }, { CS35L56_SWIRE_DP3_CH3_INPUT, 0x00000029 },
sound/soc/codecs/cs35l56.c +85 -19
152 lines not on this page · raw message
sound/soc/codecs/cs35l56.h +1 -0
@@ -49,6 +49,7 @@ struct cs35l56_private {int speaker_id;u32 rx_mask;u32 tx_mask; +u8 asp_tx_input[4 ];u8 asp_slot_width;u8 asp_slot_count;bool tdm_mode;
Signature · 1 line
2.47.3
Richard Fitzgerald
maintainerPATCH 2/2 ASoC: cs35l56: Fix unwanted writes to ASP config registers
In reply to Richard FitzgeraldRemove the ASP config registers from the regmap defaults table and use regmap_multi_reg_write() instead of regmap_register_patch() to write default values. Use custom event handlers for the ASP1 widgets so ASP1_ENABLES1 is only written if the ASP is used. Move the HIZ mode write to ASP1_CONTROL3 into the register sequence instead of writing it on every driver probe.
This is to prevent accidentally writing to these registers when the driver does not own them.
The ASP config registers have multiple ownership. They can be owned and written by the firmware on SKUs that use the ASP as a chip-to-chip audio interface managed by the firmware. They can be owned and written by an MCU through one of the other control ports. Or they can be owned by the ASoC codec driver if they are used for the CPU->amp audio. Because of this multiple ownership the codec driver must not write the registers if it doesn't own control of the ASP.
Commit 9351cf3fd92dc ("ASoC: cs35l56: Only patch ASP registers if the DAI is part of a DAIlink") attempted to deal with this by only writing default values into the cache if the dai probe() callback was called (which only happens when the DAI is part of a dailink). The intention was that the cache values would only be populated if the driver owns the DAI. But this commit was flawed in three ways:
1. A regcache_sync() without a regcache_mark_dirty() would write the registers.
The cs35l56/57/62/63 amps are designed to preserve state across suspend states, so the registers have not necessarily reset when the driver resumes. For this reason the driver may call regcache_sync() without regcache_mark_dirty() to sync any changes made while in cache-only.
Regmap pre-populates the cache from the values in the defaults table. So the cache always contained values for these registers. The regmap cache doesn't have a per-register dirty flag, only a global dirty. It will write out everything in the cache if it is dirty. Filtering of cache values that are at default only happens if regcache_mark_dirty() has been called. So the ASP config registers were being written for every non-default cache sync.
2. regmap_register_patch() writes to hardware
The intent was to populate the cache. But regmap_register_patch() disables cache-only and tries to write the patch to hardware. The DAI probe() can be called while in runtime-suspend with the hardware not accessible, so this could fail. There is no need to write the registers to hardware at this time, the only need is to populate the cache so that the register settings can be accumulated in the cache as the DAI is configured.
3. ASP1_ENABLES1 was read into the cache during widget initialization
The ASP1 RX and TX widgets provided the address of ASP1_ENABLES1 for ASoC to manage. But during widget initialization ASoC reads the initial value of the registers. This meant that the cache was populated with a value for ASP1_ENABLES1, so that would be written out by regcache_sync().
--- include/sound/cs35l56.h | 2 +- sound/soc/codecs/cs35l56-shared.c | 26 +++---------- sound/soc/codecs/cs35l56.c | 63 ++++++++++++++++++++----------- 3 files changed, 48 insertions(+), 43 deletions(-)
include/sound/cs35l56.h +1 -1
@@ -412,7 +412,7 @@ extern const char * const cs35l56_cal_set_status_text[3];extern const char *const cs35l56_tx_input_texts[CS35L56_NUM_INPUT_SRC ];extern const unsigned int cs35l56_tx_input_values[CS35L56_NUM_INPUT_SRC ]; -int cs35l56_set_asp_patch (struct cs35l56_base *cs35l56_base); +int cs35l56_set_asp_defaults (struct cs35l56_base *cs35l56_base);int cs35l56_set_patch (struct cs35l56_base *cs35l56_base);int cs35l56_mbox_send (struct cs35l56_base *cs35l56_base,unsigned int command);int cs35l56_firmware_shutdown (struct cs35l56_base *cs35l56_base);
sound/soc/codecs/cs35l56-shared.c +5 -21
@@ -34,19 +34,19 @@ static const struct reg_sequence cs35l56_asp_patch[] = { { CS35L56_ASP1_ENABLES1, 0x00000000 }, { CS35L56_ASP1_CONTROL1, 0x00000028 }, { CS35L56_ASP1_CONTROL2, 0x18180200 }, - { CS35L56_ASP1_CONTROL3, 0x00000002 }, + { CS35L56_ASP1_CONTROL3, 0x00000003 }, { CS35L56_ASP1_FRAME_CONTROL1, 0x03020100 }, { CS35L56_ASP1_FRAME_CONTROL5, 0x00020100 }, { CS35L56_ASP1_DATA_CONTROL1, 0x00000018 }, { CS35L56_ASP1_DATA_CONTROL5, 0x00000018 }, }; -int cs35l56_set_asp_patch (struct cs35l56_base *cs35l56_base) +int cs35l56_set_asp_defaults (struct cs35l56_base *cs35l56_base) { -return regmap_register_patch (cs35l56_base->regmap, cs35l56_asp_patch, -ARRAY_SIZE (cs35l56_asp_patch)); +return regmap_multi_reg_write (cs35l56_base->regmap, cs35l56_asp_patch, +ARRAY_SIZE (cs35l56_asp_patch)); } -EXPORT_SYMBOL_NS_GPL (cs35l56_set_asp_patch,"SND_SOC_CS35L56_SHARED" ); +EXPORT_SYMBOL_NS_GPL (cs35l56_set_asp_defaults,"SND_SOC_CS35L56_SHARED" );static const struct reg_sequence cs35l56_patch[] = {/*
@@ -105,14 +105,6 @@ int cs35l56_set_patch(struct cs35l56_base *cs35l56_base)EXPORT_SYMBOL_NS_GPL (cs35l56_set_patch,"SND_SOC_CS35L56_SHARED" );static const struct reg_default cs35l56_reg_defaults[] = { - {CS35L56_ASP1_ENABLES1 ,0x00000000 }, - {CS35L56_ASP1_CONTROL1 ,0x00000028 }, - {CS35L56_ASP1_CONTROL2 ,0x18180200 }, - {CS35L56_ASP1_CONTROL3 ,0x00000002 }, - {CS35L56_ASP1_FRAME_CONTROL1 ,0x03020100 }, - {CS35L56_ASP1_FRAME_CONTROL5 ,0x00020100 }, - {CS35L56_ASP1_DATA_CONTROL1 ,0x00000018 }, - {CS35L56_ASP1_DATA_CONTROL5 ,0x00000018 }, {CS35L56_SWIRE_DP3_CH1_INPUT ,0x00000018 }, {CS35L56_SWIRE_DP3_CH2_INPUT ,0x00000019 }, {CS35L56_SWIRE_DP3_CH3_INPUT ,0x00000029 },
@@ -129,14 +121,6 @@ static const struct reg_default cs35l56_reg_defaults[] = { };static const struct reg_default cs35l63_reg_defaults[] = { - {CS35L56_ASP1_ENABLES1 ,0x00000000 }, - {CS35L56_ASP1_CONTROL1 ,0x00000028 }, - {CS35L56_ASP1_CONTROL2 ,0x18180200 }, - {CS35L56_ASP1_CONTROL3 ,0x00000002 }, - {CS35L56_ASP1_FRAME_CONTROL1 ,0x03020100 }, - {CS35L56_ASP1_FRAME_CONTROL5 ,0x00020100 }, - {CS35L56_ASP1_DATA_CONTROL1 ,0x00000018 }, - {CS35L56_ASP1_DATA_CONTROL5 ,0x00000018 }, {CS35L56_SWIRE_DP3_CH1_INPUT ,0x00000018 }, {CS35L56_SWIRE_DP3_CH2_INPUT ,0x00000019 }, {CS35L56_SWIRE_DP3_CH3_INPUT ,0x00000029 },
sound/soc/codecs/cs35l56.c +42 -21
97 lines not on this page · raw message
Signature · 1 line
2.47.3
Mark Brown
maintainerQuoted 10 lines · Richard Fitzgerald
ASoC: cs35l56: Series to stop writing ASP registers the driver doesn't own
The driver was writing to the ASP registers on systems where it didn't own control of those registers. These two patches prevent that.
There is more detail in the commit messages of why this problem exists, but the summary is that these registers are usually owned by the firmware and/or a secondary (or tertiary) host using the I2C/SPI control interfaces.
[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.4
Thanks!
[1/2] ASoC: cs35l56: Only write ASP1TXn registers when widget is powered-up
https://git.kernel.org/broonie/sound/c/0085428e834c [2/2] ASoC: cs35l56: Fix unwanted writes to ASP config registers https://git.kernel.org/broonie/sound/c/396c5d8075f3
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