Merge tag 'v4.6-rockchip-clk2' of git://git.kernel.org/pub/scm/linux/kernel/git/mmind...
[linux/fpc-iii.git] / drivers / mfd / ab8500-debugfs.c
blob69d9fffe5b5cd43d3ebe084860e9a096c6d549fd
1 /*
2 * Copyright (C) ST-Ericsson SA 2010
4 * Author: Mattias Wallin <mattias.wallin@stericsson.com> for ST-Ericsson.
5 * License Terms: GNU General Public License v2
6 */
7 /*
8 * AB8500 register access
9 * ======================
11 * read:
12 * # echo BANK > <debugfs>/ab8500/register-bank
13 * # echo ADDR > <debugfs>/ab8500/register-address
14 * # cat <debugfs>/ab8500/register-value
16 * write:
17 * # echo BANK > <debugfs>/ab8500/register-bank
18 * # echo ADDR > <debugfs>/ab8500/register-address
19 * # echo VALUE > <debugfs>/ab8500/register-value
21 * read all registers from a bank:
22 * # echo BANK > <debugfs>/ab8500/register-bank
23 * # cat <debugfs>/ab8500/all-bank-register
25 * BANK target AB8500 register bank
26 * ADDR target AB8500 register address
27 * VALUE decimal or 0x-prefixed hexadecimal
30 * User Space notification on AB8500 IRQ
31 * =====================================
33 * Allows user space entity to be notified when target AB8500 IRQ occurs.
34 * When subscribed, a sysfs entry is created in ab8500.i2c platform device.
35 * One can pool this file to get target IRQ occurence information.
37 * subscribe to an AB8500 IRQ:
38 * # echo IRQ > <debugfs>/ab8500/irq-subscribe
40 * unsubscribe from an AB8500 IRQ:
41 * # echo IRQ > <debugfs>/ab8500/irq-unsubscribe
44 * AB8500 register formated read/write access
45 * ==========================================
47 * Read: read data, data>>SHIFT, data&=MASK, output data
48 * [0xABCDEF98] shift=12 mask=0xFFF => 0x00000CDE
49 * Write: read data, data &= ~(MASK<<SHIFT), data |= (VALUE<<SHIFT), write data
50 * [0xABCDEF98] shift=12 mask=0xFFF value=0x123 => [0xAB123F98]
52 * Usage:
53 * # echo "CMD [OPTIONS] BANK ADRESS [VALUE]" > $debugfs/ab8500/hwreg
55 * CMD read read access
56 * write write access
58 * BANK target reg bank
59 * ADDRESS target reg address
60 * VALUE (write) value to be updated
62 * OPTIONS
63 * -d|-dec (read) output in decimal
64 * -h|-hexa (read) output in 0x-hexa (default)
65 * -l|-w|-b 32bit (default), 16bit or 8bit reg access
66 * -m|-mask MASK 0x-hexa mask (default 0xFFFFFFFF)
67 * -s|-shift SHIFT bit shift value (read:left, write:right)
68 * -o|-offset OFFSET address offset to add to ADDRESS value
70 * Warning: bit shift operation is applied to bit-mask.
71 * Warning: bit shift direction depends on read or right command.
74 #include <linux/seq_file.h>
75 #include <linux/uaccess.h>
76 #include <linux/fs.h>
77 #include <linux/module.h>
78 #include <linux/debugfs.h>
79 #include <linux/platform_device.h>
80 #include <linux/interrupt.h>
81 #include <linux/kobject.h>
82 #include <linux/slab.h>
83 #include <linux/irq.h>
85 #include <linux/mfd/abx500.h>
86 #include <linux/mfd/abx500/ab8500.h>
87 #include <linux/mfd/abx500/ab8500-gpadc.h>
89 #ifdef CONFIG_DEBUG_FS
90 #include <linux/string.h>
91 #include <linux/ctype.h>
92 #endif
94 static u32 debug_bank;
95 static u32 debug_address;
97 static int irq_ab8500;
98 static int irq_first;
99 static int irq_last;
100 static u32 *irq_count;
101 static int num_irqs;
103 static struct device_attribute **dev_attr;
104 static char **event_name;
106 static u8 avg_sample = SAMPLE_16;
107 static u8 trig_edge = RISING_EDGE;
108 static u8 conv_type = ADC_SW;
109 static u8 trig_timer;
112 * struct ab8500_reg_range
113 * @first: the first address of the range
114 * @last: the last address of the range
115 * @perm: access permissions for the range
117 struct ab8500_reg_range {
118 u8 first;
119 u8 last;
120 u8 perm;
124 * struct ab8500_prcmu_ranges
125 * @num_ranges: the number of ranges in the list
126 * @bankid: bank identifier
127 * @range: the list of register ranges
129 struct ab8500_prcmu_ranges {
130 u8 num_ranges;
131 u8 bankid;
132 const struct ab8500_reg_range *range;
135 /* hwreg- "mask" and "shift" entries ressources */
136 struct hwreg_cfg {
137 u32 bank; /* target bank */
138 unsigned long addr; /* target address */
139 uint fmt; /* format */
140 unsigned long mask; /* read/write mask, applied before any bit shift */
141 long shift; /* bit shift (read:right shift, write:left shift */
143 /* fmt bit #0: 0=hexa, 1=dec */
144 #define REG_FMT_DEC(c) ((c)->fmt & 0x1)
145 #define REG_FMT_HEX(c) (!REG_FMT_DEC(c))
147 static struct hwreg_cfg hwreg_cfg = {
148 .addr = 0, /* default: invalid phys addr */
149 .fmt = 0, /* default: 32bit access, hex output */
150 .mask = 0xFFFFFFFF, /* default: no mask */
151 .shift = 0, /* default: no bit shift */
154 #define AB8500_NAME_STRING "ab8500"
155 #define AB8500_ADC_NAME_STRING "gpadc"
156 #define AB8500_NUM_BANKS 24
158 #define AB8500_REV_REG 0x80
160 static struct ab8500_prcmu_ranges *debug_ranges;
162 static struct ab8500_prcmu_ranges ab8500_debug_ranges[AB8500_NUM_BANKS] = {
163 [0x0] = {
164 .num_ranges = 0,
165 .range = NULL,
167 [AB8500_SYS_CTRL1_BLOCK] = {
168 .num_ranges = 3,
169 .range = (struct ab8500_reg_range[]) {
171 .first = 0x00,
172 .last = 0x02,
175 .first = 0x42,
176 .last = 0x42,
179 .first = 0x80,
180 .last = 0x81,
184 [AB8500_SYS_CTRL2_BLOCK] = {
185 .num_ranges = 4,
186 .range = (struct ab8500_reg_range[]) {
188 .first = 0x00,
189 .last = 0x0D,
192 .first = 0x0F,
193 .last = 0x17,
196 .first = 0x30,
197 .last = 0x30,
200 .first = 0x32,
201 .last = 0x33,
205 [AB8500_REGU_CTRL1] = {
206 .num_ranges = 3,
207 .range = (struct ab8500_reg_range[]) {
209 .first = 0x00,
210 .last = 0x00,
213 .first = 0x03,
214 .last = 0x10,
217 .first = 0x80,
218 .last = 0x84,
222 [AB8500_REGU_CTRL2] = {
223 .num_ranges = 5,
224 .range = (struct ab8500_reg_range[]) {
226 .first = 0x00,
227 .last = 0x15,
230 .first = 0x17,
231 .last = 0x19,
234 .first = 0x1B,
235 .last = 0x1D,
238 .first = 0x1F,
239 .last = 0x22,
242 .first = 0x40,
243 .last = 0x44,
246 * 0x80-0x8B are SIM registers and should
247 * not be accessed from here
251 [AB8500_USB] = {
252 .num_ranges = 2,
253 .range = (struct ab8500_reg_range[]) {
255 .first = 0x80,
256 .last = 0x83,
259 .first = 0x87,
260 .last = 0x8A,
264 [AB8500_TVOUT] = {
265 .num_ranges = 9,
266 .range = (struct ab8500_reg_range[]) {
268 .first = 0x00,
269 .last = 0x12,
272 .first = 0x15,
273 .last = 0x17,
276 .first = 0x19,
277 .last = 0x21,
280 .first = 0x27,
281 .last = 0x2C,
284 .first = 0x41,
285 .last = 0x41,
288 .first = 0x45,
289 .last = 0x5B,
292 .first = 0x5D,
293 .last = 0x5D,
296 .first = 0x69,
297 .last = 0x69,
300 .first = 0x80,
301 .last = 0x81,
305 [AB8500_DBI] = {
306 .num_ranges = 0,
307 .range = NULL,
309 [AB8500_ECI_AV_ACC] = {
310 .num_ranges = 1,
311 .range = (struct ab8500_reg_range[]) {
313 .first = 0x80,
314 .last = 0x82,
318 [0x9] = {
319 .num_ranges = 0,
320 .range = NULL,
322 [AB8500_GPADC] = {
323 .num_ranges = 1,
324 .range = (struct ab8500_reg_range[]) {
326 .first = 0x00,
327 .last = 0x08,
331 [AB8500_CHARGER] = {
332 .num_ranges = 9,
333 .range = (struct ab8500_reg_range[]) {
335 .first = 0x00,
336 .last = 0x03,
339 .first = 0x05,
340 .last = 0x05,
343 .first = 0x40,
344 .last = 0x40,
347 .first = 0x42,
348 .last = 0x42,
351 .first = 0x44,
352 .last = 0x44,
355 .first = 0x50,
356 .last = 0x55,
359 .first = 0x80,
360 .last = 0x82,
363 .first = 0xC0,
364 .last = 0xC2,
367 .first = 0xf5,
368 .last = 0xf6,
372 [AB8500_GAS_GAUGE] = {
373 .num_ranges = 3,
374 .range = (struct ab8500_reg_range[]) {
376 .first = 0x00,
377 .last = 0x00,
380 .first = 0x07,
381 .last = 0x0A,
384 .first = 0x10,
385 .last = 0x14,
389 [AB8500_DEVELOPMENT] = {
390 .num_ranges = 1,
391 .range = (struct ab8500_reg_range[]) {
393 .first = 0x00,
394 .last = 0x00,
398 [AB8500_DEBUG] = {
399 .num_ranges = 1,
400 .range = (struct ab8500_reg_range[]) {
402 .first = 0x05,
403 .last = 0x07,
407 [AB8500_AUDIO] = {
408 .num_ranges = 1,
409 .range = (struct ab8500_reg_range[]) {
411 .first = 0x00,
412 .last = 0x6F,
416 [AB8500_INTERRUPT] = {
417 .num_ranges = 0,
418 .range = NULL,
420 [AB8500_RTC] = {
421 .num_ranges = 1,
422 .range = (struct ab8500_reg_range[]) {
424 .first = 0x00,
425 .last = 0x0F,
429 [AB8500_MISC] = {
430 .num_ranges = 8,
431 .range = (struct ab8500_reg_range[]) {
433 .first = 0x00,
434 .last = 0x05,
437 .first = 0x10,
438 .last = 0x15,
441 .first = 0x20,
442 .last = 0x25,
445 .first = 0x30,
446 .last = 0x35,
449 .first = 0x40,
450 .last = 0x45,
453 .first = 0x50,
454 .last = 0x50,
457 .first = 0x60,
458 .last = 0x67,
461 .first = 0x80,
462 .last = 0x80,
466 [0x11] = {
467 .num_ranges = 0,
468 .range = NULL,
470 [0x12] = {
471 .num_ranges = 0,
472 .range = NULL,
474 [0x13] = {
475 .num_ranges = 0,
476 .range = NULL,
478 [0x14] = {
479 .num_ranges = 0,
480 .range = NULL,
482 [AB8500_OTP_EMUL] = {
483 .num_ranges = 1,
484 .range = (struct ab8500_reg_range[]) {
486 .first = 0x01,
487 .last = 0x0F,
493 static struct ab8500_prcmu_ranges ab8505_debug_ranges[AB8500_NUM_BANKS] = {
494 [0x0] = {
495 .num_ranges = 0,
496 .range = NULL,
498 [AB8500_SYS_CTRL1_BLOCK] = {
499 .num_ranges = 5,
500 .range = (struct ab8500_reg_range[]) {
502 .first = 0x00,
503 .last = 0x04,
506 .first = 0x42,
507 .last = 0x42,
510 .first = 0x52,
511 .last = 0x52,
514 .first = 0x54,
515 .last = 0x57,
518 .first = 0x80,
519 .last = 0x83,
523 [AB8500_SYS_CTRL2_BLOCK] = {
524 .num_ranges = 5,
525 .range = (struct ab8500_reg_range[]) {
527 .first = 0x00,
528 .last = 0x0D,
531 .first = 0x0F,
532 .last = 0x17,
535 .first = 0x20,
536 .last = 0x20,
539 .first = 0x30,
540 .last = 0x30,
543 .first = 0x32,
544 .last = 0x3A,
548 [AB8500_REGU_CTRL1] = {
549 .num_ranges = 3,
550 .range = (struct ab8500_reg_range[]) {
552 .first = 0x00,
553 .last = 0x00,
556 .first = 0x03,
557 .last = 0x11,
560 .first = 0x80,
561 .last = 0x86,
565 [AB8500_REGU_CTRL2] = {
566 .num_ranges = 6,
567 .range = (struct ab8500_reg_range[]) {
569 .first = 0x00,
570 .last = 0x06,
573 .first = 0x08,
574 .last = 0x15,
577 .first = 0x17,
578 .last = 0x19,
581 .first = 0x1B,
582 .last = 0x1D,
585 .first = 0x1F,
586 .last = 0x30,
589 .first = 0x40,
590 .last = 0x48,
593 * 0x80-0x8B are SIM registers and should
594 * not be accessed from here
598 [AB8500_USB] = {
599 .num_ranges = 3,
600 .range = (struct ab8500_reg_range[]) {
602 .first = 0x80,
603 .last = 0x83,
606 .first = 0x87,
607 .last = 0x8A,
610 .first = 0x91,
611 .last = 0x94,
615 [AB8500_TVOUT] = {
616 .num_ranges = 0,
617 .range = NULL,
619 [AB8500_DBI] = {
620 .num_ranges = 0,
621 .range = NULL,
623 [AB8500_ECI_AV_ACC] = {
624 .num_ranges = 1,
625 .range = (struct ab8500_reg_range[]) {
627 .first = 0x80,
628 .last = 0x82,
632 [AB8500_RESERVED] = {
633 .num_ranges = 0,
634 .range = NULL,
636 [AB8500_GPADC] = {
637 .num_ranges = 1,
638 .range = (struct ab8500_reg_range[]) {
640 .first = 0x00,
641 .last = 0x08,
645 [AB8500_CHARGER] = {
646 .num_ranges = 9,
647 .range = (struct ab8500_reg_range[]) {
649 .first = 0x02,
650 .last = 0x03,
653 .first = 0x05,
654 .last = 0x05,
657 .first = 0x40,
658 .last = 0x44,
661 .first = 0x50,
662 .last = 0x57,
665 .first = 0x60,
666 .last = 0x60,
669 .first = 0xA0,
670 .last = 0xA7,
673 .first = 0xAF,
674 .last = 0xB2,
677 .first = 0xC0,
678 .last = 0xC2,
681 .first = 0xF5,
682 .last = 0xF5,
686 [AB8500_GAS_GAUGE] = {
687 .num_ranges = 3,
688 .range = (struct ab8500_reg_range[]) {
690 .first = 0x00,
691 .last = 0x00,
694 .first = 0x07,
695 .last = 0x0A,
698 .first = 0x10,
699 .last = 0x14,
703 [AB8500_AUDIO] = {
704 .num_ranges = 1,
705 .range = (struct ab8500_reg_range[]) {
707 .first = 0x00,
708 .last = 0x83,
712 [AB8500_INTERRUPT] = {
713 .num_ranges = 11,
714 .range = (struct ab8500_reg_range[]) {
716 .first = 0x00,
717 .last = 0x04,
720 .first = 0x06,
721 .last = 0x07,
724 .first = 0x09,
725 .last = 0x09,
728 .first = 0x0B,
729 .last = 0x0C,
732 .first = 0x12,
733 .last = 0x15,
736 .first = 0x18,
737 .last = 0x18,
739 /* Latch registers should not be read here */
741 .first = 0x40,
742 .last = 0x44,
745 .first = 0x46,
746 .last = 0x49,
749 .first = 0x4B,
750 .last = 0x4D,
753 .first = 0x52,
754 .last = 0x55,
757 .first = 0x58,
758 .last = 0x58,
760 /* LatchHier registers should not be read here */
763 [AB8500_RTC] = {
764 .num_ranges = 2,
765 .range = (struct ab8500_reg_range[]) {
767 .first = 0x00,
768 .last = 0x14,
771 .first = 0x16,
772 .last = 0x17,
776 [AB8500_MISC] = {
777 .num_ranges = 8,
778 .range = (struct ab8500_reg_range[]) {
780 .first = 0x00,
781 .last = 0x06,
784 .first = 0x10,
785 .last = 0x16,
788 .first = 0x20,
789 .last = 0x26,
792 .first = 0x30,
793 .last = 0x36,
796 .first = 0x40,
797 .last = 0x46,
800 .first = 0x50,
801 .last = 0x50,
804 .first = 0x60,
805 .last = 0x6B,
808 .first = 0x80,
809 .last = 0x82,
813 [AB8500_DEVELOPMENT] = {
814 .num_ranges = 2,
815 .range = (struct ab8500_reg_range[]) {
817 .first = 0x00,
818 .last = 0x00,
821 .first = 0x05,
822 .last = 0x05,
826 [AB8500_DEBUG] = {
827 .num_ranges = 1,
828 .range = (struct ab8500_reg_range[]) {
830 .first = 0x05,
831 .last = 0x07,
835 [AB8500_PROD_TEST] = {
836 .num_ranges = 0,
837 .range = NULL,
839 [AB8500_STE_TEST] = {
840 .num_ranges = 0,
841 .range = NULL,
843 [AB8500_OTP_EMUL] = {
844 .num_ranges = 1,
845 .range = (struct ab8500_reg_range[]) {
847 .first = 0x01,
848 .last = 0x15,
854 static struct ab8500_prcmu_ranges ab8540_debug_ranges[AB8500_NUM_BANKS] = {
855 [AB8500_M_FSM_RANK] = {
856 .num_ranges = 1,
857 .range = (struct ab8500_reg_range[]) {
859 .first = 0x00,
860 .last = 0x0B,
864 [AB8500_SYS_CTRL1_BLOCK] = {
865 .num_ranges = 6,
866 .range = (struct ab8500_reg_range[]) {
868 .first = 0x00,
869 .last = 0x04,
872 .first = 0x42,
873 .last = 0x42,
876 .first = 0x50,
877 .last = 0x54,
880 .first = 0x57,
881 .last = 0x57,
884 .first = 0x80,
885 .last = 0x83,
888 .first = 0x90,
889 .last = 0x90,
893 [AB8500_SYS_CTRL2_BLOCK] = {
894 .num_ranges = 5,
895 .range = (struct ab8500_reg_range[]) {
897 .first = 0x00,
898 .last = 0x0D,
901 .first = 0x0F,
902 .last = 0x10,
905 .first = 0x20,
906 .last = 0x21,
909 .first = 0x32,
910 .last = 0x3C,
913 .first = 0x40,
914 .last = 0x42,
918 [AB8500_REGU_CTRL1] = {
919 .num_ranges = 4,
920 .range = (struct ab8500_reg_range[]) {
922 .first = 0x03,
923 .last = 0x15,
926 .first = 0x20,
927 .last = 0x20,
930 .first = 0x80,
931 .last = 0x85,
934 .first = 0x87,
935 .last = 0x88,
939 [AB8500_REGU_CTRL2] = {
940 .num_ranges = 8,
941 .range = (struct ab8500_reg_range[]) {
943 .first = 0x00,
944 .last = 0x06,
947 .first = 0x08,
948 .last = 0x15,
951 .first = 0x17,
952 .last = 0x19,
955 .first = 0x1B,
956 .last = 0x1D,
959 .first = 0x1F,
960 .last = 0x2F,
963 .first = 0x31,
964 .last = 0x3A,
967 .first = 0x43,
968 .last = 0x44,
971 .first = 0x48,
972 .last = 0x49,
976 [AB8500_USB] = {
977 .num_ranges = 3,
978 .range = (struct ab8500_reg_range[]) {
980 .first = 0x80,
981 .last = 0x83,
984 .first = 0x87,
985 .last = 0x8A,
988 .first = 0x91,
989 .last = 0x94,
993 [AB8500_TVOUT] = {
994 .num_ranges = 0,
995 .range = NULL
997 [AB8500_DBI] = {
998 .num_ranges = 4,
999 .range = (struct ab8500_reg_range[]) {
1001 .first = 0x00,
1002 .last = 0x07,
1005 .first = 0x10,
1006 .last = 0x11,
1009 .first = 0x20,
1010 .last = 0x21,
1013 .first = 0x30,
1014 .last = 0x43,
1018 [AB8500_ECI_AV_ACC] = {
1019 .num_ranges = 2,
1020 .range = (struct ab8500_reg_range[]) {
1022 .first = 0x00,
1023 .last = 0x03,
1026 .first = 0x80,
1027 .last = 0x82,
1031 [AB8500_RESERVED] = {
1032 .num_ranges = 0,
1033 .range = NULL,
1035 [AB8500_GPADC] = {
1036 .num_ranges = 4,
1037 .range = (struct ab8500_reg_range[]) {
1039 .first = 0x00,
1040 .last = 0x01,
1043 .first = 0x04,
1044 .last = 0x06,
1047 .first = 0x09,
1048 .last = 0x0A,
1051 .first = 0x10,
1052 .last = 0x14,
1056 [AB8500_CHARGER] = {
1057 .num_ranges = 10,
1058 .range = (struct ab8500_reg_range[]) {
1060 .first = 0x00,
1061 .last = 0x00,
1064 .first = 0x02,
1065 .last = 0x05,
1068 .first = 0x40,
1069 .last = 0x44,
1072 .first = 0x50,
1073 .last = 0x57,
1076 .first = 0x60,
1077 .last = 0x60,
1080 .first = 0x70,
1081 .last = 0x70,
1084 .first = 0xA0,
1085 .last = 0xA9,
1088 .first = 0xAF,
1089 .last = 0xB2,
1092 .first = 0xC0,
1093 .last = 0xC6,
1096 .first = 0xF5,
1097 .last = 0xF5,
1101 [AB8500_GAS_GAUGE] = {
1102 .num_ranges = 3,
1103 .range = (struct ab8500_reg_range[]) {
1105 .first = 0x00,
1106 .last = 0x00,
1109 .first = 0x07,
1110 .last = 0x0A,
1113 .first = 0x10,
1114 .last = 0x14,
1118 [AB8500_AUDIO] = {
1119 .num_ranges = 1,
1120 .range = (struct ab8500_reg_range[]) {
1122 .first = 0x00,
1123 .last = 0x9f,
1127 [AB8500_INTERRUPT] = {
1128 .num_ranges = 6,
1129 .range = (struct ab8500_reg_range[]) {
1131 .first = 0x00,
1132 .last = 0x05,
1135 .first = 0x0B,
1136 .last = 0x0D,
1139 .first = 0x12,
1140 .last = 0x20,
1142 /* Latch registers should not be read here */
1144 .first = 0x40,
1145 .last = 0x45,
1148 .first = 0x4B,
1149 .last = 0x4D,
1152 .first = 0x52,
1153 .last = 0x60,
1155 /* LatchHier registers should not be read here */
1158 [AB8500_RTC] = {
1159 .num_ranges = 3,
1160 .range = (struct ab8500_reg_range[]) {
1162 .first = 0x00,
1163 .last = 0x07,
1166 .first = 0x0B,
1167 .last = 0x18,
1170 .first = 0x20,
1171 .last = 0x25,
1175 [AB8500_MISC] = {
1176 .num_ranges = 9,
1177 .range = (struct ab8500_reg_range[]) {
1179 .first = 0x00,
1180 .last = 0x06,
1183 .first = 0x10,
1184 .last = 0x16,
1187 .first = 0x20,
1188 .last = 0x26,
1191 .first = 0x30,
1192 .last = 0x36,
1195 .first = 0x40,
1196 .last = 0x49,
1199 .first = 0x50,
1200 .last = 0x50,
1203 .first = 0x60,
1204 .last = 0x6B,
1207 .first = 0x70,
1208 .last = 0x74,
1211 .first = 0x80,
1212 .last = 0x82,
1216 [AB8500_DEVELOPMENT] = {
1217 .num_ranges = 3,
1218 .range = (struct ab8500_reg_range[]) {
1220 .first = 0x00,
1221 .last = 0x01,
1224 .first = 0x06,
1225 .last = 0x06,
1228 .first = 0x10,
1229 .last = 0x21,
1233 [AB8500_DEBUG] = {
1234 .num_ranges = 3,
1235 .range = (struct ab8500_reg_range[]) {
1237 .first = 0x01,
1238 .last = 0x0C,
1241 .first = 0x0E,
1242 .last = 0x11,
1245 .first = 0x80,
1246 .last = 0x81,
1250 [AB8500_PROD_TEST] = {
1251 .num_ranges = 0,
1252 .range = NULL,
1254 [AB8500_STE_TEST] = {
1255 .num_ranges = 0,
1256 .range = NULL,
1258 [AB8500_OTP_EMUL] = {
1259 .num_ranges = 1,
1260 .range = (struct ab8500_reg_range[]) {
1262 .first = 0x00,
1263 .last = 0x3F,
1270 static irqreturn_t ab8500_debug_handler(int irq, void *data)
1272 char buf[16];
1273 struct kobject *kobj = (struct kobject *)data;
1274 unsigned int irq_abb = irq - irq_first;
1276 if (irq_abb < num_irqs)
1277 irq_count[irq_abb]++;
1279 * This makes it possible to use poll for events (POLLPRI | POLLERR)
1280 * from userspace on sysfs file named <irq-nr>
1282 sprintf(buf, "%d", irq);
1283 sysfs_notify(kobj, NULL, buf);
1285 return IRQ_HANDLED;
1288 /* Prints to seq_file or log_buf */
1289 static int ab8500_registers_print(struct device *dev, u32 bank,
1290 struct seq_file *s)
1292 unsigned int i;
1294 for (i = 0; i < debug_ranges[bank].num_ranges; i++) {
1295 u32 reg;
1297 for (reg = debug_ranges[bank].range[i].first;
1298 reg <= debug_ranges[bank].range[i].last;
1299 reg++) {
1300 u8 value;
1301 int err;
1303 err = abx500_get_register_interruptible(dev,
1304 (u8)bank, (u8)reg, &value);
1305 if (err < 0) {
1306 dev_err(dev, "ab->read fail %d\n", err);
1307 return err;
1310 if (s) {
1311 seq_printf(s, " [0x%02X/0x%02X]: 0x%02X\n",
1312 bank, reg, value);
1314 * Error is not returned here since
1315 * the output is wanted in any case
1317 if (seq_has_overflowed(s))
1318 return 0;
1319 } else {
1320 dev_info(dev, " [0x%02X/0x%02X]: 0x%02X\n",
1321 bank, reg, value);
1326 return 0;
1329 static int ab8500_print_bank_registers(struct seq_file *s, void *p)
1331 struct device *dev = s->private;
1332 u32 bank = debug_bank;
1334 seq_puts(s, AB8500_NAME_STRING " register values:\n");
1336 seq_printf(s, " bank 0x%02X:\n", bank);
1338 return ab8500_registers_print(dev, bank, s);
1341 static int ab8500_registers_open(struct inode *inode, struct file *file)
1343 return single_open(file, ab8500_print_bank_registers, inode->i_private);
1346 static const struct file_operations ab8500_registers_fops = {
1347 .open = ab8500_registers_open,
1348 .read = seq_read,
1349 .llseek = seq_lseek,
1350 .release = single_release,
1351 .owner = THIS_MODULE,
1354 static int ab8500_print_all_banks(struct seq_file *s, void *p)
1356 struct device *dev = s->private;
1357 unsigned int i;
1359 seq_puts(s, AB8500_NAME_STRING " register values:\n");
1361 for (i = 0; i < AB8500_NUM_BANKS; i++) {
1362 int err;
1364 seq_printf(s, " bank 0x%02X:\n", i);
1365 err = ab8500_registers_print(dev, i, s);
1366 if (err)
1367 return err;
1369 return 0;
1372 /* Dump registers to kernel log */
1373 void ab8500_dump_all_banks(struct device *dev)
1375 unsigned int i;
1377 dev_info(dev, "ab8500 register values:\n");
1379 for (i = 1; i < AB8500_NUM_BANKS; i++) {
1380 dev_info(dev, " bank 0x%02X:\n", i);
1381 ab8500_registers_print(dev, i, NULL);
1385 /* Space for 500 registers. */
1386 #define DUMP_MAX_REGS 700
1387 static struct ab8500_register_dump
1389 u8 bank;
1390 u8 reg;
1391 u8 value;
1392 } ab8500_complete_register_dump[DUMP_MAX_REGS];
1394 /* This shall only be called upon kernel panic! */
1395 void ab8500_dump_all_banks_to_mem(void)
1397 int i, r = 0;
1398 u8 bank;
1399 int err = 0;
1401 pr_info("Saving all ABB registers for crash analysis.\n");
1403 for (bank = 0; bank < AB8500_NUM_BANKS; bank++) {
1404 for (i = 0; i < debug_ranges[bank].num_ranges; i++) {
1405 u8 reg;
1407 for (reg = debug_ranges[bank].range[i].first;
1408 reg <= debug_ranges[bank].range[i].last;
1409 reg++) {
1410 u8 value;
1412 err = prcmu_abb_read(bank, reg, &value, 1);
1414 if (err < 0)
1415 goto out;
1417 ab8500_complete_register_dump[r].bank = bank;
1418 ab8500_complete_register_dump[r].reg = reg;
1419 ab8500_complete_register_dump[r].value = value;
1421 r++;
1423 if (r >= DUMP_MAX_REGS) {
1424 pr_err("%s: too many register to dump!\n",
1425 __func__);
1426 err = -EINVAL;
1427 goto out;
1432 out:
1433 if (err >= 0)
1434 pr_info("Saved all ABB registers.\n");
1435 else
1436 pr_info("Failed to save all ABB registers.\n");
1439 static int ab8500_all_banks_open(struct inode *inode, struct file *file)
1441 struct seq_file *s;
1442 int err;
1444 err = single_open(file, ab8500_print_all_banks, inode->i_private);
1445 if (!err) {
1446 /* Default buf size in seq_read is not enough */
1447 s = (struct seq_file *)file->private_data;
1448 s->size = (PAGE_SIZE * 2);
1449 s->buf = kmalloc(s->size, GFP_KERNEL);
1450 if (!s->buf) {
1451 single_release(inode, file);
1452 err = -ENOMEM;
1455 return err;
1458 static const struct file_operations ab8500_all_banks_fops = {
1459 .open = ab8500_all_banks_open,
1460 .read = seq_read,
1461 .llseek = seq_lseek,
1462 .release = single_release,
1463 .owner = THIS_MODULE,
1466 static int ab8500_bank_print(struct seq_file *s, void *p)
1468 seq_printf(s, "0x%02X\n", debug_bank);
1469 return 0;
1472 static int ab8500_bank_open(struct inode *inode, struct file *file)
1474 return single_open(file, ab8500_bank_print, inode->i_private);
1477 static ssize_t ab8500_bank_write(struct file *file,
1478 const char __user *user_buf,
1479 size_t count, loff_t *ppos)
1481 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1482 unsigned long user_bank;
1483 int err;
1485 err = kstrtoul_from_user(user_buf, count, 0, &user_bank);
1486 if (err)
1487 return err;
1489 if (user_bank >= AB8500_NUM_BANKS) {
1490 dev_err(dev, "debugfs error input > number of banks\n");
1491 return -EINVAL;
1494 debug_bank = user_bank;
1496 return count;
1499 static int ab8500_address_print(struct seq_file *s, void *p)
1501 seq_printf(s, "0x%02X\n", debug_address);
1502 return 0;
1505 static int ab8500_address_open(struct inode *inode, struct file *file)
1507 return single_open(file, ab8500_address_print, inode->i_private);
1510 static ssize_t ab8500_address_write(struct file *file,
1511 const char __user *user_buf,
1512 size_t count, loff_t *ppos)
1514 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1515 unsigned long user_address;
1516 int err;
1518 err = kstrtoul_from_user(user_buf, count, 0, &user_address);
1519 if (err)
1520 return err;
1522 if (user_address > 0xff) {
1523 dev_err(dev, "debugfs error input > 0xff\n");
1524 return -EINVAL;
1526 debug_address = user_address;
1528 return count;
1531 static int ab8500_val_print(struct seq_file *s, void *p)
1533 struct device *dev = s->private;
1534 int ret;
1535 u8 regvalue;
1537 ret = abx500_get_register_interruptible(dev,
1538 (u8)debug_bank, (u8)debug_address, &regvalue);
1539 if (ret < 0) {
1540 dev_err(dev, "abx500_get_reg fail %d, %d\n",
1541 ret, __LINE__);
1542 return -EINVAL;
1544 seq_printf(s, "0x%02X\n", regvalue);
1546 return 0;
1549 static int ab8500_val_open(struct inode *inode, struct file *file)
1551 return single_open(file, ab8500_val_print, inode->i_private);
1554 static ssize_t ab8500_val_write(struct file *file,
1555 const char __user *user_buf,
1556 size_t count, loff_t *ppos)
1558 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1559 unsigned long user_val;
1560 int err;
1562 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
1563 if (err)
1564 return err;
1566 if (user_val > 0xff) {
1567 dev_err(dev, "debugfs error input > 0xff\n");
1568 return -EINVAL;
1570 err = abx500_set_register_interruptible(dev,
1571 (u8)debug_bank, debug_address, (u8)user_val);
1572 if (err < 0) {
1573 pr_err("abx500_set_reg failed %d, %d", err, __LINE__);
1574 return -EINVAL;
1577 return count;
1581 * Interrupt status
1583 static u32 num_interrupts[AB8500_MAX_NR_IRQS];
1584 static u32 num_wake_interrupts[AB8500_MAX_NR_IRQS];
1585 static int num_interrupt_lines;
1587 bool __attribute__((weak)) suspend_test_wake_cause_interrupt_is_mine(u32 my_int)
1589 return false;
1592 void ab8500_debug_register_interrupt(int line)
1594 if (line < num_interrupt_lines) {
1595 num_interrupts[line]++;
1596 if (suspend_test_wake_cause_interrupt_is_mine(irq_ab8500))
1597 num_wake_interrupts[line]++;
1601 static int ab8500_interrupts_print(struct seq_file *s, void *p)
1603 int line;
1605 seq_puts(s, "name: number: number of: wake:\n");
1607 for (line = 0; line < num_interrupt_lines; line++) {
1608 struct irq_desc *desc = irq_to_desc(line + irq_first);
1610 seq_printf(s, "%3i: %6i %4i",
1611 line,
1612 num_interrupts[line],
1613 num_wake_interrupts[line]);
1615 if (desc && desc->name)
1616 seq_printf(s, "-%-8s", desc->name);
1617 if (desc && desc->action) {
1618 struct irqaction *action = desc->action;
1620 seq_printf(s, " %s", action->name);
1621 while ((action = action->next) != NULL)
1622 seq_printf(s, ", %s", action->name);
1624 seq_putc(s, '\n');
1627 return 0;
1630 static int ab8500_interrupts_open(struct inode *inode, struct file *file)
1632 return single_open(file, ab8500_interrupts_print, inode->i_private);
1636 * - HWREG DB8500 formated routines
1638 static int ab8500_hwreg_print(struct seq_file *s, void *d)
1640 struct device *dev = s->private;
1641 int ret;
1642 u8 regvalue;
1644 ret = abx500_get_register_interruptible(dev,
1645 (u8)hwreg_cfg.bank, (u8)hwreg_cfg.addr, &regvalue);
1646 if (ret < 0) {
1647 dev_err(dev, "abx500_get_reg fail %d, %d\n",
1648 ret, __LINE__);
1649 return -EINVAL;
1652 if (hwreg_cfg.shift >= 0)
1653 regvalue >>= hwreg_cfg.shift;
1654 else
1655 regvalue <<= -hwreg_cfg.shift;
1656 regvalue &= hwreg_cfg.mask;
1658 if (REG_FMT_DEC(&hwreg_cfg))
1659 seq_printf(s, "%d\n", regvalue);
1660 else
1661 seq_printf(s, "0x%02X\n", regvalue);
1662 return 0;
1665 static int ab8500_hwreg_open(struct inode *inode, struct file *file)
1667 return single_open(file, ab8500_hwreg_print, inode->i_private);
1670 #define AB8500_SUPPLY_CONTROL_CONFIG_1 0x01
1671 #define AB8500_SUPPLY_CONTROL_REG 0x00
1672 #define AB8500_FIRST_SIM_REG 0x80
1673 #define AB8500_LAST_SIM_REG 0x8B
1674 #define AB8505_LAST_SIM_REG 0x8C
1676 static int ab8500_print_modem_registers(struct seq_file *s, void *p)
1678 struct device *dev = s->private;
1679 struct ab8500 *ab8500;
1680 int err;
1681 u8 value;
1682 u8 orig_value;
1683 u32 bank = AB8500_REGU_CTRL2;
1684 u32 last_sim_reg = AB8500_LAST_SIM_REG;
1685 u32 reg;
1687 ab8500 = dev_get_drvdata(dev->parent);
1688 dev_warn(dev, "WARNING! This operation can interfer with modem side\n"
1689 "and should only be done with care\n");
1691 err = abx500_get_register_interruptible(dev,
1692 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG, &orig_value);
1693 if (err < 0) {
1694 dev_err(dev, "ab->read fail %d\n", err);
1695 return err;
1697 /* Config 1 will allow APE side to read SIM registers */
1698 err = abx500_set_register_interruptible(dev,
1699 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG,
1700 AB8500_SUPPLY_CONTROL_CONFIG_1);
1701 if (err < 0) {
1702 dev_err(dev, "ab->write fail %d\n", err);
1703 return err;
1706 seq_printf(s, " bank 0x%02X:\n", bank);
1708 if (is_ab9540(ab8500) || is_ab8505(ab8500))
1709 last_sim_reg = AB8505_LAST_SIM_REG;
1711 for (reg = AB8500_FIRST_SIM_REG; reg <= last_sim_reg; reg++) {
1712 err = abx500_get_register_interruptible(dev,
1713 bank, reg, &value);
1714 if (err < 0) {
1715 dev_err(dev, "ab->read fail %d\n", err);
1716 return err;
1718 seq_printf(s, " [0x%02X/0x%02X]: 0x%02X\n", bank, reg, value);
1720 err = abx500_set_register_interruptible(dev,
1721 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG, orig_value);
1722 if (err < 0) {
1723 dev_err(dev, "ab->write fail %d\n", err);
1724 return err;
1726 return 0;
1729 static int ab8500_modem_open(struct inode *inode, struct file *file)
1731 return single_open(file, ab8500_print_modem_registers,
1732 inode->i_private);
1735 static const struct file_operations ab8500_modem_fops = {
1736 .open = ab8500_modem_open,
1737 .read = seq_read,
1738 .llseek = seq_lseek,
1739 .release = single_release,
1740 .owner = THIS_MODULE,
1743 static int ab8500_gpadc_bat_ctrl_print(struct seq_file *s, void *p)
1745 int bat_ctrl_raw;
1746 int bat_ctrl_convert;
1747 struct ab8500_gpadc *gpadc;
1749 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1750 bat_ctrl_raw = ab8500_gpadc_read_raw(gpadc, BAT_CTRL,
1751 avg_sample, trig_edge, trig_timer, conv_type);
1752 bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc,
1753 BAT_CTRL, bat_ctrl_raw);
1755 seq_printf(s, "%d,0x%X\n", bat_ctrl_convert, bat_ctrl_raw);
1757 return 0;
1760 static int ab8500_gpadc_bat_ctrl_open(struct inode *inode, struct file *file)
1762 return single_open(file, ab8500_gpadc_bat_ctrl_print,
1763 inode->i_private);
1766 static const struct file_operations ab8500_gpadc_bat_ctrl_fops = {
1767 .open = ab8500_gpadc_bat_ctrl_open,
1768 .read = seq_read,
1769 .llseek = seq_lseek,
1770 .release = single_release,
1771 .owner = THIS_MODULE,
1774 static int ab8500_gpadc_btemp_ball_print(struct seq_file *s, void *p)
1776 int btemp_ball_raw;
1777 int btemp_ball_convert;
1778 struct ab8500_gpadc *gpadc;
1780 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1781 btemp_ball_raw = ab8500_gpadc_read_raw(gpadc, BTEMP_BALL,
1782 avg_sample, trig_edge, trig_timer, conv_type);
1783 btemp_ball_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL,
1784 btemp_ball_raw);
1786 seq_printf(s, "%d,0x%X\n", btemp_ball_convert, btemp_ball_raw);
1788 return 0;
1791 static int ab8500_gpadc_btemp_ball_open(struct inode *inode,
1792 struct file *file)
1794 return single_open(file, ab8500_gpadc_btemp_ball_print,
1795 inode->i_private);
1798 static const struct file_operations ab8500_gpadc_btemp_ball_fops = {
1799 .open = ab8500_gpadc_btemp_ball_open,
1800 .read = seq_read,
1801 .llseek = seq_lseek,
1802 .release = single_release,
1803 .owner = THIS_MODULE,
1806 static int ab8500_gpadc_main_charger_v_print(struct seq_file *s, void *p)
1808 int main_charger_v_raw;
1809 int main_charger_v_convert;
1810 struct ab8500_gpadc *gpadc;
1812 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1813 main_charger_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_V,
1814 avg_sample, trig_edge, trig_timer, conv_type);
1815 main_charger_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
1816 MAIN_CHARGER_V, main_charger_v_raw);
1818 seq_printf(s, "%d,0x%X\n", main_charger_v_convert, main_charger_v_raw);
1820 return 0;
1823 static int ab8500_gpadc_main_charger_v_open(struct inode *inode,
1824 struct file *file)
1826 return single_open(file, ab8500_gpadc_main_charger_v_print,
1827 inode->i_private);
1830 static const struct file_operations ab8500_gpadc_main_charger_v_fops = {
1831 .open = ab8500_gpadc_main_charger_v_open,
1832 .read = seq_read,
1833 .llseek = seq_lseek,
1834 .release = single_release,
1835 .owner = THIS_MODULE,
1838 static int ab8500_gpadc_acc_detect1_print(struct seq_file *s, void *p)
1840 int acc_detect1_raw;
1841 int acc_detect1_convert;
1842 struct ab8500_gpadc *gpadc;
1844 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1845 acc_detect1_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT1,
1846 avg_sample, trig_edge, trig_timer, conv_type);
1847 acc_detect1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ACC_DETECT1,
1848 acc_detect1_raw);
1850 seq_printf(s, "%d,0x%X\n", acc_detect1_convert, acc_detect1_raw);
1852 return 0;
1855 static int ab8500_gpadc_acc_detect1_open(struct inode *inode,
1856 struct file *file)
1858 return single_open(file, ab8500_gpadc_acc_detect1_print,
1859 inode->i_private);
1862 static const struct file_operations ab8500_gpadc_acc_detect1_fops = {
1863 .open = ab8500_gpadc_acc_detect1_open,
1864 .read = seq_read,
1865 .llseek = seq_lseek,
1866 .release = single_release,
1867 .owner = THIS_MODULE,
1870 static int ab8500_gpadc_acc_detect2_print(struct seq_file *s, void *p)
1872 int acc_detect2_raw;
1873 int acc_detect2_convert;
1874 struct ab8500_gpadc *gpadc;
1876 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1877 acc_detect2_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT2,
1878 avg_sample, trig_edge, trig_timer, conv_type);
1879 acc_detect2_convert = ab8500_gpadc_ad_to_voltage(gpadc,
1880 ACC_DETECT2, acc_detect2_raw);
1882 seq_printf(s, "%d,0x%X\n", acc_detect2_convert, acc_detect2_raw);
1884 return 0;
1887 static int ab8500_gpadc_acc_detect2_open(struct inode *inode,
1888 struct file *file)
1890 return single_open(file, ab8500_gpadc_acc_detect2_print,
1891 inode->i_private);
1894 static const struct file_operations ab8500_gpadc_acc_detect2_fops = {
1895 .open = ab8500_gpadc_acc_detect2_open,
1896 .read = seq_read,
1897 .llseek = seq_lseek,
1898 .release = single_release,
1899 .owner = THIS_MODULE,
1902 static int ab8500_gpadc_aux1_print(struct seq_file *s, void *p)
1904 int aux1_raw;
1905 int aux1_convert;
1906 struct ab8500_gpadc *gpadc;
1908 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1909 aux1_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX1,
1910 avg_sample, trig_edge, trig_timer, conv_type);
1911 aux1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX1,
1912 aux1_raw);
1914 seq_printf(s, "%d,0x%X\n", aux1_convert, aux1_raw);
1916 return 0;
1919 static int ab8500_gpadc_aux1_open(struct inode *inode, struct file *file)
1921 return single_open(file, ab8500_gpadc_aux1_print, inode->i_private);
1924 static const struct file_operations ab8500_gpadc_aux1_fops = {
1925 .open = ab8500_gpadc_aux1_open,
1926 .read = seq_read,
1927 .llseek = seq_lseek,
1928 .release = single_release,
1929 .owner = THIS_MODULE,
1932 static int ab8500_gpadc_aux2_print(struct seq_file *s, void *p)
1934 int aux2_raw;
1935 int aux2_convert;
1936 struct ab8500_gpadc *gpadc;
1938 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1939 aux2_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX2,
1940 avg_sample, trig_edge, trig_timer, conv_type);
1941 aux2_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX2,
1942 aux2_raw);
1944 seq_printf(s, "%d,0x%X\n", aux2_convert, aux2_raw);
1946 return 0;
1949 static int ab8500_gpadc_aux2_open(struct inode *inode, struct file *file)
1951 return single_open(file, ab8500_gpadc_aux2_print, inode->i_private);
1954 static const struct file_operations ab8500_gpadc_aux2_fops = {
1955 .open = ab8500_gpadc_aux2_open,
1956 .read = seq_read,
1957 .llseek = seq_lseek,
1958 .release = single_release,
1959 .owner = THIS_MODULE,
1962 static int ab8500_gpadc_main_bat_v_print(struct seq_file *s, void *p)
1964 int main_bat_v_raw;
1965 int main_bat_v_convert;
1966 struct ab8500_gpadc *gpadc;
1968 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1969 main_bat_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_BAT_V,
1970 avg_sample, trig_edge, trig_timer, conv_type);
1971 main_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V,
1972 main_bat_v_raw);
1974 seq_printf(s, "%d,0x%X\n", main_bat_v_convert, main_bat_v_raw);
1976 return 0;
1979 static int ab8500_gpadc_main_bat_v_open(struct inode *inode,
1980 struct file *file)
1982 return single_open(file, ab8500_gpadc_main_bat_v_print,
1983 inode->i_private);
1986 static const struct file_operations ab8500_gpadc_main_bat_v_fops = {
1987 .open = ab8500_gpadc_main_bat_v_open,
1988 .read = seq_read,
1989 .llseek = seq_lseek,
1990 .release = single_release,
1991 .owner = THIS_MODULE,
1994 static int ab8500_gpadc_vbus_v_print(struct seq_file *s, void *p)
1996 int vbus_v_raw;
1997 int vbus_v_convert;
1998 struct ab8500_gpadc *gpadc;
2000 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2001 vbus_v_raw = ab8500_gpadc_read_raw(gpadc, VBUS_V,
2002 avg_sample, trig_edge, trig_timer, conv_type);
2003 vbus_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, VBUS_V,
2004 vbus_v_raw);
2006 seq_printf(s, "%d,0x%X\n", vbus_v_convert, vbus_v_raw);
2008 return 0;
2011 static int ab8500_gpadc_vbus_v_open(struct inode *inode, struct file *file)
2013 return single_open(file, ab8500_gpadc_vbus_v_print, inode->i_private);
2016 static const struct file_operations ab8500_gpadc_vbus_v_fops = {
2017 .open = ab8500_gpadc_vbus_v_open,
2018 .read = seq_read,
2019 .llseek = seq_lseek,
2020 .release = single_release,
2021 .owner = THIS_MODULE,
2024 static int ab8500_gpadc_main_charger_c_print(struct seq_file *s, void *p)
2026 int main_charger_c_raw;
2027 int main_charger_c_convert;
2028 struct ab8500_gpadc *gpadc;
2030 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2031 main_charger_c_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_C,
2032 avg_sample, trig_edge, trig_timer, conv_type);
2033 main_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
2034 MAIN_CHARGER_C, main_charger_c_raw);
2036 seq_printf(s, "%d,0x%X\n", main_charger_c_convert, main_charger_c_raw);
2038 return 0;
2041 static int ab8500_gpadc_main_charger_c_open(struct inode *inode,
2042 struct file *file)
2044 return single_open(file, ab8500_gpadc_main_charger_c_print,
2045 inode->i_private);
2048 static const struct file_operations ab8500_gpadc_main_charger_c_fops = {
2049 .open = ab8500_gpadc_main_charger_c_open,
2050 .read = seq_read,
2051 .llseek = seq_lseek,
2052 .release = single_release,
2053 .owner = THIS_MODULE,
2056 static int ab8500_gpadc_usb_charger_c_print(struct seq_file *s, void *p)
2058 int usb_charger_c_raw;
2059 int usb_charger_c_convert;
2060 struct ab8500_gpadc *gpadc;
2062 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2063 usb_charger_c_raw = ab8500_gpadc_read_raw(gpadc, USB_CHARGER_C,
2064 avg_sample, trig_edge, trig_timer, conv_type);
2065 usb_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
2066 USB_CHARGER_C, usb_charger_c_raw);
2068 seq_printf(s, "%d,0x%X\n", usb_charger_c_convert, usb_charger_c_raw);
2070 return 0;
2073 static int ab8500_gpadc_usb_charger_c_open(struct inode *inode,
2074 struct file *file)
2076 return single_open(file, ab8500_gpadc_usb_charger_c_print,
2077 inode->i_private);
2080 static const struct file_operations ab8500_gpadc_usb_charger_c_fops = {
2081 .open = ab8500_gpadc_usb_charger_c_open,
2082 .read = seq_read,
2083 .llseek = seq_lseek,
2084 .release = single_release,
2085 .owner = THIS_MODULE,
2088 static int ab8500_gpadc_bk_bat_v_print(struct seq_file *s, void *p)
2090 int bk_bat_v_raw;
2091 int bk_bat_v_convert;
2092 struct ab8500_gpadc *gpadc;
2094 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2095 bk_bat_v_raw = ab8500_gpadc_read_raw(gpadc, BK_BAT_V,
2096 avg_sample, trig_edge, trig_timer, conv_type);
2097 bk_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
2098 BK_BAT_V, bk_bat_v_raw);
2100 seq_printf(s, "%d,0x%X\n", bk_bat_v_convert, bk_bat_v_raw);
2102 return 0;
2105 static int ab8500_gpadc_bk_bat_v_open(struct inode *inode, struct file *file)
2107 return single_open(file, ab8500_gpadc_bk_bat_v_print,
2108 inode->i_private);
2111 static const struct file_operations ab8500_gpadc_bk_bat_v_fops = {
2112 .open = ab8500_gpadc_bk_bat_v_open,
2113 .read = seq_read,
2114 .llseek = seq_lseek,
2115 .release = single_release,
2116 .owner = THIS_MODULE,
2119 static int ab8500_gpadc_die_temp_print(struct seq_file *s, void *p)
2121 int die_temp_raw;
2122 int die_temp_convert;
2123 struct ab8500_gpadc *gpadc;
2125 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2126 die_temp_raw = ab8500_gpadc_read_raw(gpadc, DIE_TEMP,
2127 avg_sample, trig_edge, trig_timer, conv_type);
2128 die_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, DIE_TEMP,
2129 die_temp_raw);
2131 seq_printf(s, "%d,0x%X\n", die_temp_convert, die_temp_raw);
2133 return 0;
2136 static int ab8500_gpadc_die_temp_open(struct inode *inode, struct file *file)
2138 return single_open(file, ab8500_gpadc_die_temp_print,
2139 inode->i_private);
2142 static const struct file_operations ab8500_gpadc_die_temp_fops = {
2143 .open = ab8500_gpadc_die_temp_open,
2144 .read = seq_read,
2145 .llseek = seq_lseek,
2146 .release = single_release,
2147 .owner = THIS_MODULE,
2150 static int ab8500_gpadc_usb_id_print(struct seq_file *s, void *p)
2152 int usb_id_raw;
2153 int usb_id_convert;
2154 struct ab8500_gpadc *gpadc;
2156 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2157 usb_id_raw = ab8500_gpadc_read_raw(gpadc, USB_ID,
2158 avg_sample, trig_edge, trig_timer, conv_type);
2159 usb_id_convert = ab8500_gpadc_ad_to_voltage(gpadc, USB_ID,
2160 usb_id_raw);
2162 seq_printf(s, "%d,0x%X\n", usb_id_convert, usb_id_raw);
2164 return 0;
2167 static int ab8500_gpadc_usb_id_open(struct inode *inode, struct file *file)
2169 return single_open(file, ab8500_gpadc_usb_id_print, inode->i_private);
2172 static const struct file_operations ab8500_gpadc_usb_id_fops = {
2173 .open = ab8500_gpadc_usb_id_open,
2174 .read = seq_read,
2175 .llseek = seq_lseek,
2176 .release = single_release,
2177 .owner = THIS_MODULE,
2180 static int ab8540_gpadc_xtal_temp_print(struct seq_file *s, void *p)
2182 int xtal_temp_raw;
2183 int xtal_temp_convert;
2184 struct ab8500_gpadc *gpadc;
2186 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2187 xtal_temp_raw = ab8500_gpadc_read_raw(gpadc, XTAL_TEMP,
2188 avg_sample, trig_edge, trig_timer, conv_type);
2189 xtal_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, XTAL_TEMP,
2190 xtal_temp_raw);
2192 seq_printf(s, "%d,0x%X\n", xtal_temp_convert, xtal_temp_raw);
2194 return 0;
2197 static int ab8540_gpadc_xtal_temp_open(struct inode *inode, struct file *file)
2199 return single_open(file, ab8540_gpadc_xtal_temp_print,
2200 inode->i_private);
2203 static const struct file_operations ab8540_gpadc_xtal_temp_fops = {
2204 .open = ab8540_gpadc_xtal_temp_open,
2205 .read = seq_read,
2206 .llseek = seq_lseek,
2207 .release = single_release,
2208 .owner = THIS_MODULE,
2211 static int ab8540_gpadc_vbat_true_meas_print(struct seq_file *s, void *p)
2213 int vbat_true_meas_raw;
2214 int vbat_true_meas_convert;
2215 struct ab8500_gpadc *gpadc;
2217 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2218 vbat_true_meas_raw = ab8500_gpadc_read_raw(gpadc, VBAT_TRUE_MEAS,
2219 avg_sample, trig_edge, trig_timer, conv_type);
2220 vbat_true_meas_convert =
2221 ab8500_gpadc_ad_to_voltage(gpadc, VBAT_TRUE_MEAS,
2222 vbat_true_meas_raw);
2224 seq_printf(s, "%d,0x%X\n", vbat_true_meas_convert, vbat_true_meas_raw);
2226 return 0;
2229 static int ab8540_gpadc_vbat_true_meas_open(struct inode *inode,
2230 struct file *file)
2232 return single_open(file, ab8540_gpadc_vbat_true_meas_print,
2233 inode->i_private);
2236 static const struct file_operations ab8540_gpadc_vbat_true_meas_fops = {
2237 .open = ab8540_gpadc_vbat_true_meas_open,
2238 .read = seq_read,
2239 .llseek = seq_lseek,
2240 .release = single_release,
2241 .owner = THIS_MODULE,
2244 static int ab8540_gpadc_bat_ctrl_and_ibat_print(struct seq_file *s, void *p)
2246 int bat_ctrl_raw;
2247 int bat_ctrl_convert;
2248 int ibat_raw;
2249 int ibat_convert;
2250 struct ab8500_gpadc *gpadc;
2252 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2253 bat_ctrl_raw = ab8500_gpadc_double_read_raw(gpadc, BAT_CTRL_AND_IBAT,
2254 avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
2256 bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc, BAT_CTRL,
2257 bat_ctrl_raw);
2258 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2259 ibat_raw);
2261 seq_printf(s,
2262 "%d,0x%X\n"
2263 "%d,0x%X\n",
2264 bat_ctrl_convert, bat_ctrl_raw,
2265 ibat_convert, ibat_raw);
2267 return 0;
2270 static int ab8540_gpadc_bat_ctrl_and_ibat_open(struct inode *inode,
2271 struct file *file)
2273 return single_open(file, ab8540_gpadc_bat_ctrl_and_ibat_print,
2274 inode->i_private);
2277 static const struct file_operations ab8540_gpadc_bat_ctrl_and_ibat_fops = {
2278 .open = ab8540_gpadc_bat_ctrl_and_ibat_open,
2279 .read = seq_read,
2280 .llseek = seq_lseek,
2281 .release = single_release,
2282 .owner = THIS_MODULE,
2285 static int ab8540_gpadc_vbat_meas_and_ibat_print(struct seq_file *s, void *p)
2287 int vbat_meas_raw;
2288 int vbat_meas_convert;
2289 int ibat_raw;
2290 int ibat_convert;
2291 struct ab8500_gpadc *gpadc;
2293 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2294 vbat_meas_raw = ab8500_gpadc_double_read_raw(gpadc, VBAT_MEAS_AND_IBAT,
2295 avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
2296 vbat_meas_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V,
2297 vbat_meas_raw);
2298 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2299 ibat_raw);
2301 seq_printf(s,
2302 "%d,0x%X\n"
2303 "%d,0x%X\n",
2304 vbat_meas_convert, vbat_meas_raw,
2305 ibat_convert, ibat_raw);
2307 return 0;
2310 static int ab8540_gpadc_vbat_meas_and_ibat_open(struct inode *inode,
2311 struct file *file)
2313 return single_open(file, ab8540_gpadc_vbat_meas_and_ibat_print,
2314 inode->i_private);
2317 static const struct file_operations ab8540_gpadc_vbat_meas_and_ibat_fops = {
2318 .open = ab8540_gpadc_vbat_meas_and_ibat_open,
2319 .read = seq_read,
2320 .llseek = seq_lseek,
2321 .release = single_release,
2322 .owner = THIS_MODULE,
2325 static int ab8540_gpadc_vbat_true_meas_and_ibat_print(struct seq_file *s,
2326 void *p)
2328 int vbat_true_meas_raw;
2329 int vbat_true_meas_convert;
2330 int ibat_raw;
2331 int ibat_convert;
2332 struct ab8500_gpadc *gpadc;
2334 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2335 vbat_true_meas_raw = ab8500_gpadc_double_read_raw(gpadc,
2336 VBAT_TRUE_MEAS_AND_IBAT, avg_sample, trig_edge,
2337 trig_timer, conv_type, &ibat_raw);
2338 vbat_true_meas_convert = ab8500_gpadc_ad_to_voltage(gpadc,
2339 VBAT_TRUE_MEAS, vbat_true_meas_raw);
2340 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2341 ibat_raw);
2343 seq_printf(s,
2344 "%d,0x%X\n"
2345 "%d,0x%X\n",
2346 vbat_true_meas_convert, vbat_true_meas_raw,
2347 ibat_convert, ibat_raw);
2349 return 0;
2352 static int ab8540_gpadc_vbat_true_meas_and_ibat_open(struct inode *inode,
2353 struct file *file)
2355 return single_open(file, ab8540_gpadc_vbat_true_meas_and_ibat_print,
2356 inode->i_private);
2359 static const struct file_operations
2360 ab8540_gpadc_vbat_true_meas_and_ibat_fops = {
2361 .open = ab8540_gpadc_vbat_true_meas_and_ibat_open,
2362 .read = seq_read,
2363 .llseek = seq_lseek,
2364 .release = single_release,
2365 .owner = THIS_MODULE,
2368 static int ab8540_gpadc_bat_temp_and_ibat_print(struct seq_file *s, void *p)
2370 int bat_temp_raw;
2371 int bat_temp_convert;
2372 int ibat_raw;
2373 int ibat_convert;
2374 struct ab8500_gpadc *gpadc;
2376 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2377 bat_temp_raw = ab8500_gpadc_double_read_raw(gpadc, BAT_TEMP_AND_IBAT,
2378 avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
2379 bat_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL,
2380 bat_temp_raw);
2381 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2382 ibat_raw);
2384 seq_printf(s,
2385 "%d,0x%X\n"
2386 "%d,0x%X\n",
2387 bat_temp_convert, bat_temp_raw,
2388 ibat_convert, ibat_raw);
2390 return 0;
2393 static int ab8540_gpadc_bat_temp_and_ibat_open(struct inode *inode,
2394 struct file *file)
2396 return single_open(file, ab8540_gpadc_bat_temp_and_ibat_print,
2397 inode->i_private);
2400 static const struct file_operations ab8540_gpadc_bat_temp_and_ibat_fops = {
2401 .open = ab8540_gpadc_bat_temp_and_ibat_open,
2402 .read = seq_read,
2403 .llseek = seq_lseek,
2404 .release = single_release,
2405 .owner = THIS_MODULE,
2408 static int ab8540_gpadc_otp_cal_print(struct seq_file *s, void *p)
2410 struct ab8500_gpadc *gpadc;
2411 u16 vmain_l, vmain_h, btemp_l, btemp_h;
2412 u16 vbat_l, vbat_h, ibat_l, ibat_h;
2414 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2415 ab8540_gpadc_get_otp(gpadc, &vmain_l, &vmain_h, &btemp_l, &btemp_h,
2416 &vbat_l, &vbat_h, &ibat_l, &ibat_h);
2417 seq_printf(s,
2418 "VMAIN_L:0x%X\n"
2419 "VMAIN_H:0x%X\n"
2420 "BTEMP_L:0x%X\n"
2421 "BTEMP_H:0x%X\n"
2422 "VBAT_L:0x%X\n"
2423 "VBAT_H:0x%X\n"
2424 "IBAT_L:0x%X\n"
2425 "IBAT_H:0x%X\n",
2426 vmain_l, vmain_h, btemp_l, btemp_h,
2427 vbat_l, vbat_h, ibat_l, ibat_h);
2429 return 0;
2432 static int ab8540_gpadc_otp_cal_open(struct inode *inode, struct file *file)
2434 return single_open(file, ab8540_gpadc_otp_cal_print, inode->i_private);
2437 static const struct file_operations ab8540_gpadc_otp_calib_fops = {
2438 .open = ab8540_gpadc_otp_cal_open,
2439 .read = seq_read,
2440 .llseek = seq_lseek,
2441 .release = single_release,
2442 .owner = THIS_MODULE,
2445 static int ab8500_gpadc_avg_sample_print(struct seq_file *s, void *p)
2447 seq_printf(s, "%d\n", avg_sample);
2449 return 0;
2452 static int ab8500_gpadc_avg_sample_open(struct inode *inode, struct file *file)
2454 return single_open(file, ab8500_gpadc_avg_sample_print,
2455 inode->i_private);
2458 static ssize_t ab8500_gpadc_avg_sample_write(struct file *file,
2459 const char __user *user_buf,
2460 size_t count, loff_t *ppos)
2462 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2463 unsigned long user_avg_sample;
2464 int err;
2466 err = kstrtoul_from_user(user_buf, count, 0, &user_avg_sample);
2467 if (err)
2468 return err;
2470 if ((user_avg_sample == SAMPLE_1) || (user_avg_sample == SAMPLE_4)
2471 || (user_avg_sample == SAMPLE_8)
2472 || (user_avg_sample == SAMPLE_16)) {
2473 avg_sample = (u8) user_avg_sample;
2474 } else {
2475 dev_err(dev,
2476 "debugfs err input: should be egal to 1, 4, 8 or 16\n");
2477 return -EINVAL;
2480 return count;
2483 static const struct file_operations ab8500_gpadc_avg_sample_fops = {
2484 .open = ab8500_gpadc_avg_sample_open,
2485 .read = seq_read,
2486 .write = ab8500_gpadc_avg_sample_write,
2487 .llseek = seq_lseek,
2488 .release = single_release,
2489 .owner = THIS_MODULE,
2492 static int ab8500_gpadc_trig_edge_print(struct seq_file *s, void *p)
2494 seq_printf(s, "%d\n", trig_edge);
2496 return 0;
2499 static int ab8500_gpadc_trig_edge_open(struct inode *inode, struct file *file)
2501 return single_open(file, ab8500_gpadc_trig_edge_print,
2502 inode->i_private);
2505 static ssize_t ab8500_gpadc_trig_edge_write(struct file *file,
2506 const char __user *user_buf,
2507 size_t count, loff_t *ppos)
2509 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2510 unsigned long user_trig_edge;
2511 int err;
2513 err = kstrtoul_from_user(user_buf, count, 0, &user_trig_edge);
2514 if (err)
2515 return err;
2517 if ((user_trig_edge == RISING_EDGE)
2518 || (user_trig_edge == FALLING_EDGE)) {
2519 trig_edge = (u8) user_trig_edge;
2520 } else {
2521 dev_err(dev, "Wrong input:\n"
2522 "Enter 0. Rising edge\n"
2523 "Enter 1. Falling edge\n");
2524 return -EINVAL;
2527 return count;
2530 static const struct file_operations ab8500_gpadc_trig_edge_fops = {
2531 .open = ab8500_gpadc_trig_edge_open,
2532 .read = seq_read,
2533 .write = ab8500_gpadc_trig_edge_write,
2534 .llseek = seq_lseek,
2535 .release = single_release,
2536 .owner = THIS_MODULE,
2539 static int ab8500_gpadc_trig_timer_print(struct seq_file *s, void *p)
2541 seq_printf(s, "%d\n", trig_timer);
2543 return 0;
2546 static int ab8500_gpadc_trig_timer_open(struct inode *inode, struct file *file)
2548 return single_open(file, ab8500_gpadc_trig_timer_print,
2549 inode->i_private);
2552 static ssize_t ab8500_gpadc_trig_timer_write(struct file *file,
2553 const char __user *user_buf,
2554 size_t count, loff_t *ppos)
2556 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2557 unsigned long user_trig_timer;
2558 int err;
2560 err = kstrtoul_from_user(user_buf, count, 0, &user_trig_timer);
2561 if (err)
2562 return err;
2564 if (user_trig_timer & ~0xFF) {
2565 dev_err(dev,
2566 "debugfs error input: should be beetween 0 to 255\n");
2567 return -EINVAL;
2570 trig_timer = (u8) user_trig_timer;
2572 return count;
2575 static const struct file_operations ab8500_gpadc_trig_timer_fops = {
2576 .open = ab8500_gpadc_trig_timer_open,
2577 .read = seq_read,
2578 .write = ab8500_gpadc_trig_timer_write,
2579 .llseek = seq_lseek,
2580 .release = single_release,
2581 .owner = THIS_MODULE,
2584 static int ab8500_gpadc_conv_type_print(struct seq_file *s, void *p)
2586 seq_printf(s, "%d\n", conv_type);
2588 return 0;
2591 static int ab8500_gpadc_conv_type_open(struct inode *inode, struct file *file)
2593 return single_open(file, ab8500_gpadc_conv_type_print,
2594 inode->i_private);
2597 static ssize_t ab8500_gpadc_conv_type_write(struct file *file,
2598 const char __user *user_buf,
2599 size_t count, loff_t *ppos)
2601 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2602 unsigned long user_conv_type;
2603 int err;
2605 err = kstrtoul_from_user(user_buf, count, 0, &user_conv_type);
2606 if (err)
2607 return err;
2609 if ((user_conv_type == ADC_SW)
2610 || (user_conv_type == ADC_HW)) {
2611 conv_type = (u8) user_conv_type;
2612 } else {
2613 dev_err(dev, "Wrong input:\n"
2614 "Enter 0. ADC SW conversion\n"
2615 "Enter 1. ADC HW conversion\n");
2616 return -EINVAL;
2619 return count;
2622 static const struct file_operations ab8500_gpadc_conv_type_fops = {
2623 .open = ab8500_gpadc_conv_type_open,
2624 .read = seq_read,
2625 .write = ab8500_gpadc_conv_type_write,
2626 .llseek = seq_lseek,
2627 .release = single_release,
2628 .owner = THIS_MODULE,
2632 * return length of an ASCII numerical value, 0 is string is not a
2633 * numerical value.
2634 * string shall start at value 1st char.
2635 * string can be tailed with \0 or space or newline chars only.
2636 * value can be decimal or hexadecimal (prefixed 0x or 0X).
2638 static int strval_len(char *b)
2640 char *s = b;
2642 if ((*s == '0') && ((*(s+1) == 'x') || (*(s+1) == 'X'))) {
2643 s += 2;
2644 for (; *s && (*s != ' ') && (*s != '\n'); s++) {
2645 if (!isxdigit(*s))
2646 return 0;
2648 } else {
2649 if (*s == '-')
2650 s++;
2651 for (; *s && (*s != ' ') && (*s != '\n'); s++) {
2652 if (!isdigit(*s))
2653 return 0;
2656 return (int) (s-b);
2660 * parse hwreg input data.
2661 * update global hwreg_cfg only if input data syntax is ok.
2663 static ssize_t hwreg_common_write(char *b, struct hwreg_cfg *cfg,
2664 struct device *dev)
2666 uint write, val = 0;
2667 u8 regvalue;
2668 int ret;
2669 struct hwreg_cfg loc = {
2670 .bank = 0, /* default: invalid phys addr */
2671 .addr = 0, /* default: invalid phys addr */
2672 .fmt = 0, /* default: 32bit access, hex output */
2673 .mask = 0xFFFFFFFF, /* default: no mask */
2674 .shift = 0, /* default: no bit shift */
2677 /* read or write ? */
2678 if (!strncmp(b, "read ", 5)) {
2679 write = 0;
2680 b += 5;
2681 } else if (!strncmp(b, "write ", 6)) {
2682 write = 1;
2683 b += 6;
2684 } else
2685 return -EINVAL;
2687 /* OPTIONS -l|-w|-b -s -m -o */
2688 while ((*b == ' ') || (*b == '-')) {
2689 if (*(b-1) != ' ') {
2690 b++;
2691 continue;
2693 if ((!strncmp(b, "-d ", 3)) ||
2694 (!strncmp(b, "-dec ", 5))) {
2695 b += (*(b+2) == ' ') ? 3 : 5;
2696 loc.fmt |= (1<<0);
2697 } else if ((!strncmp(b, "-h ", 3)) ||
2698 (!strncmp(b, "-hex ", 5))) {
2699 b += (*(b+2) == ' ') ? 3 : 5;
2700 loc.fmt &= ~(1<<0);
2701 } else if ((!strncmp(b, "-m ", 3)) ||
2702 (!strncmp(b, "-mask ", 6))) {
2703 b += (*(b+2) == ' ') ? 3 : 6;
2704 if (strval_len(b) == 0)
2705 return -EINVAL;
2706 ret = kstrtoul(b, 0, &loc.mask);
2707 if (ret)
2708 return ret;
2709 } else if ((!strncmp(b, "-s ", 3)) ||
2710 (!strncmp(b, "-shift ", 7))) {
2711 b += (*(b+2) == ' ') ? 3 : 7;
2712 if (strval_len(b) == 0)
2713 return -EINVAL;
2714 ret = kstrtol(b, 0, &loc.shift);
2715 if (ret)
2716 return ret;
2717 } else {
2718 return -EINVAL;
2721 /* get arg BANK and ADDRESS */
2722 if (strval_len(b) == 0)
2723 return -EINVAL;
2724 ret = kstrtouint(b, 0, &loc.bank);
2725 if (ret)
2726 return ret;
2727 while (*b == ' ')
2728 b++;
2729 if (strval_len(b) == 0)
2730 return -EINVAL;
2731 ret = kstrtoul(b, 0, &loc.addr);
2732 if (ret)
2733 return ret;
2735 if (write) {
2736 while (*b == ' ')
2737 b++;
2738 if (strval_len(b) == 0)
2739 return -EINVAL;
2740 ret = kstrtouint(b, 0, &val);
2741 if (ret)
2742 return ret;
2745 /* args are ok, update target cfg (mainly for read) */
2746 *cfg = loc;
2748 #ifdef ABB_HWREG_DEBUG
2749 pr_warn("HWREG request: %s, %s,\n", (write) ? "write" : "read",
2750 REG_FMT_DEC(cfg) ? "decimal" : "hexa");
2751 pr_warn(" addr=0x%08X, mask=0x%X, shift=%d" "value=0x%X\n",
2752 cfg->addr, cfg->mask, cfg->shift, val);
2753 #endif
2755 if (!write)
2756 return 0;
2758 ret = abx500_get_register_interruptible(dev,
2759 (u8)cfg->bank, (u8)cfg->addr, &regvalue);
2760 if (ret < 0) {
2761 dev_err(dev, "abx500_get_reg fail %d, %d\n",
2762 ret, __LINE__);
2763 return -EINVAL;
2766 if (cfg->shift >= 0) {
2767 regvalue &= ~(cfg->mask << (cfg->shift));
2768 val = (val & cfg->mask) << (cfg->shift);
2769 } else {
2770 regvalue &= ~(cfg->mask >> (-cfg->shift));
2771 val = (val & cfg->mask) >> (-cfg->shift);
2773 val = val | regvalue;
2775 ret = abx500_set_register_interruptible(dev,
2776 (u8)cfg->bank, (u8)cfg->addr, (u8)val);
2777 if (ret < 0) {
2778 pr_err("abx500_set_reg failed %d, %d", ret, __LINE__);
2779 return -EINVAL;
2782 return 0;
2785 static ssize_t ab8500_hwreg_write(struct file *file,
2786 const char __user *user_buf, size_t count, loff_t *ppos)
2788 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2789 char buf[128];
2790 int buf_size, ret;
2792 /* Get userspace string and assure termination */
2793 buf_size = min(count, (sizeof(buf)-1));
2794 if (copy_from_user(buf, user_buf, buf_size))
2795 return -EFAULT;
2796 buf[buf_size] = 0;
2798 /* get args and process */
2799 ret = hwreg_common_write(buf, &hwreg_cfg, dev);
2800 return (ret) ? ret : buf_size;
2804 * - irq subscribe/unsubscribe stuff
2806 static int ab8500_subscribe_unsubscribe_print(struct seq_file *s, void *p)
2808 seq_printf(s, "%d\n", irq_first);
2810 return 0;
2813 static int ab8500_subscribe_unsubscribe_open(struct inode *inode,
2814 struct file *file)
2816 return single_open(file, ab8500_subscribe_unsubscribe_print,
2817 inode->i_private);
2821 * Userspace should use poll() on this file. When an event occur
2822 * the blocking poll will be released.
2824 static ssize_t show_irq(struct device *dev,
2825 struct device_attribute *attr, char *buf)
2827 unsigned long name;
2828 unsigned int irq_index;
2829 int err;
2831 err = kstrtoul(attr->attr.name, 0, &name);
2832 if (err)
2833 return err;
2835 irq_index = name - irq_first;
2836 if (irq_index >= num_irqs)
2837 return -EINVAL;
2839 return sprintf(buf, "%u\n", irq_count[irq_index]);
2842 static ssize_t ab8500_subscribe_write(struct file *file,
2843 const char __user *user_buf,
2844 size_t count, loff_t *ppos)
2846 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2847 unsigned long user_val;
2848 int err;
2849 unsigned int irq_index;
2851 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
2852 if (err)
2853 return err;
2855 if (user_val < irq_first) {
2856 dev_err(dev, "debugfs error input < %d\n", irq_first);
2857 return -EINVAL;
2859 if (user_val > irq_last) {
2860 dev_err(dev, "debugfs error input > %d\n", irq_last);
2861 return -EINVAL;
2864 irq_index = user_val - irq_first;
2865 if (irq_index >= num_irqs)
2866 return -EINVAL;
2869 * This will create a sysfs file named <irq-nr> which userspace can
2870 * use to select or poll and get the AB8500 events
2872 dev_attr[irq_index] = kmalloc(sizeof(struct device_attribute),
2873 GFP_KERNEL);
2874 if (!dev_attr[irq_index])
2875 return -ENOMEM;
2877 event_name[irq_index] = kmalloc(count, GFP_KERNEL);
2878 if (!event_name[irq_index])
2879 return -ENOMEM;
2881 sprintf(event_name[irq_index], "%lu", user_val);
2882 dev_attr[irq_index]->show = show_irq;
2883 dev_attr[irq_index]->store = NULL;
2884 dev_attr[irq_index]->attr.name = event_name[irq_index];
2885 dev_attr[irq_index]->attr.mode = S_IRUGO;
2886 err = sysfs_create_file(&dev->kobj, &dev_attr[irq_index]->attr);
2887 if (err < 0) {
2888 pr_info("sysfs_create_file failed %d\n", err);
2889 return err;
2892 err = request_threaded_irq(user_val, NULL, ab8500_debug_handler,
2893 IRQF_SHARED | IRQF_NO_SUSPEND | IRQF_ONESHOT,
2894 "ab8500-debug", &dev->kobj);
2895 if (err < 0) {
2896 pr_info("request_threaded_irq failed %d, %lu\n",
2897 err, user_val);
2898 sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr);
2899 return err;
2902 return count;
2905 static ssize_t ab8500_unsubscribe_write(struct file *file,
2906 const char __user *user_buf,
2907 size_t count, loff_t *ppos)
2909 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2910 unsigned long user_val;
2911 int err;
2912 unsigned int irq_index;
2914 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
2915 if (err)
2916 return err;
2918 if (user_val < irq_first) {
2919 dev_err(dev, "debugfs error input < %d\n", irq_first);
2920 return -EINVAL;
2922 if (user_val > irq_last) {
2923 dev_err(dev, "debugfs error input > %d\n", irq_last);
2924 return -EINVAL;
2927 irq_index = user_val - irq_first;
2928 if (irq_index >= num_irqs)
2929 return -EINVAL;
2931 /* Set irq count to 0 when unsubscribe */
2932 irq_count[irq_index] = 0;
2934 if (dev_attr[irq_index])
2935 sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr);
2938 free_irq(user_val, &dev->kobj);
2939 kfree(event_name[irq_index]);
2940 kfree(dev_attr[irq_index]);
2942 return count;
2946 * - several deubgfs nodes fops
2949 static const struct file_operations ab8500_bank_fops = {
2950 .open = ab8500_bank_open,
2951 .write = ab8500_bank_write,
2952 .read = seq_read,
2953 .llseek = seq_lseek,
2954 .release = single_release,
2955 .owner = THIS_MODULE,
2958 static const struct file_operations ab8500_address_fops = {
2959 .open = ab8500_address_open,
2960 .write = ab8500_address_write,
2961 .read = seq_read,
2962 .llseek = seq_lseek,
2963 .release = single_release,
2964 .owner = THIS_MODULE,
2967 static const struct file_operations ab8500_val_fops = {
2968 .open = ab8500_val_open,
2969 .write = ab8500_val_write,
2970 .read = seq_read,
2971 .llseek = seq_lseek,
2972 .release = single_release,
2973 .owner = THIS_MODULE,
2976 static const struct file_operations ab8500_interrupts_fops = {
2977 .open = ab8500_interrupts_open,
2978 .read = seq_read,
2979 .llseek = seq_lseek,
2980 .release = single_release,
2981 .owner = THIS_MODULE,
2984 static const struct file_operations ab8500_subscribe_fops = {
2985 .open = ab8500_subscribe_unsubscribe_open,
2986 .write = ab8500_subscribe_write,
2987 .read = seq_read,
2988 .llseek = seq_lseek,
2989 .release = single_release,
2990 .owner = THIS_MODULE,
2993 static const struct file_operations ab8500_unsubscribe_fops = {
2994 .open = ab8500_subscribe_unsubscribe_open,
2995 .write = ab8500_unsubscribe_write,
2996 .read = seq_read,
2997 .llseek = seq_lseek,
2998 .release = single_release,
2999 .owner = THIS_MODULE,
3002 static const struct file_operations ab8500_hwreg_fops = {
3003 .open = ab8500_hwreg_open,
3004 .write = ab8500_hwreg_write,
3005 .read = seq_read,
3006 .llseek = seq_lseek,
3007 .release = single_release,
3008 .owner = THIS_MODULE,
3011 static struct dentry *ab8500_dir;
3012 static struct dentry *ab8500_gpadc_dir;
3014 static int ab8500_debug_probe(struct platform_device *plf)
3016 struct dentry *file;
3017 struct ab8500 *ab8500;
3018 struct resource *res;
3020 debug_bank = AB8500_MISC;
3021 debug_address = AB8500_REV_REG & 0x00FF;
3023 ab8500 = dev_get_drvdata(plf->dev.parent);
3024 num_irqs = ab8500->mask_size;
3026 irq_count = devm_kzalloc(&plf->dev,
3027 sizeof(*irq_count)*num_irqs, GFP_KERNEL);
3028 if (!irq_count)
3029 return -ENOMEM;
3031 dev_attr = devm_kzalloc(&plf->dev,
3032 sizeof(*dev_attr)*num_irqs, GFP_KERNEL);
3033 if (!dev_attr)
3034 return -ENOMEM;
3036 event_name = devm_kzalloc(&plf->dev,
3037 sizeof(*event_name)*num_irqs, GFP_KERNEL);
3038 if (!event_name)
3039 return -ENOMEM;
3041 res = platform_get_resource_byname(plf, 0, "IRQ_AB8500");
3042 if (!res) {
3043 dev_err(&plf->dev, "AB8500 irq not found, err %d\n", irq_first);
3044 return -ENXIO;
3046 irq_ab8500 = res->start;
3048 irq_first = platform_get_irq_byname(plf, "IRQ_FIRST");
3049 if (irq_first < 0) {
3050 dev_err(&plf->dev, "First irq not found, err %d\n", irq_first);
3051 return irq_first;
3054 irq_last = platform_get_irq_byname(plf, "IRQ_LAST");
3055 if (irq_last < 0) {
3056 dev_err(&plf->dev, "Last irq not found, err %d\n", irq_last);
3057 return irq_last;
3060 ab8500_dir = debugfs_create_dir(AB8500_NAME_STRING, NULL);
3061 if (!ab8500_dir)
3062 goto err;
3064 ab8500_gpadc_dir = debugfs_create_dir(AB8500_ADC_NAME_STRING,
3065 ab8500_dir);
3066 if (!ab8500_gpadc_dir)
3067 goto err;
3069 file = debugfs_create_file("all-bank-registers", S_IRUGO, ab8500_dir,
3070 &plf->dev, &ab8500_registers_fops);
3071 if (!file)
3072 goto err;
3074 file = debugfs_create_file("all-banks", S_IRUGO, ab8500_dir,
3075 &plf->dev, &ab8500_all_banks_fops);
3076 if (!file)
3077 goto err;
3079 file = debugfs_create_file("register-bank",
3080 (S_IRUGO | S_IWUSR | S_IWGRP),
3081 ab8500_dir, &plf->dev, &ab8500_bank_fops);
3082 if (!file)
3083 goto err;
3085 file = debugfs_create_file("register-address",
3086 (S_IRUGO | S_IWUSR | S_IWGRP),
3087 ab8500_dir, &plf->dev, &ab8500_address_fops);
3088 if (!file)
3089 goto err;
3091 file = debugfs_create_file("register-value",
3092 (S_IRUGO | S_IWUSR | S_IWGRP),
3093 ab8500_dir, &plf->dev, &ab8500_val_fops);
3094 if (!file)
3095 goto err;
3097 file = debugfs_create_file("irq-subscribe",
3098 (S_IRUGO | S_IWUSR | S_IWGRP), ab8500_dir,
3099 &plf->dev, &ab8500_subscribe_fops);
3100 if (!file)
3101 goto err;
3103 if (is_ab8500(ab8500)) {
3104 debug_ranges = ab8500_debug_ranges;
3105 num_interrupt_lines = AB8500_NR_IRQS;
3106 } else if (is_ab8505(ab8500)) {
3107 debug_ranges = ab8505_debug_ranges;
3108 num_interrupt_lines = AB8505_NR_IRQS;
3109 } else if (is_ab9540(ab8500)) {
3110 debug_ranges = ab8505_debug_ranges;
3111 num_interrupt_lines = AB9540_NR_IRQS;
3112 } else if (is_ab8540(ab8500)) {
3113 debug_ranges = ab8540_debug_ranges;
3114 num_interrupt_lines = AB8540_NR_IRQS;
3117 file = debugfs_create_file("interrupts", (S_IRUGO), ab8500_dir,
3118 &plf->dev, &ab8500_interrupts_fops);
3119 if (!file)
3120 goto err;
3122 file = debugfs_create_file("irq-unsubscribe",
3123 (S_IRUGO | S_IWUSR | S_IWGRP), ab8500_dir,
3124 &plf->dev, &ab8500_unsubscribe_fops);
3125 if (!file)
3126 goto err;
3128 file = debugfs_create_file("hwreg", (S_IRUGO | S_IWUSR | S_IWGRP),
3129 ab8500_dir, &plf->dev, &ab8500_hwreg_fops);
3130 if (!file)
3131 goto err;
3133 file = debugfs_create_file("all-modem-registers",
3134 (S_IRUGO | S_IWUSR | S_IWGRP),
3135 ab8500_dir, &plf->dev, &ab8500_modem_fops);
3136 if (!file)
3137 goto err;
3139 file = debugfs_create_file("bat_ctrl", (S_IRUGO | S_IWUSR | S_IWGRP),
3140 ab8500_gpadc_dir, &plf->dev,
3141 &ab8500_gpadc_bat_ctrl_fops);
3142 if (!file)
3143 goto err;
3145 file = debugfs_create_file("btemp_ball", (S_IRUGO | S_IWUSR | S_IWGRP),
3146 ab8500_gpadc_dir,
3147 &plf->dev, &ab8500_gpadc_btemp_ball_fops);
3148 if (!file)
3149 goto err;
3151 file = debugfs_create_file("main_charger_v",
3152 (S_IRUGO | S_IWUSR | S_IWGRP),
3153 ab8500_gpadc_dir, &plf->dev,
3154 &ab8500_gpadc_main_charger_v_fops);
3155 if (!file)
3156 goto err;
3158 file = debugfs_create_file("acc_detect1",
3159 (S_IRUGO | S_IWUSR | S_IWGRP),
3160 ab8500_gpadc_dir, &plf->dev,
3161 &ab8500_gpadc_acc_detect1_fops);
3162 if (!file)
3163 goto err;
3165 file = debugfs_create_file("acc_detect2",
3166 (S_IRUGO | S_IWUSR | S_IWGRP),
3167 ab8500_gpadc_dir, &plf->dev,
3168 &ab8500_gpadc_acc_detect2_fops);
3169 if (!file)
3170 goto err;
3172 file = debugfs_create_file("adc_aux1", (S_IRUGO | S_IWUSR | S_IWGRP),
3173 ab8500_gpadc_dir, &plf->dev,
3174 &ab8500_gpadc_aux1_fops);
3175 if (!file)
3176 goto err;
3178 file = debugfs_create_file("adc_aux2", (S_IRUGO | S_IWUSR | S_IWGRP),
3179 ab8500_gpadc_dir, &plf->dev,
3180 &ab8500_gpadc_aux2_fops);
3181 if (!file)
3182 goto err;
3184 file = debugfs_create_file("main_bat_v", (S_IRUGO | S_IWUSR | S_IWGRP),
3185 ab8500_gpadc_dir, &plf->dev,
3186 &ab8500_gpadc_main_bat_v_fops);
3187 if (!file)
3188 goto err;
3190 file = debugfs_create_file("vbus_v", (S_IRUGO | S_IWUSR | S_IWGRP),
3191 ab8500_gpadc_dir, &plf->dev,
3192 &ab8500_gpadc_vbus_v_fops);
3193 if (!file)
3194 goto err;
3196 file = debugfs_create_file("main_charger_c",
3197 (S_IRUGO | S_IWUSR | S_IWGRP),
3198 ab8500_gpadc_dir, &plf->dev,
3199 &ab8500_gpadc_main_charger_c_fops);
3200 if (!file)
3201 goto err;
3203 file = debugfs_create_file("usb_charger_c",
3204 (S_IRUGO | S_IWUSR | S_IWGRP),
3205 ab8500_gpadc_dir,
3206 &plf->dev, &ab8500_gpadc_usb_charger_c_fops);
3207 if (!file)
3208 goto err;
3210 file = debugfs_create_file("bk_bat_v", (S_IRUGO | S_IWUSR | S_IWGRP),
3211 ab8500_gpadc_dir, &plf->dev,
3212 &ab8500_gpadc_bk_bat_v_fops);
3213 if (!file)
3214 goto err;
3216 file = debugfs_create_file("die_temp", (S_IRUGO | S_IWUSR | S_IWGRP),
3217 ab8500_gpadc_dir, &plf->dev,
3218 &ab8500_gpadc_die_temp_fops);
3219 if (!file)
3220 goto err;
3222 file = debugfs_create_file("usb_id", (S_IRUGO | S_IWUSR | S_IWGRP),
3223 ab8500_gpadc_dir, &plf->dev,
3224 &ab8500_gpadc_usb_id_fops);
3225 if (!file)
3226 goto err;
3228 if (is_ab8540(ab8500)) {
3229 file = debugfs_create_file("xtal_temp",
3230 (S_IRUGO | S_IWUSR | S_IWGRP),
3231 ab8500_gpadc_dir, &plf->dev,
3232 &ab8540_gpadc_xtal_temp_fops);
3233 if (!file)
3234 goto err;
3235 file = debugfs_create_file("vbattruemeas",
3236 (S_IRUGO | S_IWUSR | S_IWGRP),
3237 ab8500_gpadc_dir, &plf->dev,
3238 &ab8540_gpadc_vbat_true_meas_fops);
3239 if (!file)
3240 goto err;
3241 file = debugfs_create_file("batctrl_and_ibat",
3242 (S_IRUGO | S_IWUGO),
3243 ab8500_gpadc_dir,
3244 &plf->dev,
3245 &ab8540_gpadc_bat_ctrl_and_ibat_fops);
3246 if (!file)
3247 goto err;
3248 file = debugfs_create_file("vbatmeas_and_ibat",
3249 (S_IRUGO | S_IWUGO),
3250 ab8500_gpadc_dir, &plf->dev,
3251 &ab8540_gpadc_vbat_meas_and_ibat_fops);
3252 if (!file)
3253 goto err;
3254 file = debugfs_create_file("vbattruemeas_and_ibat",
3255 (S_IRUGO | S_IWUGO),
3256 ab8500_gpadc_dir,
3257 &plf->dev,
3258 &ab8540_gpadc_vbat_true_meas_and_ibat_fops);
3259 if (!file)
3260 goto err;
3261 file = debugfs_create_file("battemp_and_ibat",
3262 (S_IRUGO | S_IWUGO),
3263 ab8500_gpadc_dir,
3264 &plf->dev, &ab8540_gpadc_bat_temp_and_ibat_fops);
3265 if (!file)
3266 goto err;
3267 file = debugfs_create_file("otp_calib",
3268 (S_IRUGO | S_IWUSR | S_IWGRP),
3269 ab8500_gpadc_dir,
3270 &plf->dev, &ab8540_gpadc_otp_calib_fops);
3271 if (!file)
3272 goto err;
3274 file = debugfs_create_file("avg_sample", (S_IRUGO | S_IWUSR | S_IWGRP),
3275 ab8500_gpadc_dir, &plf->dev,
3276 &ab8500_gpadc_avg_sample_fops);
3277 if (!file)
3278 goto err;
3280 file = debugfs_create_file("trig_edge", (S_IRUGO | S_IWUSR | S_IWGRP),
3281 ab8500_gpadc_dir, &plf->dev,
3282 &ab8500_gpadc_trig_edge_fops);
3283 if (!file)
3284 goto err;
3286 file = debugfs_create_file("trig_timer", (S_IRUGO | S_IWUSR | S_IWGRP),
3287 ab8500_gpadc_dir, &plf->dev,
3288 &ab8500_gpadc_trig_timer_fops);
3289 if (!file)
3290 goto err;
3292 file = debugfs_create_file("conv_type", (S_IRUGO | S_IWUSR | S_IWGRP),
3293 ab8500_gpadc_dir, &plf->dev,
3294 &ab8500_gpadc_conv_type_fops);
3295 if (!file)
3296 goto err;
3298 return 0;
3300 err:
3301 debugfs_remove_recursive(ab8500_dir);
3302 dev_err(&plf->dev, "failed to create debugfs entries.\n");
3304 return -ENOMEM;
3307 static int ab8500_debug_remove(struct platform_device *plf)
3309 debugfs_remove_recursive(ab8500_dir);
3311 return 0;
3314 static struct platform_driver ab8500_debug_driver = {
3315 .driver = {
3316 .name = "ab8500-debug",
3318 .probe = ab8500_debug_probe,
3319 .remove = ab8500_debug_remove
3322 static int __init ab8500_debug_init(void)
3324 return platform_driver_register(&ab8500_debug_driver);
3327 static void __exit ab8500_debug_exit(void)
3329 platform_driver_unregister(&ab8500_debug_driver);
3331 subsys_initcall(ab8500_debug_init);
3332 module_exit(ab8500_debug_exit);
3334 MODULE_AUTHOR("Mattias WALLIN <mattias.wallin@stericsson.com");
3335 MODULE_DESCRIPTION("AB8500 DEBUG");
3336 MODULE_LICENSE("GPL v2");