6b4b2af6c19ea0b22bb1eb3d01090ead69fbd1b3
[openwrt/staging/chunkeey.git] / target / linux / rdc-2.6 / patches / 001-rdc3210_flash_map.patch
1 diff -urN linux-2.6.17/drivers/mtd/maps/imghdr.h linux-2.6.17.new/drivers/mtd/maps/imghdr.h
2 --- linux-2.6.17/drivers/mtd/maps/imghdr.h 1970-01-01 01:00:00.000000000 +0100
3 +++ linux-2.6.17.new/drivers/mtd/maps/imghdr.h 2006-09-24 20:29:20.000000000 +0200
4 @@ -0,0 +1,25 @@
5 +#ifndef GT_IMGHDR_H
6 +#define GT_IMGHDR_H
7 +
8 +#define GTIMG_MAGIC "GMTK"
9 +
10 +/* Product ID */
11 +#define PID_RTL_AIRGO 1
12 +#define PID_RTL_RALINK 2
13 +#define PID_RDC_AIRGO 3
14 +#define PID_RDC_RALINK 5 /* White Lable */
15 +
16 +/* Gemtek */
17 +typedef struct
18 +{
19 + UINT8 magic[4]; /* ASICII: GMTK */
20 + UINT32 checksum; /* CRC32 */
21 + UINT32 version; /* x.x.x.x */
22 + UINT32 kernelsz; /* The size of the kernel image */
23 + UINT32 imagesz; /* The length of this image file ( kernel + romfs + this header) */
24 + UINT32 pid; /* Product ID */
25 + UINT32 fastcksum; /* Partial CRC32 on (First(256), medium(256), last(512)) */
26 + UINT32 reserved;
27 +}gt_imghdr_t;
28 +
29 +#endif
30 diff -urN linux-2.6.17/drivers/mtd/maps/Kconfig linux-2.6.17.new/drivers/mtd/maps/Kconfig
31 --- linux-2.6.17/drivers/mtd/maps/Kconfig 2006-06-18 03:49:35.000000000 +0200
32 +++ linux-2.6.17.new/drivers/mtd/maps/Kconfig 2006-09-24 20:28:11.000000000 +0200
33 @@ -76,6 +76,12 @@
34 PNC-2000 is the name of Network Camera product from PHOTRON
35 Ltd. in Japan. It uses CFI-compliant flash.
36
37 +config MTD_RDC3210
38 + tristate "CFI Flash devcie mapped on RDC3210"
39 + depends on X86 && MTD_CFI && MTD_PARTITIONS
40 + help
41 + RDC-3210 is the flash device we find on Ralink reference board
42 +
43 config MTD_SC520CDP
44 tristate "CFI Flash device mapped on AMD SC520 CDP"
45 depends on X86 && MTD_CFI
46 diff -urN linux-2.6.17/drivers/mtd/maps/Makefile linux-2.6.17.new/drivers/mtd/maps/Makefile
47 --- linux-2.6.17/drivers/mtd/maps/Makefile 2006-06-18 03:49:35.000000000 +0200
48 +++ linux-2.6.17.new/drivers/mtd/maps/Makefile 2006-09-24 20:26:10.000000000 +0200
49 @@ -28,6 +28,7 @@
50 obj-$(CONFIG_MTD_PHYSMAP) += physmap.o
51 obj-$(CONFIG_MTD_PNC2000) += pnc2000.o
52 obj-$(CONFIG_MTD_PCMCIA) += pcmciamtd.o
53 +obj-$(CONFIG_MTD_RDC3210) += rdc3210.o
54 obj-$(CONFIG_MTD_RPXLITE) += rpxlite.o
55 obj-$(CONFIG_MTD_TQM8XXL) += tqm8xxl.o
56 obj-$(CONFIG_MTD_SA1100) += sa1100-flash.o
57 diff -urN linux-2.6.17/drivers/mtd/maps/rdc3210.c linux-2.6.17.new/drivers/mtd/maps/rdc3210.c
58 --- linux-2.6.17/drivers/mtd/maps/rdc3210.c 1970-01-01 01:00:00.000000000 +0100
59 +++ linux-2.6.17.new/drivers/mtd/maps/rdc3210.c 2006-09-24 22:55:20.000000000 +0200
60 @@ -0,0 +1,211 @@
61 +/*******************************************************************
62 + * Simple Flash mapping for RDC3210 *
63 + * *
64 + * 2005.03.23 *
65 + * Dante Su (dante_su@gemtek.com.tw) *
66 + * Copyright (C) 2005 Gemtek Corporation *
67 + *******************************************************************/
68 +
69 +#include <linux/module.h>
70 +#include <linux/slab.h>
71 +#include <linux/types.h>
72 +#include <linux/kernel.h>
73 +#include <asm/io.h>
74 +#include <linux/mtd/mtd.h>
75 +#include <linux/mtd/map.h>
76 +#include <linux/mtd/partitions.h>
77 +#include <linux/autoconf.h>
78 +
79 +#define WINDOW_ADDR 0xFFC00000
80 +#define WINDOW_SIZE 0x00400000
81 +
82 +#define BUSWIDTH 2
83 +
84 +static struct mtd_info *rdc3210_mtd_info;
85 +
86 +__u8 rdc3210_map_read8(struct map_info *map, unsigned long ofs)
87 +{
88 + return *(__u8 *)(map->map_priv_1 + ofs);
89 +}
90 +
91 +__u16 rdc3210_map_read16(struct map_info *map, unsigned long ofs)
92 +{
93 + return *(__u16 *)(map->map_priv_1 + ofs);
94 +}
95 +
96 +__u32 rdc3210_map_read32(struct map_info *map, unsigned long ofs)
97 +{
98 + return *(__u32 *)(map->map_priv_1 + ofs);
99 +}
100 +
101 +void rdc3210_map_write8(struct map_info *map, __u8 d, unsigned long adr)
102 +{
103 + *(__u8 *)(map->map_priv_1 + adr) = d;
104 +}
105 +
106 +void rdc3210_map_write16(struct map_info *map, __u16 d, unsigned long adr)
107 +{
108 + *(__u16 *)(map->map_priv_1 + adr) = d;
109 +}
110 +
111 +void rdc3210_map_write32(struct map_info *map, __u32 d, unsigned long adr)
112 +{
113 + *(__u32 *)(map->map_priv_1 + adr) = d;
114 +}
115 +
116 +void rdc3210_map_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
117 +{
118 + int i;
119 + u16 *dst = (u16 *)(to);
120 + u16 *src = (u16 *)(map->map_priv_1 + from);
121 +
122 + for(i = 0; i < (len / 2); ++i)
123 + dst[i] = src[i];
124 +
125 + if(len & 1)
126 + {
127 + printk("# WARNNING!!! rdc3210_map_copy_from has odd length\n");
128 + //dst[len - 1] = B0(src[i]);
129 + }
130 +}
131 +
132 +void rdc3210_map_copy_to(struct map_info *map, void *to, unsigned long from, ssize_t len)
133 +{
134 + int i;
135 + u16 *dst = (u16 *)(map->map_priv_1 + to);
136 + u16 *src = (u16 *)(from);
137 +
138 + for(i = 0; i < (len / 2); ++i)
139 + dst[i] = src[i];
140 +
141 + if(len & 1)
142 + {
143 + printk("# WARNNING!!! rdc3210_map_copy_from has odd length\n");
144 + //dst[len - 1] = B0(src[i]);
145 + }
146 +}
147 +
148 +static struct map_info rdc3210_map =
149 +{
150 + .name = "RDC3210 Flash",
151 + .size = WINDOW_SIZE,
152 + .bankwidth = BUSWIDTH,
153 + .phys = WINDOW_ADDR,
154 +};
155 +
156 +/* Dante: This is the default static mapping, however this is nothing but a hint. (Say dynamic mapping) */
157 +static struct mtd_partition rdc3210_parts[] =
158 +{
159 + { .name = "linux", .offset = 0, .size = 0x003C0000 }, /* 3840 KB = (Kernel + ROMFS) = (768 KB + 3072 KB) */
160 + { .name = "romfs", .offset = 0x000C0000, .size = 0x00300000 }, /* 3072 KB */
161 + { .name = "nvram", .offset = 0x003C0000, .size = 0x00010000 }, /* 64 KB */
162 + { .name = "factory", .offset = 0x003D0000, .size = 0x00010000 }, /* 64 KB */
163 + { .name = "bootldr", .offset = 0x003E0000, .size = 0x00020000 }, /* 128 KB */
164 +};
165 +
166 +static int __init rdc3210_mtd_init(void)
167 +{
168 + printk(KERN_NOTICE "flash device: 0x%x at 0x%x\n", WINDOW_SIZE, WINDOW_ADDR);
169 +
170 + rdc3210_map.virt = ioremap(WINDOW_ADDR, WINDOW_SIZE);
171 +
172 + if (!rdc3210_map.virt)
173 + {
174 + printk("Failed to ioremap\n");
175 + return -EIO;
176 + }
177 +
178 + simple_map_init(&rdc3210_map);
179 +
180 + rdc3210_mtd_info = do_map_probe("cfi_probe", &rdc3210_map);
181 + /* Dante: This is for fixed map */
182 + if (rdc3210_mtd_info)
183 + {
184 + rdc3210_mtd_info->owner = THIS_MODULE;
185 + add_mtd_partitions(rdc3210_mtd_info, rdc3210_parts, sizeof(rdc3210_parts)/sizeof(rdc3210_parts[0]));
186 + return 0;
187 + }
188 + /* Dante: This is for dynamic mapping */
189 +#if 0
190 + if (rdc3210_mtd_info)
191 + { // Dante
192 + unsigned int tmp;
193 + gt_imghdr_t *hdr;
194 +
195 + hdr = (gt_imghdr_t *)(rdc3210_map.virt);
196 +
197 + if(memcmp(hdr->magic, GTIMG_MAGIC, 4))
198 + {
199 + printk("Invalid MAGIC for Firmware Image!!!\n");
200 + return -EIO;
201 + }
202 +
203 + /* 1. Adjust Redboot */
204 + tmp = flashdrv_get_size() - rdc3210_parts[4].size;
205 + rdc3210_parts[4].offset = flashdrv_get_sector_addr(flashdrv_get_sector(tmp));
206 + rdc3210_parts[4].size = flashdrv_get_size() - rdc3210_parts[4].offset;
207 +
208 + /* 2. Adjust NVRAM */
209 + tmp -= rdc3210_parts[3].size;
210 + rdc3210_parts[3].offset = flashdrv_get_sector_addr(flashdrv_get_sector(tmp));
211 + rdc3210_parts[3].size = rdc3210_parts[4].offset - rdc3210_parts[3].offset;
212 +
213 + /* 3. Adjust Factory Default */
214 + tmp -= rdc3210_parts[2].size;
215 + rdc3210_parts[2].offset = flashdrv_get_sector_addr(flashdrv_get_sector(tmp));
216 + rdc3210_parts[2].size = rdc3210_parts[3].offset - rdc3210_parts[2].offset;
217 +
218 + /* 4. Adjust Linux (Kernel + ROMFS) */
219 + rdc3210_parts[0].size = rdc3210_parts[2].offset - rdc3210_parts[0].offset;
220 +
221 + /* 5. Adjust ROMFS */
222 + tmp = hdr->kernelsz + sizeof(gt_imghdr_t);
223 + rdc3210_parts[1].offset = rdc3210_parts[0].offset + (((tmp / 32) + ((tmp % 32) ? 1 : 0)) * 32);
224 + rdc3210_parts[1].size = rdc3210_parts[2].offset - rdc3210_parts[1].offset;
225 +
226 + /* 1. Adjust Redboot */
227 + tmp = flashdrv_get_size() - rdc3210_parts[3].size;
228 + rdc3210_parts[3].offset = flashdrv_get_sector_addr(flashdrv_get_sector(tmp));
229 + rdc3210_parts[3].size = flashdrv_get_size() - rdc3210_parts[3].offset;
230 +
231 + /* 2. Adjust NVRAM */
232 + tmp -= rdc3210_parts[2].size;
233 + rdc3210_parts[2].offset = flashdrv_get_sector_addr(flashdrv_get_sector(tmp));
234 + rdc3210_parts[2].size = rdc3210_parts[3].offset - rdc3210_parts[2].offset;
235 +
236 + /* 4. Adjust Linux (Kernel + ROMFS) */
237 + rdc3210_parts[0].size = rdc3210_parts[2].offset - rdc3210_parts[0].offset;
238 +
239 + /* 5. Adjust ROMFS */
240 + tmp = hdr->kernelsz + sizeof(gt_imghdr_t);
241 + rdc3210_parts[1].offset = rdc3210_parts[0].offset + (((tmp / 32) + ((tmp % 32) ? 1 : 0)) * 32);
242 + rdc3210_parts[1].size = rdc3210_parts[2].offset - rdc3210_parts[1].offset;
243 +
244 + rdc3210_mtd_info->owner = THIS_MODULE;
245 + add_mtd_partitions(rdc3210_mtd_info, rdc3210_parts, sizeof(rdc3210_parts)/sizeof(rdc3210_parts[0]));
246 + return 0;
247 + }
248 +#endif
249 + iounmap((void *)rdc3210_map.virt);
250 + return -ENXIO;
251 +}
252 +
253 +static void __exit rdc3210_mtd_exit(void)
254 +{
255 + if (rdc3210_mtd_info)
256 + {
257 + del_mtd_partitions(rdc3210_mtd_info);
258 + map_destroy(rdc3210_mtd_info);
259 + }
260 +
261 + if (rdc3210_map.virt)
262 + {
263 + iounmap(rdc3210_map.virt);
264 + rdc3210_map.virt = 0;
265 + }
266 +}
267 +
268 +module_init(rdc3210_mtd_init);
269 +module_exit(rdc3210_mtd_exit);
270 +MODULE_LICENSE("GPL");
271 +