Patchwork Add en29lv640b

login
register
about
Submitter Rudolf Marek
Date 2012-02-07 15:46:01
Message ID <4F314739.3040808@assembler.cz>
Download mbox | patch
Permalink /patch/3520/
State Accepted
Headers show

Comments

Rudolf Marek - 2012-02-07 15:46:01
Hi

Following patch adds the en29lv640b which needs special command sequences in 8 
bit mode. Also, 8 bit programming needs actually 16bit double byte program.

The chip is found on bifferboard.

Please check the patch and let me know.

Signed-off-by: Rudolf Marek <r.marek@assembler.cz>

Thanks
Rudolf
Rudolf Marek - 2012-03-20 14:28:49
Ping?

Thanks
Rudolf
Rudolf Marek - 2012-04-07 13:04:56
Ping2?

I wait for this before doing some announce of BifferBoard support in coreboot.

Thanks
Rudolf
Uwe Hermann - 2012-04-14 22:52:19
On Sat, Apr 07, 2012 at 03:04:56PM +0200, Rudolf Marek wrote:
> Ping2?

Thanks, committed in r1521 with a few minor cosmetic changes.

I also changed the voltage range to 2.7V-3.6V as per datasheet, I assume
the 4.5V-5.5V was a copy-paste left-over?

What about erase_en29lv640b()? That's not used externally, and should
probably be made static?


Cheers, Uwe.
Rudolf Marek - 2012-04-15 05:31:08
> Thanks, committed in r1521 with a few minor cosmetic changes.

Thanks!

> I also changed the voltage range to 2.7V-3.6V as per datasheet, I assume
> the 4.5V-5.5V was a copy-paste left-over?

Yes this is possible.

> What about erase_en29lv640b()? That's not used externally, and should
> probably be made static?

True. Perhaps this can be changed by someone with commit rights  ;)

Thanks again, I guess now it is time to announce the support for bifferboard 
with coreboot.

Thanks
Rudolf
Stefan Tauner - 2012-04-15 13:46:04
On Sun, 15 Apr 2012 00:52:19 +0200
Uwe Hermann <uwe@hermann-uwe.de> wrote:

> What about erase_en29lv640b()? That's not used externally, and should
> probably be made static?

it *is* used in flashchips.c for the respective chip of course...

Patch

Index: Makefile
===================================================================
--- Makefile	(revision 1486)
+++ Makefile	(working copy)
@@ -252,7 +252,7 @@ 
 CHIP_OBJS = jedec.o stm50flw0x0x.o w39.o w29ee011.o \
 	sst28sf040.o m29f400bt.o 82802ab.o pm49fl00x.o \
 	sst49lfxxxc.o sst_fwhub.o flashchips.o spi.o spi25.o sharplhf00l04.o \
-	a25.o at25.o opaque.o
+	a25.o at25.o opaque.o en29lv640b.o
 
 LIB_OBJS = layout.o
 
