GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / mtd / maps / tqm8xxl.c
blobb4e8b135a5e23660ae2dcdf31e8c7def74e090b5
1 /*
2 * Handle mapping of the flash memory access routines
3 * on TQM8xxL based devices.
5 * based on rpxlite.c
7 * Copyright(C) 2001 Kirk Lee <kirk@hpc.ee.ntu.edu.tw>
9 * This code is GPLed
14 * According to TQM8xxL hardware manual, TQM8xxL series have
15 * following flash memory organisations:
16 * | capacity | | chip type | | bank0 | | bank1 |
17 * 2MiB 512Kx16 2MiB 0
18 * 4MiB 1Mx16 4MiB 0
19 * 8MiB 1Mx16 4MiB 4MiB
20 * Thus, we choose CONFIG_MTD_CFI_I2 & CONFIG_MTD_CFI_B4 at
21 * kernel configuration.
23 #include <linux/module.h>
24 #include <linux/types.h>
25 #include <linux/kernel.h>
26 #include <linux/init.h>
27 #include <linux/slab.h>
29 #include <linux/mtd/mtd.h>
30 #include <linux/mtd/map.h>
31 #include <linux/mtd/partitions.h>
33 #include <asm/io.h>
35 #define FLASH_ADDR 0x40000000
36 #define FLASH_SIZE 0x00800000
37 #define FLASH_BANK_MAX 4
39 // trivial struct to describe partition information
40 struct mtd_part_def
42 int nums;
43 unsigned char *type;
44 struct mtd_partition* mtd_part;
47 //static struct mtd_info *mymtd;
48 static struct mtd_info* mtd_banks[FLASH_BANK_MAX];
49 static struct map_info* map_banks[FLASH_BANK_MAX];
50 static struct mtd_part_def part_banks[FLASH_BANK_MAX];
51 static unsigned long num_banks;
52 static void __iomem *start_scan_addr;
55 * Here are partition information for all known TQM8xxL series devices.
56 * See include/linux/mtd/partitions.h for definition of the mtd_partition
57 * structure.
59 * The *_max_flash_size is the maximum possible mapped flash size which
60 * is not necessarily the actual flash size. It must correspond to the
61 * value specified in the mapping definition defined by the
62 * "struct map_desc *_io_desc" for the corresponding machine.
65 #ifdef CONFIG_MTD_PARTITIONS
66 /* Currently, TQM8xxL has upto 8MiB flash */
67 static unsigned long tqm8xxl_max_flash_size = 0x00800000;
69 /* partition definition for first flash bank
70 * (cf. "drivers/char/flash_config.c")
72 static struct mtd_partition tqm8xxl_partitions[] = {
74 .name = "ppcboot",
75 .offset = 0x00000000,
76 .size = 0x00020000, /* 128KB */
77 .mask_flags = MTD_WRITEABLE, /* force read-only */
80 .name = "kernel", /* default kernel image */
81 .offset = 0x00020000,
82 .size = 0x000e0000,
83 .mask_flags = MTD_WRITEABLE, /* force read-only */
86 .name = "user",
87 .offset = 0x00100000,
88 .size = 0x00100000,
91 .name = "initrd",
92 .offset = 0x00200000,
93 .size = 0x00200000,
96 /* partition definition for second flash bank */
97 static struct mtd_partition tqm8xxl_fs_partitions[] = {
99 .name = "cramfs",
100 .offset = 0x00000000,
101 .size = 0x00200000,
104 .name = "jffs",
105 .offset = 0x00200000,
106 .size = 0x00200000,
107 //.size = MTDPART_SIZ_FULL,
110 #endif
112 static int __init init_tqm_mtd(void)
114 int idx = 0, ret = 0;
115 unsigned long flash_addr, flash_size, mtd_size = 0;
116 /* pointer to TQM8xxL board info data */
117 bd_t *bd = (bd_t *)__res;
119 flash_addr = bd->bi_flashstart;
120 flash_size = bd->bi_flashsize;
122 //request maximum flash size address space
123 start_scan_addr = ioremap(flash_addr, flash_size);
124 if (!start_scan_addr) {
125 printk(KERN_WARNING "%s:Failed to ioremap address:0x%x\n", __func__, flash_addr);
126 return -EIO;
129 for (idx = 0 ; idx < FLASH_BANK_MAX ; idx++) {
130 if(mtd_size >= flash_size)
131 break;
133 printk(KERN_INFO "%s: chip probing count %d\n", __func__, idx);
135 map_banks[idx] = kzalloc(sizeof(struct map_info), GFP_KERNEL);
136 if(map_banks[idx] == NULL) {
137 ret = -ENOMEM;
138 goto error_mem;
141 map_banks[idx]->name = (char *)kmalloc(16, GFP_KERNEL);
143 if (!map_banks[idx]->name) {
144 ret = -ENOMEM;
145 goto error_mem;
147 sprintf(map_banks[idx]->name, "TQM8xxL%d", idx);
149 map_banks[idx]->size = flash_size;
150 map_banks[idx]->bankwidth = 4;
152 simple_map_init(map_banks[idx]);
154 map_banks[idx]->virt = start_scan_addr;
155 map_banks[idx]->phys = flash_addr;
157 if (idx && mtd_banks[idx-1]) {
158 map_banks[idx]->virt += mtd_banks[idx-1]->size;
159 map_banks[idx]->phys += mtd_banks[idx-1]->size;
162 //start to probe flash chips
163 mtd_banks[idx] = do_map_probe("cfi_probe", map_banks[idx]);
165 if (mtd_banks[idx]) {
166 mtd_banks[idx]->owner = THIS_MODULE;
167 mtd_size += mtd_banks[idx]->size;
168 num_banks++;
170 printk(KERN_INFO "%s: bank%d, name:%s, size:%dbytes \n", __func__, num_banks,
171 mtd_banks[idx]->name, mtd_banks[idx]->size);
175 /* no supported flash chips found */
176 if (!num_banks) {
177 printk(KERN_NOTICE "TQM8xxL: No support flash chips found!\n");
178 ret = -ENXIO;
179 goto error_mem;
182 #ifdef CONFIG_MTD_PARTITIONS
184 * Select Static partition definitions
186 part_banks[0].mtd_part = tqm8xxl_partitions;
187 part_banks[0].type = "Static image";
188 part_banks[0].nums = ARRAY_SIZE(tqm8xxl_partitions);
190 part_banks[1].mtd_part = tqm8xxl_fs_partitions;
191 part_banks[1].type = "Static file system";
192 part_banks[1].nums = ARRAY_SIZE(tqm8xxl_fs_partitions);
194 for(idx = 0; idx < num_banks ; idx++) {
195 if (part_banks[idx].nums == 0) {
196 printk(KERN_NOTICE "TQM flash%d: no partition info available, registering whole flash at once\n", idx);
197 add_mtd_device(mtd_banks[idx]);
198 } else {
199 printk(KERN_NOTICE "TQM flash%d: Using %s partition definition\n",
200 idx, part_banks[idx].type);
201 add_mtd_partitions(mtd_banks[idx], part_banks[idx].mtd_part,
202 part_banks[idx].nums);
205 #else
206 printk(KERN_NOTICE "TQM flash: registering %d whole flash banks at once\n", num_banks);
207 for(idx = 0 ; idx < num_banks ; idx++)
208 add_mtd_device(mtd_banks[idx]);
209 #endif
210 return 0;
211 error_mem:
212 for(idx = 0 ; idx < FLASH_BANK_MAX ; idx++) {
213 if(map_banks[idx] != NULL) {
214 kfree(map_banks[idx]->name);
215 map_banks[idx]->name = NULL;
216 kfree(map_banks[idx]);
217 map_banks[idx] = NULL;
220 error:
221 iounmap(start_scan_addr);
222 return ret;
225 static void __exit cleanup_tqm_mtd(void)
227 unsigned int idx = 0;
228 for(idx = 0 ; idx < num_banks ; idx++) {
229 /* destroy mtd_info previously allocated */
230 if (mtd_banks[idx]) {
231 del_mtd_partitions(mtd_banks[idx]);
232 map_destroy(mtd_banks[idx]);
234 /* release map_info not used anymore */
235 kfree(map_banks[idx]->name);
236 kfree(map_banks[idx]);
239 if (start_scan_addr) {
240 iounmap(start_scan_addr);
241 start_scan_addr = 0;
245 module_init(init_tqm_mtd);
246 module_exit(cleanup_tqm_mtd);
248 MODULE_LICENSE("GPL");
249 MODULE_AUTHOR("Kirk Lee <kirk@hpc.ee.ntu.edu.tw>");
250 MODULE_DESCRIPTION("MTD map driver for TQM8xxL boards");