blob: 475807bea2c229d04e4e3ed91dd8647ffa26d259 [file] [log] [blame]
Cliff Cai0e77e782008-09-27 16:57:26 +08001/*
2 * ad73311.c -- ALSA Soc AD73311 codec support
3 *
4 * Copyright: Analog Device Inc.
5 * Author: Cliff Cai <cliff.cai@analog.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
Cliff Cai0e77e782008-09-27 16:57:26 +080011 */
12
13#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090014#include <linux/slab.h>
Cliff Cai0e77e782008-09-27 16:57:26 +080015#include <linux/module.h>
Cliff Cai0e77e782008-09-27 16:57:26 +080016#include <linux/kernel.h>
17#include <linux/device.h>
18#include <sound/core.h>
19#include <sound/pcm.h>
20#include <sound/ac97_codec.h>
21#include <sound/initval.h>
22#include <sound/soc.h>
23
24#include "ad73311.h"
25
26struct snd_soc_dai ad73311_dai = {
27 .name = "AD73311",
28 .playback = {
29 .stream_name = "Playback",
30 .channels_min = 1,
31 .channels_max = 1,
32 .rates = SNDRV_PCM_RATE_8000,
33 .formats = SNDRV_PCM_FMTBIT_S16_LE, },
34 .capture = {
35 .stream_name = "Capture",
36 .channels_min = 1,
37 .channels_max = 1,
38 .rates = SNDRV_PCM_RATE_8000,
39 .formats = SNDRV_PCM_FMTBIT_S16_LE, },
40};
41EXPORT_SYMBOL_GPL(ad73311_dai);
42
43static int ad73311_soc_probe(struct platform_device *pdev)
44{
45 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
46 struct snd_soc_codec *codec;
47 int ret = 0;
48
49 codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
50 if (codec == NULL)
51 return -ENOMEM;
52 mutex_init(&codec->mutex);
53 codec->name = "AD73311";
54 codec->owner = THIS_MODULE;
55 codec->dai = &ad73311_dai;
56 codec->num_dai = 1;
Mark Brown6627a652009-01-23 22:55:23 +000057 socdev->card->codec = codec;
Cliff Cai0e77e782008-09-27 16:57:26 +080058 INIT_LIST_HEAD(&codec->dapm_widgets);
59 INIT_LIST_HEAD(&codec->dapm_paths);
60
61 /* register pcms */
62 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
63 if (ret < 0) {
64 printk(KERN_ERR "ad73311: failed to create pcms\n");
65 goto pcm_err;
66 }
67
Cliff Cai0e77e782008-09-27 16:57:26 +080068 return ret;
69
Cliff Cai0e77e782008-09-27 16:57:26 +080070pcm_err:
Mark Brown6627a652009-01-23 22:55:23 +000071 kfree(socdev->card->codec);
72 socdev->card->codec = NULL;
Cliff Cai0e77e782008-09-27 16:57:26 +080073 return ret;
74}
75
76static int ad73311_soc_remove(struct platform_device *pdev)
77{
78 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
Mark Brown6627a652009-01-23 22:55:23 +000079 struct snd_soc_codec *codec = socdev->card->codec;
Cliff Cai0e77e782008-09-27 16:57:26 +080080
81 if (codec == NULL)
82 return 0;
83 snd_soc_free_pcms(socdev);
84 kfree(codec);
85 return 0;
86}
87
88struct snd_soc_codec_device soc_codec_dev_ad73311 = {
89 .probe = ad73311_soc_probe,
90 .remove = ad73311_soc_remove,
91};
92EXPORT_SYMBOL_GPL(soc_codec_dev_ad73311);
93
Takashi Iwaic9b3a402008-12-10 07:47:22 +010094static int __init ad73311_init(void)
Mark Brown64089b82008-12-08 19:17:58 +000095{
96 return snd_soc_register_dai(&ad73311_dai);
97}
98module_init(ad73311_init);
99
100static void __exit ad73311_exit(void)
101{
102 snd_soc_unregister_dai(&ad73311_dai);
103}
104module_exit(ad73311_exit);
105
Cliff Cai0e77e782008-09-27 16:57:26 +0800106MODULE_DESCRIPTION("ASoC ad73311 driver");
107MODULE_AUTHOR("Cliff Cai ");
108MODULE_LICENSE("GPL");