Skip to contentSkip to conversation

Support for OTP memory

RFC PATCH Superseded Jamie Iles 2 participants 16 messages Mar 25, 2011 – Mar 26, 2011 Char and misc drivers

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Jamie Iles

author
#0 lore raw

v3 cover Support for OTP memory

Hi,

I've updated this series following some great feedback from Greg and Mike, and aside from the code quality improvements, the main changes since v2 are:

- The OTP regions don't live directly in /sys/bus/otp/devices anymore but just as a child device of the OTP device.
- CONFIG_OTP_WRITE_ENABLE has been created that replaces the bfin-otp specific option and this disables all OTP writing at the higher levels. The PC3X3 OTP driver has also been converted to use this.
- Multiple OTP devices can now be registered at the same time.
- The bfin-otp driver has been converted to a platform_driver and the relevant Blackfin platforms have had a bfin-otp device added.
- The Blackfin OTP is now represented as a single region that does not include the ECC or control bits. This prevents users from accidentally scribbling over those bits.

Greg, Mike, thanks again for taking the time to review, it's much appreciated.

Thanks,

Jamie Iles (4):
drivers/otp: add initial support for OTP memory drivers/otp: add support for Picoxcell PC3X3 OTP drivers/otp: convert bfin otp to generic OTP
Blackfin: add the OTP device as a platform device

 Documentation/ABI/testing/sysfs-bus-otp      |   93 +++
 arch/blackfin/mach-bf518/boards/ezbrd.c      |   10 +
 arch/blackfin/mach-bf518/boards/tcm-bf518.c  |   10 +
 arch/blackfin/mach-bf527/boards/ad7160eval.c |   10 +
 arch/blackfin/mach-bf527/boards/cm_bf527.c   |   10 +
 arch/blackfin/mach-bf527/boards/ezbrd.c      |   10 +
 arch/blackfin/mach-bf527/boards/ezkit.c      |   10 +
 arch/blackfin/mach-bf527/boards/tll6527m.c   |   10 +
 arch/blackfin/mach-bf548/boards/cm_bf548.c   |    9 +
 arch/blackfin/mach-bf548/boards/ezkit.c      |   10 +
 drivers/Kconfig                              |    2 +
 drivers/Makefile                             |    1 +
 drivers/char/Kconfig                         |   28 -
 drivers/char/Makefile                        |    1 -
 drivers/otp/Kconfig                          |   51 ++
 drivers/otp/Makefile                         |    3 +
 drivers/{char => otp}/bfin-otp.c             |  275 ++++---
 drivers/otp/otp.c                            |  913 +++++++++++++++++++++
 drivers/otp/otp_pc3x3.c                      | 1099 ++++++++++++++++++++++++++
 include/linux/otp.h                          |  277 +++++++
 20 files changed, 2677 insertions(+), 155 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-otp
 create mode 100644 drivers/otp/Kconfig
 create mode 100644 drivers/otp/Makefile
 rename drivers/{char => otp}/bfin-otp.c (40%)
 create mode 100644 drivers/otp/otp.c
 create mode 100644 drivers/otp/otp_pc3x3.c
 create mode 100644 include/linux/otp.h
Signature · 1 line
1.7.4
author
#1 lore raw

RFC PATCH v3 1/4 drivers/otp: add initial support for OTP memory

OTP memory is typically found in some embedded devices and can be used for storing boot code, cryptographic keys and other persistent information onchip. This patch adds a generic layer that devices can register OTP with and allows access through a set of character device nodes.

Changes since v3:
- Updated ABI documentation.
- Don't put the OTP regions directly in /sys/bus/otp/devices.
- Squash the ioctl addition patch into this one.
- Add CONFIG_OTP_WRITE_ENABLE to allow OTP support to be build without allowing write accesses to OTP.
- Add the "ecc" redundancy format.
- Permit registration of multiple OTP devices.

---
 Documentation/ABI/testing/sysfs-bus-otp |   93 ++++
 drivers/Kconfig                         |    2 +
 drivers/Makefile                        |    1 +
 drivers/otp/Kconfig                     |   28 +
 drivers/otp/Makefile                    |    1 +
 drivers/otp/otp.c                       |  913 +++++++++++++++++++++++++++++++
 include/linux/otp.h                     |  277 ++++++++++
 7 files changed, 1315 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-otp
 create mode 100644 drivers/otp/Kconfig
 create mode 100644 drivers/otp/Makefile
 create mode 100644 drivers/otp/otp.c
 create mode 100644 include/linux/otp.h
Documentation/ABI/testing/sysfs-bus-otp new file +93 -0
new file mode 100644
index 0000000..fb98efa
@@ -0,0 +1,93 @@
+What:           /sys/bus/otp/
+Date:           March 2011
+KernelVersion:  2.6.40+
+Contact:        Jamie Iles <[email protected]>
+Description:
+		The otp bus presents a number of devices where each
+		device represents and OTP device in the system.  An OTP device
+		may have a number of regions (which can be thought of as
+		partitions) and the regions are child devices.  Each region
+		will create a device node which allows the region to be
+		written with read()/write() calls and the device on the bus
+		has attributes for controlling the redundancy format and
+		getting the region size.
+
+What:		/sys/bus/devices/otp#/
+Date:		March 2011
+KernelVersion:	2.6.40+
+Contact:	Jamie Iles <[email protected]>
+Description:
+		Each otp# directory represents an OTP device in the system.
+		The device has attributes that affect all of the regions in
+		the device such as write_enable and the number of regions.
+
+What:		/sys/bus/devices/otp#/otp#N
+Date:		March 2011
+KernelVersion:	2.6.40+
+Contact:	Jamie Iles <[email protected]>
+Description:
+		Each otp#N directory represents a region in the otp# device.
+		A region may be read from/written to through the character
+		device node named after the otp#N name.
+
+What:		/sys/bus/devices/otp#/write_enable
+Date:		March 2011
+KernelVersion:	2.6.40+
+Contact:	Jamie Iles <[email protected]>
+Description:
+		This file controls whether the OTP device can be written to.
+		If set to "enabled" then the regions may be written, the
+		number of regions may be changed and the format of any region
+		may be changed.
+
+What:		/sys/bus/devices/otp#/num_regions
+Date:		March 2011
+KernelVersion:	2.6.40+
+Contact:	Jamie Iles <[email protected]>
+Description:
+		This file controls the number of regions in the OTP device.
+		Valid values are 1, 2, 4 and 8. The number of regions may be
+		increased but never decreased. Increasing the number of
+		regions will create new devices on the otp bus.
+
+What:		/sys/bus/devices/otp#/strict_programming
+Date:		March 2011
+KernelVersion:	2.6.40+
+Contact:	Jamie Iles <[email protected]>
+Description:
+		This file indicates whether all words in a redundant format
+		must be programmed correctly to indicate success.  For
+		example, using the "redundant format", the same word is
+		written to two locations and wire-OR'd when reading back.
+		Disabling this will mean that programming will be considered a
+		success if the word can be read back correctly in its
+		redundant format even if there are bit errors when programming
+		the extra redundancy words.
+
+What:           /sys/bus/otp/devices/otp#/otp#N/format
+Date:           March 2011
+KernelVersion:  2.6.40+
+Contact:        Jamie Iles <[email protected]>
+Description:
+                The redundancy format of the region. Valid values are:
+			- single-ended (1 bit of storage per data bit).
+			- redundant (2 bits of storage, wire-OR'd per data
+			  bit).
+			- differential (2 bits of storage, differential
+			  voltage per data bit).
+			- differential-redundant (4 bits of storage, combining
+			  redundant and differential).
+			- ecc (transparent to the user)
+		Depending on the device type, it may be possible to increase
+		redundancy of a region but care will be needed if there is
+		data already in the region.
+
+What:           /sys/bus/otp/devices/otp#/otp#N/size
+Date:           March 2011
+KernelVersion:  2.6.40+
+Contact:        Jamie Iles <[email protected]>
+Description:
+                The effective storage size of the region. This is the amount
+		of data that a user can store in the region taking into
+		account the number of regions and the redundancy format of the
+		region itself.
drivers/Kconfig +2 -0
index 177c7d1..77da156 100644
@@ -119,4 +119,6 @@ source "drivers/platform/Kconfig"
 source "drivers/clk/Kconfig"
 
 source "drivers/hwspinlock/Kconfig"
+
+source "drivers/otp/Kconfig"
 endmenu
drivers/Makefile +1 -0
index 3f135b6..6ae2f815 100644
@@ -119,3 +119,4 @@ obj-y				+= ieee802154/
 obj-y				+= clk/
 
 obj-$(CONFIG_HWSPINLOCK)	+= hwspinlock/
+obj-$(CONFIG_OTP)		+= otp/
drivers/otp/Kconfig new file +28 -0
new file mode 100644
index 0000000..9a529c6
@@ -0,0 +1,28 @@
+#
+# OTP memory configuration
+#
+
+menuconfig OTP
+	bool "OTP memory support"
+	help
+	  Say Y here to support OTP memory.  This memory can commonly be used
+	  to store boot code, cryptographic keys and other persistent data.
+	  This memory is typically a few KBytes in size and different devices
+	  may have different characterstics.  This provides a character device
+	  interface to these devices to allow the OTP to be programmed and
+	  read.
+
+if OTP
+
+config WRITE_ENABLE
+	bool "Enable writing support of OTP pages"
+	default n
+	help
+	  If you say Y here, you will enable support for writing of the
+	  OTP pages.  This is dangerous by nature as you can only program
+	  the pages once, so only enable this option when you actually
+	  need it so as to not inadvertently clobber data.
+
+	  If unsure, say N.
+
+endif
drivers/otp/Makefile new file +1 -0
new file mode 100644
index 0000000..84fd03e
@@ -0,0 +1 @@
+obj-$(CONFIG_OTP)	+= otp.o
drivers/otp/otp.c new file +913 -0

913 lines not on this page · raw message

include/linux/otp.h new file +277 -0

277 lines not on this page · raw message

Signature · 1 line
1.7.4
#2 lore raw

Re: [RFC PATCHv3 1/4] drivers/otp: add initial support for OTP memory

drivers/otp/Kconfig line 11

Quoted 3 lines · Jamie Iles
drivers/otp/Kconfig new file +1 -0
+         may have different characterstics.  This provides a character device

characterstics -> characteristics

drivers/otp/Kconfig line 20

Quoted 6 lines
drivers/otp/Kconfig new file +6 -0
+if OTP
+
+config WRITE_ENABLE
+       bool "Enable writing support of OTP pages"
+       default n
+       help

does this show correctly in the kconfig by putting this under "if otp" instead of "depends otp" ? it should show the write option indented rather than at the same level.

drivers/otp/Kconfig

Quoted 2 lines
drivers/otp/Kconfig new file +2 -0
+/* We'll allow OTP devices to be named otpa-otpz. */
+#define MAX_OTP_DEVICES                26

mmm is that still true ?

drivers/otp/Kconfig

Quoted 2 lines
drivers/otp/Kconfig new file +2 -0
+static unsigned long registered_otp_map[BITS_TO_LONGS(MAX_OTP_DEVICES)];
+static DEFINE_MUTEX(otp_register_mutex);

do we really need this ? if we let the minor number dictate availability, then we can increment until that errors/wraps, and we dont need to do any tracking ...

drivers/otp/Kconfig

Quoted 12 lines
drivers/otp/Kconfig new file +12 -0
+       if (fmt == OTP_REDUNDANCY_FMT_SINGLE_ENDED)
+               fmt_string = "single-ended";
+       else if (fmt == OTP_REDUNDANCY_FMT_REDUNDANT)
+               fmt_string = "redundant";
+       else if (fmt == OTP_REDUNDANCY_FMT_DIFFERENTIAL)
+               fmt_string = "differential";
+       else if (fmt == OTP_REDUNDANCY_FMT_DIFFERENTIAL_REDUNDANT)
+               fmt_string = "differential-redundant";
+       else if (fmt == OTP_REDUNDANCY_FMT_ECC)
+               fmt_string = "ecc";
+       else
+               return -EINVAL;

i wonder if the code would be simpler if we had a local static array. then the show/store funcs would simply walk that tree, and when you add a new format in the future, you only have to update one place.

static const char * const otp_redundancy_str[] = {
[OTP_REDUNDANCY_FMT_SINGLE_ENDED] = "single-ended", [OTP_REDUNDANCY_FMT_REDUNDANT] = "redundant",
........
};

