Skip to contentSkip to conversation

Support M95040 SPI EEPROM

PATCH Superseded Ivo Sieben 5 participants 14 messages Apr 3, 2012 – Apr 17, 2012

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Ivo Sieben

author
#0 lore raw

PATCH v3 1/1 Support M95040 SPI EEPROM

Updated the generic SPI EEPROM driver AT25 for support of an additional address bit in the instruction byte. Certain EEPROMS have a size that is larger than the number of address bytes would allow (e.g. like M95040 from ST that has 512 Byte size but uses only one address byte (A0 to A7) for addressing.) For the extra address bit (A8, A16 or A24) bit 3 of the instruction byte is used. This instruction bit is normally defined as don't care for other AT25 like chips.

---
v3: Processed review comments from Wolfram Sang: no additional address_offset is calculated during the probe, but during the read/write the flag is checked and the extra address bit offset is calculated runtime.

 drivers/misc/eeprom/at25.c |   19 ++++++++++++++++---
 include/linux/spi/eeprom.h |   10 ++++++++++
 2 files changed, 26 insertions(+), 3 deletions(-)
drivers/misc/eeprom/at25.c +16 -3
index c627e41..0d272c6 100644
@@ -50,6 +50,7 @@ struct at25_data {
 #define	AT25_SR_BP1	0x08
 #define	AT25_SR_WPEN	0x80		/* writeprotect enable */
 
+#define	AT25_INSTR_BIT3	0x08		/* Additional address bit in instr */
 
 #define EE_MAXADDRLEN	3		/* 24 bit addresses, up to 2 MBytes */
 
@@ -75,6 +76,7 @@ at25_ee_read(
 	ssize_t			status;
 	struct spi_transfer	t[2];
 	struct spi_message	m;
+	u8			instr;
 
 	if (unlikely(offset >= at25->bin.size))
 		return 0;
@@ -84,7 +86,12 @@ at25_ee_read(
 		return count;
 
 	cp = command;
-	*cp++ = AT25_READ;
+
+	instr = AT25_READ;
+	if (at25->chip.flags & EE_INSTR_BIT3_IS_ADDR)
+		if (offset >= (1U << (at25->addrlen * 8)))
+			instr |= AT25_INSTR_BIT3;
+	*cp++ = instr;
 
 	/* 8/16/24-bit address is written MSB first */
 	switch (at25->addrlen) {
@@ -167,14 +174,14 @@ at25_ee_write(struct at25_data *at25, const char *buf, loff_t off,
 	/* For write, rollover is within the page ... so we write at
 	 * most one page, then manually roll over to the next page.
 	 */
-	bounce[0] = AT25_WRITE;
 	mutex_lock(&at25->lock);
 	do {
 		unsigned long	timeout, retries;
 		unsigned	segment;
 		unsigned	offset = (unsigned) off;
-		u8		*cp = bounce + 1;
+		u8		*cp = bounce;
 		int		sr;
+		u8		instr;
 
 		*cp = AT25_WREN;
 		status = spi_write(at25->spi, cp, 1);
@@ -184,6 +191,12 @@ at25_ee_write(struct at25_data *at25, const char *buf, loff_t off,
 			break;
 		}
 
+		instr = AT25_WRITE;
+		if (at25->chip.flags & EE_INSTR_BIT3_IS_ADDR)
+			if (offset >= (1U << (at25->addrlen * 8)))
+				instr |= AT25_INSTR_BIT3;
+		*cp++ = instr;
+
 		/* 8/16/24-bit address is written MSB first */
 		switch (at25->addrlen) {
 		default:	/* case 3 */
include/linux/spi/eeprom.h +10 -0
index 306e7b1..403e007 100644
@@ -20,6 +20,16 @@ struct spi_eeprom {
 #define	EE_ADDR3	0x0004			/* 24 bit addrs */
 #define	EE_READONLY	0x0008			/* disallow writes */
 
+	/*
+	 * Certain EEPROMS have a size that is larger than the number of address
+	 * bytes would allow (e.g. like M95040 from ST that has 512 Byte size
+	 * but uses only one address byte (A0 to A7) for addressing.) For
+	 * the extra address bit (A8, A16 or A24) bit 3 of the instruction byte
+	 * is used. This instruction bit is normally defined as don't care for
+	 * other AT25 like chips.
+	 */
+#define EE_INSTR_BIT3_IS_ADDR	0x0010
+
 	/* for exporting this chip's data to other kernel code */
 	void (*setup)(struct memory_accessor *mem, void *context);
 	void *context;
Signature · 1 line
1.7.0.4
Reviewed-by on v3 1/1
#1 lore raw
Quoted 8 lines · Ivo Sieben

Updated the generic SPI EEPROM driver AT25 for support of an additional address bit in the instruction byte. Certain EEPROMS have a size that is larger than the number of address bytes would allow (e.g. like M95040 from ST that has 512 Byte size but uses only one address byte (A0 to A7) for addressing.) For the extra address bit (A8, A16 or A24) bit 3 of the instruction byte is used. This instruction bit is normally defined as don't care for other AT25 like chips.

Thanks for keeping at it!

I could also pick it up (since I am looking after at24, so that fits somehow), but Greg's tree is maybe the more obvious place.

Regards,

Wolfram

Signature · 2 lines
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
#2 lore raw
In reply to Ivo Sieben
Quoted 5 lines · * Ivo Sieben ([email protected]) wrote:
drivers/misc/eeprom/at25.c +5 -0
+	instr = AT25_READ;
+	if (at25->chip.flags & EE_INSTR_BIT3_IS_ADDR)
+		if (offset >= (1U << (at25->addrlen * 8)))
+			instr |= AT25_INSTR_BIT3;
+	*cp++ = instr;

<snip>

include/linux/spi/eeprom.h struct spi_eeprom { · line 31

Quoted 9 lines
include/linux/spi/eeprom.h +9 -0
+	/*
+	 * Certain EEPROMS have a size that is larger than the number of address
+	 * bytes would allow (e.g. like M95040 from ST that has 512 Byte size
+	 * but uses only one address byte (A0 to A7) for addressing.) For
+	 * the extra address bit (A8, A16 or A24) bit 3 of the instruction byte
+	 * is used. This instruction bit is normally defined as don't care for
+	 * other AT25 like chips.
+	 */
+#define EE_INSTR_BIT3_IS_ADDR	0x0010

Is there some guarantee that this chip flag will always have this meaning?

thanks,
-chris

#3 lore raw
Quoted 7 lines · Chris Wright
Quoted 5 lines · * Ivo Sieben ([email protected]) wrote:
drivers/misc/eeprom/at25.c +5 -0
+	instr = AT25_READ;
+	if (at25->chip.flags & EE_INSTR_BIT3_IS_ADDR)
+		if (offset >= (1U << (at25->addrlen * 8)))
+			instr |= AT25_INSTR_BIT3;
+	*cp++ = instr;

<snip>

Quoted 12 lines

include/linux/spi/eeprom.h struct spi_eeprom { · line 31

Quoted 9 lines
include/linux/spi/eeprom.h +9 -0
+	/*
+	 * Certain EEPROMS have a size that is larger than the number of address
+	 * bytes would allow (e.g. like M95040 from ST that has 512 Byte size
+	 * but uses only one address byte (A0 to A7) for addressing.) For
+	 * the extra address bit (A8, A16 or A24) bit 3 of the instruction byte
+	 * is used. This instruction bit is normally defined as don't care for
+	 * other AT25 like chips.
+	 */
+#define EE_INSTR_BIT3_IS_ADDR	0x0010

Is there some guarantee that this chip flag will always have this meaning?

? This is a driver flag.

Signature · 2 lines
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
#4 lore raw
Quoted 21 lines · * Wolfram Sang ([email protected]) wrote:
Quoted 7 lines · Chris Wright
Quoted 5 lines · * Ivo Sieben ([email protected]) wrote:
drivers/misc/eeprom/at25.c +5 -0
+	instr = AT25_READ;
+	if (at25->chip.flags & EE_INSTR_BIT3_IS_ADDR)
+		if (offset >= (1U << (at25->addrlen * 8)))
+			instr |= AT25_INSTR_BIT3;
+	*cp++ = instr;

<snip>

Quoted 12 lines

include/linux/spi/eeprom.h struct spi_eeprom { · line 31

Quoted 9 lines
include/linux/spi/eeprom.h +9 -0
+	/*
+	 * Certain EEPROMS have a size that is larger than the number of address
+	 * bytes would allow (e.g. like M95040 from ST that has 512 Byte size
+	 * but uses only one address byte (A0 to A7) for addressing.) For
+	 * the extra address bit (A8, A16 or A24) bit 3 of the instruction byte
+	 * is used. This instruction bit is normally defined as don't care for
+	 * other AT25 like chips.
+	 */
+#define EE_INSTR_BIT3_IS_ADDR	0x0010

Is there some guarantee that this chip flag will always have this meaning?

Quoted 1 line

? This is a driver flag.

Sorry, I don't see it set anywhere, so unclear on where it comes from. I thought it was from a generic spi probe.

thanks,
-chris

#5 lore raw
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines

include/linux/spi/eeprom.h struct spi_eeprom { · line 31

Quoted 10 lines
include/linux/spi/eeprom.h +9 -0
+	/*
+	 * Certain EEPROMS have a size that is larger than the number of address
+	 * bytes would allow (e.g. like M95040 from ST that has 512 Byte size
+	 * but uses only one address byte (A0 to A7) for addressing.) For
+	 * the extra address bit (A8, A16 or A24) bit 3 of the instruction byte
+	 * is used. This instruction bit is normally defined as don't care for
+	 * other AT25 like chips.
+	 */
+#define EE_INSTR_BIT3_IS_ADDR	0x0010

Is there some guarantee that this chip flag will always have this meaning?

Quoted 4 lines
Quoted 1 line

? This is a driver flag.

Sorry, I don't see it set anywhere, so unclear on where it comes from. I thought it was from a generic spi probe.

Yeah, agreed, 'struct spi_eeprom' does not sound much like platform_data :/ Thanks for checking.

Signature · 2 lines
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
author
#6 lore raw

Hi,

Op 3 april 2012 19:17 heeft Wolfram Sang <[email protected]> het volgende geschreven:

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

+#define EE_INSTR_BIT3_IS_ADDR  0x0010

Is there some guarantee that this chip flag will always have this meaning?

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

? This is a driver flag.

Sorry, I don't see it set anywhere, so unclear on where it comes from. I thought it was from a generic spi probe.

Yeah, agreed, 'struct spi_eeprom' does not sound much like platform_data :/ Thanks for checking.

The flag is indeed used in the platform initialization to enable the "address bit" behavior, so you don't see it set anywhere in this patch (and not anywhere in the kernel, since no board uses this flag yet).

Is it OK if we leave this patch like this?

Regards,
Ivo Sieben

#7 lore raw
Quoted 15 lines · Ivo Sieben

Hi,

Op 3 april 2012 19:17 heeft Wolfram Sang <[email protected]> het volgende geschreven:

Quoted 11 lines
Quoted 10 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

+#define EE_INSTR_BIT3_IS_ADDR  0x0010

Is there some guarantee that this chip flag will always have this meaning?

? This is a driver flag.

Sorry, I don't see it set anywhere, so unclear on where it comes from. I thought it was from a generic spi probe.

Quoted 8 lines
Quoted 2 lines

Yeah, agreed, 'struct spi_eeprom' does not sound much like platform_data :/ Thanks for checking.

The flag is indeed used in the platform initialization to enable the "address bit" behavior, so you don't see it set anywhere in this patch (and not anywhere in the kernel, since no board uses this flag yet).

Is it OK if we leave this patch like this?

Yes. This is a useful extension and there will be boards using it.

Thanks,

Wolfram

Signature · 2 lines
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
author
#8 lore raw

Hi

Op 4 april 2012 09:59 heeft Wolfram Sang <[email protected]> het volgende geschreven:

Quoted 6 lines

Yes. This is a useful extension and there will be boards using it.

Thanks,

  Wolfram

OK, thanks

@Greg:
Can this patch be picked up in your tree? Or should it be picked up by Wolfram at24 support?

Regards,
Ivo Sieben

maintainer
#9 lore raw
Quoted 9 lines · Ivo Sieben

Hi

Op 4 april 2012 09:59 heeft Wolfram Sang <[email protected]> het volgende geschreven:

Quoted 5 lines

Yes. This is a useful extension and there will be boards using it.

Thanks,

Quoted 7 lines
Quoted 1 line

  Wolfram

OK, thanks

@Greg:
Can this patch be picked up in your tree? Or should it be picked up by Wolfram at24 support?

I'll be glad to take it, but I don't seem to be able to find the original patch anywhere, can someone bounce it to me?

thanks,

greg k-h

#10 lore raw

Hi Greg,

2012/4/5 Greg KH <[email protected]>:

Quoted 7 lines · Ivo Sieben
Quoted 3 lines

@Greg:
Can this patch be picked up in your tree? Or should it be picked up by Wolfram at24 support?

I'll be glad to take it, but I don't seem to be able to find the original patch anywhere, can someone bounce it to me?

Since Ivo is a few days off, I do not expect him to answer before next Tuesday. So, I attached the latest version (=v3) of his patch to this mail. I attached it to keep the author/owner information to Ivo.

Is this acceptable for you Greg?

Kind regards,

Remy

From: Ivo Sieben <[email protected]>
To: <[email protected]>,
Wolfram Sang <[email protected]>, Jean Delvare <[email protected]>, Kevin Hilman <[email protected]>, Chris Wright <[email protected]>
CC: Ivo Sieben <[email protected]>
Subject: [PATCH-v3] Support M95040 SPI EEPROM
Date: Tue, 3 Apr 2012 08:25:02 +0200

Updated the generic SPI EEPROM driver AT25 for support of an additional address bit in the instruction byte. Certain EEPROMS have a size that is larger than the number of address bytes would allow (e.g. like M95040 from ST that has 512 Byte size but uses only one address byte (A0 to A7) for addressing.) For the extra address bit (A8, A16 or A24) bit 3 of the instruction byte is used. This instruction bit is normally defined as don't care for other AT25 like chips.

---
v3: Processed review comments from Wolfram Sang: no additional address_offset is calculated during the probe, but during the read/write the flag is checked and the extra address bit offset is calculated runtime.

 drivers/misc/eeprom/at25.c |   19 ++++++++++++++++---
 include/linux/spi/eeprom.h |   10 ++++++++++
 2 files changed, 26 insertions(+), 3 deletions(-)
drivers/misc/eeprom/at25.c +16 -3
index c627e41..0d272c6 100644
@@ -50,6 +50,7 @@ struct at25_data {
 #define	AT25_SR_BP1	0x08
 #define	AT25_SR_WPEN	0x80		/* writeprotect enable */
 
+#define	AT25_INSTR_BIT3	0x08		/* Additional address bit in instr */
 
 #define EE_MAXADDRLEN	3		/* 24 bit addresses, up to 2 MBytes */
 
@@ -75,6 +76,7 @@ at25_ee_read(
 	ssize_t			status;
 	struct spi_transfer	t[2];
 	struct spi_message	m;
+	u8			instr;
 
 	if (unlikely(offset >= at25->bin.size))
 		return 0;
@@ -84,7 +86,12 @@ at25_ee_read(
 		return count;
 
 	cp = command;
-	*cp++ = AT25_READ;
+
+	instr = AT25_READ;
+	if (at25->chip.flags & EE_INSTR_BIT3_IS_ADDR)
+		if (offset >= (1U << (at25->addrlen * 8)))
+			instr |= AT25_INSTR_BIT3;
+	*cp++ = instr;
 
 	/* 8/16/24-bit address is written MSB first */
 	switch (at25->addrlen) {
@@ -167,14 +174,14 @@ at25_ee_write(struct at25_data *at25, const char *buf, loff_t off,
 	/* For write, rollover is within the page ... so we write at
 	 * most one page, then manually roll over to the next page.
 	 */
-	bounce[0] = AT25_WRITE;
 	mutex_lock(&at25->lock);
 	do {
 		unsigned long	timeout, retries;
 		unsigned	segment;
 		unsigned	offset = (unsigned) off;
-		u8		*cp = bounce + 1;
+		u8		*cp = bounce;
 		int		sr;
+		u8		instr;
 
 		*cp = AT25_WREN;
 		status = spi_write(at25->spi, cp, 1);
@@ -184,6 +191,12 @@ at25_ee_write(struct at25_data *at25, const char *buf, loff_t off,
 			break;
 		}
 
+		instr = AT25_WRITE;
+		if (at25->chip.flags & EE_INSTR_BIT3_IS_ADDR)
+			if (offset >= (1U << (at25->addrlen * 8)))
+				instr |= AT25_INSTR_BIT3;
+		*cp++ = instr;
+
 		/* 8/16/24-bit address is written MSB first */
 		switch (at25->addrlen) {
 		default:	/* case 3 */
include/linux/spi/eeprom.h +10 -0
index 306e7b1..403e007 100644
@@ -20,6 +20,16 @@ struct spi_eeprom {
 #define	EE_ADDR3	0x0004			/* 24 bit addrs */
 #define	EE_READONLY	0x0008			/* disallow writes */
 
+	/*
+	 * Certain EEPROMS have a size that is larger than the number of address
+	 * bytes would allow (e.g. like M95040 from ST that has 512 Byte size
+	 * but uses only one address byte (A0 to A7) for addressing.) For
+	 * the extra address bit (A8, A16 or A24) bit 3 of the instruction byte
+	 * is used. This instruction bit is normally defined as don't care for
+	 * other AT25 like chips.
+	 */
+#define EE_INSTR_BIT3_IS_ADDR	0x0010
+
 	/* for exporting this chip's data to other kernel code */
 	void (*setup)(struct memory_accessor *mem, void *context);
 	void *context;
Signature · 1 line
1.7.0.4
Reviewed-by
#11 lore raw
Quoted 1 line

Is this acceptable for you Greg?

If so, don't forget my

given to the original patch.

Regards,

Wolfram

Signature · 2 lines
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
author
#12 lore raw
Quoted 8 lines
Quoted 1 line

Is this acceptable for you Greg?

If so, don't forget my

given to the original patch.

Greg, what's the status on this patch?
Is it acceptable for you, or do you want me to resend the patch (including the "Reviewed-by" tag)

Thanks.

Regards,
Ivo Sieben

maintainer
#13 lore raw
Quoted 4 lines · Ivo Sieben
Quoted 4 lines
Quoted 1 line

Is this acceptable for you Greg?

If so, don't forget my

Quoted 8 lines
Quoted 4 lines

given to the original patch.

Greg, what's the status on this patch?
Is it acceptable for you, or do you want me to resend the patch (including the "Reviewed-by" tag)

Please resend it, as all I seem to be able to find is a base64 attachment, which is a pain to deal with...

greg k-h