summaryrefslogtreecommitdiff
path: root/sys/dev/sbus/sio16.c
blob: 31550af6d236d658b1b5f1ff66f148a4fcbd6e48 (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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
/*	$NetBSD: sio16.c,v 1.28 2021/12/07 22:13:56 andvar Exp $	*/

/*
 * Copyright (c) 1998, 2001 Matthew R. Green
 * All rights reserved.
 *
 * 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 AUTHOR ``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 AUTHOR 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.
 */

/*
 * aurora technologies nova16 driver.  this board is an sbus card with
 * an external 16 port serial box.  there are two cirrus logic cd180
 * 8 port serial chips used in the implementation.
 *
 * thanks go to Oliver Aldulea <oli@morcov.bv.ro> for writing the
 * linux driver of this that helped clear up a couple of issues.
 */

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sio16.c,v 1.28 2021/12/07 22:13:56 andvar Exp $");

#include <sys/param.h>
#include <sys/conf.h>
#include <sys/device.h>
#include <sys/systm.h>

#include <machine/autoconf.h>

#include <dev/ic/cd18xxvar.h>
#include <dev/ic/cd18xxreg.h>

#include "ioconf.h"
#include "locators.h"

/* 1600se configuration register bits */
#define SIO16_CONFIGREG_ENABLE_IO    8
#define SIO16_CONFIGREG_ENABLE_IRQ   4

/* 1600se interrupt ackknowledge register bytes */
#define	SIO16_MINT_ACK		1	/* modem interrupt acknowledge */
#define	SIO16_TINT_ACK		2	/* tx interrupt acknowledge */
#define	SIO16_RINT_ACK		3	/* rx interrupt acknowledge */

/*
 * device cfattach and cfdriver definitions, plus the routine we pass
 * to the cd18xx code or interrupt acknowledgement.
 */
static int	sio16_match(device_t, cfdata_t, void *);
static void	sio16_attach(device_t, device_t, void *);
static u_char	sio16_ackfunc(void *, int who);

/*
 * define the sio16 per-device softc.
 */
struct sio16_softc {
	device_t sc_dev;

	/* sbus information */
	bus_space_tag_t	sc_tag;			/* bus tag for below */
	bus_space_handle_t sc_configreg;	/* configuration register */
	bus_space_handle_t sc_reg[2];		/* cd180 register sets */
	bus_space_handle_t sc_ack;		/* interrupt acknowledgement */
#define	SIO16_1600SE	0x00000001

	u_int           sc_clk;

	/* cd180 information */
	int		sc_ncd180;

};

CFATTACH_DECL_NEW(siosixteen, sizeof(struct sio16_softc),
    sio16_match, sio16_attach, NULL, NULL);

struct sio16_attach_args {
	bus_space_tag_t		cd_tag;
	bus_space_handle_t	cd_handle;
	u_char			(*cd_ackfunc)(void *, int);
	void			*cd_ackfunc_arg;
	u_int			cd_osc;
};

/*
 * device match routine:  is there an sio16 present?
 *
 * note that we can not put "sio16" in the cfdriver, as this is an
 * illegal name, so we have to hard code it here.
 */
#define	SIO16_ROM_NAME	"sio16"
int
sio16_match(device_t parent, cfdata_t cf, void *aux)
{
	struct sbus_attach_args *sa = aux;

	/* does the prom think i'm an sio16? */
	if (strcmp(SIO16_ROM_NAME, sa->sa_name) != 0)
		return (0);

	return (1);
}

/*
 * device attach routine:  go attach all sub devices.
 */
void
sio16_attach(device_t parent, device_t self, void *aux)
{
	struct sbus_attach_args *sa = aux;
	struct sio16_softc *sc = device_private(self);
	bus_space_handle_t h;
	char *mode, *model;
	int i;

	sc->sc_dev = self;

	if (sa->sa_nreg != 4)
		panic("sio16_attach: got %d registers instead of 4",
		    sa->sa_nreg);

	/* copy our bus tag, we will need it */
	sc->sc_tag = sa->sa_bustag;

	/*
	 * sio16 has 4 register mappings.  a single byte configuration
	 * register, 2 128 byte regions for the cd180 registers, and
	 * a 4 byte region for interrupt acknowledgement.
	 */
	if (sbus_bus_map(sa->sa_bustag,
			 sa->sa_reg[0].oa_space,
			 sa->sa_reg[0].oa_base,
			 sa->sa_reg[0].oa_size,
			 0, &h) != 0) {
		printf("%s at sbus: can not map registers 0\n",
		    device_xname(self));
		return;
	}
	sc->sc_configreg = h;
	if (sbus_bus_map(sa->sa_bustag,
			 sa->sa_reg[1].sbr_slot,
			 sa->sa_reg[1].sbr_offset,
			 sa->sa_reg[1].sbr_size,
			 0, &h) != 0) {
		printf("%s at sbus: can not map registers 1\n",
		    device_xname(self));
		return;
	}
	sc->sc_reg[0] = h;
	if (sbus_bus_map(sa->sa_bustag,
			 sa->sa_reg[2].sbr_slot,
			 sa->sa_reg[2].sbr_offset,
			 sa->sa_reg[2].sbr_size,
			 0, &h) != 0) {
		printf("%s at sbus: can not map registers 2\n",
		    device_xname(self));
		return;
	}
	sc->sc_reg[1] = h;
	if (sbus_bus_map(sa->sa_bustag,
			 sa->sa_reg[3].sbr_slot,
			 sa->sa_reg[3].sbr_offset,
			 sa->sa_reg[3].sbr_size,
			 0, &h) != 0) {
		printf("%s at sbus: can not map registers 3\n",
		    device_xname(self));
		return;
	}
	sc->sc_ack = h;

	mode = prom_getpropstring(sa->sa_node, "mode");
	if (mode)
		printf(", %s mode", mode);

	/* get the clock frequency */
	sc->sc_clk = prom_getpropint(sa->sa_node, "clk", 24000);

	model = prom_getpropstring(sa->sa_node, "model");
	if (model == 0) {
		printf(", no model property, bailing\n");
		return;
	}

	/* are we an 1600se? */
	if (strcmp(model, "1600se") == 0) {
		printf(", 16 channels");
		sc->sc_ncd180 = 2;
	} else {
		printf(", don't know model %s, bailing\n", model);
		return;
	}

	/* establish interrupt channel */
	(void)bus_intr_establish(sa->sa_bustag, sa->sa_pri, IPL_TTY,
	    cd18xx_hardintr, sc);

	/* reset the board, and turn on interrupts and I/O */
	bus_space_write_1(sa->sa_bustag, sc->sc_configreg, 0, 0);
	delay(100);
	bus_space_write_1(sa->sa_bustag, sc->sc_configreg, 0,
	    SIO16_CONFIGREG_ENABLE_IO | SIO16_CONFIGREG_ENABLE_IRQ |
	    (((sa->sa_pri) & 0x0f) >> 2));
	delay(10000);

	printf("\n");

	/* finally, configure the clcd's underneath */
	for (i = 0; i < sc->sc_ncd180; i++) {
		struct sio16_attach_args cd;

		cd.cd_tag = sa->sa_bustag;
		cd.cd_osc = sc->sc_clk * 100;
		cd.cd_handle = (bus_space_handle_t)sc->sc_reg[i];
		cd.cd_ackfunc = sio16_ackfunc;
		cd.cd_ackfunc_arg = sc;
		(void)config_found(self, (void *)&cd, NULL, CFARGS_NONE);
	}
}

/*
 * note that the addresses used in this function match those assigned
 * in clcd_attach() below, or the various service match routines.
 */
u_char
sio16_ackfunc(void *v, int who)
{
	struct sio16_softc *sc = v;
	bus_size_t addr;

	switch (who) {
	case CD18xx_INTRACK_RxINT:
	case CD18xx_INTRACK_REINT:
		addr = SIO16_RINT_ACK;
		break;
	case CD18xx_INTRACK_TxINT:
		addr = SIO16_TINT_ACK;
		break;
	case CD18xx_INTRACK_MxINT:
		addr = SIO16_MINT_ACK;
		break;
	default:
		panic("%s: sio16_ackfunc: unknown ackfunc %d",
		    device_xname(sc->sc_dev), who);
	}
	return (bus_space_read_1(sc->sc_tag, sc->sc_ack, addr));
}

/*
 * we attach two `clcd' instances per 1600se, that each call the
 * backend cd18xx driver for help.
 */
static int	clcd_match(device_t, cfdata_t, void *);
static void	clcd_attach(device_t, device_t, void *);

CFATTACH_DECL_NEW(clcd, sizeof(struct cd18xx_softc),
    clcd_match, clcd_attach, NULL, NULL);

static int
clcd_match(device_t parent, cfdata_t cf, void *aux)
{

	/* XXX */
	return 1;
}

static void
clcd_attach(device_t parent, device_t self, void *aux)
{
	struct cd18xx_softc *sc = device_private(self);
	struct sio16_attach_args *args = aux;

	sc->sc_dev = self;
	sc->sc_tag = args->cd_tag;
	sc->sc_handle = args->cd_handle;
	sc->sc_osc = args->cd_osc;
	sc->sc_ackfunc = args->cd_ackfunc;
	sc->sc_ackfunc_arg = args->cd_ackfunc_arg;
	sc->sc_msmr = SIO16_MINT_ACK;
	sc->sc_tsmr = SIO16_TINT_ACK;
	sc->sc_rsmr = SIO16_RINT_ACK;

	/* call the common code */
	cd18xx_attach(sc);
}