blob: 81e7aa218d54491b17dc3e18e2d392b342348703 [file] [log] [blame]
Mike Frysingerc0e7c7a2009-05-25 22:42:28 -04001/*
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>
Tom Rini3bde7e22021-09-22 14:50:35 -040018#include <linux/mtd/rawnand.h>
Mike Frysingerc0e7c7a2009-05-25 22:42:28 -040019#include <asm/io.h>
Mike Frysinger3e86f2d2010-07-05 04:55:04 -040020#ifdef NAND_PLAT_GPIO_DEV_READY
21# include <asm/gpio.h>
22# define NAND_PLAT_DEV_READY(chip) gpio_get_value(NAND_PLAT_GPIO_DEV_READY)
23#endif
Mike Frysingerc0e7c7a2009-05-25 22:42:28 -040024
25#include <nand.h>
26
27static void plat_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
28{
Scott Wood17fed142016-05-30 13:57:56 -050029 struct nand_chip *this = mtd_to_nand(mtd);
Mike Frysingerc0e7c7a2009-05-25 22:42:28 -040030
31 if (cmd == NAND_CMD_NONE)
32 return;
33
34 if (ctrl & NAND_CLE)
35 NAND_PLAT_WRITE_CMD(this, cmd);
36 else
37 NAND_PLAT_WRITE_ADR(this, cmd);
38}
39
40#ifdef NAND_PLAT_DEV_READY
41static int plat_dev_ready(struct mtd_info *mtd)
42{
Scott Wood17fed142016-05-30 13:57:56 -050043 return NAND_PLAT_DEV_READY((struct nand_chip *)mtd_to_nand(mtd));
Mike Frysingerc0e7c7a2009-05-25 22:42:28 -040044}
45#else
46# define plat_dev_ready NULL
47#endif
48
49int board_nand_init(struct nand_chip *nand)
50{
Mike Frysinger3e86f2d2010-07-05 04:55:04 -040051#ifdef NAND_PLAT_GPIO_DEV_READY
52 gpio_request(NAND_PLAT_GPIO_DEV_READY, "nand-plat");
53 gpio_direction_input(NAND_PLAT_GPIO_DEV_READY);
54#endif
55
56#ifdef NAND_PLAT_INIT
Mike Frysingerc0e7c7a2009-05-25 22:42:28 -040057 NAND_PLAT_INIT();
Mike Frysinger3e86f2d2010-07-05 04:55:04 -040058#endif
Mike Frysingerc0e7c7a2009-05-25 22:42:28 -040059
60 nand->cmd_ctrl = plat_cmd_ctrl;
61 nand->dev_ready = plat_dev_ready;
62 nand->ecc.mode = NAND_ECC_SOFT;
63
64 return 0;
65}