More cleaning ...
[linux-2.6/linux-mips.git] / include / linux / mtd / map.h
blob0c933f9bf1fea22c7189390c1baf0b86f63adc19
2 /* Overhauled routines for dealing with different mmap regions of flash */
3 /* $Id: map.h,v 1.34 2003/05/28 12:42:22 dwmw2 Exp $ */
5 #ifndef __LINUX_MTD_MAP_H__
6 #define __LINUX_MTD_MAP_H__
8 #include <linux/config.h>
9 #include <linux/types.h>
10 #include <linux/list.h>
11 #include <asm/system.h>
12 #include <asm/io.h>
14 /* The map stuff is very simple. You fill in your struct map_info with
15 a handful of routines for accessing the device, making sure they handle
16 paging etc. correctly if your device needs it. Then you pass it off
17 to a chip driver which deals with a mapped device - generally either
18 do_cfi_probe() or do_ram_probe(), either of which will return a
19 struct mtd_info if they liked what they saw. At which point, you
20 fill in the mtd->module with your own module address, and register
21 it.
23 The mtd->priv field will point to the struct map_info, and any further
24 private data required by the chip driver is linked from the
25 mtd->priv->fldrv_priv field. This allows the map driver to get at
26 the destructor function map->fldrv_destroy() when it's tired
27 of living.
30 struct map_info {
31 char *name;
32 unsigned long size;
33 unsigned long phys;
34 #define NO_XIP (-1UL)
36 unsigned long virt;
37 void *cached;
39 int buswidth; /* in octets */
41 #ifdef CONFIG_MTD_COMPLEX_MAPPINGS
42 u8 (*read8)(struct map_info *, unsigned long);
43 u16 (*read16)(struct map_info *, unsigned long);
44 u32 (*read32)(struct map_info *, unsigned long);
45 u64 (*read64)(struct map_info *, unsigned long);
46 /* If it returned a 'long' I'd call it readl.
47 * It doesn't.
48 * I won't.
49 * dwmw2 */
51 void (*copy_from)(struct map_info *, void *, unsigned long, ssize_t);
52 void (*write8)(struct map_info *, u8, unsigned long);
53 void (*write16)(struct map_info *, u16, unsigned long);
54 void (*write32)(struct map_info *, u32, unsigned long);
55 void (*write64)(struct map_info *, u64, unsigned long);
56 void (*copy_to)(struct map_info *, unsigned long, const void *, ssize_t);
58 /* We can perhaps put in 'point' and 'unpoint' methods, if we really
59 want to enable XIP for non-linear mappings. Not yet though. */
60 #endif
61 /* set_vpp() must handle being reentered -- enable, enable, disable
62 must leave it enabled. */
63 void (*set_vpp)(struct map_info *, int);
65 unsigned long map_priv_1;
66 unsigned long map_priv_2;
67 void *fldrv_priv;
68 struct mtd_chip_driver *fldrv;
71 struct mtd_chip_driver {
72 struct mtd_info *(*probe)(struct map_info *map);
73 void (*destroy)(struct mtd_info *);
74 struct module *module;
75 char *name;
76 struct list_head list;
79 void register_mtd_chip_driver(struct mtd_chip_driver *);
80 void unregister_mtd_chip_driver(struct mtd_chip_driver *);
82 struct mtd_info *do_map_probe(const char *name, struct map_info *map);
83 void map_destroy(struct mtd_info *mtd);
85 #define ENABLE_VPP(map) do { if(map->set_vpp) map->set_vpp(map, 1); } while(0)
86 #define DISABLE_VPP(map) do { if(map->set_vpp) map->set_vpp(map, 0); } while(0)
88 #ifdef CONFIG_MTD_COMPLEX_MAPPINGS
89 #define map_read8(map, ofs) (map)->read8(map, ofs)
90 #define map_read16(map, ofs) (map)->read16(map, ofs)
91 #define map_read32(map, ofs) (map)->read32(map, ofs)
92 #define map_read64(map, ofs) (map)->read64(map, ofs)
93 #define map_copy_from(map, to, from, len) (map)->copy_from(map, to, from, len)
94 #define map_write8(map, datum, ofs) (map)->write8(map, datum, ofs)
95 #define map_write16(map, datum, ofs) (map)->write16(map, datum, ofs)
96 #define map_write32(map, datum, ofs) (map)->write32(map, datum, ofs)
97 #define map_write64(map, datum, ofs) (map)->write64(map, datum, ofs)
98 #define map_copy_to(map, to, from, len) (map)->copy_to(map, to, from, len)
100 extern void simple_map_init(struct map_info *);
101 #define map_is_linear(map) (map->phys != NO_XIP)
103 #else
104 static inline u8 map_read8(struct map_info *map, unsigned long ofs)
106 return __raw_readb(map->virt + ofs);
109 static inline u16 map_read16(struct map_info *map, unsigned long ofs)
111 return __raw_readw(map->virt + ofs);
114 static inline u32 map_read32(struct map_info *map, unsigned long ofs)
116 return __raw_readl(map->virt + ofs);
119 static inline u64 map_read64(struct map_info *map, unsigned long ofs)
121 #ifndef CONFIG_MTD_CFI_B8 /* 64-bit mappings */
122 BUG();
123 return 0;
124 #else
125 return __raw_readll(map->virt + ofs);
126 #endif
129 static inline void map_write8(struct map_info *map, u8 datum, unsigned long ofs)
131 __raw_writeb(datum, map->virt + ofs);
132 mb();
135 static inline void map_write16(struct map_info *map, u16 datum, unsigned long ofs)
137 __raw_writew(datum, map->virt + ofs);
138 mb();
141 static inline void map_write32(struct map_info *map, u32 datum, unsigned long ofs)
143 __raw_writel(datum, map->virt + ofs);
144 mb();
147 static inline void map_write64(struct map_info *map, u64 datum, unsigned long ofs)
149 #ifndef CONFIG_MTD_CFI_B8 /* 64-bit mappings */
150 BUG();
151 #else
152 __raw_writell(datum, map->virt + ofs);
153 mb();
154 #endif /* CFI_B8 */
157 static inline void map_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
159 memcpy_fromio(to, map->virt + from, len);
162 static inline void map_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
164 memcpy_toio(map->virt + to, from, len);
167 #define simple_map_init(map) do { } while (0)
168 #define map_is_linear(map) (1)
170 #endif /* !CONFIG_MTD_COMPLEX_MAPPINGS */
172 #endif /* __LINUX_MTD_MAP_H__ */