diff options
author | Fabio Estevam <fabio.estevam@nxp.com> | 2017-04-23 19:20:33 -0400 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2017-04-24 13:45:18 -0400 |
commit | 8f7206d69ab8c8fb8620566338d54c4b9b80477a (patch) | |
tree | 9a32136575eb08a63d2b535e772a6991e2721334 | |
parent | db22d189453cee666f8da2e67419f14f4b2fd9d1 (diff) |
ASoC: imx-wm8962: Remove global variables
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 <fabio.estevam@nxp.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r-- | sound/soc/fsl/imx-wm8962.c | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/sound/soc/fsl/imx-wm8962.c b/sound/soc/fsl/imx-wm8962.c index 52659faa2eb9..206b898e554c 100644 --- a/sound/soc/fsl/imx-wm8962.c +++ b/sound/soc/fsl/imx-wm8962.c | |||
@@ -38,8 +38,9 @@ struct imx_wm8962_data { | |||
38 | 38 | ||
39 | struct imx_priv { | 39 | struct imx_priv { |
40 | struct platform_device *pdev; | 40 | struct platform_device *pdev; |
41 | int sample_rate; | ||
42 | snd_pcm_format_t sample_format; | ||
41 | }; | 43 | }; |
42 | static struct imx_priv card_priv; | ||
43 | 44 | ||
44 | static const struct snd_soc_dapm_widget imx_wm8962_dapm_widgets[] = { | 45 | static const struct snd_soc_dapm_widget imx_wm8962_dapm_widgets[] = { |
45 | SND_SOC_DAPM_HP("Headphone Jack", NULL), | 46 | SND_SOC_DAPM_HP("Headphone Jack", NULL), |
@@ -48,14 +49,14 @@ static const struct snd_soc_dapm_widget imx_wm8962_dapm_widgets[] = { | |||
48 | SND_SOC_DAPM_MIC("DMIC", NULL), | 49 | SND_SOC_DAPM_MIC("DMIC", NULL), |
49 | }; | 50 | }; |
50 | 51 | ||
51 | static int sample_rate = 44100; | ||
52 | static snd_pcm_format_t sample_format = SNDRV_PCM_FORMAT_S16_LE; | ||
53 | |||
54 | static int imx_hifi_hw_params(struct snd_pcm_substream *substream, | 52 | static int imx_hifi_hw_params(struct snd_pcm_substream *substream, |
55 | struct snd_pcm_hw_params *params) | 53 | struct snd_pcm_hw_params *params) |
56 | { | 54 | { |
57 | sample_rate = params_rate(params); | 55 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
58 | sample_format = params_format(params); | 56 | struct imx_priv *priv = snd_soc_card_get_drvdata(rtd->card); |
57 | |||
58 | priv->sample_rate = params_rate(params); | ||
59 | priv->sample_format = params_format(params); | ||
59 | 60 | ||
60 | return 0; | 61 | return 0; |
61 | } | 62 | } |
@@ -70,7 +71,7 @@ static int imx_wm8962_set_bias_level(struct snd_soc_card *card, | |||
70 | { | 71 | { |
71 | struct snd_soc_pcm_runtime *rtd; | 72 | struct snd_soc_pcm_runtime *rtd; |
72 | struct snd_soc_dai *codec_dai; | 73 | struct snd_soc_dai *codec_dai; |
73 | struct imx_priv *priv = &card_priv; | 74 | struct imx_priv *priv = snd_soc_card_get_drvdata(card); |
74 | struct imx_wm8962_data *data = snd_soc_card_get_drvdata(card); | 75 | struct imx_wm8962_data *data = snd_soc_card_get_drvdata(card); |
75 | struct device *dev = &priv->pdev->dev; | 76 | struct device *dev = &priv->pdev->dev; |
76 | unsigned int pll_out; | 77 | unsigned int pll_out; |
@@ -84,10 +85,10 @@ static int imx_wm8962_set_bias_level(struct snd_soc_card *card, | |||
84 | switch (level) { | 85 | switch (level) { |
85 | case SND_SOC_BIAS_PREPARE: | 86 | case SND_SOC_BIAS_PREPARE: |
86 | if (dapm->bias_level == SND_SOC_BIAS_STANDBY) { | 87 | if (dapm->bias_level == SND_SOC_BIAS_STANDBY) { |
87 | if (sample_format == SNDRV_PCM_FORMAT_S24_LE) | 88 | if (priv->sample_format == SNDRV_PCM_FORMAT_S24_LE) |
88 | pll_out = sample_rate * 384; | 89 | pll_out = priv->sample_rate * 384; |
89 | else | 90 | else |
90 | pll_out = sample_rate * 256; | 91 | pll_out = priv->sample_rate * 256; |
91 | 92 | ||
92 | ret = snd_soc_dai_set_pll(codec_dai, WM8962_FLL, | 93 | ret = snd_soc_dai_set_pll(codec_dai, WM8962_FLL, |
93 | WM8962_FLL_MCLK, data->clk_frequency, | 94 | WM8962_FLL_MCLK, data->clk_frequency, |
@@ -139,7 +140,7 @@ static int imx_wm8962_late_probe(struct snd_soc_card *card) | |||
139 | { | 140 | { |
140 | struct snd_soc_pcm_runtime *rtd; | 141 | struct snd_soc_pcm_runtime *rtd; |
141 | struct snd_soc_dai *codec_dai; | 142 | struct snd_soc_dai *codec_dai; |
142 | struct imx_priv *priv = &card_priv; | 143 | struct imx_priv *priv = snd_soc_card_get_drvdata(card); |
143 | struct imx_wm8962_data *data = snd_soc_card_get_drvdata(card); | 144 | struct imx_wm8962_data *data = snd_soc_card_get_drvdata(card); |
144 | struct device *dev = &priv->pdev->dev; | 145 | struct device *dev = &priv->pdev->dev; |
145 | int ret; | 146 | int ret; |
@@ -159,14 +160,20 @@ static int imx_wm8962_probe(struct platform_device *pdev) | |||
159 | struct device_node *np = pdev->dev.of_node; | 160 | struct device_node *np = pdev->dev.of_node; |
160 | struct device_node *ssi_np, *codec_np; | 161 | struct device_node *ssi_np, *codec_np; |
161 | struct platform_device *ssi_pdev; | 162 | struct platform_device *ssi_pdev; |
162 | struct imx_priv *priv = &card_priv; | ||
163 | struct i2c_client *codec_dev; | 163 | struct i2c_client *codec_dev; |
164 | struct imx_wm8962_data *data; | 164 | struct imx_wm8962_data *data; |
165 | struct imx_priv *priv; | ||
165 | struct clk *codec_clk; | 166 | struct clk *codec_clk; |
166 | int int_port, ext_port; | 167 | int int_port, ext_port; |
167 | int ret; | 168 | int ret; |
168 | 169 | ||
170 | priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); | ||
171 | if (!priv) | ||
172 | return -ENOMEM; | ||
173 | |||
169 | priv->pdev = pdev; | 174 | priv->pdev = pdev; |
175 | priv->sample_rate = 44100; | ||
176 | priv->sample_format = SNDRV_PCM_FORMAT_S16_LE; | ||
170 | 177 | ||
171 | ret = of_property_read_u32(np, "mux-int-port", &int_port); | 178 | ret = of_property_read_u32(np, "mux-int-port", &int_port); |
172 | if (ret) { | 179 | if (ret) { |