2 * Copyright (C) ST-Ericsson SA 2010
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 #define DEFINE_SHOW_ATTRIBUTE(__name) \
1262 static int __name ## _open(struct inode *inode, struct file *file) \
1264 return single_open(file, __name ## _show, inode->i_private); \
1267 static const struct file_operations __name ## _fops = { \
1268 .owner = THIS_MODULE, \
1269 .open = __name ## _open, \
1271 .llseek = seq_lseek, \
1272 .release = single_release, \
1275 static irqreturn_t ab8500_debug_handler(int irq, void *data)
1278 struct kobject *kobj = (struct kobject *)data;
1279 unsigned int irq_abb = irq - irq_first;
1281 if (irq_abb < num_irqs)
1282 irq_count[irq_abb]++;
1284 * This makes it possible to use poll for events (POLLPRI | POLLERR)
1285 * from userspace on sysfs file named <irq-nr>
1287 sprintf(buf, "%d", irq);
1288 sysfs_notify(kobj, NULL, buf);
1293 /* Prints to seq_file or log_buf */
1294 static int ab8500_registers_print(struct device *dev, u32 bank,
1299 for (i = 0; i < debug_ranges[bank].num_ranges; i++) {
1302 for (reg = debug_ranges[bank].range[i].first;
1303 reg <= debug_ranges[bank].range[i].last;
1308 err = abx500_get_register_interruptible(dev,
1309 (u8)bank, (u8)reg, &value);
1311 dev_err(dev, "ab->read fail %d\n", err);
1316 seq_printf(s, " [0x%02X/0x%02X]: 0x%02X\n",
1319 * Error is not returned here since
1320 * the output is wanted in any case
1322 if (seq_has_overflowed(s))
1325 dev_info(dev, " [0x%02X/0x%02X]: 0x%02X\n",
1334 static int ab8500_bank_registers_show(struct seq_file *s, void *p)
1336 struct device *dev = s->private;
1337 u32 bank = debug_bank;
1339 seq_puts(s, AB8500_NAME_STRING " register values:\n");
1341 seq_printf(s, " bank 0x%02X:\n", bank);
1343 return ab8500_registers_print(dev, bank, s);
1346 DEFINE_SHOW_ATTRIBUTE(ab8500_bank_registers);
1348 static int ab8500_print_all_banks(struct seq_file *s, void *p)
1350 struct device *dev = s->private;
1353 seq_puts(s, AB8500_NAME_STRING " register values:\n");
1355 for (i = 0; i < AB8500_NUM_BANKS; i++) {
1358 seq_printf(s, " bank 0x%02X:\n", i);
1359 err = ab8500_registers_print(dev, i, s);
1366 /* Dump registers to kernel log */
1367 void ab8500_dump_all_banks(struct device *dev)
1371 dev_info(dev, "ab8500 register values:\n");
1373 for (i = 1; i < AB8500_NUM_BANKS; i++) {
1374 dev_info(dev, " bank 0x%02X:\n", i);
1375 ab8500_registers_print(dev, i, NULL);
1379 static int ab8500_all_banks_open(struct inode *inode, struct file *file)
1384 err = single_open(file, ab8500_print_all_banks, inode->i_private);
1386 /* Default buf size in seq_read is not enough */
1387 s = (struct seq_file *)file->private_data;
1388 s->size = (PAGE_SIZE * 2);
1389 s->buf = kmalloc(s->size, GFP_KERNEL);
1391 single_release(inode, file);
1398 static const struct file_operations ab8500_all_banks_fops = {
1399 .open = ab8500_all_banks_open,
1401 .llseek = seq_lseek,
1402 .release = single_release,
1403 .owner = THIS_MODULE,
1406 static int ab8500_bank_print(struct seq_file *s, void *p)
1408 seq_printf(s, "0x%02X\n", debug_bank);
1412 static int ab8500_bank_open(struct inode *inode, struct file *file)
1414 return single_open(file, ab8500_bank_print, inode->i_private);
1417 static ssize_t ab8500_bank_write(struct file *file,
1418 const char __user *user_buf,
1419 size_t count, loff_t *ppos)
1421 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1422 unsigned long user_bank;
1425 err = kstrtoul_from_user(user_buf, count, 0, &user_bank);
1429 if (user_bank >= AB8500_NUM_BANKS) {
1430 dev_err(dev, "debugfs error input > number of banks\n");
1434 debug_bank = user_bank;
1439 static int ab8500_address_print(struct seq_file *s, void *p)
1441 seq_printf(s, "0x%02X\n", debug_address);
1445 static int ab8500_address_open(struct inode *inode, struct file *file)
1447 return single_open(file, ab8500_address_print, inode->i_private);
1450 static ssize_t ab8500_address_write(struct file *file,
1451 const char __user *user_buf,
1452 size_t count, loff_t *ppos)
1454 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1455 unsigned long user_address;
1458 err = kstrtoul_from_user(user_buf, count, 0, &user_address);
1462 if (user_address > 0xff) {
1463 dev_err(dev, "debugfs error input > 0xff\n");
1466 debug_address = user_address;
1471 static int ab8500_val_print(struct seq_file *s, void *p)
1473 struct device *dev = s->private;
1477 ret = abx500_get_register_interruptible(dev,
1478 (u8)debug_bank, (u8)debug_address, ®value);
1480 dev_err(dev, "abx500_get_reg fail %d, %d\n",
1484 seq_printf(s, "0x%02X\n", regvalue);
1489 static int ab8500_val_open(struct inode *inode, struct file *file)
1491 return single_open(file, ab8500_val_print, inode->i_private);
1494 static ssize_t ab8500_val_write(struct file *file,
1495 const char __user *user_buf,
1496 size_t count, loff_t *ppos)
1498 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1499 unsigned long user_val;
1502 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
1506 if (user_val > 0xff) {
1507 dev_err(dev, "debugfs error input > 0xff\n");
1510 err = abx500_set_register_interruptible(dev,
1511 (u8)debug_bank, debug_address, (u8)user_val);
1513 pr_err("abx500_set_reg failed %d, %d", err, __LINE__);
1523 static u32 num_interrupts[AB8500_MAX_NR_IRQS];
1524 static u32 num_wake_interrupts[AB8500_MAX_NR_IRQS];
1525 static int num_interrupt_lines;
1527 void ab8500_debug_register_interrupt(int line)
1529 if (line < num_interrupt_lines)
1530 num_interrupts[line]++;
1533 static int ab8500_interrupts_show(struct seq_file *s, void *p)
1537 seq_puts(s, "name: number: number of: wake:\n");
1539 for (line = 0; line < num_interrupt_lines; line++) {
1540 struct irq_desc *desc = irq_to_desc(line + irq_first);
1542 seq_printf(s, "%3i: %6i %4i",
1544 num_interrupts[line],
1545 num_wake_interrupts[line]);
1547 if (desc && desc->name)
1548 seq_printf(s, "-%-8s", desc->name);
1549 if (desc && desc->action) {
1550 struct irqaction *action = desc->action;
1552 seq_printf(s, " %s", action->name);
1553 while ((action = action->next) != NULL)
1554 seq_printf(s, ", %s", action->name);
1562 DEFINE_SHOW_ATTRIBUTE(ab8500_interrupts);
1565 * - HWREG DB8500 formated routines
1567 static int ab8500_hwreg_print(struct seq_file *s, void *d)
1569 struct device *dev = s->private;
1573 ret = abx500_get_register_interruptible(dev,
1574 (u8)hwreg_cfg.bank, (u8)hwreg_cfg.addr, ®value);
1576 dev_err(dev, "abx500_get_reg fail %d, %d\n",
1581 if (hwreg_cfg.shift >= 0)
1582 regvalue >>= hwreg_cfg.shift;
1584 regvalue <<= -hwreg_cfg.shift;
1585 regvalue &= hwreg_cfg.mask;
1587 if (REG_FMT_DEC(&hwreg_cfg))
1588 seq_printf(s, "%d\n", regvalue);
1590 seq_printf(s, "0x%02X\n", regvalue);
1594 static int ab8500_hwreg_open(struct inode *inode, struct file *file)
1596 return single_open(file, ab8500_hwreg_print, inode->i_private);
1599 #define AB8500_SUPPLY_CONTROL_CONFIG_1 0x01
1600 #define AB8500_SUPPLY_CONTROL_REG 0x00
1601 #define AB8500_FIRST_SIM_REG 0x80
1602 #define AB8500_LAST_SIM_REG 0x8B
1603 #define AB8505_LAST_SIM_REG 0x8C
1605 static int ab8500_modem_show(struct seq_file *s, void *p)
1607 struct device *dev = s->private;
1608 struct ab8500 *ab8500;
1612 u32 bank = AB8500_REGU_CTRL2;
1613 u32 last_sim_reg = AB8500_LAST_SIM_REG;
1616 ab8500 = dev_get_drvdata(dev->parent);
1617 dev_warn(dev, "WARNING! This operation can interfer with modem side\n"
1618 "and should only be done with care\n");
1620 err = abx500_get_register_interruptible(dev,
1621 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG, &orig_value);
1623 goto report_read_failure;
1625 /* Config 1 will allow APE side to read SIM registers */
1626 err = abx500_set_register_interruptible(dev,
1627 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG,
1628 AB8500_SUPPLY_CONTROL_CONFIG_1);
1630 goto report_write_failure;
1632 seq_printf(s, " bank 0x%02X:\n", bank);
1634 if (is_ab9540(ab8500) || is_ab8505(ab8500))
1635 last_sim_reg = AB8505_LAST_SIM_REG;
1637 for (reg = AB8500_FIRST_SIM_REG; reg <= last_sim_reg; reg++) {
1638 err = abx500_get_register_interruptible(dev,
1641 goto report_read_failure;
1643 seq_printf(s, " [0x%02X/0x%02X]: 0x%02X\n", bank, reg, value);
1645 err = abx500_set_register_interruptible(dev,
1646 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG, orig_value);
1648 goto report_write_failure;
1652 report_read_failure:
1653 dev_err(dev, "ab->read fail %d\n", err);
1656 report_write_failure:
1657 dev_err(dev, "ab->write fail %d\n", err);
1661 DEFINE_SHOW_ATTRIBUTE(ab8500_modem);
1663 static int ab8500_gpadc_bat_ctrl_show(struct seq_file *s, void *p)
1666 int bat_ctrl_convert;
1667 struct ab8500_gpadc *gpadc;
1669 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1670 bat_ctrl_raw = ab8500_gpadc_read_raw(gpadc, BAT_CTRL,
1671 avg_sample, trig_edge, trig_timer, conv_type);
1672 bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc,
1673 BAT_CTRL, bat_ctrl_raw);
1675 seq_printf(s, "%d,0x%X\n", bat_ctrl_convert, bat_ctrl_raw);
1680 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_bat_ctrl);
1682 static int ab8500_gpadc_btemp_ball_show(struct seq_file *s, void *p)
1685 int btemp_ball_convert;
1686 struct ab8500_gpadc *gpadc;
1688 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1689 btemp_ball_raw = ab8500_gpadc_read_raw(gpadc, BTEMP_BALL,
1690 avg_sample, trig_edge, trig_timer, conv_type);
1691 btemp_ball_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL,
1694 seq_printf(s, "%d,0x%X\n", btemp_ball_convert, btemp_ball_raw);
1699 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_btemp_ball);
1701 static int ab8500_gpadc_main_charger_v_show(struct seq_file *s, void *p)
1703 int main_charger_v_raw;
1704 int main_charger_v_convert;
1705 struct ab8500_gpadc *gpadc;
1707 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1708 main_charger_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_V,
1709 avg_sample, trig_edge, trig_timer, conv_type);
1710 main_charger_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
1711 MAIN_CHARGER_V, main_charger_v_raw);
1713 seq_printf(s, "%d,0x%X\n", main_charger_v_convert, main_charger_v_raw);
1718 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_main_charger_v);
1720 static int ab8500_gpadc_acc_detect1_show(struct seq_file *s, void *p)
1722 int acc_detect1_raw;
1723 int acc_detect1_convert;
1724 struct ab8500_gpadc *gpadc;
1726 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1727 acc_detect1_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT1,
1728 avg_sample, trig_edge, trig_timer, conv_type);
1729 acc_detect1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ACC_DETECT1,
1732 seq_printf(s, "%d,0x%X\n", acc_detect1_convert, acc_detect1_raw);
1737 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_acc_detect1);
1739 static int ab8500_gpadc_acc_detect2_show(struct seq_file *s, void *p)
1741 int acc_detect2_raw;
1742 int acc_detect2_convert;
1743 struct ab8500_gpadc *gpadc;
1745 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1746 acc_detect2_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT2,
1747 avg_sample, trig_edge, trig_timer, conv_type);
1748 acc_detect2_convert = ab8500_gpadc_ad_to_voltage(gpadc,
1749 ACC_DETECT2, acc_detect2_raw);
1751 seq_printf(s, "%d,0x%X\n", acc_detect2_convert, acc_detect2_raw);
1756 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_acc_detect2);
1758 static int ab8500_gpadc_aux1_show(struct seq_file *s, void *p)
1762 struct ab8500_gpadc *gpadc;
1764 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1765 aux1_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX1,
1766 avg_sample, trig_edge, trig_timer, conv_type);
1767 aux1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX1,
1770 seq_printf(s, "%d,0x%X\n", aux1_convert, aux1_raw);
1775 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_aux1);
1777 static int ab8500_gpadc_aux2_show(struct seq_file *s, void *p)
1781 struct ab8500_gpadc *gpadc;
1783 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1784 aux2_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX2,
1785 avg_sample, trig_edge, trig_timer, conv_type);
1786 aux2_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX2,
1789 seq_printf(s, "%d,0x%X\n", aux2_convert, aux2_raw);
1794 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_aux2);
1796 static int ab8500_gpadc_main_bat_v_show(struct seq_file *s, void *p)
1799 int main_bat_v_convert;
1800 struct ab8500_gpadc *gpadc;
1802 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1803 main_bat_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_BAT_V,
1804 avg_sample, trig_edge, trig_timer, conv_type);
1805 main_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V,
1808 seq_printf(s, "%d,0x%X\n", main_bat_v_convert, main_bat_v_raw);
1813 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_main_bat_v);
1815 static int ab8500_gpadc_vbus_v_show(struct seq_file *s, void *p)
1819 struct ab8500_gpadc *gpadc;
1821 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1822 vbus_v_raw = ab8500_gpadc_read_raw(gpadc, VBUS_V,
1823 avg_sample, trig_edge, trig_timer, conv_type);
1824 vbus_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, VBUS_V,
1827 seq_printf(s, "%d,0x%X\n", vbus_v_convert, vbus_v_raw);
1832 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_vbus_v);
1834 static int ab8500_gpadc_main_charger_c_show(struct seq_file *s, void *p)
1836 int main_charger_c_raw;
1837 int main_charger_c_convert;
1838 struct ab8500_gpadc *gpadc;
1840 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1841 main_charger_c_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_C,
1842 avg_sample, trig_edge, trig_timer, conv_type);
1843 main_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
1844 MAIN_CHARGER_C, main_charger_c_raw);
1846 seq_printf(s, "%d,0x%X\n", main_charger_c_convert, main_charger_c_raw);
1851 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_main_charger_c);
1853 static int ab8500_gpadc_usb_charger_c_show(struct seq_file *s, void *p)
1855 int usb_charger_c_raw;
1856 int usb_charger_c_convert;
1857 struct ab8500_gpadc *gpadc;
1859 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1860 usb_charger_c_raw = ab8500_gpadc_read_raw(gpadc, USB_CHARGER_C,
1861 avg_sample, trig_edge, trig_timer, conv_type);
1862 usb_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
1863 USB_CHARGER_C, usb_charger_c_raw);
1865 seq_printf(s, "%d,0x%X\n", usb_charger_c_convert, usb_charger_c_raw);
1870 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_usb_charger_c);
1872 static int ab8500_gpadc_bk_bat_v_show(struct seq_file *s, void *p)
1875 int bk_bat_v_convert;
1876 struct ab8500_gpadc *gpadc;
1878 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1879 bk_bat_v_raw = ab8500_gpadc_read_raw(gpadc, BK_BAT_V,
1880 avg_sample, trig_edge, trig_timer, conv_type);
1881 bk_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
1882 BK_BAT_V, bk_bat_v_raw);
1884 seq_printf(s, "%d,0x%X\n", bk_bat_v_convert, bk_bat_v_raw);
1889 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_bk_bat_v);
1891 static int ab8500_gpadc_die_temp_show(struct seq_file *s, void *p)
1894 int die_temp_convert;
1895 struct ab8500_gpadc *gpadc;
1897 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1898 die_temp_raw = ab8500_gpadc_read_raw(gpadc, DIE_TEMP,
1899 avg_sample, trig_edge, trig_timer, conv_type);
1900 die_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, DIE_TEMP,
1903 seq_printf(s, "%d,0x%X\n", die_temp_convert, die_temp_raw);
1908 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_die_temp);
1910 static int ab8500_gpadc_usb_id_show(struct seq_file *s, void *p)
1914 struct ab8500_gpadc *gpadc;
1916 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1917 usb_id_raw = ab8500_gpadc_read_raw(gpadc, USB_ID,
1918 avg_sample, trig_edge, trig_timer, conv_type);
1919 usb_id_convert = ab8500_gpadc_ad_to_voltage(gpadc, USB_ID,
1922 seq_printf(s, "%d,0x%X\n", usb_id_convert, usb_id_raw);
1927 DEFINE_SHOW_ATTRIBUTE(ab8500_gpadc_usb_id);
1929 static int ab8540_gpadc_xtal_temp_show(struct seq_file *s, void *p)
1932 int xtal_temp_convert;
1933 struct ab8500_gpadc *gpadc;
1935 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1936 xtal_temp_raw = ab8500_gpadc_read_raw(gpadc, XTAL_TEMP,
1937 avg_sample, trig_edge, trig_timer, conv_type);
1938 xtal_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, XTAL_TEMP,
1941 seq_printf(s, "%d,0x%X\n", xtal_temp_convert, xtal_temp_raw);
1946 DEFINE_SHOW_ATTRIBUTE(ab8540_gpadc_xtal_temp);
1948 static int ab8540_gpadc_vbat_true_meas_show(struct seq_file *s, void *p)
1950 int vbat_true_meas_raw;
1951 int vbat_true_meas_convert;
1952 struct ab8500_gpadc *gpadc;
1954 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1955 vbat_true_meas_raw = ab8500_gpadc_read_raw(gpadc, VBAT_TRUE_MEAS,
1956 avg_sample, trig_edge, trig_timer, conv_type);
1957 vbat_true_meas_convert =
1958 ab8500_gpadc_ad_to_voltage(gpadc, VBAT_TRUE_MEAS,
1959 vbat_true_meas_raw);
1961 seq_printf(s, "%d,0x%X\n", vbat_true_meas_convert, vbat_true_meas_raw);
1966 DEFINE_SHOW_ATTRIBUTE(ab8540_gpadc_vbat_true_meas);
1968 static int ab8540_gpadc_bat_ctrl_and_ibat_show(struct seq_file *s, void *p)
1971 int bat_ctrl_convert;
1974 struct ab8500_gpadc *gpadc;
1976 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1977 bat_ctrl_raw = ab8500_gpadc_double_read_raw(gpadc, BAT_CTRL_AND_IBAT,
1978 avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
1980 bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc, BAT_CTRL,
1982 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
1988 bat_ctrl_convert, bat_ctrl_raw,
1989 ibat_convert, ibat_raw);
1994 DEFINE_SHOW_ATTRIBUTE(ab8540_gpadc_bat_ctrl_and_ibat);
1996 static int ab8540_gpadc_vbat_meas_and_ibat_show(struct seq_file *s, void *p)
1999 int vbat_meas_convert;
2002 struct ab8500_gpadc *gpadc;
2004 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2005 vbat_meas_raw = ab8500_gpadc_double_read_raw(gpadc, VBAT_MEAS_AND_IBAT,
2006 avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
2007 vbat_meas_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V,
2009 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2015 vbat_meas_convert, vbat_meas_raw,
2016 ibat_convert, ibat_raw);
2021 DEFINE_SHOW_ATTRIBUTE(ab8540_gpadc_vbat_meas_and_ibat);
2023 static int ab8540_gpadc_vbat_true_meas_and_ibat_show(struct seq_file *s, void *p)
2025 int vbat_true_meas_raw;
2026 int vbat_true_meas_convert;
2029 struct ab8500_gpadc *gpadc;
2031 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2032 vbat_true_meas_raw = ab8500_gpadc_double_read_raw(gpadc,
2033 VBAT_TRUE_MEAS_AND_IBAT, avg_sample, trig_edge,
2034 trig_timer, conv_type, &ibat_raw);
2035 vbat_true_meas_convert = ab8500_gpadc_ad_to_voltage(gpadc,
2036 VBAT_TRUE_MEAS, vbat_true_meas_raw);
2037 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2043 vbat_true_meas_convert, vbat_true_meas_raw,
2044 ibat_convert, ibat_raw);
2049 DEFINE_SHOW_ATTRIBUTE(ab8540_gpadc_vbat_true_meas_and_ibat);
2051 static int ab8540_gpadc_bat_temp_and_ibat_show(struct seq_file *s, void *p)
2054 int bat_temp_convert;
2057 struct ab8500_gpadc *gpadc;
2059 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2060 bat_temp_raw = ab8500_gpadc_double_read_raw(gpadc, BAT_TEMP_AND_IBAT,
2061 avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
2062 bat_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL,
2064 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2070 bat_temp_convert, bat_temp_raw,
2071 ibat_convert, ibat_raw);
2076 DEFINE_SHOW_ATTRIBUTE(ab8540_gpadc_bat_temp_and_ibat);
2078 static int ab8540_gpadc_otp_calib_show(struct seq_file *s, void *p)
2080 struct ab8500_gpadc *gpadc;
2081 u16 vmain_l, vmain_h, btemp_l, btemp_h;
2082 u16 vbat_l, vbat_h, ibat_l, ibat_h;
2084 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2085 ab8540_gpadc_get_otp(gpadc, &vmain_l, &vmain_h, &btemp_l, &btemp_h,
2086 &vbat_l, &vbat_h, &ibat_l, &ibat_h);
2096 vmain_l, vmain_h, btemp_l, btemp_h,
2097 vbat_l, vbat_h, ibat_l, ibat_h);
2102 DEFINE_SHOW_ATTRIBUTE(ab8540_gpadc_otp_calib);
2104 static int ab8500_gpadc_avg_sample_print(struct seq_file *s, void *p)
2106 seq_printf(s, "%d\n", avg_sample);
2111 static int ab8500_gpadc_avg_sample_open(struct inode *inode, struct file *file)
2113 return single_open(file, ab8500_gpadc_avg_sample_print,
2117 static ssize_t ab8500_gpadc_avg_sample_write(struct file *file,
2118 const char __user *user_buf,
2119 size_t count, loff_t *ppos)
2121 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2122 unsigned long user_avg_sample;
2125 err = kstrtoul_from_user(user_buf, count, 0, &user_avg_sample);
2129 if ((user_avg_sample == SAMPLE_1) || (user_avg_sample == SAMPLE_4)
2130 || (user_avg_sample == SAMPLE_8)
2131 || (user_avg_sample == SAMPLE_16)) {
2132 avg_sample = (u8) user_avg_sample;
2135 "debugfs err input: should be egal to 1, 4, 8 or 16\n");
2142 static const struct file_operations ab8500_gpadc_avg_sample_fops = {
2143 .open = ab8500_gpadc_avg_sample_open,
2145 .write = ab8500_gpadc_avg_sample_write,
2146 .llseek = seq_lseek,
2147 .release = single_release,
2148 .owner = THIS_MODULE,
2151 static int ab8500_gpadc_trig_edge_print(struct seq_file *s, void *p)
2153 seq_printf(s, "%d\n", trig_edge);
2158 static int ab8500_gpadc_trig_edge_open(struct inode *inode, struct file *file)
2160 return single_open(file, ab8500_gpadc_trig_edge_print,
2164 static ssize_t ab8500_gpadc_trig_edge_write(struct file *file,
2165 const char __user *user_buf,
2166 size_t count, loff_t *ppos)
2168 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2169 unsigned long user_trig_edge;
2172 err = kstrtoul_from_user(user_buf, count, 0, &user_trig_edge);
2176 if ((user_trig_edge == RISING_EDGE)
2177 || (user_trig_edge == FALLING_EDGE)) {
2178 trig_edge = (u8) user_trig_edge;
2180 dev_err(dev, "Wrong input:\n"
2181 "Enter 0. Rising edge\n"
2182 "Enter 1. Falling edge\n");
2189 static const struct file_operations ab8500_gpadc_trig_edge_fops = {
2190 .open = ab8500_gpadc_trig_edge_open,
2192 .write = ab8500_gpadc_trig_edge_write,
2193 .llseek = seq_lseek,
2194 .release = single_release,
2195 .owner = THIS_MODULE,
2198 static int ab8500_gpadc_trig_timer_print(struct seq_file *s, void *p)
2200 seq_printf(s, "%d\n", trig_timer);
2205 static int ab8500_gpadc_trig_timer_open(struct inode *inode, struct file *file)
2207 return single_open(file, ab8500_gpadc_trig_timer_print,
2211 static ssize_t ab8500_gpadc_trig_timer_write(struct file *file,
2212 const char __user *user_buf,
2213 size_t count, loff_t *ppos)
2215 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2216 unsigned long user_trig_timer;
2219 err = kstrtoul_from_user(user_buf, count, 0, &user_trig_timer);
2223 if (user_trig_timer & ~0xFF) {
2225 "debugfs error input: should be between 0 to 255\n");
2229 trig_timer = (u8) user_trig_timer;
2234 static const struct file_operations ab8500_gpadc_trig_timer_fops = {
2235 .open = ab8500_gpadc_trig_timer_open,
2237 .write = ab8500_gpadc_trig_timer_write,
2238 .llseek = seq_lseek,
2239 .release = single_release,
2240 .owner = THIS_MODULE,
2243 static int ab8500_gpadc_conv_type_print(struct seq_file *s, void *p)
2245 seq_printf(s, "%d\n", conv_type);
2250 static int ab8500_gpadc_conv_type_open(struct inode *inode, struct file *file)
2252 return single_open(file, ab8500_gpadc_conv_type_print,
2256 static ssize_t ab8500_gpadc_conv_type_write(struct file *file,
2257 const char __user *user_buf,
2258 size_t count, loff_t *ppos)
2260 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2261 unsigned long user_conv_type;
2264 err = kstrtoul_from_user(user_buf, count, 0, &user_conv_type);
2268 if ((user_conv_type == ADC_SW)
2269 || (user_conv_type == ADC_HW)) {
2270 conv_type = (u8) user_conv_type;
2272 dev_err(dev, "Wrong input:\n"
2273 "Enter 0. ADC SW conversion\n"
2274 "Enter 1. ADC HW conversion\n");
2281 static const struct file_operations ab8500_gpadc_conv_type_fops = {
2282 .open = ab8500_gpadc_conv_type_open,
2284 .write = ab8500_gpadc_conv_type_write,
2285 .llseek = seq_lseek,
2286 .release = single_release,
2287 .owner = THIS_MODULE,
2291 * return length of an ASCII numerical value, 0 is string is not a
2293 * string shall start at value 1st char.
2294 * string can be tailed with \0 or space or newline chars only.
2295 * value can be decimal or hexadecimal (prefixed 0x or 0X).
2297 static int strval_len(char *b)
2301 if ((*s == '0') && ((*(s+1) == 'x') || (*(s+1) == 'X'))) {
2303 for (; *s && (*s != ' ') && (*s != '\n'); s++) {
2310 for (; *s && (*s != ' ') && (*s != '\n'); s++) {
2319 * parse hwreg input data.
2320 * update global hwreg_cfg only if input data syntax is ok.
2322 static ssize_t hwreg_common_write(char *b, struct hwreg_cfg *cfg,
2325 uint write, val = 0;
2328 struct hwreg_cfg loc = {
2329 .bank = 0, /* default: invalid phys addr */
2330 .addr = 0, /* default: invalid phys addr */
2331 .fmt = 0, /* default: 32bit access, hex output */
2332 .mask = 0xFFFFFFFF, /* default: no mask */
2333 .shift = 0, /* default: no bit shift */
2336 /* read or write ? */
2337 if (!strncmp(b, "read ", 5)) {
2340 } else if (!strncmp(b, "write ", 6)) {
2346 /* OPTIONS -l|-w|-b -s -m -o */
2347 while ((*b == ' ') || (*b == '-')) {
2348 if (*(b-1) != ' ') {
2352 if ((!strncmp(b, "-d ", 3)) ||
2353 (!strncmp(b, "-dec ", 5))) {
2354 b += (*(b+2) == ' ') ? 3 : 5;
2356 } else if ((!strncmp(b, "-h ", 3)) ||
2357 (!strncmp(b, "-hex ", 5))) {
2358 b += (*(b+2) == ' ') ? 3 : 5;
2360 } else if ((!strncmp(b, "-m ", 3)) ||
2361 (!strncmp(b, "-mask ", 6))) {
2362 b += (*(b+2) == ' ') ? 3 : 6;
2363 if (strval_len(b) == 0)
2365 ret = kstrtoul(b, 0, &loc.mask);
2368 } else if ((!strncmp(b, "-s ", 3)) ||
2369 (!strncmp(b, "-shift ", 7))) {
2370 b += (*(b+2) == ' ') ? 3 : 7;
2371 if (strval_len(b) == 0)
2373 ret = kstrtol(b, 0, &loc.shift);
2380 /* get arg BANK and ADDRESS */
2381 if (strval_len(b) == 0)
2383 ret = kstrtouint(b, 0, &loc.bank);
2388 if (strval_len(b) == 0)
2390 ret = kstrtoul(b, 0, &loc.addr);
2397 if (strval_len(b) == 0)
2399 ret = kstrtouint(b, 0, &val);
2404 /* args are ok, update target cfg (mainly for read) */
2407 #ifdef ABB_HWREG_DEBUG
2408 pr_warn("HWREG request: %s, %s,\n", (write) ? "write" : "read",
2409 REG_FMT_DEC(cfg) ? "decimal" : "hexa");
2410 pr_warn(" addr=0x%08X, mask=0x%X, shift=%d" "value=0x%X\n",
2411 cfg->addr, cfg->mask, cfg->shift, val);
2417 ret = abx500_get_register_interruptible(dev,
2418 (u8)cfg->bank, (u8)cfg->addr, ®value);
2420 dev_err(dev, "abx500_get_reg fail %d, %d\n",
2425 if (cfg->shift >= 0) {
2426 regvalue &= ~(cfg->mask << (cfg->shift));
2427 val = (val & cfg->mask) << (cfg->shift);
2429 regvalue &= ~(cfg->mask >> (-cfg->shift));
2430 val = (val & cfg->mask) >> (-cfg->shift);
2432 val = val | regvalue;
2434 ret = abx500_set_register_interruptible(dev,
2435 (u8)cfg->bank, (u8)cfg->addr, (u8)val);
2437 pr_err("abx500_set_reg failed %d, %d", ret, __LINE__);
2444 static ssize_t ab8500_hwreg_write(struct file *file,
2445 const char __user *user_buf, size_t count, loff_t *ppos)
2447 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2451 /* Get userspace string and assure termination */
2452 buf_size = min(count, (sizeof(buf)-1));
2453 if (copy_from_user(buf, user_buf, buf_size))
2457 /* get args and process */
2458 ret = hwreg_common_write(buf, &hwreg_cfg, dev);
2459 return (ret) ? ret : buf_size;
2463 * - irq subscribe/unsubscribe stuff
2465 static int ab8500_subscribe_unsubscribe_print(struct seq_file *s, void *p)
2467 seq_printf(s, "%d\n", irq_first);
2472 static int ab8500_subscribe_unsubscribe_open(struct inode *inode,
2475 return single_open(file, ab8500_subscribe_unsubscribe_print,
2480 * Userspace should use poll() on this file. When an event occur
2481 * the blocking poll will be released.
2483 static ssize_t show_irq(struct device *dev,
2484 struct device_attribute *attr, char *buf)
2487 unsigned int irq_index;
2490 err = kstrtoul(attr->attr.name, 0, &name);
2494 irq_index = name - irq_first;
2495 if (irq_index >= num_irqs)
2498 return sprintf(buf, "%u\n", irq_count[irq_index]);
2501 static ssize_t ab8500_subscribe_write(struct file *file,
2502 const char __user *user_buf,
2503 size_t count, loff_t *ppos)
2505 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2506 unsigned long user_val;
2508 unsigned int irq_index;
2510 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
2514 if (user_val < irq_first) {
2515 dev_err(dev, "debugfs error input < %d\n", irq_first);
2518 if (user_val > irq_last) {
2519 dev_err(dev, "debugfs error input > %d\n", irq_last);
2523 irq_index = user_val - irq_first;
2524 if (irq_index >= num_irqs)
2528 * This will create a sysfs file named <irq-nr> which userspace can
2529 * use to select or poll and get the AB8500 events
2531 dev_attr[irq_index] = kmalloc(sizeof(struct device_attribute),
2533 if (!dev_attr[irq_index])
2536 event_name[irq_index] = kmalloc(count, GFP_KERNEL);
2537 if (!event_name[irq_index])
2540 sprintf(event_name[irq_index], "%lu", user_val);
2541 dev_attr[irq_index]->show = show_irq;
2542 dev_attr[irq_index]->store = NULL;
2543 dev_attr[irq_index]->attr.name = event_name[irq_index];
2544 dev_attr[irq_index]->attr.mode = S_IRUGO;
2545 err = sysfs_create_file(&dev->kobj, &dev_attr[irq_index]->attr);
2547 pr_info("sysfs_create_file failed %d\n", err);
2551 err = request_threaded_irq(user_val, NULL, ab8500_debug_handler,
2552 IRQF_SHARED | IRQF_NO_SUSPEND | IRQF_ONESHOT,
2553 "ab8500-debug", &dev->kobj);
2555 pr_info("request_threaded_irq failed %d, %lu\n",
2557 sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr);
2564 static ssize_t ab8500_unsubscribe_write(struct file *file,
2565 const char __user *user_buf,
2566 size_t count, loff_t *ppos)
2568 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2569 unsigned long user_val;
2571 unsigned int irq_index;
2573 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
2577 if (user_val < irq_first) {
2578 dev_err(dev, "debugfs error input < %d\n", irq_first);
2581 if (user_val > irq_last) {
2582 dev_err(dev, "debugfs error input > %d\n", irq_last);
2586 irq_index = user_val - irq_first;
2587 if (irq_index >= num_irqs)
2590 /* Set irq count to 0 when unsubscribe */
2591 irq_count[irq_index] = 0;
2593 if (dev_attr[irq_index])
2594 sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr);
2597 free_irq(user_val, &dev->kobj);
2598 kfree(event_name[irq_index]);
2599 kfree(dev_attr[irq_index]);
2605 * - several deubgfs nodes fops
2608 static const struct file_operations ab8500_bank_fops = {
2609 .open = ab8500_bank_open,
2610 .write = ab8500_bank_write,
2612 .llseek = seq_lseek,
2613 .release = single_release,
2614 .owner = THIS_MODULE,
2617 static const struct file_operations ab8500_address_fops = {
2618 .open = ab8500_address_open,
2619 .write = ab8500_address_write,
2621 .llseek = seq_lseek,
2622 .release = single_release,
2623 .owner = THIS_MODULE,
2626 static const struct file_operations ab8500_val_fops = {
2627 .open = ab8500_val_open,
2628 .write = ab8500_val_write,
2630 .llseek = seq_lseek,
2631 .release = single_release,
2632 .owner = THIS_MODULE,
2635 static const struct file_operations ab8500_subscribe_fops = {
2636 .open = ab8500_subscribe_unsubscribe_open,
2637 .write = ab8500_subscribe_write,
2639 .llseek = seq_lseek,
2640 .release = single_release,
2641 .owner = THIS_MODULE,
2644 static const struct file_operations ab8500_unsubscribe_fops = {
2645 .open = ab8500_subscribe_unsubscribe_open,
2646 .write = ab8500_unsubscribe_write,
2648 .llseek = seq_lseek,
2649 .release = single_release,
2650 .owner = THIS_MODULE,
2653 static const struct file_operations ab8500_hwreg_fops = {
2654 .open = ab8500_hwreg_open,
2655 .write = ab8500_hwreg_write,
2657 .llseek = seq_lseek,
2658 .release = single_release,
2659 .owner = THIS_MODULE,
2662 static struct dentry *ab8500_dir;
2663 static struct dentry *ab8500_gpadc_dir;
2665 static int ab8500_debug_probe(struct platform_device *plf)
2667 struct dentry *file;
2668 struct ab8500 *ab8500;
2669 struct resource *res;
2671 debug_bank = AB8500_MISC;
2672 debug_address = AB8500_REV_REG & 0x00FF;
2674 ab8500 = dev_get_drvdata(plf->dev.parent);
2675 num_irqs = ab8500->mask_size;
2677 irq_count = devm_kzalloc(&plf->dev,
2678 sizeof(*irq_count)*num_irqs, GFP_KERNEL);
2682 dev_attr = devm_kzalloc(&plf->dev,
2683 sizeof(*dev_attr)*num_irqs, GFP_KERNEL);
2687 event_name = devm_kzalloc(&plf->dev,
2688 sizeof(*event_name)*num_irqs, GFP_KERNEL);
2692 res = platform_get_resource_byname(plf, 0, "IRQ_AB8500");
2694 dev_err(&plf->dev, "AB8500 irq not found, err %d\n", irq_first);
2697 irq_ab8500 = res->start;
2699 irq_first = platform_get_irq_byname(plf, "IRQ_FIRST");
2700 if (irq_first < 0) {
2701 dev_err(&plf->dev, "First irq not found, err %d\n", irq_first);
2705 irq_last = platform_get_irq_byname(plf, "IRQ_LAST");
2707 dev_err(&plf->dev, "Last irq not found, err %d\n", irq_last);
2711 ab8500_dir = debugfs_create_dir(AB8500_NAME_STRING, NULL);
2715 ab8500_gpadc_dir = debugfs_create_dir(AB8500_ADC_NAME_STRING,
2717 if (!ab8500_gpadc_dir)
2720 file = debugfs_create_file("all-bank-registers", S_IRUGO, ab8500_dir,
2721 &plf->dev, &ab8500_bank_registers_fops);
2725 file = debugfs_create_file("all-banks", S_IRUGO, ab8500_dir,
2726 &plf->dev, &ab8500_all_banks_fops);
2730 file = debugfs_create_file("register-bank",
2731 (S_IRUGO | S_IWUSR | S_IWGRP),
2732 ab8500_dir, &plf->dev, &ab8500_bank_fops);
2736 file = debugfs_create_file("register-address",
2737 (S_IRUGO | S_IWUSR | S_IWGRP),
2738 ab8500_dir, &plf->dev, &ab8500_address_fops);
2742 file = debugfs_create_file("register-value",
2743 (S_IRUGO | S_IWUSR | S_IWGRP),
2744 ab8500_dir, &plf->dev, &ab8500_val_fops);
2748 file = debugfs_create_file("irq-subscribe",
2749 (S_IRUGO | S_IWUSR | S_IWGRP), ab8500_dir,
2750 &plf->dev, &ab8500_subscribe_fops);
2754 if (is_ab8500(ab8500)) {
2755 debug_ranges = ab8500_debug_ranges;
2756 num_interrupt_lines = AB8500_NR_IRQS;
2757 } else if (is_ab8505(ab8500)) {
2758 debug_ranges = ab8505_debug_ranges;
2759 num_interrupt_lines = AB8505_NR_IRQS;
2760 } else if (is_ab9540(ab8500)) {
2761 debug_ranges = ab8505_debug_ranges;
2762 num_interrupt_lines = AB9540_NR_IRQS;
2763 } else if (is_ab8540(ab8500)) {
2764 debug_ranges = ab8540_debug_ranges;
2765 num_interrupt_lines = AB8540_NR_IRQS;
2768 file = debugfs_create_file("interrupts", (S_IRUGO), ab8500_dir,
2769 &plf->dev, &ab8500_interrupts_fops);
2773 file = debugfs_create_file("irq-unsubscribe",
2774 (S_IRUGO | S_IWUSR | S_IWGRP), ab8500_dir,
2775 &plf->dev, &ab8500_unsubscribe_fops);
2779 file = debugfs_create_file("hwreg", (S_IRUGO | S_IWUSR | S_IWGRP),
2780 ab8500_dir, &plf->dev, &ab8500_hwreg_fops);
2784 file = debugfs_create_file("all-modem-registers",
2785 (S_IRUGO | S_IWUSR | S_IWGRP),
2786 ab8500_dir, &plf->dev, &ab8500_modem_fops);
2790 file = debugfs_create_file("bat_ctrl", (S_IRUGO | S_IWUSR | S_IWGRP),
2791 ab8500_gpadc_dir, &plf->dev,
2792 &ab8500_gpadc_bat_ctrl_fops);
2796 file = debugfs_create_file("btemp_ball", (S_IRUGO | S_IWUSR | S_IWGRP),
2798 &plf->dev, &ab8500_gpadc_btemp_ball_fops);
2802 file = debugfs_create_file("main_charger_v",
2803 (S_IRUGO | S_IWUSR | S_IWGRP),
2804 ab8500_gpadc_dir, &plf->dev,
2805 &ab8500_gpadc_main_charger_v_fops);
2809 file = debugfs_create_file("acc_detect1",
2810 (S_IRUGO | S_IWUSR | S_IWGRP),
2811 ab8500_gpadc_dir, &plf->dev,
2812 &ab8500_gpadc_acc_detect1_fops);
2816 file = debugfs_create_file("acc_detect2",
2817 (S_IRUGO | S_IWUSR | S_IWGRP),
2818 ab8500_gpadc_dir, &plf->dev,
2819 &ab8500_gpadc_acc_detect2_fops);
2823 file = debugfs_create_file("adc_aux1", (S_IRUGO | S_IWUSR | S_IWGRP),
2824 ab8500_gpadc_dir, &plf->dev,
2825 &ab8500_gpadc_aux1_fops);
2829 file = debugfs_create_file("adc_aux2", (S_IRUGO | S_IWUSR | S_IWGRP),
2830 ab8500_gpadc_dir, &plf->dev,
2831 &ab8500_gpadc_aux2_fops);
2835 file = debugfs_create_file("main_bat_v", (S_IRUGO | S_IWUSR | S_IWGRP),
2836 ab8500_gpadc_dir, &plf->dev,
2837 &ab8500_gpadc_main_bat_v_fops);
2841 file = debugfs_create_file("vbus_v", (S_IRUGO | S_IWUSR | S_IWGRP),
2842 ab8500_gpadc_dir, &plf->dev,
2843 &ab8500_gpadc_vbus_v_fops);
2847 file = debugfs_create_file("main_charger_c",
2848 (S_IRUGO | S_IWUSR | S_IWGRP),
2849 ab8500_gpadc_dir, &plf->dev,
2850 &ab8500_gpadc_main_charger_c_fops);
2854 file = debugfs_create_file("usb_charger_c",
2855 (S_IRUGO | S_IWUSR | S_IWGRP),
2857 &plf->dev, &ab8500_gpadc_usb_charger_c_fops);
2861 file = debugfs_create_file("bk_bat_v", (S_IRUGO | S_IWUSR | S_IWGRP),
2862 ab8500_gpadc_dir, &plf->dev,
2863 &ab8500_gpadc_bk_bat_v_fops);
2867 file = debugfs_create_file("die_temp", (S_IRUGO | S_IWUSR | S_IWGRP),
2868 ab8500_gpadc_dir, &plf->dev,
2869 &ab8500_gpadc_die_temp_fops);
2873 file = debugfs_create_file("usb_id", (S_IRUGO | S_IWUSR | S_IWGRP),
2874 ab8500_gpadc_dir, &plf->dev,
2875 &ab8500_gpadc_usb_id_fops);
2879 if (is_ab8540(ab8500)) {
2880 file = debugfs_create_file("xtal_temp",
2881 (S_IRUGO | S_IWUSR | S_IWGRP),
2882 ab8500_gpadc_dir, &plf->dev,
2883 &ab8540_gpadc_xtal_temp_fops);
2886 file = debugfs_create_file("vbattruemeas",
2887 (S_IRUGO | S_IWUSR | S_IWGRP),
2888 ab8500_gpadc_dir, &plf->dev,
2889 &ab8540_gpadc_vbat_true_meas_fops);
2892 file = debugfs_create_file("batctrl_and_ibat",
2893 (S_IRUGO | S_IWUGO),
2896 &ab8540_gpadc_bat_ctrl_and_ibat_fops);
2899 file = debugfs_create_file("vbatmeas_and_ibat",
2900 (S_IRUGO | S_IWUGO),
2901 ab8500_gpadc_dir, &plf->dev,
2902 &ab8540_gpadc_vbat_meas_and_ibat_fops);
2905 file = debugfs_create_file("vbattruemeas_and_ibat",
2906 (S_IRUGO | S_IWUGO),
2909 &ab8540_gpadc_vbat_true_meas_and_ibat_fops);
2912 file = debugfs_create_file("battemp_and_ibat",
2913 (S_IRUGO | S_IWUGO),
2915 &plf->dev, &ab8540_gpadc_bat_temp_and_ibat_fops);
2918 file = debugfs_create_file("otp_calib",
2919 (S_IRUGO | S_IWUSR | S_IWGRP),
2921 &plf->dev, &ab8540_gpadc_otp_calib_fops);
2925 file = debugfs_create_file("avg_sample", (S_IRUGO | S_IWUSR | S_IWGRP),
2926 ab8500_gpadc_dir, &plf->dev,
2927 &ab8500_gpadc_avg_sample_fops);
2931 file = debugfs_create_file("trig_edge", (S_IRUGO | S_IWUSR | S_IWGRP),
2932 ab8500_gpadc_dir, &plf->dev,
2933 &ab8500_gpadc_trig_edge_fops);
2937 file = debugfs_create_file("trig_timer", (S_IRUGO | S_IWUSR | S_IWGRP),
2938 ab8500_gpadc_dir, &plf->dev,
2939 &ab8500_gpadc_trig_timer_fops);
2943 file = debugfs_create_file("conv_type", (S_IRUGO | S_IWUSR | S_IWGRP),
2944 ab8500_gpadc_dir, &plf->dev,
2945 &ab8500_gpadc_conv_type_fops);
2952 debugfs_remove_recursive(ab8500_dir);
2953 dev_err(&plf->dev, "failed to create debugfs entries.\n");
2958 static struct platform_driver ab8500_debug_driver = {
2960 .name = "ab8500-debug",
2961 .suppress_bind_attrs = true,
2963 .probe = ab8500_debug_probe,
2966 static int __init ab8500_debug_init(void)
2968 return platform_driver_register(&ab8500_debug_driver);
2970 subsys_initcall(ab8500_debug_init);