Merge tag 'v3.3.7' into 3.3/master
[zen-stable.git] / drivers / mtd / maps / tsunami_flash.c
blob1de390e1c2fb3039b98100014e21ac2e6563ba4c
1 /*
2 * tsunami_flash.c
4 * flash chip on alpha ds10...
5 */
6 #include <asm/io.h>
7 #include <asm/core_tsunami.h>
8 #include <linux/init.h>
9 #include <linux/mtd/map.h>
10 #include <linux/mtd/mtd.h>
12 #define FLASH_ENABLE_PORT 0x00C00001
13 #define FLASH_ENABLE_BYTE 0x01
14 #define FLASH_DISABLE_BYTE 0x00
16 #define MAX_TIG_FLASH_SIZE (12*1024*1024)
17 static inline map_word tsunami_flash_read8(struct map_info *map, unsigned long offset)
19 map_word val;
20 val.x[0] = tsunami_tig_readb(offset);
21 return val;
24 static void tsunami_flash_write8(struct map_info *map, map_word value, unsigned long offset)
26 tsunami_tig_writeb(value.x[0], offset);
29 static void tsunami_flash_copy_from(
30 struct map_info *map, void *addr, unsigned long offset, ssize_t len)
32 unsigned char *dest;
33 dest = addr;
34 while(len && (offset < MAX_TIG_FLASH_SIZE)) {
35 *dest = tsunami_tig_readb(offset);
36 offset++;
37 dest++;
38 len--;
42 static void tsunami_flash_copy_to(
43 struct map_info *map, unsigned long offset,
44 const void *addr, ssize_t len)
46 const unsigned char *src;
47 src = addr;
48 while(len && (offset < MAX_TIG_FLASH_SIZE)) {
49 tsunami_tig_writeb(*src, offset);
50 offset++;
51 src++;
52 len--;
57 * Deliberately don't provide operations wider than 8 bits. I don't
58 * have then and it scares me to think how you could mess up if
59 * you tried to use them. Buswidth is correctly so I'm safe.
61 static struct map_info tsunami_flash_map = {
62 .name = "flash chip on the Tsunami TIG bus",
63 .size = MAX_TIG_FLASH_SIZE,
64 .phys = NO_XIP,
65 .bankwidth = 1,
66 .read = tsunami_flash_read8,
67 .copy_from = tsunami_flash_copy_from,
68 .write = tsunami_flash_write8,
69 .copy_to = tsunami_flash_copy_to,
72 static struct mtd_info *tsunami_flash_mtd;
74 static void __exit cleanup_tsunami_flash(void)
76 struct mtd_info *mtd;
77 mtd = tsunami_flash_mtd;
78 if (mtd) {
79 mtd_device_unregister(mtd);
80 map_destroy(mtd);
82 tsunami_flash_mtd = 0;
86 static int __init init_tsunami_flash(void)
88 static const char *rom_probe_types[] = { "cfi_probe", "jedec_probe", "map_rom", NULL };
89 char **type;
91 tsunami_tig_writeb(FLASH_ENABLE_BYTE, FLASH_ENABLE_PORT);
93 tsunami_flash_mtd = 0;
94 type = rom_probe_types;
95 for(; !tsunami_flash_mtd && *type; type++) {
96 tsunami_flash_mtd = do_map_probe(*type, &tsunami_flash_map);
98 if (tsunami_flash_mtd) {
99 tsunami_flash_mtd->owner = THIS_MODULE;
100 mtd_device_register(tsunami_flash_mtd, NULL, 0);
101 return 0;
103 return -ENXIO;
106 module_init(init_tsunami_flash);
107 module_exit(cleanup_tsunami_flash);