1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * wm831x-core.c -- Device access for Wolfson WM831x PMICs 4 * 5 * Copyright 2009 Wolfson Microelectronics PLC. 6 * 7 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> 8 */ 9 10 #include <linux/kernel.h> 11 #include <linux/init.h> 12 #include <linux/export.h> 13 #include <linux/bcd.h> 14 #include <linux/delay.h> 15 #include <linux/mfd/core.h> 16 #include <linux/slab.h> 17 #include <linux/err.h> 18 19 #include <linux/mfd/wm831x/core.h> 20 #include <linux/mfd/wm831x/pdata.h> 21 #include <linux/mfd/wm831x/irq.h> 22 #include <linux/mfd/wm831x/auxadc.h> 23 #include <linux/mfd/wm831x/otp.h> 24 #include <linux/mfd/wm831x/pmu.h> 25 #include <linux/mfd/wm831x/regulator.h> 26 27 /* Current settings - values are 2*2^(reg_val/4) microamps. These are 28 * exported since they are used by multiple drivers. 29 */ 30 const unsigned int wm831x_isinkv_values[WM831X_ISINK_MAX_ISEL + 1] = { 31 2, 32 2, 33 3, 34 3, 35 4, 36 5, 37 6, 38 7, 39 8, 40 10, 41 11, 42 13, 43 16, 44 19, 45 23, 46 27, 47 32, 48 38, 49 45, 50 54, 51 64, 52 76, 53 91, 54 108, 55 128, 56 152, 57 181, 58 215, 59 256, 60 304, 61 362, 62 431, 63 512, 64 609, 65 724, 66 861, 67 1024, 68 1218, 69 1448, 70 1722, 71 2048, 72 2435, 73 2896, 74 3444, 75 4096, 76 4871, 77 5793, 78 6889, 79 8192, 80 9742, 81 11585, 82 13777, 83 16384, 84 19484, 85 23170, 86 27554, 87 }; 88 EXPORT_SYMBOL_GPL(wm831x_isinkv_values); 89 90 static int wm831x_reg_locked(struct wm831x *wm831x, unsigned short reg) 91 { 92 if (!wm831x->locked) 93 return 0; 94 95 switch (reg) { 96 case WM831X_WATCHDOG: 97 case WM831X_DC4_CONTROL: 98 case WM831X_ON_PIN_CONTROL: 99 case WM831X_BACKUP_CHARGER_CONTROL: 100 case WM831X_CHARGER_CONTROL_1: 101 case WM831X_CHARGER_CONTROL_2: 102 return 1; 103 104 default: 105 return 0; 106 } 107 } 108 109 /** 110 * wm831x_reg_lock: Unlock user keyed registers 111 * 112 * The WM831x has a user key preventing writes to particularly 113 * critical registers. This function locks those registers, 114 * allowing writes to them. 115 * 116 * @wm831x: pointer to local driver data structure 117 */ 118 void wm831x_reg_lock(struct wm831x *wm831x) 119 { 120 int ret; 121 122 ret = wm831x_reg_write(wm831x, WM831X_SECURITY_KEY, 0); 123 if (ret == 0) { 124 dev_vdbg(wm831x->dev, "Registers locked\n"); 125 126 mutex_lock(&wm831x->io_lock); 127 WARN_ON(wm831x->locked); 128 wm831x->locked = 1; 129 mutex_unlock(&wm831x->io_lock); 130 } else { 131 dev_err(wm831x->dev, "Failed to lock registers: %d\n", ret); 132 } 133 134 } 135 EXPORT_SYMBOL_GPL(wm831x_reg_lock); 136 137 /** 138 * wm831x_reg_unlock: Unlock user keyed registers 139 * 140 * The WM831x has a user key preventing writes to particularly 141 * critical registers. This function locks those registers, 142 * preventing spurious writes. 143 * 144 * @wm831x: pointer to local driver data structure 145 */ 146 int wm831x_reg_unlock(struct wm831x *wm831x) 147 { 148 int ret; 149 150 /* 0x9716 is the value required to unlock the registers */ 151 ret = wm831x_reg_write(wm831x, WM831X_SECURITY_KEY, 0x9716); 152 if (ret == 0) { 153 dev_vdbg(wm831x->dev, "Registers unlocked\n"); 154 155 mutex_lock(&wm831x->io_lock); 156 WARN_ON(!wm831x->locked); 157 wm831x->locked = 0; 158 mutex_unlock(&wm831x->io_lock); 159 } 160 161 return ret; 162 } 163 EXPORT_SYMBOL_GPL(wm831x_reg_unlock); 164 165 static bool wm831x_reg_readable(struct device *dev, unsigned int reg) 166 { 167 switch (reg) { 168 case WM831X_RESET_ID: 169 case WM831X_REVISION: 170 case WM831X_PARENT_ID: 171 case WM831X_SYSVDD_CONTROL: 172 case WM831X_THERMAL_MONITORING: 173 case WM831X_POWER_STATE: 174 case WM831X_WATCHDOG: 175 case WM831X_ON_PIN_CONTROL: 176 case WM831X_RESET_CONTROL: 177 case WM831X_CONTROL_INTERFACE: 178 case WM831X_SECURITY_KEY: 179 case WM831X_SOFTWARE_SCRATCH: 180 case WM831X_OTP_CONTROL: 181 case WM831X_GPIO_LEVEL: 182 case WM831X_SYSTEM_STATUS: 183 case WM831X_ON_SOURCE: 184 case WM831X_OFF_SOURCE: 185 case WM831X_SYSTEM_INTERRUPTS: 186 case WM831X_INTERRUPT_STATUS_1: 187 case WM831X_INTERRUPT_STATUS_2: 188 case WM831X_INTERRUPT_STATUS_3: 189 case WM831X_INTERRUPT_STATUS_4: 190 case WM831X_INTERRUPT_STATUS_5: 191 case WM831X_IRQ_CONFIG: 192 case WM831X_SYSTEM_INTERRUPTS_MASK: 193 case WM831X_INTERRUPT_STATUS_1_MASK: 194 case WM831X_INTERRUPT_STATUS_2_MASK: 195 case WM831X_INTERRUPT_STATUS_3_MASK: 196 case WM831X_INTERRUPT_STATUS_4_MASK: 197 case WM831X_INTERRUPT_STATUS_5_MASK: 198 case WM831X_RTC_WRITE_COUNTER: 199 case WM831X_RTC_TIME_1: 200 case WM831X_RTC_TIME_2: 201 case WM831X_RTC_ALARM_1: 202 case WM831X_RTC_ALARM_2: 203 case WM831X_RTC_CONTROL: 204 case WM831X_RTC_TRIM: 205 case WM831X_TOUCH_CONTROL_1: 206 case WM831X_TOUCH_CONTROL_2: 207 case WM831X_TOUCH_DATA_X: 208 case WM831X_TOUCH_DATA_Y: 209 case WM831X_TOUCH_DATA_Z: 210 case WM831X_AUXADC_DATA: 211 case WM831X_AUXADC_CONTROL: 212 case WM831X_AUXADC_SOURCE: 213 case WM831X_COMPARATOR_CONTROL: 214 case WM831X_COMPARATOR_1: 215 case WM831X_COMPARATOR_2: 216 case WM831X_COMPARATOR_3: 217 case WM831X_COMPARATOR_4: 218 case WM831X_GPIO1_CONTROL: 219 case WM831X_GPIO2_CONTROL: 220 case WM831X_GPIO3_CONTROL: 221 case WM831X_GPIO4_CONTROL: 222 case WM831X_GPIO5_CONTROL: 223 case WM831X_GPIO6_CONTROL: 224 case WM831X_GPIO7_CONTROL: 225 case WM831X_GPIO8_CONTROL: 226 case WM831X_GPIO9_CONTROL: 227 case WM831X_GPIO10_CONTROL: 228 case WM831X_GPIO11_CONTROL: 229 case WM831X_GPIO12_CONTROL: 230 case WM831X_GPIO13_CONTROL: 231 case WM831X_GPIO14_CONTROL: 232 case WM831X_GPIO15_CONTROL: 233 case WM831X_GPIO16_CONTROL: 234 case WM831X_CHARGER_CONTROL_1: 235 case WM831X_CHARGER_CONTROL_2: 236 case WM831X_CHARGER_STATUS: 237 case WM831X_BACKUP_CHARGER_CONTROL: 238 case WM831X_STATUS_LED_1: 239 case WM831X_STATUS_LED_2: 240 case WM831X_CURRENT_SINK_1: 241 case WM831X_CURRENT_SINK_2: 242 case WM831X_DCDC_ENABLE: 243 case WM831X_LDO_ENABLE: 244 case WM831X_DCDC_STATUS: 245 case WM831X_LDO_STATUS: 246 case WM831X_DCDC_UV_STATUS: 247 case WM831X_LDO_UV_STATUS: 248 case WM831X_DC1_CONTROL_1: 249 case WM831X_DC1_CONTROL_2: 250 case WM831X_DC1_ON_CONFIG: 251 case WM831X_DC1_SLEEP_CONTROL: 252 case WM831X_DC1_DVS_CONTROL: 253 case WM831X_DC2_CONTROL_1: 254 case WM831X_DC2_CONTROL_2: 255 case WM831X_DC2_ON_CONFIG: 256 case WM831X_DC2_SLEEP_CONTROL: 257 case WM831X_DC2_DVS_CONTROL: 258 case WM831X_DC3_CONTROL_1: 259 case WM831X_DC3_CONTROL_2: 260 case WM831X_DC3_ON_CONFIG: 261 case WM831X_DC3_SLEEP_CONTROL: 262 case WM831X_DC4_CONTROL: 263 case WM831X_DC4_SLEEP_CONTROL: 264 case WM831X_EPE1_CONTROL: 265 case WM831X_EPE2_CONTROL: 266 case WM831X_LDO1_CONTROL: 267 case WM831X_LDO1_ON_CONTROL: 268 case WM831X_LDO1_SLEEP_CONTROL: 269 case WM831X_LDO2_CONTROL: 270 case WM831X_LDO2_ON_CONTROL: 271 case WM831X_LDO2_SLEEP_CONTROL: 272 case WM831X_LDO3_CONTROL: 273 case WM831X_LDO3_ON_CONTROL: 274 case WM831X_LDO3_SLEEP_CONTROL: 275 case WM831X_LDO4_CONTROL: 276 case WM831X_LDO4_ON_CONTROL: 277 case WM831X_LDO4_SLEEP_CONTROL: 278 case WM831X_LDO5_CONTROL: 279 case WM831X_LDO5_ON_CONTROL: 280 case WM831X_LDO5_SLEEP_CONTROL: 281 case WM831X_LDO6_CONTROL: 282 case WM831X_LDO6_ON_CONTROL: 283 case WM831X_LDO6_SLEEP_CONTROL: 284 case WM831X_LDO7_CONTROL: 285 case WM831X_LDO7_ON_CONTROL: 286 case WM831X_LDO7_SLEEP_CONTROL: 287 case WM831X_LDO8_CONTROL: 288 case WM831X_LDO8_ON_CONTROL: 289 case WM831X_LDO8_SLEEP_CONTROL: 290 case WM831X_LDO9_CONTROL: 291 case WM831X_LDO9_ON_CONTROL: 292 case WM831X_LDO9_SLEEP_CONTROL: 293 case WM831X_LDO10_CONTROL: 294 case WM831X_LDO10_ON_CONTROL: 295 case WM831X_LDO10_SLEEP_CONTROL: 296 case WM831X_LDO11_ON_CONTROL: 297 case WM831X_LDO11_SLEEP_CONTROL: 298 case WM831X_POWER_GOOD_SOURCE_1: 299 case WM831X_POWER_GOOD_SOURCE_2: 300 case WM831X_CLOCK_CONTROL_1: 301 case WM831X_CLOCK_CONTROL_2: 302 case WM831X_FLL_CONTROL_1: 303 case WM831X_FLL_CONTROL_2: 304 case WM831X_FLL_CONTROL_3: 305 case WM831X_FLL_CONTROL_4: 306 case WM831X_FLL_CONTROL_5: 307 case WM831X_UNIQUE_ID_1: 308 case WM831X_UNIQUE_ID_2: 309 case WM831X_UNIQUE_ID_3: 310 case WM831X_UNIQUE_ID_4: 311 case WM831X_UNIQUE_ID_5: 312 case WM831X_UNIQUE_ID_6: 313 case WM831X_UNIQUE_ID_7: 314 case WM831X_UNIQUE_ID_8: 315 case WM831X_FACTORY_OTP_ID: 316 case WM831X_FACTORY_OTP_1: 317 case WM831X_FACTORY_OTP_2: 318 case WM831X_FACTORY_OTP_3: 319 case WM831X_FACTORY_OTP_4: 320 case WM831X_FACTORY_OTP_5: 321 case WM831X_CUSTOMER_OTP_ID: 322 case WM831X_DC1_OTP_CONTROL: 323 case WM831X_DC2_OTP_CONTROL: 324 case WM831X_DC3_OTP_CONTROL: 325 case WM831X_LDO1_2_OTP_CONTROL: 326 case WM831X_LDO3_4_OTP_CONTROL: 327 case WM831X_LDO5_6_OTP_CONTROL: 328 case WM831X_LDO7_8_OTP_CONTROL: 329 case WM831X_LDO9_10_OTP_CONTROL: 330 case WM831X_LDO11_EPE_CONTROL: 331 case WM831X_GPIO1_OTP_CONTROL: 332 case WM831X_GPIO2_OTP_CONTROL: 333 case WM831X_GPIO3_OTP_CONTROL: 334 case WM831X_GPIO4_OTP_CONTROL: 335 case WM831X_GPIO5_OTP_CONTROL: 336 case WM831X_GPIO6_OTP_CONTROL: 337 case WM831X_DBE_CHECK_DATA: 338 return true; 339 default: 340 return false; 341 } 342 } 343 344 static bool wm831x_reg_writeable(struct device *dev, unsigned int reg) 345 { 346 struct wm831x *wm831x = dev_get_drvdata(dev); 347 348 if (wm831x_reg_locked(wm831x, reg)) 349 return false; 350 351 switch (reg) { 352 case WM831X_SYSVDD_CONTROL: 353 case WM831X_THERMAL_MONITORING: 354 case WM831X_POWER_STATE: 355 case WM831X_WATCHDOG: 356 case WM831X_ON_PIN_CONTROL: 357 case WM831X_RESET_CONTROL: 358 case WM831X_CONTROL_INTERFACE: 359 case WM831X_SECURITY_KEY: 360 case WM831X_SOFTWARE_SCRATCH: 361 case WM831X_OTP_CONTROL: 362 case WM831X_GPIO_LEVEL: 363 case WM831X_INTERRUPT_STATUS_1: 364 case WM831X_INTERRUPT_STATUS_2: 365 case WM831X_INTERRUPT_STATUS_3: 366 case WM831X_INTERRUPT_STATUS_4: 367 case WM831X_INTERRUPT_STATUS_5: 368 case WM831X_IRQ_CONFIG: 369 case WM831X_SYSTEM_INTERRUPTS_MASK: 370 case WM831X_INTERRUPT_STATUS_1_MASK: 371 case WM831X_INTERRUPT_STATUS_2_MASK: 372 case WM831X_INTERRUPT_STATUS_3_MASK: 373 case WM831X_INTERRUPT_STATUS_4_MASK: 374 case WM831X_INTERRUPT_STATUS_5_MASK: 375 case WM831X_RTC_TIME_1: 376 case WM831X_RTC_TIME_2: 377 case WM831X_RTC_ALARM_1: 378 case WM831X_RTC_ALARM_2: 379 case WM831X_RTC_CONTROL: 380 case WM831X_RTC_TRIM: 381 case WM831X_TOUCH_CONTROL_1: 382 case WM831X_TOUCH_CONTROL_2: 383 case WM831X_AUXADC_CONTROL: 384 case WM831X_AUXADC_SOURCE: 385 case WM831X_COMPARATOR_CONTROL: 386 case WM831X_COMPARATOR_1: 387 case WM831X_COMPARATOR_2: 388 case WM831X_COMPARATOR_3: 389 case WM831X_COMPARATOR_4: 390 case WM831X_GPIO1_CONTROL: 391 case WM831X_GPIO2_CONTROL: 392 case WM831X_GPIO3_CONTROL: 393 case WM831X_GPIO4_CONTROL: 394 case WM831X_GPIO5_CONTROL: 395 case WM831X_GPIO6_CONTROL: 396 case WM831X_GPIO7_CONTROL: 397 case WM831X_GPIO8_CONTROL: 398 case WM831X_GPIO9_CONTROL: 399 case WM831X_GPIO10_CONTROL: 400 case WM831X_GPIO11_CONTROL: 401 case WM831X_GPIO12_CONTROL: 402 case WM831X_GPIO13_CONTROL: 403 case WM831X_GPIO14_CONTROL: 404 case WM831X_GPIO15_CONTROL: 405 case WM831X_GPIO16_CONTROL: 406 case WM831X_CHARGER_CONTROL_1: 407 case WM831X_CHARGER_CONTROL_2: 408 case WM831X_CHARGER_STATUS: 409 case WM831X_BACKUP_CHARGER_CONTROL: 410 case WM831X_STATUS_LED_1: 411 case WM831X_STATUS_LED_2: 412 case WM831X_CURRENT_SINK_1: 413 case WM831X_CURRENT_SINK_2: 414 case WM831X_DCDC_ENABLE: 415 case WM831X_LDO_ENABLE: 416 case WM831X_DC1_CONTROL_1: 417 case WM831X_DC1_CONTROL_2: 418 case WM831X_DC1_ON_CONFIG: 419 case WM831X_DC1_SLEEP_CONTROL: 420 case WM831X_DC1_DVS_CONTROL: 421 case WM831X_DC2_CONTROL_1: 422 case WM831X_DC2_CONTROL_2: 423 case WM831X_DC2_ON_CONFIG: 424 case WM831X_DC2_SLEEP_CONTROL: 425 case WM831X_DC2_DVS_CONTROL: 426 case WM831X_DC3_CONTROL_1: 427 case WM831X_DC3_CONTROL_2: 428 case WM831X_DC3_ON_CONFIG: 429 case WM831X_DC3_SLEEP_CONTROL: 430 case WM831X_DC4_CONTROL: 431 case WM831X_DC4_SLEEP_CONTROL: 432 case WM831X_EPE1_CONTROL: 433 case WM831X_EPE2_CONTROL: 434 case WM831X_LDO1_CONTROL: 435 case WM831X_LDO1_ON_CONTROL: 436 case WM831X_LDO1_SLEEP_CONTROL: 437 case WM831X_LDO2_CONTROL: 438 case WM831X_LDO2_ON_CONTROL: 439 case WM831X_LDO2_SLEEP_CONTROL: 440 case WM831X_LDO3_CONTROL: 441 case WM831X_LDO3_ON_CONTROL: 442 case WM831X_LDO3_SLEEP_CONTROL: 443 case WM831X_LDO4_CONTROL: 444 case WM831X_LDO4_ON_CONTROL: 445 case WM831X_LDO4_SLEEP_CONTROL: 446 case WM831X_LDO5_CONTROL: 447 case WM831X_LDO5_ON_CONTROL: 448 case WM831X_LDO5_SLEEP_CONTROL: 449 case WM831X_LDO6_CONTROL: 450 case WM831X_LDO6_ON_CONTROL: 451 case WM831X_LDO6_SLEEP_CONTROL: 452 case WM831X_LDO7_CONTROL: 453 case WM831X_LDO7_ON_CONTROL: 454 case WM831X_LDO7_SLEEP_CONTROL: 455 case WM831X_LDO8_CONTROL: 456 case WM831X_LDO8_ON_CONTROL: 457 case WM831X_LDO8_SLEEP_CONTROL: 458 case WM831X_LDO9_CONTROL: 459 case WM831X_LDO9_ON_CONTROL: 460 case WM831X_LDO9_SLEEP_CONTROL: 461 case WM831X_LDO10_CONTROL: 462 case WM831X_LDO10_ON_CONTROL: 463 case WM831X_LDO10_SLEEP_CONTROL: 464 case WM831X_LDO11_ON_CONTROL: 465 case WM831X_LDO11_SLEEP_CONTROL: 466 case WM831X_POWER_GOOD_SOURCE_1: 467 case WM831X_POWER_GOOD_SOURCE_2: 468 case WM831X_CLOCK_CONTROL_1: 469 case WM831X_CLOCK_CONTROL_2: 470 case WM831X_FLL_CONTROL_1: 471 case WM831X_FLL_CONTROL_2: 472 case WM831X_FLL_CONTROL_3: 473 case WM831X_FLL_CONTROL_4: 474 case WM831X_FLL_CONTROL_5: 475 return true; 476 default: 477 return false; 478 } 479 } 480 481 static bool wm831x_reg_volatile(struct device *dev, unsigned int reg) 482 { 483 switch (reg) { 484 case WM831X_SYSTEM_STATUS: 485 case WM831X_ON_SOURCE: 486 case WM831X_OFF_SOURCE: 487 case WM831X_GPIO_LEVEL: 488 case WM831X_SYSTEM_INTERRUPTS: 489 case WM831X_INTERRUPT_STATUS_1: 490 case WM831X_INTERRUPT_STATUS_2: 491 case WM831X_INTERRUPT_STATUS_3: 492 case WM831X_INTERRUPT_STATUS_4: 493 case WM831X_INTERRUPT_STATUS_5: 494 case WM831X_RTC_TIME_1: 495 case WM831X_RTC_TIME_2: 496 case WM831X_TOUCH_DATA_X: 497 case WM831X_TOUCH_DATA_Y: 498 case WM831X_TOUCH_DATA_Z: 499 case WM831X_AUXADC_DATA: 500 case WM831X_CHARGER_STATUS: 501 case WM831X_DCDC_STATUS: 502 case WM831X_LDO_STATUS: 503 case WM831X_DCDC_UV_STATUS: 504 case WM831X_LDO_UV_STATUS: 505 return true; 506 default: 507 return false; 508 } 509 } 510 511 /** 512 * wm831x_reg_read: Read a single WM831x register. 513 * 514 * @wm831x: Device to read from. 515 * @reg: Register to read. 516 */ 517 int wm831x_reg_read(struct wm831x *wm831x, unsigned short reg) 518 { 519 unsigned int val; 520 int ret; 521 522 ret = regmap_read(wm831x->regmap, reg, &val); 523 524 if (ret < 0) 525 return ret; 526 else 527 return val; 528 } 529 EXPORT_SYMBOL_GPL(wm831x_reg_read); 530 531 /** 532 * wm831x_bulk_read: Read multiple WM831x registers 533 * 534 * @wm831x: Device to read from 535 * @reg: First register 536 * @count: Number of registers 537 * @buf: Buffer to fill. 538 */ 539 int wm831x_bulk_read(struct wm831x *wm831x, unsigned short reg, 540 int count, u16 *buf) 541 { 542 return regmap_bulk_read(wm831x->regmap, reg, buf, count); 543 } 544 EXPORT_SYMBOL_GPL(wm831x_bulk_read); 545 546 static int wm831x_write(struct wm831x *wm831x, unsigned short reg, 547 int bytes, void *src) 548 { 549 u16 *buf = src; 550 int i, ret; 551 552 BUG_ON(bytes % 2); 553 BUG_ON(bytes <= 0); 554 555 for (i = 0; i < bytes / 2; i++) { 556 if (wm831x_reg_locked(wm831x, reg)) 557 return -EPERM; 558 559 dev_vdbg(wm831x->dev, "Write %04x to R%d(0x%x)\n", 560 buf[i], reg + i, reg + i); 561 ret = regmap_write(wm831x->regmap, reg + i, buf[i]); 562 if (ret != 0) 563 return ret; 564 } 565 566 return 0; 567 } 568 569 /** 570 * wm831x_reg_write: Write a single WM831x register. 571 * 572 * @wm831x: Device to write to. 573 * @reg: Register to write to. 574 * @val: Value to write. 575 */ 576 int wm831x_reg_write(struct wm831x *wm831x, unsigned short reg, 577 unsigned short val) 578 { 579 int ret; 580 581 mutex_lock(&wm831x->io_lock); 582 583 ret = wm831x_write(wm831x, reg, 2, &val); 584 585 mutex_unlock(&wm831x->io_lock); 586 587 return ret; 588 } 589 EXPORT_SYMBOL_GPL(wm831x_reg_write); 590 591 /** 592 * wm831x_set_bits: Set the value of a bitfield in a WM831x register 593 * 594 * @wm831x: Device to write to. 595 * @reg: Register to write to. 596 * @mask: Mask of bits to set. 597 * @val: Value to set (unshifted) 598 */ 599 int wm831x_set_bits(struct wm831x *wm831x, unsigned short reg, 600 unsigned short mask, unsigned short val) 601 { 602 int ret; 603 604 mutex_lock(&wm831x->io_lock); 605 606 if (!wm831x_reg_locked(wm831x, reg)) 607 ret = regmap_update_bits(wm831x->regmap, reg, mask, val); 608 else 609 ret = -EPERM; 610 611 mutex_unlock(&wm831x->io_lock); 612 613 return ret; 614 } 615 EXPORT_SYMBOL_GPL(wm831x_set_bits); 616 617 static const struct resource wm831x_dcdc1_resources[] = { 618 { 619 .start = WM831X_DC1_CONTROL_1, 620 .end = WM831X_DC1_DVS_CONTROL, 621 .flags = IORESOURCE_REG, 622 }, 623 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_UV_DC1, "UV"), 624 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_HC_DC1, "HC"), 625 }; 626 627 628 static const struct resource wm831x_dcdc2_resources[] = { 629 { 630 .start = WM831X_DC2_CONTROL_1, 631 .end = WM831X_DC2_DVS_CONTROL, 632 .flags = IORESOURCE_REG, 633 }, 634 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_UV_DC2, "UV"), 635 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_HC_DC2, "HC"), 636 }; 637 638 static const struct resource wm831x_dcdc3_resources[] = { 639 { 640 .start = WM831X_DC3_CONTROL_1, 641 .end = WM831X_DC3_SLEEP_CONTROL, 642 .flags = IORESOURCE_REG, 643 }, 644 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_UV_DC3, "UV"), 645 }; 646 647 static const struct resource wm831x_dcdc4_resources[] = { 648 { 649 .start = WM831X_DC4_CONTROL, 650 .end = WM831X_DC4_SLEEP_CONTROL, 651 .flags = IORESOURCE_REG, 652 }, 653 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_UV_DC4, "UV"), 654 }; 655 656 static const struct resource wm8320_dcdc4_buck_resources[] = { 657 { 658 .start = WM831X_DC4_CONTROL, 659 .end = WM832X_DC4_SLEEP_CONTROL, 660 .flags = IORESOURCE_REG, 661 }, 662 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_UV_DC4, "UV"), 663 }; 664 665 static const struct resource wm831x_gpio_resources[] = { 666 { 667 .start = WM831X_IRQ_GPIO_1, 668 .end = WM831X_IRQ_GPIO_16, 669 .flags = IORESOURCE_IRQ, 670 }, 671 }; 672 673 static const struct resource wm831x_isink1_resources[] = { 674 { 675 .start = WM831X_CURRENT_SINK_1, 676 .end = WM831X_CURRENT_SINK_1, 677 .flags = IORESOURCE_REG, 678 }, 679 DEFINE_RES_IRQ(WM831X_IRQ_CS1), 680 }; 681 682 static const struct resource wm831x_isink2_resources[] = { 683 { 684 .start = WM831X_CURRENT_SINK_2, 685 .end = WM831X_CURRENT_SINK_2, 686 .flags = IORESOURCE_REG, 687 }, 688 DEFINE_RES_IRQ(WM831X_IRQ_CS2), 689 }; 690 691 static const struct resource wm831x_ldo1_resources[] = { 692 { 693 .start = WM831X_LDO1_CONTROL, 694 .end = WM831X_LDO1_SLEEP_CONTROL, 695 .flags = IORESOURCE_REG, 696 }, 697 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_UV_LDO1, "UV"), 698 }; 699 700 static const struct resource wm831x_ldo2_resources[] = { 701 { 702 .start = WM831X_LDO2_CONTROL, 703 .end = WM831X_LDO2_SLEEP_CONTROL, 704 .flags = IORESOURCE_REG, 705 }, 706 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_UV_LDO2, "UV"), 707 }; 708 709 static const struct resource wm831x_ldo3_resources[] = { 710 { 711 .start = WM831X_LDO3_CONTROL, 712 .end = WM831X_LDO3_SLEEP_CONTROL, 713 .flags = IORESOURCE_REG, 714 }, 715 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_UV_LDO3, "UV"), 716 }; 717 718 static const struct resource wm831x_ldo4_resources[] = { 719 { 720 .start = WM831X_LDO4_CONTROL, 721 .end = WM831X_LDO4_SLEEP_CONTROL, 722 .flags = IORESOURCE_REG, 723 }, 724 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_UV_LDO4, "UV"), 725 }; 726 727 static const struct resource wm831x_ldo5_resources[] = { 728 { 729 .start = WM831X_LDO5_CONTROL, 730 .end = WM831X_LDO5_SLEEP_CONTROL, 731 .flags = IORESOURCE_REG, 732 }, 733 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_UV_LDO5, "UV"), 734 }; 735 736 static const struct resource wm831x_ldo6_resources[] = { 737 { 738 .start = WM831X_LDO6_CONTROL, 739 .end = WM831X_LDO6_SLEEP_CONTROL, 740 .flags = IORESOURCE_REG, 741 }, 742 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_UV_LDO6, "UV"), 743 }; 744 745 static const struct resource wm831x_ldo7_resources[] = { 746 { 747 .start = WM831X_LDO7_CONTROL, 748 .end = WM831X_LDO7_SLEEP_CONTROL, 749 .flags = IORESOURCE_REG, 750 }, 751 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_UV_LDO7, "UV"), 752 }; 753 754 static const struct resource wm831x_ldo8_resources[] = { 755 { 756 .start = WM831X_LDO8_CONTROL, 757 .end = WM831X_LDO8_SLEEP_CONTROL, 758 .flags = IORESOURCE_REG, 759 }, 760 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_UV_LDO8, "UV"), 761 }; 762 763 static const struct resource wm831x_ldo9_resources[] = { 764 { 765 .start = WM831X_LDO9_CONTROL, 766 .end = WM831X_LDO9_SLEEP_CONTROL, 767 .flags = IORESOURCE_REG, 768 }, 769 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_UV_LDO9, "UV"), 770 }; 771 772 static const struct resource wm831x_ldo10_resources[] = { 773 { 774 .start = WM831X_LDO10_CONTROL, 775 .end = WM831X_LDO10_SLEEP_CONTROL, 776 .flags = IORESOURCE_REG, 777 }, 778 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_UV_LDO10, "UV"), 779 }; 780 781 static const struct resource wm831x_ldo11_resources[] = { 782 { 783 .start = WM831X_LDO11_ON_CONTROL, 784 .end = WM831X_LDO11_SLEEP_CONTROL, 785 .flags = IORESOURCE_REG, 786 }, 787 }; 788 789 static const struct resource wm831x_on_resources[] = { 790 DEFINE_RES_IRQ(WM831X_IRQ_ON), 791 }; 792 793 794 static const struct resource wm831x_power_resources[] = { 795 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_PPM_SYSLO, "SYSLO"), 796 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_PPM_PWR_SRC, "PWR SRC"), 797 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_PPM_USB_CURR, "USB CURR"), 798 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_CHG_BATT_HOT, "BATT HOT"), 799 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_CHG_BATT_COLD, "BATT COLD"), 800 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_CHG_BATT_FAIL, "BATT FAIL"), 801 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_CHG_OV, "OV"), 802 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_CHG_END, "END"), 803 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_CHG_TO, "TO"), 804 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_CHG_MODE, "MODE"), 805 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_CHG_START, "START"), 806 }; 807 808 static const struct resource wm831x_rtc_resources[] = { 809 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_RTC_PER, "PER"), 810 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_RTC_ALM, "ALM"), 811 }; 812 813 static const struct resource wm831x_status1_resources[] = { 814 { 815 .start = WM831X_STATUS_LED_1, 816 .end = WM831X_STATUS_LED_1, 817 .flags = IORESOURCE_REG, 818 }, 819 }; 820 821 static const struct resource wm831x_status2_resources[] = { 822 { 823 .start = WM831X_STATUS_LED_2, 824 .end = WM831X_STATUS_LED_2, 825 .flags = IORESOURCE_REG, 826 }, 827 }; 828 829 static const struct resource wm831x_touch_resources[] = { 830 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_TCHPD, "TCHPD"), 831 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_TCHDATA, "TCHDATA"), 832 }; 833 834 static const struct resource wm831x_wdt_resources[] = { 835 DEFINE_RES_IRQ(WM831X_IRQ_WDOG_TO), 836 }; 837 838 static const struct mfd_cell wm8310_devs[] = { 839 { 840 .name = "wm831x-backup", 841 }, 842 { 843 .name = "wm831x-buckv", 844 .id = 1, 845 .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources), 846 .resources = wm831x_dcdc1_resources, 847 }, 848 { 849 .name = "wm831x-buckv", 850 .id = 2, 851 .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources), 852 .resources = wm831x_dcdc2_resources, 853 }, 854 { 855 .name = "wm831x-buckp", 856 .id = 3, 857 .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources), 858 .resources = wm831x_dcdc3_resources, 859 }, 860 { 861 .name = "wm831x-boostp", 862 .id = 4, 863 .num_resources = ARRAY_SIZE(wm831x_dcdc4_resources), 864 .resources = wm831x_dcdc4_resources, 865 }, 866 { 867 .name = "wm831x-clk", 868 }, 869 { 870 .name = "wm831x-epe", 871 .id = 1, 872 }, 873 { 874 .name = "wm831x-epe", 875 .id = 2, 876 }, 877 { 878 .name = "wm831x-gpio", 879 .num_resources = ARRAY_SIZE(wm831x_gpio_resources), 880 .resources = wm831x_gpio_resources, 881 }, 882 { 883 .name = "wm831x-hwmon", 884 }, 885 { 886 .name = "wm831x-isink", 887 .id = 1, 888 .num_resources = ARRAY_SIZE(wm831x_isink1_resources), 889 .resources = wm831x_isink1_resources, 890 }, 891 { 892 .name = "wm831x-isink", 893 .id = 2, 894 .num_resources = ARRAY_SIZE(wm831x_isink2_resources), 895 .resources = wm831x_isink2_resources, 896 }, 897 { 898 .name = "wm831x-ldo", 899 .id = 1, 900 .num_resources = ARRAY_SIZE(wm831x_ldo1_resources), 901 .resources = wm831x_ldo1_resources, 902 }, 903 { 904 .name = "wm831x-ldo", 905 .id = 2, 906 .num_resources = ARRAY_SIZE(wm831x_ldo2_resources), 907 .resources = wm831x_ldo2_resources, 908 }, 909 { 910 .name = "wm831x-ldo", 911 .id = 3, 912 .num_resources = ARRAY_SIZE(wm831x_ldo3_resources), 913 .resources = wm831x_ldo3_resources, 914 }, 915 { 916 .name = "wm831x-ldo", 917 .id = 4, 918 .num_resources = ARRAY_SIZE(wm831x_ldo4_resources), 919 .resources = wm831x_ldo4_resources, 920 }, 921 { 922 .name = "wm831x-ldo", 923 .id = 5, 924 .num_resources = ARRAY_SIZE(wm831x_ldo5_resources), 925 .resources = wm831x_ldo5_resources, 926 }, 927 { 928 .name = "wm831x-ldo", 929 .id = 6, 930 .num_resources = ARRAY_SIZE(wm831x_ldo6_resources), 931 .resources = wm831x_ldo6_resources, 932 }, 933 { 934 .name = "wm831x-aldo", 935 .id = 7, 936 .num_resources = ARRAY_SIZE(wm831x_ldo7_resources), 937 .resources = wm831x_ldo7_resources, 938 }, 939 { 940 .name = "wm831x-aldo", 941 .id = 8, 942 .num_resources = ARRAY_SIZE(wm831x_ldo8_resources), 943 .resources = wm831x_ldo8_resources, 944 }, 945 { 946 .name = "wm831x-aldo", 947 .id = 9, 948 .num_resources = ARRAY_SIZE(wm831x_ldo9_resources), 949 .resources = wm831x_ldo9_resources, 950 }, 951 { 952 .name = "wm831x-aldo", 953 .id = 10, 954 .num_resources = ARRAY_SIZE(wm831x_ldo10_resources), 955 .resources = wm831x_ldo10_resources, 956 }, 957 { 958 .name = "wm831x-alive-ldo", 959 .id = 11, 960 .num_resources = ARRAY_SIZE(wm831x_ldo11_resources), 961 .resources = wm831x_ldo11_resources, 962 }, 963 { 964 .name = "wm831x-on", 965 .num_resources = ARRAY_SIZE(wm831x_on_resources), 966 .resources = wm831x_on_resources, 967 }, 968 { 969 .name = "wm831x-power", 970 .num_resources = ARRAY_SIZE(wm831x_power_resources), 971 .resources = wm831x_power_resources, 972 }, 973 { 974 .name = "wm831x-status", 975 .id = 1, 976 .num_resources = ARRAY_SIZE(wm831x_status1_resources), 977 .resources = wm831x_status1_resources, 978 }, 979 { 980 .name = "wm831x-status", 981 .id = 2, 982 .num_resources = ARRAY_SIZE(wm831x_status2_resources), 983 .resources = wm831x_status2_resources, 984 }, 985 { 986 .name = "wm831x-watchdog", 987 .num_resources = ARRAY_SIZE(wm831x_wdt_resources), 988 .resources = wm831x_wdt_resources, 989 }, 990 }; 991 992 static const struct mfd_cell wm8311_devs[] = { 993 { 994 .name = "wm831x-backup", 995 }, 996 { 997 .name = "wm831x-buckv", 998 .id = 1, 999 .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources), 1000 .resources = wm831x_dcdc1_resources, 1001 }, 1002 { 1003 .name = "wm831x-buckv", 1004 .id = 2, 1005 .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources), 1006 .resources = wm831x_dcdc2_resources, 1007 }, 1008 { 1009 .name = "wm831x-buckp", 1010 .id = 3, 1011 .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources), 1012 .resources = wm831x_dcdc3_resources, 1013 }, 1014 { 1015 .name = "wm831x-boostp", 1016 .id = 4, 1017 .num_resources = ARRAY_SIZE(wm831x_dcdc4_resources), 1018 .resources = wm831x_dcdc4_resources, 1019 }, 1020 { 1021 .name = "wm831x-clk", 1022 }, 1023 { 1024 .name = "wm831x-epe", 1025 .id = 1, 1026 }, 1027 { 1028 .name = "wm831x-epe", 1029 .id = 2, 1030 }, 1031 { 1032 .name = "wm831x-gpio", 1033 .num_resources = ARRAY_SIZE(wm831x_gpio_resources), 1034 .resources = wm831x_gpio_resources, 1035 }, 1036 { 1037 .name = "wm831x-hwmon", 1038 }, 1039 { 1040 .name = "wm831x-isink", 1041 .id = 1, 1042 .num_resources = ARRAY_SIZE(wm831x_isink1_resources), 1043 .resources = wm831x_isink1_resources, 1044 }, 1045 { 1046 .name = "wm831x-isink", 1047 .id = 2, 1048 .num_resources = ARRAY_SIZE(wm831x_isink2_resources), 1049 .resources = wm831x_isink2_resources, 1050 }, 1051 { 1052 .name = "wm831x-ldo", 1053 .id = 1, 1054 .num_resources = ARRAY_SIZE(wm831x_ldo1_resources), 1055 .resources = wm831x_ldo1_resources, 1056 }, 1057 { 1058 .name = "wm831x-ldo", 1059 .id = 2, 1060 .num_resources = ARRAY_SIZE(wm831x_ldo2_resources), 1061 .resources = wm831x_ldo2_resources, 1062 }, 1063 { 1064 .name = "wm831x-ldo", 1065 .id = 3, 1066 .num_resources = ARRAY_SIZE(wm831x_ldo3_resources), 1067 .resources = wm831x_ldo3_resources, 1068 }, 1069 { 1070 .name = "wm831x-ldo", 1071 .id = 4, 1072 .num_resources = ARRAY_SIZE(wm831x_ldo4_resources), 1073 .resources = wm831x_ldo4_resources, 1074 }, 1075 { 1076 .name = "wm831x-ldo", 1077 .id = 5, 1078 .num_resources = ARRAY_SIZE(wm831x_ldo5_resources), 1079 .resources = wm831x_ldo5_resources, 1080 }, 1081 { 1082 .name = "wm831x-aldo", 1083 .id = 7, 1084 .num_resources = ARRAY_SIZE(wm831x_ldo7_resources), 1085 .resources = wm831x_ldo7_resources, 1086 }, 1087 { 1088 .name = "wm831x-alive-ldo", 1089 .id = 11, 1090 .num_resources = ARRAY_SIZE(wm831x_ldo11_resources), 1091 .resources = wm831x_ldo11_resources, 1092 }, 1093 { 1094 .name = "wm831x-on", 1095 .num_resources = ARRAY_SIZE(wm831x_on_resources), 1096 .resources = wm831x_on_resources, 1097 }, 1098 { 1099 .name = "wm831x-power", 1100 .num_resources = ARRAY_SIZE(wm831x_power_resources), 1101 .resources = wm831x_power_resources, 1102 }, 1103 { 1104 .name = "wm831x-status", 1105 .id = 1, 1106 .num_resources = ARRAY_SIZE(wm831x_status1_resources), 1107 .resources = wm831x_status1_resources, 1108 }, 1109 { 1110 .name = "wm831x-status", 1111 .id = 2, 1112 .num_resources = ARRAY_SIZE(wm831x_status2_resources), 1113 .resources = wm831x_status2_resources, 1114 }, 1115 { 1116 .name = "wm831x-watchdog", 1117 .num_resources = ARRAY_SIZE(wm831x_wdt_resources), 1118 .resources = wm831x_wdt_resources, 1119 }, 1120 }; 1121 1122 static const struct mfd_cell wm8312_devs[] = { 1123 { 1124 .name = "wm831x-backup", 1125 }, 1126 { 1127 .name = "wm831x-buckv", 1128 .id = 1, 1129 .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources), 1130 .resources = wm831x_dcdc1_resources, 1131 }, 1132 { 1133 .name = "wm831x-buckv", 1134 .id = 2, 1135 .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources), 1136 .resources = wm831x_dcdc2_resources, 1137 }, 1138 { 1139 .name = "wm831x-buckp", 1140 .id = 3, 1141 .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources), 1142 .resources = wm831x_dcdc3_resources, 1143 }, 1144 { 1145 .name = "wm831x-boostp", 1146 .id = 4, 1147 .num_resources = ARRAY_SIZE(wm831x_dcdc4_resources), 1148 .resources = wm831x_dcdc4_resources, 1149 }, 1150 { 1151 .name = "wm831x-clk", 1152 }, 1153 { 1154 .name = "wm831x-epe", 1155 .id = 1, 1156 }, 1157 { 1158 .name = "wm831x-epe", 1159 .id = 2, 1160 }, 1161 { 1162 .name = "wm831x-gpio", 1163 .num_resources = ARRAY_SIZE(wm831x_gpio_resources), 1164 .resources = wm831x_gpio_resources, 1165 }, 1166 { 1167 .name = "wm831x-hwmon", 1168 }, 1169 { 1170 .name = "wm831x-isink", 1171 .id = 1, 1172 .num_resources = ARRAY_SIZE(wm831x_isink1_resources), 1173 .resources = wm831x_isink1_resources, 1174 }, 1175 { 1176 .name = "wm831x-isink", 1177 .id = 2, 1178 .num_resources = ARRAY_SIZE(wm831x_isink2_resources), 1179 .resources = wm831x_isink2_resources, 1180 }, 1181 { 1182 .name = "wm831x-ldo", 1183 .id = 1, 1184 .num_resources = ARRAY_SIZE(wm831x_ldo1_resources), 1185 .resources = wm831x_ldo1_resources, 1186 }, 1187 { 1188 .name = "wm831x-ldo", 1189 .id = 2, 1190 .num_resources = ARRAY_SIZE(wm831x_ldo2_resources), 1191 .resources = wm831x_ldo2_resources, 1192 }, 1193 { 1194 .name = "wm831x-ldo", 1195 .id = 3, 1196 .num_resources = ARRAY_SIZE(wm831x_ldo3_resources), 1197 .resources = wm831x_ldo3_resources, 1198 }, 1199 { 1200 .name = "wm831x-ldo", 1201 .id = 4, 1202 .num_resources = ARRAY_SIZE(wm831x_ldo4_resources), 1203 .resources = wm831x_ldo4_resources, 1204 }, 1205 { 1206 .name = "wm831x-ldo", 1207 .id = 5, 1208 .num_resources = ARRAY_SIZE(wm831x_ldo5_resources), 1209 .resources = wm831x_ldo5_resources, 1210 }, 1211 { 1212 .name = "wm831x-ldo", 1213 .id = 6, 1214 .num_resources = ARRAY_SIZE(wm831x_ldo6_resources), 1215 .resources = wm831x_ldo6_resources, 1216 }, 1217 { 1218 .name = "wm831x-aldo", 1219 .id = 7, 1220 .num_resources = ARRAY_SIZE(wm831x_ldo7_resources), 1221 .resources = wm831x_ldo7_resources, 1222 }, 1223 { 1224 .name = "wm831x-aldo", 1225 .id = 8, 1226 .num_resources = ARRAY_SIZE(wm831x_ldo8_resources), 1227 .resources = wm831x_ldo8_resources, 1228 }, 1229 { 1230 .name = "wm831x-aldo", 1231 .id = 9, 1232 .num_resources = ARRAY_SIZE(wm831x_ldo9_resources), 1233 .resources = wm831x_ldo9_resources, 1234 }, 1235 { 1236 .name = "wm831x-aldo", 1237 .id = 10, 1238 .num_resources = ARRAY_SIZE(wm831x_ldo10_resources), 1239 .resources = wm831x_ldo10_resources, 1240 }, 1241 { 1242 .name = "wm831x-alive-ldo", 1243 .id = 11, 1244 .num_resources = ARRAY_SIZE(wm831x_ldo11_resources), 1245 .resources = wm831x_ldo11_resources, 1246 }, 1247 { 1248 .name = "wm831x-on", 1249 .num_resources = ARRAY_SIZE(wm831x_on_resources), 1250 .resources = wm831x_on_resources, 1251 }, 1252 { 1253 .name = "wm831x-power", 1254 .num_resources = ARRAY_SIZE(wm831x_power_resources), 1255 .resources = wm831x_power_resources, 1256 }, 1257 { 1258 .name = "wm831x-status", 1259 .id = 1, 1260 .num_resources = ARRAY_SIZE(wm831x_status1_resources), 1261 .resources = wm831x_status1_resources, 1262 }, 1263 { 1264 .name = "wm831x-status", 1265 .id = 2, 1266 .num_resources = ARRAY_SIZE(wm831x_status2_resources), 1267 .resources = wm831x_status2_resources, 1268 }, 1269 { 1270 .name = "wm831x-watchdog", 1271 .num_resources = ARRAY_SIZE(wm831x_wdt_resources), 1272 .resources = wm831x_wdt_resources, 1273 }, 1274 }; 1275 1276 static const struct mfd_cell wm8320_devs[] = { 1277 { 1278 .name = "wm831x-backup", 1279 }, 1280 { 1281 .name = "wm831x-buckv", 1282 .id = 1, 1283 .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources), 1284 .resources = wm831x_dcdc1_resources, 1285 }, 1286 { 1287 .name = "wm831x-buckv", 1288 .id = 2, 1289 .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources), 1290 .resources = wm831x_dcdc2_resources, 1291 }, 1292 { 1293 .name = "wm831x-buckp", 1294 .id = 3, 1295 .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources), 1296 .resources = wm831x_dcdc3_resources, 1297 }, 1298 { 1299 .name = "wm831x-buckp", 1300 .id = 4, 1301 .num_resources = ARRAY_SIZE(wm8320_dcdc4_buck_resources), 1302 .resources = wm8320_dcdc4_buck_resources, 1303 }, 1304 { 1305 .name = "wm831x-clk", 1306 }, 1307 { 1308 .name = "wm831x-gpio", 1309 .num_resources = ARRAY_SIZE(wm831x_gpio_resources), 1310 .resources = wm831x_gpio_resources, 1311 }, 1312 { 1313 .name = "wm831x-hwmon", 1314 }, 1315 { 1316 .name = "wm831x-ldo", 1317 .id = 1, 1318 .num_resources = ARRAY_SIZE(wm831x_ldo1_resources), 1319 .resources = wm831x_ldo1_resources, 1320 }, 1321 { 1322 .name = "wm831x-ldo", 1323 .id = 2, 1324 .num_resources = ARRAY_SIZE(wm831x_ldo2_resources), 1325 .resources = wm831x_ldo2_resources, 1326 }, 1327 { 1328 .name = "wm831x-ldo", 1329 .id = 3, 1330 .num_resources = ARRAY_SIZE(wm831x_ldo3_resources), 1331 .resources = wm831x_ldo3_resources, 1332 }, 1333 { 1334 .name = "wm831x-ldo", 1335 .id = 4, 1336 .num_resources = ARRAY_SIZE(wm831x_ldo4_resources), 1337 .resources = wm831x_ldo4_resources, 1338 }, 1339 { 1340 .name = "wm831x-ldo", 1341 .id = 5, 1342 .num_resources = ARRAY_SIZE(wm831x_ldo5_resources), 1343 .resources = wm831x_ldo5_resources, 1344 }, 1345 { 1346 .name = "wm831x-ldo", 1347 .id = 6, 1348 .num_resources = ARRAY_SIZE(wm831x_ldo6_resources), 1349 .resources = wm831x_ldo6_resources, 1350 }, 1351 { 1352 .name = "wm831x-aldo", 1353 .id = 7, 1354 .num_resources = ARRAY_SIZE(wm831x_ldo7_resources), 1355 .resources = wm831x_ldo7_resources, 1356 }, 1357 { 1358 .name = "wm831x-aldo", 1359 .id = 8, 1360 .num_resources = ARRAY_SIZE(wm831x_ldo8_resources), 1361 .resources = wm831x_ldo8_resources, 1362 }, 1363 { 1364 .name = "wm831x-aldo", 1365 .id = 9, 1366 .num_resources = ARRAY_SIZE(wm831x_ldo9_resources), 1367 .resources = wm831x_ldo9_resources, 1368 }, 1369 { 1370 .name = "wm831x-aldo", 1371 .id = 10, 1372 .num_resources = ARRAY_SIZE(wm831x_ldo10_resources), 1373 .resources = wm831x_ldo10_resources, 1374 }, 1375 { 1376 .name = "wm831x-alive-ldo", 1377 .id = 11, 1378 .num_resources = ARRAY_SIZE(wm831x_ldo11_resources), 1379 .resources = wm831x_ldo11_resources, 1380 }, 1381 { 1382 .name = "wm831x-on", 1383 .num_resources = ARRAY_SIZE(wm831x_on_resources), 1384 .resources = wm831x_on_resources, 1385 }, 1386 { 1387 .name = "wm831x-status", 1388 .id = 1, 1389 .num_resources = ARRAY_SIZE(wm831x_status1_resources), 1390 .resources = wm831x_status1_resources, 1391 }, 1392 { 1393 .name = "wm831x-status", 1394 .id = 2, 1395 .num_resources = ARRAY_SIZE(wm831x_status2_resources), 1396 .resources = wm831x_status2_resources, 1397 }, 1398 { 1399 .name = "wm831x-watchdog", 1400 .num_resources = ARRAY_SIZE(wm831x_wdt_resources), 1401 .resources = wm831x_wdt_resources, 1402 }, 1403 }; 1404 1405 static const struct mfd_cell touch_devs[] = { 1406 { 1407 .name = "wm831x-touch", 1408 .num_resources = ARRAY_SIZE(wm831x_touch_resources), 1409 .resources = wm831x_touch_resources, 1410 }, 1411 }; 1412 1413 static const struct mfd_cell rtc_devs[] = { 1414 { 1415 .name = "wm831x-rtc", 1416 .num_resources = ARRAY_SIZE(wm831x_rtc_resources), 1417 .resources = wm831x_rtc_resources, 1418 }, 1419 }; 1420 1421 static const struct mfd_cell backlight_devs[] = { 1422 { 1423 .name = "wm831x-backlight", 1424 }, 1425 }; 1426 1427 struct regmap_config wm831x_regmap_config = { 1428 .reg_bits = 16, 1429 .val_bits = 16, 1430 1431 .cache_type = REGCACHE_MAPLE, 1432 1433 .max_register = WM831X_DBE_CHECK_DATA, 1434 .readable_reg = wm831x_reg_readable, 1435 .writeable_reg = wm831x_reg_writeable, 1436 .volatile_reg = wm831x_reg_volatile, 1437 }; 1438 EXPORT_SYMBOL_GPL(wm831x_regmap_config); 1439 1440 const struct of_device_id wm831x_of_match[] = { 1441 { .compatible = "wlf,wm8310", .data = (void *)WM8310 }, 1442 { .compatible = "wlf,wm8311", .data = (void *)WM8311 }, 1443 { .compatible = "wlf,wm8312", .data = (void *)WM8312 }, 1444 { .compatible = "wlf,wm8320", .data = (void *)WM8320 }, 1445 { .compatible = "wlf,wm8321", .data = (void *)WM8321 }, 1446 { .compatible = "wlf,wm8325", .data = (void *)WM8325 }, 1447 { .compatible = "wlf,wm8326", .data = (void *)WM8326 }, 1448 { }, 1449 }; 1450 EXPORT_SYMBOL_GPL(wm831x_of_match); 1451 1452 /* 1453 * Instantiate the generic non-control parts of the device. 1454 */ 1455 int wm831x_device_init(struct wm831x *wm831x, int irq) 1456 { 1457 struct wm831x_pdata *pdata = &wm831x->pdata; 1458 int rev, wm831x_num; 1459 enum wm831x_parent parent; 1460 int ret, i; 1461 1462 mutex_init(&wm831x->io_lock); 1463 mutex_init(&wm831x->key_lock); 1464 dev_set_drvdata(wm831x->dev, wm831x); 1465 1466 wm831x->soft_shutdown = pdata->soft_shutdown; 1467 1468 ret = wm831x_reg_read(wm831x, WM831X_PARENT_ID); 1469 if (ret < 0) { 1470 dev_err(wm831x->dev, "Failed to read parent ID: %d\n", ret); 1471 goto err; 1472 } 1473 switch (ret) { 1474 case 0x6204: 1475 case 0x6246: 1476 break; 1477 default: 1478 dev_err(wm831x->dev, "Device is not a WM831x: ID %x\n", ret); 1479 ret = -EINVAL; 1480 goto err; 1481 } 1482 1483 ret = wm831x_reg_read(wm831x, WM831X_REVISION); 1484 if (ret < 0) { 1485 dev_err(wm831x->dev, "Failed to read revision: %d\n", ret); 1486 goto err; 1487 } 1488 rev = (ret & WM831X_PARENT_REV_MASK) >> WM831X_PARENT_REV_SHIFT; 1489 1490 ret = wm831x_reg_read(wm831x, WM831X_RESET_ID); 1491 if (ret < 0) { 1492 dev_err(wm831x->dev, "Failed to read device ID: %d\n", ret); 1493 goto err; 1494 } 1495 1496 /* Some engineering samples do not have the ID set, rely on 1497 * the device being registered correctly. 1498 */ 1499 if (ret == 0) { 1500 dev_info(wm831x->dev, "Device is an engineering sample\n"); 1501 ret = wm831x->type; 1502 } 1503 1504 switch (ret) { 1505 case WM8310: 1506 parent = WM8310; 1507 wm831x->num_gpio = 16; 1508 wm831x->charger_irq_wake = 1; 1509 if (rev > 0) { 1510 wm831x->has_gpio_ena = 1; 1511 wm831x->has_cs_sts = 1; 1512 } 1513 1514 dev_info(wm831x->dev, "WM8310 revision %c\n", 'A' + rev); 1515 break; 1516 1517 case WM8311: 1518 parent = WM8311; 1519 wm831x->num_gpio = 16; 1520 wm831x->charger_irq_wake = 1; 1521 if (rev > 0) { 1522 wm831x->has_gpio_ena = 1; 1523 wm831x->has_cs_sts = 1; 1524 } 1525 1526 dev_info(wm831x->dev, "WM8311 revision %c\n", 'A' + rev); 1527 break; 1528 1529 case WM8312: 1530 parent = WM8312; 1531 wm831x->num_gpio = 16; 1532 wm831x->charger_irq_wake = 1; 1533 if (rev > 0) { 1534 wm831x->has_gpio_ena = 1; 1535 wm831x->has_cs_sts = 1; 1536 } 1537 1538 dev_info(wm831x->dev, "WM8312 revision %c\n", 'A' + rev); 1539 break; 1540 1541 case WM8320: 1542 parent = WM8320; 1543 wm831x->num_gpio = 12; 1544 dev_info(wm831x->dev, "WM8320 revision %c\n", 'A' + rev); 1545 break; 1546 1547 case WM8321: 1548 parent = WM8321; 1549 wm831x->num_gpio = 12; 1550 dev_info(wm831x->dev, "WM8321 revision %c\n", 'A' + rev); 1551 break; 1552 1553 case WM8325: 1554 parent = WM8325; 1555 wm831x->num_gpio = 12; 1556 dev_info(wm831x->dev, "WM8325 revision %c\n", 'A' + rev); 1557 break; 1558 1559 case WM8326: 1560 parent = WM8326; 1561 wm831x->num_gpio = 12; 1562 dev_info(wm831x->dev, "WM8326 revision %c\n", 'A' + rev); 1563 break; 1564 1565 default: 1566 dev_err(wm831x->dev, "Unknown WM831x device %04x\n", ret); 1567 ret = -EINVAL; 1568 goto err; 1569 } 1570 1571 /* This will need revisiting in future but is OK for all 1572 * current parts. 1573 */ 1574 if (parent != wm831x->type) 1575 dev_warn(wm831x->dev, "Device was registered as a WM%x\n", 1576 wm831x->type); 1577 1578 /* Bootstrap the user key */ 1579 ret = wm831x_reg_read(wm831x, WM831X_SECURITY_KEY); 1580 if (ret < 0) { 1581 dev_err(wm831x->dev, "Failed to read security key: %d\n", ret); 1582 goto err; 1583 } 1584 if (ret != 0) { 1585 dev_warn(wm831x->dev, "Security key had non-zero value %x\n", 1586 ret); 1587 wm831x_reg_write(wm831x, WM831X_SECURITY_KEY, 0); 1588 } 1589 wm831x->locked = 1; 1590 1591 if (pdata->pre_init) { 1592 ret = pdata->pre_init(wm831x); 1593 if (ret != 0) { 1594 dev_err(wm831x->dev, "pre_init() failed: %d\n", ret); 1595 goto err; 1596 } 1597 } 1598 1599 for (i = 0; i < ARRAY_SIZE(pdata->gpio_defaults); i++) { 1600 if (!pdata->gpio_defaults[i]) 1601 continue; 1602 1603 wm831x_reg_write(wm831x, 1604 WM831X_GPIO1_CONTROL + i, 1605 pdata->gpio_defaults[i] & 0xffff); 1606 } 1607 1608 /* Multiply by 10 as we have many subdevices of the same type */ 1609 if (pdata->wm831x_num) 1610 wm831x_num = pdata->wm831x_num * 10; 1611 else 1612 wm831x_num = -1; 1613 1614 ret = wm831x_irq_init(wm831x, irq); 1615 if (ret != 0) 1616 goto err; 1617 1618 wm831x_auxadc_init(wm831x); 1619 1620 /* The core device is up, instantiate the subdevices. */ 1621 switch (parent) { 1622 case WM8310: 1623 ret = mfd_add_devices(wm831x->dev, wm831x_num, 1624 wm8310_devs, ARRAY_SIZE(wm8310_devs), 1625 NULL, 0, NULL); 1626 break; 1627 1628 case WM8311: 1629 ret = mfd_add_devices(wm831x->dev, wm831x_num, 1630 wm8311_devs, ARRAY_SIZE(wm8311_devs), 1631 NULL, 0, NULL); 1632 if (!pdata->disable_touch) 1633 mfd_add_devices(wm831x->dev, wm831x_num, 1634 touch_devs, ARRAY_SIZE(touch_devs), 1635 NULL, 0, NULL); 1636 break; 1637 1638 case WM8312: 1639 ret = mfd_add_devices(wm831x->dev, wm831x_num, 1640 wm8312_devs, ARRAY_SIZE(wm8312_devs), 1641 NULL, 0, NULL); 1642 if (!pdata->disable_touch) 1643 mfd_add_devices(wm831x->dev, wm831x_num, 1644 touch_devs, ARRAY_SIZE(touch_devs), 1645 NULL, 0, NULL); 1646 break; 1647 1648 case WM8320: 1649 case WM8321: 1650 case WM8325: 1651 case WM8326: 1652 ret = mfd_add_devices(wm831x->dev, wm831x_num, 1653 wm8320_devs, ARRAY_SIZE(wm8320_devs), 1654 NULL, 0, NULL); 1655 break; 1656 1657 default: 1658 /* If this happens the bus probe function is buggy */ 1659 BUG(); 1660 } 1661 1662 if (ret != 0) { 1663 dev_err(wm831x->dev, "Failed to add children\n"); 1664 goto err_irq; 1665 } 1666 1667 /* The RTC can only be used if the 32.768kHz crystal is 1668 * enabled; this can't be controlled by software at runtime. 1669 */ 1670 ret = wm831x_reg_read(wm831x, WM831X_CLOCK_CONTROL_2); 1671 if (ret < 0) { 1672 dev_err(wm831x->dev, "Failed to read clock status: %d\n", ret); 1673 goto err_irq; 1674 } 1675 1676 if (ret & WM831X_XTAL_ENA) { 1677 ret = mfd_add_devices(wm831x->dev, wm831x_num, 1678 rtc_devs, ARRAY_SIZE(rtc_devs), 1679 NULL, 0, NULL); 1680 if (ret != 0) { 1681 dev_err(wm831x->dev, "Failed to add RTC: %d\n", ret); 1682 goto err_irq; 1683 } 1684 } else { 1685 dev_info(wm831x->dev, "32.768kHz clock disabled, no RTC\n"); 1686 } 1687 1688 if (pdata->backlight) { 1689 /* Treat errors as non-critical */ 1690 ret = mfd_add_devices(wm831x->dev, wm831x_num, backlight_devs, 1691 ARRAY_SIZE(backlight_devs), NULL, 1692 0, NULL); 1693 if (ret < 0) 1694 dev_err(wm831x->dev, "Failed to add backlight: %d\n", 1695 ret); 1696 } 1697 1698 wm831x_otp_init(wm831x); 1699 1700 if (pdata->post_init) { 1701 ret = pdata->post_init(wm831x); 1702 if (ret != 0) { 1703 dev_err(wm831x->dev, "post_init() failed: %d\n", ret); 1704 goto err_irq; 1705 } 1706 } 1707 1708 return 0; 1709 1710 err_irq: 1711 wm831x_irq_exit(wm831x); 1712 err: 1713 mfd_remove_devices(wm831x->dev); 1714 return ret; 1715 } 1716 1717 int wm831x_device_suspend(struct wm831x *wm831x) 1718 { 1719 int reg, mask; 1720 1721 /* If the charger IRQs are a wake source then make sure we ack 1722 * them even if they're not actively being used (eg, no power 1723 * driver or no IRQ line wired up) then acknowledge the 1724 * interrupts otherwise suspend won't last very long. 1725 */ 1726 if (wm831x->charger_irq_wake) { 1727 reg = wm831x_reg_read(wm831x, WM831X_INTERRUPT_STATUS_2_MASK); 1728 1729 mask = WM831X_CHG_BATT_HOT_EINT | 1730 WM831X_CHG_BATT_COLD_EINT | 1731 WM831X_CHG_BATT_FAIL_EINT | 1732 WM831X_CHG_OV_EINT | WM831X_CHG_END_EINT | 1733 WM831X_CHG_TO_EINT | WM831X_CHG_MODE_EINT | 1734 WM831X_CHG_START_EINT; 1735 1736 /* If any of the interrupts are masked read the statuses */ 1737 if (reg & mask) 1738 reg = wm831x_reg_read(wm831x, 1739 WM831X_INTERRUPT_STATUS_2); 1740 1741 if (reg & mask) { 1742 dev_info(wm831x->dev, 1743 "Acknowledging masked charger IRQs: %x\n", 1744 reg & mask); 1745 wm831x_reg_write(wm831x, WM831X_INTERRUPT_STATUS_2, 1746 reg & mask); 1747 } 1748 } 1749 1750 return 0; 1751 } 1752 1753 void wm831x_device_shutdown(struct wm831x *wm831x) 1754 { 1755 if (wm831x->soft_shutdown) { 1756 dev_info(wm831x->dev, "Initiating shutdown...\n"); 1757 wm831x_set_bits(wm831x, WM831X_POWER_STATE, WM831X_CHIP_ON, 0); 1758 } 1759 } 1760 EXPORT_SYMBOL_GPL(wm831x_device_shutdown); 1761