2 * Copyright (C) ST-Ericsson SA 2010
4 * Author: Mattias Wallin <mattias.wallin@stericsson.com> for ST-Ericsson.
5 * License Terms: GNU General Public License v2
8 #include <linux/seq_file.h>
9 #include <linux/uaccess.h>
11 #include <linux/debugfs.h>
12 #include <linux/platform_device.h>
14 #include <linux/mfd/abx500.h>
15 #include <linux/mfd/ab8500.h>
17 static u32 debug_bank
;
18 static u32 debug_address
;
21 * struct ab8500_reg_range
22 * @first: the first address of the range
23 * @last: the last address of the range
24 * @perm: access permissions for the range
26 struct ab8500_reg_range
{
33 * struct ab8500_i2c_ranges
34 * @num_ranges: the number of ranges in the list
35 * @bankid: bank identifier
36 * @range: the list of register ranges
38 struct ab8500_i2c_ranges
{
41 const struct ab8500_reg_range
*range
;
44 #define AB8500_NAME_STRING "ab8500"
45 #define AB8500_NUM_BANKS 22
47 #define AB8500_REV_REG 0x80
49 static struct ab8500_i2c_ranges debug_ranges
[AB8500_NUM_BANKS
] = {
54 [AB8500_SYS_CTRL1_BLOCK
] = {
56 .range
= (struct ab8500_reg_range
[]) {
71 [AB8500_SYS_CTRL2_BLOCK
] = {
73 .range
= (struct ab8500_reg_range
[]) {
92 [AB8500_REGU_CTRL1
] = {
94 .range
= (struct ab8500_reg_range
[]) {
109 [AB8500_REGU_CTRL2
] = {
111 .range
= (struct ab8500_reg_range
[]) {
132 /* 0x80-0x8B is SIM registers and should
133 * not be accessed from here */
138 .range
= (struct ab8500_reg_range
[]) {
151 .range
= (struct ab8500_reg_range
[]) {
194 [AB8500_ECI_AV_ACC
] = {
196 .range
= (struct ab8500_reg_range
[]) {
209 .range
= (struct ab8500_reg_range
[]) {
218 .range
= (struct ab8500_reg_range
[]) {
253 [AB8500_GAS_GAUGE
] = {
255 .range
= (struct ab8500_reg_range
[]) {
272 .range
= (struct ab8500_reg_range
[]) {
279 [AB8500_INTERRUPT
] = {
285 .range
= (struct ab8500_reg_range
[]) {
294 .range
= (struct ab8500_reg_range
[]) {
345 [AB8500_OTP_EMUL
] = {
347 .range
= (struct ab8500_reg_range
[]) {
356 static int ab8500_registers_print(struct seq_file
*s
, void *p
)
358 struct device
*dev
= s
->private;
360 u32 bank
= debug_bank
;
362 seq_printf(s
, AB8500_NAME_STRING
" register values:\n");
364 seq_printf(s
, " bank %u:\n", bank
);
365 for (i
= 0; i
< debug_ranges
[bank
].num_ranges
; i
++) {
368 for (reg
= debug_ranges
[bank
].range
[i
].first
;
369 reg
<= debug_ranges
[bank
].range
[i
].last
;
374 err
= abx500_get_register_interruptible(dev
,
375 (u8
)bank
, (u8
)reg
, &value
);
377 dev_err(dev
, "ab->read fail %d\n", err
);
381 err
= seq_printf(s
, " [%u/0x%02X]: 0x%02X\n", bank
,
384 dev_err(dev
, "seq_printf overflow\n");
385 /* Error is not returned here since
386 * the output is wanted in any case */
394 static int ab8500_registers_open(struct inode
*inode
, struct file
*file
)
396 return single_open(file
, ab8500_registers_print
, inode
->i_private
);
399 static const struct file_operations ab8500_registers_fops
= {
400 .open
= ab8500_registers_open
,
403 .release
= single_release
,
404 .owner
= THIS_MODULE
,
407 static int ab8500_bank_print(struct seq_file
*s
, void *p
)
409 return seq_printf(s
, "%d\n", debug_bank
);
412 static int ab8500_bank_open(struct inode
*inode
, struct file
*file
)
414 return single_open(file
, ab8500_bank_print
, inode
->i_private
);
417 static ssize_t
ab8500_bank_write(struct file
*file
,
418 const char __user
*user_buf
,
419 size_t count
, loff_t
*ppos
)
421 struct device
*dev
= ((struct seq_file
*)(file
->private_data
))->private;
424 unsigned long user_bank
;
427 /* Get userspace string and assure termination */
428 buf_size
= min(count
, (sizeof(buf
) - 1));
429 if (copy_from_user(buf
, user_buf
, buf_size
))
433 err
= strict_strtoul(buf
, 0, &user_bank
);
437 if (user_bank
>= AB8500_NUM_BANKS
) {
438 dev_err(dev
, "debugfs error input > number of banks\n");
442 debug_bank
= user_bank
;
447 static int ab8500_address_print(struct seq_file
*s
, void *p
)
449 return seq_printf(s
, "0x%02X\n", debug_address
);
452 static int ab8500_address_open(struct inode
*inode
, struct file
*file
)
454 return single_open(file
, ab8500_address_print
, inode
->i_private
);
457 static ssize_t
ab8500_address_write(struct file
*file
,
458 const char __user
*user_buf
,
459 size_t count
, loff_t
*ppos
)
461 struct device
*dev
= ((struct seq_file
*)(file
->private_data
))->private;
464 unsigned long user_address
;
467 /* Get userspace string and assure termination */
468 buf_size
= min(count
, (sizeof(buf
) - 1));
469 if (copy_from_user(buf
, user_buf
, buf_size
))
473 err
= strict_strtoul(buf
, 0, &user_address
);
476 if (user_address
> 0xff) {
477 dev_err(dev
, "debugfs error input > 0xff\n");
480 debug_address
= user_address
;
484 static int ab8500_val_print(struct seq_file
*s
, void *p
)
486 struct device
*dev
= s
->private;
490 ret
= abx500_get_register_interruptible(dev
,
491 (u8
)debug_bank
, (u8
)debug_address
, ®value
);
493 dev_err(dev
, "abx500_get_reg fail %d, %d\n",
497 seq_printf(s
, "0x%02X\n", regvalue
);
502 static int ab8500_val_open(struct inode
*inode
, struct file
*file
)
504 return single_open(file
, ab8500_val_print
, inode
->i_private
);
507 static ssize_t
ab8500_val_write(struct file
*file
,
508 const char __user
*user_buf
,
509 size_t count
, loff_t
*ppos
)
511 struct device
*dev
= ((struct seq_file
*)(file
->private_data
))->private;
514 unsigned long user_val
;
517 /* Get userspace string and assure termination */
518 buf_size
= min(count
, (sizeof(buf
)-1));
519 if (copy_from_user(buf
, user_buf
, buf_size
))
523 err
= strict_strtoul(buf
, 0, &user_val
);
526 if (user_val
> 0xff) {
527 dev_err(dev
, "debugfs error input > 0xff\n");
530 err
= abx500_set_register_interruptible(dev
,
531 (u8
)debug_bank
, debug_address
, (u8
)user_val
);
533 printk(KERN_ERR
"abx500_set_reg failed %d, %d", err
, __LINE__
);
540 static const struct file_operations ab8500_bank_fops
= {
541 .open
= ab8500_bank_open
,
542 .write
= ab8500_bank_write
,
545 .release
= single_release
,
546 .owner
= THIS_MODULE
,
549 static const struct file_operations ab8500_address_fops
= {
550 .open
= ab8500_address_open
,
551 .write
= ab8500_address_write
,
554 .release
= single_release
,
555 .owner
= THIS_MODULE
,
558 static const struct file_operations ab8500_val_fops
= {
559 .open
= ab8500_val_open
,
560 .write
= ab8500_val_write
,
563 .release
= single_release
,
564 .owner
= THIS_MODULE
,
567 static struct dentry
*ab8500_dir
;
568 static struct dentry
*ab8500_reg_file
;
569 static struct dentry
*ab8500_bank_file
;
570 static struct dentry
*ab8500_address_file
;
571 static struct dentry
*ab8500_val_file
;
573 static int __devinit
ab8500_debug_probe(struct platform_device
*plf
)
575 debug_bank
= AB8500_MISC
;
576 debug_address
= AB8500_REV_REG
& 0x00FF;
578 ab8500_dir
= debugfs_create_dir(AB8500_NAME_STRING
, NULL
);
580 goto exit_no_debugfs
;
582 ab8500_reg_file
= debugfs_create_file("all-bank-registers",
583 S_IRUGO
, ab8500_dir
, &plf
->dev
, &ab8500_registers_fops
);
584 if (!ab8500_reg_file
)
585 goto exit_destroy_dir
;
587 ab8500_bank_file
= debugfs_create_file("register-bank",
588 (S_IRUGO
| S_IWUGO
), ab8500_dir
, &plf
->dev
, &ab8500_bank_fops
);
589 if (!ab8500_bank_file
)
590 goto exit_destroy_reg
;
592 ab8500_address_file
= debugfs_create_file("register-address",
593 (S_IRUGO
| S_IWUGO
), ab8500_dir
, &plf
->dev
,
594 &ab8500_address_fops
);
595 if (!ab8500_address_file
)
596 goto exit_destroy_bank
;
598 ab8500_val_file
= debugfs_create_file("register-value",
599 (S_IRUGO
| S_IWUGO
), ab8500_dir
, &plf
->dev
, &ab8500_val_fops
);
600 if (!ab8500_val_file
)
601 goto exit_destroy_address
;
605 exit_destroy_address
:
606 debugfs_remove(ab8500_address_file
);
608 debugfs_remove(ab8500_bank_file
);
610 debugfs_remove(ab8500_reg_file
);
612 debugfs_remove(ab8500_dir
);
614 dev_err(&plf
->dev
, "failed to create debugfs entries.\n");
618 static int __devexit
ab8500_debug_remove(struct platform_device
*plf
)
620 debugfs_remove(ab8500_val_file
);
621 debugfs_remove(ab8500_address_file
);
622 debugfs_remove(ab8500_bank_file
);
623 debugfs_remove(ab8500_reg_file
);
624 debugfs_remove(ab8500_dir
);
629 static struct platform_driver ab8500_debug_driver
= {
631 .name
= "ab8500-debug",
632 .owner
= THIS_MODULE
,
634 .probe
= ab8500_debug_probe
,
635 .remove
= __devexit_p(ab8500_debug_remove
)
638 static int __init
ab8500_debug_init(void)
640 return platform_driver_register(&ab8500_debug_driver
);
643 static void __exit
ab8500_debug_exit(void)
645 platform_driver_unregister(&ab8500_debug_driver
);
647 subsys_initcall(ab8500_debug_init
);
648 module_exit(ab8500_debug_exit
);
650 MODULE_AUTHOR("Mattias WALLIN <mattias.wallin@stericsson.com");
651 MODULE_DESCRIPTION("AB8500 DEBUG");
652 MODULE_LICENSE("GPL v2");