linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] nvmem: i.MX IIM driver
@ 2017-02-13 15:31 Sascha Hauer
  2017-02-13 15:31 ` [PATCH 1/2] nvmem: Add driver for the i.MX IIM Sascha Hauer
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Sascha Hauer @ 2017-02-13 15:31 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-arm-kernel, Srinivas Kandagatla, Maxime Ripard, Shawn Guo,
	Fabio Estevam, kernel, Rob Herring, Mark Rutland


This adds a readonly nvmem driver for the i.MX IC Identification Module (IIM)
which is found on the older i.MX SoCs. The IIM is part of the i.MX dts files
for long now, but so far there is no binding document for it, so add one now.

Sascha

----------------------------------------------------------------
Michael Grzeschik (1):
      nvmem: Add driver for the i.MX IIM

Sascha Hauer (1):
      dt-bindings: nvmem: Add i.MX IIM binding doc

 .../devicetree/bindings/nvmem/imx-iim.txt          |  22 +++
 drivers/nvmem/Kconfig                              |  11 ++
 drivers/nvmem/Makefile                             |   2 +
 drivers/nvmem/imx-iim.c                            | 171 +++++++++++++++++++++
 4 files changed, 206 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/nvmem/imx-iim.txt
 create mode 100644 drivers/nvmem/imx-iim.c

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/2] nvmem: Add driver for the i.MX IIM
  2017-02-13 15:31 [PATCH v1] nvmem: i.MX IIM driver Sascha Hauer
@ 2017-02-13 15:31 ` Sascha Hauer
  2017-02-13 22:33   ` kbuild test robot
  2017-03-03  9:50   ` Srinivas Kandagatla
  2017-02-13 15:31 ` [PATCH 2/2] dt-bindings: nvmem: Add i.MX IIM binding doc Sascha Hauer
  2017-03-03  6:36 ` [PATCH v1] nvmem: i.MX IIM driver Sascha Hauer
  2 siblings, 2 replies; 10+ messages in thread
From: Sascha Hauer @ 2017-02-13 15:31 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-arm-kernel, Srinivas Kandagatla, Maxime Ripard, Shawn Guo,
	Fabio Estevam, kernel, Rob Herring, Mark Rutland,
	Michael Grzeschik, Sascha Hauer

From: Michael Grzeschik <m.grzeschik@pengutronix.de>

This adds a readonly nvmem driver for the i.MX IC Identification Module
(IIM). The IIM is found on the older i.MX SoCs like the i.MX25, i.MX27,
i.MX31, i.MX35, i.MX51 and the i.MX53.

The IIM can control up to 8 fuse banks with 256 bit each. Not all of the
banks are equipped on the different SoCs. The actual number of fuses
differ from 512 on the i.MX27 and 1152 on the i.MX53.

The fuses are one time writable, but writing is currently not supported
in the driver.

Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/nvmem/Kconfig   |  11 ++++
 drivers/nvmem/Makefile  |   2 +
 drivers/nvmem/imx-iim.c | 171 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 184 insertions(+)
 create mode 100644 drivers/nvmem/imx-iim.c

diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
index 650f1b1797ad..101ced4c84be 100644
--- a/drivers/nvmem/Kconfig
+++ b/drivers/nvmem/Kconfig
@@ -13,6 +13,17 @@ menuconfig NVMEM
 
 if NVMEM
 
+config NVMEM_IMX_IIM
+	tristate "i.MX IC Identification Module support"
+	depends on ARCH_MXC || COMPILE_TEST
+	help
+	  This is a driver for the IC Identification Module (IIM) available on
+	  i.MX SoCs, providing access to 4 Kbits of programmable
+	  eFuses.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called nvmem-imx-iim.
+
 config NVMEM_IMX_OCOTP
 	tristate "i.MX6 On-Chip OTP Controller support"
 	depends on SOC_IMX6 || COMPILE_TEST
diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile
index 86e45995fdad..173140658693 100644
--- a/drivers/nvmem/Makefile
+++ b/drivers/nvmem/Makefile
@@ -8,6 +8,8 @@ nvmem_core-y			:= core.o
 # Devices
 obj-$(CONFIG_NVMEM_BCM_OCOTP)	+= nvmem-bcm-ocotp.o
 nvmem-bcm-ocotp-y		:= bcm-ocotp.o
