sh_eth: fix EESIPR values for SH77{34|63}
[linux/fpc-iii.git] / drivers / mfd / ab8500-debugfs.c
blobc1c815241e028375e3820e861251a8288bac730d
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/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>
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 AB8500_DEBUG_FIELD_LAST
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 [AB8500_M_FSM_RANK] = {
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 [AB8500_RESERVED] = {
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_AUDIO] = {
390 .num_ranges = 1,
391 .range = (struct ab8500_reg_range[]) {
393 .first = 0x00,
394 .last = 0x6F,
398 [AB8500_INTERRUPT] = {
399 .num_ranges = 0,
400 .range = NULL,
402 [AB8500_RTC] = {
403 .num_ranges = 1,
404 .range = (struct ab8500_reg_range[]) {
406 .first = 0x00,
407 .last = 0x0F,
411 [AB8500_MISC] = {
412 .num_ranges = 8,
413 .range = (struct ab8500_reg_range[]) {
415 .first = 0x00,
416 .last = 0x05,
419 .first = 0x10,
420 .last = 0x15,
423 .first = 0x20,
424 .last = 0x25,
427 .first = 0x30,
428 .last = 0x35,
431 .first = 0x40,
432 .last = 0x45,
435 .first = 0x50,
436 .last = 0x50,
439 .first = 0x60,
440 .last = 0x67,
443 .first = 0x80,
444 .last = 0x80,
448 [AB8500_DEVELOPMENT] = {
449 .num_ranges = 1,
450 .range = (struct ab8500_reg_range[]) {
452 .first = 0x00,
453 .last = 0x00,
457 [AB8500_DEBUG] = {
458 .num_ranges = 1,
459 .range = (struct ab8500_reg_range[]) {
461 .first = 0x05,
462 .last = 0x07,
466 [AB8500_PROD_TEST] = {
467 .num_ranges = 0,
468 .range = NULL,
470 [AB8500_STE_TEST] = {
471 .num_ranges = 0,
472 .range = NULL,
474 [AB8500_OTP_EMUL] = {
475 .num_ranges = 1,
476 .range = (struct ab8500_reg_range[]) {
478 .first = 0x01,
479 .last = 0x0F,
485 static struct ab8500_prcmu_ranges ab8505_debug_ranges[AB8500_NUM_BANKS] = {
486 [0x0] = {
487 .num_ranges = 0,
488 .range = NULL,
490 [AB8500_SYS_CTRL1_BLOCK] = {
491 .num_ranges = 5,
492 .range = (struct ab8500_reg_range[]) {
494 .first = 0x00,
495 .last = 0x04,
498 .first = 0x42,
499 .last = 0x42,
502 .first = 0x52,
503 .last = 0x52,
506 .first = 0x54,
507 .last = 0x57,
510 .first = 0x80,
511 .last = 0x83,
515 [AB8500_SYS_CTRL2_BLOCK] = {
516 .num_ranges = 5,
517 .range = (struct ab8500_reg_range[]) {
519 .first = 0x00,
520 .last = 0x0D,
523 .first = 0x0F,
524 .last = 0x17,
527 .first = 0x20,
528 .last = 0x20,
531 .first = 0x30,
532 .last = 0x30,
535 .first = 0x32,
536 .last = 0x3A,
540 [AB8500_REGU_CTRL1] = {
541 .num_ranges = 3,
542 .range = (struct ab8500_reg_range[]) {
544 .first = 0x00,
545 .last = 0x00,
548 .first = 0x03,
549 .last = 0x11,
552 .first = 0x80,
553 .last = 0x86,
557 [AB8500_REGU_CTRL2] = {
558 .num_ranges = 6,
559 .range = (struct ab8500_reg_range[]) {
561 .first = 0x00,
562 .last = 0x06,
565 .first = 0x08,
566 .last = 0x15,
569 .first = 0x17,
570 .last = 0x19,
573 .first = 0x1B,
574 .last = 0x1D,
577 .first = 0x1F,
578 .last = 0x30,
581 .first = 0x40,
582 .last = 0x48,
585 * 0x80-0x8B are SIM registers and should
586 * not be accessed from here
590 [AB8500_USB] = {
591 .num_ranges = 3,
592 .range = (struct ab8500_reg_range[]) {
594 .first = 0x80,
595 .last = 0x83,
598 .first = 0x87,
599 .last = 0x8A,
602 .first = 0x91,
603 .last = 0x94,
607 [AB8500_TVOUT] = {
608 .num_ranges = 0,
609 .range = NULL,
611 [AB8500_DBI] = {
612 .num_ranges = 0,
613 .range = NULL,
615 [AB8500_ECI_AV_ACC] = {
616 .num_ranges = 1,
617 .range = (struct ab8500_reg_range[]) {
619 .first = 0x80,
620 .last = 0x82,
624 [AB8500_RESERVED] = {
625 .num_ranges = 0,
626 .range = NULL,
628 [AB8500_GPADC] = {
629 .num_ranges = 1,
630 .range = (struct ab8500_reg_range[]) {
632 .first = 0x00,
633 .last = 0x08,
637 [AB8500_CHARGER] = {
638 .num_ranges = 9,
639 .range = (struct ab8500_reg_range[]) {
641 .first = 0x02,
642 .last = 0x03,
645 .first = 0x05,
646 .last = 0x05,
649 .first = 0x40,
650 .last = 0x44,
653 .first = 0x50,
654 .last = 0x57,
657 .first = 0x60,
658 .last = 0x60,
661 .first = 0xA0,
662 .last = 0xA7,
665 .first = 0xAF,
666 .last = 0xB2,
669 .first = 0xC0,
670 .last = 0xC2,
673 .first = 0xF5,
674 .last = 0xF5,
678 [AB8500_GAS_GAUGE] = {
679 .num_ranges = 3,
680 .range = (struct ab8500_reg_range[]) {
682 .first = 0x00,
683 .last = 0x00,
686 .first = 0x07,
687 .last = 0x0A,
690 .first = 0x10,
691 .last = 0x14,
695 [AB8500_AUDIO] = {
696 .num_ranges = 1,
697 .range = (struct ab8500_reg_range[]) {
699 .first = 0x00,
700 .last = 0x83,
704 [AB8500_INTERRUPT] = {
705 .num_ranges = 11,
706 .range = (struct ab8500_reg_range[]) {
708 .first = 0x00,
709 .last = 0x04,
712 .first = 0x06,
713 .last = 0x07,
716 .first = 0x09,
717 .last = 0x09,
720 .first = 0x0B,
721 .last = 0x0C,
724 .first = 0x12,
725 .last = 0x15,
728 .first = 0x18,
729 .last = 0x18,
731 /* Latch registers should not be read here */
733 .first = 0x40,
734 .last = 0x44,
737 .first = 0x46,
738 .last = 0x49,
741 .first = 0x4B,
742 .last = 0x4D,
745 .first = 0x52,
746 .last = 0x55,
749 .first = 0x58,
750 .last = 0x58,
752 /* LatchHier registers should not be read here */
755 [AB8500_RTC] = {
756 .num_ranges = 2,
757 .range = (struct ab8500_reg_range[]) {
759 .first = 0x00,
760 .last = 0x14,
763 .first = 0x16,
764 .last = 0x17,
768 [AB8500_MISC] = {
769 .num_ranges = 8,
770 .range = (struct ab8500_reg_range[]) {
772 .first = 0x00,
773 .last = 0x06,
776 .first = 0x10,
777 .last = 0x16,
780 .first = 0x20,
781 .last = 0x26,
784 .first = 0x30,
785 .last = 0x36,
788 .first = 0x40,
789 .last = 0x46,
792 .first = 0x50,
793 .last = 0x50,
796 .first = 0x60,
797 .last = 0x6B,
800 .first = 0x80,
801 .last = 0x82,
805 [AB8500_DEVELOPMENT] = {
806 .num_ranges = 2,
807 .range = (struct ab8500_reg_range[]) {
809 .first = 0x00,
810 .last = 0x00,
813 .first = 0x05,
814 .last = 0x05,
818 [AB8500_DEBUG] = {
819 .num_ranges = 1,
820 .range = (struct ab8500_reg_range[]) {
822 .first = 0x05,
823 .last = 0x07,
827 [AB8500_PROD_TEST] = {
828 .num_ranges = 0,
829 .range = NULL,
831 [AB8500_STE_TEST] = {
832 .num_ranges = 0,
833 .range = NULL,
835 [AB8500_OTP_EMUL] = {
836 .num_ranges = 1,
837 .range = (struct ab8500_reg_range[]) {
839 .first = 0x01,
840 .last = 0x15,
846 static struct ab8500_prcmu_ranges ab8540_debug_ranges[AB8500_NUM_BANKS] = {
847 [AB8500_M_FSM_RANK] = {
848 .num_ranges = 1,
849 .range = (struct ab8500_reg_range[]) {
851 .first = 0x00,
852 .last = 0x0B,
856 [AB8500_SYS_CTRL1_BLOCK] = {
857 .num_ranges = 6,
858 .range = (struct ab8500_reg_range[]) {
860 .first = 0x00,
861 .last = 0x04,
864 .first = 0x42,
865 .last = 0x42,
868 .first = 0x50,
869 .last = 0x54,
872 .first = 0x57,
873 .last = 0x57,
876 .first = 0x80,
877 .last = 0x83,
880 .first = 0x90,
881 .last = 0x90,
885 [AB8500_SYS_CTRL2_BLOCK] = {
886 .num_ranges = 5,
887 .range = (struct ab8500_reg_range[]) {
889 .first = 0x00,
890 .last = 0x0D,
893 .first = 0x0F,
894 .last = 0x10,
897 .first = 0x20,
898 .last = 0x21,
901 .first = 0x32,
902 .last = 0x3C,
905 .first = 0x40,
906 .last = 0x42,
910 [AB8500_REGU_CTRL1] = {
911 .num_ranges = 4,
912 .range = (struct ab8500_reg_range[]) {
914 .first = 0x03,
915 .last = 0x15,
918 .first = 0x20,
919 .last = 0x20,
922 .first = 0x80,
923 .last = 0x85,
926 .first = 0x87,
927 .last = 0x88,
931 [AB8500_REGU_CTRL2] = {
932 .num_ranges = 8,
933 .range = (struct ab8500_reg_range[]) {
935 .first = 0x00,
936 .last = 0x06,
939 .first = 0x08,
940 .last = 0x15,
943 .first = 0x17,
944 .last = 0x19,
947 .first = 0x1B,
948 .last = 0x1D,
951 .first = 0x1F,
952 .last = 0x2F,
955 .first = 0x31,
956 .last = 0x3A,
959 .first = 0x43,
960 .last = 0x44,
963 .first = 0x48,
964 .last = 0x49,
968 [AB8500_USB] = {
969 .num_ranges = 3,
970 .range = (struct ab8500_reg_range[]) {
972 .first = 0x80,
973 .last = 0x83,
976 .first = 0x87,
977 .last = 0x8A,
980 .first = 0x91,
981 .last = 0x94,
985 [AB8500_TVOUT] = {
986 .num_ranges = 0,
987 .range = NULL
989 [AB8500_DBI] = {
990 .num_ranges = 4,
991 .range = (struct ab8500_reg_range[]) {
993 .first = 0x00,
994 .last = 0x07,
997 .first = 0x10,
998 .last = 0x11,
1001 .first = 0x20,
1002 .last = 0x21,
1005 .first = 0x30,
1006 .last = 0x43,
1010 [AB8500_ECI_AV_ACC] = {
1011 .num_ranges = 2,
1012 .range = (struct ab8500_reg_range[]) {
1014 .first = 0x00,
1015 .last = 0x03,
1018 .first = 0x80,
1019 .last = 0x82,
1023 [AB8500_RESERVED] = {
1024 .num_ranges = 0,
1025 .range = NULL,
1027 [AB8500_GPADC] = {
1028 .num_ranges = 4,
1029 .range = (struct ab8500_reg_range[]) {
1031 .first = 0x00,
1032 .last = 0x01,
1035 .first = 0x04,
1036 .last = 0x06,
1039 .first = 0x09,
1040 .last = 0x0A,
1043 .first = 0x10,
1044 .last = 0x14,
1048 [AB8500_CHARGER] = {
1049 .num_ranges = 10,
1050 .range = (struct ab8500_reg_range[]) {
1052 .first = 0x00,
1053 .last = 0x00,
1056 .first = 0x02,
1057 .last = 0x05,
1060 .first = 0x40,
1061 .last = 0x44,
1064 .first = 0x50,
1065 .last = 0x57,
1068 .first = 0x60,
1069 .last = 0x60,
1072 .first = 0x70,
1073 .last = 0x70,
1076 .first = 0xA0,
1077 .last = 0xA9,
1080 .first = 0xAF,
1081 .last = 0xB2,
1084 .first = 0xC0,
1085 .last = 0xC6,
1088 .first = 0xF5,
1089 .last = 0xF5,
1093 [AB8500_GAS_GAUGE] = {
1094 .num_ranges = 3,
1095 .range = (struct ab8500_reg_range[]) {
1097 .first = 0x00,
1098 .last = 0x00,
1101 .first = 0x07,
1102 .last = 0x0A,
1105 .first = 0x10,
1106 .last = 0x14,
1110 [AB8500_AUDIO] = {
1111 .num_ranges = 1,
1112 .range = (struct ab8500_reg_range[]) {
1114 .first = 0x00,
1115 .last = 0x9f,
1119 [AB8500_INTERRUPT] = {
1120 .num_ranges = 6,
1121 .range = (struct ab8500_reg_range[]) {
1123 .first = 0x00,
1124 .last = 0x05,
1127 .first = 0x0B,
1128 .last = 0x0D,
1131 .first = 0x12,
1132 .last = 0x20,
1134 /* Latch registers should not be read here */
1136 .first = 0x40,
1137 .last = 0x45,
1140 .first = 0x4B,
1141 .last = 0x4D,
1144 .first = 0x52,
1145 .last = 0x60,
1147 /* LatchHier registers should not be read here */
1150 [AB8500_RTC] = {
1151 .num_ranges = 3,
1152 .range = (struct ab8500_reg_range[]) {
1154 .first = 0x00,
1155 .last = 0x07,
1158 .first = 0x0B,
1159 .last = 0x18,
1162 .first = 0x20,
1163 .last = 0x25,
1167 [AB8500_MISC] = {
1168 .num_ranges = 9,
1169 .range = (struct ab8500_reg_range[]) {
1171 .first = 0x00,
1172 .last = 0x06,
1175 .first = 0x10,
1176 .last = 0x16,
1179 .first = 0x20,
1180 .last = 0x26,
1183 .first = 0x30,
1184 .last = 0x36,
1187 .first = 0x40,
1188 .last = 0x49,
1191 .first = 0x50,
1192 .last = 0x50,
1195 .first = 0x60,
1196 .last = 0x6B,
1199 .first = 0x70,
1200 .last = 0x74,
1203 .first = 0x80,
1204 .last = 0x82,
1208 [AB8500_DEVELOPMENT] = {
1209 .num_ranges = 3,
1210 .range = (struct ab8500_reg_range[]) {
1212 .first = 0x00,
1213 .last = 0x01,
1216 .first = 0x06,
1217 .last = 0x06,
1220 .first = 0x10,
1221 .last = 0x21,
1225 [AB8500_DEBUG] = {
1226 .num_ranges = 3,
1227 .range = (struct ab8500_reg_range[]) {
1229 .first = 0x01,
1230 .last = 0x0C,
1233 .first = 0x0E,
1234 .last = 0x11,
1237 .first = 0x80,
1238 .last = 0x81,
1242 [AB8500_PROD_TEST] = {
1243 .num_ranges = 0,
1244 .range = NULL,
1246 [AB8500_STE_TEST] = {
1247 .num_ranges = 0,
1248 .range = NULL,
1250 [AB8500_OTP_EMUL] = {
1251 .num_ranges = 1,
1252 .range = (struct ab8500_reg_range[]) {
1254 .first = 0x00,
1255 .last = 0x3F,
1262 static irqreturn_t ab8500_debug_handler(int irq, void *data)
1264 char buf[16];
1265 struct kobject *kobj = (struct kobject *)data;
1266 unsigned int irq_abb = irq - irq_first;
1268 if (irq_abb < num_irqs)
1269 irq_count[irq_abb]++;
1271 * This makes it possible to use poll for events (POLLPRI | POLLERR)
1272 * from userspace on sysfs file named <irq-nr>
1274 sprintf(buf, "%d", irq);
1275 sysfs_notify(kobj, NULL, buf);
1277 return IRQ_HANDLED;
1280 /* Prints to seq_file or log_buf */
1281 static int ab8500_registers_print(struct device *dev, u32 bank,
1282 struct seq_file *s)
1284 unsigned int i;
1286 for (i = 0; i < debug_ranges[bank].num_ranges; i++) {
1287 u32 reg;
1289 for (reg = debug_ranges[bank].range[i].first;
1290 reg <= debug_ranges[bank].range[i].last;
1291 reg++) {
1292 u8 value;
1293 int err;
1295 err = abx500_get_register_interruptible(dev,
1296 (u8)bank, (u8)reg, &value);
1297 if (err < 0) {
1298 dev_err(dev, "ab->read fail %d\n", err);
1299 return err;
1302 if (s) {
1303 seq_printf(s, " [0x%02X/0x%02X]: 0x%02X\n",
1304 bank, reg, value);
1306 * Error is not returned here since
1307 * the output is wanted in any case
1309 if (seq_has_overflowed(s))
1310 return 0;
1311 } else {
1312 dev_info(dev, " [0x%02X/0x%02X]: 0x%02X\n",
1313 bank, reg, value);
1318 return 0;
1321 static int ab8500_print_bank_registers(struct seq_file *s, void *p)
1323 struct device *dev = s->private;
1324 u32 bank = debug_bank;
1326 seq_puts(s, AB8500_NAME_STRING " register values:\n");
1328 seq_printf(s, " bank 0x%02X:\n", bank);
1330 return ab8500_registers_print(dev, bank, s);
1333 static int ab8500_registers_open(struct inode *inode, struct file *file)
1335 return single_open(file, ab8500_print_bank_registers, inode->i_private);
1338 static const struct file_operations ab8500_registers_fops = {
1339 .open = ab8500_registers_open,
1340 .read = seq_read,
1341 .llseek = seq_lseek,
1342 .release = single_release,
1343 .owner = THIS_MODULE,
1346 static int ab8500_print_all_banks(struct seq_file *s, void *p)
1348 struct device *dev = s->private;
1349 unsigned int i;
1351 seq_puts(s, AB8500_NAME_STRING " register values:\n");
1353 for (i = 0; i < AB8500_NUM_BANKS; i++) {
1354 int err;
1356 seq_printf(s, " bank 0x%02X:\n", i);
1357 err = ab8500_registers_print(dev, i, s);
1358 if (err)
1359 return err;
1361 return 0;
1364 /* Dump registers to kernel log */
1365 void ab8500_dump_all_banks(struct device *dev)
1367 unsigned int i;
1369 dev_info(dev, "ab8500 register values:\n");
1371 for (i = 1; i < AB8500_NUM_BANKS; i++) {
1372 dev_info(dev, " bank 0x%02X:\n", i);
1373 ab8500_registers_print(dev, i, NULL);
1377 static int ab8500_all_banks_open(struct inode *inode, struct file *file)
1379 struct seq_file *s;
1380 int err;
1382 err = single_open(file, ab8500_print_all_banks, inode->i_private);
1383 if (!err) {
1384 /* Default buf size in seq_read is not enough */
1385 s = (struct seq_file *)file->private_data;
1386 s->size = (PAGE_SIZE * 2);
1387 s->buf = kmalloc(s->size, GFP_KERNEL);
1388 if (!s->buf) {
1389 single_release(inode, file);
1390 err = -ENOMEM;
1393 return err;
1396 static const struct file_operations ab8500_all_banks_fops = {
1397 .open = ab8500_all_banks_open,
1398 .read = seq_read,
1399 .llseek = seq_lseek,
1400 .release = single_release,
1401 .owner = THIS_MODULE,
1404 static int ab8500_bank_print(struct seq_file *s, void *p)
1406 seq_printf(s, "0x%02X\n", debug_bank);
1407 return 0;
1410 static int ab8500_bank_open(struct inode *inode, struct file *file)
1412 return single_open(file, ab8500_bank_print, inode->i_private);
1415 static ssize_t ab8500_bank_write(struct file *file,
1416 const char __user *user_buf,
1417 size_t count, loff_t *ppos)
1419 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1420 unsigned long user_bank;
1421 int err;
1423 err = kstrtoul_from_user(user_buf, count, 0, &user_bank);
1424 if (err)
1425 return err;
1427 if (user_bank >= AB8500_NUM_BANKS) {
1428 dev_err(dev, "debugfs error input > number of banks\n");
1429 return -EINVAL;
1432 debug_bank = user_bank;
1434 return count;
1437 static int ab8500_address_print(struct seq_file *s, void *p)
1439 seq_printf(s, "0x%02X\n", debug_address);
1440 return 0;
1443 static int ab8500_address_open(struct inode *inode, struct file *file)
1445 return single_open(file, ab8500_address_print, inode->i_private);
1448 static ssize_t ab8500_address_write(struct file *file,
1449 const char __user *user_buf,
1450 size_t count, loff_t *ppos)
1452 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1453 unsigned long user_address;
1454 int err;
1456 err = kstrtoul_from_user(user_buf, count, 0, &user_address);
1457 if (err)
1458 return err;
1460 if (user_address > 0xff) {
1461 dev_err(dev, "debugfs error input > 0xff\n");
1462 return -EINVAL;
1464 debug_address = user_address;
1466 return count;
1469 static int ab8500_val_print(struct seq_file *s, void *p)
1471 struct device *dev = s->private;
1472 int ret;
1473 u8 regvalue;
1475 ret = abx500_get_register_interruptible(dev,
1476 (u8)debug_bank, (u8)debug_address, &regvalue);
1477 if (ret < 0) {
1478 dev_err(dev, "abx500_get_reg fail %d, %d\n",
1479 ret, __LINE__);
1480 return -EINVAL;
1482 seq_printf(s, "0x%02X\n", regvalue);
1484 return 0;
1487 static int ab8500_val_open(struct inode *inode, struct file *file)
1489 return single_open(file, ab8500_val_print, inode->i_private);
1492 static ssize_t ab8500_val_write(struct file *file,
1493 const char __user *user_buf,
1494 size_t count, loff_t *ppos)
1496 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1497 unsigned long user_val;
1498 int err;
1500 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
1501 if (err)
1502 return err;
1504 if (user_val > 0xff) {
1505 dev_err(dev, "debugfs error input > 0xff\n");
1506 return -EINVAL;
1508 err = abx500_set_register_interruptible(dev,
1509 (u8)debug_bank, debug_address, (u8)user_val);
1510 if (err < 0) {
1511 pr_err("abx500_set_reg failed %d, %d", err, __LINE__);
1512 return -EINVAL;
1515 return count;
1519 * Interrupt status
1521 static u32 num_interrupts[AB8500_MAX_NR_IRQS];
1522 static u32 num_wake_interrupts[AB8500_MAX_NR_IRQS];
1523 static int num_interrupt_lines;
1525 void ab8500_debug_register_interrupt(int line)
1527 if (line < num_interrupt_lines)
1528 num_interrupts[line]++;
1531 static int ab8500_interrupts_print(struct seq_file *s, void *p)
1533 int line;
1535 seq_puts(s, "name: number: number of: wake:\n");
1537 for (line = 0; line < num_interrupt_lines; line++) {
1538 struct irq_desc *desc = irq_to_desc(line + irq_first);
1540 seq_printf(s, "%3i: %6i %4i",
1541 line,
1542 num_interrupts[line],
1543 num_wake_interrupts[line]);
1545 if (desc && desc->name)
1546 seq_printf(s, "-%-8s", desc->name);
1547 if (desc && desc->action) {
1548 struct irqaction *action = desc->action;
1550 seq_printf(s, " %s", action->name);
1551 while ((action = action->next) != NULL)
1552 seq_printf(s, ", %s", action->name);
1554 seq_putc(s, '\n');
1557 return 0;
1560 static int ab8500_interrupts_open(struct inode *inode, struct file *file)
1562 return single_open(file, ab8500_interrupts_print, inode->i_private);
1566 * - HWREG DB8500 formated routines
1568 static int ab8500_hwreg_print(struct seq_file *s, void *d)
1570 struct device *dev = s->private;
1571 int ret;
1572 u8 regvalue;
1574 ret = abx500_get_register_interruptible(dev,
1575 (u8)hwreg_cfg.bank, (u8)hwreg_cfg.addr, &regvalue);
1576 if (ret < 0) {
1577 dev_err(dev, "abx500_get_reg fail %d, %d\n",
1578 ret, __LINE__);
1579 return -EINVAL;
1582 if (hwreg_cfg.shift >= 0)
1583 regvalue >>= hwreg_cfg.shift;
1584 else
1585 regvalue <<= -hwreg_cfg.shift;
1586 regvalue &= hwreg_cfg.mask;
1588 if (REG_FMT_DEC(&hwreg_cfg))
1589 seq_printf(s, "%d\n", regvalue);
1590 else
1591 seq_printf(s, "0x%02X\n", regvalue);
1592 return 0;
1595 static int ab8500_hwreg_open(struct inode *inode, struct file *file)
1597 return single_open(file, ab8500_hwreg_print, inode->i_private);
1600 #define AB8500_SUPPLY_CONTROL_CONFIG_1 0x01
1601 #define AB8500_SUPPLY_CONTROL_REG 0x00
1602 #define AB8500_FIRST_SIM_REG 0x80
1603 #define AB8500_LAST_SIM_REG 0x8B
1604 #define AB8505_LAST_SIM_REG 0x8C
1606 static int ab8500_print_modem_registers(struct seq_file *s, void *p)
1608 struct device *dev = s->private;
1609 struct ab8500 *ab8500;
1610 int err;
1611 u8 value;
1612 u8 orig_value;
1613 u32 bank = AB8500_REGU_CTRL2;
1614 u32 last_sim_reg = AB8500_LAST_SIM_REG;
1615 u32 reg;
1617 ab8500 = dev_get_drvdata(dev->parent);
1618 dev_warn(dev, "WARNING! This operation can interfer with modem side\n"
1619 "and should only be done with care\n");
1621 err = abx500_get_register_interruptible(dev,
1622 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG, &orig_value);
1623 if (err < 0) {
1624 dev_err(dev, "ab->read fail %d\n", err);
1625 return err;
1627 /* Config 1 will allow APE side to read SIM registers */
1628 err = abx500_set_register_interruptible(dev,
1629 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG,
1630 AB8500_SUPPLY_CONTROL_CONFIG_1);
1631 if (err < 0) {
1632 dev_err(dev, "ab->write fail %d\n", err);
1633 return err;
1636 seq_printf(s, " bank 0x%02X:\n", bank);
1638 if (is_ab9540(ab8500) || is_ab8505(ab8500))
1639 last_sim_reg = AB8505_LAST_SIM_REG;
1641 for (reg = AB8500_FIRST_SIM_REG; reg <= last_sim_reg; reg++) {
1642 err = abx500_get_register_interruptible(dev,
1643 bank, reg, &value);
1644 if (err < 0) {
1645 dev_err(dev, "ab->read fail %d\n", err);
1646 return err;
1648 seq_printf(s, " [0x%02X/0x%02X]: 0x%02X\n", bank, reg, value);
1650 err = abx500_set_register_interruptible(dev,
1651 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG, orig_value);
1652 if (err < 0) {
1653 dev_err(dev, "ab->write fail %d\n", err);
1654 return err;
1656 return 0;
1659 static int ab8500_modem_open(struct inode *inode, struct file *file)
1661 return single_open(file, ab8500_print_modem_registers,
1662 inode->i_private);
1665 static const struct file_operations ab8500_modem_fops = {
1666 .open = ab8500_modem_open,
1667 .read = seq_read,
1668 .llseek = seq_lseek,
1669 .release = single_release,
1670 .owner = THIS_MODULE,
1673 static int ab8500_gpadc_bat_ctrl_print(struct seq_file *s, void *p)
1675 int bat_ctrl_raw;
1676 int bat_ctrl_convert;
1677 struct ab8500_gpadc *gpadc;
1679 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1680 bat_ctrl_raw = ab8500_gpadc_read_raw(gpadc, BAT_CTRL,
1681 avg_sample, trig_edge, trig_timer, conv_type);
1682 bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc,
1683 BAT_CTRL, bat_ctrl_raw);
1685 seq_printf(s, "%d,0x%X\n", bat_ctrl_convert, bat_ctrl_raw);
1687 return 0;
1690 static int ab8500_gpadc_bat_ctrl_open(struct inode *inode, struct file *file)
1692 return single_open(file, ab8500_gpadc_bat_ctrl_print,
1693 inode->i_private);
1696 static const struct file_operations ab8500_gpadc_bat_ctrl_fops = {
1697 .open = ab8500_gpadc_bat_ctrl_open,
1698 .read = seq_read,
1699 .llseek = seq_lseek,
1700 .release = single_release,
1701 .owner = THIS_MODULE,
1704 static int ab8500_gpadc_btemp_ball_print(struct seq_file *s, void *p)
1706 int btemp_ball_raw;
1707 int btemp_ball_convert;
1708 struct ab8500_gpadc *gpadc;
1710 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1711 btemp_ball_raw = ab8500_gpadc_read_raw(gpadc, BTEMP_BALL,
1712 avg_sample, trig_edge, trig_timer, conv_type);
1713 btemp_ball_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL,
1714 btemp_ball_raw);
1716 seq_printf(s, "%d,0x%X\n", btemp_ball_convert, btemp_ball_raw);
1718 return 0;
1721 static int ab8500_gpadc_btemp_ball_open(struct inode *inode,
1722 struct file *file)
1724 return single_open(file, ab8500_gpadc_btemp_ball_print,
1725 inode->i_private);
1728 static const struct file_operations ab8500_gpadc_btemp_ball_fops = {
1729 .open = ab8500_gpadc_btemp_ball_open,
1730 .read = seq_read,
1731 .llseek = seq_lseek,
1732 .release = single_release,
1733 .owner = THIS_MODULE,
1736 static int ab8500_gpadc_main_charger_v_print(struct seq_file *s, void *p)
1738 int main_charger_v_raw;
1739 int main_charger_v_convert;
1740 struct ab8500_gpadc *gpadc;
1742 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1743 main_charger_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_V,
1744 avg_sample, trig_edge, trig_timer, conv_type);
1745 main_charger_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
1746 MAIN_CHARGER_V, main_charger_v_raw);
1748 seq_printf(s, "%d,0x%X\n", main_charger_v_convert, main_charger_v_raw);
1750 return 0;
1753 static int ab8500_gpadc_main_charger_v_open(struct inode *inode,
1754 struct file *file)
1756 return single_open(file, ab8500_gpadc_main_charger_v_print,
1757 inode->i_private);
1760 static const struct file_operations ab8500_gpadc_main_charger_v_fops = {
1761 .open = ab8500_gpadc_main_charger_v_open,
1762 .read = seq_read,
1763 .llseek = seq_lseek,
1764 .release = single_release,
1765 .owner = THIS_MODULE,
1768 static int ab8500_gpadc_acc_detect1_print(struct seq_file *s, void *p)
1770 int acc_detect1_raw;
1771 int acc_detect1_convert;
1772 struct ab8500_gpadc *gpadc;
1774 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1775 acc_detect1_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT1,
1776 avg_sample, trig_edge, trig_timer, conv_type);
1777 acc_detect1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ACC_DETECT1,
1778 acc_detect1_raw);
1780 seq_printf(s, "%d,0x%X\n", acc_detect1_convert, acc_detect1_raw);
1782 return 0;
1785 static int ab8500_gpadc_acc_detect1_open(struct inode *inode,
1786 struct file *file)
1788 return single_open(file, ab8500_gpadc_acc_detect1_print,
1789 inode->i_private);
1792 static const struct file_operations ab8500_gpadc_acc_detect1_fops = {
1793 .open = ab8500_gpadc_acc_detect1_open,
1794 .read = seq_read,
1795 .llseek = seq_lseek,
1796 .release = single_release,
1797 .owner = THIS_MODULE,
1800 static int ab8500_gpadc_acc_detect2_print(struct seq_file *s, void *p)
1802 int acc_detect2_raw;
1803 int acc_detect2_convert;
1804 struct ab8500_gpadc *gpadc;
1806 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1807 acc_detect2_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT2,
1808 avg_sample, trig_edge, trig_timer, conv_type);
1809 acc_detect2_convert = ab8500_gpadc_ad_to_voltage(gpadc,
1810 ACC_DETECT2, acc_detect2_raw);
1812 seq_printf(s, "%d,0x%X\n", acc_detect2_convert, acc_detect2_raw);
1814 return 0;
1817 static int ab8500_gpadc_acc_detect2_open(struct inode *inode,
1818 struct file *file)
1820 return single_open(file, ab8500_gpadc_acc_detect2_print,
1821 inode->i_private);
1824 static const struct file_operations ab8500_gpadc_acc_detect2_fops = {
1825 .open = ab8500_gpadc_acc_detect2_open,
1826 .read = seq_read,
1827 .llseek = seq_lseek,
1828 .release = single_release,
1829 .owner = THIS_MODULE,
1832 static int ab8500_gpadc_aux1_print(struct seq_file *s, void *p)
1834 int aux1_raw;
1835 int aux1_convert;
1836 struct ab8500_gpadc *gpadc;
1838 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1839 aux1_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX1,
1840 avg_sample, trig_edge, trig_timer, conv_type);
1841 aux1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX1,
1842 aux1_raw);
1844 seq_printf(s, "%d,0x%X\n", aux1_convert, aux1_raw);
1846 return 0;
1849 static int ab8500_gpadc_aux1_open(struct inode *inode, struct file *file)
1851 return single_open(file, ab8500_gpadc_aux1_print, inode->i_private);
1854 static const struct file_operations ab8500_gpadc_aux1_fops = {
1855 .open = ab8500_gpadc_aux1_open,
1856 .read = seq_read,
1857 .llseek = seq_lseek,
1858 .release = single_release,
1859 .owner = THIS_MODULE,
1862 static int ab8500_gpadc_aux2_print(struct seq_file *s, void *p)
1864 int aux2_raw;
1865 int aux2_convert;
1866 struct ab8500_gpadc *gpadc;
1868 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1869 aux2_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX2,
1870 avg_sample, trig_edge, trig_timer, conv_type);
1871 aux2_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX2,
1872 aux2_raw);
1874 seq_printf(s, "%d,0x%X\n", aux2_convert, aux2_raw);
1876 return 0;
1879 static int ab8500_gpadc_aux2_open(struct inode *inode, struct file *file)
1881 return single_open(file, ab8500_gpadc_aux2_print, inode->i_private);
1884 static const struct file_operations ab8500_gpadc_aux2_fops = {
1885 .open = ab8500_gpadc_aux2_open,
1886 .read = seq_read,
1887 .llseek = seq_lseek,
1888 .release = single_release,
1889 .owner = THIS_MODULE,
1892 static int ab8500_gpadc_main_bat_v_print(struct seq_file *s, void *p)
1894 int main_bat_v_raw;
1895 int main_bat_v_convert;
1896 struct ab8500_gpadc *gpadc;
1898 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1899 main_bat_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_BAT_V,
1900 avg_sample, trig_edge, trig_timer, conv_type);
1901 main_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V,
1902 main_bat_v_raw);
1904 seq_printf(s, "%d,0x%X\n", main_bat_v_convert, main_bat_v_raw);
1906 return 0;
1909 static int ab8500_gpadc_main_bat_v_open(struct inode *inode,
1910 struct file *file)
1912 return single_open(file, ab8500_gpadc_main_bat_v_print,
1913 inode->i_private);
1916 static const struct file_operations ab8500_gpadc_main_bat_v_fops = {
1917 .open = ab8500_gpadc_main_bat_v_open,
1918 .read = seq_read,
1919 .llseek = seq_lseek,
1920 .release = single_release,
1921 .owner = THIS_MODULE,
1924 static int ab8500_gpadc_vbus_v_print(struct seq_file *s, void *p)
1926 int vbus_v_raw;
1927 int vbus_v_convert;
1928 struct ab8500_gpadc *gpadc;
1930 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1931 vbus_v_raw = ab8500_gpadc_read_raw(gpadc, VBUS_V,
1932 avg_sample, trig_edge, trig_timer, conv_type);
1933 vbus_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, VBUS_V,
1934 vbus_v_raw);
1936 seq_printf(s, "%d,0x%X\n", vbus_v_convert, vbus_v_raw);
1938 return 0;
1941 static int ab8500_gpadc_vbus_v_open(struct inode *inode, struct file *file)
1943 return single_open(file, ab8500_gpadc_vbus_v_print, inode->i_private);
1946 static const struct file_operations ab8500_gpadc_vbus_v_fops = {
1947 .open = ab8500_gpadc_vbus_v_open,
1948 .read = seq_read,
1949 .llseek = seq_lseek,
1950 .release = single_release,
1951 .owner = THIS_MODULE,
1954 static int ab8500_gpadc_main_charger_c_print(struct seq_file *s, void *p)
1956 int main_charger_c_raw;
1957 int main_charger_c_convert;
1958 struct ab8500_gpadc *gpadc;
1960 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1961 main_charger_c_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_C,
1962 avg_sample, trig_edge, trig_timer, conv_type);
1963 main_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
1964 MAIN_CHARGER_C, main_charger_c_raw);
1966 seq_printf(s, "%d,0x%X\n", main_charger_c_convert, main_charger_c_raw);
1968 return 0;
1971 static int ab8500_gpadc_main_charger_c_open(struct inode *inode,
1972 struct file *file)
1974 return single_open(file, ab8500_gpadc_main_charger_c_print,
1975 inode->i_private);
1978 static const struct file_operations ab8500_gpadc_main_charger_c_fops = {
1979 .open = ab8500_gpadc_main_charger_c_open,
1980 .read = seq_read,
1981 .llseek = seq_lseek,
1982 .release = single_release,
1983 .owner = THIS_MODULE,
1986 static int ab8500_gpadc_usb_charger_c_print(struct seq_file *s, void *p)
1988 int usb_charger_c_raw;
1989 int usb_charger_c_convert;
1990 struct ab8500_gpadc *gpadc;
1992 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1993 usb_charger_c_raw = ab8500_gpadc_read_raw(gpadc, USB_CHARGER_C,
1994 avg_sample, trig_edge, trig_timer, conv_type);
1995 usb_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
1996 USB_CHARGER_C, usb_charger_c_raw);
1998 seq_printf(s, "%d,0x%X\n", usb_charger_c_convert, usb_charger_c_raw);
2000 return 0;
2003 static int ab8500_gpadc_usb_charger_c_open(struct inode *inode,
2004 struct file *file)
2006 return single_open(file, ab8500_gpadc_usb_charger_c_print,
2007 inode->i_private);
2010 static const struct file_operations ab8500_gpadc_usb_charger_c_fops = {
2011 .open = ab8500_gpadc_usb_charger_c_open,
2012 .read = seq_read,
2013 .llseek = seq_lseek,
2014 .release = single_release,
2015 .owner = THIS_MODULE,
2018 static int ab8500_gpadc_bk_bat_v_print(struct seq_file *s, void *p)
2020 int bk_bat_v_raw;
2021 int bk_bat_v_convert;
2022 struct ab8500_gpadc *gpadc;
2024 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2025 bk_bat_v_raw = ab8500_gpadc_read_raw(gpadc, BK_BAT_V,
2026 avg_sample, trig_edge, trig_timer, conv_type);
2027 bk_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
2028 BK_BAT_V, bk_bat_v_raw);
2030 seq_printf(s, "%d,0x%X\n", bk_bat_v_convert, bk_bat_v_raw);
2032 return 0;
2035 static int ab8500_gpadc_bk_bat_v_open(struct inode *inode, struct file *file)
2037 return single_open(file, ab8500_gpadc_bk_bat_v_print,
2038 inode->i_private);
2041 static const struct file_operations ab8500_gpadc_bk_bat_v_fops = {
2042 .open = ab8500_gpadc_bk_bat_v_open,
2043 .read = seq_read,
2044 .llseek = seq_lseek,
2045 .release = single_release,
2046 .owner = THIS_MODULE,
2049 static int ab8500_gpadc_die_temp_print(struct seq_file *s, void *p)
2051 int die_temp_raw;
2052 int die_temp_convert;
2053 struct ab8500_gpadc *gpadc;
2055 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2056 die_temp_raw = ab8500_gpadc_read_raw(gpadc, DIE_TEMP,
2057 avg_sample, trig_edge, trig_timer, conv_type);
2058 die_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, DIE_TEMP,
2059 die_temp_raw);
2061 seq_printf(s, "%d,0x%X\n", die_temp_convert, die_temp_raw);
2063 return 0;
2066 static int ab8500_gpadc_die_temp_open(struct inode *inode, struct file *file)
2068 return single_open(file, ab8500_gpadc_die_temp_print,
2069 inode->i_private);
2072 static const struct file_operations ab8500_gpadc_die_temp_fops = {
2073 .open = ab8500_gpadc_die_temp_open,
2074 .read = seq_read,
2075 .llseek = seq_lseek,
2076 .release = single_release,
2077 .owner = THIS_MODULE,
2080 static int ab8500_gpadc_usb_id_print(struct seq_file *s, void *p)
2082 int usb_id_raw;
2083 int usb_id_convert;
2084 struct ab8500_gpadc *gpadc;
2086 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2087 usb_id_raw = ab8500_gpadc_read_raw(gpadc, USB_ID,
2088 avg_sample, trig_edge, trig_timer, conv_type);
2089 usb_id_convert = ab8500_gpadc_ad_to_voltage(gpadc, USB_ID,
2090 usb_id_raw);
2092 seq_printf(s, "%d,0x%X\n", usb_id_convert, usb_id_raw);
2094 return 0;
2097 static int ab8500_gpadc_usb_id_open(struct inode *inode, struct file *file)
2099 return single_open(file, ab8500_gpadc_usb_id_print, inode->i_private);
2102 static const struct file_operations ab8500_gpadc_usb_id_fops = {
2103 .open = ab8500_gpadc_usb_id_open,
2104 .read = seq_read,
2105 .llseek = seq_lseek,
2106 .release = single_release,
2107 .owner = THIS_MODULE,
2110 static int ab8540_gpadc_xtal_temp_print(struct seq_file *s, void *p)
2112 int xtal_temp_raw;
2113 int xtal_temp_convert;
2114 struct ab8500_gpadc *gpadc;
2116 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2117 xtal_temp_raw = ab8500_gpadc_read_raw(gpadc, XTAL_TEMP,
2118 avg_sample, trig_edge, trig_timer, conv_type);
2119 xtal_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, XTAL_TEMP,
2120 xtal_temp_raw);
2122 seq_printf(s, "%d,0x%X\n", xtal_temp_convert, xtal_temp_raw);
2124 return 0;
2127 static int ab8540_gpadc_xtal_temp_open(struct inode *inode, struct file *file)
2129 return single_open(file, ab8540_gpadc_xtal_temp_print,
2130 inode->i_private);
2133 static const struct file_operations ab8540_gpadc_xtal_temp_fops = {
2134 .open = ab8540_gpadc_xtal_temp_open,
2135 .read = seq_read,
2136 .llseek = seq_lseek,
2137 .release = single_release,
2138 .owner = THIS_MODULE,
2141 static int ab8540_gpadc_vbat_true_meas_print(struct seq_file *s, void *p)
2143 int vbat_true_meas_raw;
2144 int vbat_true_meas_convert;
2145 struct ab8500_gpadc *gpadc;
2147 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2148 vbat_true_meas_raw = ab8500_gpadc_read_raw(gpadc, VBAT_TRUE_MEAS,
2149 avg_sample, trig_edge, trig_timer, conv_type);
2150 vbat_true_meas_convert =
2151 ab8500_gpadc_ad_to_voltage(gpadc, VBAT_TRUE_MEAS,
2152 vbat_true_meas_raw);
2154 seq_printf(s, "%d,0x%X\n", vbat_true_meas_convert, vbat_true_meas_raw);
2156 return 0;
2159 static int ab8540_gpadc_vbat_true_meas_open(struct inode *inode,
2160 struct file *file)
2162 return single_open(file, ab8540_gpadc_vbat_true_meas_print,
2163 inode->i_private);
2166 static const struct file_operations ab8540_gpadc_vbat_true_meas_fops = {
2167 .open = ab8540_gpadc_vbat_true_meas_open,
2168 .read = seq_read,
2169 .llseek = seq_lseek,
2170 .release = single_release,
2171 .owner = THIS_MODULE,
2174 static int ab8540_gpadc_bat_ctrl_and_ibat_print(struct seq_file *s, void *p)
2176 int bat_ctrl_raw;
2177 int bat_ctrl_convert;
2178 int ibat_raw;
2179 int ibat_convert;
2180 struct ab8500_gpadc *gpadc;
2182 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2183 bat_ctrl_raw = ab8500_gpadc_double_read_raw(gpadc, BAT_CTRL_AND_IBAT,
2184 avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
2186 bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc, BAT_CTRL,
2187 bat_ctrl_raw);
2188 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2189 ibat_raw);
2191 seq_printf(s,
2192 "%d,0x%X\n"
2193 "%d,0x%X\n",
2194 bat_ctrl_convert, bat_ctrl_raw,
2195 ibat_convert, ibat_raw);
2197 return 0;
2200 static int ab8540_gpadc_bat_ctrl_and_ibat_open(struct inode *inode,
2201 struct file *file)
2203 return single_open(file, ab8540_gpadc_bat_ctrl_and_ibat_print,
2204 inode->i_private);
2207 static const struct file_operations ab8540_gpadc_bat_ctrl_and_ibat_fops = {
2208 .open = ab8540_gpadc_bat_ctrl_and_ibat_open,
2209 .read = seq_read,
2210 .llseek = seq_lseek,
2211 .release = single_release,
2212 .owner = THIS_MODULE,
2215 static int ab8540_gpadc_vbat_meas_and_ibat_print(struct seq_file *s, void *p)
2217 int vbat_meas_raw;
2218 int vbat_meas_convert;
2219 int ibat_raw;
2220 int ibat_convert;
2221 struct ab8500_gpadc *gpadc;
2223 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2224 vbat_meas_raw = ab8500_gpadc_double_read_raw(gpadc, VBAT_MEAS_AND_IBAT,
2225 avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
2226 vbat_meas_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V,
2227 vbat_meas_raw);
2228 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2229 ibat_raw);
2231 seq_printf(s,
2232 "%d,0x%X\n"
2233 "%d,0x%X\n",
2234 vbat_meas_convert, vbat_meas_raw,
2235 ibat_convert, ibat_raw);
2237 return 0;
2240 static int ab8540_gpadc_vbat_meas_and_ibat_open(struct inode *inode,
2241 struct file *file)
2243 return single_open(file, ab8540_gpadc_vbat_meas_and_ibat_print,
2244 inode->i_private);
2247 static const struct file_operations ab8540_gpadc_vbat_meas_and_ibat_fops = {
2248 .open = ab8540_gpadc_vbat_meas_and_ibat_open,
2249 .read = seq_read,
2250 .llseek = seq_lseek,
2251 .release = single_release,
2252 .owner = THIS_MODULE,
2255 static int ab8540_gpadc_vbat_true_meas_and_ibat_print(struct seq_file *s,
2256 void *p)
2258 int vbat_true_meas_raw;
2259 int vbat_true_meas_convert;
2260 int ibat_raw;
2261 int ibat_convert;
2262 struct ab8500_gpadc *gpadc;
2264 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2265 vbat_true_meas_raw = ab8500_gpadc_double_read_raw(gpadc,
2266 VBAT_TRUE_MEAS_AND_IBAT, avg_sample, trig_edge,
2267 trig_timer, conv_type, &ibat_raw);
2268 vbat_true_meas_convert = ab8500_gpadc_ad_to_voltage(gpadc,
2269 VBAT_TRUE_MEAS, vbat_true_meas_raw);
2270 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2271 ibat_raw);
2273 seq_printf(s,
2274 "%d,0x%X\n"
2275 "%d,0x%X\n",
2276 vbat_true_meas_convert, vbat_true_meas_raw,
2277 ibat_convert, ibat_raw);
2279 return 0;
2282 static int ab8540_gpadc_vbat_true_meas_and_ibat_open(struct inode *inode,
2283 struct file *file)
2285 return single_open(file, ab8540_gpadc_vbat_true_meas_and_ibat_print,
2286 inode->i_private);
2289 static const struct file_operations
2290 ab8540_gpadc_vbat_true_meas_and_ibat_fops = {
2291 .open = ab8540_gpadc_vbat_true_meas_and_ibat_open,
2292 .read = seq_read,
2293 .llseek = seq_lseek,
2294 .release = single_release,
2295 .owner = THIS_MODULE,
2298 static int ab8540_gpadc_bat_temp_and_ibat_print(struct seq_file *s, void *p)
2300 int bat_temp_raw;
2301 int bat_temp_convert;
2302 int ibat_raw;
2303 int ibat_convert;
2304 struct ab8500_gpadc *gpadc;
2306 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2307 bat_temp_raw = ab8500_gpadc_double_read_raw(gpadc, BAT_TEMP_AND_IBAT,
2308 avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
2309 bat_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL,
2310 bat_temp_raw);
2311 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2312 ibat_raw);
2314 seq_printf(s,
2315 "%d,0x%X\n"
2316 "%d,0x%X\n",
2317 bat_temp_convert, bat_temp_raw,
2318 ibat_convert, ibat_raw);
2320 return 0;
2323 static int ab8540_gpadc_bat_temp_and_ibat_open(struct inode *inode,
2324 struct file *file)
2326 return single_open(file, ab8540_gpadc_bat_temp_and_ibat_print,
2327 inode->i_private);
2330 static const struct file_operations ab8540_gpadc_bat_temp_and_ibat_fops = {
2331 .open = ab8540_gpadc_bat_temp_and_ibat_open,
2332 .read = seq_read,
2333 .llseek = seq_lseek,
2334 .release = single_release,
2335 .owner = THIS_MODULE,
2338 static int ab8540_gpadc_otp_cal_print(struct seq_file *s, void *p)
2340 struct ab8500_gpadc *gpadc;
2341 u16 vmain_l, vmain_h, btemp_l, btemp_h;
2342 u16 vbat_l, vbat_h, ibat_l, ibat_h;
2344 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2345 ab8540_gpadc_get_otp(gpadc, &vmain_l, &vmain_h, &btemp_l, &btemp_h,
2346 &vbat_l, &vbat_h, &ibat_l, &ibat_h);
2347 seq_printf(s,
2348 "VMAIN_L:0x%X\n"
2349 "VMAIN_H:0x%X\n"
2350 "BTEMP_L:0x%X\n"
2351 "BTEMP_H:0x%X\n"
2352 "VBAT_L:0x%X\n"
2353 "VBAT_H:0x%X\n"
2354 "IBAT_L:0x%X\n"
2355 "IBAT_H:0x%X\n",
2356 vmain_l, vmain_h, btemp_l, btemp_h,
2357 vbat_l, vbat_h, ibat_l, ibat_h);
2359 return 0;
2362 static int ab8540_gpadc_otp_cal_open(struct inode *inode, struct file *file)
2364 return single_open(file, ab8540_gpadc_otp_cal_print, inode->i_private);
2367 static const struct file_operations ab8540_gpadc_otp_calib_fops = {
2368 .open = ab8540_gpadc_otp_cal_open,
2369 .read = seq_read,
2370 .llseek = seq_lseek,
2371 .release = single_release,
2372 .owner = THIS_MODULE,
2375 static int ab8500_gpadc_avg_sample_print(struct seq_file *s, void *p)
2377 seq_printf(s, "%d\n", avg_sample);
2379 return 0;
2382 static int ab8500_gpadc_avg_sample_open(struct inode *inode, struct file *file)
2384 return single_open(file, ab8500_gpadc_avg_sample_print,
2385 inode->i_private);
2388 static ssize_t ab8500_gpadc_avg_sample_write(struct file *file,
2389 const char __user *user_buf,
2390 size_t count, loff_t *ppos)
2392 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2393 unsigned long user_avg_sample;
2394 int err;
2396 err = kstrtoul_from_user(user_buf, count, 0, &user_avg_sample);
2397 if (err)
2398 return err;
2400 if ((user_avg_sample == SAMPLE_1) || (user_avg_sample == SAMPLE_4)
2401 || (user_avg_sample == SAMPLE_8)
2402 || (user_avg_sample == SAMPLE_16)) {
2403 avg_sample = (u8) user_avg_sample;
2404 } else {
2405 dev_err(dev,
2406 "debugfs err input: should be egal to 1, 4, 8 or 16\n");
2407 return -EINVAL;
2410 return count;
2413 static const struct file_operations ab8500_gpadc_avg_sample_fops = {
2414 .open = ab8500_gpadc_avg_sample_open,
2415 .read = seq_read,
2416 .write = ab8500_gpadc_avg_sample_write,
2417 .llseek = seq_lseek,
2418 .release = single_release,
2419 .owner = THIS_MODULE,
2422 static int ab8500_gpadc_trig_edge_print(struct seq_file *s, void *p)
2424 seq_printf(s, "%d\n", trig_edge);
2426 return 0;
2429 static int ab8500_gpadc_trig_edge_open(struct inode *inode, struct file *file)
2431 return single_open(file, ab8500_gpadc_trig_edge_print,
2432 inode->i_private);
2435 static ssize_t ab8500_gpadc_trig_edge_write(struct file *file,
2436 const char __user *user_buf,
2437 size_t count, loff_t *ppos)
2439 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2440 unsigned long user_trig_edge;
2441 int err;
2443 err = kstrtoul_from_user(user_buf, count, 0, &user_trig_edge);
2444 if (err)
2445 return err;
2447 if ((user_trig_edge == RISING_EDGE)
2448 || (user_trig_edge == FALLING_EDGE)) {
2449 trig_edge = (u8) user_trig_edge;
2450 } else {
2451 dev_err(dev, "Wrong input:\n"
2452 "Enter 0. Rising edge\n"
2453 "Enter 1. Falling edge\n");
2454 return -EINVAL;
2457 return count;
2460 static const struct file_operations ab8500_gpadc_trig_edge_fops = {
2461 .open = ab8500_gpadc_trig_edge_open,
2462 .read = seq_read,
2463 .write = ab8500_gpadc_trig_edge_write,
2464 .llseek = seq_lseek,
2465 .release = single_release,
2466 .owner = THIS_MODULE,
2469 static int ab8500_gpadc_trig_timer_print(struct seq_file *s, void *p)
2471 seq_printf(s, "%d\n", trig_timer);
2473 return 0;
2476 static int ab8500_gpadc_trig_timer_open(struct inode *inode, struct file *file)
2478 return single_open(file, ab8500_gpadc_trig_timer_print,
2479 inode->i_private);
2482 static ssize_t ab8500_gpadc_trig_timer_write(struct file *file,
2483 const char __user *user_buf,
2484 size_t count, loff_t *ppos)
2486 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2487 unsigned long user_trig_timer;
2488 int err;
2490 err = kstrtoul_from_user(user_buf, count, 0, &user_trig_timer);
2491 if (err)
2492 return err;
2494 if (user_trig_timer & ~0xFF) {
2495 dev_err(dev,
2496 "debugfs error input: should be between 0 to 255\n");
2497 return -EINVAL;
2500 trig_timer = (u8) user_trig_timer;
2502 return count;
2505 static const struct file_operations ab8500_gpadc_trig_timer_fops = {
2506 .open = ab8500_gpadc_trig_timer_open,
2507 .read = seq_read,
2508 .write = ab8500_gpadc_trig_timer_write,
2509 .llseek = seq_lseek,
2510 .release = single_release,
2511 .owner = THIS_MODULE,
2514 static int ab8500_gpadc_conv_type_print(struct seq_file *s, void *p)
2516 seq_printf(s, "%d\n", conv_type);
2518 return 0;
2521 static int ab8500_gpadc_conv_type_open(struct inode *inode, struct file *file)
2523 return single_open(file, ab8500_gpadc_conv_type_print,
2524 inode->i_private);
2527 static ssize_t ab8500_gpadc_conv_type_write(struct file *file,
2528 const char __user *user_buf,
2529 size_t count, loff_t *ppos)
2531 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2532 unsigned long user_conv_type;
2533 int err;
2535 err = kstrtoul_from_user(user_buf, count, 0, &user_conv_type);
2536 if (err)
2537 return err;
2539 if ((user_conv_type == ADC_SW)
2540 || (user_conv_type == ADC_HW)) {
2541 conv_type = (u8) user_conv_type;
2542 } else {
2543 dev_err(dev, "Wrong input:\n"
2544 "Enter 0. ADC SW conversion\n"
2545 "Enter 1. ADC HW conversion\n");
2546 return -EINVAL;
2549 return count;
2552 static const struct file_operations ab8500_gpadc_conv_type_fops = {
2553 .open = ab8500_gpadc_conv_type_open,
2554 .read = seq_read,
2555 .write = ab8500_gpadc_conv_type_write,
2556 .llseek = seq_lseek,
2557 .release = single_release,
2558 .owner = THIS_MODULE,
2562 * return length of an ASCII numerical value, 0 is string is not a
2563 * numerical value.
2564 * string shall start at value 1st char.
2565 * string can be tailed with \0 or space or newline chars only.
2566 * value can be decimal or hexadecimal (prefixed 0x or 0X).
2568 static int strval_len(char *b)
2570 char *s = b;
2572 if ((*s == '0') && ((*(s+1) == 'x') || (*(s+1) == 'X'))) {
2573 s += 2;
2574 for (; *s && (*s != ' ') && (*s != '\n'); s++) {
2575 if (!isxdigit(*s))
2576 return 0;
2578 } else {
2579 if (*s == '-')
2580 s++;
2581 for (; *s && (*s != ' ') && (*s != '\n'); s++) {
2582 if (!isdigit(*s))
2583 return 0;
2586 return (int) (s-b);
2590 * parse hwreg input data.
2591 * update global hwreg_cfg only if input data syntax is ok.
2593 static ssize_t hwreg_common_write(char *b, struct hwreg_cfg *cfg,
2594 struct device *dev)
2596 uint write, val = 0;
2597 u8 regvalue;
2598 int ret;
2599 struct hwreg_cfg loc = {
2600 .bank = 0, /* default: invalid phys addr */
2601 .addr = 0, /* default: invalid phys addr */
2602 .fmt = 0, /* default: 32bit access, hex output */
2603 .mask = 0xFFFFFFFF, /* default: no mask */
2604 .shift = 0, /* default: no bit shift */
2607 /* read or write ? */
2608 if (!strncmp(b, "read ", 5)) {
2609 write = 0;
2610 b += 5;
2611 } else if (!strncmp(b, "write ", 6)) {
2612 write = 1;
2613 b += 6;
2614 } else
2615 return -EINVAL;
2617 /* OPTIONS -l|-w|-b -s -m -o */
2618 while ((*b == ' ') || (*b == '-')) {
2619 if (*(b-1) != ' ') {
2620 b++;
2621 continue;
2623 if ((!strncmp(b, "-d ", 3)) ||
2624 (!strncmp(b, "-dec ", 5))) {
2625 b += (*(b+2) == ' ') ? 3 : 5;
2626 loc.fmt |= (1<<0);
2627 } else if ((!strncmp(b, "-h ", 3)) ||
2628 (!strncmp(b, "-hex ", 5))) {
2629 b += (*(b+2) == ' ') ? 3 : 5;
2630 loc.fmt &= ~(1<<0);
2631 } else if ((!strncmp(b, "-m ", 3)) ||
2632 (!strncmp(b, "-mask ", 6))) {
2633 b += (*(b+2) == ' ') ? 3 : 6;
2634 if (strval_len(b) == 0)
2635 return -EINVAL;
2636 ret = kstrtoul(b, 0, &loc.mask);
2637 if (ret)
2638 return ret;
2639 } else if ((!strncmp(b, "-s ", 3)) ||
2640 (!strncmp(b, "-shift ", 7))) {
2641 b += (*(b+2) == ' ') ? 3 : 7;
2642 if (strval_len(b) == 0)
2643 return -EINVAL;
2644 ret = kstrtol(b, 0, &loc.shift);
2645 if (ret)
2646 return ret;
2647 } else {
2648 return -EINVAL;
2651 /* get arg BANK and ADDRESS */
2652 if (strval_len(b) == 0)
2653 return -EINVAL;
2654 ret = kstrtouint(b, 0, &loc.bank);
2655 if (ret)
2656 return ret;
2657 while (*b == ' ')
2658 b++;
2659 if (strval_len(b) == 0)
2660 return -EINVAL;
2661 ret = kstrtoul(b, 0, &loc.addr);
2662 if (ret)
2663 return ret;
2665 if (write) {
2666 while (*b == ' ')
2667 b++;
2668 if (strval_len(b) == 0)
2669 return -EINVAL;
2670 ret = kstrtouint(b, 0, &val);
2671 if (ret)
2672 return ret;
2675 /* args are ok, update target cfg (mainly for read) */
2676 *cfg = loc;
2678 #ifdef ABB_HWREG_DEBUG
2679 pr_warn("HWREG request: %s, %s,\n", (write) ? "write" : "read",
2680 REG_FMT_DEC(cfg) ? "decimal" : "hexa");
2681 pr_warn(" addr=0x%08X, mask=0x%X, shift=%d" "value=0x%X\n",
2682 cfg->addr, cfg->mask, cfg->shift, val);
2683 #endif
2685 if (!write)
2686 return 0;
2688 ret = abx500_get_register_interruptible(dev,
2689 (u8)cfg->bank, (u8)cfg->addr, &regvalue);
2690 if (ret < 0) {
2691 dev_err(dev, "abx500_get_reg fail %d, %d\n",
2692 ret, __LINE__);
2693 return -EINVAL;
2696 if (cfg->shift >= 0) {
2697 regvalue &= ~(cfg->mask << (cfg->shift));
2698 val = (val & cfg->mask) << (cfg->shift);
2699 } else {
2700 regvalue &= ~(cfg->mask >> (-cfg->shift));
2701 val = (val & cfg->mask) >> (-cfg->shift);
2703 val = val | regvalue;
2705 ret = abx500_set_register_interruptible(dev,
2706 (u8)cfg->bank, (u8)cfg->addr, (u8)val);
2707 if (ret < 0) {
2708 pr_err("abx500_set_reg failed %d, %d", ret, __LINE__);
2709 return -EINVAL;
2712 return 0;
2715 static ssize_t ab8500_hwreg_write(struct file *file,
2716 const char __user *user_buf, size_t count, loff_t *ppos)
2718 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2719 char buf[128];
2720 int buf_size, ret;
2722 /* Get userspace string and assure termination */
2723 buf_size = min(count, (sizeof(buf)-1));
2724 if (copy_from_user(buf, user_buf, buf_size))
2725 return -EFAULT;
2726 buf[buf_size] = 0;
2728 /* get args and process */
2729 ret = hwreg_common_write(buf, &hwreg_cfg, dev);
2730 return (ret) ? ret : buf_size;
2734 * - irq subscribe/unsubscribe stuff
2736 static int ab8500_subscribe_unsubscribe_print(struct seq_file *s, void *p)
2738 seq_printf(s, "%d\n", irq_first);
2740 return 0;
2743 static int ab8500_subscribe_unsubscribe_open(struct inode *inode,
2744 struct file *file)
2746 return single_open(file, ab8500_subscribe_unsubscribe_print,
2747 inode->i_private);
2751 * Userspace should use poll() on this file. When an event occur
2752 * the blocking poll will be released.
2754 static ssize_t show_irq(struct device *dev,
2755 struct device_attribute *attr, char *buf)
2757 unsigned long name;
2758 unsigned int irq_index;
2759 int err;
2761 err = kstrtoul(attr->attr.name, 0, &name);
2762 if (err)
2763 return err;
2765 irq_index = name - irq_first;
2766 if (irq_index >= num_irqs)
2767 return -EINVAL;
2769 return sprintf(buf, "%u\n", irq_count[irq_index]);
2772 static ssize_t ab8500_subscribe_write(struct file *file,
2773 const char __user *user_buf,
2774 size_t count, loff_t *ppos)
2776 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2777 unsigned long user_val;
2778 int err;
2779 unsigned int irq_index;
2781 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
2782 if (err)
2783 return err;
2785 if (user_val < irq_first) {
2786 dev_err(dev, "debugfs error input < %d\n", irq_first);
2787 return -EINVAL;
2789 if (user_val > irq_last) {
2790 dev_err(dev, "debugfs error input > %d\n", irq_last);
2791 return -EINVAL;
2794 irq_index = user_val - irq_first;
2795 if (irq_index >= num_irqs)
2796 return -EINVAL;
2799 * This will create a sysfs file named <irq-nr> which userspace can
2800 * use to select or poll and get the AB8500 events
2802 dev_attr[irq_index] = kmalloc(sizeof(struct device_attribute),
2803 GFP_KERNEL);
2804 if (!dev_attr[irq_index])
2805 return -ENOMEM;
2807 event_name[irq_index] = kmalloc(count, GFP_KERNEL);
2808 if (!event_name[irq_index])
2809 return -ENOMEM;
2811 sprintf(event_name[irq_index], "%lu", user_val);
2812 dev_attr[irq_index]->show = show_irq;
2813 dev_attr[irq_index]->store = NULL;
2814 dev_attr[irq_index]->attr.name = event_name[irq_index];
2815 dev_attr[irq_index]->attr.mode = S_IRUGO;
2816 err = sysfs_create_file(&dev->kobj, &dev_attr[irq_index]->attr);
2817 if (err < 0) {
2818 pr_info("sysfs_create_file failed %d\n", err);
2819 return err;
2822 err = request_threaded_irq(user_val, NULL, ab8500_debug_handler,
2823 IRQF_SHARED | IRQF_NO_SUSPEND | IRQF_ONESHOT,
2824 "ab8500-debug", &dev->kobj);
2825 if (err < 0) {
2826 pr_info("request_threaded_irq failed %d, %lu\n",
2827 err, user_val);
2828 sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr);
2829 return err;
2832 return count;
2835 static ssize_t ab8500_unsubscribe_write(struct file *file,
2836 const char __user *user_buf,
2837 size_t count, loff_t *ppos)
2839 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2840 unsigned long user_val;
2841 int err;
2842 unsigned int irq_index;
2844 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
2845 if (err)
2846 return err;
2848 if (user_val < irq_first) {
2849 dev_err(dev, "debugfs error input < %d\n", irq_first);
2850 return -EINVAL;
2852 if (user_val > irq_last) {
2853 dev_err(dev, "debugfs error input > %d\n", irq_last);
2854 return -EINVAL;
2857 irq_index = user_val - irq_first;
2858 if (irq_index >= num_irqs)
2859 return -EINVAL;
2861 /* Set irq count to 0 when unsubscribe */
2862 irq_count[irq_index] = 0;
2864 if (dev_attr[irq_index])
2865 sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr);
2868 free_irq(user_val, &dev->kobj);
2869 kfree(event_name[irq_index]);
2870 kfree(dev_attr[irq_index]);
2872 return count;
2876 * - several deubgfs nodes fops
2879 static const struct file_operations ab8500_bank_fops = {
2880 .open = ab8500_bank_open,
2881 .write = ab8500_bank_write,
2882 .read = seq_read,
2883 .llseek = seq_lseek,
2884 .release = single_release,
2885 .owner = THIS_MODULE,
2888 static const struct file_operations ab8500_address_fops = {
2889 .open = ab8500_address_open,
2890 .write = ab8500_address_write,
2891 .read = seq_read,
2892 .llseek = seq_lseek,
2893 .release = single_release,
2894 .owner = THIS_MODULE,
2897 static const struct file_operations ab8500_val_fops = {
2898 .open = ab8500_val_open,
2899 .write = ab8500_val_write,
2900 .read = seq_read,
2901 .llseek = seq_lseek,
2902 .release = single_release,
2903 .owner = THIS_MODULE,
2906 static const struct file_operations ab8500_interrupts_fops = {
2907 .open = ab8500_interrupts_open,
2908 .read = seq_read,
2909 .llseek = seq_lseek,
2910 .release = single_release,
2911 .owner = THIS_MODULE,
2914 static const struct file_operations ab8500_subscribe_fops = {
2915 .open = ab8500_subscribe_unsubscribe_open,
2916 .write = ab8500_subscribe_write,
2917 .read = seq_read,
2918 .llseek = seq_lseek,
2919 .release = single_release,
2920 .owner = THIS_MODULE,
2923 static const struct file_operations ab8500_unsubscribe_fops = {
2924 .open = ab8500_subscribe_unsubscribe_open,
2925 .write = ab8500_unsubscribe_write,
2926 .read = seq_read,
2927 .llseek = seq_lseek,
2928 .release = single_release,
2929 .owner = THIS_MODULE,
2932 static const struct file_operations ab8500_hwreg_fops = {
2933 .open = ab8500_hwreg_open,
2934 .write = ab8500_hwreg_write,
2935 .read = seq_read,
2936 .llseek = seq_lseek,
2937 .release = single_release,
2938 .owner = THIS_MODULE,
2941 static struct dentry *ab8500_dir;
2942 static struct dentry *ab8500_gpadc_dir;
2944 static int ab8500_debug_probe(struct platform_device *plf)
2946 struct dentry *file;
2947 struct ab8500 *ab8500;
2948 struct resource *res;
2950 debug_bank = AB8500_MISC;
2951 debug_address = AB8500_REV_REG & 0x00FF;
2953 ab8500 = dev_get_drvdata(plf->dev.parent);
2954 num_irqs = ab8500->mask_size;
2956 irq_count = devm_kzalloc(&plf->dev,
2957 sizeof(*irq_count)*num_irqs, GFP_KERNEL);
2958 if (!irq_count)
2959 return -ENOMEM;
2961 dev_attr = devm_kzalloc(&plf->dev,
2962 sizeof(*dev_attr)*num_irqs, GFP_KERNEL);
2963 if (!dev_attr)
2964 return -ENOMEM;
2966 event_name = devm_kzalloc(&plf->dev,
2967 sizeof(*event_name)*num_irqs, GFP_KERNEL);
2968 if (!event_name)
2969 return -ENOMEM;
2971 res = platform_get_resource_byname(plf, 0, "IRQ_AB8500");
2972 if (!res) {
2973 dev_err(&plf->dev, "AB8500 irq not found, err %d\n", irq_first);
2974 return -ENXIO;
2976 irq_ab8500 = res->start;
2978 irq_first = platform_get_irq_byname(plf, "IRQ_FIRST");
2979 if (irq_first < 0) {
2980 dev_err(&plf->dev, "First irq not found, err %d\n", irq_first);
2981 return irq_first;
2984 irq_last = platform_get_irq_byname(plf, "IRQ_LAST");
2985 if (irq_last < 0) {
2986 dev_err(&plf->dev, "Last irq not found, err %d\n", irq_last);
2987 return irq_last;
2990 ab8500_dir = debugfs_create_dir(AB8500_NAME_STRING, NULL);
2991 if (!ab8500_dir)
2992 goto err;
2994 ab8500_gpadc_dir = debugfs_create_dir(AB8500_ADC_NAME_STRING,
2995 ab8500_dir);
2996 if (!ab8500_gpadc_dir)
2997 goto err;
2999 file = debugfs_create_file("all-bank-registers", S_IRUGO, ab8500_dir,
3000 &plf->dev, &ab8500_registers_fops);
3001 if (!file)
3002 goto err;
3004 file = debugfs_create_file("all-banks", S_IRUGO, ab8500_dir,
3005 &plf->dev, &ab8500_all_banks_fops);
3006 if (!file)
3007 goto err;
3009 file = debugfs_create_file("register-bank",
3010 (S_IRUGO | S_IWUSR | S_IWGRP),
3011 ab8500_dir, &plf->dev, &ab8500_bank_fops);
3012 if (!file)
3013 goto err;
3015 file = debugfs_create_file("register-address",
3016 (S_IRUGO | S_IWUSR | S_IWGRP),
3017 ab8500_dir, &plf->dev, &ab8500_address_fops);
3018 if (!file)
3019 goto err;
3021 file = debugfs_create_file("register-value",
3022 (S_IRUGO | S_IWUSR | S_IWGRP),
3023 ab8500_dir, &plf->dev, &ab8500_val_fops);
3024 if (!file)
3025 goto err;
3027 file = debugfs_create_file("irq-subscribe",
3028 (S_IRUGO | S_IWUSR | S_IWGRP), ab8500_dir,
3029 &plf->dev, &ab8500_subscribe_fops);
3030 if (!file)
3031 goto err;
3033 if (is_ab8500(ab8500)) {
3034 debug_ranges = ab8500_debug_ranges;
3035 num_interrupt_lines = AB8500_NR_IRQS;
3036 } else if (is_ab8505(ab8500)) {
3037 debug_ranges = ab8505_debug_ranges;
3038 num_interrupt_lines = AB8505_NR_IRQS;
3039 } else if (is_ab9540(ab8500)) {
3040 debug_ranges = ab8505_debug_ranges;
3041 num_interrupt_lines = AB9540_NR_IRQS;
3042 } else if (is_ab8540(ab8500)) {
3043 debug_ranges = ab8540_debug_ranges;
3044 num_interrupt_lines = AB8540_NR_IRQS;
3047 file = debugfs_create_file("interrupts", (S_IRUGO), ab8500_dir,
3048 &plf->dev, &ab8500_interrupts_fops);
3049 if (!file)
3050 goto err;
3052 file = debugfs_create_file("irq-unsubscribe",
3053 (S_IRUGO | S_IWUSR | S_IWGRP), ab8500_dir,
3054 &plf->dev, &ab8500_unsubscribe_fops);
3055 if (!file)
3056 goto err;
3058 file = debugfs_create_file("hwreg", (S_IRUGO | S_IWUSR | S_IWGRP),
3059 ab8500_dir, &plf->dev, &ab8500_hwreg_fops);
3060 if (!file)
3061 goto err;
3063 file = debugfs_create_file("all-modem-registers",
3064 (S_IRUGO | S_IWUSR | S_IWGRP),
3065 ab8500_dir, &plf->dev, &ab8500_modem_fops);
3066 if (!file)
3067 goto err;
3069 file = debugfs_create_file("bat_ctrl", (S_IRUGO | S_IWUSR | S_IWGRP),
3070 ab8500_gpadc_dir, &plf->dev,
3071 &ab8500_gpadc_bat_ctrl_fops);
3072 if (!file)
3073 goto err;
3075 file = debugfs_create_file("btemp_ball", (S_IRUGO | S_IWUSR | S_IWGRP),
3076 ab8500_gpadc_dir,
3077 &plf->dev, &ab8500_gpadc_btemp_ball_fops);
3078 if (!file)
3079 goto err;
3081 file = debugfs_create_file("main_charger_v",
3082 (S_IRUGO | S_IWUSR | S_IWGRP),
3083 ab8500_gpadc_dir, &plf->dev,
3084 &ab8500_gpadc_main_charger_v_fops);
3085 if (!file)
3086 goto err;
3088 file = debugfs_create_file("acc_detect1",
3089 (S_IRUGO | S_IWUSR | S_IWGRP),
3090 ab8500_gpadc_dir, &plf->dev,
3091 &ab8500_gpadc_acc_detect1_fops);
3092 if (!file)
3093 goto err;
3095 file = debugfs_create_file("acc_detect2",
3096 (S_IRUGO | S_IWUSR | S_IWGRP),
3097 ab8500_gpadc_dir, &plf->dev,
3098 &ab8500_gpadc_acc_detect2_fops);
3099 if (!file)
3100 goto err;
3102 file = debugfs_create_file("adc_aux1", (S_IRUGO | S_IWUSR | S_IWGRP),
3103 ab8500_gpadc_dir, &plf->dev,
3104 &ab8500_gpadc_aux1_fops);
3105 if (!file)
3106 goto err;
3108 file = debugfs_create_file("adc_aux2", (S_IRUGO | S_IWUSR | S_IWGRP),
3109 ab8500_gpadc_dir, &plf->dev,
3110 &ab8500_gpadc_aux2_fops);
3111 if (!file)
3112 goto err;
3114 file = debugfs_create_file("main_bat_v", (S_IRUGO | S_IWUSR | S_IWGRP),
3115 ab8500_gpadc_dir, &plf->dev,
3116 &ab8500_gpadc_main_bat_v_fops);
3117 if (!file)
3118 goto err;
3120 file = debugfs_create_file("vbus_v", (S_IRUGO | S_IWUSR | S_IWGRP),
3121 ab8500_gpadc_dir, &plf->dev,
3122 &ab8500_gpadc_vbus_v_fops);
3123 if (!file)
3124 goto err;
3126 file = debugfs_create_file("main_charger_c",
3127 (S_IRUGO | S_IWUSR | S_IWGRP),
3128 ab8500_gpadc_dir, &plf->dev,
3129 &ab8500_gpadc_main_charger_c_fops);
3130 if (!file)
3131 goto err;
3133 file = debugfs_create_file("usb_charger_c",
3134 (S_IRUGO | S_IWUSR | S_IWGRP),
3135 ab8500_gpadc_dir,
3136 &plf->dev, &ab8500_gpadc_usb_charger_c_fops);
3137 if (!file)
3138 goto err;
3140 file = debugfs_create_file("bk_bat_v", (S_IRUGO | S_IWUSR | S_IWGRP),
3141 ab8500_gpadc_dir, &plf->dev,
3142 &ab8500_gpadc_bk_bat_v_fops);
3143 if (!file)
3144 goto err;
3146 file = debugfs_create_file("die_temp", (S_IRUGO | S_IWUSR | S_IWGRP),
3147 ab8500_gpadc_dir, &plf->dev,
3148 &ab8500_gpadc_die_temp_fops);
3149 if (!file)
3150 goto err;
3152 file = debugfs_create_file("usb_id", (S_IRUGO | S_IWUSR | S_IWGRP),
3153 ab8500_gpadc_dir, &plf->dev,
3154 &ab8500_gpadc_usb_id_fops);
3155 if (!file)
3156 goto err;
3158 if (is_ab8540(ab8500)) {
3159 file = debugfs_create_file("xtal_temp",
3160 (S_IRUGO | S_IWUSR | S_IWGRP),
3161 ab8500_gpadc_dir, &plf->dev,
3162 &ab8540_gpadc_xtal_temp_fops);
3163 if (!file)
3164 goto err;
3165 file = debugfs_create_file("vbattruemeas",
3166 (S_IRUGO | S_IWUSR | S_IWGRP),
3167 ab8500_gpadc_dir, &plf->dev,
3168 &ab8540_gpadc_vbat_true_meas_fops);
3169 if (!file)
3170 goto err;
3171 file = debugfs_create_file("batctrl_and_ibat",
3172 (S_IRUGO | S_IWUGO),
3173 ab8500_gpadc_dir,
3174 &plf->dev,
3175 &ab8540_gpadc_bat_ctrl_and_ibat_fops);
3176 if (!file)
3177 goto err;
3178 file = debugfs_create_file("vbatmeas_and_ibat",
3179 (S_IRUGO | S_IWUGO),
3180 ab8500_gpadc_dir, &plf->dev,
3181 &ab8540_gpadc_vbat_meas_and_ibat_fops);
3182 if (!file)
3183 goto err;
3184 file = debugfs_create_file("vbattruemeas_and_ibat",
3185 (S_IRUGO | S_IWUGO),
3186 ab8500_gpadc_dir,
3187 &plf->dev,
3188 &ab8540_gpadc_vbat_true_meas_and_ibat_fops);
3189 if (!file)
3190 goto err;
3191 file = debugfs_create_file("battemp_and_ibat",
3192 (S_IRUGO | S_IWUGO),
3193 ab8500_gpadc_dir,
3194 &plf->dev, &ab8540_gpadc_bat_temp_and_ibat_fops);
3195 if (!file)
3196 goto err;
3197 file = debugfs_create_file("otp_calib",
3198 (S_IRUGO | S_IWUSR | S_IWGRP),
3199 ab8500_gpadc_dir,
3200 &plf->dev, &ab8540_gpadc_otp_calib_fops);
3201 if (!file)
3202 goto err;
3204 file = debugfs_create_file("avg_sample", (S_IRUGO | S_IWUSR | S_IWGRP),
3205 ab8500_gpadc_dir, &plf->dev,
3206 &ab8500_gpadc_avg_sample_fops);
3207 if (!file)
3208 goto err;
3210 file = debugfs_create_file("trig_edge", (S_IRUGO | S_IWUSR | S_IWGRP),
3211 ab8500_gpadc_dir, &plf->dev,
3212 &ab8500_gpadc_trig_edge_fops);
3213 if (!file)
3214 goto err;
3216 file = debugfs_create_file("trig_timer", (S_IRUGO | S_IWUSR | S_IWGRP),
3217 ab8500_gpadc_dir, &plf->dev,
3218 &ab8500_gpadc_trig_timer_fops);
3219 if (!file)
3220 goto err;
3222 file = debugfs_create_file("conv_type", (S_IRUGO | S_IWUSR | S_IWGRP),
3223 ab8500_gpadc_dir, &plf->dev,
3224 &ab8500_gpadc_conv_type_fops);
3225 if (!file)
3226 goto err;
3228 return 0;
3230 err:
3231 debugfs_remove_recursive(ab8500_dir);
3232 dev_err(&plf->dev, "failed to create debugfs entries.\n");
3234 return -ENOMEM;
3237 static struct platform_driver ab8500_debug_driver = {
3238 .driver = {
3239 .name = "ab8500-debug",
3240 .suppress_bind_attrs = true,
3242 .probe = ab8500_debug_probe,
3245 static int __init ab8500_debug_init(void)
3247 return platform_driver_register(&ab8500_debug_driver);
3249 subsys_initcall(ab8500_debug_init);