initial commit with v2.6.9
[linux-2.6.9-moxart.git] / drivers / mtd / maps / integrator-flash-v24.c
blob945d7c91001e04af25d2b6ee0e9aa034f3fc7b8e
1 /*======================================================================
3 drivers/mtd/maps/armflash.c: ARM Flash Layout/Partitioning
5 Copyright (C) 2000 ARM Limited
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 This is access code for flashes using ARM's flash partitioning
22 standards.
24 $Id: integrator-flash-v24.c,v 1.13 2004/07/12 21:59:44 dwmw2 Exp $
26 ======================================================================*/
28 #include <linux/config.h>
29 #include <linux/module.h>
30 #include <linux/types.h>
31 #include <linux/kernel.h>
32 #include <linux/slab.h>
33 #include <linux/ioport.h>
34 #include <linux/init.h>
36 #include <linux/mtd/mtd.h>
37 #include <linux/mtd/map.h>
38 #include <linux/mtd/partitions.h>
40 #include <asm/hardware.h>
41 #include <asm/io.h>
42 #include <asm/system.h>
44 // board specific stuff - sorry, it should be in arch/arm/mach-*.
45 #ifdef CONFIG_ARCH_INTEGRATOR
47 #define FLASH_BASE INTEGRATOR_FLASH_BASE
48 #define FLASH_SIZE INTEGRATOR_FLASH_SIZE
50 #define FLASH_PART_SIZE 0x400000
52 #define SC_CTRLC (IO_ADDRESS(INTEGRATOR_SC_BASE) + INTEGRATOR_SC_CTRLC_OFFSET)
53 #define SC_CTRLS (IO_ADDRESS(INTEGRATOR_SC_BASE) + INTEGRATOR_SC_CTRLS_OFFSET)
54 #define EBI_CSR1 (IO_ADDRESS(INTEGRATOR_EBI_BASE) + INTEGRATOR_EBI_CSR1_OFFSET)
55 #define EBI_LOCK (IO_ADDRESS(INTEGRATOR_EBI_BASE) + INTEGRATOR_EBI_LOCK_OFFSET)
58 * Initialise the flash access systems:
59 * - Disable VPP
60 * - Assert WP
61 * - Set write enable bit in EBI reg
63 static void armflash_flash_init(void)
65 unsigned int tmp;
67 __raw_writel(INTEGRATOR_SC_CTRL_nFLVPPEN | INTEGRATOR_SC_CTRL_nFLWP, SC_CTRLC);
69 tmp = __raw_readl(EBI_CSR1) | INTEGRATOR_EBI_WRITE_ENABLE;
70 __raw_writel(tmp, EBI_CSR1);
72 if (!(__raw_readl(EBI_CSR1) & INTEGRATOR_EBI_WRITE_ENABLE)) {
73 __raw_writel(0xa05f, EBI_LOCK);
74 __raw_writel(tmp, EBI_CSR1);
75 __raw_writel(0, EBI_LOCK);
80 * Shutdown the flash access systems:
81 * - Disable VPP
82 * - Assert WP
83 * - Clear write enable bit in EBI reg
85 static void armflash_flash_exit(void)
87 unsigned int tmp;
89 __raw_writel(INTEGRATOR_SC_CTRL_nFLVPPEN | INTEGRATOR_SC_CTRL_nFLWP, SC_CTRLC);
92 * Clear the write enable bit in system controller EBI register.
94 tmp = __raw_readl(EBI_CSR1) & ~INTEGRATOR_EBI_WRITE_ENABLE;
95 __raw_writel(tmp, EBI_CSR1);
97 if (__raw_readl(EBI_CSR1) & INTEGRATOR_EBI_WRITE_ENABLE) {
98 __raw_writel(0xa05f, EBI_LOCK);
99 __raw_writel(tmp, EBI_CSR1);
100 __raw_writel(0, EBI_LOCK);
104 static void armflash_flash_wp(int on)
106 unsigned int reg;
108 if (on)
109 reg = SC_CTRLC;
110 else
111 reg = SC_CTRLS;
113 __raw_writel(INTEGRATOR_SC_CTRL_nFLWP, reg);
116 static void armflash_set_vpp(struct map_info *map, int on)
118 unsigned int reg;
120 if (on)
121 reg = SC_CTRLS;
122 else
123 reg = SC_CTRLC;
125 __raw_writel(INTEGRATOR_SC_CTRL_nFLVPPEN, reg);
127 #endif
129 #ifdef CONFIG_ARCH_P720T
131 #define FLASH_BASE (0x04000000)
132 #define FLASH_SIZE (64*1024*1024)
134 #define FLASH_PART_SIZE (4*1024*1024)
135 #define FLASH_BLOCK_SIZE (128*1024)
137 static void armflash_flash_init(void)
141 static void armflash_flash_exit(void)
145 static void armflash_flash_wp(int on)
149 static void armflash_set_vpp(struct map_info *map, int on)
152 #endif
155 static struct map_info armflash_map =
157 .name = "AFS",
158 .set_vpp = armflash_set_vpp,
159 .phys = FLASH_BASE,
162 static struct mtd_info *mtd;
163 static struct mtd_partition *parts;
164 static const char *probes[] = { "RedBoot", "afs", NULL };
166 static int __init armflash_cfi_init(void *base, u_int size)
168 int ret;
170 armflash_flash_init();
171 armflash_flash_wp(1);
174 * look for CFI based flash parts fitted to this board
176 armflash_map.size = size;
177 armflash_map.bankwidth = 4;
178 armflash_map.virt = (unsigned long) base;
180 simple_map_init(&armflash_map);
183 * Also, the CFI layer automatically works out what size
184 * of chips we have, and does the necessary identification
185 * for us automatically.
187 mtd = do_map_probe("cfi_probe", &armflash_map);
188 if (!mtd)
189 return -ENXIO;
191 mtd->owner = THIS_MODULE;
193 ret = parse_mtd_partitions(mtd, probes, &parts, (void *)0);
194 if (ret > 0) {
195 ret = add_mtd_partitions(mtd, parts, ret);
196 if (ret)
197 printk(KERN_ERR "mtd partition registration "
198 "failed: %d\n", ret);
202 * If we got an error, free all resources.
204 if (ret < 0) {
205 del_mtd_partitions(mtd);
206 map_destroy(mtd);
209 return ret;
212 static void armflash_cfi_exit(void)
214 if (mtd) {
215 del_mtd_partitions(mtd);
216 map_destroy(mtd);
218 if (parts)
219 kfree(parts);
222 static int __init armflash_init(void)
224 int err = -EBUSY;
225 void *base;
227 if (request_mem_region(FLASH_BASE, FLASH_SIZE, "flash") == NULL)
228 goto out;
230 base = ioremap(FLASH_BASE, FLASH_SIZE);
231 err = -ENOMEM;
232 if (base == NULL)
233 goto release;
235 err = armflash_cfi_init(base, FLASH_SIZE);
236 if (err) {
237 iounmap(base);
238 release:
239 release_mem_region(FLASH_BASE, FLASH_SIZE);
241 out:
242 return err;
245 static void __exit armflash_exit(void)
247 armflash_cfi_exit();
248 iounmap((void *)armflash_map.virt);
249 release_mem_region(FLASH_BASE, FLASH_SIZE);
250 armflash_flash_exit();
253 module_init(armflash_init);
254 module_exit(armflash_exit);
256 MODULE_AUTHOR("ARM Ltd");
257 MODULE_DESCRIPTION("ARM Integrator CFI map driver");
258 MODULE_LICENSE("GPL");