1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47#include <linux/module.h>
48#include <linux/types.h>
49#include <linux/kernel.h>
50#include <linux/init.h>
51#include <asm/io.h>
52#include <linux/mtd/mtd.h>
53#include <linux/mtd/map.h>
54#include <linux/mtd/cfi.h>
55#include <linux/pci.h>
56#include <linux/pci_ids.h>
57
58#define MODNAME "scb2_flash"
59#define SCB2_ADDR 0xfff00000
60#define SCB2_WINDOW 0x00100000
61
62
63static void __iomem *scb2_ioaddr;
64static struct mtd_info *scb2_mtd;
65static struct map_info scb2_map = {
66 .name = "SCB2 BIOS Flash",
67 .size = 0,
68 .bankwidth = 1,
69};
70static int region_fail;
71
72static int __devinit
73scb2_fixup_mtd(struct mtd_info *mtd)
74{
75 int i;
76 int done = 0;
77 struct map_info *map = mtd->priv;
78 struct cfi_private *cfi = map->fldrv_priv;
79
80
81 if (cfi->cfiq->InterfaceDesc != CFI_INTERFACE_X16_ASYNC) {
82 printk(KERN_ERR MODNAME ": unsupported InterfaceDesc: %#x\n",
83 cfi->cfiq->InterfaceDesc);
84 return -1;
85 }
86
87
88
89
90 mtd->size = map->size;
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105 mtd->erasesize /= 2;
106 for (i = 0; i < mtd->numeraseregions; i++) {
107 struct mtd_erase_region_info *region = &mtd->eraseregions[i];
108 region->erasesize /= 2;
109 }
110
111
112
113
114
115
116
117 for (i = 0; !done && i < mtd->numeraseregions; i++) {
118 struct mtd_erase_region_info *region = &mtd->eraseregions[i];
119
120 if (region->numblocks * region->erasesize > mtd->size) {
121 region->numblocks = ((unsigned long)mtd->size /
122 region->erasesize);
123 done = 1;
124 } else {
125 region->numblocks = 0;
126 }
127 region->offset = 0;
128 }
129
130 return 0;
131}
132
133
134#define CSB5_FCR 0x41
135#define CSB5_FCR_DECODE_ALL 0x0e
136static int __devinit
137scb2_flash_probe(struct pci_dev *dev, const struct pci_device_id *ent)
138{
139 u8 reg;
140
141
142 pci_read_config_byte(dev, CSB5_FCR, ®);
143 pci_write_config_byte(dev, CSB5_FCR, reg | CSB5_FCR_DECODE_ALL);
144
145 if (!request_mem_region(SCB2_ADDR, SCB2_WINDOW, scb2_map.name)) {
146
147
148
149
150 printk(KERN_WARNING MODNAME
151 ": warning - can't reserve rom window, continuing\n");
152 region_fail = 1;
153 }
154
155
156 scb2_ioaddr = ioremap_nocache(SCB2_ADDR, SCB2_WINDOW);
157 if (!scb2_ioaddr) {
158 printk(KERN_ERR MODNAME ": Failed to ioremap window!\n");
159 if (!region_fail)
160 release_mem_region(SCB2_ADDR, SCB2_WINDOW);
161 return -ENOMEM;
162 }
163
164 scb2_map.phys = SCB2_ADDR;
165 scb2_map.virt = scb2_ioaddr;
166 scb2_map.size = SCB2_WINDOW;
167
168 simple_map_init(&scb2_map);
169
170
171 scb2_mtd = do_map_probe("cfi_probe", &scb2_map);
172
173 if (!scb2_mtd) {
174 printk(KERN_ERR MODNAME ": flash probe failed!\n");
175 iounmap(scb2_ioaddr);
176 if (!region_fail)
177 release_mem_region(SCB2_ADDR, SCB2_WINDOW);
178 return -ENODEV;
179 }
180
181 scb2_mtd->owner = THIS_MODULE;
182 if (scb2_fixup_mtd(scb2_mtd) < 0) {
183 del_mtd_device(scb2_mtd);
184 map_destroy(scb2_mtd);
185 iounmap(scb2_ioaddr);
186 if (!region_fail)
187 release_mem_region(SCB2_ADDR, SCB2_WINDOW);
188 return -ENODEV;
189 }
190
191 printk(KERN_NOTICE MODNAME ": chip size 0x%llx at offset 0x%llx\n",
192 (unsigned long long)scb2_mtd->size,
193 (unsigned long long)(SCB2_WINDOW - scb2_mtd->size));
194
195 add_mtd_device(scb2_mtd);
196
197 return 0;
198}
199
200static void __devexit
201scb2_flash_remove(struct pci_dev *dev)
202{
203 if (!scb2_mtd)
204 return;
205
206
207 if (scb2_mtd->lock)
208 scb2_mtd->lock(scb2_mtd, 0, scb2_mtd->size);
209
210 del_mtd_device(scb2_mtd);
211 map_destroy(scb2_mtd);
212
213 iounmap(scb2_ioaddr);
214 scb2_ioaddr = NULL;
215
216 if (!region_fail)
217 release_mem_region(SCB2_ADDR, SCB2_WINDOW);
218 pci_set_drvdata(dev, NULL);
219}
220
221static struct pci_device_id scb2_flash_pci_ids[] = {
222 {
223 .vendor = PCI_VENDOR_ID_SERVERWORKS,
224 .device = PCI_DEVICE_ID_SERVERWORKS_CSB5,
225 .subvendor = PCI_ANY_ID,
226 .subdevice = PCI_ANY_ID
227 },
228 { 0, }
229};
230
231static struct pci_driver scb2_flash_driver = {
232 .name = "Intel SCB2 BIOS Flash",
233 .id_table = scb2_flash_pci_ids,
234 .probe = scb2_flash_probe,
235 .remove = __devexit_p(scb2_flash_remove),
236};
237
238static int __init
239scb2_flash_init(void)
240{
241 return pci_register_driver(&scb2_flash_driver);
242}
243
244static void __exit
245scb2_flash_exit(void)
246{
247 pci_unregister_driver(&scb2_flash_driver);
248}
249
250module_init(scb2_flash_init);
251module_exit(scb2_flash_exit);
252
253MODULE_LICENSE("GPL");
254MODULE_AUTHOR("Tim Hockin <thockin@sun.com>");
255MODULE_DESCRIPTION("MTD map driver for Intel SCB2 BIOS Flash");
256MODULE_DEVICE_TABLE(pci, scb2_flash_pci_ids);
257