Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Benson Leung <bleung@google.com>
To: Tzung-Bi Shih <tzungbi@google.com>
Cc: gwendal@google.com, devicetree@vger.kernel.org,
	alsa-devel@alsa-project.org, cychiang@google.com,
	drinkcat@google.com, robh+dt@kernel.org, broonie@kernel.org,
	enric.balletbo@collabora.com, dgreid@google.com,
	Rob Herring <robh@kernel.org>
Subject: Re: [alsa-devel] [PATCH v3 05/10] ASoC: cros_ec_codec: read max DMIC gain from EC codec
Date: Wed, 16 Oct 2019 20:07:17 -0700	[thread overview]
Message-ID: <20191017030717.GC72195@google.com> (raw)
In-Reply-To: <20191014180059.05.Id4657c864d544634f2b5c1c9b34fa8232ecba44d@changeid>


[-- Attachment #1.1: Type: text/plain, Size: 7724 bytes --]

On Mon, Oct 14, 2019 at 06:20:17PM +0800, Tzung-Bi Shih wrote:
> 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>
> Signed-off-by: Tzung-Bi Shih <tzungbi@google.com>

Acked-By: Benson Leung <bleung@chromium.org>


> ---
>  .../bindings/sound/google,cros-ec-codec.txt   |  4 +-
>  .../linux/platform_data/cros_ec_commands.h    | 43 +++++++++++----
>  sound/soc/codecs/cros_ec_codec.c              | 53 ++++++++++++++-----
>  3 files changed, 73 insertions(+), 27 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/sound/google,cros-ec-codec.txt b/Documentation/devicetree/bindings/sound/google,cros-ec-codec.txt
> index 1084f7f22eea..0ce9fafc78e2 100644
> --- a/Documentation/devicetree/bindings/sound/google,cros-ec-codec.txt
> +++ b/Documentation/devicetree/bindings/sound/google,cros-ec-codec.txt
> @@ -1,4 +1,4 @@
> -* Audio codec controlled by ChromeOS EC
> +Audio codec controlled by ChromeOS EC
>  
>  Google's ChromeOS EC codec is a digital mic codec provided by the
>  Embedded Controller (EC) and is controlled via a host-command interface.
> @@ -9,7 +9,6 @@ Documentation/devicetree/bindings/mfd/cros-ec.txt).
>  Required properties:
>  - compatible: Must contain "google,cros-ec-codec"
>  - #sound-dai-cells: Should be 1. The cell specifies number of DAIs.
> -- max-dmic-gain: A number for maximum gain in dB on digital microphone.
>  
>  Example:
>  
> @@ -21,6 +20,5 @@ cros-ec@0 {
>  	cros_ec_codec: ec-codec {
>  		compatible = "google,cros-ec-codec";
>  		#sound-dai-cells = <1>;
> -		max-dmic-gain = <43>;
>  	};
>  };
> diff --git a/include/linux/platform_data/cros_ec_commands.h b/include/linux/platform_data/cros_ec_commands.h
> index 3ca0fa9e92a7..21db0d4d4025 100644
> --- a/include/linux/platform_data/cros_ec_commands.h
> +++ b/include/linux/platform_data/cros_ec_commands.h
> @@ -4530,30 +4530,53 @@ struct __ec_align4 ec_response_ec_codec_get_shm_addr {
>  #define EC_CMD_EC_CODEC_DMIC 0x00BD
>  
>  enum ec_codec_dmic_subcmd {
> -	EC_CODEC_DMIC_SET_GAIN = 0x0,
> -	EC_CODEC_DMIC_GET_GAIN = 0x1,
> +	EC_CODEC_DMIC_GET_MAX_GAIN = 0x0,
> +	EC_CODEC_DMIC_SET_GAIN_IDX = 0x1,
> +	EC_CODEC_DMIC_GET_GAIN_IDX = 0x2,
>  	EC_CODEC_DMIC_SUBCMD_COUNT,
>  };
>  
> -struct __ec_align1 ec_param_ec_codec_dmic_set_gain {
> -	uint8_t left;
> -	uint8_t right;
> +enum ec_codec_dmic_channel {
> +	EC_CODEC_DMIC_CHANNEL_0 = 0x0,
> +	EC_CODEC_DMIC_CHANNEL_1 = 0x1,
> +	EC_CODEC_DMIC_CHANNEL_2 = 0x2,
> +	EC_CODEC_DMIC_CHANNEL_3 = 0x3,
> +	EC_CODEC_DMIC_CHANNEL_4 = 0x4,
> +	EC_CODEC_DMIC_CHANNEL_5 = 0x5,
> +	EC_CODEC_DMIC_CHANNEL_6 = 0x6,
> +	EC_CODEC_DMIC_CHANNEL_7 = 0x7,
> +	EC_CODEC_DMIC_CHANNEL_COUNT,
> +};
> +
> +struct __ec_align1 ec_param_ec_codec_dmic_set_gain_idx {
> +	uint8_t channel; /* enum ec_codec_dmic_channel */
> +	uint8_t gain;
>  	uint8_t reserved[2];
>  };
>  
> +struct __ec_align1 ec_param_ec_codec_dmic_get_gain_idx {
> +	uint8_t channel; /* enum ec_codec_dmic_channel */
> +	uint8_t reserved[3];
> +};
> +
>  struct __ec_align4 ec_param_ec_codec_dmic {
>  	uint8_t cmd; /* enum ec_codec_dmic_subcmd */
>  	uint8_t reserved[3];
>  
>  	union {
> -		struct ec_param_ec_codec_dmic_set_gain
> -				set_gain_param;
> +		struct ec_param_ec_codec_dmic_set_gain_idx
> +				set_gain_idx_param;
> +		struct ec_param_ec_codec_dmic_get_gain_idx
> +				get_gain_idx_param;
>  	};
>  };
>  
> -struct __ec_align1 ec_response_ec_codec_dmic_get_gain {
> -	uint8_t left;
> -	uint8_t right;
> +struct __ec_align1 ec_response_ec_codec_dmic_get_max_gain {
> +	uint8_t max_gain;
> +};
> +
> +struct __ec_align1 ec_response_ec_codec_dmic_get_gain_idx {
> +	uint8_t gain;
>  };
>  
>  /*****************************************************************************/
> 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);
> -- 
> 2.23.0.700.g56cf767bdb-goog
> 

-- 
Benson Leung
Staff Software Engineer
Chrome OS Kernel
Google Inc.
bleung@google.com
Chromium OS Project
bleung@chromium.org

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

[-- Attachment #2: Type: text/plain, Size: 161 bytes --]

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

  reply	other threads:[~2019-10-17  3:08 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-14 10:20 [alsa-devel] [PATCH v3 00/10] ASoC: mediatek: mt8183-mt6358-ts3a227-max98357: support WoV Tzung-Bi Shih
2019-10-14 10:20 ` [alsa-devel] [PATCH v3 01/10] platform/chrome: cros_ec: remove unused EC feature Tzung-Bi Shih
2019-10-15 11:48   ` Mark Brown
2019-10-15 15:37     ` Tzung-Bi Shih
2019-10-17  2:25   ` Benson Leung
2019-10-18 18:06   ` [alsa-devel] Applied "platform/chrome: cros_ec: remove unused EC feature" to the asoc tree Mark Brown
2019-10-14 10:20 ` [alsa-devel] [PATCH v3 02/10] ASoC: cros_ec_codec: refactor I2S RX Tzung-Bi Shih
2019-10-17  2:30   ` Benson Leung
2019-10-18 18:06   ` [alsa-devel] Applied "ASoC: cros_ec_codec: refactor I2S RX" to the asoc tree Mark Brown
2019-10-14 10:20 ` [alsa-devel] [PATCH v3 03/10] ASoC: cros_ec_codec: extract DMIC EC command from I2S RX Tzung-Bi Shih
2019-10-17  2:48   ` Benson Leung
2019-10-18 18:06   ` [alsa-devel] Applied "ASoC: cros_ec_codec: extract DMIC EC command from I2S RX" to the asoc tree Mark Brown
2019-10-14 10:20 ` [alsa-devel] [PATCH v3 04/10] platform/chrome: cros_ec: add common commands for EC codec Tzung-Bi Shih
2019-10-17  2:57   ` Benson Leung
2019-10-14 10:20 ` [alsa-devel] [PATCH v3 05/10] ASoC: cros_ec_codec: read max DMIC gain from " Tzung-Bi Shih
2019-10-17  3:07   ` Benson Leung [this message]
2019-10-14 10:20 ` [alsa-devel] [PATCH v3 06/10] ASoC: dt-bindings: cros_ec_codec: add SHM bindings Tzung-Bi Shih
2019-10-14 17:23   ` Rob Herring
2019-10-17  3:12   ` Benson Leung
2019-10-14 10:20 ` [alsa-devel] [PATCH v3 07/10] ASoC: cros_ec_codec: support WoV Tzung-Bi Shih
2019-10-15  1:34   ` kbuild test robot
2019-10-15  6:49     ` Tzung-Bi Shih
2019-10-17 11:43       ` Mark Brown
2019-10-15  3:20   ` kbuild test robot
2019-10-14 10:20 ` [alsa-devel] [PATCH v3 08/10] ASoC: mediatek: mt6358: " Tzung-Bi Shih
2019-10-14 10:20 ` [alsa-devel] [PATCH v3 09/10] ASoC: dt-bindings: mt8183: add ec-codec Tzung-Bi Shih
2019-10-14 17:23   ` Rob Herring
2019-10-14 10:20 ` [alsa-devel] [PATCH v3 10/10] ASoC: mediatek: mt8183: support WoV Tzung-Bi Shih
2019-10-14 12:34 ` [alsa-devel] [PATCH v3 00/10] ASoC: mediatek: mt8183-mt6358-ts3a227-max98357: " Tzung-Bi Shih

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=20191017030717.GC72195@google.com \
    --to=bleung@google.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=cychiang@google.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dgreid@google.com \
    --cc=drinkcat@google.com \
    --cc=enric.balletbo@collabora.com \
    --cc=gwendal@google.com \
    --cc=robh+dt@kernel.org \
    --cc=robh@kernel.org \
    --cc=tzungbi@google.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