Lines Matching +full:rom +full:- +full:15 +full:h
1 // SPDX-License-Identifier: GPL-2.0-only
11 #include <linux/module.h>
12 #include <linux/types.h>
13 #include <linux/kernel.h>
14 #include <linux/init.h>
15 #include <linux/slab.h>
16 #include <asm/io.h>
17 #include <linux/mtd/mtd.h>
18 #include <linux/mtd/map.h>
19 #include <linux/mtd/cfi.h>
20 #include <linux/mtd/flashchip.h>
21 #include <linux/pci.h>
22 #include <linux/pci_ids.h>
23 #include <linux/list.h>
67 * The 15 bits controlling the window size are distributed as follows:
69 * byte @0x8c: bit 8..15
76 MODULE_PARM_DESC(win_size_bits, "ROM window size bits override, normally set by BIOS.");
87 if (window->pdev) { in ck804xrom_cleanup()
88 /* Disable writes through the rom window */ in ck804xrom_cleanup()
89 pci_read_config_byte(window->pdev, 0x6d, &byte); in ck804xrom_cleanup()
90 pci_write_config_byte(window->pdev, 0x6d, byte & ~1); in ck804xrom_cleanup()
94 list_for_each_entry_safe(map, scratch, &window->maps, list) { in ck804xrom_cleanup()
95 if (map->rsrc.parent) in ck804xrom_cleanup()
96 release_resource(&map->rsrc); in ck804xrom_cleanup()
98 mtd_device_unregister(map->mtd); in ck804xrom_cleanup()
99 map_destroy(map->mtd); in ck804xrom_cleanup()
100 list_del(&map->list); in ck804xrom_cleanup()
103 if (window->rsrc.parent) in ck804xrom_cleanup()
104 release_resource(&window->rsrc); in ck804xrom_cleanup()
106 if (window->virt) { in ck804xrom_cleanup()
107 iounmap(window->virt); in ck804xrom_cleanup()
108 window->virt = NULL; in ck804xrom_cleanup()
109 window->phys = 0; in ck804xrom_cleanup()
110 window->size = 0; in ck804xrom_cleanup()
112 pci_dev_put(window->pdev); in ck804xrom_cleanup()
127 window->pdev = pci_dev_get(pdev); in ck804xrom_init_one()
129 switch (ent->driver_data) { in ck804xrom_init_one()
131 /* Enable the selected rom window. This is often incorrectly in ck804xrom_init_one()
141 /* Assume the rom window is properly setup, and find it's size */ in ck804xrom_init_one()
145 window->phys = 0xffb00000; /* 5MiB */ in ck804xrom_init_one()
147 window->phys = 0xffc00000; /* 4MiB */ in ck804xrom_init_one()
149 window->phys = 0xffff0000; /* 64KiB */ in ck804xrom_init_one()
162 window->phys = 0xff000000; /* 16MiB, hardcoded for now */ in ck804xrom_init_one()
166 window->size = 0xffffffffUL - window->phys + 1UL; in ck804xrom_init_one()
172 * request_mem_region() fails then once the rom size is in ck804xrom_init_one()
175 window->rsrc.name = MOD_NAME; in ck804xrom_init_one()
176 window->rsrc.start = window->phys; in ck804xrom_init_one()
177 window->rsrc.end = window->phys + window->size - 1; in ck804xrom_init_one()
178 window->rsrc.flags = IORESOURCE_MEM | IORESOURCE_BUSY; in ck804xrom_init_one()
179 if (request_resource(&iomem_resource, &window->rsrc)) { in ck804xrom_init_one()
180 window->rsrc.parent = NULL; in ck804xrom_init_one()
182 " %s(): Unable to register resource %pR - kernel bug?\n", in ck804xrom_init_one()
183 __func__, &window->rsrc); in ck804xrom_init_one()
187 /* Enable writes through the rom window */ in ck804xrom_init_one()
191 /* FIXME handle registers 0x80 - 0x8C the bios region locks */ in ck804xrom_init_one()
194 window->virt = ioremap(window->phys, window->size); in ck804xrom_init_one()
195 if (!window->virt) { in ck804xrom_init_one()
197 window->phys, window->size); in ck804xrom_init_one()
201 /* Get the first address to look for a rom chip at */ in ck804xrom_init_one()
202 map_top = window->phys; in ck804xrom_init_one()
211 /* Loop through and look for rom chips. Since we don't know the in ck804xrom_init_one()
215 while((map_top - 1) < 0xffffffffUL) { in ck804xrom_init_one()
226 INIT_LIST_HEAD(&map->list); in ck804xrom_init_one()
227 map->map.name = map->map_name; in ck804xrom_init_one()
228 map->map.phys = map_top; in ck804xrom_init_one()
229 offset = map_top - window->phys; in ck804xrom_init_one()
230 map->map.virt = (void __iomem *) in ck804xrom_init_one()
231 (((unsigned long)(window->virt)) + offset); in ck804xrom_init_one()
232 map->map.size = 0xffffffffUL - map_top + 1UL; in ck804xrom_init_one()
234 sprintf(map->map_name, "%s @%08Lx", in ck804xrom_init_one()
235 MOD_NAME, (unsigned long long)map->map.phys); in ck804xrom_init_one()
238 for(map->map.bankwidth = 32; map->map.bankwidth; in ck804xrom_init_one()
239 map->map.bankwidth >>= 1) in ck804xrom_init_one()
243 if (!map_bankwidth_supported(map->map.bankwidth)) in ck804xrom_init_one()
247 simple_map_init(&map->map); in ck804xrom_init_one()
252 map->mtd = do_map_probe(*probe_type, &map->map); in ck804xrom_init_one()
253 if (map->mtd) in ck804xrom_init_one()
261 if (map->mtd->size > map->map.size) { in ck804xrom_init_one()
263 " rom(%llu) larger than window(%lu). fixing...\n", in ck804xrom_init_one()
264 (unsigned long long)map->mtd->size, map->map.size); in ck804xrom_init_one()
265 map->mtd->size = map->map.size; in ck804xrom_init_one()
267 if (window->rsrc.parent) { in ck804xrom_init_one()
273 map->rsrc.name = map->map_name; in ck804xrom_init_one()
274 map->rsrc.start = map->map.phys; in ck804xrom_init_one()
275 map->rsrc.end = map->map.phys + map->mtd->size - 1; in ck804xrom_init_one()
276 map->rsrc.flags = IORESOURCE_MEM | IORESOURCE_BUSY; in ck804xrom_init_one()
277 if (request_resource(&window->rsrc, &map->rsrc)) { in ck804xrom_init_one()
280 map->rsrc.parent = NULL; in ck804xrom_init_one()
285 map->map.virt = window->virt; in ck804xrom_init_one()
286 map->map.phys = window->phys; in ck804xrom_init_one()
287 cfi = map->map.fldrv_priv; in ck804xrom_init_one()
288 for(i = 0; i < cfi->numchips; i++) in ck804xrom_init_one()
289 cfi->chips[i].start += offset; in ck804xrom_init_one()
292 map->mtd->owner = THIS_MODULE; in ck804xrom_init_one()
293 if (mtd_device_register(map->mtd, NULL, 0)) { in ck804xrom_init_one()
294 map_destroy(map->mtd); in ck804xrom_init_one()
295 map->mtd = NULL; in ck804xrom_init_one()
301 map_top += map->mtd->size; in ck804xrom_init_one()
304 list_add(&map->list, &window->maps); in ck804xrom_init_one()
313 if (list_empty(&window->maps)) { in ck804xrom_init_one()
315 return -ENODEV; in ck804xrom_init_one()
359 for(id = ck804xrom_pci_tbl; id->vendor; id++) { in init_ck804xrom()
360 pdev = pci_get_device(id->vendor, id->device, NULL); in init_ck804xrom()
369 return -ENXIO; in init_ck804xrom()