All of lore.kernel.org
 help / color / mirror / Atom feed
* Strange NAND scan problem
@ 2007-07-02 16:08 z l
  2007-07-03 22:14 ` David Woodhouse
  0 siblings, 1 reply; 3+ messages in thread
From: z l @ 2007-07-02 16:08 UTC (permalink / raw)
  To: linux-mtd

We have a custom board using Cirrus Logic EP93XX
processor.  The NAND flash data bus is connected to
the SRAM bus and using GPIO line for device control. 
If compiled with ARM native gcc-3.4 compiler,
everything works great.  But if compiled with ARM
native gcc-4.1 compiler, it works fine when there IS a
NAND flash chip.  But the nand_scan will report bogus
NAND chip when there IS NO NAND chip in the system and
proceed to scan the bad blocks which it finds plenty. 
First thought is that maybe the SRAM bus was in high Z
and it will read back what ever it was written to the
previous instruction.  But would versions of compiler
make a difference as what would be read back?

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

* Re: Strange NAND scan problem
  2007-07-02 16:08 Strange NAND scan problem z l
@ 2007-07-03 22:14 ` David Woodhouse
  2007-07-04 12:35   ` z l
  0 siblings, 1 reply; 3+ messages in thread
From: David Woodhouse @ 2007-07-03 22:14 UTC (permalink / raw)
  To: z l; +Cc: linux-mtd

On Mon, 2007-07-02 at 09:08 -0700, z l wrote:
> But would versions of compiler
> make a difference as what would be read back?

Probably only if your code (or hardware) is buggy. Show driver.

-- 
dwmw2

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

* Re: Strange NAND scan problem
  2007-07-03 22:14 ` David Woodhouse