drivers/otp/Kconfig

Quoted 9 lines
drivers/otp/Kconfig new file +9 -0
+static ssize_t otp_num_regions_show(struct device *dev,
+                                   struct device_attribute *attr, char *buf)
+{
+       int nr_regions;
+
+       nr_regions = otp_dev->ops->get_nr_regions(otp_dev);
+
+       if (nr_regions < 0)
+               return (ssize_t)nr_regions;

we could make get_nr_regions() return a ssize_t ...

Quoted 1 line

+ err = alloc_chrdev_region(&otp_dev->devno, 0, max_regions, "otp");

hmm, i was thinking that we'd have 1 major for otp devices. isnt this how MTD does it ?

include/linux/otp.h line 79

Quoted 13 lines
include/linux/otp.h new file +11 -0
+/**
+ * enum otp_device_flags - Flags to indicate capabilities for the OTP device.
+ *
+ * @OTP_DEVICE_FNO_SUBWORD_WRITE:      only full word sized writes may be
+ *                                     performed.  Don't use
+ *                                     read-modify-write cycles for
+ *                                     performing unaligned writes.
+ */
+enum otp_device_flags {
+       OTP_DEVICE_FNO_SUBWORD_WRITE    = (1 << 0),
+};

use OTP_CAPS_xxx instead ?
-mike

author
#3 lore raw

Re: [RFC PATCHv3 1/4] drivers/otp: add initial support for OTP memory

Hi Mike,

Quoted 6 lines · Mike Frysinger

drivers/otp/Kconfig line 11

Quoted 3 lines · Jamie Iles
drivers/otp/Kconfig new file +1 -0
+         may have different characterstics.  This provides a character device

characterstics -> characteristics

Doh!

Quoted 10 lines

drivers/otp/Kconfig line 20

Quoted 6 lines
drivers/otp/Kconfig new file +6 -0
+if OTP
+
+config WRITE_ENABLE
+       bool "Enable writing support of OTP pages"
+       default n
+       help

does this show correctly in the kconfig by putting this under "if otp" instead of "depends otp" ? it should show the write option indented rather than at the same level.

I think it's OK because it's a menuconfig thing so the toplevel OTP thing is at the same level as misc devices and staging drivers etc.

Quoted 4 lines

drivers/otp/Kconfig

Quoted 2 lines
drivers/otp/Kconfig new file +2 -0
+/* We'll allow OTP devices to be named otpa-otpz. */
+#define MAX_OTP_DEVICES                26

mmm is that still true ?

I think so - the actual devices should be otpa-otpz, but when you register regions they could be otpa1, otpa2, otpb1, otpb2 etc.

Quoted 7 lines

drivers/otp/Kconfig

Quoted 3 lines
drivers/otp/Kconfig new file +2 -0
+static unsigned long registered_otp_map[BITS_TO_LONGS(MAX_OTP_DEVICES)];
+static DEFINE_MUTEX(otp_register_mutex);

do we really need this ? if we let the minor number dictate availability, then we can increment until that errors/wraps, and we dont need to do any tracking ...

OK, so it would be nice to get rid of this but afaict we still need to do some accounting of available minor numbers in the range that we've allocated. We could do a simple increment % 255 for the minor number but if OTP devices are removed at runtime then that may get fragmented and we would need to do retries of device_register() which feels a bit too easy to mess up.

Certainly allocating one major number for OTP devices then allocating the minors one by one would be much better than what I have now.

We probably also want it so that if you remove the OTP device that has had regions called otpaN then reinsert it they doesn't suddenly become otpbN.

Quoted 18 lines

drivers/otp/Kconfig

Quoted 13 lines
drivers/otp/Kconfig new file +12 -0
+       if (fmt == OTP_REDUNDANCY_FMT_SINGLE_ENDED)
+               fmt_string = "single-ended";
+       else if (fmt == OTP_REDUNDANCY_FMT_REDUNDANT)
+               fmt_string = "redundant";
+       else if (fmt == OTP_REDUNDANCY_FMT_DIFFERENTIAL)
+               fmt_string = "differential";
+       else if (fmt == OTP_REDUNDANCY_FMT_DIFFERENTIAL_REDUNDANT)
+               fmt_string = "differential-redundant";
+       else if (fmt == OTP_REDUNDANCY_FMT_ECC)
+               fmt_string = "ecc";
+       else
+               return -EINVAL;

i wonder if the code would be simpler if we had a local static array. then the show/store funcs would simply walk that tree, and when you add a new format in the future, you only have to update one place.

Quoted 5 lines

static const char * const otp_redundancy_str[] = {
[OTP_REDUNDANCY_FMT_SINGLE_ENDED] = "single-ended", [OTP_REDUNDANCY_FMT_REDUNDANT] = "redundant",
........
};

Yes, that would be a lot cleaner.

Quoted 11 lines

drivers/otp/Kconfig

Quoted 9 lines
drivers/otp/Kconfig new file +9 -0
+static ssize_t otp_num_regions_show(struct device *dev,
+                                   struct device_attribute *attr, char *buf)
+{
+       int nr_regions;
+
+       nr_regions = otp_dev->ops->get_nr_regions(otp_dev);
+
+       if (nr_regions < 0)
+               return (ssize_t)nr_regions;

we could make get_nr_regions() return a ssize_t ...

OK, will do.

Quoted 6 lines
Quoted 2 lines

+ err = alloc_chrdev_region(&otp_dev->devno, 0, max_regions, "otp");

hmm, i was thinking that we'd have 1 major for otp devices. isnt this how MTD does it ?

Quoted 15 lines

include/linux/otp.h line 79

Quoted 13 lines
include/linux/otp.h new file +11 -0
+/**
+ * enum otp_device_flags - Flags to indicate capabilities for the OTP device.
+ *
+ * @OTP_DEVICE_FNO_SUBWORD_WRITE:      only full word sized writes may be
+ *                                     performed.  Don't use
+ *                                     read-modify-write cycles for
+ *                                     performing unaligned writes.
+ */
+enum otp_device_flags {
+       OTP_DEVICE_FNO_SUBWORD_WRITE    = (1 << 0),
+};

use OTP_CAPS_xxx instead ?

Sounds like a plan! Thanks again for the review!

Jamie

#4 lore raw

Re: [RFC PATCHv3 1/4] drivers/otp: add initial support for OTP memory

Quoted 25 lines · Jamie Iles
Quoted 5 lines · Mike Frysinger

drivers/otp/otp.c line 26

Quoted 2 lines · Jamie Iles
drivers/otp/otp.c new file +2 -0
+/* We'll allow OTP devices to be named otpa-otpz. */
+#define MAX_OTP_DEVICES                26

mmm is that still true ?

I think so - the actual devices should be otpa-otpz, but when you register regions they could be otpa1, otpa2, otpb1, otpb2 etc.

Quoted 7 lines

drivers/otp/otp.c line 29

Quoted 3 lines
drivers/otp/otp.c new file +2 -0
+static unsigned long registered_otp_map[BITS_TO_LONGS(MAX_OTP_DEVICES)];
+static DEFINE_MUTEX(otp_register_mutex);

do we really need this ?  if we let the minor number dictate availability, then we can increment until that errors/wraps, and we dont need to do any tracking ...

OK, so it would be nice to get rid of this but afaict we still need to do some accounting of available minor numbers in the range that we've allocated.  We could do a simple increment % 255 for the minor number but if OTP devices are removed at runtime then that may get fragmented and we would need to do retries of device_register() which feels a bit too easy to mess up.

Quoted 6 lines

Certainly allocating one major number for OTP devices then allocating the minors one by one would be much better than what I have now.

We probably also want it so that if you remove the OTP device that has had regions called otpaN then reinsert it they doesn't suddenly become otpbN.

yeah that's true. guess i'll leave it be then ;).

whatever naming is picked in /dev/ should match the stuff in /sys/ btw ... -mike

author
#5 lore raw

Re: [RFC PATCHv3 1/4] drivers/otp: add initial support for OTP memory

Quoted 26 lines · Mike Frysinger
Quoted 25 lines · Jamie Iles
Quoted 5 lines · Mike Frysinger

drivers/otp/otp.c line 26

Quoted 2 lines · Jamie Iles
drivers/otp/otp.c new file +2 -0
+/* We'll allow OTP devices to be named otpa-otpz. */
+#define MAX_OTP_DEVICES                26

mmm is that still true ?

I think so - the actual devices should be otpa-otpz, but when you register regions they could be otpa1, otpa2, otpb1, otpb2 etc.

Quoted 7 lines

drivers/otp/otp.c line 29

Quoted 3 lines
drivers/otp/otp.c new file +2 -0
+static unsigned long registered_otp_map[BITS_TO_LONGS(MAX_OTP_DEVICES)];
+static DEFINE_MUTEX(otp_register_mutex);

do we really need this ?  if we let the minor number dictate availability, then we can increment until that errors/wraps, and we dont need to do any tracking ...

OK, so it would be nice to get rid of this but afaict we still need to do some accounting of available minor numbers in the range that we've allocated.  We could do a simple increment % 255 for the minor number but if OTP devices are removed at runtime then that may get fragmented and we would need to do retries of device_register() which feels a bit too easy to mess up.

Quoted 8 lines
Quoted 6 lines

Certainly allocating one major number for OTP devices then allocating the minors one by one would be much better than what I have now.

We probably also want it so that if you remove the OTP device that has had regions called otpaN then reinsert it they doesn't suddenly become otpbN.

yeah that's true. guess i'll leave it be then ;).

