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