From patchwork Sun Apr 23 22:12:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabio Estevam X-Patchwork-Id: 9695297 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 D4B7C6037D for ; Sun, 23 Apr 2017 22:13:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D146209CD for ; Sun, 23 Apr 2017 22:13:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7F02B26538; Sun, 23 Apr 2017 22:13:39 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM, 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 35183209CD for ; Sun, 23 Apr 2017 22:13:37 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id B0090266C2E; Mon, 24 Apr 2017 00:13:35 +0200 (CEST) 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 9F56A266C41; Mon, 24 Apr 2017 00:13:33 +0200 (CEST) Received: from mail-qt0-f194.google.com (mail-qt0-f194.google.com [209.85.216.194]) by alsa0.perex.cz (Postfix) with ESMTP id 89111266AF7 for ; Mon, 24 Apr 2017 00:13:31 +0200 (CEST) Received: by mail-qt0-f194.google.com with SMTP id y33so18201180qta.1 for ; Sun, 23 Apr 2017 15:13:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=HlomYyD1lPx3oDaJ69kvjvsgs5OSYXK79BYNq6StQm8=; b=GJUBQgaPjKi121YLiLe9OIE9oaxzDHldZF5A4SVkwm+KCnBUA/MLwnjEX4AsKX8lS2 Df/JR+fUxbqr9u69JRYNrIZZZjrfBZuchnEs/Q2OKCMuSDwy8CwtdIXDCoJuGpVWN28r QK8fg0LNZLGh5BBm1+60O6v5o1kS7XXYEQKv+J7oq75bYm4+rKZlf45/J5b2weTGOpRo Ra3/zdfQ3vRbrwcHvWfGdbbU4XKjmnWXn5Nxg+zOWQXoHYVVA79vqgAslMGD3jAt+J+V 9h1omn4834XRBZ/DReaj/glBoTWfTDq2Vm2OqIhfWT+GPYUM2ZiMzHlsAkowByVzgOVP Lhlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=HlomYyD1lPx3oDaJ69kvjvsgs5OSYXK79BYNq6StQm8=; b=FgBrNB7CFqQT0XYhbWioxjbtw/jw7RH5NlwlO1PFxp1yawu14z2xlKeVXNPzy7DTLY vZ2vO7jllA3/tl+ZBVEyetifqcBIKKDALKYnDeYDLWdzs0N5hGQ7YIRBaK8VGym1eFbg 6qKzxYinfOrRuV98IpyugrM2N62VDB2oQ/nlYdYBxwFjv/8hFzaMrWIeoci3L0oPVAmJ 84PxGgrc7SCExGI2oGA2IEzqP6GpJRJkz3rlNXMzzJgPHpCZ5G/RJGNEIenvgK616Wap hRtZ4B8tC4T+nAR5CNxCZrRF9idEwk0wezNzKwGg7DBS1IMyQPs5d4EdiGp0DpBx3dNb 35IA== X-Gm-Message-State: AN3rC/7BOhq1TueVwNN0Z+iANhupc8xBW4gEpIl7TwNYoVKcKP4iluk1 fx6iZvyAzZ++5w== X-Received: by 10.237.36.105 with SMTP id s38mr24800897qtc.185.1492985609993; Sun, 23 Apr 2017 15:13:29 -0700 (PDT) Received: from localhost.localdomain ([187.180.187.30]) by smtp.gmail.com with ESMTPSA id m12sm11566522qtf.2.2017.04.23.15.13.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 23 Apr 2017 15:13:29 -0700 (PDT) From: Fabio Estevam To: broonie@kernel.org Date: Sun, 23 Apr 2017 19:12:57 -0300 Message-Id: <1492985577-14731-1-git-send-email-festevam@gmail.com> X-Mailer: git-send-email 2.7.4 Cc: nicoleotsuka@gmail.com, Fabio Estevam , alsa-devel@alsa-project.org, timur@tabi.org Subject: [alsa-devel] [PATCH] ASoC: imx-wm8962: Remove global variables 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: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP From: Fabio Estevam Currently the following variables are global: - card_priv, sample_rate and sample_format ,which is not a good idea as it prevents the usage of multiple instances. Make sample_rate and sample_format part of the imx_priv structure and allocate imx_priv via the standard devm_kzalloc() mechanism inside the probe function. Signed-off-by: Fabio Estevam --- sound/soc/fsl/imx-wm8962.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/sound/soc/fsl/imx-wm8962.c b/sound/soc/fsl/imx-wm8962.c index 52659fa..fbeada7 100644 --- a/sound/soc/fsl/imx-wm8962.c +++ b/sound/soc/fsl/imx-wm8962.c @@ -38,8 +38,9 @@ struct imx_wm8962_data { struct imx_priv { struct platform_device *pdev; + u32 sample_rate; + u32 sample_format; }; -static struct imx_priv card_priv; static const struct snd_soc_dapm_widget imx_wm8962_dapm_widgets[] = { SND_SOC_DAPM_HP("Headphone Jack", NULL), @@ -48,14 +49,14 @@ static const struct snd_soc_dapm_widget imx_wm8962_dapm_widgets[] = { SND_SOC_DAPM_MIC("DMIC", NULL), }; -static int sample_rate = 44100; -static snd_pcm_format_t sample_format = SNDRV_PCM_FORMAT_S16_LE; - static int imx_hifi_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params) { - sample_rate = params_rate(params); - sample_format = params_format(params); + struct snd_soc_pcm_runtime *rtd = substream->private_data; + struct imx_priv *priv = snd_soc_card_get_drvdata(rtd->card); + + priv->sample_rate = params_rate(params); + priv->sample_format = params_format(params); return 0; } @@ -70,7 +71,7 @@ static int imx_wm8962_set_bias_level(struct snd_soc_card *card, { struct snd_soc_pcm_runtime *rtd; struct snd_soc_dai *codec_dai; - struct imx_priv *priv = &card_priv; + struct imx_priv *priv = snd_soc_card_get_drvdata(card); struct imx_wm8962_data *data = snd_soc_card_get_drvdata(card); struct device *dev = &priv->pdev->dev; unsigned int pll_out; @@ -84,10 +85,10 @@ static int imx_wm8962_set_bias_level(struct snd_soc_card *card, switch (level) { case SND_SOC_BIAS_PREPARE: if (dapm->bias_level == SND_SOC_BIAS_STANDBY) { - if (sample_format == SNDRV_PCM_FORMAT_S24_LE) - pll_out = sample_rate * 384; + if (priv->sample_format == SNDRV_PCM_FORMAT_S24_LE) + pll_out = priv->sample_rate * 384; else - pll_out = sample_rate * 256; + pll_out = priv->sample_rate * 256; ret = snd_soc_dai_set_pll(codec_dai, WM8962_FLL, WM8962_FLL_MCLK, data->clk_frequency, @@ -139,7 +140,7 @@ static int imx_wm8962_late_probe(struct snd_soc_card *card) { struct snd_soc_pcm_runtime *rtd; struct snd_soc_dai *codec_dai; - struct imx_priv *priv = &card_priv; + struct imx_priv *priv = snd_soc_card_get_drvdata(card); struct imx_wm8962_data *data = snd_soc_card_get_drvdata(card); struct device *dev = &priv->pdev->dev; int ret; @@ -159,14 +160,20 @@ static int imx_wm8962_probe(struct platform_device *pdev) struct device_node *np = pdev->dev.of_node; struct device_node *ssi_np, *codec_np; struct platform_device *ssi_pdev; - struct imx_priv *priv = &card_priv; struct i2c_client *codec_dev; struct imx_wm8962_data *data; + struct imx_priv *priv; struct clk *codec_clk; int int_port, ext_port; int ret; + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + priv->pdev = pdev; + priv->sample_rate = 44100; + priv->sample_format = SNDRV_PCM_FORMAT_S16_LE; ret = of_property_read_u32(np, "mux-int-port", &int_port); if (ret) {