Home | History | Annotate | Line # | Download | only in dev
tc5165buf.c revision 1.3
      1  1.3  uch /*	$NetBSD: tc5165buf.c,v 1.3 2000/01/07 15:19:13 uch Exp $ */
      2  1.1  uch 
      3  1.1  uch /*
      4  1.2  uch  * Copyright (c) 1999, 2000, 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.3  uch  * Device driver for TOSHIBA TC5165BFTS, PHILIPS 74ALVC16241/245
     31  1.3  uch  * buffer chip
     32  1.1  uch  */
     33  1.1  uch 
     34  1.1  uch #include "opt_tx39_debug.h"
     35  1.1  uch #include "opt_use_poll.h"
     36  1.1  uch 
     37  1.1  uch #include <sys/param.h>
     38  1.1  uch #include <sys/systm.h>
     39  1.1  uch #include <sys/device.h>
     40  1.1  uch 
     41  1.1  uch #include <machine/bus.h>
     42  1.1  uch #include <machine/intr.h>
     43  1.1  uch 
     44  1.1  uch #include <hpcmips/tx/tx39var.h>
     45  1.1  uch #include <hpcmips/tx/txcsbusvar.h>
     46  1.1  uch 
     47  1.1  uch #include <hpcmips/dev/tc5165bufvar.h>
     48  1.1  uch #include <hpcmips/dev/skbdvar.h>
     49  1.1  uch 
     50  1.1  uch #define TC5165_ROW_MAX		16
     51  1.1  uch #define TC5165_COLUMN_MAX	8
     52  1.1  uch 
     53  1.1  uch #ifdef TC5165DEBUG
     54  1.1  uch #define	DPRINTF(arg) printf arg
     55  1.1  uch #else
     56  1.1  uch #define	DPRINTF(arg)
     57  1.1  uch #endif
     58  1.1  uch 
     59  1.1  uch struct tc5165buf_chip {
     60  1.1  uch 	bus_space_tag_t		scc_cst;
     61  1.1  uch 	bus_space_handle_t	scc_csh;
     62  1.3  uch 	u_int16_t		scc_buf[TC5165_COLUMN_MAX];
     63  1.1  uch 	int			scc_enabled;
     64  1.1  uch 
     65  1.1  uch 	struct skbd_controller	scc_controller;
     66  1.1  uch };
     67  1.1  uch 
     68  1.1  uch struct tc5165buf_softc {
     69  1.1  uch 	struct device		sc_dev;
     70  1.1  uch 	struct tc5165buf_chip	*sc_chip;
     71  1.1  uch 	tx_chipset_tag_t	sc_tc;
     72  1.1  uch 	void			*sc_ih;
     73  1.1  uch };
     74  1.1  uch 
     75  1.1  uch int	tc5165buf_match __P((struct device*, struct cfdata*, void*));
     76  1.1  uch void	tc5165buf_attach __P((struct device*, struct device*, void*));
     77  1.1  uch int	tc5165buf_intr __P((void*));
     78  1.1  uch int	tc5165buf_poll __P((void*));
     79  1.1  uch void	tc5165buf_ifsetup __P((struct tc5165buf_chip*));
     80  1.1  uch 
     81  1.1  uch int	tc5165buf_input_establish __P((void*, int (*) __P((void*, int, int)),
     82  1.1  uch 				      void (*) __P((void*)), void*));
     83  1.1  uch 
     84  1.1  uch struct tc5165buf_chip tc5165buf_chip;
     85  1.1  uch 
     86  1.1  uch struct cfattach tc5165buf_ca = {
     87  1.1  uch 	sizeof(struct tc5165buf_softc), tc5165buf_match, tc5165buf_attach
     88  1.1  uch };
     89  1.1  uch 
     90  1.1  uch int
     91  1.1  uch tc5165buf_match(parent, cf, aux)
     92  1.1  uch 	struct device *parent;
     93  1.1  uch 	struct cfdata *cf;
     94  1.1  uch 	void *aux;
     95  1.1  uch {
     96  1.1  uch 	return 1;
     97  1.1  uch }
     98  1.1  uch 
     99  1.1  uch void
    100  1.1  uch tc5165buf_attach(parent, self, aux)
    101  1.1  uch 	struct device *parent;
    102  1.1  uch 	struct device *self;
    103  1.1  uch 	void *aux;
    104  1.1  uch {
    105  1.1  uch 	struct cs_attach_args *ca = aux;
    106  1.1  uch 	struct tc5165buf_softc *sc = (void*)self;
    107  1.1  uch 	struct skbd_attach_args saa;
    108  1.1  uch 
    109  1.1  uch 	sc->sc_tc = ca->ca_tc;
    110  1.1  uch 	sc->sc_chip = &tc5165buf_chip;
    111  1.1  uch 
    112  1.1  uch 	sc->sc_chip->scc_cst = ca->ca_csio.cstag;
    113  1.1  uch 
    114  1.1  uch 	if (bus_space_map(sc->sc_chip->scc_cst, ca->ca_csio.csbase,
    115  1.1  uch 			  ca->ca_csio.cssize, 0, &sc->sc_chip->scc_csh)) {
    116  1.1  uch 		printf(": can't map i/o space\n");
    117  1.1  uch 		return;
    118  1.1  uch 	}
    119  1.1  uch 
    120  1.1  uch 	sc->sc_chip->scc_enabled = 0;
    121  1.1  uch #if notyet
    122  1.1  uch 	if (!(sc->sc_ih = tx_intr_establish(sc->sc_tc, ca->ca_irq1,
    123  1.1  uch 					      IST_EDGE, IPL_TTY,
    124  1.1  uch 					      tc5165buf_intr, sc))) {
    125  1.1  uch 		printf(": can't establish interrupt(1)\n");
    126  1.1  uch 		return;
    127  1.1  uch 	}
    128  1.1  uch #endif
    129  1.2  uch 	if (!(sc->sc_ih = tx39_poll_establish(sc->sc_tc, 1,
    130  1.1  uch 					      IPL_TTY, tc5165buf_poll,
    131  1.1  uch 					      sc->sc_chip))) {
    132  1.1  uch 		printf(": can't establish interrupt\n");
    133  1.1  uch 		return;
    134  1.1  uch 	}
    135  1.1  uch 
    136  1.1  uch 	printf("\n");
    137  1.1  uch 
    138  1.1  uch 	/* setup upper interface */
    139  1.1  uch 	tc5165buf_ifsetup(sc->sc_chip);
    140  1.1  uch 
    141  1.1  uch 	saa.saa_ic = &sc->sc_chip->scc_controller;
    142  1.1  uch 
    143  1.1  uch 	config_found(self, &saa, skbd_print);
    144  1.1  uch }
    145  1.1  uch 
    146  1.1  uch void
    147  1.1  uch tc5165buf_ifsetup(scc)
    148  1.1  uch 	struct tc5165buf_chip *scc;
    149  1.1  uch {
    150  1.1  uch 	scc->scc_controller.skif_v		= scc;
    151  1.1  uch 
    152  1.1  uch 	scc->scc_controller.skif_establish	= tc5165buf_input_establish;
    153  1.1  uch 	scc->scc_controller.skif_poll		= tc5165buf_poll;
    154  1.1  uch }
    155  1.1  uch 
    156  1.1  uch int
    157  1.1  uch tc5165buf_cnattach(addr)
    158  1.1  uch 	paddr_t addr;
    159  1.1  uch {
    160  1.1  uch 	struct tc5165buf_chip *scc = &tc5165buf_chip;
    161  1.1  uch 
    162  1.1  uch 	scc->scc_csh = MIPS_PHYS_TO_KSEG1(addr);
    163  1.1  uch 
    164  1.1  uch 	tc5165buf_ifsetup(scc);
    165  1.1  uch 
    166  1.1  uch 	skbd_cnattach(&scc->scc_controller);
    167  1.1  uch 
    168  1.1  uch 	return 0;
    169  1.1  uch }
    170  1.1  uch 
    171  1.1  uch int
    172  1.1  uch tc5165buf_input_establish(ic, inputfunc, inputhookfunc, arg)
    173  1.1  uch 	void *ic;
    174  1.1  uch 	int (*inputfunc) __P((void*, int, int));
    175  1.1  uch 	void (*inputhookfunc) __P((void*));
    176  1.1  uch 	void *arg;
    177  1.1  uch {
    178  1.1  uch 	struct tc5165buf_chip *scc = ic;
    179  1.1  uch 
    180  1.1  uch 	/* setup lower interface */
    181  1.1  uch 
    182  1.1  uch 	scc->scc_controller.sk_v = arg;
    183  1.1  uch 
    184  1.1  uch 	scc->scc_controller.sk_input = inputfunc;
    185  1.1  uch 	scc->scc_controller.sk_input_hook = inputhookfunc;
    186  1.1  uch 
    187  1.1  uch 	scc->scc_enabled = 1;
    188  1.1  uch 
    189  1.1  uch 	return 0;
    190  1.1  uch }
    191  1.1  uch 
    192  1.1  uch int
    193  1.1  uch tc5165buf_intr(arg)
    194  1.1  uch 	void *arg;
    195  1.1  uch {
    196  1.1  uch 	struct tc5165buf_softc *sc = arg;
    197  1.1  uch 
    198  1.1  uch 	return tc5165buf_poll(sc->sc_chip);
    199  1.1  uch }
    200  1.1  uch 
    201  1.1  uch int
    202  1.1  uch tc5165buf_poll(arg)
    203  1.1  uch 	void *arg;
    204  1.1  uch {
    205  1.1  uch 	struct tc5165buf_chip *scc = arg;
    206  1.1  uch 	bus_space_tag_t t = scc->scc_cst;
    207  1.1  uch 	bus_space_handle_t h = scc->scc_csh;
    208  1.1  uch 	u_int16_t mask, rpat, edge;
    209  1.3  uch 	int i, j, type, val;
    210  1.1  uch 	skbd_tag_t controller;
    211  1.1  uch 
    212  1.1  uch 	if (!scc->scc_enabled) {
    213  1.1  uch 		return 0;
    214  1.1  uch 	}
    215  1.3  uch 
    216  1.3  uch 	controller = &scc->scc_controller;
    217  1.3  uch 	skbd_input_hook(controller);
    218  1.1  uch 
    219  1.3  uch 	/* clear scanlines */
    220  1.3  uch 	(void)bus_space_read_2(t, h, 0);
    221  1.3  uch 	delay(3);
    222  1.3  uch 
    223  1.3  uch 	for (i = 0; i < TC5165_COLUMN_MAX; i++) {
    224  1.3  uch 		rpat = bus_space_read_2(t, h, 2 << i);
    225  1.3  uch 		delay(3);
    226  1.3  uch 		(void)bus_space_read_2(t, h, 0);
    227  1.3  uch 		delay(3);
    228  1.3  uch 		if ((edge = (rpat ^ scc->scc_buf[i]))) {
    229  1.1  uch 			scc->scc_buf[i] = rpat;
    230  1.3  uch 
    231  1.3  uch 			for (j = 0, mask = 1; j < TC5165_ROW_MAX;
    232  1.3  uch 			     j++, mask <<= 1) {
    233  1.1  uch 				if (mask & edge) {
    234  1.1  uch 					type = mask & rpat ? 1 : 0;
    235  1.3  uch 					val = j * TC5165_COLUMN_MAX + i;
    236  1.3  uch 					DPRINTF(("%d %d\n", j, i));
    237  1.1  uch 					skbd_input(controller, type, val);
    238  1.1  uch 				}
    239  1.1  uch 			}
    240  1.1  uch 		}
    241  1.3  uch 	}
    242  1.1  uch 
    243  1.3  uch 	return POLL_CONT;
    244  1.1  uch }
    245