smdk2410.c
来自「广州斯道2410普及版II的源代码」· C语言 代码 · 共 288 行
C
288 行
/* * drivers/mtd/s3c2410_nand.c * * Copyright (c) 2003 ERIC.ZHANG <zymcomes@sina.com> * 2003-05-31 * * Copyright (c) 2002 SAMSUNG ELECTRONICS * SW.LEE <hitchcar@sec.samsung.com> * * Derived from drivers/mtd/spia.c,autcpu12.c * Copyright (C) 2000 Steven J. Hill (sjhill@cotw.com) * * 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 * autronix s3c2410 board, which is a SmartMediaCard. It supports * 16MB, 32MB and 64MB cards. */#include <linux/slab.h>#include <linux/module.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>#include <asm/arch/S3C2410.h>/* * MTD structure for S3C2410 board */static struct mtd_info *s3c2410_mtd = NULL;/* * Module stuff */#if LINUX_VERSION_CODE < 0x20212 && defined(MODULE)#define s3c2410_nand_init init_module#define s3c2410_cleanup cleanup_module#endif#ifdef MODULEMODULE_PARM(s3c2410_temp, "i");__setup("s3c2410_temp=",s3c2410_temp);#endif/* * Define partitions for flash devices *//* * THIS IS ONLY PARTITION FOR S3C2410 NAND CONTROLLER * * This partition drives from IPAQ Linux Partition * * HAVE THE BELOW PARTITION IN YOUR MIND */ extern struct nand_oobinfo jffs2_oobinfo;static struct mtd_partition partition_info64k[] = { { name: "S3C2410 flash partition : loader", offset: 0, size: 0x00020000}, { name: "S3C2410 flash partition : param", offset: 0x00020000, size: 0x00010000}, { name: "S3C2410 flash partition : kernel", offset: 0x00030000, size: 0x001c0000}, { name: "S3C2410 flash partition : root", offset: 2 * SZ_1M, size: 2 * SZ_1M}, { name: "S3C2410 flash partition : user", offset: 4 * SZ_1M, size: 0x03af8000}, /*{ name: "S3C2410 flash partition : none", offset: 50 * SZ_1M, size: 48 * SZ_1M}, size: 0x008f8000}, */}; static struct mtd_partition partition_info16k[] = { { name: "S3C2410 flash partition : loader", offset: 0, size: 0x00020000}, { name: "S3C2410 flash partition : param", offset: 0x00020000, size: 0x00010000}, { name: "S3C2410 flash partition : kernel", offset: 0x00030000, size: 0x001c0000}, { name: "S3C2410 flash partition : root", offset: 2 * SZ_1M, size: 2 * SZ_1M}, { name: "S3C2410 flash partition : user", offset: 4 * SZ_1M, size: 60 * SZ_1M}, // { name: "S3C2410 flash partition : none",// offset: 8 * SZ_1M, // size: 8 * SZ_1M},};#define NUM_PARTITIONS64K 6#define NUM_PARTITIONS16K 5/* * hardware specific access to control-lines */void s3c2410_hwcontrol(int cmd){ switch(cmd){ /* SAMSUNG S3C2410 NAND CONTROLLER HARDWARE AUTOMATIC */ case NAND_CTL_SETCLE:break; case NAND_CTL_CLRCLE:break; case NAND_CTL_SETALE:break; case NAND_CTL_CLRALE:break; /* NAND FLASH MEMORY CHIP ENABLE -- active low */ case NAND_CTL_SETNCE: NFCONF= (NFCONF&~(1<<11))|(0<<11); break; case NAND_CTL_CLRNCE: NFCONF= (NFCONF&~(1<<11))|(1<<11); break; case NAND_CTL_S3C_WAIT: NF_WAITRB(); break; }}/** read device ready pin*/int s3c2410_device_ready(void){ return (NFSTAT&1) ? 1 : 0;}void NF_Reset(void){ int i; NF_nFCE_L(); NF_CMD(0xFF); //reset command for(i=0;i<10;i++); //tWB = 100ns. NF_WAITRB(); //wait 200~500us; NF_nFCE_H();}#if 1 #define TACLS 0#define TWRPH0 3#define TWRPH1 0#endifvoid NF_Init(void){ NFCONF=(1<<15)|(1<<14)|(1<<13)|(1<<12)|(1<<11)|(TACLS<<8)|(TWRPH0<<4)|(TWRPH1<<0); NF_Reset();}/* * Main initialization routine */int __init s3c2410_nand_init (void){ struct nand_chip *this; int err = 0; /* Allocate memory for MTD device structure and private data */ s3c2410_mtd = kmalloc (sizeof(struct mtd_info) + sizeof (struct nand_chip), GFP_KERNEL); if (!s3c2410_mtd) { printk ("Unable to allocate S3C2410 NAND MTD device structure.\n"); err = -ENOMEM; goto out; } /* Get pointer to private data */ this = (struct nand_chip *) (&s3c2410_mtd[1]); /* Initialize structures */ memset((char *) s3c2410_mtd, 0, sizeof(struct mtd_info)); memset((char *) this, 0, sizeof(struct nand_chip)); /* Link the private data with the MTD structure */ s3c2410_mtd->priv = this; this->hwcontrol = s3c2410_hwcontrol; this->dev_ready = s3c2410_device_ready; /* 200 us command delay time */ this->chip_delay = 20; this->eccmode = NAND_ECC_SOFT; NF_Init(); /* S3C2410 NAND FLASH INIT */ /* Scan to find existance of the device */ if (nand_scan (s3c2410_mtd)) {/* see include/linux/mtd/nand_ids.h */ err = -ENXIO; goto out_ior; } /* Allocate memory for internal data buffer */ this->data_buf = kmalloc (sizeof(u_char) * (s3c2410_mtd->oobblock + s3c2410_mtd->oobsize), GFP_KERNEL); if (!this->data_buf) { printk ("Unable to allocate NAND data buffer for S3C2410.\n"); err = -ENOMEM; goto out_ior; } /* Register the partitions */ switch(s3c2410_mtd->size){ case SZ_64M: add_mtd_partitions(s3c2410_mtd, partition_info64k, NUM_PARTITIONS64K); break; case SZ_16M: add_mtd_partitions(s3c2410_mtd, partition_info16k, NUM_PARTITIONS16K); break; default: printk("-------------------------------------------- \n"); printk("YOU MUST SEE nand_ids.h file \n"); printk("and must register your NAND SMC Device \n"); printk("Unsupported SmartMedia device\n"); printk (" Only test in MAF 0xEC, DEV 0x76 \n"); err = -ENXIO; goto out_cac; } goto out;out_cac:// kfree (this->data_cache); out_buf: kfree (this->data_buf); out_ior:out_mtd: kfree (s3c2410_mtd);out: return err;}module_init(s3c2410_nand_init);/* * Clean up routine */#ifdef MODULEstatic void __exit s3c2410_cleanup (void){ struct nand_chip *this = (struct nand_chip *) &s3c2410_mtd[1]; /* Unregister partitions */ del_mtd_partitions(s3c2410_mtd); /* Unregister the device */ del_mtd_device (s3c2410_mtd); /* Free internal data buffers */ kfree (this->data_buf); kfree (this->data_cache); /* Free the MTD device structure */ kfree (s3c2410_mtd);}module_exit(s3c2410_cleanup);#endifMODULE_LICENSE("GPL");MODULE_AUTHOR("SW.LEE <hitchcar@sec.samsung.com>");MODULE_DESCRIPTION("Glue layer for SmartMediaCard on s3c2410");
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?