~ubuntu-branches/ubuntu/precise/alsa-driver/precise

« back to all changes in this revision

Viewing changes to alsa-kernel/soc/codecs/da7210.c

  • Committer: Bazaar Package Importer
  • Author(s): Luke Yelavich
  • Date: 2011-02-21 18:06:40 UTC
  • mfrom: (1.1.15 upstream)
  • Revision ID: james.westby@ubuntu.com-20110221180640-a8p2yxtvgf7xbxub
Tags: 1.0.24+dfsg-0ubuntu1
* New upstream release
* Refreshed patches:
  - distinguish_kernel_makefile_and_source_dirs.patch
  - debian_dfsg_configure.patch
* debian/control: Update Vcs-bzr field to point to new branch location

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 * option) any later version.
16
16
 */
17
17
 
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>
23
 
#include <linux/pm.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>
35
 
 
36
 
#include "da7210.h"
37
27
 
38
28
/* DA7210 register space */
39
29
#define DA7210_STATUS                   0x02
145
135
 
146
136
#define DA7210_VERSION "0.0.1"
147
137
 
 
138
/*
 
139
 * Playback Volume
 
140
 *
 
141
 * max          : 0x3F (+15.0 dB)
 
142
 *                 (1.5 dB step)
 
143
 * min          : 0x11 (-54.0 dB)
 
144
 * mute         : 0x10
 
145
 * reserved     : 0x00 - 0x0F
 
146
 *
 
147
 * ** FIXME **
 
148
 *
 
149
 * Reserved area are considered as "mute".
 
150
 * -> min = -79.5 dB
 
151
 */
 
152
static const DECLARE_TLV_DB_SCALE(hp_out_tlv, -7950, 150, 1);
 
153
 
 
154
static const struct snd_kcontrol_new da7210_snd_controls[] = {
 
155
 
 
156
        SOC_DOUBLE_R_TLV("HeadPhone Playback Volume",
 
157
                         DA7210_HP_L_VOL, DA7210_HP_R_VOL,
 
158
                         0, 0x3F, 0, hp_out_tlv),
 
159
};
 
160
 
148
161
/* Codec private data */
149
162
struct da7210_priv {
150
 
        struct snd_soc_codec codec;
 
163
        enum snd_soc_control_type control_type;
 
164
        void *control_data;
151
165
};
152
166
 
153
 
static struct snd_soc_codec *da7210_codec;
154
 
 
155
167
/*
156
168
 * Register cache
157
169
 */
182
194
static inline u32 da7210_read_reg_cache(struct snd_soc_codec *codec, u32 reg)
183
195
{
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];
187
199
}
188
200
 
194
206
        u8 *cache = codec->reg_cache;
195
207
        u8 data[2];
196
208
 
197
 
        BUG_ON(codec->volatile_register);
 
209
        BUG_ON(codec->driver->volatile_register);
198
210
 
199
211
        data[0] = reg & 0xff;
200
212
        data[1] = value & 0xff;
201
213
 
202
 
        if (reg >= codec->reg_cache_size)
 
214
        if (reg >= codec->driver->reg_cache_size)
203
215
                return -EIO;
204
216
 
205
217
        if (2 != codec->hw_write(codec->control_data, data, 2))
227
239
        struct snd_soc_codec *codec = dai->codec;
228
240
 
229
241
        if (is_play) {
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);
233
 
 
234
242
                /* Enable Out */
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)
257
265
{
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;
261
268
        u32 dai_cfg1;
262
269
        u32 hpf_reg, hpf_mask, hpf_value;
263
270
        u32 fs, bypass;
419
426
        .set_fmt        = da7210_set_dai_fmt,
420
427
};
421
428
 
422
 
struct snd_soc_dai da7210_dai = {
423
 
        .name = "DA7210 IIS",
424
 
        .id = 0,
 
429
static struct snd_soc_dai_driver da7210_dai = {
 
430
        .name = "da7210-hifi",
425
431
        /* playback capabilities */
426
432
        .playback = {
427
433
                .stream_name = "Playback",
441
447
        .ops = &da7210_dai_ops,
442
448
        .symmetric_rates = 1,
443
449
};
444
 
EXPORT_SYMBOL_GPL(da7210_dai);
445
450
 
446
 
/*
447
 
 * Initialize the DA7210 driver
448
 
 * register the mixer and dsp interfaces with the kernel
449
 
 */
450
 
static int da7210_init(struct da7210_priv *da7210)
 
451
static int da7210_probe(struct snd_soc_codec *codec)
451
452
{
452
 
        struct snd_soc_codec *codec = &da7210->codec;
453
 
        int ret = 0;
454
 
 
455
 
        if (da7210_codec) {
456
 
                dev_err(codec->dev, "Another da7210 is registered\n");
457
 
                return -EINVAL;
458
 
        }
459
 
 
460
 
        mutex_init(&codec->mutex);
461
 
        INIT_LIST_HEAD(&codec->dapm_widgets);
462
 
        INIT_LIST_HEAD(&codec->dapm_paths);
463
 
 
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;
470
 
        codec->num_dai          = 1;
 
453
        struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec);
 
454
 
 
455
        dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION);
 
456
 
 
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);
475
 
 
476
 
        if (!codec->reg_cache)
477
 
                return -ENOMEM;
478
 
 
479
 
        da7210_dai.dev = codec->dev;
