ASoC: wm8994: playback => capture
[deliverable/linux.git] / sound / soc / codecs / wm8727.c
1 /*
2 * wm8727.c
3 *
4 * Created on: 15-Oct-2009
5 * Author: neil.jones@imgtec.com
6 *
7 * Copyright (C) 2009 Imagination Technologies Ltd.
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
13 */
14
15 #include <linux/init.h>
16 #include <linux/module.h>
17 #include <linux/kernel.h>
18 #include <linux/device.h>
19 #include <sound/core.h>
20 #include <sound/pcm.h>
21 #include <sound/ac97_codec.h>
22 #include <sound/initval.h>
23 #include <sound/soc.h>
24
25 #include "wm8727.h"
26 /*
27 * Note this is a simple chip with no configuration interface, sample rate is
28 * determined automatically by examining the Master clock and Bit clock ratios
29 */
30 #define WM8727_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |\
31 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 |\
32 SNDRV_PCM_RATE_192000)
33
34
35 struct snd_soc_dai wm8727_dai = {
36 .name = "WM8727",
37 .playback = {
38 .stream_name = "Playback",
39 .channels_min = 2,
40 .channels_max = 2,
41 .rates = WM8727_RATES,
42 .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE,
43 },
44 };
45 EXPORT_SYMBOL_GPL(wm8727_dai);
46
47 static struct snd_soc_codec *wm8727_codec;
48
49 static int wm8727_soc_probe(struct platform_device *pdev)
50 {
51 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
52 int ret = 0;
53
54 BUG_ON(!wm8727_codec);
55
56 socdev->card->codec = wm8727_codec;
57
58 /* register pcms */
59 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
60 if (ret < 0) {
61 printk(KERN_ERR "wm8727: failed to create pcms\n");
62 goto pcm_err;
63 }
64
65 return ret;
66
67 pcm_err:
68 kfree(socdev->card->codec);
69 socdev->card->codec = NULL;
70 return ret;
71 }
72
73 static int wm8727_soc_remove(struct platform_device *pdev)
74 {
75 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
76
77 snd_soc_free_pcms(socdev);
78
79 return 0;
80 }
81
82 struct snd_soc_codec_device soc_codec_dev_wm8727 = {
83 .probe = wm8727_soc_probe,
84 .remove = wm8727_soc_remove,
85 };
86 EXPORT_SYMBOL_GPL(soc_codec_dev_wm8727);
87
88
89 static __devinit int wm8727_platform_probe(struct platform_device *pdev)
90 {
91 struct snd_soc_codec *codec;
92 int ret;
93
94 if (wm8727_codec) {
95 dev_err(&pdev->dev, "Another WM8727 is registered\n");
96 return -EBUSY;
97 }
98
99 codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
100 if (codec == NULL)
101 return -ENOMEM;
102 wm8727_codec = codec;
103
104 platform_set_drvdata(pdev, codec);
105
106 mutex_init(&codec->mutex);
107 codec->dev = &pdev->dev;
108 codec->name = "WM8727";
109 codec->owner = THIS_MODULE;
110 codec->dai = &wm8727_dai;
111 codec->num_dai = 1;
112 INIT_LIST_HEAD(&codec->dapm_widgets);
113 INIT_LIST_HEAD(&codec->dapm_paths);
114
115 wm8727_dai.dev = &pdev->dev;
116
117 ret = snd_soc_register_codec(codec);
118 if (ret != 0) {
119 dev_err(&pdev->dev, "Failed to register CODEC: %d\n", ret);
120 goto err;
121 }
122
123 ret = snd_soc_register_dai(&wm8727_dai);
124 if (ret != 0) {
125 dev_err(&pdev->dev, "Failed to register DAI: %d\n", ret);
126 goto err_codec;
127 }
128
129 err_codec:
130 snd_soc_unregister_codec(codec);
131 err:
132 kfree(codec);
133 return ret;
134 }
135
136 static int __devexit wm8727_platform_remove(struct platform_device *pdev)
137 {
138 snd_soc_unregister_dai(&wm8727_dai);
139 snd_soc_unregister_codec(platform_get_drvdata(pdev));
140 return 0;
141 }
142
143 static struct platform_driver wm8727_codec_driver = {
144 .driver = {
145 .name = "wm8727-codec",
146 .owner = THIS_MODULE,
147 },
148
149 .probe = wm8727_platform_probe,
150 .remove = __devexit_p(wm8727_platform_remove),
151 };
152
153 static int __init wm8727_init(void)
154 {
155 return platform_driver_register(&wm8727_codec_driver);
156 }
157 module_init(wm8727_init);
158
159 static void __exit wm8727_exit(void)
160 {
161 platform_driver_unregister(&wm8727_codec_driver);
162 }
163 module_exit(wm8727_exit);
164
165 MODULE_DESCRIPTION("ASoC wm8727 driver");
166 MODULE_AUTHOR("Neil Jones");
167 MODULE_LICENSE("GPL");
This page took 0.034274 seconds and 5 git commands to generate.