diff options
Diffstat (limited to 'drivers/mtd/maps/epxa10db-flash.c')
-rw-r--r-- | drivers/mtd/maps/epxa10db-flash.c | 176 |
1 files changed, 176 insertions, 0 deletions
diff --git a/drivers/mtd/maps/epxa10db-flash.c b/drivers/mtd/maps/epxa10db-flash.c new file mode 100644 index 000000000000..ab6dbe2b8cce --- /dev/null +++ b/drivers/mtd/maps/epxa10db-flash.c | |||
@@ -0,0 +1,176 @@ | |||
1 | /* | ||
2 | * Flash memory access on EPXA based devices | ||
3 | * | ||
4 | * (C) 2000 Nicolas Pitre <nico@cam.org> | ||
5 | * Copyright (C) 2001 Altera Corporation | ||
6 | * Copyright (C) 2001 Red Hat, Inc. | ||
7 | * | ||
8 | * $Id: epxa10db-flash.c,v 1.13 2004/11/04 13:24:14 gleixner Exp $ | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify | ||
11 | * it under the terms of the GNU General Public License as published by | ||
12 | * the Free Software Foundation; either version 2 of the License, or | ||
13 | * (at your option) any later version. | ||
14 | * | ||
15 | * This program is distributed in the hope that it will be useful, | ||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | * GNU General Public License for more details. | ||
19 | * | ||
20 | * You should have received a copy of the GNU General Public License | ||
21 | * along with this program; if not, write to the Free Software | ||
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
23 | */ | ||
24 | |||
25 | #include <linux/config.h> | ||
26 | #include <linux/module.h> | ||
27 | #include <linux/types.h> | ||
28 | #include <linux/kernel.h> | ||
29 | #include <linux/init.h> | ||
30 | #include <asm/io.h> | ||
31 | #include <linux/mtd/mtd.h> | ||
32 | #include <linux/mtd/map.h> | ||
33 | #include <linux/mtd/partitions.h> | ||
34 | |||
35 | #include <asm/hardware.h> | ||
36 | #ifdef CONFIG_EPXA10DB | ||
37 | #define BOARD_NAME "EPXA10DB" | ||
38 | #else | ||
39 | #define BOARD_NAME "EPXA1DB" | ||
40 | #endif | ||
41 | |||
42 | static int nr_parts = 0; | ||
43 | static struct mtd_partition *parts; | ||
44 | |||
45 | static struct mtd_info *mymtd; | ||
46 | |||
47 | static int epxa_default_partitions(struct mtd_info *master, struct mtd_partition **pparts); | ||
48 | |||
49 | |||
50 | static struct map_info epxa_map = { | ||
51 | .name = "EPXA flash", | ||
52 | .size = FLASH_SIZE, | ||
53 | .bankwidth = 2, | ||
54 | .phys = FLASH_START, | ||
55 | }; | ||
56 | |||
57 | static const char *probes[] = { "RedBoot", "afs", NULL }; | ||
58 | |||
59 | static int __init epxa_mtd_init(void) | ||
60 | { | ||
61 | int i; | ||
62 | |||
63 | printk(KERN_NOTICE "%s flash device: 0x%x at 0x%x\n", BOARD_NAME, FLASH_SIZE, FLASH_START); | ||
64 | |||
65 | epxa_map.virt = ioremap(FLASH_START, FLASH_SIZE); | ||
66 | if (!epxa_map.virt) { | ||
67 | printk("Failed to ioremap %s flash\n",BOARD_NAME); | ||
68 | return -EIO; | ||
69 | } | ||
70 | simple_map_init(&epxa_map); | ||
71 | |||
72 | mymtd = do_map_probe("cfi_probe", &epxa_map); | ||
73 | if (!mymtd) { | ||
74 | iounmap((void *)epxa_map.virt); | ||
75 | return -ENXIO; | ||
76 | } | ||
77 | |||
78 | mymtd->owner = THIS_MODULE; | ||
79 | |||
80 | /* Unlock the flash device. */ | ||
81 | if(mymtd->unlock){ | ||
82 | for (i=0; i<mymtd->numeraseregions;i++){ | ||
83 | int j; | ||
84 | for(j=0;j<mymtd->eraseregions[i].numblocks;j++){ | ||
85 | mymtd->unlock(mymtd,mymtd->eraseregions[i].offset + j * mymtd->eraseregions[i].erasesize,mymtd->eraseregions[i].erasesize); | ||
86 | } | ||
87 | } | ||
88 | } | ||
89 | |||
90 | #ifdef CONFIG_MTD_PARTITIONS | ||
91 | nr_parts = parse_mtd_partitions(mymtd, probes, &parts, 0); | ||
92 | |||
93 | if (nr_parts > 0) { | ||
94 | add_mtd_partitions(mymtd, parts, nr_parts); | ||
95 | return 0; | ||
96 | } | ||
97 | #endif | ||
98 | /* No recognised partitioning schemes found - use defaults */ | ||
99 | nr_parts = epxa_default_partitions(mymtd, &parts); | ||
100 | if (nr_parts > 0) { | ||
101 | add_mtd_partitions(mymtd, parts, nr_parts); | ||
102 | return 0; | ||
103 | } | ||
104 | |||
105 | /* If all else fails... */ | ||
106 | add_mtd_device(mymtd); | ||
107 | return 0; | ||
108 | } | ||
109 | |||
110 | static void __exit epxa_mtd_cleanup(void) | ||
111 | { | ||
112 | if (mymtd) { | ||
113 | if (nr_parts) | ||
114 | del_mtd_partitions(mymtd); | ||
115 | else | ||
116 | del_mtd_device(mymtd); | ||
117 | map_destroy(mymtd); | ||
118 | } | ||
119 | if (epxa_map.virt) { | ||
120 | iounmap((void *)epxa_map.virt); | ||
121 | epxa_map.virt = 0; | ||
122 | } | ||
123 | } | ||
124 | |||
125 | |||
126 | /* | ||
127 | * This will do for now, once we decide which bootldr we're finally | ||
128 | * going to use then we'll remove this function and do it properly | ||
129 | * | ||
130 | * Partions are currently (as offsets from base of flash): | ||
131 | * 0x00000000 - 0x003FFFFF - bootloader (!) | ||
132 | * 0x00400000 - 0x00FFFFFF - Flashdisk | ||
133 | */ | ||
134 | |||
135 | static int __init epxa_default_partitions(struct mtd_info *master, struct mtd_partition **pparts) | ||
136 | { | ||
137 | struct mtd_partition *parts; | ||
138 | int ret, i; | ||
139 | int npartitions = 0; | ||
140 | char *names; | ||
141 | const char *name = "jffs"; | ||
142 | |||
143 | printk("Using default partitions for %s\n",BOARD_NAME); | ||
144 | npartitions=1; | ||
145 | parts = kmalloc(npartitions*sizeof(*parts)+strlen(name), GFP_KERNEL); | ||
146 | memzero(parts,npartitions*sizeof(*parts)+strlen(name)); | ||
147 | if (!parts) { | ||
148 | ret = -ENOMEM; | ||
149 | goto out; | ||
150 | } | ||
151 | i=0; | ||
152 | names = (char *)&parts[npartitions]; | ||
153 | parts[i].name = names; | ||
154 | names += strlen(name) + 1; | ||
155 | strcpy(parts[i].name, name); | ||
156 | |||
157 | #ifdef CONFIG_EPXA10DB | ||
158 | parts[i].size = FLASH_SIZE-0x00400000; | ||
159 | parts[i].offset = 0x00400000; | ||
160 | #else | ||
161 | parts[i].size = FLASH_SIZE-0x00180000; | ||
162 | parts[i].offset = 0x00180000; | ||
163 | #endif | ||
164 | |||
165 | out: | ||
166 | *pparts = parts; | ||
167 | return npartitions; | ||
168 | } | ||
169 | |||
170 | |||
171 | module_init(epxa_mtd_init); | ||
172 | module_exit(epxa_mtd_cleanup); | ||
173 | |||
174 | MODULE_AUTHOR("Clive Davies"); | ||
175 | MODULE_DESCRIPTION("Altera epxa mtd flash map"); | ||
176 | MODULE_LICENSE("GPL"); | ||