xref: /netbsd/sys/arch/mac68k/dev/maccons.c (revision bf9ec67e)
1 /*	$NetBSD: maccons.c,v 1.2 2000/02/14 07:01:47 scottr Exp $	*/
2 
3 /*
4  * Copyright (C) 1999 Scott Reynolds.  All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
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  * 3. The name of the author may not be used to endorse or promote products
15  *    derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include "wsdisplay.h"
30 #include "wskbd.h"
31 #include "zsc.h"
32 
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/conf.h>
36 
37 #include <machine/autoconf.h>
38 #include <machine/cpu.h>
39 
40 #include <dev/cons.h>
41 #include <dev/wscons/wskbdvar.h>
42 #include <dev/wscons/wsdisplayvar.h>
43 #include <mac68k/dev/macfbvar.h>
44 #include <mac68k/dev/akbdvar.h>
45 
46 void maccnprobe __P((struct consdev *));
47 void maccninit __P((struct consdev *));
48 int maccngetc __P((dev_t));
49 void maccnputc __P((dev_t, int));
50 void maccnpollc __P((dev_t, int));
51 
52 #if NWSDISPLAY > 0
53 cdev_decl(wsdisplay);
54 #endif
55 
56 static int	maccons_initted = (-1);
57 
58 /* From Booter via locore */
59 extern u_int32_t	mac68k_vidphys;
60 
61 void
62 maccnprobe(struct consdev *cp)
63 {
64 #if NWSDISPLAY > 0
65 	int     maj, unit;
66 #endif
67 
68 	cp->cn_dev = NODEV;
69 	cp->cn_pri = CN_NORMAL;
70 
71 #if NWSDISPLAY > 0
72 	unit = 0;
73 	for (maj = 0; maj < nchrdev; maj++) {
74 		if (cdevsw[maj].d_open == wsdisplayopen) {
75 			break;
76 		}
77 	}
78 	if (maj != nchrdev) {
79 		cp->cn_pri = CN_INTERNAL;
80 		cp->cn_dev = makedev(maj, unit);
81 	}
82 #endif
83 }
84 
85 void
86 maccninit(struct consdev *cp)
87 {
88 	/*
89 	 * XXX evil hack; see consinit() for an explanation.
90 	 * note:  maccons_initted is initialized to (-1).
91 	 */
92 	if (++maccons_initted > 0) {
93 		macfb_cnattach(mac68k_vidphys);
94 		akbd_cnattach();
95 	}
96 }
97 
98 int
99 maccngetc (dev_t dev)
100 {
101 #if NWSKBD > 0
102 	if (maccons_initted > 0)
103 		return wskbd_cngetc(dev);
104 #endif
105 	return 0;
106 }
107 
108 void
109 maccnputc(dev_t dev, int c)
110 {
111 #if NZSC > 0
112 	extern dev_t mac68k_zsdev;
113 	extern int zscnputc __P((dev_t dev, int c));
114 #endif
115 
116 #if NWSDISPLAY > 0
117 	if (maccons_initted > 0)
118 		wsdisplay_cnputc(dev,c);
119 #endif
120 #if NZSC > 0
121         if (mac68k_machine.serial_boot_echo)
122                 zscnputc(mac68k_zsdev, c);
123 #endif
124 }
125 
126 void
127 maccnpollc(dev_t dev, int on)
128 {
129 #if NWSKBD > 0
130 	if (maccons_initted > 0)
131 		wskbd_cnpollc(dev,on);
132 #endif
133 }
134