From: <atull@opensource.altera.com>
To: <gregkh@linuxfoundation.org>, <jgunthorpe@obsidianresearch.com>,
<hpa@zytor.com>, <monstr@monstr.eu>, <michal.simek@xilinx.com>,
<rdunlap@infradead.org>
Cc: <linux-kernel@vger.kernel.org>, <devicetree@vger.kernel.org>,
<pantelis.antoniou@konsulko.com>, <robh+dt@kernel.org>,
<grant.likely@linaro.org>, <iws@ovro.caltech.edu>,
<linux-doc@vger.kernel.org>, <pavel@denx.de>,
<broonie@kernel.org>, <philip@balister.org>, <rubini@gnudd.com>,
<s.trumtrar@pengutronix.de>, <jason@lakedaemon.net>,
<kyle.teske@ni.com>, <nico@linaro.org>, <balbi@ti.com>,
<m.chehab@samsung.com>, <davidb@codeaurora.org>,
<rob@landley.net>, <davem@davemloft.net>, <cesarb@cesarb.net>,
<sameo@linux.intel.com>, <akpm@linux-foundation.org>,
<linus.walleij@linaro.org>, <delicious.quinoa@gmail.com>,
<dinguyen@opensource.altera.com>,
<yvanderv@opensource.altera.com>,
Alan Tull <atull@opensource.altera.com>
Subject: [PATCH v3 3/3] fpga manager: device tree overlay support
Date: Tue, 9 Dec 2014 10:28:01 -0600 [thread overview]
Message-ID: <1418142481-6167-4-git-send-email-atull@opensource.altera.com> (raw)
In-Reply-To: <1418142481-6167-1-git-send-email-atull@opensource.altera.com>
From: Alan Tull <atull@opensource.altera.com>
Support programming the fpga from device tree overlays.
This patch adds two exported functions to the core
(fpga-mgr.c):
of_fpga_mgr_dev_lookup
Get pointer to fpga manager struct given a phandle.
of_find_fpga_mgr_by_node
Get pointer to fpga manager given device node
This code is dependent on Pantelis Antoniou's current work
on Device Tree overlays, a method of dynamically altering
the kernel's live Device Tree. The rest of the patchset was
tested with recent for-next, but this 'bus driver' patch was
tested with Pantelis's and Grant Likely's stuff that is in git
(his git repo https://github.com/pantoniou/linux-beagle-track-mainline
v3.17-rc2-115-gbc778b8 == dt-ng/bbb) plus some dtc fixups
for compiling overlays.
TODO: Integrate bridge support
General flow is:
1. Load a DT overlay
2. This causes the FPGA to get programmed
3. TODO - enable FPGA bridges
4. Drivers get probed
The reverse flow is also supported:
1. Remove the DT overlay
2. Drivers get removed
3. TODO - disable FPGA bridges
4. FPGA gets reset
Signed-off-by: Alan Tull <atull@opensource.altera.com>
---
drivers/fpga/Kconfig | 7 ++++
drivers/fpga/fpga-mgr.c | 104 +++++++++++++++++++++++++++++++++++++++++++++-
include/linux/fpga-mgr.h | 3 ++
3 files changed, 113 insertions(+), 1 deletion(-)
diff --git a/drivers/fpga/Kconfig b/drivers/fpga/Kconfig
index e775b17..2bd6c83 100644
--- a/drivers/fpga/Kconfig
+++ b/drivers/fpga/Kconfig
@@ -18,4 +18,11 @@ config FPGA_MGR_SYSFS
help
FPGA Manager SysFS interface.
+config FPGA_MGR_BUS
+ bool "FPGA Manager Bus"
+ depends on FPGA
+ help
+ FPGA Manager Bus interface. Allows loading FPGA images
+ from Device Tree or from other drivers.
+
endmenu
diff --git a/drivers/fpga/fpga-mgr.c b/drivers/fpga/fpga-mgr.c
index d08cb82..6f9c196 100644
--- a/drivers/fpga/fpga-mgr.c
+++ b/drivers/fpga/fpga-mgr.c
@@ -36,6 +36,7 @@ static DEFINE_IDA(fpga_mgr_ida);
static struct class *fpga_mgr_class;
static LIST_HEAD(fpga_manager_list);
+static struct notifier_block fpga_mgr_of_notifier_block;
/*
* Get FPGA state from low level driver
@@ -186,12 +187,17 @@ int fpga_mgr_firmware_write(struct fpga_manager *mgr, const char *image_name)
ret = request_firmware(&fw, image_name, &mgr->dev);
if (ret) {
mgr->state = FPGA_MGR_STATE_FIRMWARE_REQ_ERR;
+ dev_dbg(&mgr->dev, "Error requesting firmware %s\n",
+ image_name);
goto fw_wr_exit;
}
ret = __fpga_mgr_write(mgr, fw->data, fw->size);
- if (ret)
+ if (ret) {
+ dev_dbg(&mgr->dev, "Error writing %s to %s\n",
+ image_name, mgr->name);
goto fw_wr_exit;
+ }
strcpy(mgr->image_name, image_name);
@@ -367,6 +373,87 @@ const struct dev_pm_ops fpga_mgr_dev_pm_ops = {
.resume = fpga_mgr_resume,
};
+#if IS_ENABLED(CONFIG_OF)
+/* Find the fpga manager that is pointed to by a phandle */
+struct fpga_manager *of_fpga_mgr_dev_lookup(struct device_node *node,
+ const char *mgr_property)
+{
+ struct fpga_manager *mgr;
+ struct device_node *mgr_node;
+
+ if (node == NULL)
+ return NULL;
+
+ mgr_node = of_parse_phandle(node, mgr_property, 0);
+ if (!mgr_node)
+ return NULL;
+
+ list_for_each_entry(mgr, &fpga_manager_list, list)
+ if (mgr_node == mgr->dev.of_node) {
+ of_node_put(mgr_node);
+ return mgr;
+ }
+
+ of_node_put(mgr_node);
+
+ return NULL;
+}
+EXPORT_SYMBOL_GPL(of_fpga_mgr_dev_lookup);
+
+struct fpga_manager *of_find_fpga_mgr_by_node(struct device_node *node)
+{
+ struct fpga_manager *mgr;
+
+ if (node == NULL)
+ return NULL;
+
+ list_for_each_entry(mgr, &fpga_manager_list, list)
+ if (node == mgr->dev.of_node)
+ return mgr;
+
+ return NULL;
+}
+EXPORT_SYMBOL_GPL(of_find_fpga_mgr_by_node);
+#endif /* CONFIG_OF */
+
+static int of_fpga_mgr_notify(struct notifier_block *nb, unsigned long action,
+ void *arg)
+{
+ struct device_node *dn;
+ const char *path;
+ struct fpga_manager *mgr;
+ int state;
+
+ state = of_reconfig_get_state_change(action, arg);
+ if (state == -1)
+ return NOTIFY_OK;
+
+ switch (action) {
+ case OF_RECONFIG_ATTACH_NODE:
+ case OF_RECONFIG_DETACH_NODE:
+ dn = arg;
+ break;
+ case OF_RECONFIG_ADD_PROPERTY:
+ case OF_RECONFIG_REMOVE_PROPERTY:
+ case OF_RECONFIG_UPDATE_PROPERTY:
+ default:
+ return NOTIFY_OK;
+ }
+
+ mgr = of_find_fpga_mgr_by_node(dn->parent);
+ if (!mgr)
+ return NOTIFY_OK; /* not for us */
+
+ if (state) {
+ if (!of_property_read_string(dn, "fpga-firmware", &path))
+ fpga_mgr_firmware_write(mgr, path);
+ } else {
+ fpga_mgr_reset(mgr);
+ }
+
+ return NOTIFY_OK;
+}
+
static void fpga_mgr_dev_release(struct device *dev)
{
struct fpga_manager *mgr = to_fpga_manager(dev);
@@ -459,6 +546,8 @@ EXPORT_SYMBOL_GPL(fpga_mgr_remove);
static int __init fpga_mgr_dev_init(void)
{
+ int ret;
+
pr_info("FPGA Manager framework driver\n");
fpga_mgr_class = class_create(THIS_MODULE, "fpga_manager");
@@ -468,11 +557,24 @@ static int __init fpga_mgr_dev_init(void)
fpga_mgr_class->dev_groups = fpga_mgr_groups;
fpga_mgr_class->pm = &fpga_mgr_dev_pm_ops;
+#if IS_ENABLED(CONFIG_OF)
+ fpga_mgr_of_notifier_block.notifier_call = of_fpga_mgr_notify;
+ ret = of_reconfig_notifier_register(&fpga_mgr_of_notifier_block);
+ if (ret) {
+ class_destroy(fpga_mgr_class);
+ ida_destroy(&fpga_mgr_ida);
+ return ret;
+ }
+#endif
+
return 0;
}
static void __exit fpga_mgr_dev_exit(void)
{
+#if IS_ENABLED(CONFIG_OF)
+ of_reconfig_notifier_unregister(&fpga_mgr_of_notifier_block);
+#endif
class_destroy(fpga_mgr_class);
ida_destroy(&fpga_mgr_ida);
}
diff --git a/include/linux/fpga-mgr.h b/include/linux/fpga-mgr.h
index 7ac762c..414d949 100644
--- a/include/linux/fpga-mgr.h
+++ b/include/linux/fpga-mgr.h
@@ -99,6 +99,9 @@ int fpga_mgr_reset(struct fpga_manager *mgr);
int fpga_mgr_register(struct device *pdev, const char *name,
struct fpga_manager_ops *mops, void *priv);
void fpga_mgr_remove(struct device *dev);
+struct fpga_manager *of_fpga_mgr_dev_lookup(struct device_node *node,
+ const char *mgr_property);
+struct fpga_manager *of_find_fpga_mgr_by_node(struct device_node *node);
#endif /* CONFIG_FPGA */
#endif /*_LINUX_FPGA_MGR_H */
--
1.7.9.5
next prev parent reply other threads:[~2014-12-09 16:43 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-09 16:27 [PATCH v3 0/3] FPGA Manager Framework atull
2014-12-09 16:27 ` [PATCH v3 1/3] fpga manager: add sysfs interface document atull
2014-12-09 16:28 ` [PATCH v3 2/3] fpga manager: framework core atull
2014-12-09 16:28 ` atull [this message]
2014-12-09 18:40 ` [PATCH v3 0/3] FPGA Manager Framework atull
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=1418142481-6167-4-git-send-email-atull@opensource.altera.com \
--to=atull@opensource.altera.com \
--cc=akpm@linux-foundation.org \
--cc=balbi@ti.com \
--cc=broonie@kernel.org \
--cc=cesarb@cesarb.net \
--cc=davem@davemloft.net \
--cc=davidb@codeaurora.org \
--cc=delicious.quinoa@gmail.com \
--cc=devicetree@vger.kernel.org \
--cc=dinguyen@opensource.altera.com \
--cc=grant.likely@linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=hpa@zytor.com \
--cc=iws@ovro.caltech.edu \
--cc=jason@lakedaemon.net \
--cc=jgunthorpe@obsidianresearch.com \
--cc=kyle.teske@ni.com \
--cc=linus.walleij@linaro.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=m.chehab@samsung.com \
--cc=michal.simek@xilinx.com \
--cc=monstr@monstr.eu \
--cc=nico@linaro.org \
--cc=pantelis.antoniou@konsulko.com \
--cc=pavel@denx.de \
--cc=philip@balister.org \
--cc=rdunlap@infradead.org \
--cc=rob@landley.net \
--cc=robh+dt@kernel.org \
--cc=rubini@gnudd.com \
--cc=s.trumtrar@pengutronix.de \
--cc=sameo@linux.intel.com \
--cc=yvanderv@opensource.altera.com \
/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
Powered by JetHome