Add support for the PMC Pm29F002T/B chips

I sucessfully tested all operations on a Pm29F002T chip. The Pm29F002B is
untested but I assume it should also work.

Corresponding to flashrom svn r590.

Signed-off-by: Uwe Hermann <uwe@hermann-uwe.de>
Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
diff --git a/Makefile b/Makefile
index 567c42c..54d662d 100644
--- a/Makefile
+++ b/Makefile
@@ -43,7 +43,7 @@
 LIBS += -lpci -lz
 
 OBJS = chipset_enable.o board_enable.o udelay.o jedec.o stm50flw0x0x.o \
-	sst28sf040.o am29f040b.o mx29f002.o m29f400bt.o \
+	sst28sf040.o am29f040b.o mx29f002.o m29f400bt.o pm29f002.c \
 	w49f002u.o 82802ab.o pm49fl00x.o sst49lf040.o en29f002a.o \
 	sst49lfxxxc.o sst_fwhub.o layout.o cbtable.o flashchips.o physmap.o \
 	flashrom.o w39v080fa.o sharplhf00l04.o w29ee011.o spi.o it87spi.o \
diff --git a/flash.h b/flash.h
index 1b798af..ac0a837 100644
--- a/flash.h
+++ b/flash.h
@@ -453,6 +453,8 @@
 #define PMC_25LV040		0x7E
 #define PMC_25LV080B		0x13
 #define PMC_25LV016B		0x14
+#define PMC_29F002T		0x1D
+#define PMC_29F002B		0x2D
 #define PMC_39LV512		0x1B
 #define PMC_39F010		0x1C	/* also Pm39LV010 */
 #define PMC_39LV020		0x3D
@@ -783,6 +785,9 @@
 int erase_29f040b(struct flashchip *flash);
 int write_29f040b(struct flashchip *flash, uint8_t *buf);
 
+/* pm29f002.c */
+int write_pm29f002(struct flashchip *flash, uint8_t *buf);
+
 /* en29f002a.c */
 int probe_en29f002a(struct flashchip *flash);
 int erase_en29f002a(struct flashchip *flash);
diff --git a/flashchips.c b/flashchips.c
index ccd7a21..c668a5b 100644
--- a/flashchips.c
+++ b/flashchips.c
@@ -1514,6 +1514,38 @@
 
 	{
 		.vendor		= "PMC",
+		.name		= "Pm29F0002T",
+		.bustype	= CHIP_BUSTYPE_PARALLEL,
+		.manufacture_id	= PMC_ID_NOPREFIX,
+		.model_id	= PMC_29F002T,
+		.total_size	= 256,
+		.page_size	= 8192,
+		.tested		= TEST_OK_PREW,
+		.probe		= probe_29f040b,
+		.probe_timing	= TIMING_FIXME, 
+		.erase		= erase_29f040b,
+		.write		= write_pm29f002,
+		.read		= read_memmapped,
+	},
+
+	{
+		.vendor		= "PMC",
+		.name		= "Pm29F0002B",
+		.bustype	= CHIP_BUSTYPE_PARALLEL,
+		.manufacture_id	= PMC_ID_NOPREFIX,
+		.model_id	= PMC_29F002B,
+		.total_size	= 256,
+		.page_size	= 8192,
+		.tested		= TEST_UNTESTED,
+		.probe		= probe_29f040b,
+		.probe_timing	= TIMING_FIXME, 
+		.erase		= erase_29f040b,
+		.write		= write_pm29f002,
+		.read		= read_memmapped,
+	},
+
+	{
+		.vendor		= "PMC",
 		.name		= "Pm39LV010",
 		.bustype	= CHIP_BUSTYPE_NONSPI,
 		.manufacture_id	= PMC_ID_NOPREFIX,
diff --git a/pm29f002.c b/pm29f002.c
new file mode 100644
index 0000000..374582b
--- /dev/null
+++ b/pm29f002.c
@@ -0,0 +1,53 @@
+/*
+ * This file is part of the flashrom project.
+ *
+ * Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
+ *
+ * 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"
+
+int write_pm29f002(struct flashchip *flash, uint8_t *buf)
+{
+	int i, total_size = flash->total_size * 1024;
+	chipaddr bios = flash->virtual_memory;
+	chipaddr dst = bios;
+
+	/* Pm29F002T/B use the same erase method... */
+	erase_29f040b(flash);
+
+	printf("Programming page: ");
+	for (i = 0; i < total_size; i++) {
+		if ((i & 0xfff) == 0)
+			printf("address: 0x%08lx", (unsigned long)i);
+
+		/* Pm29F002T/B only support byte-wise programming. */
+		chip_writeb(0xAA, bios + 0x555);
+		chip_writeb(0x55, bios + 0x2AA);
+		chip_writeb(0xA0, bios + 0x555);
+		chip_writeb(*buf++, dst++);
+
+		/* Wait for Toggle bit ready. */
+		toggle_ready_jedec(dst);
+
+		if ((i & 0xfff) == 0)
+			printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
+	}
+
+	printf("\n");
+
+	return 0;
+}