]> git.ipfire.org Git - people/ms/u-boot.git/blob - drivers/mtd/nand/nand_plat.c
mtd: nand: new base driver for memory mapped nand devices
[people/ms/u-boot.git] / drivers / mtd / nand / nand_plat.c
1 /*
2 * Genericish driver for memory mapped NAND devices
3 *
4 * Copyright (c) 2006-2009 Analog Devices Inc.
5 * Licensed under the GPL-2 or later.
6 */
7
8 /* Your board must implement the following macros:
9 * NAND_PLAT_WRITE_CMD(chip, cmd)
10 * NAND_PLAT_WRITE_ADR(chip, cmd)
11 * NAND_PLAT_INIT()
12 *
13 * It may also implement the following:
14 * NAND_PLAT_DEV_READY(chip)
15 */
16
17 #include <common.h>
18 #include <asm/io.h>
19
20 #include <nand.h>
21
22 static void plat_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
23 {
24 struct nand_chip *this = mtd->priv;
25
26 if (cmd == NAND_CMD_NONE)
27 return;
28
29 if (ctrl & NAND_CLE)
30 NAND_PLAT_WRITE_CMD(this, cmd);
31 else
32 NAND_PLAT_WRITE_ADR(this, cmd);
33 }
34
35 #ifdef NAND_PLAT_DEV_READY
36 static int plat_dev_ready(struct mtd_info *mtd)
37 {
38 return NAND_PLAT_DEV_READY((struct nand_chip *)mtd->priv);
39 }
40 #else
41 # define plat_dev_ready NULL
42 #endif
43
44 int board_nand_init(struct nand_chip *nand)
45 {
46 NAND_PLAT_INIT();
47
48 nand->cmd_ctrl = plat_cmd_ctrl;
49 nand->dev_ready = plat_dev_ready;
50 nand->ecc.mode = NAND_ECC_SOFT;
51
52 return 0;
53 }