xref: /netbsd-src/sys/dev/mvme/clmpcc_pcctwo.c (revision 8b0f9554ff8762542c4defc4f70e1eb76fb508fa)
1 /*	$NetBSD: clmpcc_pcctwo.c,v 1.13 2007/10/19 12:00:36 ad Exp $	*/
2 
3 /*-
4  * Copyright (c) 1999, 2002 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Steve C. Woodford.
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 /*
40  * Cirrus Logic CD2401 4-channel serial chip. PCCchip2 Front-end.
41  */
42 
43 #include <sys/cdefs.h>
44 __KERNEL_RCSID(0, "$NetBSD: clmpcc_pcctwo.c,v 1.13 2007/10/19 12:00:36 ad Exp $");
45 
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/proc.h>
49 #include <sys/device.h>
50 #include <sys/conf.h>
51 #include <sys/file.h>
52 #include <sys/ioctl.h>
53 #include <sys/tty.h>
54 #include <sys/time.h>
55 #include <sys/kernel.h>
56 #include <sys/syslog.h>
57 
58 #include <dev/cons.h>
59 
60 #include <sys/cpu.h>
61 #include <sys/bus.h>
62 #include <sys/intr.h>
63 
64 #include <dev/ic/clmpccvar.h>
65 
66 #include <dev/mvme/pcctwovar.h>
67 #include <dev/mvme/pcctworeg.h>
68 
69 /* XXXXSCW: Fixme */
70 #ifdef MVME68K
71 #include <mvme68k/dev/mainbus.h>
72 #else
73 #error Need consiack hook
74 #endif
75 
76 
77 /* Definition of the driver for autoconfig. */
78 int clmpcc_pcctwo_match(struct device *, struct cfdata *, void *);
79 void clmpcc_pcctwo_attach(struct device *, struct device *, void *);
80 void clmpcc_pcctwo_iackhook(struct clmpcc_softc *, int);
81 void clmpcc_pcctwo_consiackhook(struct clmpcc_softc *, int);
82 
83 CFATTACH_DECL(clmpcc_pcctwo, sizeof(struct clmpcc_softc),
84     clmpcc_pcctwo_match, clmpcc_pcctwo_attach, NULL, NULL);
85 
86 extern struct cfdriver clmpcc_cd;
87 
88 extern const struct cdevsw clmpcc_cdevsw;
89 
90 /*
91  * For clmpcccn*()
92  */
93 cons_decl(clmpcc);
94 
95 
96 /*
97  * Is the CD2401 chip present?
98  */
99 int
100 clmpcc_pcctwo_match(parent, cf, aux)
101 	struct device *parent;
102 	struct cfdata *cf;
103 	void *aux;
104 {
105 	struct pcctwo_attach_args *pa;
106 
107 	pa = aux;
108 
109 	if (strcmp(pa->pa_name, clmpcc_cd.cd_name))
110 		return (0);
111 
112 	pa->pa_ipl = cf->pcctwocf_ipl;
113 
114 	return (1);
115 }
116 
117 /*
118  * Attach a found CD2401.
119  */
120 void
121 clmpcc_pcctwo_attach(parent, self, aux)
122 	struct device *parent;
123 	struct device *self;
124 	void *aux;
125 {
126 	struct clmpcc_softc *sc;
127 	struct pcctwo_attach_args *pa = aux;
128 	int level = pa->pa_ipl;
129 
130 	sc = device_private(self);
131 	level = pa->pa_ipl;
132 	sc->sc_iot = pa->pa_bust;
133 	bus_space_map(pa->pa_bust, pa->pa_offset, 0x100, 0, &sc->sc_ioh);
134 
135 	sc->sc_clk = 20000000;
136 	sc->sc_byteswap = CLMPCC_BYTESWAP_LOW;
137 	sc->sc_swaprtsdtr = 1;
138 	sc->sc_iackhook = clmpcc_pcctwo_iackhook;
139 	sc->sc_vector_base = PCCTWO_SCC_VECBASE;
140 	sc->sc_rpilr = 0x03;
141 	sc->sc_tpilr = 0x02;
142 	sc->sc_mpilr = 0x01;
143 	sc->sc_evcnt = pcctwointr_evcnt(level);
144 
145 	/* Do common parts of CD2401 configuration. */
146 	clmpcc_attach(sc);
147 
148 	/* Hook the interrupts */
149 	pcctwointr_establish(PCCTWOV_SCC_RX, clmpcc_rxintr, level, sc, NULL);
150 	pcctwointr_establish(PCCTWOV_SCC_RX_EXCEP, clmpcc_rxintr, level, sc,
151 	    NULL);
152 	pcctwointr_establish(PCCTWOV_SCC_TX, clmpcc_txintr, level, sc, NULL);
153 	pcctwointr_establish(PCCTWOV_SCC_MODEM, clmpcc_mdintr, level, sc, NULL);
154 }
155 
156 void
157 clmpcc_pcctwo_iackhook(sc, which)
158 	struct clmpcc_softc *sc;
159 	int which;
160 {
161 	bus_size_t offset;
162 	volatile u_char foo;
163 
164 	switch (which) {
165 	case CLMPCC_IACK_MODEM:
166 		offset = PCC2REG_SCC_MODEM_PIACK;
167 		break;
168 
169 	case CLMPCC_IACK_RX:
170 		offset = PCC2REG_SCC_RX_PIACK;
171 		break;
172 
173 	case CLMPCC_IACK_TX:
174 		offset = PCC2REG_SCC_TX_PIACK;
175 		break;
176 	default:
177 #ifdef DEBUG
178 		printf("%s: Invalid IACK number '%d'\n",
179 		    sc->sc_dev.dv_xname, which);
180 #endif
181 		panic("clmpcc_pcctwo_iackhook %d", which);
182 	}
183 
184 	foo = pcc2_reg_read(sys_pcctwo, offset);
185 }
186 
187 /*
188  * This routine is only used prior to clmpcc_attach() being called
189  */
190 void
191 clmpcc_pcctwo_consiackhook(sc, which)
192 	struct clmpcc_softc *sc;
193 	int which;
194 {
195 	bus_space_handle_t bush;
196 	bus_size_t offset;
197 	volatile u_char foo;
198 
199 	switch (which) {
200 	case CLMPCC_IACK_MODEM:
201 		offset = PCC2REG_SCC_MODEM_PIACK;
202 		break;
203 
204 	case CLMPCC_IACK_RX:
205 		offset = PCC2REG_SCC_RX_PIACK;
206 		break;
207 
208 	case CLMPCC_IACK_TX:
209 		offset = PCC2REG_SCC_TX_PIACK;
210 		break;
211 	default:
212 #ifdef DEBUG
213 		printf("%s: Invalid IACK number '%d'\n",
214 		    sc->sc_dev.dv_xname, which);
215 		panic("clmpcc_pcctwo_consiackhook");
216 #endif
217 		panic("clmpcc_pcctwo_iackhook %d", which);
218 	}
219 
220 #ifdef MVME68K
221 	/*
222 	 * We need to fake the tag and handle since 'sys_pcctwo' will
223 	 * be NULL during early system startup...
224 	 */
225 	bush = (bus_space_handle_t) & (intiobase[MAINBUS_PCCTWO_OFFSET +
226 		PCCTWO_REG_OFF]);
227 
228 	foo = bus_space_read_1(&_mainbus_space_tag, bush, offset);
229 #else
230 #error Need consiack hook
231 #endif
232 }
233 
234 
235 /****************************************************************
236  * Console support functions (MVME PCCchip2 specific!)
237  ****************************************************************/
238 
239 /*
240  * Check for CD2401 console.
241  */
242 void
243 clmpcccnprobe(cp)
244 	struct consdev *cp;
245 {
246 	int maj;
247 
248 #if defined(MVME68K)
249 	if (machineid != MVME_167 && machineid != MVME_177)
250 #elif defined(MVME88K)
251 	if (machineid != MVME_187)
252 #endif
253 	{
254 		cp->cn_pri = CN_DEAD;
255 		return;
256 	}
257 
258 	/*
259 	 * Locate the major number
260 	 */
261 	maj = cdevsw_lookup_major(&clmpcc_cdevsw);
262 
263 	/* Initialize required fields. */
264 	cp->cn_dev = makedev(maj, 0);
265 	cp->cn_pri = CN_NORMAL;
266 }
267 
268 void
269 clmpcccninit(cp)
270 	struct consdev *cp;
271 {
272 	static struct clmpcc_softc cons_sc;
273 
274 	cons_sc.sc_iot = &_mainbus_space_tag;
275 	bus_space_map(&_mainbus_space_tag,
276 	    intiobase_phys + MAINBUS_PCCTWO_OFFSET + PCCTWO_SCC_OFF,
277 	    PCC2REG_SIZE, 0, &cons_sc.sc_ioh);
278 	cons_sc.sc_clk = 20000000;
279 	cons_sc.sc_byteswap = CLMPCC_BYTESWAP_LOW;
280 	cons_sc.sc_swaprtsdtr = 1;
281 	cons_sc.sc_iackhook = clmpcc_pcctwo_consiackhook;
282 	cons_sc.sc_vector_base = PCCTWO_SCC_VECBASE;
283 	cons_sc.sc_rpilr = 0x03;
284 	cons_sc.sc_tpilr = 0x02;
285 	cons_sc.sc_mpilr = 0x01;
286 
287 	clmpcc_cnattach(&cons_sc, 0, 9600);
288 }
289