Deleted Added
full compact
pcii.c (166914) pcii.c (202870)
1/*-
2 * Copyright (c) 2005 Poul-Henning Kamp <phk@FreeBSD.org>
1/*-
2 * Copyright (c) 2005 Poul-Henning Kamp <phk@FreeBSD.org>
3 * Copyright (c) 2010 Joerg Wunsch <joerg@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright

--- 17 unchanged lines hidden (view full) ---

28 * This driver just hooks up to the hardware and leaves all the interesting
29 * stuff to upd7210.c.
30 *
31 * Supported hardware:
32 * PCIIA compatible cards.
33 *
34 * Tested and known working:
35 * "B&C Microsystems PC488A-0"
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright

--- 17 unchanged lines hidden (view full) ---

29 * This driver just hooks up to the hardware and leaves all the interesting
30 * stuff to upd7210.c.
31 *
32 * Supported hardware:
33 * PCIIA compatible cards.
34 *
35 * Tested and known working:
36 * "B&C Microsystems PC488A-0"
37 * "National Instruments GPIB-PCII/PCIIA" (in PCIIa mode)
38 * "Axiom AX5488"
36 *
37 */
38
39#include <sys/cdefs.h>
39 *
40 */
41
42#include <sys/cdefs.h>
40__FBSDID("$FreeBSD: head/sys/dev/ieee488/pcii.c 166914 2007-02-23 19:34:52Z imp $");
43__FBSDID("$FreeBSD: head/sys/dev/ieee488/pcii.c 202870 2010-01-23 07:54:06Z joerg $");
41
42#include <sys/param.h>
43#include <sys/systm.h>
44#include <sys/lock.h>
45#include <sys/mutex.h>
46#include <sys/kernel.h>
47#include <sys/module.h>
48#include <sys/bus.h>
49#include <machine/bus.h>
50#include <machine/resource.h>
51#include <sys/rman.h>
52#include <isa/isavar.h>
53
54#define UPD7210_HW_DRIVER
55#include <dev/ieee488/upd7210.h>
56
57struct pcii_softc {
58 int foo;
44
45#include <sys/param.h>
46#include <sys/systm.h>
47#include <sys/lock.h>
48#include <sys/mutex.h>
49#include <sys/kernel.h>
50#include <sys/module.h>
51#include <sys/bus.h>
52#include <machine/bus.h>
53#include <machine/resource.h>
54#include <sys/rman.h>
55#include <isa/isavar.h>
56
57#define UPD7210_HW_DRIVER
58#include <dev/ieee488/upd7210.h>
59
60struct pcii_softc {
61 int foo;
59 struct resource *res[3];
62 struct resource *res[11];
60 void *intr_handler;
61 struct upd7210 upd7210;
62};
63
64static devclass_t pcii_devclass;
65
66static int pcii_probe(device_t dev);
67static int pcii_attach(device_t dev);

--- 6 unchanged lines hidden (view full) ---

74
75 { 0, 0 }
76};
77
78static struct resource_spec pcii_res_spec[] = {
79 { SYS_RES_IRQ, 0, RF_ACTIVE | RF_SHAREABLE},
80 { SYS_RES_DRQ, 0, RF_ACTIVE | RF_SHAREABLE | RF_OPTIONAL},
81 { SYS_RES_IOPORT, 0, RF_ACTIVE},
63 void *intr_handler;
64 struct upd7210 upd7210;
65};
66
67static devclass_t pcii_devclass;
68
69static int pcii_probe(device_t dev);
70static int pcii_attach(device_t dev);

--- 6 unchanged lines hidden (view full) ---

