2 * Map for flash chips on Wind River PowerQUICC II SBC82xx board.
4 * Copyright (C) 2004 Red Hat, Inc.
6 * Author: David Woodhouse <dwmw2@infradead.org>
10 #include <linux/module.h>
11 #include <linux/types.h>
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/slab.h>
16 #include <linux/mtd/mtd.h>
17 #include <linux/mtd/map.h>
18 #include <linux/mtd/partitions.h>
20 #include <asm/immap_cpm2.h>
22 static struct mtd_info
*sbcmtd
[3];
23 static struct mtd_partition
*sbcmtd_parts
[3];
25 struct map_info sbc82xx_flash_map
[3] = {
26 {.name
= "Boot flash"},
27 {.name
= "Alternate boot flash"},
28 {.name
= "User flash"}
31 static struct mtd_partition smallflash_parts
[] = {
38 .size
= MTDPART_SIZ_FULL
,
39 .offset
= MTDPART_OFS_APPEND
,
43 static struct mtd_partition bigflash_parts
[] = {
49 .name
= "file system",
51 .offset
= MTDPART_OFS_APPEND
,
53 .name
= "boot config",
55 .offset
= MTDPART_OFS_APPEND
,
59 .offset
= MTDPART_OFS_APPEND
,
63 static const char *part_probes
[] __initdata
= {"cmdlinepart", "RedBoot", NULL
};
65 #define init_sbc82xx_one_flash(map, br, or) \
67 (map).phys = (br & 1) ? (br & 0xffff8000) : 0; \
68 (map).size = (br & 1) ? (~(or & 0xffff8000) + 1) : 0; \
69 switch (br & 0x00001800) { \
71 case 0x00000800: (map).bankwidth = 1; break; \
72 case 0x00001000: (map).bankwidth = 2; break; \
73 case 0x00001800: (map).bankwidth = 4; break; \
77 static int __init
init_sbc82xx_flash(void)
79 volatile memctl_cpm2_t
*mc
= &cpm2_immr
->im_memctl
;
84 mc
= ioremap(0xff700000 + 0x5000, sizeof(memctl_cpm2_t
));
86 mc
= &cpm2_immr
->im_memctl
;
90 if ((mc
->memc_br0
& 0x00001800) == 0x00001800)
93 init_sbc82xx_one_flash(sbc82xx_flash_map
[0], mc
->memc_br0
, mc
->memc_or0
);
94 init_sbc82xx_one_flash(sbc82xx_flash_map
[1], mc
->memc_br6
, mc
->memc_or6
);
95 init_sbc82xx_one_flash(sbc82xx_flash_map
[2], mc
->memc_br1
, mc
->memc_or1
);
101 for (i
=0; i
<3; i
++) {
102 int8_t flashcs
[3] = { 0, 6, 1 };
105 printk(KERN_NOTICE
"PowerQUICC II %s (%ld MiB on CS%d",
106 sbc82xx_flash_map
[i
].name
,
107 (sbc82xx_flash_map
[i
].size
>> 20),
109 if (!sbc82xx_flash_map
[i
].phys
) {
110 /* We know it can't be at zero. */
111 printk("): disabled by bootloader.\n");
114 printk(" at %08lx)\n", sbc82xx_flash_map
[i
].phys
);
116 sbc82xx_flash_map
[i
].virt
= ioremap(sbc82xx_flash_map
[i
].phys
, sbc82xx_flash_map
[i
].size
);
118 if (!sbc82xx_flash_map
[i
].virt
) {
119 printk("Failed to ioremap\n");
123 simple_map_init(&sbc82xx_flash_map
[i
]);
125 sbcmtd
[i
] = do_map_probe("cfi_probe", &sbc82xx_flash_map
[i
]);
130 sbcmtd
[i
]->owner
= THIS_MODULE
;
132 nr_parts
= parse_mtd_partitions(sbcmtd
[i
], part_probes
,
133 &sbcmtd_parts
[i
], 0);
135 add_mtd_partitions (sbcmtd
[i
], sbcmtd_parts
[i
], nr_parts
);
139 /* No partitioning detected. Use default */
141 add_mtd_device(sbcmtd
[i
]);
142 } else if (i
== bigflash
) {
143 add_mtd_partitions (sbcmtd
[i
], bigflash_parts
, ARRAY_SIZE(bigflash_parts
));
145 add_mtd_partitions (sbcmtd
[i
], smallflash_parts
, ARRAY_SIZE(smallflash_parts
));
151 static void __exit
cleanup_sbc82xx_flash(void)
155 for (i
=0; i
<3; i
++) {
159 if (i
<2 || sbcmtd_parts
[i
])
160 del_mtd_partitions(sbcmtd
[i
]);
162 del_mtd_device(sbcmtd
[i
]);
164 kfree(sbcmtd_parts
[i
]);
165 map_destroy(sbcmtd
[i
]);
167 iounmap((void *)sbc82xx_flash_map
[i
].virt
);
168 sbc82xx_flash_map
[i
].virt
= 0;
172 module_init(init_sbc82xx_flash
);
173 module_exit(cleanup_sbc82xx_flash
);
176 MODULE_LICENSE("GPL");
177 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
178 MODULE_DESCRIPTION("Flash map driver for WindRiver PowerQUICC II");