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]);
1530 DEFINE_SHOW_ATTRIBUTE(ab8500_interrupts);
1533 * - HWREG DB8500 formated routines
1535 static int ab8500_hwreg_print(struct seq_file *s, void *d)
1537 struct device *dev = s->private;
1541 ret = abx500_get_register_interruptible(dev,
1542 (u8)hwreg_cfg.bank, (u8)hwreg_cfg.addr, ®value);
1544 dev_err(dev, "abx500_get_reg fail %d, %d\n",
1549 if (hwreg_cfg.shift >= 0)
1550 regvalue >>= hwreg_cfg.shift;
1552 regvalue <<= -hwreg_cfg.shift;
1553 regvalue &= hwreg_cfg.mask;
1555 if (REG_FMT_DEC(&hwreg_cfg))
1556 seq_printf(s, "%d\n", regvalue);
1558 seq_printf(s, "0x%02X\n", regvalue);
1562 static int ab8500_hwreg_open(struct inode *inode, struct file *file)
1564 return single_open(file, ab8500_hwreg_print, inode->i_private);
1567 #define AB8500_SUPPLY_CONTROL_CONFIG_1 0x01
1568 #define AB8500_SUPPLY_CONTROL_REG 0x00
1569 #define AB8500_FIRST_SIM_REG 0x80
1570 #define AB8500_LAST_SIM_REG 0x8B
1571 #define AB8505_LAST_SIM_REG 0x8C
1573 static int ab8500_modem_show(struct seq_file *s, void *p)
1575 struct device *dev = s->private;
1576 struct ab8500 *ab8500;
1580 u32 bank = AB8500_REGU_CTRL2;
1581 u32 last_sim_reg = AB8500_LAST_SIM_REG;
1584 ab8500 = dev_get_drvdata(dev->parent);
1585 dev_warn(dev, "WARNING! This operation can interfer with modem side\n"
1586 "and should only be done with care\n");
1588 err = abx500_get_register_interruptible(dev,
1589 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG, &orig_value);
1591 goto report_read_failure;
1593 /* Config 1 will allow APE side to read SIM registers */
1594 err = abx500_set_register_interruptible(dev,
1595 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG,
1596 AB8500_SUPPLY_CONTROL_CONFIG_1);
1598 goto report_write_failure;
1600 seq_printf(s, " bank 0x%02X:\n", bank);
1602 if (is_ab9540(ab8500) || is_ab8505(ab8500))
1603 last_sim_reg = AB8505_LAST_SIM_REG;
1605 for (reg = AB8500_FIRST_SIM_REG; reg <= last_sim_reg; reg++) {
1606 err = abx500_get_register_interruptible(dev,
1609 goto report_read_failure;
1611 seq_printf(s, " [0x%02X/0x%02X]: 0x%02X\n", bank, reg, value);
1613 err = abx500_set_register_interruptible(dev,
1614 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG, orig_value);
1616 goto report_write_failure;
1620 report_read_failure:
1621 dev_err(dev, "ab->read fail %d\n", err);
1624 report_write_failure:
1625 dev_err(dev, "ab->write fail %d\n", err);
1629 DEFINE_SHOW_ATTRIBUTE(ab8500_modem);
1632 * return length of an ASCII numerical value, 0 is string is not a
1634 * string shall start at value 1st char.
1635 * string can be tailed with \0 or space or newline chars only.
1636 * value can be decimal or hexadecimal (prefixed 0x or 0X).
1638 static int strval_len(char *b)
1642 if ((*s == '0') && ((*(s+1) == 'x') || (*(s+1) == 'X'))) {
1644 for (; *s && (*s != ' ') && (*s != '\n'); s++) {
1651 for (; *s && (*s != ' ') && (*s != '\n'); s++) {
1660 * parse hwreg input data.
1661 * update global hwreg_cfg only if input data syntax is ok.
1663 static ssize_t hwreg_common_write(char *b, struct hwreg_cfg *cfg,
1666 uint write, val = 0;
1669 struct hwreg_cfg loc = {
1670 .bank = 0, /* default: invalid phys addr */
1671 .addr = 0, /* default: invalid phys addr */
1672 .fmt = 0, /* default: 32bit access, hex output */
1673 .mask = 0xFFFFFFFF, /* default: no mask */
1674 .shift = 0, /* default: no bit shift */
1677 /* read or write ? */
1678 if (!strncmp(b, "read ", 5)) {
1681 } else if (!strncmp(b, "write ", 6)) {
1687 /* OPTIONS -l|-w|-b -s -m -o */
1688 while ((*b == ' ') || (*b == '-')) {
1689 if (*(b-1) != ' ') {
1693 if ((!strncmp(b, "-d ", 3)) ||
1694 (!strncmp(b, "-dec ", 5))) {
1695 b += (*(b+2) == ' ') ? 3 : 5;
1697 } else if ((!strncmp(b, "-h ", 3)) ||
1698 (!strncmp(b, "-hex ", 5))) {
1699 b += (*(b+2) == ' ') ? 3 : 5;
1701 } else if ((!strncmp(b, "-m ", 3)) ||
1702 (!strncmp(b, "-mask ", 6))) {
1703 b += (*(b+2) == ' ') ? 3 : 6;
1704 if (strval_len(b) == 0)
1706 ret = kstrtoul(b, 0, &loc.mask);
1709 } else if ((!strncmp(b, "-s ", 3)) ||
1710 (!strncmp(b, "-shift ", 7))) {
1711 b += (*(b+2) == ' ') ? 3 : 7;
1712 if (strval_len(b) == 0)
1714 ret = kstrtol(b, 0, &loc.shift);
1721 /* get arg BANK and ADDRESS */
1722 if (strval_len(b) == 0)
1724 ret = kstrtouint(b, 0, &loc.bank);
1729 if (strval_len(b) == 0)
1731 ret = kstrtoul(b, 0, &loc.addr);
1738 if (strval_len(b) == 0)
1740 ret = kstrtouint(b, 0, &val);
1745 /* args are ok, update target cfg (mainly for read) */
1748 #ifdef ABB_HWREG_DEBUG
1749 pr_warn("HWREG request: %s, %s,\n", (write) ? "write" : "read",
1750 REG_FMT_DEC(cfg) ? "decimal" : "hexa");
1751 pr_warn(" addr=0x%08X, mask=0x%X, shift=%d" "value=0x%X\n",
1752 cfg->addr, cfg->mask, cfg->shift, val);
1758 ret = abx500_get_register_interruptible(dev,
1759 (u8)cfg->bank, (u8)cfg->addr, ®value);
1761 dev_err(dev, "abx500_get_reg fail %d, %d\n",
1766 if (cfg->shift >= 0) {
1767 regvalue &= ~(cfg->mask << (cfg->shift));
1768 val = (val & cfg->mask) << (cfg->shift);
1770 regvalue &= ~(cfg->mask >> (-cfg->shift));
1771 val = (val & cfg->mask) >> (-cfg->shift);
1773 val = val | regvalue;
1775 ret = abx500_set_register_interruptible(dev,
1776 (u8)cfg->bank, (u8)cfg->addr, (u8)val);
1778 pr_err("abx500_set_reg failed %d, %d", ret, __LINE__);
1785 static ssize_t ab8500_hwreg_write(struct file *file,
1786 const char __user *user_buf, size_t count, loff_t *ppos)
1788 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1792 /* Get userspace string and assure termination */
1793 buf_size = min((int)count, (int)(sizeof(buf)-1));
1794 if (copy_from_user(buf, user_buf, buf_size))
1798 /* get args and process */
1799 ret = hwreg_common_write(buf, &hwreg_cfg, dev);
1800 return (ret) ? ret : buf_size;
1804 * - irq subscribe/unsubscribe stuff
1806 static int ab8500_subscribe_unsubscribe_print(struct seq_file *s, void *p)
1808 seq_printf(s, "%d\n", irq_first);
1813 static int ab8500_subscribe_unsubscribe_open(struct inode *inode,
1816 return single_open(file, ab8500_subscribe_unsubscribe_print,
1821 * Userspace should use poll() on this file. When an event occur
1822 * the blocking poll will be released.
1824 static ssize_t show_irq(struct device *dev,
1825 struct device_attribute *attr, char *buf)
1828 unsigned int irq_index;
1831 err = kstrtoul(attr->attr.name, 0, &name);
1835 irq_index = name - irq_first;
1836 if (irq_index >= num_irqs)
1839 return sprintf(buf, "%u\n", irq_count[irq_index]);
1842 static ssize_t ab8500_subscribe_write(struct file *file,
1843 const char __user *user_buf,
1844 size_t count, loff_t *ppos)
1846 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1847 unsigned long user_val;
1849 unsigned int irq_index;
1851 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
1855 if (user_val < irq_first) {
1856 dev_err(dev, "debugfs error input < %d\n", irq_first);
1859 if (user_val > irq_last) {
1860 dev_err(dev, "debugfs error input > %d\n", irq_last);
1864 irq_index = user_val - irq_first;
1865 if (irq_index >= num_irqs)
1869 * This will create a sysfs file named <irq-nr> which userspace can
1870 * use to select or poll and get the AB8500 events
1872 dev_attr[irq_index] = kmalloc(sizeof(struct device_attribute),
1874 if (!dev_attr[irq_index])
1877 event_name[irq_index] = kasprintf(GFP_KERNEL, "%lu", user_val);
1878 if (!event_name[irq_index])
1881 dev_attr[irq_index]->show = show_irq;
1882 dev_attr[irq_index]->store = NULL;
1883 dev_attr[irq_index]->attr.name = event_name[irq_index];
1884 dev_attr[irq_index]->attr.mode = S_IRUGO;
1885 err = sysfs_create_file(&dev->kobj, &dev_attr[irq_index]->attr);
1887 pr_info("sysfs_create_file failed %d\n", err);
1891 err = request_threaded_irq(user_val, NULL, ab8500_debug_handler,
1892 IRQF_SHARED | IRQF_NO_SUSPEND | IRQF_ONESHOT,
1893 "ab8500-debug", &dev->kobj);
1895 pr_info("request_threaded_irq failed %d, %lu\n",
1897 sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr);
1904 static ssize_t ab8500_unsubscribe_write(struct file *file,
1905 const char __user *user_buf,
1906 size_t count, loff_t *ppos)
1908 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1909 unsigned long user_val;
1911 unsigned int irq_index;
1913 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
1917 if (user_val < irq_first) {
1918 dev_err(dev, "debugfs error input < %d\n", irq_first);
1921 if (user_val > irq_last) {
1922 dev_err(dev, "debugfs error input > %d\n", irq_last);
1926 irq_index = user_val - irq_first;
1927 if (irq_index >= num_irqs)
1930 /* Set irq count to 0 when unsubscribe */
1931 irq_count[irq_index] = 0;
1933 if (dev_attr[irq_index])
1934 sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr);
1937 free_irq(user_val, &dev->kobj);
1938 kfree(event_name[irq_index]);
1939 kfree(dev_attr[irq_index]);
1945 * - several debugfs nodes fops
1948 static const struct file_operations ab8500_bank_fops = {
1949 .open = ab8500_bank_open,
1950 .write = ab8500_bank_write,
1952 .llseek = seq_lseek,
1953 .release = single_release,
1954 .owner = THIS_MODULE,
1957 static const struct file_operations ab8500_address_fops = {
1958 .open = ab8500_address_open,
1959 .write = ab8500_address_write,
1961 .llseek = seq_lseek,
1962 .release = single_release,
1963 .owner = THIS_MODULE,
1966 static const struct file_operations ab8500_val_fops = {
1967 .open = ab8500_val_open,
1968 .write = ab8500_val_write,
1970 .llseek = seq_lseek,
1971 .release = single_release,
1972 .owner = THIS_MODULE,
1975 static const struct file_operations ab8500_subscribe_fops = {
1976 .open = ab8500_subscribe_unsubscribe_open,
1977 .write = ab8500_subscribe_write,
1979 .llseek = seq_lseek,
1980 .release = single_release,
1981 .owner = THIS_MODULE,
1984 static const struct file_operations ab8500_unsubscribe_fops = {
1985 .open = ab8500_subscribe_unsubscribe_open,
1986 .write = ab8500_unsubscribe_write,
1988 .llseek = seq_lseek,
1989 .release = single_release,
1990 .owner = THIS_MODULE,
1993 static const struct file_operations ab8500_hwreg_fops = {
1994 .open = ab8500_hwreg_open,
1995 .write = ab8500_hwreg_write,
1997 .llseek = seq_lseek,
1998 .release = single_release,
1999 .owner = THIS_MODULE,
2002 static int ab8500_debug_probe(struct platform_device *plf)
2004 struct dentry *ab8500_dir;
2005 struct ab8500 *ab8500;
2006 struct resource *res;
2008 debug_bank = AB8500_MISC;
2009 debug_address = AB8500_REV_REG & 0x00FF;
2011 ab8500 = dev_get_drvdata(plf->dev.parent);
2012 num_irqs = ab8500->mask_size;
2014 irq_count = devm_kcalloc(&plf->dev,
2015 num_irqs, sizeof(*irq_count), GFP_KERNEL);
2019 dev_attr = devm_kcalloc(&plf->dev,
2020 num_irqs, sizeof(*dev_attr), GFP_KERNEL);
2024 event_name = devm_kcalloc(&plf->dev,
2025 num_irqs, sizeof(*event_name), GFP_KERNEL);
2029 res = platform_get_resource_byname(plf, 0, "IRQ_AB8500");
2031 dev_err(&plf->dev, "AB8500 irq not found, err %d\n", irq_first);
2034 irq_ab8500 = res->start;
2036 irq_first = platform_get_irq_byname(plf, "IRQ_FIRST");
2040 irq_last = platform_get_irq_byname(plf, "IRQ_LAST");
2044 ab8500_dir = debugfs_create_dir(AB8500_NAME_STRING, NULL);
2046 debugfs_create_file("all-bank-registers", S_IRUGO, ab8500_dir,
2047 &plf->dev, &ab8500_bank_registers_fops);
2048 debugfs_create_file("all-banks", S_IRUGO, ab8500_dir,
2049 &plf->dev, &ab8500_all_banks_fops);
2050 debugfs_create_file("register-bank", (S_IRUGO | S_IWUSR | S_IWGRP),
2051 ab8500_dir, &plf->dev, &ab8500_bank_fops);
2052 debugfs_create_file("register-address", (S_IRUGO | S_IWUSR | S_IWGRP),
2053 ab8500_dir, &plf->dev, &ab8500_address_fops);
2054 debugfs_create_file("register-value", (S_IRUGO | S_IWUSR | S_IWGRP),
2055 ab8500_dir, &plf->dev, &ab8500_val_fops);
2056 debugfs_create_file("irq-subscribe", (S_IRUGO | S_IWUSR | S_IWGRP),
2057 ab8500_dir, &plf->dev, &ab8500_subscribe_fops);
2059 if (is_ab8500(ab8500)) {
2060 debug_ranges = ab8500_debug_ranges;
2061 num_interrupt_lines = AB8500_NR_IRQS;
2062 } else if (is_ab8505(ab8500)) {
2063 debug_ranges = ab8505_debug_ranges;
2064 num_interrupt_lines = AB8505_NR_IRQS;
2065 } else if (is_ab9540(ab8500)) {
2066 debug_ranges = ab8505_debug_ranges;
2067 num_interrupt_lines = AB9540_NR_IRQS;
2068 } else if (is_ab8540(ab8500)) {
2069 debug_ranges = ab8540_debug_ranges;
2070 num_interrupt_lines = AB8540_NR_IRQS;
2073 debugfs_create_file("interrupts", (S_IRUGO), ab8500_dir, &plf->dev,
2074 &ab8500_interrupts_fops);
2075 debugfs_create_file("irq-unsubscribe", (S_IRUGO | S_IWUSR | S_IWGRP),
2076 ab8500_dir, &plf->dev, &ab8500_unsubscribe_fops);
2077 debugfs_create_file("hwreg", (S_IRUGO | S_IWUSR | S_IWGRP), ab8500_dir,
2078 &plf->dev, &ab8500_hwreg_fops);
2079 debugfs_create_file("all-modem-registers", (S_IRUGO | S_IWUSR | S_IWGRP),
2080 ab8500_dir, &plf->dev, &ab8500_modem_fops);
2085 static struct platform_driver ab8500_debug_driver = {
2087 .name = "ab8500-debug",
2088 .suppress_bind_attrs = true,
2090 .probe = ab8500_debug_probe,
2093 static int __init ab8500_debug_init(void)
2095 return platform_driver_register(&ab8500_debug_driver);
2097 subsys_initcall(ab8500_debug_init);