blob: 35f3d23200e048ed8a358861b28888d3cf20678c [file] [log] [blame]
Ian Lartey992bee42010-07-31 00:32:11 +01001/*
2 * wm8741.c -- WM8741 ALSA SoC Audio driver
3 *
Mark Brown656baae2012-05-23 12:39:07 +01004 * Copyright 2010-1 Wolfson Microelectronics plc
Ian Lartey992bee42010-07-31 00:32:11 +01005 *
6 * Author: Ian Lartey <ian@opensource.wolfsonmicro.com>
7 *
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
14#include <linux/module.h>
15#include <linux/moduleparam.h>
16#include <linux/init.h>
17#include <linux/delay.h>
18#include <linux/pm.h>
19#include <linux/i2c.h>
Mark Brown39e9b8d2011-08-03 17:30:57 +090020#include <linux/spi/spi.h>
Ian Lartey992bee42010-07-31 00:32:11 +010021#include <linux/regulator/consumer.h>
22#include <linux/slab.h>
Mark Brown80080ec2011-08-03 17:31:26 +090023#include <linux/of_device.h>
Ian Lartey992bee42010-07-31 00:32:11 +010024#include <sound/core.h>
25#include <sound/pcm.h>
26#include <sound/pcm_params.h>
27#include <sound/soc.h>
Ian Lartey992bee42010-07-31 00:32:11 +010028#include <sound/initval.h>
29#include <sound/tlv.h>
30
31#include "wm8741.h"
32
Ian Lartey992bee42010-07-31 00:32:11 +010033#define WM8741_NUM_SUPPLIES 2
34static const char *wm8741_supply_names[WM8741_NUM_SUPPLIES] = {
35 "AVDD",
36 "DVDD",
37};
38
Ian Lartey3fe4a5e2010-08-27 15:26:27 +010039#define WM8741_NUM_RATES 6
Ian Lartey992bee42010-07-31 00:32:11 +010040
41/* codec private data */
42struct wm8741_priv {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000043 enum snd_soc_control_type control_type;
Ian Lartey992bee42010-07-31 00:32:11 +010044 struct regulator_bulk_data supplies[WM8741_NUM_SUPPLIES];
45 unsigned int sysclk;
Ian Lartey3fe4a5e2010-08-27 15:26:27 +010046 struct snd_pcm_hw_constraint_list *sysclk_constraints;
Ian Lartey992bee42010-07-31 00:32:11 +010047};
48
49static const u16 wm8741_reg_defaults[WM8741_REGISTER_COUNT] = {
50 0x0000, /* R0 - DACLLSB Attenuation */
51 0x0000, /* R1 - DACLMSB Attenuation */
52 0x0000, /* R2 - DACRLSB Attenuation */
53 0x0000, /* R3 - DACRMSB Attenuation */
54 0x0000, /* R4 - Volume Control */
55 0x000A, /* R5 - Format Control */
56 0x0000, /* R6 - Filter Control */
57 0x0000, /* R7 - Mode Control 1 */
58 0x0002, /* R8 - Mode Control 2 */
59 0x0000, /* R9 - Reset */
60 0x0002, /* R32 - ADDITONAL_CONTROL_1 */
61};
62
63
64static int wm8741_reset(struct snd_soc_codec *codec)
65{
66 return snd_soc_write(codec, WM8741_RESET, 0);
67}
68
69static const DECLARE_TLV_DB_SCALE(dac_tlv_fine, -12700, 13, 0);
70static const DECLARE_TLV_DB_SCALE(dac_tlv, -12700, 400, 0);
71
72static const struct snd_kcontrol_new wm8741_snd_controls[] = {
73SOC_DOUBLE_R_TLV("Fine Playback Volume", WM8741_DACLLSB_ATTENUATION,
74 WM8741_DACRLSB_ATTENUATION, 1, 255, 1, dac_tlv_fine),
75SOC_DOUBLE_R_TLV("Playback Volume", WM8741_DACLMSB_ATTENUATION,
76 WM8741_DACRMSB_ATTENUATION, 0, 511, 1, dac_tlv),
77};
78
79static const struct snd_soc_dapm_widget wm8741_dapm_widgets[] = {
80SND_SOC_DAPM_DAC("DACL", "Playback", SND_SOC_NOPM, 0, 0),
81SND_SOC_DAPM_DAC("DACR", "Playback", SND_SOC_NOPM, 0, 0),
82SND_SOC_DAPM_OUTPUT("VOUTLP"),
83SND_SOC_DAPM_OUTPUT("VOUTLN"),
84SND_SOC_DAPM_OUTPUT("VOUTRP"),
85SND_SOC_DAPM_OUTPUT("VOUTRN"),
86};
87
Mark Brown0e627802011-12-03 17:15:06 +000088static const struct snd_soc_dapm_route wm8741_dapm_routes[] = {
Ian Lartey992bee42010-07-31 00:32:11 +010089 { "VOUTLP", NULL, "DACL" },
90 { "VOUTLN", NULL, "DACL" },
91 { "VOUTRP", NULL, "DACR" },
92 { "VOUTRN", NULL, "DACR" },
93};
94
Ian Lartey992bee42010-07-31 00:32:11 +010095static struct {
96 int value;
97 int ratio;
98} lrclk_ratios[WM8741_NUM_RATES] = {
Ian Lartey3fe4a5e2010-08-27 15:26:27 +010099 { 1, 128 },
100 { 2, 192 },
101 { 3, 256 },
102 { 4, 384 },
103 { 5, 512 },
104 { 6, 768 },
105};
106
107static unsigned int rates_11289[] = {
108 44100, 88235,
109};
110
111static struct snd_pcm_hw_constraint_list constraints_11289 = {
112 .count = ARRAY_SIZE(rates_11289),
113 .list = rates_11289,
114};
115
116static unsigned int rates_12288[] = {
117 32000, 48000, 96000,
118};
119
120static struct snd_pcm_hw_constraint_list constraints_12288 = {
121 .count = ARRAY_SIZE(rates_12288),
122 .list = rates_12288,
123};
124
125static unsigned int rates_16384[] = {
126 32000,
127};
128
129static struct snd_pcm_hw_constraint_list constraints_16384 = {
130 .count = ARRAY_SIZE(rates_16384),
131 .list = rates_16384,
132};
133
134static unsigned int rates_16934[] = {
135 44100, 88235,
136};
137
138static struct snd_pcm_hw_constraint_list constraints_16934 = {
139 .count = ARRAY_SIZE(rates_16934),
140 .list = rates_16934,
141};
142
143static unsigned int rates_18432[] = {
144 48000, 96000,
145};
146
147static struct snd_pcm_hw_constraint_list constraints_18432 = {
148 .count = ARRAY_SIZE(rates_18432),
149 .list = rates_18432,
150};
151
152static unsigned int rates_22579[] = {
153 44100, 88235, 1764000
154};
155
156static struct snd_pcm_hw_constraint_list constraints_22579 = {
157 .count = ARRAY_SIZE(rates_22579),
158 .list = rates_22579,
159};
160
161static unsigned int rates_24576[] = {
162 32000, 48000, 96000, 192000
163};
164
165static struct snd_pcm_hw_constraint_list constraints_24576 = {
166 .count = ARRAY_SIZE(rates_24576),
167 .list = rates_24576,
168};
169
170static unsigned int rates_36864[] = {
171 48000, 96000, 19200
172};
173
174static struct snd_pcm_hw_constraint_list constraints_36864 = {
175 .count = ARRAY_SIZE(rates_36864),
176 .list = rates_36864,
Ian Lartey992bee42010-07-31 00:32:11 +0100177};
178
179
180static int wm8741_startup(struct snd_pcm_substream *substream,
181 struct snd_soc_dai *dai)
182{
183 struct snd_soc_codec *codec = dai->codec;
184 struct wm8741_priv *wm8741 = snd_soc_codec_get_drvdata(codec);
185
186 /* The set of sample rates that can be supported depends on the
187 * MCLK supplied to the CODEC - enforce this.
188 */
189 if (!wm8741->sysclk) {
190 dev_err(codec->dev,
191 "No MCLK configured, call set_sysclk() on init\n");
192 return -EINVAL;
193 }
194
195 snd_pcm_hw_constraint_list(substream->runtime, 0,
196 SNDRV_PCM_HW_PARAM_RATE,
Ian Lartey3fe4a5e2010-08-27 15:26:27 +0100197 wm8741->sysclk_constraints);
Ian Lartey992bee42010-07-31 00:32:11 +0100198
199 return 0;
200}
201
202static int wm8741_hw_params(struct snd_pcm_substream *substream,
203 struct snd_pcm_hw_params *params,
204 struct snd_soc_dai *dai)
205{
Mark Browne6968a12012-04-04 15:58:16 +0100206 struct snd_soc_codec *codec = dai->codec;
Ian Lartey992bee42010-07-31 00:32:11 +0100207 struct wm8741_priv *wm8741 = snd_soc_codec_get_drvdata(codec);
208 u16 iface = snd_soc_read(codec, WM8741_FORMAT_CONTROL) & 0x1FC;
209 int i;
210
211 /* Find a supported LRCLK ratio */
212 for (i = 0; i < ARRAY_SIZE(lrclk_ratios); i++) {
213 if (wm8741->sysclk / params_rate(params) ==
214 lrclk_ratios[i].ratio)
215 break;
216 }
217
218 /* Should never happen, should be handled by constraints */
219 if (i == ARRAY_SIZE(lrclk_ratios)) {
220 dev_err(codec->dev, "MCLK/fs ratio %d unsupported\n",
221 wm8741->sysclk / params_rate(params));
222 return -EINVAL;
223 }
224
225 /* bit size */
226 switch (params_format(params)) {
227 case SNDRV_PCM_FORMAT_S16_LE:
228 break;
229 case SNDRV_PCM_FORMAT_S20_3LE:
230 iface |= 0x0001;
231 break;
232 case SNDRV_PCM_FORMAT_S24_LE:
233 iface |= 0x0002;
234 break;
235 case SNDRV_PCM_FORMAT_S32_LE:
236 iface |= 0x0003;
237 break;
238 default:
239 dev_dbg(codec->dev, "wm8741_hw_params: Unsupported bit size param = %d",
240 params_format(params));
241 return -EINVAL;
242 }
243
244 dev_dbg(codec->dev, "wm8741_hw_params: bit size param = %d",
245 params_format(params));
246
247 snd_soc_write(codec, WM8741_FORMAT_CONTROL, iface);
248 return 0;
249}
250
251static int wm8741_set_dai_sysclk(struct snd_soc_dai *codec_dai,
252 int clk_id, unsigned int freq, int dir)
253{
254 struct snd_soc_codec *codec = codec_dai->codec;
255 struct wm8741_priv *wm8741 = snd_soc_codec_get_drvdata(codec);
Ian Lartey992bee42010-07-31 00:32:11 +0100256
257 dev_dbg(codec->dev, "wm8741_set_dai_sysclk info: freq=%dHz\n", freq);
258
Ian Lartey3fe4a5e2010-08-27 15:26:27 +0100259 switch (freq) {
260 case 11289600:
261 wm8741->sysclk_constraints = &constraints_11289;
262 wm8741->sysclk = freq;
263 return 0;
Ian Lartey992bee42010-07-31 00:32:11 +0100264
Ian Lartey3fe4a5e2010-08-27 15:26:27 +0100265 case 12288000:
266 wm8741->sysclk_constraints = &constraints_12288;
267 wm8741->sysclk = freq;
268 return 0;
Ian Lartey992bee42010-07-31 00:32:11 +0100269
Ian Lartey3fe4a5e2010-08-27 15:26:27 +0100270 case 16384000:
271 wm8741->sysclk_constraints = &constraints_16384;
272 wm8741->sysclk = freq;
273 return 0;
Ian Lartey992bee42010-07-31 00:32:11 +0100274
Ian Lartey3fe4a5e2010-08-27 15:26:27 +0100275 case 16934400:
276 wm8741->sysclk_constraints = &constraints_16934;
277 wm8741->sysclk = freq;
278 return 0;
279
280 case 18432000:
281 wm8741->sysclk_constraints = &constraints_18432;
282 wm8741->sysclk = freq;
283 return 0;
284
285 case 22579200:
286 case 33868800:
287 wm8741->sysclk_constraints = &constraints_22579;
288 wm8741->sysclk = freq;
289 return 0;
290
291 case 24576000:
292 wm8741->sysclk_constraints = &constraints_24576;
293 wm8741->sysclk = freq;
294 return 0;
295
296 case 36864000:
297 wm8741->sysclk_constraints = &constraints_36864;
298 wm8741->sysclk = freq;
299 return 0;
Ian Lartey992bee42010-07-31 00:32:11 +0100300 }
Ian Lartey3fe4a5e2010-08-27 15:26:27 +0100301 return -EINVAL;
Ian Lartey992bee42010-07-31 00:32:11 +0100302}
303
304static int wm8741_set_dai_fmt(struct snd_soc_dai *codec_dai,
305 unsigned int fmt)
306{
307 struct snd_soc_codec *codec = codec_dai->codec;
308 u16 iface = snd_soc_read(codec, WM8741_FORMAT_CONTROL) & 0x1C3;
309
310 /* check master/slave audio interface */
311 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
312 case SND_SOC_DAIFMT_CBS_CFS:
313 break;
314 default:
315 return -EINVAL;
316 }
317
318 /* interface format */
319 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
320 case SND_SOC_DAIFMT_I2S:
321 iface |= 0x0008;
322 break;
323 case SND_SOC_DAIFMT_RIGHT_J:
324 break;
325 case SND_SOC_DAIFMT_LEFT_J:
326 iface |= 0x0004;
327 break;
328 case SND_SOC_DAIFMT_DSP_A:
Axel Lin3a340102011-10-17 20:14:56 +0800329 iface |= 0x000C;
Ian Lartey992bee42010-07-31 00:32:11 +0100330 break;
331 case SND_SOC_DAIFMT_DSP_B:
Axel Lin3a340102011-10-17 20:14:56 +0800332 iface |= 0x001C;
Ian Lartey992bee42010-07-31 00:32:11 +0100333 break;
334 default:
335 return -EINVAL;
336 }
337
338 /* clock inversion */
339 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
340 case SND_SOC_DAIFMT_NB_NF:
341 break;
342 case SND_SOC_DAIFMT_IB_IF:
343 iface |= 0x0010;
344 break;
345 case SND_SOC_DAIFMT_IB_NF:
346 iface |= 0x0020;
347 break;
348 case SND_SOC_DAIFMT_NB_IF:
349 iface |= 0x0030;
350 break;
351 default:
352 return -EINVAL;
353 }
354
355
356 dev_dbg(codec->dev, "wm8741_set_dai_fmt: Format=%x, Clock Inv=%x\n",
357 fmt & SND_SOC_DAIFMT_FORMAT_MASK,
358 ((fmt & SND_SOC_DAIFMT_INV_MASK)));
359
360 snd_soc_write(codec, WM8741_FORMAT_CONTROL, iface);
361 return 0;
362}
363
364#define WM8741_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
365 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | \
366 SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 | \
367 SNDRV_PCM_RATE_192000)
368
369#define WM8741_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
370 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
371
Lars-Peter Clausen85e76522011-11-23 11:40:40 +0100372static const struct snd_soc_dai_ops wm8741_dai_ops = {
Ian Lartey992bee42010-07-31 00:32:11 +0100373 .startup = wm8741_startup,
374 .hw_params = wm8741_hw_params,
375 .set_sysclk = wm8741_set_dai_sysclk,
376 .set_fmt = wm8741_set_dai_fmt,
377};
378
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000379static struct snd_soc_dai_driver wm8741_dai = {
Ian Lartey30e2d362010-08-20 17:18:44 +0100380 .name = "wm8741",
Ian Lartey992bee42010-07-31 00:32:11 +0100381 .playback = {
382 .stream_name = "Playback",
383 .channels_min = 2, /* Mono modes not yet supported */
384 .channels_max = 2,
385 .rates = WM8741_RATES,
386 .formats = WM8741_FORMATS,
387 },
388 .ops = &wm8741_dai_ops,
389};
Ian Lartey992bee42010-07-31 00:32:11 +0100390
391#ifdef CONFIG_PM
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000392static int wm8741_resume(struct snd_soc_codec *codec)
Ian Lartey992bee42010-07-31 00:32:11 +0100393{
Axel Lindf3431b2011-10-17 20:16:37 +0800394 snd_soc_cache_sync(codec);
Ian Lartey992bee42010-07-31 00:32:11 +0100395 return 0;
396}
397#else
398#define wm8741_suspend NULL
399#define wm8741_resume NULL
400#endif
401
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000402static int wm8741_probe(struct snd_soc_codec *codec)
Ian Lartey992bee42010-07-31 00:32:11 +0100403{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000404 struct wm8741_priv *wm8741 = snd_soc_codec_get_drvdata(codec);
Ian Lartey992bee42010-07-31 00:32:11 +0100405 int ret = 0;
Mark Brown398575d2011-08-03 17:16:11 +0900406 int i;
407
408 for (i = 0; i < ARRAY_SIZE(wm8741->supplies); i++)
409 wm8741->supplies[i].supply = wm8741_supply_names[i];
410
411 ret = regulator_bulk_get(codec->dev, ARRAY_SIZE(wm8741->supplies),
412 wm8741->supplies);
413 if (ret != 0) {
414 dev_err(codec->dev, "Failed to request supplies: %d\n", ret);
415 goto err;
416 }
417
418 ret = regulator_bulk_enable(ARRAY_SIZE(wm8741->supplies),
419 wm8741->supplies);
420 if (ret != 0) {
421 dev_err(codec->dev, "Failed to enable supplies: %d\n", ret);
422 goto err_get;
423 }
Ian Lartey992bee42010-07-31 00:32:11 +0100424
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000425 ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8741->control_type);
Ian Lartey992bee42010-07-31 00:32:11 +0100426 if (ret != 0) {
427 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
Mark Brown398575d2011-08-03 17:16:11 +0900428 goto err_enable;
Ian Lartey992bee42010-07-31 00:32:11 +0100429 }
430
431 ret = wm8741_reset(codec);
432 if (ret < 0) {
433 dev_err(codec->dev, "Failed to issue reset\n");
Mark Brown398575d2011-08-03 17:16:11 +0900434 goto err_enable;
Ian Lartey992bee42010-07-31 00:32:11 +0100435 }
436
Ian Lartey992bee42010-07-31 00:32:11 +0100437 /* Change some default settings - latch VU */
Mark Browna1b3b5e2010-12-24 16:59:30 +0000438 snd_soc_update_bits(codec, WM8741_DACLLSB_ATTENUATION,
439 WM8741_UPDATELL, WM8741_UPDATELL);
440 snd_soc_update_bits(codec, WM8741_DACLMSB_ATTENUATION,
441 WM8741_UPDATELM, WM8741_UPDATELM);
442 snd_soc_update_bits(codec, WM8741_DACRLSB_ATTENUATION,
443 WM8741_UPDATERL, WM8741_UPDATERL);
Axel Lin9b5999b2011-10-03 11:09:01 +0800444 snd_soc_update_bits(codec, WM8741_DACRMSB_ATTENUATION,
Mark Browna1b3b5e2010-12-24 16:59:30 +0000445 WM8741_UPDATERM, WM8741_UPDATERM);
Ian Lartey992bee42010-07-31 00:32:11 +0100446
Ian Lartey992bee42010-07-31 00:32:11 +0100447 dev_dbg(codec->dev, "Successful registration\n");
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000448 return ret;
Mark Brown398575d2011-08-03 17:16:11 +0900449
450err_enable:
451 regulator_bulk_disable(ARRAY_SIZE(wm8741->supplies), wm8741->supplies);
452err_get:
453 regulator_bulk_free(ARRAY_SIZE(wm8741->supplies), wm8741->supplies);
454err:
455 return ret;
456}
457
458static int wm8741_remove(struct snd_soc_codec *codec)
459{
460 struct wm8741_priv *wm8741 = snd_soc_codec_get_drvdata(codec);
461
462 regulator_bulk_disable(ARRAY_SIZE(wm8741->supplies), wm8741->supplies);
463 regulator_bulk_free(ARRAY_SIZE(wm8741->supplies), wm8741->supplies);
464
465 return 0;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000466}
467
468static struct snd_soc_codec_driver soc_codec_dev_wm8741 = {
469 .probe = wm8741_probe,
Mark Brown398575d2011-08-03 17:16:11 +0900470 .remove = wm8741_remove,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000471 .resume = wm8741_resume,
Dimitris Papastamose5eec342010-09-10 18:14:56 +0100472 .reg_cache_size = ARRAY_SIZE(wm8741_reg_defaults),
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000473 .reg_word_size = sizeof(u16),
Dimitris Papastamos0aa34b12010-11-08 10:41:53 +0000474 .reg_cache_default = wm8741_reg_defaults,
Mark Brown0e627802011-12-03 17:15:06 +0000475
476 .controls = wm8741_snd_controls,
477 .num_controls = ARRAY_SIZE(wm8741_snd_controls),
478 .dapm_widgets = wm8741_dapm_widgets,
479 .num_dapm_widgets = ARRAY_SIZE(wm8741_dapm_widgets),
480 .dapm_routes = wm8741_dapm_routes,
481 .num_dapm_routes = ARRAY_SIZE(wm8741_dapm_routes),
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000482};
483
Mark Brown80080ec2011-08-03 17:31:26 +0900484static const struct of_device_id wm8741_of_match[] = {
485 { .compatible = "wlf,wm8741", },
486 { }
487};
488MODULE_DEVICE_TABLE(of, wm8741_of_match);
489
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000490#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
491static int wm8741_i2c_probe(struct i2c_client *i2c,
492 const struct i2c_device_id *id)
493{
494 struct wm8741_priv *wm8741;
Mark Brown398575d2011-08-03 17:16:11 +0900495 int ret;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000496
Mark Brown5aefb302011-12-03 17:17:05 +0000497 wm8741 = devm_kzalloc(&i2c->dev, sizeof(struct wm8741_priv),
498 GFP_KERNEL);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000499 if (wm8741 == NULL)
500 return -ENOMEM;
501
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000502 i2c_set_clientdata(i2c, wm8741);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000503 wm8741->control_type = SND_SOC_I2C;
504
Mark Brown398575d2011-08-03 17:16:11 +0900505 ret = snd_soc_register_codec(&i2c->dev,
506 &soc_codec_dev_wm8741, &wm8741_dai, 1);
Mark Brown398575d2011-08-03 17:16:11 +0900507
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000508 return ret;
Ian Lartey992bee42010-07-31 00:32:11 +0100509}
510
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000511static int wm8741_i2c_remove(struct i2c_client *client)
Ian Lartey992bee42010-07-31 00:32:11 +0100512{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000513 snd_soc_unregister_codec(&client->dev);
Ian Lartey992bee42010-07-31 00:32:11 +0100514 return 0;
515}
516
517static const struct i2c_device_id wm8741_i2c_id[] = {
518 { "wm8741", 0 },
519 { }
520};
521MODULE_DEVICE_TABLE(i2c, wm8741_i2c_id);
522
Ian Lartey992bee42010-07-31 00:32:11 +0100523static struct i2c_driver wm8741_i2c_driver = {
524 .driver = {
Mark Brown0473e612011-08-03 16:52:10 +0900525 .name = "wm8741",
Ian Lartey992bee42010-07-31 00:32:11 +0100526 .owner = THIS_MODULE,
Mark Brown80080ec2011-08-03 17:31:26 +0900527 .of_match_table = wm8741_of_match,
Ian Lartey992bee42010-07-31 00:32:11 +0100528 },
529 .probe = wm8741_i2c_probe,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000530 .remove = wm8741_i2c_remove,
Ian Lartey992bee42010-07-31 00:32:11 +0100531 .id_table = wm8741_i2c_id,
532};
533#endif
534
Mark Brown39e9b8d2011-08-03 17:30:57 +0900535#if defined(CONFIG_SPI_MASTER)
536static int __devinit wm8741_spi_probe(struct spi_device *spi)
537{
538 struct wm8741_priv *wm8741;
539 int ret;
540
Mark Brown5aefb302011-12-03 17:17:05 +0000541 wm8741 = devm_kzalloc(&spi->dev, sizeof(struct wm8741_priv),
542 GFP_KERNEL);
Mark Brown39e9b8d2011-08-03 17:30:57 +0900543 if (wm8741 == NULL)
544 return -ENOMEM;
545
546 wm8741->control_type = SND_SOC_SPI;
547 spi_set_drvdata(spi, wm8741);
548
549 ret = snd_soc_register_codec(&spi->dev,
550 &soc_codec_dev_wm8741, &wm8741_dai, 1);
Mark Brown39e9b8d2011-08-03 17:30:57 +0900551 return ret;
552}
553
554static int __devexit wm8741_spi_remove(struct spi_device *spi)
555{
556 snd_soc_unregister_codec(&spi->dev);
Mark Brown39e9b8d2011-08-03 17:30:57 +0900557 return 0;
558}
559
560static struct spi_driver wm8741_spi_driver = {
561 .driver = {
562 .name = "wm8741",
563 .owner = THIS_MODULE,
Mark Brown80080ec2011-08-03 17:31:26 +0900564 .of_match_table = wm8741_of_match,
Mark Brown39e9b8d2011-08-03 17:30:57 +0900565 },
566 .probe = wm8741_spi_probe,
567 .remove = __devexit_p(wm8741_spi_remove),
568};
569#endif /* CONFIG_SPI_MASTER */
570
Ian Lartey992bee42010-07-31 00:32:11 +0100571static int __init wm8741_modinit(void)
572{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000573 int ret = 0;
574
Ian Lartey992bee42010-07-31 00:32:11 +0100575#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
576 ret = i2c_add_driver(&wm8741_i2c_driver);
Ian Lartey3fe4a5e2010-08-27 15:26:27 +0100577 if (ret != 0)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000578 pr_err("Failed to register WM8741 I2C driver: %d\n", ret);
Ian Lartey992bee42010-07-31 00:32:11 +0100579#endif
Mark Brown39e9b8d2011-08-03 17:30:57 +0900580#if defined(CONFIG_SPI_MASTER)
581 ret = spi_register_driver(&wm8741_spi_driver);
582 if (ret != 0) {
583 printk(KERN_ERR "Failed to register wm8741 SPI driver: %d\n",
584 ret);
585 }
586#endif
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000587
588 return ret;
Ian Lartey992bee42010-07-31 00:32:11 +0100589}
590module_init(wm8741_modinit);
591
592static void __exit wm8741_exit(void)
593{
Mark Brown39e9b8d2011-08-03 17:30:57 +0900594#if defined(CONFIG_SPI_MASTER)
595 spi_unregister_driver(&wm8741_spi_driver);
596#endif
Ian Lartey992bee42010-07-31 00:32:11 +0100597#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
598 i2c_del_driver(&wm8741_i2c_driver);
599#endif
600}
601module_exit(wm8741_exit);
602
603MODULE_DESCRIPTION("ASoC WM8741 driver");
604MODULE_AUTHOR("Ian Lartey <ian@opensource.wolfsonmicro.com>");
605MODULE_LICENSE("GPL");