2 * $Id: cstm_mips_ixx.c,v 1.14 2005/11/07 11:14:26 gleixner Exp $
4 * Mapping of a custom board with both AMD CFI and JEDEC flash in partitions.
5 * Config with both CFI and JEDEC device support.
7 * Basically physmap.c with the addition of partitions and
8 * an array of mapping info to accomodate more than one flash type per board.
10 * Copyright 2000 MontaVista Software Inc.
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
20 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * You should have received a copy of the GNU General Public License along
29 * with this program; if not, write to the Free Software Foundation, Inc.,
30 * 675 Mass Ave, Cambridge, MA 02139, USA.
33 #include <linux/module.h>
34 #include <linux/types.h>
35 #include <linux/kernel.h>
36 #include <linux/init.h>
38 #include <linux/mtd/mtd.h>
39 #include <linux/mtd/map.h>
40 #include <linux/mtd/partitions.h>
41 #include <linux/delay.h>
43 /* board and partition description */
45 #define MAX_PHYSMAP_PARTITIONS 8
46 struct cstm_mips_ixx_info
{
48 unsigned long window_addr
;
49 unsigned long window_size
;
54 #define PHYSMAP_NUMBER 1 // number of board desc structs needed, one per contiguous flash type
55 const struct cstm_mips_ixx_info cstm_mips_ixx_board_desc
[PHYSMAP_NUMBER
] =
59 CONFIG_MTD_CSTM_MIPS_IXX_START
, // window_addr
60 CONFIG_MTD_CSTM_MIPS_IXX_LEN
, // window_size
61 CONFIG_MTD_CSTM_MIPS_IXX_BUSWIDTH
, // bankwidth
66 static struct mtd_partition cstm_mips_ixx_partitions
[PHYSMAP_NUMBER
][MAX_PHYSMAP_PARTITIONS
] = {
69 .name
= "main partition",
70 .size
= CONFIG_MTD_CSTM_MIPS_IXX_LEN
,
76 struct map_info cstm_mips_ixx_map
[PHYSMAP_NUMBER
];
78 int __init
init_cstm_mips_ixx(void)
82 struct mtd_info
*mymtd
;
83 struct mtd_partition
*parts
;
85 /* Initialize mapping */
86 for (i
=0;i
<PHYSMAP_NUMBER
;i
++) {
87 printk(KERN_NOTICE
"cstm_mips_ixx flash device: 0x%lx at 0x%lx\n",
88 cstm_mips_ixx_board_desc
[i
].window_size
, cstm_mips_ixx_board_desc
[i
].window_addr
);
91 cstm_mips_ixx_map
[i
].phys
= cstm_mips_ixx_board_desc
[i
].window_addr
;
92 cstm_mips_ixx_map
[i
].virt
= ioremap(cstm_mips_ixx_board_desc
[i
].window_addr
, cstm_mips_ixx_board_desc
[i
].window_size
);
93 if (!cstm_mips_ixx_map
[i
].virt
) {
95 printk(KERN_WARNING
"Failed to ioremap\n");
96 for (j
= 0; j
< i
; j
++) {
97 if (cstm_mips_ixx_map
[j
].virt
) {
98 iounmap(cstm_mips_ixx_map
[j
].virt
);
99 cstm_mips_ixx_map
[j
].virt
= NULL
;
104 cstm_mips_ixx_map
[i
].name
= cstm_mips_ixx_board_desc
[i
].name
;
105 cstm_mips_ixx_map
[i
].size
= cstm_mips_ixx_board_desc
[i
].window_size
;
106 cstm_mips_ixx_map
[i
].bankwidth
= cstm_mips_ixx_board_desc
[i
].bankwidth
;
107 simple_map_init(&cstm_mips_ixx_map
[i
]);
108 //printk(KERN_NOTICE "cstm_mips_ixx: ioremap is %x\n",(unsigned int)(cstm_mips_ixx_map[i].virt));
111 for (i
=0;i
<PHYSMAP_NUMBER
;i
++) {
112 parts
= &cstm_mips_ixx_partitions
[i
][0];
114 mymtd
= (struct mtd_info
*)do_map_probe("cfi_probe", &cstm_mips_ixx_map
[i
]);
115 //printk(KERN_NOTICE "phymap %d cfi_probe: mymtd is %x\n",i,(unsigned int)mymtd);
118 mymtd
= (struct mtd_info
*)do_map_probe("jedec_probe", &cstm_mips_ixx_map
[i
]);
119 printk(KERN_NOTICE
"cstm_mips_ixx %d jedec: mymtd is %x\n",i
,(unsigned int)mymtd
);
122 mymtd
->owner
= THIS_MODULE
;
124 cstm_mips_ixx_map
[i
].map_priv_2
= (unsigned long)mymtd
;
125 add_mtd_partitions(mymtd
, parts
, cstm_mips_ixx_board_desc
[i
].num_partitions
);
128 for (i
= 0; i
< PHYSMAP_NUMBER
; i
++) {
129 if (cstm_mips_ixx_map
[i
].virt
) {
130 iounmap(cstm_mips_ixx_map
[i
].virt
);
131 cstm_mips_ixx_map
[i
].virt
= NULL
;
140 static void __exit
cleanup_cstm_mips_ixx(void)
143 struct mtd_info
*mymtd
;
145 for (i
=0;i
<PHYSMAP_NUMBER
;i
++) {
146 mymtd
= (struct mtd_info
*)cstm_mips_ixx_map
[i
].map_priv_2
;
148 del_mtd_partitions(mymtd
);
151 if (cstm_mips_ixx_map
[i
].virt
) {
152 iounmap((void *)cstm_mips_ixx_map
[i
].virt
);
153 cstm_mips_ixx_map
[i
].virt
= 0;
158 module_init(init_cstm_mips_ixx
);
159 module_exit(cleanup_cstm_mips_ixx
);
162 MODULE_LICENSE("GPL");
163 MODULE_AUTHOR("Alice Hennessy <ahennessy@mvista.com>");
164 MODULE_DESCRIPTION("MTD map driver for MIPS boards");