ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / mtd / maps / tsunami_flash.c
1 /*
2  * tsunami_flash.c
3  *
4  * flash chip on alpha ds10...
5  * $Id: tsunami_flash.c,v 1.6 2003/05/21 15:15:08 dwmw2 Exp $
6  */
7 #include <asm/io.h>
8 #include <asm/core_tsunami.h>
9 #include <linux/init.h>
10 #include <linux/mtd/map.h>
11 #include <linux/mtd/mtd.h>
12
13 #define FLASH_ENABLE_PORT 0x00C00001
14 #define FLASH_ENABLE_BYTE 0x01
15 #define FLASH_DISABLE_BYTE 0x00
16
17 #define MAX_TIG_FLASH_SIZE (12*1024*1024)
18 static inline  __u8 tsunami_flash_read8(struct map_info *map, unsigned long offset)
19 {
20         return tsunami_tig_readb(offset);
21 }
22
23 static void tsunami_flash_write8(struct map_info *map, __u8 value, unsigned long offset)
24 {
25         tsunami_tig_writeb(value, offset);
26 }
27
28 static void tsunami_flash_copy_from(
29         struct map_info *map, void *addr, unsigned long offset, ssize_t len)
30 {
31         unsigned char *dest;
32         dest = addr;
33         while(len && (offset < MAX_TIG_FLASH_SIZE)) {
34                 *dest = tsunami_tig_readb(offset);
35                 offset++;
36                 dest++;
37                 len--;
38         }
39 }
40
41 static void tsunami_flash_copy_to(
42         struct map_info *map, unsigned long offset, 
43         const void *addr, ssize_t len)
44 {
45         const unsigned char *src;
46         src = addr;
47         while(len && (offset < MAX_TIG_FLASH_SIZE)) {
48                 tsunami_tig_writeb(*src, offset);
49                 offset++;
50                 src++;
51                 len--;
52         }
53 }
54
55 /*
56  * Deliberately don't provide operations wider than 8 bits.  I don't
57  * have then and it scares me to think how you could mess up if
58  * you tried to use them.   Buswidth is correctly so I'm safe.
59  */
60 static struct map_info tsunami_flash_map = {
61         .name = "flash chip on the Tsunami TIG bus",
62         .size = MAX_TIG_FLASH_SIZE,
63         .phys = NO_XIP;
64         .buswidth = 1,
65         .read8 = tsunami_flash_read8,
66         .copy_from = tsunami_flash_copy_from,
67         .write8 = tsunami_flash_write8,
68         .copy_to = tsunami_flash_copy_to,
69 };
70
71 static struct mtd_info *tsunami_flash_mtd;
72
73 static void __exit  cleanup_tsunami_flash(void)
74 {
75         struct mtd_info *mtd;
76         mtd = tsunami_flash_mtd;
77         if (mtd) {
78                 del_mtd_device(mtd);
79                 map_destroy(mtd);
80         }
81         tsunami_flash_mtd = 0;
82 }
83
84
85 static int __init init_tsunami_flash(void)
86 {
87         static const char *rom_probe_types[] = { "cfi_probe", "jedec_probe", "map_rom", 0 };
88         char **type;
89
90         tsunami_tig_writeb(FLASH_ENABLE_BYTE, FLASH_ENABLE_PORT);
91         
92         tsunami_flash_mtd = 0;
93         type = rom_probe_types;
94         for(; !tsunami_flash_mtd && *type; type++) {
95                 tsunami_flash_mtd = do_map_probe(*type, &tsunami_flash_map);
96         }
97         if (tsunami_flash_mtd) {
98                 tsunami_flash_mtd->owner = THIS_MODULE;
99                 add_mtd_device(tsunami_flash_mtd);
100                 return 0;
101         }
102         return -ENXIO;
103 }
104
105 module_init(init_tsunami_flash);
106 module_exit(cleanup_tsunami_flash);