linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Prashant Malani <pmalani@chromium.org>
To: linux-kernel@vger.kernel.org
Cc: Prashant Malani <pmalani@chromium.org>,
	Cheng-Yi Chiang <cychiang@chromium.org>,
	Enric Balletbo i Serra <enric.balletbo@collabora.com>,
	Guenter Roeck <groeck@chromium.org>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@kernel.org>, Jaroslav Kysela <perex@perex.cz>,
	Takashi Iwai <tiwai@suse.com>, Benson Leung <bleung@chromium.org>,
	alsa-devel@alsa-project.org (moderated list:SOUND - SOC LAYER /
	DYNAMIC AUDIO POWER MANAGEM...)
Subject: [PATCH 11/17] ASoC: cros_ec_codec: Use cros_ec_send_cmd_msg()
Date: Thu, 30 Jan 2020 12:30:56 -0800	[thread overview]
Message-ID: <20200130203106.201894-12-pmalani@chromium.org> (raw)
In-Reply-To: <20200130203106.201894-1-pmalani@chromium.org>

Replace send_ec_host_command() with cros_ec_send_cmd_msg() 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@chromium.org>
---
 sound/soc/codecs/cros_ec_codec.c | 71 ++++++++++----------------------
 1 file changed, 21 insertions(+), 50 deletions(-)

diff --git a/sound/soc/codecs/cros_ec_codec.c b/sound/soc/codecs/cros_ec_codec.c
index 6a24f570c5e86f..49adb07d766963 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,7 +117,7 @@ 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,
+	ret = cros_ec_send_cmd_msg(priv->ec_device, 0, EC_CMD_EC_CODEC_DMIC,
 				   (uint8_t *)&p, sizeof(p),
 				   (uint8_t *)&r, sizeof(r));
 	if (ret < 0)
@@ -158,7 +126,7 @@ 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_1;
-	ret = send_ec_host_command(priv->ec_device, EC_CMD_EC_CODEC_DMIC,
+	ret = cros_ec_send_cmd_msg(priv->ec_device, 0, EC_CMD_EC_CODEC_DMIC,
 				   (uint8_t *)&p, sizeof(p),
 				   (uint8_t *)&r, sizeof(r));
 	if (ret < 0)
@@ -191,7 +159,7 @@ 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,
+	ret = cros_ec_send_cmd_msg(priv->ec_device, 0, EC_CMD_EC_CODEC_DMIC,
 				   (uint8_t *)&p, sizeof(p), NULL, 0);
 	if (ret < 0)
 		return ret;
@@ -199,7 +167,7 @@ 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_1;
 	p.set_gain_idx_param.gain = right;
-	return send_ec_host_command(priv->ec_device, EC_CMD_EC_CODEC_DMIC,
+	return cros_ec_send_cmd_msg(priv->ec_device, 0, EC_CMD_EC_CODEC_DMIC,
 				    (uint8_t *)&p, sizeof(p), NULL, 0);
 }
 
@@ -231,7 +199,7 @@ 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,
+	ret = cros_ec_send_cmd_msg(priv->ec_device, 0, EC_CMD_EC_CODEC_DMIC,
 				   (uint8_t *)&p, sizeof(p),
 				   (uint8_t *)&r, sizeof(r));
 	if (ret < 0) {
@@ -279,7 +247,7 @@ 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,
+	ret = cros_ec_send_cmd_msg(priv->ec_device, 0, EC_CMD_EC_CODEC_I2S_RX,
 				   (uint8_t *)&p, sizeof(p), NULL, 0);
 	if (ret < 0)
 		return ret;
@@ -289,7 +257,7 @@ 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,
+	return cros_ec_send_cmd_msg(priv->ec_device, 0, EC_CMD_EC_CODEC_I2S_RX,
 				    (uint8_t *)&p, sizeof(p), NULL, 0);
 }
 
@@ -333,7 +301,7 @@ 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,
+	return cros_ec_send_cmd_msg(priv->ec_device, 0, EC_CMD_EC_CODEC_I2S_RX,
 				    (uint8_t *)&p, sizeof(p), NULL, 0);
 }
 
@@ -364,7 +332,7 @@ 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,
+	return cros_ec_send_cmd_msg(priv->ec_device, 0, EC_CMD_EC_CODEC_I2S_RX,
 				    (uint8_t *)&p, sizeof(p), NULL, 0);
 }
 
