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