1 // $Id: vmax301.c,v 1.13 2000/07/03 10:01:38 dwmw2 Exp $
2 /* ######################################################################
4 Tempustech VMAX SBC301 MTD Driver.
6 The VMAx 301 is a SBC based on . It
7 comes with three builtin AMD 29F016B flash chips and a socket for SRAM or
8 more flash. Each unit has it's own 8k mapping into a settable region
9 (0xD8000). There are two 8k mappings for each MTD, the first is always set
10 to the lower 8k of the device the second is paged. Writing a 16 bit page
11 value to anywhere in the first 8k will cause the second 8k to page around.
13 To boot the device a bios extension must be installed into the first 8k
14 of flash that is smart enough to copy itself down, page in the rest of
15 itself and begin executing.
17 ##################################################################### */
19 #include <linux/module.h>
20 #include <linux/malloc.h>
21 #include <linux/ioport.h>
22 #include <linux/init.h>
23 #include <asm/spinlock.h>
26 #include <linux/mtd/map.h>
29 #define WINDOW_START 0xd8000
30 #define WINDOW_LENGTH 0x2000
31 #define WINDOW_SHIFT 25
32 #define WINDOW_MASK 0x1FFF
34 /* Actually we could use two spinlocks, but we'd have to have
35 more private space in the struct map_info. We lose a little
36 performance like this, but we'd probably lose more by having
37 the extra indirection from having one of the map->map_priv
38 fields pointing to yet another private struct.
40 static spinlock_t vmax301_spin
= SPIN_LOCK_UNLOCKED
;
42 static void __vmax301_page(struct map_info
*map
, unsigned long page
)
44 writew(page
, map
->map_priv_2
- WINDOW_LENGTH
);
45 map
->map_priv_1
= page
;
48 static inline void vmax301_page(struct map_info
*map
,
51 unsigned long page
= (ofs
>> WINDOW_SHIFT
);
52 if (map
->map_priv_1
!= page
)
53 __vmax301_page(map
, page
);
56 static __u8
vmax301_read8(struct map_info
*map
, unsigned long ofs
)
59 spin_lock(&vmax301_spin
);
60 vmax301_page(map
, ofs
);
61 ret
= readb(map
->map_priv_2
+ (ofs
& WINDOW_MASK
));
62 spin_unlock(&vmax301_spin
);
66 static __u16
vmax301_read16(struct map_info
*map
, unsigned long ofs
)
69 spin_lock(&vmax301_spin
);
70 vmax301_page(map
, ofs
);
71 ret
= readw(map
->map_priv_2
+ (ofs
& WINDOW_MASK
));
72 spin_unlock(&vmax301_spin
);
76 static __u32
vmax301_read32(struct map_info
*map
, unsigned long ofs
)
79 spin_lock(&vmax301_spin
);
80 vmax301_page(map
, ofs
);
81 ret
= readl(map
->map_priv_2
+ (ofs
& WINDOW_MASK
));
82 spin_unlock(&vmax301_spin
);
86 static void vmax301_copy_from(struct map_info
*map
, void *to
, unsigned long from
, ssize_t len
)
89 unsigned long thislen
= len
;
90 if (len
> (WINDOW_LENGTH
- (from
& WINDOW_MASK
)))
91 thislen
= WINDOW_LENGTH
-(from
& WINDOW_MASK
);
92 spin_lock(&vmax301_spin
);
93 vmax301_page(map
, from
);
94 memcpy_fromio(to
, map
->map_priv_2
+ from
, thislen
);
95 spin_unlock(&vmax301_spin
);
102 static void vmax301_write8(struct map_info
*map
, __u8 d
, unsigned long adr
)
104 spin_lock(&vmax301_spin
);
105 vmax301_page(map
, adr
);
106 writeb(d
, map
->map_priv_2
+ (adr
& WINDOW_MASK
));
107 spin_unlock(&vmax301_spin
);
110 static void vmax301_write16(struct map_info
*map
, __u16 d
, unsigned long adr
)
112 spin_lock(&vmax301_spin
);
113 vmax301_page(map
, adr
);
114 writew(d
, map
->map_priv_2
+ (adr
& WINDOW_MASK
));
115 spin_unlock(&vmax301_spin
);
118 static void vmax301_write32(struct map_info
*map
, __u32 d
, unsigned long adr
)
120 spin_lock(&vmax301_spin
);
121 vmax301_page(map
, adr
);
122 writel(d
, map
->map_priv_2
+ (adr
& WINDOW_MASK
));
123 spin_unlock(&vmax301_spin
);
126 static void vmax301_copy_to(struct map_info
*map
, unsigned long to
, const void *from
, ssize_t len
)
129 unsigned long thislen
= len
;
130 if (len
> (WINDOW_LENGTH
- (to
& WINDOW_MASK
)))
131 thislen
= WINDOW_LENGTH
-(to
& WINDOW_MASK
);
133 spin_lock(&vmax301_spin
);
134 vmax301_page(map
, to
);
135 memcpy_toio(map
->map_priv_2
+ to
, from
, thislen
);
136 spin_unlock(&vmax301_spin
);
143 static struct map_info vmax_map
[2] = {
145 "VMAX301 Internal Flash",
156 WINDOW_START
+ WINDOW_LENGTH
,
171 WINDOW_START
+ (3*WINDOW_LENGTH
),
176 static struct mtd_info
*vmax_mtd
[2] = {NULL
, NULL
};
178 #if LINUX_VERSION_CODE < 0x20300
180 #define init_vmax301 init_module
181 #define cleanup_vmax301 cleanup_module
186 static void __exit
cleanup_vmax301(void)
190 for (i
=0; i
<2; i
++) {
192 del_mtd_device(vmax_mtd
[i
]);
193 map_destroy(vmax_mtd
[i
]);
196 iounmap((void *)vmax_map
[0].map_priv_1
- WINDOW_START
);
199 int __init
init_vmax301(void)
202 unsigned long iomapadr
;
203 // Print out our little header..
204 printk("Tempustech VMAX 301 MEM:0x%x-0x%x\n",WINDOW_START
,
205 WINDOW_START
+4*WINDOW_LENGTH
);
207 iomapadr
= (unsigned long)ioremap(WINDOW_START
, WINDOW_LENGTH
*4);
209 printk("Failed to ioremap memory region\n");
212 /* Put the address in the map's private data area.
213 We store the actual MTD IO address rather than the
214 address of the first half, because it's used more
217 vmax_map
[0].map_priv_1
= iomapadr
+ WINDOW_START
;
218 vmax_map
[1].map_priv_1
= iomapadr
+ (3*WINDOW_START
);
220 for (i
=0; i
<2; i
++) {
221 vmax_mtd
[i
] = do_cfi_probe(&vmax_map
[i
]);
223 vmax_mtd
[i
] = do_jedec_probe(&vmax_map
[i
]);
225 vmax_mtd
[i
] = do_ram_probe(&vmax_map
[i
]);
227 vmax_mtd
[i
] = do_rom_probe(&vmax_map
[i
]);
229 vmax_mtd
[i
]->module
= THIS_MODULE
;
230 add_mtd_device(vmax_mtd
[i
]);
234 if (!vmax_mtd
[1] && !vmax_mtd
[2])
240 #if LINUX_VERSION_CODE > 0x20300
241 module_init(init_vmax301
);
242 module_exit(cleanup_vmax301
);