blob: 834cf141ea2f5a64c28377626e7b023539279c4b [file] [log] [blame]
Mark Browne88ba012008-08-06 13:18:26 +01001/*
2 * wm8580.c -- WM8580 ALSA Soc Audio driver
3 *
Mark Brown6f7cb442009-03-11 18:31:08 +00004 * Copyright 2008, 2009 Wolfson Microelectronics PLC.
Mark Browne88ba012008-08-06 13:18:26 +01005 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
10 *
11 * Notes:
12 * The WM8580 is a multichannel codec with S/PDIF support, featuring six
13 * DAC channels and two ADC channels.
14 *
15 * Currently only the primary audio interface is supported - S/PDIF and
16 * the secondary audio interfaces are not.
17 */
18
19#include <linux/module.h>
20#include <linux/moduleparam.h>
Mark Browne88ba012008-08-06 13:18:26 +010021#include <linux/kernel.h>
22#include <linux/init.h>
23#include <linux/delay.h>
24#include <linux/pm.h>
25#include <linux/i2c.h>
26#include <linux/platform_device.h>
Mark Browna583cd52009-06-17 17:30:14 +010027#include <linux/regulator/consumer.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090028#include <linux/slab.h>
Mark Browna583cd52009-06-17 17:30:14 +010029
Mark Browne88ba012008-08-06 13:18:26 +010030#include <sound/core.h>
31#include <sound/pcm.h>
32#include <sound/pcm_params.h>
33#include <sound/soc.h>
34#include <sound/soc-dapm.h>
35#include <sound/tlv.h>
36#include <sound/initval.h>
37#include <asm/div64.h>
38
39#include "wm8580.h"
40
Mark Browne88ba012008-08-06 13:18:26 +010041/* WM8580 register space */
42#define WM8580_PLLA1 0x00
43#define WM8580_PLLA2 0x01
44#define WM8580_PLLA3 0x02
45#define WM8580_PLLA4 0x03
46#define WM8580_PLLB1 0x04
47#define WM8580_PLLB2 0x05
48#define WM8580_PLLB3 0x06
49#define WM8580_PLLB4 0x07
50#define WM8580_CLKSEL 0x08
51#define WM8580_PAIF1 0x09
52#define WM8580_PAIF2 0x0A
53#define WM8580_SAIF1 0x0B
54#define WM8580_PAIF3 0x0C
55#define WM8580_PAIF4 0x0D
56#define WM8580_SAIF2 0x0E
57#define WM8580_DAC_CONTROL1 0x0F
58#define WM8580_DAC_CONTROL2 0x10
59#define WM8580_DAC_CONTROL3 0x11
60#define WM8580_DAC_CONTROL4 0x12
61#define WM8580_DAC_CONTROL5 0x13
62#define WM8580_DIGITAL_ATTENUATION_DACL1 0x14
63#define WM8580_DIGITAL_ATTENUATION_DACR1 0x15
64#define WM8580_DIGITAL_ATTENUATION_DACL2 0x16
65#define WM8580_DIGITAL_ATTENUATION_DACR2 0x17
66#define WM8580_DIGITAL_ATTENUATION_DACL3 0x18
67#define WM8580_DIGITAL_ATTENUATION_DACR3 0x19
68#define WM8580_MASTER_DIGITAL_ATTENUATION 0x1C
69#define WM8580_ADC_CONTROL1 0x1D
70#define WM8580_SPDTXCHAN0 0x1E
71#define WM8580_SPDTXCHAN1 0x1F
72#define WM8580_SPDTXCHAN2 0x20
73#define WM8580_SPDTXCHAN3 0x21
74#define WM8580_SPDTXCHAN4 0x22
75#define WM8580_SPDTXCHAN5 0x23
76#define WM8580_SPDMODE 0x24
77#define WM8580_INTMASK 0x25
78#define WM8580_GPO1 0x26
79#define WM8580_GPO2 0x27
80#define WM8580_GPO3 0x28
81#define WM8580_GPO4 0x29
82#define WM8580_GPO5 0x2A
83#define WM8580_INTSTAT 0x2B
84#define WM8580_SPDRXCHAN1 0x2C
85#define WM8580_SPDRXCHAN2 0x2D
86#define WM8580_SPDRXCHAN3 0x2E
87#define WM8580_SPDRXCHAN4 0x2F
88#define WM8580_SPDRXCHAN5 0x30
89#define WM8580_SPDSTAT 0x31
90#define WM8580_PWRDN1 0x32
91#define WM8580_PWRDN2 0x33
92#define WM8580_READBACK 0x34
93#define WM8580_RESET 0x35
94
Mark Brown6f7cb442009-03-11 18:31:08 +000095#define WM8580_MAX_REGISTER 0x35
96
Mark Browne88ba012008-08-06 13:18:26 +010097/* PLLB4 (register 7h) */
98#define WM8580_PLLB4_MCLKOUTSRC_MASK 0x60
99#define WM8580_PLLB4_MCLKOUTSRC_PLLA 0x20
100#define WM8580_PLLB4_MCLKOUTSRC_PLLB 0x40
101#define WM8580_PLLB4_MCLKOUTSRC_OSC 0x60
102
103#define WM8580_PLLB4_CLKOUTSRC_MASK 0x180
104#define WM8580_PLLB4_CLKOUTSRC_PLLACLK 0x080
105#define WM8580_PLLB4_CLKOUTSRC_PLLBCLK 0x100
106#define WM8580_PLLB4_CLKOUTSRC_OSCCLK 0x180
107
108/* CLKSEL (register 8h) */
109#define WM8580_CLKSEL_DAC_CLKSEL_MASK 0x03
110#define WM8580_CLKSEL_DAC_CLKSEL_PLLA 0x01
111#define WM8580_CLKSEL_DAC_CLKSEL_PLLB 0x02
112
113/* AIF control 1 (registers 9h-bh) */
114#define WM8580_AIF_RATE_MASK 0x7
Mark Browne88ba012008-08-06 13:18:26 +0100115#define WM8580_AIF_BCLKSEL_MASK 0x18
Mark Browne88ba012008-08-06 13:18:26 +0100116
117#define WM8580_AIF_MS 0x20
118
119#define WM8580_AIF_CLKSRC_MASK 0xc0
120#define WM8580_AIF_CLKSRC_PLLA 0x40
121#define WM8580_AIF_CLKSRC_PLLB 0x40
122#define WM8580_AIF_CLKSRC_MCLK 0xc0
123
124/* AIF control 2 (registers ch-eh) */
125#define WM8580_AIF_FMT_MASK 0x03
126#define WM8580_AIF_FMT_RIGHTJ 0x00
127#define WM8580_AIF_FMT_LEFTJ 0x01
128#define WM8580_AIF_FMT_I2S 0x02
129#define WM8580_AIF_FMT_DSP 0x03
130
131#define WM8580_AIF_LENGTH_MASK 0x0c
132#define WM8580_AIF_LENGTH_16 0x00
133#define WM8580_AIF_LENGTH_20 0x04
134#define WM8580_AIF_LENGTH_24 0x08
135#define WM8580_AIF_LENGTH_32 0x0c
136
137#define WM8580_AIF_LRP 0x10
138#define WM8580_AIF_BCP 0x20
139
140/* Powerdown Register 1 (register 32h) */
141#define WM8580_PWRDN1_PWDN 0x001
142#define WM8580_PWRDN1_ALLDACPD 0x040
143
144/* Powerdown Register 2 (register 33h) */
145#define WM8580_PWRDN2_OSSCPD 0x001
146#define WM8580_PWRDN2_PLLAPD 0x002
147#define WM8580_PWRDN2_PLLBPD 0x004
148#define WM8580_PWRDN2_SPDIFPD 0x008
149#define WM8580_PWRDN2_SPDIFTXD 0x010
150#define WM8580_PWRDN2_SPDIFRXD 0x020
151
152#define WM8580_DAC_CONTROL5_MUTEALL 0x10
153
154/*
155 * wm8580 register cache
156 * We can't read the WM8580 register space when we
157 * are using 2 wire for device control, so we cache them instead.
158 */
159static const u16 wm8580_reg[] = {
160 0x0121, 0x017e, 0x007d, 0x0014, /*R3*/
161 0x0121, 0x017e, 0x007d, 0x0194, /*R7*/
162 0x001c, 0x0002, 0x0002, 0x00c2, /*R11*/
163 0x0182, 0x0082, 0x000a, 0x0024, /*R15*/
164 0x0009, 0x0000, 0x00ff, 0x0000, /*R19*/
165 0x00ff, 0x00ff, 0x00ff, 0x00ff, /*R23*/
166 0x00ff, 0x00ff, 0x00ff, 0x00ff, /*R27*/
167 0x01f0, 0x0040, 0x0000, 0x0000, /*R31(0x1F)*/
168 0x0000, 0x0000, 0x0031, 0x000b, /*R35*/
169 0x0039, 0x0000, 0x0010, 0x0032, /*R39*/
170 0x0054, 0x0076, 0x0098, 0x0000, /*R43(0x2B)*/
171 0x0000, 0x0000, 0x0000, 0x0000, /*R47*/
172 0x0000, 0x0000, 0x005e, 0x003e, /*R51(0x33)*/
173 0x0000, 0x0000 /*R53*/
174};
175
Mark Brown6f7cb442009-03-11 18:31:08 +0000176struct pll_state {
177 unsigned int in;
178 unsigned int out;
179};
180
Mark Browna583cd52009-06-17 17:30:14 +0100181#define WM8580_NUM_SUPPLIES 3
182static const char *wm8580_supply_names[WM8580_NUM_SUPPLIES] = {
183 "AVDD",
184 "DVDD",
185 "PVDD",
186};
187
Mark Brown6f7cb442009-03-11 18:31:08 +0000188/* codec private data */
189struct wm8580_priv {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000190 enum snd_soc_control_type control_type;
Mark Browna583cd52009-06-17 17:30:14 +0100191 struct regulator_bulk_data supplies[WM8580_NUM_SUPPLIES];
Mark Brown6f7cb442009-03-11 18:31:08 +0000192 u16 reg_cache[WM8580_MAX_REGISTER + 1];
193 struct pll_state a;
194 struct pll_state b;
Mark Brownc5607d82010-08-13 19:05:04 +0100195 int sysclk[2];
Mark Brown6f7cb442009-03-11 18:31:08 +0000196};
197
Mark Browne88ba012008-08-06 13:18:26 +0100198static const DECLARE_TLV_DB_SCALE(dac_tlv, -12750, 50, 1);
199
200static int wm8580_out_vu(struct snd_kcontrol *kcontrol,
201 struct snd_ctl_elem_value *ucontrol)
202{
Mark Brownccb077f2009-04-21 12:57:00 +0100203 struct soc_mixer_control *mc =
204 (struct soc_mixer_control *)kcontrol->private_value;
Mark Browne88ba012008-08-06 13:18:26 +0100205 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Mark Brownf6f1eb12009-07-05 17:57:57 +0100206 u16 *reg_cache = codec->reg_cache;
Mark Brownccb077f2009-04-21 12:57:00 +0100207 unsigned int reg = mc->reg;
208 unsigned int reg2 = mc->rreg;
Mark Browne88ba012008-08-06 13:18:26 +0100209 int ret;
Mark Browne88ba012008-08-06 13:18:26 +0100210
211 /* Clear the register cache so we write without VU set */
Mark Brownf6f1eb12009-07-05 17:57:57 +0100212 reg_cache[reg] = 0;
213 reg_cache[reg2] = 0;
Mark Browne88ba012008-08-06 13:18:26 +0100214
215 ret = snd_soc_put_volsw_2r(kcontrol, ucontrol);
216 if (ret < 0)
217 return ret;
218
219 /* Now write again with the volume update bit set */
Mark Brownf6f1eb12009-07-05 17:57:57 +0100220 snd_soc_update_bits(codec, reg, 0x100, 0x100);
221 snd_soc_update_bits(codec, reg2, 0x100, 0x100);
Mark Browne88ba012008-08-06 13:18:26 +0100222
223 return 0;
224}
225
Mark Brownccb077f2009-04-21 12:57:00 +0100226#define SOC_WM8580_OUT_DOUBLE_R_TLV(xname, reg_left, reg_right, xshift, xmax, \
227 xinvert, tlv_array) \
Mark Browne88ba012008-08-06 13:18:26 +0100228{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
229 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
230 SNDRV_CTL_ELEM_ACCESS_READWRITE, \
231 .tlv.p = (tlv_array), \
232 .info = snd_soc_info_volsw_2r, \
233 .get = snd_soc_get_volsw_2r, .put = wm8580_out_vu, \
Mark Brownccb077f2009-04-21 12:57:00 +0100234 .private_value = (unsigned long)&(struct soc_mixer_control) \
235 {.reg = reg_left, .rreg = reg_right, .shift = xshift, \
236 .max = xmax, .invert = xinvert} }
Mark Browne88ba012008-08-06 13:18:26 +0100237
238static const struct snd_kcontrol_new wm8580_snd_controls[] = {
239SOC_WM8580_OUT_DOUBLE_R_TLV("DAC1 Playback Volume",
240 WM8580_DIGITAL_ATTENUATION_DACL1,
241 WM8580_DIGITAL_ATTENUATION_DACR1,
242 0, 0xff, 0, dac_tlv),
243SOC_WM8580_OUT_DOUBLE_R_TLV("DAC2 Playback Volume",
244 WM8580_DIGITAL_ATTENUATION_DACL2,
245 WM8580_DIGITAL_ATTENUATION_DACR2,
246 0, 0xff, 0, dac_tlv),
247SOC_WM8580_OUT_DOUBLE_R_TLV("DAC3 Playback Volume",
248 WM8580_DIGITAL_ATTENUATION_DACL3,
249 WM8580_DIGITAL_ATTENUATION_DACR3,
250 0, 0xff, 0, dac_tlv),
251
252SOC_SINGLE("DAC1 Deemphasis Switch", WM8580_DAC_CONTROL3, 0, 1, 0),
253SOC_SINGLE("DAC2 Deemphasis Switch", WM8580_DAC_CONTROL3, 1, 1, 0),
254SOC_SINGLE("DAC3 Deemphasis Switch", WM8580_DAC_CONTROL3, 2, 1, 0),
255
256SOC_DOUBLE("DAC1 Invert Switch", WM8580_DAC_CONTROL4, 0, 1, 1, 0),
257SOC_DOUBLE("DAC2 Invert Switch", WM8580_DAC_CONTROL4, 2, 3, 1, 0),
258SOC_DOUBLE("DAC3 Invert Switch", WM8580_DAC_CONTROL4, 4, 5, 1, 0),
259
260SOC_SINGLE("DAC ZC Switch", WM8580_DAC_CONTROL5, 5, 1, 0),
261SOC_SINGLE("DAC1 Switch", WM8580_DAC_CONTROL5, 0, 1, 0),
262SOC_SINGLE("DAC2 Switch", WM8580_DAC_CONTROL5, 1, 1, 0),
263SOC_SINGLE("DAC3 Switch", WM8580_DAC_CONTROL5, 2, 1, 0),
264
Mark Browndacfe9f2010-08-13 20:01:32 +0100265SOC_DOUBLE("Capture Switch", WM8580_ADC_CONTROL1, 0, 1, 1, 1),
Mark Brown6f341d142010-08-06 18:14:09 +0100266SOC_SINGLE("Capture High-Pass Filter Switch", WM8580_ADC_CONTROL1, 4, 1, 0),
Mark Browne88ba012008-08-06 13:18:26 +0100267};
268
Mark Browne88ba012008-08-06 13:18:26 +0100269static const struct snd_soc_dapm_widget wm8580_dapm_widgets[] = {
270SND_SOC_DAPM_DAC("DAC1", "Playback", WM8580_PWRDN1, 2, 1),
271SND_SOC_DAPM_DAC("DAC2", "Playback", WM8580_PWRDN1, 3, 1),
272SND_SOC_DAPM_DAC("DAC3", "Playback", WM8580_PWRDN1, 4, 1),
273
274SND_SOC_DAPM_OUTPUT("VOUT1L"),
275SND_SOC_DAPM_OUTPUT("VOUT1R"),
276SND_SOC_DAPM_OUTPUT("VOUT2L"),
277SND_SOC_DAPM_OUTPUT("VOUT2R"),
278SND_SOC_DAPM_OUTPUT("VOUT3L"),
279SND_SOC_DAPM_OUTPUT("VOUT3R"),
280
281SND_SOC_DAPM_ADC("ADC", "Capture", WM8580_PWRDN1, 1, 1),
282
283SND_SOC_DAPM_INPUT("AINL"),
284SND_SOC_DAPM_INPUT("AINR"),
285};
286
287static const struct snd_soc_dapm_route audio_map[] = {
288 { "VOUT1L", NULL, "DAC1" },
289 { "VOUT1R", NULL, "DAC1" },
290
291 { "VOUT2L", NULL, "DAC2" },
292 { "VOUT2R", NULL, "DAC2" },
293
294 { "VOUT3L", NULL, "DAC3" },
295 { "VOUT3R", NULL, "DAC3" },
296
297 { "ADC", NULL, "AINL" },
298 { "ADC", NULL, "AINR" },
299};
300
301static int wm8580_add_widgets(struct snd_soc_codec *codec)
302{
303 snd_soc_dapm_new_controls(codec, wm8580_dapm_widgets,
304 ARRAY_SIZE(wm8580_dapm_widgets));
305
306 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
307
Mark Browne88ba012008-08-06 13:18:26 +0100308 return 0;
309}
310
311/* PLL divisors */
312struct _pll_div {
313 u32 prescale:1;
314 u32 postscale:1;
315 u32 freqmode:2;
316 u32 n:4;
317 u32 k:24;
318};
319
320/* The size in bits of the pll divide */
321#define FIXED_PLL_SIZE (1 << 22)
322
323/* PLL rate to output rate divisions */
324static struct {
325 unsigned int div;
326 unsigned int freqmode;
327 unsigned int postscale;
328} post_table[] = {
329 { 2, 0, 0 },
330 { 4, 0, 1 },
331 { 4, 1, 0 },
332 { 8, 1, 1 },
333 { 8, 2, 0 },
334 { 16, 2, 1 },
335 { 12, 3, 0 },
336 { 24, 3, 1 }
337};
338
339static int pll_factors(struct _pll_div *pll_div, unsigned int target,
340 unsigned int source)
341{
342 u64 Kpart;
343 unsigned int K, Ndiv, Nmod;
344 int i;
345
Roel Kluin449bd542009-05-27 17:08:39 -0700346 pr_debug("wm8580: PLL %uHz->%uHz\n", source, target);
Mark Browne88ba012008-08-06 13:18:26 +0100347
348 /* Scale the output frequency up; the PLL should run in the
349 * region of 90-100MHz.
350 */
351 for (i = 0; i < ARRAY_SIZE(post_table); i++) {
352 if (target * post_table[i].div >= 90000000 &&
353 target * post_table[i].div <= 100000000) {
354 pll_div->freqmode = post_table[i].freqmode;
355 pll_div->postscale = post_table[i].postscale;
356 target *= post_table[i].div;
357 break;
358 }
359 }
360
361 if (i == ARRAY_SIZE(post_table)) {
362 printk(KERN_ERR "wm8580: Unable to scale output frequency "
363 "%u\n", target);
364 return -EINVAL;
365 }
366
367 Ndiv = target / source;
368
369 if (Ndiv < 5) {
370 source /= 2;
371 pll_div->prescale = 1;
372 Ndiv = target / source;
373 } else
374 pll_div->prescale = 0;
375
376 if ((Ndiv < 5) || (Ndiv > 13)) {
377 printk(KERN_ERR
Roel Kluin449bd542009-05-27 17:08:39 -0700378 "WM8580 N=%u outside supported range\n", Ndiv);
Mark Browne88ba012008-08-06 13:18:26 +0100379 return -EINVAL;
380 }
381
382 pll_div->n = Ndiv;
383 Nmod = target % source;
384 Kpart = FIXED_PLL_SIZE * (long long)Nmod;
385
386 do_div(Kpart, source);
387
388 K = Kpart & 0xFFFFFFFF;
389
390 pll_div->k = K;
391
392 pr_debug("PLL %x.%x prescale %d freqmode %d postscale %d\n",
393 pll_div->n, pll_div->k, pll_div->prescale, pll_div->freqmode,
394 pll_div->postscale);
395
396 return 0;
397}
398
Mark Brown85488032009-09-05 18:52:16 +0100399static int wm8580_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
400 int source, unsigned int freq_in, unsigned int freq_out)
Mark Browne88ba012008-08-06 13:18:26 +0100401{
402 int offset;
403 struct snd_soc_codec *codec = codec_dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +0900404 struct wm8580_priv *wm8580 = snd_soc_codec_get_drvdata(codec);
Mark Browne88ba012008-08-06 13:18:26 +0100405 struct pll_state *state;
406 struct _pll_div pll_div;
407 unsigned int reg;
408 unsigned int pwr_mask;
409 int ret;
410
411 /* GCC isn't able to work out the ifs below for initialising/using
412 * pll_div so suppress warnings.
413 */
414 memset(&pll_div, 0, sizeof(pll_div));
415
416 switch (pll_id) {
417 case WM8580_PLLA:
418 state = &wm8580->a;
419 offset = 0;
420 pwr_mask = WM8580_PWRDN2_PLLAPD;
421 break;
422 case WM8580_PLLB:
423 state = &wm8580->b;
424 offset = 4;
425 pwr_mask = WM8580_PWRDN2_PLLBPD;
426 break;
427 default:
428 return -ENODEV;
429 }
430
431 if (freq_in && freq_out) {
432 ret = pll_factors(&pll_div, freq_out, freq_in);
433 if (ret != 0)
434 return ret;
435 }
436
437 state->in = freq_in;
438 state->out = freq_out;
439
440 /* Always disable the PLL - it is not safe to leave it running
441 * while reprogramming it.
442 */
Mark Brownf6f1eb12009-07-05 17:57:57 +0100443 reg = snd_soc_read(codec, WM8580_PWRDN2);
444 snd_soc_write(codec, WM8580_PWRDN2, reg | pwr_mask);
Mark Browne88ba012008-08-06 13:18:26 +0100445
446 if (!freq_in || !freq_out)
447 return 0;
448
Mark Brownf6f1eb12009-07-05 17:57:57 +0100449 snd_soc_write(codec, WM8580_PLLA1 + offset, pll_div.k & 0x1ff);
jassi brar5c0d38c2009-09-01 11:35:08 +0900450 snd_soc_write(codec, WM8580_PLLA2 + offset, (pll_div.k >> 9) & 0x1ff);
Mark Brownf6f1eb12009-07-05 17:57:57 +0100451 snd_soc_write(codec, WM8580_PLLA3 + offset,
Mark Browne88ba012008-08-06 13:18:26 +0100452 (pll_div.k >> 18 & 0xf) | (pll_div.n << 4));
453
Mark Brownf6f1eb12009-07-05 17:57:57 +0100454 reg = snd_soc_read(codec, WM8580_PLLA4 + offset);
jassi brar5c0d38c2009-09-01 11:35:08 +0900455 reg &= ~0x1b;
Mark Browne88ba012008-08-06 13:18:26 +0100456 reg |= pll_div.prescale | pll_div.postscale << 1 |
Mark Brownce881682009-04-21 12:35:15 +0100457 pll_div.freqmode << 3;
Mark Browne88ba012008-08-06 13:18:26 +0100458
Mark Brownf6f1eb12009-07-05 17:57:57 +0100459 snd_soc_write(codec, WM8580_PLLA4 + offset, reg);
Mark Browne88ba012008-08-06 13:18:26 +0100460
461 /* All done, turn it on */
Mark Brownf6f1eb12009-07-05 17:57:57 +0100462 reg = snd_soc_read(codec, WM8580_PWRDN2);
463 snd_soc_write(codec, WM8580_PWRDN2, reg & ~pwr_mask);
Mark Browne88ba012008-08-06 13:18:26 +0100464
465 return 0;
466}
467
Mark Brownc5607d82010-08-13 19:05:04 +0100468static const int wm8580_sysclk_ratios[] = {
469 128, 192, 256, 384, 512, 768, 1152,
470};
471
Mark Browne88ba012008-08-06 13:18:26 +0100472/*
473 * Set PCM DAI bit size and sample rate.
474 */
475static int wm8580_paif_hw_params(struct snd_pcm_substream *substream,
Mark Browndee89c42008-11-18 22:11:38 +0000476 struct snd_pcm_hw_params *params,
477 struct snd_soc_dai *dai)
Mark Browne88ba012008-08-06 13:18:26 +0100478{
479 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000480 struct snd_soc_codec *codec = rtd->codec;
Mark Brownc5607d82010-08-13 19:05:04 +0100481 struct wm8580_priv *wm8580 = snd_soc_codec_get_drvdata(codec);
482 u16 paifa = 0;
Mark Browne231cab2010-08-13 17:57:28 +0100483 u16 paifb = 0;
Mark Brownc5607d82010-08-13 19:05:04 +0100484 int i, ratio;
Mark Browne88ba012008-08-06 13:18:26 +0100485
Mark Browne88ba012008-08-06 13:18:26 +0100486 /* bit size */
487 switch (params_format(params)) {
488 case SNDRV_PCM_FORMAT_S16_LE:
Mark Brownba2772e2010-08-13 19:36:56 +0100489 paifa |= 0x8;
Mark Browne88ba012008-08-06 13:18:26 +0100490 break;
491 case SNDRV_PCM_FORMAT_S20_3LE:
Mark Brownba2772e2010-08-13 19:36:56 +0100492 paifa |= 0x10;
Mark Browne88ba012008-08-06 13:18:26 +0100493 paifb |= WM8580_AIF_LENGTH_20;
494 break;
495 case SNDRV_PCM_FORMAT_S24_LE:
Mark Brownba2772e2010-08-13 19:36:56 +0100496 paifa |= 0x10;
Mark Browne88ba012008-08-06 13:18:26 +0100497 paifb |= WM8580_AIF_LENGTH_24;
498 break;
499 case SNDRV_PCM_FORMAT_S32_LE:
Mark Brownba2772e2010-08-13 19:36:56 +0100500 paifa |= 0x10;
Mark Browne88ba012008-08-06 13:18:26 +0100501 paifb |= WM8580_AIF_LENGTH_24;
502 break;
503 default:
504 return -EINVAL;
505 }
506
Mark Brownc5607d82010-08-13 19:05:04 +0100507 /* Look up the SYSCLK ratio; accept only exact matches */
508 ratio = wm8580->sysclk[dai->id] / params_rate(params);
509 for (i = 0; i < ARRAY_SIZE(wm8580_sysclk_ratios); i++)
510 if (ratio == wm8580_sysclk_ratios[i])
511 break;
512 if (i == ARRAY_SIZE(wm8580_sysclk_ratios)) {
513 dev_err(codec->dev, "Invalid clock ratio %d/%d\n",
514 wm8580->sysclk[dai->id], params_rate(params));
515 return -EINVAL;
516 }
517 paifa |= i;
518 dev_dbg(codec->dev, "Running at %dfs with %dHz clock\n",
519 wm8580_sysclk_ratios[i], wm8580->sysclk[dai->driver->id]);
520
521 snd_soc_update_bits(codec, WM8580_PAIF1 + dai->driver->id,
Mark Brownba2772e2010-08-13 19:36:56 +0100522 WM8580_AIF_RATE_MASK | WM8580_AIF_BCLKSEL_MASK,
523 paifa);
Mark Browne231cab2010-08-13 17:57:28 +0100524 snd_soc_update_bits(codec, WM8580_PAIF3 + dai->driver->id,
525 WM8580_AIF_LENGTH_MASK, paifb);
Mark Browne88ba012008-08-06 13:18:26 +0100526 return 0;
527}
528
529static int wm8580_set_paif_dai_fmt(struct snd_soc_dai *codec_dai,
530 unsigned int fmt)
531{
532 struct snd_soc_codec *codec = codec_dai->codec;
Mark Brownc5607d82010-08-13 19:05:04 +0100533 struct wm8580_priv *wm8580 = snd_soc_codec_get_drvdata(codec);
Mark Browne88ba012008-08-06 13:18:26 +0100534 unsigned int aifa;
535 unsigned int aifb;
536 int can_invert_lrclk;
Mark Brownc5607d82010-08-13 19:05:04 +0100537 int sysclk;
Mark Browne88ba012008-08-06 13:18:26 +0100538
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000539 aifa = snd_soc_read(codec, WM8580_PAIF1 + codec_dai->driver->id);
540 aifb = snd_soc_read(codec, WM8580_PAIF3 + codec_dai->driver->id);
Mark Browne88ba012008-08-06 13:18:26 +0100541
542 aifb &= ~(WM8580_AIF_FMT_MASK | WM8580_AIF_LRP | WM8580_AIF_BCP);
543
544 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
545 case SND_SOC_DAIFMT_CBS_CFS:
546 aifa &= ~WM8580_AIF_MS;
547 break;
548 case SND_SOC_DAIFMT_CBM_CFM:
549 aifa |= WM8580_AIF_MS;
550 break;
551 default:
552 return -EINVAL;
553 }
554
555 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
556 case SND_SOC_DAIFMT_I2S:
557 can_invert_lrclk = 1;
558 aifb |= WM8580_AIF_FMT_I2S;
559 break;
560 case SND_SOC_DAIFMT_RIGHT_J:
561 can_invert_lrclk = 1;
562 aifb |= WM8580_AIF_FMT_RIGHTJ;
563 break;
564 case SND_SOC_DAIFMT_LEFT_J:
565 can_invert_lrclk = 1;
566 aifb |= WM8580_AIF_FMT_LEFTJ;
567 break;
568 case SND_SOC_DAIFMT_DSP_A:
569 can_invert_lrclk = 0;
570 aifb |= WM8580_AIF_FMT_DSP;
571 break;
572 case SND_SOC_DAIFMT_DSP_B:
573 can_invert_lrclk = 0;
574 aifb |= WM8580_AIF_FMT_DSP;
575 aifb |= WM8580_AIF_LRP;
576 break;
577 default:
578 return -EINVAL;
579 }
580
581 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
582 case SND_SOC_DAIFMT_NB_NF:
583 break;
584
585 case SND_SOC_DAIFMT_IB_IF:
586 if (!can_invert_lrclk)
587 return -EINVAL;
588 aifb |= WM8580_AIF_BCP;
589 aifb |= WM8580_AIF_LRP;
590 break;
591
592 case SND_SOC_DAIFMT_IB_NF:
593 aifb |= WM8580_AIF_BCP;
594 break;
595
596 case SND_SOC_DAIFMT_NB_IF:
597 if (!can_invert_lrclk)
598 return -EINVAL;
599 aifb |= WM8580_AIF_LRP;
600 break;
601
602 default:
603 return -EINVAL;
604 }
605
Mark Brownc5607d82010-08-13 19:05:04 +0100606 sysclk = wm8580->sysclk[codec_dai->driver->id];
607
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000608 snd_soc_write(codec, WM8580_PAIF1 + codec_dai->driver->id, aifa);
609 snd_soc_write(codec, WM8580_PAIF3 + codec_dai->driver->id, aifb);
Mark Browne88ba012008-08-06 13:18:26 +0100610
611 return 0;
612}
613
614static int wm8580_set_dai_clkdiv(struct snd_soc_dai *codec_dai,
615 int div_id, int div)
616{
617 struct snd_soc_codec *codec = codec_dai->codec;
618 unsigned int reg;
619
620 switch (div_id) {
621 case WM8580_MCLK:
Mark Brownf6f1eb12009-07-05 17:57:57 +0100622 reg = snd_soc_read(codec, WM8580_PLLB4);
Mark Browne88ba012008-08-06 13:18:26 +0100623 reg &= ~WM8580_PLLB4_MCLKOUTSRC_MASK;
624
625 switch (div) {
626 case WM8580_CLKSRC_MCLK:
627 /* Input */
628 break;
629
630 case WM8580_CLKSRC_PLLA:
631 reg |= WM8580_PLLB4_MCLKOUTSRC_PLLA;
632 break;
633 case WM8580_CLKSRC_PLLB:
634 reg |= WM8580_PLLB4_MCLKOUTSRC_PLLB;
635 break;
636
637 case WM8580_CLKSRC_OSC:
638 reg |= WM8580_PLLB4_MCLKOUTSRC_OSC;
639 break;
640
641 default:
642 return -EINVAL;
643 }
Mark Brownf6f1eb12009-07-05 17:57:57 +0100644 snd_soc_write(codec, WM8580_PLLB4, reg);
Mark Browne88ba012008-08-06 13:18:26 +0100645 break;
646
Mark Browne88ba012008-08-06 13:18:26 +0100647 case WM8580_CLKOUTSRC:
Mark Brownf6f1eb12009-07-05 17:57:57 +0100648 reg = snd_soc_read(codec, WM8580_PLLB4);
Mark Browne88ba012008-08-06 13:18:26 +0100649 reg &= ~WM8580_PLLB4_CLKOUTSRC_MASK;
650
651 switch (div) {
652 case WM8580_CLKSRC_NONE:
653 break;
654
655 case WM8580_CLKSRC_PLLA:
656 reg |= WM8580_PLLB4_CLKOUTSRC_PLLACLK;
657 break;
658
659 case WM8580_CLKSRC_PLLB:
660 reg |= WM8580_PLLB4_CLKOUTSRC_PLLBCLK;
661 break;
662
663 case WM8580_CLKSRC_OSC:
664 reg |= WM8580_PLLB4_CLKOUTSRC_OSCCLK;
665 break;
666
667 default:
668 return -EINVAL;
669 }
Mark Brownf6f1eb12009-07-05 17:57:57 +0100670 snd_soc_write(codec, WM8580_PLLB4, reg);
Mark Browne88ba012008-08-06 13:18:26 +0100671 break;
672
673 default:
674 return -EINVAL;
675 }
676
677 return 0;
678}
679
Mark Brownc5607d82010-08-13 19:05:04 +0100680static int wm8580_set_sysclk(struct snd_soc_dai *dai, int clk_id,
681 unsigned int freq, int dir)
682{
683 struct snd_soc_codec *codec = dai->codec;
684 struct wm8580_priv *wm8580 = snd_soc_codec_get_drvdata(codec);
685 int sel, sel_mask, sel_shift;
686
687 switch (dai->driver->id) {
688 case WM8580_DAI_PAIFTX:
689 sel_mask = 0x3;
690 sel_shift = 0;
691 break;
692
693 case WM8580_DAI_PAIFRX:
694 sel_mask = 0xc;
695 sel_shift = 2;
696 break;
697
698 default:
699 BUG_ON("Unknown DAI driver ID\n");
700 return -EINVAL;
701 }
702
703 switch (clk_id) {
704 case WM8580_CLKSRC_ADCMCLK:
705 if (dai->id != WM8580_DAI_PAIFTX)
706 return -EINVAL;
707 sel = 0 << sel_shift;
708 break;
709 case WM8580_CLKSRC_PLLA:
710 sel = 1 << sel_shift;
711 break;
712 case WM8580_CLKSRC_PLLB:
713 sel = 2 << sel_shift;
714 break;
715 case WM8580_CLKSRC_MCLK:
716 sel = 3 << sel_shift;
717 break;
718 default:
719 dev_err(codec->dev, "Unknown clock %d\n", clk_id);
720 return -EINVAL;
721 }
722
723 /* We really should validate PLL settings but not yet */
724 wm8580->sysclk[dai->id] = freq;
725
726 return snd_soc_update_bits(codec, WM8580_CLKSEL, sel, sel_mask);
727}
728
Mark Browne88ba012008-08-06 13:18:26 +0100729static int wm8580_digital_mute(struct snd_soc_dai *codec_dai, int mute)
730{
731 struct snd_soc_codec *codec = codec_dai->codec;
732 unsigned int reg;
733
Mark Brownf6f1eb12009-07-05 17:57:57 +0100734 reg = snd_soc_read(codec, WM8580_DAC_CONTROL5);
Mark Browne88ba012008-08-06 13:18:26 +0100735
736 if (mute)
737 reg |= WM8580_DAC_CONTROL5_MUTEALL;
738 else
739 reg &= ~WM8580_DAC_CONTROL5_MUTEALL;
740
Mark Brownf6f1eb12009-07-05 17:57:57 +0100741 snd_soc_write(codec, WM8580_DAC_CONTROL5, reg);
Mark Browne88ba012008-08-06 13:18:26 +0100742
743 return 0;
744}
745
746static int wm8580_set_bias_level(struct snd_soc_codec *codec,
747 enum snd_soc_bias_level level)
748{
749 u16 reg;
750 switch (level) {
751 case SND_SOC_BIAS_ON:
752 case SND_SOC_BIAS_PREPARE:
Mark Browne88ba012008-08-06 13:18:26 +0100753 break;
Mark Brown6f7cb442009-03-11 18:31:08 +0000754
755 case SND_SOC_BIAS_STANDBY:
756 if (codec->bias_level == SND_SOC_BIAS_OFF) {
757 /* Power up and get individual control of the DACs */
Mark Brownf6f1eb12009-07-05 17:57:57 +0100758 reg = snd_soc_read(codec, WM8580_PWRDN1);
Mark Brown6f7cb442009-03-11 18:31:08 +0000759 reg &= ~(WM8580_PWRDN1_PWDN | WM8580_PWRDN1_ALLDACPD);
Mark Brownf6f1eb12009-07-05 17:57:57 +0100760 snd_soc_write(codec, WM8580_PWRDN1, reg);
Mark Brown6f7cb442009-03-11 18:31:08 +0000761
762 /* Make VMID high impedence */
Mark Brownf6f1eb12009-07-05 17:57:57 +0100763 reg = snd_soc_read(codec, WM8580_ADC_CONTROL1);
Mark Brown6f7cb442009-03-11 18:31:08 +0000764 reg &= ~0x100;
Mark Brownf6f1eb12009-07-05 17:57:57 +0100765 snd_soc_write(codec, WM8580_ADC_CONTROL1, reg);
Mark Brown6f7cb442009-03-11 18:31:08 +0000766 }
767 break;
768
Mark Browne88ba012008-08-06 13:18:26 +0100769 case SND_SOC_BIAS_OFF:
Mark Brownf6f1eb12009-07-05 17:57:57 +0100770 reg = snd_soc_read(codec, WM8580_PWRDN1);
771 snd_soc_write(codec, WM8580_PWRDN1, reg | WM8580_PWRDN1_PWDN);
Mark Browne88ba012008-08-06 13:18:26 +0100772 break;
773 }
774 codec->bias_level = level;
775 return 0;
776}
777
778#define WM8580_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
779 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
780
Eric Miao6335d052009-03-03 09:41:00 +0800781static struct snd_soc_dai_ops wm8580_dai_ops_playback = {
Mark Brownc5607d82010-08-13 19:05:04 +0100782 .set_sysclk = wm8580_set_sysclk,
Eric Miao6335d052009-03-03 09:41:00 +0800783 .hw_params = wm8580_paif_hw_params,
784 .set_fmt = wm8580_set_paif_dai_fmt,
785 .set_clkdiv = wm8580_set_dai_clkdiv,
786 .set_pll = wm8580_set_dai_pll,
787 .digital_mute = wm8580_digital_mute,
788};
789
790static struct snd_soc_dai_ops wm8580_dai_ops_capture = {
Mark Brownc5607d82010-08-13 19:05:04 +0100791 .set_sysclk = wm8580_set_sysclk,
Eric Miao6335d052009-03-03 09:41:00 +0800792 .hw_params = wm8580_paif_hw_params,
793 .set_fmt = wm8580_set_paif_dai_fmt,
794 .set_clkdiv = wm8580_set_dai_clkdiv,
795 .set_pll = wm8580_set_dai_pll,
796};
797
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000798static struct snd_soc_dai_driver wm8580_dai[] = {
Mark Browne88ba012008-08-06 13:18:26 +0100799 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000800 .name = "wm8580-hifi-playback",
801 .id = WM8580_DAI_PAIFRX,
Mark Browne88ba012008-08-06 13:18:26 +0100802 .playback = {
803 .stream_name = "Playback",
804 .channels_min = 1,
805 .channels_max = 6,
806 .rates = SNDRV_PCM_RATE_8000_192000,
807 .formats = WM8580_FORMATS,
808 },
Eric Miao6335d052009-03-03 09:41:00 +0800809 .ops = &wm8580_dai_ops_playback,
Mark Browne88ba012008-08-06 13:18:26 +0100810 },
811 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000812 .name = "wm8580-hifi-capture",
813 .id = WM8580_DAI_PAIFTX,
Mark Browne88ba012008-08-06 13:18:26 +0100814 .capture = {
815 .stream_name = "Capture",
816 .channels_min = 2,
817 .channels_max = 2,
818 .rates = SNDRV_PCM_RATE_8000_192000,
819 .formats = WM8580_FORMATS,
820 },
Eric Miao6335d052009-03-03 09:41:00 +0800821 .ops = &wm8580_dai_ops_capture,
Mark Browne88ba012008-08-06 13:18:26 +0100822 },
823};
Mark Browne88ba012008-08-06 13:18:26 +0100824
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000825static int wm8580_probe(struct snd_soc_codec *codec)
Mark Browne88ba012008-08-06 13:18:26 +0100826{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000827 struct wm8580_priv *wm8580 = snd_soc_codec_get_drvdata(codec);
828 int ret = 0,i;
Mark Browne88ba012008-08-06 13:18:26 +0100829
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000830 ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8580->control_type);
Mark Brownf6f1eb12009-07-05 17:57:57 +0100831 if (ret < 0) {
832 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000833 return ret;
Mark Brownf6f1eb12009-07-05 17:57:57 +0100834 }
835
Mark Browna583cd52009-06-17 17:30:14 +0100836 for (i = 0; i < ARRAY_SIZE(wm8580->supplies); i++)
837 wm8580->supplies[i].supply = wm8580_supply_names[i];
838
839 ret = regulator_bulk_get(codec->dev, ARRAY_SIZE(wm8580->supplies),
840 wm8580->supplies);
841 if (ret != 0) {
842 dev_err(codec->dev, "Failed to request supplies: %d\n", ret);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000843 return ret;
Mark Browna583cd52009-06-17 17:30:14 +0100844 }
845
846 ret = regulator_bulk_enable(ARRAY_SIZE(wm8580->supplies),
847 wm8580->supplies);
848 if (ret != 0) {
849 dev_err(codec->dev, "Failed to enable supplies: %d\n", ret);
850 goto err_regulator_get;
851 }
852
Mark Brown6f7cb442009-03-11 18:31:08 +0000853 /* Get the codec into a known state */
Mark Brownf6f1eb12009-07-05 17:57:57 +0100854 ret = snd_soc_write(codec, WM8580_RESET, 0);
Mark Brown6f7cb442009-03-11 18:31:08 +0000855 if (ret != 0) {
856 dev_err(codec->dev, "Failed to reset codec: %d\n", ret);
Mark Browna583cd52009-06-17 17:30:14 +0100857 goto err_regulator_enable;
Mark Brown6f7cb442009-03-11 18:31:08 +0000858 }
859
Mark Brown6f7cb442009-03-11 18:31:08 +0000860 wm8580_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
861
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000862 snd_soc_add_controls(codec, wm8580_snd_controls,
863 ARRAY_SIZE(wm8580_snd_controls));
864 wm8580_add_widgets(codec);
Mark Brown6f7cb442009-03-11 18:31:08 +0000865
866 return 0;
867
Mark Browna583cd52009-06-17 17:30:14 +0100868err_regulator_enable:
869 regulator_bulk_disable(ARRAY_SIZE(wm8580->supplies), wm8580->supplies);
870err_regulator_get:
871 regulator_bulk_free(ARRAY_SIZE(wm8580->supplies), wm8580->supplies);
Mark Brown6f7cb442009-03-11 18:31:08 +0000872 return ret;
873}
874
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000875/* power down chip */
876static int wm8580_remove(struct snd_soc_codec *codec)
Mark Brown6f7cb442009-03-11 18:31:08 +0000877{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000878 struct wm8580_priv *wm8580 = snd_soc_codec_get_drvdata(codec);
879
880 wm8580_set_bias_level(codec, SND_SOC_BIAS_OFF);
881
Mark Browna583cd52009-06-17 17:30:14 +0100882 regulator_bulk_disable(ARRAY_SIZE(wm8580->supplies), wm8580->supplies);
883 regulator_bulk_free(ARRAY_SIZE(wm8580->supplies), wm8580->supplies);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000884
885 return 0;
Mark Brown6f7cb442009-03-11 18:31:08 +0000886}
Mark Browne88ba012008-08-06 13:18:26 +0100887
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000888static struct snd_soc_codec_driver soc_codec_dev_wm8580 = {
889 .probe = wm8580_probe,
890 .remove = wm8580_remove,
891 .set_bias_level = wm8580_set_bias_level,
892 .reg_cache_size = sizeof(wm8580_reg),
893 .reg_word_size = sizeof(u16),
894 .reg_cache_default = &wm8580_reg,
895};
896
Mark Browne88ba012008-08-06 13:18:26 +0100897#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
Jean Delvare17be5522008-10-15 19:57:12 +0200898static int wm8580_i2c_probe(struct i2c_client *i2c,
899 const struct i2c_device_id *id)
Mark Browne88ba012008-08-06 13:18:26 +0100900{
Mark Brown6f7cb442009-03-11 18:31:08 +0000901 struct wm8580_priv *wm8580;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000902 int ret;
Mark Browne88ba012008-08-06 13:18:26 +0100903
Mark Brown6f7cb442009-03-11 18:31:08 +0000904 wm8580 = kzalloc(sizeof(struct wm8580_priv), GFP_KERNEL);
905 if (wm8580 == NULL)
906 return -ENOMEM;
907
Mark Brown6f7cb442009-03-11 18:31:08 +0000908 i2c_set_clientdata(i2c, wm8580);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000909 wm8580->control_type = SND_SOC_I2C;
Mark Browne88ba012008-08-06 13:18:26 +0100910
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000911 ret = snd_soc_register_codec(&i2c->dev,
912 &soc_codec_dev_wm8580, wm8580_dai, ARRAY_SIZE(wm8580_dai));
913 if (ret < 0)
914 kfree(wm8580);
915 return ret;
Mark Browne88ba012008-08-06 13:18:26 +0100916}
917
Jean Delvare17be5522008-10-15 19:57:12 +0200918static int wm8580_i2c_remove(struct i2c_client *client)
Mark Browne88ba012008-08-06 13:18:26 +0100919{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000920 snd_soc_unregister_codec(&client->dev);
921 kfree(i2c_get_clientdata(client));
Mark Browne88ba012008-08-06 13:18:26 +0100922 return 0;
923}
924
Jean Delvare17be5522008-10-15 19:57:12 +0200925static const struct i2c_device_id wm8580_i2c_id[] = {
926 { "wm8580", 0 },
927 { }
928};
929MODULE_DEVICE_TABLE(i2c, wm8580_i2c_id);
Mark Browne88ba012008-08-06 13:18:26 +0100930
Mark Browne88ba012008-08-06 13:18:26 +0100931static struct i2c_driver wm8580_i2c_driver = {
932 .driver = {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000933 .name = "wm8580-codec",
Mark Browne88ba012008-08-06 13:18:26 +0100934 .owner = THIS_MODULE,
935 },
Jean Delvare17be5522008-10-15 19:57:12 +0200936 .probe = wm8580_i2c_probe,
937 .remove = wm8580_i2c_remove,
938 .id_table = wm8580_i2c_id,
Mark Browne88ba012008-08-06 13:18:26 +0100939};
Mark Browne88ba012008-08-06 13:18:26 +0100940#endif
941
Takashi Iwaic9b3a402008-12-10 07:47:22 +0100942static int __init wm8580_modinit(void)
Mark Brown64089b82008-12-08 19:17:58 +0000943{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000944 int ret = 0;
Mark Brown6f7cb442009-03-11 18:31:08 +0000945
946#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
947 ret = i2c_add_driver(&wm8580_i2c_driver);
948 if (ret != 0) {
949 pr_err("Failed to register WM8580 I2C driver: %d\n", ret);
950 }
951#endif
952
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000953 return ret;
Mark Brown64089b82008-12-08 19:17:58 +0000954}
955module_init(wm8580_modinit);
956
957static void __exit wm8580_exit(void)
958{
Mark Brown6f7cb442009-03-11 18:31:08 +0000959#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
960 i2c_del_driver(&wm8580_i2c_driver);
961#endif
Mark Brown64089b82008-12-08 19:17:58 +0000962}
963module_exit(wm8580_exit);
964
Mark Browne88ba012008-08-06 13:18:26 +0100965MODULE_DESCRIPTION("ASoC WM8580 driver");
966MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
967MODULE_LICENSE("GPL");