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/init.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>
83 #include <linux/irq.h>
85 #include <linux/mfd/abx500.h>
86 #include <linux/mfd/abx500/ab8500.h>
87 #include <linux/mfd/abx500/ab8500-gpadc.h>
89 #ifdef CONFIG_DEBUG_FS
90 #include <linux/string.h>
91 #include <linux/ctype.h>
94 static u32 debug_bank
;
95 static u32 debug_address
;
97 static int irq_ab8500
;
100 static u32
*irq_count
;
103 static struct device_attribute
**dev_attr
;
104 static char **event_name
;
106 static u8 avg_sample
= SAMPLE_16
;
107 static u8 trig_edge
= RISING_EDGE
;
108 static u8 conv_type
= ADC_SW
;
109 static u8 trig_timer
;
112 * struct ab8500_reg_range
113 * @first: the first address of the range
114 * @last: the last address of the range
115 * @perm: access permissions for the range
117 struct ab8500_reg_range
{
124 * struct ab8500_prcmu_ranges
125 * @num_ranges: the number of ranges in the list
126 * @bankid: bank identifier
127 * @range: the list of register ranges
129 struct ab8500_prcmu_ranges
{
132 const struct ab8500_reg_range
*range
;
135 /* hwreg- "mask" and "shift" entries ressources */
137 u32 bank
; /* target bank */
138 unsigned long addr
; /* target address */
139 uint fmt
; /* format */
140 unsigned long mask
; /* read/write mask, applied before any bit shift */
141 long shift
; /* bit shift (read:right shift, write:left shift */
143 /* fmt bit #0: 0=hexa, 1=dec */
144 #define REG_FMT_DEC(c) ((c)->fmt & 0x1)
145 #define REG_FMT_HEX(c) (!REG_FMT_DEC(c))
147 static struct hwreg_cfg hwreg_cfg
= {
148 .addr
= 0, /* default: invalid phys addr */
149 .fmt
= 0, /* default: 32bit access, hex output */
150 .mask
= 0xFFFFFFFF, /* default: no mask */
151 .shift
= 0, /* default: no bit shift */
154 #define AB8500_NAME_STRING "ab8500"
155 #define AB8500_ADC_NAME_STRING "gpadc"
156 #define AB8500_NUM_BANKS AB8500_DEBUG_FIELD_LAST
158 #define AB8500_REV_REG 0x80
160 static struct ab8500_prcmu_ranges
*debug_ranges
;
162 static struct ab8500_prcmu_ranges ab8500_debug_ranges
[AB8500_NUM_BANKS
] = {
163 [AB8500_M_FSM_RANK
] = {
167 [AB8500_SYS_CTRL1_BLOCK
] = {
169 .range
= (struct ab8500_reg_range
[]) {
184 [AB8500_SYS_CTRL2_BLOCK
] = {
186 .range
= (struct ab8500_reg_range
[]) {
205 [AB8500_REGU_CTRL1
] = {
207 .range
= (struct ab8500_reg_range
[]) {
222 [AB8500_REGU_CTRL2
] = {
224 .range
= (struct ab8500_reg_range
[]) {
246 * 0x80-0x8B are SIM registers and should
247 * not be accessed from here
253 .range
= (struct ab8500_reg_range
[]) {
266 .range
= (struct ab8500_reg_range
[]) {
309 [AB8500_ECI_AV_ACC
] = {
311 .range
= (struct ab8500_reg_range
[]) {
318 [AB8500_RESERVED
] = {
324 .range
= (struct ab8500_reg_range
[]) {
333 .range
= (struct ab8500_reg_range
[]) {
372 [AB8500_GAS_GAUGE
] = {
374 .range
= (struct ab8500_reg_range
[]) {
391 .range
= (struct ab8500_reg_range
[]) {
398 [AB8500_INTERRUPT
] = {
404 .range
= (struct ab8500_reg_range
[]) {
413 .range
= (struct ab8500_reg_range
[]) {
448 [AB8500_DEVELOPMENT
] = {
450 .range
= (struct ab8500_reg_range
[]) {
459 .range
= (struct ab8500_reg_range
[]) {
466 [AB8500_PROD_TEST
] = {
470 [AB8500_STE_TEST
] = {
474 [AB8500_OTP_EMUL
] = {
476 .range
= (struct ab8500_reg_range
[]) {
485 static struct ab8500_prcmu_ranges ab8505_debug_ranges
[AB8500_NUM_BANKS
] = {
490 [AB8500_SYS_CTRL1_BLOCK
] = {
492 .range
= (struct ab8500_reg_range
[]) {
515 [AB8500_SYS_CTRL2_BLOCK
] = {
517 .range
= (struct ab8500_reg_range
[]) {
540 [AB8500_REGU_CTRL1
] = {
542 .range
= (struct ab8500_reg_range
[]) {
557 [AB8500_REGU_CTRL2
] = {
559 .range
= (struct ab8500_reg_range
[]) {
585 * 0x80-0x8B are SIM registers and should
586 * not be accessed from here
592 .range
= (struct ab8500_reg_range
[]) {
615 [AB8500_ECI_AV_ACC
] = {
617 .range
= (struct ab8500_reg_range
[]) {
624 [AB8500_RESERVED
] = {
630 .range
= (struct ab8500_reg_range
[]) {
639 .range
= (struct ab8500_reg_range
[]) {
678 [AB8500_GAS_GAUGE
] = {
680 .range
= (struct ab8500_reg_range
[]) {
697 .range
= (struct ab8500_reg_range
[]) {
704 [AB8500_INTERRUPT
] = {
706 .range
= (struct ab8500_reg_range
[]) {
731 /* Latch registers should not be read here */
752 /* LatchHier registers should not be read here */
757 .range
= (struct ab8500_reg_range
[]) {
770 .range
= (struct ab8500_reg_range
[]) {
805 [AB8500_DEVELOPMENT
] = {
807 .range
= (struct ab8500_reg_range
[]) {
820 .range
= (struct ab8500_reg_range
[]) {
827 [AB8500_PROD_TEST
] = {
831 [AB8500_STE_TEST
] = {
835 [AB8500_OTP_EMUL
] = {
837 .range
= (struct ab8500_reg_range
[]) {
846 static struct ab8500_prcmu_ranges ab8540_debug_ranges
[AB8500_NUM_BANKS
] = {
847 [AB8500_M_FSM_RANK
] = {
849 .range
= (struct ab8500_reg_range
[]) {
856 [AB8500_SYS_CTRL1_BLOCK
] = {
858 .range
= (struct ab8500_reg_range
[]) {
885 [AB8500_SYS_CTRL2_BLOCK
] = {
887 .range
= (struct ab8500_reg_range
[]) {
910 [AB8500_REGU_CTRL1
] = {
912 .range
= (struct ab8500_reg_range
[]) {
931 [AB8500_REGU_CTRL2
] = {
933 .range
= (struct ab8500_reg_range
[]) {
970 .range
= (struct ab8500_reg_range
[]) {
991 .range
= (struct ab8500_reg_range
[]) {
1010 [AB8500_ECI_AV_ACC
] = {
1012 .range
= (struct ab8500_reg_range
[]) {
1023 [AB8500_RESERVED
] = {
1029 .range
= (struct ab8500_reg_range
[]) {
1048 [AB8500_CHARGER
] = {
1050 .range
= (struct ab8500_reg_range
[]) {
1093 [AB8500_GAS_GAUGE
] = {
1095 .range
= (struct ab8500_reg_range
[]) {
1112 .range
= (struct ab8500_reg_range
[]) {
1119 [AB8500_INTERRUPT
] = {
1121 .range
= (struct ab8500_reg_range
[]) {
1134 /* Latch registers should not be read here */
1147 /* LatchHier registers should not be read here */
1152 .range
= (struct ab8500_reg_range
[]) {
1169 .range
= (struct ab8500_reg_range
[]) {
1208 [AB8500_DEVELOPMENT
] = {
1210 .range
= (struct ab8500_reg_range
[]) {
1227 .range
= (struct ab8500_reg_range
[]) {
1242 [AB8500_PROD_TEST
] = {
1246 [AB8500_STE_TEST
] = {
1250 [AB8500_OTP_EMUL
] = {
1252 .range
= (struct ab8500_reg_range
[]) {
1261 static irqreturn_t
ab8500_debug_handler(int irq
, void *data
)
1264 struct kobject
*kobj
= (struct kobject
*)data
;
1265 unsigned int irq_abb
= irq
- irq_first
;
1267 if (irq_abb
< num_irqs
)
1268 irq_count
[irq_abb
]++;
1270 * This makes it possible to use poll for events (EPOLLPRI | EPOLLERR)
1271 * from userspace on sysfs file named <irq-nr>
1273 sprintf(buf
, "%d", irq
);
1274 sysfs_notify(kobj
, NULL
, buf
);
1279 /* Prints to seq_file or log_buf */
1280 static int ab8500_registers_print(struct device
*dev
, u32 bank
,
1285 for (i
= 0; i
< debug_ranges
[bank
].num_ranges
; i
++) {
1288 for (reg
= debug_ranges
[bank
].range
[i
].first
;
1289 reg
<= debug_ranges
[bank
].range
[i
].last
;
1294 err
= abx500_get_register_interruptible(dev
,
1295 (u8
)bank
, (u8
)reg
, &value
);
1297 dev_err(dev
, "ab->read fail %d\n", err
);
1302 seq_printf(s
, " [0x%02X/0x%02X]: 0x%02X\n",
1305 * Error is not returned here since
1306 * the output is wanted in any case
1308 if (seq_has_overflowed(s
))
1311 dev_info(dev
, " [0x%02X/0x%02X]: 0x%02X\n",
1320 static int ab8500_bank_registers_show(struct seq_file
*s
, void *p
)
1322 struct device
*dev
= s
->private;
1323 u32 bank
= debug_bank
;
1325 seq_puts(s
, AB8500_NAME_STRING
" register values:\n");
1327 seq_printf(s
, " bank 0x%02X:\n", bank
);
1329 return ab8500_registers_print(dev
, bank
, s
);
1332 DEFINE_SHOW_ATTRIBUTE(ab8500_bank_registers
);
1334 static int ab8500_print_all_banks(struct seq_file
*s
, void *p
)
1336 struct device
*dev
= s
->private;
1339 seq_puts(s
, AB8500_NAME_STRING
" register values:\n");
1341 for (i
= 0; i
< AB8500_NUM_BANKS
; i
++) {
1344 seq_printf(s
, " bank 0x%02X:\n", i
);
1345 err
= ab8500_registers_print(dev
, i
, s
);
1352 /* Dump registers to kernel log */
1353 void ab8500_dump_all_banks(struct device
*dev
)
1357 dev_info(dev
, "ab8500 register values:\n");
1359 for (i
= 1; i
< AB8500_NUM_BANKS
; i
++) {
1360 dev_info(dev
, " bank 0x%02X:\n", i
);
1361 ab8500_registers_print(dev
, i
, NULL
);
1365 static int ab8500_all_banks_open(struct inode
*inode
, struct file
*file
)
1370 err
= single_open(file
, ab8500_print_all_banks
, inode
->i_private
);
1372 /* Default buf size in seq_read is not enough */
1373 s
= (struct seq_file
*)file
->private_data
;
1374 s
->size
= (PAGE_SIZE
* 2);
1375 s
->buf
= kmalloc(s
->size
, GFP_KERNEL
);
1377 single_release(inode
, file
);
1384 static const struct file_operations ab8500_all_banks_fops
= {
1385 .open
= ab8500_all_banks_open
,
1387 .llseek
= seq_lseek
,
1388 .release
= single_release
,
1389 .owner
= THIS_MODULE
,
1392 static int ab8500_bank_print(struct seq_file
*s
, void *p
)
1394 seq_printf(s
, "0x%02X\n", debug_bank
);
1398 static int ab8500_bank_open(struct inode
*inode
, struct file
*file
)
1400 return single_open(file
, ab8500_bank_print
, inode
->i_private
);
1403 static ssize_t
ab8500_bank_write(struct file
*file
,
1404 const char __user
*user_buf
,
1405 size_t count
, loff_t
*ppos
)
1407 struct device
*dev
= ((struct seq_file
*)(file
->private_data
))->private;
1408 unsigned long user_bank
;
1411 err
= kstrtoul_from_user(user_buf
, count
, 0, &user_bank
);
1415 if (user_bank
>= AB8500_NUM_BANKS
) {
1416 dev_err(dev
, "debugfs error input > number of banks\n");
1420 debug_bank
= user_bank
;
1425 static int ab8500_address_print(struct seq_file
*s
, void *p
)
1427 seq_printf(s
, "0x%02X\n", debug_address
);
1431 static int ab8500_address_open(struct inode
*inode
, struct file
*file
)
1433 return single_open(file
, ab8500_address_print
, inode
->i_private
);
1436 static ssize_t
ab8500_address_write(struct file
*file
,
1437 const char __user
*user_buf
,
1438 size_t count
, loff_t
*ppos
)
1440 struct device
*dev
= ((struct seq_file
*)(file
->private_data
))->private;
1441 unsigned long user_address
;
1444 err
= kstrtoul_from_user(user_buf
, count
, 0, &user_address
);
1448 if (user_address
> 0xff) {
1449 dev_err(dev
, "debugfs error input > 0xff\n");
1452 debug_address
= user_address
;
1457 static int ab8500_val_print(struct seq_file
*s
, void *p
)
1459 struct device
*dev
= s
->private;
1463 ret
= abx500_get_register_interruptible(dev
,
1464 (u8
)debug_bank
, (u8
)debug_address
, ®value
);
1466 dev_err(dev
, "abx500_get_reg fail %d, %d\n",
1470 seq_printf(s
, "0x%02X\n", regvalue
);
1475 static int ab8500_val_open(struct inode
*inode
, struct file
*file
)
1477 return single_open(file
, ab8500_val_print
, inode
->i_private
);
1480 static ssize_t
ab8500_val_write(struct file
*file
,
1481 const char __user
*user_buf
,
1482 size_t count
, loff_t
*ppos
)
1484 struct device
*dev
= ((struct seq_file
*)(file
->private_data
))->private;
1485 unsigned long user_val
;
1488 err
= kstrtoul_from_user(user_buf
, count
, 0, &user_val
);
1492 if (user_val
> 0xff) {
1493 dev_err(dev
, "debugfs error input > 0xff\n");
1496 err
= abx500_set_register_interruptible(dev
,
1497 (u8
)debug_bank
, debug_address
, (u8
)user_val
);
1499 pr_err("abx500_set_reg failed %d, %d", err
, __LINE__
);
1509 static u32 num_interrupts
[AB8500_MAX_NR_IRQS
];
1510 static u32 num_wake_interrupts
[AB8500_MAX_NR_IRQS
];
1511 static int num_interrupt_lines
;
1513 void ab8500_debug_register_interrupt(int line
)
1515 if (line
< num_interrupt_lines
)
1516 num_interrupts
[line
]++;
1519 static int ab8500_interrupts_show(struct seq_file
*s
, void *p
)
1523 seq_puts(s
, "name: number: number of: wake:\n");
1525 for (line
= 0; line
< num_interrupt_lines
; line
++) {
1526 struct irq_desc
*desc
= irq_to_desc(line
+ irq_first
);
1528 seq_printf(s
, "%3i: %6i %4i",
1530 num_interrupts
[line
],
1531 num_wake_interrupts
[line
]);
1533 if (desc
&& desc
->name
)
1534 seq_printf(s
, "-%-8s", desc
->name
);
1535 if (desc
&& desc
->action
) {
1536 struct irqaction
*action
= desc
->action
;
1538 seq_printf(s
, " %s", action
->name
);
1539 while ((action
= action
->next
) != NULL
)
1540 seq_printf(s
, ", %s", action
->name
);
1548 DEFINE_SHOW_ATTRIBUTE(ab8500_interrupts
);
1551 * - HWREG DB8500 formated routines
1553 static int ab8500_hwreg_print(struct seq_file
*s
, void *d
)
1555 struct device
*dev
= s
->private;
1559 ret
= abx500_get_register_interruptible(dev
,
1560 (u8
)hwreg_cfg
.bank
, (u8
)hwreg_cfg
.addr
, ®value
);
1562 dev_err(dev
, "abx500_get_reg fail %d, %d\n",
1567 if (hwreg_cfg
.shift
>= 0)
1568 regvalue
>>= hwreg_cfg
.shift
;
1570 regvalue
<<= -hwreg_cfg
.shift
;
1571 regvalue
&= hwreg_cfg
.mask
;
1573 if (REG_FMT_DEC(&hwreg_cfg
))
1574 seq_printf(s
, "%d\n", regvalue
);
1576 seq_printf(s
, "0x%02X\n", regvalue
);
1580 static int ab8500_hwreg_open(struct inode
*inode
, struct file
*file
)
1582 return single_open(file
, ab8500_hwreg_print
, inode
->i_private
);
1585 #define AB8500_SUPPLY_CONTROL_CONFIG_1 0x01
1586 #define AB8500_SUPPLY_CONTROL_REG 0x00
1587 #define AB8500_FIRST_SIM_REG 0x80
1588 #define AB8500_LAST_SIM_REG 0x8B
1589 #define AB8505_LAST_SIM_REG 0x8C
1591 static int ab8500_modem_show(struct seq_file
*s
, void *p
)
1593 struct device
*dev
= s
->private;
1594 struct ab8500
*ab8500
;
1598 u32 bank
= AB8500_REGU_CTRL2
;
1599 u32 last_sim_reg
= AB8500_LAST_SIM_REG
;
1602 ab8500
= dev_get_drvdata(dev
->parent
);
1603 dev_warn(dev
, "WARNING! This operation can interfer with modem side\n"
1604 "and should only be done with care\n");
1606 err
= abx500_get_register_interruptible(dev
,
1607 AB8500_REGU_CTRL1
, AB8500_SUPPLY_CONTROL_REG
, &orig_value
);
1609 goto report_read_failure
;
1611 /* Config 1 will allow APE side to read SIM registers */
1612 err
= abx500_set_register_interruptible(dev
,
1613 AB8500_REGU_CTRL1
, AB8500_SUPPLY_CONTROL_REG
,
1614 AB8500_SUPPLY_CONTROL_CONFIG_1
);
1616 goto report_write_failure
;
1618 seq_printf(s
, " bank 0x%02X:\n", bank
);
1620 if (is_ab9540(ab8500
) || is_ab8505(ab8500
))
1621 last_sim_reg
= AB8505_LAST_SIM_REG
;
1623 for (reg
= AB8500_FIRST_SIM_REG
; reg
<= last_sim_reg
; reg
++) {
1624 err
= abx500_get_register_interruptible(dev
,
1627 goto report_read_failure
;
1629 seq_printf(s
, " [0x%02X/0x%02X]: 0x%02X\n", bank
, reg
, value
);
1631 err
= abx500_set_register_interruptible(dev
,
1632 AB8500_REGU_CTRL1
, AB8500_SUPPLY_CONTROL_REG
, orig_value
);
1634 goto report_write_failure
;
1638 report_read_failure
:
1639 dev_err(dev
, "ab->read fail %d\n", err
);
1642 report_write_failure
:
1643 dev_err(dev
, "ab->write fail %d\n", err
);
1647 DEFINE_SHOW_ATTRIBUTE(ab8500_modem
);
1649 static int ab8500_gpadc_bat_ctrl_show(struct seq_file
*s
, void *p
)
1652 int bat_ctrl_convert
;
1653 struct ab8500_gpadc
*gpadc
;
1655 gpadc
= ab8500_gpadc_get("ab8500-gpadc.0");
1656 bat_ctrl_raw
= ab8500_gpadc_read_raw(gpadc
, BAT_CTRL
,
1657 avg_sample
, trig_edge
, trig_timer
, conv_type
);
1658 bat_ctrl_convert
= ab8500_gpadc_ad_to_voltage(gpadc
,
1659 BAT_CTRL
, bat_ctrl_raw
);
1661 seq_printf(s
, "%d,0x%X\n", bat_ctrl_convert
, bat_ctrl_raw
);
1666 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_bat_ctrl
);
1668 static int ab8500_gpadc_btemp_ball_show(struct seq_file
*s
, void *p
)
1671 int btemp_ball_convert
;
1672 struct ab8500_gpadc
*gpadc
;
1674 gpadc
= ab8500_gpadc_get("ab8500-gpadc.0");
1675 btemp_ball_raw
= ab8500_gpadc_read_raw(gpadc
, BTEMP_BALL
,
1676 avg_sample
, trig_edge
, trig_timer
, conv_type
);
1677 btemp_ball_convert
= ab8500_gpadc_ad_to_voltage(gpadc
, BTEMP_BALL
,
1680 seq_printf(s
, "%d,0x%X\n", btemp_ball_convert
, btemp_ball_raw
);
1685 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_btemp_ball
);
1687 static int ab8500_gpadc_main_charger_v_show(struct seq_file
*s
, void *p
)
1689 int main_charger_v_raw
;
1690 int main_charger_v_convert
;
1691 struct ab8500_gpadc
*gpadc
;
1693 gpadc
= ab8500_gpadc_get("ab8500-gpadc.0");
1694 main_charger_v_raw
= ab8500_gpadc_read_raw(gpadc
, MAIN_CHARGER_V
,
1695 avg_sample
, trig_edge
, trig_timer
, conv_type
);
1696 main_charger_v_convert
= ab8500_gpadc_ad_to_voltage(gpadc
,
1697 MAIN_CHARGER_V
, main_charger_v_raw
);
1699 seq_printf(s
, "%d,0x%X\n", main_charger_v_convert
, main_charger_v_raw
);
1704 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_main_charger_v
);
1706 static int ab8500_gpadc_acc_detect1_show(struct seq_file
*s
, void *p
)
1708 int acc_detect1_raw
;
1709 int acc_detect1_convert
;
1710 struct ab8500_gpadc
*gpadc
;
1712 gpadc
= ab8500_gpadc_get("ab8500-gpadc.0");
1713 acc_detect1_raw
= ab8500_gpadc_read_raw(gpadc
, ACC_DETECT1
,
1714 avg_sample
, trig_edge
, trig_timer
, conv_type
);
1715 acc_detect1_convert
= ab8500_gpadc_ad_to_voltage(gpadc
, ACC_DETECT1
,
1718 seq_printf(s
, "%d,0x%X\n", acc_detect1_convert
, acc_detect1_raw
);
1723 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_acc_detect1
);
1725 static int ab8500_gpadc_acc_detect2_show(struct seq_file
*s
, void *p
)
1727 int acc_detect2_raw
;
1728 int acc_detect2_convert
;
1729 struct ab8500_gpadc
*gpadc
;
1731 gpadc
= ab8500_gpadc_get("ab8500-gpadc.0");
1732 acc_detect2_raw
= ab8500_gpadc_read_raw(gpadc
, ACC_DETECT2
,
1733 avg_sample
, trig_edge
, trig_timer
, conv_type
);
1734 acc_detect2_convert
= ab8500_gpadc_ad_to_voltage(gpadc
,
1735 ACC_DETECT2
, acc_detect2_raw
);
1737 seq_printf(s
, "%d,0x%X\n", acc_detect2_convert
, acc_detect2_raw
);
1742 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_acc_detect2
);
1744 static int ab8500_gpadc_aux1_show(struct seq_file
*s
, void *p
)
1748 struct ab8500_gpadc
*gpadc
;
1750 gpadc
= ab8500_gpadc_get("ab8500-gpadc.0");
1751 aux1_raw
= ab8500_gpadc_read_raw(gpadc
, ADC_AUX1
,
1752 avg_sample
, trig_edge
, trig_timer
, conv_type
);
1753 aux1_convert
= ab8500_gpadc_ad_to_voltage(gpadc
, ADC_AUX1
,
1756 seq_printf(s
, "%d,0x%X\n", aux1_convert
, aux1_raw
);
1761 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_aux1
);
1763 static int ab8500_gpadc_aux2_show(struct seq_file
*s
, void *p
)
1767 struct ab8500_gpadc
*gpadc
;
1769 gpadc
= ab8500_gpadc_get("ab8500-gpadc.0");
1770 aux2_raw
= ab8500_gpadc_read_raw(gpadc
, ADC_AUX2
,
1771 avg_sample
, trig_edge
, trig_timer
, conv_type
);
1772 aux2_convert
= ab8500_gpadc_ad_to_voltage(gpadc
, ADC_AUX2
,
1775 seq_printf(s
, "%d,0x%X\n", aux2_convert
, aux2_raw
);
1780 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_aux2
);
1782 static int ab8500_gpadc_main_bat_v_show(struct seq_file
*s
, void *p
)
1785 int main_bat_v_convert
;
1786 struct ab8500_gpadc
*gpadc
;
1788 gpadc
= ab8500_gpadc_get("ab8500-gpadc.0");
1789 main_bat_v_raw
= ab8500_gpadc_read_raw(gpadc
, MAIN_BAT_V
,
1790 avg_sample
, trig_edge
, trig_timer
, conv_type
);
1791 main_bat_v_convert
= ab8500_gpadc_ad_to_voltage(gpadc
, MAIN_BAT_V
,
1794 seq_printf(s
, "%d,0x%X\n", main_bat_v_convert
, main_bat_v_raw
);
1799 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_main_bat_v
);
1801 static int ab8500_gpadc_vbus_v_show(struct seq_file
*s
, void *p
)
1805 struct ab8500_gpadc
*gpadc
;
1807 gpadc
= ab8500_gpadc_get("ab8500-gpadc.0");
1808 vbus_v_raw
= ab8500_gpadc_read_raw(gpadc
, VBUS_V
,
1809 avg_sample
, trig_edge
, trig_timer
, conv_type
);
1810 vbus_v_convert
= ab8500_gpadc_ad_to_voltage(gpadc
, VBUS_V
,
1813 seq_printf(s
, "%d,0x%X\n", vbus_v_convert
, vbus_v_raw
);
1818 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_vbus_v
);
1820 static int ab8500_gpadc_main_charger_c_show(struct seq_file
*s
, void *p
)
1822 int main_charger_c_raw
;
1823 int main_charger_c_convert
;
1824 struct ab8500_gpadc
*gpadc
;
1826 gpadc
= ab8500_gpadc_get("ab8500-gpadc.0");
1827 main_charger_c_raw
= ab8500_gpadc_read_raw(gpadc
, MAIN_CHARGER_C
,
1828 avg_sample
, trig_edge
, trig_timer
, conv_type
);
1829 main_charger_c_convert
= ab8500_gpadc_ad_to_voltage(gpadc
,
1830 MAIN_CHARGER_C
, main_charger_c_raw
);
1832 seq_printf(s
, "%d,0x%X\n", main_charger_c_convert
, main_charger_c_raw
);
1837 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_main_charger_c
);
1839 static int ab8500_gpadc_usb_charger_c_show(struct seq_file
*s
, void *p
)
1841 int usb_charger_c_raw
;
1842 int usb_charger_c_convert
;
1843 struct ab8500_gpadc
*gpadc
;
1845 gpadc
= ab8500_gpadc_get("ab8500-gpadc.0");
1846 usb_charger_c_raw
= ab8500_gpadc_read_raw(gpadc
, USB_CHARGER_C
,
1847 avg_sample
, trig_edge
, trig_timer
, conv_type
);
1848 usb_charger_c_convert
= ab8500_gpadc_ad_to_voltage(gpadc
,
1849 USB_CHARGER_C
, usb_charger_c_raw
);
1851 seq_printf(s
, "%d,0x%X\n", usb_charger_c_convert
, usb_charger_c_raw
);
1856 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_usb_charger_c
);
1858 static int ab8500_gpadc_bk_bat_v_show(struct seq_file
*s
, void *p
)
1861 int bk_bat_v_convert
;
1862 struct ab8500_gpadc
*gpadc
;
1864 gpadc
= ab8500_gpadc_get("ab8500-gpadc.0");
1865 bk_bat_v_raw
= ab8500_gpadc_read_raw(gpadc
, BK_BAT_V
,
1866 avg_sample
, trig_edge
, trig_timer
, conv_type
);
1867 bk_bat_v_convert
= ab8500_gpadc_ad_to_voltage(gpadc
,
1868 BK_BAT_V
, bk_bat_v_raw
);
1870 seq_printf(s
, "%d,0x%X\n", bk_bat_v_convert
, bk_bat_v_raw
);
1875 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_bk_bat_v
);
1877 static int ab8500_gpadc_die_temp_show(struct seq_file
*s
, void *p
)
1880 int die_temp_convert
;
1881 struct ab8500_gpadc
*gpadc
;
1883 gpadc
= ab8500_gpadc_get("ab8500-gpadc.0");
1884 die_temp_raw
= ab8500_gpadc_read_raw(gpadc
, DIE_TEMP
,
1885 avg_sample
, trig_edge
, trig_timer
, conv_type
);
1886 die_temp_convert
= ab8500_gpadc_ad_to_voltage(gpadc
, DIE_TEMP
,
1889 seq_printf(s
, "%d,0x%X\n", die_temp_convert
, die_temp_raw
);
1894 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_die_temp
);
1896 static int ab8500_gpadc_usb_id_show(struct seq_file
*s
, void *p
)
1900 struct ab8500_gpadc
*gpadc
;
1902 gpadc
= ab8500_gpadc_get("ab8500-gpadc.0");
1903 usb_id_raw
= ab8500_gpadc_read_raw(gpadc
, USB_ID
,
1904 avg_sample
, trig_edge
, trig_timer
, conv_type
);
1905 usb_id_convert
= ab8500_gpadc_ad_to_voltage(gpadc
, USB_ID
,
1908 seq_printf(s
, "%d,0x%X\n", usb_id_convert
, usb_id_raw
);
1913 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_usb_id
);
1915 static int ab8540_gpadc_xtal_temp_show(struct seq_file
*s
, void *p
)
1918 int xtal_temp_convert
;
1919 struct ab8500_gpadc
*gpadc
;
1921 gpadc
= ab8500_gpadc_get("ab8500-gpadc.0");
1922 xtal_temp_raw
= ab8500_gpadc_read_raw(gpadc
, XTAL_TEMP
,
1923 avg_sample
, trig_edge
, trig_timer
, conv_type
);
1924 xtal_temp_convert
= ab8500_gpadc_ad_to_voltage(gpadc
, XTAL_TEMP
,
1927 seq_printf(s
, "%d,0x%X\n", xtal_temp_convert
, xtal_temp_raw
);
1932 DEFINE_SHOW_ATTRIBUTE(ab8540_gpadc_xtal_temp
);
1934 static int ab8540_gpadc_vbat_true_meas_show(struct seq_file
*s
, void *p
)
1936 int vbat_true_meas_raw
;
1937 int vbat_true_meas_convert
;
1938 struct ab8500_gpadc
*gpadc
;
1940 gpadc
= ab8500_gpadc_get("ab8500-gpadc.0");
1941 vbat_true_meas_raw
= ab8500_gpadc_read_raw(gpadc
, VBAT_TRUE_MEAS
,
1942 avg_sample
, trig_edge
, trig_timer
, conv_type
);
1943 vbat_true_meas_convert
=
1944 ab8500_gpadc_ad_to_voltage(gpadc
, VBAT_TRUE_MEAS
,
1945 vbat_true_meas_raw
);
1947 seq_printf(s
, "%d,0x%X\n", vbat_true_meas_convert
, vbat_true_meas_raw
);
1952 DEFINE_SHOW_ATTRIBUTE(ab8540_gpadc_vbat_true_meas
);
1954 static int ab8540_gpadc_bat_ctrl_and_ibat_show(struct seq_file
*s
, void *p
)
1957 int bat_ctrl_convert
;
1960 struct ab8500_gpadc
*gpadc
;
1962 gpadc
= ab8500_gpadc_get("ab8500-gpadc.0");
1963 bat_ctrl_raw
= ab8500_gpadc_double_read_raw(gpadc
, BAT_CTRL_AND_IBAT
,
1964 avg_sample
, trig_edge
, trig_timer
, conv_type
, &ibat_raw
);
1966 bat_ctrl_convert
= ab8500_gpadc_ad_to_voltage(gpadc
, BAT_CTRL
,
1968 ibat_convert
= ab8500_gpadc_ad_to_voltage(gpadc
, IBAT_VIRTUAL_CHANNEL
,
1974 bat_ctrl_convert
, bat_ctrl_raw
,
1975 ibat_convert
, ibat_raw
);
1980 DEFINE_SHOW_ATTRIBUTE(ab8540_gpadc_bat_ctrl_and_ibat
);
1982 static int ab8540_gpadc_vbat_meas_and_ibat_show(struct seq_file
*s
, void *p
)
1985 int vbat_meas_convert
;
1988 struct ab8500_gpadc
*gpadc
;
1990 gpadc
= ab8500_gpadc_get("ab8500-gpadc.0");
1991 vbat_meas_raw
= ab8500_gpadc_double_read_raw(gpadc
, VBAT_MEAS_AND_IBAT
,
1992 avg_sample
, trig_edge
, trig_timer
, conv_type
, &ibat_raw
);
1993 vbat_meas_convert
= ab8500_gpadc_ad_to_voltage(gpadc
, MAIN_BAT_V
,
1995 ibat_convert
= ab8500_gpadc_ad_to_voltage(gpadc
, IBAT_VIRTUAL_CHANNEL
,
2001 vbat_meas_convert
, vbat_meas_raw
,
2002 ibat_convert
, ibat_raw
);
2007 DEFINE_SHOW_ATTRIBUTE(ab8540_gpadc_vbat_meas_and_ibat
);
2009 static int ab8540_gpadc_vbat_true_meas_and_ibat_show(struct seq_file
*s
, void *p
)
2011 int vbat_true_meas_raw
;
2012 int vbat_true_meas_convert
;
2015 struct ab8500_gpadc
*gpadc
;
2017 gpadc
= ab8500_gpadc_get("ab8500-gpadc.0");
2018 vbat_true_meas_raw
= ab8500_gpadc_double_read_raw(gpadc
,
2019 VBAT_TRUE_MEAS_AND_IBAT
, avg_sample
, trig_edge
,
2020 trig_timer
, conv_type
, &ibat_raw
);
2021 vbat_true_meas_convert
= ab8500_gpadc_ad_to_voltage(gpadc
,
2022 VBAT_TRUE_MEAS
, vbat_true_meas_raw
);
2023 ibat_convert
= ab8500_gpadc_ad_to_voltage(gpadc
, IBAT_VIRTUAL_CHANNEL
,
2029 vbat_true_meas_convert
, vbat_true_meas_raw
,
2030 ibat_convert
, ibat_raw
);
2035 DEFINE_SHOW_ATTRIBUTE(ab8540_gpadc_vbat_true_meas_and_ibat
);
2037 static int ab8540_gpadc_bat_temp_and_ibat_show(struct seq_file
*s
, void *p
)
2040 int bat_temp_convert
;
2043 struct ab8500_gpadc
*gpadc
;
2045 gpadc
= ab8500_gpadc_get("ab8500-gpadc.0");
2046 bat_temp_raw
= ab8500_gpadc_double_read_raw(gpadc
, BAT_TEMP_AND_IBAT
,
2047 avg_sample
, trig_edge
, trig_timer
, conv_type
, &ibat_raw
);
2048 bat_temp_convert
= ab8500_gpadc_ad_to_voltage(gpadc
, BTEMP_BALL
,
2050 ibat_convert
= ab8500_gpadc_ad_to_voltage(gpadc
, IBAT_VIRTUAL_CHANNEL
,
2056 bat_temp_convert
, bat_temp_raw
,
2057 ibat_convert
, ibat_raw
);
2062 DEFINE_SHOW_ATTRIBUTE(ab8540_gpadc_bat_temp_and_ibat
);
2064 static int ab8540_gpadc_otp_calib_show(struct seq_file
*s
, void *p
)
2066 struct ab8500_gpadc
*gpadc
;
2067 u16 vmain_l
, vmain_h
, btemp_l
, btemp_h
;
2068 u16 vbat_l
, vbat_h
, ibat_l
, ibat_h
;
2070 gpadc
= ab8500_gpadc_get("ab8500-gpadc.0");
2071 ab8540_gpadc_get_otp(gpadc
, &vmain_l
, &vmain_h
, &btemp_l
, &btemp_h
,
2072 &vbat_l
, &vbat_h
, &ibat_l
, &ibat_h
);
2082 vmain_l
, vmain_h
, btemp_l
, btemp_h
,
2083 vbat_l
, vbat_h
, ibat_l
, ibat_h
);
2088 DEFINE_SHOW_ATTRIBUTE(ab8540_gpadc_otp_calib
);
2090 static int ab8500_gpadc_avg_sample_print(struct seq_file
*s
, void *p
)
2092 seq_printf(s
, "%d\n", avg_sample
);
2097 static int ab8500_gpadc_avg_sample_open(struct inode
*inode
, struct file
*file
)
2099 return single_open(file
, ab8500_gpadc_avg_sample_print
,
2103 static ssize_t
ab8500_gpadc_avg_sample_write(struct file
*file
,
2104 const char __user
*user_buf
,
2105 size_t count
, loff_t
*ppos
)
2107 struct device
*dev
= ((struct seq_file
*)(file
->private_data
))->private;
2108 unsigned long user_avg_sample
;
2111 err
= kstrtoul_from_user(user_buf
, count
, 0, &user_avg_sample
);
2115 if ((user_avg_sample
== SAMPLE_1
) || (user_avg_sample
== SAMPLE_4
)
2116 || (user_avg_sample
== SAMPLE_8
)
2117 || (user_avg_sample
== SAMPLE_16
)) {
2118 avg_sample
= (u8
) user_avg_sample
;
2121 "debugfs err input: should be egal to 1, 4, 8 or 16\n");
2128 static const struct file_operations ab8500_gpadc_avg_sample_fops
= {
2129 .open
= ab8500_gpadc_avg_sample_open
,
2131 .write
= ab8500_gpadc_avg_sample_write
,
2132 .llseek
= seq_lseek
,
2133 .release
= single_release
,
2134 .owner
= THIS_MODULE
,
2137 static int ab8500_gpadc_trig_edge_print(struct seq_file
*s
, void *p
)
2139 seq_printf(s
, "%d\n", trig_edge
);
2144 static int ab8500_gpadc_trig_edge_open(struct inode
*inode
, struct file
*file
)
2146 return single_open(file
, ab8500_gpadc_trig_edge_print
,
2150 static ssize_t
ab8500_gpadc_trig_edge_write(struct file
*file
,
2151 const char __user
*user_buf
,
2152 size_t count
, loff_t
*ppos
)
2154 struct device
*dev
= ((struct seq_file
*)(file
->private_data
))->private;
2155 unsigned long user_trig_edge
;
2158 err
= kstrtoul_from_user(user_buf
, count
, 0, &user_trig_edge
);
2162 if ((user_trig_edge
== RISING_EDGE
)
2163 || (user_trig_edge
== FALLING_EDGE
)) {
2164 trig_edge
= (u8
) user_trig_edge
;
2166 dev_err(dev
, "Wrong input:\n"
2167 "Enter 0. Rising edge\n"
2168 "Enter 1. Falling edge\n");
2175 static const struct file_operations ab8500_gpadc_trig_edge_fops
= {
2176 .open
= ab8500_gpadc_trig_edge_open
,
2178 .write
= ab8500_gpadc_trig_edge_write
,
2179 .llseek
= seq_lseek
,
2180 .release
= single_release
,
2181 .owner
= THIS_MODULE
,
2184 static int ab8500_gpadc_trig_timer_print(struct seq_file
*s
, void *p
)
2186 seq_printf(s
, "%d\n", trig_timer
);
2191 static int ab8500_gpadc_trig_timer_open(struct inode
*inode
, struct file
*file
)
2193 return single_open(file
, ab8500_gpadc_trig_timer_print
,
2197 static ssize_t
ab8500_gpadc_trig_timer_write(struct file
*file
,
2198 const char __user
*user_buf
,
2199 size_t count
, loff_t
*ppos
)
2201 struct device
*dev
= ((struct seq_file
*)(file
->private_data
))->private;
2202 unsigned long user_trig_timer
;
2205 err
= kstrtoul_from_user(user_buf
, count
, 0, &user_trig_timer
);
2209 if (user_trig_timer
& ~0xFF) {
2211 "debugfs error input: should be between 0 to 255\n");
2215 trig_timer
= (u8
) user_trig_timer
;
2220 static const struct file_operations ab8500_gpadc_trig_timer_fops
= {
2221 .open
= ab8500_gpadc_trig_timer_open
,
2223 .write
= ab8500_gpadc_trig_timer_write
,
2224 .llseek
= seq_lseek
,
2225 .release
= single_release
,
2226 .owner
= THIS_MODULE
,
2229 static int ab8500_gpadc_conv_type_print(struct seq_file
*s
, void *p
)
2231 seq_printf(s
, "%d\n", conv_type
);
2236 static int ab8500_gpadc_conv_type_open(struct inode
*inode
, struct file
*file
)
2238 return single_open(file
, ab8500_gpadc_conv_type_print
,
2242 static ssize_t
ab8500_gpadc_conv_type_write(struct file
*file
,
2243 const char __user
*user_buf
,
2244 size_t count
, loff_t
*ppos
)
2246 struct device
*dev
= ((struct seq_file
*)(file
->private_data
))->private;
2247 unsigned long user_conv_type
;
2250 err
= kstrtoul_from_user(user_buf
, count
, 0, &user_conv_type
);
2254 if ((user_conv_type
== ADC_SW
)
2255 || (user_conv_type
== ADC_HW
)) {
2256 conv_type
= (u8
) user_conv_type
;
2258 dev_err(dev
, "Wrong input:\n"
2259 "Enter 0. ADC SW conversion\n"
2260 "Enter 1. ADC HW conversion\n");
2267 static const struct file_operations ab8500_gpadc_conv_type_fops
= {
2268 .open
= ab8500_gpadc_conv_type_open
,
2270 .write
= ab8500_gpadc_conv_type_write
,
2271 .llseek
= seq_lseek
,
2272 .release
= single_release
,
2273 .owner
= THIS_MODULE
,
2277 * return length of an ASCII numerical value, 0 is string is not a
2279 * string shall start at value 1st char.
2280 * string can be tailed with \0 or space or newline chars only.
2281 * value can be decimal or hexadecimal (prefixed 0x or 0X).
2283 static int strval_len(char *b
)
2287 if ((*s
== '0') && ((*(s
+1) == 'x') || (*(s
+1) == 'X'))) {
2289 for (; *s
&& (*s
!= ' ') && (*s
!= '\n'); s
++) {
2296 for (; *s
&& (*s
!= ' ') && (*s
!= '\n'); s
++) {
2305 * parse hwreg input data.
2306 * update global hwreg_cfg only if input data syntax is ok.
2308 static ssize_t
hwreg_common_write(char *b
, struct hwreg_cfg
*cfg
,
2311 uint write
, val
= 0;
2314 struct hwreg_cfg loc
= {
2315 .bank
= 0, /* default: invalid phys addr */
2316 .addr
= 0, /* default: invalid phys addr */
2317 .fmt
= 0, /* default: 32bit access, hex output */
2318 .mask
= 0xFFFFFFFF, /* default: no mask */
2319 .shift
= 0, /* default: no bit shift */
2322 /* read or write ? */
2323 if (!strncmp(b
, "read ", 5)) {
2326 } else if (!strncmp(b
, "write ", 6)) {
2332 /* OPTIONS -l|-w|-b -s -m -o */
2333 while ((*b
== ' ') || (*b
== '-')) {
2334 if (*(b
-1) != ' ') {
2338 if ((!strncmp(b
, "-d ", 3)) ||
2339 (!strncmp(b
, "-dec ", 5))) {
2340 b
+= (*(b
+2) == ' ') ? 3 : 5;
2342 } else if ((!strncmp(b
, "-h ", 3)) ||
2343 (!strncmp(b
, "-hex ", 5))) {
2344 b
+= (*(b
+2) == ' ') ? 3 : 5;
2346 } else if ((!strncmp(b
, "-m ", 3)) ||
2347 (!strncmp(b
, "-mask ", 6))) {
2348 b
+= (*(b
+2) == ' ') ? 3 : 6;
2349 if (strval_len(b
) == 0)
2351 ret
= kstrtoul(b
, 0, &loc
.mask
);
2354 } else if ((!strncmp(b
, "-s ", 3)) ||
2355 (!strncmp(b
, "-shift ", 7))) {
2356 b
+= (*(b
+2) == ' ') ? 3 : 7;
2357 if (strval_len(b
) == 0)
2359 ret
= kstrtol(b
, 0, &loc
.shift
);
2366 /* get arg BANK and ADDRESS */
2367 if (strval_len(b
) == 0)
2369 ret
= kstrtouint(b
, 0, &loc
.bank
);
2374 if (strval_len(b
) == 0)
2376 ret
= kstrtoul(b
, 0, &loc
.addr
);
2383 if (strval_len(b
) == 0)
2385 ret
= kstrtouint(b
, 0, &val
);
2390 /* args are ok, update target cfg (mainly for read) */
2393 #ifdef ABB_HWREG_DEBUG
2394 pr_warn("HWREG request: %s, %s,\n", (write
) ? "write" : "read",
2395 REG_FMT_DEC(cfg
) ? "decimal" : "hexa");
2396 pr_warn(" addr=0x%08X, mask=0x%X, shift=%d" "value=0x%X\n",
2397 cfg
->addr
, cfg
->mask
, cfg
->shift
, val
);
2403 ret
= abx500_get_register_interruptible(dev
,
2404 (u8
)cfg
->bank
, (u8
)cfg
->addr
, ®value
);
2406 dev_err(dev
, "abx500_get_reg fail %d, %d\n",
2411 if (cfg
->shift
>= 0) {
2412 regvalue
&= ~(cfg
->mask
<< (cfg
->shift
));
2413 val
= (val
& cfg
->mask
) << (cfg
->shift
);
2415 regvalue
&= ~(cfg
->mask
>> (-cfg
->shift
));
2416 val
= (val
& cfg
->mask
) >> (-cfg
->shift
);
2418 val
= val
| regvalue
;
2420 ret
= abx500_set_register_interruptible(dev
,
2421 (u8
)cfg
->bank
, (u8
)cfg
->addr
, (u8
)val
);
2423 pr_err("abx500_set_reg failed %d, %d", ret
, __LINE__
);
2430 static ssize_t
ab8500_hwreg_write(struct file
*file
,
2431 const char __user
*user_buf
, size_t count
, loff_t
*ppos
)
2433 struct device
*dev
= ((struct seq_file
*)(file
->private_data
))->private;
2437 /* Get userspace string and assure termination */
2438 buf_size
= min(count
, (sizeof(buf
)-1));
2439 if (copy_from_user(buf
, user_buf
, buf_size
))
2443 /* get args and process */
2444 ret
= hwreg_common_write(buf
, &hwreg_cfg
, dev
);
2445 return (ret
) ? ret
: buf_size
;
2449 * - irq subscribe/unsubscribe stuff
2451 static int ab8500_subscribe_unsubscribe_print(struct seq_file
*s
, void *p
)
2453 seq_printf(s
, "%d\n", irq_first
);
2458 static int ab8500_subscribe_unsubscribe_open(struct inode
*inode
,
2461 return single_open(file
, ab8500_subscribe_unsubscribe_print
,
2466 * Userspace should use poll() on this file. When an event occur
2467 * the blocking poll will be released.
2469 static ssize_t
show_irq(struct device
*dev
,
2470 struct device_attribute
*attr
, char *buf
)
2473 unsigned int irq_index
;
2476 err
= kstrtoul(attr
->attr
.name
, 0, &name
);
2480 irq_index
= name
- irq_first
;
2481 if (irq_index
>= num_irqs
)
2484 return sprintf(buf
, "%u\n", irq_count
[irq_index
]);
2487 static ssize_t
ab8500_subscribe_write(struct file
*file
,
2488 const char __user
*user_buf
,
2489 size_t count
, loff_t
*ppos
)
2491 struct device
*dev
= ((struct seq_file
*)(file
->private_data
))->private;
2492 unsigned long user_val
;
2494 unsigned int irq_index
;
2496 err
= kstrtoul_from_user(user_buf
, count
, 0, &user_val
);
2500 if (user_val
< irq_first
) {
2501 dev_err(dev
, "debugfs error input < %d\n", irq_first
);
2504 if (user_val
> irq_last
) {
2505 dev_err(dev
, "debugfs error input > %d\n", irq_last
);
2509 irq_index
= user_val
- irq_first
;
2510 if (irq_index
>= num_irqs
)
2514 * This will create a sysfs file named <irq-nr> which userspace can
2515 * use to select or poll and get the AB8500 events
2517 dev_attr
[irq_index
] = kmalloc(sizeof(struct device_attribute
),
2519 if (!dev_attr
[irq_index
])
2522 event_name
[irq_index
] = kmalloc(count
, GFP_KERNEL
);
2523 if (!event_name
[irq_index
])
2526 sprintf(event_name
[irq_index
], "%lu", user_val
);
2527 dev_attr
[irq_index
]->show
= show_irq
;
2528 dev_attr
[irq_index
]->store
= NULL
;
2529 dev_attr
[irq_index
]->attr
.name
= event_name
[irq_index
];
2530 dev_attr
[irq_index
]->attr
.mode
= S_IRUGO
;
2531 err
= sysfs_create_file(&dev
->kobj
, &dev_attr
[irq_index
]->attr
);
2533 pr_info("sysfs_create_file failed %d\n", err
);
2537 err
= request_threaded_irq(user_val
, NULL
, ab8500_debug_handler
,
2538 IRQF_SHARED
| IRQF_NO_SUSPEND
| IRQF_ONESHOT
,
2539 "ab8500-debug", &dev
->kobj
);
2541 pr_info("request_threaded_irq failed %d, %lu\n",
2543 sysfs_remove_file(&dev
->kobj
, &dev_attr
[irq_index
]->attr
);
2550 static ssize_t
ab8500_unsubscribe_write(struct file
*file
,
2551 const char __user
*user_buf
,
2552 size_t count
, loff_t
*ppos
)
2554 struct device
*dev
= ((struct seq_file
*)(file
->private_data
))->private;
2555 unsigned long user_val
;
2557 unsigned int irq_index
;
2559 err
= kstrtoul_from_user(user_buf
, count
, 0, &user_val
);
2563 if (user_val
< irq_first
) {
2564 dev_err(dev
, "debugfs error input < %d\n", irq_first
);
2567 if (user_val
> irq_last
) {
2568 dev_err(dev
, "debugfs error input > %d\n", irq_last
);
2572 irq_index
= user_val
- irq_first
;
2573 if (irq_index
>= num_irqs
)
2576 /* Set irq count to 0 when unsubscribe */
2577 irq_count
[irq_index
] = 0;
2579 if (dev_attr
[irq_index
])
2580 sysfs_remove_file(&dev
->kobj
, &dev_attr
[irq_index
]->attr
);
2583 free_irq(user_val
, &dev
->kobj
);
2584 kfree(event_name
[irq_index
]);
2585 kfree(dev_attr
[irq_index
]);
2591 * - several deubgfs nodes fops
2594 static const struct file_operations ab8500_bank_fops
= {
2595 .open
= ab8500_bank_open
,
2596 .write
= ab8500_bank_write
,
2598 .llseek
= seq_lseek
,
2599 .release
= single_release
,
2600 .owner
= THIS_MODULE
,
2603 static const struct file_operations ab8500_address_fops
= {
2604 .open
= ab8500_address_open
,
2605 .write
= ab8500_address_write
,
2607 .llseek
= seq_lseek
,
2608 .release
= single_release
,
2609 .owner
= THIS_MODULE
,
2612 static const struct file_operations ab8500_val_fops
= {
2613 .open
= ab8500_val_open
,
2614 .write
= ab8500_val_write
,
2616 .llseek
= seq_lseek
,
2617 .release
= single_release
,
2618 .owner
= THIS_MODULE
,
2621 static const struct file_operations ab8500_subscribe_fops
= {
2622 .open
= ab8500_subscribe_unsubscribe_open
,
2623 .write
= ab8500_subscribe_write
,
2625 .llseek
= seq_lseek
,
2626 .release
= single_release
,
2627 .owner
= THIS_MODULE
,
2630 static const struct file_operations ab8500_unsubscribe_fops
= {
2631 .open
= ab8500_subscribe_unsubscribe_open
,
2632 .write
= ab8500_unsubscribe_write
,
2634 .llseek
= seq_lseek
,
2635 .release
= single_release
,
2636 .owner
= THIS_MODULE
,
2639 static const struct file_operations ab8500_hwreg_fops
= {
2640 .open
= ab8500_hwreg_open
,
2641 .write
= ab8500_hwreg_write
,
2643 .llseek
= seq_lseek
,
2644 .release
= single_release
,
2645 .owner
= THIS_MODULE
,
2648 static struct dentry
*ab8500_dir
;
2649 static struct dentry
*ab8500_gpadc_dir
;
2651 static int ab8500_debug_probe(struct platform_device
*plf
)
2653 struct dentry
*file
;
2654 struct ab8500
*ab8500
;
2655 struct resource
*res
;
2657 debug_bank
= AB8500_MISC
;
2658 debug_address
= AB8500_REV_REG
& 0x00FF;
2660 ab8500
= dev_get_drvdata(plf
->dev
.parent
);
2661 num_irqs
= ab8500
->mask_size
;
2663 irq_count
= devm_kzalloc(&plf
->dev
,
2664 sizeof(*irq_count
)*num_irqs
, GFP_KERNEL
);
2668 dev_attr
= devm_kzalloc(&plf
->dev
,
2669 sizeof(*dev_attr
)*num_irqs
, GFP_KERNEL
);
2673 event_name
= devm_kzalloc(&plf
->dev
,
2674 sizeof(*event_name
)*num_irqs
, GFP_KERNEL
);
2678 res
= platform_get_resource_byname(plf
, 0, "IRQ_AB8500");
2680 dev_err(&plf
->dev
, "AB8500 irq not found, err %d\n", irq_first
);
2683 irq_ab8500
= res
->start
;
2685 irq_first
= platform_get_irq_byname(plf
, "IRQ_FIRST");
2686 if (irq_first
< 0) {
2687 dev_err(&plf
->dev
, "First irq not found, err %d\n", irq_first
);
2691 irq_last
= platform_get_irq_byname(plf
, "IRQ_LAST");
2693 dev_err(&plf
->dev
, "Last irq not found, err %d\n", irq_last
);
2697 ab8500_dir
= debugfs_create_dir(AB8500_NAME_STRING
, NULL
);
2701 ab8500_gpadc_dir
= debugfs_create_dir(AB8500_ADC_NAME_STRING
,
2703 if (!ab8500_gpadc_dir
)
2706 file
= debugfs_create_file("all-bank-registers", S_IRUGO
, ab8500_dir
,
2707 &plf
->dev
, &ab8500_bank_registers_fops
);
2711 file
= debugfs_create_file("all-banks", S_IRUGO
, ab8500_dir
,
2712 &plf
->dev
, &ab8500_all_banks_fops
);
2716 file
= debugfs_create_file("register-bank",
2717 (S_IRUGO
| S_IWUSR
| S_IWGRP
),
2718 ab8500_dir
, &plf
->dev
, &ab8500_bank_fops
);
2722 file
= debugfs_create_file("register-address",
2723 (S_IRUGO
| S_IWUSR
| S_IWGRP
),
2724 ab8500_dir
, &plf
->dev
, &ab8500_address_fops
);
2728 file
= debugfs_create_file("register-value",
2729 (S_IRUGO
| S_IWUSR
| S_IWGRP
),
2730 ab8500_dir
, &plf
->dev
, &ab8500_val_fops
);
2734 file
= debugfs_create_file("irq-subscribe",
2735 (S_IRUGO
| S_IWUSR
| S_IWGRP
), ab8500_dir
,
2736 &plf
->dev
, &ab8500_subscribe_fops
);
2740 if (is_ab8500(ab8500
)) {
2741 debug_ranges
= ab8500_debug_ranges
;
2742 num_interrupt_lines
= AB8500_NR_IRQS
;
2743 } else if (is_ab8505(ab8500
)) {
2744 debug_ranges
= ab8505_debug_ranges
;
2745 num_interrupt_lines
= AB8505_NR_IRQS
;
2746 } else if (is_ab9540(ab8500
)) {
2747 debug_ranges
= ab8505_debug_ranges
;
2748 num_interrupt_lines
= AB9540_NR_IRQS
;
2749 } else if (is_ab8540(ab8500
)) {
2750 debug_ranges
= ab8540_debug_ranges
;
2751 num_interrupt_lines
= AB8540_NR_IRQS
;
2754 file
= debugfs_create_file("interrupts", (S_IRUGO
), ab8500_dir
,
2755 &plf
->dev
, &ab8500_interrupts_fops
);
2759 file
= debugfs_create_file("irq-unsubscribe",
2760 (S_IRUGO
| S_IWUSR
| S_IWGRP
), ab8500_dir
,
2761 &plf
->dev
, &ab8500_unsubscribe_fops
);
2765 file
= debugfs_create_file("hwreg", (S_IRUGO
| S_IWUSR
| S_IWGRP
),
2766 ab8500_dir
, &plf
->dev
, &ab8500_hwreg_fops
);
2770 file
= debugfs_create_file("all-modem-registers",
2771 (S_IRUGO
| S_IWUSR
| S_IWGRP
),
2772 ab8500_dir
, &plf
->dev
, &ab8500_modem_fops
);
2776 file
= debugfs_create_file("bat_ctrl", (S_IRUGO
| S_IWUSR
| S_IWGRP
),
2777 ab8500_gpadc_dir
, &plf
->dev
,
2778 &ab8500_gpadc_bat_ctrl_fops
);
2782 file
= debugfs_create_file("btemp_ball", (S_IRUGO
| S_IWUSR
| S_IWGRP
),
2784 &plf
->dev
, &ab8500_gpadc_btemp_ball_fops
);
2788 file
= debugfs_create_file("main_charger_v",
2789 (S_IRUGO
| S_IWUSR
| S_IWGRP
),
2790 ab8500_gpadc_dir
, &plf
->dev
,
2791 &ab8500_gpadc_main_charger_v_fops
);
2795 file
= debugfs_create_file("acc_detect1",
2796 (S_IRUGO
| S_IWUSR
| S_IWGRP
),
2797 ab8500_gpadc_dir
, &plf
->dev
,
2798 &ab8500_gpadc_acc_detect1_fops
);
2802 file
= debugfs_create_file("acc_detect2",
2803 (S_IRUGO
| S_IWUSR
| S_IWGRP
),
2804 ab8500_gpadc_dir
, &plf
->dev
,
2805 &ab8500_gpadc_acc_detect2_fops
);
2809 file
= debugfs_create_file("adc_aux1", (S_IRUGO
| S_IWUSR
| S_IWGRP
),
2810 ab8500_gpadc_dir
, &plf
->dev
,
2811 &ab8500_gpadc_aux1_fops
);
2815 file
= debugfs_create_file("adc_aux2", (S_IRUGO
| S_IWUSR
| S_IWGRP
),
2816 ab8500_gpadc_dir
, &plf
->dev
,
2817 &ab8500_gpadc_aux2_fops
);
2821 file
= debugfs_create_file("main_bat_v", (S_IRUGO
| S_IWUSR
| S_IWGRP
),
2822 ab8500_gpadc_dir
, &plf
->dev
,
2823 &ab8500_gpadc_main_bat_v_fops
);
2827 file
= debugfs_create_file("vbus_v", (S_IRUGO
| S_IWUSR
| S_IWGRP
),
2828 ab8500_gpadc_dir
, &plf
->dev
,
2829 &ab8500_gpadc_vbus_v_fops
);
2833 file
= debugfs_create_file("main_charger_c",
2834 (S_IRUGO
| S_IWUSR
| S_IWGRP
),
2835 ab8500_gpadc_dir
, &plf
->dev
,
2836 &ab8500_gpadc_main_charger_c_fops
);
2840 file
= debugfs_create_file("usb_charger_c",
2841 (S_IRUGO
| S_IWUSR
| S_IWGRP
),
2843 &plf
->dev
, &ab8500_gpadc_usb_charger_c_fops
);
2847 file
= debugfs_create_file("bk_bat_v", (S_IRUGO
| S_IWUSR
| S_IWGRP
),
2848 ab8500_gpadc_dir
, &plf
->dev
,
2849 &ab8500_gpadc_bk_bat_v_fops
);
2853 file
= debugfs_create_file("die_temp", (S_IRUGO
| S_IWUSR
| S_IWGRP
),
2854 ab8500_gpadc_dir
, &plf
->dev
,
2855 &ab8500_gpadc_die_temp_fops
);
2859 file
= debugfs_create_file("usb_id", (S_IRUGO
| S_IWUSR
| S_IWGRP
),
2860 ab8500_gpadc_dir
, &plf
->dev
,
2861 &ab8500_gpadc_usb_id_fops
);
2865 if (is_ab8540(ab8500
)) {
2866 file
= debugfs_create_file("xtal_temp",
2867 (S_IRUGO
| S_IWUSR
| S_IWGRP
),
2868 ab8500_gpadc_dir
, &plf
->dev
,
2869 &ab8540_gpadc_xtal_temp_fops
);
2872 file
= debugfs_create_file("vbattruemeas",
2873 (S_IRUGO
| S_IWUSR
| S_IWGRP
),
2874 ab8500_gpadc_dir
, &plf
->dev
,
2875 &ab8540_gpadc_vbat_true_meas_fops
);
2878 file
= debugfs_create_file("batctrl_and_ibat",
2879 (S_IRUGO
| S_IWUGO
),
2882 &ab8540_gpadc_bat_ctrl_and_ibat_fops
);
2885 file
= debugfs_create_file("vbatmeas_and_ibat",
2886 (S_IRUGO
| S_IWUGO
),
2887 ab8500_gpadc_dir
, &plf
->dev
,
2888 &ab8540_gpadc_vbat_meas_and_ibat_fops
);
2891 file
= debugfs_create_file("vbattruemeas_and_ibat",
2892 (S_IRUGO
| S_IWUGO
),
2895 &ab8540_gpadc_vbat_true_meas_and_ibat_fops
);
2898 file
= debugfs_create_file("battemp_and_ibat",
2899 (S_IRUGO
| S_IWUGO
),
2901 &plf
->dev
, &ab8540_gpadc_bat_temp_and_ibat_fops
);
2904 file
= debugfs_create_file("otp_calib",
2905 (S_IRUGO
| S_IWUSR
| S_IWGRP
),
2907 &plf
->dev
, &ab8540_gpadc_otp_calib_fops
);
2911 file
= debugfs_create_file("avg_sample", (S_IRUGO
| S_IWUSR
| S_IWGRP
),
2912 ab8500_gpadc_dir
, &plf
->dev
,
2913 &ab8500_gpadc_avg_sample_fops
);
2917 file
= debugfs_create_file("trig_edge", (S_IRUGO
| S_IWUSR
| S_IWGRP
),
2918 ab8500_gpadc_dir
, &plf
->dev
,
2919 &ab8500_gpadc_trig_edge_fops
);
2923 file
= debugfs_create_file("trig_timer", (S_IRUGO
| S_IWUSR
| S_IWGRP
),
2924 ab8500_gpadc_dir
, &plf
->dev
,
2925 &ab8500_gpadc_trig_timer_fops
);
2929 file
= debugfs_create_file("conv_type", (S_IRUGO
| S_IWUSR
| S_IWGRP
),
2930 ab8500_gpadc_dir
, &plf
->dev
,
2931 &ab8500_gpadc_conv_type_fops
);
2938 debugfs_remove_recursive(ab8500_dir
);
2939 dev_err(&plf
->dev
, "failed to create debugfs entries.\n");
2944 static struct platform_driver ab8500_debug_driver
= {
2946 .name
= "ab8500-debug",
2947 .suppress_bind_attrs
= true,
2949 .probe
= ab8500_debug_probe
,
2952 static int __init
ab8500_debug_init(void)
2954 return platform_driver_register(&ab8500_debug_driver
);
2956 subsys_initcall(ab8500_debug_init
);