From 04ff40a983e864b586f189b4c3503b6f61263643 Mon Sep 17 00:00:00 2001 From: Richard Fitzgerald Date: Mon, 5 Feb 2018 11:38:17 +0000 Subject: ASoC: wm_adsp: Don't init cache from DSP memory if control is write-only For controls marked write-only don't initialize the cache from the content of the DSP memory. We stil need the cache for any new data that is written to this control, and we need to return something for a read of the ALSA control because most user-side code assumes all ALSA controls are readable. The cache is already created zero- filled so the only change needed is to skip populating it from DSP memory if the control isn't readable. Signed-off-by: Richard Fitzgerald Signed-off-by: Mark Brown --- sound/soc/codecs/wm_adsp.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'sound/soc') diff --git a/sound/soc/codecs/wm_adsp.c b/sound/soc/codecs/wm_adsp.c index 66e32f5d2917..0060aeb63a9f 100644 --- a/sound/soc/codecs/wm_adsp.c +++ b/sound/soc/codecs/wm_adsp.c @@ -1237,9 +1237,16 @@ static int wm_coeff_init_control_caches(struct wm_adsp *dsp) if (ctl->flags & WMFW_CTL_FLAG_VOLATILE) continue; - ret = wm_coeff_read_control(ctl, ctl->cache, ctl->len); - if (ret < 0) - return ret; + /* + * For readable controls populate the cache from the DSP memory. + * For non-readable controls the cache was zero-filled when + * created so we don't need to do anything. + */ + if (!ctl->flags || (ctl->flags & WMFW_CTL_FLAG_READABLE)) { + ret = wm_coeff_read_control(ctl, ctl->cache, ctl->len); + if (ret < 0) + return ret; + } } return 0; -- cgit From 2822e66bb812489aff9c41f4b265fcc2d8613989 Mon Sep 17 00:00:00 2001 From: Kuninori Morimoto Date: Mon, 29 Jan 2018 03:10:09 +0000 Subject: ASoC: wm9090: replace codec to component Now we can replace Codec to Component. Let's do it. Note: xxx_codec_xxx() -> xxx_component_xxx() .idle_bias_off = 0 -> .idle_bias_on = 1 .ignore_pmdown_time = 0 -> .use_pmdown_time = 1 - -> .endianness = 1 - -> .non_legacy_dai_naming = 1 Signed-off-by: Kuninori Morimoto Signed-off-by: Mark Brown --- sound/soc/codecs/wm9090.c | 109 ++++++++++++++++++++++------------------------ 1 file changed, 53 insertions(+), 56 deletions(-) (limited to 'sound/soc') diff --git a/sound/soc/codecs/wm9090.c b/sound/soc/codecs/wm9090.c index 5a131385cb2f..a9f1a0360a19 100644 --- a/sound/soc/codecs/wm9090.c +++ b/sound/soc/codecs/wm9090.c @@ -143,23 +143,23 @@ static bool wm9090_readable(struct device *dev, unsigned int reg) } } -static void wait_for_dc_servo(struct snd_soc_codec *codec) +static void wait_for_dc_servo(struct snd_soc_component *component) { unsigned int reg; int count = 0; - dev_dbg(codec->dev, "Waiting for DC servo...\n"); + dev_dbg(component->dev, "Waiting for DC servo...\n"); do { count++; msleep(1); - reg = snd_soc_read(codec, WM9090_DC_SERVO_READBACK_0); - dev_dbg(codec->dev, "DC servo status: %x\n", reg); + reg = snd_soc_component_read32(component, WM9090_DC_SERVO_READBACK_0); + dev_dbg(component->dev, "DC servo status: %x\n", reg); } while ((reg & WM9090_DCS_CAL_COMPLETE_MASK) != WM9090_DCS_CAL_COMPLETE_MASK && count < 1000); if ((reg & WM9090_DCS_CAL_COMPLETE_MASK) != WM9090_DCS_CAL_COMPLETE_MASK) - dev_err(codec->dev, "Timed out waiting for DC Servo\n"); + dev_err(component->dev, "Timed out waiting for DC Servo\n"); } static const DECLARE_TLV_DB_RANGE(in_tlv, @@ -251,22 +251,22 @@ SOC_SINGLE_TLV("MIXOUTR IN2B Volume", WM9090_OUTPUT_MIXER4, 0, 3, 1, static int hp_ev(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, int event) { - struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); - unsigned int reg = snd_soc_read(codec, WM9090_ANALOGUE_HP_0); + struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); + unsigned int reg = snd_soc_component_read32(component, WM9090_ANALOGUE_HP_0); switch (event) { case SND_SOC_DAPM_POST_PMU: - snd_soc_update_bits(codec, WM9090_CHARGE_PUMP_1, + snd_soc_component_update_bits(component, WM9090_CHARGE_PUMP_1, WM9090_CP_ENA, WM9090_CP_ENA); msleep(5); - snd_soc_update_bits(codec, WM9090_POWER_MANAGEMENT_1, + snd_soc_component_update_bits(component, WM9090_POWER_MANAGEMENT_1, WM9090_HPOUT1L_ENA | WM9090_HPOUT1R_ENA, WM9090_HPOUT1L_ENA | WM9090_HPOUT1R_ENA); reg |= WM9090_HPOUT1L_DLY | WM9090_HPOUT1R_DLY; - snd_soc_write(codec, WM9090_ANALOGUE_HP_0, reg); + snd_soc_component_write(component, WM9090_ANALOGUE_HP_0, reg); /* Start the DC servo. We don't currently use the * ability to save the state since we don't have full @@ -274,16 +274,16 @@ static int hp_ev(struct snd_soc_dapm_widget *w, * DC offsets; see the WM8904 driver for an example of * doing so. */ - snd_soc_write(codec, WM9090_DC_SERVO_0, + snd_soc_component_write(component, WM9090_DC_SERVO_0, WM9090_DCS_ENA_CHAN_0 | WM9090_DCS_ENA_CHAN_1 | WM9090_DCS_TRIG_STARTUP_1 | WM9090_DCS_TRIG_STARTUP_0); - wait_for_dc_servo(codec); + wait_for_dc_servo(component); reg |= WM9090_HPOUT1R_OUTP | WM9090_HPOUT1R_RMV_SHORT | WM9090_HPOUT1L_OUTP | WM9090_HPOUT1L_RMV_SHORT; - snd_soc_write(codec, WM9090_ANALOGUE_HP_0, reg); + snd_soc_component_write(component, WM9090_ANALOGUE_HP_0, reg); break; case SND_SOC_DAPM_PRE_PMD: @@ -294,15 +294,15 @@ static int hp_ev(struct snd_soc_dapm_widget *w, WM9090_HPOUT1R_DLY | WM9090_HPOUT1R_OUTP); - snd_soc_write(codec, WM9090_ANALOGUE_HP_0, reg); + snd_soc_component_write(component, WM9090_ANALOGUE_HP_0, reg); - snd_soc_write(codec, WM9090_DC_SERVO_0, 0); + snd_soc_component_write(component, WM9090_DC_SERVO_0, 0); - snd_soc_update_bits(codec, WM9090_POWER_MANAGEMENT_1, + snd_soc_component_update_bits(component, WM9090_POWER_MANAGEMENT_1, WM9090_HPOUT1L_ENA | WM9090_HPOUT1R_ENA, 0); - snd_soc_update_bits(codec, WM9090_CHARGE_PUMP_1, + snd_soc_component_update_bits(component, WM9090_CHARGE_PUMP_1, WM9090_CP_ENA, 0); break; } @@ -419,10 +419,10 @@ static const struct snd_soc_dapm_route audio_map_in2_diff[] = { { "IN2A PGA", NULL, "IN2-" }, }; -static int wm9090_add_controls(struct snd_soc_codec *codec) +static int wm9090_add_controls(struct snd_soc_component *component) { - struct wm9090_priv *wm9090 = snd_soc_codec_get_drvdata(codec); - struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec); + struct wm9090_priv *wm9090 = snd_soc_component_get_drvdata(component); + struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); int i; snd_soc_dapm_new_controls(dapm, wm9090_dapm_widgets, @@ -430,7 +430,7 @@ static int wm9090_add_controls(struct snd_soc_codec *codec) snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map)); - snd_soc_add_codec_controls(codec, wm9090_controls, + snd_soc_add_component_controls(component, wm9090_controls, ARRAY_SIZE(wm9090_controls)); if (wm9090->pdata.lin1_diff) { @@ -439,7 +439,7 @@ static int wm9090_add_controls(struct snd_soc_codec *codec) } else { snd_soc_dapm_add_routes(dapm, audio_map_in1_se, ARRAY_SIZE(audio_map_in1_se)); - snd_soc_add_codec_controls(codec, wm9090_in1_se_controls, + snd_soc_add_component_controls(component, wm9090_in1_se_controls, ARRAY_SIZE(wm9090_in1_se_controls)); } @@ -449,18 +449,18 @@ static int wm9090_add_controls(struct snd_soc_codec *codec) } else { snd_soc_dapm_add_routes(dapm, audio_map_in2_se, ARRAY_SIZE(audio_map_in2_se)); - snd_soc_add_codec_controls(codec, wm9090_in2_se_controls, + snd_soc_add_component_controls(component, wm9090_in2_se_controls, ARRAY_SIZE(wm9090_in2_se_controls)); } if (wm9090->pdata.agc_ena) { for (i = 0; i < ARRAY_SIZE(wm9090->pdata.agc); i++) - snd_soc_write(codec, WM9090_AGC_CONTROL_0 + i, + snd_soc_component_write(component, WM9090_AGC_CONTROL_0 + i, wm9090->pdata.agc[i]); - snd_soc_update_bits(codec, WM9090_POWER_MANAGEMENT_3, + snd_soc_component_update_bits(component, WM9090_POWER_MANAGEMENT_3, WM9090_AGC_ENA, WM9090_AGC_ENA); } else { - snd_soc_update_bits(codec, WM9090_POWER_MANAGEMENT_3, + snd_soc_component_update_bits(component, WM9090_POWER_MANAGEMENT_3, WM9090_AGC_ENA, 0); } @@ -472,19 +472,19 @@ static int wm9090_add_controls(struct snd_soc_codec *codec) * The machine driver should call this from their set_bias_level; if there * isn't one then this can just be set as the set_bias_level function. */ -static int wm9090_set_bias_level(struct snd_soc_codec *codec, +static int wm9090_set_bias_level(struct snd_soc_component *component, enum snd_soc_bias_level level) { - struct wm9090_priv *wm9090 = snd_soc_codec_get_drvdata(codec); + struct wm9090_priv *wm9090 = snd_soc_component_get_drvdata(component); switch (level) { case SND_SOC_BIAS_ON: break; case SND_SOC_BIAS_PREPARE: - snd_soc_update_bits(codec, WM9090_ANTIPOP2, WM9090_VMID_ENA, + snd_soc_component_update_bits(component, WM9090_ANTIPOP2, WM9090_VMID_ENA, WM9090_VMID_ENA); - snd_soc_update_bits(codec, WM9090_POWER_MANAGEMENT_1, + snd_soc_component_update_bits(component, WM9090_POWER_MANAGEMENT_1, WM9090_BIAS_ENA | WM9090_VMID_RES_MASK, WM9090_BIAS_ENA | @@ -493,7 +493,7 @@ static int wm9090_set_bias_level(struct snd_soc_codec *codec, break; case SND_SOC_BIAS_STANDBY: - if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) { + if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF) { /* Restore the register cache */ regcache_sync(wm9090->regmap); } @@ -502,9 +502,9 @@ static int wm9090_set_bias_level(struct snd_soc_codec *codec, * ground referenced outputs and class D speaker mean that * latency is not an issue. */ - snd_soc_update_bits(codec, WM9090_POWER_MANAGEMENT_1, + snd_soc_component_update_bits(component, WM9090_POWER_MANAGEMENT_1, WM9090_BIAS_ENA | WM9090_VMID_RES_MASK, 0); - snd_soc_update_bits(codec, WM9090_ANTIPOP2, + snd_soc_component_update_bits(component, WM9090_ANTIPOP2, WM9090_VMID_ENA, 0); break; @@ -515,45 +515,49 @@ static int wm9090_set_bias_level(struct snd_soc_codec *codec, return 0; } -static int wm9090_probe(struct snd_soc_codec *codec) +static int wm9090_probe(struct snd_soc_component *component) { /* Configure some defaults; they will be written out when we * bring the bias up. */ - snd_soc_update_bits(codec, WM9090_IN1_LINE_INPUT_A_VOLUME, + snd_soc_component_update_bits(component, WM9090_IN1_LINE_INPUT_A_VOLUME, WM9090_IN1_VU | WM9090_IN1A_ZC, WM9090_IN1_VU | WM9090_IN1A_ZC); - snd_soc_update_bits(codec, WM9090_IN1_LINE_INPUT_B_VOLUME, + snd_soc_component_update_bits(component, WM9090_IN1_LINE_INPUT_B_VOLUME, WM9090_IN1_VU | WM9090_IN1B_ZC, WM9090_IN1_VU | WM9090_IN1B_ZC); - snd_soc_update_bits(codec, WM9090_IN2_LINE_INPUT_A_VOLUME, + snd_soc_component_update_bits(component, WM9090_IN2_LINE_INPUT_A_VOLUME, WM9090_IN2_VU | WM9090_IN2A_ZC, WM9090_IN2_VU | WM9090_IN2A_ZC); - snd_soc_update_bits(codec, WM9090_IN2_LINE_INPUT_B_VOLUME, + snd_soc_component_update_bits(component, WM9090_IN2_LINE_INPUT_B_VOLUME, WM9090_IN2_VU | WM9090_IN2B_ZC, WM9090_IN2_VU | WM9090_IN2B_ZC); - snd_soc_update_bits(codec, WM9090_SPEAKER_VOLUME_LEFT, + snd_soc_component_update_bits(component, WM9090_SPEAKER_VOLUME_LEFT, WM9090_SPKOUT_VU | WM9090_SPKOUTL_ZC, WM9090_SPKOUT_VU | WM9090_SPKOUTL_ZC); - snd_soc_update_bits(codec, WM9090_LEFT_OUTPUT_VOLUME, + snd_soc_component_update_bits(component, WM9090_LEFT_OUTPUT_VOLUME, WM9090_HPOUT1_VU | WM9090_HPOUT1L_ZC, WM9090_HPOUT1_VU | WM9090_HPOUT1L_ZC); - snd_soc_update_bits(codec, WM9090_RIGHT_OUTPUT_VOLUME, + snd_soc_component_update_bits(component, WM9090_RIGHT_OUTPUT_VOLUME, WM9090_HPOUT1_VU | WM9090_HPOUT1R_ZC, WM9090_HPOUT1_VU | WM9090_HPOUT1R_ZC); - snd_soc_update_bits(codec, WM9090_CLOCKING_1, + snd_soc_component_update_bits(component, WM9090_CLOCKING_1, WM9090_TOCLK_ENA, WM9090_TOCLK_ENA); - wm9090_add_controls(codec); + wm9090_add_controls(component); return 0; } -static const struct snd_soc_codec_driver soc_codec_dev_wm9090 = { - .probe = wm9090_probe, - .set_bias_level = wm9090_set_bias_level, - .suspend_bias_off = true, +static const struct snd_soc_component_driver soc_component_dev_wm9090 = { + .probe = wm9090_probe, + .set_bias_level = wm9090_set_bias_level, + .suspend_bias_off = 1, + .idle_bias_on = 1, + .use_pmdown_time = 1, + .endianness = 1, + .non_legacy_dai_naming = 1, }; static const struct regmap_config wm9090_regmap = { @@ -607,8 +611,8 @@ static int wm9090_i2c_probe(struct i2c_client *i2c, i2c_set_clientdata(i2c, wm9090); - ret = snd_soc_register_codec(&i2c->dev, - &soc_codec_dev_wm9090, NULL, 0); + ret = devm_snd_soc_register_component(&i2c->dev, + &soc_component_dev_wm9090, NULL, 0); if (ret != 0) { dev_err(&i2c->dev, "Failed to register CODEC: %d\n", ret); return ret; @@ -617,12 +621,6 @@ static int wm9090_i2c_probe(struct i2c_client *i2c, return 0; } -static int wm9090_i2c_remove(struct i2c_client *i2c) -{ - snd_soc_unregister_codec(&i2c->dev); - return 0; -} - static const struct i2c_device_id wm9090_id[] = { { "wm9090", 0 }, { "wm9093", 0 }, @@ -635,7 +633,6 @@ static struct i2c_driver wm9090_i2c_driver = { .name = "wm9090", }, .probe = wm9090_i2c_probe, - .remove = wm9090_i2c_remove, .id_table = wm9090_id, }; -- cgit From 60edb2006030894a4e45c84b04369cb70939d695 Mon Sep 17 00:00:00 2001 From: Fabio Estevam Date: Tue, 13 Feb 2018 17:37:50 -0200 Subject: ASoC: wm9712: Use empty struct initializer { 0 } only clears the first member of the structure. The first member of the snd_soc_dapm_update struct is a pointer, and writing 0 to a pointer results in the following sparse warning: sound/soc/codecs/wm9712.c:229:47: warning: Using plain integer as NULL pointer Use the empty struct initializer that clears all the struct members and fixes the sparse warning. Signed-off-by: Fabio Estevam Signed-off-by: Mark Brown --- sound/soc/codecs/wm9712.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sound/soc') diff --git a/sound/soc/codecs/wm9712.c b/sound/soc/codecs/wm9712.c index 4f6d1a442bc4..c672d5d88827 100644 --- a/sound/soc/codecs/wm9712.c +++ b/sound/soc/codecs/wm9712.c @@ -226,7 +226,7 @@ static int wm9712_hp_mixer_put(struct snd_kcontrol *kcontrol, struct soc_mixer_control *mc = (struct soc_mixer_control *)kcontrol->private_value; unsigned int mixer, mask, shift, old; - struct snd_soc_dapm_update update = { 0 }; + struct snd_soc_dapm_update update = {}; bool change; mixer = mc->shift >> 8; -- cgit From 91cd00083d734258bf293dcf76793e2348be391a Mon Sep 17 00:00:00 2001 From: Fabio Estevam Date: Wed, 14 Feb 2018 13:39:04 -0200 Subject: ASoC: wm9713: Use empty struct initializer { 0 } only clears the first member of the structure. The first member of the snd_soc_dapm_update struct is a pointer, and writing 0 to a pointer results in a sparse warning. Use the empty struct initializer that clears all the struct members and fixes the sparse warning. Cc: Charles Keepax Signed-off-by: Fabio Estevam Acked-by: Charles Keepax Signed-off-by: Mark Brown --- sound/soc/codecs/wm9713.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sound/soc') diff --git a/sound/soc/codecs/wm9713.c b/sound/soc/codecs/wm9713.c index df7220656d98..093be043c1b0 100644 --- a/sound/soc/codecs/wm9713.c +++ b/sound/soc/codecs/wm9713.c @@ -235,7 +235,7 @@ static int wm9713_hp_mixer_put(struct snd_kcontrol *kcontrol, struct soc_mixer_control *mc = (struct soc_mixer_control *)kcontrol->private_value; unsigned int mixer, mask, shift, old; - struct snd_soc_dapm_update update = { 0 }; + struct snd_soc_dapm_update update = {}; bool change; mixer = mc->shift >> 8; -- cgit From e21a5acfab2f13eeffe50d5d5f87c099540a3bf3 Mon Sep 17 00:00:00 2001 From: Richard Fitzgerald Date: Fri, 16 Feb 2018 14:36:10 +0000 Subject: ASoC: wm_adsp: Fix some signedness errors in register access base and sysclk_reg should be unsigned int, as that is what regmap takes as a register address. sysclk_mask is used to mask unsigned register values so should be unsigned. sysclk_shift is a shift value so is not allowed to be negative. Signed-off-by: Richard Fitzgerald Signed-off-by: Mark Brown --- sound/soc/codecs/wm_adsp.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'sound/soc') diff --git a/sound/soc/codecs/wm_adsp.h b/sound/soc/codecs/wm_adsp.h index 41cc11c19b83..d4042c95315e 100644 --- a/sound/soc/codecs/wm_adsp.h +++ b/sound/soc/codecs/wm_adsp.h @@ -64,10 +64,10 @@ struct wm_adsp { struct regmap *regmap; struct snd_soc_codec *codec; - int base; - int sysclk_reg; - int sysclk_mask; - int sysclk_shift; + unsigned int base; + unsigned int sysclk_reg; + unsigned int sysclk_mask; + unsigned int sysclk_shift; struct list_head alg_regions; -- cgit From 61fc060c40e6b92350c08a210619fc7d93c61e42 Mon Sep 17 00:00:00 2001 From: Charles Keepax Date: Mon, 26 Feb 2018 10:49:47 +0000 Subject: ASoC: wm_adsp: Support streams which can start/stop with DSP active Clear the buffer data structure on each trigger start such that the buffer is in a sensible state even if the DSP itself didn't restart. This is necessary to support voice control streams which can trigger multiple times without reloading the firmware. Signed-off-by: Charles Keepax Signed-off-by: Mark Brown --- sound/soc/codecs/wm_adsp.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'sound/soc') diff --git a/sound/soc/codecs/wm_adsp.c b/sound/soc/codecs/wm_adsp.c index 0060aeb63a9f..ab91f1320ad5 100644 --- a/sound/soc/codecs/wm_adsp.c +++ b/sound/soc/codecs/wm_adsp.c @@ -3258,6 +3258,13 @@ static int wm_adsp_buffer_populate(struct wm_adsp_compr_buf *buf) return 0; } +static void wm_adsp_buffer_clear(struct wm_adsp_compr_buf *buf) +{ + buf->irq_count = 0xFFFFFFFF; + buf->read_index = -1; + buf->avail = 0; +} + static int wm_adsp_buffer_init(struct wm_adsp *dsp) { struct wm_adsp_compr_buf *buf; @@ -3268,8 +3275,8 @@ static int wm_adsp_buffer_init(struct wm_adsp *dsp) return -ENOMEM; buf->dsp = dsp; - buf->read_index = -1; - buf->irq_count = 0xFFFFFFFF; + + wm_adsp_buffer_clear(buf); ret = wm_adsp_buffer_locate(buf); if (ret < 0) { @@ -3327,16 +3334,17 @@ int wm_adsp_compr_trigger(struct snd_compr_stream *stream, int cmd) switch (cmd) { case SNDRV_PCM_TRIGGER_START: - if (wm_adsp_compr_attached(compr)) - break; - - ret = wm_adsp_compr_attach(compr); - if (ret < 0) { - adsp_err(dsp, "Failed to link buffer and stream: %d\n", - ret); - break; + if (!wm_adsp_compr_attached(compr)) { + ret = wm_adsp_compr_attach(compr); + if (ret < 0) { + adsp_err(dsp, "Failed to link buffer and stream: %d\n", + ret); + break; + } } + wm_adsp_buffer_clear(compr->buf); + /* Trigger the IRQ at one fragment of data */ ret = wm_adsp_buffer_write(compr->buf, HOST_BUFFER_FIELD(high_water_mark), -- cgit