Home | History | Annotate | Line # | Download | only in dev
tc5165buf.c revision 1.6.2.2
      1  1.6.2.2  bouyer /*	$NetBSD: tc5165buf.c,v 1.6.2.2 2000/11/20 20:46:16 bouyer Exp $ */
      2  1.6.2.2  bouyer 
      3  1.6.2.2  bouyer /*
      4  1.6.2.2  bouyer  * Copyright (c) 1999, 2000, by UCHIYAMA Yasushi
      5  1.6.2.2  bouyer  * All rights reserved.
      6  1.6.2.2  bouyer  *
      7  1.6.2.2  bouyer  * Redistribution and use in source and binary forms, with or without
      8  1.6.2.2  bouyer  * modification, are permitted provided that the following conditions
      9  1.6.2.2  bouyer  * are met:
     10  1.6.2.2  bouyer  * 1. Redistributions of source code must retain the above copyright
     11  1.6.2.2  bouyer  *    notice, this list of conditions and the following disclaimer.
     12  1.6.2.2  bouyer  * 2. The name of the developer may NOT be used to endorse or promote products
     13  1.6.2.2  bouyer  *    derived from this software without specific prior written permission.
     14  1.6.2.2  bouyer  *
     15  1.6.2.2  bouyer  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     16  1.6.2.2  bouyer  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     17  1.6.2.2  bouyer  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     18  1.6.2.2  bouyer  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     19  1.6.2.2  bouyer  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     20  1.6.2.2  bouyer  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     21  1.6.2.2  bouyer  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     22  1.6.2.2  bouyer  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     23  1.6.2.2  bouyer  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     24  1.6.2.2  bouyer  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     25  1.6.2.2  bouyer  * SUCH DAMAGE.
     26  1.6.2.2  bouyer  *
     27  1.6.2.2  bouyer  */
     28  1.6.2.2  bouyer 
     29  1.6.2.2  bouyer /*
     30  1.6.2.2  bouyer  * Device driver for TOSHIBA TC5165BFTS, PHILIPS 74ALVC16241/245
     31  1.6.2.2  bouyer  * buffer chip
     32  1.6.2.2  bouyer  */
     33  1.6.2.2  bouyer 
     34  1.6.2.2  bouyer #include "opt_tx39_debug.h"
     35  1.6.2.2  bouyer #include "opt_use_poll.h"
     36  1.6.2.2  bouyer 
     37  1.6.2.2  bouyer #include <sys/param.h>
     38  1.6.2.2  bouyer #include <sys/systm.h>
     39  1.6.2.2  bouyer #include <sys/callout.h>
     40  1.6.2.2  bouyer #include <sys/device.h>
     41  1.6.2.2  bouyer 
     42  1.6.2.2  bouyer #include <machine/bus.h>
     43  1.6.2.2  bouyer #include <machine/intr.h>
     44  1.6.2.2  bouyer 
     45  1.6.2.2  bouyer #include <hpcmips/tx/tx39var.h>
     46  1.6.2.2  bouyer #include <hpcmips/tx/txcsbusvar.h>
     47  1.6.2.2  bouyer 
     48  1.6.2.2  bouyer #include <hpcmips/dev/tc5165bufvar.h>
     49  1.6.2.2  bouyer #include <hpcmips/dev/hpckbdvar.h>
     50  1.6.2.2  bouyer 
     51  1.6.2.2  bouyer #define TC5165_ROW_MAX		16
     52  1.6.2.2  bouyer #define TC5165_COLUMN_MAX	8
     53  1.6.2.2  bouyer 
     54  1.6.2.2  bouyer #ifdef TC5165DEBUG
     55  1.6.2.2  bouyer #define	DPRINTF(arg) printf arg
     56  1.6.2.2  bouyer #else
     57  1.6.2.2  bouyer #define	DPRINTF(arg)
     58  1.6.2.2  bouyer #endif
     59  1.6.2.2  bouyer 
     60  1.6.2.2  bouyer struct tc5165buf_chip {
     61  1.6.2.2  bouyer 	bus_space_tag_t		scc_cst;
     62  1.6.2.2  bouyer 	bus_space_handle_t	scc_csh;
     63  1.6.2.2  bouyer 	u_int16_t		scc_buf[TC5165_COLUMN_MAX];
     64  1.6.2.2  bouyer 	int			scc_enabled;
     65  1.6.2.2  bouyer 	int			scc_queued;
     66  1.6.2.2  bouyer 	struct callout		scc_soft_ch;
     67  1.6.2.2  bouyer 	struct hpckbd_ic_if	scc_if;
     68  1.6.2.2  bouyer 	struct hpckbd_if	*scc_hpckbd;
     69  1.6.2.2  bouyer };
     70  1.6.2.2  bouyer 
     71  1.6.2.2  bouyer struct tc5165buf_softc {
     72  1.6.2.2  bouyer 	struct device		sc_dev;
     73  1.6.2.2  bouyer 	struct tc5165buf_chip	*sc_chip;
     74  1.6.2.2  bouyer 	tx_chipset_tag_t	sc_tc;
     75  1.6.2.2  bouyer 	void			*sc_ih;
     76  1.6.2.2  bouyer };
     77  1.6.2.2  bouyer 
     78  1.6.2.2  bouyer int	tc5165buf_match	__P((struct device*, struct cfdata*, void*));
     79  1.6.2.2  bouyer void	tc5165buf_attach __P((struct device*, struct device*, void*));
     80  1.6.2.2  bouyer int	tc5165buf_intr __P((void*));
     81  1.6.2.2  bouyer int	tc5165buf_poll __P((void*));
     82  1.6.2.2  bouyer void	tc5165buf_soft __P((void*));
     83  1.6.2.2  bouyer void	tc5165buf_ifsetup __P((struct tc5165buf_chip*));
     84  1.6.2.2  bouyer 
     85  1.6.2.2  bouyer int	tc5165buf_input_establish __P((void*, struct hpckbd_if*));
     86  1.6.2.2  bouyer 
     87  1.6.2.2  bouyer struct tc5165buf_chip tc5165buf_chip;
     88  1.6.2.2  bouyer 
     89  1.6.2.2  bouyer struct cfattach tc5165buf_ca = {
     90  1.6.2.2  bouyer 	sizeof(struct tc5165buf_softc), tc5165buf_match, tc5165buf_attach
     91  1.6.2.2  bouyer };
     92  1.6.2.2  bouyer 
     93  1.6.2.2  bouyer int
     94  1.6.2.2  bouyer tc5165buf_match(parent, cf, aux)
     95  1.6.2.2  bouyer 	struct device *parent;
     96  1.6.2.2  bouyer 	struct cfdata *cf;
     97  1.6.2.2  bouyer 	void *aux;
     98  1.6.2.2  bouyer {
     99  1.6.2.2  bouyer 	return 1;
    100  1.6.2.2  bouyer }
    101  1.6.2.2  bouyer 
    102  1.6.2.2  bouyer void
    103  1.6.2.2  bouyer tc5165buf_attach(parent, self, aux)
    104  1.6.2.2  bouyer 	struct device *parent;
    105  1.6.2.2  bouyer 	struct device *self;
    106  1.6.2.2  bouyer 	void *aux;
    107  1.6.2.2  bouyer {
    108  1.6.2.2  bouyer 	struct cs_attach_args *ca = aux;
    109  1.6.2.2  bouyer 	struct tc5165buf_softc *sc = (void*)self;
    110  1.6.2.2  bouyer 	struct hpckbd_attach_args haa;
    111  1.6.2.2  bouyer 
    112  1.6.2.2  bouyer 	printf(": ");
    113  1.6.2.2  bouyer 	sc->sc_tc = ca->ca_tc;
    114  1.6.2.2  bouyer 	sc->sc_chip = &tc5165buf_chip;
    115  1.6.2.2  bouyer 
    116  1.6.2.2  bouyer 	callout_init(&sc->sc_chip->scc_soft_ch);
    117  1.6.2.2  bouyer 
    118  1.6.2.2  bouyer 	sc->sc_chip->scc_cst = ca->ca_csio.cstag;
    119  1.6.2.2  bouyer 
    120  1.6.2.2  bouyer 	if (bus_space_map(sc->sc_chip->scc_cst, ca->ca_csio.csbase,
    121  1.6.2.2  bouyer 			  ca->ca_csio.cssize, 0, &sc->sc_chip->scc_csh)) {
    122  1.6.2.2  bouyer 		printf("can't map i/o space\n");
    123  1.6.2.2  bouyer 		return;
    124  1.6.2.2  bouyer 	}
    125  1.6.2.2  bouyer 
    126  1.6.2.2  bouyer 	sc->sc_chip->scc_enabled = 0;
    127  1.6.2.2  bouyer 
    128  1.6.2.2  bouyer 	if (ca->ca_irq1 != -1) {
    129  1.6.2.2  bouyer 		sc->sc_ih = tx_intr_establish(sc->sc_tc, ca->ca_irq1,
    130  1.6.2.2  bouyer 					      IST_EDGE, IPL_TTY,
    131  1.6.2.2  bouyer 					      tc5165buf_intr, sc);
    132  1.6.2.2  bouyer 		printf("interrupt mode");
    133  1.6.2.2  bouyer 	} else {
    134  1.6.2.2  bouyer 		sc->sc_ih = tx39_poll_establish(sc->sc_tc, 1, IPL_TTY,
    135  1.6.2.2  bouyer 						tc5165buf_intr, sc);
    136  1.6.2.2  bouyer 		printf("polling mode");
    137  1.6.2.2  bouyer 	}
    138  1.6.2.2  bouyer 
    139  1.6.2.2  bouyer 	if (!sc->sc_ih) {
    140  1.6.2.2  bouyer 		printf(" can't establish interrupt\n");
    141  1.6.2.2  bouyer 		return;
    142  1.6.2.2  bouyer 	}
    143  1.6.2.2  bouyer 
    144  1.6.2.2  bouyer 	printf("\n");
    145  1.6.2.2  bouyer 
    146  1.6.2.2  bouyer 	/* setup upper interface */
    147  1.6.2.2  bouyer 	tc5165buf_ifsetup(sc->sc_chip);
    148  1.6.2.2  bouyer 
    149  1.6.2.2  bouyer 	haa.haa_ic = &sc->sc_chip->scc_if;
    150  1.6.2.2  bouyer 
    151  1.6.2.2  bouyer 	config_found(self, &haa, hpckbd_print);
    152  1.6.2.2  bouyer }
    153  1.6.2.2  bouyer 
    154  1.6.2.2  bouyer void
    155  1.6.2.2  bouyer tc5165buf_ifsetup(scc)
    156  1.6.2.2  bouyer 	struct tc5165buf_chip *scc;
    157  1.6.2.2  bouyer {
    158  1.6.2.2  bouyer 	scc->scc_if.hii_ctx		= scc;
    159  1.6.2.2  bouyer 	scc->scc_if.hii_establish	= tc5165buf_input_establish;
    160  1.6.2.2  bouyer 	scc->scc_if.hii_poll		= tc5165buf_poll;
    161  1.6.2.2  bouyer }
    162  1.6.2.2  bouyer 
    163  1.6.2.2  bouyer int
    164  1.6.2.2  bouyer tc5165buf_cnattach(addr)
    165  1.6.2.2  bouyer 	paddr_t addr;
    166  1.6.2.2  bouyer {
    167  1.6.2.2  bouyer 	struct tc5165buf_chip *scc = &tc5165buf_chip;
    168  1.6.2.2  bouyer 
    169  1.6.2.2  bouyer 	scc->scc_csh = MIPS_PHYS_TO_KSEG1(addr);
    170  1.6.2.2  bouyer 
    171  1.6.2.2  bouyer 	tc5165buf_ifsetup(scc);
    172  1.6.2.2  bouyer 
    173  1.6.2.2  bouyer 	hpckbd_cnattach(&scc->scc_if);
    174  1.6.2.2  bouyer 
    175  1.6.2.2  bouyer 	return 0;
    176  1.6.2.2  bouyer }
    177  1.6.2.2  bouyer 
    178  1.6.2.2  bouyer int
    179  1.6.2.2  bouyer tc5165buf_input_establish(ic, kbdif)
    180  1.6.2.2  bouyer 	void *ic;
    181  1.6.2.2  bouyer 	struct hpckbd_if *kbdif;
    182  1.6.2.2  bouyer {
    183  1.6.2.2  bouyer 	struct tc5165buf_chip *scc = ic;
    184  1.6.2.2  bouyer 
    185  1.6.2.2  bouyer 	/* save hpckbd interface */
    186  1.6.2.2  bouyer 	scc->scc_hpckbd = kbdif;
    187  1.6.2.2  bouyer 
    188  1.6.2.2  bouyer 	scc->scc_enabled = 1;
    189  1.6.2.2  bouyer 
    190  1.6.2.2  bouyer 	return 0;
    191  1.6.2.2  bouyer }
    192  1.6.2.2  bouyer 
    193  1.6.2.2  bouyer int
    194  1.6.2.2  bouyer tc5165buf_intr(arg)
    195  1.6.2.2  bouyer 	void *arg;
    196  1.6.2.2  bouyer {
    197  1.6.2.2  bouyer 	struct tc5165buf_softc *sc = arg;
    198  1.6.2.2  bouyer 	struct tc5165buf_chip *scc = sc->sc_chip;
    199  1.6.2.2  bouyer 
    200  1.6.2.2  bouyer 	if (!scc->scc_enabled || scc->scc_queued)
    201  1.6.2.2  bouyer 		return 0;
    202  1.6.2.2  bouyer 
    203  1.6.2.2  bouyer 	scc->scc_queued = 1;
    204  1.6.2.2  bouyer 	callout_reset(&scc->scc_soft_ch, 1, tc5165buf_soft, scc);
    205  1.6.2.2  bouyer 
    206  1.6.2.2  bouyer 	return 0;
    207  1.6.2.2  bouyer }
    208  1.6.2.2  bouyer 
    209  1.6.2.2  bouyer int
    210  1.6.2.2  bouyer tc5165buf_poll(arg)
    211  1.6.2.2  bouyer 	void *arg;
    212  1.6.2.2  bouyer {
    213  1.6.2.2  bouyer 	struct tc5165buf_chip *scc = arg;
    214  1.6.2.2  bouyer 
    215  1.6.2.2  bouyer 	if (!scc->scc_enabled)
    216  1.6.2.2  bouyer 		return POLL_CONT;
    217  1.6.2.2  bouyer 
    218  1.6.2.2  bouyer 	tc5165buf_soft(arg);
    219  1.6.2.2  bouyer 
    220  1.6.2.2  bouyer 	return POLL_CONT;
    221  1.6.2.2  bouyer }
    222  1.6.2.2  bouyer 
    223  1.6.2.2  bouyer void
    224  1.6.2.2  bouyer tc5165buf_soft(arg)
    225  1.6.2.2  bouyer 	void *arg;
    226  1.6.2.2  bouyer {
    227  1.6.2.2  bouyer 	struct tc5165buf_chip *scc = arg;
    228  1.6.2.2  bouyer 	bus_space_tag_t t = scc->scc_cst;
    229  1.6.2.2  bouyer 	bus_space_handle_t h = scc->scc_csh;
    230  1.6.2.2  bouyer 	u_int16_t mask, rpat, edge;
    231  1.6.2.2  bouyer 	int i, j, type, val;
    232  1.6.2.2  bouyer 	int s;
    233  1.6.2.2  bouyer 
    234  1.6.2.2  bouyer 	hpckbd_input_hook(scc->scc_hpckbd);
    235  1.6.2.2  bouyer 
    236  1.6.2.2  bouyer 	/* clear scanlines */
    237  1.6.2.2  bouyer 	(void)bus_space_read_2(t, h, 0);
    238  1.6.2.2  bouyer 	delay(3);
    239  1.6.2.2  bouyer 
    240  1.6.2.2  bouyer 	for (i = 0; i < TC5165_COLUMN_MAX; i++) {
    241  1.6.2.2  bouyer 		rpat = bus_space_read_2(t, h, 2 << i);
    242  1.6.2.2  bouyer 		delay(3);
    243  1.6.2.2  bouyer 		(void)bus_space_read_2(t, h, 0);
    244  1.6.2.2  bouyer 		delay(3);
    245  1.6.2.2  bouyer 		if ((edge = (rpat ^ scc->scc_buf[i]))) {
    246  1.6.2.2  bouyer 			scc->scc_buf[i] = rpat;
    247  1.6.2.2  bouyer 			for (j = 0, mask = 1; j < TC5165_ROW_MAX;
    248  1.6.2.2  bouyer 			     j++, mask <<= 1) {
    249  1.6.2.2  bouyer 				if (mask & edge) {
    250  1.6.2.2  bouyer 					type = mask & rpat ? 1 : 0;
    251  1.6.2.2  bouyer 					val = j * TC5165_COLUMN_MAX + i;
    252  1.6.2.2  bouyer 					DPRINTF(("%d %d\n", j, i));
    253  1.6.2.2  bouyer 					hpckbd_input(scc->scc_hpckbd,
    254  1.6.2.2  bouyer 						     type, val);
    255  1.6.2.2  bouyer 				}
    256  1.6.2.2  bouyer 			}
    257  1.6.2.2  bouyer 		}
    258  1.6.2.2  bouyer 	}
    259  1.6.2.2  bouyer 
    260  1.6.2.2  bouyer 	s = spltty();
    261  1.6.2.2  bouyer 	scc->scc_queued = 0;
    262  1.6.2.2  bouyer 	splx(s);
    263  1.6.2.2  bouyer }
    264