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
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
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
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
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
44 + * Normal mappings of chips in physical memory
47 +#include <linux/module.h>
48 +#include <linux/types.h>
49 +#include <linux/kernel.h>
51 +#include <linux/mtd/mtd.h>
52 +#include <linux/mtd/map.h>
53 +#include <linux/config.h>
54 +#include <linux/mtd/partitions.h>
56 +#define WINDOW_ADDR CONFIG_MTD_AVALANCHE_START
57 +#define WINDOW_SIZE CONFIG_MTD_AVALANCHE_LEN
58 +#define BUSWIDTH CONFIG_MTD_AVALANCHE_BUSWIDTH
60 +#include <asm/mips-boards/prom.h>
61 +extern char *prom_getenv(char *name);
63 +static int create_mtd_partitions(void);
64 +static void __exit avalanche_mtd_cleanup(void);
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
69 +#define MAX_NUM_PARTITIONS 5
70 +static struct mtd_partition avalanche_partition_info[MAX_NUM_PARTITIONS];
71 +static int num_of_partitions = 0;
73 +static struct mtd_info *avalanche_mtd_info;
75 +int avalanche_mtd_ready=0;
77 +__u8 avalanche_read8(struct map_info *map, unsigned long ofs)
79 + return __raw_readb(map->map_priv_1 + ofs);
82 +__u16 avalanche_read16(struct map_info *map, unsigned long ofs)
84 + return __raw_readw(map->map_priv_1 + ofs);
87 +__u32 avalanche_read32(struct map_info *map, unsigned long ofs)
89 + return __raw_readl(map->map_priv_1 + ofs);
92 +void avalanche_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
94 + memcpy_fromio(to, map->map_priv_1 + from, len);
97 +void avalanche_write8(struct map_info *map, __u8 d, unsigned long adr)
99 + __raw_writeb(d, map->map_priv_1 + adr);
103 +void avalanche_write16(struct map_info *map, __u16 d, unsigned long adr)
105 + __raw_writew(d, map->map_priv_1 + adr);
109 +void avalanche_write32(struct map_info *map, __u32 d, unsigned long adr)
111 + __raw_writel(d, map->map_priv_1 + adr);
115 +void avalanche_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
117 + memcpy_toio(map->map_priv_1 + to, from, len);
120 +struct map_info avalanche_map = {
121 + name: "Physically mapped flash",
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
134 +int __init avalanche_mtd_init(void)
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);
139 + if (!avalanche_map.map_priv_1) {
140 + printk("Failed to ioremap\n");
144 + avalanche_mtd_info = do_map_probe("cfi_probe", &avalanche_map);
145 + if (!avalanche_mtd_info)
147 + avalanche_mtd_cleanup();
151 + avalanche_mtd_info->module = THIS_MODULE;
153 + if (!create_mtd_partitions())
154 + add_mtd_device(avalanche_mtd_info);
156 + add_mtd_partitions(avalanche_mtd_info, avalanche_partition_info, num_of_partitions);
158 + avalanche_mtd_ready=1;
163 +static char *strdup(char *str)
165 + int n = strlen(str)+1;
166 + char *s = kmalloc(n, GFP_KERNEL);
167 + if (!s) return NULL;
168 + return strcpy(s, str);
172 +static int create_mtd_partitions(void)
174 + unsigned int offset;
176 + unsigned int found;
177 + unsigned char *flash_base;
178 + unsigned char *flash_end;
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);
192 + env_ptr = prom_getenv(env_name);
193 + if(env_ptr == NULL) {
194 + /* No more partitions to find */
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);
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);
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);
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");
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);
234 + return num_of_partitions;
237 +static void __exit avalanche_mtd_cleanup(void)
239 + avalanche_mtd_ready=0;
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);
247 + if (avalanche_map.map_priv_1) {
248 + iounmap((void *)avalanche_map.map_priv_1);
249 + avalanche_map.map_priv_1 = 0;
253 +module_init(avalanche_mtd_init);
254 +module_exit(avalanche_mtd_cleanup);
256 +MODULE_LICENSE("GPL");
257 +MODULE_AUTHOR("Snehaprabha Narnakaje");
258 +MODULE_DESCRIPTION("Avalanche CFI map driver");