From patchwork Sun Apr 23 23:20:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabio Estevam X-Patchwork-Id: 9695331 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 8BFEF602A7 for ; Sun, 23 Apr 2017 23:21:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5ED0E2029C for ; Sun, 23 Apr 2017 23:21:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 41283262AE; Sun, 23 Apr 2017 23:21:01 +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 3BF332029C for ; Sun, 23 Apr 2017 23:20:59 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id B4283266C5C; Mon, 24 Apr 2017 01:20:57 +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 36FCB266C5D; Mon, 24 Apr 2017 01:20:53 +0200 (CEST) Received: from mail-qk0-f194.google.com (mail-qk0-f194.google.com [209.85.220.194]) by alsa0.perex.cz (Postfix) with ESMTP id 1FDE0266AF7 for ; Mon, 24 Apr 2017 01:20:46 +0200 (CEST) Received: by mail-qk0-f194.google.com with SMTP id a19so741834qkg.2 for ; Sun, 23 Apr 2017 16:20:46 -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=Mu0CPnzxDci7yVA5/jf8Mp3tV67ejM6Dm+4f5cz+s8s=; b=USytqqeDV20gkddD28r2h/iVPbj3jLrzAwLsNBN2FpMfu8gzUYYATyGB16PtFkrJ1a NZhG6Sj4rnFejZz5L9K6Gs88UZdKPdIQ99CsROZoxz3Q6Cf10sj0Do4G+0OUAhZYJ9cM xWZKIo+ewMaLLSNCZ5L4W+4i9MOxQj1x+NI07+J0IjgikpGzp6+h7JYkibBwACrumaZK LVcUVeXBUNp9vTYO/K0VRzEA33n0umxrm7VGWGMj+kOmjN8Ns9cB5gX7BXeC97/5KdWX PeyweBZAXIzZDR69b03f7p45cE+uT2yVLvmhcJTzt3j2GfaDu7EvyPUNW0d6e8iJG7Qv MRBg== 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=Mu0CPnzxDci7yVA5/jf8Mp3tV67ejM6Dm+4f5cz+s8s=; b=pI4xI50kBz+jOEc4EPY/C6qSX7ev6h3Q26tgUlhx5guMvPiD0gCjYqytW4fGXrfJ3H 5pDWqQN52bokPNi90HvUfaUWsluYkL/e6JxMQaKFx7ELQYkGKgAF8sZBInYb2SRTKapu UKvtyYrsRaKNmw9kBjaPoGTrNW7H95Uwy0uM/l2QuGy9yKmqbdmkk195j0nNAe8RCbk9 5Xw1hFRKukT/zFRXaE/52T/4J6wbqK53PbH07Tvcm/mkT1hdlxtsScYUjKKzdeO6guoP E8mwbxE4qG/Ub0T25U2f+aAO+uBbGCQ4lzq1rskPc/bLOq/7VbgxwahIZus3eM0YsmT9 6Avw== X-Gm-Message-State: AN3rC/5BHTAwJAKy6OC6BIkdB3/GRADklT7ggtQ4eo5p1clTLSGpAyHJ b22B6nPvM9Z2Lw== X-Received: by 10.55.43.168 with SMTP id r40mr23362127qkr.59.1492989645560; Sun, 23 Apr 2017 16:20:45 -0700 (PDT) Received: from localhost.localdomain ([187.180.187.30]) by smtp.gmail.com with ESMTPSA id 1sm11659476qtb.40.2017.04.23.16.20.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 23 Apr 2017 16:20:45 -0700 (PDT) From: Fabio Estevam To: broonie@kernel.org Date: Sun, 23 Apr 2017 20:20:33 -0300 Message-Id: <1492989633-19909-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 v2] 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 --- Changes since v1: - Keep the original variable types for sample_rate and sample_format. 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..206b898 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; + int sample_rate; + snd_pcm_format_t 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) {