OK, but it still might be worth pruning it down to a single major number or is that something worth doing later on if it becomes needed?

Quoted 1 line

whatever naming is picked in /dev/ should match the stuff in /sys/ btw ...

I think that's working ok. On my system I have:

/sys/bus/otp/devices/otpa/otpa1/
/sys/bus/otp/devices/otpa/otpa2/

and

	/dev/otpa1
	/dev/otpa2

Jamie

#6 lore raw

Re: [RFC PATCHv3 1/4] drivers/otp: add initial support for OTP memory

Quoted 21 lines · Jamie Iles
Quoted 20 lines · Mike Frysinger
Quoted 19 lines · Jamie Iles
Quoted 7 lines · Mike Frysinger

drivers/otp/otp.c line 29

Quoted 2 lines · Jamie Iles
drivers/otp/otp.c new file +2 -0
+static unsigned long registered_otp_map[BITS_TO_LONGS(MAX_OTP_DEVICES)];
+static DEFINE_MUTEX(otp_register_mutex);

do we really need this ?  if we let the minor number dictate availability, then we can increment until that errors/wraps, and we dont need to do any tracking ...

OK, so it would be nice to get rid of this but afaict we still need to do some accounting of available minor numbers in the range that we've allocated.  We could do a simple increment % 255 for the minor number but if OTP devices are removed at runtime then that may get fragmented and we would need to do retries of device_register() which feels a bit too easy to mess up.

Certainly allocating one major number for OTP devices then allocating the minors one by one would be much better than what I have now.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

We probably also want it so that if you remove the OTP device that has had regions called otpaN then reinsert it they doesn't suddenly become otpbN.

yeah that's true.  guess i'll leave it be then ;).

OK, but it still might be worth pruning it down to a single major number or is that something worth doing later on if it becomes needed?

i dont think we'll see an explosion of OTP devices where we have to worry about major # exhaustion. if that day comes, we'll worry about things then.

as long as we stick to dynamic device numbers, we have the flexibility to screw around later.
-mike

author
#7 lore raw

RFC PATCH v3 2/4 drivers/otp: add support for Picoxcell PC3X3 OTP

In reply to Jamie Iles

The OTP in PC3X3 is 16KB and can be split into 1, 2, 4 or 8 regions each taking a different redundancy format. The formats increase the redundancy of the memory at the expense of bit storage to help protect against programming errors for devices in the field.

Changes since v2:
- Add support for CONFIG_OTP_WRITE_ENABLE.

---
 drivers/otp/Kconfig     |    7 +
 drivers/otp/Makefile    |    1 +
 drivers/otp/otp_pc3x3.c | 1099 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 1107 insertions(+), 0 deletions(-)
 create mode 100644 drivers/otp/otp_pc3x3.c
drivers/otp/Kconfig +7 -0
index 9a529c6..c1a3f5e 100644
@@ -25,4 +25,11 @@ config WRITE_ENABLE
 
 	  If unsure, say N.
 