77
78 { 0, 0 }
79};
80
81static struct resource_spec pcii_res_spec[] = {
82 { SYS_RES_IRQ, 0, RF_ACTIVE | RF_SHAREABLE},
83 { SYS_RES_DRQ, 0, RF_ACTIVE | RF_SHAREABLE | RF_OPTIONAL},
84 { SYS_RES_IOPORT, 0, RF_ACTIVE},
85 { SYS_RES_IOPORT, 1, RF_ACTIVE},
86 { SYS_RES_IOPORT, 2, RF_ACTIVE},
87 { SYS_RES_IOPORT, 3, RF_ACTIVE},
88 { SYS_RES_IOPORT, 4, RF_ACTIVE},
89 { SYS_RES_IOPORT, 5, RF_ACTIVE},
90 { SYS_RES_IOPORT, 6, RF_ACTIVE},
91 { SYS_RES_IOPORT, 7, RF_ACTIVE},
92 { SYS_RES_IOPORT, 8, RF_ACTIVE | RF_SHAREABLE},
82 { -1, 0, 0 }
83};
84
85static driver_t pcii_driver = {
86 "pcii",
87 pcii_methods,
88 sizeof(struct pcii_softc),
89};
90
91static int
92pcii_probe(device_t dev)
93{
94 int rid, i, j;
93 { -1, 0, 0 }
94};
95
96static driver_t pcii_driver = {
97 "pcii",
98 pcii_methods,
99 sizeof(struct pcii_softc),
100};
101
102static int
103pcii_probe(device_t dev)
104{
105 int rid, i, j;
95 u_long start, count;
106 u_long start, count, addr;
96 int error = 0;
97 struct pcii_softc *sc;
98
99 device_set_desc(dev, "PCII IEEE-4888 controller");
100 sc = device_get_softc(dev);
101
102 rid = 0;
103 if (bus_get_resource(dev, SYS_RES_IOPORT, rid, &start, &count) != 0)
104 return ENXIO;
107 int error = 0;
108 struct pcii_softc *sc;
109
110 device_set_desc(dev, "PCII IEEE-4888 controller");
111 sc = device_get_softc(dev);
112
113 rid = 0;
114 if (bus_get_resource(dev, SYS_RES_IOPORT, rid, &start, &count) != 0)
115 return ENXIO;
105 if ((start & 0x3ff) != 0x2e1)
116 /*
117 * The PCIIA decodes a fixed pattern of 0x2e1 for the lower 10
118 * address bits A0 ... A9. Bits A10 through A12 are used by
119 * the �PD7210 register select lines. This makes the
120 * individual 7210 register being 0x400 bytes apart in the ISA
121 * bus address space. Address bits A13 and A14 are compared
122 * to a DIP switch setting on the card, allowing for up to 4
123 * different cards being installed (at base addresses 0x2e1,
124 * 0x22e1, 0x42e1, and 0x62e1, respectively). A15 has been
125 * used to select an optional on-board time-of-day clock chip
126 * (MM58167A) on the original PCIIA rather than the �PD7210
127 * (which is not implemented on later boards). The
128 * documentation states the respective addresses for that chip
129 * should be handled as reserved addresses, which we don't do
130 * (right now). Finally, the IO addresses 0x2f0 ... 0x2f7 for
131 * a "special interrupt handling feature" (re-enable
132 * interrupts so the IRQ can be shared).
133 *
134 * Usually, the user will only set the base address in the
135 * device hints, so we handle the rest here.
136 *
137 * (Source: GPIB-PCIIA Technical Reference Manual, September
138 * 1989 Edition, National Instruments.)
139 */
140 if ((start & 0x3ff) != 0x2e1) {
141 printf("pcii_probe: PCIIA base address 0x%lx not "
142 "0x2e1/0x22e1/0x42e1/0x62e1\n",
143 start);
106 return (ENXIO);
144 return (ENXIO);
107 count = 1;
108 if (bus_set_resource(dev, SYS_RES_IOPORT, rid, start, count) != 0)
145 }
146
147 for (rid = 0, addr = start; rid < 8; rid++, addr += 0x400) {
148 if (bus_set_resource(dev, SYS_RES_IOPORT, rid, addr, 1) != 0) {
149 printf("pcii_probe: could not set IO port 0x%lx\n",
150 addr);
151 return (ENXIO);
152 }
153 }
154 if (bus_get_resource(dev, SYS_RES_IRQ, 0, &start, &count) != 0) {
155 printf("pcii_probe: cannot obtain IRQ level\n");
109 return ENXIO;
156 return ENXIO;
157 }
158 if (start > 7) {
159 printf("pcii_probe: IRQ level %lu too high\n", start);
160 return ENXIO;
161 }
162
163 if (bus_set_resource(dev, SYS_RES_IOPORT, 8, 0x2f0 + start, 1) != 0) {
164 printf("pcii_probe: could not set IO port 0x%3lx\n",
165 0x2f0 + start);
166 return (ENXIO);
167 }
168
110 error = bus_alloc_resources(dev, pcii_res_spec, sc->res);
169 error = bus_alloc_resources(dev, pcii_res_spec, sc->res);
111 if (error)
170 if (error) {
171 printf("pcii_probe: Could not allocate resources\n");
112 return (error);
172 return (error);
173 }
113 error = ENXIO;
174 error = ENXIO;
175 /*
176 * Perform some basic tests on the �PD7210 registers. At
177 * least *some* register must read different from 0x00 or
178 * 0xff.
179 */
114 for (i = 0; i < 8; i++) {
180 for (i = 0; i < 8; i++) {
115 j = bus_read_1(sc->res[2], i * 0x400);
181 j = bus_read_1(sc->res[2 + i], 0);
116 if (j != 0x00 && j != 0xff)
117 error = 0;
118 }
182 if (j != 0x00 && j != 0xff)
183 error = 0;
184 }
185 /* SPSR/SPMR read/write test */
119 if (!error) {
186 if (!error) {
120 bus_write_1(sc->res[2], 3 * 0x400, 0x55);
121 if (bus_read_1(sc->res[2], 3 * 0x400) != 0x55)
187 bus_write_1(sc->res[2 + 3], 0, 0x55);
188 if (bus_read_1(sc->res[2 + 3], 0) != 0x55)
122 error = ENXIO;
123 }
124 if (!error) {
189 error = ENXIO;
190 }
191 if (!error) {
125 bus_write_1(sc->res[2], 3 * 0x400, 0xaa);
126 if (bus_read_1(sc->res[2], 3 * 0x400) != 0xaa)
192 bus_write_1(sc->res[2 + 3], 0, 0xaa);
193 if (bus_read_1(sc->res[2 + 3], 0) != 0xaa)
127 error = ENXIO;
128 }
194 error = ENXIO;
195 }
196 if (error)
197 printf("pcii_probe: probe failure\n");
198
129 bus_release_resources(dev, pcii_res_spec, sc->res);
130 return (error);
131}
132
133static int
134pcii_attach(device_t dev)
135{
136 struct pcii_softc *sc;
199 bus_release_resources(dev, pcii_res_spec, sc->res);
200 return (error);
201}
202
203static int
204pcii_attach(device_t dev)
205{
206 struct pcii_softc *sc;
207 u_long start, count;
137 int unit;
138 int rid;
139 int error = 0;
140
141 unit = device_get_unit(dev);
142 sc = device_get_softc(dev);
143 memset(sc, 0, sizeof *sc);
144
145 device_set_desc(dev, "PCII IEEE-4888 controller");
146
208 int unit;
209 int rid;
210 int error = 0;
211
212 unit = device_get_unit(dev);
213 sc = device_get_softc(dev);
214 memset(sc, 0, sizeof *sc);
215
216 device_set_desc(dev, "PCII IEEE-4888 controller");
217
218 if (bus_get_resource(dev, SYS_RES_IRQ, 0, &start, &count) != 0) {
219 printf("pcii_attach: cannot obtain IRQ number\n");
220 return ENXIO;
221 }
222
147 error = bus_alloc_resources(dev, pcii_res_spec, sc->res);
148 if (error)
149 return (error);
150
151 error = bus_setup_intr(dev, sc->res[0],
152 INTR_TYPE_MISC | INTR_MPSAFE, NULL,
153 upd7210intr, &sc->upd7210, &sc->intr_handler);
154 if (error) {
155 bus_release_resources(dev, pcii_res_spec, sc->res);
156 return (error);
157 }
158
159 for (rid = 0; rid < 8; rid++) {
223 error = bus_alloc_resources(dev, pcii_res_spec, sc->res);
224 if (error)
225 return (error);
226
227 error = bus_setup_intr(dev, sc->res[0],
228 INTR_TYPE_MISC | INTR_MPSAFE, NULL,
229 upd7210intr, &sc->upd7210, &sc->intr_handler);
230 if (error) {
231 bus_release_resources(dev, pcii_res_spec, sc->res);
232 return (error);
233 }
234
235 for (rid = 0; rid < 8; rid++) {
160 sc->upd7210.reg_res[rid] = sc->res[2];
161 sc->upd7210.reg_offset[rid] = 0x400 * rid;
236 sc->upd7210.reg_res[rid] = sc->res[2 + rid];
162 }
237 }
238 sc->upd7210.irq_clear_res = sc->res[10];
163
164 if (sc->res[1] == NULL)
165 sc->upd7210.dmachan = -1;
166 else
167 sc->upd7210.dmachan = rman_get_start(sc->res[1]);
168
169 upd7210attach(&sc->upd7210);
170 return (error);
171}
172
173DRIVER_MODULE(pcii, isa, pcii_driver, pcii_devclass, 0, 0);
174DRIVER_MODULE(pcii, acpi, pcii_driver, pcii_devclass, 0, 0);
239
240 if (sc->res[1] == NULL)
241 sc->upd7210.dmachan = -1;
242 else
243 sc->upd7210.dmachan = rman_get_start(sc->res[1]);
244
245 upd7210attach(&sc->upd7210);
246 return (error);
247}
248
249DRIVER_MODULE(pcii, isa, pcii_driver, pcii_devclass, 0, 0);
250DRIVER_MODULE(pcii, acpi, pcii_driver, pcii_devclass, 0, 0);