fix dependency problem
[openwrt.git] / target / linux / brcm-2.4 / patches / 004-flash.patch
1 diff -Nur linux-2.4.32/drivers/mtd/devices/Config.in linux-2.4.32-flash/drivers/mtd/devices/Config.in
2 --- linux-2.4.32/drivers/mtd/devices/Config.in 2003-06-13 16:51:34.000000000 +0200
3 +++ linux-2.4.32-flash/drivers/mtd/devices/Config.in 2006-03-27 17:10:51.000000000 +0200
4 @@ -5,6 +5,7 @@
5 mainmenu_option next_comment
6
7 comment 'Self-contained MTD device drivers'
8 +bool ' Broadcom Chipcommon Serial Flash support' CONFIG_MTD_SFLASH
9 dep_tristate ' Ramix PMC551 PCI Mezzanine RAM card support' CONFIG_MTD_PMC551 $CONFIG_MTD $CONFIG_PCI
10 if [ "$CONFIG_MTD_PMC551" = "y" -o "$CONFIG_MTD_PMC551" = "m" ]; then
11 bool ' PMC551 256M DRAM Bugfix' CONFIG_MTD_PMC551_BUGFIX
12 diff -Nur linux-2.4.32/drivers/mtd/devices/Makefile linux-2.4.32-flash/drivers/mtd/devices/Makefile
13 --- linux-2.4.32/drivers/mtd/devices/Makefile 2002-11-29 00:53:13.000000000 +0100
14 +++ linux-2.4.32-flash/drivers/mtd/devices/Makefile 2006-03-27 17:10:51.000000000 +0200
15 @@ -3,6 +3,8 @@
16 #
17 # $Id: Makefile,v 1.4 2001/06/26 21:10:05 spse Exp $
18
19 +EXTRA_CFLAGS := -I$(TOPDIR)/arch/mips/bcm947xx/include
20 +
21 O_TARGET := devlink.o
22
23 # *** BIG UGLY NOTE ***
24 @@ -12,6 +14,7 @@
25 # here where previously there was none. We now have to ensure that
26 # doc200[01].o are linked before docprobe.o
27
28 +obj-$(CONFIG_MTD_SFLASH) += sflash.o
29 obj-$(CONFIG_MTD_DOC1000) += doc1000.o
30 obj-$(CONFIG_MTD_DOC2000) += doc2000.o
31 obj-$(CONFIG_MTD_DOC2001) += doc2001.o
32 diff -Nur linux-2.4.32/drivers/mtd/devices/sflash.c linux-2.4.32-flash/drivers/mtd/devices/sflash.c
33 --- linux-2.4.32/drivers/mtd/devices/sflash.c 1970-01-01 01:00:00.000000000 +0100
34 +++ linux-2.4.32-flash/drivers/mtd/devices/sflash.c 2006-03-27 17:10:51.000000000 +0200
35 @@ -0,0 +1,298 @@
36 +/*
37 + * Broadcom SiliconBackplane chipcommon serial flash interface
38 + *
39 + * Copyright 2001-2003, Broadcom Corporation
40 + * All Rights Reserved.
41 + *
42 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
43 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
44 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
45 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
46 + *
47 + * $Id: sflash.c,v 1.1.1.3 2003/11/10 17:43:38 hyin Exp $
48 + */
49 +
50 +#include <linux/config.h>
51 +#include <linux/module.h>
52 +#include <linux/slab.h>
53 +#include <linux/ioport.h>
54 +#include <linux/mtd/compatmac.h>
55 +#include <linux/mtd/mtd.h>
56 +#include <linux/mtd/partitions.h>
57 +#include <linux/errno.h>
58 +#include <linux/pci.h>
59 +#include <linux/delay.h>
60 +#include <asm/io.h>
61 +
62 +#ifdef CONFIG_MTD_PARTITIONS
63 +#include <linux/mtd/mtd.h>
64 +#include <linux/mtd/partitions.h>
65 +#include <linux/minix_fs.h>
66 +#include <linux/ext2_fs.h>
67 +#include <linux/romfs_fs.h>
68 +#include <linux/cramfs_fs.h>
69 +#include <linux/jffs2.h>
70 +#endif
71 +
72 +#include <typedefs.h>
73 +#include <bcmdevs.h>
74 +#include <bcmutils.h>
75 +#include <osl.h>
76 +#include <bcmutils.h>
77 +#include <bcmnvram.h>
78 +#include <sbconfig.h>
79 +#include <sbchipc.h>
80 +#include <sflash.h>
81 +#include <trxhdr.h>
82 +
83 +#ifdef CONFIG_MTD_PARTITIONS
84 +extern struct mtd_partition * init_mtd_partitions(struct mtd_info *mtd, size_t size);
85 +#endif
86 +
87 +struct sflash_mtd {
88 + chipcregs_t *cc;
89 + struct semaphore lock;
90 + struct mtd_info mtd;
91 + struct mtd_erase_region_info regions[1];
92 +};
93 +
94 +/* Private global state */
95 +static struct sflash_mtd sflash;
96 +
97 +static int
98 +sflash_mtd_poll(struct sflash_mtd *sflash, unsigned int offset, int timeout)
99 +{
100 + int now = jiffies;
101 + int ret = 0;
102 +
103 + for (;;) {
104 + if (!sflash_poll(sflash->cc, offset)) {
105 + ret = 0;
106 + break;
107 + }
108 + if (time_after(jiffies, now + timeout)) {
109 + printk(KERN_ERR "sflash: timeout\n");
110 + ret = -ETIMEDOUT;
111 + break;
112 + }
113 + if (current->need_resched) {
114 + set_current_state(TASK_UNINTERRUPTIBLE);
115 + schedule_timeout(timeout / 10);
116 + } else
117 + udelay(1);
118 + }
119 +
120 + return ret;
121 +}
122 +
123 +static int
124 +sflash_mtd_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
125 +{
126 + struct sflash_mtd *sflash = (struct sflash_mtd *) mtd->priv;
127 + int bytes, ret = 0;
128 +
129 + /* Check address range */
130 + if (!len)
131 + return 0;
132 + if ((from + len) > mtd->size)
133 + return -EINVAL;
134 +
135 + down(&sflash->lock);
136 +
137 + *retlen = 0;
138 + while (len) {
139 + if ((bytes = sflash_read(sflash->cc, (uint) from, len, buf)) < 0) {
140 + ret = bytes;
141 + break;
142 + }
143 + from += (loff_t) bytes;
144 + len -= bytes;
145 + buf += bytes;
146 + *retlen += bytes;
147 + }
148 +
149 + up(&sflash->lock);
150 +
151 + return ret;
152 +}
153 +
154 +static int
155 +sflash_mtd_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf)
156 +{
157 + struct sflash_mtd *sflash = (struct sflash_mtd *) mtd->priv;
158 + int bytes, ret = 0;
159 +
160 + /* Check address range */
161 + if (!len)
162 + return 0;
163 + if ((to + len) > mtd->size)
164 + return -EINVAL;
165 +
166 + down(&sflash->lock);
167 +
168 + *retlen = 0;
169 + while (len) {
170 + if ((bytes = sflash_write(sflash->cc, (uint) to, len, buf)) < 0) {
171 + ret = bytes;
172 + break;
173 + }
174 + if ((ret = sflash_mtd_poll(sflash, (unsigned int) to, HZ / 10)))
175 + break;
176 + to += (loff_t) bytes;
177 + len -= bytes;
178 + buf += bytes;
179 + *retlen += bytes;
180 + }
181 +
182 + up(&sflash->lock);
183 +
184 + return ret;
185 +}
186 +
187 +static int
188 +sflash_mtd_erase(struct mtd_info *mtd, struct erase_info *erase)
189 +{
190 + struct sflash_mtd *sflash = (struct sflash_mtd *) mtd->priv;
191 + int i, j, ret = 0;
192 + unsigned int addr, len;
193 +
194 + /* Check address range */
195 + if (!erase->len)
196 + return 0;
197 + if ((erase->addr + erase->len) > mtd->size)
198 + return -EINVAL;
199 +
200 + addr = erase->addr;
201 + len = erase->len;
202 +
203 + down(&sflash->lock);
204 +
205 + /* Ensure that requested region is aligned */
206 + for (i = 0; i < mtd->numeraseregions; i++) {
207 + for (j = 0; j < mtd->eraseregions[i].numblocks; j++) {
208 + if (addr == mtd->eraseregions[i].offset + mtd->eraseregions[i].erasesize * j &&
209 + len >= mtd->eraseregions[i].erasesize) {
210 + if ((ret = sflash_erase(sflash->cc, addr)) < 0)
211 + break;
212 + if ((ret = sflash_mtd_poll(sflash, addr, 10 * HZ)))
213 + break;
214 + addr += mtd->eraseregions[i].erasesize;
215 + len -= mtd->eraseregions[i].erasesize;
216 + }
217 + }
218 + if (ret)
219 + break;
220 + }
221 +
222 + up(&sflash->lock);
223 +
224 + /* Set erase status */
225 + if (ret)
226 + erase->state = MTD_ERASE_FAILED;
227 + else
228 + erase->state = MTD_ERASE_DONE;
229 +
230 + /* Call erase callback */
231 + if (erase->callback)
232 + erase->callback(erase);
233 +
234 + return ret;
235 +}
236 +
237 +#if LINUX_VERSION_CODE < 0x20212 && defined(MODULE)
238 +#define sflash_mtd_init init_module
239 +#define sflash_mtd_exit cleanup_module
240 +#endif
241 +
242 +mod_init_t
243 +sflash_mtd_init(void)
244 +{
245 + struct pci_dev *pdev;
246 + int ret = 0;
247 + struct sflash *info;
248 + uint bank, i;
249 +#ifdef CONFIG_MTD_PARTITIONS
250 + struct mtd_partition *parts;
251 +#endif
252 +
253 + if (!(pdev = pci_find_device(VENDOR_BROADCOM, SB_CC, NULL))) {
254 + printk(KERN_ERR "sflash: chipcommon not found\n");
255 + return -ENODEV;
256 + }
257 +
258 + memset(&sflash, 0, sizeof(struct sflash_mtd));
259 + init_MUTEX(&sflash.lock);
260 +
261 + /* Map registers and flash base */
262 + if (!(sflash.cc = ioremap_nocache(pci_resource_start(pdev, 0),
263 + pci_resource_len(pdev, 0)))) {
264 + printk(KERN_ERR "sflash: error mapping registers\n");
265 + ret = -EIO;
266 + goto fail;
267 + }
268 +
269 + /* Initialize serial flash access */
270 + info = sflash_init(sflash.cc);
271 +
272 + if (!info) {
273 + printk(KERN_ERR "sflash: found no supported devices\n");
274 + ret = -ENODEV;
275 + goto fail;
276 + }
277 +
278 + /* Setup banks */
279 + sflash.regions[0].offset = 0;
280 + sflash.regions[0].erasesize = info->blocksize;
281 + sflash.regions[0].numblocks = info->numblocks;
282 + if (sflash.regions[0].erasesize > sflash.mtd.erasesize)
283 + sflash.mtd.erasesize = sflash.regions[0].erasesize;
284 + if (sflash.regions[0].erasesize * sflash.regions[0].numblocks) {
285 + sflash.mtd.size += sflash.regions[0].erasesize * sflash.regions[0].numblocks;
286 + }
287 + sflash.mtd.numeraseregions = 1;
288 + ASSERT(sflash.mtd.size == info->size);
289 +
290 + /* Register with MTD */
291 + sflash.mtd.name = "sflash";
292 + sflash.mtd.type = MTD_NORFLASH;
293 + sflash.mtd.flags = MTD_CAP_NORFLASH;
294 + sflash.mtd.eraseregions = sflash.regions;
295 + sflash.mtd.module = THIS_MODULE;
296 + sflash.mtd.erase = sflash_mtd_erase;
297 + sflash.mtd.read = sflash_mtd_read;
298 + sflash.mtd.write = sflash_mtd_write;
299 + sflash.mtd.priv = &sflash;
300 +
301 +#ifdef CONFIG_MTD_PARTITIONS
302 + parts = init_mtd_partitions(&sflash.mtd, sflash.mtd.size);
303 + for (i = 0; parts[i].name; i++);
304 + ret = add_mtd_partitions(&sflash.mtd, parts, i);
305 +#else
306 + ret = add_mtd_device(&sflash.mtd);
307 +#endif
308 + if (ret) {
309 + printk(KERN_ERR "sflash: add_mtd failed\n");
310 + goto fail;
311 + }
312 +
313 + return 0;
314 +
315 + fail:
316 + if (sflash.cc)
317 + iounmap((void *) sflash.cc);
318 + return ret;
319 +}
320 +
321 +mod_exit_t
322 +sflash_mtd_exit(void)
323 +{
324 +#ifdef CONFIG_MTD_PARTITIONS
325 + del_mtd_partitions(&sflash.mtd);
326 +#else
327 + del_mtd_device(&sflash.mtd);
328 +#endif
329 + iounmap((void *) sflash.cc);
330 +}
331 +
332 +module_init(sflash_mtd_init);
333 +module_exit(sflash_mtd_exit);
334 diff -Nur linux-2.4.32/drivers/mtd/maps/bcm947xx-flash.c linux-2.4.32-flash/drivers/mtd/maps/bcm947xx-flash.c
335 --- linux-2.4.32/drivers/mtd/maps/bcm947xx-flash.c 1970-01-01 01:00:00.000000000 +0100
336 +++ linux-2.4.32-flash/drivers/mtd/maps/bcm947xx-flash.c 2006-03-27 17:07:27.000000000 +0200
337 @@ -0,0 +1,416 @@
338 +/*
339 + * Copyright (C) 2004 Florian Schirmer (jolt@tuxbox.org)
340 + * Copyright (C) 2005 Waldemar Brodkorb <wbx@openwrt.org>
341 + *
342 + * original functions for finding root filesystem from Mike Baker
343 + *
344 + * This program is free software; you can redistribute it and/or modify it
345 + * under the terms of the GNU General Public License as published by the
346 + * Free Software Foundation; either version 2 of the License, or (at your
347 + * option) any later version.
348 + *
349 + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
350 + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
351 + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
352 + * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
353 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
354 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
355 + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
356 + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
357 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
358 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
359 + *
360 + * You should have received a copy of the GNU General Public License along
361 + * with this program; if not, write to the Free Software Foundation, Inc.,
362 + * 675 Mass Ave, Cambridge, MA 02139, USA.
363 + *
364 + *
365 + * Copyright 2004, Broadcom Corporation
366 + * All Rights Reserved.
367 + *
368 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
369 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
370 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
371 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
372 + *
373 + * Flash mapping for BCM947XX boards
374 + *
375 + */
376 +
377 +#include <linux/module.h>
378 +#include <linux/types.h>
379 +#include <linux/kernel.h>
380 +#include <asm/io.h>
381 +#include <linux/mtd/mtd.h>
382 +#include <linux/mtd/map.h>
383 +#ifdef CONFIG_MTD_PARTITIONS
384 +#include <linux/mtd/partitions.h>
385 +#endif
386 +#include <linux/config.h>
387 +
388 +#include <typedefs.h>
389 +#include <osl.h>
390 +#include <bcmnvram.h>
391 +#include <bcmutils.h>
392 +#include <sbconfig.h>
393 +#include <sbchipc.h>
394 +#include <sbutils.h>
395 +#include <trxhdr.h>
396 +
397 +/* Global SB handle */
398 +extern void *bcm947xx_sbh;
399 +extern spinlock_t bcm947xx_sbh_lock;
400 +
401 +/* Convenience */
402 +#define sbh bcm947xx_sbh
403 +#define sbh_lock bcm947xx_sbh_lock
404 +
405 +#define WINDOW_ADDR 0x1fc00000
406 +#define WINDOW_SIZE 0x400000
407 +#define BUSWIDTH 2
408 +
409 +static struct mtd_info *bcm947xx_mtd;
410 +
411 +__u8 bcm947xx_map_read8(struct map_info *map, unsigned long ofs)
412 +{
413 + if (map->map_priv_2 == 1)
414 + return __raw_readb(map->map_priv_1 + ofs);
415 +
416 + u16 val = __raw_readw(map->map_priv_1 + (ofs & ~1));
417 + if (ofs & 1)
418 + return ((val >> 8) & 0xff);
419 + else
420 + return (val & 0xff);
421 +}
422 +
423 +__u16 bcm947xx_map_read16(struct map_info *map, unsigned long ofs)
424 +{
425 + return __raw_readw(map->map_priv_1 + ofs);
426 +}
427 +
428 +__u32 bcm947xx_map_read32(struct map_info *map, unsigned long ofs)
429 +{
430 + return __raw_readl(map->map_priv_1 + ofs);
431 +}
432 +
433 +void bcm947xx_map_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
434 +{
435 + if (len==1) {
436 + memcpy_fromio(to, map->map_priv_1 + from, len);
437 + } else {
438 + int i;
439 + u16 *dest = (u16 *) to;
440 + u16 *src = (u16 *) (map->map_priv_1 + from);
441 + for (i = 0; i < (len / 2); i++) {
442 + dest[i] = src[i];
443 + }
444 + if (len & 1)
445 + *((u8 *)dest+len-1) = src[i] & 0xff;
446 + }
447 +}
448 +
449 +void bcm947xx_map_write8(struct map_info *map, __u8 d, unsigned long adr)
450 +{
451 + __raw_writeb(d, map->map_priv_1 + adr);
452 + mb();
453 +}
454 +
455 +void bcm947xx_map_write16(struct map_info *map, __u16 d, unsigned long adr)
456 +{
457 + __raw_writew(d, map->map_priv_1 + adr);
458 + mb();
459 +}
460 +
461 +void bcm947xx_map_write32(struct map_info *map, __u32 d, unsigned long adr)
462 +{
463 + __raw_writel(d, map->map_priv_1 + adr);
464 + mb();
465 +}
466 +
467 +void bcm947xx_map_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
468 +{
469 + memcpy_toio(map->map_priv_1 + to, from, len);
470 +}
471 +
472 +struct map_info bcm947xx_map = {
473 + name: "Physically mapped flash",
474 + size: WINDOW_SIZE,
475 + buswidth: BUSWIDTH,
476 + read8: bcm947xx_map_read8,
477 + read16: bcm947xx_map_read16,
478 + read32: bcm947xx_map_read32,
479 + copy_from: bcm947xx_map_copy_from,
480 + write8: bcm947xx_map_write8,
481 + write16: bcm947xx_map_write16,
482 + write32: bcm947xx_map_write32,
483 + copy_to: bcm947xx_map_copy_to
484 +};
485 +
486 +#ifdef CONFIG_MTD_PARTITIONS
487 +
488 +static struct mtd_partition bcm947xx_parts[] = {
489 + { name: "cfe", offset: 0, size: 0, mask_flags: MTD_WRITEABLE, },
490 + { name: "linux", offset: 0, size: 0, },
491 + { name: "rootfs", offset: 0, size: 0, },
492 + { name: "nvram", offset: 0, size: 0, },
493 + { name: "OpenWrt", offset: 0, size: 0, },
494 + { name: NULL, },
495 +};
496 +
497 +static int __init
498 +find_cfe_size(struct mtd_info *mtd, size_t size)
499 +{
500 + struct trx_header *trx;
501 + unsigned char buf[512];
502 + int off;
503 + size_t len;
504 + int blocksize;
505 +
506 + trx = (struct trx_header *) buf;
507 +
508 + blocksize = mtd->erasesize;
509 + if (blocksize < 0x10000)
510 + blocksize = 0x10000;
511 +
512 + for (off = (128*1024); off < size; off += blocksize) {
513 + memset(buf, 0xe5, sizeof(buf));
514 +
515 + /*
516 + * Read into buffer
517 + */
518 + if (MTD_READ(mtd, off, sizeof(buf), &len, buf) ||
519 + len != sizeof(buf))
520 + continue;
521 +
522 + /* found a TRX header */
523 + if (le32_to_cpu(trx->magic) == TRX_MAGIC) {
524 + goto done;
525 + }
526 + }
527 +
528 + printk(KERN_NOTICE
529 + "%s: Couldn't find bootloader size\n",
530 + mtd->name);
531 + return -1;
532 +
533 + done:
534 + printk(KERN_NOTICE "bootloader size: %d\n", off);
535 + return off;
536 +
537 +}
538 +
539 +static int __init
540 +find_root(struct mtd_info *mtd, size_t size, struct mtd_partition *part)
541 +{
542 + struct trx_header *trx;
543 + unsigned char buf[512];
544 + int off;
545 + size_t len;
546 + int blocksize;
547 +
548 + trx = (struct trx_header *) buf;
549 +
550 + blocksize = mtd->erasesize;
551 + if (blocksize < 0x10000)
552 + blocksize = 0x10000;
553 +
554 + for (off = (128*1024); off < size; off += blocksize) {
555 + memset(buf, 0xe5, sizeof(buf));
556 +
557 + /*
558 + * Read into buffer
559 + */
560 + if (MTD_READ(mtd, off, sizeof(buf), &len, buf) ||
561 + len != sizeof(buf))
562 + continue;
563 +
564 + /* found a TRX header */
565 + if (le32_to_cpu(trx->magic) == TRX_MAGIC) {
566 + part->offset = le32_to_cpu(trx->offsets[2]) ? :
567 + le32_to_cpu(trx->offsets[1]);
568 + part->size = le32_to_cpu(trx->len);
569 +
570 + part->size -= part->offset;
571 + part->offset += off;
572 +
573 + goto done;
574 + }
575 + }
576 +
577 + printk(KERN_NOTICE
578 + "%s: Couldn't find root filesystem\n",
579 + mtd->name);
580 + return -1;
581 +
582 + done:
583 + return part->size;
584 +}
585 +
586 +struct mtd_partition * __init
587 +init_mtd_partitions(struct mtd_info *mtd, size_t size)
588 +{
589 +
590 + int cfe_size;
591 +
592 + cfe_size = find_cfe_size(mtd,size);
593 +
594 + /* boot loader */
595 + bcm947xx_parts[0].offset = 0;
596 + bcm947xx_parts[0].size = cfe_size;
597 +
598 + /* nvram */
599 + if (cfe_size != 384 * 1024) {
600 + bcm947xx_parts[3].offset = size - ROUNDUP(NVRAM_SPACE, mtd->erasesize);
601 + bcm947xx_parts[3].size = ROUNDUP(NVRAM_SPACE, mtd->erasesize);
602 + } else {
603 + /* nvram (old 128kb config partition on netgear wgt634u) */
604 + bcm947xx_parts[3].offset = bcm947xx_parts[0].size;
605 + bcm947xx_parts[3].size = ROUNDUP(NVRAM_SPACE, mtd->erasesize);
606 + }
607 +
608 + /* linux (kernel and rootfs) */
609 + if (cfe_size != 384 * 1024) {
610 + bcm947xx_parts[1].offset = bcm947xx_parts[0].size;
611 + bcm947xx_parts[1].size = bcm947xx_parts[3].offset -
612 + bcm947xx_parts[1].offset;
613 + } else {
614 + /* do not count the elf loader, which is on one block */
615 + bcm947xx_parts[1].offset = bcm947xx_parts[0].size +
616 + bcm947xx_parts[3].size + mtd->erasesize;
617 + bcm947xx_parts[1].size = size -
618 + bcm947xx_parts[0].size -
619 + (2*bcm947xx_parts[3].size) -
620 + mtd->erasesize;
621 + }
622 +
623 + /* find and size rootfs */
624 + if (find_root(mtd,size,&bcm947xx_parts[2])==0) {
625 + /* entirely jffs2 */
626 + bcm947xx_parts[4].name = NULL;
627 + bcm947xx_parts[2].size = size - bcm947xx_parts[2].offset -
628 + bcm947xx_parts[3].size;
629 + } else {
630 + /* legacy setup */
631 + /* calculate leftover flash, and assign it to the jffs2 partition */
632 + if (cfe_size != 384 * 1024) {
633 + bcm947xx_parts[4].offset = bcm947xx_parts[2].offset +
634 + bcm947xx_parts[2].size;
635 + if ((bcm947xx_parts[4].offset % mtd->erasesize) > 0) {
636 + bcm947xx_parts[4].offset += mtd->erasesize -
637 + (bcm947xx_parts[4].offset % mtd->erasesize);
638 + }
639 + bcm947xx_parts[4].size = bcm947xx_parts[3].offset -
640 + bcm947xx_parts[4].offset;
641 + } else {
642 + bcm947xx_parts[4].offset = bcm947xx_parts[2].offset +
643 + bcm947xx_parts[2].size;
644 + if ((bcm947xx_parts[4].offset % mtd->erasesize) > 0) {
645 + bcm947xx_parts[4].offset += mtd->erasesize -
646 + (bcm947xx_parts[4].offset % mtd->erasesize);
647 + }
648 + bcm947xx_parts[4].size = size - bcm947xx_parts[3].size -
649 + bcm947xx_parts[4].offset;
650 + }
651 + }
652 +
653 + return bcm947xx_parts;
654 +}
655 +
656 +#endif
657 +
658 +
659 +mod_init_t init_bcm947xx_map(void)
660 +{
661 + ulong flags;
662 + uint coreidx;
663 + chipcregs_t *cc;
664 + uint32 fltype;
665 + uint window_addr = 0, window_size = 0;
666 + size_t size;
667 + int ret = 0;
668 +#ifdef CONFIG_MTD_PARTITIONS
669 + struct mtd_partition *parts;
670 + int i;
671 +#endif
672 +
673 + spin_lock_irqsave(&sbh_lock, flags);
674 + coreidx = sb_coreidx(sbh);
675 +
676 + /* Check strapping option if chipcommon exists */
677 + if ((cc = sb_setcore(sbh, SB_CC, 0))) {
678 + fltype = readl(&cc->capabilities) & CAP_FLASH_MASK;
679 + if (fltype == PFLASH) {
680 + bcm947xx_map.map_priv_2 = 1;
681 + window_addr = 0x1c000000;
682 + bcm947xx_map.size = window_size = 32 * 1024 * 1024;
683 + if ((readl(&cc->flash_config) & CC_CFG_DS) == 0)
684 + bcm947xx_map.buswidth = 1;
685 + }
686 + } else {
687 + fltype = PFLASH;
688 + bcm947xx_map.map_priv_2 = 0;
689 + window_addr = WINDOW_ADDR;
690 + window_size = WINDOW_SIZE;
691 + }
692 +
693 + sb_setcoreidx(sbh, coreidx);
694 + spin_unlock_irqrestore(&sbh_lock, flags);
695 +
696 + if (fltype != PFLASH) {
697 + printk(KERN_ERR "pflash: found no supported devices\n");
698 + ret = -ENODEV;
699 + goto fail;
700 + }
701 +
702 + bcm947xx_map.map_priv_1 = (unsigned long) ioremap(window_addr, window_size);
703 +
704 + if (!bcm947xx_map.map_priv_1) {
705 + printk(KERN_ERR "Failed to ioremap\n");
706 + return -EIO;
707 + }
708 +
709 + if (!(bcm947xx_mtd = do_map_probe("cfi_probe", &bcm947xx_map))) {
710 + printk(KERN_ERR "pflash: cfi_probe failed\n");
711 + iounmap((void *)bcm947xx_map.map_priv_1);
712 + return -ENXIO;
713 + }
714 +
715 + bcm947xx_mtd->module = THIS_MODULE;
716 +
717 + size = bcm947xx_mtd->size;
718 +
719 + printk(KERN_NOTICE "Flash device: 0x%x at 0x%x\n", size, window_addr);
720 +
721 +#ifdef CONFIG_MTD_PARTITIONS
722 + parts = init_mtd_partitions(bcm947xx_mtd, size);
723 + for (i = 0; parts[i].name; i++);
724 + ret = add_mtd_partitions(bcm947xx_mtd, parts, i);
725 + if (ret) {
726 + printk(KERN_ERR "Flash: add_mtd_partitions failed\n");
727 + goto fail;
728 + }
729 +#endif
730 +
731 + return 0;
732 +
733 + fail:
734 + if (bcm947xx_mtd)
735 + map_destroy(bcm947xx_mtd);
736 + if (bcm947xx_map.map_priv_1)
737 + iounmap((void *) bcm947xx_map.map_priv_1);
738 + bcm947xx_map.map_priv_1 = 0;
739 + return ret;
740 +}
741 +
742 +mod_exit_t cleanup_bcm947xx_map(void)
743 +{
744 +#ifdef CONFIG_MTD_PARTITIONS
745 + del_mtd_partitions(bcm947xx_mtd);
746 +#endif
747 + map_destroy(bcm947xx_mtd);
748 + iounmap((void *) bcm947xx_map.map_priv_1);
749 + bcm947xx_map.map_priv_1 = 0;
750 +}
751 +
752 +module_init(init_bcm947xx_map);
753 +module_exit(cleanup_bcm947xx_map);
754 diff -Nur linux-2.4.32/drivers/mtd/maps/Config.in linux-2.4.32-flash/drivers/mtd/maps/Config.in
755 --- linux-2.4.32/drivers/mtd/maps/Config.in 2003-06-13 16:51:34.000000000 +0200
756 +++ linux-2.4.32-flash/drivers/mtd/maps/Config.in 2006-01-31 22:03:50.000000000 +0100
757 @@ -48,6 +48,7 @@
758 fi
759
760 if [ "$CONFIG_MIPS" = "y" ]; then
761 + dep_tristate ' CFI Flash device mapped on Broadcom BCM947XX boards' CONFIG_MTD_BCM947XX $CONFIG_MTD_CFI
762 dep_tristate ' Pb1000 MTD support' CONFIG_MTD_PB1000 $CONFIG_MIPS_PB1000
763 dep_tristate ' Pb1500 MTD support' CONFIG_MTD_PB1500 $CONFIG_MIPS_PB1500
764 dep_tristate ' Pb1100 MTD support' CONFIG_MTD_PB1100 $CONFIG_MIPS_PB1100
765 diff -Nur linux-2.4.32/drivers/mtd/maps/Makefile linux-2.4.32-flash/drivers/mtd/maps/Makefile
766 --- linux-2.4.32/drivers/mtd/maps/Makefile 2003-06-13 16:51:34.000000000 +0200
767 +++ linux-2.4.32-flash/drivers/mtd/maps/Makefile 2006-01-31 22:03:50.000000000 +0100
768 @@ -3,6 +3,8 @@
769 #
770 # $Id: Makefile,v 1.37 2003/01/24 14:26:38 dwmw2 Exp $
771
772 +EXTRA_CFLAGS := -I$(TOPDIR)/arch/mips/bcm947xx/include
773 +
774 BELOW25 := $(shell echo $(PATCHLEVEL) | sed s/[1234]/y/)
775
776 ifeq ($(BELOW25),y)
777 @@ -10,6 +12,7 @@
778 endif
779
780 # Chip mappings
781 +obj-$(CONFIG_MTD_BCM947XX) += bcm947xx-flash.o
782 obj-$(CONFIG_MTD_CDB89712) += cdb89712.o
783 obj-$(CONFIG_MTD_ARM_INTEGRATOR)+= integrator-flash.o
784 obj-$(CONFIG_MTD_CFI_FLAGADM) += cfi_flagadm.o
This page took 0.076774 seconds and 5 git commands to generate.