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>
29 static int wm831x_reg_locked(struct wm831x *wm831x, unsigned short reg)
36 case WM831X_DC4_CONTROL:
37 case WM831X_ON_PIN_CONTROL:
38 case WM831X_BACKUP_CHARGER_CONTROL:
39 case WM831X_CHARGER_CONTROL_1:
40 case WM831X_CHARGER_CONTROL_2:
49 * wm831x_reg_unlock: Unlock user keyed registers
51 * The WM831x has a user key preventing writes to particularly
52 * critical registers. This function locks those registers,
53 * allowing writes to them.
55 void wm831x_reg_lock(struct wm831x *wm831x)
59 ret = wm831x_reg_write(wm831x, WM831X_SECURITY_KEY, 0);
61 dev_vdbg(wm831x->dev, "Registers locked\n");
63 mutex_lock(&wm831x->io_lock);
64 WARN_ON(wm831x->locked);
66 mutex_unlock(&wm831x->io_lock);
68 dev_err(wm831x->dev, "Failed to lock registers: %d\n", ret);
72 EXPORT_SYMBOL_GPL(wm831x_reg_lock);
75 * wm831x_reg_unlock: Unlock user keyed registers
77 * The WM831x has a user key preventing writes to particularly
78 * critical registers. This function locks those registers,
79 * preventing spurious writes.
81 int wm831x_reg_unlock(struct wm831x *wm831x)
85 /* 0x9716 is the value required to unlock the registers */
86 ret = wm831x_reg_write(wm831x, WM831X_SECURITY_KEY, 0x9716);
88 dev_vdbg(wm831x->dev, "Registers unlocked\n");
90 mutex_lock(&wm831x->io_lock);
91 WARN_ON(!wm831x->locked);
93 mutex_unlock(&wm831x->io_lock);
98 EXPORT_SYMBOL_GPL(wm831x_reg_unlock);
100 static int wm831x_read(struct wm831x *wm831x, unsigned short reg,
101 int bytes, void *dest)
109 ret = wm831x->read_dev(wm831x, reg, bytes, dest);
113 for (i = 0; i < bytes / 2; i++) {
114 buf[i] = be16_to_cpu(buf[i]);
116 dev_vdbg(wm831x->dev, "Read %04x from R%d(0x%x)\n",
117 buf[i], reg + i, reg + i);
124 * wm831x_reg_read: Read a single WM831x register.
126 * @wm831x: Device to read from.
127 * @reg: Register to read.
129 int wm831x_reg_read(struct wm831x *wm831x, unsigned short reg)
134 mutex_lock(&wm831x->io_lock);
136 ret = wm831x_read(wm831x, reg, 2, &val);
138 mutex_unlock(&wm831x->io_lock);
145 EXPORT_SYMBOL_GPL(wm831x_reg_read);
148 * wm831x_bulk_read: Read multiple WM831x registers
150 * @wm831x: Device to read from
151 * @reg: First register
152 * @count: Number of registers
153 * @buf: Buffer to fill.
155 int wm831x_bulk_read(struct wm831x *wm831x, unsigned short reg,
160 mutex_lock(&wm831x->io_lock);
162 ret = wm831x_read(wm831x, reg, count * 2, buf);
164 mutex_unlock(&wm831x->io_lock);
168 EXPORT_SYMBOL_GPL(wm831x_bulk_read);
170 static int wm831x_write(struct wm831x *wm831x, unsigned short reg,
171 int bytes, void *src)
179 for (i = 0; i < bytes / 2; i++) {
180 if (wm831x_reg_locked(wm831x, reg))
183 dev_vdbg(wm831x->dev, "Write %04x to R%d(0x%x)\n",
184 buf[i], reg + i, reg + i);
186 buf[i] = cpu_to_be16(buf[i]);
189 return wm831x->write_dev(wm831x, reg, bytes, src);
193 * wm831x_reg_write: Write a single WM831x register.
195 * @wm831x: Device to write to.
196 * @reg: Register to write to.
197 * @val: Value to write.
199 int wm831x_reg_write(struct wm831x *wm831x, unsigned short reg,
204 mutex_lock(&wm831x->io_lock);
206 ret = wm831x_write(wm831x, reg, 2, &val);
208 mutex_unlock(&wm831x->io_lock);
212 EXPORT_SYMBOL_GPL(wm831x_reg_write);
215 * wm831x_set_bits: Set the value of a bitfield in a WM831x register
217 * @wm831x: Device to write to.
218 * @reg: Register to write to.
219 * @mask: Mask of bits to set.
220 * @val: Value to set (unshifted)
222 int wm831x_set_bits(struct wm831x *wm831x, unsigned short reg,
223 unsigned short mask, unsigned short val)
228 mutex_lock(&wm831x->io_lock);
230 ret = wm831x_read(wm831x, reg, 2, &r);
237 ret = wm831x_write(wm831x, reg, 2, &r);
240 mutex_unlock(&wm831x->io_lock);
244 EXPORT_SYMBOL_GPL(wm831x_set_bits);
246 static struct resource wm831x_dcdc1_resources[] = {
248 .start = WM831X_DC1_CONTROL_1,
249 .end = WM831X_DC1_DVS_CONTROL,
250 .flags = IORESOURCE_IO,
254 .start = WM831X_IRQ_UV_DC1,
255 .end = WM831X_IRQ_UV_DC1,
256 .flags = IORESOURCE_IRQ,
260 .start = WM831X_IRQ_HC_DC1,
261 .end = WM831X_IRQ_HC_DC1,
262 .flags = IORESOURCE_IRQ,
267 static struct resource wm831x_dcdc2_resources[] = {
269 .start = WM831X_DC2_CONTROL_1,
270 .end = WM831X_DC2_DVS_CONTROL,
271 .flags = IORESOURCE_IO,
275 .start = WM831X_IRQ_UV_DC2,
276 .end = WM831X_IRQ_UV_DC2,
277 .flags = IORESOURCE_IRQ,
281 .start = WM831X_IRQ_HC_DC2,
282 .end = WM831X_IRQ_HC_DC2,
283 .flags = IORESOURCE_IRQ,
287 static struct resource wm831x_dcdc3_resources[] = {
289 .start = WM831X_DC3_CONTROL_1,
290 .end = WM831X_DC3_SLEEP_CONTROL,
291 .flags = IORESOURCE_IO,
295 .start = WM831X_IRQ_UV_DC3,
296 .end = WM831X_IRQ_UV_DC3,
297 .flags = IORESOURCE_IRQ,
301 static struct resource wm831x_dcdc4_resources[] = {
303 .start = WM831X_DC4_CONTROL,
304 .end = WM831X_DC4_SLEEP_CONTROL,
305 .flags = IORESOURCE_IO,
309 .start = WM831X_IRQ_UV_DC4,
310 .end = WM831X_IRQ_UV_DC4,
311 .flags = IORESOURCE_IRQ,
315 static struct resource wm831x_gpio_resources[] = {
317 .start = WM831X_IRQ_GPIO_1,
318 .end = WM831X_IRQ_GPIO_16,
319 .flags = IORESOURCE_IRQ,
323 static struct resource wm831x_isink1_resources[] = {
325 .start = WM831X_CURRENT_SINK_1,
326 .end = WM831X_CURRENT_SINK_1,
327 .flags = IORESOURCE_IO,
330 .start = WM831X_IRQ_CS1,
331 .end = WM831X_IRQ_CS1,
332 .flags = IORESOURCE_IRQ,
336 static struct resource wm831x_isink2_resources[] = {
338 .start = WM831X_CURRENT_SINK_2,
339 .end = WM831X_CURRENT_SINK_2,
340 .flags = IORESOURCE_IO,
343 .start = WM831X_IRQ_CS2,
344 .end = WM831X_IRQ_CS2,
345 .flags = IORESOURCE_IRQ,
349 static struct resource wm831x_ldo1_resources[] = {
351 .start = WM831X_LDO1_CONTROL,
352 .end = WM831X_LDO1_SLEEP_CONTROL,
353 .flags = IORESOURCE_IO,
357 .start = WM831X_IRQ_UV_LDO1,
358 .end = WM831X_IRQ_UV_LDO1,
359 .flags = IORESOURCE_IRQ,
363 static struct resource wm831x_ldo2_resources[] = {
365 .start = WM831X_LDO2_CONTROL,
366 .end = WM831X_LDO2_SLEEP_CONTROL,
367 .flags = IORESOURCE_IO,
371 .start = WM831X_IRQ_UV_LDO2,
372 .end = WM831X_IRQ_UV_LDO2,
373 .flags = IORESOURCE_IRQ,
377 static struct resource wm831x_ldo3_resources[] = {
379 .start = WM831X_LDO3_CONTROL,
380 .end = WM831X_LDO3_SLEEP_CONTROL,
381 .flags = IORESOURCE_IO,
385 .start = WM831X_IRQ_UV_LDO3,
386 .end = WM831X_IRQ_UV_LDO3,
387 .flags = IORESOURCE_IRQ,
391 static struct resource wm831x_ldo4_resources[] = {
393 .start = WM831X_LDO4_CONTROL,
394 .end = WM831X_LDO4_SLEEP_CONTROL,
395 .flags = IORESOURCE_IO,
399 .start = WM831X_IRQ_UV_LDO4,
400 .end = WM831X_IRQ_UV_LDO4,
401 .flags = IORESOURCE_IRQ,
405 static struct resource wm831x_ldo5_resources[] = {
407 .start = WM831X_LDO5_CONTROL,
408 .end = WM831X_LDO5_SLEEP_CONTROL,
409 .flags = IORESOURCE_IO,
413 .start = WM831X_IRQ_UV_LDO5,
414 .end = WM831X_IRQ_UV_LDO5,
415 .flags = IORESOURCE_IRQ,
419 static struct resource wm831x_ldo6_resources[] = {
421 .start = WM831X_LDO6_CONTROL,
422 .end = WM831X_LDO6_SLEEP_CONTROL,
423 .flags = IORESOURCE_IO,
427 .start = WM831X_IRQ_UV_LDO6,
428 .end = WM831X_IRQ_UV_LDO6,
429 .flags = IORESOURCE_IRQ,
433 static struct resource wm831x_ldo7_resources[] = {
435 .start = WM831X_LDO7_CONTROL,
436 .end = WM831X_LDO7_SLEEP_CONTROL,
437 .flags = IORESOURCE_IO,
441 .start = WM831X_IRQ_UV_LDO7,
442 .end = WM831X_IRQ_UV_LDO7,
443 .flags = IORESOURCE_IRQ,
447 static struct resource wm831x_ldo8_resources[] = {
449 .start = WM831X_LDO8_CONTROL,
450 .end = WM831X_LDO8_SLEEP_CONTROL,
451 .flags = IORESOURCE_IO,
455 .start = WM831X_IRQ_UV_LDO8,
456 .end = WM831X_IRQ_UV_LDO8,
457 .flags = IORESOURCE_IRQ,
461 static struct resource wm831x_ldo9_resources[] = {
463 .start = WM831X_LDO9_CONTROL,
464 .end = WM831X_LDO9_SLEEP_CONTROL,
465 .flags = IORESOURCE_IO,
469 .start = WM831X_IRQ_UV_LDO9,
470 .end = WM831X_IRQ_UV_LDO9,
471 .flags = IORESOURCE_IRQ,
475 static struct resource wm831x_ldo10_resources[] = {
477 .start = WM831X_LDO10_CONTROL,
478 .end = WM831X_LDO10_SLEEP_CONTROL,
479 .flags = IORESOURCE_IO,
483 .start = WM831X_IRQ_UV_LDO10,
484 .end = WM831X_IRQ_UV_LDO10,
485 .flags = IORESOURCE_IRQ,
489 static struct resource wm831x_ldo11_resources[] = {
491 .start = WM831X_LDO11_ON_CONTROL,
492 .end = WM831X_LDO11_SLEEP_CONTROL,
493 .flags = IORESOURCE_IO,
497 static struct resource wm831x_on_resources[] = {
499 .start = WM831X_IRQ_ON,
500 .end = WM831X_IRQ_ON,
501 .flags = IORESOURCE_IRQ,
506 static struct resource wm831x_power_resources[] = {
509 .start = WM831X_IRQ_PPM_SYSLO,
510 .end = WM831X_IRQ_PPM_SYSLO,
511 .flags = IORESOURCE_IRQ,
515 .start = WM831X_IRQ_PPM_PWR_SRC,
516 .end = WM831X_IRQ_PPM_PWR_SRC,
517 .flags = IORESOURCE_IRQ,
521 .start = WM831X_IRQ_PPM_USB_CURR,
522 .end = WM831X_IRQ_PPM_USB_CURR,
523 .flags = IORESOURCE_IRQ,
527 .start = WM831X_IRQ_CHG_BATT_HOT,
528 .end = WM831X_IRQ_CHG_BATT_HOT,
529 .flags = IORESOURCE_IRQ,
533 .start = WM831X_IRQ_CHG_BATT_COLD,
534 .end = WM831X_IRQ_CHG_BATT_COLD,
535 .flags = IORESOURCE_IRQ,
539 .start = WM831X_IRQ_CHG_BATT_FAIL,
540 .end = WM831X_IRQ_CHG_BATT_FAIL,
541 .flags = IORESOURCE_IRQ,
545 .start = WM831X_IRQ_CHG_OV,
546 .end = WM831X_IRQ_CHG_OV,
547 .flags = IORESOURCE_IRQ,
551 .start = WM831X_IRQ_CHG_END,
552 .end = WM831X_IRQ_CHG_END,
553 .flags = IORESOURCE_IRQ,
557 .start = WM831X_IRQ_CHG_TO,
558 .end = WM831X_IRQ_CHG_TO,
559 .flags = IORESOURCE_IRQ,
563 .start = WM831X_IRQ_CHG_MODE,
564 .end = WM831X_IRQ_CHG_MODE,
565 .flags = IORESOURCE_IRQ,
569 .start = WM831X_IRQ_CHG_START,
570 .end = WM831X_IRQ_CHG_START,
571 .flags = IORESOURCE_IRQ,
575 static struct resource wm831x_rtc_resources[] = {
578 .start = WM831X_IRQ_RTC_PER,
579 .end = WM831X_IRQ_RTC_PER,
580 .flags = IORESOURCE_IRQ,
584 .start = WM831X_IRQ_RTC_ALM,
585 .end = WM831X_IRQ_RTC_ALM,
586 .flags = IORESOURCE_IRQ,
590 static struct resource wm831x_status1_resources[] = {
592 .start = WM831X_STATUS_LED_1,
593 .end = WM831X_STATUS_LED_1,
594 .flags = IORESOURCE_IO,
598 static struct resource wm831x_status2_resources[] = {
600 .start = WM831X_STATUS_LED_2,
601 .end = WM831X_STATUS_LED_2,
602 .flags = IORESOURCE_IO,
606 static struct resource wm831x_touch_resources[] = {
609 .start = WM831X_IRQ_TCHPD,
610 .end = WM831X_IRQ_TCHPD,
611 .flags = IORESOURCE_IRQ,
615 .start = WM831X_IRQ_TCHDATA,
616 .end = WM831X_IRQ_TCHDATA,
617 .flags = IORESOURCE_IRQ,
621 static struct resource wm831x_wdt_resources[] = {
623 .start = WM831X_IRQ_WDOG_TO,
624 .end = WM831X_IRQ_WDOG_TO,
625 .flags = IORESOURCE_IRQ,
629 static struct mfd_cell wm8310_devs[] = {
631 .name = "wm831x-buckv",
633 .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources),
634 .resources = wm831x_dcdc1_resources,
637 .name = "wm831x-buckv",
639 .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources),
640 .resources = wm831x_dcdc2_resources,
643 .name = "wm831x-buckp",
645 .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources),
646 .resources = wm831x_dcdc3_resources,
649 .name = "wm831x-boostp",
651 .num_resources = ARRAY_SIZE(wm831x_dcdc4_resources),
652 .resources = wm831x_dcdc4_resources,
655 .name = "wm831x-epe",
659 .name = "wm831x-epe",
663 .name = "wm831x-gpio",
664 .num_resources = ARRAY_SIZE(wm831x_gpio_resources),
665 .resources = wm831x_gpio_resources,
668 .name = "wm831x-hwmon",
671 .name = "wm831x-isink",
673 .num_resources = ARRAY_SIZE(wm831x_isink1_resources),
674 .resources = wm831x_isink1_resources,
677 .name = "wm831x-isink",
679 .num_resources = ARRAY_SIZE(wm831x_isink2_resources),
680 .resources = wm831x_isink2_resources,
683 .name = "wm831x-ldo",
685 .num_resources = ARRAY_SIZE(wm831x_ldo1_resources),
686 .resources = wm831x_ldo1_resources,
689 .name = "wm831x-ldo",
691 .num_resources = ARRAY_SIZE(wm831x_ldo2_resources),
692 .resources = wm831x_ldo2_resources,
695 .name = "wm831x-ldo",
697 .num_resources = ARRAY_SIZE(wm831x_ldo3_resources),
698 .resources = wm831x_ldo3_resources,
701 .name = "wm831x-ldo",
703 .num_resources = ARRAY_SIZE(wm831x_ldo4_resources),
704 .resources = wm831x_ldo4_resources,
707 .name = "wm831x-ldo",
709 .num_resources = ARRAY_SIZE(wm831x_ldo5_resources),
710 .resources = wm831x_ldo5_resources,
713 .name = "wm831x-ldo",
715 .num_resources = ARRAY_SIZE(wm831x_ldo6_resources),
716 .resources = wm831x_ldo6_resources,
719 .name = "wm831x-aldo",
721 .num_resources = ARRAY_SIZE(wm831x_ldo7_resources),
722 .resources = wm831x_ldo7_resources,
725 .name = "wm831x-aldo",
727 .num_resources = ARRAY_SIZE(wm831x_ldo8_resources),
728 .resources = wm831x_ldo8_resources,
731 .name = "wm831x-aldo",
733 .num_resources = ARRAY_SIZE(wm831x_ldo9_resources),
734 .resources = wm831x_ldo9_resources,
737 .name = "wm831x-aldo",
739 .num_resources = ARRAY_SIZE(wm831x_ldo10_resources),
740 .resources = wm831x_ldo10_resources,
743 .name = "wm831x-alive-ldo",
745 .num_resources = ARRAY_SIZE(wm831x_ldo11_resources),
746 .resources = wm831x_ldo11_resources,
750 .num_resources = ARRAY_SIZE(wm831x_on_resources),
751 .resources = wm831x_on_resources,
754 .name = "wm831x-power",
755 .num_resources = ARRAY_SIZE(wm831x_power_resources),
756 .resources = wm831x_power_resources,
759 .name = "wm831x-rtc",
760 .num_resources = ARRAY_SIZE(wm831x_rtc_resources),
761 .resources = wm831x_rtc_resources,
764 .name = "wm831x-status",
766 .num_resources = ARRAY_SIZE(wm831x_status1_resources),
767 .resources = wm831x_status1_resources,
770 .name = "wm831x-status",
772 .num_resources = ARRAY_SIZE(wm831x_status2_resources),
773 .resources = wm831x_status2_resources,
776 .name = "wm831x-watchdog",
777 .num_resources = ARRAY_SIZE(wm831x_wdt_resources),
778 .resources = wm831x_wdt_resources,
782 static struct mfd_cell wm8311_devs[] = {
784 .name = "wm831x-buckv",
786 .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources),
787 .resources = wm831x_dcdc1_resources,
790 .name = "wm831x-buckv",
792 .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources),
793 .resources = wm831x_dcdc2_resources,
796 .name = "wm831x-buckp",
798 .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources),
799 .resources = wm831x_dcdc3_resources,
802 .name = "wm831x-boostp",
804 .num_resources = ARRAY_SIZE(wm831x_dcdc4_resources),
805 .resources = wm831x_dcdc4_resources,
808 .name = "wm831x-epe",
812 .name = "wm831x-epe",
816 .name = "wm831x-gpio",
817 .num_resources = ARRAY_SIZE(wm831x_gpio_resources),
818 .resources = wm831x_gpio_resources,
821 .name = "wm831x-hwmon",
824 .name = "wm831x-isink",
826 .num_resources = ARRAY_SIZE(wm831x_isink1_resources),
827 .resources = wm831x_isink1_resources,
830 .name = "wm831x-isink",
832 .num_resources = ARRAY_SIZE(wm831x_isink2_resources),
833 .resources = wm831x_isink2_resources,
836 .name = "wm831x-ldo",
838 .num_resources = ARRAY_SIZE(wm831x_ldo1_resources),
839 .resources = wm831x_ldo1_resources,
842 .name = "wm831x-ldo",
844 .num_resources = ARRAY_SIZE(wm831x_ldo2_resources),
845 .resources = wm831x_ldo2_resources,
848 .name = "wm831x-ldo",
850 .num_resources = ARRAY_SIZE(wm831x_ldo3_resources),
851 .resources = wm831x_ldo3_resources,
854 .name = "wm831x-ldo",
856 .num_resources = ARRAY_SIZE(wm831x_ldo4_resources),
857 .resources = wm831x_ldo4_resources,
860 .name = "wm831x-ldo",
862 .num_resources = ARRAY_SIZE(wm831x_ldo5_resources),
863 .resources = wm831x_ldo5_resources,
866 .name = "wm831x-aldo",
868 .num_resources = ARRAY_SIZE(wm831x_ldo7_resources),
869 .resources = wm831x_ldo7_resources,
872 .name = "wm831x-alive-ldo",
874 .num_resources = ARRAY_SIZE(wm831x_ldo11_resources),
875 .resources = wm831x_ldo11_resources,
879 .num_resources = ARRAY_SIZE(wm831x_on_resources),
880 .resources = wm831x_on_resources,
883 .name = "wm831x-power",
884 .num_resources = ARRAY_SIZE(wm831x_power_resources),
885 .resources = wm831x_power_resources,
888 .name = "wm831x-rtc",
889 .num_resources = ARRAY_SIZE(wm831x_rtc_resources),
890 .resources = wm831x_rtc_resources,
893 .name = "wm831x-status",
895 .num_resources = ARRAY_SIZE(wm831x_status1_resources),
896 .resources = wm831x_status1_resources,
899 .name = "wm831x-status",
901 .num_resources = ARRAY_SIZE(wm831x_status2_resources),
902 .resources = wm831x_status2_resources,
905 .name = "wm831x-touch",
906 .num_resources = ARRAY_SIZE(wm831x_touch_resources),
907 .resources = wm831x_touch_resources,
910 .name = "wm831x-watchdog",
911 .num_resources = ARRAY_SIZE(wm831x_wdt_resources),
912 .resources = wm831x_wdt_resources,
916 static struct mfd_cell wm8312_devs[] = {
918 .name = "wm831x-buckv",
920 .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources),
921 .resources = wm831x_dcdc1_resources,
924 .name = "wm831x-buckv",
926 .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources),
927 .resources = wm831x_dcdc2_resources,
930 .name = "wm831x-buckp",
932 .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources),
933 .resources = wm831x_dcdc3_resources,
936 .name = "wm831x-boostp",
938 .num_resources = ARRAY_SIZE(wm831x_dcdc4_resources),
939 .resources = wm831x_dcdc4_resources,
942 .name = "wm831x-epe",
946 .name = "wm831x-epe",
950 .name = "wm831x-gpio",
951 .num_resources = ARRAY_SIZE(wm831x_gpio_resources),
952 .resources = wm831x_gpio_resources,
955 .name = "wm831x-hwmon",
958 .name = "wm831x-isink",
960 .num_resources = ARRAY_SIZE(wm831x_isink1_resources),
961 .resources = wm831x_isink1_resources,
964 .name = "wm831x-isink",
966 .num_resources = ARRAY_SIZE(wm831x_isink2_resources),
967 .resources = wm831x_isink2_resources,
970 .name = "wm831x-ldo",
972 .num_resources = ARRAY_SIZE(wm831x_ldo1_resources),
973 .resources = wm831x_ldo1_resources,
976 .name = "wm831x-ldo",
978 .num_resources = ARRAY_SIZE(wm831x_ldo2_resources),
979 .resources = wm831x_ldo2_resources,
982 .name = "wm831x-ldo",
984 .num_resources = ARRAY_SIZE(wm831x_ldo3_resources),
985 .resources = wm831x_ldo3_resources,
988 .name = "wm831x-ldo",
990 .num_resources = ARRAY_SIZE(wm831x_ldo4_resources),
991 .resources = wm831x_ldo4_resources,
994 .name = "wm831x-ldo",
996 .num_resources = ARRAY_SIZE(wm831x_ldo5_resources),
997 .resources = wm831x_ldo5_resources,
1000 .name = "wm831x-ldo",
1002 .num_resources = ARRAY_SIZE(wm831x_ldo6_resources),
1003 .resources = wm831x_ldo6_resources,
1006 .name = "wm831x-aldo",
1008 .num_resources = ARRAY_SIZE(wm831x_ldo7_resources),
1009 .resources = wm831x_ldo7_resources,
1012 .name = "wm831x-aldo",
1014 .num_resources = ARRAY_SIZE(wm831x_ldo8_resources),
1015 .resources = wm831x_ldo8_resources,
1018 .name = "wm831x-aldo",
1020 .num_resources = ARRAY_SIZE(wm831x_ldo9_resources),
1021 .resources = wm831x_ldo9_resources,
1024 .name = "wm831x-aldo",
1026 .num_resources = ARRAY_SIZE(wm831x_ldo10_resources),
1027 .resources = wm831x_ldo10_resources,
1030 .name = "wm831x-alive-ldo",
1032 .num_resources = ARRAY_SIZE(wm831x_ldo11_resources),
1033 .resources = wm831x_ldo11_resources,
1036 .name = "wm831x-on",
1037 .num_resources = ARRAY_SIZE(wm831x_on_resources),
1038 .resources = wm831x_on_resources,
1041 .name = "wm831x-power",
1042 .num_resources = ARRAY_SIZE(wm831x_power_resources),
1043 .resources = wm831x_power_resources,
1046 .name = "wm831x-rtc",
1047 .num_resources = ARRAY_SIZE(wm831x_rtc_resources),
1048 .resources = wm831x_rtc_resources,
1051 .name = "wm831x-status",
1053 .num_resources = ARRAY_SIZE(wm831x_status1_resources),
1054 .resources = wm831x_status1_resources,
1057 .name = "wm831x-status",
1059 .num_resources = ARRAY_SIZE(wm831x_status2_resources),
1060 .resources = wm831x_status2_resources,
1063 .name = "wm831x-touch",
1064 .num_resources = ARRAY_SIZE(wm831x_touch_resources),
1065 .resources = wm831x_touch_resources,
1068 .name = "wm831x-watchdog",
1069 .num_resources = ARRAY_SIZE(wm831x_wdt_resources),
1070 .resources = wm831x_wdt_resources,
1075 * Instantiate the generic non-control parts of the device.
1077 static int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq)
1079 struct wm831x_pdata *pdata = wm831x->dev->platform_data;
1081 enum wm831x_parent parent;
1084 mutex_init(&wm831x->io_lock);
1085 mutex_init(&wm831x->key_lock);
1086 dev_set_drvdata(wm831x->dev, wm831x);
1088 ret = wm831x_reg_read(wm831x, WM831X_PARENT_ID);
1090 dev_err(wm831x->dev, "Failed to read parent ID: %d\n", ret);
1093 if (ret != 0x6204) {
1094 dev_err(wm831x->dev, "Device is not a WM831x: ID %x\n", ret);
1099 ret = wm831x_reg_read(wm831x, WM831X_REVISION);
1101 dev_err(wm831x->dev, "Failed to read revision: %d\n", ret);
1104 rev = (ret & WM831X_PARENT_REV_MASK) >> WM831X_PARENT_REV_SHIFT;
1106 ret = wm831x_reg_read(wm831x, WM831X_RESET_ID);
1108 dev_err(wm831x->dev, "Failed to read device ID: %d\n", ret);
1117 dev_info(wm831x->dev, "WM8310 revision %c\n",
1127 dev_info(wm831x->dev, "WM8311 revision %c\n",
1137 dev_info(wm831x->dev, "WM8312 revision %c\n",
1144 /* Some engineering samples do not have the ID set,
1145 * rely on the device being registered correctly.
1146 * This will need revisiting for future devices with
1152 dev_info(wm831x->dev, "WM831%d ES revision %c\n",
1159 dev_err(wm831x->dev, "Unknown WM831x device %04x\n", ret);
1164 /* This will need revisiting in future but is OK for all
1168 dev_warn(wm831x->dev, "Device was registered as a WM831%lu\n",
1171 /* Bootstrap the user key */
1172 ret = wm831x_reg_read(wm831x, WM831X_SECURITY_KEY);
1174 dev_err(wm831x->dev, "Failed to read security key: %d\n", ret);
1178 dev_warn(wm831x->dev, "Security key had non-zero value %x\n",
1180 wm831x_reg_write(wm831x, WM831X_SECURITY_KEY, 0);
1184 if (pdata && pdata->pre_init) {
1185 ret = pdata->pre_init(wm831x);
1187 dev_err(wm831x->dev, "pre_init() failed: %d\n", ret);
1192 /* The core device is up, instantiate the subdevices. */
1195 ret = mfd_add_devices(wm831x->dev, -1,
1196 wm8310_devs, ARRAY_SIZE(wm8310_devs),
1201 ret = mfd_add_devices(wm831x->dev, -1,
1202 wm8311_devs, ARRAY_SIZE(wm8311_devs),
1207 ret = mfd_add_devices(wm831x->dev, -1,
1208 wm8312_devs, ARRAY_SIZE(wm8312_devs),
1213 /* If this happens the bus probe function is buggy */
1218 dev_err(wm831x->dev, "Failed to add children\n");
1222 if (pdata && pdata->post_init) {
1223 ret = pdata->post_init(wm831x);
1225 dev_err(wm831x->dev, "post_init() failed: %d\n", ret);
1233 mfd_remove_devices(wm831x->dev);
1238 static void wm831x_device_exit(struct wm831x *wm831x)
1240 mfd_remove_devices(wm831x->dev);
1244 static int wm831x_i2c_read_device(struct wm831x *wm831x, unsigned short reg,
1245 int bytes, void *dest)
1247 struct i2c_client *i2c = wm831x->control_data;
1249 u16 r = cpu_to_be16(reg);
1251 ret = i2c_master_send(i2c, (unsigned char *)&r, 2);
1257 ret = i2c_master_recv(i2c, dest, bytes);
1265 /* Currently we allocate the write buffer on the stack; this is OK for
1266 * small writes - if we need to do large writes this will need to be
1269 static int wm831x_i2c_write_device(struct wm831x *wm831x, unsigned short reg,
1270 int bytes, void *src)
1272 struct i2c_client *i2c = wm831x->control_data;
1273 unsigned char msg[bytes + 2];
1276 reg = cpu_to_be16(reg);
1277 memcpy(&msg[0], ®, 2);
1278 memcpy(&msg[2], src, bytes);
1280 ret = i2c_master_send(i2c, msg, bytes + 2);
1283 if (ret < bytes + 2)
1289 static int wm831x_i2c_probe(struct i2c_client *i2c,
1290 const struct i2c_device_id *id)
1292 struct wm831x *wm831x;
1294 wm831x = kzalloc(sizeof(struct wm831x), GFP_KERNEL);
1295 if (wm831x == NULL) {
1300 i2c_set_clientdata(i2c, wm831x);
1301 wm831x->dev = &i2c->dev;
1302 wm831x->control_data = i2c;
1303 wm831x->read_dev = wm831x_i2c_read_device;
1304 wm831x->write_dev = wm831x_i2c_write_device;
1306 return wm831x_device_init(wm831x, id->driver_data, i2c->irq);
1309 static int wm831x_i2c_remove(struct i2c_client *i2c)
1311 struct wm831x *wm831x = i2c_get_clientdata(i2c);
1313 wm831x_device_exit(wm831x);
1318 static const struct i2c_device_id wm831x_i2c_id[] = {
1319 { "wm8310", WM8310 },
1320 { "wm8311", WM8311 },
1321 { "wm8312", WM8312 },
1324 MODULE_DEVICE_TABLE(i2c, wm831x_i2c_id);
1327 static struct i2c_driver wm831x_i2c_driver = {
1330 .owner = THIS_MODULE,
1332 .probe = wm831x_i2c_probe,
1333 .remove = wm831x_i2c_remove,
1334 .id_table = wm831x_i2c_id,
1337 static int __init wm831x_i2c_init(void)
1341 ret = i2c_add_driver(&wm831x_i2c_driver);
1343 pr_err("Failed to register wm831x I2C driver: %d\n", ret);
1347 subsys_initcall(wm831x_i2c_init);
1349 static void __exit wm831x_i2c_exit(void)
1351 i2c_del_driver(&wm831x_i2c_driver);
1353 module_exit(wm831x_i2c_exit);
1355 MODULE_DESCRIPTION("I2C support for the WM831X AudioPlus PMIC");
1356 MODULE_LICENSE("GPL");
1357 MODULE_AUTHOR("Mark Brown");