Home | History | Annotate | Line # | Download | only in sun
ms_zs.c revision 1.3.6.1
      1  1.3.6.1   nathanw /*	$NetBSD: ms_zs.c,v 1.3.6.1 2001/10/08 20:11:31 nathanw Exp $	*/
      2      1.1       mrg 
      3      1.1       mrg /*
      4      1.1       mrg  * Copyright (c) 1992, 1993
      5      1.1       mrg  *	The Regents of the University of California.  All rights reserved.
      6      1.1       mrg  *
      7      1.1       mrg  * This software was developed by the Computer Systems Engineering group
      8      1.1       mrg  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
      9      1.1       mrg  * contributed to Berkeley.
     10      1.1       mrg  *
     11      1.1       mrg  * All advertising materials mentioning features or use of this software
     12      1.1       mrg  * must display the following acknowledgement:
     13      1.1       mrg  *	This product includes software developed by the University of
     14      1.1       mrg  *	California, Lawrence Berkeley Laboratory.
     15      1.1       mrg  *
     16      1.1       mrg  * Redistribution and use in source and binary forms, with or without
     17      1.1       mrg  * modification, are permitted provided that the following conditions
     18      1.1       mrg  * are met:
     19      1.1       mrg  * 1. Redistributions of source code must retain the above copyright
     20      1.1       mrg  *    notice, this list of conditions and the following disclaimer.
     21      1.1       mrg  * 2. Redistributions in binary form must reproduce the above copyright
     22      1.1       mrg  *    notice, this list of conditions and the following disclaimer in the
     23      1.1       mrg  *    documentation and/or other materials provided with the distribution.
     24      1.1       mrg  * 3. All advertising materials mentioning features or use of this software
     25      1.1       mrg  *    must display the following acknowledgement:
     26      1.1       mrg  *	This product includes software developed by the University of
     27      1.1       mrg  *	California, Berkeley and its contributors.
     28      1.1       mrg  * 4. Neither the name of the University nor the names of its contributors
     29      1.1       mrg  *    may be used to endorse or promote products derived from this software
     30      1.1       mrg  *    without specific prior written permission.
     31      1.1       mrg  *
     32      1.1       mrg  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     33      1.1       mrg  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     34      1.1       mrg  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     35      1.1       mrg  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     36      1.1       mrg  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     37      1.1       mrg  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     38      1.1       mrg  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     39      1.1       mrg  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     40      1.1       mrg  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     41      1.1       mrg  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     42      1.1       mrg  * SUCH DAMAGE.
     43      1.1       mrg  *
     44      1.1       mrg  *	@(#)ms.c	8.1 (Berkeley) 6/11/93
     45      1.1       mrg  */
     46      1.1       mrg 
     47      1.1       mrg /*
     48      1.1       mrg  * Mouse driver (/dev/mouse)
     49      1.1       mrg  */
     50      1.1       mrg 
     51      1.1       mrg /*
     52      1.1       mrg  * Zilog Z8530 Dual UART driver (mouse interface)
     53      1.1       mrg  *
     54      1.1       mrg  * This is the "slave" driver that will be attached to
     55      1.1       mrg  * the "zsc" driver for a Sun mouse.
     56      1.1       mrg  */
     57      1.1       mrg 
     58      1.1       mrg #include <sys/param.h>
     59      1.1       mrg #include <sys/systm.h>
     60      1.1       mrg #include <sys/conf.h>
     61      1.1       mrg #include <sys/device.h>
     62      1.1       mrg #include <sys/ioctl.h>
     63      1.1       mrg #include <sys/kernel.h>
     64      1.1       mrg #include <sys/proc.h>
     65      1.1       mrg #include <sys/signal.h>
     66      1.1       mrg #include <sys/signalvar.h>
     67      1.1       mrg #include <sys/time.h>
     68      1.1       mrg #include <sys/select.h>
     69      1.1       mrg #include <sys/syslog.h>
     70      1.1       mrg 
     71      1.1       mrg #include <machine/vuid_event.h>
     72      1.1       mrg 
     73      1.1       mrg #include <dev/ic/z8530reg.h>
     74      1.1       mrg #include <machine/z8530var.h>
     75      1.1       mrg #include <dev/sun/event_var.h>
     76      1.1       mrg #include <dev/sun/msvar.h>
     77      1.1       mrg 
     78      1.1       mrg static void ms_zs_rxint __P((struct zs_chanstate *));
     79      1.1       mrg static void ms_zs_stint __P((struct zs_chanstate *, int));
     80      1.1       mrg static void ms_zs_txint __P((struct zs_chanstate *));
     81      1.1       mrg static void ms_zs_softint __P((struct zs_chanstate *));
     82      1.1       mrg 
     83      1.1       mrg struct zsops zsops_ms = {
     84      1.1       mrg 	ms_zs_rxint,	/* receive char available */
     85      1.1       mrg 	ms_zs_stint,	/* external/status */
     86      1.1       mrg 	ms_zs_txint,	/* xmit buffer empty */
     87      1.1       mrg 	ms_zs_softint,	/* process software interrupt */
     88      1.1       mrg };
     89      1.1       mrg 
     90  1.3.6.1   nathanw /* Fall-back baud rate */
     91      1.2      matt int	ms_zs_bps = MS_BPS;
     92      1.2      matt 
     93      1.1       mrg static int	ms_zs_match(struct device *, struct cfdata *, void *);
     94      1.1       mrg static void	ms_zs_attach(struct device *, struct device *, void *);
     95      1.1       mrg 
     96      1.1       mrg struct cfattach ms_zs_ca = {
     97      1.1       mrg 	sizeof(struct ms_softc), ms_zs_match, ms_zs_attach
     98      1.1       mrg };
     99      1.1       mrg 
    100      1.1       mrg /*
    101      1.1       mrg  * ms_match: how is this zs channel configured?
    102      1.1       mrg  */
    103      1.1       mrg int
    104      1.1       mrg ms_zs_match(parent, cf, aux)
    105      1.1       mrg 	struct device *parent;
    106      1.1       mrg 	struct cfdata *cf;
    107      1.1       mrg 	void   *aux;
    108      1.1       mrg {
    109      1.1       mrg 	struct zsc_attach_args *args = aux;
    110      1.1       mrg 
    111      1.2      matt 	if (ms_zs_bps == 0)
    112      1.2      matt 		return 0;
    113      1.2      matt 
    114      1.1       mrg 	/* Exact match required for keyboard. */
    115      1.1       mrg 	if (cf->cf_loc[ZSCCF_CHANNEL] == args->channel)
    116      1.1       mrg 		return 2;
    117      1.1       mrg 
    118      1.1       mrg 	return 0;
    119      1.1       mrg }
    120      1.1       mrg 
    121      1.1       mrg void
    122      1.1       mrg ms_zs_attach(parent, self, aux)
    123      1.1       mrg 	struct device *parent, *self;
    124      1.1       mrg 	void   *aux;
    125      1.1       mrg 
    126      1.1       mrg {
    127      1.1       mrg 	struct zsc_softc *zsc = (void *) parent;
    128      1.1       mrg 	struct ms_softc *ms = (void *) self;
    129      1.1       mrg 	struct zsc_attach_args *args = aux;
    130      1.1       mrg 	struct zs_chanstate *cs;
    131      1.1       mrg 	struct cfdata *cf;
    132      1.1       mrg 	int channel, ms_unit;
    133      1.1       mrg 	int reset, s;
    134  1.3.6.1   nathanw 	int bps;
    135      1.1       mrg 
    136      1.1       mrg 	cf = ms->ms_dev.dv_cfdata;
    137      1.1       mrg 	ms_unit = ms->ms_dev.dv_unit;
    138      1.1       mrg 	channel = args->channel;
    139      1.1       mrg 	cs = zsc->zsc_cs[channel];
    140      1.1       mrg 	cs->cs_private = ms;
    141      1.1       mrg 	cs->cs_ops = &zsops_ms;
    142      1.1       mrg 	ms->ms_cs = cs;
    143  1.3.6.1   nathanw 	if ((bps = cs->cs_defspeed) == 0)
    144  1.3.6.1   nathanw 		bps = ms_zs_bps;
    145      1.1       mrg 
    146  1.3.6.1   nathanw 	printf(": baud rate %d\n", bps);
    147      1.1       mrg 
    148      1.1       mrg 	/* Initialize the speed, etc. */
    149      1.1       mrg 	s = splzs();
    150      1.1       mrg 	/* May need reset... */
    151      1.1       mrg 	reset = (channel == 0) ?
    152      1.1       mrg 		ZSWR9_A_RESET : ZSWR9_B_RESET;
    153      1.1       mrg 	zs_write_reg(cs, 9, reset);
    154      1.1       mrg 	/* These are OK as set by zscc: WR3, WR4, WR5 */
    155      1.1       mrg 	/* We don't care about status or tx interrupts. */
    156      1.1       mrg 	cs->cs_preg[1] = ZSWR1_RIE;
    157  1.3.6.1   nathanw 	(void) zs_set_speed(cs, bps);
    158      1.1       mrg 	zs_loadchannelregs(cs);
    159      1.1       mrg 	splx(s);
    160      1.1       mrg 
    161      1.1       mrg 	/* Initialize translator. */
    162      1.1       mrg 	ms->ms_byteno = -1;
    163      1.1       mrg }
    164      1.1       mrg 
    165      1.1       mrg /****************************************************************
    166      1.1       mrg  * Interface to the lower layer (zscc)
    167      1.1       mrg  ****************************************************************/
    168      1.1       mrg 
    169      1.1       mrg static void
    170      1.1       mrg ms_zs_rxint(cs)
    171      1.3  augustss 	struct zs_chanstate *cs;
    172      1.1       mrg {
    173      1.3  augustss 	struct ms_softc *ms;
    174      1.3  augustss 	int put, put_next;
    175      1.3  augustss 	u_char c, rr1;
    176      1.1       mrg 
    177      1.1       mrg 	ms = cs->cs_private;
    178      1.1       mrg 	put = ms->ms_rbput;
    179      1.1       mrg 
    180      1.1       mrg 	/*
    181      1.1       mrg 	 * First read the status, because reading the received char
    182      1.1       mrg 	 * destroys the status of this char.
    183      1.1       mrg 	 */
    184      1.1       mrg 	rr1 = zs_read_reg(cs, 1);
    185      1.1       mrg 	c = zs_read_data(cs);
    186      1.1       mrg 
    187      1.1       mrg 	if (rr1 & (ZSRR1_FE | ZSRR1_DO | ZSRR1_PE)) {
    188      1.1       mrg 		/* Clear the receive error. */
    189      1.1       mrg 		zs_write_csr(cs, ZSWR0_RESET_ERRORS);
    190      1.1       mrg 	}
    191      1.1       mrg 
    192      1.1       mrg 	ms->ms_rbuf[put] = (c << 8) | rr1;
    193      1.1       mrg 	put_next = (put + 1) & MS_RX_RING_MASK;
    194      1.1       mrg 
    195      1.1       mrg 	/* Would overrun if increment makes (put==get). */
    196      1.1       mrg 	if (put_next == ms->ms_rbget) {
    197      1.1       mrg 		ms->ms_intr_flags |= INTR_RX_OVERRUN;
    198      1.1       mrg 	} else {
    199      1.1       mrg 		/* OK, really increment. */
    200      1.1       mrg 		put = put_next;
    201      1.1       mrg 	}
    202      1.1       mrg 
    203      1.1       mrg 	/* Done reading. */
    204      1.1       mrg 	ms->ms_rbput = put;
    205      1.1       mrg 
    206      1.1       mrg 	/* Ask for softint() call. */
    207      1.1       mrg 	cs->cs_softreq = 1;
    208      1.1       mrg }
    209      1.1       mrg 
    210      1.1       mrg static void
    211      1.1       mrg ms_zs_txint(cs)
    212      1.3  augustss 	struct zs_chanstate *cs;
    213      1.1       mrg {
    214      1.3  augustss 	struct ms_softc *ms;
    215      1.1       mrg 
    216      1.1       mrg 	ms = cs->cs_private;
    217      1.1       mrg 	zs_write_csr(cs, ZSWR0_RESET_TXINT);
    218      1.1       mrg 	ms->ms_intr_flags |= INTR_TX_EMPTY;
    219      1.1       mrg 	/* Ask for softint() call. */
    220      1.1       mrg 	cs->cs_softreq = 1;
    221      1.1       mrg }
    222      1.1       mrg 
    223      1.1       mrg static void
    224      1.1       mrg ms_zs_stint(cs, force)
    225      1.3  augustss 	struct zs_chanstate *cs;
    226      1.1       mrg 	int force;
    227      1.1       mrg {
    228      1.3  augustss 	struct ms_softc *ms;
    229      1.3  augustss 	int rr0;
    230      1.1       mrg 
    231      1.1       mrg 	ms = cs->cs_private;
    232      1.1       mrg 
    233      1.1       mrg 	rr0 = zs_read_csr(cs);
    234      1.1       mrg 	zs_write_csr(cs, ZSWR0_RESET_STATUS);
    235      1.1       mrg 
    236      1.1       mrg 	/*
    237      1.1       mrg 	 * We have to accumulate status line changes here.
    238      1.1       mrg 	 * Otherwise, if we get multiple status interrupts
    239      1.1       mrg 	 * before the softint runs, we could fail to notice
    240      1.1       mrg 	 * some status line changes in the softint routine.
    241      1.1       mrg 	 * Fix from Bill Studenmund, October 1996.
    242      1.1       mrg 	 */
    243      1.1       mrg 	cs->cs_rr0_delta |= (cs->cs_rr0 ^ rr0);
    244      1.1       mrg 	cs->cs_rr0 = rr0;
    245      1.1       mrg 	ms->ms_intr_flags |= INTR_ST_CHECK;
    246      1.1       mrg 
    247      1.1       mrg 	/* Ask for softint() call. */
    248      1.1       mrg 	cs->cs_softreq = 1;
    249      1.1       mrg }
    250      1.1       mrg 
    251      1.1       mrg static void
    252      1.1       mrg ms_zs_softint(cs)
    253      1.1       mrg 	struct zs_chanstate *cs;
    254      1.1       mrg {
    255      1.3  augustss 	struct ms_softc *ms;
    256      1.3  augustss 	int get, c, s;
    257      1.1       mrg 	int intr_flags;
    258      1.3  augustss 	u_short ring_data;
    259      1.1       mrg 
    260      1.1       mrg 	ms = cs->cs_private;
    261      1.1       mrg 
    262      1.1       mrg 	/* Atomically get and clear flags. */
    263      1.1       mrg 	s = splzs();
    264      1.1       mrg 	intr_flags = ms->ms_intr_flags;
    265      1.1       mrg 	ms->ms_intr_flags = 0;
    266      1.1       mrg 
    267      1.1       mrg 	/* Now lower to spltty for the rest. */
    268      1.1       mrg 	(void) spltty();
    269      1.1       mrg 
    270      1.1       mrg 	/*
    271      1.1       mrg 	 * Copy data from the receive ring to the event layer.
    272      1.1       mrg 	 */
    273      1.1       mrg 	get = ms->ms_rbget;
    274      1.1       mrg 	while (get != ms->ms_rbput) {
    275      1.1       mrg 		ring_data = ms->ms_rbuf[get];
    276      1.1       mrg 		get = (get + 1) & MS_RX_RING_MASK;
    277      1.1       mrg 
    278      1.1       mrg 		/* low byte of ring_data is rr1 */
    279      1.1       mrg 		c = (ring_data >> 8) & 0xff;
    280      1.1       mrg 
    281      1.1       mrg 		if (ring_data & ZSRR1_DO)
    282      1.1       mrg 			intr_flags |= INTR_RX_OVERRUN;
    283      1.1       mrg 		if (ring_data & (ZSRR1_FE | ZSRR1_PE)) {
    284      1.1       mrg 			log(LOG_ERR, "%s: input error (0x%x)\n",
    285      1.1       mrg 				ms->ms_dev.dv_xname, ring_data);
    286      1.1       mrg 			c = -1;	/* signal input error */
    287      1.1       mrg 		}
    288      1.1       mrg 
    289      1.1       mrg 		/* Pass this up to the "middle" layer. */
    290      1.1       mrg 		ms_input(ms, c);
    291      1.1       mrg 	}
    292      1.1       mrg 	if (intr_flags & INTR_RX_OVERRUN) {
    293      1.1       mrg 		log(LOG_ERR, "%s: input overrun\n",
    294      1.1       mrg 		    ms->ms_dev.dv_xname);
    295      1.1       mrg 	}
    296      1.1       mrg 	ms->ms_rbget = get;
    297      1.1       mrg 
    298      1.1       mrg 	if (intr_flags & INTR_TX_EMPTY) {
    299      1.1       mrg 		/*
    300      1.1       mrg 		 * Transmit done.  (Not expected.)
    301      1.1       mrg 		 */
    302      1.1       mrg 		log(LOG_ERR, "%s: transmit interrupt?\n",
    303      1.1       mrg 		    ms->ms_dev.dv_xname);
    304      1.1       mrg 	}
    305      1.1       mrg 
    306      1.1       mrg 	if (intr_flags & INTR_ST_CHECK) {
    307      1.1       mrg 		/*
    308      1.1       mrg 		 * Status line change.  (Not expected.)
    309      1.1       mrg 		 */
    310      1.1       mrg 		log(LOG_ERR, "%s: status interrupt?\n",
    311      1.1       mrg 		    ms->ms_dev.dv_xname);
    312      1.1       mrg 		cs->cs_rr0_delta = 0;
    313      1.1       mrg 	}
    314      1.1       mrg 
    315      1.1       mrg 	splx(s);
    316      1.1       mrg }
    317