From: John Stultz <john.stultz@linaro.org>
To: lkml <linux-kernel@vger.kernel.org>
Cc: Dmitry Shmidt <dimitrysh@google.com>,
Rob Herring <robh+dt@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Frank Rowand <frowand.list@gmail.com>,
devicetree@vger.kernel.org, John Stultz <john.stultz@linaro.org>
Subject: [RFC][PATCH 2/3] of: overlay_mgr: Add ability to apply through sysfs entry
Date: Mon, 9 Oct 2017 22:34:19 -0700 [thread overview]
Message-ID: <1507613660-27236-3-git-send-email-john.stultz@linaro.org> (raw)
In-Reply-To: <1507613660-27236-1-git-send-email-john.stultz@linaro.org>
From: Dmitry Shmidt <dimitrysh@google.com>
Allow pre-defined overlay_mgr DT fragments to be enabled on the
fly by writing to:
/sys/devices/platform/overlay_mgr/current_overlay
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Frank Rowand <frowand.list@gmail.com>
Cc: Dmitry Shmidt <dimitrysh@google.com>
Cc: devicetree@vger.kernel.org
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
[jstultz: Slightly reworded commit message]
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
drivers/of/overlay_mgr.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 52 insertions(+)
diff --git a/drivers/of/overlay_mgr.c b/drivers/of/overlay_mgr.c
index 1fdeb0a..5a082be 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);
--
2.7.4
next prev parent reply other threads:[~2017-10-10 5:34 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-10 5:34 [RFC][PATCH 0/3] Overlay manager for predefined DT overlay fragments John Stultz
2017-10-10 5:34 ` [RFC][PATCH 1/3] of: overlay_mgr: Add overlay manager driver John Stultz
2017-10-10 5:34 ` John Stultz [this message]
2017-10-10 5:34 ` [RFC][PATCH 3/3] of: overlay_mgr: Add ability to apply several hardware configurations John Stultz
[not found] ` <1507613660-27236-1-git-send-email-john.stultz-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2017-10-13 21:41 ` [RFC][PATCH 0/3] Overlay manager for predefined DT overlay fragments Rob Herring
2017-10-13 23:51 ` John Stultz
2017-10-17 19:46 ` Rob Herring
2017-10-17 21:20 ` John Stultz
[not found] ` <CALAqxLWSLqmN8WWGktVDxfcs3zyk8ktqVJbtAEoHtqZZw5KTVw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-11-07 23:10 ` John Stultz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1507613660-27236-3-git-send-email-john.stultz@linaro.org \
--to=john.stultz@linaro.org \
--cc=devicetree@vger.kernel.org \
--cc=dimitrysh@google.com \
--cc=frowand.list@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=robh+dt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).