* [PATCH] Support M95040 SPI EEPROM
@ 2012-03-21 15:24 Ivo Sieben
2012-03-21 15:33 ` Ivo Sieben
2012-03-21 17:30 ` Chris Wright
0 siblings, 2 replies; 4+ messages in thread
From: Ivo Sieben @ 2012-03-21 15:24 UTC (permalink / raw)
To: linux-kernel; +Cc: Ivo Sieben
Updated the generic SPI EEPROM driver AT25 for support of address bit A8
in the instruction byte. Certain EEPROMS (like M95040 from ST) have a 512
Byte size but use only one address byte (A0 to A7) for addressing. For the
extra address bit A8 bit 3 of the instruction byte is used. This instruction
bit is threated as don't care for other AT25 like chips
Signed-off-by: Ivo Sieben <meltedpianoman@gmail.com>
---
drivers/misc/eeprom/at25.c | 31 ++++++++++++++++++++++++++++---
1 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/drivers/misc/eeprom/at25.c b/drivers/misc/eeprom/at25.c
index c627e41..907aecc 100644
--- a/drivers/misc/eeprom/at25.c
+++ b/drivers/misc/eeprom/at25.c
@@ -50,6 +50,7 @@ struct at25_data {
#define AT25_SR_BP1 0x08
#define AT25_SR_WPEN 0x80 /* writeprotect enable */
+#define AT25_INSTR_A8 0x08 /* Address bit 8 in instruction */
#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,18 @@ at25_ee_read(
return count;
cp = command;
- *cp++ = AT25_READ;
+
+ /*
+ * Certain EEPROMS (like M95040 from ST) have a 512 Byte size
+ * but use only one address byte (A0 to A7) for addressing. For
+ * the extra address bit A8 bit 3 of the instruction byte is
+ * used. This instruction bit is threated as don't care for
+ * other AT25 like chips.
+ */
+ instr = AT25_READ;
+ if ((at25->addrlen == 1) && (offset >= 256))
+ instr |= AT25_INSTR_A8;
+ *cp++ = instr;
/* 8/16/24-bit address is written MSB first */
switch (at25->addrlen) {
@@ -167,14 +180,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 +197,18 @@ at25_ee_write(struct at25_data *at25, const char *buf, loff_t off,
break;
}
+ /*
+ * Certain EEPROMS (like M95040 from ST) have a 512 Byte size
+ * but use only one address byte (A0 to A7) for addressing. For
+ * the extra address bit A8 bit 3 of the instruction byte is
+ * used. This instruction bit is threated as don't care for
+ * other AT25 like chips.
+ */
+ instr = AT25_WRITE;
+ if ((at25->addrlen == 1) && (offset >= 256))
+ instr |= AT25_INSTR_A8;
+ *cp++ = instr;
+
/* 8/16/24-bit address is written MSB first */
switch (at25->addrlen) {
default: /* case 3 */
--
1.7.0.4
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Support M95040 SPI EEPROM
2012-03-21 15:24 [PATCH] Support M95040 SPI EEPROM Ivo Sieben
@ 2012-03-21 15:33 ` Ivo Sieben
2012-03-21 17:30 ` Chris Wright
1 sibling, 0 replies; 4+ messages in thread
From: Ivo Sieben @ 2012-03-21 15:33 UTC (permalink / raw)
To: Wolfram Sang, Jean Delvare, Kevin Hilman, Chris Wright; +Cc: linux-kernel
Hi,
> Updated the generic SPI EEPROM driver AT25 for support of address bit A8
> in the instruction byte. Certain EEPROMS (like M95040 from ST) have a 512
> Byte size but use only one address byte (A0 to A7) for addressing. For the
> extra address bit A8 bit 3 of the instruction byte is used. This instruction
> bit is threated as don't care for other AT25 like chips
>
> Signed-off-by: Ivo Sieben <meltedpianoman@gmail.com>
I cannot find a maintainer for the at25 driver.
Therefor I've send a CC to some people that made contributions to this driver.
I hope you can take a look at it.
Best regards,
Ivo Sieben
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Support M95040 SPI EEPROM
2012-03-21 15:24 [PATCH] Support M95040 SPI EEPROM Ivo Sieben
2012-03-21 15:33 ` Ivo Sieben
@ 2012-03-21 17:30 ` Chris Wright
2012-03-21 17:49 ` Wolfram Sang
1 sibling, 1 reply; 4+ messages in thread
From: Chris Wright @ 2012-03-21 17:30 UTC (permalink / raw)
To: Ivo Sieben
Cc: linux-kernel, Wolfram Sang, Jean Delvare, Kevin Hilman, Chris Wright
* Ivo Sieben (meltedpianoman@gmail.com) wrote:
> Updated the generic SPI EEPROM driver AT25 for support of address bit A8
> in the instruction byte. Certain EEPROMS (like M95040 from ST) have a 512
> Byte size but use only one address byte (A0 to A7) for addressing. For the
> extra address bit A8 bit 3 of the instruction byte is used. This instruction
> bit is threated as don't care for other AT25 like chips
The AT25 datasheet lists that bit in READ and PROGRAM(write) as don't
care, and the MV950x0 datasheet says just what you've said above (BTW,
it's "treated" not "threated"). How confident are you that this logic
will not cause problems for existing non-MV95040 chips? I'm unfamiliar
with this driver and SPI, so it's not entirely clear how addrlen is
known and size.
For example, random glance and I found a device that uses bit3 on READ
to implement a FAST_READ, however it's addrlen is 3 bytes.
> Signed-off-by: Ivo Sieben <meltedpianoman@gmail.com>
> ---
> drivers/misc/eeprom/at25.c | 31 ++++++++++++++++++++++++++++---
> 1 files changed, 28 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/misc/eeprom/at25.c b/drivers/misc/eeprom/at25.c
> index c627e41..907aecc 100644
> --- a/drivers/misc/eeprom/at25.c
> +++ b/drivers/misc/eeprom/at25.c
> @@ -50,6 +50,7 @@ struct at25_data {
> #define AT25_SR_BP1 0x08
> #define AT25_SR_WPEN 0x80 /* writeprotect enable */
>
> +#define AT25_INSTR_A8 0x08 /* Address bit 8 in instruction */
Perhaps a bit more detail here, Address bit 8 may be stored in bit 3 of
instruction byte for read or write...
> #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,18 @@ at25_ee_read(
> return count;
>
> cp = command;
> - *cp++ = AT25_READ;
> +
> + /*
> + * Certain EEPROMS (like M95040 from ST) have a 512 Byte size
> + * but use only one address byte (A0 to A7) for addressing. For
> + * the extra address bit A8 bit 3 of the instruction byte is
> + * used. This instruction bit is threated as don't care for
> + * other AT25 like chips.
> + */
> + instr = AT25_READ;
> + if ((at25->addrlen == 1) && (offset >= 256))
> + instr |= AT25_INSTR_A8;
> + *cp++ = instr;
I suppose this works because below offset is truncated to u8.
*cp++ = offset >> 0;
> /* 8/16/24-bit address is written MSB first */
> switch (at25->addrlen) {
> @@ -167,14 +180,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 +197,18 @@ at25_ee_write(struct at25_data *at25, const char *buf, loff_t off,
> break;
> }
>
> + /*
> + * Certain EEPROMS (like M95040 from ST) have a 512 Byte size
> + * but use only one address byte (A0 to A7) for addressing. For
> + * the extra address bit A8 bit 3 of the instruction byte is
> + * used. This instruction bit is threated as don't care for
> + * other AT25 like chips.
> + */
> + instr = AT25_WRITE;
> + if ((at25->addrlen == 1) && (offset >= 256))
> + instr |= AT25_INSTR_A8;
> + *cp++ = instr;
> +
This looks correct to me, AT25_WREN issued in bounce[0] now, then reuse
it to send AT25_WRITE, addr, data...
> /* 8/16/24-bit address is written MSB first */
> switch (at25->addrlen) {
> default: /* case 3 */
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Support M95040 SPI EEPROM
2012-03-21 17:30 ` Chris Wright
@ 2012-03-21 17:49 ` Wolfram Sang
0 siblings, 0 replies; 4+ messages in thread
From: Wolfram Sang @ 2012-03-21 17:49 UTC (permalink / raw)
To: Chris Wright; +Cc: Ivo Sieben, linux-kernel, Jean Delvare, Kevin Hilman
[-- Attachment #1: Type: text/plain, Size: 1220 bytes --]
On Wed, Mar 21, 2012 at 10:30:22AM -0700, Chris Wright wrote:
> * Ivo Sieben (meltedpianoman@gmail.com) wrote:
> > Updated the generic SPI EEPROM driver AT25 for support of address bit A8
> > in the instruction byte. Certain EEPROMS (like M95040 from ST) have a 512
> > Byte size but use only one address byte (A0 to A7) for addressing. For the
> > extra address bit A8 bit 3 of the instruction byte is used. This instruction
> > bit is threated as don't care for other AT25 like chips
>
> The AT25 datasheet lists that bit in READ and PROGRAM(write) as don't
> care, and the MV950x0 datasheet says just what you've said above (BTW,
> it's "treated" not "threated"). How confident are you that this logic
> will not cause problems for existing non-MV95040 chips?
I was thinking the same. We should not make this behaviour default, but
optional. My idea would be another flag, i.e. EE_INSTR_BIT3_IS_ADDR. I'd think
the code could then also easily be written in a way, that it gives 17 and 25
bit addresses for free.
Regards,
Wolfram
--
Pengutronix e.K. | Wolfram Sang |
Industrial Linux Solutions | http://www.pengutronix.de/ |
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-03-21 17:49 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-21 15:24 [PATCH] Support M95040 SPI EEPROM Ivo Sieben
2012-03-21 15:33 ` Ivo Sieben
2012-03-21 17:30 ` Chris Wright
2012-03-21 17:49 ` Wolfram Sang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®