aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Shmidt <dimitrysh@google.com>2016-09-06 10:54:07 -0700
committerJohn Stultz <john.stultz@linaro.org>2017-01-26 10:55:02 -0800
commit2702079f9eca16f10a4ee0b42eabb6c8a260fcd3 (patch)
tree98575fe8599d742aa3ff3b11ee72e19d3430c037
parentfa8901136f51e6d918ce4ab21ef977239b59db32 (diff)
downloadhikey-clang-2702079f9eca16f10a4ee0b42eabb6c8a260fcd3.tar.gz
of: overlay_mgr: Add ability to apply through sysfs entry
Allow to apply DT entries on the fly by writing it to /sys/devices/platform/overlay_mgr/current_overlay Change-Id: I56f0d3f15ac5e8b3ed48c0c1c812955c151d4f46 Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
-rw-r--r--drivers/of/overlay_mgr.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/drivers/of/overlay_mgr.c b/drivers/of/overlay_mgr.c
index 1fdeb0a662a1..5a082beec9b6 100644
--- a/drivers/of/overlay_mgr.c
+++ b/drivers/of/overlay_mgr.c
@@ -18,10 +18,14 @@
#include <linux/kernel.h>
#include <linux/of.h>
#include <linux/platform_device.h>
+#include <linux/slab.h>
static char *of_overlay_dt_entry;
module_param_named(overlay_dt_entry, of_overlay_dt_entry, charp, 0644);
+static char *of_overlay_dt_apply;
+DEFINE_MUTEX(of_overlay_mgr_mutex);
+
static int of_overlay_mgr_apply_overlay(struct device_node *onp)
{
int ret;
@@ -61,8 +65,56 @@ static int of_overlay_mgr_apply_dt(struct device *dev, char *dt_entry)
return 0;
}
+static ssize_t current_overlay_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ size_t len;
+
+ mutex_lock(&of_overlay_mgr_mutex);
+ if (!of_overlay_dt_apply) {
+ mutex_unlock(&of_overlay_mgr_mutex);
+ return 0;
+ }
+ len = strlen(of_overlay_dt_apply);
+ if (len >= PAGE_SIZE)
+ len = PAGE_SIZE - 1;
+ memcpy(buf, of_overlay_dt_apply, len + 1);
+ mutex_unlock(&of_overlay_mgr_mutex);
+ return len;
+}
+
+static ssize_t current_overlay_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t size)
+{
+ mutex_lock(&of_overlay_mgr_mutex);
+ kfree(of_overlay_dt_apply);
+ of_overlay_dt_apply = kmalloc(size, GFP_KERNEL);
+ if (!of_overlay_dt_apply) {
+ pr_err("overlay_mgr: fail to allocate memory\n");
+ mutex_unlock(&of_overlay_mgr_mutex);
+ return 0;
+ }
+ memcpy(of_overlay_dt_apply, buf, size);
+ of_overlay_dt_apply[size - 1] = '\0';
+
+ if (of_overlay_mgr_apply_dt(dev, of_overlay_dt_apply)) {
+ kfree(of_overlay_dt_apply);
+ of_overlay_dt_apply = NULL;
+ size = 0;
+ }
+ mutex_unlock(&of_overlay_mgr_mutex);
+ return size;
+}
+
+static DEVICE_ATTR(current_overlay, 0644, current_overlay_show,
+ current_overlay_store);
+
static int of_overlay_mgr_probe(struct platform_device *pdev)
{
+ if (device_create_file(&pdev->dev, &dev_attr_current_overlay))
+ pr_err("overlay_mgr: fail to register apply entry\n");
+
if (!of_overlay_dt_entry)
return 0;
of_overlay_mgr_apply_dt(&pdev->dev, of_overlay_dt_entry);