+config OTP_PC3X3
+	tristate "Enable support for Picochip PC3X3 OTP"
+	depends on ARCH_PICOXCELL
+	help
+	  Say Y or M here to allow support for the OTP found in PC3X3 devices.
+	  If you say M then the module will be called otp_pc3x3.
+
 endif
drivers/otp/Makefile +1 -0
index 84fd03e..c710ec4 100644
@@ -1 +1,2 @@
 obj-$(CONFIG_OTP)	+= otp.o
+obj-$(CONFIG_OTP_PC3X3)	+= otp_pc3x3.o
drivers/otp/otp_pc3x3.c new file +1099 -0

1,099 lines not on this page · raw message

Signature · 1 line
1.7.4
author
#8 lore raw

RFC PATCH v3 3/4 drivers/otp: convert bfin otp to generic OTP

In reply to Jamie Iles

Convert the blackfin OTP driver to the generic OTP layer.

Changes since v2:
- Convert bfin-otp to a platform_driver.
- Hide the ECC and control bits from the character device interface.

Cc Mike Frysinger <[email protected]>
---
 drivers/char/Kconfig             |   28 ----
 drivers/char/Makefile            |    1 -
 drivers/otp/Kconfig              |   16 +++
 drivers/otp/Makefile             |    1 +
 drivers/{char => otp}/bfin-otp.c |  275 ++++++++++++++++++++-----------------
 5 files changed, 166 insertions(+), 155 deletions(-)
 rename drivers/{char => otp}/bfin-otp.c (40%)
drivers/char/Kconfig +0 -28
index ad59b4e..a078362 100644
@@ -81,34 +81,6 @@ config BRIQ_PANEL
 
 	  It's safe to say N here.
 
-config BFIN_OTP
-	tristate "Blackfin On-Chip OTP Memory Support"
-	depends on BLACKFIN && (BF51x || BF52x || BF54x)
-	default y
-	help
-	  If you say Y here, you will get support for a character device
-	  interface into the One Time Programmable memory pages that are
-	  stored on the Blackfin processor.  This will not get you access
-	  to the secure memory pages however.  You will need to write your
-	  own secure code and reader for that.
-
-	  To compile this driver as a module, choose M here: the module
-	  will be called bfin-otp.
-
-	  If unsure, it is safe to say Y.
-
-config BFIN_OTP_WRITE_ENABLE
-	bool "Enable writing support of OTP pages"
-	depends on BFIN_OTP
-	default n
-	help
-	  If you say Y here, you will enable support for writing of the
-	  OTP pages.  This is dangerous by nature as you can only program
-	  the pages once, so only enable this option when you actually
-	  need it so as to not inadvertently clobber data.
-
-	  If unsure, say N.
-
 config PRINTER
 	tristate "Parallel printer support"
 	depends on PARPORT
drivers/char/Makefile +0 -1
index 7a00672..bc436a6 100644
@@ -17,7 +17,6 @@ obj-$(CONFIG_VIOTAPE)		+= viotape.o
 obj-$(CONFIG_IBM_BSR)		+= bsr.o
 obj-$(CONFIG_SGI_MBCS)		+= mbcs.o
 obj-$(CONFIG_BRIQ_PANEL)	+= briq_panel.o
-obj-$(CONFIG_BFIN_OTP)		+= bfin-otp.o
 
 obj-$(CONFIG_PRINTER)		+= lp.o
 
drivers/otp/Kconfig +16 -0
index c1a3f5e..74c1f92 100644
@@ -32,4 +32,20 @@ config OTP_PC3X3
 	  Say Y or M here to allow support for the OTP found in PC3X3 devices.
 	  If you say M then the module will be called otp_pc3x3.
 
+config BFIN_OTP
+	tristate "Blackfin On-Chip OTP Memory Support"
+	depends on BLACKFIN && (BF51x || BF52x || BF54x)
+	default y
+	help
+	  If you say Y here, you will get support for a character device
+	  interface into the One Time Programmable memory pages that are
+	  stored on the Blackfin processor.  This will not get you access
+	  to the secure memory pages however.  You will need to write your
+	  own secure code and reader for that.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called bfin-otp.
+
+	  If unsure, it is safe to say Y.
+
 endif
drivers/otp/Makefile +1 -0
index c710ec4..db79667 100644
@@ -1,2 +1,3 @@
 obj-$(CONFIG_OTP)	+= otp.o
 obj-$(CONFIG_OTP_PC3X3)	+= otp_pc3x3.o
+obj-$(CONFIG_BFIN_OTP)	+= bfin-otp.o
drivers/otp/bfin-otp.c renamed from drivers/char/bfin-otp.c +149 -126

366 lines not on this page · raw message

Signature · 1 line
1.7.4
#9 lore raw

Re: [RFC PATCHv3 3/4] drivers/otp: convert bfin otp to generic OTP

drivers/otp/bfin-otp.c line 55

Quoted 7 lines · Jamie Iles
drivers/otp/bfin-otp.c renamed from drivers/char/bfin-otp.c +7 -0
+       /*
+        * Skip the control pages then if we would run into the ECC area skip
+        * past to the next data region.
+        */
+       raw_addr = region_addr + control_words;
+       if (raw_addr > 0x80 * BFIN_OTP_WORDS_PER_PAGE)
+               raw_addr += 0x20 * BFIN_OTP_WORDS_PER_PAGE;

mmm, no, we dont want to do that. the Blackfin documentation is very exact when it maps out pages, and we want the driver to match the documentation.

but i guess in the other discussion we had, this would be removed anyways.

drivers/otp/bfin-otp.c static long bfin_otp_ioctl(struct file *filp, unsigned cmd, unsigned long arg) · line 190

Quoted 5 lines
drivers/otp/bfin-otp.c renamed from drivers/char/bfin-otp.c +5 -0
+static int bfin_region_write_word(struct otp_region *region, unsigned long addr,
+                                 u64 content)
+{
+       return -EACCES;
+}

i think we'd just stub this out as NULL and let the common layer take care of rejecting it ?

Quoted 2 lines

