Deleted Added
sdiff udiff text old ( 202898 ) new ( 203360 )
full compact
1/*-
2 * Copyright (c) 2005 Poul-Henning Kamp <phk@FreeBSD.org>
3 * Copyright (c) 2010 Joerg Wunsch <joerg@FreeBSD.org>
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:

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

24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 * High-level driver for �PD7210 based GPIB cards.
28 *
29 */
30
31#include <sys/cdefs.h>
32__FBSDID("$FreeBSD: head/sys/dev/ieee488/upd7210.c 202898 2010-01-23 21:33:33Z joerg $");
33
34# define GPIB_DEBUG
35# undef GPIB_DEBUG
36
37#include <sys/param.h>
38#include <sys/systm.h>
39#include <sys/conf.h>
40#include <sys/malloc.h>

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

49#include <sys/time.h>
50#include <machine/bus.h>
51#include <machine/resource.h>
52#include <isa/isavar.h>
53
54#define UPD7210_HW_DRIVER
55#define UPD7210_SW_DRIVER
56#include <dev/ieee488/upd7210.h>
57
58static MALLOC_DEFINE(M_GPIB, "GPIB", "GPIB");
59
60/* upd7210 generic stuff */
61
62void
63upd7210_print_isr(u_int isr1, u_int isr2)
64{

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

85 u->wreg[reg] = val;
86 if (reg == AUXMR)
87 u->wreg[8 + (val >> 5)] = val & 0x1f;
88}
89
90void
91upd7210intr(void *arg)
92{
93 u_int isr1, isr2;
94 struct upd7210 *u;
95
96 u = arg;
97 mtx_lock(&u->mutex);
98 isr1 = upd7210_rd(u, ISR1);
99 isr2 = upd7210_rd(u, ISR2);
100 if (isr1 != 0 || isr2 != 0) {
101 if (u->busy == 0 || u->irq == NULL || !u->irq(u, 1)) {
102#if 0
103 printf("upd7210intr [%02x %02x %02x",
104 upd7210_rd(u, DIR), isr1, isr2);
105 printf(" %02x %02x %02x %02x %02x] ",
106 upd7210_rd(u, SPSR),
107 upd7210_rd(u, ADSR),
108 upd7210_rd(u, CPTR),
109 upd7210_rd(u, ADR0),

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

163 return (0);
164 }
165 return (1);
166}
167
168/* Unaddressed Listen Only mode */
169
170static int
171gpib_l_irq(struct upd7210 *u, int intr __unused)
172{
173 int i;
174
175 if (u->rreg[ISR1] & 1) {
176 i = upd7210_rd(u, DIR);
177 u->buf[u->buf_wp++] = i;
178 u->buf_wp &= (u->bufsize - 1);
179 i = (u->buf_rp + u->bufsize - u->buf_wp) & (u->bufsize - 1);
180 if (i < 8)
181 upd7210_wr(u, IMR1, 0);
182 wakeup(u->buf);
183 return (1);
184 }
185 return (0);
186}
187
188static int
189gpib_l_open(struct cdev *dev, int oflags, int devtype, struct thread *td)

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

201 u->irq = gpib_l_irq;
202 mtx_unlock(&u->mutex);
203
204 u->buf = malloc(PAGE_SIZE, M_GPIB, M_WAITOK);
205 u->bufsize = PAGE_SIZE;
206 u->buf_wp = 0;
207 u->buf_rp = 0;
208
209 upd7210_wr(u, AUXMR, AUXMR_CRST);
210 DELAY(10000);
211 upd7210_wr(u, AUXMR, C_ICR | 8);
212 DELAY(1000);
213 upd7210_wr(u, ADR, 0x60);
214 upd7210_wr(u, ADR, 0xe0);
215 upd7210_wr(u, ADMR, 0x70);
216 upd7210_wr(u, AUXMR, AUXMR_PON);
217 upd7210_wr(u, IMR1, 0x01);
218 return (0);
219}
220
221static int
222gpib_l_close(struct cdev *dev, int oflags, int devtype, struct thread *td)
223{
224 struct upd7210 *u;
225
226 u = dev->si_drv1;
227
228 mtx_lock(&u->mutex);
229 u->busy = 0;
230 upd7210_wr(u, AUXMR, AUXMR_CRST);
231 DELAY(10000);
232 upd7210_wr(u, IMR1, 0x00);
233 upd7210_wr(u, IMR2, 0x00);
234 free(u->buf, M_GPIB);
235 u->buf = NULL;
236 mtx_unlock(&u->mutex);
237 return (0);

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

266 mtx_unlock(&u->mutex);
267 error = uiomove(u->buf + u->buf_rp, z, uio);
268 mtx_lock(&u->mutex);
269 if (error)
270 break;
271 u->buf_rp += z;
272 u->buf_rp &= (u->bufsize - 1);
273 }
274 if (u->wreg[IMR1] == 0)
275 upd7210_wr(u, IMR1, 0x01);
276 mtx_unlock(&u->mutex);
277 return (error);
278}
279
280static struct cdevsw gpib_l_cdevsw = {
281 .d_version = D_VERSION,
282 .d_name = "gpib_l",
283 .d_open = gpib_l_open,

--- 37 unchanged lines hidden ---