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 /* TODO: this file should not reference IRQ_DB8500_AB8500! */
95 #include <mach/irqs.h>
97 static u32 debug_bank;
98 static u32 debug_address;
100 static int irq_first;
102 static u32 *irq_count;
105 static struct device_attribute **dev_attr;
106 static char **event_name;
108 static u8 avg_sample = SAMPLE_16;
109 static u8 trig_edge = RISING_EDGE;
110 static u8 conv_type = ADC_SW;
111 static u8 trig_timer;
114 * struct ab8500_reg_range
115 * @first: the first address of the range
116 * @last: the last address of the range
117 * @perm: access permissions for the range
119 struct ab8500_reg_range {
126 * struct ab8500_prcmu_ranges
127 * @num_ranges: the number of ranges in the list
128 * @bankid: bank identifier
129 * @range: the list of register ranges
131 struct ab8500_prcmu_ranges {
134 const struct ab8500_reg_range *range;
137 /* hwreg- "mask" and "shift" entries ressources */
139 u32 bank; /* target bank */
140 u32 addr; /* target address */
141 uint fmt; /* format */
142 uint mask; /* read/write mask, applied before any bit shift */
143 int shift; /* bit shift (read:right shift, write:left shift */
145 /* fmt bit #0: 0=hexa, 1=dec */
146 #define REG_FMT_DEC(c) ((c)->fmt & 0x1)
147 #define REG_FMT_HEX(c) (!REG_FMT_DEC(c))
149 static struct hwreg_cfg hwreg_cfg = {
150 .addr = 0, /* default: invalid phys addr */
151 .fmt = 0, /* default: 32bit access, hex output */
152 .mask = 0xFFFFFFFF, /* default: no mask */
153 .shift = 0, /* default: no bit shift */
156 #define AB8500_NAME_STRING "ab8500"
157 #define AB8500_ADC_NAME_STRING "gpadc"
158 #define AB8500_NUM_BANKS 24
160 #define AB8500_REV_REG 0x80
162 static struct ab8500_prcmu_ranges *debug_ranges;
164 struct ab8500_prcmu_ranges ab8500_debug_ranges[AB8500_NUM_BANKS] = {
169 [AB8500_SYS_CTRL1_BLOCK] = {
171 .range = (struct ab8500_reg_range[]) {
186 [AB8500_SYS_CTRL2_BLOCK] = {
188 .range = (struct ab8500_reg_range[]) {
207 [AB8500_REGU_CTRL1] = {
209 .range = (struct ab8500_reg_range[]) {
224 [AB8500_REGU_CTRL2] = {
226 .range = (struct ab8500_reg_range[]) {
247 /* 0x80-0x8B is SIM registers and should
248 * 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[]) {
324 .range = (struct ab8500_reg_range[]) {
333 .range = (struct ab8500_reg_range[]) {
372 [AB8500_GAS_GAUGE] = {
374 .range = (struct ab8500_reg_range[]) {
389 [AB8500_DEVELOPMENT] = {
391 .range = (struct ab8500_reg_range[]) {
400 .range = (struct ab8500_reg_range[]) {
409 .range = (struct ab8500_reg_range[]) {
416 [AB8500_INTERRUPT] = {
422 .range = (struct ab8500_reg_range[]) {
431 .range = (struct ab8500_reg_range[]) {
482 [AB8500_OTP_EMUL] = {
484 .range = (struct ab8500_reg_range[]) {
493 struct ab8500_prcmu_ranges ab8505_debug_ranges[AB8500_NUM_BANKS] = {
498 [AB8500_SYS_CTRL1_BLOCK] = {
500 .range = (struct ab8500_reg_range[]) {
523 [AB8500_SYS_CTRL2_BLOCK] = {
525 .range = (struct ab8500_reg_range[]) {
548 [AB8500_REGU_CTRL1] = {
550 .range = (struct ab8500_reg_range[]) {
565 [AB8500_REGU_CTRL2] = {
567 .range = (struct ab8500_reg_range[]) {
592 /* 0x80-0x8B is SIM registers and should
593 * not be accessed from here */
598 .range = (struct ab8500_reg_range[]) {
621 [AB8500_ECI_AV_ACC] = {
623 .range = (struct ab8500_reg_range[]) {
630 [AB8500_RESERVED] = {
636 .range = (struct ab8500_reg_range[]) {
645 .range = (struct ab8500_reg_range[]) {
684 [AB8500_GAS_GAUGE] = {
686 .range = (struct ab8500_reg_range[]) {
703 .range = (struct ab8500_reg_range[]) {
710 [AB8500_INTERRUPT] = {
712 .range = (struct ab8500_reg_range[]) {
737 /* Latch registers should not be read here */
758 /* LatchHier registers should not be read here */
763 .range = (struct ab8500_reg_range[]) {
776 .range = (struct ab8500_reg_range[]) {
811 [AB8500_DEVELOPMENT] = {
813 .range = (struct ab8500_reg_range[]) {
826 .range = (struct ab8500_reg_range[]) {
833 [AB8500_PROD_TEST] = {
837 [AB8500_STE_TEST] = {
841 [AB8500_OTP_EMUL] = {
843 .range = (struct ab8500_reg_range[]) {
852 struct ab8500_prcmu_ranges ab8540_debug_ranges[AB8500_NUM_BANKS] = {
853 [AB8500_M_FSM_RANK] = {
855 .range = (struct ab8500_reg_range[]) {
862 [AB8500_SYS_CTRL1_BLOCK] = {
864 .range = (struct ab8500_reg_range[]) {
891 [AB8500_SYS_CTRL2_BLOCK] = {
893 .range = (struct ab8500_reg_range[]) {
916 [AB8500_REGU_CTRL1] = {
918 .range = (struct ab8500_reg_range[]) {
937 [AB8500_REGU_CTRL2] = {
939 .range = (struct ab8500_reg_range[]) {
976 .range = (struct ab8500_reg_range[]) {
997 .range = (struct ab8500_reg_range[]) {
1016 [AB8500_ECI_AV_ACC] = {
1018 .range = (struct ab8500_reg_range[]) {
1029 [AB8500_RESERVED] = {
1035 .range = (struct ab8500_reg_range[]) {
1054 [AB8500_CHARGER] = {
1056 .range = (struct ab8500_reg_range[]) {
1099 [AB8500_GAS_GAUGE] = {
1101 .range = (struct ab8500_reg_range[]) {
1118 .range = (struct ab8500_reg_range[]) {
1125 [AB8500_INTERRUPT] = {
1127 .range = (struct ab8500_reg_range[]) {
1140 /* Latch registers should not be read here */
1153 /* LatchHier registers should not be read here */
1158 .range = (struct ab8500_reg_range[]) {
1175 .range = (struct ab8500_reg_range[]) {
1214 [AB8500_DEVELOPMENT] = {
1216 .range = (struct ab8500_reg_range[]) {
1233 .range = (struct ab8500_reg_range[]) {
1248 [AB8500_PROD_TEST] = {
1252 [AB8500_STE_TEST] = {
1256 [AB8500_OTP_EMUL] = {
1258 .range = (struct ab8500_reg_range[]) {
1268 static irqreturn_t ab8500_debug_handler(int irq, void *data)
1271 struct kobject *kobj = (struct kobject *)data;
1272 unsigned int irq_abb = irq - irq_first;
1274 if (irq_abb < num_irqs)
1275 irq_count[irq_abb]++;
1277 * This makes it possible to use poll for events (POLLPRI | POLLERR)
1278 * from userspace on sysfs file named <irq-nr>
1280 sprintf(buf, "%d", irq);
1281 sysfs_notify(kobj, NULL, buf);
1286 /* Prints to seq_file or log_buf */
1287 static int ab8500_registers_print(struct device *dev, u32 bank,
1292 for (i = 0; i < debug_ranges[bank].num_ranges; i++) {
1295 for (reg = debug_ranges[bank].range[i].first;
1296 reg <= debug_ranges[bank].range[i].last;
1301 err = abx500_get_register_interruptible(dev,
1302 (u8)bank, (u8)reg, &value);
1304 dev_err(dev, "ab->read fail %d\n", err);
1309 err = seq_printf(s, " [0x%02X/0x%02X]: 0x%02X\n",
1312 /* Error is not returned here since
1313 * the output is wanted in any case */
1317 printk(KERN_INFO" [0x%02X/0x%02X]: 0x%02X\n",
1325 static int ab8500_print_bank_registers(struct seq_file *s, void *p)
1327 struct device *dev = s->private;
1328 u32 bank = debug_bank;
1330 seq_printf(s, AB8500_NAME_STRING " register values:\n");
1332 seq_printf(s, " bank 0x%02X:\n", bank);
1334 ab8500_registers_print(dev, bank, s);
1338 static int ab8500_registers_open(struct inode *inode, struct file *file)
1340 return single_open(file, ab8500_print_bank_registers, inode->i_private);
1343 static const struct file_operations ab8500_registers_fops = {
1344 .open = ab8500_registers_open,
1346 .llseek = seq_lseek,
1347 .release = single_release,
1348 .owner = THIS_MODULE,
1351 static int ab8500_print_all_banks(struct seq_file *s, void *p)
1353 struct device *dev = s->private;
1357 seq_printf(s, AB8500_NAME_STRING " register values:\n");
1359 for (i = 0; i < AB8500_NUM_BANKS; i++) {
1360 err = seq_printf(s, " bank 0x%02X:\n", i);
1362 ab8500_registers_print(dev, i, s);
1367 /* Dump registers to kernel log */
1368 void ab8500_dump_all_banks(struct device *dev)
1372 printk(KERN_INFO"ab8500 register values:\n");
1374 for (i = 1; i < AB8500_NUM_BANKS; i++) {
1375 printk(KERN_INFO" bank 0x%02X:\n", i);
1376 ab8500_registers_print(dev, i, NULL);
1380 /* Space for 500 registers. */
1381 #define DUMP_MAX_REGS 700
1382 struct ab8500_register_dump
1387 } ab8500_complete_register_dump[DUMP_MAX_REGS];
1389 extern int prcmu_abb_read(u8 slave, u8 reg, u8 *value, u8 size);
1391 /* This shall only be called upon kernel panic! */
1392 void ab8500_dump_all_banks_to_mem(void)
1398 pr_info("Saving all ABB registers at \"ab8500_complete_register_dump\" "
1399 "for crash analyze.\n");
1401 for (bank = 0; bank < AB8500_NUM_BANKS; bank++) {
1402 for (i = 0; i < debug_ranges[bank].num_ranges; i++) {
1405 for (reg = debug_ranges[bank].range[i].first;
1406 reg <= debug_ranges[bank].range[i].last;
1410 err = prcmu_abb_read(bank, reg, &value, 1);
1415 ab8500_complete_register_dump[r].bank = bank;
1416 ab8500_complete_register_dump[r].reg = reg;
1417 ab8500_complete_register_dump[r].value = value;
1421 if (r >= DUMP_MAX_REGS) {
1422 pr_err("%s: too many register to dump!\n",
1432 pr_info("Saved all ABB registers.\n");
1434 pr_info("Failed to save all ABB registers.\n");
1437 static int ab8500_all_banks_open(struct inode *inode, struct file *file)
1442 err = single_open(file, ab8500_print_all_banks, inode->i_private);
1444 /* Default buf size in seq_read is not enough */
1445 s = (struct seq_file *)file->private_data;
1446 s->size = (PAGE_SIZE * 2);
1447 s->buf = kmalloc(s->size, GFP_KERNEL);
1449 single_release(inode, file);
1456 static const struct file_operations ab8500_all_banks_fops = {
1457 .open = ab8500_all_banks_open,
1459 .llseek = seq_lseek,
1460 .release = single_release,
1461 .owner = THIS_MODULE,
1464 static int ab8500_bank_print(struct seq_file *s, void *p)
1466 return seq_printf(s, "0x%02X\n", debug_bank);
1469 static int ab8500_bank_open(struct inode *inode, struct file *file)
1471 return single_open(file, ab8500_bank_print, inode->i_private);
1474 static ssize_t ab8500_bank_write(struct file *file,
1475 const char __user *user_buf,
1476 size_t count, loff_t *ppos)
1478 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1479 unsigned long user_bank;
1482 err = kstrtoul_from_user(user_buf, count, 0, &user_bank);
1486 if (user_bank >= AB8500_NUM_BANKS) {
1487 dev_err(dev, "debugfs error input > number of banks\n");
1491 debug_bank = user_bank;
1496 static int ab8500_address_print(struct seq_file *s, void *p)
1498 return seq_printf(s, "0x%02X\n", debug_address);
1501 static int ab8500_address_open(struct inode *inode, struct file *file)
1503 return single_open(file, ab8500_address_print, inode->i_private);
1506 static ssize_t ab8500_address_write(struct file *file,
1507 const char __user *user_buf,
1508 size_t count, loff_t *ppos)
1510 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1511 unsigned long user_address;
1514 err = kstrtoul_from_user(user_buf, count, 0, &user_address);
1518 if (user_address > 0xff) {
1519 dev_err(dev, "debugfs error input > 0xff\n");
1522 debug_address = user_address;
1527 static int ab8500_val_print(struct seq_file *s, void *p)
1529 struct device *dev = s->private;
1533 ret = abx500_get_register_interruptible(dev,
1534 (u8)debug_bank, (u8)debug_address, ®value);
1536 dev_err(dev, "abx500_get_reg fail %d, %d\n",
1540 seq_printf(s, "0x%02X\n", regvalue);
1545 static int ab8500_val_open(struct inode *inode, struct file *file)
1547 return single_open(file, ab8500_val_print, inode->i_private);
1550 static ssize_t ab8500_val_write(struct file *file,
1551 const char __user *user_buf,
1552 size_t count, loff_t *ppos)
1554 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1555 unsigned long user_val;
1558 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
1562 if (user_val > 0xff) {
1563 dev_err(dev, "debugfs error input > 0xff\n");
1566 err = abx500_set_register_interruptible(dev,
1567 (u8)debug_bank, debug_address, (u8)user_val);
1569 printk(KERN_ERR "abx500_set_reg failed %d, %d", err, __LINE__);
1579 static u32 num_interrupts[AB8500_MAX_NR_IRQS];
1580 static u32 num_wake_interrupts[AB8500_MAX_NR_IRQS];
1581 static int num_interrupt_lines;
1583 bool __attribute__((weak)) suspend_test_wake_cause_interrupt_is_mine(u32 my_int)
1588 void ab8500_debug_register_interrupt(int line)
1590 if (line < num_interrupt_lines) {
1591 num_interrupts[line]++;
1592 if (suspend_test_wake_cause_interrupt_is_mine(IRQ_DB8500_AB8500))
1593 num_wake_interrupts[line]++;
1597 static int ab8500_interrupts_print(struct seq_file *s, void *p)
1601 seq_printf(s, "name: number: number of: wake:\n");
1603 for (line = 0; line < num_interrupt_lines; line++) {
1604 struct irq_desc *desc = irq_to_desc(line + irq_first);
1605 struct irqaction *action = desc->action;
1607 seq_printf(s, "%3i: %6i %4i", line,
1608 num_interrupts[line],
1609 num_wake_interrupts[line]);
1611 if (desc && desc->name)
1612 seq_printf(s, "-%-8s", desc->name);
1614 seq_printf(s, " %s", action->name);
1615 while ((action = action->next) != NULL)
1616 seq_printf(s, ", %s", action->name);
1624 static int ab8500_interrupts_open(struct inode *inode, struct file *file)
1626 return single_open(file, ab8500_interrupts_print, inode->i_private);
1630 * - HWREG DB8500 formated routines
1632 static int ab8500_hwreg_print(struct seq_file *s, void *d)
1634 struct device *dev = s->private;
1638 ret = abx500_get_register_interruptible(dev,
1639 (u8)hwreg_cfg.bank, (u8)hwreg_cfg.addr, ®value);
1641 dev_err(dev, "abx500_get_reg fail %d, %d\n",
1646 if (hwreg_cfg.shift >= 0)
1647 regvalue >>= hwreg_cfg.shift;
1649 regvalue <<= -hwreg_cfg.shift;
1650 regvalue &= hwreg_cfg.mask;
1652 if (REG_FMT_DEC(&hwreg_cfg))
1653 seq_printf(s, "%d\n", regvalue);
1655 seq_printf(s, "0x%02X\n", regvalue);
1659 static int ab8500_hwreg_open(struct inode *inode, struct file *file)
1661 return single_open(file, ab8500_hwreg_print, inode->i_private);
1664 #define AB8500_SUPPLY_CONTROL_CONFIG_1 0x01
1665 #define AB8500_SUPPLY_CONTROL_REG 0x00
1666 #define AB8500_FIRST_SIM_REG 0x80
1667 #define AB8500_LAST_SIM_REG 0x8B
1668 #define AB8505_LAST_SIM_REG 0x8C
1670 static int ab8500_print_modem_registers(struct seq_file *s, void *p)
1672 struct device *dev = s->private;
1673 struct ab8500 *ab8500;
1677 u32 bank = AB8500_REGU_CTRL2;
1678 u32 last_sim_reg = AB8500_LAST_SIM_REG;
1681 ab8500 = dev_get_drvdata(dev->parent);
1682 dev_warn(dev, "WARNING! This operation can interfer with modem side\n"
1683 "and should only be done with care\n");
1685 err = abx500_get_register_interruptible(dev,
1686 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG, &orig_value);
1688 dev_err(dev, "ab->read fail %d\n", err);
1691 /* Config 1 will allow APE side to read SIM registers */
1692 err = abx500_set_register_interruptible(dev,
1693 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG,
1694 AB8500_SUPPLY_CONTROL_CONFIG_1);
1696 dev_err(dev, "ab->write fail %d\n", err);
1700 seq_printf(s, " bank 0x%02X:\n", bank);
1702 if (is_ab9540(ab8500) || is_ab8505(ab8500))
1703 last_sim_reg = AB8505_LAST_SIM_REG;
1705 for (reg = AB8500_FIRST_SIM_REG; reg <= last_sim_reg; reg++) {
1706 err = abx500_get_register_interruptible(dev,
1709 dev_err(dev, "ab->read fail %d\n", err);
1712 err = seq_printf(s, " [0x%02X/0x%02X]: 0x%02X\n",
1715 err = abx500_set_register_interruptible(dev,
1716 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG, orig_value);
1718 dev_err(dev, "ab->write fail %d\n", err);
1724 static int ab8500_modem_open(struct inode *inode, struct file *file)
1726 return single_open(file, ab8500_print_modem_registers, inode->i_private);
1729 static const struct file_operations ab8500_modem_fops = {
1730 .open = ab8500_modem_open,
1732 .llseek = seq_lseek,
1733 .release = single_release,
1734 .owner = THIS_MODULE,
1737 static int ab8500_gpadc_bat_ctrl_print(struct seq_file *s, void *p)
1740 int bat_ctrl_convert;
1741 struct ab8500_gpadc *gpadc;
1743 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1744 bat_ctrl_raw = ab8500_gpadc_read_raw(gpadc, BAT_CTRL,
1745 avg_sample, trig_edge, trig_timer, conv_type);
1746 bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc,
1747 BAT_CTRL, bat_ctrl_raw);
1749 return seq_printf(s, "%d,0x%X\n",
1750 bat_ctrl_convert, bat_ctrl_raw);
1753 static int ab8500_gpadc_bat_ctrl_open(struct inode *inode, struct file *file)
1755 return single_open(file, ab8500_gpadc_bat_ctrl_print, inode->i_private);
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 return seq_printf(s,
1779 "%d,0x%X\n", btemp_ball_convert, btemp_ball_raw);
1782 static int ab8500_gpadc_btemp_ball_open(struct inode *inode,
1785 return single_open(file, ab8500_gpadc_btemp_ball_print, inode->i_private);
1788 static const struct file_operations ab8500_gpadc_btemp_ball_fops = {
1789 .open = ab8500_gpadc_btemp_ball_open,
1791 .llseek = seq_lseek,
1792 .release = single_release,
1793 .owner = THIS_MODULE,
1796 static int ab8500_gpadc_main_charger_v_print(struct seq_file *s, void *p)
1798 int main_charger_v_raw;
1799 int main_charger_v_convert;
1800 struct ab8500_gpadc *gpadc;
1802 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1803 main_charger_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_V,
1804 avg_sample, trig_edge, trig_timer, conv_type);
1805 main_charger_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
1806 MAIN_CHARGER_V, main_charger_v_raw);
1808 return seq_printf(s, "%d,0x%X\n",
1809 main_charger_v_convert, main_charger_v_raw);
1812 static int ab8500_gpadc_main_charger_v_open(struct inode *inode,
1815 return single_open(file, ab8500_gpadc_main_charger_v_print,
1819 static const struct file_operations ab8500_gpadc_main_charger_v_fops = {
1820 .open = ab8500_gpadc_main_charger_v_open,
1822 .llseek = seq_lseek,
1823 .release = single_release,
1824 .owner = THIS_MODULE,
1827 static int ab8500_gpadc_acc_detect1_print(struct seq_file *s, void *p)
1829 int acc_detect1_raw;
1830 int acc_detect1_convert;
1831 struct ab8500_gpadc *gpadc;
1833 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1834 acc_detect1_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT1,
1835 avg_sample, trig_edge, trig_timer, conv_type);
1836 acc_detect1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ACC_DETECT1,
1839 return seq_printf(s, "%d,0x%X\n",
1840 acc_detect1_convert, acc_detect1_raw);
1843 static int ab8500_gpadc_acc_detect1_open(struct inode *inode,
1846 return single_open(file, ab8500_gpadc_acc_detect1_print,
1850 static const struct file_operations ab8500_gpadc_acc_detect1_fops = {
1851 .open = ab8500_gpadc_acc_detect1_open,
1853 .llseek = seq_lseek,
1854 .release = single_release,
1855 .owner = THIS_MODULE,
1858 static int ab8500_gpadc_acc_detect2_print(struct seq_file *s, void *p)
1860 int acc_detect2_raw;
1861 int acc_detect2_convert;
1862 struct ab8500_gpadc *gpadc;
1864 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1865 acc_detect2_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT2,
1866 avg_sample, trig_edge, trig_timer, conv_type);
1867 acc_detect2_convert = ab8500_gpadc_ad_to_voltage(gpadc,
1868 ACC_DETECT2, acc_detect2_raw);
1870 return seq_printf(s, "%d,0x%X\n",
1871 acc_detect2_convert, acc_detect2_raw);
1874 static int ab8500_gpadc_acc_detect2_open(struct inode *inode,
1877 return single_open(file, ab8500_gpadc_acc_detect2_print,
1881 static const struct file_operations ab8500_gpadc_acc_detect2_fops = {
1882 .open = ab8500_gpadc_acc_detect2_open,
1884 .llseek = seq_lseek,
1885 .release = single_release,
1886 .owner = THIS_MODULE,
1889 static int ab8500_gpadc_aux1_print(struct seq_file *s, void *p)
1893 struct ab8500_gpadc *gpadc;
1895 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1896 aux1_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX1,
1897 avg_sample, trig_edge, trig_timer, conv_type);
1898 aux1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX1,
1901 return seq_printf(s, "%d,0x%X\n",
1902 aux1_convert, aux1_raw);
1905 static int ab8500_gpadc_aux1_open(struct inode *inode, struct file *file)
1907 return single_open(file, ab8500_gpadc_aux1_print, inode->i_private);
1910 static const struct file_operations ab8500_gpadc_aux1_fops = {
1911 .open = ab8500_gpadc_aux1_open,
1913 .llseek = seq_lseek,
1914 .release = single_release,
1915 .owner = THIS_MODULE,
1918 static int ab8500_gpadc_aux2_print(struct seq_file *s, void *p)
1922 struct ab8500_gpadc *gpadc;
1924 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1925 aux2_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX2,
1926 avg_sample, trig_edge, trig_timer, conv_type);
1927 aux2_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX2,
1930 return seq_printf(s, "%d,0x%X\n",
1931 aux2_convert, aux2_raw);
1934 static int ab8500_gpadc_aux2_open(struct inode *inode, struct file *file)
1936 return single_open(file, ab8500_gpadc_aux2_print, inode->i_private);
1939 static const struct file_operations ab8500_gpadc_aux2_fops = {
1940 .open = ab8500_gpadc_aux2_open,
1942 .llseek = seq_lseek,
1943 .release = single_release,
1944 .owner = THIS_MODULE,
1947 static int ab8500_gpadc_main_bat_v_print(struct seq_file *s, void *p)
1950 int main_bat_v_convert;
1951 struct ab8500_gpadc *gpadc;
1953 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1954 main_bat_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_BAT_V,
1955 avg_sample, trig_edge, trig_timer, conv_type);
1956 main_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V,
1959 return seq_printf(s, "%d,0x%X\n",
1960 main_bat_v_convert, main_bat_v_raw);
1963 static int ab8500_gpadc_main_bat_v_open(struct inode *inode,
1966 return single_open(file, ab8500_gpadc_main_bat_v_print, inode->i_private);
1969 static const struct file_operations ab8500_gpadc_main_bat_v_fops = {
1970 .open = ab8500_gpadc_main_bat_v_open,
1972 .llseek = seq_lseek,
1973 .release = single_release,
1974 .owner = THIS_MODULE,
1977 static int ab8500_gpadc_vbus_v_print(struct seq_file *s, void *p)
1981 struct ab8500_gpadc *gpadc;
1983 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1984 vbus_v_raw = ab8500_gpadc_read_raw(gpadc, VBUS_V,
1985 avg_sample, trig_edge, trig_timer, conv_type);
1986 vbus_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, VBUS_V,
1989 return seq_printf(s, "%d,0x%X\n",
1990 vbus_v_convert, vbus_v_raw);
1993 static int ab8500_gpadc_vbus_v_open(struct inode *inode, struct file *file)
1995 return single_open(file, ab8500_gpadc_vbus_v_print, inode->i_private);
1998 static const struct file_operations ab8500_gpadc_vbus_v_fops = {
1999 .open = ab8500_gpadc_vbus_v_open,
2001 .llseek = seq_lseek,
2002 .release = single_release,
2003 .owner = THIS_MODULE,
2006 static int ab8500_gpadc_main_charger_c_print(struct seq_file *s, void *p)
2008 int main_charger_c_raw;
2009 int main_charger_c_convert;
2010 struct ab8500_gpadc *gpadc;
2012 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2013 main_charger_c_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_C,
2014 avg_sample, trig_edge, trig_timer, conv_type);
2015 main_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
2016 MAIN_CHARGER_C, main_charger_c_raw);
2018 return seq_printf(s, "%d,0x%X\n",
2019 main_charger_c_convert, main_charger_c_raw);
2022 static int ab8500_gpadc_main_charger_c_open(struct inode *inode,
2025 return single_open(file, ab8500_gpadc_main_charger_c_print,
2029 static const struct file_operations ab8500_gpadc_main_charger_c_fops = {
2030 .open = ab8500_gpadc_main_charger_c_open,
2032 .llseek = seq_lseek,
2033 .release = single_release,
2034 .owner = THIS_MODULE,
2037 static int ab8500_gpadc_usb_charger_c_print(struct seq_file *s, void *p)
2039 int usb_charger_c_raw;
2040 int usb_charger_c_convert;
2041 struct ab8500_gpadc *gpadc;
2043 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2044 usb_charger_c_raw = ab8500_gpadc_read_raw(gpadc, USB_CHARGER_C,
2045 avg_sample, trig_edge, trig_timer, conv_type);
2046 usb_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
2047 USB_CHARGER_C, usb_charger_c_raw);
2049 return seq_printf(s, "%d,0x%X\n",
2050 usb_charger_c_convert, usb_charger_c_raw);
2053 static int ab8500_gpadc_usb_charger_c_open(struct inode *inode,
2056 return single_open(file, ab8500_gpadc_usb_charger_c_print,
2060 static const struct file_operations ab8500_gpadc_usb_charger_c_fops = {
2061 .open = ab8500_gpadc_usb_charger_c_open,
2063 .llseek = seq_lseek,
2064 .release = single_release,
2065 .owner = THIS_MODULE,
2068 static int ab8500_gpadc_bk_bat_v_print(struct seq_file *s, void *p)
2071 int bk_bat_v_convert;
2072 struct ab8500_gpadc *gpadc;
2074 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2075 bk_bat_v_raw = ab8500_gpadc_read_raw(gpadc, BK_BAT_V,
2076 avg_sample, trig_edge, trig_timer, conv_type);
2077 bk_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
2078 BK_BAT_V, bk_bat_v_raw);
2080 return seq_printf(s, "%d,0x%X\n",
2081 bk_bat_v_convert, bk_bat_v_raw);
2084 static int ab8500_gpadc_bk_bat_v_open(struct inode *inode, struct file *file)
2086 return single_open(file, ab8500_gpadc_bk_bat_v_print, inode->i_private);
2089 static const struct file_operations ab8500_gpadc_bk_bat_v_fops = {
2090 .open = ab8500_gpadc_bk_bat_v_open,
2092 .llseek = seq_lseek,
2093 .release = single_release,
2094 .owner = THIS_MODULE,
2097 static int ab8500_gpadc_die_temp_print(struct seq_file *s, void *p)
2100 int die_temp_convert;
2101 struct ab8500_gpadc *gpadc;
2103 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2104 die_temp_raw = ab8500_gpadc_read_raw(gpadc, DIE_TEMP,
2105 avg_sample, trig_edge, trig_timer, conv_type);
2106 die_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, DIE_TEMP,
2109 return seq_printf(s, "%d,0x%X\n",
2110 die_temp_convert, die_temp_raw);
2113 static int ab8500_gpadc_die_temp_open(struct inode *inode, struct file *file)
2115 return single_open(file, ab8500_gpadc_die_temp_print, inode->i_private);
2118 static const struct file_operations ab8500_gpadc_die_temp_fops = {
2119 .open = ab8500_gpadc_die_temp_open,
2121 .llseek = seq_lseek,
2122 .release = single_release,
2123 .owner = THIS_MODULE,
2126 static int ab8500_gpadc_usb_id_print(struct seq_file *s, void *p)
2130 struct ab8500_gpadc *gpadc;
2132 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2133 usb_id_raw = ab8500_gpadc_read_raw(gpadc, USB_ID,
2134 avg_sample, trig_edge, trig_timer, conv_type);
2135 usb_id_convert = ab8500_gpadc_ad_to_voltage(gpadc, USB_ID,
2138 return seq_printf(s, "%d,0x%X\n",
2139 usb_id_convert, usb_id_raw);
2142 static int ab8500_gpadc_usb_id_open(struct inode *inode, struct file *file)
2144 return single_open(file, ab8500_gpadc_usb_id_print, inode->i_private);
2147 static const struct file_operations ab8500_gpadc_usb_id_fops = {
2148 .open = ab8500_gpadc_usb_id_open,
2150 .llseek = seq_lseek,
2151 .release = single_release,
2152 .owner = THIS_MODULE,
2155 static int ab8540_gpadc_xtal_temp_print(struct seq_file *s, void *p)
2158 int xtal_temp_convert;
2159 struct ab8500_gpadc *gpadc;
2161 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2162 xtal_temp_raw = ab8500_gpadc_read_raw(gpadc, XTAL_TEMP,
2163 avg_sample, trig_edge, trig_timer, conv_type);
2164 xtal_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, XTAL_TEMP,
2167 return seq_printf(s, "%d,0x%X\n",
2168 xtal_temp_convert, xtal_temp_raw);
2171 static int ab8540_gpadc_xtal_temp_open(struct inode *inode, struct file *file)
2173 return single_open(file, ab8540_gpadc_xtal_temp_print,
2177 static const struct file_operations ab8540_gpadc_xtal_temp_fops = {
2178 .open = ab8540_gpadc_xtal_temp_open,
2180 .llseek = seq_lseek,
2181 .release = single_release,
2182 .owner = THIS_MODULE,
2185 static int ab8540_gpadc_vbat_true_meas_print(struct seq_file *s, void *p)
2187 int vbat_true_meas_raw;
2188 int vbat_true_meas_convert;
2189 struct ab8500_gpadc *gpadc;
2191 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2192 vbat_true_meas_raw = ab8500_gpadc_read_raw(gpadc, VBAT_TRUE_MEAS,
2193 avg_sample, trig_edge, trig_timer, conv_type);
2194 vbat_true_meas_convert = ab8500_gpadc_ad_to_voltage(gpadc, VBAT_TRUE_MEAS,
2195 vbat_true_meas_raw);
2197 return seq_printf(s, "%d,0x%X\n",
2198 vbat_true_meas_convert, vbat_true_meas_raw);
2201 static int ab8540_gpadc_vbat_true_meas_open(struct inode *inode,
2204 return single_open(file, ab8540_gpadc_vbat_true_meas_print,
2208 static const struct file_operations ab8540_gpadc_vbat_true_meas_fops = {
2209 .open = ab8540_gpadc_vbat_true_meas_open,
2211 .llseek = seq_lseek,
2212 .release = single_release,
2213 .owner = THIS_MODULE,
2216 static int ab8540_gpadc_bat_ctrl_and_ibat_print(struct seq_file *s, void *p)
2219 int bat_ctrl_convert;
2222 struct ab8500_gpadc *gpadc;
2224 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2225 bat_ctrl_raw = ab8500_gpadc_double_read_raw(gpadc, BAT_CTRL_AND_IBAT,
2226 avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
2228 bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc, BAT_CTRL,
2230 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2233 return seq_printf(s, "%d,0x%X\n" "%d,0x%X\n",
2234 bat_ctrl_convert, bat_ctrl_raw,
2235 ibat_convert, ibat_raw);
2238 static int ab8540_gpadc_bat_ctrl_and_ibat_open(struct inode *inode,
2241 return single_open(file, ab8540_gpadc_bat_ctrl_and_ibat_print,
2245 static const struct file_operations ab8540_gpadc_bat_ctrl_and_ibat_fops = {
2246 .open = ab8540_gpadc_bat_ctrl_and_ibat_open,
2248 .llseek = seq_lseek,
2249 .release = single_release,
2250 .owner = THIS_MODULE,
2253 static int ab8540_gpadc_vbat_meas_and_ibat_print(struct seq_file *s, void *p)
2256 int vbat_meas_convert;
2259 struct ab8500_gpadc *gpadc;
2261 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2262 vbat_meas_raw = ab8500_gpadc_double_read_raw(gpadc, VBAT_MEAS_AND_IBAT,
2263 avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
2264 vbat_meas_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V,
2266 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2269 return seq_printf(s, "%d,0x%X\n" "%d,0x%X\n",
2270 vbat_meas_convert, vbat_meas_raw,
2271 ibat_convert, ibat_raw);
2274 static int ab8540_gpadc_vbat_meas_and_ibat_open(struct inode *inode,
2277 return single_open(file, ab8540_gpadc_vbat_meas_and_ibat_print,
2281 static const struct file_operations ab8540_gpadc_vbat_meas_and_ibat_fops = {
2282 .open = ab8540_gpadc_vbat_meas_and_ibat_open,
2284 .llseek = seq_lseek,
2285 .release = single_release,
2286 .owner = THIS_MODULE,
2289 static int ab8540_gpadc_vbat_true_meas_and_ibat_print(struct seq_file *s, void *p)
2291 int vbat_true_meas_raw;
2292 int vbat_true_meas_convert;
2295 struct ab8500_gpadc *gpadc;
2297 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2298 vbat_true_meas_raw = ab8500_gpadc_double_read_raw(gpadc,
2299 VBAT_TRUE_MEAS_AND_IBAT, avg_sample, trig_edge,
2300 trig_timer, conv_type, &ibat_raw);
2301 vbat_true_meas_convert = ab8500_gpadc_ad_to_voltage(gpadc,
2302 VBAT_TRUE_MEAS, vbat_true_meas_raw);
2303 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2306 return seq_printf(s, "%d,0x%X\n" "%d,0x%X\n",
2307 vbat_true_meas_convert, vbat_true_meas_raw,
2308 ibat_convert, ibat_raw);
2311 static int ab8540_gpadc_vbat_true_meas_and_ibat_open(struct inode *inode,
2314 return single_open(file, ab8540_gpadc_vbat_true_meas_and_ibat_print,
2318 static const struct file_operations ab8540_gpadc_vbat_true_meas_and_ibat_fops = {
2319 .open = ab8540_gpadc_vbat_true_meas_and_ibat_open,
2321 .llseek = seq_lseek,
2322 .release = single_release,
2323 .owner = THIS_MODULE,
2326 static int ab8540_gpadc_bat_temp_and_ibat_print(struct seq_file *s, void *p)
2329 int bat_temp_convert;
2332 struct ab8500_gpadc *gpadc;
2334 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2335 bat_temp_raw = ab8500_gpadc_double_read_raw(gpadc, BAT_TEMP_AND_IBAT,
2336 avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
2337 bat_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL,
2339 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2342 return seq_printf(s, "%d,0x%X\n" "%d,0x%X\n",
2343 bat_temp_convert, bat_temp_raw,
2344 ibat_convert, ibat_raw);
2347 static int ab8540_gpadc_bat_temp_and_ibat_open(struct inode *inode,
2350 return single_open(file, ab8540_gpadc_bat_temp_and_ibat_print,
2354 static const struct file_operations ab8540_gpadc_bat_temp_and_ibat_fops = {
2355 .open = ab8540_gpadc_bat_temp_and_ibat_open,
2357 .llseek = seq_lseek,
2358 .release = single_release,
2359 .owner = THIS_MODULE,
2362 static int ab8540_gpadc_otp_cal_print(struct seq_file *s, void *p)
2364 struct ab8500_gpadc *gpadc;
2365 u16 vmain_l, vmain_h, btemp_l, btemp_h;
2366 u16 vbat_l, vbat_h, ibat_l, ibat_h;
2368 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2369 ab8540_gpadc_get_otp(gpadc, &vmain_l, &vmain_h, &btemp_l, &btemp_h,
2370 &vbat_l, &vbat_h, &ibat_l, &ibat_h);
2371 return seq_printf(s, "VMAIN_L:0x%X\n"
2379 vmain_l, vmain_h, btemp_l, btemp_h, vbat_l, vbat_h, ibat_l, ibat_h);
2382 static int ab8540_gpadc_otp_cal_open(struct inode *inode, struct file *file)
2384 return single_open(file, ab8540_gpadc_otp_cal_print, inode->i_private);
2387 static const struct file_operations ab8540_gpadc_otp_calib_fops = {
2388 .open = ab8540_gpadc_otp_cal_open,
2390 .llseek = seq_lseek,
2391 .release = single_release,
2392 .owner = THIS_MODULE,
2395 static int ab8500_gpadc_avg_sample_print(struct seq_file *s, void *p)
2397 return seq_printf(s, "%d\n", avg_sample);
2400 static int ab8500_gpadc_avg_sample_open(struct inode *inode, struct file *file)
2402 return single_open(file, ab8500_gpadc_avg_sample_print,
2406 static ssize_t ab8500_gpadc_avg_sample_write(struct file *file,
2407 const char __user *user_buf,
2408 size_t count, loff_t *ppos)
2410 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2411 unsigned long user_avg_sample;
2414 err = kstrtoul_from_user(user_buf, count, 0, &user_avg_sample);
2418 if ((user_avg_sample == SAMPLE_1) || (user_avg_sample == SAMPLE_4)
2419 || (user_avg_sample == SAMPLE_8)
2420 || (user_avg_sample == SAMPLE_16)) {
2421 avg_sample = (u8) user_avg_sample;
2423 dev_err(dev, "debugfs error input: "
2424 "should be egal to 1, 4, 8 or 16\n");
2431 static const struct file_operations ab8500_gpadc_avg_sample_fops = {
2432 .open = ab8500_gpadc_avg_sample_open,
2434 .write = ab8500_gpadc_avg_sample_write,
2435 .llseek = seq_lseek,
2436 .release = single_release,
2437 .owner = THIS_MODULE,
2440 static int ab8500_gpadc_trig_edge_print(struct seq_file *s, void *p)
2442 return seq_printf(s, "%d\n", trig_edge);
2445 static int ab8500_gpadc_trig_edge_open(struct inode *inode, struct file *file)
2447 return single_open(file, ab8500_gpadc_trig_edge_print,
2451 static ssize_t ab8500_gpadc_trig_edge_write(struct file *file,
2452 const char __user *user_buf,
2453 size_t count, loff_t *ppos)
2455 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2456 unsigned long user_trig_edge;
2459 err = kstrtoul_from_user(user_buf, count, 0, &user_trig_edge);
2463 if ((user_trig_edge == RISING_EDGE)
2464 || (user_trig_edge == FALLING_EDGE)) {
2465 trig_edge = (u8) user_trig_edge;
2467 dev_err(dev, "Wrong input:\n"
2468 "Enter 0. Rising edge\n"
2469 "Enter 1. Falling edge\n");
2476 static const struct file_operations ab8500_gpadc_trig_edge_fops = {
2477 .open = ab8500_gpadc_trig_edge_open,
2479 .write = ab8500_gpadc_trig_edge_write,
2480 .llseek = seq_lseek,
2481 .release = single_release,
2482 .owner = THIS_MODULE,
2485 static int ab8500_gpadc_trig_timer_print(struct seq_file *s, void *p)
2487 return seq_printf(s, "%d\n", trig_timer);
2490 static int ab8500_gpadc_trig_timer_open(struct inode *inode, struct file *file)
2492 return single_open(file, ab8500_gpadc_trig_timer_print,
2496 static ssize_t ab8500_gpadc_trig_timer_write(struct file *file,
2497 const char __user *user_buf,
2498 size_t count, loff_t *ppos)
2500 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2501 unsigned long user_trig_timer;
2504 err = kstrtoul_from_user(user_buf, count, 0, &user_trig_timer);
2508 if ((user_trig_timer >= 0) && (user_trig_timer <= 255)) {
2509 trig_timer = (u8) user_trig_timer;
2511 dev_err(dev, "debugfs error input: "
2512 "should be beetween 0 to 255\n");
2519 static const struct file_operations ab8500_gpadc_trig_timer_fops = {
2520 .open = ab8500_gpadc_trig_timer_open,
2522 .write = ab8500_gpadc_trig_timer_write,
2523 .llseek = seq_lseek,
2524 .release = single_release,
2525 .owner = THIS_MODULE,
2528 static int ab8500_gpadc_conv_type_print(struct seq_file *s, void *p)
2530 return seq_printf(s, "%d\n", conv_type);
2533 static int ab8500_gpadc_conv_type_open(struct inode *inode, struct file *file)
2535 return single_open(file, ab8500_gpadc_conv_type_print,
2539 static ssize_t ab8500_gpadc_conv_type_write(struct file *file,
2540 const char __user *user_buf,
2541 size_t count, loff_t *ppos)
2543 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2544 unsigned long user_conv_type;
2547 err = kstrtoul_from_user(user_buf, count, 0, &user_conv_type);
2551 if ((user_conv_type == ADC_SW)
2552 || (user_conv_type == ADC_HW)) {
2553 conv_type = (u8) user_conv_type;
2555 dev_err(dev, "Wrong input:\n"
2556 "Enter 0. ADC SW conversion\n"
2557 "Enter 1. ADC HW conversion\n");
2564 static const struct file_operations ab8500_gpadc_conv_type_fops = {
2565 .open = ab8500_gpadc_conv_type_open,
2567 .write = ab8500_gpadc_conv_type_write,
2568 .llseek = seq_lseek,
2569 .release = single_release,
2570 .owner = THIS_MODULE,
2574 * return length of an ASCII numerical value, 0 is string is not a
2576 * string shall start at value 1st char.
2577 * string can be tailed with \0 or space or newline chars only.
2578 * value can be decimal or hexadecimal (prefixed 0x or 0X).
2580 static int strval_len(char *b)
2583 if ((*s == '0') && ((*(s+1) == 'x') || (*(s+1) == 'X'))) {
2585 for (; *s && (*s != ' ') && (*s != '\n'); s++) {
2592 for (; *s && (*s != ' ') && (*s != '\n'); s++) {
2601 * parse hwreg input data.
2602 * update global hwreg_cfg only if input data syntax is ok.
2604 static ssize_t hwreg_common_write(char *b, struct hwreg_cfg *cfg,
2607 uint write, val = 0;
2610 struct hwreg_cfg loc = {
2611 .bank = 0, /* default: invalid phys addr */
2612 .addr = 0, /* default: invalid phys addr */
2613 .fmt = 0, /* default: 32bit access, hex output */
2614 .mask = 0xFFFFFFFF, /* default: no mask */
2615 .shift = 0, /* default: no bit shift */
2618 /* read or write ? */
2619 if (!strncmp(b, "read ", 5)) {
2622 } else if (!strncmp(b, "write ", 6)) {
2628 /* OPTIONS -l|-w|-b -s -m -o */
2629 while ((*b == ' ') || (*b == '-')) {
2630 if (*(b-1) != ' ') {
2634 if ((!strncmp(b, "-d ", 3)) ||
2635 (!strncmp(b, "-dec ", 5))) {
2636 b += (*(b+2) == ' ') ? 3 : 5;
2638 } else if ((!strncmp(b, "-h ", 3)) ||
2639 (!strncmp(b, "-hex ", 5))) {
2640 b += (*(b+2) == ' ') ? 3 : 5;
2642 } else if ((!strncmp(b, "-m ", 3)) ||
2643 (!strncmp(b, "-mask ", 6))) {
2644 b += (*(b+2) == ' ') ? 3 : 6;
2645 if (strval_len(b) == 0)
2647 loc.mask = simple_strtoul(b, &b, 0);
2648 } else if ((!strncmp(b, "-s ", 3)) ||
2649 (!strncmp(b, "-shift ", 7))) {
2650 b += (*(b+2) == ' ') ? 3 : 7;
2651 if (strval_len(b) == 0)
2653 loc.shift = simple_strtol(b, &b, 0);
2658 /* get arg BANK and ADDRESS */
2659 if (strval_len(b) == 0)
2661 loc.bank = simple_strtoul(b, &b, 0);
2664 if (strval_len(b) == 0)
2666 loc.addr = simple_strtoul(b, &b, 0);
2671 if (strval_len(b) == 0)
2673 val = simple_strtoul(b, &b, 0);
2676 /* args are ok, update target cfg (mainly for read) */
2679 #ifdef ABB_HWREG_DEBUG
2680 pr_warn("HWREG request: %s, %s, addr=0x%08X, mask=0x%X, shift=%d"
2681 "value=0x%X\n", (write) ? "write" : "read",
2682 REG_FMT_DEC(cfg) ? "decimal" : "hexa",
2683 cfg->addr, cfg->mask, cfg->shift, val);
2689 ret = abx500_get_register_interruptible(dev,
2690 (u8)cfg->bank, (u8)cfg->addr, ®value);
2692 dev_err(dev, "abx500_get_reg fail %d, %d\n",
2697 if (cfg->shift >= 0) {
2698 regvalue &= ~(cfg->mask << (cfg->shift));
2699 val = (val & cfg->mask) << (cfg->shift);
2701 regvalue &= ~(cfg->mask >> (-cfg->shift));
2702 val = (val & cfg->mask) >> (-cfg->shift);
2704 val = val | regvalue;
2706 ret = abx500_set_register_interruptible(dev,
2707 (u8)cfg->bank, (u8)cfg->addr, (u8)val);
2709 pr_err("abx500_set_reg failed %d, %d", ret, __LINE__);
2716 static ssize_t ab8500_hwreg_write(struct file *file,
2717 const char __user *user_buf, size_t count, loff_t *ppos)
2719 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2723 /* Get userspace string and assure termination */
2724 buf_size = min(count, (sizeof(buf)-1));
2725 if (copy_from_user(buf, user_buf, buf_size))
2729 /* get args and process */
2730 ret = hwreg_common_write(buf, &hwreg_cfg, dev);
2731 return (ret) ? ret : buf_size;
2735 * - irq subscribe/unsubscribe stuff
2737 static int ab8500_subscribe_unsubscribe_print(struct seq_file *s, void *p)
2739 seq_printf(s, "%d\n", irq_first);
2744 static int ab8500_subscribe_unsubscribe_open(struct inode *inode,
2747 return single_open(file, ab8500_subscribe_unsubscribe_print,
2752 * Userspace should use poll() on this file. When an event occur
2753 * the blocking poll will be released.
2755 static ssize_t show_irq(struct device *dev,
2756 struct device_attribute *attr, char *buf)
2759 unsigned int irq_index;
2762 err = strict_strtoul(attr->attr.name, 0, &name);
2766 irq_index = name - irq_first;
2767 if (irq_index >= num_irqs)
2770 return sprintf(buf, "%u\n", irq_count[irq_index]);
2773 static ssize_t ab8500_subscribe_write(struct file *file,
2774 const char __user *user_buf,
2775 size_t count, loff_t *ppos)
2777 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2778 unsigned long user_val;
2780 unsigned int irq_index;
2782 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
2786 if (user_val < irq_first) {
2787 dev_err(dev, "debugfs error input < %d\n", irq_first);
2790 if (user_val > irq_last) {
2791 dev_err(dev, "debugfs error input > %d\n", irq_last);
2795 irq_index = user_val - irq_first;
2796 if (irq_index >= num_irqs)
2800 * This will create a sysfs file named <irq-nr> which userspace can
2801 * use to select or poll and get the AB8500 events
2803 dev_attr[irq_index] = kmalloc(sizeof(struct device_attribute),
2805 event_name[irq_index] = kmalloc(count, GFP_KERNEL);
2806 sprintf(event_name[irq_index], "%lu", user_val);
2807 dev_attr[irq_index]->show = show_irq;
2808 dev_attr[irq_index]->store = NULL;
2809 dev_attr[irq_index]->attr.name = event_name[irq_index];
2810 dev_attr[irq_index]->attr.mode = S_IRUGO;
2811 err = sysfs_create_file(&dev->kobj, &dev_attr[irq_index]->attr);
2813 printk(KERN_ERR "sysfs_create_file failed %d\n", err);
2817 err = request_threaded_irq(user_val, NULL, ab8500_debug_handler,
2818 IRQF_SHARED | IRQF_NO_SUSPEND,
2819 "ab8500-debug", &dev->kobj);
2821 printk(KERN_ERR "request_threaded_irq failed %d, %lu\n",
2823 sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr);
2830 static ssize_t ab8500_unsubscribe_write(struct file *file,
2831 const char __user *user_buf,
2832 size_t count, loff_t *ppos)
2834 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2835 unsigned long user_val;
2837 unsigned int irq_index;
2839 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
2843 if (user_val < irq_first) {
2844 dev_err(dev, "debugfs error input < %d\n", irq_first);
2847 if (user_val > irq_last) {
2848 dev_err(dev, "debugfs error input > %d\n", irq_last);
2852 irq_index = user_val - irq_first;
2853 if (irq_index >= num_irqs)
2856 /* Set irq count to 0 when unsubscribe */
2857 irq_count[irq_index] = 0;
2859 if (dev_attr[irq_index])
2860 sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr);
2863 free_irq(user_val, &dev->kobj);
2864 kfree(event_name[irq_index]);
2865 kfree(dev_attr[irq_index]);
2871 * - several deubgfs nodes fops
2874 static const struct file_operations ab8500_bank_fops = {
2875 .open = ab8500_bank_open,
2876 .write = ab8500_bank_write,
2878 .llseek = seq_lseek,
2879 .release = single_release,
2880 .owner = THIS_MODULE,
2883 static const struct file_operations ab8500_address_fops = {
2884 .open = ab8500_address_open,
2885 .write = ab8500_address_write,
2887 .llseek = seq_lseek,
2888 .release = single_release,
2889 .owner = THIS_MODULE,
2892 static const struct file_operations ab8500_val_fops = {
2893 .open = ab8500_val_open,
2894 .write = ab8500_val_write,
2896 .llseek = seq_lseek,
2897 .release = single_release,
2898 .owner = THIS_MODULE,
2901 static const struct file_operations ab8500_interrupts_fops = {
2902 .open = ab8500_interrupts_open,
2904 .llseek = seq_lseek,
2905 .release = single_release,
2906 .owner = THIS_MODULE,
2909 static const struct file_operations ab8500_subscribe_fops = {
2910 .open = ab8500_subscribe_unsubscribe_open,
2911 .write = ab8500_subscribe_write,
2913 .llseek = seq_lseek,
2914 .release = single_release,
2915 .owner = THIS_MODULE,
2918 static const struct file_operations ab8500_unsubscribe_fops = {
2919 .open = ab8500_subscribe_unsubscribe_open,
2920 .write = ab8500_unsubscribe_write,
2922 .llseek = seq_lseek,
2923 .release = single_release,
2924 .owner = THIS_MODULE,
2927 static const struct file_operations ab8500_hwreg_fops = {
2928 .open = ab8500_hwreg_open,
2929 .write = ab8500_hwreg_write,
2931 .llseek = seq_lseek,
2932 .release = single_release,
2933 .owner = THIS_MODULE,
2936 static struct dentry *ab8500_dir;
2937 static struct dentry *ab8500_gpadc_dir;
2939 static int ab8500_debug_probe(struct platform_device *plf)
2941 struct dentry *file;
2943 struct ab8500 *ab8500;
2944 debug_bank = AB8500_MISC;
2945 debug_address = AB8500_REV_REG & 0x00FF;
2947 ab8500 = dev_get_drvdata(plf->dev.parent);
2948 num_irqs = ab8500->mask_size;
2950 irq_count = kzalloc(sizeof(*irq_count)*num_irqs, GFP_KERNEL);
2954 dev_attr = kzalloc(sizeof(*dev_attr)*num_irqs,GFP_KERNEL);
2956 goto out_freeirq_count;
2958 event_name = kzalloc(sizeof(*event_name)*num_irqs, GFP_KERNEL);
2960 goto out_freedev_attr;
2962 irq_first = platform_get_irq_byname(plf, "IRQ_FIRST");
2963 if (irq_first < 0) {
2964 dev_err(&plf->dev, "First irq not found, err %d\n",
2967 goto out_freeevent_name;
2970 irq_last = platform_get_irq_byname(plf, "IRQ_LAST");
2972 dev_err(&plf->dev, "Last irq not found, err %d\n",
2975 goto out_freeevent_name;
2978 ab8500_dir = debugfs_create_dir(AB8500_NAME_STRING, NULL);
2982 ab8500_gpadc_dir = debugfs_create_dir(AB8500_ADC_NAME_STRING,
2984 if (!ab8500_gpadc_dir)
2987 file = debugfs_create_file("all-bank-registers", S_IRUGO,
2988 ab8500_dir, &plf->dev, &ab8500_registers_fops);
2992 file = debugfs_create_file("all-banks", S_IRUGO,
2993 ab8500_dir, &plf->dev, &ab8500_all_banks_fops);
2997 file = debugfs_create_file("register-bank", (S_IRUGO | S_IWUSR | S_IWGRP),
2998 ab8500_dir, &plf->dev, &ab8500_bank_fops);
3002 file = debugfs_create_file("register-address", (S_IRUGO | S_IWUSR | S_IWGRP),
3003 ab8500_dir, &plf->dev, &ab8500_address_fops);
3007 file = debugfs_create_file("register-value", (S_IRUGO | S_IWUSR | S_IWGRP),
3008 ab8500_dir, &plf->dev, &ab8500_val_fops);
3012 file = debugfs_create_file("irq-subscribe", (S_IRUGO | S_IWUSR | S_IWGRP),
3013 ab8500_dir, &plf->dev, &ab8500_subscribe_fops);
3017 if (is_ab8500(ab8500)) {
3018 debug_ranges = ab8500_debug_ranges;
3019 num_interrupt_lines = AB8500_NR_IRQS;
3020 } else if (is_ab8505(ab8500)) {
3021 debug_ranges = ab8505_debug_ranges;
3022 num_interrupt_lines = AB8505_NR_IRQS;
3023 } else if (is_ab9540(ab8500)) {
3024 debug_ranges = ab8505_debug_ranges;
3025 num_interrupt_lines = AB9540_NR_IRQS;
3026 } else if (is_ab8540(ab8500)) {
3027 debug_ranges = ab8540_debug_ranges;
3028 num_interrupt_lines = AB8540_NR_IRQS;
3031 file = debugfs_create_file("interrupts", (S_IRUGO),
3032 ab8500_dir, &plf->dev, &ab8500_interrupts_fops);
3036 file = debugfs_create_file("irq-unsubscribe", (S_IRUGO | S_IWUSR | S_IWGRP),
3037 ab8500_dir, &plf->dev, &ab8500_unsubscribe_fops);
3041 file = debugfs_create_file("hwreg", (S_IRUGO | S_IWUSR | S_IWGRP),
3042 ab8500_dir, &plf->dev, &ab8500_hwreg_fops);
3046 file = debugfs_create_file("all-modem-registers", (S_IRUGO | S_IWUSR | S_IWGRP),
3047 ab8500_dir, &plf->dev, &ab8500_modem_fops);
3051 file = debugfs_create_file("bat_ctrl", (S_IRUGO | S_IWUSR | S_IWGRP),
3052 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_bat_ctrl_fops);
3056 file = debugfs_create_file("btemp_ball", (S_IRUGO | S_IWUSR | S_IWGRP),
3057 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_btemp_ball_fops);
3061 file = debugfs_create_file("main_charger_v", (S_IRUGO | S_IWUSR | S_IWGRP),
3062 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_charger_v_fops);
3066 file = debugfs_create_file("acc_detect1", (S_IRUGO | S_IWUSR | S_IWGRP),
3067 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_acc_detect1_fops);
3071 file = debugfs_create_file("acc_detect2", (S_IRUGO | S_IWUSR | S_IWGRP),
3072 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_acc_detect2_fops);
3076 file = debugfs_create_file("adc_aux1", (S_IRUGO | S_IWUSR | S_IWGRP),
3077 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_aux1_fops);
3081 file = debugfs_create_file("adc_aux2", (S_IRUGO | S_IWUSR | S_IWGRP),
3082 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_aux2_fops);
3086 file = debugfs_create_file("main_bat_v", (S_IRUGO | S_IWUSR | S_IWGRP),
3087 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_bat_v_fops);
3091 file = debugfs_create_file("vbus_v", (S_IRUGO | S_IWUSR | S_IWGRP),
3092 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_vbus_v_fops);
3096 file = debugfs_create_file("main_charger_c", (S_IRUGO | S_IWUSR | S_IWGRP),
3097 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_charger_c_fops);
3101 file = debugfs_create_file("usb_charger_c", (S_IRUGO | S_IWUSR | S_IWGRP),
3102 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_usb_charger_c_fops);
3106 file = debugfs_create_file("bk_bat_v", (S_IRUGO | S_IWUSR | S_IWGRP),
3107 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_bk_bat_v_fops);
3111 file = debugfs_create_file("die_temp", (S_IRUGO | S_IWUSR | S_IWGRP),
3112 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_die_temp_fops);
3116 file = debugfs_create_file("usb_id", (S_IRUGO | S_IWUSR | S_IWGRP),
3117 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_usb_id_fops);
3121 if (is_ab8540(ab8500)) {
3122 file = debugfs_create_file("xtal_temp", (S_IRUGO | S_IWUSR | S_IWGRP),
3123 ab8500_gpadc_dir, &plf->dev, &ab8540_gpadc_xtal_temp_fops);
3126 file = debugfs_create_file("vbattruemeas", (S_IRUGO | S_IWUSR | S_IWGRP),
3127 ab8500_gpadc_dir, &plf->dev,
3128 &ab8540_gpadc_vbat_true_meas_fops);
3131 file = debugfs_create_file("batctrl_and_ibat",
3132 (S_IRUGO | S_IWUGO), ab8500_gpadc_dir,
3133 &plf->dev, &ab8540_gpadc_bat_ctrl_and_ibat_fops);
3136 file = debugfs_create_file("vbatmeas_and_ibat",
3137 (S_IRUGO | S_IWUGO), ab8500_gpadc_dir,
3139 &ab8540_gpadc_vbat_meas_and_ibat_fops);
3142 file = debugfs_create_file("vbattruemeas_and_ibat",
3143 (S_IRUGO | S_IWUGO), ab8500_gpadc_dir,
3145 &ab8540_gpadc_vbat_true_meas_and_ibat_fops);
3148 file = debugfs_create_file("battemp_and_ibat",
3149 (S_IRUGO | S_IWUGO), ab8500_gpadc_dir,
3150 &plf->dev, &ab8540_gpadc_bat_temp_and_ibat_fops);
3153 file = debugfs_create_file("otp_calib", (S_IRUGO | S_IWUSR | S_IWGRP),
3154 ab8500_gpadc_dir, &plf->dev, &ab8540_gpadc_otp_calib_fops);
3158 file = debugfs_create_file("avg_sample", (S_IRUGO | S_IWUSR | S_IWGRP),
3159 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_avg_sample_fops);
3163 file = debugfs_create_file("trig_edge", (S_IRUGO | S_IWUSR | S_IWGRP),
3164 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_trig_edge_fops);
3168 file = debugfs_create_file("trig_timer", (S_IRUGO | S_IWUSR | S_IWGRP),
3169 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_trig_timer_fops);
3173 file = debugfs_create_file("conv_type", (S_IRUGO | S_IWUSR | S_IWGRP),
3174 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_conv_type_fops);
3182 debugfs_remove_recursive(ab8500_dir);
3183 dev_err(&plf->dev, "failed to create debugfs entries.\n");
3194 static int ab8500_debug_remove(struct platform_device *plf)
3196 debugfs_remove_recursive(ab8500_dir);
3204 static struct platform_driver ab8500_debug_driver = {
3206 .name = "ab8500-debug",
3207 .owner = THIS_MODULE,
3209 .probe = ab8500_debug_probe,
3210 .remove = ab8500_debug_remove
3213 static int __init ab8500_debug_init(void)
3215 return platform_driver_register(&ab8500_debug_driver);
3218 static void __exit ab8500_debug_exit(void)
3220 platform_driver_unregister(&ab8500_debug_driver);
3222 subsys_initcall(ab8500_debug_init);
3223 module_exit(ab8500_debug_exit);
3225 MODULE_AUTHOR("Mattias WALLIN <mattias.wallin@stericsson.com");
3226 MODULE_DESCRIPTION("AB8500 DEBUG");
3227 MODULE_LICENSE("GPL v2");