patch-2.4.0-test12 linux/drivers/mtd/pnc2000.c

Next file: linux/drivers/mtd/rpxlite.c
Previous file: linux/drivers/mtd/pmc551.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.4.0-test11/linux/drivers/mtd/pnc2000.c linux/drivers/mtd/pnc2000.c
@@ -5,7 +5,7 @@
  *
  * This code is GPL
  *
- * $Id: pnc2000.c,v 1.1 2000/07/12 09:34:32 dwmw2 Exp $
+ * $Id: pnc2000.c,v 1.4 2000/11/27 08:50:22 dwmw2 Exp $
  */
 
 #include <linux/module.h>
@@ -14,6 +14,7 @@
 
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/map.h>
+#include <linux/mtd/partitions.h>
 
 
 #define WINDOW_ADDR 0xbf000000
@@ -64,136 +65,60 @@
 }
 
 struct map_info pnc_map = {
-  "PNC-2000",
-  WINDOW_SIZE,
-  4,
-  pnc_read8,
-  pnc_read16,
-  pnc_read32,
-  pnc_copy_from,
-  pnc_write8,
-  pnc_write16,
-  pnc_write32,
-  pnc_copy_to,
-  0,
-  0
+	name: "PNC-2000",
+	size: WINDOW_SIZE,
+	buswidth: 4,
+	read8: pnc_read8,
+	read16: pnc_read16,
+	read32: pnc_read32,
+	copy_from: pnc_copy_from,
+	write8: pnc_write8,
+	write16: pnc_write16,
+	write32: pnc_write32,
+	copy_to: pnc_copy_to
 };
 
 
 /*
  * MTD 'PARTITIONING' STUFF 
  */
-
-/* 
- * This is the _real_ MTD device for which all the others are just
- * auto-relocating aliases.
- */
-static struct mtd_info *mymtd;
-
-/* 
- * MTD methods which simply translate the effective address and pass through
- * to the _real_ device.
- */
-
-static int pnc_mtd_read (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
-{
-	return mymtd->read(mymtd, from + (unsigned long)mtd->priv, len, retlen, buf);
-}
-
-static int pnc_mtd_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf)
-{
-	return mymtd->write(mymtd, to + (unsigned long)mtd->priv, len, retlen, buf);
-}
-
-static int pnc_mtd_erase (struct mtd_info *mtd, struct erase_info *instr)
-{
-	instr->addr += (unsigned long)mtd->priv;
-	return mymtd->erase(mymtd, instr);
-}
-
-static void pnc_mtd_sync (struct mtd_info *mtd)
-{
-	mymtd->sync(mymtd);
-}
-
-static int pnc_mtd_suspend (struct mtd_info *mtd)
-{
-	return mymtd->suspend(mymtd);
-}
-
-static void pnc_mtd_resume (struct mtd_info *mtd)
-{
-	mymtd->resume(mymtd);
-}
-
-
-static struct mtd_info pnc_mtds[3] = {  /* boot, kernel, fs */
+static struct mtd_partition pnc_partitions[3] = {
 	{
-		type: MTD_NORFLASH,
-		flags: MTD_CAP_NORFLASH,
-		size: 0x20000,
-		erasesize: 0x20000,
 		name: "PNC-2000 boot firmware",
-		module: THIS_MODULE,
-		erase: pnc_mtd_erase,
-		read: pnc_mtd_read,
-		write: pnc_mtd_write,
-		suspend: pnc_mtd_suspend,
-		resume: pnc_mtd_resume,
-		sync: pnc_mtd_sync,
-		priv: (void *)0
+		size: 0x20000,
+		offset: 0
 	},
 	{
-		type: MTD_NORFLASH,
-		flags: MTD_CAP_NORFLASH,
-		size: 0x1a0000,
-		erasesize: 0x20000,
 		name: "PNC-2000 kernel",
-		module: THIS_MODULE,
-		erase: pnc_mtd_erase,
-		read: pnc_mtd_read,
-		write: pnc_mtd_write,
-		suspend: pnc_mtd_suspend,
-		resume: pnc_mtd_resume,
-		sync: pnc_mtd_sync,
-		priv: (void *)0x20000
+		size: 0x1a0000,
+		offset: 0x20000
 	},
 	{
-		type: MTD_NORFLASH,
-		flags: MTD_CAP_NORFLASH,
-		size: 0x240000,
-		erasesize: 0x20000,
 		name: "PNC-2000 filesystem",
-		module: THIS_MODULE,
-		erase: pnc_mtd_erase,
-		read: pnc_mtd_read,
-		write: pnc_mtd_write,
-		suspend: pnc_mtd_suspend,
-		resume: pnc_mtd_resume,
-		sync: pnc_mtd_sync,
-		priv: (void *)0x1c0000
+		size: 0x240000,
+		offset: 0x1c0000
 	}
 };
 
-#if LINUX_VERSION_CODE < 0x20300
-#ifdef MODULE
+/* 
+ * This is the master MTD device for which all the others are just
+ * auto-relocating aliases.
+ */
+static struct mtd_info *mymtd;
+
+#if LINUX_VERSION_CODE < 0x20212 && defined(MODULE)
 #define init_pnc init_module
 #define cleanup_pnc cleanup_module
 #endif
-#endif
 
 int __init init_pnc(void)
 {
-       	printk(KERN_NOTICE "Photron PNC-2000 flash mapping: %x at %x\n", WINDOW_SIZE, WINDOW_ADDR);
+	printk(KERN_NOTICE "Photron PNC-2000 flash mapping: %x at %x\n", WINDOW_SIZE, WINDOW_ADDR);
 
 	mymtd = do_cfi_probe(&pnc_map);
 	if (mymtd) {
 		mymtd->module = THIS_MODULE;
-		
-		add_mtd_device(&pnc_mtds[0]); /* boot */
-		add_mtd_device(&pnc_mtds[1]); /* kernel */
-		add_mtd_device(&pnc_mtds[2]); /* file system */
-		return 0;
+		return add_mtd_partitions(mymtd, pnc_partitions, 3);
 	}
 
 	return -ENXIO;
@@ -202,9 +127,10 @@
 static void __exit cleanup_pnc(void)
 {
 	if (mymtd) {
-		del_mtd_device(&pnc_mtds[2]);
-		del_mtd_device(&pnc_mtds[1]);
-		del_mtd_device(&pnc_mtds[0]);
+		del_mtd_partitions(mymtd);
 		map_destroy(mymtd);
 	}
 }
+
+module_init(init_pnc);
+module_exit(cleanup_pnc);

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)