480
 
        da7210_codec = codec;
481
 
 
482
 
        ret = snd_soc_register_codec(codec);
483
 
        if (ret) {
484
 
                dev_err(codec->dev, "Failed to register CODEC: %d\n", ret);
485
 
                goto init_err;
486
 
        }
487
 
 
488
 
        ret = snd_soc_register_dai(&da7210_dai);
489
 
        if (ret) {
490
 
                dev_err(codec->dev, "Failed to register DAI: %d\n", ret);
491
 
                goto init_err;
492
 
        }
493
459
 
494
460
        /* FIXME
495
461
         *
572
538
        /* Activate all enabled subsystem */
573
539
        da7210_write(codec, DA7210_STARTUP1, DA7210_SC_MST_EN);
574
540
 
575
 
        return ret;
576
 
 
577
 
init_err:
578
 
        kfree(codec->reg_cache);
579
 
        codec->reg_cache = NULL;
580
 
 
581
 
        return ret;
582
 
 
 
541
        snd_soc_add_controls(codec, da7210_snd_controls,
 
542
                             ARRAY_SIZE(da7210_snd_controls));
 
543
 
 
544
        dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION);
 
545
 
 
546
        return 0;
583
547
}
584
548
 
 
549
static struct snd_soc_codec_driver soc_codec_dev_da7210 = {
 
550
        .probe                  = da7210_probe,
 
551
        .read                   = da7210_read,
 
552
        .write                  = da7210_write,
 
553
        .reg_cache_size         = ARRAY_SIZE(da7210_reg),
 
554
        .reg_word_size          = sizeof(u8),
 
555
        .reg_cache_default      = da7210_reg,
 
556
};
 
557
 
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)
588
561
{
589
562
        struct da7210_priv *da7210;
590
 
        struct snd_soc_codec *codec;
591
563
        int ret;
592
564
 
593
565
        da7210 = kzalloc(sizeof(struct da7210_priv), GFP_KERNEL);
594
566
        if (!da7210)
595
567
                return -ENOMEM;
596
568
 
597
 
        codec = &da7210->codec;
598
 
        codec->dev = &i2c->dev;
599
 
 
600
569
        i2c_set_clientdata(i2c, da7210);
601
 
        codec->control_data = i2c;
 
570
        da7210->control_data = i2c;
 
571
        da7210->control_type = SND_SOC_I2C;
602
572
 
603
 
        ret = da7210_init(da7210);
 
573
        ret =  snd_soc_register_codec(&i2c->dev,
 
574
                        &soc_codec_dev_da7210, &da7210_dai, 1);
604
575
        if (ret < 0)
605
 
                pr_err("Failed to initialise da7210 audio codec\n");
 
576
                kfree(da7210);
606
577
 
607
578
        return ret;
608
579
}
609
580
 
610
581
static int __devexit da7210_i2c_remove(struct i2c_client *client)
611
582
{
612
 
        struct da7210_priv *da7210 = i2c_get_clientdata(client);
613
 
 
614
 
        snd_soc_unregister_dai(&da7210_dai);
615
 
        kfree(da7210->codec.reg_cache);
616
 
        kfree(da7210);
617
 
        da7210_codec = NULL;
618
 
 
 
583
        snd_soc_unregister_codec(&client->dev);
 
584
        kfree(i2c_get_clientdata(client));
619
585
        return 0;
620
586
}
621
587
 
628
594
/* I2C codec control layer */
629
595
static struct i2c_driver da7210_i2c_driver = {
630
596
        .driver = {
631
 
                .name = "DA7210 I2C Codec",
 
597
                .name = "da7210-codec",
632
598
                .owner = THIS_MODULE,
633
599
        },
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,
637
603
};
638
604
#endif
639
605
 
640
 
static int da7210_probe(struct platform_device *pdev)
641
 
{
642
 
        struct snd_soc_device *socdev = platform_get_drvdata(pdev);
643
 
        struct snd_soc_codec *codec;
644
 
        int ret;
645
 
 
646
 
        if (!da7210_codec) {
647
 
                dev_err(&pdev->dev, "Codec device not registered\n");
648
 
                return -ENODEV;
649
 
        }
650
 
 
651
 
        socdev->card->codec = da7210_codec;
652
 
        codec = da7210_codec;
653
 
 
654
 
        /* Register pcms */
655
 
        ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
656
 
        if (ret < 0)
657
 
                goto pcm_err;
658
 
 
659
 
        dev_info(&pdev->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION);
660
 
 
661
 
pcm_err:
662
 
        return ret;
663
 
}
664
 
 
665
 
static int da7210_remove(struct platform_device *pdev)
666
 
{
667
 
        struct snd_soc_device *socdev = platform_get_drvdata(pdev);
668
 
 
669
 
        snd_soc_free_pcms(socdev);
670
 
        snd_soc_dapm_free(socdev);
671
 
 
672
 
        return 0;
673
 
}
674
 
 
675
 
struct snd_soc_codec_device soc_codec_dev_da7210 = {
676
 
        .probe =        da7210_probe,
677
 
        .remove =       da7210_remove,
678
 
};
679
 
EXPORT_SYMBOL_GPL(soc_codec_dev_da7210);
680
 
 
681
606
static int __init da7210_modinit(void)
682
607
{
683
608
        int ret = 0;