spc.c revision 1.23 1 1.23 thorpej /* $NetBSD: spc.c,v 1.23 2002/10/01 04:43:07 thorpej Exp $ */
2 1.1 oki
3 1.20 minoura /*-
4 1.20 minoura * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.20 minoura * All rights reserved.
6 1.20 minoura *
7 1.20 minoura * This code is derived from software contributed to The NetBSD Foundation
8 1.20 minoura * by Jarle Greipsland, Charles M. Hannum and Masaru Oki.
9 1.1 oki *
10 1.1 oki * Redistribution and use in source and binary forms, with or without
11 1.1 oki * modification, are permitted provided that the following conditions
12 1.1 oki * are met:
13 1.1 oki * 1. Redistributions of source code must retain the above copyright
14 1.1 oki * notice, this list of conditions and the following disclaimer.
15 1.1 oki * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 oki * notice, this list of conditions and the following disclaimer in the
17 1.1 oki * documentation and/or other materials provided with the distribution.
18 1.1 oki * 3. All advertising materials mentioning features or use of this software
19 1.1 oki * must display the following acknowledgement:
20 1.20 minoura * This product includes software developed by the NetBSD
21 1.20 minoura * Foundation, Inc. and its contributors.
22 1.20 minoura * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.20 minoura * contributors may be used to endorse or promote products derived
24 1.20 minoura * from this software without specific prior written permission.
25 1.1 oki *
26 1.20 minoura * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.20 minoura * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.20 minoura * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.20 minoura * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.20 minoura * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.20 minoura * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.20 minoura * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.20 minoura * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.20 minoura * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.20 minoura * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 oki * POSSIBILITY OF SUCH DAMAGE.
37 1.1 oki */
38 1.1 oki
39 1.15 jonathan #include "opt_ddb.h"
40 1.1 oki
41 1.1 oki #include <sys/param.h>
42 1.1 oki #include <sys/systm.h>
43 1.1 oki #include <sys/kernel.h>
44 1.1 oki #include <sys/device.h>
45 1.20 minoura
46 1.20 minoura #include <machine/bus.h>
47 1.20 minoura #include <machine/cpu.h>
48 1.1 oki
49 1.10 bouyer #include <dev/scsipi/scsi_all.h>
50 1.10 bouyer #include <dev/scsipi/scsipi_all.h>
51 1.10 bouyer #include <dev/scsipi/scsiconf.h>
52 1.1 oki
53 1.20 minoura #include <arch/x68k/dev/intiovar.h>
54 1.20 minoura #include <arch/x68k/dev/scsiromvar.h>
55 1.20 minoura #include <arch/x68k/x68k/iodevice.h>
56 1.1 oki
57 1.20 minoura #include <dev/ic/mb89352var.h>
58 1.20 minoura #include <dev/ic/mb89352reg.h>
59 1.1 oki
60 1.20 minoura static int spc_intio_match __P((struct device *, struct cfdata *, void *));
61 1.20 minoura static void spc_intio_attach __P((struct device *, struct device *, void *));
62 1.1 oki
63 1.23 thorpej CFATTACH_DECL(spc_intio, sizeof (struct spc_softc),
64 1.23 thorpej spc_intio_match, spc_intio_attach, NULL, NULL)
65 1.1 oki
66 1.20 minoura static int
67 1.20 minoura spc_intio_match(parent, cf, aux)
68 1.1 oki struct device *parent;
69 1.16 minoura struct cfdata *cf;
70 1.16 minoura void *aux;
71 1.1 oki {
72 1.20 minoura struct intio_attach_args *ia = aux;
73 1.20 minoura bus_space_tag_t iot = ia->ia_bst;
74 1.20 minoura bus_space_handle_t ioh;
75 1.1 oki
76 1.20 minoura ia->ia_size=0x20;
77 1.1 oki
78 1.20 minoura if (intio_map_allocate_region(parent->dv_parent, ia,
79 1.20 minoura INTIO_MAP_TESTONLY) < 0)
80 1.1 oki return 0;
81 1.1 oki
82 1.20 minoura if (bus_space_map(iot, ia->ia_addr, 0x20, BUS_SPACE_MAP_SHIFTED,
83 1.20 minoura &ioh) < 0)
84 1.20 minoura return 0;
85 1.21 minoura if (badaddr ((caddr_t)INTIO_ADDR(ia->ia_addr + BDID)))
86 1.1 oki return 0;
87 1.20 minoura bus_space_unmap(iot, ioh, 0x20);
88 1.1 oki
89 1.20 minoura return 1;
90 1.1 oki }
91 1.1 oki
92 1.20 minoura static void
93 1.20 minoura spc_intio_attach(parent, self, aux)
94 1.1 oki struct device *parent, *self;
95 1.1 oki void *aux;
96 1.1 oki {
97 1.20 minoura struct spc_softc *sc = (struct spc_softc *)self;
98 1.20 minoura struct intio_attach_args *ia = aux;
99 1.20 minoura bus_space_tag_t iot = ia->ia_bst;
100 1.20 minoura bus_space_handle_t ioh;
101 1.20 minoura
102 1.20 minoura printf ("\n");
103 1.20 minoura
104 1.20 minoura intio_map_allocate_region(parent->dv_parent, ia,
105 1.20 minoura INTIO_MAP_ALLOCATE);
106 1.20 minoura if (bus_space_map(iot, ia->ia_addr, 0x20, BUS_SPACE_MAP_SHIFTED,
107 1.20 minoura &ioh)) {
108 1.20 minoura printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
109 1.12 oki return;
110 1.1 oki }
111 1.1 oki
112 1.20 minoura sc->sc_iot = iot;
113 1.20 minoura sc->sc_ioh = ioh;
114 1.20 minoura sc->sc_initiator = IODEVbase->io_sram[0x70] & 0x7; /* XXX */
115 1.1 oki
116 1.20 minoura if (intio_intr_establish(ia->ia_intr, "spc", spcintr, sc))
117 1.20 minoura panic ("spcattach: interrupt vector busy");
118 1.1 oki
119 1.20 minoura spcattach(sc);
120 1.1 oki }
121