]> rtime.felk.cvut.cz Git - zynq/linux.git/commitdiff
firmware: zynqmp: Add sysfs interface
authorMichal Simek <michal.simek@xilinx.com>
Wed, 20 Mar 2019 14:18:32 +0000 (15:18 +0100)
committerMichal Simek <michal.simek@xilinx.com>
Mon, 1 Apr 2019 10:48:08 +0000 (12:48 +0200)
Wire sysfs interface.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
drivers/firmware/xilinx/zynqmp.c
include/linux/firmware/xlnx-zynqmp.h

index b3a6558fa84e7ab3c5898e79ff7073cbee833bde..7fab8132748a675b061f1b09c618dbc7411b35b2 100644 (file)
@@ -24,6 +24,8 @@
 #include <linux/firmware/xlnx-zynqmp.h>
 #include "zynqmp-debug.h"
 
+static unsigned long register_address;
+
 static const struct zynqmp_eemi_ops *eemi_ops_tbl;
 
 static const struct mfd_cell firmware_devs[] = {
@@ -475,6 +477,10 @@ static inline int zynqmp_is_valid_ioctl(u32 ioctl_id)
        case IOCTL_GET_PLL_FRAC_DATA:
        case IOCTL_SD_DLL_RESET:
        case IOCTL_SET_SD_TAPDELAY:
+       case IOCTL_WRITE_GGS:
+       case IOCTL_READ_GGS:
+       case IOCTL_WRITE_PGGS:
+       case IOCTL_READ_PGGS:
                return 1;
        default:
                return 0;
@@ -870,6 +876,161 @@ const struct zynqmp_eemi_ops *zynqmp_pm_get_eemi_ops(void)
 }
 EXPORT_SYMBOL_GPL(zynqmp_pm_get_eemi_ops);
 
