mtd: sm_common: split smartmedia and xD table
[deliverable/linux.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) {
a88a2b88
PZ
63 /*
64 * Since GCC has no proper constraint (PR 43518)
65 * force x variable to r2/r3 registers as ldrd instruction
66 * requires first register to be even.
67 */
68 register uint64_t x asm ("r2");
69
94da210a 70 asm volatile ("ldrd\t%0, [%1]" : "=&r" (x) : "r" (io_base));
bfee1a43
NP
71 buf64[i++] = x;
72 }
73 i *= 8;
74 while (i < len)
75 buf[i++] = readb(io_base);
76}
77
2a1dba29
TP
78static int __init orion_nand_probe(struct platform_device *pdev)
79{
80 struct mtd_info *mtd;
81 struct nand_chip *nc;
82 struct orion_nand_data *board;
e9903060 83 struct resource *res;
2a1dba29
TP
84 void __iomem *io_base;
85 int ret = 0;
86#ifdef CONFIG_MTD_PARTITIONS
87 struct mtd_partition *partitions = NULL;
88 int num_part = 0;
89#endif
90
91 nc = kzalloc(sizeof(struct nand_chip) + sizeof(struct mtd_info), GFP_KERNEL);
92 if (!nc) {
93 printk(KERN_ERR "orion_nand: failed to allocate device structure.\n");
94 ret = -ENOMEM;
95 goto no_res;
96 }
97 mtd = (struct mtd_info *)(nc + 1);
98
e9903060
HS
99 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
100 if (!res) {
2d6bfc26 101 ret = -ENODEV;
e9903060
HS
102 goto no_res;
103 }
104
105 io_base = ioremap(res->start, resource_size(res));
2a1dba29
TP
106 if (!io_base) {
107 printk(KERN_ERR "orion_nand: ioremap failed\n");
108 ret = -EIO;
109 goto no_res;
110 }
111
112 board = pdev->dev.platform_data;
113
114 mtd->priv = nc;
115 mtd->owner = THIS_MODULE;
116
117 nc->priv = board;
118 nc->IO_ADDR_R = nc->IO_ADDR_W = io_base;
119 nc->cmd_ctrl = orion_nand_cmd_ctrl;
bfee1a43 120 nc->read_buf = orion_nand_read_buf;
2a1dba29
TP
121 nc->ecc.mode = NAND_ECC_SOFT;
122
f4db56ff
SB
123 if (board->chip_delay)
124 nc->chip_delay = board->chip_delay;
125
2a1dba29
TP
126 if (board->width == 16)
127 nc->options |= NAND_BUSWIDTH_16;
128
129 platform_set_drvdata(pdev, mtd);
130
131 if (nand_scan(mtd, 1)) {
132 ret = -ENXIO;
133 goto no_dev;
134 }
135
136#ifdef CONFIG_MTD_PARTITIONS
137#ifdef CONFIG_MTD_CMDLINE_PARTS
138 mtd->name = "orion_nand";
139 num_part = parse_mtd_partitions(mtd, part_probes, &partitions, 0);
140#endif
141 /* If cmdline partitions have been passed, let them be used */
142 if (num_part <= 0) {
143 num_part = board->nr_parts;
144 partitions = board->parts;
145 }
146
147 if (partitions && num_part > 0)
148 ret = add_mtd_partitions(mtd, partitions, num_part);
149 else
150 ret = add_mtd_device(mtd);
151#else
152 ret = add_mtd_device(mtd);
153#endif
154
155 if (ret) {
156 nand_release(mtd);
157 goto no_dev;
158 }
159
160 return 0;
161
162no_dev:
163 platform_set_drvdata(pdev, NULL);
164 iounmap(io_base);
165no_res:
166 kfree(nc);
167
168 return ret;
169}
170
171static int __devexit orion_nand_remove(struct platform_device *pdev)
172{
173 struct mtd_info *mtd = platform_get_drvdata(pdev);
174 struct nand_chip *nc = mtd->priv;
175
176 nand_release(mtd);
177
178 iounmap(nc->IO_ADDR_W);
179
180 kfree(nc);
181
182 return 0;
183}
184
185static struct platform_driver orion_nand_driver = {
bdf602bd 186 .remove = __devexit_p(orion_nand_remove),
2a1dba29
TP
187 .driver = {
188 .name = "orion_nand",
189 .owner = THIS_MODULE,
190 },
191};
192
193static int __init orion_nand_init(void)
194{
f33dabbe 195 return platform_driver_probe(&orion_nand_driver, orion_nand_probe);
2a1dba29
TP
196}
197
198static void __exit orion_nand_exit(void)
199{
200 platform_driver_unregister(&orion_nand_driver);
201}
202
203module_init(orion_nand_init);
204module_exit(orion_nand_exit);
205
206MODULE_LICENSE("GPL");
207MODULE_AUTHOR("Tzachi Perelstein");
208MODULE_DESCRIPTION("NAND glue for Orion platforms");
1ff18422 209MODULE_ALIAS("platform:orion_nand");
This page took 0.185627 seconds and 5 git commands to generate.