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) 2004 Florian Schirmer (jolt@tuxbox.org)
340 + * Copyright (C) 2005 Waldemar Brodkorb <wbx@openwrt.org>
342 + * original functions for finding root filesystem from Mike Baker
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.
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.
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.
365 + * Copyright 2004, Broadcom Corporation
366 + * All Rights Reserved.
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.
373 + * Flash mapping for BCM947XX boards
377 +#include <linux/module.h>
378 +#include <linux/types.h>
379 +#include <linux/kernel.h>
380 +#include <linux/wait.h>
381 +#include <linux/mtd/mtd.h>
382 +#include <linux/mtd/map.h>
383 +#ifdef CONFIG_MTD_PARTITIONS
384 +#include <linux/mtd/partitions.h>
386 +#include <linux/config.h>
387 +#include <linux/squashfs_fs.h>
388 +#include <linux/jffs2.h>
389 +#include <linux/crc32.h>
392 +#include <typedefs.h>
394 +#include <bcmnvram.h>
395 +#include <bcmutils.h>
396 +#include <sbconfig.h>
397 +#include <sbchipc.h>
398 +#include <sbutils.h>
401 +/* Global SB handle */
402 +extern void *bcm947xx_sbh;
403 +extern spinlock_t bcm947xx_sbh_lock;
406 +#define sbh bcm947xx_sbh
407 +#define sbh_lock bcm947xx_sbh_lock
409 +#define WINDOW_ADDR 0x1fc00000
410 +#define WINDOW_SIZE 0x400000
413 +static struct mtd_info *bcm947xx_mtd;
415 +__u8 bcm947xx_map_read8(struct map_info *map, unsigned long ofs)
417 + if (map->map_priv_2 == 1)
418 + return __raw_readb(map->map_priv_1 + ofs);
420 + u16 val = __raw_readw(map->map_priv_1 + (ofs & ~1));
422 + return ((val >> 8) & 0xff);
424 + return (val & 0xff);
427 +__u16 bcm947xx_map_read16(struct map_info *map, unsigned long ofs)
429 + return __raw_readw(map->map_priv_1 + ofs);
432 +__u32 bcm947xx_map_read32(struct map_info *map, unsigned long ofs)
434 + return __raw_readl(map->map_priv_1 + ofs);
437 +void bcm947xx_map_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
440 + memcpy_fromio(to, map->map_priv_1 + from, len);
443 + u16 *dest = (u16 *) to;
444 + u16 *src = (u16 *) (map->map_priv_1 + from);
445 + for (i = 0; i < (len / 2); i++) {
449 + *((u8 *)dest+len-1) = src[i] & 0xff;
453 +void bcm947xx_map_write8(struct map_info *map, __u8 d, unsigned long adr)
455 + __raw_writeb(d, map->map_priv_1 + adr);
459 +void bcm947xx_map_write16(struct map_info *map, __u16 d, unsigned long adr)
461 + __raw_writew(d, map->map_priv_1 + adr);
465 +void bcm947xx_map_write32(struct map_info *map, __u32 d, unsigned long adr)
467 + __raw_writel(d, map->map_priv_1 + adr);
471 +void bcm947xx_map_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
473 + memcpy_toio(map->map_priv_1 + to, from, len);
476 +struct map_info bcm947xx_map = {
477 + name: "Physically mapped flash",
479 + buswidth: BUSWIDTH,
480 + read8: bcm947xx_map_read8,
481 + read16: bcm947xx_map_read16,
482 + read32: bcm947xx_map_read32,
483 + copy_from: bcm947xx_map_copy_from,
484 + write8: bcm947xx_map_write8,
485 + write16: bcm947xx_map_write16,
486 + write32: bcm947xx_map_write32,
487 + copy_to: bcm947xx_map_copy_to
490 +#ifdef CONFIG_MTD_PARTITIONS
492 +static struct mtd_partition bcm947xx_parts[] = {
493 + { name: "cfe", offset: 0, size: 0, mask_flags: MTD_WRITEABLE, },
494 + { name: "linux", offset: 0, size: 0, },
495 + { name: "rootfs", offset: 0, size: 0, },
496 + { name: "nvram", offset: 0, size: 0, },
497 + { name: "OpenWrt", offset: 0, size: 0, },
502 +find_cfe_size(struct mtd_info *mtd, size_t size)
504 + struct trx_header *trx;
505 + unsigned char buf[512];
510 + trx = (struct trx_header *) buf;
512 + blocksize = mtd->erasesize;
513 + if (blocksize < 0x10000)
514 + blocksize = 0x10000;
516 + for (off = (128*1024); off < size; off += blocksize) {
517 + memset(buf, 0xe5, sizeof(buf));
522 + if (MTD_READ(mtd, off, sizeof(buf), &len, buf) ||
523 + len != sizeof(buf))
526 + /* found a TRX header */
527 + if (le32_to_cpu(trx->magic) == TRX_MAGIC) {
533 + "%s: Couldn't find bootloader size\n",
538 + printk(KERN_NOTICE "bootloader size: %d\n", off);
544 + * Copied from mtdblock.c
548 + * Since typical flash erasable sectors are much larger than what Linux's
549 + * buffer cache can handle, we must implement read-modify-write on flash
550 + * sectors for each block write requests. To avoid over-erasing flash sectors
551 + * and to speed things up, we locally cache a whole flash sector while it is
552 + * being written to until a different sector is required.
555 +static void erase_callback(struct erase_info *done)
557 + wait_queue_head_t *wait_q = (wait_queue_head_t *)done->priv;
561 +static int erase_write (struct mtd_info *mtd, unsigned long pos,
562 + int len, const char *buf)
564 + struct erase_info erase;
565 + DECLARE_WAITQUEUE(wait, current);
566 + wait_queue_head_t wait_q;
571 + * First, let's erase the flash block.
574 + init_waitqueue_head(&wait_q);
576 + erase.callback = erase_callback;
579 + erase.priv = (u_long)&wait_q;
581 + set_current_state(TASK_INTERRUPTIBLE);
582 + add_wait_queue(&wait_q, &wait);
584 + ret = MTD_ERASE(mtd, &erase);
586 + set_current_state(TASK_RUNNING);
587 + remove_wait_queue(&wait_q, &wait);
588 + printk (KERN_WARNING "erase of region [0x%lx, 0x%x] "
589 + "on \"%s\" failed\n",
590 + pos, len, mtd->name);
594 + schedule(); /* Wait for erase to finish. */
595 + remove_wait_queue(&wait_q, &wait);
598 + * Next, writhe data to flash.
601 + ret = MTD_WRITE (mtd, pos, len, &retlen, buf);
613 +find_root(struct mtd_info *mtd, size_t size, struct mtd_partition *part)
615 + struct trx_header trx, *trx2;
616 + unsigned char buf[512], *block;
617 + int off, blocksize;
620 + struct squashfs_super_block *sb = (struct squashfs_super_block *) buf;
622 + blocksize = mtd->erasesize;
623 + if (blocksize < 0x10000)
624 + blocksize = 0x10000;
626 + for (off = (128*1024); off < size; off += blocksize) {
627 + memset(&trx, 0xe5, sizeof(trx));
632 + if (MTD_READ(mtd, off, sizeof(trx), &len, (char *) &trx) ||
633 + len != sizeof(trx))
636 + /* found a TRX header */
637 + if (le32_to_cpu(trx.magic) == TRX_MAGIC) {
638 + part->offset = le32_to_cpu(trx.offsets[2]) ? :
639 + le32_to_cpu(trx.offsets[1]);
640 + part->size = le32_to_cpu(trx.len);
642 + part->size -= part->offset;
643 + part->offset += off;
650 + "%s: Couldn't find root filesystem\n",
655 + if (part->size == 0)
658 + if (MTD_READ(mtd, part->offset, sizeof(buf), &len, buf) || len != sizeof(buf))
661 + if (*((__u32 *) buf) == SQUASHFS_MAGIC) {
662 + printk(KERN_INFO "%s: Filesystem type: squashfs, size=0x%x\n", mtd->name, (u32) sb->bytes_used);
664 + /* Update the squashfs partition size based on the superblock info */
665 + part->size = sb->bytes_used;
666 + part->size += (mtd->erasesize - 1);
667 + part->size &= ~(mtd->erasesize - 1);
668 + } else if (*((__u16 *) buf) == JFFS2_MAGIC_BITMASK) {
669 + printk(KERN_INFO "%s: Filesystem type: jffs2\n", mtd->name);
671 + /* Move the squashfs outside of the trx */
674 + printk(KERN_INFO "%s: Filesystem type: unknown\n", mtd->name);
678 + if (trx.len != part->offset + part->size - off) {
679 + /* Update the trx offsets and length */
680 + trx.len = part->offset + part->size - off;
682 + /* Update the trx crc32 */
683 + for (i = (u32) &(((struct trx_header *)NULL)->flag_version); i <= trx.len; i += sizeof(buf)) {
684 + if (MTD_READ(mtd, off + i, sizeof(buf), &len, buf) || len != sizeof(buf))
686 + crc = crc32_le(crc, buf, min(sizeof(buf), trx.len - i));
690 + /* read first eraseblock from the trx */
691 + trx2 = block = kmalloc(mtd->erasesize, GFP_KERNEL);
692 + if (MTD_READ(mtd, off, mtd->erasesize, &len, block) || len != mtd->erasesize) {
693 + printk("Error accessing the first trx eraseblock\n");
697 + printk("Updating TRX offsets and length:\n");
698 + 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);
699 + 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);
701 + /* Write updated trx header to the flash */
702 + memcpy(block, &trx, sizeof(trx));
704 + mtd->unlock(mtd, off, mtd->erasesize);
705 + erase_write(mtd, off, mtd->erasesize, block);
715 +struct mtd_partition * __init
716 +init_mtd_partitions(struct mtd_info *mtd, size_t size)
720 + cfe_size = find_cfe_size(mtd,size);
723 + bcm947xx_parts[0].offset = 0;
724 + bcm947xx_parts[0].size = cfe_size;
727 + if (cfe_size != 384 * 1024) {
728 + bcm947xx_parts[3].offset = size - ROUNDUP(NVRAM_SPACE, mtd->erasesize);
729 + bcm947xx_parts[3].size = ROUNDUP(NVRAM_SPACE, mtd->erasesize);
731 + /* nvram (old 128kb config partition on netgear wgt634u) */
732 + bcm947xx_parts[3].offset = bcm947xx_parts[0].size;
733 + bcm947xx_parts[3].size = ROUNDUP(NVRAM_SPACE, mtd->erasesize);
736 + /* linux (kernel and rootfs) */
737 + if (cfe_size != 384 * 1024) {
738 + bcm947xx_parts[1].offset = bcm947xx_parts[0].size;
739 + bcm947xx_parts[1].size = bcm947xx_parts[3].offset -
740 + bcm947xx_parts[1].offset;
742 + /* do not count the elf loader, which is on one block */
743 + bcm947xx_parts[1].offset = bcm947xx_parts[0].size +
744 + bcm947xx_parts[3].size + mtd->erasesize;
745 + bcm947xx_parts[1].size = size -
746 + bcm947xx_parts[0].size -
747 + (2*bcm947xx_parts[3].size) -
751 + /* find and size rootfs */
752 + if (find_root(mtd,size,&bcm947xx_parts[2])==0) {
753 + /* entirely jffs2 */
754 + bcm947xx_parts[4].name = NULL;
755 + bcm947xx_parts[2].size = size - bcm947xx_parts[2].offset -
756 + bcm947xx_parts[3].size;
759 + /* calculate leftover flash, and assign it to the jffs2 partition */
760 + if (cfe_size != 384 * 1024) {
761 + bcm947xx_parts[4].offset = bcm947xx_parts[2].offset +
762 + bcm947xx_parts[2].size;
763 + if ((bcm947xx_parts[4].offset % mtd->erasesize) > 0) {
764 + bcm947xx_parts[4].offset += mtd->erasesize -
765 + (bcm947xx_parts[4].offset % mtd->erasesize);
767 + bcm947xx_parts[4].size = bcm947xx_parts[3].offset -
768 + bcm947xx_parts[4].offset;
770 + bcm947xx_parts[4].offset = bcm947xx_parts[2].offset +
771 + bcm947xx_parts[2].size;
772 + if ((bcm947xx_parts[4].offset % mtd->erasesize) > 0) {
773 + bcm947xx_parts[4].offset += mtd->erasesize -
774 + (bcm947xx_parts[4].offset % mtd->erasesize);
776 + bcm947xx_parts[4].size = size - bcm947xx_parts[3].size -
777 + bcm947xx_parts[4].offset;
781 + return bcm947xx_parts;
787 +mod_init_t init_bcm947xx_map(void)
793 + uint window_addr = 0, window_size = 0;
796 +#ifdef CONFIG_MTD_PARTITIONS
797 + struct mtd_partition *parts;
801 + spin_lock_irqsave(&sbh_lock, flags);
802 + coreidx = sb_coreidx(sbh);
804 + /* Check strapping option if chipcommon exists */
805 + if ((cc = sb_setcore(sbh, SB_CC, 0))) {
806 + fltype = readl(&cc->capabilities) & CAP_FLASH_MASK;
807 + if (fltype == PFLASH) {
808 + bcm947xx_map.map_priv_2 = 1;
809 + window_addr = 0x1c000000;
810 + bcm947xx_map.size = window_size = 32 * 1024 * 1024;
811 + if ((readl(&cc->flash_config) & CC_CFG_DS) == 0)
812 + bcm947xx_map.buswidth = 1;
816 + bcm947xx_map.map_priv_2 = 0;
817 + window_addr = WINDOW_ADDR;
818 + window_size = WINDOW_SIZE;
821 + sb_setcoreidx(sbh, coreidx);
822 + spin_unlock_irqrestore(&sbh_lock, flags);
824 + if (fltype != PFLASH) {
825 + printk(KERN_ERR "pflash: found no supported devices\n");
830 + bcm947xx_map.map_priv_1 = (unsigned long) ioremap(window_addr, window_size);
832 + if (!bcm947xx_map.map_priv_1) {
833 + printk(KERN_ERR "Failed to ioremap\n");
837 + if (!(bcm947xx_mtd = do_map_probe("cfi_probe", &bcm947xx_map))) {
838 + printk(KERN_ERR "pflash: cfi_probe failed\n");
839 + iounmap((void *)bcm947xx_map.map_priv_1);
843 + bcm947xx_mtd->module = THIS_MODULE;
845 + size = bcm947xx_mtd->size;
847 + printk(KERN_NOTICE "Flash device: 0x%x at 0x%x\n", size, window_addr);
849 +#ifdef CONFIG_MTD_PARTITIONS
850 + parts = init_mtd_partitions(bcm947xx_mtd, size);
851 + for (i = 0; parts[i].name; i++);
852 + ret = add_mtd_partitions(bcm947xx_mtd, parts, i);
854 + printk(KERN_ERR "Flash: add_mtd_partitions failed\n");
863 + map_destroy(bcm947xx_mtd);
864 + if (bcm947xx_map.map_priv_1)
865 + iounmap((void *) bcm947xx_map.map_priv_1);
866 + bcm947xx_map.map_priv_1 = 0;
870 +mod_exit_t cleanup_bcm947xx_map(void)
872 +#ifdef CONFIG_MTD_PARTITIONS
873 + del_mtd_partitions(bcm947xx_mtd);
875 + map_destroy(bcm947xx_mtd);
876 + iounmap((void *) bcm947xx_map.map_priv_1);
877 + bcm947xx_map.map_priv_1 = 0;
880 +module_init(init_bcm947xx_map);
881 +module_exit(cleanup_bcm947xx_map);
882 diff -urN linux.old/drivers/mtd/maps/Config.in linux.dev/drivers/mtd/maps/Config.in
883 --- linux.old/drivers/mtd/maps/Config.in 2006-06-22 17:35:39.000000000 +0200
884 +++ linux.dev/drivers/mtd/maps/Config.in 2006-06-21 21:41:24.000000000 +0200
888 if [ "$CONFIG_MIPS" = "y" ]; then
889 + dep_tristate ' CFI Flash device mapped on Broadcom BCM947XX boards' CONFIG_MTD_BCM947XX $CONFIG_MTD_CFI
890 dep_tristate ' Pb1000 MTD support' CONFIG_MTD_PB1000 $CONFIG_MIPS_PB1000
891 dep_tristate ' Pb1500 MTD support' CONFIG_MTD_PB1500 $CONFIG_MIPS_PB1500
892 dep_tristate ' Pb1100 MTD support' CONFIG_MTD_PB1100 $CONFIG_MIPS_PB1100
893 diff -urN linux.old/drivers/mtd/maps/Makefile linux.dev/drivers/mtd/maps/Makefile
894 --- linux.old/drivers/mtd/maps/Makefile 2006-06-22 17:35:39.000000000 +0200
895 +++ linux.dev/drivers/mtd/maps/Makefile 2006-06-21 21:41:24.000000000 +0200
898 # $Id: Makefile,v 1.37 2003/01/24 14:26:38 dwmw2 Exp $
900 +EXTRA_CFLAGS := -I$(TOPDIR)/arch/mips/bcm947xx/include
902 BELOW25 := $(shell echo $(PATCHLEVEL) | sed s/[1234]/y/)
909 +obj-$(CONFIG_MTD_BCM947XX) += bcm947xx-flash.o
910 obj-$(CONFIG_MTD_CDB89712) += cdb89712.o
911 obj-$(CONFIG_MTD_ARM_INTEGRATOR)+= integrator-flash.o
912 obj-$(CONFIG_MTD_CFI_FLAGADM) += cfi_flagadm.o