Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp749315rwb; Wed, 26 Jul 2023 02:07:05 -0700 (PDT) X-Google-Smtp-Source: APBJJlG8cV2tkEehvfpMkqK8/dSstyzdS7QcPrC4nGkSDoLaCUjXc1QFnrO0Xa4YDU/yv2ljsq4R X-Received: by 2002:a05:6358:339c:b0:134:c682:213f with SMTP id i28-20020a056358339c00b00134c682213fmr1360115rwd.31.1690362425215; Wed, 26 Jul 2023 02:07:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690362425; cv=none; d=google.com; s=arc-20160816; b=VgeP2UzjYo2yLK2WcfCvUekpFemf0ouVfsCFuo/gZN/zr1Ps7sy98LLmsj5W9phl60 oxzJhNh7XaPNcGRz7SlKXCmItyqRDCmFYfjwdl1m1qxkAmYMcr+VDrDREBKy/i46vSK7 48PjcABwQNQ12TMR3oSVMKQV80cARpSFiN/M5vw4pw/AxUqidr3+eXeKg4l3H4AlooHg 1FUWvWpZgLvWmKT3sPD//mRLJ1FkyKoQO/6YZm26+yq8/13kRdw8G8e6FK6LpxdA39ku 6NagzysGzSN+/dpp8kBI/CdbcTAXqmvl2S3ZtmtmRtLKtLiSLTiuh6CFaedTjXmAI9Fw +jlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=1nyIydmjbpOmaXCIzFKR868yLx+55vZiI7fXoKK7ItM=; fh=fzIJb4eakNvpwtMw8Sd7xonuWsTPjVPomL2M5RlwkJ0=; b=PrCUukDKegSqHFcnrFuODuZG+8NMb6FwpyQlbq+WMHT5QumNJdYtKpHVrx77ZdxR8Z 43jrDMtReCzyNMeE7FkOE2PUsVP1cB+JSGQ4xzi4IYF5zo5VK2HKKS436toSFd65hT3f b9v+hQ5olOe+xzncppjDjnYEOXHQ0C8biJ0CcmLCGD6lxxE/WoV5kuUqo4bcu2ZyZBKR qbkNjA0yeMYcVjb602rjNRZjK21UmwgiFXqiX9Gb2ndlWgL4x51JlW2ilL2kA0G2Ynek X13bwB+bjCeKviAZjiGQOz5ntWOfWsS6djZ1YybMK90JGzUS7OTIcg4MmUV3yJfl619W dCMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=iYFw1p56; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 7-20020a630007000000b00553836cb761si12663542pga.717.2023.07.26.02.06.50; Wed, 26 Jul 2023 02:07:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=iYFw1p56; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233235AbjGZI0T (ORCPT + 99 others); Wed, 26 Jul 2023 04:26:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233176AbjGZIZx (ORCPT ); Wed, 26 Jul 2023 04:25:53 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3555B4236 for ; Wed, 26 Jul 2023 01:15:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690359332; x=1721895332; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=3PBwGmmLNo5LsDc6Vk46BAUMhYfkHnDVYn22klH3w7w=; b=iYFw1p56w75O9/uMtQHfWkdk4eUsdRxBkyqFOB2p2XKUMjlUmZ+KN9TS PPnq3iJliEsy5DhYi0kbF423T8e3yAoymDg5Zaj1y9Sx91dhNbN7oYepC bivox/TI98jDNFzTju2hh+DUcW7bAsixR4vtvYe1YO+6wXhA8LkdwU3Fx auG8z49ikDxYwUckTGH3Qkdi1+3ddlglWEsujCWSUfUIeM+Is20xUJaBa mXheSzEUQXZinEBN81C3vanLZxXb3xB7oOZ6JQ3twp3uUVfRbzaZ7fVqI Xau0bVgxEHZjT6ZoEktFW8XeNh9kXRL6nFXN/hGG/8mfLshz76KFIivse w==; X-IronPort-AV: E=McAfee;i="6600,9927,10782"; a="431752630" X-IronPort-AV: E=Sophos;i="6.01,231,1684825200"; d="scan'208";a="431752630" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jul 2023 01:15:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10782"; a="840179540" X-IronPort-AV: E=Sophos;i="6.01,231,1684825200"; d="scan'208";a="840179540" Received: from csmokx-mobl.ger.corp.intel.com (HELO [10.252.35.206]) ([10.252.35.206]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jul 2023 01:15:21 -0700 Message-ID: <7349d6f4-4866-6fb3-57c9-9ce2d6989576@linux.intel.com> Date: Wed, 26 Jul 2023 10:15:02 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH v2 1/2] ASoC: Intel: maxim-common: get codec number from ACPI Content-Language: en-US To: Brent Lu , alsa-devel@alsa-project.org Cc: Cezary Rojewski , Liam Girdwood , Peter Ujfalusi , Bard Liao , Ranjani Sridharan , Kai Vehmanen , Mark Brown , Jaroslav Kysela , Takashi Iwai , linux-kernel@vger.kernel.org, Ajye Huang , Yong Zhi , Terry Cheong , Uday M Bhat , Mac Chiang , "Dharageswari . R" , Kuninori Morimoto , ye xingchen , Andy Shevchenko References: <20230726140848.2267568-1-brent.lu@intel.com> <20230726140848.2267568-2-brent.lu@intel.com> From: Pierre-Louis Bossart In-Reply-To: <20230726140848.2267568-2-brent.lu@intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/26/23 4:08 PM, Brent Lu wrote: > Implement a helper function to get number of codecs from ACPI > subsystem to remove the need of quirk flag in machine driver. > > Signed-off-by: Brent Lu > --- > sound/soc/intel/boards/sof_maxim_common.c | 171 +++++++++++++--------- > sound/soc/intel/boards/sof_maxim_common.h | 21 ++- > 2 files changed, 110 insertions(+), 82 deletions(-) > > diff --git a/sound/soc/intel/boards/sof_maxim_common.c b/sound/soc/intel/boards/sof_maxim_common.c > index 112e89951da0..1fdd66f5adc2 100644 > --- a/sound/soc/intel/boards/sof_maxim_common.c > +++ b/sound/soc/intel/boards/sof_maxim_common.c > @@ -4,6 +4,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -11,6 +12,18 @@ > #include > #include "sof_maxim_common.h" > > +/* helper function to get the number of specific codec */ > +static unsigned int get_num_codecs(const char *hid) > +{ > + struct acpi_device *adev; > + unsigned int dev_num = 0; > + > + for_each_acpi_dev_match(adev, hid, NULL, -1) > + dev_num++; > + > + return dev_num; > +} > + > #define MAX_98373_PIN_NAME 16 > > const struct snd_soc_dapm_route max_98373_dapm_routes[] = { > @@ -168,17 +181,6 @@ static struct snd_soc_codec_conf max_98390_codec_conf[] = { > .dlc = COMP_CODEC_CONF(MAX_98390_DEV1_NAME), > .name_prefix = "Left", > }, > -}; > - > -static struct snd_soc_codec_conf max_98390_4spk_codec_conf[] = { > - { > - .dlc = COMP_CODEC_CONF(MAX_98390_DEV0_NAME), > - .name_prefix = "Right", > - }, > - { > - .dlc = COMP_CODEC_CONF(MAX_98390_DEV1_NAME), > - .name_prefix = "Left", > - }, if you remove the codec conf, doesn't this impact the Kcontrols names? Does this break existing UCM files? It's rather hard to review with just the diff. > { > .dlc = COMP_CODEC_CONF(MAX_98390_DEV2_NAME), > .name_prefix = "Tweeter Right", > @@ -189,19 +191,7 @@ static struct snd_soc_codec_conf max_98390_4spk_codec_conf[] = { > }, > }; > > -struct snd_soc_dai_link_component max_98390_components[] = { > - { > - .name = MAX_98390_DEV0_NAME, > - .dai_name = MAX_98390_CODEC_DAI, > - }, > - { > - .name = MAX_98390_DEV1_NAME, > - .dai_name = MAX_98390_CODEC_DAI, > - }, > -}; > -EXPORT_SYMBOL_NS(max_98390_components, SND_SOC_INTEL_SOF_MAXIM_COMMON); > - > -struct snd_soc_dai_link_component max_98390_4spk_components[] = { > +static struct snd_soc_dai_link_component max_98390_components[] = { > { > .name = MAX_98390_DEV0_NAME, > .dai_name = MAX_98390_CODEC_DAI, > @@ -219,62 +209,56 @@ struct snd_soc_dai_link_component max_98390_4spk_components[] = { > .dai_name = MAX_98390_CODEC_DAI, > }, > }; > -EXPORT_SYMBOL_NS(max_98390_4spk_components, SND_SOC_INTEL_SOF_MAXIM_COMMON); > + > +static const struct { > + unsigned int tx; > + unsigned int rx; > +} max_98390_tdm_mask[] = { > + {.tx = 0x01, .rx = 0x3}, > + {.tx = 0x02, .rx = 0x3}, > + {.tx = 0x04, .rx = 0x3}, > + {.tx = 0x08, .rx = 0x3}, > +}; > > static int max_98390_hw_params(struct snd_pcm_substream *substream, > struct snd_pcm_hw_params *params) > { > struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); > struct snd_soc_dai *codec_dai; > - int i; > + int i, ret = 0; > > for_each_rtd_codec_dais(rtd, i, codec_dai) { > - if (i >= ARRAY_SIZE(max_98390_4spk_components)) { > + if (i >= ARRAY_SIZE(max_98390_tdm_mask)) { > dev_err(codec_dai->dev, "invalid codec index %d\n", i); > return -ENODEV; > } > > - if (!strcmp(codec_dai->component->name, MAX_98390_DEV0_NAME)) { > - /* DEV0 tdm slot configuration Right */ > - snd_soc_dai_set_tdm_slot(codec_dai, 0x01, 3, 4, 32); > - } > - if (!strcmp(codec_dai->component->name, MAX_98390_DEV1_NAME)) { > - /* DEV1 tdm slot configuration Left */ > - snd_soc_dai_set_tdm_slot(codec_dai, 0x02, 3, 4, 32); > - } > - > - if (!strcmp(codec_dai->component->name, MAX_98390_DEV2_NAME)) { > - /* DEVi2 tdm slot configuration Tweeter Right */ > - snd_soc_dai_set_tdm_slot(codec_dai, 0x04, 3, 4, 32); > - } > - if (!strcmp(codec_dai->component->name, MAX_98390_DEV3_NAME)) { > - /* DEV3 tdm slot configuration Tweeter Left */ > - snd_soc_dai_set_tdm_slot(codec_dai, 0x08, 3, 4, 32); > + ret = snd_soc_dai_set_tdm_slot(codec_dai, max_98390_tdm_mask[i].tx, > + max_98390_tdm_mask[i].rx, 4, > + params_width(params)); > + if (ret < 0) { > + dev_err(codec_dai->dev, "fail to set tdm slot, ret %d\n", > + ret); > + return ret; > } > } > return 0; > } > > -int max_98390_spk_codec_init(struct snd_soc_pcm_runtime *rtd) > +static int max_98390_init(struct snd_soc_pcm_runtime *rtd) > { > struct snd_soc_card *card = rtd->card; > + unsigned int num_codecs = get_num_codecs(MAX_98390_ACPI_HID); > int ret; > > - /* add regular speakers dapm route */ > - ret = snd_soc_dapm_add_routes(&card->dapm, max_98390_dapm_routes, > - ARRAY_SIZE(max_98390_dapm_routes)); > - if (ret) { > - dev_err(rtd->dev, "unable to add Left/Right Speaker dapm, ret %d\n", ret); > - return ret; > - } > - > - /* add widgets/controls/dapm for tweeter speakers */ > - if (acpi_dev_present("MX98390", "3", -1)) { > + switch (num_codecs) { > + case 4: > + /* add widgets/controls/dapm for tweeter speakers */ > 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 tweeter dapm controls, ret %d\n", ret); > + dev_err(rtd->dev, "unable to add tweeter dapm widgets, ret %d\n", > + ret); > /* Don't need to add routes if widget addition failed */ > return ret; > } > @@ -282,33 +266,80 @@ int max_98390_spk_codec_init(struct snd_soc_pcm_runtime *rtd) > 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 tweeter card controls, ret %d\n", ret); > + dev_err(rtd->dev, "unable to add tweeter 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, > - "unable to add Tweeter Left/Right Speaker dapm, ret %d\n", ret); > + if (ret) { > + dev_err(rtd->dev, "unable to add tweeter dapm routes, ret %d\n", > + ret); > + return ret; > + } > + > + fallthrough; > + case 2: > + /* add regular speakers dapm route */ > + ret = snd_soc_dapm_add_routes(&card->dapm, max_98390_dapm_routes, > + ARRAY_SIZE(max_98390_dapm_routes)); > + if (ret) { > + dev_err(rtd->dev, "unable to add dapm routes, ret %d\n", > + ret); > + return ret; > + } > + break; > + default: > + dev_err(rtd->dev, "invalid codec number %d\n", num_codecs); > + ret = -EINVAL; > + break; > } > + > return ret; > } > -EXPORT_SYMBOL_NS(max_98390_spk_codec_init, SND_SOC_INTEL_SOF_MAXIM_COMMON); > > -const struct snd_soc_ops max_98390_ops = { > +static const struct snd_soc_ops max_98390_ops = { > .hw_params = max_98390_hw_params, > }; > -EXPORT_SYMBOL_NS(max_98390_ops, SND_SOC_INTEL_SOF_MAXIM_COMMON); > > -void max_98390_set_codec_conf(struct snd_soc_card *card, int ch) > +void max_98390_dai_link(struct snd_soc_dai_link *link) > +{ > + unsigned int num_codecs = get_num_codecs(MAX_98390_ACPI_HID); > + > + link->codecs = max_98390_components; > + > + switch (num_codecs) { > + case 2: > + case 4: > + link->num_codecs = num_codecs; > + break; > + default: > + pr_err("invalid codec number %d for %s\n", num_codecs, > + MAX_98390_ACPI_HID); > + break; > + } > + > + link->init = max_98390_init; > + link->ops = &max_98390_ops; > +} > +EXPORT_SYMBOL_NS(max_98390_dai_link, SND_SOC_INTEL_SOF_MAXIM_COMMON); > + > +void max_98390_set_codec_conf(struct snd_soc_card *card) > { > - if (ch == ARRAY_SIZE(max_98390_4spk_codec_conf)) { > - card->codec_conf = max_98390_4spk_codec_conf; > - card->num_configs = ARRAY_SIZE(max_98390_4spk_codec_conf); > - } else { > - card->codec_conf = max_98390_codec_conf; > - card->num_configs = ARRAY_SIZE(max_98390_codec_conf); > + unsigned int num_codecs = get_num_codecs(MAX_98390_ACPI_HID); > + > + card->codec_conf = max_98390_codec_conf; > + > + switch (num_codecs) { > + case 2: > + case 4: > + card->num_configs = num_codecs; > + break; > + default: > + pr_err("invalid codec number %d for %s\n", num_codecs, > + MAX_98390_ACPI_HID); > + break; > } > } > EXPORT_SYMBOL_NS(max_98390_set_codec_conf, SND_SOC_INTEL_SOF_MAXIM_COMMON); > diff --git a/sound/soc/intel/boards/sof_maxim_common.h b/sound/soc/intel/boards/sof_maxim_common.h > index 7a8c53049e4d..a3676d68cc12 100644 > --- a/sound/soc/intel/boards/sof_maxim_common.h > +++ b/sound/soc/intel/boards/sof_maxim_common.h > @@ -27,18 +27,15 @@ int max_98373_trigger(struct snd_pcm_substream *substream, int cmd); > /* > * Maxim MAX98390 > */ > -#define MAX_98390_CODEC_DAI "max98390-aif1" > -#define MAX_98390_DEV0_NAME "i2c-MX98390:00" > -#define MAX_98390_DEV1_NAME "i2c-MX98390:01" > -#define MAX_98390_DEV2_NAME "i2c-MX98390:02" > -#define MAX_98390_DEV3_NAME "i2c-MX98390:03" > - > -extern struct snd_soc_dai_link_component max_98390_components[2]; > -extern struct snd_soc_dai_link_component max_98390_4spk_components[4]; > -extern const struct snd_soc_ops max_98390_ops; > - > -void max_98390_set_codec_conf(struct snd_soc_card *card, int ch); > -int max_98390_spk_codec_init(struct snd_soc_pcm_runtime *rtd); > +#define MAX_98390_ACPI_HID "MX98390" > +#define MAX_98390_CODEC_DAI "max98390-aif1" > +#define MAX_98390_DEV0_NAME "i2c-MX98390:00" > +#define MAX_98390_DEV1_NAME "i2c-MX98390:01" > +#define MAX_98390_DEV2_NAME "i2c-MX98390:02" > +#define MAX_98390_DEV3_NAME "i2c-MX98390:03" > + > +void max_98390_dai_link(struct snd_soc_dai_link *link); > +void max_98390_set_codec_conf(struct snd_soc_card *card); > > /* > * Maxim MAX98357A/MAX98360A