summaryrefslogtreecommitdiff
path: root/sys/dev/mvme/clmpcc_pcctwo.c
blob: 36a800ebae69331a3b59a315ee616851b8ebab71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
/*	$NetBSD: clmpcc_pcctwo.c,v 1.20 2014/03/25 15:52:16 christos Exp $	*/

/*-
 * Copyright (c) 1999, 2002 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Steve C. Woodford.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * Cirrus Logic CD2401 4-channel serial chip. PCCchip2 Front-end.
 */

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: clmpcc_pcctwo.c,v 1.20 2014/03/25 15:52:16 christos Exp $");

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/proc.h>
#include <sys/device.h>
#include <sys/conf.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <sys/tty.h>
#include <sys/time.h>
#include <sys/kernel.h>
#include <sys/syslog.h>

#include <dev/cons.h>

#include <sys/cpu.h>
#include <sys/bus.h>
#include <sys/intr.h>

#include <dev/ic/clmpccvar.h>

#include <dev/mvme/pcctwovar.h>
#include <dev/mvme/pcctworeg.h>

/* XXXXSCW: Fixme */
#ifdef MVME68K
#include <mvme68k/dev/mainbus.h>
#else
#error Need consiack hook
#endif


/* Definition of the driver for autoconfig. */
int clmpcc_pcctwo_match(device_t, cfdata_t, void *);
void clmpcc_pcctwo_attach(device_t, device_t, void *);
void clmpcc_pcctwo_iackhook(struct clmpcc_softc *, int);
void clmpcc_pcctwo_consiackhook(struct clmpcc_softc *, int);

CFATTACH_DECL_NEW(clmpcc_pcctwo, sizeof(struct clmpcc_softc),
    clmpcc_pcctwo_match, clmpcc_pcctwo_attach, NULL, NULL);

extern struct cfdriver clmpcc_cd;

extern const struct cdevsw clmpcc_cdevsw;

/*
 * For clmpcccn*()
 */
cons_decl(clmpcc);


/*
 * Is the CD2401 chip present?
 */
int
clmpcc_pcctwo_match(device_t parent, cfdata_t cf, void *aux)
{
	struct pcctwo_attach_args *pa;

	pa = aux;

	if (strcmp(pa->pa_name, clmpcc_cd.cd_name))
		return (0);

	pa->pa_ipl = cf->pcctwocf_ipl;

	return (1);
}

/*
 * Attach a found CD2401.
 */
void
clmpcc_pcctwo_attach(device_t parent, device_t self, void *aux)
{
	struct clmpcc_softc *sc;
	struct pcctwo_attach_args *pa = aux;
	int level = pa->pa_ipl;

	sc = device_private(self);
	sc->sc_dev = self;
	level = pa->pa_ipl;
	sc->sc_iot = pa->pa_bust;
	bus_space_map(pa->pa_bust, pa->pa_offset, 0x100, 0, &sc->sc_ioh);

	sc->sc_clk = 20000000;
	sc->sc_byteswap = CLMPCC_BYTESWAP_LOW;
	sc->sc_swaprtsdtr = 1;
	sc->sc_iackhook = clmpcc_pcctwo_iackhook;
	sc->sc_vector_base = PCCTWO_SCC_VECBASE;
	sc->sc_rpilr = 0x03;
	sc->sc_tpilr = 0x02;
	sc->sc_mpilr = 0x01;
	sc->sc_evcnt = pcctwointr_evcnt(level);

	/* Do common parts of CD2401 configuration. */
	clmpcc_attach(sc);

	/* Hook the interrupts */
	pcctwointr_establish(PCCTWOV_SCC_RX, clmpcc_rxintr, level, sc, NULL);
	pcctwointr_establish(PCCTWOV_SCC_RX_EXCEP, clmpcc_rxintr, level, sc,
	    NULL);
	pcctwointr_establish(PCCTWOV_SCC_TX, clmpcc_txintr, level, sc, NULL);
	pcctwointr_establish(PCCTWOV_SCC_MODEM, clmpcc_mdintr, level, sc, NULL);
}

