2 * $Id: physmap64.c,v 1.1 2002/09/05 05:12:32 acurtis Exp $
4 * Normal mappings of chips in physical memory
7 #include <linux/module.h>
8 #include <linux/types.h>
9 #include <linux/kernel.h>
11 #include <linux/mtd/mtd.h>
12 #include <linux/mtd/map.h>
13 #include <linux/config.h>
14 #include <linux/mtd/cfi.h>
16 #ifdef CONFIG_MTD_PARTITIONS
17 #include <linux/mtd/partitions.h>
20 #define WINDOW_ADDR CONFIG_MTD_PHYSMAP_START
21 #define WINDOW_SIZE CONFIG_MTD_PHYSMAP_LEN
22 #define BUSWIDTH CONFIG_MTD_PHYSMAP_BUSWIDTH
24 static struct mtd_info *mymtd;
26 __u8 physmap_read8(struct map_info *map, unsigned long ofs)
28 return __raw_readb(map->map_priv_1 + ofs);
31 __u16 physmap_read16(struct map_info *map, unsigned long ofs)
33 return __raw_readw(map->map_priv_1 + ofs);
36 __u32 physmap_read32(struct map_info *map, unsigned long ofs)
38 return __raw_readl(map->map_priv_1 + ofs);
41 __u64 physmap_read64(struct map_info *map, unsigned long ofs)
43 return __raw_readll(map->map_priv_1 + ofs);
46 void physmap_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
48 memcpy_fromio(to, map->map_priv_1 + from, len);
51 void physmap_write8(struct map_info *map, __u8 d, unsigned long adr)
53 __raw_writeb(d, map->map_priv_1 + adr);
57 void physmap_write16(struct map_info *map, __u16 d, unsigned long adr)
59 __raw_writew(d, map->map_priv_1 + adr);
63 void physmap_write32(struct map_info *map, __u32 d, unsigned long adr)
65 __raw_writel(d, map->map_priv_1 + adr);
69 void physmap_write64(struct map_info *map, __u64 d, unsigned long adr)
71 __raw_writell(d, map->map_priv_1 + adr);
75 void physmap_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
77 memcpy_toio(map->map_priv_1 + to, from, len);
80 struct map_info physmap_map = {
81 name: "Physically mapped flash",
85 read16: physmap_read16,
86 read32: physmap_read32,
87 read64: physmap_read64,
88 copy_from: physmap_copy_from,
89 write8: physmap_write8,
90 write16: physmap_write16,
91 write32: physmap_write32,
92 write64: physmap_write64,
93 copy_to: physmap_copy_to
96 #ifdef CONFIG_MTD_PARTITIONS
97 #ifdef CONFIG_MTD_CMDLINE_PARTS
98 static struct mtd_partition *mtd_parts = 0;
99 static int mtd_parts_nb = 0;
101 static struct mtd_partition physmap_partitions[] = {
102 /* Put your own partition definitions here */
108 mask_flags: MTD_WRITEABLE, /* force read-only */
112 offset: MTDPART_OFS_APPEND,
113 mask_flags: MTD_WRITEABLE, /* force read-only */
117 offset: MTDPART_OFS_APPEND,
118 mask_flags: MTD_WRITEABLE, /* force read-only */
121 size: MTDPART_SIZ_FULL,
122 offset: MTDPART_OFS_APPEND,
127 #define NUM_PARTITIONS (sizeof(physmap_partitions)/sizeof(struct mtd_partition))
132 int __init init_physmap(void)
134 static const char *rom_probe_types[] = { "cfi_probe", "jedec_probe", "map_rom", 0 };
137 printk(KERN_NOTICE "physmap flash device: %x at %x\n", WINDOW_SIZE, WINDOW_ADDR);
138 physmap_map.map_priv_1 = (unsigned long)ioremap(WINDOW_ADDR, WINDOW_SIZE);
140 if (!physmap_map.map_priv_1) {
141 printk("Failed to ioremap\n");
146 type = rom_probe_types;
147 for(; !mymtd && *type; type++) {
148 mymtd = do_map_probe(*type, &physmap_map);
151 mymtd->module = THIS_MODULE;
153 add_mtd_device(mymtd);
154 #ifdef CONFIG_MTD_PARTITIONS
155 #ifdef CONFIG_MTD_CMDLINE_PARTS
156 mtd_parts_nb = parse_cmdline_partitions(mymtd, &mtd_parts,
158 if (mtd_parts_nb > 0)
161 "Using command line partition definition\n");
162 add_mtd_partitions (mymtd, mtd_parts, mtd_parts_nb);
165 if (NUM_PARTITIONS != 0)
168 "Using physmap partition definition\n");
169 add_mtd_partitions (mymtd, physmap_partitions, NUM_PARTITIONS);
177 iounmap((void *)physmap_map.map_priv_1);
181 static void __exit cleanup_physmap(void)
184 del_mtd_device(mymtd);
187 if (physmap_map.map_priv_1) {
188 iounmap((void *)physmap_map.map_priv_1);
189 physmap_map.map_priv_1 = 0;
193 module_init(init_physmap);
194 module_exit(cleanup_physmap);
197 MODULE_LICENSE("GPL");
198 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
199 MODULE_DESCRIPTION("Generic configurable MTD map driver");