⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smdk24a0_nand.c

📁 ARM的著名的启动代码 vivi s3c2440部分已测试通过
💻 C
字号:
/* * vivi/drivers/mtd/maps/s3c24a0-flash.c:  *   Flash memory access on SA11x0 based devices * * Copyright (C) 2002 MIZI Research, Inc. *  * Based on linux/drivers/mtd/maps/s3c24a0-flash.c * * This code is GPL. *  * Author: Janghoon Lyu <nandy@mizi.com> * Date  : $Date: 2003/08/19 05:12:11 $ * * $Revision: 1.2 $ * $Id: smdk24a0_nand.c,v 1.2 2003/08/19 05:12:11 nandy Exp $ * * History * * 2002-06-26: Janghoon Lyu <nandy@mizi.com> *    - Created this code * */#include <config.h>#include <machine.h>#include <mtd/mtd.h>#include <mtd/map.h>#include <mtd/nand.h>//#include <io.h>#include <vstring.h>#include <time.h>#include <vmalloc.h>#include <types.h>#include <errno.h>//extern struct mtd_info *mymtd;static void smc_hwcontrol(int cmd) {	switch (cmd) {	case NAND_CTL_SETNCE:		NANDCONT &= ~(1 << 7); break;	case NAND_CTL_CLRNCE:		NANDCONT |= (1 << 7); break;	case NAND_CTL_SETCLE:		break;	case NAND_CTL_CLRCLE:		break;	case NAND_CTL_SETALE:		break;	case NAND_CTL_CLRALE:		break;	case NAND_CTL_DAT_IN:		break;	case NAND_CTL_DAT_OUT:		break;	}}static voidwrite_cmd(u_char val) {	NFCMD = (u_char)val;}static voidwrite_addr(u_char val) {	NFADDR = (u_char)val;}static u_charread_data(void) {	return (u_char)NFDATA;}static voidwrite_data(u_char val) {	NFDATA = (u_char)val;}static voidwait_for_ready(void) {	while (!(NFSTAT & NFSTAT_RnB)) {		/* Busy */		udelay(10);	}}inline intsmc_insert(struct nand_chip *this) {	/* Scan to find existance of the device */    if (smc_scan(mymtd)) {		return -ENXIO;    }    /* Allocate memory for internal data buffer */    this->data_buf = vmalloc(sizeof(u_char) *			     (mymtd->oobblock + mymtd->oobsize));    if (!this->data_buf) {		printk("Unable to allocate NAND data buffer for S3C24a0.\n");		this->data_buf = NULL;		return -ENOMEM;    }    return 0;}extern int bon_part_parser(void *);static intsmc_init(void){	struct nand_chip *this;	//u_int16_t nfconf;	/* Allocate memory for MTD device structure and private data */	mymtd = vmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip));	if (!mymtd) {		printk("Unable to allocate S3C24a0 NAND MTD device structure.\n");		return -ENOMEM;	}	/* Get pointer to private data */	this = (struct nand_chip *)(&mymtd[1]);	/* Initialize structures */	memset((char *)mymtd, 0, sizeof(struct mtd_info));	memset((char *)this, 0, sizeof(struct nand_chip));	/* Link the private data with the MTD structure */	mymtd->priv = this;	NANDCONF = ((7 << 12) | (7 << 8) | (7 << 4) | (0 << 0) | (1 << 3)) ;	NANDCONT = ((3 << 0));		/* Active chip */	/* Disable write protect */	GPCON_M &= ~(0x3 << 8);	GPCON_M |= (0x1 << 8);	/* to set as output */	GPDAT |= (0x1 << 15);	/* Disable write protect */	/* Set address of NAND IO lines */	this->hwcontrol = smc_hwcontrol;	this->write_cmd = write_cmd;	this->write_addr = write_addr;	this->read_data = read_data;	this->write_data = write_data;	this->wait_for_ready = wait_for_ready;	/* Chip Enable -> RESET -> Wait for Ready -> Chip Disable */	this->hwcontrol(NAND_CTL_SETNCE);	this->write_cmd(NAND_CMD_RESET);	this->wait_for_ready();	this->hwcontrol(NAND_CTL_CLRNCE);	smc_insert(this);	mymtd->mtd_part_parser = bon_part_parser;	return 0;}int mtd_arch_init(void){	int ret;	if ((ret = smc_init())) {		mymtd = NULL;		return ret;	}#ifdef CONFIG_MTD_BON	bon_init();#endif	return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -