2 * Copyright (C) ST-Ericsson SA 2010
4 * Author: Mattias Wallin <mattias.wallin@stericsson.com> for ST-Ericsson.
5 * License Terms: GNU General Public License v2
8 * AB8500 register access
9 * ======================
12 * # echo BANK > <debugfs>/ab8500/register-bank
13 * # echo ADDR > <debugfs>/ab8500/register-address
14 * # cat <debugfs>/ab8500/register-value
17 * # echo BANK > <debugfs>/ab8500/register-bank
18 * # echo ADDR > <debugfs>/ab8500/register-address
19 * # echo VALUE > <debugfs>/ab8500/register-value
21 * read all registers from a bank:
22 * # echo BANK > <debugfs>/ab8500/register-bank
23 * # cat <debugfs>/ab8500/all-bank-register
25 * BANK target AB8500 register bank
26 * ADDR target AB8500 register address
27 * VALUE decimal or 0x-prefixed hexadecimal
30 * User Space notification on AB8500 IRQ
31 * =====================================
33 * Allows user space entity to be notified when target AB8500 IRQ occurs.
34 * When subscribed, a sysfs entry is created in ab8500.i2c platform device.
35 * One can pool this file to get target IRQ occurence information.
37 * subscribe to an AB8500 IRQ:
38 * # echo IRQ > <debugfs>/ab8500/irq-subscribe
40 * unsubscribe from an AB8500 IRQ:
41 * # echo IRQ > <debugfs>/ab8500/irq-unsubscribe
44 * AB8500 register formated read/write access
45 * ==========================================
47 * Read: read data, data>>SHIFT, data&=MASK, output data
48 * [0xABCDEF98] shift=12 mask=0xFFF => 0x00000CDE
49 * Write: read data, data &= ~(MASK<<SHIFT), data |= (VALUE<<SHIFT), write data
50 * [0xABCDEF98] shift=12 mask=0xFFF value=0x123 => [0xAB123F98]
53 * # echo "CMD [OPTIONS] BANK ADRESS [VALUE]" > $debugfs/ab8500/hwreg
55 * CMD read read access
58 * BANK target reg bank
59 * ADDRESS target reg address
60 * VALUE (write) value to be updated
63 * -d|-dec (read) output in decimal
64 * -h|-hexa (read) output in 0x-hexa (default)
65 * -l|-w|-b 32bit (default), 16bit or 8bit reg access
66 * -m|-mask MASK 0x-hexa mask (default 0xFFFFFFFF)
67 * -s|-shift SHIFT bit shift value (read:left, write:right)
68 * -o|-offset OFFSET address offset to add to ADDRESS value
70 * Warning: bit shift operation is applied to bit-mask.
71 * Warning: bit shift direction depends on read or right command.
74 #include <linux/seq_file.h>
75 #include <linux/uaccess.h>
77 #include <linux/module.h>
78 #include <linux/debugfs.h>
79 #include <linux/platform_device.h>
80 #include <linux/interrupt.h>
81 #include <linux/kobject.h>
82 #include <linux/slab.h>
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[]) {
1262 static irqreturn_t ab8500_debug_handler(int irq, void *data)
1265 struct kobject *kobj = (struct kobject *)data;
1266 unsigned int irq_abb = irq - irq_first;
1268 if (irq_abb < num_irqs)
1269 irq_count[irq_abb]++;
1271 * This makes it possible to use poll for events (POLLPRI | POLLERR)
1272 * from userspace on sysfs file named <irq-nr>
1274 sprintf(buf, "%d", irq);
1275 sysfs_notify(kobj, NULL, buf);
1280 /* Prints to seq_file or log_buf */
1281 static int ab8500_registers_print(struct device *dev, u32 bank,
1286 for (i = 0; i < debug_ranges[bank].num_ranges; i++) {
1289 for (reg = debug_ranges[bank].range[i].first;
1290 reg <= debug_ranges[bank].range[i].last;
1295 err = abx500_get_register_interruptible(dev,
1296 (u8)bank, (u8)reg, &value);
1298 dev_err(dev, "ab->read fail %d\n", err);
1303 seq_printf(s, " [0x%02X/0x%02X]: 0x%02X\n",
1306 * Error is not returned here since
1307 * the output is wanted in any case
1309 if (seq_has_overflowed(s))
1312 dev_info(dev, " [0x%02X/0x%02X]: 0x%02X\n",
1321 static int ab8500_print_bank_registers(struct seq_file *s, void *p)
1323 struct device *dev = s->private;
1324 u32 bank = debug_bank;
1326 seq_puts(s, AB8500_NAME_STRING " register values:\n");
1328 seq_printf(s, " bank 0x%02X:\n", bank);
1330 return ab8500_registers_print(dev, bank, s);
1333 static int ab8500_registers_open(struct inode *inode, struct file *file)
1335 return single_open(file, ab8500_print_bank_registers, inode->i_private);
1338 static const struct file_operations ab8500_registers_fops = {
1339 .open = ab8500_registers_open,
1341 .llseek = seq_lseek,
1342 .release = single_release,
1343 .owner = THIS_MODULE,
1346 static int ab8500_print_all_banks(struct seq_file *s, void *p)
1348 struct device *dev = s->private;
1351 seq_puts(s, AB8500_NAME_STRING " register values:\n");
1353 for (i = 0; i < AB8500_NUM_BANKS; i++) {
1356 seq_printf(s, " bank 0x%02X:\n", i);
1357 err = ab8500_registers_print(dev, i, s);
1364 /* Dump registers to kernel log */
1365 void ab8500_dump_all_banks(struct device *dev)
1369 dev_info(dev, "ab8500 register values:\n");
1371 for (i = 1; i < AB8500_NUM_BANKS; i++) {
1372 dev_info(dev, " bank 0x%02X:\n", i);
1373 ab8500_registers_print(dev, i, NULL);
1377 /* Space for 500 registers. */
1378 #define DUMP_MAX_REGS 700
1379 static struct ab8500_register_dump
1384 } ab8500_complete_register_dump[DUMP_MAX_REGS];
1386 /* This shall only be called upon kernel panic! */
1387 void ab8500_dump_all_banks_to_mem(void)
1393 pr_info("Saving all ABB registers for crash analysis.\n");
1395 for (bank = 0; bank < AB8500_NUM_BANKS; bank++) {
1396 for (i = 0; i < debug_ranges[bank].num_ranges; i++) {
1399 for (reg = debug_ranges[bank].range[i].first;
1400 reg <= debug_ranges[bank].range[i].last;
1404 err = prcmu_abb_read(bank, reg, &value, 1);
1409 ab8500_complete_register_dump[r].bank = bank;
1410 ab8500_complete_register_dump[r].reg = reg;
1411 ab8500_complete_register_dump[r].value = value;
1415 if (r >= DUMP_MAX_REGS) {
1416 pr_err("%s: too many register to dump!\n",
1426 pr_info("Saved all ABB registers.\n");
1428 pr_info("Failed to save all ABB registers.\n");
1431 static int ab8500_all_banks_open(struct inode *inode, struct file *file)
1436 err = single_open(file, ab8500_print_all_banks, inode->i_private);
1438 /* Default buf size in seq_read is not enough */
1439 s = (struct seq_file *)file->private_data;
1440 s->size = (PAGE_SIZE * 2);
1441 s->buf = kmalloc(s->size, GFP_KERNEL);
1443 single_release(inode, file);
1450 static const struct file_operations ab8500_all_banks_fops = {
1451 .open = ab8500_all_banks_open,
1453 .llseek = seq_lseek,
1454 .release = single_release,
1455 .owner = THIS_MODULE,
1458 static int ab8500_bank_print(struct seq_file *s, void *p)
1460 seq_printf(s, "0x%02X\n", debug_bank);
1464 static int ab8500_bank_open(struct inode *inode, struct file *file)
1466 return single_open(file, ab8500_bank_print, inode->i_private);
1469 static ssize_t ab8500_bank_write(struct file *file,
1470 const char __user *user_buf,
1471 size_t count, loff_t *ppos)
1473 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1474 unsigned long user_bank;
1477 err = kstrtoul_from_user(user_buf, count, 0, &user_bank);
1481 if (user_bank >= AB8500_NUM_BANKS) {
1482 dev_err(dev, "debugfs error input > number of banks\n");
1486 debug_bank = user_bank;
1491 static int ab8500_address_print(struct seq_file *s, void *p)
1493 seq_printf(s, "0x%02X\n", debug_address);
1497 static int ab8500_address_open(struct inode *inode, struct file *file)
1499 return single_open(file, ab8500_address_print, inode->i_private);
1502 static ssize_t ab8500_address_write(struct file *file,
1503 const char __user *user_buf,
1504 size_t count, loff_t *ppos)
1506 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1507 unsigned long user_address;
1510 err = kstrtoul_from_user(user_buf, count, 0, &user_address);
1514 if (user_address > 0xff) {
1515 dev_err(dev, "debugfs error input > 0xff\n");
1518 debug_address = user_address;
1523 static int ab8500_val_print(struct seq_file *s, void *p)
1525 struct device *dev = s->private;
1529 ret = abx500_get_register_interruptible(dev,
1530 (u8)debug_bank, (u8)debug_address, ®value);
1532 dev_err(dev, "abx500_get_reg fail %d, %d\n",
1536 seq_printf(s, "0x%02X\n", regvalue);
1541 static int ab8500_val_open(struct inode *inode, struct file *file)
1543 return single_open(file, ab8500_val_print, inode->i_private);
1546 static ssize_t ab8500_val_write(struct file *file,
1547 const char __user *user_buf,
1548 size_t count, loff_t *ppos)
1550 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1551 unsigned long user_val;
1554 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
1558 if (user_val > 0xff) {
1559 dev_err(dev, "debugfs error input > 0xff\n");
1562 err = abx500_set_register_interruptible(dev,
1563 (u8)debug_bank, debug_address, (u8)user_val);
1565 pr_err("abx500_set_reg failed %d, %d", err, __LINE__);
1575 static u32 num_interrupts[AB8500_MAX_NR_IRQS];
1576 static u32 num_wake_interrupts[AB8500_MAX_NR_IRQS];
1577 static int num_interrupt_lines;
1579 bool __attribute__((weak)) suspend_test_wake_cause_interrupt_is_mine(u32 my_int)
1584 void ab8500_debug_register_interrupt(int line)
1586 if (line < num_interrupt_lines) {
1587 num_interrupts[line]++;
1588 if (suspend_test_wake_cause_interrupt_is_mine(irq_ab8500))
1589 num_wake_interrupts[line]++;
1593 static int ab8500_interrupts_print(struct seq_file *s, void *p)
1597 seq_puts(s, "name: number: number of: wake:\n");
1599 for (line = 0; line < num_interrupt_lines; line++) {
1600 struct irq_desc *desc = irq_to_desc(line + irq_first);
1602 seq_printf(s, "%3i: %6i %4i",
1604 num_interrupts[line],
1605 num_wake_interrupts[line]);
1607 if (desc && desc->name)
1608 seq_printf(s, "-%-8s", desc->name);
1609 if (desc && desc->action) {
1610 struct irqaction *action = desc->action;
1612 seq_printf(s, " %s", action->name);
1613 while ((action = action->next) != NULL)
1614 seq_printf(s, ", %s", action->name);
1622 static int ab8500_interrupts_open(struct inode *inode, struct file *file)
1624 return single_open(file, ab8500_interrupts_print, inode->i_private);
1628 * - HWREG DB8500 formated routines
1630 static int ab8500_hwreg_print(struct seq_file *s, void *d)
1632 struct device *dev = s->private;
1636 ret = abx500_get_register_interruptible(dev,
1637 (u8)hwreg_cfg.bank, (u8)hwreg_cfg.addr, ®value);
1639 dev_err(dev, "abx500_get_reg fail %d, %d\n",
1644 if (hwreg_cfg.shift >= 0)
1645 regvalue >>= hwreg_cfg.shift;
1647 regvalue <<= -hwreg_cfg.shift;
1648 regvalue &= hwreg_cfg.mask;
1650 if (REG_FMT_DEC(&hwreg_cfg))
1651 seq_printf(s, "%d\n", regvalue);
1653 seq_printf(s, "0x%02X\n", regvalue);
1657 static int ab8500_hwreg_open(struct inode *inode, struct file *file)
1659 return single_open(file, ab8500_hwreg_print, inode->i_private);
1662 #define AB8500_SUPPLY_CONTROL_CONFIG_1 0x01
1663 #define AB8500_SUPPLY_CONTROL_REG 0x00
1664 #define AB8500_FIRST_SIM_REG 0x80
1665 #define AB8500_LAST_SIM_REG 0x8B
1666 #define AB8505_LAST_SIM_REG 0x8C
1668 static int ab8500_print_modem_registers(struct seq_file *s, void *p)
1670 struct device *dev = s->private;
1671 struct ab8500 *ab8500;
1675 u32 bank = AB8500_REGU_CTRL2;
1676 u32 last_sim_reg = AB8500_LAST_SIM_REG;
1679 ab8500 = dev_get_drvdata(dev->parent);
1680 dev_warn(dev, "WARNING! This operation can interfer with modem side\n"
1681 "and should only be done with care\n");
1683 err = abx500_get_register_interruptible(dev,
1684 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG, &orig_value);
1686 dev_err(dev, "ab->read fail %d\n", err);
1689 /* Config 1 will allow APE side to read SIM registers */
1690 err = abx500_set_register_interruptible(dev,
1691 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG,
1692 AB8500_SUPPLY_CONTROL_CONFIG_1);
1694 dev_err(dev, "ab->write fail %d\n", err);
1698 seq_printf(s, " bank 0x%02X:\n", bank);
1700 if (is_ab9540(ab8500) || is_ab8505(ab8500))
1701 last_sim_reg = AB8505_LAST_SIM_REG;
1703 for (reg = AB8500_FIRST_SIM_REG; reg <= last_sim_reg; reg++) {
1704 err = abx500_get_register_interruptible(dev,
1707 dev_err(dev, "ab->read fail %d\n", err);
1710 seq_printf(s, " [0x%02X/0x%02X]: 0x%02X\n", bank, reg, value);
1712 err = abx500_set_register_interruptible(dev,
1713 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG, orig_value);
1715 dev_err(dev, "ab->write fail %d\n", err);
1721 static int ab8500_modem_open(struct inode *inode, struct file *file)
1723 return single_open(file, ab8500_print_modem_registers,
1727 static const struct file_operations ab8500_modem_fops = {
1728 .open = ab8500_modem_open,
1730 .llseek = seq_lseek,
1731 .release = single_release,
1732 .owner = THIS_MODULE,
1735 static int ab8500_gpadc_bat_ctrl_print(struct seq_file *s, void *p)
1738 int bat_ctrl_convert;
1739 struct ab8500_gpadc *gpadc;
1741 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1742 bat_ctrl_raw = ab8500_gpadc_read_raw(gpadc, BAT_CTRL,
1743 avg_sample, trig_edge, trig_timer, conv_type);
1744 bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc,
1745 BAT_CTRL, bat_ctrl_raw);
1747 seq_printf(s, "%d,0x%X\n", bat_ctrl_convert, bat_ctrl_raw);
1752 static int ab8500_gpadc_bat_ctrl_open(struct inode *inode, struct file *file)
1754 return single_open(file, ab8500_gpadc_bat_ctrl_print,
1758 static const struct file_operations ab8500_gpadc_bat_ctrl_fops = {
1759 .open = ab8500_gpadc_bat_ctrl_open,
1761 .llseek = seq_lseek,
1762 .release = single_release,
1763 .owner = THIS_MODULE,
1766 static int ab8500_gpadc_btemp_ball_print(struct seq_file *s, void *p)
1769 int btemp_ball_convert;
1770 struct ab8500_gpadc *gpadc;
1772 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1773 btemp_ball_raw = ab8500_gpadc_read_raw(gpadc, BTEMP_BALL,
1774 avg_sample, trig_edge, trig_timer, conv_type);
1775 btemp_ball_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL,
1778 seq_printf(s, "%d,0x%X\n", btemp_ball_convert, btemp_ball_raw);
1783 static int ab8500_gpadc_btemp_ball_open(struct inode *inode,
1786 return single_open(file, ab8500_gpadc_btemp_ball_print,
1790 static const struct file_operations ab8500_gpadc_btemp_ball_fops = {
1791 .open = ab8500_gpadc_btemp_ball_open,
1793 .llseek = seq_lseek,
1794 .release = single_release,
1795 .owner = THIS_MODULE,
1798 static int ab8500_gpadc_main_charger_v_print(struct seq_file *s, void *p)
1800 int main_charger_v_raw;
1801 int main_charger_v_convert;
1802 struct ab8500_gpadc *gpadc;
1804 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1805 main_charger_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_V,
1806 avg_sample, trig_edge, trig_timer, conv_type);
1807 main_charger_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
1808 MAIN_CHARGER_V, main_charger_v_raw);
1810 seq_printf(s, "%d,0x%X\n", main_charger_v_convert, main_charger_v_raw);
1815 static int ab8500_gpadc_main_charger_v_open(struct inode *inode,
1818 return single_open(file, ab8500_gpadc_main_charger_v_print,
1822 static const struct file_operations ab8500_gpadc_main_charger_v_fops = {
1823 .open = ab8500_gpadc_main_charger_v_open,
1825 .llseek = seq_lseek,
1826 .release = single_release,
1827 .owner = THIS_MODULE,
1830 static int ab8500_gpadc_acc_detect1_print(struct seq_file *s, void *p)
1832 int acc_detect1_raw;
1833 int acc_detect1_convert;
1834 struct ab8500_gpadc *gpadc;
1836 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1837 acc_detect1_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT1,
1838 avg_sample, trig_edge, trig_timer, conv_type);
1839 acc_detect1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ACC_DETECT1,
1842 seq_printf(s, "%d,0x%X\n", acc_detect1_convert, acc_detect1_raw);
1847 static int ab8500_gpadc_acc_detect1_open(struct inode *inode,
1850 return single_open(file, ab8500_gpadc_acc_detect1_print,
1854 static const struct file_operations ab8500_gpadc_acc_detect1_fops = {
1855 .open = ab8500_gpadc_acc_detect1_open,
1857 .llseek = seq_lseek,
1858 .release = single_release,
1859 .owner = THIS_MODULE,
1862 static int ab8500_gpadc_acc_detect2_print(struct seq_file *s, void *p)
1864 int acc_detect2_raw;
1865 int acc_detect2_convert;
1866 struct ab8500_gpadc *gpadc;
1868 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1869 acc_detect2_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT2,
1870 avg_sample, trig_edge, trig_timer, conv_type);
1871 acc_detect2_convert = ab8500_gpadc_ad_to_voltage(gpadc,
1872 ACC_DETECT2, acc_detect2_raw);
1874 seq_printf(s, "%d,0x%X\n", acc_detect2_convert, acc_detect2_raw);
1879 static int ab8500_gpadc_acc_detect2_open(struct inode *inode,
1882 return single_open(file, ab8500_gpadc_acc_detect2_print,
1886 static const struct file_operations ab8500_gpadc_acc_detect2_fops = {
1887 .open = ab8500_gpadc_acc_detect2_open,
1889 .llseek = seq_lseek,
1890 .release = single_release,
1891 .owner = THIS_MODULE,
1894 static int ab8500_gpadc_aux1_print(struct seq_file *s, void *p)
1898 struct ab8500_gpadc *gpadc;
1900 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1901 aux1_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX1,
1902 avg_sample, trig_edge, trig_timer, conv_type);
1903 aux1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX1,
1906 seq_printf(s, "%d,0x%X\n", aux1_convert, aux1_raw);
1911 static int ab8500_gpadc_aux1_open(struct inode *inode, struct file *file)
1913 return single_open(file, ab8500_gpadc_aux1_print, inode->i_private);
1916 static const struct file_operations ab8500_gpadc_aux1_fops = {
1917 .open = ab8500_gpadc_aux1_open,
1919 .llseek = seq_lseek,
1920 .release = single_release,
1921 .owner = THIS_MODULE,
1924 static int ab8500_gpadc_aux2_print(struct seq_file *s, void *p)
1928 struct ab8500_gpadc *gpadc;
1930 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1931 aux2_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX2,
1932 avg_sample, trig_edge, trig_timer, conv_type);
1933 aux2_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX2,
1936 seq_printf(s, "%d,0x%X\n", aux2_convert, aux2_raw);
1941 static int ab8500_gpadc_aux2_open(struct inode *inode, struct file *file)
1943 return single_open(file, ab8500_gpadc_aux2_print, inode->i_private);
1946 static const struct file_operations ab8500_gpadc_aux2_fops = {
1947 .open = ab8500_gpadc_aux2_open,
1949 .llseek = seq_lseek,
1950 .release = single_release,
1951 .owner = THIS_MODULE,
1954 static int ab8500_gpadc_main_bat_v_print(struct seq_file *s, void *p)
1957 int main_bat_v_convert;
1958 struct ab8500_gpadc *gpadc;
1960 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1961 main_bat_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_BAT_V,
1962 avg_sample, trig_edge, trig_timer, conv_type);
1963 main_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V,
1966 seq_printf(s, "%d,0x%X\n", main_bat_v_convert, main_bat_v_raw);
1971 static int ab8500_gpadc_main_bat_v_open(struct inode *inode,
1974 return single_open(file, ab8500_gpadc_main_bat_v_print,
1978 static const struct file_operations ab8500_gpadc_main_bat_v_fops = {
1979 .open = ab8500_gpadc_main_bat_v_open,
1981 .llseek = seq_lseek,
1982 .release = single_release,
1983 .owner = THIS_MODULE,
1986 static int ab8500_gpadc_vbus_v_print(struct seq_file *s, void *p)
1990 struct ab8500_gpadc *gpadc;
1992 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1993 vbus_v_raw = ab8500_gpadc_read_raw(gpadc, VBUS_V,
1994 avg_sample, trig_edge, trig_timer, conv_type);
1995 vbus_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, VBUS_V,
1998 seq_printf(s, "%d,0x%X\n", vbus_v_convert, vbus_v_raw);
2003 static int ab8500_gpadc_vbus_v_open(struct inode *inode, struct file *file)
2005 return single_open(file, ab8500_gpadc_vbus_v_print, inode->i_private);
2008 static const struct file_operations ab8500_gpadc_vbus_v_fops = {
2009 .open = ab8500_gpadc_vbus_v_open,
2011 .llseek = seq_lseek,
2012 .release = single_release,
2013 .owner = THIS_MODULE,
2016 static int ab8500_gpadc_main_charger_c_print(struct seq_file *s, void *p)
2018 int main_charger_c_raw;
2019 int main_charger_c_convert;
2020 struct ab8500_gpadc *gpadc;
2022 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2023 main_charger_c_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_C,
2024 avg_sample, trig_edge, trig_timer, conv_type);
2025 main_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
2026 MAIN_CHARGER_C, main_charger_c_raw);
2028 seq_printf(s, "%d,0x%X\n", main_charger_c_convert, main_charger_c_raw);
2033 static int ab8500_gpadc_main_charger_c_open(struct inode *inode,
2036 return single_open(file, ab8500_gpadc_main_charger_c_print,
2040 static const struct file_operations ab8500_gpadc_main_charger_c_fops = {
2041 .open = ab8500_gpadc_main_charger_c_open,
2043 .llseek = seq_lseek,
2044 .release = single_release,
2045 .owner = THIS_MODULE,
2048 static int ab8500_gpadc_usb_charger_c_print(struct seq_file *s, void *p)
2050 int usb_charger_c_raw;
2051 int usb_charger_c_convert;
2052 struct ab8500_gpadc *gpadc;
2054 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2055 usb_charger_c_raw = ab8500_gpadc_read_raw(gpadc, USB_CHARGER_C,
2056 avg_sample, trig_edge, trig_timer, conv_type);
2057 usb_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
2058 USB_CHARGER_C, usb_charger_c_raw);
2060 seq_printf(s, "%d,0x%X\n", usb_charger_c_convert, usb_charger_c_raw);
2065 static int ab8500_gpadc_usb_charger_c_open(struct inode *inode,
2068 return single_open(file, ab8500_gpadc_usb_charger_c_print,
2072 static const struct file_operations ab8500_gpadc_usb_charger_c_fops = {
2073 .open = ab8500_gpadc_usb_charger_c_open,
2075 .llseek = seq_lseek,
2076 .release = single_release,
2077 .owner = THIS_MODULE,
2080 static int ab8500_gpadc_bk_bat_v_print(struct seq_file *s, void *p)
2083 int bk_bat_v_convert;
2084 struct ab8500_gpadc *gpadc;
2086 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2087 bk_bat_v_raw = ab8500_gpadc_read_raw(gpadc, BK_BAT_V,
2088 avg_sample, trig_edge, trig_timer, conv_type);
2089 bk_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
2090 BK_BAT_V, bk_bat_v_raw);
2092 seq_printf(s, "%d,0x%X\n", bk_bat_v_convert, bk_bat_v_raw);
2097 static int ab8500_gpadc_bk_bat_v_open(struct inode *inode, struct file *file)
2099 return single_open(file, ab8500_gpadc_bk_bat_v_print,
2103 static const struct file_operations ab8500_gpadc_bk_bat_v_fops = {
2104 .open = ab8500_gpadc_bk_bat_v_open,
2106 .llseek = seq_lseek,
2107 .release = single_release,
2108 .owner = THIS_MODULE,
2111 static int ab8500_gpadc_die_temp_print(struct seq_file *s, void *p)
2114 int die_temp_convert;
2115 struct ab8500_gpadc *gpadc;
2117 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2118 die_temp_raw = ab8500_gpadc_read_raw(gpadc, DIE_TEMP,
2119 avg_sample, trig_edge, trig_timer, conv_type);
2120 die_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, DIE_TEMP,
2123 seq_printf(s, "%d,0x%X\n", die_temp_convert, die_temp_raw);
2128 static int ab8500_gpadc_die_temp_open(struct inode *inode, struct file *file)
2130 return single_open(file, ab8500_gpadc_die_temp_print,
2134 static const struct file_operations ab8500_gpadc_die_temp_fops = {
2135 .open = ab8500_gpadc_die_temp_open,
2137 .llseek = seq_lseek,
2138 .release = single_release,
2139 .owner = THIS_MODULE,
2142 static int ab8500_gpadc_usb_id_print(struct seq_file *s, void *p)
2146 struct ab8500_gpadc *gpadc;
2148 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2149 usb_id_raw = ab8500_gpadc_read_raw(gpadc, USB_ID,
2150 avg_sample, trig_edge, trig_timer, conv_type);
2151 usb_id_convert = ab8500_gpadc_ad_to_voltage(gpadc, USB_ID,
2154 seq_printf(s, "%d,0x%X\n", usb_id_convert, usb_id_raw);
2159 static int ab8500_gpadc_usb_id_open(struct inode *inode, struct file *file)
2161 return single_open(file, ab8500_gpadc_usb_id_print, inode->i_private);
2164 static const struct file_operations ab8500_gpadc_usb_id_fops = {
2165 .open = ab8500_gpadc_usb_id_open,
2167 .llseek = seq_lseek,
2168 .release = single_release,
2169 .owner = THIS_MODULE,
2172 static int ab8540_gpadc_xtal_temp_print(struct seq_file *s, void *p)
2175 int xtal_temp_convert;
2176 struct ab8500_gpadc *gpadc;
2178 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2179 xtal_temp_raw = ab8500_gpadc_read_raw(gpadc, XTAL_TEMP,
2180 avg_sample, trig_edge, trig_timer, conv_type);
2181 xtal_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, XTAL_TEMP,
2184 seq_printf(s, "%d,0x%X\n", xtal_temp_convert, xtal_temp_raw);
2189 static int ab8540_gpadc_xtal_temp_open(struct inode *inode, struct file *file)
2191 return single_open(file, ab8540_gpadc_xtal_temp_print,
2195 static const struct file_operations ab8540_gpadc_xtal_temp_fops = {
2196 .open = ab8540_gpadc_xtal_temp_open,
2198 .llseek = seq_lseek,
2199 .release = single_release,
2200 .owner = THIS_MODULE,
2203 static int ab8540_gpadc_vbat_true_meas_print(struct seq_file *s, void *p)
2205 int vbat_true_meas_raw;
2206 int vbat_true_meas_convert;
2207 struct ab8500_gpadc *gpadc;
2209 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2210 vbat_true_meas_raw = ab8500_gpadc_read_raw(gpadc, VBAT_TRUE_MEAS,
2211 avg_sample, trig_edge, trig_timer, conv_type);
2212 vbat_true_meas_convert =
2213 ab8500_gpadc_ad_to_voltage(gpadc, VBAT_TRUE_MEAS,
2214 vbat_true_meas_raw);
2216 seq_printf(s, "%d,0x%X\n", vbat_true_meas_convert, vbat_true_meas_raw);
2221 static int ab8540_gpadc_vbat_true_meas_open(struct inode *inode,
2224 return single_open(file, ab8540_gpadc_vbat_true_meas_print,
2228 static const struct file_operations ab8540_gpadc_vbat_true_meas_fops = {
2229 .open = ab8540_gpadc_vbat_true_meas_open,
2231 .llseek = seq_lseek,
2232 .release = single_release,
2233 .owner = THIS_MODULE,
2236 static int ab8540_gpadc_bat_ctrl_and_ibat_print(struct seq_file *s, void *p)
2239 int bat_ctrl_convert;
2242 struct ab8500_gpadc *gpadc;
2244 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2245 bat_ctrl_raw = ab8500_gpadc_double_read_raw(gpadc, BAT_CTRL_AND_IBAT,
2246 avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
2248 bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc, BAT_CTRL,
2250 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2256 bat_ctrl_convert, bat_ctrl_raw,
2257 ibat_convert, ibat_raw);
2262 static int ab8540_gpadc_bat_ctrl_and_ibat_open(struct inode *inode,
2265 return single_open(file, ab8540_gpadc_bat_ctrl_and_ibat_print,
2269 static const struct file_operations ab8540_gpadc_bat_ctrl_and_ibat_fops = {
2270 .open = ab8540_gpadc_bat_ctrl_and_ibat_open,
2272 .llseek = seq_lseek,
2273 .release = single_release,
2274 .owner = THIS_MODULE,
2277 static int ab8540_gpadc_vbat_meas_and_ibat_print(struct seq_file *s, void *p)
2280 int vbat_meas_convert;
2283 struct ab8500_gpadc *gpadc;
2285 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2286 vbat_meas_raw = ab8500_gpadc_double_read_raw(gpadc, VBAT_MEAS_AND_IBAT,
2287 avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
2288 vbat_meas_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V,
2290 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2296 vbat_meas_convert, vbat_meas_raw,
2297 ibat_convert, ibat_raw);
2302 static int ab8540_gpadc_vbat_meas_and_ibat_open(struct inode *inode,
2305 return single_open(file, ab8540_gpadc_vbat_meas_and_ibat_print,
2309 static const struct file_operations ab8540_gpadc_vbat_meas_and_ibat_fops = {
2310 .open = ab8540_gpadc_vbat_meas_and_ibat_open,
2312 .llseek = seq_lseek,
2313 .release = single_release,
2314 .owner = THIS_MODULE,
2317 static int ab8540_gpadc_vbat_true_meas_and_ibat_print(struct seq_file *s,
2320 int vbat_true_meas_raw;
2321 int vbat_true_meas_convert;
2324 struct ab8500_gpadc *gpadc;
2326 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2327 vbat_true_meas_raw = ab8500_gpadc_double_read_raw(gpadc,
2328 VBAT_TRUE_MEAS_AND_IBAT, avg_sample, trig_edge,
2329 trig_timer, conv_type, &ibat_raw);
2330 vbat_true_meas_convert = ab8500_gpadc_ad_to_voltage(gpadc,
2331 VBAT_TRUE_MEAS, vbat_true_meas_raw);
2332 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2338 vbat_true_meas_convert, vbat_true_meas_raw,
2339 ibat_convert, ibat_raw);
2344 static int ab8540_gpadc_vbat_true_meas_and_ibat_open(struct inode *inode,
2347 return single_open(file, ab8540_gpadc_vbat_true_meas_and_ibat_print,
2351 static const struct file_operations
2352 ab8540_gpadc_vbat_true_meas_and_ibat_fops = {
2353 .open = ab8540_gpadc_vbat_true_meas_and_ibat_open,
2355 .llseek = seq_lseek,
2356 .release = single_release,
2357 .owner = THIS_MODULE,
2360 static int ab8540_gpadc_bat_temp_and_ibat_print(struct seq_file *s, void *p)
2363 int bat_temp_convert;
2366 struct ab8500_gpadc *gpadc;
2368 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2369 bat_temp_raw = ab8500_gpadc_double_read_raw(gpadc, BAT_TEMP_AND_IBAT,
2370 avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
2371 bat_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL,
2373 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2379 bat_temp_convert, bat_temp_raw,
2380 ibat_convert, ibat_raw);
2385 static int ab8540_gpadc_bat_temp_and_ibat_open(struct inode *inode,
2388 return single_open(file, ab8540_gpadc_bat_temp_and_ibat_print,
2392 static const struct file_operations ab8540_gpadc_bat_temp_and_ibat_fops = {
2393 .open = ab8540_gpadc_bat_temp_and_ibat_open,
2395 .llseek = seq_lseek,
2396 .release = single_release,
2397 .owner = THIS_MODULE,
2400 static int ab8540_gpadc_otp_cal_print(struct seq_file *s, void *p)
2402 struct ab8500_gpadc *gpadc;
2403 u16 vmain_l, vmain_h, btemp_l, btemp_h;
2404 u16 vbat_l, vbat_h, ibat_l, ibat_h;
2406 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2407 ab8540_gpadc_get_otp(gpadc, &vmain_l, &vmain_h, &btemp_l, &btemp_h,
2408 &vbat_l, &vbat_h, &ibat_l, &ibat_h);
2418 vmain_l, vmain_h, btemp_l, btemp_h,
2419 vbat_l, vbat_h, ibat_l, ibat_h);
2424 static int ab8540_gpadc_otp_cal_open(struct inode *inode, struct file *file)
2426 return single_open(file, ab8540_gpadc_otp_cal_print, inode->i_private);
2429 static const struct file_operations ab8540_gpadc_otp_calib_fops = {
2430 .open = ab8540_gpadc_otp_cal_open,
2432 .llseek = seq_lseek,
2433 .release = single_release,
2434 .owner = THIS_MODULE,
2437 static int ab8500_gpadc_avg_sample_print(struct seq_file *s, void *p)
2439 seq_printf(s, "%d\n", avg_sample);
2444 static int ab8500_gpadc_avg_sample_open(struct inode *inode, struct file *file)
2446 return single_open(file, ab8500_gpadc_avg_sample_print,
2450 static ssize_t ab8500_gpadc_avg_sample_write(struct file *file,
2451 const char __user *user_buf,
2452 size_t count, loff_t *ppos)
2454 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2455 unsigned long user_avg_sample;
2458 err = kstrtoul_from_user(user_buf, count, 0, &user_avg_sample);
2462 if ((user_avg_sample == SAMPLE_1) || (user_avg_sample == SAMPLE_4)
2463 || (user_avg_sample == SAMPLE_8)
2464 || (user_avg_sample == SAMPLE_16)) {
2465 avg_sample = (u8) user_avg_sample;
2468 "debugfs err input: should be egal to 1, 4, 8 or 16\n");
2475 static const struct file_operations ab8500_gpadc_avg_sample_fops = {
2476 .open = ab8500_gpadc_avg_sample_open,
2478 .write = ab8500_gpadc_avg_sample_write,
2479 .llseek = seq_lseek,
2480 .release = single_release,
2481 .owner = THIS_MODULE,
2484 static int ab8500_gpadc_trig_edge_print(struct seq_file *s, void *p)
2486 seq_printf(s, "%d\n", trig_edge);
2491 static int ab8500_gpadc_trig_edge_open(struct inode *inode, struct file *file)
2493 return single_open(file, ab8500_gpadc_trig_edge_print,
2497 static ssize_t ab8500_gpadc_trig_edge_write(struct file *file,
2498 const char __user *user_buf,
2499 size_t count, loff_t *ppos)
2501 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2502 unsigned long user_trig_edge;
2505 err = kstrtoul_from_user(user_buf, count, 0, &user_trig_edge);
2509 if ((user_trig_edge == RISING_EDGE)
2510 || (user_trig_edge == FALLING_EDGE)) {
2511 trig_edge = (u8) user_trig_edge;
2513 dev_err(dev, "Wrong input:\n"
2514 "Enter 0. Rising edge\n"
2515 "Enter 1. Falling edge\n");
2522 static const struct file_operations ab8500_gpadc_trig_edge_fops = {
2523 .open = ab8500_gpadc_trig_edge_open,
2525 .write = ab8500_gpadc_trig_edge_write,
2526 .llseek = seq_lseek,
2527 .release = single_release,
2528 .owner = THIS_MODULE,
2531 static int ab8500_gpadc_trig_timer_print(struct seq_file *s, void *p)
2533 seq_printf(s, "%d\n", trig_timer);
2538 static int ab8500_gpadc_trig_timer_open(struct inode *inode, struct file *file)
2540 return single_open(file, ab8500_gpadc_trig_timer_print,
2544 static ssize_t ab8500_gpadc_trig_timer_write(struct file *file,
2545 const char __user *user_buf,
2546 size_t count, loff_t *ppos)
2548 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2549 unsigned long user_trig_timer;
2552 err = kstrtoul_from_user(user_buf, count, 0, &user_trig_timer);
2556 if (user_trig_timer & ~0xFF) {
2558 "debugfs error input: should be between 0 to 255\n");
2562 trig_timer = (u8) user_trig_timer;
2567 static const struct file_operations ab8500_gpadc_trig_timer_fops = {
2568 .open = ab8500_gpadc_trig_timer_open,
2570 .write = ab8500_gpadc_trig_timer_write,
2571 .llseek = seq_lseek,
2572 .release = single_release,
2573 .owner = THIS_MODULE,
2576 static int ab8500_gpadc_conv_type_print(struct seq_file *s, void *p)
2578 seq_printf(s, "%d\n", conv_type);
2583 static int ab8500_gpadc_conv_type_open(struct inode *inode, struct file *file)
2585 return single_open(file, ab8500_gpadc_conv_type_print,
2589 static ssize_t ab8500_gpadc_conv_type_write(struct file *file,
2590 const char __user *user_buf,
2591 size_t count, loff_t *ppos)
2593 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2594 unsigned long user_conv_type;
2597 err = kstrtoul_from_user(user_buf, count, 0, &user_conv_type);
2601 if ((user_conv_type == ADC_SW)
2602 || (user_conv_type == ADC_HW)) {
2603 conv_type = (u8) user_conv_type;
2605 dev_err(dev, "Wrong input:\n"
2606 "Enter 0. ADC SW conversion\n"
2607 "Enter 1. ADC HW conversion\n");
2614 static const struct file_operations ab8500_gpadc_conv_type_fops = {
2615 .open = ab8500_gpadc_conv_type_open,
2617 .write = ab8500_gpadc_conv_type_write,
2618 .llseek = seq_lseek,
2619 .release = single_release,
2620 .owner = THIS_MODULE,
2624 * return length of an ASCII numerical value, 0 is string is not a
2626 * string shall start at value 1st char.
2627 * string can be tailed with \0 or space or newline chars only.
2628 * value can be decimal or hexadecimal (prefixed 0x or 0X).
2630 static int strval_len(char *b)
2634 if ((*s == '0') && ((*(s+1) == 'x') || (*(s+1) == 'X'))) {
2636 for (; *s && (*s != ' ') && (*s != '\n'); s++) {
2643 for (; *s && (*s != ' ') && (*s != '\n'); s++) {
2652 * parse hwreg input data.
2653 * update global hwreg_cfg only if input data syntax is ok.
2655 static ssize_t hwreg_common_write(char *b, struct hwreg_cfg *cfg,
2658 uint write, val = 0;
2661 struct hwreg_cfg loc = {
2662 .bank = 0, /* default: invalid phys addr */
2663 .addr = 0, /* default: invalid phys addr */
2664 .fmt = 0, /* default: 32bit access, hex output */
2665 .mask = 0xFFFFFFFF, /* default: no mask */
2666 .shift = 0, /* default: no bit shift */
2669 /* read or write ? */
2670 if (!strncmp(b, "read ", 5)) {
2673 } else if (!strncmp(b, "write ", 6)) {
2679 /* OPTIONS -l|-w|-b -s -m -o */
2680 while ((*b == ' ') || (*b == '-')) {
2681 if (*(b-1) != ' ') {
2685 if ((!strncmp(b, "-d ", 3)) ||
2686 (!strncmp(b, "-dec ", 5))) {
2687 b += (*(b+2) == ' ') ? 3 : 5;
2689 } else if ((!strncmp(b, "-h ", 3)) ||
2690 (!strncmp(b, "-hex ", 5))) {
2691 b += (*(b+2) == ' ') ? 3 : 5;
2693 } else if ((!strncmp(b, "-m ", 3)) ||
2694 (!strncmp(b, "-mask ", 6))) {
2695 b += (*(b+2) == ' ') ? 3 : 6;
2696 if (strval_len(b) == 0)
2698 ret = kstrtoul(b, 0, &loc.mask);
2701 } else if ((!strncmp(b, "-s ", 3)) ||
2702 (!strncmp(b, "-shift ", 7))) {
2703 b += (*(b+2) == ' ') ? 3 : 7;
2704 if (strval_len(b) == 0)
2706 ret = kstrtol(b, 0, &loc.shift);
2713 /* get arg BANK and ADDRESS */
2714 if (strval_len(b) == 0)
2716 ret = kstrtouint(b, 0, &loc.bank);
2721 if (strval_len(b) == 0)
2723 ret = kstrtoul(b, 0, &loc.addr);
2730 if (strval_len(b) == 0)
2732 ret = kstrtouint(b, 0, &val);
2737 /* args are ok, update target cfg (mainly for read) */
2740 #ifdef ABB_HWREG_DEBUG
2741 pr_warn("HWREG request: %s, %s,\n", (write) ? "write" : "read",
2742 REG_FMT_DEC(cfg) ? "decimal" : "hexa");
2743 pr_warn(" addr=0x%08X, mask=0x%X, shift=%d" "value=0x%X\n",
2744 cfg->addr, cfg->mask, cfg->shift, val);
2750 ret = abx500_get_register_interruptible(dev,
2751 (u8)cfg->bank, (u8)cfg->addr, ®value);
2753 dev_err(dev, "abx500_get_reg fail %d, %d\n",
2758 if (cfg->shift >= 0) {
2759 regvalue &= ~(cfg->mask << (cfg->shift));
2760 val = (val & cfg->mask) << (cfg->shift);
2762 regvalue &= ~(cfg->mask >> (-cfg->shift));
2763 val = (val & cfg->mask) >> (-cfg->shift);
2765 val = val | regvalue;
2767 ret = abx500_set_register_interruptible(dev,
2768 (u8)cfg->bank, (u8)cfg->addr, (u8)val);
2770 pr_err("abx500_set_reg failed %d, %d", ret, __LINE__);
2777 static ssize_t ab8500_hwreg_write(struct file *file,
2778 const char __user *user_buf, size_t count, loff_t *ppos)
2780 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2784 /* Get userspace string and assure termination */
2785 buf_size = min(count, (sizeof(buf)-1));
2786 if (copy_from_user(buf, user_buf, buf_size))
2790 /* get args and process */
2791 ret = hwreg_common_write(buf, &hwreg_cfg, dev);
2792 return (ret) ? ret : buf_size;
2796 * - irq subscribe/unsubscribe stuff
2798 static int ab8500_subscribe_unsubscribe_print(struct seq_file *s, void *p)
2800 seq_printf(s, "%d\n", irq_first);
2805 static int ab8500_subscribe_unsubscribe_open(struct inode *inode,
2808 return single_open(file, ab8500_subscribe_unsubscribe_print,
2813 * Userspace should use poll() on this file. When an event occur
2814 * the blocking poll will be released.
2816 static ssize_t show_irq(struct device *dev,
2817 struct device_attribute *attr, char *buf)
2820 unsigned int irq_index;
2823 err = kstrtoul(attr->attr.name, 0, &name);
2827 irq_index = name - irq_first;
2828 if (irq_index >= num_irqs)
2831 return sprintf(buf, "%u\n", irq_count[irq_index]);
2834 static ssize_t ab8500_subscribe_write(struct file *file,
2835 const char __user *user_buf,
2836 size_t count, loff_t *ppos)
2838 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2839 unsigned long user_val;
2841 unsigned int irq_index;
2843 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
2847 if (user_val < irq_first) {
2848 dev_err(dev, "debugfs error input < %d\n", irq_first);
2851 if (user_val > irq_last) {
2852 dev_err(dev, "debugfs error input > %d\n", irq_last);
2856 irq_index = user_val - irq_first;
2857 if (irq_index >= num_irqs)
2861 * This will create a sysfs file named <irq-nr> which userspace can
2862 * use to select or poll and get the AB8500 events
2864 dev_attr[irq_index] = kmalloc(sizeof(struct device_attribute),
2866 if (!dev_attr[irq_index])
2869 event_name[irq_index] = kmalloc(count, GFP_KERNEL);
2870 if (!event_name[irq_index])
2873 sprintf(event_name[irq_index], "%lu", user_val);
2874 dev_attr[irq_index]->show = show_irq;
2875 dev_attr[irq_index]->store = NULL;
2876 dev_attr[irq_index]->attr.name = event_name[irq_index];
2877 dev_attr[irq_index]->attr.mode = S_IRUGO;
2878 err = sysfs_create_file(&dev->kobj, &dev_attr[irq_index]->attr);
2880 pr_info("sysfs_create_file failed %d\n", err);
2884 err = request_threaded_irq(user_val, NULL, ab8500_debug_handler,
2885 IRQF_SHARED | IRQF_NO_SUSPEND | IRQF_ONESHOT,
2886 "ab8500-debug", &dev->kobj);
2888 pr_info("request_threaded_irq failed %d, %lu\n",
2890 sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr);
2897 static ssize_t ab8500_unsubscribe_write(struct file *file,
2898 const char __user *user_buf,
2899 size_t count, loff_t *ppos)
2901 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2902 unsigned long user_val;
2904 unsigned int irq_index;
2906 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
2910 if (user_val < irq_first) {
2911 dev_err(dev, "debugfs error input < %d\n", irq_first);
2914 if (user_val > irq_last) {
2915 dev_err(dev, "debugfs error input > %d\n", irq_last);
2919 irq_index = user_val - irq_first;
2920 if (irq_index >= num_irqs)
2923 /* Set irq count to 0 when unsubscribe */
2924 irq_count[irq_index] = 0;
2926 if (dev_attr[irq_index])
2927 sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr);
2930 free_irq(user_val, &dev->kobj);
2931 kfree(event_name[irq_index]);
2932 kfree(dev_attr[irq_index]);
2938 * - several deubgfs nodes fops
2941 static const struct file_operations ab8500_bank_fops = {
2942 .open = ab8500_bank_open,
2943 .write = ab8500_bank_write,
2945 .llseek = seq_lseek,
2946 .release = single_release,
2947 .owner = THIS_MODULE,
2950 static const struct file_operations ab8500_address_fops = {
2951 .open = ab8500_address_open,
2952 .write = ab8500_address_write,
2954 .llseek = seq_lseek,
2955 .release = single_release,
2956 .owner = THIS_MODULE,
2959 static const struct file_operations ab8500_val_fops = {
2960 .open = ab8500_val_open,
2961 .write = ab8500_val_write,
2963 .llseek = seq_lseek,
2964 .release = single_release,
2965 .owner = THIS_MODULE,
2968 static const struct file_operations ab8500_interrupts_fops = {
2969 .open = ab8500_interrupts_open,
2971 .llseek = seq_lseek,
2972 .release = single_release,
2973 .owner = THIS_MODULE,
2976 static const struct file_operations ab8500_subscribe_fops = {
2977 .open = ab8500_subscribe_unsubscribe_open,
2978 .write = ab8500_subscribe_write,
2980 .llseek = seq_lseek,
2981 .release = single_release,
2982 .owner = THIS_MODULE,
2985 static const struct file_operations ab8500_unsubscribe_fops = {
2986 .open = ab8500_subscribe_unsubscribe_open,
2987 .write = ab8500_unsubscribe_write,
2989 .llseek = seq_lseek,
2990 .release = single_release,
2991 .owner = THIS_MODULE,
2994 static const struct file_operations ab8500_hwreg_fops = {
2995 .open = ab8500_hwreg_open,
2996 .write = ab8500_hwreg_write,
2998 .llseek = seq_lseek,
2999 .release = single_release,
3000 .owner = THIS_MODULE,
3003 static struct dentry *ab8500_dir;
3004 static struct dentry *ab8500_gpadc_dir;
3006 static int ab8500_debug_probe(struct platform_device *plf)
3008 struct dentry *file;
3009 struct ab8500 *ab8500;
3010 struct resource *res;
3012 debug_bank = AB8500_MISC;
3013 debug_address = AB8500_REV_REG & 0x00FF;
3015 ab8500 = dev_get_drvdata(plf->dev.parent);
3016 num_irqs = ab8500->mask_size;
3018 irq_count = devm_kzalloc(&plf->dev,
3019 sizeof(*irq_count)*num_irqs, GFP_KERNEL);
3023 dev_attr = devm_kzalloc(&plf->dev,
3024 sizeof(*dev_attr)*num_irqs, GFP_KERNEL);
3028 event_name = devm_kzalloc(&plf->dev,
3029 sizeof(*event_name)*num_irqs, GFP_KERNEL);
3033 res = platform_get_resource_byname(plf, 0, "IRQ_AB8500");
3035 dev_err(&plf->dev, "AB8500 irq not found, err %d\n", irq_first);
3038 irq_ab8500 = res->start;
3040 irq_first = platform_get_irq_byname(plf, "IRQ_FIRST");
3041 if (irq_first < 0) {
3042 dev_err(&plf->dev, "First irq not found, err %d\n", irq_first);
3046 irq_last = platform_get_irq_byname(plf, "IRQ_LAST");
3048 dev_err(&plf->dev, "Last irq not found, err %d\n", irq_last);
3052 ab8500_dir = debugfs_create_dir(AB8500_NAME_STRING, NULL);
3056 ab8500_gpadc_dir = debugfs_create_dir(AB8500_ADC_NAME_STRING,
3058 if (!ab8500_gpadc_dir)
3061 file = debugfs_create_file("all-bank-registers", S_IRUGO, ab8500_dir,
3062 &plf->dev, &ab8500_registers_fops);
3066 file = debugfs_create_file("all-banks", S_IRUGO, ab8500_dir,
3067 &plf->dev, &ab8500_all_banks_fops);
3071 file = debugfs_create_file("register-bank",
3072 (S_IRUGO | S_IWUSR | S_IWGRP),
3073 ab8500_dir, &plf->dev, &ab8500_bank_fops);
3077 file = debugfs_create_file("register-address",
3078 (S_IRUGO | S_IWUSR | S_IWGRP),
3079 ab8500_dir, &plf->dev, &ab8500_address_fops);
3083 file = debugfs_create_file("register-value",
3084 (S_IRUGO | S_IWUSR | S_IWGRP),
3085 ab8500_dir, &plf->dev, &ab8500_val_fops);
3089 file = debugfs_create_file("irq-subscribe",
3090 (S_IRUGO | S_IWUSR | S_IWGRP), ab8500_dir,
3091 &plf->dev, &ab8500_subscribe_fops);
3095 if (is_ab8500(ab8500)) {
3096 debug_ranges = ab8500_debug_ranges;
3097 num_interrupt_lines = AB8500_NR_IRQS;
3098 } else if (is_ab8505(ab8500)) {
3099 debug_ranges = ab8505_debug_ranges;
3100 num_interrupt_lines = AB8505_NR_IRQS;
3101 } else if (is_ab9540(ab8500)) {
3102 debug_ranges = ab8505_debug_ranges;
3103 num_interrupt_lines = AB9540_NR_IRQS;
3104 } else if (is_ab8540(ab8500)) {
3105 debug_ranges = ab8540_debug_ranges;
3106 num_interrupt_lines = AB8540_NR_IRQS;
3109 file = debugfs_create_file("interrupts", (S_IRUGO), ab8500_dir,
3110 &plf->dev, &ab8500_interrupts_fops);
3114 file = debugfs_create_file("irq-unsubscribe",
3115 (S_IRUGO | S_IWUSR | S_IWGRP), ab8500_dir,
3116 &plf->dev, &ab8500_unsubscribe_fops);
3120 file = debugfs_create_file("hwreg", (S_IRUGO | S_IWUSR | S_IWGRP),
3121 ab8500_dir, &plf->dev, &ab8500_hwreg_fops);
3125 file = debugfs_create_file("all-modem-registers",
3126 (S_IRUGO | S_IWUSR | S_IWGRP),
3127 ab8500_dir, &plf->dev, &ab8500_modem_fops);
3131 file = debugfs_create_file("bat_ctrl", (S_IRUGO | S_IWUSR | S_IWGRP),
3132 ab8500_gpadc_dir, &plf->dev,
3133 &ab8500_gpadc_bat_ctrl_fops);
3137 file = debugfs_create_file("btemp_ball", (S_IRUGO | S_IWUSR | S_IWGRP),
3139 &plf->dev, &ab8500_gpadc_btemp_ball_fops);
3143 file = debugfs_create_file("main_charger_v",
3144 (S_IRUGO | S_IWUSR | S_IWGRP),
3145 ab8500_gpadc_dir, &plf->dev,
3146 &ab8500_gpadc_main_charger_v_fops);
3150 file = debugfs_create_file("acc_detect1",
3151 (S_IRUGO | S_IWUSR | S_IWGRP),
3152 ab8500_gpadc_dir, &plf->dev,
3153 &ab8500_gpadc_acc_detect1_fops);
3157 file = debugfs_create_file("acc_detect2",
3158 (S_IRUGO | S_IWUSR | S_IWGRP),
3159 ab8500_gpadc_dir, &plf->dev,
3160 &ab8500_gpadc_acc_detect2_fops);
3164 file = debugfs_create_file("adc_aux1", (S_IRUGO | S_IWUSR | S_IWGRP),
3165 ab8500_gpadc_dir, &plf->dev,
3166 &ab8500_gpadc_aux1_fops);
3170 file = debugfs_create_file("adc_aux2", (S_IRUGO | S_IWUSR | S_IWGRP),
3171 ab8500_gpadc_dir, &plf->dev,
3172 &ab8500_gpadc_aux2_fops);
3176 file = debugfs_create_file("main_bat_v", (S_IRUGO | S_IWUSR | S_IWGRP),
3177 ab8500_gpadc_dir, &plf->dev,
3178 &ab8500_gpadc_main_bat_v_fops);
3182 file = debugfs_create_file("vbus_v", (S_IRUGO | S_IWUSR | S_IWGRP),
3183 ab8500_gpadc_dir, &plf->dev,
3184 &ab8500_gpadc_vbus_v_fops);
3188 file = debugfs_create_file("main_charger_c",
3189 (S_IRUGO | S_IWUSR | S_IWGRP),
3190 ab8500_gpadc_dir, &plf->dev,
3191 &ab8500_gpadc_main_charger_c_fops);
3195 file = debugfs_create_file("usb_charger_c",
3196 (S_IRUGO | S_IWUSR | S_IWGRP),
3198 &plf->dev, &ab8500_gpadc_usb_charger_c_fops);
3202 file = debugfs_create_file("bk_bat_v", (S_IRUGO | S_IWUSR | S_IWGRP),
3203 ab8500_gpadc_dir, &plf->dev,
3204 &ab8500_gpadc_bk_bat_v_fops);
3208 file = debugfs_create_file("die_temp", (S_IRUGO | S_IWUSR | S_IWGRP),
3209 ab8500_gpadc_dir, &plf->dev,
3210 &ab8500_gpadc_die_temp_fops);
3214 file = debugfs_create_file("usb_id", (S_IRUGO | S_IWUSR | S_IWGRP),
3215 ab8500_gpadc_dir, &plf->dev,
3216 &ab8500_gpadc_usb_id_fops);
3220 if (is_ab8540(ab8500)) {
3221 file = debugfs_create_file("xtal_temp",
3222 (S_IRUGO | S_IWUSR | S_IWGRP),
3223 ab8500_gpadc_dir, &plf->dev,
3224 &ab8540_gpadc_xtal_temp_fops);
3227 file = debugfs_create_file("vbattruemeas",
3228 (S_IRUGO | S_IWUSR | S_IWGRP),
3229 ab8500_gpadc_dir, &plf->dev,
3230 &ab8540_gpadc_vbat_true_meas_fops);
3233 file = debugfs_create_file("batctrl_and_ibat",
3234 (S_IRUGO | S_IWUGO),
3237 &ab8540_gpadc_bat_ctrl_and_ibat_fops);
3240 file = debugfs_create_file("vbatmeas_and_ibat",
3241 (S_IRUGO | S_IWUGO),
3242 ab8500_gpadc_dir, &plf->dev,
3243 &ab8540_gpadc_vbat_meas_and_ibat_fops);
3246 file = debugfs_create_file("vbattruemeas_and_ibat",
3247 (S_IRUGO | S_IWUGO),
3250 &ab8540_gpadc_vbat_true_meas_and_ibat_fops);
3253 file = debugfs_create_file("battemp_and_ibat",
3254 (S_IRUGO | S_IWUGO),
3256 &plf->dev, &ab8540_gpadc_bat_temp_and_ibat_fops);
3259 file = debugfs_create_file("otp_calib",
3260 (S_IRUGO | S_IWUSR | S_IWGRP),
3262 &plf->dev, &ab8540_gpadc_otp_calib_fops);
3266 file = debugfs_create_file("avg_sample", (S_IRUGO | S_IWUSR | S_IWGRP),
3267 ab8500_gpadc_dir, &plf->dev,
3268 &ab8500_gpadc_avg_sample_fops);
3272 file = debugfs_create_file("trig_edge", (S_IRUGO | S_IWUSR | S_IWGRP),
3273 ab8500_gpadc_dir, &plf->dev,
3274 &ab8500_gpadc_trig_edge_fops);
3278 file = debugfs_create_file("trig_timer", (S_IRUGO | S_IWUSR | S_IWGRP),
3279 ab8500_gpadc_dir, &plf->dev,
3280 &ab8500_gpadc_trig_timer_fops);
3284 file = debugfs_create_file("conv_type", (S_IRUGO | S_IWUSR | S_IWGRP),
3285 ab8500_gpadc_dir, &plf->dev,
3286 &ab8500_gpadc_conv_type_fops);
3293 debugfs_remove_recursive(ab8500_dir);
3294 dev_err(&plf->dev, "failed to create debugfs entries.\n");
3299 static int ab8500_debug_remove(struct platform_device *plf)
3301 debugfs_remove_recursive(ab8500_dir);
3306 static struct platform_driver ab8500_debug_driver = {
3308 .name = "ab8500-debug",
3310 .probe = ab8500_debug_probe,
3311 .remove = ab8500_debug_remove
3314 static int __init ab8500_debug_init(void)
3316 return platform_driver_register(&ab8500_debug_driver);
3319 static void __exit ab8500_debug_exit(void)
3321 platform_driver_unregister(&ab8500_debug_driver);
3323 subsys_initcall(ab8500_debug_init);
3324 module_exit(ab8500_debug_exit);
3326 MODULE_AUTHOR("Mattias WALLIN <mattias.wallin@stericsson.com");
3327 MODULE_DESCRIPTION("AB8500 DEBUG");
3328 MODULE_LICENSE("GPL v2");