All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Lee, RyanS" <RyanS.Lee@analog.com>
To: Mark Brown <broonie@kernel.org>, Ryan Lee <ryan.lee.analog@gmail.com>
Cc: "lgirdwood@gmail.com" <lgirdwood@gmail.com>,
	"robh+dt@kernel.org" <robh+dt@kernel.org>,
	"krzk+dt@kernel.org" <krzk+dt@kernel.org>,
	"perex@perex.cz" <perex@perex.cz>,
	"tiwai@suse.com" <tiwai@suse.com>,
	"srinivas.kandagatla@linaro.org" <srinivas.kandagatla@linaro.org>,
	"ckeepax@opensource.cirrus.com" <ckeepax@opensource.cirrus.com>,
	"tanureal@opensource.cirrus.com" <tanureal@opensource.cirrus.com>,
	"cy_huang@richtek.com" <cy_huang@richtek.com>,
	"pierre-louis.bossart@linux.intel.com" 
	<pierre-louis.bossart@linux.intel.com>,
	"drhodes@opensource.cirrus.com" <drhodes@opensource.cirrus.com>,
	"pbrobinson@gmail.com" <pbrobinson@gmail.com>,
	"hdegoede@redhat.com" <hdegoede@redhat.com>,
	"lukas.bulwahn@gmail.com" <lukas.bulwahn@gmail.com>,
	"stephan@gerhold.net" <stephan@gerhold.net>,
	"arnd@arndb.de" <arnd@arndb.de>,
	"alsa-devel@alsa-project.org" <alsa-devel@alsa-project.org>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH 2/2] ASoC: max98396: add amplifier driver
Date: Thu, 21 Apr 2022 22:38:56 +0000	[thread overview]
Message-ID: <PH0PR03MB6692FB5695AE82C3EE38E6108AF49@PH0PR03MB6692.namprd03.prod.outlook.com> (raw)
In-Reply-To: <YmAyLuZIT1zYfNeA@sirena.org.uk>

> -----Original Message-----
> From: Mark Brown <broonie@kernel.org>
> Sent: Wednesday, April 20, 2022 9:18 AM
> To: Ryan Lee <ryan.lee.analog@gmail.com>
> Cc: lgirdwood@gmail.com; robh+dt@kernel.org; krzk+dt@kernel.org;
> perex@perex.cz; tiwai@suse.com; srinivas.kandagatla@linaro.org;
> ckeepax@opensource.cirrus.com; tanureal@opensource.cirrus.com;
> cy_huang@richtek.com; pierre-louis.bossart@linux.intel.com;
> drhodes@opensource.cirrus.com; pbrobinson@gmail.com;
> hdegoede@redhat.com; lukas.bulwahn@gmail.com;
> stephan@gerhold.net; arnd@arndb.de; alsa-devel@alsa-project.org;
> devicetree@vger.kernel.org; linux-kernel@vger.kernel.org; Lee, RyanS
> <RyanS.Lee@analog.com>
> Subject: Re: [PATCH 2/2] ASoC: max98396: add amplifier driver
> 
> [External]
> 
> On Fri, Apr 15, 2022 at 05:40:24PM -0700, Ryan Lee wrote:
> 
> This looks mostly good - some issues below but nothing structural.
> 
> > +	switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
> > +	case SND_SOC_DAIFMT_NB_NF:
> > +	case SND_SOC_DAIFMT_NB_IF:
> > +		break;
> 
> One of these must be wrong - the device needs to know if it's
> handling a normal or inverted frame clock, otherwise the audio will
> be corrupted.

Thanks for pointing this out.
BCLK and FSYNC clock polarity configuration was inappropriate.
I shall fix this.

> 
> > +static int max98396_mux_put(struct snd_kcontrol *kcontrol,
> > +			    struct snd_ctl_elem_value *ucontrol) {
> > +	struct snd_soc_component *component =
> > +		snd_soc_dapm_kcontrol_component(kcontrol);
> > +	struct snd_soc_dapm_context *dapm =
> snd_soc_dapm_kcontrol_dapm(kcontrol);
> > +	struct max98396_priv *max98396 =
> snd_soc_component_get_drvdata(component);
> > +	struct soc_enum *e = (struct soc_enum *)kcontrol-
> >private_value;
> > +	unsigned int *item = ucontrol->value.enumerated.item;
> > +	int reg, val;
> > +
> > +	if (item[0] >= e->items)
> > +		return -EINVAL;
> > +
> > +	val = snd_soc_enum_item_to_val(e, item[0]) << e->shift_l;
> > +
> > +	if (max98396->device_id == CODEC_TYPE_MAX98396)
> > +		reg = MAX98396_R2055_PCM_RX_SRC1;
> > +	else
> > +		reg = MAX98397_R2056_PCM_RX_SRC1;
> > +
> > +	regmap_update_bits(max98396->regmap, reg,
> > +			   MAX98396_PCM_RX_MASK, val);
> > +
> > +	snd_soc_dapm_mux_update_power(dapm, kcontrol, item[0],
> e, NULL);
> > +
> > +	return 0;
> > +}
> 
> This should return 1 if the value changed - you should get an error
> reported by mixer-test from selftests if you run them on a sound card
> with the driver.

