📄 ppchameleon.c
字号:
/* * drivers/mtd/nand/ppchameleon.c * * Copyright (C) 2003 DAVE Srl (info@wawnet.biz) * * Derived from drivers/mtd/nand/edb7312.c * Copyright (C) 2002 Marius Gr鰃er (mag@sysgo.de) * * $Id: ppchameleon.c,v 1.0 2003/07/14 12:58:16 mag Exp $ * * 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 * PPChameleon board which utilizes the Samsung K9F5608U0B part. This is * a 256Mibit (32MiB x 8 bits) NAND flash device. */#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 <platforms/PPChameleonEVB.h>/* handy sizes */#define SZ_1K 0x00000400/* * MTD structure for PPChameleon board */static struct mtd_info *ppchameleon_mtd = NULL;/* * Values specific to the EDB7312 board (used with EP7312 processor) *//* Internal buffers. Page buffer and oob buffer for one block*/static u_char data_buf[512 + 16];static u_char oob_buf[16 * 32];/* * Module stuff */static int ppchameleon_fio_pbase = CFG_NAND0_PADDR;#ifdef MODULEMODULE_PARM(ppchameleon_fio_pbase, "i");__setup("ppchameleon_fio_pbase=",ppchameleon_fio_pbase);#endif#if ((defined CONFIG_MTD_PARTITIONS) || (defined CONFIG_MTD_PARTITIONS_MODULE))/* * Define static partitions for flash device */static struct mtd_partition partition_info[] = { { name: "PPChameleon Nand Flash Boot", offset: 0, size: 4*1024*1024 }, { name: "PPChameleon Nand Flash Root", offset: 4*1024*1024, size: 28*1024*1024 },};#define NUM_PARTITIONS 2#endif/* * hardware specific access to control-lines */static void ppchameleon_hwcontrol(struct mtd_info *mtdinfo, int cmd){ switch(cmd) { case NAND_CTL_SETCLE: MACRO_NAND_CTL_SETCLE(CFG_NAND0_PADDR); break; case NAND_CTL_CLRCLE: MACRO_NAND_CTL_CLRCLE(CFG_NAND0_PADDR); break; case NAND_CTL_SETALE: MACRO_NAND_CTL_SETALE(CFG_NAND0_PADDR); break; case NAND_CTL_CLRALE: MACRO_NAND_CTL_CLRALE(CFG_NAND0_PADDR); break; case NAND_CTL_SETNCE: MACRO_NAND_ENABLE_CE(CFG_NAND0_PADDR); break; case NAND_CTL_CLRNCE: MACRO_NAND_DISABLE_CE(CFG_NAND0_PADDR); break; }}#if 0/* * read device ready pin */static int ppchameleon_device_ready(void){ return 1;}#endif#ifdef CONFIG_MTD_PARTITIONSstatic const char *part_probes[] = { "cmdlinepart", NULL };#endif/* * Main initialization routine */static int __init ppchameleon_init (void){ struct nand_chip *this; const char *part_type = 0; int mtd_parts_nb = 0; struct mtd_partition *mtd_parts = 0; int ppchameleon_fio_base; #ifdef CONFIG_MTD_DEBUG printk( "[ppchameleon_init]\n");#endif /* Allocate memory for MTD device structure and private data */ ppchameleon_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL); if (!ppchameleon_mtd) { printk("Unable to allocate PPChameleon NAND MTD device structure.\n"); return -ENOMEM; } /* map physical address */ ppchameleon_fio_base = (unsigned long)ioremap(ppchameleon_fio_pbase, SZ_1K); if(!ppchameleon_fio_base) { printk("ioremap PPChameleon NAND flash failed\n"); kfree(ppchameleon_mtd); return -EIO; } /* Get pointer to private data */ this = (struct nand_chip *) (&ppchameleon_mtd[1]); /* Initialize structures */ memset((char *) ppchameleon_mtd, 0, sizeof(struct mtd_info)); memset((char *) this, 0, sizeof(struct nand_chip)); /* Link the private data with the MTD structure */ ppchameleon_mtd->priv = this; /* Thanx to U-Boot, no need to initialize GPIOs */ /* FIXME */ /* insert callbacks */ this->IO_ADDR_R = ppchameleon_fio_base; this->IO_ADDR_W = ppchameleon_fio_base; this->hwcontrol = ppchameleon_hwcontrol; /*this->dev_ready = ppchameleon_device_ready;*/ this->dev_ready = NULL; /* 15 us command delay time */ this->chip_delay = 12; /* ECC mode */ this->eccmode = NAND_ECC_SOFT; /* Set internal data buffer */ this->data_buf = data_buf; this->oob_buf = oob_buf; /* Scan to find existence of the device */ if (nand_scan (ppchameleon_mtd, 1)) { iounmap((void *)ppchameleon_fio_base); kfree (ppchameleon_mtd); return -ENXIO; }#ifdef CONFIG_MTD_PARTITIONS ppchameleon_mtd->name = "ppchameleon-nand"; mtd_parts_nb = parse_mtd_partitions(ppchameleon_mtd, part_probes, &mtd_parts, 0); if (mtd_parts_nb > 0) part_type = "command line"; else mtd_parts_nb = 0;#endif if (mtd_parts_nb == 0) {#if ((defined CONFIG_MTD_PARTITIONS) || (defined CONFIG_MTD_PARTITIONS_MODULE)) mtd_parts = partition_info; mtd_parts_nb = NUM_PARTITIONS;#endif part_type = "static"; } /* Register the partitions */ printk(KERN_NOTICE "Using %s partition definition\n", part_type); add_mtd_partitions(ppchameleon_mtd, mtd_parts, mtd_parts_nb); /* Return happy */ return 0;}module_init(ppchameleon_init);/* * Clean up routine */static void __exit ppchameleon_cleanup (void){#ifdef CONFIG_MTD_DEBUG printk( "[ppchameleon_cleanup]\n");#endif /* Unregister the device */ del_mtd_device (ppchameleon_mtd); /* Free the MTD device structure */ kfree (ppchameleon_mtd);}module_exit(ppchameleon_cleanup);MODULE_LICENSE("GPL");MODULE_AUTHOR("llandre <llandre@wawnet.biz>");MODULE_DESCRIPTION("MTD map driver for DAVE Srl PPChameleon board");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -