blob: 8c5b9df3e54204f5f6ee1c6159d1897999fd96c9 [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 Brownb9288f42012-09-10 16:27:45 +080020#include <linux/regmap.h>
Mark Brown1dcf98f2009-07-01 18:28:54 +010021#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 {
Mark Brownb9288f42012-09-10 16:27:45 +080043 struct regmap *regmap;
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
Mark Brownb9288f42012-09-10 16:27:45 +080050static const struct reg_default wm8523_reg_defaults[] = {
51 { 2, 0x0000 }, /* R2 - PSCTRL1 */
52 { 3, 0x1812 }, /* R3 - AIF_CTRL1 */
53 { 4, 0x0000 }, /* R4 - AIF_CTRL2 */
54 { 5, 0x0001 }, /* R5 - DAC_CTRL3 */
55 { 6, 0x0190 }, /* R6 - DAC_GAINL */
56 { 7, 0x0190 }, /* R7 - DAC_GAINR */
57 { 8, 0x0000 }, /* R8 - ZERO_DETECT */
Mark Brown1dcf98f2009-07-01 18:28:54 +010058};
59
Mark Brownb9288f42012-09-10 16:27:45 +080060static bool wm8523_volatile_register(struct device *dev, unsigned int reg)
Mark Brown1dcf98f2009-07-01 18:28:54 +010061{
62 switch (reg) {
63 case WM8523_DEVICE_ID:
64 case WM8523_REVISION:
Mark Brownb9288f42012-09-10 16:27:45 +080065 return true;
Mark Brown1dcf98f2009-07-01 18:28:54 +010066 default:
Mark Brownb9288f42012-09-10 16:27:45 +080067 return false;
Mark Brown1dcf98f2009-07-01 18:28:54 +010068 }
69}
70
Mark Brown1dcf98f2009-07-01 18:28:54 +010071static const DECLARE_TLV_DB_SCALE(dac_tlv, -10000, 25, 0);
72
73static const char *wm8523_zd_count_text[] = {
74 "1024",
75 "2048",
76};
77
Takashi Iwaifed08d92014-02-18 10:35:49 +010078static SOC_ENUM_SINGLE_DECL(wm8523_zc_count, WM8523_ZERO_DETECT, 0,
79 wm8523_zd_count_text);
Mark Brown1dcf98f2009-07-01 18:28:54 +010080
Mark Brown16616992011-08-22 16:02:43 +010081static const struct snd_kcontrol_new wm8523_controls[] = {
Mark Brown1dcf98f2009-07-01 18:28:54 +010082SOC_DOUBLE_R_TLV("Playback Volume", WM8523_DAC_GAINL, WM8523_DAC_GAINR,
83 0, 448, 0, dac_tlv),
84SOC_SINGLE("ZC Switch", WM8523_DAC_CTRL3, 4, 1, 0),
85SOC_SINGLE("Playback Deemphasis Switch", WM8523_AIF_CTRL1, 8, 1, 0),
86SOC_DOUBLE("Playback Switch", WM8523_DAC_CTRL3, 2, 3, 1, 1),
87SOC_SINGLE("Volume Ramp Up Switch", WM8523_DAC_CTRL3, 1, 1, 0),
88SOC_SINGLE("Volume Ramp Down Switch", WM8523_DAC_CTRL3, 0, 1, 0),
89SOC_ENUM("Zero Detect Count", wm8523_zc_count),
90};
91
92static const struct snd_soc_dapm_widget wm8523_dapm_widgets[] = {
93SND_SOC_DAPM_DAC("DAC", "Playback", SND_SOC_NOPM, 0, 0),
94SND_SOC_DAPM_OUTPUT("LINEVOUTL"),
95SND_SOC_DAPM_OUTPUT("LINEVOUTR"),
96};
97
Mark Brown16616992011-08-22 16:02:43 +010098static const struct snd_soc_dapm_route wm8523_dapm_routes[] = {
Mark Brown1dcf98f2009-07-01 18:28:54 +010099 { "LINEVOUTL", NULL, "DAC" },
100 { "LINEVOUTR", NULL, "DAC" },
101};
102
Mark Brown1dcf98f2009-07-01 18:28:54 +0100103static struct {
104 int value;
105 int ratio;
106} lrclk_ratios[WM8523_NUM_RATES] = {
107 { 1, 128 },
108 { 2, 192 },
109 { 3, 256 },
110 { 4, 384 },
111 { 5, 512 },
112 { 6, 768 },
113 { 7, 1152 },
114};
115
116static int wm8523_startup(struct snd_pcm_substream *substream,
117 struct snd_soc_dai *dai)
118{
119 struct snd_soc_codec *codec = dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +0900120 struct wm8523_priv *wm8523 = snd_soc_codec_get_drvdata(codec);
Mark Brown1dcf98f2009-07-01 18:28:54 +0100121
122 /* The set of sample rates that can be supported depends on the
123 * MCLK supplied to the CODEC - enforce this.
124 */
125 if (!wm8523->sysclk) {
126 dev_err(codec->dev,
127 "No MCLK configured, call set_sysclk() on init\n");
128 return -EINVAL;
129 }
130
Mark Brown1dcf98f2009-07-01 18:28:54 +0100131 snd_pcm_hw_constraint_list(substream->runtime, 0,
132 SNDRV_PCM_HW_PARAM_RATE,
133 &wm8523->rate_constraint);
134
135 return 0;
136}
137
138static int wm8523_hw_params(struct snd_pcm_substream *substream,
139 struct snd_pcm_hw_params *params,
140 struct snd_soc_dai *dai)
141{
Mark Browne6968a12012-04-04 15:58:16 +0100142 struct snd_soc_codec *codec = dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +0900143 struct wm8523_priv *wm8523 = snd_soc_codec_get_drvdata(codec);
Mark Brown1dcf98f2009-07-01 18:28:54 +0100144 int i;
Mark Brown8d50e442009-07-10 23:12:01 +0100145 u16 aifctrl1 = snd_soc_read(codec, WM8523_AIF_CTRL1);
146 u16 aifctrl2 = snd_soc_read(codec, WM8523_AIF_CTRL2);
Mark Brown1dcf98f2009-07-01 18:28:54 +0100147
148 /* Find a supported LRCLK ratio */
149 for (i = 0; i < ARRAY_SIZE(lrclk_ratios); i++) {
150 if (wm8523->sysclk / params_rate(params) ==
151 lrclk_ratios[i].ratio)
152 break;
153 }
154
155 /* Should never happen, should be handled by constraints */
156 if (i == ARRAY_SIZE(lrclk_ratios)) {
157 dev_err(codec->dev, "MCLK/fs ratio %d unsupported\n",
158 wm8523->sysclk / params_rate(params));
159 return -EINVAL;
160 }
161
162 aifctrl2 &= ~WM8523_SR_MASK;
163 aifctrl2 |= lrclk_ratios[i].value;
164
165 aifctrl1 &= ~WM8523_WL_MASK;
Mark Brown3fafcc8e62014-07-31 12:51:02 +0100166 switch (params_width(params)) {
167 case 16:
Mark Brown1dcf98f2009-07-01 18:28:54 +0100168 break;
Mark Brown3fafcc8e62014-07-31 12:51:02 +0100169 case 20:
Mark Brown1dcf98f2009-07-01 18:28:54 +0100170 aifctrl1 |= 0x8;
171 break;
Mark Brown3fafcc8e62014-07-31 12:51:02 +0100172 case 24:
Mark Brown1dcf98f2009-07-01 18:28:54 +0100173 aifctrl1 |= 0x10;
174 break;
Mark Brown3fafcc8e62014-07-31 12:51:02 +0100175 case 32:
Mark Brown1dcf98f2009-07-01 18:28:54 +0100176 aifctrl1 |= 0x18;
177 break;
178 }
179
Mark Brown8d50e442009-07-10 23:12:01 +0100180 snd_soc_write(codec, WM8523_AIF_CTRL1, aifctrl1);
181 snd_soc_write(codec, WM8523_AIF_CTRL2, aifctrl2);
Mark Brown1dcf98f2009-07-01 18:28:54 +0100182
183 return 0;
184}
185
186static int wm8523_set_dai_sysclk(struct snd_soc_dai *codec_dai,
187 int clk_id, unsigned int freq, int dir)
188{
189 struct snd_soc_codec *codec = codec_dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +0900190 struct wm8523_priv *wm8523 = snd_soc_codec_get_drvdata(codec);
Mark Brown1dcf98f2009-07-01 18:28:54 +0100191 unsigned int val;
192 int i;
193
194 wm8523->sysclk = freq;
195
196 wm8523->rate_constraint.count = 0;
197 for (i = 0; i < ARRAY_SIZE(lrclk_ratios); i++) {
198 val = freq / lrclk_ratios[i].ratio;
199 /* Check that it's a standard rate since core can't
200 * cope with others and having the odd rates confuses
201 * constraint matching.
202 */
203 switch (val) {
204 case 8000:
205 case 11025:
206 case 16000:
207 case 22050:
208 case 32000:
209 case 44100:
210 case 48000:
211 case 64000:
212 case 88200:
213 case 96000:
214 case 176400:
215 case 192000:
216 dev_dbg(codec->dev, "Supported sample rate: %dHz\n",
217 val);
218 wm8523->rate_constraint_list[i] = val;
219 wm8523->rate_constraint.count++;
220 break;
221 default:
222 dev_dbg(codec->dev, "Skipping sample rate: %dHz\n",
223 val);
224 }
225 }
226
227 /* Need at least one supported rate... */
228 if (wm8523->rate_constraint.count == 0)
229 return -EINVAL;
230
231 return 0;
232}
233
234
235static int wm8523_set_dai_fmt(struct snd_soc_dai *codec_dai,
236 unsigned int fmt)
237{
238 struct snd_soc_codec *codec = codec_dai->codec;
Mark Brown8d50e442009-07-10 23:12:01 +0100239 u16 aifctrl1 = snd_soc_read(codec, WM8523_AIF_CTRL1);
Mark Brown1dcf98f2009-07-01 18:28:54 +0100240
241 aifctrl1 &= ~(WM8523_BCLK_INV_MASK | WM8523_LRCLK_INV_MASK |
242 WM8523_FMT_MASK | WM8523_AIF_MSTR_MASK);
243
244 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
245 case SND_SOC_DAIFMT_CBM_CFM:
246 aifctrl1 |= WM8523_AIF_MSTR;
247 break;
248 case SND_SOC_DAIFMT_CBS_CFS:
249 break;
250 default:
251 return -EINVAL;
252 }
253
254 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
255 case SND_SOC_DAIFMT_I2S:
256 aifctrl1 |= 0x0002;
257 break;
258 case SND_SOC_DAIFMT_RIGHT_J:
259 break;
260 case SND_SOC_DAIFMT_LEFT_J:
261 aifctrl1 |= 0x0001;
262 break;
263 case SND_SOC_DAIFMT_DSP_A:
264 aifctrl1 |= 0x0003;
265 break;
266 case SND_SOC_DAIFMT_DSP_B:
267 aifctrl1 |= 0x0023;
268 break;
269 default:
270 return -EINVAL;
271 }
272
273 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
274 case SND_SOC_DAIFMT_NB_NF:
275 break;
276 case SND_SOC_DAIFMT_IB_IF:
277 aifctrl1 |= WM8523_BCLK_INV | WM8523_LRCLK_INV;
278 break;
279 case SND_SOC_DAIFMT_IB_NF:
280 aifctrl1 |= WM8523_BCLK_INV;
281 break;
282 case SND_SOC_DAIFMT_NB_IF:
283 aifctrl1 |= WM8523_LRCLK_INV;
284 break;
285 default:
286 return -EINVAL;
287 }
288
Mark Brown8d50e442009-07-10 23:12:01 +0100289 snd_soc_write(codec, WM8523_AIF_CTRL1, aifctrl1);
Mark Brown1dcf98f2009-07-01 18:28:54 +0100290
291 return 0;
292}
293
294static int wm8523_set_bias_level(struct snd_soc_codec *codec,
295 enum snd_soc_bias_level level)
296{
Mark Brownb2c812e2010-04-14 15:35:19 +0900297 struct wm8523_priv *wm8523 = snd_soc_codec_get_drvdata(codec);
Mark Brownb9288f42012-09-10 16:27:45 +0800298 int ret;
Mark Brown1dcf98f2009-07-01 18:28:54 +0100299
300 switch (level) {
301 case SND_SOC_BIAS_ON:
302 break;
303
304 case SND_SOC_BIAS_PREPARE:
305 /* Full power on */
306 snd_soc_update_bits(codec, WM8523_PSCTRL1,
307 WM8523_SYS_ENA_MASK, 3);
308 break;
309
310 case SND_SOC_BIAS_STANDBY:
Lars-Peter Clausen7db634d2015-06-01 10:10:32 +0200311 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
Mark Brown1dcf98f2009-07-01 18:28:54 +0100312 ret = regulator_bulk_enable(ARRAY_SIZE(wm8523->supplies),
313 wm8523->supplies);
314 if (ret != 0) {
315 dev_err(codec->dev,
316 "Failed to enable supplies: %d\n",
317 ret);
318 return ret;
319 }
320
Mark Brownb9288f42012-09-10 16:27:45 +0800321 /* Sync back default/cached values */
322 regcache_sync(wm8523->regmap);
323
Mark Brown1dcf98f2009-07-01 18:28:54 +0100324 /* Initial power up */
325 snd_soc_update_bits(codec, WM8523_PSCTRL1,
326 WM8523_SYS_ENA_MASK, 1);
327
Mark Brown1dcf98f2009-07-01 18:28:54 +0100328 msleep(100);
329 }
330
331 /* Power up to mute */
332 snd_soc_update_bits(codec, WM8523_PSCTRL1,
333 WM8523_SYS_ENA_MASK, 2);
334
335 break;
336
337 case SND_SOC_BIAS_OFF:
338 /* The chip runs through the power down sequence for us. */
339 snd_soc_update_bits(codec, WM8523_PSCTRL1,
340 WM8523_SYS_ENA_MASK, 0);
341 msleep(100);
342
343 regulator_bulk_disable(ARRAY_SIZE(wm8523->supplies),
344 wm8523->supplies);
345 break;
346 }
Mark Brown1dcf98f2009-07-01 18:28:54 +0100347 return 0;
348}
349
350#define WM8523_RATES SNDRV_PCM_RATE_8000_192000
351
352#define WM8523_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
353 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
354
Lars-Peter Clausen85e76522011-11-23 11:40:40 +0100355static const struct snd_soc_dai_ops wm8523_dai_ops = {
Mark Brown1dcf98f2009-07-01 18:28:54 +0100356 .startup = wm8523_startup,
357 .hw_params = wm8523_hw_params,
358 .set_sysclk = wm8523_set_dai_sysclk,
359 .set_fmt = wm8523_set_dai_fmt,
360};
361
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000362static struct snd_soc_dai_driver wm8523_dai = {
363 .name = "wm8523-hifi",
Mark Brown1dcf98f2009-07-01 18:28:54 +0100364 .playback = {
365 .stream_name = "Playback",
366 .channels_min = 2, /* Mono modes not yet supported */
367 .channels_max = 2,
368 .rates = WM8523_RATES,
369 .formats = WM8523_FORMATS,
370 },
371 .ops = &wm8523_dai_ops,
372};
Mark Brown1dcf98f2009-07-01 18:28:54 +0100373
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000374static int wm8523_probe(struct snd_soc_codec *codec)
Mark Brown1dcf98f2009-07-01 18:28:54 +0100375{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000376 struct wm8523_priv *wm8523 = snd_soc_codec_get_drvdata(codec);
Mark Brown1dcf98f2009-07-01 18:28:54 +0100377
Mark Brown1dcf98f2009-07-01 18:28:54 +0100378 wm8523->rate_constraint.list = &wm8523->rate_constraint_list[0];
379 wm8523->rate_constraint.count =
380 ARRAY_SIZE(wm8523->rate_constraint_list);
381
Mark Brown1dcf98f2009-07-01 18:28:54 +0100382 /* Change some default settings - latch VU and enable ZC */
Mark Browna1b3b5e2010-12-24 16:59:30 +0000383 snd_soc_update_bits(codec, WM8523_DAC_GAINR,
384 WM8523_DACR_VU, WM8523_DACR_VU);
385 snd_soc_update_bits(codec, WM8523_DAC_CTRL3, WM8523_ZC, WM8523_ZC);
Mark Brown1dcf98f2009-07-01 18:28:54 +0100386
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000387 return 0;
Mark Brown1dcf98f2009-07-01 18:28:54 +0100388}
389
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000390static struct snd_soc_codec_driver soc_codec_dev_wm8523 = {
391 .probe = wm8523_probe,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000392 .set_bias_level = wm8523_set_bias_level,
Lars-Peter Clausenca5e7c6a2014-11-23 13:37:20 +0100393 .suspend_bias_off = true,
Mark Brown16616992011-08-22 16:02:43 +0100394
395 .controls = wm8523_controls,
396 .num_controls = ARRAY_SIZE(wm8523_controls),
397 .dapm_widgets = wm8523_dapm_widgets,
398 .num_dapm_widgets = ARRAY_SIZE(wm8523_dapm_widgets),
399 .dapm_routes = wm8523_dapm_routes,
400 .num_dapm_routes = ARRAY_SIZE(wm8523_dapm_routes),
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000401};
402
Mark Brownbf5a85b2011-08-02 13:08:13 +0900403static const struct of_device_id wm8523_of_match[] = {
404 { .compatible = "wlf,wm8523" },
405 { },
406};
407
Mark Brownb9288f42012-09-10 16:27:45 +0800408static const struct regmap_config wm8523_regmap = {
409 .reg_bits = 8,
410 .val_bits = 16,
411 .max_register = WM8523_ZERO_DETECT,
412
413 .reg_defaults = wm8523_reg_defaults,
414 .num_reg_defaults = ARRAY_SIZE(wm8523_reg_defaults),
415 .cache_type = REGCACHE_RBTREE,
416
417 .volatile_reg = wm8523_volatile_register,
418};
419
Fabio Estevam008ef942013-11-20 15:37:50 -0200420#if IS_ENABLED(CONFIG_I2C)
Bill Pemberton7a79e942012-12-07 09:26:37 -0500421static int wm8523_i2c_probe(struct i2c_client *i2c,
422 const struct i2c_device_id *id)
Mark Brown1dcf98f2009-07-01 18:28:54 +0100423{
424 struct wm8523_priv *wm8523;
Mark Brown59ac2142012-09-10 17:07:24 +0800425 unsigned int val;
Mark Brown719b0c52012-09-10 16:23:34 +0800426 int ret, i;
Mark Brown1dcf98f2009-07-01 18:28:54 +0100427
Mark Brown7d014db2012-09-10 16:18:56 +0800428 wm8523 = devm_kzalloc(&i2c->dev, sizeof(struct wm8523_priv),
429 GFP_KERNEL);
Mark Brown1dcf98f2009-07-01 18:28:54 +0100430 if (wm8523 == NULL)
431 return -ENOMEM;
432
Mark Brownb9288f42012-09-10 16:27:45 +0800433 wm8523->regmap = devm_regmap_init_i2c(i2c, &wm8523_regmap);
434 if (IS_ERR(wm8523->regmap)) {
435 ret = PTR_ERR(wm8523->regmap);
436 dev_err(&i2c->dev, "Failed to create regmap: %d\n", ret);
437 return ret;
438 }
439
Mark Brown719b0c52012-09-10 16:23:34 +0800440 for (i = 0; i < ARRAY_SIZE(wm8523->supplies); i++)
441 wm8523->supplies[i].supply = wm8523_supply_names[i];
442
443 ret = devm_regulator_bulk_get(&i2c->dev, ARRAY_SIZE(wm8523->supplies),
444 wm8523->supplies);
445 if (ret != 0) {
446 dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret);
447 return ret;
448 }
449
Mark Brown59ac2142012-09-10 17:07:24 +0800450 ret = regulator_bulk_enable(ARRAY_SIZE(wm8523->supplies),
451 wm8523->supplies);
452 if (ret != 0) {
453 dev_err(&i2c->dev, "Failed to enable supplies: %d\n", ret);
454 return ret;
455 }
456
457 ret = regmap_read(wm8523->regmap, WM8523_DEVICE_ID, &val);
458 if (ret < 0) {
459 dev_err(&i2c->dev, "Failed to read ID register\n");
460 goto err_enable;
461 }
462 if (val != 0x8523) {
463 dev_err(&i2c->dev, "Device is not a WM8523, ID is %x\n", ret);
464 ret = -EINVAL;
465 goto err_enable;
466 }
467
468 ret = regmap_read(wm8523->regmap, WM8523_REVISION, &val);
469 if (ret < 0) {
470 dev_err(&i2c->dev, "Failed to read revision register\n");
471 goto err_enable;
472 }
473 dev_info(&i2c->dev, "revision %c\n",
474 (val & WM8523_CHIP_REV_MASK) + 'A');
475
476 ret = regmap_write(wm8523->regmap, WM8523_DEVICE_ID, 0x8523);
477 if (ret != 0) {
478 dev_err(&i2c->dev, "Failed to reset device: %d\n", ret);
479 goto err_enable;
480 }
481
482 regulator_bulk_disable(ARRAY_SIZE(wm8523->supplies), wm8523->supplies);
483
Mark Brown1dcf98f2009-07-01 18:28:54 +0100484 i2c_set_clientdata(i2c, wm8523);
Mark Brown1dcf98f2009-07-01 18:28:54 +0100485
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000486 ret = snd_soc_register_codec(&i2c->dev,
487 &soc_codec_dev_wm8523, &wm8523_dai, 1);
Mark Brown7d014db2012-09-10 16:18:56 +0800488
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000489 return ret;
Mark Brown1dcf98f2009-07-01 18:28:54 +0100490
Mark Brown59ac2142012-09-10 17:07:24 +0800491err_enable:
492 regulator_bulk_disable(ARRAY_SIZE(wm8523->supplies), wm8523->supplies);
493 return ret;
Mark Brown1dcf98f2009-07-01 18:28:54 +0100494}
495
Bill Pemberton7a79e942012-12-07 09:26:37 -0500496static int wm8523_i2c_remove(struct i2c_client *client)
Mark Brown1dcf98f2009-07-01 18:28:54 +0100497{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000498 snd_soc_unregister_codec(&client->dev);
Mark Brown1dcf98f2009-07-01 18:28:54 +0100499 return 0;
500}
501
Mark Brown1dcf98f2009-07-01 18:28:54 +0100502static const struct i2c_device_id wm8523_i2c_id[] = {
503 { "wm8523", 0 },
504 { }
505};
506MODULE_DEVICE_TABLE(i2c, wm8523_i2c_id);
507
508static struct i2c_driver wm8523_i2c_driver = {
509 .driver = {
Mark Brown96654082011-08-02 13:04:14 +0900510 .name = "wm8523",
Mark Brown1dcf98f2009-07-01 18:28:54 +0100511 .owner = THIS_MODULE,
Mark Brownbf5a85b2011-08-02 13:08:13 +0900512 .of_match_table = wm8523_of_match,
Mark Brown1dcf98f2009-07-01 18:28:54 +0100513 },
514 .probe = wm8523_i2c_probe,
Bill Pemberton7a79e942012-12-07 09:26:37 -0500515 .remove = wm8523_i2c_remove,
Mark Brown1dcf98f2009-07-01 18:28:54 +0100516 .id_table = wm8523_i2c_id,
517};
518#endif
519
520static int __init wm8523_modinit(void)
521{
522 int ret;
Fabio Estevam008ef942013-11-20 15:37:50 -0200523#if IS_ENABLED(CONFIG_I2C)
Mark Brown1dcf98f2009-07-01 18:28:54 +0100524 ret = i2c_add_driver(&wm8523_i2c_driver);
525 if (ret != 0) {
526 printk(KERN_ERR "Failed to register WM8523 I2C driver: %d\n",
527 ret);
528 }
529#endif
530 return 0;
531}
532module_init(wm8523_modinit);
533
534static void __exit wm8523_exit(void)
535{
Fabio Estevam008ef942013-11-20 15:37:50 -0200536#if IS_ENABLED(CONFIG_I2C)
Mark Brown1dcf98f2009-07-01 18:28:54 +0100537 i2c_del_driver(&wm8523_i2c_driver);
538#endif
539}
540module_exit(wm8523_exit);
541
542MODULE_DESCRIPTION("ASoC WM8523 driver");
543MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
544MODULE_LICENSE("GPL");