@@ -415,7 +383,7 @@ 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,
+	if (cros_ec_send_cmd_msg(priv->ec_device, 0, EC_CMD_EC_CODEC,
 				 (uint8_t *)&p, sizeof(p),
 				 (uint8_t *)&r, sizeof(r)) < 0) {
 		dev_err(priv->dev, "failed to EC_CODEC_GET_SHM_ADDR\n");
@@ -453,7 +421,7 @@ 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,
+		if (cros_ec_send_cmd_msg(priv->ec_device, 0, EC_CMD_EC_CODEC,
 					 (uint8_t *)&p, sizeof(p),
 					 NULL, 0) < 0) {
 			dev_err(priv->dev, "failed to EC_CODEC_SET_SHM_ADDR\n");
@@ -571,7 +539,7 @@ 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,
+	ret = cros_ec_send_cmd_msg(priv->ec_device, 0, EC_CMD_EC_CODEC_WOV,
 				   (uint8_t *)&p, sizeof(p),
 				   (uint8_t *)&r, sizeof(r));
 	if (ret) {
@@ -596,7 +564,8 @@ 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,
+		ret = cros_ec_send_cmd_msg(priv->ec_device, 0,
+					   EC_CMD_EC_CODEC_WOV,
 					   (uint8_t *)&p, sizeof(p),
 					   (uint8_t *)&r, sizeof(r));
 		if (ret) {
@@ -669,7 +638,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,
+		ret = cros_ec_send_cmd_msg(priv->ec_device, 0,
+					   EC_CMD_EC_CODEC_WOV,
 					   (uint8_t *)&p, sizeof(p), NULL, 0);
 		if (ret) {
 			dev_err(priv->dev, "failed to %s wov\n",
@@ -716,7 +686,7 @@ 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,
+	ret = cros_ec_send_cmd_msg(priv->ec_device, 0, EC_CMD_EC_CODEC_WOV,
 				   (uint8_t *)&p, sizeof(p), NULL, 0);
 	if (ret) {
 		dev_err(priv->dev, "failed to EC_CODEC_WOV_SET_LANG_SHM\n");
@@ -743,7 +713,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,
+		ret = cros_ec_send_cmd_msg(priv->ec_device, 0,
+					   EC_CMD_EC_CODEC_WOV,
 					   (uint8_t *)&p, sizeof(p), NULL, 0);
 		if (ret) {
 			dev_err(priv->dev, "failed to EC_CODEC_WOV_SET_LANG\n");
@@ -782,7 +753,7 @@ 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,
+	ret = cros_ec_send_cmd_msg(priv->ec_device, 0, EC_CMD_EC_CODEC_WOV,
 				   (uint8_t *)&p, sizeof(p),
 				   (uint8_t *)&r, sizeof(r));
 	if (ret)
@@ -1020,7 +991,7 @@ 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,
+	ret = cros_ec_send_cmd_msg(priv->ec_device, 0, EC_CMD_EC_CODEC,
 				   (uint8_t *)&p, sizeof(p),
 				   (uint8_t *)&r, sizeof(r));
 	if (ret) {
-- 
2.25.0.341.g760bfbb309-goog


  parent reply	other threads:[~2020-01-30 20:34 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-30 20:30 [PATCH 00/17] platform/chrome: Replace cros_ec_cmd_xfer_status Prashant Malani
2020-01-30 20:30 ` [PATCH 01/17] platform/chrome: Add EC command msg wrapper Prashant Malani
2020-02-03 15:27   ` Enric Balletbo i Serra
2020-02-03 18:24     ` Prashant Malani
2020-01-30 20:30 ` [PATCH 02/17] platform/chrome: chardev: Use send_cmd_msg() Prashant Malani
2020-01-30 20:30 ` [PATCH 03/17] platform/chrome: proto: Use send_cmd_msg Prashant Malani
2020-01-30 20:30 ` [PATCH 04/17] platform/chrome: usbpd_logger: Use cmd_send_msg() Prashant Malani
2020-01-30 20:30 ` [PATCH 05/17] platform/chrome: sensorhub: Use send_cmd_msg() Prashant Malani
2020-01-30 20:30 ` [PATCH 06/17] platform/chrome: debugfs: " Prashant Malani
2020-01-30 20:30 ` [PATCH 07/17] platform/chrome: sysfs: " Prashant Malani
2020-01-30 20:30 ` [PATCH 08/17] extcon: cros_ec: Use cros_ec_send_cmd_msg() Prashant Malani
2020-01-30 20:30 ` [PATCH 09/17] hid: google-hammer: " Prashant Malani
2020-01-30 20:30 ` [PATCH 10/17] iio: cros_ec: " Prashant Malani
2020-02-02  9:43   ` Jonathan Cameron
2020-02-03 18:31     ` Prashant Malani
2020-01-30 20:30 ` Prashant Malani [this message]
2020-02-01 11:03   ` [PATCH 11/17] ASoC: cros_ec_codec: " Mark Brown
2020-02-03 18:42     ` Prashant Malani
2020-01-30 20:30 ` [PATCH 12/17] power: supply: cros: " Prashant Malani
2020-01-30 20:31 ` [PATCH 13/17] pwm: cros-ec: Remove cros_ec_cmd_xfer_status() Prashant Malani
2020-02-03 15:33   ` Enric Balletbo i Serra
2020-02-03 18:26     ` Prashant Malani
2020-02-03 18:39       ` Prashant Malani
2020-01-30 20:31 ` [PATCH 14/17] rtc: cros-ec: Use cros_ec_send_cmd_msg() Prashant Malani
2020-01-30 20:31 ` [PATCH 15/17] media: cros-ec-cec: " Prashant Malani
2020-02-02 22:08   ` kbuild test robot
2020-02-03  5:35   ` kbuild test robot
2020-01-30 20:31 ` [PATCH 16/17] i2c: cros-ec-tunnel: " Prashant Malani
2020-01-30 20:31 ` [PATCH 17/17] platform/chrome: Drop cros_ec_cmd_xfer_status() Prashant Malani
2020-02-03 15:35   ` Enric Balletbo i Serra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200130203106.201894-12-pmalani@chromium.org \
    --to=pmalani@chromium.org \
    --cc=alsa-devel@alsa-project.org \
    --cc=bleung@chromium.org \
    --cc=broonie@kernel.org \
    --cc=cychiang@chromium.org \
    --cc=enric.balletbo@collabora.com \
    --cc=groeck@chromium.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).