15
15
* option) any later version.
18
#include <linux/module.h>
19
#include <linux/moduleparam.h>
20
#include <linux/kernel.h>
21
#include <linux/init.h>
22
18
#include <linux/delay.h>
24
19
#include <linux/i2c.h>
25
20
#include <linux/platform_device.h>
26
21
#include <linux/slab.h>
27
#include <sound/core.h>
28
22
#include <sound/pcm.h>
29
23
#include <sound/pcm_params.h>
30
24
#include <sound/soc.h>
31
#include <sound/soc-dapm.h>
25
#include <sound/initval.h>
32
26
#include <sound/tlv.h>
33
#include <sound/initval.h>
34
#include <asm/div64.h>
38
28
/* DA7210 register space */
39
29
#define DA7210_STATUS 0x02
146
136
#define DA7210_VERSION "0.0.1"
141
* max : 0x3F (+15.0 dB)
143
* min : 0x11 (-54.0 dB)
145
* reserved : 0x00 - 0x0F
149
* Reserved area are considered as "mute".
152
static const DECLARE_TLV_DB_SCALE(hp_out_tlv, -7950, 150, 1);
154
static const struct snd_kcontrol_new da7210_snd_controls[] = {
156
SOC_DOUBLE_R_TLV("HeadPhone Playback Volume",
157
DA7210_HP_L_VOL, DA7210_HP_R_VOL,
158
0, 0x3F, 0, hp_out_tlv),
148
161
/* Codec private data */
149
162
struct da7210_priv {
150
struct snd_soc_codec codec;
163
enum snd_soc_control_type control_type;
153
static struct snd_soc_codec *da7210_codec;
182
194
static inline u32 da7210_read_reg_cache(struct snd_soc_codec *codec, u32 reg)
184
196
u8 *cache = codec->reg_cache;
185
BUG_ON(reg > ARRAY_SIZE(da7210_reg));
197
BUG_ON(reg >= ARRAY_SIZE(da7210_reg));
186
198
return cache[reg];
194
206
u8 *cache = codec->reg_cache;
197
BUG_ON(codec->volatile_register);
209
BUG_ON(codec->driver->volatile_register);
199
211
data[0] = reg & 0xff;
200
212
data[1] = value & 0xff;
202
if (reg >= codec->reg_cache_size)
214
if (reg >= codec->driver->reg_cache_size)
205
217
if (2 != codec->hw_write(codec->control_data, data, 2))
227
239
struct snd_soc_codec *codec = dai->codec;
230
/* PlayBack Volume 40 */
231
snd_soc_update_bits(codec, DA7210_HP_L_VOL, 0x3F, 40);
232
snd_soc_update_bits(codec, DA7210_HP_R_VOL, 0x3F, 40);
235
243
snd_soc_update_bits(codec, DA7210_OUTMIX_L, 0x1F, 0x10);
236
244
snd_soc_update_bits(codec, DA7210_OUTMIX_R, 0x1F, 0x10);
256
264
struct snd_soc_dai *dai)
258
266
struct snd_soc_pcm_runtime *rtd = substream->private_data;
259
struct snd_soc_device *socdev = rtd->socdev;
260
struct snd_soc_codec *codec = socdev->card->codec;
267
struct snd_soc_codec *codec = rtd->codec;
262
269
u32 hpf_reg, hpf_mask, hpf_value;
419
426
.set_fmt = da7210_set_dai_fmt,
422
struct snd_soc_dai da7210_dai = {
423
.name = "DA7210 IIS",
429
static struct snd_soc_dai_driver da7210_dai = {
430
.name = "da7210-hifi",
425
431
/* playback capabilities */
427
433
.stream_name = "Playback",
441
447
.ops = &da7210_dai_ops,
442
448
.symmetric_rates = 1,
444
EXPORT_SYMBOL_GPL(da7210_dai);
447
* Initialize the DA7210 driver
448
* register the mixer and dsp interfaces with the kernel
450
static int da7210_init(struct da7210_priv *da7210)
451
static int da7210_probe(struct snd_soc_codec *codec)
452
struct snd_soc_codec *codec = &da7210->codec;
456
dev_err(codec->dev, "Another da7210 is registered\n");
460
mutex_init(&codec->mutex);
461
INIT_LIST_HEAD(&codec->dapm_widgets);
462
INIT_LIST_HEAD(&codec->dapm_paths);
464
codec->private_data = da7210;
465
codec->name = "DA7210";
466
codec->owner = THIS_MODULE;
467
codec->read = da7210_read;
468
codec->write = da7210_write;
469
codec->dai = &da7210_dai;
453
struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec);
455
dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION);
457
codec->control_data = da7210->control_data;
471
458
codec->hw_write = (hw_write_t)i2c_master_send;
472
codec->reg_cache_size = ARRAY_SIZE(da7210_reg);
473
codec->reg_cache = kmemdup(da7210_reg,
474
sizeof(da7210_reg), GFP_KERNEL);
476
if (!codec->reg_cache)
479
da7210_dai.dev = codec->dev;
480
da7210_codec = codec;
482
ret = snd_soc_register_codec(codec);
484
dev_err(codec->dev, "Failed to register CODEC: %d\n", ret);
488
ret = snd_soc_register_dai(&da7210_dai);
490
dev_err(codec->dev, "Failed to register DAI: %d\n", ret);
572
538
/* Activate all enabled subsystem */
573
539
da7210_write(codec, DA7210_STARTUP1, DA7210_SC_MST_EN);
578
kfree(codec->reg_cache);
579
codec->reg_cache = NULL;
541
snd_soc_add_controls(codec, da7210_snd_controls,
542
ARRAY_SIZE(da7210_snd_controls));
544
dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION);
549
static struct snd_soc_codec_driver soc_codec_dev_da7210 = {
550
.probe = da7210_probe,
552
.write = da7210_write,
553
.reg_cache_size = ARRAY_SIZE(da7210_reg),
554
.reg_word_size = sizeof(u8),
555
.reg_cache_default = da7210_reg,
585
558
#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
586
559
static int __devinit da7210_i2c_probe(struct i2c_client *i2c,
587
560
const struct i2c_device_id *id)
589
562
struct da7210_priv *da7210;
590
struct snd_soc_codec *codec;
593
565
da7210 = kzalloc(sizeof(struct da7210_priv), GFP_KERNEL);
597
codec = &da7210->codec;
598
codec->dev = &i2c->dev;
600
569
i2c_set_clientdata(i2c, da7210);
601
codec->control_data = i2c;
570
da7210->control_data = i2c;
571
da7210->control_type = SND_SOC_I2C;
603
ret = da7210_init(da7210);
573
ret = snd_soc_register_codec(&i2c->dev,
574
&soc_codec_dev_da7210, &da7210_dai, 1);
605
pr_err("Failed to initialise da7210 audio codec\n");
610
581
static int __devexit da7210_i2c_remove(struct i2c_client *client)
612
struct da7210_priv *da7210 = i2c_get_clientdata(client);
614
snd_soc_unregister_dai(&da7210_dai);
615
kfree(da7210->codec.reg_cache);
583
snd_soc_unregister_codec(&client->dev);
584
kfree(i2c_get_clientdata(client));
628
594
/* I2C codec control layer */
629
595
static struct i2c_driver da7210_i2c_driver = {
631
.name = "DA7210 I2C Codec",
597
.name = "da7210-codec",
632
598
.owner = THIS_MODULE,
634
.probe = da7210_i2c_probe,
635
.remove = __devexit_p(da7210_i2c_remove),
636
.id_table = da7210_i2c_id,
600
.probe = da7210_i2c_probe,
601
.remove = __devexit_p(da7210_i2c_remove),
602
.id_table = da7210_i2c_id,
640
static int da7210_probe(struct platform_device *pdev)
642
struct snd_soc_device *socdev = platform_get_drvdata(pdev);
643
struct snd_soc_codec *codec;
647
dev_err(&pdev->dev, "Codec device not registered\n");
651
socdev->card->codec = da7210_codec;
652
codec = da7210_codec;
655
ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
659
dev_info(&pdev->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION);
665
static int da7210_remove(struct platform_device *pdev)
667
struct snd_soc_device *socdev = platform_get_drvdata(pdev);
669
snd_soc_free_pcms(socdev);
670
snd_soc_dapm_free(socdev);
675
struct snd_soc_codec_device soc_codec_dev_da7210 = {
676
.probe = da7210_probe,
677
.remove = da7210_remove,
679
EXPORT_SYMBOL_GPL(soc_codec_dev_da7210);
681
606
static int __init da7210_modinit(void)