+
+/**
+ * config_reg_store - Write config_reg sysfs attribute
+ * @kobj:      Kobject structure
+ * @attr:      Kobject attribute structure
+ * @buf:       User entered health_status attribute string
+ * @count:     Buffer size
+ *
+ * User-space interface for setting the config register.
+ *
+ * To write any CSU/PMU register
+ * echo <address> <mask> <values> > /sys/firmware/zynqmp/config_reg
+ * Usage:
+ * echo 0x345AB234 0xFFFFFFFF 0x1234ABCD > /sys/firmware/zynqmp/config_reg
+ *
+ * To Read any CSU/PMU register, write address to the variable like below
+ * echo <address> > /sys/firmware/zynqmp/config_reg
+ *
+ * Return:     count argument if request succeeds, the corresponding error
+ *             code otherwise
+ */
+static ssize_t config_reg_store(struct kobject *kobj,
+                               struct kobj_attribute *attr,
+                               const char *buf, size_t count)
+{
+       char *kern_buff, *inbuf, *tok;
+       unsigned long address, value, mask;
+       int ret;
+
+       kern_buff = kzalloc(count, GFP_KERNEL);
+       if (!kern_buff)
+               return -ENOMEM;
+
+       ret = strlcpy(kern_buff, buf, count);
+       if (ret < 0) {
+               ret = -EFAULT;
+               goto err;
+       }
+
+       inbuf = kern_buff;
+
+       /* Read the addess */
+       tok = strsep(&inbuf, " ");
+       if (!tok) {
+               ret = -EFAULT;
+               goto err;
+       }
+       ret = kstrtol(tok, 16, &address);
+       if (ret) {
+               ret = -EFAULT;
+               goto err;
+       }
+       /* Read the write value */
+       tok = strsep(&inbuf, " ");
+       /*
+        * If parameter provided is only address, then its a read operation.
+        * Store the address in a global variable and retrieve whenever
+        * required.
+        */
+       if (!tok) {
+               register_address = address;
+               goto err;
+       }
+       register_address = address;
+
+       ret = kstrtol(tok, 16, &mask);
+       if (ret) {
+               ret = -EFAULT;
+               goto err;
+       }
+       tok = strsep(&inbuf, " ");
+       if (!tok) {
+               ret = -EFAULT;
+               goto err;
+       }
+       ret = kstrtol(tok, 16, &value);
+       if (!tok) {
+               ret = -EFAULT;
+               goto err;
+       }
+       ret = zynqmp_pm_config_reg_access(CONFIG_REG_WRITE, address,
+                                         mask, value, NULL);
+       if (ret)
+               pr_err("unable to write value to %lx\n", value);
+err:
+       kfree(kern_buff);
+       if (ret)
+               return ret;
+       return count;
+}
+
+/**
+ * config_reg_show - Read config_reg sysfs attribute
+ * @kobj:      Kobject structure
+ * @attr:      Kobject attribute structure
+ * @buf:       User entered health_status attribute string
+ *
+ * User-space interface for getting the config register.
+ *
+ * To Read any CSU/PMU register, write address to the variable like below
+ * echo <address> > /sys/firmware/zynqmp/config_reg
+ *
+ * Then Read the address using below command
+ * cat /sys/firmware/zynqmp/config_reg
+ *
+ * Return: number of chars written to buf.
+ */
+static ssize_t config_reg_show(struct kobject *kobj,
+                              struct kobj_attribute *attr,
+                              char *buf)
+{
+       int ret;
+       u32 ret_payload[PAYLOAD_ARG_CNT];
+
+       ret = zynqmp_pm_config_reg_access(CONFIG_REG_READ, register_address,
+                                         0, 0, ret_payload);
+       if (ret)
+               return ret;
+
+       return sprintf(buf, "0x%x\n", ret_payload[1]);
+}
+
+static struct kobj_attribute zynqmp_attr_config_reg =
+                                       __ATTR_RW(config_reg);
+
+static struct attribute *attrs[] = {
+       &zynqmp_attr_config_reg.attr,
+       NULL,
+};
+
+static const struct attribute_group attr_group = {
+       .attrs = attrs,
+       NULL,
+};
+
+static int zynqmp_pm_sysfs_init(void)
+{
+       struct kobject *zynqmp_kobj;
+       int ret;
+
+       zynqmp_kobj = kobject_create_and_add("zynqmp", firmware_kobj);
+       if (!zynqmp_kobj) {
+               pr_err("zynqmp: Firmware kobj add failed.\n");
+               return -ENOMEM;
+       }
+
+       ret = sysfs_create_group(zynqmp_kobj, &attr_group);
+       if (ret) {
+               pr_err("%s() sysfs creation fail with error %d\n",
+                      __func__, ret);
+       }
+
+       return ret;
+}
+
 static int zynqmp_firmware_probe(struct platform_device *pdev)
 {
        struct device *dev = &pdev->dev;
@@ -914,6 +1075,12 @@ static int zynqmp_firmware_probe(struct platform_device *pdev)
        /* Assign eemi_ops_table */
        eemi_ops_tbl = &eemi_ops;
 
+       ret = zynqmp_pm_sysfs_init();
+       if (ret) {
+               pr_err("%s() sysfs init fail with error %d\n", __func__, ret);
+               return ret;
+       }
+
        zynqmp_pm_api_debugfs_init();
 
        ret = mfd_add_devices(&pdev->dev, PLATFORM_DEVID_NONE, firmware_devs,
index 552e8bf1fcf214aa2499c77eb80508345775f716..27b218a22f46406059d4605c1707f0585a39ee89 100644 (file)
@@ -103,6 +103,10 @@ enum pm_ioctl_id {
        IOCTL_GET_PLL_FRAC_MODE,
        IOCTL_SET_PLL_FRAC_DATA,
        IOCTL_GET_PLL_FRAC_DATA,
+       IOCTL_WRITE_GGS,
+       IOCTL_READ_GGS,
+       IOCTL_WRITE_PGGS,
+       IOCTL_READ_PGGS,
 };
 
 enum pm_query_id {
@@ -394,6 +398,11 @@ enum dll_reset_type {
        PM_DLL_RESET_PULSE,
 };
 
+enum pm_register_access_id {
+       CONFIG_REG_WRITE,
+       CONFIG_REG_READ,
+};
+
 /**
  * struct zynqmp_pm_query_data - PM query data
  * @qid:       query ID