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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
|
/* $OpenBSD: bpp.c,v 1.5 2010/08/06 00:00:38 miod Exp $ */
/*
* Copyright (c) 1997, Jason Downs. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/param.h>
#include <sys/buf.h>
#include <sys/kernel.h>
#include <sys/uio.h>
#include <sys/device.h>
#include <sys/conf.h>
#include <sys/systm.h>
#include <machine/autoconf.h>
#include <machine/conf.h>
#include <sparc/dev/bppreg.h>
#define BPP_BSIZE 1024
#define LONG_TIMEOUT 30 /* XXX */
#define SHORT_TIMEOUT 3 /* XXX */
struct bpp_softc {
struct device sc_dev;
size_t sc_count;
struct buf *sc_inbuf;
u_int8_t *sc_cp;
char sc_open;
volatile struct bppregs *sc_regs;
};
static int bppmatch(struct device *, void *, void *);
static void bppattach(struct device *, struct device *, void *);
#define BPPUNIT(s) minor(s)
struct cfattach bpp_ca = {
sizeof(struct bpp_softc), bppmatch, bppattach
};
struct cfdriver bpp_cd = {
NULL, "bpp", DV_DULL
};
static __inline__ void bpp_outb(struct bpp_softc *, u_int8_t);
static __inline__ u_int8_t bpp_inb(struct bpp_softc *);
static void bppreset(struct bpp_softc *, int);
static void bppresetmode(struct bpp_softc *);
static int bpppushbytes(struct bpp_softc *);
static int
bppmatch(parent, vcf, aux)
struct device *parent;
void *aux, *vcf;
{
register struct confargs *ca = aux;
if (strcmp(ca->ca_ra.ra_name, "SUNW,bpp"))
return (0);
return (1);
}
static void
bppattach(parent, self, aux)
struct device *parent, *self;
void *aux;
{
struct confargs *ca = aux;
struct romaux *ra = &ca->ca_ra;
struct bpp_softc *bpp = (void *)self;
bpp->sc_regs = mapiodev(ra->ra_reg, 0, ra->ra_len);
bppreset(bpp, 0);
switch (bpp->sc_regs->bpp_csr & BPP_DEV_ID_MASK) {
case BPP_DEV_ID_ZEBRA:
printf(": Zebra\n");
break;
case BPP_DEV_ID_L64854:
printf(": DMA2\n");
break;
default:
printf(": Unknown type\n");
break;
}
bppresetmode(bpp);
}
static void
bppreset(bpp, verbose)
struct bpp_softc *bpp;
int verbose;
{
volatile u_int32_t bpp_csr;
/* Reset hardware. */
bpp_csr = bpp->sc_regs->bpp_csr;
if ((bpp_csr & BPP_DRAINING) && !(bpp_csr & BPP_ERR_PEND)) {
delay(20);
bpp_csr = bpp->sc_regs->bpp_csr;
if (verbose && (bpp_csr & BPP_DRAINING) &&
!(bpp_csr & BPP_ERR_PEND))
printf("%s: draining still active (0x%08x)\n",
bpp->sc_dev.dv_xname, bpp_csr);
}
bpp->sc_regs->bpp_csr = (bpp_csr | BPP_RESET) & ~BPP_INT_EN;
delay(500);
bpp->sc_regs->bpp_csr &= ~BPP_RESET;
}
static void
bppresetmode(bpp)
struct bpp_softc *bpp;
{
bpp->sc_regs->bpp_or = BPP_OR_AFXN|BPP_OR_SLCT_IN;
bpp->sc_regs->bpp_tcr = BPP_TCR_DS;
}
static __inline__ void
bpp_outb(bpp, byte)
struct bpp_softc *bpp;
u_int8_t byte;
{
bpp->sc_regs->bpp_dr = byte;
}
static __inline__ u_int8_t
bpp_inb(bpp)
struct bpp_softc *bpp;
{
return (bpp->sc_regs->bpp_dr);
}
int
bppopen(dev, flag, mode, p)
dev_t dev;
int flag, mode;
struct proc *p;
{
int unit = BPPUNIT(dev);
struct bpp_softc *bpp;
if (unit >= bpp_cd.cd_ndevs)
return (ENXIO);
bpp = bpp_cd.cd_devs[unit];
if (!bpp)
return (ENXIO);
if (bpp->sc_open)
return (EBUSY);
bpp->sc_inbuf = geteblk(BPP_BSIZE);
bpp->sc_count = 0;
bpp->sc_open = 1;
/* bppreset(bpp, 1); */
bppresetmode(bpp);
return (0);
}
int
bppclose(dev, flag, mode, p)
dev_t dev;
int flag, mode;
struct proc *p;
{
struct bpp_softc *bpp = bpp_cd.cd_devs[BPPUNIT(dev)];
int error = 0;
if (bpp->sc_count)
(void) bpppushbytes(bpp);
/* XXX */
bppresetmode(bpp);
delay(100);
bppreset(bpp, 1);
delay(100);
bppresetmode(bpp);
brelse(bpp->sc_inbuf);
bpp->sc_open = 0;
return (error);
}
int
bpppushbytes(bpp)
struct bpp_softc *bpp;
{
int spin, error;
while (bpp->sc_count > 0) {
error = 0;
/* Wait for BPP_TCR_ACK and BPP_TCR_BUSY to clear. */
spin = 0;
while ((bpp->sc_regs->bpp_tcr & BPP_TCR_ACK) ||
(bpp->sc_regs->bpp_tcr & BPP_TCR_BUSY)) {
delay(1000);
if (++spin >= LONG_TIMEOUT)
break;
}
if ((bpp->sc_regs->bpp_tcr & BPP_TCR_ACK) ||
(bpp->sc_regs->bpp_tcr & BPP_TCR_BUSY))
return (EBUSY);
bpp_outb(bpp, *bpp->sc_cp++);
/* Clear BPP_TCR_DS. */
bpp->sc_regs->bpp_tcr &= ~BPP_TCR_DS;
/* Short wait for BPP_TCR_BUSY. */
spin = 0;
while (!(bpp->sc_regs->bpp_tcr & BPP_TCR_BUSY)) {
delay(1000);
if (++spin >= SHORT_TIMEOUT)
break;
}
if (!(bpp->sc_regs->bpp_tcr & BPP_TCR_BUSY))
error = EIO;
/* Set BPP_TCR_DS. */
bpp->sc_regs->bpp_tcr |= BPP_TCR_DS;
if (error)
return (error);
bpp->sc_count--;
}
return (error);
}
int
bppwrite(dev, uio, flags)
dev_t dev;
struct uio *uio;
int flags;
{
struct bpp_softc *bpp = bpp_cd.cd_devs[BPPUNIT(dev)];
size_t n;
int error = 0;
while ((n = min(BPP_BSIZE, uio->uio_resid)) != 0) {
error = uiomove(bpp->sc_cp = bpp->sc_inbuf->b_data, n, uio);
if (error != 0)
return error;
bpp->sc_count = n;
error = bpppushbytes(bpp);
if (error) {
/*
* Return accurate residual if interrupted or timed
* out.
*/
uio->uio_resid += bpp->sc_count;
bpp->sc_count = 0;
return (error);
}
}
return (0);
}
int
bppioctl(dev, cmd, data, flag, p)
dev_t dev;
u_long cmd;
caddr_t data;
int flag;
struct proc *p;
{
return (ENODEV);
}
|