spc.c revision 1.33 1 1.33 tsutsui /* $NetBSD: spc.c,v 1.33 2008/03/31 15:20:47 tsutsui 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.26 lukem
39 1.26 lukem #include <sys/cdefs.h>
40 1.33 tsutsui __KERNEL_RCSID(0, "$NetBSD: spc.c,v 1.33 2008/03/31 15:20:47 tsutsui Exp $");
41 1.1 oki
42 1.15 jonathan #include "opt_ddb.h"
43 1.1 oki
44 1.1 oki #include <sys/param.h>
45 1.1 oki #include <sys/systm.h>
46 1.1 oki #include <sys/kernel.h>
47 1.1 oki #include <sys/device.h>
48 1.20 minoura
49 1.20 minoura #include <machine/bus.h>
50 1.20 minoura #include <machine/cpu.h>
51 1.1 oki
52 1.10 bouyer #include <dev/scsipi/scsi_all.h>
53 1.10 bouyer #include <dev/scsipi/scsipi_all.h>
54 1.10 bouyer #include <dev/scsipi/scsiconf.h>
55 1.1 oki
56 1.20 minoura #include <arch/x68k/dev/intiovar.h>
57 1.20 minoura #include <arch/x68k/dev/scsiromvar.h>
58 1.20 minoura #include <arch/x68k/x68k/iodevice.h>
59 1.1 oki
60 1.20 minoura #include <dev/ic/mb89352var.h>
61 1.20 minoura #include <dev/ic/mb89352reg.h>
62 1.1 oki
63 1.33 tsutsui static int spc_intio_match(device_t, cfdata_t, void *);
64 1.33 tsutsui static void spc_intio_attach(device_t, device_t, void *);
65 1.1 oki
66 1.33 tsutsui CFATTACH_DECL_NEW(spc_intio, sizeof(struct spc_softc),
67 1.24 thorpej spc_intio_match, spc_intio_attach, NULL, NULL);
68 1.1 oki
69 1.31 isaki static int
70 1.33 tsutsui spc_intio_match(device_t parent, cfdata_t cf, 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.33 tsutsui ia->ia_size = 0x20;
77 1.1 oki
78 1.30 thorpej if (intio_map_allocate_region(device_parent(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.28 he if (badaddr(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.31 isaki static void
93 1.33 tsutsui spc_intio_attach(device_t parent, device_t self, void *aux)
94 1.1 oki {
95 1.33 tsutsui struct spc_softc *sc = device_private(self);
96 1.20 minoura struct intio_attach_args *ia = aux;
97 1.20 minoura bus_space_tag_t iot = ia->ia_bst;
98 1.20 minoura bus_space_handle_t ioh;
99 1.20 minoura
100 1.33 tsutsui sc->sc_dev = self;
101 1.20 minoura
102 1.30 thorpej intio_map_allocate_region(device_parent(parent), ia,
103 1.20 minoura INTIO_MAP_ALLOCATE);
104 1.20 minoura if (bus_space_map(iot, ia->ia_addr, 0x20, BUS_SPACE_MAP_SHIFTED,
105 1.20 minoura &ioh)) {
106 1.33 tsutsui aprint_error(": can't map i/o space\n");
107 1.12 oki return;
108 1.1 oki }
109 1.33 tsutsui aprint_normal("\n");
110 1.1 oki
111 1.20 minoura sc->sc_iot = iot;
112 1.20 minoura sc->sc_ioh = ioh;
113 1.20 minoura sc->sc_initiator = IODEVbase->io_sram[0x70] & 0x7; /* XXX */
114 1.1 oki
115 1.25 tsutsui if (intio_intr_establish(ia->ia_intr, "spc", spc_intr, sc))
116 1.32 isaki panic("spcattach: interrupt vector busy");
117 1.1 oki
118 1.25 tsutsui spc_attach(sc);
119 1.1 oki }
120