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