xref: /netbsd-src/sys/dev/mvme/clmpcc_pcctwo.c (revision cd22f25e6f6d1cc1f197fe8c5468a80f51d1c4e1)
1 /*	$NetBSD: clmpcc_pcctwo.c,v 1.15 2008/04/28 20:23:53 martin 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  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 /*
33  * Cirrus Logic CD2401 4-channel serial chip. PCCchip2 Front-end.
34  */
35 
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: clmpcc_pcctwo.c,v 1.15 2008/04/28 20:23:53 martin Exp $");
38 
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/proc.h>
42 #include <sys/device.h>
43 #include <sys/conf.h>
44 #include <sys/file.h>
45 #include <sys/ioctl.h>
46 #include <sys/tty.h>
47 #include <sys/time.h>
48 #include <sys/kernel.h>
49 #include <sys/syslog.h>
50 
51 #include <dev/cons.h>
52 
53 #include <sys/cpu.h>
54 #include <sys/bus.h>
55 #include <sys/intr.h>
56 
57 #include <dev/ic/clmpccvar.h>
58 
59 #include <dev/mvme/pcctwovar.h>
60 #include <dev/mvme/pcctworeg.h>
61 
62 /* XXXXSCW: Fixme */
63 #ifdef MVME68K
64 #include <mvme68k/dev/mainbus.h>
65 #else
66 #error Need consiack hook
67 #endif
68 
69 
70 /* Definition of the driver for autoconfig. */
71 int clmpcc_pcctwo_match(struct device *, struct cfdata *, void *);
72 void clmpcc_pcctwo_attach(struct device *, struct device *, void *);
73 void clmpcc_pcctwo_iackhook(struct clmpcc_softc *, int);
74 void clmpcc_pcctwo_consiackhook(struct clmpcc_softc *, int);
75 
76 CFATTACH_DECL(clmpcc_pcctwo, sizeof(struct clmpcc_softc),
77     clmpcc_pcctwo_match, clmpcc_pcctwo_attach, NULL, NULL);
78 
79 extern struct cfdriver clmpcc_cd;
80 
81 extern const struct cdevsw clmpcc_cdevsw;
82 
83 /*
84  * For clmpcccn*()
85  */
86 cons_decl(clmpcc);
87 
88 
89 /*
90  * Is the CD2401 chip present?
91  */
92 int
93 clmpcc_pcctwo_match(parent, cf, aux)
94 	struct device *parent;
95 	struct cfdata *cf;
96 	void *aux;
97 {
98 	struct pcctwo_attach_args *pa;
99 
100 	pa = aux;
101 
102 	if (strcmp(pa->pa_name, clmpcc_cd.cd_name))
103 		return (0);
104 
105 	pa->pa_ipl = cf->pcctwocf_ipl;
106 
107 	return (1);
108 }
109 
110 /*
111  * Attach a found CD2401.
112  */
113 void
114 clmpcc_pcctwo_attach(parent, self, aux)
115 	struct device *parent;
116 	struct device *self;
117 	void *aux;
118 {
119 	struct clmpcc_softc *sc;
120 	struct pcctwo_attach_args *pa = aux;
121 	int level = pa->pa_ipl;
122 
123 	sc = device_private(self);
124 	level = pa->pa_ipl;
125 	sc->sc_iot = pa->pa_bust;
126 	bus_space_map(pa->pa_bust, pa->pa_offset, 0x100, 0, &sc->sc_ioh);
127 
128 	sc->sc_clk = 20000000;
129 	sc->sc_byteswap = CLMPCC_BYTESWAP_LOW;
130 	sc->sc_swaprtsdtr = 1;
131 	sc->sc_iackhook = clmpcc_pcctwo_iackhook;
132 	sc->sc_vector_base = PCCTWO_SCC_VECBASE;
133 	sc->sc_rpilr = 0x03;
134 	sc->sc_tpilr = 0x02;
135 	sc->sc_mpilr = 0x01;
136 	sc->sc_evcnt = pcctwointr_evcnt(level);
137 
138 	/* Do common parts of CD2401 configuration. */
139 	clmpcc_attach(sc);
140 
141 	/* Hook the interrupts */
142 	pcctwointr_establish(PCCTWOV_SCC_RX, clmpcc_rxintr, level, sc, NULL);
143 	pcctwointr_establish(PCCTWOV_SCC_RX_EXCEP, clmpcc_rxintr, level, sc,
144 	    NULL);
145 	pcctwointr_establish(PCCTWOV_SCC_TX, clmpcc_txintr, level, sc, NULL);
146 	pcctwointr_establish(PCCTWOV_SCC_MODEM, clmpcc_mdintr, level, sc, NULL);
147 }
148 
149 void
150 clmpcc_pcctwo_iackhook(sc, which)
151 	struct clmpcc_softc *sc;
152 	int which;
153 {
154 	bus_size_t offset;
155 	volatile u_char foo;
156 
157 	switch (which) {
158 	case CLMPCC_IACK_MODEM:
159 		offset = PCC2REG_SCC_MODEM_PIACK;
160 		break;
161 
162 	case CLMPCC_IACK_RX:
163 		offset = PCC2REG_SCC_RX_PIACK;
164 		break;
165 
166 	case CLMPCC_IACK_TX:
167 		offset = PCC2REG_SCC_TX_PIACK;
168 		break;
169 	default:
170 #ifdef DEBUG
171 		printf("%s: Invalid IACK number '%d'\n",
172 		    device_xname(&sc->sc_dev), which);
173 #endif
174 		panic("clmpcc_pcctwo_iackhook %d", which);
175 	}
176 
177 	foo = pcc2_reg_read(sys_pcctwo, offset);
178 }
179 
180 /*
181  * This routine is only used prior to clmpcc_attach() being called
182  */
183 void
184 clmpcc_pcctwo_consiackhook(sc, which)
185 	struct clmpcc_softc *sc;
186 	int which;
187 {
188 	bus_space_handle_t bush;
189 	bus_size_t offset;
190 	volatile u_char foo;
191 
192 	switch (which) {
193 	case CLMPCC_IACK_MODEM:
194 		offset = PCC2REG_SCC_MODEM_PIACK;
195 		break;
196 
197 	case CLMPCC_IACK_RX:
198 		offset = PCC2REG_SCC_RX_PIACK;
199 		break;
200 
201 	case CLMPCC_IACK_TX:
202 		offset = PCC2REG_SCC_TX_PIACK;
203 		break;
204 	default:
205 #ifdef DEBUG
206 		printf("%s: Invalid IACK number '%d'\n",
207 		    device_xname(&sc->sc_dev), which);
208 		panic("clmpcc_pcctwo_consiackhook");
209 #endif
210 		panic("clmpcc_pcctwo_iackhook %d", which);
211 	}
212 
213 #ifdef MVME68K
214 	/*
215 	 * We need to fake the tag and handle since 'sys_pcctwo' will
216 	 * be NULL during early system startup...
217 	 */
218 	bush = (bus_space_handle_t) & (intiobase[MAINBUS_PCCTWO_OFFSET +
219 		PCCTWO_REG_OFF]);
220 
221 	foo = bus_space_read_1(&_mainbus_space_tag, bush, offset);
222 #else
223 #error Need consiack hook
224 #endif
225 }
226 
227 
228 /****************************************************************
229  * Console support functions (MVME PCCchip2 specific!)
230  ****************************************************************/
231 
232 /*
233  * Check for CD2401 console.
234  */
235 void
236 clmpcccnprobe(cp)
237 	struct consdev *cp;
238 {
239 	int maj;
240 
241 #if defined(MVME68K)
242 	if (machineid != MVME_167 && machineid != MVME_177)
243 #elif defined(MVME88K)
244 	if (machineid != MVME_187)
245 #endif
246 	{
247 		cp->cn_pri = CN_DEAD;
248 		return;
249 	}
250 
251 	/*
252 	 * Locate the major number
253 	 */
254 	maj = cdevsw_lookup_major(&clmpcc_cdevsw);
255 
256 	/* Initialize required fields. */
257 	cp->cn_dev = makedev(maj, 0);
258 	cp->cn_pri = CN_NORMAL;
259 }
260 
261 void
262 clmpcccninit(cp)
263 	struct consdev *cp;
264 {
265 	static struct clmpcc_softc cons_sc;
266 
267 	cons_sc.sc_iot = &_mainbus_space_tag;
268 	bus_space_map(&_mainbus_space_tag,
269 	    intiobase_phys + MAINBUS_PCCTWO_OFFSET + PCCTWO_SCC_OFF,
270 	    PCC2REG_SIZE, 0, &cons_sc.sc_ioh);
271 	cons_sc.sc_clk = 20000000;
272 	cons_sc.sc_byteswap = CLMPCC_BYTESWAP_LOW;
273 	cons_sc.sc_swaprtsdtr = 1;
274 	cons_sc.sc_iackhook = clmpcc_pcctwo_consiackhook;
275 	cons_sc.sc_vector_base = PCCTWO_SCC_VECBASE;
276 	cons_sc.sc_rpilr = 0x03;
277 	cons_sc.sc_tpilr = 0x02;
278 	cons_sc.sc_mpilr = 0x01;
279 
280 	clmpcc_cnattach(&cons_sc, 0, 9600);
281 }
282