Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / mfd / ab8500-debugfs.c
blobe43dea89b0947a8b91430a818d19de43d6fe1240
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (C) ST-Ericsson SA 2010
5 * Author: Mattias Wallin <mattias.wallin@stericsson.com> for ST-Ericsson.
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/init.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>
88 #ifdef CONFIG_DEBUG_FS
89 #include <linux/string.h>
90 #include <linux/ctype.h>
91 #endif
93 static u32 debug_bank;
94 static u32 debug_address;
96 static int irq_ab8500;
97 static int irq_first;
98 static int irq_last;
99 static u32 *irq_count;
100 static int num_irqs;
102 static struct device_attribute **dev_attr;
103 static char **event_name;
106 * struct ab8500_reg_range
107 * @first: the first address of the range
108 * @last: the last address of the range
109 * @perm: access permissions for the range
111 struct ab8500_reg_range {
112 u8 first;
113 u8 last;
114 u8 perm;
118 * struct ab8500_prcmu_ranges
119 * @num_ranges: the number of ranges in the list
120 * @bankid: bank identifier
121 * @range: the list of register ranges
123 struct ab8500_prcmu_ranges {
124 u8 num_ranges;
125 u8 bankid;
126 const struct ab8500_reg_range *range;
129 /* hwreg- "mask" and "shift" entries ressources */
130 struct hwreg_cfg {
131 u32 bank; /* target bank */
132 unsigned long addr; /* target address */
133 uint fmt; /* format */
134 unsigned long mask; /* read/write mask, applied before any bit shift */
135 long shift; /* bit shift (read:right shift, write:left shift */
137 /* fmt bit #0: 0=hexa, 1=dec */
138 #define REG_FMT_DEC(c) ((c)->fmt & 0x1)
139 #define REG_FMT_HEX(c) (!REG_FMT_DEC(c))
141 static struct hwreg_cfg hwreg_cfg = {
142 .addr = 0, /* default: invalid phys addr */
143 .fmt = 0, /* default: 32bit access, hex output */
144 .mask = 0xFFFFFFFF, /* default: no mask */
145 .shift = 0, /* default: no bit shift */
148 #define AB8500_NAME_STRING "ab8500"
149 #define AB8500_NUM_BANKS AB8500_DEBUG_FIELD_LAST
151 #define AB8500_REV_REG 0x80
153 static struct ab8500_prcmu_ranges *debug_ranges;
155 static struct ab8500_prcmu_ranges ab8500_debug_ranges[AB8500_NUM_BANKS] = {
156 [AB8500_M_FSM_RANK] = {
157 .num_ranges = 0,
158 .range = NULL,
160 [AB8500_SYS_CTRL1_BLOCK] = {
161 .num_ranges = 3,
162 .range = (struct ab8500_reg_range[]) {
164 .first = 0x00,
165 .last = 0x02,
168 .first = 0x42,
169 .last = 0x42,
172 .first = 0x80,
173 .last = 0x81,
177 [AB8500_SYS_CTRL2_BLOCK] = {
178 .num_ranges = 4,
179 .range = (struct ab8500_reg_range[]) {
181 .first = 0x00,
182 .last = 0x0D,
185 .first = 0x0F,
186 .last = 0x17,
189 .first = 0x30,
190 .last = 0x30,
193 .first = 0x32,
194 .last = 0x33,
198 [AB8500_REGU_CTRL1] = {
199 .num_ranges = 3,
200 .range = (struct ab8500_reg_range[]) {
202 .first = 0x00,
203 .last = 0x00,
206 .first = 0x03,
207 .last = 0x10,
210 .first = 0x80,
211 .last = 0x84,
215 [AB8500_REGU_CTRL2] = {
216 .num_ranges = 5,
217 .range = (struct ab8500_reg_range[]) {
219 .first = 0x00,
220 .last = 0x15,
223 .first = 0x17,
224 .last = 0x19,
227 .first = 0x1B,
228 .last = 0x1D,
231 .first = 0x1F,
232 .last = 0x22,
235 .first = 0x40,
236 .last = 0x44,
239 * 0x80-0x8B are SIM registers and should
240 * not be accessed from here
244 [AB8500_USB] = {
245 .num_ranges = 2,
246 .range = (struct ab8500_reg_range[]) {
248 .first = 0x80,
249 .last = 0x83,
252 .first = 0x87,
253 .last = 0x8A,
257 [AB8500_TVOUT] = {
258 .num_ranges = 9,
259 .range = (struct ab8500_reg_range[]) {
261 .first = 0x00,
262 .last = 0x12,
265 .first = 0x15,
266 .last = 0x17,
269 .first = 0x19,
270 .last = 0x21,
273 .first = 0x27,
274 .last = 0x2C,
277 .first = 0x41,
278 .last = 0x41,
281 .first = 0x45,
282 .last = 0x5B,
285 .first = 0x5D,
286 .last = 0x5D,
289 .first = 0x69,
290 .last = 0x69,
293 .first = 0x80,
294 .last = 0x81,
298 [AB8500_DBI] = {
299 .num_ranges = 0,
300 .range = NULL,
302 [AB8500_ECI_AV_ACC] = {
303 .num_ranges = 1,
304 .range = (struct ab8500_reg_range[]) {
306 .first = 0x80,
307 .last = 0x82,
311 [AB8500_RESERVED] = {
312 .num_ranges = 0,
313 .range = NULL,
315 [AB8500_GPADC] = {
316 .num_ranges = 1,
317 .range = (struct ab8500_reg_range[]) {
319 .first = 0x00,
320 .last = 0x08,
324 [AB8500_CHARGER] = {
325 .num_ranges = 9,
326 .range = (struct ab8500_reg_range[]) {
328 .first = 0x00,
329 .last = 0x03,
332 .first = 0x05,
333 .last = 0x05,
336 .first = 0x40,
337 .last = 0x40,
340 .first = 0x42,
341 .last = 0x42,
344 .first = 0x44,
345 .last = 0x44,
348 .first = 0x50,
349 .last = 0x55,
352 .first = 0x80,
353 .last = 0x82,
356 .first = 0xC0,
357 .last = 0xC2,
360 .first = 0xf5,
361 .last = 0xf6,
365 [AB8500_GAS_GAUGE] = {
366 .num_ranges = 3,
367 .range = (struct ab8500_reg_range[]) {
369 .first = 0x00,
370 .last = 0x00,
373 .first = 0x07,
374 .last = 0x0A,
377 .first = 0x10,
378 .last = 0x14,
382 [AB8500_AUDIO] = {
383 .num_ranges = 1,
384 .range = (struct ab8500_reg_range[]) {
386 .first = 0x00,
387 .last = 0x6F,
391 [AB8500_INTERRUPT] = {
392 .num_ranges = 0,
393 .range = NULL,
395 [AB8500_RTC] = {
396 .num_ranges = 1,
397 .range = (struct ab8500_reg_range[]) {
399 .first = 0x00,
400 .last = 0x0F,
404 [AB8500_MISC] = {
405 .num_ranges = 8,
406 .range = (struct ab8500_reg_range[]) {
408 .first = 0x00,
409 .last = 0x05,
412 .first = 0x10,
413 .last = 0x15,
416 .first = 0x20,
417 .last = 0x25,
420 .first = 0x30,
421 .last = 0x35,
424 .first = 0x40,
425 .last = 0x45,
428 .first = 0x50,
429 .last = 0x50,
432 .first = 0x60,
433 .last = 0x67,
436 .first = 0x80,
437 .last = 0x80,
441 [AB8500_DEVELOPMENT] = {
442 .num_ranges = 1,
443 .range = (struct ab8500_reg_range[]) {
445 .first = 0x00,
446 .last = 0x00,
450 [AB8500_DEBUG] = {
451 .num_ranges = 1,
452 .range = (struct ab8500_reg_range[]) {
454 .first = 0x05,
455 .last = 0x07,
459 [AB8500_PROD_TEST] = {
460 .num_ranges = 0,
461 .range = NULL,
463 [AB8500_STE_TEST] = {
464 .num_ranges = 0,
465 .range = NULL,
467 [AB8500_OTP_EMUL] = {
468 .num_ranges = 1,
469 .range = (struct ab8500_reg_range[]) {
471 .first = 0x01,
472 .last = 0x0F,
478 static struct ab8500_prcmu_ranges ab8505_debug_ranges[AB8500_NUM_BANKS] = {
479 [0x0] = {
480 .num_ranges = 0,
481 .range = NULL,
483 [AB8500_SYS_CTRL1_BLOCK] = {
484 .num_ranges = 5,
485 .range = (struct ab8500_reg_range[]) {
487 .first = 0x00,
488 .last = 0x04,
491 .first = 0x42,
492 .last = 0x42,
495 .first = 0x52,
496 .last = 0x52,
499 .first = 0x54,
500 .last = 0x57,
503 .first = 0x80,
504 .last = 0x83,
508 [AB8500_SYS_CTRL2_BLOCK] = {
509 .num_ranges = 5,
510 .range = (struct ab8500_reg_range[]) {
512 .first = 0x00,
513 .last = 0x0D,
516 .first = 0x0F,
517 .last = 0x17,
520 .first = 0x20,
521 .last = 0x20,
524 .first = 0x30,
525 .last = 0x30,
528 .first = 0x32,
529 .last = 0x3A,
533 [AB8500_REGU_CTRL1] = {
534 .num_ranges = 3,
535 .range = (struct ab8500_reg_range[]) {
537 .first = 0x00,
538 .last = 0x00,
541 .first = 0x03,
542 .last = 0x11,
545 .first = 0x80,
546 .last = 0x86,
550 [AB8500_REGU_CTRL2] = {
551 .num_ranges = 6,
552 .range = (struct ab8500_reg_range[]) {
554 .first = 0x00,
555 .last = 0x06,
558 .first = 0x08,
559 .last = 0x15,
562 .first = 0x17,
563 .last = 0x19,
566 .first = 0x1B,
567 .last = 0x1D,
570 .first = 0x1F,
571 .last = 0x30,
574 .first = 0x40,
575 .last = 0x48,
578 * 0x80-0x8B are SIM registers and should
579 * not be accessed from here
583 [AB8500_USB] = {
584 .num_ranges = 3,
585 .range = (struct ab8500_reg_range[]) {
587 .first = 0x80,
588 .last = 0x83,
591 .first = 0x87,
592 .last = 0x8A,
595 .first = 0x91,
596 .last = 0x94,
600 [AB8500_TVOUT] = {
601 .num_ranges = 0,
602 .range = NULL,
604 [AB8500_DBI] = {
605 .num_ranges = 0,
606 .range = NULL,
608 [AB8500_ECI_AV_ACC] = {
609 .num_ranges = 1,
610 .range = (struct ab8500_reg_range[]) {
612 .first = 0x80,
613 .last = 0x82,
617 [AB8500_RESERVED] = {
618 .num_ranges = 0,
619 .range = NULL,
621 [AB8500_GPADC] = {
622 .num_ranges = 1,
623 .range = (struct ab8500_reg_range[]) {
625 .first = 0x00,
626 .last = 0x08,
630 [AB8500_CHARGER] = {
631 .num_ranges = 9,
632 .range = (struct ab8500_reg_range[]) {
634 .first = 0x02,
635 .last = 0x03,
638 .first = 0x05,
639 .last = 0x05,
642 .first = 0x40,
643 .last = 0x44,
646 .first = 0x50,
647 .last = 0x57,
650 .first = 0x60,
651 .last = 0x60,
654 .first = 0xA0,
655 .last = 0xA7,
658 .first = 0xAF,
659 .last = 0xB2,
662 .first = 0xC0,
663 .last = 0xC2,
666 .first = 0xF5,
667 .last = 0xF5,
671 [AB8500_GAS_GAUGE] = {
672 .num_ranges = 3,
673 .range = (struct ab8500_reg_range[]) {
675 .first = 0x00,
676 .last = 0x00,
679 .first = 0x07,
680 .last = 0x0A,
683 .first = 0x10,
684 .last = 0x14,
688 [AB8500_AUDIO] = {
689 .num_ranges = 1,
690 .range = (struct ab8500_reg_range[]) {
692 .first = 0x00,
693 .last = 0x83,
697 [AB8500_INTERRUPT] = {
698 .num_ranges = 11,
699 .range = (struct ab8500_reg_range[]) {
701 .first = 0x00,
702 .last = 0x04,
705 .first = 0x06,
706 .last = 0x07,
709 .first = 0x09,
710 .last = 0x09,
713 .first = 0x0B,
714 .last = 0x0C,
717 .first = 0x12,
718 .last = 0x15,
721 .first = 0x18,
722 .last = 0x18,
724 /* Latch registers should not be read here */
726 .first = 0x40,
727 .last = 0x44,
730 .first = 0x46,
731 .last = 0x49,
734 .first = 0x4B,
735 .last = 0x4D,
738 .first = 0x52,
739 .last = 0x55,
742 .first = 0x58,
743 .last = 0x58,
745 /* LatchHier registers should not be read here */
748 [AB8500_RTC] = {
749 .num_ranges = 2,
750 .range = (struct ab8500_reg_range[]) {
752 .first = 0x00,
753 .last = 0x14,
756 .first = 0x16,
757 .last = 0x17,
761 [AB8500_MISC] = {
762 .num_ranges = 8,
763 .range = (struct ab8500_reg_range[]) {
765 .first = 0x00,
766 .last = 0x06,
769 .first = 0x10,
770 .last = 0x16,
773 .first = 0x20,
774 .last = 0x26,
777 .first = 0x30,
778 .last = 0x36,
781 .first = 0x40,
782 .last = 0x46,
785 .first = 0x50,
786 .last = 0x50,
789 .first = 0x60,
790 .last = 0x6B,
793 .first = 0x80,
794 .last = 0x82,
798 [AB8500_DEVELOPMENT] = {
799 .num_ranges = 2,
800 .range = (struct ab8500_reg_range[]) {
802 .first = 0x00,
803 .last = 0x00,
806 .first = 0x05,
807 .last = 0x05,
811 [AB8500_DEBUG] = {
812 .num_ranges = 1,
813 .range = (struct ab8500_reg_range[]) {
815 .first = 0x05,
816 .last = 0x07,
820 [AB8500_PROD_TEST] = {
821 .num_ranges = 0,
822 .range = NULL,
824 [AB8500_STE_TEST] = {
825 .num_ranges = 0,
826 .range = NULL,
828 [AB8500_OTP_EMUL] = {
829 .num_ranges = 1,
830 .range = (struct ab8500_reg_range[]) {
832 .first = 0x01,
833 .last = 0x15,
839 static struct ab8500_prcmu_ranges ab8540_debug_ranges[AB8500_NUM_BANKS] = {
840 [AB8500_M_FSM_RANK] = {
841 .num_ranges = 1,
842 .range = (struct ab8500_reg_range[]) {
844 .first = 0x00,
845 .last = 0x0B,
849 [AB8500_SYS_CTRL1_BLOCK] = {
850 .num_ranges = 6,
851 .range = (struct ab8500_reg_range[]) {
853 .first = 0x00,
854 .last = 0x04,
857 .first = 0x42,
858 .last = 0x42,
861 .first = 0x50,
862 .last = 0x54,
865 .first = 0x57,
866 .last = 0x57,
869 .first = 0x80,
870 .last = 0x83,
873 .first = 0x90,
874 .last = 0x90,
878 [AB8500_SYS_CTRL2_BLOCK] = {
879 .num_ranges = 5,
880 .range = (struct ab8500_reg_range[]) {
882 .first = 0x00,
883 .last = 0x0D,
886 .first = 0x0F,
887 .last = 0x10,
890 .first = 0x20,
891 .last = 0x21,
894 .first = 0x32,
895 .last = 0x3C,
898 .first = 0x40,
899 .last = 0x42,
903 [AB8500_REGU_CTRL1] = {
904 .num_ranges = 4,
905 .range = (struct ab8500_reg_range[]) {
907 .first = 0x03,
908 .last = 0x15,
911 .first = 0x20,
912 .last = 0x20,
915 .first = 0x80,
916 .last = 0x85,
919 .first = 0x87,
920 .last = 0x88,
924 [AB8500_REGU_CTRL2] = {
925 .num_ranges = 8,
926 .range = (struct ab8500_reg_range[]) {
928 .first = 0x00,
929 .last = 0x06,
932 .first = 0x08,
933 .last = 0x15,
936 .first = 0x17,
937 .last = 0x19,
940 .first = 0x1B,
941 .last = 0x1D,
944 .first = 0x1F,
945 .last = 0x2F,
948 .first = 0x31,
949 .last = 0x3A,
952 .first = 0x43,
953 .last = 0x44,
956 .first = 0x48,
957 .last = 0x49,
961 [AB8500_USB] = {
962 .num_ranges = 3,
963 .range = (struct ab8500_reg_range[]) {
965 .first = 0x80,
966 .last = 0x83,
969 .first = 0x87,
970 .last = 0x8A,
973 .first = 0x91,
974 .last = 0x94,
978 [AB8500_TVOUT] = {
979 .num_ranges = 0,
980 .range = NULL
982 [AB8500_DBI] = {
983 .num_ranges = 4,
984 .range = (struct ab8500_reg_range[]) {
986 .first = 0x00,
987 .last = 0x07,
990 .first = 0x10,
991 .last = 0x11,
994 .first = 0x20,
995 .last = 0x21,
998 .first = 0x30,
999 .last = 0x43,
1003 [AB8500_ECI_AV_ACC] = {
1004 .num_ranges = 2,
1005 .range = (struct ab8500_reg_range[]) {
1007 .first = 0x00,
1008 .last = 0x03,
1011 .first = 0x80,
1012 .last = 0x82,
1016 [AB8500_RESERVED] = {
1017 .num_ranges = 0,
1018 .range = NULL,
1020 [AB8500_GPADC] = {
1021 .num_ranges = 4,
1022 .range = (struct ab8500_reg_range[]) {
1024 .first = 0x00,
1025 .last = 0x01,
1028 .first = 0x04,
1029 .last = 0x06,
1032 .first = 0x09,
1033 .last = 0x0A,
1036 .first = 0x10,
1037 .last = 0x14,
1041 [AB8500_CHARGER] = {
1042 .num_ranges = 10,
1043 .range = (struct ab8500_reg_range[]) {
1045 .first = 0x00,
1046 .last = 0x00,
1049 .first = 0x02,
1050 .last = 0x05,
1053 .first = 0x40,
1054 .last = 0x44,
1057 .first = 0x50,
1058 .last = 0x57,
1061 .first = 0x60,
1062 .last = 0x60,
1065 .first = 0x70,
1066 .last = 0x70,
1069 .first = 0xA0,
1070 .last = 0xA9,
1073 .first = 0xAF,
1074 .last = 0xB2,
1077 .first = 0xC0,
1078 .last = 0xC6,
1081 .first = 0xF5,
1082 .last = 0xF5,
1086 [AB8500_GAS_GAUGE] = {
1087 .num_ranges = 3,
1088 .range = (struct ab8500_reg_range[]) {
1090 .first = 0x00,
1091 .last = 0x00,
1094 .first = 0x07,
1095 .last = 0x0A,
1098 .first = 0x10,
1099 .last = 0x14,
1103 [AB8500_AUDIO] = {
1104 .num_ranges = 1,
1105 .range = (struct ab8500_reg_range[]) {
1107 .first = 0x00,
1108 .last = 0x9f,
1112 [AB8500_INTERRUPT] = {
1113 .num_ranges = 6,
1114 .range = (struct ab8500_reg_range[]) {
1116 .first = 0x00,
1117 .last = 0x05,
1120 .first = 0x0B,
1121 .last = 0x0D,
1124 .first = 0x12,
1125 .last = 0x20,
1127 /* Latch registers should not be read here */
1129 .first = 0x40,
1130 .last = 0x45,
1133 .first = 0x4B,
1134 .last = 0x4D,
1137 .first = 0x52,
1138 .last = 0x60,
1140 /* LatchHier registers should not be read here */
1143 [AB8500_RTC] = {
1144 .num_ranges = 3,
1145 .range = (struct ab8500_reg_range[]) {
1147 .first = 0x00,
1148 .last = 0x07,
1151 .first = 0x0B,
1152 .last = 0x18,
1155 .first = 0x20,
1156 .last = 0x25,
1160 [AB8500_MISC] = {
1161 .num_ranges = 9,
1162 .range = (struct ab8500_reg_range[]) {
1164 .first = 0x00,
1165 .last = 0x06,
1168 .first = 0x10,
1169 .last = 0x16,
1172 .first = 0x20,
1173 .last = 0x26,
1176 .first = 0x30,
1177 .last = 0x36,
1180 .first = 0x40,
1181 .last = 0x49,
1184 .first = 0x50,
1185 .last = 0x50,
1188 .first = 0x60,
1189 .last = 0x6B,
1192 .first = 0x70,
1193 .last = 0x74,
1196 .first = 0x80,
1197 .last = 0x82,
1201 [AB8500_DEVELOPMENT] = {
1202 .num_ranges = 3,
1203 .range = (struct ab8500_reg_range[]) {
1205 .first = 0x00,
1206 .last = 0x01,
1209 .first = 0x06,
1210 .last = 0x06,
1213 .first = 0x10,
1214 .last = 0x21,
1218 [AB8500_DEBUG] = {
1219 .num_ranges = 3,
1220 .range = (struct ab8500_reg_range[]) {
1222 .first = 0x01,
1223 .last = 0x0C,
1226 .first = 0x0E,
1227 .last = 0x11,
1230 .first = 0x80,
1231 .last = 0x81,
1235 [AB8500_PROD_TEST] = {
1236 .num_ranges = 0,
1237 .range = NULL,
1239 [AB8500_STE_TEST] = {
1240 .num_ranges = 0,
1241 .range = NULL,
1243 [AB8500_OTP_EMUL] = {
1244 .num_ranges = 1,
1245 .range = (struct ab8500_reg_range[]) {
1247 .first = 0x00,
1248 .last = 0x3F,
1254 static irqreturn_t ab8500_debug_handler(int irq, void *data)
1256 char buf[16];
1257 struct kobject *kobj = (struct kobject *)data;
1258 unsigned int irq_abb = irq - irq_first;
1260 if (irq_abb < num_irqs)
1261 irq_count[irq_abb]++;
1263 * This makes it possible to use poll for events (EPOLLPRI | EPOLLERR)
1264 * from userspace on sysfs file named <irq-nr>
1266 sprintf(buf, "%d", irq);
1267 sysfs_notify(kobj, NULL, buf);
1269 return IRQ_HANDLED;
1272 /* Prints to seq_file or log_buf */
1273 static int ab8500_registers_print(struct device *dev, u32 bank,
1274 struct seq_file *s)
1276 unsigned int i;
1278 for (i = 0; i < debug_ranges[bank].num_ranges; i++) {
1279 u32 reg;
1281 for (reg = debug_ranges[bank].range[i].first;
1282 reg <= debug_ranges[bank].range[i].last;
1283 reg++) {
1284 u8 value;
1285 int err;
1287 err = abx500_get_register_interruptible(dev,
1288 (u8)bank, (u8)reg, &value);
1289 if (err < 0) {
1290 dev_err(dev, "ab->read fail %d\n", err);
1291 return err;
1294 if (s) {
1295 seq_printf(s, " [0x%02X/0x%02X]: 0x%02X\n",
1296 bank, reg, value);
1298 * Error is not returned here since
1299 * the output is wanted in any case
1301 if (seq_has_overflowed(s))
1302 return 0;
1303 } else {
1304 dev_info(dev, " [0x%02X/0x%02X]: 0x%02X\n",
1305 bank, reg, value);
1310 return 0;
1313 static int ab8500_bank_registers_show(struct seq_file *s, void *p)
1315 struct device *dev = s->private;
1316 u32 bank = debug_bank;
1318 seq_puts(s, AB8500_NAME_STRING " register values:\n");
1320 seq_printf(s, " bank 0x%02X:\n", bank);
1322 return ab8500_registers_print(dev, bank, s);
1325 DEFINE_SHOW_ATTRIBUTE(ab8500_bank_registers);
1327 static int ab8500_print_all_banks(struct seq_file *s, void *p)
1329 struct device *dev = s->private;
1330 unsigned int i;
1332 seq_puts(s, AB8500_NAME_STRING " register values:\n");
1334 for (i = 0; i < AB8500_NUM_BANKS; i++) {
1335 int err;
1337 seq_printf(s, " bank 0x%02X:\n", i);
1338 err = ab8500_registers_print(dev, i, s);
1339 if (err)
1340 return err;
1342 return 0;
1345 /* Dump registers to kernel log */
1346 void ab8500_dump_all_banks(struct device *dev)
1348 unsigned int i;
1350 dev_info(dev, "ab8500 register values:\n");
1352 for (i = 1; i < AB8500_NUM_BANKS; i++) {
1353 dev_info(dev, " bank 0x%02X:\n", i);
1354 ab8500_registers_print(dev, i, NULL);
1358 static int ab8500_all_banks_open(struct inode *inode, struct file *file)
1360 struct seq_file *s;
1361 int err;
1363 err = single_open(file, ab8500_print_all_banks, inode->i_private);
1364 if (!err) {
1365 /* Default buf size in seq_read is not enough */
1366 s = (struct seq_file *)file->private_data;
1367 s->size = (PAGE_SIZE * 2);
1368 s->buf = kmalloc(s->size, GFP_KERNEL);
1369 if (!s->buf) {
1370 single_release(inode, file);
1371 err = -ENOMEM;
1374 return err;
1377 static const struct file_operations ab8500_all_banks_fops = {
1378 .open = ab8500_all_banks_open,
1379 .read = seq_read,
1380 .llseek = seq_lseek,
1381 .release = single_release,
1382 .owner = THIS_MODULE,
1385 static int ab8500_bank_print(struct seq_file *s, void *p)
1387 seq_printf(s, "0x%02X\n", debug_bank);
1388 return 0;
1391 static int ab8500_bank_open(struct inode *inode, struct file *file)
1393 return single_open(file, ab8500_bank_print, inode->i_private);
1396 static ssize_t ab8500_bank_write(struct file *file,
1397 const char __user *user_buf,
1398 size_t count, loff_t *ppos)
1400 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1401 unsigned long user_bank;
1402 int err;
1404 err = kstrtoul_from_user(user_buf, count, 0, &user_bank);
1405 if (err)
1406 return err;
1408 if (user_bank >= AB8500_NUM_BANKS) {
1409 dev_err(dev, "debugfs error input > number of banks\n");
1410 return -EINVAL;
1413 debug_bank = user_bank;
1415 return count;
1418 static int ab8500_address_print(struct seq_file *s, void *p)
1420 seq_printf(s, "0x%02X\n", debug_address);
1421 return 0;
1424 static int ab8500_address_open(struct inode *inode, struct file *file)
1426 return single_open(file, ab8500_address_print, inode->i_private);
1429 static ssize_t ab8500_address_write(struct file *file,
1430 const char __user *user_buf,
1431 size_t count, loff_t *ppos)
1433 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1434 unsigned long user_address;
1435 int err;
1437 err = kstrtoul_from_user(user_buf, count, 0, &user_address);
1438 if (err)
1439 return err;
1441 if (user_address > 0xff) {
1442 dev_err(dev, "debugfs error input > 0xff\n");
1443 return -EINVAL;
1445 debug_address = user_address;
1447 return count;
1450 static int ab8500_val_print(struct seq_file *s, void *p)
1452 struct device *dev = s->private;
1453 int ret;
1454 u8 regvalue;
1456 ret = abx500_get_register_interruptible(dev,
1457 (u8)debug_bank, (u8)debug_address, &regvalue);
1458 if (ret < 0) {
1459 dev_err(dev, "abx500_get_reg fail %d, %d\n",
1460 ret, __LINE__);
1461 return -EINVAL;
1463 seq_printf(s, "0x%02X\n", regvalue);
1465 return 0;
1468 static int ab8500_val_open(struct inode *inode, struct file *file)
1470 return single_open(file, ab8500_val_print, inode->i_private);
1473 static ssize_t ab8500_val_write(struct file *file,
1474 const char __user *user_buf,
1475 size_t count, loff_t *ppos)
1477 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1478 unsigned long user_val;
1479 int err;
1481 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
1482 if (err)
1483 return err;
1485 if (user_val > 0xff) {
1486 dev_err(dev, "debugfs error input > 0xff\n");
1487 return -EINVAL;
1489 err = abx500_set_register_interruptible(dev,
1490 (u8)debug_bank, debug_address, (u8)user_val);
1491 if (err < 0) {
1492 pr_err("abx500_set_reg failed %d, %d", err, __LINE__);
1493 return -EINVAL;
1496 return count;
1500 * Interrupt status
1502 static u32 num_interrupts[AB8500_MAX_NR_IRQS];
1503 static u32 num_wake_interrupts[AB8500_MAX_NR_IRQS];
1504 static int num_interrupt_lines;
1506 void ab8500_debug_register_interrupt(int line)
1508 if (line < num_interrupt_lines)
1509 num_interrupts[line]++;
1512 static int ab8500_interrupts_show(struct seq_file *s, void *p)
1514 int line;
1516 seq_puts(s, "name: number: irq: number of: wake:\n");
1518 for (line = 0; line < num_interrupt_lines; line++) {
1519 seq_printf(s, "%3i: %4i %6i %4i\n",
1520 line,
1521 line + irq_first,
1522 num_interrupts[line],
1523 num_wake_interrupts[line]);
1526 return 0;
1529 DEFINE_SHOW_ATTRIBUTE(ab8500_interrupts);
1532 * - HWREG DB8500 formated routines
1534 static int ab8500_hwreg_print(struct seq_file *s, void *d)
1536 struct device *dev = s->private;
1537 int ret;
1538 u8 regvalue;
1540 ret = abx500_get_register_interruptible(dev,
1541 (u8)hwreg_cfg.bank, (u8)hwreg_cfg.addr, &regvalue);
1542 if (ret < 0) {
1543 dev_err(dev, "abx500_get_reg fail %d, %d\n",
1544 ret, __LINE__);
1545 return -EINVAL;
1548 if (hwreg_cfg.shift >= 0)
1549 regvalue >>= hwreg_cfg.shift;
1550 else
1551 regvalue <<= -hwreg_cfg.shift;
1552 regvalue &= hwreg_cfg.mask;
1554 if (REG_FMT_DEC(&hwreg_cfg))
1555 seq_printf(s, "%d\n", regvalue);
1556 else
1557 seq_printf(s, "0x%02X\n", regvalue);
1558 return 0;
1561 static int ab8500_hwreg_open(struct inode *inode, struct file *file)
1563 return single_open(file, ab8500_hwreg_print, inode->i_private);
1566 #define AB8500_SUPPLY_CONTROL_CONFIG_1 0x01
1567 #define AB8500_SUPPLY_CONTROL_REG 0x00
1568 #define AB8500_FIRST_SIM_REG 0x80
1569 #define AB8500_LAST_SIM_REG 0x8B
1570 #define AB8505_LAST_SIM_REG 0x8C
1572 static int ab8500_modem_show(struct seq_file *s, void *p)
1574 struct device *dev = s->private;
1575 struct ab8500 *ab8500;
1576 int err;
1577 u8 value;
1578 u8 orig_value;
1579 u32 bank = AB8500_REGU_CTRL2;
1580 u32 last_sim_reg = AB8500_LAST_SIM_REG;
1581 u32 reg;
1583 ab8500 = dev_get_drvdata(dev->parent);
1584 dev_warn(dev, "WARNING! This operation can interfer with modem side\n"
1585 "and should only be done with care\n");
1587 err = abx500_get_register_interruptible(dev,
1588 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG, &orig_value);
1589 if (err < 0)
1590 goto report_read_failure;
1592 /* Config 1 will allow APE side to read SIM registers */
1593 err = abx500_set_register_interruptible(dev,
1594 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG,
1595 AB8500_SUPPLY_CONTROL_CONFIG_1);
1596 if (err < 0)
1597 goto report_write_failure;
1599 seq_printf(s, " bank 0x%02X:\n", bank);
1601 if (is_ab9540(ab8500) || is_ab8505(ab8500))
1602 last_sim_reg = AB8505_LAST_SIM_REG;
1604 for (reg = AB8500_FIRST_SIM_REG; reg <= last_sim_reg; reg++) {
1605 err = abx500_get_register_interruptible(dev,
1606 bank, reg, &value);
1607 if (err < 0)
1608 goto report_read_failure;
1610 seq_printf(s, " [0x%02X/0x%02X]: 0x%02X\n", bank, reg, value);
1612 err = abx500_set_register_interruptible(dev,
1613 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG, orig_value);
1614 if (err < 0)
1615 goto report_write_failure;
1617 return 0;
1619 report_read_failure:
1620 dev_err(dev, "ab->read fail %d\n", err);
1621 return err;
1623 report_write_failure:
1624 dev_err(dev, "ab->write fail %d\n", err);
1625 return err;
1628 DEFINE_SHOW_ATTRIBUTE(ab8500_modem);
1631 * return length of an ASCII numerical value, 0 is string is not a
1632 * numerical value.
1633 * string shall start at value 1st char.
1634 * string can be tailed with \0 or space or newline chars only.
1635 * value can be decimal or hexadecimal (prefixed 0x or 0X).
1637 static int strval_len(char *b)
1639 char *s = b;
1641 if ((*s == '0') && ((*(s+1) == 'x') || (*(s+1) == 'X'))) {
1642 s += 2;
1643 for (; *s && (*s != ' ') && (*s != '\n'); s++) {
1644 if (!isxdigit(*s))
1645 return 0;
1647 } else {
1648 if (*s == '-')
1649 s++;
1650 for (; *s && (*s != ' ') && (*s != '\n'); s++) {
1651 if (!isdigit(*s))
1652 return 0;
1655 return (int) (s-b);
1659 * parse hwreg input data.
1660 * update global hwreg_cfg only if input data syntax is ok.
1662 static ssize_t hwreg_common_write(char *b, struct hwreg_cfg *cfg,
1663 struct device *dev)
1665 uint write, val = 0;
1666 u8 regvalue;
1667 int ret;
1668 struct hwreg_cfg loc = {
1669 .bank = 0, /* default: invalid phys addr */
1670 .addr = 0, /* default: invalid phys addr */
1671 .fmt = 0, /* default: 32bit access, hex output */
1672 .mask = 0xFFFFFFFF, /* default: no mask */
1673 .shift = 0, /* default: no bit shift */
1676 /* read or write ? */
1677 if (!strncmp(b, "read ", 5)) {
1678 write = 0;
1679 b += 5;
1680 } else if (!strncmp(b, "write ", 6)) {
1681 write = 1;
1682 b += 6;
1683 } else
1684 return -EINVAL;
1686 /* OPTIONS -l|-w|-b -s -m -o */
1687 while ((*b == ' ') || (*b == '-')) {
1688 if (*(b-1) != ' ') {
1689 b++;
1690 continue;
1692 if ((!strncmp(b, "-d ", 3)) ||
1693 (!strncmp(b, "-dec ", 5))) {
1694 b += (*(b+2) == ' ') ? 3 : 5;
1695 loc.fmt |= (1<<0);
1696 } else if ((!strncmp(b, "-h ", 3)) ||
1697 (!strncmp(b, "-hex ", 5))) {
1698 b += (*(b+2) == ' ') ? 3 : 5;
1699 loc.fmt &= ~(1<<0);
1700 } else if ((!strncmp(b, "-m ", 3)) ||
1701 (!strncmp(b, "-mask ", 6))) {
1702 b += (*(b+2) == ' ') ? 3 : 6;
1703 if (strval_len(b) == 0)
1704 return -EINVAL;
1705 ret = kstrtoul(b, 0, &loc.mask);
1706 if (ret)
1707 return ret;
1708 } else if ((!strncmp(b, "-s ", 3)) ||
1709 (!strncmp(b, "-shift ", 7))) {
1710 b += (*(b+2) == ' ') ? 3 : 7;
1711 if (strval_len(b) == 0)
1712 return -EINVAL;
1713 ret = kstrtol(b, 0, &loc.shift);
1714 if (ret)
1715 return ret;
1716 } else {
1717 return -EINVAL;
1720 /* get arg BANK and ADDRESS */
1721 if (strval_len(b) == 0)
1722 return -EINVAL;
1723 ret = kstrtouint(b, 0, &loc.bank);
1724 if (ret)
1725 return ret;
1726 while (*b == ' ')
1727 b++;
1728 if (strval_len(b) == 0)
1729 return -EINVAL;
1730 ret = kstrtoul(b, 0, &loc.addr);
1731 if (ret)
1732 return ret;
1734 if (write) {
1735 while (*b == ' ')
1736 b++;
1737 if (strval_len(b) == 0)
1738 return -EINVAL;
1739 ret = kstrtouint(b, 0, &val);
1740 if (ret)
1741 return ret;
1744 /* args are ok, update target cfg (mainly for read) */
1745 *cfg = loc;
1747 #ifdef ABB_HWREG_DEBUG
1748 pr_warn("HWREG request: %s, %s,\n", (write) ? "write" : "read",
1749 REG_FMT_DEC(cfg) ? "decimal" : "hexa");
1750 pr_warn(" addr=0x%08X, mask=0x%X, shift=%d" "value=0x%X\n",
1751 cfg->addr, cfg->mask, cfg->shift, val);
1752 #endif
1754 if (!write)
1755 return 0;
1757 ret = abx500_get_register_interruptible(dev,
1758 (u8)cfg->bank, (u8)cfg->addr, &regvalue);
1759 if (ret < 0) {
1760 dev_err(dev, "abx500_get_reg fail %d, %d\n",
1761 ret, __LINE__);
1762 return -EINVAL;
1765 if (cfg->shift >= 0) {
1766 regvalue &= ~(cfg->mask << (cfg->shift));
1767 val = (val & cfg->mask) << (cfg->shift);
1768 } else {
1769 regvalue &= ~(cfg->mask >> (-cfg->shift));
1770 val = (val & cfg->mask) >> (-cfg->shift);
1772 val = val | regvalue;
1774 ret = abx500_set_register_interruptible(dev,
1775 (u8)cfg->bank, (u8)cfg->addr, (u8)val);
1776 if (ret < 0) {
1777 pr_err("abx500_set_reg failed %d, %d", ret, __LINE__);
1778 return -EINVAL;
1781 return 0;
1784 static ssize_t ab8500_hwreg_write(struct file *file,
1785 const char __user *user_buf, size_t count, loff_t *ppos)
1787 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1788 char buf[128];
1789 int buf_size, ret;
1791 /* Get userspace string and assure termination */
1792 buf_size = min((int)count, (int)(sizeof(buf)-1));
1793 if (copy_from_user(buf, user_buf, buf_size))
1794 return -EFAULT;
1795 buf[buf_size] = 0;
1797 /* get args and process */
1798 ret = hwreg_common_write(buf, &hwreg_cfg, dev);
1799 return (ret) ? ret : buf_size;
1803 * - irq subscribe/unsubscribe stuff
1805 static int ab8500_subscribe_unsubscribe_print(struct seq_file *s, void *p)
1807 seq_printf(s, "%d\n", irq_first);
1809 return 0;
1812 static int ab8500_subscribe_unsubscribe_open(struct inode *inode,
1813 struct file *file)
1815 return single_open(file, ab8500_subscribe_unsubscribe_print,
1816 inode->i_private);
1820 * Userspace should use poll() on this file. When an event occur
1821 * the blocking poll will be released.
1823 static ssize_t show_irq(struct device *dev,
1824 struct device_attribute *attr, char *buf)
1826 unsigned long name;
1827 unsigned int irq_index;
1828 int err;
1830 err = kstrtoul(attr->attr.name, 0, &name);
1831 if (err)
1832 return err;
1834 irq_index = name - irq_first;
1835 if (irq_index >= num_irqs)
1836 return -EINVAL;
1838 return sprintf(buf, "%u\n", irq_count[irq_index]);
1841 static ssize_t ab8500_subscribe_write(struct file *file,
1842 const char __user *user_buf,
1843 size_t count, loff_t *ppos)
1845 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1846 unsigned long user_val;
1847 int err;
1848 unsigned int irq_index;
1850 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
1851 if (err)
1852 return err;
1854 if (user_val < irq_first) {
1855 dev_err(dev, "debugfs error input < %d\n", irq_first);
1856 return -EINVAL;
1858 if (user_val > irq_last) {
1859 dev_err(dev, "debugfs error input > %d\n", irq_last);
1860 return -EINVAL;
1863 irq_index = user_val - irq_first;
1864 if (irq_index >= num_irqs)
1865 return -EINVAL;
1868 * This will create a sysfs file named <irq-nr> which userspace can
1869 * use to select or poll and get the AB8500 events
1871 dev_attr[irq_index] = kmalloc(sizeof(struct device_attribute),
1872 GFP_KERNEL);
1873 if (!dev_attr[irq_index])
1874 return -ENOMEM;
1876 event_name[irq_index] = kasprintf(GFP_KERNEL, "%lu", user_val);
1877 if (!event_name[irq_index])
1878 return -ENOMEM;
1880 dev_attr[irq_index]->show = show_irq;
1881 dev_attr[irq_index]->store = NULL;
1882 dev_attr[irq_index]->attr.name = event_name[irq_index];
1883 dev_attr[irq_index]->attr.mode = S_IRUGO;
1884 err = sysfs_create_file(&dev->kobj, &dev_attr[irq_index]->attr);
1885 if (err < 0) {
1886 pr_info("sysfs_create_file failed %d\n", err);
1887 return err;
1890 err = request_threaded_irq(user_val, NULL, ab8500_debug_handler,
1891 IRQF_SHARED | IRQF_NO_SUSPEND | IRQF_ONESHOT,
1892 "ab8500-debug", &dev->kobj);
1893 if (err < 0) {
1894 pr_info("request_threaded_irq failed %d, %lu\n",
1895 err, user_val);
1896 sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr);
1897 return err;
1900 return count;
1903 static ssize_t ab8500_unsubscribe_write(struct file *file,
1904 const char __user *user_buf,
1905 size_t count, loff_t *ppos)
1907 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1908 unsigned long user_val;
1909 int err;
1910 unsigned int irq_index;
1912 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
1913 if (err)
1914 return err;
1916 if (user_val < irq_first) {
1917 dev_err(dev, "debugfs error input < %d\n", irq_first);
1918 return -EINVAL;
1920 if (user_val > irq_last) {
1921 dev_err(dev, "debugfs error input > %d\n", irq_last);
1922 return -EINVAL;
1925 irq_index = user_val - irq_first;
1926 if (irq_index >= num_irqs)
1927 return -EINVAL;
1929 /* Set irq count to 0 when unsubscribe */
1930 irq_count[irq_index] = 0;
1932 if (dev_attr[irq_index])
1933 sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr);
1936 free_irq(user_val, &dev->kobj);
1937 kfree(event_name[irq_index]);
1938 kfree(dev_attr[irq_index]);
1940 return count;
1944 * - several debugfs nodes fops
1947 static const struct file_operations ab8500_bank_fops = {
1948 .open = ab8500_bank_open,
1949 .write = ab8500_bank_write,
1950 .read = seq_read,
1951 .llseek = seq_lseek,
1952 .release = single_release,
1953 .owner = THIS_MODULE,
1956 static const struct file_operations ab8500_address_fops = {
1957 .open = ab8500_address_open,
1958 .write = ab8500_address_write,
1959 .read = seq_read,
1960 .llseek = seq_lseek,
1961 .release = single_release,
1962 .owner = THIS_MODULE,
1965 static const struct file_operations ab8500_val_fops = {
1966 .open = ab8500_val_open,
1967 .write = ab8500_val_write,
1968 .read = seq_read,
1969 .llseek = seq_lseek,
1970 .release = single_release,
1971 .owner = THIS_MODULE,
1974 static const struct file_operations ab8500_subscribe_fops = {
1975 .open = ab8500_subscribe_unsubscribe_open,
1976 .write = ab8500_subscribe_write,
1977 .read = seq_read,
1978 .llseek = seq_lseek,
1979 .release = single_release,
1980 .owner = THIS_MODULE,
1983 static const struct file_operations ab8500_unsubscribe_fops = {
1984 .open = ab8500_subscribe_unsubscribe_open,
1985 .write = ab8500_unsubscribe_write,
1986 .read = seq_read,
1987 .llseek = seq_lseek,
1988 .release = single_release,
1989 .owner = THIS_MODULE,
1992 static const struct file_operations ab8500_hwreg_fops = {
1993 .open = ab8500_hwreg_open,
1994 .write = ab8500_hwreg_write,
1995 .read = seq_read,
1996 .llseek = seq_lseek,
1997 .release = single_release,
1998 .owner = THIS_MODULE,
2001 static int ab8500_debug_probe(struct platform_device *plf)
2003 struct dentry *ab8500_dir;
2004 struct ab8500 *ab8500;
2005 struct resource *res;
2007 debug_bank = AB8500_MISC;
2008 debug_address = AB8500_REV_REG & 0x00FF;
2010 ab8500 = dev_get_drvdata(plf->dev.parent);
2011 num_irqs = ab8500->mask_size;
2013 irq_count = devm_kcalloc(&plf->dev,
2014 num_irqs, sizeof(*irq_count), GFP_KERNEL);
2015 if (!irq_count)
2016 return -ENOMEM;
2018 dev_attr = devm_kcalloc(&plf->dev,
2019 num_irqs, sizeof(*dev_attr), GFP_KERNEL);
2020 if (!dev_attr)
2021 return -ENOMEM;
2023 event_name = devm_kcalloc(&plf->dev,
2024 num_irqs, sizeof(*event_name), GFP_KERNEL);
2025 if (!event_name)
2026 return -ENOMEM;
2028 res = platform_get_resource_byname(plf, 0, "IRQ_AB8500");
2029 if (!res) {
2030 dev_err(&plf->dev, "AB8500 irq not found, err %d\n", irq_first);
2031 return -ENXIO;
2033 irq_ab8500 = res->start;
2035 irq_first = platform_get_irq_byname(plf, "IRQ_FIRST");
2036 if (irq_first < 0)
2037 return irq_first;
2039 irq_last = platform_get_irq_byname(plf, "IRQ_LAST");
2040 if (irq_last < 0)
2041 return irq_last;
2043 ab8500_dir = debugfs_create_dir(AB8500_NAME_STRING, NULL);
2045 debugfs_create_file("all-bank-registers", S_IRUGO, ab8500_dir,
2046 &plf->dev, &ab8500_bank_registers_fops);
2047 debugfs_create_file("all-banks", S_IRUGO, ab8500_dir,
2048 &plf->dev, &ab8500_all_banks_fops);
2049 debugfs_create_file("register-bank", (S_IRUGO | S_IWUSR | S_IWGRP),
2050 ab8500_dir, &plf->dev, &ab8500_bank_fops);
2051 debugfs_create_file("register-address", (S_IRUGO | S_IWUSR | S_IWGRP),
2052 ab8500_dir, &plf->dev, &ab8500_address_fops);
2053 debugfs_create_file("register-value", (S_IRUGO | S_IWUSR | S_IWGRP),
2054 ab8500_dir, &plf->dev, &ab8500_val_fops);
2055 debugfs_create_file("irq-subscribe", (S_IRUGO | S_IWUSR | S_IWGRP),
2056 ab8500_dir, &plf->dev, &ab8500_subscribe_fops);
2058 if (is_ab8500(ab8500)) {
2059 debug_ranges = ab8500_debug_ranges;
2060 num_interrupt_lines = AB8500_NR_IRQS;
2061 } else if (is_ab8505(ab8500)) {
2062 debug_ranges = ab8505_debug_ranges;
2063 num_interrupt_lines = AB8505_NR_IRQS;
2064 } else if (is_ab9540(ab8500)) {
2065 debug_ranges = ab8505_debug_ranges;
2066 num_interrupt_lines = AB9540_NR_IRQS;
2067 } else if (is_ab8540(ab8500)) {
2068 debug_ranges = ab8540_debug_ranges;
2069 num_interrupt_lines = AB8540_NR_IRQS;
2072 debugfs_create_file("interrupts", (S_IRUGO), ab8500_dir, &plf->dev,
2073 &ab8500_interrupts_fops);
2074 debugfs_create_file("irq-unsubscribe", (S_IRUGO | S_IWUSR | S_IWGRP),
2075 ab8500_dir, &plf->dev, &ab8500_unsubscribe_fops);
2076 debugfs_create_file("hwreg", (S_IRUGO | S_IWUSR | S_IWGRP), ab8500_dir,
2077 &plf->dev, &ab8500_hwreg_fops);
2078 debugfs_create_file("all-modem-registers", (S_IRUGO | S_IWUSR | S_IWGRP),
2079 ab8500_dir, &plf->dev, &ab8500_modem_fops);
2081 return 0;
2084 static struct platform_driver ab8500_debug_driver = {
2085 .driver = {
2086 .name = "ab8500-debug",
2087 .suppress_bind_attrs = true,
2089 .probe = ab8500_debug_probe,
2092 static int __init ab8500_debug_init(void)
2094 return platform_driver_register(&ab8500_debug_driver);
2096 subsys_initcall(ab8500_debug_init);