public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* FW: Patch: adding mtd support for new machine
@ 2001-11-01 13:58 Clive Davies
  2001-11-01 14:12 ` David Woodhouse
  0 siblings, 1 reply; 2+ messages in thread
From: Clive Davies @ 2001-11-01 13:58 UTC (permalink / raw)
  To: 'linux-mtd@lists.infradead.org'

[-- Attachment #1: Type: text/plain, Size: 920 bytes --]

I sent the follwing message to mtd@infradead.org a couple of days ago, but
I've had no response. Is that the same list as
linux-mtd@lists.infradead.org? Can anyone tell me why I've had no reply?

Clive

--------------------------------------------------

I submitted a patch to Russell King to add mtd support for a new mchine type
to his arm linux source tree. He sent me here to discuss:

>- lack of $id$ in the new map driver
>- missing help entry for the new CONFIG_* symbol
>- concerns about overloading the read_oob

The first one I don't really understand, the second I can deal with myself.
For the third, I've used the oob interface to access the protection data in
Intel flash devices. This seemed to me to fit ok as its essentially data
that isn't in the main flash array. 

The patch (against 2.4.13-ac4-rmk1) is attached, any comments would be
gratefully received.

Please cc any replies to me.

TIA
Clive


[-- Attachment #2: mtd_patch --]
[-- Type: application/octet-stream, Size: 10820 bytes --]

diff -purN linux_2.4.13/drivers/mtd/chips/cfi_cmdset_0001.c linux/drivers/mtd/chips/cfi_cmdset_0001.c
--- linux_2.4.13/drivers/mtd/chips/cfi_cmdset_0001.c	Thu Oct  4 23:14:59 2001
+++ linux/drivers/mtd/chips/cfi_cmdset_0001.c	Tue Oct 30 10:48:59 2001
@@ -31,6 +31,7 @@
 #include <linux/mtd/compatmac.h>
 
 static int cfi_intelext_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
+static int cfi_intelext_read_OTP (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
 static int cfi_intelext_write_words(struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
 static int cfi_intelext_write_buffers(struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
 static int cfi_intelext_erase_varsize(struct mtd_info *, struct erase_info *);
@@ -151,7 +152,23 @@ struct mtd_info *cfi_cmdset_0001(struct 
 		/* Do some byteswapping if necessary */
 		extp->FeatureSupport = cfi32_to_cpu(extp->FeatureSupport);
 		extp->BlkStatusRegMask = cfi32_to_cpu(extp->BlkStatusRegMask);
+		extp->OTPAddr = cfi32_to_cpu(extp->OTPAddr);
 		
+		
+		/* Read the OTP area from flash */
+		if(extp->NumProtectionFields){
+			cfi_send_gen_cmd(0x90, 0x55, base, map, cfi, cfi->device_type, NULL);
+			cfi->OTPData=kmalloc((1<<extp->FactOTPSize)+(1<<extp->UserOTPSize),GFP_KERNEL);
+			if(!cfi->OTPData){
+				printk(KERN_ERR "Failed to allocate memory\n");
+				return 0;
+			}
+			for (i=0; i<((1<<extp->FactOTPSize)+(1<<extp->UserOTPSize));i++){
+				cfi->OTPData[i]=
+					map->read8(map,(base+(extp->OTPAddr*ofs_factor)+i));
+			}
+		}
+			
 #ifdef DEBUG_CFI_FEATURES
 		/* Tell the user about it in lots of lovely detail */
 		cfi_tell_features(extp);
@@ -247,6 +264,7 @@ static struct mtd_info *cfi_intelext_set
 		//printk(KERN_INFO "Using word write method\n" );
 		mtd->write = cfi_intelext_write_words;
 	}
+	mtd->read_oob = cfi_intelext_read_OTP;
 	mtd->sync = cfi_intelext_sync;
 	mtd->lock = cfi_intelext_lock;
 	mtd->unlock = cfi_intelext_unlock;
@@ -432,6 +450,30 @@ static int cfi_intelext_read (struct mtd
 	}
 	return ret;
 }
+
+static int cfi_intelext_read_OTP (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
+{
+	struct map_info *map = mtd->priv;
+	struct cfi_private *cfi = map->fldrv_priv;
+	struct cfi_pri_intelext *extp=cfi->cmdset_priv;
+	unsigned char* data=cfi->OTPData+from;
+	int   count=len;
+	
+	while(count){
+		if(data>=cfi->OTPData + 
+		   (1<<extp->FactOTPSize)+(1<<extp->UserOTPSize)){
+		   return len-count;
+		}
+		*buf=*data;
+		buf++;		
+		data++;
+		count--;	     
+	}
+	return len-count;
+}
+	
+	
+
 
 static int do_write_oneword(struct map_info *map, struct flchip *chip, unsigned long adr, __u32 datum)
 {
diff -purN linux_2.4.13/drivers/mtd/maps/Config.in linux/drivers/mtd/maps/Config.in
--- linux_2.4.13/drivers/mtd/maps/Config.in	Mon Oct 29 15:47:07 2001
+++ linux/drivers/mtd/maps/Config.in	Wed Oct 24 10:17:47 2001
@@ -57,6 +57,7 @@ if [ "$CONFIG_ARM" = "y" ]; then
    dep_tristate '  CFI Flash device mapped on StrongARM SA11x0' CONFIG_MTD_SA1100 $CONFIG_MTD_CFI $CONFIG_ARCH_SA1100 $CONFIG_MTD_PARTITIONS
    dep_tristate '  CFI Flash device mapped on DC21285 Footbridge' CONFIG_MTD_DC21285 $CONFIG_MTD_CFI $CONFIG_ARCH_FOOTBRIDGE $CONFIG_MTD_PARTITIONS
    dep_tristate '  CFI Flash device mapped on the XScale IQ80310 board' CONFIG_MTD_IQ80310 $CONFIG_MTD_CFI $CONFIG_ARCH_IQ80310
+   dep_tristate '  CFI Flash device mapped on Epxa10db' CONFIG_MTD_EPXA10DB $CONFIG_MTD_CFI  $CONFIG_MTD_PARTITIONS 
 fi
 
 # This needs CFI or JEDEC, depending on the cards found.
diff -purN linux_2.4.13/drivers/mtd/maps/Makefile linux/drivers/mtd/maps/Makefile
--- linux_2.4.13/drivers/mtd/maps/Makefile	Mon Oct 29 15:47:07 2001
+++ linux/drivers/mtd/maps/Makefile	Wed Oct 24 10:17:47 2001
@@ -31,6 +31,7 @@ obj-$(CONFIG_MTD_SUN_UFLASH)    += sun_u
 obj-$(CONFIG_MTD_VMAX)		+= vmax301.o
 obj-$(CONFIG_MTD_DBOX2)		+= dbox2-flash.o
 obj-$(CONFIG_MTD_OCELOT)	+= ocelot.o
+obj-$(CONFIG_MTD_EPXA10DB)	+= epxa10db-flash.o
 obj-$(CONFIG_MTD_SOLUTIONENGINE)+= solutionengine.o
 obj-$(CONFIG_MTD_PCI)		+= pci.o
 
diff -purN linux_2.4.13/drivers/mtd/maps/epxa10db-flash.c linux/drivers/mtd/maps/epxa10db-flash.c
--- linux_2.4.13/drivers/mtd/maps/epxa10db-flash.c	Thu Jan  1 01:00:00 1970
+++ linux/drivers/mtd/maps/epxa10db-flash.c	Tue Oct 30 11:04:39 2001
@@ -0,0 +1,216 @@
+/*
+ * Flash memory access on EPXA based devices
+ *
+ * (C) 2000 Nicolas Pitre <nico@cam.org>
+ *  Copyright (C) 2001 Altera 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <linux/config.h>
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/kernel.h>
+
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/map.h>
+#include <linux/mtd/partitions.h>
+
+#include <asm/hardware.h>
+
+
+MODULE_AUTHOR("Clive Davies");
+MODULE_DESCRIPTION("Altera epxa10db mtd flash map");
+MODULE_LICENSE("GPL");
+
+static __u8 epxa10db_read8(struct map_info *map, unsigned long ofs)
+{
+	return *(__u8 *)(FLASH_VADDR(EXC_EBI_BLOCK0_BASE + ofs));
+}
+
+static __u16 epxa10db_read16(struct map_info *map, unsigned long ofs)
+{
+	return *(__u16 *)(FLASH_VADDR(EXC_EBI_BLOCK0_BASE + ofs));
+}
+
+static __u32 epxa10db_read32(struct map_info *map, unsigned long ofs)
+{
+	return *(__u32 *)(FLASH_VADDR(EXC_EBI_BLOCK0_BASE + ofs));
+}
+
+static void epxa10db_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
+{
+	memcpy(to, (void *)(FLASH_VADDR(EXC_EBI_BLOCK0_BASE + from)), len);
+}
+
+static void epxa10db_write8(struct map_info *map, __u8 d, unsigned long adr)
+{
+	*(__u8 *)(FLASH_VADDR(EXC_EBI_BLOCK0_BASE + adr)) = d;
+}
+
+static void epxa10db_write16(struct map_info *map, __u16 d, unsigned long adr)
+{
+	*(__u16 *)(FLASH_VADDR(EXC_EBI_BLOCK0_BASE + adr)) = d;
+}
+
+static void epxa10db_write32(struct map_info *map, __u32 d, unsigned long adr)
+{
+	*(__u32 *)(FLASH_VADDR(EXC_EBI_BLOCK0_BASE + adr)) = d;
+}
+
+static void epxa10db_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
+{
+	memcpy((void *)FLASH_VADDR(EXC_EBI_BLOCK0_BASE + to), from, len);
+}
+
+
+
+static struct map_info epxa10db_map = {
+	name:		"EPXA10DB flash",
+	read8:		epxa10db_read8,
+	read16:		epxa10db_read16,
+	read32:		epxa10db_read32,
+	copy_from:	epxa10db_copy_from,
+	write8:		epxa10db_write8,
+	write16:	epxa10db_write16,
+	write32:	epxa10db_write32,
+	copy_to:	epxa10db_copy_to
+};
+
+
+
+
+
+int fixup_epxa10db_partitions(struct mtd_info *master, struct mtd_partition **pparts);
+
+static struct mtd_partition *parsed_parts;
+static struct mtd_info *mymtd;
+
+int __init epxa10db_mtd_init(void)
+{
+	struct mtd_partition *parts;
+	int nb_parts = 0;
+	int parsed_nr_parts = 0;
+	char *part_type;
+	int i;
+	const char* master_name="master";
+	
+	epxa10db_map.buswidth =  2;
+	epxa10db_map.size = 0x01000000;
+	printk(KERN_NOTICE "EPXA10DB flash: probing %d-bit flash bus\n", epxa10db_map.buswidth*8);
+	mymtd = do_map_probe("cfi_probe", &epxa10db_map);
+	if (!mymtd)
+		return -ENXIO;
+	mymtd->module = THIS_MODULE;
+
+
+
+	/*
+	 * Dynamic partition selection stuff (might override the static ones)
+	 */
+	if (parsed_nr_parts == 0) {
+		int ret = fixup_epxa10db_partitions(mymtd, &parsed_parts);
+		if (ret > 0) {
+			part_type = "Compaq bootldr";
+			parsed_nr_parts = ret;
+		}
+	}
+
+	if (parsed_nr_parts > 0) {
+		parts = parsed_parts;
+		nb_parts = parsed_nr_parts;
+	}
+
+	if (nb_parts == 0) {
+		printk(KERN_NOTICE "EPXA10DB flash: no partition info available, registering whole flash at once\n");
+		add_mtd_device(mymtd);
+	} else {
+		printk(KERN_NOTICE "Using %s partition definition\n", part_type);
+		add_mtd_partitions(mymtd, parts, nb_parts);
+	}
+	
+        /* unlock the flash device */
+
+	for (i=0; i<mymtd->numeraseregions;i++){
+		int j;
+		for(j=0;j<mymtd->eraseregions[i].numblocks;j++){
+			mymtd->unlock(mymtd,mymtd->eraseregions[i].offset + j * mymtd->eraseregions[i].erasesize,4);
+		}
+	}
+
+	/* 
+	 * Register mymtd as an mtd device so that we can read the 
+	 * protection data 
+	 */
+	mymtd->name=master_name;
+	add_mtd_device(mymtd);
+
+
+	return 0;
+}
+
+static void __exit epxa10db_mtd_cleanup(void)
+{
+	if (mymtd) {
+		del_mtd_partitions(mymtd);
+		map_destroy(mymtd);
+		if (parsed_parts)
+			kfree(parsed_parts);
+	}
+}
+
+
+/* 
+ * This will do for now, once we decide which bootldr we're finally 
+ * going to use then we'll remove this function and do it properly
+ *
+ * Partions are currently (as offsets from base of flash):
+ * 0x00000000 - 0x003FFFFF - bootloader (!)
+ * 0x00400000 - 0x00FFFFFF - Flashdisk
+ */
+
+int fixup_epxa10db_partitions(struct mtd_info *master, struct mtd_partition **pparts)
+{
+	struct mtd_partition *parts;
+	int ret, i;
+	int npartitions = 0;
+	char *names; 
+	const char *name = "jffs";
+
+	printk("Fixing up epxa10db partitions\n");
+	npartitions=1;
+	parts = kmalloc(npartitions*sizeof(*parts)+strlen(name), GFP_KERNEL);
+	if (!parts) {
+		ret = -ENOMEM;
+		goto out;
+	}
+	i=0;
+	names = (char *)&parts[npartitions];	
+	parts[i].name = names;
+	names += strlen(name) + 1;
+	strcpy(parts[i].name, name);
+
+	parts[i].size = 0x00C00000;
+	parts[i].offset = 0x00400000;
+	parts[i].mask_flags = 0;
+		
+
+ out:
+	*pparts = parts;
+	return npartitions;
+}
+
+module_init(epxa10db_mtd_init);
+module_exit(epxa10db_mtd_cleanup);
diff -purN linux_2.4.13/drivers/mtd/mtdpart.c linux/drivers/mtd/mtdpart.c
--- linux_2.4.13/drivers/mtd/mtdpart.c	Thu Oct  4 23:14:59 2001
+++ linux/drivers/mtd/mtdpart.c	Wed Oct 24 10:17:47 2001
@@ -195,6 +195,7 @@ int add_mtd_partitions(struct mtd_info *
 		slave->mtd.oobsize = master->oobsize;
 		slave->mtd.ecctype = master->ecctype;
 		slave->mtd.eccsize = master->eccsize;
+		slave->mtd.read_oob = master->read_oob;
 
 		slave->mtd.name = parts[i].name;
 		slave->mtd.bank_size = master->bank_size;

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: FW: Patch: adding mtd support for new machine
  2001-11-01 13:58 FW: Patch: adding mtd support for new machine Clive Davies
@ 2001-11-01 14:12 ` David Woodhouse
  0 siblings, 0 replies; 2+ messages in thread
From: David Woodhouse @ 2001-11-01 14:12 UTC (permalink / raw)
  To: Clive Davies; +Cc: 'linux-mtd@lists.infradead.org'

cdavies@altera.com said:
>  I sent the follwing message to mtd@infradead.org a couple of days
> ago, but I've had no response. Is that the same list as
> linux-mtd@lists.infradead.org? 

Yes, it is. That's the old address for the list, and the alias still works.

> Can anyone tell me why I've had no reply? 

Er, just because I didn't notice your mail - sorry. 


cdavies@altera.com said:
> I submitted a patch to Russell King to add mtd support for a new
> mchine type to his arm linux source tree. He sent me here to discuss:

> >- lack of $id$ in the new map driver 
> >- missing help entry for the new CONFIG_* symbol
> >- concerns about overloading the read_oob

> The first one I don't really understand, 

Files in CVS have $Id$ tags to mark which version they are. Just add $Id$ 
in the comments at the top of the file and it'll get expanded when it's 
committed to look like the others:
	 * $Id: redboot.c,v 1.6 2001/10/25 09:16:06 dwmw2 Exp $
	
> the second I can deal with myself. For the third, I've used the oob 
> interface to access the protection data in Intel flash devices. This 
> seemed to me to fit ok as its essentially data that isn't in the main 
> flash array. 

read_oob is there to access the 'extra' storage area on NAND flash chips. 
What happens if people make NAND flash chips with the same kind of 
protection data? We probably need to distinguish between the two. Maybe by 
adding a pair of extra read/write methods, or maybe by adding an extra 
argument to the existing read_oob/write_oob to indicate which space they're 
supposed to operate on, and adding an enumeration of the available spaces 
in the mtd_info somehow.


--
dwmw2

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2001-11-01 14:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-11-01 13:58 FW: Patch: adding mtd support for new machine Clive Davies
2001-11-01 14:12 ` David Woodhouse

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox