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