Hi all,
我们在板子上集成了一块FPGA,通过GPMC总线,GPMC配置如下:
1. CS0: Nand flash
2. CS3: FPGA
下面的代码是配置GPMC CS3的:
void gpmc_fpga_init(void)
{
/* Perform the GPMC configurations for FPGA. */
gpmc_cs_write_reg(3, GPMC_CS_CONFIG7, 0); //CS3 disable
//burst read,single write
gpmc_cs_write_reg(3, GPMC_CS_CONFIG1, 0x69001001);
gpmc_cs_write_reg(3, GPMC_CS_CONFIG2, 0x00030701);
gpmc_cs_write_reg(3, GPMC_CS_CONFIG3, 0);
gpmc_cs_write_reg(3, GPMC_CS_CONFIG4, 0x03010684);
gpmc_cs_write_reg(3, GPMC_CS_CONFIG5, 0x02060408);
gpmc_cs_write_reg(3, GPMC_CS_CONFIG6, 0x03000200);
gpmc_cs_write_reg(3, GPMC_CS_CONFIG7, ((12 << 8) | ((0x4000000 >> 24) & 0x3F) | (1 << 6)));
gpmc_cs_write_reg(1, GPMC_CS_CONFIG7, 0);
gpmc_cs_write_reg(2, GPMC_CS_CONFIG7, 0);
gpmc_cs_write_reg(4, GPMC_CS_CONFIG7, 0);
gpmc_cs_write_reg(5, GPMC_CS_CONFIG7, 0);
gpmc_cs_write_reg(6, GPMC_CS_CONFIG7, 0);
gpmc_write_reg(GPMC_CONFIG, gpmc_read_reg(GPMC_CONFIG) & ~(0x2));
}
现在我们可以访问我们自己的FPGA了,但是在和Nand Flash一起使用时,发现了一些有趣的事情:
Step 1: 加载FPGA固件
Step 2: 读取FPGA版本号寄存器: __raw_readw(FPGA_BASE + 0x6);
Step 3: nandtest /dev/mtd0
Step 3总是会出错,如下:
[root@Ronds: ~]# nandtest /dev/mtd0
ECC corrections: 0
ECC failures : 128
Bad blocks : 0
BBT blocks : 0
00000000: reading (1 of 4)...[ 53.863347] omap2-nand 8000000.nand: uncorrectable bit-flips found
[ 53.871043] omap2-nand 8000000.nand: uncorrectable bit-flips found
[ 53.877252] omap2-nand 8000000.nand: uncorrectable bit-flips found
......
如果跳过Step1,那么nandtest就不会出错,也就是说如果FPGA本身没有工作,则不会出错。
经过一些测试,我找到了一个WA,如下:
Step 1: 加载FPGA固件
Step 2: 读取FPGA版本号: __raw_readw(FPGA_BASE + 0x6);
Step 3: devmem 0x50000114 --> 读取 GPMC_NAND_DATA_3 寄存器
Step 4: nandtest /dev/mtd0
在nandtest之前,读取一下GPMC_NAND_DATA_3 寄存器(必须是此寄存器,读其他的寄存器不管用),这样就不会出错了!!!
最终我把这个WA加到了nand控制器驱动里(drivers/mtd/nand/omap2.c):
void gpmc_wr_for_nand_fpga(void)
{
gpmc_cs_read_reg(3, GPMC_CS_NAND_DATA);
}
static void __maybe_unused omap_enable_hwecc_bch(struct mtd_info *mtd, int mode)
{
......
gpmc_wr_for_nand_fpga();
/* GPMC configurations for calculating ECC */
switch (ecc_opt) {
......
}
这样FPGA和Nand Flash就能和平共处了。
问题虽然解决了,但是我还是不明白,这个WA起作用的原因是什么?
希望各位有知道的烦请解个惑,谢谢了。。。