2 * Flash mapping for BCM947XX boards
4 * Copyright (C) 2009, Broadcom Corporation
7 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
8 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
9 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
10 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
12 * $Id: bcm947xx-flash.c,v 1.6 2009/07/27 07:34:33 Exp $
15 #include <linux/module.h>
16 #include <linux/types.h>
17 #include <linux/kernel.h>
18 #include <linux/init.h>
20 #include <linux/mtd/mtd.h>
21 #include <linux/mtd/map.h>
22 #include <linux/mtd/partitions.h>
23 #include <linux/config.h>
33 /* Global SB handle */
34 extern void *bcm947xx_sih
;
35 extern spinlock_t bcm947xx_sih_lock
;
38 #define sih bcm947xx_sih
39 #define sih_lock bcm947xx_sih_lock
41 #ifdef CONFIG_MTD_PARTITIONS
42 extern struct mtd_partition
* init_mtd_partitions(struct mtd_info
*mtd
, size_t size
);
45 extern struct mutex
*partitions_mutex_init(void);
47 #define WINDOW_ADDR 0x1fc00000
48 #define WINDOW_SIZE 0x400000
51 /* e.g., flash=2M or flash=4M */
53 module_param(flash
, int, 0);
55 bcm947xx_setup(char *str
)
57 flash
= memparse(str
, &str
);
60 __setup("flash=", bcm947xx_setup
);
62 static struct mtd_info
*bcm947xx_mtd
;
65 #if LINUX_VERSION_CODE < 0x20212 && defined(MODULE)
66 #define init_bcm947xx_map init_module
67 #define cleanup_bcm947xx_map cleanup_module
70 struct map_info bcm947xx_map
= {
71 .name
= "Physically mapped flash",
77 init_bcm947xx_map(void)
83 uint window_addr
= 0, window_size
= 0;
86 #ifdef CONFIG_MTD_PARTITIONS
87 struct mtd_partition
*parts
;
91 spin_lock_irqsave(&sih_lock
, flags
);
92 coreidx
= si_coreidx(sih
);
94 /* Check strapping option if chipcommon exists */
95 if ((cc
= si_setcore(sih
, CC_CORE_ID
, 0))) {
96 fltype
= readl(&cc
->capabilities
) & CC_CAP_FLASH_MASK
;
97 if (fltype
== PFLASH
) {
98 bcm947xx_map
.map_priv_2
= 1;
99 window_addr
= 0x1c000000;
100 bcm947xx_map
.size
= window_size
= 32 * 1024 * 1024;
101 if ((readl(&cc
->flash_config
) & CC_CFG_DS
) == 0)
102 bcm947xx_map
.bankwidth
= 1;
106 bcm947xx_map
.map_priv_2
= 0;
107 window_addr
= WINDOW_ADDR
;
108 bcm947xx_map
.size
= window_size
= WINDOW_SIZE
;
111 si_setcoreidx(sih
, coreidx
);
112 spin_unlock_irqrestore(&sih_lock
, flags
);
114 if (fltype
!= PFLASH
) {
115 printk(KERN_ERR
"pflash: found no supported devices\n");
120 bcm947xx_map
.virt
= ioremap(window_addr
, window_size
);
121 if (bcm947xx_map
.virt
== NULL
) {
122 printk(KERN_ERR
"pflash: ioremap failed\n");
127 if ((bcm947xx_mtd
= do_map_probe("cfi_probe", &bcm947xx_map
)) == NULL
) {
128 printk(KERN_ERR
"pflash: cfi_probe failed\n");
133 bcm947xx_mtd
->owner
= THIS_MODULE
;
134 bcm947xx_mtd
->mutex
= partitions_mutex_init();
136 /* Allow size override for testing */
137 size
= flash
? : bcm947xx_mtd
->size
;
139 printk(KERN_NOTICE
"Flash device: 0x%x at 0x%x\n", size
, window_addr
);
141 #ifdef CONFIG_MTD_PARTITIONS
142 parts
= init_mtd_partitions(bcm947xx_mtd
, size
);
143 for (i
= 0; parts
[i
].name
; i
++);
144 ret
= add_mtd_partitions(bcm947xx_mtd
, parts
, i
);
146 printk(KERN_ERR
"pflash: add_mtd_partitions failed\n");
155 map_destroy(bcm947xx_mtd
);
156 if (bcm947xx_map
.map_priv_1
)
157 iounmap((void *) bcm947xx_map
.map_priv_1
);
158 bcm947xx_map
.map_priv_1
= 0;
163 cleanup_bcm947xx_map(void)
165 #ifdef CONFIG_MTD_PARTITIONS
166 del_mtd_partitions(bcm947xx_mtd
);
168 map_destroy(bcm947xx_mtd
);
169 iounmap((void *) bcm947xx_map
.map_priv_1
);
170 bcm947xx_map
.map_priv_1
= 0;
173 module_init(init_bcm947xx_map
);
174 module_exit(cleanup_bcm947xx_map
);