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