Staging: vt6655: Makefile: cleaned up Makefile cflag lines
[linux-2.6/libata-dev.git] / sound / soc / codecs / wm8727.c
blob9d1df26281361ef9ed569e0b87a39d9a934f9254
1 /*
2 * wm8727.c
4 * Created on: 15-Oct-2009
5 * Author: neil.jones@imgtec.com
7 * Copyright (C) 2009 Imagination Technologies Ltd.
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.
15 #include <linux/init.h>
16 #include <linux/slab.h>
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>
26 #include "wm8727.h"
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
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)
36 struct 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,
46 EXPORT_SYMBOL_GPL(wm8727_dai);
48 static struct snd_soc_codec *wm8727_codec;
50 static int wm8727_soc_probe(struct platform_device *pdev)
52 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
53 int ret = 0;
55 BUG_ON(!wm8727_codec);
57 socdev->card->codec = wm8727_codec;
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;
66 return ret;
68 pcm_err:
69 kfree(socdev->card->codec);
70 socdev->card->codec = NULL;
71 return ret;
74 static int wm8727_soc_remove(struct platform_device *pdev)
76 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
78 snd_soc_free_pcms(socdev);
80 return 0;
83 struct snd_soc_codec_device soc_codec_dev_wm8727 = {
84 .probe = wm8727_soc_probe,
85 .remove = wm8727_soc_remove,
87 EXPORT_SYMBOL_GPL(soc_codec_dev_wm8727);
90 static __devinit int wm8727_platform_probe(struct platform_device *pdev)
92 struct snd_soc_codec *codec;
93 int ret;
95 if (wm8727_codec) {
96 dev_err(&pdev->dev, "Another WM8727 is registered\n");
97 return -EBUSY;
100 codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
101 if (codec == NULL)
102 return -ENOMEM;
103 wm8727_codec = codec;
105 platform_set_drvdata(pdev, codec);
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);
116 wm8727_dai.dev = &pdev->dev;
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;
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;
130 return 0;
132 err_codec:
133 snd_soc_unregister_codec(codec);
134 err:
135 kfree(codec);
136 return ret;
139 static int __devexit wm8727_platform_remove(struct platform_device *pdev)
141 snd_soc_unregister_dai(&wm8727_dai);
142 snd_soc_unregister_codec(platform_get_drvdata(pdev));
143 return 0;
146 static struct platform_driver wm8727_codec_driver = {
147 .driver = {
148 .name = "wm8727-codec",
149 .owner = THIS_MODULE,
152 .probe = wm8727_platform_probe,
153 .remove = __devexit_p(wm8727_platform_remove),
156 static int __init wm8727_init(void)
158 return platform_driver_register(&wm8727_codec_driver);
160 module_init(wm8727_init);
162 static void __exit wm8727_exit(void)
164 platform_driver_unregister(&wm8727_codec_driver);
166 module_exit(wm8727_exit);
168 MODULE_DESCRIPTION("ASoC wm8727 driver");
169 MODULE_AUTHOR("Neil Jones");
170 MODULE_LICENSE("GPL");