Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 28ced727 authored by Jilai Wang's avatar Jilai Wang
Browse files

msm: npu: Add a sysfs node to load/unload fw



This change is to add a sysfs node to allow user to load/unload
firmware by accessing it.

Change-Id: I5115534aec9fcd15e9657dc691a6a493149390d7
Signed-off-by: default avatarJilai Wang <jilaiw@codeaurora.org>
parent 9217418c
Loading
Loading
Loading
Loading
+49 −0
Original line number Diff line number Diff line
@@ -68,6 +68,12 @@ static ssize_t npu_show_perf_mode_override(struct device *dev,
static ssize_t npu_store_perf_mode_override(struct device *dev,
					  struct device_attribute *attr,
					  const char *buf, size_t count);
static ssize_t npu_show_fw_state(struct device *dev,
					 struct device_attribute *attr,
					 char *buf);
static ssize_t npu_store_fw_state(struct device *dev,
					  struct device_attribute *attr,
					  const char *buf, size_t count);
static void npu_suspend_devbw(struct npu_device *npu_dev);
static void npu_resume_devbw(struct npu_device *npu_dev);
static bool npu_is_post_clock(const char *clk_name);
@@ -166,11 +172,13 @@ static DEVICE_ATTR(caps, 0444, npu_show_capabilities, NULL);
static DEVICE_ATTR(pwr, 0644, npu_show_pwr_state, npu_store_pwr_state);
static DEVICE_ATTR(perf_mode_override, 0644,
	npu_show_perf_mode_override, npu_store_perf_mode_override);
static DEVICE_ATTR(fw_state, 0644, npu_show_fw_state, npu_store_fw_state);

static struct attribute *npu_fs_attrs[] = {
	&dev_attr_caps.attr,
	&dev_attr_pwr.attr,
	&dev_attr_perf_mode_override.attr,
	&dev_attr_fw_state.attr,
	NULL
};

@@ -307,6 +315,47 @@ static ssize_t npu_store_perf_mode_override(struct device *dev,
	return count;
}

/* -------------------------------------------------------------------------
 * SysFS - firmware state
 * -------------------------------------------------------------------------
 */
static ssize_t npu_show_fw_state(struct device *dev,
					 struct device_attribute *attr,
					 char *buf)
{
	struct npu_device *npu_dev = dev_get_drvdata(dev);

	return scnprintf(buf, PAGE_SIZE, "%s\n",
			(npu_dev->host_ctx.fw_state == FW_ENABLED) ?
			"on" : "off");
}

static ssize_t npu_store_fw_state(struct device *dev,
					  struct device_attribute *attr,
					  const char *buf, size_t count)
{
	struct npu_device *npu_dev = dev_get_drvdata(dev);
	bool enable = false;
	int rc;

	if (strtobool(buf, &enable) < 0)
		return -EINVAL;

	if (enable) {
		pr_debug("%s: fw init\n", __func__);
		rc = fw_init(npu_dev);
		if (rc) {
			pr_err("fw init failed\n");
			return rc;
		}
	} else {
		pr_debug("%s: fw deinit\n", __func__);
		fw_deinit(npu_dev, false, true);
	}

	return count;
}

/* -------------------------------------------------------------------------
 * Power Related
 * -------------------------------------------------------------------------