10 #include <linux/module.h>
11 #include <linux/types.h>
12 #include <linux/kernel.h>
14 #include <linux/slab.h>
20 #include <linux/pci.h>
22 #include <linux/list.h>
25 #define MOD_NAME KBUILD_BASENAME
27 #define ADDRESS_NAME_LEN 18
29 #define ROM_PROBE_STEP_SIZE (64*1024)
73 static uint win_size_bits = 0;
75 MODULE_PARM_DESC(win_size_bits,
"ROM window size bits override, normally set by BIOS.");
81 static void ck804xrom_cleanup(
struct ck804xrom_window *
window)
88 pci_read_config_byte(window->
pdev, 0x6d, &byte);
89 pci_write_config_byte(window->
pdev, 0x6d, byte & ~1);
102 if (window->
rsrc.parent)
118 static char *rom_probe_types[] = {
"cfi_probe",
"jedec_probe",
NULL };
121 struct ck804xrom_window *window = &ck804xrom_window;
123 unsigned long map_top;
137 pci_read_config_byte(pdev, 0x88, &byte);
138 pci_write_config_byte(pdev, 0x88, byte | win_size_bits );
141 pci_read_config_byte(pdev, 0x88, &byte);
143 if ((byte & ((1<<7)|(1<<6))) == ((1<<7)|(1<<6)))
144 window->
phys = 0xffb00000;
145 else if ((byte & (1<<7)) == (1<<7))
146 window->
phys = 0xffc00000;
148 window->
phys = 0xffff0000;
152 pci_read_config_byte(pdev, 0x88, &byte);
153 pci_write_config_byte(pdev, 0x88, byte | (win_size_bits & 0xff));
155 pci_read_config_byte(pdev, 0x8c, &byte);
156 pci_write_config_byte(pdev, 0x8c, byte | ((win_size_bits & 0xff00) >> 8));
158 pci_read_config_word(pdev, 0x90, &word);
159 pci_write_config_word(pdev, 0x90, word | ((win_size_bits & 0x7fff0000) >> 16));
161 window->
phys = 0xff000000;
181 " %s(): Unable to register resource %pR - kernel bug?\n",
182 __func__, &window->
rsrc);
187 pci_read_config_byte(pdev, 0x6d, &byte);
188 pci_write_config_byte(pdev, 0x6d, byte | 1);
201 map_top = window->
phys;
207 if (map_top < 0xffc00000)
208 map_top = 0xffc00000;
214 while((map_top - 1) < 0xffffffffUL) {
226 memset(map, 0,
sizeof(*map));
227 INIT_LIST_HEAD(&map->
list);
229 map->
map.phys = map_top;
230 offset = map_top - window->
phys;
233 map->
map.size = 0xffffffff
UL - map_top + 1
UL;
239 for(map->
map.bankwidth = 32; map->
map.bankwidth;
240 map->
map.bankwidth >>= 1)
244 if (!map_bankwidth_supported(map->
map.bankwidth))
251 probe_type = rom_probe_types;
252 for(; *probe_type; probe_type++) {
262 if (map->
mtd->size > map->
map.size) {
264 " rom(%llu) larger than window(%lu). fixing...\n",
265 (
unsigned long long)map->
mtd->size, map->
map.size);
266 map->
mtd->size = map->
map.size;
268 if (window->
rsrc.parent) {
275 map->
rsrc.start = map->
map.phys;
276 map->
rsrc.end = map->
map.phys + map->
mtd->size - 1;
280 ": cannot reserve MTD resource\n");
288 cfi = map->
map.fldrv_priv;
290 cfi->
chips[i].start += offset;
302 map_top += map->
mtd->size;
305 list_add(&map->
list, &window->
maps);
315 if (list_empty(&window->
maps)) {
316 ck804xrom_cleanup(window);
325 struct ck804xrom_window *window = &ck804xrom_window;
327 ck804xrom_cleanup(window);
348 .id_table = ck804xrom_pci_tbl,
349 .probe = ck804xrom_init_one,
350 .remove = ck804xrom_remove_one,
354 static int __init init_ck804xrom(
void)
361 for(
id = ck804xrom_pci_tbl;
id->
vendor;
id++) {
367 retVal = ck804xrom_init_one(pdev,
id);
373 return pci_register_driver(&ck804xrom_driver);
377 static void __exit cleanup_ck804xrom(
void)
379 ck804xrom_remove_one(ck804xrom_window.
pdev);