2 * Handle mapping of the flash memory access routines
3 * on TQM8xxL based devices.
7 * Copyright(C) 2001 Kirk Lee <kirk@hpc.ee.ntu.edu.tw>
14 * According to TQM8xxL hardware manual, TQM8xxL series have
15 * following flash memory organisations:
16 * | capacity | | chip type | | bank0 | | bank1 |
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>
35 #define FLASH_ADDR 0x40000000
36 #define FLASH_SIZE 0x00800000
37 #define FLASH_BANK_MAX 4
39 // trivial struct to describe partition information
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
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 /* Currently, TQM8xxL has up to 8MiB flash */
66 static unsigned long tqm8xxl_max_flash_size
= 0x00800000;
68 /* partition definition for first flash bank
69 * (cf. "drivers/char/flash_config.c")
71 static struct mtd_partition tqm8xxl_partitions
[] = {
75 .size
= 0x00020000, /* 128KB */
76 .mask_flags
= MTD_WRITEABLE
, /* force read-only */
79 .name
= "kernel", /* default kernel image */
82 .mask_flags
= MTD_WRITEABLE
, /* force read-only */
95 /* partition definition for second flash bank */
96 static struct mtd_partition tqm8xxl_fs_partitions
[] = {
104 .offset
= 0x00200000,
106 //.size = MTDPART_SIZ_FULL,
110 static int __init
init_tqm_mtd(void)
112 int idx
= 0, ret
= 0;
113 unsigned long flash_addr
, flash_size
, mtd_size
= 0;
114 /* pointer to TQM8xxL board info data */
115 bd_t
*bd
= (bd_t
*)__res
;
117 flash_addr
= bd
->bi_flashstart
;
118 flash_size
= bd
->bi_flashsize
;
120 //request maximum flash size address space
121 start_scan_addr
= ioremap(flash_addr
, flash_size
);
122 if (!start_scan_addr
) {
123 printk(KERN_WARNING
"%s:Failed to ioremap address:0x%x\n", __func__
, flash_addr
);
127 for (idx
= 0 ; idx
< FLASH_BANK_MAX
; idx
++) {
128 if(mtd_size
>= flash_size
)
131 printk(KERN_INFO
"%s: chip probing count %d\n", __func__
, idx
);
133 map_banks
[idx
] = kzalloc(sizeof(struct map_info
), GFP_KERNEL
);
134 if(map_banks
[idx
] == NULL
) {
136 /* FIXME: What if some MTD devices were probed already? */
140 map_banks
[idx
]->name
= kmalloc(16, GFP_KERNEL
);
142 if (!map_banks
[idx
]->name
) {
144 /* FIXME: What if some MTD devices were probed already? */
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
;
156 /* FIXME: This looks utterly bogus, but I'm trying to
157 preserve the behaviour of the original (shown here)...
159 map_banks[idx]->map_priv_1 =
160 start_scan_addr + ((idx > 0) ?
161 (mtd_banks[idx-1] ? mtd_banks[idx-1]->size : 0) : 0);
164 if (idx
&& mtd_banks
[idx
-1]) {
165 map_banks
[idx
]->virt
+= mtd_banks
[idx
-1]->size
;
166 map_banks
[idx
]->phys
+= mtd_banks
[idx
-1]->size
;
169 //start to probe flash chips
170 mtd_banks
[idx
] = do_map_probe("cfi_probe", map_banks
[idx
]);
172 if (mtd_banks
[idx
]) {
173 mtd_banks
[idx
]->owner
= THIS_MODULE
;
174 mtd_size
+= mtd_banks
[idx
]->size
;
177 printk(KERN_INFO
"%s: bank%d, name:%s, size:%dbytes \n", __func__
, num_banks
,
178 mtd_banks
[idx
]->name
, mtd_banks
[idx
]->size
);
182 /* no supported flash chips found */
184 printk(KERN_NOTICE
"TQM8xxL: No support flash chips found!\n");
190 * Select Static partition definitions
192 part_banks
[0].mtd_part
= tqm8xxl_partitions
;
193 part_banks
[0].type
= "Static image";
194 part_banks
[0].nums
= ARRAY_SIZE(tqm8xxl_partitions
);
196 part_banks
[1].mtd_part
= tqm8xxl_fs_partitions
;
197 part_banks
[1].type
= "Static file system";
198 part_banks
[1].nums
= ARRAY_SIZE(tqm8xxl_fs_partitions
);
200 for(idx
= 0; idx
< num_banks
; idx
++) {
201 if (part_banks
[idx
].nums
== 0)
202 printk(KERN_NOTICE
"TQM flash%d: no partition info available, registering whole flash at once\n", idx
);
204 printk(KERN_NOTICE
"TQM flash%d: Using %s partition definition\n",
205 idx
, part_banks
[idx
].type
);
206 mtd_device_register(mtd_banks
[idx
], part_banks
[idx
].mtd_part
,
207 part_banks
[idx
].nums
);
211 for(idx
= 0 ; idx
< FLASH_BANK_MAX
; idx
++) {
212 if(map_banks
[idx
] != NULL
) {
213 kfree(map_banks
[idx
]->name
);
214 map_banks
[idx
]->name
= NULL
;
215 kfree(map_banks
[idx
]);
216 map_banks
[idx
] = NULL
;
220 iounmap(start_scan_addr
);
224 static void __exit
cleanup_tqm_mtd(void)
226 unsigned int idx
= 0;
227 for(idx
= 0 ; idx
< num_banks
; idx
++) {
228 /* destroy mtd_info previously allocated */
229 if (mtd_banks
[idx
]) {
230 mtd_device_unregister(mtd_banks
[idx
]);
231 map_destroy(mtd_banks
[idx
]);
233 /* release map_info not used anymore */
234 kfree(map_banks
[idx
]->name
);
235 kfree(map_banks
[idx
]);
238 if (start_scan_addr
) {
239 iounmap(start_scan_addr
);
244 module_init(init_tqm_mtd
);
245 module_exit(cleanup_tqm_mtd
);
247 MODULE_LICENSE("GPL");
248 MODULE_AUTHOR("Kirk Lee <kirk@hpc.ee.ntu.edu.tw>");
249 MODULE_DESCRIPTION("MTD map driver for TQM8xxL boards");