Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
wm9090.c
Go to the documentation of this file.
1 /*
2  * ALSA SoC WM9090 driver
3  *
4  * Copyright 2009-12 Wolfson Microelectronics
5  *
6  * Author: Mark Brown <[email protected]>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * version 2 as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  */
22 
23 #include <linux/module.h>
24 #include <linux/errno.h>
25 #include <linux/device.h>
26 #include <linux/i2c.h>
27 #include <linux/delay.h>
28 #include <linux/regmap.h>
29 #include <linux/slab.h>
30 #include <sound/initval.h>
31 #include <sound/soc.h>
32 #include <sound/tlv.h>
33 #include <sound/wm9090.h>
34 
35 #include "wm9090.h"
36 
37 static const struct reg_default wm9090_reg_defaults[] = {
38  { 1, 0x0006 }, /* R1 - Power Management (1) */
39  { 2, 0x6000 }, /* R2 - Power Management (2) */
40  { 3, 0x0000 }, /* R3 - Power Management (3) */
41  { 6, 0x01C0 }, /* R6 - Clocking 1 */
42  { 22, 0x0003 }, /* R22 - IN1 Line Control */
43  { 23, 0x0003 }, /* R23 - IN2 Line Control */
44  { 24, 0x0083 }, /* R24 - IN1 Line Input A Volume */
45  { 25, 0x0083 }, /* R25 - IN1 Line Input B Volume */
46  { 26, 0x0083 }, /* R26 - IN2 Line Input A Volume */
47  { 27, 0x0083 }, /* R27 - IN2 Line Input B Volume */
48  { 28, 0x002D }, /* R28 - Left Output Volume */
49  { 29, 0x002D }, /* R29 - Right Output Volume */
50  { 34, 0x0100 }, /* R34 - SPKMIXL Attenuation */
51  { 35, 0x0010 }, /* R36 - SPKOUT Mixers */
52  { 37, 0x0140 }, /* R37 - ClassD3 */
53  { 38, 0x0039 }, /* R38 - Speaker Volume Left */
54  { 45, 0x0000 }, /* R45 - Output Mixer1 */
55  { 46, 0x0000 }, /* R46 - Output Mixer2 */
56  { 47, 0x0100 }, /* R47 - Output Mixer3 */
57  { 48, 0x0100 }, /* R48 - Output Mixer4 */
58  { 54, 0x0000 }, /* R54 - Speaker Mixer */
59  { 57, 0x000D }, /* R57 - AntiPOP2 */
60  { 70, 0x0000 }, /* R70 - Write Sequencer 0 */
61  { 71, 0x0000 }, /* R71 - Write Sequencer 1 */
62  { 72, 0x0000 }, /* R72 - Write Sequencer 2 */
63  { 73, 0x0000 }, /* R73 - Write Sequencer 3 */
64  { 74, 0x0000 }, /* R74 - Write Sequencer 4 */
65  { 75, 0x0000 }, /* R75 - Write Sequencer 5 */
66  { 76, 0x1F25 }, /* R76 - Charge Pump 1 */
67  { 85, 0x054A }, /* R85 - DC Servo 1 */
68  { 87, 0x0000 }, /* R87 - DC Servo 3 */
69  { 96, 0x0100 }, /* R96 - Analogue HP 0 */
70  { 98, 0x8640 }, /* R98 - AGC Control 0 */
71  { 99, 0xC000 }, /* R99 - AGC Control 1 */
72  { 100, 0x0200 }, /* R100 - AGC Control 2 */
73 };
74 
75 /* This struct is used to save the context */
76 struct wm9090_priv {
78  struct regmap *regmap;
79 };
80 
81 static bool wm9090_volatile(struct device *dev, unsigned int reg)
82 {
83  switch (reg) {
85  case WM9090_DC_SERVO_0:
89  return true;
90 
91  default:
92  return false;
93  }
94 }
95 
96 static bool wm9090_readable(struct device *dev, unsigned int reg)
97 {
98  switch (reg) {
103  case WM9090_CLOCKING_1:
114  case WM9090_CLASSD3:
121  case WM9090_ANTIPOP2:
129  case WM9090_DC_SERVO_0:
130  case WM9090_DC_SERVO_1:
131  case WM9090_DC_SERVO_3:
139  return true;
140 
141  default:
142  return false;
143  }
144 }
145 
146 static void wait_for_dc_servo(struct snd_soc_codec *codec)
147 {
148  unsigned int reg;
149  int count = 0;
150 
151  dev_dbg(codec->dev, "Waiting for DC servo...\n");
152  do {
153  count++;
154  msleep(1);
156  dev_dbg(codec->dev, "DC servo status: %x\n", reg);
157  } while ((reg & WM9090_DCS_CAL_COMPLETE_MASK)
158  != WM9090_DCS_CAL_COMPLETE_MASK && count < 1000);
159 
160  if ((reg & WM9090_DCS_CAL_COMPLETE_MASK)
161  != WM9090_DCS_CAL_COMPLETE_MASK)
162  dev_err(codec->dev, "Timed out waiting for DC Servo\n");
163 }
164 
165 static const unsigned int in_tlv[] = {
167  0, 0, TLV_DB_SCALE_ITEM(-600, 0, 0),
168  1, 3, TLV_DB_SCALE_ITEM(-350, 350, 0),
169  4, 6, TLV_DB_SCALE_ITEM(600, 600, 0),
170 };
171 static const unsigned int mix_tlv[] = {
173  0, 2, TLV_DB_SCALE_ITEM(-1200, 300, 0),
174  3, 3, TLV_DB_SCALE_ITEM(0, 0, 0),
175 };
176 static const DECLARE_TLV_DB_SCALE(out_tlv, -5700, 100, 0);
177 static const unsigned int spkboost_tlv[] = {
179  0, 6, TLV_DB_SCALE_ITEM(0, 150, 0),
180  7, 7, TLV_DB_SCALE_ITEM(1200, 0, 0),
181 };
182 
183 static const struct snd_kcontrol_new wm9090_controls[] = {
184 SOC_SINGLE_TLV("IN1A Volume", WM9090_IN1_LINE_INPUT_A_VOLUME, 0, 6, 0,
185  in_tlv),
186 SOC_SINGLE("IN1A Switch", WM9090_IN1_LINE_INPUT_A_VOLUME, 7, 1, 1),
187 SOC_SINGLE("IN1A ZC Switch", WM9090_IN1_LINE_INPUT_A_VOLUME, 6, 1, 0),
188 
189 SOC_SINGLE_TLV("IN2A Volume", WM9090_IN2_LINE_INPUT_A_VOLUME, 0, 6, 0,
190  in_tlv),
191 SOC_SINGLE("IN2A Switch", WM9090_IN2_LINE_INPUT_A_VOLUME, 7, 1, 1),
192 SOC_SINGLE("IN2A ZC Switch", WM9090_IN2_LINE_INPUT_A_VOLUME, 6, 1, 0),
193 
194 SOC_SINGLE("MIXOUTL Switch", WM9090_OUTPUT_MIXER3, 8, 1, 1),
195 SOC_SINGLE_TLV("MIXOUTL IN1A Volume", WM9090_OUTPUT_MIXER3, 6, 3, 1,
196  mix_tlv),
197 SOC_SINGLE_TLV("MIXOUTL IN2A Volume", WM9090_OUTPUT_MIXER3, 2, 3, 1,
198  mix_tlv),
199 
200 SOC_SINGLE("MIXOUTR Switch", WM9090_OUTPUT_MIXER4, 8, 1, 1),
201 SOC_SINGLE_TLV("MIXOUTR IN1A Volume", WM9090_OUTPUT_MIXER4, 6, 3, 1,
202  mix_tlv),
203 SOC_SINGLE_TLV("MIXOUTR IN2A Volume", WM9090_OUTPUT_MIXER4, 2, 3, 1,
204  mix_tlv),
205 
206 SOC_SINGLE("SPKMIX Switch", WM9090_SPKMIXL_ATTENUATION, 8, 1, 1),
207 SOC_SINGLE_TLV("SPKMIX IN1A Volume", WM9090_SPKMIXL_ATTENUATION, 6, 3, 1,
208  mix_tlv),
209 SOC_SINGLE_TLV("SPKMIX IN2A Volume", WM9090_SPKMIXL_ATTENUATION, 2, 3, 1,
210  mix_tlv),
211 
212 SOC_DOUBLE_R_TLV("Headphone Volume", WM9090_LEFT_OUTPUT_VOLUME,
213  WM9090_RIGHT_OUTPUT_VOLUME, 0, 63, 0, out_tlv),
214 SOC_DOUBLE_R("Headphone Switch", WM9090_LEFT_OUTPUT_VOLUME,
215  WM9090_RIGHT_OUTPUT_VOLUME, 6, 1, 1),
216 SOC_DOUBLE_R("Headphone ZC Switch", WM9090_LEFT_OUTPUT_VOLUME,
217  WM9090_RIGHT_OUTPUT_VOLUME, 7, 1, 0),
218 
219 SOC_SINGLE_TLV("Speaker Volume", WM9090_SPEAKER_VOLUME_LEFT, 0, 63, 0,
220  out_tlv),
221 SOC_SINGLE("Speaker Switch", WM9090_SPEAKER_VOLUME_LEFT, 6, 1, 1),
222 SOC_SINGLE("Speaker ZC Switch", WM9090_SPEAKER_VOLUME_LEFT, 7, 1, 0),
223 SOC_SINGLE_TLV("Speaker Boost Volume", WM9090_CLASSD3, 3, 7, 0, spkboost_tlv),
224 };
225 
226 static const struct snd_kcontrol_new wm9090_in1_se_controls[] = {
227 SOC_SINGLE_TLV("IN1B Volume", WM9090_IN1_LINE_INPUT_B_VOLUME, 0, 6, 0,
228  in_tlv),
229 SOC_SINGLE("IN1B Switch", WM9090_IN1_LINE_INPUT_B_VOLUME, 7, 1, 1),
230 SOC_SINGLE("IN1B ZC Switch", WM9090_IN1_LINE_INPUT_B_VOLUME, 6, 1, 0),
231 
232 SOC_SINGLE_TLV("SPKMIX IN1B Volume", WM9090_SPKMIXL_ATTENUATION, 4, 3, 1,
233  mix_tlv),
234 SOC_SINGLE_TLV("MIXOUTL IN1B Volume", WM9090_OUTPUT_MIXER3, 4, 3, 1,
235  mix_tlv),
236 SOC_SINGLE_TLV("MIXOUTR IN1B Volume", WM9090_OUTPUT_MIXER4, 4, 3, 1,
237  mix_tlv),
238 };
239 
240 static const struct snd_kcontrol_new wm9090_in2_se_controls[] = {
241 SOC_SINGLE_TLV("IN2B Volume", WM9090_IN2_LINE_INPUT_B_VOLUME, 0, 6, 0,
242  in_tlv),
243 SOC_SINGLE("IN2B Switch", WM9090_IN2_LINE_INPUT_B_VOLUME, 7, 1, 1),
244 SOC_SINGLE("IN2B ZC Switch", WM9090_IN2_LINE_INPUT_B_VOLUME, 6, 1, 0),
245 
246 SOC_SINGLE_TLV("SPKMIX IN2B Volume", WM9090_SPKMIXL_ATTENUATION, 0, 3, 1,
247  mix_tlv),
248 SOC_SINGLE_TLV("MIXOUTL IN2B Volume", WM9090_OUTPUT_MIXER3, 0, 3, 1,
249  mix_tlv),
250 SOC_SINGLE_TLV("MIXOUTR IN2B Volume", WM9090_OUTPUT_MIXER4, 0, 3, 1,
251  mix_tlv),
252 };
253 
254 static int hp_ev(struct snd_soc_dapm_widget *w,
255  struct snd_kcontrol *kcontrol, int event)
256 {
257  struct snd_soc_codec *codec = w->codec;
258  unsigned int reg = snd_soc_read(codec, WM9090_ANALOGUE_HP_0);
259 
260  switch (event) {
264 
265  msleep(5);
266 
270 
272  snd_soc_write(codec, WM9090_ANALOGUE_HP_0, reg);
273 
274  /* Start the DC servo. We don't currently use the
275  * ability to save the state since we don't have full
276  * control of the analogue paths and they can change
277  * DC offsets; see the WM8904 driver for an example of
278  * doing so.
279  */
285  wait_for_dc_servo(codec);
286 
289  snd_soc_write(codec, WM9090_ANALOGUE_HP_0, reg);
290  break;
291 
293  reg &= ~(WM9090_HPOUT1L_RMV_SHORT |
299 
300  snd_soc_write(codec, WM9090_ANALOGUE_HP_0, reg);
301 
302  snd_soc_write(codec, WM9090_DC_SERVO_0, 0);
303 
306  0);
307 
309  WM9090_CP_ENA, 0);
310  break;
311  }
312 
313  return 0;
314 }
315 
316 static const struct snd_kcontrol_new spkmix[] = {
317 SOC_DAPM_SINGLE("IN1A Switch", WM9090_SPEAKER_MIXER, 6, 1, 0),
318 SOC_DAPM_SINGLE("IN1B Switch", WM9090_SPEAKER_MIXER, 4, 1, 0),
319 SOC_DAPM_SINGLE("IN2A Switch", WM9090_SPEAKER_MIXER, 2, 1, 0),
320 SOC_DAPM_SINGLE("IN2B Switch", WM9090_SPEAKER_MIXER, 0, 1, 0),
321 };
322 
323 static const struct snd_kcontrol_new spkout[] = {
324 SOC_DAPM_SINGLE("Mixer Switch", WM9090_SPKOUT_MIXERS, 4, 1, 0),
325 };
326 
327 static const struct snd_kcontrol_new mixoutl[] = {
328 SOC_DAPM_SINGLE("IN1A Switch", WM9090_OUTPUT_MIXER1, 6, 1, 0),
329 SOC_DAPM_SINGLE("IN1B Switch", WM9090_OUTPUT_MIXER1, 4, 1, 0),
330 SOC_DAPM_SINGLE("IN2A Switch", WM9090_OUTPUT_MIXER1, 2, 1, 0),
331 SOC_DAPM_SINGLE("IN2B Switch", WM9090_OUTPUT_MIXER1, 0, 1, 0),
332 };
333 
334 static const struct snd_kcontrol_new mixoutr[] = {
335 SOC_DAPM_SINGLE("IN1A Switch", WM9090_OUTPUT_MIXER2, 6, 1, 0),
336 SOC_DAPM_SINGLE("IN1B Switch", WM9090_OUTPUT_MIXER2, 4, 1, 0),
337 SOC_DAPM_SINGLE("IN2A Switch", WM9090_OUTPUT_MIXER2, 2, 1, 0),
338 SOC_DAPM_SINGLE("IN2B Switch", WM9090_OUTPUT_MIXER2, 0, 1, 0),
339 };
340 
341 static const struct snd_soc_dapm_widget wm9090_dapm_widgets[] = {
342 SND_SOC_DAPM_INPUT("IN1+"),
343 SND_SOC_DAPM_INPUT("IN1-"),
344 SND_SOC_DAPM_INPUT("IN2+"),
345 SND_SOC_DAPM_INPUT("IN2-"),
346 
348 
349 SND_SOC_DAPM_PGA("IN1A PGA", WM9090_POWER_MANAGEMENT_2, 7, 0, NULL, 0),
350 SND_SOC_DAPM_PGA("IN1B PGA", WM9090_POWER_MANAGEMENT_2, 6, 0, NULL, 0),
351 SND_SOC_DAPM_PGA("IN2A PGA", WM9090_POWER_MANAGEMENT_2, 5, 0, NULL, 0),
352 SND_SOC_DAPM_PGA("IN2B PGA", WM9090_POWER_MANAGEMENT_2, 4, 0, NULL, 0),
353 
355  spkmix, ARRAY_SIZE(spkmix)),
357  mixoutl, ARRAY_SIZE(mixoutl)),
359  mixoutr, ARRAY_SIZE(mixoutr)),
360 
361 SND_SOC_DAPM_PGA_E("HP PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
363 
364 SND_SOC_DAPM_PGA("SPKPGA", WM9090_POWER_MANAGEMENT_3, 8, 0, NULL, 0),
366  spkout, ARRAY_SIZE(spkout)),
367 
368 SND_SOC_DAPM_OUTPUT("HPR"),
369 SND_SOC_DAPM_OUTPUT("HPL"),
370 SND_SOC_DAPM_OUTPUT("Speaker"),
371 };
372 
373 static const struct snd_soc_dapm_route audio_map[] = {
374  { "IN1A PGA", NULL, "IN1+" },
375  { "IN2A PGA", NULL, "IN2+" },
376 
377  { "SPKMIX", "IN1A Switch", "IN1A PGA" },
378  { "SPKMIX", "IN2A Switch", "IN2A PGA" },
379 
380  { "MIXOUTL", "IN1A Switch", "IN1A PGA" },
381  { "MIXOUTL", "IN2A Switch", "IN2A PGA" },
382 
383  { "MIXOUTR", "IN1A Switch", "IN1A PGA" },
384  { "MIXOUTR", "IN2A Switch", "IN2A PGA" },
385 
386  { "HP PGA", NULL, "OSC" },
387  { "HP PGA", NULL, "MIXOUTL" },
388  { "HP PGA", NULL, "MIXOUTR" },
389 
390  { "HPL", NULL, "HP PGA" },
391  { "HPR", NULL, "HP PGA" },
392 
393  { "SPKPGA", NULL, "OSC" },
394  { "SPKPGA", NULL, "SPKMIX" },
395 
396  { "SPKOUT", "Mixer Switch", "SPKPGA" },
397 
398  { "Speaker", NULL, "SPKOUT" },
399 };
400 
401 static const struct snd_soc_dapm_route audio_map_in1_se[] = {
402  { "IN1B PGA", NULL, "IN1-" },
403 
404  { "SPKMIX", "IN1B Switch", "IN1B PGA" },
405  { "MIXOUTL", "IN1B Switch", "IN1B PGA" },
406  { "MIXOUTR", "IN1B Switch", "IN1B PGA" },
407 };
408 
409 static const struct snd_soc_dapm_route audio_map_in1_diff[] = {
410  { "IN1A PGA", NULL, "IN1-" },
411 };
412 
413 static const struct snd_soc_dapm_route audio_map_in2_se[] = {
414  { "IN2B PGA", NULL, "IN2-" },
415 
416  { "SPKMIX", "IN2B Switch", "IN2B PGA" },
417  { "MIXOUTL", "IN2B Switch", "IN2B PGA" },
418  { "MIXOUTR", "IN2B Switch", "IN2B PGA" },
419 };
420 
421 static const struct snd_soc_dapm_route audio_map_in2_diff[] = {
422  { "IN2A PGA", NULL, "IN2-" },
423 };
424 
425 static int wm9090_add_controls(struct snd_soc_codec *codec)
426 {
427  struct wm9090_priv *wm9090 = snd_soc_codec_get_drvdata(codec);
428  struct snd_soc_dapm_context *dapm = &codec->dapm;
429  int i;
430 
431  snd_soc_dapm_new_controls(dapm, wm9090_dapm_widgets,
432  ARRAY_SIZE(wm9090_dapm_widgets));
433 
434  snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
435 
436  snd_soc_add_codec_controls(codec, wm9090_controls,
437  ARRAY_SIZE(wm9090_controls));
438 
439  if (wm9090->pdata.lin1_diff) {
440  snd_soc_dapm_add_routes(dapm, audio_map_in1_diff,
441  ARRAY_SIZE(audio_map_in1_diff));
442  } else {
443  snd_soc_dapm_add_routes(dapm, audio_map_in1_se,
444  ARRAY_SIZE(audio_map_in1_se));
445  snd_soc_add_codec_controls(codec, wm9090_in1_se_controls,
446  ARRAY_SIZE(wm9090_in1_se_controls));
447  }
448 
449  if (wm9090->pdata.lin2_diff) {
450  snd_soc_dapm_add_routes(dapm, audio_map_in2_diff,
451  ARRAY_SIZE(audio_map_in2_diff));
452  } else {
453  snd_soc_dapm_add_routes(dapm, audio_map_in2_se,
454  ARRAY_SIZE(audio_map_in2_se));
455  snd_soc_add_codec_controls(codec, wm9090_in2_se_controls,
456  ARRAY_SIZE(wm9090_in2_se_controls));
457  }
458 
459  if (wm9090->pdata.agc_ena) {
460  for (i = 0; i < ARRAY_SIZE(wm9090->pdata.agc); i++)
462  wm9090->pdata.agc[i]);
465  } else {
467  WM9090_AGC_ENA, 0);
468  }
469 
470  return 0;
471 
472 }
473 
474 /*
475  * The machine driver should call this from their set_bias_level; if there
476  * isn't one then this can just be set as the set_bias_level function.
477  */
478 static int wm9090_set_bias_level(struct snd_soc_codec *codec,
480 {
481  struct wm9090_priv *wm9090 = snd_soc_codec_get_drvdata(codec);
482 
483  switch (level) {
484  case SND_SOC_BIAS_ON:
485  break;
486 
494  1 << WM9090_VMID_RES_SHIFT);
495  msleep(1); /* Probably an overestimate */
496  break;
497 
499  if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
500  /* Restore the register cache */
501  regcache_sync(wm9090->regmap);
502  }
503 
504  /* We keep VMID off during standby since the combination of
505  * ground referenced outputs and class D speaker mean that
506  * latency is not an issue.
507  */
511  WM9090_VMID_ENA, 0);
512  break;
513 
514  case SND_SOC_BIAS_OFF:
515  break;
516  }
517 
518  codec->dapm.bias_level = level;
519 
520  return 0;
521 }
522 
523 static int wm9090_probe(struct snd_soc_codec *codec)
524 {
525  struct wm9090_priv *wm9090 = dev_get_drvdata(codec->dev);
526  int ret;
527 
528  codec->control_data = wm9090->regmap;
529  ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_REGMAP);
530  if (ret != 0) {
531  dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
532  return ret;
533  }
534 
535  /* Configure some defaults; they will be written out when we
536  * bring the bias up.
537  */
559 
562 
563  wm9090_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
564 
565  wm9090_add_controls(codec);
566 
567  return 0;
568 }
569 
570 #ifdef CONFIG_PM
571 static int wm9090_suspend(struct snd_soc_codec *codec)
572 {
573  wm9090_set_bias_level(codec, SND_SOC_BIAS_OFF);
574 
575  return 0;
576 }
577 
578 static int wm9090_resume(struct snd_soc_codec *codec)
579 {
580  wm9090_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
581 
582  return 0;
583 }
584 #else
585 #define wm9090_suspend NULL
586 #define wm9090_resume NULL
587 #endif
588 
589 static int wm9090_remove(struct snd_soc_codec *codec)
590 {
591  wm9090_set_bias_level(codec, SND_SOC_BIAS_OFF);
592 
593  return 0;
594 }
595 
596 static struct snd_soc_codec_driver soc_codec_dev_wm9090 = {
597  .probe = wm9090_probe,
598  .remove = wm9090_remove,
599  .suspend = wm9090_suspend,
600  .resume = wm9090_resume,
601  .set_bias_level = wm9090_set_bias_level,
602 };
603 
604 static const struct regmap_config wm9090_regmap = {
605  .reg_bits = 8,
606  .val_bits = 16,
607 
608  .max_register = WM9090_MAX_REGISTER,
609  .volatile_reg = wm9090_volatile,
610  .readable_reg = wm9090_readable,
611 
612  .cache_type = REGCACHE_RBTREE,
613  .reg_defaults = wm9090_reg_defaults,
614  .num_reg_defaults = ARRAY_SIZE(wm9090_reg_defaults),
615 };
616 
617 
618 static int wm9090_i2c_probe(struct i2c_client *i2c,
619  const struct i2c_device_id *id)
620 {
621  struct wm9090_priv *wm9090;
622  unsigned int reg;
623  int ret;
624 
625  wm9090 = devm_kzalloc(&i2c->dev, sizeof(*wm9090), GFP_KERNEL);
626  if (wm9090 == NULL) {
627  dev_err(&i2c->dev, "Can not allocate memory\n");
628  return -ENOMEM;
629  }
630 
631  wm9090->regmap = regmap_init_i2c(i2c, &wm9090_regmap);
632  if (IS_ERR(wm9090->regmap)) {
633  ret = PTR_ERR(wm9090->regmap);
634  dev_err(&i2c->dev, "Failed to allocate regmap: %d\n", ret);
635  return ret;
636  }
637 
638  ret = regmap_read(wm9090->regmap, WM9090_SOFTWARE_RESET, &reg);
639  if (ret < 0)
640  goto err;
641  if (reg != 0x9093) {
642  dev_err(&i2c->dev, "Device is not a WM9090, ID=%x\n", reg);
643  ret = -ENODEV;
644  goto err;
645  }
646 
647  ret = regmap_write(wm9090->regmap, WM9090_SOFTWARE_RESET, 0);
648  if (ret < 0)
649  goto err;
650 
651  if (i2c->dev.platform_data)
652  memcpy(&wm9090->pdata, i2c->dev.platform_data,
653  sizeof(wm9090->pdata));
654 
655  i2c_set_clientdata(i2c, wm9090);
656 
657  ret = snd_soc_register_codec(&i2c->dev,
658  &soc_codec_dev_wm9090, NULL, 0);
659  if (ret != 0) {
660  dev_err(&i2c->dev, "Failed to register CODEC: %d\n", ret);
661  goto err;
662  }
663 
664  return 0;
665 
666 err:
667  regmap_exit(wm9090->regmap);
668  return ret;
669 }
670 
671 static int __devexit wm9090_i2c_remove(struct i2c_client *i2c)
672 {
673  struct wm9090_priv *wm9090 = i2c_get_clientdata(i2c);
674 
676  regmap_exit(wm9090->regmap);
677 
678  return 0;
679 }
680 
681 static const struct i2c_device_id wm9090_id[] = {
682  { "wm9090", 0 },
683  { "wm9093", 0 },
684  { }
685 };
686 MODULE_DEVICE_TABLE(i2c, wm9090_id);
687 
688 static struct i2c_driver wm9090_i2c_driver = {
689  .driver = {
690  .name = "wm9090",
691  .owner = THIS_MODULE,
692  },
693  .probe = wm9090_i2c_probe,
694  .remove = __devexit_p(wm9090_i2c_remove),
695  .id_table = wm9090_id,
696 };
697 
698 module_i2c_driver(wm9090_i2c_driver);
699 
700 MODULE_AUTHOR("Mark Brown <[email protected]>");
701 MODULE_DESCRIPTION("WM9090 ASoC driver");
702 MODULE_LICENSE("GPL");