osiop_jazzio.c revision 1.4.2.1 1 /* $NetBSD: osiop_jazzio.c,v 1.4.2.1 2004/08/03 10:32:22 skrll Exp $ */
2
3 /*
4 * Copyright (c) 2001 Izumi Tsutsui. 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
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: osiop_jazzio.c,v 1.4.2.1 2004/08/03 10:32:22 skrll Exp $");
31
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/device.h>
35 #include <sys/buf.h>
36 #include <sys/malloc.h>
37
38 #include <dev/scsipi/scsi_all.h>
39 #include <dev/scsipi/scsipi_all.h>
40 #include <dev/scsipi/scsiconf.h>
41
42 #include <machine/cpu.h>
43 #include <machine/autoconf.h>
44 #include <machine/bus.h>
45
46 #include <dev/ic/osiopreg.h>
47 #include <dev/ic/osiopvar.h>
48
49 #include <arc/jazz/jazziovar.h>
50
51 int osiop_jazzio_match(struct device *, struct cfdata *, void *);
52 void osiop_jazzio_attach(struct device *, struct device *, void *);
53 int osiop_jazzio_intr(void *);
54
55 CFATTACH_DECL(osiop_jazzio, sizeof(struct osiop_softc),
56 osiop_jazzio_match, osiop_jazzio_attach, NULL, NULL);
57
58 int
59 osiop_jazzio_match(parent, match, aux)
60 struct device *parent;
61 struct cfdata *match;
62 void *aux;
63 {
64 struct jazzio_attach_args *ja = aux;
65
66 if (strcmp(ja->ja_name, "NCRC710") != 0)
67 return (0);
68
69 return (1);
70 }
71
72 void
73 osiop_jazzio_attach(parent, self, aux)
74 struct device *parent;
75 struct device *self;
76 void *aux;
77 {
78 struct jazzio_attach_args *ja = aux;
79 struct osiop_softc *sc = (void *)self;
80 int err, scid;
81
82 sc->sc_bst = ja->ja_bust;
83 sc->sc_dmat = ja->ja_dmat;
84
85 /*
86 * Map registers
87 */
88 err = bus_space_map(sc->sc_bst, ja->ja_addr,
89 OSIOP_NREGS, 0, &sc->sc_reg);
90 if (err) {
91 printf("%s: failed to map registers, err=%d\n",
92 sc->sc_dev.dv_xname, err);
93 return;
94 }
95
96 sc->sc_clock_freq = 50; /* MHz */
97 sc->sc_ctest7 = 0; /* | OSIOP_CTEST7_TT1 */
98 sc->sc_dcntl = OSIOP_DCNTL_EA;
99
100 /* XXX should check ID in BIOS variables? */
101 scid = ffs(osiop_read_1(sc, OSIOP_SCID));
102
103 if (scid == 0)
104 scid = 7;
105 else
106 scid--;
107
108 sc->sc_id = scid;
109
110 /*
111 * Call common attachment
112 */
113 osiop_attach(sc);
114
115 /*
116 * Set up interrupt handler.
117 */
118 jazzio_intr_establish(ja->ja_intr,
119 (intr_handler_t)osiop_jazzio_intr, sc);
120 }
121
122 /*
123 * interrupt handler
124 */
125 int
126 osiop_jazzio_intr(arg)
127 void *arg;
128 {
129 struct osiop_softc *sc = arg;
130 u_int8_t istat;
131
132 /* This is potentially nasty, since the IRQ is level triggered... */
133 if (sc->sc_flags & OSIOP_INTSOFF)
134 return (0);
135
136 istat = osiop_read_1(sc, OSIOP_ISTAT);
137
138 if ((istat & (OSIOP_ISTAT_SIP | OSIOP_ISTAT_DIP)) == 0)
139 return (0);
140
141 /* Save interrupt details for the back-end interrupt handler */
142 sc->sc_sstat0 = osiop_read_1(sc, OSIOP_SSTAT0);
143 sc->sc_istat = istat;
144 sc->sc_dstat = osiop_read_1(sc, OSIOP_DSTAT);
145
146 /* Deal with the interrupt */
147 osiop_intr(sc);
148
149 return (1);
150 }
151