syscons_cbus.c revision 146211
1/*- 2 * Copyright (c) 1999 FreeBSD(98) Porting Team. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 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. 14 * 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. 25 * 26 * $FreeBSD: head/sys/pc98/cbus/syscons_cbus.c 146211 2005-05-14 09:10:02Z nyan $ 27 */ 28 29#include "opt_syscons.h" 30 31#include <sys/param.h> 32#include <sys/systm.h> 33#include <sys/kernel.h> 34#include <sys/module.h> 35#include <sys/bus.h> 36#include <sys/cons.h> 37#include <sys/consio.h> 38#include <sys/sysctl.h> 39 40#include <machine/clock.h> 41#include <machine/ppireg.h> 42#include <machine/timerreg.h> 43 44#include <pc98/cbus/cbus.h> 45#include <pc98/pc98/pc98_machdep.h> 46 47#include <dev/syscons/syscons.h> 48 49#include <isa/isavar.h> 50 51static devclass_t sc_devclass; 52 53static sc_softc_t main_softc; 54#ifdef SC_NO_SUSPEND_VTYSWITCH 55static int sc_no_suspend_vtswitch = 1; 56#else 57static int sc_no_suspend_vtswitch = 0; 58#endif 59static int sc_cur_scr; 60 61TUNABLE_INT("hw.syscons.sc_no_suspend_vtswitch", (int *)&sc_no_suspend_vtswitch); 62SYSCTL_DECL(_hw_syscons); 63SYSCTL_INT(_hw_syscons, OID_AUTO, sc_no_suspend_vtswitch, CTLFLAG_RW, 64 &sc_no_suspend_vtswitch, 0, "Disable VT switch before suspend."); 65 66static void 67scidentify (driver_t *driver, device_t parent) 68{ 69 BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE, "sc", 0); 70} 71 72static int 73scprobe(device_t dev) 74{ 75 /* No pnp support */ 76 if (isa_get_vendorid(dev)) 77 return (ENXIO); 78 79 device_set_desc(dev, "System console"); 80 return sc_probe_unit(device_get_unit(dev), device_get_flags(dev)); 81} 82 83static int 84scattach(device_t dev) 85{ 86 return sc_attach_unit(device_get_unit(dev), device_get_flags(dev)); 87} 88 89static int 90scsuspend(device_t dev) 91{ 92 int retry = 10; 93 static int dummy; 94 sc_softc_t *sc; 95 96 sc = &main_softc; 97 98 if (sc->cur_scp == NULL) 99 return (0); 100 101 sc_cur_scr = sc->cur_scp->index; 102 103 if (sc_no_suspend_vtswitch) 104 return (0); 105 106 do { 107 sc_switch_scr(sc, 0); 108 if (!sc->switch_in_progress) { 109 break; 110 } 111 tsleep(&dummy, 0, "scsuspend", 100); 112 } while (retry--); 113 114 return (0); 115} 116 117static int 118scresume(device_t dev) 119{ 120 sc_softc_t *sc; 121 122 if (sc_no_suspend_vtswitch) 123 return (0); 124 125 sc = &main_softc; 126 sc_switch_scr(sc, sc_cur_scr); 127 128 return (0); 129} 130 131int 132sc_max_unit(void) 133{ 134 return devclass_get_maxunit(sc_devclass); 135} 136 137sc_softc_t 138*sc_get_softc(int unit, int flags) 139{ 140 sc_softc_t *sc; 141 142 if (unit < 0) 143 return NULL; 144 if (flags & SC_KERNEL_CONSOLE) { 145 /* FIXME: clear if it is wired to another unit! */ 146 sc = &main_softc; 147 } else { 148 sc = (sc_softc_t *)device_get_softc(devclass_get_device(sc_devclass, unit)); 149 if (sc == NULL) 150 return NULL; 151 } 152 sc->unit = unit; 153 if (!(sc->flags & SC_INIT_DONE)) { 154 sc->keyboard = -1; 155 sc->adapter = -1; 156 sc->mouse_char = SC_MOUSE_CHAR; 157 } 158 return sc; 159} 160 161sc_softc_t 162*sc_find_softc(struct video_adapter *adp, struct keyboard *kbd) 163{ 164 sc_softc_t *sc; 165 int units; 166 int i; 167 168 sc = &main_softc; 169 if (((adp == NULL) || (adp == sc->adp)) 170 && ((kbd == NULL) || (kbd == sc->kbd))) 171 return sc; 172 units = devclass_get_maxunit(sc_devclass); 173 for (i = 0; i < units; ++i) { 174 sc = (sc_softc_t *)device_get_softc(devclass_get_device(sc_devclass, i)); 175 if (sc == NULL) 176 continue; 177 if (((adp == NULL) || (adp == sc->adp)) 178 && ((kbd == NULL) || (kbd == sc->kbd))) 179 return sc; 180 } 181 return NULL; 182} 183 184int 185sc_get_cons_priority(int *unit, int *flags) 186{ 187 const char *at; 188 int u, f; 189 190 *unit = -1; 191 for (u = 0; u < 16; u++) { 192 if (resource_disabled(SC_DRIVER_NAME, u)) 193 continue; 194 if (resource_string_value(SC_DRIVER_NAME, u, "at", &at) != 0) 195 continue; 196 if (resource_int_value(SC_DRIVER_NAME, u, "flags", &f) != 0) 197 f = 0; 198 if (f & SC_KERNEL_CONSOLE) { 199 /* the user designates this unit to be the console */ 200 *unit = u; 201 *flags = f; 202 break; 203 } 204 if (*unit < 0) { 205 /* ...otherwise remember the first found unit */ 206 *unit = u; 207 *flags = f; 208 } 209 } 210 if (*unit < 0) 211 return CN_DEAD; 212 return CN_INTERNAL; 213} 214 215void 216sc_get_bios_values(bios_values_t *values) 217{ 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; 223 else 224 values->bell_pitch = BELL_PITCH_5M; 225} 226 227int 228sc_tone(int herz) 229{ 230 231 if (herz) { 232 /* enable counter 1 */ 233 ppi_spkr_on(); 234 /* set command for counter 1, 2 byte write */ 235 if (timer_spkr_acquire()) 236 return EBUSY; 237 /* set pitch */ 238 spkr_set_pitch(timer_freq / herz); 239 } else { 240 /* disable counter 1 */ 241 ppi_spkr_off(); 242 timer_spkr_release(); 243 } 244 return 0; 245} 246 247static 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), 253 { 0, 0 } 254}; 255 256static driver_t sc_driver = { 257 SC_DRIVER_NAME, 258 sc_methods, 259 sizeof(sc_softc_t), 260}; 261 262DRIVER_MODULE(sc, isa, sc_driver, sc_devclass, 0, 0); 263