blob: 52812d1a90e44590baea445c4fbcbe53dd4021b6 [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>
20#include <linux/platform_device.h>
21#include <linux/regulator/consumer.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090022#include <linux/slab.h>
Mark Brownbf5a85b2011-08-02 13:08:13 +090023#include <linux/of_device.h>
Mark Brown1dcf98f2009-07-01 18:28:54 +010024#include <sound/core.h>
25#include <sound/pcm.h>
26#include <sound/pcm_params.h>
27#include <sound/soc.h>
Mark Brown1dcf98f2009-07-01 18:28:54 +010028#include <sound/initval.h>
29#include <sound/tlv.h>
30
31#include "wm8523.h"
32
Mark Brown1dcf98f2009-07-01 18:28:54 +010033#define WM8523_NUM_SUPPLIES 2
34static const char *wm8523_supply_names[WM8523_NUM_SUPPLIES] = {
35 "AVDD",
36 "LINEVDD",
37};
38
39#define WM8523_NUM_RATES 7
40
41/* codec private data */
42struct wm8523_priv {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000043 enum snd_soc_control_type control_type;
Mark Brown1dcf98f2009-07-01 18:28:54 +010044 struct regulator_bulk_data supplies[WM8523_NUM_SUPPLIES];
45 unsigned int sysclk;
46 unsigned int rate_constraint_list[WM8523_NUM_RATES];
47 struct snd_pcm_hw_constraint_list rate_constraint;
48};
49
50static const u16 wm8523_reg[WM8523_REGISTER_COUNT] = {
51 0x8523, /* R0 - DEVICE_ID */
52 0x0001, /* R1 - REVISION */
53 0x0000, /* R2 - PSCTRL1 */
54 0x1812, /* R3 - AIF_CTRL1 */
55 0x0000, /* R4 - AIF_CTRL2 */
56 0x0001, /* R5 - DAC_CTRL3 */
57 0x0190, /* R6 - DAC_GAINL */
58 0x0190, /* R7 - DAC_GAINR */
59 0x0000, /* R8 - ZERO_DETECT */
60};
61
Dimitris Papastamosd4754ec2011-01-13 12:20:37 +000062static int wm8523_volatile_register(struct snd_soc_codec *codec, unsigned int reg)
Mark Brown1dcf98f2009-07-01 18:28:54 +010063{
64 switch (reg) {
65 case WM8523_DEVICE_ID:
66 case WM8523_REVISION:
67 return 1;
68 default:
69 return 0;
70 }
71}
72
Mark Brown1dcf98f2009-07-01 18:28:54 +010073static int wm8523_reset(struct snd_soc_codec *codec)
74{
Mark Brown8d50e442009-07-10 23:12:01 +010075 return snd_soc_write(codec, WM8523_DEVICE_ID, 0);
Mark Brown1dcf98f2009-07-01 18:28:54 +010076}
77
78static const DECLARE_TLV_DB_SCALE(dac_tlv, -10000, 25, 0);
79
80static const char *wm8523_zd_count_text[] = {
81 "1024",
82 "2048",
83};
84
85static const struct soc_enum wm8523_zc_count =
86 SOC_ENUM_SINGLE(WM8523_ZERO_DETECT, 0, 2, wm8523_zd_count_text);
87
88static const struct snd_kcontrol_new wm8523_snd_controls[] = {
89SOC_DOUBLE_R_TLV("Playback Volume", WM8523_DAC_GAINL, WM8523_DAC_GAINR,
90 0, 448, 0, dac_tlv),
91SOC_SINGLE("ZC Switch", WM8523_DAC_CTRL3, 4, 1, 0),
92SOC_SINGLE("Playback Deemphasis Switch", WM8523_AIF_CTRL1, 8, 1, 0),
93SOC_DOUBLE("Playback Switch", WM8523_DAC_CTRL3, 2, 3, 1, 1),
94SOC_SINGLE("Volume Ramp Up Switch", WM8523_DAC_CTRL3, 1, 1, 0),
95SOC_SINGLE("Volume Ramp Down Switch", WM8523_DAC_CTRL3, 0, 1, 0),
96SOC_ENUM("Zero Detect Count", wm8523_zc_count),
97};
98
99static const struct snd_soc_dapm_widget wm8523_dapm_widgets[] = {
100SND_SOC_DAPM_DAC("DAC", "Playback", SND_SOC_NOPM, 0, 0),
101SND_SOC_DAPM_OUTPUT("LINEVOUTL"),
102SND_SOC_DAPM_OUTPUT("LINEVOUTR"),
103};
104
105static const struct snd_soc_dapm_route intercon[] = {
106 { "LINEVOUTL", NULL, "DAC" },
107 { "LINEVOUTR", NULL, "DAC" },
108};
109
110static int wm8523_add_widgets(struct snd_soc_codec *codec)
111{
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200112 struct snd_soc_dapm_context *dapm = &codec->dapm;
Mark Brown1dcf98f2009-07-01 18:28:54 +0100113
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200114 snd_soc_dapm_new_controls(dapm, wm8523_dapm_widgets,
115 ARRAY_SIZE(wm8523_dapm_widgets));
116 snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
Mark Brown1dcf98f2009-07-01 18:28:54 +0100117
Mark Brown1dcf98f2009-07-01 18:28:54 +0100118 return 0;
119}
120
121static struct {
122 int value;
123 int ratio;
124} lrclk_ratios[WM8523_NUM_RATES] = {
125 { 1, 128 },
126 { 2, 192 },
127 { 3, 256 },
128 { 4, 384 },
129 { 5, 512 },
130 { 6, 768 },
131 { 7, 1152 },
132};
133
134static int wm8523_startup(struct snd_pcm_substream *substream,
135 struct snd_soc_dai *dai)
136{
137 struct snd_soc_codec *codec = dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +0900138 struct wm8523_priv *wm8523 = snd_soc_codec_get_drvdata(codec);
Mark Brown1dcf98f2009-07-01 18:28:54 +0100139
140 /* The set of sample rates that can be supported depends on the
141 * MCLK supplied to the CODEC - enforce this.
142 */
143 if (!wm8523->sysclk) {
144 dev_err(codec->dev,
145 "No MCLK configured, call set_sysclk() on init\n");
146 return -EINVAL;
147 }
148
Mark Brown1dcf98f2009-07-01 18:28:54 +0100149 snd_pcm_hw_constraint_list(substream->runtime, 0,
150 SNDRV_PCM_HW_PARAM_RATE,
151 &wm8523->rate_constraint);
152
153 return 0;
154}
155
156static int wm8523_hw_params(struct snd_pcm_substream *substream,
157 struct snd_pcm_hw_params *params,
158 struct snd_soc_dai *dai)
159{
160 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000161 struct snd_soc_codec *codec = rtd->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +0900162 struct wm8523_priv *wm8523 = snd_soc_codec_get_drvdata(codec);
Mark Brown1dcf98f2009-07-01 18:28:54 +0100163 int i;
Mark Brown8d50e442009-07-10 23:12:01 +0100164 u16 aifctrl1 = snd_soc_read(codec, WM8523_AIF_CTRL1);
165 u16 aifctrl2 = snd_soc_read(codec, WM8523_AIF_CTRL2);
Mark Brown1dcf98f2009-07-01 18:28:54 +0100166
167 /* Find a supported LRCLK ratio */
168 for (i = 0; i < ARRAY_SIZE(lrclk_ratios); i++) {
169 if (wm8523->sysclk / params_rate(params) ==
170 lrclk_ratios[i].ratio)
171 break;
172 }
173
174 /* Should never happen, should be handled by constraints */
175 if (i == ARRAY_SIZE(lrclk_ratios)) {
176 dev_err(codec->dev, "MCLK/fs ratio %d unsupported\n",
177 wm8523->sysclk / params_rate(params));
178 return -EINVAL;
179 }
180
181 aifctrl2 &= ~WM8523_SR_MASK;
182 aifctrl2 |= lrclk_ratios[i].value;
183
184 aifctrl1 &= ~WM8523_WL_MASK;
185 switch (params_format(params)) {
186 case SNDRV_PCM_FORMAT_S16_LE:
187 break;
188 case SNDRV_PCM_FORMAT_S20_3LE:
189 aifctrl1 |= 0x8;
190 break;
191 case SNDRV_PCM_FORMAT_S24_LE:
192 aifctrl1 |= 0x10;
193 break;
194 case SNDRV_PCM_FORMAT_S32_LE:
195 aifctrl1 |= 0x18;
196 break;
197 }
198
Mark Brown8d50e442009-07-10 23:12:01 +0100199 snd_soc_write(codec, WM8523_AIF_CTRL1, aifctrl1);
200 snd_soc_write(codec, WM8523_AIF_CTRL2, aifctrl2);
Mark Brown1dcf98f2009-07-01 18:28:54 +0100201
202 return 0;
203}
204
205static int wm8523_set_dai_sysclk(struct snd_soc_dai *codec_dai,
206 int clk_id, unsigned int freq, int dir)
207{
208 struct snd_soc_codec *codec = codec_dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +0900209 struct wm8523_priv *wm8523 = snd_soc_codec_get_drvdata(codec);
Mark Brown1dcf98f2009-07-01 18:28:54 +0100210 unsigned int val;
211 int i;
212
213 wm8523->sysclk = freq;
214
215 wm8523->rate_constraint.count = 0;
216 for (i = 0; i < ARRAY_SIZE(lrclk_ratios); i++) {
217 val = freq / lrclk_ratios[i].ratio;
218 /* Check that it's a standard rate since core can't
219 * cope with others and having the odd rates confuses
220 * constraint matching.
221 */
222 switch (val) {
223 case 8000:
224 case 11025:
225 case 16000:
226 case 22050:
227 case 32000:
228 case 44100:
229 case 48000:
230 case 64000:
231 case 88200:
232 case 96000:
233 case 176400:
234 case 192000:
235 dev_dbg(codec->dev, "Supported sample rate: %dHz\n",
236 val);
237 wm8523->rate_constraint_list[i] = val;
238 wm8523->rate_constraint.count++;
239 break;
240 default:
241 dev_dbg(codec->dev, "Skipping sample rate: %dHz\n",
242 val);
243 }
244 }
245
246 /* Need at least one supported rate... */
247 if (wm8523->rate_constraint.count == 0)
248 return -EINVAL;
249
250 return 0;
251}
252
253
254static int wm8523_set_dai_fmt(struct snd_soc_dai *codec_dai,
255 unsigned int fmt)
256{
257 struct snd_soc_codec *codec = codec_dai->codec;
Mark Brown8d50e442009-07-10 23:12:01 +0100258 u16 aifctrl1 = snd_soc_read(codec, WM8523_AIF_CTRL1);
Mark Brown1dcf98f2009-07-01 18:28:54 +0100259
260 aifctrl1 &= ~(WM8523_BCLK_INV_MASK | WM8523_LRCLK_INV_MASK |
261 WM8523_FMT_MASK | WM8523_AIF_MSTR_MASK);
262
263 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
264 case SND_SOC_DAIFMT_CBM_CFM:
265 aifctrl1 |= WM8523_AIF_MSTR;
266 break;
267 case SND_SOC_DAIFMT_CBS_CFS:
268 break;
269 default:
270 return -EINVAL;
271 }
272
273 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
274 case SND_SOC_DAIFMT_I2S:
275 aifctrl1 |= 0x0002;
276 break;
277 case SND_SOC_DAIFMT_RIGHT_J:
278 break;
279 case SND_SOC_DAIFMT_LEFT_J:
280 aifctrl1 |= 0x0001;
281 break;
282 case SND_SOC_DAIFMT_DSP_A:
283 aifctrl1 |= 0x0003;
284 break;
285 case SND_SOC_DAIFMT_DSP_B:
286 aifctrl1 |= 0x0023;
287 break;
288 default:
289 return -EINVAL;
290 }
291
292 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
293 case SND_SOC_DAIFMT_NB_NF:
294 break;
295 case SND_SOC_DAIFMT_IB_IF:
296 aifctrl1 |= WM8523_BCLK_INV | WM8523_LRCLK_INV;
297 break;
298 case SND_SOC_DAIFMT_IB_NF:
299 aifctrl1 |= WM8523_BCLK_INV;
300 break;
301 case SND_SOC_DAIFMT_NB_IF:
302 aifctrl1 |= WM8523_LRCLK_INV;
303 break;
304 default:
305 return -EINVAL;
306 }
307
Mark Brown8d50e442009-07-10 23:12:01 +0100308 snd_soc_write(codec, WM8523_AIF_CTRL1, aifctrl1);
Mark Brown1dcf98f2009-07-01 18:28:54 +0100309
310 return 0;
311}
312
313static int wm8523_set_bias_level(struct snd_soc_codec *codec,
314 enum snd_soc_bias_level level)
315{
Mark Brownb2c812e2010-04-14 15:35:19 +0900316 struct wm8523_priv *wm8523 = snd_soc_codec_get_drvdata(codec);
Lars-Peter Clausenbeebca32010-12-28 21:37:57 +0100317 u16 *reg_cache = codec->reg_cache;
Mark Brown1dcf98f2009-07-01 18:28:54 +0100318 int ret, i;
319
320 switch (level) {
321 case SND_SOC_BIAS_ON:
322 break;
323
324 case SND_SOC_BIAS_PREPARE:
325 /* Full power on */
326 snd_soc_update_bits(codec, WM8523_PSCTRL1,
327 WM8523_SYS_ENA_MASK, 3);
328 break;
329
330 case SND_SOC_BIAS_STANDBY:
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200331 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
Mark Brown1dcf98f2009-07-01 18:28:54 +0100332 ret = regulator_bulk_enable(ARRAY_SIZE(wm8523->supplies),
333 wm8523->supplies);
334 if (ret != 0) {
335 dev_err(codec->dev,
336 "Failed to enable supplies: %d\n",
337 ret);
338 return ret;
339 }
340
341 /* Initial power up */
342 snd_soc_update_bits(codec, WM8523_PSCTRL1,
343 WM8523_SYS_ENA_MASK, 1);
344
345 /* Sync back default/cached values */
346 for (i = WM8523_AIF_CTRL1;
347 i < WM8523_MAX_REGISTER; i++)
Lars-Peter Clausenbeebca32010-12-28 21:37:57 +0100348 snd_soc_write(codec, i, reg_cache[i]);
Mark Brown1dcf98f2009-07-01 18:28:54 +0100349
350
351 msleep(100);
352 }
353
354 /* Power up to mute */
355 snd_soc_update_bits(codec, WM8523_PSCTRL1,
356 WM8523_SYS_ENA_MASK, 2);
357
358 break;
359
360 case SND_SOC_BIAS_OFF:
361 /* The chip runs through the power down sequence for us. */
362 snd_soc_update_bits(codec, WM8523_PSCTRL1,
363 WM8523_SYS_ENA_MASK, 0);
364 msleep(100);
365
366 regulator_bulk_disable(ARRAY_SIZE(wm8523->supplies),
367 wm8523->supplies);
368 break;
369 }
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200370 codec->dapm.bias_level = level;
Mark Brown1dcf98f2009-07-01 18:28:54 +0100371 return 0;
372}
373
374#define WM8523_RATES SNDRV_PCM_RATE_8000_192000
375
376#define WM8523_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
377 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
378
379static struct snd_soc_dai_ops wm8523_dai_ops = {
380 .startup = wm8523_startup,
381 .hw_params = wm8523_hw_params,
382 .set_sysclk = wm8523_set_dai_sysclk,
383 .set_fmt = wm8523_set_dai_fmt,
384};
385
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000386static struct snd_soc_dai_driver wm8523_dai = {
387 .name = "wm8523-hifi",
Mark Brown1dcf98f2009-07-01 18:28:54 +0100388 .playback = {
389 .stream_name = "Playback",
390 .channels_min = 2, /* Mono modes not yet supported */
391 .channels_max = 2,
392 .rates = WM8523_RATES,
393 .formats = WM8523_FORMATS,
394 },
395 .ops = &wm8523_dai_ops,
396};
Mark Brown1dcf98f2009-07-01 18:28:54 +0100397
398#ifdef CONFIG_PM
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000399static int wm8523_suspend(struct snd_soc_codec *codec, pm_message_t state)
Mark Brown1dcf98f2009-07-01 18:28:54 +0100400{
Mark Brown1dcf98f2009-07-01 18:28:54 +0100401 wm8523_set_bias_level(codec, SND_SOC_BIAS_OFF);
402 return 0;
403}
404
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000405static int wm8523_resume(struct snd_soc_codec *codec)
Mark Brown1dcf98f2009-07-01 18:28:54 +0100406{
Mark Brown1dcf98f2009-07-01 18:28:54 +0100407 wm8523_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
Mark Brown1dcf98f2009-07-01 18:28:54 +0100408 return 0;
409}
410#else
411#define wm8523_suspend NULL
412#define wm8523_resume NULL
413#endif
414
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000415static int wm8523_probe(struct snd_soc_codec *codec)
Mark Brown1dcf98f2009-07-01 18:28:54 +0100416{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000417 struct wm8523_priv *wm8523 = snd_soc_codec_get_drvdata(codec);
418 int ret, i;
Mark Brown1dcf98f2009-07-01 18:28:54 +0100419
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000420 codec->hw_write = (hw_write_t)i2c_master_send;
Mark Brown1dcf98f2009-07-01 18:28:54 +0100421 wm8523->rate_constraint.list = &wm8523->rate_constraint_list[0];
422 wm8523->rate_constraint.count =
423 ARRAY_SIZE(wm8523->rate_constraint_list);
424
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000425 ret = snd_soc_codec_set_cache_io(codec, 8, 16, wm8523->control_type);
Mark Brown8d50e442009-07-10 23:12:01 +0100426 if (ret != 0) {
427 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000428 return ret;
Mark Brown8d50e442009-07-10 23:12:01 +0100429 }
430
Mark Brown1dcf98f2009-07-01 18:28:54 +0100431 for (i = 0; i < ARRAY_SIZE(wm8523->supplies); i++)
432 wm8523->supplies[i].supply = wm8523_supply_names[i];
433
434 ret = regulator_bulk_get(codec->dev, ARRAY_SIZE(wm8523->supplies),
435 wm8523->supplies);
436 if (ret != 0) {
437 dev_err(codec->dev, "Failed to request supplies: %d\n", ret);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000438 return ret;
Mark Brown1dcf98f2009-07-01 18:28:54 +0100439 }
440
441 ret = regulator_bulk_enable(ARRAY_SIZE(wm8523->supplies),
442 wm8523->supplies);
443 if (ret != 0) {
444 dev_err(codec->dev, "Failed to enable supplies: %d\n", ret);
445 goto err_get;
446 }
447
Mark Brown8d50e442009-07-10 23:12:01 +0100448 ret = snd_soc_read(codec, WM8523_DEVICE_ID);
Mark Brown1dcf98f2009-07-01 18:28:54 +0100449 if (ret < 0) {
450 dev_err(codec->dev, "Failed to read ID register\n");
451 goto err_enable;
452 }
453 if (ret != wm8523_reg[WM8523_DEVICE_ID]) {
454 dev_err(codec->dev, "Device is not a WM8523, ID is %x\n", ret);
455 ret = -EINVAL;
456 goto err_enable;
457 }
458
Mark Brown8d50e442009-07-10 23:12:01 +0100459 ret = snd_soc_read(codec, WM8523_REVISION);
Mark Brown1dcf98f2009-07-01 18:28:54 +0100460 if (ret < 0) {
461 dev_err(codec->dev, "Failed to read revision register\n");
462 goto err_enable;
463 }
464 dev_info(codec->dev, "revision %c\n",
465 (ret & WM8523_CHIP_REV_MASK) + 'A');
466
467 ret = wm8523_reset(codec);
468 if (ret < 0) {
469 dev_err(codec->dev, "Failed to issue reset\n");
470 goto err_enable;
471 }
472
Mark Brown1dcf98f2009-07-01 18:28:54 +0100473 /* Change some default settings - latch VU and enable ZC */
Mark Browna1b3b5e2010-12-24 16:59:30 +0000474 snd_soc_update_bits(codec, WM8523_DAC_GAINR,
475 WM8523_DACR_VU, WM8523_DACR_VU);
476 snd_soc_update_bits(codec, WM8523_DAC_CTRL3, WM8523_ZC, WM8523_ZC);
Mark Brown1dcf98f2009-07-01 18:28:54 +0100477
478 wm8523_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
479
480 /* Bias level configuration will have done an extra enable */
481 regulator_bulk_disable(ARRAY_SIZE(wm8523->supplies), wm8523->supplies);
482
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000483 snd_soc_add_controls(codec, wm8523_snd_controls,
484 ARRAY_SIZE(wm8523_snd_controls));
485 wm8523_add_widgets(codec);
Mark Brown1dcf98f2009-07-01 18:28:54 +0100486
487 return 0;
488
489err_enable:
490 regulator_bulk_disable(ARRAY_SIZE(wm8523->supplies), wm8523->supplies);
491err_get:
492 regulator_bulk_free(ARRAY_SIZE(wm8523->supplies), wm8523->supplies);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000493
Mark Brown1dcf98f2009-07-01 18:28:54 +0100494 return ret;
495}
496
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000497static int wm8523_remove(struct snd_soc_codec *codec)
Mark Brown1dcf98f2009-07-01 18:28:54 +0100498{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000499 struct wm8523_priv *wm8523 = snd_soc_codec_get_drvdata(codec);
500
501 wm8523_set_bias_level(codec, SND_SOC_BIAS_OFF);
Mark Brown1dcf98f2009-07-01 18:28:54 +0100502 regulator_bulk_free(ARRAY_SIZE(wm8523->supplies), wm8523->supplies);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000503 return 0;
Mark Brown1dcf98f2009-07-01 18:28:54 +0100504}
505
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000506static struct snd_soc_codec_driver soc_codec_dev_wm8523 = {
507 .probe = wm8523_probe,
508 .remove = wm8523_remove,
509 .suspend = wm8523_suspend,
510 .resume = wm8523_resume,
511 .set_bias_level = wm8523_set_bias_level,
512 .reg_cache_size = WM8523_REGISTER_COUNT,
513 .reg_word_size = sizeof(u16),
514 .reg_cache_default = wm8523_reg,
515 .volatile_register = wm8523_volatile_register,
516};
517
Mark Brownbf5a85b2011-08-02 13:08:13 +0900518static const struct of_device_id wm8523_of_match[] = {
519 { .compatible = "wlf,wm8523" },
520 { },
521};
522
Mark Brown1dcf98f2009-07-01 18:28:54 +0100523#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
524static __devinit int wm8523_i2c_probe(struct i2c_client *i2c,
525 const struct i2c_device_id *id)
526{
527 struct wm8523_priv *wm8523;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000528 int ret;
Mark Brown1dcf98f2009-07-01 18:28:54 +0100529
530 wm8523 = kzalloc(sizeof(struct wm8523_priv), GFP_KERNEL);
531 if (wm8523 == NULL)
532 return -ENOMEM;
533
Mark Brown1dcf98f2009-07-01 18:28:54 +0100534 i2c_set_clientdata(i2c, wm8523);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000535 wm8523->control_type = SND_SOC_I2C;
Mark Brown1dcf98f2009-07-01 18:28:54 +0100536
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000537 ret = snd_soc_register_codec(&i2c->dev,
538 &soc_codec_dev_wm8523, &wm8523_dai, 1);
539 if (ret < 0)
540 kfree(wm8523);
541 return ret;
Mark Brown1dcf98f2009-07-01 18:28:54 +0100542
Mark Brown1dcf98f2009-07-01 18:28:54 +0100543}
544
545static __devexit int wm8523_i2c_remove(struct i2c_client *client)
546{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000547 snd_soc_unregister_codec(&client->dev);
548 kfree(i2c_get_clientdata(client));
Mark Brown1dcf98f2009-07-01 18:28:54 +0100549 return 0;
550}
551
Mark Brown1dcf98f2009-07-01 18:28:54 +0100552static const struct i2c_device_id wm8523_i2c_id[] = {
553 { "wm8523", 0 },
554 { }
555};
556MODULE_DEVICE_TABLE(i2c, wm8523_i2c_id);
557
558static struct i2c_driver wm8523_i2c_driver = {
559 .driver = {
Mark Brown96654082011-08-02 13:04:14 +0900560 .name = "wm8523",
Mark Brown1dcf98f2009-07-01 18:28:54 +0100561 .owner = THIS_MODULE,
Mark Brownbf5a85b2011-08-02 13:08:13 +0900562 .of_match_table = wm8523_of_match,
Mark Brown1dcf98f2009-07-01 18:28:54 +0100563 },
564 .probe = wm8523_i2c_probe,
565 .remove = __devexit_p(wm8523_i2c_remove),
Mark Brown1dcf98f2009-07-01 18:28:54 +0100566 .id_table = wm8523_i2c_id,
567};
568#endif
569
570static int __init wm8523_modinit(void)
571{
572 int ret;
573#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
574 ret = i2c_add_driver(&wm8523_i2c_driver);
575 if (ret != 0) {
576 printk(KERN_ERR "Failed to register WM8523 I2C driver: %d\n",
577 ret);
578 }
579#endif
580 return 0;
581}
582module_init(wm8523_modinit);
583
584static void __exit wm8523_exit(void)
585{
586#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
587 i2c_del_driver(&wm8523_i2c_driver);
588#endif
589}
590module_exit(wm8523_exit);
591
592MODULE_DESCRIPTION("ASoC WM8523 driver");
593MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
594MODULE_LICENSE("GPL");