2 * A simple flash mapping code for BCM963xx board flash memory
3 * It is simple because it only treats all the flash memory as ROM
4 * It is used with chips/map_rom.c
6 * Song Wang (songw@broadcom.com)
9 #include <linux/module.h>
10 #include <linux/types.h>
11 #include <linux/kernel.h>
12 #include <linux/init.h>
14 #include <linux/mtd/mtd.h>
15 #include <linux/mtd/map.h>
16 #include <linux/config.h>
22 extern PFILE_TAG kerSysImageTagGet(void);
24 static struct mtd_info *mymtd;
26 static map_word brcm_physmap_read16(struct map_info *map, unsigned long ofs)
30 val.x[0] = __raw_readw(map->map_priv_1 + ofs);
35 static void brcm_physmap_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
37 memcpy_fromio(to, map->map_priv_1 + from, len);
40 static struct map_info brcm_physmap_map = {
41 .name = "Physically mapped flash",
43 .read = brcm_physmap_read16,
44 .copy_from = brcm_physmap_copy_from
47 static int __init init_brcm_physmap(void)
49 PFILE_TAG pTag = NULL;
50 u_int32_t rootfs_addr, kernel_addr;
53 printk("bcm963xx_mtd driver v%s\n", VERSION);
54 kerSysFlashAddrInfoGet( &info );
56 /* Read the flash memory map from flash memory. */
57 if (!(pTag = kerSysImageTagGet())) {
58 printk("Failed to read image tag from flash\n");
62 rootfs_addr = (u_int32_t) simple_strtoul(pTag->rootfsAddress, NULL, 10);
63 kernel_addr = (u_int32_t) simple_strtoul(pTag->kernelAddress, NULL, 10);
65 brcm_physmap_map.size = kernel_addr - rootfs_addr;
66 brcm_physmap_map.map_priv_1 = (unsigned long)rootfs_addr;
68 if (!brcm_physmap_map.map_priv_1) {
69 printk("Wrong rootfs starting address\n");
73 if (brcm_physmap_map.size <= 0) {
74 printk("Wrong rootfs size\n");
78 mymtd = do_map_probe("map_rom", &brcm_physmap_map);
80 mymtd->owner = THIS_MODULE;
81 add_mtd_device(mymtd);
89 static void __exit cleanup_brcm_physmap(void)
92 del_mtd_device(mymtd);
95 if (brcm_physmap_map.map_priv_1) {
96 brcm_physmap_map.map_priv_1 = 0;
100 module_init(init_brcm_physmap);
101 module_exit(cleanup_brcm_physmap);
104 MODULE_LICENSE("GPL");
105 MODULE_AUTHOR("Song Wang songw@broadcom.com");
106 MODULE_DESCRIPTION("Configurable MTD map driver for read-only root file system");