Mike Frysinger | c0e7c7a | 2009-05-25 22:42:28 -0400 | [diff] [blame] | 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> |
Tom Rini | 3bde7e2 | 2021-09-22 14:50:35 -0400 | [diff] [blame] | 18 | #include <linux/mtd/rawnand.h> |
Mike Frysinger | c0e7c7a | 2009-05-25 22:42:28 -0400 | [diff] [blame] | 19 | #include <asm/io.h> |
Mike Frysinger | 3e86f2d | 2010-07-05 04:55:04 -0400 | [diff] [blame] | 20 | #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 Frysinger | c0e7c7a | 2009-05-25 22:42:28 -0400 | [diff] [blame] | 24 | |
| 25 | #include <nand.h> |
| 26 | |
| 27 | static void plat_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl) |
| 28 | { |
Scott Wood | 17fed14 | 2016-05-30 13:57:56 -0500 | [diff] [blame] | 29 | struct nand_chip *this = mtd_to_nand(mtd); |
Mike Frysinger | c0e7c7a | 2009-05-25 22:42:28 -0400 | [diff] [blame] | 30 | |
| 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 |
| 41 | static int plat_dev_ready(struct mtd_info *mtd) |
| 42 | { |
Scott Wood | 17fed14 | 2016-05-30 13:57:56 -0500 | [diff] [blame] | 43 | return NAND_PLAT_DEV_READY((struct nand_chip *)mtd_to_nand(mtd)); |
Mike Frysinger | c0e7c7a | 2009-05-25 22:42:28 -0400 | [diff] [blame] | 44 | } |
| 45 | #else |
| 46 | # define plat_dev_ready NULL |
| 47 | #endif |
| 48 | |
| 49 | int board_nand_init(struct nand_chip *nand) |
| 50 | { |
Mike Frysinger | 3e86f2d | 2010-07-05 04:55:04 -0400 | [diff] [blame] | 51 | #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 Frysinger | c0e7c7a | 2009-05-25 22:42:28 -0400 | [diff] [blame] | 57 | NAND_PLAT_INIT(); |
Mike Frysinger | 3e86f2d | 2010-07-05 04:55:04 -0400 | [diff] [blame] | 58 | #endif |
Mike Frysinger | c0e7c7a | 2009-05-25 22:42:28 -0400 | [diff] [blame] | 59 | |
| 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 | } |