blob: 810ac6faabba6904190002e8d2d35eaf23452ac0 [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
Mattias Wallind7b9f322010-11-26 13:06:39 +01001482 /* Get userspace string and assure termination */
Peter Huewe8504d632011-06-06 22:43:32 +02001483 err = kstrtoul_from_user(user_buf, count, 0, &user_bank);
Mattias Wallind7b9f322010-11-26 13:06:39 +01001484 if (err)
Peter Huewe8504d632011-06-06 22:43:32 +02001485 return err;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001486
Mattias Wallind7b9f322010-11-26 13:06:39 +01001487 if (user_bank >= AB8500_NUM_BANKS) {
1488 dev_err(dev, "debugfs error input > number of banks\n");
1489 return -EINVAL;
1490 }
Mattias Wallin5814fc32010-09-13 16:05:04 +02001491
Mattias Wallind7b9f322010-11-26 13:06:39 +01001492 debug_bank = user_bank;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001493
Peter Huewe8504d632011-06-06 22:43:32 +02001494 return count;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001495}
1496
1497static int ab8500_address_print(struct seq_file *s, void *p)
1498{
Mattias Wallind7b9f322010-11-26 13:06:39 +01001499 return seq_printf(s, "0x%02X\n", debug_address);
Mattias Wallin5814fc32010-09-13 16:05:04 +02001500}
1501
1502static int ab8500_address_open(struct inode *inode, struct file *file)
1503{
Mattias Wallind7b9f322010-11-26 13:06:39 +01001504 return single_open(file, ab8500_address_print, inode->i_private);
Mattias Wallin5814fc32010-09-13 16:05:04 +02001505}
1506
1507static ssize_t ab8500_address_write(struct file *file,
Mattias Wallind7b9f322010-11-26 13:06:39 +01001508 const char __user *user_buf,
1509 size_t count, loff_t *ppos)
Mattias Wallin5814fc32010-09-13 16:05:04 +02001510{
Mattias Wallind7b9f322010-11-26 13:06:39 +01001511 struct device *dev = ((struct seq_file *)(file->private_data))->private;
Mattias Wallind7b9f322010-11-26 13:06:39 +01001512 unsigned long user_address;
1513 int err;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001514
Mattias Wallind7b9f322010-11-26 13:06:39 +01001515 /* Get userspace string and assure termination */
Peter Huewe8504d632011-06-06 22:43:32 +02001516 err = kstrtoul_from_user(user_buf, count, 0, &user_address);
Mattias Wallind7b9f322010-11-26 13:06:39 +01001517 if (err)
Peter Huewe8504d632011-06-06 22:43:32 +02001518 return err;
1519
Mattias Wallind7b9f322010-11-26 13:06:39 +01001520 if (user_address > 0xff) {
1521 dev_err(dev, "debugfs error input > 0xff\n");
1522 return -EINVAL;
1523 }
1524 debug_address = user_address;
Peter Huewe8504d632011-06-06 22:43:32 +02001525 return count;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001526}
1527
1528static int ab8500_val_print(struct seq_file *s, void *p)
1529{
Mattias Wallind7b9f322010-11-26 13:06:39 +01001530 struct device *dev = s->private;
1531 int ret;
1532 u8 regvalue;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001533
Mattias Wallind7b9f322010-11-26 13:06:39 +01001534 ret = abx500_get_register_interruptible(dev,
1535 (u8)debug_bank, (u8)debug_address, &regvalue);
1536 if (ret < 0) {
1537 dev_err(dev, "abx500_get_reg fail %d, %d\n",
1538 ret, __LINE__);
1539 return -EINVAL;
1540 }
1541 seq_printf(s, "0x%02X\n", regvalue);
Mattias Wallin5814fc32010-09-13 16:05:04 +02001542
Mattias Wallind7b9f322010-11-26 13:06:39 +01001543 return 0;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001544}
1545
1546static int ab8500_val_open(struct inode *inode, struct file *file)
1547{
Mattias Wallind7b9f322010-11-26 13:06:39 +01001548 return single_open(file, ab8500_val_print, inode->i_private);
Mattias Wallin5814fc32010-09-13 16:05:04 +02001549}
1550
1551static ssize_t ab8500_val_write(struct file *file,
Mattias Wallind7b9f322010-11-26 13:06:39 +01001552 const char __user *user_buf,
1553 size_t count, loff_t *ppos)
Mattias Wallin5814fc32010-09-13 16:05:04 +02001554{
Mattias Wallind7b9f322010-11-26 13:06:39 +01001555 struct device *dev = ((struct seq_file *)(file->private_data))->private;
Mattias Wallind7b9f322010-11-26 13:06:39 +01001556 unsigned long user_val;
1557 int err;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001558
Mattias Wallind7b9f322010-11-26 13:06:39 +01001559 /* Get userspace string and assure termination */
Peter Huewe8504d632011-06-06 22:43:32 +02001560 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
Mattias Wallind7b9f322010-11-26 13:06:39 +01001561 if (err)
Peter Huewe8504d632011-06-06 22:43:32 +02001562 return err;
1563
Mattias Wallind7b9f322010-11-26 13:06:39 +01001564 if (user_val > 0xff) {
1565 dev_err(dev, "debugfs error input > 0xff\n");
1566 return -EINVAL;
1567 }
1568 err = abx500_set_register_interruptible(dev,
1569 (u8)debug_bank, debug_address, (u8)user_val);
1570 if (err < 0) {
1571 printk(KERN_ERR "abx500_set_reg failed %d, %d", err, __LINE__);
1572 return -EINVAL;
1573 }
Mattias Wallin5814fc32010-09-13 16:05:04 +02001574
Peter Huewe8504d632011-06-06 22:43:32 +02001575 return count;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001576}
1577
carriere etienne0fbce762011-04-08 16:26:36 +02001578/*
Bengt Jonsson8f0eb432012-02-14 13:01:00 +01001579 * Interrupt status
1580 */
1581static u32 num_interrupts[AB8500_MAX_NR_IRQS];
Jonas Aaberg2cf64e22012-05-31 07:57:07 +02001582static u32 num_wake_interrupts[AB8500_MAX_NR_IRQS];
Bengt Jonsson8f0eb432012-02-14 13:01:00 +01001583static int num_interrupt_lines;
1584
Jonas Aaberg2cf64e22012-05-31 07:57:07 +02001585bool __attribute__((weak)) suspend_test_wake_cause_interrupt_is_mine(u32 my_int)
1586{
1587 return false;
1588}
1589
Bengt Jonsson8f0eb432012-02-14 13:01:00 +01001590void ab8500_debug_register_interrupt(int line)
1591{
Jonas Aaberg2cf64e22012-05-31 07:57:07 +02001592 if (line < num_interrupt_lines) {
Bengt Jonsson8f0eb432012-02-14 13:01:00 +01001593 num_interrupts[line]++;
Jonas Aaberg2cf64e22012-05-31 07:57:07 +02001594 if (suspend_test_wake_cause_interrupt_is_mine(IRQ_DB8500_AB8500))
1595 num_wake_interrupts[line]++;
1596 }
Bengt Jonsson8f0eb432012-02-14 13:01:00 +01001597}
1598
1599static int ab8500_interrupts_print(struct seq_file *s, void *p)
1600{
1601 int line;
1602
Jonas Aaberg2cf64e22012-05-31 07:57:07 +02001603 seq_printf(s, "name: number: number of: wake:\n");
Bengt Jonsson8f0eb432012-02-14 13:01:00 +01001604
Jonas Aaberg2cf64e22012-05-31 07:57:07 +02001605 for (line = 0; line < num_interrupt_lines; line++) {
1606 struct irq_desc *desc = irq_to_desc(line + irq_first);
1607 struct irqaction *action = desc->action;
1608
1609 seq_printf(s, "%3i: %6i %4i", line,
1610 num_interrupts[line],
1611 num_wake_interrupts[line]);
1612
1613 if (desc && desc->name)
1614 seq_printf(s, "-%-8s", desc->name);
1615 if (action) {
1616 seq_printf(s, " %s", action->name);
1617 while ((action = action->next) != NULL)
1618 seq_printf(s, ", %s", action->name);
1619 }
1620 seq_putc(s, '\n');
1621 }
Bengt Jonsson8f0eb432012-02-14 13:01:00 +01001622
1623 return 0;
1624}
1625
1626static int ab8500_interrupts_open(struct inode *inode, struct file *file)
1627{
1628 return single_open(file, ab8500_interrupts_print, inode->i_private);
1629}
1630
1631/*
carriere etienne0fbce762011-04-08 16:26:36 +02001632 * - HWREG DB8500 formated routines
1633 */
1634static int ab8500_hwreg_print(struct seq_file *s, void *d)
1635{
1636 struct device *dev = s->private;
1637 int ret;
1638 u8 regvalue;
1639
1640 ret = abx500_get_register_interruptible(dev,
1641 (u8)hwreg_cfg.bank, (u8)hwreg_cfg.addr, &regvalue);
1642 if (ret < 0) {
1643 dev_err(dev, "abx500_get_reg fail %d, %d\n",
1644 ret, __LINE__);
1645 return -EINVAL;
1646 }
1647
1648 if (hwreg_cfg.shift >= 0)
1649 regvalue >>= hwreg_cfg.shift;
1650 else
1651 regvalue <<= -hwreg_cfg.shift;
1652 regvalue &= hwreg_cfg.mask;
1653
1654 if (REG_FMT_DEC(&hwreg_cfg))
1655 seq_printf(s, "%d\n", regvalue);
1656 else
1657 seq_printf(s, "0x%02X\n", regvalue);
1658 return 0;
1659}
1660
1661static int ab8500_hwreg_open(struct inode *inode, struct file *file)
1662{
1663 return single_open(file, ab8500_hwreg_print, inode->i_private);
1664}
1665
Lee Jonesc7ebaee2013-02-26 14:03:33 +00001666#define AB8500_SUPPLY_CONTROL_CONFIG_1 0x01
1667#define AB8500_SUPPLY_CONTROL_REG 0x00
1668#define AB8500_FIRST_SIM_REG 0x80
1669#define AB8500_LAST_SIM_REG 0x8B
1670#define AB8505_LAST_SIM_REG 0x8C
1671
1672static int ab8500_print_modem_registers(struct seq_file *s, void *p)
1673{
1674 struct device *dev = s->private;
1675 struct ab8500 *ab8500;
1676 int err;
1677 u8 value;
1678 u8 orig_value;
1679 u32 bank = AB8500_REGU_CTRL2;
1680 u32 last_sim_reg = AB8500_LAST_SIM_REG;
1681 u32 reg;
1682
1683 ab8500 = dev_get_drvdata(dev->parent);
1684 dev_warn(dev, "WARNING! This operation can interfer with modem side\n"
1685 "and should only be done with care\n");
1686
1687 err = abx500_get_register_interruptible(dev,
1688 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG, &orig_value);
1689 if (err < 0) {
1690 dev_err(dev, "ab->read fail %d\n", err);
1691 return err;
1692 }
1693 /* Config 1 will allow APE side to read SIM registers */
1694 err = abx500_set_register_interruptible(dev,
1695 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG,
1696 AB8500_SUPPLY_CONTROL_CONFIG_1);
1697 if (err < 0) {
1698 dev_err(dev, "ab->write fail %d\n", err);
1699 return err;
1700 }
1701
1702 seq_printf(s, " bank 0x%02X:\n", bank);
1703
1704 if (is_ab9540(ab8500) || is_ab8505(ab8500))
1705 last_sim_reg = AB8505_LAST_SIM_REG;
1706
1707 for (reg = AB8500_FIRST_SIM_REG; reg <= last_sim_reg; reg++) {
1708 err = abx500_get_register_interruptible(dev,
1709 bank, reg, &value);
1710 if (err < 0) {
1711 dev_err(dev, "ab->read fail %d\n", err);
1712 return err;
1713 }
1714 err = seq_printf(s, " [0x%02X/0x%02X]: 0x%02X\n",
1715 bank, reg, value);
1716 }
1717 err = abx500_set_register_interruptible(dev,
1718 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG, orig_value);
1719 if (err < 0) {
1720 dev_err(dev, "ab->write fail %d\n", err);
1721 return err;
1722 }
1723 return 0;
1724}
1725
1726static int ab8500_modem_open(struct inode *inode, struct file *file)
1727{
1728 return single_open(file, ab8500_print_modem_registers, inode->i_private);
1729}
1730
1731static const struct file_operations ab8500_modem_fops = {
1732 .open = ab8500_modem_open,
1733 .read = seq_read,
1734 .llseek = seq_lseek,
1735 .release = single_release,
1736 .owner = THIS_MODULE,
1737};
1738
John Beckett1478a312011-05-31 13:54:27 +01001739static int ab8500_gpadc_bat_ctrl_print(struct seq_file *s, void *p)
1740{
1741 int bat_ctrl_raw;
1742 int bat_ctrl_convert;
1743 struct ab8500_gpadc *gpadc;
1744
Philippe Langlais8908c042012-04-18 15:52:59 +02001745 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00001746 bat_ctrl_raw = ab8500_gpadc_read_raw(gpadc, BAT_CTRL,
1747 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01001748 bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc,
Lee Jones73482342013-02-26 10:06:55 +00001749 BAT_CTRL, bat_ctrl_raw);
John Beckett1478a312011-05-31 13:54:27 +01001750
1751 return seq_printf(s, "%d,0x%X\n",
1752 bat_ctrl_convert, bat_ctrl_raw);
1753}
1754
1755static int ab8500_gpadc_bat_ctrl_open(struct inode *inode, struct file *file)
1756{
1757 return single_open(file, ab8500_gpadc_bat_ctrl_print, inode->i_private);
1758}
1759
1760static const struct file_operations ab8500_gpadc_bat_ctrl_fops = {
1761 .open = ab8500_gpadc_bat_ctrl_open,
1762 .read = seq_read,
1763 .llseek = seq_lseek,
1764 .release = single_release,
1765 .owner = THIS_MODULE,
1766};
1767
1768static int ab8500_gpadc_btemp_ball_print(struct seq_file *s, void *p)
1769{
1770 int btemp_ball_raw;
1771 int btemp_ball_convert;
1772 struct ab8500_gpadc *gpadc;
1773
Philippe Langlais8908c042012-04-18 15:52:59 +02001774 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00001775 btemp_ball_raw = ab8500_gpadc_read_raw(gpadc, BTEMP_BALL,
1776 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01001777 btemp_ball_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL,
Lee Jones73482342013-02-26 10:06:55 +00001778 btemp_ball_raw);
John Beckett1478a312011-05-31 13:54:27 +01001779
1780 return seq_printf(s,
1781 "%d,0x%X\n", btemp_ball_convert, btemp_ball_raw);
1782}
1783
1784static int ab8500_gpadc_btemp_ball_open(struct inode *inode,
1785 struct file *file)
1786{
1787 return single_open(file, ab8500_gpadc_btemp_ball_print, inode->i_private);
1788}
1789
1790static const struct file_operations ab8500_gpadc_btemp_ball_fops = {
1791 .open = ab8500_gpadc_btemp_ball_open,
1792 .read = seq_read,
1793 .llseek = seq_lseek,
1794 .release = single_release,
1795 .owner = THIS_MODULE,
1796};
1797
1798static int ab8500_gpadc_main_charger_v_print(struct seq_file *s, void *p)
1799{
1800 int main_charger_v_raw;
1801 int main_charger_v_convert;
1802 struct ab8500_gpadc *gpadc;
1803
Philippe Langlais8908c042012-04-18 15:52:59 +02001804 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00001805 main_charger_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_V,
1806 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01001807 main_charger_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
Lee Jones73482342013-02-26 10:06:55 +00001808 MAIN_CHARGER_V, main_charger_v_raw);
John Beckett1478a312011-05-31 13:54:27 +01001809
1810 return seq_printf(s, "%d,0x%X\n",
1811 main_charger_v_convert, main_charger_v_raw);
1812}
1813
1814static int ab8500_gpadc_main_charger_v_open(struct inode *inode,
1815 struct file *file)
1816{
1817 return single_open(file, ab8500_gpadc_main_charger_v_print,
1818 inode->i_private);
1819}
1820
1821static const struct file_operations ab8500_gpadc_main_charger_v_fops = {
1822 .open = ab8500_gpadc_main_charger_v_open,
1823 .read = seq_read,
1824 .llseek = seq_lseek,
1825 .release = single_release,
1826 .owner = THIS_MODULE,
1827};
1828
1829static int ab8500_gpadc_acc_detect1_print(struct seq_file *s, void *p)
1830{
1831 int acc_detect1_raw;
1832 int acc_detect1_convert;
1833 struct ab8500_gpadc *gpadc;
1834
Philippe Langlais8908c042012-04-18 15:52:59 +02001835 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00001836 acc_detect1_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT1,
1837 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01001838 acc_detect1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ACC_DETECT1,
Lee Jones73482342013-02-26 10:06:55 +00001839 acc_detect1_raw);
John Beckett1478a312011-05-31 13:54:27 +01001840
1841 return seq_printf(s, "%d,0x%X\n",
1842 acc_detect1_convert, acc_detect1_raw);
1843}
1844
1845static int ab8500_gpadc_acc_detect1_open(struct inode *inode,
1846 struct file *file)
1847{
1848 return single_open(file, ab8500_gpadc_acc_detect1_print,
1849 inode->i_private);
1850}
1851
1852static const struct file_operations ab8500_gpadc_acc_detect1_fops = {
1853 .open = ab8500_gpadc_acc_detect1_open,
1854 .read = seq_read,
1855 .llseek = seq_lseek,
1856 .release = single_release,
1857 .owner = THIS_MODULE,
1858};
1859
1860static int ab8500_gpadc_acc_detect2_print(struct seq_file *s, void *p)
1861{
1862 int acc_detect2_raw;
1863 int acc_detect2_convert;
1864 struct ab8500_gpadc *gpadc;
1865
Philippe Langlais8908c042012-04-18 15:52:59 +02001866 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00001867 acc_detect2_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT2,
1868 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01001869 acc_detect2_convert = ab8500_gpadc_ad_to_voltage(gpadc,
Lee Jones73482342013-02-26 10:06:55 +00001870 ACC_DETECT2, acc_detect2_raw);
John Beckett1478a312011-05-31 13:54:27 +01001871
1872 return seq_printf(s, "%d,0x%X\n",
1873 acc_detect2_convert, acc_detect2_raw);
1874}
1875
1876static int ab8500_gpadc_acc_detect2_open(struct inode *inode,
1877 struct file *file)
1878{
1879 return single_open(file, ab8500_gpadc_acc_detect2_print,
1880 inode->i_private);
1881}
1882
1883static const struct file_operations ab8500_gpadc_acc_detect2_fops = {
1884 .open = ab8500_gpadc_acc_detect2_open,
1885 .read = seq_read,
1886 .llseek = seq_lseek,
1887 .release = single_release,
1888 .owner = THIS_MODULE,
1889};
1890
1891static int ab8500_gpadc_aux1_print(struct seq_file *s, void *p)
1892{
1893 int aux1_raw;
1894 int aux1_convert;
1895 struct ab8500_gpadc *gpadc;
1896
Philippe Langlais8908c042012-04-18 15:52:59 +02001897 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00001898 aux1_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX1,
1899 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01001900 aux1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX1,
Lee Jones73482342013-02-26 10:06:55 +00001901 aux1_raw);
John Beckett1478a312011-05-31 13:54:27 +01001902
1903 return seq_printf(s, "%d,0x%X\n",
1904 aux1_convert, aux1_raw);
1905}
1906
1907static int ab8500_gpadc_aux1_open(struct inode *inode, struct file *file)
1908{
1909 return single_open(file, ab8500_gpadc_aux1_print, inode->i_private);
1910}
1911
1912static const struct file_operations ab8500_gpadc_aux1_fops = {
1913 .open = ab8500_gpadc_aux1_open,
1914 .read = seq_read,
1915 .llseek = seq_lseek,
1916 .release = single_release,
1917 .owner = THIS_MODULE,
1918};
1919
1920static int ab8500_gpadc_aux2_print(struct seq_file *s, void *p)
1921{
1922 int aux2_raw;
1923 int aux2_convert;
1924 struct ab8500_gpadc *gpadc;
1925
Philippe Langlais8908c042012-04-18 15:52:59 +02001926 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00001927 aux2_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX2,
1928 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01001929 aux2_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX2,
Lee Jones73482342013-02-26 10:06:55 +00001930 aux2_raw);
John Beckett1478a312011-05-31 13:54:27 +01001931
1932 return seq_printf(s, "%d,0x%X\n",
1933 aux2_convert, aux2_raw);
1934}
1935
1936static int ab8500_gpadc_aux2_open(struct inode *inode, struct file *file)
1937{
1938 return single_open(file, ab8500_gpadc_aux2_print, inode->i_private);
1939}
1940
1941static const struct file_operations ab8500_gpadc_aux2_fops = {
1942 .open = ab8500_gpadc_aux2_open,
1943 .read = seq_read,
1944 .llseek = seq_lseek,
1945 .release = single_release,
1946 .owner = THIS_MODULE,
1947};
1948
1949static int ab8500_gpadc_main_bat_v_print(struct seq_file *s, void *p)
1950{
1951 int main_bat_v_raw;
1952 int main_bat_v_convert;
1953 struct ab8500_gpadc *gpadc;
1954
Philippe Langlais8908c042012-04-18 15:52:59 +02001955 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00001956 main_bat_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_BAT_V,
1957 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01001958 main_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V,
Lee Jones73482342013-02-26 10:06:55 +00001959 main_bat_v_raw);
John Beckett1478a312011-05-31 13:54:27 +01001960
1961 return seq_printf(s, "%d,0x%X\n",
1962 main_bat_v_convert, main_bat_v_raw);
1963}
1964
1965static int ab8500_gpadc_main_bat_v_open(struct inode *inode,
1966 struct file *file)
1967{
1968 return single_open(file, ab8500_gpadc_main_bat_v_print, inode->i_private);
1969}
1970
1971static const struct file_operations ab8500_gpadc_main_bat_v_fops = {
1972 .open = ab8500_gpadc_main_bat_v_open,
1973 .read = seq_read,
1974 .llseek = seq_lseek,
1975 .release = single_release,
1976 .owner = THIS_MODULE,
1977};
1978
1979static int ab8500_gpadc_vbus_v_print(struct seq_file *s, void *p)
1980{
1981 int vbus_v_raw;
1982 int vbus_v_convert;
1983 struct ab8500_gpadc *gpadc;
1984
Philippe Langlais8908c042012-04-18 15:52:59 +02001985 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00001986 vbus_v_raw = ab8500_gpadc_read_raw(gpadc, VBUS_V,
1987 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01001988 vbus_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, VBUS_V,
Lee Jones73482342013-02-26 10:06:55 +00001989 vbus_v_raw);
John Beckett1478a312011-05-31 13:54:27 +01001990
1991 return seq_printf(s, "%d,0x%X\n",
1992 vbus_v_convert, vbus_v_raw);
1993}
1994
1995static int ab8500_gpadc_vbus_v_open(struct inode *inode, struct file *file)
1996{
1997 return single_open(file, ab8500_gpadc_vbus_v_print, inode->i_private);
1998}
1999
2000static const struct file_operations ab8500_gpadc_vbus_v_fops = {
2001 .open = ab8500_gpadc_vbus_v_open,
2002 .read = seq_read,
2003 .llseek = seq_lseek,
2004 .release = single_release,
2005 .owner = THIS_MODULE,
2006};
2007
2008static int ab8500_gpadc_main_charger_c_print(struct seq_file *s, void *p)
2009{
2010 int main_charger_c_raw;
2011 int main_charger_c_convert;
2012 struct ab8500_gpadc *gpadc;
2013
Philippe Langlais8908c042012-04-18 15:52:59 +02002014 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00002015 main_charger_c_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_C,
2016 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01002017 main_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
Lee Jones73482342013-02-26 10:06:55 +00002018 MAIN_CHARGER_C, main_charger_c_raw);
John Beckett1478a312011-05-31 13:54:27 +01002019
2020 return seq_printf(s, "%d,0x%X\n",
2021 main_charger_c_convert, main_charger_c_raw);
2022}
2023
2024static int ab8500_gpadc_main_charger_c_open(struct inode *inode,
2025 struct file *file)
2026{
2027 return single_open(file, ab8500_gpadc_main_charger_c_print,
2028 inode->i_private);
2029}
2030
2031static const struct file_operations ab8500_gpadc_main_charger_c_fops = {
2032 .open = ab8500_gpadc_main_charger_c_open,
2033 .read = seq_read,
2034 .llseek = seq_lseek,
2035 .release = single_release,
2036 .owner = THIS_MODULE,
2037};
2038
2039static int ab8500_gpadc_usb_charger_c_print(struct seq_file *s, void *p)
2040{
2041 int usb_charger_c_raw;
2042 int usb_charger_c_convert;
2043 struct ab8500_gpadc *gpadc;
2044
Philippe Langlais8908c042012-04-18 15:52:59 +02002045 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00002046 usb_charger_c_raw = ab8500_gpadc_read_raw(gpadc, USB_CHARGER_C,
2047 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01002048 usb_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
Lee Jones73482342013-02-26 10:06:55 +00002049 USB_CHARGER_C, usb_charger_c_raw);
John Beckett1478a312011-05-31 13:54:27 +01002050
2051 return seq_printf(s, "%d,0x%X\n",
2052 usb_charger_c_convert, usb_charger_c_raw);
2053}
2054
2055static int ab8500_gpadc_usb_charger_c_open(struct inode *inode,
2056 struct file *file)
2057{
2058 return single_open(file, ab8500_gpadc_usb_charger_c_print,
2059 inode->i_private);
2060}
2061
2062static const struct file_operations ab8500_gpadc_usb_charger_c_fops = {
2063 .open = ab8500_gpadc_usb_charger_c_open,
2064 .read = seq_read,
2065 .llseek = seq_lseek,
2066 .release = single_release,
2067 .owner = THIS_MODULE,
2068};
2069
2070static int ab8500_gpadc_bk_bat_v_print(struct seq_file *s, void *p)
2071{
2072 int bk_bat_v_raw;
2073 int bk_bat_v_convert;
2074 struct ab8500_gpadc *gpadc;
2075
Philippe Langlais8908c042012-04-18 15:52:59 +02002076 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00002077 bk_bat_v_raw = ab8500_gpadc_read_raw(gpadc, BK_BAT_V,
2078 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01002079 bk_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
Lee Jones73482342013-02-26 10:06:55 +00002080 BK_BAT_V, bk_bat_v_raw);
John Beckett1478a312011-05-31 13:54:27 +01002081
2082 return seq_printf(s, "%d,0x%X\n",
2083 bk_bat_v_convert, bk_bat_v_raw);
2084}
2085
2086static int ab8500_gpadc_bk_bat_v_open(struct inode *inode, struct file *file)
2087{
2088 return single_open(file, ab8500_gpadc_bk_bat_v_print, inode->i_private);
2089}
2090
2091static const struct file_operations ab8500_gpadc_bk_bat_v_fops = {
2092 .open = ab8500_gpadc_bk_bat_v_open,
2093 .read = seq_read,
2094 .llseek = seq_lseek,
2095 .release = single_release,
2096 .owner = THIS_MODULE,
2097};
2098
2099static int ab8500_gpadc_die_temp_print(struct seq_file *s, void *p)
2100{
2101 int die_temp_raw;
2102 int die_temp_convert;
2103 struct ab8500_gpadc *gpadc;
2104
Philippe Langlais8908c042012-04-18 15:52:59 +02002105 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00002106 die_temp_raw = ab8500_gpadc_read_raw(gpadc, DIE_TEMP,
2107 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01002108 die_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, DIE_TEMP,
Lee Jones73482342013-02-26 10:06:55 +00002109 die_temp_raw);
John Beckett1478a312011-05-31 13:54:27 +01002110
2111 return seq_printf(s, "%d,0x%X\n",
2112 die_temp_convert, die_temp_raw);
2113}
2114
2115static int ab8500_gpadc_die_temp_open(struct inode *inode, struct file *file)
2116{
2117 return single_open(file, ab8500_gpadc_die_temp_print, inode->i_private);
2118}
2119
2120static const struct file_operations ab8500_gpadc_die_temp_fops = {
2121 .open = ab8500_gpadc_die_temp_open,
2122 .read = seq_read,
2123 .llseek = seq_lseek,
2124 .release = single_release,
2125 .owner = THIS_MODULE,
2126};
2127
Lee Jones127629d2013-02-26 14:04:37 +00002128static int ab8500_gpadc_usb_id_print(struct seq_file *s, void *p)
2129{
2130 int usb_id_raw;
2131 int usb_id_convert;
2132 struct ab8500_gpadc *gpadc;
2133
2134 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2135 usb_id_raw = ab8500_gpadc_read_raw(gpadc, USB_ID,
2136 avg_sample, trig_edge, trig_timer, conv_type);
2137 usb_id_convert = ab8500_gpadc_ad_to_voltage(gpadc, USB_ID,
2138 usb_id_raw);
2139
2140 return seq_printf(s, "%d,0x%X\n",
2141 usb_id_convert, usb_id_raw);
2142}
2143
2144static int ab8500_gpadc_usb_id_open(struct inode *inode, struct file *file)
2145{
2146 return single_open(file, ab8500_gpadc_usb_id_print, inode->i_private);
2147}
2148
2149static const struct file_operations ab8500_gpadc_usb_id_fops = {
2150 .open = ab8500_gpadc_usb_id_open,
2151 .read = seq_read,
2152 .llseek = seq_lseek,
2153 .release = single_release,
2154 .owner = THIS_MODULE,
2155};
2156
Lee Jonesbc6b4132013-02-26 14:02:31 +00002157static int ab8540_gpadc_xtal_temp_print(struct seq_file *s, void *p)
2158{
2159 int xtal_temp_raw;
2160 int xtal_temp_convert;
2161 struct ab8500_gpadc *gpadc;
2162
2163 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2164 xtal_temp_raw = ab8500_gpadc_read_raw(gpadc, XTAL_TEMP,
2165 avg_sample, trig_edge, trig_timer, conv_type);
2166 xtal_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, XTAL_TEMP,
2167 xtal_temp_raw);
2168
2169 return seq_printf(s, "%d,0x%X\n",
2170 xtal_temp_convert, xtal_temp_raw);
2171}
2172
2173static int ab8540_gpadc_xtal_temp_open(struct inode *inode, struct file *file)
2174{
2175 return single_open(file, ab8540_gpadc_xtal_temp_print,
2176 inode->i_private);
2177}
2178
2179static const struct file_operations ab8540_gpadc_xtal_temp_fops = {
2180 .open = ab8540_gpadc_xtal_temp_open,
2181 .read = seq_read,
2182 .llseek = seq_lseek,
2183 .release = single_release,
2184 .owner = THIS_MODULE,
2185};
2186
2187static int ab8540_gpadc_vbat_true_meas_print(struct seq_file *s, void *p)
2188{
2189 int vbat_true_meas_raw;
2190 int vbat_true_meas_convert;
2191 struct ab8500_gpadc *gpadc;
2192
2193 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2194 vbat_true_meas_raw = ab8500_gpadc_read_raw(gpadc, VBAT_TRUE_MEAS,
2195 avg_sample, trig_edge, trig_timer, conv_type);
2196 vbat_true_meas_convert = ab8500_gpadc_ad_to_voltage(gpadc, VBAT_TRUE_MEAS,
2197 vbat_true_meas_raw);
2198
2199 return seq_printf(s, "%d,0x%X\n",
2200 vbat_true_meas_convert, vbat_true_meas_raw);
2201}
2202
2203static int ab8540_gpadc_vbat_true_meas_open(struct inode *inode,
2204 struct file *file)
2205{
2206 return single_open(file, ab8540_gpadc_vbat_true_meas_print,
2207 inode->i_private);
2208}
2209
2210static const struct file_operations ab8540_gpadc_vbat_true_meas_fops = {
2211 .open = ab8540_gpadc_vbat_true_meas_open,
2212 .read = seq_read,
2213 .llseek = seq_lseek,
2214 .release = single_release,
2215 .owner = THIS_MODULE,
2216};
2217
2218static int ab8540_gpadc_bat_ctrl_and_ibat_print(struct seq_file *s, void *p)
2219{
2220 int bat_ctrl_raw;
2221 int bat_ctrl_convert;
2222 int ibat_raw;
2223 int ibat_convert;
2224 struct ab8500_gpadc *gpadc;
2225
2226 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2227 bat_ctrl_raw = ab8500_gpadc_double_read_raw(gpadc, BAT_CTRL_AND_IBAT,
2228 avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
2229
2230 bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc, BAT_CTRL,
2231 bat_ctrl_raw);
2232 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2233 ibat_raw);
2234
2235 return seq_printf(s, "%d,0x%X\n" "%d,0x%X\n",
2236 bat_ctrl_convert, bat_ctrl_raw,
2237 ibat_convert, ibat_raw);
2238}
2239
2240static int ab8540_gpadc_bat_ctrl_and_ibat_open(struct inode *inode,
2241 struct file *file)
2242{
2243 return single_open(file, ab8540_gpadc_bat_ctrl_and_ibat_print,
2244 inode->i_private);
2245}
2246
2247static const struct file_operations ab8540_gpadc_bat_ctrl_and_ibat_fops = {
2248 .open = ab8540_gpadc_bat_ctrl_and_ibat_open,
2249 .read = seq_read,
2250 .llseek = seq_lseek,
2251 .release = single_release,
2252 .owner = THIS_MODULE,
2253};
2254
2255static int ab8540_gpadc_vbat_meas_and_ibat_print(struct seq_file *s, void *p)
2256{
2257 int vbat_meas_raw;
2258 int vbat_meas_convert;
2259 int ibat_raw;
2260 int ibat_convert;
2261 struct ab8500_gpadc *gpadc;
2262
2263 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2264 vbat_meas_raw = ab8500_gpadc_double_read_raw(gpadc, VBAT_MEAS_AND_IBAT,
2265 avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
2266 vbat_meas_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V,
2267 vbat_meas_raw);
2268 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2269 ibat_raw);
2270
2271 return seq_printf(s, "%d,0x%X\n" "%d,0x%X\n",
2272 vbat_meas_convert, vbat_meas_raw,
2273 ibat_convert, ibat_raw);
2274}
2275
2276static int ab8540_gpadc_vbat_meas_and_ibat_open(struct inode *inode,
2277 struct file *file)
2278{
2279 return single_open(file, ab8540_gpadc_vbat_meas_and_ibat_print,
2280 inode->i_private);
2281}
2282
2283static const struct file_operations ab8540_gpadc_vbat_meas_and_ibat_fops = {
2284 .open = ab8540_gpadc_vbat_meas_and_ibat_open,
2285 .read = seq_read,
2286 .llseek = seq_lseek,
2287 .release = single_release,
2288 .owner = THIS_MODULE,
2289};
2290
2291static int ab8540_gpadc_vbat_true_meas_and_ibat_print(struct seq_file *s, void *p)
2292{
2293 int vbat_true_meas_raw;
2294 int vbat_true_meas_convert;
2295 int ibat_raw;
2296 int ibat_convert;
2297 struct ab8500_gpadc *gpadc;
2298
2299 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2300 vbat_true_meas_raw = ab8500_gpadc_double_read_raw(gpadc,
2301 VBAT_TRUE_MEAS_AND_IBAT, avg_sample, trig_edge,
2302 trig_timer, conv_type, &ibat_raw);
2303 vbat_true_meas_convert = ab8500_gpadc_ad_to_voltage(gpadc,
2304 VBAT_TRUE_MEAS, vbat_true_meas_raw);
2305 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2306 ibat_raw);
2307
2308 return seq_printf(s, "%d,0x%X\n" "%d,0x%X\n",
2309 vbat_true_meas_convert, vbat_true_meas_raw,
2310 ibat_convert, ibat_raw);
2311}
2312
2313static int ab8540_gpadc_vbat_true_meas_and_ibat_open(struct inode *inode,
2314 struct file *file)
2315{
2316 return single_open(file, ab8540_gpadc_vbat_true_meas_and_ibat_print,
2317 inode->i_private);
2318}
2319
2320static const struct file_operations ab8540_gpadc_vbat_true_meas_and_ibat_fops = {
2321 .open = ab8540_gpadc_vbat_true_meas_and_ibat_open,
2322 .read = seq_read,
2323 .llseek = seq_lseek,
2324 .release = single_release,
2325 .owner = THIS_MODULE,
2326};
2327
2328static int ab8540_gpadc_bat_temp_and_ibat_print(struct seq_file *s, void *p)
2329{
2330 int bat_temp_raw;
2331 int bat_temp_convert;
2332 int ibat_raw;
2333 int ibat_convert;
2334 struct ab8500_gpadc *gpadc;
2335
2336 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2337 bat_temp_raw = ab8500_gpadc_double_read_raw(gpadc, BAT_TEMP_AND_IBAT,
2338 avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
2339 bat_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL,
2340 bat_temp_raw);
2341 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2342 ibat_raw);
2343
2344 return seq_printf(s, "%d,0x%X\n" "%d,0x%X\n",
2345 bat_temp_convert, bat_temp_raw,
2346 ibat_convert, ibat_raw);
2347}
2348
2349static int ab8540_gpadc_bat_temp_and_ibat_open(struct inode *inode,
2350 struct file *file)
2351{
2352 return single_open(file, ab8540_gpadc_bat_temp_and_ibat_print,
2353 inode->i_private);
2354}
2355
2356static const struct file_operations ab8540_gpadc_bat_temp_and_ibat_fops = {
2357 .open = ab8540_gpadc_bat_temp_and_ibat_open,
2358 .read = seq_read,
2359 .llseek = seq_lseek,
2360 .release = single_release,
2361 .owner = THIS_MODULE,
2362};
2363
2364static int ab8540_gpadc_otp_cal_print(struct seq_file *s, void *p)
2365{
2366 struct ab8500_gpadc *gpadc;
2367 u16 vmain_l, vmain_h, btemp_l, btemp_h;
2368 u16 vbat_l, vbat_h, ibat_l, ibat_h;
2369
2370 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2371 ab8540_gpadc_get_otp(gpadc, &vmain_l, &vmain_h, &btemp_l, &btemp_h,
2372 &vbat_l, &vbat_h, &ibat_l, &ibat_h);
2373 return seq_printf(s, "VMAIN_L:0x%X\n"
2374 "VMAIN_H:0x%X\n"
2375 "BTEMP_L:0x%X\n"
2376 "BTEMP_H:0x%X\n"
2377 "VBAT_L:0x%X\n"
2378 "VBAT_H:0x%X\n"
2379 "IBAT_L:0x%X\n"
2380 "IBAT_H:0x%X\n"
2381 ,
2382 vmain_l,
2383 vmain_h,
2384 btemp_l,
2385 btemp_h,
2386 vbat_l,
2387 vbat_h,
2388 ibat_l,
2389 ibat_h);
2390}
2391
2392static int ab8540_gpadc_otp_cal_open(struct inode *inode, struct file *file)
2393{
2394 return single_open(file, ab8540_gpadc_otp_cal_print, inode->i_private);
2395}
2396
2397static const struct file_operations ab8540_gpadc_otp_calib_fops = {
2398 .open = ab8540_gpadc_otp_cal_open,
2399 .read = seq_read,
2400 .llseek = seq_lseek,
2401 .release = single_release,
2402 .owner = THIS_MODULE,
2403};
2404
Lee Jones73482342013-02-26 10:06:55 +00002405static int ab8500_gpadc_avg_sample_print(struct seq_file *s, void *p)
2406{
2407 return seq_printf(s, "%d\n", avg_sample);
2408}
2409
2410static int ab8500_gpadc_avg_sample_open(struct inode *inode, struct file *file)
2411{
2412 return single_open(file, ab8500_gpadc_avg_sample_print,
2413 inode->i_private);
2414}
2415
2416static ssize_t ab8500_gpadc_avg_sample_write(struct file *file,
2417 const char __user *user_buf,
2418 size_t count, loff_t *ppos)
2419{
2420 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2421 char buf[32];
2422 int buf_size;
2423 unsigned long user_avg_sample;
2424 int err;
2425
2426 /* Get userspace string and assure termination */
2427 buf_size = min(count, (sizeof(buf) - 1));
2428 if (copy_from_user(buf, user_buf, buf_size))
2429 return -EFAULT;
2430 buf[buf_size] = 0;
2431
2432 err = strict_strtoul(buf, 0, &user_avg_sample);
2433 if (err)
2434 return -EINVAL;
2435 if ((user_avg_sample == SAMPLE_1) || (user_avg_sample == SAMPLE_4)
2436 || (user_avg_sample == SAMPLE_8)
2437 || (user_avg_sample == SAMPLE_16)) {
2438 avg_sample = (u8) user_avg_sample;
2439 } else {
2440 dev_err(dev, "debugfs error input: "
2441 "should be egal to 1, 4, 8 or 16\n");
2442 return -EINVAL;
2443 }
2444 return buf_size;
2445}
2446
2447static const struct file_operations ab8500_gpadc_avg_sample_fops = {
2448 .open = ab8500_gpadc_avg_sample_open,
2449 .read = seq_read,
2450 .write = ab8500_gpadc_avg_sample_write,
2451 .llseek = seq_lseek,
2452 .release = single_release,
2453 .owner = THIS_MODULE,
2454};
2455
2456static int ab8500_gpadc_trig_edge_print(struct seq_file *s, void *p)
2457{
2458 return seq_printf(s, "%d\n", trig_edge);
2459}
2460
2461static int ab8500_gpadc_trig_edge_open(struct inode *inode, struct file *file)
2462{
2463 return single_open(file, ab8500_gpadc_trig_edge_print,
2464 inode->i_private);
2465}
2466
2467static ssize_t ab8500_gpadc_trig_edge_write(struct file *file,
2468 const char __user *user_buf,
2469 size_t count, loff_t *ppos)
2470{
2471 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2472 char buf[32];
2473 int buf_size;
2474 unsigned long user_trig_edge;
2475 int err;
2476
2477 /* Get userspace string and assure termination */
2478 buf_size = min(count, (sizeof(buf) - 1));
2479 if (copy_from_user(buf, user_buf, buf_size))
2480 return -EFAULT;
2481 buf[buf_size] = 0;
2482
2483 err = strict_strtoul(buf, 0, &user_trig_edge);
2484 if (err)
2485 return -EINVAL;
2486 if ((user_trig_edge == RISING_EDGE)
2487 || (user_trig_edge == FALLING_EDGE)) {
2488 trig_edge = (u8) user_trig_edge;
2489 } else {
2490 dev_err(dev, "Wrong input:\n"
2491 "Enter 0. Rising edge\n"
2492 "Enter 1. Falling edge\n");
2493 return -EINVAL;
2494 }
2495 return buf_size;
2496}
2497
2498static const struct file_operations ab8500_gpadc_trig_edge_fops = {
2499 .open = ab8500_gpadc_trig_edge_open,
2500 .read = seq_read,
2501 .write = ab8500_gpadc_trig_edge_write,
2502 .llseek = seq_lseek,
2503 .release = single_release,
2504 .owner = THIS_MODULE,
2505};
2506
2507static int ab8500_gpadc_trig_timer_print(struct seq_file *s, void *p)
2508{
2509 return seq_printf(s, "%d\n", trig_timer);
2510}
2511
2512static int ab8500_gpadc_trig_timer_open(struct inode *inode, struct file *file)
2513{
2514 return single_open(file, ab8500_gpadc_trig_timer_print,
2515 inode->i_private);
2516}
2517
2518static ssize_t ab8500_gpadc_trig_timer_write(struct file *file,
2519 const char __user *user_buf,
2520 size_t count, loff_t *ppos)
2521{
2522 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2523 char buf[32];
2524 int buf_size;
2525 unsigned long user_trig_timer;
2526 int err;
2527
2528 /* Get userspace string and assure termination */
2529 buf_size = min(count, (sizeof(buf) - 1));
2530 if (copy_from_user(buf, user_buf, buf_size))
2531 return -EFAULT;
2532 buf[buf_size] = 0;
2533
2534 err = strict_strtoul(buf, 0, &user_trig_timer);
2535 if (err)
2536 return -EINVAL;
2537 if ((user_trig_timer >= 0) && (user_trig_timer <= 255)) {
2538 trig_timer = (u8) user_trig_timer;
2539 } else {
2540 dev_err(dev, "debugfs error input: "
2541 "should be beetween 0 to 255\n");
2542 return -EINVAL;
2543 }
2544 return buf_size;
2545}
2546
2547static const struct file_operations ab8500_gpadc_trig_timer_fops = {
2548 .open = ab8500_gpadc_trig_timer_open,
2549 .read = seq_read,
2550 .write = ab8500_gpadc_trig_timer_write,
2551 .llseek = seq_lseek,
2552 .release = single_release,
2553 .owner = THIS_MODULE,
2554};
2555
2556static int ab8500_gpadc_conv_type_print(struct seq_file *s, void *p)
2557{
2558 return seq_printf(s, "%d\n", conv_type);
2559}
2560
2561static int ab8500_gpadc_conv_type_open(struct inode *inode, struct file *file)
2562{
2563 return single_open(file, ab8500_gpadc_conv_type_print,
2564 inode->i_private);
2565}
2566
2567static ssize_t ab8500_gpadc_conv_type_write(struct file *file,
2568 const char __user *user_buf,
2569 size_t count, loff_t *ppos)
2570{
2571 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2572 char buf[32];
2573 int buf_size;
2574 unsigned long user_conv_type;
2575 int err;
2576
2577 /* Get userspace string and assure termination */
2578 buf_size = min(count, (sizeof(buf) - 1));
2579 if (copy_from_user(buf, user_buf, buf_size))
2580 return -EFAULT;
2581 buf[buf_size] = 0;
2582
2583 err = strict_strtoul(buf, 0, &user_conv_type);
2584 if (err)
2585 return -EINVAL;
2586 if ((user_conv_type == ADC_SW)
2587 || (user_conv_type == ADC_HW)) {
2588 conv_type = (u8) user_conv_type;
2589 } else {
2590 dev_err(dev, "Wrong input:\n"
2591 "Enter 0. ADC SW conversion\n"
2592 "Enter 1. ADC HW conversion\n");
2593 return -EINVAL;
2594 }
2595 return buf_size;
2596}
2597
2598static const struct file_operations ab8500_gpadc_conv_type_fops = {
2599 .open = ab8500_gpadc_conv_type_open,
2600 .read = seq_read,
2601 .write = ab8500_gpadc_conv_type_write,
2602 .llseek = seq_lseek,
2603 .release = single_release,
2604 .owner = THIS_MODULE,
2605};
2606
carriere etienne0fbce762011-04-08 16:26:36 +02002607/*
2608 * return length of an ASCII numerical value, 0 is string is not a
2609 * numerical value.
2610 * string shall start at value 1st char.
2611 * string can be tailed with \0 or space or newline chars only.
2612 * value can be decimal or hexadecimal (prefixed 0x or 0X).
2613 */
2614static int strval_len(char *b)
2615{
2616 char *s = b;
2617 if ((*s == '0') && ((*(s+1) == 'x') || (*(s+1) == 'X'))) {
2618 s += 2;
2619 for (; *s && (*s != ' ') && (*s != '\n'); s++) {
2620 if (!isxdigit(*s))
2621 return 0;
2622 }
2623 } else {
2624 if (*s == '-')
2625 s++;
2626 for (; *s && (*s != ' ') && (*s != '\n'); s++) {
2627 if (!isdigit(*s))
2628 return 0;
2629 }
2630 }
2631 return (int) (s-b);
2632}
2633
2634/*
2635 * parse hwreg input data.
2636 * update global hwreg_cfg only if input data syntax is ok.
2637 */
2638static ssize_t hwreg_common_write(char *b, struct hwreg_cfg *cfg,
2639 struct device *dev)
2640{
2641 uint write, val = 0;
2642 u8 regvalue;
2643 int ret;
2644 struct hwreg_cfg loc = {
2645 .bank = 0, /* default: invalid phys addr */
2646 .addr = 0, /* default: invalid phys addr */
2647 .fmt = 0, /* default: 32bit access, hex output */
2648 .mask = 0xFFFFFFFF, /* default: no mask */
2649 .shift = 0, /* default: no bit shift */
2650 };
2651
2652 /* read or write ? */
2653 if (!strncmp(b, "read ", 5)) {
2654 write = 0;
2655 b += 5;
2656 } else if (!strncmp(b, "write ", 6)) {
2657 write = 1;
2658 b += 6;
2659 } else
2660 return -EINVAL;
2661
2662 /* OPTIONS -l|-w|-b -s -m -o */
2663 while ((*b == ' ') || (*b == '-')) {
2664 if (*(b-1) != ' ') {
2665 b++;
2666 continue;
2667 }
2668 if ((!strncmp(b, "-d ", 3)) ||
2669 (!strncmp(b, "-dec ", 5))) {
2670 b += (*(b+2) == ' ') ? 3 : 5;
2671 loc.fmt |= (1<<0);
2672 } else if ((!strncmp(b, "-h ", 3)) ||
2673 (!strncmp(b, "-hex ", 5))) {
2674 b += (*(b+2) == ' ') ? 3 : 5;
2675 loc.fmt &= ~(1<<0);
2676 } else if ((!strncmp(b, "-m ", 3)) ||
2677 (!strncmp(b, "-mask ", 6))) {
2678 b += (*(b+2) == ' ') ? 3 : 6;
2679 if (strval_len(b) == 0)
2680 return -EINVAL;
2681 loc.mask = simple_strtoul(b, &b, 0);
2682 } else if ((!strncmp(b, "-s ", 3)) ||
2683 (!strncmp(b, "-shift ", 7))) {
2684 b += (*(b+2) == ' ') ? 3 : 7;
2685 if (strval_len(b) == 0)
2686 return -EINVAL;
2687 loc.shift = simple_strtol(b, &b, 0);
2688 } else {
2689 return -EINVAL;
2690 }
2691 }
2692 /* get arg BANK and ADDRESS */
2693 if (strval_len(b) == 0)
2694 return -EINVAL;
2695 loc.bank = simple_strtoul(b, &b, 0);
2696 while (*b == ' ')
2697 b++;
2698 if (strval_len(b) == 0)
2699 return -EINVAL;
2700 loc.addr = simple_strtoul(b, &b, 0);
2701
2702 if (write) {
2703 while (*b == ' ')
2704 b++;
2705 if (strval_len(b) == 0)
2706 return -EINVAL;
2707 val = simple_strtoul(b, &b, 0);
2708 }
2709
2710 /* args are ok, update target cfg (mainly for read) */
2711 *cfg = loc;
2712
2713#ifdef ABB_HWREG_DEBUG
2714 pr_warn("HWREG request: %s, %s, addr=0x%08X, mask=0x%X, shift=%d"
2715 "value=0x%X\n", (write) ? "write" : "read",
2716 REG_FMT_DEC(cfg) ? "decimal" : "hexa",
2717 cfg->addr, cfg->mask, cfg->shift, val);
2718#endif
2719
2720 if (!write)
2721 return 0;
2722
2723 ret = abx500_get_register_interruptible(dev,
2724 (u8)cfg->bank, (u8)cfg->addr, &regvalue);
2725 if (ret < 0) {
2726 dev_err(dev, "abx500_get_reg fail %d, %d\n",
2727 ret, __LINE__);
2728 return -EINVAL;
2729 }
2730
2731 if (cfg->shift >= 0) {
2732 regvalue &= ~(cfg->mask << (cfg->shift));
2733 val = (val & cfg->mask) << (cfg->shift);
2734 } else {
2735 regvalue &= ~(cfg->mask >> (-cfg->shift));
2736 val = (val & cfg->mask) >> (-cfg->shift);
2737 }
2738 val = val | regvalue;
2739
2740 ret = abx500_set_register_interruptible(dev,
2741 (u8)cfg->bank, (u8)cfg->addr, (u8)val);
2742 if (ret < 0) {
2743 pr_err("abx500_set_reg failed %d, %d", ret, __LINE__);
2744 return -EINVAL;
2745 }
2746
2747 return 0;
2748}
2749
2750static ssize_t ab8500_hwreg_write(struct file *file,
2751 const char __user *user_buf, size_t count, loff_t *ppos)
2752{
2753 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2754 char buf[128];
2755 int buf_size, ret;
2756
2757 /* Get userspace string and assure termination */
2758 buf_size = min(count, (sizeof(buf)-1));
2759 if (copy_from_user(buf, user_buf, buf_size))
2760 return -EFAULT;
2761 buf[buf_size] = 0;
2762
2763 /* get args and process */
2764 ret = hwreg_common_write(buf, &hwreg_cfg, dev);
2765 return (ret) ? ret : buf_size;
2766}
2767
2768/*
2769 * - irq subscribe/unsubscribe stuff
2770 */
Lee Jones4b8ac082013-01-14 16:10:36 +00002771static int ab8500_subscribe_unsubscribe_print(struct seq_file *s, void *p)
2772{
2773 seq_printf(s, "%d\n", irq_first);
2774
2775 return 0;
2776}
2777
2778static int ab8500_subscribe_unsubscribe_open(struct inode *inode,
2779 struct file *file)
2780{
2781 return single_open(file, ab8500_subscribe_unsubscribe_print,
2782 inode->i_private);
2783}
2784
2785/*
Mattias Wallin0b337e72010-11-19 17:55:11 +01002786 * Userspace should use poll() on this file. When an event occur
Lee Jones4b8ac082013-01-14 16:10:36 +00002787 * the blocking poll will be released.
2788 */
2789static ssize_t show_irq(struct device *dev,
2790 struct device_attribute *attr, char *buf)
2791{
Mattias Wallin0b337e72010-11-19 17:55:11 +01002792 unsigned long name;
2793 unsigned int irq_index;
2794 int err;
Lee Jones4b8ac082013-01-14 16:10:36 +00002795
Mattias Wallin0b337e72010-11-19 17:55:11 +01002796 err = strict_strtoul(attr->attr.name, 0, &name);
2797 if (err)
2798 return err;
2799
2800 irq_index = name - irq_first;
Linus Walleijddba25f2012-02-03 11:19:05 +01002801 if (irq_index >= num_irqs)
Mattias Wallin0b337e72010-11-19 17:55:11 +01002802 return -EINVAL;
2803 else
2804 return sprintf(buf, "%u\n", irq_count[irq_index]);
2805}
Lee Jones4b8ac082013-01-14 16:10:36 +00002806
2807static ssize_t ab8500_subscribe_write(struct file *file,
2808 const char __user *user_buf,
2809 size_t count, loff_t *ppos)
2810{
2811 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2812 char buf[32];
2813 int buf_size;
2814 unsigned long user_val;
2815 int err;
Mattias Wallin0b337e72010-11-19 17:55:11 +01002816 unsigned int irq_index;
Lee Jones4b8ac082013-01-14 16:10:36 +00002817
2818 /* Get userspace string and assure termination */
2819 buf_size = min(count, (sizeof(buf)-1));
2820 if (copy_from_user(buf, user_buf, buf_size))
2821 return -EFAULT;
2822 buf[buf_size] = 0;
2823
2824 err = strict_strtoul(buf, 0, &user_val);
2825 if (err)
2826 return -EINVAL;
2827 if (user_val < irq_first) {
2828 dev_err(dev, "debugfs error input < %d\n", irq_first);
2829 return -EINVAL;
2830 }
2831 if (user_val > irq_last) {
2832 dev_err(dev, "debugfs error input > %d\n", irq_last);
2833 return -EINVAL;
2834 }
2835
Mattias Wallin0b337e72010-11-19 17:55:11 +01002836 irq_index = user_val - irq_first;
Linus Walleijddba25f2012-02-03 11:19:05 +01002837 if (irq_index >= num_irqs)
Mattias Wallin0b337e72010-11-19 17:55:11 +01002838 return -EINVAL;
2839
Lee Jones4b8ac082013-01-14 16:10:36 +00002840 /*
Mattias Wallin0b337e72010-11-19 17:55:11 +01002841 * This will create a sysfs file named <irq-nr> which userspace can
Lee Jones4b8ac082013-01-14 16:10:36 +00002842 * use to select or poll and get the AB8500 events
2843 */
Mattias Wallin0b337e72010-11-19 17:55:11 +01002844 dev_attr[irq_index] = kmalloc(sizeof(struct device_attribute),
2845 GFP_KERNEL);
2846 event_name[irq_index] = kmalloc(buf_size, GFP_KERNEL);
2847 sprintf(event_name[irq_index], "%lu", user_val);
2848 dev_attr[irq_index]->show = show_irq;
2849 dev_attr[irq_index]->store = NULL;
2850 dev_attr[irq_index]->attr.name = event_name[irq_index];
2851 dev_attr[irq_index]->attr.mode = S_IRUGO;
2852 err = sysfs_create_file(&dev->kobj, &dev_attr[irq_index]->attr);
Lee Jones4b8ac082013-01-14 16:10:36 +00002853 if (err < 0) {
2854 printk(KERN_ERR "sysfs_create_file failed %d\n", err);
2855 return err;
2856 }
2857
2858 err = request_threaded_irq(user_val, NULL, ab8500_debug_handler,
2859 IRQF_SHARED | IRQF_NO_SUSPEND,
2860 "ab8500-debug", &dev->kobj);
2861 if (err < 0) {
2862 printk(KERN_ERR "request_threaded_irq failed %d, %lu\n",
2863 err, user_val);
Mattias Wallin0b337e72010-11-19 17:55:11 +01002864 sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr);
Lee Jones4b8ac082013-01-14 16:10:36 +00002865 return err;
2866 }
2867
2868 return buf_size;
2869}
2870
2871static ssize_t ab8500_unsubscribe_write(struct file *file,
2872 const char __user *user_buf,
2873 size_t count, loff_t *ppos)
2874{
2875 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2876 char buf[32];
2877 int buf_size;
2878 unsigned long user_val;
2879 int err;
Mattias Wallin0b337e72010-11-19 17:55:11 +01002880 unsigned int irq_index;
Lee Jones4b8ac082013-01-14 16:10:36 +00002881
2882 /* Get userspace string and assure termination */
2883 buf_size = min(count, (sizeof(buf)-1));
2884 if (copy_from_user(buf, user_buf, buf_size))
2885 return -EFAULT;
2886 buf[buf_size] = 0;
2887
2888 err = strict_strtoul(buf, 0, &user_val);
2889 if (err)
2890 return -EINVAL;
2891 if (user_val < irq_first) {
2892 dev_err(dev, "debugfs error input < %d\n", irq_first);
2893 return -EINVAL;
2894 }
2895 if (user_val > irq_last) {
2896 dev_err(dev, "debugfs error input > %d\n", irq_last);
2897 return -EINVAL;
2898 }
2899
Mattias Wallin0b337e72010-11-19 17:55:11 +01002900 irq_index = user_val - irq_first;
Linus Walleijddba25f2012-02-03 11:19:05 +01002901 if (irq_index >= num_irqs)
Mattias Wallin0b337e72010-11-19 17:55:11 +01002902 return -EINVAL;
Lee Jones4b8ac082013-01-14 16:10:36 +00002903
Mattias Wallin0b337e72010-11-19 17:55:11 +01002904 /* Set irq count to 0 when unsubscribe */
2905 irq_count[irq_index] = 0;
2906
2907 if (dev_attr[irq_index])
2908 sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr);
2909
2910
2911 free_irq(user_val, &dev->kobj);
2912 kfree(event_name[irq_index]);
2913 kfree(dev_attr[irq_index]);
Lee Jones4b8ac082013-01-14 16:10:36 +00002914
2915 return buf_size;
2916}
2917
carriere etienne0fbce762011-04-08 16:26:36 +02002918/*
2919 * - several deubgfs nodes fops
2920 */
2921
Mattias Wallin5814fc32010-09-13 16:05:04 +02002922static const struct file_operations ab8500_bank_fops = {
Mattias Wallind7b9f322010-11-26 13:06:39 +01002923 .open = ab8500_bank_open,
2924 .write = ab8500_bank_write,
2925 .read = seq_read,
2926 .llseek = seq_lseek,
2927 .release = single_release,
2928 .owner = THIS_MODULE,
Mattias Wallin5814fc32010-09-13 16:05:04 +02002929};
2930
2931static const struct file_operations ab8500_address_fops = {
Mattias Wallind7b9f322010-11-26 13:06:39 +01002932 .open = ab8500_address_open,
2933 .write = ab8500_address_write,
2934 .read = seq_read,
2935 .llseek = seq_lseek,
2936 .release = single_release,
2937 .owner = THIS_MODULE,
Mattias Wallin5814fc32010-09-13 16:05:04 +02002938};
2939
2940static const struct file_operations ab8500_val_fops = {
Mattias Wallind7b9f322010-11-26 13:06:39 +01002941 .open = ab8500_val_open,
2942 .write = ab8500_val_write,
2943 .read = seq_read,
2944 .llseek = seq_lseek,
2945 .release = single_release,
2946 .owner = THIS_MODULE,
Mattias Wallin5814fc32010-09-13 16:05:04 +02002947};
2948
Bengt Jonsson8f0eb432012-02-14 13:01:00 +01002949static const struct file_operations ab8500_interrupts_fops = {
2950 .open = ab8500_interrupts_open,
2951 .read = seq_read,
2952 .llseek = seq_lseek,
2953 .release = single_release,
2954 .owner = THIS_MODULE,
2955};
2956
Lee Jones4b8ac082013-01-14 16:10:36 +00002957static const struct file_operations ab8500_subscribe_fops = {
2958 .open = ab8500_subscribe_unsubscribe_open,
2959 .write = ab8500_subscribe_write,
2960 .read = seq_read,
2961 .llseek = seq_lseek,
2962 .release = single_release,
2963 .owner = THIS_MODULE,
2964};
2965
2966static const struct file_operations ab8500_unsubscribe_fops = {
2967 .open = ab8500_subscribe_unsubscribe_open,
2968 .write = ab8500_unsubscribe_write,
2969 .read = seq_read,
2970 .llseek = seq_lseek,
2971 .release = single_release,
2972 .owner = THIS_MODULE,
2973};
2974
carriere etienne0fbce762011-04-08 16:26:36 +02002975static const struct file_operations ab8500_hwreg_fops = {
2976 .open = ab8500_hwreg_open,
2977 .write = ab8500_hwreg_write,
2978 .read = seq_read,
2979 .llseek = seq_lseek,
2980 .release = single_release,
2981 .owner = THIS_MODULE,
2982};
2983
Mattias Wallin5814fc32010-09-13 16:05:04 +02002984static struct dentry *ab8500_dir;
John Beckett1478a312011-05-31 13:54:27 +01002985static struct dentry *ab8500_gpadc_dir;
Mattias Wallin5814fc32010-09-13 16:05:04 +02002986
Bill Pembertonf791be42012-11-19 13:23:04 -05002987static int ab8500_debug_probe(struct platform_device *plf)
Mattias Wallin5814fc32010-09-13 16:05:04 +02002988{
carriere etienne0fbce762011-04-08 16:26:36 +02002989 struct dentry *file;
Linus Walleijddba25f2012-02-03 11:19:05 +01002990 int ret = -ENOMEM;
2991 struct ab8500 *ab8500;
Mattias Wallind7b9f322010-11-26 13:06:39 +01002992 debug_bank = AB8500_MISC;
2993 debug_address = AB8500_REV_REG & 0x00FF;
Mattias Wallin5814fc32010-09-13 16:05:04 +02002994
Linus Walleijddba25f2012-02-03 11:19:05 +01002995 ab8500 = dev_get_drvdata(plf->dev.parent);
2996 num_irqs = ab8500->mask_size;
2997
Ashok G70bad042012-02-28 10:21:00 +05302998 irq_count = kzalloc(sizeof(*irq_count)*num_irqs, GFP_KERNEL);
Linus Walleijddba25f2012-02-03 11:19:05 +01002999 if (!irq_count)
3000 return -ENOMEM;
3001
3002 dev_attr = kzalloc(sizeof(*dev_attr)*num_irqs,GFP_KERNEL);
3003 if (!dev_attr)
3004 goto out_freeirq_count;
3005
3006 event_name = kzalloc(sizeof(*event_name)*num_irqs, GFP_KERNEL);
3007 if (!event_name)
3008 goto out_freedev_attr;
3009
Lee Jones4b8ac082013-01-14 16:10:36 +00003010 irq_first = platform_get_irq_byname(plf, "IRQ_FIRST");
3011 if (irq_first < 0) {
3012 dev_err(&plf->dev, "First irq not found, err %d\n",
John Beckett1478a312011-05-31 13:54:27 +01003013 irq_first);
Linus Walleijddba25f2012-02-03 11:19:05 +01003014 ret = irq_first;
3015 goto out_freeevent_name;
Lee Jones4b8ac082013-01-14 16:10:36 +00003016 }
3017
3018 irq_last = platform_get_irq_byname(plf, "IRQ_LAST");
3019 if (irq_last < 0) {
3020 dev_err(&plf->dev, "Last irq not found, err %d\n",
John Beckett1478a312011-05-31 13:54:27 +01003021 irq_last);
Linus Walleijddba25f2012-02-03 11:19:05 +01003022 ret = irq_last;
Jonas Aaberg2cf64e22012-05-31 07:57:07 +02003023 goto out_freeevent_name;
Lee Jones4b8ac082013-01-14 16:10:36 +00003024 }
3025
Mattias Wallind7b9f322010-11-26 13:06:39 +01003026 ab8500_dir = debugfs_create_dir(AB8500_NAME_STRING, NULL);
3027 if (!ab8500_dir)
carriere etienne0fbce762011-04-08 16:26:36 +02003028 goto err;
Mattias Wallin5814fc32010-09-13 16:05:04 +02003029
John Beckett1478a312011-05-31 13:54:27 +01003030 ab8500_gpadc_dir = debugfs_create_dir(AB8500_ADC_NAME_STRING,
3031 ab8500_dir);
3032 if (!ab8500_gpadc_dir)
3033 goto err;
3034
3035 file = debugfs_create_file("all-bank-registers", S_IRUGO,
3036 ab8500_dir, &plf->dev, &ab8500_registers_fops);
carriere etienne0fbce762011-04-08 16:26:36 +02003037 if (!file)
3038 goto err;
Mattias Wallin5814fc32010-09-13 16:05:04 +02003039
Mian Yousaf Kaukab42002c62012-01-26 15:39:20 +01003040 file = debugfs_create_file("all-banks", S_IRUGO,
3041 ab8500_dir, &plf->dev, &ab8500_all_banks_fops);
3042 if (!file)
3043 goto err;
3044
Lee Jonesf38487f2013-02-26 14:09:08 +00003045 file = debugfs_create_file("register-bank", (S_IRUGO | S_IWUSR | S_IWGRP),
John Beckett1478a312011-05-31 13:54:27 +01003046 ab8500_dir, &plf->dev, &ab8500_bank_fops);
carriere etienne0fbce762011-04-08 16:26:36 +02003047 if (!file)
3048 goto err;
Mattias Wallin5814fc32010-09-13 16:05:04 +02003049
Lee Jonesf38487f2013-02-26 14:09:08 +00003050 file = debugfs_create_file("register-address", (S_IRUGO | S_IWUSR | S_IWGRP),
John Beckett1478a312011-05-31 13:54:27 +01003051 ab8500_dir, &plf->dev, &ab8500_address_fops);
carriere etienne0fbce762011-04-08 16:26:36 +02003052 if (!file)
3053 goto err;
Mattias Wallin5814fc32010-09-13 16:05:04 +02003054
Lee Jonesf38487f2013-02-26 14:09:08 +00003055 file = debugfs_create_file("register-value", (S_IRUGO | S_IWUSR | S_IWGRP),
John Beckett1478a312011-05-31 13:54:27 +01003056 ab8500_dir, &plf->dev, &ab8500_val_fops);
carriere etienne0fbce762011-04-08 16:26:36 +02003057 if (!file)
3058 goto err;
Mattias Wallin5814fc32010-09-13 16:05:04 +02003059
Lee Jonesf38487f2013-02-26 14:09:08 +00003060 file = debugfs_create_file("irq-subscribe", (S_IRUGO | S_IWUSR | S_IWGRP),
John Beckett1478a312011-05-31 13:54:27 +01003061 ab8500_dir, &plf->dev, &ab8500_subscribe_fops);
carriere etienne0fbce762011-04-08 16:26:36 +02003062 if (!file)
3063 goto err;
Lee Jones4b8ac082013-01-14 16:10:36 +00003064
Lee Jones9581ae32012-07-06 16:11:50 +02003065 if (is_ab8500(ab8500)) {
3066 debug_ranges = ab8500_debug_ranges;
Bengt Jonsson8f0eb432012-02-14 13:01:00 +01003067 num_interrupt_lines = AB8500_NR_IRQS;
Lee Jones9581ae32012-07-06 16:11:50 +02003068 } else if (is_ab8505(ab8500)) {
3069 debug_ranges = ab8505_debug_ranges;
Bengt Jonsson8f0eb432012-02-14 13:01:00 +01003070 num_interrupt_lines = AB8505_NR_IRQS;
Lee Jones9581ae32012-07-06 16:11:50 +02003071 } else if (is_ab9540(ab8500)) {
3072 debug_ranges = ab8505_debug_ranges;
Bengt Jonsson8f0eb432012-02-14 13:01:00 +01003073 num_interrupt_lines = AB9540_NR_IRQS;
Lee Jones9581ae32012-07-06 16:11:50 +02003074 } else if (is_ab8540(ab8500)) {
Lee Jones971480f2012-11-19 12:20:03 +01003075 debug_ranges = ab8540_debug_ranges;
Lee Jonese436ddf2013-02-26 10:09:41 +00003076 num_interrupt_lines = AB8540_NR_IRQS;
Lee Jones9581ae32012-07-06 16:11:50 +02003077 }
Bengt Jonsson8f0eb432012-02-14 13:01:00 +01003078
3079 file = debugfs_create_file("interrupts", (S_IRUGO),
3080 ab8500_dir, &plf->dev, &ab8500_interrupts_fops);
3081 if (!file)
3082 goto err;
3083
Lee Jonesf38487f2013-02-26 14:09:08 +00003084 file = debugfs_create_file("irq-unsubscribe", (S_IRUGO | S_IWUSR | S_IWGRP),
John Beckett1478a312011-05-31 13:54:27 +01003085 ab8500_dir, &plf->dev, &ab8500_unsubscribe_fops);
carriere etienne0fbce762011-04-08 16:26:36 +02003086 if (!file)
3087 goto err;
3088
Lee Jonesf38487f2013-02-26 14:09:08 +00003089 file = debugfs_create_file("hwreg", (S_IRUGO | S_IWUSR | S_IWGRP),
John Beckett1478a312011-05-31 13:54:27 +01003090 ab8500_dir, &plf->dev, &ab8500_hwreg_fops);
3091 if (!file)
3092 goto err;
3093
Lee Jonesf38487f2013-02-26 14:09:08 +00003094 file = debugfs_create_file("all-modem-registers", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jonesc7ebaee2013-02-26 14:03:33 +00003095 ab8500_dir, &plf->dev, &ab8500_modem_fops);
3096 if (!file)
3097 goto err;
3098
Lee Jonesf38487f2013-02-26 14:09:08 +00003099 file = debugfs_create_file("bat_ctrl", (S_IRUGO | S_IWUSR | S_IWGRP),
John Beckett1478a312011-05-31 13:54:27 +01003100 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_bat_ctrl_fops);
3101 if (!file)
3102 goto err;
3103
Lee Jonesf38487f2013-02-26 14:09:08 +00003104 file = debugfs_create_file("btemp_ball", (S_IRUGO | S_IWUSR | S_IWGRP),
John Beckett1478a312011-05-31 13:54:27 +01003105 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_btemp_ball_fops);
3106 if (!file)
3107 goto err;
3108
Lee Jonesf38487f2013-02-26 14:09:08 +00003109 file = debugfs_create_file("main_charger_v", (S_IRUGO | S_IWUSR | S_IWGRP),
John Beckett1478a312011-05-31 13:54:27 +01003110 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_charger_v_fops);
3111 if (!file)
3112 goto err;
3113
Lee Jonesf38487f2013-02-26 14:09:08 +00003114 file = debugfs_create_file("acc_detect1", (S_IRUGO | S_IWUSR | S_IWGRP),
John Beckett1478a312011-05-31 13:54:27 +01003115 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_acc_detect1_fops);
3116 if (!file)
3117 goto err;
3118
Lee Jonesf38487f2013-02-26 14:09:08 +00003119 file = debugfs_create_file("acc_detect2", (S_IRUGO | S_IWUSR | S_IWGRP),
John Beckett1478a312011-05-31 13:54:27 +01003120 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_acc_detect2_fops);
3121 if (!file)
3122 goto err;
3123
Lee Jonesf38487f2013-02-26 14:09:08 +00003124 file = debugfs_create_file("adc_aux1", (S_IRUGO | S_IWUSR | S_IWGRP),
John Beckett1478a312011-05-31 13:54:27 +01003125 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_aux1_fops);
3126 if (!file)
3127 goto err;
3128
Lee Jonesf38487f2013-02-26 14:09:08 +00003129 file = debugfs_create_file("adc_aux2", (S_IRUGO | S_IWUSR | S_IWGRP),
John Beckett1478a312011-05-31 13:54:27 +01003130 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_aux2_fops);
3131 if (!file)
3132 goto err;
3133
Lee Jonesf38487f2013-02-26 14:09:08 +00003134 file = debugfs_create_file("main_bat_v", (S_IRUGO | S_IWUSR | S_IWGRP),
John Beckett1478a312011-05-31 13:54:27 +01003135 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_bat_v_fops);
3136 if (!file)
3137 goto err;
3138
Lee Jonesf38487f2013-02-26 14:09:08 +00003139 file = debugfs_create_file("vbus_v", (S_IRUGO | S_IWUSR | S_IWGRP),
John Beckett1478a312011-05-31 13:54:27 +01003140 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_vbus_v_fops);
3141 if (!file)
3142 goto err;
3143
Lee Jonesf38487f2013-02-26 14:09:08 +00003144 file = debugfs_create_file("main_charger_c", (S_IRUGO | S_IWUSR | S_IWGRP),
John Beckett1478a312011-05-31 13:54:27 +01003145 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_charger_c_fops);
3146 if (!file)
3147 goto err;
3148
Lee Jonesf38487f2013-02-26 14:09:08 +00003149 file = debugfs_create_file("usb_charger_c", (S_IRUGO | S_IWUSR | S_IWGRP),
John Beckett1478a312011-05-31 13:54:27 +01003150 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_usb_charger_c_fops);
3151 if (!file)
3152 goto err;
3153
Lee Jonesf38487f2013-02-26 14:09:08 +00003154 file = debugfs_create_file("bk_bat_v", (S_IRUGO | S_IWUSR | S_IWGRP),
John Beckett1478a312011-05-31 13:54:27 +01003155 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_bk_bat_v_fops);
3156 if (!file)
3157 goto err;
3158
Lee Jonesf38487f2013-02-26 14:09:08 +00003159 file = debugfs_create_file("die_temp", (S_IRUGO | S_IWUSR | S_IWGRP),
John Beckett1478a312011-05-31 13:54:27 +01003160 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_die_temp_fops);
carriere etienne0fbce762011-04-08 16:26:36 +02003161 if (!file)
3162 goto err;
Lee Jones127629d2013-02-26 14:04:37 +00003163
Lee Jonesf38487f2013-02-26 14:09:08 +00003164 file = debugfs_create_file("usb_id", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones127629d2013-02-26 14:04:37 +00003165 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_usb_id_fops);
3166 if (!file)
3167 goto err;
3168
Lee Jonesbc6b4132013-02-26 14:02:31 +00003169 if (is_ab8540(ab8500)) {
Lee Jonesf38487f2013-02-26 14:09:08 +00003170 file = debugfs_create_file("xtal_temp", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jonesbc6b4132013-02-26 14:02:31 +00003171 ab8500_gpadc_dir, &plf->dev, &ab8540_gpadc_xtal_temp_fops);
3172 if (!file)
3173 goto err;
Lee Jonesf38487f2013-02-26 14:09:08 +00003174 file = debugfs_create_file("vbattruemeas", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jonesbc6b4132013-02-26 14:02:31 +00003175 ab8500_gpadc_dir, &plf->dev,
3176 &ab8540_gpadc_vbat_true_meas_fops);
3177 if (!file)
3178 goto err;
3179 file = debugfs_create_file("batctrl_and_ibat",
3180 (S_IRUGO | S_IWUGO), ab8500_gpadc_dir,
3181 &plf->dev, &ab8540_gpadc_bat_ctrl_and_ibat_fops);
3182 if (!file)
3183 goto err;
3184 file = debugfs_create_file("vbatmeas_and_ibat",
3185 (S_IRUGO | S_IWUGO), ab8500_gpadc_dir,
3186 &plf->dev,
3187 &ab8540_gpadc_vbat_meas_and_ibat_fops);
3188 if (!file)
3189 goto err;
3190 file = debugfs_create_file("vbattruemeas_and_ibat",
3191 (S_IRUGO | S_IWUGO), ab8500_gpadc_dir,
3192 &plf->dev,
3193 &ab8540_gpadc_vbat_true_meas_and_ibat_fops);
3194 if (!file)
3195 goto err;
3196 file = debugfs_create_file("battemp_and_ibat",
3197 (S_IRUGO | S_IWUGO), ab8500_gpadc_dir,
3198 &plf->dev, &ab8540_gpadc_bat_temp_and_ibat_fops);
3199 if (!file)
3200 goto err;
Lee Jonesf38487f2013-02-26 14:09:08 +00003201 file = debugfs_create_file("otp_calib", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jonesbc6b4132013-02-26 14:02:31 +00003202 ab8500_gpadc_dir, &plf->dev, &ab8540_gpadc_otp_calib_fops);
3203 if (!file)
3204 goto err;
3205 }
Lee Jonesf38487f2013-02-26 14:09:08 +00003206 file = debugfs_create_file("avg_sample", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones73482342013-02-26 10:06:55 +00003207 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_avg_sample_fops);
3208 if (!file)
3209 goto err;
3210
Lee Jonesf38487f2013-02-26 14:09:08 +00003211 file = debugfs_create_file("trig_edge", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones73482342013-02-26 10:06:55 +00003212 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_trig_edge_fops);
3213 if (!file)
3214 goto err;
3215
Lee Jonesf38487f2013-02-26 14:09:08 +00003216 file = debugfs_create_file("trig_timer", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones73482342013-02-26 10:06:55 +00003217 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_trig_timer_fops);
3218 if (!file)
3219 goto err;
3220
Lee Jonesf38487f2013-02-26 14:09:08 +00003221 file = debugfs_create_file("conv_type", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones73482342013-02-26 10:06:55 +00003222 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_conv_type_fops);
3223 if (!file)
3224 goto err;
3225
Mattias Wallind7b9f322010-11-26 13:06:39 +01003226 return 0;
Mattias Wallin5814fc32010-09-13 16:05:04 +02003227
carriere etienne0fbce762011-04-08 16:26:36 +02003228err:
3229 if (ab8500_dir)
3230 debugfs_remove_recursive(ab8500_dir);
Mattias Wallind7b9f322010-11-26 13:06:39 +01003231 dev_err(&plf->dev, "failed to create debugfs entries.\n");
Linus Walleijddba25f2012-02-03 11:19:05 +01003232out_freeevent_name:
3233 kfree(event_name);
3234out_freedev_attr:
3235 kfree(dev_attr);
3236out_freeirq_count:
3237 kfree(irq_count);
3238
3239 return ret;
Mattias Wallin5814fc32010-09-13 16:05:04 +02003240}
3241
Bill Pemberton4740f732012-11-19 13:26:01 -05003242static int ab8500_debug_remove(struct platform_device *plf)
Mattias Wallin5814fc32010-09-13 16:05:04 +02003243{
carriere etienne0fbce762011-04-08 16:26:36 +02003244 debugfs_remove_recursive(ab8500_dir);
Linus Walleijddba25f2012-02-03 11:19:05 +01003245 kfree(event_name);
3246 kfree(dev_attr);
3247 kfree(irq_count);
3248
Mattias Wallind7b9f322010-11-26 13:06:39 +01003249 return 0;
Mattias Wallin5814fc32010-09-13 16:05:04 +02003250}
3251
3252static struct platform_driver ab8500_debug_driver = {
Mattias Wallind7b9f322010-11-26 13:06:39 +01003253 .driver = {
3254 .name = "ab8500-debug",
3255 .owner = THIS_MODULE,
3256 },
3257 .probe = ab8500_debug_probe,
Bill Pemberton84449212012-11-19 13:20:24 -05003258 .remove = ab8500_debug_remove
Mattias Wallin5814fc32010-09-13 16:05:04 +02003259};
3260
3261static int __init ab8500_debug_init(void)
3262{
Mattias Wallind7b9f322010-11-26 13:06:39 +01003263 return platform_driver_register(&ab8500_debug_driver);
Mattias Wallin5814fc32010-09-13 16:05:04 +02003264}
3265
3266static void __exit ab8500_debug_exit(void)
3267{
Mattias Wallind7b9f322010-11-26 13:06:39 +01003268 platform_driver_unregister(&ab8500_debug_driver);
Mattias Wallin5814fc32010-09-13 16:05:04 +02003269}
3270subsys_initcall(ab8500_debug_init);
3271module_exit(ab8500_debug_exit);
3272
3273MODULE_AUTHOR("Mattias WALLIN <mattias.wallin@stericsson.com");
3274MODULE_DESCRIPTION("AB8500 DEBUG");
3275MODULE_LICENSE("GPL v2");