1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74#include <linux/seq_file.h>
75#include <linux/uaccess.h>
76#include <linux/fs.h>
77#include <linux/module.h>
78#include <linux/debugfs.h>
79#include <linux/platform_device.h>
80#include <linux/interrupt.h>
81#include <linux/kobject.h>
82#include <linux/slab.h>
83#include <linux/irq.h>
84
85#include <linux/mfd/abx500.h>
86#include <linux/mfd/abx500/ab8500.h>
87#include <linux/mfd/abx500/ab8500-gpadc.h>
88
89#ifdef CONFIG_DEBUG_FS
90#include <linux/string.h>
91#include <linux/ctype.h>
92#endif
93
94static u32 debug_bank;
95static u32 debug_address;
96
97static int irq_ab8500;
98static int irq_first;
99static int irq_last;
100static u32 *irq_count;
101static int num_irqs;
102
103static struct device_attribute **dev_attr;
104static char **event_name;
105
106static u8 avg_sample = SAMPLE_16;
107static u8 trig_edge = RISING_EDGE;
108static u8 conv_type = ADC_SW;
109static u8 trig_timer;
110
111
112
113
114
115
116
117struct ab8500_reg_range {
118 u8 first;
119 u8 last;
120 u8 perm;
121};
122
123
124
125
126
127
128
129struct ab8500_prcmu_ranges {
130 u8 num_ranges;
131 u8 bankid;
132 const struct ab8500_reg_range *range;
133};
134
135
136struct hwreg_cfg {
137 u32 bank;
138 unsigned long addr;
139 uint fmt;
140 unsigned long mask;
141 long shift;
142};
143
144#define REG_FMT_DEC(c) ((c)->fmt & 0x1)
145#define REG_FMT_HEX(c) (!REG_FMT_DEC(c))
146
147static struct hwreg_cfg hwreg_cfg = {
148 .addr = 0,
149 .fmt = 0,
150 .mask = 0xFFFFFFFF,
151 .shift = 0,
152};
153
154#define AB8500_NAME_STRING "ab8500"
155#define AB8500_ADC_NAME_STRING "gpadc"
156#define AB8500_NUM_BANKS AB8500_DEBUG_FIELD_LAST
157
158#define AB8500_REV_REG 0x80
159
160static struct ab8500_prcmu_ranges *debug_ranges;
161
162static struct ab8500_prcmu_ranges ab8500_debug_ranges[AB8500_NUM_BANKS] = {
163 [AB8500_M_FSM_RANK] = {
164 .num_ranges = 0,
165 .range = NULL,
166 },
167 [AB8500_SYS_CTRL1_BLOCK] = {
168 .num_ranges = 3,
169 .range = (struct ab8500_reg_range[]) {
170 {
171 .first = 0x00,
172 .last = 0x02,
173 },
174 {
175 .first = 0x42,
176 .last = 0x42,
177 },
178 {
179 .first = 0x80,
180 .last = 0x81,
181 },
182 },
183 },
184 [AB8500_SYS_CTRL2_BLOCK] = {
185 .num_ranges = 4,
186 .range = (struct ab8500_reg_range[]) {
187 {
188 .first = 0x00,
189 .last = 0x0D,
190 },
191 {
192 .first = 0x0F,
193 .last = 0x17,
194 },
195 {
196 .first = 0x30,
197 .last = 0x30,
198 },
199 {
200 .first = 0x32,
201 .last = 0x33,
202 },
203 },
204 },
205 [AB8500_REGU_CTRL1] = {
206 .num_ranges = 3,
207 .range = (struct ab8500_reg_range[]) {
208 {
209 .first = 0x00,
210 .last = 0x00,
211 },
212 {
213 .first = 0x03,
214 .last = 0x10,
215 },
216 {
217 .first = 0x80,
218 .last = 0x84,
219 },
220 },
221 },
222 [AB8500_REGU_CTRL2] = {
223 .num_ranges = 5,
224 .range = (struct ab8500_reg_range[]) {
225 {
226 .first = 0x00,
227 .last = 0x15,
228 },
229 {
230 .first = 0x17,
231 .last = 0x19,
232 },
233 {
234 .first = 0x1B,
235 .last = 0x1D,
236 },
237 {
238 .first = 0x1F,
239 .last = 0x22,
240 },
241 {
242 .first = 0x40,
243 .last = 0x44,
244 },
245
246
247
248
249 },
250 },
251 [AB8500_USB] = {
252 .num_ranges = 2,
253 .range = (struct ab8500_reg_range[]) {
254 {
255 .first = 0x80,
256 .last = 0x83,
257 },
258 {
259 .first = 0x87,
260 .last = 0x8A,
261 },
262 },
263 },
264 [AB8500_TVOUT] = {
265 .num_ranges = 9,
266 .range = (struct ab8500_reg_range[]) {
267 {
268 .first = 0x00,
269 .last = 0x12,
270 },
271 {
272 .first = 0x15,
273 .last = 0x17,
274 },
275 {
276 .first = 0x19,
277 .last = 0x21,
278 },
279 {
280 .first = 0x27,
281 .last = 0x2C,
282 },
283 {
284 .first = 0x41,
285 .last = 0x41,
286 },
287 {
288 .first = 0x45,
289 .last = 0x5B,
290 },
291 {
292 .first = 0x5D,
293 .last = 0x5D,
294 },
295 {
296 .first = 0x69,
297 .last = 0x69,
298 },
299 {
300 .first = 0x80,
301 .last = 0x81,
302 },
303 },
304 },
305 [AB8500_DBI] = {
306 .num_ranges = 0,
307 .range = NULL,
308 },
309 [AB8500_ECI_AV_ACC] = {
310 .num_ranges = 1,
311 .range = (struct ab8500_reg_range[]) {
312 {
313 .first = 0x80,
314 .last = 0x82,
315 },
316 },
317 },
318 [AB8500_RESERVED] = {
319 .num_ranges = 0,
320 .range = NULL,
321 },
322 [AB8500_GPADC] = {
323 .num_ranges = 1,
324 .range = (struct ab8500_reg_range[]) {
325 {
326 .first = 0x00,
327 .last = 0x08,
328 },
329 },
330 },
331 [AB8500_CHARGER] = {
332 .num_ranges = 9,
333 .range = (struct ab8500_reg_range[]) {
334 {
335 .first = 0x00,
336 .last = 0x03,
337 },
338 {
339 .first = 0x05,
340 .last = 0x05,
341 },
342 {
343 .first = 0x40,
344 .last = 0x40,
345 },
346 {
347 .first = 0x42,
348 .last = 0x42,
349 },
350 {
351 .first = 0x44,
352 .last = 0x44,
353 },
354 {
355 .first = 0x50,
356 .last = 0x55,
357 },
358 {
359 .first = 0x80,
360 .last = 0x82,
361 },
362 {
363 .first = 0xC0,
364 .last = 0xC2,
365 },
366 {
367 .first = 0xf5,
368 .last = 0xf6,
369 },
370 },
371 },
372 [AB8500_GAS_GAUGE] = {
373 .num_ranges = 3,
374 .range = (struct ab8500_reg_range[]) {
375 {
376 .first = 0x00,
377 .last = 0x00,
378 },
379 {
380 .first = 0x07,
381 .last = 0x0A,
382 },
383 {
384 .first = 0x10,
385 .last = 0x14,
386 },
387 },
388 },
389 [AB8500_AUDIO] = {
390 .num_ranges = 1,
391 .range = (struct ab8500_reg_range[]) {
392 {
393 .first = 0x00,
394 .last = 0x6F,
395 },
396 },
397 },
398 [AB8500_INTERRUPT] = {
399 .num_ranges = 0,
400 .range = NULL,
401 },
402 [AB8500_RTC] = {
403 .num_ranges = 1,
404 .range = (struct ab8500_reg_range[]) {
405 {
406 .first = 0x00,
407 .last = 0x0F,
408 },
409 },
410 },
411 [AB8500_MISC] = {
412 .num_ranges = 8,
413 .range = (struct ab8500_reg_range[]) {
414 {
415 .first = 0x00,
416 .last = 0x05,
417 },
418 {
419 .first = 0x10,
420 .last = 0x15,
421 },
422 {
423 .first = 0x20,
424 .last = 0x25,
425 },
426 {
427 .first = 0x30,
428 .last = 0x35,
429 },
430 {
431 .first = 0x40,
432 .last = 0x45,
433 },
434 {
435 .first = 0x50,
436 .last = 0x50,
437 },
438 {
439 .first = 0x60,
440 .last = 0x67,
441 },
442 {
443 .first = 0x80,
444 .last = 0x80,
445 },
446 },
447 },
448 [AB8500_DEVELOPMENT] = {
449 .num_ranges = 1,
450 .range = (struct ab8500_reg_range[]) {
451 {
452 .first = 0x00,
453 .last = 0x00,
454 },
455 },
456 },
457 [AB8500_DEBUG] = {
458 .num_ranges = 1,
459 .range = (struct ab8500_reg_range[]) {
460 {
461 .first = 0x05,
462 .last = 0x07,
463 },
464 },
465 },
466 [AB8500_PROD_TEST] = {
467 .num_ranges = 0,
468 .range = NULL,
469 },
470 [AB8500_STE_TEST] = {
471 .num_ranges = 0,
472 .range = NULL,
473 },
474 [AB8500_OTP_EMUL] = {
475 .num_ranges = 1,
476 .range = (struct ab8500_reg_range[]) {
477 {
478 .first = 0x01,
479 .last = 0x0F,
480 },
481 },
482 },
483};
484
485static struct ab8500_prcmu_ranges ab8505_debug_ranges[AB8500_NUM_BANKS] = {
486 [0x0] = {
487 .num_ranges = 0,
488 .range = NULL,
489 },
490 [AB8500_SYS_CTRL1_BLOCK] = {
491 .num_ranges = 5,
492 .range = (struct ab8500_reg_range[]) {
493 {
494 .first = 0x00,
495 .last = 0x04,
496 },
497 {
498 .first = 0x42,
499 .last = 0x42,
500 },
501 {
502 .first = 0x52,
503 .last = 0x52,
504 },
505 {
506 .first = 0x54,
507 .last = 0x57,
508 },
509 {
510 .first = 0x80,
511 .last = 0x83,
512 },
513 },
514 },
515 [AB8500_SYS_CTRL2_BLOCK] = {
516 .num_ranges = 5,
517 .range = (struct ab8500_reg_range[]) {
518 {
519 .first = 0x00,
520 .last = 0x0D,
521 },
522 {
523 .first = 0x0F,
524 .last = 0x17,
525 },
526 {
527 .first = 0x20,
528 .last = 0x20,
529 },
530 {
531 .first = 0x30,
532 .last = 0x30,
533 },
534 {
535 .first = 0x32,
536 .last = 0x3A,
537 },
538 },
539 },
540 [AB8500_REGU_CTRL1] = {
541 .num_ranges = 3,
542 .range = (struct ab8500_reg_range[]) {
543 {
544 .first = 0x00,
545 .last = 0x00,
546 },
547 {
548 .first = 0x03,
549 .last = 0x11,
550 },
551 {
552 .first = 0x80,
553 .last = 0x86,
554 },
555 },
556 },
557 [AB8500_REGU_CTRL2] = {
558 .num_ranges = 6,
559 .range = (struct ab8500_reg_range[]) {
560 {
561 .first = 0x00,
562 .last = 0x06,
563 },
564 {
565 .first = 0x08,
566 .last = 0x15,
567 },
568 {
569 .first = 0x17,
570 .last = 0x19,
571 },
572 {
573 .first = 0x1B,
574 .last = 0x1D,
575 },
576 {
577 .first = 0x1F,
578 .last = 0x30,
579 },
580 {
581 .first = 0x40,
582 .last = 0x48,
583 },
584
585
586
587
588 },
589 },
590 [AB8500_USB] = {
591 .num_ranges = 3,
592 .range = (struct ab8500_reg_range[]) {
593 {
594 .first = 0x80,
595 .last = 0x83,
596 },
597 {
598 .first = 0x87,
599 .last = 0x8A,
600 },
601 {
602 .first = 0x91,
603 .last = 0x94,
604 },
605 },
606 },
607 [AB8500_TVOUT] = {
608 .num_ranges = 0,
609 .range = NULL,
610 },
611 [AB8500_DBI] = {
612 .num_ranges = 0,
613 .range = NULL,
614 },
615 [AB8500_ECI_AV_ACC] = {
616 .num_ranges = 1,
617 .range = (struct ab8500_reg_range[]) {
618 {
619 .first = 0x80,
620 .last = 0x82,
621 },
622 },
623 },
624 [AB8500_RESERVED] = {
625 .num_ranges = 0,
626 .range = NULL,
627 },
628 [AB8500_GPADC] = {
629 .num_ranges = 1,
630 .range = (struct ab8500_reg_range[]) {
631 {
632 .first = 0x00,
633 .last = 0x08,
634 },
635 },
636 },
637 [AB8500_CHARGER] = {
638 .num_ranges = 9,
639 .range = (struct ab8500_reg_range[]) {
640 {
641 .first = 0x02,
642 .last = 0x03,
643 },
644 {
645 .first = 0x05,
646 .last = 0x05,
647 },
648 {
649 .first = 0x40,
650 .last = 0x44,
651 },
652 {
653 .first = 0x50,
654 .last = 0x57,
655 },
656 {
657 .first = 0x60,
658 .last = 0x60,
659 },
660 {
661 .first = 0xA0,
662 .last = 0xA7,
663 },
664 {
665 .first = 0xAF,
666 .last = 0xB2,
667 },
668 {
669 .first = 0xC0,
670 .last = 0xC2,
671 },
672 {
673 .first = 0xF5,
674 .last = 0xF5,
675 },
676 },
677 },
678 [AB8500_GAS_GAUGE] = {
679 .num_ranges = 3,
680 .range = (struct ab8500_reg_range[]) {
681 {
682 .first = 0x00,
683 .last = 0x00,
684 },
685 {
686 .first = 0x07,
687 .last = 0x0A,
688 },
689 {
690 .first = 0x10,
691 .last = 0x14,
692 },
693 },
694 },
695 [AB8500_AUDIO] = {
696 .num_ranges = 1,
697 .range = (struct ab8500_reg_range[]) {
698 {
699 .first = 0x00,
700 .last = 0x83,
701 },
702 },
703 },
704 [AB8500_INTERRUPT] = {
705 .num_ranges = 11,
706 .range = (struct ab8500_reg_range[]) {
707 {
708 .first = 0x00,
709 .last = 0x04,
710 },
711 {
712 .first = 0x06,
713 .last = 0x07,
714 },
715 {
716 .first = 0x09,
717 .last = 0x09,
718 },
719 {
720 .first = 0x0B,
721 .last = 0x0C,
722 },
723 {
724 .first = 0x12,
725 .last = 0x15,
726 },
727 {
728 .first = 0x18,
729 .last = 0x18,
730 },
731
732 {
733 .first = 0x40,
734 .last = 0x44,
735 },
736 {
737 .first = 0x46,
738 .last = 0x49,
739 },
740 {
741 .first = 0x4B,
742 .last = 0x4D,
743 },
744 {
745 .first = 0x52,
746 .last = 0x55,
747 },
748 {
749 .first = 0x58,
750 .last = 0x58,
751 },
752
753 },
754 },
755 [AB8500_RTC] = {
756 .num_ranges = 2,
757 .range = (struct ab8500_reg_range[]) {
758 {
759 .first = 0x00,
760 .last = 0x14,
761 },
762 {
763 .first = 0x16,
764 .last = 0x17,
765 },
766 },
767 },
768 [AB8500_MISC] = {
769 .num_ranges = 8,
770 .range = (struct ab8500_reg_range[]) {
771 {
772 .first = 0x00,
773 .last = 0x06,
774 },
775 {
776 .first = 0x10,
777 .last = 0x16,
778 },
779 {
780 .first = 0x20,
781 .last = 0x26,
782 },
783 {
784 .first = 0x30,
785 .last = 0x36,
786 },
787 {
788 .first = 0x40,
789 .last = 0x46,
790 },
791 {
792 .first = 0x50,
793 .last = 0x50,
794 },
795 {
796 .first = 0x60,
797 .last = 0x6B,
798 },
799 {
800 .first = 0x80,
801 .last = 0x82,
802 },
803 },
804 },
805 [AB8500_DEVELOPMENT] = {
806 .num_ranges = 2,
807 .range = (struct ab8500_reg_range[]) {
808 {
809 .first = 0x00,
810 .last = 0x00,
811 },
812 {
813 .first = 0x05,
814 .last = 0x05,
815 },
816 },
817 },
818 [AB8500_DEBUG] = {
819 .num_ranges = 1,
820 .range = (struct ab8500_reg_range[]) {
821 {
822 .first = 0x05,
823 .last = 0x07,
824 },
825 },
826 },
827 [AB8500_PROD_TEST] = {
828 .num_ranges = 0,
829 .range = NULL,
830 },
831 [AB8500_STE_TEST] = {
832 .num_ranges = 0,
833 .range = NULL,
834 },
835 [AB8500_OTP_EMUL] = {
836 .num_ranges = 1,
837 .range = (struct ab8500_reg_range[]) {
838 {
839 .first = 0x01,
840 .last = 0x15,
841 },
842 },
843 },
844};
845
846static 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[]) {
850 {
851 .first = 0x00,
852 .last = 0x0B,
853 },
854 },
855 },
856 [AB8500_SYS_CTRL1_BLOCK] = {
857 .num_ranges = 6,
858 .range = (struct ab8500_reg_range[]) {
859 {
860 .first = 0x00,
861 .last = 0x04,
862 },
863 {
864 .first = 0x42,
865 .last = 0x42,
866 },
867 {
868 .first = 0x50,
869 .last = 0x54,
870 },
871 {
872 .first = 0x57,
873 .last = 0x57,
874 },
875 {
876 .first = 0x80,
877 .last = 0x83,
878 },
879 {
880 .first = 0x90,
881 .last = 0x90,
882 },
883 },
884 },
885 [AB8500_SYS_CTRL2_BLOCK] = {
886 .num_ranges = 5,
887 .range = (struct ab8500_reg_range[]) {
888 {
889 .first = 0x00,
890 .last = 0x0D,
891 },
892 {
893 .first = 0x0F,
894 .last = 0x10,
895 },
896 {
897 .first = 0x20,
898 .last = 0x21,
899 },
900 {
901 .first = 0x32,
902 .last = 0x3C,
903 },
904 {
905 .first = 0x40,
906 .last = 0x42,
907 },
908 },
909 },
910 [AB8500_REGU_CTRL1] = {
911 .num_ranges = 4,
912 .range = (struct ab8500_reg_range[]) {
913 {
914 .first = 0x03,
915 .last = 0x15,
916 },
917 {
918 .first = 0x20,
919 .last = 0x20,
920 },
921 {
922 .first = 0x80,
923 .last = 0x85,
924 },
925 {
926 .first = 0x87,
927 .last = 0x88,
928 },
929 },
930 },
931 [AB8500_REGU_CTRL2] = {
932 .num_ranges = 8,
933 .range = (struct ab8500_reg_range[]) {
934 {
935 .first = 0x00,
936 .last = 0x06,
937 },
938 {
939 .first = 0x08,
940 .last = 0x15,
941 },
942 {
943 .first = 0x17,
944 .last = 0x19,
945 },
946 {
947 .first = 0x1B,
948 .last = 0x1D,
949 },
950 {
951 .first = 0x1F,
952 .last = 0x2F,
953 },
954 {
955 .first = 0x31,
956 .last = 0x3A,
957 },
958 {
959 .first = 0x43,
960 .last = 0x44,
961 },
962 {
963 .first = 0x48,
964 .last = 0x49,
965 },
966 },
967 },
968 [AB8500_USB] = {
969 .num_ranges = 3,
970 .range = (struct ab8500_reg_range[]) {
971 {
972 .first = 0x80,
973 .last = 0x83,
974 },
975 {
976 .first = 0x87,
977 .last = 0x8A,
978 },
979 {
980 .first = 0x91,
981 .last = 0x94,
982 },
983 },
984 },
985 [AB8500_TVOUT] = {
986 .num_ranges = 0,
987 .range = NULL
988 },
989 [AB8500_DBI] = {
990 .num_ranges = 4,
991 .range = (struct ab8500_reg_range[]) {
992 {
993 .first = 0x00,
994 .last = 0x07,
995 },
996 {
997 .first = 0x10,
998 .last = 0x11,
999 },
1000 {
1001 .first = 0x20,
1002 .last = 0x21,
1003 },
1004 {
1005 .first = 0x30,
1006 .last = 0x43,
1007 },
1008 },
1009 },
1010 [AB8500_ECI_AV_ACC] = {
1011 .num_ranges = 2,
1012 .range = (struct ab8500_reg_range[]) {
1013 {
1014 .first = 0x00,
1015 .last = 0x03,
1016 },
1017 {
1018 .first = 0x80,
1019 .last = 0x82,
1020 },
1021 },
1022 },
1023 [AB8500_RESERVED] = {
1024 .num_ranges = 0,
1025 .range = NULL,
1026 },
1027 [AB8500_GPADC] = {
1028 .num_ranges = 4,
1029 .range = (struct ab8500_reg_range[]) {
1030 {
1031 .first = 0x00,
1032 .last = 0x01,
1033 },
1034 {
1035 .first = 0x04,
1036 .last = 0x06,
1037 },
1038 {
1039 .first = 0x09,
1040 .last = 0x0A,
1041 },
1042 {
1043 .first = 0x10,
1044 .last = 0x14,
1045 },
1046 },
1047 },
1048 [AB8500_CHARGER] = {
1049 .num_ranges = 10,
1050 .range = (struct ab8500_reg_range[]) {
1051 {
1052 .first = 0x00,
1053 .last = 0x00,
1054 },
1055 {
1056 .first = 0x02,
1057 .last = 0x05,
1058 },
1059 {
1060 .first = 0x40,
1061 .last = 0x44,
1062 },
1063 {
1064 .first = 0x50,
1065 .last = 0x57,
1066 },
1067 {
1068 .first = 0x60,
1069 .last = 0x60,
1070 },
1071 {
1072 .first = 0x70,
1073 .last = 0x70,
1074 },
1075 {
1076 .first = 0xA0,
1077 .last = 0xA9,
1078 },
1079 {
1080 .first = 0xAF,
1081 .last = 0xB2,
1082 },
1083 {
1084 .first = 0xC0,
1085 .last = 0xC6,
1086 },
1087 {
1088 .first = 0xF5,
1089 .last = 0xF5,
1090 },
1091 },
1092 },
1093 [AB8500_GAS_GAUGE] = {
1094 .num_ranges = 3,
1095 .range = (struct ab8500_reg_range[]) {
1096 {
1097 .first = 0x00,
1098 .last = 0x00,
1099 },
1100 {
1101 .first = 0x07,
1102 .last = 0x0A,
1103 },
1104 {
1105 .first = 0x10,
1106 .last = 0x14,
1107 },
1108 },
1109 },
1110 [AB8500_AUDIO] = {
1111 .num_ranges = 1,
1112 .range = (struct ab8500_reg_range[]) {
1113 {
1114 .first = 0x00,
1115 .last = 0x9f,
1116 },
1117 },
1118 },
1119 [AB8500_INTERRUPT] = {
1120 .num_ranges = 6,
1121 .range = (struct ab8500_reg_range[]) {
1122 {
1123 .first = 0x00,
1124 .last = 0x05,
1125 },
1126 {
1127 .first = 0x0B,
1128 .last = 0x0D,
1129 },
1130 {
1131 .first = 0x12,
1132 .last = 0x20,
1133 },
1134
1135 {
1136 .first = 0x40,
1137 .last = 0x45,
1138 },
1139 {
1140 .first = 0x4B,
1141 .last = 0x4D,
1142 },
1143 {
1144 .first = 0x52,
1145 .last = 0x60,
1146 },
1147
1148 },
1149 },
1150 [AB8500_RTC] = {
1151 .num_ranges = 3,
1152 .range = (struct ab8500_reg_range[]) {
1153 {
1154 .first = 0x00,
1155 .last = 0x07,
1156 },
1157 {
1158 .first = 0x0B,
1159 .last = 0x18,
1160 },
1161 {
1162 .first = 0x20,
1163 .last = 0x25,
1164 },
1165 },
1166 },
1167 [AB8500_MISC] = {
1168 .num_ranges = 9,
1169 .range = (struct ab8500_reg_range[]) {
1170 {
1171 .first = 0x00,
1172 .last = 0x06,
1173 },
1174 {
1175 .first = 0x10,
1176 .last = 0x16,
1177 },
1178 {
1179 .first = 0x20,
1180 .last = 0x26,
1181 },
1182 {
1183 .first = 0x30,
1184 .last = 0x36,
1185 },
1186 {
1187 .first = 0x40,
1188 .last = 0x49,
1189 },
1190 {
1191 .first = 0x50,
1192 .last = 0x50,
1193 },
1194 {
1195 .first = 0x60,
1196 .last = 0x6B,
1197 },
1198 {
1199 .first = 0x70,
1200 .last = 0x74,
1201 },
1202 {
1203 .first = 0x80,
1204 .last = 0x82,
1205 },
1206 },
1207 },
1208 [AB8500_DEVELOPMENT] = {
1209 .num_ranges = 3,
1210 .range = (struct ab8500_reg_range[]) {
1211 {
1212 .first = 0x00,
1213 .last = 0x01,
1214 },
1215 {
1216 .first = 0x06,
1217 .last = 0x06,
1218 },
1219 {
1220 .first = 0x10,
1221 .last = 0x21,
1222 },
1223 },
1224 },
1225 [AB8500_DEBUG] = {
1226 .num_ranges = 3,
1227 .range = (struct ab8500_reg_range[]) {
1228 {
1229 .first = 0x01,
1230 .last = 0x0C,
1231 },
1232 {
1233 .first = 0x0E,
1234 .last = 0x11,
1235 },
1236 {
1237 .first = 0x80,
1238 .last = 0x81,
1239 },
1240 },
1241 },
1242 [AB8500_PROD_TEST] = {
1243 .num_ranges = 0,
1244 .range = NULL,
1245 },
1246 [AB8500_STE_TEST] = {
1247 .num_ranges = 0,
1248 .range = NULL,
1249 },
1250 [AB8500_OTP_EMUL] = {
1251 .num_ranges = 1,
1252 .range = (struct ab8500_reg_range[]) {
1253 {
1254 .first = 0x00,
1255 .last = 0x3F,
1256 },
1257 },
1258 },
1259};
1260
1261
1262static irqreturn_t ab8500_debug_handler(int irq, void *data)
1263{
1264 char buf[16];
1265 struct kobject *kobj = (struct kobject *)data;
1266 unsigned int irq_abb = irq - irq_first;
1267
1268 if (irq_abb < num_irqs)
1269 irq_count[irq_abb]++;
1270
1271
1272
1273
1274 sprintf(buf, "%d", irq);
1275 sysfs_notify(kobj, NULL, buf);
1276
1277 return IRQ_HANDLED;
1278}
1279
1280
1281static int ab8500_registers_print(struct device *dev, u32 bank,
1282 struct seq_file *s)
1283{
1284 unsigned int i;
1285
1286 for (i = 0; i < debug_ranges[bank].num_ranges; i++) {
1287 u32 reg;
1288
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;
1294
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;
1300 }
1301
1302 if (s) {
1303 seq_printf(s, " [0x%02X/0x%02X]: 0x%02X\n",
1304 bank, reg, value);
1305
1306
1307
1308
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);
1314 }
1315 }
1316 }
1317
1318 return 0;
1319}
1320
1321static int ab8500_print_bank_registers(struct seq_file *s, void *p)
1322{
1323 struct device *dev = s->private;
1324 u32 bank = debug_bank;
1325
1326 seq_puts(s, AB8500_NAME_STRING " register values:\n");
1327
1328 seq_printf(s, " bank 0x%02X:\n", bank);
1329
1330 return ab8500_registers_print(dev, bank, s);
1331}
1332
1333static int ab8500_registers_open(struct inode *inode, struct file *file)
1334{
1335 return single_open(file, ab8500_print_bank_registers, inode->i_private);
1336}
1337
1338static 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,
1344};
1345
1346static int ab8500_print_all_banks(struct seq_file *s, void *p)
1347{
1348 struct device *dev = s->private;
1349 unsigned int i;
1350
1351 seq_puts(s, AB8500_NAME_STRING " register values:\n");
1352
1353 for (i = 0; i < AB8500_NUM_BANKS; i++) {
1354 int err;
1355
1356 seq_printf(s, " bank 0x%02X:\n", i);
1357 err = ab8500_registers_print(dev, i, s);
1358 if (err)
1359 return err;
1360 }
1361 return 0;
1362}
1363
1364
1365void ab8500_dump_all_banks(struct device *dev)
1366{
1367 unsigned int i;
1368
1369 dev_info(dev, "ab8500 register values:\n");
1370
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);
1374 }
1375}
1376
1377static int ab8500_all_banks_open(struct inode *inode, struct file *file)
1378{
1379 struct seq_file *s;
1380 int err;
1381
1382 err = single_open(file, ab8500_print_all_banks, inode->i_private);
1383 if (!err) {
1384
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;
1391 }
1392 }
1393 return err;
1394}
1395
1396static 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,
1402};
1403
1404static int ab8500_bank_print(struct seq_file *s, void *p)
1405{
1406 seq_printf(s, "0x%02X\n", debug_bank);
1407 return 0;
1408}
1409
1410static int ab8500_bank_open(struct inode *inode, struct file *file)
1411{
1412 return single_open(file, ab8500_bank_print, inode->i_private);
1413}
1414
1415static ssize_t ab8500_bank_write(struct file *file,
1416 const char __user *user_buf,
1417 size_t count, loff_t *ppos)
1418{
1419 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1420 unsigned long user_bank;
1421 int err;
1422
1423 err = kstrtoul_from_user(user_buf, count, 0, &user_bank);
1424 if (err)
1425 return err;
1426
1427 if (user_bank >= AB8500_NUM_BANKS) {
1428 dev_err(dev, "debugfs error input > number of banks\n");
1429 return -EINVAL;
1430 }
1431
1432 debug_bank = user_bank;
1433
1434 return count;
1435}
1436
1437static int ab8500_address_print(struct seq_file *s, void *p)
1438{
1439 seq_printf(s, "0x%02X\n", debug_address);
1440 return 0;
1441}
1442
1443static int ab8500_address_open(struct inode *inode, struct file *file)
1444{
1445 return single_open(file, ab8500_address_print, inode->i_private);
1446}
1447
1448static ssize_t ab8500_address_write(struct file *file,
1449 const char __user *user_buf,
1450 size_t count, loff_t *ppos)
1451{
1452 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1453 unsigned long user_address;
1454 int err;
1455
1456 err = kstrtoul_from_user(user_buf, count, 0, &user_address);
1457 if (err)
1458 return err;
1459
1460 if (user_address > 0xff) {
1461 dev_err(dev, "debugfs error input > 0xff\n");
1462 return -EINVAL;
1463 }
1464 debug_address = user_address;
1465
1466 return count;
1467}
1468
1469static int ab8500_val_print(struct seq_file *s, void *p)
1470{
1471 struct device *dev = s->private;
1472 int ret;
1473 u8 regvalue;
1474
1475 ret = abx500_get_register_interruptible(dev,
1476 (u8)debug_bank, (u8)debug_address, ®value);
1477 if (ret < 0) {
1478 dev_err(dev, "abx500_get_reg fail %d, %d\n",
1479 ret, __LINE__);
1480 return -EINVAL;
1481 }
1482 seq_printf(s, "0x%02X\n", regvalue);
1483
1484 return 0;
1485}
1486
1487static int ab8500_val_open(struct inode *inode, struct file *file)
1488{
1489 return single_open(file, ab8500_val_print, inode->i_private);
1490}
1491
1492static ssize_t ab8500_val_write(struct file *file,
1493 const char __user *user_buf,
1494 size_t count, loff_t *ppos)
1495{
1496 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1497 unsigned long user_val;
1498 int err;
1499
1500 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
1501 if (err)
1502 return err;
1503
1504 if (user_val > 0xff) {
1505 dev_err(dev, "debugfs error input > 0xff\n");
1506 return -EINVAL;
1507 }
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;
1513 }
1514
1515 return count;
1516}
1517
1518
1519
1520
1521static u32 num_interrupts[AB8500_MAX_NR_IRQS];
1522static u32 num_wake_interrupts[AB8500_MAX_NR_IRQS];
1523static int num_interrupt_lines;
1524
1525void ab8500_debug_register_interrupt(int line)
1526{
1527 if (line < num_interrupt_lines)
1528 num_interrupts[line]++;
1529}
1530
1531static int ab8500_interrupts_print(struct seq_file *s, void *p)
1532{
1533 int line;
1534
1535 seq_puts(s, "name: number: number of: wake:\n");
1536
1537 for (line = 0; line < num_interrupt_lines; line++) {
1538 struct irq_desc *desc = irq_to_desc(line + irq_first);
1539
1540 seq_printf(s, "%3i: %6i %4i",
1541 line,
1542 num_interrupts[line],
1543 num_wake_interrupts[line]);
1544
1545 if (desc && desc->name)
1546 seq_printf(s, "-%-8s", desc->name);
1547 if (desc && desc->action) {
1548 struct irqaction *action = desc->action;
1549
1550 seq_printf(s, " %s", action->name);
1551 while ((action = action->next) != NULL)
1552 seq_printf(s, ", %s", action->name);
1553 }
1554 seq_putc(s, '\n');
1555 }
1556
1557 return 0;
1558}
1559
1560static int ab8500_interrupts_open(struct inode *inode, struct file *file)
1561{
1562 return single_open(file, ab8500_interrupts_print, inode->i_private);
1563}
1564
1565
1566
1567
1568static int ab8500_hwreg_print(struct seq_file *s, void *d)
1569{
1570 struct device *dev = s->private;
1571 int ret;
1572 u8 regvalue;
1573
1574 ret = abx500_get_register_interruptible(dev,
1575 (u8)hwreg_cfg.bank, (u8)hwreg_cfg.addr, ®value);
1576 if (ret < 0) {
1577 dev_err(dev, "abx500_get_reg fail %d, %d\n",
1578 ret, __LINE__);
1579 return -EINVAL;
1580 }
1581
1582 if (hwreg_cfg.shift >= 0)
1583 regvalue >>= hwreg_cfg.shift;
1584 else
1585 regvalue <<= -hwreg_cfg.shift;
1586 regvalue &= hwreg_cfg.mask;
1587
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;
1593}
1594
1595static int ab8500_hwreg_open(struct inode *inode, struct file *file)
1596{
1597 return single_open(file, ab8500_hwreg_print, inode->i_private);
1598}
1599
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
1605
1606static int ab8500_print_modem_registers(struct seq_file *s, void *p)
1607{
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;
1616
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");
1620
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;
1626 }
1627
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;
1634 }
1635
1636 seq_printf(s, " bank 0x%02X:\n", bank);
1637
1638 if (is_ab9540(ab8500) || is_ab8505(ab8500))
1639 last_sim_reg = AB8505_LAST_SIM_REG;
1640
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;
1647 }
1648 seq_printf(s, " [0x%02X/0x%02X]: 0x%02X\n", bank, reg, value);
1649 }
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;
1655 }
1656 return 0;
1657}
1658
1659static int ab8500_modem_open(struct inode *inode, struct file *file)
1660{
1661 return single_open(file, ab8500_print_modem_registers,
1662 inode->i_private);
1663}
1664
1665static 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,
1671};
1672
1673static int ab8500_gpadc_bat_ctrl_print(struct seq_file *s, void *p)
1674{
1675 int bat_ctrl_raw;
1676 int bat_ctrl_convert;
1677 struct ab8500_gpadc *gpadc;
1678
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);
1684
1685 seq_printf(s, "%d,0x%X\n", bat_ctrl_convert, bat_ctrl_raw);
1686
1687 return 0;
1688}
1689
1690static int ab8500_gpadc_bat_ctrl_open(struct inode *inode, struct file *file)
1691{
1692 return single_open(file, ab8500_gpadc_bat_ctrl_print,
1693 inode->i_private);
1694}
1695
1696static 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,
1702};
1703
1704static int ab8500_gpadc_btemp_ball_print(struct seq_file *s, void *p)
1705{
1706 int btemp_ball_raw;
1707 int btemp_ball_convert;
1708 struct ab8500_gpadc *gpadc;
1709
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);
1715
1716 seq_printf(s, "%d,0x%X\n", btemp_ball_convert, btemp_ball_raw);
1717
1718 return 0;
1719}
1720
1721static int ab8500_gpadc_btemp_ball_open(struct inode *inode,
1722 struct file *file)
1723{
1724 return single_open(file, ab8500_gpadc_btemp_ball_print,
1725 inode->i_private);
1726}
1727
1728static 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,
1734};
1735
1736static int ab8500_gpadc_main_charger_v_print(struct seq_file *s, void *p)
1737{
1738 int main_charger_v_raw;
1739 int main_charger_v_convert;
1740 struct ab8500_gpadc *gpadc;
1741
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);
1747
1748 seq_printf(s, "%d,0x%X\n", main_charger_v_convert, main_charger_v_raw);
1749
1750 return 0;
1751}
1752
1753static int ab8500_gpadc_main_charger_v_open(struct inode *inode,
1754 struct file *file)
1755{
1756 return single_open(file, ab8500_gpadc_main_charger_v_print,
1757 inode->i_private);
1758}
1759
1760static 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,
1766};
1767
1768static int ab8500_gpadc_acc_detect1_print(struct seq_file *s, void *p)
1769{
1770 int acc_detect1_raw;
1771 int acc_detect1_convert;
1772 struct ab8500_gpadc *gpadc;
1773
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);
1779
1780 seq_printf(s, "%d,0x%X\n", acc_detect1_convert, acc_detect1_raw);
1781
1782 return 0;
1783}
1784
1785static int ab8500_gpadc_acc_detect1_open(struct inode *inode,
1786 struct file *file)
1787{
1788 return single_open(file, ab8500_gpadc_acc_detect1_print,
1789 inode->i_private);
1790}
1791
1792static 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,
1798};
1799
1800static int ab8500_gpadc_acc_detect2_print(struct seq_file *s, void *p)
1801{
1802 int acc_detect2_raw;
1803 int acc_detect2_convert;
1804 struct ab8500_gpadc *gpadc;
1805
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);
1811
1812 seq_printf(s, "%d,0x%X\n", acc_detect2_convert, acc_detect2_raw);
1813
1814 return 0;
1815}
1816
1817static int ab8500_gpadc_acc_detect2_open(struct inode *inode,
1818 struct file *file)
1819{
1820 return single_open(file, ab8500_gpadc_acc_detect2_print,
1821 inode->i_private);
1822}
1823
1824static 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,
1830};
1831
1832static int ab8500_gpadc_aux1_print(struct seq_file *s, void *p)
1833{
1834 int aux1_raw;
1835 int aux1_convert;
1836 struct ab8500_gpadc *gpadc;
1837
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);
1843
1844 seq_printf(s, "%d,0x%X\n", aux1_convert, aux1_raw);
1845
1846 return 0;
1847}
1848
1849static int ab8500_gpadc_aux1_open(struct inode *inode, struct file *file)
1850{
1851 return single_open(file, ab8500_gpadc_aux1_print, inode->i_private);
1852}
1853
1854static 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,
1860};
1861
1862static int ab8500_gpadc_aux2_print(struct seq_file *s, void *p)
1863{
1864 int aux2_raw;
1865 int aux2_convert;
1866 struct ab8500_gpadc *gpadc;
1867
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);
1873
1874 seq_printf(s, "%d,0x%X\n", aux2_convert, aux2_raw);
1875
1876 return 0;
1877}
1878
1879static int ab8500_gpadc_aux2_open(struct inode *inode, struct file *file)
1880{
1881 return single_open(file, ab8500_gpadc_aux2_print, inode->i_private);
1882}
1883
1884static 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,
1890};
1891
1892static int ab8500_gpadc_main_bat_v_print(struct seq_file *s, void *p)
1893{
1894 int main_bat_v_raw;
1895 int main_bat_v_convert;
1896 struct ab8500_gpadc *gpadc;
1897
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);
1903
1904 seq_printf(s, "%d,0x%X\n", main_bat_v_convert, main_bat_v_raw);
1905
1906 return 0;
1907}
1908
1909static int ab8500_gpadc_main_bat_v_open(struct inode *inode,
1910 struct file *file)
1911{
1912 return single_open(file, ab8500_gpadc_main_bat_v_print,
1913 inode->i_private);
1914}
1915
1916static 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,
1922};
1923
1924static int ab8500_gpadc_vbus_v_print(struct seq_file *s, void *p)
1925{
1926 int vbus_v_raw;
1927 int vbus_v_convert;
1928 struct ab8500_gpadc *gpadc;
1929
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);
1935
1936 seq_printf(s, "%d,0x%X\n", vbus_v_convert, vbus_v_raw);
1937
1938 return 0;
1939}
1940
1941static int ab8500_gpadc_vbus_v_open(struct inode *inode, struct file *file)
1942{
1943 return single_open(file, ab8500_gpadc_vbus_v_print, inode->i_private);
1944}
1945
1946static 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,
1952};
1953
1954static int ab8500_gpadc_main_charger_c_print(struct seq_file *s, void *p)
1955{
1956 int main_charger_c_raw;
1957 int main_charger_c_convert;
1958 struct ab8500_gpadc *gpadc;
1959
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);
1965
1966 seq_printf(s, "%d,0x%X\n", main_charger_c_convert, main_charger_c_raw);
1967
1968 return 0;
1969}
1970
1971static int ab8500_gpadc_main_charger_c_open(struct inode *inode,
1972 struct file *file)
1973{
1974 return single_open(file, ab8500_gpadc_main_charger_c_print,
1975 inode->i_private);
1976}
1977
1978static 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,
1984};
1985
1986static int ab8500_gpadc_usb_charger_c_print(struct seq_file *s, void *p)
1987{
1988 int usb_charger_c_raw;
1989 int usb_charger_c_convert;
1990 struct ab8500_gpadc *gpadc;
1991
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);
1997
1998 seq_printf(s, "%d,0x%X\n", usb_charger_c_convert, usb_charger_c_raw);
1999
2000 return 0;
2001}
2002
2003static int ab8500_gpadc_usb_charger_c_open(struct inode *inode,
2004 struct file *file)
2005{
2006 return single_open(file, ab8500_gpadc_usb_charger_c_print,
2007 inode->i_private);
2008}
2009
2010static 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,
2016};
2017
2018static int ab8500_gpadc_bk_bat_v_print(struct seq_file *s, void *p)
2019{
2020 int bk_bat_v_raw;
2021 int bk_bat_v_convert;
2022 struct ab8500_gpadc *gpadc;
2023
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);
2029
2030 seq_printf(s, "%d,0x%X\n", bk_bat_v_convert, bk_bat_v_raw);
2031
2032 return 0;
2033}
2034
2035static int ab8500_gpadc_bk_bat_v_open(struct inode *inode, struct file *file)
2036{
2037 return single_open(file, ab8500_gpadc_bk_bat_v_print,
2038 inode->i_private);
2039}
2040
2041static 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,
2047};
2048
2049static int ab8500_gpadc_die_temp_print(struct seq_file *s, void *p)
2050{
2051 int die_temp_raw;
2052 int die_temp_convert;
2053 struct ab8500_gpadc *gpadc;
2054
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);
2060
2061 seq_printf(s, "%d,0x%X\n", die_temp_convert, die_temp_raw);
2062
2063 return 0;
2064}
2065
2066static int ab8500_gpadc_die_temp_open(struct inode *inode, struct file *file)
2067{
2068 return single_open(file, ab8500_gpadc_die_temp_print,
2069 inode->i_private);
2070}
2071
2072static 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,
2078};
2079
2080static int ab8500_gpadc_usb_id_print(struct seq_file *s, void *p)
2081{
2082 int usb_id_raw;
2083 int usb_id_convert;
2084 struct ab8500_gpadc *gpadc;
2085
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);
2091
2092 seq_printf(s, "%d,0x%X\n", usb_id_convert, usb_id_raw);
2093
2094 return 0;
2095}
2096
2097static int ab8500_gpadc_usb_id_open(struct inode *inode, struct file *file)
2098{
2099 return single_open(file, ab8500_gpadc_usb_id_print, inode->i_private);
2100}
2101
2102static 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,
2108};
2109
2110static int ab8540_gpadc_xtal_temp_print(struct seq_file *s, void *p)
2111{
2112 int xtal_temp_raw;
2113 int xtal_temp_convert;
2114 struct ab8500_gpadc *gpadc;
2115
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);
2121
2122 seq_printf(s, "%d,0x%X\n", xtal_temp_convert, xtal_temp_raw);
2123
2124 return 0;
2125}
2126
2127static int ab8540_gpadc_xtal_temp_open(struct inode *inode, struct file *file)
2128{
2129 return single_open(file, ab8540_gpadc_xtal_temp_print,
2130 inode->i_private);
2131}
2132
2133static 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,
2139};
2140
2141static int ab8540_gpadc_vbat_true_meas_print(struct seq_file *s, void *p)
2142{
2143 int vbat_true_meas_raw;
2144 int vbat_true_meas_convert;
2145 struct ab8500_gpadc *gpadc;
2146
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);
2153
2154 seq_printf(s, "%d,0x%X\n", vbat_true_meas_convert, vbat_true_meas_raw);
2155
2156 return 0;
2157}
2158
2159static int ab8540_gpadc_vbat_true_meas_open(struct inode *inode,
2160 struct file *file)
2161{
2162 return single_open(file, ab8540_gpadc_vbat_true_meas_print,
2163 inode->i_private);
2164}
2165
2166static 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,
2172};
2173
2174static int ab8540_gpadc_bat_ctrl_and_ibat_print(struct seq_file *s, void *p)
2175{
2176 int bat_ctrl_raw;
2177 int bat_ctrl_convert;
2178 int ibat_raw;
2179 int ibat_convert;
2180 struct ab8500_gpadc *gpadc;
2181
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);
2185
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);
2190
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);
2196
2197 return 0;
2198}
2199
2200static int ab8540_gpadc_bat_ctrl_and_ibat_open(struct inode *inode,
2201 struct file *file)
2202{
2203 return single_open(file, ab8540_gpadc_bat_ctrl_and_ibat_print,
2204 inode->i_private);
2205}
2206
2207static 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,
2213};
2214
2215static int ab8540_gpadc_vbat_meas_and_ibat_print(struct seq_file *s, void *p)
2216{
2217 int vbat_meas_raw;
2218 int vbat_meas_convert;
2219 int ibat_raw;
2220 int ibat_convert;
2221 struct ab8500_gpadc *gpadc;
2222
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);
2230
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);
2236
2237 return 0;
2238}
2239
2240static int ab8540_gpadc_vbat_meas_and_ibat_open(struct inode *inode,
2241 struct file *file)
2242{
2243 return single_open(file, ab8540_gpadc_vbat_meas_and_ibat_print,
2244 inode->i_private);
2245}
2246
2247static 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,
2253};
2254
2255static int ab8540_gpadc_vbat_true_meas_and_ibat_print(struct seq_file *s,
2256 void *p)
2257{
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;
2263
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);
2272
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);
2278
2279 return 0;
2280}
2281
2282static int ab8540_gpadc_vbat_true_meas_and_ibat_open(struct inode *inode,
2283 struct file *file)
2284{
2285 return single_open(file, ab8540_gpadc_vbat_true_meas_and_ibat_print,
2286 inode->i_private);
2287}
2288
2289static const struct file_operations
2290ab8540_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,
2296};
2297
2298static int ab8540_gpadc_bat_temp_and_ibat_print(struct seq_file *s, void *p)
2299{
2300 int bat_temp_raw;
2301 int bat_temp_convert;
2302 int ibat_raw;
2303 int ibat_convert;
2304 struct ab8500_gpadc *gpadc;
2305
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);
2313
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);
2319
2320 return 0;
2321}
2322
2323static int ab8540_gpadc_bat_temp_and_ibat_open(struct inode *inode,
2324 struct file *file)
2325{
2326 return single_open(file, ab8540_gpadc_bat_temp_and_ibat_print,
2327 inode->i_private);
2328}
2329
2330static 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,
2336};
2337
2338static int ab8540_gpadc_otp_cal_print(struct seq_file *s, void *p)
2339{
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;
2343
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);
2358
2359 return 0;
2360}
2361
2362static int ab8540_gpadc_otp_cal_open(struct inode *inode, struct file *file)
2363{
2364 return single_open(file, ab8540_gpadc_otp_cal_print, inode->i_private);
2365}
2366
2367static 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,
2373};
2374
2375static int ab8500_gpadc_avg_sample_print(struct seq_file *s, void *p)
2376{
2377 seq_printf(s, "%d\n", avg_sample);
2378
2379 return 0;
2380}
2381
2382static int ab8500_gpadc_avg_sample_open(struct inode *inode, struct file *file)
2383{
2384 return single_open(file, ab8500_gpadc_avg_sample_print,
2385 inode->i_private);
2386}
2387
2388static ssize_t ab8500_gpadc_avg_sample_write(struct file *file,
2389 const char __user *user_buf,
2390 size_t count, loff_t *ppos)
2391{
2392 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2393 unsigned long user_avg_sample;
2394 int err;
2395
2396 err = kstrtoul_from_user(user_buf, count, 0, &user_avg_sample);
2397 if (err)
2398 return err;
2399
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;
2408 }
2409
2410 return count;
2411}
2412
2413static 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,
2420};
2421
2422static int ab8500_gpadc_trig_edge_print(struct seq_file *s, void *p)
2423{
2424 seq_printf(s, "%d\n", trig_edge);
2425
2426 return 0;
2427}
2428
2429static int ab8500_gpadc_trig_edge_open(struct inode *inode, struct file *file)
2430{
2431 return single_open(file, ab8500_gpadc_trig_edge_print,
2432 inode->i_private);
2433}
2434
2435static ssize_t ab8500_gpadc_trig_edge_write(struct file *file,
2436 const char __user *user_buf,
2437 size_t count, loff_t *ppos)
2438{
2439 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2440 unsigned long user_trig_edge;
2441 int err;
2442
2443 err = kstrtoul_from_user(user_buf, count, 0, &user_trig_edge);
2444 if (err)
2445 return err;
2446
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;
2455 }
2456
2457 return count;
2458}
2459
2460static 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,
2467};
2468
2469static int ab8500_gpadc_trig_timer_print(struct seq_file *s, void *p)
2470{
2471 seq_printf(s, "%d\n", trig_timer);
2472
2473 return 0;
2474}
2475
2476static int ab8500_gpadc_trig_timer_open(struct inode *inode, struct file *file)
2477{
2478 return single_open(file, ab8500_gpadc_trig_timer_print,
2479 inode->i_private);
2480}
2481
2482static ssize_t ab8500_gpadc_trig_timer_write(struct file *file,
2483 const char __user *user_buf,
2484 size_t count, loff_t *ppos)
2485{
2486 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2487 unsigned long user_trig_timer;
2488 int err;
2489
2490 err = kstrtoul_from_user(user_buf, count, 0, &user_trig_timer);
2491 if (err)
2492 return err;
2493
2494 if (user_trig_timer & ~0xFF) {
2495 dev_err(dev,
2496 "debugfs error input: should be between 0 to 255\n");
2497 return -EINVAL;
2498 }
2499
2500 trig_timer = (u8) user_trig_timer;
2501
2502 return count;
2503}
2504
2505static 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,
2512};
2513
2514static int ab8500_gpadc_conv_type_print(struct seq_file *s, void *p)
2515{
2516 seq_printf(s, "%d\n", conv_type);
2517
2518 return 0;
2519}
2520
2521static int ab8500_gpadc_conv_type_open(struct inode *inode, struct file *file)
2522{
2523 return single_open(file, ab8500_gpadc_conv_type_print,
2524 inode->i_private);
2525}
2526
2527static ssize_t ab8500_gpadc_conv_type_write(struct file *file,
2528 const char __user *user_buf,
2529 size_t count, loff_t *ppos)
2530{
2531 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2532 unsigned long user_conv_type;
2533 int err;
2534
2535 err = kstrtoul_from_user(user_buf, count, 0, &user_conv_type);
2536 if (err)
2537 return err;
2538
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;
2547 }
2548
2549 return count;
2550}
2551
2552static 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,
2559};
2560
2561
2562
2563
2564
2565
2566
2567
2568static int strval_len(char *b)
2569{
2570 char *s = b;
2571
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;
2577 }
2578 } else {
2579 if (*s == '-')
2580 s++;
2581 for (; *s && (*s != ' ') && (*s != '\n'); s++) {
2582 if (!isdigit(*s))
2583 return 0;
2584 }
2585 }
2586 return (int) (s-b);
2587}
2588
2589
2590
2591
2592
2593static ssize_t hwreg_common_write(char *b, struct hwreg_cfg *cfg,
2594 struct device *dev)
2595{
2596 uint write, val = 0;
2597 u8 regvalue;
2598 int ret;
2599 struct hwreg_cfg loc = {
2600 .bank = 0,
2601 .addr = 0,
2602 .fmt = 0,
2603 .mask = 0xFFFFFFFF,
2604 .shift = 0,
2605 };
2606
2607
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;
2616
2617
2618 while ((*b == ' ') || (*b == '-')) {
2619 if (*(b-1) != ' ') {
2620 b++;
2621 continue;
2622 }
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;
2649 }
2650 }
2651
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;
2664
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;
2673 }
2674
2675
2676 *cfg = loc;
2677
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
2684
2685 if (!write)
2686 return 0;
2687
2688 ret = abx500_get_register_interruptible(dev,
2689 (u8)cfg->bank, (u8)cfg->addr, ®value);
2690 if (ret < 0) {
2691 dev_err(dev, "abx500_get_reg fail %d, %d\n",
2692 ret, __LINE__);
2693 return -EINVAL;
2694 }
2695
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);
2702 }
2703 val = val | regvalue;
2704
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;
2710 }
2711
2712 return 0;
2713}
2714
2715static ssize_t ab8500_hwreg_write(struct file *file,
2716 const char __user *user_buf, size_t count, loff_t *ppos)
2717{
2718 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2719 char buf[128];
2720 int buf_size, ret;
2721
2722
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;
2727
2728
2729 ret = hwreg_common_write(buf, &hwreg_cfg, dev);
2730 return (ret) ? ret : buf_size;
2731}
2732
2733
2734
2735
2736static int ab8500_subscribe_unsubscribe_print(struct seq_file *s, void *p)
2737{
2738 seq_printf(s, "%d\n", irq_first);
2739
2740 return 0;
2741}
2742
2743static int ab8500_subscribe_unsubscribe_open(struct inode *inode,
2744 struct file *file)
2745{
2746 return single_open(file, ab8500_subscribe_unsubscribe_print,
2747 inode->i_private);
2748}
2749
2750
2751
2752
2753
2754static ssize_t show_irq(struct device *dev,
2755 struct device_attribute *attr, char *buf)
2756{
2757 unsigned long name;
2758 unsigned int irq_index;
2759 int err;
2760
2761 err = kstrtoul(attr->attr.name, 0, &name);
2762 if (err)
2763 return err;
2764
2765 irq_index = name - irq_first;
2766 if (irq_index >= num_irqs)
2767 return -EINVAL;
2768
2769 return sprintf(buf, "%u\n", irq_count[irq_index]);
2770}
2771
2772static ssize_t ab8500_subscribe_write(struct file *file,
2773 const char __user *user_buf,
2774 size_t count, loff_t *ppos)
2775{
2776 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2777 unsigned long user_val;
2778 int err;
2779 unsigned int irq_index;
2780
2781 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
2782 if (err)
2783 return err;
2784
2785 if (user_val < irq_first) {
2786 dev_err(dev, "debugfs error input < %d\n", irq_first);
2787 return -EINVAL;
2788 }
2789 if (user_val > irq_last) {
2790 dev_err(dev, "debugfs error input > %d\n", irq_last);
2791 return -EINVAL;
2792 }
2793
2794 irq_index = user_val - irq_first;
2795 if (irq_index >= num_irqs)
2796 return -EINVAL;
2797
2798
2799
2800
2801
2802 dev_attr[irq_index] = kmalloc(sizeof(struct device_attribute),
2803 GFP_KERNEL);
2804 if (!dev_attr[irq_index])
2805 return -ENOMEM;
2806
2807 event_name[irq_index] = kmalloc(count, GFP_KERNEL);
2808 if (!event_name[irq_index])
2809 return -ENOMEM;
2810
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;
2820 }
2821
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;
2830 }
2831
2832 return count;
2833}
2834
2835static ssize_t ab8500_unsubscribe_write(struct file *file,
2836 const char __user *user_buf,
2837 size_t count, loff_t *ppos)
2838{
2839 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2840 unsigned long user_val;
2841 int err;
2842 unsigned int irq_index;
2843
2844 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
2845 if (err)
2846 return err;
2847
2848 if (user_val < irq_first) {
2849 dev_err(dev, "debugfs error input < %d\n", irq_first);
2850 return -EINVAL;
2851 }
2852 if (user_val > irq_last) {
2853 dev_err(dev, "debugfs error input > %d\n", irq_last);
2854 return -EINVAL;
2855 }
2856
2857 irq_index = user_val - irq_first;
2858 if (irq_index >= num_irqs)
2859 return -EINVAL;
2860
2861
2862 irq_count[irq_index] = 0;
2863
2864 if (dev_attr[irq_index])
2865 sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr);
2866
2867
2868 free_irq(user_val, &dev->kobj);
2869 kfree(event_name[irq_index]);
2870 kfree(dev_attr[irq_index]);
2871
2872 return count;
2873}
2874
2875
2876
2877
2878
2879static 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,
2886};
2887
2888static 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,
2895};
2896
2897static 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,
2904};
2905
2906static 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,
2912};
2913
2914static 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,
2921};
2922
2923static 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,
2930};
2931
2932static 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,
2939};
2940
2941static struct dentry *ab8500_dir;
2942static struct dentry *ab8500_gpadc_dir;
2943
2944static int ab8500_debug_probe(struct platform_device *plf)
2945{
2946 struct dentry *file;
2947 struct ab8500 *ab8500;
2948 struct resource *res;
2949
2950 debug_bank = AB8500_MISC;
2951 debug_address = AB8500_REV_REG & 0x00FF;
2952
2953 ab8500 = dev_get_drvdata(plf->dev.parent);
2954 num_irqs = ab8500->mask_size;
2955
2956 irq_count = devm_kzalloc(&plf->dev,
2957 sizeof(*irq_count)*num_irqs, GFP_KERNEL);
2958 if (!irq_count)
2959 return -ENOMEM;
2960
2961 dev_attr = devm_kzalloc(&plf->dev,
2962 sizeof(*dev_attr)*num_irqs, GFP_KERNEL);
2963 if (!dev_attr)
2964 return -ENOMEM;
2965
2966 event_name = devm_kzalloc(&plf->dev,
2967 sizeof(*event_name)*num_irqs, GFP_KERNEL);
2968 if (!event_name)
2969 return -ENOMEM;
2970
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;
2975 }
2976 irq_ab8500 = res->start;
2977
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;
2982 }
2983
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;
2988 }
2989
2990 ab8500_dir = debugfs_create_dir(AB8500_NAME_STRING, NULL);
2991 if (!ab8500_dir)
2992 goto err;
2993
2994 ab8500_gpadc_dir = debugfs_create_dir(AB8500_ADC_NAME_STRING,
2995 ab8500_dir);
2996 if (!ab8500_gpadc_dir)
2997 goto err;
2998
2999 file = debugfs_create_file("all-bank-registers", S_IRUGO, ab8500_dir,
3000 &plf->dev, &ab8500_registers_fops);
3001 if (!file)
3002 goto err;
3003
3004 file = debugfs_create_file("all-banks", S_IRUGO, ab8500_dir,
3005 &plf->dev, &ab8500_all_banks_fops);
3006 if (!file)
3007 goto err;
3008
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;
3014
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;
3020
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;
3026
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;
3032
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;
3045 }
3046
3047 file = debugfs_create_file("interrupts", (S_IRUGO), ab8500_dir,
3048 &plf->dev, &ab8500_interrupts_fops);
3049 if (!file)
3050 goto err;
3051
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;
3057
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;
3062
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;
3068
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;
3074
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;
3080
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;
3087
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;
3094
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;
3101
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;
3107
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;
3113
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;
3119
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;
3125
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;
3132
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;
3139
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;
3145
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;
3151
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;
3157
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;
3203 }
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;
3209
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;
3215
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;
3221
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;
3227
3228 return 0;
3229
3230err:
3231 debugfs_remove_recursive(ab8500_dir);
3232 dev_err(&plf->dev, "failed to create debugfs entries.\n");
3233
3234 return -ENOMEM;
3235}
3236
3237static int ab8500_debug_remove(struct platform_device *plf)
3238{
3239 debugfs_remove_recursive(ab8500_dir);
3240
3241 return 0;
3242}
3243
3244static struct platform_driver ab8500_debug_driver = {
3245 .driver = {
3246 .name = "ab8500-debug",
3247 },
3248 .probe = ab8500_debug_probe,
3249 .remove = ab8500_debug_remove
3250};
3251
3252static int __init ab8500_debug_init(void)
3253{
3254 return platform_driver_register(&ab8500_debug_driver);
3255}
3256
3257static void __exit ab8500_debug_exit(void)
3258{
3259 platform_driver_unregister(&ab8500_debug_driver);
3260}
3261subsys_initcall(ab8500_debug_init);
3262module_exit(ab8500_debug_exit);
3263
3264MODULE_AUTHOR("Mattias WALLIN <mattias.wallin@stericsson.com");
3265MODULE_DESCRIPTION("AB8500 DEBUG");
3266MODULE_LICENSE("GPL v2");
3267