Home | History | Annotate | Line # | Download | only in dev
sio.c revision 1.4.44.2
      1  1.4.44.2      yamt /* $NetBSD: sio.c,v 1.4.44.2 2009/05/04 08:11:24 yamt 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.4.44.2      yamt __KERNEL_RCSID(0, "$NetBSD: sio.c,v 1.4.44.2 2009/05/04 08:11:24 yamt 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.4.44.2      yamt static int  sio_match(struct device *, struct cfdata *, void *);
     47  1.4.44.2      yamt static void sio_attach(struct device *, struct device *, void *);
     48  1.4.44.2      yamt static int  sio_print(void *, const char *);
     49       1.1  nisimura 
     50       1.2   thorpej CFATTACH_DECL(sio, sizeof(struct sio_softc),
     51       1.2   thorpej     sio_match, sio_attach, NULL, NULL);
     52       1.1  nisimura extern struct cfdriver sio_cd;
     53       1.1  nisimura 
     54  1.4.44.2      yamt static void nullintr(int);
     55  1.4.44.2      yamt static int xsiointr(void *);
     56       1.1  nisimura 
     57       1.1  nisimura static int
     58  1.4.44.2      yamt sio_match(struct device *parent, struct cfdata *cf, void *aux)
     59       1.1  nisimura {
     60       1.1  nisimura 	struct mainbus_attach_args *ma = aux;
     61       1.1  nisimura 
     62       1.1  nisimura 	if (strcmp(ma->ma_name, sio_cd.cd_name))
     63       1.1  nisimura 		return 0;
     64       1.4  christos 	if (badaddr((void *)ma->ma_addr, 4))
     65       1.1  nisimura 		return 0;
     66       1.1  nisimura 	return 1;
     67       1.1  nisimura }
     68       1.1  nisimura 
     69       1.1  nisimura static void
     70  1.4.44.2      yamt sio_attach(struct device *parent, struct device *self, void *aux)
     71       1.1  nisimura {
     72       1.1  nisimura 	struct sio_softc *sc = (void *)self;
     73       1.1  nisimura 	struct mainbus_attach_args *ma = aux;
     74       1.1  nisimura 	struct sio_attach_args sio_args;
     75       1.1  nisimura 	int channel;
     76       1.1  nisimura 	extern int sysconsole; /* console: 0 for ttya, 1 for desktop */
     77       1.1  nisimura 
     78       1.1  nisimura 	printf(": 7201a\n");
     79       1.1  nisimura 
     80       1.4  christos 	sc->scp_ctl = (void *)ma->ma_addr;
     81       1.1  nisimura 	sc->scp_intr[0] = sc->scp_intr[1] = nullintr;
     82       1.1  nisimura 	for (channel = 0; channel < 2; channel++) {
     83       1.1  nisimura 		sio_args.channel = channel;
     84       1.1  nisimura 		sio_args.hwflags = (channel == sysconsole);
     85       1.1  nisimura 		config_found(self, (void *)&sio_args, sio_print);
     86       1.1  nisimura 	}
     87       1.1  nisimura 
     88       1.1  nisimura 	isrlink_autovec(xsiointr, sc, ma->ma_ilvl, ISRPRI_TTYNOBUF);
     89       1.1  nisimura }
     90       1.1  nisimura 
     91       1.1  nisimura static int
     92  1.4.44.2      yamt sio_print(void *aux, const char *name)
     93       1.1  nisimura {
     94       1.1  nisimura 	struct sio_attach_args *args = aux;
     95       1.1  nisimura 
     96       1.1  nisimura 	if (name != NULL)
     97       1.3   thorpej 		aprint_normal("%s: ", name);
     98       1.1  nisimura 
     99       1.1  nisimura 	if (args->channel != -1)
    100       1.3   thorpej 		aprint_normal(" channel %d", args->channel);
    101       1.1  nisimura 
    102       1.1  nisimura 	return UNCONF;
    103       1.1  nisimura }
    104       1.1  nisimura 
    105       1.1  nisimura static int
    106  1.4.44.2      yamt xsiointr(void *arg)
    107       1.1  nisimura {
    108       1.1  nisimura 	struct sio_softc *sc = arg;
    109       1.1  nisimura 
    110       1.1  nisimura 	(*sc->scp_intr[0])(0); 	/* 0: ttya system serial port */
    111       1.1  nisimura 	(*sc->scp_intr[1])(1);	/* 1: keyboard and mouse */
    112       1.1  nisimura 	return 1;
    113       1.1  nisimura }
    114       1.1  nisimura 
    115       1.1  nisimura static void nullintr(v) int v; { }
    116