1 From e2c285e95e75258c196fbc04a742d91be6d00f49 Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Wed, 30 Jan 2013 21:12:47 +0100
4 Subject: [PATCH 18/31] MTD: lantiq: Add NAND support on Lantiq Falcon SoC.
6 The driver uses plat_nand. As the platform_device is loaded from DT, we need
7 to lookup the node and attach our falcon specific "struct platform_nand_data"
10 Signed-off-by: Thomas Langer <thomas.langer@lantiq.com>
11 Signed-off-by: John Crispin <blogic@openwrt.org>
13 drivers/mtd/nand/Kconfig | 8 ++++
14 drivers/mtd/nand/Makefile | 1 +
15 drivers/mtd/nand/falcon_nand.c | 83 ++++++++++++++++++++++++++++++++++++++++
16 3 files changed, 92 insertions(+)
17 create mode 100644 drivers/mtd/nand/falcon_nand.c
19 diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
20 index 90ff447..7064f0e 100644
21 --- a/drivers/mtd/nand/Kconfig
22 +++ b/drivers/mtd/nand/Kconfig
23 @@ -510,4 +510,12 @@ config MTD_NAND_XWAY
24 Enables support for NAND Flash chips on Lantiq XWAY SoCs. NAND is attached
25 to the External Bus Unit (EBU).
27 +config MTD_NAND_FALCON
28 + tristate "Support for NAND on Lantiq FALC-ON SoC"
29 + depends on LANTIQ && SOC_FALCON
30 + select MTD_NAND_PLATFORM
32 + Enables support for NAND Flash chips on Lantiq FALC-ON SoCs. NAND is
33 + attached to the External Bus Unit (EBU).
36 diff --git a/drivers/mtd/nand/Makefile b/drivers/mtd/nand/Makefile
37 index 542b568..78a1cd2 100644
38 --- a/drivers/mtd/nand/Makefile
39 +++ b/drivers/mtd/nand/Makefile
40 @@ -49,5 +49,6 @@ obj-$(CONFIG_MTD_NAND_JZ4740) += jz4740_nand.o
41 obj-$(CONFIG_MTD_NAND_GPMI_NAND) += gpmi-nand/
42 obj-$(CONFIG_MTD_NAND_XWAY) += xway_nand.o
43 obj-$(CONFIG_MTD_NAND_BCM47XXNFLASH) += bcm47xxnflash/
44 +obj-$(CONFIG_MTD_NAND_FALCON) += falcon_nand.o
46 nand-objs := nand_base.o nand_bbt.o
47 diff --git a/drivers/mtd/nand/falcon_nand.c b/drivers/mtd/nand/falcon_nand.c
49 index 0000000..13458d3
51 +++ b/drivers/mtd/nand/falcon_nand.c
54 + * This program is free software; you can redistribute it and/or modify it
55 + * under the terms of the GNU General Public License version 2 as published
56 + * by the Free Software Foundation.
58 + * Copyright (C) 2011 Thomas Langer <thomas.langer@lantiq.com>
59 + * Copyright (C) 2011 John Crispin <blogic@openwrt.org>
62 +#include <linux/mtd/nand.h>
63 +#include <linux/of_platform.h>
65 +#include <lantiq_soc.h>
67 +/* address lines used for NAND control signals */
68 +#define NAND_ADDR_ALE 0x10000
69 +#define NAND_ADDR_CLE 0x20000
71 +/* Ready/Busy Status */
72 +#define MODCON_STS 0x0002
74 +/* Ready/Busy Status Edge */
75 +#define MODCON_STSEDGE 0x0004
76 +#define LTQ_EBU_MODCON 0x000C
78 +static const char const *part_probes[] = { "cmdlinepart", "ofpart", NULL };
80 +static int falcon_nand_ready(struct mtd_info *mtd)
82 + u32 modcon = ltq_ebu_r32(LTQ_EBU_MODCON);
84 + return (((modcon & (MODCON_STS | MODCON_STSEDGE)) ==
85 + (MODCON_STS | MODCON_STSEDGE)));
88 +static void falcon_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
90 + struct nand_chip *this = mtd->priv;
91 + unsigned long nandaddr = (unsigned long) this->IO_ADDR_W;
93 + if (ctrl & NAND_CTRL_CHANGE) {
94 + nandaddr &= ~(NAND_ADDR_ALE | NAND_ADDR_CLE);
96 + if (ctrl & NAND_CLE)
97 + nandaddr |= NAND_ADDR_CLE;
98 + if (ctrl & NAND_ALE)
99 + nandaddr |= NAND_ADDR_ALE;
101 + this->IO_ADDR_W = (void __iomem *) nandaddr;
104 + if (cmd != NAND_CMD_NONE)
105 + writeb(cmd, this->IO_ADDR_W);
108 +static struct platform_nand_data falcon_nand_data = {
112 + .part_probe_types = part_probes,
115 + .cmd_ctrl = falcon_hwcontrol,
116 + .dev_ready = falcon_nand_ready,
120 +int __init falcon_register_nand(void)
122 + struct device_node *node;
123 + struct platform_device *pdev;
125 + node = of_find_compatible_node(NULL, NULL, "lantiq,nand-falcon");
128 + pdev = of_find_device_by_node(node);
130 + pdev->dev.platform_data = &falcon_nand_data;
135 +arch_initcall(falcon_register_nand);