Skip to contentSkip to conversation

FPGA Manager support for Arria10

PATCH In review Alan Tull 4 participants 11 messages Jul 12, 2016 – Jul 19, 2016

Subsystems (2)
lore
Share & tools
lore

Alan Tull

author
#0 lore raw

cover FPGA Manager support for Arria10

New patch submission for FPGA Manager support for the Altera SoCFPGA Arria10 plus device tree bindings.

Alan Tull (2):
ARM: socfpga: add bindings doc for arria10 fpga manager
fpga-manager: Add Socfpga Arria10 support

 .../bindings/fpga/altera-socfpga-a10-fpga-mgr.txt  |  19 +
 drivers/fpga/Kconfig                               |   6 +
 drivers/fpga/Makefile                              |   1 +
 drivers/fpga/socfpga-a10.c                         | 573 +++++++++++++++++++++
 4 files changed, 599 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/fpga/altera-socfpga-a10-fpga-mgr.txt
 create mode 100644 drivers/fpga/socfpga-a10.c
Signature · 1 line
2.9.1
author
#1 lore raw

PATCH 1/2 ARM: socfpga: add bindings doc for arria10 fpga manager

Add a device tree bindings document for the SoCFPGA Arria10 FPGA Manager driver.

---
 .../bindings/fpga/altera-socfpga-a10-fpga-mgr.txt     | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/fpga/altera-socfpga-a10-fpga-mgr.txt
Documentation/devicetree/bindings/fpga/altera-socfpga-a10-fpga-mgr.txt new file +19 -0
new file mode 100644
index 0000000..2fd8e7a
@@ -0,0 +1,19 @@
+Altera SOCFPGA Arria10 FPGA Manager
+
+Required properties:
+- compatible : should contain "altr,socfpga-a10-fpga-mgr"
+- reg        : base address and size for memory mapped io.
+               - The first index is for FPGA manager register access.
+               - The second index is for writing FPGA configuration data.
+- resets     : Phandle and reset specifier for the device's reset.
+- clocks     : Clocks used by the device.
+
+Example:
+
+	fpga_mgr: fpga-mgr at ffd03000 {
+		compatible = "altr,socfpga-a10-fpga-mgr";
+		reg = <0xffd03000 0x100
+		       0xffcfe400 0x20>;
+		clocks = <&l4_mp_clk>;
+		resets = <&rst FPGAMGR_RESET>;
+	};
Signature · 1 line
2.9.1
author
#6 lore raw

PATCH 2/2 fpga-manager: Add Socfpga Arria10 support

In reply to Alan Tull

Add low level driver to support reprogramming FPGAs for Altera SoCFPGA Arria10.

---
 drivers/fpga/Kconfig       |   6 +
 drivers/fpga/Makefile      |   1 +
 drivers/fpga/socfpga-a10.c | 573 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 580 insertions(+)
 create mode 100644 drivers/fpga/socfpga-a10.c
drivers/fpga/Kconfig +6 -0
index b346166..1a18623 100644
@@ -26,6 +26,12 @@ config FPGA_MGR_SOCFPGA
 	help
 	  FPGA manager driver support for Altera SOCFPGA.
 
+config FPGA_MGR_SOCFPGA_A10
+	tristate "Altera SoCFPGA Arria10"
+	depends on ARCH_SOCFPGA
+	help
+	  FPGA manager driver support for Altera Arria10 SoCFPGA.
+
 config FPGA_MGR_ZYNQ_FPGA
 	tristate "Xilinx Zynq FPGA"
 	depends on HAS_DMA
drivers/fpga/Makefile +1 -0
index e658436..0375cbd 100644
@@ -7,6 +7,7 @@ obj-$(CONFIG_FPGA)			+= fpga-mgr.o
 
 # FPGA Manager Drivers
 obj-$(CONFIG_FPGA_MGR_SOCFPGA)		+= socfpga.o
+obj-$(CONFIG_FPGA_MGR_SOCFPGA_A10)	+= socfpga-a10.o
 obj-$(CONFIG_FPGA_MGR_ZYNQ_FPGA)	+= zynq-fpga.o
 
 # FPGA Bridge Drivers
drivers/fpga/socfpga-a10.c new file +573 -0

573 lines not on this page · raw message

Signature · 1 line
2.9.1
#7 lore raw

Re: [PATCH 2/2] fpga-manager: Add Socfpga Arria10 support

Hi Alan,

couple of nits inline below.

