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 * AB8500 register access
9 * ======================
12 * # echo BANK > <debugfs>/ab8500/register-bank
13 * # echo ADDR > <debugfs>/ab8500/register-address
14 * # cat <debugfs>/ab8500/register-value
17 * # echo BANK > <debugfs>/ab8500/register-bank
18 * # echo ADDR > <debugfs>/ab8500/register-address
19 * # echo VALUE > <debugfs>/ab8500/register-value
21 * read all registers from a bank:
22 * # echo BANK > <debugfs>/ab8500/register-bank
23 * # cat <debugfs>/ab8500/all-bank-register
25 * BANK target AB8500 register bank
26 * ADDR target AB8500 register address
27 * VALUE decimal or 0x-prefixed hexadecimal
30 * User Space notification on AB8500 IRQ
31 * =====================================
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.
37 * subscribe to an AB8500 IRQ:
38 * # echo IRQ > <debugfs>/ab8500/irq-subscribe
40 * unsubscribe from an AB8500 IRQ:
41 * # echo IRQ > <debugfs>/ab8500/irq-unsubscribe
44 * AB8500 register formated read/write access
45 * ==========================================
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]
53 * # echo "CMD [OPTIONS] BANK ADRESS [VALUE]" > $debugfs/ab8500/hwreg
55 * CMD read read access
58 * BANK target reg bank
59 * ADDRESS target reg address
60 * VALUE (write) value to be updated
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
70 * Warning: bit shift operation is applied to bit-mask.
71 * Warning: bit shift direction depends on read or right command.
74 #include <linux/seq_file.h>
75 #include <linux/uaccess.h>
77 #include <linux/module.h>
78 #include <linux/debugfs.h>
79 #include <linux/platform_device.h>
80 #include <linux/interrupt.h>
81 #include <linux/kobject.h>
82 #include <linux/slab.h>
84 #include <linux/mfd/abx500.h>
85 #include <linux/mfd/abx500/ab8500.h>
86 #include <linux/mfd/abx500/ab8500-gpadc.h>
88 #ifdef CONFIG_DEBUG_FS
89 #include <linux/string.h>
90 #include <linux/ctype.h>
93 static u32 debug_bank
;
94 static u32 debug_address
;
98 static u32
*irq_count
;
101 static struct device_attribute
**dev_attr
;
102 static char **event_name
;
105 * struct ab8500_reg_range
106 * @first: the first address of the range
107 * @last: the last address of the range
108 * @perm: access permissions for the range
110 struct ab8500_reg_range
{
117 * struct ab8500_prcmu_ranges
118 * @num_ranges: the number of ranges in the list
119 * @bankid: bank identifier
120 * @range: the list of register ranges
122 struct ab8500_prcmu_ranges
{
125 const struct ab8500_reg_range
*range
;
128 /* hwreg- "mask" and "shift" entries ressources */
130 u32 bank
; /* target bank */
131 u32 addr
; /* target address */
132 uint fmt
; /* format */
133 uint mask
; /* read/write mask, applied before any bit shift */
134 int shift
; /* bit shift (read:right shift, write:left shift */
136 /* fmt bit #0: 0=hexa, 1=dec */
137 #define REG_FMT_DEC(c) ((c)->fmt & 0x1)
138 #define REG_FMT_HEX(c) (!REG_FMT_DEC(c))
140 static struct hwreg_cfg hwreg_cfg
= {
141 .addr
= 0, /* default: invalid phys addr */
142 .fmt
= 0, /* default: 32bit access, hex output */
143 .mask
= 0xFFFFFFFF, /* default: no mask */
144 .shift
= 0, /* default: no bit shift */
147 #define AB8500_NAME_STRING "ab8500"
148 #define AB8500_ADC_NAME_STRING "gpadc"
149 #define AB8500_NUM_BANKS 24
151 #define AB8500_REV_REG 0x80
153 static struct ab8500_prcmu_ranges debug_ranges
[AB8500_NUM_BANKS
] = {
158 [AB8500_SYS_CTRL1_BLOCK
] = {
160 .range
= (struct ab8500_reg_range
[]) {
175 [AB8500_SYS_CTRL2_BLOCK
] = {
177 .range
= (struct ab8500_reg_range
[]) {
196 [AB8500_REGU_CTRL1
] = {
198 .range
= (struct ab8500_reg_range
[]) {
213 [AB8500_REGU_CTRL2
] = {
215 .range
= (struct ab8500_reg_range
[]) {
236 /* 0x80-0x8B is SIM registers and should
237 * not be accessed from here */
242 .range
= (struct ab8500_reg_range
[]) {
255 .range
= (struct ab8500_reg_range
[]) {
298 [AB8500_ECI_AV_ACC
] = {
300 .range
= (struct ab8500_reg_range
[]) {
313 .range
= (struct ab8500_reg_range
[]) {
322 .range
= (struct ab8500_reg_range
[]) {
361 [AB8500_GAS_GAUGE
] = {
363 .range
= (struct ab8500_reg_range
[]) {
378 [AB8500_DEVELOPMENT
] = {
380 .range
= (struct ab8500_reg_range
[]) {
389 .range
= (struct ab8500_reg_range
[]) {
398 .range
= (struct ab8500_reg_range
[]) {
405 [AB8500_INTERRUPT
] = {
411 .range
= (struct ab8500_reg_range
[]) {
420 .range
= (struct ab8500_reg_range
[]) {
471 [AB8500_OTP_EMUL
] = {
473 .range
= (struct ab8500_reg_range
[]) {
482 static irqreturn_t
ab8500_debug_handler(int irq
, void *data
)
485 struct kobject
*kobj
= (struct kobject
*)data
;
486 unsigned int irq_abb
= irq
- irq_first
;
488 if (irq_abb
< num_irqs
)
489 irq_count
[irq_abb
]++;
491 * This makes it possible to use poll for events (POLLPRI | POLLERR)
492 * from userspace on sysfs file named <irq-nr>
494 sprintf(buf
, "%d", irq
);
495 sysfs_notify(kobj
, NULL
, buf
);
500 /* Prints to seq_file or log_buf */
501 static int ab8500_registers_print(struct device
*dev
, u32 bank
,
506 for (i
= 0; i
< debug_ranges
[bank
].num_ranges
; i
++) {
509 for (reg
= debug_ranges
[bank
].range
[i
].first
;
510 reg
<= debug_ranges
[bank
].range
[i
].last
;
515 err
= abx500_get_register_interruptible(dev
,
516 (u8
)bank
, (u8
)reg
, &value
);
518 dev_err(dev
, "ab->read fail %d\n", err
);
523 err
= seq_printf(s
, " [%u/0x%02X]: 0x%02X\n",
527 "seq_printf overflow bank=%d reg=%d\n",
529 /* Error is not returned here since
530 * the output is wanted in any case */
534 printk(KERN_INFO
" [%u/0x%02X]: 0x%02X\n", bank
,
542 static int ab8500_print_bank_registers(struct seq_file
*s
, void *p
)
544 struct device
*dev
= s
->private;
545 u32 bank
= debug_bank
;
547 seq_printf(s
, AB8500_NAME_STRING
" register values:\n");
549 seq_printf(s
, " bank %u:\n", bank
);
551 ab8500_registers_print(dev
, bank
, s
);
555 static int ab8500_registers_open(struct inode
*inode
, struct file
*file
)
557 return single_open(file
, ab8500_print_bank_registers
, inode
->i_private
);
560 static const struct file_operations ab8500_registers_fops
= {
561 .open
= ab8500_registers_open
,
564 .release
= single_release
,
565 .owner
= THIS_MODULE
,
568 static int ab8500_print_all_banks(struct seq_file
*s
, void *p
)
570 struct device
*dev
= s
->private;
574 seq_printf(s
, AB8500_NAME_STRING
" register values:\n");
576 for (i
= 1; i
< AB8500_NUM_BANKS
; i
++) {
577 err
= seq_printf(s
, " bank %u:\n", i
);
579 dev_err(dev
, "seq_printf overflow, bank=%d\n", i
);
581 ab8500_registers_print(dev
, i
, s
);
586 /* Dump registers to kernel log */
587 void ab8500_dump_all_banks(struct device
*dev
)
591 printk(KERN_INFO
"ab8500 register values:\n");
593 for (i
= 1; i
< AB8500_NUM_BANKS
; i
++) {
594 printk(KERN_INFO
" bank %u:\n", i
);
595 ab8500_registers_print(dev
, i
, NULL
);
599 static int ab8500_all_banks_open(struct inode
*inode
, struct file
*file
)
604 err
= single_open(file
, ab8500_print_all_banks
, inode
->i_private
);
606 /* Default buf size in seq_read is not enough */
607 s
= (struct seq_file
*)file
->private_data
;
608 s
->size
= (PAGE_SIZE
* 2);
609 s
->buf
= kmalloc(s
->size
, GFP_KERNEL
);
611 single_release(inode
, file
);
618 static const struct file_operations ab8500_all_banks_fops
= {
619 .open
= ab8500_all_banks_open
,
622 .release
= single_release
,
623 .owner
= THIS_MODULE
,
626 static int ab8500_bank_print(struct seq_file
*s
, void *p
)
628 return seq_printf(s
, "%d\n", debug_bank
);
631 static int ab8500_bank_open(struct inode
*inode
, struct file
*file
)
633 return single_open(file
, ab8500_bank_print
, inode
->i_private
);
636 static ssize_t
ab8500_bank_write(struct file
*file
,
637 const char __user
*user_buf
,
638 size_t count
, loff_t
*ppos
)
640 struct device
*dev
= ((struct seq_file
*)(file
->private_data
))->private;
641 unsigned long user_bank
;
644 /* Get userspace string and assure termination */
645 err
= kstrtoul_from_user(user_buf
, count
, 0, &user_bank
);
649 if (user_bank
>= AB8500_NUM_BANKS
) {
650 dev_err(dev
, "debugfs error input > number of banks\n");
654 debug_bank
= user_bank
;
659 static int ab8500_address_print(struct seq_file
*s
, void *p
)
661 return seq_printf(s
, "0x%02X\n", debug_address
);
664 static int ab8500_address_open(struct inode
*inode
, struct file
*file
)
666 return single_open(file
, ab8500_address_print
, inode
->i_private
);
669 static ssize_t
ab8500_address_write(struct file
*file
,
670 const char __user
*user_buf
,
671 size_t count
, loff_t
*ppos
)
673 struct device
*dev
= ((struct seq_file
*)(file
->private_data
))->private;
674 unsigned long user_address
;
677 /* Get userspace string and assure termination */
678 err
= kstrtoul_from_user(user_buf
, count
, 0, &user_address
);
682 if (user_address
> 0xff) {
683 dev_err(dev
, "debugfs error input > 0xff\n");
686 debug_address
= user_address
;
690 static int ab8500_val_print(struct seq_file
*s
, void *p
)
692 struct device
*dev
= s
->private;
696 ret
= abx500_get_register_interruptible(dev
,
697 (u8
)debug_bank
, (u8
)debug_address
, ®value
);
699 dev_err(dev
, "abx500_get_reg fail %d, %d\n",
703 seq_printf(s
, "0x%02X\n", regvalue
);
708 static int ab8500_val_open(struct inode
*inode
, struct file
*file
)
710 return single_open(file
, ab8500_val_print
, inode
->i_private
);
713 static ssize_t
ab8500_val_write(struct file
*file
,
714 const char __user
*user_buf
,
715 size_t count
, loff_t
*ppos
)
717 struct device
*dev
= ((struct seq_file
*)(file
->private_data
))->private;
718 unsigned long user_val
;
721 /* Get userspace string and assure termination */
722 err
= kstrtoul_from_user(user_buf
, count
, 0, &user_val
);
726 if (user_val
> 0xff) {
727 dev_err(dev
, "debugfs error input > 0xff\n");
730 err
= abx500_set_register_interruptible(dev
,
731 (u8
)debug_bank
, debug_address
, (u8
)user_val
);
733 printk(KERN_ERR
"abx500_set_reg failed %d, %d", err
, __LINE__
);
743 static u32 num_interrupts
[AB8500_MAX_NR_IRQS
];
744 static int num_interrupt_lines
;
746 void ab8500_debug_register_interrupt(int line
)
748 if (line
< num_interrupt_lines
)
749 num_interrupts
[line
]++;
752 static int ab8500_interrupts_print(struct seq_file
*s
, void *p
)
756 seq_printf(s
, "irq: number of\n");
758 for (line
= 0; line
< num_interrupt_lines
; line
++)
759 seq_printf(s
, "%3i: %6i\n", line
, num_interrupts
[line
]);
764 static int ab8500_interrupts_open(struct inode
*inode
, struct file
*file
)
766 return single_open(file
, ab8500_interrupts_print
, inode
->i_private
);
770 * - HWREG DB8500 formated routines
772 static int ab8500_hwreg_print(struct seq_file
*s
, void *d
)
774 struct device
*dev
= s
->private;
778 ret
= abx500_get_register_interruptible(dev
,
779 (u8
)hwreg_cfg
.bank
, (u8
)hwreg_cfg
.addr
, ®value
);
781 dev_err(dev
, "abx500_get_reg fail %d, %d\n",
786 if (hwreg_cfg
.shift
>= 0)
787 regvalue
>>= hwreg_cfg
.shift
;
789 regvalue
<<= -hwreg_cfg
.shift
;
790 regvalue
&= hwreg_cfg
.mask
;
792 if (REG_FMT_DEC(&hwreg_cfg
))
793 seq_printf(s
, "%d\n", regvalue
);
795 seq_printf(s
, "0x%02X\n", regvalue
);
799 static int ab8500_hwreg_open(struct inode
*inode
, struct file
*file
)
801 return single_open(file
, ab8500_hwreg_print
, inode
->i_private
);
804 static int ab8500_gpadc_bat_ctrl_print(struct seq_file
*s
, void *p
)
807 int bat_ctrl_convert
;
808 struct ab8500_gpadc
*gpadc
;
810 gpadc
= ab8500_gpadc_get("ab8500-gpadc.0");
811 bat_ctrl_raw
= ab8500_gpadc_read_raw(gpadc
, BAT_CTRL
);
812 bat_ctrl_convert
= ab8500_gpadc_ad_to_voltage(gpadc
,
813 BAT_CTRL
, bat_ctrl_raw
);
815 return seq_printf(s
, "%d,0x%X\n",
816 bat_ctrl_convert
, bat_ctrl_raw
);
819 static int ab8500_gpadc_bat_ctrl_open(struct inode
*inode
, struct file
*file
)
821 return single_open(file
, ab8500_gpadc_bat_ctrl_print
, inode
->i_private
);
824 static const struct file_operations ab8500_gpadc_bat_ctrl_fops
= {
825 .open
= ab8500_gpadc_bat_ctrl_open
,
828 .release
= single_release
,
829 .owner
= THIS_MODULE
,
832 static int ab8500_gpadc_btemp_ball_print(struct seq_file
*s
, void *p
)
835 int btemp_ball_convert
;
836 struct ab8500_gpadc
*gpadc
;
838 gpadc
= ab8500_gpadc_get("ab8500-gpadc.0");
839 btemp_ball_raw
= ab8500_gpadc_read_raw(gpadc
, BTEMP_BALL
);
840 btemp_ball_convert
= ab8500_gpadc_ad_to_voltage(gpadc
, BTEMP_BALL
,
844 "%d,0x%X\n", btemp_ball_convert
, btemp_ball_raw
);
847 static int ab8500_gpadc_btemp_ball_open(struct inode
*inode
,
850 return single_open(file
, ab8500_gpadc_btemp_ball_print
, inode
->i_private
);
853 static const struct file_operations ab8500_gpadc_btemp_ball_fops
= {
854 .open
= ab8500_gpadc_btemp_ball_open
,
857 .release
= single_release
,
858 .owner
= THIS_MODULE
,
861 static int ab8500_gpadc_main_charger_v_print(struct seq_file
*s
, void *p
)
863 int main_charger_v_raw
;
864 int main_charger_v_convert
;
865 struct ab8500_gpadc
*gpadc
;
867 gpadc
= ab8500_gpadc_get("ab8500-gpadc.0");
868 main_charger_v_raw
= ab8500_gpadc_read_raw(gpadc
, MAIN_CHARGER_V
);
869 main_charger_v_convert
= ab8500_gpadc_ad_to_voltage(gpadc
,
870 MAIN_CHARGER_V
, main_charger_v_raw
);
872 return seq_printf(s
, "%d,0x%X\n",
873 main_charger_v_convert
, main_charger_v_raw
);
876 static int ab8500_gpadc_main_charger_v_open(struct inode
*inode
,
879 return single_open(file
, ab8500_gpadc_main_charger_v_print
,
883 static const struct file_operations ab8500_gpadc_main_charger_v_fops
= {
884 .open
= ab8500_gpadc_main_charger_v_open
,
887 .release
= single_release
,
888 .owner
= THIS_MODULE
,
891 static int ab8500_gpadc_acc_detect1_print(struct seq_file
*s
, void *p
)
894 int acc_detect1_convert
;
895 struct ab8500_gpadc
*gpadc
;
897 gpadc
= ab8500_gpadc_get("ab8500-gpadc.0");
898 acc_detect1_raw
= ab8500_gpadc_read_raw(gpadc
, ACC_DETECT1
);
899 acc_detect1_convert
= ab8500_gpadc_ad_to_voltage(gpadc
, ACC_DETECT1
,
902 return seq_printf(s
, "%d,0x%X\n",
903 acc_detect1_convert
, acc_detect1_raw
);
906 static int ab8500_gpadc_acc_detect1_open(struct inode
*inode
,
909 return single_open(file
, ab8500_gpadc_acc_detect1_print
,
913 static const struct file_operations ab8500_gpadc_acc_detect1_fops
= {
914 .open
= ab8500_gpadc_acc_detect1_open
,
917 .release
= single_release
,
918 .owner
= THIS_MODULE
,
921 static int ab8500_gpadc_acc_detect2_print(struct seq_file
*s
, void *p
)
924 int acc_detect2_convert
;
925 struct ab8500_gpadc
*gpadc
;
927 gpadc
= ab8500_gpadc_get("ab8500-gpadc.0");
928 acc_detect2_raw
= ab8500_gpadc_read_raw(gpadc
, ACC_DETECT2
);
929 acc_detect2_convert
= ab8500_gpadc_ad_to_voltage(gpadc
,
930 ACC_DETECT2
, acc_detect2_raw
);
932 return seq_printf(s
, "%d,0x%X\n",
933 acc_detect2_convert
, acc_detect2_raw
);
936 static int ab8500_gpadc_acc_detect2_open(struct inode
*inode
,
939 return single_open(file
, ab8500_gpadc_acc_detect2_print
,
943 static const struct file_operations ab8500_gpadc_acc_detect2_fops
= {
944 .open
= ab8500_gpadc_acc_detect2_open
,
947 .release
= single_release
,
948 .owner
= THIS_MODULE
,
951 static int ab8500_gpadc_aux1_print(struct seq_file
*s
, void *p
)
955 struct ab8500_gpadc
*gpadc
;
957 gpadc
= ab8500_gpadc_get("ab8500-gpadc.0");
958 aux1_raw
= ab8500_gpadc_read_raw(gpadc
, ADC_AUX1
);
959 aux1_convert
= ab8500_gpadc_ad_to_voltage(gpadc
, ADC_AUX1
,
962 return seq_printf(s
, "%d,0x%X\n",
963 aux1_convert
, aux1_raw
);
966 static int ab8500_gpadc_aux1_open(struct inode
*inode
, struct file
*file
)
968 return single_open(file
, ab8500_gpadc_aux1_print
, inode
->i_private
);
971 static const struct file_operations ab8500_gpadc_aux1_fops
= {
972 .open
= ab8500_gpadc_aux1_open
,
975 .release
= single_release
,
976 .owner
= THIS_MODULE
,
979 static int ab8500_gpadc_aux2_print(struct seq_file
*s
, void *p
)
983 struct ab8500_gpadc
*gpadc
;
985 gpadc
= ab8500_gpadc_get("ab8500-gpadc.0");
986 aux2_raw
= ab8500_gpadc_read_raw(gpadc
, ADC_AUX2
);
987 aux2_convert
= ab8500_gpadc_ad_to_voltage(gpadc
, ADC_AUX2
,
990 return seq_printf(s
, "%d,0x%X\n",
991 aux2_convert
, aux2_raw
);
994 static int ab8500_gpadc_aux2_open(struct inode
*inode
, struct file
*file
)
996 return single_open(file
, ab8500_gpadc_aux2_print
, inode
->i_private
);
999 static const struct file_operations ab8500_gpadc_aux2_fops
= {
1000 .open
= ab8500_gpadc_aux2_open
,
1002 .llseek
= seq_lseek
,
1003 .release
= single_release
,
1004 .owner
= THIS_MODULE
,
1007 static int ab8500_gpadc_main_bat_v_print(struct seq_file
*s
, void *p
)
1010 int main_bat_v_convert
;
1011 struct ab8500_gpadc
*gpadc
;
1013 gpadc
= ab8500_gpadc_get("ab8500-gpadc.0");
1014 main_bat_v_raw
= ab8500_gpadc_read_raw(gpadc
, MAIN_BAT_V
);
1015 main_bat_v_convert
= ab8500_gpadc_ad_to_voltage(gpadc
, MAIN_BAT_V
,
1018 return seq_printf(s
, "%d,0x%X\n",
1019 main_bat_v_convert
, main_bat_v_raw
);
1022 static int ab8500_gpadc_main_bat_v_open(struct inode
*inode
,
1025 return single_open(file
, ab8500_gpadc_main_bat_v_print
, inode
->i_private
);
1028 static const struct file_operations ab8500_gpadc_main_bat_v_fops
= {
1029 .open
= ab8500_gpadc_main_bat_v_open
,
1031 .llseek
= seq_lseek
,
1032 .release
= single_release
,
1033 .owner
= THIS_MODULE
,
1036 static int ab8500_gpadc_vbus_v_print(struct seq_file
*s
, void *p
)
1040 struct ab8500_gpadc
*gpadc
;
1042 gpadc
= ab8500_gpadc_get("ab8500-gpadc.0");
1043 vbus_v_raw
= ab8500_gpadc_read_raw(gpadc
, VBUS_V
);
1044 vbus_v_convert
= ab8500_gpadc_ad_to_voltage(gpadc
, VBUS_V
,
1047 return seq_printf(s
, "%d,0x%X\n",
1048 vbus_v_convert
, vbus_v_raw
);
1051 static int ab8500_gpadc_vbus_v_open(struct inode
*inode
, struct file
*file
)
1053 return single_open(file
, ab8500_gpadc_vbus_v_print
, inode
->i_private
);
1056 static const struct file_operations ab8500_gpadc_vbus_v_fops
= {
1057 .open
= ab8500_gpadc_vbus_v_open
,
1059 .llseek
= seq_lseek
,
1060 .release
= single_release
,
1061 .owner
= THIS_MODULE
,
1064 static int ab8500_gpadc_main_charger_c_print(struct seq_file
*s
, void *p
)
1066 int main_charger_c_raw
;
1067 int main_charger_c_convert
;
1068 struct ab8500_gpadc
*gpadc
;
1070 gpadc
= ab8500_gpadc_get("ab8500-gpadc.0");
1071 main_charger_c_raw
= ab8500_gpadc_read_raw(gpadc
, MAIN_CHARGER_C
);
1072 main_charger_c_convert
= ab8500_gpadc_ad_to_voltage(gpadc
,
1073 MAIN_CHARGER_C
, main_charger_c_raw
);
1075 return seq_printf(s
, "%d,0x%X\n",
1076 main_charger_c_convert
, main_charger_c_raw
);
1079 static int ab8500_gpadc_main_charger_c_open(struct inode
*inode
,
1082 return single_open(file
, ab8500_gpadc_main_charger_c_print
,
1086 static const struct file_operations ab8500_gpadc_main_charger_c_fops
= {
1087 .open
= ab8500_gpadc_main_charger_c_open
,
1089 .llseek
= seq_lseek
,
1090 .release
= single_release
,
1091 .owner
= THIS_MODULE
,
1094 static int ab8500_gpadc_usb_charger_c_print(struct seq_file
*s
, void *p
)
1096 int usb_charger_c_raw
;
1097 int usb_charger_c_convert
;
1098 struct ab8500_gpadc
*gpadc
;
1100 gpadc
= ab8500_gpadc_get("ab8500-gpadc.0");
1101 usb_charger_c_raw
= ab8500_gpadc_read_raw(gpadc
, USB_CHARGER_C
);
1102 usb_charger_c_convert
= ab8500_gpadc_ad_to_voltage(gpadc
,
1103 USB_CHARGER_C
, usb_charger_c_raw
);
1105 return seq_printf(s
, "%d,0x%X\n",
1106 usb_charger_c_convert
, usb_charger_c_raw
);
1109 static int ab8500_gpadc_usb_charger_c_open(struct inode
*inode
,
1112 return single_open(file
, ab8500_gpadc_usb_charger_c_print
,
1116 static const struct file_operations ab8500_gpadc_usb_charger_c_fops
= {
1117 .open
= ab8500_gpadc_usb_charger_c_open
,
1119 .llseek
= seq_lseek
,
1120 .release
= single_release
,
1121 .owner
= THIS_MODULE
,
1124 static int ab8500_gpadc_bk_bat_v_print(struct seq_file
*s
, void *p
)
1127 int bk_bat_v_convert
;
1128 struct ab8500_gpadc
*gpadc
;
1130 gpadc
= ab8500_gpadc_get("ab8500-gpadc.0");
1131 bk_bat_v_raw
= ab8500_gpadc_read_raw(gpadc
, BK_BAT_V
);
1132 bk_bat_v_convert
= ab8500_gpadc_ad_to_voltage(gpadc
,
1133 BK_BAT_V
, bk_bat_v_raw
);
1135 return seq_printf(s
, "%d,0x%X\n",
1136 bk_bat_v_convert
, bk_bat_v_raw
);
1139 static int ab8500_gpadc_bk_bat_v_open(struct inode
*inode
, struct file
*file
)
1141 return single_open(file
, ab8500_gpadc_bk_bat_v_print
, inode
->i_private
);
1144 static const struct file_operations ab8500_gpadc_bk_bat_v_fops
= {
1145 .open
= ab8500_gpadc_bk_bat_v_open
,
1147 .llseek
= seq_lseek
,
1148 .release
= single_release
,
1149 .owner
= THIS_MODULE
,
1152 static int ab8500_gpadc_die_temp_print(struct seq_file
*s
, void *p
)
1155 int die_temp_convert
;
1156 struct ab8500_gpadc
*gpadc
;
1158 gpadc
= ab8500_gpadc_get("ab8500-gpadc.0");
1159 die_temp_raw
= ab8500_gpadc_read_raw(gpadc
, DIE_TEMP
);
1160 die_temp_convert
= ab8500_gpadc_ad_to_voltage(gpadc
, DIE_TEMP
,
1163 return seq_printf(s
, "%d,0x%X\n",
1164 die_temp_convert
, die_temp_raw
);
1167 static int ab8500_gpadc_die_temp_open(struct inode
*inode
, struct file
*file
)
1169 return single_open(file
, ab8500_gpadc_die_temp_print
, inode
->i_private
);
1172 static const struct file_operations ab8500_gpadc_die_temp_fops
= {
1173 .open
= ab8500_gpadc_die_temp_open
,
1175 .llseek
= seq_lseek
,
1176 .release
= single_release
,
1177 .owner
= THIS_MODULE
,
1181 * return length of an ASCII numerical value, 0 is string is not a
1183 * string shall start at value 1st char.
1184 * string can be tailed with \0 or space or newline chars only.
1185 * value can be decimal or hexadecimal (prefixed 0x or 0X).
1187 static int strval_len(char *b
)
1190 if ((*s
== '0') && ((*(s
+1) == 'x') || (*(s
+1) == 'X'))) {
1192 for (; *s
&& (*s
!= ' ') && (*s
!= '\n'); s
++) {
1199 for (; *s
&& (*s
!= ' ') && (*s
!= '\n'); s
++) {
1208 * parse hwreg input data.
1209 * update global hwreg_cfg only if input data syntax is ok.
1211 static ssize_t
hwreg_common_write(char *b
, struct hwreg_cfg
*cfg
,
1214 uint write
, val
= 0;
1217 struct hwreg_cfg loc
= {
1218 .bank
= 0, /* default: invalid phys addr */
1219 .addr
= 0, /* default: invalid phys addr */
1220 .fmt
= 0, /* default: 32bit access, hex output */
1221 .mask
= 0xFFFFFFFF, /* default: no mask */
1222 .shift
= 0, /* default: no bit shift */
1225 /* read or write ? */
1226 if (!strncmp(b
, "read ", 5)) {
1229 } else if (!strncmp(b
, "write ", 6)) {
1235 /* OPTIONS -l|-w|-b -s -m -o */
1236 while ((*b
== ' ') || (*b
== '-')) {
1237 if (*(b
-1) != ' ') {
1241 if ((!strncmp(b
, "-d ", 3)) ||
1242 (!strncmp(b
, "-dec ", 5))) {
1243 b
+= (*(b
+2) == ' ') ? 3 : 5;
1245 } else if ((!strncmp(b
, "-h ", 3)) ||
1246 (!strncmp(b
, "-hex ", 5))) {
1247 b
+= (*(b
+2) == ' ') ? 3 : 5;
1249 } else if ((!strncmp(b
, "-m ", 3)) ||
1250 (!strncmp(b
, "-mask ", 6))) {
1251 b
+= (*(b
+2) == ' ') ? 3 : 6;
1252 if (strval_len(b
) == 0)
1254 loc
.mask
= simple_strtoul(b
, &b
, 0);
1255 } else if ((!strncmp(b
, "-s ", 3)) ||
1256 (!strncmp(b
, "-shift ", 7))) {
1257 b
+= (*(b
+2) == ' ') ? 3 : 7;
1258 if (strval_len(b
) == 0)
1260 loc
.shift
= simple_strtol(b
, &b
, 0);
1265 /* get arg BANK and ADDRESS */
1266 if (strval_len(b
) == 0)
1268 loc
.bank
= simple_strtoul(b
, &b
, 0);
1271 if (strval_len(b
) == 0)
1273 loc
.addr
= simple_strtoul(b
, &b
, 0);
1278 if (strval_len(b
) == 0)
1280 val
= simple_strtoul(b
, &b
, 0);
1283 /* args are ok, update target cfg (mainly for read) */
1286 #ifdef ABB_HWREG_DEBUG
1287 pr_warn("HWREG request: %s, %s, addr=0x%08X, mask=0x%X, shift=%d"
1288 "value=0x%X\n", (write
) ? "write" : "read",
1289 REG_FMT_DEC(cfg
) ? "decimal" : "hexa",
1290 cfg
->addr
, cfg
->mask
, cfg
->shift
, val
);
1296 ret
= abx500_get_register_interruptible(dev
,
1297 (u8
)cfg
->bank
, (u8
)cfg
->addr
, ®value
);
1299 dev_err(dev
, "abx500_get_reg fail %d, %d\n",
1304 if (cfg
->shift
>= 0) {
1305 regvalue
&= ~(cfg
->mask
<< (cfg
->shift
));
1306 val
= (val
& cfg
->mask
) << (cfg
->shift
);
1308 regvalue
&= ~(cfg
->mask
>> (-cfg
->shift
));
1309 val
= (val
& cfg
->mask
) >> (-cfg
->shift
);
1311 val
= val
| regvalue
;
1313 ret
= abx500_set_register_interruptible(dev
,
1314 (u8
)cfg
->bank
, (u8
)cfg
->addr
, (u8
)val
);
1316 pr_err("abx500_set_reg failed %d, %d", ret
, __LINE__
);
1323 static ssize_t
ab8500_hwreg_write(struct file
*file
,
1324 const char __user
*user_buf
, size_t count
, loff_t
*ppos
)
1326 struct device
*dev
= ((struct seq_file
*)(file
->private_data
))->private;
1330 /* Get userspace string and assure termination */
1331 buf_size
= min(count
, (sizeof(buf
)-1));
1332 if (copy_from_user(buf
, user_buf
, buf_size
))
1336 /* get args and process */
1337 ret
= hwreg_common_write(buf
, &hwreg_cfg
, dev
);
1338 return (ret
) ? ret
: buf_size
;
1342 * - irq subscribe/unsubscribe stuff
1344 static int ab8500_subscribe_unsubscribe_print(struct seq_file
*s
, void *p
)
1346 seq_printf(s
, "%d\n", irq_first
);
1351 static int ab8500_subscribe_unsubscribe_open(struct inode
*inode
,
1354 return single_open(file
, ab8500_subscribe_unsubscribe_print
,
1359 * Userspace should use poll() on this file. When an event occur
1360 * the blocking poll will be released.
1362 static ssize_t
show_irq(struct device
*dev
,
1363 struct device_attribute
*attr
, char *buf
)
1366 unsigned int irq_index
;
1369 err
= strict_strtoul(attr
->attr
.name
, 0, &name
);
1373 irq_index
= name
- irq_first
;
1374 if (irq_index
>= num_irqs
)
1377 return sprintf(buf
, "%u\n", irq_count
[irq_index
]);
1380 static ssize_t
ab8500_subscribe_write(struct file
*file
,
1381 const char __user
*user_buf
,
1382 size_t count
, loff_t
*ppos
)
1384 struct device
*dev
= ((struct seq_file
*)(file
->private_data
))->private;
1387 unsigned long user_val
;
1389 unsigned int irq_index
;
1391 /* Get userspace string and assure termination */
1392 buf_size
= min(count
, (sizeof(buf
)-1));
1393 if (copy_from_user(buf
, user_buf
, buf_size
))
1397 err
= strict_strtoul(buf
, 0, &user_val
);
1400 if (user_val
< irq_first
) {
1401 dev_err(dev
, "debugfs error input < %d\n", irq_first
);
1404 if (user_val
> irq_last
) {
1405 dev_err(dev
, "debugfs error input > %d\n", irq_last
);
1409 irq_index
= user_val
- irq_first
;
1410 if (irq_index
>= num_irqs
)
1414 * This will create a sysfs file named <irq-nr> which userspace can
1415 * use to select or poll and get the AB8500 events
1417 dev_attr
[irq_index
] = kmalloc(sizeof(struct device_attribute
),
1419 event_name
[irq_index
] = kmalloc(buf_size
, GFP_KERNEL
);
1420 sprintf(event_name
[irq_index
], "%lu", user_val
);
1421 dev_attr
[irq_index
]->show
= show_irq
;
1422 dev_attr
[irq_index
]->store
= NULL
;
1423 dev_attr
[irq_index
]->attr
.name
= event_name
[irq_index
];
1424 dev_attr
[irq_index
]->attr
.mode
= S_IRUGO
;
1425 err
= sysfs_create_file(&dev
->kobj
, &dev_attr
[irq_index
]->attr
);
1427 printk(KERN_ERR
"sysfs_create_file failed %d\n", err
);
1431 err
= request_threaded_irq(user_val
, NULL
, ab8500_debug_handler
,
1432 IRQF_SHARED
| IRQF_NO_SUSPEND
,
1433 "ab8500-debug", &dev
->kobj
);
1435 printk(KERN_ERR
"request_threaded_irq failed %d, %lu\n",
1437 sysfs_remove_file(&dev
->kobj
, &dev_attr
[irq_index
]->attr
);
1444 static ssize_t
ab8500_unsubscribe_write(struct file
*file
,
1445 const char __user
*user_buf
,
1446 size_t count
, loff_t
*ppos
)
1448 struct device
*dev
= ((struct seq_file
*)(file
->private_data
))->private;
1451 unsigned long user_val
;
1453 unsigned int irq_index
;
1455 /* Get userspace string and assure termination */
1456 buf_size
= min(count
, (sizeof(buf
)-1));
1457 if (copy_from_user(buf
, user_buf
, buf_size
))
1461 err
= strict_strtoul(buf
, 0, &user_val
);
1464 if (user_val
< irq_first
) {
1465 dev_err(dev
, "debugfs error input < %d\n", irq_first
);
1468 if (user_val
> irq_last
) {
1469 dev_err(dev
, "debugfs error input > %d\n", irq_last
);
1473 irq_index
= user_val
- irq_first
;
1474 if (irq_index
>= num_irqs
)
1477 /* Set irq count to 0 when unsubscribe */
1478 irq_count
[irq_index
] = 0;
1480 if (dev_attr
[irq_index
])
1481 sysfs_remove_file(&dev
->kobj
, &dev_attr
[irq_index
]->attr
);
1484 free_irq(user_val
, &dev
->kobj
);
1485 kfree(event_name
[irq_index
]);
1486 kfree(dev_attr
[irq_index
]);
1492 * - several deubgfs nodes fops
1495 static const struct file_operations ab8500_bank_fops
= {
1496 .open
= ab8500_bank_open
,
1497 .write
= ab8500_bank_write
,
1499 .llseek
= seq_lseek
,
1500 .release
= single_release
,
1501 .owner
= THIS_MODULE
,
1504 static const struct file_operations ab8500_address_fops
= {
1505 .open
= ab8500_address_open
,
1506 .write
= ab8500_address_write
,
1508 .llseek
= seq_lseek
,
1509 .release
= single_release
,
1510 .owner
= THIS_MODULE
,
1513 static const struct file_operations ab8500_val_fops
= {
1514 .open
= ab8500_val_open
,
1515 .write
= ab8500_val_write
,
1517 .llseek
= seq_lseek
,
1518 .release
= single_release
,
1519 .owner
= THIS_MODULE
,
1522 static const struct file_operations ab8500_interrupts_fops
= {
1523 .open
= ab8500_interrupts_open
,
1525 .llseek
= seq_lseek
,
1526 .release
= single_release
,
1527 .owner
= THIS_MODULE
,
1530 static const struct file_operations ab8500_subscribe_fops
= {
1531 .open
= ab8500_subscribe_unsubscribe_open
,
1532 .write
= ab8500_subscribe_write
,
1534 .llseek
= seq_lseek
,
1535 .release
= single_release
,
1536 .owner
= THIS_MODULE
,
1539 static const struct file_operations ab8500_unsubscribe_fops
= {
1540 .open
= ab8500_subscribe_unsubscribe_open
,
1541 .write
= ab8500_unsubscribe_write
,
1543 .llseek
= seq_lseek
,
1544 .release
= single_release
,
1545 .owner
= THIS_MODULE
,
1548 static const struct file_operations ab8500_hwreg_fops
= {
1549 .open
= ab8500_hwreg_open
,
1550 .write
= ab8500_hwreg_write
,
1552 .llseek
= seq_lseek
,
1553 .release
= single_release
,
1554 .owner
= THIS_MODULE
,
1557 static struct dentry
*ab8500_dir
;
1558 static struct dentry
*ab8500_gpadc_dir
;
1560 static int ab8500_debug_probe(struct platform_device
*plf
)
1562 struct dentry
*file
;
1564 struct ab8500
*ab8500
;
1565 debug_bank
= AB8500_MISC
;
1566 debug_address
= AB8500_REV_REG
& 0x00FF;
1568 ab8500
= dev_get_drvdata(plf
->dev
.parent
);
1569 num_irqs
= ab8500
->mask_size
;
1571 irq_count
= kzalloc(sizeof(*irq_count
)*num_irqs
, GFP_KERNEL
);
1575 dev_attr
= kzalloc(sizeof(*dev_attr
)*num_irqs
,GFP_KERNEL
);
1577 goto out_freeirq_count
;
1579 event_name
= kzalloc(sizeof(*event_name
)*num_irqs
, GFP_KERNEL
);
1581 goto out_freedev_attr
;
1583 irq_first
= platform_get_irq_byname(plf
, "IRQ_FIRST");
1584 if (irq_first
< 0) {
1585 dev_err(&plf
->dev
, "First irq not found, err %d\n",
1588 goto out_freeevent_name
;
1591 irq_last
= platform_get_irq_byname(plf
, "IRQ_LAST");
1593 dev_err(&plf
->dev
, "Last irq not found, err %d\n",
1596 goto out_freeevent_name
;
1599 ab8500_dir
= debugfs_create_dir(AB8500_NAME_STRING
, NULL
);
1603 ab8500_gpadc_dir
= debugfs_create_dir(AB8500_ADC_NAME_STRING
,
1605 if (!ab8500_gpadc_dir
)
1608 file
= debugfs_create_file("all-bank-registers", S_IRUGO
,
1609 ab8500_dir
, &plf
->dev
, &ab8500_registers_fops
);
1613 file
= debugfs_create_file("all-banks", S_IRUGO
,
1614 ab8500_dir
, &plf
->dev
, &ab8500_all_banks_fops
);
1618 file
= debugfs_create_file("register-bank", (S_IRUGO
| S_IWUSR
),
1619 ab8500_dir
, &plf
->dev
, &ab8500_bank_fops
);
1623 file
= debugfs_create_file("register-address", (S_IRUGO
| S_IWUSR
),
1624 ab8500_dir
, &plf
->dev
, &ab8500_address_fops
);
1628 file
= debugfs_create_file("register-value", (S_IRUGO
| S_IWUSR
),
1629 ab8500_dir
, &plf
->dev
, &ab8500_val_fops
);
1633 file
= debugfs_create_file("irq-subscribe", (S_IRUGO
| S_IWUSR
),
1634 ab8500_dir
, &plf
->dev
, &ab8500_subscribe_fops
);
1638 if (is_ab8500(ab8500
))
1639 num_interrupt_lines
= AB8500_NR_IRQS
;
1640 else if (is_ab8505(ab8500
))
1641 num_interrupt_lines
= AB8505_NR_IRQS
;
1642 else if (is_ab9540(ab8500
))
1643 num_interrupt_lines
= AB9540_NR_IRQS
;
1645 file
= debugfs_create_file("interrupts", (S_IRUGO
),
1646 ab8500_dir
, &plf
->dev
, &ab8500_interrupts_fops
);
1650 file
= debugfs_create_file("irq-unsubscribe", (S_IRUGO
| S_IWUSR
),
1651 ab8500_dir
, &plf
->dev
, &ab8500_unsubscribe_fops
);
1655 file
= debugfs_create_file("hwreg", (S_IRUGO
| S_IWUSR
),
1656 ab8500_dir
, &plf
->dev
, &ab8500_hwreg_fops
);
1660 file
= debugfs_create_file("bat_ctrl", (S_IRUGO
| S_IWUSR
),
1661 ab8500_gpadc_dir
, &plf
->dev
, &ab8500_gpadc_bat_ctrl_fops
);
1665 file
= debugfs_create_file("btemp_ball", (S_IRUGO
| S_IWUSR
),
1666 ab8500_gpadc_dir
, &plf
->dev
, &ab8500_gpadc_btemp_ball_fops
);
1670 file
= debugfs_create_file("main_charger_v", (S_IRUGO
| S_IWUSR
),
1671 ab8500_gpadc_dir
, &plf
->dev
, &ab8500_gpadc_main_charger_v_fops
);
1675 file
= debugfs_create_file("acc_detect1", (S_IRUGO
| S_IWUSR
),
1676 ab8500_gpadc_dir
, &plf
->dev
, &ab8500_gpadc_acc_detect1_fops
);
1680 file
= debugfs_create_file("acc_detect2", (S_IRUGO
| S_IWUSR
),
1681 ab8500_gpadc_dir
, &plf
->dev
, &ab8500_gpadc_acc_detect2_fops
);
1685 file
= debugfs_create_file("adc_aux1", (S_IRUGO
| S_IWUSR
),
1686 ab8500_gpadc_dir
, &plf
->dev
, &ab8500_gpadc_aux1_fops
);
1690 file
= debugfs_create_file("adc_aux2", (S_IRUGO
| S_IWUSR
),
1691 ab8500_gpadc_dir
, &plf
->dev
, &ab8500_gpadc_aux2_fops
);
1695 file
= debugfs_create_file("main_bat_v", (S_IRUGO
| S_IWUSR
),
1696 ab8500_gpadc_dir
, &plf
->dev
, &ab8500_gpadc_main_bat_v_fops
);
1700 file
= debugfs_create_file("vbus_v", (S_IRUGO
| S_IWUSR
),
1701 ab8500_gpadc_dir
, &plf
->dev
, &ab8500_gpadc_vbus_v_fops
);
1705 file
= debugfs_create_file("main_charger_c", (S_IRUGO
| S_IWUSR
),
1706 ab8500_gpadc_dir
, &plf
->dev
, &ab8500_gpadc_main_charger_c_fops
);
1710 file
= debugfs_create_file("usb_charger_c", (S_IRUGO
| S_IWUSR
),
1711 ab8500_gpadc_dir
, &plf
->dev
, &ab8500_gpadc_usb_charger_c_fops
);
1715 file
= debugfs_create_file("bk_bat_v", (S_IRUGO
| S_IWUSR
),
1716 ab8500_gpadc_dir
, &plf
->dev
, &ab8500_gpadc_bk_bat_v_fops
);
1720 file
= debugfs_create_file("die_temp", (S_IRUGO
| S_IWUSR
),
1721 ab8500_gpadc_dir
, &plf
->dev
, &ab8500_gpadc_die_temp_fops
);
1729 debugfs_remove_recursive(ab8500_dir
);
1730 dev_err(&plf
->dev
, "failed to create debugfs entries.\n");
1741 static int ab8500_debug_remove(struct platform_device
*plf
)
1743 debugfs_remove_recursive(ab8500_dir
);
1751 static struct platform_driver ab8500_debug_driver
= {
1753 .name
= "ab8500-debug",
1754 .owner
= THIS_MODULE
,
1756 .probe
= ab8500_debug_probe
,
1757 .remove
= ab8500_debug_remove
1760 static int __init
ab8500_debug_init(void)
1762 return platform_driver_register(&ab8500_debug_driver
);
1765 static void __exit
ab8500_debug_exit(void)
1767 platform_driver_unregister(&ab8500_debug_driver
);
1769 subsys_initcall(ab8500_debug_init
);
1770 module_exit(ab8500_debug_exit
);
1772 MODULE_AUTHOR("Mattias WALLIN <mattias.wallin@stericsson.com");
1773 MODULE_DESCRIPTION("AB8500 DEBUG");
1774 MODULE_LICENSE("GPL v2");