Linux 3.11-rc3
[cris-mirror.git] / drivers / mfd / wm8994-core.c
blob781115e8dca90823bbae297ab4eadc9ff63fa791
1 /*
2 * wm8994-core.c -- Device access for Wolfson WM8994
4 * Copyright 2009 Wolfson Microelectronics PLC.
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
15 #include <linux/kernel.h>
16 #include <linux/module.h>
17 #include <linux/slab.h>
18 #include <linux/i2c.h>
19 #include <linux/err.h>
20 #include <linux/delay.h>
21 #include <linux/mfd/core.h>
22 #include <linux/of.h>
23 #include <linux/of_device.h>
24 #include <linux/of_gpio.h>
25 #include <linux/pm_runtime.h>
26 #include <linux/regmap.h>
27 #include <linux/regulator/consumer.h>
28 #include <linux/regulator/machine.h>
30 #include <linux/mfd/wm8994/core.h>
31 #include <linux/mfd/wm8994/pdata.h>
32 #include <linux/mfd/wm8994/registers.h>
34 #include "wm8994.h"
36 /**
37 * wm8994_reg_read: Read a single WM8994 register.
39 * @wm8994: Device to read from.
40 * @reg: Register to read.
42 int wm8994_reg_read(struct wm8994 *wm8994, unsigned short reg)
44 unsigned int val;
45 int ret;
47 ret = regmap_read(wm8994->regmap, reg, &val);
49 if (ret < 0)
50 return ret;
51 else
52 return val;
54 EXPORT_SYMBOL_GPL(wm8994_reg_read);
56 /**
57 * wm8994_bulk_read: Read multiple WM8994 registers
59 * @wm8994: Device to read from
60 * @reg: First register
61 * @count: Number of registers
62 * @buf: Buffer to fill. The data will be returned big endian.
64 int wm8994_bulk_read(struct wm8994 *wm8994, unsigned short reg,
65 int count, u16 *buf)
67 return regmap_bulk_read(wm8994->regmap, reg, buf, count);
70 /**
71 * wm8994_reg_write: Write a single WM8994 register.
73 * @wm8994: Device to write to.
74 * @reg: Register to write to.
75 * @val: Value to write.
77 int wm8994_reg_write(struct wm8994 *wm8994, unsigned short reg,
78 unsigned short val)
80 return regmap_write(wm8994->regmap, reg, val);
82 EXPORT_SYMBOL_GPL(wm8994_reg_write);
84 /**
85 * wm8994_bulk_write: Write multiple WM8994 registers
87 * @wm8994: Device to write to
88 * @reg: First register
89 * @count: Number of registers
90 * @buf: Buffer to write from. Data must be big-endian formatted.
92 int wm8994_bulk_write(struct wm8994 *wm8994, unsigned short reg,
93 int count, const u16 *buf)
95 return regmap_raw_write(wm8994->regmap, reg, buf, count * sizeof(u16));
97 EXPORT_SYMBOL_GPL(wm8994_bulk_write);
99 /**
100 * wm8994_set_bits: Set the value of a bitfield in a WM8994 register
102 * @wm8994: Device to write to.
103 * @reg: Register to write to.
104 * @mask: Mask of bits to set.
105 * @val: Value to set (unshifted)
107 int wm8994_set_bits(struct wm8994 *wm8994, unsigned short reg,
108 unsigned short mask, unsigned short val)
110 return regmap_update_bits(wm8994->regmap, reg, mask, val);
112 EXPORT_SYMBOL_GPL(wm8994_set_bits);
114 static struct mfd_cell wm8994_regulator_devs[] = {
116 .name = "wm8994-ldo",
117 .id = 1,
118 .pm_runtime_no_callbacks = true,
121 .name = "wm8994-ldo",
122 .id = 2,
123 .pm_runtime_no_callbacks = true,
127 static struct resource wm8994_codec_resources[] = {
129 .start = WM8994_IRQ_TEMP_SHUT,
130 .end = WM8994_IRQ_TEMP_WARN,
131 .flags = IORESOURCE_IRQ,
135 static struct resource wm8994_gpio_resources[] = {
137 .start = WM8994_IRQ_GPIO(1),
138 .end = WM8994_IRQ_GPIO(11),
139 .flags = IORESOURCE_IRQ,
143 static struct mfd_cell wm8994_devs[] = {
145 .name = "wm8994-codec",
146 .num_resources = ARRAY_SIZE(wm8994_codec_resources),
147 .resources = wm8994_codec_resources,
151 .name = "wm8994-gpio",
152 .num_resources = ARRAY_SIZE(wm8994_gpio_resources),
153 .resources = wm8994_gpio_resources,
154 .pm_runtime_no_callbacks = true,
159 * Supplies for the main bulk of CODEC; the LDO supplies are ignored
160 * and should be handled via the standard regulator API supply
161 * management.
163 static const char *wm1811_main_supplies[] = {
164 "DBVDD1",
165 "DBVDD2",
166 "DBVDD3",
167 "DCVDD",
168 "AVDD1",
169 "AVDD2",
170 "CPVDD",
171 "SPKVDD1",
172 "SPKVDD2",
175 static const char *wm8994_main_supplies[] = {
176 "DBVDD",
177 "DCVDD",
178 "AVDD1",
179 "AVDD2",
180 "CPVDD",
181 "SPKVDD1",
182 "SPKVDD2",
185 static const char *wm8958_main_supplies[] = {
186 "DBVDD1",
187 "DBVDD2",
188 "DBVDD3",
189 "DCVDD",
190 "AVDD1",
191 "AVDD2",
192 "CPVDD",
193 "SPKVDD1",
194 "SPKVDD2",
197 #ifdef CONFIG_PM_RUNTIME
198 static int wm8994_suspend(struct device *dev)
200 struct wm8994 *wm8994 = dev_get_drvdata(dev);
201 int ret;
203 /* Don't actually go through with the suspend if the CODEC is
204 * still active (eg, for audio passthrough from CP. */
205 ret = wm8994_reg_read(wm8994, WM8994_POWER_MANAGEMENT_1);
206 if (ret < 0) {
207 dev_err(dev, "Failed to read power status: %d\n", ret);
208 } else if (ret & WM8994_VMID_SEL_MASK) {
209 dev_dbg(dev, "CODEC still active, ignoring suspend\n");
210 return 0;
213 ret = wm8994_reg_read(wm8994, WM8994_POWER_MANAGEMENT_4);
214 if (ret < 0) {
215 dev_err(dev, "Failed to read power status: %d\n", ret);
216 } else if (ret & (WM8994_AIF2ADCL_ENA | WM8994_AIF2ADCR_ENA |
217 WM8994_AIF1ADC2L_ENA | WM8994_AIF1ADC2R_ENA |
218 WM8994_AIF1ADC1L_ENA | WM8994_AIF1ADC1R_ENA)) {
219 dev_dbg(dev, "CODEC still active, ignoring suspend\n");
220 return 0;
223 ret = wm8994_reg_read(wm8994, WM8994_POWER_MANAGEMENT_5);
224 if (ret < 0) {
225 dev_err(dev, "Failed to read power status: %d\n", ret);
226 } else if (ret & (WM8994_AIF2DACL_ENA | WM8994_AIF2DACR_ENA |
227 WM8994_AIF1DAC2L_ENA | WM8994_AIF1DAC2R_ENA |
228 WM8994_AIF1DAC1L_ENA | WM8994_AIF1DAC1R_ENA)) {
229 dev_dbg(dev, "CODEC still active, ignoring suspend\n");
230 return 0;
233 switch (wm8994->type) {
234 case WM8958:
235 case WM1811:
236 ret = wm8994_reg_read(wm8994, WM8958_MIC_DETECT_1);
237 if (ret < 0) {
238 dev_err(dev, "Failed to read power status: %d\n", ret);
239 } else if (ret & WM8958_MICD_ENA) {
240 dev_dbg(dev, "CODEC still active, ignoring suspend\n");
241 return 0;
243 break;
244 default:
245 break;
248 switch (wm8994->type) {
249 case WM1811:
250 ret = wm8994_reg_read(wm8994, WM8994_ANTIPOP_2);
251 if (ret < 0) {
252 dev_err(dev, "Failed to read jackdet: %d\n", ret);
253 } else if (ret & WM1811_JACKDET_MODE_MASK) {
254 dev_dbg(dev, "CODEC still active, ignoring suspend\n");
255 return 0;
257 break;
258 default:
259 break;
262 /* Disable LDO pulldowns while the device is suspended if we
263 * don't know that something will be driving them. */
264 if (!wm8994->ldo_ena_always_driven)
265 wm8994_set_bits(wm8994, WM8994_PULL_CONTROL_2,
266 WM8994_LDO1ENA_PD | WM8994_LDO2ENA_PD,
267 WM8994_LDO1ENA_PD | WM8994_LDO2ENA_PD);
269 /* Explicitly put the device into reset in case regulators
270 * don't get disabled in order to ensure consistent restart.
272 wm8994_reg_write(wm8994, WM8994_SOFTWARE_RESET,
273 wm8994_reg_read(wm8994, WM8994_SOFTWARE_RESET));
275 regcache_mark_dirty(wm8994->regmap);
277 /* Restore GPIO registers to prevent problems with mismatched
278 * pin configurations.
280 ret = regcache_sync_region(wm8994->regmap, WM8994_GPIO_1,
281 WM8994_GPIO_11);
282 if (ret != 0)
283 dev_err(dev, "Failed to restore GPIO registers: %d\n", ret);
285 /* In case one of the GPIOs is used as a wake input. */
286 ret = regcache_sync_region(wm8994->regmap,
287 WM8994_INTERRUPT_STATUS_1_MASK,
288 WM8994_INTERRUPT_STATUS_1_MASK);
289 if (ret != 0)
290 dev_err(dev, "Failed to restore interrupt mask: %d\n", ret);
292 regcache_cache_only(wm8994->regmap, true);
293 wm8994->suspended = true;
295 ret = regulator_bulk_disable(wm8994->num_supplies,
296 wm8994->supplies);
297 if (ret != 0) {
298 dev_err(dev, "Failed to disable supplies: %d\n", ret);
299 return ret;
302 return 0;
305 static int wm8994_resume(struct device *dev)
307 struct wm8994 *wm8994 = dev_get_drvdata(dev);
308 int ret;
310 /* We may have lied to the PM core about suspending */
311 if (!wm8994->suspended)
312 return 0;
314 ret = regulator_bulk_enable(wm8994->num_supplies,
315 wm8994->supplies);
316 if (ret != 0) {
317 dev_err(dev, "Failed to enable supplies: %d\n", ret);
318 return ret;
321 regcache_cache_only(wm8994->regmap, false);
322 ret = regcache_sync(wm8994->regmap);
323 if (ret != 0) {
324 dev_err(dev, "Failed to restore register map: %d\n", ret);
325 goto err_enable;
328 /* Disable LDO pulldowns while the device is active */
329 wm8994_set_bits(wm8994, WM8994_PULL_CONTROL_2,
330 WM8994_LDO1ENA_PD | WM8994_LDO2ENA_PD,
333 wm8994->suspended = false;
335 return 0;
337 err_enable:
338 regulator_bulk_disable(wm8994->num_supplies, wm8994->supplies);
340 return ret;
342 #endif
344 #ifdef CONFIG_REGULATOR
345 static int wm8994_ldo_in_use(struct wm8994_pdata *pdata, int ldo)
347 struct wm8994_ldo_pdata *ldo_pdata;
349 if (!pdata)
350 return 0;
352 ldo_pdata = &pdata->ldo[ldo];
354 if (!ldo_pdata->init_data)
355 return 0;
357 return ldo_pdata->init_data->num_consumer_supplies != 0;
359 #else
360 static int wm8994_ldo_in_use(struct wm8994_pdata *pdata, int ldo)
362 return 0;
364 #endif
366 static const struct reg_default wm8994_revc_patch[] = {
367 { 0x102, 0x3 },
368 { 0x56, 0x3 },
369 { 0x817, 0x0 },
370 { 0x102, 0x0 },
373 static const struct reg_default wm8958_reva_patch[] = {
374 { 0x102, 0x3 },
375 { 0xcb, 0x81 },
376 { 0x817, 0x0 },
377 { 0x102, 0x0 },
380 static const struct reg_default wm1811_reva_patch[] = {
381 { 0x102, 0x3 },
382 { 0x56, 0xc07 },
383 { 0x5d, 0x7e },
384 { 0x5e, 0x0 },
385 { 0x102, 0x0 },
388 #ifdef CONFIG_OF
389 static int wm8994_set_pdata_from_of(struct wm8994 *wm8994)
391 struct device_node *np = wm8994->dev->of_node;
392 struct wm8994_pdata *pdata = &wm8994->pdata;
393 int i;
395 if (!np)
396 return 0;
398 if (of_property_read_u32_array(np, "wlf,gpio-cfg", pdata->gpio_defaults,
399 ARRAY_SIZE(pdata->gpio_defaults)) >= 0) {
400 for (i = 0; i < ARRAY_SIZE(pdata->gpio_defaults); i++) {
401 if (wm8994->pdata.gpio_defaults[i] == 0)
402 pdata->gpio_defaults[i]
403 = WM8994_CONFIGURE_GPIO;
407 of_property_read_u32_array(np, "wlf,micbias-cfg", pdata->micbias,
408 ARRAY_SIZE(pdata->micbias));
410 pdata->lineout1_diff = true;
411 pdata->lineout2_diff = true;
412 if (of_find_property(np, "wlf,lineout1-se", NULL))
413 pdata->lineout1_diff = false;
414 if (of_find_property(np, "wlf,lineout2-se", NULL))
415 pdata->lineout2_diff = false;
417 if (of_find_property(np, "wlf,lineout1-feedback", NULL))
418 pdata->lineout1fb = true;
419 if (of_find_property(np, "wlf,lineout2-feedback", NULL))
420 pdata->lineout2fb = true;
422 if (of_find_property(np, "wlf,ldoena-always-driven", NULL))
423 pdata->lineout2fb = true;
425 pdata->ldo[0].enable = of_get_named_gpio(np, "wlf,ldo1ena", 0);
426 if (pdata->ldo[0].enable < 0)
427 pdata->ldo[0].enable = 0;
429 pdata->ldo[1].enable = of_get_named_gpio(np, "wlf,ldo2ena", 0);
430 if (pdata->ldo[1].enable < 0)
431 pdata->ldo[1].enable = 0;
433 return 0;
435 #else
436 static int wm8994_set_pdata_from_of(struct wm8994 *wm8994)
438 return 0;
440 #endif
443 * Instantiate the generic non-control parts of the device.
445 static int wm8994_device_init(struct wm8994 *wm8994, int irq)
447 struct wm8994_pdata *pdata;
448 struct regmap_config *regmap_config;
449 const struct reg_default *regmap_patch = NULL;
450 const char *devname;
451 int ret, i, patch_regs = 0;
452 int pulls = 0;
454 if (dev_get_platdata(wm8994->dev)) {
455 pdata = dev_get_platdata(wm8994->dev);
456 wm8994->pdata = *pdata;
458 pdata = &wm8994->pdata;
460 ret = wm8994_set_pdata_from_of(wm8994);
461 if (ret != 0)
462 return ret;
464 dev_set_drvdata(wm8994->dev, wm8994);
466 /* Add the on-chip regulators first for bootstrapping */
467 ret = mfd_add_devices(wm8994->dev, -1,
468 wm8994_regulator_devs,
469 ARRAY_SIZE(wm8994_regulator_devs),
470 NULL, 0, NULL);
471 if (ret != 0) {
472 dev_err(wm8994->dev, "Failed to add children: %d\n", ret);
473 goto err;
476 switch (wm8994->type) {
477 case WM1811:
478 wm8994->num_supplies = ARRAY_SIZE(wm1811_main_supplies);
479 break;
480 case WM8994:
481 wm8994->num_supplies = ARRAY_SIZE(wm8994_main_supplies);
482 break;
483 case WM8958:
484 wm8994->num_supplies = ARRAY_SIZE(wm8958_main_supplies);
485 break;
486 default:
487 BUG();
488 goto err;
491 wm8994->supplies = devm_kzalloc(wm8994->dev,
492 sizeof(struct regulator_bulk_data) *
493 wm8994->num_supplies, GFP_KERNEL);
494 if (!wm8994->supplies) {
495 ret = -ENOMEM;
496 goto err;
499 switch (wm8994->type) {
500 case WM1811:
501 for (i = 0; i < ARRAY_SIZE(wm1811_main_supplies); i++)
502 wm8994->supplies[i].supply = wm1811_main_supplies[i];
503 break;
504 case WM8994:
505 for (i = 0; i < ARRAY_SIZE(wm8994_main_supplies); i++)
506 wm8994->supplies[i].supply = wm8994_main_supplies[i];
507 break;
508 case WM8958:
509 for (i = 0; i < ARRAY_SIZE(wm8958_main_supplies); i++)
510 wm8994->supplies[i].supply = wm8958_main_supplies[i];
511 break;
512 default:
513 BUG();
514 goto err;
517 ret = devm_regulator_bulk_get(wm8994->dev, wm8994->num_supplies,
518 wm8994->supplies);
519 if (ret != 0) {
520 dev_err(wm8994->dev, "Failed to get supplies: %d\n", ret);
521 goto err;
524 ret = regulator_bulk_enable(wm8994->num_supplies,
525 wm8994->supplies);
526 if (ret != 0) {
527 dev_err(wm8994->dev, "Failed to enable supplies: %d\n", ret);
528 goto err;
531 ret = wm8994_reg_read(wm8994, WM8994_SOFTWARE_RESET);
532 if (ret < 0) {
533 dev_err(wm8994->dev, "Failed to read ID register\n");
534 goto err_enable;
536 switch (ret) {
537 case 0x1811:
538 devname = "WM1811";
539 if (wm8994->type != WM1811)
540 dev_warn(wm8994->dev, "Device registered as type %d\n",
541 wm8994->type);
542 wm8994->type = WM1811;
543 break;
544 case 0x8994:
545 devname = "WM8994";
546 if (wm8994->type != WM8994)
547 dev_warn(wm8994->dev, "Device registered as type %d\n",
548 wm8994->type);
549 wm8994->type = WM8994;
550 break;
551 case 0x8958:
552 devname = "WM8958";
553 if (wm8994->type != WM8958)
554 dev_warn(wm8994->dev, "Device registered as type %d\n",
555 wm8994->type);
556 wm8994->type = WM8958;
557 break;
558 default:
559 dev_err(wm8994->dev, "Device is not a WM8994, ID is %x\n",
560 ret);
561 ret = -EINVAL;
562 goto err_enable;
565 ret = wm8994_reg_read(wm8994, WM8994_CHIP_REVISION);
566 if (ret < 0) {
567 dev_err(wm8994->dev, "Failed to read revision register: %d\n",
568 ret);
569 goto err_enable;
571 wm8994->revision = ret & WM8994_CHIP_REV_MASK;
572 wm8994->cust_id = (ret & WM8994_CUST_ID_MASK) >> WM8994_CUST_ID_SHIFT;
574 switch (wm8994->type) {
575 case WM8994:
576 switch (wm8994->revision) {
577 case 0:
578 case 1:
579 dev_warn(wm8994->dev,
580 "revision %c not fully supported\n",
581 'A' + wm8994->revision);
582 break;
583 case 2:
584 case 3:
585 default:
586 regmap_patch = wm8994_revc_patch;
587 patch_regs = ARRAY_SIZE(wm8994_revc_patch);
588 break;
590 break;
592 case WM8958:
593 switch (wm8994->revision) {
594 case 0:
595 regmap_patch = wm8958_reva_patch;
596 patch_regs = ARRAY_SIZE(wm8958_reva_patch);
597 break;
598 default:
599 break;
601 break;
603 case WM1811:
604 /* Revision C did not change the relevant layer */
605 if (wm8994->revision > 1)
606 wm8994->revision++;
608 regmap_patch = wm1811_reva_patch;
609 patch_regs = ARRAY_SIZE(wm1811_reva_patch);
610 break;
612 default:
613 break;
616 dev_info(wm8994->dev, "%s revision %c CUST_ID %02x\n", devname,
617 'A' + wm8994->revision, wm8994->cust_id);
619 switch (wm8994->type) {
620 case WM1811:
621 regmap_config = &wm1811_regmap_config;
622 break;
623 case WM8994:
624 regmap_config = &wm8994_regmap_config;
625 break;
626 case WM8958:
627 regmap_config = &wm8958_regmap_config;
628 break;
629 default:
630 dev_err(wm8994->dev, "Unknown device type %d\n", wm8994->type);
631 return -EINVAL;
634 ret = regmap_reinit_cache(wm8994->regmap, regmap_config);
635 if (ret != 0) {
636 dev_err(wm8994->dev, "Failed to reinit register cache: %d\n",
637 ret);
638 return ret;
641 /* Explicitly put the device into reset in case regulators
642 * don't get disabled in order to ensure we know the device
643 * state.
645 ret = wm8994_reg_write(wm8994, WM8994_SOFTWARE_RESET,
646 wm8994_reg_read(wm8994, WM8994_SOFTWARE_RESET));
647 if (ret != 0) {
648 dev_err(wm8994->dev, "Failed to reset device: %d\n", ret);
649 return ret;
652 if (regmap_patch) {
653 ret = regmap_register_patch(wm8994->regmap, regmap_patch,
654 patch_regs);
655 if (ret != 0) {
656 dev_err(wm8994->dev, "Failed to register patch: %d\n",
657 ret);
658 goto err;
662 wm8994->irq_base = pdata->irq_base;
663 wm8994->gpio_base = pdata->gpio_base;
665 /* GPIO configuration is only applied if it's non-zero */
666 for (i = 0; i < ARRAY_SIZE(pdata->gpio_defaults); i++) {
667 if (pdata->gpio_defaults[i]) {
668 wm8994_set_bits(wm8994, WM8994_GPIO_1 + i,
669 0xffff, pdata->gpio_defaults[i]);
673 wm8994->ldo_ena_always_driven = pdata->ldo_ena_always_driven;
675 if (pdata->spkmode_pu)
676 pulls |= WM8994_SPKMODE_PU;
678 /* Disable unneeded pulls */
679 wm8994_set_bits(wm8994, WM8994_PULL_CONTROL_2,
680 WM8994_LDO1ENA_PD | WM8994_LDO2ENA_PD |
681 WM8994_SPKMODE_PU | WM8994_CSNADDR_PD,
682 pulls);
684 /* In some system designs where the regulators are not in use,
685 * we can achieve a small reduction in leakage currents by
686 * floating LDO outputs. This bit makes no difference if the
687 * LDOs are enabled, it only affects cases where the LDOs were
688 * in operation and are then disabled.
690 for (i = 0; i < WM8994_NUM_LDO_REGS; i++) {
691 if (wm8994_ldo_in_use(pdata, i))
692 wm8994_set_bits(wm8994, WM8994_LDO_1 + i,
693 WM8994_LDO1_DISCH, WM8994_LDO1_DISCH);
694 else
695 wm8994_set_bits(wm8994, WM8994_LDO_1 + i,
696 WM8994_LDO1_DISCH, 0);
699 wm8994_irq_init(wm8994);
701 ret = mfd_add_devices(wm8994->dev, -1,
702 wm8994_devs, ARRAY_SIZE(wm8994_devs),
703 NULL, 0, NULL);
704 if (ret != 0) {
705 dev_err(wm8994->dev, "Failed to add children: %d\n", ret);
706 goto err_irq;
709 pm_runtime_enable(wm8994->dev);
710 pm_runtime_idle(wm8994->dev);
712 return 0;
714 err_irq:
715 wm8994_irq_exit(wm8994);
716 err_enable:
717 regulator_bulk_disable(wm8994->num_supplies,
718 wm8994->supplies);
719 err:
720 mfd_remove_devices(wm8994->dev);
721 return ret;
724 static void wm8994_device_exit(struct wm8994 *wm8994)
726 pm_runtime_disable(wm8994->dev);
727 mfd_remove_devices(wm8994->dev);
728 wm8994_irq_exit(wm8994);
729 regulator_bulk_disable(wm8994->num_supplies,
730 wm8994->supplies);
733 static const struct of_device_id wm8994_of_match[] = {
734 { .compatible = "wlf,wm1811", .data = (void *)WM1811 },
735 { .compatible = "wlf,wm8994", .data = (void *)WM8994 },
736 { .compatible = "wlf,wm8958", .data = (void *)WM8958 },
739 MODULE_DEVICE_TABLE(of, wm8994_of_match);
741 static int wm8994_i2c_probe(struct i2c_client *i2c,
742 const struct i2c_device_id *id)
744 const struct of_device_id *of_id;
745 struct wm8994 *wm8994;
746 int ret;
748 wm8994 = devm_kzalloc(&i2c->dev, sizeof(struct wm8994), GFP_KERNEL);
749 if (wm8994 == NULL)
750 return -ENOMEM;
752 i2c_set_clientdata(i2c, wm8994);
753 wm8994->dev = &i2c->dev;
754 wm8994->irq = i2c->irq;
756 if (i2c->dev.of_node) {
757 of_id = of_match_device(wm8994_of_match, &i2c->dev);
758 if (of_id)
759 wm8994->type = (int)of_id->data;
760 } else {
761 wm8994->type = id->driver_data;
764 wm8994->regmap = devm_regmap_init_i2c(i2c, &wm8994_base_regmap_config);
765 if (IS_ERR(wm8994->regmap)) {
766 ret = PTR_ERR(wm8994->regmap);
767 dev_err(wm8994->dev, "Failed to allocate register map: %d\n",
768 ret);
769 return ret;
772 return wm8994_device_init(wm8994, i2c->irq);
775 static int wm8994_i2c_remove(struct i2c_client *i2c)
777 struct wm8994 *wm8994 = i2c_get_clientdata(i2c);
779 wm8994_device_exit(wm8994);
781 return 0;
784 static const struct i2c_device_id wm8994_i2c_id[] = {
785 { "wm1811", WM1811 },
786 { "wm1811a", WM1811 },
787 { "wm8994", WM8994 },
788 { "wm8958", WM8958 },
791 MODULE_DEVICE_TABLE(i2c, wm8994_i2c_id);
793 static const struct dev_pm_ops wm8994_pm_ops = {
794 SET_RUNTIME_PM_OPS(wm8994_suspend, wm8994_resume, NULL)
797 static struct i2c_driver wm8994_i2c_driver = {
798 .driver = {
799 .name = "wm8994",
800 .owner = THIS_MODULE,
801 .pm = &wm8994_pm_ops,
802 .of_match_table = of_match_ptr(wm8994_of_match),
804 .probe = wm8994_i2c_probe,
805 .remove = wm8994_i2c_remove,
806 .id_table = wm8994_i2c_id,
809 module_i2c_driver(wm8994_i2c_driver);
811 MODULE_DESCRIPTION("Core support for the WM8994 audio CODEC");
812 MODULE_LICENSE("GPL");
813 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");