Quoted 9 lines · Alan Tull
drivers/fpga/socfpga-a10.c new file +9 -0
+static int socfpga_a10_fpga_write_complete(struct fpga_manager *mgr, u32 flags)
+{
+       struct a10_fpga_priv *priv = mgr->priv;
+       u32 reg;
+       int ret;
+
+       /* Wait for pr_done */
+       ret = socfpga_a10_fpga_wait_for_pr_done(priv);
+

drivers/fpga/socfpga-a10.c line 437

Quoted 10 lines
drivers/fpga/socfpga-a10.c new file +10 -0
+       /* Clear pr_request */
+       regmap_update_bits(priv->regmap, A10_FPGAMGR_IMGCFG_CTL_01_OFST,
+                          A10_FPGAMGR_IMGCFG_CTL_01_S2F_PR_REQUEST, 0);
+
+       /* Send some clocks to clear out any errors */
+       socfpga_a10_fpga_generate_dclks(priv, 256);
+
+       /* Disable s2f dclk and data */
+       regmap_update_bits(priv->regmap, A10_FPGAMGR_IMGCFG_CTL_02_OFST,
+                          A10_FPGAMGR_IMGCFG_CTL_02_EN_CFG_CTRL, 0);

Maybe replace 0 with named constant.

Quoted 86 lines
drivers/fpga/socfpga-a10.c new file +86 -0
+
+       /* Deassert chip select */
+       regmap_update_bits(priv->regmap, A10_FPGAMGR_IMGCFG_CTL_01_OFST,
+                          A10_FPGAMGR_IMGCFG_CTL_01_S2F_NCE,
+                          A10_FPGAMGR_IMGCFG_CTL_01_S2F_NCE);
+
+       /* Disable data, dclk, nce, and pr_request override to CSS */
+       regmap_update_bits(priv->regmap, A10_FPGAMGR_IMGCFG_CTL_01_OFST,
+                          A10_FPGAMGR_IMGCFG_CTL_01_S2F_NENABLE_CONFIG,
+                          A10_FPGAMGR_IMGCFG_CTL_01_S2F_NENABLE_CONFIG);
+
+       /* Return any errors regarding pr_done or pr_error */
+       if (ret)
+               return ret;
+
+       /* Final check */
+       reg = socfpga_a10_fpga_read_stat(priv);
+
+       if (((reg & A10_FPGAMGR_IMGCFG_STAT_F2S_USERMODE) == 0) ||
+           ((reg & A10_FPGAMGR_IMGCFG_STAT_F2S_CONDONE_PIN) == 0) ||
+           ((reg & A10_FPGAMGR_IMGCFG_STAT_F2S_NSTATUS_PIN) == 0)) {
+               dev_dbg(&mgr->dev,
+                       "Timeout in final check. Status=%08xf\n", reg);
+               return -ETIMEDOUT;
+       }
+
+       return 0;
+}
+
+static enum fpga_mgr_states socfpga_a10_fpga_state(struct fpga_manager *mgr)
+{
+       struct a10_fpga_priv *priv = mgr->priv;
+       u32 reg = socfpga_a10_fpga_read_stat(priv);
+
+       if (reg & A10_FPGAMGR_IMGCFG_STAT_F2S_USERMODE)
+               return FPGA_MGR_STATE_OPERATING;
+
+       if (reg & A10_FPGAMGR_IMGCFG_STAT_F2S_PR_READY)
+               return FPGA_MGR_STATE_WRITE;
+
+       if (reg & A10_FPGAMGR_IMGCFG_STAT_F2S_CRC_ERROR)
+               return FPGA_MGR_STATE_WRITE_COMPLETE_ERR;
+
+       if ((reg & A10_FPGAMGR_IMGCFG_STAT_F2S_NSTATUS_PIN) == 0)
+               return FPGA_MGR_STATE_RESET;
+
+       return FPGA_MGR_STATE_UNKNOWN;
+}
+
+static const struct fpga_manager_ops socfpga_a10_fpga_mgr_ops = {
+       .state = socfpga_a10_fpga_state,
+       .write_init = socfpga_a10_fpga_write_init,
+       .write = socfpga_a10_fpga_write,
+       .write_complete = socfpga_a10_fpga_write_complete,
+};
+
+static int socfpga_a10_fpga_probe(struct platform_device *pdev)
+{
+       struct device *dev = &pdev->dev;
+       struct a10_fpga_priv *priv;
+       void __iomem *reg_base;
+       struct resource *res;
+       int ret;
+
+       priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+       if (!priv)
+               return -ENOMEM;
+
+       /* First mmio base is for register access */
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       reg_base = devm_ioremap_resource(dev, res);
+       if (IS_ERR(reg_base))
+               return PTR_ERR(reg_base);
+
+       /* Second mmio base is for writing FPGA image data */
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+       priv->fpga_data_addr = devm_ioremap_resource(dev, res);
+       if (IS_ERR(priv->fpga_data_addr))
+               return PTR_ERR(priv->fpga_data_addr);
+
+       /* regmap for register access */
+       priv->regmap = devm_regmap_init_mmio(dev, reg_base,
+                                            &socfpga_a10_fpga_regmap_config);
+       if (IS_ERR(priv->regmap))
+               return -ENODEV;
+

drivers/fpga/socfpga-a10.c line 533

Quoted 10 lines
drivers/fpga/socfpga-a10.c new file +10 -0
+       priv->clk = devm_clk_get(dev, NULL);
+       if (IS_ERR(priv->clk)) {
+               dev_err(dev, "no clock specified\n");
+               return PTR_ERR(priv->clk);
+       }
+
+       ret = clk_prepare_enable(priv->clk);
+       if (ret) {
+               dev_err(dev, "could not enable clock\n");
+               clk_put(priv->clk);

Seen that you used devm_clk_get() is this one necessary?

drivers/fpga/socfpga-a10.c line 548

Quoted 8 lines
drivers/fpga/socfpga-a10.c new file +8 -0
+static int socfpga_a10_fpga_remove(struct platform_device *pdev)
+{
+       struct fpga_manager *mgr = platform_get_drvdata(pdev);
+       struct a10_fpga_priv *priv = mgr->priv;
+
+       fpga_mgr_unregister(&pdev->dev);
+       clk_disable_unprepare(priv->clk);
+       clk_put(priv->clk);

Same here, if needed at all shouldn't it be devm_clk_put() ?

Cheers,

Moritz

#8 lore raw

Re: [PATCH 2/2] fpga-manager: Add Socfpga Arria10 support

Quoted 12 lines · Moritz Fischer

drivers/fpga/socfpga-a10.c line 533

Quoted 10 lines · Alan Tull
drivers/fpga/socfpga-a10.c new file +10 -0
+       priv->clk = devm_clk_get(dev, NULL);
+       if (IS_ERR(priv->clk)) {
+               dev_err(dev, "no clock specified\n");
+               return PTR_ERR(priv->clk);
+       }
+
+       ret = clk_prepare_enable(priv->clk);
+       if (ret) {
+               dev_err(dev, "could not enable clock\n");
+               clk_put(priv->clk);
Quoted 1 line

Seen that you used devm_clk_get() is this one necessary?

That's actually a bug. Never clk_put() a devm_clk_get()'d clock. devm_clk_put() is what you want if provided. However, I think this clk_put() call is useless here.

Quoted 10 lines

drivers/fpga/socfpga-a10.c line 548

Quoted 8 lines
drivers/fpga/socfpga-a10.c new file +8 -0
+static int socfpga_a10_fpga_remove(struct platform_device *pdev)
+{
+       struct fpga_manager *mgr = platform_get_drvdata(pdev);
+       struct a10_fpga_priv *priv = mgr->priv;
+
+       fpga_mgr_unregister(&pdev->dev);
+       clk_disable_unprepare(priv->clk);
+       clk_put(priv->clk);

Same here, if needed at all shouldn't it be devm_clk_put() ?

And also useless here, as the whole point of the devm_* stuff is to clean up the resources that were claimed on probe failure or when the device is unbound from its driver.

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
author
#9 lore raw

Re: [PATCH 2/2] fpga-manager: Add Socfpga Arria10 support

Quoted 13 lines · Russell King - ARM Linux
Quoted 12 lines · Moritz Fischer
Quoted 10 lines · Alan Tull
drivers/fpga/socfpga-a10.c new file +10 -0
+       priv->clk = devm_clk_get(dev, NULL);
+       if (IS_ERR(priv->clk)) {
+               dev_err(dev, "no clock specified\n");
+               return PTR_ERR(priv->clk);
+       }
+
+       ret = clk_prepare_enable(priv->clk);
+       if (ret) {
+               dev_err(dev, "could not enable clock\n");
+               clk_put(priv->clk);
Quoted 3 lines
Quoted 1 line

Seen that you used devm_clk_get() is this one necessary?

That's actually a bug.

Yes, it's wrong. And not needed anyway.

Quoted 15 lines

Never clk_put() a devm_clk_get()'d clock.
devm_clk_put() is what you want if provided. However, I think this clk_put() call is useless here.

Quoted 10 lines

drivers/fpga/socfpga-a10.c line 548

Quoted 8 lines
drivers/fpga/socfpga-a10.c new file +8 -0
+static int socfpga_a10_fpga_remove(struct platform_device *pdev)
+{
+       struct fpga_manager *mgr = platform_get_drvdata(pdev);
+       struct a10_fpga_priv *priv = mgr->priv;
+
+       fpga_mgr_unregister(&pdev->dev);
+       clk_disable_unprepare(priv->clk);
+       clk_put(priv->clk);

Same here, if needed at all shouldn't it be devm_clk_put() ?

Quoted 3 lines

And also useless here, as the whole point of the devm_* stuff is to clean up the resources that were claimed on probe failure or when the device is unbound from its driver.

Thanks for pointing this out. I'll take out the clk_put's.

Alan

Quoted 6 lines
Signature · 4 lines
-- 
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
author
#10 lore raw

Re: [PATCH 2/2] fpga-manager: Add Socfpga Arria10 support

In reply to Moritz Fischer
Quoted 4 lines · Moritz Fischer

Hi Alan,

couple of nits inline below.

Hi Moritz!

Thanks for your review!

Quoted 15 lines · Alan Tull
Quoted 14 lines
drivers/fpga/socfpga-a10.c new file +13 -0
+static int socfpga_a10_fpga_write_complete(struct fpga_manager *mgr, u32 flags)
+{
+       struct a10_fpga_priv *priv = mgr->priv;
+       u32 reg;
+       int ret;
+
+       /* Wait for pr_done */
+       ret = socfpga_a10_fpga_wait_for_pr_done(priv);
+
+       /* Clear pr_request */
+       regmap_update_bits(priv->regmap, A10_FPGAMGR_IMGCFG_CTL_01_OFST,
+                          A10_FPGAMGR_IMGCFG_CTL_01_S2F_PR_REQUEST, 0);
+
Quoted 8 lines

drivers/fpga/socfpga-a10.c line 437

Quoted 6 lines
drivers/fpga/socfpga-a10.c new file +6 -0
+       /* Send some clocks to clear out any errors */
+       socfpga_a10_fpga_generate_dclks(priv, 256);
+
+       /* Disable s2f dclk and data */
+       regmap_update_bits(priv->regmap, A10_FPGAMGR_IMGCFG_CTL_02_OFST,
+                          A10_FPGAMGR_IMGCFG_CTL_02_EN_CFG_CTRL, 0);

Maybe replace 0 with named constant.

Generally I use named constants, but since regmap_updates_bits uses a mask, it is clear that we're clearing the A10_FPGAMGR_IMGCFG_CTL_02_EN_CFG_CTRL bit.

Quoted 34 lines
Quoted 34 lines
drivers/fpga/socfpga-a10.c new file +34 -0
+static int socfpga_a10_fpga_probe(struct platform_device *pdev)
+{
+       struct device *dev = &pdev->dev;
+       struct a10_fpga_priv *priv;
+       void __iomem *reg_base;
+       struct resource *res;
+       int ret;
+
+       priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+       if (!priv)
+               return -ENOMEM;
+
+       /* First mmio base is for register access */
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       reg_base = devm_ioremap_resource(dev, res);
+       if (IS_ERR(reg_base))
+               return PTR_ERR(reg_base);
+
+       /* Second mmio base is for writing FPGA image data */
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+       priv->fpga_data_addr = devm_ioremap_resource(dev, res);
+       if (IS_ERR(priv->fpga_data_addr))
+               return PTR_ERR(priv->fpga_data_addr);
+
+       /* regmap for register access */
+       priv->regmap = devm_regmap_init_mmio(dev, reg_base,
+                                            &socfpga_a10_fpga_regmap_config);
+       if (IS_ERR(priv->regmap))
+               return -ENODEV;
+
+       priv->clk = devm_clk_get(dev, NULL);
+       if (IS_ERR(priv->clk)) {
+               dev_err(dev, "no clock specified\n");
+               return PTR_ERR(priv->clk);
Quoted 8 lines

drivers/fpga/socfpga-a10.c line 533

Quoted 6 lines
drivers/fpga/socfpga-a10.c new file +6 -0
+       }
+
+       ret = clk_prepare_enable(priv->clk);
+       if (ret) {
+               dev_err(dev, "could not enable clock\n");
+               clk_put(priv->clk);

Seen that you used devm_clk_get() is this one necessary?

Yes, this is wrong. I'll fix it.

Thanks,
Alan

Quoted 16 lines

drivers/fpga/socfpga-a10.c line 548

Quoted 9 lines
drivers/fpga/socfpga-a10.c new file +8 -0
+static int socfpga_a10_fpga_remove(struct platform_device *pdev)
+{
+       struct fpga_manager *mgr = platform_get_drvdata(pdev);
+       struct a10_fpga_priv *priv = mgr->priv;
+
+       fpga_mgr_unregister(&pdev->dev);
+       clk_disable_unprepare(priv->clk);
+       clk_put(priv->clk);

Same here, if needed at all shouldn't it be devm_clk_put() ?

Cheers,

Moritz

maintainer Acked-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] ARM: socfpga: add bindings doc for arria10 fpga manager

In reply to Alan Tull
Quoted 8 lines · Alan Tull

Add a device tree bindings document for the SoCFPGA Arria10 FPGA Manager driver.

---
 .../bindings/fpga/altera-socfpga-a10-fpga-mgr.txt     | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/fpga/altera-socfpga-a10-fpga-mgr.txt
Acked-by on v1 1/2
#4 lore raw

Re: [PATCH 1/2] ARM: socfpga: add bindings doc for arria10 fpga manager

In reply to Alan Tull
Quoted 37 lines · Alan Tull

Add a device tree bindings document for the SoCFPGA Arria10 FPGA Manager driver.

---
 .../bindings/fpga/altera-socfpga-a10-fpga-mgr.txt     | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/fpga/altera-socfpga-a10-fpga-mgr.txt
Documentation/devicetree/bindings/fpga/altera-socfpga-a10-fpga-mgr.txt new file +19 -1
new file mode 100644
index 0000000..2fd8e7a
@@ -0,0 +1,19 @@
+Altera SOCFPGA Arria10 FPGA Manager
+
+Required properties:
+- compatible : should contain "altr,socfpga-a10-fpga-mgr"
+- reg        : base address and size for memory mapped io.
+               - The first index is for FPGA manager register access.
+               - The second index is for writing FPGA configuration data.
+- resets     : Phandle and reset specifier for the device's reset.
+- clocks     : Clocks used by the device.
+
+Example:
+
+       fpga_mgr: fpga-mgr at ffd03000 {
+               compatible = "altr,socfpga-a10-fpga-mgr";
+               reg = <0xffd03000 0x100
+                      0xffcfe400 0x20>;
+               clocks = <&l4_mp_clk>;
+               resets = <&rst FPGAMGR_RESET>;
+       };
--

2.9.1

author
#3 lore raw

Re: [PATCH 1/2] ARM: socfpga: add bindings doc for arria10 fpga manager

In reply to Rob Herring
Quoted 4 lines · Rob Herring
Quoted 3 lines · Alan Tull

Add a device tree bindings document for the SoCFPGA Arria10 FPGA Manager driver.

Quoted 8 lines
Quoted 5 lines
---
 .../bindings/fpga/altera-socfpga-a10-fpga-mgr.txt     | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/fpga/altera-socfpga-a10-fpga-mgr.txt

Thanks!

Alan

author
#5 lore raw

Re: [PATCH 1/2] ARM: socfpga: add bindings doc for arria10 fpga manager

In reply to Moritz Fischer
Quoted 1 line · Moritz Fischer

Thanks Moritz!

Alan

Quoted 40 lines · Alan Tull
Quoted 37 lines

Add a device tree bindings document for the SoCFPGA Arria10 FPGA Manager driver.

---
 .../bindings/fpga/altera-socfpga-a10-fpga-mgr.txt     | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/fpga/altera-socfpga-a10-fpga-mgr.txt
Documentation/devicetree/bindings/fpga/altera-socfpga-a10-fpga-mgr.txt new file +19 -1
new file mode 100644
index 0000000..2fd8e7a
@@ -0,0 +1,19 @@
+Altera SOCFPGA Arria10 FPGA Manager
+
+Required properties:
+- compatible : should contain "altr,socfpga-a10-fpga-mgr"
+- reg        : base address and size for memory mapped io.
+               - The first index is for FPGA manager register access.
+               - The second index is for writing FPGA configuration data.
+- resets     : Phandle and reset specifier for the device's reset.
+- clocks     : Clocks used by the device.
+
+Example:
+
+       fpga_mgr: fpga-mgr at ffd03000 {
+               compatible = "altr,socfpga-a10-fpga-mgr";
+               reg = <0xffd03000 0x100
+                      0xffcfe400 0x20>;
+               clocks = <&l4_mp_clk>;
+               resets = <&rst FPGAMGR_RESET>;
+       };
--

2.9.1