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