IPVS: netns, misc init_net removal in core.
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / sound / soc / codecs / wm8731.c
blobe725c09a3e79bf7bafa6fda17ee6112fd629e6ee
1 /*
2 * wm8731.c -- WM8731 ALSA SoC Audio driver
4 * Copyright 2005 Openedhand Ltd.
6 * Author: Richard Purdie <richard@openedhand.com>
8 * Based on wm8753.c by Liam Girdwood
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
15 #include <linux/module.h>
16 #include <linux/moduleparam.h>
17 #include <linux/init.h>
18 #include <linux/delay.h>
19 #include <linux/pm.h>
20 #include <linux/i2c.h>
21 #include <linux/slab.h>
22 #include <linux/platform_device.h>
23 #include <linux/regulator/consumer.h>
24 #include <linux/spi/spi.h>
25 #include <sound/core.h>
26 #include <sound/pcm.h>
27 #include <sound/pcm_params.h>
28 #include <sound/soc.h>
29 #include <sound/soc-dapm.h>
30 #include <sound/initval.h>
31 #include <sound/tlv.h>
33 #include "wm8731.h"
35 #define WM8731_NUM_SUPPLIES 4
36 static const char *wm8731_supply_names[WM8731_NUM_SUPPLIES] = {
37 "AVDD",
38 "HPVDD",
39 "DCVDD",
40 "DBVDD",
43 /* codec private data */
44 struct wm8731_priv {
45 enum snd_soc_control_type control_type;
46 struct regulator_bulk_data supplies[WM8731_NUM_SUPPLIES];
47 u16 reg_cache[WM8731_CACHEREGNUM];
48 unsigned int sysclk;
49 int sysclk_type;
54 * wm8731 register cache
55 * We can't read the WM8731 register space when we are
56 * using 2 wire for device control, so we cache them instead.
57 * There is no point in caching the reset register
59 static const u16 wm8731_reg[WM8731_CACHEREGNUM] = {
60 0x0097, 0x0097, 0x0079, 0x0079,
61 0x000a, 0x0008, 0x009f, 0x000a,
62 0x0000, 0x0000
65 #define wm8731_reset(c) snd_soc_write(c, WM8731_RESET, 0)
67 static const char *wm8731_input_select[] = {"Line In", "Mic"};
68 static const char *wm8731_deemph[] = {"None", "32Khz", "44.1Khz", "48Khz"};
70 static const struct soc_enum wm8731_enum[] = {
71 SOC_ENUM_SINGLE(WM8731_APANA, 2, 2, wm8731_input_select),
72 SOC_ENUM_SINGLE(WM8731_APDIGI, 1, 4, wm8731_deemph),
75 static const DECLARE_TLV_DB_SCALE(in_tlv, -3450, 150, 0);
76 static const DECLARE_TLV_DB_SCALE(sidetone_tlv, -1500, 300, 0);
77 static const DECLARE_TLV_DB_SCALE(out_tlv, -12100, 100, 1);
79 static const struct snd_kcontrol_new wm8731_snd_controls[] = {
81 SOC_DOUBLE_R_TLV("Master Playback Volume", WM8731_LOUT1V, WM8731_ROUT1V,
82 0, 127, 0, out_tlv),
83 SOC_DOUBLE_R("Master Playback ZC Switch", WM8731_LOUT1V, WM8731_ROUT1V,
84 7, 1, 0),
86 SOC_DOUBLE_R_TLV("Capture Volume", WM8731_LINVOL, WM8731_RINVOL, 0, 31, 0,
87 in_tlv),
88 SOC_DOUBLE_R("Line Capture Switch", WM8731_LINVOL, WM8731_RINVOL, 7, 1, 1),
90 SOC_SINGLE("Mic Boost (+20dB)", WM8731_APANA, 0, 1, 0),
91 SOC_SINGLE("Mic Capture Switch", WM8731_APANA, 1, 1, 1),
93 SOC_SINGLE_TLV("Sidetone Playback Volume", WM8731_APANA, 6, 3, 1,
94 sidetone_tlv),
96 SOC_SINGLE("ADC High Pass Filter Switch", WM8731_APDIGI, 0, 1, 1),
97 SOC_SINGLE("Store DC Offset Switch", WM8731_APDIGI, 4, 1, 0),
99 SOC_ENUM("Playback De-emphasis", wm8731_enum[1]),
102 /* Output Mixer */
103 static const struct snd_kcontrol_new wm8731_output_mixer_controls[] = {
104 SOC_DAPM_SINGLE("Line Bypass Switch", WM8731_APANA, 3, 1, 0),
105 SOC_DAPM_SINGLE("Mic Sidetone Switch", WM8731_APANA, 5, 1, 0),
106 SOC_DAPM_SINGLE("HiFi Playback Switch", WM8731_APANA, 4, 1, 0),
109 /* Input mux */
110 static const struct snd_kcontrol_new wm8731_input_mux_controls =
111 SOC_DAPM_ENUM("Input Select", wm8731_enum[0]);
113 static const struct snd_soc_dapm_widget wm8731_dapm_widgets[] = {
114 SND_SOC_DAPM_SUPPLY("OSC", WM8731_PWR, 5, 1, NULL, 0),
115 SND_SOC_DAPM_MIXER("Output Mixer", WM8731_PWR, 4, 1,
116 &wm8731_output_mixer_controls[0],
117 ARRAY_SIZE(wm8731_output_mixer_controls)),
118 SND_SOC_DAPM_DAC("DAC", "HiFi Playback", WM8731_PWR, 3, 1),
119 SND_SOC_DAPM_OUTPUT("LOUT"),
120 SND_SOC_DAPM_OUTPUT("LHPOUT"),
121 SND_SOC_DAPM_OUTPUT("ROUT"),
122 SND_SOC_DAPM_OUTPUT("RHPOUT"),
123 SND_SOC_DAPM_ADC("ADC", "HiFi Capture", WM8731_PWR, 2, 1),
124 SND_SOC_DAPM_MUX("Input Mux", SND_SOC_NOPM, 0, 0, &wm8731_input_mux_controls),
125 SND_SOC_DAPM_PGA("Line Input", WM8731_PWR, 0, 1, NULL, 0),
126 SND_SOC_DAPM_MICBIAS("Mic Bias", WM8731_PWR, 1, 1),
127 SND_SOC_DAPM_INPUT("MICIN"),
128 SND_SOC_DAPM_INPUT("RLINEIN"),
129 SND_SOC_DAPM_INPUT("LLINEIN"),
132 static int wm8731_check_osc(struct snd_soc_dapm_widget *source,
133 struct snd_soc_dapm_widget *sink)
135 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(source->codec);
137 return wm8731->sysclk_type == WM8731_SYSCLK_MCLK;
140 static const struct snd_soc_dapm_route intercon[] = {
141 {"DAC", NULL, "OSC", wm8731_check_osc},
142 {"ADC", NULL, "OSC", wm8731_check_osc},
144 /* output mixer */
145 {"Output Mixer", "Line Bypass Switch", "Line Input"},
146 {"Output Mixer", "HiFi Playback Switch", "DAC"},
147 {"Output Mixer", "Mic Sidetone Switch", "Mic Bias"},
149 /* outputs */
150 {"RHPOUT", NULL, "Output Mixer"},
151 {"ROUT", NULL, "Output Mixer"},
152 {"LHPOUT", NULL, "Output Mixer"},
153 {"LOUT", NULL, "Output Mixer"},
155 /* input mux */
156 {"Input Mux", "Line In", "Line Input"},
157 {"Input Mux", "Mic", "Mic Bias"},
158 {"ADC", NULL, "Input Mux"},
160 /* inputs */
161 {"Line Input", NULL, "LLINEIN"},
162 {"Line Input", NULL, "RLINEIN"},
163 {"Mic Bias", NULL, "MICIN"},
166 static int wm8731_add_widgets(struct snd_soc_codec *codec)
168 snd_soc_dapm_new_controls(codec, wm8731_dapm_widgets,
169 ARRAY_SIZE(wm8731_dapm_widgets));
171 snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon));
173 return 0;
176 struct _coeff_div {
177 u32 mclk;
178 u32 rate;
179 u16 fs;
180 u8 sr:4;
181 u8 bosr:1;
182 u8 usb:1;
185 /* codec mclk clock divider coefficients */
186 static const struct _coeff_div coeff_div[] = {
187 /* 48k */
188 {12288000, 48000, 256, 0x0, 0x0, 0x0},
189 {18432000, 48000, 384, 0x0, 0x1, 0x0},
190 {12000000, 48000, 250, 0x0, 0x0, 0x1},
192 /* 32k */
193 {12288000, 32000, 384, 0x6, 0x0, 0x0},
194 {18432000, 32000, 576, 0x6, 0x1, 0x0},
195 {12000000, 32000, 375, 0x6, 0x0, 0x1},
197 /* 8k */
198 {12288000, 8000, 1536, 0x3, 0x0, 0x0},
199 {18432000, 8000, 2304, 0x3, 0x1, 0x0},
200 {11289600, 8000, 1408, 0xb, 0x0, 0x0},
201 {16934400, 8000, 2112, 0xb, 0x1, 0x0},
202 {12000000, 8000, 1500, 0x3, 0x0, 0x1},
204 /* 96k */
205 {12288000, 96000, 128, 0x7, 0x0, 0x0},
206 {18432000, 96000, 192, 0x7, 0x1, 0x0},
207 {12000000, 96000, 125, 0x7, 0x0, 0x1},
209 /* 44.1k */
210 {11289600, 44100, 256, 0x8, 0x0, 0x0},
211 {16934400, 44100, 384, 0x8, 0x1, 0x0},
212 {12000000, 44100, 272, 0x8, 0x1, 0x1},
214 /* 88.2k */
215 {11289600, 88200, 128, 0xf, 0x0, 0x0},
216 {16934400, 88200, 192, 0xf, 0x1, 0x0},
217 {12000000, 88200, 136, 0xf, 0x1, 0x1},
220 static inline int get_coeff(int mclk, int rate)
222 int i;
224 for (i = 0; i < ARRAY_SIZE(coeff_div); i++) {
225 if (coeff_div[i].rate == rate && coeff_div[i].mclk == mclk)
226 return i;
228 return 0;
231 static int wm8731_hw_params(struct snd_pcm_substream *substream,
232 struct snd_pcm_hw_params *params,
233 struct snd_soc_dai *dai)
235 struct snd_soc_codec *codec = dai->codec;
236 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec);
237 u16 iface = snd_soc_read(codec, WM8731_IFACE) & 0xfff3;
238 int i = get_coeff(wm8731->sysclk, params_rate(params));
239 u16 srate = (coeff_div[i].sr << 2) |
240 (coeff_div[i].bosr << 1) | coeff_div[i].usb;
242 snd_soc_write(codec, WM8731_SRATE, srate);
244 /* bit size */
245 switch (params_format(params)) {
246 case SNDRV_PCM_FORMAT_S16_LE:
247 break;
248 case SNDRV_PCM_FORMAT_S20_3LE:
249 iface |= 0x0004;
250 break;
251 case SNDRV_PCM_FORMAT_S24_LE:
252 iface |= 0x0008;
253 break;
256 snd_soc_write(codec, WM8731_IFACE, iface);
257 return 0;
260 static int wm8731_pcm_prepare(struct snd_pcm_substream *substream,
261 struct snd_soc_dai *dai)
263 struct snd_soc_codec *codec = dai->codec;
265 /* set active */
266 snd_soc_write(codec, WM8731_ACTIVE, 0x0001);
268 return 0;
271 static void wm8731_shutdown(struct snd_pcm_substream *substream,
272 struct snd_soc_dai *dai)
274 struct snd_soc_codec *codec = dai->codec;
276 /* deactivate */
277 if (!codec->active) {
278 udelay(50);
279 snd_soc_write(codec, WM8731_ACTIVE, 0x0);
283 static int wm8731_mute(struct snd_soc_dai *dai, int mute)
285 struct snd_soc_codec *codec = dai->codec;
286 u16 mute_reg = snd_soc_read(codec, WM8731_APDIGI) & 0xfff7;
288 if (mute)
289 snd_soc_write(codec, WM8731_APDIGI, mute_reg | 0x8);
290 else
291 snd_soc_write(codec, WM8731_APDIGI, mute_reg);
292 return 0;
295 static int wm8731_set_dai_sysclk(struct snd_soc_dai *codec_dai,
296 int clk_id, unsigned int freq, int dir)
298 struct snd_soc_codec *codec = codec_dai->codec;
299 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec);
301 switch (clk_id) {
302 case WM8731_SYSCLK_XTAL:
303 case WM8731_SYSCLK_MCLK:
304 wm8731->sysclk_type = clk_id;
305 break;
306 default:
307 return -EINVAL;
310 switch (freq) {
311 case 11289600:
312 case 12000000:
313 case 12288000:
314 case 16934400:
315 case 18432000:
316 wm8731->sysclk = freq;
317 break;
318 default:
319 return -EINVAL;
322 snd_soc_dapm_sync(codec);
324 return 0;
328 static int wm8731_set_dai_fmt(struct snd_soc_dai *codec_dai,
329 unsigned int fmt)
331 struct snd_soc_codec *codec = codec_dai->codec;
332 u16 iface = 0;
334 /* set master/slave audio interface */
335 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
336 case SND_SOC_DAIFMT_CBM_CFM:
337 iface |= 0x0040;
338 break;
339 case SND_SOC_DAIFMT_CBS_CFS:
340 break;
341 default:
342 return -EINVAL;
345 /* interface format */
346 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
347 case SND_SOC_DAIFMT_I2S:
348 iface |= 0x0002;
349 break;
350 case SND_SOC_DAIFMT_RIGHT_J:
351 break;
352 case SND_SOC_DAIFMT_LEFT_J:
353 iface |= 0x0001;
354 break;
355 case SND_SOC_DAIFMT_DSP_A:
356 iface |= 0x0003;
357 break;
358 case SND_SOC_DAIFMT_DSP_B:
359 iface |= 0x0013;
360 break;
361 default:
362 return -EINVAL;
365 /* clock inversion */
366 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
367 case SND_SOC_DAIFMT_NB_NF:
368 break;
369 case SND_SOC_DAIFMT_IB_IF:
370 iface |= 0x0090;
371 break;
372 case SND_SOC_DAIFMT_IB_NF:
373 iface |= 0x0080;
374 break;
375 case SND_SOC_DAIFMT_NB_IF:
376 iface |= 0x0010;
377 break;
378 default:
379 return -EINVAL;
382 /* set iface */
383 snd_soc_write(codec, WM8731_IFACE, iface);
384 return 0;
387 static int wm8731_set_bias_level(struct snd_soc_codec *codec,
388 enum snd_soc_bias_level level)
390 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec);
391 int i, ret;
392 u8 data[2];
393 u16 *cache = codec->reg_cache;
394 u16 reg;
396 switch (level) {
397 case SND_SOC_BIAS_ON:
398 break;
399 case SND_SOC_BIAS_PREPARE:
400 break;
401 case SND_SOC_BIAS_STANDBY:
402 if (codec->bias_level == SND_SOC_BIAS_OFF) {
403 ret = regulator_bulk_enable(ARRAY_SIZE(wm8731->supplies),
404 wm8731->supplies);
405 if (ret != 0)
406 return ret;
408 /* Sync reg_cache with the hardware */
409 for (i = 0; i < ARRAY_SIZE(wm8731_reg); i++) {
410 if (cache[i] == wm8731_reg[i])
411 continue;
413 data[0] = (i << 1) | ((cache[i] >> 8)
414 & 0x0001);
415 data[1] = cache[i] & 0x00ff;
416 codec->hw_write(codec->control_data, data, 2);
420 /* Clear PWROFF, gate CLKOUT, everything else as-is */
421 reg = snd_soc_read(codec, WM8731_PWR) & 0xff7f;
422 snd_soc_write(codec, WM8731_PWR, reg | 0x0040);
423 break;
424 case SND_SOC_BIAS_OFF:
425 snd_soc_write(codec, WM8731_ACTIVE, 0x0);
426 snd_soc_write(codec, WM8731_PWR, 0xffff);
427 regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies),
428 wm8731->supplies);
429 break;
431 codec->bias_level = level;
432 return 0;
435 #define WM8731_RATES SNDRV_PCM_RATE_8000_96000
437 #define WM8731_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
438 SNDRV_PCM_FMTBIT_S24_LE)
440 static struct snd_soc_dai_ops wm8731_dai_ops = {
441 .prepare = wm8731_pcm_prepare,
442 .hw_params = wm8731_hw_params,
443 .shutdown = wm8731_shutdown,
444 .digital_mute = wm8731_mute,
445 .set_sysclk = wm8731_set_dai_sysclk,
446 .set_fmt = wm8731_set_dai_fmt,
449 static struct snd_soc_dai_driver wm8731_dai = {
450 .name = "wm8731-hifi",
451 .playback = {
452 .stream_name = "Playback",
453 .channels_min = 1,
454 .channels_max = 2,
455 .rates = WM8731_RATES,
456 .formats = WM8731_FORMATS,},
457 .capture = {
458 .stream_name = "Capture",
459 .channels_min = 1,
460 .channels_max = 2,
461 .rates = WM8731_RATES,
462 .formats = WM8731_FORMATS,},
463 .ops = &wm8731_dai_ops,
464 .symmetric_rates = 1,
467 #ifdef CONFIG_PM
468 static int wm8731_suspend(struct snd_soc_codec *codec, pm_message_t state)
470 wm8731_set_bias_level(codec, SND_SOC_BIAS_OFF);
472 return 0;
475 static int wm8731_resume(struct snd_soc_codec *codec)
477 wm8731_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
479 return 0;
481 #else
482 #define wm8731_suspend NULL
483 #define wm8731_resume NULL
484 #endif
486 static int wm8731_probe(struct snd_soc_codec *codec)
488 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec);
489 int ret = 0, i;
491 ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8731->control_type);
492 if (ret < 0) {
493 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
494 return ret;
497 for (i = 0; i < ARRAY_SIZE(wm8731->supplies); i++)
498 wm8731->supplies[i].supply = wm8731_supply_names[i];
500 ret = regulator_bulk_get(codec->dev, ARRAY_SIZE(wm8731->supplies),
501 wm8731->supplies);
502 if (ret != 0) {
503 dev_err(codec->dev, "Failed to request supplies: %d\n", ret);
504 return ret;
507 ret = regulator_bulk_enable(ARRAY_SIZE(wm8731->supplies),
508 wm8731->supplies);
509 if (ret != 0) {
510 dev_err(codec->dev, "Failed to enable supplies: %d\n", ret);
511 goto err_regulator_get;
514 ret = wm8731_reset(codec);
515 if (ret < 0) {
516 dev_err(codec->dev, "Failed to issue reset: %d\n", ret);
517 goto err_regulator_enable;
520 wm8731_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
522 /* Latch the update bits */
523 snd_soc_update_bits(codec, WM8731_LOUT1V, 0x100, 0);
524 snd_soc_update_bits(codec, WM8731_ROUT1V, 0x100, 0);
525 snd_soc_update_bits(codec, WM8731_LINVOL, 0x100, 0);
526 snd_soc_update_bits(codec, WM8731_RINVOL, 0x100, 0);
528 /* Disable bypass path by default */
529 snd_soc_update_bits(codec, WM8731_APANA, 0x8, 0);
531 snd_soc_add_controls(codec, wm8731_snd_controls,
532 ARRAY_SIZE(wm8731_snd_controls));
533 wm8731_add_widgets(codec);
535 /* Regulators will have been enabled by bias management */
536 regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies), wm8731->supplies);
538 return 0;
540 err_regulator_enable:
541 regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies), wm8731->supplies);
542 err_regulator_get:
543 regulator_bulk_free(ARRAY_SIZE(wm8731->supplies), wm8731->supplies);
545 kfree(wm8731);
546 return ret;
549 /* power down chip */
550 static int wm8731_remove(struct snd_soc_codec *codec)
552 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec);
554 wm8731_set_bias_level(codec, SND_SOC_BIAS_OFF);
556 regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies), wm8731->supplies);
557 regulator_bulk_free(ARRAY_SIZE(wm8731->supplies), wm8731->supplies);
559 return 0;
562 static struct snd_soc_codec_driver soc_codec_dev_wm8731 = {
563 .probe = wm8731_probe,
564 .remove = wm8731_remove,
565 .suspend = wm8731_suspend,
566 .resume = wm8731_resume,
567 .set_bias_level = wm8731_set_bias_level,
568 .reg_cache_size = ARRAY_SIZE(wm8731_reg),
569 .reg_word_size = sizeof(u16),
570 .reg_cache_default = wm8731_reg,
573 #if defined(CONFIG_SPI_MASTER)
574 static int __devinit wm8731_spi_probe(struct spi_device *spi)
576 struct wm8731_priv *wm8731;
577 int ret;
579 wm8731 = kzalloc(sizeof(struct wm8731_priv), GFP_KERNEL);
580 if (wm8731 == NULL)
581 return -ENOMEM;
583 wm8731->control_type = SND_SOC_SPI;
584 spi_set_drvdata(spi, wm8731);
586 ret = snd_soc_register_codec(&spi->dev,
587 &soc_codec_dev_wm8731, &wm8731_dai, 1);
588 if (ret < 0)
589 kfree(wm8731);
590 return ret;
593 static int __devexit wm8731_spi_remove(struct spi_device *spi)
595 snd_soc_unregister_codec(&spi->dev);
596 kfree(spi_get_drvdata(spi));
597 return 0;
600 static struct spi_driver wm8731_spi_driver = {
601 .driver = {
602 .name = "wm8731-codec",
603 .owner = THIS_MODULE,
605 .probe = wm8731_spi_probe,
606 .remove = __devexit_p(wm8731_spi_remove),
608 #endif /* CONFIG_SPI_MASTER */
610 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
611 static __devinit int wm8731_i2c_probe(struct i2c_client *i2c,
612 const struct i2c_device_id *id)
614 struct wm8731_priv *wm8731;
615 int ret;
617 wm8731 = kzalloc(sizeof(struct wm8731_priv), GFP_KERNEL);
618 if (wm8731 == NULL)
619 return -ENOMEM;
621 i2c_set_clientdata(i2c, wm8731);
622 wm8731->control_type = SND_SOC_I2C;
624 ret = snd_soc_register_codec(&i2c->dev,
625 &soc_codec_dev_wm8731, &wm8731_dai, 1);
626 if (ret < 0)
627 kfree(wm8731);
628 return ret;
631 static __devexit int wm8731_i2c_remove(struct i2c_client *client)
633 snd_soc_unregister_codec(&client->dev);
634 kfree(i2c_get_clientdata(client));
635 return 0;
638 static const struct i2c_device_id wm8731_i2c_id[] = {
639 { "wm8731", 0 },
642 MODULE_DEVICE_TABLE(i2c, wm8731_i2c_id);
644 static struct i2c_driver wm8731_i2c_driver = {
645 .driver = {
646 .name = "wm8731-codec",
647 .owner = THIS_MODULE,
649 .probe = wm8731_i2c_probe,
650 .remove = __devexit_p(wm8731_i2c_remove),
651 .id_table = wm8731_i2c_id,
653 #endif
655 static int __init wm8731_modinit(void)
657 int ret = 0;
658 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
659 ret = i2c_add_driver(&wm8731_i2c_driver);
660 if (ret != 0) {
661 printk(KERN_ERR "Failed to register WM8731 I2C driver: %d\n",
662 ret);
664 #endif
665 #if defined(CONFIG_SPI_MASTER)
666 ret = spi_register_driver(&wm8731_spi_driver);
667 if (ret != 0) {
668 printk(KERN_ERR "Failed to register WM8731 SPI driver: %d\n",
669 ret);
671 #endif
672 return ret;
674 module_init(wm8731_modinit);
676 static void __exit wm8731_exit(void)
678 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
679 i2c_del_driver(&wm8731_i2c_driver);
680 #endif
681 #if defined(CONFIG_SPI_MASTER)
682 spi_unregister_driver(&wm8731_spi_driver);
683 #endif
685 module_exit(wm8731_exit);
687 MODULE_DESCRIPTION("ASoC WM8731 driver");
688 MODULE_AUTHOR("Richard Purdie");
689 MODULE_LICENSE("GPL");