blob: 7fc8097e41d224bbf690f9b72d7fc109495b68a3 [file] [log] [blame]
Pete Popov002fa302005-02-27 21:50:25 +00001/*
2 * Flash memory access on AMD Alchemy evaluation boards
Thomas Gleixner69f34c92005-11-07 11:15:40 +00003 *
4 * $Id: alchemy-flash.c,v 1.2 2005/11/07 11:14:26 gleixner Exp $
Pete Popov002fa302005-02-27 21:50:25 +00005 *
6 * (C) 2003, 2004 Pete Popov <ppopov@embeddedalley.com>
Thomas Gleixner69f34c92005-11-07 11:15:40 +00007 *
Pete Popov002fa302005-02-27 21:50:25 +00008 */
9
Pete Popov002fa302005-02-27 21:50:25 +000010#include <linux/init.h>
11#include <linux/module.h>
12#include <linux/types.h>
13#include <linux/kernel.h>
14
15#include <linux/mtd/mtd.h>
16#include <linux/mtd/map.h>
17#include <linux/mtd/partitions.h>
18
19#include <asm/io.h>
20
21#ifdef DEBUG_RW
22#define DBG(x...) printk(x)
23#else
Thomas Gleixner69f34c92005-11-07 11:15:40 +000024#define DBG(x...)
Pete Popov002fa302005-02-27 21:50:25 +000025#endif
26
27#ifdef CONFIG_MIPS_PB1000
28#define BOARD_MAP_NAME "Pb1000 Flash"
29#define BOARD_FLASH_SIZE 0x00800000 /* 8MB */
30#define BOARD_FLASH_WIDTH 4 /* 32-bits */
31#endif
32
33#ifdef CONFIG_MIPS_PB1500
34#define BOARD_MAP_NAME "Pb1500 Flash"
35#define BOARD_FLASH_SIZE 0x04000000 /* 64MB */
36#define BOARD_FLASH_WIDTH 4 /* 32-bits */
37#endif
38
39#ifdef CONFIG_MIPS_PB1100
40#define BOARD_MAP_NAME "Pb1100 Flash"
41#define BOARD_FLASH_SIZE 0x04000000 /* 64MB */
42#define BOARD_FLASH_WIDTH 4 /* 32-bits */
43#endif
44
45#ifdef CONFIG_MIPS_PB1550
46#define BOARD_MAP_NAME "Pb1550 Flash"
47#define BOARD_FLASH_SIZE 0x08000000 /* 128MB */
48#define BOARD_FLASH_WIDTH 4 /* 32-bits */
49#endif
50
51#ifdef CONFIG_MIPS_PB1200
52#define BOARD_MAP_NAME "Pb1200 Flash"
53#define BOARD_FLASH_SIZE 0x08000000 /* 128MB */
54#define BOARD_FLASH_WIDTH 2 /* 16-bits */
55#endif
56
57#ifdef CONFIG_MIPS_DB1000
58#define BOARD_MAP_NAME "Db1000 Flash"
59#define BOARD_FLASH_SIZE 0x02000000 /* 32MB */
60#define BOARD_FLASH_WIDTH 4 /* 32-bits */
61#endif
62
63#ifdef CONFIG_MIPS_DB1500
64#define BOARD_MAP_NAME "Db1500 Flash"
65#define BOARD_FLASH_SIZE 0x02000000 /* 32MB */
66#define BOARD_FLASH_WIDTH 4 /* 32-bits */
67#endif
68
69#ifdef CONFIG_MIPS_DB1100
70#define BOARD_MAP_NAME "Db1100 Flash"
71#define BOARD_FLASH_SIZE 0x02000000 /* 32MB */
72#define BOARD_FLASH_WIDTH 4 /* 32-bits */
73#endif
74
75#ifdef CONFIG_MIPS_DB1550
76#define BOARD_MAP_NAME "Db1550 Flash"
77#define BOARD_FLASH_SIZE 0x08000000 /* 128MB */
78#define BOARD_FLASH_WIDTH 4 /* 32-bits */
79#endif
80
81#ifdef CONFIG_MIPS_DB1200
82#define BOARD_MAP_NAME "Db1200 Flash"
83#define BOARD_FLASH_SIZE 0x04000000 /* 64MB */
84#define BOARD_FLASH_WIDTH 2 /* 16-bits */
85#endif
86
87#ifdef CONFIG_MIPS_HYDROGEN3
88#define BOARD_MAP_NAME "Hydrogen3 Flash"
89#define BOARD_FLASH_SIZE 0x02000000 /* 32MB */
90#define BOARD_FLASH_WIDTH 4 /* 32-bits */
91#define USE_LOCAL_ACCESSORS /* why? */
92#endif
93
94#ifdef CONFIG_MIPS_BOSPORUS
95#define BOARD_MAP_NAME "Bosporus Flash"
96#define BOARD_FLASH_SIZE 0x01000000 /* 16MB */
97#define BOARD_FLASH_WIDTH 2 /* 16-bits */
98#endif
99
100#ifdef CONFIG_MIPS_MIRAGE
101#define BOARD_MAP_NAME "Mirage Flash"
102#define BOARD_FLASH_SIZE 0x04000000 /* 64MB */
103#define BOARD_FLASH_WIDTH 4 /* 32-bits */
104#define USE_LOCAL_ACCESSORS /* why? */
105#endif
106
107static struct map_info alchemy_map = {
108 .name = BOARD_MAP_NAME,
109};
110
111static struct mtd_partition alchemy_partitions[] = {
112 {
113 .name = "User FS",
114 .size = BOARD_FLASH_SIZE - 0x00400000,
115 .offset = 0x0000000
116 },{
117 .name = "YAMON",
118 .size = 0x0100000,
119 .offset = MTDPART_OFS_APPEND,
120 .mask_flags = MTD_WRITEABLE
121 },{
122 .name = "raw kernel",
123 .size = (0x300000 - 0x40000), /* last 256KB is yamon env */
124 .offset = MTDPART_OFS_APPEND,
125 }
126};
127
Pete Popov002fa302005-02-27 21:50:25 +0000128static struct mtd_info *mymtd;
129
130int __init alchemy_mtd_init(void)
131{
132 struct mtd_partition *parts;
133 int nb_parts = 0;
134 unsigned long window_addr;
135 unsigned long window_size;
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000136
Pete Popov002fa302005-02-27 21:50:25 +0000137 /* Default flash buswidth */
138 alchemy_map.bankwidth = BOARD_FLASH_WIDTH;
139
140 window_addr = 0x20000000 - BOARD_FLASH_SIZE;
141 window_size = BOARD_FLASH_SIZE;
142#ifdef CONFIG_MIPS_MIRAGE_WHY
143 /* Boot ROM flash bank only; no user bank */
144 window_addr = 0x1C000000;
145 window_size = 0x04000000;
146 /* USERFS from 0x1C00 0000 to 0x1FC00000 */
147 alchemy_partitions[0].size = 0x03C00000;
148#endif
149
150 /*
151 * Static partition definition selection
152 */
153 parts = alchemy_partitions;
Tobias Klauser87d10f32006-03-31 02:29:45 -0800154 nb_parts = ARRAY_SIZE(alchemy_partitions);
Pete Popov002fa302005-02-27 21:50:25 +0000155 alchemy_map.size = window_size;
156
157 /*
158 * Now let's probe for the actual flash. Do it here since
159 * specific machine settings might have been set above.
160 */
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000161 printk(KERN_NOTICE BOARD_MAP_NAME ": probing %d-bit flash bus\n",
Pete Popov002fa302005-02-27 21:50:25 +0000162 alchemy_map.bankwidth*8);
163 alchemy_map.virt = ioremap(window_addr, window_size);
164 mymtd = do_map_probe("cfi_probe", &alchemy_map);
165 if (!mymtd) {
166 iounmap(alchemy_map.virt);
167 return -ENXIO;
168 }
169 mymtd->owner = THIS_MODULE;
170
171 add_mtd_partitions(mymtd, parts, nb_parts);
172 return 0;
173}
174
175static void __exit alchemy_mtd_cleanup(void)
176{
177 if (mymtd) {
178 del_mtd_partitions(mymtd);
179 map_destroy(mymtd);
180 iounmap(alchemy_map.virt);
181 }
182}
183
184module_init(alchemy_mtd_init);
185module_exit(alchemy_mtd_cleanup);
186
187MODULE_AUTHOR("Embedded Alley Solutions, Inc");
188MODULE_DESCRIPTION(BOARD_MAP_NAME " MTD driver");
189MODULE_LICENSE("GPL");