diff options
author | Linqiang Pu <dpu@nvidia.com> | 2012-06-04 21:22:34 +0800 |
---|---|---|
committer | Simone Willett <swillett@nvidia.com> | 2012-06-11 16:07:25 -0700 |
commit | a79e68c19180953ba479b3730e2945974660b43d (patch) | |
tree | b9bf139d7b1748ff3d0b15f77d0e1d962ccbd9d5 /drivers/power | |
parent | aa6b5519136df2630344e10c27277943408b6fde (diff) |
power: smb349: added debugfs to dump registers.
also cleanup the driver code to remove warnings and indent issue.
Change-Id: I6fd81a369be9141a5819bf086078bc609360efd8
Signed-off-by: Linqiang Pu <dpu@nvidia.com>
Reviewed-on: http://git-master/r/106682
Reviewed-by: Simone Willett <swillett@nvidia.com>
Tested-by: Simone Willett <swillett@nvidia.com>
Diffstat (limited to 'drivers/power')
-rw-r--r-- | drivers/power/smb349-charger.c | 99 |
1 files changed, 95 insertions, 4 deletions
diff --git a/drivers/power/smb349-charger.c b/drivers/power/smb349-charger.c index 58778409b6ba..59ee98418354 100644 --- a/drivers/power/smb349-charger.c +++ b/drivers/power/smb349-charger.c @@ -36,6 +36,9 @@ #include <linux/interrupt.h> #include <linux/irq.h> #include <linux/usb/otg.h> +#include <linux/debugfs.h> +#include <linux/seq_file.h> +#include <linux/uaccess.h> #define SMB349_CHARGE 0x00 #define SMB349_CHRG_CRNTS 0x01 @@ -286,7 +289,7 @@ error: int update_charger_status(void) { struct i2c_client *client; - int ret, val; + int val; if (!charger) return -ENODEV; @@ -315,8 +318,6 @@ int update_charger_status(void) return 0; val_error: return val; -ret_error: - return ret; } EXPORT_SYMBOL_GPL(update_charger_status); @@ -425,13 +426,97 @@ static int smb349_enable_charging(struct regulator_dev *rdev, if (charger->charger_cb) charger->charger_cb(charger->state, charger->chrg_type, charger->charger_cb_data); -return 0; + return 0; } static struct regulator_ops smb349_tegra_regulator_ops = { .set_current_limit = smb349_enable_charging, }; +#if defined(CONFIG_DEBUG_FS) +static struct dentry *smb349_dentry_regs; + +static int smb349_dump_regs(struct i2c_client *client, u8 *addrs, int num_addrs, + char *buf, ssize_t *len) +{ + ssize_t count = *len; + int ret = 0; + int i; + + if (count >= PAGE_SIZE - 1) + return -ERANGE; + + for (i = 0; i < num_addrs; i++) { + count += sprintf(buf + count, "0x%02x: ", addrs[i]); + if (count >= PAGE_SIZE - 1) + return -ERANGE; + + ret = smb349_read(client, addrs[i]); + if (ret < 0) + count += sprintf(buf + count, "<read fail: %d\n", ret); + else + count += sprintf(buf + count, "0x%02x\n", ret); + + if (count >= PAGE_SIZE - 1) + return -ERANGE; + } + *len = count; + + return 0; +} + +static ssize_t smb349_debugfs_open(struct inode *inode, struct file *file) +{ + file->private_data = inode->i_private; + return 0; +} + +static u8 regs[] = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x09, 0x0A, 0x0B, + 0x0C, 0x0D, 0x0E, 0x10, 0x11, 0x12, 0x30, 0x31, 0x33, 0x35, 0x36, + 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F +}; +static ssize_t smb349_debugfs_read(struct file *file, char __user *user_buf, + size_t count, loff_t *ppos) +{ + ssize_t ret; + struct i2c_client *client = file->private_data; + char *buf; + size_t len = 0; + + buf = kzalloc(PAGE_SIZE, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + len += sprintf(buf + len, "SMB349 Registers\n"); + smb349_dump_regs(client, regs, ARRAY_SIZE(regs), buf, &len); + + ret = simple_read_from_buffer(user_buf, count, ppos, buf, len); + kfree(buf); + return ret; +} + +static const struct file_operations smb349_debugfs_fops = { + .open = smb349_debugfs_open, + .read = smb349_debugfs_read, +}; + +static void smb349_debugfs_init(struct i2c_client *client) +{ + smb349_dentry_regs = debugfs_create_file(client->name, + 0444, 0, client, + &smb349_debugfs_fops); +} + +static void smb349_debugfs_exit(struct i2c_client *client) +{ + debugfs_remove(smb349_dentry_regs); +} +#else +static void smb349_debugfs_init(struct i2c_client *client){} +static void smb349_debugfs_exit(struct i2c_client *client){} +#endif /* CONFIG_DEBUG_FS */ + static int __devinit smb349_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -493,6 +578,9 @@ static int __devinit smb349_probe(struct i2c_client *client, charger->rdev = regulator_register(&charger->reg_desc, charger->dev, &charger->reg_init_data, charger); + + smb349_debugfs_init(client); + if (IS_ERR(charger->rdev)) { dev_err(&client->dev, "failed to register %s\n", charger->reg_desc.name); @@ -500,6 +588,7 @@ static int __devinit smb349_probe(struct i2c_client *client, goto regulator_error; } + /* disable OTG */ ret = smb349_configure_otg(client, 0); if (ret < 0) { @@ -537,6 +626,7 @@ static int __devinit smb349_probe(struct i2c_client *client, return 0; error: + smb349_debugfs_exit(client); regulator_unregister(charger->rdev); regulator_error: kfree(charger); @@ -548,6 +638,7 @@ static int __devexit smb349_remove(struct i2c_client *client) { struct smb349_charger *charger = i2c_get_clientdata(client); + smb349_debugfs_exit(client); regulator_unregister(charger->rdev); kfree(charger); |