Re: [PATCH v7 3/4] drivers: nvmem: Add Vybrid OCOTP support

2015-08-10 Thread maitysanchayan
Hello,

On 15-08-10 10:17:53, Srinivas Kandagatla wrote:
> Hi Sanchayan,
> 
> 
> Could you add Greg to the "to list" so that we can request him to pick 
> this via his tree.

Will add Greg in cc with the next revision.

> 
> 
> Few nits, other than that driver looks good.
> 
> 
> On 06/08/15 16:27, Sanchayan Maity wrote:
> > The patch adds support for the On Chip One Time Programmable Peripheral
> > (OCOTP) on the Vybrid platform.
> >
> > Signed-off-by: Sanchayan Maity 
> > ---
> >   drivers/nvmem/Kconfig   |  10 ++
> >   drivers/nvmem/Makefile  |   2 +
> >   drivers/nvmem/vf610-ocotp.c | 297 
> > 
> >   3 files changed, 309 insertions(+)
> >   create mode 100644 drivers/nvmem/vf610-ocotp.c
> >
> > diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
> > index 0b33014..bfd0c02 100644
> > --- a/drivers/nvmem/Kconfig
> > +++ b/drivers/nvmem/Kconfig
> > @@ -47,4 +47,14 @@ config NVMEM_IMX_OCOTP
> >   This driver can also be built as a module. If so, the module
> >   will be called nvmem-imx-ocotp.
> >
> > +config NVMEM_VF610_OCOTP
> > +   tristate "VF610_SoCs OCOTP support"
> > +   depends on SOC_VF610
> You could also add COMPILE_TEST which will ensure that its compile checked.

Ok.

> > +   help
> > + This is a driver for the 'OCOTP' peripheral available on Vybrid
> > + devices like VF5xx and VF6xx.
> > +
> > + This driver can also be built as a module. If so, the module will
> > + be called nvmem-vf610-ocotp.
> > +
> >   endif
> > diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile
> > index b512d77..8a1eea8 100644
> > --- a/drivers/nvmem/Makefile
> > +++ b/drivers/nvmem/Makefile
> > @@ -12,3 +12,5 @@ obj-$(CONFIG_NVMEM_SUNXI_SID) += nvmem_sunxi_sid.o
> >   nvmem_sunxi_sid-y := sunxi_sid.o
> >   obj-$(CONFIG_NVMEM_IMX_OCOTP) += nvmem-imx-ocotp.o
> >   nvmem-imx-ocotp-y := imx-ocotp.o
> > +obj-$(CONFIG_NVMEM_VF610_OCOTP)+= nvmem-vf610-ocotp.o
> > +nvmem-vf610-ocotp-y:= vf610-ocotp.o
> > diff --git a/drivers/nvmem/vf610-ocotp.c b/drivers/nvmem/vf610-ocotp.c
> > new file mode 100644
> > index 000..25ee701
> > --- /dev/null
> > +++ b/drivers/nvmem/vf610-ocotp.c
> > @@ -0,0 +1,297 @@
> > +/*
> > + * Copyright (C) 2015 Toradex AG.
> > + *
> > + * Author: Sanchayan Maity 
> > + *
> > + * This program is free software; you can redistribute it and/or modify
> > + * it under the terms of the GNU General Public License version 2 and
> > + * only version 2 as published by the Free Software Foundation.
> > + *
> > + * This program is distributed in the hope that 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.
> > + */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +/* OCOTP Register Offsets */
> > +#define OCOTP_CTRL_REG 0x00
> > +#define OCOTP_CTRL_SET 0x04
> > +#define OCOTP_CTRL_CLR 0x08
> > +#define OCOTP_TIMING   0x10
> > +#define OCOTP_DATA 0x20
> > +#define OCOTP_READ_CTRL_REG0x30
> > +#define OCOTP_READ_FUSE_DATA   0x40
> > +
> > +/* OCOTP Register bits and masks */
> > +#define OCOTP_CTRL_WR_UNLOCK   16
> > +#define OCOTP_CTRL_WR_UNLOCK_KEY   0x3E77
> > +#define OCOTP_CTRL_WR_UNLOCK_MASK  0x
> > +#define OCOTP_CTRL_ADDR0
> > +#define OCOTP_CTRL_ADDR_MASK   0x7F
> > +#define OCOTP_CTRL_RELOAD_SHADOWS  (0x1 << 10)
> > +#define OCOTP_CTRL_ERROR   (0x1 << 9)
> > +#define OCOTP_CTRL_BUSY(0x1 << 8)
> 
> we can use BIT and GENMASK variants here for most of the defines.