void
clmpcc_pcctwo_iackhook(struct clmpcc_softc *sc, int which)
{
	bus_size_t offset;
	volatile u_char foo;

	switch (which) {
	case CLMPCC_IACK_MODEM:
		offset = PCC2REG_SCC_MODEM_PIACK;
		break;

	case CLMPCC_IACK_RX:
		offset = PCC2REG_SCC_RX_PIACK;
		break;

	case CLMPCC_IACK_TX:
		offset = PCC2REG_SCC_TX_PIACK;
		break;
	default:
#ifdef DEBUG
		printf("%s: Invalid IACK number '%d'\n",
		    device_xname(sc->sc_dev), which);
#endif
		panic("clmpcc_pcctwo_iackhook %d", which);
	}

	foo = pcc2_reg_read(sys_pcctwo, offset);
	__USE(foo);
}

/*
 * This routine is only used prior to clmpcc_attach() being called
 */
void
clmpcc_pcctwo_consiackhook(struct clmpcc_softc *sc, int which)
{
	bus_space_handle_t bush;
	bus_size_t offset;
	volatile u_char foo;

	switch (which) {
	case CLMPCC_IACK_MODEM:
		offset = PCC2REG_SCC_MODEM_PIACK;
		break;

	case CLMPCC_IACK_RX:
		offset = PCC2REG_SCC_RX_PIACK;
		break;

	case CLMPCC_IACK_TX:
		offset = PCC2REG_SCC_TX_PIACK;
		break;
	default:
#ifdef DEBUG
		printf("%s: Invalid IACK number '%d'\n",
		    device_xname(sc->sc_dev), which);
		panic("clmpcc_pcctwo_consiackhook");
#endif
		panic("clmpcc_pcctwo_iackhook %d", which);
	}

#ifdef MVME68K
	/*
	 * We need to fake the tag and handle since 'sys_pcctwo' will
	 * be NULL during early system startup...
	 */
	bush = (bus_space_handle_t) & (intiobase[MAINBUS_PCCTWO_OFFSET +
		PCCTWO_REG_OFF]);

	foo = bus_space_read_1(&_mainbus_space_tag, bush, offset);
	__USE(foo);
#else
#error Need consiack hook
#endif
}


/****************************************************************
 * Console support functions (MVME PCCchip2 specific!)
 ****************************************************************/

/*
 * Check for CD2401 console.
 */
void
clmpcccnprobe(struct consdev *cp)
{
	int maj;

#if defined(MVME68K)
	if (machineid != MVME_167 && machineid != MVME_177)
#elif defined(MVME88K)
	if (machineid != MVME_187)
#endif
	{
		cp->cn_pri = CN_DEAD;
		return;
	}

	/*
	 * Locate the major number
	 */
	maj = cdevsw_lookup_major(&clmpcc_cdevsw);

	/* Initialize required fields. */
	cp->cn_dev = makedev(maj, 0);
	cp->cn_pri = CN_NORMAL;
}

void
clmpcccninit(struct consdev *cp)
{
	static struct clmpcc_softc cons_sc;

	cons_sc.sc_iot = &_mainbus_space_tag;
	bus_space_map(&_mainbus_space_tag,
	    intiobase_phys + MAINBUS_PCCTWO_OFFSET + PCCTWO_SCC_OFF,
	    PCC2REG_SIZE, 0, &cons_sc.sc_ioh);
	cons_sc.sc_clk = 20000000;
	cons_sc.sc_byteswap = CLMPCC_BYTESWAP_LOW;
	cons_sc.sc_swaprtsdtr = 1;
	cons_sc.sc_iackhook = clmpcc_pcctwo_consiackhook;
	cons_sc.sc_vector_base = PCCTWO_SCC_VECBASE;
	cons_sc.sc_rpilr = 0x03;
	cons_sc.sc_tpilr = 0x02;
	cons_sc.sc_mpilr = 0x01;

	clmpcc_cnattach(&cons_sc, 0, 9600);
}