mtd: fix Orion NAND driver compilation with ARM OABI
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / mtd / nand / orion_nand.c
blobd60fc5719fef33e29ff29e970aadc735a00f40de
1 /*
2 * drivers/mtd/nand/orion_nand.c
4 * NAND support for Marvell Orion SoC platforms
6 * Tzachi Perelstein <tzachi@marvell.com>
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.
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 <mach/hardware.h>
22 #include <plat/orion_nand.h>
24 #ifdef CONFIG_MTD_CMDLINE_PARTS
25 static const char *part_probes[] = { "cmdlinepart", NULL };
26 #endif
28 static void orion_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
30 struct nand_chip *nc = mtd->priv;
31 struct orion_nand_data *board = nc->priv;
32 u32 offs;
34 if (cmd == NAND_CMD_NONE)
35 return;
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;
44 if (nc->options & NAND_BUSWIDTH_16)
45 offs <<= 1;
47 writeb(cmd, nc->IO_ADDR_W + offs);
50 static void orion_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
52 struct nand_chip *chip = mtd->priv;
53 void __iomem *io_base = chip->IO_ADDR_R;
54 uint64_t *buf64;
55 int i = 0;
57 while (len && (unsigned long)buf & 7) {
58 *buf++ = readb(io_base);
59 len--;
61 buf64 = (uint64_t *)buf;
62 while (i < len/8) {
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.
68 register uint64_t x asm ("r2");
70 asm volatile ("ldrd\t%0, [%1]" : "=&r" (x) : "r" (io_base));
71 buf64[i++] = x;
73 i *= 8;
74 while (i < len)
75 buf[i++] = readb(io_base);
78 static int __init orion_nand_probe(struct platform_device *pdev)
80 struct mtd_info *mtd;
81 struct nand_chip *nc;
82 struct orion_nand_data *board;
83 void __iomem *io_base;
84 int ret = 0;
85 #ifdef CONFIG_MTD_PARTITIONS
86 struct mtd_partition *partitions = NULL;
87 int num_part = 0;
88 #endif
90 nc = kzalloc(sizeof(struct nand_chip) + sizeof(struct mtd_info), GFP_KERNEL);
91 if (!nc) {
92 printk(KERN_ERR "orion_nand: failed to allocate device structure.\n");
93 ret = -ENOMEM;
94 goto no_res;
96 mtd = (struct mtd_info *)(nc + 1);
98 io_base = ioremap(pdev->resource[0].start,
99 pdev->resource[0].end - pdev->resource[0].start + 1);
100 if (!io_base) {
101 printk(KERN_ERR "orion_nand: ioremap failed\n");
102 ret = -EIO;
103 goto no_res;
106 board = pdev->dev.platform_data;
108 mtd->priv = nc;
109 mtd->owner = THIS_MODULE;
111 nc->priv = board;
112 nc->IO_ADDR_R = nc->IO_ADDR_W = io_base;
113 nc->cmd_ctrl = orion_nand_cmd_ctrl;
114 nc->read_buf = orion_nand_read_buf;
115 nc->ecc.mode = NAND_ECC_SOFT;
117 if (board->chip_delay)
118 nc->chip_delay = board->chip_delay;
120 if (board->width == 16)
121 nc->options |= NAND_BUSWIDTH_16;
123 platform_set_drvdata(pdev, mtd);
125 if (nand_scan(mtd, 1)) {
126 ret = -ENXIO;
127 goto no_dev;
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;
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
149 if (ret) {
150 nand_release(mtd);
151 goto no_dev;
154 return 0;
156 no_dev:
157 platform_set_drvdata(pdev, NULL);
158 iounmap(io_base);
159 no_res:
160 kfree(nc);
162 return ret;
165 static int __devexit orion_nand_remove(struct platform_device *pdev)
167 struct mtd_info *mtd = platform_get_drvdata(pdev);
168 struct nand_chip *nc = mtd->priv;
170 nand_release(mtd);
172 iounmap(nc->IO_ADDR_W);
174 kfree(nc);
176 return 0;
179 static struct platform_driver orion_nand_driver = {
180 .remove = __devexit_p(orion_nand_remove),
181 .driver = {
182 .name = "orion_nand",
183 .owner = THIS_MODULE,
187 static int __init orion_nand_init(void)
189 return platform_driver_probe(&orion_nand_driver, orion_nand_probe);
192 static void __exit orion_nand_exit(void)
194 platform_driver_unregister(&orion_nand_driver);
197 module_init(orion_nand_init);
198 module_exit(orion_nand_exit);
200 MODULE_LICENSE("GPL");
201 MODULE_AUTHOR("Tzachi Perelstein");
202 MODULE_DESCRIPTION("NAND glue for Orion platforms");
203 MODULE_ALIAS("platform:orion_nand");