Skip to contentSkip to conversation

Add a map_sram driver to drivers/chips/

PATCH In review Ian Campbell 2 participants 2 messages Nov 12, 2002 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add a map_sram driver to drivers/chips/

Howdy,

The attached patch adds "map_sram" as a second chip driver in drivers/mtd/chips/map_ram.c. The two are basically identical apart from the use of the MTD_VOLATILE flag.

I have another patch which makes an entirely separate map_sram.c, but there was so much code duplication with map_ram.c I didn't see the point. I guess if you are using modules then you will need 'alias map_sram map_ram' in /etc/modules.conf or something to get autoloading to work.

The patch also includes a previous patch to set the state to MTD_ERASE_DONE in mapram_erase. This is needed to mount a JFFS2 f/s on an SRAM or RAM device.

Cheers,
Ian.

Signature · 18 lines
Ian Campbell
Design Engineer

Arcom Control Systems Ltd,
Clifton Road,
Cambridge CB1 7EA
United Kingdom

Tel: +44 (0)1223 403465
E-Mail: [email protected]
Web: http://www.arcomcontrols.com


________________________________________________________________________
This email has been scanned for all viruses by the MessageLabs SkyScan
service. For more information on a proactive anti-virus service working
around the clock, around the globe, visit http://www.messagelabs.com
________________________________________________________________________
include/linux/mtd/mtd.h +1 -0
diff -urN kernel-2.4.18.orig/include/linux/mtd/mtd.h kernel-2.4.18/include/linux/mtd/mtd.h
@@ -39,5 +39,6 @@
 #define MTD_NORFLASH		3
 #define MTD_NANDFLASH		4
 #define MTD_PEROM		5
+#define MTD_SRAM		6
 #define MTD_OTHER		14
 #define MTD_UNKNOWN		15
drivers/mtd/chips/Config.in +1 -1
diff -urN kernel-2.4.18.orig/drivers/mtd/chips/Config.in kernel-2.4.18/drivers/mtd/chips/Config.in
@@ -44,7 +44,7 @@
 dep_tristate '  Support for Intel/Sharp flash chips' CONFIG_MTD_CFI_INTELEXT $CONFIG_MTD_GEN_PROBE
 dep_tristate '  Support for AMD/Fujitsu flash chips' CONFIG_MTD_CFI_AMDSTD $CONFIG_MTD_GEN_PROBE
 
-dep_tristate '  Support for RAM chips in bus mapping' CONFIG_MTD_RAM $CONFIG_MTD
+dep_tristate '  Support for RAM/SRAM chips in bus mapping' CONFIG_MTD_RAM $CONFIG_MTD
 dep_tristate '  Support for ROM chips in bus mapping' CONFIG_MTD_ROM $CONFIG_MTD
 dep_tristate '  Support for absent chips in bus mapping' CONFIG_MTD_ABSENT $CONFIG_MTD
 
drivers/mtd/chips/map_ram.c +38 -0
diff -urN kernel-2.4.18.orig/drivers/mtd/chips/map_ram.c kernel-2.4.18/drivers/mtd/chips/map_ram.c
@@ -20,6 +20,7 @@
 static int mapram_erase (struct mtd_info *, struct erase_info *);
 static void mapram_nop (struct mtd_info *);
 static struct mtd_info *map_ram_probe(struct map_info *map);
+static struct mtd_info *map_sram_probe(struct map_info *map);
 
 
 static struct mtd_chip_driver mapram_chipdrv = {
@@ -27,6 +28,11 @@
 	name: "map_ram",
 	module: THIS_MODULE
 };
+static struct mtd_chip_driver mapsram_chipdrv = {
+	probe: map_sram_probe,
+	name: "map_sram",
+	module: THIS_MODULE
+};
 
 static struct mtd_info *map_ram_probe(struct map_info *map)
 {
@@ -78,6 +84,34 @@
 	return mtd;
 }
 
+static struct mtd_info *map_sram_probe(struct map_info *map)
+{
+	struct mtd_info *mtd;
+
+	mtd = kmalloc(sizeof(*mtd), GFP_KERNEL);
+	if (!mtd)
+		return NULL;
+
+	memset(mtd, 0, sizeof(*mtd));
+
+	map->fldrv = &mapram_chipdrv;
+	mtd->priv = map;
+	mtd->name = map->name;
+	mtd->type = MTD_SRAM;
+	mtd->size = map->size;
+	mtd->erase = mapram_erase;
+	mtd->read = mapram_read;
+	mtd->write = mapram_write;
+	mtd->sync = mapram_nop;
+	mtd->flags = MTD_CAP_RAM;
+
+	mtd->erasesize = PAGE_SIZE;
+ 	while(mtd->size & (mtd->erasesize - 1))
+		mtd->erasesize >>= 1;
+
+	MOD_INC_USE_COUNT;
+	return mtd;
+}
 
 static int mapram_read (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
 {
@@ -107,6 +141,8 @@
 	for (i=0; i<instr->len; i++)
 		map->write8(map, 0xFF, instr->addr + i);
 
+	instr->state = MTD_ERASE_DONE;
+
 	if (instr->callback)
 		instr->callback(instr);
 
@@ -121,12 +157,14 @@
 int __init map_ram_init(void)
 {
 	register_mtd_chip_driver(&mapram_chipdrv);
+	register_mtd_chip_driver(&mapsram_chipdrv);
 	return 0;
 }
 
 static void __exit map_ram_exit(void)
 {
 	unregister_mtd_chip_driver(&mapram_chipdrv);
+	unregister_mtd_chip_driver(&mapsram_chipdrv);
 }
 
 module_init(map_ram_init);
#1 lore raw
Quoted 4 lines · Ian Campbell

The attached patch adds "map_sram" as a second chip driver in drivers/mtd/chips/map_ram.c. The two are basically identical apart from the use of the MTD_VOLATILE flag.

Slightly OT.

Have you tried the slram driver? I have always used that one to access plain old memory and was very happy. And now you make me wonder, if there is another way that might even be better.

Jörn

Signature · 2 lines
A victorious army first wins and then seeks battle.
-- Sun Tzu