#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[] = {
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;
}
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;
/* 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,