From nobody Mon Feb 9 12:15:38 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F86EEB64DD for ; Wed, 5 Jul 2023 13:44:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231891AbjGENoD (ORCPT ); Wed, 5 Jul 2023 09:44:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231213AbjGENn5 (ORCPT ); Wed, 5 Jul 2023 09:43:57 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4820171B for ; Wed, 5 Jul 2023 06:43:55 -0700 (PDT) Received: from localhost (unknown [188.24.137.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: cristicc) by madras.collabora.co.uk (Postfix) with ESMTPSA id 9BE1B6606FB9; Wed, 5 Jul 2023 14:43:54 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1688564634; bh=RDOqL2QvBsWdGDtjLILdg3uwJMqeZ/zmgqZTS73BrJo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R9+hXXfoQBhv2BkO+lcoUezRvdGuWvPh2dbcGjdiUWAMbQPVeqJwnAqnbekAXIlsR 6yzZVNYDX0U+bebjeEmbrL/imbi57wYBrbKbJoQM9syAQMeqr4sRW9LwiwBk4qMpjw +lgaaq6iKNBnL//EygYNxObX2Z/i+KxPk0R05yP+0ZZCoDw0DLJeZTXmcw2hK56+tW 3xqyG0wUtWFEafTvk5bFZwnypQCz72y+7/CiXEjqw6L4N+QDhXDlPHVDA27kRnC+aw z96Ik8w3KnlzUWAjdQmrz7wRcam7smUIs85hwYlGUghJ5XU5ZmCR6iU0Sj+UWuuQgB Em761I+1rgGyQ== From: Cristian Ciocaltea To: Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , Syed Saba Kareem , Vijendar Mukunda , Arnd Bergmann , Randy Dunlap , Charles Keepax , Kuninori Morimoto Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, kernel@collabora.com Subject: [PATCH v2 3/3] ASoC: amd: vangogh: Add support for NAU8821/MAX98388 variant Date: Wed, 5 Jul 2023 16:43:41 +0300 Message-ID: <20230705134341.175889-4-cristian.ciocaltea@collabora.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230705134341.175889-1-cristian.ciocaltea@collabora.com> References: <20230705134341.175889-1-cristian.ciocaltea@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Extend the Vangogh machine driver to support a variant based on the Nuvoton NAU88L21 Codec and the Analog Devices MAX98388 Speaker Amplifier. Additionally, enable probing via ACPI match table for this and future hardware revisions. Co-developed-by: Lucas Tanure Signed-off-by: Lucas Tanure Signed-off-by: Cristian Ciocaltea --- sound/soc/amd/Kconfig | 5 +- sound/soc/amd/vangogh/acp5x-mach.c | 155 +++++++++++++++++++++++++++-- 2 files changed, 150 insertions(+), 10 deletions(-) diff --git a/sound/soc/amd/Kconfig b/sound/soc/amd/Kconfig index 1dd8579e8034..273688c05317 100644 --- a/sound/soc/amd/Kconfig +++ b/sound/soc/amd/Kconfig @@ -79,14 +79,15 @@ config SND_SOC_AMD_ACP5x ACP DMA driver, CPU DAI driver. =20 config SND_SOC_AMD_VANGOGH_MACH - tristate "AMD Vangogh support for NAU8821 CS35L41" + tristate "AMD Vangogh support for NAU8821/CS35L41/MAX98388" select SND_SOC_NAU8821 select SND_SOC_CS35L41_SPI + select SND_SOC_MAX98388 select SND_AMD_ACP_CONFIG depends on SND_SOC_AMD_ACP5x && I2C && SPI_MASTER help This option enables machine driver for Vangogh platform - using NAU8821 and CS35L41 codecs. + using NAU8821 and either CS35L41 or MAX98388 codecs. Say m if you have such a device. If unsure select "N". =20 diff --git a/sound/soc/amd/vangogh/acp5x-mach.c b/sound/soc/amd/vangogh/acp= 5x-mach.c index 1efa8f8b77ab..42e37f4f1495 100644 --- a/sound/soc/amd/vangogh/acp5x-mach.c +++ b/sound/soc/amd/vangogh/acp5x-mach.c @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0+ /* - * Machine driver for AMD Vangogh platform using NAU8821 & CS35L41 - * codecs. + * Machine driver for AMD Vangogh platform using either + * NAU8821 & CS35L41 or NAU8821 & MAX98388 codecs. * * Copyright 2021 Advanced Micro Devices, Inc. */ @@ -29,6 +29,9 @@ #define ACP5X_CS35L41_COMP_LNAME "spi-VLV1776:00" #define ACP5X_CS35L41_COMP_RNAME "spi-VLV1776:01" #define ACP5X_CS35L41_DAI_NAME "cs35l41-pcm" +#define ACP5X_MAX98388_COMP_LNAME "i2c-ADS8388:00" +#define ACP5X_MAX98388_COMP_RNAME "i2c-ADS8388:01" +#define ACP5X_MAX98388_DAI_NAME "max98388-aif1" =20 static struct snd_soc_jack vg_headset; =20 @@ -326,6 +329,126 @@ static struct snd_soc_card acp5x_8821_35l41_card =3D { .num_controls =3D ARRAY_SIZE(acp5x_8821_controls), }; =20 +static int acp5x_max98388_startup(struct snd_pcm_substream *substream) +{ + struct snd_soc_pcm_runtime *rtd =3D asoc_substream_to_rtd(substream); + struct acp5x_platform_info *machine =3D snd_soc_card_get_drvdata(rtd->car= d); + struct snd_pcm_runtime *runtime =3D substream->runtime; + + machine->play_i2s_instance =3D I2S_HS_INSTANCE; + + runtime->hw.channels_max =3D DUAL_CHANNEL; + snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, + &constraints_channels); + snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, + &constraints_rates); + return 0; +} + +static int acp5x_max98388_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params) +{ + struct snd_soc_pcm_runtime *rtd =3D asoc_substream_to_rtd(substream); + struct snd_soc_dai *dai =3D snd_soc_card_get_codec_dai(rtd->card, + ACP5X_MAX98388_DAI_NAME); + int ret; + + ret =3D snd_soc_dai_set_fmt(dai, + SND_SOC_DAIFMT_CBS_CFS | SND_SOC_DAIFMT_I2S | + SND_SOC_DAIFMT_NB_NF); + if (ret < 0) + dev_err(dai->dev, "Failed to set format: %d\n", ret); + + return ret; +} + +static const struct snd_soc_ops acp5x_max98388_play_ops =3D { + .startup =3D acp5x_max98388_startup, + .hw_params =3D acp5x_max98388_hw_params, +}; + +static struct snd_soc_codec_conf acp5x_max98388_conf[] =3D { + { + .dlc =3D COMP_CODEC_CONF(ACP5X_MAX98388_COMP_LNAME), + .name_prefix =3D "Left", + }, + { + .dlc =3D COMP_CODEC_CONF(ACP5X_MAX98388_COMP_RNAME), + .name_prefix =3D "Right", + }, +}; + +SND_SOC_DAILINK_DEF(max98388, DAILINK_COMP_ARRAY(COMP_CODEC(ACP5X_MAX98388= _COMP_LNAME, + ACP5X_MAX98388_DAI_NAME), + COMP_CODEC(ACP5X_MAX98388_COMP_RNAME, + ACP5X_MAX98388_DAI_NAME))); + +static struct snd_soc_dai_link acp5x_8821_98388_dai[] =3D { + { + .name =3D "acp5x-8821-play", + .stream_name =3D "Playback/Capture", + .dai_fmt =3D SND_SOC_DAIFMT_I2S | + SND_SOC_DAIFMT_NB_NF | + SND_SOC_DAIFMT_CBC_CFC, + .dpcm_playback =3D 1, + .dpcm_capture =3D 1, + .ops =3D &acp5x_8821_ops, + .init =3D acp5x_8821_init, + SND_SOC_DAILINK_REG(acp5x_i2s, nau8821, platform), + }, + { + .name =3D "acp5x-max98388-play", + .stream_name =3D "MAX98388 Playback", + .dai_fmt =3D SND_SOC_DAIFMT_I2S | + SND_SOC_DAIFMT_NB_NF | + SND_SOC_DAIFMT_CBC_CFC, + .dpcm_playback =3D 1, + .playback_only =3D 1, + .ops =3D &acp5x_max98388_play_ops, + SND_SOC_DAILINK_REG(acp5x_bt, max98388, platform), + }, +}; + +static const struct snd_soc_dapm_widget acp5x_8821_98388_widgets[] =3D { + SND_SOC_DAPM_HP("Headphone", NULL), + SND_SOC_DAPM_MIC("Headset Mic", NULL), + SND_SOC_DAPM_MIC("Int Mic", NULL), + SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0, + platform_clock_control, + SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), + SND_SOC_DAPM_SPK("SPK", NULL), +}; + +static const struct snd_soc_dapm_route acp5x_8821_98388_route[] =3D { + { "Headphone", NULL, "HPOL" }, + { "Headphone", NULL, "HPOR" }, + { "MICL", NULL, "Headset Mic" }, + { "MICR", NULL, "Headset Mic" }, + { "DMIC", NULL, "Int Mic" }, + + { "Headphone", NULL, "Platform Clock" }, + { "Headset Mic", NULL, "Platform Clock" }, + { "Int Mic", NULL, "Platform Clock" }, + + { "SPK", NULL, "Left BE_OUT" }, + { "SPK", NULL, "Right BE_OUT" }, +}; + +static struct snd_soc_card acp5x_8821_98388_card =3D { + .name =3D "acp5x-max98388", + .owner =3D THIS_MODULE, + .dai_link =3D acp5x_8821_98388_dai, + .num_links =3D ARRAY_SIZE(acp5x_8821_98388_dai), + .dapm_widgets =3D acp5x_8821_98388_widgets, + .num_dapm_widgets =3D ARRAY_SIZE(acp5x_8821_98388_widgets), + .dapm_routes =3D acp5x_8821_98388_route, + .num_dapm_routes =3D ARRAY_SIZE(acp5x_8821_98388_route), + .codec_conf =3D acp5x_max98388_conf, + .num_configs =3D ARRAY_SIZE(acp5x_max98388_conf), + .controls =3D acp5x_8821_controls, + .num_controls =3D ARRAY_SIZE(acp5x_8821_controls), +}; + static const struct dmi_system_id acp5x_vg_quirk_table[] =3D { { .matches =3D { @@ -344,11 +467,20 @@ static int acp5x_probe(struct platform_device *pdev) struct snd_soc_card *card; int ret; =20 - dmi_id =3D dmi_first_match(acp5x_vg_quirk_table); - if (!dmi_id) - return -ENODEV; - - card =3D &acp5x_8821_35l41_card; + card =3D (struct snd_soc_card *)device_get_match_data(dev); + if (!card) { + /* + * This is normally the result of directly probing the driver + * in pci-acp5x through platform_device_register_full(), which + * is necessary for the CS35L41 variant, as it doesn't support + * ACPI probing and relies on DMI quirks. + */ + dmi_id =3D dmi_first_match(acp5x_vg_quirk_table); + if (!dmi_id) + return -ENODEV; + + card =3D &acp5x_8821_35l41_card; + } =20 machine =3D devm_kzalloc(dev, sizeof(*machine), GFP_KERNEL); if (!machine) @@ -365,10 +497,17 @@ static int acp5x_probe(struct platform_device *pdev) return 0; } =20 +static const struct acpi_device_id acp5x_acpi_match[] =3D { + { "AMDI8821", (kernel_ulong_t)&acp5x_8821_98388_card }, + {}, +}; +MODULE_DEVICE_TABLE(acpi, acp5x_acpi_match); + static struct platform_driver acp5x_mach_driver =3D { .driver =3D { .name =3D DRV_NAME, .pm =3D &snd_soc_pm_ops, + .acpi_match_table =3D acp5x_acpi_match, }, .probe =3D acp5x_probe, }; @@ -376,6 +515,6 @@ static struct platform_driver acp5x_mach_driver =3D { module_platform_driver(acp5x_mach_driver); =20 MODULE_AUTHOR("Vijendar.Mukunda@amd.com"); -MODULE_DESCRIPTION("NAU8821 & CS35L41 audio support"); +MODULE_DESCRIPTION("NAU8821/CS35L41 & NAU8821/MAX98388 audio support"); MODULE_LICENSE("GPL v2"); MODULE_ALIAS("platform:" DRV_NAME); --=20 2.41.0