@ 2007-07-04 12:35   ` z l
  0 siblings, 0 replies; 3+ messages in thread
From: z l @ 2007-07-04 12:35 UTC (permalink / raw)
  To: David Woodhouse; +Cc: linux-mtd

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


--- David Woodhouse <dwmw2@infradead.org> wrote:

> On Mon, 2007-07-02 at 09:08 -0700, z l wrote:
> > But would versions of compiler
> > make a difference as what would be read back?
> 
> Probably only if your code (or hardware) is buggy.
> Show driver.
> 
Driver attached

__________________________________________
> Linux MTD discussion mailing list
>
http://lists.infradead.org/mailman/listinfo/linux-mtd/
> 

[-- Attachment #2: 4220865168-gesbc.c --]
[-- Type: application/octet-stream, Size: 6063 bytes --]

/*
 *  drivers/mtd/nand/gesbc-9302.c
 *
 *  Copyright (C) 2004 Glomation (support@glomationinc.com)
 *
 *  Derived from drivers/mtd/nand/edb7312.c
 *       Copyright (C) 2004 Marius Grer (mag@sysgo.de)
 *
 *  Derived from drivers/mtd/nand/autcpu12.c
 *       Copyright (c) 2001 Thomas Gleixner (gleixner@autronix.de)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 *  Overview:
 *   This is a device driver for the NAND flash device found on the
 *   GESBC-93xx board with Samsung 128/256/512 Mbyte part.
 */

#include <linux/slab.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/nand.h>
#include <linux/mtd/partitions.h>
#include <asm/io.h>
#include <asm/arch/hardware.h>
#include <asm/sizes.h>

#define GESBC_NAND_FLASH_DATA 0x10000000

#define GPIO_PADR	EP93XX_GPIO_REG(0x0)
#define GPIO_PADDR	EP93XX_GPIO_REG(0x10)
#define SMCBCR1		(EP93XX_AHB_VIRT_BASE + 0x00082000 + 0x04)

/*
 * MTD structure for GESBC-93xx board
 */
static struct mtd_info *gesbc_mtd = NULL;


/*
 * Module stuff
 */
static unsigned long gesbc_fio_pbase = GESBC_NAND_FLASH_DATA;

#ifdef CONFIG_MTD_PARTITIONS
/*
 * Define static partitions for flash device
 */
static struct mtd_partition partition_info32[] = {
	{ .name= "GESBC NAND FLASH",
		  .offset= 0,
		  .size= 128*1024*1024 },
};
/*
 * Define static partitions for flash device
 */
static struct mtd_partition partition_info128[] = {
	{ .name= "GESBC NAND FLASH",
		  .offset= 0,
		  .size= 128*1024*1024 },
};

/*
 * Define static partitions for flash device
 */
static struct mtd_partition partition_info256[] = {
	{ .name= "GESBC NAND FLASH",
		  .offset= 0,
		  .size= 256*1024*1024 },
};

/*
 * Define static partitions for flash device
 */
static struct mtd_partition partition_info512[] = {
	{ .name= "GESBC NAND FLASH",
		  .offset= 0,
		  .size= 512*1024*1024 },
};

#define NUM_PARTITIONS 1
#endif


/* 
 *	hardware specific access to control-lines
 *      NAND_NCE: bit 0 -> bit 3
 *      NAND_CLE: bit 1 -> bit 4
 *      NAND_ALE: bit 2 -> bit 6
 */
static void gesbc_hwcontrol(struct mtd_info *mtd, int cmd, int ctrl) 
{
	unsigned long flags;
        struct nand_chip *chip = mtd->priv;

	/* Disbale interrupt to avoid race condition */
	local_irq_save(flags);

        if (ctrl & NAND_CTRL_CHANGE) {
                unsigned char bits;

                bits = (ctrl & NAND_CLE) << 3;
                bits |= (ctrl & NAND_ALE) << 4;
		if (ctrl & NAND_NCE)
			bits &= ~0x08;
		else
			bits |= 0x08;

		__raw_writel( (__raw_readl(GPIO_PADR) & ~0x58 )| bits, GPIO_PADR);
        }
        if (cmd != NAND_CMD_NONE)
                writeb(cmd, chip->IO_ADDR_W);
	/* Restore interrupt state */
	local_irq_restore(flags);
}

/*
 *	read device ready pin
 */
static int gesbc_device_ready(struct mtd_info *mtd)
{
	return  (__raw_readl(GPIO_PADR) & 0x80) >> 7;
}


/*
 * Main initialization routine
 */
static int __init gesbc_nand_init (void)
{
	struct nand_chip *this;
	const char *part_type = 0;
	int mtd_parts_nb = 0;
	struct mtd_partition *mtd_parts = 0;
	unsigned long flags;
	void * gesbc_fio_base;

	/* Allocate memory for MTD device structure and private data */
	gesbc_mtd = kmalloc(sizeof(struct mtd_info) + 
			     sizeof(struct nand_chip),
			     GFP_KERNEL);
	if (!gesbc_mtd) {
		printk("Unable to allocate GESBC NAND MTD device structure.\n");
		return -ENOMEM;
	}

	/* map physical adress */
	gesbc_fio_base = ioremap(gesbc_fio_pbase, SZ_1K);
	if(!gesbc_fio_base) {
		printk("ioremap GESBC-93xx NAND flash failed\n");
		kfree(gesbc_mtd);
		return -EIO;
	}

	
	/* Get pointer to private data */
	this = (struct nand_chip *) (&gesbc_mtd[1]);
	
	/* Initialize structures */
	memset((char *) gesbc_mtd, 0, sizeof(struct mtd_info));
	memset((char *) this, 0, sizeof(struct nand_chip));

	/* Link the private data with the MTD structure */
	gesbc_mtd->priv = this;

	/* Disbale interrupt to avoid race condition */
	local_irq_save(flags);

	/*
	 * Set GPIO Port A control register so that the pins are configured
	 * to be outputs for controlling the NAND flash.
	 */
	__raw_writel((__raw_readl(GPIO_PADDR) | 0x58) & ~0x80, GPIO_PADDR);
	/* Clear NCE, clear CLE, clear ALE */
	__raw_writel( (__raw_readl(GPIO_PADR) | 0x08 ) & ~0x50, GPIO_PADR);
	/* Set SRAM controller to 32 bit (8 bit just doesn't work, don't know why) bus width and 7 CLK wait state */
	__raw_writel(0x10003ce0, SMCBCR1);
	local_irq_restore(flags);

	
	/* insert callbacks */
	this->IO_ADDR_R = (void *) gesbc_fio_base;
	this->IO_ADDR_W = (void *) gesbc_fio_base;
	this->cmd_ctrl = (void *) gesbc_hwcontrol;
	this->dev_ready = gesbc_device_ready;
	this->chip_delay = 25;
	this->ecc.mode = NAND_ECC_SOFT;
	
	__raw_writel(0xffffffff, gesbc_fio_base);
	printk("Searching for NAND flash...\n");
	/* Scan to find existence of the device */
	if (nand_scan (gesbc_mtd, 1)) {
		iounmap((void *)gesbc_fio_base);
		kfree (gesbc_mtd);
		return -ENXIO;
	}
	
	if (mtd_parts_nb == 0)
	{
		mtd_parts_nb = NUM_PARTITIONS;
		mtd_parts = partition_info32;
		if (gesbc_mtd->size >= (128 * 0x100000))
			mtd_parts = partition_info128;
		if (gesbc_mtd->size >= (256 * 0x100000))
			mtd_parts = partition_info256;
		if (gesbc_mtd->size >= (512 * 0x100000))
			mtd_parts = partition_info512;
		part_type = "static";
	}
	
	/* Register the partitions */
	printk(KERN_NOTICE "Using %s partition definition\n", part_type);
	add_mtd_partitions(gesbc_mtd, mtd_parts, mtd_parts_nb);
	
	/* Return happy */
	return 0;
}
module_init(gesbc_nand_init);

/*
 * Clean up routine
 */
static void __exit gesbc_nand_cleanup (void)
{
/*	struct nand_chip *this = (struct nand_chip *) &gesbc_mtd[1]; */
	
	/* Unregister the device */
	del_mtd_device (gesbc_mtd);
	
	/* Free the MTD device structure */
	kfree (gesbc_mtd);
}
module_exit(gesbc_nand_cleanup);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("zql@glomationinc.com");
MODULE_DESCRIPTION("MTD map driver for Glomation GESBC-93xx board");


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

end of thread, other threads:[~2007-07-04 12:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-07-02 16:08 Strange NAND scan problem z l
2007-07-03 22:14 ` David Woodhouse
2007-07-04 12:35   ` z l

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.