All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Chiang, Mac" <mac.chiang@intel.com>
To: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>,
	"alsa-devel@alsa-project.org" <alsa-devel@alsa-project.org>
Cc: "Arava, Jairaj" <jairaj.arava@intel.com>,
	"mark_hsieh@wistron.com" <mark_hsieh@wistron.com>,
	"Cheng, Keith" <keith.tzeng@quantatw.com>,
	"broonie@kernel.org" <broonie@kernel.org>,
	"Nujella, Sathyanarayana" <sathyanarayana.nujella@intel.com>,
	"Liao,  Bard" <bard.liao@intel.com>
Subject: RE: [PATCH v2] ASoC: Intel: boards: add max98390 2/4 speakers support
Date: Tue, 14 Sep 2021 16:46:01 +0000	[thread overview]
Message-ID: <DM5PR1101MB2091939E461BFA0313FA4B0184DA9@DM5PR1101MB2091.namprd11.prod.outlook.com> (raw)
In-Reply-To: <06178b15-9ab2-4c8b-4354-17063ed0fe0d@linux.intel.com>

> I don't quite follow the initialization part. In the 4-ch case, you will setup
> control and widgets but...
> 
> > +int max_98390_spk_codec_init(struct snd_soc_pcm_runtime *rtd) {
> > +	struct snd_soc_card *card = rtd->card;
> > +	int ret;
> > +
> > +	ret = snd_soc_dapm_new_controls(&card->dapm,
> max_98390_tt_dapm_widgets,
> > +
> 	ARRAY_SIZE(max_98390_tt_dapm_widgets));
> > +	if (ret) {
> > +		dev_err(rtd->dev, "unable to add dapm controls, ret %d\n",
> ret);
> > +		/* Don't need to add routes if widget addition failed */
> > +		return ret;
> > +	}
> > +
> > +	ret = snd_soc_add_card_controls(card, max_98390_tt_kcontrols,
> > +
> 	ARRAY_SIZE(max_98390_tt_kcontrols));
> > +	if (ret) {
> > +		dev_err(rtd->dev, "unable to add card controls, ret %d\n",
> ret);
> > +		return ret;
> > +	}
> > +
> > +	ret = snd_soc_dapm_add_routes(&card->dapm,
> max_98373_dapm_routes,
> > +
> 	ARRAY_SIZE(max_98373_dapm_routes));
> > +	if (ret) {
> > +		dev_err(rtd->dev, "Speaker Left, Right  map addition failed:
> %d\n", ret);
> > +		return ret;
> > +	}
> > +
> > +	ret = snd_soc_dapm_add_routes(&card->dapm,
> max_98390_tt_dapm_routes,
> > +
> 	ARRAY_SIZE(max_98390_tt_dapm_routes));
> > +	if (ret)
> > +		dev_err(rtd->dev, "Tweeter Speaker Left, Right map addition
> failed:
> > +%d\n", ret);
> > +
> > +	return ret;
> > +}
> > +EXPORT_SYMBOL_NS(max_98390_spk_codec_init,
> > +SND_SOC_INTEL_SOF_MAXIM_COMMON);
> 
> > @@ -745,6 +778,21 @@ static struct snd_soc_dai_link
> *sof_card_dai_links_create(struct device *dev,
> >  		} else if (sof_rt5682_quirk &
> >  				SOF_RT1011_SPEAKER_AMP_PRESENT) {
> >  			sof_rt1011_dai_link(&links[id]);
> > +		} else if (sof_rt5682_quirk &
> > +				SOF_MAX98390_SPEAKER_AMP_PRESENT) {
> > +			if (sof_rt5682_quirk &
> > +
> 	SOF_MAX98390_TWEETER_SPEAKER_PRESENT) {
> > +				links[id].codecs =
> max_98390_4spk_components;
> > +				links[id].num_codecs =
> ARRAY_SIZE(max_98390_4spk_components);
> > +				links[id].init = max_98390_spk_codec_init;
> > +			} else {
> > +				links[id].codecs = max_98390_components;
> > +				links[id].num_codecs =
> ARRAY_SIZE(max_98390_components);
> > +				links[id].init = max_98373_spk_codec_init;
> > +			}
> 
> ... in the 2 ch case you use this function
> 
> int max_98373_spk_codec_init(struct snd_soc_pcm_runtime *rtd) {
> 	struct snd_soc_card *card = rtd->card;
> 	int ret;
> 
> 	ret = snd_soc_dapm_add_routes(&card->dapm,
> max_98373_dapm_routes,
> 				      ARRAY_SIZE(max_98373_dapm_routes));
> 	if (ret)
> 		dev_err(rtd->dev, "Speaker map addition failed: %d\n", ret);
> 	return ret;
> }
> 
> which only adds routes. Isn't there a need for widgets/controls for the
> 2 channel case as well?
2 channels controls/widgets already exist in sof_controls[] and sof_widgets[] from sof_rt5682.c
> 
> It's also not good practice to mix the initialization of max98090 with a
> function with an explicit 98373 prefix. it's hard to maintain and error-prone.
> You might as well duplicate the function, if it's not used it will be removed
> while linking. 
I am not sure whether I understand your suggestions.
When both using links[id].init = max_98390_spk_codec_init;
I can only think out add 2 spk dapm initially then check if 4 codec existing by using acpi_dev_present with uid.
If no good, any example I can refer to?

int max_98390_spk_codec_init(struct snd_soc_pcm_runtime *rtd, int num_amps)
{
        struct snd_soc_card *card = rtd->card;
        int ret;

        ret = snd_soc_dapm_add_routes(&card->dapm, max_98390_dapm_routes,
                                        ARRAY_SIZE(max_98390_dapm_routes));
 	if (ret)
 		dev_err(rtd->dev, "Speaker map addition failed: %d\n", ret);

        if (acpi_dev_present("MX98390", "3", -1)) {
            ret = snd_soc_dapm_new_controls(&card->dapm, max_98390_tt_dapm_widgets,
                                                             ARRAY_SIZE(max_98390_tt_dapm_widgets));
	if (ret) {
	        dev_err(rtd->dev, "unable to add dapm controls, ret %d\n", ret);
	        /* Don't need to add routes if widget addition failed */
	        return ret;
	}
	
	ret = snd_soc_add_card_controls(card, max_98390_tt_kcontrols,
	                                        ARRAY_SIZE(max_98390_tt_kcontrols));
	if (ret) {
	        dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret);
	        return ret;
	}
	
	ret = snd_soc_dapm_add_routes(&card->dapm, max_98390_tt_dapm_routes,
	                                        ARRAY_SIZE(max_98390_tt_dapm_routes));
	if (ret)
	        dev_err(rtd->dev, "Tweeter Speaker Left, Right map addition failed: %d\n", ret);
        }
        return ret;
} 
> > +			links[id].ops = &max_98390_ops;
> > +			links[id].dpcm_capture = 1;
> > +
> >  		} else {
> >  			max_98357a_dai_link(&links[id]);
> >  		}
> > @@ -881,6 +929,14 @@ static int sof_audio_probe(struct platform_device
> *pdev)
> >  		sof_rt1011_codec_conf(&sof_audio_card_rt5682);
> >  	else if (sof_rt5682_quirk & SOF_RT1015P_SPEAKER_AMP_PRESENT)
> >  		sof_rt1015p_codec_conf(&sof_audio_card_rt5682);
> > +	else if (sof_rt5682_quirk & SOF_MAX98390_SPEAKER_AMP_PRESENT)
> {
> > +		if (sof_rt5682_quirk &
> SOF_MAX98390_TWEETER_SPEAKER_PRESENT)
> > +
> 	max_98390_set_codec_conf(&sof_audio_card_rt5682,
> > +
> 	ARRAY_SIZE(max_98390_4spk_components));
> > +		else
> > +
> 	max_98390_set_codec_conf(&sof_audio_card_rt5682,
> > +
> 	ARRAY_SIZE(max_98390_components));
> > +	}
> >
> >  	if (sof_rt5682_quirk & SOF_SSP_BT_OFFLOAD_PRESENT)
> >  		sof_audio_card_rt5682.num_links++;
> > @@ -1007,6 +1063,18 @@ static const struct platform_device_id
> board_ids[] = {
> >  					SOF_RT5682_SSP_AMP(2) |
> >  					SOF_RT5682_NUM_HDMIDEV(4)),
> >  	},
> > +	{
> > +		.name = "adl_max98390_rt5682",
> > +		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
> > +					SOF_RT5682_SSP_CODEC(0) |
> > +					SOF_SPEAKER_AMP_PRESENT |
> > +
> 	SOF_MAX98390_SPEAKER_AMP_PRESENT |
> > +					SOF_RT5682_SSP_AMP(1) |
> > +					SOF_RT5682_NUM_HDMIDEV(4) |
> > +					SOF_BT_OFFLOAD_SSP(2) |
> > +					SOF_SSP_BT_OFFLOAD_PRESENT),
> > +	},
> > +
> >  	{ }
> >  };
> >  MODULE_DEVICE_TABLE(platform, board_ids); @@ -1026,6 +1094,7 @@
> > MODULE_DESCRIPTION("SOF Audio Machine driver");
> MODULE_AUTHOR("Bard
> > Liao <bard.liao@intel.com>");  MODULE_AUTHOR("Sathya Prakash M R
> > <sathya.prakash.m.r@intel.com>");  MODULE_AUTHOR("Brent Lu
> > <brent.lu@intel.com>");
> > +MODULE_AUTHOR("Mac Chiang <mac.chiang@intel.com>");
> >  MODULE_LICENSE("GPL v2");
> >  MODULE_IMPORT_NS(SND_SOC_INTEL_HDA_DSP_COMMON);
> >  MODULE_IMPORT_NS(SND_SOC_INTEL_SOF_MAXIM_COMMON);
> > diff --git a/sound/soc/intel/common/soc-acpi-intel-adl-match.c
> > b/sound/soc/intel/common/soc-acpi-intel-adl-match.c
> > index a0f6a69c7038..2db152998e4a 100644
> > --- a/sound/soc/intel/common/soc-acpi-intel-adl-match.c
> > +++ b/sound/soc/intel/common/soc-acpi-intel-adl-match.c
> > @@ -280,6 +280,11 @@ static const struct snd_soc_acpi_codecs
> adl_max98357a_amp = {
> >  	.codecs = {"MX98357A"}
> >  };
> >
> > +static const struct snd_soc_acpi_codecs adl_max98390_amp = {
> > +	.num_codecs = 1,
> > +	.codecs = {"MX98390"}
> > +};
> > +
> >  struct snd_soc_acpi_mach snd_soc_acpi_intel_adl_machines[] = {
> >  	{
> >  		.id = "10EC5682",
> > @@ -297,6 +302,14 @@ struct snd_soc_acpi_mach
> snd_soc_acpi_intel_adl_machines[] = {
> >  		.sof_fw_filename = "sof-adl.ri",
> >  		.sof_tplg_filename = "sof-adl-max98357a-rt5682.tplg",
> >  	},
> > +	{
> > +		.id = "10EC5682",
> > +		.drv_name = "adl_max98390_rt5682",
> > +		.machine_quirk = snd_soc_acpi_codec_list,
> > +		.quirk_data = &adl_max98390_amp,
> > +		.sof_fw_filename = "sof-adl.ri",
> > +		.sof_tplg_filename = "sof-adl-max98390-rt5682.tplg",
> > +	},
> >  	{},
> >  };
> >  EXPORT_SYMBOL_GPL(snd_soc_acpi_intel_adl_machines);
> > diff --git a/sound/soc/sof/sof-pci-dev.c b/sound/soc/sof/sof-pci-dev.c
> > index bc9e70765678..be90a5f79766 100644
> > --- a/sound/soc/sof/sof-pci-dev.c
> > +++ b/sound/soc/sof/sof-pci-dev.c
> > @@ -59,6 +59,15 @@ static const struct dmi_system_id sof_tplg_table[] =
> {
> >  		},
> >  		.driver_data = "sof-adl-rt5682-ssp0-max98373-ssp2.tplg",
> >  	},
> > +	{
> > +		.callback = sof_tplg_cb,
> > +		.matches = {
> > +			DMI_MATCH(DMI_PRODUCT_FAMILY,
> "Google_Brya"),
> > +			DMI_MATCH(DMI_OEM_STRING, "AUDIO-
> MAX98390_ALC5682I_I2S"),
> > +		},
> > +		.driver_data = "sof-adl-max98390-ssp2-rt5682-ssp0.tplg",
> > +	},
> > +
> 
> I am still relatively confused since you still have two alternatives for topology
> but you described three configurations.
3rd hw board without quirk, so it is applying SSP1 2 speakers which declare in board_id[]. 

        {
                .name = "adl_max98390_rt5682",
                .driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
                                        SOF_RT5682_SSP_CODEC(0) |
                                        SOF_SPEAKER_AMP_PRESENT |
                                        SOF_MAX98390_SPEAKER_AMP_PRESENT |
                                        SOF_RT5682_SSP_AMP(1) |
                                        SOF_RT5682_NUM_HDMIDEV(4) |
                                        SOF_BT_OFFLOAD_SSP(2) |
                                        SOF_SSP_BT_OFFLOAD_PRESENT),
        },

      reply	other threads:[~2021-09-14 16:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-13 10:00 [PATCH v2] ASoC: Intel: boards: add max98390 2/4 speakers support Mac Chiang
2021-09-13 16:21 ` Pierre-Louis Bossart
2021-09-14 16:46   ` Chiang, Mac [this message]

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=DM5PR1101MB2091939E461BFA0313FA4B0184DA9@DM5PR1101MB2091.namprd11.prod.outlook.com \
    --to=mac.chiang@intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=bard.liao@intel.com \
    --cc=broonie@kernel.org \
    --cc=jairaj.arava@intel.com \
    --cc=keith.tzeng@quantatw.com \
    --cc=mark_hsieh@wistron.com \
    --cc=pierre-louis.bossart@linux.intel.com \
    --cc=sathyanarayana.nujella@intel.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.