1*355a2878Srin /* $NetBSD: maccons.c,v 1.10 2019/07/26 10:48:44 rin Exp $ */
28a007407Sscottr
38a007407Sscottr /*
48a007407Sscottr * Copyright (C) 1999 Scott Reynolds. All rights reserved.
58a007407Sscottr *
68a007407Sscottr * Redistribution and use in source and binary forms, with or without
78a007407Sscottr * modification, are permitted provided that the following conditions
88a007407Sscottr * are met:
98a007407Sscottr * 1. Redistributions of source code must retain the above copyright
108a007407Sscottr * notice, this list of conditions and the following disclaimer.
118a007407Sscottr * 2. Redistributions in binary form must reproduce the above copyright
128a007407Sscottr * notice, this list of conditions and the following disclaimer in the
138a007407Sscottr * documentation and/or other materials provided with the distribution.
148a007407Sscottr * 3. The name of the author may not be used to endorse or promote products
158a007407Sscottr * derived from this software without specific prior written permission.
168a007407Sscottr *
178a007407Sscottr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
188a007407Sscottr * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
198a007407Sscottr * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
208a007407Sscottr * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
218a007407Sscottr * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
228a007407Sscottr * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
238a007407Sscottr * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
248a007407Sscottr * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
258a007407Sscottr * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
268a007407Sscottr * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
278a007407Sscottr */
288a007407Sscottr
294b2744bfSlukem #include <sys/cdefs.h>
30*355a2878Srin __KERNEL_RCSID(0, "$NetBSD: maccons.c,v 1.10 2019/07/26 10:48:44 rin Exp $");
314b2744bfSlukem
32*355a2878Srin #include "genfb.h"
33*355a2878Srin #include "macfb.h"
348a007407Sscottr #include "wsdisplay.h"
358a007407Sscottr #include "wskbd.h"
368a007407Sscottr #include "zsc.h"
378a007407Sscottr
38*355a2878Srin #if (NGENFB + NMACFB) > 1
39*355a2878Srin #error "genfb(4) and macfb(4) cannot be enabled at the same time"
40*355a2878Srin #endif
41*355a2878Srin
428a007407Sscottr #include <sys/param.h>
438a007407Sscottr #include <sys/systm.h>
448a007407Sscottr #include <sys/conf.h>
458a007407Sscottr
468a007407Sscottr #include <machine/autoconf.h>
478a007407Sscottr #include <machine/cpu.h>
4892203533Sjmmv #include <machine/video.h>
49*355a2878Srin
508a007407Sscottr #include <dev/cons.h>
518a007407Sscottr #include <dev/wscons/wsdisplayvar.h>
52*355a2878Srin #include <dev/wscons/wskbdvar.h>
53*355a2878Srin #if NGENFB > 0
54*355a2878Srin #include <dev/wsfb/genfbvar.h>
55*355a2878Srin #endif
56*355a2878Srin
578a007407Sscottr #include <mac68k/dev/akbdvar.h>
58*355a2878Srin #if NMACFB > 0
59*355a2878Srin #include <mac68k/dev/macfbvar.h>
60*355a2878Srin #endif
618a007407Sscottr
627acd68b1Schs void maccnprobe(struct consdev *);
637acd68b1Schs void maccninit(struct consdev *);
647acd68b1Schs int maccngetc(dev_t);
657acd68b1Schs void maccnputc(dev_t, int);
667acd68b1Schs void maccnpollc(dev_t, int);
678a007407Sscottr
688a007407Sscottr static int maccons_initted = (-1);
698a007407Sscottr
708a007407Sscottr void
maccnprobe(struct consdev * cp)718a007407Sscottr maccnprobe(struct consdev *cp)
728a007407Sscottr {
738a007407Sscottr #if NWSDISPLAY > 0
7477a6b82bSgehenna extern const struct cdevsw wsdisplay_cdevsw;
758a007407Sscottr int maj, unit;
768a007407Sscottr #endif
778a007407Sscottr
788a007407Sscottr cp->cn_dev = NODEV;
798a007407Sscottr cp->cn_pri = CN_NORMAL;
808a007407Sscottr
818a007407Sscottr #if NWSDISPLAY > 0
828a007407Sscottr unit = 0;
8377a6b82bSgehenna maj = cdevsw_lookup_major(&wsdisplay_cdevsw);
8477a6b82bSgehenna if (maj != -1) {
858a007407Sscottr cp->cn_pri = CN_INTERNAL;
868a007407Sscottr cp->cn_dev = makedev(maj, unit);
878a007407Sscottr }
888a007407Sscottr #endif
898a007407Sscottr }
908a007407Sscottr
918a007407Sscottr void
maccninit(struct consdev * cp)928a007407Sscottr maccninit(struct consdev *cp)
938a007407Sscottr {
948a007407Sscottr /*
958a007407Sscottr * XXX evil hack; see consinit() for an explanation.
968a007407Sscottr * note: maccons_initted is initialized to (-1).
978a007407Sscottr */
988a007407Sscottr if (++maccons_initted > 0) {
99*355a2878Srin #if NMACFB > 0
1008583ef18Sjmmv macfb_cnattach(mac68k_video.mv_phys);
101*355a2878Srin #elif NGENFB > 0
102*355a2878Srin genfb_cnattach();
103*355a2878Srin #endif
1048a007407Sscottr akbd_cnattach();
1058a007407Sscottr }
1068a007407Sscottr }
1078a007407Sscottr
1088a007407Sscottr int
maccngetc(dev_t dev)1098a007407Sscottr maccngetc (dev_t dev)
1108a007407Sscottr {
1118a007407Sscottr #if NWSKBD > 0
1128a007407Sscottr if (maccons_initted > 0)
1138a007407Sscottr return wskbd_cngetc(dev);
1148a007407Sscottr #endif
1158a007407Sscottr return 0;
1168a007407Sscottr }
1178a007407Sscottr
1188a007407Sscottr void
maccnputc(dev_t dev,int c)1198a007407Sscottr maccnputc(dev_t dev, int c)
1208a007407Sscottr {
1218a007407Sscottr #if NZSC > 0
1228a007407Sscottr extern dev_t mac68k_zsdev;
1237acd68b1Schs extern int zscnputc(dev_t, int);
1248a007407Sscottr #endif
1258a007407Sscottr
1268a007407Sscottr #if NWSDISPLAY > 0
1278a007407Sscottr if (maccons_initted > 0)
1288a007407Sscottr wsdisplay_cnputc(dev,c);
1298a007407Sscottr #endif
1308a007407Sscottr #if NZSC > 0
1318a007407Sscottr if (mac68k_machine.serial_boot_echo)
1328a007407Sscottr zscnputc(mac68k_zsdev, c);
1338a007407Sscottr #endif
1348a007407Sscottr }
1358a007407Sscottr
1368a007407Sscottr void
maccnpollc(dev_t dev,int on)1378a007407Sscottr maccnpollc(dev_t dev, int on)
1388a007407Sscottr {
1398a007407Sscottr #if NWSKBD > 0
1408a007407Sscottr if (maccons_initted > 0)
1418a007407Sscottr wskbd_cnpollc(dev,on);
1428a007407Sscottr #endif
1438a007407Sscottr }
144