blob: af2289ee6cd695c684d77f4b21f048fceda38cb8 [file] [log] [blame]
Mark Brown1dcf98f2009-07-01 18:28:54 +01001/*
2 * wm8523.c -- WM8523 ALSA SoC Audio driver
3 *
4 * Copyright 2009 Wolfson Microelectronics plc
5 *
6 * Author: Mark Brown <broonie@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 Brown1dcf98f2009-07-01 18:28:54 +010020#include <linux/regulator/consumer.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090021#include <linux/slab.h>
Mark Brownbf5a85b2011-08-02 13:08:13 +090022#include <linux/of_device.h>
Mark Brown1dcf98f2009-07-01 18:28:54 +010023#include <sound/core.h>
24#include <sound/pcm.h>
25#include <sound/pcm_params.h>
26#include <sound/soc.h>
Mark Brown1dcf98f2009-07-01 18:28:54 +010027#include <sound/initval.h>
28#include <sound/tlv.h>
29
30#include "wm8523.h"
31
Mark Brown1dcf98f2009-07-01 18:28:54 +010032#define WM8523_NUM_SUPPLIES 2
33static const char *wm8523_supply_names[WM8523_NUM_SUPPLIES] = {
34 "AVDD",
35 "LINEVDD",
36};
37
38#define WM8523_NUM_RATES 7
39
40/* codec private data */
41struct wm8523_priv {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000042 enum snd_soc_control_type control_type;
Mark Brown1dcf98f2009-07-01 18:28:54 +010043 struct regulator_bulk_data supplies[WM8523_NUM_SUPPLIES];
44 unsigned int sysclk;
45 unsigned int rate_constraint_list[WM8523_NUM_RATES];
46 struct snd_pcm_hw_constraint_list rate_constraint;
47};
48
49static const u16 wm8523_reg[WM8523_REGISTER_COUNT] = {
50 0x8523, /* R0 - DEVICE_ID */
51 0x0001, /* R1 - REVISION */
52 0x0000, /* R2 - PSCTRL1 */
53 0x1812, /* R3 - AIF_CTRL1 */
54 0x0000, /* R4 - AIF_CTRL2 */
55 0x0001, /* R5 - DAC_CTRL3 */
56 0x0190, /* R6 - DAC_GAINL */
57 0x0190, /* R7 - DAC_GAINR */
58 0x0000, /* R8 - ZERO_DETECT */
59};
60
Dimitris Papastamosd4754ec2011-01-13 12:20:37 +000061static int wm8523_volatile_register(struct snd_soc_codec *codec, unsigned int reg)
Mark Brown1dcf98f2009-07-01 18:28:54 +010062{
63 switch (reg) {
64 case WM8523_DEVICE_ID:
65 case WM8523_REVISION:
66 return 1;
67 default:
68 return 0;
69 }
70}
71
Mark Brown1dcf98f2009-07-01 18:28:54 +010072static int wm8523_reset(struct snd_soc_codec *codec)
73{
Mark Brown8d50e442009-07-10 23:12:01 +010074 return snd_soc_write(codec, WM8523_DEVICE_ID, 0);
Mark Brown1dcf98f2009-07-01 18:28:54 +010075}
76
77static const DECLARE_TLV_DB_SCALE(dac_tlv, -10000, 25, 0);
78
79static const char *wm8523_zd_count_text[] = {
80 "1024",
81 "2048",
82};
83
84static const struct soc_enum wm8523_zc_count =
85 SOC_ENUM_SINGLE(WM8523_ZERO_DETECT, 0, 2, wm8523_zd_count_text);
86
Mark Brown16616992011-08-22 16:02:43 +010087static const struct snd_kcontrol_new wm8523_controls[] = {
Mark Brown1dcf98f2009-07-01 18:28:54 +010088SOC_DOUBLE_R_TLV("Playback Volume", WM8523_DAC_GAINL, WM8523_DAC_GAINR,
89 0, 448, 0, dac_tlv),
90SOC_SINGLE("ZC Switch", WM8523_DAC_CTRL3, 4, 1, 0),
91SOC_SINGLE("Playback Deemphasis Switch", WM8523_AIF_CTRL1, 8, 1, 0),
92SOC_DOUBLE("Playback Switch", WM8523_DAC_CTRL3, 2, 3, 1, 1),
93SOC_SINGLE("Volume Ramp Up Switch", WM8523_DAC_CTRL3, 1, 1, 0),
94SOC_SINGLE("Volume Ramp Down Switch", WM8523_DAC_CTRL3, 0, 1, 0),
95SOC_ENUM("Zero Detect Count", wm8523_zc_count),
96};
97
98static const struct snd_soc_dapm_widget wm8523_dapm_widgets[] = {
99SND_SOC_DAPM_DAC("DAC", "Playback", SND_SOC_NOPM, 0, 0),
100SND_SOC_DAPM_OUTPUT("LINEVOUTL"),
101SND_SOC_DAPM_OUTPUT("LINEVOUTR"),
102};
103
Mark Brown16616992011-08-22 16:02:43 +0100104static const struct snd_soc_dapm_route wm8523_dapm_routes[] = {
Mark Brown1dcf98f2009-07-01 18:28:54 +0100105 { "LINEVOUTL", NULL, "DAC" },
106 { "LINEVOUTR", NULL, "DAC" },
107};
108
Mark Brown1dcf98f2009-07-01 18:28:54 +0100109static struct {
110 int value;
111 int ratio;
112} lrclk_ratios[WM8523_NUM_RATES] = {
113 { 1, 128 },
114 { 2, 192 },
115 { 3, 256 },
116 { 4, 384 },
117 { 5, 512 },
118 { 6, 768 },
119 { 7, 1152 },
120};
121
122static int wm8523_startup(struct snd_pcm_substream *substream,
123 struct snd_soc_dai *dai)
124{
125 struct snd_soc_codec *codec = dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +0900126 struct wm8523_priv *wm8523 = snd_soc_codec_get_drvdata(codec);
Mark Brown1dcf98f2009-07-01 18:28:54 +0100127
128 /* The set of sample rates that can be supported depends on the
129 * MCLK supplied to the CODEC - enforce this.
130 */
131 if (!wm8523->sysclk) {
132 dev_err(codec->dev,
133 "No MCLK configured, call set_sysclk() on init\n");
134 return -EINVAL;
135 }
136
Mark Brown1dcf98f2009-07-01 18:28:54 +0100137 snd_pcm_hw_constraint_list(substream->runtime, 0,
138 SNDRV_PCM_HW_PARAM_RATE,
139 &wm8523->rate_constraint);
140
141 return 0;
142}
143
144static int wm8523_hw_params(struct snd_pcm_substream *substream,
145 struct snd_pcm_hw_params *params,
146 struct snd_soc_dai *dai)
147{
Mark Browne6968a12012-04-04 15:58:16 +0100148 struct snd_soc_codec *codec = dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +0900149 struct wm8523_priv *wm8523 = snd_soc_codec_get_drvdata(codec);
Mark Brown1dcf98f2009-07-01 18:28:54 +0100150 int i;
Mark Brown8d50e442009-07-10 23:12:01 +0100151 u16 aifctrl1 = snd_soc_read(codec, WM8523_AIF_CTRL1);
152 u16 aifctrl2 = snd_soc_read(codec, WM8523_AIF_CTRL2);
Mark Brown1dcf98f2009-07-01 18:28:54 +0100153
154 /* Find a supported LRCLK ratio */
155 for (i = 0; i < ARRAY_SIZE(lrclk_ratios); i++) {
156 if (wm8523->sysclk / params_rate(params) ==
157 lrclk_ratios[i].ratio)
158 break;
159 }
160
161 /* Should never happen, should be handled by constraints */
162 if (i == ARRAY_SIZE(lrclk_ratios)) {
163 dev_err(codec->dev, "MCLK/fs ratio %d unsupported\n",
164 wm8523->sysclk / params_rate(params));
165 return -EINVAL;
166 }
167
168 aifctrl2 &= ~WM8523_SR_MASK;
169 aifctrl2 |= lrclk_ratios[i].value;
170
171 aifctrl1 &= ~WM8523_WL_MASK;
172 switch (params_format(params)) {
173 case SNDRV_PCM_FORMAT_S16_LE:
174 break;
175 case SNDRV_PCM_FORMAT_S20_3LE:
176 aifctrl1 |= 0x8;
177 break;
178 case SNDRV_PCM_FORMAT_S24_LE:
179 aifctrl1 |= 0x10;
180 break;
181 case SNDRV_PCM_FORMAT_S32_LE:
182 aifctrl1 |= 0x18;
183 break;
184 }
185
Mark Brown8d50e442009-07-10 23:12:01 +0100186 snd_soc_write(codec, WM8523_AIF_CTRL1, aifctrl1);
187 snd_soc_write(codec, WM8523_AIF_CTRL2, aifctrl2);
Mark Brown1dcf98f2009-07-01 18:28:54 +0100188
189 return 0;
190}
191
192static int wm8523_set_dai_sysclk(struct snd_soc_dai *codec_dai,
193 int clk_id, unsigned int freq, int dir)
194{
195 struct snd_soc_codec *codec = codec_dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +0900196 struct wm8523_priv *wm8523 = snd_soc_codec_get_drvdata(codec);
Mark Brown1dcf98f2009-07-01 18:28:54 +0100197 unsigned int val;
198 int i;
199
200 wm8523->sysclk = freq;
201
202 wm8523->rate_constraint.count = 0;
203 for (i = 0; i < ARRAY_SIZE(lrclk_ratios); i++) {
204 val = freq / lrclk_ratios[i].ratio;
205 /* Check that it's a standard rate since core can't
206 * cope with others and having the odd rates confuses
207 * constraint matching.
208 */
209 switch (val) {
210 case 8000:
211 case 11025:
212 case 16000:
213 case 22050:
214 case 32000:
215 case 44100:
216 case 48000:
217 case 64000:
218 case 88200:
219 case 96000:
220 case 176400:
221 case 192000:
222 dev_dbg(codec->dev, "Supported sample rate: %dHz\n",
223 val);
224 wm8523->rate_constraint_list[i] = val;
225 wm8523->rate_constraint.count++;
226 break;
227 default:
228 dev_dbg(codec->dev, "Skipping sample rate: %dHz\n",
229 val);
230 }
231 }
232
233 /* Need at least one supported rate... */
234 if (wm8523->rate_constraint.count == 0)
235 return -EINVAL;
236
237 return 0;
238}
239
240
241static int wm8523_set_dai_fmt(struct snd_soc_dai *codec_dai,
242 unsigned int fmt)
243{
244 struct snd_soc_codec *codec = codec_dai->codec;
Mark Brown8d50e442009-07-10 23:12:01 +0100245 u16 aifctrl1 = snd_soc_read(codec, WM8523_AIF_CTRL1);
Mark Brown1dcf98f2009-07-01 18:28:54 +0100246
247 aifctrl1 &= ~(WM8523_BCLK_INV_MASK | WM8523_LRCLK_INV_MASK |
248 WM8523_FMT_MASK | WM8523_AIF_MSTR_MASK);
249
250 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
251 case SND_SOC_DAIFMT_CBM_CFM:
252 aifctrl1 |= WM8523_AIF_MSTR;
253 break;
254 case SND_SOC_DAIFMT_CBS_CFS:
255 break;
256 default:
257 return -EINVAL;
258 }
259
260 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
261 case SND_SOC_DAIFMT_I2S:
262 aifctrl1 |= 0x0002;
263 break;
264 case SND_SOC_DAIFMT_RIGHT_J:
265 break;
266 case SND_SOC_DAIFMT_LEFT_J:
267 aifctrl1 |= 0x0001;
268 break;
269 case SND_SOC_DAIFMT_DSP_A:
270 aifctrl1 |= 0x0003;
271 break;
272 case SND_SOC_DAIFMT_DSP_B:
273 aifctrl1 |= 0x0023;
274 break;
275 default:
276 return -EINVAL;
277 }
278
279 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
280 case SND_SOC_DAIFMT_NB_NF:
281 break;
282 case SND_SOC_DAIFMT_IB_IF:
283 aifctrl1 |= WM8523_BCLK_INV | WM8523_LRCLK_INV;
284 break;
285 case SND_SOC_DAIFMT_IB_NF:
286 aifctrl1 |= WM8523_BCLK_INV;
287 break;
288 case SND_SOC_DAIFMT_NB_IF:
289 aifctrl1 |= WM8523_LRCLK_INV;
290 break;
291 default:
292 return -EINVAL;
293 }
294
Mark Brown8d50e442009-07-10 23:12:01 +0100295 snd_soc_write(codec, WM8523_AIF_CTRL1, aifctrl1);
Mark Brown1dcf98f2009-07-01 18:28:54 +0100296
297 return 0;
298}
299
300static int wm8523_set_bias_level(struct snd_soc_codec *codec,
301 enum snd_soc_bias_level level)
302{
Mark Brownb2c812e2010-04-14 15:35:19 +0900303 struct wm8523_priv *wm8523 = snd_soc_codec_get_drvdata(codec);
Lars-Peter Clausenbeebca32010-12-28 21:37:57 +0100304 u16 *reg_cache = codec->reg_cache;
Mark Brown1dcf98f2009-07-01 18:28:54 +0100305 int ret, i;
306
307 switch (level) {
308 case SND_SOC_BIAS_ON:
309 break;
310
311 case SND_SOC_BIAS_PREPARE:
312 /* Full power on */
313 snd_soc_update_bits(codec, WM8523_PSCTRL1,
314 WM8523_SYS_ENA_MASK, 3);
315 break;
316
317 case SND_SOC_BIAS_STANDBY:
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200318 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
Mark Brown1dcf98f2009-07-01 18:28:54 +0100319 ret = regulator_bulk_enable(ARRAY_SIZE(wm8523->supplies),
320 wm8523->supplies);
321 if (ret != 0) {
322 dev_err(codec->dev,
323 "Failed to enable supplies: %d\n",
324 ret);
325 return ret;
326 }
327
328 /* Initial power up */
329 snd_soc_update_bits(codec, WM8523_PSCTRL1,
330 WM8523_SYS_ENA_MASK, 1);
331
332 /* Sync back default/cached values */
333 for (i = WM8523_AIF_CTRL1;
334 i < WM8523_MAX_REGISTER; i++)
Lars-Peter Clausenbeebca32010-12-28 21:37:57 +0100335 snd_soc_write(codec, i, reg_cache[i]);
Mark Brown1dcf98f2009-07-01 18:28:54 +0100336
337
338 msleep(100);
339 }
340
341 /* Power up to mute */
342 snd_soc_update_bits(codec, WM8523_PSCTRL1,
343 WM8523_SYS_ENA_MASK, 2);
344
345 break;
346
347 case SND_SOC_BIAS_OFF:
348 /* The chip runs through the power down sequence for us. */
349 snd_soc_update_bits(codec, WM8523_PSCTRL1,
350 WM8523_SYS_ENA_MASK, 0);
351 msleep(100);
352
353 regulator_bulk_disable(ARRAY_SIZE(wm8523->supplies),
354 wm8523->supplies);
355 break;
356 }
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200357 codec->dapm.bias_level = level;
Mark Brown1dcf98f2009-07-01 18:28:54 +0100358 return 0;
359}
360
361#define WM8523_RATES SNDRV_PCM_RATE_8000_192000
362
363#define WM8523_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
364 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
365
Lars-Peter Clausen85e76522011-11-23 11:40:40 +0100366static const struct snd_soc_dai_ops wm8523_dai_ops = {
Mark Brown1dcf98f2009-07-01 18:28:54 +0100367 .startup = wm8523_startup,
368 .hw_params = wm8523_hw_params,
369 .set_sysclk = wm8523_set_dai_sysclk,
370 .set_fmt = wm8523_set_dai_fmt,
371};
372
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000373static struct snd_soc_dai_driver wm8523_dai = {
374 .name = "wm8523-hifi",
Mark Brown1dcf98f2009-07-01 18:28:54 +0100375 .playback = {
376 .stream_name = "Playback",
377 .channels_min = 2, /* Mono modes not yet supported */
378 .channels_max = 2,
379 .rates = WM8523_RATES,
380 .formats = WM8523_FORMATS,
381 },
382 .ops = &wm8523_dai_ops,
383};
Mark Brown1dcf98f2009-07-01 18:28:54 +0100384
385#ifdef CONFIG_PM
Lars-Peter Clausen84b315e2011-12-02 10:18:28 +0100386static int wm8523_suspend(struct snd_soc_codec *codec)
Mark Brown1dcf98f2009-07-01 18:28:54 +0100387{
Mark Brown1dcf98f2009-07-01 18:28:54 +0100388 wm8523_set_bias_level(codec, SND_SOC_BIAS_OFF);
389 return 0;
390}
391
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000392static int wm8523_resume(struct snd_soc_codec *codec)
Mark Brown1dcf98f2009-07-01 18:28:54 +0100393{
Mark Brown1dcf98f2009-07-01 18:28:54 +0100394 wm8523_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
Mark Brown1dcf98f2009-07-01 18:28:54 +0100395 return 0;
396}
397#else
398#define wm8523_suspend NULL
399#define wm8523_resume NULL
400#endif
401
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000402static int wm8523_probe(struct snd_soc_codec *codec)
Mark Brown1dcf98f2009-07-01 18:28:54 +0100403{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000404 struct wm8523_priv *wm8523 = snd_soc_codec_get_drvdata(codec);
405 int ret, i;
Mark Brown1dcf98f2009-07-01 18:28:54 +0100406
Mark Brown1dcf98f2009-07-01 18:28:54 +0100407 wm8523->rate_constraint.list = &wm8523->rate_constraint_list[0];
408 wm8523->rate_constraint.count =
409 ARRAY_SIZE(wm8523->rate_constraint_list);
410
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000411 ret = snd_soc_codec_set_cache_io(codec, 8, 16, wm8523->control_type);
Mark Brown8d50e442009-07-10 23:12:01 +0100412 if (ret != 0) {
413 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000414 return ret;
Mark Brown8d50e442009-07-10 23:12:01 +0100415 }
416
Mark Brown1dcf98f2009-07-01 18:28:54 +0100417 for (i = 0; i < ARRAY_SIZE(wm8523->supplies); i++)
418 wm8523->supplies[i].supply = wm8523_supply_names[i];
419
420 ret = regulator_bulk_get(codec->dev, ARRAY_SIZE(wm8523->supplies),
421 wm8523->supplies);
422 if (ret != 0) {
423 dev_err(codec->dev, "Failed to request supplies: %d\n", ret);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000424 return ret;
Mark Brown1dcf98f2009-07-01 18:28:54 +0100425 }
426
427 ret = regulator_bulk_enable(ARRAY_SIZE(wm8523->supplies),
428 wm8523->supplies);
429 if (ret != 0) {
430 dev_err(codec->dev, "Failed to enable supplies: %d\n", ret);
431 goto err_get;
432 }
433
Mark Brown8d50e442009-07-10 23:12:01 +0100434 ret = snd_soc_read(codec, WM8523_DEVICE_ID);
Mark Brown1dcf98f2009-07-01 18:28:54 +0100435 if (ret < 0) {
436 dev_err(codec->dev, "Failed to read ID register\n");
437 goto err_enable;
438 }
439 if (ret != wm8523_reg[WM8523_DEVICE_ID]) {
440 dev_err(codec->dev, "Device is not a WM8523, ID is %x\n", ret);
441 ret = -EINVAL;
442 goto err_enable;
443 }
444
Mark Brown8d50e442009-07-10 23:12:01 +0100445 ret = snd_soc_read(codec, WM8523_REVISION);
Mark Brown1dcf98f2009-07-01 18:28:54 +0100446 if (ret < 0) {
447 dev_err(codec->dev, "Failed to read revision register\n");
448 goto err_enable;
449 }
450 dev_info(codec->dev, "revision %c\n",
451 (ret & WM8523_CHIP_REV_MASK) + 'A');
452
453 ret = wm8523_reset(codec);
454 if (ret < 0) {
455 dev_err(codec->dev, "Failed to issue reset\n");
456 goto err_enable;
457 }
458
Mark Brown1dcf98f2009-07-01 18:28:54 +0100459 /* Change some default settings - latch VU and enable ZC */
Mark Browna1b3b5e2010-12-24 16:59:30 +0000460 snd_soc_update_bits(codec, WM8523_DAC_GAINR,
461 WM8523_DACR_VU, WM8523_DACR_VU);
462 snd_soc_update_bits(codec, WM8523_DAC_CTRL3, WM8523_ZC, WM8523_ZC);
Mark Brown1dcf98f2009-07-01 18:28:54 +0100463
464 wm8523_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
465
466 /* Bias level configuration will have done an extra enable */
467 regulator_bulk_disable(ARRAY_SIZE(wm8523->supplies), wm8523->supplies);
468
Mark Brown1dcf98f2009-07-01 18:28:54 +0100469 return 0;
470
471err_enable:
472 regulator_bulk_disable(ARRAY_SIZE(wm8523->supplies), wm8523->supplies);
473err_get:
474 regulator_bulk_free(ARRAY_SIZE(wm8523->supplies), wm8523->supplies);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000475
Mark Brown1dcf98f2009-07-01 18:28:54 +0100476 return ret;
477}
478
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000479static int wm8523_remove(struct snd_soc_codec *codec)
Mark Brown1dcf98f2009-07-01 18:28:54 +0100480{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000481 struct wm8523_priv *wm8523 = snd_soc_codec_get_drvdata(codec);
482
483 wm8523_set_bias_level(codec, SND_SOC_BIAS_OFF);
Mark Brown1dcf98f2009-07-01 18:28:54 +0100484 regulator_bulk_free(ARRAY_SIZE(wm8523->supplies), wm8523->supplies);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000485 return 0;
Mark Brown1dcf98f2009-07-01 18:28:54 +0100486}
487
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000488static struct snd_soc_codec_driver soc_codec_dev_wm8523 = {
489 .probe = wm8523_probe,
490 .remove = wm8523_remove,
491 .suspend = wm8523_suspend,
492 .resume = wm8523_resume,
493 .set_bias_level = wm8523_set_bias_level,
494 .reg_cache_size = WM8523_REGISTER_COUNT,
495 .reg_word_size = sizeof(u16),
496 .reg_cache_default = wm8523_reg,
497 .volatile_register = wm8523_volatile_register,
Mark Brown16616992011-08-22 16:02:43 +0100498
499 .controls = wm8523_controls,
500 .num_controls = ARRAY_SIZE(wm8523_controls),
501 .dapm_widgets = wm8523_dapm_widgets,
502 .num_dapm_widgets = ARRAY_SIZE(wm8523_dapm_widgets),
503 .dapm_routes = wm8523_dapm_routes,
504 .num_dapm_routes = ARRAY_SIZE(wm8523_dapm_routes),
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000505};
506
Mark Brownbf5a85b2011-08-02 13:08:13 +0900507static const struct of_device_id wm8523_of_match[] = {
508 { .compatible = "wlf,wm8523" },
509 { },
510};
511
Mark Brown1dcf98f2009-07-01 18:28:54 +0100512#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
513static __devinit int wm8523_i2c_probe(struct i2c_client *i2c,
514 const struct i2c_device_id *id)
515{
516 struct wm8523_priv *wm8523;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000517 int ret;
Mark Brown1dcf98f2009-07-01 18:28:54 +0100518
Mark Brown7d014db2012-09-10 16:18:56 +0800519 wm8523 = devm_kzalloc(&i2c->dev, sizeof(struct wm8523_priv),
520 GFP_KERNEL);
Mark Brown1dcf98f2009-07-01 18:28:54 +0100521 if (wm8523 == NULL)
522 return -ENOMEM;
523
Mark Brown1dcf98f2009-07-01 18:28:54 +0100524 i2c_set_clientdata(i2c, wm8523);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000525 wm8523->control_type = SND_SOC_I2C;
Mark Brown1dcf98f2009-07-01 18:28:54 +0100526
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000527 ret = snd_soc_register_codec(&i2c->dev,
528 &soc_codec_dev_wm8523, &wm8523_dai, 1);
Mark Brown7d014db2012-09-10 16:18:56 +0800529
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000530 return ret;
Mark Brown1dcf98f2009-07-01 18:28:54 +0100531
Mark Brown1dcf98f2009-07-01 18:28:54 +0100532}
533
534static __devexit int wm8523_i2c_remove(struct i2c_client *client)
535{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000536 snd_soc_unregister_codec(&client->dev);
Mark Brown1dcf98f2009-07-01 18:28:54 +0100537 return 0;
538}
539
Mark Brown1dcf98f2009-07-01 18:28:54 +0100540static const struct i2c_device_id wm8523_i2c_id[] = {
541 { "wm8523", 0 },
542 { }
543};
544MODULE_DEVICE_TABLE(i2c, wm8523_i2c_id);
545
546static struct i2c_driver wm8523_i2c_driver = {
547 .driver = {
Mark Brown96654082011-08-02 13:04:14 +0900548 .name = "wm8523",
Mark Brown1dcf98f2009-07-01 18:28:54 +0100549 .owner = THIS_MODULE,
Mark Brownbf5a85b2011-08-02 13:08:13 +0900550 .of_match_table = wm8523_of_match,
Mark Brown1dcf98f2009-07-01 18:28:54 +0100551 },
552 .probe = wm8523_i2c_probe,
553 .remove = __devexit_p(wm8523_i2c_remove),
Mark Brown1dcf98f2009-07-01 18:28:54 +0100554 .id_table = wm8523_i2c_id,
555};
556#endif
557
558static int __init wm8523_modinit(void)
559{
560 int ret;
561#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
562 ret = i2c_add_driver(&wm8523_i2c_driver);
563 if (ret != 0) {
564 printk(KERN_ERR "Failed to register WM8523 I2C driver: %d\n",
565 ret);
566 }
567#endif
568 return 0;
569}
570module_init(wm8523_modinit);
571
572static void __exit wm8523_exit(void)
573{
574#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
575 i2c_del_driver(&wm8523_i2c_driver);
576#endif
577}
578module_exit(wm8523_exit);
579
580MODULE_DESCRIPTION("ASoC WM8523 driver");
581MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
582MODULE_LICENSE("GPL");