1 /* $NetBSD: zs.c,v 1.4 2008/03/29 19:15:34 tsutsui Exp $ */
4 * Copyright (c) 1996, 2005 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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.
33 * Zilog Z8530 Dual UART driver (machine-dependent part)
35 * Runs two serial lines per chip using slave drivers.
36 * Plain tty/async lines use the zs_async slave.
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: zs.c,v 1.4 2008/03/29 19:15:34 tsutsui Exp $");
44 #include <sys/param.h>
45 #include <sys/device.h>
47 #include <sys/systm.h>
50 #include <machine/z8530var.h>
51 #include <dev/ic/z8530reg.h>
55 /* console status for consinit() */
56 static struct zs_chanstate zs_conscs_store
;
57 struct zs_chanstate
*zs_conscs
= &zs_conscs_store
;
61 * Some warts needed by z8530tty.c -
62 * The default parity REALLY needs to be the same as the PROM uses,
63 * or you can not see messages done with printf during boot-up...
65 int zs_def_cflag
= (CREAD
| CS8
| HUPCL
);
68 zs_print(void *aux
, const char *name
)
70 struct zsc_attach_args
*args
= aux
;
73 aprint_normal("%s: ", name
);
75 if (args
->channel
!= -1)
76 aprint_normal(" channel %d", args
->channel
);
84 struct zsc_softc
*zsc
;
88 rval
= zsc_intr_hard(zsc
);
89 if (zsc
->zsc_cs
[0]->cs_softreq
|| zsc
->zsc_cs
[1]->cs_softreq
)
90 softint_schedule(zsc
->zsc_si
);
96 * Compute the current baud rate given a ZS channel.
99 zs_get_speed(struct zs_chanstate
*cs
)
103 tconst
= zs_read_reg(cs
, 12);
104 tconst
|= zs_read_reg(cs
, 13) << 8;
105 return TCONST_TO_BPS(cs
->cs_brg_clk
, tconst
);
109 * MD functions for setting the baud rate and control modes.
112 zs_set_speed(struct zs_chanstate
*cs
, int bps
)
114 int tconst
, real_bps
;
120 if (cs
->cs_brg_clk
== 0)
121 panic("zs_set_speed");
124 tconst
= BPS_TO_TCONST(cs
->cs_brg_clk
, bps
);
128 /* Convert back to make sure we can do it. */
129 real_bps
= TCONST_TO_BPS(cs
->cs_brg_clk
, tconst
);
131 /* XXX - Allow some tolerance here? */
135 cs
->cs_preg
[12] = tconst
;
136 cs
->cs_preg
[13] = tconst
>> 8;
138 /* Caller will stuff the pending registers. */
143 zs_set_modes(struct zs_chanstate
*cs
, int cflag
)
148 * Output hardware flow control on the chip is horrendous:
149 * if carrier detect drops, the receiver is disabled, and if
150 * CTS drops, the transmitter is stoped IN MID CHARACTER!
151 * Therefore, NEVER set the HFC bit, and instead use the
152 * status interrupt to detect CTS changes.
156 if ((cflag
& (CLOCAL
| MDMBUF
)) != 0) {
158 if ((cflag
& MDMBUF
) == 0)
159 cs
->cs_rr0_pps
= ZSRR0_DCD
;
161 cs
->cs_rr0_dcd
= ZSRR0_DCD
;
162 if ((cflag
& CRTSCTS
) != 0) {
163 cs
->cs_wr5_dtr
= ZSWR5_DTR
;
164 cs
->cs_wr5_rts
= ZSWR5_RTS
;
165 cs
->cs_rr0_cts
= ZSRR0_CTS
;
166 } else if ((cflag
& MDMBUF
) != 0) {
168 cs
->cs_wr5_rts
= ZSWR5_DTR
;
169 cs
->cs_rr0_cts
= ZSRR0_DCD
;
171 cs
->cs_wr5_dtr
= ZSWR5_DTR
| ZSWR5_RTS
;
177 /* Caller will stuff the pending registers. */
182 * Read or write the chip with suitable delays.
185 zs_read_reg(struct zs_chanstate
*cs
, uint8_t reg
)
189 *cs
->cs_reg_csr
= reg
;
191 val
= *cs
->cs_reg_csr
;
197 zs_write_reg(struct zs_chanstate
*cs
, uint8_t reg
, uint8_t val
)
200 *cs
->cs_reg_csr
= reg
;
202 *cs
->cs_reg_csr
= val
;
207 zs_read_csr(struct zs_chanstate
*cs
)
211 val
= *cs
->cs_reg_csr
;
217 zs_write_csr(struct zs_chanstate
*cs
, uint8_t val
)
220 *cs
->cs_reg_csr
= val
;
225 zs_read_data(struct zs_chanstate
*cs
)
229 val
= *cs
->cs_reg_data
;
235 zs_write_data(struct zs_chanstate
*cs
, uint8_t val
)
238 *cs
->cs_reg_data
= val
;
242 zs_abort(struct zs_chanstate
*cs
)
256 struct zs_chanstate
*cs
= arg
;
261 /* Wait for a character to arrive. */
263 rr0
= *cs
->cs_reg_csr
;
265 } while ((rr0
& ZSRR0_RX_READY
) == 0);
267 c
= *cs
->cs_reg_data
;
272 * This could be used by the kd driver to read scan codes,
273 * so don't translate '\r' ==> '\n' here...
279 * Polled output char.
282 zs_putc(void *arg
, int c
)
284 struct zs_chanstate
*cs
= arg
;
289 /* Wait for transmitter to become ready. */
291 rr0
= *cs
->cs_reg_csr
;
293 } while ((rr0
& ZSRR0_TX_READY
) == 0);
295 *cs
->cs_reg_data
= c
;
304 return zs_getc((void *)zs_conscs
);
308 zscnputc(dev_t dev
, int c
)
311 zs_putc((void *)zs_conscs
, c
);