blob: 07f274f853d95f5dc0cf8b671e989fca3a65742f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* Code to support devices on the DIO and DIO-II bus
2 * Copyright (C) 05/1998 Peter Maydell <pmaydell@chiark.greenend.org.uk>
3 * Copyright (C) 2004 Jochen Friedrich <jochen@scram.de>
4 *
5 * This code has basically these routines at the moment:
6 * int dio_find(u_int deviceid)
7 * Search the list of DIO devices and return the select code
8 * of the next unconfigured device found that matches the given device ID.
9 * Note that the deviceid parameter should be the encoded ID.
10 * This means that framebuffers should pass it as
11 * DIO_ENCODE_ID(DIO_ID_FBUFFER,DIO_ID2_TOPCAT)
12 * (or whatever); everybody else just uses DIO_ID_FOOBAR.
13 * unsigned long dio_scodetophysaddr(int scode)
14 * Return the physical address corresponding to the given select code.
15 * int dio_scodetoipl(int scode)
16 * Every DIO card has a fixed interrupt priority level. This function
17 * returns it, whatever it is.
18 * const char *dio_scodetoname(int scode)
19 * Return a character string describing this board [might be "" if
20 * not CONFIG_DIO_CONSTANTS]
21 * void dio_config_board(int scode) mark board as configured in the list
22 * void dio_unconfig_board(int scode) mark board as no longer configured
23 *
24 * This file is based on the way the Amiga port handles Zorro II cards,
25 * although we aren't so complicated...
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> /* kmalloc() */
34#include <asm/uaccess.h>
35#include <asm/io.h> /* readb() */
36
37struct dio_bus dio_bus = {
38 .resources = {
39 /* DIO range */
40 { .name = "DIO mem", .start = 0x00600000, .end = 0x007fffff },
41 /* DIO-II range */
42 { .name = "DIO-II mem", .start = 0x01000000, .end = 0x1fffffff }
43 },
44 .name = "DIO bus"
45};
46
47/* not a real config option yet! */
48#define CONFIG_DIO_CONSTANTS
49
50#ifdef CONFIG_DIO_CONSTANTS
51/* We associate each numeric ID with an appropriate descriptive string
52 * using a constant array of these structs.
53 * FIXME: we should be able to arrange to throw away most of the strings
54 * using the initdata stuff. Then we wouldn't need to worry about
55 * carrying them around...
56 * I think we do this by copying them into newly kmalloc()ed memory and
57 * marking the names[] array as .initdata ?
58 */
59struct dioname
60{
61 int id;
62 const char *name;
63};
64
65/* useful macro */
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070091static 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 /* return pointer to a constant string describing the board with given ID */
97 unsigned int i;
Alejandro Martinez Ruiz0a8320b2008-02-04 22:30:19 -080098 for (i = 0; i < ARRAY_SIZE(names); i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 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 /* CONFIG_DIO_CONSTANTS */
111
112int __init dio_find(int deviceid)
113{
114 /* Called to find a DIO device before the full bus scan has run.
115 * Only used by the console driver.
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; /* no board present at that select code */
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/* This is the function that scans the DIO space and works out what
168 * hardware is actually present.
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
177 if (!MACH_IS_HP300)
178 return 0;
179
180 printk(KERN_INFO "Scanning for DIO devices...\n");
181
182 /* Initialize the DIO bus */
183 INIT_LIST_HEAD(&dio_bus.devices);
184 strcpy(dio_bus.dev.bus_id, "dio");
185 device_register(&dio_bus.dev);
186
187 /* Request all resources */
188 dio_bus.num_resources = (hp300_model == HP_320 ? 1 : 2);
189 for (i = 0; i < dio_bus.num_resources; i++)
190 request_resource(&iomem_resource, &dio_bus.resources[i]);
191
192 /* Register all devices */
193 for (scode = 0; scode < DIO_SCMAX; ++scode)
194 {
195 u_char prid, secid = 0; /* primary, secondary ID bytes */
196 u_char *va;
197 unsigned long pa;
198
199 if (DIO_SCINHOLE(scode))
200 continue;
201
202 pa = dio_scodetophysaddr(scode);
203
204 if (!pa)
205 continue;
206
207 if (scode < DIOII_SCBASE)
208 va = (void *)(pa + DIO_VIRADDRBASE);
209 else
210 va = ioremap(pa, PAGE_SIZE);
211
212 fs = get_fs();
213 set_fs(KERNEL_DS);
214
215 if (get_user(i, (unsigned char *)va + DIO_IDOFF)) {
216 set_fs(fs);
217 if (scode >= DIOII_SCBASE)
218 iounmap(va);
219 continue; /* no board present at that select code */
220 }
221
222 set_fs(fs);
223
224 /* Found a board, allocate it an entry in the list */
Deepak Saxenae66860c2005-11-07 01:01:22 -0800225 dev = kzalloc(sizeof(struct dio_dev), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 if (!dev)
227 return 0;
228
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 dev->bus = &dio_bus;
230 dev->dev.parent = &dio_bus.dev;
231 dev->dev.bus = &dio_bus_type;
232 dev->scode = scode;
233 dev->resource.start = pa;
234 dev->resource.end = pa + DIO_SIZE(scode, va);
235 sprintf(dev->dev.bus_id,"%02x", scode);
236
237 /* read the ID byte(s) and encode if necessary. */
238 prid = DIO_ID(va);
239
240 if (DIO_NEEDSSECID(prid)) {
241 secid = DIO_SECID(va);
242 dev->id = DIO_ENCODE_ID(prid, secid);
243 } else
244 dev->id = prid;
245
246 dev->ipl = DIO_IPL(va);
247 strcpy(dev->name,dio_getname(dev->id));
248 printk(KERN_INFO "select code %3d: ipl %d: ID %02X", dev->scode, dev->ipl, prid);
249 if (DIO_NEEDSSECID(prid))
250 printk(":%02X", secid);
251 printk(": %s\n", dev->name);
252
253 if (scode >= DIOII_SCBASE)
254 iounmap(va);
255 device_register(&dev->dev);
256 dio_create_sysfs_dev_files(dev);
257 }
258 return 0;
259}
260
261subsys_initcall(dio_init);
262
263/* Bear in mind that this is called in the very early stages of initialisation
264 * in order to get the address of the serial port for the console...
265 */
266unsigned 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}