2 * $Id: l440gx.c,v 1.8 2002/01/10 20:27:40 eric Exp $
4 * BIOS Flash chip on Intel 440GX board.
6 * Bugs this currently does not work under linuxBIOS.
9 #include <linux/module.h>
10 #include <linux/pci.h>
11 #include <linux/kernel.h>
13 #include <linux/mtd/mtd.h>
14 #include <linux/mtd/map.h>
15 #include <linux/config.h>
17 #define PIIXE_IOBASE_RESOURCE 11
19 #define WINDOW_ADDR 0xfff00000
20 #define WINDOW_SIZE 0x00100000
25 #define TRIBUF_PORT (IOBASE+0x37)
26 #define VPP_PORT (IOBASE+0x28)
28 static struct mtd_info *mymtd;
30 __u8 l440gx_read8(struct map_info *map, unsigned long ofs)
32 return __raw_readb(map->map_priv_1 + ofs);
35 __u16 l440gx_read16(struct map_info *map, unsigned long ofs)
37 return __raw_readw(map->map_priv_1 + ofs);
40 __u32 l440gx_read32(struct map_info *map, unsigned long ofs)
42 return __raw_readl(map->map_priv_1 + ofs);
45 void l440gx_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
47 memcpy_fromio(to, map->map_priv_1 + from, len);
50 void l440gx_write8(struct map_info *map, __u8 d, unsigned long adr)
52 __raw_writeb(d, map->map_priv_1 + adr);
56 void l440gx_write16(struct map_info *map, __u16 d, unsigned long adr)
58 __raw_writew(d, map->map_priv_1 + adr);
62 void l440gx_write32(struct map_info *map, __u32 d, unsigned long adr)
64 __raw_writel(d, map->map_priv_1 + adr);
68 void l440gx_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
70 memcpy_toio(map->map_priv_1 + to, from, len);
73 /* Is this really the vpp port? */
74 void l440gx_set_vpp(struct map_info *map, int vpp)
87 struct map_info l440gx_map = {
92 read16: l440gx_read16,
93 read32: l440gx_read32,
94 copy_from: l440gx_copy_from,
95 write8: l440gx_write8,
96 write16: l440gx_write16,
97 write32: l440gx_write32,
98 copy_to: l440gx_copy_to,
100 /* FIXME verify that this is the
101 * appripriate code for vpp enable/disable
103 set_vpp: l440gx_set_vpp
107 static int __init init_l440gx(void)
109 struct pci_dev *dev, *pm_dev;
110 struct resource *pm_iobase;
113 dev = pci_find_device(PCI_VENDOR_ID_INTEL,
114 PCI_DEVICE_ID_INTEL_82371AB_0, NULL);
117 pm_dev = pci_find_device(PCI_VENDOR_ID_INTEL,
118 PCI_DEVICE_ID_INTEL_82371AB_3, NULL);
120 if (!dev || !pm_dev) {
121 printk(KERN_NOTICE "L440GX flash mapping: failed to find PIIX4 ISA bridge, cannot continue\n");
126 l440gx_map.map_priv_1 = (unsigned long)ioremap_nocache(WINDOW_ADDR, WINDOW_SIZE);
128 if (!l440gx_map.map_priv_1) {
129 printk(KERN_WARNING "Failed to ioremap L440GX flash region\n");
133 printk(KERN_NOTICE "window_addr = 0x%08lx\n", (unsigned long)l440gx_map.map_priv_1);
135 /* Setup the pm iobase resource
136 * This code should move into some kind of generic bridge
137 * driver but for the moment I'm content with getting the
138 * allocation correct.
140 pm_iobase = &pm_dev->resource[PIIXE_IOBASE_RESOURCE];
141 if (!(pm_iobase->flags & IORESOURCE_IO)) {
142 pm_iobase->name = "pm iobase";
143 pm_iobase->start = 0;
145 pm_iobase->flags = IORESOURCE_IO;
147 /* Put the current value in the resource */
148 pci_read_config_dword(pm_dev, 0x40, &iobase);
150 pm_iobase->start += iobase & ~1;
151 pm_iobase->end += iobase & ~1;
153 /* Allocate the resource region */
154 if (pci_assign_resource(pm_dev, PIIXE_IOBASE_RESOURCE) != 0) {
155 printk(KERN_WARNING "Could not allocate pm iobase resource\n");
156 iounmap((void *)l440gx_map.map_priv_1);
161 iobase = pm_iobase->start;
162 pci_write_config_dword(pm_dev, 0x40, iobase | 1);
166 pci_read_config_word(dev, 0x4e, &word);
168 pci_write_config_word(dev, 0x4e, word);
170 /* Supply write voltage to the chip */
171 l440gx_set_vpp(&l440gx_map, 1);
173 /* Enable the gate on the WE line */
174 outb(inb(TRIBUF_PORT) & ~1, TRIBUF_PORT);
176 printk(KERN_NOTICE "Enabled WE line to L440GX BIOS flash chip.\n");
178 mymtd = do_map_probe("jedec_probe", &l440gx_map);
180 printk(KERN_NOTICE "JEDEC probe on BIOS chip failed. Using ROM\n");
181 mymtd = do_map_probe("map_rom", &l440gx_map);
184 mymtd->module = THIS_MODULE;
186 add_mtd_device(mymtd);
190 iounmap((void *)l440gx_map.map_priv_1);
194 static void __exit cleanup_l440gx(void)
196 del_mtd_device(mymtd);
199 iounmap((void *)l440gx_map.map_priv_1);
202 module_init(init_l440gx);
203 module_exit(cleanup_l440gx);
205 MODULE_LICENSE("GPL");
206 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
207 MODULE_DESCRIPTION("MTD map driver for BIOS chips on Intel L440GX motherboards");