1 /*
2 * $Id: physmap.c,v 1.8 2000/11/27 08:50:22 dwmw2 Exp $
3 *
4 * Normal mappings of chips in physical memory
5 */
6
7 #include <linux/module.h>
8 #include <linux/types.h>
9 #include <linux/kernel.h>
10 #include <asm/io.h>
11 #include <linux/mtd/mtd.h>
12 #include <linux/mtd/map.h>
13 #include <linux/config.h>
14
15
16 #define WINDOW_ADDR CONFIG_MTD_PHYSMAP_START
17 #define WINDOW_SIZE CONFIG_MTD_PHYSMAP_LEN
18 #define BUSWIDTH CONFIG_MTD_PHYSMAP_BUSWIDTH
19
20 static struct mtd_info *mymtd;
21
22 __u8 physmap_read8(struct map_info *map, unsigned long ofs)
23 {
24 return readb(map->map_priv_1 + ofs);
25 }
26
27 __u16 physmap_read16(struct map_info *map, unsigned long ofs)
28 {
29 return readw(map->map_priv_1 + ofs);
30 }
31
32 __u32 physmap_read32(struct map_info *map, unsigned long ofs)
33 {
34 return readl(map->map_priv_1 + ofs);
35 }
36
37 void physmap_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
38 {
39 memcpy_fromio(to, map->map_priv_1 + from, len);
40 }
41
42 void physmap_write8(struct map_info *map, __u8 d, unsigned long adr)
43 {
44 writeb(d, map->map_priv_1 + adr);
45 }
46
47 void physmap_write16(struct map_info *map, __u16 d, unsigned long adr)
48 {
49 writew(d, map->map_priv_1 + adr);
50 }
51
52 void physmap_write32(struct map_info *map, __u32 d, unsigned long adr)
53 {
54 writel(d, map->map_priv_1 + adr);
55 }
56
57 void physmap_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
58 {
59 memcpy_toio(map->map_priv_1 + to, from, len);
60 }
61
62 struct map_info physmap_map = {
63 name: "Physically mapped flash",
64 size: WINDOW_SIZE,
65 buswidth: BUSWIDTH,
66 read8: physmap_read8,
67 read16: physmap_read16,
68 read32: physmap_read32,
69 copy_from: physmap_copy_from,
70 write8: physmap_write8,
71 write16: physmap_write16,
72 write32: physmap_write32,
73 copy_to: physmap_copy_to
74 };
75
76 #if LINUX_VERSION_CODE < 0x20212 && defined(MODULE)
77 #define init_physmap init_module
78 #define cleanup_physmap cleanup_module
79 #endif
80
81 int __init init_physmap(void)
82 {
83 printk(KERN_NOTICE "physmap flash device: %x at %x\n", WINDOW_SIZE, WINDOW_ADDR);
84 physmap_map.map_priv_1 = (unsigned long)ioremap(WINDOW_ADDR, WINDOW_SIZE);
85
86 if (!physmap_map.map_priv_1) {
87 printk("Failed to ioremap\n");
88 return -EIO;
89 }
90 mymtd = do_cfi_probe(&physmap_map);
91 if (mymtd) {
92 #ifdef MODULE
93 mymtd->module = &__this_module;
94 #endif
95 add_mtd_device(mymtd);
96 return 0;
97 }
98
99 iounmap((void *)physmap_map.map_priv_1);
100 return -ENXIO;
101 }
102
103 static void __exit cleanup_physmap(void)
104 {
105 if (mymtd) {
106 del_mtd_device(mymtd);
107 map_destroy(mymtd);
108 }
109 if (physmap_map.map_priv_1) {
110 iounmap((void *)physmap_map.map_priv_1);
111 physmap_map.map_priv_1 = 0;
112 }
113 }
114
115 module_init(init_physmap);
116 module_exit(cleanup_physmap);
117
118
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.