Index: en29lv640b.c
===================================================================
--- en29lv640b.c	(revision 0)
+++ en29lv640b.c	(revision 0)
@@ -0,0 +1,137 @@ 
+/*
+ * This file is part of the flashrom project.
+ *
+ * Copyright (C) 2012 Rudolf Marek <r.marek@assembler.cz>
+ * Copyright (C) 2000 Silicon Integrated System Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#include "flash.h"
+#include "chipdrivers.h"
+
+/* WARNING! 
+   This chip uses the standard JEDEC Addresses in 16-bit mode as word
+   addresses. In byte mode, 0xAAA has to be used instead of 0x555 and
+   0x555 instead of 0x2AA. Do *not* blindly replace with standard JEDEC
+   functions. */
+
+/* chunksize is 1 */
+int write_en29lv640b(struct flashctx *flash, uint8_t *src, unsigned int start,
+		    unsigned int len)
+{
+	int i;
+	chipaddr bios = flash->virtual_memory;
+	chipaddr dst = flash->virtual_memory + start;
+
+	for (i = 0; i < len; i+=2) {
+		chip_writeb(flash, 0xAA, bios + 0xAAA);
+		chip_writeb(flash, 0x55, bios + 0x555);
+		chip_writeb(flash, 0xA0, bios + 0xAAA);
+
+		/* transfer data from source to destination */
+		chip_writew(flash, (*src) | ((*(src + 1)) << 8 ), dst);
+		toggle_ready_jedec(flash, dst);
+#if 0
+		/* We only want to print something in the error case. */
+		msg_cerr("Value in the flash at address 0x%lx = %#x, want %#x\n",
+		     (dst - bios), chip_readb(flash, dst), *src);
+#endif
+		dst += 2;
+		src += 2;
+	}
+
+	/* FIXME: Ignore errors for now. */
+	return 0;
+}
+
+int probe_en29lv640b(struct flashctx *flash)
+{
+	chipaddr bios = flash->virtual_memory;
+	uint16_t id1, id2;
+
+	chip_writeb(flash, 0xAA, bios + 0xAAA);
+	chip_writeb(flash, 0x55, bios + 0x555);
+	chip_writeb(flash, 0x90, bios + 0xAAA);
+
+	programmer_delay(10);
+
+	id1 = chip_readb(flash, bios + 0x200);
+	id1 |= (chip_readb(flash, bios) << 8);
+
+	id2 = chip_readb(flash, bios + 0x02);
+
+	chip_writeb(flash, 0xF0, bios + 0xAAA);
+
+	programmer_delay(10);
+
+	msg_cdbg("%s: id1 0x%04x, id2 0x%04x\n", __func__, id1, id2);
+
+	if (id1 == flash->manufacture_id && id2 == flash->model_id)
+		return 1;
+
+	return 0;
+}
+
+int erase_en29lv640b(struct flashctx *flash)
+{
+	chipaddr bios = flash->virtual_memory;
+
+	chip_writeb(flash, 0xAA, bios + 0xAAA);
+	chip_writeb(flash, 0x55, bios + 0x555);
+	chip_writeb(flash, 0x80, bios + 0xAAA);
+
+	chip_writeb(flash, 0xAA, bios + 0xAAA);
+	chip_writeb(flash, 0x55, bios + 0x555);
+	chip_writeb(flash, 0x10, bios + 0xAAA);
+
+	programmer_delay(10);
+	toggle_ready_jedec(flash, bios);
+
+	/* FIXME: Check the status register for errors. */
+	return 0;
+}
+
+int block_erase_en29lv640b(struct flashctx *flash, unsigned int start,
+			  unsigned int len)
+{
+	chipaddr bios = flash->virtual_memory;
+	chipaddr dst = bios + start;
+
+	chip_writeb(flash, 0xAA, bios + 0xAAA);
+	chip_writeb(flash, 0x55, bios + 0x555);
+	chip_writeb(flash, 0x80, bios + 0xAAA);
+
+	chip_writeb(flash, 0xAA, bios + 0xAAA);
+	chip_writeb(flash, 0x55, bios + 0x555);
+	chip_writeb(flash, 0x30, dst);
+
+	programmer_delay(10);
+	toggle_ready_jedec(flash, bios);
+
+	/* FIXME: Check the status register for errors. */
+	return 0;
+}
+
+int block_erase_chip_en29lv640b(struct flashctx *flash, unsigned int address,
+			       unsigned int blocklen)
+{
+	if ((address != 0) || (blocklen != flash->total_size * 1024)) {
+		msg_cerr("%s called with incorrect arguments\n",
+			__func__);
+		return -1;
+	}
+	return erase_en29lv640b(flash);
+}
Index: flashchips.c
===================================================================
--- flashchips.c	(revision 1486)
+++ flashchips.c	(working copy)
@@ -3574,6 +3574,36 @@ 
 	},
 
 	{
+		.vendor		= "Eon",
+		.name		= "EN29LV640B",
+		.bustype	= BUS_PARALLEL,
+		.manufacture_id	= EON_ID,
+		.model_id	= EON_EN29LV640B,
+		.total_size	= 8192,
+		.page_size	= 8192,
+		.feature_bits	= 0,
+		.tested		= TEST_OK_PREW,
+		.probe		= probe_en29lv640b,
+		.probe_timing	= TIMING_ZERO,	/* Datasheet has no timing info specified */
+		.block_erasers	=
+		{
+			{
+				.eraseblocks = { 
+					{8 * 1024, 8},
+					{64 * 1024, 127},
+				},
+				.block_erase = block_erase_en29lv640b,
+			}, {
+				.eraseblocks = { {8 * 1024 * 1024, 1} },
+				.block_erase = block_erase_chip_en29lv640b,
+			},
+		},
+		.write		= write_en29lv640b,
+		.read		= read_memmapped,
+		.voltage	= {4500, 5500},
+	},
+
+	{
 		.vendor		= "Fujitsu",
 		.name		= "MBM29F004BC",
 		.bustype	= BUS_PARALLEL,
Index: flashchips.h
===================================================================
--- flashchips.h	(revision 1486)
+++ flashchips.h	(working copy)
@@ -253,6 +253,7 @@ 
 #define EON_EN29F040A		0x7F04
 #define EON_EN29LV010		0x7F6E
 #define EON_EN29LV040A		0x7F4F	/* EN29LV040(A) */
+#define EON_EN29LV640B		0xCB
 #define EON_EN29F002T		0x7F92	/* Same as EN29F002A */
 #define EON_EN29F002B		0x7F97	/* Same as EN29F002AN */
 
Index: chipdrivers.h
===================================================================
--- chipdrivers.h	(revision 1486)
+++ chipdrivers.h	(working copy)
@@ -153,4 +153,10 @@ 
 int erase_sector_stm50flw0x0x(struct flashctx *flash, unsigned int block, unsigned int blocksize);
 int unlock_stm50flw0x0x(struct flashctx *flash);
 
+/* en29lv640b.c */
+int probe_en29lv640b(struct flashctx *flash);
+int block_erase_en29lv640b(struct flashctx *flash, unsigned int start, unsigned int len);
+int block_erase_chip_en29lv640b(struct flashctx *flash, unsigned int start, unsigned int len);
+int write_en29lv640b(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
+
 #endif /* !__CHIPDRIVERS_H__ */