aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/codecs/wm8728.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/soc/codecs/wm8728.c')
-rw-r--r--sound/soc/codecs/wm8728.c50
1 files changed, 19 insertions, 31 deletions
diff --git a/sound/soc/codecs/wm8728.c b/sound/soc/codecs/wm8728.c
index 80b11983e137..e7ff2121ede9 100644
--- a/sound/soc/codecs/wm8728.c
+++ b/sound/soc/codecs/wm8728.c
@@ -47,7 +47,7 @@ static inline unsigned int wm8728_read_reg_cache(struct snd_soc_codec *codec,
47 unsigned int reg) 47 unsigned int reg)
48{ 48{
49 u16 *cache = codec->reg_cache; 49 u16 *cache = codec->reg_cache;
50 BUG_ON(reg > ARRAY_SIZE(wm8728_reg_defaults)); 50 BUG_ON(reg >= ARRAY_SIZE(wm8728_reg_defaults));
51 return cache[reg]; 51 return cache[reg];
52} 52}
53 53
@@ -55,7 +55,7 @@ static inline void wm8728_write_reg_cache(struct snd_soc_codec *codec,
55 u16 reg, unsigned int value) 55 u16 reg, unsigned int value)
56{ 56{
57 u16 *cache = codec->reg_cache; 57 u16 *cache = codec->reg_cache;
58 BUG_ON(reg > ARRAY_SIZE(wm8728_reg_defaults)); 58 BUG_ON(reg >= ARRAY_SIZE(wm8728_reg_defaults));
59 cache[reg] = value; 59 cache[reg] = value;
60} 60}
61 61
@@ -92,21 +92,6 @@ SOC_DOUBLE_R_TLV("Digital Playback Volume", WM8728_DACLVOL, WM8728_DACRVOL,
92SOC_SINGLE("Deemphasis", WM8728_DACCTL, 1, 1, 0), 92SOC_SINGLE("Deemphasis", WM8728_DACCTL, 1, 1, 0),
93}; 93};
94 94
95static int wm8728_add_controls(struct snd_soc_codec *codec)
96{
97 int err, i;
98
99 for (i = 0; i < ARRAY_SIZE(wm8728_snd_controls); i++) {
100 err = snd_ctl_add(codec->card,
101 snd_soc_cnew(&wm8728_snd_controls[i],
102 codec, NULL));
103 if (err < 0)
104 return err;
105 }
106
107 return 0;
108}
109
110/* 95/*
111 * DAPM controls. 96 * DAPM controls.
112 */ 97 */
@@ -152,7 +137,7 @@ static int wm8728_hw_params(struct snd_pcm_substream *substream,
152{ 137{
153 struct snd_soc_pcm_runtime *rtd = substream->private_data; 138 struct snd_soc_pcm_runtime *rtd = substream->private_data;
154 struct snd_soc_device *socdev = rtd->socdev; 139 struct snd_soc_device *socdev = rtd->socdev;
155 struct snd_soc_codec *codec = socdev->codec; 140 struct snd_soc_codec *codec = socdev->card->codec;
156 u16 dac = wm8728_read_reg_cache(codec, WM8728_DACCTL); 141 u16 dac = wm8728_read_reg_cache(codec, WM8728_DACCTL);
157 142
158 dac &= ~0x18; 143 dac &= ~0x18;
@@ -259,6 +244,12 @@ static int wm8728_set_bias_level(struct snd_soc_codec *codec,
259#define WM8728_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ 244#define WM8728_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
260 SNDRV_PCM_FMTBIT_S24_LE) 245 SNDRV_PCM_FMTBIT_S24_LE)
261 246
247static struct snd_soc_dai_ops wm8728_dai_ops = {
248 .hw_params = wm8728_hw_params,
249 .digital_mute = wm8728_mute,
250 .set_fmt = wm8728_set_dai_fmt,
251};
252
262struct snd_soc_dai wm8728_dai = { 253struct snd_soc_dai wm8728_dai = {
263 .name = "WM8728", 254 .name = "WM8728",
264 .playback = { 255 .playback = {
@@ -268,18 +259,14 @@ struct snd_soc_dai wm8728_dai = {
268 .rates = WM8728_RATES, 259 .rates = WM8728_RATES,
269 .formats = WM8728_FORMATS, 260 .formats = WM8728_FORMATS,
270 }, 261 },
271 .ops = { 262 .ops = &wm8728_dai_ops,
272 .hw_params = wm8728_hw_params,
273 .digital_mute = wm8728_mute,
274 .set_fmt = wm8728_set_dai_fmt,
275 }
276}; 263};
277EXPORT_SYMBOL_GPL(wm8728_dai); 264EXPORT_SYMBOL_GPL(wm8728_dai);
278 265
279static int wm8728_suspend(struct platform_device *pdev, pm_message_t state) 266static int wm8728_suspend(struct platform_device *pdev, pm_message_t state)
280{ 267{
281 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 268 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
282 struct snd_soc_codec *codec = socdev->codec; 269 struct snd_soc_codec *codec = socdev->card->codec;
283 270
284 wm8728_set_bias_level(codec, SND_SOC_BIAS_OFF); 271 wm8728_set_bias_level(codec, SND_SOC_BIAS_OFF);
285 272
@@ -289,7 +276,7 @@ static int wm8728_suspend(struct platform_device *pdev, pm_message_t state)
289static int wm8728_resume(struct platform_device *pdev) 276static int wm8728_resume(struct platform_device *pdev)
290{ 277{
291 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 278 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
292 struct snd_soc_codec *codec = socdev->codec; 279 struct snd_soc_codec *codec = socdev->card->codec;
293 280
294 wm8728_set_bias_level(codec, codec->suspend_bias_level); 281 wm8728_set_bias_level(codec, codec->suspend_bias_level);
295 282
@@ -302,7 +289,7 @@ static int wm8728_resume(struct platform_device *pdev)
302 */ 289 */
303static int wm8728_init(struct snd_soc_device *socdev) 290static int wm8728_init(struct snd_soc_device *socdev)
304{ 291{
305 struct snd_soc_codec *codec = socdev->codec; 292 struct snd_soc_codec *codec = socdev->card->codec;
306 int ret = 0; 293 int ret = 0;
307 294
308 codec->name = "WM8728"; 295 codec->name = "WM8728";
@@ -330,7 +317,8 @@ static int wm8728_init(struct snd_soc_device *socdev)
330 /* power on device */ 317 /* power on device */
331 wm8728_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 318 wm8728_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
332 319
333 wm8728_add_controls(codec); 320 snd_soc_add_controls(codec, wm8728_snd_controls,
321 ARRAY_SIZE(wm8728_snd_controls));
334 wm8728_add_widgets(codec); 322 wm8728_add_widgets(codec);
335 ret = snd_soc_init_card(socdev); 323 ret = snd_soc_init_card(socdev);
336 if (ret < 0) { 324 if (ret < 0) {
@@ -363,7 +351,7 @@ static int wm8728_i2c_probe(struct i2c_client *i2c,
363 const struct i2c_device_id *id) 351 const struct i2c_device_id *id)
364{ 352{
365 struct snd_soc_device *socdev = wm8728_socdev; 353 struct snd_soc_device *socdev = wm8728_socdev;
366 struct snd_soc_codec *codec = socdev->codec; 354 struct snd_soc_codec *codec = socdev->card->codec;
367 int ret; 355 int ret;
368 356
369 i2c_set_clientdata(i2c, codec); 357 i2c_set_clientdata(i2c, codec);
@@ -444,7 +432,7 @@ err_driver:
444static int __devinit wm8728_spi_probe(struct spi_device *spi) 432static int __devinit wm8728_spi_probe(struct spi_device *spi)
445{ 433{
446 struct snd_soc_device *socdev = wm8728_socdev; 434 struct snd_soc_device *socdev = wm8728_socdev;
447 struct snd_soc_codec *codec = socdev->codec; 435 struct snd_soc_codec *codec = socdev->card->codec;
448 int ret; 436 int ret;
449 437
450 codec->control_data = spi; 438 codec->control_data = spi;
@@ -508,7 +496,7 @@ static int wm8728_probe(struct platform_device *pdev)
508 if (codec == NULL) 496 if (codec == NULL)
509 return -ENOMEM; 497 return -ENOMEM;
510 498
511 socdev->codec = codec; 499 socdev->card->codec = codec;
512 mutex_init(&codec->mutex); 500 mutex_init(&codec->mutex);
513 INIT_LIST_HEAD(&codec->dapm_widgets); 501 INIT_LIST_HEAD(&codec->dapm_widgets);
514 INIT_LIST_HEAD(&codec->dapm_paths); 502 INIT_LIST_HEAD(&codec->dapm_paths);
@@ -541,7 +529,7 @@ static int wm8728_probe(struct platform_device *pdev)
541static int wm8728_remove(struct platform_device *pdev) 529static int wm8728_remove(struct platform_device *pdev)
542{ 530{
543 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 531 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
544 struct snd_soc_codec *codec = socdev->codec; 532 struct snd_soc_codec *codec = socdev->card->codec;
545 533
546 if (codec->control_data) 534 if (codec->control_data)
547 wm8728_set_bias_level(codec, SND_SOC_BIAS_OFF); 535 wm8728_set_bias_level(codec, SND_SOC_BIAS_OFF);