aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTzachi Perelstein <tzachi@marvell.com>2007-10-16 19:10:40 -0400
committerDavid Woodhouse <dwmw2@infradead.org>2007-12-03 08:03:46 -0500
commit2a1dba2931dc14a2a202eef435ab24cf6bc6dbd4 (patch)
tree242cd1dff1c47df15ae027afa2d84b757359fff7
parentcec80bf2cc5283f2f00c34f474be857e5c9f6f65 (diff)
[MTD] [NAND] Marvell Orion device bus NAND controller
Driver for the device bus NAND controller in the Marvell Orion family of ARM SoCs. Signed-off-by: Tzachi Perelstein <tzachi@marvell.com> Signed-off-by: Lennert Buytenhek <buytenh@marvell.com> Acked-by: Jörn Engel <joern@logfs.org> Signed-off-by: David Woodhouse <dwmw2@infradead.org>
-rw-r--r--drivers/mtd/nand/Kconfig9
-rw-r--r--drivers/mtd/nand/Makefile1
-rw-r--r--drivers/mtd/nand/orion_nand.c171
3 files changed, 181 insertions, 0 deletions
diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
index f8db62512090..0a840d5d75ae 100644
--- a/drivers/mtd/nand/Kconfig
+++ b/drivers/mtd/nand/Kconfig
@@ -312,4 +312,13 @@ config MTD_ALAUDA
312 These two (and possibly other) Alauda-based cardreaders for 312 These two (and possibly other) Alauda-based cardreaders for
313 SmartMedia and xD allow raw flash access. 313 SmartMedia and xD allow raw flash access.
314 314
315config MTD_NAND_ORION
316 tristate "NAND Flash support for Marvell Orion SoC"
317 depends on ARCH_ORION && MTD_NAND
318 help
319 This enables the NAND flash controller on Orion machines.
320
321 No board specific support is done by this driver, each board
322 must advertise a platform_device for the driver to attach.
323
315endif # MTD_NAND 324endif # MTD_NAND
diff --git a/drivers/mtd/nand/Makefile b/drivers/mtd/nand/Makefile
index fd5004795ec1..e35f5ea3a7a9 100644
--- a/drivers/mtd/nand/Makefile
+++ b/drivers/mtd/nand/Makefile
@@ -30,5 +30,6 @@ obj-$(CONFIG_MTD_NAND_BASLER_EXCITE) += excite_nandflash.o
30obj-$(CONFIG_MTD_NAND_PLATFORM) += plat_nand.o 30obj-$(CONFIG_MTD_NAND_PLATFORM) += plat_nand.o
31obj-$(CONFIG_MTD_ALAUDA) += alauda.o 31obj-$(CONFIG_MTD_ALAUDA) += alauda.o
32obj-$(CONFIG_MTD_NAND_PASEMI) += pasemi_nand.o 32obj-$(CONFIG_MTD_NAND_PASEMI) += pasemi_nand.o
33obj-$(CONFIG_MTD_NAND_ORION) += orion_nand.o
33 34
34nand-objs := nand_base.o nand_bbt.o 35nand-objs := nand_base.o nand_bbt.o
diff --git a/drivers/mtd/nand/orion_nand.c b/drivers/mtd/nand/orion_nand.c
new file mode 100644
index 000000000000..9162cca0182b
--- /dev/null
+++ b/drivers/mtd/nand/orion_nand.c
@@ -0,0 +1,171 @@
1/*
2 * drivers/mtd/nand/orion_nand.c
3 *
4 * NAND support for Marvell Orion SoC platforms
5 *
6 * Tzachi Perelstein <tzachi@marvell.com>
7 *
8 * This file is licensed under the terms of the GNU General Public
9 * License version 2. This program is licensed "as is" without any
10 * warranty of any kind, whether express or implied.
11 */
12
13#include <linux/slab.h>
14#include <linux/module.h>
15#include <linux/platform_device.h>
16#include <linux/mtd/mtd.h>
17#include <linux/mtd/nand.h>
18#include <linux/mtd/partitions.h>
19#include <asm/io.h>
20#include <asm/sizes.h>
21#include <asm/arch/platform.h>
22#include <asm/arch/hardware.h>
23
24#ifdef CONFIG_MTD_CMDLINE_PARTS
25static const char *part_probes[] = { "cmdlinepart", NULL };
26#endif
27
28static void orion_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
29{
30 struct nand_chip *nc = mtd->priv;
31 struct orion_nand_data *board = nc->priv;
32 u32 offs;
33
34 if (cmd == NAND_CMD_NONE)
35 return;
36
37 if (ctrl & NAND_CLE)
38 offs = (1 << board->cle);
39 else if (ctrl & NAND_ALE)
40 offs = (1 << board->ale);
41 else
42 return;
43
44 if (nc->options & NAND_BUSWIDTH_16)
45 offs <<= 1;
46
47 writeb(cmd, nc->IO_ADDR_W + offs);
48}
49
50static int __init orion_nand_probe(struct platform_device *pdev)
51{
52 struct mtd_info *mtd;
53 struct nand_chip *nc;
54 struct orion_nand_data *board;
55 void __iomem *io_base;
56 int ret = 0;
57#ifdef CONFIG_MTD_PARTITIONS
58 struct mtd_partition *partitions = NULL;
59 int num_part = 0;
60#endif
61
62 nc = kzalloc(sizeof(struct nand_chip) + sizeof(struct mtd_info), GFP_KERNEL);
63 if (!nc) {
64 printk(KERN_ERR "orion_nand: failed to allocate device structure.\n");
65 ret = -ENOMEM;
66 goto no_res;
67 }
68 mtd = (struct mtd_info *)(nc + 1);
69
70 io_base = ioremap(pdev->resource[0].start,
71 pdev->resource[0].end - pdev->resource[0].start + 1);
72 if (!io_base) {
73 printk(KERN_ERR "orion_nand: ioremap failed\n");
74 ret = -EIO;
75 goto no_res;
76 }
77
78 board = pdev->dev.platform_data;
79
80 mtd->priv = nc;
81 mtd->owner = THIS_MODULE;
82
83 nc->priv = board;
84 nc->IO_ADDR_R = nc->IO_ADDR_W = io_base;
85 nc->cmd_ctrl = orion_nand_cmd_ctrl;
86 nc->ecc.mode = NAND_ECC_SOFT;
87
88 if (board->width == 16)
89 nc->options |= NAND_BUSWIDTH_16;
90
91 platform_set_drvdata(pdev, mtd);
92
93 if (nand_scan(mtd, 1)) {
94 ret = -ENXIO;
95 goto no_dev;
96 }
97
98#ifdef CONFIG_MTD_PARTITIONS
99#ifdef CONFIG_MTD_CMDLINE_PARTS
100 mtd->name = "orion_nand";
101 num_part = parse_mtd_partitions(mtd, part_probes, &partitions, 0);
102#endif
103 /* If cmdline partitions have been passed, let them be used */
104 if (num_part <= 0) {
105 num_part = board->nr_parts;
106 partitions = board->parts;
107 }
108
109 if (partitions && num_part > 0)
110 ret = add_mtd_partitions(mtd, partitions, num_part);
111 else
112 ret = add_mtd_device(mtd);
113#else
114 ret = add_mtd_device(mtd);
115#endif
116
117 if (ret) {
118 nand_release(mtd);
119 goto no_dev;
120 }
121
122 return 0;
123
124no_dev:
125 platform_set_drvdata(pdev, NULL);
126 iounmap(io_base);
127no_res:
128 kfree(nc);
129
130 return ret;
131}
132
133static int __devexit orion_nand_remove(struct platform_device *pdev)
134{
135 struct mtd_info *mtd = platform_get_drvdata(pdev);
136 struct nand_chip *nc = mtd->priv;
137
138 nand_release(mtd);
139
140 iounmap(nc->IO_ADDR_W);
141
142 kfree(nc);
143
144 return 0;
145}
146
147static struct platform_driver orion_nand_driver = {
148 .probe = orion_nand_probe,
149 .remove = orion_nand_remove,
150 .driver = {
151 .name = "orion_nand",
152 .owner = THIS_MODULE,
153 },
154};
155
156static int __init orion_nand_init(void)
157{
158 return platform_driver_register(&orion_nand_driver);
159}
160
161static void __exit orion_nand_exit(void)
162{
163 platform_driver_unregister(&orion_nand_driver);
164}
165
166module_init(orion_nand_init);
167module_exit(orion_nand_exit);
168
169MODULE_LICENSE("GPL");
170MODULE_AUTHOR("Tzachi Perelstein");
171MODULE_DESCRIPTION("NAND glue for Orion platforms");