Ok.

> > +
> > +#define OCOTP_TIMING_STROBE_READ   16
> > +#define OCOTP_TIMING_STROBE_READ_MASK  0x003F
> > +#define OCOTP_TIMING_RELAX 12
> > +#define OCOTP_TIMING_RELAX_MASK0xF000
> > +#define OCOTP_TIMING_STROBE_PROG   0
> > +#define OCOTP_TIMING_STROBE_PROG_MASK  0x0FFF
> > +
> > +#define OCOTP_READ_CTRL_READ_FUSE  0x1
> > +
> > +#define VF610_OCOTP_TIMEOUT10
> > +
> > +#define BF(value, field)   (((value) << field) & field##_MASK)
> > +
> > +#define DEF_RELAX  20
> > +
> > +static const int base_to_fuse_addr_mappings[][2] = {
> > +   {0x400, 0x00},
> > +   {0x410, 0x01},
> > +   {0x420, 0x02},
> > +   {0x450, 0x05},
> > +   {0x4F0, 0x0F},
> > +   {0x600, 0x20},
> > +   {0x610, 0x21},
> > +   {0x620, 0x22},
> > +   {0x630, 0x23},
> > +   {0x640, 0x24},
> > +   

Re: [PATCH v7 3/4] drivers: nvmem: Add Vybrid OCOTP support

2015-08-10 Thread Srinivas Kandagatla

Hi Sanchayan,


Could you add Greg to the "to list" so that we can request him to pick 
this via his tree.



Few nits, other than that driver looks good.


On 06/08/15 16:27, Sanchayan Maity wrote:

The patch adds support for the On Chip One Time Programmable Peripheral
(OCOTP) on the Vybrid platform.

Signed-off-by: Sanchayan Maity 
---
  drivers/nvmem/Kconfig   |  10 ++
  drivers/nvmem/Makefile  |   2 +
  drivers/nvmem/vf610-ocotp.c | 297 
  3 files changed, 309 insertions(+)
  create mode 100644 drivers/nvmem/vf610-ocotp.c

diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
index 0b33014..bfd0c02 100644
--- a/drivers/nvmem/Kconfig
+++ b/drivers/nvmem/Kconfig
@@ -47,4 +47,14 @@ config NVMEM_IMX_OCOTP
  This driver can also be built as a module. If so, the module
  will be called nvmem-imx-ocotp.

+config NVMEM_VF610_OCOTP
+   tristate "VF610_SoCs OCOTP support"
+   depends on SOC_VF610

You could also add COMPILE_TEST which will ensure that its compile checked.

+   help
+ This is a driver for the 'OCOTP' peripheral available on Vybrid
+ devices like VF5xx and VF6xx.
+
+ This driver can also be built as a module. If so, the module will
+ be called nvmem-vf610-ocotp.
+
  endif
diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile
index b512d77..8a1eea8 100644
--- a/drivers/nvmem/Makefile
+++ b/drivers/nvmem/Makefile
@@ -12,3 +12,5 @@ obj-$(CONFIG_NVMEM_SUNXI_SID) += nvmem_sunxi_sid.o
  nvmem_sunxi_sid-y := sunxi_sid.o
  obj-$(CONFIG_NVMEM_IMX_OCOTP) += nvmem-imx-ocotp.o
  nvmem-imx-ocotp-y := imx-ocotp.o
+obj-$(CONFIG_NVMEM_VF610_OCOTP)+= nvmem-vf610-ocotp.o
+nvmem-vf610-ocotp-y:= vf610-ocotp.o
diff --git a/drivers/nvmem/vf610-ocotp.c b/drivers/nvmem/vf610-ocotp.c
new file mode 100644
index 000..25ee701
--- /dev/null
+++ b/drivers/nvmem/vf610-ocotp.c
@@ -0,0 +1,297 @@
+/*
+ * Copyright (C) 2015 Toradex AG.
+ *
+ * Author: Sanchayan Maity 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* OCOTP Register Offsets */
+#define OCOTP_CTRL_REG 0x00
+#define OCOTP_CTRL_SET 0x04
+#define OCOTP_CTRL_CLR 0x08
+#define OCOTP_TIMING   0x10
+#define OCOTP_DATA 0x20
+#define OCOTP_READ_CTRL_REG0x30
+#define OCOTP_READ_FUSE_DATA   0x40
+
+/* OCOTP Register bits and masks */
+#define OCOTP_CTRL_WR_UNLOCK   16
+#define OCOTP_CTRL_WR_UNLOCK_KEY   0x3E77
+#define OCOTP_CTRL_WR_UNLOCK_MASK  0x
+#define OCOTP_CTRL_ADDR0
+#define OCOTP_CTRL_ADDR_MASK   0x7F
+#define OCOTP_CTRL_RELOAD_SHADOWS  (0x1 << 10)
+#define OCOTP_CTRL_ERROR   (0x1 << 9)
+#define OCOTP_CTRL_BUSY(0x1 << 8)


we can use BIT and GENMASK variants here for most of the defines.

+
+#define OCOTP_TIMING_STROBE_READ   16
+#define OCOTP_TIMING_STROBE_READ_MASK  0x003F
+#define OCOTP_TIMING_RELAX 12
+#define OCOTP_TIMING_RELAX_MASK0xF000
+#define OCOTP_TIMING_STROBE_PROG   0
+#define OCOTP_TIMING_STROBE_PROG_MASK  0x0FFF
+
+#define OCOTP_READ_CTRL_READ_FUSE  0x1
+
+#define VF610_OCOTP_TIMEOUT10
+
+#define BF(value, field)   (((value) << field) & field##_MASK)
+
+#define DEF_RELAX  20
+
+static const int base_to_fuse_addr_mappings[][2] = {
+   {0x400, 0x00},
+   {0x410, 0x01},
+   {0x420, 0x02},
+   {0x450, 0x05},
+   {0x4F0, 0x0F},
+   {0x600, 0x20},
+   {0x610, 0x21},
+   {0x620, 0x22},
+   {0x630, 0x23},
+   {0x640, 0x24},
+   {0x650, 0x25},
+   {0x660, 0x26},
+   {0x670, 0x27},
+   {0x6F0, 0x2F},
+   {0x880, 0x38},
+   {0x890, 0x39},
+   {0x8A0, 0x3A},
+   {0x8B0, 0x3B},
+   {0x8C0, 0x3C},
+   {0x8D0, 0x3D},
+   {0x8E0, 0x3E},
+   {0x8F0, 0x3F},
+   {0xC80, 0x78},
+   {0xC90, 0x79},
+   {0xCA0, 0x7A},
+   {0xCB0, 0x7B},
+   {0xCC0, 0x7C},
+   {0xCD0, 0x7D},
+   {0xCE0, 0x7E},
+   {0xCF0, 0x7F},
+};
+
+struct vf610_ocotp {
+   void __iomem *base;
+   

Re: [PATCH v7 3/4] drivers: nvmem: Add Vybrid OCOTP support

2015-08-10 Thread Srinivas Kandagatla

Hi Sanchayan,


Could you add Greg to the to list so that we can request him to pick 
this via his tree.



Few nits, other than that driver looks good.


On 06/08/15 16:27, Sanchayan Maity wrote:

The patch adds support for the On Chip One Time Programmable Peripheral
(OCOTP) on the Vybrid platform.

Signed-off-by: Sanchayan Maity maitysancha...@gmail.com
---
  drivers/nvmem/Kconfig   |  10 ++
  drivers/nvmem/Makefile  |   2 +
  drivers/nvmem/vf610-ocotp.c | 297 
  3 files changed, 309 insertions(+)
  create mode 100644 drivers/nvmem/vf610-ocotp.c

diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
index 0b33014..bfd0c02 100644
--- a/drivers/nvmem/Kconfig
+++ b/drivers/nvmem/Kconfig
@@ -47,4 +47,14 @@ config NVMEM_IMX_OCOTP
  This driver can also be built as a module. If so, the module
  will be called nvmem-imx-ocotp.

+config NVMEM_VF610_OCOTP
+   tristate VF610_SoCs OCOTP support
+   depends on SOC_VF610

You could also add COMPILE_TEST which will ensure that its compile checked.

+   help
+ This is a driver for the 'OCOTP' peripheral available on Vybrid
+ devices like VF5xx and VF6xx.
+
+ This driver can also be built as a module. If so, the module will
+ be called nvmem-vf610-ocotp.
+
  endif
diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile
index b512d77..8a1eea8 100644
--- a/drivers/nvmem/Makefile
+++ b/drivers/nvmem/Makefile
@@ -12,3 +12,5 @@ obj-$(CONFIG_NVMEM_SUNXI_SID) += nvmem_sunxi_sid.o
  nvmem_sunxi_sid-y := sunxi_sid.o
  obj-$(CONFIG_NVMEM_IMX_OCOTP) += nvmem-imx-ocotp.o
  nvmem-imx-ocotp-y := imx-ocotp.o
+obj-$(CONFIG_NVMEM_VF610_OCOTP)+= nvmem-vf610-ocotp.o
+nvmem-vf610-ocotp-y:= vf610-ocotp.o
diff --git a/drivers/nvmem/vf610-ocotp.c b/drivers/nvmem/vf610-ocotp.c
new file mode 100644
index 000..25ee701
--- /dev/null
+++ b/drivers/nvmem/vf610-ocotp.c
@@ -0,0 +1,297 @@
+/*
+ * Copyright (C) 2015 Toradex AG.
+ *
+ * Author: Sanchayan Maity sanchayan.ma...@toradex.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that 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.
+ */
+
+#include linux/clk.h
+#include linux/delay.h
+#include linux/device.h
+#include linux/io.h
+#include linux/module.h
+#include linux/nvmem-provider.h
+#include linux/of.h
+#include linux/platform_device.h
+#include linux/regmap.h
+#include linux/slab.h
+
+/* OCOTP Register Offsets */
+#define OCOTP_CTRL_REG 0x00
+#define OCOTP_CTRL_SET 0x04
+#define OCOTP_CTRL_CLR 0x08
+#define OCOTP_TIMING   0x10
+#define OCOTP_DATA 0x20
+#define OCOTP_READ_CTRL_REG0x30
+#define OCOTP_READ_FUSE_DATA   0x40
+
+/* OCOTP Register bits and masks */
+#define OCOTP_CTRL_WR_UNLOCK   16
+#define OCOTP_CTRL_WR_UNLOCK_KEY   0x3E77
+#define OCOTP_CTRL_WR_UNLOCK_MASK  0x
+#define OCOTP_CTRL_ADDR0
+#define OCOTP_CTRL_ADDR_MASK   0x7F
+#define OCOTP_CTRL_RELOAD_SHADOWS  (0x1  10)
+#define OCOTP_CTRL_ERROR   (0x1  9)
+#define OCOTP_CTRL_BUSY(0x1  8)


we can use BIT and GENMASK variants here for most of the defines.

+
+#define OCOTP_TIMING_STROBE_READ   16
+#define OCOTP_TIMING_STROBE_READ_MASK  0x003F
+#define OCOTP_TIMING_RELAX 12
+#define OCOTP_TIMING_RELAX_MASK0xF000
+#define OCOTP_TIMING_STROBE_PROG   0
+#define OCOTP_TIMING_STROBE_PROG_MASK  0x0FFF
+
+#define OCOTP_READ_CTRL_READ_FUSE  0x1
+
+#define VF610_OCOTP_TIMEOUT10
+
+#define BF(value, field)   (((value)  field)  field##_MASK)
+
+#define DEF_RELAX  20
+
+static const int base_to_fuse_addr_mappings[][2] = {
+   {0x400, 0x00},
+   {0x410, 0x01},
+   {0x420, 0x02},
+   {0x450, 0x05},
+   {0x4F0, 0x0F},
+   {0x600, 0x20},
+   {0x610, 0x21},
+   {0x620, 0x22},
+   {0x630, 0x23},
+   {0x640, 0x24},
+   {0x650, 0x25},
+   {0x660, 0x26},
+   {0x670, 0x27},
+   {0x6F0, 0x2F},
+   {0x880, 0x38},
+   {0x890, 0x39},
+   {0x8A0, 0x3A},
+   {0x8B0, 0x3B},
+   {0x8C0, 0x3C},
+   {0x8D0, 0x3D},
+   {0x8E0, 0x3E},
+   {0x8F0, 0x3F},
+   {0xC80, 0x78},
+   {0xC90, 0x79},
+   {0xCA0, 0x7A},

Re: [PATCH v7 3/4] drivers: nvmem: Add Vybrid OCOTP support

2015-08-10 Thread maitysanchayan
Hello,

On 15-08-10 10:17:53, Srinivas Kandagatla wrote:
 Hi Sanchayan,
 
 
 Could you add Greg to the to list so that we can request him to pick 
 this via his tree.

Will add Greg in cc with the next revision.

 
 
 Few nits, other than that driver looks good.
 
 
 On 06/08/15 16:27, Sanchayan Maity wrote:
  The patch adds support for the On Chip One Time Programmable Peripheral
  (OCOTP) on the Vybrid platform.
 
  Signed-off-by: Sanchayan Maity maitysancha...@gmail.com
  ---
drivers/nvmem/Kconfig   |  10 ++
drivers/nvmem/Makefile  |   2 +
drivers/nvmem/vf610-ocotp.c | 297 
  
3 files changed, 309 insertions(+)
create mode 100644 drivers/nvmem/vf610-ocotp.c
 
  diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
  index 0b33014..bfd0c02 100644
  --- a/drivers/nvmem/Kconfig
  +++ b/drivers/nvmem/Kconfig
  @@ -47,4 +47,14 @@ config NVMEM_IMX_OCOTP
This driver can also be built as a module. If so, the module
will be called nvmem-imx-ocotp.
 
  +config NVMEM_VF610_OCOTP
  +   tristate VF610_SoCs OCOTP support
  +   depends on SOC_VF610
 You could also add COMPILE_TEST which will ensure that its compile checked.

Ok.

  +   help
  + This is a driver for the 'OCOTP' peripheral available on Vybrid
  + devices like VF5xx and VF6xx.
  +
  + This driver can also be built as a module. If so, the module will
  + be called nvmem-vf610-ocotp.
  +
endif
  diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile
  index b512d77..8a1eea8 100644
  --- a/drivers/nvmem/Makefile
  +++ b/drivers/nvmem/Makefile
  @@ -12,3 +12,5 @@ obj-$(CONFIG_NVMEM_SUNXI_SID) += nvmem_sunxi_sid.o
nvmem_sunxi_sid-y := sunxi_sid.o
obj-$(CONFIG_NVMEM_IMX_OCOTP) += nvmem-imx-ocotp.o
nvmem-imx-ocotp-y := imx-ocotp.o
  +obj-$(CONFIG_NVMEM_VF610_OCOTP)+= nvmem-vf610-ocotp.o
  +nvmem-vf610-ocotp-y:= vf610-ocotp.o
  diff --git a/drivers/nvmem/vf610-ocotp.c b/drivers/nvmem/vf610-ocotp.c
  new file mode 100644
  index 000..25ee701
  --- /dev/null
  +++ b/drivers/nvmem/vf610-ocotp.c
  @@ -0,0 +1,297 @@
  +/*
  + * Copyright (C) 2015 Toradex AG.
  + *
  + * Author: Sanchayan Maity sanchayan.ma...@toradex.com
  + *
  + * This program is free software; you can redistribute it and/or modify
  + * it under the terms of the GNU General Public License version 2 and
  + * only version 2 as published by the Free Software Foundation.
  + *
  + * This program is distributed in the hope that 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.
  + */
  +
  +#include linux/clk.h
  +#include linux/delay.h
  +#include linux/device.h
  +#include linux/io.h
  +#include linux/module.h
  +#include linux/nvmem-provider.h
  +#include linux/of.h
  +#include linux/platform_device.h
  +#include linux/regmap.h
  +#include linux/slab.h
  +
  +/* OCOTP Register Offsets */
  +#define OCOTP_CTRL_REG 0x00
  +#define OCOTP_CTRL_SET 0x04
  +#define OCOTP_CTRL_CLR 0x08
  +#define OCOTP_TIMING   0x10
  +#define OCOTP_DATA 0x20
  +#define OCOTP_READ_CTRL_REG0x30
  +#define OCOTP_READ_FUSE_DATA   0x40
  +
  +/* OCOTP Register bits and masks */
  +#define OCOTP_CTRL_WR_UNLOCK   16
  +#define OCOTP_CTRL_WR_UNLOCK_KEY   0x3E77
  +#define OCOTP_CTRL_WR_UNLOCK_MASK  0x
  +#define OCOTP_CTRL_ADDR0
  +#define OCOTP_CTRL_ADDR_MASK   0x7F
  +#define OCOTP_CTRL_RELOAD_SHADOWS  (0x1  10)
  +#define OCOTP_CTRL_ERROR   (0x1  9)
  +#define OCOTP_CTRL_BUSY(0x1  8)
 
 we can use BIT and GENMASK variants here for most of the defines.

Ok.

  +
  +#define OCOTP_TIMING_STROBE_READ   16
  +#define OCOTP_TIMING_STROBE_READ_MASK  0x003F
  +#define OCOTP_TIMING_RELAX 12
  +#define OCOTP_TIMING_RELAX_MASK0xF000
  +#define OCOTP_TIMING_STROBE_PROG   0
  +#define OCOTP_TIMING_STROBE_PROG_MASK  0x0FFF
  +
  +#define OCOTP_READ_CTRL_READ_FUSE  0x1
  +
  +#define VF610_OCOTP_TIMEOUT10
  +
  +#define BF(value, field)   (((value)  field)  field##_MASK)
  +
  +#define DEF_RELAX  20
  +
  +static const int base_to_fuse_addr_mappings[][2] = {
  +   {0x400, 0x00},
  +   {0x410, 0x01},
  +   {0x420, 0x02},
  +   {0x450, 0x05},
  +   {0x4F0, 0x0F},
  +   {0x600, 0x20},
  +   {0x610, 0x21},
  +   {0x620, 0x22},
  +   {0x630, 0x23},
  +   {0x640, 0x24},
  +   {0x650, 0x25},
  +   {0x660, 0x26},
  +   {0x670, 0x27},
  +   {0x6F0, 

[PATCH v7 3/4] drivers: nvmem: Add Vybrid OCOTP support

2015-08-06 Thread Sanchayan Maity
The patch adds support for the On Chip One Time Programmable Peripheral
(OCOTP) on the Vybrid platform.

Signed-off-by: Sanchayan Maity 
---
 drivers/nvmem/Kconfig   |  10 ++
 drivers/nvmem/Makefile  |   2 +
 drivers/nvmem/vf610-ocotp.c | 297 
 3 files changed, 309 insertions(+)
 create mode 100644 drivers/nvmem/vf610-ocotp.c

diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
index 0b33014..bfd0c02 100644
--- a/drivers/nvmem/Kconfig
+++ b/drivers/nvmem/Kconfig
@@ -47,4 +47,14 @@ config NVMEM_IMX_OCOTP
  This driver can also be built as a module. If so, the module
  will be called nvmem-imx-ocotp.
 
+config NVMEM_VF610_OCOTP
+   tristate "VF610_SoCs OCOTP support"
+   depends on SOC_VF610
+   help
+ This is a driver for the 'OCOTP' peripheral available on Vybrid
+ devices like VF5xx and VF6xx.
+
+ This driver can also be built as a module. If so, the module will
+ be called nvmem-vf610-ocotp.
+
 endif
diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile
index b512d77..8a1eea8 100644
--- a/drivers/nvmem/Makefile
+++ b/drivers/nvmem/Makefile
@@ -12,3 +12,5 @@ obj-$(CONFIG_NVMEM_SUNXI_SID) += nvmem_sunxi_sid.o
 nvmem_sunxi_sid-y  := sunxi_sid.o
 obj-$(CONFIG_NVMEM_IMX_OCOTP)  += nvmem-imx-ocotp.o
 nvmem-imx-ocotp-y  := imx-ocotp.o
+obj-$(CONFIG_NVMEM_VF610_OCOTP)+= nvmem-vf610-ocotp.o
+nvmem-vf610-ocotp-y:= vf610-ocotp.o
diff --git a/drivers/nvmem/vf610-ocotp.c b/drivers/nvmem/vf610-ocotp.c
new file mode 100644
index 000..25ee701
--- /dev/null
+++ b/drivers/nvmem/vf610-ocotp.c
@@ -0,0 +1,297 @@
+/*
+ * Copyright (C) 2015 Toradex AG.
+ *
+ * Author: Sanchayan Maity 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* OCOTP Register Offsets */
+#define OCOTP_CTRL_REG 0x00
+#define OCOTP_CTRL_SET 0x04
+#define OCOTP_CTRL_CLR 0x08
+#define OCOTP_TIMING   0x10
+#define OCOTP_DATA 0x20
+#define OCOTP_READ_CTRL_REG0x30
+#define OCOTP_READ_FUSE_DATA   0x40
+
+/* OCOTP Register bits and masks */
+#define OCOTP_CTRL_WR_UNLOCK   16
+#define OCOTP_CTRL_WR_UNLOCK_KEY   0x3E77
+#define OCOTP_CTRL_WR_UNLOCK_MASK  0x
+#define OCOTP_CTRL_ADDR0
+#define OCOTP_CTRL_ADDR_MASK   0x7F
+#define OCOTP_CTRL_RELOAD_SHADOWS  (0x1 << 10)
+#define OCOTP_CTRL_ERROR   (0x1 << 9)
+#define OCOTP_CTRL_BUSY(0x1 << 8)
+
+#define OCOTP_TIMING_STROBE_READ   16
+#define OCOTP_TIMING_STROBE_READ_MASK  0x003F
+#define OCOTP_TIMING_RELAX 12
+#define OCOTP_TIMING_RELAX_MASK0xF000
+#define OCOTP_TIMING_STROBE_PROG   0
+#define OCOTP_TIMING_STROBE_PROG_MASK  0x0FFF
+
+#define OCOTP_READ_CTRL_READ_FUSE  0x1
+
+#define VF610_OCOTP_TIMEOUT10
+
+#define BF(value, field)   (((value) << field) & field##_MASK)
+
+#define DEF_RELAX  20
+
+static const int base_to_fuse_addr_mappings[][2] = {
+   {0x400, 0x00},
+   {0x410, 0x01},
+   {0x420, 0x02},
+   {0x450, 0x05},
+   {0x4F0, 0x0F},
+   {0x600, 0x20},
+   {0x610, 0x21},
+   {0x620, 0x22},
+   {0x630, 0x23},
+   {0x640, 0x24},
+   {0x650, 0x25},
+   {0x660, 0x26},
+   {0x670, 0x27},
+   {0x6F0, 0x2F},
+   {0x880, 0x38},
+   {0x890, 0x39},
+   {0x8A0, 0x3A},
+   {0x8B0, 0x3B},
+   {0x8C0, 0x3C},
+   {0x8D0, 0x3D},
+   {0x8E0, 0x3E},
+   {0x8F0, 0x3F},
+   {0xC80, 0x78},
+   {0xC90, 0x79},
+   {0xCA0, 0x7A},
+   {0xCB0, 0x7B},
+   {0xCC0, 0x7C},
+   {0xCD0, 0x7D},
+   {0xCE0, 0x7E},
+   {0xCF0, 0x7F},
+};
+
+struct vf610_ocotp {
+   void __iomem *base;
+   struct clk *clk;
+   struct device *dev;
+   struct nvmem_device *nvmem;
+   int timing;
+};
+
+static int vf610_ocotp_wait_busy(void __iomem *base)
+{
+   int timeout = VF610_OCOTP_TIMEOUT;
+
+   while ((readl(base) & OCOTP_CTRL_BUSY) && --timeout)
+   udelay(10);
+
+   if (!timeout) {
+   

[PATCH v7 3/4] drivers: nvmem: Add Vybrid OCOTP support

2015-08-06 Thread Sanchayan Maity
The patch adds support for the On Chip One Time Programmable Peripheral
(OCOTP) on the Vybrid platform.

Signed-off-by: Sanchayan Maity maitysancha...@gmail.com
---
 drivers/nvmem/Kconfig   |  10 ++
 drivers/nvmem/Makefile  |   2 +
 drivers/nvmem/vf610-ocotp.c | 297 
 3 files changed, 309 insertions(+)
 create mode 100644 drivers/nvmem/vf610-ocotp.c

diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
index 0b33014..bfd0c02 100644
--- a/drivers/nvmem/Kconfig
+++ b/drivers/nvmem/Kconfig
@@ -47,4 +47,14 @@ config NVMEM_IMX_OCOTP
  This driver can also be built as a module. If so, the module
  will be called nvmem-imx-ocotp.
 
+config NVMEM_VF610_OCOTP
+   tristate VF610_SoCs OCOTP support
+   depends on SOC_VF610
+   help
+ This is a driver for the 'OCOTP' peripheral available on Vybrid
+ devices like VF5xx and VF6xx.
+
+ This driver can also be built as a module. If so, the module will
+ be called nvmem-vf610-ocotp.
+
 endif
diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile
index b512d77..8a1eea8 100644
--- a/drivers/nvmem/Makefile
+++ b/drivers/nvmem/Makefile
@@ -12,3 +12,5 @@ obj-$(CONFIG_NVMEM_SUNXI_SID) += nvmem_sunxi_sid.o
 nvmem_sunxi_sid-y  := sunxi_sid.o
 obj-$(CONFIG_NVMEM_IMX_OCOTP)  += nvmem-imx-ocotp.o
 nvmem-imx-ocotp-y  := imx-ocotp.o
+obj-$(CONFIG_NVMEM_VF610_OCOTP)+= nvmem-vf610-ocotp.o
+nvmem-vf610-ocotp-y:= vf610-ocotp.o
diff --git a/drivers/nvmem/vf610-ocotp.c b/drivers/nvmem/vf610-ocotp.c
new file mode 100644
index 000..25ee701
--- /dev/null
+++ b/drivers/nvmem/vf610-ocotp.c
@@ -0,0 +1,297 @@
+/*
+ * Copyright (C) 2015 Toradex AG.
+ *
+ * Author: Sanchayan Maity sanchayan.ma...@toradex.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that 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.
+ */
+
+#include linux/clk.h
+#include linux/delay.h
+#include linux/device.h
+#include linux/io.h
+#include linux/module.h
+#include linux/nvmem-provider.h
+#include linux/of.h
+#include linux/platform_device.h
+#include linux/regmap.h
+#include linux/slab.h
+
+/* OCOTP Register Offsets */
+#define OCOTP_CTRL_REG 0x00
+#define OCOTP_CTRL_SET 0x04
+#define OCOTP_CTRL_CLR 0x08
+#define OCOTP_TIMING   0x10
+#define OCOTP_DATA 0x20
+#define OCOTP_READ_CTRL_REG0x30
+#define OCOTP_READ_FUSE_DATA   0x40
+
+/* OCOTP Register bits and masks */
+#define OCOTP_CTRL_WR_UNLOCK   16
+#define OCOTP_CTRL_WR_UNLOCK_KEY   0x3E77
+#define OCOTP_CTRL_WR_UNLOCK_MASK  0x
+#define OCOTP_CTRL_ADDR0
+#define OCOTP_CTRL_ADDR_MASK   0x7F
+#define OCOTP_CTRL_RELOAD_SHADOWS  (0x1  10)
+#define OCOTP_CTRL_ERROR   (0x1  9)
+#define OCOTP_CTRL_BUSY(0x1  8)
+
+#define OCOTP_TIMING_STROBE_READ   16
+#define OCOTP_TIMING_STROBE_READ_MASK  0x003F
+#define OCOTP_TIMING_RELAX 12
+#define OCOTP_TIMING_RELAX_MASK0xF000
+#define OCOTP_TIMING_STROBE_PROG   0
+#define OCOTP_TIMING_STROBE_PROG_MASK  0x0FFF
+
+#define OCOTP_READ_CTRL_READ_FUSE  0x1
+
+#define VF610_OCOTP_TIMEOUT10
+
+#define BF(value, field)   (((value)  field)  field##_MASK)
+
+#define DEF_RELAX  20
+
+static const int base_to_fuse_addr_mappings[][2] = {
+   {0x400, 0x00},
+   {0x410, 0x01},
+   {0x420, 0x02},
+   {0x450, 0x05},
+   {0x4F0, 0x0F},
+   {0x600, 0x20},
+   {0x610, 0x21},
+   {0x620, 0x22},
+   {0x630, 0x23},
+   {0x640, 0x24},
+   {0x650, 0x25},
+   {0x660, 0x26},
+   {0x670, 0x27},
+   {0x6F0, 0x2F},
+   {0x880, 0x38},
+   {0x890, 0x39},
+   {0x8A0, 0x3A},
+   {0x8B0, 0x3B},
+   {0x8C0, 0x3C},
+   {0x8D0, 0x3D},
+   {0x8E0, 0x3E},
+   {0x8F0, 0x3F},
+   {0xC80, 0x78},
+   {0xC90, 0x79},
+   {0xCA0, 0x7A},
+   {0xCB0, 0x7B},
+   {0xCC0, 0x7C},
+   {0xCD0, 0x7D},
+   {0xCE0, 0x7E},
+   {0xCF0, 0x7F},
+};
+
+struct vf610_ocotp {
+   void __iomem *base;
+   struct clk *clk;
+   struct device *dev;
+   struct nvmem_device *nvmem;
+   int timing;
+};
+
+static int vf610_ocotp_wait_busy(void __iomem *base)
+{
+