xref: /netbsd-src/sys/arch/mac68k/dev/maccons.c (revision 355a2878fad22b80314bcbfd857f2fb9f9076bd0)
1 /*	$NetBSD: maccons.c,v 1.10 2019/07/26 10:48:44 rin 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 <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: maccons.c,v 1.10 2019/07/26 10:48:44 rin Exp $");
31 
32 #include "genfb.h"
33 #include "macfb.h"
34 #include "wsdisplay.h"
35 #include "wskbd.h"
36 #include "zsc.h"
37 
38 #if (NGENFB + NMACFB) > 1
39 #error "genfb(4) and macfb(4) cannot be enabled at the same time"
40 #endif
41 
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/conf.h>
45 
46 #include <machine/autoconf.h>
47 #include <machine/cpu.h>
48 #include <machine/video.h>
49 
50 #include <dev/cons.h>
51 #include <dev/wscons/wsdisplayvar.h>
52 #include <dev/wscons/wskbdvar.h>
53 #if NGENFB > 0
54 #include <dev/wsfb/genfbvar.h>
55 #endif
56 
57 #include <mac68k/dev/akbdvar.h>
58 #if NMACFB > 0
59 #include <mac68k/dev/macfbvar.h>
60 #endif
61 
62 void maccnprobe(struct consdev *);
63 void maccninit(struct consdev *);
64 int maccngetc(dev_t);
65 void maccnputc(dev_t, int);
66 void maccnpollc(dev_t, int);
67 
68 static int	maccons_initted = (-1);
69 
70 void
maccnprobe(struct consdev * cp)71 maccnprobe(struct consdev *cp)
72 {
73 #if NWSDISPLAY > 0
74 	extern const struct cdevsw wsdisplay_cdevsw;
75 	int     maj, unit;
76 #endif
77 
78 	cp->cn_dev = NODEV;
79 	cp->cn_pri = CN_NORMAL;
80 
81 #if NWSDISPLAY > 0
82 	unit = 0;
83 	maj = cdevsw_lookup_major(&wsdisplay_cdevsw);
84 	if (maj != -1) {
85 		cp->cn_pri = CN_INTERNAL;
86 		cp->cn_dev = makedev(maj, unit);
87 	}
88 #endif
89 }
90 
91 void
maccninit(struct consdev * cp)92 maccninit(struct consdev *cp)
93 {
94 	/*
95 	 * XXX evil hack; see consinit() for an explanation.
96 	 * note:  maccons_initted is initialized to (-1).
97 	 */
98 	if (++maccons_initted > 0) {
99 #if NMACFB > 0
100 		macfb_cnattach(mac68k_video.mv_phys);
101 #elif NGENFB > 0
102 		genfb_cnattach();
103 #endif
104 		akbd_cnattach();
105 	}
106 }
107 
108 int
maccngetc(dev_t dev)109 maccngetc (dev_t dev)
110 {
111 #if NWSKBD > 0
112 	if (maccons_initted > 0)
113 		return wskbd_cngetc(dev);
114 #endif
115 	return 0;
116 }
117 
118 void
maccnputc(dev_t dev,int c)119 maccnputc(dev_t dev, int c)
120 {
121 #if NZSC > 0
122 	extern dev_t mac68k_zsdev;
123 	extern int zscnputc(dev_t, int);
124 #endif
125 
126 #if NWSDISPLAY > 0
127 	if (maccons_initted > 0)
128 		wsdisplay_cnputc(dev,c);
129 #endif
130 #if NZSC > 0
131         if (mac68k_machine.serial_boot_echo)
132                 zscnputc(mac68k_zsdev, c);
133 #endif
134 }
135 
136 void
maccnpollc(dev_t dev,int on)137 maccnpollc(dev_t dev, int on)
138 {
139 #if NWSKBD > 0
140 	if (maccons_initted > 0)
141 		wskbd_cnpollc(dev,on);
142 #endif
143 }
144