blob: 0f4110f4bceba08092065d2001329a14ab7a9d02 [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.
11 *
12 * Revision history
13 * 25th Sep 2008 Initial version.
14 */
15
16#include <linux/init.h>
17#include <linux/module.h>
Cliff Cai0e77e782008-09-27 16:57:26 +080018#include <linux/kernel.h>
19#include <linux/device.h>
20#include <sound/core.h>
21#include <sound/pcm.h>
22#include <sound/ac97_codec.h>
23#include <sound/initval.h>
24#include <sound/soc.h>
25
26#include "ad73311.h"
27
28struct snd_soc_dai ad73311_dai = {
29 .name = "AD73311",
30 .playback = {
31 .stream_name = "Playback",
32 .channels_min = 1,
33 .channels_max = 1,
34 .rates = SNDRV_PCM_RATE_8000,
35 .formats = SNDRV_PCM_FMTBIT_S16_LE, },
36 .capture = {
37 .stream_name = "Capture",
38 .channels_min = 1,
39 .channels_max = 1,
40 .rates = SNDRV_PCM_RATE_8000,
41 .formats = SNDRV_PCM_FMTBIT_S16_LE, },
42};
43EXPORT_SYMBOL_GPL(ad73311_dai);
44
45static int ad73311_soc_probe(struct platform_device *pdev)
46{
47 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
48 struct snd_soc_codec *codec;
49 int ret = 0;
50
51 codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
52 if (codec == NULL)
53 return -ENOMEM;
54 mutex_init(&codec->mutex);
55 codec->name = "AD73311";
56 codec->owner = THIS_MODULE;
57 codec->dai = &ad73311_dai;
58 codec->num_dai = 1;
59 socdev->codec = codec;
60 INIT_LIST_HEAD(&codec->dapm_widgets);
61 INIT_LIST_HEAD(&codec->dapm_paths);
62
63 /* register pcms */
64 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
65 if (ret < 0) {
66 printk(KERN_ERR "ad73311: failed to create pcms\n");
67 goto pcm_err;
68 }
69
Mark Brown968a6022008-11-28 11:49:07 +000070 ret = snd_soc_init_card(socdev);
Cliff Cai0e77e782008-09-27 16:57:26 +080071 if (ret < 0) {
72 printk(KERN_ERR "ad73311: failed to register card\n");
73 goto register_err;
74 }
75
76 return ret;
77
78register_err:
79 snd_soc_free_pcms(socdev);
80pcm_err:
81 kfree(socdev->codec);
82 socdev->codec = NULL;
83 return ret;
84}
85
86static int ad73311_soc_remove(struct platform_device *pdev)
87{
88 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
89 struct snd_soc_codec *codec = socdev->codec;
90
91 if (codec == NULL)
92 return 0;
93 snd_soc_free_pcms(socdev);
94 kfree(codec);
95 return 0;
96}
97
98struct snd_soc_codec_device soc_codec_dev_ad73311 = {
99 .probe = ad73311_soc_probe,
100 .remove = ad73311_soc_remove,
101};
102EXPORT_SYMBOL_GPL(soc_codec_dev_ad73311);
103
104MODULE_DESCRIPTION("ASoC ad73311 driver");
105MODULE_AUTHOR("Cliff Cai ");
106MODULE_LICENSE("GPL");