2 * Copyright (c) 1999 FreeBSD(98) Porting Team.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer as
10 * the first lines of this file unmodified.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include "opt_syscons.h"
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/kernel.h>
34 #include <sys/module.h>
37 #include <sys/consio.h>
38 #include <sys/sysctl.h>
40 #include <machine/clock.h>
41 #include <machine/ppireg.h>
42 #include <machine/timerreg.h>
44 #include <pc98/pc98/pc98_machdep.h>
46 #include <dev/syscons/syscons.h>
48 #include <isa/isavar.h>
50 static devclass_t sc_devclass;
52 static sc_softc_t main_softc;
53 #ifdef SC_NO_SUSPEND_VTYSWITCH
54 static int sc_no_suspend_vtswitch = 1;
56 static int sc_no_suspend_vtswitch = 0;
58 static int sc_cur_scr;
60 TUNABLE_INT("hw.syscons.sc_no_suspend_vtswitch", (int *)&sc_no_suspend_vtswitch);
61 SYSCTL_DECL(_hw_syscons);
62 SYSCTL_INT(_hw_syscons, OID_AUTO, sc_no_suspend_vtswitch, CTLFLAG_RW,
63 &sc_no_suspend_vtswitch, 0, "Disable VT switch before suspend.");
66 scidentify (driver_t *driver, device_t parent)
68 BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE, "sc", 0);
75 if (isa_get_vendorid(dev))
78 device_set_desc(dev, "System console");
79 return sc_probe_unit(device_get_unit(dev), device_get_flags(dev));
83 scattach(device_t dev)
85 return sc_attach_unit(device_get_unit(dev), device_get_flags(dev));
89 scsuspend(device_t dev)
96 if (sc->cur_scp == NULL)
99 sc_cur_scr = sc->cur_scp->index;
101 if (sc_no_suspend_vtswitch)
105 sc_switch_scr(sc, 0);
106 if (!sc->switch_in_progress) {
109 pause("scsuspend", hz);
116 scresume(device_t dev)
120 if (sc_no_suspend_vtswitch)
124 sc_switch_scr(sc, sc_cur_scr);
132 return devclass_get_maxunit(sc_devclass);
136 *sc_get_softc(int unit, int flags)
142 if (flags & SC_KERNEL_CONSOLE) {
143 /* FIXME: clear if it is wired to another unit! */
146 sc = (sc_softc_t *)device_get_softc(devclass_get_device(sc_devclass, unit));
151 if (!(sc->flags & SC_INIT_DONE)) {
154 sc->mouse_char = SC_MOUSE_CHAR;
160 *sc_find_softc(struct video_adapter *adp, struct keyboard *kbd)
167 if (((adp == NULL) || (adp == sc->adp))
168 && ((kbd == NULL) || (kbd == sc->kbd)))
170 units = devclass_get_maxunit(sc_devclass);
171 for (i = 0; i < units; ++i) {
172 sc = (sc_softc_t *)device_get_softc(devclass_get_device(sc_devclass, i));
175 if (((adp == NULL) || (adp == sc->adp))
176 && ((kbd == NULL) || (kbd == sc->kbd)))
183 sc_get_cons_priority(int *unit, int *flags)
189 for (u = 0; u < 16; u++) {
190 if (resource_disabled(SC_DRIVER_NAME, u))
192 if (resource_string_value(SC_DRIVER_NAME, u, "at", &at) != 0)
194 if (resource_int_value(SC_DRIVER_NAME, u, "flags", &f) != 0)
196 if (f & SC_KERNEL_CONSOLE) {
197 /* the user designates this unit to be the console */
203 /* ...otherwise remember the first found unit */
216 sc_get_bios_values(bios_values_t *values)
218 values->cursor_start = 15;
219 values->cursor_end = 16;
220 values->shift_state = 0;
221 if (pc98_machine_type & M_8M)
222 values->bell_pitch = BELL_PITCH_8M;
224 values->bell_pitch = BELL_PITCH_5M;
232 /* enable counter 1 */
234 /* set command for counter 1, 2 byte write */
235 if (timer_spkr_acquire())
238 spkr_set_pitch(timer_freq / herz);
240 /* disable counter 1 */
242 timer_spkr_release();
247 static device_method_t sc_methods[] = {
248 DEVMETHOD(device_identify, scidentify),
249 DEVMETHOD(device_probe, scprobe),
250 DEVMETHOD(device_attach, scattach),
251 DEVMETHOD(device_suspend, scsuspend),
252 DEVMETHOD(device_resume, scresume),
256 static driver_t sc_driver = {
262 DRIVER_MODULE(sc, isa, sc_driver, sc_devclass, 0, 0);