+static const struct otp_device_ops bfin_otp_ops = {
+       .name           = "BFIN",

guess this should be "bfin-otp"

drivers/otp/bfin-otp.c static long bfin_otp_ioctl(struct file *filp, unsigned cmd, unsigned long arg) · line 231

Quoted 7 lines
drivers/otp/bfin-otp.c renamed from drivers/char/bfin-otp.c +7 -0
+static const struct otp_region_ops bfin_region_ops = {
+       .read_word      = bfin_region_read_word,
+       .write_word     = bfin_region_write_word,
+       .get_size       = bfin_region_get_size,
+       .get_fmt        = bfin_region_get_fmt,
+       .ioctl          = bfin_region_ioctl,
+};

hmm, i just realized this stuff is per-region. wouldnt the read/write/ioctl make more sense as per-device ? -mike

author
#10 lore raw

Re: [RFC PATCHv3 3/4] drivers/otp: convert bfin otp to generic OTP

Quoted 9 lines · Mike Frysinger

drivers/otp/bfin-otp.c line 55

Quoted 7 lines · Jamie Iles
drivers/otp/bfin-otp.c renamed from drivers/char/bfin-otp.c +7 -0
+       /*
+        * Skip the control pages then if we would run into the ECC area skip
+        * past to the next data region.
+        */
+       raw_addr = region_addr + control_words;
+       if (raw_addr > 0x80 * BFIN_OTP_WORDS_PER_PAGE)
+               raw_addr += 0x20 * BFIN_OTP_WORDS_PER_PAGE;
Quoted 5 lines

mmm, no, we dont want to do that. the Blackfin documentation is very exact when it maps out pages, and we want the driver to match the documentation.

but i guess in the other discussion we had, this would be removed anyways.

OK, so in that case could we initially have:

- region for control bits
- region for the first data bits
- region for the ecc for the first data
- region for the second data bits
- region for the ecc for the second data

or shall I just leave it as one big region for now?

Quoted 9 lines

drivers/otp/bfin-otp.c static long bfin_otp_ioctl(struct file *filp, unsigned cmd, unsigned long arg) · line 190

Quoted 6 lines
drivers/otp/bfin-otp.c renamed from drivers/char/bfin-otp.c +5 -0
+static int bfin_region_write_word(struct otp_region *region, unsigned long addr,
+                                 u64 content)
+{
+       return -EACCES;
+}

i think we'd just stub this out as NULL and let the common layer take care of rejecting it ?

Yes, that's probably best. At least we're always building the whole driver then.

Quoted 5 lines
Quoted 3 lines

+static const struct otp_device_ops bfin_otp_ops = {
+       .name           = "BFIN",

guess this should be "bfin-otp"

Good spot.

Quoted 11 lines

drivers/otp/bfin-otp.c static long bfin_otp_ioctl(struct file *filp, unsigned cmd, unsigned long arg) · line 231

Quoted 8 lines
drivers/otp/bfin-otp.c renamed from drivers/char/bfin-otp.c +7 -0
+static const struct otp_region_ops bfin_region_ops = {
+       .read_word      = bfin_region_read_word,
+       .write_word     = bfin_region_write_word,
+       .get_size       = bfin_region_get_size,
+       .get_fmt        = bfin_region_get_fmt,
+       .ioctl          = bfin_region_ioctl,
+};

hmm, i just realized this stuff is per-region. wouldnt the read/write/ioctl make more sense as per-device ?

No, I don't think so. The file_operations are all based on the regions rather than the device so I think it makes sense to have these as region based operations. We could make them per device and pass the region as a parameter but I'm not sure that it gains us anything.

Jamie

#11 lore raw

Re: [RFC PATCHv3 3/4] drivers/otp: convert bfin otp to generic OTP

Quoted 1 line · Jamie Iles

or shall I just leave it as one big region for now?

for now, stick with one region. i can refine it later if i desire.

Quoted 11 lines
Quoted 10 lines

drivers/otp/bfin-otp.c static long bfin_otp_ioctl(struct file *filp, unsigned cmd, unsigned long arg) · line 231

Quoted 7 lines
drivers/otp/bfin-otp.c renamed from drivers/char/bfin-otp.c +7 -0
+static const struct otp_region_ops bfin_region_ops = {
+       .read_word      = bfin_region_read_word,
+       .write_word     = bfin_region_write_word,
+       .get_size       = bfin_region_get_size,
+       .get_fmt        = bfin_region_get_fmt,
+       .ioctl          = bfin_region_ioctl,
+};

hmm, i just realized this stuff is per-region.  wouldnt the read/write/ioctl make more sense as per-device ?

Quoted 4 lines

No, I don't think so.  The file_operations are all based on the regions rather than the device so I think it makes sense to have these as region based operations.  We could make them per device and pass the region as a parameter but I'm not sure that it gains us anything.

for a device that exports more than one region, you dont need to duplicate the structure. as you add in more regions, the amount of duplication increases.

how many regions does your device export ? does it need different read/write behavior for each ?
-mike

author
#12 lore raw

Re: [RFC PATCHv3 3/4] drivers/otp: convert bfin otp to generic OTP

Quoted 16 lines · Mike Frysinger
Quoted 11 lines
Quoted 10 lines

drivers/otp/bfin-otp.c static long bfin_otp_ioctl(struct file *filp, unsigned cmd, unsigned long arg) · line 231

Quoted 7 lines
drivers/otp/bfin-otp.c renamed from drivers/char/bfin-otp.c +7 -0
+static const struct otp_region_ops bfin_region_ops = {
+       .read_word      = bfin_region_read_word,
+       .write_word     = bfin_region_write_word,
+       .get_size       = bfin_region_get_size,
+       .get_fmt        = bfin_region_get_fmt,
+       .ioctl          = bfin_region_ioctl,
+};

hmm, i just realized this stuff is per-region.  wouldnt the read/write/ioctl make more sense as per-device ?

Quoted 4 lines

No, I don't think so.  The file_operations are all based on the regions rather than the device so I think it makes sense to have these as region based operations.  We could make them per device and pass the region as a parameter but I'm not sure that it gains us anything.

Quoted 6 lines

for a device that exports more than one region, you dont need to duplicate the structure. as you add in more regions, the amount of duplication increases.

how many regions does your device export ? does it need different read/write behavior for each ?

The current devices are up to 8 regions and whilst the behaviour is the same for each it does need to know what region it's operating on so it can set the redundancy correctly.

We could move the read and write methods into some device ops but they'd need to take an otp_region as a parameter. Also, at the moment we don't duplicate the structure as we're just keeping a pointer to it but I'm happy to move these into the device ops if you have a strong preference.

Jamie

#13 lore raw

Re: [RFC PATCHv3 3/4] drivers/otp: convert bfin otp to generic OTP

Quoted 24 lines · Jamie Iles
Quoted 16 lines · Mike Frysinger
Quoted 11 lines
Quoted 10 lines

drivers/otp/bfin-otp.c static long bfin_otp_ioctl(struct file *filp, unsigned cmd, unsigned long arg) · line 231

Quoted 7 lines
drivers/otp/bfin-otp.c renamed from drivers/char/bfin-otp.c +7 -0
+static const struct otp_region_ops bfin_region_ops = {
+       .read_word      = bfin_region_read_word,
+       .write_word     = bfin_region_write_word,
+       .get_size       = bfin_region_get_size,
+       .get_fmt        = bfin_region_get_fmt,
+       .ioctl          = bfin_region_ioctl,
+};

hmm, i just realized this stuff is per-region.  wouldnt the read/write/ioctl make more sense as per-device ?

Quoted 4 lines

No, I don't think so.  The file_operations are all based on the regions rather than the device so I think it makes sense to have these as region based operations.  We could make them per device and pass the region as a parameter but I'm not sure that it gains us anything.

Quoted 6 lines

for a device that exports more than one region, you dont need to duplicate the structure.  as you add in more regions, the amount of duplication increases.

how many regions does your device export ?  does it need different read/write behavior for each ?

Quoted 8 lines

The current devices are up to 8 regions and whilst the behaviour is the same for each it does need to know what region it's operating on so it can set the redundancy correctly.

We could move the read and write methods into some device ops but they'd need to take an otp_region as a parameter.  Also, at the moment we don't duplicate the structure as we're just keeping a pointer to it but I'm happy to move these into the device ops if you have a strong preference.

i can see keeping the fmt/size in the region, but the read/write/ioctl really look like they belong at the device level
-mike

author
#14 lore raw

RFC PATCH v3 4/4 Blackfin: add the OTP device as a platform device

In reply to Jamie Iles

Register the OTP as a platform device so that we can use the generic OTP subsystem.

Cc Mike Frysinger <[email protected]>
---
 arch/blackfin/mach-bf518/boards/ezbrd.c      |   10 ++++++++++
 arch/blackfin/mach-bf518/boards/tcm-bf518.c  |   10 ++++++++++
 arch/blackfin/mach-bf527/boards/ad7160eval.c |   10 ++++++++++
 arch/blackfin/mach-bf527/boards/cm_bf527.c   |   10 ++++++++++
 arch/blackfin/mach-bf527/boards/ezbrd.c      |   10 ++++++++++
 arch/blackfin/mach-bf527/boards/ezkit.c      |   10 ++++++++++
 arch/blackfin/mach-bf527/boards/tll6527m.c   |   10 ++++++++++
 arch/blackfin/mach-bf548/boards/cm_bf548.c   |    9 +++++++++
 arch/blackfin/mach-bf548/boards/ezkit.c      |   10 ++++++++++
 9 files changed, 89 insertions(+), 0 deletions(-)
arch/blackfin/mach-bf518/boards/ezbrd.c +10 -0
index c0ccadc..7328ea1 100644
@@ -747,6 +747,12 @@ static struct platform_device bfin_dpmc = {
 	},
 };
 
+#if defined(CONFIG_BFIN_OTP) || defined(CONFIG_BFIN_OTP_MODULE)
+static struct platform_device bfin_otp_device = {
+	.name = "bfin-otp",
+};
+#endif
+
 static struct platform_device *stamp_devices[] __initdata = {
 
 	&bfin_dpmc,
@@ -814,6 +820,10 @@ static struct platform_device *stamp_devices[] __initdata = {
 #if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
 	&ezbrd_flash_device,
 #endif
+
+#if defined(CONFIG_BFIN_OTP) || defined(CONFIG_BFIN_OTP_MODULE)
+	&bfin_otp_device,
+#endif
 };
 
 static int __init ezbrd_init(void)
arch/blackfin/mach-bf518/boards/tcm-bf518.c +10 -0
index 50fc5c8..a36a1b2 100644
@@ -659,6 +659,12 @@ static struct platform_device bfin_dpmc = {
 	},
 };
 
+#if defined(CONFIG_BFIN_OTP) || defined(CONFIG_BFIN_OTP_MODULE)
+static struct platform_device bfin_otp_device = {
+	.name = "bfin-otp",
+};
+#endif
+
 static struct platform_device *tcm_devices[] __initdata = {
 
 	&bfin_dpmc,
@@ -719,6 +725,10 @@ static struct platform_device *tcm_devices[] __initdata = {
 #if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
 	&tcm_flash_device,
 #endif
+
+#if defined(CONFIG_BFIN_OTP) || defined(CONFIG_BFIN_OTP_MODULE)
+	&bfin_otp_device,
+#endif
 };
 
 static int __init tcm_init(void)
arch/blackfin/mach-bf527/boards/ad7160eval.c +10 -0
index ccab4c6..05ac322 100644
@@ -731,6 +731,12 @@ static struct platform_device bfin_dpmc = {
 	},
 };
 
+#if defined(CONFIG_BFIN_OTP) || defined(CONFIG_BFIN_OTP_MODULE)
+static struct platform_device bfin_otp_device = {
+	.name = "bfin-otp",
+};
+#endif
+
 static struct platform_device *stamp_devices[] __initdata = {
 
 	&bfin_dpmc,
@@ -806,6 +812,10 @@ static struct platform_device *stamp_devices[] __initdata = {
 #if defined(CONFIG_SND_BF5XX_TDM) || defined(CONFIG_SND_BF5XX_TDM_MODULE)
 	&bfin_tdm,
 #endif
+
+#if defined(CONFIG_BFIN_OTP) || defined(CONFIG_BFIN_OTP_MODULE)
+	&bfin_otp_device,
+#endif
 };
 
 static int __init ad7160eval_init(void)
arch/blackfin/mach-bf527/boards/cm_bf527.c +10 -0
index c9d6dc8..a8e807a 100644
@@ -896,6 +896,12 @@ static struct platform_device bfin_dpmc = {
 	},
 };
 
+#if defined(CONFIG_BFIN_OTP) || defined(CONFIG_BFIN_OTP_MODULE)
+static struct platform_device bfin_otp_device = {
+	.name = "bfin-otp",
+};
+#endif
+
 static struct platform_device *cmbf527_devices[] __initdata = {
 
 	&bfin_dpmc,
@@ -979,6 +985,10 @@ static struct platform_device *cmbf527_devices[] __initdata = {
 #if defined(CONFIG_MTD_GPIO_ADDR) || defined(CONFIG_MTD_GPIO_ADDR_MODULE)
 	&cm_flash_device,
 #endif
+
+#if defined(CONFIG_BFIN_OTP) || defined(CONFIG_BFIN_OTP_MODULE)
+	&bfin_otp_device,
+#endif
 };
 
 static int __init cm_init(void)
arch/blackfin/mach-bf527/boards/ezbrd.c +10 -0
index b7101aa..aabfb72 100644
@@ -806,6 +806,12 @@ static struct platform_device bfin_lq035q1_device = {
 };
 #endif
 
+#if defined(CONFIG_BFIN_OTP) || defined(CONFIG_BFIN_OTP_MODULE)
+static struct platform_device bfin_otp_device = {
+	.name = "bfin-otp",
+};
+#endif
+
 static struct platform_device *stamp_devices[] __initdata = {
 
 	&bfin_dpmc,
@@ -873,6 +879,10 @@ static struct platform_device *stamp_devices[] __initdata = {
 #if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
 	&ezbrd_flash_device,
 #endif
+
+#if defined(CONFIG_BFIN_OTP) || defined(CONFIG_BFIN_OTP_MODULE)
+	&bfin_otp_device,
+#endif
 };
 
 static int __init ezbrd_init(void)
arch/blackfin/mach-bf527/boards/ezkit.c +10 -0
index 2cd2ff6..8e1d6eb 100644
@@ -1115,6 +1115,12 @@ static struct platform_device bfin_dpmc = {
 	},
 };
 
+#if defined(CONFIG_BFIN_OTP) || defined(CONFIG_BFIN_OTP_MODULE)
+static struct platform_device bfin_otp_device = {
+	.name = "bfin-otp",
+};
+#endif
+
 static struct platform_device *stamp_devices[] __initdata = {
 
 	&bfin_dpmc,
@@ -1218,6 +1224,10 @@ static struct platform_device *stamp_devices[] __initdata = {
 #if defined(CONFIG_SND_BF5XX_TDM) || defined(CONFIG_SND_BF5XX_TDM_MODULE)
 	&bfin_tdm,
 #endif
+
+#if defined(CONFIG_BFIN_OTP) || defined(CONFIG_BFIN_OTP_MODULE)
+	&bfin_otp_device,
+#endif
 };
 
 static int __init ezkit_init(void)
arch/blackfin/mach-bf527/boards/tll6527m.c +10 -0
index 18d303d..f1de548 100644
@@ -873,6 +873,12 @@ static struct platform_device bfin_dpmc = {
 	},
 };
 
+#if defined(CONFIG_BFIN_OTP) || defined(CONFIG_BFIN_OTP_MODULE)
+static struct platform_device bfin_otp_device = {
+	.name = "bfin-otp",
+};
+#endif
+
 static struct platform_device *tll6527m_devices[] __initdata = {
 
 	&bfin_dpmc,
@@ -941,6 +947,10 @@ static struct platform_device *tll6527m_devices[] __initdata = {
 #if defined(CONFIG_GPIO_DECODER) || defined(CONFIG_GPIO_DECODER_MODULE)
 	&spi_decoded_gpio,
 #endif
+
+#if defined(CONFIG_BFIN_OTP) || defined(CONFIG_BFIN_OTP_MODULE)
+	&bfin_otp_device,
+#endif
 };
 
 static int __init tll6527m_init(void)
arch/blackfin/mach-bf548/boards/cm_bf548.c +9 -0
index d11502a..746b3df 100644
@@ -1093,6 +1093,12 @@ static struct platform_device bfin_dpmc = {
 	},
 };
 
+#if defined(CONFIG_BFIN_OTP) || defined(CONFIG_BFIN_OTP_MODULE)
+static struct platform_device bfin_otp_device = {
+	.name = "bfin-otp",
+};
+#endif
+
 static struct platform_device *cm_bf548_devices[] __initdata = {
 
 	&bfin_dpmc,
@@ -1198,6 +1204,9 @@ static struct platform_device *cm_bf548_devices[] __initdata = {
 	&bfin_can_device,
 #endif
 
+#if defined(CONFIG_BFIN_OTP) || defined(CONFIG_BFIN_OTP_MODULE)
+	&bfin_otp_device,
+#endif
 };
 
 static int __init cm_bf548_init(void)
arch/blackfin/mach-bf548/boards/ezkit.c +10 -0
index 93e19a5..6385c4e 100644
@@ -1336,6 +1336,12 @@ static struct platform_device bfin_ac97 = {
 };
 #endif
 
+#if defined(CONFIG_BFIN_OTP) || defined(CONFIG_BFIN_OTP_MODULE)
+static struct platform_device bfin_otp_device = {
+	.name = "bfin-otp",
+};
+#endif
+
 static struct platform_device *ezkit_devices[] __initdata = {
 
 	&bfin_dpmc,
@@ -1461,6 +1467,10 @@ static struct platform_device *ezkit_devices[] __initdata = {
 #if defined(CONFIG_SND_BF5XX_AC97) || defined(CONFIG_SND_BF5XX_AC97_MODULE)
 	&bfin_ac97,
 #endif
+
+#if defined(CONFIG_BFIN_OTP) || defined(CONFIG_BFIN_OTP_MODULE)
+	&bfin_otp_device,
+#endif
 };
 
 static int __init ezkit_init(void)
Signature · 1 line
1.7.4
#15 lore raw

Re: [RFC PATCHv3 4/4] Blackfin: add the OTP device as a platform device

Quoted 2 lines · Jamie Iles

Register the OTP as a platform device so that we can use the generic OTP subsystem.

i would move this to patch 3/4 so that the boards are updated before the driver is converted to a platform_driver

otherwise, this patch looks good to me (i'll hold off on actually testing things until common code has settled a bit) -mike