mfd: rk808: add sysfs debug node "/sys/rk8xx/rk8xx_dbg"
authorchenjh <chenjh@rock-chips.com>
Wed, 15 Feb 2017 11:48:03 +0000 (19:48 +0800)
committerHuang, Tao <huangtao@rock-chips.com>
Fri, 17 Feb 2017 09:18:56 +0000 (17:18 +0800)
Change-Id: I197dc97b7337414a7d52426da0e0cb8c7480c917
Signed-off-by: chenjh <chenjh@rock-chips.com>
drivers/mfd/rk808.c

index 9d9327828ca571be0864ccc14caea23d77a268b8..60b4a628b281255dc076a44ba5d072ee7be3d7c1 100644 (file)
@@ -467,6 +467,54 @@ static void rk808_device_shutdown(void)
        }
 }
 
+static ssize_t rk8xx_dbg_store(struct device *dev,
+                              struct device_attribute *attr,
+                              const char *buf, size_t count)
+{
+       int ret;
+       char cmd;
+       u32 input[2], addr, data;
+       struct rk808 *rk808 = i2c_get_clientdata(rk808_i2c_client);
+
+       ret = sscanf(buf, "%c ", &cmd);
+       switch (cmd) {
+       case 'w':
+               ret = sscanf(buf, "%c %x %x ", &cmd, &input[0], &input[1]);
+               if (ret != 3) {
+                       pr_err("erro! cmd format: echo w [addr] [value]\n");
+                       goto out;
+               };
+               addr = input[0] & 0xff;
+               data = input[1] & 0xff;
+               pr_info("cmd : %c %x %x\n\n", cmd, input[0], input[1]);
+               regmap_write(rk808->regmap, addr, data);
+               regmap_read(rk808->regmap, addr, &data);
+               pr_info("new: %x %x\n", addr, data);
+               break;
+       case 'r':
+               ret = sscanf(buf, "%c %x ", &cmd, &input[0]);
+               if (ret != 2) {
+                       pr_err("erro! cmd format: echo r [addr]\n");
+                       goto out;
+               };
+               pr_info("cmd : %c %x\n\n", cmd, input[0]);
+               addr = input[0] & 0xff;
+               regmap_read(rk808->regmap, addr, &data);
+               pr_info("%x %x\n", input[0], data);
+               break;
+       default:
+               pr_err("Unknown command\n");
+               break;
+       }
+
+out:
+       return count;
+}
+
+static struct kobject *rk8xx_kobj;
+static struct device_attribute rk8xx_attrs =
+               __ATTR(rk8xx_dbg, 0200, NULL, rk8xx_dbg_store);
+
 static const struct of_device_id rk808_of_match[] = {
        { .compatible = "rockchip,rk805" },
        { .compatible = "rockchip,rk808" },
@@ -628,6 +676,13 @@ static int rk808_probe(struct i2c_client *client,
                }
        }
 
+       rk8xx_kobj = kobject_create_and_add("rk8xx", NULL);
+       if (rk8xx_kobj) {
+               ret = sysfs_create_file(rk8xx_kobj, &rk8xx_attrs.attr);
+               if (ret)
+                       dev_err(&client->dev, "create rk8xx sysfs error\n");
+       }
+
        return 0;
 
 err_irq: