source: src/linux/brcm/linux.v24_2/drivers/mtd/maps/bcm947xx-flash.c @ 12221

Last change on this file since 12221 was 12221, checked in by eko, 4 years ago

wgr614L with boardnum = 0123 support

File size: 17.9 KB
Line 
1/*
2 *  Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
3 *  Copyright (C) 2005 Waldemar Brodkorb <wbx@openwrt.org>
4 *  Copyright (C) 2004 Florian Schirmer (jolt@tuxbox.org)
5 *
6 *  original functions for finding root filesystem from Mike Baker
7 *
8 *  This program is free software; you can redistribute  it and/or modify it
9 *  under  the terms of  the GNU General  Public License as published by the
10 *  Free Software Foundation;  either version 2 of the  License, or (at your
11 *  option) any later version.
12 *
13 *  THIS  SOFTWARE  IS PROVIDED   ``AS  IS'' AND   ANY  EXPRESS OR IMPLIED
14 *  WARRANTIES,   INCLUDING, BUT NOT  LIMITED  TO, THE IMPLIED WARRANTIES OF
15 *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
16 *  NO  EVENT  SHALL   THE AUTHOR  BE    LIABLE FOR ANY   DIRECT, INDIRECT,
17 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 *  NOT LIMITED   TO, PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS OF
19 *  USE, DATA,  OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 *  ANY THEORY OF LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT
21 *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 *  You should have received a copy of the  GNU General Public License along
25 *  with this program; if not, write  to the Free Software Foundation, Inc.,
26 *  675 Mass Ave, Cambridge, MA 02139, USA.
27 *
28 *
29 * Copyright 2004, Broadcom Corporation
30 * All Rights Reserved.
31 *
32 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
33 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
34 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
35 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
36 *
37 * Flash mapping for BCM947XX boards
38 *
39 */
40
41#include <linux/module.h>
42#include <linux/types.h>
43#include <linux/kernel.h>
44#include <linux/wait.h>
45#include <linux/mtd/mtd.h>
46#include <linux/mtd/map.h>
47#ifdef CONFIG_MTD_PARTITIONS
48#include <linux/mtd/partitions.h>
49#endif
50#include <linux/config.h>
51#include <linux/squashfs_fs.h>
52#include <linux/jffs2.h>
53#include <linux/crc32.h>
54#include <asm/io.h>
55
56#include <typedefs.h>
57#include <osl.h>
58#include <bcmnvram.h>
59#include <bcmutils.h>
60#include <sbconfig.h>
61#include <sbchipc.h>
62#include <sbutils.h>
63#include <trxhdr.h>
64
65/* Global SB handle */
66extern void *bcm947xx_sbh;
67extern spinlock_t bcm947xx_sbh_lock;
68
69/* Convenience */
70#define sbh bcm947xx_sbh
71#define sbh_lock bcm947xx_sbh_lock
72
73#define WINDOW_ADDR 0x1fc00000
74#define WINDOW_SIZE 0x400000
75#define BUSWIDTH 2
76
77static struct mtd_info *bcm947xx_mtd;
78
79__u8 bcm947xx_map_read8(struct map_info *map, unsigned long ofs)
80{
81        if (map->map_priv_2 == 1)
82                return __raw_readb(map->map_priv_1 + ofs);
83
84        u16 val = __raw_readw(map->map_priv_1 + (ofs & ~1));
85        if (ofs & 1)
86                return ((val >> 8) & 0xff);
87        else
88                return (val & 0xff);
89}
90
91__u16 bcm947xx_map_read16(struct map_info *map, unsigned long ofs)
92{
93        return __raw_readw(map->map_priv_1 + ofs);
94}
95
96__u32 bcm947xx_map_read32(struct map_info *map, unsigned long ofs)
97{
98        return __raw_readl(map->map_priv_1 + ofs);
99}
100
101void bcm947xx_map_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
102{
103        if (len==1) {
104                memcpy_fromio(to, map->map_priv_1 + from, len);
105        } else {
106                int i;
107                u16 *dest = (u16 *) to;
108                u16 *src  = (u16 *) (map->map_priv_1 + from);
109                for (i = 0; i < (len / 2); i++) {
110                        dest[i] = src[i];
111                }
112                if (len & 1)
113                        *((u8 *)dest+len-1) = src[i] & 0xff;
114        }
115}
116
117void bcm947xx_map_write8(struct map_info *map, __u8 d, unsigned long adr)
118{
119        __raw_writeb(d, map->map_priv_1 + adr);
120        mb();
121}
122
123void bcm947xx_map_write16(struct map_info *map, __u16 d, unsigned long adr)
124{
125        __raw_writew(d, map->map_priv_1 + adr);
126        mb();
127}
128
129void bcm947xx_map_write32(struct map_info *map, __u32 d, unsigned long adr)
130{
131        __raw_writel(d, map->map_priv_1 + adr);
132        mb();
133}
134
135void bcm947xx_map_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
136{
137        memcpy_toio(map->map_priv_1 + to, from, len);
138}
139
140struct map_info bcm947xx_map = {
141        name: "Physically mapped flash",
142        size: WINDOW_SIZE,
143        buswidth: BUSWIDTH,
144        read8: bcm947xx_map_read8,
145        read16: bcm947xx_map_read16,
146        read32: bcm947xx_map_read32,
147        copy_from: bcm947xx_map_copy_from,
148        write8: bcm947xx_map_write8,
149        write16: bcm947xx_map_write16,
150        write32: bcm947xx_map_write32,
151        copy_to: bcm947xx_map_copy_to
152};
153
154#ifdef CONFIG_MTD_PARTITIONS
155
156static struct mtd_partition bcm947xx_parts[] = {
157        { name: "cfe",  offset: 0, size: 0, },
158        { name: "linux", offset: 0, size: 0, },
159        { name: "rootfs", offset: 0, size: 0, },
160        { name: "nvram", offset: 0, size: 0, },
161        { name: "ddwrt", offset: 0, size: 0, },
162        { name: NULL, },
163};
164
165static int __init
166find_cfe_size(struct mtd_info *mtd, size_t size)
167{
168        struct trx_header *trx;
169        unsigned char buf[512];
170        int off;
171        size_t len;
172        int blocksize;
173
174        trx = (struct trx_header *) buf;
175
176        blocksize = mtd->erasesize;
177        if (blocksize < 0x10000)
178                blocksize = 0x10000;
179//      printk(KERN_EMERG "blocksize is %d\n",blocksize);
180        for (off = 0; off < size; off += 64*1024) {
181                memset(buf, 0xe5, sizeof(buf));
182//              printk(KERN_EMERG "scan at 0x%08x\n",off);
183                /*
184                 * Read into buffer
185                 */
186                if (MTD_READ(mtd, off, sizeof(buf), &len, buf) ||
187                    len != sizeof(buf))
188                        continue;
189
190                /* found a TRX header */
191                if (le32_to_cpu(trx->magic) == TRX_MAGIC) {
192                        goto found;
193                }
194        }
195
196        printk(KERN_EMERG
197               "%s: Couldn't find bootloader size\n",
198               mtd->name);
199        return -1;
200
201 found:
202        printk(KERN_EMERG  "bootloader size: %d\n", off);
203        return off;
204
205}
206
207/*
208 * Copied from mtdblock.c
209 *
210 * Cache stuff...
211 *
212 * Since typical flash erasable sectors are much larger than what Linux's
213 * buffer cache can handle, we must implement read-modify-write on flash
214 * sectors for each block write requests.  To avoid over-erasing flash sectors
215 * and to speed things up, we locally cache a whole flash sector while it is
216 * being written to until a different sector is required.
217 */
218
219static void erase_callback(struct erase_info *done)
220{
221        wait_queue_head_t *wait_q = (wait_queue_head_t *)done->priv;
222        wake_up(wait_q);
223}
224
225static int erase_write (struct mtd_info *mtd, unsigned long pos,
226                        int len, const char *buf)
227{
228        struct erase_info erase;
229        DECLARE_WAITQUEUE(wait, current);
230        wait_queue_head_t wait_q;
231        size_t retlen;
232        int ret;
233
234        /*
235         * First, let's erase the flash block.
236         */
237
238        init_waitqueue_head(&wait_q);
239        erase.mtd = mtd;
240        erase.callback = erase_callback;
241        erase.addr = pos;
242        erase.len = len;
243        erase.priv = (u_long)&wait_q;
244
245        set_current_state(TASK_INTERRUPTIBLE);
246        add_wait_queue(&wait_q, &wait);
247
248        ret = MTD_ERASE(mtd, &erase);
249        if (ret) {
250                set_current_state(TASK_RUNNING);
251                remove_wait_queue(&wait_q, &wait);
252                printk (KERN_WARNING "erase of region [0x%lx, 0x%x] "
253                                     "on \"%s\" failed\n",
254                        pos, len, mtd->name);
255                return ret;
256        }
257
258        schedule();  /* Wait for erase to finish. */
259        remove_wait_queue(&wait_q, &wait);
260
261        /*
262         * Next, writhe data to flash.
263         */
264
265        ret = MTD_WRITE (mtd, pos, len, &retlen, buf);
266        if (ret)
267                return ret;
268        if (retlen != len)
269                return -EIO;
270        return 0;
271}
272
273
274
275
276static int __init
277find_root(struct mtd_info *mtd, size_t size, struct mtd_partition *part)
278{
279        struct trx_header trx, *trx2;
280        unsigned char buf[512], *block;
281        int off, blocksize;
282        u32 i, crc = ~0;
283        size_t len;
284        struct squashfs_super_block *sb = (struct squashfs_super_block *) buf;
285
286        blocksize = mtd->erasesize;
287        if (blocksize < 0x10000)
288                blocksize = 0x10000;
289
290        for (off = 0; off < size; off += 64*1024) {
291                memset(&trx, 0xe5, sizeof(trx));
292//              printk(KERN_EMERG "scan root at 0x%08x\n",off);
293
294                /*
295                 * Read into buffer
296                 */
297                if (MTD_READ(mtd, off, sizeof(trx), &len, (char *) &trx) ||
298                    len != sizeof(trx))
299                        continue;
300
301                /* found a TRX header */
302                if (le32_to_cpu(trx.magic) == TRX_MAGIC) {
303                        part->offset = le32_to_cpu(trx.offsets[2]) ? :
304                                le32_to_cpu(trx.offsets[1]);
305                        part->size = le32_to_cpu(trx.len);
306
307                        part->size -= part->offset;
308                        part->offset += off;
309
310                        goto found;
311                }
312        }
313
314        printk(KERN_EMERG
315               "%s: Couldn't find root filesystem\n",
316               mtd->name);
317        return -1;
318
319 found:
320        if (part->size == 0)
321                return 0;
322       
323        if (MTD_READ(mtd, part->offset, sizeof(buf), &len, buf) || len != sizeof(buf))
324                return 0;
325
326        if (*((__u32 *) buf) == SQUASHFS_MAGIC) {
327                printk(KERN_EMERG  "%s: Filesystem type: squashfs, size=0x%x\n", mtd->name, (u32) sb->bytes_used);
328
329                /* Update the squashfs partition size based on the superblock info */
330                part->size = sb->bytes_used;
331                //part->size = part->size + 1024; /* uncomment for belkin v2000 ! */
332                len = part->offset + part->size;
333                len +=  (mtd->erasesize - 1);
334                len &= ~(mtd->erasesize - 1);
335                part->size = len - part->offset;
336                printk(KERN_EMERG "partition size = %d\n",part->size);
337        } else if (*((__u16 *) buf) == JFFS2_MAGIC_BITMASK) {
338                printk(KERN_EMERG  "%s: Filesystem type: jffs2\n", mtd->name);
339
340                /* Move the squashfs outside of the trx */
341                part->size = 0;
342        } else {
343                printk(KERN_EMERG  "%s: Filesystem type: unknown\n", mtd->name);
344                return 0;
345        }
346
347        if (trx.len != part->offset + part->size - off) {
348                /* Update the trx offsets and length */
349                trx.len = part->offset + part->size - off;
350//              printk(KERN_EMERG "update crc32\n");
351                /* Update the trx crc32 */
352                for (i = (u32) &(((struct trx_header *)NULL)->flag_version); i <= trx.len; i += sizeof(buf)) {
353//                      printk(KERN_EMERG "read from %d\n",off + i);
354                        if (MTD_READ(mtd, off + i, sizeof(buf), &len, buf) || len != sizeof(buf))
355                                return 0;
356                        crc = crc32_le(crc, buf, min(sizeof(buf), trx.len - i));
357                }
358                trx.crc32 = crc;
359
360//                      printk(KERN_EMERG "malloc\n",off + i);
361                /* read first eraseblock from the trx */
362                trx2 = block = vmalloc(mtd->erasesize);
363                if (MTD_READ(mtd, off, mtd->erasesize, &len, block) || len != mtd->erasesize) {
364                        printk(KERN_EMERG "Error accessing the first trx eraseblock\n");
365                        vfree(block);
366                        return 0;
367                }
368               
369                printk(KERN_EMERG "Updating TRX offsets and length:\n");
370                printk(KERN_EMERG "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);
371                printk(KERN_EMERG "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);
372
373                /* Write updated trx header to the flash */
374                memcpy(block, &trx, sizeof(trx));
375                if (mtd->unlock)
376                        mtd->unlock(mtd, off, mtd->erasesize);
377                erase_write(mtd, off, mtd->erasesize, block);
378                if (mtd->sync)
379                        mtd->sync(mtd);
380                vfree(block);
381                printk(KERN_EMERG "Done\n");
382               
383                /* Write fake Netgear checksum to the flash */         
384                uint boardnum = bcm_strtoul( nvram_safe_get( "boardnum" ), NULL, 0 );
385                if ( (boardnum == 83258 || boardnum == 1 || boardnum == 0123)  //or 01 or 001 or 0x01
386                && (nvram_match("boardtype", "0x048e") || nvram_match("boardtype", "0x48E"))
387                && (nvram_match("boardrev", "0x11") || nvram_match("boardrev", "0x10"))
388                && (nvram_match("boardflags", "0x750") || nvram_match("boardflags", "0x0750"))
389                &&  nvram_match ("sdram_init", "0x000A") ) {
390#define WGR614_CHECKSUM_BLOCK_START    0x003A0000
391#define WGR614_CHECKSUM_OFF            0x003AFFF8
392#define WGR614_FAKE_LEN                0x00000004  //we fake checksum only over 4 bytes (HDR0)
393#define WGR614_FAKE_CHK                0x02C0010E
394                /*
395                 * Read into buffer
396                 */
397                block = vmalloc(mtd->erasesize);
398                if (MTD_READ(mtd, WGR614_CHECKSUM_BLOCK_START, mtd->erasesize, &len, block) ||
399                    len != mtd->erasesize) {
400                        printk(KERN_EMERG "Error accessing the WGR614 checksum eraseblock\n");
401                        vfree(block);
402                        }
403                        else {
404                        char imageInfo[8];
405                        u32 fake_len = le32_to_cpu(WGR614_FAKE_LEN);
406                        u32 fake_chk = le32_to_cpu(WGR614_FAKE_CHK);
407                        memcpy(&imageInfo[0], (char *)&fake_len, 4);
408                        memcpy(&imageInfo[4], (char *)&fake_chk, 4);
409                        char *tmp;     
410                        tmp = block + ((WGR614_CHECKSUM_OFF - WGR614_CHECKSUM_BLOCK_START) % mtd->erasesize);
411                        memcpy( tmp, imageInfo, sizeof( imageInfo ) );
412                        if (mtd->unlock)
413                                mtd->unlock(mtd, WGR614_CHECKSUM_BLOCK_START, mtd->erasesize);
414                        erase_write(mtd, WGR614_CHECKSUM_BLOCK_START, mtd->erasesize, block);
415                        if (mtd->sync)
416                                mtd->sync(mtd);
417                        vfree(block);
418                        printk(KERN_EMERG "Done fixing WGR614 checksum\n");               
419                        }
420                }       
421               
422               
423        }
424       
425        return part->size;
426}
427
428struct mtd_partition * __init
429init_mtd_partitions(struct mtd_info *mtd, size_t size)
430{
431        int cfe_size;
432
433        int board_data_size = 0; // e.g Netgear 0x003e0000-0x003f0000 : "board_data", we exclude this part from our mapping
434        int jffs_exclude_size = 0;  // to prevent overwriting len/checksum on e.g. Netgear WGR614v8/L/WW
435       
436        uint boardnum = bcm_strtoul( nvram_safe_get( "boardnum" ), NULL, 0 );   
437               
438        if ( (boardnum == 8 || boardnum == 01)
439          && nvram_match ("boardtype", "0x0472")
440          && nvram_match ("cardbus", "1") ) {
441                board_data_size = 4 * 0x10000;  //Netgear WNR834B, Netgear WNR834Bv2
442                jffs_exclude_size = 0x10000;    //checksum is @ 0x003AFFF8             
443        }
444
445        if ( boardnum == 01
446          && nvram_match ("boardtype", "0x0472")
447          && nvram_match ("boardrev", "0x23") ) {
448                board_data_size = 4 * 0x10000;  //Netgear WNDR-3300
449                jffs_exclude_size = 0x10000;    //checksum is @ 0x003AFFF8             
450        }       
451       
452        if ( (boardnum == 83258 || boardnum == 01)  //or 001 or 0x01
453          && (nvram_match("boardtype", "0x048e") || nvram_match("boardtype", "0x48E"))
454          && (nvram_match("boardrev", "0x11") || nvram_match("boardrev", "0x10"))
455          && (nvram_match("boardflags", "0x750") || nvram_match("boardflags", "0x0750"))
456          &&  nvram_match ("sdram_init", "0x000A") ) {
457                board_data_size = 4 * 0x10000;  //Netgear WGR614v8/L/WW 16MB ram, cfe v1.3 or v1.5
458                jffs_exclude_size = 0x10000;    //checksum is @ 0x003AFFF8
459        }                                                                                                                               
460
461        if ((cfe_size = find_cfe_size(mtd,size)) < 0)
462                return NULL;
463
464        /* boot loader */
465        bcm947xx_parts[0].offset = 0;
466        bcm947xx_parts[0].size   = cfe_size;
467
468        /* nvram */
469        if (cfe_size != 384 * 1024) {
470                bcm947xx_parts[3].offset = size - ROUNDUP(NVRAM_SPACE, mtd->erasesize);
471                bcm947xx_parts[3].size   = ROUNDUP(NVRAM_SPACE, mtd->erasesize);
472        } else {
473                /* nvram (old 128kb config partition on netgear wgt634u) */
474                bcm947xx_parts[3].offset = bcm947xx_parts[0].size;
475                bcm947xx_parts[3].size   = ROUNDUP(NVRAM_SPACE, mtd->erasesize);
476        }
477
478        /* linux (kernel and rootfs) */
479        if (cfe_size != 384 * 1024) {
480                bcm947xx_parts[1].offset = bcm947xx_parts[0].size;
481                bcm947xx_parts[1].size   = (bcm947xx_parts[3].offset - bcm947xx_parts[1].offset) - board_data_size;
482        } else {
483                /* do not count the elf loader, which is on one block */
484                bcm947xx_parts[1].offset = bcm947xx_parts[0].size +
485                        bcm947xx_parts[3].size + mtd->erasesize;
486                bcm947xx_parts[1].size   = (((size - bcm947xx_parts[0].size) - (2*bcm947xx_parts[3].size)) - mtd->erasesize) - board_data_size;
487        }
488
489        /* find and size rootfs */
490        if (find_root(mtd,size,&bcm947xx_parts[2])==0) {
491                /* entirely jffs2 */
492                bcm947xx_parts[4].name = NULL;
493                bcm947xx_parts[2].size = (size - bcm947xx_parts[2].offset) - bcm947xx_parts[3].size;
494        } else {
495                /* legacy setup */
496                /* calculate leftover flash, and assign it to the jffs2 partition */
497                if (cfe_size != 384 * 1024) {
498                        bcm947xx_parts[4].offset = bcm947xx_parts[2].offset +
499                                bcm947xx_parts[2].size;
500                        if ((bcm947xx_parts[4].offset % mtd->erasesize) > 0) {
501                                bcm947xx_parts[4].offset += mtd->erasesize -
502                                        (bcm947xx_parts[4].offset % mtd->erasesize);
503                        }
504                        bcm947xx_parts[4].size = ((bcm947xx_parts[3].offset - bcm947xx_parts[4].offset) - board_data_size) - jffs_exclude_size;
505                } else {
506                        bcm947xx_parts[4].offset = bcm947xx_parts[2].offset +
507                                bcm947xx_parts[2].size;
508                        if ((bcm947xx_parts[4].offset % mtd->erasesize) > 0) {
509                                bcm947xx_parts[4].offset += mtd->erasesize -
510                                        (bcm947xx_parts[4].offset % mtd->erasesize);
511                        }
512                        bcm947xx_parts[4].size = (((size - bcm947xx_parts[3].size) - bcm947xx_parts[4].offset) - board_data_size) - jffs_exclude_size;
513                }
514                /* do not make zero size jffs2 partition  */
515                if (bcm947xx_parts[4].size < mtd->erasesize) {
516                        bcm947xx_parts[4].name = NULL;
517                }
518        }
519
520        return bcm947xx_parts;
521}
522
523#endif
524
525
526mod_init_t init_bcm947xx_map(void)
527{
528        ulong flags;
529        uint coreidx;
530        chipcregs_t *cc;
531        uint32 fltype;
532        uint window_addr = 0, window_size = 0;
533        size_t size;
534        int ret = 0;
535#ifdef CONFIG_MTD_PARTITIONS
536        struct mtd_partition *parts;
537        int i;
538#endif
539
540        spin_lock_irqsave(&sbh_lock, flags);
541        coreidx = sb_coreidx(sbh);
542
543        /* Check strapping option if chipcommon exists */
544        if ((cc = sb_setcore(sbh, SB_CC, 0))) {
545                fltype = readl(&cc->capabilities) & CC_CAP_FLASH_MASK;
546                if (fltype == PFLASH) {
547                        bcm947xx_map.map_priv_2 = 1;
548                        window_addr = 0x1c000000;
549                        bcm947xx_map.size = window_size = 32 * 1024 * 1024;
550                        if ((readl(&cc->flash_config) & CC_CFG_DS) == 0)
551                                bcm947xx_map.buswidth = 1;
552                }
553        } else {
554                fltype = PFLASH;
555                bcm947xx_map.map_priv_2 = 0;
556                window_addr = WINDOW_ADDR;
557                window_size = WINDOW_SIZE;
558        }
559
560        sb_setcoreidx(sbh, coreidx);
561        spin_unlock_irqrestore(&sbh_lock, flags);
562
563        if (fltype != PFLASH) {
564                printk(KERN_ERR "pflash: found no supported devices\n");
565                ret = -ENODEV;
566                goto fail;
567        }
568
569        bcm947xx_map.map_priv_1 = (unsigned long) ioremap(window_addr, window_size);
570
571        if (!bcm947xx_map.map_priv_1) {
572                printk(KERN_ERR "Failed to ioremap\n");
573                return -EIO;
574        }
575
576        if (!(bcm947xx_mtd = do_map_probe("cfi_probe", &bcm947xx_map))) {
577                printk(KERN_ERR "pflash: cfi_probe failed\n");
578                iounmap((void *)bcm947xx_map.map_priv_1);
579                return -ENXIO;
580        }
581
582        bcm947xx_mtd->module = THIS_MODULE;
583
584        size = bcm947xx_mtd->size;
585
586        printk(KERN_EMERG "Flash device: 0x%x at 0x%x\n", size, window_addr);
587
588#ifdef CONFIG_MTD_PARTITIONS
589        parts = init_mtd_partitions(bcm947xx_mtd, size);
590        for (i = 0; parts[i].name; i++);
591        ret = add_mtd_partitions(bcm947xx_mtd, parts, i);
592        if (ret) {
593                printk(KERN_ERR "Flash: add_mtd_partitions failed\n");
594                goto fail;
595        }
596#endif
597
598        return 0;
599
600 fail:
601        if (bcm947xx_mtd)
602                map_destroy(bcm947xx_mtd);
603        if (bcm947xx_map.map_priv_1)
604                iounmap((void *) bcm947xx_map.map_priv_1);
605        bcm947xx_map.map_priv_1 = 0;
606        return ret;
607}
608
609mod_exit_t cleanup_bcm947xx_map(void)
610{
611#ifdef CONFIG_MTD_PARTITIONS
612        del_mtd_partitions(bcm947xx_mtd);
613#endif
614        map_destroy(bcm947xx_mtd);
615        iounmap((void *) bcm947xx_map.map_priv_1);
616        bcm947xx_map.map_priv_1 = 0;
617}
618
619module_init(init_bcm947xx_map);
620module_exit(cleanup_bcm947xx_map);
Note: See TracBrowser for help on using the repository browser.