xref: /openbsd/sys/arch/sparc64/dev/stp_sbus.c (revision db3296cf)
1 /*	$OpenBSD: stp_sbus.c,v 1.4 2003/06/25 17:36:51 miod Exp $	*/
2 /*	$NetBSD: stp4020.c,v 1.23 2002/06/01 23:51:03 lukem Exp $	*/
3 
4 /*-
5  * Copyright (c) 1998 The NetBSD Foundation, Inc.
6  * All rights reserved.
7  *
8  * This code is derived from software contributed to The NetBSD Foundation
9  * by Paul Kranenburg.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. All advertising materials mentioning features or use of this software
20  *    must display the following acknowledgement:
21  *        This product includes software developed by the NetBSD
22  *        Foundation, Inc. and its contributors.
23  * 4. Neither the name of The NetBSD Foundation nor the names of its
24  *    contributors may be used to endorse or promote products derived
25  *    from this software without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37  * POSSIBILITY OF SUCH DAMAGE.
38  */
39 
40 /*
41  * STP4020: SBus/PCMCIA bridge supporting two Type-3 PCMCIA cards.
42  */
43 
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/errno.h>
47 #include <sys/malloc.h>
48 #include <sys/extent.h>
49 #include <sys/proc.h>
50 #include <sys/kernel.h>
51 #include <sys/kthread.h>
52 #include <sys/device.h>
53 
54 #include <dev/pcmcia/pcmciareg.h>
55 #include <dev/pcmcia/pcmciavar.h>
56 #include <dev/pcmcia/pcmciachip.h>
57 
58 #include <machine/bus.h>
59 #include <machine/intr.h>
60 
61 #include <dev/sbus/sbusvar.h>
62 #include <dev/sbus/stp4020reg.h>
63 #include <dev/sbus/stp4020var.h>
64 
65 struct stp4020_sbus_softc {
66 	struct stp4020_softc stp;
67 	struct sbusdev	sc_sd;		/* SBus device */
68 };
69 
70 int	stpmatch(struct device *, void *, void *);
71 void	stpattach(struct device *, struct device *, void *);
72 
73 struct cfattach stp_sbus_ca = {
74 	sizeof(struct stp4020_sbus_softc), stpmatch, stpattach
75 };
76 
77 int
78 stpmatch(parent, match, aux)
79 	struct device *parent;
80 	void *match;
81 	void *aux;
82 {
83 	struct sbus_attach_args *sa = aux;
84 
85 	return (strcmp("SUNW,pcmcia", sa->sa_name) == 0);
86 }
87 
88 /*
89  * Attach all the sub-devices we can find
90  */
91 void
92 stpattach(parent, self, aux)
93 	struct device *parent, *self;
94 	void *aux;
95 {
96 	struct sbus_attach_args *sa = aux;
97 	struct stp4020_sbus_softc *ssc = (void *)self;
98 	struct stp4020_softc *sc = (void *)self;
99 	int node;
100 	int i;
101 	bus_space_handle_t bh;
102 
103 	node = sa->sa_node;
104 
105 	/* Transfer bus tags */
106 	sc->sc_bustag = sa->sa_bustag;
107 
108 	/* Set up per-socket static initialization */
109 	sc->sc_socks[0].sc = sc->sc_socks[1].sc = sc;
110 	sc->sc_socks[0].tag = sc->sc_socks[1].tag = sa->sa_bustag;
111 
112 	if (sa->sa_nreg < 8) {
113 		printf(": only %d register sets\n", sa->sa_nreg);
114 		return;
115 	}
116 
117 	if (sa->sa_nintr != 2) {
118 		printf(": expect 2 interrupt Sbus levels; got %d\n",
119 		    sa->sa_nintr);
120 		return;
121 	}
122 
123 #define STP4020_BANK_PROM	0
124 #define STP4020_BANK_CTRL	4
125 	for (i = 0; i < 8; i++) {
126 
127 		/*
128 		 * STP4020 Register address map:
129 		 *	bank  0:   Forth PROM
130 		 *	banks 1-3: socket 0, windows 0-2
131 		 *	bank  4:   control registers
132 		 *	banks 5-7: socket 1, windows 0-2
133 		 */
134 
135 		if (i == STP4020_BANK_PROM)
136 			/* Skip the PROM */
137 			continue;
138 
139 		if (sbus_bus_map(sa->sa_bustag, sa->sa_reg[i].sbr_slot,
140 		    sa->sa_reg[i].sbr_offset, sa->sa_reg[i].sbr_size,
141 		    BUS_SPACE_MAP_LINEAR, 0, &bh) != 0) {
142 			printf(": attach: cannot map registers\n");
143 			return;
144 		}
145 
146 		if (i == STP4020_BANK_CTRL) {
147 			/*
148 			 * Copy tag and handle to both socket structures
149 			 * for easy access in control/status IO functions.
150 			 */
151 			sc->sc_socks[0].regs = sc->sc_socks[1].regs = bh;
152 		} else if (i < STP4020_BANK_CTRL) {
153 			/* banks 1-3 */
154 			sc->sc_socks[0].windows[i-1].winaddr = bh;
155 			sc->sc_socks[0].wintag = sc->sc_bustag;
156 		} else {
157 			/* banks 5-7 */
158 			sc->sc_socks[1].windows[i-5].winaddr = bh;
159 			sc->sc_socks[1].wintag = sc->sc_bustag;
160 		}
161 	}
162 
163 	sbus_establish(&ssc->sc_sd, &sc->sc_dev);
164 
165 	/*
166 	 * We get to use two SBus interrupt levels.
167 	 * The higher level we use for status change interrupts;
168 	 * the lower level for PC card I/O.
169 	 */
170 	bus_intr_establish(sa->sa_bustag, sa->sa_intr[1].sbi_pri,
171 	    IPL_NONE, 0, stp4020_statintr, sc, self->dv_xname);
172 
173 	bus_intr_establish(sa->sa_bustag, sa->sa_intr[0].sbi_pri,
174 	    IPL_NONE, 0, stp4020_iointr, sc, self->dv_xname);
175 
176 	stpattach_common(sc, sa->sa_frequency);
177 }
178