sync with brcm
[openwrt.git] / openwrt / target / linux / linux-2.6 / patches / brcm / 003-flash-map.patch
1 diff -Nur linux-2.6.12.5/drivers/mtd/maps/Kconfig linux-2.6.12.5-flash/drivers/mtd/maps/Kconfig
2 --- linux-2.6.12.5/drivers/mtd/maps/Kconfig 2005-08-15 02:20:18.000000000 +0200
3 +++ linux-2.6.12.5-flash/drivers/mtd/maps/Kconfig 2005-09-16 22:27:36.513533784 +0200
4 @@ -357,6 +357,12 @@
5 Mapping for the Flaga digital module. If you don't have one, ignore
6 this setting.
7
8 +config MTD_BCM47XX
9 + tristate "BCM47xx flash device"
10 + depends on MIPS && MTD_CFI && BCM947XX
11 + help
12 + Support for the flash chips on the BCM947xx board.
13 +
14 config MTD_BEECH
15 tristate "CFI Flash device mapped on IBM 405LP Beech"
16 depends on MTD_CFI && PPC32 && 40x && BEECH
17 diff -Nur linux-2.6.12.5/drivers/mtd/maps/Makefile linux-2.6.12.5-flash/drivers/mtd/maps/Makefile
18 --- linux-2.6.12.5/drivers/mtd/maps/Makefile 2005-08-15 02:20:18.000000000 +0200
19 +++ linux-2.6.12.5-flash/drivers/mtd/maps/Makefile 2005-09-16 22:27:01.110915800 +0200
20 @@ -31,6 +31,7 @@
21 obj-$(CONFIG_MTD_PCMCIA) += pcmciamtd.o
22 obj-$(CONFIG_MTD_RPXLITE) += rpxlite.o
23 obj-$(CONFIG_MTD_TQM8XXL) += tqm8xxl.o
24 +obj-$(CONFIG_MTD_BCM47XX) += bcm47xx-flash.o
25 obj-$(CONFIG_MTD_SA1100) += sa1100-flash.o
26 obj-$(CONFIG_MTD_IPAQ) += ipaq-flash.o
27 obj-$(CONFIG_MTD_SBC_GXX) += sbc_gxx.o
28 diff -Nur linux-2.6.12.5/drivers/mtd/maps/bcm47xx-flash.c linux-2.6.12.5-flash/drivers/mtd/maps/bcm47xx-flash.c
29 --- linux-2.6.12.5/drivers/mtd/maps/bcm47xx-flash.c 1970-01-01 01:00:00.000000000 +0100
30 +++ linux-2.6.12.5-flash/drivers/mtd/maps/bcm47xx-flash.c 2005-09-16 22:26:41.470901536 +0200
31 @@ -0,0 +1,249 @@
32 +/*
33 + * Copyright (C) 2004 Florian Schirmer (jolt@tuxbox.org)
34 + * Copyright (C) 2005 Waldemar Brodkorb <wbx@openwrt.org>
35 + *
36 + * original functions for finding root filesystem from Mike Baker
37 + *
38 + * This program is free software; you can redistribute it and/or modify it
39 + * under the terms of the GNU General Public License as published by the
40 + * Free Software Foundation; either version 2 of the License, or (at your
41 + * option) any later version.
42 + *
43 + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
44 + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
45 + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
46 + * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
47 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
49 + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
50 + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
51 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
52 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53 + *
54 + * You should have received a copy of the GNU General Public License along
55 + * with this program; if not, write to the Free Software Foundation, Inc.,
56 + * 675 Mass Ave, Cambridge, MA 02139, USA.
57 + *
58 + * Copyright 2001-2003, Broadcom Corporation
59 + * All Rights Reserved.
60 + *
61 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
62 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
63 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
64 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
65 + *
66 + * $Id$
67 + *
68 + * Flash mapping for BCM947XX boards
69 + */
70 +
71 +#include <linux/init.h>
72 +#include <linux/module.h>
73 +#include <linux/types.h>
74 +#include <linux/kernel.h>
75 +#include <asm/io.h>
76 +#include <linux/mtd/mtd.h>
77 +#include <linux/mtd/map.h>
78 +#include <linux/mtd/partitions.h>
79 +#include <linux/config.h>
80 +#include <typedefs.h>
81 +#include <bcmutils.h>
82 +#include <bcmnvram.h>
83 +#include <trxhdr.h>
84 +
85 +#ifdef CONFIG_MTD_PARTITIONS
86 +extern struct mtd_partition * init_mtd_partitions(struct mtd_info *mtd, size_t size);
87 +#endif
88 +
89 +#define CFE_SIZE 1024*384
90 +#define NVRAM_SIZE 1024*128
91 +
92 +#define WINDOW_ADDR 0x1c000000
93 +#define WINDOW_SIZE (0x400000*2)
94 +#define BUSWIDTH 2
95 +
96 +static struct mtd_info *bcm947xx_mtd;
97 +
98 +static void bcm947xx_map_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
99 +{
100 +#define MIPS_MEMCPY_ALIGN 4
101 + map_word ret;
102 + ssize_t transfer;
103 + ssize_t done = 0;
104 + if ((len >= MIPS_MEMCPY_ALIGN) && (!(from & (MIPS_MEMCPY_ALIGN - 1))) && (!(((unsigned int)to & (MIPS_MEMCPY_ALIGN - 1))))) {
105 + done = len & ~(MIPS_MEMCPY_ALIGN - 1);
106 + memcpy_fromio(to, map->virt + from, done);
107 + }
108 + while (done < len) {
109 + ret = map->read(map, from + done);
110 + transfer = len - done;
111 + if (transfer > map->bankwidth)
112 + transfer = map->bankwidth;
113 + memcpy((void *)((unsigned long)to + done), &ret.x[0], transfer);
114 + done += transfer;
115 + }
116 +}
117 +
118 +static struct map_info bcm947xx_map = {
119 + name: "Physically mapped flash",
120 + size: WINDOW_SIZE,
121 + bankwidth: BUSWIDTH,
122 + phys: WINDOW_ADDR,
123 +};
124 +
125 +#ifdef CONFIG_MTD_PARTITIONS
126 +
127 +static struct mtd_partition bcm947xx_parts[] = {
128 + { name: "cfe", offset: 0, size: 0, mask_flags: MTD_WRITEABLE, },
129 + { name: "linux", offset: 0, size: 0, },
130 + { name: "rootfs", offset: 0, size: 0, },
131 + { name: "nvram", offset: 0, size: 0, },
132 + { name: "OpenWrt", offset: 0, size: 0, },
133 + { name: NULL, },
134 +};
135 +
136 +static int __init
137 +find_root(struct mtd_info *mtd, size_t size, struct mtd_partition *part)
138 +{
139 + struct trx_header *trx;
140 + unsigned char buf[512];
141 + int off;
142 + size_t len;
143 +
144 + trx = (struct trx_header *) buf;
145 +
146 + for (off = (256*1024); off < size; off += mtd->erasesize) {
147 + memset(buf, 0xe5, sizeof(buf));
148 +
149 + /*
150 + * Read into buffer
151 + */
152 + if (MTD_READ(mtd, off, sizeof(buf), &len, buf) ||
153 + len != sizeof(buf))
154 + continue;
155 +
156 + /* found a TRX header */
157 + if (le32_to_cpu(trx->magic) == TRX_MAGIC) {
158 + part->offset = le32_to_cpu(trx->offsets[2]) ? :
159 + le32_to_cpu(trx->offsets[1]);
160 + part->size = le32_to_cpu(trx->len);
161 +
162 + part->size -= part->offset;
163 + part->offset += off;
164 +
165 + goto done;
166 + }
167 + }
168 +
169 + printk(KERN_NOTICE
170 + "%s: Couldn't find root filesystem\n",
171 + mtd->name);
172 + return -1;
173 +
174 + done:
175 + return part->size;
176 +}
177 +
178 +struct mtd_partition * __init
179 +init_mtd_partitions(struct mtd_info *mtd, size_t size)
180 +{
181 +
182 + /* boot loader */
183 + bcm947xx_parts[0].offset = 0;
184 + bcm947xx_parts[0].size = CFE_SIZE;
185 +
186 + /* nvram (old config partition) */
187 + bcm947xx_parts[3].offset = bcm947xx_parts[0].size;
188 + bcm947xx_parts[3].size = NVRAM_SIZE;
189 +
190 + /* Size linux (kernel and rootfs) */
191 + /* do not count the elf loader, which is on one sector */
192 + bcm947xx_parts[1].offset = bcm947xx_parts[0].size + bcm947xx_parts[3].size + mtd->erasesize;
193 + bcm947xx_parts[1].size = size - NVRAM_SIZE - bcm947xx_parts[0].size -
194 + bcm947xx_parts[3].size - mtd->erasesize;
195 +
196 + /* Find and size rootfs */
197 + if (find_root(mtd,size,&bcm947xx_parts[2])==0) {
198 + /* entirely jffs2 */
199 + bcm947xx_parts[2].size = size - bcm947xx_parts[2].offset - NVRAM_SIZE;
200 + bcm947xx_parts[4].name = NULL;
201 + } else {
202 + /* legacy setup */
203 + /* calculate leftover flash, and assign it to the jffs2 partition */
204 + bcm947xx_parts[4].offset = bcm947xx_parts[2].offset + bcm947xx_parts[2].size;
205 + if ((bcm947xx_parts[4].offset % mtd->erasesize) > 0) {
206 + bcm947xx_parts[4].offset += mtd->erasesize -
207 + (bcm947xx_parts[4].offset % mtd->erasesize);
208 + }
209 + bcm947xx_parts[4].size = size - NVRAM_SIZE - bcm947xx_parts[4].offset;
210 + }
211 +
212 + return bcm947xx_parts;
213 +}
214 +
215 +EXPORT_SYMBOL(init_mtd_partitions);
216 +#endif
217 +
218 +int __init init_bcm947xx_map(void)
219 +{
220 + size_t size;
221 + int ret = 0;
222 +#ifdef CONFIG_MTD_PARTITIONS
223 + struct mtd_partition *parts;
224 + int i;
225 +#endif
226 +
227 + bcm947xx_map.virt = ioremap(WINDOW_ADDR, WINDOW_SIZE);
228 +
229 + if (!bcm947xx_map.virt) {
230 + printk("Failed to ioremap\n");
231 + return -EIO;
232 + }
233 + simple_map_init(&bcm947xx_map);
234 +
235 + bcm947xx_map.copy_from = bcm947xx_map_copy_from;
236 +
237 + if (!(bcm947xx_mtd = do_map_probe("cfi_probe", &bcm947xx_map))) {
238 + printk("Failed to do_map_probe\n");
239 + iounmap((void *)bcm947xx_map.virt);
240 + return -ENXIO;
241 + }
242 +
243 + bcm947xx_mtd->owner = THIS_MODULE;
244 +
245 + size = bcm947xx_mtd->size;
246 +
247 + printk(KERN_NOTICE "Flash device: 0x%x at 0x%x\n", bcm947xx_mtd->size, WINDOW_ADDR);
248 +
249 +#ifdef CONFIG_MTD_PARTITIONS
250 + parts = init_mtd_partitions(bcm947xx_mtd, size);
251 + for (i = 0; parts[i].name; i++);
252 + ret = add_mtd_partitions(bcm947xx_mtd, parts, i);
253 + if (ret) {
254 + printk(KERN_ERR "Flash: add_mtd_partitions failed\n");
255 + goto fail;
256 + }
257 +#endif
258 +
259 + return 0;
260 +
261 + fail:
262 + if (bcm947xx_mtd)
263 + map_destroy(bcm947xx_mtd);
264 + if (bcm947xx_map.map_priv_1)
265 + iounmap((void *) bcm947xx_map.map_priv_1);
266 + bcm947xx_map.map_priv_1 = 0;
267 + return ret;
268 +}
269 +
270 +void __exit cleanup_bcm947xx_map(void)
271 +{
272 +#ifdef CONFIG_MTD_PARTITIONS
273 + del_mtd_partitions(bcm947xx_mtd);
274 +#endif
275 + map_destroy(bcm947xx_mtd);
276 + iounmap((void *)bcm947xx_map.virt);
277 +}
278 +
279 +module_init(init_bcm947xx_map);
280 +module_exit(cleanup_bcm947xx_map);
This page took 0.06473 seconds and 5 git commands to generate.