From patchwork Fri Feb 16 07:41:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akshu Agrawal X-Patchwork-Id: 10224141 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0741F602CB for ; Fri, 16 Feb 2018 07:54:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC74029350 for ; Fri, 16 Feb 2018 07:54:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DF5A829360; Fri, 16 Feb 2018 07:54:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, RCVD_IN_DNSWL_NONE, T_DKIM_INVALID autolearn=no version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C21BE29350 for ; Fri, 16 Feb 2018 07:54:54 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 36D90267D92; Fri, 16 Feb 2018 08:54:47 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id BC21C267D87; Fri, 16 Feb 2018 08:54:45 +0100 (CET) Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on0059.outbound.protection.outlook.com [104.47.40.59]) by alsa0.perex.cz (Postfix) with ESMTP id 4C1DC267D5E for ; Fri, 16 Feb 2018 08:54:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=ovuZTUBWFUI/Ypd5sSvyW5MuU5cTkZ4QIofUuPIzniY=; b=rTyvSton5bFXOlsT1G29r/knSZkcoVRYXh1B9xLl68pjFTNULPXV+KVpOO6T/PiNT16NbjARAxHWjqrlx5PS6AJ2HM1BwDmLo54vJfSy0agZeLrTjUOGybwekHPAI81CBTRL2WKnOtiMjePcJap42J0deh96XEPOpgmFbM4S+9A= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Akshu.Agrawal@amd.com; Received: from akshu-HP-EliteBook-745-G2.amd.com (202.56.249.162) by BN6PR1201MB0179.namprd12.prod.outlook.com (10.174.115.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.506.18; Fri, 16 Feb 2018 07:54:36 +0000 From: Akshu Agrawal To: broonie@kernel.org, alsa-devel@alsa-project.org Date: Fri, 16 Feb 2018 13:11:13 +0530 Message-Id: <1518766875-15164-2-git-send-email-akshu.agrawal@amd.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1518766875-15164-1-git-send-email-akshu.agrawal@amd.com> References: <1518766875-15164-1-git-send-email-akshu.agrawal@amd.com> MIME-Version: 1.0 X-Originating-IP: [202.56.249.162] X-ClientProxiedBy: MAXPR0101CA0053.INDPRD01.PROD.OUTLOOK.COM (10.174.63.15) To BN6PR1201MB0179.namprd12.prod.outlook.com (10.174.115.11) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: b6a108b0-a799-466e-c110-08d575128765 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060)(7193020); SRVR:BN6PR1201MB0179; X-Microsoft-Exchange-Diagnostics: 1; BN6PR1201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U+ZZxBg4/RKAejVtbtL0sQoizJmhrEF4TZNoTzQ9wdxBYn2gucJuhWReWx7ywqzw0x2RH/+pNVdVLjOHPiTPjSIb4UE8TYMcWTBcMQQJeILKiz5iTvTj4ViKIkVnWYEPbV/goMjmHUfJ3g8VRt1RPdfdtCuw6ZxQqb4XMXByjON3DtkIGxWrk8UoHVrLKY6eiAaKjALJHCwWcw7cc2MxfJCzhesCpIrMMhmc2t3diHh1FRLBBAKIaXhEyiBeJKLQ3V4KD2UsHVpm9azl26nckEy5cMBD+69bo8VREcY6objfI4a4vxXHLKc8Ly4+CWqbRIbp8oOL9lTn8keB2CjRebvRwpG/5i3NmDlU+x/ggnvBL3kUB; 4:xqV2q5rwKUE3YHPgbU6Tq04IxnMI6clFzCKM7cQQIgvpnO9uBw07BrHlq1xcQ88EdzDj2P3LKEvZ3A1Mz08TXGb14MYjbUi7gomnIGpQhqy6AxzQ6793uddW2KdsMo9g5cFxOpbVEmuymbxWL7VXm26hYTXTfiW5v3g8ffgGsAhwoA96azO+QSJZ/l3jXPBOcdqgkdwbFbwbZzmDQ9agN3scP/W+jk2DtH5FJSUeAFVI1rDCwsJxoN2iPQf+k8EmQFlChPrDX5GPf4nR6Y8AYMy6vZ+jO2ekJwwQz4q7XfSbbXHEQp9a38nMY8k/ug2B X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040501)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(3231101)(944501161)(3002001)(6055026)(6041288)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(20161123562045)(20161123558120)(6072148)(201708071742011); SRVR:BN6PR1201MB0179; BCL:0; PCL:0; RULEID:; SRVR:BN6PR1201MB0179; X-Forefront-PRVS: 0585417D7B X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(39860400002)(346002)(39380400002)(376002)(366004)(396003)(189003)(199004)(8676002)(6486002)(51416003)(81156014)(81166006)(105586002)(4326008)(2906002)(59450400001)(16586007)(316002)(386003)(478600001)(50226002)(76176011)(53416004)(7696005)(8936002)(52116002)(72206003)(66066001)(47776003)(53936002)(26005)(6116002)(3846002)(6666003)(2950100002)(16526019)(1857600001)(186003)(36756003)(86362001)(5660300001)(25786009)(39060400002)(7736002)(305945005)(50466002)(48376002)(97736004)(106356001)(68736007); DIR:OUT; SFP:1101; SCL:1; SRVR:BN6PR1201MB0179; H:akshu-HP-EliteBook-745-G2.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN6PR1201MB0179; 23:yrlPW5FoWHcehekv5DtMbvQbqKB6BAGanjaiE6A?= =?us-ascii?Q?1TFU0VPg3GMrvMivt0r7n+etAvIi4ddYuI/11f7/teywDnvzdRHJ84aq07dz?= =?us-ascii?Q?/Sen9aZu+GVWK2LS0zxIPOlEpDC31s8rgvCbGCPAmkoUi4CE4Stg043Xefmz?= =?us-ascii?Q?g1XqQ+18SnikgmYqR/gFmIOlxdBjB5Ew0gYeTZ8LG6kVPtYe7WtmS4MO0d4x?= =?us-ascii?Q?II11qbohGWwLHgZ3BAliI0DzPmoHuTfYf8BcgdHxgIXwMZoPLFq0bsr7Ie0I?= =?us-ascii?Q?MFJYlYJpF8ubV7YB/g7D91Ua6PZ64eLcI8tOh4e8/qOMLIRKeI0WGPY1VBeu?= =?us-ascii?Q?OWkuCrFFf/sbhtoauV3xElb39PC4N6QdRzkaRnSdZZJb4EXxwM/hEkVse30c?= =?us-ascii?Q?lLPB2Z32h6IpKVRRrsILq00FrIRiBs+PoXjW81/Da3wbP0E4l6b0qLg3ZhVT?= =?us-ascii?Q?RP1y0LG/Y32NTUMkPsoew14BzaE7k+k+jkckcjQCVLhoGdFKLPsUxp3CdTTw?= =?us-ascii?Q?2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m1ZWCy0xeNDzmrHStd4XVzG5ZgJ7n28JjUhYKnqksW5F9ZT7r7KBhXO1eUFl34Ns2oUlfvYzJkZooA+gi3GvWSRVGye9sCNHXRD4PAoq7MuN6tdQHEtFmPbyD2HFhpao+OLm6VzwdwZXPxDrTptMJDXpB1s=; 5:3YNejAFx62Tz5/QUrA0xvnAP0FcNyYghdJq01PQB0PiiS2MEbrI75tK34e1DbtjZnoOD5rYavOEmz6jrov5S2ktA2+ashSr/arWHHb18ChRA3Uqu4iaENmZvYRg1hnJ9hnl+MK0OBKRCuI35EbO6PrDHPJp1MNeRaWMv6c4eqcc=; 24:hizmEslkr1D8GRQgY0k/+mJW10W5Mn1fL7vC9hOYYmTT5AY589J/ar4qTYlc5lrmdN6Iy9Ws0omdLNXxM8BvkaEMBSZ821FueKxVIbH+FJw=; 7:v1fPgZ3c2UdsHAaNwhmHLACiTmYxCX0w/VPuygkNLrJuRfirnY02yTD/AyybJZd3VemcmVtjhobwpJh5yWyJLEN4zs/e6eq5tD8omr/TK4CXOBYkgO1BA0Yua/D5H/qL19WIOrzH6hmZb95+RXfRrJ4VleOBQetMQMSzN79KHU9n2j1t0pu5lcobj3q8cM2/pGK4jkZTNqyE9VP0t883WhtMGGtR6corfMGFbsOg+Ovjrrynv61tKC5rJB9N9KAZ SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BN6PR1201MB0179; 20:UaMKtjThMd9TuaMbrYb1hqOkK9kaVmb/y4ZguefqDy/bQc+16AsOBp3BpV+WmnunXK/AkQMttSptUkwAz/5fSq4kI2xmmryB3I9HoWyAWut9EuVLT51sqD5/5Y4r47y8zCHw/+LrADcZnL6J5Ms4wUR8OOl268wEhWwkIoU2TPnYh1bVnaEJOnIfIg0A+kIt+J74zin5soaLBFSxPgwWIQ4b//PhR5kf+g6Urs26SH1xmOZh34YmErdrjCvT04Sy X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Feb 2018 07:54:36.3778 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b6a108b0-a799-466e-c110-08d575128765 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR1201MB0179 Cc: tiwai@suse.de, lgirdwood@gmail.com, Daniel Kurtz , akshu.agrawal@amd.com Subject: [alsa-devel] [PATCH] ASoC: AMD: Add machine driver for ST DA7219 MAX98357 X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP The driver is used for AMD board using DA7219 and MAX98357 codec. TEST=Build, apply grunt_mixer_settings: iotools mmio_write32 0xfed80e40 0x040c40c0 iotools mmio_write32 0xfed80e28 0x10000 iotools mmio_write8 0xfed816de 0xc0 aplay -D plughw:0,0 ./sample_48000.wav -vv aplay -D plughw:0,0 ./sample_44100.wav -vv Signed-off-by: Akshu Agrawal Signed-off-by: Daniel Kurtz Reviewed-by: Alex Deucher --- sound/soc/amd/Kconfig | 9 ++ sound/soc/amd/Makefile | 2 + sound/soc/amd/acp-da7219-max98357a.c | 246 +++++++++++++++++++++++++++++++++++ 3 files changed, 257 insertions(+) create mode 100644 sound/soc/amd/acp-da7219-max98357a.c diff --git a/sound/soc/amd/Kconfig b/sound/soc/amd/Kconfig index d583840..6cbf9cf 100644 --- a/sound/soc/amd/Kconfig +++ b/sound/soc/amd/Kconfig @@ -3,6 +3,15 @@ config SND_SOC_AMD_ACP help This option enables ACP DMA support on AMD platform. +config SND_SOC_AMD_CZ_DA7219MX98357_MACH + tristate "AMD CZ support for DA7219 and MAX9835" + select SND_SOC_DA7219 + select SND_SOC_MAX98357A + select SND_SOC_ADAU7002 + depends on SND_SOC_AMD_ACP && I2C + help + This option enables machine driver for DA7219 and MAX9835. + config SND_SOC_AMD_CZ_RT5645_MACH tristate "AMD CZ support for RT5645" select SND_SOC_RT5645 diff --git a/sound/soc/amd/Makefile b/sound/soc/amd/Makefile index f07fd2e..79b0622 100644 --- a/sound/soc/amd/Makefile +++ b/sound/soc/amd/Makefile @@ -1,5 +1,7 @@ acp_audio_dma-objs := acp-pcm-dma.o +snd-soc-acp-da7219mx98357-mach-objs := acp-da7219-max98357a.o snd-soc-acp-rt5645-mach-objs := acp-rt5645.o obj-$(CONFIG_SND_SOC_AMD_ACP) += acp_audio_dma.o +obj-$(CONFIG_SND_SOC_AMD_CZ_DA7219MX98357_MACH) += snd-soc-acp-da7219mx98357-mach.o obj-$(CONFIG_SND_SOC_AMD_CZ_RT5645_MACH) += snd-soc-acp-rt5645-mach.o diff --git a/sound/soc/amd/acp-da7219-max98357a.c b/sound/soc/amd/acp-da7219-max98357a.c new file mode 100644 index 0000000..e51a878 --- /dev/null +++ b/sound/soc/amd/acp-da7219-max98357a.c @@ -0,0 +1,246 @@ +/* + * Machine driver for AMD ACP Audio engine using DA7219 & MAX98357 codec + * + * Copyright 2017 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../codecs/da7219.h" +#include "../codecs/da7219-aad.h" + +#define CZ_PLAT_CLK 24000000 +#define MCLK_RATE 24576000 +#define DUAL_CHANNEL 2 + +static struct snd_soc_jack cz_jack; + +static int cz_da7219_init(struct snd_soc_pcm_runtime *rtd) +{ + int ret; + struct snd_soc_card *card = rtd->card; + struct snd_soc_codec *codec = rtd->codec; + struct snd_soc_dai *codec_dai = rtd->codec_dai; + + dev_info(rtd->dev, "codec dai name = %s\n", codec_dai->name); + + ret = snd_soc_dai_set_sysclk(codec_dai, DA7219_CLKSRC_MCLK, + CZ_PLAT_CLK, SND_SOC_CLOCK_IN); + if (ret < 0) { + dev_err(rtd->dev, "can't set codec sysclk: %d\n", ret); + return ret; + } + + ret = snd_soc_dai_set_pll(codec_dai, 0, DA7219_SYSCLK_PLL, + CZ_PLAT_CLK, MCLK_RATE); + if (ret < 0) { + dev_err(rtd->dev, "can't set codec pll: %d\n", ret); + return ret; + } + + ret = snd_soc_card_jack_new(card, "Headset Jack", + SND_JACK_HEADPHONE | SND_JACK_MICROPHONE | + SND_JACK_BTN_0 | SND_JACK_BTN_1 | + SND_JACK_BTN_2 | SND_JACK_BTN_3, + &cz_jack, NULL, 0); + if (ret) { + dev_err(card->dev, "HP jack creation failed %d\n", ret); + return ret; + } + + da7219_aad_jack_det(codec, &cz_jack); + + return 0; +} + +static const unsigned int channels[] = { + DUAL_CHANNEL, +}; + +static const unsigned int rates[] = { + 48000, +}; + +static const struct snd_pcm_hw_constraint_list constraints_rates = { + .count = ARRAY_SIZE(rates), + .list = rates, + .mask = 0, +}; + +static const struct snd_pcm_hw_constraint_list constraints_channels = { + .count = ARRAY_SIZE(channels), + .list = channels, + .mask = 0, +}; + +static int cz_fe_startup(struct snd_pcm_substream *substream) +{ + struct snd_pcm_runtime *runtime = substream->runtime; + + /* + * On this platform for PCM device we support stereo + */ + + runtime->hw.channels_max = 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 struct snd_soc_ops cz_da7219_cap_ops = { + .startup = cz_fe_startup, +}; + +static struct snd_soc_dai_link cz_dai_7219_98357[] = { + { + .name = "amd-da7219-play", + .stream_name = "Playback", + .platform_name = "acp_audio_dma.0.auto", + .cpu_dai_name = "designware-i2s.3.auto", + .codec_dai_name = "da7219-hifi", + .codec_name = "i2c-DLGS7219:00", + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF + | SND_SOC_DAIFMT_CBM_CFM, + .init = cz_da7219_init, + .dpcm_playback = 1, + }, + { + .name = "amd-da7219-cap", + .stream_name = "Capture", + .platform_name = "acp_audio_dma.0.auto", + .cpu_dai_name = "designware-i2s.4.auto", + .codec_dai_name = "da7219-hifi", + .codec_name = "i2c-DLGS7219:00", + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF + | SND_SOC_DAIFMT_CBM_CFM, + .dpcm_capture = 1, + .ops = &cz_da7219_cap_ops, + }, + { + .name = "amd-max98357-play", + .stream_name = "HiFi Playback", + .platform_name = "acp_audio_dma.0.auto", + .cpu_dai_name = "designware-i2s.1.auto", + .codec_dai_name = "HiFi", + .codec_name = "MX98357A:00", + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF + | SND_SOC_DAIFMT_CBM_CFM, + .dpcm_playback = 1, + }, + { + .name = "dmic", + .stream_name = "DMIC Capture", + .platform_name = "acp_audio_dma.0.auto", + .cpu_dai_name = "designware-i2s.2.auto", + .codec_dai_name = "adau7002-hifi", + .codec_name = "ADAU7002:00", + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF + | SND_SOC_DAIFMT_CBM_CFM, + .dpcm_capture = 1, + }, +}; + +static const struct snd_soc_dapm_widget cz_widgets[] = { + SND_SOC_DAPM_HP("Headphones", NULL), + SND_SOC_DAPM_SPK("Speakers", NULL), + SND_SOC_DAPM_MIC("Headset Mic", NULL), + SND_SOC_DAPM_MIC("Int Mic", NULL), +}; + +static const struct snd_soc_dapm_route cz_audio_route[] = { + {"Headphones", NULL, "HPL"}, + {"Headphones", NULL, "HPR"}, + {"MIC", NULL, "Headset Mic"}, + {"Speakers", NULL, "Speaker"}, + {"PDM_DAT", NULL, "Int Mic"}, +}; + +static const struct snd_kcontrol_new cz_mc_controls[] = { + SOC_DAPM_PIN_SWITCH("Headphones"), + SOC_DAPM_PIN_SWITCH("Speakers"), + SOC_DAPM_PIN_SWITCH("Headset Mic"), + SOC_DAPM_PIN_SWITCH("Int Mic"), +}; + +static struct snd_soc_card cz_card = { + .name = "acpd7219m98357", + .owner = THIS_MODULE, + .dai_link = cz_dai_7219_98357, + .num_links = ARRAY_SIZE(cz_dai_7219_98357), + .dapm_widgets = cz_widgets, + .num_dapm_widgets = ARRAY_SIZE(cz_widgets), + .dapm_routes = cz_audio_route, + .num_dapm_routes = ARRAY_SIZE(cz_audio_route), + .controls = cz_mc_controls, + .num_controls = ARRAY_SIZE(cz_mc_controls), +}; + +static int cz_probe(struct platform_device *pdev) +{ + int ret; + struct snd_soc_card *card; + + card = &cz_card; + cz_card.dev = &pdev->dev; + platform_set_drvdata(pdev, card); + ret = devm_snd_soc_register_card(&pdev->dev, &cz_card); + if (ret) { + dev_err(&pdev->dev, + "devm_snd_soc_register_card(%s) failed: %d\n", + cz_card.name, ret); + return ret; + } + return 0; +} + +static const struct acpi_device_id cz_audio_acpi_match[] = { + { "AMD7219", 0 }, + {}, +}; +MODULE_DEVICE_TABLE(acpi, cz_audio_acpi_match); + +static struct platform_driver cz_pcm_driver = { + .driver = { + .name = "cz-da7219-max98357a", + .acpi_match_table = ACPI_PTR(cz_audio_acpi_match), + .pm = &snd_soc_pm_ops, + }, + .probe = cz_probe, +}; + +module_platform_driver(cz_pcm_driver); + +MODULE_AUTHOR("akshu.agrawal@amd.com"); +MODULE_DESCRIPTION("DA7219 & MAX98357A audio support"); +MODULE_LICENSE("GPL v2");