mfd: ab8500-sysctrl: Error check clean up
[deliverable/linux.git] / drivers / mfd / ab8500-debugfs.c
CommitLineData
5814fc35
MW
1/*
2 * Copyright (C) ST-Ericsson SA 2010
3 *
4 * Author: Mattias Wallin <mattias.wallin@stericsson.com> for ST-Ericsson.
5 * License Terms: GNU General Public License v2
6 */
0fbce76e 7/*
8 * AB8500 register access
9 * ======================
10 *
11 * read:
12 * # echo BANK > <debugfs>/ab8500/register-bank
13 * # echo ADDR > <debugfs>/ab8500/register-address
14 * # cat <debugfs>/ab8500/register-value
15 *
16 * write:
17 * # echo BANK > <debugfs>/ab8500/register-bank
18 * # echo ADDR > <debugfs>/ab8500/register-address
19 * # echo VALUE > <debugfs>/ab8500/register-value
20 *
21 * read all registers from a bank:
22 * # echo BANK > <debugfs>/ab8500/register-bank
23 * # cat <debugfs>/ab8500/all-bank-register
24 *
25 * BANK target AB8500 register bank
26 * ADDR target AB8500 register address
27 * VALUE decimal or 0x-prefixed hexadecimal
28 *
29 *
30 * User Space notification on AB8500 IRQ
31 * =====================================
32 *
33 * Allows user space entity to be notified when target AB8500 IRQ occurs.
34 * When subscribed, a sysfs entry is created in ab8500.i2c platform device.
35 * One can pool this file to get target IRQ occurence information.
36 *
37 * subscribe to an AB8500 IRQ:
38 * # echo IRQ > <debugfs>/ab8500/irq-subscribe
39 *
40 * unsubscribe from an AB8500 IRQ:
41 * # echo IRQ > <debugfs>/ab8500/irq-unsubscribe
42 *
43 *
44 * AB8500 register formated read/write access
45 * ==========================================
46 *
47 * Read: read data, data>>SHIFT, data&=MASK, output data
48 * [0xABCDEF98] shift=12 mask=0xFFF => 0x00000CDE
49 * Write: read data, data &= ~(MASK<<SHIFT), data |= (VALUE<<SHIFT), write data
50 * [0xABCDEF98] shift=12 mask=0xFFF value=0x123 => [0xAB123F98]
51 *
52 * Usage:
53 * # echo "CMD [OPTIONS] BANK ADRESS [VALUE]" > $debugfs/ab8500/hwreg
54 *
55 * CMD read read access
56 * write write access
57 *
58 * BANK target reg bank
59 * ADDRESS target reg address
60 * VALUE (write) value to be updated
61 *
62 * OPTIONS
63 * -d|-dec (read) output in decimal
64 * -h|-hexa (read) output in 0x-hexa (default)
65 * -l|-w|-b 32bit (default), 16bit or 8bit reg access
66 * -m|-mask MASK 0x-hexa mask (default 0xFFFFFFFF)
67 * -s|-shift SHIFT bit shift value (read:left, write:right)
68 * -o|-offset OFFSET address offset to add to ADDRESS value
69 *
70 * Warning: bit shift operation is applied to bit-mask.
71 * Warning: bit shift direction depends on read or right command.
72 */
5814fc35
MW
73
74#include <linux/seq_file.h>
75#include <linux/uaccess.h>
76#include <linux/fs.h>
4e36dd33 77#include <linux/module.h>
5814fc35
MW
78#include <linux/debugfs.h>
79#include <linux/platform_device.h>
4b8ac082
LJ
80#include <linux/interrupt.h>
81#include <linux/kobject.h>
82#include <linux/slab.h>
2cf64e26 83#include <linux/irq.h>
5814fc35
MW
84
85#include <linux/mfd/abx500.h>
0cd5b6d0 86#include <linux/mfd/abx500/ab8500.h>
1478a316 87#include <linux/mfd/abx500/ab8500-gpadc.h>
5814fc35 88
0fbce76e 89#ifdef CONFIG_DEBUG_FS
90#include <linux/string.h>
91#include <linux/ctype.h>
92#endif
93
5814fc35
MW
94static u32 debug_bank;
95static u32 debug_address;
96
4b8ac082
LJ
97static int irq_first;
98static int irq_last;
ddba25f1
LW
99static u32 *irq_count;
100static int num_irqs;
0b337e70 101
ddba25f1
LW
102static struct device_attribute **dev_attr;
103static char **event_name;
4b8ac082 104
73482346
LJ
105static u8 avg_sample = SAMPLE_16;
106static u8 trig_edge = RISING_EDGE;
107static u8 conv_type = ADC_SW;
108static u8 trig_timer;
109
5814fc35
MW
110/**
111 * struct ab8500_reg_range
112 * @first: the first address of the range
113 * @last: the last address of the range
114 * @perm: access permissions for the range
115 */
116struct ab8500_reg_range {
d7b9f322
MW
117 u8 first;
118 u8 last;
119 u8 perm;
5814fc35
MW
120};
121
122/**
822672a7 123 * struct ab8500_prcmu_ranges
5814fc35
MW
124 * @num_ranges: the number of ranges in the list
125 * @bankid: bank identifier
126 * @range: the list of register ranges
127 */
822672a7 128struct ab8500_prcmu_ranges {
d7b9f322
MW
129 u8 num_ranges;
130 u8 bankid;
131 const struct ab8500_reg_range *range;
5814fc35
MW
132};
133
0fbce76e 134/* hwreg- "mask" and "shift" entries ressources */
135struct hwreg_cfg {
136 u32 bank; /* target bank */
137 u32 addr; /* target address */
138 uint fmt; /* format */
139 uint mask; /* read/write mask, applied before any bit shift */
140 int shift; /* bit shift (read:right shift, write:left shift */
141};
142/* fmt bit #0: 0=hexa, 1=dec */
143#define REG_FMT_DEC(c) ((c)->fmt & 0x1)
144#define REG_FMT_HEX(c) (!REG_FMT_DEC(c))
145
146static struct hwreg_cfg hwreg_cfg = {
147 .addr = 0, /* default: invalid phys addr */
148 .fmt = 0, /* default: 32bit access, hex output */
149 .mask = 0xFFFFFFFF, /* default: no mask */
150 .shift = 0, /* default: no bit shift */
151};
152
5814fc35 153#define AB8500_NAME_STRING "ab8500"
1478a316 154#define AB8500_ADC_NAME_STRING "gpadc"
40c064e4 155#define AB8500_NUM_BANKS 24
5814fc35
MW
156
157#define AB8500_REV_REG 0x80
158
822672a7 159static struct ab8500_prcmu_ranges debug_ranges[AB8500_NUM_BANKS] = {
d7b9f322
MW
160 [0x0] = {
161 .num_ranges = 0,
fad55a86 162 .range = NULL,
d7b9f322
MW
163 },
164 [AB8500_SYS_CTRL1_BLOCK] = {
165 .num_ranges = 3,
166 .range = (struct ab8500_reg_range[]) {
167 {
168 .first = 0x00,
169 .last = 0x02,
170 },
171 {
172 .first = 0x42,
173 .last = 0x42,
174 },
175 {
176 .first = 0x80,
177 .last = 0x81,
178 },
179 },
180 },
181 [AB8500_SYS_CTRL2_BLOCK] = {
182 .num_ranges = 4,
183 .range = (struct ab8500_reg_range[]) {
184 {
185 .first = 0x00,
186 .last = 0x0D,
187 },
188 {
189 .first = 0x0F,
190 .last = 0x17,
191 },
192 {
193 .first = 0x30,
194 .last = 0x30,
195 },
196 {
197 .first = 0x32,
198 .last = 0x33,
199 },
200 },
201 },
202 [AB8500_REGU_CTRL1] = {
203 .num_ranges = 3,
204 .range = (struct ab8500_reg_range[]) {
205 {
206 .first = 0x00,
207 .last = 0x00,
208 },
209 {
210 .first = 0x03,
211 .last = 0x10,
212 },
213 {
214 .first = 0x80,
215 .last = 0x84,
216 },
217 },
218 },
219 [AB8500_REGU_CTRL2] = {
220 .num_ranges = 5,
221 .range = (struct ab8500_reg_range[]) {
222 {
223 .first = 0x00,
224 .last = 0x15,
225 },
226 {
227 .first = 0x17,
228 .last = 0x19,
229 },
230 {
231 .first = 0x1B,
232 .last = 0x1D,
233 },
234 {
235 .first = 0x1F,
236 .last = 0x22,
237 },
238 {
239 .first = 0x40,
240 .last = 0x44,
241 },
242 /* 0x80-0x8B is SIM registers and should
243 * not be accessed from here */
244 },
245 },
246 [AB8500_USB] = {
247 .num_ranges = 2,
248 .range = (struct ab8500_reg_range[]) {
249 {
250 .first = 0x80,
251 .last = 0x83,
252 },
253 {
254 .first = 0x87,
255 .last = 0x8A,
256 },
257 },
258 },
259 [AB8500_TVOUT] = {
260 .num_ranges = 9,
261 .range = (struct ab8500_reg_range[]) {
262 {
263 .first = 0x00,
264 .last = 0x12,
265 },
266 {
267 .first = 0x15,
268 .last = 0x17,
269 },
270 {
271 .first = 0x19,
272 .last = 0x21,
273 },
274 {
275 .first = 0x27,
276 .last = 0x2C,
277 },
278 {
279 .first = 0x41,
280 .last = 0x41,
281 },
282 {
283 .first = 0x45,
284 .last = 0x5B,
285 },
286 {
287 .first = 0x5D,
288 .last = 0x5D,
289 },
290 {
291 .first = 0x69,
292 .last = 0x69,
293 },
294 {
295 .first = 0x80,
296 .last = 0x81,
297 },
298 },
299 },
300 [AB8500_DBI] = {
301 .num_ranges = 0,
87fff232 302 .range = NULL,
d7b9f322
MW
303 },
304 [AB8500_ECI_AV_ACC] = {
305 .num_ranges = 1,
306 .range = (struct ab8500_reg_range[]) {
307 {
308 .first = 0x80,
309 .last = 0x82,
310 },
311 },
312 },
313 [0x9] = {
314 .num_ranges = 0,
87fff232 315 .range = NULL,
d7b9f322
MW
316 },
317 [AB8500_GPADC] = {
318 .num_ranges = 1,
319 .range = (struct ab8500_reg_range[]) {
320 {
321 .first = 0x00,
322 .last = 0x08,
323 },
324 },
325 },
326 [AB8500_CHARGER] = {
40c064e4 327 .num_ranges = 9,
d7b9f322
MW
328 .range = (struct ab8500_reg_range[]) {
329 {
330 .first = 0x00,
331 .last = 0x03,
332 },
333 {
334 .first = 0x05,
335 .last = 0x05,
336 },
337 {
338 .first = 0x40,
339 .last = 0x40,
340 },
341 {
342 .first = 0x42,
343 .last = 0x42,
344 },
345 {
346 .first = 0x44,
347 .last = 0x44,
348 },
349 {
350 .first = 0x50,
351 .last = 0x55,
352 },
353 {
354 .first = 0x80,
355 .last = 0x82,
356 },
357 {
358 .first = 0xC0,
359 .last = 0xC2,
360 },
40c064e4
PL
361 {
362 .first = 0xf5,
363 .last = 0xf6,
364 },
d7b9f322
MW
365 },
366 },
367 [AB8500_GAS_GAUGE] = {
368 .num_ranges = 3,
369 .range = (struct ab8500_reg_range[]) {
370 {
371 .first = 0x00,
372 .last = 0x00,
373 },
374 {
375 .first = 0x07,
376 .last = 0x0A,
377 },
378 {
379 .first = 0x10,
380 .last = 0x14,
381 },
382 },
383 },
40c064e4
PL
384 [AB8500_DEVELOPMENT] = {
385 .num_ranges = 1,
386 .range = (struct ab8500_reg_range[]) {
387 {
388 .first = 0x00,
389 .last = 0x00,
390 },
391 },
392 },
393 [AB8500_DEBUG] = {
394 .num_ranges = 1,
395 .range = (struct ab8500_reg_range[]) {
396 {
397 .first = 0x05,
398 .last = 0x07,
399 },
400 },
401 },
d7b9f322
MW
402 [AB8500_AUDIO] = {
403 .num_ranges = 1,
404 .range = (struct ab8500_reg_range[]) {
405 {
406 .first = 0x00,
407 .last = 0x6F,
408 },
409 },
410 },
411 [AB8500_INTERRUPT] = {
412 .num_ranges = 0,
87fff232 413 .range = NULL,
d7b9f322
MW
414 },
415 [AB8500_RTC] = {
416 .num_ranges = 1,
417 .range = (struct ab8500_reg_range[]) {
418 {
419 .first = 0x00,
420 .last = 0x0F,
421 },
422 },
423 },
424 [AB8500_MISC] = {
425 .num_ranges = 8,
426 .range = (struct ab8500_reg_range[]) {
427 {
428 .first = 0x00,
429 .last = 0x05,
430 },
431 {
432 .first = 0x10,
433 .last = 0x15,
434 },
435 {
436 .first = 0x20,
437 .last = 0x25,
438 },
439 {
440 .first = 0x30,
441 .last = 0x35,
442 },
443 {
444 .first = 0x40,
445 .last = 0x45,
446 },
447 {
448 .first = 0x50,
449 .last = 0x50,
450 },
451 {
452 .first = 0x60,
453 .last = 0x67,
454 },
455 {
456 .first = 0x80,
457 .last = 0x80,
458 },
459 },
460 },
461 [0x11] = {
462 .num_ranges = 0,
87fff232 463 .range = NULL,
d7b9f322
MW
464 },
465 [0x12] = {
466 .num_ranges = 0,
87fff232 467 .range = NULL,
d7b9f322
MW
468 },
469 [0x13] = {
470 .num_ranges = 0,
87fff232 471 .range = NULL,
d7b9f322
MW
472 },
473 [0x14] = {
474 .num_ranges = 0,
87fff232 475 .range = NULL,
d7b9f322
MW
476 },
477 [AB8500_OTP_EMUL] = {
478 .num_ranges = 1,
479 .range = (struct ab8500_reg_range[]) {
480 {
481 .first = 0x01,
482 .last = 0x0F,
483 },
484 },
485 },
5814fc35
MW
486};
487
4b8ac082
LJ
488static irqreturn_t ab8500_debug_handler(int irq, void *data)
489{
490 char buf[16];
491 struct kobject *kobj = (struct kobject *)data;
0b337e70 492 unsigned int irq_abb = irq - irq_first;
4b8ac082 493
ddba25f1 494 if (irq_abb < num_irqs)
0b337e70 495 irq_count[irq_abb]++;
4b8ac082
LJ
496 /*
497 * This makes it possible to use poll for events (POLLPRI | POLLERR)
0b337e70 498 * from userspace on sysfs file named <irq-nr>
4b8ac082 499 */
0b337e70 500 sprintf(buf, "%d", irq);
4b8ac082
LJ
501 sysfs_notify(kobj, NULL, buf);
502
503 return IRQ_HANDLED;
504}
505
42002c6d
MYK
506/* Prints to seq_file or log_buf */
507static int ab8500_registers_print(struct device *dev, u32 bank,
508 struct seq_file *s)
5814fc35 509{
d7b9f322 510 unsigned int i;
d7b9f322 511
d7b9f322
MW
512 for (i = 0; i < debug_ranges[bank].num_ranges; i++) {
513 u32 reg;
514
515 for (reg = debug_ranges[bank].range[i].first;
516 reg <= debug_ranges[bank].range[i].last;
517 reg++) {
518 u8 value;
519 int err;
520
521 err = abx500_get_register_interruptible(dev,
522 (u8)bank, (u8)reg, &value);
523 if (err < 0) {
524 dev_err(dev, "ab->read fail %d\n", err);
525 return err;
526 }
527
42002c6d 528 if (s) {
cfc0849c 529 err = seq_printf(s, " [0x%02X/0x%02X]: 0x%02X\n",
42002c6d
MYK
530 bank, reg, value);
531 if (err < 0) {
532 dev_err(dev,
cfc0849c 533 "seq_printf overflow bank=0x%02X reg=0x%02X\n",
42002c6d
MYK
534 bank, reg);
535 /* Error is not returned here since
536 * the output is wanted in any case */
537 return 0;
538 }
539 } else {
cfc0849c
MW
540 printk(KERN_INFO" [0x%02X/0x%02X]: 0x%02X\n",
541 bank, reg, value);
d7b9f322
MW
542 }
543 }
544 }
545 return 0;
5814fc35
MW
546}
547
42002c6d
MYK
548static int ab8500_print_bank_registers(struct seq_file *s, void *p)
549{
550 struct device *dev = s->private;
551 u32 bank = debug_bank;
552
553 seq_printf(s, AB8500_NAME_STRING " register values:\n");
554
cfc0849c 555 seq_printf(s, " bank 0x%02X:\n", bank);
42002c6d
MYK
556
557 ab8500_registers_print(dev, bank, s);
558 return 0;
559}
560
5814fc35
MW
561static int ab8500_registers_open(struct inode *inode, struct file *file)
562{
42002c6d 563 return single_open(file, ab8500_print_bank_registers, inode->i_private);
5814fc35
MW
564}
565
566static const struct file_operations ab8500_registers_fops = {
d7b9f322
MW
567 .open = ab8500_registers_open,
568 .read = seq_read,
569 .llseek = seq_lseek,
570 .release = single_release,
571 .owner = THIS_MODULE,
5814fc35
MW
572};
573
42002c6d
MYK
574static int ab8500_print_all_banks(struct seq_file *s, void *p)
575{
576 struct device *dev = s->private;
577 unsigned int i;
578 int err;
579
580 seq_printf(s, AB8500_NAME_STRING " register values:\n");
581
582 for (i = 1; i < AB8500_NUM_BANKS; i++) {
cfc0849c 583 err = seq_printf(s, " bank 0x%02X:\n", i);
42002c6d 584 if (err < 0)
cfc0849c 585 dev_err(dev, "seq_printf overflow, bank=0x%02X\n", i);
42002c6d
MYK
586
587 ab8500_registers_print(dev, i, s);
588 }
589 return 0;
590}
591
1d843a6c
MYK
592/* Dump registers to kernel log */
593void ab8500_dump_all_banks(struct device *dev)
594{
595 unsigned int i;
596
597 printk(KERN_INFO"ab8500 register values:\n");
598
599 for (i = 1; i < AB8500_NUM_BANKS; i++) {
cfc0849c 600 printk(KERN_INFO" bank 0x%02X:\n", i);
1d843a6c
MYK
601 ab8500_registers_print(dev, i, NULL);
602 }
603}
604
5ff9090f
LJ
605/* Space for 500 registers. */
606#define DUMP_MAX_REGS 700
607struct ab8500_register_dump
608{
609 u8 bank;
610 u8 reg;
611 u8 value;
5ff9090f
LJ
612} ab8500_complete_register_dump[DUMP_MAX_REGS];
613
614extern int prcmu_abb_read(u8 slave, u8 reg, u8 *value, u8 size);
615
616/* This shall only be called upon kernel panic! */
617void ab8500_dump_all_banks_to_mem(void)
618{
619 int i, r = 0;
620 u8 bank;
222460cb 621 int err = 0;
5ff9090f
LJ
622
623 pr_info("Saving all ABB registers at \"ab8500_complete_register_dump\" "
624 "for crash analyze.\n");
625
626 for (bank = 1; bank < AB8500_NUM_BANKS; bank++) {
627 for (i = 0; i < debug_ranges[bank].num_ranges; i++) {
628 u8 reg;
629
630 for (reg = debug_ranges[bank].range[i].first;
631 reg <= debug_ranges[bank].range[i].last;
632 reg++) {
633 u8 value;
5ff9090f
LJ
634
635 err = prcmu_abb_read(bank, reg, &value, 1);
636
222460cb
JA
637 if (err < 0)
638 goto out;
639
5ff9090f
LJ
640 ab8500_complete_register_dump[r].bank = bank;
641 ab8500_complete_register_dump[r].reg = reg;
642 ab8500_complete_register_dump[r].value = value;
643
644 r++;
645
646 if (r >= DUMP_MAX_REGS) {
647 pr_err("%s: too many register to dump!\n",
648 __func__);
222460cb
JA
649 err = -EINVAL;
650 goto out;
5ff9090f
LJ
651 }
652 }
653 }
654 }
222460cb
JA
655out:
656 if (err >= 0)
657 pr_info("Saved all ABB registers.\n");
658 else
659 pr_info("Failed to save all ABB registers.\n");
5ff9090f
LJ
660}
661
42002c6d
MYK
662static int ab8500_all_banks_open(struct inode *inode, struct file *file)
663{
664 struct seq_file *s;
665 int err;
666
667 err = single_open(file, ab8500_print_all_banks, inode->i_private);
668 if (!err) {
669 /* Default buf size in seq_read is not enough */
670 s = (struct seq_file *)file->private_data;
671 s->size = (PAGE_SIZE * 2);
672 s->buf = kmalloc(s->size, GFP_KERNEL);
673 if (!s->buf) {
674 single_release(inode, file);
675 err = -ENOMEM;
676 }
677 }
678 return err;
679}
680
681static const struct file_operations ab8500_all_banks_fops = {
682 .open = ab8500_all_banks_open,
683 .read = seq_read,
684 .llseek = seq_lseek,
685 .release = single_release,
686 .owner = THIS_MODULE,
687};
688
5814fc35
MW
689static int ab8500_bank_print(struct seq_file *s, void *p)
690{
cfc0849c 691 return seq_printf(s, "0x%02X\n", debug_bank);
5814fc35
MW
692}
693
694static int ab8500_bank_open(struct inode *inode, struct file *file)
695{
d7b9f322 696 return single_open(file, ab8500_bank_print, inode->i_private);
5814fc35
MW
697}
698
699static ssize_t ab8500_bank_write(struct file *file,
d7b9f322
MW
700 const char __user *user_buf,
701 size_t count, loff_t *ppos)
5814fc35 702{
d7b9f322 703 struct device *dev = ((struct seq_file *)(file->private_data))->private;
d7b9f322
MW
704 unsigned long user_bank;
705 int err;
706
707 /* Get userspace string and assure termination */
8504d638 708 err = kstrtoul_from_user(user_buf, count, 0, &user_bank);
d7b9f322 709 if (err)
8504d638 710 return err;
d7b9f322
MW
711
712 if (user_bank >= AB8500_NUM_BANKS) {
713 dev_err(dev, "debugfs error input > number of banks\n");
714 return -EINVAL;
715 }
716
717 debug_bank = user_bank;
718
8504d638 719 return count;
5814fc35
MW
720}
721
722static int ab8500_address_print(struct seq_file *s, void *p)
723{
d7b9f322 724 return seq_printf(s, "0x%02X\n", debug_address);
5814fc35
MW
725}
726
727static int ab8500_address_open(struct inode *inode, struct file *file)
728{
d7b9f322 729 return single_open(file, ab8500_address_print, inode->i_private);
5814fc35
MW
730}
731
732static ssize_t ab8500_address_write(struct file *file,
d7b9f322
MW
733 const char __user *user_buf,
734 size_t count, loff_t *ppos)
5814fc35 735{
d7b9f322 736 struct device *dev = ((struct seq_file *)(file->private_data))->private;
d7b9f322
MW
737 unsigned long user_address;
738 int err;
739
740 /* Get userspace string and assure termination */
8504d638 741 err = kstrtoul_from_user(user_buf, count, 0, &user_address);
d7b9f322 742 if (err)
8504d638
PH
743 return err;
744
d7b9f322
MW
745 if (user_address > 0xff) {
746 dev_err(dev, "debugfs error input > 0xff\n");
747 return -EINVAL;
748 }
749 debug_address = user_address;
8504d638 750 return count;
5814fc35
MW
751}
752
753static int ab8500_val_print(struct seq_file *s, void *p)
754{
d7b9f322
MW
755 struct device *dev = s->private;
756 int ret;
757 u8 regvalue;
758
759 ret = abx500_get_register_interruptible(dev,
760 (u8)debug_bank, (u8)debug_address, &regvalue);
761 if (ret < 0) {
762 dev_err(dev, "abx500_get_reg fail %d, %d\n",
763 ret, __LINE__);
764 return -EINVAL;
765 }
766 seq_printf(s, "0x%02X\n", regvalue);
767
768 return 0;
5814fc35
MW
769}
770
771static int ab8500_val_open(struct inode *inode, struct file *file)
772{
d7b9f322 773 return single_open(file, ab8500_val_print, inode->i_private);
5814fc35
MW
774}
775
776static ssize_t ab8500_val_write(struct file *file,
d7b9f322
MW
777 const char __user *user_buf,
778 size_t count, loff_t *ppos)
5814fc35 779{
d7b9f322 780 struct device *dev = ((struct seq_file *)(file->private_data))->private;
d7b9f322
MW
781 unsigned long user_val;
782 int err;
783
784 /* Get userspace string and assure termination */
8504d638 785 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
d7b9f322 786 if (err)
8504d638
PH
787 return err;
788
d7b9f322
MW
789 if (user_val > 0xff) {
790 dev_err(dev, "debugfs error input > 0xff\n");
791 return -EINVAL;
792 }
793 err = abx500_set_register_interruptible(dev,
794 (u8)debug_bank, debug_address, (u8)user_val);
795 if (err < 0) {
796 printk(KERN_ERR "abx500_set_reg failed %d, %d", err, __LINE__);
797 return -EINVAL;
798 }
799
8504d638 800 return count;
5814fc35
MW
801}
802
8f0eb43b
BJ
803/*
804 * Interrupt status
805 */
806static u32 num_interrupts[AB8500_MAX_NR_IRQS];
2cf64e26 807static u32 num_wake_interrupts[AB8500_MAX_NR_IRQS];
8f0eb43b
BJ
808static int num_interrupt_lines;
809
2cf64e26
JA
810bool __attribute__((weak)) suspend_test_wake_cause_interrupt_is_mine(u32 my_int)
811{
812 return false;
813}
814
8f0eb43b
BJ
815void ab8500_debug_register_interrupt(int line)
816{
2cf64e26 817 if (line < num_interrupt_lines) {
8f0eb43b 818 num_interrupts[line]++;
2cf64e26
JA
819 if (suspend_test_wake_cause_interrupt_is_mine(IRQ_DB8500_AB8500))
820 num_wake_interrupts[line]++;
821 }
8f0eb43b
BJ
822}
823
824static int ab8500_interrupts_print(struct seq_file *s, void *p)
825{
826 int line;
827
2cf64e26
JA
828 seq_printf(s, "name: number: number of: wake:\n");
829
830 for (line = 0; line < num_interrupt_lines; line++) {
831 struct irq_desc *desc = irq_to_desc(line + irq_first);
832 struct irqaction *action = desc->action;
8f0eb43b 833
2cf64e26
JA
834 seq_printf(s, "%3i: %6i %4i", line,
835 num_interrupts[line],
836 num_wake_interrupts[line]);
837
838 if (desc && desc->name)
839 seq_printf(s, "-%-8s", desc->name);
840 if (action) {
841 seq_printf(s, " %s", action->name);
842 while ((action = action->next) != NULL)
843 seq_printf(s, ", %s", action->name);
844 }
845 seq_putc(s, '\n');
846 }
8f0eb43b
BJ
847
848 return 0;
849}
850
851static int ab8500_interrupts_open(struct inode *inode, struct file *file)
852{
853 return single_open(file, ab8500_interrupts_print, inode->i_private);
854}
855
0fbce76e 856/*
857 * - HWREG DB8500 formated routines
858 */
859static int ab8500_hwreg_print(struct seq_file *s, void *d)
860{
861 struct device *dev = s->private;
862 int ret;
863 u8 regvalue;
864
865 ret = abx500_get_register_interruptible(dev,
866 (u8)hwreg_cfg.bank, (u8)hwreg_cfg.addr, &regvalue);
867 if (ret < 0) {
868 dev_err(dev, "abx500_get_reg fail %d, %d\n",
869 ret, __LINE__);
870 return -EINVAL;
871 }
872
873 if (hwreg_cfg.shift >= 0)
874 regvalue >>= hwreg_cfg.shift;
875 else
876 regvalue <<= -hwreg_cfg.shift;
877 regvalue &= hwreg_cfg.mask;
878
879 if (REG_FMT_DEC(&hwreg_cfg))
880 seq_printf(s, "%d\n", regvalue);
881 else
882 seq_printf(s, "0x%02X\n", regvalue);
883 return 0;
884}
885
886static int ab8500_hwreg_open(struct inode *inode, struct file *file)
887{
888 return single_open(file, ab8500_hwreg_print, inode->i_private);
889}
890
1478a316
JB
891static int ab8500_gpadc_bat_ctrl_print(struct seq_file *s, void *p)
892{
893 int bat_ctrl_raw;
894 int bat_ctrl_convert;
895 struct ab8500_gpadc *gpadc;
896
8908c049 897 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
73482346
LJ
898 bat_ctrl_raw = ab8500_gpadc_read_raw(gpadc, BAT_CTRL,
899 avg_sample, trig_edge, trig_timer, conv_type);
1478a316 900 bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc,
73482346 901 BAT_CTRL, bat_ctrl_raw);
1478a316
JB
902
903 return seq_printf(s, "%d,0x%X\n",
904 bat_ctrl_convert, bat_ctrl_raw);
905}
906
907static int ab8500_gpadc_bat_ctrl_open(struct inode *inode, struct file *file)
908{
909 return single_open(file, ab8500_gpadc_bat_ctrl_print, inode->i_private);
910}
911
912static const struct file_operations ab8500_gpadc_bat_ctrl_fops = {
913 .open = ab8500_gpadc_bat_ctrl_open,
914 .read = seq_read,
915 .llseek = seq_lseek,
916 .release = single_release,
917 .owner = THIS_MODULE,
918};
919
920static int ab8500_gpadc_btemp_ball_print(struct seq_file *s, void *p)
921{
922 int btemp_ball_raw;
923 int btemp_ball_convert;
924 struct ab8500_gpadc *gpadc;
925
8908c049 926 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
73482346
LJ
927 btemp_ball_raw = ab8500_gpadc_read_raw(gpadc, BTEMP_BALL,
928 avg_sample, trig_edge, trig_timer, conv_type);
1478a316 929 btemp_ball_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL,
73482346 930 btemp_ball_raw);
1478a316
JB
931
932 return seq_printf(s,
933 "%d,0x%X\n", btemp_ball_convert, btemp_ball_raw);
934}
935
936static int ab8500_gpadc_btemp_ball_open(struct inode *inode,
937 struct file *file)
938{
939 return single_open(file, ab8500_gpadc_btemp_ball_print, inode->i_private);
940}
941
942static const struct file_operations ab8500_gpadc_btemp_ball_fops = {
943 .open = ab8500_gpadc_btemp_ball_open,
944 .read = seq_read,
945 .llseek = seq_lseek,
946 .release = single_release,
947 .owner = THIS_MODULE,
948};
949
950static int ab8500_gpadc_main_charger_v_print(struct seq_file *s, void *p)
951{
952 int main_charger_v_raw;
953 int main_charger_v_convert;
954 struct ab8500_gpadc *gpadc;
955
8908c049 956 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
73482346
LJ
957 main_charger_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_V,
958 avg_sample, trig_edge, trig_timer, conv_type);
1478a316 959 main_charger_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
73482346 960 MAIN_CHARGER_V, main_charger_v_raw);
1478a316
JB
961
962 return seq_printf(s, "%d,0x%X\n",
963 main_charger_v_convert, main_charger_v_raw);
964}
965
966static int ab8500_gpadc_main_charger_v_open(struct inode *inode,
967 struct file *file)
968{
969 return single_open(file, ab8500_gpadc_main_charger_v_print,
970 inode->i_private);
971}
972
973static const struct file_operations ab8500_gpadc_main_charger_v_fops = {
974 .open = ab8500_gpadc_main_charger_v_open,
975 .read = seq_read,
976 .llseek = seq_lseek,
977 .release = single_release,
978 .owner = THIS_MODULE,
979};
980
981static int ab8500_gpadc_acc_detect1_print(struct seq_file *s, void *p)
982{
983 int acc_detect1_raw;
984 int acc_detect1_convert;
985 struct ab8500_gpadc *gpadc;
986
8908c049 987 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
73482346
LJ
988 acc_detect1_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT1,
989 avg_sample, trig_edge, trig_timer, conv_type);
1478a316 990 acc_detect1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ACC_DETECT1,
73482346 991 acc_detect1_raw);
1478a316
JB
992
993 return seq_printf(s, "%d,0x%X\n",
994 acc_detect1_convert, acc_detect1_raw);
995}
996
997static int ab8500_gpadc_acc_detect1_open(struct inode *inode,
998 struct file *file)
999{
1000 return single_open(file, ab8500_gpadc_acc_detect1_print,
1001 inode->i_private);
1002}
1003
1004static const struct file_operations ab8500_gpadc_acc_detect1_fops = {
1005 .open = ab8500_gpadc_acc_detect1_open,
1006 .read = seq_read,
1007 .llseek = seq_lseek,
1008 .release = single_release,
1009 .owner = THIS_MODULE,
1010};
1011
1012static int ab8500_gpadc_acc_detect2_print(struct seq_file *s, void *p)
1013{
1014 int acc_detect2_raw;
1015 int acc_detect2_convert;
1016 struct ab8500_gpadc *gpadc;
1017
8908c049 1018 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
73482346
LJ
1019 acc_detect2_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT2,
1020 avg_sample, trig_edge, trig_timer, conv_type);
1478a316 1021 acc_detect2_convert = ab8500_gpadc_ad_to_voltage(gpadc,
73482346 1022 ACC_DETECT2, acc_detect2_raw);
1478a316
JB
1023
1024 return seq_printf(s, "%d,0x%X\n",
1025 acc_detect2_convert, acc_detect2_raw);
1026}
1027
1028static int ab8500_gpadc_acc_detect2_open(struct inode *inode,
1029 struct file *file)
1030{
1031 return single_open(file, ab8500_gpadc_acc_detect2_print,
1032 inode->i_private);
1033}
1034
1035static const struct file_operations ab8500_gpadc_acc_detect2_fops = {
1036 .open = ab8500_gpadc_acc_detect2_open,
1037 .read = seq_read,
1038 .llseek = seq_lseek,
1039 .release = single_release,
1040 .owner = THIS_MODULE,
1041};
1042
1043static int ab8500_gpadc_aux1_print(struct seq_file *s, void *p)
1044{
1045 int aux1_raw;
1046 int aux1_convert;
1047 struct ab8500_gpadc *gpadc;
1048
8908c049 1049 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
73482346
LJ
1050 aux1_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX1,
1051 avg_sample, trig_edge, trig_timer, conv_type);
1478a316 1052 aux1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX1,
73482346 1053 aux1_raw);
1478a316
JB
1054
1055 return seq_printf(s, "%d,0x%X\n",
1056 aux1_convert, aux1_raw);
1057}
1058
1059static int ab8500_gpadc_aux1_open(struct inode *inode, struct file *file)
1060{
1061 return single_open(file, ab8500_gpadc_aux1_print, inode->i_private);
1062}
1063
1064static const struct file_operations ab8500_gpadc_aux1_fops = {
1065 .open = ab8500_gpadc_aux1_open,
1066 .read = seq_read,
1067 .llseek = seq_lseek,
1068 .release = single_release,
1069 .owner = THIS_MODULE,
1070};
1071
1072static int ab8500_gpadc_aux2_print(struct seq_file *s, void *p)
1073{
1074 int aux2_raw;
1075 int aux2_convert;
1076 struct ab8500_gpadc *gpadc;
1077
8908c049 1078 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
73482346
LJ
1079 aux2_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX2,
1080 avg_sample, trig_edge, trig_timer, conv_type);
1478a316 1081 aux2_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX2,
73482346 1082 aux2_raw);
1478a316
JB
1083
1084 return seq_printf(s, "%d,0x%X\n",
1085 aux2_convert, aux2_raw);
1086}
1087
1088static int ab8500_gpadc_aux2_open(struct inode *inode, struct file *file)
1089{
1090 return single_open(file, ab8500_gpadc_aux2_print, inode->i_private);
1091}
1092
1093static const struct file_operations ab8500_gpadc_aux2_fops = {
1094 .open = ab8500_gpadc_aux2_open,
1095 .read = seq_read,
1096 .llseek = seq_lseek,
1097 .release = single_release,
1098 .owner = THIS_MODULE,
1099};
1100
1101static int ab8500_gpadc_main_bat_v_print(struct seq_file *s, void *p)
1102{
1103 int main_bat_v_raw;
1104 int main_bat_v_convert;
1105 struct ab8500_gpadc *gpadc;
1106
8908c049 1107 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
73482346
LJ
1108 main_bat_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_BAT_V,
1109 avg_sample, trig_edge, trig_timer, conv_type);
1478a316 1110 main_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V,
73482346 1111 main_bat_v_raw);
1478a316
JB
1112
1113 return seq_printf(s, "%d,0x%X\n",
1114 main_bat_v_convert, main_bat_v_raw);
1115}
1116
1117static int ab8500_gpadc_main_bat_v_open(struct inode *inode,
1118 struct file *file)
1119{
1120 return single_open(file, ab8500_gpadc_main_bat_v_print, inode->i_private);
1121}
1122
1123static const struct file_operations ab8500_gpadc_main_bat_v_fops = {
1124 .open = ab8500_gpadc_main_bat_v_open,
1125 .read = seq_read,
1126 .llseek = seq_lseek,
1127 .release = single_release,
1128 .owner = THIS_MODULE,
1129};
1130
1131static int ab8500_gpadc_vbus_v_print(struct seq_file *s, void *p)
1132{
1133 int vbus_v_raw;
1134 int vbus_v_convert;
1135 struct ab8500_gpadc *gpadc;
1136
8908c049 1137 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
73482346
LJ
1138 vbus_v_raw = ab8500_gpadc_read_raw(gpadc, VBUS_V,
1139 avg_sample, trig_edge, trig_timer, conv_type);
1478a316 1140 vbus_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, VBUS_V,
73482346 1141 vbus_v_raw);
1478a316
JB
1142
1143 return seq_printf(s, "%d,0x%X\n",
1144 vbus_v_convert, vbus_v_raw);
1145}
1146
1147static int ab8500_gpadc_vbus_v_open(struct inode *inode, struct file *file)
1148{
1149 return single_open(file, ab8500_gpadc_vbus_v_print, inode->i_private);
1150}
1151
1152static const struct file_operations ab8500_gpadc_vbus_v_fops = {
1153 .open = ab8500_gpadc_vbus_v_open,
1154 .read = seq_read,
1155 .llseek = seq_lseek,
1156 .release = single_release,
1157 .owner = THIS_MODULE,
1158};
1159
1160static int ab8500_gpadc_main_charger_c_print(struct seq_file *s, void *p)
1161{
1162 int main_charger_c_raw;
1163 int main_charger_c_convert;
1164 struct ab8500_gpadc *gpadc;
1165
8908c049 1166 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
73482346
LJ
1167 main_charger_c_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_C,
1168 avg_sample, trig_edge, trig_timer, conv_type);
1478a316 1169 main_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
73482346 1170 MAIN_CHARGER_C, main_charger_c_raw);
1478a316
JB
1171
1172 return seq_printf(s, "%d,0x%X\n",
1173 main_charger_c_convert, main_charger_c_raw);
1174}
1175
1176static int ab8500_gpadc_main_charger_c_open(struct inode *inode,
1177 struct file *file)
1178{
1179 return single_open(file, ab8500_gpadc_main_charger_c_print,
1180 inode->i_private);
1181}
1182
1183static const struct file_operations ab8500_gpadc_main_charger_c_fops = {
1184 .open = ab8500_gpadc_main_charger_c_open,
1185 .read = seq_read,
1186 .llseek = seq_lseek,
1187 .release = single_release,
1188 .owner = THIS_MODULE,
1189};
1190
1191static int ab8500_gpadc_usb_charger_c_print(struct seq_file *s, void *p)
1192{
1193 int usb_charger_c_raw;
1194 int usb_charger_c_convert;
1195 struct ab8500_gpadc *gpadc;
1196
8908c049 1197 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
73482346
LJ
1198 usb_charger_c_raw = ab8500_gpadc_read_raw(gpadc, USB_CHARGER_C,
1199 avg_sample, trig_edge, trig_timer, conv_type);
1478a316 1200 usb_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
73482346 1201 USB_CHARGER_C, usb_charger_c_raw);
1478a316
JB
1202
1203 return seq_printf(s, "%d,0x%X\n",
1204 usb_charger_c_convert, usb_charger_c_raw);
1205}
1206
1207static int ab8500_gpadc_usb_charger_c_open(struct inode *inode,
1208 struct file *file)
1209{
1210 return single_open(file, ab8500_gpadc_usb_charger_c_print,
1211 inode->i_private);
1212}
1213
1214static const struct file_operations ab8500_gpadc_usb_charger_c_fops = {
1215 .open = ab8500_gpadc_usb_charger_c_open,
1216 .read = seq_read,
1217 .llseek = seq_lseek,
1218 .release = single_release,
1219 .owner = THIS_MODULE,
1220};
1221
1222static int ab8500_gpadc_bk_bat_v_print(struct seq_file *s, void *p)
1223{
1224 int bk_bat_v_raw;
1225 int bk_bat_v_convert;
1226 struct ab8500_gpadc *gpadc;
1227
8908c049 1228 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
73482346
LJ
1229 bk_bat_v_raw = ab8500_gpadc_read_raw(gpadc, BK_BAT_V,
1230 avg_sample, trig_edge, trig_timer, conv_type);
1478a316 1231 bk_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
73482346 1232 BK_BAT_V, bk_bat_v_raw);
1478a316
JB
1233
1234 return seq_printf(s, "%d,0x%X\n",
1235 bk_bat_v_convert, bk_bat_v_raw);
1236}
1237
1238static int ab8500_gpadc_bk_bat_v_open(struct inode *inode, struct file *file)
1239{
1240 return single_open(file, ab8500_gpadc_bk_bat_v_print, inode->i_private);
1241}
1242
1243static const struct file_operations ab8500_gpadc_bk_bat_v_fops = {
1244 .open = ab8500_gpadc_bk_bat_v_open,
1245 .read = seq_read,
1246 .llseek = seq_lseek,
1247 .release = single_release,
1248 .owner = THIS_MODULE,
1249};
1250
1251static int ab8500_gpadc_die_temp_print(struct seq_file *s, void *p)
1252{
1253 int die_temp_raw;
1254 int die_temp_convert;
1255 struct ab8500_gpadc *gpadc;
1256
8908c049 1257 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
73482346
LJ
1258 die_temp_raw = ab8500_gpadc_read_raw(gpadc, DIE_TEMP,
1259 avg_sample, trig_edge, trig_timer, conv_type);
1478a316 1260 die_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, DIE_TEMP,
73482346 1261 die_temp_raw);
1478a316
JB
1262
1263 return seq_printf(s, "%d,0x%X\n",
1264 die_temp_convert, die_temp_raw);
1265}
1266
1267static int ab8500_gpadc_die_temp_open(struct inode *inode, struct file *file)
1268{
1269 return single_open(file, ab8500_gpadc_die_temp_print, inode->i_private);
1270}
1271
1272static const struct file_operations ab8500_gpadc_die_temp_fops = {
1273 .open = ab8500_gpadc_die_temp_open,
1274 .read = seq_read,
1275 .llseek = seq_lseek,
1276 .release = single_release,
1277 .owner = THIS_MODULE,
1278};
1279
73482346
LJ
1280static int ab8500_gpadc_avg_sample_print(struct seq_file *s, void *p)
1281{
1282 return seq_printf(s, "%d\n", avg_sample);
1283}
1284
1285static int ab8500_gpadc_avg_sample_open(struct inode *inode, struct file *file)
1286{
1287 return single_open(file, ab8500_gpadc_avg_sample_print,
1288 inode->i_private);
1289}
1290
1291static ssize_t ab8500_gpadc_avg_sample_write(struct file *file,
1292 const char __user *user_buf,
1293 size_t count, loff_t *ppos)
1294{
1295 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1296 char buf[32];
1297 int buf_size;
1298 unsigned long user_avg_sample;
1299 int err;
1300
1301 /* Get userspace string and assure termination */
1302 buf_size = min(count, (sizeof(buf) - 1));
1303 if (copy_from_user(buf, user_buf, buf_size))
1304 return -EFAULT;
1305 buf[buf_size] = 0;
1306
1307 err = strict_strtoul(buf, 0, &user_avg_sample);
1308 if (err)
1309 return -EINVAL;
1310 if ((user_avg_sample == SAMPLE_1) || (user_avg_sample == SAMPLE_4)
1311 || (user_avg_sample == SAMPLE_8)
1312 || (user_avg_sample == SAMPLE_16)) {
1313 avg_sample = (u8) user_avg_sample;
1314 } else {
1315 dev_err(dev, "debugfs error input: "
1316 "should be egal to 1, 4, 8 or 16\n");
1317 return -EINVAL;
1318 }
1319 return buf_size;
1320}
1321
1322static const struct file_operations ab8500_gpadc_avg_sample_fops = {
1323 .open = ab8500_gpadc_avg_sample_open,
1324 .read = seq_read,
1325 .write = ab8500_gpadc_avg_sample_write,
1326 .llseek = seq_lseek,
1327 .release = single_release,
1328 .owner = THIS_MODULE,
1329};
1330
1331static int ab8500_gpadc_trig_edge_print(struct seq_file *s, void *p)
1332{
1333 return seq_printf(s, "%d\n", trig_edge);
1334}
1335
1336static int ab8500_gpadc_trig_edge_open(struct inode *inode, struct file *file)
1337{
1338 return single_open(file, ab8500_gpadc_trig_edge_print,
1339 inode->i_private);
1340}
1341
1342static ssize_t ab8500_gpadc_trig_edge_write(struct file *file,
1343 const char __user *user_buf,
1344 size_t count, loff_t *ppos)
1345{
1346 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1347 char buf[32];
1348 int buf_size;
1349 unsigned long user_trig_edge;
1350 int err;
1351
1352 /* Get userspace string and assure termination */
1353 buf_size = min(count, (sizeof(buf) - 1));
1354 if (copy_from_user(buf, user_buf, buf_size))
1355 return -EFAULT;
1356 buf[buf_size] = 0;
1357
1358 err = strict_strtoul(buf, 0, &user_trig_edge);
1359 if (err)
1360 return -EINVAL;
1361 if ((user_trig_edge == RISING_EDGE)
1362 || (user_trig_edge == FALLING_EDGE)) {
1363 trig_edge = (u8) user_trig_edge;
1364 } else {
1365 dev_err(dev, "Wrong input:\n"
1366 "Enter 0. Rising edge\n"
1367 "Enter 1. Falling edge\n");
1368 return -EINVAL;
1369 }
1370 return buf_size;
1371}
1372
1373static const struct file_operations ab8500_gpadc_trig_edge_fops = {
1374 .open = ab8500_gpadc_trig_edge_open,
1375 .read = seq_read,
1376 .write = ab8500_gpadc_trig_edge_write,
1377 .llseek = seq_lseek,
1378 .release = single_release,
1379 .owner = THIS_MODULE,
1380};
1381
1382static int ab8500_gpadc_trig_timer_print(struct seq_file *s, void *p)
1383{
1384 return seq_printf(s, "%d\n", trig_timer);
1385}
1386
1387static int ab8500_gpadc_trig_timer_open(struct inode *inode, struct file *file)
1388{
1389 return single_open(file, ab8500_gpadc_trig_timer_print,
1390 inode->i_private);
1391}
1392
1393static ssize_t ab8500_gpadc_trig_timer_write(struct file *file,
1394 const char __user *user_buf,
1395 size_t count, loff_t *ppos)
1396{
1397 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1398 char buf[32];
1399 int buf_size;
1400 unsigned long user_trig_timer;
1401 int err;
1402
1403 /* Get userspace string and assure termination */
1404 buf_size = min(count, (sizeof(buf) - 1));
1405 if (copy_from_user(buf, user_buf, buf_size))
1406 return -EFAULT;
1407 buf[buf_size] = 0;
1408
1409 err = strict_strtoul(buf, 0, &user_trig_timer);
1410 if (err)
1411 return -EINVAL;
1412 if ((user_trig_timer >= 0) && (user_trig_timer <= 255)) {
1413 trig_timer = (u8) user_trig_timer;
1414 } else {
1415 dev_err(dev, "debugfs error input: "
1416 "should be beetween 0 to 255\n");
1417 return -EINVAL;
1418 }
1419 return buf_size;
1420}
1421
1422static const struct file_operations ab8500_gpadc_trig_timer_fops = {
1423 .open = ab8500_gpadc_trig_timer_open,
1424 .read = seq_read,
1425 .write = ab8500_gpadc_trig_timer_write,
1426 .llseek = seq_lseek,
1427 .release = single_release,
1428 .owner = THIS_MODULE,
1429};
1430
1431static int ab8500_gpadc_conv_type_print(struct seq_file *s, void *p)
1432{
1433 return seq_printf(s, "%d\n", conv_type);
1434}
1435
1436static int ab8500_gpadc_conv_type_open(struct inode *inode, struct file *file)
1437{
1438 return single_open(file, ab8500_gpadc_conv_type_print,
1439 inode->i_private);
1440}
1441
1442static ssize_t ab8500_gpadc_conv_type_write(struct file *file,
1443 const char __user *user_buf,
1444 size_t count, loff_t *ppos)
1445{
1446 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1447 char buf[32];
1448 int buf_size;
1449 unsigned long user_conv_type;
1450 int err;
1451
1452 /* Get userspace string and assure termination */
1453 buf_size = min(count, (sizeof(buf) - 1));
1454 if (copy_from_user(buf, user_buf, buf_size))
1455 return -EFAULT;
1456 buf[buf_size] = 0;
1457
1458 err = strict_strtoul(buf, 0, &user_conv_type);
1459 if (err)
1460 return -EINVAL;
1461 if ((user_conv_type == ADC_SW)
1462 || (user_conv_type == ADC_HW)) {
1463 conv_type = (u8) user_conv_type;
1464 } else {
1465 dev_err(dev, "Wrong input:\n"
1466 "Enter 0. ADC SW conversion\n"
1467 "Enter 1. ADC HW conversion\n");
1468 return -EINVAL;
1469 }
1470 return buf_size;
1471}
1472
1473static const struct file_operations ab8500_gpadc_conv_type_fops = {
1474 .open = ab8500_gpadc_conv_type_open,
1475 .read = seq_read,
1476 .write = ab8500_gpadc_conv_type_write,
1477 .llseek = seq_lseek,
1478 .release = single_release,
1479 .owner = THIS_MODULE,
1480};
1481
0fbce76e 1482/*
1483 * return length of an ASCII numerical value, 0 is string is not a
1484 * numerical value.
1485 * string shall start at value 1st char.
1486 * string can be tailed with \0 or space or newline chars only.
1487 * value can be decimal or hexadecimal (prefixed 0x or 0X).
1488 */
1489static int strval_len(char *b)
1490{
1491 char *s = b;
1492 if ((*s == '0') && ((*(s+1) == 'x') || (*(s+1) == 'X'))) {
1493 s += 2;
1494 for (; *s && (*s != ' ') && (*s != '\n'); s++) {
1495 if (!isxdigit(*s))
1496 return 0;
1497 }
1498 } else {
1499 if (*s == '-')
1500 s++;
1501 for (; *s && (*s != ' ') && (*s != '\n'); s++) {
1502 if (!isdigit(*s))
1503 return 0;
1504 }
1505 }
1506 return (int) (s-b);
1507}
1508
1509/*
1510 * parse hwreg input data.
1511 * update global hwreg_cfg only if input data syntax is ok.
1512 */
1513static ssize_t hwreg_common_write(char *b, struct hwreg_cfg *cfg,
1514 struct device *dev)
1515{
1516 uint write, val = 0;
1517 u8 regvalue;
1518 int ret;
1519 struct hwreg_cfg loc = {
1520 .bank = 0, /* default: invalid phys addr */
1521 .addr = 0, /* default: invalid phys addr */
1522 .fmt = 0, /* default: 32bit access, hex output */
1523 .mask = 0xFFFFFFFF, /* default: no mask */
1524 .shift = 0, /* default: no bit shift */
1525 };
1526
1527 /* read or write ? */
1528 if (!strncmp(b, "read ", 5)) {
1529 write = 0;
1530 b += 5;
1531 } else if (!strncmp(b, "write ", 6)) {
1532 write = 1;
1533 b += 6;
1534 } else
1535 return -EINVAL;
1536
1537 /* OPTIONS -l|-w|-b -s -m -o */
1538 while ((*b == ' ') || (*b == '-')) {
1539 if (*(b-1) != ' ') {
1540 b++;
1541 continue;
1542 }
1543 if ((!strncmp(b, "-d ", 3)) ||
1544 (!strncmp(b, "-dec ", 5))) {
1545 b += (*(b+2) == ' ') ? 3 : 5;
1546 loc.fmt |= (1<<0);
1547 } else if ((!strncmp(b, "-h ", 3)) ||
1548 (!strncmp(b, "-hex ", 5))) {
1549 b += (*(b+2) == ' ') ? 3 : 5;
1550 loc.fmt &= ~(1<<0);
1551 } else if ((!strncmp(b, "-m ", 3)) ||
1552 (!strncmp(b, "-mask ", 6))) {
1553 b += (*(b+2) == ' ') ? 3 : 6;
1554 if (strval_len(b) == 0)
1555 return -EINVAL;
1556 loc.mask = simple_strtoul(b, &b, 0);
1557 } else if ((!strncmp(b, "-s ", 3)) ||
1558 (!strncmp(b, "-shift ", 7))) {
1559 b += (*(b+2) == ' ') ? 3 : 7;
1560 if (strval_len(b) == 0)
1561 return -EINVAL;
1562 loc.shift = simple_strtol(b, &b, 0);
1563 } else {
1564 return -EINVAL;
1565 }
1566 }
1567 /* get arg BANK and ADDRESS */
1568 if (strval_len(b) == 0)
1569 return -EINVAL;
1570 loc.bank = simple_strtoul(b, &b, 0);
1571 while (*b == ' ')
1572 b++;
1573 if (strval_len(b) == 0)
1574 return -EINVAL;
1575 loc.addr = simple_strtoul(b, &b, 0);
1576
1577 if (write) {
1578 while (*b == ' ')
1579 b++;
1580 if (strval_len(b) == 0)
1581 return -EINVAL;
1582 val = simple_strtoul(b, &b, 0);
1583 }
1584
1585 /* args are ok, update target cfg (mainly for read) */
1586 *cfg = loc;
1587
1588#ifdef ABB_HWREG_DEBUG
1589 pr_warn("HWREG request: %s, %s, addr=0x%08X, mask=0x%X, shift=%d"
1590 "value=0x%X\n", (write) ? "write" : "read",
1591 REG_FMT_DEC(cfg) ? "decimal" : "hexa",
1592 cfg->addr, cfg->mask, cfg->shift, val);
1593#endif
1594
1595 if (!write)
1596 return 0;
1597
1598 ret = abx500_get_register_interruptible(dev,
1599 (u8)cfg->bank, (u8)cfg->addr, &regvalue);
1600 if (ret < 0) {
1601 dev_err(dev, "abx500_get_reg fail %d, %d\n",
1602 ret, __LINE__);
1603 return -EINVAL;
1604 }
1605
1606 if (cfg->shift >= 0) {
1607 regvalue &= ~(cfg->mask << (cfg->shift));
1608 val = (val & cfg->mask) << (cfg->shift);
1609 } else {
1610 regvalue &= ~(cfg->mask >> (-cfg->shift));
1611 val = (val & cfg->mask) >> (-cfg->shift);
1612 }
1613 val = val | regvalue;
1614
1615 ret = abx500_set_register_interruptible(dev,
1616 (u8)cfg->bank, (u8)cfg->addr, (u8)val);
1617 if (ret < 0) {
1618 pr_err("abx500_set_reg failed %d, %d", ret, __LINE__);
1619 return -EINVAL;
1620 }
1621
1622 return 0;
1623}
1624
1625static ssize_t ab8500_hwreg_write(struct file *file,
1626 const char __user *user_buf, size_t count, loff_t *ppos)
1627{
1628 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1629 char buf[128];
1630 int buf_size, ret;
1631
1632 /* Get userspace string and assure termination */
1633 buf_size = min(count, (sizeof(buf)-1));
1634 if (copy_from_user(buf, user_buf, buf_size))
1635 return -EFAULT;
1636 buf[buf_size] = 0;
1637
1638 /* get args and process */
1639 ret = hwreg_common_write(buf, &hwreg_cfg, dev);
1640 return (ret) ? ret : buf_size;
1641}
1642
1643/*
1644 * - irq subscribe/unsubscribe stuff
1645 */
4b8ac082
LJ
1646static int ab8500_subscribe_unsubscribe_print(struct seq_file *s, void *p)
1647{
1648 seq_printf(s, "%d\n", irq_first);
1649
1650 return 0;
1651}
1652
1653static int ab8500_subscribe_unsubscribe_open(struct inode *inode,
1654 struct file *file)
1655{
1656 return single_open(file, ab8500_subscribe_unsubscribe_print,
1657 inode->i_private);
1658}
1659
1660/*
0b337e70 1661 * Userspace should use poll() on this file. When an event occur
4b8ac082
LJ
1662 * the blocking poll will be released.
1663 */
1664static ssize_t show_irq(struct device *dev,
1665 struct device_attribute *attr, char *buf)
1666{
0b337e70
MW
1667 unsigned long name;
1668 unsigned int irq_index;
1669 int err;
4b8ac082 1670
0b337e70
MW
1671 err = strict_strtoul(attr->attr.name, 0, &name);
1672 if (err)
1673 return err;
1674
1675 irq_index = name - irq_first;
ddba25f1 1676 if (irq_index >= num_irqs)
0b337e70
MW
1677 return -EINVAL;
1678 else
1679 return sprintf(buf, "%u\n", irq_count[irq_index]);
1680}
4b8ac082
LJ
1681
1682static ssize_t ab8500_subscribe_write(struct file *file,
1683 const char __user *user_buf,
1684 size_t count, loff_t *ppos)
1685{
1686 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1687 char buf[32];
1688 int buf_size;
1689 unsigned long user_val;
1690 int err;
0b337e70 1691 unsigned int irq_index;
4b8ac082
LJ
1692
1693 /* Get userspace string and assure termination */
1694 buf_size = min(count, (sizeof(buf)-1));
1695 if (copy_from_user(buf, user_buf, buf_size))
1696 return -EFAULT;
1697 buf[buf_size] = 0;
1698
1699 err = strict_strtoul(buf, 0, &user_val);
1700 if (err)
1701 return -EINVAL;
1702 if (user_val < irq_first) {
1703 dev_err(dev, "debugfs error input < %d\n", irq_first);
1704 return -EINVAL;
1705 }
1706 if (user_val > irq_last) {
1707 dev_err(dev, "debugfs error input > %d\n", irq_last);
1708 return -EINVAL;
1709 }
1710
0b337e70 1711 irq_index = user_val - irq_first;
ddba25f1 1712 if (irq_index >= num_irqs)
0b337e70
MW
1713 return -EINVAL;
1714
4b8ac082 1715 /*
0b337e70 1716 * This will create a sysfs file named <irq-nr> which userspace can
4b8ac082
LJ
1717 * use to select or poll and get the AB8500 events
1718 */
0b337e70
MW
1719 dev_attr[irq_index] = kmalloc(sizeof(struct device_attribute),
1720 GFP_KERNEL);
1721 event_name[irq_index] = kmalloc(buf_size, GFP_KERNEL);
1722 sprintf(event_name[irq_index], "%lu", user_val);
1723 dev_attr[irq_index]->show = show_irq;
1724 dev_attr[irq_index]->store = NULL;
1725 dev_attr[irq_index]->attr.name = event_name[irq_index];
1726 dev_attr[irq_index]->attr.mode = S_IRUGO;
1727 err = sysfs_create_file(&dev->kobj, &dev_attr[irq_index]->attr);
4b8ac082
LJ
1728 if (err < 0) {
1729 printk(KERN_ERR "sysfs_create_file failed %d\n", err);
1730 return err;
1731 }
1732
1733 err = request_threaded_irq(user_val, NULL, ab8500_debug_handler,
1734 IRQF_SHARED | IRQF_NO_SUSPEND,
1735 "ab8500-debug", &dev->kobj);
1736 if (err < 0) {
1737 printk(KERN_ERR "request_threaded_irq failed %d, %lu\n",
1738 err, user_val);
0b337e70 1739 sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr);
4b8ac082
LJ
1740 return err;
1741 }
1742
1743 return buf_size;
1744}
1745
1746static ssize_t ab8500_unsubscribe_write(struct file *file,
1747 const char __user *user_buf,
1748 size_t count, loff_t *ppos)
1749{
1750 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1751 char buf[32];
1752 int buf_size;
1753 unsigned long user_val;
1754 int err;
0b337e70 1755 unsigned int irq_index;
4b8ac082
LJ
1756
1757 /* Get userspace string and assure termination */
1758 buf_size = min(count, (sizeof(buf)-1));
1759 if (copy_from_user(buf, user_buf, buf_size))
1760 return -EFAULT;
1761 buf[buf_size] = 0;
1762
1763 err = strict_strtoul(buf, 0, &user_val);
1764 if (err)
1765 return -EINVAL;
1766 if (user_val < irq_first) {
1767 dev_err(dev, "debugfs error input < %d\n", irq_first);
1768 return -EINVAL;
1769 }
1770 if (user_val > irq_last) {
1771 dev_err(dev, "debugfs error input > %d\n", irq_last);
1772 return -EINVAL;
1773 }
1774
0b337e70 1775 irq_index = user_val - irq_first;
ddba25f1 1776 if (irq_index >= num_irqs)
0b337e70
MW
1777 return -EINVAL;
1778
1779 /* Set irq count to 0 when unsubscribe */
1780 irq_count[irq_index] = 0;
1781
1782 if (dev_attr[irq_index])
1783 sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr);
4b8ac082 1784
0b337e70
MW
1785
1786 free_irq(user_val, &dev->kobj);
1787 kfree(event_name[irq_index]);
1788 kfree(dev_attr[irq_index]);
4b8ac082
LJ
1789
1790 return buf_size;
1791}
1792
0fbce76e 1793/*
1794 * - several deubgfs nodes fops
1795 */
1796
5814fc35 1797static const struct file_operations ab8500_bank_fops = {
d7b9f322
MW
1798 .open = ab8500_bank_open,
1799 .write = ab8500_bank_write,
1800 .read = seq_read,
1801 .llseek = seq_lseek,
1802 .release = single_release,
1803 .owner = THIS_MODULE,
5814fc35
MW
1804};
1805
1806static const struct file_operations ab8500_address_fops = {
d7b9f322
MW
1807 .open = ab8500_address_open,
1808 .write = ab8500_address_write,
1809 .read = seq_read,
1810 .llseek = seq_lseek,
1811 .release = single_release,
1812 .owner = THIS_MODULE,
5814fc35
MW
1813};
1814
1815static const struct file_operations ab8500_val_fops = {
d7b9f322
MW
1816 .open = ab8500_val_open,
1817 .write = ab8500_val_write,
1818 .read = seq_read,
1819 .llseek = seq_lseek,
1820 .release = single_release,
1821 .owner = THIS_MODULE,
5814fc35
MW
1822};
1823
8f0eb43b
BJ
1824static const struct file_operations ab8500_interrupts_fops = {
1825 .open = ab8500_interrupts_open,
1826 .read = seq_read,
1827 .llseek = seq_lseek,
1828 .release = single_release,
1829 .owner = THIS_MODULE,
1830};
1831
4b8ac082
LJ
1832static const struct file_operations ab8500_subscribe_fops = {
1833 .open = ab8500_subscribe_unsubscribe_open,
1834 .write = ab8500_subscribe_write,
1835 .read = seq_read,
1836 .llseek = seq_lseek,
1837 .release = single_release,
1838 .owner = THIS_MODULE,
1839};
1840
1841static const struct file_operations ab8500_unsubscribe_fops = {
1842 .open = ab8500_subscribe_unsubscribe_open,
1843 .write = ab8500_unsubscribe_write,
1844 .read = seq_read,
1845 .llseek = seq_lseek,
1846 .release = single_release,
1847 .owner = THIS_MODULE,
1848};
1849
0fbce76e 1850static const struct file_operations ab8500_hwreg_fops = {
1851 .open = ab8500_hwreg_open,
1852 .write = ab8500_hwreg_write,
1853 .read = seq_read,
1854 .llseek = seq_lseek,
1855 .release = single_release,
1856 .owner = THIS_MODULE,
1857};
1858
5814fc35 1859static struct dentry *ab8500_dir;
1478a316 1860static struct dentry *ab8500_gpadc_dir;
5814fc35 1861
f791be49 1862static int ab8500_debug_probe(struct platform_device *plf)
5814fc35 1863{
0fbce76e 1864 struct dentry *file;
ddba25f1
LW
1865 int ret = -ENOMEM;
1866 struct ab8500 *ab8500;
d7b9f322
MW
1867 debug_bank = AB8500_MISC;
1868 debug_address = AB8500_REV_REG & 0x00FF;
5814fc35 1869
ddba25f1
LW
1870 ab8500 = dev_get_drvdata(plf->dev.parent);
1871 num_irqs = ab8500->mask_size;
1872
70bad04f 1873 irq_count = kzalloc(sizeof(*irq_count)*num_irqs, GFP_KERNEL);
ddba25f1
LW
1874 if (!irq_count)
1875 return -ENOMEM;
1876
1877 dev_attr = kzalloc(sizeof(*dev_attr)*num_irqs,GFP_KERNEL);
1878 if (!dev_attr)
1879 goto out_freeirq_count;
1880
1881 event_name = kzalloc(sizeof(*event_name)*num_irqs, GFP_KERNEL);
1882 if (!event_name)
1883 goto out_freedev_attr;
1884
4b8ac082
LJ
1885 irq_first = platform_get_irq_byname(plf, "IRQ_FIRST");
1886 if (irq_first < 0) {
1887 dev_err(&plf->dev, "First irq not found, err %d\n",
1478a316 1888 irq_first);
ddba25f1
LW
1889 ret = irq_first;
1890 goto out_freeevent_name;
4b8ac082
LJ
1891 }
1892
1893 irq_last = platform_get_irq_byname(plf, "IRQ_LAST");
1894 if (irq_last < 0) {
1895 dev_err(&plf->dev, "Last irq not found, err %d\n",
1478a316 1896 irq_last);
ddba25f1 1897 ret = irq_last;
2cf64e26 1898 goto out_freeevent_name;
4b8ac082
LJ
1899 }
1900
d7b9f322
MW
1901 ab8500_dir = debugfs_create_dir(AB8500_NAME_STRING, NULL);
1902 if (!ab8500_dir)
0fbce76e 1903 goto err;
5814fc35 1904
1478a316
JB
1905 ab8500_gpadc_dir = debugfs_create_dir(AB8500_ADC_NAME_STRING,
1906 ab8500_dir);
1907 if (!ab8500_gpadc_dir)
1908 goto err;
1909
1910 file = debugfs_create_file("all-bank-registers", S_IRUGO,
1911 ab8500_dir, &plf->dev, &ab8500_registers_fops);
1912 if (!file)
1913 goto err;
1914
42002c6d
MYK
1915 file = debugfs_create_file("all-banks", S_IRUGO,
1916 ab8500_dir, &plf->dev, &ab8500_all_banks_fops);
1917 if (!file)
1918 goto err;
1919
1478a316
JB
1920 file = debugfs_create_file("register-bank", (S_IRUGO | S_IWUSR),
1921 ab8500_dir, &plf->dev, &ab8500_bank_fops);
1922 if (!file)
1923 goto err;
1924
1925 file = debugfs_create_file("register-address", (S_IRUGO | S_IWUSR),
1926 ab8500_dir, &plf->dev, &ab8500_address_fops);
1927 if (!file)
1928 goto err;
1929
1930 file = debugfs_create_file("register-value", (S_IRUGO | S_IWUSR),
1931 ab8500_dir, &plf->dev, &ab8500_val_fops);
1932 if (!file)
1933 goto err;
1934
1935 file = debugfs_create_file("irq-subscribe", (S_IRUGO | S_IWUSR),
1936 ab8500_dir, &plf->dev, &ab8500_subscribe_fops);
1937 if (!file)
1938 goto err;
1939
8f0eb43b
BJ
1940 if (is_ab8500(ab8500))
1941 num_interrupt_lines = AB8500_NR_IRQS;
1942 else if (is_ab8505(ab8500))
1943 num_interrupt_lines = AB8505_NR_IRQS;
1944 else if (is_ab9540(ab8500))
1945 num_interrupt_lines = AB9540_NR_IRQS;
1946
1947 file = debugfs_create_file("interrupts", (S_IRUGO),
1948 ab8500_dir, &plf->dev, &ab8500_interrupts_fops);
1949 if (!file)
1950 goto err;
1951
1478a316
JB
1952 file = debugfs_create_file("irq-unsubscribe", (S_IRUGO | S_IWUSR),
1953 ab8500_dir, &plf->dev, &ab8500_unsubscribe_fops);
1954 if (!file)
1955 goto err;
1956
1957 file = debugfs_create_file("hwreg", (S_IRUGO | S_IWUSR),
1958 ab8500_dir, &plf->dev, &ab8500_hwreg_fops);
1959 if (!file)
1960 goto err;
1961
1962 file = debugfs_create_file("bat_ctrl", (S_IRUGO | S_IWUSR),
1963 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_bat_ctrl_fops);
1964 if (!file)
1965 goto err;
1966
1967 file = debugfs_create_file("btemp_ball", (S_IRUGO | S_IWUSR),
1968 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_btemp_ball_fops);
1969 if (!file)
1970 goto err;
1971
1972 file = debugfs_create_file("main_charger_v", (S_IRUGO | S_IWUSR),
1973 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_charger_v_fops);
1974 if (!file)
1975 goto err;
1976
1977 file = debugfs_create_file("acc_detect1", (S_IRUGO | S_IWUSR),
1978 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_acc_detect1_fops);
1979 if (!file)
1980 goto err;
1981
1982 file = debugfs_create_file("acc_detect2", (S_IRUGO | S_IWUSR),
1983 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_acc_detect2_fops);
1984 if (!file)
1985 goto err;
1986
1987 file = debugfs_create_file("adc_aux1", (S_IRUGO | S_IWUSR),
1988 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_aux1_fops);
1989 if (!file)
1990 goto err;
1991
1992 file = debugfs_create_file("adc_aux2", (S_IRUGO | S_IWUSR),
1993 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_aux2_fops);
0fbce76e 1994 if (!file)
1995 goto err;
5814fc35 1996
1478a316
JB
1997 file = debugfs_create_file("main_bat_v", (S_IRUGO | S_IWUSR),
1998 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_bat_v_fops);
0fbce76e 1999 if (!file)
2000 goto err;
5814fc35 2001
1478a316
JB
2002 file = debugfs_create_file("vbus_v", (S_IRUGO | S_IWUSR),
2003 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_vbus_v_fops);
0fbce76e 2004 if (!file)
2005 goto err;
5814fc35 2006
1478a316
JB
2007 file = debugfs_create_file("main_charger_c", (S_IRUGO | S_IWUSR),
2008 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_charger_c_fops);
0fbce76e 2009 if (!file)
2010 goto err;
2011
1478a316
JB
2012 file = debugfs_create_file("usb_charger_c", (S_IRUGO | S_IWUSR),
2013 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_usb_charger_c_fops);
0fbce76e 2014 if (!file)
2015 goto err;
2016
1478a316
JB
2017 file = debugfs_create_file("bk_bat_v", (S_IRUGO | S_IWUSR),
2018 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_bk_bat_v_fops);
0fbce76e 2019 if (!file)
2020 goto err;
2021
1478a316
JB
2022 file = debugfs_create_file("die_temp", (S_IRUGO | S_IWUSR),
2023 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_die_temp_fops);
0fbce76e 2024 if (!file)
2025 goto err;
73482346
LJ
2026
2027 file = debugfs_create_file("avg_sample", (S_IRUGO | S_IWUGO),
2028 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_avg_sample_fops);
2029 if (!file)
2030 goto err;
2031
2032 file = debugfs_create_file("trig_edge", (S_IRUGO | S_IWUGO),
2033 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_trig_edge_fops);
2034 if (!file)
2035 goto err;
2036
2037 file = debugfs_create_file("trig_timer", (S_IRUGO | S_IWUGO),
2038 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_trig_timer_fops);
2039 if (!file)
2040 goto err;
2041
2042 file = debugfs_create_file("conv_type", (S_IRUGO | S_IWUGO),
2043 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_conv_type_fops);
2044 if (!file)
2045 goto err;
4b8ac082 2046
d7b9f322 2047 return 0;
5814fc35 2048
0fbce76e 2049err:
2050 if (ab8500_dir)
2051 debugfs_remove_recursive(ab8500_dir);
d7b9f322 2052 dev_err(&plf->dev, "failed to create debugfs entries.\n");
ddba25f1
LW
2053out_freeevent_name:
2054 kfree(event_name);
2055out_freedev_attr:
2056 kfree(dev_attr);
2057out_freeirq_count:
2058 kfree(irq_count);
2059
2060 return ret;
5814fc35
MW
2061}
2062
4740f73f 2063static int ab8500_debug_remove(struct platform_device *plf)
5814fc35 2064{
0fbce76e 2065 debugfs_remove_recursive(ab8500_dir);
ddba25f1
LW
2066 kfree(event_name);
2067 kfree(dev_attr);
2068 kfree(irq_count);
2069
d7b9f322 2070 return 0;
5814fc35
MW
2071}
2072
2073static struct platform_driver ab8500_debug_driver = {
d7b9f322
MW
2074 .driver = {
2075 .name = "ab8500-debug",
2076 .owner = THIS_MODULE,
2077 },
2078 .probe = ab8500_debug_probe,
84449216 2079 .remove = ab8500_debug_remove
5814fc35
MW
2080};
2081
2082static int __init ab8500_debug_init(void)
2083{
d7b9f322 2084 return platform_driver_register(&ab8500_debug_driver);
5814fc35
MW
2085}
2086
2087static void __exit ab8500_debug_exit(void)
2088{
d7b9f322 2089 platform_driver_unregister(&ab8500_debug_driver);
5814fc35
MW
2090}
2091subsys_initcall(ab8500_debug_init);
2092module_exit(ab8500_debug_exit);
2093
2094MODULE_AUTHOR("Mattias WALLIN <mattias.wallin@stericsson.com");
2095MODULE_DESCRIPTION("AB8500 DEBUG");
2096MODULE_LICENSE("GPL v2");
This page took 0.243198 seconds and 5 git commands to generate.