1 diff -urN linux.old/drivers/mtd/devices/Config.in linux.dev/drivers/mtd/devices/Config.in
2 --- linux.old/drivers/mtd/devices/Config.in 2006-06-22 17:35:39.000000000 +0200
3 +++ linux.dev/drivers/mtd/devices/Config.in 2006-06-21 21:41:24.000000000 +0200
5 mainmenu_option next_comment
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 -urN linux.old/drivers/mtd/devices/Makefile linux.dev/drivers/mtd/devices/Makefile
13 --- linux.old/drivers/mtd/devices/Makefile 2006-06-22 17:35:39.000000000 +0200
14 +++ linux.dev/drivers/mtd/devices/Makefile 2006-06-21 21:41:24.000000000 +0200
17 # $Id: Makefile,v 1.4 2001/06/26 21:10:05 spse Exp $
19 +EXTRA_CFLAGS := -I$(TOPDIR)/arch/mips/bcm947xx/include
23 # *** BIG UGLY NOTE ***
25 # here where previously there was none. We now have to ensure that
26 # doc200[01].o are linked before docprobe.o
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 -urN linux.old/drivers/mtd/devices/sflash.c linux.dev/drivers/mtd/devices/sflash.c
33 --- linux.old/drivers/mtd/devices/sflash.c 1970-01-01 01:00:00.000000000 +0100
34 +++ linux.dev/drivers/mtd/devices/sflash.c 2006-06-21 21:41:24.000000000 +0200
37 + * Broadcom SiliconBackplane chipcommon serial flash interface
39 + * Copyright 2001-2003, Broadcom Corporation
40 + * All Rights Reserved.
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.
47 + * $Id: sflash.c,v 1.1.1.3 2003/11/10 17:43:38 hyin Exp $
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>
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>
72 +#include <typedefs.h>
74 +#include <bcmutils.h>
76 +#include <bcmutils.h>
77 +#include <bcmnvram.h>
78 +#include <sbconfig.h>
83 +#ifdef CONFIG_MTD_PARTITIONS
84 +extern struct mtd_partition * init_mtd_partitions(struct mtd_info *mtd, size_t size);
89 + struct semaphore lock;
90 + struct mtd_info mtd;
91 + struct mtd_erase_region_info regions[1];
94 +/* Private global state */
95 +static struct sflash_mtd sflash;
98 +sflash_mtd_poll(struct sflash_mtd *sflash, unsigned int offset, int timeout)
104 + if (!sflash_poll(sflash->cc, offset)) {
108 + if (time_after(jiffies, now + timeout)) {
109 + printk(KERN_ERR "sflash: timeout\n");
113 + if (current->need_resched) {
114 + set_current_state(TASK_UNINTERRUPTIBLE);
115 + schedule_timeout(timeout / 10);
124 +sflash_mtd_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
126 + struct sflash_mtd *sflash = (struct sflash_mtd *) mtd->priv;
127 + int bytes, ret = 0;
129 + /* Check address range */
132 + if ((from + len) > mtd->size)
135 + down(&sflash->lock);
139 + if ((bytes = sflash_read(sflash->cc, (uint) from, len, buf)) < 0) {
143 + from += (loff_t) bytes;
155 +sflash_mtd_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf)
157 + struct sflash_mtd *sflash = (struct sflash_mtd *) mtd->priv;
158 + int bytes, ret = 0;
160 + /* Check address range */
163 + if ((to + len) > mtd->size)
166 + down(&sflash->lock);
170 + if ((bytes = sflash_write(sflash->cc, (uint) to, len, buf)) < 0) {
174 + if ((ret = sflash_mtd_poll(sflash, (unsigned int) to, HZ / 10)))
176 + to += (loff_t) bytes;
188 +sflash_mtd_erase(struct mtd_info *mtd, struct erase_info *erase)
190 + struct sflash_mtd *sflash = (struct sflash_mtd *) mtd->priv;
192 + unsigned int addr, len;
194 + /* Check address range */
197 + if ((erase->addr + erase->len) > mtd->size)
200 + addr = erase->addr;
203 + down(&sflash->lock);
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)
212 + if ((ret = sflash_mtd_poll(sflash, addr, 10 * HZ)))
214 + addr += mtd->eraseregions[i].erasesize;
215 + len -= mtd->eraseregions[i].erasesize;
224 + /* Set erase status */
226 + erase->state = MTD_ERASE_FAILED;
228 + erase->state = MTD_ERASE_DONE;
230 + /* Call erase callback */
231 + if (erase->callback)
232 + erase->callback(erase);
237 +#if LINUX_VERSION_CODE < 0x20212 && defined(MODULE)
238 +#define sflash_mtd_init init_module
239 +#define sflash_mtd_exit cleanup_module
243 +sflash_mtd_init(void)
245 + struct pci_dev *pdev;
247 + struct sflash *info;
249 +#ifdef CONFIG_MTD_PARTITIONS
250 + struct mtd_partition *parts;
253 + if (!(pdev = pci_find_device(VENDOR_BROADCOM, SB_CC, NULL))) {
254 + printk(KERN_ERR "sflash: chipcommon not found\n");
258 + memset(&sflash, 0, sizeof(struct sflash_mtd));
259 + init_MUTEX(&sflash.lock);
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");
269 + /* Initialize serial flash access */
270 + info = sflash_init(sflash.cc);
273 + printk(KERN_ERR "sflash: found no supported devices\n");
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;
287 + sflash.mtd.numeraseregions = 1;
288 + ASSERT(sflash.mtd.size == info->size);
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;
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);
306 + ret = add_mtd_device(&sflash.mtd);
309 + printk(KERN_ERR "sflash: add_mtd failed\n");
317 + iounmap((void *) sflash.cc);
322 +sflash_mtd_exit(void)
324 +#ifdef CONFIG_MTD_PARTITIONS
325 + del_mtd_partitions(&sflash.mtd);
327 + del_mtd_device(&sflash.mtd);
329 + iounmap((void *) sflash.cc);
332 +module_init(sflash_mtd_init);
333 +module_exit(sflash_mtd_exit);
334 diff -urN linux.old/drivers/mtd/maps/bcm947xx-flash.c linux.dev/drivers/mtd/maps/bcm947xx-flash.c
335 --- linux.old/drivers/mtd/maps/bcm947xx-flash.c 1970-01-01 01:00:00.000000000 +0100
336 +++ linux.dev/drivers/mtd/maps/bcm947xx-flash.c 2006-06-23 18:08:46.000000000 +0200
339 + * Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
340 + * Copyright (C) 2005 Waldemar Brodkorb <wbx@openwrt.org>
341 + * Copyright (C) 2004 Florian Schirmer (jolt@tuxbox.org)
343 + * original functions for finding root filesystem from Mike Baker
345 + * This program is free software; you can redistribute it and/or modify it
346 + * under the terms of the GNU General Public License as published by the
347 + * Free Software Foundation; either version 2 of the License, or (at your
348 + * option) any later version.
350 + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
351 + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
352 + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
353 + * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
354 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
355 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
356 + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
357 + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
358 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
359 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
361 + * You should have received a copy of the GNU General Public License along
362 + * with this program; if not, write to the Free Software Foundation, Inc.,
363 + * 675 Mass Ave, Cambridge, MA 02139, USA.
366 + * Copyright 2004, Broadcom Corporation
367 + * All Rights Reserved.
369 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
370 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
371 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
372 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
374 + * Flash mapping for BCM947XX boards
378 +#include <linux/module.h>
379 +#include <linux/types.h>
380 +#include <linux/kernel.h>
381 +#include <linux/wait.h>
382 +#include <linux/mtd/mtd.h>
383 +#include <linux/mtd/map.h>
384 +#ifdef CONFIG_MTD_PARTITIONS
385 +#include <linux/mtd/partitions.h>
387 +#include <linux/config.h>
388 +#include <linux/squashfs_fs.h>
389 +#include <linux/jffs2.h>
390 +#include <linux/crc32.h>
393 +#include <typedefs.h>
395 +#include <bcmnvram.h>
396 +#include <bcmutils.h>
397 +#include <sbconfig.h>
398 +#include <sbchipc.h>
399 +#include <sbutils.h>
402 +/* Global SB handle */
403 +extern void *bcm947xx_sbh;
404 +extern spinlock_t bcm947xx_sbh_lock;
407 +#define sbh bcm947xx_sbh
408 +#define sbh_lock bcm947xx_sbh_lock
410 +#define WINDOW_ADDR 0x1fc00000
411 +#define WINDOW_SIZE 0x400000
414 +static struct mtd_info *bcm947xx_mtd;
416 +__u8 bcm947xx_map_read8(struct map_info *map, unsigned long ofs)
418 + if (map->map_priv_2 == 1)
419 + return __raw_readb(map->map_priv_1 + ofs);
421 + u16 val = __raw_readw(map->map_priv_1 + (ofs & ~1));
423 + return ((val >> 8) & 0xff);
425 + return (val & 0xff);
428 +__u16 bcm947xx_map_read16(struct map_info *map, unsigned long ofs)
430 + return __raw_readw(map->map_priv_1 + ofs);
433 +__u32 bcm947xx_map_read32(struct map_info *map, unsigned long ofs)
435 + return __raw_readl(map->map_priv_1 + ofs);
438 +void bcm947xx_map_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
441 + memcpy_fromio(to, map->map_priv_1 + from, len);
444 + u16 *dest = (u16 *) to;
445 + u16 *src = (u16 *) (map->map_priv_1 + from);
446 + for (i = 0; i < (len / 2); i++) {
450 + *((u8 *)dest+len-1) = src[i] & 0xff;
454 +void bcm947xx_map_write8(struct map_info *map, __u8 d, unsigned long adr)
456 + __raw_writeb(d, map->map_priv_1 + adr);
460 +void bcm947xx_map_write16(struct map_info *map, __u16 d, unsigned long adr)
462 + __raw_writew(d, map->map_priv_1 + adr);
466 +void bcm947xx_map_write32(struct map_info *map, __u32 d, unsigned long adr)
468 + __raw_writel(d, map->map_priv_1 + adr);
472 +void bcm947xx_map_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
474 + memcpy_toio(map->map_priv_1 + to, from, len);
477 +struct map_info bcm947xx_map = {
478 + name: "Physically mapped flash",
480 + buswidth: BUSWIDTH,
481 + read8: bcm947xx_map_read8,
482 + read16: bcm947xx_map_read16,
483 + read32: bcm947xx_map_read32,
484 + copy_from: bcm947xx_map_copy_from,
485 + write8: bcm947xx_map_write8,
486 + write16: bcm947xx_map_write16,
487 + write32: bcm947xx_map_write32,
488 + copy_to: bcm947xx_map_copy_to
491 +#ifdef CONFIG_MTD_PARTITIONS
493 +static struct mtd_partition bcm947xx_parts[] = {
494 + { name: "cfe", offset: 0, size: 0, mask_flags: MTD_WRITEABLE, },
495 + { name: "linux", offset: 0, size: 0, },
496 + { name: "rootfs", offset: 0, size: 0, },
497 + { name: "nvram", offset: 0, size: 0, },
498 + { name: "OpenWrt", offset: 0, size: 0, },
503 +find_cfe_size(struct mtd_info *mtd, size_t size)
505 + struct trx_header *trx;
506 + unsigned char buf[512];
511 + trx = (struct trx_header *) buf;
513 + blocksize = mtd->erasesize;
514 + if (blocksize < 0x10000)
515 + blocksize = 0x10000;
517 + for (off = (128*1024); off < size; off += blocksize) {
518 + memset(buf, 0xe5, sizeof(buf));
523 + if (MTD_READ(mtd, off, sizeof(buf), &len, buf) ||
524 + len != sizeof(buf))
527 + /* found a TRX header */
528 + if (le32_to_cpu(trx->magic) == TRX_MAGIC) {
534 + "%s: Couldn't find bootloader size\n",
539 + printk(KERN_NOTICE "bootloader size: %d\n", off);
545 + * Copied from mtdblock.c
549 + * Since typical flash erasable sectors are much larger than what Linux's
550 + * buffer cache can handle, we must implement read-modify-write on flash
551 + * sectors for each block write requests. To avoid over-erasing flash sectors
552 + * and to speed things up, we locally cache a whole flash sector while it is
553 + * being written to until a different sector is required.
556 +static void erase_callback(struct erase_info *done)
558 + wait_queue_head_t *wait_q = (wait_queue_head_t *)done->priv;
562 +static int erase_write (struct mtd_info *mtd, unsigned long pos,
563 + int len, const char *buf)
565 + struct erase_info erase;
566 + DECLARE_WAITQUEUE(wait, current);
567 + wait_queue_head_t wait_q;
572 + * First, let's erase the flash block.
575 + init_waitqueue_head(&wait_q);
577 + erase.callback = erase_callback;
580 + erase.priv = (u_long)&wait_q;
582 + set_current_state(TASK_INTERRUPTIBLE);
583 + add_wait_queue(&wait_q, &wait);
585 + ret = MTD_ERASE(mtd, &erase);
587 + set_current_state(TASK_RUNNING);
588 + remove_wait_queue(&wait_q, &wait);
589 + printk (KERN_WARNING "erase of region [0x%lx, 0x%x] "
590 + "on \"%s\" failed\n",
591 + pos, len, mtd->name);
595 + schedule(); /* Wait for erase to finish. */
596 + remove_wait_queue(&wait_q, &wait);
599 + * Next, writhe data to flash.
602 + ret = MTD_WRITE (mtd, pos, len, &retlen, buf);
614 +find_root(struct mtd_info *mtd, size_t size, struct mtd_partition *part)
616 + struct trx_header trx, *trx2;
617 + unsigned char buf[512], *block;
618 + int off, blocksize;
621 + struct squashfs_super_block *sb = (struct squashfs_super_block *) buf;
623 + blocksize = mtd->erasesize;
624 + if (blocksize < 0x10000)
625 + blocksize = 0x10000;
627 + for (off = (128*1024); off < size; off += blocksize) {
628 + memset(&trx, 0xe5, sizeof(trx));
633 + if (MTD_READ(mtd, off, sizeof(trx), &len, (char *) &trx) ||
634 + len != sizeof(trx))
637 + /* found a TRX header */
638 + if (le32_to_cpu(trx.magic) == TRX_MAGIC) {
639 + part->offset = le32_to_cpu(trx.offsets[2]) ? :
640 + le32_to_cpu(trx.offsets[1]);
641 + part->size = le32_to_cpu(trx.len);
643 + part->size -= part->offset;
644 + part->offset += off;
651 + "%s: Couldn't find root filesystem\n",
656 + if (part->size == 0)
659 + if (MTD_READ(mtd, part->offset, sizeof(buf), &len, buf) || len != sizeof(buf))
662 + if (*((__u32 *) buf) == SQUASHFS_MAGIC) {
663 + printk(KERN_INFO "%s: Filesystem type: squashfs, size=0x%x\n", mtd->name, (u32) sb->bytes_used);
665 + /* Update the squashfs partition size based on the superblock info */
666 + part->size = sb->bytes_used;
667 + len = part->offset + part->size;
668 + len += (mtd->erasesize - 1);
669 + len &= ~(mtd->erasesize - 1);
670 + part->size = len - part->offset;
671 + } else if (*((__u16 *) buf) == JFFS2_MAGIC_BITMASK) {
672 + printk(KERN_INFO "%s: Filesystem type: jffs2\n", mtd->name);
674 + /* Move the squashfs outside of the trx */
677 + printk(KERN_INFO "%s: Filesystem type: unknown\n", mtd->name);
681 + if (trx.len != part->offset + part->size - off) {
682 + /* Update the trx offsets and length */
683 + trx.len = part->offset + part->size - off;
685 + /* Update the trx crc32 */
686 + for (i = (u32) &(((struct trx_header *)NULL)->flag_version); i <= trx.len; i += sizeof(buf)) {
687 + if (MTD_READ(mtd, off + i, sizeof(buf), &len, buf) || len != sizeof(buf))
689 + crc = crc32_le(crc, buf, min(sizeof(buf), trx.len - i));
693 + /* read first eraseblock from the trx */
694 + trx2 = block = kmalloc(mtd->erasesize, GFP_KERNEL);
695 + if (MTD_READ(mtd, off, mtd->erasesize, &len, block) || len != mtd->erasesize) {
696 + printk("Error accessing the first trx eraseblock\n");
700 + printk("Updating TRX offsets and length:\n");
701 + printk("old trx = [0x%08x, 0x%08x, 0x%08x], len=0x%08x crc32=0x%08x\n", trx2->offsets[0], trx2->offsets[1], trx2->offsets[2], trx2->len, trx2->crc32);
702 + printk("new trx = [0x%08x, 0x%08x, 0x%08x], len=0x%08x crc32=0x%08x\n", trx.offsets[0], trx.offsets[1], trx.offsets[2], trx.len, trx.crc32);
704 + /* Write updated trx header to the flash */
705 + memcpy(block, &trx, sizeof(trx));
707 + mtd->unlock(mtd, off, mtd->erasesize);
708 + erase_write(mtd, off, mtd->erasesize, block);
718 +struct mtd_partition * __init
719 +init_mtd_partitions(struct mtd_info *mtd, size_t size)
723 + cfe_size = find_cfe_size(mtd,size);
726 + bcm947xx_parts[0].offset = 0;
727 + bcm947xx_parts[0].size = cfe_size;
730 + if (cfe_size != 384 * 1024) {
731 + bcm947xx_parts[3].offset = size - ROUNDUP(NVRAM_SPACE, mtd->erasesize);
732 + bcm947xx_parts[3].size = ROUNDUP(NVRAM_SPACE, mtd->erasesize);
734 + /* nvram (old 128kb config partition on netgear wgt634u) */
735 + bcm947xx_parts[3].offset = bcm947xx_parts[0].size;
736 + bcm947xx_parts[3].size = ROUNDUP(NVRAM_SPACE, mtd->erasesize);
739 + /* linux (kernel and rootfs) */
740 + if (cfe_size != 384 * 1024) {
741 + bcm947xx_parts[1].offset = bcm947xx_parts[0].size;
742 + bcm947xx_parts[1].size = bcm947xx_parts[3].offset -
743 + bcm947xx_parts[1].offset;
745 + /* do not count the elf loader, which is on one block */
746 + bcm947xx_parts[1].offset = bcm947xx_parts[0].size +
747 + bcm947xx_parts[3].size + mtd->erasesize;
748 + bcm947xx_parts[1].size = size -
749 + bcm947xx_parts[0].size -
750 + (2*bcm947xx_parts[3].size) -
754 + /* find and size rootfs */
755 + if (find_root(mtd,size,&bcm947xx_parts[2])==0) {
756 + /* entirely jffs2 */
757 + bcm947xx_parts[4].name = NULL;
758 + bcm947xx_parts[2].size = size - bcm947xx_parts[2].offset -
759 + bcm947xx_parts[3].size;
762 + /* calculate leftover flash, and assign it to the jffs2 partition */
763 + if (cfe_size != 384 * 1024) {
764 + bcm947xx_parts[4].offset = bcm947xx_parts[2].offset +
765 + bcm947xx_parts[2].size;
766 + if ((bcm947xx_parts[4].offset % mtd->erasesize) > 0) {
767 + bcm947xx_parts[4].offset += mtd->erasesize -
768 + (bcm947xx_parts[4].offset % mtd->erasesize);
770 + bcm947xx_parts[4].size = bcm947xx_parts[3].offset -
771 + bcm947xx_parts[4].offset;
773 + bcm947xx_parts[4].offset = bcm947xx_parts[2].offset +
774 + bcm947xx_parts[2].size;
775 + if ((bcm947xx_parts[4].offset % mtd->erasesize) > 0) {
776 + bcm947xx_parts[4].offset += mtd->erasesize -
777 + (bcm947xx_parts[4].offset % mtd->erasesize);
779 + bcm947xx_parts[4].size = size - bcm947xx_parts[3].size -
780 + bcm947xx_parts[4].offset;
784 + return bcm947xx_parts;
790 +mod_init_t init_bcm947xx_map(void)
796 + uint window_addr = 0, window_size = 0;
799 +#ifdef CONFIG_MTD_PARTITIONS
800 + struct mtd_partition *parts;
804 + spin_lock_irqsave(&sbh_lock, flags);
805 + coreidx = sb_coreidx(sbh);
807 + /* Check strapping option if chipcommon exists */
808 + if ((cc = sb_setcore(sbh, SB_CC, 0))) {
809 + fltype = readl(&cc->capabilities) & CAP_FLASH_MASK;
810 + if (fltype == PFLASH) {
811 + bcm947xx_map.map_priv_2 = 1;
812 + window_addr = 0x1c000000;
813 + bcm947xx_map.size = window_size = 32 * 1024 * 1024;
814 + if ((readl(&cc->flash_config) & CC_CFG_DS) == 0)
815 + bcm947xx_map.buswidth = 1;
819 + bcm947xx_map.map_priv_2 = 0;
820 + window_addr = WINDOW_ADDR;
821 + window_size = WINDOW_SIZE;
824 + sb_setcoreidx(sbh, coreidx);
825 + spin_unlock_irqrestore(&sbh_lock, flags);
827 + if (fltype != PFLASH) {
828 + printk(KERN_ERR "pflash: found no supported devices\n");
833 + bcm947xx_map.map_priv_1 = (unsigned long) ioremap(window_addr, window_size);
835 + if (!bcm947xx_map.map_priv_1) {
836 + printk(KERN_ERR "Failed to ioremap\n");
840 + if (!(bcm947xx_mtd = do_map_probe("cfi_probe", &bcm947xx_map))) {
841 + printk(KERN_ERR "pflash: cfi_probe failed\n");
842 + iounmap((void *)bcm947xx_map.map_priv_1);
846 + bcm947xx_mtd->module = THIS_MODULE;
848 + size = bcm947xx_mtd->size;
850 + printk(KERN_NOTICE "Flash device: 0x%x at 0x%x\n", size, window_addr);
852 +#ifdef CONFIG_MTD_PARTITIONS
853 + parts = init_mtd_partitions(bcm947xx_mtd, size);
854 + for (i = 0; parts[i].name; i++);
855 + ret = add_mtd_partitions(bcm947xx_mtd, parts, i);
857 + printk(KERN_ERR "Flash: add_mtd_partitions failed\n");
866 + map_destroy(bcm947xx_mtd);
867 + if (bcm947xx_map.map_priv_1)
868 + iounmap((void *) bcm947xx_map.map_priv_1);
869 + bcm947xx_map.map_priv_1 = 0;
873 +mod_exit_t cleanup_bcm947xx_map(void)
875 +#ifdef CONFIG_MTD_PARTITIONS
876 + del_mtd_partitions(bcm947xx_mtd);
878 + map_destroy(bcm947xx_mtd);
879 + iounmap((void *) bcm947xx_map.map_priv_1);
880 + bcm947xx_map.map_priv_1 = 0;
883 +module_init(init_bcm947xx_map);
884 +module_exit(cleanup_bcm947xx_map);
885 diff -urN linux.old/drivers/mtd/maps/Config.in linux.dev/drivers/mtd/maps/Config.in
886 --- linux.old/drivers/mtd/maps/Config.in 2006-06-22 17:35:39.000000000 +0200
887 +++ linux.dev/drivers/mtd/maps/Config.in 2006-06-21 21:41:24.000000000 +0200
891 if [ "$CONFIG_MIPS" = "y" ]; then
892 + dep_tristate ' CFI Flash device mapped on Broadcom BCM947XX boards' CONFIG_MTD_BCM947XX $CONFIG_MTD_CFI
893 dep_tristate ' Pb1000 MTD support' CONFIG_MTD_PB1000 $CONFIG_MIPS_PB1000
894 dep_tristate ' Pb1500 MTD support' CONFIG_MTD_PB1500 $CONFIG_MIPS_PB1500
895 dep_tristate ' Pb1100 MTD support' CONFIG_MTD_PB1100 $CONFIG_MIPS_PB1100
896 diff -urN linux.old/drivers/mtd/maps/Makefile linux.dev/drivers/mtd/maps/Makefile
897 --- linux.old/drivers/mtd/maps/Makefile 2006-06-22 17:35:39.000000000 +0200
898 +++ linux.dev/drivers/mtd/maps/Makefile 2006-06-21 21:41:24.000000000 +0200
901 # $Id: Makefile,v 1.37 2003/01/24 14:26:38 dwmw2 Exp $
903 +EXTRA_CFLAGS := -I$(TOPDIR)/arch/mips/bcm947xx/include
905 BELOW25 := $(shell echo $(PATCHLEVEL) | sed s/[1234]/y/)
912 +obj-$(CONFIG_MTD_BCM947XX) += bcm947xx-flash.o
913 obj-$(CONFIG_MTD_CDB89712) += cdb89712.o
914 obj-$(CONFIG_MTD_ARM_INTEGRATOR)+= integrator-flash.o
915 obj-$(CONFIG_MTD_CFI_FLAGADM) += cfi_flagadm.o