+obj-$(CONFIG_NVMEM_IMX_IIM)	+= nvmem-imx-iim.o
+nvmem-imx-iim-y			:= imx-iim.o
 obj-$(CONFIG_NVMEM_IMX_OCOTP)	+= nvmem-imx-ocotp.o
 nvmem-imx-ocotp-y		:= imx-ocotp.o
 obj-$(CONFIG_NVMEM_LPC18XX_EEPROM)	+= nvmem_lpc18xx_eeprom.o
diff --git a/drivers/nvmem/imx-iim.c b/drivers/nvmem/imx-iim.c
new file mode 100644
index 000000000000..83b546f42e26
--- /dev/null
+++ b/drivers/nvmem/imx-iim.c
@@ -0,0 +1,171 @@
+/*
+ * i.MX IIM driver
+ *
+ * Copyright (c) 2017 Pengutronix, Michael Grzeschik <m.grzeschik@pengutronix.de>
+ *
+ * Based on the barebox iim driver,
+ * Copyright (c) 2010 Baruch Siach <baruch@tkos.co.il>,
+ *	Orex Computed Radiography
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+#include <linux/device.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/nvmem-provider.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/clk.h>
+
+#define IIM_BANK_BASE(n)	(0x800 + 0x400 * (n))
+
+struct imx_iim_drvdata {
+	unsigned int nregs;
+};
+
+struct iim_priv {
+	void __iomem *base;
+	struct clk *clk;
+	struct nvmem_config nvmem;
+};
+
+static int imx_iim_read(void *context, unsigned int offset,
+			  void *buf, size_t bytes)
+{
+	struct iim_priv *iim = context;
+	int i, ret;
+	u8 *buf8 = buf;
+
+	ret = clk_prepare_enable(iim->clk);
+	if (ret)
+		return ret;
+
+	for (i = offset; i < offset + bytes; i++) {
+		int bank = i >> 5;
+		int reg = i & 0x1f;
+
+		*buf8++ = readl(iim->base + IIM_BANK_BASE(bank) + reg * 4);
+	}
+
+	clk_disable_unprepare(iim->clk);
+
+	return 0;
+}
+
+static struct imx_iim_drvdata imx27_drvdata = {
+	.nregs = 2 * 32,
+};
+
+static struct imx_iim_drvdata imx25_imx31_imx35_drvdata = {
+	.nregs = 3 * 32,
+};
+
+static struct imx_iim_drvdata imx51_drvdata = {
+	.nregs = 4 * 32,
+};
+
+static struct imx_iim_drvdata imx53_drvdata = {
+	.nregs = 4 * 32 + 16,
+};
+
+static const struct of_device_id imx_iim_dt_ids[] = {
+	{
+		.compatible = "fsl,imx25-iim",
+		.data = &imx25_imx31_imx35_drvdata,
+	}, {
+		.compatible = "fsl,imx27-iim",
+		.data = &imx27_drvdata,
+	}, {
+		.compatible = "fsl,imx31-iim",
+		.data = &imx25_imx31_imx35_drvdata,
+	}, {
+		.compatible = "fsl,imx35-iim",
+		.data = &imx25_imx31_imx35_drvdata,
+	}, {
+		.compatible = "fsl,imx51-iim",
+		.data = &imx51_drvdata,
+	}, {
+		.compatible = "fsl,imx53-iim",
+		.data = &imx53_drvdata,
+	},
+};
+MODULE_DEVICE_TABLE(of, imx_iim_dt_ids);
+
+static int imx_iim_probe(struct platform_device *pdev)
+{
+	const struct of_device_id *of_id;
+	struct device *dev = &pdev->dev;
+	struct resource *res;
+	struct iim_priv *iim;
+	struct nvmem_device *nvmem;
+	struct nvmem_config *cfg;
+	const struct imx_iim_drvdata *drvdata = NULL;
+
+	iim = devm_kzalloc(dev, sizeof(*iim), GFP_KERNEL);
+	if (!iim)
+		return -ENOMEM;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	iim->base = devm_ioremap_resource(dev, res);
+	if (IS_ERR(iim->base))
+		return PTR_ERR(iim->base);
+
+	of_id = of_match_device(imx_iim_dt_ids, dev);
+	if (!of_id)
+		return -ENODEV;
+
+	drvdata = of_id->data;
+
+	iim->clk = devm_clk_get(&pdev->dev, NULL);
+	if (IS_ERR(iim->clk))
+		return PTR_ERR(iim->clk);
+
+	cfg = &iim->nvmem;
+
+	cfg->name = "imx-iim",
+	cfg->read_only = true,
+	cfg->word_size = 1,
+	cfg->stride = 1,
+	cfg->owner = THIS_MODULE,
+	cfg->reg_read = imx_iim_read,
+	cfg->dev = dev;
+	cfg->size = drvdata->nregs;
+	cfg->priv = iim;
+
+	nvmem = nvmem_register(cfg);
+	if (IS_ERR(nvmem))
+		return PTR_ERR(nvmem);
+
+	platform_set_drvdata(pdev, nvmem);
+
+	return 0;
+}
+
+static int imx_iim_remove(struct platform_device *pdev)
+{
+	struct nvmem_device *nvmem = platform_get_drvdata(pdev);
+
+	return nvmem_unregister(nvmem);
+}
+
+static struct platform_driver imx_iim_driver = {
+	.probe	= imx_iim_probe,
+	.remove	= imx_iim_remove,
+	.driver = {
+		.name	= "imx-iim",
+		.of_match_table = imx_iim_dt_ids,
+	},
+};
+module_platform_driver(imx_iim_driver);
+
+MODULE_AUTHOR("Michael Grzeschik <m.grzeschik@pengutronix.de>");
+MODULE_DESCRIPTION("i.MX IIM driver");
+MODULE_LICENSE("GPL v2");
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/2] dt-bindings: nvmem: Add i.MX IIM binding doc
  2017-02-13 15:31 [PATCH v1] nvmem: i.MX IIM driver Sascha Hauer
  2017-02-13 15:31 ` [PATCH 1/2] nvmem: Add driver for the i.MX IIM Sascha Hauer
@ 2017-02-13 15:31 ` Sascha Hauer
  2017-03-03  6:36 ` [PATCH v1] nvmem: i.MX IIM driver Sascha Hauer
  2 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2017-02-13 15:31 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-arm-kernel, Srinivas Kandagatla, Maxime Ripard, Shawn Guo,
	Fabio Estevam, kernel, Rob Herring, Mark Rutland, Sascha Hauer

The IIM is part of the i.MX device trees for long already, add a binding
document for it.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 .../devicetree/bindings/nvmem/imx-iim.txt          | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/nvmem/imx-iim.txt

diff --git a/Documentation/devicetree/bindings/nvmem/imx-iim.txt b/Documentation/devicetree/bindings/nvmem/imx-iim.txt
new file mode 100644
index 000000000000..1978c5bcd96d
--- /dev/null
+++ b/Documentation/devicetree/bindings/nvmem/imx-iim.txt
@@ -0,0 +1,22 @@
+Freescale i.MX IC Identification Module (IIM) device tree bindings
+
+This binding represents the IC Identification Module (IIM) found on
+i.MX25, i.MX27, i.MX31, i.MX35, i.MX51 and i.MX53 SoCs.
+
+Required properties:
+- compatible: should be one of
+	"fsl,imx25-iim", "fsl,imx27-iim",
+	"fsl,imx31-iim", "fsl,imx35-iim",
+	"fsl,imx51-iim", "fsl,imx53-iim",
+- reg: Should contain the register base and length.
+- interrupts: Should contain the interrupt for the IIM
+- clocks: Should contain a phandle pointing to the gated peripheral clock.
+
+Example:
+
+	iim: iim@63f98000 {
+		compatible = "fsl,imx53-iim", "fsl,imx27-iim";
+		reg = <0x63f98000 0x4000>;
+		interrupts = <69>;
+                clocks = <&clks IMX5_CLK_IIM_GATE>;
+	};
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] nvmem: Add driver for the i.MX IIM
  2017-02-13 15:31 ` [PATCH 1/2] nvmem: Add driver for the i.MX IIM Sascha Hauer
@ 2017-02-13 22:33   ` kbuild test robot
  2017-02-14  8:00     ` Sascha Hauer
  2017-03-03  9:50   ` Srinivas Kandagatla
  1 sibling, 1 reply; 10+ messages in thread
From: kbuild test robot @ 2017-02-13 22:33 UTC (permalink / raw)
  To: Sascha Hauer
  Cc: kbuild-all, linux-kernel, linux-arm-kernel, Srinivas Kandagatla,
	Maxime Ripard, Shawn Guo, Fabio Estevam, kernel, Rob Herring,
	Mark Rutland, Michael Grzeschik, Sascha Hauer

[-- Attachment #1: Type: text/plain, Size: 1869 bytes --]

Hi Michael,

[auto build test ERROR on linus/master]
[also build test ERROR on v4.10-rc8 next-20170213]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Sascha-Hauer/nvmem-Add-driver-for-the-i-MX-IIM/20170214-000520
config: i386-allmodconfig (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

   drivers/nvmem/nvmem-imx-iim: struct of_device_id is 196 bytes.  The last of 6 is:
   0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x66 0x73 0x6c 0x2c 0x69 0x6d 0x78 0x35 0x33 0x2d 0x69 0x69 0x6d 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x5c 0x00 0x00 0x00 
>> FATAL: drivers/nvmem/nvmem-imx-iim: struct of_device_id is not terminated with a NULL entry!

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 57952 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] nvmem: Add driver for the i.MX IIM
  2017-02-13 22:33   ` kbuild test robot
@ 2017-02-14  8:00     ` Sascha Hauer
  0 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2017-02-14  8:00 UTC (permalink / raw)
  To: knux-kernel
  Cc: linux-kernel, linux-arm-kernel, Srinivas Kandagatla,
	Maxime Ripard, Shawn Guo, Fabio Estevam, kernel, Rob Herring,
	Mark Rutland, Michael Grzeschik

On Tue, Feb 14, 2017 at 06:33:25AM +0800, kbuild test robot wrote:
> Hi Michael,
> 
> [auto build test ERROR on linus/master]
> [also build test ERROR on v4.10-rc8 next-20170213]
> [if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
> 
> url:    https://github.com/0day-ci/linux/commits/Sascha-Hauer/nvmem-Add-driver-for-the-i-MX-IIM/20170214-000520
> config: i386-allmodconfig (attached as .config)
> compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
> reproduce:
>         # save the attached .config to linux build tree
>         make ARCH=i386 
> 
> All errors (new ones prefixed by >>):
> 
>    drivers/nvmem/nvmem-imx-iim: struct of_device_id is 196 bytes.  The last of 6 is:
>    0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x66 0x73 0x6c 0x2c 0x69 0x6d 0x78 0x35 0x33 0x2d 0x69 0x69 0x6d 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x5c 0x00 0x00 0x00 
> >> FATAL: drivers/nvmem/nvmem-imx-iim: struct of_device_id is not terminated with a NULL entry!

I'm amazed that the kbuild test is able to catch this kind of error :)

Will fix in v2, but wait for other comments first.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v1] nvmem: i.MX IIM driver
  2017-02-13 15:31 [PATCH v1] nvmem: i.MX IIM driver Sascha Hauer
  2017-02-13 15:31 ` [PATCH 1/2] nvmem: Add driver for the i.MX IIM Sascha Hauer
  2017-02-13 15:31 ` [PATCH 2/2] dt-bindings: nvmem: Add i.MX IIM binding doc Sascha Hauer
@ 2017-03-03  6:36 ` Sascha Hauer
  2 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2017-03-03  6:36 UTC (permalink / raw)
  To: Srinivas Kandagatla, Maxime Ripard
  Cc: linux-kernel, Mark Rutland, Rob Herring, kernel, Fabio Estevam,
	Shawn Guo, linux-arm-kernel

Srinivas, Maxime,

Any comments on this one?

Sascha

On Mon, Feb 13, 2017 at 04:31:47PM +0100, Sascha Hauer wrote:
> 
> This adds a readonly nvmem driver for the i.MX IC Identification Module (IIM)
> which is found on the older i.MX SoCs. The IIM is part of the i.MX dts files
> for long now, but so far there is no binding document for it, so add one now.
> 
> Sascha
> 
> ----------------------------------------------------------------
> Michael Grzeschik (1):
>       nvmem: Add driver for the i.MX IIM
> 
> Sascha Hauer (1):
>       dt-bindings: nvmem: Add i.MX IIM binding doc
> 
>  .../devicetree/bindings/nvmem/imx-iim.txt          |  22 +++
>  drivers/nvmem/Kconfig                              |  11 ++
>  drivers/nvmem/Makefile                             |   2 +
>  drivers/nvmem/imx-iim.c                            | 171 +++++++++++++++++++++
>  4 files changed, 206 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/nvmem/imx-iim.txt
>  create mode 100644 drivers/nvmem/imx-iim.c
> 
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] nvmem: Add driver for the i.MX IIM
  2017-02-13 15:31 ` [PATCH 1/2] nvmem: Add driver for the i.MX IIM Sascha Hauer
  2017-02-13 22:33   ` kbuild test robot
@ 2017-03-03  9:50   ` Srinivas Kandagatla
  2017-03-03  9:54     ` Srinivas Kandagatla
  1 sibling, 1 reply; 10+ messages in thread
From: Srinivas Kandagatla @ 2017-03-03  9:50 UTC (permalink / raw)
  To: Sascha Hauer, linux-kernel
  Cc: linux-arm-kernel, Maxime Ripard, Shawn Guo, Fabio Estevam,
	kernel, Rob Herring, Mark Rutland, Michael Grzeschik



On 13/02/17 15:31, Sascha Hauer wrote:
> From: Michael Grzeschik <m.grzeschik@pengutronix.de>
>
> This adds a readonly nvmem driver for the i.MX IC Identification Module
> (IIM). The IIM is found on the older i.MX SoCs like the i.MX25, i.MX27,
> i.MX31, i.MX35, i.MX51 and the i.MX53.
>
> The IIM can control up to 8 fuse banks with 256 bit each. Not all of the
> banks are equipped on the different SoCs. The actual number of fuses
> differ from 512 on the i.MX27 and 1152 on the i.MX53.
>
> The fuses are one time writable, but writing is currently not supported
> in the driver.
>
> Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>


> ---
>  drivers/nvmem/Kconfig   |  11 ++++
>  drivers/nvmem/Makefile  |   2 +
>  drivers/nvmem/imx-iim.c | 171 ++++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 184 insertions(+)
>  create mode 100644 drivers/nvmem/imx-iim.c

Patch looks good to me, Will pick both bindings and this patch in next 
cycle for 4.12.

thanks,
srini

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] nvmem: Add driver for the i.MX IIM
  2017-03-03  9:50   ` Srinivas Kandagatla
@ 2017-03-03  9:54     ` Srinivas Kandagatla
  2017-03-03 10:47       ` Sascha Hauer
  0 siblings, 1 reply; 10+ messages in thread
From: Srinivas Kandagatla @ 2017-03-03  9:54 UTC (permalink / raw)
  To: Sascha Hauer, linux-kernel
  Cc: linux-arm-kernel, Maxime Ripard, Shawn Guo, Fabio Estevam,
	kernel, Rob Herring, Mark Rutland, Michael Grzeschik



On 03/03/17 09:50, Srinivas Kandagatla wrote:
>
>
> On 13/02/17 15:31, Sascha Hauer wrote:
>> From: Michael Grzeschik <m.grzeschik@pengutronix.de>
>>
>> This adds a readonly nvmem driver for the i.MX IC Identification Module
>> (IIM). The IIM is found on the older i.MX SoCs like the i.MX25, i.MX27,
>> i.MX31, i.MX35, i.MX51 and the i.MX53.
>>
>> The IIM can control up to 8 fuse banks with 256 bit each. Not all of the
>> banks are equipped on the different SoCs. The actual number of fuses
>> differ from 512 on the i.MX27 and 1152 on the i.MX53.
>>
>> The fuses are one time writable, but writing is currently not supported
>> in the driver.
>>
>> Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
>> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
>
>
>> ---
>>  drivers/nvmem/Kconfig   |  11 ++++
>>  drivers/nvmem/Makefile  |   2 +
>>  drivers/nvmem/imx-iim.c | 171
>> ++++++++++++++++++++++++++++++++++++++++++++++++
>>  3 files changed, 184 insertions(+)
>>  create mode 100644 drivers/nvmem/imx-iim.c
>
> Patch looks good to me, Will pick both bindings and this patch in next
> cycle for 4.12.
Opps sent email too quick..

Can you also make sure that ids are null terminated as reported by 
kbuild https://www.spinics.net/lists/arm-kernel/msg562543.html in next 
version.

--srini

>
> thanks,
> srini

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] nvmem: Add driver for the i.MX IIM
  2017-03-03  9:54     ` Srinivas Kandagatla
@ 2017-03-03 10:47       ` Sascha Hauer
  0 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2017-03-03 10:47 UTC (permalink / raw)
  To: Srinivas Kandagatla
  Cc: linux-kernel, linux-arm-kernel, Maxime Ripard, Shawn Guo,
	Fabio Estevam, kernel, Rob Herring, Mark Rutland,
	Michael Grzeschik

On Fri, Mar 03, 2017 at 09:54:07AM +0000, Srinivas Kandagatla wrote:
> 
> 
> On 03/03/17 09:50, Srinivas Kandagatla wrote:
> > 
> > 
> > On 13/02/17 15:31, Sascha Hauer wrote:
> > > From: Michael Grzeschik <m.grzeschik@pengutronix.de>
> > > 
> > > This adds a readonly nvmem driver for the i.MX IC Identification Module
> > > (IIM). The IIM is found on the older i.MX SoCs like the i.MX25, i.MX27,
> > > i.MX31, i.MX35, i.MX51 and the i.MX53.
> > > 
> > > The IIM can control up to 8 fuse banks with 256 bit each. Not all of the
> > > banks are equipped on the different SoCs. The actual number of fuses
> > > differ from 512 on the i.MX27 and 1152 on the i.MX53.
> > > 
> > > The fuses are one time writable, but writing is currently not supported
> > > in the driver.
> > > 
> > > Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
> > > Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> > 
> > 
> > > ---
> > >  drivers/nvmem/Kconfig   |  11 ++++
> > >  drivers/nvmem/Makefile  |   2 +
> > >  drivers/nvmem/imx-iim.c | 171
> > > ++++++++++++++++++++++++++++++++++++++++++++++++
> > >  3 files changed, 184 insertions(+)
> > >  create mode 100644 drivers/nvmem/imx-iim.c
> > 
> > Patch looks good to me, Will pick both bindings and this patch in next
> > cycle for 4.12.
> Opps sent email too quick..
> 
> Can you also make sure that ids are null terminated as reported by kbuild
> https://www.spinics.net/lists/arm-kernel/msg562543.html in next version.
> 

Thanks for looking. I just sent the v2 series.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/2] nvmem: Add driver for the i.MX IIM
  2017-03-03 10:45 [PATCH v2] " Sascha Hauer
@ 2017-03-03 10:45 ` Sascha Hauer
  0 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2017-03-03 10:45 UTC (permalink / raw)
  To: linux-kernel
  Cc: Mark Rutland, Rob Herring, Srinivas Kandagatla, kernel,
	Fabio Estevam, Maxime Ripard, Shawn Guo, linux-arm-kernel,
	Michael Grzeschik, Sascha Hauer

From: Michael Grzeschik <m.grzeschik@pengutronix.de>

This adds a readonly nvmem driver for the i.MX IC Identification Module
(IIM). The IIM is found on the older i.MX SoCs like the i.MX25, i.MX27,
i.MX31, i.MX35, i.MX51 and the i.MX53.

The IIM can control up to 8 fuse banks with 256 bit each. Not all of the
banks are equipped on the different SoCs. The actual number of fuses
differ from 512 on the i.MX27 and 1152 on the i.MX53.

The fuses are one time writable, but writing is currently not supported
in the driver.

Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/nvmem/Kconfig   |  11 +++
 drivers/nvmem/Makefile  |   2 +
 drivers/nvmem/imx-iim.c | 173 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 186 insertions(+)
 create mode 100644 drivers/nvmem/imx-iim.c

diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
index 650f1b1797ad..101ced4c84be 100644
--- a/drivers/nvmem/Kconfig
+++ b/drivers/nvmem/Kconfig
@@ -13,6 +13,17 @@ menuconfig NVMEM
 
 if NVMEM
 
+config NVMEM_IMX_IIM
+	tristate "i.MX IC Identification Module support"
+	depends on ARCH_MXC || COMPILE_TEST
+	help
+	  This is a driver for the IC Identification Module (IIM) available on
+	  i.MX SoCs, providing access to 4 Kbits of programmable
+	  eFuses.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called nvmem-imx-iim.
+
 config NVMEM_IMX_OCOTP
 	tristate "i.MX6 On-Chip OTP Controller support"
 	depends on SOC_IMX6 || COMPILE_TEST
diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile
index 86e45995fdad..173140658693 100644
--- a/drivers/nvmem/Makefile
+++ b/drivers/nvmem/Makefile
@@ -8,6 +8,8 @@ nvmem_core-y			:= core.o
 # Devices
 obj-$(CONFIG_NVMEM_BCM_OCOTP)	+= nvmem-bcm-ocotp.o
 nvmem-bcm-ocotp-y		:= bcm-ocotp.o
+obj-$(CONFIG_NVMEM_IMX_IIM)	+= nvmem-imx-iim.o
+nvmem-imx-iim-y			:= imx-iim.o
 obj-$(CONFIG_NVMEM_IMX_OCOTP)	+= nvmem-imx-ocotp.o
 nvmem-imx-ocotp-y		:= imx-ocotp.o
 obj-$(CONFIG_NVMEM_LPC18XX_EEPROM)	+= nvmem_lpc18xx_eeprom.o
diff --git a/drivers/nvmem/imx-iim.c b/drivers/nvmem/imx-iim.c
new file mode 100644
index 000000000000..52ff65e0673f
--- /dev/null
+++ b/drivers/nvmem/imx-iim.c
@@ -0,0 +1,173 @@
+/*
+ * i.MX IIM driver
+ *
+ * Copyright (c) 2017 Pengutronix, Michael Grzeschik <m.grzeschik@pengutronix.de>
+ *
+ * Based on the barebox iim driver,
+ * Copyright (c) 2010 Baruch Siach <baruch@tkos.co.il>,
+ *	Orex Computed Radiography
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+#include <linux/device.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/nvmem-provider.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/clk.h>
+
+#define IIM_BANK_BASE(n)	(0x800 + 0x400 * (n))
+
+struct imx_iim_drvdata {
+	unsigned int nregs;
+};
+
+struct iim_priv {
+	void __iomem *base;
+	struct clk *clk;
+	struct nvmem_config nvmem;
+};
+
+static int imx_iim_read(void *context, unsigned int offset,
+			  void *buf, size_t bytes)
+{
+	struct iim_priv *iim = context;
+	int i, ret;
+	u8 *buf8 = buf;
+
+	ret = clk_prepare_enable(iim->clk);
+	if (ret)
+		return ret;
+
+	for (i = offset; i < offset + bytes; i++) {
+		int bank = i >> 5;
+		int reg = i & 0x1f;
+
+		*buf8++ = readl(iim->base + IIM_BANK_BASE(bank) + reg * 4);
+	}
+
+	clk_disable_unprepare(iim->clk);
+
+	return 0;
+}
+
+static struct imx_iim_drvdata imx27_drvdata = {
+	.nregs = 2 * 32,
+};
+
+static struct imx_iim_drvdata imx25_imx31_imx35_drvdata = {
+	.nregs = 3 * 32,
+};
+
+static struct imx_iim_drvdata imx51_drvdata = {
+	.nregs = 4 * 32,
+};
+
+static struct imx_iim_drvdata imx53_drvdata = {
+	.nregs = 4 * 32 + 16,
+};
+
+static const struct of_device_id imx_iim_dt_ids[] = {
+	{
+		.compatible = "fsl,imx25-iim",
+		.data = &imx25_imx31_imx35_drvdata,
+	}, {
+		.compatible = "fsl,imx27-iim",
+		.data = &imx27_drvdata,
+	}, {
+		.compatible = "fsl,imx31-iim",
+		.data = &imx25_imx31_imx35_drvdata,
+	}, {
+		.compatible = "fsl,imx35-iim",
+		.data = &imx25_imx31_imx35_drvdata,
+	}, {
+		.compatible = "fsl,imx51-iim",
+		.data = &imx51_drvdata,
+	}, {
+		.compatible = "fsl,imx53-iim",
+		.data = &imx53_drvdata,
+	}, {
+		/* sentinel */
+	},
+};
+MODULE_DEVICE_TABLE(of, imx_iim_dt_ids);
+
+static int imx_iim_probe(struct platform_device *pdev)
+{
+	const struct of_device_id *of_id;
+	struct device *dev = &pdev->dev;
+	struct resource *res;
+	struct iim_priv *iim;
+	struct nvmem_device *nvmem;
+	struct nvmem_config *cfg;
+	const struct imx_iim_drvdata *drvdata = NULL;
+
+	iim = devm_kzalloc(dev, sizeof(*iim), GFP_KERNEL);
+	if (!iim)
+		return -ENOMEM;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	iim->base = devm_ioremap_resource(dev, res);
+	if (IS_ERR(iim->base))
+		return PTR_ERR(iim->base);
+
+	of_id = of_match_device(imx_iim_dt_ids, dev);
+	if (!of_id)
+		return -ENODEV;
+
+	drvdata = of_id->data;
+
+	iim->clk = devm_clk_get(&pdev->dev, NULL);
+	if (IS_ERR(iim->clk))
+		return PTR_ERR(iim->clk);
+
+	cfg = &iim->nvmem;
+
+	cfg->name = "imx-iim",
+	cfg->read_only = true,
+	cfg->word_size = 1,
+	cfg->stride = 1,
+	cfg->owner = THIS_MODULE,
+	cfg->reg_read = imx_iim_read,
+	cfg->dev = dev;
+	cfg->size = drvdata->nregs;
+	cfg->priv = iim;
+
+	nvmem = nvmem_register(cfg);
+	if (IS_ERR(nvmem))
+		return PTR_ERR(nvmem);
+
+	platform_set_drvdata(pdev, nvmem);
+
+	return 0;
+}
+
+static int imx_iim_remove(struct platform_device *pdev)
+{
+	struct nvmem_device *nvmem = platform_get_drvdata(pdev);
+
+	return nvmem_unregister(nvmem);
+}
+
+static struct platform_driver imx_iim_driver = {
+	.probe	= imx_iim_probe,
+	.remove	= imx_iim_remove,
+	.driver = {
+		.name	= "imx-iim",
+		.of_match_table = imx_iim_dt_ids,
+	},
+};
+module_platform_driver(imx_iim_driver);
+
+MODULE_AUTHOR("Michael Grzeschik <m.grzeschik@pengutronix.de>");
+MODULE_DESCRIPTION("i.MX IIM driver");
+MODULE_LICENSE("GPL v2");
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2017-03-03 11:41 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-13 15:31 [PATCH v1] nvmem: i.MX IIM driver Sascha Hauer
2017-02-13 15:31 ` [PATCH 1/2] nvmem: Add driver for the i.MX IIM Sascha Hauer
2017-02-13 22:33   ` kbuild test robot
2017-02-14  8:00     ` Sascha Hauer
2017-03-03  9:50   ` Srinivas Kandagatla
2017-03-03  9:54     ` Srinivas Kandagatla
2017-03-03 10:47       ` Sascha Hauer
2017-02-13 15:31 ` [PATCH 2/2] dt-bindings: nvmem: Add i.MX IIM binding doc Sascha Hauer
2017-03-03  6:36 ` [PATCH v1] nvmem: i.MX IIM driver Sascha Hauer
2017-03-03 10:45 [PATCH v2] " Sascha Hauer
2017-03-03 10:45 ` [PATCH 1/2] nvmem: Add driver for the i.MX IIM Sascha Hauer

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).