2 * drivers/mtd/nand/ams-delta.c
4 * Copyright (C) 2006 Jonathan McDowell <noodles@earth.li>
6 * Derived from drivers/mtd/toto.c
7 * Converted to platform driver by Janusz Krzysztofik <jkrzyszt@tis.icnet.pl>
8 * Partially stolen from drivers/mtd/nand/plat_nand.c
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
15 * This is a device driver for the NAND flash device found on the
19 #include <linux/slab.h>
20 #include <linux/module.h>
21 #include <linux/delay.h>
22 #include <linux/mtd/mtd.h>
23 #include <linux/mtd/nand.h>
24 #include <linux/mtd/partitions.h>
25 #include <linux/gpio.h>
26 #include <linux/platform_data/gpio-omap.h>
29 #include <asm/sizes.h>
31 #include <mach/board-ams-delta.h>
33 #include <mach/hardware.h>
36 * MTD structure for E3 (Delta)
38 static struct mtd_info
*ams_delta_mtd
= NULL
;
41 * Define partitions for flash devices
44 static struct mtd_partition partition_info
[] = {
47 .size
= 3 * SZ_1M
+ SZ_512K
},
49 .offset
= 3 * SZ_1M
+ SZ_512K
,
51 { .name
= "u-boot params",
52 .offset
= 3 * SZ_1M
+ SZ_512K
+ SZ_256K
,
54 { .name
= "Amstrad LDR",
57 { .name
= "File system",
58 .offset
= 4 * SZ_1M
+ 1 * SZ_256K
,
60 { .name
= "PBL reserved",
61 .offset
= 32 * SZ_1M
- 3 * SZ_256K
,
62 .size
= 3 * SZ_256K
},
65 static void ams_delta_write_byte(struct mtd_info
*mtd
, u_char byte
)
67 struct nand_chip
*this = mtd
->priv
;
68 void __iomem
*io_base
= this->priv
;
70 writew(0, io_base
+ OMAP_MPUIO_IO_CNTL
);
71 writew(byte
, this->IO_ADDR_W
);
72 gpio_set_value(AMS_DELTA_GPIO_PIN_NAND_NWE
, 0);
74 gpio_set_value(AMS_DELTA_GPIO_PIN_NAND_NWE
, 1);
77 static u_char
ams_delta_read_byte(struct mtd_info
*mtd
)
80 struct nand_chip
*this = mtd
->priv
;
81 void __iomem
*io_base
= this->priv
;
83 gpio_set_value(AMS_DELTA_GPIO_PIN_NAND_NRE
, 0);
85 writew(~0, io_base
+ OMAP_MPUIO_IO_CNTL
);
86 res
= readw(this->IO_ADDR_R
);
87 gpio_set_value(AMS_DELTA_GPIO_PIN_NAND_NRE
, 1);
92 static void ams_delta_write_buf(struct mtd_info
*mtd
, const u_char
*buf
,
98 ams_delta_write_byte(mtd
, buf
[i
]);
101 static void ams_delta_read_buf(struct mtd_info
*mtd
, u_char
*buf
, int len
)
105 for (i
=0; i
<len
; i
++)
106 buf
[i
] = ams_delta_read_byte(mtd
);
110 * Command control function
113 * NAND_NCE: bit 0 -> bit 2
114 * NAND_CLE: bit 1 -> bit 7
115 * NAND_ALE: bit 2 -> bit 6
117 static void ams_delta_hwcontrol(struct mtd_info
*mtd
, int cmd
,
121 if (ctrl
& NAND_CTRL_CHANGE
) {
122 gpio_set_value(AMS_DELTA_GPIO_PIN_NAND_NCE
,
123 (ctrl
& NAND_NCE
) == 0);
124 gpio_set_value(AMS_DELTA_GPIO_PIN_NAND_CLE
,
125 (ctrl
& NAND_CLE
) != 0);
126 gpio_set_value(AMS_DELTA_GPIO_PIN_NAND_ALE
,
127 (ctrl
& NAND_ALE
) != 0);
130 if (cmd
!= NAND_CMD_NONE
)
131 ams_delta_write_byte(mtd
, cmd
);
134 static int ams_delta_nand_ready(struct mtd_info
*mtd
)
136 return gpio_get_value(AMS_DELTA_GPIO_PIN_NAND_RB
);
139 static const struct gpio _mandatory_gpio
[] = {
141 .gpio
= AMS_DELTA_GPIO_PIN_NAND_NCE
,
142 .flags
= GPIOF_OUT_INIT_HIGH
,
146 .gpio
= AMS_DELTA_GPIO_PIN_NAND_NRE
,
147 .flags
= GPIOF_OUT_INIT_HIGH
,
151 .gpio
= AMS_DELTA_GPIO_PIN_NAND_NWP
,
152 .flags
= GPIOF_OUT_INIT_HIGH
,
156 .gpio
= AMS_DELTA_GPIO_PIN_NAND_NWE
,
157 .flags
= GPIOF_OUT_INIT_HIGH
,
161 .gpio
= AMS_DELTA_GPIO_PIN_NAND_ALE
,
162 .flags
= GPIOF_OUT_INIT_LOW
,
166 .gpio
= AMS_DELTA_GPIO_PIN_NAND_CLE
,
167 .flags
= GPIOF_OUT_INIT_LOW
,
173 * Main initialization routine
175 static int ams_delta_init(struct platform_device
*pdev
)
177 struct nand_chip
*this;
178 struct resource
*res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
179 void __iomem
*io_base
;
185 /* Allocate memory for MTD device structure and private data */
186 ams_delta_mtd
= kzalloc(sizeof(struct mtd_info
) +
187 sizeof(struct nand_chip
), GFP_KERNEL
);
188 if (!ams_delta_mtd
) {
189 printk (KERN_WARNING
"Unable to allocate E3 NAND MTD device structure.\n");
194 ams_delta_mtd
->owner
= THIS_MODULE
;
196 /* Get pointer to private data */
197 this = (struct nand_chip
*) (&ams_delta_mtd
[1]);
199 /* Link the private data with the MTD structure */
200 ams_delta_mtd
->priv
= this;
203 * Don't try to request the memory region from here,
204 * it should have been already requested from the
205 * gpio-omap driver and requesting it again would fail.
208 io_base
= ioremap(res
->start
, resource_size(res
));
209 if (io_base
== NULL
) {
210 dev_err(&pdev
->dev
, "ioremap failed\n");
215 this->priv
= io_base
;
217 /* Set address of NAND IO lines */
218 this->IO_ADDR_R
= io_base
+ OMAP_MPUIO_INPUT_LATCH
;
219 this->IO_ADDR_W
= io_base
+ OMAP_MPUIO_OUTPUT
;
220 this->read_byte
= ams_delta_read_byte
;
221 this->write_buf
= ams_delta_write_buf
;
222 this->read_buf
= ams_delta_read_buf
;
223 this->cmd_ctrl
= ams_delta_hwcontrol
;
224 if (gpio_request(AMS_DELTA_GPIO_PIN_NAND_RB
, "nand_rdy") == 0) {
225 this->dev_ready
= ams_delta_nand_ready
;
227 this->dev_ready
= NULL
;
228 printk(KERN_NOTICE
"Couldn't request gpio for Delta NAND ready.\n");
230 /* 25 us command delay time */
231 this->chip_delay
= 30;
232 this->ecc
.mode
= NAND_ECC_SOFT
;
234 platform_set_drvdata(pdev
, io_base
);
236 /* Set chip enabled, but */
237 err
= gpio_request_array(_mandatory_gpio
, ARRAY_SIZE(_mandatory_gpio
));
241 /* Scan to find existence of the device */
242 if (nand_scan(ams_delta_mtd
, 1)) {
247 /* Register the partitions */
248 mtd_device_register(ams_delta_mtd
, partition_info
,
249 ARRAY_SIZE(partition_info
));
254 gpio_free_array(_mandatory_gpio
, ARRAY_SIZE(_mandatory_gpio
));
256 gpio_free(AMS_DELTA_GPIO_PIN_NAND_RB
);
259 kfree(ams_delta_mtd
);
267 static int ams_delta_cleanup(struct platform_device
*pdev
)
269 void __iomem
*io_base
= platform_get_drvdata(pdev
);
271 /* Release resources, unregister device */
272 nand_release(ams_delta_mtd
);
274 gpio_free_array(_mandatory_gpio
, ARRAY_SIZE(_mandatory_gpio
));
275 gpio_free(AMS_DELTA_GPIO_PIN_NAND_RB
);
278 /* Free the MTD device structure */
279 kfree(ams_delta_mtd
);
284 static struct platform_driver ams_delta_nand_driver
= {
285 .probe
= ams_delta_init
,
286 .remove
= ams_delta_cleanup
,
288 .name
= "ams-delta-nand",
292 module_platform_driver(ams_delta_nand_driver
);
294 MODULE_LICENSE("GPL");
295 MODULE_AUTHOR("Jonathan McDowell <noodles@earth.li>");
296 MODULE_DESCRIPTION("Glue layer for NAND flash on Amstrad E3 (Delta)");