blob: c1c815241e028375e3820e861251a8288bac730d [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 Gortmaker4b3f2b62016-10-29 21:24:37 -040077#include <linux/init.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
Mattias Wallin5814fc32010-09-13 16:05:04 +020094static u32 debug_bank;
95static u32 debug_address;
96
Linus Walleij69991812013-04-12 17:02:09 +020097static int irq_ab8500;
Lee Jones4b8ac082013-01-14 16:10:36 +000098static int irq_first;
99static int irq_last;
Linus Walleijddba25f2012-02-03 11:19:05 +0100100static u32 *irq_count;
101static int num_irqs;
Mattias Wallin0b337e72010-11-19 17:55:11 +0100102
Linus Walleijddba25f2012-02-03 11:19:05 +0100103static struct device_attribute **dev_attr;
104static char **event_name;
Lee Jones4b8ac082013-01-14 16:10:36 +0000105
Lee Jones73482342013-02-26 10:06:55 +0000106static u8 avg_sample = SAMPLE_16;
107static u8 trig_edge = RISING_EDGE;
108static u8 conv_type = ADC_SW;
109static u8 trig_timer;
110
Mattias Wallin5814fc32010-09-13 16:05:04 +0200111/**
112 * struct ab8500_reg_range
113 * @first: the first address of the range
114 * @last: the last address of the range
115 * @perm: access permissions for the range
116 */
117struct ab8500_reg_range {
Mattias Wallind7b9f322010-11-26 13:06:39 +0100118 u8 first;
119 u8 last;
120 u8 perm;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200121};
122
123/**
Lee Jones822672a2012-06-20 13:56:38 +0100124 * struct ab8500_prcmu_ranges
Mattias Wallin5814fc32010-09-13 16:05:04 +0200125 * @num_ranges: the number of ranges in the list
126 * @bankid: bank identifier
127 * @range: the list of register ranges
128 */
Lee Jones822672a2012-06-20 13:56:38 +0100129struct ab8500_prcmu_ranges {
Mattias Wallind7b9f322010-11-26 13:06:39 +0100130 u8 num_ranges;
131 u8 bankid;
132 const struct ab8500_reg_range *range;
Mattias Wallin5814fc32010-09-13 16:05:04 +0200133};
134
carriere etienne0fbce762011-04-08 16:26:36 +0200135/* hwreg- "mask" and "shift" entries ressources */
136struct hwreg_cfg {
137 u32 bank; /* target bank */
Lee Jones43621752014-07-14 18:29:16 +0100138 unsigned long addr; /* target address */
carriere etienne0fbce762011-04-08 16:26:36 +0200139 uint fmt; /* format */
Lee Jones43621752014-07-14 18:29:16 +0100140 unsigned long mask; /* read/write mask, applied before any bit shift */
141 long shift; /* bit shift (read:right shift, write:left shift */
carriere etienne0fbce762011-04-08 16:26:36 +0200142};
143/* fmt bit #0: 0=hexa, 1=dec */
144#define REG_FMT_DEC(c) ((c)->fmt & 0x1)
145#define REG_FMT_HEX(c) (!REG_FMT_DEC(c))
146
147static struct hwreg_cfg hwreg_cfg = {
148 .addr = 0, /* default: invalid phys addr */
149 .fmt = 0, /* default: 32bit access, hex output */
150 .mask = 0xFFFFFFFF, /* default: no mask */
151 .shift = 0, /* default: no bit shift */
152};
153
Mattias Wallin5814fc32010-09-13 16:05:04 +0200154#define AB8500_NAME_STRING "ab8500"
John Beckett1478a312011-05-31 13:54:27 +0100155#define AB8500_ADC_NAME_STRING "gpadc"
Lee Jonesc45eab22016-09-14 11:14:30 +0100156#define AB8500_NUM_BANKS AB8500_DEBUG_FIELD_LAST
Mattias Wallin5814fc32010-09-13 16:05:04 +0200157
158#define AB8500_REV_REG 0x80
159
Lee Jones9581ae32012-07-06 16:11:50 +0200160static struct ab8500_prcmu_ranges *debug_ranges;
161
Sachin Kamat8455eae2013-08-23 17:37:42 +0530162static struct ab8500_prcmu_ranges ab8500_debug_ranges[AB8500_NUM_BANKS] = {
Lee Jonesc45eab22016-09-14 11:14:30 +0100163 [AB8500_M_FSM_RANK] = {
Mattias Wallind7b9f322010-11-26 13:06:39 +0100164 .num_ranges = 0,
Lee Jonesfad55a82013-01-14 17:17:34 +0000165 .range = NULL,
Mattias Wallind7b9f322010-11-26 13:06:39 +0100166 },
167 [AB8500_SYS_CTRL1_BLOCK] = {
168 .num_ranges = 3,
169 .range = (struct ab8500_reg_range[]) {
170 {
171 .first = 0x00,
172 .last = 0x02,
173 },
174 {
175 .first = 0x42,
176 .last = 0x42,
177 },
178 {
179 .first = 0x80,
180 .last = 0x81,
181 },
182 },
183 },
184 [AB8500_SYS_CTRL2_BLOCK] = {
185 .num_ranges = 4,
186 .range = (struct ab8500_reg_range[]) {
187 {
188 .first = 0x00,
189 .last = 0x0D,
190 },
191 {
192 .first = 0x0F,
193 .last = 0x17,
194 },
195 {
196 .first = 0x30,
197 .last = 0x30,
198 },
199 {
200 .first = 0x32,
201 .last = 0x33,
202 },
203 },
204 },
205 [AB8500_REGU_CTRL1] = {
206 .num_ranges = 3,
207 .range = (struct ab8500_reg_range[]) {
208 {
209 .first = 0x00,
210 .last = 0x00,
211 },
212 {
213 .first = 0x03,
214 .last = 0x10,
215 },
216 {
217 .first = 0x80,
218 .last = 0x84,
219 },
220 },
221 },
222 [AB8500_REGU_CTRL2] = {
223 .num_ranges = 5,
224 .range = (struct ab8500_reg_range[]) {
225 {
226 .first = 0x00,
227 .last = 0x15,
228 },
229 {
230 .first = 0x17,
231 .last = 0x19,
232 },
233 {
234 .first = 0x1B,
235 .last = 0x1D,
236 },
237 {
238 .first = 0x1F,
239 .last = 0x22,
240 },
241 {
242 .first = 0x40,
243 .last = 0x44,
244 },
Lee Jonesde6a7692015-10-28 09:27:32 +0000245 /*
246 * 0x80-0x8B are SIM registers and should
247 * not be accessed from here
248 */
Mattias Wallind7b9f322010-11-26 13:06:39 +0100249 },
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 },
Lee Jonesc45eab22016-09-14 11:14:30 +0100318 [AB8500_RESERVED] = {
Mattias Wallind7b9f322010-11-26 13:06:39 +0100319 .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 },
389 [AB8500_AUDIO] = {
390 .num_ranges = 1,
391 .range = (struct ab8500_reg_range[]) {
392 {
393 .first = 0x00,
394 .last = 0x6F,
395 },
396 },
397 },
398 [AB8500_INTERRUPT] = {
399 .num_ranges = 0,
Mark Brown87fff232010-12-13 14:06:47 +0000400 .range = NULL,
Mattias Wallind7b9f322010-11-26 13:06:39 +0100401 },
402 [AB8500_RTC] = {
403 .num_ranges = 1,
404 .range = (struct ab8500_reg_range[]) {
405 {
406 .first = 0x00,
407 .last = 0x0F,
408 },
409 },
410 },
411 [AB8500_MISC] = {
412 .num_ranges = 8,
413 .range = (struct ab8500_reg_range[]) {
414 {
415 .first = 0x00,
416 .last = 0x05,
417 },
418 {
419 .first = 0x10,
420 .last = 0x15,
421 },
422 {
423 .first = 0x20,
424 .last = 0x25,
425 },
426 {
427 .first = 0x30,
428 .last = 0x35,
429 },
430 {
431 .first = 0x40,
432 .last = 0x45,
433 },
434 {
435 .first = 0x50,
436 .last = 0x50,
437 },
438 {
439 .first = 0x60,
440 .last = 0x67,
441 },
442 {
443 .first = 0x80,
444 .last = 0x80,
445 },
446 },
447 },
Lee Jonesc45eab22016-09-14 11:14:30 +0100448 [AB8500_DEVELOPMENT] = {
449 .num_ranges = 1,
450 .range = (struct ab8500_reg_range[]) {
451 {
452 .first = 0x00,
453 .last = 0x00,
454 },
455 },
456 },
457 [AB8500_DEBUG] = {
458 .num_ranges = 1,
459 .range = (struct ab8500_reg_range[]) {
460 {
461 .first = 0x05,
462 .last = 0x07,
463 },
464 },
465 },
466 [AB8500_PROD_TEST] = {
Mattias Wallind7b9f322010-11-26 13:06:39 +0100467 .num_ranges = 0,
Mark Brown87fff232010-12-13 14:06:47 +0000468 .range = NULL,
Mattias Wallind7b9f322010-11-26 13:06:39 +0100469 },
Lee Jonesc45eab22016-09-14 11:14:30 +0100470 [AB8500_STE_TEST] = {
Mattias Wallind7b9f322010-11-26 13:06:39 +0100471 .num_ranges = 0,
Mark Brown87fff232010-12-13 14:06:47 +0000472 .range = NULL,
Mattias Wallind7b9f322010-11-26 13:06:39 +0100473 },
474 [AB8500_OTP_EMUL] = {
475 .num_ranges = 1,
476 .range = (struct ab8500_reg_range[]) {
477 {
478 .first = 0x01,
479 .last = 0x0F,
480 },
481 },
482 },
Mattias Wallin5814fc32010-09-13 16:05:04 +0200483};
484
Sachin Kamat8455eae2013-08-23 17:37:42 +0530485static struct ab8500_prcmu_ranges ab8505_debug_ranges[AB8500_NUM_BANKS] = {
Lee Jones9581ae32012-07-06 16:11:50 +0200486 [0x0] = {
487 .num_ranges = 0,
488 .range = NULL,
489 },
490 [AB8500_SYS_CTRL1_BLOCK] = {
491 .num_ranges = 5,
492 .range = (struct ab8500_reg_range[]) {
493 {
494 .first = 0x00,
495 .last = 0x04,
496 },
497 {
498 .first = 0x42,
499 .last = 0x42,
500 },
501 {
502 .first = 0x52,
503 .last = 0x52,
504 },
505 {
506 .first = 0x54,
507 .last = 0x57,
508 },
509 {
510 .first = 0x80,
511 .last = 0x83,
512 },
513 },
514 },
515 [AB8500_SYS_CTRL2_BLOCK] = {
516 .num_ranges = 5,
517 .range = (struct ab8500_reg_range[]) {
518 {
519 .first = 0x00,
520 .last = 0x0D,
521 },
522 {
523 .first = 0x0F,
524 .last = 0x17,
525 },
526 {
527 .first = 0x20,
528 .last = 0x20,
529 },
530 {
531 .first = 0x30,
532 .last = 0x30,
533 },
534 {
535 .first = 0x32,
536 .last = 0x3A,
537 },
538 },
539 },
540 [AB8500_REGU_CTRL1] = {
541 .num_ranges = 3,
542 .range = (struct ab8500_reg_range[]) {
543 {
544 .first = 0x00,
545 .last = 0x00,
546 },
547 {
548 .first = 0x03,
549 .last = 0x11,
550 },
551 {
552 .first = 0x80,
553 .last = 0x86,
554 },
555 },
556 },
557 [AB8500_REGU_CTRL2] = {
558 .num_ranges = 6,
559 .range = (struct ab8500_reg_range[]) {
560 {
561 .first = 0x00,
562 .last = 0x06,
563 },
564 {
565 .first = 0x08,
566 .last = 0x15,
567 },
568 {
569 .first = 0x17,
570 .last = 0x19,
571 },
572 {
573 .first = 0x1B,
574 .last = 0x1D,
575 },
576 {
577 .first = 0x1F,
578 .last = 0x30,
579 },
580 {
581 .first = 0x40,
582 .last = 0x48,
583 },
Lee Jonesde6a7692015-10-28 09:27:32 +0000584 /*
585 * 0x80-0x8B are SIM registers and should
586 * not be accessed from here
587 */
Lee Jones9581ae32012-07-06 16:11:50 +0200588 },
589 },
590 [AB8500_USB] = {
591 .num_ranges = 3,
592 .range = (struct ab8500_reg_range[]) {
593 {
594 .first = 0x80,
595 .last = 0x83,
596 },
597 {
598 .first = 0x87,
599 .last = 0x8A,
600 },
601 {
602 .first = 0x91,
603 .last = 0x94,
604 },
605 },
606 },
607 [AB8500_TVOUT] = {
608 .num_ranges = 0,
609 .range = NULL,
610 },
611 [AB8500_DBI] = {
612 .num_ranges = 0,
613 .range = NULL,
614 },
615 [AB8500_ECI_AV_ACC] = {
616 .num_ranges = 1,
617 .range = (struct ab8500_reg_range[]) {
618 {
619 .first = 0x80,
620 .last = 0x82,
621 },
622 },
623 },
624 [AB8500_RESERVED] = {
625 .num_ranges = 0,
626 .range = NULL,
627 },
628 [AB8500_GPADC] = {
629 .num_ranges = 1,
630 .range = (struct ab8500_reg_range[]) {
631 {
632 .first = 0x00,
633 .last = 0x08,
634 },
635 },
636 },
637 [AB8500_CHARGER] = {
638 .num_ranges = 9,
639 .range = (struct ab8500_reg_range[]) {
640 {
641 .first = 0x02,
642 .last = 0x03,
643 },
644 {
645 .first = 0x05,
646 .last = 0x05,
647 },
648 {
649 .first = 0x40,
650 .last = 0x44,
651 },
652 {
653 .first = 0x50,
654 .last = 0x57,
655 },
656 {
657 .first = 0x60,
658 .last = 0x60,
659 },
660 {
661 .first = 0xA0,
662 .last = 0xA7,
663 },
664 {
665 .first = 0xAF,
666 .last = 0xB2,
667 },
668 {
669 .first = 0xC0,
670 .last = 0xC2,
671 },
672 {
673 .first = 0xF5,
674 .last = 0xF5,
675 },
676 },
677 },
678 [AB8500_GAS_GAUGE] = {
679 .num_ranges = 3,
680 .range = (struct ab8500_reg_range[]) {
681 {
682 .first = 0x00,
683 .last = 0x00,
684 },
685 {
686 .first = 0x07,
687 .last = 0x0A,
688 },
689 {
690 .first = 0x10,
691 .last = 0x14,
692 },
693 },
694 },
695 [AB8500_AUDIO] = {
696 .num_ranges = 1,
697 .range = (struct ab8500_reg_range[]) {
698 {
699 .first = 0x00,
700 .last = 0x83,
701 },
702 },
703 },
704 [AB8500_INTERRUPT] = {
705 .num_ranges = 11,
706 .range = (struct ab8500_reg_range[]) {
707 {
708 .first = 0x00,
709 .last = 0x04,
710 },
711 {
712 .first = 0x06,
713 .last = 0x07,
714 },
715 {
716 .first = 0x09,
717 .last = 0x09,
718 },
719 {
720 .first = 0x0B,
721 .last = 0x0C,
722 },
723 {
724 .first = 0x12,
725 .last = 0x15,
726 },
727 {
728 .first = 0x18,
729 .last = 0x18,
730 },
731 /* Latch registers should not be read here */
732 {
733 .first = 0x40,
734 .last = 0x44,
735 },
736 {
737 .first = 0x46,
738 .last = 0x49,
739 },
740 {
741 .first = 0x4B,
742 .last = 0x4D,
743 },
744 {
745 .first = 0x52,
746 .last = 0x55,
747 },
748 {
749 .first = 0x58,
750 .last = 0x58,
751 },
752 /* LatchHier registers should not be read here */
753 },
754 },
755 [AB8500_RTC] = {
756 .num_ranges = 2,
757 .range = (struct ab8500_reg_range[]) {
758 {
759 .first = 0x00,
760 .last = 0x14,
761 },
762 {
763 .first = 0x16,
764 .last = 0x17,
765 },
766 },
767 },
768 [AB8500_MISC] = {
769 .num_ranges = 8,
770 .range = (struct ab8500_reg_range[]) {
771 {
772 .first = 0x00,
773 .last = 0x06,
774 },
775 {
776 .first = 0x10,
777 .last = 0x16,
778 },
779 {
780 .first = 0x20,
781 .last = 0x26,
782 },
783 {
784 .first = 0x30,
785 .last = 0x36,
786 },
787 {
788 .first = 0x40,
789 .last = 0x46,
790 },
791 {
792 .first = 0x50,
793 .last = 0x50,
794 },
795 {
796 .first = 0x60,
797 .last = 0x6B,
798 },
799 {
800 .first = 0x80,
801 .last = 0x82,
802 },
803 },
804 },
805 [AB8500_DEVELOPMENT] = {
806 .num_ranges = 2,
807 .range = (struct ab8500_reg_range[]) {
808 {
809 .first = 0x00,
810 .last = 0x00,
811 },
812 {
813 .first = 0x05,
814 .last = 0x05,
815 },
816 },
817 },
818 [AB8500_DEBUG] = {
819 .num_ranges = 1,
820 .range = (struct ab8500_reg_range[]) {
821 {
822 .first = 0x05,
823 .last = 0x07,
824 },
825 },
826 },
827 [AB8500_PROD_TEST] = {
828 .num_ranges = 0,
829 .range = NULL,
830 },
831 [AB8500_STE_TEST] = {
832 .num_ranges = 0,
833 .range = NULL,
834 },
835 [AB8500_OTP_EMUL] = {
836 .num_ranges = 1,
837 .range = (struct ab8500_reg_range[]) {
838 {
839 .first = 0x01,
840 .last = 0x15,
841 },
842 },
843 },
844};
845
Sachin Kamat8455eae2013-08-23 17:37:42 +0530846static struct ab8500_prcmu_ranges ab8540_debug_ranges[AB8500_NUM_BANKS] = {
Lee Jones971480f2012-11-19 12:20:03 +0100847 [AB8500_M_FSM_RANK] = {
848 .num_ranges = 1,
849 .range = (struct ab8500_reg_range[]) {
850 {
851 .first = 0x00,
852 .last = 0x0B,
853 },
854 },
855 },
856 [AB8500_SYS_CTRL1_BLOCK] = {
857 .num_ranges = 6,
858 .range = (struct ab8500_reg_range[]) {
859 {
860 .first = 0x00,
861 .last = 0x04,
862 },
863 {
864 .first = 0x42,
865 .last = 0x42,
866 },
867 {
868 .first = 0x50,
869 .last = 0x54,
870 },
871 {
872 .first = 0x57,
873 .last = 0x57,
874 },
875 {
876 .first = 0x80,
877 .last = 0x83,
878 },
879 {
880 .first = 0x90,
881 .last = 0x90,
882 },
883 },
884 },
885 [AB8500_SYS_CTRL2_BLOCK] = {
886 .num_ranges = 5,
887 .range = (struct ab8500_reg_range[]) {
888 {
889 .first = 0x00,
890 .last = 0x0D,
891 },
892 {
893 .first = 0x0F,
894 .last = 0x10,
895 },
896 {
897 .first = 0x20,
898 .last = 0x21,
899 },
900 {
901 .first = 0x32,
902 .last = 0x3C,
903 },
904 {
905 .first = 0x40,
906 .last = 0x42,
907 },
908 },
909 },
910 [AB8500_REGU_CTRL1] = {
911 .num_ranges = 4,
912 .range = (struct ab8500_reg_range[]) {
913 {
914 .first = 0x03,
915 .last = 0x15,
916 },
917 {
918 .first = 0x20,
919 .last = 0x20,
920 },
921 {
922 .first = 0x80,
923 .last = 0x85,
924 },
925 {
926 .first = 0x87,
927 .last = 0x88,
928 },
929 },
930 },
931 [AB8500_REGU_CTRL2] = {
932 .num_ranges = 8,
933 .range = (struct ab8500_reg_range[]) {
934 {
935 .first = 0x00,
936 .last = 0x06,
937 },
938 {
939 .first = 0x08,
940 .last = 0x15,
941 },
942 {
943 .first = 0x17,
944 .last = 0x19,
945 },
946 {
947 .first = 0x1B,
948 .last = 0x1D,
949 },
950 {
951 .first = 0x1F,
952 .last = 0x2F,
953 },
954 {
955 .first = 0x31,
956 .last = 0x3A,
957 },
958 {
959 .first = 0x43,
960 .last = 0x44,
961 },
962 {
963 .first = 0x48,
964 .last = 0x49,
965 },
966 },
967 },
968 [AB8500_USB] = {
969 .num_ranges = 3,
970 .range = (struct ab8500_reg_range[]) {
971 {
972 .first = 0x80,
973 .last = 0x83,
974 },
975 {
976 .first = 0x87,
977 .last = 0x8A,
978 },
979 {
980 .first = 0x91,
981 .last = 0x94,
982 },
983 },
984 },
985 [AB8500_TVOUT] = {
986 .num_ranges = 0,
987 .range = NULL
988 },
989 [AB8500_DBI] = {
990 .num_ranges = 4,
991 .range = (struct ab8500_reg_range[]) {
992 {
993 .first = 0x00,
994 .last = 0x07,
995 },
996 {
997 .first = 0x10,
998 .last = 0x11,
999 },
1000 {
1001 .first = 0x20,
1002 .last = 0x21,
1003 },
1004 {
1005 .first = 0x30,
1006 .last = 0x43,
1007 },
1008 },
1009 },
1010 [AB8500_ECI_AV_ACC] = {
1011 .num_ranges = 2,
1012 .range = (struct ab8500_reg_range[]) {
1013 {
1014 .first = 0x00,
1015 .last = 0x03,
1016 },
1017 {
1018 .first = 0x80,
1019 .last = 0x82,
1020 },
1021 },
1022 },
1023 [AB8500_RESERVED] = {
1024 .num_ranges = 0,
1025 .range = NULL,
1026 },
1027 [AB8500_GPADC] = {
1028 .num_ranges = 4,
1029 .range = (struct ab8500_reg_range[]) {
1030 {
1031 .first = 0x00,
1032 .last = 0x01,
1033 },
1034 {
1035 .first = 0x04,
1036 .last = 0x06,
1037 },
1038 {
1039 .first = 0x09,
1040 .last = 0x0A,
1041 },
1042 {
1043 .first = 0x10,
1044 .last = 0x14,
1045 },
1046 },
1047 },
1048 [AB8500_CHARGER] = {
1049 .num_ranges = 10,
1050 .range = (struct ab8500_reg_range[]) {
1051 {
1052 .first = 0x00,
1053 .last = 0x00,
1054 },
1055 {
1056 .first = 0x02,
1057 .last = 0x05,
1058 },
1059 {
1060 .first = 0x40,
1061 .last = 0x44,
1062 },
1063 {
1064 .first = 0x50,
1065 .last = 0x57,
1066 },
1067 {
1068 .first = 0x60,
1069 .last = 0x60,
1070 },
1071 {
1072 .first = 0x70,
1073 .last = 0x70,
1074 },
1075 {
1076 .first = 0xA0,
1077 .last = 0xA9,
1078 },
1079 {
1080 .first = 0xAF,
1081 .last = 0xB2,
1082 },
1083 {
1084 .first = 0xC0,
1085 .last = 0xC6,
1086 },
1087 {
1088 .first = 0xF5,
1089 .last = 0xF5,
1090 },
1091 },
1092 },
1093 [AB8500_GAS_GAUGE] = {
1094 .num_ranges = 3,
1095 .range = (struct ab8500_reg_range[]) {
1096 {
1097 .first = 0x00,
1098 .last = 0x00,
1099 },
1100 {
1101 .first = 0x07,
1102 .last = 0x0A,
1103 },
1104 {
1105 .first = 0x10,
1106 .last = 0x14,
1107 },
1108 },
1109 },
1110 [AB8500_AUDIO] = {
1111 .num_ranges = 1,
1112 .range = (struct ab8500_reg_range[]) {
1113 {
1114 .first = 0x00,
1115 .last = 0x9f,
1116 },
1117 },
1118 },
1119 [AB8500_INTERRUPT] = {
1120 .num_ranges = 6,
1121 .range = (struct ab8500_reg_range[]) {
1122 {
1123 .first = 0x00,
1124 .last = 0x05,
1125 },
1126 {
1127 .first = 0x0B,
1128 .last = 0x0D,
1129 },
1130 {
1131 .first = 0x12,
1132 .last = 0x20,
1133 },
1134 /* Latch registers should not be read here */
1135 {
1136 .first = 0x40,
1137 .last = 0x45,
1138 },
1139 {
1140 .first = 0x4B,
1141 .last = 0x4D,
1142 },
1143 {
1144 .first = 0x52,
1145 .last = 0x60,
1146 },
1147 /* LatchHier registers should not be read here */
1148 },
1149 },
1150 [AB8500_RTC] = {
1151 .num_ranges = 3,
1152 .range = (struct ab8500_reg_range[]) {
1153 {
1154 .first = 0x00,
1155 .last = 0x07,
1156 },
1157 {
1158 .first = 0x0B,
1159 .last = 0x18,
1160 },
1161 {
1162 .first = 0x20,
1163 .last = 0x25,
1164 },
1165 },
1166 },
1167 [AB8500_MISC] = {
1168 .num_ranges = 9,
1169 .range = (struct ab8500_reg_range[]) {
1170 {
1171 .first = 0x00,
1172 .last = 0x06,
1173 },
1174 {
1175 .first = 0x10,
1176 .last = 0x16,
1177 },
1178 {
1179 .first = 0x20,
1180 .last = 0x26,
1181 },
1182 {
1183 .first = 0x30,
1184 .last = 0x36,
1185 },
1186 {
1187 .first = 0x40,
1188 .last = 0x49,
1189 },
1190 {
1191 .first = 0x50,
1192 .last = 0x50,
1193 },
1194 {
1195 .first = 0x60,
1196 .last = 0x6B,
1197 },
1198 {
1199 .first = 0x70,
1200 .last = 0x74,
1201 },
1202 {
1203 .first = 0x80,
1204 .last = 0x82,
1205 },
1206 },
1207 },
1208 [AB8500_DEVELOPMENT] = {
1209 .num_ranges = 3,
1210 .range = (struct ab8500_reg_range[]) {
1211 {
1212 .first = 0x00,
1213 .last = 0x01,
1214 },
1215 {
1216 .first = 0x06,
1217 .last = 0x06,
1218 },
1219 {
1220 .first = 0x10,
1221 .last = 0x21,
1222 },
1223 },
1224 },
1225 [AB8500_DEBUG] = {
1226 .num_ranges = 3,
1227 .range = (struct ab8500_reg_range[]) {
1228 {
1229 .first = 0x01,
1230 .last = 0x0C,
1231 },
1232 {
1233 .first = 0x0E,
1234 .last = 0x11,
1235 },
1236 {
1237 .first = 0x80,
1238 .last = 0x81,
1239 },
1240 },
1241 },
1242 [AB8500_PROD_TEST] = {
1243 .num_ranges = 0,
1244 .range = NULL,
1245 },
1246 [AB8500_STE_TEST] = {
1247 .num_ranges = 0,
1248 .range = NULL,
1249 },
1250 [AB8500_OTP_EMUL] = {
1251 .num_ranges = 1,
1252 .range = (struct ab8500_reg_range[]) {
1253 {
1254 .first = 0x00,
1255 .last = 0x3F,
1256 },
1257 },
1258 },
1259};
1260
1261
Lee Jones4b8ac082013-01-14 16:10:36 +00001262static irqreturn_t ab8500_debug_handler(int irq, void *data)
1263{
1264 char buf[16];
1265 struct kobject *kobj = (struct kobject *)data;
Mattias Wallin0b337e72010-11-19 17:55:11 +01001266 unsigned int irq_abb = irq - irq_first;
Lee Jones4b8ac082013-01-14 16:10:36 +00001267
Linus Walleijddba25f2012-02-03 11:19:05 +01001268 if (irq_abb < num_irqs)
Mattias Wallin0b337e72010-11-19 17:55:11 +01001269 irq_count[irq_abb]++;
Lee Jones4b8ac082013-01-14 16:10:36 +00001270 /*
1271 * This makes it possible to use poll for events (POLLPRI | POLLERR)
Mattias Wallin0b337e72010-11-19 17:55:11 +01001272 * from userspace on sysfs file named <irq-nr>
Lee Jones4b8ac082013-01-14 16:10:36 +00001273 */
Mattias Wallin0b337e72010-11-19 17:55:11 +01001274 sprintf(buf, "%d", irq);
Lee Jones4b8ac082013-01-14 16:10:36 +00001275 sysfs_notify(kobj, NULL, buf);
1276
1277 return IRQ_HANDLED;
1278}
1279
Mian Yousaf Kaukab42002c62012-01-26 15:39:20 +01001280/* Prints to seq_file or log_buf */
1281static int ab8500_registers_print(struct device *dev, u32 bank,
Joe Perches9a503a72015-02-21 18:53:43 -08001282 struct seq_file *s)
Mattias Wallin5814fc32010-09-13 16:05:04 +02001283{
Mattias Wallind7b9f322010-11-26 13:06:39 +01001284 unsigned int i;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001285
Mattias Wallind7b9f322010-11-26 13:06:39 +01001286 for (i = 0; i < debug_ranges[bank].num_ranges; i++) {
1287 u32 reg;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001288
Mattias Wallind7b9f322010-11-26 13:06:39 +01001289 for (reg = debug_ranges[bank].range[i].first;
1290 reg <= debug_ranges[bank].range[i].last;
1291 reg++) {
1292 u8 value;
1293 int err;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001294
Mattias Wallind7b9f322010-11-26 13:06:39 +01001295 err = abx500_get_register_interruptible(dev,
1296 (u8)bank, (u8)reg, &value);
1297 if (err < 0) {
1298 dev_err(dev, "ab->read fail %d\n", err);
1299 return err;
1300 }
Mattias Wallin5814fc32010-09-13 16:05:04 +02001301
Mian Yousaf Kaukab42002c62012-01-26 15:39:20 +01001302 if (s) {
Joe Perches9a503a72015-02-21 18:53:43 -08001303 seq_printf(s, " [0x%02X/0x%02X]: 0x%02X\n",
1304 bank, reg, value);
Lee Jonesde6a7692015-10-28 09:27:32 +00001305 /*
1306 * Error is not returned here since
1307 * the output is wanted in any case
1308 */
Joe Perches9a503a72015-02-21 18:53:43 -08001309 if (seq_has_overflowed(s))
Mian Yousaf Kaukab42002c62012-01-26 15:39:20 +01001310 return 0;
Mian Yousaf Kaukab42002c62012-01-26 15:39:20 +01001311 } else {
Lee Jones43621752014-07-14 18:29:16 +01001312 dev_info(dev, " [0x%02X/0x%02X]: 0x%02X\n",
1313 bank, reg, value);
Mattias Wallind7b9f322010-11-26 13:06:39 +01001314 }
1315 }
1316 }
Joe Perches9a503a72015-02-21 18:53:43 -08001317
Mattias Wallind7b9f322010-11-26 13:06:39 +01001318 return 0;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001319}
1320
Mian Yousaf Kaukab42002c62012-01-26 15:39:20 +01001321static int ab8500_print_bank_registers(struct seq_file *s, void *p)
1322{
1323 struct device *dev = s->private;
1324 u32 bank = debug_bank;
1325
Lee Jones43621752014-07-14 18:29:16 +01001326 seq_puts(s, AB8500_NAME_STRING " register values:\n");
Mian Yousaf Kaukab42002c62012-01-26 15:39:20 +01001327
Mattias Wallincfc08492012-05-28 15:53:58 +02001328 seq_printf(s, " bank 0x%02X:\n", bank);
Mian Yousaf Kaukab42002c62012-01-26 15:39:20 +01001329
Joe Perches9a503a72015-02-21 18:53:43 -08001330 return ab8500_registers_print(dev, bank, s);
Mian Yousaf Kaukab42002c62012-01-26 15:39:20 +01001331}
1332
Mattias Wallin5814fc32010-09-13 16:05:04 +02001333static int ab8500_registers_open(struct inode *inode, struct file *file)
1334{
Mian Yousaf Kaukab42002c62012-01-26 15:39:20 +01001335 return single_open(file, ab8500_print_bank_registers, inode->i_private);
Mattias Wallin5814fc32010-09-13 16:05:04 +02001336}
1337
1338static const struct file_operations ab8500_registers_fops = {
Mattias Wallind7b9f322010-11-26 13:06:39 +01001339 .open = ab8500_registers_open,
1340 .read = seq_read,
1341 .llseek = seq_lseek,
1342 .release = single_release,
1343 .owner = THIS_MODULE,
Mattias Wallin5814fc32010-09-13 16:05:04 +02001344};
1345
Mian Yousaf Kaukab42002c62012-01-26 15:39:20 +01001346static int ab8500_print_all_banks(struct seq_file *s, void *p)
1347{
1348 struct device *dev = s->private;
1349 unsigned int i;
Mian Yousaf Kaukab42002c62012-01-26 15:39:20 +01001350
Lee Jones43621752014-07-14 18:29:16 +01001351 seq_puts(s, AB8500_NAME_STRING " register values:\n");
Mian Yousaf Kaukab42002c62012-01-26 15:39:20 +01001352
Lee Jones971480f2012-11-19 12:20:03 +01001353 for (i = 0; i < AB8500_NUM_BANKS; i++) {
Joe Perches9a503a72015-02-21 18:53:43 -08001354 int err;
Mian Yousaf Kaukab42002c62012-01-26 15:39:20 +01001355
Joe Perches9a503a72015-02-21 18:53:43 -08001356 seq_printf(s, " bank 0x%02X:\n", i);
1357 err = ab8500_registers_print(dev, i, s);
1358 if (err)
1359 return err;
Mian Yousaf Kaukab42002c62012-01-26 15:39:20 +01001360 }
1361 return 0;
1362}
1363
Mian Yousaf Kaukab1d843a62012-01-27 11:35:41 +01001364/* Dump registers to kernel log */
1365void ab8500_dump_all_banks(struct device *dev)
1366{
1367 unsigned int i;
1368
Lee Jones43621752014-07-14 18:29:16 +01001369 dev_info(dev, "ab8500 register values:\n");
Mian Yousaf Kaukab1d843a62012-01-27 11:35:41 +01001370
1371 for (i = 1; i < AB8500_NUM_BANKS; i++) {
Lee Jones43621752014-07-14 18:29:16 +01001372 dev_info(dev, " bank 0x%02X:\n", i);
Mian Yousaf Kaukab1d843a62012-01-27 11:35:41 +01001373 ab8500_registers_print(dev, i, NULL);
1374 }
1375}
1376
Mian Yousaf Kaukab42002c62012-01-26 15:39:20 +01001377static int ab8500_all_banks_open(struct inode *inode, struct file *file)
1378{
1379 struct seq_file *s;
1380 int err;
1381
1382 err = single_open(file, ab8500_print_all_banks, inode->i_private);
1383 if (!err) {
1384 /* Default buf size in seq_read is not enough */
1385 s = (struct seq_file *)file->private_data;
1386 s->size = (PAGE_SIZE * 2);
1387 s->buf = kmalloc(s->size, GFP_KERNEL);
1388 if (!s->buf) {
1389 single_release(inode, file);
1390 err = -ENOMEM;
1391 }
1392 }
1393 return err;
1394}
1395
1396static const struct file_operations ab8500_all_banks_fops = {
1397 .open = ab8500_all_banks_open,
1398 .read = seq_read,
1399 .llseek = seq_lseek,
1400 .release = single_release,
1401 .owner = THIS_MODULE,
1402};
1403
Mattias Wallin5814fc32010-09-13 16:05:04 +02001404static int ab8500_bank_print(struct seq_file *s, void *p)
1405{
Joe Perches9a503a72015-02-21 18:53:43 -08001406 seq_printf(s, "0x%02X\n", debug_bank);
1407 return 0;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001408}
1409
1410static int ab8500_bank_open(struct inode *inode, struct file *file)
1411{
Mattias Wallind7b9f322010-11-26 13:06:39 +01001412 return single_open(file, ab8500_bank_print, inode->i_private);
Mattias Wallin5814fc32010-09-13 16:05:04 +02001413}
1414
1415static ssize_t ab8500_bank_write(struct file *file,
Mattias Wallind7b9f322010-11-26 13:06:39 +01001416 const char __user *user_buf,
1417 size_t count, loff_t *ppos)
Mattias Wallin5814fc32010-09-13 16:05:04 +02001418{
Mattias Wallind7b9f322010-11-26 13:06:39 +01001419 struct device *dev = ((struct seq_file *)(file->private_data))->private;
Mattias Wallind7b9f322010-11-26 13:06:39 +01001420 unsigned long user_bank;
1421 int err;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001422
Peter Huewe8504d632011-06-06 22:43:32 +02001423 err = kstrtoul_from_user(user_buf, count, 0, &user_bank);
Mattias Wallind7b9f322010-11-26 13:06:39 +01001424 if (err)
Peter Huewe8504d632011-06-06 22:43:32 +02001425 return err;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001426
Mattias Wallind7b9f322010-11-26 13:06:39 +01001427 if (user_bank >= AB8500_NUM_BANKS) {
1428 dev_err(dev, "debugfs error input > number of banks\n");
1429 return -EINVAL;
1430 }
Mattias Wallin5814fc32010-09-13 16:05:04 +02001431
Mattias Wallind7b9f322010-11-26 13:06:39 +01001432 debug_bank = user_bank;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001433
Peter Huewe8504d632011-06-06 22:43:32 +02001434 return count;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001435}
1436
1437static int ab8500_address_print(struct seq_file *s, void *p)
1438{
Joe Perches9a503a72015-02-21 18:53:43 -08001439 seq_printf(s, "0x%02X\n", debug_address);
1440 return 0;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001441}
1442
1443static int ab8500_address_open(struct inode *inode, struct file *file)
1444{
Mattias Wallind7b9f322010-11-26 13:06:39 +01001445 return single_open(file, ab8500_address_print, inode->i_private);
Mattias Wallin5814fc32010-09-13 16:05:04 +02001446}
1447
1448static ssize_t ab8500_address_write(struct file *file,
Lee Jones9f9ba152013-02-26 12:05:15 +00001449 const char __user *user_buf,
1450 size_t count, loff_t *ppos)
Mattias Wallin5814fc32010-09-13 16:05:04 +02001451{
Mattias Wallind7b9f322010-11-26 13:06:39 +01001452 struct device *dev = ((struct seq_file *)(file->private_data))->private;
Mattias Wallind7b9f322010-11-26 13:06:39 +01001453 unsigned long user_address;
1454 int err;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001455
Peter Huewe8504d632011-06-06 22:43:32 +02001456 err = kstrtoul_from_user(user_buf, count, 0, &user_address);
Mattias Wallind7b9f322010-11-26 13:06:39 +01001457 if (err)
Peter Huewe8504d632011-06-06 22:43:32 +02001458 return err;
1459
Mattias Wallind7b9f322010-11-26 13:06:39 +01001460 if (user_address > 0xff) {
1461 dev_err(dev, "debugfs error input > 0xff\n");
1462 return -EINVAL;
1463 }
1464 debug_address = user_address;
srinidhi kasagar7b830ae2012-11-23 15:11:00 +05301465
Peter Huewe8504d632011-06-06 22:43:32 +02001466 return count;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001467}
1468
1469static int ab8500_val_print(struct seq_file *s, void *p)
1470{
Mattias Wallind7b9f322010-11-26 13:06:39 +01001471 struct device *dev = s->private;
1472 int ret;
1473 u8 regvalue;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001474
Mattias Wallind7b9f322010-11-26 13:06:39 +01001475 ret = abx500_get_register_interruptible(dev,
1476 (u8)debug_bank, (u8)debug_address, &regvalue);
1477 if (ret < 0) {
1478 dev_err(dev, "abx500_get_reg fail %d, %d\n",
1479 ret, __LINE__);
1480 return -EINVAL;
1481 }
1482 seq_printf(s, "0x%02X\n", regvalue);
Mattias Wallin5814fc32010-09-13 16:05:04 +02001483
Mattias Wallind7b9f322010-11-26 13:06:39 +01001484 return 0;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001485}
1486
1487static int ab8500_val_open(struct inode *inode, struct file *file)
1488{
Mattias Wallind7b9f322010-11-26 13:06:39 +01001489 return single_open(file, ab8500_val_print, inode->i_private);
Mattias Wallin5814fc32010-09-13 16:05:04 +02001490}
1491
1492static ssize_t ab8500_val_write(struct file *file,
Lee Jones9f9ba152013-02-26 12:05:15 +00001493 const char __user *user_buf,
1494 size_t count, loff_t *ppos)
Mattias Wallin5814fc32010-09-13 16:05:04 +02001495{
Mattias Wallind7b9f322010-11-26 13:06:39 +01001496 struct device *dev = ((struct seq_file *)(file->private_data))->private;
Mattias Wallind7b9f322010-11-26 13:06:39 +01001497 unsigned long user_val;
1498 int err;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001499
Peter Huewe8504d632011-06-06 22:43:32 +02001500 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
Mattias Wallind7b9f322010-11-26 13:06:39 +01001501 if (err)
Peter Huewe8504d632011-06-06 22:43:32 +02001502 return err;
1503
Mattias Wallind7b9f322010-11-26 13:06:39 +01001504 if (user_val > 0xff) {
1505 dev_err(dev, "debugfs error input > 0xff\n");
1506 return -EINVAL;
1507 }
1508 err = abx500_set_register_interruptible(dev,
1509 (u8)debug_bank, debug_address, (u8)user_val);
1510 if (err < 0) {
Lee Jones43621752014-07-14 18:29:16 +01001511 pr_err("abx500_set_reg failed %d, %d", err, __LINE__);
Mattias Wallind7b9f322010-11-26 13:06:39 +01001512 return -EINVAL;
1513 }
Mattias Wallin5814fc32010-09-13 16:05:04 +02001514
Peter Huewe8504d632011-06-06 22:43:32 +02001515 return count;
Mattias Wallin5814fc32010-09-13 16:05:04 +02001516}
1517
carriere etienne0fbce762011-04-08 16:26:36 +02001518/*
Bengt Jonsson8f0eb432012-02-14 13:01:00 +01001519 * Interrupt status
1520 */
1521static u32 num_interrupts[AB8500_MAX_NR_IRQS];
Jonas Aaberg2cf64e22012-05-31 07:57:07 +02001522static u32 num_wake_interrupts[AB8500_MAX_NR_IRQS];
Bengt Jonsson8f0eb432012-02-14 13:01:00 +01001523static int num_interrupt_lines;
1524
1525void ab8500_debug_register_interrupt(int line)
1526{
Lee Jones364c5172016-09-14 11:56:34 +01001527 if (line < num_interrupt_lines)
Bengt Jonsson8f0eb432012-02-14 13:01:00 +01001528 num_interrupts[line]++;
1529}
1530
1531static int ab8500_interrupts_print(struct seq_file *s, void *p)
1532{
1533 int line;
1534
Lee Jones43621752014-07-14 18:29:16 +01001535 seq_puts(s, "name: number: number of: wake:\n");
Bengt Jonsson8f0eb432012-02-14 13:01:00 +01001536
Jonas Aaberg2cf64e22012-05-31 07:57:07 +02001537 for (line = 0; line < num_interrupt_lines; line++) {
1538 struct irq_desc *desc = irq_to_desc(line + irq_first);
Jonas Aaberg2cf64e22012-05-31 07:57:07 +02001539
Joe Perches9a503a72015-02-21 18:53:43 -08001540 seq_printf(s, "%3i: %6i %4i",
1541 line,
Jonas Aaberg2cf64e22012-05-31 07:57:07 +02001542 num_interrupts[line],
1543 num_wake_interrupts[line]);
1544
1545 if (desc && desc->name)
1546 seq_printf(s, "-%-8s", desc->name);
Dan Carpenter7c0b2382013-11-13 10:40:30 +03001547 if (desc && desc->action) {
1548 struct irqaction *action = desc->action;
1549
Jonas Aaberg2cf64e22012-05-31 07:57:07 +02001550 seq_printf(s, " %s", action->name);
1551 while ((action = action->next) != NULL)
1552 seq_printf(s, ", %s", action->name);
1553 }
1554 seq_putc(s, '\n');
1555 }
Bengt Jonsson8f0eb432012-02-14 13:01:00 +01001556
1557 return 0;
1558}
1559
1560static int ab8500_interrupts_open(struct inode *inode, struct file *file)
1561{
1562 return single_open(file, ab8500_interrupts_print, inode->i_private);
1563}
1564
1565/*
carriere etienne0fbce762011-04-08 16:26:36 +02001566 * - HWREG DB8500 formated routines
1567 */
1568static int ab8500_hwreg_print(struct seq_file *s, void *d)
1569{
1570 struct device *dev = s->private;
1571 int ret;
1572 u8 regvalue;
1573
1574 ret = abx500_get_register_interruptible(dev,
1575 (u8)hwreg_cfg.bank, (u8)hwreg_cfg.addr, &regvalue);
1576 if (ret < 0) {
1577 dev_err(dev, "abx500_get_reg fail %d, %d\n",
1578 ret, __LINE__);
1579 return -EINVAL;
1580 }
1581
1582 if (hwreg_cfg.shift >= 0)
1583 regvalue >>= hwreg_cfg.shift;
1584 else
1585 regvalue <<= -hwreg_cfg.shift;
1586 regvalue &= hwreg_cfg.mask;
1587
1588 if (REG_FMT_DEC(&hwreg_cfg))
1589 seq_printf(s, "%d\n", regvalue);
1590 else
1591 seq_printf(s, "0x%02X\n", regvalue);
1592 return 0;
1593}
1594
1595static int ab8500_hwreg_open(struct inode *inode, struct file *file)
1596{
1597 return single_open(file, ab8500_hwreg_print, inode->i_private);
1598}
1599
Lee Jonesc7ebaee2013-02-26 14:03:33 +00001600#define AB8500_SUPPLY_CONTROL_CONFIG_1 0x01
1601#define AB8500_SUPPLY_CONTROL_REG 0x00
1602#define AB8500_FIRST_SIM_REG 0x80
1603#define AB8500_LAST_SIM_REG 0x8B
1604#define AB8505_LAST_SIM_REG 0x8C
1605
1606static int ab8500_print_modem_registers(struct seq_file *s, void *p)
1607{
1608 struct device *dev = s->private;
1609 struct ab8500 *ab8500;
1610 int err;
1611 u8 value;
1612 u8 orig_value;
1613 u32 bank = AB8500_REGU_CTRL2;
1614 u32 last_sim_reg = AB8500_LAST_SIM_REG;
1615 u32 reg;
1616
1617 ab8500 = dev_get_drvdata(dev->parent);
1618 dev_warn(dev, "WARNING! This operation can interfer with modem side\n"
1619 "and should only be done with care\n");
1620
1621 err = abx500_get_register_interruptible(dev,
1622 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG, &orig_value);
1623 if (err < 0) {
1624 dev_err(dev, "ab->read fail %d\n", err);
1625 return err;
1626 }
1627 /* Config 1 will allow APE side to read SIM registers */
1628 err = abx500_set_register_interruptible(dev,
1629 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG,
1630 AB8500_SUPPLY_CONTROL_CONFIG_1);
1631 if (err < 0) {
1632 dev_err(dev, "ab->write fail %d\n", err);
1633 return err;
1634 }
1635
1636 seq_printf(s, " bank 0x%02X:\n", bank);
1637
1638 if (is_ab9540(ab8500) || is_ab8505(ab8500))
1639 last_sim_reg = AB8505_LAST_SIM_REG;
1640
1641 for (reg = AB8500_FIRST_SIM_REG; reg <= last_sim_reg; reg++) {
1642 err = abx500_get_register_interruptible(dev,
1643 bank, reg, &value);
1644 if (err < 0) {
1645 dev_err(dev, "ab->read fail %d\n", err);
1646 return err;
1647 }
Joe Perches9a503a72015-02-21 18:53:43 -08001648 seq_printf(s, " [0x%02X/0x%02X]: 0x%02X\n", bank, reg, value);
Lee Jonesc7ebaee2013-02-26 14:03:33 +00001649 }
1650 err = abx500_set_register_interruptible(dev,
1651 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG, orig_value);
1652 if (err < 0) {
1653 dev_err(dev, "ab->write fail %d\n", err);
1654 return err;
1655 }
1656 return 0;
1657}
1658
1659static int ab8500_modem_open(struct inode *inode, struct file *file)
1660{
Lee Jones43621752014-07-14 18:29:16 +01001661 return single_open(file, ab8500_print_modem_registers,
1662 inode->i_private);
Lee Jonesc7ebaee2013-02-26 14:03:33 +00001663}
1664
1665static const struct file_operations ab8500_modem_fops = {
1666 .open = ab8500_modem_open,
1667 .read = seq_read,
1668 .llseek = seq_lseek,
1669 .release = single_release,
1670 .owner = THIS_MODULE,
1671};
1672
John Beckett1478a312011-05-31 13:54:27 +01001673static int ab8500_gpadc_bat_ctrl_print(struct seq_file *s, void *p)
1674{
1675 int bat_ctrl_raw;
1676 int bat_ctrl_convert;
1677 struct ab8500_gpadc *gpadc;
1678
Philippe Langlais8908c042012-04-18 15:52:59 +02001679 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00001680 bat_ctrl_raw = ab8500_gpadc_read_raw(gpadc, BAT_CTRL,
1681 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01001682 bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc,
Lee Jones73482342013-02-26 10:06:55 +00001683 BAT_CTRL, bat_ctrl_raw);
John Beckett1478a312011-05-31 13:54:27 +01001684
Joe Perches9a503a72015-02-21 18:53:43 -08001685 seq_printf(s, "%d,0x%X\n", bat_ctrl_convert, bat_ctrl_raw);
1686
1687 return 0;
John Beckett1478a312011-05-31 13:54:27 +01001688}
1689
1690static int ab8500_gpadc_bat_ctrl_open(struct inode *inode, struct file *file)
1691{
Lee Jones43621752014-07-14 18:29:16 +01001692 return single_open(file, ab8500_gpadc_bat_ctrl_print,
1693 inode->i_private);
John Beckett1478a312011-05-31 13:54:27 +01001694}
1695
1696static const struct file_operations ab8500_gpadc_bat_ctrl_fops = {
1697 .open = ab8500_gpadc_bat_ctrl_open,
1698 .read = seq_read,
1699 .llseek = seq_lseek,
1700 .release = single_release,
1701 .owner = THIS_MODULE,
1702};
1703
1704static int ab8500_gpadc_btemp_ball_print(struct seq_file *s, void *p)
1705{
1706 int btemp_ball_raw;
1707 int btemp_ball_convert;
1708 struct ab8500_gpadc *gpadc;
1709
Philippe Langlais8908c042012-04-18 15:52:59 +02001710 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00001711 btemp_ball_raw = ab8500_gpadc_read_raw(gpadc, BTEMP_BALL,
1712 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01001713 btemp_ball_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL,
Lee Jones73482342013-02-26 10:06:55 +00001714 btemp_ball_raw);
John Beckett1478a312011-05-31 13:54:27 +01001715
Joe Perches9a503a72015-02-21 18:53:43 -08001716 seq_printf(s, "%d,0x%X\n", btemp_ball_convert, btemp_ball_raw);
1717
1718 return 0;
John Beckett1478a312011-05-31 13:54:27 +01001719}
1720
1721static int ab8500_gpadc_btemp_ball_open(struct inode *inode,
Lee Jones9f9ba152013-02-26 12:05:15 +00001722 struct file *file)
John Beckett1478a312011-05-31 13:54:27 +01001723{
Lee Jones43621752014-07-14 18:29:16 +01001724 return single_open(file, ab8500_gpadc_btemp_ball_print,
1725 inode->i_private);
John Beckett1478a312011-05-31 13:54:27 +01001726}
1727
1728static const struct file_operations ab8500_gpadc_btemp_ball_fops = {
1729 .open = ab8500_gpadc_btemp_ball_open,
1730 .read = seq_read,
1731 .llseek = seq_lseek,
1732 .release = single_release,
1733 .owner = THIS_MODULE,
1734};
1735
1736static int ab8500_gpadc_main_charger_v_print(struct seq_file *s, void *p)
1737{
1738 int main_charger_v_raw;
1739 int main_charger_v_convert;
1740 struct ab8500_gpadc *gpadc;
1741
Philippe Langlais8908c042012-04-18 15:52:59 +02001742 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00001743 main_charger_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_V,
1744 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01001745 main_charger_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
Lee Jones73482342013-02-26 10:06:55 +00001746 MAIN_CHARGER_V, main_charger_v_raw);
John Beckett1478a312011-05-31 13:54:27 +01001747
Joe Perches9a503a72015-02-21 18:53:43 -08001748 seq_printf(s, "%d,0x%X\n", main_charger_v_convert, main_charger_v_raw);
1749
1750 return 0;
John Beckett1478a312011-05-31 13:54:27 +01001751}
1752
1753static int ab8500_gpadc_main_charger_v_open(struct inode *inode,
Lee Jones9f9ba152013-02-26 12:05:15 +00001754 struct file *file)
John Beckett1478a312011-05-31 13:54:27 +01001755{
1756 return single_open(file, ab8500_gpadc_main_charger_v_print,
Lee Jones9f9ba152013-02-26 12:05:15 +00001757 inode->i_private);
John Beckett1478a312011-05-31 13:54:27 +01001758}
1759
1760static const struct file_operations ab8500_gpadc_main_charger_v_fops = {
1761 .open = ab8500_gpadc_main_charger_v_open,
1762 .read = seq_read,
1763 .llseek = seq_lseek,
1764 .release = single_release,
1765 .owner = THIS_MODULE,
1766};
1767
1768static int ab8500_gpadc_acc_detect1_print(struct seq_file *s, void *p)
1769{
1770 int acc_detect1_raw;
1771 int acc_detect1_convert;
1772 struct ab8500_gpadc *gpadc;
1773
Philippe Langlais8908c042012-04-18 15:52:59 +02001774 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00001775 acc_detect1_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT1,
1776 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01001777 acc_detect1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ACC_DETECT1,
Lee Jones73482342013-02-26 10:06:55 +00001778 acc_detect1_raw);
John Beckett1478a312011-05-31 13:54:27 +01001779
Joe Perches9a503a72015-02-21 18:53:43 -08001780 seq_printf(s, "%d,0x%X\n", acc_detect1_convert, acc_detect1_raw);
1781
1782 return 0;
John Beckett1478a312011-05-31 13:54:27 +01001783}
1784
1785static int ab8500_gpadc_acc_detect1_open(struct inode *inode,
Lee Jones9f9ba152013-02-26 12:05:15 +00001786 struct file *file)
John Beckett1478a312011-05-31 13:54:27 +01001787{
1788 return single_open(file, ab8500_gpadc_acc_detect1_print,
Lee Jones9f9ba152013-02-26 12:05:15 +00001789 inode->i_private);
John Beckett1478a312011-05-31 13:54:27 +01001790}
1791
1792static const struct file_operations ab8500_gpadc_acc_detect1_fops = {
1793 .open = ab8500_gpadc_acc_detect1_open,
1794 .read = seq_read,
1795 .llseek = seq_lseek,
1796 .release = single_release,
1797 .owner = THIS_MODULE,
1798};
1799
1800static int ab8500_gpadc_acc_detect2_print(struct seq_file *s, void *p)
1801{
1802 int acc_detect2_raw;
1803 int acc_detect2_convert;
1804 struct ab8500_gpadc *gpadc;
1805
Philippe Langlais8908c042012-04-18 15:52:59 +02001806 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00001807 acc_detect2_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT2,
1808 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01001809 acc_detect2_convert = ab8500_gpadc_ad_to_voltage(gpadc,
Lee Jones73482342013-02-26 10:06:55 +00001810 ACC_DETECT2, acc_detect2_raw);
John Beckett1478a312011-05-31 13:54:27 +01001811
Joe Perches9a503a72015-02-21 18:53:43 -08001812 seq_printf(s, "%d,0x%X\n", acc_detect2_convert, acc_detect2_raw);
1813
1814 return 0;
John Beckett1478a312011-05-31 13:54:27 +01001815}
1816
1817static int ab8500_gpadc_acc_detect2_open(struct inode *inode,
1818 struct file *file)
1819{
1820 return single_open(file, ab8500_gpadc_acc_detect2_print,
Lee Jones9f9ba152013-02-26 12:05:15 +00001821 inode->i_private);
John Beckett1478a312011-05-31 13:54:27 +01001822}
1823
1824static const struct file_operations ab8500_gpadc_acc_detect2_fops = {
1825 .open = ab8500_gpadc_acc_detect2_open,
1826 .read = seq_read,
1827 .llseek = seq_lseek,
1828 .release = single_release,
1829 .owner = THIS_MODULE,
1830};
1831
1832static int ab8500_gpadc_aux1_print(struct seq_file *s, void *p)
1833{
1834 int aux1_raw;
1835 int aux1_convert;
1836 struct ab8500_gpadc *gpadc;
1837
Philippe Langlais8908c042012-04-18 15:52:59 +02001838 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00001839 aux1_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX1,
1840 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01001841 aux1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX1,
Lee Jones73482342013-02-26 10:06:55 +00001842 aux1_raw);
John Beckett1478a312011-05-31 13:54:27 +01001843
Joe Perches9a503a72015-02-21 18:53:43 -08001844 seq_printf(s, "%d,0x%X\n", aux1_convert, aux1_raw);
1845
1846 return 0;
John Beckett1478a312011-05-31 13:54:27 +01001847}
1848
1849static int ab8500_gpadc_aux1_open(struct inode *inode, struct file *file)
1850{
1851 return single_open(file, ab8500_gpadc_aux1_print, inode->i_private);
1852}
1853
1854static const struct file_operations ab8500_gpadc_aux1_fops = {
1855 .open = ab8500_gpadc_aux1_open,
1856 .read = seq_read,
1857 .llseek = seq_lseek,
1858 .release = single_release,
1859 .owner = THIS_MODULE,
1860};
1861
1862static int ab8500_gpadc_aux2_print(struct seq_file *s, void *p)
1863{
1864 int aux2_raw;
1865 int aux2_convert;
1866 struct ab8500_gpadc *gpadc;
1867
Philippe Langlais8908c042012-04-18 15:52:59 +02001868 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00001869 aux2_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX2,
1870 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01001871 aux2_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX2,
Lee Jones73482342013-02-26 10:06:55 +00001872 aux2_raw);
John Beckett1478a312011-05-31 13:54:27 +01001873
Joe Perches9a503a72015-02-21 18:53:43 -08001874 seq_printf(s, "%d,0x%X\n", aux2_convert, aux2_raw);
1875
1876 return 0;
John Beckett1478a312011-05-31 13:54:27 +01001877}
1878
1879static int ab8500_gpadc_aux2_open(struct inode *inode, struct file *file)
1880{
1881 return single_open(file, ab8500_gpadc_aux2_print, inode->i_private);
1882}
1883
1884static const struct file_operations ab8500_gpadc_aux2_fops = {
1885 .open = ab8500_gpadc_aux2_open,
1886 .read = seq_read,
1887 .llseek = seq_lseek,
1888 .release = single_release,
1889 .owner = THIS_MODULE,
1890};
1891
1892static int ab8500_gpadc_main_bat_v_print(struct seq_file *s, void *p)
1893{
1894 int main_bat_v_raw;
1895 int main_bat_v_convert;
1896 struct ab8500_gpadc *gpadc;
1897
Philippe Langlais8908c042012-04-18 15:52:59 +02001898 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00001899 main_bat_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_BAT_V,
1900 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01001901 main_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V,
Lee Jones73482342013-02-26 10:06:55 +00001902 main_bat_v_raw);
John Beckett1478a312011-05-31 13:54:27 +01001903
Joe Perches9a503a72015-02-21 18:53:43 -08001904 seq_printf(s, "%d,0x%X\n", main_bat_v_convert, main_bat_v_raw);
1905
1906 return 0;
John Beckett1478a312011-05-31 13:54:27 +01001907}
1908
1909static int ab8500_gpadc_main_bat_v_open(struct inode *inode,
Lee Jones9f9ba152013-02-26 12:05:15 +00001910 struct file *file)
John Beckett1478a312011-05-31 13:54:27 +01001911{
Lee Jones43621752014-07-14 18:29:16 +01001912 return single_open(file, ab8500_gpadc_main_bat_v_print,
1913 inode->i_private);
John Beckett1478a312011-05-31 13:54:27 +01001914}
1915
1916static const struct file_operations ab8500_gpadc_main_bat_v_fops = {
1917 .open = ab8500_gpadc_main_bat_v_open,
1918 .read = seq_read,
1919 .llseek = seq_lseek,
1920 .release = single_release,
1921 .owner = THIS_MODULE,
1922};
1923
1924static int ab8500_gpadc_vbus_v_print(struct seq_file *s, void *p)
1925{
1926 int vbus_v_raw;
1927 int vbus_v_convert;
1928 struct ab8500_gpadc *gpadc;
1929
Philippe Langlais8908c042012-04-18 15:52:59 +02001930 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00001931 vbus_v_raw = ab8500_gpadc_read_raw(gpadc, VBUS_V,
1932 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01001933 vbus_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, VBUS_V,
Lee Jones73482342013-02-26 10:06:55 +00001934 vbus_v_raw);
John Beckett1478a312011-05-31 13:54:27 +01001935
Joe Perches9a503a72015-02-21 18:53:43 -08001936 seq_printf(s, "%d,0x%X\n", vbus_v_convert, vbus_v_raw);
1937
1938 return 0;
John Beckett1478a312011-05-31 13:54:27 +01001939}
1940
1941static int ab8500_gpadc_vbus_v_open(struct inode *inode, struct file *file)
1942{
1943 return single_open(file, ab8500_gpadc_vbus_v_print, inode->i_private);
1944}
1945
1946static const struct file_operations ab8500_gpadc_vbus_v_fops = {
1947 .open = ab8500_gpadc_vbus_v_open,
1948 .read = seq_read,
1949 .llseek = seq_lseek,
1950 .release = single_release,
1951 .owner = THIS_MODULE,
1952};
1953
1954static int ab8500_gpadc_main_charger_c_print(struct seq_file *s, void *p)
1955{
1956 int main_charger_c_raw;
1957 int main_charger_c_convert;
1958 struct ab8500_gpadc *gpadc;
1959
Philippe Langlais8908c042012-04-18 15:52:59 +02001960 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00001961 main_charger_c_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_C,
1962 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01001963 main_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
Lee Jones73482342013-02-26 10:06:55 +00001964 MAIN_CHARGER_C, main_charger_c_raw);
John Beckett1478a312011-05-31 13:54:27 +01001965
Joe Perches9a503a72015-02-21 18:53:43 -08001966 seq_printf(s, "%d,0x%X\n", main_charger_c_convert, main_charger_c_raw);
1967
1968 return 0;
John Beckett1478a312011-05-31 13:54:27 +01001969}
1970
1971static int ab8500_gpadc_main_charger_c_open(struct inode *inode,
1972 struct file *file)
1973{
1974 return single_open(file, ab8500_gpadc_main_charger_c_print,
Lee Jones9f9ba152013-02-26 12:05:15 +00001975 inode->i_private);
John Beckett1478a312011-05-31 13:54:27 +01001976}
1977
1978static const struct file_operations ab8500_gpadc_main_charger_c_fops = {
1979 .open = ab8500_gpadc_main_charger_c_open,
1980 .read = seq_read,
1981 .llseek = seq_lseek,
1982 .release = single_release,
1983 .owner = THIS_MODULE,
1984};
1985
1986static int ab8500_gpadc_usb_charger_c_print(struct seq_file *s, void *p)
1987{
1988 int usb_charger_c_raw;
1989 int usb_charger_c_convert;
1990 struct ab8500_gpadc *gpadc;
1991
Philippe Langlais8908c042012-04-18 15:52:59 +02001992 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00001993 usb_charger_c_raw = ab8500_gpadc_read_raw(gpadc, USB_CHARGER_C,
1994 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01001995 usb_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
Lee Jones73482342013-02-26 10:06:55 +00001996 USB_CHARGER_C, usb_charger_c_raw);
John Beckett1478a312011-05-31 13:54:27 +01001997
Joe Perches9a503a72015-02-21 18:53:43 -08001998 seq_printf(s, "%d,0x%X\n", usb_charger_c_convert, usb_charger_c_raw);
1999
2000 return 0;
John Beckett1478a312011-05-31 13:54:27 +01002001}
2002
2003static int ab8500_gpadc_usb_charger_c_open(struct inode *inode,
2004 struct file *file)
2005{
2006 return single_open(file, ab8500_gpadc_usb_charger_c_print,
Lee Jones9f9ba152013-02-26 12:05:15 +00002007 inode->i_private);
John Beckett1478a312011-05-31 13:54:27 +01002008}
2009
2010static const struct file_operations ab8500_gpadc_usb_charger_c_fops = {
2011 .open = ab8500_gpadc_usb_charger_c_open,
2012 .read = seq_read,
2013 .llseek = seq_lseek,
2014 .release = single_release,
2015 .owner = THIS_MODULE,
2016};
2017
2018static int ab8500_gpadc_bk_bat_v_print(struct seq_file *s, void *p)
2019{
2020 int bk_bat_v_raw;
2021 int bk_bat_v_convert;
2022 struct ab8500_gpadc *gpadc;
2023
Philippe Langlais8908c042012-04-18 15:52:59 +02002024 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00002025 bk_bat_v_raw = ab8500_gpadc_read_raw(gpadc, BK_BAT_V,
2026 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01002027 bk_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
Lee Jones73482342013-02-26 10:06:55 +00002028 BK_BAT_V, bk_bat_v_raw);
John Beckett1478a312011-05-31 13:54:27 +01002029
Joe Perches9a503a72015-02-21 18:53:43 -08002030 seq_printf(s, "%d,0x%X\n", bk_bat_v_convert, bk_bat_v_raw);
2031
2032 return 0;
John Beckett1478a312011-05-31 13:54:27 +01002033}
2034
2035static int ab8500_gpadc_bk_bat_v_open(struct inode *inode, struct file *file)
2036{
Lee Jones43621752014-07-14 18:29:16 +01002037 return single_open(file, ab8500_gpadc_bk_bat_v_print,
2038 inode->i_private);
John Beckett1478a312011-05-31 13:54:27 +01002039}
2040
2041static const struct file_operations ab8500_gpadc_bk_bat_v_fops = {
2042 .open = ab8500_gpadc_bk_bat_v_open,
2043 .read = seq_read,
2044 .llseek = seq_lseek,
2045 .release = single_release,
2046 .owner = THIS_MODULE,
2047};
2048
2049static int ab8500_gpadc_die_temp_print(struct seq_file *s, void *p)
2050{
2051 int die_temp_raw;
2052 int die_temp_convert;
2053 struct ab8500_gpadc *gpadc;
2054
Philippe Langlais8908c042012-04-18 15:52:59 +02002055 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
Lee Jones73482342013-02-26 10:06:55 +00002056 die_temp_raw = ab8500_gpadc_read_raw(gpadc, DIE_TEMP,
2057 avg_sample, trig_edge, trig_timer, conv_type);
John Beckett1478a312011-05-31 13:54:27 +01002058 die_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, DIE_TEMP,
Lee Jones73482342013-02-26 10:06:55 +00002059 die_temp_raw);
John Beckett1478a312011-05-31 13:54:27 +01002060
Joe Perches9a503a72015-02-21 18:53:43 -08002061 seq_printf(s, "%d,0x%X\n", die_temp_convert, die_temp_raw);
2062
2063 return 0;
John Beckett1478a312011-05-31 13:54:27 +01002064}
2065
2066static int ab8500_gpadc_die_temp_open(struct inode *inode, struct file *file)
2067{
Lee Jones43621752014-07-14 18:29:16 +01002068 return single_open(file, ab8500_gpadc_die_temp_print,
2069 inode->i_private);
John Beckett1478a312011-05-31 13:54:27 +01002070}
2071
2072static const struct file_operations ab8500_gpadc_die_temp_fops = {
2073 .open = ab8500_gpadc_die_temp_open,
2074 .read = seq_read,
2075 .llseek = seq_lseek,
2076 .release = single_release,
2077 .owner = THIS_MODULE,
2078};
2079
Lee Jones127629d2013-02-26 14:04:37 +00002080static int ab8500_gpadc_usb_id_print(struct seq_file *s, void *p)
2081{
2082 int usb_id_raw;
2083 int usb_id_convert;
2084 struct ab8500_gpadc *gpadc;
2085
2086 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2087 usb_id_raw = ab8500_gpadc_read_raw(gpadc, USB_ID,
2088 avg_sample, trig_edge, trig_timer, conv_type);
2089 usb_id_convert = ab8500_gpadc_ad_to_voltage(gpadc, USB_ID,
2090 usb_id_raw);
2091
Joe Perches9a503a72015-02-21 18:53:43 -08002092 seq_printf(s, "%d,0x%X\n", usb_id_convert, usb_id_raw);
2093
2094 return 0;
Lee Jones127629d2013-02-26 14:04:37 +00002095}
2096
2097static int ab8500_gpadc_usb_id_open(struct inode *inode, struct file *file)
2098{
2099 return single_open(file, ab8500_gpadc_usb_id_print, inode->i_private);
2100}
2101
2102static const struct file_operations ab8500_gpadc_usb_id_fops = {
2103 .open = ab8500_gpadc_usb_id_open,
2104 .read = seq_read,
2105 .llseek = seq_lseek,
2106 .release = single_release,
2107 .owner = THIS_MODULE,
2108};
2109
Lee Jonesbc6b4132013-02-26 14:02:31 +00002110static int ab8540_gpadc_xtal_temp_print(struct seq_file *s, void *p)
2111{
2112 int xtal_temp_raw;
2113 int xtal_temp_convert;
2114 struct ab8500_gpadc *gpadc;
2115
2116 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2117 xtal_temp_raw = ab8500_gpadc_read_raw(gpadc, XTAL_TEMP,
2118 avg_sample, trig_edge, trig_timer, conv_type);
2119 xtal_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, XTAL_TEMP,
2120 xtal_temp_raw);
2121
Joe Perches9a503a72015-02-21 18:53:43 -08002122 seq_printf(s, "%d,0x%X\n", xtal_temp_convert, xtal_temp_raw);
2123
2124 return 0;
Lee Jonesbc6b4132013-02-26 14:02:31 +00002125}
2126
2127static int ab8540_gpadc_xtal_temp_open(struct inode *inode, struct file *file)
2128{
2129 return single_open(file, ab8540_gpadc_xtal_temp_print,
Lee Jones9f9ba152013-02-26 12:05:15 +00002130 inode->i_private);
Lee Jonesbc6b4132013-02-26 14:02:31 +00002131}
2132
2133static const struct file_operations ab8540_gpadc_xtal_temp_fops = {
2134 .open = ab8540_gpadc_xtal_temp_open,
2135 .read = seq_read,
2136 .llseek = seq_lseek,
2137 .release = single_release,
2138 .owner = THIS_MODULE,
2139};
2140
2141static int ab8540_gpadc_vbat_true_meas_print(struct seq_file *s, void *p)
2142{
2143 int vbat_true_meas_raw;
2144 int vbat_true_meas_convert;
2145 struct ab8500_gpadc *gpadc;
2146
2147 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2148 vbat_true_meas_raw = ab8500_gpadc_read_raw(gpadc, VBAT_TRUE_MEAS,
2149 avg_sample, trig_edge, trig_timer, conv_type);
Lee Jones43621752014-07-14 18:29:16 +01002150 vbat_true_meas_convert =
2151 ab8500_gpadc_ad_to_voltage(gpadc, VBAT_TRUE_MEAS,
2152 vbat_true_meas_raw);
Lee Jonesbc6b4132013-02-26 14:02:31 +00002153
Joe Perches9a503a72015-02-21 18:53:43 -08002154 seq_printf(s, "%d,0x%X\n", vbat_true_meas_convert, vbat_true_meas_raw);
2155
2156 return 0;
Lee Jonesbc6b4132013-02-26 14:02:31 +00002157}
2158
2159static int ab8540_gpadc_vbat_true_meas_open(struct inode *inode,
2160 struct file *file)
2161{
2162 return single_open(file, ab8540_gpadc_vbat_true_meas_print,
Lee Jones9f9ba152013-02-26 12:05:15 +00002163 inode->i_private);
Lee Jonesbc6b4132013-02-26 14:02:31 +00002164}
2165
2166static const struct file_operations ab8540_gpadc_vbat_true_meas_fops = {
2167 .open = ab8540_gpadc_vbat_true_meas_open,
2168 .read = seq_read,
2169 .llseek = seq_lseek,
2170 .release = single_release,
2171 .owner = THIS_MODULE,
2172};
2173
2174static int ab8540_gpadc_bat_ctrl_and_ibat_print(struct seq_file *s, void *p)
2175{
2176 int bat_ctrl_raw;
2177 int bat_ctrl_convert;
2178 int ibat_raw;
2179 int ibat_convert;
2180 struct ab8500_gpadc *gpadc;
2181
2182 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2183 bat_ctrl_raw = ab8500_gpadc_double_read_raw(gpadc, BAT_CTRL_AND_IBAT,
2184 avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
2185
2186 bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc, BAT_CTRL,
2187 bat_ctrl_raw);
2188 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2189 ibat_raw);
2190
Joe Perches9a503a72015-02-21 18:53:43 -08002191 seq_printf(s,
2192 "%d,0x%X\n"
2193 "%d,0x%X\n",
2194 bat_ctrl_convert, bat_ctrl_raw,
2195 ibat_convert, ibat_raw);
2196
2197 return 0;
Lee Jonesbc6b4132013-02-26 14:02:31 +00002198}
2199
2200static int ab8540_gpadc_bat_ctrl_and_ibat_open(struct inode *inode,
2201 struct file *file)
2202{
2203 return single_open(file, ab8540_gpadc_bat_ctrl_and_ibat_print,
Lee Jones9f9ba152013-02-26 12:05:15 +00002204 inode->i_private);
Lee Jonesbc6b4132013-02-26 14:02:31 +00002205}
2206
2207static const struct file_operations ab8540_gpadc_bat_ctrl_and_ibat_fops = {
2208 .open = ab8540_gpadc_bat_ctrl_and_ibat_open,
2209 .read = seq_read,
2210 .llseek = seq_lseek,
2211 .release = single_release,
2212 .owner = THIS_MODULE,
2213};
2214
2215static int ab8540_gpadc_vbat_meas_and_ibat_print(struct seq_file *s, void *p)
2216{
2217 int vbat_meas_raw;
2218 int vbat_meas_convert;
2219 int ibat_raw;
2220 int ibat_convert;
2221 struct ab8500_gpadc *gpadc;
2222
2223 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2224 vbat_meas_raw = ab8500_gpadc_double_read_raw(gpadc, VBAT_MEAS_AND_IBAT,
2225 avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
2226 vbat_meas_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V,
2227 vbat_meas_raw);
2228 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2229 ibat_raw);
2230
Joe Perches9a503a72015-02-21 18:53:43 -08002231 seq_printf(s,
2232 "%d,0x%X\n"
2233 "%d,0x%X\n",
2234 vbat_meas_convert, vbat_meas_raw,
2235 ibat_convert, ibat_raw);
2236
2237 return 0;
Lee Jonesbc6b4132013-02-26 14:02:31 +00002238}
2239
2240static int ab8540_gpadc_vbat_meas_and_ibat_open(struct inode *inode,
2241 struct file *file)
2242{
2243 return single_open(file, ab8540_gpadc_vbat_meas_and_ibat_print,
Lee Jones9f9ba152013-02-26 12:05:15 +00002244 inode->i_private);
Lee Jonesbc6b4132013-02-26 14:02:31 +00002245}
2246
2247static const struct file_operations ab8540_gpadc_vbat_meas_and_ibat_fops = {
2248 .open = ab8540_gpadc_vbat_meas_and_ibat_open,
2249 .read = seq_read,
2250 .llseek = seq_lseek,
2251 .release = single_release,
2252 .owner = THIS_MODULE,
2253};
2254
Lee Jones43621752014-07-14 18:29:16 +01002255static int ab8540_gpadc_vbat_true_meas_and_ibat_print(struct seq_file *s,
2256 void *p)
Lee Jonesbc6b4132013-02-26 14:02:31 +00002257{
2258 int vbat_true_meas_raw;
2259 int vbat_true_meas_convert;
2260 int ibat_raw;
2261 int ibat_convert;
2262 struct ab8500_gpadc *gpadc;
2263
2264 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2265 vbat_true_meas_raw = ab8500_gpadc_double_read_raw(gpadc,
2266 VBAT_TRUE_MEAS_AND_IBAT, avg_sample, trig_edge,
2267 trig_timer, conv_type, &ibat_raw);
2268 vbat_true_meas_convert = ab8500_gpadc_ad_to_voltage(gpadc,
2269 VBAT_TRUE_MEAS, vbat_true_meas_raw);
2270 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2271 ibat_raw);
2272
Joe Perches9a503a72015-02-21 18:53:43 -08002273 seq_printf(s,
2274 "%d,0x%X\n"
2275 "%d,0x%X\n",
2276 vbat_true_meas_convert, vbat_true_meas_raw,
2277 ibat_convert, ibat_raw);
2278
2279 return 0;
Lee Jonesbc6b4132013-02-26 14:02:31 +00002280}
2281
2282static int ab8540_gpadc_vbat_true_meas_and_ibat_open(struct inode *inode,
2283 struct file *file)
2284{
2285 return single_open(file, ab8540_gpadc_vbat_true_meas_and_ibat_print,
Lee Jones9f9ba152013-02-26 12:05:15 +00002286 inode->i_private);
Lee Jonesbc6b4132013-02-26 14:02:31 +00002287}
2288
Lee Jones43621752014-07-14 18:29:16 +01002289static const struct file_operations
2290ab8540_gpadc_vbat_true_meas_and_ibat_fops = {
Lee Jonesbc6b4132013-02-26 14:02:31 +00002291 .open = ab8540_gpadc_vbat_true_meas_and_ibat_open,
2292 .read = seq_read,
2293 .llseek = seq_lseek,
2294 .release = single_release,
2295 .owner = THIS_MODULE,
2296};
2297
2298static int ab8540_gpadc_bat_temp_and_ibat_print(struct seq_file *s, void *p)
2299{
2300 int bat_temp_raw;
2301 int bat_temp_convert;
2302 int ibat_raw;
2303 int ibat_convert;
2304 struct ab8500_gpadc *gpadc;
2305
2306 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2307 bat_temp_raw = ab8500_gpadc_double_read_raw(gpadc, BAT_TEMP_AND_IBAT,
2308 avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
2309 bat_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL,
2310 bat_temp_raw);
2311 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2312 ibat_raw);
2313
Joe Perches9a503a72015-02-21 18:53:43 -08002314 seq_printf(s,
2315 "%d,0x%X\n"
2316 "%d,0x%X\n",
2317 bat_temp_convert, bat_temp_raw,
2318 ibat_convert, ibat_raw);
2319
2320 return 0;
Lee Jonesbc6b4132013-02-26 14:02:31 +00002321}
2322
2323static int ab8540_gpadc_bat_temp_and_ibat_open(struct inode *inode,
2324 struct file *file)
2325{
2326 return single_open(file, ab8540_gpadc_bat_temp_and_ibat_print,
Lee Jones9f9ba152013-02-26 12:05:15 +00002327 inode->i_private);
Lee Jonesbc6b4132013-02-26 14:02:31 +00002328}
2329
2330static const struct file_operations ab8540_gpadc_bat_temp_and_ibat_fops = {
2331 .open = ab8540_gpadc_bat_temp_and_ibat_open,
2332 .read = seq_read,
2333 .llseek = seq_lseek,
2334 .release = single_release,
2335 .owner = THIS_MODULE,
2336};
2337
2338static int ab8540_gpadc_otp_cal_print(struct seq_file *s, void *p)
2339{
2340 struct ab8500_gpadc *gpadc;
2341 u16 vmain_l, vmain_h, btemp_l, btemp_h;
2342 u16 vbat_l, vbat_h, ibat_l, ibat_h;
2343
2344 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2345 ab8540_gpadc_get_otp(gpadc, &vmain_l, &vmain_h, &btemp_l, &btemp_h,
2346 &vbat_l, &vbat_h, &ibat_l, &ibat_h);
Joe Perches9a503a72015-02-21 18:53:43 -08002347 seq_printf(s,
2348 "VMAIN_L:0x%X\n"
2349 "VMAIN_H:0x%X\n"
2350 "BTEMP_L:0x%X\n"
2351 "BTEMP_H:0x%X\n"
2352 "VBAT_L:0x%X\n"
2353 "VBAT_H:0x%X\n"
2354 "IBAT_L:0x%X\n"
2355 "IBAT_H:0x%X\n",
2356 vmain_l, vmain_h, btemp_l, btemp_h,
2357 vbat_l, vbat_h, ibat_l, ibat_h);
2358
2359 return 0;
Lee Jonesbc6b4132013-02-26 14:02:31 +00002360}
2361
2362static int ab8540_gpadc_otp_cal_open(struct inode *inode, struct file *file)
2363{
2364 return single_open(file, ab8540_gpadc_otp_cal_print, inode->i_private);
2365}
2366
2367static const struct file_operations ab8540_gpadc_otp_calib_fops = {
2368 .open = ab8540_gpadc_otp_cal_open,
2369 .read = seq_read,
2370 .llseek = seq_lseek,
2371 .release = single_release,
2372 .owner = THIS_MODULE,
2373};
2374
Lee Jones73482342013-02-26 10:06:55 +00002375static int ab8500_gpadc_avg_sample_print(struct seq_file *s, void *p)
2376{
Joe Perches9a503a72015-02-21 18:53:43 -08002377 seq_printf(s, "%d\n", avg_sample);
2378
2379 return 0;
Lee Jones73482342013-02-26 10:06:55 +00002380}
2381
2382static int ab8500_gpadc_avg_sample_open(struct inode *inode, struct file *file)
2383{
2384 return single_open(file, ab8500_gpadc_avg_sample_print,
Lee Jones9f9ba152013-02-26 12:05:15 +00002385 inode->i_private);
Lee Jones73482342013-02-26 10:06:55 +00002386}
2387
2388static ssize_t ab8500_gpadc_avg_sample_write(struct file *file,
2389 const char __user *user_buf,
2390 size_t count, loff_t *ppos)
2391{
2392 struct device *dev = ((struct seq_file *)(file->private_data))->private;
Lee Jones73482342013-02-26 10:06:55 +00002393 unsigned long user_avg_sample;
2394 int err;
2395
srinidhi kasagar7b830ae2012-11-23 15:11:00 +05302396 err = kstrtoul_from_user(user_buf, count, 0, &user_avg_sample);
Lee Jones73482342013-02-26 10:06:55 +00002397 if (err)
srinidhi kasagar7b830ae2012-11-23 15:11:00 +05302398 return err;
2399
Lee Jones73482342013-02-26 10:06:55 +00002400 if ((user_avg_sample == SAMPLE_1) || (user_avg_sample == SAMPLE_4)
2401 || (user_avg_sample == SAMPLE_8)
2402 || (user_avg_sample == SAMPLE_16)) {
2403 avg_sample = (u8) user_avg_sample;
2404 } else {
Lee Jones43621752014-07-14 18:29:16 +01002405 dev_err(dev,
2406 "debugfs err input: should be egal to 1, 4, 8 or 16\n");
Lee Jones73482342013-02-26 10:06:55 +00002407 return -EINVAL;
2408 }
srinidhi kasagar7b830ae2012-11-23 15:11:00 +05302409
2410 return count;
Lee Jones73482342013-02-26 10:06:55 +00002411}
2412
2413static const struct file_operations ab8500_gpadc_avg_sample_fops = {
2414 .open = ab8500_gpadc_avg_sample_open,
2415 .read = seq_read,
2416 .write = ab8500_gpadc_avg_sample_write,
2417 .llseek = seq_lseek,
2418 .release = single_release,
2419 .owner = THIS_MODULE,
2420};
2421
2422static int ab8500_gpadc_trig_edge_print(struct seq_file *s, void *p)
2423{
Joe Perches9a503a72015-02-21 18:53:43 -08002424 seq_printf(s, "%d\n", trig_edge);
2425
2426 return 0;
Lee Jones73482342013-02-26 10:06:55 +00002427}
2428
2429static int ab8500_gpadc_trig_edge_open(struct inode *inode, struct file *file)
2430{
2431 return single_open(file, ab8500_gpadc_trig_edge_print,
Lee Jones9f9ba152013-02-26 12:05:15 +00002432 inode->i_private);
Lee Jones73482342013-02-26 10:06:55 +00002433}
2434
2435static ssize_t ab8500_gpadc_trig_edge_write(struct file *file,
2436 const char __user *user_buf,
2437 size_t count, loff_t *ppos)
2438{
2439 struct device *dev = ((struct seq_file *)(file->private_data))->private;
Lee Jones73482342013-02-26 10:06:55 +00002440 unsigned long user_trig_edge;
2441 int err;
2442
srinidhi kasagar7b830ae2012-11-23 15:11:00 +05302443 err = kstrtoul_from_user(user_buf, count, 0, &user_trig_edge);
Lee Jones73482342013-02-26 10:06:55 +00002444 if (err)
srinidhi kasagar7b830ae2012-11-23 15:11:00 +05302445 return err;
2446
Lee Jones73482342013-02-26 10:06:55 +00002447 if ((user_trig_edge == RISING_EDGE)
2448 || (user_trig_edge == FALLING_EDGE)) {
2449 trig_edge = (u8) user_trig_edge;
2450 } else {
2451 dev_err(dev, "Wrong input:\n"
2452 "Enter 0. Rising edge\n"
2453 "Enter 1. Falling edge\n");
2454 return -EINVAL;
2455 }
srinidhi kasagar7b830ae2012-11-23 15:11:00 +05302456
2457 return count;
Lee Jones73482342013-02-26 10:06:55 +00002458}
2459
2460static const struct file_operations ab8500_gpadc_trig_edge_fops = {
2461 .open = ab8500_gpadc_trig_edge_open,
2462 .read = seq_read,
2463 .write = ab8500_gpadc_trig_edge_write,
2464 .llseek = seq_lseek,
2465 .release = single_release,
2466 .owner = THIS_MODULE,
2467};
2468
2469static int ab8500_gpadc_trig_timer_print(struct seq_file *s, void *p)
2470{
Joe Perches9a503a72015-02-21 18:53:43 -08002471 seq_printf(s, "%d\n", trig_timer);
2472
2473 return 0;
Lee Jones73482342013-02-26 10:06:55 +00002474}
2475
2476static int ab8500_gpadc_trig_timer_open(struct inode *inode, struct file *file)
2477{
2478 return single_open(file, ab8500_gpadc_trig_timer_print,
Lee Jones9f9ba152013-02-26 12:05:15 +00002479 inode->i_private);
Lee Jones73482342013-02-26 10:06:55 +00002480}
2481
2482static ssize_t ab8500_gpadc_trig_timer_write(struct file *file,
2483 const char __user *user_buf,
2484 size_t count, loff_t *ppos)
2485{
2486 struct device *dev = ((struct seq_file *)(file->private_data))->private;
Lee Jones73482342013-02-26 10:06:55 +00002487 unsigned long user_trig_timer;
2488 int err;
2489
srinidhi kasagar7b830ae2012-11-23 15:11:00 +05302490 err = kstrtoul_from_user(user_buf, count, 0, &user_trig_timer);
Lee Jones73482342013-02-26 10:06:55 +00002491 if (err)
srinidhi kasagar7b830ae2012-11-23 15:11:00 +05302492 return err;
2493
Lee Jonesc3f27a22014-07-02 11:22:10 +01002494 if (user_trig_timer & ~0xFF) {
2495 dev_err(dev,
Colin Ian Kingc094cf12016-04-25 22:42:25 +01002496 "debugfs error input: should be between 0 to 255\n");
Lee Jones73482342013-02-26 10:06:55 +00002497 return -EINVAL;
2498 }
srinidhi kasagar7b830ae2012-11-23 15:11:00 +05302499
Lee Jonesc3f27a22014-07-02 11:22:10 +01002500 trig_timer = (u8) user_trig_timer;
2501
srinidhi kasagar7b830ae2012-11-23 15:11:00 +05302502 return count;
Lee Jones73482342013-02-26 10:06:55 +00002503}
2504
2505static const struct file_operations ab8500_gpadc_trig_timer_fops = {
2506 .open = ab8500_gpadc_trig_timer_open,
2507 .read = seq_read,
2508 .write = ab8500_gpadc_trig_timer_write,
2509 .llseek = seq_lseek,
2510 .release = single_release,
2511 .owner = THIS_MODULE,
2512};
2513
2514static int ab8500_gpadc_conv_type_print(struct seq_file *s, void *p)
2515{
Joe Perches9a503a72015-02-21 18:53:43 -08002516 seq_printf(s, "%d\n", conv_type);
2517
2518 return 0;
Lee Jones73482342013-02-26 10:06:55 +00002519}
2520
2521static int ab8500_gpadc_conv_type_open(struct inode *inode, struct file *file)
2522{
2523 return single_open(file, ab8500_gpadc_conv_type_print,
Lee Jones9f9ba152013-02-26 12:05:15 +00002524 inode->i_private);
Lee Jones73482342013-02-26 10:06:55 +00002525}
2526
2527static ssize_t ab8500_gpadc_conv_type_write(struct file *file,
2528 const char __user *user_buf,
2529 size_t count, loff_t *ppos)
2530{
2531 struct device *dev = ((struct seq_file *)(file->private_data))->private;
Lee Jones73482342013-02-26 10:06:55 +00002532 unsigned long user_conv_type;
2533 int err;
2534
srinidhi kasagar7b830ae2012-11-23 15:11:00 +05302535 err = kstrtoul_from_user(user_buf, count, 0, &user_conv_type);
Lee Jones73482342013-02-26 10:06:55 +00002536 if (err)
srinidhi kasagar7b830ae2012-11-23 15:11:00 +05302537 return err;
2538
Lee Jones73482342013-02-26 10:06:55 +00002539 if ((user_conv_type == ADC_SW)
2540 || (user_conv_type == ADC_HW)) {
2541 conv_type = (u8) user_conv_type;
2542 } else {
2543 dev_err(dev, "Wrong input:\n"
2544 "Enter 0. ADC SW conversion\n"
2545 "Enter 1. ADC HW conversion\n");
2546 return -EINVAL;
2547 }
srinidhi kasagar7b830ae2012-11-23 15:11:00 +05302548
2549 return count;
Lee Jones73482342013-02-26 10:06:55 +00002550}
2551
2552static const struct file_operations ab8500_gpadc_conv_type_fops = {
2553 .open = ab8500_gpadc_conv_type_open,
2554 .read = seq_read,
2555 .write = ab8500_gpadc_conv_type_write,
2556 .llseek = seq_lseek,
2557 .release = single_release,
2558 .owner = THIS_MODULE,
2559};
2560
carriere etienne0fbce762011-04-08 16:26:36 +02002561/*
2562 * return length of an ASCII numerical value, 0 is string is not a
2563 * numerical value.
2564 * string shall start at value 1st char.
2565 * string can be tailed with \0 or space or newline chars only.
2566 * value can be decimal or hexadecimal (prefixed 0x or 0X).
2567 */
2568static int strval_len(char *b)
2569{
2570 char *s = b;
Lee Jones43621752014-07-14 18:29:16 +01002571
carriere etienne0fbce762011-04-08 16:26:36 +02002572 if ((*s == '0') && ((*(s+1) == 'x') || (*(s+1) == 'X'))) {
2573 s += 2;
2574 for (; *s && (*s != ' ') && (*s != '\n'); s++) {
2575 if (!isxdigit(*s))
2576 return 0;
2577 }
2578 } else {
2579 if (*s == '-')
2580 s++;
2581 for (; *s && (*s != ' ') && (*s != '\n'); s++) {
2582 if (!isdigit(*s))
2583 return 0;
2584 }
2585 }
2586 return (int) (s-b);
2587}
2588
2589/*
2590 * parse hwreg input data.
2591 * update global hwreg_cfg only if input data syntax is ok.
2592 */
2593static ssize_t hwreg_common_write(char *b, struct hwreg_cfg *cfg,
2594 struct device *dev)
2595{
2596 uint write, val = 0;
2597 u8 regvalue;
2598 int ret;
2599 struct hwreg_cfg loc = {
2600 .bank = 0, /* default: invalid phys addr */
2601 .addr = 0, /* default: invalid phys addr */
2602 .fmt = 0, /* default: 32bit access, hex output */
2603 .mask = 0xFFFFFFFF, /* default: no mask */
2604 .shift = 0, /* default: no bit shift */
2605 };
2606
2607 /* read or write ? */
2608 if (!strncmp(b, "read ", 5)) {
2609 write = 0;
2610 b += 5;
2611 } else if (!strncmp(b, "write ", 6)) {
2612 write = 1;
2613 b += 6;
2614 } else
2615 return -EINVAL;
2616
2617 /* OPTIONS -l|-w|-b -s -m -o */
2618 while ((*b == ' ') || (*b == '-')) {
2619 if (*(b-1) != ' ') {
2620 b++;
2621 continue;
2622 }
2623 if ((!strncmp(b, "-d ", 3)) ||
2624 (!strncmp(b, "-dec ", 5))) {
2625 b += (*(b+2) == ' ') ? 3 : 5;
2626 loc.fmt |= (1<<0);
2627 } else if ((!strncmp(b, "-h ", 3)) ||
2628 (!strncmp(b, "-hex ", 5))) {
2629 b += (*(b+2) == ' ') ? 3 : 5;
2630 loc.fmt &= ~(1<<0);
2631 } else if ((!strncmp(b, "-m ", 3)) ||
2632 (!strncmp(b, "-mask ", 6))) {
2633 b += (*(b+2) == ' ') ? 3 : 6;
2634 if (strval_len(b) == 0)
2635 return -EINVAL;
Lee Jones43621752014-07-14 18:29:16 +01002636 ret = kstrtoul(b, 0, &loc.mask);
2637 if (ret)
2638 return ret;
carriere etienne0fbce762011-04-08 16:26:36 +02002639 } else if ((!strncmp(b, "-s ", 3)) ||
2640 (!strncmp(b, "-shift ", 7))) {
2641 b += (*(b+2) == ' ') ? 3 : 7;
2642 if (strval_len(b) == 0)
2643 return -EINVAL;
Lee Jones43621752014-07-14 18:29:16 +01002644 ret = kstrtol(b, 0, &loc.shift);
2645 if (ret)
2646 return ret;
carriere etienne0fbce762011-04-08 16:26:36 +02002647 } else {
2648 return -EINVAL;
2649 }
2650 }
2651 /* get arg BANK and ADDRESS */
2652 if (strval_len(b) == 0)
2653 return -EINVAL;
Lee Jones43621752014-07-14 18:29:16 +01002654 ret = kstrtouint(b, 0, &loc.bank);
2655 if (ret)
2656 return ret;
carriere etienne0fbce762011-04-08 16:26:36 +02002657 while (*b == ' ')
2658 b++;
2659 if (strval_len(b) == 0)
2660 return -EINVAL;
Lee Jones43621752014-07-14 18:29:16 +01002661 ret = kstrtoul(b, 0, &loc.addr);
2662 if (ret)
2663 return ret;
carriere etienne0fbce762011-04-08 16:26:36 +02002664
2665 if (write) {
2666 while (*b == ' ')
2667 b++;
2668 if (strval_len(b) == 0)
2669 return -EINVAL;
Lee Jones43621752014-07-14 18:29:16 +01002670 ret = kstrtouint(b, 0, &val);
2671 if (ret)
2672 return ret;
carriere etienne0fbce762011-04-08 16:26:36 +02002673 }
2674
2675 /* args are ok, update target cfg (mainly for read) */
2676 *cfg = loc;
2677
2678#ifdef ABB_HWREG_DEBUG
Lee Jonesde6a7692015-10-28 09:27:32 +00002679 pr_warn("HWREG request: %s, %s,\n", (write) ? "write" : "read",
2680 REG_FMT_DEC(cfg) ? "decimal" : "hexa");
2681 pr_warn(" addr=0x%08X, mask=0x%X, shift=%d" "value=0x%X\n",
Lee Jones43621752014-07-14 18:29:16 +01002682 cfg->addr, cfg->mask, cfg->shift, val);
carriere etienne0fbce762011-04-08 16:26:36 +02002683#endif
2684
2685 if (!write)
2686 return 0;
2687
2688 ret = abx500_get_register_interruptible(dev,
2689 (u8)cfg->bank, (u8)cfg->addr, &regvalue);
2690 if (ret < 0) {
2691 dev_err(dev, "abx500_get_reg fail %d, %d\n",
2692 ret, __LINE__);
2693 return -EINVAL;
2694 }
2695
2696 if (cfg->shift >= 0) {
2697 regvalue &= ~(cfg->mask << (cfg->shift));
2698 val = (val & cfg->mask) << (cfg->shift);
2699 } else {
2700 regvalue &= ~(cfg->mask >> (-cfg->shift));
2701 val = (val & cfg->mask) >> (-cfg->shift);
2702 }
2703 val = val | regvalue;
2704
2705 ret = abx500_set_register_interruptible(dev,
2706 (u8)cfg->bank, (u8)cfg->addr, (u8)val);
2707 if (ret < 0) {
2708 pr_err("abx500_set_reg failed %d, %d", ret, __LINE__);
2709 return -EINVAL;
2710 }
2711
2712 return 0;
2713}
2714
2715static ssize_t ab8500_hwreg_write(struct file *file,
2716 const char __user *user_buf, size_t count, loff_t *ppos)
2717{
2718 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2719 char buf[128];
2720 int buf_size, ret;
2721
2722 /* Get userspace string and assure termination */
2723 buf_size = min(count, (sizeof(buf)-1));
2724 if (copy_from_user(buf, user_buf, buf_size))
2725 return -EFAULT;
2726 buf[buf_size] = 0;
2727
2728 /* get args and process */
2729 ret = hwreg_common_write(buf, &hwreg_cfg, dev);
2730 return (ret) ? ret : buf_size;
2731}
2732
2733/*
2734 * - irq subscribe/unsubscribe stuff
2735 */
Lee Jones4b8ac082013-01-14 16:10:36 +00002736static int ab8500_subscribe_unsubscribe_print(struct seq_file *s, void *p)
2737{
2738 seq_printf(s, "%d\n", irq_first);
2739
2740 return 0;
2741}
2742
2743static int ab8500_subscribe_unsubscribe_open(struct inode *inode,
2744 struct file *file)
2745{
2746 return single_open(file, ab8500_subscribe_unsubscribe_print,
Lee Jones9f9ba152013-02-26 12:05:15 +00002747 inode->i_private);
Lee Jones4b8ac082013-01-14 16:10:36 +00002748}
2749
2750/*
Mattias Wallin0b337e72010-11-19 17:55:11 +01002751 * Userspace should use poll() on this file. When an event occur
Lee Jones4b8ac082013-01-14 16:10:36 +00002752 * the blocking poll will be released.
2753 */
2754static ssize_t show_irq(struct device *dev,
2755 struct device_attribute *attr, char *buf)
2756{
Mattias Wallin0b337e72010-11-19 17:55:11 +01002757 unsigned long name;
2758 unsigned int irq_index;
2759 int err;
Lee Jones4b8ac082013-01-14 16:10:36 +00002760
Jingoo Han8420a242013-06-04 13:11:50 +09002761 err = kstrtoul(attr->attr.name, 0, &name);
Mattias Wallin0b337e72010-11-19 17:55:11 +01002762 if (err)
2763 return err;
2764
2765 irq_index = name - irq_first;
Linus Walleijddba25f2012-02-03 11:19:05 +01002766 if (irq_index >= num_irqs)
Mattias Wallin0b337e72010-11-19 17:55:11 +01002767 return -EINVAL;
Lee Jonesc3f27a22014-07-02 11:22:10 +01002768
2769 return sprintf(buf, "%u\n", irq_count[irq_index]);
Mattias Wallin0b337e72010-11-19 17:55:11 +01002770}
Lee Jones4b8ac082013-01-14 16:10:36 +00002771
2772static ssize_t ab8500_subscribe_write(struct file *file,
2773 const char __user *user_buf,
2774 size_t count, loff_t *ppos)
2775{
2776 struct device *dev = ((struct seq_file *)(file->private_data))->private;
Lee Jones4b8ac082013-01-14 16:10:36 +00002777 unsigned long user_val;
2778 int err;
Mattias Wallin0b337e72010-11-19 17:55:11 +01002779 unsigned int irq_index;
Lee Jones4b8ac082013-01-14 16:10:36 +00002780
srinidhi kasagar7b830ae2012-11-23 15:11:00 +05302781 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
Lee Jones4b8ac082013-01-14 16:10:36 +00002782 if (err)
srinidhi kasagar7b830ae2012-11-23 15:11:00 +05302783 return err;
2784
Lee Jones4b8ac082013-01-14 16:10:36 +00002785 if (user_val < irq_first) {
2786 dev_err(dev, "debugfs error input < %d\n", irq_first);
2787 return -EINVAL;
2788 }
2789 if (user_val > irq_last) {
2790 dev_err(dev, "debugfs error input > %d\n", irq_last);
2791 return -EINVAL;
2792 }
2793
Mattias Wallin0b337e72010-11-19 17:55:11 +01002794 irq_index = user_val - irq_first;
Linus Walleijddba25f2012-02-03 11:19:05 +01002795 if (irq_index >= num_irqs)
Mattias Wallin0b337e72010-11-19 17:55:11 +01002796 return -EINVAL;
2797
Lee Jones4b8ac082013-01-14 16:10:36 +00002798 /*
Mattias Wallin0b337e72010-11-19 17:55:11 +01002799 * This will create a sysfs file named <irq-nr> which userspace can
Lee Jones4b8ac082013-01-14 16:10:36 +00002800 * use to select or poll and get the AB8500 events
2801 */
Mattias Wallin0b337e72010-11-19 17:55:11 +01002802 dev_attr[irq_index] = kmalloc(sizeof(struct device_attribute),
2803 GFP_KERNEL);
Lee Jonesf840e232013-07-19 08:44:50 +01002804 if (!dev_attr[irq_index])
2805 return -ENOMEM;
2806
srinidhi kasagar7b830ae2012-11-23 15:11:00 +05302807 event_name[irq_index] = kmalloc(count, GFP_KERNEL);
Lee Jonesd551c4c2013-07-19 08:53:24 +01002808 if (!event_name[irq_index])
2809 return -ENOMEM;
2810
Mattias Wallin0b337e72010-11-19 17:55:11 +01002811 sprintf(event_name[irq_index], "%lu", user_val);
2812 dev_attr[irq_index]->show = show_irq;
2813 dev_attr[irq_index]->store = NULL;
2814 dev_attr[irq_index]->attr.name = event_name[irq_index];
2815 dev_attr[irq_index]->attr.mode = S_IRUGO;
2816 err = sysfs_create_file(&dev->kobj, &dev_attr[irq_index]->attr);
Lee Jones4b8ac082013-01-14 16:10:36 +00002817 if (err < 0) {
Lee Jones43621752014-07-14 18:29:16 +01002818 pr_info("sysfs_create_file failed %d\n", err);
Lee Jones4b8ac082013-01-14 16:10:36 +00002819 return err;
2820 }
2821
2822 err = request_threaded_irq(user_val, NULL, ab8500_debug_handler,
Fabio Estevamabe5b472015-05-16 15:42:15 -03002823 IRQF_SHARED | IRQF_NO_SUSPEND | IRQF_ONESHOT,
Lee Jones4b8ac082013-01-14 16:10:36 +00002824 "ab8500-debug", &dev->kobj);
2825 if (err < 0) {
Lee Jones43621752014-07-14 18:29:16 +01002826 pr_info("request_threaded_irq failed %d, %lu\n",
2827 err, user_val);
Mattias Wallin0b337e72010-11-19 17:55:11 +01002828 sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr);
Lee Jones4b8ac082013-01-14 16:10:36 +00002829 return err;
2830 }
2831
srinidhi kasagar7b830ae2012-11-23 15:11:00 +05302832 return count;
Lee Jones4b8ac082013-01-14 16:10:36 +00002833}
2834
2835static ssize_t ab8500_unsubscribe_write(struct file *file,
2836 const char __user *user_buf,
2837 size_t count, loff_t *ppos)
2838{
2839 struct device *dev = ((struct seq_file *)(file->private_data))->private;
Lee Jones4b8ac082013-01-14 16:10:36 +00002840 unsigned long user_val;
2841 int err;
Mattias Wallin0b337e72010-11-19 17:55:11 +01002842 unsigned int irq_index;
Lee Jones4b8ac082013-01-14 16:10:36 +00002843
srinidhi kasagar7b830ae2012-11-23 15:11:00 +05302844 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
Lee Jones4b8ac082013-01-14 16:10:36 +00002845 if (err)
srinidhi kasagar7b830ae2012-11-23 15:11:00 +05302846 return err;
2847
Lee Jones4b8ac082013-01-14 16:10:36 +00002848 if (user_val < irq_first) {
2849 dev_err(dev, "debugfs error input < %d\n", irq_first);
2850 return -EINVAL;
2851 }
2852 if (user_val > irq_last) {
2853 dev_err(dev, "debugfs error input > %d\n", irq_last);
2854 return -EINVAL;
2855 }
2856
Mattias Wallin0b337e72010-11-19 17:55:11 +01002857 irq_index = user_val - irq_first;
Linus Walleijddba25f2012-02-03 11:19:05 +01002858 if (irq_index >= num_irqs)
Mattias Wallin0b337e72010-11-19 17:55:11 +01002859 return -EINVAL;
Lee Jones4b8ac082013-01-14 16:10:36 +00002860
Mattias Wallin0b337e72010-11-19 17:55:11 +01002861 /* Set irq count to 0 when unsubscribe */
2862 irq_count[irq_index] = 0;
2863
2864 if (dev_attr[irq_index])
2865 sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr);
2866
2867
2868 free_irq(user_val, &dev->kobj);
2869 kfree(event_name[irq_index]);
2870 kfree(dev_attr[irq_index]);
Lee Jones4b8ac082013-01-14 16:10:36 +00002871
srinidhi kasagar7b830ae2012-11-23 15:11:00 +05302872 return count;
Lee Jones4b8ac082013-01-14 16:10:36 +00002873}
2874
carriere etienne0fbce762011-04-08 16:26:36 +02002875/*
2876 * - several deubgfs nodes fops
2877 */
2878
Mattias Wallin5814fc32010-09-13 16:05:04 +02002879static const struct file_operations ab8500_bank_fops = {
Mattias Wallind7b9f322010-11-26 13:06:39 +01002880 .open = ab8500_bank_open,
2881 .write = ab8500_bank_write,
2882 .read = seq_read,
2883 .llseek = seq_lseek,
2884 .release = single_release,
2885 .owner = THIS_MODULE,
Mattias Wallin5814fc32010-09-13 16:05:04 +02002886};
2887
2888static const struct file_operations ab8500_address_fops = {
Mattias Wallind7b9f322010-11-26 13:06:39 +01002889 .open = ab8500_address_open,
2890 .write = ab8500_address_write,
2891 .read = seq_read,
2892 .llseek = seq_lseek,
2893 .release = single_release,
2894 .owner = THIS_MODULE,
Mattias Wallin5814fc32010-09-13 16:05:04 +02002895};
2896
2897static const struct file_operations ab8500_val_fops = {
Mattias Wallind7b9f322010-11-26 13:06:39 +01002898 .open = ab8500_val_open,
2899 .write = ab8500_val_write,
2900 .read = seq_read,
2901 .llseek = seq_lseek,
2902 .release = single_release,
2903 .owner = THIS_MODULE,
Mattias Wallin5814fc32010-09-13 16:05:04 +02002904};
2905
Bengt Jonsson8f0eb432012-02-14 13:01:00 +01002906static const struct file_operations ab8500_interrupts_fops = {
2907 .open = ab8500_interrupts_open,
2908 .read = seq_read,
2909 .llseek = seq_lseek,
2910 .release = single_release,
2911 .owner = THIS_MODULE,
2912};
2913
Lee Jones4b8ac082013-01-14 16:10:36 +00002914static const struct file_operations ab8500_subscribe_fops = {
2915 .open = ab8500_subscribe_unsubscribe_open,
2916 .write = ab8500_subscribe_write,
2917 .read = seq_read,
2918 .llseek = seq_lseek,
2919 .release = single_release,
2920 .owner = THIS_MODULE,
2921};
2922
2923static const struct file_operations ab8500_unsubscribe_fops = {
2924 .open = ab8500_subscribe_unsubscribe_open,
2925 .write = ab8500_unsubscribe_write,
2926 .read = seq_read,
2927 .llseek = seq_lseek,
2928 .release = single_release,
2929 .owner = THIS_MODULE,
2930};
2931
carriere etienne0fbce762011-04-08 16:26:36 +02002932static const struct file_operations ab8500_hwreg_fops = {
2933 .open = ab8500_hwreg_open,
2934 .write = ab8500_hwreg_write,
2935 .read = seq_read,
2936 .llseek = seq_lseek,
2937 .release = single_release,
2938 .owner = THIS_MODULE,
2939};
2940
Mattias Wallin5814fc32010-09-13 16:05:04 +02002941static struct dentry *ab8500_dir;
John Beckett1478a312011-05-31 13:54:27 +01002942static struct dentry *ab8500_gpadc_dir;
Mattias Wallin5814fc32010-09-13 16:05:04 +02002943
Bill Pembertonf791be42012-11-19 13:23:04 -05002944static int ab8500_debug_probe(struct platform_device *plf)
Mattias Wallin5814fc32010-09-13 16:05:04 +02002945{
carriere etienne0fbce762011-04-08 16:26:36 +02002946 struct dentry *file;
Linus Walleijddba25f2012-02-03 11:19:05 +01002947 struct ab8500 *ab8500;
Linus Walleij69991812013-04-12 17:02:09 +02002948 struct resource *res;
Lee Jones43621752014-07-14 18:29:16 +01002949
Mattias Wallind7b9f322010-11-26 13:06:39 +01002950 debug_bank = AB8500_MISC;
2951 debug_address = AB8500_REV_REG & 0x00FF;
Mattias Wallin5814fc32010-09-13 16:05:04 +02002952
Linus Walleijddba25f2012-02-03 11:19:05 +01002953 ab8500 = dev_get_drvdata(plf->dev.parent);
2954 num_irqs = ab8500->mask_size;
2955
Lee Jonesc18cf6d2013-05-23 16:25:05 +01002956 irq_count = devm_kzalloc(&plf->dev,
2957 sizeof(*irq_count)*num_irqs, GFP_KERNEL);
Linus Walleijddba25f2012-02-03 11:19:05 +01002958 if (!irq_count)
2959 return -ENOMEM;
2960
Lee Jonesc18cf6d2013-05-23 16:25:05 +01002961 dev_attr = devm_kzalloc(&plf->dev,
Lee Jones43621752014-07-14 18:29:16 +01002962 sizeof(*dev_attr)*num_irqs, GFP_KERNEL);
Linus Walleijddba25f2012-02-03 11:19:05 +01002963 if (!dev_attr)
Lee Jonesc18cf6d2013-05-23 16:25:05 +01002964 return -ENOMEM;
Linus Walleijddba25f2012-02-03 11:19:05 +01002965
Lee Jonesc18cf6d2013-05-23 16:25:05 +01002966 event_name = devm_kzalloc(&plf->dev,
2967 sizeof(*event_name)*num_irqs, GFP_KERNEL);
Linus Walleijddba25f2012-02-03 11:19:05 +01002968 if (!event_name)
Lee Jonesc18cf6d2013-05-23 16:25:05 +01002969 return -ENOMEM;
Linus Walleijddba25f2012-02-03 11:19:05 +01002970
Linus Walleij69991812013-04-12 17:02:09 +02002971 res = platform_get_resource_byname(plf, 0, "IRQ_AB8500");
2972 if (!res) {
Lee Jones43621752014-07-14 18:29:16 +01002973 dev_err(&plf->dev, "AB8500 irq not found, err %d\n", irq_first);
2974 return -ENXIO;
Linus Walleij69991812013-04-12 17:02:09 +02002975 }
2976 irq_ab8500 = res->start;
2977
Lee Jones4b8ac082013-01-14 16:10:36 +00002978 irq_first = platform_get_irq_byname(plf, "IRQ_FIRST");
2979 if (irq_first < 0) {
Lee Jones43621752014-07-14 18:29:16 +01002980 dev_err(&plf->dev, "First irq not found, err %d\n", irq_first);
Lee Jonesc18cf6d2013-05-23 16:25:05 +01002981 return irq_first;
Lee Jones4b8ac082013-01-14 16:10:36 +00002982 }
2983
2984 irq_last = platform_get_irq_byname(plf, "IRQ_LAST");
2985 if (irq_last < 0) {
Lee Jones43621752014-07-14 18:29:16 +01002986 dev_err(&plf->dev, "Last irq not found, err %d\n", irq_last);
Lee Jonesc18cf6d2013-05-23 16:25:05 +01002987 return irq_last;
Lee Jones4b8ac082013-01-14 16:10:36 +00002988 }
2989
Mattias Wallind7b9f322010-11-26 13:06:39 +01002990 ab8500_dir = debugfs_create_dir(AB8500_NAME_STRING, NULL);
2991 if (!ab8500_dir)
carriere etienne0fbce762011-04-08 16:26:36 +02002992 goto err;
Mattias Wallin5814fc32010-09-13 16:05:04 +02002993
John Beckett1478a312011-05-31 13:54:27 +01002994 ab8500_gpadc_dir = debugfs_create_dir(AB8500_ADC_NAME_STRING,
Lee Jones43621752014-07-14 18:29:16 +01002995 ab8500_dir);
John Beckett1478a312011-05-31 13:54:27 +01002996 if (!ab8500_gpadc_dir)
2997 goto err;
2998
Lee Jones43621752014-07-14 18:29:16 +01002999 file = debugfs_create_file("all-bank-registers", S_IRUGO, ab8500_dir,
3000 &plf->dev, &ab8500_registers_fops);
carriere etienne0fbce762011-04-08 16:26:36 +02003001 if (!file)
3002 goto err;
Mattias Wallin5814fc32010-09-13 16:05:04 +02003003
Lee Jones43621752014-07-14 18:29:16 +01003004 file = debugfs_create_file("all-banks", S_IRUGO, ab8500_dir,
3005 &plf->dev, &ab8500_all_banks_fops);
Mian Yousaf Kaukab42002c62012-01-26 15:39:20 +01003006 if (!file)
3007 goto err;
3008
Lee Jones43621752014-07-14 18:29:16 +01003009 file = debugfs_create_file("register-bank",
3010 (S_IRUGO | S_IWUSR | S_IWGRP),
3011 ab8500_dir, &plf->dev, &ab8500_bank_fops);
carriere etienne0fbce762011-04-08 16:26:36 +02003012 if (!file)
3013 goto err;
Mattias Wallin5814fc32010-09-13 16:05:04 +02003014
Lee Jones43621752014-07-14 18:29:16 +01003015 file = debugfs_create_file("register-address",
3016 (S_IRUGO | S_IWUSR | S_IWGRP),
3017 ab8500_dir, &plf->dev, &ab8500_address_fops);
carriere etienne0fbce762011-04-08 16:26:36 +02003018 if (!file)
3019 goto err;
Mattias Wallin5814fc32010-09-13 16:05:04 +02003020
Lee Jones43621752014-07-14 18:29:16 +01003021 file = debugfs_create_file("register-value",
3022 (S_IRUGO | S_IWUSR | S_IWGRP),
3023 ab8500_dir, &plf->dev, &ab8500_val_fops);
carriere etienne0fbce762011-04-08 16:26:36 +02003024 if (!file)
3025 goto err;
Mattias Wallin5814fc32010-09-13 16:05:04 +02003026
Lee Jones43621752014-07-14 18:29:16 +01003027 file = debugfs_create_file("irq-subscribe",
3028 (S_IRUGO | S_IWUSR | S_IWGRP), ab8500_dir,
3029 &plf->dev, &ab8500_subscribe_fops);
carriere etienne0fbce762011-04-08 16:26:36 +02003030 if (!file)
3031 goto err;
Lee Jones4b8ac082013-01-14 16:10:36 +00003032
Lee Jones9581ae32012-07-06 16:11:50 +02003033 if (is_ab8500(ab8500)) {
3034 debug_ranges = ab8500_debug_ranges;
Bengt Jonsson8f0eb432012-02-14 13:01:00 +01003035 num_interrupt_lines = AB8500_NR_IRQS;
Lee Jones9581ae32012-07-06 16:11:50 +02003036 } else if (is_ab8505(ab8500)) {
3037 debug_ranges = ab8505_debug_ranges;
Bengt Jonsson8f0eb432012-02-14 13:01:00 +01003038 num_interrupt_lines = AB8505_NR_IRQS;
Lee Jones9581ae32012-07-06 16:11:50 +02003039 } else if (is_ab9540(ab8500)) {
3040 debug_ranges = ab8505_debug_ranges;
Bengt Jonsson8f0eb432012-02-14 13:01:00 +01003041 num_interrupt_lines = AB9540_NR_IRQS;
Lee Jones9581ae32012-07-06 16:11:50 +02003042 } else if (is_ab8540(ab8500)) {
Lee Jones971480f2012-11-19 12:20:03 +01003043 debug_ranges = ab8540_debug_ranges;
Lee Jonese436ddf2013-02-26 10:09:41 +00003044 num_interrupt_lines = AB8540_NR_IRQS;
Lee Jones9581ae32012-07-06 16:11:50 +02003045 }
Bengt Jonsson8f0eb432012-02-14 13:01:00 +01003046
Lee Jones43621752014-07-14 18:29:16 +01003047 file = debugfs_create_file("interrupts", (S_IRUGO), ab8500_dir,
3048 &plf->dev, &ab8500_interrupts_fops);
Bengt Jonsson8f0eb432012-02-14 13:01:00 +01003049 if (!file)
3050 goto err;
3051
Lee Jones43621752014-07-14 18:29:16 +01003052 file = debugfs_create_file("irq-unsubscribe",
3053 (S_IRUGO | S_IWUSR | S_IWGRP), ab8500_dir,
3054 &plf->dev, &ab8500_unsubscribe_fops);
carriere etienne0fbce762011-04-08 16:26:36 +02003055 if (!file)
3056 goto err;
3057
Lee Jonesf38487f2013-02-26 14:09:08 +00003058 file = debugfs_create_file("hwreg", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones43621752014-07-14 18:29:16 +01003059 ab8500_dir, &plf->dev, &ab8500_hwreg_fops);
John Beckett1478a312011-05-31 13:54:27 +01003060 if (!file)
3061 goto err;
3062
Lee Jones43621752014-07-14 18:29:16 +01003063 file = debugfs_create_file("all-modem-registers",
3064 (S_IRUGO | S_IWUSR | S_IWGRP),
3065 ab8500_dir, &plf->dev, &ab8500_modem_fops);
Lee Jonesc7ebaee2013-02-26 14:03:33 +00003066 if (!file)
3067 goto err;
3068
Lee Jonesf38487f2013-02-26 14:09:08 +00003069 file = debugfs_create_file("bat_ctrl", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones43621752014-07-14 18:29:16 +01003070 ab8500_gpadc_dir, &plf->dev,
3071 &ab8500_gpadc_bat_ctrl_fops);
John Beckett1478a312011-05-31 13:54:27 +01003072 if (!file)
3073 goto err;
3074
Lee Jonesf38487f2013-02-26 14:09:08 +00003075 file = debugfs_create_file("btemp_ball", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones43621752014-07-14 18:29:16 +01003076 ab8500_gpadc_dir,
3077 &plf->dev, &ab8500_gpadc_btemp_ball_fops);
John Beckett1478a312011-05-31 13:54:27 +01003078 if (!file)
3079 goto err;
3080
Lee Jones43621752014-07-14 18:29:16 +01003081 file = debugfs_create_file("main_charger_v",
3082 (S_IRUGO | S_IWUSR | S_IWGRP),
3083 ab8500_gpadc_dir, &plf->dev,
3084 &ab8500_gpadc_main_charger_v_fops);
John Beckett1478a312011-05-31 13:54:27 +01003085 if (!file)
3086 goto err;
3087
Lee Jones43621752014-07-14 18:29:16 +01003088 file = debugfs_create_file("acc_detect1",
3089 (S_IRUGO | S_IWUSR | S_IWGRP),
3090 ab8500_gpadc_dir, &plf->dev,
3091 &ab8500_gpadc_acc_detect1_fops);
John Beckett1478a312011-05-31 13:54:27 +01003092 if (!file)
3093 goto err;
3094
Lee Jones43621752014-07-14 18:29:16 +01003095 file = debugfs_create_file("acc_detect2",
3096 (S_IRUGO | S_IWUSR | S_IWGRP),
3097 ab8500_gpadc_dir, &plf->dev,
3098 &ab8500_gpadc_acc_detect2_fops);
John Beckett1478a312011-05-31 13:54:27 +01003099 if (!file)
3100 goto err;
3101
Lee Jonesf38487f2013-02-26 14:09:08 +00003102 file = debugfs_create_file("adc_aux1", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones43621752014-07-14 18:29:16 +01003103 ab8500_gpadc_dir, &plf->dev,
3104 &ab8500_gpadc_aux1_fops);
John Beckett1478a312011-05-31 13:54:27 +01003105 if (!file)
3106 goto err;
3107
Lee Jonesf38487f2013-02-26 14:09:08 +00003108 file = debugfs_create_file("adc_aux2", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones43621752014-07-14 18:29:16 +01003109 ab8500_gpadc_dir, &plf->dev,
3110 &ab8500_gpadc_aux2_fops);
John Beckett1478a312011-05-31 13:54:27 +01003111 if (!file)
3112 goto err;
3113
Lee Jonesf38487f2013-02-26 14:09:08 +00003114 file = debugfs_create_file("main_bat_v", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones43621752014-07-14 18:29:16 +01003115 ab8500_gpadc_dir, &plf->dev,
3116 &ab8500_gpadc_main_bat_v_fops);
John Beckett1478a312011-05-31 13:54:27 +01003117 if (!file)
3118 goto err;
3119
Lee Jonesf38487f2013-02-26 14:09:08 +00003120 file = debugfs_create_file("vbus_v", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones43621752014-07-14 18:29:16 +01003121 ab8500_gpadc_dir, &plf->dev,
3122 &ab8500_gpadc_vbus_v_fops);
John Beckett1478a312011-05-31 13:54:27 +01003123 if (!file)
3124 goto err;
3125
Lee Jones43621752014-07-14 18:29:16 +01003126 file = debugfs_create_file("main_charger_c",
3127 (S_IRUGO | S_IWUSR | S_IWGRP),
3128 ab8500_gpadc_dir, &plf->dev,
3129 &ab8500_gpadc_main_charger_c_fops);
John Beckett1478a312011-05-31 13:54:27 +01003130 if (!file)
3131 goto err;
3132
Lee Jones43621752014-07-14 18:29:16 +01003133 file = debugfs_create_file("usb_charger_c",
3134 (S_IRUGO | S_IWUSR | S_IWGRP),
3135 ab8500_gpadc_dir,
3136 &plf->dev, &ab8500_gpadc_usb_charger_c_fops);
John Beckett1478a312011-05-31 13:54:27 +01003137 if (!file)
3138 goto err;
3139
Lee Jonesf38487f2013-02-26 14:09:08 +00003140 file = debugfs_create_file("bk_bat_v", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones43621752014-07-14 18:29:16 +01003141 ab8500_gpadc_dir, &plf->dev,
3142 &ab8500_gpadc_bk_bat_v_fops);
John Beckett1478a312011-05-31 13:54:27 +01003143 if (!file)
3144 goto err;
3145
Lee Jonesf38487f2013-02-26 14:09:08 +00003146 file = debugfs_create_file("die_temp", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones43621752014-07-14 18:29:16 +01003147 ab8500_gpadc_dir, &plf->dev,
3148 &ab8500_gpadc_die_temp_fops);
carriere etienne0fbce762011-04-08 16:26:36 +02003149 if (!file)
3150 goto err;
Lee Jones127629d2013-02-26 14:04:37 +00003151
Lee Jonesf38487f2013-02-26 14:09:08 +00003152 file = debugfs_create_file("usb_id", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones43621752014-07-14 18:29:16 +01003153 ab8500_gpadc_dir, &plf->dev,
3154 &ab8500_gpadc_usb_id_fops);
Lee Jones127629d2013-02-26 14:04:37 +00003155 if (!file)
3156 goto err;
3157
Lee Jonesbc6b4132013-02-26 14:02:31 +00003158 if (is_ab8540(ab8500)) {
Lee Jones43621752014-07-14 18:29:16 +01003159 file = debugfs_create_file("xtal_temp",
3160 (S_IRUGO | S_IWUSR | S_IWGRP),
3161 ab8500_gpadc_dir, &plf->dev,
3162 &ab8540_gpadc_xtal_temp_fops);
Lee Jonesbc6b4132013-02-26 14:02:31 +00003163 if (!file)
3164 goto err;
Lee Jones43621752014-07-14 18:29:16 +01003165 file = debugfs_create_file("vbattruemeas",
3166 (S_IRUGO | S_IWUSR | S_IWGRP),
3167 ab8500_gpadc_dir, &plf->dev,
3168 &ab8540_gpadc_vbat_true_meas_fops);
Lee Jonesbc6b4132013-02-26 14:02:31 +00003169 if (!file)
3170 goto err;
3171 file = debugfs_create_file("batctrl_and_ibat",
Lee Jones43621752014-07-14 18:29:16 +01003172 (S_IRUGO | S_IWUGO),
3173 ab8500_gpadc_dir,
3174 &plf->dev,
3175 &ab8540_gpadc_bat_ctrl_and_ibat_fops);
Lee Jonesbc6b4132013-02-26 14:02:31 +00003176 if (!file)
3177 goto err;
3178 file = debugfs_create_file("vbatmeas_and_ibat",
Lee Jones43621752014-07-14 18:29:16 +01003179 (S_IRUGO | S_IWUGO),
3180 ab8500_gpadc_dir, &plf->dev,
3181 &ab8540_gpadc_vbat_meas_and_ibat_fops);
Lee Jonesbc6b4132013-02-26 14:02:31 +00003182 if (!file)
3183 goto err;
3184 file = debugfs_create_file("vbattruemeas_and_ibat",
Lee Jones43621752014-07-14 18:29:16 +01003185 (S_IRUGO | S_IWUGO),
3186 ab8500_gpadc_dir,
3187 &plf->dev,
3188 &ab8540_gpadc_vbat_true_meas_and_ibat_fops);
Lee Jonesbc6b4132013-02-26 14:02:31 +00003189 if (!file)
3190 goto err;
3191 file = debugfs_create_file("battemp_and_ibat",
Lee Jones43621752014-07-14 18:29:16 +01003192 (S_IRUGO | S_IWUGO),
3193 ab8500_gpadc_dir,
Lee Jones9f9ba152013-02-26 12:05:15 +00003194 &plf->dev, &ab8540_gpadc_bat_temp_and_ibat_fops);
Lee Jonesbc6b4132013-02-26 14:02:31 +00003195 if (!file)
3196 goto err;
Lee Jones43621752014-07-14 18:29:16 +01003197 file = debugfs_create_file("otp_calib",
3198 (S_IRUGO | S_IWUSR | S_IWGRP),
3199 ab8500_gpadc_dir,
3200 &plf->dev, &ab8540_gpadc_otp_calib_fops);
Lee Jonesbc6b4132013-02-26 14:02:31 +00003201 if (!file)
3202 goto err;
3203 }
Lee Jonesf38487f2013-02-26 14:09:08 +00003204 file = debugfs_create_file("avg_sample", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones43621752014-07-14 18:29:16 +01003205 ab8500_gpadc_dir, &plf->dev,
3206 &ab8500_gpadc_avg_sample_fops);
Lee Jones73482342013-02-26 10:06:55 +00003207 if (!file)
3208 goto err;
3209
Lee Jonesf38487f2013-02-26 14:09:08 +00003210 file = debugfs_create_file("trig_edge", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones43621752014-07-14 18:29:16 +01003211 ab8500_gpadc_dir, &plf->dev,
3212 &ab8500_gpadc_trig_edge_fops);
Lee Jones73482342013-02-26 10:06:55 +00003213 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 Jones43621752014-07-14 18:29:16 +01003217 ab8500_gpadc_dir, &plf->dev,
3218 &ab8500_gpadc_trig_timer_fops);
Lee Jones73482342013-02-26 10:06:55 +00003219 if (!file)
3220 goto err;
3221
Lee Jonesf38487f2013-02-26 14:09:08 +00003222 file = debugfs_create_file("conv_type", (S_IRUGO | S_IWUSR | S_IWGRP),
Lee Jones43621752014-07-14 18:29:16 +01003223 ab8500_gpadc_dir, &plf->dev,
3224 &ab8500_gpadc_conv_type_fops);
Lee Jones73482342013-02-26 10:06:55 +00003225 if (!file)
3226 goto err;
3227
Mattias Wallind7b9f322010-11-26 13:06:39 +01003228 return 0;
Mattias Wallin5814fc32010-09-13 16:05:04 +02003229
carriere etienne0fbce762011-04-08 16:26:36 +02003230err:
Fabian Frederick005d16b2014-06-28 13:58:17 +02003231 debugfs_remove_recursive(ab8500_dir);
Mattias Wallind7b9f322010-11-26 13:06:39 +01003232 dev_err(&plf->dev, "failed to create debugfs entries.\n");
Linus Walleijddba25f2012-02-03 11:19:05 +01003233
Lee Jonesc18cf6d2013-05-23 16:25:05 +01003234 return -ENOMEM;
Mattias Wallin5814fc32010-09-13 16:05:04 +02003235}
3236
Mattias Wallin5814fc32010-09-13 16:05:04 +02003237static struct platform_driver ab8500_debug_driver = {
Mattias Wallind7b9f322010-11-26 13:06:39 +01003238 .driver = {
3239 .name = "ab8500-debug",
Paul Gortmaker4b3f2b62016-10-29 21:24:37 -04003240 .suppress_bind_attrs = true,
Mattias Wallind7b9f322010-11-26 13:06:39 +01003241 },
3242 .probe = ab8500_debug_probe,
Mattias Wallin5814fc32010-09-13 16:05:04 +02003243};
3244
3245static int __init ab8500_debug_init(void)
3246{
Mattias Wallind7b9f322010-11-26 13:06:39 +01003247 return platform_driver_register(&ab8500_debug_driver);
Mattias Wallin5814fc32010-09-13 16:05:04 +02003248}
Mattias Wallin5814fc32010-09-13 16:05:04 +02003249subsys_initcall(ab8500_debug_init);