diff options
author | Sylwester Nawrocki <s.nawrocki@samsung.com> | 2016-10-25 06:57:57 -0400 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2016-10-25 09:06:19 -0400 |
commit | 892ccf0f2173a9ede5448411e9475616fb21fb51 (patch) | |
tree | 44cf5c863b09d03bce98c3b65c2338e66ea4072f | |
parent | 5faf071d08ddd1c1be66deaa93a09ccf43f5b538 (diff) |
ASoC: s3c24xx_uda134x: Move global variables to driver's data structure
Gather all driver's private variables in common data structure
and allocate the data structure dynamically.
Also unused ENFORCE_RATES symbol and local variable (leftovers
from an erroneous rebase) are removed.
Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r-- | sound/soc/samsung/s3c24xx_uda134x.c | 79 |
1 files changed, 43 insertions, 36 deletions
diff --git a/sound/soc/samsung/s3c24xx_uda134x.c b/sound/soc/samsung/s3c24xx_uda134x.c index 7853fbe6ccc9..81a78940967c 100644 --- a/sound/soc/samsung/s3c24xx_uda134x.c +++ b/sound/soc/samsung/s3c24xx_uda134x.c | |||
@@ -19,9 +19,15 @@ | |||
19 | #include <sound/s3c24xx_uda134x.h> | 19 | #include <sound/s3c24xx_uda134x.h> |
20 | 20 | ||
21 | #include "regs-iis.h" | 21 | #include "regs-iis.h" |
22 | |||
23 | #include "s3c24xx-i2s.h" | 22 | #include "s3c24xx-i2s.h" |
24 | 23 | ||
24 | struct s3c24xx_uda134x { | ||
25 | struct clk *xtal; | ||
26 | struct clk *pclk; | ||
27 | struct mutex clk_lock; | ||
28 | int clk_users; | ||
29 | }; | ||
30 | |||
25 | /* #define ENFORCE_RATES 1 */ | 31 | /* #define ENFORCE_RATES 1 */ |
26 | /* | 32 | /* |
27 | Unfortunately the S3C24XX in master mode has a limited capacity of | 33 | Unfortunately the S3C24XX in master mode has a limited capacity of |
@@ -36,15 +42,6 @@ | |||
36 | possible an error will be returned. | 42 | possible an error will be returned. |
37 | */ | 43 | */ |
38 | 44 | ||
39 | static struct clk *xtal; | ||
40 | static struct clk *pclk; | ||
41 | /* this is need because we don't have a place where to keep the | ||
42 | * pointers to the clocks in each substream. We get the clocks only | ||
43 | * when we are actually using them so we don't block stuff like | ||
44 | * frequency change or oscillator power-off */ | ||
45 | static int clk_users; | ||
46 | static DEFINE_MUTEX(clk_lock); | ||
47 | |||
48 | static unsigned int rates[33 * 2]; | 45 | static unsigned int rates[33 * 2]; |
49 | #ifdef ENFORCE_RATES | 46 | #ifdef ENFORCE_RATES |
50 | static struct snd_pcm_hw_constraint_list hw_constraints_rates = { | 47 | static struct snd_pcm_hw_constraint_list hw_constraints_rates = { |
@@ -57,26 +54,24 @@ static struct snd_pcm_hw_constraint_list hw_constraints_rates = { | |||
57 | static int s3c24xx_uda134x_startup(struct snd_pcm_substream *substream) | 54 | static int s3c24xx_uda134x_startup(struct snd_pcm_substream *substream) |
58 | { | 55 | { |
59 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 56 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
57 | struct s3c24xx_uda134x *priv = snd_soc_card_get_drvdata(rtd->card); | ||
60 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; | 58 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
61 | #ifdef ENFORCE_RATES | ||
62 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
63 | #endif | ||
64 | int ret = 0; | 59 | int ret = 0; |
65 | 60 | ||
66 | mutex_lock(&clk_lock); | 61 | mutex_lock(&priv->clk_lock); |
67 | 62 | ||
68 | if (clk_users == 0) { | 63 | if (priv->clk_users == 0) { |
69 | xtal = clk_get(rtd->dev, "xtal"); | 64 | priv->xtal = clk_get(rtd->dev, "xtal"); |
70 | if (IS_ERR(xtal)) { | 65 | if (IS_ERR(priv->xtal)) { |
71 | dev_err(rtd->dev, "%s cannot get xtal\n", __func__); | 66 | dev_err(rtd->dev, "%s cannot get xtal\n", __func__); |
72 | ret = PTR_ERR(xtal); | 67 | ret = PTR_ERR(priv->xtal); |
73 | } else { | 68 | } else { |
74 | pclk = clk_get(cpu_dai->dev, "iis"); | 69 | priv->pclk = clk_get(cpu_dai->dev, "iis"); |
75 | if (IS_ERR(pclk)) { | 70 | if (IS_ERR(priv->pclk)) { |
76 | dev_err(rtd->dev, "%s cannot get pclk\n", | 71 | dev_err(rtd->dev, "%s cannot get pclk\n", |
77 | __func__); | 72 | __func__); |
78 | clk_put(xtal); | 73 | clk_put(priv->xtal); |
79 | ret = PTR_ERR(pclk); | 74 | ret = PTR_ERR(priv->pclk); |
80 | } | 75 | } |
81 | } | 76 | } |
82 | if (!ret) { | 77 | if (!ret) { |
@@ -85,18 +80,19 @@ static int s3c24xx_uda134x_startup(struct snd_pcm_substream *substream) | |||
85 | for (i = 0; i < 2; i++) { | 80 | for (i = 0; i < 2; i++) { |
86 | int fs = i ? 256 : 384; | 81 | int fs = i ? 256 : 384; |
87 | 82 | ||
88 | rates[i*33] = clk_get_rate(xtal) / fs; | 83 | rates[i*33] = clk_get_rate(priv->xtal) / fs; |
89 | for (j = 1; j < 33; j++) | 84 | for (j = 1; j < 33; j++) |
90 | rates[i*33 + j] = clk_get_rate(pclk) / | 85 | rates[i*33 + j] = clk_get_rate(priv->pclk) / |
91 | (j * fs); | 86 | (j * fs); |
92 | } | 87 | } |
93 | } | 88 | } |
94 | } | 89 | } |
95 | clk_users += 1; | 90 | priv->clk_users += 1; |
96 | mutex_unlock(&clk_lock); | 91 | mutex_unlock(&priv->clk_lock); |
92 | |||
97 | if (!ret) { | 93 | if (!ret) { |
98 | #ifdef ENFORCE_RATES | 94 | #ifdef ENFORCE_RATES |
99 | ret = snd_pcm_hw_constraint_list(runtime, 0, | 95 | ret = snd_pcm_hw_constraint_list(substream->runtime, 0, |
100 | SNDRV_PCM_HW_PARAM_RATE, | 96 | SNDRV_PCM_HW_PARAM_RATE, |
101 | &hw_constraints_rates); | 97 | &hw_constraints_rates); |
102 | if (ret < 0) | 98 | if (ret < 0) |
@@ -109,15 +105,18 @@ static int s3c24xx_uda134x_startup(struct snd_pcm_substream *substream) | |||
109 | 105 | ||
110 | static void s3c24xx_uda134x_shutdown(struct snd_pcm_substream *substream) | 106 | static void s3c24xx_uda134x_shutdown(struct snd_pcm_substream *substream) |
111 | { | 107 | { |
112 | mutex_lock(&clk_lock); | 108 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
113 | clk_users -= 1; | 109 | struct s3c24xx_uda134x *priv = snd_soc_card_get_drvdata(rtd->card); |
114 | if (clk_users == 0) { | 110 | |
115 | clk_put(xtal); | 111 | mutex_lock(&priv->clk_lock); |
116 | xtal = NULL; | 112 | priv->clk_users -= 1; |
117 | clk_put(pclk); | 113 | if (priv->clk_users == 0) { |
118 | pclk = NULL; | 114 | clk_put(priv->xtal); |
115 | priv->xtal = NULL; | ||
116 | clk_put(priv->pclk); | ||
117 | priv->pclk = NULL; | ||
119 | } | 118 | } |
120 | mutex_unlock(&clk_lock); | 119 | mutex_unlock(&priv->clk_lock); |
121 | } | 120 | } |
122 | 121 | ||
123 | static int s3c24xx_uda134x_hw_params(struct snd_pcm_substream *substream, | 122 | static int s3c24xx_uda134x_hw_params(struct snd_pcm_substream *substream, |
@@ -228,10 +227,18 @@ static struct snd_soc_card snd_soc_s3c24xx_uda134x = { | |||
228 | static int s3c24xx_uda134x_probe(struct platform_device *pdev) | 227 | static int s3c24xx_uda134x_probe(struct platform_device *pdev) |
229 | { | 228 | { |
230 | struct snd_soc_card *card = &snd_soc_s3c24xx_uda134x; | 229 | struct snd_soc_card *card = &snd_soc_s3c24xx_uda134x; |
230 | struct s3c24xx_uda134x *priv; | ||
231 | int ret; | 231 | int ret; |
232 | 232 | ||
233 | platform_set_drvdata(pdev, card); | 233 | priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); |
234 | if (!priv) | ||
235 | return -ENOMEM; | ||
236 | |||
237 | mutex_init(&priv->clk_lock); | ||
238 | |||
234 | card->dev = &pdev->dev; | 239 | card->dev = &pdev->dev; |
240 | platform_set_drvdata(pdev, card); | ||
241 | snd_soc_card_set_drvdata(card, priv); | ||
235 | 242 | ||
236 | ret = devm_snd_soc_register_card(&pdev->dev, card); | 243 | ret = devm_snd_soc_register_card(&pdev->dev, card); |
237 | if (ret) | 244 | if (ret) |