- 论坛徽章:
- 0
|
本帖最后由 forch 于 2011-09-22 00:11 编辑
- [root@forch /proc]# cat iomem
- 30000000-31ffffff : System RAM
- 3002a000-3035efff : Kernel text
- 30360000-303ab927 : Kernel data
- 49000000-490fffff : s3c2410-ohci
- 49000000-490fffff : ohci_hcd
- 4e000000-4e0fffff : s3c2440-nand
- 4e000000-4e0fffff : s3c2440-nand
- 50000000-50003fff : s3c2440-uart.0
- 50000000-500000ff : s3c2440-uart
- 50004000-50007fff : s3c2440-uart.1
- 50004000-500040ff : s3c2440-uart
- 50008000-5000bfff : s3c2440-uart.2
- 50008000-500080ff : s3c2440-uart
- [root@forch /proc]#
复制代码 开机后可以看到nand IO内存的相关信息如上,4e000000就是nand寄存器的开始地址,使用ioremap返回错误,先注销IO内存重新申请就可以ioremap成功,到底怎么把数据读出来呢?
s3c2410和s3c2440 nand 寄存器定义在内核头文件include\asm-arm\plat-s3c\regs-nand.h中- #define S3C2410_NFREG(x) (x)
- #define S3C2410_NFCONF S3C2410_NFREG(0x00)
- #define S3C2410_NFCMD S3C2410_NFREG(0x04)
- #define S3C2410_NFADDR S3C2410_NFREG(0x08)
- #define S3C2410_NFDATA S3C2410_NFREG(0x0C)
复制代码 这个函数有问题吗?这样运行不会死机,数据似乎就没有读正确
- int nand_read_page_2626(unsigned char *buf, unsigned long addr)
- {
- struct resource *res;
- int size;
- unsigned long cfg=0;
- // unsigned char buf[1024]={0};
- int len=512;
- int cmd=0;
-
- cfg=0;
-
- // 直接释放内存IO
- release_mem_region(S3C2410_PA_NAND,S3C24XX_SZ_NAND);
- // 申请IO内存
- res=request_mem_region(S3C2410_PA_NAND,S3C24XX_SZ_NAND,"lcm_fgw_t1");//
- if (res==NULL)
- {
- printk("request_mem_region fail \n");
- printk("release_mem_region \n");
- release_mem_region(S3C2410_PA_NAND,S3C24XX_SZ_NAND);
- return -1;
- }
-
- // 重映射IO内存
- res->start = S3C2410_PA_NAND;
- size = S3C24XX_SZ_NAND;
- regs = ioremap(res->start, size);
- if (regs == NULL) {
- printk("cannot reserve register region\n");
- return -2;
- }
- printk("ready to nandrw \n");
- mdelay(500);
-
- // 操作IO内存
- printk("nandll_read_page addr=%#x \n",(int)addr);
- // 操作IO内存开始
- // printk("nandll_read_page addr=%#x \n",(int)addr);
- // (NFCONT &= ~(1 << 1))
- cmd=readb(regs + S3C2440_NFCONT);
- cmd &= ~(1 << 1);
- writeb(cmd,regs + S3C2440_NFCONT);
- // (NFSTAT |= (1 << 2))
- cmd=readb(regs + S3C2440_NFSTAT);
- cmd |= (1 << 2);
- writeb(cmd,regs + S3C2440_NFSTAT);
- // NFCMMD = 0;
- cmd = 0;
- writeb(cmd,regs + S3C2440_NFCMD);
- /* Write Address */
- // NFADDR = addr & 0xff;
- cmd =addr & 0xff;
- writeb(cmd,regs + S3C2440_NFADDR);
- cmd = (addr >> 9) & 0xff;
- writeb(cmd,regs + S3C2440_NFADDR);
- // NFADDR = (addr >> 9) & 0xff;
- cmd = (addr >> 17) & 0xff;
- writeb(cmd,regs + S3C2440_NFADDR);
- // NFADDR = (addr >> 17) & 0xff;
- cmd = (addr >> 25) & 0xff;
- writeb(cmd,regs + S3C2440_NFADDR);
- // NFADDR = (addr >> 25) & 0xff;
- // { while(!(NFSTAT & 0x4));
- while(!( readb(regs + S3C2440_NFSTAT) & 0x4));
- // for(i=0; i < 512/4; i++)
- // {
- // *ptr16 = NFDATA32;
- // ptr16++;
- // }
- readsl(regs + S3C2440_NFDATA, buf, len / 4);
- // (NFCONT |= (1 << 1))
- cmd=readb(regs + S3C2440_NFCONT);
- cmd |= (1 << 1);
- writeb(cmd,regs + S3C2440_NFCONT);
-
- // 操作IO内存结束
-
- // 解除重映射IO内存
- if (regs != NULL)
- {
- iounmap(regs);
- regs = NULL;
- }
-
-
- // 释放IO内存
- release_mem_region(S3C2410_PA_NAND,S3C24XX_SZ_NAND);
-
- return 0;
- }
复制代码 |
|