[alsa-devel] [PATCH v2 11/17] ASoC: cros_ec_codec: Use cros_ec_cmd()
Prashant Malani
pmalani at chromium.org
Wed Feb 5 20:00:16 CET 2020
Replace send_ec_host_command() with cros_ec_cmd() which does the same
thing, but is defined in a common location in platform/chrome and
exposed for other modules to use. This allows us to remove
send_ec_host_command() entirely.
Signed-off-by: Prashant Malani <pmalani at chromium.org>
---
Changes in v2:
- Updated to use new function name and parameter list.
sound/soc/codecs/cros_ec_codec.c | 119 +++++++++++--------------------
1 file changed, 42 insertions(+), 77 deletions(-)
diff --git a/sound/soc/codecs/cros_ec_codec.c b/sound/soc/codecs/cros_ec_codec.c
index 6a24f570c5e86f..8516ba5f7624f8 100644
--- a/sound/soc/codecs/cros_ec_codec.c
+++ b/sound/soc/codecs/cros_ec_codec.c
@@ -69,38 +69,6 @@ static int ec_codec_capable(struct cros_ec_codec_priv *priv, uint8_t cap)
return priv->ec_capabilities & BIT(cap);
}
-static int send_ec_host_command(struct cros_ec_device *ec_dev, uint32_t cmd,
- uint8_t *out, size_t outsize,
- uint8_t *in, size_t insize)
-{
- int ret;
- struct cros_ec_command *msg;
-
- msg = kmalloc(sizeof(*msg) + max(outsize, insize), GFP_KERNEL);
- if (!msg)
- return -ENOMEM;
-
- msg->version = 0;
- msg->command = cmd;
- msg->outsize = outsize;
- msg->insize = insize;
-
- if (outsize)
- memcpy(msg->data, out, outsize);
-
- ret = cros_ec_cmd_xfer_status(ec_dev, msg);
- if (ret < 0)
- goto error;
-
- if (insize)
- memcpy(in, msg->data, insize);
-
- ret = 0;
-error:
- kfree(msg);
- return ret;
-}
-
static int calculate_sha256(struct cros_ec_codec_priv *priv,
uint8_t *buf, uint32_t size, uint8_t *digest)
{
@@ -149,18 +117,18 @@ static int dmic_get_gain(struct snd_kcontrol *kcontrol,
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));
+ ret = cros_ec_cmd(priv->ec_device, 0, EC_CMD_EC_CODEC_DMIC,
+ (uint8_t *)&p, sizeof(p), (uint8_t *)&r, sizeof(r),
+ NULL);
if (ret < 0)
return ret;
ucontrol->value.integer.value[0] = r.gain;
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));
+ ret = cros_ec_cmd(priv->ec_device, 0, EC_CMD_EC_CODEC_DMIC,
+ (uint8_t *)&p, sizeof(p), (uint8_t *)&r, sizeof(r),
+ NULL);
if (ret < 0)
return ret;
ucontrol->value.integer.value[1] = r.gain;
@@ -191,16 +159,16 @@ static int dmic_put_gain(struct snd_kcontrol *kcontrol,
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);
+ ret = cros_ec_cmd(priv->ec_device, 0, EC_CMD_EC_CODEC_DMIC,
+ (uint8_t *)&p, sizeof(p), NULL, 0, NULL);
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);
+ return cros_ec_cmd(priv->ec_device, 0, EC_CMD_EC_CODEC_DMIC,
+ (uint8_t *)&p, sizeof(p), NULL, 0, NULL);
}
static const DECLARE_TLV_DB_SCALE(dmic_gain_tlv, 0, 100, 0);
@@ -231,9 +199,9 @@ static int dmic_probe(struct snd_soc_component *component)
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));
+ ret = cros_ec_cmd(priv->ec_device, 0, EC_CMD_EC_CODEC_DMIC,
+ (uint8_t *)&p, sizeof(p), (uint8_t *)&r, sizeof(r),
+ NULL);
if (ret < 0) {
dev_warn(dev, "get_max_gain() unsupported\n");
return 0;
@@ -279,8 +247,8 @@ static int i2s_rx_hw_params(struct snd_pcm_substream *substream,
p.cmd = EC_CODEC_I2S_RX_SET_SAMPLE_DEPTH;
p.set_sample_depth_param.depth = depth;
- ret = send_ec_host_command(priv->ec_device, EC_CMD_EC_CODEC_I2S_RX,
- (uint8_t *)&p, sizeof(p), NULL, 0);
+ ret = cros_ec_cmd(priv->ec_device, 0, EC_CMD_EC_CODEC_I2S_RX,
+ (uint8_t *)&p, sizeof(p), NULL, 0, NULL);
if (ret < 0)
return ret;
@@ -289,8 +257,8 @@ static int i2s_rx_hw_params(struct snd_pcm_substream *substream,
p.cmd = EC_CODEC_I2S_RX_SET_BCLK;
p.set_bclk_param.bclk = snd_soc_params_to_bclk(params);
- return send_ec_host_command(priv->ec_device, EC_CMD_EC_CODEC_I2S_RX,
- (uint8_t *)&p, sizeof(p), NULL, 0);
+ return cros_ec_cmd(priv->ec_device, 0, EC_CMD_EC_CODEC_I2S_RX,
+ (uint8_t *)&p, sizeof(p), NULL, 0, NULL);
}
static int i2s_rx_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
@@ -333,8 +301,8 @@ static int i2s_rx_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
p.cmd = EC_CODEC_I2S_RX_SET_DAIFMT;
p.set_daifmt_param.daifmt = daifmt;
- return send_ec_host_command(priv->ec_device, EC_CMD_EC_CODEC_I2S_RX,
- (uint8_t *)&p, sizeof(p), NULL, 0);
+ return cros_ec_cmd(priv->ec_device, 0, EC_CMD_EC_CODEC_I2S_RX,
+ (uint8_t *)&p, sizeof(p), NULL, 0, NULL);
}
static const struct snd_soc_dai_ops i2s_rx_dai_ops = {
@@ -364,8 +332,8 @@ static int i2s_rx_event(struct snd_soc_dapm_widget *w,
return 0;
}
- return send_ec_host_command(priv->ec_device, EC_CMD_EC_CODEC_I2S_RX,
- (uint8_t *)&p, sizeof(p), NULL, 0);
+ return cros_ec_cmd(priv->ec_device, 0, EC_CMD_EC_CODEC_I2S_RX,
+ (uint8_t *)&p, sizeof(p), NULL, 0, NULL);
}
static struct snd_soc_dapm_widget i2s_rx_dapm_widgets[] = {
@@ -415,9 +383,8 @@ static void *wov_map_shm(struct cros_ec_codec_priv *priv,
p.cmd = EC_CODEC_GET_SHM_ADDR;
p.get_shm_addr_param.shm_id = shm_id;
- if (send_ec_host_command(priv->ec_device, EC_CMD_EC_CODEC,
- (uint8_t *)&p, sizeof(p),
- (uint8_t *)&r, sizeof(r)) < 0) {
+ if (cros_ec_cmd(priv->ec_device, 0, EC_CMD_EC_CODEC, (uint8_t *)&p,
+ sizeof(p), (uint8_t *)&r, sizeof(r), NULL) < 0) {
dev_err(priv->dev, "failed to EC_CODEC_GET_SHM_ADDR\n");
return NULL;
}
@@ -453,9 +420,8 @@ static void *wov_map_shm(struct cros_ec_codec_priv *priv,
p.set_shm_addr_param.phys_addr = priv->ap_shm_last_alloc;
p.set_shm_addr_param.len = req;
p.set_shm_addr_param.shm_id = shm_id;
- if (send_ec_host_command(priv->ec_device, EC_CMD_EC_CODEC,
- (uint8_t *)&p, sizeof(p),
- NULL, 0) < 0) {
+ if (cros_ec_cmd(priv->ec_device, 0, EC_CMD_EC_CODEC,
+ (uint8_t *)&p, sizeof(p), NULL, 0, NULL) < 0) {
dev_err(priv->dev, "failed to EC_CODEC_SET_SHM_ADDR\n");
return NULL;
}
@@ -571,9 +537,9 @@ static int wov_read_audio_shm(struct cros_ec_codec_priv *priv)
int ret;
p.cmd = EC_CODEC_WOV_READ_AUDIO_SHM;
- ret = send_ec_host_command(priv->ec_device, EC_CMD_EC_CODEC_WOV,
- (uint8_t *)&p, sizeof(p),
- (uint8_t *)&r, sizeof(r));
+ ret = cros_ec_cmd(priv->ec_device, 0, EC_CMD_EC_CODEC_WOV,
+ (uint8_t *)&p, sizeof(p), (uint8_t *)&r, sizeof(r),
+ NULL);
if (ret) {
dev_err(priv->dev, "failed to EC_CODEC_WOV_READ_AUDIO_SHM\n");
return ret;
@@ -596,9 +562,9 @@ static int wov_read_audio(struct cros_ec_codec_priv *priv)
while (remain >= 0) {
p.cmd = EC_CODEC_WOV_READ_AUDIO;
- ret = send_ec_host_command(priv->ec_device, EC_CMD_EC_CODEC_WOV,
- (uint8_t *)&p, sizeof(p),
- (uint8_t *)&r, sizeof(r));
+ ret = cros_ec_cmd(priv->ec_device, 0, EC_CMD_EC_CODEC_WOV,
+ (uint8_t *)&p, sizeof(p), (uint8_t *)&r,
+ sizeof(r), NULL);
if (ret) {
dev_err(priv->dev,
"failed to EC_CODEC_WOV_READ_AUDIO\n");
@@ -669,8 +635,8 @@ static int wov_enable_put(struct snd_kcontrol *kcontrol,
else
p.cmd = EC_CODEC_WOV_DISABLE;
- ret = send_ec_host_command(priv->ec_device, EC_CMD_EC_CODEC_WOV,
- (uint8_t *)&p, sizeof(p), NULL, 0);
+ ret = cros_ec_cmd(priv->ec_device, 0, EC_CMD_EC_CODEC_WOV,
+ (uint8_t *)&p, sizeof(p), NULL, 0, NULL);
if (ret) {
dev_err(priv->dev, "failed to %s wov\n",
enabled ? "enable" : "disable");
@@ -716,8 +682,8 @@ static int wov_set_lang_shm(struct cros_ec_codec_priv *priv,
p.cmd = EC_CODEC_WOV_SET_LANG_SHM;
memcpy(pp->hash, digest, SHA256_DIGEST_SIZE);
pp->total_len = size;
- ret = send_ec_host_command(priv->ec_device, EC_CMD_EC_CODEC_WOV,
- (uint8_t *)&p, sizeof(p), NULL, 0);
+ ret = cros_ec_cmd(priv->ec_device, 0, EC_CMD_EC_CODEC_WOV,
+ (uint8_t *)&p, sizeof(p), NULL, 0, NULL);
if (ret) {
dev_err(priv->dev, "failed to EC_CODEC_WOV_SET_LANG_SHM\n");
return ret;
@@ -743,8 +709,8 @@ static int wov_set_lang(struct cros_ec_codec_priv *priv,
pp->offset = i;
memcpy(pp->buf, buf + i, req);
pp->len = req;
- ret = send_ec_host_command(priv->ec_device, EC_CMD_EC_CODEC_WOV,
- (uint8_t *)&p, sizeof(p), NULL, 0);
+ ret = cros_ec_cmd(priv->ec_device, 0, EC_CMD_EC_CODEC_WOV,
+ (uint8_t *)&p, sizeof(p), NULL, 0, NULL);
if (ret) {
dev_err(priv->dev, "failed to EC_CODEC_WOV_SET_LANG\n");
return ret;
@@ -782,9 +748,9 @@ static int wov_hotword_model_put(struct snd_kcontrol *kcontrol,
goto leave;
p.cmd = EC_CODEC_WOV_GET_LANG;
- ret = send_ec_host_command(priv->ec_device, EC_CMD_EC_CODEC_WOV,
- (uint8_t *)&p, sizeof(p),
- (uint8_t *)&r, sizeof(r));
+ ret = cros_ec_cmd(priv->ec_device, 0, EC_CMD_EC_CODEC_WOV,
+ (uint8_t *)&p, sizeof(p), (uint8_t *)&r, sizeof(r),
+ NULL);
if (ret)
goto leave;
@@ -1020,9 +986,8 @@ static int cros_ec_codec_platform_probe(struct platform_device *pdev)
atomic_set(&priv->dmic_probed, 0);
p.cmd = EC_CODEC_GET_CAPABILITIES;
- ret = send_ec_host_command(priv->ec_device, EC_CMD_EC_CODEC,
- (uint8_t *)&p, sizeof(p),
- (uint8_t *)&r, sizeof(r));
+ ret = cros_ec_cmd(priv->ec_device, 0, EC_CMD_EC_CODEC, (uint8_t *)&p,
+ sizeof(p), (uint8_t *)&r, sizeof(r), NULL);
if (ret) {
dev_err(dev, "failed to EC_CODEC_GET_CAPABILITIES\n");
return ret;
--
2.25.0.341.g760bfbb309-goog
More information about the Alsa-devel
mailing list