1 /* $NetBSD: zs_any.c,v 1.17 2008/03/29 19:15:35 tsutsui Exp $ */
4 * Copyright (c) 1996 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Gordon W. Ross and Matthew Fredette.
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.
37 * Sun keyboard/mouse uses the zs_kbd/zs_ms slaves.
40 #include <sys/cdefs.h>
41 __KERNEL_RCSID(0, "$NetBSD: zs_any.c,v 1.17 2008/03/29 19:15:35 tsutsui Exp $");
45 #include <sys/param.h>
46 #include <sys/systm.h>
48 #include <sys/device.h>
50 #include <sys/ioctl.h>
51 #include <sys/kernel.h>
55 #include <sys/syslog.h>
57 #include <machine/autoconf.h>
58 #include <machine/bus.h>
59 #include <machine/z8530var.h>
62 #include <uvm/uvm_extern.h>
64 #include <machine/idprom.h>
65 #include <machine/pmap.h>
66 #include <sun2/dev/cons.h>
69 #include <sun2/sun2/machdep.h>
70 #include <dev/ic/z8530reg.h>
71 #include <dev/sun/kbd_reg.h>
73 /****************************************************************
75 ****************************************************************/
77 /* Definition of the driver for autoconfig. */
78 static int zs_any_match(device_t
, cfdata_t
, void *);
79 static void zs_any_attach(device_t
, device_t
, void *);
81 CFATTACH_DECL_NEW(zs_obio
, sizeof(struct zsc_softc
),
82 zs_any_match
, zs_any_attach
, NULL
, NULL
);
84 CFATTACH_DECL_NEW(zs_obmem
, sizeof(struct zsc_softc
),
85 zs_any_match
, zs_any_attach
, NULL
, NULL
);
87 CFATTACH_DECL_NEW(zs_mbmem
, sizeof(struct zsc_softc
),
88 zs_any_match
, zs_any_attach
, NULL
, NULL
);
91 * Is the zs chip present?
94 zs_any_match(device_t parent
, cfdata_t cf
, void *aux
)
96 struct mainbus_attach_args
*ma
= aux
;
97 bus_space_handle_t bh
;
100 /* Make sure there is something there... */
101 if (bus_space_map(ma
->ma_bustag
, ma
->ma_paddr
, sizeof(struct zsdevice
),
104 matched
= (bus_space_peek_1(ma
->ma_bustag
, bh
, 0, NULL
) == 0);
105 bus_space_unmap(ma
->ma_bustag
, bh
, sizeof(struct zsdevice
));
109 /* Default interrupt priority (always splbio==2) */
110 if (ma
->ma_pri
== -1)
111 ma
->ma_pri
= ZSHARD_PRI
;
120 zs_any_attach(device_t parent
, device_t self
, void *aux
)
122 struct zsc_softc
*zsc
= device_private(self
);
123 struct mainbus_attach_args
*ma
= aux
;
124 bus_space_handle_t bh
;
127 zsc
->zsc_bustag
= ma
->ma_bustag
;
128 zsc
->zsc_dmatag
= ma
->ma_dmatag
;
129 /* XXX device_unit() abuse */
130 zsc
->zsc_promunit
= device_unit(self
);
133 /* Map in the device. */
134 if (bus_space_map(ma
->ma_bustag
, ma
->ma_paddr
, sizeof(struct zsdevice
),
135 BUS_SPACE_MAP_LINEAR
, &bh
)) {
137 panic("%s: can't map", __func__
);
140 /* This is where we break the bus_space(9) abstraction: */
141 zs_attach(zsc
, (void *)bh
, ma
->ma_pri
);
145 zs_console_flags(int promunit
, int node
, int channel
)
147 int cookie
, flags
= 0;
150 * Use `promunit' and `channel' to derive the PROM
151 * stdio handles that correspond to this device.
154 cookie
= PROMDEV_TTYA
+ channel
;
155 else if (promunit
== 1 && channel
== 0)
156 cookie
= PROMDEV_KBD
;
161 * We have the console keyboard only if it's a Sun-2
162 * keyboard or better. (i.e., not a Sun-1 parallel kbd).
164 if (cookie
== prom_stdin() &&
165 (cookie
!= PROMDEV_KBD
|| prom_kbdid() >= KB_SUN2
))
166 flags
|= ZS_HWFLAG_CONSOLE_INPUT
;
169 * Prevent the keyboard from matching the output device
170 * (note that PROMDEV_KBD == PROMDEV_SCREEN == 0!).
172 if (cookie
!= PROMDEV_KBD
&& cookie
== prom_stdout())
173 flags
|= ZS_HWFLAG_CONSOLE_OUTPUT
;
180 * Find a zs mapped by the PROM. Currently this only works to find
184 zs_find_prom(int unit
)
193 * The physical address of zs0 is model-dependent.
195 zs0_phys
= (cpu_machine_id
== ID_SUN2_120
? 0x002000 : 0x7f2000);
196 if (find_prom_map(zs0_phys
, PMAP_OBIO
, sizeof(struct zsdevice
), &va
))