more debug output
[linux-2.4.git] / drivers / mtd / maps / l440gx.c
1 /*
2  * $Id: l440gx.c,v 1.8 2002/01/10 20:27:40 eric Exp $
3  *
4  * BIOS Flash chip on Intel 440GX board.
5  *
6  * Bugs this currently does not work under linuxBIOS.
7  */
8
9 #include <linux/module.h>
10 #include <linux/pci.h>
11 #include <linux/kernel.h>
12 #include <asm/io.h>
13 #include <linux/mtd/mtd.h>
14 #include <linux/mtd/map.h>
15 #include <linux/config.h>
16
17 #define PIIXE_IOBASE_RESOURCE   11
18
19 #define WINDOW_ADDR 0xfff00000
20 #define WINDOW_SIZE 0x00100000
21 #define BUSWIDTH 1
22
23 static u32 iobase;
24 #define IOBASE iobase
25 #define TRIBUF_PORT (IOBASE+0x37)
26 #define VPP_PORT (IOBASE+0x28)
27
28 static struct mtd_info *mymtd;
29
30 __u8 l440gx_read8(struct map_info *map, unsigned long ofs)
31 {
32         return __raw_readb(map->map_priv_1 + ofs);
33 }
34
35 __u16 l440gx_read16(struct map_info *map, unsigned long ofs)
36 {
37         return __raw_readw(map->map_priv_1 + ofs);
38 }
39
40 __u32 l440gx_read32(struct map_info *map, unsigned long ofs)
41 {
42         return __raw_readl(map->map_priv_1 + ofs);
43 }
44
45 void l440gx_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
46 {
47         memcpy_fromio(to, map->map_priv_1 + from, len);
48 }
49
50 void l440gx_write8(struct map_info *map, __u8 d, unsigned long adr)
51 {
52         __raw_writeb(d, map->map_priv_1 + adr);
53         mb();
54 }
55
56 void l440gx_write16(struct map_info *map, __u16 d, unsigned long adr)
57 {
58         __raw_writew(d, map->map_priv_1 + adr);
59         mb();
60 }
61
62 void l440gx_write32(struct map_info *map, __u32 d, unsigned long adr)
63 {
64         __raw_writel(d, map->map_priv_1 + adr);
65         mb();
66 }
67
68 void l440gx_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
69 {
70         memcpy_toio(map->map_priv_1 + to, from, len);
71 }
72
73 /* Is this really the vpp port? */
74 void l440gx_set_vpp(struct map_info *map, int vpp)
75 {
76         unsigned long l;
77
78         l = inl(VPP_PORT);
79         if (vpp) {
80                 l |= 1;
81         } else {
82                 l &= ~1;
83         }
84         outl(l, VPP_PORT);
85 }
86
87 struct map_info l440gx_map = {
88         name: "L440GX BIOS",
89         size: WINDOW_SIZE,
90         buswidth: BUSWIDTH,
91         read8: l440gx_read8,
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,
99 #if 0
100         /* FIXME verify that this is the 
101          * appripriate code for vpp enable/disable
102          */
103         set_vpp: l440gx_set_vpp
104 #endif
105 };
106
107 static int __init init_l440gx(void)
108 {
109         struct pci_dev *dev, *pm_dev;
110         struct resource *pm_iobase;
111         __u16 word;
112
113         dev = pci_find_device(PCI_VENDOR_ID_INTEL, 
114                 PCI_DEVICE_ID_INTEL_82371AB_0, NULL);
115
116
117         pm_dev = pci_find_device(PCI_VENDOR_ID_INTEL, 
118                 PCI_DEVICE_ID_INTEL_82371AB_3, NULL);
119
120         if (!dev || !pm_dev) {
121                 printk(KERN_NOTICE "L440GX flash mapping: failed to find PIIX4 ISA bridge, cannot continue\n");
122                 return -ENODEV;
123         }
124
125
126         l440gx_map.map_priv_1 = (unsigned long)ioremap_nocache(WINDOW_ADDR, WINDOW_SIZE);
127
128         if (!l440gx_map.map_priv_1) {
129                 printk(KERN_WARNING "Failed to ioremap L440GX flash region\n");
130                 return -ENOMEM;
131         }
132
133         printk(KERN_NOTICE "window_addr = 0x%08lx\n", (unsigned long)l440gx_map.map_priv_1);
134
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. 
139          */
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;
144                 pm_iobase->end = 63;
145                 pm_iobase->flags = IORESOURCE_IO;
146
147                 /* Put the current value in the resource */
148                 pci_read_config_dword(pm_dev, 0x40, &iobase);
149                 iobase &= ~1;
150                 pm_iobase->start += iobase & ~1;
151                 pm_iobase->end += iobase & ~1;
152
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);
157                         return -ENXIO;
158                 }
159         }
160         /* Set the iobase */
161         iobase = pm_iobase->start;
162         pci_write_config_dword(pm_dev, 0x40, iobase | 1);
163         
164
165         /* Set XBCS# */
166         pci_read_config_word(dev, 0x4e, &word);
167         word |= 0x4;
168         pci_write_config_word(dev, 0x4e, word);
169
170         /* Supply write voltage to the chip */
171         l440gx_set_vpp(&l440gx_map, 1);
172
173         /* Enable the gate on the WE line */
174         outb(inb(TRIBUF_PORT) & ~1, TRIBUF_PORT);
175         
176         printk(KERN_NOTICE "Enabled WE line to L440GX BIOS flash chip.\n");
177
178         mymtd = do_map_probe("jedec_probe", &l440gx_map);
179         if (!mymtd) {
180                 printk(KERN_NOTICE "JEDEC probe on BIOS chip failed. Using ROM\n");
181                 mymtd = do_map_probe("map_rom", &l440gx_map);
182         }
183         if (mymtd) {
184                 mymtd->module = THIS_MODULE;
185
186                 add_mtd_device(mymtd);
187                 return 0;
188         }
189
190         iounmap((void *)l440gx_map.map_priv_1);
191         return -ENXIO;
192 }
193
194 static void __exit cleanup_l440gx(void)
195 {
196         del_mtd_device(mymtd);
197         map_destroy(mymtd);
198         
199         iounmap((void *)l440gx_map.map_priv_1);
200 }
201
202 module_init(init_l440gx);
203 module_exit(cleanup_l440gx);
204
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");