1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) ST-Ericsson SA 2010
5 * Author: Mattias Wallin <mattias.wallin@stericsson.com> for ST-Ericsson.
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>
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
;
96 static int irq_ab8500
;
99 static u32
*irq_count
;
102 static struct device_attribute
**dev_attr
;
103 static char **event_name
;
106 * struct ab8500_reg_range
107 * @first: the first address of the range
108 * @last: the last address of the range
109 * @perm: access permissions for the range
111 struct ab8500_reg_range
{
118 * struct ab8500_prcmu_ranges
119 * @num_ranges: the number of ranges in the list
120 * @bankid: bank identifier
121 * @range: the list of register ranges
123 struct ab8500_prcmu_ranges
{
126 const struct ab8500_reg_range
*range
;
129 /* hwreg- "mask" and "shift" entries ressources */
131 u32 bank
; /* target bank */
132 unsigned long addr
; /* target address */
133 uint fmt
; /* format */
134 unsigned long mask
; /* read/write mask, applied before any bit shift */
135 long shift
; /* bit shift (read:right shift, write:left shift */
137 /* fmt bit #0: 0=hexa, 1=dec */
138 #define REG_FMT_DEC(c) ((c)->fmt & 0x1)
139 #define REG_FMT_HEX(c) (!REG_FMT_DEC(c))
141 static struct hwreg_cfg hwreg_cfg
= {
142 .addr
= 0, /* default: invalid phys addr */
143 .fmt
= 0, /* default: 32bit access, hex output */
144 .mask
= 0xFFFFFFFF, /* default: no mask */
145 .shift
= 0, /* default: no bit shift */
148 #define AB8500_NAME_STRING "ab8500"
149 #define AB8500_NUM_BANKS AB8500_DEBUG_FIELD_LAST
151 #define AB8500_REV_REG 0x80
153 static struct ab8500_prcmu_ranges
*debug_ranges
;
155 static struct ab8500_prcmu_ranges ab8500_debug_ranges
[AB8500_NUM_BANKS
] = {
156 [AB8500_M_FSM_RANK
] = {
160 [AB8500_SYS_CTRL1_BLOCK
] = {
162 .range
= (struct ab8500_reg_range
[]) {
177 [AB8500_SYS_CTRL2_BLOCK
] = {
179 .range
= (struct ab8500_reg_range
[]) {
198 [AB8500_REGU_CTRL1
] = {
200 .range
= (struct ab8500_reg_range
[]) {
215 [AB8500_REGU_CTRL2
] = {
217 .range
= (struct ab8500_reg_range
[]) {
239 * 0x80-0x8B are SIM registers and should
240 * not be accessed from here
246 .range
= (struct ab8500_reg_range
[]) {
259 .range
= (struct ab8500_reg_range
[]) {
302 [AB8500_ECI_AV_ACC
] = {
304 .range
= (struct ab8500_reg_range
[]) {
311 [AB8500_RESERVED
] = {
317 .range
= (struct ab8500_reg_range
[]) {
326 .range
= (struct ab8500_reg_range
[]) {
365 [AB8500_GAS_GAUGE
] = {
367 .range
= (struct ab8500_reg_range
[]) {
384 .range
= (struct ab8500_reg_range
[]) {
391 [AB8500_INTERRUPT
] = {
397 .range
= (struct ab8500_reg_range
[]) {
406 .range
= (struct ab8500_reg_range
[]) {
441 [AB8500_DEVELOPMENT
] = {
443 .range
= (struct ab8500_reg_range
[]) {
452 .range
= (struct ab8500_reg_range
[]) {
459 [AB8500_PROD_TEST
] = {
463 [AB8500_STE_TEST
] = {
467 [AB8500_OTP_EMUL
] = {
469 .range
= (struct ab8500_reg_range
[]) {
478 static struct ab8500_prcmu_ranges ab8505_debug_ranges
[AB8500_NUM_BANKS
] = {
483 [AB8500_SYS_CTRL1_BLOCK
] = {
485 .range
= (struct ab8500_reg_range
[]) {
508 [AB8500_SYS_CTRL2_BLOCK
] = {
510 .range
= (struct ab8500_reg_range
[]) {
533 [AB8500_REGU_CTRL1
] = {
535 .range
= (struct ab8500_reg_range
[]) {
550 [AB8500_REGU_CTRL2
] = {
552 .range
= (struct ab8500_reg_range
[]) {
578 * 0x80-0x8B are SIM registers and should
579 * not be accessed from here
585 .range
= (struct ab8500_reg_range
[]) {
608 [AB8500_ECI_AV_ACC
] = {
610 .range
= (struct ab8500_reg_range
[]) {
617 [AB8500_RESERVED
] = {
623 .range
= (struct ab8500_reg_range
[]) {
632 .range
= (struct ab8500_reg_range
[]) {
671 [AB8500_GAS_GAUGE
] = {
673 .range
= (struct ab8500_reg_range
[]) {
690 .range
= (struct ab8500_reg_range
[]) {
697 [AB8500_INTERRUPT
] = {
699 .range
= (struct ab8500_reg_range
[]) {
724 /* Latch registers should not be read here */
745 /* LatchHier registers should not be read here */
750 .range
= (struct ab8500_reg_range
[]) {
763 .range
= (struct ab8500_reg_range
[]) {
798 [AB8500_DEVELOPMENT
] = {
800 .range
= (struct ab8500_reg_range
[]) {
813 .range
= (struct ab8500_reg_range
[]) {
820 [AB8500_PROD_TEST
] = {
824 [AB8500_STE_TEST
] = {
828 [AB8500_OTP_EMUL
] = {
830 .range
= (struct ab8500_reg_range
[]) {
839 static struct ab8500_prcmu_ranges ab8540_debug_ranges
[AB8500_NUM_BANKS
] = {
840 [AB8500_M_FSM_RANK
] = {
842 .range
= (struct ab8500_reg_range
[]) {
849 [AB8500_SYS_CTRL1_BLOCK
] = {
851 .range
= (struct ab8500_reg_range
[]) {
878 [AB8500_SYS_CTRL2_BLOCK
] = {
880 .range
= (struct ab8500_reg_range
[]) {
903 [AB8500_REGU_CTRL1
] = {
905 .range
= (struct ab8500_reg_range
[]) {
924 [AB8500_REGU_CTRL2
] = {
926 .range
= (struct ab8500_reg_range
[]) {
963 .range
= (struct ab8500_reg_range
[]) {
984 .range
= (struct ab8500_reg_range
[]) {
1003 [AB8500_ECI_AV_ACC
] = {
1005 .range
= (struct ab8500_reg_range
[]) {
1016 [AB8500_RESERVED
] = {
1022 .range
= (struct ab8500_reg_range
[]) {
1041 [AB8500_CHARGER
] = {
1043 .range
= (struct ab8500_reg_range
[]) {
1086 [AB8500_GAS_GAUGE
] = {
1088 .range
= (struct ab8500_reg_range
[]) {
1105 .range
= (struct ab8500_reg_range
[]) {
1112 [AB8500_INTERRUPT
] = {
1114 .range
= (struct ab8500_reg_range
[]) {
1127 /* Latch registers should not be read here */
1140 /* LatchHier registers should not be read here */
1145 .range
= (struct ab8500_reg_range
[]) {
1162 .range
= (struct ab8500_reg_range
[]) {
1201 [AB8500_DEVELOPMENT
] = {
1203 .range
= (struct ab8500_reg_range
[]) {
1220 .range
= (struct ab8500_reg_range
[]) {
1235 [AB8500_PROD_TEST
] = {
1239 [AB8500_STE_TEST
] = {
1243 [AB8500_OTP_EMUL
] = {
1245 .range
= (struct ab8500_reg_range
[]) {
1254 static irqreturn_t
ab8500_debug_handler(int irq
, void *data
)
1257 struct kobject
*kobj
= (struct kobject
*)data
;
1258 unsigned int irq_abb
= irq
- irq_first
;
1260 if (irq_abb
< num_irqs
)
1261 irq_count
[irq_abb
]++;
1263 * This makes it possible to use poll for events (EPOLLPRI | EPOLLERR)
1264 * from userspace on sysfs file named <irq-nr>
1266 sprintf(buf
, "%d", irq
);
1267 sysfs_notify(kobj
, NULL
, buf
);
1272 /* Prints to seq_file or log_buf */
1273 static int ab8500_registers_print(struct device
*dev
, u32 bank
,
1278 for (i
= 0; i
< debug_ranges
[bank
].num_ranges
; i
++) {
1281 for (reg
= debug_ranges
[bank
].range
[i
].first
;
1282 reg
<= debug_ranges
[bank
].range
[i
].last
;
1287 err
= abx500_get_register_interruptible(dev
,
1288 (u8
)bank
, (u8
)reg
, &value
);
1290 dev_err(dev
, "ab->read fail %d\n", err
);
1295 seq_printf(s
, " [0x%02X/0x%02X]: 0x%02X\n",
1298 * Error is not returned here since
1299 * the output is wanted in any case
1301 if (seq_has_overflowed(s
))
1304 dev_info(dev
, " [0x%02X/0x%02X]: 0x%02X\n",
1313 static int ab8500_bank_registers_show(struct seq_file
*s
, void *p
)
1315 struct device
*dev
= s
->private;
1316 u32 bank
= debug_bank
;
1318 seq_puts(s
, AB8500_NAME_STRING
" register values:\n");
1320 seq_printf(s
, " bank 0x%02X:\n", bank
);
1322 return ab8500_registers_print(dev
, bank
, s
);
1325 DEFINE_SHOW_ATTRIBUTE(ab8500_bank_registers
);
1327 static int ab8500_print_all_banks(struct seq_file
*s
, void *p
)
1329 struct device
*dev
= s
->private;
1332 seq_puts(s
, AB8500_NAME_STRING
" register values:\n");
1334 for (i
= 0; i
< AB8500_NUM_BANKS
; i
++) {
1337 seq_printf(s
, " bank 0x%02X:\n", i
);
1338 err
= ab8500_registers_print(dev
, i
, s
);
1345 /* Dump registers to kernel log */
1346 void ab8500_dump_all_banks(struct device
*dev
)
1350 dev_info(dev
, "ab8500 register values:\n");
1352 for (i
= 1; i
< AB8500_NUM_BANKS
; i
++) {
1353 dev_info(dev
, " bank 0x%02X:\n", i
);
1354 ab8500_registers_print(dev
, i
, NULL
);
1358 static int ab8500_all_banks_open(struct inode
*inode
, struct file
*file
)
1363 err
= single_open(file
, ab8500_print_all_banks
, inode
->i_private
);
1365 /* Default buf size in seq_read is not enough */
1366 s
= (struct seq_file
*)file
->private_data
;
1367 s
->size
= (PAGE_SIZE
* 2);
1368 s
->buf
= kmalloc(s
->size
, GFP_KERNEL
);
1370 single_release(inode
, file
);
1377 static const struct file_operations ab8500_all_banks_fops
= {
1378 .open
= ab8500_all_banks_open
,
1380 .llseek
= seq_lseek
,
1381 .release
= single_release
,
1382 .owner
= THIS_MODULE
,
1385 static int ab8500_bank_print(struct seq_file
*s
, void *p
)
1387 seq_printf(s
, "0x%02X\n", debug_bank
);
1391 static int ab8500_bank_open(struct inode
*inode
, struct file
*file
)
1393 return single_open(file
, ab8500_bank_print
, inode
->i_private
);
1396 static ssize_t
ab8500_bank_write(struct file
*file
,
1397 const char __user
*user_buf
,
1398 size_t count
, loff_t
*ppos
)
1400 struct device
*dev
= ((struct seq_file
*)(file
->private_data
))->private;
1401 unsigned long user_bank
;
1404 err
= kstrtoul_from_user(user_buf
, count
, 0, &user_bank
);
1408 if (user_bank
>= AB8500_NUM_BANKS
) {
1409 dev_err(dev
, "debugfs error input > number of banks\n");
1413 debug_bank
= user_bank
;
1418 static int ab8500_address_print(struct seq_file
*s
, void *p
)
1420 seq_printf(s
, "0x%02X\n", debug_address
);
1424 static int ab8500_address_open(struct inode
*inode
, struct file
*file
)
1426 return single_open(file
, ab8500_address_print
, inode
->i_private
);
1429 static ssize_t
ab8500_address_write(struct file
*file
,
1430 const char __user
*user_buf
,
1431 size_t count
, loff_t
*ppos
)
1433 struct device
*dev
= ((struct seq_file
*)(file
->private_data
))->private;
1434 unsigned long user_address
;
1437 err
= kstrtoul_from_user(user_buf
, count
, 0, &user_address
);
1441 if (user_address
> 0xff) {
1442 dev_err(dev
, "debugfs error input > 0xff\n");
1445 debug_address
= user_address
;
1450 static int ab8500_val_print(struct seq_file
*s
, void *p
)
1452 struct device
*dev
= s
->private;
1456 ret
= abx500_get_register_interruptible(dev
,
1457 (u8
)debug_bank
, (u8
)debug_address
, ®value
);
1459 dev_err(dev
, "abx500_get_reg fail %d, %d\n",
1463 seq_printf(s
, "0x%02X\n", regvalue
);
1468 static int ab8500_val_open(struct inode
*inode
, struct file
*file
)
1470 return single_open(file
, ab8500_val_print
, inode
->i_private
);
1473 static ssize_t
ab8500_val_write(struct file
*file
,
1474 const char __user
*user_buf
,
1475 size_t count
, loff_t
*ppos
)
1477 struct device
*dev
= ((struct seq_file
*)(file
->private_data
))->private;
1478 unsigned long user_val
;
1481 err
= kstrtoul_from_user(user_buf
, count
, 0, &user_val
);
1485 if (user_val
> 0xff) {
1486 dev_err(dev
, "debugfs error input > 0xff\n");
1489 err
= abx500_set_register_interruptible(dev
,
1490 (u8
)debug_bank
, debug_address
, (u8
)user_val
);
1492 pr_err("abx500_set_reg failed %d, %d", err
, __LINE__
);
1502 static u32 num_interrupts
[AB8500_MAX_NR_IRQS
];
1503 static u32 num_wake_interrupts
[AB8500_MAX_NR_IRQS
];
1504 static int num_interrupt_lines
;
1506 void ab8500_debug_register_interrupt(int line
)
1508 if (line
< num_interrupt_lines
)
1509 num_interrupts
[line
]++;
1512 static int ab8500_interrupts_show(struct seq_file
*s
, void *p
)
1516 seq_puts(s
, "name: number: irq: number of: wake:\n");
1518 for (line
= 0; line
< num_interrupt_lines
; line
++) {
1519 seq_printf(s
, "%3i: %4i %6i %4i\n",
1522 num_interrupts
[line
],
1523 num_wake_interrupts
[line
]);
1529 DEFINE_SHOW_ATTRIBUTE(ab8500_interrupts
);
1532 * - HWREG DB8500 formated routines
1534 static int ab8500_hwreg_print(struct seq_file
*s
, void *d
)
1536 struct device
*dev
= s
->private;
1540 ret
= abx500_get_register_interruptible(dev
,
1541 (u8
)hwreg_cfg
.bank
, (u8
)hwreg_cfg
.addr
, ®value
);
1543 dev_err(dev
, "abx500_get_reg fail %d, %d\n",
1548 if (hwreg_cfg
.shift
>= 0)
1549 regvalue
>>= hwreg_cfg
.shift
;
1551 regvalue
<<= -hwreg_cfg
.shift
;
1552 regvalue
&= hwreg_cfg
.mask
;
1554 if (REG_FMT_DEC(&hwreg_cfg
))
1555 seq_printf(s
, "%d\n", regvalue
);
1557 seq_printf(s
, "0x%02X\n", regvalue
);
1561 static int ab8500_hwreg_open(struct inode
*inode
, struct file
*file
)
1563 return single_open(file
, ab8500_hwreg_print
, inode
->i_private
);
1566 #define AB8500_SUPPLY_CONTROL_CONFIG_1 0x01
1567 #define AB8500_SUPPLY_CONTROL_REG 0x00
1568 #define AB8500_FIRST_SIM_REG 0x80
1569 #define AB8500_LAST_SIM_REG 0x8B
1570 #define AB8505_LAST_SIM_REG 0x8C
1572 static int ab8500_modem_show(struct seq_file
*s
, void *p
)
1574 struct device
*dev
= s
->private;
1575 struct ab8500
*ab8500
;
1579 u32 bank
= AB8500_REGU_CTRL2
;
1580 u32 last_sim_reg
= AB8500_LAST_SIM_REG
;
1583 ab8500
= dev_get_drvdata(dev
->parent
);
1584 dev_warn(dev
, "WARNING! This operation can interfer with modem side\n"
1585 "and should only be done with care\n");
1587 err
= abx500_get_register_interruptible(dev
,
1588 AB8500_REGU_CTRL1
, AB8500_SUPPLY_CONTROL_REG
, &orig_value
);
1590 goto report_read_failure
;
1592 /* Config 1 will allow APE side to read SIM registers */
1593 err
= abx500_set_register_interruptible(dev
,
1594 AB8500_REGU_CTRL1
, AB8500_SUPPLY_CONTROL_REG
,
1595 AB8500_SUPPLY_CONTROL_CONFIG_1
);
1597 goto report_write_failure
;
1599 seq_printf(s
, " bank 0x%02X:\n", bank
);
1601 if (is_ab9540(ab8500
) || is_ab8505(ab8500
))
1602 last_sim_reg
= AB8505_LAST_SIM_REG
;
1604 for (reg
= AB8500_FIRST_SIM_REG
; reg
<= last_sim_reg
; reg
++) {
1605 err
= abx500_get_register_interruptible(dev
,
1608 goto report_read_failure
;
1610 seq_printf(s
, " [0x%02X/0x%02X]: 0x%02X\n", bank
, reg
, value
);
1612 err
= abx500_set_register_interruptible(dev
,
1613 AB8500_REGU_CTRL1
, AB8500_SUPPLY_CONTROL_REG
, orig_value
);
1615 goto report_write_failure
;
1619 report_read_failure
:
1620 dev_err(dev
, "ab->read fail %d\n", err
);
1623 report_write_failure
:
1624 dev_err(dev
, "ab->write fail %d\n", err
);
1628 DEFINE_SHOW_ATTRIBUTE(ab8500_modem
);
1631 * return length of an ASCII numerical value, 0 is string is not a
1633 * string shall start at value 1st char.
1634 * string can be tailed with \0 or space or newline chars only.
1635 * value can be decimal or hexadecimal (prefixed 0x or 0X).
1637 static int strval_len(char *b
)
1641 if ((*s
== '0') && ((*(s
+1) == 'x') || (*(s
+1) == 'X'))) {
1643 for (; *s
&& (*s
!= ' ') && (*s
!= '\n'); s
++) {
1650 for (; *s
&& (*s
!= ' ') && (*s
!= '\n'); s
++) {
1659 * parse hwreg input data.
1660 * update global hwreg_cfg only if input data syntax is ok.
1662 static ssize_t
hwreg_common_write(char *b
, struct hwreg_cfg
*cfg
,
1665 uint write
, val
= 0;
1668 struct hwreg_cfg loc
= {
1669 .bank
= 0, /* default: invalid phys addr */
1670 .addr
= 0, /* default: invalid phys addr */
1671 .fmt
= 0, /* default: 32bit access, hex output */
1672 .mask
= 0xFFFFFFFF, /* default: no mask */
1673 .shift
= 0, /* default: no bit shift */
1676 /* read or write ? */
1677 if (!strncmp(b
, "read ", 5)) {
1680 } else if (!strncmp(b
, "write ", 6)) {
1686 /* OPTIONS -l|-w|-b -s -m -o */
1687 while ((*b
== ' ') || (*b
== '-')) {
1688 if (*(b
-1) != ' ') {
1692 if ((!strncmp(b
, "-d ", 3)) ||
1693 (!strncmp(b
, "-dec ", 5))) {
1694 b
+= (*(b
+2) == ' ') ? 3 : 5;
1696 } else if ((!strncmp(b
, "-h ", 3)) ||
1697 (!strncmp(b
, "-hex ", 5))) {
1698 b
+= (*(b
+2) == ' ') ? 3 : 5;
1700 } else if ((!strncmp(b
, "-m ", 3)) ||
1701 (!strncmp(b
, "-mask ", 6))) {
1702 b
+= (*(b
+2) == ' ') ? 3 : 6;
1703 if (strval_len(b
) == 0)
1705 ret
= kstrtoul(b
, 0, &loc
.mask
);
1708 } else if ((!strncmp(b
, "-s ", 3)) ||
1709 (!strncmp(b
, "-shift ", 7))) {
1710 b
+= (*(b
+2) == ' ') ? 3 : 7;
1711 if (strval_len(b
) == 0)
1713 ret
= kstrtol(b
, 0, &loc
.shift
);
1720 /* get arg BANK and ADDRESS */
1721 if (strval_len(b
) == 0)
1723 ret
= kstrtouint(b
, 0, &loc
.bank
);
1728 if (strval_len(b
) == 0)
1730 ret
= kstrtoul(b
, 0, &loc
.addr
);
1737 if (strval_len(b
) == 0)
1739 ret
= kstrtouint(b
, 0, &val
);
1744 /* args are ok, update target cfg (mainly for read) */
1747 #ifdef ABB_HWREG_DEBUG
1748 pr_warn("HWREG request: %s, %s,\n", (write
) ? "write" : "read",
1749 REG_FMT_DEC(cfg
) ? "decimal" : "hexa");
1750 pr_warn(" addr=0x%08X, mask=0x%X, shift=%d" "value=0x%X\n",
1751 cfg
->addr
, cfg
->mask
, cfg
->shift
, val
);
1757 ret
= abx500_get_register_interruptible(dev
,
1758 (u8
)cfg
->bank
, (u8
)cfg
->addr
, ®value
);
1760 dev_err(dev
, "abx500_get_reg fail %d, %d\n",
1765 if (cfg
->shift
>= 0) {
1766 regvalue
&= ~(cfg
->mask
<< (cfg
->shift
));
1767 val
= (val
& cfg
->mask
) << (cfg
->shift
);
1769 regvalue
&= ~(cfg
->mask
>> (-cfg
->shift
));
1770 val
= (val
& cfg
->mask
) >> (-cfg
->shift
);
1772 val
= val
| regvalue
;
1774 ret
= abx500_set_register_interruptible(dev
,
1775 (u8
)cfg
->bank
, (u8
)cfg
->addr
, (u8
)val
);
1777 pr_err("abx500_set_reg failed %d, %d", ret
, __LINE__
);
1784 static ssize_t
ab8500_hwreg_write(struct file
*file
,
1785 const char __user
*user_buf
, size_t count
, loff_t
*ppos
)
1787 struct device
*dev
= ((struct seq_file
*)(file
->private_data
))->private;
1791 /* Get userspace string and assure termination */
1792 buf_size
= min((int)count
, (int)(sizeof(buf
)-1));
1793 if (copy_from_user(buf
, user_buf
, buf_size
))
1797 /* get args and process */
1798 ret
= hwreg_common_write(buf
, &hwreg_cfg
, dev
);
1799 return (ret
) ? ret
: buf_size
;
1803 * - irq subscribe/unsubscribe stuff
1805 static int ab8500_subscribe_unsubscribe_print(struct seq_file
*s
, void *p
)
1807 seq_printf(s
, "%d\n", irq_first
);
1812 static int ab8500_subscribe_unsubscribe_open(struct inode
*inode
,
1815 return single_open(file
, ab8500_subscribe_unsubscribe_print
,
1820 * Userspace should use poll() on this file. When an event occur
1821 * the blocking poll will be released.
1823 static ssize_t
show_irq(struct device
*dev
,
1824 struct device_attribute
*attr
, char *buf
)
1827 unsigned int irq_index
;
1830 err
= kstrtoul(attr
->attr
.name
, 0, &name
);
1834 irq_index
= name
- irq_first
;
1835 if (irq_index
>= num_irqs
)
1838 return sprintf(buf
, "%u\n", irq_count
[irq_index
]);
1841 static ssize_t
ab8500_subscribe_write(struct file
*file
,
1842 const char __user
*user_buf
,
1843 size_t count
, loff_t
*ppos
)
1845 struct device
*dev
= ((struct seq_file
*)(file
->private_data
))->private;
1846 unsigned long user_val
;
1848 unsigned int irq_index
;
1850 err
= kstrtoul_from_user(user_buf
, count
, 0, &user_val
);
1854 if (user_val
< irq_first
) {
1855 dev_err(dev
, "debugfs error input < %d\n", irq_first
);
1858 if (user_val
> irq_last
) {
1859 dev_err(dev
, "debugfs error input > %d\n", irq_last
);
1863 irq_index
= user_val
- irq_first
;
1864 if (irq_index
>= num_irqs
)
1868 * This will create a sysfs file named <irq-nr> which userspace can
1869 * use to select or poll and get the AB8500 events
1871 dev_attr
[irq_index
] = kmalloc(sizeof(struct device_attribute
),
1873 if (!dev_attr
[irq_index
])
1876 event_name
[irq_index
] = kasprintf(GFP_KERNEL
, "%lu", user_val
);
1877 if (!event_name
[irq_index
])
1880 dev_attr
[irq_index
]->show
= show_irq
;
1881 dev_attr
[irq_index
]->store
= NULL
;
1882 dev_attr
[irq_index
]->attr
.name
= event_name
[irq_index
];
1883 dev_attr
[irq_index
]->attr
.mode
= S_IRUGO
;
1884 err
= sysfs_create_file(&dev
->kobj
, &dev_attr
[irq_index
]->attr
);
1886 pr_info("sysfs_create_file failed %d\n", err
);
1890 err
= request_threaded_irq(user_val
, NULL
, ab8500_debug_handler
,
1891 IRQF_SHARED
| IRQF_NO_SUSPEND
| IRQF_ONESHOT
,
1892 "ab8500-debug", &dev
->kobj
);
1894 pr_info("request_threaded_irq failed %d, %lu\n",
1896 sysfs_remove_file(&dev
->kobj
, &dev_attr
[irq_index
]->attr
);
1903 static ssize_t
ab8500_unsubscribe_write(struct file
*file
,
1904 const char __user
*user_buf
,
1905 size_t count
, loff_t
*ppos
)
1907 struct device
*dev
= ((struct seq_file
*)(file
->private_data
))->private;
1908 unsigned long user_val
;
1910 unsigned int irq_index
;
1912 err
= kstrtoul_from_user(user_buf
, count
, 0, &user_val
);
1916 if (user_val
< irq_first
) {
1917 dev_err(dev
, "debugfs error input < %d\n", irq_first
);
1920 if (user_val
> irq_last
) {
1921 dev_err(dev
, "debugfs error input > %d\n", irq_last
);
1925 irq_index
= user_val
- irq_first
;
1926 if (irq_index
>= num_irqs
)
1929 /* Set irq count to 0 when unsubscribe */
1930 irq_count
[irq_index
] = 0;
1932 if (dev_attr
[irq_index
])
1933 sysfs_remove_file(&dev
->kobj
, &dev_attr
[irq_index
]->attr
);
1936 free_irq(user_val
, &dev
->kobj
);
1937 kfree(event_name
[irq_index
]);
1938 kfree(dev_attr
[irq_index
]);
1944 * - several debugfs nodes fops
1947 static const struct file_operations ab8500_bank_fops
= {
1948 .open
= ab8500_bank_open
,
1949 .write
= ab8500_bank_write
,
1951 .llseek
= seq_lseek
,
1952 .release
= single_release
,
1953 .owner
= THIS_MODULE
,
1956 static const struct file_operations ab8500_address_fops
= {
1957 .open
= ab8500_address_open
,
1958 .write
= ab8500_address_write
,
1960 .llseek
= seq_lseek
,
1961 .release
= single_release
,
1962 .owner
= THIS_MODULE
,
1965 static const struct file_operations ab8500_val_fops
= {
1966 .open
= ab8500_val_open
,
1967 .write
= ab8500_val_write
,
1969 .llseek
= seq_lseek
,
1970 .release
= single_release
,
1971 .owner
= THIS_MODULE
,
1974 static const struct file_operations ab8500_subscribe_fops
= {
1975 .open
= ab8500_subscribe_unsubscribe_open
,
1976 .write
= ab8500_subscribe_write
,
1978 .llseek
= seq_lseek
,
1979 .release
= single_release
,
1980 .owner
= THIS_MODULE
,
1983 static const struct file_operations ab8500_unsubscribe_fops
= {
1984 .open
= ab8500_subscribe_unsubscribe_open
,
1985 .write
= ab8500_unsubscribe_write
,
1987 .llseek
= seq_lseek
,
1988 .release
= single_release
,
1989 .owner
= THIS_MODULE
,
1992 static const struct file_operations ab8500_hwreg_fops
= {
1993 .open
= ab8500_hwreg_open
,
1994 .write
= ab8500_hwreg_write
,
1996 .llseek
= seq_lseek
,
1997 .release
= single_release
,
1998 .owner
= THIS_MODULE
,
2001 static int ab8500_debug_probe(struct platform_device
*plf
)
2003 struct dentry
*ab8500_dir
;
2004 struct ab8500
*ab8500
;
2005 struct resource
*res
;
2007 debug_bank
= AB8500_MISC
;
2008 debug_address
= AB8500_REV_REG
& 0x00FF;
2010 ab8500
= dev_get_drvdata(plf
->dev
.parent
);
2011 num_irqs
= ab8500
->mask_size
;
2013 irq_count
= devm_kcalloc(&plf
->dev
,
2014 num_irqs
, sizeof(*irq_count
), GFP_KERNEL
);
2018 dev_attr
= devm_kcalloc(&plf
->dev
,
2019 num_irqs
, sizeof(*dev_attr
), GFP_KERNEL
);
2023 event_name
= devm_kcalloc(&plf
->dev
,
2024 num_irqs
, sizeof(*event_name
), GFP_KERNEL
);
2028 res
= platform_get_resource_byname(plf
, 0, "IRQ_AB8500");
2030 dev_err(&plf
->dev
, "AB8500 irq not found, err %d\n", irq_first
);
2033 irq_ab8500
= res
->start
;
2035 irq_first
= platform_get_irq_byname(plf
, "IRQ_FIRST");
2039 irq_last
= platform_get_irq_byname(plf
, "IRQ_LAST");
2043 ab8500_dir
= debugfs_create_dir(AB8500_NAME_STRING
, NULL
);
2045 debugfs_create_file("all-bank-registers", S_IRUGO
, ab8500_dir
,
2046 &plf
->dev
, &ab8500_bank_registers_fops
);
2047 debugfs_create_file("all-banks", S_IRUGO
, ab8500_dir
,
2048 &plf
->dev
, &ab8500_all_banks_fops
);
2049 debugfs_create_file("register-bank", (S_IRUGO
| S_IWUSR
| S_IWGRP
),
2050 ab8500_dir
, &plf
->dev
, &ab8500_bank_fops
);
2051 debugfs_create_file("register-address", (S_IRUGO
| S_IWUSR
| S_IWGRP
),
2052 ab8500_dir
, &plf
->dev
, &ab8500_address_fops
);
2053 debugfs_create_file("register-value", (S_IRUGO
| S_IWUSR
| S_IWGRP
),
2054 ab8500_dir
, &plf
->dev
, &ab8500_val_fops
);
2055 debugfs_create_file("irq-subscribe", (S_IRUGO
| S_IWUSR
| S_IWGRP
),
2056 ab8500_dir
, &plf
->dev
, &ab8500_subscribe_fops
);
2058 if (is_ab8500(ab8500
)) {
2059 debug_ranges
= ab8500_debug_ranges
;
2060 num_interrupt_lines
= AB8500_NR_IRQS
;
2061 } else if (is_ab8505(ab8500
)) {
2062 debug_ranges
= ab8505_debug_ranges
;
2063 num_interrupt_lines
= AB8505_NR_IRQS
;
2064 } else if (is_ab9540(ab8500
)) {
2065 debug_ranges
= ab8505_debug_ranges
;
2066 num_interrupt_lines
= AB9540_NR_IRQS
;
2067 } else if (is_ab8540(ab8500
)) {
2068 debug_ranges
= ab8540_debug_ranges
;
2069 num_interrupt_lines
= AB8540_NR_IRQS
;
2072 debugfs_create_file("interrupts", (S_IRUGO
), ab8500_dir
, &plf
->dev
,
2073 &ab8500_interrupts_fops
);
2074 debugfs_create_file("irq-unsubscribe", (S_IRUGO
| S_IWUSR
| S_IWGRP
),
2075 ab8500_dir
, &plf
->dev
, &ab8500_unsubscribe_fops
);
2076 debugfs_create_file("hwreg", (S_IRUGO
| S_IWUSR
| S_IWGRP
), ab8500_dir
,
2077 &plf
->dev
, &ab8500_hwreg_fops
);
2078 debugfs_create_file("all-modem-registers", (S_IRUGO
| S_IWUSR
| S_IWGRP
),
2079 ab8500_dir
, &plf
->dev
, &ab8500_modem_fops
);
2084 static struct platform_driver ab8500_debug_driver
= {
2086 .name
= "ab8500-debug",
2087 .suppress_bind_attrs
= true,
2089 .probe
= ab8500_debug_probe
,
2092 static int __init
ab8500_debug_init(void)
2094 return platform_driver_register(&ab8500_debug_driver
);
2096 subsys_initcall(ab8500_debug_init
);