public inbox for devicetree@vger.kernel.org
 help / color / mirror / Atom feed
From: atull <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
Subject: Re: [PATCH v2 3/3] fpga manager: bus driver
Date: Wed, 22 Oct 2014 17:22:18 -0500	[thread overview]
Message-ID: <alpine.DEB.2.02.1410221716270.9996@atx-linux-37> (raw)
In-Reply-To: <1414007405-32186-4-git-send-email-atull@opensource.altera.com>

On Wed, 22 Oct 2014, atull@opensource.altera.com wrote:

> From: Alan Tull <atull@opensource.altera.com>
> 
> Support programming the fpga from device tree overlays.
> 
> This patch adds one exported function to the core
> (fpga-mgr.c): of_fpga_mgr_dev_lookup
>   Get pointer to fpga manager struct given a phandle.
> 
> 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.
> 

Since this patch is dependent on a branch that would be hard
to put together, I have pushed a branch.  If you happen to
have a cyclone5 board sitting around, you should be able to
load a FPGA from DT overlays using the steps below.

The branch name is 'dt-ng-overlays-v2.2'.  The repo is at:
git://git.rocketboards.org/linux-socfpga-next.git

Alan

> Here's a simple example. Start with:
>   * the altera-gpio driver built in to the kernel but not in the
>     device tree.
>   * raw fpga image at /lib/firmware/soc_system.rbf
>   * Load appropriate device tree overlay in configfs by doing
>     $ mkdir /config/device-tree/overlays/1
>     $ echo socfpga_overlay.dtbo > /config/device-tree/overlays/1/path
>   * This results in the FPGA getting programmed and the altera
>     gpio driver getting probed.
>   * To remove/clear FPGA image by putting the FPGA in reset,
>     remove device tree overlay by doing:
>     $ rmdir /config/device-tree/overlays/1
> 
> Device tree overlay looks like this:
> /dts-v1/;
> /plugin/;
> / {
> 	fragment@0 {
> 		target-path="/soc";
> 		__overlay__ {
> 			#address-cells = <1>;
> 	                #size-cells = <1>;
> 
> 			bridge@0xff200000 {
> 				compatible = "fpga-mgr-bus", "simple-bus";
> 				reg = <0xff200000 0x200000>;
> 				clocks = <0x2 0x2>;
> 				clock-names = "h2f_lw_axi_clock", "f2h_sdram0_clock";
> 				#address-cells = <0x2>;
> 				#size-cells = <0x1>;
> 				ranges = <0x1 0x10040 0xff210040 0x20>;
> 
> 				fpgamgr = <&hps_0_fpgamgr>;
> 				fpga-firmware = "soc_system.rbf";
> 
> 				gpio@0x100010040 {
> 					compatible = "altr,pio-14.0", "altr,pio-1.0";
> 					reg = <0x1 0x10040 0x20>;
> 					clocks = <0x2>;
> 					altr,gpio-bank-width = <0x4>;
> 					resetvalue = <0x0>;
> 					#gpio-cells = <0x2>;
> 					gpio-controller;
> 					linux,phandle = <0x2d>;
> 				};
> 			};
> 		};
> 	};
> };
> 
> Signed-off-by: Alan Tull <atull@opensource.altera.com>
> 
> v2: simplify of_fpga_mgr_dev_lookup to return NULL on failure
>     move suspend/resume to fpga-mgr.c core
>     support 'rmdir' to remove overlay
> ---
>  drivers/fpga/Kconfig     |    7 +++
>  drivers/fpga/Makefile    |    1 +
>  drivers/fpga/bus.c       |  124 ++++++++++++++++++++++++++++++++++++++++++++++
>  drivers/fpga/fpga-mgr.c  |   23 +++++++++
>  include/linux/fpga-mgr.h |    2 +
>  5 files changed, 157 insertions(+)
>  create mode 100644 drivers/fpga/bus.c
> 
> 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/Makefile b/drivers/fpga/Makefile
> index c8a676f..e39911f 100644
> --- a/drivers/fpga/Makefile
> +++ b/drivers/fpga/Makefile
> @@ -6,5 +6,6 @@ fpga-mgr-core-y += fpga-mgr.o
>  
>  # Core FPGA Manager Framework
>  obj-$(CONFIG_FPGA)			+= fpga-mgr-core.o
> +obj-$(CONFIG_FPGA_MGR_BUS)		+= bus.o
>  
>  # FPGA Manager Drivers
> diff --git a/drivers/fpga/bus.c b/drivers/fpga/bus.c
> new file mode 100644
> index 0000000..999346e
> --- /dev/null
> +++ b/drivers/fpga/bus.c
> @@ -0,0 +1,124 @@
> +/*
> + * FPGA Manager Bus Driver
> + *
> + *  Copyright (C) 2013-2014 Altera Corporation
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms and conditions of the GNU General Public License,
> + * version 2, as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope it will be useful, but WITHOUT
> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
> + * more details.
> + *
> + * You should have received a copy of the GNU General Public License along with
> + * this program.  If not, see <http://www.gnu.org/licenses/>.
> + */
> +#include <linux/completion.h>
> +#include <linux/fs.h>
> +#include <linux/fpga-mgr.h>
> +#include <linux/io.h>
> +#include <linux/irq.h>
> +#include <linux/kernel.h>
> +#include <linux/list.h>
> +#include <linux/mm.h>
> +#include <linux/module.h>
> +#include <linux/of.h>
> +#include <linux/of_address.h>
> +#include <linux/of_device.h>
> +#include <linux/of_platform.h>
> +#include <linux/pm.h>
> +#include <linux/slab.h>
> +#include <linux/string.h>
> +#include <linux/types.h>
> +
> +struct fpga_mgr_bus_priv {
> +	struct device *dev;
> +	struct device_node *np;
> +	struct fpga_manager *mgr;
> +	const char *path;
> +};
> +
> +static int fpga_mgr_bus_probe(struct platform_device *pdev)
> +{
> +	struct device_node *np = pdev->dev.of_node;
> +	struct device *dev = &pdev->dev;
> +	struct fpga_mgr_bus_priv *priv;
> +	const char *path;
> +	struct fpga_manager *mgr;
> +	int ret = 0;
> +
> +	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
> +	if (!priv)
> +		return -ENOMEM;
> +
> +	/* Find the FPGA Manager to associate with */
> +	mgr = of_fpga_mgr_dev_lookup(np, "fpgamgr");
> +	if (!mgr) {
> +		dev_err(mgr->dev, "%s could not find fpga mgr\n", __func__);
> +		return -ENODEV;
> +	}
> +
> +	/* Find the FPGA image on the firmware path */
> +	of_property_read_string(np, "fpga-firmware", &path);
> +
> +	ret = fpga_mgr_firmware_write(mgr, path);
> +	if (ret != 0) {
> +		dev_err(mgr->dev, "%s fpga mgr write failure\n", __func__);
> +		return -EIO;
> +	}
> +
> +	priv->dev = dev;
> +	priv->np = np;
> +	priv->mgr = mgr;
> +	priv->path = path;
> +	platform_set_drvdata(pdev, priv);
> +
> +	return 0;
> +}
> +
> +/* Called when the Device Tree overlay is removed */
> +static int fpga_mgr_bus_remove(struct platform_device *pdev)
> +{
> +	struct fpga_mgr_bus_priv *priv = platform_get_drvdata(pdev);
> +	struct fpga_manager *mgr = priv->mgr;
> +
> +	return fpga_mgr_reset(mgr);
> +}
> +
> +#ifdef CONFIG_OF
> +static const struct of_device_id fpga_mgr_bus_of_match[] = {
> +	{ .compatible = "fpga-mgr-bus", },
> +	{},
> +};
> +
> +MODULE_DEVICE_TABLE(of, fpga_mgr_bus_of_match);
> +#endif
> +
> +static struct platform_driver fpga_mgr_bus_driver = {
> +	.probe = fpga_mgr_bus_probe,
> +	.remove = fpga_mgr_bus_remove,
> +	.driver = {
> +		.name	= "fpga_manager_bus",
> +		.owner	= THIS_MODULE,
> +		.of_match_table = of_match_ptr(fpga_mgr_bus_of_match),
> +	},
> +};
> +
> +static int __init fpga_mgr_bus_init(void)
> +{
> +	return platform_driver_register(&fpga_mgr_bus_driver);
> +}
> +
> +static void __exit fpga_mgr_bus_exit(void)
> +{
> +	platform_driver_unregister(&fpga_mgr_bus_driver);
> +}
> +
> +module_init(fpga_mgr_bus_init);
> +module_exit(fpga_mgr_bus_exit);
> +
> +MODULE_AUTHOR("Alan Tull <atull@opensource.altera.com>");
> +MODULE_DESCRIPTION("Altera FPGA Manager Bus");
> +MODULE_LICENSE("GPL v2");
> diff --git a/drivers/fpga/fpga-mgr.c b/drivers/fpga/fpga-mgr.c
> index 0c7236a..fed13a6 100644
> --- a/drivers/fpga/fpga-mgr.c
> +++ b/drivers/fpga/fpga-mgr.c
> @@ -350,6 +350,29 @@ const struct attribute_group *fpga_mgr_groups[] = {
>  #define fpga_mgr_groups NULL
>  #endif /* CONFIG_FPGA_MGR_SYSFS */
>  
> +/* 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;
> +
> +	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->np) {
> +			of_node_put(mgr_node);
> +			return mgr;
> +		}
> +
> +	of_node_put(mgr_node);
> +
> +	return NULL;
> +}
> +EXPORT_SYMBOL_GPL(of_fpga_mgr_dev_lookup);
> +
>  static int fpga_mgr_suspend(struct device *dev)
>  {
>  	struct fpga_manager *mgr = dev_get_drvdata(dev);
> diff --git a/include/linux/fpga-mgr.h b/include/linux/fpga-mgr.h
> index 97c7e0b..abf2699 100644
> --- a/include/linux/fpga-mgr.h
> +++ b/include/linux/fpga-mgr.h
> @@ -110,6 +110,8 @@ int fpga_mgr_register(struct platform_device *pdev,
>  		      struct fpga_manager_ops *mops,
>  		      const char *name, void *priv);
>  void fpga_mgr_remove(struct platform_device *pdev);
> +struct fpga_manager *of_fpga_mgr_dev_lookup(struct device_node *node,
> +					    const char *mgr_property);
>  
>  #endif /* CONFIG_FPGA */
>  #endif /*_LINUX_FPGA_MGR_H */
> -- 
> 1.7.9.5
> 
> 

      reply	other threads:[~2014-10-22 22:22 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-22 19:50 [PATCH v2 0/3] FPGA Framework with DT and sysfs support atull-yzvPICuk2ABMcg4IHK0kFoH6Mc4MB0Vx
2014-10-22 19:50 ` [PATCH v2 1/3] fpga manager: add sysfs interface document atull
2014-10-22 19:50 ` [PATCH v2 2/3] fpga manager: framework core atull
2014-10-24 10:52   ` Pavel Machek
2014-10-24 10:55     ` Pantelis Antoniou
2014-10-24 14:54       ` atull
2014-12-06 13:01         ` Grant Likely
2014-12-06 13:55           ` Pavel Machek
2014-12-08 17:50             ` Grant Likely
2014-12-08 17:56               ` Grant Likely
2014-12-08 17:56               ` Pantelis Antoniou
2014-12-08 18:30                 ` Grant Likely
2014-12-08 20:53               ` Rob Landley
2014-10-24 21:00     ` One Thousand Gnomes
2014-12-06 13:00     ` Grant Likely
2014-12-06 14:02       ` Pavel Machek
     [not found]       ` <CACxGe6sa=ysJAjx5TQZH5sKoas1PkoUUR4zT=Z35+uF6rrk-vw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-12-08 22:55         ` One Thousand Gnomes
2014-12-09 13:11           ` Grant Likely
2014-12-09 13:42             ` Michal Simek
2014-12-09 16:07           ` atull
2014-12-09 21:02             ` One Thousand Gnomes
2014-12-09 22:12               ` atull
2014-12-12 12:14               ` Pavel Machek
2014-12-18 20:50         ` atull
2014-10-22 19:50 ` [PATCH v2 3/3] fpga manager: bus driver atull
2014-10-22 22:22   ` atull [this message]

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=alpine.DEB.2.02.1410221716270.9996@atx-linux-37 \
    --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