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/mfd/core.h>
20 #include <linux/mfd/wm831x/core.h>
21 #include <linux/mfd/wm831x/pdata.h>
22 #include <linux/mfd/wm831x/irq.h>
30 static int wm831x_reg_locked(struct wm831x
*wm831x
, unsigned short reg
)
37 case WM831X_DC4_CONTROL
:
38 case WM831X_ON_PIN_CONTROL
:
39 case WM831X_BACKUP_CHARGER_CONTROL
:
40 case WM831X_CHARGER_CONTROL_1
:
41 case WM831X_CHARGER_CONTROL_2
:
50 * wm831x_reg_unlock: Unlock user keyed registers
52 * The WM831x has a user key preventing writes to particularly
53 * critical registers. This function locks those registers,
54 * allowing writes to them.
56 void wm831x_reg_lock(struct wm831x
*wm831x
)
60 ret
= wm831x_reg_write(wm831x
, WM831X_SECURITY_KEY
, 0);
62 dev_vdbg(wm831x
->dev
, "Registers locked\n");
64 mutex_lock(&wm831x
->io_lock
);
65 WARN_ON(wm831x
->locked
);
67 mutex_unlock(&wm831x
->io_lock
);
69 dev_err(wm831x
->dev
, "Failed to lock registers: %d\n", ret
);
73 EXPORT_SYMBOL_GPL(wm831x_reg_lock
);
76 * wm831x_reg_unlock: Unlock user keyed registers
78 * The WM831x has a user key preventing writes to particularly
79 * critical registers. This function locks those registers,
80 * preventing spurious writes.
82 int wm831x_reg_unlock(struct wm831x
*wm831x
)
86 /* 0x9716 is the value required to unlock the registers */
87 ret
= wm831x_reg_write(wm831x
, WM831X_SECURITY_KEY
, 0x9716);
89 dev_vdbg(wm831x
->dev
, "Registers unlocked\n");
91 mutex_lock(&wm831x
->io_lock
);
92 WARN_ON(!wm831x
->locked
);
94 mutex_unlock(&wm831x
->io_lock
);
99 EXPORT_SYMBOL_GPL(wm831x_reg_unlock
);
101 static int wm831x_read(struct wm831x
*wm831x
, unsigned short reg
,
102 int bytes
, void *dest
)
110 ret
= wm831x
->read_dev(wm831x
, reg
, bytes
, dest
);
114 for (i
= 0; i
< bytes
/ 2; i
++) {
115 buf
[i
] = be16_to_cpu(buf
[i
]);
117 dev_vdbg(wm831x
->dev
, "Read %04x from R%d(0x%x)\n",
118 buf
[i
], reg
+ i
, reg
+ i
);
125 * wm831x_reg_read: Read a single WM831x register.
127 * @wm831x: Device to read from.
128 * @reg: Register to read.
130 int wm831x_reg_read(struct wm831x
*wm831x
, unsigned short reg
)
135 mutex_lock(&wm831x
->io_lock
);
137 ret
= wm831x_read(wm831x
, reg
, 2, &val
);
139 mutex_unlock(&wm831x
->io_lock
);
146 EXPORT_SYMBOL_GPL(wm831x_reg_read
);
149 * wm831x_bulk_read: Read multiple WM831x registers
151 * @wm831x: Device to read from
152 * @reg: First register
153 * @count: Number of registers
154 * @buf: Buffer to fill.
156 int wm831x_bulk_read(struct wm831x
*wm831x
, unsigned short reg
,
161 mutex_lock(&wm831x
->io_lock
);
163 ret
= wm831x_read(wm831x
, reg
, count
* 2, buf
);
165 mutex_unlock(&wm831x
->io_lock
);
169 EXPORT_SYMBOL_GPL(wm831x_bulk_read
);
171 static int wm831x_write(struct wm831x
*wm831x
, unsigned short reg
,
172 int bytes
, void *src
)
180 for (i
= 0; i
< bytes
/ 2; i
++) {
181 if (wm831x_reg_locked(wm831x
, reg
))
184 dev_vdbg(wm831x
->dev
, "Write %04x to R%d(0x%x)\n",
185 buf
[i
], reg
+ i
, reg
+ i
);
187 buf
[i
] = cpu_to_be16(buf
[i
]);
190 return wm831x
->write_dev(wm831x
, reg
, bytes
, src
);
194 * wm831x_reg_write: Write a single WM831x register.
196 * @wm831x: Device to write to.
197 * @reg: Register to write to.
198 * @val: Value to write.
200 int wm831x_reg_write(struct wm831x
*wm831x
, unsigned short reg
,
205 mutex_lock(&wm831x
->io_lock
);
207 ret
= wm831x_write(wm831x
, reg
, 2, &val
);
209 mutex_unlock(&wm831x
->io_lock
);
213 EXPORT_SYMBOL_GPL(wm831x_reg_write
);
216 * wm831x_set_bits: Set the value of a bitfield in a WM831x register
218 * @wm831x: Device to write to.
219 * @reg: Register to write to.
220 * @mask: Mask of bits to set.
221 * @val: Value to set (unshifted)
223 int wm831x_set_bits(struct wm831x
*wm831x
, unsigned short reg
,
224 unsigned short mask
, unsigned short val
)
229 mutex_lock(&wm831x
->io_lock
);
231 ret
= wm831x_read(wm831x
, reg
, 2, &r
);
238 ret
= wm831x_write(wm831x
, reg
, 2, &r
);
241 mutex_unlock(&wm831x
->io_lock
);
245 EXPORT_SYMBOL_GPL(wm831x_set_bits
);
247 static struct resource wm831x_dcdc1_resources
[] = {
249 .start
= WM831X_DC1_CONTROL_1
,
250 .end
= WM831X_DC1_DVS_CONTROL
,
251 .flags
= IORESOURCE_IO
,
255 .start
= WM831X_IRQ_UV_DC1
,
256 .end
= WM831X_IRQ_UV_DC1
,
257 .flags
= IORESOURCE_IRQ
,
261 .start
= WM831X_IRQ_HC_DC1
,
262 .end
= WM831X_IRQ_HC_DC1
,
263 .flags
= IORESOURCE_IRQ
,
268 static struct resource wm831x_dcdc2_resources
[] = {
270 .start
= WM831X_DC2_CONTROL_1
,
271 .end
= WM831X_DC2_DVS_CONTROL
,
272 .flags
= IORESOURCE_IO
,
276 .start
= WM831X_IRQ_UV_DC2
,
277 .end
= WM831X_IRQ_UV_DC2
,
278 .flags
= IORESOURCE_IRQ
,
282 .start
= WM831X_IRQ_HC_DC2
,
283 .end
= WM831X_IRQ_HC_DC2
,
284 .flags
= IORESOURCE_IRQ
,
288 static struct resource wm831x_dcdc3_resources
[] = {
290 .start
= WM831X_DC3_CONTROL_1
,
291 .end
= WM831X_DC3_SLEEP_CONTROL
,
292 .flags
= IORESOURCE_IO
,
296 .start
= WM831X_IRQ_UV_DC3
,
297 .end
= WM831X_IRQ_UV_DC3
,
298 .flags
= IORESOURCE_IRQ
,
302 static struct resource wm831x_dcdc4_resources
[] = {
304 .start
= WM831X_DC4_CONTROL
,
305 .end
= WM831X_DC4_SLEEP_CONTROL
,
306 .flags
= IORESOURCE_IO
,
310 .start
= WM831X_IRQ_UV_DC4
,
311 .end
= WM831X_IRQ_UV_DC4
,
312 .flags
= IORESOURCE_IRQ
,
316 static struct resource wm831x_gpio_resources
[] = {
318 .start
= WM831X_IRQ_GPIO_1
,
319 .end
= WM831X_IRQ_GPIO_16
,
320 .flags
= IORESOURCE_IRQ
,
324 static struct resource wm831x_isink1_resources
[] = {
326 .start
= WM831X_CURRENT_SINK_1
,
327 .end
= WM831X_CURRENT_SINK_1
,
328 .flags
= IORESOURCE_IO
,
331 .start
= WM831X_IRQ_CS1
,
332 .end
= WM831X_IRQ_CS1
,
333 .flags
= IORESOURCE_IRQ
,
337 static struct resource wm831x_isink2_resources
[] = {
339 .start
= WM831X_CURRENT_SINK_2
,
340 .end
= WM831X_CURRENT_SINK_2
,
341 .flags
= IORESOURCE_IO
,
344 .start
= WM831X_IRQ_CS2
,
345 .end
= WM831X_IRQ_CS2
,
346 .flags
= IORESOURCE_IRQ
,
350 static struct resource wm831x_ldo1_resources
[] = {
352 .start
= WM831X_LDO1_CONTROL
,
353 .end
= WM831X_LDO1_SLEEP_CONTROL
,
354 .flags
= IORESOURCE_IO
,
358 .start
= WM831X_IRQ_UV_LDO1
,
359 .end
= WM831X_IRQ_UV_LDO1
,
360 .flags
= IORESOURCE_IRQ
,
364 static struct resource wm831x_ldo2_resources
[] = {
366 .start
= WM831X_LDO2_CONTROL
,
367 .end
= WM831X_LDO2_SLEEP_CONTROL
,
368 .flags
= IORESOURCE_IO
,
372 .start
= WM831X_IRQ_UV_LDO2
,
373 .end
= WM831X_IRQ_UV_LDO2
,
374 .flags
= IORESOURCE_IRQ
,
378 static struct resource wm831x_ldo3_resources
[] = {
380 .start
= WM831X_LDO3_CONTROL
,
381 .end
= WM831X_LDO3_SLEEP_CONTROL
,
382 .flags
= IORESOURCE_IO
,
386 .start
= WM831X_IRQ_UV_LDO3
,
387 .end
= WM831X_IRQ_UV_LDO3
,
388 .flags
= IORESOURCE_IRQ
,
392 static struct resource wm831x_ldo4_resources
[] = {
394 .start
= WM831X_LDO4_CONTROL
,
395 .end
= WM831X_LDO4_SLEEP_CONTROL
,
396 .flags
= IORESOURCE_IO
,
400 .start
= WM831X_IRQ_UV_LDO4
,
401 .end
= WM831X_IRQ_UV_LDO4
,
402 .flags
= IORESOURCE_IRQ
,
406 static struct resource wm831x_ldo5_resources
[] = {
408 .start
= WM831X_LDO5_CONTROL
,
409 .end
= WM831X_LDO5_SLEEP_CONTROL
,
410 .flags
= IORESOURCE_IO
,
414 .start
= WM831X_IRQ_UV_LDO5
,
415 .end
= WM831X_IRQ_UV_LDO5
,
416 .flags
= IORESOURCE_IRQ
,
420 static struct resource wm831x_ldo6_resources
[] = {
422 .start
= WM831X_LDO6_CONTROL
,
423 .end
= WM831X_LDO6_SLEEP_CONTROL
,
424 .flags
= IORESOURCE_IO
,
428 .start
= WM831X_IRQ_UV_LDO6
,
429 .end
= WM831X_IRQ_UV_LDO6
,
430 .flags
= IORESOURCE_IRQ
,
434 static struct resource wm831x_ldo7_resources
[] = {
436 .start
= WM831X_LDO7_CONTROL
,
437 .end
= WM831X_LDO7_SLEEP_CONTROL
,
438 .flags
= IORESOURCE_IO
,
442 .start
= WM831X_IRQ_UV_LDO7
,
443 .end
= WM831X_IRQ_UV_LDO7
,
444 .flags
= IORESOURCE_IRQ
,
448 static struct resource wm831x_ldo8_resources
[] = {
450 .start
= WM831X_LDO8_CONTROL
,
451 .end
= WM831X_LDO8_SLEEP_CONTROL
,
452 .flags
= IORESOURCE_IO
,
456 .start
= WM831X_IRQ_UV_LDO8
,
457 .end
= WM831X_IRQ_UV_LDO8
,
458 .flags
= IORESOURCE_IRQ
,
462 static struct resource wm831x_ldo9_resources
[] = {
464 .start
= WM831X_LDO9_CONTROL
,
465 .end
= WM831X_LDO9_SLEEP_CONTROL
,
466 .flags
= IORESOURCE_IO
,
470 .start
= WM831X_IRQ_UV_LDO9
,
471 .end
= WM831X_IRQ_UV_LDO9
,
472 .flags
= IORESOURCE_IRQ
,
476 static struct resource wm831x_ldo10_resources
[] = {
478 .start
= WM831X_LDO10_CONTROL
,
479 .end
= WM831X_LDO10_SLEEP_CONTROL
,
480 .flags
= IORESOURCE_IO
,
484 .start
= WM831X_IRQ_UV_LDO10
,
485 .end
= WM831X_IRQ_UV_LDO10
,
486 .flags
= IORESOURCE_IRQ
,
490 static struct resource wm831x_ldo11_resources
[] = {
492 .start
= WM831X_LDO11_ON_CONTROL
,
493 .end
= WM831X_LDO11_SLEEP_CONTROL
,
494 .flags
= IORESOURCE_IO
,
498 static struct resource wm831x_on_resources
[] = {
500 .start
= WM831X_IRQ_ON
,
501 .end
= WM831X_IRQ_ON
,
502 .flags
= IORESOURCE_IRQ
,
507 static struct resource wm831x_power_resources
[] = {
510 .start
= WM831X_IRQ_PPM_SYSLO
,
511 .end
= WM831X_IRQ_PPM_SYSLO
,
512 .flags
= IORESOURCE_IRQ
,
516 .start
= WM831X_IRQ_PPM_PWR_SRC
,
517 .end
= WM831X_IRQ_PPM_PWR_SRC
,
518 .flags
= IORESOURCE_IRQ
,
522 .start
= WM831X_IRQ_PPM_USB_CURR
,
523 .end
= WM831X_IRQ_PPM_USB_CURR
,
524 .flags
= IORESOURCE_IRQ
,
528 .start
= WM831X_IRQ_CHG_BATT_HOT
,
529 .end
= WM831X_IRQ_CHG_BATT_HOT
,
530 .flags
= IORESOURCE_IRQ
,
534 .start
= WM831X_IRQ_CHG_BATT_COLD
,
535 .end
= WM831X_IRQ_CHG_BATT_COLD
,
536 .flags
= IORESOURCE_IRQ
,
540 .start
= WM831X_IRQ_CHG_BATT_FAIL
,
541 .end
= WM831X_IRQ_CHG_BATT_FAIL
,
542 .flags
= IORESOURCE_IRQ
,
546 .start
= WM831X_IRQ_CHG_OV
,
547 .end
= WM831X_IRQ_CHG_OV
,
548 .flags
= IORESOURCE_IRQ
,
552 .start
= WM831X_IRQ_CHG_END
,
553 .end
= WM831X_IRQ_CHG_END
,
554 .flags
= IORESOURCE_IRQ
,
558 .start
= WM831X_IRQ_CHG_TO
,
559 .end
= WM831X_IRQ_CHG_TO
,
560 .flags
= IORESOURCE_IRQ
,
564 .start
= WM831X_IRQ_CHG_MODE
,
565 .end
= WM831X_IRQ_CHG_MODE
,
566 .flags
= IORESOURCE_IRQ
,
570 .start
= WM831X_IRQ_CHG_START
,
571 .end
= WM831X_IRQ_CHG_START
,
572 .flags
= IORESOURCE_IRQ
,
576 static struct resource wm831x_rtc_resources
[] = {
579 .start
= WM831X_IRQ_RTC_PER
,
580 .end
= WM831X_IRQ_RTC_PER
,
581 .flags
= IORESOURCE_IRQ
,
585 .start
= WM831X_IRQ_RTC_ALM
,
586 .end
= WM831X_IRQ_RTC_ALM
,
587 .flags
= IORESOURCE_IRQ
,
591 static struct resource wm831x_status1_resources
[] = {
593 .start
= WM831X_STATUS_LED_1
,
594 .end
= WM831X_STATUS_LED_1
,
595 .flags
= IORESOURCE_IO
,
599 static struct resource wm831x_status2_resources
[] = {
601 .start
= WM831X_STATUS_LED_2
,
602 .end
= WM831X_STATUS_LED_2
,
603 .flags
= IORESOURCE_IO
,
607 static struct resource wm831x_touch_resources
[] = {
610 .start
= WM831X_IRQ_TCHPD
,
611 .end
= WM831X_IRQ_TCHPD
,
612 .flags
= IORESOURCE_IRQ
,
616 .start
= WM831X_IRQ_TCHDATA
,
617 .end
= WM831X_IRQ_TCHDATA
,
618 .flags
= IORESOURCE_IRQ
,
622 static struct resource wm831x_wdt_resources
[] = {
624 .start
= WM831X_IRQ_WDOG_TO
,
625 .end
= WM831X_IRQ_WDOG_TO
,
626 .flags
= IORESOURCE_IRQ
,
630 static struct mfd_cell wm8310_devs
[] = {
632 .name
= "wm831x-buckv",
634 .num_resources
= ARRAY_SIZE(wm831x_dcdc1_resources
),
635 .resources
= wm831x_dcdc1_resources
,
638 .name
= "wm831x-buckv",
640 .num_resources
= ARRAY_SIZE(wm831x_dcdc2_resources
),
641 .resources
= wm831x_dcdc2_resources
,
644 .name
= "wm831x-buckp",
646 .num_resources
= ARRAY_SIZE(wm831x_dcdc3_resources
),
647 .resources
= wm831x_dcdc3_resources
,
650 .name
= "wm831x-boostp",
652 .num_resources
= ARRAY_SIZE(wm831x_dcdc4_resources
),
653 .resources
= wm831x_dcdc4_resources
,
656 .name
= "wm831x-epe",
660 .name
= "wm831x-epe",
664 .name
= "wm831x-gpio",
665 .num_resources
= ARRAY_SIZE(wm831x_gpio_resources
),
666 .resources
= wm831x_gpio_resources
,
669 .name
= "wm831x-hwmon",
672 .name
= "wm831x-isink",
674 .num_resources
= ARRAY_SIZE(wm831x_isink1_resources
),
675 .resources
= wm831x_isink1_resources
,
678 .name
= "wm831x-isink",
680 .num_resources
= ARRAY_SIZE(wm831x_isink2_resources
),
681 .resources
= wm831x_isink2_resources
,
684 .name
= "wm831x-ldo",
686 .num_resources
= ARRAY_SIZE(wm831x_ldo1_resources
),
687 .resources
= wm831x_ldo1_resources
,
690 .name
= "wm831x-ldo",
692 .num_resources
= ARRAY_SIZE(wm831x_ldo2_resources
),
693 .resources
= wm831x_ldo2_resources
,
696 .name
= "wm831x-ldo",
698 .num_resources
= ARRAY_SIZE(wm831x_ldo3_resources
),
699 .resources
= wm831x_ldo3_resources
,
702 .name
= "wm831x-ldo",
704 .num_resources
= ARRAY_SIZE(wm831x_ldo4_resources
),
705 .resources
= wm831x_ldo4_resources
,
708 .name
= "wm831x-ldo",
710 .num_resources
= ARRAY_SIZE(wm831x_ldo5_resources
),
711 .resources
= wm831x_ldo5_resources
,
714 .name
= "wm831x-ldo",
716 .num_resources
= ARRAY_SIZE(wm831x_ldo6_resources
),
717 .resources
= wm831x_ldo6_resources
,
720 .name
= "wm831x-aldo",
722 .num_resources
= ARRAY_SIZE(wm831x_ldo7_resources
),
723 .resources
= wm831x_ldo7_resources
,
726 .name
= "wm831x-aldo",
728 .num_resources
= ARRAY_SIZE(wm831x_ldo8_resources
),
729 .resources
= wm831x_ldo8_resources
,
732 .name
= "wm831x-aldo",
734 .num_resources
= ARRAY_SIZE(wm831x_ldo9_resources
),
735 .resources
= wm831x_ldo9_resources
,
738 .name
= "wm831x-aldo",
740 .num_resources
= ARRAY_SIZE(wm831x_ldo10_resources
),
741 .resources
= wm831x_ldo10_resources
,
744 .name
= "wm831x-alive-ldo",
746 .num_resources
= ARRAY_SIZE(wm831x_ldo11_resources
),
747 .resources
= wm831x_ldo11_resources
,
751 .num_resources
= ARRAY_SIZE(wm831x_on_resources
),
752 .resources
= wm831x_on_resources
,
755 .name
= "wm831x-power",
756 .num_resources
= ARRAY_SIZE(wm831x_power_resources
),
757 .resources
= wm831x_power_resources
,
760 .name
= "wm831x-rtc",
761 .num_resources
= ARRAY_SIZE(wm831x_rtc_resources
),
762 .resources
= wm831x_rtc_resources
,
765 .name
= "wm831x-status",
767 .num_resources
= ARRAY_SIZE(wm831x_status1_resources
),
768 .resources
= wm831x_status1_resources
,
771 .name
= "wm831x-status",
773 .num_resources
= ARRAY_SIZE(wm831x_status2_resources
),
774 .resources
= wm831x_status2_resources
,
777 .name
= "wm831x-watchdog",
778 .num_resources
= ARRAY_SIZE(wm831x_wdt_resources
),
779 .resources
= wm831x_wdt_resources
,
783 static struct mfd_cell wm8311_devs
[] = {
785 .name
= "wm831x-buckv",
787 .num_resources
= ARRAY_SIZE(wm831x_dcdc1_resources
),
788 .resources
= wm831x_dcdc1_resources
,
791 .name
= "wm831x-buckv",
793 .num_resources
= ARRAY_SIZE(wm831x_dcdc2_resources
),
794 .resources
= wm831x_dcdc2_resources
,
797 .name
= "wm831x-buckp",
799 .num_resources
= ARRAY_SIZE(wm831x_dcdc3_resources
),
800 .resources
= wm831x_dcdc3_resources
,
803 .name
= "wm831x-boostp",
805 .num_resources
= ARRAY_SIZE(wm831x_dcdc4_resources
),
806 .resources
= wm831x_dcdc4_resources
,
809 .name
= "wm831x-epe",
813 .name
= "wm831x-epe",
817 .name
= "wm831x-gpio",
818 .num_resources
= ARRAY_SIZE(wm831x_gpio_resources
),
819 .resources
= wm831x_gpio_resources
,
822 .name
= "wm831x-hwmon",
825 .name
= "wm831x-isink",
827 .num_resources
= ARRAY_SIZE(wm831x_isink1_resources
),
828 .resources
= wm831x_isink1_resources
,
831 .name
= "wm831x-isink",
833 .num_resources
= ARRAY_SIZE(wm831x_isink2_resources
),
834 .resources
= wm831x_isink2_resources
,
837 .name
= "wm831x-ldo",
839 .num_resources
= ARRAY_SIZE(wm831x_ldo1_resources
),
840 .resources
= wm831x_ldo1_resources
,
843 .name
= "wm831x-ldo",
845 .num_resources
= ARRAY_SIZE(wm831x_ldo2_resources
),
846 .resources
= wm831x_ldo2_resources
,
849 .name
= "wm831x-ldo",
851 .num_resources
= ARRAY_SIZE(wm831x_ldo3_resources
),
852 .resources
= wm831x_ldo3_resources
,
855 .name
= "wm831x-ldo",
857 .num_resources
= ARRAY_SIZE(wm831x_ldo4_resources
),
858 .resources
= wm831x_ldo4_resources
,
861 .name
= "wm831x-ldo",
863 .num_resources
= ARRAY_SIZE(wm831x_ldo5_resources
),
864 .resources
= wm831x_ldo5_resources
,
867 .name
= "wm831x-aldo",
869 .num_resources
= ARRAY_SIZE(wm831x_ldo7_resources
),
870 .resources
= wm831x_ldo7_resources
,
873 .name
= "wm831x-alive-ldo",
875 .num_resources
= ARRAY_SIZE(wm831x_ldo11_resources
),
876 .resources
= wm831x_ldo11_resources
,
880 .num_resources
= ARRAY_SIZE(wm831x_on_resources
),
881 .resources
= wm831x_on_resources
,
884 .name
= "wm831x-power",
885 .num_resources
= ARRAY_SIZE(wm831x_power_resources
),
886 .resources
= wm831x_power_resources
,
889 .name
= "wm831x-rtc",
890 .num_resources
= ARRAY_SIZE(wm831x_rtc_resources
),
891 .resources
= wm831x_rtc_resources
,
894 .name
= "wm831x-status",
896 .num_resources
= ARRAY_SIZE(wm831x_status1_resources
),
897 .resources
= wm831x_status1_resources
,
900 .name
= "wm831x-status",
902 .num_resources
= ARRAY_SIZE(wm831x_status2_resources
),
903 .resources
= wm831x_status2_resources
,
906 .name
= "wm831x-touch",
907 .num_resources
= ARRAY_SIZE(wm831x_touch_resources
),
908 .resources
= wm831x_touch_resources
,
911 .name
= "wm831x-watchdog",
912 .num_resources
= ARRAY_SIZE(wm831x_wdt_resources
),
913 .resources
= wm831x_wdt_resources
,
917 static struct mfd_cell wm8312_devs
[] = {
919 .name
= "wm831x-buckv",
921 .num_resources
= ARRAY_SIZE(wm831x_dcdc1_resources
),
922 .resources
= wm831x_dcdc1_resources
,
925 .name
= "wm831x-buckv",
927 .num_resources
= ARRAY_SIZE(wm831x_dcdc2_resources
),
928 .resources
= wm831x_dcdc2_resources
,
931 .name
= "wm831x-buckp",
933 .num_resources
= ARRAY_SIZE(wm831x_dcdc3_resources
),
934 .resources
= wm831x_dcdc3_resources
,
937 .name
= "wm831x-boostp",
939 .num_resources
= ARRAY_SIZE(wm831x_dcdc4_resources
),
940 .resources
= wm831x_dcdc4_resources
,
943 .name
= "wm831x-epe",
947 .name
= "wm831x-epe",
951 .name
= "wm831x-gpio",
952 .num_resources
= ARRAY_SIZE(wm831x_gpio_resources
),
953 .resources
= wm831x_gpio_resources
,
956 .name
= "wm831x-hwmon",
959 .name
= "wm831x-isink",
961 .num_resources
= ARRAY_SIZE(wm831x_isink1_resources
),
962 .resources
= wm831x_isink1_resources
,
965 .name
= "wm831x-isink",
967 .num_resources
= ARRAY_SIZE(wm831x_isink2_resources
),
968 .resources
= wm831x_isink2_resources
,
971 .name
= "wm831x-ldo",
973 .num_resources
= ARRAY_SIZE(wm831x_ldo1_resources
),
974 .resources
= wm831x_ldo1_resources
,
977 .name
= "wm831x-ldo",
979 .num_resources
= ARRAY_SIZE(wm831x_ldo2_resources
),
980 .resources
= wm831x_ldo2_resources
,
983 .name
= "wm831x-ldo",
985 .num_resources
= ARRAY_SIZE(wm831x_ldo3_resources
),
986 .resources
= wm831x_ldo3_resources
,
989 .name
= "wm831x-ldo",
991 .num_resources
= ARRAY_SIZE(wm831x_ldo4_resources
),
992 .resources
= wm831x_ldo4_resources
,
995 .name
= "wm831x-ldo",
997 .num_resources
= ARRAY_SIZE(wm831x_ldo5_resources
),
998 .resources
= wm831x_ldo5_resources
,
1001 .name
= "wm831x-ldo",
1003 .num_resources
= ARRAY_SIZE(wm831x_ldo6_resources
),
1004 .resources
= wm831x_ldo6_resources
,
1007 .name
= "wm831x-aldo",
1009 .num_resources
= ARRAY_SIZE(wm831x_ldo7_resources
),
1010 .resources
= wm831x_ldo7_resources
,
1013 .name
= "wm831x-aldo",
1015 .num_resources
= ARRAY_SIZE(wm831x_ldo8_resources
),
1016 .resources
= wm831x_ldo8_resources
,
1019 .name
= "wm831x-aldo",
1021 .num_resources
= ARRAY_SIZE(wm831x_ldo9_resources
),
1022 .resources
= wm831x_ldo9_resources
,
1025 .name
= "wm831x-aldo",
1027 .num_resources
= ARRAY_SIZE(wm831x_ldo10_resources
),
1028 .resources
= wm831x_ldo10_resources
,
1031 .name
= "wm831x-alive-ldo",
1033 .num_resources
= ARRAY_SIZE(wm831x_ldo11_resources
),
1034 .resources
= wm831x_ldo11_resources
,
1037 .name
= "wm831x-on",
1038 .num_resources
= ARRAY_SIZE(wm831x_on_resources
),
1039 .resources
= wm831x_on_resources
,
1042 .name
= "wm831x-power",
1043 .num_resources
= ARRAY_SIZE(wm831x_power_resources
),
1044 .resources
= wm831x_power_resources
,
1047 .name
= "wm831x-rtc",
1048 .num_resources
= ARRAY_SIZE(wm831x_rtc_resources
),
1049 .resources
= wm831x_rtc_resources
,
1052 .name
= "wm831x-status",
1054 .num_resources
= ARRAY_SIZE(wm831x_status1_resources
),
1055 .resources
= wm831x_status1_resources
,
1058 .name
= "wm831x-status",
1060 .num_resources
= ARRAY_SIZE(wm831x_status2_resources
),
1061 .resources
= wm831x_status2_resources
,
1064 .name
= "wm831x-touch",
1065 .num_resources
= ARRAY_SIZE(wm831x_touch_resources
),
1066 .resources
= wm831x_touch_resources
,
1069 .name
= "wm831x-watchdog",
1070 .num_resources
= ARRAY_SIZE(wm831x_wdt_resources
),
1071 .resources
= wm831x_wdt_resources
,
1076 * Instantiate the generic non-control parts of the device.
1078 static int wm831x_device_init(struct wm831x
*wm831x
, unsigned long id
, int irq
)
1080 struct wm831x_pdata
*pdata
= wm831x
->dev
->platform_data
;
1082 enum wm831x_parent parent
;
1085 mutex_init(&wm831x
->io_lock
);
1086 mutex_init(&wm831x
->key_lock
);
1087 dev_set_drvdata(wm831x
->dev
, wm831x
);
1089 ret
= wm831x_reg_read(wm831x
, WM831X_PARENT_ID
);
1091 dev_err(wm831x
->dev
, "Failed to read parent ID: %d\n", ret
);
1094 if (ret
!= 0x6204) {
1095 dev_err(wm831x
->dev
, "Device is not a WM831x: ID %x\n", ret
);
1100 ret
= wm831x_reg_read(wm831x
, WM831X_REVISION
);
1102 dev_err(wm831x
->dev
, "Failed to read revision: %d\n", ret
);
1105 rev
= (ret
& WM831X_PARENT_REV_MASK
) >> WM831X_PARENT_REV_SHIFT
;
1107 ret
= wm831x_reg_read(wm831x
, WM831X_RESET_ID
);
1109 dev_err(wm831x
->dev
, "Failed to read device ID: %d\n", ret
);
1118 dev_info(wm831x
->dev
, "WM8310 revision %c\n",
1128 dev_info(wm831x
->dev
, "WM8311 revision %c\n",
1138 dev_info(wm831x
->dev
, "WM8312 revision %c\n",
1145 /* Some engineering samples do not have the ID set,
1146 * rely on the device being registered correctly.
1147 * This will need revisiting for future devices with
1153 dev_info(wm831x
->dev
, "WM831%d ES revision %c\n",
1160 dev_err(wm831x
->dev
, "Unknown WM831x device %04x\n", ret
);
1165 /* This will need revisiting in future but is OK for all
1169 dev_warn(wm831x
->dev
, "Device was registered as a WM831%lu\n",
1172 /* Bootstrap the user key */
1173 ret
= wm831x_reg_read(wm831x
, WM831X_SECURITY_KEY
);
1175 dev_err(wm831x
->dev
, "Failed to read security key: %d\n", ret
);
1179 dev_warn(wm831x
->dev
, "Security key had non-zero value %x\n",
1181 wm831x_reg_write(wm831x
, WM831X_SECURITY_KEY
, 0);
1185 if (pdata
&& pdata
->pre_init
) {
1186 ret
= pdata
->pre_init(wm831x
);
1188 dev_err(wm831x
->dev
, "pre_init() failed: %d\n", ret
);
1193 ret
= wm831x_irq_init(wm831x
, irq
);
1197 /* The core device is up, instantiate the subdevices. */
1200 ret
= mfd_add_devices(wm831x
->dev
, -1,
1201 wm8310_devs
, ARRAY_SIZE(wm8310_devs
),
1206 ret
= mfd_add_devices(wm831x
->dev
, -1,
1207 wm8311_devs
, ARRAY_SIZE(wm8311_devs
),
1212 ret
= mfd_add_devices(wm831x
->dev
, -1,
1213 wm8312_devs
, ARRAY_SIZE(wm8312_devs
),
1218 /* If this happens the bus probe function is buggy */
1223 dev_err(wm831x
->dev
, "Failed to add children\n");
1227 if (pdata
&& pdata
->post_init
) {
1228 ret
= pdata
->post_init(wm831x
);
1230 dev_err(wm831x
->dev
, "post_init() failed: %d\n", ret
);
1238 wm831x_irq_exit(wm831x
);
1240 mfd_remove_devices(wm831x
->dev
);
1245 static void wm831x_device_exit(struct wm831x
*wm831x
)
1247 mfd_remove_devices(wm831x
->dev
);
1248 wm831x_irq_exit(wm831x
);
1252 static int wm831x_i2c_read_device(struct wm831x
*wm831x
, unsigned short reg
,
1253 int bytes
, void *dest
)
1255 struct i2c_client
*i2c
= wm831x
->control_data
;
1257 u16 r
= cpu_to_be16(reg
);
1259 ret
= i2c_master_send(i2c
, (unsigned char *)&r
, 2);
1265 ret
= i2c_master_recv(i2c
, dest
, bytes
);
1273 /* Currently we allocate the write buffer on the stack; this is OK for
1274 * small writes - if we need to do large writes this will need to be
1277 static int wm831x_i2c_write_device(struct wm831x
*wm831x
, unsigned short reg
,
1278 int bytes
, void *src
)
1280 struct i2c_client
*i2c
= wm831x
->control_data
;
1281 unsigned char msg
[bytes
+ 2];
1284 reg
= cpu_to_be16(reg
);
1285 memcpy(&msg
[0], ®
, 2);
1286 memcpy(&msg
[2], src
, bytes
);
1288 ret
= i2c_master_send(i2c
, msg
, bytes
+ 2);
1291 if (ret
< bytes
+ 2)
1297 static int wm831x_i2c_probe(struct i2c_client
*i2c
,
1298 const struct i2c_device_id
*id
)
1300 struct wm831x
*wm831x
;
1302 wm831x
= kzalloc(sizeof(struct wm831x
), GFP_KERNEL
);
1303 if (wm831x
== NULL
) {
1308 i2c_set_clientdata(i2c
, wm831x
);
1309 wm831x
->dev
= &i2c
->dev
;
1310 wm831x
->control_data
= i2c
;
1311 wm831x
->read_dev
= wm831x_i2c_read_device
;
1312 wm831x
->write_dev
= wm831x_i2c_write_device
;
1314 return wm831x_device_init(wm831x
, id
->driver_data
, i2c
->irq
);
1317 static int wm831x_i2c_remove(struct i2c_client
*i2c
)
1319 struct wm831x
*wm831x
= i2c_get_clientdata(i2c
);
1321 wm831x_device_exit(wm831x
);
1326 static const struct i2c_device_id wm831x_i2c_id
[] = {
1327 { "wm8310", WM8310
},
1328 { "wm8311", WM8311
},
1329 { "wm8312", WM8312
},
1332 MODULE_DEVICE_TABLE(i2c
, wm831x_i2c_id
);
1335 static struct i2c_driver wm831x_i2c_driver
= {
1338 .owner
= THIS_MODULE
,
1340 .probe
= wm831x_i2c_probe
,
1341 .remove
= wm831x_i2c_remove
,
1342 .id_table
= wm831x_i2c_id
,
1345 static int __init
wm831x_i2c_init(void)
1349 ret
= i2c_add_driver(&wm831x_i2c_driver
);
1351 pr_err("Failed to register wm831x I2C driver: %d\n", ret
);
1355 subsys_initcall(wm831x_i2c_init
);
1357 static void __exit
wm831x_i2c_exit(void)
1359 i2c_del_driver(&wm831x_i2c_driver
);
1361 module_exit(wm831x_i2c_exit
);
1363 MODULE_DESCRIPTION("I2C support for the WM831X AudioPlus PMIC");
1364 MODULE_LICENSE("GPL");
1365 MODULE_AUTHOR("Mark Brown");