1 /*
2 * $Id: rpxlite.c,v 1.15 2001/10/02 15:05:14 dwmw2 Exp $
3 *
4 * Handle mapping of the flash on the RPX Lite and CLLF boards
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
14
15 #define WINDOW_ADDR 0xfe000000
16 #define WINDOW_SIZE 0x800000
17
18 static struct mtd_info *mymtd;
19
rpxlite_read8(struct map_info * map,unsigned long ofs)20 __u8 rpxlite_read8(struct map_info *map, unsigned long ofs)
21 {
22 return __raw_readb(map->map_priv_1 + ofs);
23 }
24
rpxlite_read16(struct map_info * map,unsigned long ofs)25 __u16 rpxlite_read16(struct map_info *map, unsigned long ofs)
26 {
27 return __raw_readw(map->map_priv_1 + ofs);
28 }
29
rpxlite_read32(struct map_info * map,unsigned long ofs)30 __u32 rpxlite_read32(struct map_info *map, unsigned long ofs)
31 {
32 return __raw_readl(map->map_priv_1 + ofs);
33 }
34
rpxlite_copy_from(struct map_info * map,void * to,unsigned long from,ssize_t len)35 void rpxlite_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
36 {
37 memcpy_fromio(to, (void *)(map->map_priv_1 + from), len);
38 }
39
rpxlite_write8(struct map_info * map,__u8 d,unsigned long adr)40 void rpxlite_write8(struct map_info *map, __u8 d, unsigned long adr)
41 {
42 __raw_writeb(d, map->map_priv_1 + adr);
43 mb();
44 }
45
rpxlite_write16(struct map_info * map,__u16 d,unsigned long adr)46 void rpxlite_write16(struct map_info *map, __u16 d, unsigned long adr)
47 {
48 __raw_writew(d, map->map_priv_1 + adr);
49 mb();
50 }
51
rpxlite_write32(struct map_info * map,__u32 d,unsigned long adr)52 void rpxlite_write32(struct map_info *map, __u32 d, unsigned long adr)
53 {
54 __raw_writel(d, map->map_priv_1 + adr);
55 mb();
56 }
57
rpxlite_copy_to(struct map_info * map,unsigned long to,const void * from,ssize_t len)58 void rpxlite_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
59 {
60 memcpy_toio((void *)(map->map_priv_1 + to), from, len);
61 }
62
63 struct map_info rpxlite_map = {
64 name: "RPX",
65 size: WINDOW_SIZE,
66 buswidth: 4,
67 read8: rpxlite_read8,
68 read16: rpxlite_read16,
69 read32: rpxlite_read32,
70 copy_from: rpxlite_copy_from,
71 write8: rpxlite_write8,
72 write16: rpxlite_write16,
73 write32: rpxlite_write32,
74 copy_to: rpxlite_copy_to
75 };
76
init_rpxlite(void)77 int __init init_rpxlite(void)
78 {
79 printk(KERN_NOTICE "RPX Lite or CLLF flash device: %x at %x\n", WINDOW_SIZE*4, WINDOW_ADDR);
80 rpxlite_map.map_priv_1 = (unsigned long)ioremap(WINDOW_ADDR, WINDOW_SIZE * 4);
81
82 if (!rpxlite_map.map_priv_1) {
83 printk("Failed to ioremap\n");
84 return -EIO;
85 }
86 mymtd = do_map_probe("cfi_probe", &rpxlite_map);
87 if (mymtd) {
88 mymtd->module = THIS_MODULE;
89 add_mtd_device(mymtd);
90 return 0;
91 }
92
93 iounmap((void *)rpxlite_map.map_priv_1);
94 return -ENXIO;
95 }
96
cleanup_rpxlite(void)97 static void __exit cleanup_rpxlite(void)
98 {
99 if (mymtd) {
100 del_mtd_device(mymtd);
101 map_destroy(mymtd);
102 }
103 if (rpxlite_map.map_priv_1) {
104 iounmap((void *)rpxlite_map.map_priv_1);
105 rpxlite_map.map_priv_1 = 0;
106 }
107 }
108
109 module_init(init_rpxlite);
110 module_exit(cleanup_rpxlite);
111
112 MODULE_LICENSE("GPL");
113 MODULE_AUTHOR("Arnold Christensen <AKC@pel.dk>");
114 MODULE_DESCRIPTION("MTD map driver for RPX Lite and CLLF boards");
115