blob: b88bbbc15f1e962f8f131d0f50bc25768091f55c [file] [log] [blame]
Mattias Wallin5814fc32010-09-13 16:05:04 +02001/*
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 */
carriere etienne0fbce762011-04-08 16:26:36 +02007/*
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 */
Mattias Wallin5814fc32010-09-13 16:05:04 +020073
74#include <linux/seq_file.h>
75#include <linux/uaccess.h>
76#include <linux/fs.h>
Paul Gortmaker4e36dd32011-07-03 15:13:27 -040077#include <linux/module.h>
Mattias Wallin5814fc32010-09-13 16:05:04 +020078#include <linux/debugfs.h>
79#include <linux/platform_device.h>
Lee Jones4b8ac082013-01-14 16:10:36 +000080#include <linux/interrupt.h>
81#include <linux/kobject.h>
82#include <linux/slab.h>
Jonas Aaberg2cf64e22012-05-31 07:57:07 +020083#include <linux/irq.h>
Mattias Wallin5814fc32010-09-13 16:05:04 +020084
85#include <linux/mfd/abx500.h>
Linus Walleij0cd5b6d02013-02-06 23:23:01 +010086#include <linux/mfd/abx500/ab8500.h>
John Beckett1478a312011-05-31 13:54:27 +010087#include <linux/mfd/abx500/ab8500-gpadc.h>
Mattias Wallin5814fc32010-09-13 16:05:04 +020088
carriere etienne0fbce762011-04-08 16:26:36 +020089#ifdef CONFIG_DEBUG_FS
90#include <linux/string.h>
91#include <linux/ctype.h>
92#endif
93
Linus Walleijeb1f9582012-11-22 18:50:06 +010094/* TODO: this file should not reference IRQ_DB8500_AB8500! */
95#include <mach/irqs.h>
96
Mattias Wallin5814fc32010-09-13 16:05:04 +020097static u32 debug_bank;
98static u32 debug_address;
99
Lee Jones4b8ac082013-01-14 16:10:36 +0000100static int irq_first;
101static int irq_last;
Linus Walleijddba25f2012-02-03 11:19:05 +0100102static u32 *irq_count;
103static int num_irqs;
Mattias Wallin0b337e72010-11-19 17:55:11 +0100104
Linus Walleijddba25f2012-02-03 11:19:05 +0100105static struct device_attribute **dev_attr;
106static char **event_name;
Lee Jones4b8ac082013-01-14 16:10:36 +0000107
Lee Jones73482342013-02-26 10:06:55 +0000108static u8 avg_sample = SAMPLE_16;
109static u8 trig_edge = RISING_EDGE;
110static u8 conv_type = ADC_SW;
111static u8 trig_timer;
112
Mattias Wallin5814fc32010-09-13 16:05:04 +0200113/**
114 * struct ab8500_reg_range
115 * @first: the first address of the range
116 * @last: the last address of the range
117 * @perm: access permissions for the range
118 */
119struct ab8500_reg_range {
Mattias Wallind7b9f322010-11-26 13:06:39 +0100120 u8 first;
121 u8 last;
122 u8 perm;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200123};
124
125/**
Lee Jones822672a2012-06-20 13:56:38 +0100126 * struct ab8500_prcmu_ranges
Mattias Wallin5814fc32010-09-13 16:05:04 +0200127 * @num_ranges: the number of ranges in the list
128 * @bankid: bank identifier
129 * @range: the list of register ranges
130 */
Lee Jones822672a2012-06-20 13:56:38 +0100131struct ab8500_prcmu_ranges {
Mattias Wallind7b9f322010-11-26 13:06:39 +0100132 u8 num_ranges;
133 u8 bankid;
134 const struct ab8500_reg_range *range;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200135};
136
carriere etienne0fbce762011-04-08 16:26:36 +0200137/* hwreg- "mask" and "shift" entries ressources */
138struct hwreg_cfg {
139 u32 bank; /* target bank */
140 u32 addr; /* target address */
141 uint fmt; /* format */
142 uint mask; /* read/write mask, applied before any bit shift */
143 int shift; /* bit shift (read:right shift, write:left shift */
144};
145/* fmt bit #0: 0=hexa, 1=dec */
146#define REG_FMT_DEC(c) ((c)->fmt & 0x1)
147#define REG_FMT_HEX(c) (!REG_FMT_DEC(c))
148
149static struct hwreg_cfg hwreg_cfg = {
150 .addr = 0, /* default: invalid phys addr */
151 .fmt = 0, /* default: 32bit access, hex output */
152 .mask = 0xFFFFFFFF, /* default: no mask */
153 .shift = 0, /* default: no bit shift */
154};
155
Mattias Wallin5814fc32010-09-13 16:05:04 +0200156#define AB8500_NAME_STRING "ab8500"
John Beckett1478a312011-05-31 13:54:27 +0100157#define AB8500_ADC_NAME_STRING "gpadc"
Philippe Langlais40c064e2011-10-17 09:48:55 +0200158#define AB8500_NUM_BANKS 24
Mattias Wallin5814fc32010-09-13 16:05:04 +0200159
160#define AB8500_REV_REG 0x80
161
Lee Jones9581ae32012-07-06 16:11:50 +0200162static struct ab8500_prcmu_ranges *debug_ranges;
163
164struct ab8500_prcmu_ranges ab8500_debug_ranges[AB8500_NUM_BANKS] = {
Mattias Wallind7b9f322010-11-26 13:06:39 +0100165 [0x0] = {
166 .num_ranges = 0,
Lee Jonesfad55a82013-01-14 17:17:34 +0000167 .range = NULL,
Mattias Wallind7b9f322010-11-26 13:06:39 +0100168 },
169 [AB8500_SYS_CTRL1_BLOCK] = {
170 .num_ranges = 3,
171 .range = (struct ab8500_reg_range[]) {
172 {
173 .first = 0x00,
174 .last = 0x02,
175 },
176 {
177 .first = 0x42,
178 .last = 0x42,
179 },
180 {
181 .first = 0x80,
182 .last = 0x81,
183 },
184 },
185 },
186 [AB8500_SYS_CTRL2_BLOCK] = {
187 .num_ranges = 4,
188 .range = (struct ab8500_reg_range[]) {
189 {
190 .first = 0x00,
191 .last = 0x0D,
192 },
193 {
194 .first = 0x0F,
195 .last = 0x17,
196 },
197 {
198 .first = 0x30,
199 .last = 0x30,
200 },
201 {
202 .first = 0x32,
203 .last = 0x33,
204 },
205 },
206 },
207 [AB8500_REGU_CTRL1] = {
208 .num_ranges = 3,
209 .range = (struct ab8500_reg_range[]) {
210 {
211 .first = 0x00,
212 .last = 0x00,
213 },
214 {
215 .first = 0x03,
216 .last = 0x10,
217 },
218 {
219 .first = 0x80,
220 .last = 0x84,
221 },
222 },
223 },
224 [AB8500_REGU_CTRL2] = {
225 .num_ranges = 5,
226 .range = (struct ab8500_reg_range[]) {
227 {
228 .first = 0x00,
229 .last = 0x15,
230 },
231 {
232 .first = 0x17,
233 .last = 0x19,
234 },
235 {
236 .first = 0x1B,
237 .last = 0x1D,
238 },
239 {
240 .first = 0x1F,
241 .last = 0x22,
242 },
243 {
244 .first = 0x40,
245 .last = 0x44,
246 },
247 /* 0x80-0x8B is SIM registers and should
248 * not be accessed from here */
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,
Mark Brown87fff232010-12-13 14:06:47 +0000307 .range = NULL,
Mattias Wallind7b9f322010-11-26 13:06:39 +0100308 },
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 [0x9] = {
319 .num_ranges = 0,
Mark Brown87fff232010-12-13 14:06:47 +0000320 .range = NULL,
Mattias Wallind7b9f322010-11-26 13:06:39 +0100321 },
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] = {
Philippe Langlais40c064e2011-10-17 09:48:55 +0200332 .num_ranges = 9,
Mattias Wallind7b9f322010-11-26 13:06:39 +0100333 .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 },
Philippe Langlais40c064e2011-10-17 09:48:55 +0200366 {
367 .first = 0xf5,
Lee Jones9581ae32012-07-06 16:11:50 +0200368 .last = 0xf6,
Philippe Langlais40c064e2011-10-17 09:48:55 +0200369 },
Mattias Wallind7b9f322010-11-26 13:06:39 +0100370 },
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 },
Philippe Langlais40c064e2011-10-17 09:48:55 +0200389 [AB8500_DEVELOPMENT] = {
390 .num_ranges = 1,
391 .range = (struct ab8500_reg_range[]) {
392 {
393 .first = 0x00,
394 .last = 0x00,
395 },
396 },
397 },
398 [AB8500_DEBUG] = {
399 .num_ranges = 1,
400 .range = (struct ab8500_reg_range[]) {
401 {
402 .first = 0x05,
403 .last = 0x07,
404 },
405 },
406 },
Mattias Wallind7b9f322010-11-26 13:06:39 +0100407 [AB8500_AUDIO] = {
408 .num_ranges = 1,
409 .range = (struct ab8500_reg_range[]) {
410 {
411 .first = 0x00,
412 .last = 0x6F,
413 },
414 },
415 },
416 [AB8500_INTERRUPT] = {
417 .num_ranges = 0,
Mark Brown87fff232010-12-13 14:06:47 +0000418 .range = NULL,
Mattias Wallind7b9f322010-11-26 13:06:39 +0100419 },
420 [AB8500_RTC] = {
421 .num_ranges = 1,
422 .range = (struct ab8500_reg_range[]) {
423 {
424 .first = 0x00,
425 .last = 0x0F,
426 },
427 },
428 },
429 [AB8500_MISC] = {
430 .num_ranges = 8,
431 .range = (struct ab8500_reg_range[]) {
432 {
433 .first = 0x00,
434 .last = 0x05,
435 },
436 {
437 .first = 0x10,
438 .last = 0x15,
439 },
440 {
441 .first = 0x20,
442 .last = 0x25,
443 },
444 {
445 .first = 0x30,
446 .last = 0x35,
447 },
448 {
449 .first = 0x40,
450 .last = 0x45,
451 },
452 {
453 .first = 0x50,
454 .last = 0x50,
455 },
456 {
457 .first = 0x60,
458 .last = 0x67,
459 },
460 {
461 .first = 0x80,
462 .last = 0x80,
463 },
464 },
465 },
466 [0x11] = {
467 .num_ranges = 0,
Mark Brown87fff232010-12-13 14:06:47 +0000468 .range = NULL,
Mattias Wallind7b9f322010-11-26 13:06:39 +0100469 },
470 [0x12] = {
471 .num_ranges = 0,
Mark Brown87fff232010-12-13 14:06:47 +0000472 .range = NULL,
Mattias Wallind7b9f322010-11-26 13:06:39 +0100473 },
474 [0x13] = {
475 .num_ranges = 0,
Mark Brown87fff232010-12-13 14:06:47 +0000476 .range = NULL,
Mattias Wallind7b9f322010-11-26 13:06:39 +0100477 },
478 [0x14] = {
479 .num_ranges = 0,
Mark Brown87fff232010-12-13 14:06:47 +0000480 .range = NULL,
Mattias Wallind7b9f322010-11-26 13:06:39 +0100481 },
482 [AB8500_OTP_EMUL] = {
483 .num_ranges = 1,
484 .range = (struct ab8500_reg_range[]) {
485 {
486 .first = 0x01,
487 .last = 0x0F,
488 },
489 },
490 },
Mattias Wallin5814fc32010-09-13 16:05:04 +0200491};
492
Lee Jones9581ae32012-07-06 16:11:50 +0200493struct ab8500_prcmu_ranges ab8505_debug_ranges[AB8500_NUM_BANKS] = {
494 [0x0] = {
495 .num_ranges = 0,
496 .range = NULL,
497 },
498 [AB8500_SYS_CTRL1_BLOCK] = {
499 .num_ranges = 5,
500 .range = (struct ab8500_reg_range[]) {
501 {
502 .first = 0x00,
503 .last = 0x04,
504 },
505 {
506 .first = 0x42,
507 .last = 0x42,
508 },
509 {
510 .first = 0x52,
511 .last = 0x52,
512 },
513 {
514 .first = 0x54,
515 .last = 0x57,
516 },
517 {
518 .first = 0x80,
519 .last = 0x83,
520 },
521 },
522 },
523 [AB8500_SYS_CTRL2_BLOCK] = {
524 .num_ranges = 5,
525 .range = (struct ab8500_reg_range[]) {
526 {
527 .first = 0x00,
528 .last = 0x0D,
529 },
530 {
531 .first = 0x0F,
532 .last = 0x17,
533 },
534 {
535 .first = 0x20,
536 .last = 0x20,
537 },
538 {
539 .first = 0x30,
540 .last = 0x30,
541 },
542 {
543 .first = 0x32,
544 .last = 0x3A,
545 },
546 },
547 },
548 [AB8500_REGU_CTRL1] = {
549 .num_ranges = 3,
550 .range = (struct ab8500_reg_range[]) {
551 {
552 .first = 0x00,
553 .last = 0x00,
554 },
555 {
556 .first = 0x03,
557 .last = 0x11,
558 },
559 {
560 .first = 0x80,
561 .last = 0x86,
562 },
563 },
564 },
565 [AB8500_REGU_CTRL2] = {
566 .num_ranges = 6,
567 .range = (struct ab8500_reg_range[]) {
568 {
569 .first = 0x00,
570 .last = 0x06,
571 },
572 {
573 .first = 0x08,
574 .last = 0x15,
575 },
576 {
577 .first = 0x17,
578 .last = 0x19,
579 },
580 {
581 .first = 0x1B,
582 .last = 0x1D,
583 },
584 {
585 .first = 0x1F,
586 .last = 0x30,
587 },
588 {
589 .first = 0x40,
590 .last = 0x48,
591 },
592 /* 0x80-0x8B is SIM registers and should
593 * not be accessed from here */
594 },
595 },
596 [AB8500_USB] = {
597 .num_ranges = 3,
598 .range = (struct ab8500_reg_range[]) {
599 {
600 .first = 0x80,
601 .last = 0x83,
602 },
603 {
604 .first = 0x87,
605 .last = 0x8A,
606 },
607 {
608 .first = 0x91,
609 .last = 0x94,
610 },
611 },
612 },
613 [AB8500_TVOUT] = {
614 .num_ranges = 0,
615 .range = NULL,
616 },
617 [AB8500_DBI] = {
618 .num_ranges = 0,
619 .range = NULL,
620 },
621 [AB8500_ECI_AV_ACC] = {
622 .num_ranges = 1,
623 .range = (struct ab8500_reg_range[]) {
624 {
625 .first = 0x80,
626 .last = 0x82,
627 },
628 },
629 },
630 [AB8500_RESERVED] = {
631 .num_ranges = 0,
632 .range = NULL,
633 },
634 [AB8500_GPADC] = {
635 .num_ranges = 1,
636 .range = (struct ab8500_reg_range[]) {
637 {
638 .first = 0x00,
639 .last = 0x08,
640 },
641 },
642 },
643 [AB8500_CHARGER] = {
644 .num_ranges = 9,
645 .range = (struct ab8500_reg_range[]) {
646 {
647 .first = 0x02,
648 .last = 0x03,
649 },
650 {
651 .first = 0x05,
652 .last = 0x05,
653 },
654 {
655 .first = 0x40,
656 .last = 0x44,
657 },
658 {
659 .first = 0x50,
660 .last = 0x57,
661 },
662 {
663 .first = 0x60,
664 .last = 0x60,
665 },
666 {
667 .first = 0xA0,
668 .last = 0xA7,
669 },
670 {
671 .first = 0xAF,
672 .last = 0xB2,
673 },
674 {
675 .first = 0xC0,
676 .last = 0xC2,
677 },
678 {
679 .first = 0xF5,
680 .last = 0xF5,
681 },
682 },
683 },
684 [AB8500_GAS_GAUGE] = {
685 .num_ranges = 3,
686 .range = (struct ab8500_reg_range[]) {
687 {
688 .first = 0x00,
689 .last = 0x00,
690 },
691 {
692 .first = 0x07,
693 .last = 0x0A,
694 },
695 {
696 .first = 0x10,
697 .last = 0x14,
698 },
699 },
700 },
701 [AB8500_AUDIO] = {
702 .num_ranges = 1,
703 .range = (struct ab8500_reg_range[]) {
704 {
705 .first = 0x00,
706 .last = 0x83,
707 },
708 },
709 },
710 [AB8500_INTERRUPT] = {
711 .num_ranges = 11,
712 .range = (struct ab8500_reg_range[]) {
713 {
714 .first = 0x00,
715 .last = 0x04,
716 },
717 {
718 .first = 0x06,
719 .last = 0x07,
720 },
721 {
722 .first = 0x09,
723 .last = 0x09,
724 },
725 {
726 .first = 0x0B,
727 .last = 0x0C,
728 },
729 {
730 .first = 0x12,
731 .last = 0x15,
732 },
733 {
734 .first = 0x18,
735 .last = 0x18,
736 },
737 /* Latch registers should not be read here */
738 {
739 .first = 0x40,
740 .last = 0x44,
741 },
742 {
743 .first = 0x46,
744 .last = 0x49,
745 },
746 {
747 .first = 0x4B,
748 .last = 0x4D,
749 },
750 {
751 .first = 0x52,
752 .last = 0x55,
753 },
754 {
755 .first = 0x58,
756 .last = 0x58,
757 },
758 /* LatchHier registers should not be read here */
759 },
760 },
761 [AB8500_RTC] = {
762 .num_ranges = 2,
763 .range = (struct ab8500_reg_range[]) {
764 {
765 .first = 0x00,
766 .last = 0x14,
767 },
768 {
769 .first = 0x16,
770 .last = 0x17,
771 },
772 },
773 },
774 [AB8500_MISC] = {
775 .num_ranges = 8,
776 .range = (struct ab8500_reg_range[]) {
777 {
778 .first = 0x00,
779 .last = 0x06,
780 },
781 {
782 .first = 0x10,
783 .last = 0x16,
784 },
785 {
786 .first = 0x20,
787 .last = 0x26,
788 },
789 {
790 .first = 0x30,
791 .last = 0x36,
792 },
793 {
794 .first = 0x40,
795 .last = 0x46,
796 },
797 {
798 .first = 0x50,
799 .last = 0x50,
800 },
801 {
802 .first = 0x60,
803 .last = 0x6B,
804 },
805 {
806 .first = 0x80,
807 .last = 0x82,
808 },
809 },
810 },
811 [AB8500_DEVELOPMENT] = {
812 .num_ranges = 2,
813 .range = (struct ab8500_reg_range[]) {
814 {
815 .first = 0x00,
816 .last = 0x00,
817 },
818 {
819 .first = 0x05,
820 .last = 0x05,
821 },
822 },
823 },
824 [AB8500_DEBUG] = {
825 .num_ranges = 1,
826 .range = (struct ab8500_reg_range[]) {
827 {
828 .first = 0x05,
829 .last = 0x07,
830 },
831 },
832 },
833 [AB8500_PROD_TEST] = {
834 .num_ranges = 0,
835 .range = NULL,
836 },
837 [AB8500_STE_TEST] = {
838 .num_ranges = 0,
839 .range = NULL,
840 },
841 [AB8500_OTP_EMUL] = {
842 .num_ranges = 1,
843 .range = (struct ab8500_reg_range[]) {
844 {
845 .first = 0x01,
846 .last = 0x15,
847 },
848 },
849 },
850};
851
Lee Jones971480f2012-11-19 12:20:03 +0100852struct ab8500_prcmu_ranges ab8540_debug_ranges[AB8500_NUM_BANKS] = {
853 [AB8500_M_FSM_RANK] = {
854 .num_ranges = 1,
855 .range = (struct ab8500_reg_range[]) {
856 {
857 .first = 0x00,
858 .last = 0x0B,
859 },
860 },
861 },
862 [AB8500_SYS_CTRL1_BLOCK] = {
863 .num_ranges = 6,
864 .range = (struct ab8500_reg_range[]) {
865 {
866 .first = 0x00,
867 .last = 0x04,
868 },
869 {
870 .first = 0x42,
871 .last = 0x42,
872 },
873 {
874 .first = 0x50,
875 .last = 0x54,
876 },
877 {
878 .first = 0x57,
879 .last = 0x57,
880 },
881 {
882 .first = 0x80,
883 .last = 0x83,
884 },
885 {
886 .first = 0x90,
887 .last = 0x90,
888 },
889 },
890 },
891 [AB8500_SYS_CTRL2_BLOCK] = {
892 .num_ranges = 5,
893 .range = (struct ab8500_reg_range[]) {
894 {
895 .first = 0x00,
896 .last = 0x0D,
897 },
898 {
899 .first = 0x0F,
900 .last = 0x10,
901 },
902 {
903 .first = 0x20,
904 .last = 0x21,
905 },
906 {
907 .first = 0x32,
908 .last = 0x3C,
909 },
910 {
911 .first = 0x40,
912 .last = 0x42,
913 },
914 },
915 },
916 [AB8500_REGU_CTRL1] = {
917 .num_ranges = 4,
918 .range = (struct ab8500_reg_range[]) {
919 {
920 .first = 0x03,
921 .last = 0x15,
922 },
923 {
924 .first = 0x20,
925 .last = 0x20,
926 },
927 {
928 .first = 0x80,
929 .last = 0x85,
930 },
931 {
932 .first = 0x87,
933 .last = 0x88,
934 },
935 },
936 },
937 [AB8500_REGU_CTRL2] = {
938 .num_ranges = 8,
939 .range = (struct ab8500_reg_range[]) {
940 {
941 .first = 0x00,
942 .last = 0x06,
943 },
944 {
945 .first = 0x08,
946 .last = 0x15,
947 },
948 {
949 .first = 0x17,
950 .last = 0x19,
951 },
952 {
953 .first = 0x1B,
954 .last = 0x1D,
955 },
956 {
957 .first = 0x1F,
958 .last = 0x2F,
959 },
960 {
961 .first = 0x31,
962 .last = 0x3A,
963 },
964 {
965 .first = 0x43,
966 .last = 0x44,
967 },
968 {
969 .first = 0x48,
970 .last = 0x49,
971 },
972 },
973 },
974 [AB8500_USB] = {
975 .num_ranges = 3,
976 .range = (struct ab8500_reg_range[]) {
977 {
978 .first = 0x80,
979 .last = 0x83,
980 },
981 {
982 .first = 0x87,
983 .last = 0x8A,
984 },
985 {
986 .first = 0x91,
987 .last = 0x94,
988 },
989 },
990 },
991 [AB8500_TVOUT] = {
992 .num_ranges = 0,
993 .range = NULL
994 },
995 [AB8500_DBI] = {
996 .num_ranges = 4,
997 .range = (struct ab8500_reg_range[]) {
998 {
999 .first = 0x00,
1000 .last = 0x07,
1001 },
1002 {
1003 .first = 0x10,
1004 .last = 0x11,
1005 },
1006 {
1007 .first = 0x20,
1008 .last = 0x21,
1009 },
1010 {
1011 .first = 0x30,
1012 .last = 0x43,
1013 },
1014 },
1015 },
1016 [AB8500_ECI_AV_ACC] = {
1017 .num_ranges = 2,
1018 .range = (struct ab8500_reg_range[]) {
1019 {
1020 .first = 0x00,
1021 .last = 0x03,
1022 },
1023 {
1024 .first = 0x80,
1025 .last = 0x82,
1026 },
1027 },
1028 },
1029 [AB8500_RESERVED] = {
1030 .num_ranges = 0,
1031 .range = NULL,
1032 },
1033 [AB8500_GPADC] = {
1034 .num_ranges = 4,
1035 .range = (struct ab8500_reg_range[]) {
1036 {
1037 .first = 0x00,
1038 .last = 0x01,
1039 },
1040 {
1041 .first = 0x04,
1042 .last = 0x06,
1043 },
1044 {
1045 .first = 0x09,
1046 .last = 0x0A,
1047 },
1048 {
1049 .first = 0x10,
1050 .last = 0x14,
1051 },
1052 },
1053 },
1054 [AB8500_CHARGER] = {
1055 .num_ranges = 10,
1056 .range = (struct ab8500_reg_range[]) {
1057 {
1058 .first = 0x00,
1059 .last = 0x00,
1060 },
1061 {
1062 .first = 0x02,
1063 .last = 0x05,
1064 },
1065 {
1066 .first = 0x40,
1067 .last = 0x44,
1068 },
1069 {
1070 .first = 0x50,
1071 .last = 0x57,
1072 },
1073 {
1074 .first = 0x60,
1075 .last = 0x60,
1076 },
1077 {
1078 .first = 0x70,
1079 .last = 0x70,
1080 },
1081 {
1082 .first = 0xA0,
1083 .last = 0xA9,
1084 },
1085 {
1086 .first = 0xAF,
1087 .last = 0xB2,
1088 },
1089 {
1090 .first = 0xC0,
1091 .last = 0xC6,
1092 },
1093 {
1094 .first = 0xF5,
1095 .last = 0xF5,
1096 },
1097 },
1098 },
1099 [AB8500_GAS_GAUGE] = {
1100 .num_ranges = 3,
1101 .range = (struct ab8500_reg_range[]) {
1102 {
1103 .first = 0x00,
1104 .last = 0x00,
1105 },
1106 {
1107 .first = 0x07,
1108 .last = 0x0A,
1109 },
1110 {
1111 .first = 0x10,
1112 .last = 0x14,
1113 },
1114 },
1115 },
1116 [AB8500_AUDIO] = {
1117 .num_ranges = 1,
1118 .range = (struct ab8500_reg_range[]) {
1119 {
1120 .first = 0x00,
1121 .last = 0x9f,
1122 },
1123 },
1124 },
1125 [AB8500_INTERRUPT] = {
1126 .num_ranges = 6,
1127 .range = (struct ab8500_reg_range[]) {
1128 {
1129 .first = 0x00,
1130 .last = 0x05,
1131 },
1132 {
1133 .first = 0x0B,
1134 .last = 0x0D,
1135 },
1136 {
1137 .first = 0x12,
1138 .last = 0x20,
1139 },
1140 /* Latch registers should not be read here */
1141 {
1142 .first = 0x40,
1143 .last = 0x45,
1144 },
1145 {
1146 .first = 0x4B,
1147 .last = 0x4D,
1148 },
1149 {
1150 .first = 0x52,
1151 .last = 0x60,
1152 },
1153 /* LatchHier registers should not be read here */
1154 },
1155 },
1156 [AB8500_RTC] = {
1157 .num_ranges = 3,
1158 .range = (struct ab8500_reg_range[]) {
1159 {
1160 .first = 0x00,
1161 .last = 0x07,
1162 },
1163 {
1164 .first = 0x0B,
1165 .last = 0x18,
1166 },
1167 {
1168 .first = 0x20,
1169 .last = 0x25,
1170 },
1171 },
1172 },
1173 [AB8500_MISC] = {
1174 .num_ranges = 9,
1175 .range = (struct ab8500_reg_range[]) {
1176 {
1177 .first = 0x00,
1178 .last = 0x06,
1179 },
1180 {
1181 .first = 0x10,
1182 .last = 0x16,
1183 },
1184 {
1185 .first = 0x20,
1186 .last = 0x26,
1187 },
1188 {
1189 .first = 0x30,
1190 .last = 0x36,
1191 },
1192 {
1193 .first = 0x40,
1194 .last = 0x49,
1195 },
1196 {
1197 .first = 0x50,
1198 .last = 0x50,
1199 },
1200 {
1201 .first = 0x60,
1202 .last = 0x6B,
1203 },
1204 {
1205 .first = 0x70,
1206 .last = 0x74,
1207 },
1208 {
1209 .first = 0x80,
1210 .last = 0x82,
1211 },
1212 },
1213 },
1214 [AB8500_DEVELOPMENT] = {
1215 .num_ranges = 3,
1216 .range = (struct ab8500_reg_range[]) {
1217 {
1218 .first = 0x00,
1219 .last = 0x01,
1220 },
1221 {
1222 .first = 0x06,
1223 .last = 0x06,
1224 },
1225 {
1226 .first = 0x10,
1227 .last = 0x21,
1228 },
1229 },
1230 },
1231 [AB8500_DEBUG] = {
1232 .num_ranges = 3,
1233 .range = (struct ab8500_reg_range[]) {
1234 {
1235 .first = 0x01,
1236 .last = 0x0C,
1237 },
1238 {
1239 .first = 0x0E,
1240 .last = 0x11,
1241 },
1242 {
1243 .first = 0x80,
1244 .last = 0x81,
1245 },
1246 },
1247 },
1248 [AB8500_PROD_TEST] = {
1249 .num_ranges = 0,
1250 .range = NULL,
1251 },
1252 [AB8500_STE_TEST] = {
1253 .num_ranges = 0,
1254 .range = NULL,
1255 },
1256 [AB8500_OTP_EMUL] = {
1257 .num_ranges = 1,
1258 .range = (struct ab8500_reg_range[]) {
1259 {
1260 .first = 0x00,
1261 .last = 0x3F,
1262 },
1263 },
1264 },
1265};
1266
1267
Lee Jones4b8ac082013-01-14 16:10:36 +00001268static irqreturn_t ab8500_debug_handler(int irq, void *data)
1269{
1270 char buf[16];
1271 struct kobject *kobj = (struct kobject *)data;
Mattias Wallin0b337e72010-11-19 17:55:11 +01001272 unsigned int irq_abb = irq - irq_first;
Lee Jones4b8ac082013-01-14 16:10:36 +00001273
Linus Walleijddba25f2012-02-03 11:19:05 +01001274 if (irq_abb < num_irqs)
Mattias Wallin0b337e72010-11-19 17:55:11 +01001275 irq_count[irq_abb]++;
Lee Jones4b8ac082013-01-14 16:10:36 +00001276 /*
1277 * This makes it possible to use poll for events (POLLPRI | POLLERR)
Mattias Wallin0b337e72010-11-19 17:55:11 +01001278 * from userspace on sysfs file named <irq-nr>
Lee Jones4b8ac082013-01-14 16:10:36 +00001279 */
Mattias Wallin0b337e72010-11-19 17:55:11 +01001280 sprintf(buf, "%d", irq);
Lee Jones4b8ac082013-01-14 16:10:36 +00001281 sysfs_notify(kobj, NULL, buf);
1282
1283 return IRQ_HANDLED;
1284}
1285
Mian Yousaf Kaukab42002c62012-01-26 15:39:20 +01001286/* Prints to seq_file or log_buf */
1287static int ab8500_registers_print(struct device *dev, u32 bank,
1288 struct seq_file *s)
Mattias Wallin5814fc32010-09-13 16:05:04 +02001289{
Mattias Wallind7b9f322010-11-26 13:06:39 +01001290 unsigned int i;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001291
Mattias Wallind7b9f322010-11-26 13:06:39 +01001292 for (i = 0; i < debug_ranges[bank].num_ranges; i++) {
1293 u32 reg;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001294
Mattias Wallind7b9f322010-11-26 13:06:39 +01001295 for (reg = debug_ranges[bank].range[i].first;
1296 reg <= debug_ranges[bank].range[i].last;
1297 reg++) {
1298 u8 value;
1299 int err;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001300
Mattias Wallind7b9f322010-11-26 13:06:39 +01001301 err = abx500_get_register_interruptible(dev,
1302 (u8)bank, (u8)reg, &value);
1303 if (err < 0) {
1304 dev_err(dev, "ab->read fail %d\n", err);
1305 return err;
1306 }
Mattias Wallin5814fc32010-09-13 16:05:04 +02001307
Mian Yousaf Kaukab42002c62012-01-26 15:39:20 +01001308 if (s) {
Mattias Wallincfc08492012-05-28 15:53:58 +02001309 err = seq_printf(s, " [0x%02X/0x%02X]: 0x%02X\n",
Mian Yousaf Kaukab42002c62012-01-26 15:39:20 +01001310 bank, reg, value);
1311 if (err < 0) {
Mian Yousaf Kaukab42002c62012-01-26 15:39:20 +01001312 /* Error is not returned here since
1313 * the output is wanted in any case */
1314 return 0;
1315 }
1316 } else {
Mattias Wallincfc08492012-05-28 15:53:58 +02001317 printk(KERN_INFO" [0x%02X/0x%02X]: 0x%02X\n",
1318 bank, reg, value);
Mattias Wallind7b9f322010-11-26 13:06:39 +01001319 }
1320 }
1321 }
1322 return 0;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001323}
1324
Mian Yousaf Kaukab42002c62012-01-26 15:39:20 +01001325static int ab8500_print_bank_registers(struct seq_file *s, void *p)
1326{
1327 struct device *dev = s->private;
1328 u32 bank = debug_bank;
1329
1330 seq_printf(s, AB8500_NAME_STRING " register values:\n");
1331
Mattias Wallincfc08492012-05-28 15:53:58 +02001332 seq_printf(s, " bank 0x%02X:\n", bank);
Mian Yousaf Kaukab42002c62012-01-26 15:39:20 +01001333
1334 ab8500_registers_print(dev, bank, s);
1335 return 0;
1336}
1337
Mattias Wallin5814fc32010-09-13 16:05:04 +02001338static int ab8500_registers_open(struct inode *inode, struct file *file)
1339{
Mian Yousaf Kaukab42002c62012-01-26 15:39:20 +01001340 return single_open(file, ab8500_print_bank_registers, inode->i_private);
Mattias Wallin5814fc32010-09-13 16:05:04 +02001341}
1342
1343static const struct file_operations ab8500_registers_fops = {
Mattias Wallind7b9f322010-11-26 13:06:39 +01001344 .open = ab8500_registers_open,
1345 .read = seq_read,
1346 .llseek = seq_lseek,
1347 .release = single_release,
1348 .owner = THIS_MODULE,
Mattias Wallin5814fc32010-09-13 16:05:04 +02001349};
1350
Mian Yousaf Kaukab42002c62012-01-26 15:39:20 +01001351static int ab8500_print_all_banks(struct seq_file *s, void *p)
1352{
1353 struct device *dev = s->private;
1354 unsigned int i;
1355 int err;
1356
1357 seq_printf(s, AB8500_NAME_STRING " register values:\n");
1358
Lee Jones971480f2012-11-19 12:20:03 +01001359 for (i = 0; i < AB8500_NUM_BANKS; i++) {
Mattias Wallincfc08492012-05-28 15:53:58 +02001360 err = seq_printf(s, " bank 0x%02X:\n", i);
Mian Yousaf Kaukab42002c62012-01-26 15:39:20 +01001361
1362 ab8500_registers_print(dev, i, s);
1363 }
1364 return 0;
1365}
1366
Mian Yousaf Kaukab1d843a62012-01-27 11:35:41 +01001367/* Dump registers to kernel log */
1368void ab8500_dump_all_banks(struct device *dev)
1369{
1370 unsigned int i;
1371
1372 printk(KERN_INFO"ab8500 register values:\n");
1373
1374 for (i = 1; i < AB8500_NUM_BANKS; i++) {
Mattias Wallincfc08492012-05-28 15:53:58 +02001375 printk(KERN_INFO" bank 0x%02X:\n", i);
Mian Yousaf Kaukab1d843a62012-01-27 11:35:41 +01001376 ab8500_registers_print(dev, i, NULL);
1377 }
1378}
1379
Lee Jones5ff90902013-02-12 14:35:28 +00001380/* Space for 500 registers. */
1381#define DUMP_MAX_REGS 700
1382struct ab8500_register_dump
1383{
1384 u8 bank;
1385 u8 reg;
1386 u8 value;
Lee Jones5ff90902013-02-12 14:35:28 +00001387} ab8500_complete_register_dump[DUMP_MAX_REGS];
1388
1389extern int prcmu_abb_read(u8 slave, u8 reg, u8 *value, u8 size);
1390
1391/* This shall only be called upon kernel panic! */
1392void ab8500_dump_all_banks_to_mem(void)
1393{
1394 int i, r = 0;
1395 u8 bank;
Jonas Aaberg222460c2012-06-18 10:35:28 +02001396 int err = 0;
Lee Jones5ff90902013-02-12 14:35:28 +00001397
1398 pr_info("Saving all ABB registers at \"ab8500_complete_register_dump\" "
1399 "for crash analyze.\n");
1400
Lee Jones971480f2012-11-19 12:20:03 +01001401 for (bank = 0; bank < AB8500_NUM_BANKS; bank++) {
Lee Jones5ff90902013-02-12 14:35:28 +00001402 for (i = 0; i < debug_ranges[bank].num_ranges; i++) {
1403 u8 reg;
1404
1405 for (reg = debug_ranges[bank].range[i].first;
1406 reg <= debug_ranges[bank].range[i].last;
1407 reg++) {
1408 u8 value;
Lee Jones5ff90902013-02-12 14:35:28 +00001409
1410 err = prcmu_abb_read(bank, reg, &value, 1);
1411
Jonas Aaberg222460c2012-06-18 10:35:28 +02001412 if (err < 0)
1413 goto out;
1414
Lee Jones5ff90902013-02-12 14:35:28 +00001415 ab8500_complete_register_dump[r].bank = bank;
1416 ab8500_complete_register_dump[r].reg = reg;
1417 ab8500_complete_register_dump[r].value = value;
1418
1419 r++;
1420
1421 if (r >= DUMP_MAX_REGS) {
1422 pr_err("%s: too many register to dump!\n",
1423 __func__);
Jonas Aaberg222460c2012-06-18 10:35:28 +02001424 err = -EINVAL;
1425 goto out;
Lee Jones5ff90902013-02-12 14:35:28 +00001426 }
1427 }
1428 }
1429 }
Jonas Aaberg222460c2012-06-18 10:35:28 +02001430out:
1431 if (err >= 0)
1432 pr_info("Saved all ABB registers.\n");
1433 else
1434 pr_info("Failed to save all ABB registers.\n");
Lee Jones5ff90902013-02-12 14:35:28 +00001435}
1436
Mian Yousaf Kaukab42002c62012-01-26 15:39:20 +01001437static int ab8500_all_banks_open(struct inode *inode, struct file *file)
1438{
1439 struct seq_file *s;
1440 int err;
1441
1442 err = single_open(file, ab8500_print_all_banks, inode->i_private);
1443 if (!err) {
1444 /* Default buf size in seq_read is not enough */
1445 s = (struct seq_file *)file->private_data;
1446 s->size = (PAGE_SIZE * 2);
1447 s->buf = kmalloc(s->size, GFP_KERNEL);
1448 if (!s->buf) {
1449 single_release(inode, file);
1450 err = -ENOMEM;
1451 }
1452 }
1453 return err;
1454}
1455
1456static const struct file_operations ab8500_all_banks_fops = {
1457 .open = ab8500_all_banks_open,
1458 .read = seq_read,
1459 .llseek = seq_lseek,
1460 .release = single_release,
1461 .owner = THIS_MODULE,
1462};
1463
Mattias Wallin5814fc32010-09-13 16:05:04 +02001464static int ab8500_bank_print(struct seq_file *s, void *p)
1465{
Mattias Wallincfc08492012-05-28 15:53:58 +02001466 return seq_printf(s, "0x%02X\n", debug_bank);
Mattias Wallin5814fc32010-09-13 16:05:04 +02001467}
1468
1469static int ab8500_bank_open(struct inode *inode, struct file *file)
1470{
Mattias Wallind7b9f322010-11-26 13:06:39 +01001471 return single_open(file, ab8500_bank_print, inode->i_private);
Mattias Wallin5814fc32010-09-13 16:05:04 +02001472}
1473
1474static ssize_t ab8500_bank_write(struct file *file,
Mattias Wallind7b9f322010-11-26 13:06:39 +01001475 const char __user *user_buf,
1476 size_t count, loff_t *ppos)
Mattias Wallin5814fc32010-09-13 16:05:04 +02001477{
Mattias Wallind7b9f322010-11-26 13:06:39 +01001478 struct device *dev = ((struct seq_file *)(file->private_data))->private;
Mattias Wallind7b9f322010-11-26 13:06:39 +01001479 unsigned long user_bank;
1480 int err;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001481
Peter Huewe8504d632011-06-06 22:43:32 +02001482 err = kstrtoul_from_user(user_buf, count, 0, &user_bank);
Mattias Wallind7b9f322010-11-26 13:06:39 +01001483 if (err)
Peter Huewe8504d632011-06-06 22:43:32 +02001484 return err;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001485
Mattias Wallind7b9f322010-11-26 13:06:39 +01001486 if (user_bank >= AB8500_NUM_BANKS) {
1487 dev_err(dev, "debugfs error input > number of banks\n");
1488 return -EINVAL;
1489 }
Mattias Wallin5814fc32010-09-13 16:05:04 +02001490
Mattias Wallind7b9f322010-11-26 13:06:39 +01001491 debug_bank = user_bank;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001492
Peter Huewe8504d632011-06-06 22:43:32 +02001493 return count;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001494}
1495
1496static int ab8500_address_print(struct seq_file *s, void *p)
1497{
Mattias Wallind7b9f322010-11-26 13:06:39 +01001498 return seq_printf(s, "0x%02X\n", debug_address);
Mattias Wallin5814fc32010-09-13 16:05:04 +02001499}
1500
1501static int ab8500_address_open(struct inode *inode, struct file *file)
1502{
Mattias Wallind7b9f322010-11-26 13:06:39 +01001503 return single_open(file, ab8500_address_print, inode->i_private);
Mattias Wallin5814fc32010-09-13 16:05:04 +02001504}
1505
1506static ssize_t ab8500_address_write(struct file *file,
Lee Jones9f9ba152013-02-26 12:05:15 +00001507 const char __user *user_buf,
1508 size_t count, loff_t *ppos)
Mattias Wallin5814fc32010-09-13 16:05:04 +02001509{
Mattias Wallind7b9f322010-11-26 13:06:39 +01001510 struct device *dev = ((struct seq_file *)(file->private_data))->private;
Mattias Wallind7b9f322010-11-26 13:06:39 +01001511 unsigned long user_address;
1512 int err;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001513
Peter Huewe8504d632011-06-06 22:43:32 +02001514 err = kstrtoul_from_user(user_buf, count, 0, &user_address);
Mattias Wallind7b9f322010-11-26 13:06:39 +01001515 if (err)
Peter Huewe8504d632011-06-06 22:43:32 +02001516 return err;
1517
Mattias Wallind7b9f322010-11-26 13:06:39 +01001518 if (user_address > 0xff) {
1519 dev_err(dev, "debugfs error input > 0xff\n");
1520 return -EINVAL;
1521 }
1522 debug_address = user_address;
srinidhi kasagar7b830ae2012-11-23 15:11:00 +05301523
Peter Huewe8504d632011-06-06 22:43:32 +02001524 return count;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001525}
1526
1527static int ab8500_val_print(struct seq_file *s, void *p)
1528{
Mattias Wallind7b9f322010-11-26 13:06:39 +01001529 struct device *dev = s->private;
1530 int ret;
1531 u8 regvalue;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001532
Mattias Wallind7b9f322010-11-26 13:06:39 +01001533 ret = abx500_get_register_interruptible(dev,
1534 (u8)debug_bank, (u8)debug_address, &regvalue);
1535 if (ret < 0) {
1536 dev_err(dev, "abx500_get_reg fail %d, %d\n",
1537 ret, __LINE__);
1538 return -EINVAL;
1539 }
1540 seq_printf(s, "0x%02X\n", regvalue);
Mattias Wallin5814fc32010-09-13 16:05:04 +02001541
Mattias Wallind7b9f322010-11-26 13:06:39 +01001542 return 0;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001543}
1544
1545static int ab8500_val_open(struct inode *inode, struct file *file)
1546{
Mattias Wallind7b9f322010-11-26 13:06:39 +01001547 return single_open(file, ab8500_val_print, inode->i_private);
Mattias Wallin5814fc32010-09-13 16:05:04 +02001548}
1549
1550static ssize_t ab8500_val_write(struct file *file,
Lee Jones9f9ba152013-02-26 12:05:15 +00001551 const char __user *user_buf,
1552 size_t count, loff_t *ppos)
Mattias Wallin5814fc32010-09-13 16:05:04 +02001553{
Mattias Wallind7b9f322010-11-26 13:06:39 +01001554 struct device *dev = ((struct seq_file *)(file->private_data))->private;
Mattias Wallind7b9f322010-11-26 13:06:39 +01001555 unsigned long user_val;
1556 int err;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001557
Peter Huewe8504d632011-06-06 22:43:32 +02001558 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
Mattias Wallind7b9f322010-11-26 13:06:39 +01001559 if (err)
Peter Huewe8504d632011-06-06 22:43:32 +02001560 return err;
1561
Mattias Wallind7b9f322010-11-26 13:06:39 +01001562 if (user_val > 0xff) {
1563 dev_err(dev, "debugfs error input > 0xff\n");
1564 return -EINVAL;
1565 }
1566 err = abx500_set_register_interruptible(dev,
1567 (u8)debug_bank, debug_address, (u8)user_val);
1568 if (err < 0) {
1569 printk(KERN_ERR "abx500_set_reg failed %d, %d", err, __LINE__);
1570 return -EINVAL;
1571 }
Mattias Wallin5814fc32010-09-13 16:05:04 +02001572
Peter Huewe8504d632011-06-06 22:43:32 +02001573 return count;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001574}
1575
carriere etienne0fbce762011-04-08 16:26:36 +02001576/*
Bengt Jonsson8f0eb432012-02-14 13:01:00 +01001577 * Interrupt status
1578 */
1579static u32 num_interrupts[AB8500_MAX_NR_IRQS];
Jonas Aaberg2cf64e22012-05-31 07:57:07 +02001580static u32 num_wake_interrupts[AB8500_MAX_NR_IRQS];
Bengt Jonsson8f0eb432012-02-14 13:01:00 +01001581static int num_interrupt_lines;
1582
Jonas Aaberg2cf64e22012-05-31 07:57:07 +02001583bool __attribute__((weak)) suspend_test_wake_cause_interrupt_is_mine(u32 my_int)
1584{
1585 return false;
1586}
1587
Bengt Jonsson8f0eb432012-02-14 13:01:00 +01001588void ab8500_debug_register_interrupt(int line)
1589{
Jonas Aaberg2cf64e22012-05-31 07:57:07 +02001590 if (line < num_interrupt_lines) {
Bengt Jonsson8f0eb432012-02-14 13:01:00 +01001591 num_interrupts[line]++;
Jonas Aaberg2cf64e22012-05-31 07:57:07 +02001592 if (suspend_test_wake_cause_interrupt_is_mine(IRQ_DB8500_AB8500))
1593 num_wake_interrupts[line]++;
1594 }
Bengt Jonsson8f0eb432012-02-14 13:01:00 +01001595}
1596
1597static int ab8500_interrupts_print(struct seq_file *s, void *p)
1598{
1599 int line;
1600
Jonas Aaberg2cf64e22012-05-31 07:57:07 +02001601 seq_printf(s, "name: number: number of: wake:\n");
Bengt Jonsson8f0eb432012-02-14 13:01:00 +01001602
Jonas Aaberg2cf64e22012-05-31 07:57:07 +02001603 for (line = 0; line < num_interrupt_lines; line++) {
1604 struct irq_desc *desc = irq_to_desc(line + irq_first);
1605 struct irqaction *action = desc->action;
1606
1607 seq_printf(s, "%3i: %6i %4i", line,
1608 num_interrupts[line],
1609 num_wake_interrupts[line]);
1610
1611 if (desc && desc->name)
1612 seq_printf(s, "-%-8s", desc->name);
1613 if (action) {
1614 seq_printf(s, " %s", action->name);
1615 while ((action = action->next) != NULL)
1616 seq_printf(s, ", %s", action->name);
1617 }
1618 seq_putc(s, '\n');
1619 }
Bengt Jonsson8f0eb432012-02-14 13:01:00 +01001620
1621 return 0;
1622}
1623
1624static int ab8500_interrupts_open(struct inode *inode, struct file *file)
1625{
1626 return single_open(file, ab8500_interrupts_print, inode->i_private);
1627}
1628
1629/*
carriere etienne0fbce762011-04-08 16:26:36 +02001630 * - HWREG DB8500 formated routines
1631 */
1632static int ab8500_hwreg_print(struct seq_file *s, void *d)
1633{
1634 struct device *dev = s->private;
1635 int ret;
1636 u8 regvalue;
1637
1638 ret = abx500_get_register_interruptible(dev,
1639 (u8)hwreg_cfg.bank, (u8)hwreg_cfg.addr, &regvalue);
1640 if (ret < 0) {
1641 dev_err(dev, "abx500_get_reg fail %d, %d\n",
1642 ret, __LINE__);
1643 return -EINVAL;
1644 }
1645
1646 if (hwreg_cfg.shift >= 0)
1647 regvalue >>= hwreg_cfg.shift;
1648 else
1649 regvalue <<= -hwreg_cfg.shift;
1650 regvalue &= hwreg_cfg.mask;
1651
1652 if (REG_FMT_DEC(&hwreg_cfg))
1653 seq_printf(s, "%d\n", regvalue);
1654 else
1655 seq_printf(s, "0x%02X\n", regvalue);
1656 return 0;
1657}
1658
1659static int ab8500_hwreg_open(struct inode *inode, struct file *file)
1660{
1661 return single_open(file, ab8500_hwreg_print, inode->i_private);
1662}
1663
Lee Jonesc7ebaee2013-02-26 14:03:33 +00001664#define AB8500_SUPPLY_CONTROL_CONFIG_1 0x01
1665#define AB8500_SUPPLY_CONTROL_REG 0x00
1666#define AB8500_FIRST_SIM_REG 0x80
1667#define AB8500_LAST_SIM_REG 0x8B
1668#define AB8505_LAST_SIM_REG 0x8C
1669
1670static int ab8500_print_modem_registers(struct seq_file *s, void *p)
1671{
1672 struct device *dev = s->private;
1673 struct ab8500 *ab8500;
1674 int err;
1675 u8 value;
1676 u8 orig_value;
1677 u32 bank = AB8500_REGU_CTRL2;
1678 u32 last_sim_reg = AB8500_LAST_SIM_REG;
1679 u32 reg;
1680
1681 ab8500 = dev_get_drvdata(dev->parent);
1682 dev_warn(dev, "WARNING! This operation can interfer with modem side\n"
1683 "and should only be done with care\n");
1684
1685 err = abx500_get_register_interruptible(dev,
1686 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG, &orig_value);
1687 if (err < 0) {
1688 dev_err(dev, "ab->read fail %d\n", err);
1689 return err;
1690 }
1691 /* Config 1 will allow APE side to read SIM registers */
1692 err = abx500_set_register_interruptible(dev,
1693 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG,
1694 AB8500_SUPPLY_CONTROL_CONFIG_1);
1695 if (err < 0) {
1696 dev_err(dev, "ab->write fail %d\n", err);
1697 return err;
1698 }
1699
1700 seq_printf(s, " bank 0x%02X:\n", bank);
1701
1702 if (is_ab9540(ab8500) || is_ab8505(ab8500))
1703 last_sim_reg = AB8505_LAST_SIM_REG;
1704
1705 for (reg = AB8500_FIRST_SIM_REG; reg <= last_sim_reg; reg++) {
1706 err = abx500_get_register_interruptible(dev,
1707 bank, reg, &value);
1708 if (err < 0) {
1709 dev_err(dev, "ab->read fail %d\n", err);
1710 return err;
1711 }
1712 err = seq_printf(s, " [0x%02X/0x%02X]: 0x%02X\n",
1713 bank, reg, value);
1714 }
1715 err = abx500_set_register_interruptible(dev,
1716 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG, orig_value);
1717 if (err < 0) {
1718 dev_err(dev, "ab->write fail %d\n", err);
1719 return err;
1720 }
1721 return 0;
1722}
1723
1724static int ab8500_modem_open(struct inode *inode, struct file *file)
1725{
1726 return single_open(file, ab8500_print_modem_registers, inode->i_private);
1727}
1728
1729static const struct file_operations ab8500_modem_fops = {
1730 .open = ab8500_modem_open,
1731 .read = seq_read,
1732 .llseek = seq_lseek,
1733 .release = single_release,
1734 .owner = THIS_MODULE,
1735};
1736
John Beckett1478a312011-05-31 13:54:27 +01001737static int ab8500_gpadc_bat_ctrl_print(struct seq_file *s, void *p)
1738{
1739 int bat_ctrl_raw;
1740 int bat_ctrl_convert;
1741 struct ab8500_gpadc *gpadc;
1742
Philippe Langlais8908c042012-04-18 15:52:59 +02001743 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00001744 bat_ctrl_raw = ab8500_gpadc_read_raw(gpadc, BAT_CTRL,
1745 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01001746 bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc,
Lee Jones73482342013-02-26 10:06:55 +00001747 BAT_CTRL, bat_ctrl_raw);
John Beckett1478a312011-05-31 13:54:27 +01001748
1749 return seq_printf(s, "%d,0x%X\n",
Lee Jones9f9ba152013-02-26 12:05:15 +00001750 bat_ctrl_convert, bat_ctrl_raw);
John Beckett1478a312011-05-31 13:54:27 +01001751}
1752
1753static int ab8500_gpadc_bat_ctrl_open(struct inode *inode, struct file *file)
1754{
1755 return single_open(file, ab8500_gpadc_bat_ctrl_print, inode->i_private);
1756}
1757
1758static const struct file_operations ab8500_gpadc_bat_ctrl_fops = {
1759 .open = ab8500_gpadc_bat_ctrl_open,
1760 .read = seq_read,
1761 .llseek = seq_lseek,
1762 .release = single_release,
1763 .owner = THIS_MODULE,
1764};
1765
1766static int ab8500_gpadc_btemp_ball_print(struct seq_file *s, void *p)
1767{
1768 int btemp_ball_raw;
1769 int btemp_ball_convert;
1770 struct ab8500_gpadc *gpadc;
1771
Philippe Langlais8908c042012-04-18 15:52:59 +02001772 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00001773 btemp_ball_raw = ab8500_gpadc_read_raw(gpadc, BTEMP_BALL,
1774 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01001775 btemp_ball_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL,
Lee Jones73482342013-02-26 10:06:55 +00001776 btemp_ball_raw);
John Beckett1478a312011-05-31 13:54:27 +01001777
1778 return seq_printf(s,
Lee Jones9f9ba152013-02-26 12:05:15 +00001779 "%d,0x%X\n", btemp_ball_convert, btemp_ball_raw);
John Beckett1478a312011-05-31 13:54:27 +01001780}
1781
1782static int ab8500_gpadc_btemp_ball_open(struct inode *inode,
Lee Jones9f9ba152013-02-26 12:05:15 +00001783 struct file *file)
John Beckett1478a312011-05-31 13:54:27 +01001784{
1785 return single_open(file, ab8500_gpadc_btemp_ball_print, inode->i_private);
1786}
1787
1788static const struct file_operations ab8500_gpadc_btemp_ball_fops = {
1789 .open = ab8500_gpadc_btemp_ball_open,
1790 .read = seq_read,
1791 .llseek = seq_lseek,
1792 .release = single_release,
1793 .owner = THIS_MODULE,
1794};
1795
1796static int ab8500_gpadc_main_charger_v_print(struct seq_file *s, void *p)
1797{
1798 int main_charger_v_raw;
1799 int main_charger_v_convert;
1800 struct ab8500_gpadc *gpadc;
1801
Philippe Langlais8908c042012-04-18 15:52:59 +02001802 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00001803 main_charger_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_V,
1804 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01001805 main_charger_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
Lee Jones73482342013-02-26 10:06:55 +00001806 MAIN_CHARGER_V, main_charger_v_raw);
John Beckett1478a312011-05-31 13:54:27 +01001807
1808 return seq_printf(s, "%d,0x%X\n",
1809 main_charger_v_convert, main_charger_v_raw);
1810}
1811
1812static int ab8500_gpadc_main_charger_v_open(struct inode *inode,
Lee Jones9f9ba152013-02-26 12:05:15 +00001813 struct file *file)
John Beckett1478a312011-05-31 13:54:27 +01001814{
1815 return single_open(file, ab8500_gpadc_main_charger_v_print,
Lee Jones9f9ba152013-02-26 12:05:15 +00001816 inode->i_private);
John Beckett1478a312011-05-31 13:54:27 +01001817}
1818
1819static const struct file_operations ab8500_gpadc_main_charger_v_fops = {
1820 .open = ab8500_gpadc_main_charger_v_open,
1821 .read = seq_read,
1822 .llseek = seq_lseek,
1823 .release = single_release,
1824 .owner = THIS_MODULE,
1825};
1826
1827static int ab8500_gpadc_acc_detect1_print(struct seq_file *s, void *p)
1828{
1829 int acc_detect1_raw;
1830 int acc_detect1_convert;
1831 struct ab8500_gpadc *gpadc;
1832
Philippe Langlais8908c042012-04-18 15:52:59 +02001833 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00001834 acc_detect1_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT1,
1835 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01001836 acc_detect1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ACC_DETECT1,
Lee Jones73482342013-02-26 10:06:55 +00001837 acc_detect1_raw);
John Beckett1478a312011-05-31 13:54:27 +01001838
1839 return seq_printf(s, "%d,0x%X\n",
Lee Jones9f9ba152013-02-26 12:05:15 +00001840 acc_detect1_convert, acc_detect1_raw);
John Beckett1478a312011-05-31 13:54:27 +01001841}
1842
1843static int ab8500_gpadc_acc_detect1_open(struct inode *inode,
Lee Jones9f9ba152013-02-26 12:05:15 +00001844 struct file *file)
John Beckett1478a312011-05-31 13:54:27 +01001845{
1846 return single_open(file, ab8500_gpadc_acc_detect1_print,
Lee Jones9f9ba152013-02-26 12:05:15 +00001847 inode->i_private);
John Beckett1478a312011-05-31 13:54:27 +01001848}
1849
1850static const struct file_operations ab8500_gpadc_acc_detect1_fops = {
1851 .open = ab8500_gpadc_acc_detect1_open,
1852 .read = seq_read,
1853 .llseek = seq_lseek,
1854 .release = single_release,
1855 .owner = THIS_MODULE,
1856};
1857
1858static int ab8500_gpadc_acc_detect2_print(struct seq_file *s, void *p)
1859{
1860 int acc_detect2_raw;
1861 int acc_detect2_convert;
1862 struct ab8500_gpadc *gpadc;
1863
Philippe Langlais8908c042012-04-18 15:52:59 +02001864 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00001865 acc_detect2_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT2,
1866 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01001867 acc_detect2_convert = ab8500_gpadc_ad_to_voltage(gpadc,
Lee Jones73482342013-02-26 10:06:55 +00001868 ACC_DETECT2, acc_detect2_raw);
John Beckett1478a312011-05-31 13:54:27 +01001869
1870 return seq_printf(s, "%d,0x%X\n",
Lee Jones9f9ba152013-02-26 12:05:15 +00001871 acc_detect2_convert, acc_detect2_raw);
John Beckett1478a312011-05-31 13:54:27 +01001872}
1873
1874static int ab8500_gpadc_acc_detect2_open(struct inode *inode,
1875 struct file *file)
1876{
1877 return single_open(file, ab8500_gpadc_acc_detect2_print,
Lee Jones9f9ba152013-02-26 12:05:15 +00001878 inode->i_private);
John Beckett1478a312011-05-31 13:54:27 +01001879}
1880
1881static const struct file_operations ab8500_gpadc_acc_detect2_fops = {
1882 .open = ab8500_gpadc_acc_detect2_open,
1883 .read = seq_read,
1884 .llseek = seq_lseek,
1885 .release = single_release,
1886 .owner = THIS_MODULE,
1887};
1888
1889static int ab8500_gpadc_aux1_print(struct seq_file *s, void *p)
1890{
1891 int aux1_raw;
1892 int aux1_convert;
1893 struct ab8500_gpadc *gpadc;
1894
Philippe Langlais8908c042012-04-18 15:52:59 +02001895 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00001896 aux1_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX1,
1897 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01001898 aux1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX1,
Lee Jones73482342013-02-26 10:06:55 +00001899 aux1_raw);
John Beckett1478a312011-05-31 13:54:27 +01001900
1901 return seq_printf(s, "%d,0x%X\n",
Lee Jones9f9ba152013-02-26 12:05:15 +00001902 aux1_convert, aux1_raw);
John Beckett1478a312011-05-31 13:54:27 +01001903}
1904
1905static int ab8500_gpadc_aux1_open(struct inode *inode, struct file *file)
1906{
1907 return single_open(file, ab8500_gpadc_aux1_print, inode->i_private);
1908}
1909
1910static const struct file_operations ab8500_gpadc_aux1_fops = {
1911 .open = ab8500_gpadc_aux1_open,
1912 .read = seq_read,
1913 .llseek = seq_lseek,
1914 .release = single_release,
1915 .owner = THIS_MODULE,
1916};
1917
1918static int ab8500_gpadc_aux2_print(struct seq_file *s, void *p)
1919{
1920 int aux2_raw;
1921 int aux2_convert;
1922 struct ab8500_gpadc *gpadc;
1923
Philippe Langlais8908c042012-04-18 15:52:59 +02001924 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00001925 aux2_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX2,
1926 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01001927 aux2_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX2,
Lee Jones73482342013-02-26 10:06:55 +00001928 aux2_raw);
John Beckett1478a312011-05-31 13:54:27 +01001929
1930 return seq_printf(s, "%d,0x%X\n",
1931 aux2_convert, aux2_raw);
1932}
1933
1934static int ab8500_gpadc_aux2_open(struct inode *inode, struct file *file)
1935{
1936 return single_open(file, ab8500_gpadc_aux2_print, inode->i_private);
1937}
1938
1939static const struct file_operations ab8500_gpadc_aux2_fops = {
1940 .open = ab8500_gpadc_aux2_open,
1941 .read = seq_read,
1942 .llseek = seq_lseek,
1943 .release = single_release,
1944 .owner = THIS_MODULE,
1945};
1946
1947static int ab8500_gpadc_main_bat_v_print(struct seq_file *s, void *p)
1948{
1949 int main_bat_v_raw;
1950 int main_bat_v_convert;
1951 struct ab8500_gpadc *gpadc;
1952
Philippe Langlais8908c042012-04-18 15:52:59 +02001953 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00001954 main_bat_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_BAT_V,
1955 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01001956 main_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V,
Lee Jones73482342013-02-26 10:06:55 +00001957 main_bat_v_raw);
John Beckett1478a312011-05-31 13:54:27 +01001958
1959 return seq_printf(s, "%d,0x%X\n",
Lee Jones9f9ba152013-02-26 12:05:15 +00001960 main_bat_v_convert, main_bat_v_raw);
John Beckett1478a312011-05-31 13:54:27 +01001961}
1962
1963static int ab8500_gpadc_main_bat_v_open(struct inode *inode,
Lee Jones9f9ba152013-02-26 12:05:15 +00001964 struct file *file)
John Beckett1478a312011-05-31 13:54:27 +01001965{
1966 return single_open(file, ab8500_gpadc_main_bat_v_print, inode->i_private);
1967}
1968
1969static const struct file_operations ab8500_gpadc_main_bat_v_fops = {
1970 .open = ab8500_gpadc_main_bat_v_open,
1971 .read = seq_read,
1972 .llseek = seq_lseek,
1973 .release = single_release,
1974 .owner = THIS_MODULE,
1975};
1976
1977static int ab8500_gpadc_vbus_v_print(struct seq_file *s, void *p)
1978{
1979 int vbus_v_raw;
1980 int vbus_v_convert;
1981 struct ab8500_gpadc *gpadc;
1982
Philippe Langlais8908c042012-04-18 15:52:59 +02001983 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00001984 vbus_v_raw = ab8500_gpadc_read_raw(gpadc, VBUS_V,
1985 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01001986 vbus_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, VBUS_V,
Lee Jones73482342013-02-26 10:06:55 +00001987 vbus_v_raw);
John Beckett1478a312011-05-31 13:54:27 +01001988
1989 return seq_printf(s, "%d,0x%X\n",
Lee Jones9f9ba152013-02-26 12:05:15 +00001990 vbus_v_convert, vbus_v_raw);
John Beckett1478a312011-05-31 13:54:27 +01001991}
1992
1993static int ab8500_gpadc_vbus_v_open(struct inode *inode, struct file *file)
1994{
1995 return single_open(file, ab8500_gpadc_vbus_v_print, inode->i_private);
1996}
1997
1998static const struct file_operations ab8500_gpadc_vbus_v_fops = {
1999 .open = ab8500_gpadc_vbus_v_open,
2000 .read = seq_read,
2001 .llseek = seq_lseek,
2002 .release = single_release,
2003 .owner = THIS_MODULE,
2004};
2005
2006static int ab8500_gpadc_main_charger_c_print(struct seq_file *s, void *p)
2007{
2008 int main_charger_c_raw;
2009 int main_charger_c_convert;
2010 struct ab8500_gpadc *gpadc;
2011
Philippe Langlais8908c042012-04-18 15:52:59 +02002012 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00002013 main_charger_c_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_C,
2014 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01002015 main_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
Lee Jones73482342013-02-26 10:06:55 +00002016 MAIN_CHARGER_C, main_charger_c_raw);
John Beckett1478a312011-05-31 13:54:27 +01002017
2018 return seq_printf(s, "%d,0x%X\n",
Lee Jones9f9ba152013-02-26 12:05:15 +00002019 main_charger_c_convert, main_charger_c_raw);
John Beckett1478a312011-05-31 13:54:27 +01002020}
2021
2022static int ab8500_gpadc_main_charger_c_open(struct inode *inode,
2023 struct file *file)
2024{
2025 return single_open(file, ab8500_gpadc_main_charger_c_print,
Lee Jones9f9ba152013-02-26 12:05:15 +00002026 inode->i_private);
John Beckett1478a312011-05-31 13:54:27 +01002027}
2028
2029static const struct file_operations ab8500_gpadc_main_charger_c_fops = {
2030 .open = ab8500_gpadc_main_charger_c_open,
2031 .read = seq_read,
2032 .llseek = seq_lseek,
2033 .release = single_release,
2034 .owner = THIS_MODULE,
2035};
2036
2037static int ab8500_gpadc_usb_charger_c_print(struct seq_file *s, void *p)
2038{
2039 int usb_charger_c_raw;
2040 int usb_charger_c_convert;
2041 struct ab8500_gpadc *gpadc;
2042
Philippe Langlais8908c042012-04-18 15:52:59 +02002043 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00002044 usb_charger_c_raw = ab8500_gpadc_read_raw(gpadc, USB_CHARGER_C,
2045 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01002046 usb_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
Lee Jones73482342013-02-26 10:06:55 +00002047 USB_CHARGER_C, usb_charger_c_raw);
John Beckett1478a312011-05-31 13:54:27 +01002048
2049 return seq_printf(s, "%d,0x%X\n",
Lee Jones9f9ba152013-02-26 12:05:15 +00002050 usb_charger_c_convert, usb_charger_c_raw);
John Beckett1478a312011-05-31 13:54:27 +01002051}
2052
2053static int ab8500_gpadc_usb_charger_c_open(struct inode *inode,
2054 struct file *file)
2055{
2056 return single_open(file, ab8500_gpadc_usb_charger_c_print,
Lee Jones9f9ba152013-02-26 12:05:15 +00002057 inode->i_private);
John Beckett1478a312011-05-31 13:54:27 +01002058}
2059
2060static const struct file_operations ab8500_gpadc_usb_charger_c_fops = {
2061 .open = ab8500_gpadc_usb_charger_c_open,
2062 .read = seq_read,
2063 .llseek = seq_lseek,
2064 .release = single_release,
2065 .owner = THIS_MODULE,
2066};
2067
2068static int ab8500_gpadc_bk_bat_v_print(struct seq_file *s, void *p)
2069{
2070 int bk_bat_v_raw;
2071 int bk_bat_v_convert;
2072 struct ab8500_gpadc *gpadc;
2073
Philippe Langlais8908c042012-04-18 15:52:59 +02002074 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00002075 bk_bat_v_raw = ab8500_gpadc_read_raw(gpadc, BK_BAT_V,
2076 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01002077 bk_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
Lee Jones73482342013-02-26 10:06:55 +00002078 BK_BAT_V, bk_bat_v_raw);
John Beckett1478a312011-05-31 13:54:27 +01002079
2080 return seq_printf(s, "%d,0x%X\n",
Lee Jones9f9ba152013-02-26 12:05:15 +00002081 bk_bat_v_convert, bk_bat_v_raw);
John Beckett1478a312011-05-31 13:54:27 +01002082}
2083
2084static int ab8500_gpadc_bk_bat_v_open(struct inode *inode, struct file *file)
2085{
2086 return single_open(file, ab8500_gpadc_bk_bat_v_print, inode->i_private);
2087}
2088
2089static const struct file_operations ab8500_gpadc_bk_bat_v_fops = {
2090 .open = ab8500_gpadc_bk_bat_v_open,
2091 .read = seq_read,
2092 .llseek = seq_lseek,
2093 .release = single_release,
2094 .owner = THIS_MODULE,
2095};
2096
2097static int ab8500_gpadc_die_temp_print(struct seq_file *s, void *p)
2098{
2099 int die_temp_raw;
2100 int die_temp_convert;
2101 struct ab8500_gpadc *gpadc;
2102
Philippe Langlais8908c042012-04-18 15:52:59 +02002103 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00002104 die_temp_raw = ab8500_gpadc_read_raw(gpadc, DIE_TEMP,
2105 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01002106 die_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, DIE_TEMP,
Lee Jones73482342013-02-26 10:06:55 +00002107 die_temp_raw);
John Beckett1478a312011-05-31 13:54:27 +01002108
2109 return seq_printf(s, "%d,0x%X\n",
Lee Jones9f9ba152013-02-26 12:05:15 +00002110 die_temp_convert, die_temp_raw);
John Beckett1478a312011-05-31 13:54:27 +01002111}
2112
2113static int ab8500_gpadc_die_temp_open(struct inode *inode, struct file *file)
2114{
2115 return single_open(file, ab8500_gpadc_die_temp_print, inode->i_private);
2116}
2117
2118static const struct file_operations ab8500_gpadc_die_temp_fops = {
2119 .open = ab8500_gpadc_die_temp_open,
2120 .read = seq_read,
2121 .llseek = seq_lseek,
2122 .release = single_release,
2123 .owner = THIS_MODULE,
2124};
2125
Lee Jones127629d2013-02-26 14:04:37 +00002126static int ab8500_gpadc_usb_id_print(struct seq_file *s, void *p)
2127{
2128 int usb_id_raw;
2129 int usb_id_convert;
2130 struct ab8500_gpadc *gpadc;
2131
2132 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2133 usb_id_raw = ab8500_gpadc_read_raw(gpadc, USB_ID,
2134 avg_sample, trig_edge, trig_timer, conv_type);
2135 usb_id_convert = ab8500_gpadc_ad_to_voltage(gpadc, USB_ID,
2136 usb_id_raw);
2137
2138 return seq_printf(s, "%d,0x%X\n",
Lee Jones9f9ba152013-02-26 12:05:15 +00002139 usb_id_convert, usb_id_raw);
Lee Jones127629d2013-02-26 14:04:37 +00002140}
2141
2142static int ab8500_gpadc_usb_id_open(struct inode *inode, struct file *file)
2143{
2144 return single_open(file, ab8500_gpadc_usb_id_print, inode->i_private);
2145}
2146
2147static const struct file_operations ab8500_gpadc_usb_id_fops = {
2148 .open = ab8500_gpadc_usb_id_open,
2149 .read = seq_read,
2150 .llseek = seq_lseek,
2151 .release = single_release,
2152 .owner = THIS_MODULE,
2153};
2154
Lee Jonesbc6b4132013-02-26 14:02:31 +00002155static int ab8540_gpadc_xtal_temp_print(struct seq_file *s, void *p)
2156{
2157 int xtal_temp_raw;
2158 int xtal_temp_convert;
2159 struct ab8500_gpadc *gpadc;
2160
2161 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2162 xtal_temp_raw = ab8500_gpadc_read_raw(gpadc, XTAL_TEMP,
2163 avg_sample, trig_edge, trig_timer, conv_type);
2164 xtal_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, XTAL_TEMP,
2165 xtal_temp_raw);
2166
2167 return seq_printf(s, "%d,0x%X\n",
Lee Jones9f9ba152013-02-26 12:05:15 +00002168 xtal_temp_convert, xtal_temp_raw);
Lee Jonesbc6b4132013-02-26 14:02:31 +00002169}
2170
2171static int ab8540_gpadc_xtal_temp_open(struct inode *inode, struct file *file)
2172{
2173 return single_open(file, ab8540_gpadc_xtal_temp_print,
Lee Jones9f9ba152013-02-26 12:05:15 +00002174 inode->i_private);
Lee Jonesbc6b4132013-02-26 14:02:31 +00002175}
2176
2177static const struct file_operations ab8540_gpadc_xtal_temp_fops = {
2178 .open = ab8540_gpadc_xtal_temp_open,
2179 .read = seq_read,
2180 .llseek = seq_lseek,
2181 .release = single_release,
2182 .owner = THIS_MODULE,
2183};
2184
2185static int ab8540_gpadc_vbat_true_meas_print(struct seq_file *s, void *p)
2186{
2187 int vbat_true_meas_raw;
2188 int vbat_true_meas_convert;
2189 struct ab8500_gpadc *gpadc;
2190
2191 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2192 vbat_true_meas_raw = ab8500_gpadc_read_raw(gpadc, VBAT_TRUE_MEAS,
2193 avg_sample, trig_edge, trig_timer, conv_type);
2194 vbat_true_meas_convert = ab8500_gpadc_ad_to_voltage(gpadc, VBAT_TRUE_MEAS,
2195 vbat_true_meas_raw);
2196
2197 return seq_printf(s, "%d,0x%X\n",
Lee Jones9f9ba152013-02-26 12:05:15 +00002198 vbat_true_meas_convert, vbat_true_meas_raw);
Lee Jonesbc6b4132013-02-26 14:02:31 +00002199}
2200
2201static int ab8540_gpadc_vbat_true_meas_open(struct inode *inode,
2202 struct file *file)
2203{
2204 return single_open(file, ab8540_gpadc_vbat_true_meas_print,
Lee Jones9f9ba152013-02-26 12:05:15 +00002205 inode->i_private);
Lee Jonesbc6b4132013-02-26 14:02:31 +00002206}
2207
2208static const struct file_operations ab8540_gpadc_vbat_true_meas_fops = {
2209 .open = ab8540_gpadc_vbat_true_meas_open,
2210 .read = seq_read,
2211 .llseek = seq_lseek,
2212 .release = single_release,
2213 .owner = THIS_MODULE,
2214};
2215
2216static int ab8540_gpadc_bat_ctrl_and_ibat_print(struct seq_file *s, void *p)
2217{
2218 int bat_ctrl_raw;
2219 int bat_ctrl_convert;
2220 int ibat_raw;
2221 int ibat_convert;
2222 struct ab8500_gpadc *gpadc;
2223
2224 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2225 bat_ctrl_raw = ab8500_gpadc_double_read_raw(gpadc, BAT_CTRL_AND_IBAT,
2226 avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
2227
2228 bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc, BAT_CTRL,
2229 bat_ctrl_raw);
2230 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2231 ibat_raw);
2232
2233 return seq_printf(s, "%d,0x%X\n" "%d,0x%X\n",
Lee Jones9f9ba152013-02-26 12:05:15 +00002234 bat_ctrl_convert, bat_ctrl_raw,
2235 ibat_convert, ibat_raw);
Lee Jonesbc6b4132013-02-26 14:02:31 +00002236}
2237
2238static int ab8540_gpadc_bat_ctrl_and_ibat_open(struct inode *inode,
2239 struct file *file)
2240{
2241 return single_open(file, ab8540_gpadc_bat_ctrl_and_ibat_print,
Lee Jones9f9ba152013-02-26 12:05:15 +00002242 inode->i_private);
Lee Jonesbc6b4132013-02-26 14:02:31 +00002243}
2244
2245static const struct file_operations ab8540_gpadc_bat_ctrl_and_ibat_fops = {
2246 .open = ab8540_gpadc_bat_ctrl_and_ibat_open,
2247 .read = seq_read,
2248 .llseek = seq_lseek,
2249 .release = single_release,
2250 .owner = THIS_MODULE,
2251};
2252
2253static int ab8540_gpadc_vbat_meas_and_ibat_print(struct seq_file *s, void *p)
2254{
2255 int vbat_meas_raw;
2256 int vbat_meas_convert;
2257 int ibat_raw;
2258 int ibat_convert;
2259 struct ab8500_gpadc *gpadc;
2260
2261 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2262 vbat_meas_raw = ab8500_gpadc_double_read_raw(gpadc, VBAT_MEAS_AND_IBAT,
2263 avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
2264 vbat_meas_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V,
2265 vbat_meas_raw);
2266 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2267 ibat_raw);
2268
2269 return seq_printf(s, "%d,0x%X\n" "%d,0x%X\n",
Lee Jones9f9ba152013-02-26 12:05:15 +00002270 vbat_meas_convert, vbat_meas_raw,
2271 ibat_convert, ibat_raw);
Lee Jonesbc6b4132013-02-26 14:02:31 +00002272}
2273
2274static int ab8540_gpadc_vbat_meas_and_ibat_open(struct inode *inode,
2275 struct file *file)
2276{
2277 return single_open(file, ab8540_gpadc_vbat_meas_and_ibat_print,
Lee Jones9f9ba152013-02-26 12:05:15 +00002278 inode->i_private);
Lee Jonesbc6b4132013-02-26 14:02:31 +00002279}
2280
2281static const struct file_operations ab8540_gpadc_vbat_meas_and_ibat_fops = {
2282 .open = ab8540_gpadc_vbat_meas_and_ibat_open,
2283 .read = seq_read,
2284 .llseek = seq_lseek,
2285 .release = single_release,
2286 .owner = THIS_MODULE,
2287};
2288
2289static int ab8540_gpadc_vbat_true_meas_and_ibat_print(struct seq_file *s, void *p)
2290{
2291 int vbat_true_meas_raw;
2292 int vbat_true_meas_convert;
2293 int ibat_raw;
2294 int ibat_convert;
2295 struct ab8500_gpadc *gpadc;
2296
2297 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2298 vbat_true_meas_raw = ab8500_gpadc_double_read_raw(gpadc,
2299 VBAT_TRUE_MEAS_AND_IBAT, avg_sample, trig_edge,
2300 trig_timer, conv_type, &ibat_raw);
2301 vbat_true_meas_convert = ab8500_gpadc_ad_to_voltage(gpadc,
2302 VBAT_TRUE_MEAS, vbat_true_meas_raw);
2303 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2304 ibat_raw);
2305
2306 return seq_printf(s, "%d,0x%X\n" "%d,0x%X\n",
Lee Jones9f9ba152013-02-26 12:05:15 +00002307 vbat_true_meas_convert, vbat_true_meas_raw,
2308 ibat_convert, ibat_raw);
Lee Jonesbc6b4132013-02-26 14:02:31 +00002309}
2310
2311static int ab8540_gpadc_vbat_true_meas_and_ibat_open(struct inode *inode,
2312 struct file *file)
2313{
2314 return single_open(file, ab8540_gpadc_vbat_true_meas_and_ibat_print,
Lee Jones9f9ba152013-02-26 12:05:15 +00002315 inode->i_private);
Lee Jonesbc6b4132013-02-26 14:02:31 +00002316}
2317
2318static const struct file_operations ab8540_gpadc_vbat_true_meas_and_ibat_fops = {
2319 .open = ab8540_gpadc_vbat_true_meas_and_ibat_open,
2320 .read = seq_read,
2321 .llseek = seq_lseek,
2322 .release = single_release,
2323 .owner = THIS_MODULE,
2324};
2325
2326static int ab8540_gpadc_bat_temp_and_ibat_print(struct seq_file *s, void *p)
2327{
2328 int bat_temp_raw;
2329 int bat_temp_convert;
2330 int ibat_raw;
2331 int ibat_convert;
2332 struct ab8500_gpadc *gpadc;
2333
2334 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2335 bat_temp_raw = ab8500_gpadc_double_read_raw(gpadc, BAT_TEMP_AND_IBAT,
2336 avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
2337 bat_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL,
2338 bat_temp_raw);
2339 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2340 ibat_raw);
2341
2342 return seq_printf(s, "%d,0x%X\n" "%d,0x%X\n",
Lee Jones9f9ba152013-02-26 12:05:15 +00002343 bat_temp_convert, bat_temp_raw,
2344 ibat_convert, ibat_raw);
Lee Jonesbc6b4132013-02-26 14:02:31 +00002345}
2346
2347static int ab8540_gpadc_bat_temp_and_ibat_open(struct inode *inode,
2348 struct file *file)
2349{
2350 return single_open(file, ab8540_gpadc_bat_temp_and_ibat_print,
Lee Jones9f9ba152013-02-26 12:05:15 +00002351 inode->i_private);
Lee Jonesbc6b4132013-02-26 14:02:31 +00002352}
2353
2354static const struct file_operations ab8540_gpadc_bat_temp_and_ibat_fops = {
2355 .open = ab8540_gpadc_bat_temp_and_ibat_open,
2356 .read = seq_read,
2357 .llseek = seq_lseek,
2358 .release = single_release,
2359 .owner = THIS_MODULE,
2360};
2361
2362static int ab8540_gpadc_otp_cal_print(struct seq_file *s, void *p)
2363{
2364 struct ab8500_gpadc *gpadc;
2365 u16 vmain_l, vmain_h, btemp_l, btemp_h;
2366 u16 vbat_l, vbat_h, ibat_l, ibat_h;
2367
2368 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2369 ab8540_gpadc_get_otp(gpadc, &vmain_l, &vmain_h, &btemp_l, &btemp_h,
2370 &vbat_l, &vbat_h, &ibat_l, &ibat_h);
2371 return seq_printf(s, "VMAIN_L:0x%X\n"
Lee Jones9f9ba152013-02-26 12:05:15 +00002372 "VMAIN_H:0x%X\n"
2373 "BTEMP_L:0x%X\n"
2374 "BTEMP_H:0x%X\n"
2375 "VBAT_L:0x%X\n"
2376 "VBAT_H:0x%X\n"
2377 "IBAT_L:0x%X\n"
2378 "IBAT_H:0x%X\n",
2379 vmain_l, vmain_h, btemp_l, btemp_h, vbat_l, vbat_h, ibat_l, ibat_h);
Lee Jonesbc6b4132013-02-26 14:02:31 +00002380}
2381
2382static int ab8540_gpadc_otp_cal_open(struct inode *inode, struct file *file)
2383{
2384 return single_open(file, ab8540_gpadc_otp_cal_print, inode->i_private);
2385}
2386
2387static const struct file_operations ab8540_gpadc_otp_calib_fops = {
2388 .open = ab8540_gpadc_otp_cal_open,
2389 .read = seq_read,
2390 .llseek = seq_lseek,
2391 .release = single_release,
2392 .owner = THIS_MODULE,
2393};
2394
Lee Jones73482342013-02-26 10:06:55 +00002395static int ab8500_gpadc_avg_sample_print(struct seq_file *s, void *p)
2396{
2397 return seq_printf(s, "%d\n", avg_sample);
2398}
2399
2400static int ab8500_gpadc_avg_sample_open(struct inode *inode, struct file *file)
2401{
2402 return single_open(file, ab8500_gpadc_avg_sample_print,
Lee Jones9f9ba152013-02-26 12:05:15 +00002403 inode->i_private);
Lee Jones73482342013-02-26 10:06:55 +00002404}
2405
2406static ssize_t ab8500_gpadc_avg_sample_write(struct file *file,
2407 const char __user *user_buf,
2408 size_t count, loff_t *ppos)
2409{
2410 struct device *dev = ((struct seq_file *)(file->private_data))->private;
Lee Jones73482342013-02-26 10:06:55 +00002411 unsigned long user_avg_sample;
2412 int err;
2413
srinidhi kasagar7b830ae2012-11-23 15:11:00 +05302414 err = kstrtoul_from_user(user_buf, count, 0, &user_avg_sample);
Lee Jones73482342013-02-26 10:06:55 +00002415 if (err)
srinidhi kasagar7b830ae2012-11-23 15:11:00 +05302416 return err;
2417
Lee Jones73482342013-02-26 10:06:55 +00002418 if ((user_avg_sample == SAMPLE_1) || (user_avg_sample == SAMPLE_4)
2419 || (user_avg_sample == SAMPLE_8)
2420 || (user_avg_sample == SAMPLE_16)) {
2421 avg_sample = (u8) user_avg_sample;
2422 } else {
2423 dev_err(dev, "debugfs error input: "
2424 "should be egal to 1, 4, 8 or 16\n");
2425 return -EINVAL;
2426 }
srinidhi kasagar7b830ae2012-11-23 15:11:00 +05302427
2428 return count;
Lee Jones73482342013-02-26 10:06:55 +00002429}
2430
2431static const struct file_operations ab8500_gpadc_avg_sample_fops = {
2432 .open = ab8500_gpadc_avg_sample_open,
2433 .read = seq_read,
2434 .write = ab8500_gpadc_avg_sample_write,
2435 .llseek = seq_lseek,
2436 .release = single_release,
2437 .owner = THIS_MODULE,
2438};
2439
2440static int ab8500_gpadc_trig_edge_print(struct seq_file *s, void *p)
2441{
2442 return seq_printf(s, "%d\n", trig_edge);
2443}
2444
2445static int ab8500_gpadc_trig_edge_open(struct inode *inode, struct file *file)
2446{
2447 return single_open(file, ab8500_gpadc_trig_edge_print,
Lee Jones9f9ba152013-02-26 12:05:15 +00002448 inode->i_private);
Lee Jones73482342013-02-26 10:06:55 +00002449}
2450
2451static ssize_t ab8500_gpadc_trig_edge_write(struct file *file,
2452 const char __user *user_buf,
2453 size_t count, loff_t *ppos)
2454{
2455 struct device *dev = ((struct seq_file *)(file->private_data))->private;
Lee Jones73482342013-02-26 10:06:55 +00002456 unsigned long user_trig_edge;
2457 int err;
2458
srinidhi kasagar7b830ae2012-11-23 15:11:00 +05302459 err = kstrtoul_from_user(user_buf, count, 0, &user_trig_edge);
Lee Jones73482342013-02-26 10:06:55 +00002460 if (err)
srinidhi kasagar7b830ae2012-11-23 15:11:00 +05302461 return err;
2462
Lee Jones73482342013-02-26 10:06:55 +00002463 if ((user_trig_edge == RISING_EDGE)
2464 || (user_trig_edge == FALLING_EDGE)) {
2465 trig_edge = (u8) user_trig_edge;
2466 } else {
2467 dev_err(dev, "Wrong input:\n"
2468 "Enter 0. Rising edge\n"
2469 "Enter 1. Falling edge\n");
2470 return -EINVAL;
2471 }
srinidhi kasagar7b830ae2012-11-23 15:11:00 +05302472
2473 return count;
Lee Jones73482342013-02-26 10:06:55 +00002474}
2475
2476static const struct file_operations ab8500_gpadc_trig_edge_fops = {
2477 .open = ab8500_gpadc_trig_edge_open,
2478 .read = seq_read,
2479 .write = ab8500_gpadc_trig_edge_write,
2480 .llseek = seq_lseek,
2481 .release = single_release,
2482 .owner = THIS_MODULE,
2483};
2484
2485static int ab8500_gpadc_trig_timer_print(struct seq_file *s, void *p)
2486{
2487 return seq_printf(s, "%d\n", trig_timer);
2488}
2489
2490static int ab8500_gpadc_trig_timer_open(struct inode *inode, struct file *file)
2491{
2492 return single_open(file, ab8500_gpadc_trig_timer_print,
Lee Jones9f9ba152013-02-26 12:05:15 +00002493 inode->i_private);
Lee Jones73482342013-02-26 10:06:55 +00002494}
2495
2496static ssize_t ab8500_gpadc_trig_timer_write(struct file *file,
2497 const char __user *user_buf,
2498 size_t count, loff_t *ppos)
2499{
2500 struct device *dev = ((struct seq_file *)(file->private_data))->private;
Lee Jones73482342013-02-26 10:06:55 +00002501 unsigned long user_trig_timer;
2502 int err;
2503
srinidhi kasagar7b830ae2012-11-23 15:11:00 +05302504 err = kstrtoul_from_user(user_buf, count, 0, &user_trig_timer);
Lee Jones73482342013-02-26 10:06:55 +00002505 if (err)
srinidhi kasagar7b830ae2012-11-23 15:11:00 +05302506 return err;
2507
Lee Jones73482342013-02-26 10:06:55 +00002508 if ((user_trig_timer >= 0) && (user_trig_timer <= 255)) {
2509 trig_timer = (u8) user_trig_timer;
2510 } else {
2511 dev_err(dev, "debugfs error input: "
2512 "should be beetween 0 to 255\n");
2513 return -EINVAL;
2514 }
srinidhi kasagar7b830ae2012-11-23 15:11:00 +05302515
2516 return count;
Lee Jones73482342013-02-26 10:06:55 +00002517}
2518
2519static const struct file_operations ab8500_gpadc_trig_timer_fops = {
2520 .open = ab8500_gpadc_trig_timer_open,
2521 .read = seq_read,
2522 .write = ab8500_gpadc_trig_timer_write,
2523 .llseek = seq_lseek,
2524 .release = single_release,
2525 .owner = THIS_MODULE,
2526};
2527
2528static int ab8500_gpadc_conv_type_print(struct seq_file *s, void *p)
2529{
2530 return seq_printf(s, "%d\n", conv_type);
2531}
2532
2533static int ab8500_gpadc_conv_type_open(struct inode *inode, struct file *file)
2534{
2535 return single_open(file, ab8500_gpadc_conv_type_print,
Lee Jones9f9ba152013-02-26 12:05:15 +00002536 inode->i_private);
Lee Jones73482342013-02-26 10:06:55 +00002537}
2538
2539static ssize_t ab8500_gpadc_conv_type_write(struct file *file,
2540 const char __user *user_buf,
2541 size_t count, loff_t *ppos)
2542{
2543 struct device *dev = ((struct seq_file *)(file->private_data))->private;
Lee Jones73482342013-02-26 10:06:55 +00002544 unsigned long user_conv_type;
2545 int err;
2546
srinidhi kasagar7b830ae2012-11-23 15:11:00 +05302547 err = kstrtoul_from_user(user_buf, count, 0, &user_conv_type);
Lee Jones73482342013-02-26 10:06:55 +00002548 if (err)
srinidhi kasagar7b830ae2012-11-23 15:11:00 +05302549 return err;
2550
Lee Jones73482342013-02-26 10:06:55 +00002551 if ((user_conv_type == ADC_SW)
2552 || (user_conv_type == ADC_HW)) {
2553 conv_type = (u8) user_conv_type;
2554 } else {
2555 dev_err(dev, "Wrong input:\n"
2556 "Enter 0. ADC SW conversion\n"
2557 "Enter 1. ADC HW conversion\n");
2558 return -EINVAL;
2559 }
srinidhi kasagar7b830ae2012-11-23 15:11:00 +05302560
2561 return count;
Lee Jones73482342013-02-26 10:06:55 +00002562}
2563
2564static const struct file_operations ab8500_gpadc_conv_type_fops = {
2565 .open = ab8500_gpadc_conv_type_open,
2566 .read = seq_read,
2567 .write = ab8500_gpadc_conv_type_write,
2568 .llseek = seq_lseek,
2569 .release = single_release,
2570 .owner = THIS_MODULE,
2571};
2572
carriere etienne0fbce762011-04-08 16:26:36 +02002573/*
2574 * return length of an ASCII numerical value, 0 is string is not a
2575 * numerical value.
2576 * string shall start at value 1st char.
2577 * string can be tailed with \0 or space or newline chars only.
2578 * value can be decimal or hexadecimal (prefixed 0x or 0X).
2579 */
2580static int strval_len(char *b)
2581{
2582 char *s = b;
2583 if ((*s == '0') && ((*(s+1) == 'x') || (*(s+1) == 'X'))) {
2584 s += 2;
2585 for (; *s && (*s != ' ') && (*s != '\n'); s++) {
2586 if (!isxdigit(*s))
2587 return 0;
2588 }
2589 } else {
2590 if (*s == '-')
2591 s++;
2592 for (; *s && (*s != ' ') && (*s != '\n'); s++) {
2593 if (!isdigit(*s))
2594 return 0;
2595 }
2596 }
2597 return (int) (s-b);
2598}
2599
2600/*
2601 * parse hwreg input data.
2602 * update global hwreg_cfg only if input data syntax is ok.
2603 */
2604static ssize_t hwreg_common_write(char *b, struct hwreg_cfg *cfg,
2605 struct device *dev)
2606{
2607 uint write, val = 0;
2608 u8 regvalue;
2609 int ret;
2610 struct hwreg_cfg loc = {
2611 .bank = 0, /* default: invalid phys addr */
2612 .addr = 0, /* default: invalid phys addr */
2613 .fmt = 0, /* default: 32bit access, hex output */
2614 .mask = 0xFFFFFFFF, /* default: no mask */
2615 .shift = 0, /* default: no bit shift */
2616 };
2617
2618 /* read or write ? */
2619 if (!strncmp(b, "read ", 5)) {
2620 write = 0;
2621 b += 5;
2622 } else if (!strncmp(b, "write ", 6)) {
2623 write = 1;
2624 b += 6;
2625 } else
2626 return -EINVAL;
2627
2628 /* OPTIONS -l|-w|-b -s -m -o */
2629 while ((*b == ' ') || (*b == '-')) {
2630 if (*(b-1) != ' ') {
2631 b++;
2632 continue;
2633 }
2634 if ((!strncmp(b, "-d ", 3)) ||
2635 (!strncmp(b, "-dec ", 5))) {
2636 b += (*(b+2) == ' ') ? 3 : 5;
2637 loc.fmt |= (1<<0);
2638 } else if ((!strncmp(b, "-h ", 3)) ||
2639 (!strncmp(b, "-hex ", 5))) {
2640 b += (*(b+2) == ' ') ? 3 : 5;
2641 loc.fmt &= ~(1<<0);
2642 } else if ((!strncmp(b, "-m ", 3)) ||
2643 (!strncmp(b, "-mask ", 6))) {
2644 b += (*(b+2) == ' ') ? 3 : 6;
2645 if (strval_len(b) == 0)
2646 return -EINVAL;
2647 loc.mask = simple_strtoul(b, &b, 0);
2648 } else if ((!strncmp(b, "-s ", 3)) ||
2649 (!strncmp(b, "-shift ", 7))) {
2650 b += (*(b+2) == ' ') ? 3 : 7;
2651 if (strval_len(b) == 0)
2652 return -EINVAL;
2653 loc.shift = simple_strtol(b, &b, 0);
2654 } else {
2655 return -EINVAL;
2656 }
2657 }
2658 /* get arg BANK and ADDRESS */
2659 if (strval_len(b) == 0)
2660 return -EINVAL;
2661 loc.bank = simple_strtoul(b, &b, 0);
2662 while (*b == ' ')
2663 b++;
2664 if (strval_len(b) == 0)
2665 return -EINVAL;
2666 loc.addr = simple_strtoul(b, &b, 0);
2667
2668 if (write) {
2669 while (*b == ' ')
2670 b++;
2671 if (strval_len(b) == 0)
2672 return -EINVAL;
2673 val = simple_strtoul(b, &b, 0);
2674 }
2675
2676 /* args are ok, update target cfg (mainly for read) */
2677 *cfg = loc;
2678
2679#ifdef ABB_HWREG_DEBUG
2680 pr_warn("HWREG request: %s, %s, addr=0x%08X, mask=0x%X, shift=%d"
2681 "value=0x%X\n", (write) ? "write" : "read",
2682 REG_FMT_DEC(cfg) ? "decimal" : "hexa",
2683 cfg->addr, cfg->mask, cfg->shift, val);
2684#endif
2685
2686 if (!write)
2687 return 0;
2688
2689 ret = abx500_get_register_interruptible(dev,
2690 (u8)cfg->bank, (u8)cfg->addr, &regvalue);
2691 if (ret < 0) {
2692 dev_err(dev, "abx500_get_reg fail %d, %d\n",
2693 ret, __LINE__);
2694 return -EINVAL;
2695 }
2696
2697 if (cfg->shift >= 0) {
2698 regvalue &= ~(cfg->mask << (cfg->shift));
2699 val = (val & cfg->mask) << (cfg->shift);
2700 } else {
2701 regvalue &= ~(cfg->mask >> (-cfg->shift));
2702 val = (val & cfg->mask) >> (-cfg->shift);
2703 }
2704 val = val | regvalue;
2705
2706 ret = abx500_set_register_interruptible(dev,
2707 (u8)cfg->bank, (u8)cfg->addr, (u8)val);
2708 if (ret < 0) {
2709 pr_err("abx500_set_reg failed %d, %d", ret, __LINE__);
2710 return -EINVAL;
2711 }
2712
2713 return 0;
2714}
2715
2716static ssize_t ab8500_hwreg_write(struct file *file,
2717 const char __user *user_buf, size_t count, loff_t *ppos)
2718{
2719 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2720 char buf[128];
2721 int buf_size, ret;
2722
2723 /* Get userspace string and assure termination */
2724 buf_size = min(count, (sizeof(buf)-1));
2725 if (copy_from_user(buf, user_buf, buf_size))
2726 return -EFAULT;
2727 buf[buf_size] = 0;
2728
2729 /* get args and process */
2730 ret = hwreg_common_write(buf, &hwreg_cfg, dev);
2731 return (ret) ? ret : buf_size;
2732}
2733
2734/*
2735 * - irq subscribe/unsubscribe stuff
2736 */
Lee Jones4b8ac082013-01-14 16:10:36 +00002737static int ab8500_subscribe_unsubscribe_print(struct seq_file *s, void *p)
2738{
2739 seq_printf(s, "%d\n", irq_first);
2740
2741 return 0;
2742}
2743
2744static int ab8500_subscribe_unsubscribe_open(struct inode *inode,
2745 struct file *file)
2746{
2747 return single_open(file, ab8500_subscribe_unsubscribe_print,
Lee Jones9f9ba152013-02-26 12:05:15 +00002748 inode->i_private);
Lee Jones4b8ac082013-01-14 16:10:36 +00002749}
2750
2751/*
Mattias Wallin0b337e72010-11-19 17:55:11 +01002752 * Userspace should use poll() on this file. When an event occur
Lee Jones4b8ac082013-01-14 16:10:36 +00002753 * the blocking poll will be released.
2754 */
2755static ssize_t show_irq(struct device *dev,
2756 struct device_attribute *attr, char *buf)
2757{
Mattias Wallin0b337e72010-11-19 17:55:11 +01002758 unsigned long name;
2759 unsigned int irq_index;
2760 int err;
Lee Jones4b8ac082013-01-14 16:10:36 +00002761
Mattias Wallin0b337e72010-11-19 17:55:11 +01002762 err = strict_strtoul(attr->attr.name, 0, &name);
2763 if (err)
2764 return err;
2765
2766 irq_index = name - irq_first;
Linus Walleijddba25f2012-02-03 11:19:05 +01002767 if (irq_index >= num_irqs)
Mattias Wallin0b337e72010-11-19 17:55:11 +01002768 return -EINVAL;
2769 else
2770 return sprintf(buf, "%u\n", irq_count[irq_index]);
2771}
Lee Jones4b8ac082013-01-14 16:10:36 +00002772
2773static ssize_t ab8500_subscribe_write(struct file *file,
2774 const char __user *user_buf,
2775 size_t count, loff_t *ppos)
2776{
2777 struct device *dev = ((struct seq_file *)(file->private_data))->private;
Lee Jones4b8ac082013-01-14 16:10:36 +00002778 unsigned long user_val;
2779 int err;
Mattias Wallin0b337e72010-11-19 17:55:11 +01002780 unsigned int irq_index;
Lee Jones4b8ac082013-01-14 16:10:36 +00002781
srinidhi kasagar7b830ae2012-11-23 15:11:00 +05302782 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
Lee Jones4b8ac082013-01-14 16:10:36 +00002783 if (err)
srinidhi kasagar7b830ae2012-11-23 15:11:00 +05302784 return err;
2785
Lee Jones4b8ac082013-01-14 16:10:36 +00002786 if (user_val < irq_first) {
2787 dev_err(dev, "debugfs error input < %d\n", irq_first);
2788 return -EINVAL;
2789 }
2790 if (user_val > irq_last) {
2791 dev_err(dev, "debugfs error input > %d\n", irq_last);
2792 return -EINVAL;
2793 }
2794
Mattias Wallin0b337e72010-11-19 17:55:11 +01002795 irq_index = user_val - irq_first;
Linus Walleijddba25f2012-02-03 11:19:05 +01002796 if (irq_index >= num_irqs)
Mattias Wallin0b337e72010-11-19 17:55:11 +01002797 return -EINVAL;
2798
Lee Jones4b8ac082013-01-14 16:10:36 +00002799 /*
Mattias Wallin0b337e72010-11-19 17:55:11 +01002800 * This will create a sysfs file named <irq-nr> which userspace can
Lee Jones4b8ac082013-01-14 16:10:36 +00002801 * use to select or poll and get the AB8500 events
2802 */
Mattias Wallin0b337e72010-11-19 17:55:11 +01002803 dev_attr[irq_index] = kmalloc(sizeof(struct device_attribute),
2804 GFP_KERNEL);
srinidhi kasagar7b830ae2012-11-23 15:11:00 +05302805 event_name[irq_index] = kmalloc(count, GFP_KERNEL);
Mattias Wallin0b337e72010-11-19 17:55:11 +01002806 sprintf(event_name[irq_index], "%lu", user_val);
2807 dev_attr[irq_index]->show = show_irq;
2808 dev_attr[irq_index]->store = NULL;
2809 dev_attr[irq_index]->attr.name = event_name[irq_index];
2810 dev_attr[irq_index]->attr.mode = S_IRUGO;
2811 err = sysfs_create_file(&dev->kobj, &dev_attr[irq_index]->attr);
Lee Jones4b8ac082013-01-14 16:10:36 +00002812 if (err < 0) {
2813 printk(KERN_ERR "sysfs_create_file failed %d\n", err);
2814 return err;
2815 }
2816
2817 err = request_threaded_irq(user_val, NULL, ab8500_debug_handler,
2818 IRQF_SHARED | IRQF_NO_SUSPEND,
2819 "ab8500-debug", &dev->kobj);
2820 if (err < 0) {
2821 printk(KERN_ERR "request_threaded_irq failed %d, %lu\n",
2822 err, user_val);
Mattias Wallin0b337e72010-11-19 17:55:11 +01002823 sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr);
Lee Jones4b8ac082013-01-14 16:10:36 +00002824 return err;
2825 }
2826
srinidhi kasagar7b830ae2012-11-23 15:11:00 +05302827 return count;
Lee Jones4b8ac082013-01-14 16:10:36 +00002828}
2829
2830static ssize_t ab8500_unsubscribe_write(struct file *file,
2831 const char __user *user_buf,
2832 size_t count, loff_t *ppos)
2833{
2834 struct device *dev = ((struct seq_file *)(file->private_data))->private;
Lee Jones4b8ac082013-01-14 16:10:36 +00002835 unsigned long user_val;
2836 int err;
Mattias Wallin0b337e72010-11-19 17:55:11 +01002837 unsigned int irq_index;
Lee Jones4b8ac082013-01-14 16:10:36 +00002838
srinidhi kasagar7b830ae2012-11-23 15:11:00 +05302839 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
Lee Jones4b8ac082013-01-14 16:10:36 +00002840 if (err)
srinidhi kasagar7b830ae2012-11-23 15:11:00 +05302841 return err;
2842
Lee Jones4b8ac082013-01-14 16:10:36 +00002843 if (user_val < irq_first) {
2844 dev_err(dev, "debugfs error input < %d\n", irq_first);
2845 return -EINVAL;
2846 }
2847 if (user_val > irq_last) {
2848 dev_err(dev, "debugfs error input > %d\n", irq_last);
2849 return -EINVAL;
2850 }
2851
Mattias Wallin0b337e72010-11-19 17:55:11 +01002852 irq_index = user_val - irq_first;
Linus Walleijddba25f2012-02-03 11:19:05 +01002853 if (irq_index >= num_irqs)
Mattias Wallin0b337e72010-11-19 17:55:11 +01002854 return -EINVAL;
Lee Jones4b8ac082013-01-14 16:10:36 +00002855
Mattias Wallin0b337e72010-11-19 17:55:11 +01002856 /* Set irq count to 0 when unsubscribe */
2857 irq_count[irq_index] = 0;
2858
2859 if (dev_attr[irq_index])
2860 sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr);
2861
2862
2863 free_irq(user_val, &dev->kobj);
2864 kfree(event_name[irq_index]);
2865 kfree(dev_attr[irq_index]);
Lee Jones4b8ac082013-01-14 16:10:36 +00002866
srinidhi kasagar7b830ae2012-11-23 15:11:00 +05302867 return count;
Lee Jones4b8ac082013-01-14 16:10:36 +00002868}
2869
carriere etienne0fbce762011-04-08 16:26:36 +02002870/*
2871 * - several deubgfs nodes fops
2872 */
2873
Mattias Wallin5814fc32010-09-13 16:05:04 +02002874static const struct file_operations ab8500_bank_fops = {
Mattias Wallind7b9f322010-11-26 13:06:39 +01002875 .open = ab8500_bank_open,
2876 .write = ab8500_bank_write,
2877 .read = seq_read,
2878 .llseek = seq_lseek,
2879 .release = single_release,
2880 .owner = THIS_MODULE,
Mattias Wallin5814fc32010-09-13 16:05:04 +02002881};
2882
2883static const struct file_operations ab8500_address_fops = {
Mattias Wallind7b9f322010-11-26 13:06:39 +01002884 .open = ab8500_address_open,
2885 .write = ab8500_address_write,
2886 .read = seq_read,
2887 .llseek = seq_lseek,
2888 .release = single_release,
2889 .owner = THIS_MODULE,
Mattias Wallin5814fc32010-09-13 16:05:04 +02002890};
2891
2892static const struct file_operations ab8500_val_fops = {
Mattias Wallind7b9f322010-11-26 13:06:39 +01002893 .open = ab8500_val_open,
2894 .write = ab8500_val_write,
2895 .read = seq_read,
2896 .llseek = seq_lseek,
2897 .release = single_release,
2898 .owner = THIS_MODULE,
Mattias Wallin5814fc32010-09-13 16:05:04 +02002899};
2900
Bengt Jonsson8f0eb432012-02-14 13:01:00 +01002901static const struct file_operations ab8500_interrupts_fops = {
2902 .open = ab8500_interrupts_open,
2903 .read = seq_read,
2904 .llseek = seq_lseek,
2905 .release = single_release,
2906 .owner = THIS_MODULE,
2907};
2908
Lee Jones4b8ac082013-01-14 16:10:36 +00002909static const struct file_operations ab8500_subscribe_fops = {
2910 .open = ab8500_subscribe_unsubscribe_open,
2911 .write = ab8500_subscribe_write,
2912 .read = seq_read,
2913 .llseek = seq_lseek,
2914 .release = single_release,
2915 .owner = THIS_MODULE,
2916};
2917
2918static const struct file_operations ab8500_unsubscribe_fops = {
2919 .open = ab8500_subscribe_unsubscribe_open,
2920 .write = ab8500_unsubscribe_write,
2921 .read = seq_read,
2922 .llseek = seq_lseek,
2923 .release = single_release,
2924 .owner = THIS_MODULE,
2925};
2926
carriere etienne0fbce762011-04-08 16:26:36 +02002927static const struct file_operations ab8500_hwreg_fops = {
2928 .open = ab8500_hwreg_open,
2929 .write = ab8500_hwreg_write,
2930 .read = seq_read,
2931 .llseek = seq_lseek,
2932 .release = single_release,
2933 .owner = THIS_MODULE,
2934};
2935
Mattias Wallin5814fc32010-09-13 16:05:04 +02002936static struct dentry *ab8500_dir;
John Beckett1478a312011-05-31 13:54:27 +01002937static struct dentry *ab8500_gpadc_dir;
Mattias Wallin5814fc32010-09-13 16:05:04 +02002938
Bill Pembertonf791be42012-11-19 13:23:04 -05002939static int ab8500_debug_probe(struct platform_device *plf)
Mattias Wallin5814fc32010-09-13 16:05:04 +02002940{
carriere etienne0fbce762011-04-08 16:26:36 +02002941 struct dentry *file;
Linus Walleijddba25f2012-02-03 11:19:05 +01002942 int ret = -ENOMEM;
2943 struct ab8500 *ab8500;
Mattias Wallind7b9f322010-11-26 13:06:39 +01002944 debug_bank = AB8500_MISC;
2945 debug_address = AB8500_REV_REG & 0x00FF;
Mattias Wallin5814fc32010-09-13 16:05:04 +02002946
Linus Walleijddba25f2012-02-03 11:19:05 +01002947 ab8500 = dev_get_drvdata(plf->dev.parent);
2948 num_irqs = ab8500->mask_size;
2949
Ashok G70bad042012-02-28 10:21:00 +05302950 irq_count = kzalloc(sizeof(*irq_count)*num_irqs, GFP_KERNEL);
Linus Walleijddba25f2012-02-03 11:19:05 +01002951 if (!irq_count)
2952 return -ENOMEM;
2953
2954 dev_attr = kzalloc(sizeof(*dev_attr)*num_irqs,GFP_KERNEL);
2955 if (!dev_attr)
2956 goto out_freeirq_count;
2957
2958 event_name = kzalloc(sizeof(*event_name)*num_irqs, GFP_KERNEL);
2959 if (!event_name)
2960 goto out_freedev_attr;
2961
Lee Jones4b8ac082013-01-14 16:10:36 +00002962 irq_first = platform_get_irq_byname(plf, "IRQ_FIRST");
2963 if (irq_first < 0) {
2964 dev_err(&plf->dev, "First irq not found, err %d\n",
Lee Jones9f9ba152013-02-26 12:05:15 +00002965 irq_first);
Linus Walleijddba25f2012-02-03 11:19:05 +01002966 ret = irq_first;
2967 goto out_freeevent_name;
Lee Jones4b8ac082013-01-14 16:10:36 +00002968 }
2969
2970 irq_last = platform_get_irq_byname(plf, "IRQ_LAST");
2971 if (irq_last < 0) {
2972 dev_err(&plf->dev, "Last irq not found, err %d\n",
Lee Jones9f9ba152013-02-26 12:05:15 +00002973 irq_last);
Linus Walleijddba25f2012-02-03 11:19:05 +01002974 ret = irq_last;
Jonas Aaberg2cf64e22012-05-31 07:57:07 +02002975 goto out_freeevent_name;
Lee Jones4b8ac082013-01-14 16:10:36 +00002976 }
2977
Mattias Wallind7b9f322010-11-26 13:06:39 +01002978 ab8500_dir = debugfs_create_dir(AB8500_NAME_STRING, NULL);
2979 if (!ab8500_dir)
carriere etienne0fbce762011-04-08 16:26:36 +02002980 goto err;
Mattias Wallin5814fc32010-09-13 16:05:04 +02002981
John Beckett1478a312011-05-31 13:54:27 +01002982 ab8500_gpadc_dir = debugfs_create_dir(AB8500_ADC_NAME_STRING,
Lee Jones9f9ba152013-02-26 12:05:15 +00002983 ab8500_dir);
John Beckett1478a312011-05-31 13:54:27 +01002984 if (!ab8500_gpadc_dir)
2985 goto err;
2986
2987 file = debugfs_create_file("all-bank-registers", S_IRUGO,
Lee Jones9f9ba152013-02-26 12:05:15 +00002988 ab8500_dir, &plf->dev, &ab8500_registers_fops);
carriere etienne0fbce762011-04-08 16:26:36 +02002989 if (!file)
2990 goto err;
Mattias Wallin5814fc32010-09-13 16:05:04 +02002991
Mian Yousaf Kaukab42002c62012-01-26 15:39:20 +01002992 file = debugfs_create_file("all-banks", S_IRUGO,
Lee Jones9f9ba152013-02-26 12:05:15 +00002993 ab8500_dir, &plf->dev, &ab8500_all_banks_fops);
Mian Yousaf Kaukab42002c62012-01-26 15:39:20 +01002994 if (!file)
2995 goto err;
2996
Lee Jonesf38487f2013-02-26 14:09:08 +00002997 file = debugfs_create_file("register-bank", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones9f9ba152013-02-26 12:05:15 +00002998 ab8500_dir, &plf->dev, &ab8500_bank_fops);
carriere etienne0fbce762011-04-08 16:26:36 +02002999 if (!file)
3000 goto err;
Mattias Wallin5814fc32010-09-13 16:05:04 +02003001
Lee Jonesf38487f2013-02-26 14:09:08 +00003002 file = debugfs_create_file("register-address", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones9f9ba152013-02-26 12:05:15 +00003003 ab8500_dir, &plf->dev, &ab8500_address_fops);
carriere etienne0fbce762011-04-08 16:26:36 +02003004 if (!file)
3005 goto err;
Mattias Wallin5814fc32010-09-13 16:05:04 +02003006
Lee Jonesf38487f2013-02-26 14:09:08 +00003007 file = debugfs_create_file("register-value", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones9f9ba152013-02-26 12:05:15 +00003008 ab8500_dir, &plf->dev, &ab8500_val_fops);
carriere etienne0fbce762011-04-08 16:26:36 +02003009 if (!file)
3010 goto err;
Mattias Wallin5814fc32010-09-13 16:05:04 +02003011
Lee Jonesf38487f2013-02-26 14:09:08 +00003012 file = debugfs_create_file("irq-subscribe", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones9f9ba152013-02-26 12:05:15 +00003013 ab8500_dir, &plf->dev, &ab8500_subscribe_fops);
carriere etienne0fbce762011-04-08 16:26:36 +02003014 if (!file)
3015 goto err;
Lee Jones4b8ac082013-01-14 16:10:36 +00003016
Lee Jones9581ae32012-07-06 16:11:50 +02003017 if (is_ab8500(ab8500)) {
3018 debug_ranges = ab8500_debug_ranges;
Bengt Jonsson8f0eb432012-02-14 13:01:00 +01003019 num_interrupt_lines = AB8500_NR_IRQS;
Lee Jones9581ae32012-07-06 16:11:50 +02003020 } else if (is_ab8505(ab8500)) {
3021 debug_ranges = ab8505_debug_ranges;
Bengt Jonsson8f0eb432012-02-14 13:01:00 +01003022 num_interrupt_lines = AB8505_NR_IRQS;
Lee Jones9581ae32012-07-06 16:11:50 +02003023 } else if (is_ab9540(ab8500)) {
3024 debug_ranges = ab8505_debug_ranges;
Bengt Jonsson8f0eb432012-02-14 13:01:00 +01003025 num_interrupt_lines = AB9540_NR_IRQS;
Lee Jones9581ae32012-07-06 16:11:50 +02003026 } else if (is_ab8540(ab8500)) {
Lee Jones971480f2012-11-19 12:20:03 +01003027 debug_ranges = ab8540_debug_ranges;
Lee Jonese436ddf2013-02-26 10:09:41 +00003028 num_interrupt_lines = AB8540_NR_IRQS;
Lee Jones9581ae32012-07-06 16:11:50 +02003029 }
Bengt Jonsson8f0eb432012-02-14 13:01:00 +01003030
3031 file = debugfs_create_file("interrupts", (S_IRUGO),
Lee Jones9f9ba152013-02-26 12:05:15 +00003032 ab8500_dir, &plf->dev, &ab8500_interrupts_fops);
Bengt Jonsson8f0eb432012-02-14 13:01:00 +01003033 if (!file)
3034 goto err;
3035
Lee Jonesf38487f2013-02-26 14:09:08 +00003036 file = debugfs_create_file("irq-unsubscribe", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones9f9ba152013-02-26 12:05:15 +00003037 ab8500_dir, &plf->dev, &ab8500_unsubscribe_fops);
carriere etienne0fbce762011-04-08 16:26:36 +02003038 if (!file)
3039 goto err;
3040
Lee Jonesf38487f2013-02-26 14:09:08 +00003041 file = debugfs_create_file("hwreg", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones9f9ba152013-02-26 12:05:15 +00003042 ab8500_dir, &plf->dev, &ab8500_hwreg_fops);
John Beckett1478a312011-05-31 13:54:27 +01003043 if (!file)
3044 goto err;
3045
Lee Jonesf38487f2013-02-26 14:09:08 +00003046 file = debugfs_create_file("all-modem-registers", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jonesc7ebaee2013-02-26 14:03:33 +00003047 ab8500_dir, &plf->dev, &ab8500_modem_fops);
3048 if (!file)
3049 goto err;
3050
Lee Jonesf38487f2013-02-26 14:09:08 +00003051 file = debugfs_create_file("bat_ctrl", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones9f9ba152013-02-26 12:05:15 +00003052 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_bat_ctrl_fops);
John Beckett1478a312011-05-31 13:54:27 +01003053 if (!file)
3054 goto err;
3055
Lee Jonesf38487f2013-02-26 14:09:08 +00003056 file = debugfs_create_file("btemp_ball", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones9f9ba152013-02-26 12:05:15 +00003057 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_btemp_ball_fops);
John Beckett1478a312011-05-31 13:54:27 +01003058 if (!file)
3059 goto err;
3060
Lee Jonesf38487f2013-02-26 14:09:08 +00003061 file = debugfs_create_file("main_charger_v", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones9f9ba152013-02-26 12:05:15 +00003062 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_charger_v_fops);
John Beckett1478a312011-05-31 13:54:27 +01003063 if (!file)
3064 goto err;
3065
Lee Jonesf38487f2013-02-26 14:09:08 +00003066 file = debugfs_create_file("acc_detect1", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones9f9ba152013-02-26 12:05:15 +00003067 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_acc_detect1_fops);
John Beckett1478a312011-05-31 13:54:27 +01003068 if (!file)
3069 goto err;
3070
Lee Jonesf38487f2013-02-26 14:09:08 +00003071 file = debugfs_create_file("acc_detect2", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones9f9ba152013-02-26 12:05:15 +00003072 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_acc_detect2_fops);
John Beckett1478a312011-05-31 13:54:27 +01003073 if (!file)
3074 goto err;
3075
Lee Jonesf38487f2013-02-26 14:09:08 +00003076 file = debugfs_create_file("adc_aux1", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones9f9ba152013-02-26 12:05:15 +00003077 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_aux1_fops);
John Beckett1478a312011-05-31 13:54:27 +01003078 if (!file)
3079 goto err;
3080
Lee Jonesf38487f2013-02-26 14:09:08 +00003081 file = debugfs_create_file("adc_aux2", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones9f9ba152013-02-26 12:05:15 +00003082 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_aux2_fops);
John Beckett1478a312011-05-31 13:54:27 +01003083 if (!file)
3084 goto err;
3085
Lee Jonesf38487f2013-02-26 14:09:08 +00003086 file = debugfs_create_file("main_bat_v", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones9f9ba152013-02-26 12:05:15 +00003087 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_bat_v_fops);
John Beckett1478a312011-05-31 13:54:27 +01003088 if (!file)
3089 goto err;
3090
Lee Jonesf38487f2013-02-26 14:09:08 +00003091 file = debugfs_create_file("vbus_v", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones9f9ba152013-02-26 12:05:15 +00003092 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_vbus_v_fops);
John Beckett1478a312011-05-31 13:54:27 +01003093 if (!file)
3094 goto err;
3095
Lee Jonesf38487f2013-02-26 14:09:08 +00003096 file = debugfs_create_file("main_charger_c", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones9f9ba152013-02-26 12:05:15 +00003097 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_charger_c_fops);
John Beckett1478a312011-05-31 13:54:27 +01003098 if (!file)
3099 goto err;
3100
Lee Jonesf38487f2013-02-26 14:09:08 +00003101 file = debugfs_create_file("usb_charger_c", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones9f9ba152013-02-26 12:05:15 +00003102 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_usb_charger_c_fops);
John Beckett1478a312011-05-31 13:54:27 +01003103 if (!file)
3104 goto err;
3105
Lee Jonesf38487f2013-02-26 14:09:08 +00003106 file = debugfs_create_file("bk_bat_v", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones9f9ba152013-02-26 12:05:15 +00003107 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_bk_bat_v_fops);
John Beckett1478a312011-05-31 13:54:27 +01003108 if (!file)
3109 goto err;
3110
Lee Jonesf38487f2013-02-26 14:09:08 +00003111 file = debugfs_create_file("die_temp", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones9f9ba152013-02-26 12:05:15 +00003112 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_die_temp_fops);
carriere etienne0fbce762011-04-08 16:26:36 +02003113 if (!file)
3114 goto err;
Lee Jones127629d2013-02-26 14:04:37 +00003115
Lee Jonesf38487f2013-02-26 14:09:08 +00003116 file = debugfs_create_file("usb_id", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones127629d2013-02-26 14:04:37 +00003117 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_usb_id_fops);
3118 if (!file)
3119 goto err;
3120
Lee Jonesbc6b4132013-02-26 14:02:31 +00003121 if (is_ab8540(ab8500)) {
Lee Jonesf38487f2013-02-26 14:09:08 +00003122 file = debugfs_create_file("xtal_temp", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jonesbc6b4132013-02-26 14:02:31 +00003123 ab8500_gpadc_dir, &plf->dev, &ab8540_gpadc_xtal_temp_fops);
3124 if (!file)
3125 goto err;
Lee Jonesf38487f2013-02-26 14:09:08 +00003126 file = debugfs_create_file("vbattruemeas", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jonesbc6b4132013-02-26 14:02:31 +00003127 ab8500_gpadc_dir, &plf->dev,
3128 &ab8540_gpadc_vbat_true_meas_fops);
3129 if (!file)
3130 goto err;
3131 file = debugfs_create_file("batctrl_and_ibat",
Lee Jones9f9ba152013-02-26 12:05:15 +00003132 (S_IRUGO | S_IWUGO), ab8500_gpadc_dir,
3133 &plf->dev, &ab8540_gpadc_bat_ctrl_and_ibat_fops);
Lee Jonesbc6b4132013-02-26 14:02:31 +00003134 if (!file)
3135 goto err;
3136 file = debugfs_create_file("vbatmeas_and_ibat",
Lee Jones9f9ba152013-02-26 12:05:15 +00003137 (S_IRUGO | S_IWUGO), ab8500_gpadc_dir,
3138 &plf->dev,
3139 &ab8540_gpadc_vbat_meas_and_ibat_fops);
Lee Jonesbc6b4132013-02-26 14:02:31 +00003140 if (!file)
3141 goto err;
3142 file = debugfs_create_file("vbattruemeas_and_ibat",
Lee Jones9f9ba152013-02-26 12:05:15 +00003143 (S_IRUGO | S_IWUGO), ab8500_gpadc_dir,
3144 &plf->dev,
3145 &ab8540_gpadc_vbat_true_meas_and_ibat_fops);
Lee Jonesbc6b4132013-02-26 14:02:31 +00003146 if (!file)
3147 goto err;
3148 file = debugfs_create_file("battemp_and_ibat",
Lee Jones9f9ba152013-02-26 12:05:15 +00003149 (S_IRUGO | S_IWUGO), ab8500_gpadc_dir,
3150 &plf->dev, &ab8540_gpadc_bat_temp_and_ibat_fops);
Lee Jonesbc6b4132013-02-26 14:02:31 +00003151 if (!file)
3152 goto err;
Lee Jonesf38487f2013-02-26 14:09:08 +00003153 file = debugfs_create_file("otp_calib", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jonesbc6b4132013-02-26 14:02:31 +00003154 ab8500_gpadc_dir, &plf->dev, &ab8540_gpadc_otp_calib_fops);
3155 if (!file)
3156 goto err;
3157 }
Lee Jonesf38487f2013-02-26 14:09:08 +00003158 file = debugfs_create_file("avg_sample", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones73482342013-02-26 10:06:55 +00003159 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_avg_sample_fops);
3160 if (!file)
3161 goto err;
3162
Lee Jonesf38487f2013-02-26 14:09:08 +00003163 file = debugfs_create_file("trig_edge", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones73482342013-02-26 10:06:55 +00003164 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_trig_edge_fops);
3165 if (!file)
3166 goto err;
3167
Lee Jonesf38487f2013-02-26 14:09:08 +00003168 file = debugfs_create_file("trig_timer", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones73482342013-02-26 10:06:55 +00003169 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_trig_timer_fops);
3170 if (!file)
3171 goto err;
3172
Lee Jonesf38487f2013-02-26 14:09:08 +00003173 file = debugfs_create_file("conv_type", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones73482342013-02-26 10:06:55 +00003174 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_conv_type_fops);
3175 if (!file)
3176 goto err;
3177
Mattias Wallind7b9f322010-11-26 13:06:39 +01003178 return 0;
Mattias Wallin5814fc32010-09-13 16:05:04 +02003179
carriere etienne0fbce762011-04-08 16:26:36 +02003180err:
3181 if (ab8500_dir)
3182 debugfs_remove_recursive(ab8500_dir);
Mattias Wallind7b9f322010-11-26 13:06:39 +01003183 dev_err(&plf->dev, "failed to create debugfs entries.\n");
Linus Walleijddba25f2012-02-03 11:19:05 +01003184out_freeevent_name:
3185 kfree(event_name);
3186out_freedev_attr:
3187 kfree(dev_attr);
3188out_freeirq_count:
3189 kfree(irq_count);
3190
3191 return ret;
Mattias Wallin5814fc32010-09-13 16:05:04 +02003192}
3193
Bill Pemberton4740f732012-11-19 13:26:01 -05003194static int ab8500_debug_remove(struct platform_device *plf)
Mattias Wallin5814fc32010-09-13 16:05:04 +02003195{
carriere etienne0fbce762011-04-08 16:26:36 +02003196 debugfs_remove_recursive(ab8500_dir);
Linus Walleijddba25f2012-02-03 11:19:05 +01003197 kfree(event_name);
3198 kfree(dev_attr);
3199 kfree(irq_count);
3200
Mattias Wallind7b9f322010-11-26 13:06:39 +01003201 return 0;
Mattias Wallin5814fc32010-09-13 16:05:04 +02003202}
3203
3204static struct platform_driver ab8500_debug_driver = {
Mattias Wallind7b9f322010-11-26 13:06:39 +01003205 .driver = {
3206 .name = "ab8500-debug",
3207 .owner = THIS_MODULE,
3208 },
3209 .probe = ab8500_debug_probe,
Bill Pemberton84449212012-11-19 13:20:24 -05003210 .remove = ab8500_debug_remove
Mattias Wallin5814fc32010-09-13 16:05:04 +02003211};
3212
3213static int __init ab8500_debug_init(void)
3214{
Mattias Wallind7b9f322010-11-26 13:06:39 +01003215 return platform_driver_register(&ab8500_debug_driver);
Mattias Wallin5814fc32010-09-13 16:05:04 +02003216}
3217
3218static void __exit ab8500_debug_exit(void)
3219{
Mattias Wallind7b9f322010-11-26 13:06:39 +01003220 platform_driver_unregister(&ab8500_debug_driver);
Mattias Wallin5814fc32010-09-13 16:05:04 +02003221}
3222subsys_initcall(ab8500_debug_init);
3223module_exit(ab8500_debug_exit);
3224
3225MODULE_AUTHOR("Mattias WALLIN <mattias.wallin@stericsson.com");
3226MODULE_DESCRIPTION("AB8500 DEBUG");
3227MODULE_LICENSE("GPL v2");