include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[linux-2.6-block.git] / sound / soc / codecs / wm8727.c
CommitLineData
89933dee
NJ
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>
5a0e3ad6 16#include <linux/slab.h>
89933dee
NJ
17#include <linux/module.h>
18#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 "wm8727.h"
27/*
28 * Note this is a simple chip with no configuration interface, sample rate is
29 * determined automatically by examining the Master clock and Bit clock ratios
30 */
31#define WM8727_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |\
32 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 |\
33 SNDRV_PCM_RATE_192000)
34
35
36struct snd_soc_dai wm8727_dai = {
37 .name = "WM8727",
38 .playback = {
39 .stream_name = "Playback",
40 .channels_min = 2,
41 .channels_max = 2,
42 .rates = WM8727_RATES,
43 .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE,
44 },
45};
46EXPORT_SYMBOL_GPL(wm8727_dai);
47
cce2e9db
MB
48static struct snd_soc_codec *wm8727_codec;
49
89933dee
NJ
50static int wm8727_soc_probe(struct platform_device *pdev)
51{
52 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
89933dee
NJ
53 int ret = 0;
54
cce2e9db
MB
55 BUG_ON(!wm8727_codec);
56
57 socdev->card->codec = wm8727_codec;
89933dee
NJ
58
59 /* register pcms */
60 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
61 if (ret < 0) {
62 printk(KERN_ERR "wm8727: failed to create pcms\n");
63 goto pcm_err;
64 }
89933dee
NJ
65
66 return ret;
67
89933dee
NJ
68pcm_err:
69 kfree(socdev->card->codec);
70 socdev->card->codec = NULL;
71 return ret;
72}
73
74static int wm8727_soc_remove(struct platform_device *pdev)
75{
76 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
89933dee 77
89933dee 78 snd_soc_free_pcms(socdev);
cce2e9db 79
89933dee
NJ
80 return 0;
81}
82
83struct snd_soc_codec_device soc_codec_dev_wm8727 = {
84 .probe = wm8727_soc_probe,
85 .remove = wm8727_soc_remove,
86};
87EXPORT_SYMBOL_GPL(soc_codec_dev_wm8727);
88
89
90static __devinit int wm8727_platform_probe(struct platform_device *pdev)
91{
cce2e9db
MB
92 struct snd_soc_codec *codec;
93 int ret;
94
95 if (wm8727_codec) {
96 dev_err(&pdev->dev, "Another WM8727 is registered\n");
97 return -EBUSY;
98 }
99
100 codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
101 if (codec == NULL)
102 return -ENOMEM;
103 wm8727_codec = codec;
104
105 platform_set_drvdata(pdev, codec);
106
107 mutex_init(&codec->mutex);
108 codec->dev = &pdev->dev;
109 codec->name = "WM8727";
110 codec->owner = THIS_MODULE;
111 codec->dai = &wm8727_dai;
112 codec->num_dai = 1;
113 INIT_LIST_HEAD(&codec->dapm_widgets);
114 INIT_LIST_HEAD(&codec->dapm_paths);
115
89933dee 116 wm8727_dai.dev = &pdev->dev;
cce2e9db
MB
117
118 ret = snd_soc_register_codec(codec);
119 if (ret != 0) {
120 dev_err(&pdev->dev, "Failed to register CODEC: %d\n", ret);
121 goto err;
122 }
123
124 ret = snd_soc_register_dai(&wm8727_dai);
125 if (ret != 0) {
126 dev_err(&pdev->dev, "Failed to register DAI: %d\n", ret);
127 goto err_codec;
128 }
129
130err_codec:
131 snd_soc_unregister_codec(codec);
132err:
133 kfree(codec);
134 return ret;
89933dee
NJ
135}
136
137static int __devexit wm8727_platform_remove(struct platform_device *pdev)
138{
139 snd_soc_unregister_dai(&wm8727_dai);
cce2e9db 140 snd_soc_unregister_codec(platform_get_drvdata(pdev));
89933dee
NJ
141 return 0;
142}
143
529697c5 144static struct platform_driver wm8727_codec_driver = {
89933dee
NJ
145 .driver = {
146 .name = "wm8727-codec",
147 .owner = THIS_MODULE,
148 },
149
150 .probe = wm8727_platform_probe,
151 .remove = __devexit_p(wm8727_platform_remove),
152};
153
154static int __init wm8727_init(void)
155{
156 return platform_driver_register(&wm8727_codec_driver);
157}
158module_init(wm8727_init);
159
160static void __exit wm8727_exit(void)
161{
162 platform_driver_unregister(&wm8727_codec_driver);
163}
164module_exit(wm8727_exit);
165
166MODULE_DESCRIPTION("ASoC wm8727 driver");
167MODULE_AUTHOR("Neil Jones");
168MODULE_LICENSE("GPL");