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>
22 #include <linux/mfd/wm831x/core.h>
23 #include <linux/mfd/wm831x/pdata.h>
24 #include <linux/mfd/wm831x/irq.h>
25 #include <linux/mfd/wm831x/auxadc.h>
26 #include <linux/mfd/wm831x/otp.h>
27 #include <linux/mfd/wm831x/regulator.h>
29 /* Current settings - values are 2*2^(reg_val/4) microamps. These are
30 * exported since they are used by multiple drivers.
32 int wm831x_isinkv_values
[WM831X_ISINK_MAX_ISEL
+ 1] = {
90 EXPORT_SYMBOL_GPL(wm831x_isinkv_values
);
92 static int wm831x_reg_locked(struct wm831x
*wm831x
, unsigned short reg
)
99 case WM831X_DC4_CONTROL
:
100 case WM831X_ON_PIN_CONTROL
:
101 case WM831X_BACKUP_CHARGER_CONTROL
:
102 case WM831X_CHARGER_CONTROL_1
:
103 case WM831X_CHARGER_CONTROL_2
:
112 * wm831x_reg_unlock: Unlock user keyed registers
114 * The WM831x has a user key preventing writes to particularly
115 * critical registers. This function locks those registers,
116 * allowing writes to them.
118 void wm831x_reg_lock(struct wm831x
*wm831x
)
122 ret
= wm831x_reg_write(wm831x
, WM831X_SECURITY_KEY
, 0);
124 dev_vdbg(wm831x
->dev
, "Registers locked\n");
126 mutex_lock(&wm831x
->io_lock
);
127 WARN_ON(wm831x
->locked
);
129 mutex_unlock(&wm831x
->io_lock
);
131 dev_err(wm831x
->dev
, "Failed to lock registers: %d\n", ret
);
135 EXPORT_SYMBOL_GPL(wm831x_reg_lock
);
138 * wm831x_reg_unlock: Unlock user keyed registers
140 * The WM831x has a user key preventing writes to particularly
141 * critical registers. This function locks those registers,
142 * preventing spurious writes.
144 int wm831x_reg_unlock(struct wm831x
*wm831x
)
148 /* 0x9716 is the value required to unlock the registers */
149 ret
= wm831x_reg_write(wm831x
, WM831X_SECURITY_KEY
, 0x9716);
151 dev_vdbg(wm831x
->dev
, "Registers unlocked\n");
153 mutex_lock(&wm831x
->io_lock
);
154 WARN_ON(!wm831x
->locked
);
156 mutex_unlock(&wm831x
->io_lock
);
161 EXPORT_SYMBOL_GPL(wm831x_reg_unlock
);
163 static int wm831x_read(struct wm831x
*wm831x
, unsigned short reg
,
164 int bytes
, void *dest
)
172 ret
= wm831x
->read_dev(wm831x
, reg
, bytes
, dest
);
176 for (i
= 0; i
< bytes
/ 2; i
++) {
177 buf
[i
] = be16_to_cpu(buf
[i
]);
179 dev_vdbg(wm831x
->dev
, "Read %04x from R%d(0x%x)\n",
180 buf
[i
], reg
+ i
, reg
+ i
);
187 * wm831x_reg_read: Read a single WM831x register.
189 * @wm831x: Device to read from.
190 * @reg: Register to read.
192 int wm831x_reg_read(struct wm831x
*wm831x
, unsigned short reg
)
197 mutex_lock(&wm831x
->io_lock
);
199 ret
= wm831x_read(wm831x
, reg
, 2, &val
);
201 mutex_unlock(&wm831x
->io_lock
);
208 EXPORT_SYMBOL_GPL(wm831x_reg_read
);
211 * wm831x_bulk_read: Read multiple WM831x registers
213 * @wm831x: Device to read from
214 * @reg: First register
215 * @count: Number of registers
216 * @buf: Buffer to fill.
218 int wm831x_bulk_read(struct wm831x
*wm831x
, unsigned short reg
,
223 mutex_lock(&wm831x
->io_lock
);
225 ret
= wm831x_read(wm831x
, reg
, count
* 2, buf
);
227 mutex_unlock(&wm831x
->io_lock
);
231 EXPORT_SYMBOL_GPL(wm831x_bulk_read
);
233 static int wm831x_write(struct wm831x
*wm831x
, unsigned short reg
,
234 int bytes
, void *src
)
242 for (i
= 0; i
< bytes
/ 2; i
++) {
243 if (wm831x_reg_locked(wm831x
, reg
))
246 dev_vdbg(wm831x
->dev
, "Write %04x to R%d(0x%x)\n",
247 buf
[i
], reg
+ i
, reg
+ i
);
249 buf
[i
] = cpu_to_be16(buf
[i
]);
252 return wm831x
->write_dev(wm831x
, reg
, bytes
, src
);
256 * wm831x_reg_write: Write a single WM831x register.
258 * @wm831x: Device to write to.
259 * @reg: Register to write to.
260 * @val: Value to write.
262 int wm831x_reg_write(struct wm831x
*wm831x
, unsigned short reg
,
267 mutex_lock(&wm831x
->io_lock
);
269 ret
= wm831x_write(wm831x
, reg
, 2, &val
);
271 mutex_unlock(&wm831x
->io_lock
);
275 EXPORT_SYMBOL_GPL(wm831x_reg_write
);
278 * wm831x_set_bits: Set the value of a bitfield in a WM831x register
280 * @wm831x: Device to write to.
281 * @reg: Register to write to.
282 * @mask: Mask of bits to set.
283 * @val: Value to set (unshifted)
285 int wm831x_set_bits(struct wm831x
*wm831x
, unsigned short reg
,
286 unsigned short mask
, unsigned short val
)
291 mutex_lock(&wm831x
->io_lock
);
293 ret
= wm831x_read(wm831x
, reg
, 2, &r
);
300 ret
= wm831x_write(wm831x
, reg
, 2, &r
);
303 mutex_unlock(&wm831x
->io_lock
);
307 EXPORT_SYMBOL_GPL(wm831x_set_bits
);
310 * wm831x_auxadc_read: Read a value from the WM831x AUXADC
312 * @wm831x: Device to read from.
313 * @input: AUXADC input to read.
315 int wm831x_auxadc_read(struct wm831x
*wm831x
, enum wm831x_auxadc input
)
317 int ret
, src
, irq_masked
, timeout
;
319 /* Are we using the interrupt? */
320 irq_masked
= wm831x_reg_read(wm831x
, WM831X_INTERRUPT_STATUS_1_MASK
);
321 irq_masked
&= WM831X_AUXADC_DATA_EINT
;
323 mutex_lock(&wm831x
->auxadc_lock
);
325 ret
= wm831x_set_bits(wm831x
, WM831X_AUXADC_CONTROL
,
326 WM831X_AUX_ENA
, WM831X_AUX_ENA
);
328 dev_err(wm831x
->dev
, "Failed to enable AUXADC: %d\n", ret
);
332 /* We force a single source at present */
334 ret
= wm831x_reg_write(wm831x
, WM831X_AUXADC_SOURCE
,
337 dev_err(wm831x
->dev
, "Failed to set AUXADC source: %d\n", ret
);
341 /* Clear any notification from a very late arriving interrupt */
342 try_wait_for_completion(&wm831x
->auxadc_done
);
344 ret
= wm831x_set_bits(wm831x
, WM831X_AUXADC_CONTROL
,
345 WM831X_AUX_CVT_ENA
, WM831X_AUX_CVT_ENA
);
347 dev_err(wm831x
->dev
, "Failed to start AUXADC: %d\n", ret
);
352 /* If we're not using interrupts then poll the
353 * interrupt status register */
358 ret
= wm831x_reg_read(wm831x
,
359 WM831X_INTERRUPT_STATUS_1
);
362 "ISR 1 read failed: %d\n", ret
);
366 /* Did it complete? */
367 if (ret
& WM831X_AUXADC_DATA_EINT
) {
368 wm831x_reg_write(wm831x
,
369 WM831X_INTERRUPT_STATUS_1
,
370 WM831X_AUXADC_DATA_EINT
);
374 "AUXADC conversion timeout\n");
380 /* If we are using interrupts then wait for the
381 * interrupt to complete. Use an extremely long
382 * timeout to handle situations with heavy load where
383 * the notification of the interrupt may be delayed by
384 * threaded IRQ handling. */
385 if (!wait_for_completion_timeout(&wm831x
->auxadc_done
,
386 msecs_to_jiffies(500))) {
387 dev_err(wm831x
->dev
, "Timed out waiting for AUXADC\n");
393 ret
= wm831x_reg_read(wm831x
, WM831X_AUXADC_DATA
);
395 dev_err(wm831x
->dev
, "Failed to read AUXADC data: %d\n", ret
);
397 src
= ((ret
& WM831X_AUX_DATA_SRC_MASK
)
398 >> WM831X_AUX_DATA_SRC_SHIFT
) - 1;
401 src
= WM831X_AUX_CAL
;
404 dev_err(wm831x
->dev
, "Data from source %d not %d\n",
408 ret
&= WM831X_AUX_DATA_MASK
;
413 wm831x_set_bits(wm831x
, WM831X_AUXADC_CONTROL
, WM831X_AUX_ENA
, 0);
415 mutex_unlock(&wm831x
->auxadc_lock
);
418 EXPORT_SYMBOL_GPL(wm831x_auxadc_read
);
420 static irqreturn_t
wm831x_auxadc_irq(int irq
, void *irq_data
)
422 struct wm831x
*wm831x
= irq_data
;
424 complete(&wm831x
->auxadc_done
);
430 * wm831x_auxadc_read_uv: Read a voltage from the WM831x AUXADC
432 * @wm831x: Device to read from.
433 * @input: AUXADC input to read.
435 int wm831x_auxadc_read_uv(struct wm831x
*wm831x
, enum wm831x_auxadc input
)
439 ret
= wm831x_auxadc_read(wm831x
, input
);
447 EXPORT_SYMBOL_GPL(wm831x_auxadc_read_uv
);
449 static struct resource wm831x_dcdc1_resources
[] = {
451 .start
= WM831X_DC1_CONTROL_1
,
452 .end
= WM831X_DC1_DVS_CONTROL
,
453 .flags
= IORESOURCE_IO
,
457 .start
= WM831X_IRQ_UV_DC1
,
458 .end
= WM831X_IRQ_UV_DC1
,
459 .flags
= IORESOURCE_IRQ
,
463 .start
= WM831X_IRQ_HC_DC1
,
464 .end
= WM831X_IRQ_HC_DC1
,
465 .flags
= IORESOURCE_IRQ
,
470 static struct resource wm831x_dcdc2_resources
[] = {
472 .start
= WM831X_DC2_CONTROL_1
,
473 .end
= WM831X_DC2_DVS_CONTROL
,
474 .flags
= IORESOURCE_IO
,
478 .start
= WM831X_IRQ_UV_DC2
,
479 .end
= WM831X_IRQ_UV_DC2
,
480 .flags
= IORESOURCE_IRQ
,
484 .start
= WM831X_IRQ_HC_DC2
,
485 .end
= WM831X_IRQ_HC_DC2
,
486 .flags
= IORESOURCE_IRQ
,
490 static struct resource wm831x_dcdc3_resources
[] = {
492 .start
= WM831X_DC3_CONTROL_1
,
493 .end
= WM831X_DC3_SLEEP_CONTROL
,
494 .flags
= IORESOURCE_IO
,
498 .start
= WM831X_IRQ_UV_DC3
,
499 .end
= WM831X_IRQ_UV_DC3
,
500 .flags
= IORESOURCE_IRQ
,
504 static struct resource wm831x_dcdc4_resources
[] = {
506 .start
= WM831X_DC4_CONTROL
,
507 .end
= WM831X_DC4_SLEEP_CONTROL
,
508 .flags
= IORESOURCE_IO
,
512 .start
= WM831X_IRQ_UV_DC4
,
513 .end
= WM831X_IRQ_UV_DC4
,
514 .flags
= IORESOURCE_IRQ
,
518 static struct resource wm8320_dcdc4_buck_resources
[] = {
520 .start
= WM831X_DC4_CONTROL
,
521 .end
= WM832X_DC4_SLEEP_CONTROL
,
522 .flags
= IORESOURCE_IO
,
526 .start
= WM831X_IRQ_UV_DC4
,
527 .end
= WM831X_IRQ_UV_DC4
,
528 .flags
= IORESOURCE_IRQ
,
532 static struct resource wm831x_gpio_resources
[] = {
534 .start
= WM831X_IRQ_GPIO_1
,
535 .end
= WM831X_IRQ_GPIO_16
,
536 .flags
= IORESOURCE_IRQ
,
540 static struct resource wm831x_isink1_resources
[] = {
542 .start
= WM831X_CURRENT_SINK_1
,
543 .end
= WM831X_CURRENT_SINK_1
,
544 .flags
= IORESOURCE_IO
,
547 .start
= WM831X_IRQ_CS1
,
548 .end
= WM831X_IRQ_CS1
,
549 .flags
= IORESOURCE_IRQ
,
553 static struct resource wm831x_isink2_resources
[] = {
555 .start
= WM831X_CURRENT_SINK_2
,
556 .end
= WM831X_CURRENT_SINK_2
,
557 .flags
= IORESOURCE_IO
,
560 .start
= WM831X_IRQ_CS2
,
561 .end
= WM831X_IRQ_CS2
,
562 .flags
= IORESOURCE_IRQ
,
566 static struct resource wm831x_ldo1_resources
[] = {
568 .start
= WM831X_LDO1_CONTROL
,
569 .end
= WM831X_LDO1_SLEEP_CONTROL
,
570 .flags
= IORESOURCE_IO
,
574 .start
= WM831X_IRQ_UV_LDO1
,
575 .end
= WM831X_IRQ_UV_LDO1
,
576 .flags
= IORESOURCE_IRQ
,
580 static struct resource wm831x_ldo2_resources
[] = {
582 .start
= WM831X_LDO2_CONTROL
,
583 .end
= WM831X_LDO2_SLEEP_CONTROL
,
584 .flags
= IORESOURCE_IO
,
588 .start
= WM831X_IRQ_UV_LDO2
,
589 .end
= WM831X_IRQ_UV_LDO2
,
590 .flags
= IORESOURCE_IRQ
,
594 static struct resource wm831x_ldo3_resources
[] = {
596 .start
= WM831X_LDO3_CONTROL
,
597 .end
= WM831X_LDO3_SLEEP_CONTROL
,
598 .flags
= IORESOURCE_IO
,
602 .start
= WM831X_IRQ_UV_LDO3
,
603 .end
= WM831X_IRQ_UV_LDO3
,
604 .flags
= IORESOURCE_IRQ
,
608 static struct resource wm831x_ldo4_resources
[] = {
610 .start
= WM831X_LDO4_CONTROL
,
611 .end
= WM831X_LDO4_SLEEP_CONTROL
,
612 .flags
= IORESOURCE_IO
,
616 .start
= WM831X_IRQ_UV_LDO4
,
617 .end
= WM831X_IRQ_UV_LDO4
,
618 .flags
= IORESOURCE_IRQ
,
622 static struct resource wm831x_ldo5_resources
[] = {
624 .start
= WM831X_LDO5_CONTROL
,
625 .end
= WM831X_LDO5_SLEEP_CONTROL
,
626 .flags
= IORESOURCE_IO
,
630 .start
= WM831X_IRQ_UV_LDO5
,
631 .end
= WM831X_IRQ_UV_LDO5
,
632 .flags
= IORESOURCE_IRQ
,
636 static struct resource wm831x_ldo6_resources
[] = {
638 .start
= WM831X_LDO6_CONTROL
,
639 .end
= WM831X_LDO6_SLEEP_CONTROL
,
640 .flags
= IORESOURCE_IO
,
644 .start
= WM831X_IRQ_UV_LDO6
,
645 .end
= WM831X_IRQ_UV_LDO6
,
646 .flags
= IORESOURCE_IRQ
,
650 static struct resource wm831x_ldo7_resources
[] = {
652 .start
= WM831X_LDO7_CONTROL
,
653 .end
= WM831X_LDO7_SLEEP_CONTROL
,
654 .flags
= IORESOURCE_IO
,
658 .start
= WM831X_IRQ_UV_LDO7
,
659 .end
= WM831X_IRQ_UV_LDO7
,
660 .flags
= IORESOURCE_IRQ
,
664 static struct resource wm831x_ldo8_resources
[] = {
666 .start
= WM831X_LDO8_CONTROL
,
667 .end
= WM831X_LDO8_SLEEP_CONTROL
,
668 .flags
= IORESOURCE_IO
,
672 .start
= WM831X_IRQ_UV_LDO8
,
673 .end
= WM831X_IRQ_UV_LDO8
,
674 .flags
= IORESOURCE_IRQ
,
678 static struct resource wm831x_ldo9_resources
[] = {
680 .start
= WM831X_LDO9_CONTROL
,
681 .end
= WM831X_LDO9_SLEEP_CONTROL
,
682 .flags
= IORESOURCE_IO
,
686 .start
= WM831X_IRQ_UV_LDO9
,
687 .end
= WM831X_IRQ_UV_LDO9
,
688 .flags
= IORESOURCE_IRQ
,
692 static struct resource wm831x_ldo10_resources
[] = {
694 .start
= WM831X_LDO10_CONTROL
,
695 .end
= WM831X_LDO10_SLEEP_CONTROL
,
696 .flags
= IORESOURCE_IO
,
700 .start
= WM831X_IRQ_UV_LDO10
,
701 .end
= WM831X_IRQ_UV_LDO10
,
702 .flags
= IORESOURCE_IRQ
,
706 static struct resource wm831x_ldo11_resources
[] = {
708 .start
= WM831X_LDO11_ON_CONTROL
,
709 .end
= WM831X_LDO11_SLEEP_CONTROL
,
710 .flags
= IORESOURCE_IO
,
714 static struct resource wm831x_on_resources
[] = {
716 .start
= WM831X_IRQ_ON
,
717 .end
= WM831X_IRQ_ON
,
718 .flags
= IORESOURCE_IRQ
,
723 static struct resource wm831x_power_resources
[] = {
726 .start
= WM831X_IRQ_PPM_SYSLO
,
727 .end
= WM831X_IRQ_PPM_SYSLO
,
728 .flags
= IORESOURCE_IRQ
,
732 .start
= WM831X_IRQ_PPM_PWR_SRC
,
733 .end
= WM831X_IRQ_PPM_PWR_SRC
,
734 .flags
= IORESOURCE_IRQ
,
738 .start
= WM831X_IRQ_PPM_USB_CURR
,
739 .end
= WM831X_IRQ_PPM_USB_CURR
,
740 .flags
= IORESOURCE_IRQ
,
744 .start
= WM831X_IRQ_CHG_BATT_HOT
,
745 .end
= WM831X_IRQ_CHG_BATT_HOT
,
746 .flags
= IORESOURCE_IRQ
,
750 .start
= WM831X_IRQ_CHG_BATT_COLD
,
751 .end
= WM831X_IRQ_CHG_BATT_COLD
,
752 .flags
= IORESOURCE_IRQ
,
756 .start
= WM831X_IRQ_CHG_BATT_FAIL
,
757 .end
= WM831X_IRQ_CHG_BATT_FAIL
,
758 .flags
= IORESOURCE_IRQ
,
762 .start
= WM831X_IRQ_CHG_OV
,
763 .end
= WM831X_IRQ_CHG_OV
,
764 .flags
= IORESOURCE_IRQ
,
768 .start
= WM831X_IRQ_CHG_END
,
769 .end
= WM831X_IRQ_CHG_END
,
770 .flags
= IORESOURCE_IRQ
,
774 .start
= WM831X_IRQ_CHG_TO
,
775 .end
= WM831X_IRQ_CHG_TO
,
776 .flags
= IORESOURCE_IRQ
,
780 .start
= WM831X_IRQ_CHG_MODE
,
781 .end
= WM831X_IRQ_CHG_MODE
,
782 .flags
= IORESOURCE_IRQ
,
786 .start
= WM831X_IRQ_CHG_START
,
787 .end
= WM831X_IRQ_CHG_START
,
788 .flags
= IORESOURCE_IRQ
,
792 static struct resource wm831x_rtc_resources
[] = {
795 .start
= WM831X_IRQ_RTC_PER
,
796 .end
= WM831X_IRQ_RTC_PER
,
797 .flags
= IORESOURCE_IRQ
,
801 .start
= WM831X_IRQ_RTC_ALM
,
802 .end
= WM831X_IRQ_RTC_ALM
,
803 .flags
= IORESOURCE_IRQ
,
807 static struct resource wm831x_status1_resources
[] = {
809 .start
= WM831X_STATUS_LED_1
,
810 .end
= WM831X_STATUS_LED_1
,
811 .flags
= IORESOURCE_IO
,
815 static struct resource wm831x_status2_resources
[] = {
817 .start
= WM831X_STATUS_LED_2
,
818 .end
= WM831X_STATUS_LED_2
,
819 .flags
= IORESOURCE_IO
,
823 static struct resource wm831x_touch_resources
[] = {
826 .start
= WM831X_IRQ_TCHPD
,
827 .end
= WM831X_IRQ_TCHPD
,
828 .flags
= IORESOURCE_IRQ
,
832 .start
= WM831X_IRQ_TCHDATA
,
833 .end
= WM831X_IRQ_TCHDATA
,
834 .flags
= IORESOURCE_IRQ
,
838 static struct resource wm831x_wdt_resources
[] = {
840 .start
= WM831X_IRQ_WDOG_TO
,
841 .end
= WM831X_IRQ_WDOG_TO
,
842 .flags
= IORESOURCE_IRQ
,
846 static struct mfd_cell wm8310_devs
[] = {
848 .name
= "wm831x-backup",
851 .name
= "wm831x-buckv",
853 .num_resources
= ARRAY_SIZE(wm831x_dcdc1_resources
),
854 .resources
= wm831x_dcdc1_resources
,
857 .name
= "wm831x-buckv",
859 .num_resources
= ARRAY_SIZE(wm831x_dcdc2_resources
),
860 .resources
= wm831x_dcdc2_resources
,
863 .name
= "wm831x-buckp",
865 .num_resources
= ARRAY_SIZE(wm831x_dcdc3_resources
),
866 .resources
= wm831x_dcdc3_resources
,
869 .name
= "wm831x-boostp",
871 .num_resources
= ARRAY_SIZE(wm831x_dcdc4_resources
),
872 .resources
= wm831x_dcdc4_resources
,
875 .name
= "wm831x-epe",
879 .name
= "wm831x-epe",
883 .name
= "wm831x-gpio",
884 .num_resources
= ARRAY_SIZE(wm831x_gpio_resources
),
885 .resources
= wm831x_gpio_resources
,
888 .name
= "wm831x-hwmon",
891 .name
= "wm831x-isink",
893 .num_resources
= ARRAY_SIZE(wm831x_isink1_resources
),
894 .resources
= wm831x_isink1_resources
,
897 .name
= "wm831x-isink",
899 .num_resources
= ARRAY_SIZE(wm831x_isink2_resources
),
900 .resources
= wm831x_isink2_resources
,
903 .name
= "wm831x-ldo",
905 .num_resources
= ARRAY_SIZE(wm831x_ldo1_resources
),
906 .resources
= wm831x_ldo1_resources
,
909 .name
= "wm831x-ldo",
911 .num_resources
= ARRAY_SIZE(wm831x_ldo2_resources
),
912 .resources
= wm831x_ldo2_resources
,
915 .name
= "wm831x-ldo",
917 .num_resources
= ARRAY_SIZE(wm831x_ldo3_resources
),
918 .resources
= wm831x_ldo3_resources
,
921 .name
= "wm831x-ldo",
923 .num_resources
= ARRAY_SIZE(wm831x_ldo4_resources
),
924 .resources
= wm831x_ldo4_resources
,
927 .name
= "wm831x-ldo",
929 .num_resources
= ARRAY_SIZE(wm831x_ldo5_resources
),
930 .resources
= wm831x_ldo5_resources
,
933 .name
= "wm831x-ldo",
935 .num_resources
= ARRAY_SIZE(wm831x_ldo6_resources
),
936 .resources
= wm831x_ldo6_resources
,
939 .name
= "wm831x-aldo",
941 .num_resources
= ARRAY_SIZE(wm831x_ldo7_resources
),
942 .resources
= wm831x_ldo7_resources
,
945 .name
= "wm831x-aldo",
947 .num_resources
= ARRAY_SIZE(wm831x_ldo8_resources
),
948 .resources
= wm831x_ldo8_resources
,
951 .name
= "wm831x-aldo",
953 .num_resources
= ARRAY_SIZE(wm831x_ldo9_resources
),
954 .resources
= wm831x_ldo9_resources
,
957 .name
= "wm831x-aldo",
959 .num_resources
= ARRAY_SIZE(wm831x_ldo10_resources
),
960 .resources
= wm831x_ldo10_resources
,
963 .name
= "wm831x-alive-ldo",
965 .num_resources
= ARRAY_SIZE(wm831x_ldo11_resources
),
966 .resources
= wm831x_ldo11_resources
,
970 .num_resources
= ARRAY_SIZE(wm831x_on_resources
),
971 .resources
= wm831x_on_resources
,
974 .name
= "wm831x-power",
975 .num_resources
= ARRAY_SIZE(wm831x_power_resources
),
976 .resources
= wm831x_power_resources
,
979 .name
= "wm831x-rtc",
980 .num_resources
= ARRAY_SIZE(wm831x_rtc_resources
),
981 .resources
= wm831x_rtc_resources
,
984 .name
= "wm831x-status",
986 .num_resources
= ARRAY_SIZE(wm831x_status1_resources
),
987 .resources
= wm831x_status1_resources
,
990 .name
= "wm831x-status",
992 .num_resources
= ARRAY_SIZE(wm831x_status2_resources
),
993 .resources
= wm831x_status2_resources
,
996 .name
= "wm831x-watchdog",
997 .num_resources
= ARRAY_SIZE(wm831x_wdt_resources
),
998 .resources
= wm831x_wdt_resources
,
1002 static struct mfd_cell wm8311_devs
[] = {
1004 .name
= "wm831x-backup",
1007 .name
= "wm831x-buckv",
1009 .num_resources
= ARRAY_SIZE(wm831x_dcdc1_resources
),
1010 .resources
= wm831x_dcdc1_resources
,
1013 .name
= "wm831x-buckv",
1015 .num_resources
= ARRAY_SIZE(wm831x_dcdc2_resources
),
1016 .resources
= wm831x_dcdc2_resources
,
1019 .name
= "wm831x-buckp",
1021 .num_resources
= ARRAY_SIZE(wm831x_dcdc3_resources
),
1022 .resources
= wm831x_dcdc3_resources
,
1025 .name
= "wm831x-boostp",
1027 .num_resources
= ARRAY_SIZE(wm831x_dcdc4_resources
),
1028 .resources
= wm831x_dcdc4_resources
,
1031 .name
= "wm831x-epe",
1035 .name
= "wm831x-epe",
1039 .name
= "wm831x-gpio",
1040 .num_resources
= ARRAY_SIZE(wm831x_gpio_resources
),
1041 .resources
= wm831x_gpio_resources
,
1044 .name
= "wm831x-hwmon",
1047 .name
= "wm831x-isink",
1049 .num_resources
= ARRAY_SIZE(wm831x_isink1_resources
),
1050 .resources
= wm831x_isink1_resources
,
1053 .name
= "wm831x-isink",
1055 .num_resources
= ARRAY_SIZE(wm831x_isink2_resources
),
1056 .resources
= wm831x_isink2_resources
,
1059 .name
= "wm831x-ldo",
1061 .num_resources
= ARRAY_SIZE(wm831x_ldo1_resources
),
1062 .resources
= wm831x_ldo1_resources
,
1065 .name
= "wm831x-ldo",
1067 .num_resources
= ARRAY_SIZE(wm831x_ldo2_resources
),
1068 .resources
= wm831x_ldo2_resources
,
1071 .name
= "wm831x-ldo",
1073 .num_resources
= ARRAY_SIZE(wm831x_ldo3_resources
),
1074 .resources
= wm831x_ldo3_resources
,
1077 .name
= "wm831x-ldo",
1079 .num_resources
= ARRAY_SIZE(wm831x_ldo4_resources
),
1080 .resources
= wm831x_ldo4_resources
,
1083 .name
= "wm831x-ldo",
1085 .num_resources
= ARRAY_SIZE(wm831x_ldo5_resources
),
1086 .resources
= wm831x_ldo5_resources
,
1089 .name
= "wm831x-aldo",
1091 .num_resources
= ARRAY_SIZE(wm831x_ldo7_resources
),
1092 .resources
= wm831x_ldo7_resources
,
1095 .name
= "wm831x-alive-ldo",
1097 .num_resources
= ARRAY_SIZE(wm831x_ldo11_resources
),
1098 .resources
= wm831x_ldo11_resources
,
1101 .name
= "wm831x-on",
1102 .num_resources
= ARRAY_SIZE(wm831x_on_resources
),
1103 .resources
= wm831x_on_resources
,
1106 .name
= "wm831x-power",
1107 .num_resources
= ARRAY_SIZE(wm831x_power_resources
),
1108 .resources
= wm831x_power_resources
,
1111 .name
= "wm831x-rtc",
1112 .num_resources
= ARRAY_SIZE(wm831x_rtc_resources
),
1113 .resources
= wm831x_rtc_resources
,
1116 .name
= "wm831x-status",
1118 .num_resources
= ARRAY_SIZE(wm831x_status1_resources
),
1119 .resources
= wm831x_status1_resources
,
1122 .name
= "wm831x-status",
1124 .num_resources
= ARRAY_SIZE(wm831x_status2_resources
),
1125 .resources
= wm831x_status2_resources
,
1128 .name
= "wm831x-touch",
1129 .num_resources
= ARRAY_SIZE(wm831x_touch_resources
),
1130 .resources
= wm831x_touch_resources
,
1133 .name
= "wm831x-watchdog",
1134 .num_resources
= ARRAY_SIZE(wm831x_wdt_resources
),
1135 .resources
= wm831x_wdt_resources
,
1139 static struct mfd_cell wm8312_devs
[] = {
1141 .name
= "wm831x-backup",
1144 .name
= "wm831x-buckv",
1146 .num_resources
= ARRAY_SIZE(wm831x_dcdc1_resources
),
1147 .resources
= wm831x_dcdc1_resources
,
1150 .name
= "wm831x-buckv",
1152 .num_resources
= ARRAY_SIZE(wm831x_dcdc2_resources
),
1153 .resources
= wm831x_dcdc2_resources
,
1156 .name
= "wm831x-buckp",
1158 .num_resources
= ARRAY_SIZE(wm831x_dcdc3_resources
),
1159 .resources
= wm831x_dcdc3_resources
,
1162 .name
= "wm831x-boostp",
1164 .num_resources
= ARRAY_SIZE(wm831x_dcdc4_resources
),
1165 .resources
= wm831x_dcdc4_resources
,
1168 .name
= "wm831x-epe",
1172 .name
= "wm831x-epe",
1176 .name
= "wm831x-gpio",
1177 .num_resources
= ARRAY_SIZE(wm831x_gpio_resources
),
1178 .resources
= wm831x_gpio_resources
,
1181 .name
= "wm831x-hwmon",
1184 .name
= "wm831x-isink",
1186 .num_resources
= ARRAY_SIZE(wm831x_isink1_resources
),
1187 .resources
= wm831x_isink1_resources
,
1190 .name
= "wm831x-isink",
1192 .num_resources
= ARRAY_SIZE(wm831x_isink2_resources
),
1193 .resources
= wm831x_isink2_resources
,
1196 .name
= "wm831x-ldo",
1198 .num_resources
= ARRAY_SIZE(wm831x_ldo1_resources
),
1199 .resources
= wm831x_ldo1_resources
,
1202 .name
= "wm831x-ldo",
1204 .num_resources
= ARRAY_SIZE(wm831x_ldo2_resources
),
1205 .resources
= wm831x_ldo2_resources
,
1208 .name
= "wm831x-ldo",
1210 .num_resources
= ARRAY_SIZE(wm831x_ldo3_resources
),
1211 .resources
= wm831x_ldo3_resources
,
1214 .name
= "wm831x-ldo",
1216 .num_resources
= ARRAY_SIZE(wm831x_ldo4_resources
),
1217 .resources
= wm831x_ldo4_resources
,
1220 .name
= "wm831x-ldo",
1222 .num_resources
= ARRAY_SIZE(wm831x_ldo5_resources
),
1223 .resources
= wm831x_ldo5_resources
,
1226 .name
= "wm831x-ldo",
1228 .num_resources
= ARRAY_SIZE(wm831x_ldo6_resources
),
1229 .resources
= wm831x_ldo6_resources
,
1232 .name
= "wm831x-aldo",
1234 .num_resources
= ARRAY_SIZE(wm831x_ldo7_resources
),
1235 .resources
= wm831x_ldo7_resources
,
1238 .name
= "wm831x-aldo",
1240 .num_resources
= ARRAY_SIZE(wm831x_ldo8_resources
),
1241 .resources
= wm831x_ldo8_resources
,
1244 .name
= "wm831x-aldo",
1246 .num_resources
= ARRAY_SIZE(wm831x_ldo9_resources
),
1247 .resources
= wm831x_ldo9_resources
,
1250 .name
= "wm831x-aldo",
1252 .num_resources
= ARRAY_SIZE(wm831x_ldo10_resources
),
1253 .resources
= wm831x_ldo10_resources
,
1256 .name
= "wm831x-alive-ldo",
1258 .num_resources
= ARRAY_SIZE(wm831x_ldo11_resources
),
1259 .resources
= wm831x_ldo11_resources
,
1262 .name
= "wm831x-on",
1263 .num_resources
= ARRAY_SIZE(wm831x_on_resources
),
1264 .resources
= wm831x_on_resources
,
1267 .name
= "wm831x-power",
1268 .num_resources
= ARRAY_SIZE(wm831x_power_resources
),
1269 .resources
= wm831x_power_resources
,
1272 .name
= "wm831x-rtc",
1273 .num_resources
= ARRAY_SIZE(wm831x_rtc_resources
),
1274 .resources
= wm831x_rtc_resources
,
1277 .name
= "wm831x-status",
1279 .num_resources
= ARRAY_SIZE(wm831x_status1_resources
),
1280 .resources
= wm831x_status1_resources
,
1283 .name
= "wm831x-status",
1285 .num_resources
= ARRAY_SIZE(wm831x_status2_resources
),
1286 .resources
= wm831x_status2_resources
,
1289 .name
= "wm831x-touch",
1290 .num_resources
= ARRAY_SIZE(wm831x_touch_resources
),
1291 .resources
= wm831x_touch_resources
,
1294 .name
= "wm831x-watchdog",
1295 .num_resources
= ARRAY_SIZE(wm831x_wdt_resources
),
1296 .resources
= wm831x_wdt_resources
,
1300 static struct mfd_cell wm8320_devs
[] = {
1302 .name
= "wm831x-backup",
1305 .name
= "wm831x-buckv",
1307 .num_resources
= ARRAY_SIZE(wm831x_dcdc1_resources
),
1308 .resources
= wm831x_dcdc1_resources
,
1311 .name
= "wm831x-buckv",
1313 .num_resources
= ARRAY_SIZE(wm831x_dcdc2_resources
),
1314 .resources
= wm831x_dcdc2_resources
,
1317 .name
= "wm831x-buckp",
1319 .num_resources
= ARRAY_SIZE(wm831x_dcdc3_resources
),
1320 .resources
= wm831x_dcdc3_resources
,
1323 .name
= "wm831x-buckp",
1325 .num_resources
= ARRAY_SIZE(wm8320_dcdc4_buck_resources
),
1326 .resources
= wm8320_dcdc4_buck_resources
,
1329 .name
= "wm831x-gpio",
1330 .num_resources
= ARRAY_SIZE(wm831x_gpio_resources
),
1331 .resources
= wm831x_gpio_resources
,
1334 .name
= "wm831x-hwmon",
1337 .name
= "wm831x-ldo",
1339 .num_resources
= ARRAY_SIZE(wm831x_ldo1_resources
),
1340 .resources
= wm831x_ldo1_resources
,
1343 .name
= "wm831x-ldo",
1345 .num_resources
= ARRAY_SIZE(wm831x_ldo2_resources
),
1346 .resources
= wm831x_ldo2_resources
,
1349 .name
= "wm831x-ldo",
1351 .num_resources
= ARRAY_SIZE(wm831x_ldo3_resources
),
1352 .resources
= wm831x_ldo3_resources
,
1355 .name
= "wm831x-ldo",
1357 .num_resources
= ARRAY_SIZE(wm831x_ldo4_resources
),
1358 .resources
= wm831x_ldo4_resources
,
1361 .name
= "wm831x-ldo",
1363 .num_resources
= ARRAY_SIZE(wm831x_ldo5_resources
),
1364 .resources
= wm831x_ldo5_resources
,
1367 .name
= "wm831x-ldo",
1369 .num_resources
= ARRAY_SIZE(wm831x_ldo6_resources
),
1370 .resources
= wm831x_ldo6_resources
,
1373 .name
= "wm831x-aldo",
1375 .num_resources
= ARRAY_SIZE(wm831x_ldo7_resources
),
1376 .resources
= wm831x_ldo7_resources
,
1379 .name
= "wm831x-aldo",
1381 .num_resources
= ARRAY_SIZE(wm831x_ldo8_resources
),
1382 .resources
= wm831x_ldo8_resources
,
1385 .name
= "wm831x-aldo",
1387 .num_resources
= ARRAY_SIZE(wm831x_ldo9_resources
),
1388 .resources
= wm831x_ldo9_resources
,
1391 .name
= "wm831x-aldo",
1393 .num_resources
= ARRAY_SIZE(wm831x_ldo10_resources
),
1394 .resources
= wm831x_ldo10_resources
,
1397 .name
= "wm831x-alive-ldo",
1399 .num_resources
= ARRAY_SIZE(wm831x_ldo11_resources
),
1400 .resources
= wm831x_ldo11_resources
,
1403 .name
= "wm831x-on",
1404 .num_resources
= ARRAY_SIZE(wm831x_on_resources
),
1405 .resources
= wm831x_on_resources
,
1408 .name
= "wm831x-rtc",
1409 .num_resources
= ARRAY_SIZE(wm831x_rtc_resources
),
1410 .resources
= wm831x_rtc_resources
,
1413 .name
= "wm831x-status",
1415 .num_resources
= ARRAY_SIZE(wm831x_status1_resources
),
1416 .resources
= wm831x_status1_resources
,
1419 .name
= "wm831x-status",
1421 .num_resources
= ARRAY_SIZE(wm831x_status2_resources
),
1422 .resources
= wm831x_status2_resources
,
1425 .name
= "wm831x-watchdog",
1426 .num_resources
= ARRAY_SIZE(wm831x_wdt_resources
),
1427 .resources
= wm831x_wdt_resources
,
1431 static struct mfd_cell backlight_devs
[] = {
1433 .name
= "wm831x-backlight",
1438 * Instantiate the generic non-control parts of the device.
1440 int wm831x_device_init(struct wm831x
*wm831x
, unsigned long id
, int irq
)
1442 struct wm831x_pdata
*pdata
= wm831x
->dev
->platform_data
;
1444 enum wm831x_parent parent
;
1447 mutex_init(&wm831x
->io_lock
);
1448 mutex_init(&wm831x
->key_lock
);
1449 mutex_init(&wm831x
->auxadc_lock
);
1450 init_completion(&wm831x
->auxadc_done
);
1451 dev_set_drvdata(wm831x
->dev
, wm831x
);
1453 ret
= wm831x_reg_read(wm831x
, WM831X_PARENT_ID
);
1455 dev_err(wm831x
->dev
, "Failed to read parent ID: %d\n", ret
);
1463 dev_err(wm831x
->dev
, "Device is not a WM831x: ID %x\n", ret
);
1468 ret
= wm831x_reg_read(wm831x
, WM831X_REVISION
);
1470 dev_err(wm831x
->dev
, "Failed to read revision: %d\n", ret
);
1473 rev
= (ret
& WM831X_PARENT_REV_MASK
) >> WM831X_PARENT_REV_SHIFT
;
1475 ret
= wm831x_reg_read(wm831x
, WM831X_RESET_ID
);
1477 dev_err(wm831x
->dev
, "Failed to read device ID: %d\n", ret
);
1481 /* Some engineering samples do not have the ID set, rely on
1482 * the device being registered correctly.
1485 dev_info(wm831x
->dev
, "Device is an engineering sample\n");
1492 wm831x
->num_gpio
= 16;
1493 wm831x
->charger_irq_wake
= 1;
1495 wm831x
->has_gpio_ena
= 1;
1496 wm831x
->has_cs_sts
= 1;
1499 dev_info(wm831x
->dev
, "WM8310 revision %c\n", 'A' + rev
);
1504 wm831x
->num_gpio
= 16;
1505 wm831x
->charger_irq_wake
= 1;
1507 wm831x
->has_gpio_ena
= 1;
1508 wm831x
->has_cs_sts
= 1;
1511 dev_info(wm831x
->dev
, "WM8311 revision %c\n", 'A' + rev
);
1516 wm831x
->num_gpio
= 16;
1517 wm831x
->charger_irq_wake
= 1;
1519 wm831x
->has_gpio_ena
= 1;
1520 wm831x
->has_cs_sts
= 1;
1523 dev_info(wm831x
->dev
, "WM8312 revision %c\n", 'A' + rev
);
1528 wm831x
->num_gpio
= 12;
1529 dev_info(wm831x
->dev
, "WM8320 revision %c\n", 'A' + rev
);
1534 wm831x
->num_gpio
= 12;
1535 dev_info(wm831x
->dev
, "WM8321 revision %c\n", 'A' + rev
);
1540 wm831x
->num_gpio
= 12;
1541 dev_info(wm831x
->dev
, "WM8325 revision %c\n", 'A' + rev
);
1546 wm831x
->num_gpio
= 12;
1547 dev_info(wm831x
->dev
, "WM8326 revision %c\n", 'A' + rev
);
1551 dev_err(wm831x
->dev
, "Unknown WM831x device %04x\n", ret
);
1556 /* This will need revisiting in future but is OK for all
1560 dev_warn(wm831x
->dev
, "Device was registered as a WM%lx\n",
1563 /* Bootstrap the user key */
1564 ret
= wm831x_reg_read(wm831x
, WM831X_SECURITY_KEY
);
1566 dev_err(wm831x
->dev
, "Failed to read security key: %d\n", ret
);
1570 dev_warn(wm831x
->dev
, "Security key had non-zero value %x\n",
1572 wm831x_reg_write(wm831x
, WM831X_SECURITY_KEY
, 0);
1576 if (pdata
&& pdata
->pre_init
) {
1577 ret
= pdata
->pre_init(wm831x
);
1579 dev_err(wm831x
->dev
, "pre_init() failed: %d\n", ret
);
1585 for (i
= 0; i
< ARRAY_SIZE(pdata
->gpio_defaults
); i
++) {
1586 if (!pdata
->gpio_defaults
[i
])
1589 wm831x_reg_write(wm831x
,
1590 WM831X_GPIO1_CONTROL
+ i
,
1591 pdata
->gpio_defaults
[i
] & 0xffff);
1595 ret
= wm831x_irq_init(wm831x
, irq
);
1599 if (wm831x
->irq_base
) {
1600 ret
= request_threaded_irq(wm831x
->irq_base
+
1601 WM831X_IRQ_AUXADC_DATA
,
1602 NULL
, wm831x_auxadc_irq
, 0,
1605 dev_err(wm831x
->dev
, "AUXADC IRQ request failed: %d\n",
1609 /* The core device is up, instantiate the subdevices. */
1612 ret
= mfd_add_devices(wm831x
->dev
, -1,
1613 wm8310_devs
, ARRAY_SIZE(wm8310_devs
),
1614 NULL
, wm831x
->irq_base
);
1618 ret
= mfd_add_devices(wm831x
->dev
, -1,
1619 wm8311_devs
, ARRAY_SIZE(wm8311_devs
),
1620 NULL
, wm831x
->irq_base
);
1624 ret
= mfd_add_devices(wm831x
->dev
, -1,
1625 wm8312_devs
, ARRAY_SIZE(wm8312_devs
),
1626 NULL
, wm831x
->irq_base
);
1633 ret
= mfd_add_devices(wm831x
->dev
, -1,
1634 wm8320_devs
, ARRAY_SIZE(wm8320_devs
),
1635 NULL
, wm831x
->irq_base
);
1639 /* If this happens the bus probe function is buggy */
1644 dev_err(wm831x
->dev
, "Failed to add children\n");
1648 if (pdata
&& pdata
->backlight
) {
1649 /* Treat errors as non-critical */
1650 ret
= mfd_add_devices(wm831x
->dev
, -1, backlight_devs
,
1651 ARRAY_SIZE(backlight_devs
), NULL
,
1654 dev_err(wm831x
->dev
, "Failed to add backlight: %d\n",
1658 wm831x_otp_init(wm831x
);
1660 if (pdata
&& pdata
->post_init
) {
1661 ret
= pdata
->post_init(wm831x
);
1663 dev_err(wm831x
->dev
, "post_init() failed: %d\n", ret
);
1671 wm831x_irq_exit(wm831x
);
1673 mfd_remove_devices(wm831x
->dev
);
1678 void wm831x_device_exit(struct wm831x
*wm831x
)
1680 wm831x_otp_exit(wm831x
);
1681 mfd_remove_devices(wm831x
->dev
);
1682 if (wm831x
->irq_base
)
1683 free_irq(wm831x
->irq_base
+ WM831X_IRQ_AUXADC_DATA
, wm831x
);
1684 wm831x_irq_exit(wm831x
);
1688 int wm831x_device_suspend(struct wm831x
*wm831x
)
1692 /* If the charger IRQs are a wake source then make sure we ack
1693 * them even if they're not actively being used (eg, no power
1694 * driver or no IRQ line wired up) then acknowledge the
1695 * interrupts otherwise suspend won't last very long.
1697 if (wm831x
->charger_irq_wake
) {
1698 reg
= wm831x_reg_read(wm831x
, WM831X_INTERRUPT_STATUS_2_MASK
);
1700 mask
= WM831X_CHG_BATT_HOT_EINT
|
1701 WM831X_CHG_BATT_COLD_EINT
|
1702 WM831X_CHG_BATT_FAIL_EINT
|
1703 WM831X_CHG_OV_EINT
| WM831X_CHG_END_EINT
|
1704 WM831X_CHG_TO_EINT
| WM831X_CHG_MODE_EINT
|
1705 WM831X_CHG_START_EINT
;
1707 /* If any of the interrupts are masked read the statuses */
1709 reg
= wm831x_reg_read(wm831x
,
1710 WM831X_INTERRUPT_STATUS_2
);
1713 dev_info(wm831x
->dev
,
1714 "Acknowledging masked charger IRQs: %x\n",
1716 wm831x_reg_write(wm831x
, WM831X_INTERRUPT_STATUS_2
,
1724 MODULE_DESCRIPTION("Core support for the WM831X AudioPlus PMIC");
1725 MODULE_LICENSE("GPL");
1726 MODULE_AUTHOR("Mark Brown");