19
19
#include <linux/i2c.h>
20
20
#include <linux/platform_device.h>
21
21
#include <linux/regulator/consumer.h>
22
#include <linux/slab.h>
22
23
#include <sound/core.h>
23
24
#include <sound/pcm.h>
24
25
#include <sound/pcm_params.h>
25
26
#include <sound/soc.h>
26
#include <sound/soc-dapm.h>
27
27
#include <sound/initval.h>
28
28
#include <sound/tlv.h>
30
30
#include "wm8523.h"
32
static struct snd_soc_codec *wm8523_codec;
33
struct snd_soc_codec_device soc_codec_dev_wm8523;
35
32
#define WM8523_NUM_SUPPLIES 2
36
33
static const char *wm8523_supply_names[WM8523_NUM_SUPPLIES] = {
113
109
static int wm8523_add_widgets(struct snd_soc_codec *codec)
115
snd_soc_dapm_new_controls(codec, wm8523_dapm_widgets,
111
struct snd_soc_dapm_context *dapm = &codec->dapm;
113
snd_soc_dapm_new_controls(dapm, wm8523_dapm_widgets,
116
114
ARRAY_SIZE(wm8523_dapm_widgets));
118
snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon));
120
snd_soc_dapm_new_widgets(codec);
115
snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
162
157
struct snd_soc_dai *dai)
164
159
struct snd_soc_pcm_runtime *rtd = substream->private_data;
165
struct snd_soc_device *socdev = rtd->socdev;
166
struct snd_soc_codec *codec = socdev->card->codec;
167
struct wm8523_priv *wm8523 = codec->private_data;
160
struct snd_soc_codec *codec = rtd->codec;
161
struct wm8523_priv *wm8523 = snd_soc_codec_get_drvdata(codec);
169
163
u16 aifctrl1 = snd_soc_read(codec, WM8523_AIF_CTRL1);
170
164
u16 aifctrl2 = snd_soc_read(codec, WM8523_AIF_CTRL2);
399
394
.ops = &wm8523_dai_ops,
401
EXPORT_SYMBOL_GPL(wm8523_dai);
404
static int wm8523_suspend(struct platform_device *pdev, pm_message_t state)
398
static int wm8523_suspend(struct snd_soc_codec *codec, pm_message_t state)
406
struct snd_soc_device *socdev = platform_get_drvdata(pdev);
407
struct snd_soc_codec *codec = socdev->card->codec;
409
400
wm8523_set_bias_level(codec, SND_SOC_BIAS_OFF);
413
static int wm8523_resume(struct platform_device *pdev)
404
static int wm8523_resume(struct snd_soc_codec *codec)
415
struct snd_soc_device *socdev = platform_get_drvdata(pdev);
416
struct snd_soc_codec *codec = socdev->card->codec;
418
406
wm8523_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
424
411
#define wm8523_resume NULL
427
static int wm8523_probe(struct platform_device *pdev)
429
struct snd_soc_device *socdev = platform_get_drvdata(pdev);
430
struct snd_soc_codec *codec;
433
if (wm8523_codec == NULL) {
434
dev_err(&pdev->dev, "Codec device not registered\n");
438
socdev->card->codec = wm8523_codec;
439
codec = wm8523_codec;
442
ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
444
dev_err(codec->dev, "failed to create pcms: %d\n", ret);
448
snd_soc_add_controls(codec, wm8523_snd_controls,
449
ARRAY_SIZE(wm8523_snd_controls));
450
wm8523_add_widgets(codec);
451
ret = snd_soc_init_card(socdev);
453
dev_err(codec->dev, "failed to register card: %d\n", ret);
460
snd_soc_free_pcms(socdev);
461
snd_soc_dapm_free(socdev);
466
static int wm8523_remove(struct platform_device *pdev)
468
struct snd_soc_device *socdev = platform_get_drvdata(pdev);
470
snd_soc_free_pcms(socdev);
471
snd_soc_dapm_free(socdev);
476
struct snd_soc_codec_device soc_codec_dev_wm8523 = {
477
.probe = wm8523_probe,
478
.remove = wm8523_remove,
479
.suspend = wm8523_suspend,
480
.resume = wm8523_resume,
482
EXPORT_SYMBOL_GPL(soc_codec_dev_wm8523);
484
static int wm8523_register(struct wm8523_priv *wm8523,
485
enum snd_soc_control_type control)
488
struct snd_soc_codec *codec = &wm8523->codec;
492
dev_err(codec->dev, "Another WM8523 is registered\n");
496
mutex_init(&codec->mutex);
497
INIT_LIST_HEAD(&codec->dapm_widgets);
498
INIT_LIST_HEAD(&codec->dapm_paths);
500
codec->private_data = wm8523;
501
codec->name = "WM8523";
502
codec->owner = THIS_MODULE;
503
codec->bias_level = SND_SOC_BIAS_OFF;
504
codec->set_bias_level = wm8523_set_bias_level;
505
codec->dai = &wm8523_dai;
507
codec->reg_cache_size = WM8523_REGISTER_COUNT;
508
codec->reg_cache = &wm8523->reg_cache;
509
codec->volatile_register = wm8523_volatile_register;
414
static int wm8523_probe(struct snd_soc_codec *codec)
416
struct wm8523_priv *wm8523 = snd_soc_codec_get_drvdata(codec);
417
u16 *reg_cache = codec->reg_cache;
420
codec->hw_write = (hw_write_t)i2c_master_send;
511
421
wm8523->rate_constraint.list = &wm8523->rate_constraint_list[0];
512
422
wm8523->rate_constraint.count =
513
423
ARRAY_SIZE(wm8523->rate_constraint_list);
515
memcpy(codec->reg_cache, wm8523_reg, sizeof(wm8523_reg));
517
ret = snd_soc_codec_set_cache_io(codec, 8, 16, control);
425
ret = snd_soc_codec_set_cache_io(codec, 8, 16, wm8523->control_type);
519
427
dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
523
431
for (i = 0; i < ARRAY_SIZE(wm8523->supplies); i++)
565
wm8523_dai.dev = codec->dev;
567
473
/* Change some default settings - latch VU and enable ZC */
568
wm8523->reg_cache[WM8523_DAC_GAINR] |= WM8523_DACR_VU;
569
wm8523->reg_cache[WM8523_DAC_CTRL3] |= WM8523_ZC;
474
reg_cache[WM8523_DAC_GAINR] |= WM8523_DACR_VU;
475
reg_cache[WM8523_DAC_CTRL3] |= WM8523_ZC;
571
477
wm8523_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
573
479
/* Bias level configuration will have done an extra enable */
574
480
regulator_bulk_disable(ARRAY_SIZE(wm8523->supplies), wm8523->supplies);
576
wm8523_codec = codec;
578
ret = snd_soc_register_codec(codec);
580
dev_err(codec->dev, "Failed to register codec: %d\n", ret);
584
ret = snd_soc_register_dai(&wm8523_dai);
586
dev_err(codec->dev, "Failed to register DAI: %d\n", ret);
587
snd_soc_unregister_codec(codec);
482
snd_soc_add_controls(codec, wm8523_snd_controls,
483
ARRAY_SIZE(wm8523_snd_controls));
484
wm8523_add_widgets(codec);
594
489
regulator_bulk_disable(ARRAY_SIZE(wm8523->supplies), wm8523->supplies);
596
491
regulator_bulk_free(ARRAY_SIZE(wm8523->supplies), wm8523->supplies);
602
static void wm8523_unregister(struct wm8523_priv *wm8523)
496
static int wm8523_remove(struct snd_soc_codec *codec)
604
wm8523_set_bias_level(&wm8523->codec, SND_SOC_BIAS_OFF);
498
struct wm8523_priv *wm8523 = snd_soc_codec_get_drvdata(codec);
500
wm8523_set_bias_level(codec, SND_SOC_BIAS_OFF);
605
501
regulator_bulk_free(ARRAY_SIZE(wm8523->supplies), wm8523->supplies);
606
snd_soc_unregister_dai(&wm8523_dai);
607
snd_soc_unregister_codec(&wm8523->codec);
505
static struct snd_soc_codec_driver soc_codec_dev_wm8523 = {
506
.probe = wm8523_probe,
507
.remove = wm8523_remove,
508
.suspend = wm8523_suspend,
509
.resume = wm8523_resume,
510
.set_bias_level = wm8523_set_bias_level,
511
.reg_cache_size = WM8523_REGISTER_COUNT,
512
.reg_word_size = sizeof(u16),
513
.reg_cache_default = wm8523_reg,
514
.volatile_register = wm8523_volatile_register,
612
517
#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
613
518
static __devinit int wm8523_i2c_probe(struct i2c_client *i2c,
614
519
const struct i2c_device_id *id)
616
521
struct wm8523_priv *wm8523;
617
struct snd_soc_codec *codec;
619
524
wm8523 = kzalloc(sizeof(struct wm8523_priv), GFP_KERNEL);
620
525
if (wm8523 == NULL)
623
codec = &wm8523->codec;
624
codec->hw_write = (hw_write_t)i2c_master_send;
626
528
i2c_set_clientdata(i2c, wm8523);
627
codec->control_data = i2c;
629
codec->dev = &i2c->dev;
631
return wm8523_register(wm8523, SND_SOC_I2C);
529
wm8523->control_type = SND_SOC_I2C;
531
ret = snd_soc_register_codec(&i2c->dev,
532
&soc_codec_dev_wm8523, &wm8523_dai, 1);
634
539
static __devexit int wm8523_i2c_remove(struct i2c_client *client)
636
struct wm8523_priv *wm8523 = i2c_get_clientdata(client);
637
wm8523_unregister(wm8523);
541
snd_soc_unregister_codec(&client->dev);
542
kfree(i2c_get_clientdata(client));
642
static int wm8523_i2c_suspend(struct i2c_client *i2c, pm_message_t msg)
644
return snd_soc_suspend_device(&i2c->dev);
647
static int wm8523_i2c_resume(struct i2c_client *i2c)
649
return snd_soc_resume_device(&i2c->dev);
652
#define wm8523_i2c_suspend NULL
653
#define wm8523_i2c_resume NULL
656
546
static const struct i2c_device_id wm8523_i2c_id[] = {