From mboxrd@z Thu Jan 1 00:00:00 1970 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 31D84C433F5 for ; Fri, 18 Feb 2022 14:55:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234152AbiBROz0 (ORCPT ); Fri, 18 Feb 2022 09:55:26 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:48238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235152AbiBROzM (ORCPT ); Fri, 18 Feb 2022 09:55:12 -0500 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C1FF5717D; Fri, 18 Feb 2022 06:54:52 -0800 (PST) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: kholk11) with ESMTPSA id 270C21F46B85 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1645196091; bh=al6Ev0bQKorkckF2iTM/jxCkPr35vPyHBaRFp9zx2wg=; h=Date:From:Subject:To:Cc:References:In-Reply-To:From; b=JABE/NDHqXiChVUIOUwgcgWWfmBkoDCrMTVFDcPnx9onUsr3vWZrMkHoDK5JDfpdt ER/sFomFfCRzO90HeEf5YnqMlJM1n/vHzmwtIIyRiTHbWZfpQQE7ZqovIyDZtEGzr2 vHe92RxN4JsKH84jdlq/5xKgFMrd4vKRM9rUNPrvJBTza7Mb271Dt1ENj74fjx1t9X T1ELDH9lHFXVoNCCtplqAAdU0QbJZmFpu+TaJ/mHrexNfE7krhUflPcX4QQxVFrV+J eR1xgPqFSDotoGGON0gUG5ACKIYT04Q4qgVFnHTBfxP9BXkXWPOw7fHuurEDGSgcQ+ cD6mdVX2hKyqg== Message-ID: <70147e6f-a008-ab1a-eb07-dbb1236849b0@collabora.com> Date: Fri, 18 Feb 2022 15:54:47 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.1 From: AngeloGioacchino Del Regno Subject: Re: [v2 14/17] ASoC: mediatek: mt8186: add machine driver with mt6366, da7219 and max98357 To: Jiaxin Yu , broonie@kernel.org Cc: lgirdwood@gmail.com, tiwai@suse.com, robh+dt@kernel.org, matthias.bgg@gmail.com, perex@perex.cz, p.zabel@pengutronix.de, geert+renesas@glider.be, trevor.wu@mediatek.com, tzungbi@google.com, aaronyu@google.com, zhangqilong3@huawei.com, alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org References: <20220217134205.15400-1-jiaxin.yu@mediatek.com> <20220217134205.15400-15-jiaxin.yu@mediatek.com> Content-Language: en-US In-Reply-To: <20220217134205.15400-15-jiaxin.yu@mediatek.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Il 17/02/22 14:42, Jiaxin Yu ha scritto: > This patch adds support for mt8186 board with mt6366, da7219 and max98357. > > Signed-off-by: Jiaxin Yu > --- > .../mt8186/mt8186-mt6366-da7219-max98357.c | 910 ++++++++++++++++++ > 1 file changed, 910 insertions(+) > create mode 100644 sound/soc/mediatek/mt8186/mt8186-mt6366-da7219-max98357.c > > diff --git a/sound/soc/mediatek/mt8186/mt8186-mt6366-da7219-max98357.c b/sound/soc/mediatek/mt8186/mt8186-mt6366-da7219-max98357.c > new file mode 100644 > index 000000000000..6ba53b8d1e46 > --- /dev/null > +++ b/sound/soc/mediatek/mt8186/mt8186-mt6366-da7219-max98357.c > @@ -0,0 +1,910 @@ > +// SPDX-License-Identifier: GPL-2.0 > +// > +// mt8186-mt6366-da7219-max98357.c > +// -- MT8186-MT6366-DA7219-MAX98357 ALSA SoC machine driver > +// > +// Copyright (c) 2022 MediaTek Inc. > +// Author: Jiaxin Yu > +// > + > +#include > +#include > +#include > +#include > +#include > + > +#include "../../codecs/da7219-aad.h" > +#include "../../codecs/da7219.h" > +#include "../../codecs/mt6358.h" > +#include "../common/mtk-afe-platform-driver.h" > +#include "mt8186-afe-common.h" > +#include "mt8186-afe-clk.h" > +#include "mt8186-afe-gpio.h" > + > +#define DA7219_CODEC_DAI "da7219-hifi" > +#define DA7219_DEV_NAME "da7219.5-001a" > + > +struct mt8186_mt6366_da7219_max98357_priv { > + struct snd_soc_jack headset_jack, hdmi_jack; > +}; > + > +static struct snd_soc_codec_conf mt6366_codec_conf[] = { > + { > + .dlc = COMP_CODEC_CONF("mt6358-sound"), > + .name_prefix = "Mt6366", > + }, > +}; > + > +static int mt8186_da7219_init(struct snd_soc_pcm_runtime *rtd) > +{ > + struct mt8186_mt6366_da7219_max98357_priv *priv = > + snd_soc_card_get_drvdata(rtd->card); > + struct snd_soc_jack *jack = &priv->headset_jack; > + struct snd_soc_component *cmpnt_codec = > + asoc_rtd_to_codec(rtd, 0)->component; > + int ret; > + > + /* Enable Headset and 4 Buttons Jack detection */ > + ret = snd_soc_card_jack_new(rtd->card, "Headset Jack", > + SND_JACK_HEADSET | SND_JACK_BTN_0 | > + SND_JACK_BTN_1 | SND_JACK_BTN_2 | > + SND_JACK_BTN_3 | SND_JACK_LINEOUT, > + jack, NULL, 0); > + if (ret) { > + dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret); > + return ret; > + } > + > + snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE); > + snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOLUMEUP); > + snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEDOWN); > + snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOICECOMMAND); > + > + da7219_aad_jack_det(cmpnt_codec, &priv->headset_jack); > + > + return 0; > +} > + > +static int mt8186_da7219_i2s_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; > + unsigned int rate = params_rate(params); > + unsigned int mclk_fs_ratio = 256; > + unsigned int mclk_fs = rate * mclk_fs_ratio; > + unsigned int freq; > + int ret = 0, j; > + > + ret = snd_soc_dai_set_sysclk(asoc_rtd_to_cpu(rtd, 0), 0, > + mclk_fs, SND_SOC_CLOCK_OUT); > + if (ret < 0) > + dev_err(rtd->dev, "failed to set cpu dai sysclk\n"); Does it really make sense to go on after this failure? > + > + for_each_rtd_codec_dais(rtd, j, codec_dai) { > + if (!strcmp(codec_dai->component->name, DA7219_DEV_NAME)) { > + ret = snd_soc_dai_set_sysclk(codec_dai, > + DA7219_CLKSRC_MCLK, > + mclk_fs, > + SND_SOC_CLOCK_IN); > + if (ret < 0) > + dev_err(rtd->dev, "failed to set sysclk\n"); > + I think that going on past this wouldn't make sense as well, as it may result in unexpected behavior... just return a failure here > + if ((rate % 8000) == 0) > + freq = DA7219_PLL_FREQ_OUT_98304; > + else > + freq = DA7219_PLL_FREQ_OUT_90316; > + > + ret = snd_soc_dai_set_pll(codec_dai, 0, > + DA7219_SYSCLK_PLL_SRM, > + 0, freq); > + if (ret) > + dev_err(rtd->dev, "failed to start PLL: %d\n", > + ret); and here > + } > + } > + So, you've covered all failure cases already, for which, you can simply return 0 here. > + return ret; > +} > + > +static int mt8186_da7219_i2s_hw_free(struct snd_pcm_substream *substream) > +{ > + struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); > + struct snd_soc_dai *codec_dai; > + int ret = 0, j; > + > + for_each_rtd_codec_dais(rtd, j, codec_dai) { > + if (!strcmp(codec_dai->component->name, DA7219_DEV_NAME)) { > + ret = snd_soc_dai_set_pll(codec_dai, > + 0, DA7219_SYSCLK_MCLK, 0, 0); > + if (ret < 0) { > + dev_err(rtd->dev, "failed to stop PLL: %d\n", > + ret); > + break; > + } > + } > + } > + > + return ret; > +} > + > +static const struct snd_soc_ops mt8186_da7219_i2s_ops = { > + .hw_params = mt8186_da7219_i2s_hw_params, > + .hw_free = mt8186_da7219_i2s_hw_free, > +}; > + > +static int mt8186_mt6366_hdmi_init(struct snd_soc_pcm_runtime *rtd) > +{ > + struct snd_soc_component *cmpnt_codec = > + asoc_rtd_to_codec(rtd, 0)->component; > + struct mt8186_mt6366_da7219_max98357_priv *priv = > + snd_soc_card_get_drvdata(rtd->card); > + int ret; > + > + ret = snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT, > + &priv->hdmi_jack, NULL, 0); > + if (ret) { > + dev_err(rtd->dev, "HDMI Jack creation failed: %d\n", ret); > + return ret; > + } > + > + return snd_soc_component_set_jack(cmpnt_codec, &priv->hdmi_jack, NULL); > +} > + > +static int mt8186_mt6366_init(struct snd_soc_pcm_runtime *rtd) > +{ > + struct snd_soc_component *cmpnt_afe = > + snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME); > + struct snd_soc_component *cmpnt_codec = > + asoc_rtd_to_codec(rtd, 0)->component; > + struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe); > + struct mt8186_afe_private *afe_priv = afe->platform_priv; > + struct snd_soc_dapm_context *dapm = &rtd->card->dapm; > + int ret; > + > + /* set mtkaif protocol */ > + mt6358_set_mtkaif_protocol(cmpnt_codec, > + MT6358_MTKAIF_PROTOCOL_1); > + afe_priv->mtkaif_protocol = MT6358_MTKAIF_PROTOCOL_1; > + > + ret = snd_soc_dapm_sync(dapm); > + if (ret) { > + dev_info(rtd->dev, "failed to snd_soc_dapm_sync\n"); dev_err() > + return ret; > + } > + > + return 0; > +} > + > +static int mt8186_i2s_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, > + struct snd_pcm_hw_params *params) > +{ > + struct snd_interval *channels = hw_param_interval(params, > + SNDRV_PCM_HW_PARAM_CHANNELS); > + dev_info(rtd->dev, "%s(), fix format to 32bit\n", __func__); > + dev_dbg() > + /* fix BE i2s channel to 2 channel */ > + channels->min = 2; > + channels->max = 2; > + > + /* fix BE i2s format to S32_LE, clean param mask first */ > + snd_mask_reset_range(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), > + 0, (__force unsigned int)SNDRV_PCM_FORMAT_LAST); > + > + params_set_format(params, SNDRV_PCM_FORMAT_S32_LE); > + > + return 0; > +} > + > +static int mt8186_hdmi_i2s_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, > + struct snd_pcm_hw_params *params) > +{ > + struct snd_interval *channels = hw_param_interval(params, > + SNDRV_PCM_HW_PARAM_CHANNELS); > + dev_info(rtd->dev, "%s(), fix format to 32bit\n", __func__); > + dev_dbg() > + /* fix BE i2s channel to 2 channel */ > + channels->min = 2; > + channels->max = 2; > + > + /* fix BE i2s format to S24_LE, clean param mask first */ > + snd_mask_reset_range(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), > + 0, (__force unsigned int)SNDRV_PCM_FORMAT_LAST); > + > + params_set_format(params, SNDRV_PCM_FORMAT_S24_LE); > + > + return 0; > +} Besides, I would do the following instead: static int mt8186_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params, snd_pcm_format_t fmt) { struct snd_interval *channels = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); dev_dbg(rtd->dev, "%s(), fix format to 32bit\n", __func__); /* fix BE i2s channel to 2 channel */ channels->min = 2; channels->max = 2; /* fix BE i2s format to S32_LE, clean param mask first */ snd_mask_reset_range(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), 0, (__force unsigned int)SNDRV_PCM_FORMAT_LAST); params_set_format(params, fmt); return 0; } static int mt8186_i2s_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params) { return mt8186_hw_params_fixup(rtd, params, SNDRV_PCM_FORMAT_S32_LE); } static int mt8186_hdmi_i2s_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params) { return mt8186_hw_params_fixup(rtd, params, SNDRV_PCM_FORMAT_S24_LE); } ... this reduces code duplication! > + > +/* FE */ > +SND_SOC_DAILINK_DEFS(playback1, > + DAILINK_COMP_ARRAY(COMP_CPU("DL1")), > + DAILINK_COMP_ARRAY(COMP_DUMMY()), > + DAILINK_COMP_ARRAY(COMP_EMPTY())); ..snip.. > +static int mt8186_mt6366_da7219_max98357_dev_probe(struct platform_device *pdev) > +{ > + struct snd_soc_card *card = &mt8186_mt6366_da7219_max98357_soc_card; > + struct snd_soc_dai_link *dai_link; > + struct mt8186_mt6366_da7219_max98357_priv *priv; > + struct device_node *platform_node, *hdmi_codec; > + int ret, i; > + > + dev_info(&pdev->dev, "%s(), ++\n", __func__); > + > + card->dev = &pdev->dev; > + > + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); > + if (!priv) > + return -ENOMEM; > + > + platform_node = of_parse_phandle(pdev->dev.of_node, > + "mediatek,platform", 0); > + if (!platform_node) { > + dev_info(&pdev->dev, > + "Property 'platform' missing or invalid\n"); if (!platform_node) return dev_err_probe(&pdev->dev, -EINVAL, "mediatek,platform missing or invalid\n"); > + return -EINVAL; > + } > + > + hdmi_codec = of_parse_phandle(pdev->dev.of_node, > + "mediatek,hdmi-codec", 0); > + if (!hdmi_codec) { > + dev_info(&pdev->dev, > + "Property 'hdmi' missing or invalid\n"); dev_err() > + return -EINVAL; > + } > + > + for_each_card_prelinks(card, i, dai_link) { > + if (dai_link->platforms->name) > + continue; > + > + if (hdmi_codec && strcmp(dai_link->name, "I2S3") == 0) { > + dai_link->codecs->of_node = hdmi_codec; > + dai_link->ignore = 0; > + } > + > + dai_link->platforms->of_node = platform_node; > + } > + > + snd_soc_card_set_drvdata(card, priv); > + > + /* init gpio */ > + ret = mt8186_afe_gpio_init(&pdev->dev); > + if (ret) > + dev_info(&pdev->dev, "init gpio error\n"); dev_err() and goto end; > + > + dev_info(&pdev->dev, "%s(), devm_snd_soc_register_card\n", __func__); > + ret = devm_snd_soc_register_card(&pdev->dev, card); > + if (ret) > + dev_info(&pdev->dev, "%s snd_soc_register_card fail %d\n", > + __func__, ret); dev_err_probe() end: > + of_node_put(platform_node); > + of_node_put(hdmi_codec); > + > + return ret; > +} > + > +#if IS_ENABLED(CONFIG_OF) > +static const struct of_device_id mt8186_mt6366_da7219_max98357_dt_match[] = { > + {.compatible = "mediatek,mt8186_mt6366_da7219_max98357_sound",}, > + {} > +}; > +#endif > + > +static struct platform_driver mt8186_mt6366_da7219_max98357_driver = { > + .driver = { > + .name = "mt8186_mt6366_da7219_max98357", > +#if IS_ENABLED(CONFIG_OF) > + .of_match_table = mt8186_mt6366_da7219_max98357_dt_match, > +#endif > + .pm = &snd_soc_pm_ops, > + }, > + .probe = mt8186_mt6366_da7219_max98357_dev_probe, > +}; > + > +module_platform_driver(mt8186_mt6366_da7219_max98357_driver); > + > +/* Module information */ > +MODULE_DESCRIPTION("MT8186-MT6366-DA7219-MAX98357 ALSA SoC machine driver"); > +MODULE_AUTHOR("Jiaxin Yu "); > +MODULE_LICENSE("GPL v2"); > +MODULE_ALIAS("mt8186_mt6366_da7219_max98357 soc card"); From mboxrd@z Thu Jan 1 00:00:00 1970 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 alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EDAE3C433EF for ; Fri, 18 Feb 2022 14:58:49 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 2C3E917C1; Fri, 18 Feb 2022 15:57:58 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 2C3E917C1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1645196328; bh=al6Ev0bQKorkckF2iTM/jxCkPr35vPyHBaRFp9zx2wg=; h=Date:From:Subject:To:References:In-Reply-To:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=P8df0O/Dzm4EAq8K8vx5weX6OElB6SGXJ7+aTzK7UgqE2m/aixHsd4kSwXEUg0DLW cGU9igtKxzZpVyrf2cZiZGF7NuvWenGrmX1aliRIBGGWSmqvR3J9N90cuh6bICOMrt TFjdIngukzaGyrrloziTgL2Q1D7w6YBpwybeg/vA= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 5E9D0F8055B; Fri, 18 Feb 2022 15:55:00 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 2CEF9F8055B; Fri, 18 Feb 2022 15:54:58 +0100 (CET) Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id F089FF80563 for ; Fri, 18 Feb 2022 15:54:51 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz F089FF80563 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="JABE/NDH" Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: kholk11) with ESMTPSA id 270C21F46B85 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1645196091; bh=al6Ev0bQKorkckF2iTM/jxCkPr35vPyHBaRFp9zx2wg=; h=Date:From:Subject:To:Cc:References:In-Reply-To:From; b=JABE/NDHqXiChVUIOUwgcgWWfmBkoDCrMTVFDcPnx9onUsr3vWZrMkHoDK5JDfpdt ER/sFomFfCRzO90HeEf5YnqMlJM1n/vHzmwtIIyRiTHbWZfpQQE7ZqovIyDZtEGzr2 vHe92RxN4JsKH84jdlq/5xKgFMrd4vKRM9rUNPrvJBTza7Mb271Dt1ENj74fjx1t9X T1ELDH9lHFXVoNCCtplqAAdU0QbJZmFpu+TaJ/mHrexNfE7krhUflPcX4QQxVFrV+J eR1xgPqFSDotoGGON0gUG5ACKIYT04Q4qgVFnHTBfxP9BXkXWPOw7fHuurEDGSgcQ+ cD6mdVX2hKyqg== Message-ID: <70147e6f-a008-ab1a-eb07-dbb1236849b0@collabora.com> Date: Fri, 18 Feb 2022 15:54:47 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.1 From: AngeloGioacchino Del Regno Subject: Re: [v2 14/17] ASoC: mediatek: mt8186: add machine driver with mt6366, da7219 and max98357 To: Jiaxin Yu , broonie@kernel.org References: <20220217134205.15400-1-jiaxin.yu@mediatek.com> <20220217134205.15400-15-jiaxin.yu@mediatek.com> Content-Language: en-US In-Reply-To: <20220217134205.15400-15-jiaxin.yu@mediatek.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Cc: devicetree@vger.kernel.org, alsa-devel@alsa-project.org, geert+renesas@glider.be, linux-kernel@vger.kernel.org, zhangqilong3@huawei.com, tiwai@suse.com, lgirdwood@gmail.com, tzungbi@google.com, robh+dt@kernel.org, linux-mediatek@lists.infradead.org, trevor.wu@mediatek.com, p.zabel@pengutronix.de, matthias.bgg@gmail.com, aaronyu@google.com, linux-arm-kernel@lists.infradead.org X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 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" Il 17/02/22 14:42, Jiaxin Yu ha scritto: > This patch adds support for mt8186 board with mt6366, da7219 and max98357. > > Signed-off-by: Jiaxin Yu > --- > .../mt8186/mt8186-mt6366-da7219-max98357.c | 910 ++++++++++++++++++ > 1 file changed, 910 insertions(+) > create mode 100644 sound/soc/mediatek/mt8186/mt8186-mt6366-da7219-max98357.c > > diff --git a/sound/soc/mediatek/mt8186/mt8186-mt6366-da7219-max98357.c b/sound/soc/mediatek/mt8186/mt8186-mt6366-da7219-max98357.c > new file mode 100644 > index 000000000000..6ba53b8d1e46 > --- /dev/null > +++ b/sound/soc/mediatek/mt8186/mt8186-mt6366-da7219-max98357.c > @@ -0,0 +1,910 @@ > +// SPDX-License-Identifier: GPL-2.0 > +// > +// mt8186-mt6366-da7219-max98357.c > +// -- MT8186-MT6366-DA7219-MAX98357 ALSA SoC machine driver > +// > +// Copyright (c) 2022 MediaTek Inc. > +// Author: Jiaxin Yu > +// > + > +#include > +#include > +#include > +#include > +#include > + > +#include "../../codecs/da7219-aad.h" > +#include "../../codecs/da7219.h" > +#include "../../codecs/mt6358.h" > +#include "../common/mtk-afe-platform-driver.h" > +#include "mt8186-afe-common.h" > +#include "mt8186-afe-clk.h" > +#include "mt8186-afe-gpio.h" > + > +#define DA7219_CODEC_DAI "da7219-hifi" > +#define DA7219_DEV_NAME "da7219.5-001a" > + > +struct mt8186_mt6366_da7219_max98357_priv { > + struct snd_soc_jack headset_jack, hdmi_jack; > +}; > + > +static struct snd_soc_codec_conf mt6366_codec_conf[] = { > + { > + .dlc = COMP_CODEC_CONF("mt6358-sound"), > + .name_prefix = "Mt6366", > + }, > +}; > + > +static int mt8186_da7219_init(struct snd_soc_pcm_runtime *rtd) > +{ > + struct mt8186_mt6366_da7219_max98357_priv *priv = > + snd_soc_card_get_drvdata(rtd->card); > + struct snd_soc_jack *jack = &priv->headset_jack; > + struct snd_soc_component *cmpnt_codec = > + asoc_rtd_to_codec(rtd, 0)->component; > + int ret; > + > + /* Enable Headset and 4 Buttons Jack detection */ > + ret = snd_soc_card_jack_new(rtd->card, "Headset Jack", > + SND_JACK_HEADSET | SND_JACK_BTN_0 | > + SND_JACK_BTN_1 | SND_JACK_BTN_2 | > + SND_JACK_BTN_3 | SND_JACK_LINEOUT, > + jack, NULL, 0); > + if (ret) { > + dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret); > + return ret; > + } > + > + snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE); > + snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOLUMEUP); > + snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEDOWN); > + snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOICECOMMAND); > + > + da7219_aad_jack_det(cmpnt_codec, &priv->headset_jack); > + > + return 0; > +} > + > +static int mt8186_da7219_i2s_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; > + unsigned int rate = params_rate(params); > + unsigned int mclk_fs_ratio = 256; > + unsigned int mclk_fs = rate * mclk_fs_ratio; > + unsigned int freq; > + int ret = 0, j; > + > + ret = snd_soc_dai_set_sysclk(asoc_rtd_to_cpu(rtd, 0), 0, > + mclk_fs, SND_SOC_CLOCK_OUT); > + if (ret < 0) > + dev_err(rtd->dev, "failed to set cpu dai sysclk\n"); Does it really make sense to go on after this failure? > + > + for_each_rtd_codec_dais(rtd, j, codec_dai) { > + if (!strcmp(codec_dai->component->name, DA7219_DEV_NAME)) { > + ret = snd_soc_dai_set_sysclk(codec_dai, > + DA7219_CLKSRC_MCLK, > + mclk_fs, > + SND_SOC_CLOCK_IN); > + if (ret < 0) > + dev_err(rtd->dev, "failed to set sysclk\n"); > + I think that going on past this wouldn't make sense as well, as it may result in unexpected behavior... just return a failure here > + if ((rate % 8000) == 0) > + freq = DA7219_PLL_FREQ_OUT_98304; > + else > + freq = DA7219_PLL_FREQ_OUT_90316; > + > + ret = snd_soc_dai_set_pll(codec_dai, 0, > + DA7219_SYSCLK_PLL_SRM, > + 0, freq); > + if (ret) > + dev_err(rtd->dev, "failed to start PLL: %d\n", > + ret); and here > + } > + } > + So, you've covered all failure cases already, for which, you can simply return 0 here. > + return ret; > +} > + > +static int mt8186_da7219_i2s_hw_free(struct snd_pcm_substream *substream) > +{ > + struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); > + struct snd_soc_dai *codec_dai; > + int ret = 0, j; > + > + for_each_rtd_codec_dais(rtd, j, codec_dai) { > + if (!strcmp(codec_dai->component->name, DA7219_DEV_NAME)) { > + ret = snd_soc_dai_set_pll(codec_dai, > + 0, DA7219_SYSCLK_MCLK, 0, 0); > + if (ret < 0) { > + dev_err(rtd->dev, "failed to stop PLL: %d\n", > + ret); > + break; > + } > + } > + } > + > + return ret; > +} > + > +static const struct snd_soc_ops mt8186_da7219_i2s_ops = { > + .hw_params = mt8186_da7219_i2s_hw_params, > + .hw_free = mt8186_da7219_i2s_hw_free, > +}; > + > +static int mt8186_mt6366_hdmi_init(struct snd_soc_pcm_runtime *rtd) > +{ > + struct snd_soc_component *cmpnt_codec = > + asoc_rtd_to_codec(rtd, 0)->component; > + struct mt8186_mt6366_da7219_max98357_priv *priv = > + snd_soc_card_get_drvdata(rtd->card); > + int ret; > + > + ret = snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT, > + &priv->hdmi_jack, NULL, 0); > + if (ret) { > + dev_err(rtd->dev, "HDMI Jack creation failed: %d\n", ret); > + return ret; > + } > + > + return snd_soc_component_set_jack(cmpnt_codec, &priv->hdmi_jack, NULL); > +} > + > +static int mt8186_mt6366_init(struct snd_soc_pcm_runtime *rtd) > +{ > + struct snd_soc_component *cmpnt_afe = > + snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME); > + struct snd_soc_component *cmpnt_codec = > + asoc_rtd_to_codec(rtd, 0)->component; > + struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe); > + struct mt8186_afe_private *afe_priv = afe->platform_priv; > + struct snd_soc_dapm_context *dapm = &rtd->card->dapm; > + int ret; > + > + /* set mtkaif protocol */ > + mt6358_set_mtkaif_protocol(cmpnt_codec, > + MT6358_MTKAIF_PROTOCOL_1); > + afe_priv->mtkaif_protocol = MT6358_MTKAIF_PROTOCOL_1; > + > + ret = snd_soc_dapm_sync(dapm); > + if (ret) { > + dev_info(rtd->dev, "failed to snd_soc_dapm_sync\n"); dev_err() > + return ret; > + } > + > + return 0; > +} > + > +static int mt8186_i2s_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, > + struct snd_pcm_hw_params *params) > +{ > + struct snd_interval *channels = hw_param_interval(params, > + SNDRV_PCM_HW_PARAM_CHANNELS); > + dev_info(rtd->dev, "%s(), fix format to 32bit\n", __func__); > + dev_dbg() > + /* fix BE i2s channel to 2 channel */ > + channels->min = 2; > + channels->max = 2; > + > + /* fix BE i2s format to S32_LE, clean param mask first */ > + snd_mask_reset_range(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), > + 0, (__force unsigned int)SNDRV_PCM_FORMAT_LAST); > + > + params_set_format(params, SNDRV_PCM_FORMAT_S32_LE); > + > + return 0; > +} > + > +static int mt8186_hdmi_i2s_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, > + struct snd_pcm_hw_params *params) > +{ > + struct snd_interval *channels = hw_param_interval(params, > + SNDRV_PCM_HW_PARAM_CHANNELS); > + dev_info(rtd->dev, "%s(), fix format to 32bit\n", __func__); > + dev_dbg() > + /* fix BE i2s channel to 2 channel */ > + channels->min = 2; > + channels->max = 2; > + > + /* fix BE i2s format to S24_LE, clean param mask first */ > + snd_mask_reset_range(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), > + 0, (__force unsigned int)SNDRV_PCM_FORMAT_LAST); > + > + params_set_format(params, SNDRV_PCM_FORMAT_S24_LE); > + > + return 0; > +} Besides, I would do the following instead: static int mt8186_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params, snd_pcm_format_t fmt) { struct snd_interval *channels = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); dev_dbg(rtd->dev, "%s(), fix format to 32bit\n", __func__); /* fix BE i2s channel to 2 channel */ channels->min = 2; channels->max = 2; /* fix BE i2s format to S32_LE, clean param mask first */ snd_mask_reset_range(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), 0, (__force unsigned int)SNDRV_PCM_FORMAT_LAST); params_set_format(params, fmt); return 0; } static int mt8186_i2s_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params) { return mt8186_hw_params_fixup(rtd, params, SNDRV_PCM_FORMAT_S32_LE); } static int mt8186_hdmi_i2s_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params) { return mt8186_hw_params_fixup(rtd, params, SNDRV_PCM_FORMAT_S24_LE); } ... this reduces code duplication! > + > +/* FE */ > +SND_SOC_DAILINK_DEFS(playback1, > + DAILINK_COMP_ARRAY(COMP_CPU("DL1")), > + DAILINK_COMP_ARRAY(COMP_DUMMY()), > + DAILINK_COMP_ARRAY(COMP_EMPTY())); ..snip.. > +static int mt8186_mt6366_da7219_max98357_dev_probe(struct platform_device *pdev) > +{ > + struct snd_soc_card *card = &mt8186_mt6366_da7219_max98357_soc_card; > + struct snd_soc_dai_link *dai_link; > + struct mt8186_mt6366_da7219_max98357_priv *priv; > + struct device_node *platform_node, *hdmi_codec; > + int ret, i; > + > + dev_info(&pdev->dev, "%s(), ++\n", __func__); > + > + card->dev = &pdev->dev; > + > + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); > + if (!priv) > + return -ENOMEM; > + > + platform_node = of_parse_phandle(pdev->dev.of_node, > + "mediatek,platform", 0); > + if (!platform_node) { > + dev_info(&pdev->dev, > + "Property 'platform' missing or invalid\n"); if (!platform_node) return dev_err_probe(&pdev->dev, -EINVAL, "mediatek,platform missing or invalid\n"); > + return -EINVAL; > + } > + > + hdmi_codec = of_parse_phandle(pdev->dev.of_node, > + "mediatek,hdmi-codec", 0); > + if (!hdmi_codec) { > + dev_info(&pdev->dev, > + "Property 'hdmi' missing or invalid\n"); dev_err() > + return -EINVAL; > + } > + > + for_each_card_prelinks(card, i, dai_link) { > + if (dai_link->platforms->name) > + continue; > + > + if (hdmi_codec && strcmp(dai_link->name, "I2S3") == 0) { > + dai_link->codecs->of_node = hdmi_codec; > + dai_link->ignore = 0; > + } > + > + dai_link->platforms->of_node = platform_node; > + } > + > + snd_soc_card_set_drvdata(card, priv); > + > + /* init gpio */ > + ret = mt8186_afe_gpio_init(&pdev->dev); > + if (ret) > + dev_info(&pdev->dev, "init gpio error\n"); dev_err() and goto end; > + > + dev_info(&pdev->dev, "%s(), devm_snd_soc_register_card\n", __func__); > + ret = devm_snd_soc_register_card(&pdev->dev, card); > + if (ret) > + dev_info(&pdev->dev, "%s snd_soc_register_card fail %d\n", > + __func__, ret); dev_err_probe() end: > + of_node_put(platform_node); > + of_node_put(hdmi_codec); > + > + return ret; > +} > + > +#if IS_ENABLED(CONFIG_OF) > +static const struct of_device_id mt8186_mt6366_da7219_max98357_dt_match[] = { > + {.compatible = "mediatek,mt8186_mt6366_da7219_max98357_sound",}, > + {} > +}; > +#endif > + > +static struct platform_driver mt8186_mt6366_da7219_max98357_driver = { > + .driver = { > + .name = "mt8186_mt6366_da7219_max98357", > +#if IS_ENABLED(CONFIG_OF) > + .of_match_table = mt8186_mt6366_da7219_max98357_dt_match, > +#endif > + .pm = &snd_soc_pm_ops, > + }, > + .probe = mt8186_mt6366_da7219_max98357_dev_probe, > +}; > + > +module_platform_driver(mt8186_mt6366_da7219_max98357_driver); > + > +/* Module information */ > +MODULE_DESCRIPTION("MT8186-MT6366-DA7219-MAX98357 ALSA SoC machine driver"); > +MODULE_AUTHOR("Jiaxin Yu "); > +MODULE_LICENSE("GPL v2"); > +MODULE_ALIAS("mt8186_mt6366_da7219_max98357 soc card"); From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 550AAC433F5 for ; Fri, 18 Feb 2022 15:01:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:References:Cc:To:Subject:From: MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=w2rhbGRz0BawFR4K4P9H+ZKzZ534acLhfziLLd6+b94=; b=41QmUmjJXHPs/p O/buu2PdAaC99lJHW6xdfLHUeXOYTbeGT4xx0Q1mYJoLSZL+HxeWkgINEBt7U2EFUMY3WT/9MHnnL zYrbD3qnswuQuIydrPs4byEgBGlLXXaAJG9SBhFhyovKMtlkUGEtr9FgGsbf/Bb/e2dt11lVDQ/T+ psSm3HSaQTE1ZtmyiW1DDRXve0lBMFLo0Cd71qgwMIZRba+F3R2MiG7vsQbL8hi38Mqfr2gZJhp7W 2y1TMyxU0VAfOCbdHh9kmVO1U9RCF6177CuDwmC2Fyg+ZdaOy5LcrbWU4OgKWfUStu1uttsljenF9 uNVYgNnMQ3ZQOo24JDkA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nL4kl-00Ev5X-HV; Fri, 18 Feb 2022 15:00:59 +0000 Received: from bhuna.collabora.co.uk ([2a00:1098:0:82:1000:25:2eeb:e3e3]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nL4eq-00ErHs-H3; Fri, 18 Feb 2022 14:54:56 +0000 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: kholk11) with ESMTPSA id 270C21F46B85 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1645196091; bh=al6Ev0bQKorkckF2iTM/jxCkPr35vPyHBaRFp9zx2wg=; h=Date:From:Subject:To:Cc:References:In-Reply-To:From; b=JABE/NDHqXiChVUIOUwgcgWWfmBkoDCrMTVFDcPnx9onUsr3vWZrMkHoDK5JDfpdt ER/sFomFfCRzO90HeEf5YnqMlJM1n/vHzmwtIIyRiTHbWZfpQQE7ZqovIyDZtEGzr2 vHe92RxN4JsKH84jdlq/5xKgFMrd4vKRM9rUNPrvJBTza7Mb271Dt1ENj74fjx1t9X T1ELDH9lHFXVoNCCtplqAAdU0QbJZmFpu+TaJ/mHrexNfE7krhUflPcX4QQxVFrV+J eR1xgPqFSDotoGGON0gUG5ACKIYT04Q4qgVFnHTBfxP9BXkXWPOw7fHuurEDGSgcQ+ cD6mdVX2hKyqg== Message-ID: <70147e6f-a008-ab1a-eb07-dbb1236849b0@collabora.com> Date: Fri, 18 Feb 2022 15:54:47 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.1 From: AngeloGioacchino Del Regno Subject: Re: [v2 14/17] ASoC: mediatek: mt8186: add machine driver with mt6366, da7219 and max98357 To: Jiaxin Yu , broonie@kernel.org Cc: lgirdwood@gmail.com, tiwai@suse.com, robh+dt@kernel.org, matthias.bgg@gmail.com, perex@perex.cz, p.zabel@pengutronix.de, geert+renesas@glider.be, trevor.wu@mediatek.com, tzungbi@google.com, aaronyu@google.com, zhangqilong3@huawei.com, alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org References: <20220217134205.15400-1-jiaxin.yu@mediatek.com> <20220217134205.15400-15-jiaxin.yu@mediatek.com> Content-Language: en-US In-Reply-To: <20220217134205.15400-15-jiaxin.yu@mediatek.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220218_065452_942753_7F4C855C X-CRM114-Status: GOOD ( 28.43 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org Il 17/02/22 14:42, Jiaxin Yu ha scritto: > This patch adds support for mt8186 board with mt6366, da7219 and max98357. > > Signed-off-by: Jiaxin Yu > --- > .../mt8186/mt8186-mt6366-da7219-max98357.c | 910 ++++++++++++++++++ > 1 file changed, 910 insertions(+) > create mode 100644 sound/soc/mediatek/mt8186/mt8186-mt6366-da7219-max98357.c > > diff --git a/sound/soc/mediatek/mt8186/mt8186-mt6366-da7219-max98357.c b/sound/soc/mediatek/mt8186/mt8186-mt6366-da7219-max98357.c > new file mode 100644 > index 000000000000..6ba53b8d1e46 > --- /dev/null > +++ b/sound/soc/mediatek/mt8186/mt8186-mt6366-da7219-max98357.c > @@ -0,0 +1,910 @@ > +// SPDX-License-Identifier: GPL-2.0 > +// > +// mt8186-mt6366-da7219-max98357.c > +// -- MT8186-MT6366-DA7219-MAX98357 ALSA SoC machine driver > +// > +// Copyright (c) 2022 MediaTek Inc. > +// Author: Jiaxin Yu > +// > + > +#include > +#include > +#include > +#include > +#include > + > +#include "../../codecs/da7219-aad.h" > +#include "../../codecs/da7219.h" > +#include "../../codecs/mt6358.h" > +#include "../common/mtk-afe-platform-driver.h" > +#include "mt8186-afe-common.h" > +#include "mt8186-afe-clk.h" > +#include "mt8186-afe-gpio.h" > + > +#define DA7219_CODEC_DAI "da7219-hifi" > +#define DA7219_DEV_NAME "da7219.5-001a" > + > +struct mt8186_mt6366_da7219_max98357_priv { > + struct snd_soc_jack headset_jack, hdmi_jack; > +}; > + > +static struct snd_soc_codec_conf mt6366_codec_conf[] = { > + { > + .dlc = COMP_CODEC_CONF("mt6358-sound"), > + .name_prefix = "Mt6366", > + }, > +}; > + > +static int mt8186_da7219_init(struct snd_soc_pcm_runtime *rtd) > +{ > + struct mt8186_mt6366_da7219_max98357_priv *priv = > + snd_soc_card_get_drvdata(rtd->card); > + struct snd_soc_jack *jack = &priv->headset_jack; > + struct snd_soc_component *cmpnt_codec = > + asoc_rtd_to_codec(rtd, 0)->component; > + int ret; > + > + /* Enable Headset and 4 Buttons Jack detection */ > + ret = snd_soc_card_jack_new(rtd->card, "Headset Jack", > + SND_JACK_HEADSET | SND_JACK_BTN_0 | > + SND_JACK_BTN_1 | SND_JACK_BTN_2 | > + SND_JACK_BTN_3 | SND_JACK_LINEOUT, > + jack, NULL, 0); > + if (ret) { > + dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret); > + return ret; > + } > + > + snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE); > + snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOLUMEUP); > + snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEDOWN); > + snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOICECOMMAND); > + > + da7219_aad_jack_det(cmpnt_codec, &priv->headset_jack); > + > + return 0; > +} > + > +static int mt8186_da7219_i2s_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; > + unsigned int rate = params_rate(params); > + unsigned int mclk_fs_ratio = 256; > + unsigned int mclk_fs = rate * mclk_fs_ratio; > + unsigned int freq; > + int ret = 0, j; > + > + ret = snd_soc_dai_set_sysclk(asoc_rtd_to_cpu(rtd, 0), 0, > + mclk_fs, SND_SOC_CLOCK_OUT); > + if (ret < 0) > + dev_err(rtd->dev, "failed to set cpu dai sysclk\n"); Does it really make sense to go on after this failure? > + > + for_each_rtd_codec_dais(rtd, j, codec_dai) { > + if (!strcmp(codec_dai->component->name, DA7219_DEV_NAME)) { > + ret = snd_soc_dai_set_sysclk(codec_dai, > + DA7219_CLKSRC_MCLK, > + mclk_fs, > + SND_SOC_CLOCK_IN); > + if (ret < 0) > + dev_err(rtd->dev, "failed to set sysclk\n"); > + I think that going on past this wouldn't make sense as well, as it may result in unexpected behavior... just return a failure here > + if ((rate % 8000) == 0) > + freq = DA7219_PLL_FREQ_OUT_98304; > + else > + freq = DA7219_PLL_FREQ_OUT_90316; > + > + ret = snd_soc_dai_set_pll(codec_dai, 0, > + DA7219_SYSCLK_PLL_SRM, > + 0, freq); > + if (ret) > + dev_err(rtd->dev, "failed to start PLL: %d\n", > + ret); and here > + } > + } > + So, you've covered all failure cases already, for which, you can simply return 0 here. > + return ret; > +} > + > +static int mt8186_da7219_i2s_hw_free(struct snd_pcm_substream *substream) > +{ > + struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); > + struct snd_soc_dai *codec_dai; > + int ret = 0, j; > + > + for_each_rtd_codec_dais(rtd, j, codec_dai) { > + if (!strcmp(codec_dai->component->name, DA7219_DEV_NAME)) { > + ret = snd_soc_dai_set_pll(codec_dai, > + 0, DA7219_SYSCLK_MCLK, 0, 0); > + if (ret < 0) { > + dev_err(rtd->dev, "failed to stop PLL: %d\n", > + ret); > + break; > + } > + } > + } > + > + return ret; > +} > + > +static const struct snd_soc_ops mt8186_da7219_i2s_ops = { > + .hw_params = mt8186_da7219_i2s_hw_params, > + .hw_free = mt8186_da7219_i2s_hw_free, > +}; > + > +static int mt8186_mt6366_hdmi_init(struct snd_soc_pcm_runtime *rtd) > +{ > + struct snd_soc_component *cmpnt_codec = > + asoc_rtd_to_codec(rtd, 0)->component; > + struct mt8186_mt6366_da7219_max98357_priv *priv = > + snd_soc_card_get_drvdata(rtd->card); > + int ret; > + > + ret = snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT, > + &priv->hdmi_jack, NULL, 0); > + if (ret) { > + dev_err(rtd->dev, "HDMI Jack creation failed: %d\n", ret); > + return ret; > + } > + > + return snd_soc_component_set_jack(cmpnt_codec, &priv->hdmi_jack, NULL); > +} > + > +static int mt8186_mt6366_init(struct snd_soc_pcm_runtime *rtd) > +{ > + struct snd_soc_component *cmpnt_afe = > + snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME); > + struct snd_soc_component *cmpnt_codec = > + asoc_rtd_to_codec(rtd, 0)->component; > + struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe); > + struct mt8186_afe_private *afe_priv = afe->platform_priv; > + struct snd_soc_dapm_context *dapm = &rtd->card->dapm; > + int ret; > + > + /* set mtkaif protocol */ > + mt6358_set_mtkaif_protocol(cmpnt_codec, > + MT6358_MTKAIF_PROTOCOL_1); > + afe_priv->mtkaif_protocol = MT6358_MTKAIF_PROTOCOL_1; > + > + ret = snd_soc_dapm_sync(dapm); > + if (ret) { > + dev_info(rtd->dev, "failed to snd_soc_dapm_sync\n"); dev_err() > + return ret; > + } > + > + return 0; > +} > + > +static int mt8186_i2s_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, > + struct snd_pcm_hw_params *params) > +{ > + struct snd_interval *channels = hw_param_interval(params, > + SNDRV_PCM_HW_PARAM_CHANNELS); > + dev_info(rtd->dev, "%s(), fix format to 32bit\n", __func__); > + dev_dbg() > + /* fix BE i2s channel to 2 channel */ > + channels->min = 2; > + channels->max = 2; > + > + /* fix BE i2s format to S32_LE, clean param mask first */ > + snd_mask_reset_range(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), > + 0, (__force unsigned int)SNDRV_PCM_FORMAT_LAST); > + > + params_set_format(params, SNDRV_PCM_FORMAT_S32_LE); > + > + return 0; > +} > + > +static int mt8186_hdmi_i2s_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, > + struct snd_pcm_hw_params *params) > +{ > + struct snd_interval *channels = hw_param_interval(params, > + SNDRV_PCM_HW_PARAM_CHANNELS); > + dev_info(rtd->dev, "%s(), fix format to 32bit\n", __func__); > + dev_dbg() > + /* fix BE i2s channel to 2 channel */ > + channels->min = 2; > + channels->max = 2; > + > + /* fix BE i2s format to S24_LE, clean param mask first */ > + snd_mask_reset_range(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), > + 0, (__force unsigned int)SNDRV_PCM_FORMAT_LAST); > + > + params_set_format(params, SNDRV_PCM_FORMAT_S24_LE); > + > + return 0; > +} Besides, I would do the following instead: static int mt8186_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params, snd_pcm_format_t fmt) { struct snd_interval *channels = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); dev_dbg(rtd->dev, "%s(), fix format to 32bit\n", __func__); /* fix BE i2s channel to 2 channel */ channels->min = 2; channels->max = 2; /* fix BE i2s format to S32_LE, clean param mask first */ snd_mask_reset_range(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), 0, (__force unsigned int)SNDRV_PCM_FORMAT_LAST); params_set_format(params, fmt); return 0; } static int mt8186_i2s_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params) { return mt8186_hw_params_fixup(rtd, params, SNDRV_PCM_FORMAT_S32_LE); } static int mt8186_hdmi_i2s_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params) { return mt8186_hw_params_fixup(rtd, params, SNDRV_PCM_FORMAT_S24_LE); } ... this reduces code duplication! > + > +/* FE */ > +SND_SOC_DAILINK_DEFS(playback1, > + DAILINK_COMP_ARRAY(COMP_CPU("DL1")), > + DAILINK_COMP_ARRAY(COMP_DUMMY()), > + DAILINK_COMP_ARRAY(COMP_EMPTY())); ..snip.. > +static int mt8186_mt6366_da7219_max98357_dev_probe(struct platform_device *pdev) > +{ > + struct snd_soc_card *card = &mt8186_mt6366_da7219_max98357_soc_card; > + struct snd_soc_dai_link *dai_link; > + struct mt8186_mt6366_da7219_max98357_priv *priv; > + struct device_node *platform_node, *hdmi_codec; > + int ret, i; > + > + dev_info(&pdev->dev, "%s(), ++\n", __func__); > + > + card->dev = &pdev->dev; > + > + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); > + if (!priv) > + return -ENOMEM; > + > + platform_node = of_parse_phandle(pdev->dev.of_node, > + "mediatek,platform", 0); > + if (!platform_node) { > + dev_info(&pdev->dev, > + "Property 'platform' missing or invalid\n"); if (!platform_node) return dev_err_probe(&pdev->dev, -EINVAL, "mediatek,platform missing or invalid\n"); > + return -EINVAL; > + } > + > + hdmi_codec = of_parse_phandle(pdev->dev.of_node, > + "mediatek,hdmi-codec", 0); > + if (!hdmi_codec) { > + dev_info(&pdev->dev, > + "Property 'hdmi' missing or invalid\n"); dev_err() > + return -EINVAL; > + } > + > + for_each_card_prelinks(card, i, dai_link) { > + if (dai_link->platforms->name) > + continue; > + > + if (hdmi_codec && strcmp(dai_link->name, "I2S3") == 0) { > + dai_link->codecs->of_node = hdmi_codec; > + dai_link->ignore = 0; > + } > + > + dai_link->platforms->of_node = platform_node; > + } > + > + snd_soc_card_set_drvdata(card, priv); > + > + /* init gpio */ > + ret = mt8186_afe_gpio_init(&pdev->dev); > + if (ret) > + dev_info(&pdev->dev, "init gpio error\n"); dev_err() and goto end; > + > + dev_info(&pdev->dev, "%s(), devm_snd_soc_register_card\n", __func__); > + ret = devm_snd_soc_register_card(&pdev->dev, card); > + if (ret) > + dev_info(&pdev->dev, "%s snd_soc_register_card fail %d\n", > + __func__, ret); dev_err_probe() end: > + of_node_put(platform_node); > + of_node_put(hdmi_codec); > + > + return ret; > +} > + > +#if IS_ENABLED(CONFIG_OF) > +static const struct of_device_id mt8186_mt6366_da7219_max98357_dt_match[] = { > + {.compatible = "mediatek,mt8186_mt6366_da7219_max98357_sound",}, > + {} > +}; > +#endif > + > +static struct platform_driver mt8186_mt6366_da7219_max98357_driver = { > + .driver = { > + .name = "mt8186_mt6366_da7219_max98357", > +#if IS_ENABLED(CONFIG_OF) > + .of_match_table = mt8186_mt6366_da7219_max98357_dt_match, > +#endif > + .pm = &snd_soc_pm_ops, > + }, > + .probe = mt8186_mt6366_da7219_max98357_dev_probe, > +}; > + > +module_platform_driver(mt8186_mt6366_da7219_max98357_driver); > + > +/* Module information */ > +MODULE_DESCRIPTION("MT8186-MT6366-DA7219-MAX98357 ALSA SoC machine driver"); > +MODULE_AUTHOR("Jiaxin Yu "); > +MODULE_LICENSE("GPL v2"); > +MODULE_ALIAS("mt8186_mt6366_da7219_max98357 soc card"); _______________________________________________ Linux-mediatek mailing list Linux-mediatek@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-mediatek From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B947DC433F5 for ; Fri, 18 Feb 2022 15:02:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:References:Cc:To:Subject:From: MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Dd5+pkiz4/AEvXYJ3c0gwB5nKU8ryg9qB2PIYbEGqy8=; b=1x8L93AIkZjIUw UHMJ4Q3PDQ/08lWYQmrl4mLu3n5klfZza1KxZQrFbvrz05j+ZrbpmuyaE+tfw2C6zR7PWGs4uiWuq VkGLs8hueMIWL+OkKHbOCcFY7NcPO4zkB8NUTlO9CstyMwcb7dVBMmEkTEYdCv2b1DgIH1IXoKCRX AIirkpVHVVSk4I8ToXQXb3v+bvC7ATbj2ChDiwujIZR4bALa/4Und4NZuFgN4fA2H5fhmTeRfyNLt 5ZaFBzM+4EdbSNXX7uGPqGpw6Eu4UC/TSzbD2cifxkzfi1MX83WpI/GlB3Rp3BO+sT7D7+N//UJRv 3pkl4fwxHqDYoWHN0MeQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nL4kL-00Eumb-V4; Fri, 18 Feb 2022 15:00:34 +0000 Received: from bhuna.collabora.co.uk ([2a00:1098:0:82:1000:25:2eeb:e3e3]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nL4eq-00ErHs-H3; Fri, 18 Feb 2022 14:54:56 +0000 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: kholk11) with ESMTPSA id 270C21F46B85 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1645196091; bh=al6Ev0bQKorkckF2iTM/jxCkPr35vPyHBaRFp9zx2wg=; h=Date:From:Subject:To:Cc:References:In-Reply-To:From; b=JABE/NDHqXiChVUIOUwgcgWWfmBkoDCrMTVFDcPnx9onUsr3vWZrMkHoDK5JDfpdt ER/sFomFfCRzO90HeEf5YnqMlJM1n/vHzmwtIIyRiTHbWZfpQQE7ZqovIyDZtEGzr2 vHe92RxN4JsKH84jdlq/5xKgFMrd4vKRM9rUNPrvJBTza7Mb271Dt1ENj74fjx1t9X T1ELDH9lHFXVoNCCtplqAAdU0QbJZmFpu+TaJ/mHrexNfE7krhUflPcX4QQxVFrV+J eR1xgPqFSDotoGGON0gUG5ACKIYT04Q4qgVFnHTBfxP9BXkXWPOw7fHuurEDGSgcQ+ cD6mdVX2hKyqg== Message-ID: <70147e6f-a008-ab1a-eb07-dbb1236849b0@collabora.com> Date: Fri, 18 Feb 2022 15:54:47 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.1 From: AngeloGioacchino Del Regno Subject: Re: [v2 14/17] ASoC: mediatek: mt8186: add machine driver with mt6366, da7219 and max98357 To: Jiaxin Yu , broonie@kernel.org Cc: lgirdwood@gmail.com, tiwai@suse.com, robh+dt@kernel.org, matthias.bgg@gmail.com, perex@perex.cz, p.zabel@pengutronix.de, geert+renesas@glider.be, trevor.wu@mediatek.com, tzungbi@google.com, aaronyu@google.com, zhangqilong3@huawei.com, alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org References: <20220217134205.15400-1-jiaxin.yu@mediatek.com> <20220217134205.15400-15-jiaxin.yu@mediatek.com> Content-Language: en-US In-Reply-To: <20220217134205.15400-15-jiaxin.yu@mediatek.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220218_065452_942753_7F4C855C X-CRM114-Status: GOOD ( 28.43 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Il 17/02/22 14:42, Jiaxin Yu ha scritto: > This patch adds support for mt8186 board with mt6366, da7219 and max98357. > > Signed-off-by: Jiaxin Yu > --- > .../mt8186/mt8186-mt6366-da7219-max98357.c | 910 ++++++++++++++++++ > 1 file changed, 910 insertions(+) > create mode 100644 sound/soc/mediatek/mt8186/mt8186-mt6366-da7219-max98357.c > > diff --git a/sound/soc/mediatek/mt8186/mt8186-mt6366-da7219-max98357.c b/sound/soc/mediatek/mt8186/mt8186-mt6366-da7219-max98357.c > new file mode 100644 > index 000000000000..6ba53b8d1e46 > --- /dev/null > +++ b/sound/soc/mediatek/mt8186/mt8186-mt6366-da7219-max98357.c > @@ -0,0 +1,910 @@ > +// SPDX-License-Identifier: GPL-2.0 > +// > +// mt8186-mt6366-da7219-max98357.c > +// -- MT8186-MT6366-DA7219-MAX98357 ALSA SoC machine driver > +// > +// Copyright (c) 2022 MediaTek Inc. > +// Author: Jiaxin Yu > +// > + > +#include > +#include > +#include > +#include > +#include > + > +#include "../../codecs/da7219-aad.h" > +#include "../../codecs/da7219.h" > +#include "../../codecs/mt6358.h" > +#include "../common/mtk-afe-platform-driver.h" > +#include "mt8186-afe-common.h" > +#include "mt8186-afe-clk.h" > +#include "mt8186-afe-gpio.h" > + > +#define DA7219_CODEC_DAI "da7219-hifi" > +#define DA7219_DEV_NAME "da7219.5-001a" > + > +struct mt8186_mt6366_da7219_max98357_priv { > + struct snd_soc_jack headset_jack, hdmi_jack; > +}; > + > +static struct snd_soc_codec_conf mt6366_codec_conf[] = { > + { > + .dlc = COMP_CODEC_CONF("mt6358-sound"), > + .name_prefix = "Mt6366", > + }, > +}; > + > +static int mt8186_da7219_init(struct snd_soc_pcm_runtime *rtd) > +{ > + struct mt8186_mt6366_da7219_max98357_priv *priv = > + snd_soc_card_get_drvdata(rtd->card); > + struct snd_soc_jack *jack = &priv->headset_jack; > + struct snd_soc_component *cmpnt_codec = > + asoc_rtd_to_codec(rtd, 0)->component; > + int ret; > + > + /* Enable Headset and 4 Buttons Jack detection */ > + ret = snd_soc_card_jack_new(rtd->card, "Headset Jack", > + SND_JACK_HEADSET | SND_JACK_BTN_0 | > + SND_JACK_BTN_1 | SND_JACK_BTN_2 | > + SND_JACK_BTN_3 | SND_JACK_LINEOUT, > + jack, NULL, 0); > + if (ret) { > + dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret); > + return ret; > + } > + > + snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE); > + snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOLUMEUP); > + snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEDOWN); > + snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOICECOMMAND); > + > + da7219_aad_jack_det(cmpnt_codec, &priv->headset_jack); > + > + return 0; > +} > + > +static int mt8186_da7219_i2s_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; > + unsigned int rate = params_rate(params); > + unsigned int mclk_fs_ratio = 256; > + unsigned int mclk_fs = rate * mclk_fs_ratio; > + unsigned int freq; > + int ret = 0, j; > + > + ret = snd_soc_dai_set_sysclk(asoc_rtd_to_cpu(rtd, 0), 0, > + mclk_fs, SND_SOC_CLOCK_OUT); > + if (ret < 0) > + dev_err(rtd->dev, "failed to set cpu dai sysclk\n"); Does it really make sense to go on after this failure? > + > + for_each_rtd_codec_dais(rtd, j, codec_dai) { > + if (!strcmp(codec_dai->component->name, DA7219_DEV_NAME)) { > + ret = snd_soc_dai_set_sysclk(codec_dai, > + DA7219_CLKSRC_MCLK, > + mclk_fs, > + SND_SOC_CLOCK_IN); > + if (ret < 0) > + dev_err(rtd->dev, "failed to set sysclk\n"); > + I think that going on past this wouldn't make sense as well, as it may result in unexpected behavior... just return a failure here > + if ((rate % 8000) == 0) > + freq = DA7219_PLL_FREQ_OUT_98304; > + else > + freq = DA7219_PLL_FREQ_OUT_90316; > + > + ret = snd_soc_dai_set_pll(codec_dai, 0, > + DA7219_SYSCLK_PLL_SRM, > + 0, freq); > + if (ret) > + dev_err(rtd->dev, "failed to start PLL: %d\n", > + ret); and here > + } > + } > + So, you've covered all failure cases already, for which, you can simply return 0 here. > + return ret; > +} > + > +static int mt8186_da7219_i2s_hw_free(struct snd_pcm_substream *substream) > +{ > + struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); > + struct snd_soc_dai *codec_dai; > + int ret = 0, j; > + > + for_each_rtd_codec_dais(rtd, j, codec_dai) { > + if (!strcmp(codec_dai->component->name, DA7219_DEV_NAME)) { > + ret = snd_soc_dai_set_pll(codec_dai, > + 0, DA7219_SYSCLK_MCLK, 0, 0); > + if (ret < 0) { > + dev_err(rtd->dev, "failed to stop PLL: %d\n", > + ret); > + break; > + } > + } > + } > + > + return ret; > +} > + > +static const struct snd_soc_ops mt8186_da7219_i2s_ops = { > + .hw_params = mt8186_da7219_i2s_hw_params, > + .hw_free = mt8186_da7219_i2s_hw_free, > +}; > + > +static int mt8186_mt6366_hdmi_init(struct snd_soc_pcm_runtime *rtd) > +{ > + struct snd_soc_component *cmpnt_codec = > + asoc_rtd_to_codec(rtd, 0)->component; > + struct mt8186_mt6366_da7219_max98357_priv *priv = > + snd_soc_card_get_drvdata(rtd->card); > + int ret; > + > + ret = snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT, > + &priv->hdmi_jack, NULL, 0); > + if (ret) { > + dev_err(rtd->dev, "HDMI Jack creation failed: %d\n", ret); > + return ret; > + } > + > + return snd_soc_component_set_jack(cmpnt_codec, &priv->hdmi_jack, NULL); > +} > + > +static int mt8186_mt6366_init(struct snd_soc_pcm_runtime *rtd) > +{ > + struct snd_soc_component *cmpnt_afe = > + snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME); > + struct snd_soc_component *cmpnt_codec = > + asoc_rtd_to_codec(rtd, 0)->component; > + struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe); > + struct mt8186_afe_private *afe_priv = afe->platform_priv; > + struct snd_soc_dapm_context *dapm = &rtd->card->dapm; > + int ret; > + > + /* set mtkaif protocol */ > + mt6358_set_mtkaif_protocol(cmpnt_codec, > + MT6358_MTKAIF_PROTOCOL_1); > + afe_priv->mtkaif_protocol = MT6358_MTKAIF_PROTOCOL_1; > + > + ret = snd_soc_dapm_sync(dapm); > + if (ret) { > + dev_info(rtd->dev, "failed to snd_soc_dapm_sync\n"); dev_err() > + return ret; > + } > + > + return 0; > +} > + > +static int mt8186_i2s_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, > + struct snd_pcm_hw_params *params) > +{ > + struct snd_interval *channels = hw_param_interval(params, > + SNDRV_PCM_HW_PARAM_CHANNELS); > + dev_info(rtd->dev, "%s(), fix format to 32bit\n", __func__); > + dev_dbg() > + /* fix BE i2s channel to 2 channel */ > + channels->min = 2; > + channels->max = 2; > + > + /* fix BE i2s format to S32_LE, clean param mask first */ > + snd_mask_reset_range(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), > + 0, (__force unsigned int)SNDRV_PCM_FORMAT_LAST); > + > + params_set_format(params, SNDRV_PCM_FORMAT_S32_LE); > + > + return 0; > +} > + > +static int mt8186_hdmi_i2s_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, > + struct snd_pcm_hw_params *params) > +{ > + struct snd_interval *channels = hw_param_interval(params, > + SNDRV_PCM_HW_PARAM_CHANNELS); > + dev_info(rtd->dev, "%s(), fix format to 32bit\n", __func__); > + dev_dbg() > + /* fix BE i2s channel to 2 channel */ > + channels->min = 2; > + channels->max = 2; > + > + /* fix BE i2s format to S24_LE, clean param mask first */ > + snd_mask_reset_range(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), > + 0, (__force unsigned int)SNDRV_PCM_FORMAT_LAST); > + > + params_set_format(params, SNDRV_PCM_FORMAT_S24_LE); > + > + return 0; > +} Besides, I would do the following instead: static int mt8186_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params, snd_pcm_format_t fmt) { struct snd_interval *channels = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); dev_dbg(rtd->dev, "%s(), fix format to 32bit\n", __func__); /* fix BE i2s channel to 2 channel */ channels->min = 2; channels->max = 2; /* fix BE i2s format to S32_LE, clean param mask first */ snd_mask_reset_range(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), 0, (__force unsigned int)SNDRV_PCM_FORMAT_LAST); params_set_format(params, fmt); return 0; } static int mt8186_i2s_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params) { return mt8186_hw_params_fixup(rtd, params, SNDRV_PCM_FORMAT_S32_LE); } static int mt8186_hdmi_i2s_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params) { return mt8186_hw_params_fixup(rtd, params, SNDRV_PCM_FORMAT_S24_LE); } ... this reduces code duplication! > + > +/* FE */ > +SND_SOC_DAILINK_DEFS(playback1, > + DAILINK_COMP_ARRAY(COMP_CPU("DL1")), > + DAILINK_COMP_ARRAY(COMP_DUMMY()), > + DAILINK_COMP_ARRAY(COMP_EMPTY())); ..snip.. > +static int mt8186_mt6366_da7219_max98357_dev_probe(struct platform_device *pdev) > +{ > + struct snd_soc_card *card = &mt8186_mt6366_da7219_max98357_soc_card; > + struct snd_soc_dai_link *dai_link; > + struct mt8186_mt6366_da7219_max98357_priv *priv; > + struct device_node *platform_node, *hdmi_codec; > + int ret, i; > + > + dev_info(&pdev->dev, "%s(), ++\n", __func__); > + > + card->dev = &pdev->dev; > + > + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); > + if (!priv) > + return -ENOMEM; > + > + platform_node = of_parse_phandle(pdev->dev.of_node, > + "mediatek,platform", 0); > + if (!platform_node) { > + dev_info(&pdev->dev, > + "Property 'platform' missing or invalid\n"); if (!platform_node) return dev_err_probe(&pdev->dev, -EINVAL, "mediatek,platform missing or invalid\n"); > + return -EINVAL; > + } > + > + hdmi_codec = of_parse_phandle(pdev->dev.of_node, > + "mediatek,hdmi-codec", 0); > + if (!hdmi_codec) { > + dev_info(&pdev->dev, > + "Property 'hdmi' missing or invalid\n"); dev_err() > + return -EINVAL; > + } > + > + for_each_card_prelinks(card, i, dai_link) { > + if (dai_link->platforms->name) > + continue; > + > + if (hdmi_codec && strcmp(dai_link->name, "I2S3") == 0) { > + dai_link->codecs->of_node = hdmi_codec; > + dai_link->ignore = 0; > + } > + > + dai_link->platforms->of_node = platform_node; > + } > + > + snd_soc_card_set_drvdata(card, priv); > + > + /* init gpio */ > + ret = mt8186_afe_gpio_init(&pdev->dev); > + if (ret) > + dev_info(&pdev->dev, "init gpio error\n"); dev_err() and goto end; > + > + dev_info(&pdev->dev, "%s(), devm_snd_soc_register_card\n", __func__); > + ret = devm_snd_soc_register_card(&pdev->dev, card); > + if (ret) > + dev_info(&pdev->dev, "%s snd_soc_register_card fail %d\n", > + __func__, ret); dev_err_probe() end: > + of_node_put(platform_node); > + of_node_put(hdmi_codec); > + > + return ret; > +} > + > +#if IS_ENABLED(CONFIG_OF) > +static const struct of_device_id mt8186_mt6366_da7219_max98357_dt_match[] = { > + {.compatible = "mediatek,mt8186_mt6366_da7219_max98357_sound",}, > + {} > +}; > +#endif > + > +static struct platform_driver mt8186_mt6366_da7219_max98357_driver = { > + .driver = { > + .name = "mt8186_mt6366_da7219_max98357", > +#if IS_ENABLED(CONFIG_OF) > + .of_match_table = mt8186_mt6366_da7219_max98357_dt_match, > +#endif > + .pm = &snd_soc_pm_ops, > + }, > + .probe = mt8186_mt6366_da7219_max98357_dev_probe, > +}; > + > +module_platform_driver(mt8186_mt6366_da7219_max98357_driver); > + > +/* Module information */ > +MODULE_DESCRIPTION("MT8186-MT6366-DA7219-MAX98357 ALSA SoC machine driver"); > +MODULE_AUTHOR("Jiaxin Yu "); > +MODULE_LICENSE("GPL v2"); > +MODULE_ALIAS("mt8186_mt6366_da7219_max98357 soc card"); _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel