Commit e0c7d767 authored by David Woodhouse's avatar David Woodhouse

[MTD NAND] Indent all of drivers/mtd/nand/*.c.

It was just too painful to deal with.
Signed-off-by: default avatarDavid Woodhouse <dwmw2@infradead.org>
parent 6943f8af
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
*/ */
static struct mtd_info *au1550_mtd = NULL; static struct mtd_info *au1550_mtd = NULL;
static void __iomem *p_nand; static void __iomem *p_nand;
static int nand_width = 1; /* default x8*/ static int nand_width = 1; /* default x8 */
/* /*
* Define partitions for flash device * Define partitions for flash device
...@@ -47,13 +47,11 @@ static const struct mtd_partition partition_info[] = { ...@@ -47,13 +47,11 @@ static const struct mtd_partition partition_info[] = {
{ {
.name = "NAND FS 0", .name = "NAND FS 0",
.offset = 0, .offset = 0,
.size = 8*1024*1024 .size = 8 * 1024 * 1024},
},
{ {
.name = "NAND FS 1", .name = "NAND FS 1",
.offset = MTDPART_OFS_APPEND, .offset = MTDPART_OFS_APPEND,
.size = MTDPART_SIZ_FULL .size = MTDPART_SIZ_FULL}
}
}; };
/** /**
...@@ -157,7 +155,7 @@ static void au_write_buf(struct mtd_info *mtd, const u_char *buf, int len) ...@@ -157,7 +155,7 @@ static void au_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
int i; int i;
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
for (i=0; i<len; i++) { for (i = 0; i < len; i++) {
writeb(buf[i], this->IO_ADDR_W); writeb(buf[i], this->IO_ADDR_W);
au_sync(); au_sync();
} }
...@@ -176,7 +174,7 @@ static void au_read_buf(struct mtd_info *mtd, u_char *buf, int len) ...@@ -176,7 +174,7 @@ static void au_read_buf(struct mtd_info *mtd, u_char *buf, int len)
int i; int i;
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
for (i=0; i<len; i++) { for (i = 0; i < len; i++) {
buf[i] = readb(this->IO_ADDR_R); buf[i] = readb(this->IO_ADDR_R);
au_sync(); au_sync();
} }
...@@ -195,7 +193,7 @@ static int au_verify_buf(struct mtd_info *mtd, const u_char *buf, int len) ...@@ -195,7 +193,7 @@ static int au_verify_buf(struct mtd_info *mtd, const u_char *buf, int len)
int i; int i;
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
for (i=0; i<len; i++) { for (i = 0; i < len; i++) {
if (buf[i] != readb(this->IO_ADDR_R)) if (buf[i] != readb(this->IO_ADDR_R))
return -EFAULT; return -EFAULT;
au_sync(); au_sync();
...@@ -219,7 +217,7 @@ static void au_write_buf16(struct mtd_info *mtd, const u_char *buf, int len) ...@@ -219,7 +217,7 @@ static void au_write_buf16(struct mtd_info *mtd, const u_char *buf, int len)
u16 *p = (u16 *) buf; u16 *p = (u16 *) buf;
len >>= 1; len >>= 1;
for (i=0; i<len; i++) { for (i = 0; i < len; i++) {
writew(p[i], this->IO_ADDR_W); writew(p[i], this->IO_ADDR_W);
au_sync(); au_sync();
} }
...@@ -241,7 +239,7 @@ static void au_read_buf16(struct mtd_info *mtd, u_char *buf, int len) ...@@ -241,7 +239,7 @@ static void au_read_buf16(struct mtd_info *mtd, u_char *buf, int len)
u16 *p = (u16 *) buf; u16 *p = (u16 *) buf;
len >>= 1; len >>= 1;
for (i=0; i<len; i++) { for (i = 0; i < len; i++) {
p[i] = readw(this->IO_ADDR_R); p[i] = readw(this->IO_ADDR_R);
au_sync(); au_sync();
} }
...@@ -262,7 +260,7 @@ static int au_verify_buf16(struct mtd_info *mtd, const u_char *buf, int len) ...@@ -262,7 +260,7 @@ static int au_verify_buf16(struct mtd_info *mtd, const u_char *buf, int len)
u16 *p = (u16 *) buf; u16 *p = (u16 *) buf;
len >>= 1; len >>= 1;
for (i=0; i<len; i++) { for (i = 0; i < len; i++) {
if (p[i] != readw(this->IO_ADDR_R)) if (p[i] != readw(this->IO_ADDR_R))
return -EFAULT; return -EFAULT;
au_sync(); au_sync();
...@@ -275,27 +273,35 @@ static void au1550_hwcontrol(struct mtd_info *mtd, int cmd) ...@@ -275,27 +273,35 @@ static void au1550_hwcontrol(struct mtd_info *mtd, int cmd)
{ {
register struct nand_chip *this = mtd->priv; register struct nand_chip *this = mtd->priv;
switch(cmd){ switch (cmd) {
case NAND_CTL_SETCLE:
this->IO_ADDR_W = p_nand + MEM_STNAND_CMD;
break;
case NAND_CTL_CLRCLE:
this->IO_ADDR_W = p_nand + MEM_STNAND_DATA;
break;
case NAND_CTL_SETCLE: this->IO_ADDR_W = p_nand + MEM_STNAND_CMD; break; case NAND_CTL_SETALE:
case NAND_CTL_CLRCLE: this->IO_ADDR_W = p_nand + MEM_STNAND_DATA; break; this->IO_ADDR_W = p_nand + MEM_STNAND_ADDR;
break;
case NAND_CTL_SETALE: this->IO_ADDR_W = p_nand + MEM_STNAND_ADDR; break;
case NAND_CTL_CLRALE: case NAND_CTL_CLRALE:
this->IO_ADDR_W = p_nand + MEM_STNAND_DATA; this->IO_ADDR_W = p_nand + MEM_STNAND_DATA;
/* FIXME: Nobody knows why this is neccecary, /* FIXME: Nobody knows why this is necessary,
* but it works only that way */ * but it works only that way */
udelay(1); udelay(1);
break; break;
case NAND_CTL_SETNCE: case NAND_CTL_SETNCE:
/* assert (force assert) chip enable */ /* assert (force assert) chip enable */
au_writel((1<<(4+NAND_CS)) , MEM_STNDCTL); break; au_writel((1 << (4 + NAND_CS)), MEM_STNDCTL);
break; break;
case NAND_CTL_CLRNCE: case NAND_CTL_CLRNCE:
/* deassert chip enable */ /* deassert chip enable */
au_writel(0, MEM_STNDCTL); break; au_writel(0, MEM_STNDCTL);
break; break;
} }
...@@ -315,7 +321,7 @@ int au1550_device_ready(struct mtd_info *mtd) ...@@ -315,7 +321,7 @@ int au1550_device_ready(struct mtd_info *mtd)
/* /*
* Main initialization routine * Main initialization routine
*/ */
int __init au1xxx_nand_init (void) int __init au1xxx_nand_init(void)
{ {
struct nand_chip *this; struct nand_chip *this;
u16 boot_swapboot = 0; /* default value */ u16 boot_swapboot = 0; /* default value */
...@@ -324,36 +330,33 @@ int __init au1xxx_nand_init (void) ...@@ -324,36 +330,33 @@ int __init au1xxx_nand_init (void)
u32 nand_phys; u32 nand_phys;
/* Allocate memory for MTD device structure and private data */ /* Allocate memory for MTD device structure and private data */
au1550_mtd = kmalloc (sizeof(struct mtd_info) + au1550_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
sizeof (struct nand_chip), GFP_KERNEL);
if (!au1550_mtd) { if (!au1550_mtd) {
printk ("Unable to allocate NAND MTD dev structure.\n"); printk("Unable to allocate NAND MTD dev structure.\n");
return -ENOMEM; return -ENOMEM;
} }
/* Get pointer to private data */ /* Get pointer to private data */
this = (struct nand_chip *) (&au1550_mtd[1]); this = (struct nand_chip *)(&au1550_mtd[1]);
/* Initialize structures */ /* Initialize structures */
memset((char *) au1550_mtd, 0, sizeof(struct mtd_info)); memset(au1550_mtd, 0, sizeof(struct mtd_info));
memset((char *) this, 0, sizeof(struct nand_chip)); memset(this, 0, sizeof(struct nand_chip));
/* Link the private data with the MTD structure */ /* Link the private data with the MTD structure */
au1550_mtd->priv = this; au1550_mtd->priv = this;
/* disable interrupts */ /* disable interrupts */
au_writel(au_readl(MEM_STNDCTL) & ~(1<<8), MEM_STNDCTL); au_writel(au_readl(MEM_STNDCTL) & ~(1 << 8), MEM_STNDCTL);
/* disable NAND boot */ /* disable NAND boot */
au_writel(au_readl(MEM_STNDCTL) & ~(1<<0), MEM_STNDCTL); au_writel(au_readl(MEM_STNDCTL) & ~(1 << 0), MEM_STNDCTL);
#ifdef CONFIG_MIPS_PB1550 #ifdef CONFIG_MIPS_PB1550
/* set gpio206 high */ /* set gpio206 high */
au_writel(au_readl(GPIO2_DIR) & ~(1<<6), GPIO2_DIR); au_writel(au_readl(GPIO2_DIR) & ~(1 << 6), GPIO2_DIR);
boot_swapboot = (au_readl(MEM_STSTAT) & (0x7<<1)) | boot_swapboot = (au_readl(MEM_STSTAT) & (0x7 << 1)) | ((bcsr->status >> 6) & 0x1);
((bcsr->status >> 6) & 0x1);
switch (boot_swapboot) { switch (boot_swapboot) {
case 0: case 0:
case 2: case 2:
...@@ -424,14 +427,13 @@ int __init au1xxx_nand_init (void) ...@@ -424,14 +427,13 @@ int __init au1xxx_nand_init (void)
/* make controller and MTD agree */ /* make controller and MTD agree */
if (NAND_CS == 0) if (NAND_CS == 0)
nand_width = au_readl(MEM_STCFG0) & (1<<22); nand_width = au_readl(MEM_STCFG0) & (1 << 22);
if (NAND_CS == 1) if (NAND_CS == 1)
nand_width = au_readl(MEM_STCFG1) & (1<<22); nand_width = au_readl(MEM_STCFG1) & (1 << 22);
if (NAND_CS == 2) if (NAND_CS == 2)
nand_width = au_readl(MEM_STCFG2) & (1<<22); nand_width = au_readl(MEM_STCFG2) & (1 << 22);
if (NAND_CS == 3) if (NAND_CS == 3)
nand_width = au_readl(MEM_STCFG3) & (1<<22); nand_width = au_readl(MEM_STCFG3) & (1 << 22);
/* Set address of hardware control function */ /* Set address of hardware control function */
this->hwcontrol = au1550_hwcontrol; this->hwcontrol = au1550_hwcontrol;
...@@ -454,7 +456,7 @@ int __init au1xxx_nand_init (void) ...@@ -454,7 +456,7 @@ int __init au1xxx_nand_init (void)
this->verify_buf = (!nand_width) ? au_verify_buf16 : au_verify_buf; this->verify_buf = (!nand_width) ? au_verify_buf16 : au_verify_buf;
/* Scan to find existence of the device */ /* Scan to find existence of the device */
if (nand_scan (au1550_mtd, 1)) { if (nand_scan(au1550_mtd, 1)) {
retval = -ENXIO; retval = -ENXIO;
goto outio; goto outio;
} }
...@@ -465,10 +467,10 @@ int __init au1xxx_nand_init (void) ...@@ -465,10 +467,10 @@ int __init au1xxx_nand_init (void)
return 0; return 0;
outio: outio:
iounmap ((void *)p_nand); iounmap((void *)p_nand);
outmem: outmem:
kfree (au1550_mtd); kfree(au1550_mtd);
return retval; return retval;
} }
...@@ -478,19 +480,20 @@ module_init(au1xxx_nand_init); ...@@ -478,19 +480,20 @@ module_init(au1xxx_nand_init);
* Clean up routine * Clean up routine
*/ */
#ifdef MODULE #ifdef MODULE
static void __exit au1550_cleanup (void) static void __exit au1550_cleanup(void)
{ {
struct nand_chip *this = (struct nand_chip *) &au1550_mtd[1]; struct nand_chip *this = (struct nand_chip *)&au1550_mtd[1];
/* Release resources, unregister device */ /* Release resources, unregister device */
nand_release (au1550_mtd); nand_release(au1550_mtd);
/* Free the MTD device structure */ /* Free the MTD device structure */
kfree (au1550_mtd); kfree(au1550_mtd);
/* Unmap */ /* Unmap */
iounmap ((void *)p_nand); iounmap((void *)p_nand);
} }
module_exit(au1550_cleanup); module_exit(au1550_cleanup);
#endif #endif
......
...@@ -47,7 +47,7 @@ static int autcpu12_io_base = CS89712_VIRT_BASE; ...@@ -47,7 +47,7 @@ static int autcpu12_io_base = CS89712_VIRT_BASE;
static int autcpu12_fio_pbase = AUTCPU12_PHYS_SMC; static int autcpu12_fio_pbase = AUTCPU12_PHYS_SMC;
static int autcpu12_fio_ctrl = AUTCPU12_SMC_SELECT_OFFSET; static int autcpu12_fio_ctrl = AUTCPU12_SMC_SELECT_OFFSET;
static int autcpu12_pedr = AUTCPU12_SMC_PORT_OFFSET; static int autcpu12_pedr = AUTCPU12_SMC_PORT_OFFSET;
static void __iomem * autcpu12_fio_base; static void __iomem *autcpu12_fio_base;
/* /*
* Define partitions for flash devices * Define partitions for flash devices
...@@ -95,10 +95,10 @@ static struct mtd_partition partition_info128k[] = { ...@@ -95,10 +95,10 @@ static struct mtd_partition partition_info128k[] = {
/* /*
* hardware specific access to control-lines * hardware specific access to control-lines
*/ */
static void autcpu12_hwcontrol(struct mtd_info *mtd, int cmd) static void autcpu12_hwcontrol(struct mtd_info *mtd, int cmd)
{ {
switch (cmd) {
switch(cmd){
case NAND_CTL_SETCLE: (*(volatile unsigned char *) (autcpu12_io_base + autcpu12_pedr)) |= AUTCPU12_SMC_CLE; break; case NAND_CTL_SETCLE: (*(volatile unsigned char *) (autcpu12_io_base + autcpu12_pedr)) |= AUTCPU12_SMC_CLE; break;
case NAND_CTL_CLRCLE: (*(volatile unsigned char *) (autcpu12_io_base + autcpu12_pedr)) &= ~AUTCPU12_SMC_CLE; break; case NAND_CTL_CLRCLE: (*(volatile unsigned char *) (autcpu12_io_base + autcpu12_pedr)) &= ~AUTCPU12_SMC_CLE; break;
...@@ -117,41 +117,40 @@ static void autcpu12_hwcontrol(struct mtd_info *mtd, int cmd) ...@@ -117,41 +117,40 @@ static void autcpu12_hwcontrol(struct mtd_info *mtd, int cmd)
int autcpu12_device_ready(struct mtd_info *mtd) int autcpu12_device_ready(struct mtd_info *mtd)
{ {
return ( (*(volatile unsigned char *) (autcpu12_io_base + autcpu12_pedr)) & AUTCPU12_SMC_RDY) ? 1 : 0; return ((*(volatile unsigned char *)(autcpu12_io_base + autcpu12_pedr)) & AUTCPU12_SMC_RDY) ? 1 : 0;
} }
/* /*
* Main initialization routine * Main initialization routine
*/ */
int __init autcpu12_init (void) int __init autcpu12_init(void)
{ {
struct nand_chip *this; struct nand_chip *this;
int err = 0; int err = 0;
/* Allocate memory for MTD device structure and private data */ /* Allocate memory for MTD device structure and private data */
autcpu12_mtd = kmalloc (sizeof(struct mtd_info) + sizeof (struct nand_chip), autcpu12_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
GFP_KERNEL);
if (!autcpu12_mtd) { if (!autcpu12_mtd) {
printk ("Unable to allocate AUTCPU12 NAND MTD device structure.\n"); printk("Unable to allocate AUTCPU12 NAND MTD device structure.\n");
err = -ENOMEM; err = -ENOMEM;
goto out; goto out;
} }
/* map physical adress */ /* map physical adress */
autcpu12_fio_base = ioremap(autcpu12_fio_pbase,SZ_1K); autcpu12_fio_base = ioremap(autcpu12_fio_pbase, SZ_1K);
if(!autcpu12_fio_base){ if (!autcpu12_fio_base) {
printk("Ioremap autcpu12 SmartMedia Card failed\n"); printk("Ioremap autcpu12 SmartMedia Card failed\n");
err = -EIO; err = -EIO;
goto out_mtd; goto out_mtd;
} }
/* Get pointer to private data */ /* Get pointer to private data */
this = (struct nand_chip *) (&autcpu12_mtd[1]); this = (struct nand_chip *)(&autcpu12_mtd[1]);
/* Initialize structures */ /* Initialize structures */
memset((char *) autcpu12_mtd, 0, sizeof(struct mtd_info)); memset(autcpu12_mtd, 0, sizeof(struct mtd_info));
memset((char *) this, 0, sizeof(struct nand_chip)); memset(this, 0, sizeof(struct nand_chip));
/* Link the private data with the MTD structure */ /* Link the private data with the MTD structure */
autcpu12_mtd->priv = this; autcpu12_mtd->priv = this;
...@@ -172,30 +171,29 @@ int __init autcpu12_init (void) ...@@ -172,30 +171,29 @@ int __init autcpu12_init (void)
this->options = NAND_USE_FLASH_BBT; this->options = NAND_USE_FLASH_BBT;
/* Scan to find existance of the device */ /* Scan to find existance of the device */
if (nand_scan (autcpu12_mtd, 1)) { if (nand_scan(autcpu12_mtd, 1)) {
err = -ENXIO; err = -ENXIO;
goto out_ior; goto out_ior;
} }
/* Register the partitions */ /* Register the partitions */
switch(autcpu12_mtd->size){ switch (autcpu12_mtd->size) {
case SZ_16M: add_mtd_partitions(autcpu12_mtd, partition_info16k, NUM_PARTITIONS16K); break; case SZ_16M: add_mtd_partitions(autcpu12_mtd, partition_info16k, NUM_PARTITIONS16K); break;
case SZ_32M: add_mtd_partitions(autcpu12_mtd, partition_info32k, NUM_PARTITIONS32K); break; case SZ_32M: add_mtd_partitions(autcpu12_mtd, partition_info32k, NUM_PARTITIONS32K); break;
case SZ_64M: add_mtd_partitions(autcpu12_mtd, partition_info64k, NUM_PARTITIONS64K); break; case SZ_64M: add_mtd_partitions(autcpu12_mtd, partition_info64k, NUM_PARTITIONS64K); break;
case SZ_128M: add_mtd_partitions(autcpu12_mtd, partition_info128k, NUM_PARTITIONS128K); break; case SZ_128M: add_mtd_partitions(autcpu12_mtd, partition_info128k, NUM_PARTITIONS128K); break;
default: { default:
printk ("Unsupported SmartMedia device\n"); printk("Unsupported SmartMedia device\n");
err = -ENXIO; err = -ENXIO;
goto out_ior; goto out_ior;
} }
}
goto out; goto out;
out_ior: out_ior:
iounmap((void *)autcpu12_fio_base); iounmap((void *)autcpu12_fio_base);
out_mtd: out_mtd:
kfree (autcpu12_mtd); kfree(autcpu12_mtd);
out: out:
return err; return err;
} }
...@@ -205,17 +203,18 @@ module_init(autcpu12_init); ...@@ -205,17 +203,18 @@ module_init(autcpu12_init);
* Clean up routine * Clean up routine
*/ */
#ifdef MODULE #ifdef MODULE
static void __exit autcpu12_cleanup (void) static void __exit autcpu12_cleanup(void)
{ {
/* Release resources, unregister device */ /* Release resources, unregister device */
nand_release (autcpu12_mtd); nand_release(autcpu12_mtd);
/* unmap physical adress */ /* unmap physical adress */
iounmap((void *)autcpu12_fio_base); iounmap((void *)autcpu12_fio_base);
/* Free the MTD device structure */ /* Free the MTD device structure */
kfree (autcpu12_mtd); kfree(autcpu12_mtd);
} }
module_exit(autcpu12_cleanup); module_exit(autcpu12_cleanup);
#endif #endif
......
...@@ -128,7 +128,7 @@ static void cs553x_write_byte(struct mtd_info *mtd, u_char byte) ...@@ -128,7 +128,7 @@ static void cs553x_write_byte(struct mtd_info *mtd, u_char byte)
udelay(1); udelay(1);
i--; i--;
} }
writeb(byte, this->IO_ADDR_W+0x801); writeb(byte, this->IO_ADDR_W + 0x801);
} }
static void cs553x_hwcontrol(struct mtd_info *mtd, int cmd) static void cs553x_hwcontrol(struct mtd_info *mtd, int cmd)
...@@ -137,7 +137,7 @@ static void cs553x_hwcontrol(struct mtd_info *mtd, int cmd) ...@@ -137,7 +137,7 @@ static void cs553x_hwcontrol(struct mtd_info *mtd, int cmd)
void __iomem *mmio_base = this->IO_ADDR_R; void __iomem *mmio_base = this->IO_ADDR_R;
unsigned char ctl; unsigned char ctl;
switch(cmd) { switch (cmd) {
case NAND_CTL_SETCLE: case NAND_CTL_SETCLE:
ctl = CS_NAND_CTL_CLE; ctl = CS_NAND_CTL_CLE;
break; break;
...@@ -160,7 +160,6 @@ static void cs553x_hwcontrol(struct mtd_info *mtd, int cmd) ...@@ -160,7 +160,6 @@ static void cs553x_hwcontrol(struct mtd_info *mtd, int cmd)
writeb(ctl, mmio_base + MM_NAND_CTL); writeb(ctl, mmio_base + MM_NAND_CTL);
} }
static int cs553x_device_ready(struct mtd_info *mtd) static int cs553x_device_ready(struct mtd_info *mtd)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
...@@ -170,7 +169,6 @@ static int cs553x_device_ready(struct mtd_info *mtd) ...@@ -170,7 +169,6 @@ static int cs553x_device_ready(struct mtd_info *mtd)
return (foo & CS_NAND_STS_FLASH_RDY) && !(foo & CS_NAND_CTLR_BUSY); return (foo & CS_NAND_STS_FLASH_RDY) && !(foo & CS_NAND_CTLR_BUSY);
} }
static void cs_enable_hwecc(struct mtd_info *mtd, int mode) static void cs_enable_hwecc(struct mtd_info *mtd, int mode)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
...@@ -209,7 +207,7 @@ static int __init cs553x_init_one(int cs, int mmio, unsigned long adr) ...@@ -209,7 +207,7 @@ static int __init cs553x_init_one(int cs, int mmio, unsigned long adr)
} }
/* Allocate memory for MTD device structure and private data */ /* Allocate memory for MTD device structure and private data */
new_mtd = kmalloc(sizeof(struct mtd_info) + sizeof (struct nand_chip), GFP_KERNEL); new_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
if (!new_mtd) { if (!new_mtd) {
printk(KERN_WARNING "Unable to allocate CS553X NAND MTD device structure.\n"); printk(KERN_WARNING "Unable to allocate CS553X NAND MTD device structure.\n");
err = -ENOMEM; err = -ENOMEM;
...@@ -217,7 +215,7 @@ static int __init cs553x_init_one(int cs, int mmio, unsigned long adr) ...@@ -217,7 +215,7 @@ static int __init cs553x_init_one(int cs, int mmio, unsigned long adr)
} }
/* Get pointer to private data */ /* Get pointer to private data */
this = (struct nand_chip *) (&new_mtd[1]); this = (struct nand_chip *)(&new_mtd[1]);
/* Initialize structures */ /* Initialize structures */
memset(new_mtd, 0, sizeof(struct mtd_info)); memset(new_mtd, 0, sizeof(struct mtd_info));
...@@ -286,8 +284,8 @@ int __init cs553x_init(void) ...@@ -286,8 +284,8 @@ int __init cs553x_init(void)
return -ENXIO; return -ENXIO;
} }
for (i=0; i<NR_CS553X_CONTROLLERS; i++) { for (i = 0; i < NR_CS553X_CONTROLLERS; i++) {
rdmsrl(MSR_DIVIL_LBAR_FLSH0+i, val); rdmsrl(MSR_DIVIL_LBAR_FLSH0 + i, val);
if ((val & (FLSH_LBAR_EN|FLSH_NOR_NAND)) == (FLSH_LBAR_EN|FLSH_NOR_NAND)) if ((val & (FLSH_LBAR_EN|FLSH_NOR_NAND)) == (FLSH_LBAR_EN|FLSH_NOR_NAND))
err = cs553x_init_one(i, !!(val & FLSH_MEM_IO), val & 0xFFFFFFFF); err = cs553x_init_one(i, !!(val & FLSH_MEM_IO), val & 0xFFFFFFFF);
...@@ -295,7 +293,7 @@ int __init cs553x_init(void) ...@@ -295,7 +293,7 @@ int __init cs553x_init(void)
/* Register all devices together here. This means we can easily hack it to /* Register all devices together here. This means we can easily hack it to
do mtdconcat etc. if we want to. */ do mtdconcat etc. if we want to. */
for (i=0; i<NR_CS553X_CONTROLLERS; i++) { for (i = 0; i < NR_CS553X_CONTROLLERS; i++) {
if (cs553x_mtd[i]) { if (cs553x_mtd[i]) {
add_mtd_device(cs553x_mtd[i]); add_mtd_device(cs553x_mtd[i]);
...@@ -306,13 +304,14 @@ int __init cs553x_init(void) ...@@ -306,13 +304,14 @@ int __init cs553x_init(void)
return err; return err;
} }
module_init(cs553x_init); module_init(cs553x_init);
static void __exit cs553x_cleanup (void) static void __exit cs553x_cleanup(void)
{ {
int i; int i;
for (i=0; i<NR_CS553X_CONTROLLERS; i++) { for (i = 0; i < NR_CS553X_CONTROLLERS; i++) {
struct mtd_info *mtd = cs553x_mtd[i]; struct mtd_info *mtd = cs553x_mtd[i];
struct nand_chip *this; struct nand_chip *this;
void __iomem *mmio_base; void __iomem *mmio_base;
...@@ -324,7 +323,7 @@ static void __exit cs553x_cleanup (void) ...@@ -324,7 +323,7 @@ static void __exit cs553x_cleanup (void)
mmio_base = this->IO_ADDR_R; mmio_base = this->IO_ADDR_R;
/* Release resources, unregister device */ /* Release resources, unregister device */
nand_release (cs553x_mtd[i]); nand_release(cs553x_mtd[i]);
cs553x_mtd[i] = NULL; cs553x_mtd[i] = NULL;
/* unmap physical adress */ /* unmap physical adress */
...@@ -334,6 +333,7 @@ static void __exit cs553x_cleanup (void) ...@@ -334,6 +333,7 @@ static void __exit cs553x_cleanup (void)
kfree(mtd); kfree(mtd);
} }
} }
module_exit(cs553x_cleanup); module_exit(cs553x_cleanup);
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
......
...@@ -61,7 +61,7 @@ static unsigned long __initdata doc_locations[] = { ...@@ -61,7 +61,7 @@ static unsigned long __initdata doc_locations[] = {
0xff000000, 0xff000000,
#elif defined(CONFIG_MOMENCO_OCELOT_G) || defined (CONFIG_MOMENCO_OCELOT_C) #elif defined(CONFIG_MOMENCO_OCELOT_G) || defined (CONFIG_MOMENCO_OCELOT_C)
0xff000000, 0xff000000,
##else #else
#warning Unknown architecture for DiskOnChip. No default probe locations defined #warning Unknown architecture for DiskOnChip. No default probe locations defined
#endif #endif
0xffffffff }; 0xffffffff };
...@@ -84,6 +84,7 @@ struct doc_priv { ...@@ -84,6 +84,7 @@ struct doc_priv {
/* This is the syndrome computed by the HW ecc generator upon reading an empty /* This is the syndrome computed by the HW ecc generator upon reading an empty
page, one with all 0xff for data and stored ecc code. */ page, one with all 0xff for data and stored ecc code. */
static u_char empty_read_syndrome[6] = { 0x26, 0xff, 0x6d, 0x47, 0x73, 0x7a }; static u_char empty_read_syndrome[6] = { 0x26, 0xff, 0x6d, 0x47, 0x73, 0x7a };
/* This is the ecc value computed by the HW ecc generator upon writing an empty /* This is the ecc value computed by the HW ecc generator upon writing an empty
page, one with all 0xff for data. */ page, one with all 0xff for data. */
static u_char empty_write_ecc[6] = { 0x4b, 0x00, 0xe2, 0x0e, 0x93, 0xf7 }; static u_char empty_write_ecc[6] = { 0x4b, 0x00, 0xe2, 0x0e, 0x93, 0xf7 };
...@@ -97,25 +98,25 @@ static u_char empty_write_ecc[6] = { 0x4b, 0x00, 0xe2, 0x0e, 0x93, 0xf7 }; ...@@ -97,25 +98,25 @@ static u_char empty_write_ecc[6] = { 0x4b, 0x00, 0xe2, 0x0e, 0x93, 0xf7 };
static void doc200x_hwcontrol(struct mtd_info *mtd, int cmd); static void doc200x_hwcontrol(struct mtd_info *mtd, int cmd);
static void doc200x_select_chip(struct mtd_info *mtd, int chip); static void doc200x_select_chip(struct mtd_info *mtd, int chip);
static int debug=0; static int debug = 0;
module_param(debug, int, 0); module_param(debug, int, 0);
static int try_dword=1; static int try_dword = 1;
module_param(try_dword, int, 0); module_param(try_dword, int, 0);
static int no_ecc_failures=0; static int no_ecc_failures = 0;
module_param(no_ecc_failures, int, 0); module_param(no_ecc_failures, int, 0);
static int no_autopart=0; static int no_autopart = 0;
module_param(no_autopart, int, 0); module_param(no_autopart, int, 0);
static int show_firmware_partition=0; static int show_firmware_partition = 0;
module_param(show_firmware_partition, int, 0); module_param(show_firmware_partition, int, 0);
#ifdef MTD_NAND_DISKONCHIP_BBTWRITE #ifdef MTD_NAND_DISKONCHIP_BBTWRITE
static int inftl_bbt_write=1; static int inftl_bbt_write = 1;
#else #else
static int inftl_bbt_write=0; static int inftl_bbt_write = 0;
#endif #endif
module_param(inftl_bbt_write, int, 0); module_param(inftl_bbt_write, int, 0);
...@@ -123,7 +124,6 @@ static unsigned long doc_config_location = CONFIG_MTD_NAND_DISKONCHIP_PROBE_ADDR ...@@ -123,7 +124,6 @@ static unsigned long doc_config_location = CONFIG_MTD_NAND_DISKONCHIP_PROBE_ADDR
module_param(doc_config_location, ulong, 0); module_param(doc_config_location, ulong, 0);
MODULE_PARM_DESC(doc_config_location, "Physical memory address at which to probe for DiskOnChip"); MODULE_PARM_DESC(doc_config_location, "Physical memory address at which to probe for DiskOnChip");
/* Sector size for HW ECC */ /* Sector size for HW ECC */
#define SECTOR_SIZE 512 #define SECTOR_SIZE 512
/* The sector bytes are packed into NB_DATA 10 bit words */ /* The sector bytes are packed into NB_DATA 10 bit words */
...@@ -147,7 +147,7 @@ static struct rs_control *rs_decoder; ...@@ -147,7 +147,7 @@ static struct rs_control *rs_decoder;
* some comments, improved a minor bit and converted it to make use * some comments, improved a minor bit and converted it to make use
* of the generic Reed-Solomon libary. tglx * of the generic Reed-Solomon libary. tglx
*/ */
static int doc_ecc_decode (struct rs_control *rs, uint8_t *data, uint8_t *ecc) static int doc_ecc_decode(struct rs_control *rs, uint8_t *data, uint8_t *ecc)
{ {
int i, j, nerr, errpos[8]; int i, j, nerr, errpos[8];
uint8_t parity; uint8_t parity;
...@@ -168,11 +168,11 @@ static int doc_ecc_decode (struct rs_control *rs, uint8_t *data, uint8_t *ecc) ...@@ -168,11 +168,11 @@ static int doc_ecc_decode (struct rs_control *rs, uint8_t *data, uint8_t *ecc)
* s[i] = ds[3]x^3 + ds[2]x^2 + ds[1]x^1 + ds[0] * s[i] = ds[3]x^3 + ds[2]x^2 + ds[1]x^1 + ds[0]
* where x = alpha^(FCR + i) * where x = alpha^(FCR + i)
*/ */
for(j = 1; j < NROOTS; j++) { for (j = 1; j < NROOTS; j++) {
if(ds[j] == 0) if (ds[j] == 0)
continue; continue;
tmp = rs->index_of[ds[j]]; tmp = rs->index_of[ds[j]];
for(i = 0; i < NROOTS; i++) for (i = 0; i < NROOTS; i++)
s[i] ^= rs->alpha_to[rs_modnn(rs, tmp + (FCR + i) * j)]; s[i] ^= rs->alpha_to[rs_modnn(rs, tmp + (FCR + i) * j)];
} }
...@@ -193,7 +193,7 @@ static int doc_ecc_decode (struct rs_control *rs, uint8_t *data, uint8_t *ecc) ...@@ -193,7 +193,7 @@ static int doc_ecc_decode (struct rs_control *rs, uint8_t *data, uint8_t *ecc)
* but they are given by the design of the de/encoder circuit * but they are given by the design of the de/encoder circuit
* in the DoC ASIC's. * in the DoC ASIC's.
*/ */
for(i = 0;i < nerr; i++) { for (i = 0; i < nerr; i++) {
int index, bitpos, pos = 1015 - errpos[i]; int index, bitpos, pos = 1015 - errpos[i];
uint8_t val; uint8_t val;
if (pos >= NB_DATA && pos < 1019) if (pos >= NB_DATA && pos < 1019)
...@@ -205,8 +205,7 @@ static int doc_ecc_decode (struct rs_control *rs, uint8_t *data, uint8_t *ecc) ...@@ -205,8 +205,7 @@ static int doc_ecc_decode (struct rs_control *rs, uint8_t *data, uint8_t *ecc)
can be modified since pos is even */ can be modified since pos is even */
index = (pos >> 3) ^ 1; index = (pos >> 3) ^ 1;
bitpos = pos & 7; bitpos = pos & 7;
if ((index >= 0 && index < SECTOR_SIZE) || if ((index >= 0 && index < SECTOR_SIZE) || index == (SECTOR_SIZE + 1)) {
index == (SECTOR_SIZE + 1)) {
val = (uint8_t) (errval[i] >> (2 + bitpos)); val = (uint8_t) (errval[i] >> (2 + bitpos));
parity ^= val; parity ^= val;
if (index < SECTOR_SIZE) if (index < SECTOR_SIZE)
...@@ -216,9 +215,8 @@ static int doc_ecc_decode (struct rs_control *rs, uint8_t *data, uint8_t *ecc) ...@@ -216,9 +215,8 @@ static int doc_ecc_decode (struct rs_control *rs, uint8_t *data, uint8_t *ecc)
bitpos = (bitpos + 10) & 7; bitpos = (bitpos + 10) & 7;
if (bitpos == 0) if (bitpos == 0)
bitpos = 8; bitpos = 8;
if ((index >= 0 && index < SECTOR_SIZE) || if ((index >= 0 && index < SECTOR_SIZE) || index == (SECTOR_SIZE + 1)) {
index == (SECTOR_SIZE + 1)) { val = (uint8_t) (errval[i] << (8 - bitpos));
val = (uint8_t)(errval[i] << (8 - bitpos));
parity ^= val; parity ^= val;
if (index < SECTOR_SIZE) if (index < SECTOR_SIZE)
data[index] ^= val; data[index] ^= val;
...@@ -253,7 +251,8 @@ static int _DoC_WaitReady(struct doc_priv *doc) ...@@ -253,7 +251,8 @@ static int _DoC_WaitReady(struct doc_priv *doc)
void __iomem *docptr = doc->virtadr; void __iomem *docptr = doc->virtadr;
unsigned long timeo = jiffies + (HZ * 10); unsigned long timeo = jiffies + (HZ * 10);
if(debug) printk("_DoC_WaitReady...\n"); if (debug)
printk("_DoC_WaitReady...\n");
/* Out-of-line routine to wait for chip response */ /* Out-of-line routine to wait for chip response */
if (DoC_is_MillenniumPlus(doc)) { if (DoC_is_MillenniumPlus(doc)) {
while ((ReadDOC(docptr, Mplus_FlashControl) & CDSN_CTRL_FR_B_MASK) != CDSN_CTRL_FR_B_MASK) { while ((ReadDOC(docptr, Mplus_FlashControl) & CDSN_CTRL_FR_B_MASK) != CDSN_CTRL_FR_B_MASK) {
...@@ -298,7 +297,8 @@ static inline int DoC_WaitReady(struct doc_priv *doc) ...@@ -298,7 +297,8 @@ static inline int DoC_WaitReady(struct doc_priv *doc)
DoC_Delay(doc, 2); DoC_Delay(doc, 2);
} }
if(debug) printk("DoC_WaitReady OK\n"); if (debug)
printk("DoC_WaitReady OK\n");
return ret; return ret;
} }
...@@ -308,7 +308,8 @@ static void doc2000_write_byte(struct mtd_info *mtd, u_char datum) ...@@ -308,7 +308,8 @@ static void doc2000_write_byte(struct mtd_info *mtd, u_char datum)
struct doc_priv *doc = this->priv; struct doc_priv *doc = this->priv;
void __iomem *docptr = doc->virtadr; void __iomem *docptr = doc->virtadr;
if(debug)printk("write_byte %02x\n", datum); if (debug)
printk("write_byte %02x\n", datum);
WriteDOC(datum, docptr, CDSNSlowIO); WriteDOC(datum, docptr, CDSNSlowIO);
WriteDOC(datum, docptr, 2k_CDSN_IO); WriteDOC(datum, docptr, 2k_CDSN_IO);
} }
...@@ -323,71 +324,72 @@ static u_char doc2000_read_byte(struct mtd_info *mtd) ...@@ -323,71 +324,72 @@ static u_char doc2000_read_byte(struct mtd_info *mtd)
ReadDOC(docptr, CDSNSlowIO); ReadDOC(docptr, CDSNSlowIO);
DoC_Delay(doc, 2); DoC_Delay(doc, 2);
ret = ReadDOC(docptr, 2k_CDSN_IO); ret = ReadDOC(docptr, 2k_CDSN_IO);
if (debug) printk("read_byte returns %02x\n", ret); if (debug)
printk("read_byte returns %02x\n", ret);
return ret; return ret;
} }
static void doc2000_writebuf(struct mtd_info *mtd, static void doc2000_writebuf(struct mtd_info *mtd, const u_char *buf, int len)
const u_char *buf, int len)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
struct doc_priv *doc = this->priv; struct doc_priv *doc = this->priv;
void __iomem *docptr = doc->virtadr; void __iomem *docptr = doc->virtadr;
int i; int i;
if (debug)printk("writebuf of %d bytes: ", len); if (debug)
for (i=0; i < len; i++) { printk("writebuf of %d bytes: ", len);
for (i = 0; i < len; i++) {
WriteDOC_(buf[i], docptr, DoC_2k_CDSN_IO + i); WriteDOC_(buf[i], docptr, DoC_2k_CDSN_IO + i);
if (debug && i < 16) if (debug && i < 16)
printk("%02x ", buf[i]); printk("%02x ", buf[i]);
} }
if (debug) printk("\n"); if (debug)
printk("\n");
} }
static void doc2000_readbuf(struct mtd_info *mtd, static void doc2000_readbuf(struct mtd_info *mtd, u_char *buf, int len)
u_char *buf, int len)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
struct doc_priv *doc = this->priv; struct doc_priv *doc = this->priv;
void __iomem *docptr = doc->virtadr; void __iomem *docptr = doc->virtadr;
int i; int i;
if (debug)printk("readbuf of %d bytes: ", len); if (debug)
printk("readbuf of %d bytes: ", len);
for (i=0; i < len; i++) { for (i = 0; i < len; i++) {
buf[i] = ReadDOC(docptr, 2k_CDSN_IO + i); buf[i] = ReadDOC(docptr, 2k_CDSN_IO + i);
} }
} }
static void doc2000_readbuf_dword(struct mtd_info *mtd, static void doc2000_readbuf_dword(struct mtd_info *mtd, u_char *buf, int len)
u_char *buf, int len)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
struct doc_priv *doc = this->priv; struct doc_priv *doc = this->priv;
void __iomem *docptr = doc->virtadr; void __iomem *docptr = doc->virtadr;
int i; int i;
if (debug) printk("readbuf_dword of %d bytes: ", len); if (debug)
printk("readbuf_dword of %d bytes: ", len);
if (unlikely((((unsigned long)buf)|len) & 3)) { if (unlikely((((unsigned long)buf) | len) & 3)) {
for (i=0; i < len; i++) { for (i = 0; i < len; i++) {
*(uint8_t *)(&buf[i]) = ReadDOC(docptr, 2k_CDSN_IO + i); *(uint8_t *) (&buf[i]) = ReadDOC(docptr, 2k_CDSN_IO + i);
} }
} else { } else {
for (i=0; i < len; i+=4) { for (i = 0; i < len; i += 4) {
*(uint32_t*)(&buf[i]) = readl(docptr + DoC_2k_CDSN_IO + i); *(uint32_t *) (&buf[i]) = readl(docptr + DoC_2k_CDSN_IO + i);
} }
} }
} }
static int doc2000_verifybuf(struct mtd_info *mtd, static int doc2000_verifybuf(struct mtd_info *mtd, const u_char *buf, int len)
const u_char *buf, int len)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
struct doc_priv *doc = this->priv; struct doc_priv *doc = this->priv;
void __iomem *docptr = doc->virtadr; void __iomem *docptr = doc->virtadr;
int i; int i;
for (i=0; i < len; i++) for (i = 0; i < len; i++)
if (buf[i] != ReadDOC(docptr, 2k_CDSN_IO)) if (buf[i] != ReadDOC(docptr, 2k_CDSN_IO))
return -EFAULT; return -EFAULT;
return 0; return 0;
...@@ -503,22 +505,20 @@ static u_char doc2001_read_byte(struct mtd_info *mtd) ...@@ -503,22 +505,20 @@ static u_char doc2001_read_byte(struct mtd_info *mtd)
return ReadDOC(docptr, LastDataRead); return ReadDOC(docptr, LastDataRead);
} }
static void doc2001_writebuf(struct mtd_info *mtd, static void doc2001_writebuf(struct mtd_info *mtd, const u_char *buf, int len)
const u_char *buf, int len)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
struct doc_priv *doc = this->priv; struct doc_priv *doc = this->priv;
void __iomem *docptr = doc->virtadr; void __iomem *docptr = doc->virtadr;
int i; int i;
for (i=0; i < len; i++) for (i = 0; i < len; i++)
WriteDOC_(buf[i], docptr, DoC_Mil_CDSN_IO + i); WriteDOC_(buf[i], docptr, DoC_Mil_CDSN_IO + i);
/* Terminate write pipeline */ /* Terminate write pipeline */
WriteDOC(0x00, docptr, WritePipeTerm); WriteDOC(0x00, docptr, WritePipeTerm);
} }
static void doc2001_readbuf(struct mtd_info *mtd, static void doc2001_readbuf(struct mtd_info *mtd, u_char *buf, int len)
u_char *buf, int len)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
struct doc_priv *doc = this->priv; struct doc_priv *doc = this->priv;
...@@ -528,15 +528,14 @@ static void doc2001_readbuf(struct mtd_info *mtd, ...@@ -528,15 +528,14 @@ static void doc2001_readbuf(struct mtd_info *mtd,
/* Start read pipeline */ /* Start read pipeline */
ReadDOC(docptr, ReadPipeInit); ReadDOC(docptr, ReadPipeInit);
for (i=0; i < len-1; i++) for (i = 0; i < len - 1; i++)
buf[i] = ReadDOC(docptr, Mil_CDSN_IO + (i & 0xff)); buf[i] = ReadDOC(docptr, Mil_CDSN_IO + (i & 0xff));
/* Terminate read pipeline */ /* Terminate read pipeline */
buf[i] = ReadDOC(docptr, LastDataRead); buf[i] = ReadDOC(docptr, LastDataRead);
} }
static int doc2001_verifybuf(struct mtd_info *mtd, static int doc2001_verifybuf(struct mtd_info *mtd, const u_char *buf, int len)
const u_char *buf, int len)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
struct doc_priv *doc = this->priv; struct doc_priv *doc = this->priv;
...@@ -546,7 +545,7 @@ static int doc2001_verifybuf(struct mtd_info *mtd, ...@@ -546,7 +545,7 @@ static int doc2001_verifybuf(struct mtd_info *mtd,
/* Start read pipeline */ /* Start read pipeline */
ReadDOC(docptr, ReadPipeInit); ReadDOC(docptr, ReadPipeInit);
for (i=0; i < len-1; i++) for (i = 0; i < len - 1; i++)
if (buf[i] != ReadDOC(docptr, Mil_CDSN_IO)) { if (buf[i] != ReadDOC(docptr, Mil_CDSN_IO)) {
ReadDOC(docptr, LastDataRead); ReadDOC(docptr, LastDataRead);
return i; return i;
...@@ -566,81 +565,84 @@ static u_char doc2001plus_read_byte(struct mtd_info *mtd) ...@@ -566,81 +565,84 @@ static u_char doc2001plus_read_byte(struct mtd_info *mtd)
ReadDOC(docptr, Mplus_ReadPipeInit); ReadDOC(docptr, Mplus_ReadPipeInit);
ReadDOC(docptr, Mplus_ReadPipeInit); ReadDOC(docptr, Mplus_ReadPipeInit);
ret = ReadDOC(docptr, Mplus_LastDataRead); ret = ReadDOC(docptr, Mplus_LastDataRead);
if (debug) printk("read_byte returns %02x\n", ret); if (debug)
printk("read_byte returns %02x\n", ret);
return ret; return ret;
} }
static void doc2001plus_writebuf(struct mtd_info *mtd, static void doc2001plus_writebuf(struct mtd_info *mtd, const u_char *buf, int len)
const u_char *buf, int len)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
struct doc_priv *doc = this->priv; struct doc_priv *doc = this->priv;
void __iomem *docptr = doc->virtadr; void __iomem *docptr = doc->virtadr;
int i; int i;
if (debug)printk("writebuf of %d bytes: ", len); if (debug)
for (i=0; i < len; i++) { printk("writebuf of %d bytes: ", len);
for (i = 0; i < len; i++) {
WriteDOC_(buf[i], docptr, DoC_Mil_CDSN_IO + i); WriteDOC_(buf[i], docptr, DoC_Mil_CDSN_IO + i);
if (debug && i < 16) if (debug && i < 16)
printk("%02x ", buf[i]); printk("%02x ", buf[i]);
} }
if (debug) printk("\n"); if (debug)
printk("\n");
} }
static void doc2001plus_readbuf(struct mtd_info *mtd, static void doc2001plus_readbuf(struct mtd_info *mtd, u_char *buf, int len)
u_char *buf, int len)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
struct doc_priv *doc = this->priv; struct doc_priv *doc = this->priv;
void __iomem *docptr = doc->virtadr; void __iomem *docptr = doc->virtadr;
int i; int i;
if (debug)printk("readbuf of %d bytes: ", len); if (debug)
printk("readbuf of %d bytes: ", len);
/* Start read pipeline */ /* Start read pipeline */
ReadDOC(docptr, Mplus_ReadPipeInit); ReadDOC(docptr, Mplus_ReadPipeInit);
ReadDOC(docptr, Mplus_ReadPipeInit); ReadDOC(docptr, Mplus_ReadPipeInit);
for (i=0; i < len-2; i++) { for (i = 0; i < len - 2; i++) {
buf[i] = ReadDOC(docptr, Mil_CDSN_IO); buf[i] = ReadDOC(docptr, Mil_CDSN_IO);
if (debug && i < 16) if (debug && i < 16)
printk("%02x ", buf[i]); printk("%02x ", buf[i]);
} }
/* Terminate read pipeline */ /* Terminate read pipeline */
buf[len-2] = ReadDOC(docptr, Mplus_LastDataRead); buf[len - 2] = ReadDOC(docptr, Mplus_LastDataRead);
if (debug && i < 16) if (debug && i < 16)
printk("%02x ", buf[len-2]); printk("%02x ", buf[len - 2]);
buf[len-1] = ReadDOC(docptr, Mplus_LastDataRead); buf[len - 1] = ReadDOC(docptr, Mplus_LastDataRead);
if (debug && i < 16) if (debug && i < 16)
printk("%02x ", buf[len-1]); printk("%02x ", buf[len - 1]);
if (debug) printk("\n"); if (debug)
printk("\n");
} }
static int doc2001plus_verifybuf(struct mtd_info *mtd, static int doc2001plus_verifybuf(struct mtd_info *mtd, const u_char *buf, int len)
const u_char *buf, int len)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
struct doc_priv *doc = this->priv; struct doc_priv *doc = this->priv;
void __iomem *docptr = doc->virtadr; void __iomem *docptr = doc->virtadr;
int i; int i;
if (debug)printk("verifybuf of %d bytes: ", len); if (debug)
printk("verifybuf of %d bytes: ", len);
/* Start read pipeline */ /* Start read pipeline */
ReadDOC(docptr, Mplus_ReadPipeInit); ReadDOC(docptr, Mplus_ReadPipeInit);
ReadDOC(docptr, Mplus_ReadPipeInit); ReadDOC(docptr, Mplus_ReadPipeInit);
for (i=0; i < len-2; i++) for (i = 0; i < len - 2; i++)
if (buf[i] != ReadDOC(docptr, Mil_CDSN_IO)) { if (buf[i] != ReadDOC(docptr, Mil_CDSN_IO)) {
ReadDOC(docptr, Mplus_LastDataRead); ReadDOC(docptr, Mplus_LastDataRead);
ReadDOC(docptr, Mplus_LastDataRead); ReadDOC(docptr, Mplus_LastDataRead);
return i; return i;
} }
if (buf[len-2] != ReadDOC(docptr, Mplus_LastDataRead)) if (buf[len - 2] != ReadDOC(docptr, Mplus_LastDataRead))
return len-2; return len - 2;
if (buf[len-1] != ReadDOC(docptr, Mplus_LastDataRead)) if (buf[len - 1] != ReadDOC(docptr, Mplus_LastDataRead))
return len-1; return len - 1;
return 0; return 0;
} }
...@@ -651,7 +653,8 @@ static void doc2001plus_select_chip(struct mtd_info *mtd, int chip) ...@@ -651,7 +653,8 @@ static void doc2001plus_select_chip(struct mtd_info *mtd, int chip)
void __iomem *docptr = doc->virtadr; void __iomem *docptr = doc->virtadr;
int floor = 0; int floor = 0;
if(debug)printk("select chip (%d)\n", chip); if (debug)
printk("select chip (%d)\n", chip);
if (chip == -1) { if (chip == -1) {
/* Disable flash internally */ /* Disable flash internally */
...@@ -677,7 +680,8 @@ static void doc200x_select_chip(struct mtd_info *mtd, int chip) ...@@ -677,7 +680,8 @@ static void doc200x_select_chip(struct mtd_info *mtd, int chip)
void __iomem *docptr = doc->virtadr; void __iomem *docptr = doc->virtadr;
int floor = 0; int floor = 0;
if(debug)printk("select chip (%d)\n", chip); if (debug)
printk("select chip (%d)\n", chip);
if (chip == -1) if (chip == -1)
return; return;
...@@ -703,7 +707,7 @@ static void doc200x_hwcontrol(struct mtd_info *mtd, int cmd) ...@@ -703,7 +707,7 @@ static void doc200x_hwcontrol(struct mtd_info *mtd, int cmd)
struct doc_priv *doc = this->priv; struct doc_priv *doc = this->priv;
void __iomem *docptr = doc->virtadr; void __iomem *docptr = doc->virtadr;
switch(cmd) { switch (cmd) {
case NAND_CTL_SETNCE: case NAND_CTL_SETNCE:
doc->CDSNControl |= CDSN_CTRL_CE; doc->CDSNControl |= CDSN_CTRL_CE;
break; break;
...@@ -729,13 +733,14 @@ static void doc200x_hwcontrol(struct mtd_info *mtd, int cmd) ...@@ -729,13 +733,14 @@ static void doc200x_hwcontrol(struct mtd_info *mtd, int cmd)
doc->CDSNControl &= ~CDSN_CTRL_WP; doc->CDSNControl &= ~CDSN_CTRL_WP;
break; break;
} }
if (debug)printk("hwcontrol(%d): %02x\n", cmd, doc->CDSNControl); if (debug)
printk("hwcontrol(%d): %02x\n", cmd, doc->CDSNControl);
WriteDOC(doc->CDSNControl, docptr, CDSNControl); WriteDOC(doc->CDSNControl, docptr, CDSNControl);
/* 11.4.3 -- 4 NOPs after CSDNControl write */ /* 11.4.3 -- 4 NOPs after CSDNControl write */
DoC_Delay(doc, 4); DoC_Delay(doc, 4);
} }
static void doc2001plus_command (struct mtd_info *mtd, unsigned command, int column, int page_addr) static void doc2001plus_command(struct mtd_info *mtd, unsigned command, int column, int page_addr)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
struct doc_priv *doc = this->priv; struct doc_priv *doc = this->priv;
...@@ -782,18 +787,19 @@ static void doc2001plus_command (struct mtd_info *mtd, unsigned command, int col ...@@ -782,18 +787,19 @@ static void doc2001plus_command (struct mtd_info *mtd, unsigned command, int col
WriteDOC(column, docptr, Mplus_FlashAddress); WriteDOC(column, docptr, Mplus_FlashAddress);
} }
if (page_addr != -1) { if (page_addr != -1) {
WriteDOC((unsigned char) (page_addr & 0xff), docptr, Mplus_FlashAddress); WriteDOC((unsigned char)(page_addr & 0xff), docptr, Mplus_FlashAddress);
WriteDOC((unsigned char) ((page_addr >> 8) & 0xff), docptr, Mplus_FlashAddress); WriteDOC((unsigned char)((page_addr >> 8) & 0xff), docptr, Mplus_FlashAddress);
/* One more address cycle for higher density devices */ /* One more address cycle for higher density devices */
if (this->chipsize & 0x0c000000) { if (this->chipsize & 0x0c000000) {
WriteDOC((unsigned char) ((page_addr >> 16) & 0x0f), docptr, Mplus_FlashAddress); WriteDOC((unsigned char)((page_addr >> 16) & 0x0f), docptr, Mplus_FlashAddress);
printk("high density\n"); printk("high density\n");
} }
} }
WriteDOC(0, docptr, Mplus_WritePipeTerm); WriteDOC(0, docptr, Mplus_WritePipeTerm);
WriteDOC(0, docptr, Mplus_WritePipeTerm); WriteDOC(0, docptr, Mplus_WritePipeTerm);
/* deassert ALE */ /* deassert ALE */
if (command == NAND_CMD_READ0 || command == NAND_CMD_READ1 || command == NAND_CMD_READOOB || command == NAND_CMD_READID) if (command == NAND_CMD_READ0 || command == NAND_CMD_READ1 ||
command == NAND_CMD_READOOB || command == NAND_CMD_READID)
WriteDOC(0, docptr, Mplus_FlashControl); WriteDOC(0, docptr, Mplus_FlashControl);
} }
...@@ -817,7 +823,7 @@ static void doc2001plus_command (struct mtd_info *mtd, unsigned command, int col ...@@ -817,7 +823,7 @@ static void doc2001plus_command (struct mtd_info *mtd, unsigned command, int col
WriteDOC(NAND_CMD_STATUS, docptr, Mplus_FlashCmd); WriteDOC(NAND_CMD_STATUS, docptr, Mplus_FlashCmd);
WriteDOC(0, docptr, Mplus_WritePipeTerm); WriteDOC(0, docptr, Mplus_WritePipeTerm);
WriteDOC(0, docptr, Mplus_WritePipeTerm); WriteDOC(0, docptr, Mplus_WritePipeTerm);
while ( !(this->read_byte(mtd) & 0x40)); while (!(this->read_byte(mtd) & 0x40)) ;
return; return;
/* This applies to read commands */ /* This applies to read commands */
...@@ -827,16 +833,16 @@ static void doc2001plus_command (struct mtd_info *mtd, unsigned command, int col ...@@ -827,16 +833,16 @@ static void doc2001plus_command (struct mtd_info *mtd, unsigned command, int col
* command delay * command delay
*/ */
if (!this->dev_ready) { if (!this->dev_ready) {
udelay (this->chip_delay); udelay(this->chip_delay);
return; return;
} }
} }
/* Apply this short delay always to ensure that we do wait tWB in /* Apply this short delay always to ensure that we do wait tWB in
* any case on any machine. */ * any case on any machine. */
ndelay (100); ndelay(100);
/* wait until command is processed */ /* wait until command is processed */
while (!this->dev_ready(mtd)); while (!this->dev_ready(mtd)) ;
} }
static int doc200x_dev_ready(struct mtd_info *mtd) static int doc200x_dev_ready(struct mtd_info *mtd)
...@@ -849,23 +855,25 @@ static int doc200x_dev_ready(struct mtd_info *mtd) ...@@ -849,23 +855,25 @@ static int doc200x_dev_ready(struct mtd_info *mtd)
/* 11.4.2 -- must NOP four times before checking FR/B# */ /* 11.4.2 -- must NOP four times before checking FR/B# */
DoC_Delay(doc, 4); DoC_Delay(doc, 4);
if ((ReadDOC(docptr, Mplus_FlashControl) & CDSN_CTRL_FR_B_MASK) != CDSN_CTRL_FR_B_MASK) { if ((ReadDOC(docptr, Mplus_FlashControl) & CDSN_CTRL_FR_B_MASK) != CDSN_CTRL_FR_B_MASK) {
if(debug) if (debug)
printk("not ready\n"); printk("not ready\n");
return 0; return 0;
} }
if (debug)printk("was ready\n"); if (debug)
printk("was ready\n");
return 1; return 1;
} else { } else {
/* 11.4.2 -- must NOP four times before checking FR/B# */ /* 11.4.2 -- must NOP four times before checking FR/B# */
DoC_Delay(doc, 4); DoC_Delay(doc, 4);
if (!(ReadDOC(docptr, CDSNControl) & CDSN_CTRL_FR_B)) { if (!(ReadDOC(docptr, CDSNControl) & CDSN_CTRL_FR_B)) {
if(debug) if (debug)
printk("not ready\n"); printk("not ready\n");
return 0; return 0;
} }
/* 11.4.2 -- Must NOP twice if it's ready */ /* 11.4.2 -- Must NOP twice if it's ready */
DoC_Delay(doc, 2); DoC_Delay(doc, 2);
if (debug)printk("was ready\n"); if (debug)
printk("was ready\n");
return 1; return 1;
} }
} }
...@@ -884,7 +892,7 @@ static void doc200x_enable_hwecc(struct mtd_info *mtd, int mode) ...@@ -884,7 +892,7 @@ static void doc200x_enable_hwecc(struct mtd_info *mtd, int mode)
void __iomem *docptr = doc->virtadr; void __iomem *docptr = doc->virtadr;
/* Prime the ECC engine */ /* Prime the ECC engine */
switch(mode) { switch (mode) {
case NAND_ECC_READ: case NAND_ECC_READ:
WriteDOC(DOC_ECC_RESET, docptr, ECCConf); WriteDOC(DOC_ECC_RESET, docptr, ECCConf);
WriteDOC(DOC_ECC_EN, docptr, ECCConf); WriteDOC(DOC_ECC_EN, docptr, ECCConf);
...@@ -903,7 +911,7 @@ static void doc2001plus_enable_hwecc(struct mtd_info *mtd, int mode) ...@@ -903,7 +911,7 @@ static void doc2001plus_enable_hwecc(struct mtd_info *mtd, int mode)
void __iomem *docptr = doc->virtadr; void __iomem *docptr = doc->virtadr;
/* Prime the ECC engine */ /* Prime the ECC engine */
switch(mode) { switch (mode) {
case NAND_ECC_READ: case NAND_ECC_READ:
WriteDOC(DOC_ECC_RESET, docptr, Mplus_ECCConf); WriteDOC(DOC_ECC_RESET, docptr, Mplus_ECCConf);
WriteDOC(DOC_ECC_EN, docptr, Mplus_ECCConf); WriteDOC(DOC_ECC_EN, docptr, Mplus_ECCConf);
...@@ -916,8 +924,7 @@ static void doc2001plus_enable_hwecc(struct mtd_info *mtd, int mode) ...@@ -916,8 +924,7 @@ static void doc2001plus_enable_hwecc(struct mtd_info *mtd, int mode)
} }
/* This code is only called on write */ /* This code is only called on write */
static int doc200x_calculate_ecc(struct mtd_info *mtd, const u_char *dat, static int doc200x_calculate_ecc(struct mtd_info *mtd, const u_char *dat, unsigned char *ecc_code)
unsigned char *ecc_code)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
struct doc_priv *doc = this->priv; struct doc_priv *doc = this->priv;
...@@ -961,7 +968,8 @@ static int doc200x_calculate_ecc(struct mtd_info *mtd, const u_char *dat, ...@@ -961,7 +968,8 @@ static int doc200x_calculate_ecc(struct mtd_info *mtd, const u_char *dat,
often. It could be optimized away by examining the data in often. It could be optimized away by examining the data in
the writebuf routine, and remembering the result. */ the writebuf routine, and remembering the result. */
for (i = 0; i < 512; i++) { for (i = 0; i < 512; i++) {
if (dat[i] == 0xff) continue; if (dat[i] == 0xff)
continue;
emptymatch = 0; emptymatch = 0;
break; break;
} }
...@@ -969,7 +977,8 @@ static int doc200x_calculate_ecc(struct mtd_info *mtd, const u_char *dat, ...@@ -969,7 +977,8 @@ static int doc200x_calculate_ecc(struct mtd_info *mtd, const u_char *dat,
/* If emptymatch still =1, we do have an all-0xff data buffer. /* If emptymatch still =1, we do have an all-0xff data buffer.
Return all-0xff ecc value instead of the computed one, so Return all-0xff ecc value instead of the computed one, so
it'll look just like a freshly-erased page. */ it'll look just like a freshly-erased page. */
if (emptymatch) memset(ecc_code, 0xff, 6); if (emptymatch)
memset(ecc_code, 0xff, 6);
#endif #endif
return 0; return 0;
} }
...@@ -1012,7 +1021,8 @@ static int doc200x_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_ ...@@ -1012,7 +1021,8 @@ static int doc200x_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_
all-0xff data and stored ecc block. Check the stored ecc. */ all-0xff data and stored ecc block. Check the stored ecc. */
if (emptymatch) { if (emptymatch) {
for (i = 0; i < 6; i++) { for (i = 0; i < 6; i++) {
if (read_ecc[i] == 0xff) continue; if (read_ecc[i] == 0xff)
continue;
emptymatch = 0; emptymatch = 0;
break; break;
} }
...@@ -1023,7 +1033,8 @@ static int doc200x_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_ ...@@ -1023,7 +1033,8 @@ static int doc200x_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_
often. It could be optimized away by examining the data in often. It could be optimized away by examining the data in
the readbuf routine, and remembering the result. */ the readbuf routine, and remembering the result. */
for (i = 0; i < 512; i++) { for (i = 0; i < 512; i++) {
if (dat[i] == 0xff) continue; if (dat[i] == 0xff)
continue;
emptymatch = 0; emptymatch = 0;
break; break;
} }
...@@ -1032,7 +1043,8 @@ static int doc200x_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_ ...@@ -1032,7 +1043,8 @@ static int doc200x_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_
erased block, in which case the ECC will not come out right. erased block, in which case the ECC will not come out right.
We'll suppress the error and tell the caller everything's We'll suppress the error and tell the caller everything's
OK. Because it is. */ OK. Because it is. */
if (!emptymatch) ret = doc_ecc_decode (rs_decoder, dat, calc_ecc); if (!emptymatch)
ret = doc_ecc_decode(rs_decoder, dat, calc_ecc);
if (ret > 0) if (ret > 0)
printk(KERN_ERR "doc200x_correct_data corrected %d errors\n", ret); printk(KERN_ERR "doc200x_correct_data corrected %d errors\n", ret);
} }
...@@ -1063,7 +1075,7 @@ static struct nand_oobinfo doc200x_oobinfo = { ...@@ -1063,7 +1075,7 @@ static struct nand_oobinfo doc200x_oobinfo = {
.useecc = MTD_NANDECC_AUTOPLACE, .useecc = MTD_NANDECC_AUTOPLACE,
.eccbytes = 6, .eccbytes = 6,
.eccpos = {0, 1, 2, 3, 4, 5}, .eccpos = {0, 1, 2, 3, 4, 5},
.oobfree = { {8, 8}, {6, 2} } .oobfree = {{8, 8}, {6, 2}}
}; };
/* Find the (I)NFTL Media Header, and optionally also the mirror media header. /* Find the (I)NFTL Media Header, and optionally also the mirror media header.
...@@ -1072,8 +1084,7 @@ static struct nand_oobinfo doc200x_oobinfo = { ...@@ -1072,8 +1084,7 @@ static struct nand_oobinfo doc200x_oobinfo = {
either "ANAND" or "BNAND". If findmirror=1, also look for the mirror media either "ANAND" or "BNAND". If findmirror=1, also look for the mirror media
header. The page #s of the found media headers are placed in mh0_page and header. The page #s of the found media headers are placed in mh0_page and
mh1_page in the DOC private structure. */ mh1_page in the DOC private structure. */
static int __init find_media_headers(struct mtd_info *mtd, u_char *buf, static int __init find_media_headers(struct mtd_info *mtd, u_char *buf, const char *id, int findmirror)
const char *id, int findmirror)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
struct doc_priv *doc = this->priv; struct doc_priv *doc = this->priv;
...@@ -1083,16 +1094,18 @@ static int __init find_media_headers(struct mtd_info *mtd, u_char *buf, ...@@ -1083,16 +1094,18 @@ static int __init find_media_headers(struct mtd_info *mtd, u_char *buf,
for (offs = 0; offs < mtd->size; offs += mtd->erasesize) { for (offs = 0; offs < mtd->size; offs += mtd->erasesize) {
ret = mtd->read(mtd, offs, mtd->oobblock, &retlen, buf); ret = mtd->read(mtd, offs, mtd->oobblock, &retlen, buf);
if (retlen != mtd->oobblock) continue; if (retlen != mtd->oobblock)
continue;
if (ret) { if (ret) {
printk(KERN_WARNING "ECC error scanning DOC at 0x%x\n", printk(KERN_WARNING "ECC error scanning DOC at 0x%x\n", offs);
offs);
} }
if (memcmp(buf, id, 6)) continue; if (memcmp(buf, id, 6))
continue;
printk(KERN_INFO "Found DiskOnChip %s Media Header at 0x%x\n", id, offs); printk(KERN_INFO "Found DiskOnChip %s Media Header at 0x%x\n", id, offs);
if (doc->mh0_page == -1) { if (doc->mh0_page == -1) {
doc->mh0_page = offs >> this->page_shift; doc->mh0_page = offs >> this->page_shift;
if (!findmirror) return 1; if (!findmirror)
return 1;
continue; continue;
} }
doc->mh1_page = offs >> this->page_shift; doc->mh1_page = offs >> this->page_shift;
...@@ -1114,8 +1127,7 @@ static int __init find_media_headers(struct mtd_info *mtd, u_char *buf, ...@@ -1114,8 +1127,7 @@ static int __init find_media_headers(struct mtd_info *mtd, u_char *buf,
return 1; return 1;
} }
static inline int __init nftl_partscan(struct mtd_info *mtd, static inline int __init nftl_partscan(struct mtd_info *mtd, struct mtd_partition *parts)
struct mtd_partition *parts)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
struct doc_priv *doc = this->priv; struct doc_priv *doc = this->priv;
...@@ -1132,8 +1144,9 @@ static inline int __init nftl_partscan(struct mtd_info *mtd, ...@@ -1132,8 +1144,9 @@ static inline int __init nftl_partscan(struct mtd_info *mtd,
printk(KERN_ERR "DiskOnChip mediaheader kmalloc failed!\n"); printk(KERN_ERR "DiskOnChip mediaheader kmalloc failed!\n");
return 0; return 0;
} }
if (!(numheaders=find_media_headers(mtd, buf, "ANAND", 1))) goto out; if (!(numheaders = find_media_headers(mtd, buf, "ANAND", 1)))
mh = (struct NFTLMediaHeader *) buf; goto out;
mh = (struct NFTLMediaHeader *)buf;
mh->NumEraseUnits = le16_to_cpu(mh->NumEraseUnits); mh->NumEraseUnits = le16_to_cpu(mh->NumEraseUnits);
mh->FirstPhysicalEUN = le16_to_cpu(mh->FirstPhysicalEUN); mh->FirstPhysicalEUN = le16_to_cpu(mh->FirstPhysicalEUN);
...@@ -1211,14 +1224,13 @@ static inline int __init nftl_partscan(struct mtd_info *mtd, ...@@ -1211,14 +1224,13 @@ static inline int __init nftl_partscan(struct mtd_info *mtd,
} }
ret = numparts; ret = numparts;
out: out:
kfree(buf); kfree(buf);
return ret; return ret;
} }
/* This is a stripped-down copy of the code in inftlmount.c */ /* This is a stripped-down copy of the code in inftlmount.c */
static inline int __init inftl_partscan(struct mtd_info *mtd, static inline int __init inftl_partscan(struct mtd_info *mtd, struct mtd_partition *parts)
struct mtd_partition *parts)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
struct doc_priv *doc = this->priv; struct doc_priv *doc = this->priv;
...@@ -1241,9 +1253,10 @@ static inline int __init inftl_partscan(struct mtd_info *mtd, ...@@ -1241,9 +1253,10 @@ static inline int __init inftl_partscan(struct mtd_info *mtd,
return 0; return 0;
} }
if (!find_media_headers(mtd, buf, "BNAND", 0)) goto out; if (!find_media_headers(mtd, buf, "BNAND", 0))
goto out;
doc->mh1_page = doc->mh0_page + (4096 >> this->page_shift); doc->mh1_page = doc->mh0_page + (4096 >> this->page_shift);
mh = (struct INFTLMediaHeader *) buf; mh = (struct INFTLMediaHeader *)buf;
mh->NoOfBootImageBlocks = le32_to_cpu(mh->NoOfBootImageBlocks); mh->NoOfBootImageBlocks = le32_to_cpu(mh->NoOfBootImageBlocks);
mh->NoOfBinaryPartitions = le32_to_cpu(mh->NoOfBinaryPartitions); mh->NoOfBinaryPartitions = le32_to_cpu(mh->NoOfBinaryPartitions);
...@@ -1319,8 +1332,10 @@ static inline int __init inftl_partscan(struct mtd_info *mtd, ...@@ -1319,8 +1332,10 @@ static inline int __init inftl_partscan(struct mtd_info *mtd,
parts[numparts].offset = ip->firstUnit << vshift; parts[numparts].offset = ip->firstUnit << vshift;
parts[numparts].size = (1 + ip->lastUnit - ip->firstUnit) << vshift; parts[numparts].size = (1 + ip->lastUnit - ip->firstUnit) << vshift;
numparts++; numparts++;
if (ip->lastUnit > lastvunit) lastvunit = ip->lastUnit; if (ip->lastUnit > lastvunit)
if (ip->flags & INFTL_LAST) break; lastvunit = ip->lastUnit;
if (ip->flags & INFTL_LAST)
break;
} }
lastvunit++; lastvunit++;
if ((lastvunit << vshift) < end) { if ((lastvunit << vshift) < end) {
...@@ -1330,7 +1345,7 @@ static inline int __init inftl_partscan(struct mtd_info *mtd, ...@@ -1330,7 +1345,7 @@ static inline int __init inftl_partscan(struct mtd_info *mtd,
numparts++; numparts++;
} }
ret = numparts; ret = numparts;
out: out:
kfree(buf); kfree(buf);
return ret; return ret;
} }
...@@ -1342,11 +1357,12 @@ static int __init nftl_scan_bbt(struct mtd_info *mtd) ...@@ -1342,11 +1357,12 @@ static int __init nftl_scan_bbt(struct mtd_info *mtd)
struct doc_priv *doc = this->priv; struct doc_priv *doc = this->priv;
struct mtd_partition parts[2]; struct mtd_partition parts[2];
memset((char *) parts, 0, sizeof(parts)); memset((char *)parts, 0, sizeof(parts));
/* On NFTL, we have to find the media headers before we can read the /* On NFTL, we have to find the media headers before we can read the
BBTs, since they're stored in the media header eraseblocks. */ BBTs, since they're stored in the media header eraseblocks. */
numparts = nftl_partscan(mtd, parts); numparts = nftl_partscan(mtd, parts);
if (!numparts) return -EIO; if (!numparts)
return -EIO;
this->bbt_td->options = NAND_BBT_ABSPAGE | NAND_BBT_8BIT | this->bbt_td->options = NAND_BBT_ABSPAGE | NAND_BBT_8BIT |
NAND_BBT_SAVECONTENT | NAND_BBT_WRITE | NAND_BBT_SAVECONTENT | NAND_BBT_WRITE |
NAND_BBT_VERSION; NAND_BBT_VERSION;
...@@ -1393,8 +1409,7 @@ static int __init inftl_scan_bbt(struct mtd_info *mtd) ...@@ -1393,8 +1409,7 @@ static int __init inftl_scan_bbt(struct mtd_info *mtd)
this->bbt_td->pages[0] = 2; this->bbt_td->pages[0] = 2;
this->bbt_md = NULL; this->bbt_md = NULL;
} else { } else {
this->bbt_td->options = NAND_BBT_LASTBLOCK | NAND_BBT_8BIT | this->bbt_td->options = NAND_BBT_LASTBLOCK | NAND_BBT_8BIT | NAND_BBT_VERSION;
NAND_BBT_VERSION;
if (inftl_bbt_write) if (inftl_bbt_write)
this->bbt_td->options |= NAND_BBT_WRITE; this->bbt_td->options |= NAND_BBT_WRITE;
this->bbt_td->offs = 8; this->bbt_td->offs = 8;
...@@ -1404,8 +1419,7 @@ static int __init inftl_scan_bbt(struct mtd_info *mtd) ...@@ -1404,8 +1419,7 @@ static int __init inftl_scan_bbt(struct mtd_info *mtd)
this->bbt_td->reserved_block_code = 0x01; this->bbt_td->reserved_block_code = 0x01;
this->bbt_td->pattern = "MSYS_BBT"; this->bbt_td->pattern = "MSYS_BBT";
this->bbt_md->options = NAND_BBT_LASTBLOCK | NAND_BBT_8BIT | this->bbt_md->options = NAND_BBT_LASTBLOCK | NAND_BBT_8BIT | NAND_BBT_VERSION;
NAND_BBT_VERSION;
if (inftl_bbt_write) if (inftl_bbt_write)
this->bbt_md->options |= NAND_BBT_WRITE; this->bbt_md->options |= NAND_BBT_WRITE;
this->bbt_md->offs = 8; this->bbt_md->offs = 8;
...@@ -1420,12 +1434,13 @@ static int __init inftl_scan_bbt(struct mtd_info *mtd) ...@@ -1420,12 +1434,13 @@ static int __init inftl_scan_bbt(struct mtd_info *mtd)
At least as nand_bbt.c is currently written. */ At least as nand_bbt.c is currently written. */
if ((ret = nand_scan_bbt(mtd, NULL))) if ((ret = nand_scan_bbt(mtd, NULL)))
return ret; return ret;
memset((char *) parts, 0, sizeof(parts)); memset((char *)parts, 0, sizeof(parts));
numparts = inftl_partscan(mtd, parts); numparts = inftl_partscan(mtd, parts);
/* At least for now, require the INFTL Media Header. We could probably /* At least for now, require the INFTL Media Header. We could probably
do without it for non-INFTL use, since all it gives us is do without it for non-INFTL use, since all it gives us is
autopartitioning, but I want to give it more thought. */ autopartitioning, but I want to give it more thought. */
if (!numparts) return -EIO; if (!numparts)
return -EIO;
add_mtd_device(mtd); add_mtd_device(mtd);
#ifdef CONFIG_MTD_PARTITIONS #ifdef CONFIG_MTD_PARTITIONS
if (!no_autopart) if (!no_autopart)
...@@ -1535,20 +1550,16 @@ static int __init doc_probe(unsigned long physadr) ...@@ -1535,20 +1550,16 @@ static int __init doc_probe(unsigned long physadr)
save_control = ReadDOC(virtadr, DOCControl); save_control = ReadDOC(virtadr, DOCControl);
/* Reset the DiskOnChip ASIC */ /* Reset the DiskOnChip ASIC */
WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_RESET, WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_RESET, virtadr, DOCControl);
virtadr, DOCControl); WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_RESET, virtadr, DOCControl);
WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_RESET,
virtadr, DOCControl);
/* Enable the DiskOnChip ASIC */ /* Enable the DiskOnChip ASIC */
WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_NORMAL, WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_NORMAL, virtadr, DOCControl);
virtadr, DOCControl); WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_NORMAL, virtadr, DOCControl);
WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_NORMAL,
virtadr, DOCControl);
ChipID = ReadDOC(virtadr, ChipID); ChipID = ReadDOC(virtadr, ChipID);
switch(ChipID) { switch (ChipID) {
case DOC_ChipID_Doc2k: case DOC_ChipID_Doc2k:
reg = DoC_2k_ECCStatus; reg = DoC_2k_ECCStatus;
break; break;
...@@ -1564,15 +1575,13 @@ static int __init doc_probe(unsigned long physadr) ...@@ -1564,15 +1575,13 @@ static int __init doc_probe(unsigned long physadr)
ReadDOC(virtadr, Mplus_Power); ReadDOC(virtadr, Mplus_Power);
/* Reset the Millennium Plus ASIC */ /* Reset the Millennium Plus ASIC */
tmp = DOC_MODE_RESET | DOC_MODE_MDWREN | DOC_MODE_RST_LAT | tmp = DOC_MODE_RESET | DOC_MODE_MDWREN | DOC_MODE_RST_LAT | DOC_MODE_BDECT;
DOC_MODE_BDECT;
WriteDOC(tmp, virtadr, Mplus_DOCControl); WriteDOC(tmp, virtadr, Mplus_DOCControl);
WriteDOC(~tmp, virtadr, Mplus_CtrlConfirm); WriteDOC(~tmp, virtadr, Mplus_CtrlConfirm);
mdelay(1); mdelay(1);
/* Enable the Millennium Plus ASIC */ /* Enable the Millennium Plus ASIC */
tmp = DOC_MODE_NORMAL | DOC_MODE_MDWREN | DOC_MODE_RST_LAT | tmp = DOC_MODE_NORMAL | DOC_MODE_MDWREN | DOC_MODE_RST_LAT | DOC_MODE_BDECT;
DOC_MODE_BDECT;
WriteDOC(tmp, virtadr, Mplus_DOCControl); WriteDOC(tmp, virtadr, Mplus_DOCControl);
WriteDOC(~tmp, virtadr, Mplus_CtrlConfirm); WriteDOC(~tmp, virtadr, Mplus_CtrlConfirm);
mdelay(1); mdelay(1);
...@@ -1642,9 +1651,7 @@ static int __init doc_probe(unsigned long physadr) ...@@ -1642,9 +1651,7 @@ static int __init doc_probe(unsigned long physadr)
printk(KERN_NOTICE "DiskOnChip found at 0x%lx\n", physadr); printk(KERN_NOTICE "DiskOnChip found at 0x%lx\n", physadr);
len = sizeof(struct mtd_info) + len = sizeof(struct mtd_info) +
sizeof(struct nand_chip) + sizeof(struct nand_chip) + sizeof(struct doc_priv) + (2 * sizeof(struct nand_bbt_descr));
sizeof(struct doc_priv) +
(2 * sizeof(struct nand_bbt_descr));
mtd = kmalloc(len, GFP_KERNEL); mtd = kmalloc(len, GFP_KERNEL);
if (!mtd) { if (!mtd) {
printk(KERN_ERR "DiskOnChip kmalloc (%d bytes) failed!\n", len); printk(KERN_ERR "DiskOnChip kmalloc (%d bytes) failed!\n", len);
...@@ -1707,11 +1714,11 @@ static int __init doc_probe(unsigned long physadr) ...@@ -1707,11 +1714,11 @@ static int __init doc_probe(unsigned long physadr)
doclist = mtd; doclist = mtd;
return 0; return 0;
notfound: notfound:
/* Put back the contents of the DOCControl register, in case it's not /* Put back the contents of the DOCControl register, in case it's not
actually a DiskOnChip. */ actually a DiskOnChip. */
WriteDOC(save_control, virtadr, DOCControl); WriteDOC(save_control, virtadr, DOCControl);
fail: fail:
iounmap(virtadr); iounmap(virtadr);
return ret; return ret;
} }
...@@ -1748,7 +1755,7 @@ static int __init init_nanddoc(void) ...@@ -1748,7 +1755,7 @@ static int __init init_nanddoc(void)
*/ */
rs_decoder = init_rs(10, 0x409, FCR, 1, NROOTS); rs_decoder = init_rs(10, 0x409, FCR, 1, NROOTS);
if (!rs_decoder) { if (!rs_decoder) {
printk (KERN_ERR "DiskOnChip: Could not create a RS decoder\n"); printk(KERN_ERR "DiskOnChip: Could not create a RS decoder\n");
return -ENOMEM; return -ENOMEM;
} }
...@@ -1758,7 +1765,7 @@ static int __init init_nanddoc(void) ...@@ -1758,7 +1765,7 @@ static int __init init_nanddoc(void)
if (ret < 0) if (ret < 0)
goto outerr; goto outerr;
} else { } else {
for (i=0; (doc_locations[i] != 0xffffffff); i++) { for (i = 0; (doc_locations[i] != 0xffffffff); i++) {
doc_probe(doc_locations[i]); doc_probe(doc_locations[i]);
} }
} }
...@@ -1770,7 +1777,7 @@ static int __init init_nanddoc(void) ...@@ -1770,7 +1777,7 @@ static int __init init_nanddoc(void)
goto outerr; goto outerr;
} }
return 0; return 0;
outerr: outerr:
free_rs(rs_decoder); free_rs(rs_decoder);
return ret; return ret;
} }
......
...@@ -54,29 +54,29 @@ static struct mtd_info *ep7312_mtd = NULL; ...@@ -54,29 +54,29 @@ static struct mtd_info *ep7312_mtd = NULL;
*/ */
static unsigned long ep7312_fio_pbase = EP7312_FIO_PBASE; static unsigned long ep7312_fio_pbase = EP7312_FIO_PBASE;
static void __iomem * ep7312_pxdr = (void __iomem *) EP7312_PXDR; static void __iomem *ep7312_pxdr = (void __iomem *)EP7312_PXDR;
static void __iomem * ep7312_pxddr = (void __iomem *) EP7312_PXDDR; static void __iomem *ep7312_pxddr = (void __iomem *)EP7312_PXDDR;
#ifdef CONFIG_MTD_PARTITIONS #ifdef CONFIG_MTD_PARTITIONS
/* /*
* Define static partitions for flash device * Define static partitions for flash device
*/ */
static struct mtd_partition partition_info[] = { static struct mtd_partition partition_info[] = {
{ .name = "EP7312 Nand Flash", {.name = "EP7312 Nand Flash",
.offset = 0, .offset = 0,
.size = 8*1024*1024 } .size = 8 * 1024 * 1024}
}; };
#define NUM_PARTITIONS 1 #define NUM_PARTITIONS 1
#endif #endif
/* /*
* hardware specific access to control-lines * hardware specific access to control-lines
*/ */
static void ep7312_hwcontrol(struct mtd_info *mtd, int cmd) static void ep7312_hwcontrol(struct mtd_info *mtd, int cmd)
{ {
switch(cmd) { switch (cmd) {
case NAND_CTL_SETCLE: case NAND_CTL_SETCLE:
clps_writeb(clps_readb(ep7312_pxdr) | 0x10, ep7312_pxdr); clps_writeb(clps_readb(ep7312_pxdr) | 0x10, ep7312_pxdr);
...@@ -108,6 +108,7 @@ static int ep7312_device_ready(struct mtd_info *mtd) ...@@ -108,6 +108,7 @@ static int ep7312_device_ready(struct mtd_info *mtd)
{ {
return 1; return 1;
} }
#ifdef CONFIG_MTD_PARTITIONS #ifdef CONFIG_MTD_PARTITIONS
const char *part_probes[] = { "cmdlinepart", NULL }; const char *part_probes[] = { "cmdlinepart", NULL };
#endif #endif
...@@ -115,18 +116,16 @@ const char *part_probes[] = { "cmdlinepart", NULL }; ...@@ -115,18 +116,16 @@ const char *part_probes[] = { "cmdlinepart", NULL };
/* /*
* Main initialization routine * Main initialization routine
*/ */
static int __init ep7312_init (void) static int __init ep7312_init(void)
{ {
struct nand_chip *this; struct nand_chip *this;
const char *part_type = 0; const char *part_type = 0;
int mtd_parts_nb = 0; int mtd_parts_nb = 0;
struct mtd_partition *mtd_parts = 0; struct mtd_partition *mtd_parts = 0;
void __iomem * ep7312_fio_base; void __iomem *ep7312_fio_base;
/* Allocate memory for MTD device structure and private data */ /* Allocate memory for MTD device structure and private data */
ep7312_mtd = kmalloc(sizeof(struct mtd_info) + ep7312_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
sizeof(struct nand_chip),
GFP_KERNEL);
if (!ep7312_mtd) { if (!ep7312_mtd) {
printk("Unable to allocate EDB7312 NAND MTD device structure.\n"); printk("Unable to allocate EDB7312 NAND MTD device structure.\n");
return -ENOMEM; return -ENOMEM;
...@@ -134,18 +133,18 @@ static int __init ep7312_init (void) ...@@ -134,18 +133,18 @@ static int __init ep7312_init (void)
/* map physical adress */ /* map physical adress */
ep7312_fio_base = ioremap(ep7312_fio_pbase, SZ_1K); ep7312_fio_base = ioremap(ep7312_fio_pbase, SZ_1K);
if(!ep7312_fio_base) { if (!ep7312_fio_base) {
printk("ioremap EDB7312 NAND flash failed\n"); printk("ioremap EDB7312 NAND flash failed\n");
kfree(ep7312_mtd); kfree(ep7312_mtd);
return -EIO; return -EIO;
} }
/* Get pointer to private data */ /* Get pointer to private data */
this = (struct nand_chip *) (&ep7312_mtd[1]); this = (struct nand_chip *)(&ep7312_mtd[1]);
/* Initialize structures */ /* Initialize structures */
memset((char *) ep7312_mtd, 0, sizeof(struct mtd_info)); memset(ep7312_mtd, 0, sizeof(struct mtd_info));
memset((char *) this, 0, sizeof(struct nand_chip)); memset(this, 0, sizeof(struct nand_chip));
/* Link the private data with the MTD structure */ /* Link the private data with the MTD structure */
ep7312_mtd->priv = this; ep7312_mtd->priv = this;
...@@ -165,16 +164,14 @@ static int __init ep7312_init (void) ...@@ -165,16 +164,14 @@ static int __init ep7312_init (void)
this->chip_delay = 15; this->chip_delay = 15;
/* Scan to find existence of the device */ /* Scan to find existence of the device */
if (nand_scan (ep7312_mtd, 1)) { if (nand_scan(ep7312_mtd, 1)) {
iounmap((void *)ep7312_fio_base); iounmap((void *)ep7312_fio_base);
kfree (ep7312_mtd); kfree(ep7312_mtd);
return -ENXIO; return -ENXIO;
} }
#ifdef CONFIG_MTD_PARTITIONS #ifdef CONFIG_MTD_PARTITIONS
ep7312_mtd->name = "edb7312-nand"; ep7312_mtd->name = "edb7312-nand";
mtd_parts_nb = parse_mtd_partitions(ep7312_mtd, part_probes, mtd_parts_nb = parse_mtd_partitions(ep7312_mtd, part_probes, &mtd_parts, 0);
&mtd_parts, 0);
if (mtd_parts_nb > 0) if (mtd_parts_nb > 0)
part_type = "command line"; part_type = "command line";
else else
...@@ -193,24 +190,26 @@ static int __init ep7312_init (void) ...@@ -193,24 +190,26 @@ static int __init ep7312_init (void)
/* Return happy */ /* Return happy */
return 0; return 0;
} }
module_init(ep7312_init); module_init(ep7312_init);
/* /*
* Clean up routine * Clean up routine
*/ */
static void __exit ep7312_cleanup (void) static void __exit ep7312_cleanup(void)
{ {
struct nand_chip *this = (struct nand_chip *) &ep7312_mtd[1]; struct nand_chip *this = (struct nand_chip *)&ep7312_mtd[1];
/* Release resources, unregister device */ /* Release resources, unregister device */
nand_release (ap7312_mtd); nand_release(ap7312_mtd);
/* Free internal data buffer */ /* Free internal data buffer */
kfree (this->data_buf); kfree(this->data_buf);
/* Free the MTD device structure */ /* Free the MTD device structure */
kfree (ep7312_mtd); kfree(ep7312_mtd);
} }
module_exit(ep7312_cleanup); module_exit(ep7312_cleanup);
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
......
...@@ -45,23 +45,23 @@ static struct mtd_info *h1910_nand_mtd = NULL; ...@@ -45,23 +45,23 @@ static struct mtd_info *h1910_nand_mtd = NULL;
* Define static partitions for flash device * Define static partitions for flash device
*/ */
static struct mtd_partition partition_info[] = { static struct mtd_partition partition_info[] = {
{ name: "h1910 NAND Flash", {name:"h1910 NAND Flash",
offset: 0, offset:0,
size: 16*1024*1024 } size:16 * 1024 * 1024}
}; };
#define NUM_PARTITIONS 1 #define NUM_PARTITIONS 1
#endif #endif
/* /*
* hardware specific access to control-lines * hardware specific access to control-lines
*/ */
static void h1910_hwcontrol(struct mtd_info *mtd, int cmd) static void h1910_hwcontrol(struct mtd_info *mtd, int cmd)
{ {
struct nand_chip* this = (struct nand_chip *) (mtd->priv); struct nand_chip *this = (struct nand_chip *)(mtd->priv);
switch(cmd) { switch (cmd) {
case NAND_CTL_SETCLE: case NAND_CTL_SETCLE:
this->IO_ADDR_R |= (1 << 2); this->IO_ADDR_R |= (1 << 2);
...@@ -101,7 +101,7 @@ static int h1910_device_ready(struct mtd_info *mtd) ...@@ -101,7 +101,7 @@ static int h1910_device_ready(struct mtd_info *mtd)
/* /*
* Main initialization routine * Main initialization routine
*/ */
static int __init h1910_init (void) static int __init h1910_init(void)
{ {
struct nand_chip *this; struct nand_chip *this;
const char *part_type = 0; const char *part_type = 0;
...@@ -119,21 +119,19 @@ static int __init h1910_init (void) ...@@ -119,21 +119,19 @@ static int __init h1910_init (void)
} }
/* Allocate memory for MTD device structure and private data */ /* Allocate memory for MTD device structure and private data */
h1910_nand_mtd = kmalloc(sizeof(struct mtd_info) + h1910_nand_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
sizeof(struct nand_chip),
GFP_KERNEL);
if (!h1910_nand_mtd) { if (!h1910_nand_mtd) {
printk("Unable to allocate h1910 NAND MTD device structure.\n"); printk("Unable to allocate h1910 NAND MTD device structure.\n");
iounmap ((void *) nandaddr); iounmap((void *)nandaddr);
return -ENOMEM; return -ENOMEM;
} }
/* Get pointer to private data */ /* Get pointer to private data */
this = (struct nand_chip *) (&h1910_nand_mtd[1]); this = (struct nand_chip *)(&h1910_nand_mtd[1]);
/* Initialize structures */ /* Initialize structures */
memset((char *) h1910_nand_mtd, 0, sizeof(struct mtd_info)); memset(h1910_nand_mtd, 0, sizeof(struct mtd_info));
memset((char *) this, 0, sizeof(struct nand_chip)); memset(this, 0, sizeof(struct nand_chip));
/* Link the private data with the MTD structure */ /* Link the private data with the MTD structure */
h1910_nand_mtd->priv = this; h1910_nand_mtd->priv = this;
...@@ -154,23 +152,20 @@ static int __init h1910_init (void) ...@@ -154,23 +152,20 @@ static int __init h1910_init (void)
this->options = NAND_NO_AUTOINCR; this->options = NAND_NO_AUTOINCR;
/* Scan to find existence of the device */ /* Scan to find existence of the device */
if (nand_scan (h1910_nand_mtd, 1)) { if (nand_scan(h1910_nand_mtd, 1)) {
printk(KERN_NOTICE "No NAND device - returning -ENXIO\n"); printk(KERN_NOTICE "No NAND device - returning -ENXIO\n");
kfree (h1910_nand_mtd); kfree(h1910_nand_mtd);
iounmap ((void *) nandaddr); iounmap((void *)nandaddr);
return -ENXIO; return -ENXIO;
} }
#ifdef CONFIG_MTD_CMDLINE_PARTS #ifdef CONFIG_MTD_CMDLINE_PARTS
mtd_parts_nb = parse_cmdline_partitions(h1910_nand_mtd, &mtd_parts, mtd_parts_nb = parse_cmdline_partitions(h1910_nand_mtd, &mtd_parts, "h1910-nand");
"h1910-nand");
if (mtd_parts_nb > 0) if (mtd_parts_nb > 0)
part_type = "command line"; part_type = "command line";
else else
mtd_parts_nb = 0; mtd_parts_nb = 0;
#endif #endif
if (mtd_parts_nb == 0) if (mtd_parts_nb == 0) {
{
mtd_parts = partition_info; mtd_parts = partition_info;
mtd_parts_nb = NUM_PARTITIONS; mtd_parts_nb = NUM_PARTITIONS;
part_type = "static"; part_type = "static";
...@@ -183,24 +178,26 @@ static int __init h1910_init (void) ...@@ -183,24 +178,26 @@ static int __init h1910_init (void)
/* Return happy */ /* Return happy */
return 0; return 0;
} }
module_init(h1910_init); module_init(h1910_init);
/* /*
* Clean up routine * Clean up routine
*/ */
static void __exit h1910_cleanup (void) static void __exit h1910_cleanup(void)
{ {
struct nand_chip *this = (struct nand_chip *) &h1910_nand_mtd[1]; struct nand_chip *this = (struct nand_chip *)&h1910_nand_mtd[1];
/* Release resources, unregister device */ /* Release resources, unregister device */
nand_release (h1910_nand_mtd); nand_release(h1910_nand_mtd);
/* Release io resource */ /* Release io resource */
iounmap ((void *) this->IO_ADDR_W); iounmap((void *)this->IO_ADDR_W);
/* Free the MTD device structure */ /* Free the MTD device structure */
kfree (h1910_nand_mtd); kfree(h1910_nand_mtd);
} }
module_exit(h1910_cleanup); module_exit(h1910_cleanup);
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
......
...@@ -92,14 +92,14 @@ static struct nand_oobinfo nand_oob_8 = { ...@@ -92,14 +92,14 @@ static struct nand_oobinfo nand_oob_8 = {
.useecc = MTD_NANDECC_AUTOPLACE, .useecc = MTD_NANDECC_AUTOPLACE,
.eccbytes = 3, .eccbytes = 3,
.eccpos = {0, 1, 2}, .eccpos = {0, 1, 2},
.oobfree = { {3, 2}, {6, 2} } .oobfree = {{3, 2}, {6, 2}}
}; };
static struct nand_oobinfo nand_oob_16 = { static struct nand_oobinfo nand_oob_16 = {
.useecc = MTD_NANDECC_AUTOPLACE, .useecc = MTD_NANDECC_AUTOPLACE,
.eccbytes = 6, .eccbytes = 6,
.eccpos = {0, 1, 2, 3, 6, 7}, .eccpos = {0, 1, 2, 3, 6, 7},
.oobfree = { {8, 8} } .oobfree = {{8, 8}}
}; };
static struct nand_oobinfo nand_oob_64 = { static struct nand_oobinfo nand_oob_64 = {
...@@ -109,7 +109,7 @@ static struct nand_oobinfo nand_oob_64 = { ...@@ -109,7 +109,7 @@ static struct nand_oobinfo nand_oob_64 = {
40, 41, 42, 43, 44, 45, 46, 47, 40, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55, 48, 49, 50, 51, 52, 53, 54, 55,
56, 57, 58, 59, 60, 61, 62, 63}, 56, 57, 58, 59, 60, 61, 62, 63},
.oobfree = { {2, 38} } .oobfree = {{2, 38}}
}; };
/* This is used for padding purposes in nand_write_oob */ /* This is used for padding purposes in nand_write_oob */
...@@ -131,32 +131,32 @@ static void nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len); ...@@ -131,32 +131,32 @@ static void nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len);
static void nand_read_buf(struct mtd_info *mtd, u_char *buf, int len); static void nand_read_buf(struct mtd_info *mtd, u_char *buf, int len);
static int nand_verify_buf(struct mtd_info *mtd, const u_char *buf, int len); static int nand_verify_buf(struct mtd_info *mtd, const u_char *buf, int len);
static int nand_read (struct mtd_info *mtd, loff_t from, size_t len, size_t * retlen, u_char * buf); static int nand_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
static int nand_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, static int nand_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
size_t * retlen, u_char * buf, u_char * eccbuf, struct nand_oobinfo *oobsel); size_t *retlen, u_char *buf, u_char *eccbuf, struct nand_oobinfo *oobsel);
static int nand_read_oob (struct mtd_info *mtd, loff_t from, size_t len, size_t * retlen, u_char * buf); static int nand_read_oob(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
static int nand_write (struct mtd_info *mtd, loff_t to, size_t len, size_t * retlen, const u_char * buf); static int nand_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf);
static int nand_write_ecc (struct mtd_info *mtd, loff_t to, size_t len, static int nand_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
size_t * retlen, const u_char * buf, u_char * eccbuf, struct nand_oobinfo *oobsel); size_t *retlen, const u_char *buf, u_char *eccbuf, struct nand_oobinfo *oobsel);
static int nand_write_oob (struct mtd_info *mtd, loff_t to, size_t len, size_t * retlen, const u_char *buf); static int nand_write_oob(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf);
static int nand_writev (struct mtd_info *mtd, const struct kvec *vecs, static int nand_writev(struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, loff_t to, size_t *retlen);
unsigned long count, loff_t to, size_t * retlen); static int nand_writev_ecc(struct mtd_info *mtd, const struct kvec *vecs,
static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, loff_t to, size_t *retlen, u_char *eccbuf,
unsigned long count, loff_t to, size_t * retlen, u_char *eccbuf, struct nand_oobinfo *oobsel); struct nand_oobinfo *oobsel);
static int nand_erase (struct mtd_info *mtd, struct erase_info *instr); static int nand_erase(struct mtd_info *mtd, struct erase_info *instr);
static void nand_sync (struct mtd_info *mtd); static void nand_sync(struct mtd_info *mtd);
/* Some internal functions */ /* Some internal functions */
static int nand_write_page (struct mtd_info *mtd, struct nand_chip *this, int page, u_char *oob_buf, static int nand_write_page(struct mtd_info *mtd, struct nand_chip *this, int page, u_char * oob_buf,
struct nand_oobinfo *oobsel, int mode); struct nand_oobinfo *oobsel, int mode);
#ifdef CONFIG_MTD_NAND_VERIFY_WRITE #ifdef CONFIG_MTD_NAND_VERIFY_WRITE
static int nand_verify_pages (struct mtd_info *mtd, struct nand_chip *this, int page, int numpages, static int nand_verify_pages(struct mtd_info *mtd, struct nand_chip *this, int page, int numpages,
u_char *oob_buf, struct nand_oobinfo *oobsel, int chipnr, int oobmode); u_char *oob_buf, struct nand_oobinfo *oobsel, int chipnr, int oobmode);
#else #else
#define nand_verify_pages(...) (0) #define nand_verify_pages(...) (0)
#endif #endif
static int nand_get_device (struct nand_chip *this, struct mtd_info *mtd, int new_state); static int nand_get_device(struct nand_chip *this, struct mtd_info *mtd, int new_state);
/** /**
* nand_release_device - [GENERIC] release chip * nand_release_device - [GENERIC] release chip
...@@ -164,7 +164,7 @@ static int nand_get_device (struct nand_chip *this, struct mtd_info *mtd, int ne ...@@ -164,7 +164,7 @@ static int nand_get_device (struct nand_chip *this, struct mtd_info *mtd, int ne
* *
* Deselect, release chip lock and wake up anyone waiting on the device * Deselect, release chip lock and wake up anyone waiting on the device
*/ */
static void nand_release_device (struct mtd_info *mtd) static void nand_release_device(struct mtd_info *mtd)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
...@@ -276,7 +276,7 @@ static void nand_write_word(struct mtd_info *mtd, u16 word) ...@@ -276,7 +276,7 @@ static void nand_write_word(struct mtd_info *mtd, u16 word)
static void nand_select_chip(struct mtd_info *mtd, int chip) static void nand_select_chip(struct mtd_info *mtd, int chip)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
switch(chip) { switch (chip) {
case -1: case -1:
this->hwcontrol(mtd, NAND_CTL_CLRNCE); this->hwcontrol(mtd, NAND_CTL_CLRNCE);
break; break;
...@@ -302,7 +302,7 @@ static void nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len) ...@@ -302,7 +302,7 @@ static void nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
int i; int i;
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
for (i=0; i<len; i++) for (i = 0; i < len; i++)
writeb(buf[i], this->IO_ADDR_W); writeb(buf[i], this->IO_ADDR_W);
} }
...@@ -319,7 +319,7 @@ static void nand_read_buf(struct mtd_info *mtd, u_char *buf, int len) ...@@ -319,7 +319,7 @@ static void nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
int i; int i;
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
for (i=0; i<len; i++) for (i = 0; i < len; i++)
buf[i] = readb(this->IO_ADDR_R); buf[i] = readb(this->IO_ADDR_R);
} }
...@@ -336,7 +336,7 @@ static int nand_verify_buf(struct mtd_info *mtd, const u_char *buf, int len) ...@@ -336,7 +336,7 @@ static int nand_verify_buf(struct mtd_info *mtd, const u_char *buf, int len)
int i; int i;
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
for (i=0; i<len; i++) for (i = 0; i < len; i++)
if (buf[i] != readb(this->IO_ADDR_R)) if (buf[i] != readb(this->IO_ADDR_R))
return -EFAULT; return -EFAULT;
...@@ -358,7 +358,7 @@ static void nand_write_buf16(struct mtd_info *mtd, const u_char *buf, int len) ...@@ -358,7 +358,7 @@ static void nand_write_buf16(struct mtd_info *mtd, const u_char *buf, int len)
u16 *p = (u16 *) buf; u16 *p = (u16 *) buf;
len >>= 1; len >>= 1;
for (i=0; i<len; i++) for (i = 0; i < len; i++)
writew(p[i], this->IO_ADDR_W); writew(p[i], this->IO_ADDR_W);
} }
...@@ -378,7 +378,7 @@ static void nand_read_buf16(struct mtd_info *mtd, u_char *buf, int len) ...@@ -378,7 +378,7 @@ static void nand_read_buf16(struct mtd_info *mtd, u_char *buf, int len)
u16 *p = (u16 *) buf; u16 *p = (u16 *) buf;
len >>= 1; len >>= 1;
for (i=0; i<len; i++) for (i = 0; i < len; i++)
p[i] = readw(this->IO_ADDR_R); p[i] = readw(this->IO_ADDR_R);
} }
...@@ -397,7 +397,7 @@ static int nand_verify_buf16(struct mtd_info *mtd, const u_char *buf, int len) ...@@ -397,7 +397,7 @@ static int nand_verify_buf16(struct mtd_info *mtd, const u_char *buf, int len)
u16 *p = (u16 *) buf; u16 *p = (u16 *) buf;
len >>= 1; len >>= 1;
for (i=0; i<len; i++) for (i = 0; i < len; i++)
if (p[i] != readw(this->IO_ADDR_R)) if (p[i] != readw(this->IO_ADDR_R))
return -EFAULT; return -EFAULT;
...@@ -423,22 +423,22 @@ static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip) ...@@ -423,22 +423,22 @@ static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip)
chipnr = (int)(ofs >> this->chip_shift); chipnr = (int)(ofs >> this->chip_shift);
/* Grab the lock and see if the device is available */ /* Grab the lock and see if the device is available */
nand_get_device (this, mtd, FL_READING); nand_get_device(this, mtd, FL_READING);
/* Select the NAND device */ /* Select the NAND device */
this->select_chip(mtd, chipnr); this->select_chip(mtd, chipnr);
} else } else
page = (int) ofs; page = (int)ofs;
if (this->options & NAND_BUSWIDTH_16) { if (this->options & NAND_BUSWIDTH_16) {
this->cmdfunc (mtd, NAND_CMD_READOOB, this->badblockpos & 0xFE, page & this->pagemask); this->cmdfunc(mtd, NAND_CMD_READOOB, this->badblockpos & 0xFE, page & this->pagemask);
bad = cpu_to_le16(this->read_word(mtd)); bad = cpu_to_le16(this->read_word(mtd));
if (this->badblockpos & 0x1) if (this->badblockpos & 0x1)
bad >>= 8; bad >>= 8;
if ((bad & 0xFF) != 0xff) if ((bad & 0xFF) != 0xff)
res = 1; res = 1;
} else { } else {
this->cmdfunc (mtd, NAND_CMD_READOOB, this->badblockpos, page & this->pagemask); this->cmdfunc(mtd, NAND_CMD_READOOB, this->badblockpos, page & this->pagemask);
if (this->read_byte(mtd) != 0xff) if (this->read_byte(mtd) != 0xff)
res = 1; res = 1;
} }
...@@ -462,22 +462,22 @@ static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip) ...@@ -462,22 +462,22 @@ static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip)
static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs) static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
u_char buf[2] = {0, 0}; u_char buf[2] = { 0, 0 };
size_t retlen; size_t retlen;
int block; int block;
/* Get block number */ /* Get block number */
block = ((int) ofs) >> this->bbt_erase_shift; block = ((int)ofs) >> this->bbt_erase_shift;
if (this->bbt) if (this->bbt)
this->bbt[block >> 2] |= 0x01 << ((block & 0x03) << 1); this->bbt[block >> 2] |= 0x01 << ((block & 0x03) << 1);
/* Do we have a flash based bad block table ? */ /* Do we have a flash based bad block table ? */
if (this->options & NAND_USE_FLASH_BBT) if (this->options & NAND_USE_FLASH_BBT)
return nand_update_bbt (mtd, ofs); return nand_update_bbt(mtd, ofs);
/* We write two bytes, so we dont have to mess with 16 bit access */ /* We write two bytes, so we dont have to mess with 16 bit access */
ofs += mtd->oobsize + (this->badblockpos & ~0x01); ofs += mtd->oobsize + (this->badblockpos & ~0x01);
return nand_write_oob (mtd, ofs , 2, &retlen, buf); return nand_write_oob(mtd, ofs, 2, &retlen, buf);
} }
/** /**
...@@ -487,11 +487,11 @@ static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs) ...@@ -487,11 +487,11 @@ static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs)
* *
* The function expects, that the device is already selected * The function expects, that the device is already selected
*/ */
static int nand_check_wp (struct mtd_info *mtd) static int nand_check_wp(struct mtd_info *mtd)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
/* Check the WP bit */ /* Check the WP bit */
this->cmdfunc (mtd, NAND_CMD_STATUS, -1, -1); this->cmdfunc(mtd, NAND_CMD_STATUS, -1, -1);
return (this->read_byte(mtd) & NAND_STATUS_WP) ? 0 : 1; return (this->read_byte(mtd) & NAND_STATUS_WP) ? 0 : 1;
} }
...@@ -505,7 +505,7 @@ static int nand_check_wp (struct mtd_info *mtd) ...@@ -505,7 +505,7 @@ static int nand_check_wp (struct mtd_info *mtd)
* Check, if the block is bad. Either by reading the bad block table or * Check, if the block is bad. Either by reading the bad block table or
* calling of the scan function. * calling of the scan function.
*/ */
static int nand_block_checkbad (struct mtd_info *mtd, loff_t ofs, int getchip, int allowbbt) static int nand_block_checkbad(struct mtd_info *mtd, loff_t ofs, int getchip, int allowbbt)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
...@@ -513,7 +513,7 @@ static int nand_block_checkbad (struct mtd_info *mtd, loff_t ofs, int getchip, i ...@@ -513,7 +513,7 @@ static int nand_block_checkbad (struct mtd_info *mtd, loff_t ofs, int getchip, i
return this->block_bad(mtd, ofs, getchip); return this->block_bad(mtd, ofs, getchip);
/* Return info from the table */ /* Return info from the table */
return nand_isbad_bbt (mtd, ofs, allowbbt); return nand_isbad_bbt(mtd, ofs, allowbbt);
} }
DEFINE_LED_TRIGGER(nand_led_trigger); DEFINE_LED_TRIGGER(nand_led_trigger);
...@@ -547,7 +547,7 @@ static void nand_wait_ready(struct mtd_info *mtd) ...@@ -547,7 +547,7 @@ static void nand_wait_ready(struct mtd_info *mtd)
* Send command to NAND device. This function is used for small page * Send command to NAND device. This function is used for small page
* devices (256/512 Bytes per page) * devices (256/512 Bytes per page)
*/ */
static void nand_command (struct mtd_info *mtd, unsigned command, int column, int page_addr) static void nand_command(struct mtd_info *mtd, unsigned command, int column, int page_addr)
{ {
register struct nand_chip *this = mtd->priv; register struct nand_chip *this = mtd->priv;
...@@ -588,11 +588,11 @@ static void nand_command (struct mtd_info *mtd, unsigned command, int column, in ...@@ -588,11 +588,11 @@ static void nand_command (struct mtd_info *mtd, unsigned command, int column, in
this->write_byte(mtd, column); this->write_byte(mtd, column);
} }
if (page_addr != -1) { if (page_addr != -1) {
this->write_byte(mtd, (unsigned char) (page_addr & 0xff)); this->write_byte(mtd, (unsigned char)(page_addr & 0xff));
this->write_byte(mtd, (unsigned char) ((page_addr >> 8) & 0xff)); this->write_byte(mtd, (unsigned char)((page_addr >> 8) & 0xff));
/* One more address cycle for devices > 32MiB */ /* One more address cycle for devices > 32MiB */
if (this->chipsize > (32 << 20)) if (this->chipsize > (32 << 20))
this->write_byte(mtd, (unsigned char) ((page_addr >> 16) & 0x0f)); this->write_byte(mtd, (unsigned char)((page_addr >> 16) & 0x0f));
} }
/* Latch in address */ /* Latch in address */
this->hwcontrol(mtd, NAND_CTL_CLRALE); this->hwcontrol(mtd, NAND_CTL_CLRALE);
...@@ -618,7 +618,7 @@ static void nand_command (struct mtd_info *mtd, unsigned command, int column, in ...@@ -618,7 +618,7 @@ static void nand_command (struct mtd_info *mtd, unsigned command, int column, in
this->hwcontrol(mtd, NAND_CTL_SETCLE); this->hwcontrol(mtd, NAND_CTL_SETCLE);
this->write_byte(mtd, NAND_CMD_STATUS); this->write_byte(mtd, NAND_CMD_STATUS);
this->hwcontrol(mtd, NAND_CTL_CLRCLE); this->hwcontrol(mtd, NAND_CTL_CLRCLE);
while ( !(this->read_byte(mtd) & NAND_STATUS_READY)); while (!(this->read_byte(mtd) & NAND_STATUS_READY)) ;
return; return;
/* This applies to read commands */ /* This applies to read commands */
...@@ -628,13 +628,13 @@ static void nand_command (struct mtd_info *mtd, unsigned command, int column, in ...@@ -628,13 +628,13 @@ static void nand_command (struct mtd_info *mtd, unsigned command, int column, in
* command delay * command delay
*/ */
if (!this->dev_ready) { if (!this->dev_ready) {
udelay (this->chip_delay); udelay(this->chip_delay);
return; return;
} }
} }
/* Apply this short delay always to ensure that we do wait tWB in /* Apply this short delay always to ensure that we do wait tWB in
* any case on any machine. */ * any case on any machine. */
ndelay (100); ndelay(100);
nand_wait_ready(mtd); nand_wait_ready(mtd);
} }
...@@ -647,11 +647,11 @@ static void nand_command (struct mtd_info *mtd, unsigned command, int column, in ...@@ -647,11 +647,11 @@ static void nand_command (struct mtd_info *mtd, unsigned command, int column, in
* @page_addr: the page address for this command, -1 if none * @page_addr: the page address for this command, -1 if none
* *
* Send command to NAND device. This is the version for the new large page devices * Send command to NAND device. This is the version for the new large page devices
* We dont have the seperate regions as we have in the small page devices. * We dont have the separate regions as we have in the small page devices.
* We must emulate NAND_CMD_READOOB to keep the code compatible. * We must emulate NAND_CMD_READOOB to keep the code compatible.
* *
*/ */
static void nand_command_lp (struct mtd_info *mtd, unsigned command, int column, int page_addr) static void nand_command_lp(struct mtd_info *mtd, unsigned command, int column, int page_addr)
{ {
register struct nand_chip *this = mtd->priv; register struct nand_chip *this = mtd->priv;
...@@ -661,7 +661,6 @@ static void nand_command_lp (struct mtd_info *mtd, unsigned command, int column, ...@@ -661,7 +661,6 @@ static void nand_command_lp (struct mtd_info *mtd, unsigned command, int column,
command = NAND_CMD_READ0; command = NAND_CMD_READ0;
} }
/* Begin command latch cycle */ /* Begin command latch cycle */
this->hwcontrol(mtd, NAND_CTL_SETCLE); this->hwcontrol(mtd, NAND_CTL_SETCLE);
/* Write out the command to the device. */ /* Write out the command to the device. */
...@@ -681,11 +680,11 @@ static void nand_command_lp (struct mtd_info *mtd, unsigned command, int column, ...@@ -681,11 +680,11 @@ static void nand_command_lp (struct mtd_info *mtd, unsigned command, int column,
this->write_byte(mtd, column >> 8); this->write_byte(mtd, column >> 8);
} }
if (page_addr != -1) { if (page_addr != -1) {
this->write_byte(mtd, (unsigned char) (page_addr & 0xff)); this->write_byte(mtd, (unsigned char)(page_addr & 0xff));
this->write_byte(mtd, (unsigned char) ((page_addr >> 8) & 0xff)); this->write_byte(mtd, (unsigned char)((page_addr >> 8) & 0xff));
/* One more address cycle for devices > 128MiB */ /* One more address cycle for devices > 128MiB */
if (this->chipsize > (128 << 20)) if (this->chipsize > (128 << 20))
this->write_byte(mtd, (unsigned char) ((page_addr >> 16) & 0xff)); this->write_byte(mtd, (unsigned char)((page_addr >> 16) & 0xff));
} }
/* Latch in address */ /* Latch in address */
this->hwcontrol(mtd, NAND_CTL_CLRALE); this->hwcontrol(mtd, NAND_CTL_CLRALE);
...@@ -724,7 +723,7 @@ static void nand_command_lp (struct mtd_info *mtd, unsigned command, int column, ...@@ -724,7 +723,7 @@ static void nand_command_lp (struct mtd_info *mtd, unsigned command, int column,
this->hwcontrol(mtd, NAND_CTL_SETCLE); this->hwcontrol(mtd, NAND_CTL_SETCLE);
this->write_byte(mtd, NAND_CMD_STATUS); this->write_byte(mtd, NAND_CMD_STATUS);
this->hwcontrol(mtd, NAND_CTL_CLRCLE); this->hwcontrol(mtd, NAND_CTL_CLRCLE);
while ( !(this->read_byte(mtd) & NAND_STATUS_READY)); while (!(this->read_byte(mtd) & NAND_STATUS_READY)) ;
return; return;
case NAND_CMD_READ0: case NAND_CMD_READ0:
...@@ -743,14 +742,14 @@ static void nand_command_lp (struct mtd_info *mtd, unsigned command, int column, ...@@ -743,14 +742,14 @@ static void nand_command_lp (struct mtd_info *mtd, unsigned command, int column,
* command delay * command delay
*/ */
if (!this->dev_ready) { if (!this->dev_ready) {
udelay (this->chip_delay); udelay(this->chip_delay);
return; return;
} }
} }
/* Apply this short delay always to ensure that we do wait tWB in /* Apply this short delay always to ensure that we do wait tWB in
* any case on any machine. */ * any case on any machine. */
ndelay (100); ndelay(100);
nand_wait_ready(mtd); nand_wait_ready(mtd);
} }
...@@ -763,16 +762,16 @@ static void nand_command_lp (struct mtd_info *mtd, unsigned command, int column, ...@@ -763,16 +762,16 @@ static void nand_command_lp (struct mtd_info *mtd, unsigned command, int column,
* *
* Get the device and lock it for exclusive access * Get the device and lock it for exclusive access
*/ */
static int nand_get_device (struct nand_chip *this, struct mtd_info *mtd, int new_state) static int nand_get_device(struct nand_chip *this, struct mtd_info *mtd, int new_state)
{ {
struct nand_chip *active; struct nand_chip *active;
spinlock_t *lock; spinlock_t *lock;
wait_queue_head_t *wq; wait_queue_head_t *wq;
DECLARE_WAITQUEUE (wait, current); DECLARE_WAITQUEUE(wait, current);
lock = (this->controller) ? &this->controller->lock : &this->chip_lock; lock = (this->controller) ? &this->controller->lock : &this->chip_lock;
wq = (this->controller) ? &this->controller->wq : &this->wq; wq = (this->controller) ? &this->controller->wq : &this->wq;
retry: retry:
active = this; active = this;
spin_lock(lock); spin_lock(lock);
...@@ -826,12 +825,12 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *this, int state) ...@@ -826,12 +825,12 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *this, int state)
/* Apply this short delay always to ensure that we do wait tWB in /* Apply this short delay always to ensure that we do wait tWB in
* any case on any machine. */ * any case on any machine. */
ndelay (100); ndelay(100);
if ((state == FL_ERASING) && (this->options & NAND_IS_AND)) if ((state == FL_ERASING) && (this->options & NAND_IS_AND))
this->cmdfunc (mtd, NAND_CMD_STATUS_MULTI, -1, -1); this->cmdfunc(mtd, NAND_CMD_STATUS_MULTI, -1, -1);
else else
this->cmdfunc (mtd, NAND_CMD_STATUS, -1, -1); this->cmdfunc(mtd, NAND_CMD_STATUS, -1, -1);
while (time_before(jiffies, timeo)) { while (time_before(jiffies, timeo)) {
/* Check, if we were interrupted */ /* Check, if we were interrupted */
...@@ -849,7 +848,7 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *this, int state) ...@@ -849,7 +848,7 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *this, int state)
} }
led_trigger_event(nand_led_trigger, LED_OFF); led_trigger_event(nand_led_trigger, LED_OFF);
status = (int) this->read_byte(mtd); status = (int)this->read_byte(mtd);
return status; return status;
} }
...@@ -868,7 +867,7 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *this, int state) ...@@ -868,7 +867,7 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *this, int state)
* *
* Cached programming is not supported yet. * Cached programming is not supported yet.
*/ */
static int nand_write_page (struct mtd_info *mtd, struct nand_chip *this, int page, static int nand_write_page(struct mtd_info *mtd, struct nand_chip *this, int page,
u_char *oob_buf, struct nand_oobinfo *oobsel, int cached) u_char *oob_buf, struct nand_oobinfo *oobsel, int cached)
{ {
int i, status; int i, status;
...@@ -882,13 +881,13 @@ static int nand_write_page (struct mtd_info *mtd, struct nand_chip *this, int pa ...@@ -882,13 +881,13 @@ static int nand_write_page (struct mtd_info *mtd, struct nand_chip *this, int pa
cached = 0; cached = 0;
/* Send command to begin auto page programming */ /* Send command to begin auto page programming */
this->cmdfunc (mtd, NAND_CMD_SEQIN, 0x00, page); this->cmdfunc(mtd, NAND_CMD_SEQIN, 0x00, page);
/* Write out complete page of data, take care of eccmode */ /* Write out complete page of data, take care of eccmode */
switch (eccmode) { switch (eccmode) {
/* No ecc, write all */ /* No ecc, write all */
case NAND_ECC_NONE: case NAND_ECC_NONE:
printk (KERN_WARNING "Writing data without ECC to NAND-FLASH is not recommended\n"); printk(KERN_WARNING "Writing data without ECC to NAND-FLASH is not recommended\n");
this->write_buf(mtd, this->data_poi, mtd->oobblock); this->write_buf(mtd, this->data_poi, mtd->oobblock);
break; break;
...@@ -928,11 +927,11 @@ static int nand_write_page (struct mtd_info *mtd, struct nand_chip *this, int pa ...@@ -928,11 +927,11 @@ static int nand_write_page (struct mtd_info *mtd, struct nand_chip *this, int pa
this->write_buf(mtd, oob_buf, mtd->oobsize); this->write_buf(mtd, oob_buf, mtd->oobsize);
/* Send command to actually program the data */ /* Send command to actually program the data */
this->cmdfunc (mtd, cached ? NAND_CMD_CACHEDPROG : NAND_CMD_PAGEPROG, -1, -1); this->cmdfunc(mtd, cached ? NAND_CMD_CACHEDPROG : NAND_CMD_PAGEPROG, -1, -1);
if (!cached) { if (!cached) {
/* call wait ready function */ /* call wait ready function */
status = this->waitfunc (mtd, this, FL_WRITING); status = this->waitfunc(mtd, this, FL_WRITING);
/* See if operation failed and additional status checks are available */ /* See if operation failed and additional status checks are available */
if ((status & NAND_STATUS_FAIL) && (this->errstat)) { if ((status & NAND_STATUS_FAIL) && (this->errstat)) {
...@@ -941,12 +940,12 @@ static int nand_write_page (struct mtd_info *mtd, struct nand_chip *this, int pa ...@@ -941,12 +940,12 @@ static int nand_write_page (struct mtd_info *mtd, struct nand_chip *this, int pa
/* See if device thinks it succeeded */ /* See if device thinks it succeeded */
if (status & NAND_STATUS_FAIL) { if (status & NAND_STATUS_FAIL) {
DEBUG (MTD_DEBUG_LEVEL0, "%s: " "Failed write, page 0x%08x, ", __FUNCTION__, page); DEBUG(MTD_DEBUG_LEVEL0, "%s: " "Failed write, page 0x%08x, ", __FUNCTION__, page);
return -EIO; return -EIO;
} }
} else { } else {
/* FIXME: Implement cached programming ! */ /* FIXME: Implement cached programming ! */
/* wait until cache is ready*/ /* wait until cache is ready */
// status = this->waitfunc (mtd, this, FL_CACHEDRPG); // status = this->waitfunc (mtd, this, FL_CACHEDRPG);
} }
return 0; return 0;
...@@ -972,7 +971,7 @@ static int nand_write_page (struct mtd_info *mtd, struct nand_chip *this, int pa ...@@ -972,7 +971,7 @@ static int nand_write_page (struct mtd_info *mtd, struct nand_chip *this, int pa
* the error later when the ECC page check fails, but we would rather catch * the error later when the ECC page check fails, but we would rather catch
* it early in the page write stage. Better to write no data than invalid data. * it early in the page write stage. Better to write no data than invalid data.
*/ */
static int nand_verify_pages (struct mtd_info *mtd, struct nand_chip *this, int page, int numpages, static int nand_verify_pages(struct mtd_info *mtd, struct nand_chip *this, int page, int numpages,
u_char *oob_buf, struct nand_oobinfo *oobsel, int chipnr, int oobmode) u_char *oob_buf, struct nand_oobinfo *oobsel, int chipnr, int oobmode)
{ {
int i, j, datidx = 0, oobofs = 0, res = -EIO; int i, j, datidx = 0, oobofs = 0, res = -EIO;
...@@ -983,13 +982,13 @@ static int nand_verify_pages (struct mtd_info *mtd, struct nand_chip *this, int ...@@ -983,13 +982,13 @@ static int nand_verify_pages (struct mtd_info *mtd, struct nand_chip *this, int
hweccbytes = (this->options & NAND_HWECC_SYNDROME) ? (oobsel->eccbytes / eccsteps) : 0; hweccbytes = (this->options & NAND_HWECC_SYNDROME) ? (oobsel->eccbytes / eccsteps) : 0;
/* Send command to read back the first page */ /* Send command to read back the first page */
this->cmdfunc (mtd, NAND_CMD_READ0, 0, page); this->cmdfunc(mtd, NAND_CMD_READ0, 0, page);
for(;;) { for (;;) {
for (j = 0; j < eccsteps; j++) { for (j = 0; j < eccsteps; j++) {
/* Loop through and verify the data */ /* Loop through and verify the data */
if (this->verify_buf(mtd, &this->data_poi[datidx], mtd->eccsize)) { if (this->verify_buf(mtd, &this->data_poi[datidx], mtd->eccsize)) {
DEBUG (MTD_DEBUG_LEVEL0, "%s: " "Failed write verify, page 0x%08x ", __FUNCTION__, page); DEBUG(MTD_DEBUG_LEVEL0, "%s: " "Failed write verify, page 0x%08x ", __FUNCTION__, page);
goto out; goto out;
} }
datidx += mtd->eccsize; datidx += mtd->eccsize;
...@@ -997,7 +996,7 @@ static int nand_verify_pages (struct mtd_info *mtd, struct nand_chip *this, int ...@@ -997,7 +996,7 @@ static int nand_verify_pages (struct mtd_info *mtd, struct nand_chip *this, int
if (!hweccbytes) if (!hweccbytes)
continue; continue;
if (this->verify_buf(mtd, &this->oob_buf[oobofs], hweccbytes)) { if (this->verify_buf(mtd, &this->oob_buf[oobofs], hweccbytes)) {
DEBUG (MTD_DEBUG_LEVEL0, "%s: " "Failed write verify, page 0x%08x ", __FUNCTION__, page); DEBUG(MTD_DEBUG_LEVEL0, "%s: " "Failed write verify, page 0x%08x ", __FUNCTION__, page);
goto out; goto out;
} }
oobofs += hweccbytes; oobofs += hweccbytes;
...@@ -1008,7 +1007,7 @@ static int nand_verify_pages (struct mtd_info *mtd, struct nand_chip *this, int ...@@ -1008,7 +1007,7 @@ static int nand_verify_pages (struct mtd_info *mtd, struct nand_chip *this, int
*/ */
if (oobmode) { if (oobmode) {
if (this->verify_buf(mtd, &oob_buf[oobofs], mtd->oobsize - hweccbytes * eccsteps)) { if (this->verify_buf(mtd, &oob_buf[oobofs], mtd->oobsize - hweccbytes * eccsteps)) {
DEBUG (MTD_DEBUG_LEVEL0, "%s: " "Failed write verify, page 0x%08x ", __FUNCTION__, page); DEBUG(MTD_DEBUG_LEVEL0, "%s: " "Failed write verify, page 0x%08x ", __FUNCTION__, page);
goto out; goto out;
} }
} else { } else {
...@@ -1020,10 +1019,9 @@ static int nand_verify_pages (struct mtd_info *mtd, struct nand_chip *this, int ...@@ -1020,10 +1019,9 @@ static int nand_verify_pages (struct mtd_info *mtd, struct nand_chip *this, int
for (i = 0; i < ecccnt; i++) { for (i = 0; i < ecccnt; i++) {
int idx = oobsel->eccpos[i]; int idx = oobsel->eccpos[i];
if (oobdata[idx] != oob_buf[oobofs + idx] ) { if (oobdata[idx] != oob_buf[oobofs + idx]) {
DEBUG (MTD_DEBUG_LEVEL0, DEBUG(MTD_DEBUG_LEVEL0, "%s: Failed ECC write verify, page 0x%08x, %6i bytes were succesful\n",
"%s: Failed ECC write " __FUNCTION__, page, i);
"verify, page 0x%08x, " "%6i bytes were succesful\n", __FUNCTION__, page, i);
goto out; goto out;
} }
} }
...@@ -1041,7 +1039,7 @@ static int nand_verify_pages (struct mtd_info *mtd, struct nand_chip *this, int ...@@ -1041,7 +1039,7 @@ static int nand_verify_pages (struct mtd_info *mtd, struct nand_chip *this, int
* ready for the next command. * ready for the next command.
*/ */
if (!this->dev_ready) if (!this->dev_ready)
udelay (this->chip_delay); udelay(this->chip_delay);
else else
nand_wait_ready(mtd); nand_wait_ready(mtd);
...@@ -1049,17 +1047,16 @@ static int nand_verify_pages (struct mtd_info *mtd, struct nand_chip *this, int ...@@ -1049,17 +1047,16 @@ static int nand_verify_pages (struct mtd_info *mtd, struct nand_chip *this, int
if (!numpages) if (!numpages)
return 0; return 0;
/* Check, if the chip supports auto page increment */ /* Check, if the chip supports auto page increment */
if (!NAND_CANAUTOINCR(this)) if (!NAND_CANAUTOINCR(this))
this->cmdfunc (mtd, NAND_CMD_READ0, 0x00, page); this->cmdfunc(mtd, NAND_CMD_READ0, 0x00, page);
} }
/* /*
* Terminate the read command. We come here in case of an error * Terminate the read command. We come here in case of an error
* So we must issue a reset command. * So we must issue a reset command.
*/ */
out: out:
this->cmdfunc (mtd, NAND_CMD_RESET, -1, -1); this->cmdfunc(mtd, NAND_CMD_RESET, -1, -1);
return res; return res;
} }
#endif #endif
...@@ -1075,12 +1072,11 @@ static int nand_verify_pages (struct mtd_info *mtd, struct nand_chip *this, int ...@@ -1075,12 +1072,11 @@ static int nand_verify_pages (struct mtd_info *mtd, struct nand_chip *this, int
* This function simply calls nand_do_read_ecc with oob buffer and oobsel = NULL * This function simply calls nand_do_read_ecc with oob buffer and oobsel = NULL
* and flags = 0xff * and flags = 0xff
*/ */
static int nand_read (struct mtd_info *mtd, loff_t from, size_t len, size_t * retlen, u_char * buf) static int nand_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
{ {
return nand_do_read_ecc (mtd, from, len, retlen, buf, NULL, &mtd->oobinfo, 0xff); return nand_do_read_ecc(mtd, from, len, retlen, buf, NULL, &mtd->oobinfo, 0xff);
} }
/** /**
* nand_read_ecc - [MTD Interface] MTD compability function for nand_do_read_ecc * nand_read_ecc - [MTD Interface] MTD compability function for nand_do_read_ecc
* @mtd: MTD device structure * @mtd: MTD device structure
...@@ -1093,8 +1089,8 @@ static int nand_read (struct mtd_info *mtd, loff_t from, size_t len, size_t * re ...@@ -1093,8 +1089,8 @@ static int nand_read (struct mtd_info *mtd, loff_t from, size_t len, size_t * re
* *
* This function simply calls nand_do_read_ecc with flags = 0xff * This function simply calls nand_do_read_ecc with flags = 0xff
*/ */
static int nand_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, static int nand_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
size_t * retlen, u_char * buf, u_char * oob_buf, struct nand_oobinfo *oobsel) size_t *retlen, u_char *buf, u_char *oob_buf, struct nand_oobinfo *oobsel)
{ {
/* use userspace supplied oobinfo, if zero */ /* use userspace supplied oobinfo, if zero */
if (oobsel == NULL) if (oobsel == NULL)
...@@ -1102,7 +1098,6 @@ static int nand_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, ...@@ -1102,7 +1098,6 @@ static int nand_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
return nand_do_read_ecc(mtd, from, len, retlen, buf, oob_buf, oobsel, 0xff); return nand_do_read_ecc(mtd, from, len, retlen, buf, oob_buf, oobsel, 0xff);
} }
/** /**
* nand_do_read_ecc - [MTD Interface] Read data with ECC * nand_do_read_ecc - [MTD Interface] Read data with ECC
* @mtd: MTD device structure * @mtd: MTD device structure
...@@ -1119,9 +1114,8 @@ static int nand_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, ...@@ -1119,9 +1114,8 @@ static int nand_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
* *
* NAND read with ECC * NAND read with ECC
*/ */
int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, int nand_do_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
size_t * retlen, u_char * buf, u_char * oob_buf, size_t *retlen, u_char *buf, u_char *oob_buf, struct nand_oobinfo *oobsel, int flags)
struct nand_oobinfo *oobsel, int flags)
{ {
int i, j, col, realpage, page, end, ecc, chipnr, sndcmd = 1; int i, j, col, realpage, page, end, ecc, chipnr, sndcmd = 1;
...@@ -1137,19 +1131,18 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, ...@@ -1137,19 +1131,18 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
int compareecc = 1; int compareecc = 1;
int oobreadlen; int oobreadlen;
DEBUG(MTD_DEBUG_LEVEL3, "nand_read_ecc: from = 0x%08x, len = %i\n", (unsigned int)from, (int)len);
DEBUG (MTD_DEBUG_LEVEL3, "nand_read_ecc: from = 0x%08x, len = %i\n", (unsigned int) from, (int) len);
/* Do not allow reads past end of device */ /* Do not allow reads past end of device */
if ((from + len) > mtd->size) { if ((from + len) > mtd->size) {
DEBUG (MTD_DEBUG_LEVEL0, "nand_read_ecc: Attempt read beyond end of device\n"); DEBUG(MTD_DEBUG_LEVEL0, "nand_read_ecc: Attempt read beyond end of device\n");
*retlen = 0; *retlen = 0;
return -EINVAL; return -EINVAL;
} }
/* Grab the lock and see if the device is available */ /* Grab the lock and see if the device is available */
if (flags & NAND_GET_DEVICE) if (flags & NAND_GET_DEVICE)
nand_get_device (this, mtd, FL_READING); nand_get_device(this, mtd, FL_READING);
/* Autoplace of oob data ? Use the default placement scheme */ /* Autoplace of oob data ? Use the default placement scheme */
if (oobsel->useecc == MTD_NANDECC_AUTOPLACE) if (oobsel->useecc == MTD_NANDECC_AUTOPLACE)
...@@ -1163,7 +1156,7 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, ...@@ -1163,7 +1156,7 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
this->select_chip(mtd, chipnr); this->select_chip(mtd, chipnr);
/* First we calculate the starting page */ /* First we calculate the starting page */
realpage = (int) (from >> this->page_shift); realpage = (int)(from >> this->page_shift);
page = realpage & this->pagemask; page = realpage & this->pagemask;
/* Get raw starting column */ /* Get raw starting column */
...@@ -1201,13 +1194,13 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, ...@@ -1201,13 +1194,13 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
if (realpage == this->pagebuf && !oob_buf) { if (realpage == this->pagebuf && !oob_buf) {
/* aligned read ? */ /* aligned read ? */
if (aligned) if (aligned)
memcpy (data_poi, this->data_buf, end); memcpy(data_poi, this->data_buf, end);
goto readdata; goto readdata;
} }
/* Check, if we must send the read command */ /* Check, if we must send the read command */
if (sndcmd) { if (sndcmd) {
this->cmdfunc (mtd, NAND_CMD_READ0, 0x00, page); this->cmdfunc(mtd, NAND_CMD_READ0, 0x00, page);
sndcmd = 0; sndcmd = 0;
} }
...@@ -1219,10 +1212,12 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, ...@@ -1219,10 +1212,12 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
eccsteps = this->eccsteps; eccsteps = this->eccsteps;
switch (eccmode) { switch (eccmode) {
case NAND_ECC_NONE: { /* No ECC, Read in a page */ case NAND_ECC_NONE:{
/* No ECC, Read in a page */
static unsigned long lastwhinge = 0; static unsigned long lastwhinge = 0;
if ((lastwhinge / HZ) != (jiffies / HZ)) { if ((lastwhinge / HZ) != (jiffies / HZ)) {
printk (KERN_WARNING "Reading data from NAND FLASH without ECC is not recommended\n"); printk(KERN_WARNING
"Reading data from NAND FLASH without ECC is not recommended\n");
lastwhinge = jiffies; lastwhinge = jiffies;
} }
this->read_buf(mtd, data_poi, end); this->read_buf(mtd, data_poi, end);
...@@ -1231,12 +1226,12 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, ...@@ -1231,12 +1226,12 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
case NAND_ECC_SOFT: /* Software ECC 3/256: Read in a page + oob data */ case NAND_ECC_SOFT: /* Software ECC 3/256: Read in a page + oob data */
this->read_buf(mtd, data_poi, end); this->read_buf(mtd, data_poi, end);
for (i = 0, datidx = 0; eccsteps; eccsteps--, i+=3, datidx += ecc) for (i = 0, datidx = 0; eccsteps; eccsteps--, i += 3, datidx += ecc)
this->calculate_ecc(mtd, &data_poi[datidx], &ecc_calc[i]); this->calculate_ecc(mtd, &data_poi[datidx], &ecc_calc[i]);
break; break;
default: default:
for (i = 0, datidx = 0; eccsteps; eccsteps--, i+=eccbytes, datidx += ecc) { for (i = 0, datidx = 0; eccsteps; eccsteps--, i += eccbytes, datidx += ecc) {
this->enable_hwecc(mtd, NAND_ECC_READ); this->enable_hwecc(mtd, NAND_ECC_READ);
this->read_buf(mtd, &data_poi[datidx], ecc); this->read_buf(mtd, &data_poi[datidx], ecc);
...@@ -1252,7 +1247,7 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, ...@@ -1252,7 +1247,7 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
* does the error correction on the fly */ * does the error correction on the fly */
ecc_status = this->correct_data(mtd, &data_poi[datidx], &oob_data[i], &ecc_code[i]); ecc_status = this->correct_data(mtd, &data_poi[datidx], &oob_data[i], &ecc_code[i]);
if ((ecc_status == -1) || (ecc_status > (flags && 0xff))) { if ((ecc_status == -1) || (ecc_status > (flags && 0xff))) {
DEBUG (MTD_DEBUG_LEVEL0, "nand_read_ecc: " DEBUG(MTD_DEBUG_LEVEL0, "nand_read_ecc: "
"Failed ECC read, page 0x%08x on chip %d\n", page, chipnr); "Failed ECC read, page 0x%08x on chip %d\n", page, chipnr);
ecc_failed++; ecc_failed++;
} }
...@@ -1274,7 +1269,7 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, ...@@ -1274,7 +1269,7 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
for (j = 0; j < oobsel->eccbytes; j++) for (j = 0; j < oobsel->eccbytes; j++)
ecc_code[j] = oob_data[oob_config[j]]; ecc_code[j] = oob_data[oob_config[j]];
/* correct data, if neccecary */ /* correct data, if necessary */
for (i = 0, j = 0, datidx = 0; i < this->eccsteps; i++, datidx += ecc) { for (i = 0, j = 0, datidx = 0; i < this->eccsteps; i++, datidx += ecc) {
ecc_status = this->correct_data(mtd, &data_poi[datidx], &ecc_code[j], &ecc_calc[j]); ecc_status = this->correct_data(mtd, &data_poi[datidx], &ecc_code[j], &ecc_calc[j]);
...@@ -1291,7 +1286,7 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, ...@@ -1291,7 +1286,7 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
} }
if ((ecc_status == -1) || (ecc_status > (flags && 0xff))) { if ((ecc_status == -1) || (ecc_status > (flags && 0xff))) {
DEBUG (MTD_DEBUG_LEVEL0, "nand_read_ecc: " "Failed ECC read, page 0x%08x\n", page); DEBUG(MTD_DEBUG_LEVEL0, "nand_read_ecc: " "Failed ECC read, page 0x%08x\n", page);
ecc_failed++; ecc_failed++;
} }
} }
...@@ -1300,7 +1295,7 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, ...@@ -1300,7 +1295,7 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
/* check, if we have a fs supplied oob-buffer */ /* check, if we have a fs supplied oob-buffer */
if (oob_buf) { if (oob_buf) {
/* without autoplace. Legacy mode used by YAFFS1 */ /* without autoplace. Legacy mode used by YAFFS1 */
switch(oobsel->useecc) { switch (oobsel->useecc) {
case MTD_NANDECC_AUTOPLACE: case MTD_NANDECC_AUTOPLACE:
case MTD_NANDECC_AUTOPL_USR: case MTD_NANDECC_AUTOPL_USR:
/* Walk through the autoplace chunks */ /* Walk through the autoplace chunks */
...@@ -1313,7 +1308,7 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, ...@@ -1313,7 +1308,7 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
break; break;
case MTD_NANDECC_PLACE: case MTD_NANDECC_PLACE:
/* YAFFS1 legacy mode */ /* YAFFS1 legacy mode */
oob_data += this->eccsteps * sizeof (int); oob_data += this->eccsteps * sizeof(int);
default: default:
oob_data += mtd->oobsize; oob_data += mtd->oobsize;
} }
...@@ -1333,7 +1328,7 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, ...@@ -1333,7 +1328,7 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
* is marked as NOAUTOINCR by the board driver. * is marked as NOAUTOINCR by the board driver.
*/ */
if (!this->dev_ready) if (!this->dev_ready)
udelay (this->chip_delay); udelay(this->chip_delay);
else else
nand_wait_ready(mtd); nand_wait_ready(mtd);
...@@ -1382,13 +1377,13 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, ...@@ -1382,13 +1377,13 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
* *
* NAND read out-of-band data from the spare area * NAND read out-of-band data from the spare area
*/ */
static int nand_read_oob (struct mtd_info *mtd, loff_t from, size_t len, size_t * retlen, u_char * buf) static int nand_read_oob(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
{ {
int i, col, page, chipnr; int i, col, page, chipnr;
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
int blockcheck = (1 << (this->phys_erase_shift - this->page_shift)) - 1; int blockcheck = (1 << (this->phys_erase_shift - this->page_shift)) - 1;
DEBUG (MTD_DEBUG_LEVEL3, "nand_read_oob: from = 0x%08x, len = %i\n", (unsigned int) from, (int) len); DEBUG(MTD_DEBUG_LEVEL3, "nand_read_oob: from = 0x%08x, len = %i\n", (unsigned int)from, (int)len);
/* Shift to get page */ /* Shift to get page */
page = (int)(from >> this->page_shift); page = (int)(from >> this->page_shift);
...@@ -1402,19 +1397,19 @@ static int nand_read_oob (struct mtd_info *mtd, loff_t from, size_t len, size_t ...@@ -1402,19 +1397,19 @@ static int nand_read_oob (struct mtd_info *mtd, loff_t from, size_t len, size_t
/* Do not allow reads past end of device */ /* Do not allow reads past end of device */
if ((from + len) > mtd->size) { if ((from + len) > mtd->size) {
DEBUG (MTD_DEBUG_LEVEL0, "nand_read_oob: Attempt read beyond end of device\n"); DEBUG(MTD_DEBUG_LEVEL0, "nand_read_oob: Attempt read beyond end of device\n");
*retlen = 0; *retlen = 0;
return -EINVAL; return -EINVAL;
} }
/* Grab the lock and see if the device is available */ /* Grab the lock and see if the device is available */
nand_get_device (this, mtd , FL_READING); nand_get_device(this, mtd, FL_READING);
/* Select the NAND device */ /* Select the NAND device */
this->select_chip(mtd, chipnr); this->select_chip(mtd, chipnr);
/* Send the read command */ /* Send the read command */
this->cmdfunc (mtd, NAND_CMD_READOOB, col, page & this->pagemask); this->cmdfunc(mtd, NAND_CMD_READOOB, col, page & this->pagemask);
/* /*
* Read the data, if we read more than one page * Read the data, if we read more than one page
* oob data, let the device transfer the data ! * oob data, let the device transfer the data !
...@@ -1444,7 +1439,7 @@ static int nand_read_oob (struct mtd_info *mtd, loff_t from, size_t len, size_t ...@@ -1444,7 +1439,7 @@ static int nand_read_oob (struct mtd_info *mtd, loff_t from, size_t len, size_t
* is marked as NOAUTOINCR by the board driver. * is marked as NOAUTOINCR by the board driver.
*/ */
if (!this->dev_ready) if (!this->dev_ready)
udelay (this->chip_delay); udelay(this->chip_delay);
else else
nand_wait_ready(mtd); nand_wait_ready(mtd);
...@@ -1453,7 +1448,7 @@ static int nand_read_oob (struct mtd_info *mtd, loff_t from, size_t len, size_t ...@@ -1453,7 +1448,7 @@ static int nand_read_oob (struct mtd_info *mtd, loff_t from, size_t len, size_t
*/ */
if (!NAND_CANAUTOINCR(this) || !(page & blockcheck)) { if (!NAND_CANAUTOINCR(this) || !(page & blockcheck)) {
/* For subsequent page reads set offset to 0 */ /* For subsequent page reads set offset to 0 */
this->cmdfunc (mtd, NAND_CMD_READOOB, 0x0, page & this->pagemask); this->cmdfunc(mtd, NAND_CMD_READOOB, 0x0, page & this->pagemask);
} }
} }
} }
...@@ -1476,11 +1471,11 @@ static int nand_read_oob (struct mtd_info *mtd, loff_t from, size_t len, size_t ...@@ -1476,11 +1471,11 @@ static int nand_read_oob (struct mtd_info *mtd, loff_t from, size_t len, size_t
* *
* Read raw data including oob into buffer * Read raw data including oob into buffer
*/ */
int nand_read_raw (struct mtd_info *mtd, uint8_t *buf, loff_t from, size_t len, size_t ooblen) int nand_read_raw(struct mtd_info *mtd, uint8_t *buf, loff_t from, size_t len, size_t ooblen)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
int page = (int) (from >> this->page_shift); int page = (int)(from >> this->page_shift);
int chip = (int) (from >> this->chip_shift); int chip = (int)(from >> this->chip_shift);
int sndcmd = 1; int sndcmd = 1;
int cnt = 0; int cnt = 0;
int pagesize = mtd->oobblock + mtd->oobsize; int pagesize = mtd->oobblock + mtd->oobsize;
...@@ -1488,31 +1483,31 @@ int nand_read_raw (struct mtd_info *mtd, uint8_t *buf, loff_t from, size_t len, ...@@ -1488,31 +1483,31 @@ int nand_read_raw (struct mtd_info *mtd, uint8_t *buf, loff_t from, size_t len,
/* Do not allow reads past end of device */ /* Do not allow reads past end of device */
if ((from + len) > mtd->size) { if ((from + len) > mtd->size) {
DEBUG (MTD_DEBUG_LEVEL0, "nand_read_raw: Attempt read beyond end of device\n"); DEBUG(MTD_DEBUG_LEVEL0, "nand_read_raw: Attempt read beyond end of device\n");
return -EINVAL; return -EINVAL;
} }
/* Grab the lock and see if the device is available */ /* Grab the lock and see if the device is available */
nand_get_device (this, mtd , FL_READING); nand_get_device(this, mtd, FL_READING);
this->select_chip (mtd, chip); this->select_chip(mtd, chip);
/* Add requested oob length */ /* Add requested oob length */
len += ooblen; len += ooblen;
while (len) { while (len) {
if (sndcmd) if (sndcmd)
this->cmdfunc (mtd, NAND_CMD_READ0, 0, page & this->pagemask); this->cmdfunc(mtd, NAND_CMD_READ0, 0, page & this->pagemask);
sndcmd = 0; sndcmd = 0;
this->read_buf (mtd, &buf[cnt], pagesize); this->read_buf(mtd, &buf[cnt], pagesize);
len -= pagesize; len -= pagesize;
cnt += pagesize; cnt += pagesize;
page++; page++;
if (!this->dev_ready) if (!this->dev_ready)
udelay (this->chip_delay); udelay(this->chip_delay);
else else
nand_wait_ready(mtd); nand_wait_ready(mtd);
...@@ -1526,7 +1521,6 @@ int nand_read_raw (struct mtd_info *mtd, uint8_t *buf, loff_t from, size_t len, ...@@ -1526,7 +1521,6 @@ int nand_read_raw (struct mtd_info *mtd, uint8_t *buf, loff_t from, size_t len,
return 0; return 0;
} }
/** /**
* nand_prepare_oobbuf - [GENERIC] Prepare the out of band buffer * nand_prepare_oobbuf - [GENERIC] Prepare the out of band buffer
* @mtd: MTD device structure * @mtd: MTD device structure
...@@ -1550,7 +1544,7 @@ int nand_read_raw (struct mtd_info *mtd, uint8_t *buf, loff_t from, size_t len, ...@@ -1550,7 +1544,7 @@ int nand_read_raw (struct mtd_info *mtd, uint8_t *buf, loff_t from, size_t len,
* forces the 0xff fill before using the buffer again. * forces the 0xff fill before using the buffer again.
* *
*/ */
static u_char * nand_prepare_oobbuf (struct mtd_info *mtd, u_char *fsbuf, struct nand_oobinfo *oobsel, static u_char *nand_prepare_oobbuf(struct mtd_info *mtd, u_char *fsbuf, struct nand_oobinfo *oobsel,
int autoplace, int numpages) int autoplace, int numpages)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
...@@ -1562,8 +1556,7 @@ static u_char * nand_prepare_oobbuf (struct mtd_info *mtd, u_char *fsbuf, struct ...@@ -1562,8 +1556,7 @@ static u_char * nand_prepare_oobbuf (struct mtd_info *mtd, u_char *fsbuf, struct
/* Check, if the buffer must be filled with ff again */ /* Check, if the buffer must be filled with ff again */
if (this->oobdirty) { if (this->oobdirty) {
memset (this->oob_buf, 0xff, memset(this->oob_buf, 0xff, mtd->oobsize << (this->phys_erase_shift - this->page_shift));
mtd->oobsize << (this->phys_erase_shift - this->page_shift));
this->oobdirty = 0; this->oobdirty = 0;
} }
...@@ -1578,7 +1571,7 @@ static u_char * nand_prepare_oobbuf (struct mtd_info *mtd, u_char *fsbuf, struct ...@@ -1578,7 +1571,7 @@ static u_char * nand_prepare_oobbuf (struct mtd_info *mtd, u_char *fsbuf, struct
for (i = 0, len = 0; len < mtd->oobavail; i++) { for (i = 0, len = 0; len < mtd->oobavail; i++) {
int to = ofs + oobsel->oobfree[i][0]; int to = ofs + oobsel->oobfree[i][0];
int num = oobsel->oobfree[i][1]; int num = oobsel->oobfree[i][1];
memcpy (&this->oob_buf[to], fsbuf, num); memcpy(&this->oob_buf[to], fsbuf, num);
len += num; len += num;
fsbuf += num; fsbuf += num;
} }
...@@ -1600,9 +1593,9 @@ static u_char * nand_prepare_oobbuf (struct mtd_info *mtd, u_char *fsbuf, struct ...@@ -1600,9 +1593,9 @@ static u_char * nand_prepare_oobbuf (struct mtd_info *mtd, u_char *fsbuf, struct
* This function simply calls nand_write_ecc with oob buffer and oobsel = NULL * This function simply calls nand_write_ecc with oob buffer and oobsel = NULL
* *
*/ */
static int nand_write (struct mtd_info *mtd, loff_t to, size_t len, size_t * retlen, const u_char * buf) static int nand_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf)
{ {
return (nand_write_ecc (mtd, to, len, retlen, buf, NULL, NULL)); return (nand_write_ecc(mtd, to, len, retlen, buf, NULL, NULL));
} }
/** /**
...@@ -1617,8 +1610,9 @@ static int nand_write (struct mtd_info *mtd, loff_t to, size_t len, size_t * ret ...@@ -1617,8 +1610,9 @@ static int nand_write (struct mtd_info *mtd, loff_t to, size_t len, size_t * ret
* *
* NAND write with ECC * NAND write with ECC
*/ */
static int nand_write_ecc (struct mtd_info *mtd, loff_t to, size_t len, static int nand_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
size_t * retlen, const u_char * buf, u_char * eccbuf, struct nand_oobinfo *oobsel) size_t *retlen, const u_char *buf, u_char *eccbuf,
struct nand_oobinfo *oobsel)
{ {
int startpage, page, ret = -EIO, oob = 0, written = 0, chipnr; int startpage, page, ret = -EIO, oob = 0, written = 0, chipnr;
int autoplace = 0, numpages, totalpages; int autoplace = 0, numpages, totalpages;
...@@ -1626,25 +1620,25 @@ static int nand_write_ecc (struct mtd_info *mtd, loff_t to, size_t len, ...@@ -1626,25 +1620,25 @@ static int nand_write_ecc (struct mtd_info *mtd, loff_t to, size_t len,
u_char *oobbuf, *bufstart; u_char *oobbuf, *bufstart;
int ppblock = (1 << (this->phys_erase_shift - this->page_shift)); int ppblock = (1 << (this->phys_erase_shift - this->page_shift));
DEBUG (MTD_DEBUG_LEVEL3, "nand_write_ecc: to = 0x%08x, len = %i\n", (unsigned int) to, (int) len); DEBUG(MTD_DEBUG_LEVEL3, "nand_write_ecc: to = 0x%08x, len = %i\n", (unsigned int)to, (int)len);
/* Initialize retlen, in case of early exit */ /* Initialize retlen, in case of early exit */
*retlen = 0; *retlen = 0;
/* Do not allow write past end of device */ /* Do not allow write past end of device */
if ((to + len) > mtd->size) { if ((to + len) > mtd->size) {
DEBUG (MTD_DEBUG_LEVEL0, "nand_write_ecc: Attempt to write past end of page\n"); DEBUG(MTD_DEBUG_LEVEL0, "nand_write_ecc: Attempt to write past end of page\n");
return -EINVAL; return -EINVAL;
} }
/* reject writes, which are not page aligned */ /* reject writes, which are not page aligned */
if (NOTALIGNED (to) || NOTALIGNED(len)) { if (NOTALIGNED(to) || NOTALIGNED(len)) {
printk (KERN_NOTICE "nand_write_ecc: Attempt to write not page aligned data\n"); printk(KERN_NOTICE "nand_write_ecc: Attempt to write not page aligned data\n");
return -EINVAL; return -EINVAL;
} }
/* Grab the lock and see if the device is available */ /* Grab the lock and see if the device is available */
nand_get_device (this, mtd, FL_WRITING); nand_get_device(this, mtd, FL_WRITING);
/* Calculate chipnr */ /* Calculate chipnr */
chipnr = (int)(to >> this->chip_shift); chipnr = (int)(to >> this->chip_shift);
...@@ -1669,7 +1663,7 @@ static int nand_write_ecc (struct mtd_info *mtd, loff_t to, size_t len, ...@@ -1669,7 +1663,7 @@ static int nand_write_ecc (struct mtd_info *mtd, loff_t to, size_t len,
/* Setup variables and oob buffer */ /* Setup variables and oob buffer */
totalpages = len >> this->page_shift; totalpages = len >> this->page_shift;
page = (int) (to >> this->page_shift); page = (int)(to >> this->page_shift);
/* Invalidate the page cache, if we write to the cached page */ /* Invalidate the page cache, if we write to the cached page */
if (page <= this->pagebuf && this->pagebuf < (page + totalpages)) if (page <= this->pagebuf && this->pagebuf < (page + totalpages))
this->pagebuf = -1; this->pagebuf = -1;
...@@ -1678,22 +1672,22 @@ static int nand_write_ecc (struct mtd_info *mtd, loff_t to, size_t len, ...@@ -1678,22 +1672,22 @@ static int nand_write_ecc (struct mtd_info *mtd, loff_t to, size_t len,
page &= this->pagemask; page &= this->pagemask;
startpage = page; startpage = page;
/* Calc number of pages we can write in one go */ /* Calc number of pages we can write in one go */
numpages = min (ppblock - (startpage & (ppblock - 1)), totalpages); numpages = min(ppblock - (startpage & (ppblock - 1)), totalpages);
oobbuf = nand_prepare_oobbuf (mtd, eccbuf, oobsel, autoplace, numpages); oobbuf = nand_prepare_oobbuf(mtd, eccbuf, oobsel, autoplace, numpages);
bufstart = (u_char *)buf; bufstart = (u_char *) buf;
/* Loop until all data is written */ /* Loop until all data is written */
while (written < len) { while (written < len) {
this->data_poi = (u_char*) &buf[written]; this->data_poi = (u_char *) &buf[written];
/* Write one page. If this is the last page to write /* Write one page. If this is the last page to write
* or the last page in this block, then use the * or the last page in this block, then use the
* real pageprogram command, else select cached programming * real pageprogram command, else select cached programming
* if supported by the chip. * if supported by the chip.
*/ */
ret = nand_write_page (mtd, this, page, &oobbuf[oob], oobsel, (--numpages > 0)); ret = nand_write_page(mtd, this, page, &oobbuf[oob], oobsel, (--numpages > 0));
if (ret) { if (ret) {
DEBUG (MTD_DEBUG_LEVEL0, "nand_write_ecc: write_page failed %d\n", ret); DEBUG(MTD_DEBUG_LEVEL0, "nand_write_ecc: write_page failed %d\n", ret);
goto out; goto out;
} }
/* Next oob page */ /* Next oob page */
...@@ -1710,14 +1704,13 @@ static int nand_write_ecc (struct mtd_info *mtd, loff_t to, size_t len, ...@@ -1710,14 +1704,13 @@ static int nand_write_ecc (struct mtd_info *mtd, loff_t to, size_t len,
* if verify is ok, we have to setup the oob buffer for * if verify is ok, we have to setup the oob buffer for
* the next pages. * the next pages.
*/ */
if (!(page & (ppblock - 1))){ if (!(page & (ppblock - 1))) {
int ofs; int ofs;
this->data_poi = bufstart; this->data_poi = bufstart;
ret = nand_verify_pages (mtd, this, startpage, ret = nand_verify_pages(mtd, this, startpage, page - startpage,
page - startpage,
oobbuf, oobsel, chipnr, (eccbuf != NULL)); oobbuf, oobsel, chipnr, (eccbuf != NULL));
if (ret) { if (ret) {
DEBUG (MTD_DEBUG_LEVEL0, "nand_write_ecc: verify_pages failed %d\n", ret); DEBUG(MTD_DEBUG_LEVEL0, "nand_write_ecc: verify_pages failed %d\n", ret);
goto out; goto out;
} }
*retlen = written; *retlen = written;
...@@ -1726,11 +1719,10 @@ static int nand_write_ecc (struct mtd_info *mtd, loff_t to, size_t len, ...@@ -1726,11 +1719,10 @@ static int nand_write_ecc (struct mtd_info *mtd, loff_t to, size_t len,
if (eccbuf) if (eccbuf)
eccbuf += (page - startpage) * ofs; eccbuf += (page - startpage) * ofs;
totalpages -= page - startpage; totalpages -= page - startpage;
numpages = min (totalpages, ppblock); numpages = min(totalpages, ppblock);
page &= this->pagemask; page &= this->pagemask;
startpage = page; startpage = page;
oobbuf = nand_prepare_oobbuf (mtd, eccbuf, oobsel, oobbuf = nand_prepare_oobbuf(mtd, eccbuf, oobsel, autoplace, numpages);
autoplace, numpages);
oob = 0; oob = 0;
/* Check, if we cross a chip boundary */ /* Check, if we cross a chip boundary */
if (!page) { if (!page) {
...@@ -1741,23 +1733,21 @@ static int nand_write_ecc (struct mtd_info *mtd, loff_t to, size_t len, ...@@ -1741,23 +1733,21 @@ static int nand_write_ecc (struct mtd_info *mtd, loff_t to, size_t len,
} }
} }
/* Verify the remaining pages */ /* Verify the remaining pages */
cmp: cmp:
this->data_poi = bufstart; this->data_poi = bufstart;
ret = nand_verify_pages (mtd, this, startpage, totalpages, ret = nand_verify_pages(mtd, this, startpage, totalpages, oobbuf, oobsel, chipnr, (eccbuf != NULL));
oobbuf, oobsel, chipnr, (eccbuf != NULL));
if (!ret) if (!ret)
*retlen = written; *retlen = written;
else else
DEBUG (MTD_DEBUG_LEVEL0, "nand_write_ecc: verify_pages failed %d\n", ret); DEBUG(MTD_DEBUG_LEVEL0, "nand_write_ecc: verify_pages failed %d\n", ret);
out: out:
/* Deselect and wake up anyone waiting on the device */ /* Deselect and wake up anyone waiting on the device */
nand_release_device(mtd); nand_release_device(mtd);
return ret; return ret;
} }
/** /**
* nand_write_oob - [MTD Interface] NAND write out-of-band * nand_write_oob - [MTD Interface] NAND write out-of-band
* @mtd: MTD device structure * @mtd: MTD device structure
...@@ -1768,16 +1758,16 @@ static int nand_write_ecc (struct mtd_info *mtd, loff_t to, size_t len, ...@@ -1768,16 +1758,16 @@ static int nand_write_ecc (struct mtd_info *mtd, loff_t to, size_t len,
* *
* NAND write out-of-band * NAND write out-of-band
*/ */
static int nand_write_oob (struct mtd_info *mtd, loff_t to, size_t len, size_t * retlen, const u_char * buf) static int nand_write_oob(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf)
{ {
int column, page, status, ret = -EIO, chipnr; int column, page, status, ret = -EIO, chipnr;
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
DEBUG (MTD_DEBUG_LEVEL3, "nand_write_oob: to = 0x%08x, len = %i\n", (unsigned int) to, (int) len); DEBUG(MTD_DEBUG_LEVEL3, "nand_write_oob: to = 0x%08x, len = %i\n", (unsigned int)to, (int)len);
/* Shift to get page */ /* Shift to get page */
page = (int) (to >> this->page_shift); page = (int)(to >> this->page_shift);
chipnr = (int) (to >> this->chip_shift); chipnr = (int)(to >> this->chip_shift);
/* Mask to get column */ /* Mask to get column */
column = to & (mtd->oobsize - 1); column = to & (mtd->oobsize - 1);
...@@ -1787,12 +1777,12 @@ static int nand_write_oob (struct mtd_info *mtd, loff_t to, size_t len, size_t * ...@@ -1787,12 +1777,12 @@ static int nand_write_oob (struct mtd_info *mtd, loff_t to, size_t len, size_t *
/* Do not allow write past end of page */ /* Do not allow write past end of page */
if ((column + len) > mtd->oobsize) { if ((column + len) > mtd->oobsize) {
DEBUG (MTD_DEBUG_LEVEL0, "nand_write_oob: Attempt to write past end of page\n"); DEBUG(MTD_DEBUG_LEVEL0, "nand_write_oob: Attempt to write past end of page\n");
return -EINVAL; return -EINVAL;
} }
/* Grab the lock and see if the device is available */ /* Grab the lock and see if the device is available */
nand_get_device (this, mtd, FL_WRITING); nand_get_device(this, mtd, FL_WRITING);
/* Select the NAND device */ /* Select the NAND device */
this->select_chip(mtd, chipnr); this->select_chip(mtd, chipnr);
...@@ -1814,27 +1804,27 @@ static int nand_write_oob (struct mtd_info *mtd, loff_t to, size_t len, size_t * ...@@ -1814,27 +1804,27 @@ static int nand_write_oob (struct mtd_info *mtd, loff_t to, size_t len, size_t *
if (NAND_MUST_PAD(this)) { if (NAND_MUST_PAD(this)) {
/* Write out desired data */ /* Write out desired data */
this->cmdfunc (mtd, NAND_CMD_SEQIN, mtd->oobblock, page & this->pagemask); this->cmdfunc(mtd, NAND_CMD_SEQIN, mtd->oobblock, page & this->pagemask);
/* prepad 0xff for partial programming */ /* prepad 0xff for partial programming */
this->write_buf(mtd, ffchars, column); this->write_buf(mtd, ffchars, column);
/* write data */ /* write data */
this->write_buf(mtd, buf, len); this->write_buf(mtd, buf, len);
/* postpad 0xff for partial programming */ /* postpad 0xff for partial programming */
this->write_buf(mtd, ffchars, mtd->oobsize - (len+column)); this->write_buf(mtd, ffchars, mtd->oobsize - (len + column));
} else { } else {
/* Write out desired data */ /* Write out desired data */
this->cmdfunc (mtd, NAND_CMD_SEQIN, mtd->oobblock + column, page & this->pagemask); this->cmdfunc(mtd, NAND_CMD_SEQIN, mtd->oobblock + column, page & this->pagemask);
/* write data */ /* write data */
this->write_buf(mtd, buf, len); this->write_buf(mtd, buf, len);
} }
/* Send command to program the OOB data */ /* Send command to program the OOB data */
this->cmdfunc (mtd, NAND_CMD_PAGEPROG, -1, -1); this->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
status = this->waitfunc (mtd, this, FL_WRITING); status = this->waitfunc(mtd, this, FL_WRITING);
/* See if device thinks it succeeded */ /* See if device thinks it succeeded */
if (status & NAND_STATUS_FAIL) { if (status & NAND_STATUS_FAIL) {
DEBUG (MTD_DEBUG_LEVEL0, "nand_write_oob: " "Failed write, page 0x%08x\n", page); DEBUG(MTD_DEBUG_LEVEL0, "nand_write_oob: " "Failed write, page 0x%08x\n", page);
ret = -EIO; ret = -EIO;
goto out; goto out;
} }
...@@ -1843,23 +1833,22 @@ static int nand_write_oob (struct mtd_info *mtd, loff_t to, size_t len, size_t * ...@@ -1843,23 +1833,22 @@ static int nand_write_oob (struct mtd_info *mtd, loff_t to, size_t len, size_t *
#ifdef CONFIG_MTD_NAND_VERIFY_WRITE #ifdef CONFIG_MTD_NAND_VERIFY_WRITE
/* Send command to read back the data */ /* Send command to read back the data */
this->cmdfunc (mtd, NAND_CMD_READOOB, column, page & this->pagemask); this->cmdfunc(mtd, NAND_CMD_READOOB, column, page & this->pagemask);
if (this->verify_buf(mtd, buf, len)) { if (this->verify_buf(mtd, buf, len)) {
DEBUG (MTD_DEBUG_LEVEL0, "nand_write_oob: " "Failed write verify, page 0x%08x\n", page); DEBUG(MTD_DEBUG_LEVEL0, "nand_write_oob: " "Failed write verify, page 0x%08x\n", page);
ret = -EIO; ret = -EIO;
goto out; goto out;
} }
#endif #endif
ret = 0; ret = 0;
out: out:
/* Deselect and wake up anyone waiting on the device */ /* Deselect and wake up anyone waiting on the device */
nand_release_device(mtd); nand_release_device(mtd);
return ret; return ret;
} }
/** /**
* nand_writev - [MTD Interface] compabilty function for nand_writev_ecc * nand_writev - [MTD Interface] compabilty function for nand_writev_ecc
* @mtd: MTD device structure * @mtd: MTD device structure
...@@ -1870,10 +1859,10 @@ static int nand_write_oob (struct mtd_info *mtd, loff_t to, size_t len, size_t * ...@@ -1870,10 +1859,10 @@ static int nand_write_oob (struct mtd_info *mtd, loff_t to, size_t len, size_t *
* *
* NAND write with kvec. This just calls the ecc function * NAND write with kvec. This just calls the ecc function
*/ */
static int nand_writev (struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, static int nand_writev(struct mtd_info *mtd, const struct kvec *vecs, unsigned long count,
loff_t to, size_t * retlen) loff_t to, size_t *retlen)
{ {
return (nand_writev_ecc (mtd, vecs, count, to, retlen, NULL, NULL)); return (nand_writev_ecc(mtd, vecs, count, to, retlen, NULL, NULL));
} }
/** /**
...@@ -1888,8 +1877,8 @@ static int nand_writev (struct mtd_info *mtd, const struct kvec *vecs, unsigned ...@@ -1888,8 +1877,8 @@ static int nand_writev (struct mtd_info *mtd, const struct kvec *vecs, unsigned
* *
* NAND write with iovec with ecc * NAND write with iovec with ecc
*/ */
static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, static int nand_writev_ecc(struct mtd_info *mtd, const struct kvec *vecs, unsigned long count,
loff_t to, size_t * retlen, u_char *eccbuf, struct nand_oobinfo *oobsel) loff_t to, size_t *retlen, u_char *eccbuf, struct nand_oobinfo *oobsel)
{ {
int i, page, len, total_len, ret = -EIO, written = 0, chipnr; int i, page, len, total_len, ret = -EIO, written = 0, chipnr;
int oob, numpages, autoplace = 0, startpage; int oob, numpages, autoplace = 0, startpage;
...@@ -1903,28 +1892,27 @@ static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsig ...@@ -1903,28 +1892,27 @@ static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsig
/* Calculate total length of data */ /* Calculate total length of data */
total_len = 0; total_len = 0;
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
total_len += (int) vecs[i].iov_len; total_len += (int)vecs[i].iov_len;
DEBUG (MTD_DEBUG_LEVEL3, DEBUG(MTD_DEBUG_LEVEL3, "nand_writev: to = 0x%08x, len = %i, count = %ld\n", (unsigned int)to, (unsigned int)total_len, count);
"nand_writev: to = 0x%08x, len = %i, count = %ld\n", (unsigned int) to, (unsigned int) total_len, count);
/* Do not allow write past end of page */ /* Do not allow write past end of page */
if ((to + total_len) > mtd->size) { if ((to + total_len) > mtd->size) {
DEBUG (MTD_DEBUG_LEVEL0, "nand_writev: Attempted write past end of device\n"); DEBUG(MTD_DEBUG_LEVEL0, "nand_writev: Attempted write past end of device\n");
return -EINVAL; return -EINVAL;
} }
/* reject writes, which are not page aligned */ /* reject writes, which are not page aligned */
if (NOTALIGNED (to) || NOTALIGNED(total_len)) { if (NOTALIGNED(to) || NOTALIGNED(total_len)) {
printk (KERN_NOTICE "nand_write_ecc: Attempt to write not page aligned data\n"); printk(KERN_NOTICE "nand_write_ecc: Attempt to write not page aligned data\n");
return -EINVAL; return -EINVAL;
} }
/* Grab the lock and see if the device is available */ /* Grab the lock and see if the device is available */
nand_get_device (this, mtd, FL_WRITING); nand_get_device(this, mtd, FL_WRITING);
/* Get the current chip-nr */ /* Get the current chip-nr */
chipnr = (int) (to >> this->chip_shift); chipnr = (int)(to >> this->chip_shift);
/* Select the NAND device */ /* Select the NAND device */
this->select_chip(mtd, chipnr); this->select_chip(mtd, chipnr);
...@@ -1945,7 +1933,7 @@ static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsig ...@@ -1945,7 +1933,7 @@ static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsig
autoplace = 1; autoplace = 1;
/* Setup start page */ /* Setup start page */
page = (int) (to >> this->page_shift); page = (int)(to >> this->page_shift);
/* Invalidate the page cache, if we write to the cached page */ /* Invalidate the page cache, if we write to the cached page */
if (page <= this->pagebuf && this->pagebuf < ((to + total_len) >> this->page_shift)) if (page <= this->pagebuf && this->pagebuf < ((to + total_len) >> this->page_shift))
this->pagebuf = -1; this->pagebuf = -1;
...@@ -1963,9 +1951,9 @@ static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsig ...@@ -1963,9 +1951,9 @@ static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsig
* out of this iov in one go */ * out of this iov in one go */
numpages = (vecs->iov_len - len) >> this->page_shift; numpages = (vecs->iov_len - len) >> this->page_shift;
/* Do not cross block boundaries */ /* Do not cross block boundaries */
numpages = min (ppblock - (startpage & (ppblock - 1)), numpages); numpages = min(ppblock - (startpage & (ppblock - 1)), numpages);
oobbuf = nand_prepare_oobbuf (mtd, NULL, oobsel, autoplace, numpages); oobbuf = nand_prepare_oobbuf(mtd, NULL, oobsel, autoplace, numpages);
bufstart = (u_char *)vecs->iov_base; bufstart = (u_char *) vecs->iov_base;
bufstart += len; bufstart += len;
this->data_poi = bufstart; this->data_poi = bufstart;
oob = 0; oob = 0;
...@@ -1974,7 +1962,7 @@ static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsig ...@@ -1974,7 +1962,7 @@ static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsig
* then use the real pageprogram command, else select * then use the real pageprogram command, else select
* cached programming if supported by the chip. * cached programming if supported by the chip.
*/ */
ret = nand_write_page (mtd, this, page & this->pagemask, ret = nand_write_page(mtd, this, page & this->pagemask,
&oobbuf[oob], oobsel, i != numpages); &oobbuf[oob], oobsel, i != numpages);
if (ret) if (ret)
goto out; goto out;
...@@ -1984,7 +1972,7 @@ static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsig ...@@ -1984,7 +1972,7 @@ static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsig
page++; page++;
} }
/* Check, if we have to switch to the next tuple */ /* Check, if we have to switch to the next tuple */
if (len >= (int) vecs->iov_len) { if (len >= (int)vecs->iov_len) {
vecs++; vecs++;
len = 0; len = 0;
count--; count--;
...@@ -1998,7 +1986,7 @@ static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsig ...@@ -1998,7 +1986,7 @@ static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsig
if (vecs->iov_base != NULL && vecs->iov_len) if (vecs->iov_base != NULL && vecs->iov_len)
this->data_buf[cnt++] = ((u_char *) vecs->iov_base)[len++]; this->data_buf[cnt++] = ((u_char *) vecs->iov_base)[len++];
/* Check, if we have to switch to the next tuple */ /* Check, if we have to switch to the next tuple */
if (len >= (int) vecs->iov_len) { if (len >= (int)vecs->iov_len) {
vecs++; vecs++;
len = 0; len = 0;
count--; count--;
...@@ -2008,16 +1996,15 @@ static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsig ...@@ -2008,16 +1996,15 @@ static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsig
this->data_poi = this->data_buf; this->data_poi = this->data_buf;
bufstart = this->data_poi; bufstart = this->data_poi;
numpages = 1; numpages = 1;
oobbuf = nand_prepare_oobbuf (mtd, NULL, oobsel, autoplace, numpages); oobbuf = nand_prepare_oobbuf(mtd, NULL, oobsel, autoplace, numpages);
ret = nand_write_page (mtd, this, page & this->pagemask, ret = nand_write_page(mtd, this, page & this->pagemask, oobbuf, oobsel, 0);
oobbuf, oobsel, 0);
if (ret) if (ret)
goto out; goto out;
page++; page++;
} }
this->data_poi = bufstart; this->data_poi = bufstart;
ret = nand_verify_pages (mtd, this, startpage, numpages, oobbuf, oobsel, chipnr, 0); ret = nand_verify_pages(mtd, this, startpage, numpages, oobbuf, oobsel, chipnr, 0);
if (ret) if (ret)
goto out; goto out;
...@@ -2035,7 +2022,7 @@ static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsig ...@@ -2035,7 +2022,7 @@ static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsig
} }
} }
ret = 0; ret = 0;
out: out:
/* Deselect and wake up anyone waiting on the device */ /* Deselect and wake up anyone waiting on the device */
nand_release_device(mtd); nand_release_device(mtd);
...@@ -2050,12 +2037,12 @@ static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsig ...@@ -2050,12 +2037,12 @@ static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsig
* *
* Standard erase command for NAND chips * Standard erase command for NAND chips
*/ */
static void single_erase_cmd (struct mtd_info *mtd, int page) static void single_erase_cmd(struct mtd_info *mtd, int page)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
/* Send commands to erase a block */ /* Send commands to erase a block */
this->cmdfunc (mtd, NAND_CMD_ERASE1, -1, page); this->cmdfunc(mtd, NAND_CMD_ERASE1, -1, page);
this->cmdfunc (mtd, NAND_CMD_ERASE2, -1, -1); this->cmdfunc(mtd, NAND_CMD_ERASE2, -1, -1);
} }
/** /**
...@@ -2066,15 +2053,15 @@ static void single_erase_cmd (struct mtd_info *mtd, int page) ...@@ -2066,15 +2053,15 @@ static void single_erase_cmd (struct mtd_info *mtd, int page)
* AND multi block erase command function * AND multi block erase command function
* Erase 4 consecutive blocks * Erase 4 consecutive blocks
*/ */
static void multi_erase_cmd (struct mtd_info *mtd, int page) static void multi_erase_cmd(struct mtd_info *mtd, int page)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
/* Send commands to erase a block */ /* Send commands to erase a block */
this->cmdfunc (mtd, NAND_CMD_ERASE1, -1, page++); this->cmdfunc(mtd, NAND_CMD_ERASE1, -1, page++);
this->cmdfunc (mtd, NAND_CMD_ERASE1, -1, page++); this->cmdfunc(mtd, NAND_CMD_ERASE1, -1, page++);
this->cmdfunc (mtd, NAND_CMD_ERASE1, -1, page++); this->cmdfunc(mtd, NAND_CMD_ERASE1, -1, page++);
this->cmdfunc (mtd, NAND_CMD_ERASE1, -1, page); this->cmdfunc(mtd, NAND_CMD_ERASE1, -1, page);
this->cmdfunc (mtd, NAND_CMD_ERASE2, -1, -1); this->cmdfunc(mtd, NAND_CMD_ERASE2, -1, -1);
} }
/** /**
...@@ -2084,9 +2071,9 @@ static void multi_erase_cmd (struct mtd_info *mtd, int page) ...@@ -2084,9 +2071,9 @@ static void multi_erase_cmd (struct mtd_info *mtd, int page)
* *
* Erase one ore more blocks * Erase one ore more blocks
*/ */
static int nand_erase (struct mtd_info *mtd, struct erase_info *instr) static int nand_erase(struct mtd_info *mtd, struct erase_info *instr)
{ {
return nand_erase_nand (mtd, instr, 0); return nand_erase_nand(mtd, instr, 0);
} }
#define BBT_PAGE_MASK 0xffffff3f #define BBT_PAGE_MASK 0xffffff3f
...@@ -2098,7 +2085,7 @@ static int nand_erase (struct mtd_info *mtd, struct erase_info *instr) ...@@ -2098,7 +2085,7 @@ static int nand_erase (struct mtd_info *mtd, struct erase_info *instr)
* *
* Erase one ore more blocks * Erase one ore more blocks
*/ */
int nand_erase_nand (struct mtd_info *mtd, struct erase_info *instr, int allowbbt) int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr, int allowbbt)
{ {
int page, len, status, pages_per_block, ret, chipnr; int page, len, status, pages_per_block, ret, chipnr;
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
...@@ -2107,35 +2094,34 @@ int nand_erase_nand (struct mtd_info *mtd, struct erase_info *instr, int allowbb ...@@ -2107,35 +2094,34 @@ int nand_erase_nand (struct mtd_info *mtd, struct erase_info *instr, int allowbb
/* It is used to see if the current page is in the same */ /* It is used to see if the current page is in the same */
/* 256 block group and the same bank as the bbt. */ /* 256 block group and the same bank as the bbt. */
DEBUG (MTD_DEBUG_LEVEL3, DEBUG(MTD_DEBUG_LEVEL3, "nand_erase: start = 0x%08x, len = %i\n", (unsigned int)instr->addr, (unsigned int)instr->len);
"nand_erase: start = 0x%08x, len = %i\n", (unsigned int) instr->addr, (unsigned int) instr->len);
/* Start address must align on block boundary */ /* Start address must align on block boundary */
if (instr->addr & ((1 << this->phys_erase_shift) - 1)) { if (instr->addr & ((1 << this->phys_erase_shift) - 1)) {
DEBUG (MTD_DEBUG_LEVEL0, "nand_erase: Unaligned address\n"); DEBUG(MTD_DEBUG_LEVEL0, "nand_erase: Unaligned address\n");
return -EINVAL; return -EINVAL;
} }
/* Length must align on block boundary */ /* Length must align on block boundary */
if (instr->len & ((1 << this->phys_erase_shift) - 1)) { if (instr->len & ((1 << this->phys_erase_shift) - 1)) {
DEBUG (MTD_DEBUG_LEVEL0, "nand_erase: Length not block aligned\n"); DEBUG(MTD_DEBUG_LEVEL0, "nand_erase: Length not block aligned\n");
return -EINVAL; return -EINVAL;
} }
/* Do not allow erase past end of device */ /* Do not allow erase past end of device */
if ((instr->len + instr->addr) > mtd->size) { if ((instr->len + instr->addr) > mtd->size) {
DEBUG (MTD_DEBUG_LEVEL0, "nand_erase: Erase past end of device\n"); DEBUG(MTD_DEBUG_LEVEL0, "nand_erase: Erase past end of device\n");
return -EINVAL; return -EINVAL;
} }
instr->fail_addr = 0xffffffff; instr->fail_addr = 0xffffffff;
/* Grab the lock and see if the device is available */ /* Grab the lock and see if the device is available */
nand_get_device (this, mtd, FL_ERASING); nand_get_device(this, mtd, FL_ERASING);
/* Shift to get first page */ /* Shift to get first page */
page = (int) (instr->addr >> this->page_shift); page = (int)(instr->addr >> this->page_shift);
chipnr = (int) (instr->addr >> this->chip_shift); chipnr = (int)(instr->addr >> this->chip_shift);
/* Calculate pages in each block */ /* Calculate pages in each block */
pages_per_block = 1 << (this->phys_erase_shift - this->page_shift); pages_per_block = 1 << (this->phys_erase_shift - this->page_shift);
...@@ -2146,7 +2132,7 @@ int nand_erase_nand (struct mtd_info *mtd, struct erase_info *instr, int allowbb ...@@ -2146,7 +2132,7 @@ int nand_erase_nand (struct mtd_info *mtd, struct erase_info *instr, int allowbb
/* Check the WP bit */ /* Check the WP bit */
/* Check, if it is write protected */ /* Check, if it is write protected */
if (nand_check_wp(mtd)) { if (nand_check_wp(mtd)) {
DEBUG (MTD_DEBUG_LEVEL0, "nand_erase: Device is write protected!!!\n"); DEBUG(MTD_DEBUG_LEVEL0, "nand_erase: Device is write protected!!!\n");
instr->state = MTD_ERASE_FAILED; instr->state = MTD_ERASE_FAILED;
goto erase_exit; goto erase_exit;
} }
...@@ -2166,7 +2152,7 @@ int nand_erase_nand (struct mtd_info *mtd, struct erase_info *instr, int allowbb ...@@ -2166,7 +2152,7 @@ int nand_erase_nand (struct mtd_info *mtd, struct erase_info *instr, int allowbb
while (len) { while (len) {
/* Check if we have a bad block, we do not erase bad blocks ! */ /* Check if we have a bad block, we do not erase bad blocks ! */
if (nand_block_checkbad(mtd, ((loff_t) page) << this->page_shift, 0, allowbbt)) { if (nand_block_checkbad(mtd, ((loff_t) page) << this->page_shift, 0, allowbbt)) {
printk (KERN_WARNING "nand_erase: attempt to erase a bad block at page 0x%08x\n", page); printk(KERN_WARNING "nand_erase: attempt to erase a bad block at page 0x%08x\n", page);
instr->state = MTD_ERASE_FAILED; instr->state = MTD_ERASE_FAILED;
goto erase_exit; goto erase_exit;
} }
...@@ -2176,9 +2162,9 @@ int nand_erase_nand (struct mtd_info *mtd, struct erase_info *instr, int allowbb ...@@ -2176,9 +2162,9 @@ int nand_erase_nand (struct mtd_info *mtd, struct erase_info *instr, int allowbb
if (page <= this->pagebuf && this->pagebuf < (page + pages_per_block)) if (page <= this->pagebuf && this->pagebuf < (page + pages_per_block))
this->pagebuf = -1; this->pagebuf = -1;
this->erase_cmd (mtd, page & this->pagemask); this->erase_cmd(mtd, page & this->pagemask);
status = this->waitfunc (mtd, this, FL_ERASING); status = this->waitfunc(mtd, this, FL_ERASING);
/* See if operation failed and additional status checks are available */ /* See if operation failed and additional status checks are available */
if ((status & NAND_STATUS_FAIL) && (this->errstat)) { if ((status & NAND_STATUS_FAIL) && (this->errstat)) {
...@@ -2187,7 +2173,7 @@ int nand_erase_nand (struct mtd_info *mtd, struct erase_info *instr, int allowbb ...@@ -2187,7 +2173,7 @@ int nand_erase_nand (struct mtd_info *mtd, struct erase_info *instr, int allowbb
/* See if block erase succeeded */ /* See if block erase succeeded */
if (status & NAND_STATUS_FAIL) { if (status & NAND_STATUS_FAIL) {
DEBUG (MTD_DEBUG_LEVEL0, "nand_erase: " "Failed erase, page 0x%08x\n", page); DEBUG(MTD_DEBUG_LEVEL0, "nand_erase: " "Failed erase, page 0x%08x\n", page);
instr->state = MTD_ERASE_FAILED; instr->state = MTD_ERASE_FAILED;
instr->fail_addr = (page << this->page_shift); instr->fail_addr = (page << this->page_shift);
goto erase_exit; goto erase_exit;
...@@ -2221,7 +2207,7 @@ int nand_erase_nand (struct mtd_info *mtd, struct erase_info *instr, int allowbb ...@@ -2221,7 +2207,7 @@ int nand_erase_nand (struct mtd_info *mtd, struct erase_info *instr, int allowbb
} }
instr->state = MTD_ERASE_DONE; instr->state = MTD_ERASE_DONE;
erase_exit: erase_exit:
ret = instr->state == MTD_ERASE_DONE ? 0 : -EIO; ret = instr->state == MTD_ERASE_DONE ? 0 : -EIO;
/* Do call back function */ /* Do call back function */
...@@ -2236,9 +2222,9 @@ int nand_erase_nand (struct mtd_info *mtd, struct erase_info *instr, int allowbb ...@@ -2236,9 +2222,9 @@ int nand_erase_nand (struct mtd_info *mtd, struct erase_info *instr, int allowbb
for (chipnr = 0; chipnr < this->numchips; chipnr++) { for (chipnr = 0; chipnr < this->numchips; chipnr++) {
if (rewrite_bbt[chipnr]) { if (rewrite_bbt[chipnr]) {
/* update the BBT for chip */ /* update the BBT for chip */
DEBUG (MTD_DEBUG_LEVEL0, "nand_erase_nand: nand_update_bbt (%d:0x%0x 0x%0x)\n", DEBUG(MTD_DEBUG_LEVEL0, "nand_erase_nand: nand_update_bbt (%d:0x%0x 0x%0x)\n",
chipnr, rewrite_bbt[chipnr], this->bbt_td->pages[chipnr]); chipnr, rewrite_bbt[chipnr], this->bbt_td->pages[chipnr]);
nand_update_bbt (mtd, rewrite_bbt[chipnr]); nand_update_bbt(mtd, rewrite_bbt[chipnr]);
} }
} }
} }
...@@ -2253,31 +2239,30 @@ int nand_erase_nand (struct mtd_info *mtd, struct erase_info *instr, int allowbb ...@@ -2253,31 +2239,30 @@ int nand_erase_nand (struct mtd_info *mtd, struct erase_info *instr, int allowbb
* *
* Sync is actually a wait for chip ready function * Sync is actually a wait for chip ready function
*/ */
static void nand_sync (struct mtd_info *mtd) static void nand_sync(struct mtd_info *mtd)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
DEBUG (MTD_DEBUG_LEVEL3, "nand_sync: called\n"); DEBUG(MTD_DEBUG_LEVEL3, "nand_sync: called\n");
/* Grab the lock and see if the device is available */ /* Grab the lock and see if the device is available */
nand_get_device (this, mtd, FL_SYNCING); nand_get_device(this, mtd, FL_SYNCING);
/* Release it and go back */ /* Release it and go back */
nand_release_device (mtd); nand_release_device(mtd);
} }
/** /**
* nand_block_isbad - [MTD Interface] Check whether the block at the given offset is bad * nand_block_isbad - [MTD Interface] Check whether the block at the given offset is bad
* @mtd: MTD device structure * @mtd: MTD device structure
* @ofs: offset relative to mtd start * @ofs: offset relative to mtd start
*/ */
static int nand_block_isbad (struct mtd_info *mtd, loff_t ofs) static int nand_block_isbad(struct mtd_info *mtd, loff_t ofs)
{ {
/* Check for invalid offset */ /* Check for invalid offset */
if (ofs > mtd->size) if (ofs > mtd->size)
return -EINVAL; return -EINVAL;
return nand_block_checkbad (mtd, ofs, 1, 0); return nand_block_checkbad(mtd, ofs, 1, 0);
} }
/** /**
...@@ -2285,7 +2270,7 @@ static int nand_block_isbad (struct mtd_info *mtd, loff_t ofs) ...@@ -2285,7 +2270,7 @@ static int nand_block_isbad (struct mtd_info *mtd, loff_t ofs)
* @mtd: MTD device structure * @mtd: MTD device structure
* @ofs: offset relative to mtd start * @ofs: offset relative to mtd start
*/ */
static int nand_block_markbad (struct mtd_info *mtd, loff_t ofs) static int nand_block_markbad(struct mtd_info *mtd, loff_t ofs)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
int ret; int ret;
...@@ -2308,7 +2293,7 @@ static int nand_suspend(struct mtd_info *mtd) ...@@ -2308,7 +2293,7 @@ static int nand_suspend(struct mtd_info *mtd)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
return nand_get_device (this, mtd, FL_PM_SUSPENDED); return nand_get_device(this, mtd, FL_PM_SUSPENDED);
} }
/** /**
...@@ -2322,12 +2307,10 @@ static void nand_resume(struct mtd_info *mtd) ...@@ -2322,12 +2307,10 @@ static void nand_resume(struct mtd_info *mtd)
if (this->state == FL_PM_SUSPENDED) if (this->state == FL_PM_SUSPENDED)
nand_release_device(mtd); nand_release_device(mtd);
else else
printk(KERN_ERR "resume() called for the chip which is not " printk(KERN_ERR "resume() called for the chip which is not in suspended state\n");
"in suspended state\n");
} }
/** /**
* nand_scan - [NAND Interface] Scan for the NAND device * nand_scan - [NAND Interface] Scan for the NAND device
* @mtd: MTD device structure * @mtd: MTD device structure
...@@ -2340,12 +2323,12 @@ static void nand_resume(struct mtd_info *mtd) ...@@ -2340,12 +2323,12 @@ static void nand_resume(struct mtd_info *mtd)
* they are not provided by the board driver * they are not provided by the board driver
* *
*/ */
int nand_scan (struct mtd_info *mtd, int maxchips) int nand_scan(struct mtd_info *mtd, int maxchips)
{ {
int i, nand_maf_id, nand_dev_id, busw, maf_id; int i, nand_maf_id, nand_dev_id, busw, maf_id;
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
/* Get buswidth to select the correct functions*/ /* Get buswidth to select the correct functions */
busw = this->options & NAND_BUSWIDTH_16; busw = this->options & NAND_BUSWIDTH_16;
/* check for proper chip_delay setup, set 20us if not */ /* check for proper chip_delay setup, set 20us if not */
...@@ -2387,7 +2370,7 @@ int nand_scan (struct mtd_info *mtd, int maxchips) ...@@ -2387,7 +2370,7 @@ int nand_scan (struct mtd_info *mtd, int maxchips)
this->select_chip(mtd, 0); this->select_chip(mtd, 0);
/* Send the command for reading device ID */ /* Send the command for reading device ID */
this->cmdfunc (mtd, NAND_CMD_READID, 0x00, -1); this->cmdfunc(mtd, NAND_CMD_READID, 0x00, -1);
/* Read manufacturer and device IDs */ /* Read manufacturer and device IDs */
nand_maf_id = this->read_byte(mtd); nand_maf_id = this->read_byte(mtd);
...@@ -2399,7 +2382,8 @@ int nand_scan (struct mtd_info *mtd, int maxchips) ...@@ -2399,7 +2382,8 @@ int nand_scan (struct mtd_info *mtd, int maxchips)
if (nand_dev_id != nand_flash_ids[i].id) if (nand_dev_id != nand_flash_ids[i].id)
continue; continue;
if (!mtd->name) mtd->name = nand_flash_ids[i].name; if (!mtd->name)
mtd->name = nand_flash_ids[i].name;
this->chipsize = nand_flash_ids[i].chipsize << 20; this->chipsize = nand_flash_ids[i].chipsize << 20;
/* New devices have all the information in additional id bytes */ /* New devices have all the information in additional id bytes */
...@@ -2439,13 +2423,12 @@ int nand_scan (struct mtd_info *mtd, int maxchips) ...@@ -2439,13 +2423,12 @@ int nand_scan (struct mtd_info *mtd, int maxchips)
/* Check, if buswidth is correct. Hardware drivers should set /* Check, if buswidth is correct. Hardware drivers should set
* this correct ! */ * this correct ! */
if (busw != (this->options & NAND_BUSWIDTH_16)) { if (busw != (this->options & NAND_BUSWIDTH_16)) {
printk (KERN_INFO "NAND device: Manufacturer ID:" printk(KERN_INFO "NAND device: Manufacturer ID:"
" 0x%02x, Chip ID: 0x%02x (%s %s)\n", nand_maf_id, nand_dev_id, " 0x%02x, Chip ID: 0x%02x (%s %s)\n", nand_maf_id, nand_dev_id,
nand_manuf_ids[maf_id].name , mtd->name); nand_manuf_ids[maf_id].name, mtd->name);
printk (KERN_WARNING printk(KERN_WARNING
"NAND bus width %d instead %d bit\n", "NAND bus width %d instead %d bit\n",
(this->options & NAND_BUSWIDTH_16) ? 16 : 8, (this->options & NAND_BUSWIDTH_16) ? 16 : 8, busw ? 16 : 8);
busw ? 16 : 8);
this->select_chip(mtd, -1); this->select_chip(mtd, -1);
return 1; return 1;
} }
...@@ -2456,13 +2439,12 @@ int nand_scan (struct mtd_info *mtd, int maxchips) ...@@ -2456,13 +2439,12 @@ int nand_scan (struct mtd_info *mtd, int maxchips)
this->chip_shift = ffs(this->chipsize) - 1; this->chip_shift = ffs(this->chipsize) - 1;
/* Set the bad block position */ /* Set the bad block position */
this->badblockpos = mtd->oobblock > 512 ? this->badblockpos = mtd->oobblock > 512 ? NAND_LARGE_BADBLOCK_POS : NAND_SMALL_BADBLOCK_POS;
NAND_LARGE_BADBLOCK_POS : NAND_SMALL_BADBLOCK_POS;
/* Get chip options, preserve non chip based options */ /* Get chip options, preserve non chip based options */
this->options &= ~NAND_CHIPOPTIONS_MSK; this->options &= ~NAND_CHIPOPTIONS_MSK;
this->options |= nand_flash_ids[i].options & NAND_CHIPOPTIONS_MSK; this->options |= nand_flash_ids[i].options & NAND_CHIPOPTIONS_MSK;
/* Set this as a default. Board drivers can override it, if neccecary */ /* Set this as a default. Board drivers can override it, if necessary */
this->options |= NAND_NO_AUTOINCR; this->options |= NAND_NO_AUTOINCR;
/* Check if this is a not a samsung device. Do not clear the options /* Check if this is a not a samsung device. Do not clear the options
* for chips which are not having an extended id. * for chips which are not having an extended id.
...@@ -2480,23 +2462,23 @@ int nand_scan (struct mtd_info *mtd, int maxchips) ...@@ -2480,23 +2462,23 @@ int nand_scan (struct mtd_info *mtd, int maxchips)
if (mtd->oobblock > 512 && this->cmdfunc == nand_command) if (mtd->oobblock > 512 && this->cmdfunc == nand_command)
this->cmdfunc = nand_command_lp; this->cmdfunc = nand_command_lp;
printk (KERN_INFO "NAND device: Manufacturer ID:" printk(KERN_INFO "NAND device: Manufacturer ID:"
" 0x%02x, Chip ID: 0x%02x (%s %s)\n", nand_maf_id, nand_dev_id, " 0x%02x, Chip ID: 0x%02x (%s %s)\n", nand_maf_id, nand_dev_id,
nand_manuf_ids[maf_id].name , nand_flash_ids[i].name); nand_manuf_ids[maf_id].name, nand_flash_ids[i].name);
break; break;
} }
if (!nand_flash_ids[i].name) { if (!nand_flash_ids[i].name) {
printk (KERN_WARNING "No NAND device found!!!\n"); printk(KERN_WARNING "No NAND device found!!!\n");
this->select_chip(mtd, -1); this->select_chip(mtd, -1);
return 1; return 1;
} }
for (i=1; i < maxchips; i++) { for (i = 1; i < maxchips; i++) {
this->select_chip(mtd, i); this->select_chip(mtd, i);
/* Send the command for reading device ID */ /* Send the command for reading device ID */
this->cmdfunc (mtd, NAND_CMD_READID, 0x00, -1); this->cmdfunc(mtd, NAND_CMD_READID, 0x00, -1);
/* Read manufacturer and device IDs */ /* Read manufacturer and device IDs */
if (nand_maf_id != this->read_byte(mtd) || if (nand_maf_id != this->read_byte(mtd) ||
...@@ -2506,13 +2488,13 @@ int nand_scan (struct mtd_info *mtd, int maxchips) ...@@ -2506,13 +2488,13 @@ int nand_scan (struct mtd_info *mtd, int maxchips)
if (i > 1) if (i > 1)
printk(KERN_INFO "%d NAND chips detected\n", i); printk(KERN_INFO "%d NAND chips detected\n", i);
/* Allocate buffers, if neccecary */ /* Allocate buffers, if necessary */
if (!this->oob_buf) { if (!this->oob_buf) {
size_t len; size_t len;
len = mtd->oobsize << (this->phys_erase_shift - this->page_shift); len = mtd->oobsize << (this->phys_erase_shift - this->page_shift);
this->oob_buf = kmalloc (len, GFP_KERNEL); this->oob_buf = kmalloc(len, GFP_KERNEL);
if (!this->oob_buf) { if (!this->oob_buf) {
printk (KERN_ERR "nand_scan(): Cannot allocate oob_buf\n"); printk(KERN_ERR "nand_scan(): Cannot allocate oob_buf\n");
return -ENOMEM; return -ENOMEM;
} }
this->options |= NAND_OOBBUF_ALLOC; this->options |= NAND_OOBBUF_ALLOC;
...@@ -2521,11 +2503,11 @@ int nand_scan (struct mtd_info *mtd, int maxchips) ...@@ -2521,11 +2503,11 @@ int nand_scan (struct mtd_info *mtd, int maxchips)
if (!this->data_buf) { if (!this->data_buf) {
size_t len; size_t len;
len = mtd->oobblock + mtd->oobsize; len = mtd->oobblock + mtd->oobsize;
this->data_buf = kmalloc (len, GFP_KERNEL); this->data_buf = kmalloc(len, GFP_KERNEL);
if (!this->data_buf) { if (!this->data_buf) {
if (this->options & NAND_OOBBUF_ALLOC) if (this->options & NAND_OOBBUF_ALLOC)
kfree (this->oob_buf); kfree(this->oob_buf);
printk (KERN_ERR "nand_scan(): Cannot allocate data_buf\n"); printk(KERN_ERR "nand_scan(): Cannot allocate data_buf\n");
return -ENOMEM; return -ENOMEM;
} }
this->options |= NAND_DATABUF_ALLOC; this->options |= NAND_DATABUF_ALLOC;
...@@ -2555,8 +2537,7 @@ int nand_scan (struct mtd_info *mtd, int maxchips) ...@@ -2555,8 +2537,7 @@ int nand_scan (struct mtd_info *mtd, int maxchips)
this->autooob = &nand_oob_64; this->autooob = &nand_oob_64;
break; break;
default: default:
printk (KERN_WARNING "No oob scheme defined for oobsize %d\n", printk(KERN_WARNING "No oob scheme defined for oobsize %d\n", mtd->oobsize);
mtd->oobsize);
BUG(); BUG();
} }
} }
...@@ -2591,7 +2572,7 @@ int nand_scan (struct mtd_info *mtd, int maxchips) ...@@ -2591,7 +2572,7 @@ int nand_scan (struct mtd_info *mtd, int maxchips)
case NAND_ECC_HW6_512: case NAND_ECC_HW6_512:
case NAND_ECC_HW8_512: case NAND_ECC_HW8_512:
if (mtd->oobblock == 256) { if (mtd->oobblock == 256) {
printk (KERN_WARNING "512 byte HW ECC not possible on 256 Byte pagesize, fallback to SW ECC \n"); printk(KERN_WARNING "512 byte HW ECC not possible on 256 Byte pagesize, fallback to SW ECC \n");
this->eccmode = NAND_ECC_SOFT; this->eccmode = NAND_ECC_SOFT;
this->calculate_ecc = nand_calculate_ecc; this->calculate_ecc = nand_calculate_ecc;
this->correct_data = nand_correct_data; this->correct_data = nand_correct_data;
...@@ -2603,7 +2584,7 @@ int nand_scan (struct mtd_info *mtd, int maxchips) ...@@ -2603,7 +2584,7 @@ int nand_scan (struct mtd_info *mtd, int maxchips)
break; break;
case NAND_ECC_NONE: case NAND_ECC_NONE:
printk (KERN_WARNING "NAND_ECC_NONE selected by board driver. This is not recommended !!\n"); printk(KERN_WARNING "NAND_ECC_NONE selected by board driver. This is not recommended !!\n");
this->eccmode = NAND_ECC_NONE; this->eccmode = NAND_ECC_NONE;
break; break;
...@@ -2613,7 +2594,7 @@ int nand_scan (struct mtd_info *mtd, int maxchips) ...@@ -2613,7 +2594,7 @@ int nand_scan (struct mtd_info *mtd, int maxchips)
break; break;
default: default:
printk (KERN_WARNING "Invalid NAND_ECC_MODE %d\n", this->eccmode); printk(KERN_WARNING "Invalid NAND_ECC_MODE %d\n", this->eccmode);
BUG(); BUG();
} }
...@@ -2631,7 +2612,7 @@ int nand_scan (struct mtd_info *mtd, int maxchips) ...@@ -2631,7 +2612,7 @@ int nand_scan (struct mtd_info *mtd, int maxchips)
case NAND_ECC_HW3_256: case NAND_ECC_HW3_256:
if (this->calculate_ecc && this->correct_data && this->enable_hwecc) if (this->calculate_ecc && this->correct_data && this->enable_hwecc)
break; break;
printk (KERN_WARNING "No ECC functions supplied, Hardware ECC not possible\n"); printk(KERN_WARNING "No ECC functions supplied, Hardware ECC not possible\n");
BUG(); BUG();
} }
...@@ -2659,8 +2640,8 @@ int nand_scan (struct mtd_info *mtd, int maxchips) ...@@ -2659,8 +2640,8 @@ int nand_scan (struct mtd_info *mtd, int maxchips)
/* Initialize state, waitqueue and spinlock */ /* Initialize state, waitqueue and spinlock */
this->state = FL_READY; this->state = FL_READY;
init_waitqueue_head (&this->wq); init_waitqueue_head(&this->wq);
spin_lock_init (&this->chip_lock); spin_lock_init(&this->chip_lock);
/* De-select the device */ /* De-select the device */
this->select_chip(mtd, -1); this->select_chip(mtd, -1);
...@@ -2702,37 +2683,36 @@ int nand_scan (struct mtd_info *mtd, int maxchips) ...@@ -2702,37 +2683,36 @@ int nand_scan (struct mtd_info *mtd, int maxchips)
return 0; return 0;
/* Build bad block table */ /* Build bad block table */
return this->scan_bbt (mtd); return this->scan_bbt(mtd);
} }
/** /**
* nand_release - [NAND Interface] Free resources held by the NAND device * nand_release - [NAND Interface] Free resources held by the NAND device
* @mtd: MTD device structure * @mtd: MTD device structure
*/ */
void nand_release (struct mtd_info *mtd) void nand_release(struct mtd_info *mtd)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
#ifdef CONFIG_MTD_PARTITIONS #ifdef CONFIG_MTD_PARTITIONS
/* Deregister partitions */ /* Deregister partitions */
del_mtd_partitions (mtd); del_mtd_partitions(mtd);
#endif #endif
/* Deregister the device */ /* Deregister the device */
del_mtd_device (mtd); del_mtd_device(mtd);
/* Free bad block table memory */ /* Free bad block table memory */
kfree (this->bbt); kfree(this->bbt);
/* Buffer allocated by nand_scan ? */ /* Buffer allocated by nand_scan ? */
if (this->options & NAND_OOBBUF_ALLOC) if (this->options & NAND_OOBBUF_ALLOC)
kfree (this->oob_buf); kfree(this->oob_buf);
/* Buffer allocated by nand_scan ? */ /* Buffer allocated by nand_scan ? */
if (this->options & NAND_DATABUF_ALLOC) if (this->options & NAND_DATABUF_ALLOC)
kfree (this->data_buf); kfree(this->data_buf);
} }
EXPORT_SYMBOL_GPL (nand_scan); EXPORT_SYMBOL_GPL(nand_scan);
EXPORT_SYMBOL_GPL (nand_release); EXPORT_SYMBOL_GPL(nand_release);
static int __init nand_base_init(void) static int __init nand_base_init(void)
{ {
...@@ -2748,6 +2728,6 @@ static void __exit nand_base_exit(void) ...@@ -2748,6 +2728,6 @@ static void __exit nand_base_exit(void)
module_init(nand_base_init); module_init(nand_base_init);
module_exit(nand_base_exit); module_exit(nand_base_exit);
MODULE_LICENSE ("GPL"); MODULE_LICENSE("GPL");
MODULE_AUTHOR ("Steven J. Hill <sjhill@realitydiluted.com>, Thomas Gleixner <tglx@linutronix.de>"); MODULE_AUTHOR("Steven J. Hill <sjhill@realitydiluted.com>, Thomas Gleixner <tglx@linutronix.de>");
MODULE_DESCRIPTION ("Generic NAND flash driver code"); MODULE_DESCRIPTION("Generic NAND flash driver code");
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
* *
* Following assumptions are made: * Following assumptions are made:
* - bbts start at a page boundary, if autolocated on a block boundary * - bbts start at a page boundary, if autolocated on a block boundary
* - the space neccecary for a bbt in FLASH does not exceed a block boundary * - the space necessary for a bbt in FLASH does not exceed a block boundary
* *
*/ */
...@@ -75,7 +75,7 @@ ...@@ -75,7 +75,7 @@
* pattern area contain 0xff * pattern area contain 0xff
* *
*/ */
static int check_pattern (uint8_t *buf, int len, int paglen, struct nand_bbt_descr *td) static int check_pattern(uint8_t *buf, int len, int paglen, struct nand_bbt_descr *td)
{ {
int i, end = 0; int i, end = 0;
uint8_t *p = buf; uint8_t *p = buf;
...@@ -116,7 +116,7 @@ static int check_pattern (uint8_t *buf, int len, int paglen, struct nand_bbt_des ...@@ -116,7 +116,7 @@ static int check_pattern (uint8_t *buf, int len, int paglen, struct nand_bbt_des
* no optional empty check * no optional empty check
* *
*/ */
static int check_short_pattern (uint8_t *buf, struct nand_bbt_descr *td) static int check_short_pattern(uint8_t *buf, struct nand_bbt_descr *td)
{ {
int i; int i;
uint8_t *p = buf; uint8_t *p = buf;
...@@ -142,7 +142,7 @@ static int check_short_pattern (uint8_t *buf, struct nand_bbt_descr *td) ...@@ -142,7 +142,7 @@ static int check_short_pattern (uint8_t *buf, struct nand_bbt_descr *td)
* Read the bad block table starting from page. * Read the bad block table starting from page.
* *
*/ */
static int read_bbt (struct mtd_info *mtd, uint8_t *buf, int page, int num, static int read_bbt(struct mtd_info *mtd, uint8_t *buf, int page, int num,
int bits, int offs, int reserved_block_code) int bits, int offs, int reserved_block_code)
{ {
int res, i, j, act = 0; int res, i, j, act = 0;
...@@ -152,17 +152,17 @@ static int read_bbt (struct mtd_info *mtd, uint8_t *buf, int page, int num, ...@@ -152,17 +152,17 @@ static int read_bbt (struct mtd_info *mtd, uint8_t *buf, int page, int num,
uint8_t msk = (uint8_t) ((1 << bits) - 1); uint8_t msk = (uint8_t) ((1 << bits) - 1);
totlen = (num * bits) >> 3; totlen = (num * bits) >> 3;
from = ((loff_t)page) << this->page_shift; from = ((loff_t) page) << this->page_shift;
while (totlen) { while (totlen) {
len = min (totlen, (size_t) (1 << this->bbt_erase_shift)); len = min(totlen, (size_t) (1 << this->bbt_erase_shift));
res = mtd->read_ecc (mtd, from, len, &retlen, buf, NULL, this->autooob); res = mtd->read_ecc(mtd, from, len, &retlen, buf, NULL, this->autooob);
if (res < 0) { if (res < 0) {
if (retlen != len) { if (retlen != len) {
printk (KERN_INFO "nand_bbt: Error reading bad block table\n"); printk(KERN_INFO "nand_bbt: Error reading bad block table\n");
return res; return res;
} }
printk (KERN_WARNING "nand_bbt: ECC error while reading bad block table\n"); printk(KERN_WARNING "nand_bbt: ECC error while reading bad block table\n");
} }
/* Analyse data */ /* Analyse data */
...@@ -172,16 +172,15 @@ static int read_bbt (struct mtd_info *mtd, uint8_t *buf, int page, int num, ...@@ -172,16 +172,15 @@ static int read_bbt (struct mtd_info *mtd, uint8_t *buf, int page, int num,
uint8_t tmp = (dat >> j) & msk; uint8_t tmp = (dat >> j) & msk;
if (tmp == msk) if (tmp == msk)
continue; continue;
if (reserved_block_code && if (reserved_block_code && (tmp == reserved_block_code)) {
(tmp == reserved_block_code)) { printk(KERN_DEBUG "nand_read_bbt: Reserved block at 0x%08x\n",
printk (KERN_DEBUG "nand_read_bbt: Reserved block at 0x%08x\n",
((offs << 2) + (act >> 1)) << this->bbt_erase_shift); ((offs << 2) + (act >> 1)) << this->bbt_erase_shift);
this->bbt[offs + (act >> 3)] |= 0x2 << (act & 0x06); this->bbt[offs + (act >> 3)] |= 0x2 << (act & 0x06);
continue; continue;
} }
/* Leave it for now, if its matured we can move this /* Leave it for now, if its matured we can move this
* message to MTD_DEBUG_LEVEL0 */ * message to MTD_DEBUG_LEVEL0 */
printk (KERN_DEBUG "nand_read_bbt: Bad block at 0x%08x\n", printk(KERN_DEBUG "nand_read_bbt: Bad block at 0x%08x\n",
((offs << 2) + (act >> 1)) << this->bbt_erase_shift); ((offs << 2) + (act >> 1)) << this->bbt_erase_shift);
/* Factory marked bad or worn out ? */ /* Factory marked bad or worn out ? */
if (tmp == 0) if (tmp == 0)
...@@ -207,7 +206,7 @@ static int read_bbt (struct mtd_info *mtd, uint8_t *buf, int page, int num, ...@@ -207,7 +206,7 @@ static int read_bbt (struct mtd_info *mtd, uint8_t *buf, int page, int num,
* Read the bad block table for all chips starting at a given page * Read the bad block table for all chips starting at a given page
* We assume that the bbt bits are in consecutive order. * We assume that the bbt bits are in consecutive order.
*/ */
static int read_abs_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *td, int chip) static int read_abs_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *td, int chip)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
int res = 0, i; int res = 0, i;
...@@ -242,23 +241,22 @@ static int read_abs_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_des ...@@ -242,23 +241,22 @@ static int read_abs_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_des
* We assume that the bbt bits are in consecutive order. * We assume that the bbt bits are in consecutive order.
* *
*/ */
static int read_abs_bbts (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *td, static int read_abs_bbts(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *td, struct nand_bbt_descr *md)
struct nand_bbt_descr *md)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
/* Read the primary version, if available */ /* Read the primary version, if available */
if (td->options & NAND_BBT_VERSION) { if (td->options & NAND_BBT_VERSION) {
nand_read_raw (mtd, buf, td->pages[0] << this->page_shift, mtd->oobblock, mtd->oobsize); nand_read_raw(mtd, buf, td->pages[0] << this->page_shift, mtd->oobblock, mtd->oobsize);
td->version[0] = buf[mtd->oobblock + td->veroffs]; td->version[0] = buf[mtd->oobblock + td->veroffs];
printk (KERN_DEBUG "Bad block table at page %d, version 0x%02X\n", td->pages[0], td->version[0]); printk(KERN_DEBUG "Bad block table at page %d, version 0x%02X\n", td->pages[0], td->version[0]);
} }
/* Read the mirror version, if available */ /* Read the mirror version, if available */
if (md && (md->options & NAND_BBT_VERSION)) { if (md && (md->options & NAND_BBT_VERSION)) {
nand_read_raw (mtd, buf, md->pages[0] << this->page_shift, mtd->oobblock, mtd->oobsize); nand_read_raw(mtd, buf, md->pages[0] << this->page_shift, mtd->oobblock, mtd->oobsize);
md->version[0] = buf[mtd->oobblock + md->veroffs]; md->version[0] = buf[mtd->oobblock + md->veroffs];
printk (KERN_DEBUG "Bad block table at page %d, version 0x%02X\n", md->pages[0], md->version[0]); printk(KERN_DEBUG "Bad block table at page %d, version 0x%02X\n", md->pages[0], md->version[0]);
} }
return 1; return 1;
...@@ -275,7 +273,7 @@ static int read_abs_bbts (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_de ...@@ -275,7 +273,7 @@ static int read_abs_bbts (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_de
* Create a bad block table by scanning the device * Create a bad block table by scanning the device
* for the given good/bad block identify pattern * for the given good/bad block identify pattern
*/ */
static int create_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *bd, int chip) static int create_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *bd, int chip)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
int i, j, numblocks, len, scanlen; int i, j, numblocks, len, scanlen;
...@@ -283,7 +281,7 @@ static int create_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr ...@@ -283,7 +281,7 @@ static int create_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
loff_t from; loff_t from;
size_t readlen, ooblen; size_t readlen, ooblen;
printk (KERN_INFO "Scanning device for bad blocks\n"); printk(KERN_INFO "Scanning device for bad blocks\n");
if (bd->options & NAND_BBT_SCANALLPAGES) if (bd->options & NAND_BBT_SCANALLPAGES)
len = 1 << (this->bbt_erase_shift - this->page_shift); len = 1 << (this->bbt_erase_shift - this->page_shift);
...@@ -313,7 +311,7 @@ static int create_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr ...@@ -313,7 +311,7 @@ static int create_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
from = 0; from = 0;
} else { } else {
if (chip >= this->numchips) { if (chip >= this->numchips) {
printk (KERN_WARNING "create_bbt(): chipnr (%d) > available chips (%d)\n", printk(KERN_WARNING "create_bbt(): chipnr (%d) > available chips (%d)\n",
chip + 1, this->numchips); chip + 1, this->numchips);
return -EINVAL; return -EINVAL;
} }
...@@ -327,7 +325,7 @@ static int create_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr ...@@ -327,7 +325,7 @@ static int create_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
int ret; int ret;
if (bd->options & NAND_BBT_SCANEMPTY) if (bd->options & NAND_BBT_SCANEMPTY)
if ((ret = nand_read_raw (mtd, buf, from, readlen, ooblen))) if ((ret = nand_read_raw(mtd, buf, from, readlen, ooblen)))
return ret; return ret;
for (j = 0; j < len; j++) { for (j = 0; j < len; j++) {
...@@ -336,22 +334,21 @@ static int create_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr ...@@ -336,22 +334,21 @@ static int create_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
/* Read the full oob until read_oob is fixed to /* Read the full oob until read_oob is fixed to
* handle single byte reads for 16 bit buswidth */ * handle single byte reads for 16 bit buswidth */
ret = mtd->read_oob(mtd, from + j * mtd->oobblock, ret = mtd->read_oob(mtd, from + j * mtd->oobblock, mtd->oobsize, &retlen, buf);
mtd->oobsize, &retlen, buf);
if (ret) if (ret)
return ret; return ret;
if (check_short_pattern (buf, bd)) { if (check_short_pattern(buf, bd)) {
this->bbt[i >> 3] |= 0x03 << (i & 0x6); this->bbt[i >> 3] |= 0x03 << (i & 0x6);
printk (KERN_WARNING "Bad eraseblock %d at 0x%08x\n", printk(KERN_WARNING "Bad eraseblock %d at 0x%08x\n",
i >> 1, (unsigned int) from); i >> 1, (unsigned int)from);
break; break;
} }
} else { } else {
if (check_pattern (&buf[j * scanlen], scanlen, mtd->oobblock, bd)) { if (check_pattern(&buf[j * scanlen], scanlen, mtd->oobblock, bd)) {
this->bbt[i >> 3] |= 0x03 << (i & 0x6); this->bbt[i >> 3] |= 0x03 << (i & 0x6);
printk (KERN_WARNING "Bad eraseblock %d at 0x%08x\n", printk(KERN_WARNING "Bad eraseblock %d at 0x%08x\n",
i >> 1, (unsigned int) from); i >> 1, (unsigned int)from);
break; break;
} }
} }
...@@ -374,12 +371,12 @@ static int create_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr ...@@ -374,12 +371,12 @@ static int create_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
* block. * block.
* If the option NAND_BBT_PERCHIP is given, each chip is searched * If the option NAND_BBT_PERCHIP is given, each chip is searched
* for a bbt, which contains the bad block information of this chip. * for a bbt, which contains the bad block information of this chip.
* This is neccecary to provide support for certain DOC devices. * This is necessary to provide support for certain DOC devices.
* *
* The bbt ident pattern resides in the oob area of the first page * The bbt ident pattern resides in the oob area of the first page
* in a block. * in a block.
*/ */
static int search_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *td) static int search_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *td)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
int i, chips; int i, chips;
...@@ -389,7 +386,7 @@ static int search_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr ...@@ -389,7 +386,7 @@ static int search_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
/* Search direction top -> down ? */ /* Search direction top -> down ? */
if (td->options & NAND_BBT_LASTBLOCK) { if (td->options & NAND_BBT_LASTBLOCK) {
startblock = (mtd->size >> this->bbt_erase_shift) -1; startblock = (mtd->size >> this->bbt_erase_shift) - 1;
dir = -1; dir = -1;
} else { } else {
startblock = 0; startblock = 0;
...@@ -417,7 +414,7 @@ static int search_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr ...@@ -417,7 +414,7 @@ static int search_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
for (block = 0; block < td->maxblocks; block++) { for (block = 0; block < td->maxblocks; block++) {
int actblock = startblock + dir * block; int actblock = startblock + dir * block;
/* Read first page */ /* Read first page */
nand_read_raw (mtd, buf, actblock << this->bbt_erase_shift, mtd->oobblock, mtd->oobsize); nand_read_raw(mtd, buf, actblock << this->bbt_erase_shift, mtd->oobblock, mtd->oobsize);
if (!check_pattern(buf, scanlen, mtd->oobblock, td)) { if (!check_pattern(buf, scanlen, mtd->oobblock, td)) {
td->pages[i] = actblock << (this->bbt_erase_shift - this->page_shift); td->pages[i] = actblock << (this->bbt_erase_shift - this->page_shift);
if (td->options & NAND_BBT_VERSION) { if (td->options & NAND_BBT_VERSION) {
...@@ -431,9 +428,10 @@ static int search_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr ...@@ -431,9 +428,10 @@ static int search_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
/* Check, if we found a bbt for each requested chip */ /* Check, if we found a bbt for each requested chip */
for (i = 0; i < chips; i++) { for (i = 0; i < chips; i++) {
if (td->pages[i] == -1) if (td->pages[i] == -1)
printk (KERN_WARNING "Bad block table not found for chip %d\n", i); printk(KERN_WARNING "Bad block table not found for chip %d\n", i);
else else
printk (KERN_DEBUG "Bad block table found at page %d, version 0x%02X\n", td->pages[i], td->version[i]); printk(KERN_DEBUG "Bad block table found at page %d, version 0x%02X\n", td->pages[i],
td->version[i]);
} }
return 0; return 0;
} }
...@@ -447,21 +445,19 @@ static int search_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr ...@@ -447,21 +445,19 @@ static int search_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
* *
* Search and read the bad block table(s) * Search and read the bad block table(s)
*/ */
static int search_read_bbts (struct mtd_info *mtd, uint8_t *buf, static int search_read_bbts(struct mtd_info *mtd, uint8_t * buf, struct nand_bbt_descr *td, struct nand_bbt_descr *md)
struct nand_bbt_descr *td, struct nand_bbt_descr *md)
{ {
/* Search the primary table */ /* Search the primary table */
search_bbt (mtd, buf, td); search_bbt(mtd, buf, td);
/* Search the mirror table */ /* Search the mirror table */
if (md) if (md)
search_bbt (mtd, buf, md); search_bbt(mtd, buf, md);
/* Force result check */ /* Force result check */
return 1; return 1;
} }
/** /**
* write_bbt - [GENERIC] (Re)write the bad block table * write_bbt - [GENERIC] (Re)write the bad block table
* *
...@@ -474,7 +470,7 @@ static int search_read_bbts (struct mtd_info *mtd, uint8_t *buf, ...@@ -474,7 +470,7 @@ static int search_read_bbts (struct mtd_info *mtd, uint8_t *buf,
* (Re)write the bad block table * (Re)write the bad block table
* *
*/ */
static int write_bbt (struct mtd_info *mtd, uint8_t *buf, static int write_bbt(struct mtd_info *mtd, uint8_t *buf,
struct nand_bbt_descr *td, struct nand_bbt_descr *md, int chipsel) struct nand_bbt_descr *td, struct nand_bbt_descr *md, int chipsel)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
...@@ -492,7 +488,7 @@ static int write_bbt (struct mtd_info *mtd, uint8_t *buf, ...@@ -492,7 +488,7 @@ static int write_bbt (struct mtd_info *mtd, uint8_t *buf,
rcode = 0xff; rcode = 0xff;
/* Write bad block table per chip rather than per device ? */ /* Write bad block table per chip rather than per device ? */
if (td->options & NAND_BBT_PERCHIP) { if (td->options & NAND_BBT_PERCHIP) {
numblocks = (int) (this->chipsize >> this->bbt_erase_shift); numblocks = (int)(this->chipsize >> this->bbt_erase_shift);
/* Full device write or specific chip ? */ /* Full device write or specific chip ? */
if (chipsel == -1) { if (chipsel == -1) {
nrchips = this->numchips; nrchips = this->numchips;
...@@ -501,7 +497,7 @@ static int write_bbt (struct mtd_info *mtd, uint8_t *buf, ...@@ -501,7 +497,7 @@ static int write_bbt (struct mtd_info *mtd, uint8_t *buf,
chip = chipsel; chip = chipsel;
} }
} else { } else {
numblocks = (int) (mtd->size >> this->bbt_erase_shift); numblocks = (int)(mtd->size >> this->bbt_erase_shift);
nrchips = 1; nrchips = 1;
} }
...@@ -540,9 +536,9 @@ static int write_bbt (struct mtd_info *mtd, uint8_t *buf, ...@@ -540,9 +536,9 @@ static int write_bbt (struct mtd_info *mtd, uint8_t *buf,
if (!md || md->pages[chip] != page) if (!md || md->pages[chip] != page)
goto write; goto write;
} }
printk (KERN_ERR "No space left to write bad block table\n"); printk(KERN_ERR "No space left to write bad block table\n");
return -ENOSPC; return -ENOSPC;
write: write:
/* Set up shift count and masks for the flash table */ /* Set up shift count and masks for the flash table */
bits = td->options & NAND_BBT_NRBITS_MSK; bits = td->options & NAND_BBT_NRBITS_MSK;
...@@ -558,7 +554,7 @@ static int write_bbt (struct mtd_info *mtd, uint8_t *buf, ...@@ -558,7 +554,7 @@ static int write_bbt (struct mtd_info *mtd, uint8_t *buf,
to = ((loff_t) page) << this->page_shift; to = ((loff_t) page) << this->page_shift;
memcpy (&oobinfo, this->autooob, sizeof(oobinfo)); memcpy(&oobinfo, this->autooob, sizeof(oobinfo));
oobinfo.useecc = MTD_NANDECC_PLACEONLY; oobinfo.useecc = MTD_NANDECC_PLACEONLY;
/* Must we save the block contents ? */ /* Must we save the block contents ? */
...@@ -566,21 +562,22 @@ static int write_bbt (struct mtd_info *mtd, uint8_t *buf, ...@@ -566,21 +562,22 @@ static int write_bbt (struct mtd_info *mtd, uint8_t *buf,
/* Make it block aligned */ /* Make it block aligned */
to &= ~((loff_t) ((1 << this->bbt_erase_shift) - 1)); to &= ~((loff_t) ((1 << this->bbt_erase_shift) - 1));
len = 1 << this->bbt_erase_shift; len = 1 << this->bbt_erase_shift;
res = mtd->read_ecc (mtd, to, len, &retlen, buf, &buf[len], &oobinfo); res = mtd->read_ecc(mtd, to, len, &retlen, buf, &buf[len], &oobinfo);
if (res < 0) { if (res < 0) {
if (retlen != len) { if (retlen != len) {
printk (KERN_INFO "nand_bbt: Error reading block for writing the bad block table\n"); printk(KERN_INFO
"nand_bbt: Error reading block for writing the bad block table\n");
return res; return res;
} }
printk (KERN_WARNING "nand_bbt: ECC error while reading block for writing bad block table\n"); printk(KERN_WARNING "nand_bbt: ECC error while reading block for writing bad block table\n");
} }
/* Calc the byte offset in the buffer */ /* Calc the byte offset in the buffer */
pageoffs = page - (int)(to >> this->page_shift); pageoffs = page - (int)(to >> this->page_shift);
offs = pageoffs << this->page_shift; offs = pageoffs << this->page_shift;
/* Preset the bbt area with 0xff */ /* Preset the bbt area with 0xff */
memset (&buf[offs], 0xff, (size_t)(numblocks >> sft)); memset(&buf[offs], 0xff, (size_t) (numblocks >> sft));
/* Preset the bbt's oob area with 0xff */ /* Preset the bbt's oob area with 0xff */
memset (&buf[len + pageoffs * mtd->oobsize], 0xff, memset(&buf[len + pageoffs * mtd->oobsize], 0xff,
((len >> this->page_shift) - pageoffs) * mtd->oobsize); ((len >> this->page_shift) - pageoffs) * mtd->oobsize);
if (td->options & NAND_BBT_VERSION) { if (td->options & NAND_BBT_VERSION) {
buf[len + (pageoffs * mtd->oobsize) + td->veroffs] = td->version[chip]; buf[len + (pageoffs * mtd->oobsize) + td->veroffs] = td->version[chip];
...@@ -589,22 +586,22 @@ static int write_bbt (struct mtd_info *mtd, uint8_t *buf, ...@@ -589,22 +586,22 @@ static int write_bbt (struct mtd_info *mtd, uint8_t *buf,
/* Calc length */ /* Calc length */
len = (size_t) (numblocks >> sft); len = (size_t) (numblocks >> sft);
/* Make it page aligned ! */ /* Make it page aligned ! */
len = (len + (mtd->oobblock-1)) & ~(mtd->oobblock-1); len = (len + (mtd->oobblock - 1)) & ~(mtd->oobblock - 1);
/* Preset the buffer with 0xff */ /* Preset the buffer with 0xff */
memset (buf, 0xff, len + (len >> this->page_shift) * mtd->oobsize); memset(buf, 0xff, len + (len >> this->page_shift) * mtd->oobsize);
offs = 0; offs = 0;
/* Pattern is located in oob area of first page */ /* Pattern is located in oob area of first page */
memcpy (&buf[len + td->offs], td->pattern, td->len); memcpy(&buf[len + td->offs], td->pattern, td->len);
if (td->options & NAND_BBT_VERSION) { if (td->options & NAND_BBT_VERSION) {
buf[len + td->veroffs] = td->version[chip]; buf[len + td->veroffs] = td->version[chip];
} }
} }
/* walk through the memory table */ /* walk through the memory table */
for (i = 0; i < numblocks; ) { for (i = 0; i < numblocks;) {
uint8_t dat; uint8_t dat;
dat = this->bbt[bbtoffs + (i >> 2)]; dat = this->bbt[bbtoffs + (i >> 2)];
for (j = 0; j < 4; j++ , i++) { for (j = 0; j < 4; j++, i++) {
int sftcnt = (i << (3 - sft)) & sftmsk; int sftcnt = (i << (3 - sft)) & sftmsk;
/* Do not store the reserved bbt blocks ! */ /* Do not store the reserved bbt blocks ! */
buf[offs + (i >> sft)] &= ~(msk[dat & 0x03] << sftcnt); buf[offs + (i >> sft)] &= ~(msk[dat & 0x03] << sftcnt);
...@@ -612,23 +609,23 @@ static int write_bbt (struct mtd_info *mtd, uint8_t *buf, ...@@ -612,23 +609,23 @@ static int write_bbt (struct mtd_info *mtd, uint8_t *buf,
} }
} }
memset (&einfo, 0, sizeof (einfo)); memset(&einfo, 0, sizeof(einfo));
einfo.mtd = mtd; einfo.mtd = mtd;
einfo.addr = (unsigned long) to; einfo.addr = (unsigned long)to;
einfo.len = 1 << this->bbt_erase_shift; einfo.len = 1 << this->bbt_erase_shift;
res = nand_erase_nand (mtd, &einfo, 1); res = nand_erase_nand(mtd, &einfo, 1);
if (res < 0) { if (res < 0) {
printk (KERN_WARNING "nand_bbt: Error during block erase: %d\n", res); printk(KERN_WARNING "nand_bbt: Error during block erase: %d\n", res);
return res; return res;
} }
res = mtd->write_ecc (mtd, to, len, &retlen, buf, &buf[len], &oobinfo); res = mtd->write_ecc(mtd, to, len, &retlen, buf, &buf[len], &oobinfo);
if (res < 0) { if (res < 0) {
printk (KERN_WARNING "nand_bbt: Error while writing bad block table %d\n", res); printk(KERN_WARNING "nand_bbt: Error while writing bad block table %d\n", res);
return res; return res;
} }
printk (KERN_DEBUG "Bad block table written to 0x%08x, version 0x%02X\n", printk(KERN_DEBUG "Bad block table written to 0x%08x, version 0x%02X\n",
(unsigned int) to, td->version[chip]); (unsigned int)to, td->version[chip]);
/* Mark it as used */ /* Mark it as used */
td->pages[chip] = page; td->pages[chip] = page;
...@@ -644,27 +641,27 @@ static int write_bbt (struct mtd_info *mtd, uint8_t *buf, ...@@ -644,27 +641,27 @@ static int write_bbt (struct mtd_info *mtd, uint8_t *buf,
* The function creates a memory based bbt by scanning the device * The function creates a memory based bbt by scanning the device
* for manufacturer / software marked good / bad blocks * for manufacturer / software marked good / bad blocks
*/ */
static inline int nand_memory_bbt (struct mtd_info *mtd, struct nand_bbt_descr *bd) static inline int nand_memory_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
bd->options &= ~NAND_BBT_SCANEMPTY; bd->options &= ~NAND_BBT_SCANEMPTY;
return create_bbt (mtd, this->data_buf, bd, -1); return create_bbt(mtd, this->data_buf, bd, -1);
} }
/** /**
* check_create - [GENERIC] create and write bbt(s) if neccecary * check_create - [GENERIC] create and write bbt(s) if necessary
* @mtd: MTD device structure * @mtd: MTD device structure
* @buf: temporary buffer * @buf: temporary buffer
* @bd: descriptor for the good/bad block search pattern * @bd: descriptor for the good/bad block search pattern
* *
* The function checks the results of the previous call to read_bbt * The function checks the results of the previous call to read_bbt
* and creates / updates the bbt(s) if neccecary * and creates / updates the bbt(s) if necessary
* Creation is neccecary if no bbt was found for the chip/device * Creation is necessary if no bbt was found for the chip/device
* Update is neccecary if one of the tables is missing or the * Update is necessary if one of the tables is missing or the
* version nr. of one table is less than the other * version nr. of one table is less than the other
*/ */
static int check_create (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *bd) static int check_create(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *bd)
{ {
int i, chips, writeops, chipsel, res; int i, chips, writeops, chipsel, res;
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
...@@ -732,35 +729,35 @@ static int check_create (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_des ...@@ -732,35 +729,35 @@ static int check_create (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_des
rd = td; rd = td;
goto writecheck; goto writecheck;
} }
create: create:
/* Create the bad block table by scanning the device ? */ /* Create the bad block table by scanning the device ? */
if (!(td->options & NAND_BBT_CREATE)) if (!(td->options & NAND_BBT_CREATE))
continue; continue;
/* Create the table in memory by scanning the chip(s) */ /* Create the table in memory by scanning the chip(s) */
create_bbt (mtd, buf, bd, chipsel); create_bbt(mtd, buf, bd, chipsel);
td->version[i] = 1; td->version[i] = 1;
if (md) if (md)
md->version[i] = 1; md->version[i] = 1;
writecheck: writecheck:
/* read back first ? */ /* read back first ? */
if (rd) if (rd)
read_abs_bbt (mtd, buf, rd, chipsel); read_abs_bbt(mtd, buf, rd, chipsel);
/* If they weren't versioned, read both. */ /* If they weren't versioned, read both. */
if (rd2) if (rd2)
read_abs_bbt (mtd, buf, rd2, chipsel); read_abs_bbt(mtd, buf, rd2, chipsel);
/* Write the bad block table to the device ? */ /* Write the bad block table to the device ? */
if ((writeops & 0x01) && (td->options & NAND_BBT_WRITE)) { if ((writeops & 0x01) && (td->options & NAND_BBT_WRITE)) {
res = write_bbt (mtd, buf, td, md, chipsel); res = write_bbt(mtd, buf, td, md, chipsel);
if (res < 0) if (res < 0)
return res; return res;
} }
/* Write the mirror bad block table to the device ? */ /* Write the mirror bad block table to the device ? */
if ((writeops & 0x02) && md && (md->options & NAND_BBT_WRITE)) { if ((writeops & 0x02) && md && (md->options & NAND_BBT_WRITE)) {
res = write_bbt (mtd, buf, md, td, chipsel); res = write_bbt(mtd, buf, md, td, chipsel);
if (res < 0) if (res < 0)
return res; return res;
} }
...@@ -777,7 +774,7 @@ static int check_create (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_des ...@@ -777,7 +774,7 @@ static int check_create (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_des
* accidental erasures / writes. The regions are identified by * accidental erasures / writes. The regions are identified by
* the mark 0x02. * the mark 0x02.
*/ */
static void mark_bbt_region (struct mtd_info *mtd, struct nand_bbt_descr *td) static void mark_bbt_region(struct mtd_info *mtd, struct nand_bbt_descr *td)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
int i, j, chips, block, nrblocks, update; int i, j, chips, block, nrblocks, update;
...@@ -795,7 +792,8 @@ static void mark_bbt_region (struct mtd_info *mtd, struct nand_bbt_descr *td) ...@@ -795,7 +792,8 @@ static void mark_bbt_region (struct mtd_info *mtd, struct nand_bbt_descr *td)
for (i = 0; i < chips; i++) { for (i = 0; i < chips; i++) {
if ((td->options & NAND_BBT_ABSPAGE) || if ((td->options & NAND_BBT_ABSPAGE) ||
!(td->options & NAND_BBT_WRITE)) { !(td->options & NAND_BBT_WRITE)) {
if (td->pages[i] == -1) continue; if (td->pages[i] == -1)
continue;
block = td->pages[i] >> (this->bbt_erase_shift - this->page_shift); block = td->pages[i] >> (this->bbt_erase_shift - this->page_shift);
block <<= 1; block <<= 1;
oldval = this->bbt[(block >> 3)]; oldval = this->bbt[(block >> 3)];
...@@ -815,7 +813,8 @@ static void mark_bbt_region (struct mtd_info *mtd, struct nand_bbt_descr *td) ...@@ -815,7 +813,8 @@ static void mark_bbt_region (struct mtd_info *mtd, struct nand_bbt_descr *td)
oldval = this->bbt[(block >> 3)]; oldval = this->bbt[(block >> 3)];
newval = oldval | (0x2 << (block & 0x06)); newval = oldval | (0x2 << (block & 0x06));
this->bbt[(block >> 3)] = newval; this->bbt[(block >> 3)] = newval;
if (oldval != newval) update = 1; if (oldval != newval)
update = 1;
block += 2; block += 2;
} }
/* If we want reserved blocks to be recorded to flash, and some /* If we want reserved blocks to be recorded to flash, and some
...@@ -840,7 +839,7 @@ static void mark_bbt_region (struct mtd_info *mtd, struct nand_bbt_descr *td) ...@@ -840,7 +839,7 @@ static void mark_bbt_region (struct mtd_info *mtd, struct nand_bbt_descr *td)
* by calling the nand_free_bbt function. * by calling the nand_free_bbt function.
* *
*/ */
int nand_scan_bbt (struct mtd_info *mtd, struct nand_bbt_descr *bd) int nand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
int len, res = 0; int len, res = 0;
...@@ -850,21 +849,21 @@ int nand_scan_bbt (struct mtd_info *mtd, struct nand_bbt_descr *bd) ...@@ -850,21 +849,21 @@ int nand_scan_bbt (struct mtd_info *mtd, struct nand_bbt_descr *bd)
len = mtd->size >> (this->bbt_erase_shift + 2); len = mtd->size >> (this->bbt_erase_shift + 2);
/* Allocate memory (2bit per block) */ /* Allocate memory (2bit per block) */
this->bbt = kmalloc (len, GFP_KERNEL); this->bbt = kmalloc(len, GFP_KERNEL);
if (!this->bbt) { if (!this->bbt) {
printk (KERN_ERR "nand_scan_bbt: Out of memory\n"); printk(KERN_ERR "nand_scan_bbt: Out of memory\n");
return -ENOMEM; return -ENOMEM;
} }
/* Clear the memory bad block table */ /* Clear the memory bad block table */
memset (this->bbt, 0x00, len); memset(this->bbt, 0x00, len);
/* If no primary table decriptor is given, scan the device /* If no primary table decriptor is given, scan the device
* to build a memory based bad block table * to build a memory based bad block table
*/ */
if (!td) { if (!td) {
if ((res = nand_memory_bbt(mtd, bd))) { if ((res = nand_memory_bbt(mtd, bd))) {
printk (KERN_ERR "nand_bbt: Can't scan flash and build the RAM-based BBT\n"); printk(KERN_ERR "nand_bbt: Can't scan flash and build the RAM-based BBT\n");
kfree (this->bbt); kfree(this->bbt);
this->bbt = NULL; this->bbt = NULL;
} }
return res; return res;
...@@ -875,33 +874,32 @@ int nand_scan_bbt (struct mtd_info *mtd, struct nand_bbt_descr *bd) ...@@ -875,33 +874,32 @@ int nand_scan_bbt (struct mtd_info *mtd, struct nand_bbt_descr *bd)
len += (len >> this->page_shift) * mtd->oobsize; len += (len >> this->page_shift) * mtd->oobsize;
buf = vmalloc(len); buf = vmalloc(len);
if (!buf) { if (!buf) {
printk (KERN_ERR "nand_bbt: Out of memory\n"); printk(KERN_ERR "nand_bbt: Out of memory\n");
kfree (this->bbt); kfree(this->bbt);
this->bbt = NULL; this->bbt = NULL;
return -ENOMEM; return -ENOMEM;
} }
/* Is the bbt at a given page ? */ /* Is the bbt at a given page ? */
if (td->options & NAND_BBT_ABSPAGE) { if (td->options & NAND_BBT_ABSPAGE) {
res = read_abs_bbts (mtd, buf, td, md); res = read_abs_bbts(mtd, buf, td, md);
} else { } else {
/* Search the bad block table using a pattern in oob */ /* Search the bad block table using a pattern in oob */
res = search_read_bbts (mtd, buf, td, md); res = search_read_bbts(mtd, buf, td, md);
} }
if (res) if (res)
res = check_create (mtd, buf, bd); res = check_create(mtd, buf, bd);
/* Prevent the bbt regions from erasing / writing */ /* Prevent the bbt regions from erasing / writing */
mark_bbt_region (mtd, td); mark_bbt_region(mtd, td);
if (md) if (md)
mark_bbt_region (mtd, md); mark_bbt_region(mtd, md);
vfree (buf); vfree(buf);
return res; return res;
} }
/** /**
* nand_update_bbt - [NAND Interface] update bad block table(s) * nand_update_bbt - [NAND Interface] update bad block table(s)
* @mtd: MTD device structure * @mtd: MTD device structure
...@@ -909,7 +907,7 @@ int nand_scan_bbt (struct mtd_info *mtd, struct nand_bbt_descr *bd) ...@@ -909,7 +907,7 @@ int nand_scan_bbt (struct mtd_info *mtd, struct nand_bbt_descr *bd)
* *
* The function updates the bad block table(s) * The function updates the bad block table(s)
*/ */
int nand_update_bbt (struct mtd_info *mtd, loff_t offs) int nand_update_bbt(struct mtd_info *mtd, loff_t offs)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
int len, res = 0, writeops = 0; int len, res = 0, writeops = 0;
...@@ -925,9 +923,9 @@ int nand_update_bbt (struct mtd_info *mtd, loff_t offs) ...@@ -925,9 +923,9 @@ int nand_update_bbt (struct mtd_info *mtd, loff_t offs)
/* Allocate a temporary buffer for one eraseblock incl. oob */ /* Allocate a temporary buffer for one eraseblock incl. oob */
len = (1 << this->bbt_erase_shift); len = (1 << this->bbt_erase_shift);
len += (len >> this->page_shift) * mtd->oobsize; len += (len >> this->page_shift) * mtd->oobsize;
buf = kmalloc (len, GFP_KERNEL); buf = kmalloc(len, GFP_KERNEL);
if (!buf) { if (!buf) {
printk (KERN_ERR "nand_update_bbt: Out of memory\n"); printk(KERN_ERR "nand_update_bbt: Out of memory\n");
return -ENOMEM; return -ENOMEM;
} }
...@@ -935,7 +933,7 @@ int nand_update_bbt (struct mtd_info *mtd, loff_t offs) ...@@ -935,7 +933,7 @@ int nand_update_bbt (struct mtd_info *mtd, loff_t offs)
/* Do we have a bbt per chip ? */ /* Do we have a bbt per chip ? */
if (td->options & NAND_BBT_PERCHIP) { if (td->options & NAND_BBT_PERCHIP) {
chip = (int) (offs >> this->chip_shift); chip = (int)(offs >> this->chip_shift);
chipsel = chip; chipsel = chip;
} else { } else {
chip = 0; chip = 0;
...@@ -948,17 +946,17 @@ int nand_update_bbt (struct mtd_info *mtd, loff_t offs) ...@@ -948,17 +946,17 @@ int nand_update_bbt (struct mtd_info *mtd, loff_t offs)
/* Write the bad block table to the device ? */ /* Write the bad block table to the device ? */
if ((writeops & 0x01) && (td->options & NAND_BBT_WRITE)) { if ((writeops & 0x01) && (td->options & NAND_BBT_WRITE)) {
res = write_bbt (mtd, buf, td, md, chipsel); res = write_bbt(mtd, buf, td, md, chipsel);
if (res < 0) if (res < 0)
goto out; goto out;
} }
/* Write the mirror bad block table to the device ? */ /* Write the mirror bad block table to the device ? */
if ((writeops & 0x02) && md && (md->options & NAND_BBT_WRITE)) { if ((writeops & 0x02) && md && (md->options & NAND_BBT_WRITE)) {
res = write_bbt (mtd, buf, md, td, chipsel); res = write_bbt(mtd, buf, md, td, chipsel);
} }
out: out:
kfree (buf); kfree(buf);
return res; return res;
} }
...@@ -1036,7 +1034,7 @@ static struct nand_bbt_descr bbt_mirror_descr = { ...@@ -1036,7 +1034,7 @@ static struct nand_bbt_descr bbt_mirror_descr = {
* support for the device and calls the nand_scan_bbt function * support for the device and calls the nand_scan_bbt function
* *
*/ */
int nand_default_bbt (struct mtd_info *mtd) int nand_default_bbt(struct mtd_info *mtd)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
...@@ -1054,10 +1052,9 @@ int nand_default_bbt (struct mtd_info *mtd) ...@@ -1054,10 +1052,9 @@ int nand_default_bbt (struct mtd_info *mtd)
this->bbt_md = &bbt_mirror_descr; this->bbt_md = &bbt_mirror_descr;
} }
this->options |= NAND_USE_FLASH_BBT; this->options |= NAND_USE_FLASH_BBT;
return nand_scan_bbt (mtd, &agand_flashbased); return nand_scan_bbt(mtd, &agand_flashbased);
} }
/* Is a flash based bad block table requested ? */ /* Is a flash based bad block table requested ? */
if (this->options & NAND_USE_FLASH_BBT) { if (this->options & NAND_USE_FLASH_BBT) {
/* Use the default pattern descriptors */ /* Use the default pattern descriptors */
...@@ -1066,8 +1063,7 @@ int nand_default_bbt (struct mtd_info *mtd) ...@@ -1066,8 +1063,7 @@ int nand_default_bbt (struct mtd_info *mtd)
this->bbt_md = &bbt_mirror_descr; this->bbt_md = &bbt_mirror_descr;
} }
if (!this->badblock_pattern) { if (!this->badblock_pattern) {
this->badblock_pattern = (mtd->oobblock > 512) ? this->badblock_pattern = (mtd->oobblock > 512) ? &largepage_flashbased : &smallpage_flashbased;
&largepage_flashbased : &smallpage_flashbased;
} }
} else { } else {
this->bbt_td = NULL; this->bbt_td = NULL;
...@@ -1077,7 +1073,7 @@ int nand_default_bbt (struct mtd_info *mtd) ...@@ -1077,7 +1073,7 @@ int nand_default_bbt (struct mtd_info *mtd)
&largepage_memorybased : &smallpage_memorybased; &largepage_memorybased : &smallpage_memorybased;
} }
} }
return nand_scan_bbt (mtd, this->badblock_pattern); return nand_scan_bbt(mtd, this->badblock_pattern);
} }
/** /**
...@@ -1087,26 +1083,29 @@ int nand_default_bbt (struct mtd_info *mtd) ...@@ -1087,26 +1083,29 @@ int nand_default_bbt (struct mtd_info *mtd)
* @allowbbt: allow access to bad block table region * @allowbbt: allow access to bad block table region
* *
*/ */
int nand_isbad_bbt (struct mtd_info *mtd, loff_t offs, int allowbbt) int nand_isbad_bbt(struct mtd_info *mtd, loff_t offs, int allowbbt)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
int block; int block;
uint8_t res; uint8_t res;
/* Get block number * 2 */ /* Get block number * 2 */
block = (int) (offs >> (this->bbt_erase_shift - 1)); block = (int)(offs >> (this->bbt_erase_shift - 1));
res = (this->bbt[block >> 3] >> (block & 0x06)) & 0x03; res = (this->bbt[block >> 3] >> (block & 0x06)) & 0x03;
DEBUG (MTD_DEBUG_LEVEL2, "nand_isbad_bbt(): bbt info for offs 0x%08x: (block %d) 0x%02x\n", DEBUG(MTD_DEBUG_LEVEL2, "nand_isbad_bbt(): bbt info for offs 0x%08x: (block %d) 0x%02x\n",
(unsigned int)offs, block >> 1, res); (unsigned int)offs, block >> 1, res);
switch ((int)res) { switch ((int)res) {
case 0x00: return 0; case 0x00:
case 0x01: return 1; return 0;
case 0x02: return allowbbt ? 0 : 1; case 0x01:
return 1;
case 0x02:
return allowbbt ? 0 : 1;
} }
return 1; return 1;
} }
EXPORT_SYMBOL (nand_scan_bbt); EXPORT_SYMBOL(nand_scan_bbt);
EXPORT_SYMBOL (nand_default_bbt); EXPORT_SYMBOL(nand_default_bbt);
...@@ -62,7 +62,6 @@ static const u_char nand_ecc_precalc_table[] = { ...@@ -62,7 +62,6 @@ static const u_char nand_ecc_precalc_table[] = {
0x00, 0x55, 0x56, 0x03, 0x59, 0x0c, 0x0f, 0x5a, 0x5a, 0x0f, 0x0c, 0x59, 0x03, 0x56, 0x55, 0x00 0x00, 0x55, 0x56, 0x03, 0x59, 0x0c, 0x0f, 0x5a, 0x5a, 0x0f, 0x0c, 0x59, 0x03, 0x56, 0x55, 0x00
}; };
/** /**
* nand_trans_result - [GENERIC] create non-inverted ECC * nand_trans_result - [GENERIC] create non-inverted ECC
* @reg2: line parity reg 2 * @reg2: line parity reg 2
...@@ -71,8 +70,7 @@ static const u_char nand_ecc_precalc_table[] = { ...@@ -71,8 +70,7 @@ static const u_char nand_ecc_precalc_table[] = {
* *
* Creates non-inverted ECC code from line parity * Creates non-inverted ECC code from line parity
*/ */
static void nand_trans_result(u_char reg2, u_char reg3, static void nand_trans_result(u_char reg2, u_char reg3, u_char *ecc_code)
u_char *ecc_code)
{ {
u_char a, b, i, tmp1, tmp2; u_char a, b, i, tmp1, tmp2;
...@@ -124,7 +122,7 @@ int nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code ...@@ -124,7 +122,7 @@ int nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code
ecc_code[0] = ecc_code[1] = ecc_code[2] = 0; ecc_code[0] = ecc_code[1] = ecc_code[2] = 0;
/* Build up column parity */ /* Build up column parity */
for(j = 0; j < 256; j++) { for (j = 0; j < 256; j++) {
/* Get CP0 - CP5 from table */ /* Get CP0 - CP5 from table */
idx = nand_ecc_precalc_table[dat[j]]; idx = nand_ecc_precalc_table[dat[j]];
...@@ -168,8 +166,7 @@ int nand_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_ecc, u_cha ...@@ -168,8 +166,7 @@ int nand_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_ecc, u_cha
if ((d1 | d2 | d3) == 0) { if ((d1 | d2 | d3) == 0) {
/* No errors */ /* No errors */
return 0; return 0;
} } else {
else {
a = (d1 ^ (d1 >> 1)) & 0x55; a = (d1 ^ (d1 >> 1)) & 0x55;
b = (d2 ^ (d2 >> 1)) & 0x55; b = (d2 ^ (d2 >> 1)) & 0x55;
c = (d3 ^ (d3 >> 1)) & 0x54; c = (d3 ^ (d3 >> 1)) & 0x54;
...@@ -179,14 +176,14 @@ int nand_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_ecc, u_cha ...@@ -179,14 +176,14 @@ int nand_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_ecc, u_cha
c = 0x80; c = 0x80;
add = 0; add = 0;
a = 0x80; a = 0x80;
for (i=0; i<4; i++) { for (i = 0; i < 4; i++) {
if (d1 & c) if (d1 & c)
add |= a; add |= a;
c >>= 2; c >>= 2;
a >>= 1; a >>= 1;
} }
c = 0x80; c = 0x80;
for (i=0; i<4; i++) { for (i = 0; i < 4; i++) {
if (d2 & c) if (d2 & c)
add |= a; add |= a;
c >>= 2; c >>= 2;
...@@ -195,7 +192,7 @@ int nand_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_ecc, u_cha ...@@ -195,7 +192,7 @@ int nand_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_ecc, u_cha
bit = 0; bit = 0;
b = 0x04; b = 0x04;
c = 0x80; c = 0x80;
for (i=0; i<3; i++) { for (i = 0; i < 3; i++) {
if (d3 & c) if (d3 & c)
bit |= b; bit |= b;
c >>= 2; c >>= 2;
...@@ -206,8 +203,7 @@ int nand_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_ecc, u_cha ...@@ -206,8 +203,7 @@ int nand_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_ecc, u_cha
a ^= (b << bit); a ^= (b << bit);
dat[add] = a; dat[add] = a;
return 1; return 1;
} } else {
else {
i = 0; i = 0;
while (d1) { while (d1) {
if (d1 & 0x01) if (d1 & 0x01)
...@@ -230,8 +226,7 @@ int nand_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_ecc, u_cha ...@@ -230,8 +226,7 @@ int nand_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_ecc, u_cha
read_ecc[1] = calc_ecc[1]; read_ecc[1] = calc_ecc[1];
read_ecc[2] = calc_ecc[2]; read_ecc[2] = calc_ecc[2];
return 2; return 2;
} } else {
else {
/* Uncorrectable Error */ /* Uncorrectable Error */
return -1; return -1;
} }
......
...@@ -129,9 +129,9 @@ struct nand_manufacturers nand_manuf_ids[] = { ...@@ -129,9 +129,9 @@ struct nand_manufacturers nand_manuf_ids[] = {
{0x0, "Unknown"} {0x0, "Unknown"}
}; };
EXPORT_SYMBOL (nand_manuf_ids); EXPORT_SYMBOL(nand_manuf_ids);
EXPORT_SYMBOL (nand_flash_ids); EXPORT_SYMBOL(nand_flash_ids);
MODULE_LICENSE ("GPL"); MODULE_LICENSE("GPL");
MODULE_AUTHOR ("Thomas Gleixner <tglx@linutronix.de>"); MODULE_AUTHOR("Thomas Gleixner <tglx@linutronix.de>");
MODULE_DESCRIPTION ("Nand device & manufacturer ID's"); MODULE_DESCRIPTION("Nand device & manufacturer IDs");
...@@ -71,8 +71,8 @@ static unsigned long ppchameleonevb_fio_pbase = CFG_NAND1_PADDR; ...@@ -71,8 +71,8 @@ static unsigned long ppchameleonevb_fio_pbase = CFG_NAND1_PADDR;
module_param(ppchameleon_fio_pbase, ulong, 0); module_param(ppchameleon_fio_pbase, ulong, 0);
module_param(ppchameleonevb_fio_pbase, ulong, 0); module_param(ppchameleonevb_fio_pbase, ulong, 0);
#else #else
__setup("ppchameleon_fio_pbase=",ppchameleon_fio_pbase); __setup("ppchameleon_fio_pbase=", ppchameleon_fio_pbase);
__setup("ppchameleonevb_fio_pbase=",ppchameleonevb_fio_pbase); __setup("ppchameleonevb_fio_pbase=", ppchameleonevb_fio_pbase);
#endif #endif
#ifdef CONFIG_MTD_PARTITIONS #ifdef CONFIG_MTD_PARTITIONS
...@@ -80,37 +80,37 @@ __setup("ppchameleonevb_fio_pbase=",ppchameleonevb_fio_pbase); ...@@ -80,37 +80,37 @@ __setup("ppchameleonevb_fio_pbase=",ppchameleonevb_fio_pbase);
* Define static partitions for flash devices * Define static partitions for flash devices
*/ */
static struct mtd_partition partition_info_hi[] = { static struct mtd_partition partition_info_hi[] = {
{ name: "PPChameleon HI Nand Flash", { .name = "PPChameleon HI Nand Flash",
offset: 0, offset = 0,
size: 128*1024*1024 } .size = 128 * 1024 * 1024
}
}; };
static struct mtd_partition partition_info_me[] = { static struct mtd_partition partition_info_me[] = {
{ name: "PPChameleon ME Nand Flash", { .name = "PPChameleon ME Nand Flash",
offset: 0, .offset = 0,
size: 32*1024*1024 } .size = 32 * 1024 * 1024
}
}; };
static struct mtd_partition partition_info_evb[] = { static struct mtd_partition partition_info_evb[] = {
{ name: "PPChameleonEVB Nand Flash", { .name = "PPChameleonEVB Nand Flash",
offset: 0, .offset = 0,
size: 32*1024*1024 } .size = 32 * 1024 * 1024
}
}; };
#define NUM_PARTITIONS 1 #define NUM_PARTITIONS 1
extern int parse_cmdline_partitions(struct mtd_info *master, extern int parse_cmdline_partitions(struct mtd_info *master, struct mtd_partition **pparts, const char *mtd_id);
struct mtd_partition **pparts,
const char *mtd_id);
#endif #endif
/* /*
* hardware specific access to control-lines * hardware specific access to control-lines
*/ */
static void ppchameleon_hwcontrol(struct mtd_info *mtdinfo, int cmd) static void ppchameleon_hwcontrol(struct mtd_info *mtdinfo, int cmd)
{ {
switch(cmd) { switch (cmd) {
case NAND_CTL_SETCLE: case NAND_CTL_SETCLE:
MACRO_NAND_CTL_SETCLE((unsigned long)CFG_NAND0_PADDR); MACRO_NAND_CTL_SETCLE((unsigned long)CFG_NAND0_PADDR);
...@@ -135,7 +135,7 @@ static void ppchameleon_hwcontrol(struct mtd_info *mtdinfo, int cmd) ...@@ -135,7 +135,7 @@ static void ppchameleon_hwcontrol(struct mtd_info *mtdinfo, int cmd)
static void ppchameleonevb_hwcontrol(struct mtd_info *mtdinfo, int cmd) static void ppchameleonevb_hwcontrol(struct mtd_info *mtdinfo, int cmd)
{ {
switch(cmd) { switch (cmd) {
case NAND_CTL_SETCLE: case NAND_CTL_SETCLE:
MACRO_NAND_CTL_SETCLE((unsigned long)CFG_NAND1_PADDR); MACRO_NAND_CTL_SETCLE((unsigned long)CFG_NAND1_PADDR);
...@@ -164,14 +164,14 @@ static void ppchameleonevb_hwcontrol(struct mtd_info *mtdinfo, int cmd) ...@@ -164,14 +164,14 @@ static void ppchameleonevb_hwcontrol(struct mtd_info *mtdinfo, int cmd)
*/ */
static int ppchameleon_device_ready(struct mtd_info *minfo) static int ppchameleon_device_ready(struct mtd_info *minfo)
{ {
if (in_be32((volatile unsigned*)GPIO0_IR) & NAND_RB_GPIO_PIN) if (in_be32((volatile unsigned *)GPIO0_IR) & NAND_RB_GPIO_PIN)
return 1; return 1;
return 0; return 0;
} }
static int ppchameleonevb_device_ready(struct mtd_info *minfo) static int ppchameleonevb_device_ready(struct mtd_info *minfo)
{ {
if (in_be32((volatile unsigned*)GPIO0_IR) & NAND_EVB_RB_GPIO_PIN) if (in_be32((volatile unsigned *)GPIO0_IR) & NAND_EVB_RB_GPIO_PIN)
return 1; return 1;
return 0; return 0;
} }
...@@ -185,7 +185,7 @@ const char *part_probes_evb[] = { "cmdlinepart", NULL }; ...@@ -185,7 +185,7 @@ const char *part_probes_evb[] = { "cmdlinepart", NULL };
/* /*
* Main initialization routine * Main initialization routine
*/ */
static int __init ppchameleonevb_init (void) static int __init ppchameleonevb_init(void)
{ {
struct nand_chip *this; struct nand_chip *this;
const char *part_type = 0; const char *part_type = 0;
...@@ -194,13 +194,11 @@ static int __init ppchameleonevb_init (void) ...@@ -194,13 +194,11 @@ static int __init ppchameleonevb_init (void)
void __iomem *ppchameleon_fio_base; void __iomem *ppchameleon_fio_base;
void __iomem *ppchameleonevb_fio_base; void __iomem *ppchameleonevb_fio_base;
/********************************* /*********************************
* Processor module NAND (if any) * * Processor module NAND (if any) *
*********************************/ *********************************/
/* Allocate memory for MTD device structure and private data */ /* Allocate memory for MTD device structure and private data */
ppchameleon_mtd = kmalloc(sizeof(struct mtd_info) + ppchameleon_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
sizeof(struct nand_chip), GFP_KERNEL);
if (!ppchameleon_mtd) { if (!ppchameleon_mtd) {
printk("Unable to allocate PPChameleon NAND MTD device structure.\n"); printk("Unable to allocate PPChameleon NAND MTD device structure.\n");
return -ENOMEM; return -ENOMEM;
...@@ -208,18 +206,18 @@ static int __init ppchameleonevb_init (void) ...@@ -208,18 +206,18 @@ static int __init ppchameleonevb_init (void)
/* map physical address */ /* map physical address */
ppchameleon_fio_base = ioremap(ppchameleon_fio_pbase, SZ_4M); ppchameleon_fio_base = ioremap(ppchameleon_fio_pbase, SZ_4M);
if(!ppchameleon_fio_base) { if (!ppchameleon_fio_base) {
printk("ioremap PPChameleon NAND flash failed\n"); printk("ioremap PPChameleon NAND flash failed\n");
kfree(ppchameleon_mtd); kfree(ppchameleon_mtd);
return -EIO; return -EIO;
} }
/* Get pointer to private data */ /* Get pointer to private data */
this = (struct nand_chip *) (&ppchameleon_mtd[1]); this = (struct nand_chip *)(&ppchameleon_mtd[1]);
/* Initialize structures */ /* Initialize structures */
memset((char *) ppchameleon_mtd, 0, sizeof(struct mtd_info)); memset(ppchameleon_mtd, 0, sizeof(struct mtd_info));
memset((char *) this, 0, sizeof(struct nand_chip)); memset(this, 0, sizeof(struct nand_chip));
/* Link the private data with the MTD structure */ /* Link the private data with the MTD structure */
ppchameleon_mtd->priv = this; ppchameleon_mtd->priv = this;
...@@ -233,18 +231,20 @@ static int __init ppchameleonevb_init (void) ...@@ -233,18 +231,20 @@ static int __init ppchameleonevb_init (void)
R/B GPIO_04 R/B GPIO_04
*/ */
/* output select */ /* output select */
out_be32((volatile unsigned*)GPIO0_OSRH, in_be32((volatile unsigned*)GPIO0_OSRH) & 0xC0FFFFFF); out_be32((volatile unsigned *)GPIO0_OSRH, in_be32((volatile unsigned *)GPIO0_OSRH) & 0xC0FFFFFF);
/* three-state select */ /* three-state select */
out_be32((volatile unsigned*)GPIO0_TSRH, in_be32((volatile unsigned*)GPIO0_TSRH) & 0xC0FFFFFF); out_be32((volatile unsigned *)GPIO0_TSRH, in_be32((volatile unsigned *)GPIO0_TSRH) & 0xC0FFFFFF);
/* enable output driver */ /* enable output driver */
out_be32((volatile unsigned*)GPIO0_TCR, in_be32((volatile unsigned*)GPIO0_TCR) | NAND_nCE_GPIO_PIN | NAND_CLE_GPIO_PIN | NAND_ALE_GPIO_PIN); out_be32((volatile unsigned *)GPIO0_TCR,
in_be32((volatile unsigned *)GPIO0_TCR) | NAND_nCE_GPIO_PIN | NAND_CLE_GPIO_PIN | NAND_ALE_GPIO_PIN);
#ifdef USE_READY_BUSY_PIN #ifdef USE_READY_BUSY_PIN
/* three-state select */ /* three-state select */
out_be32((volatile unsigned*)GPIO0_TSRH, in_be32((volatile unsigned*)GPIO0_TSRH) & 0xFF3FFFFF); out_be32((volatile unsigned *)GPIO0_TSRH, in_be32((volatile unsigned *)GPIO0_TSRH) & 0xFF3FFFFF);
/* high-impedecence */ /* high-impedecence */
out_be32((volatile unsigned*)GPIO0_TCR, in_be32((volatile unsigned*)GPIO0_TCR) & (~NAND_RB_GPIO_PIN)); out_be32((volatile unsigned *)GPIO0_TCR, in_be32((volatile unsigned *)GPIO0_TCR) & (~NAND_RB_GPIO_PIN));
/* input select */ /* input select */
out_be32((volatile unsigned*)GPIO0_ISR1H, (in_be32((volatile unsigned*)GPIO0_ISR1H) & 0xFF3FFFFF) | 0x00400000); out_be32((volatile unsigned *)GPIO0_ISR1H,
(in_be32((volatile unsigned *)GPIO0_ISR1H) & 0xFF3FFFFF) | 0x00400000);
#endif #endif
/* insert callbacks */ /* insert callbacks */
...@@ -259,12 +259,11 @@ static int __init ppchameleonevb_init (void) ...@@ -259,12 +259,11 @@ static int __init ppchameleonevb_init (void)
this->eccmode = NAND_ECC_SOFT; this->eccmode = NAND_ECC_SOFT;
/* Scan to find existence of the device (it could not be mounted) */ /* Scan to find existence of the device (it could not be mounted) */
if (nand_scan (ppchameleon_mtd, 1)) { if (nand_scan(ppchameleon_mtd, 1)) {
iounmap((void *)ppchameleon_fio_base); iounmap((void *)ppchameleon_fio_base);
kfree (ppchameleon_mtd); kfree(ppchameleon_mtd);
goto nand_evb_init; goto nand_evb_init;
} }
#ifndef USE_READY_BUSY_PIN #ifndef USE_READY_BUSY_PIN
/* Adjust delay if necessary */ /* Adjust delay if necessary */
if (ppchameleon_mtd->size == NAND_SMALL_SIZE) if (ppchameleon_mtd->size == NAND_SMALL_SIZE)
...@@ -279,8 +278,7 @@ static int __init ppchameleonevb_init (void) ...@@ -279,8 +278,7 @@ static int __init ppchameleonevb_init (void)
else else
mtd_parts_nb = 0; mtd_parts_nb = 0;
#endif #endif
if (mtd_parts_nb == 0) if (mtd_parts_nb == 0) {
{
if (ppchameleon_mtd->size == NAND_SMALL_SIZE) if (ppchameleon_mtd->size == NAND_SMALL_SIZE)
mtd_parts = partition_info_me; mtd_parts = partition_info_me;
else else
...@@ -293,13 +291,12 @@ static int __init ppchameleonevb_init (void) ...@@ -293,13 +291,12 @@ static int __init ppchameleonevb_init (void)
printk(KERN_NOTICE "Using %s partition definition\n", part_type); printk(KERN_NOTICE "Using %s partition definition\n", part_type);
add_mtd_partitions(ppchameleon_mtd, mtd_parts, mtd_parts_nb); add_mtd_partitions(ppchameleon_mtd, mtd_parts, mtd_parts_nb);
nand_evb_init: nand_evb_init:
/**************************** /****************************
* EVB NAND (always present) * * EVB NAND (always present) *
****************************/ ****************************/
/* Allocate memory for MTD device structure and private data */ /* Allocate memory for MTD device structure and private data */
ppchameleonevb_mtd = kmalloc(sizeof(struct mtd_info) + ppchameleonevb_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
sizeof(struct nand_chip), GFP_KERNEL);
if (!ppchameleonevb_mtd) { if (!ppchameleonevb_mtd) {
printk("Unable to allocate PPChameleonEVB NAND MTD device structure.\n"); printk("Unable to allocate PPChameleonEVB NAND MTD device structure.\n");
return -ENOMEM; return -ENOMEM;
...@@ -307,18 +304,18 @@ static int __init ppchameleonevb_init (void) ...@@ -307,18 +304,18 @@ static int __init ppchameleonevb_init (void)
/* map physical address */ /* map physical address */
ppchameleonevb_fio_base = ioremap(ppchameleonevb_fio_pbase, SZ_4M); ppchameleonevb_fio_base = ioremap(ppchameleonevb_fio_pbase, SZ_4M);
if(!ppchameleonevb_fio_base) { if (!ppchameleonevb_fio_base) {
printk("ioremap PPChameleonEVB NAND flash failed\n"); printk("ioremap PPChameleonEVB NAND flash failed\n");
kfree(ppchameleonevb_mtd); kfree(ppchameleonevb_mtd);
return -EIO; return -EIO;
} }
/* Get pointer to private data */ /* Get pointer to private data */
this = (struct nand_chip *) (&ppchameleonevb_mtd[1]); this = (struct nand_chip *)(&ppchameleonevb_mtd[1]);
/* Initialize structures */ /* Initialize structures */
memset((char *) ppchameleonevb_mtd, 0, sizeof(struct mtd_info)); memset(ppchameleonevb_mtd, 0, sizeof(struct mtd_info));
memset((char *) this, 0, sizeof(struct nand_chip)); memset(this, 0, sizeof(struct nand_chip));
/* Link the private data with the MTD structure */ /* Link the private data with the MTD structure */
ppchameleonevb_mtd->priv = this; ppchameleonevb_mtd->priv = this;
...@@ -332,21 +329,22 @@ static int __init ppchameleonevb_init (void) ...@@ -332,21 +329,22 @@ static int __init ppchameleonevb_init (void)
R/B GPIO_31 R/B GPIO_31
*/ */
/* output select */ /* output select */
out_be32((volatile unsigned*)GPIO0_OSRH, in_be32((volatile unsigned*)GPIO0_OSRH) & 0xFFFFFFF0); out_be32((volatile unsigned *)GPIO0_OSRH, in_be32((volatile unsigned *)GPIO0_OSRH) & 0xFFFFFFF0);
out_be32((volatile unsigned*)GPIO0_OSRL, in_be32((volatile unsigned*)GPIO0_OSRL) & 0x3FFFFFFF); out_be32((volatile unsigned *)GPIO0_OSRL, in_be32((volatile unsigned *)GPIO0_OSRL) & 0x3FFFFFFF);
/* three-state select */ /* three-state select */
out_be32((volatile unsigned*)GPIO0_TSRH, in_be32((volatile unsigned*)GPIO0_TSRH) & 0xFFFFFFF0); out_be32((volatile unsigned *)GPIO0_TSRH, in_be32((volatile unsigned *)GPIO0_TSRH) & 0xFFFFFFF0);
out_be32((volatile unsigned*)GPIO0_TSRL, in_be32((volatile unsigned*)GPIO0_TSRL) & 0x3FFFFFFF); out_be32((volatile unsigned *)GPIO0_TSRL, in_be32((volatile unsigned *)GPIO0_TSRL) & 0x3FFFFFFF);
/* enable output driver */ /* enable output driver */
out_be32((volatile unsigned*)GPIO0_TCR, in_be32((volatile unsigned*)GPIO0_TCR) | NAND_EVB_nCE_GPIO_PIN | out_be32((volatile unsigned *)GPIO0_TCR, in_be32((volatile unsigned *)GPIO0_TCR) | NAND_EVB_nCE_GPIO_PIN |
NAND_EVB_CLE_GPIO_PIN | NAND_EVB_ALE_GPIO_PIN); NAND_EVB_CLE_GPIO_PIN | NAND_EVB_ALE_GPIO_PIN);
#ifdef USE_READY_BUSY_PIN #ifdef USE_READY_BUSY_PIN
/* three-state select */ /* three-state select */
out_be32((volatile unsigned*)GPIO0_TSRL, in_be32((volatile unsigned*)GPIO0_TSRL) & 0xFFFFFFFC); out_be32((volatile unsigned *)GPIO0_TSRL, in_be32((volatile unsigned *)GPIO0_TSRL) & 0xFFFFFFFC);
/* high-impedecence */ /* high-impedecence */
out_be32((volatile unsigned*)GPIO0_TCR, in_be32((volatile unsigned*)GPIO0_TCR) & (~NAND_EVB_RB_GPIO_PIN)); out_be32((volatile unsigned *)GPIO0_TCR, in_be32((volatile unsigned *)GPIO0_TCR) & (~NAND_EVB_RB_GPIO_PIN));
/* input select */ /* input select */
out_be32((volatile unsigned*)GPIO0_ISR1L, (in_be32((volatile unsigned*)GPIO0_ISR1L) & 0xFFFFFFFC) | 0x00000001); out_be32((volatile unsigned *)GPIO0_ISR1L,
(in_be32((volatile unsigned *)GPIO0_ISR1L) & 0xFFFFFFFC) | 0x00000001);
#endif #endif
/* insert callbacks */ /* insert callbacks */
...@@ -362,12 +360,11 @@ static int __init ppchameleonevb_init (void) ...@@ -362,12 +360,11 @@ static int __init ppchameleonevb_init (void)
this->eccmode = NAND_ECC_SOFT; this->eccmode = NAND_ECC_SOFT;
/* Scan to find existence of the device */ /* Scan to find existence of the device */
if (nand_scan (ppchameleonevb_mtd, 1)) { if (nand_scan(ppchameleonevb_mtd, 1)) {
iounmap((void *)ppchameleonevb_fio_base); iounmap((void *)ppchameleonevb_fio_base);
kfree (ppchameleonevb_mtd); kfree(ppchameleonevb_mtd);
return -ENXIO; return -ENXIO;
} }
#ifdef CONFIG_MTD_PARTITIONS #ifdef CONFIG_MTD_PARTITIONS
ppchameleonevb_mtd->name = NAND_EVB_MTD_NAME; ppchameleonevb_mtd->name = NAND_EVB_MTD_NAME;
mtd_parts_nb = parse_mtd_partitions(ppchameleonevb_mtd, part_probes_evb, &mtd_parts, 0); mtd_parts_nb = parse_mtd_partitions(ppchameleonevb_mtd, part_probes_evb, &mtd_parts, 0);
...@@ -376,8 +373,7 @@ static int __init ppchameleonevb_init (void) ...@@ -376,8 +373,7 @@ static int __init ppchameleonevb_init (void)
else else
mtd_parts_nb = 0; mtd_parts_nb = 0;
#endif #endif
if (mtd_parts_nb == 0) if (mtd_parts_nb == 0) {
{
mtd_parts = partition_info_evb; mtd_parts = partition_info_evb;
mtd_parts_nb = NUM_PARTITIONS; mtd_parts_nb = NUM_PARTITIONS;
part_type = "static"; part_type = "static";
...@@ -390,18 +386,19 @@ static int __init ppchameleonevb_init (void) ...@@ -390,18 +386,19 @@ static int __init ppchameleonevb_init (void)
/* Return happy */ /* Return happy */
return 0; return 0;
} }
module_init(ppchameleonevb_init); module_init(ppchameleonevb_init);
/* /*
* Clean up routine * Clean up routine
*/ */
static void __exit ppchameleonevb_cleanup (void) static void __exit ppchameleonevb_cleanup(void)
{ {
struct nand_chip *this; struct nand_chip *this;
/* Release resources, unregister device(s) */ /* Release resources, unregister device(s) */
nand_release (ppchameleon_mtd); nand_release(ppchameleon_mtd);
nand_release (ppchameleonevb_mtd); nand_release(ppchameleonevb_mtd);
/* Release iomaps */ /* Release iomaps */
this = (struct nand_chip *) &ppchameleon_mtd[1]; this = (struct nand_chip *) &ppchameleon_mtd[1];
......
...@@ -100,9 +100,9 @@ static const struct mtd_partition partition_info[] = { ...@@ -100,9 +100,9 @@ static const struct mtd_partition partition_info[] = {
{ {
.name = "Renesas flash partition 1", .name = "Renesas flash partition 1",
.offset = 0, .offset = 0,
.size = MTDPART_SIZ_FULL .size = MTDPART_SIZ_FULL},
},
}; };
#define NUM_PARTITIONS 1 #define NUM_PARTITIONS 1
/* /*
...@@ -111,8 +111,8 @@ static const struct mtd_partition partition_info[] = { ...@@ -111,8 +111,8 @@ static const struct mtd_partition partition_info[] = {
* NAND_BBT_CREATE and/or NAND_BBT_WRITE * NAND_BBT_CREATE and/or NAND_BBT_WRITE
* *
*/ */
static uint8_t bbt_pattern[] = {'B', 'b', 't', '0' }; static uint8_t bbt_pattern[] = { 'B', 'b', 't', '0' };
static uint8_t mirror_pattern[] = {'1', 't', 'b', 'B' }; static uint8_t mirror_pattern[] = { '1', 't', 'b', 'B' };
static struct nand_bbt_descr rtc_from4_bbt_main_descr = { static struct nand_bbt_descr rtc_from4_bbt_main_descr = {
.options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE
...@@ -134,8 +134,6 @@ static struct nand_bbt_descr rtc_from4_bbt_mirror_descr = { ...@@ -134,8 +134,6 @@ static struct nand_bbt_descr rtc_from4_bbt_mirror_descr = {
.pattern = mirror_pattern .pattern = mirror_pattern
}; };
#ifdef RTC_FROM4_HWECC #ifdef RTC_FROM4_HWECC
/* the Reed Solomon control structure */ /* the Reed Solomon control structure */
...@@ -152,7 +150,7 @@ static struct nand_oobinfo rtc_from4_nand_oobinfo = { ...@@ -152,7 +150,7 @@ static struct nand_oobinfo rtc_from4_nand_oobinfo = {
8, 9, 10, 11, 12, 13, 14, 15, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31}, 24, 25, 26, 27, 28, 29, 30, 31},
.oobfree = { {32, 32} } .oobfree = {{32, 32}}
}; };
/* Aargh. I missed the reversed bit order, when I /* Aargh. I missed the reversed bit order, when I
...@@ -198,8 +196,6 @@ static uint8_t revbits[256] = { ...@@ -198,8 +196,6 @@ static uint8_t revbits[256] = {
#endif #endif
/* /*
* rtc_from4_hwcontrol - hardware specific access to control-lines * rtc_from4_hwcontrol - hardware specific access to control-lines
* @mtd: MTD device structure * @mtd: MTD device structure
...@@ -214,9 +210,9 @@ static uint8_t revbits[256] = { ...@@ -214,9 +210,9 @@ static uint8_t revbits[256] = {
*/ */
static void rtc_from4_hwcontrol(struct mtd_info *mtd, int cmd) static void rtc_from4_hwcontrol(struct mtd_info *mtd, int cmd)
{ {
struct nand_chip* this = (struct nand_chip *) (mtd->priv); struct nand_chip *this = (struct nand_chip *)(mtd->priv);
switch(cmd) { switch (cmd) {
case NAND_CTL_SETCLE: case NAND_CTL_SETCLE:
this->IO_ADDR_W = (void __iomem *)((unsigned long)this->IO_ADDR_W | RTC_FROM4_CLE); this->IO_ADDR_W = (void __iomem *)((unsigned long)this->IO_ADDR_W | RTC_FROM4_CLE);
...@@ -240,7 +236,6 @@ static void rtc_from4_hwcontrol(struct mtd_info *mtd, int cmd) ...@@ -240,7 +236,6 @@ static void rtc_from4_hwcontrol(struct mtd_info *mtd, int cmd)
} }
} }
/* /*
* rtc_from4_nand_select_chip - hardware specific chip select * rtc_from4_nand_select_chip - hardware specific chip select
* @mtd: MTD device structure * @mtd: MTD device structure
...@@ -257,7 +252,7 @@ static void rtc_from4_nand_select_chip(struct mtd_info *mtd, int chip) ...@@ -257,7 +252,7 @@ static void rtc_from4_nand_select_chip(struct mtd_info *mtd, int chip)
this->IO_ADDR_R = (void __iomem *)((unsigned long)this->IO_ADDR_R & ~RTC_FROM4_NAND_ADDR_MASK); this->IO_ADDR_R = (void __iomem *)((unsigned long)this->IO_ADDR_R & ~RTC_FROM4_NAND_ADDR_MASK);
this->IO_ADDR_W = (void __iomem *)((unsigned long)this->IO_ADDR_W & ~RTC_FROM4_NAND_ADDR_MASK); this->IO_ADDR_W = (void __iomem *)((unsigned long)this->IO_ADDR_W & ~RTC_FROM4_NAND_ADDR_MASK);
switch(chip) { switch (chip) {
case 0: /* select slot 3 chip */ case 0: /* select slot 3 chip */
this->IO_ADDR_R = (void __iomem *)((unsigned long)this->IO_ADDR_R | RTC_FROM4_NAND_ADDR_SLOT3); this->IO_ADDR_R = (void __iomem *)((unsigned long)this->IO_ADDR_R | RTC_FROM4_NAND_ADDR_SLOT3);
...@@ -271,7 +266,6 @@ static void rtc_from4_nand_select_chip(struct mtd_info *mtd, int chip) ...@@ -271,7 +266,6 @@ static void rtc_from4_nand_select_chip(struct mtd_info *mtd, int chip)
} }
} }
/* /*
* rtc_from4_nand_device_ready - hardware specific ready/busy check * rtc_from4_nand_device_ready - hardware specific ready/busy check
* @mtd: MTD device structure * @mtd: MTD device structure
...@@ -290,7 +284,6 @@ static int rtc_from4_nand_device_ready(struct mtd_info *mtd) ...@@ -290,7 +284,6 @@ static int rtc_from4_nand_device_ready(struct mtd_info *mtd)
} }
/* /*
* deplete - code to perform device recovery in case there was a power loss * deplete - code to perform device recovery in case there was a power loss
* @mtd: MTD device structure * @mtd: MTD device structure
...@@ -309,21 +302,20 @@ static void deplete(struct mtd_info *mtd, int chip) ...@@ -309,21 +302,20 @@ static void deplete(struct mtd_info *mtd, int chip)
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
/* wait until device is ready */ /* wait until device is ready */
while (!this->dev_ready(mtd)); while (!this->dev_ready(mtd)) ;
this->select_chip(mtd, chip); this->select_chip(mtd, chip);
/* Send the commands for device recovery, phase 1 */ /* Send the commands for device recovery, phase 1 */
this->cmdfunc (mtd, NAND_CMD_DEPLETE1, 0x0000, 0x0000); this->cmdfunc(mtd, NAND_CMD_DEPLETE1, 0x0000, 0x0000);
this->cmdfunc (mtd, NAND_CMD_DEPLETE2, -1, -1); this->cmdfunc(mtd, NAND_CMD_DEPLETE2, -1, -1);
/* Send the commands for device recovery, phase 2 */ /* Send the commands for device recovery, phase 2 */
this->cmdfunc (mtd, NAND_CMD_DEPLETE1, 0x0000, 0x0004); this->cmdfunc(mtd, NAND_CMD_DEPLETE1, 0x0000, 0x0004);
this->cmdfunc (mtd, NAND_CMD_DEPLETE2, -1, -1); this->cmdfunc(mtd, NAND_CMD_DEPLETE2, -1, -1);
} }
#ifdef RTC_FROM4_HWECC #ifdef RTC_FROM4_HWECC
/* /*
* rtc_from4_enable_hwecc - hardware specific hardware ECC enable function * rtc_from4_enable_hwecc - hardware specific hardware ECC enable function
...@@ -335,27 +327,24 @@ static void deplete(struct mtd_info *mtd, int chip) ...@@ -335,27 +327,24 @@ static void deplete(struct mtd_info *mtd, int chip)
*/ */
static void rtc_from4_enable_hwecc(struct mtd_info *mtd, int mode) static void rtc_from4_enable_hwecc(struct mtd_info *mtd, int mode)
{ {
volatile unsigned short * rs_ecc_ctl = (volatile unsigned short *)(rtc_from4_fio_base + RTC_FROM4_RS_ECC_CTL); volatile unsigned short *rs_ecc_ctl = (volatile unsigned short *)(rtc_from4_fio_base + RTC_FROM4_RS_ECC_CTL);
unsigned short status; unsigned short status;
switch (mode) { switch (mode) {
case NAND_ECC_READ : case NAND_ECC_READ:
status = RTC_FROM4_RS_ECC_CTL_CLR status = RTC_FROM4_RS_ECC_CTL_CLR | RTC_FROM4_RS_ECC_CTL_FD_E;
| RTC_FROM4_RS_ECC_CTL_FD_E;
*rs_ecc_ctl = status; *rs_ecc_ctl = status;
break; break;
case NAND_ECC_READSYN : case NAND_ECC_READSYN:
status = 0x00; status = 0x00;
*rs_ecc_ctl = status; *rs_ecc_ctl = status;
break; break;
case NAND_ECC_WRITE : case NAND_ECC_WRITE:
status = RTC_FROM4_RS_ECC_CTL_CLR status = RTC_FROM4_RS_ECC_CTL_CLR | RTC_FROM4_RS_ECC_CTL_GEN | RTC_FROM4_RS_ECC_CTL_FD_E;
| RTC_FROM4_RS_ECC_CTL_GEN
| RTC_FROM4_RS_ECC_CTL_FD_E;
*rs_ecc_ctl = status; *rs_ecc_ctl = status;
break; break;
...@@ -367,7 +356,6 @@ static void rtc_from4_enable_hwecc(struct mtd_info *mtd, int mode) ...@@ -367,7 +356,6 @@ static void rtc_from4_enable_hwecc(struct mtd_info *mtd, int mode)
} }
/* /*
* rtc_from4_calculate_ecc - hardware specific code to read ECC code * rtc_from4_calculate_ecc - hardware specific code to read ECC code
* @mtd: MTD device structure * @mtd: MTD device structure
...@@ -383,7 +371,7 @@ static void rtc_from4_enable_hwecc(struct mtd_info *mtd, int mode) ...@@ -383,7 +371,7 @@ static void rtc_from4_enable_hwecc(struct mtd_info *mtd, int mode)
*/ */
static void rtc_from4_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code) static void rtc_from4_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code)
{ {
volatile unsigned short * rs_eccn = (volatile unsigned short *)(rtc_from4_fio_base + RTC_FROM4_RS_ECCN); volatile unsigned short *rs_eccn = (volatile unsigned short *)(rtc_from4_fio_base + RTC_FROM4_RS_ECCN);
unsigned short value; unsigned short value;
int i; int i;
...@@ -395,7 +383,6 @@ static void rtc_from4_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_c ...@@ -395,7 +383,6 @@ static void rtc_from4_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_c
ecc_code[7] |= 0x0f; /* set the last four bits (not used) */ ecc_code[7] |= 0x0f; /* set the last four bits (not used) */
} }
/* /*
* rtc_from4_correct_data - hardware specific code to correct data using ECC code * rtc_from4_correct_data - hardware specific code to correct data using ECC code
* @mtd: MTD device structure * @mtd: MTD device structure
...@@ -430,17 +417,12 @@ static int rtc_from4_correct_data(struct mtd_info *mtd, const u_char *buf, u_cha ...@@ -430,17 +417,12 @@ static int rtc_from4_correct_data(struct mtd_info *mtd, const u_char *buf, u_cha
} }
/* convert into 6 10bit syndrome fields */ /* convert into 6 10bit syndrome fields */
par[5] = rs_decoder->index_of[(((uint16_t)ecc[0] >> 0) & 0x0ff) | par[5] = rs_decoder->index_of[(((uint16_t) ecc[0] >> 0) & 0x0ff) | (((uint16_t) ecc[1] << 8) & 0x300)];
(((uint16_t)ecc[1] << 8) & 0x300)]; par[4] = rs_decoder->index_of[(((uint16_t) ecc[1] >> 2) & 0x03f) | (((uint16_t) ecc[2] << 6) & 0x3c0)];
par[4] = rs_decoder->index_of[(((uint16_t)ecc[1] >> 2) & 0x03f) | par[3] = rs_decoder->index_of[(((uint16_t) ecc[2] >> 4) & 0x00f) | (((uint16_t) ecc[3] << 4) & 0x3f0)];
(((uint16_t)ecc[2] << 6) & 0x3c0)]; par[2] = rs_decoder->index_of[(((uint16_t) ecc[3] >> 6) & 0x003) | (((uint16_t) ecc[4] << 2) & 0x3fc)];
par[3] = rs_decoder->index_of[(((uint16_t)ecc[2] >> 4) & 0x00f) | par[1] = rs_decoder->index_of[(((uint16_t) ecc[5] >> 0) & 0x0ff) | (((uint16_t) ecc[6] << 8) & 0x300)];
(((uint16_t)ecc[3] << 4) & 0x3f0)]; par[0] = (((uint16_t) ecc[6] >> 2) & 0x03f) | (((uint16_t) ecc[7] << 6) & 0x3c0);
par[2] = rs_decoder->index_of[(((uint16_t)ecc[3] >> 6) & 0x003) |
(((uint16_t)ecc[4] << 2) & 0x3fc)];
par[1] = rs_decoder->index_of[(((uint16_t)ecc[5] >> 0) & 0x0ff) |
(((uint16_t)ecc[6] << 8) & 0x300)];
par[0] = (((uint16_t)ecc[6] >> 2) & 0x03f) | (((uint16_t)ecc[7] << 6) & 0x3c0);
/* Convert to computable syndrome */ /* Convert to computable syndrome */
for (i = 0; i < 6; i++) { for (i = 0; i < 6; i++) {
...@@ -453,16 +435,14 @@ static int rtc_from4_correct_data(struct mtd_info *mtd, const u_char *buf, u_cha ...@@ -453,16 +435,14 @@ static int rtc_from4_correct_data(struct mtd_info *mtd, const u_char *buf, u_cha
syn[i] = rs_decoder->index_of[syn[i]]; syn[i] = rs_decoder->index_of[syn[i]];
} }
/* Let the library code do its magic.*/ /* Let the library code do its magic. */
res = decode_rs8(rs_decoder, (uint8_t *)buf, par, 512, syn, 0, NULL, 0xff, NULL); res = decode_rs8(rs_decoder, (uint8_t *) buf, par, 512, syn, 0, NULL, 0xff, NULL);
if (res > 0) { if (res > 0) {
DEBUG (MTD_DEBUG_LEVEL0, "rtc_from4_correct_data: " DEBUG(MTD_DEBUG_LEVEL0, "rtc_from4_correct_data: " "ECC corrected %d errors on read\n", res);
"ECC corrected %d errors on read\n", res);
} }
return res; return res;
} }
/** /**
* rtc_from4_errstat - perform additional error status checks * rtc_from4_errstat - perform additional error status checks
* @mtd: MTD device structure * @mtd: MTD device structure
...@@ -480,44 +460,44 @@ static int rtc_from4_correct_data(struct mtd_info *mtd, const u_char *buf, u_cha ...@@ -480,44 +460,44 @@ static int rtc_from4_correct_data(struct mtd_info *mtd, const u_char *buf, u_cha
*/ */
static int rtc_from4_errstat(struct mtd_info *mtd, struct nand_chip *this, int state, int status, int page) static int rtc_from4_errstat(struct mtd_info *mtd, struct nand_chip *this, int state, int status, int page)
{ {
int er_stat=0; int er_stat = 0;
int rtn, retlen; int rtn, retlen;
size_t len; size_t len;
uint8_t *buf; uint8_t *buf;
int i; int i;
this->cmdfunc (mtd, NAND_CMD_STATUS_CLEAR, -1, -1); this->cmdfunc(mtd, NAND_CMD_STATUS_CLEAR, -1, -1);
if (state == FL_ERASING) { if (state == FL_ERASING) {
for (i=0; i<4; i++) { for (i = 0; i < 4; i++) {
if (status & 1<<(i+1)) { if (status & 1 << (i + 1)) {
this->cmdfunc (mtd, (NAND_CMD_STATUS_ERROR + i + 1), -1, -1); this->cmdfunc(mtd, (NAND_CMD_STATUS_ERROR + i + 1), -1, -1);
rtn = this->read_byte(mtd); rtn = this->read_byte(mtd);
this->cmdfunc (mtd, NAND_CMD_STATUS_RESET, -1, -1); this->cmdfunc(mtd, NAND_CMD_STATUS_RESET, -1, -1);
if (!(rtn & ERR_STAT_ECC_AVAILABLE)) { if (!(rtn & ERR_STAT_ECC_AVAILABLE)) {
er_stat |= 1<<(i+1); /* err_ecc_not_avail */ er_stat |= 1 << (i + 1); /* err_ecc_not_avail */
} }
} }
} }
} else if (state == FL_WRITING) { } else if (state == FL_WRITING) {
/* single bank write logic */ /* single bank write logic */
this->cmdfunc (mtd, NAND_CMD_STATUS_ERROR, -1, -1); this->cmdfunc(mtd, NAND_CMD_STATUS_ERROR, -1, -1);
rtn = this->read_byte(mtd); rtn = this->read_byte(mtd);
this->cmdfunc (mtd, NAND_CMD_STATUS_RESET, -1, -1); this->cmdfunc(mtd, NAND_CMD_STATUS_RESET, -1, -1);
if (!(rtn & ERR_STAT_ECC_AVAILABLE)) { if (!(rtn & ERR_STAT_ECC_AVAILABLE)) {
er_stat |= 1<<1; /* err_ecc_not_avail */ er_stat |= 1 << 1; /* err_ecc_not_avail */
} else { } else {
len = mtd->oobblock; len = mtd->oobblock;
buf = kmalloc (len, GFP_KERNEL); buf = kmalloc(len, GFP_KERNEL);
if (!buf) { if (!buf) {
printk (KERN_ERR "rtc_from4_errstat: Out of memory!\n"); printk(KERN_ERR "rtc_from4_errstat: Out of memory!\n");
er_stat = 1; /* if we can't check, assume failed */ er_stat = 1; /* if we can't check, assume failed */
} else { } else {
/* recovery read */ /* recovery read */
/* page read */ /* page read */
rtn = nand_do_read_ecc (mtd, page, len, &retlen, buf, NULL, this->autooob, 1); rtn = nand_do_read_ecc(mtd, page, len, &retlen, buf, NULL, this->autooob, 1);
if (rtn) { /* if read failed or > 1-bit error corrected */ if (rtn) { /* if read failed or > 1-bit error corrected */
er_stat |= 1<<1; /* ECC read failed */ er_stat |= 1 << 1; /* ECC read failed */
} }
kfree(buf); kfree(buf);
} }
...@@ -533,30 +513,28 @@ static int rtc_from4_errstat(struct mtd_info *mtd, struct nand_chip *this, int s ...@@ -533,30 +513,28 @@ static int rtc_from4_errstat(struct mtd_info *mtd, struct nand_chip *this, int s
} }
#endif #endif
/* /*
* Main initialization routine * Main initialization routine
*/ */
int __init rtc_from4_init (void) int __init rtc_from4_init(void)
{ {
struct nand_chip *this; struct nand_chip *this;
unsigned short bcr1, bcr2, wcr2; unsigned short bcr1, bcr2, wcr2;
int i; int i;
/* Allocate memory for MTD device structure and private data */ /* Allocate memory for MTD device structure and private data */
rtc_from4_mtd = kmalloc(sizeof(struct mtd_info) + sizeof (struct nand_chip), rtc_from4_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
GFP_KERNEL);
if (!rtc_from4_mtd) { if (!rtc_from4_mtd) {
printk ("Unable to allocate Renesas NAND MTD device structure.\n"); printk("Unable to allocate Renesas NAND MTD device structure.\n");
return -ENOMEM; return -ENOMEM;
} }
/* Get pointer to private data */ /* Get pointer to private data */
this = (struct nand_chip *) (&rtc_from4_mtd[1]); this = (struct nand_chip *)(&rtc_from4_mtd[1]);
/* Initialize structures */ /* Initialize structures */
memset((char *) rtc_from4_mtd, 0, sizeof(struct mtd_info)); memset(rtc_from4_mtd, 0, sizeof(struct mtd_info));
memset((char *) this, 0, sizeof(struct nand_chip)); memset(this, 0, sizeof(struct nand_chip));
/* Link the private data with the MTD structure */ /* Link the private data with the MTD structure */
rtc_from4_mtd->priv = this; rtc_from4_mtd->priv = this;
...@@ -617,7 +595,7 @@ int __init rtc_from4_init (void) ...@@ -617,7 +595,7 @@ int __init rtc_from4_init (void)
} }
/* Perform 'device recovery' for each chip in case there was a power loss. */ /* Perform 'device recovery' for each chip in case there was a power loss. */
for (i=0; i < this->numchips; i++) { for (i = 0; i < this->numchips; i++) {
deplete(rtc_from4_mtd, i); deplete(rtc_from4_mtd, i);
} }
...@@ -643,7 +621,7 @@ int __init rtc_from4_init (void) ...@@ -643,7 +621,7 @@ int __init rtc_from4_init (void)
*/ */
rs_decoder = init_rs(10, 0x409, 0, 1, 6); rs_decoder = init_rs(10, 0x409, 0, 1, 6);
if (!rs_decoder) { if (!rs_decoder) {
printk (KERN_ERR "Could not create a RS decoder\n"); printk(KERN_ERR "Could not create a RS decoder\n");
nand_release(rtc_from4_mtd); nand_release(rtc_from4_mtd);
kfree(rtc_from4_mtd); kfree(rtc_from4_mtd);
return -ENOMEM; return -ENOMEM;
...@@ -652,20 +630,20 @@ int __init rtc_from4_init (void) ...@@ -652,20 +630,20 @@ int __init rtc_from4_init (void)
/* Return happy */ /* Return happy */
return 0; return 0;
} }
module_init(rtc_from4_init);
module_init(rtc_from4_init);
/* /*
* Clean up routine * Clean up routine
*/ */
#ifdef MODULE #ifdef MODULE
static void __exit rtc_from4_cleanup (void) static void __exit rtc_from4_cleanup(void)
{ {
/* Release resource, unregister partitions */ /* Release resource, unregister partitions */
nand_release(rtc_from4_mtd); nand_release(rtc_from4_mtd);
/* Free the MTD device structure */ /* Free the MTD device structure */
kfree (rtc_from4_mtd); kfree(rtc_from4_mtd);
#ifdef RTC_FROM4_HWECC #ifdef RTC_FROM4_HWECC
/* Free the reed solomon resources */ /* Free the reed solomon resources */
...@@ -674,10 +652,10 @@ static void __exit rtc_from4_cleanup (void) ...@@ -674,10 +652,10 @@ static void __exit rtc_from4_cleanup (void)
} }
#endif #endif
} }
module_exit(rtc_from4_cleanup); module_exit(rtc_from4_cleanup);
#endif #endif
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
MODULE_AUTHOR("d.marlin <dmarlin@redhat.com"); MODULE_AUTHOR("d.marlin <dmarlin@redhat.com");
MODULE_DESCRIPTION("Board-specific glue layer for AG-AND flash on Renesas FROM_BOARD4"); MODULE_DESCRIPTION("Board-specific glue layer for AG-AND flash on Renesas FROM_BOARD4");
...@@ -79,8 +79,8 @@ static int hardware_ecc = 0; ...@@ -79,8 +79,8 @@ static int hardware_ecc = 0;
static struct nand_oobinfo nand_hw_eccoob = { static struct nand_oobinfo nand_hw_eccoob = {
.useecc = MTD_NANDECC_AUTOPLACE, .useecc = MTD_NANDECC_AUTOPLACE,
.eccbytes = 3, .eccbytes = 3,
.eccpos = {0, 1, 2 }, .eccpos = {0, 1, 2},
.oobfree = { {8, 8} } .oobfree = {{8, 8}}
}; };
/* controller and mtd information */ /* controller and mtd information */
...@@ -149,8 +149,7 @@ static int s3c2410_nand_calc_rate(int wanted, unsigned long clk, int max) ...@@ -149,8 +149,7 @@ static int s3c2410_nand_calc_rate(int wanted, unsigned long clk, int max)
pr_debug("result %d from %ld, %d\n", result, clk, wanted); pr_debug("result %d from %ld, %d\n", result, clk, wanted);
if (result > max) { if (result > max) {
printk("%d ns is too big for current clock rate %ld\n", printk("%d ns is too big for current clock rate %ld\n", wanted, clk);
wanted, clk);
return -1; return -1;
} }
...@@ -164,8 +163,7 @@ static int s3c2410_nand_calc_rate(int wanted, unsigned long clk, int max) ...@@ -164,8 +163,7 @@ static int s3c2410_nand_calc_rate(int wanted, unsigned long clk, int max)
/* controller setup */ /* controller setup */
static int s3c2410_nand_inithw(struct s3c2410_nand_info *info, static int s3c2410_nand_inithw(struct s3c2410_nand_info *info, struct platform_device *pdev)
struct platform_device *pdev)
{ {
struct s3c2410_platform_nand *plat = to_nand_plat(pdev); struct s3c2410_platform_nand *plat = to_nand_plat(pdev);
unsigned long clkrate = clk_get_rate(info->clk); unsigned long clkrate = clk_get_rate(info->clk);
...@@ -193,19 +191,17 @@ static int s3c2410_nand_inithw(struct s3c2410_nand_info *info, ...@@ -193,19 +191,17 @@ static int s3c2410_nand_inithw(struct s3c2410_nand_info *info,
} }
printk(KERN_INFO PFX "Tacls=%d, %dns Twrph0=%d %dns, Twrph1=%d %dns\n", printk(KERN_INFO PFX "Tacls=%d, %dns Twrph0=%d %dns, Twrph1=%d %dns\n",
tacls, to_ns(tacls, clkrate), tacls, to_ns(tacls, clkrate), twrph0, to_ns(twrph0, clkrate), twrph1, to_ns(twrph1, clkrate));
twrph0, to_ns(twrph0, clkrate),
twrph1, to_ns(twrph1, clkrate));
if (!info->is_s3c2440) { if (!info->is_s3c2440) {
cfg = S3C2410_NFCONF_EN; cfg = S3C2410_NFCONF_EN;
cfg |= S3C2410_NFCONF_TACLS(tacls-1); cfg |= S3C2410_NFCONF_TACLS(tacls - 1);
cfg |= S3C2410_NFCONF_TWRPH0(twrph0-1); cfg |= S3C2410_NFCONF_TWRPH0(twrph0 - 1);
cfg |= S3C2410_NFCONF_TWRPH1(twrph1-1); cfg |= S3C2410_NFCONF_TWRPH1(twrph1 - 1);
} else { } else {
cfg = S3C2440_NFCONF_TACLS(tacls-1); cfg = S3C2440_NFCONF_TACLS(tacls - 1);
cfg |= S3C2440_NFCONF_TWRPH0(twrph0-1); cfg |= S3C2440_NFCONF_TWRPH0(twrph0 - 1);
cfg |= S3C2440_NFCONF_TWRPH1(twrph1-1); cfg |= S3C2440_NFCONF_TWRPH1(twrph1 - 1);
} }
pr_debug(PFX "NF_CONF is 0x%lx\n", cfg); pr_debug(PFX "NF_CONF is 0x%lx\n", cfg);
...@@ -229,7 +225,7 @@ static void s3c2410_nand_select_chip(struct mtd_info *mtd, int chip) ...@@ -229,7 +225,7 @@ static void s3c2410_nand_select_chip(struct mtd_info *mtd, int chip)
info = nmtd->info; info = nmtd->info;
bit = (info->is_s3c2440) ? S3C2440_NFCONT_nFCE : S3C2410_NFCONF_nFCE; bit = (info->is_s3c2440) ? S3C2440_NFCONT_nFCE : S3C2410_NFCONF_nFCE;
reg = info->regs+((info->is_s3c2440) ? S3C2440_NFCONT:S3C2410_NFCONF); reg = info->regs + ((info->is_s3c2440) ? S3C2440_NFCONT : S3C2410_NFCONF);
cur = readl(reg); cur = readl(reg);
...@@ -243,7 +239,7 @@ static void s3c2410_nand_select_chip(struct mtd_info *mtd, int chip) ...@@ -243,7 +239,7 @@ static void s3c2410_nand_select_chip(struct mtd_info *mtd, int chip)
if (info->platform != NULL) { if (info->platform != NULL) {
if (info->platform->select_chip != NULL) if (info->platform->select_chip != NULL)
(info->platform->select_chip)(nmtd->set, chip); (info->platform->select_chip) (nmtd->set, chip);
} }
cur &= ~bit; cur &= ~bit;
...@@ -330,22 +326,16 @@ static int s3c2410_nand_devready(struct mtd_info *mtd) ...@@ -330,22 +326,16 @@ static int s3c2410_nand_devready(struct mtd_info *mtd)
return readb(info->regs + S3C2410_NFSTAT) & S3C2410_NFSTAT_BUSY; return readb(info->regs + S3C2410_NFSTAT) & S3C2410_NFSTAT_BUSY;
} }
/* ECC handling functions */ /* ECC handling functions */
static int s3c2410_nand_correct_data(struct mtd_info *mtd, u_char *dat, static int s3c2410_nand_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_ecc, u_char *calc_ecc)
u_char *read_ecc, u_char *calc_ecc)
{ {
pr_debug("s3c2410_nand_correct_data(%p,%p,%p,%p)\n", pr_debug("s3c2410_nand_correct_data(%p,%p,%p,%p)\n", mtd, dat, read_ecc, calc_ecc);
mtd, dat, read_ecc, calc_ecc);
pr_debug("eccs: read %02x,%02x,%02x vs calc %02x,%02x,%02x\n", pr_debug("eccs: read %02x,%02x,%02x vs calc %02x,%02x,%02x\n",
read_ecc[0], read_ecc[1], read_ecc[2], read_ecc[0], read_ecc[1], read_ecc[2], calc_ecc[0], calc_ecc[1], calc_ecc[2]);
calc_ecc[0], calc_ecc[1], calc_ecc[2]);
if (read_ecc[0] == calc_ecc[0] && if (read_ecc[0] == calc_ecc[0] && read_ecc[1] == calc_ecc[1] && read_ecc[2] == calc_ecc[2])
read_ecc[1] == calc_ecc[1] &&
read_ecc[2] == calc_ecc[2])
return 0; return 0;
/* we curently have no method for correcting the error */ /* we curently have no method for correcting the error */
...@@ -378,8 +368,7 @@ static void s3c2440_nand_enable_hwecc(struct mtd_info *mtd, int mode) ...@@ -378,8 +368,7 @@ static void s3c2440_nand_enable_hwecc(struct mtd_info *mtd, int mode)
writel(ctrl | S3C2440_NFCONT_INITECC, info->regs + S3C2440_NFCONT); writel(ctrl | S3C2440_NFCONT_INITECC, info->regs + S3C2440_NFCONT);
} }
static int s3c2410_nand_calculate_ecc(struct mtd_info *mtd, static int s3c2410_nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code)
const u_char *dat, u_char *ecc_code)
{ {
struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd); struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
...@@ -387,15 +376,12 @@ static int s3c2410_nand_calculate_ecc(struct mtd_info *mtd, ...@@ -387,15 +376,12 @@ static int s3c2410_nand_calculate_ecc(struct mtd_info *mtd,
ecc_code[1] = readb(info->regs + S3C2410_NFECC + 1); ecc_code[1] = readb(info->regs + S3C2410_NFECC + 1);
ecc_code[2] = readb(info->regs + S3C2410_NFECC + 2); ecc_code[2] = readb(info->regs + S3C2410_NFECC + 2);
pr_debug("calculate_ecc: returning ecc %02x,%02x,%02x\n", pr_debug("calculate_ecc: returning ecc %02x,%02x,%02x\n", ecc_code[0], ecc_code[1], ecc_code[2]);
ecc_code[0], ecc_code[1], ecc_code[2]);
return 0; return 0;
} }
static int s3c2440_nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code)
static int s3c2440_nand_calculate_ecc(struct mtd_info *mtd,
const u_char *dat, u_char *ecc_code)
{ {
struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd); struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
unsigned long ecc = readl(info->regs + S3C2440_NFMECC0); unsigned long ecc = readl(info->regs + S3C2440_NFMECC0);
...@@ -404,13 +390,11 @@ static int s3c2440_nand_calculate_ecc(struct mtd_info *mtd, ...@@ -404,13 +390,11 @@ static int s3c2440_nand_calculate_ecc(struct mtd_info *mtd,
ecc_code[1] = ecc >> 8; ecc_code[1] = ecc >> 8;
ecc_code[2] = ecc >> 16; ecc_code[2] = ecc >> 16;
pr_debug("calculate_ecc: returning ecc %02x,%02x,%02x\n", pr_debug("calculate_ecc: returning ecc %02x,%02x,%02x\n", ecc_code[0], ecc_code[1], ecc_code[2]);
ecc_code[0], ecc_code[1], ecc_code[2]);
return 0; return 0;
} }
/* over-ride the standard functions for a little more speed. We can /* over-ride the standard functions for a little more speed. We can
* use read/write block to move the data buffers to/from the controller * use read/write block to move the data buffers to/from the controller
*/ */
...@@ -421,8 +405,7 @@ static void s3c2410_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len) ...@@ -421,8 +405,7 @@ static void s3c2410_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
readsb(this->IO_ADDR_R, buf, len); readsb(this->IO_ADDR_R, buf, len);
} }
static void s3c2410_nand_write_buf(struct mtd_info *mtd, static void s3c2410_nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
const u_char *buf, int len)
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
writesb(this->IO_ADDR_W, buf, len); writesb(this->IO_ADDR_W, buf, len);
...@@ -488,9 +471,7 @@ static int s3c2410_nand_add_partition(struct s3c2410_nand_info *info, ...@@ -488,9 +471,7 @@ static int s3c2410_nand_add_partition(struct s3c2410_nand_info *info,
return add_mtd_device(&mtd->mtd); return add_mtd_device(&mtd->mtd);
if (set->nr_partitions > 0 && set->partitions != NULL) { if (set->nr_partitions > 0 && set->partitions != NULL) {
return add_mtd_partitions(&mtd->mtd, return add_mtd_partitions(&mtd->mtd, set->partitions, set->nr_partitions);
set->partitions,
set->nr_partitions);
} }
return add_mtd_device(&mtd->mtd); return add_mtd_device(&mtd->mtd);
...@@ -654,13 +635,11 @@ static int s3c24xx_nand_probe(struct platform_device *pdev, int is_s3c2440) ...@@ -654,13 +635,11 @@ static int s3c24xx_nand_probe(struct platform_device *pdev, int is_s3c2440)
nmtd = info->mtds; nmtd = info->mtds;
for (setno = 0; setno < nr_sets; setno++, nmtd++) { for (setno = 0; setno < nr_sets; setno++, nmtd++) {
pr_debug("initialising set %d (%p, info %p)\n", pr_debug("initialising set %d (%p, info %p)\n", setno, nmtd, info);
setno, nmtd, info);
s3c2410_nand_init_chip(info, nmtd, sets); s3c2410_nand_init_chip(info, nmtd, sets);
nmtd->scan_res = nand_scan(&nmtd->mtd, nmtd->scan_res = nand_scan(&nmtd->mtd, (sets) ? sets->nr_chips : 1);
(sets) ? sets->nr_chips : 1);
if (nmtd->scan_res == 0) { if (nmtd->scan_res == 0) {
s3c2410_nand_add_partition(info, nmtd, sets); s3c2410_nand_add_partition(info, nmtd, sets);
......
...@@ -46,7 +46,6 @@ static int sharpsl_phys_base = 0x0C000000; ...@@ -46,7 +46,6 @@ static int sharpsl_phys_base = 0x0C000000;
#define FLCLE (1 << 1) #define FLCLE (1 << 1)
#define FLCE0 (1 << 0) #define FLCE0 (1 << 0)
/* /*
* MTD structure for SharpSL * MTD structure for SharpSL
*/ */
...@@ -71,16 +70,15 @@ static struct mtd_partition sharpsl_nand_default_partition_info[] = { ...@@ -71,16 +70,15 @@ static struct mtd_partition sharpsl_nand_default_partition_info[] = {
}, },
{ {
.name = "Home Filesystem", .name = "Home Filesystem",
.offset = MTDPART_OFS_APPEND , .offset = MTDPART_OFS_APPEND,
.size = MTDPART_SIZ_FULL , .size = MTDPART_SIZ_FULL,
}, },
}; };
/* /*
* hardware specific access to control-lines * hardware specific access to control-lines
*/ */
static void static void sharpsl_nand_hwcontrol(struct mtd_info *mtd, int cmd)
sharpsl_nand_hwcontrol(struct mtd_info* mtd, int cmd)
{ {
switch (cmd) { switch (cmd) {
case NAND_CTL_SETCLE: case NAND_CTL_SETCLE:
...@@ -98,10 +96,10 @@ sharpsl_nand_hwcontrol(struct mtd_info* mtd, int cmd) ...@@ -98,10 +96,10 @@ sharpsl_nand_hwcontrol(struct mtd_info* mtd, int cmd)
break; break;
case NAND_CTL_SETNCE: case NAND_CTL_SETNCE:
writeb(readb(FLASHCTL) & ~(FLCE0|FLCE1), FLASHCTL); writeb(readb(FLASHCTL) & ~(FLCE0 | FLCE1), FLASHCTL);
break; break;
case NAND_CTL_CLRNCE: case NAND_CTL_CLRNCE:
writeb(readb(FLASHCTL) | (FLCE0|FLCE1), FLASHCTL); writeb(readb(FLASHCTL) | (FLCE0 | FLCE1), FLASHCTL);
break; break;
} }
} }
...@@ -129,24 +127,20 @@ static struct nand_oobinfo akita_oobinfo = { ...@@ -129,24 +127,20 @@ static struct nand_oobinfo akita_oobinfo = {
0x5, 0x1, 0x2, 0x3, 0x6, 0x7, 0x15, 0x11, 0x5, 0x1, 0x2, 0x3, 0x6, 0x7, 0x15, 0x11,
0x12, 0x13, 0x16, 0x17, 0x25, 0x21, 0x22, 0x23, 0x12, 0x13, 0x16, 0x17, 0x25, 0x21, 0x22, 0x23,
0x26, 0x27, 0x35, 0x31, 0x32, 0x33, 0x36, 0x37}, 0x26, 0x27, 0x35, 0x31, 0x32, 0x33, 0x36, 0x37},
.oobfree = { {0x08, 0x09} } .oobfree = {{0x08, 0x09}}
}; };
static int static int sharpsl_nand_dev_ready(struct mtd_info *mtd)
sharpsl_nand_dev_ready(struct mtd_info* mtd)
{ {
return !((readb(FLASHCTL) & FLRYBY) == 0); return !((readb(FLASHCTL) & FLRYBY) == 0);
} }
static void static void sharpsl_nand_enable_hwecc(struct mtd_info *mtd, int mode)
sharpsl_nand_enable_hwecc(struct mtd_info* mtd, int mode)
{ {
writeb(0 ,ECCCLRR); writeb(0, ECCCLRR);
} }
static int static int sharpsl_nand_calculate_ecc(struct mtd_info *mtd, const u_char * dat, u_char * ecc_code)
sharpsl_nand_calculate_ecc(struct mtd_info* mtd, const u_char* dat,
u_char* ecc_code)
{ {
ecc_code[0] = ~readb(ECCLPUB); ecc_code[0] = ~readb(ECCLPUB);
ecc_code[1] = ~readb(ECCLPLB); ecc_code[1] = ~readb(ECCLPLB);
...@@ -154,44 +148,40 @@ sharpsl_nand_calculate_ecc(struct mtd_info* mtd, const u_char* dat, ...@@ -154,44 +148,40 @@ sharpsl_nand_calculate_ecc(struct mtd_info* mtd, const u_char* dat,
return readb(ECCCNTR) != 0; return readb(ECCCNTR) != 0;
} }
#ifdef CONFIG_MTD_PARTITIONS #ifdef CONFIG_MTD_PARTITIONS
const char *part_probes[] = { "cmdlinepart", NULL }; const char *part_probes[] = { "cmdlinepart", NULL };
#endif #endif
/* /*
* Main initialization routine * Main initialization routine
*/ */
int __init int __init sharpsl_nand_init(void)
sharpsl_nand_init(void)
{ {
struct nand_chip *this; struct nand_chip *this;
struct mtd_partition* sharpsl_partition_info; struct mtd_partition *sharpsl_partition_info;
int err = 0; int err = 0;
/* Allocate memory for MTD device structure and private data */ /* Allocate memory for MTD device structure and private data */
sharpsl_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), sharpsl_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
GFP_KERNEL);
if (!sharpsl_mtd) { if (!sharpsl_mtd) {
printk ("Unable to allocate SharpSL NAND MTD device structure.\n"); printk("Unable to allocate SharpSL NAND MTD device structure.\n");
return -ENOMEM; return -ENOMEM;
} }
/* map physical adress */ /* map physical adress */
sharpsl_io_base = ioremap(sharpsl_phys_base, 0x1000); sharpsl_io_base = ioremap(sharpsl_phys_base, 0x1000);
if(!sharpsl_io_base){ if (!sharpsl_io_base) {
printk("ioremap to access Sharp SL NAND chip failed\n"); printk("ioremap to access Sharp SL NAND chip failed\n");
kfree(sharpsl_mtd); kfree(sharpsl_mtd);
return -EIO; return -EIO;
} }
/* Get pointer to private data */ /* Get pointer to private data */
this = (struct nand_chip *) (&sharpsl_mtd[1]); this = (struct nand_chip *)(&sharpsl_mtd[1]);
/* Initialize structures */ /* Initialize structures */
memset((char *) sharpsl_mtd, 0, sizeof(struct mtd_info)); memset(sharpsl_mtd, 0, sizeof(struct mtd_info));
memset((char *) this, 0, sizeof(struct nand_chip)); memset(this, 0, sizeof(struct nand_chip));
/* Link the private data with the MTD structure */ /* Link the private data with the MTD structure */
sharpsl_mtd->priv = this; sharpsl_mtd->priv = this;
...@@ -221,7 +211,7 @@ sharpsl_nand_init(void) ...@@ -221,7 +211,7 @@ sharpsl_nand_init(void)
this->correct_data = nand_correct_data; this->correct_data = nand_correct_data;
/* Scan to find existence of the device */ /* Scan to find existence of the device */
err=nand_scan(sharpsl_mtd,1); err = nand_scan(sharpsl_mtd, 1);
if (err) { if (err) {
iounmap(sharpsl_io_base); iounmap(sharpsl_io_base);
kfree(sharpsl_mtd); kfree(sharpsl_mtd);
...@@ -230,24 +220,23 @@ sharpsl_nand_init(void) ...@@ -230,24 +220,23 @@ sharpsl_nand_init(void)
/* Register the partitions */ /* Register the partitions */
sharpsl_mtd->name = "sharpsl-nand"; sharpsl_mtd->name = "sharpsl-nand";
nr_partitions = parse_mtd_partitions(sharpsl_mtd, part_probes, nr_partitions = parse_mtd_partitions(sharpsl_mtd, part_probes, &sharpsl_partition_info, 0);
&sharpsl_partition_info, 0);
if (nr_partitions <= 0) { if (nr_partitions <= 0) {
nr_partitions = DEFAULT_NUM_PARTITIONS; nr_partitions = DEFAULT_NUM_PARTITIONS;
sharpsl_partition_info = sharpsl_nand_default_partition_info; sharpsl_partition_info = sharpsl_nand_default_partition_info;
if (machine_is_poodle()) { if (machine_is_poodle()) {
sharpsl_partition_info[1].size=22 * 1024 * 1024; sharpsl_partition_info[1].size = 22 * 1024 * 1024;
} else if (machine_is_corgi() || machine_is_shepherd()) { } else if (machine_is_corgi() || machine_is_shepherd()) {
sharpsl_partition_info[1].size=25 * 1024 * 1024; sharpsl_partition_info[1].size = 25 * 1024 * 1024;
} else if (machine_is_husky()) { } else if (machine_is_husky()) {
sharpsl_partition_info[1].size=53 * 1024 * 1024; sharpsl_partition_info[1].size = 53 * 1024 * 1024;
} else if (machine_is_spitz()) { } else if (machine_is_spitz()) {
sharpsl_partition_info[1].size=5 * 1024 * 1024; sharpsl_partition_info[1].size = 5 * 1024 * 1024;
} else if (machine_is_akita()) { } else if (machine_is_akita()) {
sharpsl_partition_info[1].size=58 * 1024 * 1024; sharpsl_partition_info[1].size = 58 * 1024 * 1024;
} else if (machine_is_borzoi()) { } else if (machine_is_borzoi()) {
sharpsl_partition_info[1].size=32 * 1024 * 1024; sharpsl_partition_info[1].size = 32 * 1024 * 1024;
} }
} }
...@@ -261,6 +250,7 @@ sharpsl_nand_init(void) ...@@ -261,6 +250,7 @@ sharpsl_nand_init(void)
/* Return happy */ /* Return happy */
return 0; return 0;
} }
module_init(sharpsl_nand_init); module_init(sharpsl_nand_init);
/* /*
...@@ -269,7 +259,7 @@ module_init(sharpsl_nand_init); ...@@ -269,7 +259,7 @@ module_init(sharpsl_nand_init);
#ifdef MODULE #ifdef MODULE
static void __exit sharpsl_nand_cleanup(void) static void __exit sharpsl_nand_cleanup(void)
{ {
struct nand_chip *this = (struct nand_chip *) &sharpsl_mtd[1]; struct nand_chip *this = (struct nand_chip *)&sharpsl_mtd[1];
/* Release resources, unregister device */ /* Release resources, unregister device */
nand_release(sharpsl_mtd); nand_release(sharpsl_mtd);
...@@ -279,6 +269,7 @@ static void __exit sharpsl_nand_cleanup(void) ...@@ -279,6 +269,7 @@ static void __exit sharpsl_nand_cleanup(void)
/* Free the MTD device structure */ /* Free the MTD device structure */
kfree(sharpsl_mtd); kfree(sharpsl_mtd);
} }
module_exit(sharpsl_nand_cleanup); module_exit(sharpsl_nand_cleanup);
#endif #endif
......
...@@ -71,23 +71,21 @@ static const struct mtd_partition partition_info[] = { ...@@ -71,23 +71,21 @@ static const struct mtd_partition partition_info[] = {
{ {
.name = "SPIA flash partition 1", .name = "SPIA flash partition 1",
.offset = 0, .offset = 0,
.size = 2*1024*1024 .size = 2 * 1024 * 1024},
},
{ {
.name = "SPIA flash partition 2", .name = "SPIA flash partition 2",
.offset = 2*1024*1024, .offset = 2 * 1024 * 1024,
.size = 6*1024*1024 .size = 6 * 1024 * 1024}
}
}; };
#define NUM_PARTITIONS 2
#define NUM_PARTITIONS 2
/* /*
* hardware specific access to control-lines * hardware specific access to control-lines
*/ */
static void spia_hwcontrol(struct mtd_info *mtd, int cmd){ static void spia_hwcontrol(struct mtd_info *mtd, int cmd)
{
switch(cmd){ switch (cmd) {
case NAND_CTL_SETCLE: (*(volatile unsigned char *) (spia_io_base + spia_pedr)) |= 0x01; break; case NAND_CTL_SETCLE: (*(volatile unsigned char *) (spia_io_base + spia_pedr)) |= 0x01; break;
case NAND_CTL_CLRCLE: (*(volatile unsigned char *) (spia_io_base + spia_pedr)) &= ~0x01; break; case NAND_CTL_CLRCLE: (*(volatile unsigned char *) (spia_io_base + spia_pedr)) &= ~0x01; break;
...@@ -103,24 +101,23 @@ static void spia_hwcontrol(struct mtd_info *mtd, int cmd){ ...@@ -103,24 +101,23 @@ static void spia_hwcontrol(struct mtd_info *mtd, int cmd){
/* /*
* Main initialization routine * Main initialization routine
*/ */
int __init spia_init (void) int __init spia_init(void)
{ {
struct nand_chip *this; struct nand_chip *this;
/* Allocate memory for MTD device structure and private data */ /* Allocate memory for MTD device structure and private data */
spia_mtd = kmalloc (sizeof(struct mtd_info) + sizeof (struct nand_chip), spia_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
GFP_KERNEL);
if (!spia_mtd) { if (!spia_mtd) {
printk ("Unable to allocate SPIA NAND MTD device structure.\n"); printk("Unable to allocate SPIA NAND MTD device structure.\n");
return -ENOMEM; return -ENOMEM;
} }
/* Get pointer to private data */ /* Get pointer to private data */
this = (struct nand_chip *) (&spia_mtd[1]); this = (struct nand_chip *)(&spia_mtd[1]);
/* Initialize structures */ /* Initialize structures */
memset((char *) spia_mtd, 0, sizeof(struct mtd_info)); memset(spia_mtd, 0, sizeof(struct mtd_info));
memset((char *) this, 0, sizeof(struct nand_chip)); memset(this, 0, sizeof(struct nand_chip));
/* Link the private data with the MTD structure */ /* Link the private data with the MTD structure */
spia_mtd->priv = this; spia_mtd->priv = this;
...@@ -129,19 +126,19 @@ int __init spia_init (void) ...@@ -129,19 +126,19 @@ int __init spia_init (void)
* Set GPIO Port E control register so that the pins are configured * Set GPIO Port E control register so that the pins are configured
* to be outputs for controlling the NAND flash. * to be outputs for controlling the NAND flash.
*/ */
(*(volatile unsigned char *) (spia_io_base + spia_peddr)) = 0x07; (*(volatile unsigned char *)(spia_io_base + spia_peddr)) = 0x07;
/* Set address of NAND IO lines */ /* Set address of NAND IO lines */
this->IO_ADDR_R = (void __iomem *) spia_fio_base; this->IO_ADDR_R = (void __iomem *)spia_fio_base;
this->IO_ADDR_W = (void __iomem *) spia_fio_base; this->IO_ADDR_W = (void __iomem *)spia_fio_base;
/* Set address of hardware control function */ /* Set address of hardware control function */
this->hwcontrol = spia_hwcontrol; this->hwcontrol = spia_hwcontrol;
/* 15 us command delay time */ /* 15 us command delay time */
this->chip_delay = 15; this->chip_delay = 15;
/* Scan to find existence of the device */ /* Scan to find existence of the device */
if (nand_scan (spia_mtd, 1)) { if (nand_scan(spia_mtd, 1)) {
kfree (spia_mtd); kfree(spia_mtd);
return -ENXIO; return -ENXIO;
} }
...@@ -151,20 +148,22 @@ int __init spia_init (void) ...@@ -151,20 +148,22 @@ int __init spia_init (void)
/* Return happy */ /* Return happy */
return 0; return 0;
} }
module_init(spia_init); module_init(spia_init);
/* /*
* Clean up routine * Clean up routine
*/ */
#ifdef MODULE #ifdef MODULE
static void __exit spia_cleanup (void) static void __exit spia_cleanup(void)
{ {
/* Release resources, unregister device */ /* Release resources, unregister device */
nand_release (spia_mtd); nand_release(spia_mtd);
/* Free the MTD device structure */ /* Free the MTD device structure */
kfree (spia_mtd); kfree(spia_mtd);
} }
module_exit(spia_cleanup); module_exit(spia_cleanup);
#endif #endif
......
...@@ -99,8 +99,7 @@ static void toto_hwcontrol(struct mtd_info *mtd, int cmd) ...@@ -99,8 +99,7 @@ static void toto_hwcontrol(struct mtd_info *mtd, int cmd)
{ {
udelay(1); /* hopefully enough time for tc make proceding write to clear */ udelay(1); /* hopefully enough time for tc make proceding write to clear */
switch(cmd){ switch (cmd) {
case NAND_CTL_SETCLE: T_NAND_CTL_SETCLE(cmd); break; case NAND_CTL_SETCLE: T_NAND_CTL_SETCLE(cmd); break;
case NAND_CTL_CLRCLE: T_NAND_CTL_CLRCLE(cmd); break; case NAND_CTL_CLRCLE: T_NAND_CTL_CLRCLE(cmd); break;
...@@ -116,26 +115,25 @@ static void toto_hwcontrol(struct mtd_info *mtd, int cmd) ...@@ -116,26 +115,25 @@ static void toto_hwcontrol(struct mtd_info *mtd, int cmd)
/* /*
* Main initialization routine * Main initialization routine
*/ */
int __init toto_init (void) int __init toto_init(void)
{ {
struct nand_chip *this; struct nand_chip *this;
int err = 0; int err = 0;
/* Allocate memory for MTD device structure and private data */ /* Allocate memory for MTD device structure and private data */
toto_mtd = kmalloc (sizeof(struct mtd_info) + sizeof (struct nand_chip), toto_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
GFP_KERNEL);
if (!toto_mtd) { if (!toto_mtd) {
printk (KERN_WARNING "Unable to allocate toto NAND MTD device structure.\n"); printk(KERN_WARNING "Unable to allocate toto NAND MTD device structure.\n");
err = -ENOMEM; err = -ENOMEM;
goto out; goto out;
} }
/* Get pointer to private data */ /* Get pointer to private data */
this = (struct nand_chip *) (&toto_mtd[1]); this = (struct nand_chip *)(&toto_mtd[1]);
/* Initialize structures */ /* Initialize structures */
memset((char *) toto_mtd, 0, sizeof(struct mtd_info)); memset(toto_mtd, 0, sizeof(struct mtd_info));
memset((char *) this, 0, sizeof(struct nand_chip)); memset(this, 0, sizeof(struct nand_chip));
/* Link the private data with the MTD structure */ /* Link the private data with the MTD structure */
toto_mtd->priv = this; toto_mtd->priv = this;
...@@ -150,32 +148,36 @@ int __init toto_init (void) ...@@ -150,32 +148,36 @@ int __init toto_init (void)
this->eccmode = NAND_ECC_SOFT; this->eccmode = NAND_ECC_SOFT;
/* Scan to find existance of the device */ /* Scan to find existance of the device */
if (nand_scan (toto_mtd, 1)) { if (nand_scan(toto_mtd, 1)) {
err = -ENXIO; err = -ENXIO;
goto out_mtd; goto out_mtd;
} }
/* Register the partitions */ /* Register the partitions */
switch(toto_mtd->size){ switch (toto_mtd->size) {
case SZ_64M: add_mtd_partitions(toto_mtd, partition_info64M, NUM_PARTITIONS64M); break; case SZ_64M:
case SZ_32M: add_mtd_partitions(toto_mtd, partition_info32M, NUM_PARTITIONS32M); break; add_mtd_partitions(toto_mtd, partition_info64M, NUM_PARTITIONS64M);
default: { break;
printk (KERN_WARNING "Unsupported Nand device\n"); case SZ_32M:
add_mtd_partitions(toto_mtd, partition_info32M, NUM_PARTITIONS32M);
break;
default:{
printk(KERN_WARNING "Unsupported Nand device\n");
err = -ENXIO; err = -ENXIO;
goto out_buf; goto out_buf;
} }
} }
gpioreserve(NAND_MASK); /* claim our gpios */ gpioreserve(NAND_MASK); /* claim our gpios */
archflashwp(0,0); /* open up flash for writing */ archflashwp(0, 0); /* open up flash for writing */
goto out; goto out;
out_buf: out_buf:
kfree (this->data_buf); kfree(this->data_buf);
out_mtd: out_mtd:
kfree (toto_mtd); kfree(toto_mtd);
out: out:
return err; return err;
} }
...@@ -184,20 +186,21 @@ module_init(toto_init); ...@@ -184,20 +186,21 @@ module_init(toto_init);
/* /*
* Clean up routine * Clean up routine
*/ */
static void __exit toto_cleanup (void) static void __exit toto_cleanup(void)
{ {
/* Release resources, unregister device */ /* Release resources, unregister device */
nand_release (toto_mtd); nand_release(toto_mtd);
/* Free the MTD device structure */ /* Free the MTD device structure */
kfree (toto_mtd); kfree(toto_mtd);
/* stop flash writes */ /* stop flash writes */
archflashwp(0,1); archflashwp(0, 1);
/* release gpios to system */ /* release gpios to system */
gpiorelease(NAND_MASK); gpiorelease(NAND_MASK);
} }
module_exit(toto_cleanup); module_exit(toto_cleanup);
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
......
...@@ -88,7 +88,7 @@ static void ts7250_hwcontrol(struct mtd_info *mtd, int cmd) ...@@ -88,7 +88,7 @@ static void ts7250_hwcontrol(struct mtd_info *mtd, int cmd)
{ {
unsigned long ctrl = TS72XX_NAND_CONTROL_VIRT_BASE; unsigned long ctrl = TS72XX_NAND_CONTROL_VIRT_BASE;
switch(cmd) { switch (cmd) {
case NAND_CTL_SETCLE: case NAND_CTL_SETCLE:
__raw_writeb(__raw_readb(ctrl) | 0x2, ctrl); __raw_writeb(__raw_readb(ctrl) | 0x2, ctrl);
break; break;
...@@ -132,8 +132,7 @@ static int __init ts7250_init(void) ...@@ -132,8 +132,7 @@ static int __init ts7250_init(void)
return -ENXIO; return -ENXIO;
/* Allocate memory for MTD device structure and private data */ /* Allocate memory for MTD device structure and private data */
ts7250_mtd = kmalloc(sizeof(struct mtd_info) + ts7250_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
sizeof(struct nand_chip), GFP_KERNEL);
if (!ts7250_mtd) { if (!ts7250_mtd) {
printk("Unable to allocate TS7250 NAND MTD device structure.\n"); printk("Unable to allocate TS7250 NAND MTD device structure.\n");
return -ENOMEM; return -ENOMEM;
...@@ -163,11 +162,9 @@ static int __init ts7250_init(void) ...@@ -163,11 +162,9 @@ static int __init ts7250_init(void)
kfree(ts7250_mtd); kfree(ts7250_mtd);
return -ENXIO; return -ENXIO;
} }
#ifdef CONFIG_MTD_PARTITIONS #ifdef CONFIG_MTD_PARTITIONS
ts7250_mtd->name = "ts7250-nand"; ts7250_mtd->name = "ts7250-nand";
mtd_parts_nb = parse_mtd_partitions(ts7250_mtd, part_probes, mtd_parts_nb = parse_mtd_partitions(ts7250_mtd, part_probes, &mtd_parts, 0);
&mtd_parts, 0);
if (mtd_parts_nb > 0) if (mtd_parts_nb > 0)
part_type = "command line"; part_type = "command line";
else else
...@@ -188,6 +185,7 @@ static int __init ts7250_init(void) ...@@ -188,6 +185,7 @@ static int __init ts7250_init(void)
/* Return happy */ /* Return happy */
return 0; return 0;
} }
module_init(ts7250_init); module_init(ts7250_init);
/* /*
...@@ -201,6 +199,7 @@ static void __exit ts7250_cleanup(void) ...@@ -201,6 +199,7 @@ static void __exit ts7250_cleanup(void)
/* Free the MTD device structure */ /* Free the MTD device structure */
kfree(ts7250_mtd); kfree(ts7250_mtd);
} }
module_exit(ts7250_cleanup); module_exit(ts7250_cleanup);
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment