blob: da2cdb5fd6db98862dba7a0fe7c84ca6abd563af [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * tsunami_flash.c
3 *
4 * flash chip on alpha ds10...
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 */
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>
11
12#define FLASH_ENABLE_PORT 0x00C00001
13#define FLASH_ENABLE_BYTE 0x01
14#define FLASH_DISABLE_BYTE 0x00
15
16#define MAX_TIG_FLASH_SIZE (12*1024*1024)
17static inline map_word tsunami_flash_read8(struct map_info *map, unsigned long offset)
18{
19 map_word val;
20 val.x[0] = tsunami_tig_readb(offset);
21 return val;
22}
23
24static void tsunami_flash_write8(struct map_info *map, map_word value, unsigned long offset)
25{
26 tsunami_tig_writeb(value.x[0], offset);
27}
28
29static void tsunami_flash_copy_from(
30 struct map_info *map, void *addr, unsigned long offset, ssize_t len)
31{
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--;
39 }
40}
41
42static void tsunami_flash_copy_to(
Thomas Gleixner69f34c92005-11-07 11:15:40 +000043 struct map_info *map, unsigned long offset,
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 const void *addr, ssize_t len)
45{
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--;
53 }
54}
55
56/*
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.
60 */
61static struct map_info tsunami_flash_map = {
62 .name = "flash chip on the Tsunami TIG bus",
63 .size = MAX_TIG_FLASH_SIZE,
Alexey Dobriyan70e51012006-02-01 03:04:48 -080064 .phys = NO_XIP,
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 .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,
70};
71
72static struct mtd_info *tsunami_flash_mtd;
73
74static void __exit cleanup_tsunami_flash(void)
75{
76 struct mtd_info *mtd;
77 mtd = tsunami_flash_mtd;
78 if (mtd) {
Jamie Ilesee0e87b2011-05-23 10:23:40 +010079 mtd_device_unregister(mtd);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 map_destroy(mtd);
81 }
82 tsunami_flash_mtd = 0;
83}
84
Artem Bityutskiy0984c892013-03-12 10:46:37 +020085static const char * const rom_probe_types[] = {
86 "cfi_probe", "jedec_probe", "map_rom", NULL };
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
88static int __init init_tsunami_flash(void)
89{
Artem Bityutskiy0984c892013-03-12 10:46:37 +020090 const char * const *type;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92 tsunami_tig_writeb(FLASH_ENABLE_BYTE, FLASH_ENABLE_PORT);
Thomas Gleixner69f34c92005-11-07 11:15:40 +000093
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 tsunami_flash_mtd = 0;
95 type = rom_probe_types;
96 for(; !tsunami_flash_mtd && *type; type++) {
97 tsunami_flash_mtd = do_map_probe(*type, &tsunami_flash_map);
98 }
99 if (tsunami_flash_mtd) {
100 tsunami_flash_mtd->owner = THIS_MODULE;
Jamie Ilesee0e87b2011-05-23 10:23:40 +0100101 mtd_device_register(tsunami_flash_mtd, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 return 0;
103 }
104 return -ENXIO;
105}
106
107module_init(init_tsunami_flash);
108module_exit(cleanup_tsunami_flash);