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/i2c.h>
18 #include <linux/bcd.h>
19 #include <linux/delay.h>
20 #include <linux/mfd/core.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
] = {
90 EXPORT_SYMBOL_GPL(wm831x_isinkv_values
);
99 static int wm831x_reg_locked(struct wm831x
*wm831x
, unsigned short reg
)
105 case WM831X_WATCHDOG
:
106 case WM831X_DC4_CONTROL
:
107 case WM831X_ON_PIN_CONTROL
:
108 case WM831X_BACKUP_CHARGER_CONTROL
:
109 case WM831X_CHARGER_CONTROL_1
:
110 case WM831X_CHARGER_CONTROL_2
:
119 * wm831x_reg_unlock: Unlock user keyed registers
121 * The WM831x has a user key preventing writes to particularly
122 * critical registers. This function locks those registers,
123 * allowing writes to them.
125 void wm831x_reg_lock(struct wm831x
*wm831x
)
129 ret
= wm831x_reg_write(wm831x
, WM831X_SECURITY_KEY
, 0);
131 dev_vdbg(wm831x
->dev
, "Registers locked\n");
133 mutex_lock(&wm831x
->io_lock
);
134 WARN_ON(wm831x
->locked
);
136 mutex_unlock(&wm831x
->io_lock
);
138 dev_err(wm831x
->dev
, "Failed to lock registers: %d\n", ret
);
142 EXPORT_SYMBOL_GPL(wm831x_reg_lock
);
145 * wm831x_reg_unlock: Unlock user keyed registers
147 * The WM831x has a user key preventing writes to particularly
148 * critical registers. This function locks those registers,
149 * preventing spurious writes.
151 int wm831x_reg_unlock(struct wm831x
*wm831x
)
155 /* 0x9716 is the value required to unlock the registers */
156 ret
= wm831x_reg_write(wm831x
, WM831X_SECURITY_KEY
, 0x9716);
158 dev_vdbg(wm831x
->dev
, "Registers unlocked\n");
160 mutex_lock(&wm831x
->io_lock
);
161 WARN_ON(!wm831x
->locked
);
163 mutex_unlock(&wm831x
->io_lock
);
168 EXPORT_SYMBOL_GPL(wm831x_reg_unlock
);
170 static int wm831x_read(struct wm831x
*wm831x
, unsigned short reg
,
171 int bytes
, void *dest
)
179 ret
= wm831x
->read_dev(wm831x
, reg
, bytes
, dest
);
183 for (i
= 0; i
< bytes
/ 2; i
++) {
184 buf
[i
] = be16_to_cpu(buf
[i
]);
186 dev_vdbg(wm831x
->dev
, "Read %04x from R%d(0x%x)\n",
187 buf
[i
], reg
+ i
, reg
+ i
);
194 * wm831x_reg_read: Read a single WM831x register.
196 * @wm831x: Device to read from.
197 * @reg: Register to read.
199 int wm831x_reg_read(struct wm831x
*wm831x
, unsigned short reg
)
204 mutex_lock(&wm831x
->io_lock
);
206 ret
= wm831x_read(wm831x
, reg
, 2, &val
);
208 mutex_unlock(&wm831x
->io_lock
);
215 EXPORT_SYMBOL_GPL(wm831x_reg_read
);
218 * wm831x_bulk_read: Read multiple WM831x registers
220 * @wm831x: Device to read from
221 * @reg: First register
222 * @count: Number of registers
223 * @buf: Buffer to fill.
225 int wm831x_bulk_read(struct wm831x
*wm831x
, unsigned short reg
,
230 mutex_lock(&wm831x
->io_lock
);
232 ret
= wm831x_read(wm831x
, reg
, count
* 2, buf
);
234 mutex_unlock(&wm831x
->io_lock
);
238 EXPORT_SYMBOL_GPL(wm831x_bulk_read
);
240 static int wm831x_write(struct wm831x
*wm831x
, unsigned short reg
,
241 int bytes
, void *src
)
249 for (i
= 0; i
< bytes
/ 2; i
++) {
250 if (wm831x_reg_locked(wm831x
, reg
))
253 dev_vdbg(wm831x
->dev
, "Write %04x to R%d(0x%x)\n",
254 buf
[i
], reg
+ i
, reg
+ i
);
256 buf
[i
] = cpu_to_be16(buf
[i
]);
259 return wm831x
->write_dev(wm831x
, reg
, bytes
, src
);
263 * wm831x_reg_write: Write a single WM831x register.
265 * @wm831x: Device to write to.
266 * @reg: Register to write to.
267 * @val: Value to write.
269 int wm831x_reg_write(struct wm831x
*wm831x
, unsigned short reg
,
274 mutex_lock(&wm831x
->io_lock
);
276 ret
= wm831x_write(wm831x
, reg
, 2, &val
);
278 mutex_unlock(&wm831x
->io_lock
);
282 EXPORT_SYMBOL_GPL(wm831x_reg_write
);
285 * wm831x_set_bits: Set the value of a bitfield in a WM831x register
287 * @wm831x: Device to write to.
288 * @reg: Register to write to.
289 * @mask: Mask of bits to set.
290 * @val: Value to set (unshifted)
292 int wm831x_set_bits(struct wm831x
*wm831x
, unsigned short reg
,
293 unsigned short mask
, unsigned short val
)
298 mutex_lock(&wm831x
->io_lock
);
300 ret
= wm831x_read(wm831x
, reg
, 2, &r
);
307 ret
= wm831x_write(wm831x
, reg
, 2, &r
);
310 mutex_unlock(&wm831x
->io_lock
);
314 EXPORT_SYMBOL_GPL(wm831x_set_bits
);
317 * wm831x_auxadc_read: Read a value from the WM831x AUXADC
319 * @wm831x: Device to read from.
320 * @input: AUXADC input to read.
322 int wm831x_auxadc_read(struct wm831x
*wm831x
, enum wm831x_auxadc input
)
327 mutex_lock(&wm831x
->auxadc_lock
);
329 ret
= wm831x_set_bits(wm831x
, WM831X_AUXADC_CONTROL
,
330 WM831X_AUX_ENA
, WM831X_AUX_ENA
);
332 dev_err(wm831x
->dev
, "Failed to enable AUXADC: %d\n", ret
);
336 /* We force a single source at present */
338 ret
= wm831x_reg_write(wm831x
, WM831X_AUXADC_SOURCE
,
341 dev_err(wm831x
->dev
, "Failed to set AUXADC source: %d\n", ret
);
345 ret
= wm831x_set_bits(wm831x
, WM831X_AUXADC_CONTROL
,
346 WM831X_AUX_CVT_ENA
, WM831X_AUX_CVT_ENA
);
348 dev_err(wm831x
->dev
, "Failed to start AUXADC: %d\n", ret
);
355 ret
= wm831x_reg_read(wm831x
, WM831X_AUXADC_CONTROL
);
357 ret
= WM831X_AUX_CVT_ENA
;
358 } while ((ret
& WM831X_AUX_CVT_ENA
) && --tries
);
360 if (ret
& WM831X_AUX_CVT_ENA
) {
361 dev_err(wm831x
->dev
, "Timed out reading AUXADC\n");
366 ret
= wm831x_reg_read(wm831x
, WM831X_AUXADC_DATA
);
368 dev_err(wm831x
->dev
, "Failed to read AUXADC data: %d\n", ret
);
370 src
= ((ret
& WM831X_AUX_DATA_SRC_MASK
)
371 >> WM831X_AUX_DATA_SRC_SHIFT
) - 1;
374 src
= WM831X_AUX_CAL
;
377 dev_err(wm831x
->dev
, "Data from source %d not %d\n",
381 ret
&= WM831X_AUX_DATA_MASK
;
386 wm831x_set_bits(wm831x
, WM831X_AUXADC_CONTROL
, WM831X_AUX_ENA
, 0);
388 mutex_unlock(&wm831x
->auxadc_lock
);
391 EXPORT_SYMBOL_GPL(wm831x_auxadc_read
);
394 * wm831x_auxadc_read_uv: Read a voltage from the WM831x AUXADC
396 * @wm831x: Device to read from.
397 * @input: AUXADC input to read.
399 int wm831x_auxadc_read_uv(struct wm831x
*wm831x
, enum wm831x_auxadc input
)
403 ret
= wm831x_auxadc_read(wm831x
, input
);
411 EXPORT_SYMBOL_GPL(wm831x_auxadc_read_uv
);
413 static struct resource wm831x_dcdc1_resources
[] = {
415 .start
= WM831X_DC1_CONTROL_1
,
416 .end
= WM831X_DC1_DVS_CONTROL
,
417 .flags
= IORESOURCE_IO
,
421 .start
= WM831X_IRQ_UV_DC1
,
422 .end
= WM831X_IRQ_UV_DC1
,
423 .flags
= IORESOURCE_IRQ
,
427 .start
= WM831X_IRQ_HC_DC1
,
428 .end
= WM831X_IRQ_HC_DC1
,
429 .flags
= IORESOURCE_IRQ
,
434 static struct resource wm831x_dcdc2_resources
[] = {
436 .start
= WM831X_DC2_CONTROL_1
,
437 .end
= WM831X_DC2_DVS_CONTROL
,
438 .flags
= IORESOURCE_IO
,
442 .start
= WM831X_IRQ_UV_DC2
,
443 .end
= WM831X_IRQ_UV_DC2
,
444 .flags
= IORESOURCE_IRQ
,
448 .start
= WM831X_IRQ_HC_DC2
,
449 .end
= WM831X_IRQ_HC_DC2
,
450 .flags
= IORESOURCE_IRQ
,
454 static struct resource wm831x_dcdc3_resources
[] = {
456 .start
= WM831X_DC3_CONTROL_1
,
457 .end
= WM831X_DC3_SLEEP_CONTROL
,
458 .flags
= IORESOURCE_IO
,
462 .start
= WM831X_IRQ_UV_DC3
,
463 .end
= WM831X_IRQ_UV_DC3
,
464 .flags
= IORESOURCE_IRQ
,
468 static struct resource wm831x_dcdc4_resources
[] = {
470 .start
= WM831X_DC4_CONTROL
,
471 .end
= WM831X_DC4_SLEEP_CONTROL
,
472 .flags
= IORESOURCE_IO
,
476 .start
= WM831X_IRQ_UV_DC4
,
477 .end
= WM831X_IRQ_UV_DC4
,
478 .flags
= IORESOURCE_IRQ
,
482 static struct resource wm8320_dcdc4_buck_resources
[] = {
484 .start
= WM831X_DC4_CONTROL
,
485 .end
= WM832X_DC4_SLEEP_CONTROL
,
486 .flags
= IORESOURCE_IO
,
490 .start
= WM831X_IRQ_UV_DC4
,
491 .end
= WM831X_IRQ_UV_DC4
,
492 .flags
= IORESOURCE_IRQ
,
496 static struct resource wm831x_gpio_resources
[] = {
498 .start
= WM831X_IRQ_GPIO_1
,
499 .end
= WM831X_IRQ_GPIO_16
,
500 .flags
= IORESOURCE_IRQ
,
504 static struct resource wm831x_isink1_resources
[] = {
506 .start
= WM831X_CURRENT_SINK_1
,
507 .end
= WM831X_CURRENT_SINK_1
,
508 .flags
= IORESOURCE_IO
,
511 .start
= WM831X_IRQ_CS1
,
512 .end
= WM831X_IRQ_CS1
,
513 .flags
= IORESOURCE_IRQ
,
517 static struct resource wm831x_isink2_resources
[] = {
519 .start
= WM831X_CURRENT_SINK_2
,
520 .end
= WM831X_CURRENT_SINK_2
,
521 .flags
= IORESOURCE_IO
,
524 .start
= WM831X_IRQ_CS2
,
525 .end
= WM831X_IRQ_CS2
,
526 .flags
= IORESOURCE_IRQ
,
530 static struct resource wm831x_ldo1_resources
[] = {
532 .start
= WM831X_LDO1_CONTROL
,
533 .end
= WM831X_LDO1_SLEEP_CONTROL
,
534 .flags
= IORESOURCE_IO
,
538 .start
= WM831X_IRQ_UV_LDO1
,
539 .end
= WM831X_IRQ_UV_LDO1
,
540 .flags
= IORESOURCE_IRQ
,
544 static struct resource wm831x_ldo2_resources
[] = {
546 .start
= WM831X_LDO2_CONTROL
,
547 .end
= WM831X_LDO2_SLEEP_CONTROL
,
548 .flags
= IORESOURCE_IO
,
552 .start
= WM831X_IRQ_UV_LDO2
,
553 .end
= WM831X_IRQ_UV_LDO2
,
554 .flags
= IORESOURCE_IRQ
,
558 static struct resource wm831x_ldo3_resources
[] = {
560 .start
= WM831X_LDO3_CONTROL
,
561 .end
= WM831X_LDO3_SLEEP_CONTROL
,
562 .flags
= IORESOURCE_IO
,
566 .start
= WM831X_IRQ_UV_LDO3
,
567 .end
= WM831X_IRQ_UV_LDO3
,
568 .flags
= IORESOURCE_IRQ
,
572 static struct resource wm831x_ldo4_resources
[] = {
574 .start
= WM831X_LDO4_CONTROL
,
575 .end
= WM831X_LDO4_SLEEP_CONTROL
,
576 .flags
= IORESOURCE_IO
,
580 .start
= WM831X_IRQ_UV_LDO4
,
581 .end
= WM831X_IRQ_UV_LDO4
,
582 .flags
= IORESOURCE_IRQ
,
586 static struct resource wm831x_ldo5_resources
[] = {
588 .start
= WM831X_LDO5_CONTROL
,
589 .end
= WM831X_LDO5_SLEEP_CONTROL
,
590 .flags
= IORESOURCE_IO
,
594 .start
= WM831X_IRQ_UV_LDO5
,
595 .end
= WM831X_IRQ_UV_LDO5
,
596 .flags
= IORESOURCE_IRQ
,
600 static struct resource wm831x_ldo6_resources
[] = {
602 .start
= WM831X_LDO6_CONTROL
,
603 .end
= WM831X_LDO6_SLEEP_CONTROL
,
604 .flags
= IORESOURCE_IO
,
608 .start
= WM831X_IRQ_UV_LDO6
,
609 .end
= WM831X_IRQ_UV_LDO6
,
610 .flags
= IORESOURCE_IRQ
,
614 static struct resource wm831x_ldo7_resources
[] = {
616 .start
= WM831X_LDO7_CONTROL
,
617 .end
= WM831X_LDO7_SLEEP_CONTROL
,
618 .flags
= IORESOURCE_IO
,
622 .start
= WM831X_IRQ_UV_LDO7
,
623 .end
= WM831X_IRQ_UV_LDO7
,
624 .flags
= IORESOURCE_IRQ
,
628 static struct resource wm831x_ldo8_resources
[] = {
630 .start
= WM831X_LDO8_CONTROL
,
631 .end
= WM831X_LDO8_SLEEP_CONTROL
,
632 .flags
= IORESOURCE_IO
,
636 .start
= WM831X_IRQ_UV_LDO8
,
637 .end
= WM831X_IRQ_UV_LDO8
,
638 .flags
= IORESOURCE_IRQ
,
642 static struct resource wm831x_ldo9_resources
[] = {
644 .start
= WM831X_LDO9_CONTROL
,
645 .end
= WM831X_LDO9_SLEEP_CONTROL
,
646 .flags
= IORESOURCE_IO
,
650 .start
= WM831X_IRQ_UV_LDO9
,
651 .end
= WM831X_IRQ_UV_LDO9
,
652 .flags
= IORESOURCE_IRQ
,
656 static struct resource wm831x_ldo10_resources
[] = {
658 .start
= WM831X_LDO10_CONTROL
,
659 .end
= WM831X_LDO10_SLEEP_CONTROL
,
660 .flags
= IORESOURCE_IO
,
664 .start
= WM831X_IRQ_UV_LDO10
,
665 .end
= WM831X_IRQ_UV_LDO10
,
666 .flags
= IORESOURCE_IRQ
,
670 static struct resource wm831x_ldo11_resources
[] = {
672 .start
= WM831X_LDO11_ON_CONTROL
,
673 .end
= WM831X_LDO11_SLEEP_CONTROL
,
674 .flags
= IORESOURCE_IO
,
678 static struct resource wm831x_on_resources
[] = {
680 .start
= WM831X_IRQ_ON
,
681 .end
= WM831X_IRQ_ON
,
682 .flags
= IORESOURCE_IRQ
,
687 static struct resource wm831x_power_resources
[] = {
690 .start
= WM831X_IRQ_PPM_SYSLO
,
691 .end
= WM831X_IRQ_PPM_SYSLO
,
692 .flags
= IORESOURCE_IRQ
,
696 .start
= WM831X_IRQ_PPM_PWR_SRC
,
697 .end
= WM831X_IRQ_PPM_PWR_SRC
,
698 .flags
= IORESOURCE_IRQ
,
702 .start
= WM831X_IRQ_PPM_USB_CURR
,
703 .end
= WM831X_IRQ_PPM_USB_CURR
,
704 .flags
= IORESOURCE_IRQ
,
708 .start
= WM831X_IRQ_CHG_BATT_HOT
,
709 .end
= WM831X_IRQ_CHG_BATT_HOT
,
710 .flags
= IORESOURCE_IRQ
,
714 .start
= WM831X_IRQ_CHG_BATT_COLD
,
715 .end
= WM831X_IRQ_CHG_BATT_COLD
,
716 .flags
= IORESOURCE_IRQ
,
720 .start
= WM831X_IRQ_CHG_BATT_FAIL
,
721 .end
= WM831X_IRQ_CHG_BATT_FAIL
,
722 .flags
= IORESOURCE_IRQ
,
726 .start
= WM831X_IRQ_CHG_OV
,
727 .end
= WM831X_IRQ_CHG_OV
,
728 .flags
= IORESOURCE_IRQ
,
732 .start
= WM831X_IRQ_CHG_END
,
733 .end
= WM831X_IRQ_CHG_END
,
734 .flags
= IORESOURCE_IRQ
,
738 .start
= WM831X_IRQ_CHG_TO
,
739 .end
= WM831X_IRQ_CHG_TO
,
740 .flags
= IORESOURCE_IRQ
,
744 .start
= WM831X_IRQ_CHG_MODE
,
745 .end
= WM831X_IRQ_CHG_MODE
,
746 .flags
= IORESOURCE_IRQ
,
750 .start
= WM831X_IRQ_CHG_START
,
751 .end
= WM831X_IRQ_CHG_START
,
752 .flags
= IORESOURCE_IRQ
,
756 static struct resource wm831x_rtc_resources
[] = {
759 .start
= WM831X_IRQ_RTC_PER
,
760 .end
= WM831X_IRQ_RTC_PER
,
761 .flags
= IORESOURCE_IRQ
,
765 .start
= WM831X_IRQ_RTC_ALM
,
766 .end
= WM831X_IRQ_RTC_ALM
,
767 .flags
= IORESOURCE_IRQ
,
771 static struct resource wm831x_status1_resources
[] = {
773 .start
= WM831X_STATUS_LED_1
,
774 .end
= WM831X_STATUS_LED_1
,
775 .flags
= IORESOURCE_IO
,
779 static struct resource wm831x_status2_resources
[] = {
781 .start
= WM831X_STATUS_LED_2
,
782 .end
= WM831X_STATUS_LED_2
,
783 .flags
= IORESOURCE_IO
,
787 static struct resource wm831x_touch_resources
[] = {
790 .start
= WM831X_IRQ_TCHPD
,
791 .end
= WM831X_IRQ_TCHPD
,
792 .flags
= IORESOURCE_IRQ
,
796 .start
= WM831X_IRQ_TCHDATA
,
797 .end
= WM831X_IRQ_TCHDATA
,
798 .flags
= IORESOURCE_IRQ
,
802 static struct resource wm831x_wdt_resources
[] = {
804 .start
= WM831X_IRQ_WDOG_TO
,
805 .end
= WM831X_IRQ_WDOG_TO
,
806 .flags
= IORESOURCE_IRQ
,
810 static struct mfd_cell wm8310_devs
[] = {
812 .name
= "wm831x-buckv",
814 .num_resources
= ARRAY_SIZE(wm831x_dcdc1_resources
),
815 .resources
= wm831x_dcdc1_resources
,
818 .name
= "wm831x-buckv",
820 .num_resources
= ARRAY_SIZE(wm831x_dcdc2_resources
),
821 .resources
= wm831x_dcdc2_resources
,
824 .name
= "wm831x-buckp",
826 .num_resources
= ARRAY_SIZE(wm831x_dcdc3_resources
),
827 .resources
= wm831x_dcdc3_resources
,
830 .name
= "wm831x-boostp",
832 .num_resources
= ARRAY_SIZE(wm831x_dcdc4_resources
),
833 .resources
= wm831x_dcdc4_resources
,
836 .name
= "wm831x-epe",
840 .name
= "wm831x-epe",
844 .name
= "wm831x-gpio",
845 .num_resources
= ARRAY_SIZE(wm831x_gpio_resources
),
846 .resources
= wm831x_gpio_resources
,
849 .name
= "wm831x-hwmon",
852 .name
= "wm831x-isink",
854 .num_resources
= ARRAY_SIZE(wm831x_isink1_resources
),
855 .resources
= wm831x_isink1_resources
,
858 .name
= "wm831x-isink",
860 .num_resources
= ARRAY_SIZE(wm831x_isink2_resources
),
861 .resources
= wm831x_isink2_resources
,
864 .name
= "wm831x-ldo",
866 .num_resources
= ARRAY_SIZE(wm831x_ldo1_resources
),
867 .resources
= wm831x_ldo1_resources
,
870 .name
= "wm831x-ldo",
872 .num_resources
= ARRAY_SIZE(wm831x_ldo2_resources
),
873 .resources
= wm831x_ldo2_resources
,
876 .name
= "wm831x-ldo",
878 .num_resources
= ARRAY_SIZE(wm831x_ldo3_resources
),
879 .resources
= wm831x_ldo3_resources
,
882 .name
= "wm831x-ldo",
884 .num_resources
= ARRAY_SIZE(wm831x_ldo4_resources
),
885 .resources
= wm831x_ldo4_resources
,
888 .name
= "wm831x-ldo",
890 .num_resources
= ARRAY_SIZE(wm831x_ldo5_resources
),
891 .resources
= wm831x_ldo5_resources
,
894 .name
= "wm831x-ldo",
896 .num_resources
= ARRAY_SIZE(wm831x_ldo6_resources
),
897 .resources
= wm831x_ldo6_resources
,
900 .name
= "wm831x-aldo",
902 .num_resources
= ARRAY_SIZE(wm831x_ldo7_resources
),
903 .resources
= wm831x_ldo7_resources
,
906 .name
= "wm831x-aldo",
908 .num_resources
= ARRAY_SIZE(wm831x_ldo8_resources
),
909 .resources
= wm831x_ldo8_resources
,
912 .name
= "wm831x-aldo",
914 .num_resources
= ARRAY_SIZE(wm831x_ldo9_resources
),
915 .resources
= wm831x_ldo9_resources
,
918 .name
= "wm831x-aldo",
920 .num_resources
= ARRAY_SIZE(wm831x_ldo10_resources
),
921 .resources
= wm831x_ldo10_resources
,
924 .name
= "wm831x-alive-ldo",
926 .num_resources
= ARRAY_SIZE(wm831x_ldo11_resources
),
927 .resources
= wm831x_ldo11_resources
,
931 .num_resources
= ARRAY_SIZE(wm831x_on_resources
),
932 .resources
= wm831x_on_resources
,
935 .name
= "wm831x-power",
936 .num_resources
= ARRAY_SIZE(wm831x_power_resources
),
937 .resources
= wm831x_power_resources
,
940 .name
= "wm831x-rtc",
941 .num_resources
= ARRAY_SIZE(wm831x_rtc_resources
),
942 .resources
= wm831x_rtc_resources
,
945 .name
= "wm831x-status",
947 .num_resources
= ARRAY_SIZE(wm831x_status1_resources
),
948 .resources
= wm831x_status1_resources
,
951 .name
= "wm831x-status",
953 .num_resources
= ARRAY_SIZE(wm831x_status2_resources
),
954 .resources
= wm831x_status2_resources
,
957 .name
= "wm831x-watchdog",
958 .num_resources
= ARRAY_SIZE(wm831x_wdt_resources
),
959 .resources
= wm831x_wdt_resources
,
963 static struct mfd_cell wm8311_devs
[] = {
965 .name
= "wm831x-buckv",
967 .num_resources
= ARRAY_SIZE(wm831x_dcdc1_resources
),
968 .resources
= wm831x_dcdc1_resources
,
971 .name
= "wm831x-buckv",
973 .num_resources
= ARRAY_SIZE(wm831x_dcdc2_resources
),
974 .resources
= wm831x_dcdc2_resources
,
977 .name
= "wm831x-buckp",
979 .num_resources
= ARRAY_SIZE(wm831x_dcdc3_resources
),
980 .resources
= wm831x_dcdc3_resources
,
983 .name
= "wm831x-boostp",
985 .num_resources
= ARRAY_SIZE(wm831x_dcdc4_resources
),
986 .resources
= wm831x_dcdc4_resources
,
989 .name
= "wm831x-epe",
993 .name
= "wm831x-epe",
997 .name
= "wm831x-gpio",
998 .num_resources
= ARRAY_SIZE(wm831x_gpio_resources
),
999 .resources
= wm831x_gpio_resources
,
1002 .name
= "wm831x-hwmon",
1005 .name
= "wm831x-isink",
1007 .num_resources
= ARRAY_SIZE(wm831x_isink1_resources
),
1008 .resources
= wm831x_isink1_resources
,
1011 .name
= "wm831x-isink",
1013 .num_resources
= ARRAY_SIZE(wm831x_isink2_resources
),
1014 .resources
= wm831x_isink2_resources
,
1017 .name
= "wm831x-ldo",
1019 .num_resources
= ARRAY_SIZE(wm831x_ldo1_resources
),
1020 .resources
= wm831x_ldo1_resources
,
1023 .name
= "wm831x-ldo",
1025 .num_resources
= ARRAY_SIZE(wm831x_ldo2_resources
),
1026 .resources
= wm831x_ldo2_resources
,
1029 .name
= "wm831x-ldo",
1031 .num_resources
= ARRAY_SIZE(wm831x_ldo3_resources
),
1032 .resources
= wm831x_ldo3_resources
,
1035 .name
= "wm831x-ldo",
1037 .num_resources
= ARRAY_SIZE(wm831x_ldo4_resources
),
1038 .resources
= wm831x_ldo4_resources
,
1041 .name
= "wm831x-ldo",
1043 .num_resources
= ARRAY_SIZE(wm831x_ldo5_resources
),
1044 .resources
= wm831x_ldo5_resources
,
1047 .name
= "wm831x-aldo",
1049 .num_resources
= ARRAY_SIZE(wm831x_ldo7_resources
),
1050 .resources
= wm831x_ldo7_resources
,
1053 .name
= "wm831x-alive-ldo",
1055 .num_resources
= ARRAY_SIZE(wm831x_ldo11_resources
),
1056 .resources
= wm831x_ldo11_resources
,
1059 .name
= "wm831x-on",
1060 .num_resources
= ARRAY_SIZE(wm831x_on_resources
),
1061 .resources
= wm831x_on_resources
,
1064 .name
= "wm831x-power",
1065 .num_resources
= ARRAY_SIZE(wm831x_power_resources
),
1066 .resources
= wm831x_power_resources
,
1069 .name
= "wm831x-rtc",
1070 .num_resources
= ARRAY_SIZE(wm831x_rtc_resources
),
1071 .resources
= wm831x_rtc_resources
,
1074 .name
= "wm831x-status",
1076 .num_resources
= ARRAY_SIZE(wm831x_status1_resources
),
1077 .resources
= wm831x_status1_resources
,
1080 .name
= "wm831x-status",
1082 .num_resources
= ARRAY_SIZE(wm831x_status2_resources
),
1083 .resources
= wm831x_status2_resources
,
1086 .name
= "wm831x-touch",
1087 .num_resources
= ARRAY_SIZE(wm831x_touch_resources
),
1088 .resources
= wm831x_touch_resources
,
1091 .name
= "wm831x-watchdog",
1092 .num_resources
= ARRAY_SIZE(wm831x_wdt_resources
),
1093 .resources
= wm831x_wdt_resources
,
1097 static struct mfd_cell wm8312_devs
[] = {
1099 .name
= "wm831x-buckv",
1101 .num_resources
= ARRAY_SIZE(wm831x_dcdc1_resources
),
1102 .resources
= wm831x_dcdc1_resources
,
1105 .name
= "wm831x-buckv",
1107 .num_resources
= ARRAY_SIZE(wm831x_dcdc2_resources
),
1108 .resources
= wm831x_dcdc2_resources
,
1111 .name
= "wm831x-buckp",
1113 .num_resources
= ARRAY_SIZE(wm831x_dcdc3_resources
),
1114 .resources
= wm831x_dcdc3_resources
,
1117 .name
= "wm831x-boostp",
1119 .num_resources
= ARRAY_SIZE(wm831x_dcdc4_resources
),
1120 .resources
= wm831x_dcdc4_resources
,
1123 .name
= "wm831x-epe",
1127 .name
= "wm831x-epe",
1131 .name
= "wm831x-gpio",
1132 .num_resources
= ARRAY_SIZE(wm831x_gpio_resources
),
1133 .resources
= wm831x_gpio_resources
,
1136 .name
= "wm831x-hwmon",
1139 .name
= "wm831x-isink",
1141 .num_resources
= ARRAY_SIZE(wm831x_isink1_resources
),
1142 .resources
= wm831x_isink1_resources
,
1145 .name
= "wm831x-isink",
1147 .num_resources
= ARRAY_SIZE(wm831x_isink2_resources
),
1148 .resources
= wm831x_isink2_resources
,
1151 .name
= "wm831x-ldo",
1153 .num_resources
= ARRAY_SIZE(wm831x_ldo1_resources
),
1154 .resources
= wm831x_ldo1_resources
,
1157 .name
= "wm831x-ldo",
1159 .num_resources
= ARRAY_SIZE(wm831x_ldo2_resources
),
1160 .resources
= wm831x_ldo2_resources
,
1163 .name
= "wm831x-ldo",
1165 .num_resources
= ARRAY_SIZE(wm831x_ldo3_resources
),
1166 .resources
= wm831x_ldo3_resources
,
1169 .name
= "wm831x-ldo",
1171 .num_resources
= ARRAY_SIZE(wm831x_ldo4_resources
),
1172 .resources
= wm831x_ldo4_resources
,
1175 .name
= "wm831x-ldo",
1177 .num_resources
= ARRAY_SIZE(wm831x_ldo5_resources
),
1178 .resources
= wm831x_ldo5_resources
,
1181 .name
= "wm831x-ldo",
1183 .num_resources
= ARRAY_SIZE(wm831x_ldo6_resources
),
1184 .resources
= wm831x_ldo6_resources
,
1187 .name
= "wm831x-aldo",
1189 .num_resources
= ARRAY_SIZE(wm831x_ldo7_resources
),
1190 .resources
= wm831x_ldo7_resources
,
1193 .name
= "wm831x-aldo",
1195 .num_resources
= ARRAY_SIZE(wm831x_ldo8_resources
),
1196 .resources
= wm831x_ldo8_resources
,
1199 .name
= "wm831x-aldo",
1201 .num_resources
= ARRAY_SIZE(wm831x_ldo9_resources
),
1202 .resources
= wm831x_ldo9_resources
,
1205 .name
= "wm831x-aldo",
1207 .num_resources
= ARRAY_SIZE(wm831x_ldo10_resources
),
1208 .resources
= wm831x_ldo10_resources
,
1211 .name
= "wm831x-alive-ldo",
1213 .num_resources
= ARRAY_SIZE(wm831x_ldo11_resources
),
1214 .resources
= wm831x_ldo11_resources
,
1217 .name
= "wm831x-on",
1218 .num_resources
= ARRAY_SIZE(wm831x_on_resources
),
1219 .resources
= wm831x_on_resources
,
1222 .name
= "wm831x-power",
1223 .num_resources
= ARRAY_SIZE(wm831x_power_resources
),
1224 .resources
= wm831x_power_resources
,
1227 .name
= "wm831x-rtc",
1228 .num_resources
= ARRAY_SIZE(wm831x_rtc_resources
),
1229 .resources
= wm831x_rtc_resources
,
1232 .name
= "wm831x-status",
1234 .num_resources
= ARRAY_SIZE(wm831x_status1_resources
),
1235 .resources
= wm831x_status1_resources
,
1238 .name
= "wm831x-status",
1240 .num_resources
= ARRAY_SIZE(wm831x_status2_resources
),
1241 .resources
= wm831x_status2_resources
,
1244 .name
= "wm831x-touch",
1245 .num_resources
= ARRAY_SIZE(wm831x_touch_resources
),
1246 .resources
= wm831x_touch_resources
,
1249 .name
= "wm831x-watchdog",
1250 .num_resources
= ARRAY_SIZE(wm831x_wdt_resources
),
1251 .resources
= wm831x_wdt_resources
,
1255 static struct mfd_cell wm8320_devs
[] = {
1257 .name
= "wm831x-backup",
1260 .name
= "wm831x-buckv",
1262 .num_resources
= ARRAY_SIZE(wm831x_dcdc1_resources
),
1263 .resources
= wm831x_dcdc1_resources
,
1266 .name
= "wm831x-buckv",
1268 .num_resources
= ARRAY_SIZE(wm831x_dcdc2_resources
),
1269 .resources
= wm831x_dcdc2_resources
,
1272 .name
= "wm831x-buckp",
1274 .num_resources
= ARRAY_SIZE(wm831x_dcdc3_resources
),
1275 .resources
= wm831x_dcdc3_resources
,
1278 .name
= "wm831x-buckp",
1280 .num_resources
= ARRAY_SIZE(wm8320_dcdc4_buck_resources
),
1281 .resources
= wm8320_dcdc4_buck_resources
,
1284 .name
= "wm831x-gpio",
1285 .num_resources
= ARRAY_SIZE(wm831x_gpio_resources
),
1286 .resources
= wm831x_gpio_resources
,
1289 .name
= "wm831x-hwmon",
1292 .name
= "wm831x-ldo",
1294 .num_resources
= ARRAY_SIZE(wm831x_ldo1_resources
),
1295 .resources
= wm831x_ldo1_resources
,
1298 .name
= "wm831x-ldo",
1300 .num_resources
= ARRAY_SIZE(wm831x_ldo2_resources
),
1301 .resources
= wm831x_ldo2_resources
,
1304 .name
= "wm831x-ldo",
1306 .num_resources
= ARRAY_SIZE(wm831x_ldo3_resources
),
1307 .resources
= wm831x_ldo3_resources
,
1310 .name
= "wm831x-ldo",
1312 .num_resources
= ARRAY_SIZE(wm831x_ldo4_resources
),
1313 .resources
= wm831x_ldo4_resources
,
1316 .name
= "wm831x-ldo",
1318 .num_resources
= ARRAY_SIZE(wm831x_ldo5_resources
),
1319 .resources
= wm831x_ldo5_resources
,
1322 .name
= "wm831x-ldo",
1324 .num_resources
= ARRAY_SIZE(wm831x_ldo6_resources
),
1325 .resources
= wm831x_ldo6_resources
,
1328 .name
= "wm831x-aldo",
1330 .num_resources
= ARRAY_SIZE(wm831x_ldo7_resources
),
1331 .resources
= wm831x_ldo7_resources
,
1334 .name
= "wm831x-aldo",
1336 .num_resources
= ARRAY_SIZE(wm831x_ldo8_resources
),
1337 .resources
= wm831x_ldo8_resources
,
1340 .name
= "wm831x-aldo",
1342 .num_resources
= ARRAY_SIZE(wm831x_ldo9_resources
),
1343 .resources
= wm831x_ldo9_resources
,
1346 .name
= "wm831x-aldo",
1348 .num_resources
= ARRAY_SIZE(wm831x_ldo10_resources
),
1349 .resources
= wm831x_ldo10_resources
,
1352 .name
= "wm831x-alive-ldo",
1354 .num_resources
= ARRAY_SIZE(wm831x_ldo11_resources
),
1355 .resources
= wm831x_ldo11_resources
,
1358 .name
= "wm831x-on",
1359 .num_resources
= ARRAY_SIZE(wm831x_on_resources
),
1360 .resources
= wm831x_on_resources
,
1363 .name
= "wm831x-rtc",
1364 .num_resources
= ARRAY_SIZE(wm831x_rtc_resources
),
1365 .resources
= wm831x_rtc_resources
,
1368 .name
= "wm831x-status",
1370 .num_resources
= ARRAY_SIZE(wm831x_status1_resources
),
1371 .resources
= wm831x_status1_resources
,
1374 .name
= "wm831x-status",
1376 .num_resources
= ARRAY_SIZE(wm831x_status2_resources
),
1377 .resources
= wm831x_status2_resources
,
1380 .name
= "wm831x-watchdog",
1381 .num_resources
= ARRAY_SIZE(wm831x_wdt_resources
),
1382 .resources
= wm831x_wdt_resources
,
1386 static struct mfd_cell backlight_devs
[] = {
1388 .name
= "wm831x-backlight",
1393 * Instantiate the generic non-control parts of the device.
1395 static int wm831x_device_init(struct wm831x
*wm831x
, unsigned long id
, int irq
)
1397 struct wm831x_pdata
*pdata
= wm831x
->dev
->platform_data
;
1399 enum wm831x_parent parent
;
1402 mutex_init(&wm831x
->io_lock
);
1403 mutex_init(&wm831x
->key_lock
);
1404 mutex_init(&wm831x
->auxadc_lock
);
1405 dev_set_drvdata(wm831x
->dev
, wm831x
);
1407 ret
= wm831x_reg_read(wm831x
, WM831X_PARENT_ID
);
1409 dev_err(wm831x
->dev
, "Failed to read parent ID: %d\n", ret
);
1412 if (ret
!= 0x6204) {
1413 dev_err(wm831x
->dev
, "Device is not a WM831x: ID %x\n", ret
);
1418 ret
= wm831x_reg_read(wm831x
, WM831X_REVISION
);
1420 dev_err(wm831x
->dev
, "Failed to read revision: %d\n", ret
);
1423 rev
= (ret
& WM831X_PARENT_REV_MASK
) >> WM831X_PARENT_REV_SHIFT
;
1425 ret
= wm831x_reg_read(wm831x
, WM831X_RESET_ID
);
1427 dev_err(wm831x
->dev
, "Failed to read device ID: %d\n", ret
);
1431 /* Some engineering samples do not have the ID set, rely on
1432 * the device being registered correctly.
1435 dev_info(wm831x
->dev
, "Device is an engineering sample\n");
1442 wm831x
->num_gpio
= 16;
1443 dev_info(wm831x
->dev
, "WM8310 revision %c\n", 'A' + rev
);
1448 wm831x
->num_gpio
= 16;
1449 dev_info(wm831x
->dev
, "WM8311 revision %c\n", 'A' + rev
);
1454 wm831x
->num_gpio
= 16;
1455 dev_info(wm831x
->dev
, "WM8312 revision %c\n", 'A' + rev
);
1460 wm831x
->num_gpio
= 12;
1461 dev_info(wm831x
->dev
, "WM8320 revision %c\n", 'A' + rev
);
1465 dev_err(wm831x
->dev
, "Unknown WM831x device %04x\n", ret
);
1470 /* This will need revisiting in future but is OK for all
1474 dev_warn(wm831x
->dev
, "Device was registered as a WM%lx\n",
1477 /* Bootstrap the user key */
1478 ret
= wm831x_reg_read(wm831x
, WM831X_SECURITY_KEY
);
1480 dev_err(wm831x
->dev
, "Failed to read security key: %d\n", ret
);
1484 dev_warn(wm831x
->dev
, "Security key had non-zero value %x\n",
1486 wm831x_reg_write(wm831x
, WM831X_SECURITY_KEY
, 0);
1490 if (pdata
&& pdata
->pre_init
) {
1491 ret
= pdata
->pre_init(wm831x
);
1493 dev_err(wm831x
->dev
, "pre_init() failed: %d\n", ret
);
1498 ret
= wm831x_irq_init(wm831x
, irq
);
1502 /* The core device is up, instantiate the subdevices. */
1505 ret
= mfd_add_devices(wm831x
->dev
, -1,
1506 wm8310_devs
, ARRAY_SIZE(wm8310_devs
),
1511 ret
= mfd_add_devices(wm831x
->dev
, -1,
1512 wm8311_devs
, ARRAY_SIZE(wm8311_devs
),
1517 ret
= mfd_add_devices(wm831x
->dev
, -1,
1518 wm8312_devs
, ARRAY_SIZE(wm8312_devs
),
1523 ret
= mfd_add_devices(wm831x
->dev
, -1,
1524 wm8320_devs
, ARRAY_SIZE(wm8320_devs
),
1529 /* If this happens the bus probe function is buggy */
1534 dev_err(wm831x
->dev
, "Failed to add children\n");
1538 if (pdata
&& pdata
->backlight
) {
1539 /* Treat errors as non-critical */
1540 ret
= mfd_add_devices(wm831x
->dev
, -1, backlight_devs
,
1541 ARRAY_SIZE(backlight_devs
), NULL
, 0);
1543 dev_err(wm831x
->dev
, "Failed to add backlight: %d\n",
1547 wm831x_otp_init(wm831x
);
1549 if (pdata
&& pdata
->post_init
) {
1550 ret
= pdata
->post_init(wm831x
);
1552 dev_err(wm831x
->dev
, "post_init() failed: %d\n", ret
);
1560 wm831x_irq_exit(wm831x
);
1562 mfd_remove_devices(wm831x
->dev
);
1567 static void wm831x_device_exit(struct wm831x
*wm831x
)
1569 wm831x_otp_exit(wm831x
);
1570 mfd_remove_devices(wm831x
->dev
);
1571 wm831x_irq_exit(wm831x
);
1575 static int wm831x_i2c_read_device(struct wm831x
*wm831x
, unsigned short reg
,
1576 int bytes
, void *dest
)
1578 struct i2c_client
*i2c
= wm831x
->control_data
;
1580 u16 r
= cpu_to_be16(reg
);
1582 ret
= i2c_master_send(i2c
, (unsigned char *)&r
, 2);
1588 ret
= i2c_master_recv(i2c
, dest
, bytes
);
1596 /* Currently we allocate the write buffer on the stack; this is OK for
1597 * small writes - if we need to do large writes this will need to be
1600 static int wm831x_i2c_write_device(struct wm831x
*wm831x
, unsigned short reg
,
1601 int bytes
, void *src
)
1603 struct i2c_client
*i2c
= wm831x
->control_data
;
1604 unsigned char msg
[bytes
+ 2];
1607 reg
= cpu_to_be16(reg
);
1608 memcpy(&msg
[0], ®
, 2);
1609 memcpy(&msg
[2], src
, bytes
);
1611 ret
= i2c_master_send(i2c
, msg
, bytes
+ 2);
1614 if (ret
< bytes
+ 2)
1620 static int wm831x_i2c_probe(struct i2c_client
*i2c
,
1621 const struct i2c_device_id
*id
)
1623 struct wm831x
*wm831x
;
1625 wm831x
= kzalloc(sizeof(struct wm831x
), GFP_KERNEL
);
1626 if (wm831x
== NULL
) {
1631 i2c_set_clientdata(i2c
, wm831x
);
1632 wm831x
->dev
= &i2c
->dev
;
1633 wm831x
->control_data
= i2c
;
1634 wm831x
->read_dev
= wm831x_i2c_read_device
;
1635 wm831x
->write_dev
= wm831x_i2c_write_device
;
1637 return wm831x_device_init(wm831x
, id
->driver_data
, i2c
->irq
);
1640 static int wm831x_i2c_remove(struct i2c_client
*i2c
)
1642 struct wm831x
*wm831x
= i2c_get_clientdata(i2c
);
1644 wm831x_device_exit(wm831x
);
1649 static const struct i2c_device_id wm831x_i2c_id
[] = {
1650 { "wm8310", WM8310
},
1651 { "wm8311", WM8311
},
1652 { "wm8312", WM8312
},
1653 { "wm8320", WM8320
},
1656 MODULE_DEVICE_TABLE(i2c
, wm831x_i2c_id
);
1659 static struct i2c_driver wm831x_i2c_driver
= {
1662 .owner
= THIS_MODULE
,
1664 .probe
= wm831x_i2c_probe
,
1665 .remove
= wm831x_i2c_remove
,
1666 .id_table
= wm831x_i2c_id
,
1669 static int __init
wm831x_i2c_init(void)
1673 ret
= i2c_add_driver(&wm831x_i2c_driver
);
1675 pr_err("Failed to register wm831x I2C driver: %d\n", ret
);
1679 subsys_initcall(wm831x_i2c_init
);
1681 static void __exit
wm831x_i2c_exit(void)
1683 i2c_del_driver(&wm831x_i2c_driver
);
1685 module_exit(wm831x_i2c_exit
);
1687 MODULE_DESCRIPTION("I2C support for the WM831X AudioPlus PMIC");
1688 MODULE_LICENSE("GPL");
1689 MODULE_AUTHOR("Mark Brown");