Home | History | Annotate | Line # | Download | only in dev
m38813c.c revision 1.1.2.1
      1  1.1.2.1  wrstuden /*	$NetBSD: m38813c.c,v 1.1.2.1 1999/12/27 18:32:02 wrstuden Exp $ */
      2      1.1       uch 
      3      1.1       uch /*
      4      1.1       uch  * Copyright (c) 1999, by UCHIYAMA Yasushi
      5      1.1       uch  * All rights reserved.
      6      1.1       uch  *
      7      1.1       uch  * Redistribution and use in source and binary forms, with or without
      8      1.1       uch  * modification, are permitted provided that the following conditions
      9      1.1       uch  * are met:
     10      1.1       uch  * 1. Redistributions of source code must retain the above copyright
     11      1.1       uch  *    notice, this list of conditions and the following disclaimer.
     12      1.1       uch  * 2. The name of the developer may NOT be used to endorse or promote products
     13      1.1       uch  *    derived from this software without specific prior written permission.
     14      1.1       uch  *
     15      1.1       uch  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     16      1.1       uch  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     17      1.1       uch  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     18      1.1       uch  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     19      1.1       uch  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     20      1.1       uch  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     21      1.1       uch  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     22      1.1       uch  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     23      1.1       uch  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     24      1.1       uch  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     25      1.1       uch  * SUCH DAMAGE.
     26      1.1       uch  *
     27      1.1       uch  */
     28      1.1       uch 
     29      1.1       uch /*
     30      1.1       uch  * Device driver for MITUBISHI M38813 controller
     31      1.1       uch  */
     32      1.1       uch 
     33      1.1       uch #include "opt_tx39_debug.h"
     34      1.1       uch #include "opt_use_poll.h"
     35      1.1       uch 
     36      1.1       uch #include <sys/param.h>
     37      1.1       uch #include <sys/systm.h>
     38      1.1       uch #include <sys/device.h>
     39      1.1       uch 
     40      1.1       uch #include <machine/bus.h>
     41      1.1       uch #include <machine/intr.h>
     42      1.1       uch 
     43      1.1       uch #include <hpcmips/tx/tx39var.h>
     44      1.1       uch #include <hpcmips/tx/txcsbusvar.h>
     45      1.1       uch 
     46      1.1       uch #include <hpcmips/dev/m38813cvar.h>
     47      1.1       uch #include <hpcmips/dev/skbdvar.h>
     48      1.1       uch 
     49      1.1       uch struct m38813c_chip {
     50      1.1       uch 	bus_space_tag_t		scc_cst;
     51      1.1       uch 	bus_space_handle_t	scc_csh;
     52      1.1       uch 	int			scc_enabled;
     53      1.1       uch 	int t_lastchar;
     54      1.1       uch 	int t_extended;
     55      1.1       uch 	int t_extended1;
     56      1.1       uch 
     57      1.1       uch 	struct skbd_controller	scc_controller;
     58      1.1       uch };
     59      1.1       uch 
     60      1.1       uch struct m38813c_softc {
     61      1.1       uch 	struct	device		sc_dev;
     62      1.1       uch 	struct m38813c_chip	*sc_chip;
     63      1.1       uch 	tx_chipset_tag_t	sc_tc;
     64      1.1       uch 	void			*sc_ih;
     65      1.1       uch };
     66      1.1       uch 
     67      1.1       uch int	m38813c_match __P((struct device*, struct cfdata*, void*));
     68      1.1       uch void	m38813c_attach __P((struct device*, struct device*, void*));
     69      1.1       uch int	m38813c_intr __P((void*));
     70      1.1       uch int	m38813c_poll __P((void*));
     71      1.1       uch void	m38813c_ifsetup __P((struct m38813c_chip*));
     72      1.1       uch 
     73      1.1       uch int	m38813c_input_establish __P((void*, int (*) __P((void*, int, int)),
     74      1.1       uch 				     void (*) __P((void*)), void*));
     75      1.1       uch 
     76      1.1       uch struct m38813c_chip m38813c_chip;
     77      1.1       uch 
     78      1.1       uch struct cfattach m38813c_ca = {
     79      1.1       uch 	sizeof(struct m38813c_softc), m38813c_match, m38813c_attach
     80      1.1       uch };
     81      1.1       uch 
     82      1.1       uch int
     83      1.1       uch m38813c_match(parent, cf, aux)
     84      1.1       uch 	struct device *parent;
     85      1.1       uch 	struct cfdata *cf;
     86      1.1       uch 	void *aux;
     87      1.1       uch {
     88      1.1       uch 	return 1;
     89      1.1       uch }
     90      1.1       uch 
     91      1.1       uch void
     92      1.1       uch m38813c_attach(parent, self, aux)
     93      1.1       uch 	struct device *parent;
     94      1.1       uch 	struct device *self;
     95      1.1       uch 	void *aux;
     96      1.1       uch {
     97      1.1       uch 	struct cs_attach_args *ca = aux;
     98      1.1       uch 	struct m38813c_softc *sc = (void*)self;
     99      1.1       uch 	struct skbd_attach_args saa;
    100      1.1       uch 
    101      1.1       uch 	sc->sc_tc = ca->ca_tc;
    102      1.1       uch 	sc->sc_chip = &m38813c_chip;
    103      1.1       uch 	sc->sc_chip->scc_cst = ca->ca_csio.cstag;
    104      1.1       uch 
    105      1.1       uch 	if (bus_space_map(sc->sc_chip->scc_cst, ca->ca_csio.csbase,
    106      1.1       uch 			  ca->ca_csio.cssize, 0, &sc->sc_chip->scc_csh)) {
    107      1.1       uch 		printf(": can't map i/o space\n");
    108      1.1       uch 	}
    109      1.1       uch 
    110      1.1       uch #ifndef USE_POLL
    111      1.1       uch #error options USE_POLL requied.
    112      1.1       uch #endif
    113      1.1       uch 	if (!(sc->sc_ih = tx39_poll_establish(sc->sc_tc, 5, IST_EDGE,
    114      1.1       uch 					      IPL_TTY, m38813c_intr,
    115      1.1       uch 					      sc))) {
    116      1.1       uch 		printf(": can't establish interrupt\n");
    117      1.1       uch 	}
    118      1.1       uch 
    119      1.1       uch 	printf("\n");
    120      1.1       uch 
    121      1.1       uch 	/* setup upper interface */
    122      1.1       uch 	m38813c_ifsetup(sc->sc_chip);
    123      1.1       uch 
    124      1.1       uch 	saa.saa_ic = &sc->sc_chip->scc_controller;
    125      1.1       uch 
    126      1.1       uch 	config_found(self, &saa, skbd_print);
    127      1.1       uch }
    128      1.1       uch 
    129      1.1       uch void
    130      1.1       uch m38813c_ifsetup(scc)
    131      1.1       uch 	struct m38813c_chip *scc;
    132      1.1       uch {
    133      1.1       uch 	scc->scc_controller.skif_v		= scc;
    134      1.1       uch 
    135      1.1       uch 	scc->scc_controller.skif_establish	= m38813c_input_establish;
    136      1.1       uch 	scc->scc_controller.skif_poll		= m38813c_intr;
    137      1.1       uch }
    138      1.1       uch 
    139      1.1       uch int
    140      1.1       uch m38813c_cnattach(addr)
    141      1.1       uch 	paddr_t addr;
    142      1.1       uch {
    143      1.1       uch 	struct m38813c_chip *scc = &m38813c_chip;
    144      1.1       uch 
    145      1.1       uch 	scc->scc_csh = MIPS_PHYS_TO_KSEG1(addr);
    146      1.1       uch 
    147      1.1       uch 	m38813c_ifsetup(scc);
    148      1.1       uch 
    149      1.1       uch 	skbd_cnattach(&scc->scc_controller);
    150      1.1       uch 
    151      1.1       uch 	return 0;
    152      1.1       uch }
    153      1.1       uch 
    154      1.1       uch int
    155      1.1       uch m38813c_input_establish(ic, inputfunc, inputhookfunc, arg)
    156      1.1       uch 	void *ic;
    157      1.1       uch 	int (*inputfunc) __P((void*, int, int));
    158      1.1       uch 	void (*inputhookfunc) __P((void*));
    159      1.1       uch 	void *arg;
    160      1.1       uch {
    161      1.1       uch 	struct m38813c_chip *scc = ic;
    162      1.1       uch 
    163      1.1       uch 	/* setup lower interface */
    164      1.1       uch 
    165      1.1       uch 	scc->scc_controller.sk_v = arg;
    166      1.1       uch 
    167      1.1       uch 	scc->scc_controller.sk_input = inputfunc;
    168      1.1       uch 	scc->scc_controller.sk_input_hook = inputhookfunc;
    169      1.1       uch 
    170      1.1       uch 	scc->scc_enabled = 1;
    171      1.1       uch 
    172      1.1       uch 	return 0;
    173      1.1       uch }
    174      1.1       uch 
    175      1.1       uch #define	KBR_EXTENDED0	0xE0	/* extended key sequence */
    176      1.1       uch #define	KBR_EXTENDED1	0xE1	/* extended key sequence */
    177      1.1       uch 
    178      1.1       uch int
    179      1.1       uch m38813c_intr(arg)
    180      1.1       uch  	void *arg;
    181      1.1       uch {
    182      1.1       uch 	struct m38813c_softc *sc = arg;
    183      1.1       uch 
    184      1.1       uch 	return m38813c_poll(sc->sc_chip);
    185      1.1       uch }
    186      1.1       uch 
    187      1.1       uch int
    188      1.1       uch m38813c_poll(arg)
    189      1.1       uch  	void *arg;
    190      1.1       uch {
    191      1.1       uch 	struct m38813c_chip *scc = arg;
    192      1.1       uch 	bus_space_tag_t t = scc->scc_cst;
    193      1.1       uch 	bus_space_handle_t h = scc->scc_csh;
    194      1.1       uch 	int datain, type, key;
    195      1.1       uch 
    196      1.1       uch 	if (!scc->scc_enabled) {
    197      1.1       uch 		return 0;
    198      1.1       uch 	}
    199      1.1       uch 
    200      1.1       uch 	datain= bus_space_read_1(t, h, 0);
    201      1.1       uch 
    202      1.1       uch 	skbd_input_hook(&scc->scc_controller);
    203      1.1       uch 
    204      1.1       uch 	if (datain == KBR_EXTENDED0) {
    205      1.1       uch 		scc->t_extended = 1;
    206      1.1       uch 		return 0;
    207      1.1       uch 	} else if (datain == KBR_EXTENDED1) {
    208      1.1       uch 		scc->t_extended1 = 2;
    209      1.1       uch 		return 0;
    210      1.1       uch 	}
    211      1.1       uch 
    212      1.1       uch  	/* map extended keys to (unused) codes 128-254 */
    213      1.1       uch 	key = (datain & 0x7f) | (scc->t_extended ? 0x80 : 0);
    214      1.1       uch 	scc->t_extended = 0;
    215      1.1       uch 
    216      1.1       uch 	/*
    217      1.1       uch 	 * process BREAK key (EXT1 1D 45  EXT1 9D C5):
    218      1.1       uch 	 * map to (unused) code 7F
    219      1.1       uch 	 */
    220      1.1       uch 	if (scc->t_extended1 == 2 && (datain == 0x1d || datain == 0x9d)) {
    221      1.1       uch 		scc->t_extended1 = 1;
    222      1.1       uch 		return 0;
    223      1.1       uch 	} else if (scc->t_extended1 == 1 &&
    224      1.1       uch 		   (datain == 0x45 || datain == 0xc5)) {
    225      1.1       uch 		scc->t_extended1 = 0;
    226      1.1       uch 		key = 0x7f;
    227      1.1       uch 	} else if (scc->t_extended1 > 0) {
    228      1.1       uch 		scc->t_extended1 = 0;
    229      1.1       uch 	}
    230      1.1       uch 
    231      1.1       uch 	if (datain & 0x80) {
    232      1.1       uch 		scc->t_lastchar = 0;
    233      1.1       uch 		type = 0;
    234      1.1       uch 	} else {
    235      1.1       uch 		/* Always ignore typematic keys */
    236      1.1       uch 		if (key == scc->t_lastchar)
    237      1.1       uch 			return 0;
    238      1.1       uch 		scc->t_lastchar = key;
    239      1.1       uch 		type = 1;
    240      1.1       uch 	}
    241      1.1       uch 
    242      1.1       uch 	skbd_input(&scc->scc_controller, type, key);
    243      1.1       uch 
    244      1.1       uch 	return 0;
    245      1.1       uch }
    246