summaryrefslogtreecommitdiff
path: root/sound/soc/codecs/cros_ec_codec.c
diff options
context:
space:
mode:
authorTzung-Bi Shih <tzungbi@google.com>2019-10-17 17:00:10 +0300
committerMark Brown <broonie@kernel.org>2019-10-18 20:13:20 +0300
commitf3e82ad43ca538a7e0db0f310e26c5e75db6ba18 (patch)
tree8d3a0ccccf6f6eb74115492785c7180b1289da83 /sound/soc/codecs/cros_ec_codec.c
parent104c6f8f7ff859ddd53b69c4af11e83f2971f0c4 (diff)
downloadlinux-f3e82ad43ca538a7e0db0f310e26c5e75db6ba18.tar.xz
ASoC: cros_ec_codec: read max DMIC gain from EC codec
Read max DMIC gain from EC codec instead of DTS. Also removes the dt-binding of max-dmic-gain. Acked-by: Rob Herring <robh@kernel.org> Acked-by: Benson Leung <bleung@chromium.org> Signed-off-by: Tzung-Bi Shih <tzungbi@google.com> Link: https://lore.kernel.org/r/20191017213539.05.Id4657c864d544634f2b5c1c9b34fa8232ecba44d@changeid Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'sound/soc/codecs/cros_ec_codec.c')
-rw-r--r--sound/soc/codecs/cros_ec_codec.c53
1 files changed, 39 insertions, 14 deletions
diff --git a/sound/soc/codecs/cros_ec_codec.c b/sound/soc/codecs/cros_ec_codec.c
index c19c7fe42e2e..3d4f9e82d6e9 100644
--- a/sound/soc/codecs/cros_ec_codec.c
+++ b/sound/soc/codecs/cros_ec_codec.c
@@ -65,18 +65,26 @@ static int dmic_get_gain(struct snd_kcontrol *kcontrol,
struct cros_ec_codec_priv *priv =
snd_soc_component_get_drvdata(component);
struct ec_param_ec_codec_dmic p;
- struct ec_response_ec_codec_dmic_get_gain r;
+ struct ec_response_ec_codec_dmic_get_gain_idx r;
int ret;
- p.cmd = EC_CODEC_DMIC_GET_GAIN;
+ p.cmd = EC_CODEC_DMIC_GET_GAIN_IDX;
+ p.get_gain_idx_param.channel = EC_CODEC_DMIC_CHANNEL_0;
ret = send_ec_host_command(priv->ec_device, EC_CMD_EC_CODEC_DMIC,
(uint8_t *)&p, sizeof(p),
(uint8_t *)&r, sizeof(r));
if (ret < 0)
return ret;
+ ucontrol->value.integer.value[0] = r.gain;
- ucontrol->value.integer.value[0] = r.left;
- ucontrol->value.integer.value[1] = r.right;
+ p.cmd = EC_CODEC_DMIC_GET_GAIN_IDX;
+ p.get_gain_idx_param.channel = EC_CODEC_DMIC_CHANNEL_1;
+ ret = send_ec_host_command(priv->ec_device, EC_CMD_EC_CODEC_DMIC,
+ (uint8_t *)&p, sizeof(p),
+ (uint8_t *)&r, sizeof(r));
+ if (ret < 0)
+ return ret;
+ ucontrol->value.integer.value[1] = r.gain;
return 0;
}
@@ -94,15 +102,24 @@ static int dmic_put_gain(struct snd_kcontrol *kcontrol,
int left = ucontrol->value.integer.value[0];
int right = ucontrol->value.integer.value[1];
struct ec_param_ec_codec_dmic p;
+ int ret;
if (left > max_dmic_gain || right > max_dmic_gain)
return -EINVAL;
dev_dbg(component->dev, "set mic gain to %u, %u\n", left, right);
- p.cmd = EC_CODEC_DMIC_SET_GAIN;
- p.set_gain_param.left = left;
- p.set_gain_param.right = right;
+ p.cmd = EC_CODEC_DMIC_SET_GAIN_IDX;
+ p.set_gain_idx_param.channel = EC_CODEC_DMIC_CHANNEL_0;
+ p.set_gain_idx_param.gain = left;
+ ret = send_ec_host_command(priv->ec_device, EC_CMD_EC_CODEC_DMIC,
+ (uint8_t *)&p, sizeof(p), NULL, 0);
+ if (ret < 0)
+ return ret;
+
+ p.cmd = EC_CODEC_DMIC_SET_GAIN_IDX;
+ p.set_gain_idx_param.channel = EC_CODEC_DMIC_CHANNEL_1;
+ p.set_gain_idx_param.gain = right;
return send_ec_host_command(priv->ec_device, EC_CMD_EC_CODEC_DMIC,
(uint8_t *)&p, sizeof(p), NULL, 0);
}
@@ -125,19 +142,27 @@ static int dmic_probe(struct snd_soc_component *component)
struct cros_ec_codec_priv *priv =
snd_soc_component_get_drvdata(component);
struct device *dev = priv->dev;
- int ret, val;
struct soc_mixer_control *control;
+ struct ec_param_ec_codec_dmic p;
+ struct ec_response_ec_codec_dmic_get_max_gain r;
+ int ret;
- ret = device_property_read_u32(dev, "max-dmic-gain", &val);
- if (ret) {
- dev_err(dev, "Failed to read 'max-dmic-gain'\n");
- return ret;
+ p.cmd = EC_CODEC_DMIC_GET_MAX_GAIN;
+
+ ret = send_ec_host_command(priv->ec_device, EC_CMD_EC_CODEC_DMIC,
+ (uint8_t *)&p, sizeof(p),
+ (uint8_t *)&r, sizeof(r));
+ if (ret < 0) {
+ dev_warn(dev, "get_max_gain() unsupported\n");
+ return 0;
}
+ dev_dbg(dev, "max gain = %d\n", r.max_gain);
+
control = (struct soc_mixer_control *)
dmic_controls[DMIC_CTL_GAIN].private_value;
- control->max = val;
- control->platform_max = val;
+ control->max = r.max_gain;
+ control->platform_max = r.max_gain;
return snd_soc_add_component_controls(component,
&dmic_controls[DMIC_CTL_GAIN], 1);