use readable names for mtd partitions (hardcoded)
[openwrt/staging/dedeckeh.git] / openwrt / target / linux / linux-2.4 / patches / ar7 / 001-flash_map.patch
1 diff -urN linux-2.4.30/drivers/mtd/maps/Config.in linux-2.4.30.dev/drivers/mtd/maps/Config.in
2 --- linux-2.4.30/drivers/mtd/maps/Config.in 2005-06-14 19:31:49.000000000 +0200
3 +++ linux-2.4.30.dev/drivers/mtd/maps/Config.in 2005-06-14 15:36:59.000000000 +0200
4 @@ -48,6 +48,21 @@
5 fi
6
7 if [ "$CONFIG_MIPS" = "y" ]; then
8 + if [ "$CONFIG_AR7" = "y" ]; then
9 + dep_tristate ' Flash chip mapping on Texas Instruments AR7' CONFIG_MTD_AVALANCHE $CONFIG_MTD_CFI $CONFIG_MTD_PARTITIONS
10 + dep_bool ' Use defaults for Texas Instruments AR7' CONFIG_MTD_AVALANCHE_DEFAULTS $CONFIG_MTD_AVALANCHE
11 + if [ "$CONFIG_MTD_AVALANCHE" = "y" -o "$CONFIG_MTD_AVALANCHE" = "m" ]; then
12 + if [ "$CONFIG_MTD_AVALANCHE_DEFAULTS" = "y" ]; then
13 + define_hex CONFIG_MTD_AVALANCHE_START 0x10000000
14 + define_hex CONFIG_MTD_AVALANCHE_LEN 0x400000
15 + define_int CONFIG_MTD_AVALANCHE_BUSWIDTH 2
16 + else
17 + hex ' Physical start address of flash mapping' CONFIG_MTD_AVALANCHE_START 0x10000000
18 + hex ' Physical length of flash mapping' CONFIG_MTD_AVALANCHE_LEN 0x400000
19 + int ' Bus width in octets' CONFIG_MTD_AVALANCHE_BUSWIDTH 2
20 + fi
21 + fi
22 + fi
23 dep_tristate ' Pb1000 MTD support' CONFIG_MTD_PB1000 $CONFIG_MIPS_PB1000
24 dep_tristate ' Pb1500 MTD support' CONFIG_MTD_PB1500 $CONFIG_MIPS_PB1500
25 dep_tristate ' Pb1100 MTD support' CONFIG_MTD_PB1100 $CONFIG_MIPS_PB1100
26 diff -urN linux-2.4.30/drivers/mtd/maps/Makefile linux-2.4.30.dev/drivers/mtd/maps/Makefile
27 --- linux-2.4.30/drivers/mtd/maps/Makefile 2005-06-14 19:31:49.000000000 +0200
28 +++ linux-2.4.30.dev/drivers/mtd/maps/Makefile 2005-06-14 15:36:59.000000000 +0200
29 @@ -10,6 +10,7 @@
30 endif
31
32 # Chip mappings
33 +obj-$(CONFIG_MTD_AVALANCHE) += ar7-flash.o
34 obj-$(CONFIG_MTD_CDB89712) += cdb89712.o
35 obj-$(CONFIG_MTD_ARM_INTEGRATOR)+= integrator-flash.o
36 obj-$(CONFIG_MTD_CFI_FLAGADM) += cfi_flagadm.o
37 diff -urN linux-2.4.30/drivers/mtd/maps/ar7-flash.c linux-2.4.30.dev/drivers/mtd/maps/ar7-flash.c
38 --- linux-2.4.30/drivers/mtd/maps/ar7-flash.c 1970-01-01 01:00:00.000000000 +0100
39 +++ linux-2.4.30.dev/drivers/mtd/maps/ar7-flash.c 2005-06-14 19:38:19.000000000 +0200
40 @@ -0,0 +1,218 @@
41 +/*
42 + * $Id$
43 + *
44 + * Normal mappings of chips in physical memory
45 + */
46 +
47 +#include <linux/module.h>
48 +#include <linux/types.h>
49 +#include <linux/kernel.h>
50 +#include <asm/io.h>
51 +#include <linux/mtd/mtd.h>
52 +#include <linux/mtd/map.h>
53 +#include <linux/config.h>
54 +#include <linux/mtd/partitions.h>
55 +
56 +#define WINDOW_ADDR CONFIG_MTD_AVALANCHE_START
57 +#define WINDOW_SIZE CONFIG_MTD_AVALANCHE_LEN
58 +#define BUSWIDTH CONFIG_MTD_AVALANCHE_BUSWIDTH
59 +
60 +#include <asm/mips-boards/prom.h>
61 +extern char *prom_getenv(char *name);
62 +
63 +static int create_mtd_partitions(void);
64 +static void __exit avalanche_mtd_cleanup(void);
65 +
66 +/* avalanche__partition_info gives details on the logical partitions that splits
67 + * the flash device into. If the size if zero we use up to the end of
68 + * the device. */
69 +#define MAX_NUM_PARTITIONS 5
70 +static struct mtd_partition avalanche_partition_info[MAX_NUM_PARTITIONS];
71 +static int num_of_partitions = 0;
72 +
73 +static struct mtd_info *avalanche_mtd_info;
74 +
75 +int avalanche_mtd_ready=0;
76 +
77 +__u8 avalanche_read8(struct map_info *map, unsigned long ofs)
78 +{
79 + return __raw_readb(map->map_priv_1 + ofs);
80 +}
81 +
82 +__u16 avalanche_read16(struct map_info *map, unsigned long ofs)
83 +{
84 + return __raw_readw(map->map_priv_1 + ofs);
85 +}
86 +
87 +__u32 avalanche_read32(struct map_info *map, unsigned long ofs)
88 +{
89 + return __raw_readl(map->map_priv_1 + ofs);
90 +}
91 +
92 +void avalanche_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
93 +{
94 + memcpy_fromio(to, map->map_priv_1 + from, len);
95 +}
96 +
97 +void avalanche_write8(struct map_info *map, __u8 d, unsigned long adr)
98 +{
99 + __raw_writeb(d, map->map_priv_1 + adr);
100 + mb();
101 +}
102 +
103 +void avalanche_write16(struct map_info *map, __u16 d, unsigned long adr)
104 +{
105 + __raw_writew(d, map->map_priv_1 + adr);
106 + mb();
107 +}
108 +
109 +void avalanche_write32(struct map_info *map, __u32 d, unsigned long adr)
110 +{
111 + __raw_writel(d, map->map_priv_1 + adr);
112 + mb();
113 +}
114 +
115 +void avalanche_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
116 +{
117 + memcpy_toio(map->map_priv_1 + to, from, len);
118 +}
119 +
120 +struct map_info avalanche_map = {
121 + name: "Physically mapped flash",
122 + size: WINDOW_SIZE,
123 + buswidth: BUSWIDTH,
124 + read8: avalanche_read8,
125 + read16: avalanche_read16,
126 + read32: avalanche_read32,
127 + copy_from: avalanche_copy_from,
128 + write8: avalanche_write8,
129 + write16: avalanche_write16,
130 + write32: avalanche_write32,
131 + copy_to: avalanche_copy_to
132 +};
133 +
134 +int __init avalanche_mtd_init(void)
135 +{
136 + printk(KERN_NOTICE "avalanche flash device: 0x%lx at 0x%lx.\n", (unsigned long)WINDOW_SIZE, (unsigned long)WINDOW_ADDR);
137 + avalanche_map.map_priv_1 = (unsigned long)ioremap_nocache(WINDOW_ADDR, WINDOW_SIZE);
138 +
139 + if (!avalanche_map.map_priv_1) {
140 + printk("Failed to ioremap\n");
141 + return -EIO;
142 + }
143 +
144 + avalanche_mtd_info = do_map_probe("cfi_probe", &avalanche_map);
145 + if (!avalanche_mtd_info)
146 + {
147 + avalanche_mtd_cleanup();
148 + return -ENXIO;
149 + }
150 +
151 + avalanche_mtd_info->module = THIS_MODULE;
152 +
153 + if (!create_mtd_partitions())
154 + add_mtd_device(avalanche_mtd_info);
155 + else
156 + add_mtd_partitions(avalanche_mtd_info, avalanche_partition_info, num_of_partitions);
157 +
158 + avalanche_mtd_ready=1;
159 +
160 + return 0;
161 +}
162 +
163 +static char *strdup(char *str)
164 +{
165 + int n = strlen(str)+1;
166 + char *s = kmalloc(n, GFP_KERNEL);
167 + if (!s) return NULL;
168 + return strcpy(s, str);
169 +}
170 +
171 +
172 +static int create_mtd_partitions(void)
173 +{
174 + unsigned int offset;
175 + unsigned int size;
176 + unsigned int found;
177 + unsigned char *flash_base;
178 + unsigned char *flash_end;
179 + char *env_ptr;
180 + char *base_ptr;
181 + char *end_ptr;
182 +
183 + do {
184 + char env_name[20];
185 +
186 + found = 0;
187 +
188 + /* get base and end addresses of flash file system from environment */
189 + sprintf(env_name, "mtd%1u", num_of_partitions);
190 + printk("Looking for mtd device :%s:\n", env_name);
191 +
192 + env_ptr = prom_getenv(env_name);
193 + if(env_ptr == NULL) {
194 + /* No more partitions to find */
195 + break;
196 + }
197 +
198 + /* Extract the start and stop addresses of the partition */
199 + base_ptr = strtok(env_ptr, ",");
200 + end_ptr = strtok(NULL, ",");
201 + if ((base_ptr == NULL) || (end_ptr == NULL)) {
202 + printk("JFFS2 ERROR: Invalid %s start,end.\n", env_name);
203 + break;
204 + }
205 +
206 + flash_base = (unsigned char*) simple_strtol(base_ptr, NULL, 0);
207 + flash_end = (unsigned char*) simple_strtol(end_ptr, NULL, 0);
208 + if((!flash_base) || (!flash_end)) {
209 + printk("JFFS2 ERROR: Invalid %s start,end.\n", env_name);
210 + break;
211 + }
212 +
213 + offset = virt_to_bus(flash_base) - WINDOW_ADDR;
214 + size = flash_end - flash_base;
215 + printk("Found a %s image (0x%x), with size (0x%x).\n",env_name, offset, size);
216 +
217 + /* Setup the partition info. We duplicate the env_name for the partiton name */
218 + if (num_of_partitions == 0)
219 + avalanche_partition_info[num_of_partitions].name = strdup("linux");
220 + else if (num_of_partitions == 1)
221 + avalanche_partition_info[num_of_partitions].name = strdup("rootfs");
222 + else if (num_of_partitions == 2)
223 + avalanche_partition_info[num_of_partitions].name = strdup("adam2");
224 + else if (num_of_partitions == 3)
225 + avalanche_partition_info[num_of_partitions].name = strdup("config");
226 + else
227 + avalanche_partition_info[num_of_partitions].name = strdup(env_name);
228 + avalanche_partition_info[num_of_partitions].offset = offset;
229 + avalanche_partition_info[num_of_partitions].size = size;
230 + avalanche_partition_info[num_of_partitions].mask_flags = 0;
231 + num_of_partitions++;
232 + } while (num_of_partitions < MAX_NUM_PARTITIONS);
233 +
234 + return num_of_partitions;
235 +}
236 +
237 +static void __exit avalanche_mtd_cleanup(void)
238 +{
239 + avalanche_mtd_ready=0;
240 +
241 + if (avalanche_mtd_info) {
242 + del_mtd_partitions(avalanche_mtd_info);
243 + del_mtd_device(avalanche_mtd_info);
244 + map_destroy(avalanche_mtd_info);
245 + }
246 +
247 + if (avalanche_map.map_priv_1) {
248 + iounmap((void *)avalanche_map.map_priv_1);
249 + avalanche_map.map_priv_1 = 0;
250 + }
251 +}
252 +
253 +module_init(avalanche_mtd_init);
254 +module_exit(avalanche_mtd_cleanup);
255 +
256 +MODULE_LICENSE("GPL");
257 +MODULE_AUTHOR("Snehaprabha Narnakaje");
258 +MODULE_DESCRIPTION("Avalanche CFI map driver");