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
+ 1] = {
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-backup",
815 .name
= "wm831x-buckv",
817 .num_resources
= ARRAY_SIZE(wm831x_dcdc1_resources
),
818 .resources
= wm831x_dcdc1_resources
,
821 .name
= "wm831x-buckv",
823 .num_resources
= ARRAY_SIZE(wm831x_dcdc2_resources
),
824 .resources
= wm831x_dcdc2_resources
,
827 .name
= "wm831x-buckp",
829 .num_resources
= ARRAY_SIZE(wm831x_dcdc3_resources
),
830 .resources
= wm831x_dcdc3_resources
,
833 .name
= "wm831x-boostp",
835 .num_resources
= ARRAY_SIZE(wm831x_dcdc4_resources
),
836 .resources
= wm831x_dcdc4_resources
,
839 .name
= "wm831x-epe",
843 .name
= "wm831x-epe",
847 .name
= "wm831x-gpio",
848 .num_resources
= ARRAY_SIZE(wm831x_gpio_resources
),
849 .resources
= wm831x_gpio_resources
,
852 .name
= "wm831x-hwmon",
855 .name
= "wm831x-isink",
857 .num_resources
= ARRAY_SIZE(wm831x_isink1_resources
),
858 .resources
= wm831x_isink1_resources
,
861 .name
= "wm831x-isink",
863 .num_resources
= ARRAY_SIZE(wm831x_isink2_resources
),
864 .resources
= wm831x_isink2_resources
,
867 .name
= "wm831x-ldo",
869 .num_resources
= ARRAY_SIZE(wm831x_ldo1_resources
),
870 .resources
= wm831x_ldo1_resources
,
873 .name
= "wm831x-ldo",
875 .num_resources
= ARRAY_SIZE(wm831x_ldo2_resources
),
876 .resources
= wm831x_ldo2_resources
,
879 .name
= "wm831x-ldo",
881 .num_resources
= ARRAY_SIZE(wm831x_ldo3_resources
),
882 .resources
= wm831x_ldo3_resources
,
885 .name
= "wm831x-ldo",
887 .num_resources
= ARRAY_SIZE(wm831x_ldo4_resources
),
888 .resources
= wm831x_ldo4_resources
,
891 .name
= "wm831x-ldo",
893 .num_resources
= ARRAY_SIZE(wm831x_ldo5_resources
),
894 .resources
= wm831x_ldo5_resources
,
897 .name
= "wm831x-ldo",
899 .num_resources
= ARRAY_SIZE(wm831x_ldo6_resources
),
900 .resources
= wm831x_ldo6_resources
,
903 .name
= "wm831x-aldo",
905 .num_resources
= ARRAY_SIZE(wm831x_ldo7_resources
),
906 .resources
= wm831x_ldo7_resources
,
909 .name
= "wm831x-aldo",
911 .num_resources
= ARRAY_SIZE(wm831x_ldo8_resources
),
912 .resources
= wm831x_ldo8_resources
,
915 .name
= "wm831x-aldo",
917 .num_resources
= ARRAY_SIZE(wm831x_ldo9_resources
),
918 .resources
= wm831x_ldo9_resources
,
921 .name
= "wm831x-aldo",
923 .num_resources
= ARRAY_SIZE(wm831x_ldo10_resources
),
924 .resources
= wm831x_ldo10_resources
,
927 .name
= "wm831x-alive-ldo",
929 .num_resources
= ARRAY_SIZE(wm831x_ldo11_resources
),
930 .resources
= wm831x_ldo11_resources
,
934 .num_resources
= ARRAY_SIZE(wm831x_on_resources
),
935 .resources
= wm831x_on_resources
,
938 .name
= "wm831x-power",
939 .num_resources
= ARRAY_SIZE(wm831x_power_resources
),
940 .resources
= wm831x_power_resources
,
943 .name
= "wm831x-rtc",
944 .num_resources
= ARRAY_SIZE(wm831x_rtc_resources
),
945 .resources
= wm831x_rtc_resources
,
948 .name
= "wm831x-status",
950 .num_resources
= ARRAY_SIZE(wm831x_status1_resources
),
951 .resources
= wm831x_status1_resources
,
954 .name
= "wm831x-status",
956 .num_resources
= ARRAY_SIZE(wm831x_status2_resources
),
957 .resources
= wm831x_status2_resources
,
960 .name
= "wm831x-watchdog",
961 .num_resources
= ARRAY_SIZE(wm831x_wdt_resources
),
962 .resources
= wm831x_wdt_resources
,
966 static struct mfd_cell wm8311_devs
[] = {
968 .name
= "wm831x-backup",
971 .name
= "wm831x-buckv",
973 .num_resources
= ARRAY_SIZE(wm831x_dcdc1_resources
),
974 .resources
= wm831x_dcdc1_resources
,
977 .name
= "wm831x-buckv",
979 .num_resources
= ARRAY_SIZE(wm831x_dcdc2_resources
),
980 .resources
= wm831x_dcdc2_resources
,
983 .name
= "wm831x-buckp",
985 .num_resources
= ARRAY_SIZE(wm831x_dcdc3_resources
),
986 .resources
= wm831x_dcdc3_resources
,
989 .name
= "wm831x-boostp",
991 .num_resources
= ARRAY_SIZE(wm831x_dcdc4_resources
),
992 .resources
= wm831x_dcdc4_resources
,
995 .name
= "wm831x-epe",
999 .name
= "wm831x-epe",
1003 .name
= "wm831x-gpio",
1004 .num_resources
= ARRAY_SIZE(wm831x_gpio_resources
),
1005 .resources
= wm831x_gpio_resources
,
1008 .name
= "wm831x-hwmon",
1011 .name
= "wm831x-isink",
1013 .num_resources
= ARRAY_SIZE(wm831x_isink1_resources
),
1014 .resources
= wm831x_isink1_resources
,
1017 .name
= "wm831x-isink",
1019 .num_resources
= ARRAY_SIZE(wm831x_isink2_resources
),
1020 .resources
= wm831x_isink2_resources
,
1023 .name
= "wm831x-ldo",
1025 .num_resources
= ARRAY_SIZE(wm831x_ldo1_resources
),
1026 .resources
= wm831x_ldo1_resources
,
1029 .name
= "wm831x-ldo",
1031 .num_resources
= ARRAY_SIZE(wm831x_ldo2_resources
),
1032 .resources
= wm831x_ldo2_resources
,
1035 .name
= "wm831x-ldo",
1037 .num_resources
= ARRAY_SIZE(wm831x_ldo3_resources
),
1038 .resources
= wm831x_ldo3_resources
,
1041 .name
= "wm831x-ldo",
1043 .num_resources
= ARRAY_SIZE(wm831x_ldo4_resources
),
1044 .resources
= wm831x_ldo4_resources
,
1047 .name
= "wm831x-ldo",
1049 .num_resources
= ARRAY_SIZE(wm831x_ldo5_resources
),
1050 .resources
= wm831x_ldo5_resources
,
1053 .name
= "wm831x-aldo",
1055 .num_resources
= ARRAY_SIZE(wm831x_ldo7_resources
),
1056 .resources
= wm831x_ldo7_resources
,
1059 .name
= "wm831x-alive-ldo",
1061 .num_resources
= ARRAY_SIZE(wm831x_ldo11_resources
),
1062 .resources
= wm831x_ldo11_resources
,
1065 .name
= "wm831x-on",
1066 .num_resources
= ARRAY_SIZE(wm831x_on_resources
),
1067 .resources
= wm831x_on_resources
,
1070 .name
= "wm831x-power",
1071 .num_resources
= ARRAY_SIZE(wm831x_power_resources
),
1072 .resources
= wm831x_power_resources
,
1075 .name
= "wm831x-rtc",
1076 .num_resources
= ARRAY_SIZE(wm831x_rtc_resources
),
1077 .resources
= wm831x_rtc_resources
,
1080 .name
= "wm831x-status",
1082 .num_resources
= ARRAY_SIZE(wm831x_status1_resources
),
1083 .resources
= wm831x_status1_resources
,
1086 .name
= "wm831x-status",
1088 .num_resources
= ARRAY_SIZE(wm831x_status2_resources
),
1089 .resources
= wm831x_status2_resources
,
1092 .name
= "wm831x-touch",
1093 .num_resources
= ARRAY_SIZE(wm831x_touch_resources
),
1094 .resources
= wm831x_touch_resources
,
1097 .name
= "wm831x-watchdog",
1098 .num_resources
= ARRAY_SIZE(wm831x_wdt_resources
),
1099 .resources
= wm831x_wdt_resources
,
1103 static struct mfd_cell wm8312_devs
[] = {
1105 .name
= "wm831x-backup",
1108 .name
= "wm831x-buckv",
1110 .num_resources
= ARRAY_SIZE(wm831x_dcdc1_resources
),
1111 .resources
= wm831x_dcdc1_resources
,
1114 .name
= "wm831x-buckv",
1116 .num_resources
= ARRAY_SIZE(wm831x_dcdc2_resources
),
1117 .resources
= wm831x_dcdc2_resources
,
1120 .name
= "wm831x-buckp",
1122 .num_resources
= ARRAY_SIZE(wm831x_dcdc3_resources
),
1123 .resources
= wm831x_dcdc3_resources
,
1126 .name
= "wm831x-boostp",
1128 .num_resources
= ARRAY_SIZE(wm831x_dcdc4_resources
),
1129 .resources
= wm831x_dcdc4_resources
,
1132 .name
= "wm831x-epe",
1136 .name
= "wm831x-epe",
1140 .name
= "wm831x-gpio",
1141 .num_resources
= ARRAY_SIZE(wm831x_gpio_resources
),
1142 .resources
= wm831x_gpio_resources
,
1145 .name
= "wm831x-hwmon",
1148 .name
= "wm831x-isink",
1150 .num_resources
= ARRAY_SIZE(wm831x_isink1_resources
),
1151 .resources
= wm831x_isink1_resources
,
1154 .name
= "wm831x-isink",
1156 .num_resources
= ARRAY_SIZE(wm831x_isink2_resources
),
1157 .resources
= wm831x_isink2_resources
,
1160 .name
= "wm831x-ldo",
1162 .num_resources
= ARRAY_SIZE(wm831x_ldo1_resources
),
1163 .resources
= wm831x_ldo1_resources
,
1166 .name
= "wm831x-ldo",
1168 .num_resources
= ARRAY_SIZE(wm831x_ldo2_resources
),
1169 .resources
= wm831x_ldo2_resources
,
1172 .name
= "wm831x-ldo",
1174 .num_resources
= ARRAY_SIZE(wm831x_ldo3_resources
),
1175 .resources
= wm831x_ldo3_resources
,
1178 .name
= "wm831x-ldo",
1180 .num_resources
= ARRAY_SIZE(wm831x_ldo4_resources
),
1181 .resources
= wm831x_ldo4_resources
,
1184 .name
= "wm831x-ldo",
1186 .num_resources
= ARRAY_SIZE(wm831x_ldo5_resources
),
1187 .resources
= wm831x_ldo5_resources
,
1190 .name
= "wm831x-ldo",
1192 .num_resources
= ARRAY_SIZE(wm831x_ldo6_resources
),
1193 .resources
= wm831x_ldo6_resources
,
1196 .name
= "wm831x-aldo",
1198 .num_resources
= ARRAY_SIZE(wm831x_ldo7_resources
),
1199 .resources
= wm831x_ldo7_resources
,
1202 .name
= "wm831x-aldo",
1204 .num_resources
= ARRAY_SIZE(wm831x_ldo8_resources
),
1205 .resources
= wm831x_ldo8_resources
,
1208 .name
= "wm831x-aldo",
1210 .num_resources
= ARRAY_SIZE(wm831x_ldo9_resources
),
1211 .resources
= wm831x_ldo9_resources
,
1214 .name
= "wm831x-aldo",
1216 .num_resources
= ARRAY_SIZE(wm831x_ldo10_resources
),
1217 .resources
= wm831x_ldo10_resources
,
1220 .name
= "wm831x-alive-ldo",
1222 .num_resources
= ARRAY_SIZE(wm831x_ldo11_resources
),
1223 .resources
= wm831x_ldo11_resources
,
1226 .name
= "wm831x-on",
1227 .num_resources
= ARRAY_SIZE(wm831x_on_resources
),
1228 .resources
= wm831x_on_resources
,
1231 .name
= "wm831x-power",
1232 .num_resources
= ARRAY_SIZE(wm831x_power_resources
),
1233 .resources
= wm831x_power_resources
,
1236 .name
= "wm831x-rtc",
1237 .num_resources
= ARRAY_SIZE(wm831x_rtc_resources
),
1238 .resources
= wm831x_rtc_resources
,
1241 .name
= "wm831x-status",
1243 .num_resources
= ARRAY_SIZE(wm831x_status1_resources
),
1244 .resources
= wm831x_status1_resources
,
1247 .name
= "wm831x-status",
1249 .num_resources
= ARRAY_SIZE(wm831x_status2_resources
),
1250 .resources
= wm831x_status2_resources
,
1253 .name
= "wm831x-touch",
1254 .num_resources
= ARRAY_SIZE(wm831x_touch_resources
),
1255 .resources
= wm831x_touch_resources
,
1258 .name
= "wm831x-watchdog",
1259 .num_resources
= ARRAY_SIZE(wm831x_wdt_resources
),
1260 .resources
= wm831x_wdt_resources
,
1264 static struct mfd_cell wm8320_devs
[] = {
1266 .name
= "wm831x-backup",
1269 .name
= "wm831x-buckv",
1271 .num_resources
= ARRAY_SIZE(wm831x_dcdc1_resources
),
1272 .resources
= wm831x_dcdc1_resources
,
1275 .name
= "wm831x-buckv",
1277 .num_resources
= ARRAY_SIZE(wm831x_dcdc2_resources
),
1278 .resources
= wm831x_dcdc2_resources
,
1281 .name
= "wm831x-buckp",
1283 .num_resources
= ARRAY_SIZE(wm831x_dcdc3_resources
),
1284 .resources
= wm831x_dcdc3_resources
,
1287 .name
= "wm831x-buckp",
1289 .num_resources
= ARRAY_SIZE(wm8320_dcdc4_buck_resources
),
1290 .resources
= wm8320_dcdc4_buck_resources
,
1293 .name
= "wm831x-gpio",
1294 .num_resources
= ARRAY_SIZE(wm831x_gpio_resources
),
1295 .resources
= wm831x_gpio_resources
,
1298 .name
= "wm831x-hwmon",
1301 .name
= "wm831x-ldo",
1303 .num_resources
= ARRAY_SIZE(wm831x_ldo1_resources
),
1304 .resources
= wm831x_ldo1_resources
,
1307 .name
= "wm831x-ldo",
1309 .num_resources
= ARRAY_SIZE(wm831x_ldo2_resources
),
1310 .resources
= wm831x_ldo2_resources
,
1313 .name
= "wm831x-ldo",
1315 .num_resources
= ARRAY_SIZE(wm831x_ldo3_resources
),
1316 .resources
= wm831x_ldo3_resources
,
1319 .name
= "wm831x-ldo",
1321 .num_resources
= ARRAY_SIZE(wm831x_ldo4_resources
),
1322 .resources
= wm831x_ldo4_resources
,
1325 .name
= "wm831x-ldo",
1327 .num_resources
= ARRAY_SIZE(wm831x_ldo5_resources
),
1328 .resources
= wm831x_ldo5_resources
,
1331 .name
= "wm831x-ldo",
1333 .num_resources
= ARRAY_SIZE(wm831x_ldo6_resources
),
1334 .resources
= wm831x_ldo6_resources
,
1337 .name
= "wm831x-aldo",
1339 .num_resources
= ARRAY_SIZE(wm831x_ldo7_resources
),
1340 .resources
= wm831x_ldo7_resources
,
1343 .name
= "wm831x-aldo",
1345 .num_resources
= ARRAY_SIZE(wm831x_ldo8_resources
),
1346 .resources
= wm831x_ldo8_resources
,
1349 .name
= "wm831x-aldo",
1351 .num_resources
= ARRAY_SIZE(wm831x_ldo9_resources
),
1352 .resources
= wm831x_ldo9_resources
,
1355 .name
= "wm831x-aldo",
1357 .num_resources
= ARRAY_SIZE(wm831x_ldo10_resources
),
1358 .resources
= wm831x_ldo10_resources
,
1361 .name
= "wm831x-alive-ldo",
1363 .num_resources
= ARRAY_SIZE(wm831x_ldo11_resources
),
1364 .resources
= wm831x_ldo11_resources
,
1367 .name
= "wm831x-on",
1368 .num_resources
= ARRAY_SIZE(wm831x_on_resources
),
1369 .resources
= wm831x_on_resources
,
1372 .name
= "wm831x-rtc",
1373 .num_resources
= ARRAY_SIZE(wm831x_rtc_resources
),
1374 .resources
= wm831x_rtc_resources
,
1377 .name
= "wm831x-status",
1379 .num_resources
= ARRAY_SIZE(wm831x_status1_resources
),
1380 .resources
= wm831x_status1_resources
,
1383 .name
= "wm831x-status",
1385 .num_resources
= ARRAY_SIZE(wm831x_status2_resources
),
1386 .resources
= wm831x_status2_resources
,
1389 .name
= "wm831x-watchdog",
1390 .num_resources
= ARRAY_SIZE(wm831x_wdt_resources
),
1391 .resources
= wm831x_wdt_resources
,
1395 static struct mfd_cell backlight_devs
[] = {
1397 .name
= "wm831x-backlight",
1402 * Instantiate the generic non-control parts of the device.
1404 static int wm831x_device_init(struct wm831x
*wm831x
, unsigned long id
, int irq
)
1406 struct wm831x_pdata
*pdata
= wm831x
->dev
->platform_data
;
1408 enum wm831x_parent parent
;
1411 mutex_init(&wm831x
->io_lock
);
1412 mutex_init(&wm831x
->key_lock
);
1413 mutex_init(&wm831x
->auxadc_lock
);
1414 dev_set_drvdata(wm831x
->dev
, wm831x
);
1416 ret
= wm831x_reg_read(wm831x
, WM831X_PARENT_ID
);
1418 dev_err(wm831x
->dev
, "Failed to read parent ID: %d\n", ret
);
1421 if (ret
!= 0x6204) {
1422 dev_err(wm831x
->dev
, "Device is not a WM831x: ID %x\n", ret
);
1427 ret
= wm831x_reg_read(wm831x
, WM831X_REVISION
);
1429 dev_err(wm831x
->dev
, "Failed to read revision: %d\n", ret
);
1432 rev
= (ret
& WM831X_PARENT_REV_MASK
) >> WM831X_PARENT_REV_SHIFT
;
1434 ret
= wm831x_reg_read(wm831x
, WM831X_RESET_ID
);
1436 dev_err(wm831x
->dev
, "Failed to read device ID: %d\n", ret
);
1440 /* Some engineering samples do not have the ID set, rely on
1441 * the device being registered correctly.
1444 dev_info(wm831x
->dev
, "Device is an engineering sample\n");
1451 wm831x
->num_gpio
= 16;
1452 dev_info(wm831x
->dev
, "WM8310 revision %c\n", 'A' + rev
);
1457 wm831x
->num_gpio
= 16;
1458 dev_info(wm831x
->dev
, "WM8311 revision %c\n", 'A' + rev
);
1463 wm831x
->num_gpio
= 16;
1464 dev_info(wm831x
->dev
, "WM8312 revision %c\n", 'A' + rev
);
1469 wm831x
->num_gpio
= 12;
1470 dev_info(wm831x
->dev
, "WM8320 revision %c\n", 'A' + rev
);
1474 dev_err(wm831x
->dev
, "Unknown WM831x device %04x\n", ret
);
1479 /* This will need revisiting in future but is OK for all
1483 dev_warn(wm831x
->dev
, "Device was registered as a WM%lx\n",
1486 /* Bootstrap the user key */
1487 ret
= wm831x_reg_read(wm831x
, WM831X_SECURITY_KEY
);
1489 dev_err(wm831x
->dev
, "Failed to read security key: %d\n", ret
);
1493 dev_warn(wm831x
->dev
, "Security key had non-zero value %x\n",
1495 wm831x_reg_write(wm831x
, WM831X_SECURITY_KEY
, 0);
1499 if (pdata
&& pdata
->pre_init
) {
1500 ret
= pdata
->pre_init(wm831x
);
1502 dev_err(wm831x
->dev
, "pre_init() failed: %d\n", ret
);
1507 ret
= wm831x_irq_init(wm831x
, irq
);
1511 /* The core device is up, instantiate the subdevices. */
1514 ret
= mfd_add_devices(wm831x
->dev
, -1,
1515 wm8310_devs
, ARRAY_SIZE(wm8310_devs
),
1516 NULL
, wm831x
->irq_base
);
1520 ret
= mfd_add_devices(wm831x
->dev
, -1,
1521 wm8311_devs
, ARRAY_SIZE(wm8311_devs
),
1522 NULL
, wm831x
->irq_base
);
1526 ret
= mfd_add_devices(wm831x
->dev
, -1,
1527 wm8312_devs
, ARRAY_SIZE(wm8312_devs
),
1528 NULL
, wm831x
->irq_base
);
1532 ret
= mfd_add_devices(wm831x
->dev
, -1,
1533 wm8320_devs
, ARRAY_SIZE(wm8320_devs
),
1538 /* If this happens the bus probe function is buggy */
1543 dev_err(wm831x
->dev
, "Failed to add children\n");
1547 if (pdata
&& pdata
->backlight
) {
1548 /* Treat errors as non-critical */
1549 ret
= mfd_add_devices(wm831x
->dev
, -1, backlight_devs
,
1550 ARRAY_SIZE(backlight_devs
), NULL
,
1553 dev_err(wm831x
->dev
, "Failed to add backlight: %d\n",
1557 wm831x_otp_init(wm831x
);
1559 if (pdata
&& pdata
->post_init
) {
1560 ret
= pdata
->post_init(wm831x
);
1562 dev_err(wm831x
->dev
, "post_init() failed: %d\n", ret
);
1570 wm831x_irq_exit(wm831x
);
1572 mfd_remove_devices(wm831x
->dev
);
1577 static void wm831x_device_exit(struct wm831x
*wm831x
)
1579 wm831x_otp_exit(wm831x
);
1580 mfd_remove_devices(wm831x
->dev
);
1581 wm831x_irq_exit(wm831x
);
1585 static int wm831x_i2c_read_device(struct wm831x
*wm831x
, unsigned short reg
,
1586 int bytes
, void *dest
)
1588 struct i2c_client
*i2c
= wm831x
->control_data
;
1590 u16 r
= cpu_to_be16(reg
);
1592 ret
= i2c_master_send(i2c
, (unsigned char *)&r
, 2);
1598 ret
= i2c_master_recv(i2c
, dest
, bytes
);
1606 /* Currently we allocate the write buffer on the stack; this is OK for
1607 * small writes - if we need to do large writes this will need to be
1610 static int wm831x_i2c_write_device(struct wm831x
*wm831x
, unsigned short reg
,
1611 int bytes
, void *src
)
1613 struct i2c_client
*i2c
= wm831x
->control_data
;
1614 unsigned char msg
[bytes
+ 2];
1617 reg
= cpu_to_be16(reg
);
1618 memcpy(&msg
[0], ®
, 2);
1619 memcpy(&msg
[2], src
, bytes
);
1621 ret
= i2c_master_send(i2c
, msg
, bytes
+ 2);
1624 if (ret
< bytes
+ 2)
1630 static int wm831x_i2c_probe(struct i2c_client
*i2c
,
1631 const struct i2c_device_id
*id
)
1633 struct wm831x
*wm831x
;
1635 wm831x
= kzalloc(sizeof(struct wm831x
), GFP_KERNEL
);
1636 if (wm831x
== NULL
) {
1641 i2c_set_clientdata(i2c
, wm831x
);
1642 wm831x
->dev
= &i2c
->dev
;
1643 wm831x
->control_data
= i2c
;
1644 wm831x
->read_dev
= wm831x_i2c_read_device
;
1645 wm831x
->write_dev
= wm831x_i2c_write_device
;
1647 return wm831x_device_init(wm831x
, id
->driver_data
, i2c
->irq
);
1650 static int wm831x_i2c_remove(struct i2c_client
*i2c
)
1652 struct wm831x
*wm831x
= i2c_get_clientdata(i2c
);
1654 wm831x_device_exit(wm831x
);
1659 static const struct i2c_device_id wm831x_i2c_id
[] = {
1660 { "wm8310", WM8310
},
1661 { "wm8311", WM8311
},
1662 { "wm8312", WM8312
},
1663 { "wm8320", WM8320
},
1666 MODULE_DEVICE_TABLE(i2c
, wm831x_i2c_id
);
1669 static struct i2c_driver wm831x_i2c_driver
= {
1672 .owner
= THIS_MODULE
,
1674 .probe
= wm831x_i2c_probe
,
1675 .remove
= wm831x_i2c_remove
,
1676 .id_table
= wm831x_i2c_id
,
1679 static int __init
wm831x_i2c_init(void)
1683 ret
= i2c_add_driver(&wm831x_i2c_driver
);
1685 pr_err("Failed to register wm831x I2C driver: %d\n", ret
);
1689 subsys_initcall(wm831x_i2c_init
);
1691 static void __exit
wm831x_i2c_exit(void)
1693 i2c_del_driver(&wm831x_i2c_driver
);
1695 module_exit(wm831x_i2c_exit
);
1697 MODULE_DESCRIPTION("I2C support for the WM831X AudioPlus PMIC");
1698 MODULE_LICENSE("GPL");
1699 MODULE_AUTHOR("Mark Brown");