Thanks. Shall fix this on the v2.

> 
> > +	/* L/R mix configuration */
> > +	if (max98396->device_id == CODEC_TYPE_MAX98396) {
> > +		regmap_write(max98396->regmap,
> > +			     MAX98396_R2055_PCM_RX_SRC1, 0x02);
> > +		regmap_write(max98396->regmap,
> > +			     MAX98396_R2056_PCM_RX_SRC2, 0x10);
> > +	} else {
> > +		regmap_write(max98396->regmap,
> > +			     MAX98397_R2056_PCM_RX_SRC1, 0x02);
> > +		regmap_write(max98396->regmap,
> > +			     MAX98397_R2057_PCM_RX_SRC2, 0x10);
> > +	}
> 
> Shouldn't these be user controllable?  Most of the setup being done
> here looks system specific, especially the routing stuff.

MAX98396 is a mono amplifer and 'DAI MUX Sel' mixer control is provided for
audio mono mix. The chip default configuration take the left channel only,
so I wanted to set (L+R)/2 as default. The user still can change this value.
0x2057 is an extra register for the left and the right channel selection.
The user do not need to control this register because 'DAI MUX Sel' already
supports same function. Thank you.

WARNING: multiple messages have this Message-ID (diff)
From: "Lee, RyanS" <RyanS.Lee@analog.com>
To: Mark Brown <broonie@kernel.org>, Ryan Lee <ryan.lee.analog@gmail.com>
Cc: "drhodes@opensource.cirrus.com" <drhodes@opensource.cirrus.com>,
	"pierre-louis.bossart@linux.intel.com"
	<pierre-louis.bossart@linux.intel.com>,
	"alsa-devel@alsa-project.org" <alsa-devel@alsa-project.org>,
	"ckeepax@opensource.cirrus.com" <ckeepax@opensource.cirrus.com>,
	"stephan@gerhold.net" <stephan@gerhold.net>,
	"tanureal@opensource.cirrus.com" <tanureal@opensource.cirrus.com>,
	"hdegoede@redhat.com" <hdegoede@redhat.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"tiwai@suse.com" <tiwai@suse.com>,
	"lgirdwood@gmail.com" <lgirdwood@gmail.com>,
	"cy_huang@richtek.com" <cy_huang@richtek.com>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	"robh+dt@kernel.org" <robh+dt@kernel.org>,
	"srinivas.kandagatla@linaro.org" <srinivas.kandagatla@linaro.org>,
	"pbrobinson@gmail.com" <pbrobinson@gmail.com>,
	"lukas.bulwahn@gmail.com" <lukas.bulwahn@gmail.com>,
	"krzk+dt@kernel.org" <krzk+dt@kernel.org>,
	"arnd@arndb.de" <arnd@arndb.de>
Subject: RE: [PATCH 2/2] ASoC: max98396: add amplifier driver
Date: Thu, 21 Apr 2022 22:38:56 +0000	[thread overview]
Message-ID: <PH0PR03MB6692FB5695AE82C3EE38E6108AF49@PH0PR03MB6692.namprd03.prod.outlook.com> (raw)
In-Reply-To: <YmAyLuZIT1zYfNeA@sirena.org.uk>

> -----Original Message-----
> From: Mark Brown <broonie@kernel.org>
> Sent: Wednesday, April 20, 2022 9:18 AM
> To: Ryan Lee <ryan.lee.analog@gmail.com>
> Cc: lgirdwood@gmail.com; robh+dt@kernel.org; krzk+dt@kernel.org;
> perex@perex.cz; tiwai@suse.com; srinivas.kandagatla@linaro.org;
> ckeepax@opensource.cirrus.com; tanureal@opensource.cirrus.com;
> cy_huang@richtek.com; pierre-louis.bossart@linux.intel.com;
> drhodes@opensource.cirrus.com; pbrobinson@gmail.com;
> hdegoede@redhat.com; lukas.bulwahn@gmail.com;
> stephan@gerhold.net; arnd@arndb.de; alsa-devel@alsa-project.org;
> devicetree@vger.kernel.org; linux-kernel@vger.kernel.org; Lee, RyanS
> <RyanS.Lee@analog.com>
> Subject: Re: [PATCH 2/2] ASoC: max98396: add amplifier driver
> 
> [External]
> 
> On Fri, Apr 15, 2022 at 05:40:24PM -0700, Ryan Lee wrote:
> 
> This looks mostly good - some issues below but nothing structural.
> 
> > +	switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
> > +	case SND_SOC_DAIFMT_NB_NF:
> > +	case SND_SOC_DAIFMT_NB_IF:
> > +		break;
> 
> One of these must be wrong - the device needs to know if it's
> handling a normal or inverted frame clock, otherwise the audio will
> be corrupted.

