Path: blob/master/arch/cris/arch-v32/drivers/mach-a3/nandflash.c
15131 views
/*1* arch/cris/arch-v32/drivers/nandflash.c2*3* Copyright (c) 20074*5* Derived from drivers/mtd/nand/spia.c6* Copyright (C) 2000 Steven J. Hill ([email protected])7*8* This program is free software; you can redistribute it and/or modify9* it under the terms of the GNU General Public License version 2 as10* published by the Free Software Foundation.11*12*/1314#include <linux/slab.h>15#include <linux/init.h>16#include <linux/module.h>17#include <linux/mtd/mtd.h>18#include <linux/mtd/nand.h>19#include <linux/mtd/partitions.h>20#include <arch/memmap.h>21#include <hwregs/reg_map.h>22#include <hwregs/reg_rdwr.h>23#include <hwregs/pio_defs.h>24#include <pinmux.h>25#include <asm/io.h>2627#define MANUAL_ALE_CLE_CONTROL 12829#define regf_ALE a030#define regf_CLE a131#define regf_NCE ce0_n3233#define CLE_BIT 1034#define ALE_BIT 1135#define CE_BIT 123637struct mtd_info_wrapper {38struct mtd_info info;39struct nand_chip chip;40};4142/* Bitmask for control pins */43#define PIN_BITMASK ((1 << CE_BIT) | (1 << CLE_BIT) | (1 << ALE_BIT))4445static struct mtd_info *crisv32_mtd;46/*47* hardware specific access to control-lines48*/49static void crisv32_hwcontrol(struct mtd_info *mtd, int cmd,50unsigned int ctrl)51{52unsigned long flags;53reg_pio_rw_dout dout;54struct nand_chip *this = mtd->priv;5556local_irq_save(flags);5758/* control bits change */59if (ctrl & NAND_CTRL_CHANGE) {60dout = REG_RD(pio, regi_pio, rw_dout);61dout.regf_NCE = (ctrl & NAND_NCE) ? 0 : 1;6263#if !MANUAL_ALE_CLE_CONTROL64if (ctrl & NAND_ALE) {65/* A0 = ALE high */66this->IO_ADDR_W = (void __iomem *)REG_ADDR(pio,67regi_pio, rw_io_access1);68} else if (ctrl & NAND_CLE) {69/* A1 = CLE high */70this->IO_ADDR_W = (void __iomem *)REG_ADDR(pio,71regi_pio, rw_io_access2);72} else {73/* A1 = CLE and A0 = ALE low */74this->IO_ADDR_W = (void __iomem *)REG_ADDR(pio,75regi_pio, rw_io_access0);76}77#else7879dout.regf_CLE = (ctrl & NAND_CLE) ? 1 : 0;80dout.regf_ALE = (ctrl & NAND_ALE) ? 1 : 0;81#endif82REG_WR(pio, regi_pio, rw_dout, dout);83}8485/* command to chip */86if (cmd != NAND_CMD_NONE)87writeb(cmd, this->IO_ADDR_W);8889local_irq_restore(flags);90}9192/*93* read device ready pin94*/95static int crisv32_device_ready(struct mtd_info *mtd)96{97reg_pio_r_din din = REG_RD(pio, regi_pio, r_din);98return din.rdy;99}100101/*102* Main initialization routine103*/104struct mtd_info *__init crisv32_nand_flash_probe(void)105{106void __iomem *read_cs;107void __iomem *write_cs;108109struct mtd_info_wrapper *wrapper;110struct nand_chip *this;111int err = 0;112113reg_pio_rw_man_ctrl man_ctrl = {114.regf_NCE = regk_pio_yes,115#if MANUAL_ALE_CLE_CONTROL116.regf_ALE = regk_pio_yes,117.regf_CLE = regk_pio_yes118#endif119};120reg_pio_rw_oe oe = {121.regf_NCE = regk_pio_yes,122#if MANUAL_ALE_CLE_CONTROL123.regf_ALE = regk_pio_yes,124.regf_CLE = regk_pio_yes125#endif126};127reg_pio_rw_dout dout = { .regf_NCE = 1 };128129/* Allocate pio pins to pio */130crisv32_pinmux_alloc_fixed(pinmux_pio);131/* Set up CE, ALE, CLE (ce0_n, a0, a1) for manual control and output */132REG_WR(pio, regi_pio, rw_man_ctrl, man_ctrl);133REG_WR(pio, regi_pio, rw_dout, dout);134REG_WR(pio, regi_pio, rw_oe, oe);135136/* Allocate memory for MTD device structure and private data */137wrapper = kzalloc(sizeof(struct mtd_info_wrapper), GFP_KERNEL);138if (!wrapper) {139printk(KERN_ERR "Unable to allocate CRISv32 NAND MTD "140"device structure.\n");141err = -ENOMEM;142return NULL;143}144145read_cs = write_cs = (void __iomem *)REG_ADDR(pio, regi_pio,146rw_io_access0);147148/* Get pointer to private data */149this = &wrapper->chip;150crisv32_mtd = &wrapper->info;151152/* Link the private data with the MTD structure */153crisv32_mtd->priv = this;154155/* Set address of NAND IO lines */156this->IO_ADDR_R = read_cs;157this->IO_ADDR_W = write_cs;158this->cmd_ctrl = crisv32_hwcontrol;159this->dev_ready = crisv32_device_ready;160/* 20 us command delay time */161this->chip_delay = 20;162this->ecc.mode = NAND_ECC_SOFT;163164/* Enable the following for a flash based bad block table */165/* this->options = NAND_USE_FLASH_BBT; */166167/* Scan to find existence of the device */168if (nand_scan(crisv32_mtd, 1)) {169err = -ENXIO;170goto out_mtd;171}172173return crisv32_mtd;174175out_mtd:176kfree(wrapper);177return NULL;178}179180181182