1 /* $NetBSD: sio.c,v 1.16 2021/09/25 15:18:38 tsutsui Exp $ */ 2 3 /*- 4 * Copyright (c) 2000 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Tohru Nishimura. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ 33 34 __KERNEL_RCSID(0, "$NetBSD: sio.c,v 1.16 2021/09/25 15:18:38 tsutsui Exp $"); 35 36 #include <sys/param.h> 37 #include <sys/systm.h> 38 #include <sys/device.h> 39 40 #include <machine/cpu.h> 41 #include <machine/autoconf.h> 42 43 #include <luna68k/luna68k/isr.h> 44 #include <luna68k/dev/sioreg.h> 45 #include <luna68k/dev/siovar.h> 46 47 #include "ioconf.h" 48 49 static int sio_match(device_t, cfdata_t, void *); 50 static void sio_attach(device_t, device_t, void *); 51 static int sio_print(void *, const char *); 52 53 CFATTACH_DECL_NEW(sio, sizeof(struct sio_softc), 54 sio_match, sio_attach, NULL, NULL); 55 56 static void nullintr(void *); 57 static int xsiointr(void *); 58 59 static int 60 sio_match(device_t parent, cfdata_t cf, void *aux) 61 { 62 struct mainbus_attach_args *ma = aux; 63 64 if (strcmp(ma->ma_name, sio_cd.cd_name)) 65 return 0; 66 if (badaddr((void *)ma->ma_addr, 4)) 67 return 0; 68 return 1; 69 } 70 71 static void 72 sio_attach(device_t parent, device_t self, void *aux) 73 { 74 struct sio_softc *sc = device_private(self); 75 struct mainbus_attach_args *ma = aux; 76 struct sio_attach_args sio_args; 77 int channel; 78 extern int sysconsole; /* console: 0 for ttya, 1 for desktop */ 79 80 aprint_normal(": uPD7201A\n"); 81 82 sc->sc_dev = self; 83 sc->sc_ctl = (void *)ma->ma_addr; 84 for (channel = 0; channel < 2; channel++) { 85 sc->sc_intrhand[channel].ih_func = nullintr; 86 sio_args.channel = channel; 87 sio_args.hwflags = (channel == sysconsole); 88 config_found(self, (void *)&sio_args, sio_print, CFARGS_NONE); 89 } 90 91 isrlink_autovec(xsiointr, sc, ma->ma_ilvl, ISRPRI_TTYNOBUF); 92 } 93 94 static int 95 sio_print(void *aux, const char *name) 96 { 97 struct sio_attach_args *args = aux; 98 99 if (name != NULL) 100 aprint_normal("%s: ", name); 101 102 if (args->channel != -1) 103 aprint_normal(" channel %d", args->channel); 104 105 return UNCONF; 106 } 107 108 static int 109 xsiointr(void *arg) 110 { 111 struct sio_softc *sc = arg; 112 113 /* channel 0: ttya system serial port */ 114 (*sc->sc_intrhand[0].ih_func)(sc->sc_intrhand[0].ih_arg); 115 116 /* channel 1: keyboard and mouse */ 117 (*sc->sc_intrhand[1].ih_func)(sc->sc_intrhand[1].ih_arg); 118 119 return 1; 120 } 121 122 static void 123 nullintr(void *arg) 124 { 125 } 126