aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorMian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>2012-01-26 09:39:20 -0500
committerLee Jones <lee.jones@linaro.org>2013-02-04 03:31:45 -0500
commit42002c6de9ee1916a118d6a732c533bfe138ed6f (patch)
tree98032839ad9448d44c3318368da7a13a12bc1061 /drivers
parent40c064e43ee4db4159331a1c421d0df577b447dd (diff)
mfd: ab8500-debugfs: add debugfs node to read all registers
Update the ab8500_registers_print() to reuse it from multiple places. Signed-off-by: Lee Jones <lee.jones@linaro.org> Signed-off-by: Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com> Reviewed-by: Linus WALLEIJ <linus.walleij@stericsson.com> Reviewed-by: Jonas ABERG <jonas.aberg@stericsson.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/mfd/ab8500-debugfs.c95
1 files changed, 81 insertions, 14 deletions
diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
index 226d751d7e51..cd3cee814fb7 100644
--- a/drivers/mfd/ab8500-debugfs.c
+++ b/drivers/mfd/ab8500-debugfs.c
@@ -495,15 +495,12 @@ static irqreturn_t ab8500_debug_handler(int irq, void *data)
495 return IRQ_HANDLED; 495 return IRQ_HANDLED;
496} 496}
497 497
498static int ab8500_registers_print(struct seq_file *s, void *p) 498/* Prints to seq_file or log_buf */
499static int ab8500_registers_print(struct device *dev, u32 bank,
500 struct seq_file *s)
499{ 501{
500 struct device *dev = s->private;
501 unsigned int i; 502 unsigned int i;
502 u32 bank = debug_bank;
503
504 seq_printf(s, AB8500_NAME_STRING " register values:\n");
505 503
506 seq_printf(s, " bank %u:\n", bank);
507 for (i = 0; i < debug_ranges[bank].num_ranges; i++) { 504 for (i = 0; i < debug_ranges[bank].num_ranges; i++) {
508 u32 reg; 505 u32 reg;
509 506
@@ -520,22 +517,42 @@ static int ab8500_registers_print(struct seq_file *s, void *p)
520 return err; 517 return err;
521 } 518 }
522 519
523 err = seq_printf(s, " [%u/0x%02X]: 0x%02X\n", bank, 520 if (s) {
524 reg, value); 521 err = seq_printf(s, " [%u/0x%02X]: 0x%02X\n",
525 if (err < 0) { 522 bank, reg, value);
526 dev_err(dev, "seq_printf overflow\n"); 523 if (err < 0) {
527 /* Error is not returned here since 524 dev_err(dev,
528 * the output is wanted in any case */ 525 "seq_printf overflow bank=%d reg=%d\n",
529 return 0; 526 bank, reg);
527 /* Error is not returned here since
528 * the output is wanted in any case */
529 return 0;
530 }
531 } else {
532 printk(KERN_INFO" [%u/0x%02X]: 0x%02X\n", bank,
533 reg, value);
530 } 534 }
531 } 535 }
532 } 536 }
533 return 0; 537 return 0;
534} 538}
535 539
540static int ab8500_print_bank_registers(struct seq_file *s, void *p)
541{
542 struct device *dev = s->private;
543 u32 bank = debug_bank;
544
545 seq_printf(s, AB8500_NAME_STRING " register values:\n");
546
547 seq_printf(s, " bank %u:\n", bank);
548
549 ab8500_registers_print(dev, bank, s);
550 return 0;
551}
552
536static int ab8500_registers_open(struct inode *inode, struct file *file) 553static int ab8500_registers_open(struct inode *inode, struct file *file)
537{ 554{
538 return single_open(file, ab8500_registers_print, inode->i_private); 555 return single_open(file, ab8500_print_bank_registers, inode->i_private);
539} 556}
540 557
541static const struct file_operations ab8500_registers_fops = { 558static const struct file_operations ab8500_registers_fops = {
@@ -546,6 +563,51 @@ static const struct file_operations ab8500_registers_fops = {
546 .owner = THIS_MODULE, 563 .owner = THIS_MODULE,
547}; 564};
548 565
566static int ab8500_print_all_banks(struct seq_file *s, void *p)
567{
568 struct device *dev = s->private;
569 unsigned int i;
570 int err;
571
572 seq_printf(s, AB8500_NAME_STRING " register values:\n");
573
574 for (i = 1; i < AB8500_NUM_BANKS; i++) {
575 err = seq_printf(s, " bank %u:\n", i);
576 if (err < 0)
577 dev_err(dev, "seq_printf overflow, bank=%d\n", i);
578
579 ab8500_registers_print(dev, i, s);
580 }
581 return 0;
582}
583
584static int ab8500_all_banks_open(struct inode *inode, struct file *file)
585{
586 struct seq_file *s;
587 int err;
588
589 err = single_open(file, ab8500_print_all_banks, inode->i_private);
590 if (!err) {
591 /* Default buf size in seq_read is not enough */
592 s = (struct seq_file *)file->private_data;
593 s->size = (PAGE_SIZE * 2);
594 s->buf = kmalloc(s->size, GFP_KERNEL);
595 if (!s->buf) {
596 single_release(inode, file);
597 err = -ENOMEM;
598 }
599 }
600 return err;
601}
602
603static const struct file_operations ab8500_all_banks_fops = {
604 .open = ab8500_all_banks_open,
605 .read = seq_read,
606 .llseek = seq_lseek,
607 .release = single_release,
608 .owner = THIS_MODULE,
609};
610
549static int ab8500_bank_print(struct seq_file *s, void *p) 611static int ab8500_bank_print(struct seq_file *s, void *p)
550{ 612{
551 return seq_printf(s, "%d\n", debug_bank); 613 return seq_printf(s, "%d\n", debug_bank);
@@ -1477,6 +1539,11 @@ static int ab8500_debug_probe(struct platform_device *plf)
1477 if (!file) 1539 if (!file)
1478 goto err; 1540 goto err;
1479 1541
1542 file = debugfs_create_file("all-banks", S_IRUGO,
1543 ab8500_dir, &plf->dev, &ab8500_all_banks_fops);
1544 if (!file)
1545 goto err;
1546
1480 file = debugfs_create_file("register-bank", (S_IRUGO | S_IWUSR), 1547 file = debugfs_create_file("register-bank", (S_IRUGO | S_IWUSR),
1481 ab8500_dir, &plf->dev, &ab8500_bank_fops); 1548 ab8500_dir, &plf->dev, &ab8500_bank_fops);
1482 if (!file) 1549 if (!file)