[PATCH v3 1/2] mtd: Add a common JEDEC flash device table

Tony Prisk linux at prisktech.co.nz
Wed Jan 23 03:01:07 EST 2013


This patch adds a common JEDEC flash device table which can be
expanded on as more features are required.

A simple match function is also included to query the table for
a match based on the JEDEC id.

Signed-off-by: Tony Prisk <linux at prisktech.co.nz>
---
 drivers/mtd/devices/flash_jedec.c |   96 +++++++++++++++++++++++++++++++++++++
 drivers/mtd/devices/flash_jedec.h |   30 ++++++++++++
 2 files changed, 126 insertions(+)
 create mode 100644 drivers/mtd/devices/flash_jedec.c
 create mode 100644 drivers/mtd/devices/flash_jedec.h

diff --git a/drivers/mtd/devices/flash_jedec.c b/drivers/mtd/devices/flash_jedec.c
new file mode 100644
index 0000000..c0b2272
--- /dev/null
+++ b/drivers/mtd/devices/flash_jedec.c
@@ -0,0 +1,96 @@
+/*
+ * Copyright Tony Prisk <linux at prisktech.co.nz>
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <linux/bug.h>
+#include <linux/err.h>
+#include <linux/kernel.h>
+#include <linux/types.h>
+
+#include "flash_jedec.h"
+
+/*
+ * Device Manufacturer IDs
+ * Please keep sorted by manufacturer ID
+ */
+#define MFR_SPANSION		0X01
+#define MFR_EON			0X1C
+#define MFR_ATMEL		0X1F
+#define MFR_MICRON		0X20	/* Also Numonyx & STM */
+#define MFR_INTEL		0x89
+#define MFR_FUDAN		0XA1
+#define MFR_SST			0XBF
+#define MFR_MXIC		0XC2
+#define MFR_WINBOND		0XEF
+
+#define _ID(m, d)	((m << 16) | d)
+
+/*
+ * Flash device information
+ * Please keep sorted by manufacturer id, then device id
+ */
+static struct flash_device_info flash_devices[] = {
+	/* Spansion */
+	{ "s25fl016", _ID(MFR_SPANSION, 0x0214), 2048 },
+	{ "s25fl064", _ID(MFR_SPANSION, 0x0216), 8192 },
+	/* EON */
+	{ "en25p16", _ID(MFR_EON, 0x2015), 2048 },
+	{ "en25p64", _ID(MFR_EON, 0x2017), 8192 },
+	{ "en25f40", _ID(MFR_EON, 0x3113),  512 },
+	{ "en25f16", _ID(MFR_EON, 0x3115), 2048 },
+	/* ATMEL */
+	{ "at25df041a", _ID(MFR_ATMEL, 0x4401), 512 },
+	/* Micron, STM & Numonyx */
+	{ "stm25p16", _ID(MFR_MICRON, 0x2015), 2048 },
+	{ "stm25p64", _ID(MFR_MICRON, 0x2017), 8192 },
+	/* Fudan */
+	{ "fm25f04", _ID(MFR_FUDAN, 0x3113), 512 },
+	/* SST */
+	{ "sst25vf016b", _ID(MFR_SST, 0x2541), 2048 },
+	/* Macronix - MXIC */
+	{ "mx25l512",   _ID(MFR_MXIC, 0x2010),    64 },
+	{ "mx25l4005",  _ID(MFR_MXIC, 0x2013),   512 },
+	{ "mx25l1605",  _ID(MFR_MXIC, 0x2015),  2048 },
+	{ "mx25l3205",  _ID(MFR_MXIC, 0x2016),  4096 },
+	{ "mx25l6405",  _ID(MFR_MXIC, 0x2017),  8192 },
+	{ "mx25l12805", _ID(MFR_MXIC, 0x2018), 16384 },
+	{ "mx25l1635",  _ID(MFR_MXIC, 0x2415),  2048 },
+	{ "mx25l3235",  _ID(MFR_MXIC, 0x5E16),  4096 },
+	/* Winbond */
+	{ "w25x40", _ID(MFR_WINBOND, 0x3013),   512 },
+	{ "w25x16", _ID(MFR_WINBOND, 0x3015),  2048 },
+	{ "w25x32", _ID(MFR_WINBOND, 0x3016),  4096 },
+	{ "w25x64", _ID(MFR_WINBOND, 0x3017),  8192 },
+};
+
+/*
+ * jedec_match_device - match a jedec id against the flash_devices table
+ * @jedecid: JEDEC formatted id to match
+ *	bits 16..24: manufacturer id
+ *	bits  0..15: device id
+ * Returns a valid flash_device_info* or ERR_PTR(-ENODEV) if an entry is
+ * not found
+ */
+struct flash_device_info *jedec_match_device(u32 jedec_id)
+{
+	int i;
+	for (i = 0; i < ARRAY_SIZE(flash_devices); i++)
+		if (flash_devices[i].jedec_id == jedec_id)
+			return &flash_devices[i];
+
+	return ERR_PTR(-ENODEV);
+}
diff --git a/drivers/mtd/devices/flash_jedec.h b/drivers/mtd/devices/flash_jedec.h
new file mode 100644
index 0000000..27b978a
--- /dev/null
+++ b/drivers/mtd/devices/flash_jedec.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright Tony Prisk <linux at prisktech.co.nz>
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifndef __MTD_FLASH_JEDEC
+#define __MTD_FLASH_JEDEC
+
+struct flash_device_info {
+	const char	*name;
+	u32		jedec_id;
+	u32		size_kb;
+};
+
+extern struct flash_device_info *jedec_match_device(u32 jedec_id);
+
+#endif
-- 
1.7.9.5




More information about the linux-mtd mailing list