2 * Copyright (C) ST-Ericsson SA 2010
5 * License Terms: GNU General Public License v2
8 * AB8500 register access
9 * ======================
12 * # echo BANK > <debugfs>/ab8500/register-bank
13 * # echo ADDR > <debugfs>/ab8500/register-address
14 * # cat <debugfs>/ab8500/register-value
17 * # echo BANK > <debugfs>/ab8500/register-bank
18 * # echo ADDR > <debugfs>/ab8500/register-address
19 * # echo VALUE > <debugfs>/ab8500/register-value
21 * read all registers from a bank:
22 * # echo BANK > <debugfs>/ab8500/register-bank
23 * # cat <debugfs>/ab8500/all-bank-register
25 * BANK target AB8500 register bank
26 * ADDR target AB8500 register address
27 * VALUE decimal or 0x-prefixed hexadecimal
30 * User Space notification on AB8500 IRQ
31 * =====================================
33 * Allows user space entity to be notified when target AB8500 IRQ occurs.
34 * When subscribed, a sysfs entry is created in ab8500.i2c platform device.
35 * One can pool this file to get target IRQ occurence information.
37 * subscribe to an AB8500 IRQ:
38 * # echo IRQ > <debugfs>/ab8500/irq-subscribe
40 * unsubscribe from an AB8500 IRQ:
41 * # echo IRQ > <debugfs>/ab8500/irq-unsubscribe
44 * AB8500 register formated read/write access
45 * ==========================================
47 * Read: read data, data>>SHIFT, data&=MASK, output data
48 * [0xABCDEF98] shift=12 mask=0xFFF => 0x00000CDE
49 * Write: read data, data &= ~(MASK<<SHIFT), data |= (VALUE<<SHIFT), write data
50 * [0xABCDEF98] shift=12 mask=0xFFF value=0x123 => [0xAB123F98]
53 * # echo "CMD [OPTIONS] BANK ADRESS [VALUE]" > $debugfs/ab8500/hwreg
55 * CMD read read access
58 * BANK target reg bank
59 * ADDRESS target reg address
60 * VALUE (write) value to be updated
63 * -d|-dec (read) output in decimal
64 * -h|-hexa (read) output in 0x-hexa (default)
65 * -l|-w|-b 32bit (default), 16bit or 8bit reg access
66 * -m|-mask MASK 0x-hexa mask (default 0xFFFFFFFF)
67 * -s|-shift SHIFT bit shift value (read:left, write:right)
68 * -o|-offset OFFSET address offset to add to ADDRESS value
70 * Warning: bit shift operation is applied to bit-mask.
71 * Warning: bit shift direction depends on read or right command.
74 #include <linux/seq_file.h>
75 #include <linux/uaccess.h>
77 #include <linux/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 24
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] = {
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[]) {
245 /* 0x80-0x8B is SIM registers and should
246 * not be accessed from here */
251 .range = (struct ab8500_reg_range[]) {
264 .range = (struct ab8500_reg_range[]) {
307 [AB8500_ECI_AV_ACC] = {
309 .range = (struct ab8500_reg_range[]) {
322 .range = (struct ab8500_reg_range[]) {
331 .range = (struct ab8500_reg_range[]) {
370 [AB8500_GAS_GAUGE] = {
372 .range = (struct ab8500_reg_range[]) {
387 [AB8500_DEVELOPMENT] = {
389 .range = (struct ab8500_reg_range[]) {
398 .range = (struct ab8500_reg_range[]) {
407 .range = (struct ab8500_reg_range[]) {
414 [AB8500_INTERRUPT] = {
420 .range = (struct ab8500_reg_range[]) {
429 .range = (struct ab8500_reg_range[]) {
480 [AB8500_OTP_EMUL] = {
482 .range = (struct ab8500_reg_range[]) {
491 static struct ab8500_prcmu_ranges ab8505_debug_ranges[AB8500_NUM_BANKS] = {
496 [AB8500_SYS_CTRL1_BLOCK] = {
498 .range = (struct ab8500_reg_range[]) {
521 [AB8500_SYS_CTRL2_BLOCK] = {
523 .range = (struct ab8500_reg_range[]) {
546 [AB8500_REGU_CTRL1] = {
548 .range = (struct ab8500_reg_range[]) {
563 [AB8500_REGU_CTRL2] = {
565 .range = (struct ab8500_reg_range[]) {
590 /* 0x80-0x8B is SIM registers and should
591 * not be accessed from here */
596 .range = (struct ab8500_reg_range[]) {
619 [AB8500_ECI_AV_ACC] = {
621 .range = (struct ab8500_reg_range[]) {
628 [AB8500_RESERVED] = {
634 .range = (struct ab8500_reg_range[]) {
643 .range = (struct ab8500_reg_range[]) {
682 [AB8500_GAS_GAUGE] = {
684 .range = (struct ab8500_reg_range[]) {
701 .range = (struct ab8500_reg_range[]) {
708 [AB8500_INTERRUPT] = {
710 .range = (struct ab8500_reg_range[]) {
735 /* Latch registers should not be read here */
756 /* LatchHier registers should not be read here */
761 .range = (struct ab8500_reg_range[]) {
774 .range = (struct ab8500_reg_range[]) {
809 [AB8500_DEVELOPMENT] = {
811 .range = (struct ab8500_reg_range[]) {
824 .range = (struct ab8500_reg_range[]) {
831 [AB8500_PROD_TEST] = {
835 [AB8500_STE_TEST] = {
839 [AB8500_OTP_EMUL] = {
841 .range = (struct ab8500_reg_range[]) {
850 static struct ab8500_prcmu_ranges ab8540_debug_ranges[AB8500_NUM_BANKS] = {
851 [AB8500_M_FSM_RANK] = {
853 .range = (struct ab8500_reg_range[]) {
860 [AB8500_SYS_CTRL1_BLOCK] = {
862 .range = (struct ab8500_reg_range[]) {
889 [AB8500_SYS_CTRL2_BLOCK] = {
891 .range = (struct ab8500_reg_range[]) {
914 [AB8500_REGU_CTRL1] = {
916 .range = (struct ab8500_reg_range[]) {
935 [AB8500_REGU_CTRL2] = {
937 .range = (struct ab8500_reg_range[]) {
974 .range = (struct ab8500_reg_range[]) {
995 .range = (struct ab8500_reg_range[]) {
1014 [AB8500_ECI_AV_ACC] = {
1016 .range = (struct ab8500_reg_range[]) {
1027 [AB8500_RESERVED] = {
1033 .range = (struct ab8500_reg_range[]) {
1052 [AB8500_CHARGER] = {
1054 .range = (struct ab8500_reg_range[]) {
1097 [AB8500_GAS_GAUGE] = {
1099 .range = (struct ab8500_reg_range[]) {
1116 .range = (struct ab8500_reg_range[]) {
1123 [AB8500_INTERRUPT] = {
1125 .range = (struct ab8500_reg_range[]) {
1138 /* Latch registers should not be read here */
1151 /* LatchHier registers should not be read here */
1156 .range = (struct ab8500_reg_range[]) {
1173 .range = (struct ab8500_reg_range[]) {
1212 [AB8500_DEVELOPMENT] = {
1214 .range = (struct ab8500_reg_range[]) {
1231 .range = (struct ab8500_reg_range[]) {
1246 [AB8500_PROD_TEST] = {
1250 [AB8500_STE_TEST] = {
1254 [AB8500_OTP_EMUL] = {
1256 .range = (struct ab8500_reg_range[]) {
1266 static irqreturn_t ab8500_debug_handler(int irq, void *data)
1269 struct kobject *kobj = (struct kobject *)data;
1270 unsigned int irq_abb = irq - irq_first;
1272 if (irq_abb < num_irqs)
1273 irq_count[irq_abb]++;
1275 * This makes it possible to use poll for events (POLLPRI | POLLERR)
1276 * from userspace on sysfs file named <irq-nr>
1278 sprintf(buf, "%d", irq);
1279 sysfs_notify(kobj, NULL, buf);
1284 /* Prints to seq_file or log_buf */
1285 static int ab8500_registers_print(struct device *dev, u32 bank,
1290 for (i = 0; i < debug_ranges[bank].num_ranges; i++) {
1293 for (reg = debug_ranges[bank].range[i].first;
1294 reg <= debug_ranges[bank].range[i].last;
1299 err = abx500_get_register_interruptible(dev,
1300 (u8)bank, (u8)reg, &value);
1302 dev_err(dev, "ab->read fail %d\n", err);
1307 seq_printf(s, " [0x%02X/0x%02X]: 0x%02X\n",
1309 /* Error is not returned here since
1310 * the output is wanted in any case */
1311 if (seq_has_overflowed(s))
1314 dev_info(dev, " [0x%02X/0x%02X]: 0x%02X\n",
1323 static int ab8500_print_bank_registers(struct seq_file *s, void *p)
1325 struct device *dev = s->private;
1326 u32 bank = debug_bank;
1328 seq_puts(s, AB8500_NAME_STRING " register values:\n");
1330 seq_printf(s, " bank 0x%02X:\n", bank);
1332 return ab8500_registers_print(dev, bank, s);
1335 static int ab8500_registers_open(struct inode *inode, struct file *file)
1337 return single_open(file, ab8500_print_bank_registers, inode->i_private);
1340 static const struct file_operations ab8500_registers_fops = {
1341 .open = ab8500_registers_open,
1343 .llseek = seq_lseek,
1344 .release = single_release,
1345 .owner = THIS_MODULE,
1348 static int ab8500_print_all_banks(struct seq_file *s, void *p)
1350 struct device *dev = s->private;
1353 seq_puts(s, AB8500_NAME_STRING " register values:\n");
1355 for (i = 0; i < AB8500_NUM_BANKS; i++) {
1358 seq_printf(s, " bank 0x%02X:\n", i);
1359 err = ab8500_registers_print(dev, i, s);
1366 /* Dump registers to kernel log */
1367 void ab8500_dump_all_banks(struct device *dev)
1371 dev_info(dev, "ab8500 register values:\n");
1373 for (i = 1; i < AB8500_NUM_BANKS; i++) {
1374 dev_info(dev, " bank 0x%02X:\n", i);
1375 ab8500_registers_print(dev, i, NULL);
1379 /* Space for 500 registers. */
1380 #define DUMP_MAX_REGS 700
1381 static struct ab8500_register_dump
1386 } ab8500_complete_register_dump[DUMP_MAX_REGS];
1388 /* This shall only be called upon kernel panic! */
1389 void ab8500_dump_all_banks_to_mem(void)
1395 pr_info("Saving all ABB registers for crash analysis.\n");
1397 for (bank = 0; bank < AB8500_NUM_BANKS; bank++) {
1398 for (i = 0; i < debug_ranges[bank].num_ranges; i++) {
1401 for (reg = debug_ranges[bank].range[i].first;
1402 reg <= debug_ranges[bank].range[i].last;
1406 err = prcmu_abb_read(bank, reg, &value, 1);
1411 ab8500_complete_register_dump[r].bank = bank;
1412 ab8500_complete_register_dump[r].reg = reg;
1413 ab8500_complete_register_dump[r].value = value;
1417 if (r >= DUMP_MAX_REGS) {
1418 pr_err("%s: too many register to dump!\n",
1428 pr_info("Saved all ABB registers.\n");
1430 pr_info("Failed to save all ABB registers.\n");
1433 static int ab8500_all_banks_open(struct inode *inode, struct file *file)
1438 err = single_open(file, ab8500_print_all_banks, inode->i_private);
1440 /* Default buf size in seq_read is not enough */
1441 s = (struct seq_file *)file->private_data;
1442 s->size = (PAGE_SIZE * 2);
1443 s->buf = kmalloc(s->size, GFP_KERNEL);
1445 single_release(inode, file);
1452 static const struct file_operations ab8500_all_banks_fops = {
1453 .open = ab8500_all_banks_open,
1455 .llseek = seq_lseek,
1456 .release = single_release,
1457 .owner = THIS_MODULE,
1460 static int ab8500_bank_print(struct seq_file *s, void *p)
1462 seq_printf(s, "0x%02X\n", debug_bank);
1466 static int ab8500_bank_open(struct inode *inode, struct file *file)
1468 return single_open(file, ab8500_bank_print, inode->i_private);
1471 static ssize_t ab8500_bank_write(struct file *file,
1472 const char __user *user_buf,
1473 size_t count, loff_t *ppos)
1475 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1476 unsigned long user_bank;
1479 err = kstrtoul_from_user(user_buf, count, 0, &user_bank);
1483 if (user_bank >= AB8500_NUM_BANKS) {
1484 dev_err(dev, "debugfs error input > number of banks\n");
1488 debug_bank = user_bank;
1493 static int ab8500_address_print(struct seq_file *s, void *p)
1495 seq_printf(s, "0x%02X\n", debug_address);
1499 static int ab8500_address_open(struct inode *inode, struct file *file)
1501 return single_open(file, ab8500_address_print, inode->i_private);
1504 static ssize_t ab8500_address_write(struct file *file,
1505 const char __user *user_buf,
1506 size_t count, loff_t *ppos)
1508 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1509 unsigned long user_address;
1512 err = kstrtoul_from_user(user_buf, count, 0, &user_address);
1516 if (user_address > 0xff) {
1517 dev_err(dev, "debugfs error input > 0xff\n");
1520 debug_address = user_address;
1525 static int ab8500_val_print(struct seq_file *s, void *p)
1527 struct device *dev = s->private;
1531 ret = abx500_get_register_interruptible(dev,
1532 (u8)debug_bank, (u8)debug_address, ®value);
1534 dev_err(dev, "abx500_get_reg fail %d, %d\n",
1538 seq_printf(s, "0x%02X\n", regvalue);
1543 static int ab8500_val_open(struct inode *inode, struct file *file)
1545 return single_open(file, ab8500_val_print, inode->i_private);
1548 static ssize_t ab8500_val_write(struct file *file,
1549 const char __user *user_buf,
1550 size_t count, loff_t *ppos)
1552 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1553 unsigned long user_val;
1556 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
1560 if (user_val > 0xff) {
1561 dev_err(dev, "debugfs error input > 0xff\n");
1564 err = abx500_set_register_interruptible(dev,
1565 (u8)debug_bank, debug_address, (u8)user_val);
1567 pr_err("abx500_set_reg failed %d, %d", err, __LINE__);
1577 static u32 num_interrupts[AB8500_MAX_NR_IRQS];
1578 static u32 num_wake_interrupts[AB8500_MAX_NR_IRQS];
1579 static int num_interrupt_lines;
1581 bool __attribute__((weak)) suspend_test_wake_cause_interrupt_is_mine(u32 my_int)
1586 void ab8500_debug_register_interrupt(int line)
1588 if (line < num_interrupt_lines) {
1589 num_interrupts[line]++;
1590 if (suspend_test_wake_cause_interrupt_is_mine(irq_ab8500))
1591 num_wake_interrupts[line]++;
1595 static int ab8500_interrupts_print(struct seq_file *s, void *p)
1599 seq_puts(s, "name: number: number of: wake:\n");
1601 for (line = 0; line < num_interrupt_lines; line++) {
1602 struct irq_desc *desc = irq_to_desc(line + irq_first);
1604 seq_printf(s, "%3i: %6i %4i",
1606 num_interrupts[line],
1607 num_wake_interrupts[line]);
1609 if (desc && desc->name)
1610 seq_printf(s, "-%-8s", desc->name);
1611 if (desc && desc->action) {
1612 struct irqaction *action = desc->action;
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 seq_printf(s, " [0x%02X/0x%02X]: 0x%02X\n", bank, reg, value);
1714 err = abx500_set_register_interruptible(dev,
1715 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG, orig_value);
1717 dev_err(dev, "ab->write fail %d\n", err);
1723 static int ab8500_modem_open(struct inode *inode, struct file *file)
1725 return single_open(file, ab8500_print_modem_registers,
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 seq_printf(s, "%d,0x%X\n", bat_ctrl_convert, bat_ctrl_raw);
1754 static int ab8500_gpadc_bat_ctrl_open(struct inode *inode, struct file *file)
1756 return single_open(file, ab8500_gpadc_bat_ctrl_print,
1760 static const struct file_operations ab8500_gpadc_bat_ctrl_fops = {
1761 .open = ab8500_gpadc_bat_ctrl_open,
1763 .llseek = seq_lseek,
1764 .release = single_release,
1765 .owner = THIS_MODULE,
1768 static int ab8500_gpadc_btemp_ball_print(struct seq_file *s, void *p)
1771 int btemp_ball_convert;
1772 struct ab8500_gpadc *gpadc;
1774 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1775 btemp_ball_raw = ab8500_gpadc_read_raw(gpadc, BTEMP_BALL,
1776 avg_sample, trig_edge, trig_timer, conv_type);
1777 btemp_ball_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL,
1780 seq_printf(s, "%d,0x%X\n", btemp_ball_convert, btemp_ball_raw);
1785 static int ab8500_gpadc_btemp_ball_open(struct inode *inode,
1788 return single_open(file, ab8500_gpadc_btemp_ball_print,
1792 static const struct file_operations ab8500_gpadc_btemp_ball_fops = {
1793 .open = ab8500_gpadc_btemp_ball_open,
1795 .llseek = seq_lseek,
1796 .release = single_release,
1797 .owner = THIS_MODULE,
1800 static int ab8500_gpadc_main_charger_v_print(struct seq_file *s, void *p)
1802 int main_charger_v_raw;
1803 int main_charger_v_convert;
1804 struct ab8500_gpadc *gpadc;
1806 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1807 main_charger_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_V,
1808 avg_sample, trig_edge, trig_timer, conv_type);
1809 main_charger_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
1810 MAIN_CHARGER_V, main_charger_v_raw);
1812 seq_printf(s, "%d,0x%X\n", main_charger_v_convert, main_charger_v_raw);
1817 static int ab8500_gpadc_main_charger_v_open(struct inode *inode,
1820 return single_open(file, ab8500_gpadc_main_charger_v_print,
1824 static const struct file_operations ab8500_gpadc_main_charger_v_fops = {
1825 .open = ab8500_gpadc_main_charger_v_open,
1827 .llseek = seq_lseek,
1828 .release = single_release,
1829 .owner = THIS_MODULE,
1832 static int ab8500_gpadc_acc_detect1_print(struct seq_file *s, void *p)
1834 int acc_detect1_raw;
1835 int acc_detect1_convert;
1836 struct ab8500_gpadc *gpadc;
1838 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1839 acc_detect1_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT1,
1840 avg_sample, trig_edge, trig_timer, conv_type);
1841 acc_detect1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ACC_DETECT1,
1844 seq_printf(s, "%d,0x%X\n", acc_detect1_convert, acc_detect1_raw);
1849 static int ab8500_gpadc_acc_detect1_open(struct inode *inode,
1852 return single_open(file, ab8500_gpadc_acc_detect1_print,
1856 static const struct file_operations ab8500_gpadc_acc_detect1_fops = {
1857 .open = ab8500_gpadc_acc_detect1_open,
1859 .llseek = seq_lseek,
1860 .release = single_release,
1861 .owner = THIS_MODULE,
1864 static int ab8500_gpadc_acc_detect2_print(struct seq_file *s, void *p)
1866 int acc_detect2_raw;
1867 int acc_detect2_convert;
1868 struct ab8500_gpadc *gpadc;
1870 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1871 acc_detect2_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT2,
1872 avg_sample, trig_edge, trig_timer, conv_type);
1873 acc_detect2_convert = ab8500_gpadc_ad_to_voltage(gpadc,
1874 ACC_DETECT2, acc_detect2_raw);
1876 seq_printf(s, "%d,0x%X\n", acc_detect2_convert, acc_detect2_raw);
1881 static int ab8500_gpadc_acc_detect2_open(struct inode *inode,
1884 return single_open(file, ab8500_gpadc_acc_detect2_print,
1888 static const struct file_operations ab8500_gpadc_acc_detect2_fops = {
1889 .open = ab8500_gpadc_acc_detect2_open,
1891 .llseek = seq_lseek,
1892 .release = single_release,
1893 .owner = THIS_MODULE,
1896 static int ab8500_gpadc_aux1_print(struct seq_file *s, void *p)
1900 struct ab8500_gpadc *gpadc;
1902 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1903 aux1_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX1,
1904 avg_sample, trig_edge, trig_timer, conv_type);
1905 aux1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX1,
1908 seq_printf(s, "%d,0x%X\n", aux1_convert, aux1_raw);
1913 static int ab8500_gpadc_aux1_open(struct inode *inode, struct file *file)
1915 return single_open(file, ab8500_gpadc_aux1_print, inode->i_private);
1918 static const struct file_operations ab8500_gpadc_aux1_fops = {
1919 .open = ab8500_gpadc_aux1_open,
1921 .llseek = seq_lseek,
1922 .release = single_release,
1923 .owner = THIS_MODULE,
1926 static int ab8500_gpadc_aux2_print(struct seq_file *s, void *p)
1930 struct ab8500_gpadc *gpadc;
1932 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1933 aux2_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX2,
1934 avg_sample, trig_edge, trig_timer, conv_type);
1935 aux2_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX2,
1938 seq_printf(s, "%d,0x%X\n", aux2_convert, aux2_raw);
1943 static int ab8500_gpadc_aux2_open(struct inode *inode, struct file *file)
1945 return single_open(file, ab8500_gpadc_aux2_print, inode->i_private);
1948 static const struct file_operations ab8500_gpadc_aux2_fops = {
1949 .open = ab8500_gpadc_aux2_open,
1951 .llseek = seq_lseek,
1952 .release = single_release,
1953 .owner = THIS_MODULE,
1956 static int ab8500_gpadc_main_bat_v_print(struct seq_file *s, void *p)
1959 int main_bat_v_convert;
1960 struct ab8500_gpadc *gpadc;
1962 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1963 main_bat_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_BAT_V,
1964 avg_sample, trig_edge, trig_timer, conv_type);
1965 main_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V,
1968 seq_printf(s, "%d,0x%X\n", main_bat_v_convert, main_bat_v_raw);
1973 static int ab8500_gpadc_main_bat_v_open(struct inode *inode,
1976 return single_open(file, ab8500_gpadc_main_bat_v_print,
1980 static const struct file_operations ab8500_gpadc_main_bat_v_fops = {
1981 .open = ab8500_gpadc_main_bat_v_open,
1983 .llseek = seq_lseek,
1984 .release = single_release,
1985 .owner = THIS_MODULE,
1988 static int ab8500_gpadc_vbus_v_print(struct seq_file *s, void *p)
1992 struct ab8500_gpadc *gpadc;
1994 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1995 vbus_v_raw = ab8500_gpadc_read_raw(gpadc, VBUS_V,
1996 avg_sample, trig_edge, trig_timer, conv_type);
1997 vbus_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, VBUS_V,
2000 seq_printf(s, "%d,0x%X\n", vbus_v_convert, vbus_v_raw);
2005 static int ab8500_gpadc_vbus_v_open(struct inode *inode, struct file *file)
2007 return single_open(file, ab8500_gpadc_vbus_v_print, inode->i_private);
2010 static const struct file_operations ab8500_gpadc_vbus_v_fops = {
2011 .open = ab8500_gpadc_vbus_v_open,
2013 .llseek = seq_lseek,
2014 .release = single_release,
2015 .owner = THIS_MODULE,
2018 static int ab8500_gpadc_main_charger_c_print(struct seq_file *s, void *p)
2020 int main_charger_c_raw;
2021 int main_charger_c_convert;
2022 struct ab8500_gpadc *gpadc;
2024 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2025 main_charger_c_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_C,
2026 avg_sample, trig_edge, trig_timer, conv_type);
2027 main_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
2028 MAIN_CHARGER_C, main_charger_c_raw);
2030 seq_printf(s, "%d,0x%X\n", main_charger_c_convert, main_charger_c_raw);
2035 static int ab8500_gpadc_main_charger_c_open(struct inode *inode,
2038 return single_open(file, ab8500_gpadc_main_charger_c_print,
2042 static const struct file_operations ab8500_gpadc_main_charger_c_fops = {
2043 .open = ab8500_gpadc_main_charger_c_open,
2045 .llseek = seq_lseek,
2046 .release = single_release,
2047 .owner = THIS_MODULE,
2050 static int ab8500_gpadc_usb_charger_c_print(struct seq_file *s, void *p)
2052 int usb_charger_c_raw;
2053 int usb_charger_c_convert;
2054 struct ab8500_gpadc *gpadc;
2056 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2057 usb_charger_c_raw = ab8500_gpadc_read_raw(gpadc, USB_CHARGER_C,
2058 avg_sample, trig_edge, trig_timer, conv_type);
2059 usb_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
2060 USB_CHARGER_C, usb_charger_c_raw);
2062 seq_printf(s, "%d,0x%X\n", usb_charger_c_convert, usb_charger_c_raw);
2067 static int ab8500_gpadc_usb_charger_c_open(struct inode *inode,
2070 return single_open(file, ab8500_gpadc_usb_charger_c_print,
2074 static const struct file_operations ab8500_gpadc_usb_charger_c_fops = {
2075 .open = ab8500_gpadc_usb_charger_c_open,
2077 .llseek = seq_lseek,
2078 .release = single_release,
2079 .owner = THIS_MODULE,
2082 static int ab8500_gpadc_bk_bat_v_print(struct seq_file *s, void *p)
2085 int bk_bat_v_convert;
2086 struct ab8500_gpadc *gpadc;
2088 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2089 bk_bat_v_raw = ab8500_gpadc_read_raw(gpadc, BK_BAT_V,
2090 avg_sample, trig_edge, trig_timer, conv_type);
2091 bk_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
2092 BK_BAT_V, bk_bat_v_raw);
2094 seq_printf(s, "%d,0x%X\n", bk_bat_v_convert, bk_bat_v_raw);
2099 static int ab8500_gpadc_bk_bat_v_open(struct inode *inode, struct file *file)
2101 return single_open(file, ab8500_gpadc_bk_bat_v_print,
2105 static const struct file_operations ab8500_gpadc_bk_bat_v_fops = {
2106 .open = ab8500_gpadc_bk_bat_v_open,
2108 .llseek = seq_lseek,
2109 .release = single_release,
2110 .owner = THIS_MODULE,
2113 static int ab8500_gpadc_die_temp_print(struct seq_file *s, void *p)
2116 int die_temp_convert;
2117 struct ab8500_gpadc *gpadc;
2119 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2120 die_temp_raw = ab8500_gpadc_read_raw(gpadc, DIE_TEMP,
2121 avg_sample, trig_edge, trig_timer, conv_type);
2122 die_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, DIE_TEMP,
2125 seq_printf(s, "%d,0x%X\n", die_temp_convert, die_temp_raw);
2130 static int ab8500_gpadc_die_temp_open(struct inode *inode, struct file *file)
2132 return single_open(file, ab8500_gpadc_die_temp_print,
2136 static const struct file_operations ab8500_gpadc_die_temp_fops = {
2137 .open = ab8500_gpadc_die_temp_open,
2139 .llseek = seq_lseek,
2140 .release = single_release,
2141 .owner = THIS_MODULE,
2144 static int ab8500_gpadc_usb_id_print(struct seq_file *s, void *p)
2148 struct ab8500_gpadc *gpadc;
2150 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2151 usb_id_raw = ab8500_gpadc_read_raw(gpadc, USB_ID,
2152 avg_sample, trig_edge, trig_timer, conv_type);
2153 usb_id_convert = ab8500_gpadc_ad_to_voltage(gpadc, USB_ID,
2156 seq_printf(s, "%d,0x%X\n", usb_id_convert, usb_id_raw);
2161 static int ab8500_gpadc_usb_id_open(struct inode *inode, struct file *file)
2163 return single_open(file, ab8500_gpadc_usb_id_print, inode->i_private);
2166 static const struct file_operations ab8500_gpadc_usb_id_fops = {
2167 .open = ab8500_gpadc_usb_id_open,
2169 .llseek = seq_lseek,
2170 .release = single_release,
2171 .owner = THIS_MODULE,
2174 static int ab8540_gpadc_xtal_temp_print(struct seq_file *s, void *p)
2177 int xtal_temp_convert;
2178 struct ab8500_gpadc *gpadc;
2180 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2181 xtal_temp_raw = ab8500_gpadc_read_raw(gpadc, XTAL_TEMP,
2182 avg_sample, trig_edge, trig_timer, conv_type);
2183 xtal_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, XTAL_TEMP,
2186 seq_printf(s, "%d,0x%X\n", xtal_temp_convert, xtal_temp_raw);
2191 static int ab8540_gpadc_xtal_temp_open(struct inode *inode, struct file *file)
2193 return single_open(file, ab8540_gpadc_xtal_temp_print,
2197 static const struct file_operations ab8540_gpadc_xtal_temp_fops = {
2198 .open = ab8540_gpadc_xtal_temp_open,
2200 .llseek = seq_lseek,
2201 .release = single_release,
2202 .owner = THIS_MODULE,
2205 static int ab8540_gpadc_vbat_true_meas_print(struct seq_file *s, void *p)
2207 int vbat_true_meas_raw;
2208 int vbat_true_meas_convert;
2209 struct ab8500_gpadc *gpadc;
2211 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2212 vbat_true_meas_raw = ab8500_gpadc_read_raw(gpadc, VBAT_TRUE_MEAS,
2213 avg_sample, trig_edge, trig_timer, conv_type);
2214 vbat_true_meas_convert =
2215 ab8500_gpadc_ad_to_voltage(gpadc, VBAT_TRUE_MEAS,
2216 vbat_true_meas_raw);
2218 seq_printf(s, "%d,0x%X\n", vbat_true_meas_convert, vbat_true_meas_raw);
2223 static int ab8540_gpadc_vbat_true_meas_open(struct inode *inode,
2226 return single_open(file, ab8540_gpadc_vbat_true_meas_print,
2230 static const struct file_operations ab8540_gpadc_vbat_true_meas_fops = {
2231 .open = ab8540_gpadc_vbat_true_meas_open,
2233 .llseek = seq_lseek,
2234 .release = single_release,
2235 .owner = THIS_MODULE,
2238 static int ab8540_gpadc_bat_ctrl_and_ibat_print(struct seq_file *s, void *p)
2241 int bat_ctrl_convert;
2244 struct ab8500_gpadc *gpadc;
2246 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2247 bat_ctrl_raw = ab8500_gpadc_double_read_raw(gpadc, BAT_CTRL_AND_IBAT,
2248 avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
2250 bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc, BAT_CTRL,
2252 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2258 bat_ctrl_convert, bat_ctrl_raw,
2259 ibat_convert, ibat_raw);
2264 static int ab8540_gpadc_bat_ctrl_and_ibat_open(struct inode *inode,
2267 return single_open(file, ab8540_gpadc_bat_ctrl_and_ibat_print,
2271 static const struct file_operations ab8540_gpadc_bat_ctrl_and_ibat_fops = {
2272 .open = ab8540_gpadc_bat_ctrl_and_ibat_open,
2274 .llseek = seq_lseek,
2275 .release = single_release,
2276 .owner = THIS_MODULE,
2279 static int ab8540_gpadc_vbat_meas_and_ibat_print(struct seq_file *s, void *p)
2282 int vbat_meas_convert;
2285 struct ab8500_gpadc *gpadc;
2287 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2288 vbat_meas_raw = ab8500_gpadc_double_read_raw(gpadc, VBAT_MEAS_AND_IBAT,
2289 avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
2290 vbat_meas_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V,
2292 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2298 vbat_meas_convert, vbat_meas_raw,
2299 ibat_convert, ibat_raw);
2304 static int ab8540_gpadc_vbat_meas_and_ibat_open(struct inode *inode,
2307 return single_open(file, ab8540_gpadc_vbat_meas_and_ibat_print,
2311 static const struct file_operations ab8540_gpadc_vbat_meas_and_ibat_fops = {
2312 .open = ab8540_gpadc_vbat_meas_and_ibat_open,
2314 .llseek = seq_lseek,
2315 .release = single_release,
2316 .owner = THIS_MODULE,
2319 static int ab8540_gpadc_vbat_true_meas_and_ibat_print(struct seq_file *s,
2322 int vbat_true_meas_raw;
2323 int vbat_true_meas_convert;
2326 struct ab8500_gpadc *gpadc;
2328 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2329 vbat_true_meas_raw = ab8500_gpadc_double_read_raw(gpadc,
2330 VBAT_TRUE_MEAS_AND_IBAT, avg_sample, trig_edge,
2331 trig_timer, conv_type, &ibat_raw);
2332 vbat_true_meas_convert = ab8500_gpadc_ad_to_voltage(gpadc,
2333 VBAT_TRUE_MEAS, vbat_true_meas_raw);
2334 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2340 vbat_true_meas_convert, vbat_true_meas_raw,
2341 ibat_convert, ibat_raw);
2346 static int ab8540_gpadc_vbat_true_meas_and_ibat_open(struct inode *inode,
2349 return single_open(file, ab8540_gpadc_vbat_true_meas_and_ibat_print,
2353 static const struct file_operations
2354 ab8540_gpadc_vbat_true_meas_and_ibat_fops = {
2355 .open = ab8540_gpadc_vbat_true_meas_and_ibat_open,
2357 .llseek = seq_lseek,
2358 .release = single_release,
2359 .owner = THIS_MODULE,
2362 static int ab8540_gpadc_bat_temp_and_ibat_print(struct seq_file *s, void *p)
2365 int bat_temp_convert;
2368 struct ab8500_gpadc *gpadc;
2370 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2371 bat_temp_raw = ab8500_gpadc_double_read_raw(gpadc, BAT_TEMP_AND_IBAT,
2372 avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
2373 bat_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL,
2375 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2381 bat_temp_convert, bat_temp_raw,
2382 ibat_convert, ibat_raw);
2387 static int ab8540_gpadc_bat_temp_and_ibat_open(struct inode *inode,
2390 return single_open(file, ab8540_gpadc_bat_temp_and_ibat_print,
2394 static const struct file_operations ab8540_gpadc_bat_temp_and_ibat_fops = {
2395 .open = ab8540_gpadc_bat_temp_and_ibat_open,
2397 .llseek = seq_lseek,
2398 .release = single_release,
2399 .owner = THIS_MODULE,
2402 static int ab8540_gpadc_otp_cal_print(struct seq_file *s, void *p)
2404 struct ab8500_gpadc *gpadc;
2405 u16 vmain_l, vmain_h, btemp_l, btemp_h;
2406 u16 vbat_l, vbat_h, ibat_l, ibat_h;
2408 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2409 ab8540_gpadc_get_otp(gpadc, &vmain_l, &vmain_h, &btemp_l, &btemp_h,
2410 &vbat_l, &vbat_h, &ibat_l, &ibat_h);
2420 vmain_l, vmain_h, btemp_l, btemp_h,
2421 vbat_l, vbat_h, ibat_l, ibat_h);
2426 static int ab8540_gpadc_otp_cal_open(struct inode *inode, struct file *file)
2428 return single_open(file, ab8540_gpadc_otp_cal_print, inode->i_private);
2431 static const struct file_operations ab8540_gpadc_otp_calib_fops = {
2432 .open = ab8540_gpadc_otp_cal_open,
2434 .llseek = seq_lseek,
2435 .release = single_release,
2436 .owner = THIS_MODULE,
2439 static int ab8500_gpadc_avg_sample_print(struct seq_file *s, void *p)
2441 seq_printf(s, "%d\n", avg_sample);
2446 static int ab8500_gpadc_avg_sample_open(struct inode *inode, struct file *file)
2448 return single_open(file, ab8500_gpadc_avg_sample_print,
2452 static ssize_t ab8500_gpadc_avg_sample_write(struct file *file,
2453 const char __user *user_buf,
2454 size_t count, loff_t *ppos)
2456 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2457 unsigned long user_avg_sample;
2460 err = kstrtoul_from_user(user_buf, count, 0, &user_avg_sample);
2464 if ((user_avg_sample == SAMPLE_1) || (user_avg_sample == SAMPLE_4)
2465 || (user_avg_sample == SAMPLE_8)
2466 || (user_avg_sample == SAMPLE_16)) {
2467 avg_sample = (u8) user_avg_sample;
2470 "debugfs err input: should be egal to 1, 4, 8 or 16\n");
2477 static const struct file_operations ab8500_gpadc_avg_sample_fops = {
2478 .open = ab8500_gpadc_avg_sample_open,
2480 .write = ab8500_gpadc_avg_sample_write,
2481 .llseek = seq_lseek,
2482 .release = single_release,
2483 .owner = THIS_MODULE,
2486 static int ab8500_gpadc_trig_edge_print(struct seq_file *s, void *p)
2488 seq_printf(s, "%d\n", trig_edge);
2493 static int ab8500_gpadc_trig_edge_open(struct inode *inode, struct file *file)
2495 return single_open(file, ab8500_gpadc_trig_edge_print,
2499 static ssize_t ab8500_gpadc_trig_edge_write(struct file *file,
2500 const char __user *user_buf,
2501 size_t count, loff_t *ppos)
2503 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2504 unsigned long user_trig_edge;
2507 err = kstrtoul_from_user(user_buf, count, 0, &user_trig_edge);
2511 if ((user_trig_edge == RISING_EDGE)
2512 || (user_trig_edge == FALLING_EDGE)) {
2513 trig_edge = (u8) user_trig_edge;
2515 dev_err(dev, "Wrong input:\n"
2516 "Enter 0. Rising edge\n"
2517 "Enter 1. Falling edge\n");
2524 static const struct file_operations ab8500_gpadc_trig_edge_fops = {
2525 .open = ab8500_gpadc_trig_edge_open,
2527 .write = ab8500_gpadc_trig_edge_write,
2528 .llseek = seq_lseek,
2529 .release = single_release,
2530 .owner = THIS_MODULE,
2533 static int ab8500_gpadc_trig_timer_print(struct seq_file *s, void *p)
2535 seq_printf(s, "%d\n", trig_timer);
2540 static int ab8500_gpadc_trig_timer_open(struct inode *inode, struct file *file)
2542 return single_open(file, ab8500_gpadc_trig_timer_print,
2546 static ssize_t ab8500_gpadc_trig_timer_write(struct file *file,
2547 const char __user *user_buf,
2548 size_t count, loff_t *ppos)
2550 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2551 unsigned long user_trig_timer;
2554 err = kstrtoul_from_user(user_buf, count, 0, &user_trig_timer);
2558 if (user_trig_timer & ~0xFF) {
2560 "debugfs error input: should be beetween 0 to 255\n");
2564 trig_timer = (u8) user_trig_timer;
2569 static const struct file_operations ab8500_gpadc_trig_timer_fops = {
2570 .open = ab8500_gpadc_trig_timer_open,
2572 .write = ab8500_gpadc_trig_timer_write,
2573 .llseek = seq_lseek,
2574 .release = single_release,
2575 .owner = THIS_MODULE,
2578 static int ab8500_gpadc_conv_type_print(struct seq_file *s, void *p)
2580 seq_printf(s, "%d\n", conv_type);
2585 static int ab8500_gpadc_conv_type_open(struct inode *inode, struct file *file)
2587 return single_open(file, ab8500_gpadc_conv_type_print,
2591 static ssize_t ab8500_gpadc_conv_type_write(struct file *file,
2592 const char __user *user_buf,
2593 size_t count, loff_t *ppos)
2595 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2596 unsigned long user_conv_type;
2599 err = kstrtoul_from_user(user_buf, count, 0, &user_conv_type);
2603 if ((user_conv_type == ADC_SW)
2604 || (user_conv_type == ADC_HW)) {
2605 conv_type = (u8) user_conv_type;
2607 dev_err(dev, "Wrong input:\n"
2608 "Enter 0. ADC SW conversion\n"
2609 "Enter 1. ADC HW conversion\n");
2616 static const struct file_operations ab8500_gpadc_conv_type_fops = {
2617 .open = ab8500_gpadc_conv_type_open,
2619 .write = ab8500_gpadc_conv_type_write,
2620 .llseek = seq_lseek,
2621 .release = single_release,
2622 .owner = THIS_MODULE,
2626 * return length of an ASCII numerical value, 0 is string is not a
2628 * string shall start at value 1st char.
2629 * string can be tailed with \0 or space or newline chars only.
2630 * value can be decimal or hexadecimal (prefixed 0x or 0X).
2632 static int strval_len(char *b)
2636 if ((*s == '0') && ((*(s+1) == 'x') || (*(s+1) == 'X'))) {
2638 for (; *s && (*s != ' ') && (*s != '\n'); s++) {
2645 for (; *s && (*s != ' ') && (*s != '\n'); s++) {
2654 * parse hwreg input data.
2655 * update global hwreg_cfg only if input data syntax is ok.
2657 static ssize_t hwreg_common_write(char *b, struct hwreg_cfg *cfg,
2660 uint write, val = 0;
2663 struct hwreg_cfg loc = {
2664 .bank = 0, /* default: invalid phys addr */
2665 .addr = 0, /* default: invalid phys addr */
2666 .fmt = 0, /* default: 32bit access, hex output */
2667 .mask = 0xFFFFFFFF, /* default: no mask */
2668 .shift = 0, /* default: no bit shift */
2671 /* read or write ? */
2672 if (!strncmp(b, "read ", 5)) {
2675 } else if (!strncmp(b, "write ", 6)) {
2681 /* OPTIONS -l|-w|-b -s -m -o */
2682 while ((*b == ' ') || (*b == '-')) {
2683 if (*(b-1) != ' ') {
2687 if ((!strncmp(b, "-d ", 3)) ||
2688 (!strncmp(b, "-dec ", 5))) {
2689 b += (*(b+2) == ' ') ? 3 : 5;
2691 } else if ((!strncmp(b, "-h ", 3)) ||
2692 (!strncmp(b, "-hex ", 5))) {
2693 b += (*(b+2) == ' ') ? 3 : 5;
2695 } else if ((!strncmp(b, "-m ", 3)) ||
2696 (!strncmp(b, "-mask ", 6))) {
2697 b += (*(b+2) == ' ') ? 3 : 6;
2698 if (strval_len(b) == 0)
2700 ret = kstrtoul(b, 0, &loc.mask);
2703 } else if ((!strncmp(b, "-s ", 3)) ||
2704 (!strncmp(b, "-shift ", 7))) {
2705 b += (*(b+2) == ' ') ? 3 : 7;
2706 if (strval_len(b) == 0)
2708 ret = kstrtol(b, 0, &loc.shift);
2715 /* get arg BANK and ADDRESS */
2716 if (strval_len(b) == 0)
2718 ret = kstrtouint(b, 0, &loc.bank);
2723 if (strval_len(b) == 0)
2725 ret = kstrtoul(b, 0, &loc.addr);
2732 if (strval_len(b) == 0)
2734 ret = kstrtouint(b, 0, &val);
2739 /* args are ok, update target cfg (mainly for read) */
2742 #ifdef ABB_HWREG_DEBUG
2743 pr_warn("HWREG request: %s, %s,\n"
2744 " addr=0x%08X, mask=0x%X, shift=%d" "value=0x%X\n",
2745 (write) ? "write" : "read",
2746 REG_FMT_DEC(cfg) ? "decimal" : "hexa",
2747 cfg->addr, cfg->mask, cfg->shift, val);
2753 ret = abx500_get_register_interruptible(dev,
2754 (u8)cfg->bank, (u8)cfg->addr, ®value);
2756 dev_err(dev, "abx500_get_reg fail %d, %d\n",
2761 if (cfg->shift >= 0) {
2762 regvalue &= ~(cfg->mask << (cfg->shift));
2763 val = (val & cfg->mask) << (cfg->shift);
2765 regvalue &= ~(cfg->mask >> (-cfg->shift));
2766 val = (val & cfg->mask) >> (-cfg->shift);
2768 val = val | regvalue;
2770 ret = abx500_set_register_interruptible(dev,
2771 (u8)cfg->bank, (u8)cfg->addr, (u8)val);
2773 pr_err("abx500_set_reg failed %d, %d", ret, __LINE__);
2780 static ssize_t ab8500_hwreg_write(struct file *file,
2781 const char __user *user_buf, size_t count, loff_t *ppos)
2783 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2787 /* Get userspace string and assure termination */
2788 buf_size = min(count, (sizeof(buf)-1));
2789 if (copy_from_user(buf, user_buf, buf_size))
2793 /* get args and process */
2794 ret = hwreg_common_write(buf, &hwreg_cfg, dev);
2795 return (ret) ? ret : buf_size;
2799 * - irq subscribe/unsubscribe stuff
2801 static int ab8500_subscribe_unsubscribe_print(struct seq_file *s, void *p)
2803 seq_printf(s, "%d\n", irq_first);
2808 static int ab8500_subscribe_unsubscribe_open(struct inode *inode,
2811 return single_open(file, ab8500_subscribe_unsubscribe_print,
2816 * Userspace should use poll() on this file. When an event occur
2817 * the blocking poll will be released.
2819 static ssize_t show_irq(struct device *dev,
2820 struct device_attribute *attr, char *buf)
2823 unsigned int irq_index;
2826 err = kstrtoul(attr->attr.name, 0, &name);
2830 irq_index = name - irq_first;
2831 if (irq_index >= num_irqs)
2834 return sprintf(buf, "%u\n", irq_count[irq_index]);
2837 static ssize_t ab8500_subscribe_write(struct file *file,
2838 const char __user *user_buf,
2839 size_t count, loff_t *ppos)
2841 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2842 unsigned long user_val;
2844 unsigned int irq_index;
2846 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
2850 if (user_val < irq_first) {
2851 dev_err(dev, "debugfs error input < %d\n", irq_first);
2854 if (user_val > irq_last) {
2855 dev_err(dev, "debugfs error input > %d\n", irq_last);
2859 irq_index = user_val - irq_first;
2860 if (irq_index >= num_irqs)
2864 * This will create a sysfs file named <irq-nr> which userspace can
2865 * use to select or poll and get the AB8500 events
2867 dev_attr[irq_index] = kmalloc(sizeof(struct device_attribute),
2869 if (!dev_attr[irq_index])
2872 event_name[irq_index] = kmalloc(count, GFP_KERNEL);
2873 if (!event_name[irq_index])
2876 sprintf(event_name[irq_index], "%lu", user_val);
2877 dev_attr[irq_index]->show = show_irq;
2878 dev_attr[irq_index]->store = NULL;
2879 dev_attr[irq_index]->attr.name = event_name[irq_index];
2880 dev_attr[irq_index]->attr.mode = S_IRUGO;
2881 err = sysfs_create_file(&dev->kobj, &dev_attr[irq_index]->attr);
2883 pr_info("sysfs_create_file failed %d\n", err);
2887 err = request_threaded_irq(user_val, NULL, ab8500_debug_handler,
2888 IRQF_SHARED | IRQF_NO_SUSPEND | IRQF_ONESHOT,
2889 "ab8500-debug", &dev->kobj);
2891 pr_info("request_threaded_irq failed %d, %lu\n",
2893 sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr);
2900 static ssize_t ab8500_unsubscribe_write(struct file *file,
2901 const char __user *user_buf,
2902 size_t count, loff_t *ppos)
2904 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2905 unsigned long user_val;
2907 unsigned int irq_index;
2909 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
2913 if (user_val < irq_first) {
2914 dev_err(dev, "debugfs error input < %d\n", irq_first);
2917 if (user_val > irq_last) {
2918 dev_err(dev, "debugfs error input > %d\n", irq_last);
2922 irq_index = user_val - irq_first;
2923 if (irq_index >= num_irqs)
2926 /* Set irq count to 0 when unsubscribe */
2927 irq_count[irq_index] = 0;
2929 if (dev_attr[irq_index])
2930 sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr);
2933 free_irq(user_val, &dev->kobj);
2934 kfree(event_name[irq_index]);
2935 kfree(dev_attr[irq_index]);
2941 * - several deubgfs nodes fops
2944 static const struct file_operations ab8500_bank_fops = {
2945 .open = ab8500_bank_open,
2946 .write = ab8500_bank_write,
2948 .llseek = seq_lseek,
2949 .release = single_release,
2950 .owner = THIS_MODULE,
2953 static const struct file_operations ab8500_address_fops = {
2954 .open = ab8500_address_open,
2955 .write = ab8500_address_write,
2957 .llseek = seq_lseek,
2958 .release = single_release,
2959 .owner = THIS_MODULE,
2962 static const struct file_operations ab8500_val_fops = {
2963 .open = ab8500_val_open,
2964 .write = ab8500_val_write,
2966 .llseek = seq_lseek,
2967 .release = single_release,
2968 .owner = THIS_MODULE,
2971 static const struct file_operations ab8500_interrupts_fops = {
2972 .open = ab8500_interrupts_open,
2974 .llseek = seq_lseek,
2975 .release = single_release,
2976 .owner = THIS_MODULE,
2979 static const struct file_operations ab8500_subscribe_fops = {
2980 .open = ab8500_subscribe_unsubscribe_open,
2981 .write = ab8500_subscribe_write,
2983 .llseek = seq_lseek,
2984 .release = single_release,
2985 .owner = THIS_MODULE,
2988 static const struct file_operations ab8500_unsubscribe_fops = {
2989 .open = ab8500_subscribe_unsubscribe_open,
2990 .write = ab8500_unsubscribe_write,
2992 .llseek = seq_lseek,
2993 .release = single_release,
2994 .owner = THIS_MODULE,
2997 static const struct file_operations ab8500_hwreg_fops = {
2998 .open = ab8500_hwreg_open,
2999 .write = ab8500_hwreg_write,
3001 .llseek = seq_lseek,
3002 .release = single_release,
3003 .owner = THIS_MODULE,
3006 static struct dentry *ab8500_dir;
3007 static struct dentry *ab8500_gpadc_dir;
3009 static int ab8500_debug_probe(struct platform_device *plf)
3011 struct dentry *file;
3012 struct ab8500 *ab8500;
3013 struct resource *res;
3015 debug_bank = AB8500_MISC;
3016 debug_address = AB8500_REV_REG & 0x00FF;
3018 ab8500 = dev_get_drvdata(plf->dev.parent);
3019 num_irqs = ab8500->mask_size;
3021 irq_count = devm_kzalloc(&plf->dev,
3022 sizeof(*irq_count)*num_irqs, GFP_KERNEL);
3026 dev_attr = devm_kzalloc(&plf->dev,
3027 sizeof(*dev_attr)*num_irqs, GFP_KERNEL);
3031 event_name = devm_kzalloc(&plf->dev,
3032 sizeof(*event_name)*num_irqs, GFP_KERNEL);
3036 res = platform_get_resource_byname(plf, 0, "IRQ_AB8500");
3038 dev_err(&plf->dev, "AB8500 irq not found, err %d\n", irq_first);
3041 irq_ab8500 = res->start;
3043 irq_first = platform_get_irq_byname(plf, "IRQ_FIRST");
3044 if (irq_first < 0) {
3045 dev_err(&plf->dev, "First irq not found, err %d\n", irq_first);
3049 irq_last = platform_get_irq_byname(plf, "IRQ_LAST");
3051 dev_err(&plf->dev, "Last irq not found, err %d\n", irq_last);
3055 ab8500_dir = debugfs_create_dir(AB8500_NAME_STRING, NULL);
3059 ab8500_gpadc_dir = debugfs_create_dir(AB8500_ADC_NAME_STRING,
3061 if (!ab8500_gpadc_dir)
3064 file = debugfs_create_file("all-bank-registers", S_IRUGO, ab8500_dir,
3065 &plf->dev, &ab8500_registers_fops);
3069 file = debugfs_create_file("all-banks", S_IRUGO, ab8500_dir,
3070 &plf->dev, &ab8500_all_banks_fops);
3074 file = debugfs_create_file("register-bank",
3075 (S_IRUGO | S_IWUSR | S_IWGRP),
3076 ab8500_dir, &plf->dev, &ab8500_bank_fops);
3080 file = debugfs_create_file("register-address",
3081 (S_IRUGO | S_IWUSR | S_IWGRP),
3082 ab8500_dir, &plf->dev, &ab8500_address_fops);
3086 file = debugfs_create_file("register-value",
3087 (S_IRUGO | S_IWUSR | S_IWGRP),
3088 ab8500_dir, &plf->dev, &ab8500_val_fops);
3092 file = debugfs_create_file("irq-subscribe",
3093 (S_IRUGO | S_IWUSR | S_IWGRP), ab8500_dir,
3094 &plf->dev, &ab8500_subscribe_fops);
3098 if (is_ab8500(ab8500)) {
3099 debug_ranges = ab8500_debug_ranges;
3100 num_interrupt_lines = AB8500_NR_IRQS;
3101 } else if (is_ab8505(ab8500)) {
3102 debug_ranges = ab8505_debug_ranges;
3103 num_interrupt_lines = AB8505_NR_IRQS;
3104 } else if (is_ab9540(ab8500)) {
3105 debug_ranges = ab8505_debug_ranges;
3106 num_interrupt_lines = AB9540_NR_IRQS;
3107 } else if (is_ab8540(ab8500)) {
3108 debug_ranges = ab8540_debug_ranges;
3109 num_interrupt_lines = AB8540_NR_IRQS;
3112 file = debugfs_create_file("interrupts", (S_IRUGO), ab8500_dir,
3113 &plf->dev, &ab8500_interrupts_fops);
3117 file = debugfs_create_file("irq-unsubscribe",
3118 (S_IRUGO | S_IWUSR | S_IWGRP), ab8500_dir,
3119 &plf->dev, &ab8500_unsubscribe_fops);
3123 file = debugfs_create_file("hwreg", (S_IRUGO | S_IWUSR | S_IWGRP),
3124 ab8500_dir, &plf->dev, &ab8500_hwreg_fops);
3128 file = debugfs_create_file("all-modem-registers",
3129 (S_IRUGO | S_IWUSR | S_IWGRP),
3130 ab8500_dir, &plf->dev, &ab8500_modem_fops);
3134 file = debugfs_create_file("bat_ctrl", (S_IRUGO | S_IWUSR | S_IWGRP),
3135 ab8500_gpadc_dir, &plf->dev,
3136 &ab8500_gpadc_bat_ctrl_fops);
3140 file = debugfs_create_file("btemp_ball", (S_IRUGO | S_IWUSR | S_IWGRP),
3142 &plf->dev, &ab8500_gpadc_btemp_ball_fops);
3146 file = debugfs_create_file("main_charger_v",
3147 (S_IRUGO | S_IWUSR | S_IWGRP),
3148 ab8500_gpadc_dir, &plf->dev,
3149 &ab8500_gpadc_main_charger_v_fops);
3153 file = debugfs_create_file("acc_detect1",
3154 (S_IRUGO | S_IWUSR | S_IWGRP),
3155 ab8500_gpadc_dir, &plf->dev,
3156 &ab8500_gpadc_acc_detect1_fops);
3160 file = debugfs_create_file("acc_detect2",
3161 (S_IRUGO | S_IWUSR | S_IWGRP),
3162 ab8500_gpadc_dir, &plf->dev,
3163 &ab8500_gpadc_acc_detect2_fops);
3167 file = debugfs_create_file("adc_aux1", (S_IRUGO | S_IWUSR | S_IWGRP),
3168 ab8500_gpadc_dir, &plf->dev,
3169 &ab8500_gpadc_aux1_fops);
3173 file = debugfs_create_file("adc_aux2", (S_IRUGO | S_IWUSR | S_IWGRP),
3174 ab8500_gpadc_dir, &plf->dev,
3175 &ab8500_gpadc_aux2_fops);
3179 file = debugfs_create_file("main_bat_v", (S_IRUGO | S_IWUSR | S_IWGRP),
3180 ab8500_gpadc_dir, &plf->dev,
3181 &ab8500_gpadc_main_bat_v_fops);
3185 file = debugfs_create_file("vbus_v", (S_IRUGO | S_IWUSR | S_IWGRP),
3186 ab8500_gpadc_dir, &plf->dev,
3187 &ab8500_gpadc_vbus_v_fops);
3191 file = debugfs_create_file("main_charger_c",
3192 (S_IRUGO | S_IWUSR | S_IWGRP),
3193 ab8500_gpadc_dir, &plf->dev,
3194 &ab8500_gpadc_main_charger_c_fops);
3198 file = debugfs_create_file("usb_charger_c",
3199 (S_IRUGO | S_IWUSR | S_IWGRP),
3201 &plf->dev, &ab8500_gpadc_usb_charger_c_fops);
3205 file = debugfs_create_file("bk_bat_v", (S_IRUGO | S_IWUSR | S_IWGRP),
3206 ab8500_gpadc_dir, &plf->dev,
3207 &ab8500_gpadc_bk_bat_v_fops);
3211 file = debugfs_create_file("die_temp", (S_IRUGO | S_IWUSR | S_IWGRP),
3212 ab8500_gpadc_dir, &plf->dev,
3213 &ab8500_gpadc_die_temp_fops);
3217 file = debugfs_create_file("usb_id", (S_IRUGO | S_IWUSR | S_IWGRP),
3218 ab8500_gpadc_dir, &plf->dev,
3219 &ab8500_gpadc_usb_id_fops);
3223 if (is_ab8540(ab8500)) {
3224 file = debugfs_create_file("xtal_temp",
3225 (S_IRUGO | S_IWUSR | S_IWGRP),
3226 ab8500_gpadc_dir, &plf->dev,
3227 &ab8540_gpadc_xtal_temp_fops);
3230 file = debugfs_create_file("vbattruemeas",
3231 (S_IRUGO | S_IWUSR | S_IWGRP),
3232 ab8500_gpadc_dir, &plf->dev,
3233 &ab8540_gpadc_vbat_true_meas_fops);
3236 file = debugfs_create_file("batctrl_and_ibat",
3237 (S_IRUGO | S_IWUGO),
3240 &ab8540_gpadc_bat_ctrl_and_ibat_fops);
3243 file = debugfs_create_file("vbatmeas_and_ibat",
3244 (S_IRUGO | S_IWUGO),
3245 ab8500_gpadc_dir, &plf->dev,
3246 &ab8540_gpadc_vbat_meas_and_ibat_fops);
3249 file = debugfs_create_file("vbattruemeas_and_ibat",
3250 (S_IRUGO | S_IWUGO),
3253 &ab8540_gpadc_vbat_true_meas_and_ibat_fops);
3256 file = debugfs_create_file("battemp_and_ibat",
3257 (S_IRUGO | S_IWUGO),
3259 &plf->dev, &ab8540_gpadc_bat_temp_and_ibat_fops);
3262 file = debugfs_create_file("otp_calib",
3263 (S_IRUGO | S_IWUSR | S_IWGRP),
3265 &plf->dev, &ab8540_gpadc_otp_calib_fops);
3269 file = debugfs_create_file("avg_sample", (S_IRUGO | S_IWUSR | S_IWGRP),
3270 ab8500_gpadc_dir, &plf->dev,
3271 &ab8500_gpadc_avg_sample_fops);
3275 file = debugfs_create_file("trig_edge", (S_IRUGO | S_IWUSR | S_IWGRP),
3276 ab8500_gpadc_dir, &plf->dev,
3277 &ab8500_gpadc_trig_edge_fops);
3281 file = debugfs_create_file("trig_timer", (S_IRUGO | S_IWUSR | S_IWGRP),
3282 ab8500_gpadc_dir, &plf->dev,
3283 &ab8500_gpadc_trig_timer_fops);
3287 file = debugfs_create_file("conv_type", (S_IRUGO | S_IWUSR | S_IWGRP),
3288 ab8500_gpadc_dir, &plf->dev,
3289 &ab8500_gpadc_conv_type_fops);
3296 debugfs_remove_recursive(ab8500_dir);
3297 dev_err(&plf->dev, "failed to create debugfs entries.\n");
3302 static int ab8500_debug_remove(struct platform_device *plf)
3304 debugfs_remove_recursive(ab8500_dir);
3309 static struct platform_driver ab8500_debug_driver = {
3311 .name = "ab8500-debug",
3313 .probe = ab8500_debug_probe,
3314 .remove = ab8500_debug_remove
3317 static int __init ab8500_debug_init(void)
3319 return platform_driver_register(&ab8500_debug_driver);
3322 static void __exit ab8500_debug_exit(void)
3324 platform_driver_unregister(&ab8500_debug_driver);
3326 subsys_initcall(ab8500_debug_init);
3327 module_exit(ab8500_debug_exit);
3330 MODULE_DESCRIPTION("AB8500 DEBUG");
3331 MODULE_LICENSE("GPL v2");