* drivers/mfd/rt5025-debug.c
* Driver foo Richtek RT5025 PMIC Debug
*
- * Copyright (C) 2013 Richtek Electronics
+ * Copyright (C) 2013 Richtek Technologh Corp.
* cy_huang <cy_huang@richtek.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
+ * published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
*/
#include <linux/module.h>
#include <linux/err.h>
#include <linux/i2c.h>
#include <linux/platform_device.h>
-#include <linux/slab.h>
-
-#include <linux/uaccess.h>
#include <linux/debugfs.h>
-#include <linux/string.h>
+#include <linux/uaccess.h>
#include <linux/mfd/rt5025.h>
struct rt5025_debug_info {
struct i2c_client *i2c;
+ struct device *dev;
+ unsigned char reg_addr;
+ unsigned char reg_data;
};
-static struct i2c_client *client;
-static struct dentry *debugfs_rt_dent;
-static struct dentry *debugfs_peek;
-static struct dentry *debugfs_poke;
-static struct dentry *debugfs_regs;
+struct rt_debug_st {
+ void *info;
+ int id;
+};
+
+enum {
+ RT5025_DBG_REG,
+ RT5025_DBG_DATA,
+ RT5025_DBG_REGS,
+ RT5025_DBG_MAX
+};
-static unsigned char read_data[10];
+static struct dentry *debugfs_rt_dent;
+static struct dentry *debugfs_file[RT5025_DBG_MAX];
+static struct rt_debug_st rtdbg_data[RT5025_DBG_MAX];
static int reg_debug_open(struct inode *inode, struct file *file)
{
return -EINVAL;
token = strsep(&buf, " ");
- }
- else
+ } else {
return -EINVAL;
+ }
}
return 0;
}
-#define LOG_FORMAT "0x%02x\n0x%02x\n0x%02x\n0x%02x\n0x%02x\n"
-
static ssize_t reg_debug_read(struct file *filp, char __user *ubuf,
size_t count, loff_t *ppos)
{
- char *access_str = filp->private_data;
- char lbuf[150];
- if (!strcmp(access_str, "regs"))
- {
- RTINFO("read regs file\n");
- /* read regs */
- snprintf(lbuf, sizeof(lbuf), LOG_FORMAT LOG_FORMAT, read_data[0], \
- read_data[1], read_data[2], read_data[3], read_data[4], read_data[5], \
- read_data[6], read_data[7], read_data[8], read_data[9]);
+ struct rt_debug_st *st = filp->private_data;
+ struct rt5025_debug_info *di = st->info;
+ char lbuf[1000];
+ int i = 0, j = 0;
+
+ lbuf[0] = '\0';
+ switch (st->id) {
+ case RT5025_DBG_REG:
+ snprintf(lbuf, sizeof(lbuf), "0x%x\n", di->reg_addr);
+ break;
+ case RT5025_DBG_DATA:
+ di->reg_data = (unsigned char)rt5025_reg_read(di->i2c,
+ di->reg_addr);
+ snprintf(lbuf, sizeof(lbuf), "0x%x\n", di->reg_data);
+ break;
+ case RT5025_DBG_REGS:
+ for (i = RT5025_REG_RANGE1START;
+ i <= RT5025_REG_RANGE1END; i++)
+ j += sprintf(lbuf+j, "0x%02x:%02x\n", i, \
+ rt5025_reg_read(di->i2c, i));
+ for (i = RT5025_REG_RANGE2START;
+ i <= RT5025_REG_RANGE2END; i++)
+ j += sprintf(lbuf+j, "0x%02x:%02x\n", i, \
+ rt5025_reg_read(di->i2c, i));
+ for (i = RT5025_REG_RANGE3START;
+ i <= RT5025_REG_RANGE3END; i++)
+ j += sprintf(lbuf+j, "0x%02x:%02x\n", i, \
+ rt5025_reg_read(di->i2c, i));
+ for (i = RT5025_REG_RANGE4START;
+ i <= RT5025_REG_RANGE4END; i++)
+ j += sprintf(lbuf+j, "0x%02x:%02x\n", i, \
+ rt5025_reg_read(di->i2c, i));
+ break;
+ default:
+ return -EINVAL;
}
- else
- snprintf(lbuf, sizeof(lbuf), "0x%02x\n", read_data[0]);
return simple_read_from_buffer(ubuf, count, ppos, lbuf, strlen(lbuf));
}
static ssize_t reg_debug_write(struct file *filp,
const char __user *ubuf, size_t cnt, loff_t *ppos)
{
- char *access_str = filp->private_data;
+ struct rt_debug_st *st = filp->private_data;
+ struct rt5025_debug_info *di = st->info;
char lbuf[32];
int rc;
long int param[5];
lbuf[cnt] = '\0';
- if (!strcmp(access_str, "poke")) {
- /* write */
- rc = get_parameters(lbuf, param, 2);
- if ((param[0] <= 0xFF) && (param[1] <= 0xFF) && (rc == 0))
- {
- rt5025_reg_write(client, param[0], (unsigned char)param[1]);
- }
- else
- rc = -EINVAL;
- } else if (!strcmp(access_str, "peek")) {
- /* read */
+ switch (st->id) {
+ case RT5025_DBG_REG:
rc = get_parameters(lbuf, param, 1);
- if ((param[0] <= 0xFF) && (rc == 0))
- {
- read_data[0] = rt5025_reg_read(client, param[0]);
+ if ((param[0] < RT5025_REG_MAX) && (rc == 0)) {
+ if ((param[0] >= RT5025_REG_RANGE1START && param[0]
+ <= RT5025_REG_RANGE1END) || \
+ (param[0] >= RT5025_REG_RANGE2START && param[0]
+ <= RT5025_REG_RANGE2END) || \
+ (param[0] >= RT5025_REG_RANGE3START && param[0]
+ <= RT5025_REG_RANGE3END) || \
+ (param[0] >= RT5025_REG_RANGE4START && param[0]
+ <= RT5025_REG_RANGE4END))
+ di->reg_addr = (unsigned char)param[0];
+ else
+ rc = -EINVAL;
+ } else {
+ rc = -EINVAL;
}
- else
- rc = -EINVAL;
- } else if (!strcmp(access_str, "regs")) {
- /* read */
+ break;
+ case RT5025_DBG_DATA:
rc = get_parameters(lbuf, param, 1);
- if ((param[0] <= 0xFF) && (rc == 0))
- {
- rt5025_reg_block_read(client, param[0], 10, read_data);
- RTINFO("regs 0 = 0x%02x\n", read_data[0]);
- RTINFO("regs 1 = 0x%02x\n", read_data[1]);
- RTINFO("regs 2 = 0x%02x\n", read_data[2]);
- RTINFO("regs 3 = 0x%02x\n", read_data[3]);
- RTINFO("regs 4 = 0x%02x\n", read_data[4]);
- RTINFO("regs 5 = 0x%02x\n", read_data[5]);
- RTINFO("regs 6 = 0x%02x\n", read_data[6]);
- RTINFO("regs 7 = 0x%02x\n", read_data[7]);
- RTINFO("regs 8 = 0x%02x\n", read_data[8]);
- RTINFO("regs 9 = 0x%02x\n", read_data[9]);
- }
+ if ((param[0] <= 0xff) && (rc == 0))
+ rt5025_reg_write(di->i2c, di->reg_addr, param[0]);
else
rc = -EINVAL;
+ break;
+ default:
+ return -EINVAL;
}
-
if (rc == 0)
rc = cnt;
-
return rc;
}
.read = reg_debug_read
};
-static int __devinit rt5025_debug_probe(struct platform_device *pdev)
+static int rt5025_debug_probe(struct platform_device *pdev)
{
struct rt5025_chip *chip = dev_get_drvdata(pdev->dev.parent);
struct rt5025_debug_info *di;
+ int ret = 0;
- di = kzalloc(sizeof(*di), GFP_KERNEL);
+ di = devm_kzalloc(&pdev->dev, sizeof(*di), GFP_KERNEL);
if (!di)
return -ENOMEM;
di->i2c = chip->i2c;
+ di->dev = &pdev->dev;
- RTINFO("add debugfs for core RT5025");
- client = chip->i2c;
+ RTINFO("add debugfs for RT5025");
debugfs_rt_dent = debugfs_create_dir("rt5025_dbg", 0);
if (!IS_ERR(debugfs_rt_dent)) {
- debugfs_peek = debugfs_create_file("peek",
+ rtdbg_data[0].info = di;
+ rtdbg_data[0].id = RT5025_DBG_REG;
+ debugfs_file[0] = debugfs_create_file("reg",
S_IFREG | S_IRUGO, debugfs_rt_dent,
- (void *) "peek", ®_debug_ops);
+ (void *) &rtdbg_data[0], ®_debug_ops);
- debugfs_poke = debugfs_create_file("poke",
+ rtdbg_data[1].info = di;
+ rtdbg_data[1].id = RT5025_DBG_DATA;
+ debugfs_file[1] = debugfs_create_file("data",
S_IFREG | S_IRUGO, debugfs_rt_dent,
- (void *) "poke", ®_debug_ops);
+ (void *) &rtdbg_data[1], ®_debug_ops);
- debugfs_regs = debugfs_create_file("regs",
+ rtdbg_data[2].info = di;
+ rtdbg_data[2].id = RT5025_DBG_REGS;
+ debugfs_file[2] = debugfs_create_file("regs",
S_IFREG | S_IRUGO, debugfs_rt_dent,
- (void *) "regs", ®_debug_ops);
+ (void *) &rtdbg_data[2], ®_debug_ops);
+ } else {
+ dev_err(&pdev->dev, "create debugfs failed\n");
+ ret = -EINVAL;
+ goto err_init;
}
-
platform_set_drvdata(pdev, di);
-
return 0;
+err_init:
+ return ret;
}
-static int __devexit rt5025_debug_remove(struct platform_device *pdev)
+static int rt5025_debug_remove(struct platform_device *pdev)
{
- struct rt5025_debug_info *di = platform_get_drvdata(pdev);
-
if (!IS_ERR(debugfs_rt_dent))
debugfs_remove_recursive(debugfs_rt_dent);
-
- kfree(di);
return 0;
}
-static struct platform_driver rt5025_debug_driver =
-{
+static const struct of_device_id rt_match_table[] = {
+ { .compatible = "rt,rt5025-debug",},
+ {},
+};
+
+static struct platform_driver rt5025_debug_driver = {
.driver = {
- .name = RT5025_DEVICE_NAME "-debug",
+ .name = RT5025_DEV_NAME "-debug",
.owner = THIS_MODULE,
+ .of_match_table = rt_match_table,
},
.probe = rt5025_debug_probe,
- .remove = __devexit_p(rt5025_debug_remove),
+ .remove = rt5025_debug_remove,
};
-static int __init rt5025_debug_init(void)
+static int rt5025_debug_init(void)
{
return platform_driver_register(&rt5025_debug_driver);
}
module_init(rt5025_debug_init);
-static void __exit rt5025_debug_exit(void)
+static void rt5025_debug_exit(void)
{
platform_driver_unregister(&rt5025_debug_driver);
}
module_exit(rt5025_debug_exit);
-
-MODULE_LICENSE("GPL v2");
MODULE_AUTHOR("CY Huang <cy_huang@richtek.com");
MODULE_DESCRIPTION("Debug driver for RT5025");
-MODULE_ALIAS("platform:" RT5025_DEVICE_NAME "-debug");
+MODULE_ALIAS("platform:" RT5025_DEV_NAME "-debug");
+MODULE_VERSION(RT5025_DRV_VER);