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
);
98 static int wm831x_reg_locked(struct wm831x
*wm831x
, unsigned short reg
)
104 case WM831X_WATCHDOG
:
105 case WM831X_DC4_CONTROL
:
106 case WM831X_ON_PIN_CONTROL
:
107 case WM831X_BACKUP_CHARGER_CONTROL
:
108 case WM831X_CHARGER_CONTROL_1
:
109 case WM831X_CHARGER_CONTROL_2
:
118 * wm831x_reg_unlock: Unlock user keyed registers
120 * The WM831x has a user key preventing writes to particularly
121 * critical registers. This function locks those registers,
122 * allowing writes to them.
124 void wm831x_reg_lock(struct wm831x
*wm831x
)
128 ret
= wm831x_reg_write(wm831x
, WM831X_SECURITY_KEY
, 0);
130 dev_vdbg(wm831x
->dev
, "Registers locked\n");
132 mutex_lock(&wm831x
->io_lock
);
133 WARN_ON(wm831x
->locked
);
135 mutex_unlock(&wm831x
->io_lock
);
137 dev_err(wm831x
->dev
, "Failed to lock registers: %d\n", ret
);
141 EXPORT_SYMBOL_GPL(wm831x_reg_lock
);
144 * wm831x_reg_unlock: Unlock user keyed registers
146 * The WM831x has a user key preventing writes to particularly
147 * critical registers. This function locks those registers,
148 * preventing spurious writes.
150 int wm831x_reg_unlock(struct wm831x
*wm831x
)
154 /* 0x9716 is the value required to unlock the registers */
155 ret
= wm831x_reg_write(wm831x
, WM831X_SECURITY_KEY
, 0x9716);
157 dev_vdbg(wm831x
->dev
, "Registers unlocked\n");
159 mutex_lock(&wm831x
->io_lock
);
160 WARN_ON(!wm831x
->locked
);
162 mutex_unlock(&wm831x
->io_lock
);
167 EXPORT_SYMBOL_GPL(wm831x_reg_unlock
);
169 static int wm831x_read(struct wm831x
*wm831x
, unsigned short reg
,
170 int bytes
, void *dest
)
178 ret
= wm831x
->read_dev(wm831x
, reg
, bytes
, dest
);
182 for (i
= 0; i
< bytes
/ 2; i
++) {
183 buf
[i
] = be16_to_cpu(buf
[i
]);
185 dev_vdbg(wm831x
->dev
, "Read %04x from R%d(0x%x)\n",
186 buf
[i
], reg
+ i
, reg
+ i
);
193 * wm831x_reg_read: Read a single WM831x register.
195 * @wm831x: Device to read from.
196 * @reg: Register to read.
198 int wm831x_reg_read(struct wm831x
*wm831x
, unsigned short reg
)
203 mutex_lock(&wm831x
->io_lock
);
205 ret
= wm831x_read(wm831x
, reg
, 2, &val
);
207 mutex_unlock(&wm831x
->io_lock
);
214 EXPORT_SYMBOL_GPL(wm831x_reg_read
);
217 * wm831x_bulk_read: Read multiple WM831x registers
219 * @wm831x: Device to read from
220 * @reg: First register
221 * @count: Number of registers
222 * @buf: Buffer to fill.
224 int wm831x_bulk_read(struct wm831x
*wm831x
, unsigned short reg
,
229 mutex_lock(&wm831x
->io_lock
);
231 ret
= wm831x_read(wm831x
, reg
, count
* 2, buf
);
233 mutex_unlock(&wm831x
->io_lock
);
237 EXPORT_SYMBOL_GPL(wm831x_bulk_read
);
239 static int wm831x_write(struct wm831x
*wm831x
, unsigned short reg
,
240 int bytes
, void *src
)
248 for (i
= 0; i
< bytes
/ 2; i
++) {
249 if (wm831x_reg_locked(wm831x
, reg
))
252 dev_vdbg(wm831x
->dev
, "Write %04x to R%d(0x%x)\n",
253 buf
[i
], reg
+ i
, reg
+ i
);
255 buf
[i
] = cpu_to_be16(buf
[i
]);
258 return wm831x
->write_dev(wm831x
, reg
, bytes
, src
);
262 * wm831x_reg_write: Write a single WM831x register.
264 * @wm831x: Device to write to.
265 * @reg: Register to write to.
266 * @val: Value to write.
268 int wm831x_reg_write(struct wm831x
*wm831x
, unsigned short reg
,
273 mutex_lock(&wm831x
->io_lock
);
275 ret
= wm831x_write(wm831x
, reg
, 2, &val
);
277 mutex_unlock(&wm831x
->io_lock
);
281 EXPORT_SYMBOL_GPL(wm831x_reg_write
);
284 * wm831x_set_bits: Set the value of a bitfield in a WM831x register
286 * @wm831x: Device to write to.
287 * @reg: Register to write to.
288 * @mask: Mask of bits to set.
289 * @val: Value to set (unshifted)
291 int wm831x_set_bits(struct wm831x
*wm831x
, unsigned short reg
,
292 unsigned short mask
, unsigned short val
)
297 mutex_lock(&wm831x
->io_lock
);
299 ret
= wm831x_read(wm831x
, reg
, 2, &r
);
306 ret
= wm831x_write(wm831x
, reg
, 2, &r
);
309 mutex_unlock(&wm831x
->io_lock
);
313 EXPORT_SYMBOL_GPL(wm831x_set_bits
);
316 * wm831x_auxadc_read: Read a value from the WM831x AUXADC
318 * @wm831x: Device to read from.
319 * @input: AUXADC input to read.
321 int wm831x_auxadc_read(struct wm831x
*wm831x
, enum wm831x_auxadc input
)
326 mutex_lock(&wm831x
->auxadc_lock
);
328 ret
= wm831x_set_bits(wm831x
, WM831X_AUXADC_CONTROL
,
329 WM831X_AUX_ENA
, WM831X_AUX_ENA
);
331 dev_err(wm831x
->dev
, "Failed to enable AUXADC: %d\n", ret
);
335 /* We force a single source at present */
337 ret
= wm831x_reg_write(wm831x
, WM831X_AUXADC_SOURCE
,
340 dev_err(wm831x
->dev
, "Failed to set AUXADC source: %d\n", ret
);
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
);
354 ret
= wm831x_reg_read(wm831x
, WM831X_AUXADC_CONTROL
);
356 ret
= WM831X_AUX_CVT_ENA
;
357 } while ((ret
& WM831X_AUX_CVT_ENA
) && --tries
);
359 if (ret
& WM831X_AUX_CVT_ENA
) {
360 dev_err(wm831x
->dev
, "Timed out reading AUXADC\n");
365 ret
= wm831x_reg_read(wm831x
, WM831X_AUXADC_DATA
);
367 dev_err(wm831x
->dev
, "Failed to read AUXADC data: %d\n", ret
);
369 src
= ((ret
& WM831X_AUX_DATA_SRC_MASK
)
370 >> WM831X_AUX_DATA_SRC_SHIFT
) - 1;
373 src
= WM831X_AUX_CAL
;
376 dev_err(wm831x
->dev
, "Data from source %d not %d\n",
380 ret
&= WM831X_AUX_DATA_MASK
;
385 wm831x_set_bits(wm831x
, WM831X_AUXADC_CONTROL
, WM831X_AUX_ENA
, 0);
387 mutex_unlock(&wm831x
->auxadc_lock
);
390 EXPORT_SYMBOL_GPL(wm831x_auxadc_read
);
393 * wm831x_auxadc_read_uv: Read a voltage from the WM831x AUXADC
395 * @wm831x: Device to read from.
396 * @input: AUXADC input to read.
398 int wm831x_auxadc_read_uv(struct wm831x
*wm831x
, enum wm831x_auxadc input
)
402 ret
= wm831x_auxadc_read(wm831x
, input
);
410 EXPORT_SYMBOL_GPL(wm831x_auxadc_read_uv
);
412 static struct resource wm831x_dcdc1_resources
[] = {
414 .start
= WM831X_DC1_CONTROL_1
,
415 .end
= WM831X_DC1_DVS_CONTROL
,
416 .flags
= IORESOURCE_IO
,
420 .start
= WM831X_IRQ_UV_DC1
,
421 .end
= WM831X_IRQ_UV_DC1
,
422 .flags
= IORESOURCE_IRQ
,
426 .start
= WM831X_IRQ_HC_DC1
,
427 .end
= WM831X_IRQ_HC_DC1
,
428 .flags
= IORESOURCE_IRQ
,
433 static struct resource wm831x_dcdc2_resources
[] = {
435 .start
= WM831X_DC2_CONTROL_1
,
436 .end
= WM831X_DC2_DVS_CONTROL
,
437 .flags
= IORESOURCE_IO
,
441 .start
= WM831X_IRQ_UV_DC2
,
442 .end
= WM831X_IRQ_UV_DC2
,
443 .flags
= IORESOURCE_IRQ
,
447 .start
= WM831X_IRQ_HC_DC2
,
448 .end
= WM831X_IRQ_HC_DC2
,
449 .flags
= IORESOURCE_IRQ
,
453 static struct resource wm831x_dcdc3_resources
[] = {
455 .start
= WM831X_DC3_CONTROL_1
,
456 .end
= WM831X_DC3_SLEEP_CONTROL
,
457 .flags
= IORESOURCE_IO
,
461 .start
= WM831X_IRQ_UV_DC3
,
462 .end
= WM831X_IRQ_UV_DC3
,
463 .flags
= IORESOURCE_IRQ
,
467 static struct resource wm831x_dcdc4_resources
[] = {
469 .start
= WM831X_DC4_CONTROL
,
470 .end
= WM831X_DC4_SLEEP_CONTROL
,
471 .flags
= IORESOURCE_IO
,
475 .start
= WM831X_IRQ_UV_DC4
,
476 .end
= WM831X_IRQ_UV_DC4
,
477 .flags
= IORESOURCE_IRQ
,
481 static struct resource wm831x_gpio_resources
[] = {
483 .start
= WM831X_IRQ_GPIO_1
,
484 .end
= WM831X_IRQ_GPIO_16
,
485 .flags
= IORESOURCE_IRQ
,
489 static struct resource wm831x_isink1_resources
[] = {
491 .start
= WM831X_CURRENT_SINK_1
,
492 .end
= WM831X_CURRENT_SINK_1
,
493 .flags
= IORESOURCE_IO
,
496 .start
= WM831X_IRQ_CS1
,
497 .end
= WM831X_IRQ_CS1
,
498 .flags
= IORESOURCE_IRQ
,
502 static struct resource wm831x_isink2_resources
[] = {
504 .start
= WM831X_CURRENT_SINK_2
,
505 .end
= WM831X_CURRENT_SINK_2
,
506 .flags
= IORESOURCE_IO
,
509 .start
= WM831X_IRQ_CS2
,
510 .end
= WM831X_IRQ_CS2
,
511 .flags
= IORESOURCE_IRQ
,
515 static struct resource wm831x_ldo1_resources
[] = {
517 .start
= WM831X_LDO1_CONTROL
,
518 .end
= WM831X_LDO1_SLEEP_CONTROL
,
519 .flags
= IORESOURCE_IO
,
523 .start
= WM831X_IRQ_UV_LDO1
,
524 .end
= WM831X_IRQ_UV_LDO1
,
525 .flags
= IORESOURCE_IRQ
,
529 static struct resource wm831x_ldo2_resources
[] = {
531 .start
= WM831X_LDO2_CONTROL
,
532 .end
= WM831X_LDO2_SLEEP_CONTROL
,
533 .flags
= IORESOURCE_IO
,
537 .start
= WM831X_IRQ_UV_LDO2
,
538 .end
= WM831X_IRQ_UV_LDO2
,
539 .flags
= IORESOURCE_IRQ
,
543 static struct resource wm831x_ldo3_resources
[] = {
545 .start
= WM831X_LDO3_CONTROL
,
546 .end
= WM831X_LDO3_SLEEP_CONTROL
,
547 .flags
= IORESOURCE_IO
,
551 .start
= WM831X_IRQ_UV_LDO3
,
552 .end
= WM831X_IRQ_UV_LDO3
,
553 .flags
= IORESOURCE_IRQ
,
557 static struct resource wm831x_ldo4_resources
[] = {
559 .start
= WM831X_LDO4_CONTROL
,
560 .end
= WM831X_LDO4_SLEEP_CONTROL
,
561 .flags
= IORESOURCE_IO
,
565 .start
= WM831X_IRQ_UV_LDO4
,
566 .end
= WM831X_IRQ_UV_LDO4
,
567 .flags
= IORESOURCE_IRQ
,
571 static struct resource wm831x_ldo5_resources
[] = {
573 .start
= WM831X_LDO5_CONTROL
,
574 .end
= WM831X_LDO5_SLEEP_CONTROL
,
575 .flags
= IORESOURCE_IO
,
579 .start
= WM831X_IRQ_UV_LDO5
,
580 .end
= WM831X_IRQ_UV_LDO5
,
581 .flags
= IORESOURCE_IRQ
,
585 static struct resource wm831x_ldo6_resources
[] = {
587 .start
= WM831X_LDO6_CONTROL
,
588 .end
= WM831X_LDO6_SLEEP_CONTROL
,
589 .flags
= IORESOURCE_IO
,
593 .start
= WM831X_IRQ_UV_LDO6
,
594 .end
= WM831X_IRQ_UV_LDO6
,
595 .flags
= IORESOURCE_IRQ
,
599 static struct resource wm831x_ldo7_resources
[] = {
601 .start
= WM831X_LDO7_CONTROL
,
602 .end
= WM831X_LDO7_SLEEP_CONTROL
,
603 .flags
= IORESOURCE_IO
,
607 .start
= WM831X_IRQ_UV_LDO7
,
608 .end
= WM831X_IRQ_UV_LDO7
,
609 .flags
= IORESOURCE_IRQ
,
613 static struct resource wm831x_ldo8_resources
[] = {
615 .start
= WM831X_LDO8_CONTROL
,
616 .end
= WM831X_LDO8_SLEEP_CONTROL
,
617 .flags
= IORESOURCE_IO
,
621 .start
= WM831X_IRQ_UV_LDO8
,
622 .end
= WM831X_IRQ_UV_LDO8
,
623 .flags
= IORESOURCE_IRQ
,
627 static struct resource wm831x_ldo9_resources
[] = {
629 .start
= WM831X_LDO9_CONTROL
,
630 .end
= WM831X_LDO9_SLEEP_CONTROL
,
631 .flags
= IORESOURCE_IO
,
635 .start
= WM831X_IRQ_UV_LDO9
,
636 .end
= WM831X_IRQ_UV_LDO9
,
637 .flags
= IORESOURCE_IRQ
,
641 static struct resource wm831x_ldo10_resources
[] = {
643 .start
= WM831X_LDO10_CONTROL
,
644 .end
= WM831X_LDO10_SLEEP_CONTROL
,
645 .flags
= IORESOURCE_IO
,
649 .start
= WM831X_IRQ_UV_LDO10
,
650 .end
= WM831X_IRQ_UV_LDO10
,
651 .flags
= IORESOURCE_IRQ
,
655 static struct resource wm831x_ldo11_resources
[] = {
657 .start
= WM831X_LDO11_ON_CONTROL
,
658 .end
= WM831X_LDO11_SLEEP_CONTROL
,
659 .flags
= IORESOURCE_IO
,
663 static struct resource wm831x_on_resources
[] = {
665 .start
= WM831X_IRQ_ON
,
666 .end
= WM831X_IRQ_ON
,
667 .flags
= IORESOURCE_IRQ
,
672 static struct resource wm831x_power_resources
[] = {
675 .start
= WM831X_IRQ_PPM_SYSLO
,
676 .end
= WM831X_IRQ_PPM_SYSLO
,
677 .flags
= IORESOURCE_IRQ
,
681 .start
= WM831X_IRQ_PPM_PWR_SRC
,
682 .end
= WM831X_IRQ_PPM_PWR_SRC
,
683 .flags
= IORESOURCE_IRQ
,
687 .start
= WM831X_IRQ_PPM_USB_CURR
,
688 .end
= WM831X_IRQ_PPM_USB_CURR
,
689 .flags
= IORESOURCE_IRQ
,
693 .start
= WM831X_IRQ_CHG_BATT_HOT
,
694 .end
= WM831X_IRQ_CHG_BATT_HOT
,
695 .flags
= IORESOURCE_IRQ
,
699 .start
= WM831X_IRQ_CHG_BATT_COLD
,
700 .end
= WM831X_IRQ_CHG_BATT_COLD
,
701 .flags
= IORESOURCE_IRQ
,
705 .start
= WM831X_IRQ_CHG_BATT_FAIL
,
706 .end
= WM831X_IRQ_CHG_BATT_FAIL
,
707 .flags
= IORESOURCE_IRQ
,
711 .start
= WM831X_IRQ_CHG_OV
,
712 .end
= WM831X_IRQ_CHG_OV
,
713 .flags
= IORESOURCE_IRQ
,
717 .start
= WM831X_IRQ_CHG_END
,
718 .end
= WM831X_IRQ_CHG_END
,
719 .flags
= IORESOURCE_IRQ
,
723 .start
= WM831X_IRQ_CHG_TO
,
724 .end
= WM831X_IRQ_CHG_TO
,
725 .flags
= IORESOURCE_IRQ
,
729 .start
= WM831X_IRQ_CHG_MODE
,
730 .end
= WM831X_IRQ_CHG_MODE
,
731 .flags
= IORESOURCE_IRQ
,
735 .start
= WM831X_IRQ_CHG_START
,
736 .end
= WM831X_IRQ_CHG_START
,
737 .flags
= IORESOURCE_IRQ
,
741 static struct resource wm831x_rtc_resources
[] = {
744 .start
= WM831X_IRQ_RTC_PER
,
745 .end
= WM831X_IRQ_RTC_PER
,
746 .flags
= IORESOURCE_IRQ
,
750 .start
= WM831X_IRQ_RTC_ALM
,
751 .end
= WM831X_IRQ_RTC_ALM
,
752 .flags
= IORESOURCE_IRQ
,
756 static struct resource wm831x_status1_resources
[] = {
758 .start
= WM831X_STATUS_LED_1
,
759 .end
= WM831X_STATUS_LED_1
,
760 .flags
= IORESOURCE_IO
,
764 static struct resource wm831x_status2_resources
[] = {
766 .start
= WM831X_STATUS_LED_2
,
767 .end
= WM831X_STATUS_LED_2
,
768 .flags
= IORESOURCE_IO
,
772 static struct resource wm831x_touch_resources
[] = {
775 .start
= WM831X_IRQ_TCHPD
,
776 .end
= WM831X_IRQ_TCHPD
,
777 .flags
= IORESOURCE_IRQ
,
781 .start
= WM831X_IRQ_TCHDATA
,
782 .end
= WM831X_IRQ_TCHDATA
,
783 .flags
= IORESOURCE_IRQ
,
787 static struct resource wm831x_wdt_resources
[] = {
789 .start
= WM831X_IRQ_WDOG_TO
,
790 .end
= WM831X_IRQ_WDOG_TO
,
791 .flags
= IORESOURCE_IRQ
,
795 static struct mfd_cell wm8310_devs
[] = {
797 .name
= "wm831x-buckv",
799 .num_resources
= ARRAY_SIZE(wm831x_dcdc1_resources
),
800 .resources
= wm831x_dcdc1_resources
,
803 .name
= "wm831x-buckv",
805 .num_resources
= ARRAY_SIZE(wm831x_dcdc2_resources
),
806 .resources
= wm831x_dcdc2_resources
,
809 .name
= "wm831x-buckp",
811 .num_resources
= ARRAY_SIZE(wm831x_dcdc3_resources
),
812 .resources
= wm831x_dcdc3_resources
,
815 .name
= "wm831x-boostp",
817 .num_resources
= ARRAY_SIZE(wm831x_dcdc4_resources
),
818 .resources
= wm831x_dcdc4_resources
,
821 .name
= "wm831x-epe",
825 .name
= "wm831x-epe",
829 .name
= "wm831x-gpio",
830 .num_resources
= ARRAY_SIZE(wm831x_gpio_resources
),
831 .resources
= wm831x_gpio_resources
,
834 .name
= "wm831x-hwmon",
837 .name
= "wm831x-isink",
839 .num_resources
= ARRAY_SIZE(wm831x_isink1_resources
),
840 .resources
= wm831x_isink1_resources
,
843 .name
= "wm831x-isink",
845 .num_resources
= ARRAY_SIZE(wm831x_isink2_resources
),
846 .resources
= wm831x_isink2_resources
,
849 .name
= "wm831x-ldo",
851 .num_resources
= ARRAY_SIZE(wm831x_ldo1_resources
),
852 .resources
= wm831x_ldo1_resources
,
855 .name
= "wm831x-ldo",
857 .num_resources
= ARRAY_SIZE(wm831x_ldo2_resources
),
858 .resources
= wm831x_ldo2_resources
,
861 .name
= "wm831x-ldo",
863 .num_resources
= ARRAY_SIZE(wm831x_ldo3_resources
),
864 .resources
= wm831x_ldo3_resources
,
867 .name
= "wm831x-ldo",
869 .num_resources
= ARRAY_SIZE(wm831x_ldo4_resources
),
870 .resources
= wm831x_ldo4_resources
,
873 .name
= "wm831x-ldo",
875 .num_resources
= ARRAY_SIZE(wm831x_ldo5_resources
),
876 .resources
= wm831x_ldo5_resources
,
879 .name
= "wm831x-ldo",
881 .num_resources
= ARRAY_SIZE(wm831x_ldo6_resources
),
882 .resources
= wm831x_ldo6_resources
,
885 .name
= "wm831x-aldo",
887 .num_resources
= ARRAY_SIZE(wm831x_ldo7_resources
),
888 .resources
= wm831x_ldo7_resources
,
891 .name
= "wm831x-aldo",
893 .num_resources
= ARRAY_SIZE(wm831x_ldo8_resources
),
894 .resources
= wm831x_ldo8_resources
,
897 .name
= "wm831x-aldo",
899 .num_resources
= ARRAY_SIZE(wm831x_ldo9_resources
),
900 .resources
= wm831x_ldo9_resources
,
903 .name
= "wm831x-aldo",
905 .num_resources
= ARRAY_SIZE(wm831x_ldo10_resources
),
906 .resources
= wm831x_ldo10_resources
,
909 .name
= "wm831x-alive-ldo",
911 .num_resources
= ARRAY_SIZE(wm831x_ldo11_resources
),
912 .resources
= wm831x_ldo11_resources
,
916 .num_resources
= ARRAY_SIZE(wm831x_on_resources
),
917 .resources
= wm831x_on_resources
,
920 .name
= "wm831x-power",
921 .num_resources
= ARRAY_SIZE(wm831x_power_resources
),
922 .resources
= wm831x_power_resources
,
925 .name
= "wm831x-rtc",
926 .num_resources
= ARRAY_SIZE(wm831x_rtc_resources
),
927 .resources
= wm831x_rtc_resources
,
930 .name
= "wm831x-status",
932 .num_resources
= ARRAY_SIZE(wm831x_status1_resources
),
933 .resources
= wm831x_status1_resources
,
936 .name
= "wm831x-status",
938 .num_resources
= ARRAY_SIZE(wm831x_status2_resources
),
939 .resources
= wm831x_status2_resources
,
942 .name
= "wm831x-watchdog",
943 .num_resources
= ARRAY_SIZE(wm831x_wdt_resources
),
944 .resources
= wm831x_wdt_resources
,
948 static struct mfd_cell wm8311_devs
[] = {
950 .name
= "wm831x-buckv",
952 .num_resources
= ARRAY_SIZE(wm831x_dcdc1_resources
),
953 .resources
= wm831x_dcdc1_resources
,
956 .name
= "wm831x-buckv",
958 .num_resources
= ARRAY_SIZE(wm831x_dcdc2_resources
),
959 .resources
= wm831x_dcdc2_resources
,
962 .name
= "wm831x-buckp",
964 .num_resources
= ARRAY_SIZE(wm831x_dcdc3_resources
),
965 .resources
= wm831x_dcdc3_resources
,
968 .name
= "wm831x-boostp",
970 .num_resources
= ARRAY_SIZE(wm831x_dcdc4_resources
),
971 .resources
= wm831x_dcdc4_resources
,
974 .name
= "wm831x-epe",
978 .name
= "wm831x-epe",
982 .name
= "wm831x-gpio",
983 .num_resources
= ARRAY_SIZE(wm831x_gpio_resources
),
984 .resources
= wm831x_gpio_resources
,
987 .name
= "wm831x-hwmon",
990 .name
= "wm831x-isink",
992 .num_resources
= ARRAY_SIZE(wm831x_isink1_resources
),
993 .resources
= wm831x_isink1_resources
,
996 .name
= "wm831x-isink",
998 .num_resources
= ARRAY_SIZE(wm831x_isink2_resources
),
999 .resources
= wm831x_isink2_resources
,
1002 .name
= "wm831x-ldo",
1004 .num_resources
= ARRAY_SIZE(wm831x_ldo1_resources
),
1005 .resources
= wm831x_ldo1_resources
,
1008 .name
= "wm831x-ldo",
1010 .num_resources
= ARRAY_SIZE(wm831x_ldo2_resources
),
1011 .resources
= wm831x_ldo2_resources
,
1014 .name
= "wm831x-ldo",
1016 .num_resources
= ARRAY_SIZE(wm831x_ldo3_resources
),
1017 .resources
= wm831x_ldo3_resources
,
1020 .name
= "wm831x-ldo",
1022 .num_resources
= ARRAY_SIZE(wm831x_ldo4_resources
),
1023 .resources
= wm831x_ldo4_resources
,
1026 .name
= "wm831x-ldo",
1028 .num_resources
= ARRAY_SIZE(wm831x_ldo5_resources
),
1029 .resources
= wm831x_ldo5_resources
,
1032 .name
= "wm831x-aldo",
1034 .num_resources
= ARRAY_SIZE(wm831x_ldo7_resources
),
1035 .resources
= wm831x_ldo7_resources
,
1038 .name
= "wm831x-alive-ldo",
1040 .num_resources
= ARRAY_SIZE(wm831x_ldo11_resources
),
1041 .resources
= wm831x_ldo11_resources
,
1044 .name
= "wm831x-on",
1045 .num_resources
= ARRAY_SIZE(wm831x_on_resources
),
1046 .resources
= wm831x_on_resources
,
1049 .name
= "wm831x-power",
1050 .num_resources
= ARRAY_SIZE(wm831x_power_resources
),
1051 .resources
= wm831x_power_resources
,
1054 .name
= "wm831x-rtc",
1055 .num_resources
= ARRAY_SIZE(wm831x_rtc_resources
),
1056 .resources
= wm831x_rtc_resources
,
1059 .name
= "wm831x-status",
1061 .num_resources
= ARRAY_SIZE(wm831x_status1_resources
),
1062 .resources
= wm831x_status1_resources
,
1065 .name
= "wm831x-status",
1067 .num_resources
= ARRAY_SIZE(wm831x_status2_resources
),
1068 .resources
= wm831x_status2_resources
,
1071 .name
= "wm831x-touch",
1072 .num_resources
= ARRAY_SIZE(wm831x_touch_resources
),
1073 .resources
= wm831x_touch_resources
,
1076 .name
= "wm831x-watchdog",
1077 .num_resources
= ARRAY_SIZE(wm831x_wdt_resources
),
1078 .resources
= wm831x_wdt_resources
,
1082 static struct mfd_cell wm8312_devs
[] = {
1084 .name
= "wm831x-buckv",
1086 .num_resources
= ARRAY_SIZE(wm831x_dcdc1_resources
),
1087 .resources
= wm831x_dcdc1_resources
,
1090 .name
= "wm831x-buckv",
1092 .num_resources
= ARRAY_SIZE(wm831x_dcdc2_resources
),
1093 .resources
= wm831x_dcdc2_resources
,
1096 .name
= "wm831x-buckp",
1098 .num_resources
= ARRAY_SIZE(wm831x_dcdc3_resources
),
1099 .resources
= wm831x_dcdc3_resources
,
1102 .name
= "wm831x-boostp",
1104 .num_resources
= ARRAY_SIZE(wm831x_dcdc4_resources
),
1105 .resources
= wm831x_dcdc4_resources
,
1108 .name
= "wm831x-epe",
1112 .name
= "wm831x-epe",
1116 .name
= "wm831x-gpio",
1117 .num_resources
= ARRAY_SIZE(wm831x_gpio_resources
),
1118 .resources
= wm831x_gpio_resources
,
1121 .name
= "wm831x-hwmon",
1124 .name
= "wm831x-isink",
1126 .num_resources
= ARRAY_SIZE(wm831x_isink1_resources
),
1127 .resources
= wm831x_isink1_resources
,
1130 .name
= "wm831x-isink",
1132 .num_resources
= ARRAY_SIZE(wm831x_isink2_resources
),
1133 .resources
= wm831x_isink2_resources
,
1136 .name
= "wm831x-ldo",
1138 .num_resources
= ARRAY_SIZE(wm831x_ldo1_resources
),
1139 .resources
= wm831x_ldo1_resources
,
1142 .name
= "wm831x-ldo",
1144 .num_resources
= ARRAY_SIZE(wm831x_ldo2_resources
),
1145 .resources
= wm831x_ldo2_resources
,
1148 .name
= "wm831x-ldo",
1150 .num_resources
= ARRAY_SIZE(wm831x_ldo3_resources
),
1151 .resources
= wm831x_ldo3_resources
,
1154 .name
= "wm831x-ldo",
1156 .num_resources
= ARRAY_SIZE(wm831x_ldo4_resources
),
1157 .resources
= wm831x_ldo4_resources
,
1160 .name
= "wm831x-ldo",
1162 .num_resources
= ARRAY_SIZE(wm831x_ldo5_resources
),
1163 .resources
= wm831x_ldo5_resources
,
1166 .name
= "wm831x-ldo",
1168 .num_resources
= ARRAY_SIZE(wm831x_ldo6_resources
),
1169 .resources
= wm831x_ldo6_resources
,
1172 .name
= "wm831x-aldo",
1174 .num_resources
= ARRAY_SIZE(wm831x_ldo7_resources
),
1175 .resources
= wm831x_ldo7_resources
,
1178 .name
= "wm831x-aldo",
1180 .num_resources
= ARRAY_SIZE(wm831x_ldo8_resources
),
1181 .resources
= wm831x_ldo8_resources
,
1184 .name
= "wm831x-aldo",
1186 .num_resources
= ARRAY_SIZE(wm831x_ldo9_resources
),
1187 .resources
= wm831x_ldo9_resources
,
1190 .name
= "wm831x-aldo",
1192 .num_resources
= ARRAY_SIZE(wm831x_ldo10_resources
),
1193 .resources
= wm831x_ldo10_resources
,
1196 .name
= "wm831x-alive-ldo",
1198 .num_resources
= ARRAY_SIZE(wm831x_ldo11_resources
),
1199 .resources
= wm831x_ldo11_resources
,
1202 .name
= "wm831x-on",
1203 .num_resources
= ARRAY_SIZE(wm831x_on_resources
),
1204 .resources
= wm831x_on_resources
,
1207 .name
= "wm831x-power",
1208 .num_resources
= ARRAY_SIZE(wm831x_power_resources
),
1209 .resources
= wm831x_power_resources
,
1212 .name
= "wm831x-rtc",
1213 .num_resources
= ARRAY_SIZE(wm831x_rtc_resources
),
1214 .resources
= wm831x_rtc_resources
,
1217 .name
= "wm831x-status",
1219 .num_resources
= ARRAY_SIZE(wm831x_status1_resources
),
1220 .resources
= wm831x_status1_resources
,
1223 .name
= "wm831x-status",
1225 .num_resources
= ARRAY_SIZE(wm831x_status2_resources
),
1226 .resources
= wm831x_status2_resources
,
1229 .name
= "wm831x-touch",
1230 .num_resources
= ARRAY_SIZE(wm831x_touch_resources
),
1231 .resources
= wm831x_touch_resources
,
1234 .name
= "wm831x-watchdog",
1235 .num_resources
= ARRAY_SIZE(wm831x_wdt_resources
),
1236 .resources
= wm831x_wdt_resources
,
1240 static struct mfd_cell backlight_devs
[] = {
1242 .name
= "wm831x-backlight",
1247 * Instantiate the generic non-control parts of the device.
1249 static int wm831x_device_init(struct wm831x
*wm831x
, unsigned long id
, int irq
)
1251 struct wm831x_pdata
*pdata
= wm831x
->dev
->platform_data
;
1253 enum wm831x_parent parent
;
1256 mutex_init(&wm831x
->io_lock
);
1257 mutex_init(&wm831x
->key_lock
);
1258 mutex_init(&wm831x
->auxadc_lock
);
1259 dev_set_drvdata(wm831x
->dev
, wm831x
);
1261 ret
= wm831x_reg_read(wm831x
, WM831X_PARENT_ID
);
1263 dev_err(wm831x
->dev
, "Failed to read parent ID: %d\n", ret
);
1266 if (ret
!= 0x6204) {
1267 dev_err(wm831x
->dev
, "Device is not a WM831x: ID %x\n", ret
);
1272 ret
= wm831x_reg_read(wm831x
, WM831X_REVISION
);
1274 dev_err(wm831x
->dev
, "Failed to read revision: %d\n", ret
);
1277 rev
= (ret
& WM831X_PARENT_REV_MASK
) >> WM831X_PARENT_REV_SHIFT
;
1279 ret
= wm831x_reg_read(wm831x
, WM831X_RESET_ID
);
1281 dev_err(wm831x
->dev
, "Failed to read device ID: %d\n", ret
);
1290 dev_info(wm831x
->dev
, "WM8310 revision %c\n",
1300 dev_info(wm831x
->dev
, "WM8311 revision %c\n",
1310 dev_info(wm831x
->dev
, "WM8312 revision %c\n",
1317 /* Some engineering samples do not have the ID set,
1318 * rely on the device being registered correctly.
1319 * This will need revisiting for future devices with
1325 dev_info(wm831x
->dev
, "WM831%d ES revision %c\n",
1332 dev_err(wm831x
->dev
, "Unknown WM831x device %04x\n", ret
);
1337 /* This will need revisiting in future but is OK for all
1341 dev_warn(wm831x
->dev
, "Device was registered as a WM831%lu\n",
1344 /* Bootstrap the user key */
1345 ret
= wm831x_reg_read(wm831x
, WM831X_SECURITY_KEY
);
1347 dev_err(wm831x
->dev
, "Failed to read security key: %d\n", ret
);
1351 dev_warn(wm831x
->dev
, "Security key had non-zero value %x\n",
1353 wm831x_reg_write(wm831x
, WM831X_SECURITY_KEY
, 0);
1357 if (pdata
&& pdata
->pre_init
) {
1358 ret
= pdata
->pre_init(wm831x
);
1360 dev_err(wm831x
->dev
, "pre_init() failed: %d\n", ret
);
1365 ret
= wm831x_irq_init(wm831x
, irq
);
1369 /* The core device is up, instantiate the subdevices. */
1372 ret
= mfd_add_devices(wm831x
->dev
, -1,
1373 wm8310_devs
, ARRAY_SIZE(wm8310_devs
),
1378 ret
= mfd_add_devices(wm831x
->dev
, -1,
1379 wm8311_devs
, ARRAY_SIZE(wm8311_devs
),
1384 ret
= mfd_add_devices(wm831x
->dev
, -1,
1385 wm8312_devs
, ARRAY_SIZE(wm8312_devs
),
1390 /* If this happens the bus probe function is buggy */
1395 dev_err(wm831x
->dev
, "Failed to add children\n");
1399 if (pdata
&& pdata
->backlight
) {
1400 /* Treat errors as non-critical */
1401 ret
= mfd_add_devices(wm831x
->dev
, -1, backlight_devs
,
1402 ARRAY_SIZE(backlight_devs
), NULL
, 0);
1404 dev_err(wm831x
->dev
, "Failed to add backlight: %d\n",
1408 wm831x_otp_init(wm831x
);
1410 if (pdata
&& pdata
->post_init
) {
1411 ret
= pdata
->post_init(wm831x
);
1413 dev_err(wm831x
->dev
, "post_init() failed: %d\n", ret
);
1421 wm831x_irq_exit(wm831x
);
1423 mfd_remove_devices(wm831x
->dev
);
1428 static void wm831x_device_exit(struct wm831x
*wm831x
)
1430 wm831x_otp_exit(wm831x
);
1431 mfd_remove_devices(wm831x
->dev
);
1432 wm831x_irq_exit(wm831x
);
1436 static int wm831x_i2c_read_device(struct wm831x
*wm831x
, unsigned short reg
,
1437 int bytes
, void *dest
)
1439 struct i2c_client
*i2c
= wm831x
->control_data
;
1441 u16 r
= cpu_to_be16(reg
);
1443 ret
= i2c_master_send(i2c
, (unsigned char *)&r
, 2);
1449 ret
= i2c_master_recv(i2c
, dest
, bytes
);
1457 /* Currently we allocate the write buffer on the stack; this is OK for
1458 * small writes - if we need to do large writes this will need to be
1461 static int wm831x_i2c_write_device(struct wm831x
*wm831x
, unsigned short reg
,
1462 int bytes
, void *src
)
1464 struct i2c_client
*i2c
= wm831x
->control_data
;
1465 unsigned char msg
[bytes
+ 2];
1468 reg
= cpu_to_be16(reg
);
1469 memcpy(&msg
[0], ®
, 2);
1470 memcpy(&msg
[2], src
, bytes
);
1472 ret
= i2c_master_send(i2c
, msg
, bytes
+ 2);
1475 if (ret
< bytes
+ 2)
1481 static int wm831x_i2c_probe(struct i2c_client
*i2c
,
1482 const struct i2c_device_id
*id
)
1484 struct wm831x
*wm831x
;
1486 wm831x
= kzalloc(sizeof(struct wm831x
), GFP_KERNEL
);
1487 if (wm831x
== NULL
) {
1492 i2c_set_clientdata(i2c
, wm831x
);
1493 wm831x
->dev
= &i2c
->dev
;
1494 wm831x
->control_data
= i2c
;
1495 wm831x
->read_dev
= wm831x_i2c_read_device
;
1496 wm831x
->write_dev
= wm831x_i2c_write_device
;
1498 return wm831x_device_init(wm831x
, id
->driver_data
, i2c
->irq
);
1501 static int wm831x_i2c_remove(struct i2c_client
*i2c
)
1503 struct wm831x
*wm831x
= i2c_get_clientdata(i2c
);
1505 wm831x_device_exit(wm831x
);
1510 static const struct i2c_device_id wm831x_i2c_id
[] = {
1511 { "wm8310", WM8310
},
1512 { "wm8311", WM8311
},
1513 { "wm8312", WM8312
},
1516 MODULE_DEVICE_TABLE(i2c
, wm831x_i2c_id
);
1519 static struct i2c_driver wm831x_i2c_driver
= {
1522 .owner
= THIS_MODULE
,
1524 .probe
= wm831x_i2c_probe
,
1525 .remove
= wm831x_i2c_remove
,
1526 .id_table
= wm831x_i2c_id
,
1529 static int __init
wm831x_i2c_init(void)
1533 ret
= i2c_add_driver(&wm831x_i2c_driver
);
1535 pr_err("Failed to register wm831x I2C driver: %d\n", ret
);
1539 subsys_initcall(wm831x_i2c_init
);
1541 static void __exit
wm831x_i2c_exit(void)
1543 i2c_del_driver(&wm831x_i2c_driver
);
1545 module_exit(wm831x_i2c_exit
);
1547 MODULE_DESCRIPTION("I2C support for the WM831X AudioPlus PMIC");
1548 MODULE_LICENSE("GPL");
1549 MODULE_AUTHOR("Mark Brown");