01c0e7985deb9cb8d04ff4f6d1cb69a44a2238c6
[bcm963xx.git] / kernel / linux / drivers / mtd / maps / bcm963xx.c
1 /*
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
5  *
6  *  Song Wang (songw@broadcom.com)
7  */
8
9 #include <linux/module.h>
10 #include <linux/types.h>
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <asm/io.h>
14 #include <linux/mtd/mtd.h>
15 #include <linux/mtd/map.h>
16 #include <linux/config.h>
17
18 #include <board.h>
19 #include <bcmTag.h>
20 #define  VERSION        "1.0"
21
22 extern PFILE_TAG kerSysImageTagGet(void);
23
24 static struct mtd_info *mymtd;
25
26 static map_word brcm_physmap_read16(struct map_info *map, unsigned long ofs)
27 {
28         map_word val;
29         
30         val.x[0] = __raw_readw(map->map_priv_1 + ofs);
31         
32         return val;
33 }
34
35 static void brcm_physmap_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
36 {
37         memcpy_fromio(to, map->map_priv_1 + from, len);
38 }
39
40 static struct map_info brcm_physmap_map = {
41         .name           = "Physically mapped flash",
42         .bankwidth      = 2,
43         .read           = brcm_physmap_read16,
44         .copy_from      = brcm_physmap_copy_from
45 };
46
47 static int __init init_brcm_physmap(void)
48 {
49         PFILE_TAG pTag = NULL;
50         u_int32_t rootfs_addr, kernel_addr;
51         FLASH_ADDR_INFO info;
52
53         printk("bcm963xx_mtd driver v%s\n", VERSION);
54         kerSysFlashAddrInfoGet( &info );
55
56         /* Read the flash memory map from flash memory. */
57         if (!(pTag = kerSysImageTagGet())) {
58                 printk("Failed to read image tag from flash\n");
59                 return -EIO;
60         }
61
62         rootfs_addr = (u_int32_t) simple_strtoul(pTag->rootfsAddress, NULL, 10);
63         kernel_addr = (u_int32_t) simple_strtoul(pTag->kernelAddress, NULL, 10);
64         
65         brcm_physmap_map.size = kernel_addr - rootfs_addr;
66         brcm_physmap_map.map_priv_1 = (unsigned long)rootfs_addr;
67
68         if (!brcm_physmap_map.map_priv_1) {
69                 printk("Wrong rootfs starting address\n");
70                 return -EIO;
71         }
72         
73         if (brcm_physmap_map.size <= 0) {
74                 printk("Wrong rootfs size\n");
75                 return -EIO;
76         }       
77         
78         mymtd = do_map_probe("map_rom", &brcm_physmap_map);
79         if (mymtd) {
80                 mymtd->owner = THIS_MODULE;
81                 add_mtd_device(mymtd);
82
83                 return 0;
84         }
85
86         return -ENXIO;
87 }
88
89 static void __exit cleanup_brcm_physmap(void)
90 {
91         if (mymtd) {
92                 del_mtd_device(mymtd);
93                 map_destroy(mymtd);
94         }
95         if (brcm_physmap_map.map_priv_1) {
96                 brcm_physmap_map.map_priv_1 = 0;
97         }
98 }
99
100 module_init(init_brcm_physmap);
101 module_exit(cleanup_brcm_physmap);
102
103
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");