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>
20 #include <bcm_map_part.h>
23 extern PFILE_TAG kerSysImageTagGet(void);
25 static struct mtd_info *mymtd;
27 static map_word brcm_physmap_read16(struct map_info *map, unsigned long ofs)
31 /* If the requested flash address is in a memory mapped range, use
32 * __raw_readw. Otherwise, use kerSysReadFromFlash.
34 if(((map->map_priv_1 & ~0xfff00000) + ofs + sizeof(short)) < map->map_priv_2)
35 val.x[0] = __raw_readw(map->map_priv_1 + ofs);
37 kerSysReadFromFlash( &val.x[0], map->map_priv_1 + ofs, sizeof(short) );
42 static void brcm_physmap_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
44 /* If the requested flash address is in a memory mapped range, use
45 * memcpy_fromio. Otherwise, use kerSysReadFromFlash.
47 if( ((map->map_priv_1 & ~0xfff00000) + from + len) < map->map_priv_2 )
48 memcpy_fromio(to, map->map_priv_1 + from, len);
50 kerSysReadFromFlash( to, map->map_priv_1 + from, len );
53 static struct map_info brcm_physmap_map = {
54 .name = "Physically mapped flash",
56 .read = brcm_physmap_read16,
57 .copy_from = brcm_physmap_copy_from
60 static int __init init_brcm_physmap(void)
62 PFILE_TAG pTag = NULL;
63 u_int32_t rootfs_addr, kernel_addr;
65 printk("bcm963xx_mtd driver v%s\n", VERSION);
67 /* Read the flash memory map from flash memory. */
68 if (!(pTag = kerSysImageTagGet())) {
69 printk("Failed to read image tag from flash\n");
73 rootfs_addr = (u_int32_t) simple_strtoul(pTag->rootfsAddress, NULL, 10) + BOOT_OFFSET;
74 kernel_addr = (u_int32_t) simple_strtoul(pTag->kernelAddress, NULL, 10) + BOOT_OFFSET;
76 brcm_physmap_map.size = kernel_addr - rootfs_addr;
77 brcm_physmap_map.map_priv_1 = (unsigned long)rootfs_addr;
79 /* Set map_priv_2 to the amount of flash memory that is memory mapped to
80 * the flash base address. On the BCM6338, serial flash parts are only
81 * memory mapped up to 1MB even though the flash part may be bigger.
83 brcm_physmap_map.map_priv_2 =(unsigned long)kerSysMemoryMappedFlashSizeGet();
85 if (!brcm_physmap_map.map_priv_1) {
86 printk("Wrong rootfs starting address\n");
90 if (brcm_physmap_map.size <= 0) {
91 printk("Wrong rootfs size\n");
95 mymtd = do_map_probe("map_rom", &brcm_physmap_map);
97 mymtd->owner = THIS_MODULE;
98 add_mtd_device(mymtd);
106 static void __exit cleanup_brcm_physmap(void)
109 del_mtd_device(mymtd);
112 if (brcm_physmap_map.map_priv_1) {
113 brcm_physmap_map.map_priv_1 = 0;
117 module_init(init_brcm_physmap);
118 module_exit(cleanup_brcm_physmap);
121 MODULE_LICENSE("GPL");
122 MODULE_AUTHOR("Song Wang songw@broadcom.com");
123 MODULE_DESCRIPTION("Configurable MTD map driver for read-only root file system");