wm8994-core.c revision 4dd0b2ba1d8c96d18c4a5624b167e267671d047f
1/* 2 * wm8994-core.c -- Device access for Wolfson WM8994 3 * 4 * Copyright 2009 Wolfson Microelectronics PLC. 5 * 6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> 7 * 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. 12 * 13 */ 14 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> 29 30#include <linux/mfd/wm8994/core.h> 31#include <linux/mfd/wm8994/pdata.h> 32#include <linux/mfd/wm8994/registers.h> 33 34#include "wm8994.h" 35 36/** 37 * wm8994_reg_read: Read a single WM8994 register. 38 * 39 * @wm8994: Device to read from. 40 * @reg: Register to read. 41 */ 42int wm8994_reg_read(struct wm8994 *wm8994, unsigned short reg) 43{ 44 unsigned int val; 45 int ret; 46 47 ret = regmap_read(wm8994->regmap, reg, &val); 48 49 if (ret < 0) 50 return ret; 51 else 52 return val; 53} 54EXPORT_SYMBOL_GPL(wm8994_reg_read); 55 56/** 57 * wm8994_bulk_read: Read multiple WM8994 registers 58 * 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. 63 */ 64int wm8994_bulk_read(struct wm8994 *wm8994, unsigned short reg, 65 int count, u16 *buf) 66{ 67 return regmap_bulk_read(wm8994->regmap, reg, buf, count); 68} 69 70/** 71 * wm8994_reg_write: Write a single WM8994 register. 72 * 73 * @wm8994: Device to write to. 74 * @reg: Register to write to. 75 * @val: Value to write. 76 */ 77int wm8994_reg_write(struct wm8994 *wm8994, unsigned short reg, 78 unsigned short val) 79{ 80 return regmap_write(wm8994->regmap, reg, val); 81} 82EXPORT_SYMBOL_GPL(wm8994_reg_write); 83 84/** 85 * wm8994_bulk_write: Write multiple WM8994 registers 86 * 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. 91 */ 92int wm8994_bulk_write(struct wm8994 *wm8994, unsigned short reg, 93 int count, const u16 *buf) 94{ 95 return regmap_raw_write(wm8994->regmap, reg, buf, count * sizeof(u16)); 96} 97EXPORT_SYMBOL_GPL(wm8994_bulk_write); 98 99/** 100 * wm8994_set_bits: Set the value of a bitfield in a WM8994 register 101 * 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) 106 */ 107int wm8994_set_bits(struct wm8994 *wm8994, unsigned short reg, 108 unsigned short mask, unsigned short val) 109{ 110 return regmap_update_bits(wm8994->regmap, reg, mask, val); 111} 112EXPORT_SYMBOL_GPL(wm8994_set_bits); 113 114static struct mfd_cell wm8994_regulator_devs[] = { 115 { 116 .name = "wm8994-ldo", 117 .id = 1, 118 .pm_runtime_no_callbacks = true, 119 }, 120 { 121 .name = "wm8994-ldo", 122 .id = 2, 123 .pm_runtime_no_callbacks = true, 124 }, 125}; 126 127static struct resource wm8994_codec_resources[] = { 128 { 129 .start = WM8994_IRQ_TEMP_SHUT, 130 .end = WM8994_IRQ_TEMP_WARN, 131 .flags = IORESOURCE_IRQ, 132 }, 133}; 134 135static struct resource wm8994_gpio_resources[] = { 136 { 137 .start = WM8994_IRQ_GPIO(1), 138 .end = WM8994_IRQ_GPIO(11), 139 .flags = IORESOURCE_IRQ, 140 }, 141}; 142 143static struct mfd_cell wm8994_devs[] = { 144 { 145 .name = "wm8994-codec", 146 .num_resources = ARRAY_SIZE(wm8994_codec_resources), 147 .resources = wm8994_codec_resources, 148 }, 149 150 { 151 .name = "wm8994-gpio", 152 .num_resources = ARRAY_SIZE(wm8994_gpio_resources), 153 .resources = wm8994_gpio_resources, 154 .pm_runtime_no_callbacks = true, 155 }, 156}; 157 158/* 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. 162 */ 163static const char *wm1811_main_supplies[] = { 164 "DBVDD1", 165 "DBVDD2", 166 "DBVDD3", 167 "DCVDD", 168 "AVDD1", 169 "AVDD2", 170 "CPVDD", 171 "SPKVDD1", 172 "SPKVDD2", 173}; 174 175static const char *wm8994_main_supplies[] = { 176 "DBVDD", 177 "DCVDD", 178 "AVDD1", 179 "AVDD2", 180 "CPVDD", 181 "SPKVDD1", 182 "SPKVDD2", 183}; 184 185static const char *wm8958_main_supplies[] = { 186 "DBVDD1", 187 "DBVDD2", 188 "DBVDD3", 189 "DCVDD", 190 "AVDD1", 191 "AVDD2", 192 "CPVDD", 193 "SPKVDD1", 194 "SPKVDD2", 195}; 196 197#ifdef CONFIG_PM_RUNTIME 198static int wm8994_suspend(struct device *dev) 199{ 200 struct wm8994 *wm8994 = dev_get_drvdata(dev); 201 int ret; 202 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; 211 } 212 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; 221 } 222 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; 231 } 232 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; 242 } 243 break; 244 default: 245 break; 246 } 247 248 /* Disable LDO pulldowns while the device is suspended if we 249 * don't know that something will be driving them. */ 250 if (!wm8994->ldo_ena_always_driven) 251 wm8994_set_bits(wm8994, WM8994_PULL_CONTROL_2, 252 WM8994_LDO1ENA_PD | WM8994_LDO2ENA_PD, 253 WM8994_LDO1ENA_PD | WM8994_LDO2ENA_PD); 254 255 /* Explicitly put the device into reset in case regulators 256 * don't get disabled in order to ensure consistent restart. 257 */ 258 wm8994_reg_write(wm8994, WM8994_SOFTWARE_RESET, 259 wm8994_reg_read(wm8994, WM8994_SOFTWARE_RESET)); 260 261 regcache_mark_dirty(wm8994->regmap); 262 263 /* Restore GPIO registers to prevent problems with mismatched 264 * pin configurations. 265 */ 266 ret = regcache_sync_region(wm8994->regmap, WM8994_GPIO_1, 267 WM8994_GPIO_11); 268 if (ret != 0) 269 dev_err(dev, "Failed to restore GPIO registers: %d\n", ret); 270 271 /* In case one of the GPIOs is used as a wake input. */ 272 ret = regcache_sync_region(wm8994->regmap, 273 WM8994_INTERRUPT_STATUS_1_MASK, 274 WM8994_INTERRUPT_STATUS_1_MASK); 275 if (ret != 0) 276 dev_err(dev, "Failed to restore interrupt mask: %d\n", ret); 277 278 regcache_cache_only(wm8994->regmap, true); 279 wm8994->suspended = true; 280 281 ret = regulator_bulk_disable(wm8994->num_supplies, 282 wm8994->supplies); 283 if (ret != 0) { 284 dev_err(dev, "Failed to disable supplies: %d\n", ret); 285 return ret; 286 } 287 288 return 0; 289} 290 291static int wm8994_resume(struct device *dev) 292{ 293 struct wm8994 *wm8994 = dev_get_drvdata(dev); 294 int ret; 295 296 /* We may have lied to the PM core about suspending */ 297 if (!wm8994->suspended) 298 return 0; 299 300 ret = regulator_bulk_enable(wm8994->num_supplies, 301 wm8994->supplies); 302 if (ret != 0) { 303 dev_err(dev, "Failed to enable supplies: %d\n", ret); 304 return ret; 305 } 306 307 regcache_cache_only(wm8994->regmap, false); 308 ret = regcache_sync(wm8994->regmap); 309 if (ret != 0) { 310 dev_err(dev, "Failed to restore register map: %d\n", ret); 311 goto err_enable; 312 } 313 314 /* Disable LDO pulldowns while the device is active */ 315 wm8994_set_bits(wm8994, WM8994_PULL_CONTROL_2, 316 WM8994_LDO1ENA_PD | WM8994_LDO2ENA_PD, 317 0); 318 319 wm8994->suspended = false; 320 321 return 0; 322 323err_enable: 324 regulator_bulk_disable(wm8994->num_supplies, wm8994->supplies); 325 326 return ret; 327} 328#endif 329 330#ifdef CONFIG_REGULATOR 331static int wm8994_ldo_in_use(struct wm8994_pdata *pdata, int ldo) 332{ 333 struct wm8994_ldo_pdata *ldo_pdata; 334 335 if (!pdata) 336 return 0; 337 338 ldo_pdata = &pdata->ldo[ldo]; 339 340 if (!ldo_pdata->init_data) 341 return 0; 342 343 return ldo_pdata->init_data->num_consumer_supplies != 0; 344} 345#else 346static int wm8994_ldo_in_use(struct wm8994_pdata *pdata, int ldo) 347{ 348 return 0; 349} 350#endif 351 352static const struct reg_default wm8994_revc_patch[] = { 353 { 0x102, 0x3 }, 354 { 0x56, 0x3 }, 355 { 0x817, 0x0 }, 356 { 0x102, 0x0 }, 357}; 358 359static const struct reg_default wm8958_reva_patch[] = { 360 { 0x102, 0x3 }, 361 { 0xcb, 0x81 }, 362 { 0x817, 0x0 }, 363 { 0x102, 0x0 }, 364}; 365 366static const struct reg_default wm1811_reva_patch[] = { 367 { 0x102, 0x3 }, 368 { 0x56, 0xc07 }, 369 { 0x5d, 0x7e }, 370 { 0x5e, 0x0 }, 371 { 0x102, 0x0 }, 372}; 373 374#ifdef CONFIG_OF 375static int wm8994_set_pdata_from_of(struct wm8994 *wm8994) 376{ 377 struct device_node *np = wm8994->dev->of_node; 378 struct wm8994_pdata *pdata = &wm8994->pdata; 379 int i; 380 381 if (!np) 382 return 0; 383 384 if (of_property_read_u32_array(np, "wlf,gpio-cfg", pdata->gpio_defaults, 385 ARRAY_SIZE(pdata->gpio_defaults)) >= 0) { 386 for (i = 0; i < ARRAY_SIZE(pdata->gpio_defaults); i++) { 387 if (wm8994->pdata.gpio_defaults[i] == 0) 388 pdata->gpio_defaults[i] 389 = WM8994_CONFIGURE_GPIO; 390 } 391 } 392 393 of_property_read_u32_array(np, "wlf,micbias-cfg", pdata->micbias, 394 ARRAY_SIZE(pdata->micbias)); 395 396 pdata->lineout1_diff = true; 397 pdata->lineout2_diff = true; 398 if (of_find_property(np, "wlf,lineout1-se", NULL)) 399 pdata->lineout1_diff = false; 400 if (of_find_property(np, "wlf,lineout2-se", NULL)) 401 pdata->lineout2_diff = false; 402 403 if (of_find_property(np, "wlf,lineout1-feedback", NULL)) 404 pdata->lineout1fb = true; 405 if (of_find_property(np, "wlf,lineout2-feedback", NULL)) 406 pdata->lineout2fb = true; 407 408 if (of_find_property(np, "wlf,ldoena-always-driven", NULL)) 409 pdata->lineout2fb = true; 410 411 pdata->ldo[0].enable = of_get_named_gpio(np, "wlf,ldo1ena", 0); 412 if (pdata->ldo[0].enable < 0) 413 pdata->ldo[0].enable = 0; 414 415 pdata->ldo[1].enable = of_get_named_gpio(np, "wlf,ldo2ena", 0); 416 if (pdata->ldo[1].enable < 0) 417 pdata->ldo[1].enable = 0; 418 419 return 0; 420} 421#else 422static int wm8994_set_pdata_from_of(struct wm8994 *wm8994) 423{ 424 return 0; 425} 426#endif 427 428/* 429 * Instantiate the generic non-control parts of the device. 430 */ 431static int wm8994_device_init(struct wm8994 *wm8994, int irq) 432{ 433 struct wm8994_pdata *pdata; 434 struct regmap_config *regmap_config; 435 const struct reg_default *regmap_patch = NULL; 436 const char *devname; 437 int ret, i, patch_regs = 0; 438 int pulls = 0; 439 440 if (dev_get_platdata(wm8994->dev)) { 441 pdata = dev_get_platdata(wm8994->dev); 442 wm8994->pdata = *pdata; 443 } 444 pdata = &wm8994->pdata; 445 446 ret = wm8994_set_pdata_from_of(wm8994); 447 if (ret != 0) 448 return ret; 449 450 dev_set_drvdata(wm8994->dev, wm8994); 451 452 /* Add the on-chip regulators first for bootstrapping */ 453 ret = mfd_add_devices(wm8994->dev, -1, 454 wm8994_regulator_devs, 455 ARRAY_SIZE(wm8994_regulator_devs), 456 NULL, 0, NULL); 457 if (ret != 0) { 458 dev_err(wm8994->dev, "Failed to add children: %d\n", ret); 459 goto err; 460 } 461 462 switch (wm8994->type) { 463 case WM1811: 464 wm8994->num_supplies = ARRAY_SIZE(wm1811_main_supplies); 465 break; 466 case WM8994: 467 wm8994->num_supplies = ARRAY_SIZE(wm8994_main_supplies); 468 break; 469 case WM8958: 470 wm8994->num_supplies = ARRAY_SIZE(wm8958_main_supplies); 471 break; 472 default: 473 BUG(); 474 goto err; 475 } 476 477 wm8994->supplies = devm_kzalloc(wm8994->dev, 478 sizeof(struct regulator_bulk_data) * 479 wm8994->num_supplies, GFP_KERNEL); 480 if (!wm8994->supplies) { 481 ret = -ENOMEM; 482 goto err; 483 } 484 485 switch (wm8994->type) { 486 case WM1811: 487 for (i = 0; i < ARRAY_SIZE(wm1811_main_supplies); i++) 488 wm8994->supplies[i].supply = wm1811_main_supplies[i]; 489 break; 490 case WM8994: 491 for (i = 0; i < ARRAY_SIZE(wm8994_main_supplies); i++) 492 wm8994->supplies[i].supply = wm8994_main_supplies[i]; 493 break; 494 case WM8958: 495 for (i = 0; i < ARRAY_SIZE(wm8958_main_supplies); i++) 496 wm8994->supplies[i].supply = wm8958_main_supplies[i]; 497 break; 498 default: 499 BUG(); 500 goto err; 501 } 502 503 ret = devm_regulator_bulk_get(wm8994->dev, wm8994->num_supplies, 504 wm8994->supplies); 505 if (ret != 0) { 506 dev_err(wm8994->dev, "Failed to get supplies: %d\n", ret); 507 goto err; 508 } 509 510 ret = regulator_bulk_enable(wm8994->num_supplies, 511 wm8994->supplies); 512 if (ret != 0) { 513 dev_err(wm8994->dev, "Failed to enable supplies: %d\n", ret); 514 goto err; 515 } 516 517 ret = wm8994_reg_read(wm8994, WM8994_SOFTWARE_RESET); 518 if (ret < 0) { 519 dev_err(wm8994->dev, "Failed to read ID register\n"); 520 goto err_enable; 521 } 522 switch (ret) { 523 case 0x1811: 524 devname = "WM1811"; 525 if (wm8994->type != WM1811) 526 dev_warn(wm8994->dev, "Device registered as type %d\n", 527 wm8994->type); 528 wm8994->type = WM1811; 529 break; 530 case 0x8994: 531 devname = "WM8994"; 532 if (wm8994->type != WM8994) 533 dev_warn(wm8994->dev, "Device registered as type %d\n", 534 wm8994->type); 535 wm8994->type = WM8994; 536 break; 537 case 0x8958: 538 devname = "WM8958"; 539 if (wm8994->type != WM8958) 540 dev_warn(wm8994->dev, "Device registered as type %d\n", 541 wm8994->type); 542 wm8994->type = WM8958; 543 break; 544 default: 545 dev_err(wm8994->dev, "Device is not a WM8994, ID is %x\n", 546 ret); 547 ret = -EINVAL; 548 goto err_enable; 549 } 550 551 ret = wm8994_reg_read(wm8994, WM8994_CHIP_REVISION); 552 if (ret < 0) { 553 dev_err(wm8994->dev, "Failed to read revision register: %d\n", 554 ret); 555 goto err_enable; 556 } 557 wm8994->revision = ret & WM8994_CHIP_REV_MASK; 558 wm8994->cust_id = (ret & WM8994_CUST_ID_MASK) >> WM8994_CUST_ID_SHIFT; 559 560 switch (wm8994->type) { 561 case WM8994: 562 switch (wm8994->revision) { 563 case 0: 564 case 1: 565 dev_warn(wm8994->dev, 566 "revision %c not fully supported\n", 567 'A' + wm8994->revision); 568 break; 569 case 2: 570 case 3: 571 default: 572 regmap_patch = wm8994_revc_patch; 573 patch_regs = ARRAY_SIZE(wm8994_revc_patch); 574 break; 575 } 576 break; 577 578 case WM8958: 579 switch (wm8994->revision) { 580 case 0: 581 regmap_patch = wm8958_reva_patch; 582 patch_regs = ARRAY_SIZE(wm8958_reva_patch); 583 break; 584 default: 585 break; 586 } 587 break; 588 589 case WM1811: 590 /* Revision C did not change the relevant layer */ 591 if (wm8994->revision > 1) 592 wm8994->revision++; 593 594 regmap_patch = wm1811_reva_patch; 595 patch_regs = ARRAY_SIZE(wm1811_reva_patch); 596 break; 597 598 default: 599 break; 600 } 601 602 dev_info(wm8994->dev, "%s revision %c CUST_ID %02x\n", devname, 603 'A' + wm8994->revision, wm8994->cust_id); 604 605 switch (wm8994->type) { 606 case WM1811: 607 regmap_config = &wm1811_regmap_config; 608 break; 609 case WM8994: 610 regmap_config = &wm8994_regmap_config; 611 break; 612 case WM8958: 613 regmap_config = &wm8958_regmap_config; 614 break; 615 default: 616 dev_err(wm8994->dev, "Unknown device type %d\n", wm8994->type); 617 return -EINVAL; 618 } 619 620 ret = regmap_reinit_cache(wm8994->regmap, regmap_config); 621 if (ret != 0) { 622 dev_err(wm8994->dev, "Failed to reinit register cache: %d\n", 623 ret); 624 return ret; 625 } 626 627 /* Explicitly put the device into reset in case regulators 628 * don't get disabled in order to ensure we know the device 629 * state. 630 */ 631 ret = wm8994_reg_write(wm8994, WM8994_SOFTWARE_RESET, 632 wm8994_reg_read(wm8994, WM8994_SOFTWARE_RESET)); 633 if (ret != 0) { 634 dev_err(wm8994->dev, "Failed to reset device: %d\n", ret); 635 return ret; 636 } 637 638 if (regmap_patch) { 639 ret = regmap_register_patch(wm8994->regmap, regmap_patch, 640 patch_regs); 641 if (ret != 0) { 642 dev_err(wm8994->dev, "Failed to register patch: %d\n", 643 ret); 644 goto err; 645 } 646 } 647 648 wm8994->irq_base = pdata->irq_base; 649 wm8994->gpio_base = pdata->gpio_base; 650 651 /* GPIO configuration is only applied if it's non-zero */ 652 for (i = 0; i < ARRAY_SIZE(pdata->gpio_defaults); i++) { 653 if (pdata->gpio_defaults[i]) { 654 wm8994_set_bits(wm8994, WM8994_GPIO_1 + i, 655 0xffff, pdata->gpio_defaults[i]); 656 } 657 } 658 659 wm8994->ldo_ena_always_driven = pdata->ldo_ena_always_driven; 660 661 if (pdata->spkmode_pu) 662 pulls |= WM8994_SPKMODE_PU; 663 664 /* Disable unneeded pulls */ 665 wm8994_set_bits(wm8994, WM8994_PULL_CONTROL_2, 666 WM8994_LDO1ENA_PD | WM8994_LDO2ENA_PD | 667 WM8994_SPKMODE_PU | WM8994_CSNADDR_PD, 668 pulls); 669 670 /* In some system designs where the regulators are not in use, 671 * we can achieve a small reduction in leakage currents by 672 * floating LDO outputs. This bit makes no difference if the 673 * LDOs are enabled, it only affects cases where the LDOs were 674 * in operation and are then disabled. 675 */ 676 for (i = 0; i < WM8994_NUM_LDO_REGS; i++) { 677 if (wm8994_ldo_in_use(pdata, i)) 678 wm8994_set_bits(wm8994, WM8994_LDO_1 + i, 679 WM8994_LDO1_DISCH, WM8994_LDO1_DISCH); 680 else 681 wm8994_set_bits(wm8994, WM8994_LDO_1 + i, 682 WM8994_LDO1_DISCH, 0); 683 } 684 685 wm8994_irq_init(wm8994); 686 687 ret = mfd_add_devices(wm8994->dev, -1, 688 wm8994_devs, ARRAY_SIZE(wm8994_devs), 689 NULL, 0, NULL); 690 if (ret != 0) { 691 dev_err(wm8994->dev, "Failed to add children: %d\n", ret); 692 goto err_irq; 693 } 694 695 pm_runtime_enable(wm8994->dev); 696 pm_runtime_idle(wm8994->dev); 697 698 return 0; 699 700err_irq: 701 wm8994_irq_exit(wm8994); 702err_enable: 703 regulator_bulk_disable(wm8994->num_supplies, 704 wm8994->supplies); 705err: 706 mfd_remove_devices(wm8994->dev); 707 return ret; 708} 709 710static void wm8994_device_exit(struct wm8994 *wm8994) 711{ 712 pm_runtime_disable(wm8994->dev); 713 mfd_remove_devices(wm8994->dev); 714 wm8994_irq_exit(wm8994); 715 regulator_bulk_disable(wm8994->num_supplies, 716 wm8994->supplies); 717} 718 719static const struct of_device_id wm8994_of_match[] = { 720 { .compatible = "wlf,wm1811", .data = (void *)WM1811 }, 721 { .compatible = "wlf,wm8994", .data = (void *)WM8994 }, 722 { .compatible = "wlf,wm8958", .data = (void *)WM8958 }, 723 { } 724}; 725MODULE_DEVICE_TABLE(of, wm8994_of_match); 726 727static int wm8994_i2c_probe(struct i2c_client *i2c, 728 const struct i2c_device_id *id) 729{ 730 const struct of_device_id *of_id; 731 struct wm8994 *wm8994; 732 int ret; 733 734 wm8994 = devm_kzalloc(&i2c->dev, sizeof(struct wm8994), GFP_KERNEL); 735 if (wm8994 == NULL) 736 return -ENOMEM; 737 738 i2c_set_clientdata(i2c, wm8994); 739 wm8994->dev = &i2c->dev; 740 wm8994->irq = i2c->irq; 741 742 if (i2c->dev.of_node) { 743 of_id = of_match_device(wm8994_of_match, &i2c->dev); 744 if (of_id) 745 wm8994->type = (int)of_id->data; 746 } else { 747 wm8994->type = id->driver_data; 748 } 749 750 wm8994->regmap = devm_regmap_init_i2c(i2c, &wm8994_base_regmap_config); 751 if (IS_ERR(wm8994->regmap)) { 752 ret = PTR_ERR(wm8994->regmap); 753 dev_err(wm8994->dev, "Failed to allocate register map: %d\n", 754 ret); 755 return ret; 756 } 757 758 return wm8994_device_init(wm8994, i2c->irq); 759} 760 761static int wm8994_i2c_remove(struct i2c_client *i2c) 762{ 763 struct wm8994 *wm8994 = i2c_get_clientdata(i2c); 764 765 wm8994_device_exit(wm8994); 766 767 return 0; 768} 769 770static const struct i2c_device_id wm8994_i2c_id[] = { 771 { "wm1811", WM1811 }, 772 { "wm1811a", WM1811 }, 773 { "wm8994", WM8994 }, 774 { "wm8958", WM8958 }, 775 { } 776}; 777MODULE_DEVICE_TABLE(i2c, wm8994_i2c_id); 778 779static const struct dev_pm_ops wm8994_pm_ops = { 780 SET_RUNTIME_PM_OPS(wm8994_suspend, wm8994_resume, NULL) 781}; 782 783static struct i2c_driver wm8994_i2c_driver = { 784 .driver = { 785 .name = "wm8994", 786 .owner = THIS_MODULE, 787 .pm = &wm8994_pm_ops, 788 .of_match_table = of_match_ptr(wm8994_of_match), 789 }, 790 .probe = wm8994_i2c_probe, 791 .remove = wm8994_i2c_remove, 792 .id_table = wm8994_i2c_id, 793}; 794 795module_i2c_driver(wm8994_i2c_driver); 796 797MODULE_DESCRIPTION("Core support for the WM8994 audio CODEC"); 798MODULE_LICENSE("GPL"); 799MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); 800