]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/mfd/ab8500-debugfs.c
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[mirror_ubuntu-bionic-kernel.git] / drivers / mfd / ab8500-debugfs.c
CommitLineData
5814fc35
MW
1/*
2 * Copyright (C) ST-Ericsson SA 2010
3 *
4 * Author: Mattias Wallin <mattias.wallin@stericsson.com> for ST-Ericsson.
5 * License Terms: GNU General Public License v2
6 */
0fbce76e 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 */
5814fc35
MW
73
74#include <linux/seq_file.h>
75#include <linux/uaccess.h>
76#include <linux/fs.h>
4e36dd33 77#include <linux/module.h>
5814fc35
MW
78#include <linux/debugfs.h>
79#include <linux/platform_device.h>
4b8ac082
LJ
80#include <linux/interrupt.h>
81#include <linux/kobject.h>
82#include <linux/slab.h>
2cf64e26 83#include <linux/irq.h>
5814fc35
MW
84
85#include <linux/mfd/abx500.h>
0cd5b6d0 86#include <linux/mfd/abx500/ab8500.h>
1478a316 87#include <linux/mfd/abx500/ab8500-gpadc.h>
5814fc35 88
0fbce76e 89#ifdef CONFIG_DEBUG_FS
90#include <linux/string.h>
91#include <linux/ctype.h>
92#endif
93
5814fc35
MW
94static u32 debug_bank;
95static u32 debug_address;
96
6999181e 97static int irq_ab8500;
4b8ac082
LJ
98static int irq_first;
99static int irq_last;
ddba25f1
LW
100static u32 *irq_count;
101static int num_irqs;
0b337e70 102
ddba25f1
LW
103static struct device_attribute **dev_attr;
104static char **event_name;
4b8ac082 105
73482346
LJ
106static u8 avg_sample = SAMPLE_16;
107static u8 trig_edge = RISING_EDGE;
108static u8 conv_type = ADC_SW;
109static u8 trig_timer;
110
5814fc35
MW
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 */
117struct ab8500_reg_range {
d7b9f322
MW
118 u8 first;
119 u8 last;
120 u8 perm;
5814fc35
MW
121};
122
123/**
822672a7 124 * struct ab8500_prcmu_ranges
5814fc35
MW
125 * @num_ranges: the number of ranges in the list
126 * @bankid: bank identifier
127 * @range: the list of register ranges
128 */
822672a7 129struct ab8500_prcmu_ranges {
d7b9f322
MW
130 u8 num_ranges;
131 u8 bankid;
132 const struct ab8500_reg_range *range;
5814fc35
MW
133};
134
0fbce76e 135/* hwreg- "mask" and "shift" entries ressources */
136struct hwreg_cfg {
137 u32 bank; /* target bank */
138 u32 addr; /* target address */
139 uint fmt; /* format */
140 uint mask; /* read/write mask, applied before any bit shift */
141 int 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
147static 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
5814fc35 154#define AB8500_NAME_STRING "ab8500"
1478a316 155#define AB8500_ADC_NAME_STRING "gpadc"
40c064e4 156#define AB8500_NUM_BANKS 24
5814fc35
MW
157
158#define AB8500_REV_REG 0x80
159
9581ae39
LJ
160static struct ab8500_prcmu_ranges *debug_ranges;
161
8455eaee 162static struct ab8500_prcmu_ranges ab8500_debug_ranges[AB8500_NUM_BANKS] = {
d7b9f322
MW
163 [0x0] = {
164 .num_ranges = 0,
fad55a86 165 .range = NULL,
d7b9f322
MW
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 /* 0x80-0x8B is SIM registers and should
246 * not be accessed from here */
247 },
248 },
249 [AB8500_USB] = {
250 .num_ranges = 2,
251 .range = (struct ab8500_reg_range[]) {
252 {
253 .first = 0x80,
254 .last = 0x83,
255 },
256 {
257 .first = 0x87,
258 .last = 0x8A,
259 },
260 },
261 },
262 [AB8500_TVOUT] = {
263 .num_ranges = 9,
264 .range = (struct ab8500_reg_range[]) {
265 {
266 .first = 0x00,
267 .last = 0x12,
268 },
269 {
270 .first = 0x15,
271 .last = 0x17,
272 },
273 {
274 .first = 0x19,
275 .last = 0x21,
276 },
277 {
278 .first = 0x27,
279 .last = 0x2C,
280 },
281 {
282 .first = 0x41,
283 .last = 0x41,
284 },
285 {
286 .first = 0x45,
287 .last = 0x5B,
288 },
289 {
290 .first = 0x5D,
291 .last = 0x5D,
292 },
293 {
294 .first = 0x69,
295 .last = 0x69,
296 },
297 {
298 .first = 0x80,
299 .last = 0x81,
300 },
301 },
302 },
303 [AB8500_DBI] = {
304 .num_ranges = 0,
87fff232 305 .range = NULL,
d7b9f322
MW
306 },
307 [AB8500_ECI_AV_ACC] = {
308 .num_ranges = 1,
309 .range = (struct ab8500_reg_range[]) {
310 {
311 .first = 0x80,
312 .last = 0x82,
313 },
314 },
315 },
316 [0x9] = {
317 .num_ranges = 0,
87fff232 318 .range = NULL,
d7b9f322
MW
319 },
320 [AB8500_GPADC] = {
321 .num_ranges = 1,
322 .range = (struct ab8500_reg_range[]) {
323 {
324 .first = 0x00,
325 .last = 0x08,
326 },
327 },
328 },
329 [AB8500_CHARGER] = {
40c064e4 330 .num_ranges = 9,
d7b9f322
MW
331 .range = (struct ab8500_reg_range[]) {
332 {
333 .first = 0x00,
334 .last = 0x03,
335 },
336 {
337 .first = 0x05,
338 .last = 0x05,
339 },
340 {
341 .first = 0x40,
342 .last = 0x40,
343 },
344 {
345 .first = 0x42,
346 .last = 0x42,
347 },
348 {
349 .first = 0x44,
350 .last = 0x44,
351 },
352 {
353 .first = 0x50,
354 .last = 0x55,
355 },
356 {
357 .first = 0x80,
358 .last = 0x82,
359 },
360 {
361 .first = 0xC0,
362 .last = 0xC2,
363 },
40c064e4
PL
364 {
365 .first = 0xf5,
9581ae39 366 .last = 0xf6,
40c064e4 367 },
d7b9f322
MW
368 },
369 },
370 [AB8500_GAS_GAUGE] = {
371 .num_ranges = 3,
372 .range = (struct ab8500_reg_range[]) {
373 {
374 .first = 0x00,
375 .last = 0x00,
376 },
377 {
378 .first = 0x07,
379 .last = 0x0A,
380 },
381 {
382 .first = 0x10,
383 .last = 0x14,
384 },
385 },
386 },
40c064e4
PL
387 [AB8500_DEVELOPMENT] = {
388 .num_ranges = 1,
389 .range = (struct ab8500_reg_range[]) {
390 {
391 .first = 0x00,
392 .last = 0x00,
393 },
394 },
395 },
396 [AB8500_DEBUG] = {
397 .num_ranges = 1,
398 .range = (struct ab8500_reg_range[]) {
399 {
400 .first = 0x05,
401 .last = 0x07,
402 },
403 },
404 },
d7b9f322
MW
405 [AB8500_AUDIO] = {
406 .num_ranges = 1,
407 .range = (struct ab8500_reg_range[]) {
408 {
409 .first = 0x00,
410 .last = 0x6F,
411 },
412 },
413 },
414 [AB8500_INTERRUPT] = {
415 .num_ranges = 0,
87fff232 416 .range = NULL,
d7b9f322
MW
417 },
418 [AB8500_RTC] = {
419 .num_ranges = 1,
420 .range = (struct ab8500_reg_range[]) {
421 {
422 .first = 0x00,
423 .last = 0x0F,
424 },
425 },
426 },
427 [AB8500_MISC] = {
428 .num_ranges = 8,
429 .range = (struct ab8500_reg_range[]) {
430 {
431 .first = 0x00,
432 .last = 0x05,
433 },
434 {
435 .first = 0x10,
436 .last = 0x15,
437 },
438 {
439 .first = 0x20,
440 .last = 0x25,
441 },
442 {
443 .first = 0x30,
444 .last = 0x35,
445 },
446 {
447 .first = 0x40,
448 .last = 0x45,
449 },
450 {
451 .first = 0x50,
452 .last = 0x50,
453 },
454 {
455 .first = 0x60,
456 .last = 0x67,
457 },
458 {
459 .first = 0x80,
460 .last = 0x80,
461 },
462 },
463 },
464 [0x11] = {
465 .num_ranges = 0,
87fff232 466 .range = NULL,
d7b9f322
MW
467 },
468 [0x12] = {
469 .num_ranges = 0,
87fff232 470 .range = NULL,
d7b9f322
MW
471 },
472 [0x13] = {
473 .num_ranges = 0,
87fff232 474 .range = NULL,
d7b9f322
MW
475 },
476 [0x14] = {
477 .num_ranges = 0,
87fff232 478 .range = NULL,
d7b9f322
MW
479 },
480 [AB8500_OTP_EMUL] = {
481 .num_ranges = 1,
482 .range = (struct ab8500_reg_range[]) {
483 {
484 .first = 0x01,
485 .last = 0x0F,
486 },
487 },
488 },
5814fc35
MW
489};
490
8455eaee 491static struct ab8500_prcmu_ranges ab8505_debug_ranges[AB8500_NUM_BANKS] = {
9581ae39
LJ
492 [0x0] = {
493 .num_ranges = 0,
494 .range = NULL,
495 },
496 [AB8500_SYS_CTRL1_BLOCK] = {
497 .num_ranges = 5,
498 .range = (struct ab8500_reg_range[]) {
499 {
500 .first = 0x00,
501 .last = 0x04,
502 },
503 {
504 .first = 0x42,
505 .last = 0x42,
506 },
507 {
508 .first = 0x52,
509 .last = 0x52,
510 },
511 {
512 .first = 0x54,
513 .last = 0x57,
514 },
515 {
516 .first = 0x80,
517 .last = 0x83,
518 },
519 },
520 },
521 [AB8500_SYS_CTRL2_BLOCK] = {
522 .num_ranges = 5,
523 .range = (struct ab8500_reg_range[]) {
524 {
525 .first = 0x00,
526 .last = 0x0D,
527 },
528 {
529 .first = 0x0F,
530 .last = 0x17,
531 },
532 {
533 .first = 0x20,
534 .last = 0x20,
535 },
536 {
537 .first = 0x30,
538 .last = 0x30,
539 },
540 {
541 .first = 0x32,
542 .last = 0x3A,
543 },
544 },
545 },
546 [AB8500_REGU_CTRL1] = {
547 .num_ranges = 3,
548 .range = (struct ab8500_reg_range[]) {
549 {
550 .first = 0x00,
551 .last = 0x00,
552 },
553 {
554 .first = 0x03,
555 .last = 0x11,
556 },
557 {
558 .first = 0x80,
559 .last = 0x86,
560 },
561 },
562 },
563 [AB8500_REGU_CTRL2] = {
564 .num_ranges = 6,
565 .range = (struct ab8500_reg_range[]) {
566 {
567 .first = 0x00,
568 .last = 0x06,
569 },
570 {
571 .first = 0x08,
572 .last = 0x15,
573 },
574 {
575 .first = 0x17,
576 .last = 0x19,
577 },
578 {
579 .first = 0x1B,
580 .last = 0x1D,
581 },
582 {
583 .first = 0x1F,
584 .last = 0x30,
585 },
586 {
587 .first = 0x40,
588 .last = 0x48,
589 },
590 /* 0x80-0x8B is SIM registers and should
591 * not be accessed from here */
592 },
593 },
594 [AB8500_USB] = {
595 .num_ranges = 3,
596 .range = (struct ab8500_reg_range[]) {
597 {
598 .first = 0x80,
599 .last = 0x83,
600 },
601 {
602 .first = 0x87,
603 .last = 0x8A,
604 },
605 {
606 .first = 0x91,
607 .last = 0x94,
608 },
609 },
610 },
611 [AB8500_TVOUT] = {
612 .num_ranges = 0,
613 .range = NULL,
614 },
615 [AB8500_DBI] = {
616 .num_ranges = 0,
617 .range = NULL,
618 },
619 [AB8500_ECI_AV_ACC] = {
620 .num_ranges = 1,
621 .range = (struct ab8500_reg_range[]) {
622 {
623 .first = 0x80,
624 .last = 0x82,
625 },
626 },
627 },
628 [AB8500_RESERVED] = {
629 .num_ranges = 0,
630 .range = NULL,
631 },
632 [AB8500_GPADC] = {
633 .num_ranges = 1,
634 .range = (struct ab8500_reg_range[]) {
635 {
636 .first = 0x00,
637 .last = 0x08,
638 },
639 },
640 },
641 [AB8500_CHARGER] = {
642 .num_ranges = 9,
643 .range = (struct ab8500_reg_range[]) {
644 {
645 .first = 0x02,
646 .last = 0x03,
647 },
648 {
649 .first = 0x05,
650 .last = 0x05,
651 },
652 {
653 .first = 0x40,
654 .last = 0x44,
655 },
656 {
657 .first = 0x50,
658 .last = 0x57,
659 },
660 {
661 .first = 0x60,
662 .last = 0x60,
663 },
664 {
665 .first = 0xA0,
666 .last = 0xA7,
667 },
668 {
669 .first = 0xAF,
670 .last = 0xB2,
671 },
672 {
673 .first = 0xC0,
674 .last = 0xC2,
675 },
676 {
677 .first = 0xF5,
678 .last = 0xF5,
679 },
680 },
681 },
682 [AB8500_GAS_GAUGE] = {
683 .num_ranges = 3,
684 .range = (struct ab8500_reg_range[]) {
685 {
686 .first = 0x00,
687 .last = 0x00,
688 },
689 {
690 .first = 0x07,
691 .last = 0x0A,
692 },
693 {
694 .first = 0x10,
695 .last = 0x14,
696 },
697 },
698 },
699 [AB8500_AUDIO] = {
700 .num_ranges = 1,
701 .range = (struct ab8500_reg_range[]) {
702 {
703 .first = 0x00,
704 .last = 0x83,
705 },
706 },
707 },
708 [AB8500_INTERRUPT] = {
709 .num_ranges = 11,
710 .range = (struct ab8500_reg_range[]) {
711 {
712 .first = 0x00,
713 .last = 0x04,
714 },
715 {
716 .first = 0x06,
717 .last = 0x07,
718 },
719 {
720 .first = 0x09,
721 .last = 0x09,
722 },
723 {
724 .first = 0x0B,
725 .last = 0x0C,
726 },
727 {
728 .first = 0x12,
729 .last = 0x15,
730 },
731 {
732 .first = 0x18,
733 .last = 0x18,
734 },
735 /* Latch registers should not be read here */
736 {
737 .first = 0x40,
738 .last = 0x44,
739 },
740 {
741 .first = 0x46,
742 .last = 0x49,
743 },
744 {
745 .first = 0x4B,
746 .last = 0x4D,
747 },
748 {
749 .first = 0x52,
750 .last = 0x55,
751 },
752 {
753 .first = 0x58,
754 .last = 0x58,
755 },
756 /* LatchHier registers should not be read here */
757 },
758 },
759 [AB8500_RTC] = {
760 .num_ranges = 2,
761 .range = (struct ab8500_reg_range[]) {
762 {
763 .first = 0x00,
764 .last = 0x14,
765 },
766 {
767 .first = 0x16,
768 .last = 0x17,
769 },
770 },
771 },
772 [AB8500_MISC] = {
773 .num_ranges = 8,
774 .range = (struct ab8500_reg_range[]) {
775 {
776 .first = 0x00,
777 .last = 0x06,
778 },
779 {
780 .first = 0x10,
781 .last = 0x16,
782 },
783 {
784 .first = 0x20,
785 .last = 0x26,
786 },
787 {
788 .first = 0x30,
789 .last = 0x36,
790 },
791 {
792 .first = 0x40,
793 .last = 0x46,
794 },
795 {
796 .first = 0x50,
797 .last = 0x50,
798 },
799 {
800 .first = 0x60,
801 .last = 0x6B,
802 },
803 {
804 .first = 0x80,
805 .last = 0x82,
806 },
807 },
808 },
809 [AB8500_DEVELOPMENT] = {
810 .num_ranges = 2,
811 .range = (struct ab8500_reg_range[]) {
812 {
813 .first = 0x00,
814 .last = 0x00,
815 },
816 {
817 .first = 0x05,
818 .last = 0x05,
819 },
820 },
821 },
822 [AB8500_DEBUG] = {
823 .num_ranges = 1,
824 .range = (struct ab8500_reg_range[]) {
825 {
826 .first = 0x05,
827 .last = 0x07,
828 },
829 },
830 },
831 [AB8500_PROD_TEST] = {
832 .num_ranges = 0,
833 .range = NULL,
834 },
835 [AB8500_STE_TEST] = {
836 .num_ranges = 0,
837 .range = NULL,
838 },
839 [AB8500_OTP_EMUL] = {
840 .num_ranges = 1,
841 .range = (struct ab8500_reg_range[]) {
842 {
843 .first = 0x01,
844 .last = 0x15,
845 },
846 },
847 },
848};
849
8455eaee 850static struct ab8500_prcmu_ranges ab8540_debug_ranges[AB8500_NUM_BANKS] = {
971480f5
LJ
851 [AB8500_M_FSM_RANK] = {
852 .num_ranges = 1,
853 .range = (struct ab8500_reg_range[]) {
854 {
855 .first = 0x00,
856 .last = 0x0B,
857 },
858 },
859 },
860 [AB8500_SYS_CTRL1_BLOCK] = {
861 .num_ranges = 6,
862 .range = (struct ab8500_reg_range[]) {
863 {
864 .first = 0x00,
865 .last = 0x04,
866 },
867 {
868 .first = 0x42,
869 .last = 0x42,
870 },
871 {
872 .first = 0x50,
873 .last = 0x54,
874 },
875 {
876 .first = 0x57,
877 .last = 0x57,
878 },
879 {
880 .first = 0x80,
881 .last = 0x83,
882 },
883 {
884 .first = 0x90,
885 .last = 0x90,
886 },
887 },
888 },
889 [AB8500_SYS_CTRL2_BLOCK] = {
890 .num_ranges = 5,
891 .range = (struct ab8500_reg_range[]) {
892 {
893 .first = 0x00,
894 .last = 0x0D,
895 },
896 {
897 .first = 0x0F,
898 .last = 0x10,
899 },
900 {
901 .first = 0x20,
902 .last = 0x21,
903 },
904 {
905 .first = 0x32,
906 .last = 0x3C,
907 },
908 {
909 .first = 0x40,
910 .last = 0x42,
911 },
912 },
913 },
914 [AB8500_REGU_CTRL1] = {
915 .num_ranges = 4,
916 .range = (struct ab8500_reg_range[]) {
917 {
918 .first = 0x03,
919 .last = 0x15,
920 },
921 {
922 .first = 0x20,
923 .last = 0x20,
924 },
925 {
926 .first = 0x80,
927 .last = 0x85,
928 },
929 {
930 .first = 0x87,
931 .last = 0x88,
932 },
933 },
934 },
935 [AB8500_REGU_CTRL2] = {
936 .num_ranges = 8,
937 .range = (struct ab8500_reg_range[]) {
938 {
939 .first = 0x00,
940 .last = 0x06,
941 },
942 {
943 .first = 0x08,
944 .last = 0x15,
945 },
946 {
947 .first = 0x17,
948 .last = 0x19,
949 },
950 {
951 .first = 0x1B,
952 .last = 0x1D,
953 },
954 {
955 .first = 0x1F,
956 .last = 0x2F,
957 },
958 {
959 .first = 0x31,
960 .last = 0x3A,
961 },
962 {
963 .first = 0x43,
964 .last = 0x44,
965 },
966 {
967 .first = 0x48,
968 .last = 0x49,
969 },
970 },
971 },
972 [AB8500_USB] = {
973 .num_ranges = 3,
974 .range = (struct ab8500_reg_range[]) {
975 {
976 .first = 0x80,
977 .last = 0x83,
978 },
979 {
980 .first = 0x87,
981 .last = 0x8A,
982 },
983 {
984 .first = 0x91,
985 .last = 0x94,
986 },
987 },
988 },
989 [AB8500_TVOUT] = {
990 .num_ranges = 0,
991 .range = NULL
992 },
993 [AB8500_DBI] = {
994 .num_ranges = 4,
995 .range = (struct ab8500_reg_range[]) {
996 {
997 .first = 0x00,
998 .last = 0x07,
999 },
1000 {
1001 .first = 0x10,
1002 .last = 0x11,
1003 },
1004 {
1005 .first = 0x20,
1006 .last = 0x21,
1007 },
1008 {
1009 .first = 0x30,
1010 .last = 0x43,
1011 },
1012 },
1013 },
1014 [AB8500_ECI_AV_ACC] = {
1015 .num_ranges = 2,
1016 .range = (struct ab8500_reg_range[]) {
1017 {
1018 .first = 0x00,
1019 .last = 0x03,
1020 },
1021 {
1022 .first = 0x80,
1023 .last = 0x82,
1024 },
1025 },
1026 },
1027 [AB8500_RESERVED] = {
1028 .num_ranges = 0,
1029 .range = NULL,
1030 },
1031 [AB8500_GPADC] = {
1032 .num_ranges = 4,
1033 .range = (struct ab8500_reg_range[]) {
1034 {
1035 .first = 0x00,
1036 .last = 0x01,
1037 },
1038 {
1039 .first = 0x04,
1040 .last = 0x06,
1041 },
1042 {
1043 .first = 0x09,
1044 .last = 0x0A,
1045 },
1046 {
1047 .first = 0x10,
1048 .last = 0x14,
1049 },
1050 },
1051 },
1052 [AB8500_CHARGER] = {
1053 .num_ranges = 10,
1054 .range = (struct ab8500_reg_range[]) {
1055 {
1056 .first = 0x00,
1057 .last = 0x00,
1058 },
1059 {
1060 .first = 0x02,
1061 .last = 0x05,
1062 },
1063 {
1064 .first = 0x40,
1065 .last = 0x44,
1066 },
1067 {
1068 .first = 0x50,
1069 .last = 0x57,
1070 },
1071 {
1072 .first = 0x60,
1073 .last = 0x60,
1074 },
1075 {
1076 .first = 0x70,
1077 .last = 0x70,
1078 },
1079 {
1080 .first = 0xA0,
1081 .last = 0xA9,
1082 },
1083 {
1084 .first = 0xAF,
1085 .last = 0xB2,
1086 },
1087 {
1088 .first = 0xC0,
1089 .last = 0xC6,
1090 },
1091 {
1092 .first = 0xF5,
1093 .last = 0xF5,
1094 },
1095 },
1096 },
1097 [AB8500_GAS_GAUGE] = {
1098 .num_ranges = 3,
1099 .range = (struct ab8500_reg_range[]) {
1100 {
1101 .first = 0x00,
1102 .last = 0x00,
1103 },
1104 {
1105 .first = 0x07,
1106 .last = 0x0A,
1107 },
1108 {
1109 .first = 0x10,
1110 .last = 0x14,
1111 },
1112 },
1113 },
1114 [AB8500_AUDIO] = {
1115 .num_ranges = 1,
1116 .range = (struct ab8500_reg_range[]) {
1117 {
1118 .first = 0x00,
1119 .last = 0x9f,
1120 },
1121 },
1122 },
1123 [AB8500_INTERRUPT] = {
1124 .num_ranges = 6,
1125 .range = (struct ab8500_reg_range[]) {
1126 {
1127 .first = 0x00,
1128 .last = 0x05,
1129 },
1130 {
1131 .first = 0x0B,
1132 .last = 0x0D,
1133 },
1134 {
1135 .first = 0x12,
1136 .last = 0x20,
1137 },
1138 /* Latch registers should not be read here */
1139 {
1140 .first = 0x40,
1141 .last = 0x45,
1142 },
1143 {
1144 .first = 0x4B,
1145 .last = 0x4D,
1146 },
1147 {
1148 .first = 0x52,
1149 .last = 0x60,
1150 },
1151 /* LatchHier registers should not be read here */
1152 },
1153 },
1154 [AB8500_RTC] = {
1155 .num_ranges = 3,
1156 .range = (struct ab8500_reg_range[]) {
1157 {
1158 .first = 0x00,
1159 .last = 0x07,
1160 },
1161 {
1162 .first = 0x0B,
1163 .last = 0x18,
1164 },
1165 {
1166 .first = 0x20,
1167 .last = 0x25,
1168 },
1169 },
1170 },
1171 [AB8500_MISC] = {
1172 .num_ranges = 9,
1173 .range = (struct ab8500_reg_range[]) {
1174 {
1175 .first = 0x00,
1176 .last = 0x06,
1177 },
1178 {
1179 .first = 0x10,
1180 .last = 0x16,
1181 },
1182 {
1183 .first = 0x20,
1184 .last = 0x26,
1185 },
1186 {
1187 .first = 0x30,
1188 .last = 0x36,
1189 },
1190 {
1191 .first = 0x40,
1192 .last = 0x49,
1193 },
1194 {
1195 .first = 0x50,
1196 .last = 0x50,
1197 },
1198 {
1199 .first = 0x60,
1200 .last = 0x6B,
1201 },
1202 {
1203 .first = 0x70,
1204 .last = 0x74,
1205 },
1206 {
1207 .first = 0x80,
1208 .last = 0x82,
1209 },
1210 },
1211 },
1212 [AB8500_DEVELOPMENT] = {
1213 .num_ranges = 3,
1214 .range = (struct ab8500_reg_range[]) {
1215 {
1216 .first = 0x00,
1217 .last = 0x01,
1218 },
1219 {
1220 .first = 0x06,
1221 .last = 0x06,
1222 },
1223 {
1224 .first = 0x10,
1225 .last = 0x21,
1226 },
1227 },
1228 },
1229 [AB8500_DEBUG] = {
1230 .num_ranges = 3,
1231 .range = (struct ab8500_reg_range[]) {
1232 {
1233 .first = 0x01,
1234 .last = 0x0C,
1235 },
1236 {
1237 .first = 0x0E,
1238 .last = 0x11,
1239 },
1240 {
1241 .first = 0x80,
1242 .last = 0x81,
1243 },
1244 },
1245 },
1246 [AB8500_PROD_TEST] = {
1247 .num_ranges = 0,
1248 .range = NULL,
1249 },
1250 [AB8500_STE_TEST] = {
1251 .num_ranges = 0,
1252 .range = NULL,
1253 },
1254 [AB8500_OTP_EMUL] = {
1255 .num_ranges = 1,
1256 .range = (struct ab8500_reg_range[]) {
1257 {
1258 .first = 0x00,
1259 .last = 0x3F,
1260 },
1261 },
1262 },
1263};
1264
1265
4b8ac082
LJ
1266static irqreturn_t ab8500_debug_handler(int irq, void *data)
1267{
1268 char buf[16];
1269 struct kobject *kobj = (struct kobject *)data;
0b337e70 1270 unsigned int irq_abb = irq - irq_first;
4b8ac082 1271
ddba25f1 1272 if (irq_abb < num_irqs)
0b337e70 1273 irq_count[irq_abb]++;
4b8ac082
LJ
1274 /*
1275 * This makes it possible to use poll for events (POLLPRI | POLLERR)
0b337e70 1276 * from userspace on sysfs file named <irq-nr>
4b8ac082 1277 */
0b337e70 1278 sprintf(buf, "%d", irq);
4b8ac082
LJ
1279 sysfs_notify(kobj, NULL, buf);
1280
1281 return IRQ_HANDLED;
1282}
1283
42002c6d
MYK
1284/* Prints to seq_file or log_buf */
1285static int ab8500_registers_print(struct device *dev, u32 bank,
1286 struct seq_file *s)
5814fc35 1287{
d7b9f322 1288 unsigned int i;
d7b9f322 1289
d7b9f322
MW
1290 for (i = 0; i < debug_ranges[bank].num_ranges; i++) {
1291 u32 reg;
1292
1293 for (reg = debug_ranges[bank].range[i].first;
1294 reg <= debug_ranges[bank].range[i].last;
1295 reg++) {
1296 u8 value;
1297 int err;
1298
1299 err = abx500_get_register_interruptible(dev,
1300 (u8)bank, (u8)reg, &value);
1301 if (err < 0) {
1302 dev_err(dev, "ab->read fail %d\n", err);
1303 return err;
1304 }
1305
42002c6d 1306 if (s) {
cfc0849c 1307 err = seq_printf(s, " [0x%02X/0x%02X]: 0x%02X\n",
42002c6d
MYK
1308 bank, reg, value);
1309 if (err < 0) {
42002c6d
MYK
1310 /* Error is not returned here since
1311 * the output is wanted in any case */
1312 return 0;
1313 }
1314 } else {
cfc0849c
MW
1315 printk(KERN_INFO" [0x%02X/0x%02X]: 0x%02X\n",
1316 bank, reg, value);
d7b9f322
MW
1317 }
1318 }
1319 }
1320 return 0;
5814fc35
MW
1321}
1322
42002c6d
MYK
1323static int ab8500_print_bank_registers(struct seq_file *s, void *p)
1324{
1325 struct device *dev = s->private;
1326 u32 bank = debug_bank;
1327
1328 seq_printf(s, AB8500_NAME_STRING " register values:\n");
1329
cfc0849c 1330 seq_printf(s, " bank 0x%02X:\n", bank);
42002c6d
MYK
1331
1332 ab8500_registers_print(dev, bank, s);
1333 return 0;
1334}
1335
5814fc35
MW
1336static int ab8500_registers_open(struct inode *inode, struct file *file)
1337{
42002c6d 1338 return single_open(file, ab8500_print_bank_registers, inode->i_private);
5814fc35
MW
1339}
1340
1341static const struct file_operations ab8500_registers_fops = {
d7b9f322
MW
1342 .open = ab8500_registers_open,
1343 .read = seq_read,
1344 .llseek = seq_lseek,
1345 .release = single_release,
1346 .owner = THIS_MODULE,
5814fc35
MW
1347};
1348
42002c6d
MYK
1349static int ab8500_print_all_banks(struct seq_file *s, void *p)
1350{
1351 struct device *dev = s->private;
1352 unsigned int i;
1353 int err;
1354
1355 seq_printf(s, AB8500_NAME_STRING " register values:\n");
1356
971480f5 1357 for (i = 0; i < AB8500_NUM_BANKS; i++) {
cfc0849c 1358 err = seq_printf(s, " bank 0x%02X:\n", i);
42002c6d
MYK
1359
1360 ab8500_registers_print(dev, i, s);
1361 }
1362 return 0;
1363}
1364
1d843a6c
MYK
1365/* Dump registers to kernel log */
1366void ab8500_dump_all_banks(struct device *dev)
1367{
1368 unsigned int i;
1369
1370 printk(KERN_INFO"ab8500 register values:\n");
1371
1372 for (i = 1; i < AB8500_NUM_BANKS; i++) {
cfc0849c 1373 printk(KERN_INFO" bank 0x%02X:\n", i);
1d843a6c
MYK
1374 ab8500_registers_print(dev, i, NULL);
1375 }
1376}
1377
5ff9090f
LJ
1378/* Space for 500 registers. */
1379#define DUMP_MAX_REGS 700
8455eaee 1380static struct ab8500_register_dump
5ff9090f
LJ
1381{
1382 u8 bank;
1383 u8 reg;
1384 u8 value;
5ff9090f
LJ
1385} ab8500_complete_register_dump[DUMP_MAX_REGS];
1386
1387extern int prcmu_abb_read(u8 slave, u8 reg, u8 *value, u8 size);
1388
1389/* This shall only be called upon kernel panic! */
1390void ab8500_dump_all_banks_to_mem(void)
1391{
1392 int i, r = 0;
1393 u8 bank;
222460cb 1394 int err = 0;
5ff9090f
LJ
1395
1396 pr_info("Saving all ABB registers at \"ab8500_complete_register_dump\" "
1397 "for crash analyze.\n");
1398
971480f5 1399 for (bank = 0; bank < AB8500_NUM_BANKS; bank++) {
5ff9090f
LJ
1400 for (i = 0; i < debug_ranges[bank].num_ranges; i++) {
1401 u8 reg;
1402
1403 for (reg = debug_ranges[bank].range[i].first;
1404 reg <= debug_ranges[bank].range[i].last;
1405 reg++) {
1406 u8 value;
5ff9090f
LJ
1407
1408 err = prcmu_abb_read(bank, reg, &value, 1);
1409
222460cb
JA
1410 if (err < 0)
1411 goto out;
1412
5ff9090f
LJ
1413 ab8500_complete_register_dump[r].bank = bank;
1414 ab8500_complete_register_dump[r].reg = reg;
1415 ab8500_complete_register_dump[r].value = value;
1416
1417 r++;
1418
1419 if (r >= DUMP_MAX_REGS) {
1420 pr_err("%s: too many register to dump!\n",
1421 __func__);
222460cb
JA
1422 err = -EINVAL;
1423 goto out;
5ff9090f
LJ
1424 }
1425 }
1426 }
1427 }
222460cb
JA
1428out:
1429 if (err >= 0)
1430 pr_info("Saved all ABB registers.\n");
1431 else
1432 pr_info("Failed to save all ABB registers.\n");
5ff9090f
LJ
1433}
1434
42002c6d
MYK
1435static int ab8500_all_banks_open(struct inode *inode, struct file *file)
1436{
1437 struct seq_file *s;
1438 int err;
1439
1440 err = single_open(file, ab8500_print_all_banks, inode->i_private);
1441 if (!err) {
1442 /* Default buf size in seq_read is not enough */
1443 s = (struct seq_file *)file->private_data;
1444 s->size = (PAGE_SIZE * 2);
1445 s->buf = kmalloc(s->size, GFP_KERNEL);
1446 if (!s->buf) {
1447 single_release(inode, file);
1448 err = -ENOMEM;
1449 }
1450 }
1451 return err;
1452}
1453
1454static const struct file_operations ab8500_all_banks_fops = {
1455 .open = ab8500_all_banks_open,
1456 .read = seq_read,
1457 .llseek = seq_lseek,
1458 .release = single_release,
1459 .owner = THIS_MODULE,
1460};
1461
5814fc35
MW
1462static int ab8500_bank_print(struct seq_file *s, void *p)
1463{
cfc0849c 1464 return seq_printf(s, "0x%02X\n", debug_bank);
5814fc35
MW
1465}
1466
1467static int ab8500_bank_open(struct inode *inode, struct file *file)
1468{
d7b9f322 1469 return single_open(file, ab8500_bank_print, inode->i_private);
5814fc35
MW
1470}
1471
1472static ssize_t ab8500_bank_write(struct file *file,
d7b9f322
MW
1473 const char __user *user_buf,
1474 size_t count, loff_t *ppos)
5814fc35 1475{
d7b9f322 1476 struct device *dev = ((struct seq_file *)(file->private_data))->private;
d7b9f322
MW
1477 unsigned long user_bank;
1478 int err;
1479
8504d638 1480 err = kstrtoul_from_user(user_buf, count, 0, &user_bank);
d7b9f322 1481 if (err)
8504d638 1482 return err;
d7b9f322
MW
1483
1484 if (user_bank >= AB8500_NUM_BANKS) {
1485 dev_err(dev, "debugfs error input > number of banks\n");
1486 return -EINVAL;
1487 }
1488
1489 debug_bank = user_bank;
1490
8504d638 1491 return count;
5814fc35
MW
1492}
1493
1494static int ab8500_address_print(struct seq_file *s, void *p)
1495{
d7b9f322 1496 return seq_printf(s, "0x%02X\n", debug_address);
5814fc35
MW
1497}
1498
1499static int ab8500_address_open(struct inode *inode, struct file *file)
1500{
d7b9f322 1501 return single_open(file, ab8500_address_print, inode->i_private);
5814fc35
MW
1502}
1503
1504static ssize_t ab8500_address_write(struct file *file,
9f9ba15f
LJ
1505 const char __user *user_buf,
1506 size_t count, loff_t *ppos)
5814fc35 1507{
d7b9f322 1508 struct device *dev = ((struct seq_file *)(file->private_data))->private;
d7b9f322
MW
1509 unsigned long user_address;
1510 int err;
1511
8504d638 1512 err = kstrtoul_from_user(user_buf, count, 0, &user_address);
d7b9f322 1513 if (err)
8504d638
PH
1514 return err;
1515
d7b9f322
MW
1516 if (user_address > 0xff) {
1517 dev_err(dev, "debugfs error input > 0xff\n");
1518 return -EINVAL;
1519 }
1520 debug_address = user_address;
7b830ae4 1521
8504d638 1522 return count;
5814fc35
MW
1523}
1524
1525static int ab8500_val_print(struct seq_file *s, void *p)
1526{
d7b9f322
MW
1527 struct device *dev = s->private;
1528 int ret;
1529 u8 regvalue;
1530
1531 ret = abx500_get_register_interruptible(dev,
1532 (u8)debug_bank, (u8)debug_address, &regvalue);
1533 if (ret < 0) {
1534 dev_err(dev, "abx500_get_reg fail %d, %d\n",
1535 ret, __LINE__);
1536 return -EINVAL;
1537 }
1538 seq_printf(s, "0x%02X\n", regvalue);
1539
1540 return 0;
5814fc35
MW
1541}
1542
1543static int ab8500_val_open(struct inode *inode, struct file *file)
1544{
d7b9f322 1545 return single_open(file, ab8500_val_print, inode->i_private);
5814fc35
MW
1546}
1547
1548static ssize_t ab8500_val_write(struct file *file,
9f9ba15f
LJ
1549 const char __user *user_buf,
1550 size_t count, loff_t *ppos)
5814fc35 1551{
d7b9f322 1552 struct device *dev = ((struct seq_file *)(file->private_data))->private;
d7b9f322
MW
1553 unsigned long user_val;
1554 int err;
1555
8504d638 1556 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
d7b9f322 1557 if (err)
8504d638
PH
1558 return err;
1559
d7b9f322
MW
1560 if (user_val > 0xff) {
1561 dev_err(dev, "debugfs error input > 0xff\n");
1562 return -EINVAL;
1563 }
1564 err = abx500_set_register_interruptible(dev,
1565 (u8)debug_bank, debug_address, (u8)user_val);
1566 if (err < 0) {
1567 printk(KERN_ERR "abx500_set_reg failed %d, %d", err, __LINE__);
1568 return -EINVAL;
1569 }
1570
8504d638 1571 return count;
5814fc35
MW
1572}
1573
8f0eb43b
BJ
1574/*
1575 * Interrupt status
1576 */
1577static u32 num_interrupts[AB8500_MAX_NR_IRQS];
2cf64e26 1578static u32 num_wake_interrupts[AB8500_MAX_NR_IRQS];
8f0eb43b
BJ
1579static int num_interrupt_lines;
1580
2cf64e26
JA
1581bool __attribute__((weak)) suspend_test_wake_cause_interrupt_is_mine(u32 my_int)
1582{
1583 return false;
1584}
1585
8f0eb43b
BJ
1586void ab8500_debug_register_interrupt(int line)
1587{
2cf64e26 1588 if (line < num_interrupt_lines) {
8f0eb43b 1589 num_interrupts[line]++;
6999181e 1590 if (suspend_test_wake_cause_interrupt_is_mine(irq_ab8500))
2cf64e26
JA
1591 num_wake_interrupts[line]++;
1592 }
8f0eb43b
BJ
1593}
1594
1595static int ab8500_interrupts_print(struct seq_file *s, void *p)
1596{
1597 int line;
1598
2cf64e26
JA
1599 seq_printf(s, "name: number: number of: wake:\n");
1600
1601 for (line = 0; line < num_interrupt_lines; line++) {
1602 struct irq_desc *desc = irq_to_desc(line + irq_first);
8f0eb43b 1603
2cf64e26
JA
1604 seq_printf(s, "%3i: %6i %4i", line,
1605 num_interrupts[line],
1606 num_wake_interrupts[line]);
1607
1608 if (desc && desc->name)
1609 seq_printf(s, "-%-8s", desc->name);
7c0b2380
DC
1610 if (desc && desc->action) {
1611 struct irqaction *action = desc->action;
1612
2cf64e26
JA
1613 seq_printf(s, " %s", action->name);
1614 while ((action = action->next) != NULL)
1615 seq_printf(s, ", %s", action->name);
1616 }
1617 seq_putc(s, '\n');
1618 }
8f0eb43b
BJ
1619
1620 return 0;
1621}
1622
1623static int ab8500_interrupts_open(struct inode *inode, struct file *file)
1624{
1625 return single_open(file, ab8500_interrupts_print, inode->i_private);
1626}
1627
0fbce76e 1628/*
1629 * - HWREG DB8500 formated routines
1630 */
1631static int ab8500_hwreg_print(struct seq_file *s, void *d)
1632{
1633 struct device *dev = s->private;
1634 int ret;
1635 u8 regvalue;
1636
1637 ret = abx500_get_register_interruptible(dev,
1638 (u8)hwreg_cfg.bank, (u8)hwreg_cfg.addr, &regvalue);
1639 if (ret < 0) {
1640 dev_err(dev, "abx500_get_reg fail %d, %d\n",
1641 ret, __LINE__);
1642 return -EINVAL;
1643 }
1644
1645 if (hwreg_cfg.shift >= 0)
1646 regvalue >>= hwreg_cfg.shift;
1647 else
1648 regvalue <<= -hwreg_cfg.shift;
1649 regvalue &= hwreg_cfg.mask;
1650
1651 if (REG_FMT_DEC(&hwreg_cfg))
1652 seq_printf(s, "%d\n", regvalue);
1653 else
1654 seq_printf(s, "0x%02X\n", regvalue);
1655 return 0;
1656}
1657
1658static int ab8500_hwreg_open(struct inode *inode, struct file *file)
1659{
1660 return single_open(file, ab8500_hwreg_print, inode->i_private);
1661}
1662
c7ebaee2
LJ
1663#define AB8500_SUPPLY_CONTROL_CONFIG_1 0x01
1664#define AB8500_SUPPLY_CONTROL_REG 0x00
1665#define AB8500_FIRST_SIM_REG 0x80
1666#define AB8500_LAST_SIM_REG 0x8B
1667#define AB8505_LAST_SIM_REG 0x8C
1668
1669static int ab8500_print_modem_registers(struct seq_file *s, void *p)
1670{
1671 struct device *dev = s->private;
1672 struct ab8500 *ab8500;
1673 int err;
1674 u8 value;
1675 u8 orig_value;
1676 u32 bank = AB8500_REGU_CTRL2;
1677 u32 last_sim_reg = AB8500_LAST_SIM_REG;
1678 u32 reg;
1679
1680 ab8500 = dev_get_drvdata(dev->parent);
1681 dev_warn(dev, "WARNING! This operation can interfer with modem side\n"
1682 "and should only be done with care\n");
1683
1684 err = abx500_get_register_interruptible(dev,
1685 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG, &orig_value);
1686 if (err < 0) {
1687 dev_err(dev, "ab->read fail %d\n", err);
1688 return err;
1689 }
1690 /* Config 1 will allow APE side to read SIM registers */
1691 err = abx500_set_register_interruptible(dev,
1692 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG,
1693 AB8500_SUPPLY_CONTROL_CONFIG_1);
1694 if (err < 0) {
1695 dev_err(dev, "ab->write fail %d\n", err);
1696 return err;
1697 }
1698
1699 seq_printf(s, " bank 0x%02X:\n", bank);
1700
1701 if (is_ab9540(ab8500) || is_ab8505(ab8500))
1702 last_sim_reg = AB8505_LAST_SIM_REG;
1703
1704 for (reg = AB8500_FIRST_SIM_REG; reg <= last_sim_reg; reg++) {
1705 err = abx500_get_register_interruptible(dev,
1706 bank, reg, &value);
1707 if (err < 0) {
1708 dev_err(dev, "ab->read fail %d\n", err);
1709 return err;
1710 }
1711 err = seq_printf(s, " [0x%02X/0x%02X]: 0x%02X\n",
1712 bank, reg, value);
1713 }
1714 err = abx500_set_register_interruptible(dev,
1715 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG, orig_value);
1716 if (err < 0) {
1717 dev_err(dev, "ab->write fail %d\n", err);
1718 return err;
1719 }
1720 return 0;
1721}
1722
1723static int ab8500_modem_open(struct inode *inode, struct file *file)
1724{
1725 return single_open(file, ab8500_print_modem_registers, inode->i_private);
1726}
1727
1728static const struct file_operations ab8500_modem_fops = {
1729 .open = ab8500_modem_open,
1730 .read = seq_read,
1731 .llseek = seq_lseek,
1732 .release = single_release,
1733 .owner = THIS_MODULE,
1734};
1735
1478a316
JB
1736static int ab8500_gpadc_bat_ctrl_print(struct seq_file *s, void *p)
1737{
1738 int bat_ctrl_raw;
1739 int bat_ctrl_convert;
1740 struct ab8500_gpadc *gpadc;
1741
8908c049 1742 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
73482346
LJ
1743 bat_ctrl_raw = ab8500_gpadc_read_raw(gpadc, BAT_CTRL,
1744 avg_sample, trig_edge, trig_timer, conv_type);
1478a316 1745 bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc,
73482346 1746 BAT_CTRL, bat_ctrl_raw);
1478a316
JB
1747
1748 return seq_printf(s, "%d,0x%X\n",
9f9ba15f 1749 bat_ctrl_convert, bat_ctrl_raw);
1478a316
JB
1750}
1751
1752static int ab8500_gpadc_bat_ctrl_open(struct inode *inode, struct file *file)
1753{
1754 return single_open(file, ab8500_gpadc_bat_ctrl_print, inode->i_private);
1755}
1756
1757static const struct file_operations ab8500_gpadc_bat_ctrl_fops = {
1758 .open = ab8500_gpadc_bat_ctrl_open,
1759 .read = seq_read,
1760 .llseek = seq_lseek,
1761 .release = single_release,
1762 .owner = THIS_MODULE,
1763};
1764
1765static int ab8500_gpadc_btemp_ball_print(struct seq_file *s, void *p)
1766{
1767 int btemp_ball_raw;
1768 int btemp_ball_convert;
1769 struct ab8500_gpadc *gpadc;
1770
8908c049 1771 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
73482346
LJ
1772 btemp_ball_raw = ab8500_gpadc_read_raw(gpadc, BTEMP_BALL,
1773 avg_sample, trig_edge, trig_timer, conv_type);
1478a316 1774 btemp_ball_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL,
73482346 1775 btemp_ball_raw);
1478a316
JB
1776
1777 return seq_printf(s,
9f9ba15f 1778 "%d,0x%X\n", btemp_ball_convert, btemp_ball_raw);
1478a316
JB
1779}
1780
1781static int ab8500_gpadc_btemp_ball_open(struct inode *inode,
9f9ba15f 1782 struct file *file)
1478a316
JB
1783{
1784 return single_open(file, ab8500_gpadc_btemp_ball_print, inode->i_private);
1785}
1786
1787static const struct file_operations ab8500_gpadc_btemp_ball_fops = {
1788 .open = ab8500_gpadc_btemp_ball_open,
1789 .read = seq_read,
1790 .llseek = seq_lseek,
1791 .release = single_release,
1792 .owner = THIS_MODULE,
1793};
1794
1795static int ab8500_gpadc_main_charger_v_print(struct seq_file *s, void *p)
1796{
1797 int main_charger_v_raw;
1798 int main_charger_v_convert;
1799 struct ab8500_gpadc *gpadc;
1800
8908c049 1801 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
73482346
LJ
1802 main_charger_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_V,
1803 avg_sample, trig_edge, trig_timer, conv_type);
1478a316 1804 main_charger_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
73482346 1805 MAIN_CHARGER_V, main_charger_v_raw);
1478a316
JB
1806
1807 return seq_printf(s, "%d,0x%X\n",
1808 main_charger_v_convert, main_charger_v_raw);
1809}
1810
1811static int ab8500_gpadc_main_charger_v_open(struct inode *inode,
9f9ba15f 1812 struct file *file)
1478a316
JB
1813{
1814 return single_open(file, ab8500_gpadc_main_charger_v_print,
9f9ba15f 1815 inode->i_private);
1478a316
JB
1816}
1817
1818static const struct file_operations ab8500_gpadc_main_charger_v_fops = {
1819 .open = ab8500_gpadc_main_charger_v_open,
1820 .read = seq_read,
1821 .llseek = seq_lseek,
1822 .release = single_release,
1823 .owner = THIS_MODULE,
1824};
1825
1826static int ab8500_gpadc_acc_detect1_print(struct seq_file *s, void *p)
1827{
1828 int acc_detect1_raw;
1829 int acc_detect1_convert;
1830 struct ab8500_gpadc *gpadc;
1831
8908c049 1832 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
73482346
LJ
1833 acc_detect1_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT1,
1834 avg_sample, trig_edge, trig_timer, conv_type);
1478a316 1835 acc_detect1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ACC_DETECT1,
73482346 1836 acc_detect1_raw);
1478a316
JB
1837
1838 return seq_printf(s, "%d,0x%X\n",
9f9ba15f 1839 acc_detect1_convert, acc_detect1_raw);
1478a316
JB
1840}
1841
1842static int ab8500_gpadc_acc_detect1_open(struct inode *inode,
9f9ba15f 1843 struct file *file)
1478a316
JB
1844{
1845 return single_open(file, ab8500_gpadc_acc_detect1_print,
9f9ba15f 1846 inode->i_private);
1478a316
JB
1847}
1848
1849static const struct file_operations ab8500_gpadc_acc_detect1_fops = {
1850 .open = ab8500_gpadc_acc_detect1_open,
1851 .read = seq_read,
1852 .llseek = seq_lseek,
1853 .release = single_release,
1854 .owner = THIS_MODULE,
1855};
1856
1857static int ab8500_gpadc_acc_detect2_print(struct seq_file *s, void *p)
1858{
1859 int acc_detect2_raw;
1860 int acc_detect2_convert;
1861 struct ab8500_gpadc *gpadc;
1862
8908c049 1863 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
73482346
LJ
1864 acc_detect2_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT2,
1865 avg_sample, trig_edge, trig_timer, conv_type);
1478a316 1866 acc_detect2_convert = ab8500_gpadc_ad_to_voltage(gpadc,
73482346 1867 ACC_DETECT2, acc_detect2_raw);
1478a316
JB
1868
1869 return seq_printf(s, "%d,0x%X\n",
9f9ba15f 1870 acc_detect2_convert, acc_detect2_raw);
1478a316
JB
1871}
1872
1873static int ab8500_gpadc_acc_detect2_open(struct inode *inode,
1874 struct file *file)
1875{
1876 return single_open(file, ab8500_gpadc_acc_detect2_print,
9f9ba15f 1877 inode->i_private);
1478a316
JB
1878}
1879
1880static const struct file_operations ab8500_gpadc_acc_detect2_fops = {
1881 .open = ab8500_gpadc_acc_detect2_open,
1882 .read = seq_read,
1883 .llseek = seq_lseek,
1884 .release = single_release,
1885 .owner = THIS_MODULE,
1886};
1887
1888static int ab8500_gpadc_aux1_print(struct seq_file *s, void *p)
1889{
1890 int aux1_raw;
1891 int aux1_convert;
1892 struct ab8500_gpadc *gpadc;
1893
8908c049 1894 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
73482346
LJ
1895 aux1_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX1,
1896 avg_sample, trig_edge, trig_timer, conv_type);
1478a316 1897 aux1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX1,
73482346 1898 aux1_raw);
1478a316
JB
1899
1900 return seq_printf(s, "%d,0x%X\n",
9f9ba15f 1901 aux1_convert, aux1_raw);
1478a316
JB
1902}
1903
1904static int ab8500_gpadc_aux1_open(struct inode *inode, struct file *file)
1905{
1906 return single_open(file, ab8500_gpadc_aux1_print, inode->i_private);
1907}
1908
1909static const struct file_operations ab8500_gpadc_aux1_fops = {
1910 .open = ab8500_gpadc_aux1_open,
1911 .read = seq_read,
1912 .llseek = seq_lseek,
1913 .release = single_release,
1914 .owner = THIS_MODULE,
1915};
1916
1917static int ab8500_gpadc_aux2_print(struct seq_file *s, void *p)
1918{
1919 int aux2_raw;
1920 int aux2_convert;
1921 struct ab8500_gpadc *gpadc;
1922
8908c049 1923 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
73482346
LJ
1924 aux2_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX2,
1925 avg_sample, trig_edge, trig_timer, conv_type);
1478a316 1926 aux2_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX2,
73482346 1927 aux2_raw);
1478a316
JB
1928
1929 return seq_printf(s, "%d,0x%X\n",
1930 aux2_convert, aux2_raw);
1931}
1932
1933static int ab8500_gpadc_aux2_open(struct inode *inode, struct file *file)
1934{
1935 return single_open(file, ab8500_gpadc_aux2_print, inode->i_private);
1936}
1937
1938static const struct file_operations ab8500_gpadc_aux2_fops = {
1939 .open = ab8500_gpadc_aux2_open,
1940 .read = seq_read,
1941 .llseek = seq_lseek,
1942 .release = single_release,
1943 .owner = THIS_MODULE,
1944};
1945
1946static int ab8500_gpadc_main_bat_v_print(struct seq_file *s, void *p)
1947{
1948 int main_bat_v_raw;
1949 int main_bat_v_convert;
1950 struct ab8500_gpadc *gpadc;
1951
8908c049 1952 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
73482346
LJ
1953 main_bat_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_BAT_V,
1954 avg_sample, trig_edge, trig_timer, conv_type);
1478a316 1955 main_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V,
73482346 1956 main_bat_v_raw);
1478a316
JB
1957
1958 return seq_printf(s, "%d,0x%X\n",
9f9ba15f 1959 main_bat_v_convert, main_bat_v_raw);
1478a316
JB
1960}
1961
1962static int ab8500_gpadc_main_bat_v_open(struct inode *inode,
9f9ba15f 1963 struct file *file)
1478a316
JB
1964{
1965 return single_open(file, ab8500_gpadc_main_bat_v_print, inode->i_private);
1966}
1967
1968static const struct file_operations ab8500_gpadc_main_bat_v_fops = {
1969 .open = ab8500_gpadc_main_bat_v_open,
1970 .read = seq_read,
1971 .llseek = seq_lseek,
1972 .release = single_release,
1973 .owner = THIS_MODULE,
1974};
1975
1976static int ab8500_gpadc_vbus_v_print(struct seq_file *s, void *p)
1977{
1978 int vbus_v_raw;
1979 int vbus_v_convert;
1980 struct ab8500_gpadc *gpadc;
1981
8908c049 1982 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
73482346
LJ
1983 vbus_v_raw = ab8500_gpadc_read_raw(gpadc, VBUS_V,
1984 avg_sample, trig_edge, trig_timer, conv_type);
1478a316 1985 vbus_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, VBUS_V,
73482346 1986 vbus_v_raw);
1478a316
JB
1987
1988 return seq_printf(s, "%d,0x%X\n",
9f9ba15f 1989 vbus_v_convert, vbus_v_raw);
1478a316
JB
1990}
1991
1992static int ab8500_gpadc_vbus_v_open(struct inode *inode, struct file *file)
1993{
1994 return single_open(file, ab8500_gpadc_vbus_v_print, inode->i_private);
1995}
1996
1997static const struct file_operations ab8500_gpadc_vbus_v_fops = {
1998 .open = ab8500_gpadc_vbus_v_open,
1999 .read = seq_read,
2000 .llseek = seq_lseek,
2001 .release = single_release,
2002 .owner = THIS_MODULE,
2003};
2004
2005static int ab8500_gpadc_main_charger_c_print(struct seq_file *s, void *p)
2006{
2007 int main_charger_c_raw;
2008 int main_charger_c_convert;
2009 struct ab8500_gpadc *gpadc;
2010
8908c049 2011 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
73482346
LJ
2012 main_charger_c_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_C,
2013 avg_sample, trig_edge, trig_timer, conv_type);
1478a316 2014 main_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
73482346 2015 MAIN_CHARGER_C, main_charger_c_raw);
1478a316
JB
2016
2017 return seq_printf(s, "%d,0x%X\n",
9f9ba15f 2018 main_charger_c_convert, main_charger_c_raw);
1478a316
JB
2019}
2020
2021static int ab8500_gpadc_main_charger_c_open(struct inode *inode,
2022 struct file *file)
2023{
2024 return single_open(file, ab8500_gpadc_main_charger_c_print,
9f9ba15f 2025 inode->i_private);
1478a316
JB
2026}
2027
2028static const struct file_operations ab8500_gpadc_main_charger_c_fops = {
2029 .open = ab8500_gpadc_main_charger_c_open,
2030 .read = seq_read,
2031 .llseek = seq_lseek,
2032 .release = single_release,
2033 .owner = THIS_MODULE,
2034};
2035
2036static int ab8500_gpadc_usb_charger_c_print(struct seq_file *s, void *p)
2037{
2038 int usb_charger_c_raw;
2039 int usb_charger_c_convert;
2040 struct ab8500_gpadc *gpadc;
2041
8908c049 2042 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
73482346
LJ
2043 usb_charger_c_raw = ab8500_gpadc_read_raw(gpadc, USB_CHARGER_C,
2044 avg_sample, trig_edge, trig_timer, conv_type);
1478a316 2045 usb_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
73482346 2046 USB_CHARGER_C, usb_charger_c_raw);
1478a316
JB
2047
2048 return seq_printf(s, "%d,0x%X\n",
9f9ba15f 2049 usb_charger_c_convert, usb_charger_c_raw);
1478a316
JB
2050}
2051
2052static int ab8500_gpadc_usb_charger_c_open(struct inode *inode,
2053 struct file *file)
2054{
2055 return single_open(file, ab8500_gpadc_usb_charger_c_print,
9f9ba15f 2056 inode->i_private);
1478a316
JB
2057}
2058
2059static const struct file_operations ab8500_gpadc_usb_charger_c_fops = {
2060 .open = ab8500_gpadc_usb_charger_c_open,
2061 .read = seq_read,
2062 .llseek = seq_lseek,
2063 .release = single_release,
2064 .owner = THIS_MODULE,
2065};
2066
2067static int ab8500_gpadc_bk_bat_v_print(struct seq_file *s, void *p)
2068{
2069 int bk_bat_v_raw;
2070 int bk_bat_v_convert;
2071 struct ab8500_gpadc *gpadc;
2072
8908c049 2073 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
73482346
LJ
2074 bk_bat_v_raw = ab8500_gpadc_read_raw(gpadc, BK_BAT_V,
2075 avg_sample, trig_edge, trig_timer, conv_type);
1478a316 2076 bk_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
73482346 2077 BK_BAT_V, bk_bat_v_raw);
1478a316
JB
2078
2079 return seq_printf(s, "%d,0x%X\n",
9f9ba15f 2080 bk_bat_v_convert, bk_bat_v_raw);
1478a316
JB
2081}
2082
2083static int ab8500_gpadc_bk_bat_v_open(struct inode *inode, struct file *file)
2084{
2085 return single_open(file, ab8500_gpadc_bk_bat_v_print, inode->i_private);
2086}
2087
2088static const struct file_operations ab8500_gpadc_bk_bat_v_fops = {
2089 .open = ab8500_gpadc_bk_bat_v_open,
2090 .read = seq_read,
2091 .llseek = seq_lseek,
2092 .release = single_release,
2093 .owner = THIS_MODULE,
2094};
2095
2096static int ab8500_gpadc_die_temp_print(struct seq_file *s, void *p)
2097{
2098 int die_temp_raw;
2099 int die_temp_convert;
2100 struct ab8500_gpadc *gpadc;
2101
8908c049 2102 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
73482346
LJ
2103 die_temp_raw = ab8500_gpadc_read_raw(gpadc, DIE_TEMP,
2104 avg_sample, trig_edge, trig_timer, conv_type);
1478a316 2105 die_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, DIE_TEMP,
73482346 2106 die_temp_raw);
1478a316
JB
2107
2108 return seq_printf(s, "%d,0x%X\n",
9f9ba15f 2109 die_temp_convert, die_temp_raw);
1478a316
JB
2110}
2111
2112static int ab8500_gpadc_die_temp_open(struct inode *inode, struct file *file)
2113{
2114 return single_open(file, ab8500_gpadc_die_temp_print, inode->i_private);
2115}
2116
2117static const struct file_operations ab8500_gpadc_die_temp_fops = {
2118 .open = ab8500_gpadc_die_temp_open,
2119 .read = seq_read,
2120 .llseek = seq_lseek,
2121 .release = single_release,
2122 .owner = THIS_MODULE,
2123};
2124
127629d7
LJ
2125static int ab8500_gpadc_usb_id_print(struct seq_file *s, void *p)
2126{
2127 int usb_id_raw;
2128 int usb_id_convert;
2129 struct ab8500_gpadc *gpadc;
2130
2131 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2132 usb_id_raw = ab8500_gpadc_read_raw(gpadc, USB_ID,
2133 avg_sample, trig_edge, trig_timer, conv_type);
2134 usb_id_convert = ab8500_gpadc_ad_to_voltage(gpadc, USB_ID,
2135 usb_id_raw);
2136
2137 return seq_printf(s, "%d,0x%X\n",
9f9ba15f 2138 usb_id_convert, usb_id_raw);
127629d7
LJ
2139}
2140
2141static int ab8500_gpadc_usb_id_open(struct inode *inode, struct file *file)
2142{
2143 return single_open(file, ab8500_gpadc_usb_id_print, inode->i_private);
2144}
2145
2146static const struct file_operations ab8500_gpadc_usb_id_fops = {
2147 .open = ab8500_gpadc_usb_id_open,
2148 .read = seq_read,
2149 .llseek = seq_lseek,
2150 .release = single_release,
2151 .owner = THIS_MODULE,
2152};
2153
bc6b4132
LJ
2154static int ab8540_gpadc_xtal_temp_print(struct seq_file *s, void *p)
2155{
2156 int xtal_temp_raw;
2157 int xtal_temp_convert;
2158 struct ab8500_gpadc *gpadc;
2159
2160 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2161 xtal_temp_raw = ab8500_gpadc_read_raw(gpadc, XTAL_TEMP,
2162 avg_sample, trig_edge, trig_timer, conv_type);
2163 xtal_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, XTAL_TEMP,
2164 xtal_temp_raw);
2165
2166 return seq_printf(s, "%d,0x%X\n",
9f9ba15f 2167 xtal_temp_convert, xtal_temp_raw);
bc6b4132
LJ
2168}
2169
2170static int ab8540_gpadc_xtal_temp_open(struct inode *inode, struct file *file)
2171{
2172 return single_open(file, ab8540_gpadc_xtal_temp_print,
9f9ba15f 2173 inode->i_private);
bc6b4132
LJ
2174}
2175
2176static const struct file_operations ab8540_gpadc_xtal_temp_fops = {
2177 .open = ab8540_gpadc_xtal_temp_open,
2178 .read = seq_read,
2179 .llseek = seq_lseek,
2180 .release = single_release,
2181 .owner = THIS_MODULE,
2182};
2183
2184static int ab8540_gpadc_vbat_true_meas_print(struct seq_file *s, void *p)
2185{
2186 int vbat_true_meas_raw;
2187 int vbat_true_meas_convert;
2188 struct ab8500_gpadc *gpadc;
2189
2190 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2191 vbat_true_meas_raw = ab8500_gpadc_read_raw(gpadc, VBAT_TRUE_MEAS,
2192 avg_sample, trig_edge, trig_timer, conv_type);
2193 vbat_true_meas_convert = ab8500_gpadc_ad_to_voltage(gpadc, VBAT_TRUE_MEAS,
2194 vbat_true_meas_raw);
2195
2196 return seq_printf(s, "%d,0x%X\n",
9f9ba15f 2197 vbat_true_meas_convert, vbat_true_meas_raw);
bc6b4132
LJ
2198}
2199
2200static int ab8540_gpadc_vbat_true_meas_open(struct inode *inode,
2201 struct file *file)
2202{
2203 return single_open(file, ab8540_gpadc_vbat_true_meas_print,
9f9ba15f 2204 inode->i_private);
bc6b4132
LJ
2205}
2206
2207static const struct file_operations ab8540_gpadc_vbat_true_meas_fops = {
2208 .open = ab8540_gpadc_vbat_true_meas_open,
2209 .read = seq_read,
2210 .llseek = seq_lseek,
2211 .release = single_release,
2212 .owner = THIS_MODULE,
2213};
2214
2215static int ab8540_gpadc_bat_ctrl_and_ibat_print(struct seq_file *s, void *p)
2216{
2217 int bat_ctrl_raw;
2218 int bat_ctrl_convert;
2219 int ibat_raw;
2220 int ibat_convert;
2221 struct ab8500_gpadc *gpadc;
2222
2223 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2224 bat_ctrl_raw = ab8500_gpadc_double_read_raw(gpadc, BAT_CTRL_AND_IBAT,
2225 avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
2226
2227 bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc, BAT_CTRL,
2228 bat_ctrl_raw);
2229 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2230 ibat_raw);
2231
2232 return seq_printf(s, "%d,0x%X\n" "%d,0x%X\n",
9f9ba15f
LJ
2233 bat_ctrl_convert, bat_ctrl_raw,
2234 ibat_convert, ibat_raw);
bc6b4132
LJ
2235}
2236
2237static int ab8540_gpadc_bat_ctrl_and_ibat_open(struct inode *inode,
2238 struct file *file)
2239{
2240 return single_open(file, ab8540_gpadc_bat_ctrl_and_ibat_print,
9f9ba15f 2241 inode->i_private);
bc6b4132
LJ
2242}
2243
2244static const struct file_operations ab8540_gpadc_bat_ctrl_and_ibat_fops = {
2245 .open = ab8540_gpadc_bat_ctrl_and_ibat_open,
2246 .read = seq_read,
2247 .llseek = seq_lseek,
2248 .release = single_release,
2249 .owner = THIS_MODULE,
2250};
2251
2252static int ab8540_gpadc_vbat_meas_and_ibat_print(struct seq_file *s, void *p)
2253{
2254 int vbat_meas_raw;
2255 int vbat_meas_convert;
2256 int ibat_raw;
2257 int ibat_convert;
2258 struct ab8500_gpadc *gpadc;
2259
2260 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2261 vbat_meas_raw = ab8500_gpadc_double_read_raw(gpadc, VBAT_MEAS_AND_IBAT,
2262 avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
2263 vbat_meas_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V,
2264 vbat_meas_raw);
2265 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2266 ibat_raw);
2267
2268 return seq_printf(s, "%d,0x%X\n" "%d,0x%X\n",
9f9ba15f
LJ
2269 vbat_meas_convert, vbat_meas_raw,
2270 ibat_convert, ibat_raw);
bc6b4132
LJ
2271}
2272
2273static int ab8540_gpadc_vbat_meas_and_ibat_open(struct inode *inode,
2274 struct file *file)
2275{
2276 return single_open(file, ab8540_gpadc_vbat_meas_and_ibat_print,
9f9ba15f 2277 inode->i_private);
bc6b4132
LJ
2278}
2279
2280static const struct file_operations ab8540_gpadc_vbat_meas_and_ibat_fops = {
2281 .open = ab8540_gpadc_vbat_meas_and_ibat_open,
2282 .read = seq_read,
2283 .llseek = seq_lseek,
2284 .release = single_release,
2285 .owner = THIS_MODULE,
2286};
2287
2288static int ab8540_gpadc_vbat_true_meas_and_ibat_print(struct seq_file *s, void *p)
2289{
2290 int vbat_true_meas_raw;
2291 int vbat_true_meas_convert;
2292 int ibat_raw;
2293 int ibat_convert;
2294 struct ab8500_gpadc *gpadc;
2295
2296 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2297 vbat_true_meas_raw = ab8500_gpadc_double_read_raw(gpadc,
2298 VBAT_TRUE_MEAS_AND_IBAT, avg_sample, trig_edge,
2299 trig_timer, conv_type, &ibat_raw);
2300 vbat_true_meas_convert = ab8500_gpadc_ad_to_voltage(gpadc,
2301 VBAT_TRUE_MEAS, vbat_true_meas_raw);
2302 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2303 ibat_raw);
2304
2305 return seq_printf(s, "%d,0x%X\n" "%d,0x%X\n",
9f9ba15f
LJ
2306 vbat_true_meas_convert, vbat_true_meas_raw,
2307 ibat_convert, ibat_raw);
bc6b4132
LJ
2308}
2309
2310static int ab8540_gpadc_vbat_true_meas_and_ibat_open(struct inode *inode,
2311 struct file *file)
2312{
2313 return single_open(file, ab8540_gpadc_vbat_true_meas_and_ibat_print,
9f9ba15f 2314 inode->i_private);
bc6b4132
LJ
2315}
2316
2317static const struct file_operations ab8540_gpadc_vbat_true_meas_and_ibat_fops = {
2318 .open = ab8540_gpadc_vbat_true_meas_and_ibat_open,
2319 .read = seq_read,
2320 .llseek = seq_lseek,
2321 .release = single_release,
2322 .owner = THIS_MODULE,
2323};
2324
2325static int ab8540_gpadc_bat_temp_and_ibat_print(struct seq_file *s, void *p)
2326{
2327 int bat_temp_raw;
2328 int bat_temp_convert;
2329 int ibat_raw;
2330 int ibat_convert;
2331 struct ab8500_gpadc *gpadc;
2332
2333 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2334 bat_temp_raw = ab8500_gpadc_double_read_raw(gpadc, BAT_TEMP_AND_IBAT,
2335 avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
2336 bat_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL,
2337 bat_temp_raw);
2338 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2339 ibat_raw);
2340
2341 return seq_printf(s, "%d,0x%X\n" "%d,0x%X\n",
9f9ba15f
LJ
2342 bat_temp_convert, bat_temp_raw,
2343 ibat_convert, ibat_raw);
bc6b4132
LJ
2344}
2345
2346static int ab8540_gpadc_bat_temp_and_ibat_open(struct inode *inode,
2347 struct file *file)
2348{
2349 return single_open(file, ab8540_gpadc_bat_temp_and_ibat_print,
9f9ba15f 2350 inode->i_private);
bc6b4132
LJ
2351}
2352
2353static const struct file_operations ab8540_gpadc_bat_temp_and_ibat_fops = {
2354 .open = ab8540_gpadc_bat_temp_and_ibat_open,
2355 .read = seq_read,
2356 .llseek = seq_lseek,
2357 .release = single_release,
2358 .owner = THIS_MODULE,
2359};
2360
2361static int ab8540_gpadc_otp_cal_print(struct seq_file *s, void *p)
2362{
2363 struct ab8500_gpadc *gpadc;
2364 u16 vmain_l, vmain_h, btemp_l, btemp_h;
2365 u16 vbat_l, vbat_h, ibat_l, ibat_h;
2366
2367 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2368 ab8540_gpadc_get_otp(gpadc, &vmain_l, &vmain_h, &btemp_l, &btemp_h,
2369 &vbat_l, &vbat_h, &ibat_l, &ibat_h);
2370 return seq_printf(s, "VMAIN_L:0x%X\n"
9f9ba15f
LJ
2371 "VMAIN_H:0x%X\n"
2372 "BTEMP_L:0x%X\n"
2373 "BTEMP_H:0x%X\n"
2374 "VBAT_L:0x%X\n"
2375 "VBAT_H:0x%X\n"
2376 "IBAT_L:0x%X\n"
2377 "IBAT_H:0x%X\n",
2378 vmain_l, vmain_h, btemp_l, btemp_h, vbat_l, vbat_h, ibat_l, ibat_h);
bc6b4132
LJ
2379}
2380
2381static int ab8540_gpadc_otp_cal_open(struct inode *inode, struct file *file)
2382{
2383 return single_open(file, ab8540_gpadc_otp_cal_print, inode->i_private);
2384}
2385
2386static const struct file_operations ab8540_gpadc_otp_calib_fops = {
2387 .open = ab8540_gpadc_otp_cal_open,
2388 .read = seq_read,
2389 .llseek = seq_lseek,
2390 .release = single_release,
2391 .owner = THIS_MODULE,
2392};
2393
73482346
LJ
2394static int ab8500_gpadc_avg_sample_print(struct seq_file *s, void *p)
2395{
2396 return seq_printf(s, "%d\n", avg_sample);
2397}
2398
2399static int ab8500_gpadc_avg_sample_open(struct inode *inode, struct file *file)
2400{
2401 return single_open(file, ab8500_gpadc_avg_sample_print,
9f9ba15f 2402 inode->i_private);
73482346
LJ
2403}
2404
2405static ssize_t ab8500_gpadc_avg_sample_write(struct file *file,
2406 const char __user *user_buf,
2407 size_t count, loff_t *ppos)
2408{
2409 struct device *dev = ((struct seq_file *)(file->private_data))->private;
73482346
LJ
2410 unsigned long user_avg_sample;
2411 int err;
2412
7b830ae4 2413 err = kstrtoul_from_user(user_buf, count, 0, &user_avg_sample);
73482346 2414 if (err)
7b830ae4 2415 return err;
2416
73482346
LJ
2417 if ((user_avg_sample == SAMPLE_1) || (user_avg_sample == SAMPLE_4)
2418 || (user_avg_sample == SAMPLE_8)
2419 || (user_avg_sample == SAMPLE_16)) {
2420 avg_sample = (u8) user_avg_sample;
2421 } else {
2422 dev_err(dev, "debugfs error input: "
2423 "should be egal to 1, 4, 8 or 16\n");
2424 return -EINVAL;
2425 }
7b830ae4 2426
2427 return count;
73482346
LJ
2428}
2429
2430static const struct file_operations ab8500_gpadc_avg_sample_fops = {
2431 .open = ab8500_gpadc_avg_sample_open,
2432 .read = seq_read,
2433 .write = ab8500_gpadc_avg_sample_write,
2434 .llseek = seq_lseek,
2435 .release = single_release,
2436 .owner = THIS_MODULE,
2437};
2438
2439static int ab8500_gpadc_trig_edge_print(struct seq_file *s, void *p)
2440{
2441 return seq_printf(s, "%d\n", trig_edge);
2442}
2443
2444static int ab8500_gpadc_trig_edge_open(struct inode *inode, struct file *file)
2445{
2446 return single_open(file, ab8500_gpadc_trig_edge_print,
9f9ba15f 2447 inode->i_private);
73482346
LJ
2448}
2449
2450static ssize_t ab8500_gpadc_trig_edge_write(struct file *file,
2451 const char __user *user_buf,
2452 size_t count, loff_t *ppos)
2453{
2454 struct device *dev = ((struct seq_file *)(file->private_data))->private;
73482346
LJ
2455 unsigned long user_trig_edge;
2456 int err;
2457
7b830ae4 2458 err = kstrtoul_from_user(user_buf, count, 0, &user_trig_edge);
73482346 2459 if (err)
7b830ae4 2460 return err;
2461
73482346
LJ
2462 if ((user_trig_edge == RISING_EDGE)
2463 || (user_trig_edge == FALLING_EDGE)) {
2464 trig_edge = (u8) user_trig_edge;
2465 } else {
2466 dev_err(dev, "Wrong input:\n"
2467 "Enter 0. Rising edge\n"
2468 "Enter 1. Falling edge\n");
2469 return -EINVAL;
2470 }
7b830ae4 2471
2472 return count;
73482346
LJ
2473}
2474
2475static const struct file_operations ab8500_gpadc_trig_edge_fops = {
2476 .open = ab8500_gpadc_trig_edge_open,
2477 .read = seq_read,
2478 .write = ab8500_gpadc_trig_edge_write,
2479 .llseek = seq_lseek,
2480 .release = single_release,
2481 .owner = THIS_MODULE,
2482};
2483
2484static int ab8500_gpadc_trig_timer_print(struct seq_file *s, void *p)
2485{
2486 return seq_printf(s, "%d\n", trig_timer);
2487}
2488
2489static int ab8500_gpadc_trig_timer_open(struct inode *inode, struct file *file)
2490{
2491 return single_open(file, ab8500_gpadc_trig_timer_print,
9f9ba15f 2492 inode->i_private);
73482346
LJ
2493}
2494
2495static ssize_t ab8500_gpadc_trig_timer_write(struct file *file,
2496 const char __user *user_buf,
2497 size_t count, loff_t *ppos)
2498{
2499 struct device *dev = ((struct seq_file *)(file->private_data))->private;
73482346
LJ
2500 unsigned long user_trig_timer;
2501 int err;
2502
7b830ae4 2503 err = kstrtoul_from_user(user_buf, count, 0, &user_trig_timer);
73482346 2504 if (err)
7b830ae4 2505 return err;
2506
73482346
LJ
2507 if ((user_trig_timer >= 0) && (user_trig_timer <= 255)) {
2508 trig_timer = (u8) user_trig_timer;
2509 } else {
2510 dev_err(dev, "debugfs error input: "
2511 "should be beetween 0 to 255\n");
2512 return -EINVAL;
2513 }
7b830ae4 2514
2515 return count;
73482346
LJ
2516}
2517
2518static const struct file_operations ab8500_gpadc_trig_timer_fops = {
2519 .open = ab8500_gpadc_trig_timer_open,
2520 .read = seq_read,
2521 .write = ab8500_gpadc_trig_timer_write,
2522 .llseek = seq_lseek,
2523 .release = single_release,
2524 .owner = THIS_MODULE,
2525};
2526
2527static int ab8500_gpadc_conv_type_print(struct seq_file *s, void *p)
2528{
2529 return seq_printf(s, "%d\n", conv_type);
2530}
2531
2532static int ab8500_gpadc_conv_type_open(struct inode *inode, struct file *file)
2533{
2534 return single_open(file, ab8500_gpadc_conv_type_print,
9f9ba15f 2535 inode->i_private);
73482346
LJ
2536}
2537
2538static ssize_t ab8500_gpadc_conv_type_write(struct file *file,
2539 const char __user *user_buf,
2540 size_t count, loff_t *ppos)
2541{
2542 struct device *dev = ((struct seq_file *)(file->private_data))->private;
73482346
LJ
2543 unsigned long user_conv_type;
2544 int err;
2545
7b830ae4 2546 err = kstrtoul_from_user(user_buf, count, 0, &user_conv_type);
73482346 2547 if (err)
7b830ae4 2548 return err;
2549
73482346
LJ
2550 if ((user_conv_type == ADC_SW)
2551 || (user_conv_type == ADC_HW)) {
2552 conv_type = (u8) user_conv_type;
2553 } else {
2554 dev_err(dev, "Wrong input:\n"
2555 "Enter 0. ADC SW conversion\n"
2556 "Enter 1. ADC HW conversion\n");
2557 return -EINVAL;
2558 }
7b830ae4 2559
2560 return count;
73482346
LJ
2561}
2562
2563static const struct file_operations ab8500_gpadc_conv_type_fops = {
2564 .open = ab8500_gpadc_conv_type_open,
2565 .read = seq_read,
2566 .write = ab8500_gpadc_conv_type_write,
2567 .llseek = seq_lseek,
2568 .release = single_release,
2569 .owner = THIS_MODULE,
2570};
2571
0fbce76e 2572/*
2573 * return length of an ASCII numerical value, 0 is string is not a
2574 * numerical value.
2575 * string shall start at value 1st char.
2576 * string can be tailed with \0 or space or newline chars only.
2577 * value can be decimal or hexadecimal (prefixed 0x or 0X).
2578 */
2579static int strval_len(char *b)
2580{
2581 char *s = b;
2582 if ((*s == '0') && ((*(s+1) == 'x') || (*(s+1) == 'X'))) {
2583 s += 2;
2584 for (; *s && (*s != ' ') && (*s != '\n'); s++) {
2585 if (!isxdigit(*s))
2586 return 0;
2587 }
2588 } else {
2589 if (*s == '-')
2590 s++;
2591 for (; *s && (*s != ' ') && (*s != '\n'); s++) {
2592 if (!isdigit(*s))
2593 return 0;
2594 }
2595 }
2596 return (int) (s-b);
2597}
2598
2599/*
2600 * parse hwreg input data.
2601 * update global hwreg_cfg only if input data syntax is ok.
2602 */
2603static ssize_t hwreg_common_write(char *b, struct hwreg_cfg *cfg,
2604 struct device *dev)
2605{
2606 uint write, val = 0;
2607 u8 regvalue;
2608 int ret;
2609 struct hwreg_cfg loc = {
2610 .bank = 0, /* default: invalid phys addr */
2611 .addr = 0, /* default: invalid phys addr */
2612 .fmt = 0, /* default: 32bit access, hex output */
2613 .mask = 0xFFFFFFFF, /* default: no mask */
2614 .shift = 0, /* default: no bit shift */
2615 };
2616
2617 /* read or write ? */
2618 if (!strncmp(b, "read ", 5)) {
2619 write = 0;
2620 b += 5;
2621 } else if (!strncmp(b, "write ", 6)) {
2622 write = 1;
2623 b += 6;
2624 } else
2625 return -EINVAL;
2626
2627 /* OPTIONS -l|-w|-b -s -m -o */
2628 while ((*b == ' ') || (*b == '-')) {
2629 if (*(b-1) != ' ') {
2630 b++;
2631 continue;
2632 }
2633 if ((!strncmp(b, "-d ", 3)) ||
2634 (!strncmp(b, "-dec ", 5))) {
2635 b += (*(b+2) == ' ') ? 3 : 5;
2636 loc.fmt |= (1<<0);
2637 } else if ((!strncmp(b, "-h ", 3)) ||
2638 (!strncmp(b, "-hex ", 5))) {
2639 b += (*(b+2) == ' ') ? 3 : 5;
2640 loc.fmt &= ~(1<<0);
2641 } else if ((!strncmp(b, "-m ", 3)) ||
2642 (!strncmp(b, "-mask ", 6))) {
2643 b += (*(b+2) == ' ') ? 3 : 6;
2644 if (strval_len(b) == 0)
2645 return -EINVAL;
2646 loc.mask = simple_strtoul(b, &b, 0);
2647 } else if ((!strncmp(b, "-s ", 3)) ||
2648 (!strncmp(b, "-shift ", 7))) {
2649 b += (*(b+2) == ' ') ? 3 : 7;
2650 if (strval_len(b) == 0)
2651 return -EINVAL;
2652 loc.shift = simple_strtol(b, &b, 0);
2653 } else {
2654 return -EINVAL;
2655 }
2656 }
2657 /* get arg BANK and ADDRESS */
2658 if (strval_len(b) == 0)
2659 return -EINVAL;
2660 loc.bank = simple_strtoul(b, &b, 0);
2661 while (*b == ' ')
2662 b++;
2663 if (strval_len(b) == 0)
2664 return -EINVAL;
2665 loc.addr = simple_strtoul(b, &b, 0);
2666
2667 if (write) {
2668 while (*b == ' ')
2669 b++;
2670 if (strval_len(b) == 0)
2671 return -EINVAL;
2672 val = simple_strtoul(b, &b, 0);
2673 }
2674
2675 /* args are ok, update target cfg (mainly for read) */
2676 *cfg = loc;
2677
2678#ifdef ABB_HWREG_DEBUG
2679 pr_warn("HWREG request: %s, %s, addr=0x%08X, mask=0x%X, shift=%d"
2680 "value=0x%X\n", (write) ? "write" : "read",
2681 REG_FMT_DEC(cfg) ? "decimal" : "hexa",
2682 cfg->addr, cfg->mask, cfg->shift, val);
2683#endif
2684
2685 if (!write)
2686 return 0;
2687
2688 ret = abx500_get_register_interruptible(dev,
2689 (u8)cfg->bank, (u8)cfg->addr, &regvalue);
2690 if (ret < 0) {
2691 dev_err(dev, "abx500_get_reg fail %d, %d\n",
2692 ret, __LINE__);
2693 return -EINVAL;
2694 }
2695
2696 if (cfg->shift >= 0) {
2697 regvalue &= ~(cfg->mask << (cfg->shift));
2698 val = (val & cfg->mask) << (cfg->shift);
2699 } else {
2700 regvalue &= ~(cfg->mask >> (-cfg->shift));
2701 val = (val & cfg->mask) >> (-cfg->shift);
2702 }
2703 val = val | regvalue;
2704
2705 ret = abx500_set_register_interruptible(dev,
2706 (u8)cfg->bank, (u8)cfg->addr, (u8)val);
2707 if (ret < 0) {
2708 pr_err("abx500_set_reg failed %d, %d", ret, __LINE__);
2709 return -EINVAL;
2710 }
2711
2712 return 0;
2713}
2714
2715static ssize_t ab8500_hwreg_write(struct file *file,
2716 const char __user *user_buf, size_t count, loff_t *ppos)
2717{
2718 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2719 char buf[128];
2720 int buf_size, ret;
2721
2722 /* Get userspace string and assure termination */
2723 buf_size = min(count, (sizeof(buf)-1));
2724 if (copy_from_user(buf, user_buf, buf_size))
2725 return -EFAULT;
2726 buf[buf_size] = 0;
2727
2728 /* get args and process */
2729 ret = hwreg_common_write(buf, &hwreg_cfg, dev);
2730 return (ret) ? ret : buf_size;
2731}
2732
2733/*
2734 * - irq subscribe/unsubscribe stuff
2735 */
4b8ac082
LJ
2736static int ab8500_subscribe_unsubscribe_print(struct seq_file *s, void *p)
2737{
2738 seq_printf(s, "%d\n", irq_first);
2739
2740 return 0;
2741}
2742
2743static int ab8500_subscribe_unsubscribe_open(struct inode *inode,
2744 struct file *file)
2745{
2746 return single_open(file, ab8500_subscribe_unsubscribe_print,
9f9ba15f 2747 inode->i_private);
4b8ac082
LJ
2748}
2749
2750/*
0b337e70 2751 * Userspace should use poll() on this file. When an event occur
4b8ac082
LJ
2752 * the blocking poll will be released.
2753 */
2754static ssize_t show_irq(struct device *dev,
2755 struct device_attribute *attr, char *buf)
2756{
0b337e70
MW
2757 unsigned long name;
2758 unsigned int irq_index;
2759 int err;
4b8ac082 2760
8420a241 2761 err = kstrtoul(attr->attr.name, 0, &name);
0b337e70
MW
2762 if (err)
2763 return err;
2764
2765 irq_index = name - irq_first;
ddba25f1 2766 if (irq_index >= num_irqs)
0b337e70
MW
2767 return -EINVAL;
2768 else
2769 return sprintf(buf, "%u\n", irq_count[irq_index]);
2770}
4b8ac082
LJ
2771
2772static ssize_t ab8500_subscribe_write(struct file *file,
2773 const char __user *user_buf,
2774 size_t count, loff_t *ppos)
2775{
2776 struct device *dev = ((struct seq_file *)(file->private_data))->private;
4b8ac082
LJ
2777 unsigned long user_val;
2778 int err;
0b337e70 2779 unsigned int irq_index;
4b8ac082 2780
7b830ae4 2781 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
4b8ac082 2782 if (err)
7b830ae4 2783 return err;
2784
4b8ac082
LJ
2785 if (user_val < irq_first) {
2786 dev_err(dev, "debugfs error input < %d\n", irq_first);
2787 return -EINVAL;
2788 }
2789 if (user_val > irq_last) {
2790 dev_err(dev, "debugfs error input > %d\n", irq_last);
2791 return -EINVAL;
2792 }
2793
0b337e70 2794 irq_index = user_val - irq_first;
ddba25f1 2795 if (irq_index >= num_irqs)
0b337e70
MW
2796 return -EINVAL;
2797
4b8ac082 2798 /*
0b337e70 2799 * This will create a sysfs file named <irq-nr> which userspace can
4b8ac082
LJ
2800 * use to select or poll and get the AB8500 events
2801 */
0b337e70
MW
2802 dev_attr[irq_index] = kmalloc(sizeof(struct device_attribute),
2803 GFP_KERNEL);
f840e23b
LJ
2804 if (!dev_attr[irq_index])
2805 return -ENOMEM;
2806
7b830ae4 2807 event_name[irq_index] = kmalloc(count, GFP_KERNEL);
d551c4c4
LJ
2808 if (!event_name[irq_index])
2809 return -ENOMEM;
2810
0b337e70
MW
2811 sprintf(event_name[irq_index], "%lu", user_val);
2812 dev_attr[irq_index]->show = show_irq;
2813 dev_attr[irq_index]->store = NULL;
2814 dev_attr[irq_index]->attr.name = event_name[irq_index];
2815 dev_attr[irq_index]->attr.mode = S_IRUGO;
2816 err = sysfs_create_file(&dev->kobj, &dev_attr[irq_index]->attr);
4b8ac082
LJ
2817 if (err < 0) {
2818 printk(KERN_ERR "sysfs_create_file failed %d\n", err);
2819 return err;
2820 }
2821
2822 err = request_threaded_irq(user_val, NULL, ab8500_debug_handler,
2823 IRQF_SHARED | IRQF_NO_SUSPEND,
2824 "ab8500-debug", &dev->kobj);
2825 if (err < 0) {
2826 printk(KERN_ERR "request_threaded_irq failed %d, %lu\n",
2827 err, user_val);
0b337e70 2828 sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr);
4b8ac082
LJ
2829 return err;
2830 }
2831
7b830ae4 2832 return count;
4b8ac082
LJ
2833}
2834
2835static ssize_t ab8500_unsubscribe_write(struct file *file,
2836 const char __user *user_buf,
2837 size_t count, loff_t *ppos)
2838{
2839 struct device *dev = ((struct seq_file *)(file->private_data))->private;
4b8ac082
LJ
2840 unsigned long user_val;
2841 int err;
0b337e70 2842 unsigned int irq_index;
4b8ac082 2843
7b830ae4 2844 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
4b8ac082 2845 if (err)
7b830ae4 2846 return err;
2847
4b8ac082
LJ
2848 if (user_val < irq_first) {
2849 dev_err(dev, "debugfs error input < %d\n", irq_first);
2850 return -EINVAL;
2851 }
2852 if (user_val > irq_last) {
2853 dev_err(dev, "debugfs error input > %d\n", irq_last);
2854 return -EINVAL;
2855 }
2856
0b337e70 2857 irq_index = user_val - irq_first;
ddba25f1 2858 if (irq_index >= num_irqs)
0b337e70
MW
2859 return -EINVAL;
2860
2861 /* Set irq count to 0 when unsubscribe */
2862 irq_count[irq_index] = 0;
2863
2864 if (dev_attr[irq_index])
2865 sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr);
4b8ac082 2866
0b337e70
MW
2867
2868 free_irq(user_val, &dev->kobj);
2869 kfree(event_name[irq_index]);
2870 kfree(dev_attr[irq_index]);
4b8ac082 2871
7b830ae4 2872 return count;
4b8ac082
LJ
2873}
2874
0fbce76e 2875/*
2876 * - several deubgfs nodes fops
2877 */
2878
5814fc35 2879static const struct file_operations ab8500_bank_fops = {
d7b9f322
MW
2880 .open = ab8500_bank_open,
2881 .write = ab8500_bank_write,
2882 .read = seq_read,
2883 .llseek = seq_lseek,
2884 .release = single_release,
2885 .owner = THIS_MODULE,
5814fc35
MW
2886};
2887
2888static const struct file_operations ab8500_address_fops = {
d7b9f322
MW
2889 .open = ab8500_address_open,
2890 .write = ab8500_address_write,
2891 .read = seq_read,
2892 .llseek = seq_lseek,
2893 .release = single_release,
2894 .owner = THIS_MODULE,
5814fc35
MW
2895};
2896
2897static const struct file_operations ab8500_val_fops = {
d7b9f322
MW
2898 .open = ab8500_val_open,
2899 .write = ab8500_val_write,
2900 .read = seq_read,
2901 .llseek = seq_lseek,
2902 .release = single_release,
2903 .owner = THIS_MODULE,
5814fc35
MW
2904};
2905
8f0eb43b
BJ
2906static const struct file_operations ab8500_interrupts_fops = {
2907 .open = ab8500_interrupts_open,
2908 .read = seq_read,
2909 .llseek = seq_lseek,
2910 .release = single_release,
2911 .owner = THIS_MODULE,
2912};
2913
4b8ac082
LJ
2914static const struct file_operations ab8500_subscribe_fops = {
2915 .open = ab8500_subscribe_unsubscribe_open,
2916 .write = ab8500_subscribe_write,
2917 .read = seq_read,
2918 .llseek = seq_lseek,
2919 .release = single_release,
2920 .owner = THIS_MODULE,
2921};
2922
2923static const struct file_operations ab8500_unsubscribe_fops = {
2924 .open = ab8500_subscribe_unsubscribe_open,
2925 .write = ab8500_unsubscribe_write,
2926 .read = seq_read,
2927 .llseek = seq_lseek,
2928 .release = single_release,
2929 .owner = THIS_MODULE,
2930};
2931
0fbce76e 2932static const struct file_operations ab8500_hwreg_fops = {
2933 .open = ab8500_hwreg_open,
2934 .write = ab8500_hwreg_write,
2935 .read = seq_read,
2936 .llseek = seq_lseek,
2937 .release = single_release,
2938 .owner = THIS_MODULE,
2939};
2940
5814fc35 2941static struct dentry *ab8500_dir;
1478a316 2942static struct dentry *ab8500_gpadc_dir;
5814fc35 2943
f791be49 2944static int ab8500_debug_probe(struct platform_device *plf)
5814fc35 2945{
0fbce76e 2946 struct dentry *file;
ddba25f1 2947 struct ab8500 *ab8500;
6999181e 2948 struct resource *res;
d7b9f322
MW
2949 debug_bank = AB8500_MISC;
2950 debug_address = AB8500_REV_REG & 0x00FF;
5814fc35 2951
ddba25f1
LW
2952 ab8500 = dev_get_drvdata(plf->dev.parent);
2953 num_irqs = ab8500->mask_size;
2954
c18cf6d1
LJ
2955 irq_count = devm_kzalloc(&plf->dev,
2956 sizeof(*irq_count)*num_irqs, GFP_KERNEL);
ddba25f1
LW
2957 if (!irq_count)
2958 return -ENOMEM;
2959
c18cf6d1
LJ
2960 dev_attr = devm_kzalloc(&plf->dev,
2961 sizeof(*dev_attr)*num_irqs,GFP_KERNEL);
ddba25f1 2962 if (!dev_attr)
c18cf6d1 2963 return -ENOMEM;
ddba25f1 2964
c18cf6d1
LJ
2965 event_name = devm_kzalloc(&plf->dev,
2966 sizeof(*event_name)*num_irqs, GFP_KERNEL);
ddba25f1 2967 if (!event_name)
c18cf6d1 2968 return -ENOMEM;
ddba25f1 2969
6999181e
LW
2970 res = platform_get_resource_byname(plf, 0, "IRQ_AB8500");
2971 if (!res) {
2972 dev_err(&plf->dev, "AB8500 irq not found, err %d\n",
2973 irq_first);
c18cf6d1 2974 return ENXIO;
6999181e
LW
2975 }
2976 irq_ab8500 = res->start;
2977
4b8ac082
LJ
2978 irq_first = platform_get_irq_byname(plf, "IRQ_FIRST");
2979 if (irq_first < 0) {
2980 dev_err(&plf->dev, "First irq not found, err %d\n",
9f9ba15f 2981 irq_first);
c18cf6d1 2982 return irq_first;
4b8ac082
LJ
2983 }
2984
2985 irq_last = platform_get_irq_byname(plf, "IRQ_LAST");
2986 if (irq_last < 0) {
2987 dev_err(&plf->dev, "Last irq not found, err %d\n",
9f9ba15f 2988 irq_last);
c18cf6d1 2989 return irq_last;
4b8ac082
LJ
2990 }
2991
d7b9f322
MW
2992 ab8500_dir = debugfs_create_dir(AB8500_NAME_STRING, NULL);
2993 if (!ab8500_dir)
0fbce76e 2994 goto err;
5814fc35 2995
1478a316 2996 ab8500_gpadc_dir = debugfs_create_dir(AB8500_ADC_NAME_STRING,
9f9ba15f 2997 ab8500_dir);
1478a316
JB
2998 if (!ab8500_gpadc_dir)
2999 goto err;
3000
3001 file = debugfs_create_file("all-bank-registers", S_IRUGO,
9f9ba15f 3002 ab8500_dir, &plf->dev, &ab8500_registers_fops);
1478a316
JB
3003 if (!file)
3004 goto err;
3005
42002c6d 3006 file = debugfs_create_file("all-banks", S_IRUGO,
9f9ba15f 3007 ab8500_dir, &plf->dev, &ab8500_all_banks_fops);
42002c6d
MYK
3008 if (!file)
3009 goto err;
3010
f38487f2 3011 file = debugfs_create_file("register-bank", (S_IRUGO | S_IWUSR | S_IWGRP),
9f9ba15f 3012 ab8500_dir, &plf->dev, &ab8500_bank_fops);
1478a316
JB
3013 if (!file)
3014 goto err;
3015
f38487f2 3016 file = debugfs_create_file("register-address", (S_IRUGO | S_IWUSR | S_IWGRP),
9f9ba15f 3017 ab8500_dir, &plf->dev, &ab8500_address_fops);
1478a316
JB
3018 if (!file)
3019 goto err;
3020
f38487f2 3021 file = debugfs_create_file("register-value", (S_IRUGO | S_IWUSR | S_IWGRP),
9f9ba15f 3022 ab8500_dir, &plf->dev, &ab8500_val_fops);
1478a316
JB
3023 if (!file)
3024 goto err;
3025
f38487f2 3026 file = debugfs_create_file("irq-subscribe", (S_IRUGO | S_IWUSR | S_IWGRP),
9f9ba15f 3027 ab8500_dir, &plf->dev, &ab8500_subscribe_fops);
1478a316
JB
3028 if (!file)
3029 goto err;
3030
9581ae39
LJ
3031 if (is_ab8500(ab8500)) {
3032 debug_ranges = ab8500_debug_ranges;
8f0eb43b 3033 num_interrupt_lines = AB8500_NR_IRQS;
9581ae39
LJ
3034 } else if (is_ab8505(ab8500)) {
3035 debug_ranges = ab8505_debug_ranges;
8f0eb43b 3036 num_interrupt_lines = AB8505_NR_IRQS;
9581ae39
LJ
3037 } else if (is_ab9540(ab8500)) {
3038 debug_ranges = ab8505_debug_ranges;
8f0eb43b 3039 num_interrupt_lines = AB9540_NR_IRQS;
9581ae39 3040 } else if (is_ab8540(ab8500)) {
971480f5 3041 debug_ranges = ab8540_debug_ranges;
e436ddff 3042 num_interrupt_lines = AB8540_NR_IRQS;
9581ae39 3043 }
8f0eb43b
BJ
3044
3045 file = debugfs_create_file("interrupts", (S_IRUGO),
9f9ba15f 3046 ab8500_dir, &plf->dev, &ab8500_interrupts_fops);
8f0eb43b
BJ
3047 if (!file)
3048 goto err;
3049
f38487f2 3050 file = debugfs_create_file("irq-unsubscribe", (S_IRUGO | S_IWUSR | S_IWGRP),
9f9ba15f 3051 ab8500_dir, &plf->dev, &ab8500_unsubscribe_fops);
1478a316
JB
3052 if (!file)
3053 goto err;
3054
f38487f2 3055 file = debugfs_create_file("hwreg", (S_IRUGO | S_IWUSR | S_IWGRP),
9f9ba15f 3056 ab8500_dir, &plf->dev, &ab8500_hwreg_fops);
1478a316
JB
3057 if (!file)
3058 goto err;
3059
f38487f2 3060 file = debugfs_create_file("all-modem-registers", (S_IRUGO | S_IWUSR | S_IWGRP),
c7ebaee2
LJ
3061 ab8500_dir, &plf->dev, &ab8500_modem_fops);
3062 if (!file)
3063 goto err;
3064
f38487f2 3065 file = debugfs_create_file("bat_ctrl", (S_IRUGO | S_IWUSR | S_IWGRP),
9f9ba15f 3066 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_bat_ctrl_fops);
1478a316
JB
3067 if (!file)
3068 goto err;
3069
f38487f2 3070 file = debugfs_create_file("btemp_ball", (S_IRUGO | S_IWUSR | S_IWGRP),
9f9ba15f 3071 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_btemp_ball_fops);
1478a316
JB
3072 if (!file)
3073 goto err;
3074
f38487f2 3075 file = debugfs_create_file("main_charger_v", (S_IRUGO | S_IWUSR | S_IWGRP),
9f9ba15f 3076 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_charger_v_fops);
1478a316
JB
3077 if (!file)
3078 goto err;
3079
f38487f2 3080 file = debugfs_create_file("acc_detect1", (S_IRUGO | S_IWUSR | S_IWGRP),
9f9ba15f 3081 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_acc_detect1_fops);
1478a316
JB
3082 if (!file)
3083 goto err;
3084
f38487f2 3085 file = debugfs_create_file("acc_detect2", (S_IRUGO | S_IWUSR | S_IWGRP),
9f9ba15f 3086 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_acc_detect2_fops);
1478a316
JB
3087 if (!file)
3088 goto err;
3089
f38487f2 3090 file = debugfs_create_file("adc_aux1", (S_IRUGO | S_IWUSR | S_IWGRP),
9f9ba15f 3091 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_aux1_fops);
1478a316
JB
3092 if (!file)
3093 goto err;
3094
f38487f2 3095 file = debugfs_create_file("adc_aux2", (S_IRUGO | S_IWUSR | S_IWGRP),
9f9ba15f 3096 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_aux2_fops);
0fbce76e 3097 if (!file)
3098 goto err;
5814fc35 3099
f38487f2 3100 file = debugfs_create_file("main_bat_v", (S_IRUGO | S_IWUSR | S_IWGRP),
9f9ba15f 3101 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_bat_v_fops);
0fbce76e 3102 if (!file)
3103 goto err;
5814fc35 3104
f38487f2 3105 file = debugfs_create_file("vbus_v", (S_IRUGO | S_IWUSR | S_IWGRP),
9f9ba15f 3106 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_vbus_v_fops);
0fbce76e 3107 if (!file)
3108 goto err;
5814fc35 3109
f38487f2 3110 file = debugfs_create_file("main_charger_c", (S_IRUGO | S_IWUSR | S_IWGRP),
9f9ba15f 3111 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_charger_c_fops);
0fbce76e 3112 if (!file)
3113 goto err;
3114
f38487f2 3115 file = debugfs_create_file("usb_charger_c", (S_IRUGO | S_IWUSR | S_IWGRP),
9f9ba15f 3116 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_usb_charger_c_fops);
0fbce76e 3117 if (!file)
3118 goto err;
3119
f38487f2 3120 file = debugfs_create_file("bk_bat_v", (S_IRUGO | S_IWUSR | S_IWGRP),
9f9ba15f 3121 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_bk_bat_v_fops);
0fbce76e 3122 if (!file)
3123 goto err;
3124
f38487f2 3125 file = debugfs_create_file("die_temp", (S_IRUGO | S_IWUSR | S_IWGRP),
9f9ba15f 3126 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_die_temp_fops);
0fbce76e 3127 if (!file)
3128 goto err;
127629d7 3129
f38487f2 3130 file = debugfs_create_file("usb_id", (S_IRUGO | S_IWUSR | S_IWGRP),
127629d7
LJ
3131 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_usb_id_fops);
3132 if (!file)
3133 goto err;
3134
bc6b4132 3135 if (is_ab8540(ab8500)) {
f38487f2 3136 file = debugfs_create_file("xtal_temp", (S_IRUGO | S_IWUSR | S_IWGRP),
bc6b4132
LJ
3137 ab8500_gpadc_dir, &plf->dev, &ab8540_gpadc_xtal_temp_fops);
3138 if (!file)
3139 goto err;
f38487f2 3140 file = debugfs_create_file("vbattruemeas", (S_IRUGO | S_IWUSR | S_IWGRP),
bc6b4132
LJ
3141 ab8500_gpadc_dir, &plf->dev,
3142 &ab8540_gpadc_vbat_true_meas_fops);
3143 if (!file)
3144 goto err;
3145 file = debugfs_create_file("batctrl_and_ibat",
9f9ba15f
LJ
3146 (S_IRUGO | S_IWUGO), ab8500_gpadc_dir,
3147 &plf->dev, &ab8540_gpadc_bat_ctrl_and_ibat_fops);
bc6b4132
LJ
3148 if (!file)
3149 goto err;
3150 file = debugfs_create_file("vbatmeas_and_ibat",
9f9ba15f
LJ
3151 (S_IRUGO | S_IWUGO), ab8500_gpadc_dir,
3152 &plf->dev,
3153 &ab8540_gpadc_vbat_meas_and_ibat_fops);
bc6b4132
LJ
3154 if (!file)
3155 goto err;
3156 file = debugfs_create_file("vbattruemeas_and_ibat",
9f9ba15f
LJ
3157 (S_IRUGO | S_IWUGO), ab8500_gpadc_dir,
3158 &plf->dev,
3159 &ab8540_gpadc_vbat_true_meas_and_ibat_fops);
bc6b4132
LJ
3160 if (!file)
3161 goto err;
3162 file = debugfs_create_file("battemp_and_ibat",
9f9ba15f
LJ
3163 (S_IRUGO | S_IWUGO), ab8500_gpadc_dir,
3164 &plf->dev, &ab8540_gpadc_bat_temp_and_ibat_fops);
bc6b4132
LJ
3165 if (!file)
3166 goto err;
f38487f2 3167 file = debugfs_create_file("otp_calib", (S_IRUGO | S_IWUSR | S_IWGRP),
bc6b4132
LJ
3168 ab8500_gpadc_dir, &plf->dev, &ab8540_gpadc_otp_calib_fops);
3169 if (!file)
3170 goto err;
3171 }
f38487f2 3172 file = debugfs_create_file("avg_sample", (S_IRUGO | S_IWUSR | S_IWGRP),
73482346
LJ
3173 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_avg_sample_fops);
3174 if (!file)
3175 goto err;
3176
f38487f2 3177 file = debugfs_create_file("trig_edge", (S_IRUGO | S_IWUSR | S_IWGRP),
73482346
LJ
3178 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_trig_edge_fops);
3179 if (!file)
3180 goto err;
3181
f38487f2 3182 file = debugfs_create_file("trig_timer", (S_IRUGO | S_IWUSR | S_IWGRP),
73482346
LJ
3183 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_trig_timer_fops);
3184 if (!file)
3185 goto err;
3186
f38487f2 3187 file = debugfs_create_file("conv_type", (S_IRUGO | S_IWUSR | S_IWGRP),
73482346
LJ
3188 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_conv_type_fops);
3189 if (!file)
3190 goto err;
4b8ac082 3191
d7b9f322 3192 return 0;
5814fc35 3193
0fbce76e 3194err:
3195 if (ab8500_dir)
3196 debugfs_remove_recursive(ab8500_dir);
d7b9f322 3197 dev_err(&plf->dev, "failed to create debugfs entries.\n");
ddba25f1 3198
c18cf6d1 3199 return -ENOMEM;
5814fc35
MW
3200}
3201
4740f73f 3202static int ab8500_debug_remove(struct platform_device *plf)
5814fc35 3203{
0fbce76e 3204 debugfs_remove_recursive(ab8500_dir);
ddba25f1 3205
d7b9f322 3206 return 0;
5814fc35
MW
3207}
3208
3209static struct platform_driver ab8500_debug_driver = {
d7b9f322
MW
3210 .driver = {
3211 .name = "ab8500-debug",
3212 .owner = THIS_MODULE,
3213 },
3214 .probe = ab8500_debug_probe,
84449216 3215 .remove = ab8500_debug_remove
5814fc35
MW
3216};
3217
3218static int __init ab8500_debug_init(void)
3219{
d7b9f322 3220 return platform_driver_register(&ab8500_debug_driver);
5814fc35
MW
3221}
3222
3223static void __exit ab8500_debug_exit(void)
3224{
d7b9f322 3225 platform_driver_unregister(&ab8500_debug_driver);
5814fc35
MW
3226}
3227subsys_initcall(ab8500_debug_init);
3228module_exit(ab8500_debug_exit);
3229
3230MODULE_AUTHOR("Mattias WALLIN <mattias.wallin@stericsson.com");
3231MODULE_DESCRIPTION("AB8500 DEBUG");
3232MODULE_LICENSE("GPL v2");