00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #if 0
00020 #include <linux/slab.h>
00021 #include <linux/init.h>
00022 #include <linux/module.h>
00023 #include <linux/mtd/mtd.h>
00024 #include <linux/mtd/nand.h>
00025 #include <linux/mtd/partitions.h>
00026 #endif
00027 #include <asm/arch/memmap.h>
00028 #include <asm/arch/hwregs/reg_map.h>
00029 #include <asm/arch/hwregs/reg_rdwr.h>
00030 #include <asm/arch/hwregs/gio_defs.h>
00031 #include <asm/arch/hwregs/bif_core_defs.h>
00032 #if 0
00033 #include <asm/io.h>
00034 #endif
00035
00036 #include <linux/errno.h>
00037
00038 #include "mtd.h"
00039 #include "nand.h"
00040 #include "lib.h"
00041
00042 #define CE_BIT 4
00043 #define CLE_BIT 5
00044 #define ALE_BIT 6
00045 #define BY_BIT 7
00046
00047 static struct mtd_info *crisv32_mtd = NULL;
00048
00049
00050
00051 static void crisv32_hwcontrol(struct mtd_info *mtd, int cmd)
00052 {
00053 unsigned long flags;
00054 reg_gio_rw_pa_dout dout = REG_RD(gio, regi_gio, rw_pa_dout);
00055
00056 local_irq_save(flags);
00057 switch(cmd){
00058 case NAND_CTL_SETCLE:
00059 dout.data |= (1<<CLE_BIT);
00060 break;
00061 case NAND_CTL_CLRCLE:
00062 dout.data &= ~(1<<CLE_BIT);
00063 break;
00064 case NAND_CTL_SETALE:
00065 dout.data |= (1<<ALE_BIT);
00066 break;
00067 case NAND_CTL_CLRALE:
00068 dout.data &= ~(1<<ALE_BIT);
00069 break;
00070 case NAND_CTL_SETNCE:
00071
00072 dout.data &= ~((1<<CE_BIT) | (1<<ALE_BIT) | (1<<CLE_BIT));
00073 break;
00074 case NAND_CTL_CLRNCE:
00075 dout.data |= (1<<CE_BIT);
00076 dout.data &= ~((1<<ALE_BIT) | (1<<CLE_BIT));
00077 break;
00078 }
00079 REG_WR(gio, regi_gio, rw_pa_dout, dout);
00080 local_irq_restore(flags);
00081 }
00082
00083
00084
00085
00086 int crisv32_device_ready(struct mtd_info *mtd)
00087 {
00088 reg_gio_r_pa_din din = REG_RD(gio, regi_gio, r_pa_din);
00089 return ((din.data & (1 << BY_BIT)) >> BY_BIT);
00090 }
00091
00092
00093
00094
00095 struct mtd_info* __init crisv32_nand_flash_probe (void)
00096 {
00097 void __iomem *read_cs;
00098 void __iomem *write_cs;
00099
00100 reg_bif_core_rw_grp3_cfg bif_cfg = REG_RD(bif_core, regi_bif_core, rw_grp3_cfg);
00101 reg_gio_rw_pa_oe pa_oe = REG_RD(gio, regi_gio, rw_pa_oe);
00102 struct nand_chip *this;
00103 int err = 0;
00104
00105
00106 crisv32_mtd = kmalloc (sizeof(struct mtd_info) + sizeof (struct nand_chip),
00107 GFP_KERNEL);
00108 if (!crisv32_mtd) {
00109 printk ("Unable to allocate CRISv32 NAND MTD device structure.\n");
00110 err = -ENOMEM;
00111 return NULL;
00112 }
00113
00114 read_cs = ioremap(MEM_CSP0_START | MEM_NON_CACHEABLE, 8192);
00115 write_cs = ioremap(MEM_CSP1_START | MEM_NON_CACHEABLE, 8192);
00116
00117 if (!read_cs || !write_cs) {
00118 printk("CRISv32 NAND ioremap failed\n");
00119 err = -EIO;
00120 goto out_mtd;
00121 }
00122
00123
00124 this = (struct nand_chip *) (&crisv32_mtd[1]);
00125
00126 pa_oe.oe |= 1 << CE_BIT;
00127 pa_oe.oe |= 1 << ALE_BIT;
00128 pa_oe.oe |= 1 << CLE_BIT;
00129 pa_oe.oe &= ~ (1 << BY_BIT);
00130 REG_WR(gio, regi_gio, rw_pa_oe, pa_oe);
00131
00132 bif_cfg.gated_csp0 = regk_bif_core_rd;
00133 bif_cfg.gated_csp1 = regk_bif_core_wr;
00134 REG_WR(bif_core, regi_bif_core, rw_grp3_cfg, bif_cfg);
00135
00136
00137 memset((char *) crisv32_mtd, 0, sizeof(struct mtd_info));
00138 memset((char *) this, 0, sizeof(struct nand_chip));
00139
00140
00141 crisv32_mtd->priv = this;
00142
00143
00144 this->IO_ADDR_R = read_cs;
00145 this->IO_ADDR_W = write_cs;
00146 this->hwcontrol = crisv32_hwcontrol;
00147 this->dev_ready = crisv32_device_ready;
00148
00149 this->chip_delay = 20;
00150 this->eccmode = NAND_ECC_SOFT;
00151
00152 #if 0
00153
00154 this->options = NAND_USE_FLASH_BBT;
00155 #endif
00156
00157
00158 this->options = NAND_USE_FLASH_BBT;
00159
00160
00161 if (nand_scan (crisv32_mtd, 1)) {
00162 err = -ENXIO;
00163 goto out_ior;
00164 }
00165
00166 return crisv32_mtd;
00167
00168 out_ior:
00169 iounmap((void *)read_cs);
00170 iounmap((void *)write_cs);
00171 out_mtd:
00172 kfree (crisv32_mtd);
00173 return NULL;
00174 }
00175