]> Git Repo - linux.git/blob - drivers/mfd/ab8500-debugfs.c
Merge tag 'for-v4.16' of git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux...
[linux.git] / drivers / mfd / ab8500-debugfs.c
1 /*
2  * Copyright (C) ST-Ericsson SA 2010
3  *
4  * Author: Mattias Wallin <[email protected]> for ST-Ericsson.
5  * License Terms: GNU General Public License v2
6  */
7 /*
8  * AB8500 register access
9  * ======================
10  *
11  * read:
12  * # echo BANK  >  <debugfs>/ab8500/register-bank
13  * # echo ADDR  >  <debugfs>/ab8500/register-address
14  * # cat <debugfs>/ab8500/register-value
15  *
16  * write:
17  * # echo BANK  >  <debugfs>/ab8500/register-bank
18  * # echo ADDR  >  <debugfs>/ab8500/register-address
19  * # echo VALUE >  <debugfs>/ab8500/register-value
20  *
21  * read all registers from a bank:
22  * # echo BANK  >  <debugfs>/ab8500/register-bank
23  * # cat <debugfs>/ab8500/all-bank-register
24  *
25  * BANK   target AB8500 register bank
26  * ADDR   target AB8500 register address
27  * VALUE  decimal or 0x-prefixed hexadecimal
28  *
29  *
30  * User Space notification on AB8500 IRQ
31  * =====================================
32  *
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.
36  *
37  * subscribe to an AB8500 IRQ:
38  * # echo IRQ  >  <debugfs>/ab8500/irq-subscribe
39  *
40  * unsubscribe from an AB8500 IRQ:
41  * # echo IRQ  >  <debugfs>/ab8500/irq-unsubscribe
42  *
43  *
44  * AB8500 register formated read/write access
45  * ==========================================
46  *
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]
51  *
52  * Usage:
53  * # echo "CMD [OPTIONS] BANK ADRESS [VALUE]" > $debugfs/ab8500/hwreg
54  *
55  * CMD      read      read access
56  *          write     write access
57  *
58  * BANK     target reg bank
59  * ADDRESS  target reg address
60  * VALUE    (write) value to be updated
61  *
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
69  *
70  * Warning: bit shift operation is applied to bit-mask.
71  * Warning: bit shift direction depends on read or right command.
72  */
73
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>
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
94 static u32 debug_bank;
95 static u32 debug_address;
96
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;
102
103 static struct device_attribute **dev_attr;
104 static char **event_name;
105
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;
110
111 /**
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
116  */
117 struct ab8500_reg_range {
118         u8 first;
119         u8 last;
120         u8 perm;
121 };
122
123 /**
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
128  */
129 struct ab8500_prcmu_ranges {
130         u8 num_ranges;
131         u8 bankid;
132         const struct ab8500_reg_range *range;
133 };
134
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 */
142 };
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))
146
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 */
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
160 static struct ab8500_prcmu_ranges *debug_ranges;
161
162 static 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                          * 0x80-0x8B are SIM registers and should
247                          * not be accessed from here
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
485 static 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                          * 0x80-0x8B are SIM registers and should
586                          * not be accessed from here
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                         /* Latch registers should not be read here */
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                         /* LatchHier registers should not be read here */
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
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[]) {
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                         /* Latch registers should not be read here */
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                         /* LatchHier registers should not be read here */
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 #define DEFINE_SHOW_ATTRIBUTE(__name)                                         \
1262 static int __name ## _open(struct inode *inode, struct file *file)            \
1263 {                                                                             \
1264         return single_open(file, __name ## _show, inode->i_private);          \
1265 }                                                                             \
1266                                                                               \
1267 static const struct file_operations __name ## _fops = {                       \
1268         .owner          = THIS_MODULE,                                        \
1269         .open           = __name ## _open,                                    \
1270         .read           = seq_read,                                           \
1271         .llseek         = seq_lseek,                                          \
1272         .release        = single_release,                                     \
1273 }                                                                             \
1274
1275 static irqreturn_t ab8500_debug_handler(int irq, void *data)
1276 {
1277         char buf[16];
1278         struct kobject *kobj = (struct kobject *)data;
1279         unsigned int irq_abb = irq - irq_first;
1280
1281         if (irq_abb < num_irqs)
1282                 irq_count[irq_abb]++;
1283         /*
1284          * This makes it possible to use poll for events (POLLPRI | POLLERR)
1285          * from userspace on sysfs file named <irq-nr>
1286          */
1287         sprintf(buf, "%d", irq);
1288         sysfs_notify(kobj, NULL, buf);
1289
1290         return IRQ_HANDLED;
1291 }
1292
1293 /* Prints to seq_file or log_buf */
1294 static int ab8500_registers_print(struct device *dev, u32 bank,
1295                                   struct seq_file *s)
1296 {
1297         unsigned int i;
1298
1299         for (i = 0; i < debug_ranges[bank].num_ranges; i++) {
1300                 u32 reg;
1301
1302                 for (reg = debug_ranges[bank].range[i].first;
1303                         reg <= debug_ranges[bank].range[i].last;
1304                         reg++) {
1305                         u8 value;
1306                         int err;
1307
1308                         err = abx500_get_register_interruptible(dev,
1309                                 (u8)bank, (u8)reg, &value);
1310                         if (err < 0) {
1311                                 dev_err(dev, "ab->read fail %d\n", err);
1312                                 return err;
1313                         }
1314
1315                         if (s) {
1316                                 seq_printf(s, "  [0x%02X/0x%02X]: 0x%02X\n",
1317                                            bank, reg, value);
1318                                 /*
1319                                  * Error is not returned here since
1320                                  * the output is wanted in any case
1321                                  */
1322                                 if (seq_has_overflowed(s))
1323                                         return 0;
1324                         } else {
1325                                 dev_info(dev, " [0x%02X/0x%02X]: 0x%02X\n",
1326                                          bank, reg, value);
1327                         }
1328                 }
1329         }
1330
1331         return 0;
1332 }
1333
1334 static int ab8500_bank_registers_show(struct seq_file *s, void *p)
1335 {
1336         struct device *dev = s->private;
1337         u32 bank = debug_bank;
1338
1339         seq_puts(s, AB8500_NAME_STRING " register values:\n");
1340
1341         seq_printf(s, " bank 0x%02X:\n", bank);
1342
1343         return ab8500_registers_print(dev, bank, s);
1344 }
1345
1346 DEFINE_SHOW_ATTRIBUTE(ab8500_bank_registers);
1347
1348 static int ab8500_print_all_banks(struct seq_file *s, void *p)
1349 {
1350         struct device *dev = s->private;
1351         unsigned int i;
1352
1353         seq_puts(s, AB8500_NAME_STRING " register values:\n");
1354
1355         for (i = 0; i < AB8500_NUM_BANKS; i++) {
1356                 int err;
1357
1358                 seq_printf(s, " bank 0x%02X:\n", i);
1359                 err = ab8500_registers_print(dev, i, s);
1360                 if (err)
1361                         return err;
1362         }
1363         return 0;
1364 }
1365
1366 /* Dump registers to kernel log */
1367 void ab8500_dump_all_banks(struct device *dev)
1368 {
1369         unsigned int i;
1370
1371         dev_info(dev, "ab8500 register values:\n");
1372
1373         for (i = 1; i < AB8500_NUM_BANKS; i++) {
1374                 dev_info(dev, " bank 0x%02X:\n", i);
1375                 ab8500_registers_print(dev, i, NULL);
1376         }
1377 }
1378
1379 static int ab8500_all_banks_open(struct inode *inode, struct file *file)
1380 {
1381         struct seq_file *s;
1382         int err;
1383
1384         err = single_open(file, ab8500_print_all_banks, inode->i_private);
1385         if (!err) {
1386                 /* Default buf size in seq_read is not enough */
1387                 s = (struct seq_file *)file->private_data;
1388                 s->size = (PAGE_SIZE * 2);
1389                 s->buf = kmalloc(s->size, GFP_KERNEL);
1390                 if (!s->buf) {
1391                         single_release(inode, file);
1392                         err = -ENOMEM;
1393                 }
1394         }
1395         return err;
1396 }
1397
1398 static const struct file_operations ab8500_all_banks_fops = {
1399         .open = ab8500_all_banks_open,
1400         .read = seq_read,
1401         .llseek = seq_lseek,
1402         .release = single_release,
1403         .owner = THIS_MODULE,
1404 };
1405
1406 static int ab8500_bank_print(struct seq_file *s, void *p)
1407 {
1408         seq_printf(s, "0x%02X\n", debug_bank);
1409         return 0;
1410 }
1411
1412 static int ab8500_bank_open(struct inode *inode, struct file *file)
1413 {
1414         return single_open(file, ab8500_bank_print, inode->i_private);
1415 }
1416
1417 static ssize_t ab8500_bank_write(struct file *file,
1418         const char __user *user_buf,
1419         size_t count, loff_t *ppos)
1420 {
1421         struct device *dev = ((struct seq_file *)(file->private_data))->private;
1422         unsigned long user_bank;
1423         int err;
1424
1425         err = kstrtoul_from_user(user_buf, count, 0, &user_bank);
1426         if (err)
1427                 return err;
1428
1429         if (user_bank >= AB8500_NUM_BANKS) {
1430                 dev_err(dev, "debugfs error input > number of banks\n");
1431                 return -EINVAL;
1432         }
1433
1434         debug_bank = user_bank;
1435
1436         return count;
1437 }
1438
1439 static int ab8500_address_print(struct seq_file *s, void *p)
1440 {
1441         seq_printf(s, "0x%02X\n", debug_address);
1442         return 0;
1443 }
1444
1445 static int ab8500_address_open(struct inode *inode, struct file *file)
1446 {
1447         return single_open(file, ab8500_address_print, inode->i_private);
1448 }
1449
1450 static ssize_t ab8500_address_write(struct file *file,
1451                                     const char __user *user_buf,
1452                                     size_t count, loff_t *ppos)
1453 {
1454         struct device *dev = ((struct seq_file *)(file->private_data))->private;
1455         unsigned long user_address;
1456         int err;
1457
1458         err = kstrtoul_from_user(user_buf, count, 0, &user_address);
1459         if (err)
1460                 return err;
1461
1462         if (user_address > 0xff) {
1463                 dev_err(dev, "debugfs error input > 0xff\n");
1464                 return -EINVAL;
1465         }
1466         debug_address = user_address;
1467
1468         return count;
1469 }
1470
1471 static int ab8500_val_print(struct seq_file *s, void *p)
1472 {
1473         struct device *dev = s->private;
1474         int ret;
1475         u8 regvalue;
1476
1477         ret = abx500_get_register_interruptible(dev,
1478                 (u8)debug_bank, (u8)debug_address, &regvalue);
1479         if (ret < 0) {
1480                 dev_err(dev, "abx500_get_reg fail %d, %d\n",
1481                         ret, __LINE__);
1482                 return -EINVAL;
1483         }
1484         seq_printf(s, "0x%02X\n", regvalue);
1485
1486         return 0;
1487 }
1488
1489 static int ab8500_val_open(struct inode *inode, struct file *file)
1490 {
1491         return single_open(file, ab8500_val_print, inode->i_private);
1492 }
1493
1494 static ssize_t ab8500_val_write(struct file *file,
1495                                 const char __user *user_buf,
1496                                 size_t count, loff_t *ppos)
1497 {
1498         struct device *dev = ((struct seq_file *)(file->private_data))->private;
1499         unsigned long user_val;
1500         int err;
1501
1502         err = kstrtoul_from_user(user_buf, count, 0, &user_val);
1503         if (err)
1504                 return err;
1505
1506         if (user_val > 0xff) {
1507                 dev_err(dev, "debugfs error input > 0xff\n");
1508                 return -EINVAL;
1509         }
1510         err = abx500_set_register_interruptible(dev,
1511                 (u8)debug_bank, debug_address, (u8)user_val);
1512         if (err < 0) {
1513                 pr_err("abx500_set_reg failed %d, %d", err, __LINE__);
1514                 return -EINVAL;
1515         }
1516
1517         return count;
1518 }
1519
1520 /*
1521  * Interrupt status
1522  */
1523 static u32 num_interrupts[AB8500_MAX_NR_IRQS];
1524 static u32 num_wake_interrupts[AB8500_MAX_NR_IRQS];
1525 static int num_interrupt_lines;
1526
1527 void ab8500_debug_register_interrupt(int line)
1528 {
1529         if (line < num_interrupt_lines)
1530                 num_interrupts[line]++;
1531 }
1532
1533 static int ab8500_interrupts_show(struct seq_file *s, void *p)
1534 {
1535         int line;
1536
1537         seq_puts(s, "name: number:  number of: wake:\n");
1538
1539         for (line = 0; line < num_interrupt_lines; line++) {
1540                 struct irq_desc *desc = irq_to_desc(line + irq_first);
1541
1542                 seq_printf(s, "%3i:  %6i %4i",
1543                            line,
1544                            num_interrupts[line],
1545                            num_wake_interrupts[line]);
1546
1547                 if (desc && desc->name)
1548                         seq_printf(s, "-%-8s", desc->name);
1549                 if (desc && desc->action) {
1550                         struct irqaction *action = desc->action;
1551
1552                         seq_printf(s, "  %s", action->name);
1553                         while ((action = action->next) != NULL)
1554                                 seq_printf(s, ", %s", action->name);
1555                 }
1556                 seq_putc(s, '\n');
1557         }
1558
1559         return 0;
1560 }
1561
1562 DEFINE_SHOW_ATTRIBUTE(ab8500_interrupts);
1563
1564 /*
1565  * - HWREG DB8500 formated routines
1566  */
1567 static int ab8500_hwreg_print(struct seq_file *s, void *d)
1568 {
1569         struct device *dev = s->private;
1570         int ret;
1571         u8 regvalue;
1572
1573         ret = abx500_get_register_interruptible(dev,
1574                 (u8)hwreg_cfg.bank, (u8)hwreg_cfg.addr, &regvalue);
1575         if (ret < 0) {
1576                 dev_err(dev, "abx500_get_reg fail %d, %d\n",
1577                         ret, __LINE__);
1578                 return -EINVAL;
1579         }
1580
1581         if (hwreg_cfg.shift >= 0)
1582                 regvalue >>= hwreg_cfg.shift;
1583         else
1584                 regvalue <<= -hwreg_cfg.shift;
1585         regvalue &= hwreg_cfg.mask;
1586
1587         if (REG_FMT_DEC(&hwreg_cfg))
1588                 seq_printf(s, "%d\n", regvalue);
1589         else
1590                 seq_printf(s, "0x%02X\n", regvalue);
1591         return 0;
1592 }
1593
1594 static int ab8500_hwreg_open(struct inode *inode, struct file *file)
1595 {
1596         return single_open(file, ab8500_hwreg_print, inode->i_private);
1597 }
1598
1599 #define AB8500_SUPPLY_CONTROL_CONFIG_1 0x01
1600 #define AB8500_SUPPLY_CONTROL_REG 0x00
1601 #define AB8500_FIRST_SIM_REG 0x80
1602 #define AB8500_LAST_SIM_REG 0x8B
1603 #define AB8505_LAST_SIM_REG 0x8C
1604
1605 static int ab8500_modem_show(struct seq_file *s, void *p)
1606 {
1607         struct device *dev = s->private;
1608         struct ab8500 *ab8500;
1609         int err;
1610         u8 value;
1611         u8 orig_value;
1612         u32 bank = AB8500_REGU_CTRL2;
1613         u32 last_sim_reg = AB8500_LAST_SIM_REG;
1614         u32 reg;
1615
1616         ab8500 = dev_get_drvdata(dev->parent);
1617         dev_warn(dev, "WARNING! This operation can interfer with modem side\n"
1618                 "and should only be done with care\n");
1619
1620         err = abx500_get_register_interruptible(dev,
1621                 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG, &orig_value);
1622         if (err < 0)
1623                 goto report_read_failure;
1624
1625         /* Config 1 will allow APE side to read SIM registers */
1626         err = abx500_set_register_interruptible(dev,
1627                 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG,
1628                 AB8500_SUPPLY_CONTROL_CONFIG_1);
1629         if (err < 0)
1630                 goto report_write_failure;
1631
1632         seq_printf(s, " bank 0x%02X:\n", bank);
1633
1634         if (is_ab9540(ab8500) || is_ab8505(ab8500))
1635                 last_sim_reg = AB8505_LAST_SIM_REG;
1636
1637         for (reg = AB8500_FIRST_SIM_REG; reg <= last_sim_reg; reg++) {
1638                 err = abx500_get_register_interruptible(dev,
1639                         bank, reg, &value);
1640                 if (err < 0)
1641                         goto report_read_failure;
1642
1643                 seq_printf(s, "  [0x%02X/0x%02X]: 0x%02X\n", bank, reg, value);
1644         }
1645         err = abx500_set_register_interruptible(dev,
1646                 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG, orig_value);
1647         if (err < 0)
1648                 goto report_write_failure;
1649
1650         return 0;
1651
1652 report_read_failure:
1653         dev_err(dev, "ab->read fail %d\n", err);
1654         return err;
1655
1656 report_write_failure:
1657         dev_err(dev, "ab->write fail %d\n", err);
1658         return err;
1659 }
1660
1661 DEFINE_SHOW_ATTRIBUTE(ab8500_modem);
1662
1663 static int ab8500_gpadc_bat_ctrl_show(struct seq_file *s, void *p)
1664 {
1665         int bat_ctrl_raw;
1666         int bat_ctrl_convert;
1667         struct ab8500_gpadc *gpadc;
1668
1669         gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1670         bat_ctrl_raw = ab8500_gpadc_read_raw(gpadc, BAT_CTRL,
1671                 avg_sample, trig_edge, trig_timer, conv_type);
1672         bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc,
1673                 BAT_CTRL, bat_ctrl_raw);
1674
1675         seq_printf(s, "%d,0x%X\n", bat_ctrl_convert, bat_ctrl_raw);
1676
1677         return 0;
1678 }
1679
1680 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_bat_ctrl);
1681
1682 static int ab8500_gpadc_btemp_ball_show(struct seq_file *s, void *p)
1683 {
1684         int btemp_ball_raw;
1685         int btemp_ball_convert;
1686         struct ab8500_gpadc *gpadc;
1687
1688         gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1689         btemp_ball_raw = ab8500_gpadc_read_raw(gpadc, BTEMP_BALL,
1690                 avg_sample, trig_edge, trig_timer, conv_type);
1691         btemp_ball_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL,
1692                 btemp_ball_raw);
1693
1694         seq_printf(s, "%d,0x%X\n", btemp_ball_convert, btemp_ball_raw);
1695
1696         return 0;
1697 }
1698
1699 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_btemp_ball);
1700
1701 static int ab8500_gpadc_main_charger_v_show(struct seq_file *s, void *p)
1702 {
1703         int main_charger_v_raw;
1704         int main_charger_v_convert;
1705         struct ab8500_gpadc *gpadc;
1706
1707         gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1708         main_charger_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_V,
1709                 avg_sample, trig_edge, trig_timer, conv_type);
1710         main_charger_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
1711                 MAIN_CHARGER_V, main_charger_v_raw);
1712
1713         seq_printf(s, "%d,0x%X\n", main_charger_v_convert, main_charger_v_raw);
1714
1715         return 0;
1716 }
1717
1718 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_main_charger_v);
1719
1720 static int ab8500_gpadc_acc_detect1_show(struct seq_file *s, void *p)
1721 {
1722         int acc_detect1_raw;
1723         int acc_detect1_convert;
1724         struct ab8500_gpadc *gpadc;
1725
1726         gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1727         acc_detect1_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT1,
1728                 avg_sample, trig_edge, trig_timer, conv_type);
1729         acc_detect1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ACC_DETECT1,
1730                 acc_detect1_raw);
1731
1732         seq_printf(s, "%d,0x%X\n", acc_detect1_convert, acc_detect1_raw);
1733
1734         return 0;
1735 }
1736
1737 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_acc_detect1);
1738
1739 static int ab8500_gpadc_acc_detect2_show(struct seq_file *s, void *p)
1740 {
1741         int acc_detect2_raw;
1742         int acc_detect2_convert;
1743         struct ab8500_gpadc *gpadc;
1744
1745         gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1746         acc_detect2_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT2,
1747                 avg_sample, trig_edge, trig_timer, conv_type);
1748         acc_detect2_convert = ab8500_gpadc_ad_to_voltage(gpadc,
1749                 ACC_DETECT2, acc_detect2_raw);
1750
1751         seq_printf(s, "%d,0x%X\n", acc_detect2_convert, acc_detect2_raw);
1752
1753         return 0;
1754 }
1755
1756 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_acc_detect2);
1757
1758 static int ab8500_gpadc_aux1_show(struct seq_file *s, void *p)
1759 {
1760         int aux1_raw;
1761         int aux1_convert;
1762         struct ab8500_gpadc *gpadc;
1763
1764         gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1765         aux1_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX1,
1766                 avg_sample, trig_edge, trig_timer, conv_type);
1767         aux1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX1,
1768                 aux1_raw);
1769
1770         seq_printf(s, "%d,0x%X\n", aux1_convert, aux1_raw);
1771
1772         return 0;
1773 }
1774
1775 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_aux1);
1776
1777 static int ab8500_gpadc_aux2_show(struct seq_file *s, void *p)
1778 {
1779         int aux2_raw;
1780         int aux2_convert;
1781         struct ab8500_gpadc *gpadc;
1782
1783         gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1784         aux2_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX2,
1785                 avg_sample, trig_edge, trig_timer, conv_type);
1786         aux2_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX2,
1787                 aux2_raw);
1788
1789         seq_printf(s, "%d,0x%X\n", aux2_convert, aux2_raw);
1790
1791         return 0;
1792 }
1793
1794 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_aux2);
1795
1796 static int ab8500_gpadc_main_bat_v_show(struct seq_file *s, void *p)
1797 {
1798         int main_bat_v_raw;
1799         int main_bat_v_convert;
1800         struct ab8500_gpadc *gpadc;
1801
1802         gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1803         main_bat_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_BAT_V,
1804                 avg_sample, trig_edge, trig_timer, conv_type);
1805         main_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V,
1806                 main_bat_v_raw);
1807
1808         seq_printf(s, "%d,0x%X\n", main_bat_v_convert, main_bat_v_raw);
1809
1810         return 0;
1811 }
1812
1813 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_main_bat_v);
1814
1815 static int ab8500_gpadc_vbus_v_show(struct seq_file *s, void *p)
1816 {
1817         int vbus_v_raw;
1818         int vbus_v_convert;
1819         struct ab8500_gpadc *gpadc;
1820
1821         gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1822         vbus_v_raw =  ab8500_gpadc_read_raw(gpadc, VBUS_V,
1823                 avg_sample, trig_edge, trig_timer, conv_type);
1824         vbus_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, VBUS_V,
1825                 vbus_v_raw);
1826
1827         seq_printf(s, "%d,0x%X\n", vbus_v_convert, vbus_v_raw);
1828
1829         return 0;
1830 }
1831
1832 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_vbus_v);
1833
1834 static int ab8500_gpadc_main_charger_c_show(struct seq_file *s, void *p)
1835 {
1836         int main_charger_c_raw;
1837         int main_charger_c_convert;
1838         struct ab8500_gpadc *gpadc;
1839
1840         gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1841         main_charger_c_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_C,
1842                 avg_sample, trig_edge, trig_timer, conv_type);
1843         main_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
1844                 MAIN_CHARGER_C, main_charger_c_raw);
1845
1846         seq_printf(s, "%d,0x%X\n", main_charger_c_convert, main_charger_c_raw);
1847
1848         return 0;
1849 }
1850
1851 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_main_charger_c);
1852
1853 static int ab8500_gpadc_usb_charger_c_show(struct seq_file *s, void *p)
1854 {
1855         int usb_charger_c_raw;
1856         int usb_charger_c_convert;
1857         struct ab8500_gpadc *gpadc;
1858
1859         gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1860         usb_charger_c_raw = ab8500_gpadc_read_raw(gpadc, USB_CHARGER_C,
1861                 avg_sample, trig_edge, trig_timer, conv_type);
1862         usb_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
1863                 USB_CHARGER_C, usb_charger_c_raw);
1864
1865         seq_printf(s, "%d,0x%X\n", usb_charger_c_convert, usb_charger_c_raw);
1866
1867         return 0;
1868 }
1869
1870 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_usb_charger_c);
1871
1872 static int ab8500_gpadc_bk_bat_v_show(struct seq_file *s, void *p)
1873 {
1874         int bk_bat_v_raw;
1875         int bk_bat_v_convert;
1876         struct ab8500_gpadc *gpadc;
1877
1878         gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1879         bk_bat_v_raw = ab8500_gpadc_read_raw(gpadc, BK_BAT_V,
1880                 avg_sample, trig_edge, trig_timer, conv_type);
1881         bk_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
1882                 BK_BAT_V, bk_bat_v_raw);
1883
1884         seq_printf(s, "%d,0x%X\n", bk_bat_v_convert, bk_bat_v_raw);
1885
1886         return 0;
1887 }
1888
1889 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_bk_bat_v);
1890
1891 static int ab8500_gpadc_die_temp_show(struct seq_file *s, void *p)
1892 {
1893         int die_temp_raw;
1894         int die_temp_convert;
1895         struct ab8500_gpadc *gpadc;
1896
1897         gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1898         die_temp_raw = ab8500_gpadc_read_raw(gpadc, DIE_TEMP,
1899                 avg_sample, trig_edge, trig_timer, conv_type);
1900         die_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, DIE_TEMP,
1901                 die_temp_raw);
1902
1903         seq_printf(s, "%d,0x%X\n", die_temp_convert, die_temp_raw);
1904
1905         return 0;
1906 }
1907
1908 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_die_temp);
1909
1910 static int ab8500_gpadc_usb_id_show(struct seq_file *s, void *p)
1911 {
1912         int usb_id_raw;
1913         int usb_id_convert;
1914         struct ab8500_gpadc *gpadc;
1915
1916         gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1917         usb_id_raw = ab8500_gpadc_read_raw(gpadc, USB_ID,
1918                 avg_sample, trig_edge, trig_timer, conv_type);
1919         usb_id_convert = ab8500_gpadc_ad_to_voltage(gpadc, USB_ID,
1920                 usb_id_raw);
1921
1922         seq_printf(s, "%d,0x%X\n", usb_id_convert, usb_id_raw);
1923
1924         return 0;
1925 }
1926
1927 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_usb_id);
1928
1929 static int ab8540_gpadc_xtal_temp_show(struct seq_file *s, void *p)
1930 {
1931         int xtal_temp_raw;
1932         int xtal_temp_convert;
1933         struct ab8500_gpadc *gpadc;
1934
1935         gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1936         xtal_temp_raw = ab8500_gpadc_read_raw(gpadc, XTAL_TEMP,
1937                 avg_sample, trig_edge, trig_timer, conv_type);
1938         xtal_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, XTAL_TEMP,
1939                 xtal_temp_raw);
1940
1941         seq_printf(s, "%d,0x%X\n", xtal_temp_convert, xtal_temp_raw);
1942
1943         return 0;
1944 }
1945
1946 DEFINE_SHOW_ATTRIBUTE(ab8540_gpadc_xtal_temp);
1947
1948 static int ab8540_gpadc_vbat_true_meas_show(struct seq_file *s, void *p)
1949 {
1950         int vbat_true_meas_raw;
1951         int vbat_true_meas_convert;
1952         struct ab8500_gpadc *gpadc;
1953
1954         gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1955         vbat_true_meas_raw = ab8500_gpadc_read_raw(gpadc, VBAT_TRUE_MEAS,
1956                 avg_sample, trig_edge, trig_timer, conv_type);
1957         vbat_true_meas_convert =
1958                 ab8500_gpadc_ad_to_voltage(gpadc, VBAT_TRUE_MEAS,
1959                                            vbat_true_meas_raw);
1960
1961         seq_printf(s, "%d,0x%X\n", vbat_true_meas_convert, vbat_true_meas_raw);
1962
1963         return 0;
1964 }
1965
1966 DEFINE_SHOW_ATTRIBUTE(ab8540_gpadc_vbat_true_meas);
1967
1968 static int ab8540_gpadc_bat_ctrl_and_ibat_show(struct seq_file *s, void *p)
1969 {
1970         int bat_ctrl_raw;
1971         int bat_ctrl_convert;
1972         int ibat_raw;
1973         int ibat_convert;
1974         struct ab8500_gpadc *gpadc;
1975
1976         gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1977         bat_ctrl_raw = ab8500_gpadc_double_read_raw(gpadc, BAT_CTRL_AND_IBAT,
1978                 avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
1979
1980         bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc, BAT_CTRL,
1981                 bat_ctrl_raw);
1982         ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
1983                 ibat_raw);
1984
1985         seq_printf(s,
1986                    "%d,0x%X\n"
1987                    "%d,0x%X\n",
1988                    bat_ctrl_convert, bat_ctrl_raw,
1989                    ibat_convert, ibat_raw);
1990
1991         return 0;
1992 }
1993
1994 DEFINE_SHOW_ATTRIBUTE(ab8540_gpadc_bat_ctrl_and_ibat);
1995
1996 static int ab8540_gpadc_vbat_meas_and_ibat_show(struct seq_file *s, void *p)
1997 {
1998         int vbat_meas_raw;
1999         int vbat_meas_convert;
2000         int ibat_raw;
2001         int ibat_convert;
2002         struct ab8500_gpadc *gpadc;
2003
2004         gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2005         vbat_meas_raw = ab8500_gpadc_double_read_raw(gpadc, VBAT_MEAS_AND_IBAT,
2006                 avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
2007         vbat_meas_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V,
2008                 vbat_meas_raw);
2009         ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2010                 ibat_raw);
2011
2012         seq_printf(s,
2013                    "%d,0x%X\n"
2014                    "%d,0x%X\n",
2015                    vbat_meas_convert, vbat_meas_raw,
2016                    ibat_convert, ibat_raw);
2017
2018         return 0;
2019 }
2020
2021 DEFINE_SHOW_ATTRIBUTE(ab8540_gpadc_vbat_meas_and_ibat);
2022
2023 static int ab8540_gpadc_vbat_true_meas_and_ibat_show(struct seq_file *s, void *p)
2024 {
2025         int vbat_true_meas_raw;
2026         int vbat_true_meas_convert;
2027         int ibat_raw;
2028         int ibat_convert;
2029         struct ab8500_gpadc *gpadc;
2030
2031         gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2032         vbat_true_meas_raw = ab8500_gpadc_double_read_raw(gpadc,
2033                         VBAT_TRUE_MEAS_AND_IBAT, avg_sample, trig_edge,
2034                         trig_timer, conv_type, &ibat_raw);
2035         vbat_true_meas_convert = ab8500_gpadc_ad_to_voltage(gpadc,
2036                         VBAT_TRUE_MEAS, vbat_true_meas_raw);
2037         ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2038                 ibat_raw);
2039
2040         seq_printf(s,
2041                    "%d,0x%X\n"
2042                    "%d,0x%X\n",
2043                    vbat_true_meas_convert, vbat_true_meas_raw,
2044                    ibat_convert, ibat_raw);
2045
2046         return 0;
2047 }
2048
2049 DEFINE_SHOW_ATTRIBUTE(ab8540_gpadc_vbat_true_meas_and_ibat);
2050
2051 static int ab8540_gpadc_bat_temp_and_ibat_show(struct seq_file *s, void *p)
2052 {
2053         int bat_temp_raw;
2054         int bat_temp_convert;
2055         int ibat_raw;
2056         int ibat_convert;
2057         struct ab8500_gpadc *gpadc;
2058
2059         gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2060         bat_temp_raw = ab8500_gpadc_double_read_raw(gpadc, BAT_TEMP_AND_IBAT,
2061                 avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
2062         bat_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL,
2063                 bat_temp_raw);
2064         ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2065                 ibat_raw);
2066
2067         seq_printf(s,
2068                    "%d,0x%X\n"
2069                    "%d,0x%X\n",
2070                    bat_temp_convert, bat_temp_raw,
2071                    ibat_convert, ibat_raw);
2072
2073         return 0;
2074 }
2075
2076 DEFINE_SHOW_ATTRIBUTE(ab8540_gpadc_bat_temp_and_ibat);
2077
2078 static int ab8540_gpadc_otp_calib_show(struct seq_file *s, void *p)
2079 {
2080         struct ab8500_gpadc *gpadc;
2081         u16 vmain_l, vmain_h, btemp_l, btemp_h;
2082         u16 vbat_l, vbat_h, ibat_l, ibat_h;
2083
2084         gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2085         ab8540_gpadc_get_otp(gpadc, &vmain_l, &vmain_h, &btemp_l, &btemp_h,
2086                         &vbat_l, &vbat_h, &ibat_l, &ibat_h);
2087         seq_printf(s,
2088                    "VMAIN_L:0x%X\n"
2089                    "VMAIN_H:0x%X\n"
2090                    "BTEMP_L:0x%X\n"
2091                    "BTEMP_H:0x%X\n"
2092                    "VBAT_L:0x%X\n"
2093                    "VBAT_H:0x%X\n"
2094                    "IBAT_L:0x%X\n"
2095                    "IBAT_H:0x%X\n",
2096                    vmain_l, vmain_h, btemp_l, btemp_h,
2097                    vbat_l, vbat_h, ibat_l, ibat_h);
2098
2099         return 0;
2100 }
2101
2102 DEFINE_SHOW_ATTRIBUTE(ab8540_gpadc_otp_calib);
2103
2104 static int ab8500_gpadc_avg_sample_print(struct seq_file *s, void *p)
2105 {
2106         seq_printf(s, "%d\n", avg_sample);
2107
2108         return 0;
2109 }
2110
2111 static int ab8500_gpadc_avg_sample_open(struct inode *inode, struct file *file)
2112 {
2113         return single_open(file, ab8500_gpadc_avg_sample_print,
2114                 inode->i_private);
2115 }
2116
2117 static ssize_t ab8500_gpadc_avg_sample_write(struct file *file,
2118         const char __user *user_buf,
2119         size_t count, loff_t *ppos)
2120 {
2121         struct device *dev = ((struct seq_file *)(file->private_data))->private;
2122         unsigned long user_avg_sample;
2123         int err;
2124
2125         err = kstrtoul_from_user(user_buf, count, 0, &user_avg_sample);
2126         if (err)
2127                 return err;
2128
2129         if ((user_avg_sample == SAMPLE_1) || (user_avg_sample == SAMPLE_4)
2130                         || (user_avg_sample == SAMPLE_8)
2131                         || (user_avg_sample == SAMPLE_16)) {
2132                 avg_sample = (u8) user_avg_sample;
2133         } else {
2134                 dev_err(dev,
2135                         "debugfs err input: should be egal to 1, 4, 8 or 16\n");
2136                 return -EINVAL;
2137         }
2138
2139         return count;
2140 }
2141
2142 static const struct file_operations ab8500_gpadc_avg_sample_fops = {
2143         .open = ab8500_gpadc_avg_sample_open,
2144         .read = seq_read,
2145         .write = ab8500_gpadc_avg_sample_write,
2146         .llseek = seq_lseek,
2147         .release = single_release,
2148         .owner = THIS_MODULE,
2149 };
2150
2151 static int ab8500_gpadc_trig_edge_print(struct seq_file *s, void *p)
2152 {
2153         seq_printf(s, "%d\n", trig_edge);
2154
2155         return 0;
2156 }
2157
2158 static int ab8500_gpadc_trig_edge_open(struct inode *inode, struct file *file)
2159 {
2160         return single_open(file, ab8500_gpadc_trig_edge_print,
2161                 inode->i_private);
2162 }
2163
2164 static ssize_t ab8500_gpadc_trig_edge_write(struct file *file,
2165         const char __user *user_buf,
2166         size_t count, loff_t *ppos)
2167 {
2168         struct device *dev = ((struct seq_file *)(file->private_data))->private;
2169         unsigned long user_trig_edge;
2170         int err;
2171
2172         err = kstrtoul_from_user(user_buf, count, 0, &user_trig_edge);
2173         if (err)
2174                 return err;
2175
2176         if ((user_trig_edge == RISING_EDGE)
2177                         || (user_trig_edge == FALLING_EDGE)) {
2178                 trig_edge = (u8) user_trig_edge;
2179         } else {
2180                 dev_err(dev, "Wrong input:\n"
2181                         "Enter 0. Rising edge\n"
2182                         "Enter 1. Falling edge\n");
2183                 return -EINVAL;
2184         }
2185
2186         return count;
2187 }
2188
2189 static const struct file_operations ab8500_gpadc_trig_edge_fops = {
2190         .open = ab8500_gpadc_trig_edge_open,
2191         .read = seq_read,
2192         .write = ab8500_gpadc_trig_edge_write,
2193         .llseek = seq_lseek,
2194         .release = single_release,
2195         .owner = THIS_MODULE,
2196 };
2197
2198 static int ab8500_gpadc_trig_timer_print(struct seq_file *s, void *p)
2199 {
2200         seq_printf(s, "%d\n", trig_timer);
2201
2202         return 0;
2203 }
2204
2205 static int ab8500_gpadc_trig_timer_open(struct inode *inode, struct file *file)
2206 {
2207         return single_open(file, ab8500_gpadc_trig_timer_print,
2208                 inode->i_private);
2209 }
2210
2211 static ssize_t ab8500_gpadc_trig_timer_write(struct file *file,
2212         const char __user *user_buf,
2213         size_t count, loff_t *ppos)
2214 {
2215         struct device *dev = ((struct seq_file *)(file->private_data))->private;
2216         unsigned long user_trig_timer;
2217         int err;
2218
2219         err = kstrtoul_from_user(user_buf, count, 0, &user_trig_timer);
2220         if (err)
2221                 return err;
2222
2223         if (user_trig_timer & ~0xFF) {
2224                 dev_err(dev,
2225                         "debugfs error input: should be between 0 to 255\n");
2226                 return -EINVAL;
2227         }
2228
2229         trig_timer = (u8) user_trig_timer;
2230
2231         return count;
2232 }
2233
2234 static const struct file_operations ab8500_gpadc_trig_timer_fops = {
2235         .open = ab8500_gpadc_trig_timer_open,
2236         .read = seq_read,
2237         .write = ab8500_gpadc_trig_timer_write,
2238         .llseek = seq_lseek,
2239         .release = single_release,
2240         .owner = THIS_MODULE,
2241 };
2242
2243 static int ab8500_gpadc_conv_type_print(struct seq_file *s, void *p)
2244 {
2245         seq_printf(s, "%d\n", conv_type);
2246
2247         return 0;
2248 }
2249
2250 static int ab8500_gpadc_conv_type_open(struct inode *inode, struct file *file)
2251 {
2252         return single_open(file, ab8500_gpadc_conv_type_print,
2253                 inode->i_private);
2254 }
2255
2256 static ssize_t ab8500_gpadc_conv_type_write(struct file *file,
2257         const char __user *user_buf,
2258         size_t count, loff_t *ppos)
2259 {
2260         struct device *dev = ((struct seq_file *)(file->private_data))->private;
2261         unsigned long user_conv_type;
2262         int err;
2263
2264         err = kstrtoul_from_user(user_buf, count, 0, &user_conv_type);
2265         if (err)
2266                 return err;
2267
2268         if ((user_conv_type == ADC_SW)
2269                         || (user_conv_type == ADC_HW)) {
2270                 conv_type = (u8) user_conv_type;
2271         } else {
2272                 dev_err(dev, "Wrong input:\n"
2273                         "Enter 0. ADC SW conversion\n"
2274                         "Enter 1. ADC HW conversion\n");
2275                 return -EINVAL;
2276         }
2277
2278         return count;
2279 }
2280
2281 static const struct file_operations ab8500_gpadc_conv_type_fops = {
2282         .open = ab8500_gpadc_conv_type_open,
2283         .read = seq_read,
2284         .write = ab8500_gpadc_conv_type_write,
2285         .llseek = seq_lseek,
2286         .release = single_release,
2287         .owner = THIS_MODULE,
2288 };
2289
2290 /*
2291  * return length of an ASCII numerical value, 0 is string is not a
2292  * numerical value.
2293  * string shall start at value 1st char.
2294  * string can be tailed with \0 or space or newline chars only.
2295  * value can be decimal or hexadecimal (prefixed 0x or 0X).
2296  */
2297 static int strval_len(char *b)
2298 {
2299         char *s = b;
2300
2301         if ((*s == '0') && ((*(s+1) == 'x') || (*(s+1) == 'X'))) {
2302                 s += 2;
2303                 for (; *s && (*s != ' ') && (*s != '\n'); s++) {
2304                         if (!isxdigit(*s))
2305                                 return 0;
2306                 }
2307         } else {
2308                 if (*s == '-')
2309                         s++;
2310                 for (; *s && (*s != ' ') && (*s != '\n'); s++) {
2311                         if (!isdigit(*s))
2312                                 return 0;
2313                 }
2314         }
2315         return (int) (s-b);
2316 }
2317
2318 /*
2319  * parse hwreg input data.
2320  * update global hwreg_cfg only if input data syntax is ok.
2321  */
2322 static ssize_t hwreg_common_write(char *b, struct hwreg_cfg *cfg,
2323                 struct device *dev)
2324 {
2325         uint write, val = 0;
2326         u8  regvalue;
2327         int ret;
2328         struct hwreg_cfg loc = {
2329                 .bank = 0,          /* default: invalid phys addr */
2330                 .addr = 0,          /* default: invalid phys addr */
2331                 .fmt = 0,           /* default: 32bit access, hex output */
2332                 .mask = 0xFFFFFFFF, /* default: no mask */
2333                 .shift = 0,         /* default: no bit shift */
2334         };
2335
2336         /* read or write ? */
2337         if (!strncmp(b, "read ", 5)) {
2338                 write = 0;
2339                 b += 5;
2340         } else if (!strncmp(b, "write ", 6)) {
2341                 write = 1;
2342                 b += 6;
2343         } else
2344                 return -EINVAL;
2345
2346         /* OPTIONS -l|-w|-b -s -m -o */
2347         while ((*b == ' ') || (*b == '-')) {
2348                 if (*(b-1) != ' ') {
2349                         b++;
2350                         continue;
2351                 }
2352                 if ((!strncmp(b, "-d ", 3)) ||
2353                                 (!strncmp(b, "-dec ", 5))) {
2354                         b += (*(b+2) == ' ') ? 3 : 5;
2355                         loc.fmt |= (1<<0);
2356                 } else if ((!strncmp(b, "-h ", 3)) ||
2357                                 (!strncmp(b, "-hex ", 5))) {
2358                         b += (*(b+2) == ' ') ? 3 : 5;
2359                         loc.fmt &= ~(1<<0);
2360                 } else if ((!strncmp(b, "-m ", 3)) ||
2361                                 (!strncmp(b, "-mask ", 6))) {
2362                         b += (*(b+2) == ' ') ? 3 : 6;
2363                         if (strval_len(b) == 0)
2364                                 return -EINVAL;
2365                         ret = kstrtoul(b, 0, &loc.mask);
2366                         if (ret)
2367                                 return ret;
2368                 } else if ((!strncmp(b, "-s ", 3)) ||
2369                                 (!strncmp(b, "-shift ", 7))) {
2370                         b += (*(b+2) == ' ') ? 3 : 7;
2371                         if (strval_len(b) == 0)
2372                                 return -EINVAL;
2373                         ret = kstrtol(b, 0, &loc.shift);
2374                         if (ret)
2375                                 return ret;
2376                 } else {
2377                         return -EINVAL;
2378                 }
2379         }
2380         /* get arg BANK and ADDRESS */
2381         if (strval_len(b) == 0)
2382                 return -EINVAL;
2383         ret = kstrtouint(b, 0, &loc.bank);
2384         if (ret)
2385                 return ret;
2386         while (*b == ' ')
2387                 b++;
2388         if (strval_len(b) == 0)
2389                 return -EINVAL;
2390         ret = kstrtoul(b, 0, &loc.addr);
2391         if (ret)
2392                 return ret;
2393
2394         if (write) {
2395                 while (*b == ' ')
2396                         b++;
2397                 if (strval_len(b) == 0)
2398                         return -EINVAL;
2399                 ret = kstrtouint(b, 0, &val);
2400                 if (ret)
2401                         return ret;
2402         }
2403
2404         /* args are ok, update target cfg (mainly for read) */
2405         *cfg = loc;
2406
2407 #ifdef ABB_HWREG_DEBUG
2408         pr_warn("HWREG request: %s, %s,\n", (write) ? "write" : "read",
2409                 REG_FMT_DEC(cfg) ? "decimal" : "hexa");
2410         pr_warn("  addr=0x%08X, mask=0x%X, shift=%d" "value=0x%X\n",
2411                 cfg->addr, cfg->mask, cfg->shift, val);
2412 #endif
2413
2414         if (!write)
2415                 return 0;
2416
2417         ret = abx500_get_register_interruptible(dev,
2418                         (u8)cfg->bank, (u8)cfg->addr, &regvalue);
2419         if (ret < 0) {
2420                 dev_err(dev, "abx500_get_reg fail %d, %d\n",
2421                         ret, __LINE__);
2422                 return -EINVAL;
2423         }
2424
2425         if (cfg->shift >= 0) {
2426                 regvalue &= ~(cfg->mask << (cfg->shift));
2427                 val = (val & cfg->mask) << (cfg->shift);
2428         } else {
2429                 regvalue &= ~(cfg->mask >> (-cfg->shift));
2430                 val = (val & cfg->mask) >> (-cfg->shift);
2431         }
2432         val = val | regvalue;
2433
2434         ret = abx500_set_register_interruptible(dev,
2435                         (u8)cfg->bank, (u8)cfg->addr, (u8)val);
2436         if (ret < 0) {
2437                 pr_err("abx500_set_reg failed %d, %d", ret, __LINE__);
2438                 return -EINVAL;
2439         }
2440
2441         return 0;
2442 }
2443
2444 static ssize_t ab8500_hwreg_write(struct file *file,
2445         const char __user *user_buf, size_t count, loff_t *ppos)
2446 {
2447         struct device *dev = ((struct seq_file *)(file->private_data))->private;
2448         char buf[128];
2449         int buf_size, ret;
2450
2451         /* Get userspace string and assure termination */
2452         buf_size = min(count, (sizeof(buf)-1));
2453         if (copy_from_user(buf, user_buf, buf_size))
2454                 return -EFAULT;
2455         buf[buf_size] = 0;
2456
2457         /* get args and process */
2458         ret = hwreg_common_write(buf, &hwreg_cfg, dev);
2459         return (ret) ? ret : buf_size;
2460 }
2461
2462 /*
2463  * - irq subscribe/unsubscribe stuff
2464  */
2465 static int ab8500_subscribe_unsubscribe_print(struct seq_file *s, void *p)
2466 {
2467         seq_printf(s, "%d\n", irq_first);
2468
2469         return 0;
2470 }
2471
2472 static int ab8500_subscribe_unsubscribe_open(struct inode *inode,
2473                                              struct file *file)
2474 {
2475         return single_open(file, ab8500_subscribe_unsubscribe_print,
2476                 inode->i_private);
2477 }
2478
2479 /*
2480  * Userspace should use poll() on this file. When an event occur
2481  * the blocking poll will be released.
2482  */
2483 static ssize_t show_irq(struct device *dev,
2484                         struct device_attribute *attr, char *buf)
2485 {
2486         unsigned long name;
2487         unsigned int irq_index;
2488         int err;
2489
2490         err = kstrtoul(attr->attr.name, 0, &name);
2491         if (err)
2492                 return err;
2493
2494         irq_index = name - irq_first;
2495         if (irq_index >= num_irqs)
2496                 return -EINVAL;
2497
2498         return sprintf(buf, "%u\n", irq_count[irq_index]);
2499 }
2500
2501 static ssize_t ab8500_subscribe_write(struct file *file,
2502                                       const char __user *user_buf,
2503                                       size_t count, loff_t *ppos)
2504 {
2505         struct device *dev = ((struct seq_file *)(file->private_data))->private;
2506         unsigned long user_val;
2507         int err;
2508         unsigned int irq_index;
2509
2510         err = kstrtoul_from_user(user_buf, count, 0, &user_val);
2511         if (err)
2512                 return err;
2513
2514         if (user_val < irq_first) {
2515                 dev_err(dev, "debugfs error input < %d\n", irq_first);
2516                 return -EINVAL;
2517         }
2518         if (user_val > irq_last) {
2519                 dev_err(dev, "debugfs error input > %d\n", irq_last);
2520                 return -EINVAL;
2521         }
2522
2523         irq_index = user_val - irq_first;
2524         if (irq_index >= num_irqs)
2525                 return -EINVAL;
2526
2527         /*
2528          * This will create a sysfs file named <irq-nr> which userspace can
2529          * use to select or poll and get the AB8500 events
2530          */
2531         dev_attr[irq_index] = kmalloc(sizeof(struct device_attribute),
2532                 GFP_KERNEL);
2533         if (!dev_attr[irq_index])
2534                 return -ENOMEM;
2535
2536         event_name[irq_index] = kmalloc(count, GFP_KERNEL);
2537         if (!event_name[irq_index])
2538                 return -ENOMEM;
2539
2540         sprintf(event_name[irq_index], "%lu", user_val);
2541         dev_attr[irq_index]->show = show_irq;
2542         dev_attr[irq_index]->store = NULL;
2543         dev_attr[irq_index]->attr.name = event_name[irq_index];
2544         dev_attr[irq_index]->attr.mode = S_IRUGO;
2545         err = sysfs_create_file(&dev->kobj, &dev_attr[irq_index]->attr);
2546         if (err < 0) {
2547                 pr_info("sysfs_create_file failed %d\n", err);
2548                 return err;
2549         }
2550
2551         err = request_threaded_irq(user_val, NULL, ab8500_debug_handler,
2552                                    IRQF_SHARED | IRQF_NO_SUSPEND | IRQF_ONESHOT,
2553                                    "ab8500-debug", &dev->kobj);
2554         if (err < 0) {
2555                 pr_info("request_threaded_irq failed %d, %lu\n",
2556                         err, user_val);
2557                 sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr);
2558                 return err;
2559         }
2560
2561         return count;
2562 }
2563
2564 static ssize_t ab8500_unsubscribe_write(struct file *file,
2565                                         const char __user *user_buf,
2566                                         size_t count, loff_t *ppos)
2567 {
2568         struct device *dev = ((struct seq_file *)(file->private_data))->private;
2569         unsigned long user_val;
2570         int err;
2571         unsigned int irq_index;
2572
2573         err = kstrtoul_from_user(user_buf, count, 0, &user_val);
2574         if (err)
2575                 return err;
2576
2577         if (user_val < irq_first) {
2578                 dev_err(dev, "debugfs error input < %d\n", irq_first);
2579                 return -EINVAL;
2580         }
2581         if (user_val > irq_last) {
2582                 dev_err(dev, "debugfs error input > %d\n", irq_last);
2583                 return -EINVAL;
2584         }
2585
2586         irq_index = user_val - irq_first;
2587         if (irq_index >= num_irqs)
2588                 return -EINVAL;
2589
2590         /* Set irq count to 0 when unsubscribe */
2591         irq_count[irq_index] = 0;
2592
2593         if (dev_attr[irq_index])
2594                 sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr);
2595
2596
2597         free_irq(user_val, &dev->kobj);
2598         kfree(event_name[irq_index]);
2599         kfree(dev_attr[irq_index]);
2600
2601         return count;
2602 }
2603
2604 /*
2605  * - several deubgfs nodes fops
2606  */
2607
2608 static const struct file_operations ab8500_bank_fops = {
2609         .open = ab8500_bank_open,
2610         .write = ab8500_bank_write,
2611         .read = seq_read,
2612         .llseek = seq_lseek,
2613         .release = single_release,
2614         .owner = THIS_MODULE,
2615 };
2616
2617 static const struct file_operations ab8500_address_fops = {
2618         .open = ab8500_address_open,
2619         .write = ab8500_address_write,
2620         .read = seq_read,
2621         .llseek = seq_lseek,
2622         .release = single_release,
2623         .owner = THIS_MODULE,
2624 };
2625
2626 static const struct file_operations ab8500_val_fops = {
2627         .open = ab8500_val_open,
2628         .write = ab8500_val_write,
2629         .read = seq_read,
2630         .llseek = seq_lseek,
2631         .release = single_release,
2632         .owner = THIS_MODULE,
2633 };
2634
2635 static const struct file_operations ab8500_subscribe_fops = {
2636         .open = ab8500_subscribe_unsubscribe_open,
2637         .write = ab8500_subscribe_write,
2638         .read = seq_read,
2639         .llseek = seq_lseek,
2640         .release = single_release,
2641         .owner = THIS_MODULE,
2642 };
2643
2644 static const struct file_operations ab8500_unsubscribe_fops = {
2645         .open = ab8500_subscribe_unsubscribe_open,
2646         .write = ab8500_unsubscribe_write,
2647         .read = seq_read,
2648         .llseek = seq_lseek,
2649         .release = single_release,
2650         .owner = THIS_MODULE,
2651 };
2652
2653 static const struct file_operations ab8500_hwreg_fops = {
2654         .open = ab8500_hwreg_open,
2655         .write = ab8500_hwreg_write,
2656         .read = seq_read,
2657         .llseek = seq_lseek,
2658         .release = single_release,
2659         .owner = THIS_MODULE,
2660 };
2661
2662 static struct dentry *ab8500_dir;
2663 static struct dentry *ab8500_gpadc_dir;
2664
2665 static int ab8500_debug_probe(struct platform_device *plf)
2666 {
2667         struct dentry *file;
2668         struct ab8500 *ab8500;
2669         struct resource *res;
2670
2671         debug_bank = AB8500_MISC;
2672         debug_address = AB8500_REV_REG & 0x00FF;
2673
2674         ab8500 = dev_get_drvdata(plf->dev.parent);
2675         num_irqs = ab8500->mask_size;
2676
2677         irq_count = devm_kzalloc(&plf->dev,
2678                                  sizeof(*irq_count)*num_irqs, GFP_KERNEL);
2679         if (!irq_count)
2680                 return -ENOMEM;
2681
2682         dev_attr = devm_kzalloc(&plf->dev,
2683                                 sizeof(*dev_attr)*num_irqs, GFP_KERNEL);
2684         if (!dev_attr)
2685                 return -ENOMEM;
2686
2687         event_name = devm_kzalloc(&plf->dev,
2688                                   sizeof(*event_name)*num_irqs, GFP_KERNEL);
2689         if (!event_name)
2690                 return -ENOMEM;
2691
2692         res = platform_get_resource_byname(plf, 0, "IRQ_AB8500");
2693         if (!res) {
2694                 dev_err(&plf->dev, "AB8500 irq not found, err %d\n", irq_first);
2695                 return -ENXIO;
2696         }
2697         irq_ab8500 = res->start;
2698
2699         irq_first = platform_get_irq_byname(plf, "IRQ_FIRST");
2700         if (irq_first < 0) {
2701                 dev_err(&plf->dev, "First irq not found, err %d\n", irq_first);
2702                 return irq_first;
2703         }
2704
2705         irq_last = platform_get_irq_byname(plf, "IRQ_LAST");
2706         if (irq_last < 0) {
2707                 dev_err(&plf->dev, "Last irq not found, err %d\n", irq_last);
2708                 return irq_last;
2709         }
2710
2711         ab8500_dir = debugfs_create_dir(AB8500_NAME_STRING, NULL);
2712         if (!ab8500_dir)
2713                 goto err;
2714
2715         ab8500_gpadc_dir = debugfs_create_dir(AB8500_ADC_NAME_STRING,
2716                                               ab8500_dir);
2717         if (!ab8500_gpadc_dir)
2718                 goto err;
2719
2720         file = debugfs_create_file("all-bank-registers", S_IRUGO, ab8500_dir,
2721                                    &plf->dev, &ab8500_bank_registers_fops);
2722         if (!file)
2723                 goto err;
2724
2725         file = debugfs_create_file("all-banks", S_IRUGO, ab8500_dir,
2726                                    &plf->dev, &ab8500_all_banks_fops);
2727         if (!file)
2728                 goto err;
2729
2730         file = debugfs_create_file("register-bank",
2731                                    (S_IRUGO | S_IWUSR | S_IWGRP),
2732                                    ab8500_dir, &plf->dev, &ab8500_bank_fops);
2733         if (!file)
2734                 goto err;
2735
2736         file = debugfs_create_file("register-address",
2737                                    (S_IRUGO | S_IWUSR | S_IWGRP),
2738                                    ab8500_dir, &plf->dev, &ab8500_address_fops);
2739         if (!file)
2740                 goto err;
2741
2742         file = debugfs_create_file("register-value",
2743                                    (S_IRUGO | S_IWUSR | S_IWGRP),
2744                                    ab8500_dir, &plf->dev, &ab8500_val_fops);
2745         if (!file)
2746                 goto err;
2747
2748         file = debugfs_create_file("irq-subscribe",
2749                                    (S_IRUGO | S_IWUSR | S_IWGRP), ab8500_dir,
2750                                    &plf->dev, &ab8500_subscribe_fops);
2751         if (!file)
2752                 goto err;
2753
2754         if (is_ab8500(ab8500)) {
2755                 debug_ranges = ab8500_debug_ranges;
2756                 num_interrupt_lines = AB8500_NR_IRQS;
2757         } else if (is_ab8505(ab8500)) {
2758                 debug_ranges = ab8505_debug_ranges;
2759                 num_interrupt_lines = AB8505_NR_IRQS;
2760         } else if (is_ab9540(ab8500)) {
2761                 debug_ranges = ab8505_debug_ranges;
2762                 num_interrupt_lines = AB9540_NR_IRQS;
2763         } else if (is_ab8540(ab8500)) {
2764                 debug_ranges = ab8540_debug_ranges;
2765                 num_interrupt_lines = AB8540_NR_IRQS;
2766         }
2767
2768         file = debugfs_create_file("interrupts", (S_IRUGO), ab8500_dir,
2769                                    &plf->dev, &ab8500_interrupts_fops);
2770         if (!file)
2771                 goto err;
2772
2773         file = debugfs_create_file("irq-unsubscribe",
2774                                    (S_IRUGO | S_IWUSR | S_IWGRP), ab8500_dir,
2775                                    &plf->dev, &ab8500_unsubscribe_fops);
2776         if (!file)
2777                 goto err;
2778
2779         file = debugfs_create_file("hwreg", (S_IRUGO | S_IWUSR | S_IWGRP),
2780                                    ab8500_dir, &plf->dev, &ab8500_hwreg_fops);
2781         if (!file)
2782                 goto err;
2783
2784         file = debugfs_create_file("all-modem-registers",
2785                                    (S_IRUGO | S_IWUSR | S_IWGRP),
2786                                    ab8500_dir, &plf->dev, &ab8500_modem_fops);
2787         if (!file)
2788                 goto err;
2789
2790         file = debugfs_create_file("bat_ctrl", (S_IRUGO | S_IWUSR | S_IWGRP),
2791                                    ab8500_gpadc_dir, &plf->dev,
2792                                    &ab8500_gpadc_bat_ctrl_fops);
2793         if (!file)
2794                 goto err;
2795
2796         file = debugfs_create_file("btemp_ball", (S_IRUGO | S_IWUSR | S_IWGRP),
2797                                    ab8500_gpadc_dir,
2798                                    &plf->dev, &ab8500_gpadc_btemp_ball_fops);
2799         if (!file)
2800                 goto err;
2801
2802         file = debugfs_create_file("main_charger_v",
2803                                    (S_IRUGO | S_IWUSR | S_IWGRP),
2804                                    ab8500_gpadc_dir, &plf->dev,
2805                                    &ab8500_gpadc_main_charger_v_fops);
2806         if (!file)
2807                 goto err;
2808
2809         file = debugfs_create_file("acc_detect1",
2810                                    (S_IRUGO | S_IWUSR | S_IWGRP),
2811                                    ab8500_gpadc_dir, &plf->dev,
2812                                    &ab8500_gpadc_acc_detect1_fops);
2813         if (!file)
2814                 goto err;
2815
2816         file = debugfs_create_file("acc_detect2",
2817                                    (S_IRUGO | S_IWUSR | S_IWGRP),
2818                                    ab8500_gpadc_dir, &plf->dev,
2819                                    &ab8500_gpadc_acc_detect2_fops);
2820         if (!file)
2821                 goto err;
2822
2823         file = debugfs_create_file("adc_aux1", (S_IRUGO | S_IWUSR | S_IWGRP),
2824                                    ab8500_gpadc_dir, &plf->dev,
2825                                    &ab8500_gpadc_aux1_fops);
2826         if (!file)
2827                 goto err;
2828
2829         file = debugfs_create_file("adc_aux2", (S_IRUGO | S_IWUSR | S_IWGRP),
2830                                    ab8500_gpadc_dir, &plf->dev,
2831                                    &ab8500_gpadc_aux2_fops);
2832         if (!file)
2833                 goto err;
2834
2835         file = debugfs_create_file("main_bat_v", (S_IRUGO | S_IWUSR | S_IWGRP),
2836                                    ab8500_gpadc_dir, &plf->dev,
2837                                    &ab8500_gpadc_main_bat_v_fops);
2838         if (!file)
2839                 goto err;
2840
2841         file = debugfs_create_file("vbus_v", (S_IRUGO | S_IWUSR | S_IWGRP),
2842                                    ab8500_gpadc_dir, &plf->dev,
2843                                    &ab8500_gpadc_vbus_v_fops);
2844         if (!file)
2845                 goto err;
2846
2847         file = debugfs_create_file("main_charger_c",
2848                                    (S_IRUGO | S_IWUSR | S_IWGRP),
2849                                    ab8500_gpadc_dir, &plf->dev,
2850                                    &ab8500_gpadc_main_charger_c_fops);
2851         if (!file)
2852                 goto err;
2853
2854         file = debugfs_create_file("usb_charger_c",
2855                                    (S_IRUGO | S_IWUSR | S_IWGRP),
2856                                    ab8500_gpadc_dir,
2857                                    &plf->dev, &ab8500_gpadc_usb_charger_c_fops);
2858         if (!file)
2859                 goto err;
2860
2861         file = debugfs_create_file("bk_bat_v", (S_IRUGO | S_IWUSR | S_IWGRP),
2862                                    ab8500_gpadc_dir, &plf->dev,
2863                                    &ab8500_gpadc_bk_bat_v_fops);
2864         if (!file)
2865                 goto err;
2866
2867         file = debugfs_create_file("die_temp", (S_IRUGO | S_IWUSR | S_IWGRP),
2868                                    ab8500_gpadc_dir, &plf->dev,
2869                                    &ab8500_gpadc_die_temp_fops);
2870         if (!file)
2871                 goto err;
2872
2873         file = debugfs_create_file("usb_id", (S_IRUGO | S_IWUSR | S_IWGRP),
2874                                    ab8500_gpadc_dir, &plf->dev,
2875                                    &ab8500_gpadc_usb_id_fops);
2876         if (!file)
2877                 goto err;
2878
2879         if (is_ab8540(ab8500)) {
2880                 file = debugfs_create_file("xtal_temp",
2881                                            (S_IRUGO | S_IWUSR | S_IWGRP),
2882                                            ab8500_gpadc_dir, &plf->dev,
2883                                            &ab8540_gpadc_xtal_temp_fops);
2884                 if (!file)
2885                         goto err;
2886                 file = debugfs_create_file("vbattruemeas",
2887                                            (S_IRUGO | S_IWUSR | S_IWGRP),
2888                                            ab8500_gpadc_dir, &plf->dev,
2889                                            &ab8540_gpadc_vbat_true_meas_fops);
2890                 if (!file)
2891                         goto err;
2892                 file = debugfs_create_file("batctrl_and_ibat",
2893                                         (S_IRUGO | S_IWUGO),
2894                                         ab8500_gpadc_dir,
2895                                         &plf->dev,
2896                                         &ab8540_gpadc_bat_ctrl_and_ibat_fops);
2897                 if (!file)
2898                         goto err;
2899                 file = debugfs_create_file("vbatmeas_and_ibat",
2900                                         (S_IRUGO | S_IWUGO),
2901                                         ab8500_gpadc_dir, &plf->dev,
2902                                         &ab8540_gpadc_vbat_meas_and_ibat_fops);
2903                 if (!file)
2904                         goto err;
2905                 file = debugfs_create_file("vbattruemeas_and_ibat",
2906                                 (S_IRUGO | S_IWUGO),
2907                                 ab8500_gpadc_dir,
2908                                 &plf->dev,
2909                                 &ab8540_gpadc_vbat_true_meas_and_ibat_fops);
2910                 if (!file)
2911                         goto err;
2912                 file = debugfs_create_file("battemp_and_ibat",
2913                         (S_IRUGO | S_IWUGO),
2914                         ab8500_gpadc_dir,
2915                         &plf->dev, &ab8540_gpadc_bat_temp_and_ibat_fops);
2916                 if (!file)
2917                         goto err;
2918                 file = debugfs_create_file("otp_calib",
2919                                 (S_IRUGO | S_IWUSR | S_IWGRP),
2920                                 ab8500_gpadc_dir,
2921                                 &plf->dev, &ab8540_gpadc_otp_calib_fops);
2922                 if (!file)
2923                         goto err;
2924         }
2925         file = debugfs_create_file("avg_sample", (S_IRUGO | S_IWUSR | S_IWGRP),
2926                                    ab8500_gpadc_dir, &plf->dev,
2927                                    &ab8500_gpadc_avg_sample_fops);
2928         if (!file)
2929                 goto err;
2930
2931         file = debugfs_create_file("trig_edge", (S_IRUGO | S_IWUSR | S_IWGRP),
2932                                    ab8500_gpadc_dir, &plf->dev,
2933                                    &ab8500_gpadc_trig_edge_fops);
2934         if (!file)
2935                 goto err;
2936
2937         file = debugfs_create_file("trig_timer", (S_IRUGO | S_IWUSR | S_IWGRP),
2938                                    ab8500_gpadc_dir, &plf->dev,
2939                                    &ab8500_gpadc_trig_timer_fops);
2940         if (!file)
2941                 goto err;
2942
2943         file = debugfs_create_file("conv_type", (S_IRUGO | S_IWUSR | S_IWGRP),
2944                                    ab8500_gpadc_dir, &plf->dev,
2945                                    &ab8500_gpadc_conv_type_fops);
2946         if (!file)
2947                 goto err;
2948
2949         return 0;
2950
2951 err:
2952         debugfs_remove_recursive(ab8500_dir);
2953         dev_err(&plf->dev, "failed to create debugfs entries.\n");
2954
2955         return -ENOMEM;
2956 }
2957
2958 static struct platform_driver ab8500_debug_driver = {
2959         .driver = {
2960                 .name = "ab8500-debug",
2961                 .suppress_bind_attrs = true,
2962         },
2963         .probe  = ab8500_debug_probe,
2964 };
2965
2966 static int __init ab8500_debug_init(void)
2967 {
2968         return platform_driver_register(&ab8500_debug_driver);
2969 }
2970 subsys_initcall(ab8500_debug_init);
This page took 0.201022 seconds and 4 git commands to generate.