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#include <linux/module.h>
28#include <linux/string.h>
29#include <linux/types.h>
30#include <linux/kernel.h>
31#include <linux/init.h>
32#include <linux/dio.h>
33#include <linux/slab.h>
34#include <asm/uaccess.h>
35#include <asm/io.h>
36
37struct dio_bus dio_bus = {
38 .resources = {
39
40 { .name = "DIO mem", .start = 0x00600000, .end = 0x007fffff },
41
42 { .name = "DIO-II mem", .start = 0x01000000, .end = 0x1fffffff }
43 },
44 .name = "DIO bus"
45};
46
47
48#define CONFIG_DIO_CONSTANTS
49
50#ifdef CONFIG_DIO_CONSTANTS
51
52
53
54
55
56
57
58
59struct dioname
60{
61 int id;
62 const char *name;
63};
64
65
66#define DIONAME(x) { DIO_ID_##x, DIO_DESC_##x }
67#define DIOFBNAME(x) { DIO_ENCODE_ID( DIO_ID_FBUFFER, DIO_ID2_##x), DIO_DESC2_##x }
68
69static struct dioname names[] =
70{
71 DIONAME(DCA0), DIONAME(DCA0REM), DIONAME(DCA1), DIONAME(DCA1REM),
72 DIONAME(DCM), DIONAME(DCMREM),
73 DIONAME(LAN),
74 DIONAME(FHPIB), DIONAME(NHPIB),
75 DIONAME(SCSI0), DIONAME(SCSI1), DIONAME(SCSI2), DIONAME(SCSI3),
76 DIONAME(FBUFFER),
77 DIONAME(PARALLEL), DIONAME(VME), DIONAME(DCL), DIONAME(DCLREM),
78 DIONAME(MISC0), DIONAME(MISC1), DIONAME(MISC2), DIONAME(MISC3),
79 DIONAME(MISC4), DIONAME(MISC5), DIONAME(MISC6), DIONAME(MISC7),
80 DIONAME(MISC8), DIONAME(MISC9), DIONAME(MISC10), DIONAME(MISC11),
81 DIONAME(MISC12), DIONAME(MISC13),
82 DIOFBNAME(GATORBOX), DIOFBNAME(TOPCAT), DIOFBNAME(RENAISSANCE),
83 DIOFBNAME(LRCATSEYE), DIOFBNAME(HRCCATSEYE), DIOFBNAME(HRMCATSEYE),
84 DIOFBNAME(DAVINCI), DIOFBNAME(XXXCATSEYE), DIOFBNAME(HYPERION),
85 DIOFBNAME(XGENESIS), DIOFBNAME(TIGER), DIOFBNAME(YGENESIS)
86};
87
88#undef DIONAME
89#undef DIOFBNAME
90
91static const char *unknowndioname
92 = "unknown DIO board -- please email <linux-m68k@lists.linux-m68k.org>!";
93
94static const char *dio_getname(int id)
95{
96
97 unsigned int i;
98 for (i = 0; i < ARRAY_SIZE(names); i++)
99 if (names[i].id == id)
100 return names[i].name;
101
102 return unknowndioname;
103}
104
105#else
106
107static char dio_no_name[] = { 0 };
108#define dio_getname(_id) (dio_no_name)
109
110#endif
111
112int __init dio_find(int deviceid)
113{
114
115
116
117 int scode, id;
118 u_char prid, secid, i;
119 mm_segment_t fs;
120
121 for (scode = 0; scode < DIO_SCMAX; scode++) {
122 void *va;
123 unsigned long pa;
124
125 if (DIO_SCINHOLE(scode))
126 continue;
127
128 pa = dio_scodetophysaddr(scode);
129
130 if (!pa)
131 continue;
132
133 if (scode < DIOII_SCBASE)
134 va = (void *)(pa + DIO_VIRADDRBASE);
135 else
136 va = ioremap(pa, PAGE_SIZE);
137
138 fs = get_fs();
139 set_fs(KERNEL_DS);
140
141 if (get_user(i, (unsigned char *)va + DIO_IDOFF)) {
142 set_fs(fs);
143 if (scode >= DIOII_SCBASE)
144 iounmap(va);
145 continue;
146 }
147
148 set_fs(fs);
149 prid = DIO_ID(va);
150
151 if (DIO_NEEDSSECID(prid)) {
152 secid = DIO_SECID(va);
153 id = DIO_ENCODE_ID(prid, secid);
154 } else
155 id = prid;
156
157 if (id == deviceid) {
158 if (scode >= DIOII_SCBASE)
159 iounmap(va);
160 return scode;
161 }
162 }
163
164 return -1;
165}
166
167
168
169
170static int __init dio_init(void)
171{
172 int scode;
173 mm_segment_t fs;
174 int i;
175 struct dio_dev *dev;
176 int error;
177
178 if (!MACH_IS_HP300)
179 return 0;
180
181 printk(KERN_INFO "Scanning for DIO devices...\n");
182
183
184 INIT_LIST_HEAD(&dio_bus.devices);
185 dev_set_name(&dio_bus.dev, "dio");
186 error = device_register(&dio_bus.dev);
187 if (error) {
188 pr_err("DIO: Error registering dio_bus\n");
189 return error;
190 }
191
192
193 dio_bus.num_resources = (hp300_model == HP_320 ? 1 : 2);
194 for (i = 0; i < dio_bus.num_resources; i++)
195 request_resource(&iomem_resource, &dio_bus.resources[i]);
196
197
198 for (scode = 0; scode < DIO_SCMAX; ++scode)
199 {
200 u_char prid, secid = 0;
201 u_char *va;
202 unsigned long pa;
203
204 if (DIO_SCINHOLE(scode))
205 continue;
206
207 pa = dio_scodetophysaddr(scode);
208
209 if (!pa)
210 continue;
211
212 if (scode < DIOII_SCBASE)
213 va = (void *)(pa + DIO_VIRADDRBASE);
214 else
215 va = ioremap(pa, PAGE_SIZE);
216
217 fs = get_fs();
218 set_fs(KERNEL_DS);
219
220 if (get_user(i, (unsigned char *)va + DIO_IDOFF)) {
221 set_fs(fs);
222 if (scode >= DIOII_SCBASE)
223 iounmap(va);
224 continue;
225 }
226
227 set_fs(fs);
228
229
230 dev = kzalloc(sizeof(struct dio_dev), GFP_KERNEL);
231 if (!dev)
232 return 0;
233
234 dev->bus = &dio_bus;
235 dev->dev.parent = &dio_bus.dev;
236 dev->dev.bus = &dio_bus_type;
237 dev->scode = scode;
238 dev->resource.start = pa;
239 dev->resource.end = pa + DIO_SIZE(scode, va);
240 dev_set_name(&dev->dev, "%02x", scode);
241
242
243 prid = DIO_ID(va);
244
245 if (DIO_NEEDSSECID(prid)) {
246 secid = DIO_SECID(va);
247 dev->id = DIO_ENCODE_ID(prid, secid);
248 } else
249 dev->id = prid;
250
251 dev->ipl = DIO_IPL(va);
252 strcpy(dev->name,dio_getname(dev->id));
253 printk(KERN_INFO "select code %3d: ipl %d: ID %02X", dev->scode, dev->ipl, prid);
254 if (DIO_NEEDSSECID(prid))
255 printk(":%02X", secid);
256 printk(": %s\n", dev->name);
257
258 if (scode >= DIOII_SCBASE)
259 iounmap(va);
260 error = device_register(&dev->dev);
261 if (error) {
262 pr_err("DIO: Error registering device %s\n",
263 dev->name);
264 continue;
265 }
266 error = dio_create_sysfs_dev_files(dev);
267 if (error)
268 dev_err(&dev->dev, "Error creating sysfs files\n");
269 }
270 return 0;
271}
272
273subsys_initcall(dio_init);
274
275
276
277
278unsigned long dio_scodetophysaddr(int scode)
279{
280 if (scode >= DIOII_SCBASE) {
281 return (DIOII_BASE + (scode - 132) * DIOII_DEVSIZE);
282 } else if (scode > DIO_SCMAX || scode < 0)
283 return 0;
284 else if (DIO_SCINHOLE(scode))
285 return 0;
286
287 return (DIO_BASE + scode * DIO_DEVSIZE);
288}
289