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 <asm/io.h>
51#include <linux/mtd/mtd.h>
52#include <linux/mtd/map.h>
53#include <linux/mtd/cfi.h>
54#include <linux/pci.h>
55#include <linux/pci_ids.h>
56
57#define MODNAME "scb2_flash"
58#define SCB2_ADDR 0xfff00000
59#define SCB2_WINDOW 0x00100000
60
61
62static void __iomem *scb2_ioaddr;
63static struct mtd_info *scb2_mtd;
64static struct map_info scb2_map = {
65 .name = "SCB2 BIOS Flash",
66 .size = 0,
67 .bankwidth = 1,
68};
69static int region_fail;
70
71static int scb2_fixup_mtd(struct mtd_info *mtd)
72{
73 int i;
74 int done = 0;
75 struct map_info *map = mtd->priv;
76 struct cfi_private *cfi = map->fldrv_priv;
77
78
79 if (cfi->cfiq->InterfaceDesc != CFI_INTERFACE_X16_ASYNC) {
80 printk(KERN_ERR MODNAME ": unsupported InterfaceDesc: %#x\n",
81 cfi->cfiq->InterfaceDesc);
82 return -1;
83 }
84
85
86
87
88 mtd->size = map->size;
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103 mtd->erasesize /= 2;
104 for (i = 0; i < mtd->numeraseregions; i++) {
105 struct mtd_erase_region_info *region = &mtd->eraseregions[i];
106 region->erasesize /= 2;
107 }
108
109
110
111
112
113
114
115 for (i = 0; !done && i < mtd->numeraseregions; i++) {
116 struct mtd_erase_region_info *region = &mtd->eraseregions[i];
117
118 if (region->numblocks * region->erasesize > mtd->size) {
119 region->numblocks = ((unsigned long)mtd->size /
120 region->erasesize);
121 done = 1;
122 } else {
123 region->numblocks = 0;
124 }
125 region->offset = 0;
126 }
127
128 return 0;
129}
130
131
132#define CSB5_FCR 0x41
133#define CSB5_FCR_DECODE_ALL 0x0e
134static int scb2_flash_probe(struct pci_dev *dev,
135 const struct pci_device_id *ent)
136{
137 u8 reg;
138
139
140 pci_read_config_byte(dev, CSB5_FCR, ®);
141 pci_write_config_byte(dev, CSB5_FCR, reg | CSB5_FCR_DECODE_ALL);
142
143 if (!request_mem_region(SCB2_ADDR, SCB2_WINDOW, scb2_map.name)) {
144
145
146
147
148 printk(KERN_WARNING MODNAME
149 ": warning - can't reserve rom window, continuing\n");
150 region_fail = 1;
151 }
152
153
154 scb2_ioaddr = ioremap_nocache(SCB2_ADDR, SCB2_WINDOW);
155 if (!scb2_ioaddr) {
156 printk(KERN_ERR MODNAME ": Failed to ioremap window!\n");
157 if (!region_fail)
158 release_mem_region(SCB2_ADDR, SCB2_WINDOW);
159 return -ENOMEM;
160 }
161
162 scb2_map.phys = SCB2_ADDR;
163 scb2_map.virt = scb2_ioaddr;
164 scb2_map.size = SCB2_WINDOW;
165
166 simple_map_init(&scb2_map);
167
168
169 scb2_mtd = do_map_probe("cfi_probe", &scb2_map);
170
171 if (!scb2_mtd) {
172 printk(KERN_ERR MODNAME ": flash probe failed!\n");
173 iounmap(scb2_ioaddr);
174 if (!region_fail)
175 release_mem_region(SCB2_ADDR, SCB2_WINDOW);
176 return -ENODEV;
177 }
178
179 scb2_mtd->owner = THIS_MODULE;
180 if (scb2_fixup_mtd(scb2_mtd) < 0) {
181 mtd_device_unregister(scb2_mtd);
182 map_destroy(scb2_mtd);
183 iounmap(scb2_ioaddr);
184 if (!region_fail)
185 release_mem_region(SCB2_ADDR, SCB2_WINDOW);
186 return -ENODEV;
187 }
188
189 printk(KERN_NOTICE MODNAME ": chip size 0x%llx at offset 0x%llx\n",
190 (unsigned long long)scb2_mtd->size,
191 (unsigned long long)(SCB2_WINDOW - scb2_mtd->size));
192
193 mtd_device_register(scb2_mtd, NULL, 0);
194
195 return 0;
196}
197
198static void scb2_flash_remove(struct pci_dev *dev)
199{
200 if (!scb2_mtd)
201 return;
202
203
204 mtd_lock(scb2_mtd, 0, scb2_mtd->size);
205
206 mtd_device_unregister(scb2_mtd);
207 map_destroy(scb2_mtd);
208
209 iounmap(scb2_ioaddr);
210 scb2_ioaddr = NULL;
211
212 if (!region_fail)
213 release_mem_region(SCB2_ADDR, SCB2_WINDOW);
214}
215
216static struct pci_device_id scb2_flash_pci_ids[] = {
217 {
218 .vendor = PCI_VENDOR_ID_SERVERWORKS,
219 .device = PCI_DEVICE_ID_SERVERWORKS_CSB5,
220 .subvendor = PCI_ANY_ID,
221 .subdevice = PCI_ANY_ID
222 },
223 { 0, }
224};
225
226static struct pci_driver scb2_flash_driver = {
227 .name = "Intel SCB2 BIOS Flash",
228 .id_table = scb2_flash_pci_ids,
229 .probe = scb2_flash_probe,
230 .remove = scb2_flash_remove,
231};
232
233module_pci_driver(scb2_flash_driver);
234
235MODULE_LICENSE("GPL");
236MODULE_AUTHOR("Tim Hockin <thockin@sun.com>");
237MODULE_DESCRIPTION("MTD map driver for Intel SCB2 BIOS Flash");
238MODULE_DEVICE_TABLE(pci, scb2_flash_pci_ids);
239