]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - sound/soc/codecs/wm8727.c
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[mirror_ubuntu-bionic-kernel.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/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>
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
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,
44 },
45 };
46 EXPORT_SYMBOL_GPL(wm8727_dai);
47
48 static struct snd_soc_codec *wm8727_codec;
49
50 static int wm8727_soc_probe(struct platform_device *pdev)
51 {
52 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
53 int ret = 0;
54
55 BUG_ON(!wm8727_codec);
56
57 socdev->card->codec = wm8727_codec;
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 }
65
66 return ret;
67
68 pcm_err:
69 kfree(socdev->card->codec);
70 socdev->card->codec = NULL;
71 return ret;
72 }
73
74 static int wm8727_soc_remove(struct platform_device *pdev)
75 {
76 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
77
78 snd_soc_free_pcms(socdev);
79
80 return 0;
81 }
82
83 struct snd_soc_codec_device soc_codec_dev_wm8727 = {
84 .probe = wm8727_soc_probe,
85 .remove = wm8727_soc_remove,
86 };
87 EXPORT_SYMBOL_GPL(soc_codec_dev_wm8727);
88
89
90 static __devinit int wm8727_platform_probe(struct platform_device *pdev)
91 {
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
116 wm8727_dai.dev = &pdev->dev;
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
130 err_codec:
131 snd_soc_unregister_codec(codec);
132 err:
133 kfree(codec);
134 return ret;
135 }
136
137 static int __devexit wm8727_platform_remove(struct platform_device *pdev)
138 {
139 snd_soc_unregister_dai(&wm8727_dai);
140 snd_soc_unregister_codec(platform_get_drvdata(pdev));
141 return 0;
142 }
143
144 static struct platform_driver wm8727_codec_driver = {
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
154 static int __init wm8727_init(void)
155 {
156 return platform_driver_register(&wm8727_codec_driver);
157 }
158 module_init(wm8727_init);
159
160 static void __exit wm8727_exit(void)
161 {
162 platform_driver_unregister(&wm8727_codec_driver);
163 }
164 module_exit(wm8727_exit);
165
166 MODULE_DESCRIPTION("ASoC wm8727 driver");
167 MODULE_AUTHOR("Neil Jones");
168 MODULE_LICENSE("GPL");