syscons_cbus.c revision 48187
1/*-
2 * $Id: $
3 */
4
5#include "sc.h"
6#include "opt_syscons.h"
7
8#if NSC > 0
9
10#include <sys/param.h>
11#include <sys/systm.h>
12#include <sys/kernel.h>
13#include <sys/module.h>
14#include <sys/bus.h>
15
16#include <machine/cons.h>
17#include <machine/console.h>
18#include <machine/clock.h>
19
20#include <pc98/pc98/pc98.h>
21#include <pc98/pc98/pc98_machdep.h>
22
23#include <dev/syscons/syscons.h>
24
25#include <i386/isa/timerreg.h>
26
27#include <isa/isavar.h>
28
29static devclass_t	sc_devclass;
30
31static int	scprobe(device_t dev);
32static int	scattach(device_t dev);
33static int	scresume(device_t dev);
34
35static device_method_t sc_methods[] = {
36	DEVMETHOD(device_probe,         scprobe),
37	DEVMETHOD(device_attach,        scattach),
38	DEVMETHOD(device_resume,        scresume),
39	{ 0, 0 }
40};
41
42static driver_t sc_driver = {
43	SC_DRIVER_NAME,
44	sc_methods,
45	1,                          /* XXX */
46};
47
48static sc_softc_t main_softc = { 0, 0, 0, -1, NULL, -1, NULL, };
49
50static int
51scprobe(device_t dev)
52{
53	/* No pnp support */
54	if (isa_get_vendorid(dev))
55		return (ENXIO);
56
57	device_set_desc(dev, "System console");
58	return sc_probe_unit(device_get_unit(dev), isa_get_flags(dev));
59}
60
61static int
62scattach(device_t dev)
63{
64	return sc_attach_unit(device_get_unit(dev), isa_get_flags(dev));
65}
66
67static int
68scresume(device_t dev)
69{
70	return sc_resume_unit(device_get_unit(dev));
71}
72
73int
74sc_max_unit(void)
75{
76	return devclass_get_maxunit(sc_devclass);
77}
78
79sc_softc_t
80*sc_get_softc(int unit, int flags)
81{
82	sc_softc_t *sc;
83
84	if ((unit < 0) || (unit >= NSC))
85		return NULL;
86	if (flags & SC_KERNEL_CONSOLE) {
87		/* FIXME: clear if it is wired to another unit! */
88		main_softc.unit = unit;
89		return &main_softc;
90	} else {
91	        sc = (sc_softc_t *)devclass_get_softc(sc_devclass, unit);
92		if (!(sc->flags & SC_INIT_DONE)) {
93			sc->unit = unit;
94			sc->keyboard = -1;
95			sc->adapter = -1;
96		}
97		return sc;
98	}
99}
100
101sc_softc_t
102*sc_find_softc(struct video_adapter *adp, struct keyboard *kbd)
103{
104	sc_softc_t *sc;
105	int units;
106	int i;
107
108	sc = &main_softc;
109	if (((adp == NULL) || (adp == sc->adp))
110	    && ((kbd == NULL) || (kbd == sc->kbd)))
111		return sc;
112	units = devclass_get_maxunit(sc_devclass);
113	for (i = 0; i < units; ++i) {
114	        sc = (sc_softc_t *)devclass_get_softc(sc_devclass, i);
115		if (sc == NULL)
116			continue;
117		if (((adp == NULL) || (adp == sc->adp))
118		    && ((kbd == NULL) || (kbd == sc->kbd)))
119			return sc;
120	}
121	return NULL;
122}
123
124int
125sc_get_cons_priority(int *unit, int *flags)
126{
127	int disabled;
128	int u, f;
129	int i;
130
131	*unit = -1;
132	for (i = -1; (i = resource_locate(i, SC_DRIVER_NAME)) >= 0;) {
133		u = resource_query_unit(i);
134		if ((resource_int_value(SC_DRIVER_NAME, u, "disabled",
135					&disabled) == 0) && disabled)
136			continue;
137		if (resource_int_value(SC_DRIVER_NAME, u, "flags", &f) != 0)
138			f = 0;
139		if (f & SC_KERNEL_CONSOLE) {
140			/* the user designates this unit to be the console */
141			*unit = u;
142			*flags = f;
143			break;
144		}
145		if (*unit < 0) {
146			/* ...otherwise remember the first found unit */
147			*unit = u;
148			*flags = f;
149		}
150	}
151	if ((i < 0) && (*unit < 0))
152		return CN_DEAD;
153	return CN_INTERNAL;
154}
155
156void
157sc_get_bios_values(bios_values_t *values)
158{
159	values->cursor_start = 0;
160	values->cursor_end = 16;
161	values->shift_state = 0;
162	if (pc98_machine_type & M_8M)
163		values->bell_pitch = BELL_PITCH_8M;
164	else
165		values->bell_pitch = BELL_PITCH_5M;
166}
167
168int
169sc_tone(int herz)
170{
171	int pitch;
172
173	if (herz) {
174		/* enable counter 1 */
175		outb(0x35, inb(0x35) & 0xf7);
176		/* set command for counter 1, 2 byte write */
177		if (acquire_timer1(TIMER_16BIT | TIMER_SQWAVE))
178			return EBUSY;
179		/* set pitch */
180		pitch = timer_freq/herz;
181		outb(TIMER_CNTR1, pitch);
182		outb(TIMER_CNTR1, pitch >> 8);
183	} else {
184		/* disable counter 1 */
185		outb(0x35, inb(0x35) | 0x08);
186		release_timer1();
187	}
188	return 0;
189}
190
191DRIVER_MODULE(sc, isa, sc_driver, sc_devclass, 0, 0);
192
193#endif /* NSC > 0 */
194