2 * wm831x-core.c -- Device access for Wolfson WM831x PMICs
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/bcd.h>
18 #include <linux/delay.h>
19 #include <linux/mfd/core.h>
20 #include <linux/slab.h>
21 #include <linux/err.h>
23 #include <linux/mfd/wm831x/core.h>
24 #include <linux/mfd/wm831x/pdata.h>
25 #include <linux/mfd/wm831x/irq.h>
26 #include <linux/mfd/wm831x/auxadc.h>
27 #include <linux/mfd/wm831x/otp.h>
28 #include <linux/mfd/wm831x/pmu.h>
29 #include <linux/mfd/wm831x/regulator.h>
31 /* Current settings - values are 2*2^(reg_val/4) microamps. These are
32 * exported since they are used by multiple drivers.
34 int wm831x_isinkv_values[WM831X_ISINK_MAX_ISEL + 1] = {
92 EXPORT_SYMBOL_GPL(wm831x_isinkv_values);
94 static int wm831x_reg_locked(struct wm831x *wm831x, unsigned short reg)
100 case WM831X_WATCHDOG:
101 case WM831X_DC4_CONTROL:
102 case WM831X_ON_PIN_CONTROL:
103 case WM831X_BACKUP_CHARGER_CONTROL:
104 case WM831X_CHARGER_CONTROL_1:
105 case WM831X_CHARGER_CONTROL_2:
114 * wm831x_reg_unlock: Unlock user keyed registers
116 * The WM831x has a user key preventing writes to particularly
117 * critical registers. This function locks those registers,
118 * allowing writes to them.
120 void wm831x_reg_lock(struct wm831x *wm831x)
124 ret = wm831x_reg_write(wm831x, WM831X_SECURITY_KEY, 0);
126 dev_vdbg(wm831x->dev, "Registers locked\n");
128 mutex_lock(&wm831x->io_lock);
129 WARN_ON(wm831x->locked);
131 mutex_unlock(&wm831x->io_lock);
133 dev_err(wm831x->dev, "Failed to lock registers: %d\n", ret);
137 EXPORT_SYMBOL_GPL(wm831x_reg_lock);
140 * wm831x_reg_unlock: Unlock user keyed registers
142 * The WM831x has a user key preventing writes to particularly
143 * critical registers. This function locks those registers,
144 * preventing spurious writes.
146 int wm831x_reg_unlock(struct wm831x *wm831x)
150 /* 0x9716 is the value required to unlock the registers */
151 ret = wm831x_reg_write(wm831x, WM831X_SECURITY_KEY, 0x9716);
153 dev_vdbg(wm831x->dev, "Registers unlocked\n");
155 mutex_lock(&wm831x->io_lock);
156 WARN_ON(!wm831x->locked);
158 mutex_unlock(&wm831x->io_lock);
163 EXPORT_SYMBOL_GPL(wm831x_reg_unlock);
165 static bool wm831x_reg_readable(struct device *dev, unsigned int 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:
344 static bool wm831x_reg_writeable(struct device *dev, unsigned int reg)
346 struct wm831x *wm831x = dev_get_drvdata(dev);
348 if (wm831x_reg_locked(wm831x, 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:
481 static bool wm831x_reg_volatile(struct device *dev, unsigned int 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:
512 * wm831x_reg_read: Read a single WM831x register.
514 * @wm831x: Device to read from.
515 * @reg: Register to read.
517 int wm831x_reg_read(struct wm831x *wm831x, unsigned short reg)
522 ret = regmap_read(wm831x->regmap, reg, &val);
529 EXPORT_SYMBOL_GPL(wm831x_reg_read);
532 * wm831x_bulk_read: Read multiple WM831x registers
534 * @wm831x: Device to read from
535 * @reg: First register
536 * @count: Number of registers
537 * @buf: Buffer to fill.
539 int wm831x_bulk_read(struct wm831x *wm831x, unsigned short reg,
542 return regmap_bulk_read(wm831x->regmap, reg, buf, count);
544 EXPORT_SYMBOL_GPL(wm831x_bulk_read);
546 static int wm831x_write(struct wm831x *wm831x, unsigned short reg,
547 int bytes, void *src)
555 for (i = 0; i < bytes / 2; i++) {
556 if (wm831x_reg_locked(wm831x, reg))
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]);
570 * wm831x_reg_write: Write a single WM831x register.
572 * @wm831x: Device to write to.
573 * @reg: Register to write to.
574 * @val: Value to write.
576 int wm831x_reg_write(struct wm831x *wm831x, unsigned short reg,
581 mutex_lock(&wm831x->io_lock);
583 ret = wm831x_write(wm831x, reg, 2, &val);
585 mutex_unlock(&wm831x->io_lock);
589 EXPORT_SYMBOL_GPL(wm831x_reg_write);
592 * wm831x_set_bits: Set the value of a bitfield in a WM831x register
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)
599 int wm831x_set_bits(struct wm831x *wm831x, unsigned short reg,
600 unsigned short mask, unsigned short val)
604 mutex_lock(&wm831x->io_lock);
606 if (!wm831x_reg_locked(wm831x, reg))
607 ret = regmap_update_bits(wm831x->regmap, reg, mask, val);
611 mutex_unlock(&wm831x->io_lock);
615 EXPORT_SYMBOL_GPL(wm831x_set_bits);
617 static struct resource wm831x_dcdc1_resources[] = {
619 .start = WM831X_DC1_CONTROL_1,
620 .end = WM831X_DC1_DVS_CONTROL,
621 .flags = IORESOURCE_REG,
625 .start = WM831X_IRQ_UV_DC1,
626 .end = WM831X_IRQ_UV_DC1,
627 .flags = IORESOURCE_IRQ,
631 .start = WM831X_IRQ_HC_DC1,
632 .end = WM831X_IRQ_HC_DC1,
633 .flags = IORESOURCE_IRQ,
638 static struct resource wm831x_dcdc2_resources[] = {
640 .start = WM831X_DC2_CONTROL_1,
641 .end = WM831X_DC2_DVS_CONTROL,
642 .flags = IORESOURCE_REG,
646 .start = WM831X_IRQ_UV_DC2,
647 .end = WM831X_IRQ_UV_DC2,
648 .flags = IORESOURCE_IRQ,
652 .start = WM831X_IRQ_HC_DC2,
653 .end = WM831X_IRQ_HC_DC2,
654 .flags = IORESOURCE_IRQ,
658 static struct resource wm831x_dcdc3_resources[] = {
660 .start = WM831X_DC3_CONTROL_1,
661 .end = WM831X_DC3_SLEEP_CONTROL,
662 .flags = IORESOURCE_REG,
666 .start = WM831X_IRQ_UV_DC3,
667 .end = WM831X_IRQ_UV_DC3,
668 .flags = IORESOURCE_IRQ,
672 static struct resource wm831x_dcdc4_resources[] = {
674 .start = WM831X_DC4_CONTROL,
675 .end = WM831X_DC4_SLEEP_CONTROL,
676 .flags = IORESOURCE_REG,
680 .start = WM831X_IRQ_UV_DC4,
681 .end = WM831X_IRQ_UV_DC4,
682 .flags = IORESOURCE_IRQ,
686 static struct resource wm8320_dcdc4_buck_resources[] = {
688 .start = WM831X_DC4_CONTROL,
689 .end = WM832X_DC4_SLEEP_CONTROL,
690 .flags = IORESOURCE_REG,
694 .start = WM831X_IRQ_UV_DC4,
695 .end = WM831X_IRQ_UV_DC4,
696 .flags = IORESOURCE_IRQ,
700 static struct resource wm831x_gpio_resources[] = {
702 .start = WM831X_IRQ_GPIO_1,
703 .end = WM831X_IRQ_GPIO_16,
704 .flags = IORESOURCE_IRQ,
708 static struct resource wm831x_isink1_resources[] = {
710 .start = WM831X_CURRENT_SINK_1,
711 .end = WM831X_CURRENT_SINK_1,
712 .flags = IORESOURCE_REG,
715 .start = WM831X_IRQ_CS1,
716 .end = WM831X_IRQ_CS1,
717 .flags = IORESOURCE_IRQ,
721 static struct resource wm831x_isink2_resources[] = {
723 .start = WM831X_CURRENT_SINK_2,
724 .end = WM831X_CURRENT_SINK_2,
725 .flags = IORESOURCE_REG,
728 .start = WM831X_IRQ_CS2,
729 .end = WM831X_IRQ_CS2,
730 .flags = IORESOURCE_IRQ,
734 static struct resource wm831x_ldo1_resources[] = {
736 .start = WM831X_LDO1_CONTROL,
737 .end = WM831X_LDO1_SLEEP_CONTROL,
738 .flags = IORESOURCE_REG,
742 .start = WM831X_IRQ_UV_LDO1,
743 .end = WM831X_IRQ_UV_LDO1,
744 .flags = IORESOURCE_IRQ,
748 static struct resource wm831x_ldo2_resources[] = {
750 .start = WM831X_LDO2_CONTROL,
751 .end = WM831X_LDO2_SLEEP_CONTROL,
752 .flags = IORESOURCE_REG,
756 .start = WM831X_IRQ_UV_LDO2,
757 .end = WM831X_IRQ_UV_LDO2,
758 .flags = IORESOURCE_IRQ,
762 static struct resource wm831x_ldo3_resources[] = {
764 .start = WM831X_LDO3_CONTROL,
765 .end = WM831X_LDO3_SLEEP_CONTROL,
766 .flags = IORESOURCE_REG,
770 .start = WM831X_IRQ_UV_LDO3,
771 .end = WM831X_IRQ_UV_LDO3,
772 .flags = IORESOURCE_IRQ,
776 static struct resource wm831x_ldo4_resources[] = {
778 .start = WM831X_LDO4_CONTROL,
779 .end = WM831X_LDO4_SLEEP_CONTROL,
780 .flags = IORESOURCE_REG,
784 .start = WM831X_IRQ_UV_LDO4,
785 .end = WM831X_IRQ_UV_LDO4,
786 .flags = IORESOURCE_IRQ,
790 static struct resource wm831x_ldo5_resources[] = {
792 .start = WM831X_LDO5_CONTROL,
793 .end = WM831X_LDO5_SLEEP_CONTROL,
794 .flags = IORESOURCE_REG,
798 .start = WM831X_IRQ_UV_LDO5,
799 .end = WM831X_IRQ_UV_LDO5,
800 .flags = IORESOURCE_IRQ,
804 static struct resource wm831x_ldo6_resources[] = {
806 .start = WM831X_LDO6_CONTROL,
807 .end = WM831X_LDO6_SLEEP_CONTROL,
808 .flags = IORESOURCE_REG,
812 .start = WM831X_IRQ_UV_LDO6,
813 .end = WM831X_IRQ_UV_LDO6,
814 .flags = IORESOURCE_IRQ,
818 static struct resource wm831x_ldo7_resources[] = {
820 .start = WM831X_LDO7_CONTROL,
821 .end = WM831X_LDO7_SLEEP_CONTROL,
822 .flags = IORESOURCE_REG,
826 .start = WM831X_IRQ_UV_LDO7,
827 .end = WM831X_IRQ_UV_LDO7,
828 .flags = IORESOURCE_IRQ,
832 static struct resource wm831x_ldo8_resources[] = {
834 .start = WM831X_LDO8_CONTROL,
835 .end = WM831X_LDO8_SLEEP_CONTROL,
836 .flags = IORESOURCE_REG,
840 .start = WM831X_IRQ_UV_LDO8,
841 .end = WM831X_IRQ_UV_LDO8,
842 .flags = IORESOURCE_IRQ,
846 static struct resource wm831x_ldo9_resources[] = {
848 .start = WM831X_LDO9_CONTROL,
849 .end = WM831X_LDO9_SLEEP_CONTROL,
850 .flags = IORESOURCE_REG,
854 .start = WM831X_IRQ_UV_LDO9,
855 .end = WM831X_IRQ_UV_LDO9,
856 .flags = IORESOURCE_IRQ,
860 static struct resource wm831x_ldo10_resources[] = {
862 .start = WM831X_LDO10_CONTROL,
863 .end = WM831X_LDO10_SLEEP_CONTROL,
864 .flags = IORESOURCE_REG,
868 .start = WM831X_IRQ_UV_LDO10,
869 .end = WM831X_IRQ_UV_LDO10,
870 .flags = IORESOURCE_IRQ,
874 static struct resource wm831x_ldo11_resources[] = {
876 .start = WM831X_LDO11_ON_CONTROL,
877 .end = WM831X_LDO11_SLEEP_CONTROL,
878 .flags = IORESOURCE_REG,
882 static struct resource wm831x_on_resources[] = {
884 .start = WM831X_IRQ_ON,
885 .end = WM831X_IRQ_ON,
886 .flags = IORESOURCE_IRQ,
891 static struct resource wm831x_power_resources[] = {
894 .start = WM831X_IRQ_PPM_SYSLO,
895 .end = WM831X_IRQ_PPM_SYSLO,
896 .flags = IORESOURCE_IRQ,
900 .start = WM831X_IRQ_PPM_PWR_SRC,
901 .end = WM831X_IRQ_PPM_PWR_SRC,
902 .flags = IORESOURCE_IRQ,
906 .start = WM831X_IRQ_PPM_USB_CURR,
907 .end = WM831X_IRQ_PPM_USB_CURR,
908 .flags = IORESOURCE_IRQ,
912 .start = WM831X_IRQ_CHG_BATT_HOT,
913 .end = WM831X_IRQ_CHG_BATT_HOT,
914 .flags = IORESOURCE_IRQ,
918 .start = WM831X_IRQ_CHG_BATT_COLD,
919 .end = WM831X_IRQ_CHG_BATT_COLD,
920 .flags = IORESOURCE_IRQ,
924 .start = WM831X_IRQ_CHG_BATT_FAIL,
925 .end = WM831X_IRQ_CHG_BATT_FAIL,
926 .flags = IORESOURCE_IRQ,
930 .start = WM831X_IRQ_CHG_OV,
931 .end = WM831X_IRQ_CHG_OV,
932 .flags = IORESOURCE_IRQ,
936 .start = WM831X_IRQ_CHG_END,
937 .end = WM831X_IRQ_CHG_END,
938 .flags = IORESOURCE_IRQ,
942 .start = WM831X_IRQ_CHG_TO,
943 .end = WM831X_IRQ_CHG_TO,
944 .flags = IORESOURCE_IRQ,
948 .start = WM831X_IRQ_CHG_MODE,
949 .end = WM831X_IRQ_CHG_MODE,
950 .flags = IORESOURCE_IRQ,
954 .start = WM831X_IRQ_CHG_START,
955 .end = WM831X_IRQ_CHG_START,
956 .flags = IORESOURCE_IRQ,
960 static struct resource wm831x_rtc_resources[] = {
963 .start = WM831X_IRQ_RTC_PER,
964 .end = WM831X_IRQ_RTC_PER,
965 .flags = IORESOURCE_IRQ,
969 .start = WM831X_IRQ_RTC_ALM,
970 .end = WM831X_IRQ_RTC_ALM,
971 .flags = IORESOURCE_IRQ,
975 static struct resource wm831x_status1_resources[] = {
977 .start = WM831X_STATUS_LED_1,
978 .end = WM831X_STATUS_LED_1,
979 .flags = IORESOURCE_REG,
983 static struct resource wm831x_status2_resources[] = {
985 .start = WM831X_STATUS_LED_2,
986 .end = WM831X_STATUS_LED_2,
987 .flags = IORESOURCE_REG,
991 static struct resource wm831x_touch_resources[] = {
994 .start = WM831X_IRQ_TCHPD,
995 .end = WM831X_IRQ_TCHPD,
996 .flags = IORESOURCE_IRQ,
1000 .start = WM831X_IRQ_TCHDATA,
1001 .end = WM831X_IRQ_TCHDATA,
1002 .flags = IORESOURCE_IRQ,
1006 static struct resource wm831x_wdt_resources[] = {
1008 .start = WM831X_IRQ_WDOG_TO,
1009 .end = WM831X_IRQ_WDOG_TO,
1010 .flags = IORESOURCE_IRQ,
1014 static const struct mfd_cell wm8310_devs[] = {
1016 .name = "wm831x-backup",
1019 .name = "wm831x-buckv",
1021 .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources),
1022 .resources = wm831x_dcdc1_resources,
1025 .name = "wm831x-buckv",
1027 .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources),
1028 .resources = wm831x_dcdc2_resources,
1031 .name = "wm831x-buckp",
1033 .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources),
1034 .resources = wm831x_dcdc3_resources,
1037 .name = "wm831x-boostp",
1039 .num_resources = ARRAY_SIZE(wm831x_dcdc4_resources),
1040 .resources = wm831x_dcdc4_resources,
1043 .name = "wm831x-clk",
1046 .name = "wm831x-epe",
1050 .name = "wm831x-epe",
1054 .name = "wm831x-gpio",
1055 .num_resources = ARRAY_SIZE(wm831x_gpio_resources),
1056 .resources = wm831x_gpio_resources,
1059 .name = "wm831x-hwmon",
1062 .name = "wm831x-isink",
1064 .num_resources = ARRAY_SIZE(wm831x_isink1_resources),
1065 .resources = wm831x_isink1_resources,
1068 .name = "wm831x-isink",
1070 .num_resources = ARRAY_SIZE(wm831x_isink2_resources),
1071 .resources = wm831x_isink2_resources,
1074 .name = "wm831x-ldo",
1076 .num_resources = ARRAY_SIZE(wm831x_ldo1_resources),
1077 .resources = wm831x_ldo1_resources,
1080 .name = "wm831x-ldo",
1082 .num_resources = ARRAY_SIZE(wm831x_ldo2_resources),
1083 .resources = wm831x_ldo2_resources,
1086 .name = "wm831x-ldo",
1088 .num_resources = ARRAY_SIZE(wm831x_ldo3_resources),
1089 .resources = wm831x_ldo3_resources,
1092 .name = "wm831x-ldo",
1094 .num_resources = ARRAY_SIZE(wm831x_ldo4_resources),
1095 .resources = wm831x_ldo4_resources,
1098 .name = "wm831x-ldo",
1100 .num_resources = ARRAY_SIZE(wm831x_ldo5_resources),
1101 .resources = wm831x_ldo5_resources,
1104 .name = "wm831x-ldo",
1106 .num_resources = ARRAY_SIZE(wm831x_ldo6_resources),
1107 .resources = wm831x_ldo6_resources,
1110 .name = "wm831x-aldo",
1112 .num_resources = ARRAY_SIZE(wm831x_ldo7_resources),
1113 .resources = wm831x_ldo7_resources,
1116 .name = "wm831x-aldo",
1118 .num_resources = ARRAY_SIZE(wm831x_ldo8_resources),
1119 .resources = wm831x_ldo8_resources,
1122 .name = "wm831x-aldo",
1124 .num_resources = ARRAY_SIZE(wm831x_ldo9_resources),
1125 .resources = wm831x_ldo9_resources,
1128 .name = "wm831x-aldo",
1130 .num_resources = ARRAY_SIZE(wm831x_ldo10_resources),
1131 .resources = wm831x_ldo10_resources,
1134 .name = "wm831x-alive-ldo",
1136 .num_resources = ARRAY_SIZE(wm831x_ldo11_resources),
1137 .resources = wm831x_ldo11_resources,
1140 .name = "wm831x-on",
1141 .num_resources = ARRAY_SIZE(wm831x_on_resources),
1142 .resources = wm831x_on_resources,
1145 .name = "wm831x-power",
1146 .num_resources = ARRAY_SIZE(wm831x_power_resources),
1147 .resources = wm831x_power_resources,
1150 .name = "wm831x-status",
1152 .num_resources = ARRAY_SIZE(wm831x_status1_resources),
1153 .resources = wm831x_status1_resources,
1156 .name = "wm831x-status",
1158 .num_resources = ARRAY_SIZE(wm831x_status2_resources),
1159 .resources = wm831x_status2_resources,
1162 .name = "wm831x-watchdog",
1163 .num_resources = ARRAY_SIZE(wm831x_wdt_resources),
1164 .resources = wm831x_wdt_resources,
1168 static const struct mfd_cell wm8311_devs[] = {
1170 .name = "wm831x-backup",
1173 .name = "wm831x-buckv",
1175 .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources),
1176 .resources = wm831x_dcdc1_resources,
1179 .name = "wm831x-buckv",
1181 .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources),
1182 .resources = wm831x_dcdc2_resources,
1185 .name = "wm831x-buckp",
1187 .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources),
1188 .resources = wm831x_dcdc3_resources,
1191 .name = "wm831x-boostp",
1193 .num_resources = ARRAY_SIZE(wm831x_dcdc4_resources),
1194 .resources = wm831x_dcdc4_resources,
1197 .name = "wm831x-clk",
1200 .name = "wm831x-epe",
1204 .name = "wm831x-epe",
1208 .name = "wm831x-gpio",
1209 .num_resources = ARRAY_SIZE(wm831x_gpio_resources),
1210 .resources = wm831x_gpio_resources,
1213 .name = "wm831x-hwmon",
1216 .name = "wm831x-isink",
1218 .num_resources = ARRAY_SIZE(wm831x_isink1_resources),
1219 .resources = wm831x_isink1_resources,
1222 .name = "wm831x-isink",
1224 .num_resources = ARRAY_SIZE(wm831x_isink2_resources),
1225 .resources = wm831x_isink2_resources,
1228 .name = "wm831x-ldo",
1230 .num_resources = ARRAY_SIZE(wm831x_ldo1_resources),
1231 .resources = wm831x_ldo1_resources,
1234 .name = "wm831x-ldo",
1236 .num_resources = ARRAY_SIZE(wm831x_ldo2_resources),
1237 .resources = wm831x_ldo2_resources,
1240 .name = "wm831x-ldo",
1242 .num_resources = ARRAY_SIZE(wm831x_ldo3_resources),
1243 .resources = wm831x_ldo3_resources,
1246 .name = "wm831x-ldo",
1248 .num_resources = ARRAY_SIZE(wm831x_ldo4_resources),
1249 .resources = wm831x_ldo4_resources,
1252 .name = "wm831x-ldo",
1254 .num_resources = ARRAY_SIZE(wm831x_ldo5_resources),
1255 .resources = wm831x_ldo5_resources,
1258 .name = "wm831x-aldo",
1260 .num_resources = ARRAY_SIZE(wm831x_ldo7_resources),
1261 .resources = wm831x_ldo7_resources,
1264 .name = "wm831x-alive-ldo",
1266 .num_resources = ARRAY_SIZE(wm831x_ldo11_resources),
1267 .resources = wm831x_ldo11_resources,
1270 .name = "wm831x-on",
1271 .num_resources = ARRAY_SIZE(wm831x_on_resources),
1272 .resources = wm831x_on_resources,
1275 .name = "wm831x-power",
1276 .num_resources = ARRAY_SIZE(wm831x_power_resources),
1277 .resources = wm831x_power_resources,
1280 .name = "wm831x-status",
1282 .num_resources = ARRAY_SIZE(wm831x_status1_resources),
1283 .resources = wm831x_status1_resources,
1286 .name = "wm831x-status",
1288 .num_resources = ARRAY_SIZE(wm831x_status2_resources),
1289 .resources = wm831x_status2_resources,
1292 .name = "wm831x-watchdog",
1293 .num_resources = ARRAY_SIZE(wm831x_wdt_resources),
1294 .resources = wm831x_wdt_resources,
1298 static const struct mfd_cell wm8312_devs[] = {
1300 .name = "wm831x-backup",
1303 .name = "wm831x-buckv",
1305 .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources),
1306 .resources = wm831x_dcdc1_resources,
1309 .name = "wm831x-buckv",
1311 .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources),
1312 .resources = wm831x_dcdc2_resources,
1315 .name = "wm831x-buckp",
1317 .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources),
1318 .resources = wm831x_dcdc3_resources,
1321 .name = "wm831x-boostp",
1323 .num_resources = ARRAY_SIZE(wm831x_dcdc4_resources),
1324 .resources = wm831x_dcdc4_resources,
1327 .name = "wm831x-clk",
1330 .name = "wm831x-epe",
1334 .name = "wm831x-epe",
1338 .name = "wm831x-gpio",
1339 .num_resources = ARRAY_SIZE(wm831x_gpio_resources),
1340 .resources = wm831x_gpio_resources,
1343 .name = "wm831x-hwmon",
1346 .name = "wm831x-isink",
1348 .num_resources = ARRAY_SIZE(wm831x_isink1_resources),
1349 .resources = wm831x_isink1_resources,
1352 .name = "wm831x-isink",
1354 .num_resources = ARRAY_SIZE(wm831x_isink2_resources),
1355 .resources = wm831x_isink2_resources,
1358 .name = "wm831x-ldo",
1360 .num_resources = ARRAY_SIZE(wm831x_ldo1_resources),
1361 .resources = wm831x_ldo1_resources,
1364 .name = "wm831x-ldo",
1366 .num_resources = ARRAY_SIZE(wm831x_ldo2_resources),
1367 .resources = wm831x_ldo2_resources,
1370 .name = "wm831x-ldo",
1372 .num_resources = ARRAY_SIZE(wm831x_ldo3_resources),
1373 .resources = wm831x_ldo3_resources,
1376 .name = "wm831x-ldo",
1378 .num_resources = ARRAY_SIZE(wm831x_ldo4_resources),
1379 .resources = wm831x_ldo4_resources,
1382 .name = "wm831x-ldo",
1384 .num_resources = ARRAY_SIZE(wm831x_ldo5_resources),
1385 .resources = wm831x_ldo5_resources,
1388 .name = "wm831x-ldo",
1390 .num_resources = ARRAY_SIZE(wm831x_ldo6_resources),
1391 .resources = wm831x_ldo6_resources,
1394 .name = "wm831x-aldo",
1396 .num_resources = ARRAY_SIZE(wm831x_ldo7_resources),
1397 .resources = wm831x_ldo7_resources,
1400 .name = "wm831x-aldo",
1402 .num_resources = ARRAY_SIZE(wm831x_ldo8_resources),
1403 .resources = wm831x_ldo8_resources,
1406 .name = "wm831x-aldo",
1408 .num_resources = ARRAY_SIZE(wm831x_ldo9_resources),
1409 .resources = wm831x_ldo9_resources,
1412 .name = "wm831x-aldo",
1414 .num_resources = ARRAY_SIZE(wm831x_ldo10_resources),
1415 .resources = wm831x_ldo10_resources,
1418 .name = "wm831x-alive-ldo",
1420 .num_resources = ARRAY_SIZE(wm831x_ldo11_resources),
1421 .resources = wm831x_ldo11_resources,
1424 .name = "wm831x-on",
1425 .num_resources = ARRAY_SIZE(wm831x_on_resources),
1426 .resources = wm831x_on_resources,
1429 .name = "wm831x-power",
1430 .num_resources = ARRAY_SIZE(wm831x_power_resources),
1431 .resources = wm831x_power_resources,
1434 .name = "wm831x-status",
1436 .num_resources = ARRAY_SIZE(wm831x_status1_resources),
1437 .resources = wm831x_status1_resources,
1440 .name = "wm831x-status",
1442 .num_resources = ARRAY_SIZE(wm831x_status2_resources),
1443 .resources = wm831x_status2_resources,
1446 .name = "wm831x-watchdog",
1447 .num_resources = ARRAY_SIZE(wm831x_wdt_resources),
1448 .resources = wm831x_wdt_resources,
1452 static const struct mfd_cell wm8320_devs[] = {
1454 .name = "wm831x-backup",
1457 .name = "wm831x-buckv",
1459 .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources),
1460 .resources = wm831x_dcdc1_resources,
1463 .name = "wm831x-buckv",
1465 .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources),
1466 .resources = wm831x_dcdc2_resources,
1469 .name = "wm831x-buckp",
1471 .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources),
1472 .resources = wm831x_dcdc3_resources,
1475 .name = "wm831x-buckp",
1477 .num_resources = ARRAY_SIZE(wm8320_dcdc4_buck_resources),
1478 .resources = wm8320_dcdc4_buck_resources,
1481 .name = "wm831x-clk",
1484 .name = "wm831x-gpio",
1485 .num_resources = ARRAY_SIZE(wm831x_gpio_resources),
1486 .resources = wm831x_gpio_resources,
1489 .name = "wm831x-hwmon",
1492 .name = "wm831x-ldo",
1494 .num_resources = ARRAY_SIZE(wm831x_ldo1_resources),
1495 .resources = wm831x_ldo1_resources,
1498 .name = "wm831x-ldo",
1500 .num_resources = ARRAY_SIZE(wm831x_ldo2_resources),
1501 .resources = wm831x_ldo2_resources,
1504 .name = "wm831x-ldo",
1506 .num_resources = ARRAY_SIZE(wm831x_ldo3_resources),
1507 .resources = wm831x_ldo3_resources,
1510 .name = "wm831x-ldo",
1512 .num_resources = ARRAY_SIZE(wm831x_ldo4_resources),
1513 .resources = wm831x_ldo4_resources,
1516 .name = "wm831x-ldo",
1518 .num_resources = ARRAY_SIZE(wm831x_ldo5_resources),
1519 .resources = wm831x_ldo5_resources,
1522 .name = "wm831x-ldo",
1524 .num_resources = ARRAY_SIZE(wm831x_ldo6_resources),
1525 .resources = wm831x_ldo6_resources,
1528 .name = "wm831x-aldo",
1530 .num_resources = ARRAY_SIZE(wm831x_ldo7_resources),
1531 .resources = wm831x_ldo7_resources,
1534 .name = "wm831x-aldo",
1536 .num_resources = ARRAY_SIZE(wm831x_ldo8_resources),
1537 .resources = wm831x_ldo8_resources,
1540 .name = "wm831x-aldo",
1542 .num_resources = ARRAY_SIZE(wm831x_ldo9_resources),
1543 .resources = wm831x_ldo9_resources,
1546 .name = "wm831x-aldo",
1548 .num_resources = ARRAY_SIZE(wm831x_ldo10_resources),
1549 .resources = wm831x_ldo10_resources,
1552 .name = "wm831x-alive-ldo",
1554 .num_resources = ARRAY_SIZE(wm831x_ldo11_resources),
1555 .resources = wm831x_ldo11_resources,
1558 .name = "wm831x-on",
1559 .num_resources = ARRAY_SIZE(wm831x_on_resources),
1560 .resources = wm831x_on_resources,
1563 .name = "wm831x-status",
1565 .num_resources = ARRAY_SIZE(wm831x_status1_resources),
1566 .resources = wm831x_status1_resources,
1569 .name = "wm831x-status",
1571 .num_resources = ARRAY_SIZE(wm831x_status2_resources),
1572 .resources = wm831x_status2_resources,
1575 .name = "wm831x-watchdog",
1576 .num_resources = ARRAY_SIZE(wm831x_wdt_resources),
1577 .resources = wm831x_wdt_resources,
1581 static const struct mfd_cell touch_devs[] = {
1583 .name = "wm831x-touch",
1584 .num_resources = ARRAY_SIZE(wm831x_touch_resources),
1585 .resources = wm831x_touch_resources,
1589 static const struct mfd_cell rtc_devs[] = {
1591 .name = "wm831x-rtc",
1592 .num_resources = ARRAY_SIZE(wm831x_rtc_resources),
1593 .resources = wm831x_rtc_resources,
1597 static const struct mfd_cell backlight_devs[] = {
1599 .name = "wm831x-backlight",
1603 struct regmap_config wm831x_regmap_config = {
1607 .cache_type = REGCACHE_RBTREE,
1609 .max_register = WM831X_DBE_CHECK_DATA,
1610 .readable_reg = wm831x_reg_readable,
1611 .writeable_reg = wm831x_reg_writeable,
1612 .volatile_reg = wm831x_reg_volatile,
1614 EXPORT_SYMBOL_GPL(wm831x_regmap_config);
1617 * Instantiate the generic non-control parts of the device.
1619 int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq)
1621 struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev);
1622 int rev, wm831x_num;
1623 enum wm831x_parent parent;
1626 mutex_init(&wm831x->io_lock);
1627 mutex_init(&wm831x->key_lock);
1628 dev_set_drvdata(wm831x->dev, wm831x);
1631 wm831x->soft_shutdown = pdata->soft_shutdown;
1633 ret = wm831x_reg_read(wm831x, WM831X_PARENT_ID);
1635 dev_err(wm831x->dev, "Failed to read parent ID: %d\n", ret);
1643 dev_err(wm831x->dev, "Device is not a WM831x: ID %x\n", ret);
1648 ret = wm831x_reg_read(wm831x, WM831X_REVISION);
1650 dev_err(wm831x->dev, "Failed to read revision: %d\n", ret);
1653 rev = (ret & WM831X_PARENT_REV_MASK) >> WM831X_PARENT_REV_SHIFT;
1655 ret = wm831x_reg_read(wm831x, WM831X_RESET_ID);
1657 dev_err(wm831x->dev, "Failed to read device ID: %d\n", ret);
1661 /* Some engineering samples do not have the ID set, rely on
1662 * the device being registered correctly.
1665 dev_info(wm831x->dev, "Device is an engineering sample\n");
1672 wm831x->num_gpio = 16;
1673 wm831x->charger_irq_wake = 1;
1675 wm831x->has_gpio_ena = 1;
1676 wm831x->has_cs_sts = 1;
1679 dev_info(wm831x->dev, "WM8310 revision %c\n", 'A' + rev);
1684 wm831x->num_gpio = 16;
1685 wm831x->charger_irq_wake = 1;
1687 wm831x->has_gpio_ena = 1;
1688 wm831x->has_cs_sts = 1;
1691 dev_info(wm831x->dev, "WM8311 revision %c\n", 'A' + rev);
1696 wm831x->num_gpio = 16;
1697 wm831x->charger_irq_wake = 1;
1699 wm831x->has_gpio_ena = 1;
1700 wm831x->has_cs_sts = 1;
1703 dev_info(wm831x->dev, "WM8312 revision %c\n", 'A' + rev);
1708 wm831x->num_gpio = 12;
1709 dev_info(wm831x->dev, "WM8320 revision %c\n", 'A' + rev);
1714 wm831x->num_gpio = 12;
1715 dev_info(wm831x->dev, "WM8321 revision %c\n", 'A' + rev);
1720 wm831x->num_gpio = 12;
1721 dev_info(wm831x->dev, "WM8325 revision %c\n", 'A' + rev);
1726 wm831x->num_gpio = 12;
1727 dev_info(wm831x->dev, "WM8326 revision %c\n", 'A' + rev);
1731 dev_err(wm831x->dev, "Unknown WM831x device %04x\n", ret);
1736 /* This will need revisiting in future but is OK for all
1740 dev_warn(wm831x->dev, "Device was registered as a WM%lx\n",
1743 /* Bootstrap the user key */
1744 ret = wm831x_reg_read(wm831x, WM831X_SECURITY_KEY);
1746 dev_err(wm831x->dev, "Failed to read security key: %d\n", ret);
1750 dev_warn(wm831x->dev, "Security key had non-zero value %x\n",
1752 wm831x_reg_write(wm831x, WM831X_SECURITY_KEY, 0);
1756 if (pdata && pdata->pre_init) {
1757 ret = pdata->pre_init(wm831x);
1759 dev_err(wm831x->dev, "pre_init() failed: %d\n", ret);
1765 for (i = 0; i < ARRAY_SIZE(pdata->gpio_defaults); i++) {
1766 if (!pdata->gpio_defaults[i])
1769 wm831x_reg_write(wm831x,
1770 WM831X_GPIO1_CONTROL + i,
1771 pdata->gpio_defaults[i] & 0xffff);
1775 /* Multiply by 10 as we have many subdevices of the same type */
1776 if (pdata && pdata->wm831x_num)
1777 wm831x_num = pdata->wm831x_num * 10;
1781 ret = wm831x_irq_init(wm831x, irq);
1785 wm831x_auxadc_init(wm831x);
1787 /* The core device is up, instantiate the subdevices. */
1790 ret = mfd_add_devices(wm831x->dev, wm831x_num,
1791 wm8310_devs, ARRAY_SIZE(wm8310_devs),
1796 ret = mfd_add_devices(wm831x->dev, wm831x_num,
1797 wm8311_devs, ARRAY_SIZE(wm8311_devs),
1799 if (!pdata || !pdata->disable_touch)
1800 mfd_add_devices(wm831x->dev, wm831x_num,
1801 touch_devs, ARRAY_SIZE(touch_devs),
1806 ret = mfd_add_devices(wm831x->dev, wm831x_num,
1807 wm8312_devs, ARRAY_SIZE(wm8312_devs),
1809 if (!pdata || !pdata->disable_touch)
1810 mfd_add_devices(wm831x->dev, wm831x_num,
1811 touch_devs, ARRAY_SIZE(touch_devs),
1819 ret = mfd_add_devices(wm831x->dev, wm831x_num,
1820 wm8320_devs, ARRAY_SIZE(wm8320_devs),
1825 /* If this happens the bus probe function is buggy */
1830 dev_err(wm831x->dev, "Failed to add children\n");
1834 /* The RTC can only be used if the 32.768kHz crystal is
1835 * enabled; this can't be controlled by software at runtime.
1837 ret = wm831x_reg_read(wm831x, WM831X_CLOCK_CONTROL_2);
1839 dev_err(wm831x->dev, "Failed to read clock status: %d\n", ret);
1843 if (ret & WM831X_XTAL_ENA) {
1844 ret = mfd_add_devices(wm831x->dev, wm831x_num,
1845 rtc_devs, ARRAY_SIZE(rtc_devs),
1848 dev_err(wm831x->dev, "Failed to add RTC: %d\n", ret);
1852 dev_info(wm831x->dev, "32.768kHz clock disabled, no RTC\n");
1855 if (pdata && pdata->backlight) {
1856 /* Treat errors as non-critical */
1857 ret = mfd_add_devices(wm831x->dev, wm831x_num, backlight_devs,
1858 ARRAY_SIZE(backlight_devs), NULL,
1861 dev_err(wm831x->dev, "Failed to add backlight: %d\n",
1865 wm831x_otp_init(wm831x);
1867 if (pdata && pdata->post_init) {
1868 ret = pdata->post_init(wm831x);
1870 dev_err(wm831x->dev, "post_init() failed: %d\n", ret);
1878 wm831x_irq_exit(wm831x);
1880 mfd_remove_devices(wm831x->dev);
1884 void wm831x_device_exit(struct wm831x *wm831x)
1886 wm831x_otp_exit(wm831x);
1887 mfd_remove_devices(wm831x->dev);
1888 free_irq(wm831x_irq(wm831x, WM831X_IRQ_AUXADC_DATA), wm831x);
1889 wm831x_irq_exit(wm831x);
1892 int wm831x_device_suspend(struct wm831x *wm831x)
1896 /* If the charger IRQs are a wake source then make sure we ack
1897 * them even if they're not actively being used (eg, no power
1898 * driver or no IRQ line wired up) then acknowledge the
1899 * interrupts otherwise suspend won't last very long.
1901 if (wm831x->charger_irq_wake) {
1902 reg = wm831x_reg_read(wm831x, WM831X_INTERRUPT_STATUS_2_MASK);
1904 mask = WM831X_CHG_BATT_HOT_EINT |
1905 WM831X_CHG_BATT_COLD_EINT |
1906 WM831X_CHG_BATT_FAIL_EINT |
1907 WM831X_CHG_OV_EINT | WM831X_CHG_END_EINT |
1908 WM831X_CHG_TO_EINT | WM831X_CHG_MODE_EINT |
1909 WM831X_CHG_START_EINT;
1911 /* If any of the interrupts are masked read the statuses */
1913 reg = wm831x_reg_read(wm831x,
1914 WM831X_INTERRUPT_STATUS_2);
1917 dev_info(wm831x->dev,
1918 "Acknowledging masked charger IRQs: %x\n",
1920 wm831x_reg_write(wm831x, WM831X_INTERRUPT_STATUS_2,
1928 void wm831x_device_shutdown(struct wm831x *wm831x)
1930 if (wm831x->soft_shutdown) {
1931 dev_info(wm831x->dev, "Initiating shutdown...\n");
1932 wm831x_set_bits(wm831x, WM831X_POWER_STATE, WM831X_CHIP_ON, 0);
1935 EXPORT_SYMBOL_GPL(wm831x_device_shutdown);
1937 MODULE_DESCRIPTION("Core support for the WM831X AudioPlus PMIC");
1938 MODULE_LICENSE("GPL");
1939 MODULE_AUTHOR("Mark Brown");