Thanks for pointing this out.
BCLK and FSYNC clock polarity configuration was inappropriate.
I shall fix this.

> 
> > +static int max98396_mux_put(struct snd_kcontrol *kcontrol,
> > +			    struct snd_ctl_elem_value *ucontrol) {
> > +	struct snd_soc_component *component =
> > +		snd_soc_dapm_kcontrol_component(kcontrol);
> > +	struct snd_soc_dapm_context *dapm =
> snd_soc_dapm_kcontrol_dapm(kcontrol);
> > +	struct max98396_priv *max98396 =
> snd_soc_component_get_drvdata(component);
> > +	struct soc_enum *e = (struct soc_enum *)kcontrol-
> >private_value;
> > +	unsigned int *item = ucontrol->value.enumerated.item;
> > +	int reg, val;
> > +
> > +	if (item[0] >= e->items)
> > +		return -EINVAL;
> > +
> > +	val = snd_soc_enum_item_to_val(e, item[0]) << e->shift_l;
> > +
> > +	if (max98396->device_id == CODEC_TYPE_MAX98396)
> > +		reg = MAX98396_R2055_PCM_RX_SRC1;
> > +	else
> > +		reg = MAX98397_R2056_PCM_RX_SRC1;
> > +
> > +	regmap_update_bits(max98396->regmap, reg,
> > +			   MAX98396_PCM_RX_MASK, val);
> > +
> > +	snd_soc_dapm_mux_update_power(dapm, kcontrol, item[0],
> e, NULL);
> > +
> > +	return 0;
> > +}
> 
> This should return 1 if the value changed - you should get an error
> reported by mixer-test from selftests if you run them on a sound card
> with the driver.

Thanks. Shall fix this on the v2.

> 
> > +	/* L/R mix configuration */
> > +	if (max98396->device_id == CODEC_TYPE_MAX98396) {
> > +		regmap_write(max98396->regmap,
> > +			     MAX98396_R2055_PCM_RX_SRC1, 0x02);
> > +		regmap_write(max98396->regmap,
> > +			     MAX98396_R2056_PCM_RX_SRC2, 0x10);
> > +	} else {
> > +		regmap_write(max98396->regmap,
> > +			     MAX98397_R2056_PCM_RX_SRC1, 0x02);
> > +		regmap_write(max98396->regmap,
> > +			     MAX98397_R2057_PCM_RX_SRC2, 0x10);
> > +	}
> 
> Shouldn't these be user controllable?  Most of the setup being done
> here looks system specific, especially the routing stuff.

MAX98396 is a mono amplifer and 'DAI MUX Sel' mixer control is provided for
audio mono mix. The chip default configuration take the left channel only,
so I wanted to set (L+R)/2 as default. The user still can change this value.
0x2057 is an extra register for the left and the right channel selection.
The user do not need to control this register because 'DAI MUX Sel' already
supports same function. Thank you.

  reply	other threads:[~2022-04-21 22:40 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-16  0:40 [PATCH 1/2] ASoC: dt-bindings: max98396: add amplifier driver Ryan Lee
2022-04-16  0:40 ` [PATCH 2/2] ASoC: " Ryan Lee
2022-04-20 16:17   ` Mark Brown
2022-04-20 16:17     ` Mark Brown
2022-04-21 22:38     ` Lee, RyanS [this message]
2022-04-21 22:38       ` Lee, RyanS
2022-04-16 22:17 ` [PATCH 1/2] ASoC: dt-bindings: " Rob Herring
2022-04-16 22:17   ` Rob Herring
2022-04-18 22:32   ` Lee, RyanS
2022-04-18 22:32     ` Lee, RyanS

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=PH0PR03MB6692FB5695AE82C3EE38E6108AF49@PH0PR03MB6692.namprd03.prod.outlook.com \
    --to=ryans.lee@analog.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=arnd@arndb.de \
    --cc=broonie@kernel.org \
    --cc=ckeepax@opensource.cirrus.com \
    --cc=cy_huang@richtek.com \
    --cc=devicetree@vger.kernel.org \
    --cc=drhodes@opensource.cirrus.com \
    --cc=hdegoede@redhat.com \
    --cc=krzk+dt@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lukas.bulwahn@gmail.com \
    --cc=pbrobinson@gmail.com \
    --cc=perex@perex.cz \
    --cc=pierre-louis.bossart@linux.intel.com \
    --cc=robh+dt@kernel.org \
    --cc=ryan.lee.analog@gmail.com \
    --cc=srinivas.kandagatla@linaro.org \
    --cc=stephan@gerhold.net \
    --cc=tanureal@opensource.cirrus.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.