]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/mtd/nand/orion_nand.c
mtd: orion_nand: Fix build failure caused by typo
[net-next-2.6.git] / drivers / mtd / nand / orion_nand.c
CommitLineData
2a1dba29
TP
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>
a09e64fb 21#include <mach/hardware.h>
6f088f1d 22#include <plat/orion_nand.h>
2a1dba29
TP
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
bfee1a43
NP
50static void orion_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
51{
52 struct nand_chip *chip = mtd->priv;
53 void __iomem *io_base = chip->IO_ADDR_R;
54 uint64_t *buf64;
55 int i = 0;
56
57 while (len && (unsigned long)buf & 7) {
58 *buf++ = readb(io_base);
59 len--;
60 }
61 buf64 = (uint64_t *)buf;
62 while (i < len/8) {
63 uint64_t x;
94da210a 64 asm volatile ("ldrd\t%0, [%1]" : "=&r" (x) : "r" (io_base));
bfee1a43
NP
65 buf64[i++] = x;
66 }
67 i *= 8;
68 while (i < len)
69 buf[i++] = readb(io_base);
70}
71
2a1dba29
TP
72static int __init orion_nand_probe(struct platform_device *pdev)
73{
74 struct mtd_info *mtd;
75 struct nand_chip *nc;
76 struct orion_nand_data *board;
e9903060 77 struct resource *res;
2a1dba29
TP
78 void __iomem *io_base;
79 int ret = 0;
80#ifdef CONFIG_MTD_PARTITIONS
81 struct mtd_partition *partitions = NULL;
82 int num_part = 0;
83#endif
84
85 nc = kzalloc(sizeof(struct nand_chip) + sizeof(struct mtd_info), GFP_KERNEL);
86 if (!nc) {
87 printk(KERN_ERR "orion_nand: failed to allocate device structure.\n");
88 ret = -ENOMEM;
89 goto no_res;
90 }
91 mtd = (struct mtd_info *)(nc + 1);
92
e9903060
HS
93 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
94 if (!res) {
2d6bfc26 95 ret = -ENODEV;
e9903060
HS
96 goto no_res;
97 }
98
99 io_base = ioremap(res->start, resource_size(res));
2a1dba29
TP
100 if (!io_base) {
101 printk(KERN_ERR "orion_nand: ioremap failed\n");
102 ret = -EIO;
103 goto no_res;
104 }
105
106 board = pdev->dev.platform_data;
107
108 mtd->priv = nc;
109 mtd->owner = THIS_MODULE;
110
111 nc->priv = board;
112 nc->IO_ADDR_R = nc->IO_ADDR_W = io_base;
113 nc->cmd_ctrl = orion_nand_cmd_ctrl;
bfee1a43 114 nc->read_buf = orion_nand_read_buf;
2a1dba29
TP
115 nc->ecc.mode = NAND_ECC_SOFT;
116
f4db56ff
SB
117 if (board->chip_delay)
118 nc->chip_delay = board->chip_delay;
119
2a1dba29
TP
120 if (board->width == 16)
121 nc->options |= NAND_BUSWIDTH_16;
122
123 platform_set_drvdata(pdev, mtd);
124
125 if (nand_scan(mtd, 1)) {
126 ret = -ENXIO;
127 goto no_dev;
128 }
129
130#ifdef CONFIG_MTD_PARTITIONS
131#ifdef CONFIG_MTD_CMDLINE_PARTS
132 mtd->name = "orion_nand";
133 num_part = parse_mtd_partitions(mtd, part_probes, &partitions, 0);
134#endif
135 /* If cmdline partitions have been passed, let them be used */
136 if (num_part <= 0) {
137 num_part = board->nr_parts;
138 partitions = board->parts;
139 }
140
141 if (partitions && num_part > 0)
142 ret = add_mtd_partitions(mtd, partitions, num_part);
143 else
144 ret = add_mtd_device(mtd);
145#else
146 ret = add_mtd_device(mtd);
147#endif
148
149 if (ret) {
150 nand_release(mtd);
151 goto no_dev;
152 }
153
154 return 0;
155
156no_dev:
157 platform_set_drvdata(pdev, NULL);
158 iounmap(io_base);
159no_res:
160 kfree(nc);
161
162 return ret;
163}
164
165static int __devexit orion_nand_remove(struct platform_device *pdev)
166{
167 struct mtd_info *mtd = platform_get_drvdata(pdev);
168 struct nand_chip *nc = mtd->priv;
169
170 nand_release(mtd);
171
172 iounmap(nc->IO_ADDR_W);
173
174 kfree(nc);
175
176 return 0;
177}
178
179static struct platform_driver orion_nand_driver = {
bdf602bd 180 .remove = __devexit_p(orion_nand_remove),
2a1dba29
TP
181 .driver = {
182 .name = "orion_nand",
183 .owner = THIS_MODULE,
184 },
185};
186
187static int __init orion_nand_init(void)
188{
f33dabbe 189 return platform_driver_probe(&orion_nand_driver, orion_nand_probe);
2a1dba29
TP
190}
191
192static void __exit orion_nand_exit(void)
193{
194 platform_driver_unregister(&orion_nand_driver);
195}
196
197module_init(orion_nand_init);
198module_exit(orion_nand_exit);
199
200MODULE_LICENSE("GPL");
201MODULE_AUTHOR("Tzachi Perelstein");
202MODULE_DESCRIPTION("NAND glue for Orion platforms");
1ff18422 203MODULE_ALIAS("platform:orion_nand");