aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/dio
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/dio
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/dio')
-rw-r--r--drivers/dio/Makefile5
-rw-r--r--drivers/dio/dio-driver.c163
-rw-r--r--drivers/dio/dio-sysfs.c77
-rw-r--r--drivers/dio/dio.c279
4 files changed, 524 insertions, 0 deletions
diff --git a/drivers/dio/Makefile b/drivers/dio/Makefile
new file mode 100644
index 000000000000..ae92d17083f2
--- /dev/null
+++ b/drivers/dio/Makefile
@@ -0,0 +1,5 @@
1#
2# Makefile for the linux kernel.
3#
4
5obj-y := dio.o dio-driver.o dio-sysfs.o
diff --git a/drivers/dio/dio-driver.c b/drivers/dio/dio-driver.c
new file mode 100644
index 000000000000..ffe6f44ac76f
--- /dev/null
+++ b/drivers/dio/dio-driver.c
@@ -0,0 +1,163 @@
1/*
2 * DIO Driver Services
3 *
4 * Copyright (C) 2004 Jochen Friedrich
5 *
6 * Loosely based on drivers/pci/pci-driver.c and drivers/zorro/zorro-driver.c
7 *
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file COPYING in the main directory of this archive
10 * for more details.
11 */
12
13#include <linux/init.h>
14#include <linux/module.h>
15#include <linux/dio.h>
16
17
18 /**
19 * dio_match_device - Tell if a DIO device structure has a matching
20 * DIO device id structure
21 * @ids: array of DIO device id structures to search in
22 * @dev: the DIO device structure to match against
23 *
24 * Used by a driver to check whether a DIO device present in the
25 * system is in its list of supported devices. Returns the matching
26 * dio_device_id structure or %NULL if there is no match.
27 */
28
29const struct dio_device_id *
30dio_match_device(const struct dio_device_id *ids,
31 const struct dio_dev *d)
32{
33 while (ids->id) {
34 if (ids->id == DIO_WILDCARD)
35 return ids;
36 if (DIO_NEEDSSECID(ids->id & 0xff)) {
37 if (ids->id == d->id)
38 return ids;
39 } else {
40 if ((ids->id & 0xff) == (d->id & 0xff))
41 return ids;
42 }
43 ids++;
44 }
45 return NULL;
46}
47
48static int dio_device_probe(struct device *dev)
49{
50 int error = 0;
51 struct dio_driver *drv = to_dio_driver(dev->driver);
52 struct dio_dev *d = to_dio_dev(dev);
53
54 if (!d->driver && drv->probe) {
55 const struct dio_device_id *id;
56
57 id = dio_match_device(drv->id_table, d);
58 if (id)
59 error = drv->probe(d, id);
60 if (error >= 0) {
61 d->driver = drv;
62 error = 0;
63 }
64 }
65 return error;
66}
67
68
69 /**
70 * dio_register_driver - register a new DIO driver
71 * @drv: the driver structure to register
72 *
73 * Adds the driver structure to the list of registered drivers
74 * Returns the number of DIO devices which were claimed by the driver
75 * during registration. The driver remains registered even if the
76 * return value is zero.
77 */
78
79int dio_register_driver(struct dio_driver *drv)
80{
81 int count = 0;
82
83 /* initialize common driver fields */
84 drv->driver.name = drv->name;
85 drv->driver.bus = &dio_bus_type;
86 drv->driver.probe = dio_device_probe;
87
88 /* register with core */
89 count = driver_register(&drv->driver);
90 return count ? count : 1;
91}
92
93
94 /**
95 * dio_unregister_driver - unregister a DIO driver
96 * @drv: the driver structure to unregister
97 *
98 * Deletes the driver structure from the list of registered DIO drivers,
99 * gives it a chance to clean up by calling its remove() function for
100 * each device it was responsible for, and marks those devices as
101 * driverless.
102 */
103
104void dio_unregister_driver(struct dio_driver *drv)
105{
106 driver_unregister(&drv->driver);
107}
108
109
110 /**
111 * dio_bus_match - Tell if a DIO device structure has a matching DIO
112 * device id structure
113 * @ids: array of DIO device id structures to search in
114 * @dev: the DIO device structure to match against
115 *
116 * Used by a driver to check whether a DIO device present in the
117 * system is in its list of supported devices. Returns the matching
118 * dio_device_id structure or %NULL if there is no match.
119 */
120
121static int dio_bus_match(struct device *dev, struct device_driver *drv)
122{
123 struct dio_dev *d = to_dio_dev(dev);
124 struct dio_driver *dio_drv = to_dio_driver(drv);
125 const struct dio_device_id *ids = dio_drv->id_table;
126
127 if (!ids)
128 return 0;
129
130 while (ids->id) {
131 if (ids->id == DIO_WILDCARD)
132 return 1;
133 if (DIO_NEEDSSECID(ids->id & 0xff)) {
134 if (ids->id == d->id)
135 return 1;
136 } else {
137 if ((ids->id & 0xff) == (d->id & 0xff))
138 return 1;
139 }
140 ids++;
141 }
142 return 0;
143}
144
145
146struct bus_type dio_bus_type = {
147 .name = "dio",
148 .match = dio_bus_match
149};
150
151
152static int __init dio_driver_init(void)
153{
154 return bus_register(&dio_bus_type);
155}
156
157postcore_initcall(dio_driver_init);
158
159EXPORT_SYMBOL(dio_match_device);
160EXPORT_SYMBOL(dio_register_driver);
161EXPORT_SYMBOL(dio_unregister_driver);
162EXPORT_SYMBOL(dio_dev_driver);
163EXPORT_SYMBOL(dio_bus_type);
diff --git a/drivers/dio/dio-sysfs.c b/drivers/dio/dio-sysfs.c
new file mode 100644
index 000000000000..d30591f69dd9
--- /dev/null
+++ b/drivers/dio/dio-sysfs.c
@@ -0,0 +1,77 @@
1/*
2 * File Attributes for DIO Devices
3 *
4 * Copyright (C) 2004 Jochen Friedrich
5 *
6 * Loosely based on drivers/pci/pci-sysfs.c and drivers/zorro/zorro-sysfs.c
7 *
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file COPYING in the main directory of this archive
10 * for more details.
11 */
12
13
14#include <linux/kernel.h>
15#include <linux/dio.h>
16#include <linux/stat.h>
17
18/* show configuration fields */
19
20static ssize_t dio_show_id(struct device *dev, char *buf)
21{
22 struct dio_dev *d;
23
24 d = to_dio_dev(dev);
25 return sprintf(buf, "0x%02x\n", (d->id & 0xff));
26}
27static DEVICE_ATTR(id, S_IRUGO, dio_show_id, NULL);
28
29static ssize_t dio_show_ipl(struct device *dev, char *buf)
30{
31 struct dio_dev *d;
32
33 d = to_dio_dev(dev);
34 return sprintf(buf, "0x%02x\n", d->ipl);
35}
36static DEVICE_ATTR(ipl, S_IRUGO, dio_show_ipl, NULL);
37
38static ssize_t dio_show_secid(struct device *dev, char *buf)
39{
40 struct dio_dev *d;
41
42 d = to_dio_dev(dev);
43 return sprintf(buf, "0x%02x\n", ((d->id >> 8)& 0xff));
44}
45static DEVICE_ATTR(secid, S_IRUGO, dio_show_secid, NULL);
46
47static ssize_t dio_show_name(struct device *dev, char *buf)
48{
49 struct dio_dev *d;
50
51 d = to_dio_dev(dev);
52 return sprintf(buf, "%s\n", d->name);
53}
54static DEVICE_ATTR(name, S_IRUGO, dio_show_name, NULL);
55
56static ssize_t dio_show_resource(struct device *dev, char *buf)
57{
58 struct dio_dev *d = to_dio_dev(dev);
59
60 return sprintf(buf, "0x%08lx 0x%08lx 0x%08lx\n",
61 dio_resource_start(d), dio_resource_end(d),
62 dio_resource_flags(d));
63}
64static DEVICE_ATTR(resource, S_IRUGO, dio_show_resource, NULL);
65
66void dio_create_sysfs_dev_files(struct dio_dev *d)
67{
68 struct device *dev = &d->dev;
69
70 /* current configuration's attributes */
71 device_create_file(dev, &dev_attr_id);
72 device_create_file(dev, &dev_attr_ipl);
73 device_create_file(dev, &dev_attr_secid);
74 device_create_file(dev, &dev_attr_name);
75 device_create_file(dev, &dev_attr_resource);
76}
77
diff --git a/drivers/dio/dio.c b/drivers/dio/dio.c
new file mode 100644
index 000000000000..a620f7d9ac8e
--- /dev/null
+++ b/drivers/dio/dio.c
@@ -0,0 +1,279 @@
1/* 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
91#define NUMNAMES (sizeof(names) / sizeof(struct dioname))
92
93static const char *unknowndioname
94 = "unknown DIO board -- please email <linux-m68k@lists.linux-m68k.org>!";
95
96static const char *dio_getname(int id)
97{
98 /* return pointer to a constant string describing the board with given ID */
99 unsigned int i;
100 for (i = 0; i < NUMNAMES; i++)
101 if (names[i].id == id)
102 return names[i].name;
103
104 return unknowndioname;
105}
106
107#else
108
109static char dio_no_name[] = { 0 };
110#define dio_getname(_id) (dio_no_name)
111
112#endif /* CONFIG_DIO_CONSTANTS */
113
114int __init dio_find(int deviceid)
115{
116 /* Called to find a DIO device before the full bus scan has run.
117 * Only used by the console driver.
118 */
119 int scode, id;
120 u_char prid, secid, i;
121 mm_segment_t fs;
122
123 for (scode = 0; scode < DIO_SCMAX; scode++) {
124 void *va;
125 unsigned long pa;
126
127 if (DIO_SCINHOLE(scode))
128 continue;
129
130 pa = dio_scodetophysaddr(scode);
131
132 if (!pa)
133 continue;
134
135 if (scode < DIOII_SCBASE)
136 va = (void *)(pa + DIO_VIRADDRBASE);
137 else
138 va = ioremap(pa, PAGE_SIZE);
139
140 fs = get_fs();
141 set_fs(KERNEL_DS);
142
143 if (get_user(i, (unsigned char *)va + DIO_IDOFF)) {
144 set_fs(fs);
145 if (scode >= DIOII_SCBASE)
146 iounmap(va);
147 continue; /* no board present at that select code */
148 }
149
150 set_fs(fs);
151 prid = DIO_ID(va);
152
153 if (DIO_NEEDSSECID(prid)) {
154 secid = DIO_SECID(va);
155 id = DIO_ENCODE_ID(prid, secid);
156 } else
157 id = prid;
158
159 if (id == deviceid) {
160 if (scode >= DIOII_SCBASE)
161 iounmap(va);
162 return scode;
163 }
164 }
165
166 return -1;
167}
168
169/* This is the function that scans the DIO space and works out what
170 * hardware is actually present.
171 */
172static int __init dio_init(void)
173{
174 int scode;
175 mm_segment_t fs;
176 int i;
177 struct dio_dev *dev;
178
179 if (!MACH_IS_HP300)
180 return 0;
181
182 printk(KERN_INFO "Scanning for DIO devices...\n");
183
184 /* Initialize the DIO bus */
185 INIT_LIST_HEAD(&dio_bus.devices);
186 strcpy(dio_bus.dev.bus_id, "dio");
187 device_register(&dio_bus.dev);
188
189 /* Request all resources */
190 dio_bus.num_resources = (hp300_model == HP_320 ? 1 : 2);
191 for (i = 0; i < dio_bus.num_resources; i++)
192 request_resource(&iomem_resource, &dio_bus.resources[i]);
193
194 /* Register all devices */
195 for (scode = 0; scode < DIO_SCMAX; ++scode)
196 {
197 u_char prid, secid = 0; /* primary, secondary ID bytes */
198 u_char *va;
199 unsigned long pa;
200
201 if (DIO_SCINHOLE(scode))
202 continue;
203
204 pa = dio_scodetophysaddr(scode);
205
206 if (!pa)
207 continue;
208
209 if (scode < DIOII_SCBASE)
210 va = (void *)(pa + DIO_VIRADDRBASE);
211 else
212 va = ioremap(pa, PAGE_SIZE);
213
214 fs = get_fs();
215 set_fs(KERNEL_DS);
216
217 if (get_user(i, (unsigned char *)va + DIO_IDOFF)) {
218 set_fs(fs);
219 if (scode >= DIOII_SCBASE)
220 iounmap(va);
221 continue; /* no board present at that select code */
222 }
223
224 set_fs(fs);
225
226 /* Found a board, allocate it an entry in the list */
227 dev = kmalloc(sizeof(struct dio_dev), GFP_KERNEL);
228 if (!dev)
229 return 0;
230
231 memset(dev, 0, sizeof(struct dio_dev));
232 dev->bus = &dio_bus;
233 dev->dev.parent = &dio_bus.dev;
234 dev->dev.bus = &dio_bus_type;
235 dev->scode = scode;
236 dev->resource.start = pa;
237 dev->resource.end = pa + DIO_SIZE(scode, va);
238 sprintf(dev->dev.bus_id,"%02x", scode);
239
240 /* read the ID byte(s) and encode if necessary. */
241 prid = DIO_ID(va);
242
243 if (DIO_NEEDSSECID(prid)) {
244 secid = DIO_SECID(va);
245 dev->id = DIO_ENCODE_ID(prid, secid);
246 } else
247 dev->id = prid;
248
249 dev->ipl = DIO_IPL(va);
250 strcpy(dev->name,dio_getname(dev->id));
251 printk(KERN_INFO "select code %3d: ipl %d: ID %02X", dev->scode, dev->ipl, prid);
252 if (DIO_NEEDSSECID(prid))
253 printk(":%02X", secid);
254 printk(": %s\n", dev->name);
255
256 if (scode >= DIOII_SCBASE)
257 iounmap(va);
258 device_register(&dev->dev);
259 dio_create_sysfs_dev_files(dev);
260 }
261 return 0;
262}
263
264subsys_initcall(dio_init);
265
266/* Bear in mind that this is called in the very early stages of initialisation
267 * in order to get the address of the serial port for the console...
268 */
269unsigned long dio_scodetophysaddr(int scode)
270{
271 if (scode >= DIOII_SCBASE) {
272 return (DIOII_BASE + (scode - 132) * DIOII_DEVSIZE);
273 } else if (scode > DIO_SCMAX || scode < 0)
274 return 0;
275 else if (DIO_SCINHOLE(scode))
276 return 0;
277
278 return (DIO_BASE + scode * DIO_DEVSIZE);
279}