2009-03-14 18:35:58 +03:00
|
|
|
/* $NetBSD: sci.c,v 1.52 2009/03/14 15:36:13 dsl Exp $ */
|
1999-09-13 14:30:21 +04:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (C) 1999 T.Horiuchi and SAITOH Masanobu. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1999-09-13 23:13:09 +04:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Charles M. Hannum.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1991 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 20:26:28 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1999-09-13 23:13:09 +04:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* @(#)com.c 7.5 (Berkeley) 5/16/91
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SH internal serial driver
|
|
|
|
*
|
|
|
|
* This code is derived from both z8530tty.c and com.c
|
|
|
|
*/
|
|
|
|
|
2003-07-15 06:54:31 +04:00
|
|
|
#include <sys/cdefs.h>
|
2009-03-14 18:35:58 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: sci.c,v 1.52 2009/03/14 15:36:13 dsl Exp $");
|
2003-07-15 06:54:31 +04:00
|
|
|
|
2001-05-30 19:24:23 +04:00
|
|
|
#include "opt_kgdb.h"
|
1999-09-13 14:30:21 +04:00
|
|
|
#include "opt_sci.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/tty.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/malloc.h>
|
2006-05-15 01:55:09 +04:00
|
|
|
#include <sys/kauth.h>
|
2007-11-19 21:51:36 +03:00
|
|
|
#include <sys/intr.h>
|
1999-09-13 14:30:21 +04:00
|
|
|
|
|
|
|
#include <dev/cons.h>
|
|
|
|
|
2002-02-22 22:43:58 +03:00
|
|
|
#include <sh3/clock.h>
|
1999-09-13 14:30:21 +04:00
|
|
|
#include <sh3/scireg.h>
|
2002-03-24 21:04:39 +03:00
|
|
|
#include <sh3/pfcreg.h>
|
1999-09-13 14:30:21 +04:00
|
|
|
#include <sh3/tmureg.h>
|
2002-03-24 21:04:39 +03:00
|
|
|
#include <sh3/exception.h>
|
1999-09-13 14:30:21 +04:00
|
|
|
|
2002-02-12 18:26:45 +03:00
|
|
|
static void scistart(struct tty *);
|
|
|
|
static int sciparam(struct tty *, struct termios *);
|
1999-09-13 14:30:21 +04:00
|
|
|
|
2002-02-12 18:26:45 +03:00
|
|
|
void scicnprobe(struct consdev *);
|
|
|
|
void scicninit(struct consdev *);
|
|
|
|
void scicnputc(dev_t, int);
|
|
|
|
int scicngetc(dev_t);
|
|
|
|
void scicnpoolc(dev_t, int);
|
|
|
|
int sciintr(void *);
|
1999-09-13 14:30:21 +04:00
|
|
|
|
|
|
|
struct sci_softc {
|
|
|
|
struct device sc_dev; /* boilerplate */
|
|
|
|
struct tty *sc_tty;
|
2002-03-24 21:04:39 +03:00
|
|
|
void *sc_si;
|
2007-07-10 00:51:58 +04:00
|
|
|
callout_t sc_diag_ch;
|
2000-03-23 09:40:33 +03:00
|
|
|
|
1999-09-13 14:30:21 +04:00
|
|
|
#if 0
|
|
|
|
bus_space_tag_t sc_iot; /* ISA i/o space identifier */
|
|
|
|
bus_space_handle_t sc_ioh; /* ISA io handle */
|
|
|
|
|
|
|
|
int sc_drq;
|
|
|
|
|
|
|
|
int sc_frequency;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
u_int sc_overflows,
|
|
|
|
sc_floods,
|
|
|
|
sc_errors; /* number of retries so far */
|
|
|
|
u_char sc_status[7]; /* copy of registers */
|
|
|
|
|
|
|
|
int sc_hwflags;
|
|
|
|
int sc_swflags;
|
|
|
|
u_int sc_fifolen; /* XXX always 0? */
|
|
|
|
|
|
|
|
u_int sc_r_hiwat,
|
|
|
|
sc_r_lowat;
|
|
|
|
u_char *volatile sc_rbget,
|
|
|
|
*volatile sc_rbput;
|
|
|
|
volatile u_int sc_rbavail;
|
|
|
|
u_char *sc_rbuf,
|
|
|
|
*sc_ebuf;
|
|
|
|
|
|
|
|
u_char *sc_tba; /* transmit buffer address */
|
|
|
|
u_int sc_tbc, /* transmit byte count */
|
|
|
|
sc_heldtbc;
|
|
|
|
|
1999-09-13 23:13:09 +04:00
|
|
|
volatile u_char sc_rx_flags, /* receiver blocked */
|
1999-09-13 14:30:21 +04:00
|
|
|
#define RX_TTY_BLOCKED 0x01
|
|
|
|
#define RX_TTY_OVERFLOWED 0x02
|
|
|
|
#define RX_IBUF_BLOCKED 0x04
|
|
|
|
#define RX_IBUF_OVERFLOWED 0x08
|
|
|
|
#define RX_ANY_BLOCK 0x0f
|
1999-09-17 01:17:26 +04:00
|
|
|
sc_tx_busy, /* working on an output chunk */
|
|
|
|
sc_tx_done, /* done with one output chunk */
|
1999-09-13 23:13:09 +04:00
|
|
|
sc_tx_stopped, /* H/W level stop (lost CTS) */
|
|
|
|
sc_st_check, /* got a status interrupt */
|
1999-09-13 14:30:21 +04:00
|
|
|
sc_rx_ready;
|
|
|
|
|
|
|
|
volatile u_char sc_heldchange;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* controller driver configuration */
|
2002-02-12 18:26:45 +03:00
|
|
|
static int sci_match(struct device *, struct cfdata *, void *);
|
|
|
|
static void sci_attach(struct device *, struct device *, void *);
|
1999-09-13 14:30:21 +04:00
|
|
|
|
2002-02-12 18:26:45 +03:00
|
|
|
void sci_break(struct sci_softc *, int);
|
|
|
|
void sci_iflush(struct sci_softc *);
|
1999-09-13 14:30:21 +04:00
|
|
|
|
|
|
|
#define integrate static inline
|
2002-02-12 18:26:45 +03:00
|
|
|
void scisoft(void *);
|
2007-07-10 00:51:58 +04:00
|
|
|
|
2002-02-12 18:26:45 +03:00
|
|
|
integrate void sci_rxsoft(struct sci_softc *, struct tty *);
|
|
|
|
integrate void sci_txsoft(struct sci_softc *, struct tty *);
|
|
|
|
integrate void sci_stsoft(struct sci_softc *, struct tty *);
|
|
|
|
integrate void sci_schedrx(struct sci_softc *);
|
|
|
|
void scidiag(void *);
|
1999-09-13 14:30:21 +04:00
|
|
|
|
|
|
|
#define SCIUNIT_MASK 0x7ffff
|
|
|
|
#define SCIDIALOUT_MASK 0x80000
|
|
|
|
|
|
|
|
#define SCIUNIT(x) (minor(x) & SCIUNIT_MASK)
|
|
|
|
#define SCIDIALOUT(x) (minor(x) & SCIDIALOUT_MASK)
|
|
|
|
|
|
|
|
/* Hardware flag masks */
|
|
|
|
#define SCI_HW_NOIEN 0x01
|
|
|
|
#define SCI_HW_FIFO 0x02
|
|
|
|
#define SCI_HW_FLOW 0x08
|
|
|
|
#define SCI_HW_DEV_OK 0x20
|
|
|
|
#define SCI_HW_CONSOLE 0x40
|
|
|
|
#define SCI_HW_KGDB 0x80
|
|
|
|
|
|
|
|
/* Buffer size for character buffer */
|
|
|
|
#define SCI_RING_SIZE 2048
|
|
|
|
|
|
|
|
/* Stop input when 3/4 of the ring is full; restart when only 1/4 is full. */
|
|
|
|
u_int sci_rbuf_hiwat = (SCI_RING_SIZE * 1) / 4;
|
|
|
|
u_int sci_rbuf_lowat = (SCI_RING_SIZE * 3) / 4;
|
|
|
|
|
2002-04-28 21:10:32 +04:00
|
|
|
#define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
|
1999-09-13 14:30:21 +04:00
|
|
|
int sciconscflag = CONMODE;
|
2000-03-27 20:24:08 +04:00
|
|
|
int sciisconsole = 0;
|
1999-09-13 14:30:21 +04:00
|
|
|
|
2000-02-22 04:37:11 +03:00
|
|
|
#ifdef SCICN_SPEED
|
|
|
|
int scicn_speed = SCICN_SPEED;
|
|
|
|
#else
|
|
|
|
int scicn_speed = 9600;
|
|
|
|
#endif
|
|
|
|
|
1999-09-13 14:30:21 +04:00
|
|
|
#define divrnd(n, q) (((n)*2/(q)+1)/2) /* divide and round off */
|
|
|
|
|
|
|
|
u_int sci_rbuf_size = SCI_RING_SIZE;
|
|
|
|
|
2002-10-02 01:24:43 +04:00
|
|
|
CFATTACH_DECL(sci, sizeof(struct sci_softc),
|
2002-10-02 19:52:22 +04:00
|
|
|
sci_match, sci_attach, NULL, NULL);
|
1999-09-13 14:30:21 +04:00
|
|
|
|
|
|
|
extern struct cfdriver sci_cd;
|
|
|
|
|
2004-12-13 05:14:13 +03:00
|
|
|
static int sci_attached;
|
|
|
|
|
2002-09-06 17:18:43 +04:00
|
|
|
dev_type_open(sciopen);
|
|
|
|
dev_type_close(sciclose);
|
|
|
|
dev_type_read(sciread);
|
|
|
|
dev_type_write(sciwrite);
|
|
|
|
dev_type_ioctl(sciioctl);
|
|
|
|
dev_type_stop(scistop);
|
|
|
|
dev_type_tty(scitty);
|
|
|
|
dev_type_poll(scipoll);
|
|
|
|
|
|
|
|
const struct cdevsw sci_cdevsw = {
|
|
|
|
sciopen, sciclose, sciread, sciwrite, sciioctl,
|
2002-10-23 13:10:23 +04:00
|
|
|
scistop, scitty, scipoll, nommap, ttykqfilter, D_TTY
|
2002-09-06 17:18:43 +04:00
|
|
|
};
|
1999-09-13 14:30:21 +04:00
|
|
|
|
2002-02-12 18:26:45 +03:00
|
|
|
void InitializeSci (unsigned int);
|
1999-09-13 14:30:21 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* following functions are debugging prupose only
|
|
|
|
*/
|
2002-04-28 21:10:32 +04:00
|
|
|
#define CR 0x0D
|
|
|
|
#define I2C_ADRS (*(volatile unsigned int *)0xa8000000)
|
|
|
|
#define USART_ON (unsigned int)~0x08
|
1999-09-13 14:30:21 +04:00
|
|
|
|
2002-02-12 18:26:45 +03:00
|
|
|
void sci_putc(unsigned char);
|
|
|
|
unsigned char sci_getc(void);
|
|
|
|
int SciErrCheck(void);
|
1999-09-13 14:30:21 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* InitializeSci
|
|
|
|
* : unsigned int bps;
|
|
|
|
* : SCI(Serial Communication Interface)
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
2002-02-12 18:26:45 +03:00
|
|
|
InitializeSci(unsigned int bps)
|
1999-09-13 14:30:21 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
/* Initialize SCR */
|
1999-09-17 01:17:26 +04:00
|
|
|
SHREG_SCSCR = 0x00;
|
1999-09-13 14:30:21 +04:00
|
|
|
|
1999-09-17 01:17:26 +04:00
|
|
|
/* Serial Mode Register */
|
|
|
|
SHREG_SCSMR = 0x00; /* Async,8bit,NonParity,Even,1Stop,NoMulti */
|
1999-09-13 14:30:21 +04:00
|
|
|
|
1999-09-17 01:17:26 +04:00
|
|
|
/* Bit Rate Register */
|
2002-02-24 22:35:42 +03:00
|
|
|
SHREG_SCBRR = divrnd(sh_clock_get_pclock(), 32 * bps) - 1;
|
1999-09-13 14:30:21 +04:00
|
|
|
|
1999-09-17 01:17:26 +04:00
|
|
|
/*
|
|
|
|
* wait 1mSec, because Send/Recv must begin 1 bit period after
|
|
|
|
* BRR is set.
|
|
|
|
*/
|
2002-02-22 22:43:58 +03:00
|
|
|
delay(1000);
|
1999-09-13 14:30:21 +04:00
|
|
|
|
2001-06-12 19:17:10 +04:00
|
|
|
/* Send permission, Receive permission ON */
|
1999-09-17 01:17:26 +04:00
|
|
|
SHREG_SCSCR = SCSCR_TE | SCSCR_RE;
|
1999-09-13 14:30:21 +04:00
|
|
|
|
2000-02-22 04:37:11 +03:00
|
|
|
/* Serial Status Register */
|
1999-09-13 14:30:21 +04:00
|
|
|
SHREG_SCSSR &= SCSSR_TDRE; /* Clear Status */
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
I2C_ADRS &= ~0x08; /* enable RS-232C */
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2000-11-23 00:14:25 +03:00
|
|
|
* sci_putc
|
1999-09-13 14:30:21 +04:00
|
|
|
* : unsigned char c;
|
|
|
|
*/
|
|
|
|
void
|
2002-02-12 18:26:45 +03:00
|
|
|
sci_putc(unsigned char c)
|
1999-09-13 14:30:21 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
/* wait for ready */
|
2005-03-11 10:08:33 +03:00
|
|
|
while ((SHREG_SCSSR & SCSSR_TDRE) == 0)
|
1999-09-13 14:30:21 +04:00
|
|
|
;
|
|
|
|
|
|
|
|
/* write send data to send register */
|
|
|
|
SHREG_SCTDR = c;
|
|
|
|
|
|
|
|
/* clear ready flag */
|
|
|
|
SHREG_SCSSR &= ~SCSSR_TDRE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* : SciErrCheck
|
|
|
|
* 0x20 = over run
|
|
|
|
* 0x10 = frame error
|
|
|
|
* 0x80 = parity error
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
SciErrCheck(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
return(SHREG_SCSSR & (SCSSR_ORER | SCSSR_FER | SCSSR_PER));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-11-23 00:14:25 +03:00
|
|
|
* sci_getc
|
1999-09-13 14:30:21 +04:00
|
|
|
*/
|
|
|
|
unsigned char
|
2000-11-23 00:14:25 +03:00
|
|
|
sci_getc(void)
|
1999-09-13 14:30:21 +04:00
|
|
|
{
|
|
|
|
unsigned char c, err_c;
|
|
|
|
|
|
|
|
while (((err_c = SHREG_SCSSR)
|
|
|
|
& (SCSSR_RDRF | SCSSR_ORER | SCSSR_FER | SCSSR_PER)) == 0)
|
|
|
|
;
|
2000-06-19 13:32:00 +04:00
|
|
|
if ((err_c & (SCSSR_ORER | SCSSR_FER | SCSSR_PER)) != 0) {
|
|
|
|
SHREG_SCSSR &= ~(SCSSR_ORER | SCSSR_FER | SCSSR_PER);
|
1999-09-13 14:30:21 +04:00
|
|
|
return(err_c |= 0x80);
|
2000-06-19 13:32:00 +04:00
|
|
|
}
|
1999-09-13 14:30:21 +04:00
|
|
|
|
|
|
|
c = SHREG_SCRDR;
|
|
|
|
|
|
|
|
SHREG_SCSSR &= ~SCSSR_RDRF;
|
|
|
|
|
|
|
|
return(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-02-12 18:26:45 +03:00
|
|
|
sci_match(struct device *parent, struct cfdata *cfp, void *aux)
|
1999-09-13 14:30:21 +04:00
|
|
|
{
|
|
|
|
|
2004-12-13 05:14:13 +03:00
|
|
|
if (strcmp(cfp->cf_name, "sci") || sci_attached)
|
1999-09-13 14:30:21 +04:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-02-12 18:26:45 +03:00
|
|
|
sci_attach(struct device *parent, struct device *self, void *aux)
|
1999-09-13 14:30:21 +04:00
|
|
|
{
|
|
|
|
struct sci_softc *sc = (struct sci_softc *)self;
|
|
|
|
struct tty *tp;
|
|
|
|
|
2004-12-13 05:14:13 +03:00
|
|
|
sci_attached = 1;
|
|
|
|
|
1999-09-13 14:30:21 +04:00
|
|
|
sc->sc_hwflags = 0; /* XXX */
|
|
|
|
sc->sc_swflags = 0; /* XXX */
|
|
|
|
sc->sc_fifolen = 0; /* XXX */
|
|
|
|
|
2000-03-27 20:24:08 +04:00
|
|
|
if (sciisconsole) {
|
|
|
|
SET(sc->sc_hwflags, SCI_HW_CONSOLE);
|
|
|
|
SET(sc->sc_swflags, TIOCFLAG_SOFTCAR);
|
|
|
|
printf("\n%s: console\n", sc->sc_dev.dv_xname);
|
|
|
|
} else {
|
|
|
|
InitializeSci(9600);
|
|
|
|
printf("\n");
|
|
|
|
}
|
1999-09-13 14:30:21 +04:00
|
|
|
|
2007-07-10 00:51:58 +04:00
|
|
|
callout_init(&sc->sc_diag_ch, 0);
|
2000-03-23 09:40:33 +03:00
|
|
|
|
2002-03-24 21:04:39 +03:00
|
|
|
intc_intr_establish(SH_INTEVT_SCI_ERI, IST_LEVEL, IPL_SERIAL, sciintr,
|
|
|
|
sc);
|
|
|
|
intc_intr_establish(SH_INTEVT_SCI_RXI, IST_LEVEL, IPL_SERIAL, sciintr,
|
|
|
|
sc);
|
|
|
|
intc_intr_establish(SH_INTEVT_SCI_TXI, IST_LEVEL, IPL_SERIAL, sciintr,
|
|
|
|
sc);
|
|
|
|
intc_intr_establish(SH_INTEVT_SCI_TEI, IST_LEVEL, IPL_SERIAL, sciintr,
|
|
|
|
sc);
|
1999-09-13 14:30:21 +04:00
|
|
|
|
2007-11-19 21:51:36 +03:00
|
|
|
sc->sc_si = softint_establish(SOFTINT_SERIAL, scisoft, sc);
|
2000-03-27 20:24:08 +04:00
|
|
|
SET(sc->sc_hwflags, SCI_HW_DEV_OK);
|
1999-09-13 14:30:21 +04:00
|
|
|
|
|
|
|
tp = ttymalloc();
|
|
|
|
tp->t_oproc = scistart;
|
|
|
|
tp->t_param = sciparam;
|
|
|
|
tp->t_hwiflow = NULL;
|
|
|
|
|
|
|
|
sc->sc_tty = tp;
|
|
|
|
sc->sc_rbuf = malloc(sci_rbuf_size << 1, M_DEVBUF, M_NOWAIT);
|
|
|
|
if (sc->sc_rbuf == NULL) {
|
|
|
|
printf("%s: unable to allocate ring buffer\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sc->sc_ebuf = sc->sc_rbuf + (sci_rbuf_size << 1);
|
|
|
|
|
|
|
|
tty_attach(tp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start or restart transmission.
|
|
|
|
*/
|
|
|
|
static void
|
2002-02-12 18:26:45 +03:00
|
|
|
scistart(struct tty *tp)
|
1999-09-13 14:30:21 +04:00
|
|
|
{
|
2008-06-13 17:08:57 +04:00
|
|
|
struct sci_softc *sc = device_lookup_private(&sci_cd,SCIUNIT(tp->t_dev));
|
1999-09-13 14:30:21 +04:00
|
|
|
int s;
|
|
|
|
|
|
|
|
s = spltty();
|
|
|
|
if (ISSET(tp->t_state, TS_BUSY | TS_TIMEOUT | TS_TTSTOP))
|
|
|
|
goto out;
|
|
|
|
if (sc->sc_tx_stopped)
|
|
|
|
goto out;
|
2007-11-19 21:51:36 +03:00
|
|
|
if (!ttypull(tp))
|
|
|
|
goto out;
|
1999-09-13 14:30:21 +04:00
|
|
|
|
|
|
|
/* Grab the first contiguous region of buffer space. */
|
|
|
|
{
|
|
|
|
u_char *tba;
|
|
|
|
int tbc;
|
|
|
|
|
|
|
|
tba = tp->t_outq.c_cf;
|
|
|
|
tbc = ndqb(&tp->t_outq, 0);
|
|
|
|
|
|
|
|
(void)splserial();
|
|
|
|
|
|
|
|
sc->sc_tba = tba;
|
|
|
|
sc->sc_tbc = tbc;
|
|
|
|
}
|
|
|
|
|
|
|
|
SET(tp->t_state, TS_BUSY);
|
|
|
|
sc->sc_tx_busy = 1;
|
|
|
|
|
|
|
|
/* Enable transmit completion interrupts if necessary. */
|
|
|
|
SHREG_SCSCR |= SCSCR_TIE | SCSCR_RIE;
|
|
|
|
|
|
|
|
/* Output the first byte of the contiguous buffer. */
|
|
|
|
{
|
|
|
|
if (sc->sc_tbc > 0) {
|
2000-11-23 00:14:25 +03:00
|
|
|
sci_putc(*(sc->sc_tba));
|
1999-09-13 14:30:21 +04:00
|
|
|
sc->sc_tba++;
|
|
|
|
sc->sc_tbc--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set SCI tty parameters from termios.
|
|
|
|
* XXX - Should just copy the whole termios after
|
|
|
|
* making sure all the changes could be done.
|
|
|
|
*/
|
|
|
|
static int
|
2002-02-12 18:26:45 +03:00
|
|
|
sciparam(struct tty *tp, struct termios *t)
|
1999-09-13 14:30:21 +04:00
|
|
|
{
|
2008-06-13 17:08:57 +04:00
|
|
|
struct sci_softc *sc = device_lookup_private(&sci_cd, SCIUNIT(tp->t_dev));
|
1999-09-13 14:30:21 +04:00
|
|
|
int ospeed = t->c_ospeed;
|
|
|
|
int s;
|
|
|
|
|
2006-02-20 19:50:36 +03:00
|
|
|
if (!device_is_active(&sc->sc_dev))
|
1999-09-13 14:30:21 +04:00
|
|
|
return (EIO);
|
|
|
|
|
|
|
|
/* Check requested parameters. */
|
|
|
|
if (ospeed < 0)
|
|
|
|
return (EINVAL);
|
|
|
|
if (t->c_ispeed && t->c_ispeed != t->c_ospeed)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For the console, always force CLOCAL and !HUPCL, so that the port
|
|
|
|
* is always active.
|
|
|
|
*/
|
|
|
|
if (ISSET(sc->sc_swflags, TIOCFLAG_SOFTCAR) ||
|
|
|
|
ISSET(sc->sc_hwflags, SCI_HW_CONSOLE)) {
|
|
|
|
SET(t->c_cflag, CLOCAL);
|
|
|
|
CLR(t->c_cflag, HUPCL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If there were no changes, don't do anything. This avoids dropping
|
|
|
|
* input and improves performance when all we did was frob things like
|
|
|
|
* VMIN and VTIME.
|
|
|
|
*/
|
|
|
|
if (tp->t_ospeed == t->c_ospeed &&
|
|
|
|
tp->t_cflag == t->c_cflag)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* XXX (msaitoh) */
|
|
|
|
lcr = ISSET(sc->sc_lcr, LCR_SBREAK) | cflag2lcr(t->c_cflag);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
s = splserial();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the FIFO threshold based on the receive speed.
|
|
|
|
*
|
|
|
|
* * If it's a low speed, it's probably a mouse or some other
|
|
|
|
* interactive device, so set the threshold low.
|
|
|
|
* * If it's a high speed, trim the trigger level down to prevent
|
|
|
|
* overflows.
|
|
|
|
* * Otherwise set it a bit higher.
|
|
|
|
*/
|
|
|
|
#if 0
|
|
|
|
/* XXX (msaitoh) */
|
|
|
|
if (ISSET(sc->sc_hwflags, SCI_HW_HAYESP))
|
|
|
|
sc->sc_fifo = FIFO_DMA_MODE | FIFO_ENABLE | FIFO_TRIGGER_8;
|
|
|
|
else if (ISSET(sc->sc_hwflags, SCI_HW_FIFO))
|
|
|
|
sc->sc_fifo = FIFO_ENABLE |
|
|
|
|
(t->c_ospeed <= 1200 ? FIFO_TRIGGER_1 :
|
|
|
|
t->c_ospeed <= 38400 ? FIFO_TRIGGER_8 : FIFO_TRIGGER_4);
|
|
|
|
else
|
|
|
|
sc->sc_fifo = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* And copy to tty. */
|
|
|
|
tp->t_ispeed = 0;
|
|
|
|
tp->t_ospeed = t->c_ospeed;
|
|
|
|
tp->t_cflag = t->c_cflag;
|
|
|
|
|
|
|
|
if (!sc->sc_heldchange) {
|
|
|
|
if (sc->sc_tx_busy) {
|
|
|
|
sc->sc_heldtbc = sc->sc_tbc;
|
|
|
|
sc->sc_tbc = 0;
|
|
|
|
sc->sc_heldchange = 1;
|
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
/* XXX (msaitoh) */
|
|
|
|
else
|
|
|
|
sci_loadchannelregs(sc);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ISSET(t->c_cflag, CHWFLOW)) {
|
|
|
|
/* Disable the high water mark. */
|
|
|
|
sc->sc_r_hiwat = 0;
|
|
|
|
sc->sc_r_lowat = 0;
|
|
|
|
if (ISSET(sc->sc_rx_flags, RX_TTY_OVERFLOWED)) {
|
|
|
|
CLR(sc->sc_rx_flags, RX_TTY_OVERFLOWED);
|
|
|
|
sci_schedrx(sc);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sc->sc_r_hiwat = sci_rbuf_hiwat;
|
|
|
|
sc->sc_r_lowat = sci_rbuf_lowat;
|
|
|
|
}
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
#ifdef SCI_DEBUG
|
|
|
|
if (sci_debug)
|
|
|
|
scistatus(sc, "sciparam ");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!ISSET(t->c_cflag, CHWFLOW)) {
|
|
|
|
if (sc->sc_tx_stopped) {
|
|
|
|
sc->sc_tx_stopped = 0;
|
|
|
|
scistart(tp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-02-12 18:26:45 +03:00
|
|
|
sci_iflush(struct sci_softc *sc)
|
1999-09-13 14:30:21 +04:00
|
|
|
{
|
|
|
|
unsigned char err_c;
|
|
|
|
volatile unsigned char c;
|
|
|
|
|
|
|
|
if (((err_c = SHREG_SCSSR)
|
2000-06-19 13:32:00 +04:00
|
|
|
& (SCSSR_RDRF | SCSSR_ORER | SCSSR_FER | SCSSR_PER)) != 0) {
|
1999-09-13 14:30:21 +04:00
|
|
|
|
2000-06-19 13:32:00 +04:00
|
|
|
if ((err_c & (SCSSR_ORER | SCSSR_FER | SCSSR_PER)) != 0) {
|
|
|
|
SHREG_SCSSR &= ~(SCSSR_ORER | SCSSR_FER | SCSSR_PER);
|
1999-09-13 14:30:21 +04:00
|
|
|
return;
|
2000-06-19 13:32:00 +04:00
|
|
|
}
|
1999-09-13 14:30:21 +04:00
|
|
|
|
|
|
|
c = SHREG_SCRDR;
|
|
|
|
|
|
|
|
SHREG_SCSSR &= ~SCSSR_RDRF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2005-12-11 15:16:03 +03:00
|
|
|
sciopen(dev_t dev, int flag, int mode, struct lwp *l)
|
1999-09-13 14:30:21 +04:00
|
|
|
{
|
|
|
|
struct sci_softc *sc;
|
|
|
|
struct tty *tp;
|
|
|
|
int s, s2;
|
|
|
|
int error;
|
|
|
|
|
2008-06-13 17:08:57 +04:00
|
|
|
sc = device_lookup_private(&sci_cd, SCIUNIT(dev));
|
1999-09-13 14:30:21 +04:00
|
|
|
if (sc == 0 || !ISSET(sc->sc_hwflags, SCI_HW_DEV_OK) ||
|
|
|
|
sc->sc_rbuf == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
|
2006-02-20 19:50:36 +03:00
|
|
|
if (!device_is_active(&sc->sc_dev))
|
1999-09-13 14:30:21 +04:00
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
#ifdef KGDB
|
|
|
|
/*
|
|
|
|
* If this is the kgdb port, no other use is permitted.
|
|
|
|
*/
|
|
|
|
if (ISSET(sc->sc_hwflags, SCI_HW_KGDB))
|
|
|
|
return (EBUSY);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
tp = sc->sc_tty;
|
|
|
|
|
2006-10-01 22:56:21 +04:00
|
|
|
if (kauth_authorize_device_tty(l->l_cred, KAUTH_DEVICE_TTY_OPEN, tp))
|
1999-09-13 14:30:21 +04:00
|
|
|
return (EBUSY);
|
|
|
|
|
|
|
|
s = spltty();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do the following iff this is a first open.
|
|
|
|
*/
|
|
|
|
if (!ISSET(tp->t_state, TS_ISOPEN) && tp->t_wopen == 0) {
|
|
|
|
struct termios t;
|
|
|
|
|
|
|
|
tp->t_dev = dev;
|
|
|
|
|
|
|
|
s2 = splserial();
|
|
|
|
|
|
|
|
/* Turn on interrupts. */
|
|
|
|
SHREG_SCSCR |= SCSCR_TIE | SCSCR_RIE;
|
|
|
|
|
|
|
|
splx(s2);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the termios status to the defaults. Add in the
|
|
|
|
* sticky bits from TIOCSFLAGS.
|
|
|
|
*/
|
|
|
|
t.c_ispeed = 0;
|
|
|
|
if (ISSET(sc->sc_hwflags, SCI_HW_CONSOLE)) {
|
2000-02-22 04:37:11 +03:00
|
|
|
t.c_ospeed = scicn_speed;
|
1999-09-13 14:30:21 +04:00
|
|
|
t.c_cflag = sciconscflag;
|
|
|
|
} else {
|
|
|
|
t.c_ospeed = TTYDEF_SPEED;
|
|
|
|
t.c_cflag = TTYDEF_CFLAG;
|
|
|
|
}
|
|
|
|
if (ISSET(sc->sc_swflags, TIOCFLAG_CLOCAL))
|
|
|
|
SET(t.c_cflag, CLOCAL);
|
|
|
|
if (ISSET(sc->sc_swflags, TIOCFLAG_CRTSCTS))
|
|
|
|
SET(t.c_cflag, CRTSCTS);
|
|
|
|
if (ISSET(sc->sc_swflags, TIOCFLAG_MDMBUF))
|
|
|
|
SET(t.c_cflag, MDMBUF);
|
|
|
|
/* Make sure sciparam() will do something. */
|
|
|
|
tp->t_ospeed = 0;
|
|
|
|
(void) sciparam(tp, &t);
|
|
|
|
tp->t_iflag = TTYDEF_IFLAG;
|
|
|
|
tp->t_oflag = TTYDEF_OFLAG;
|
|
|
|
tp->t_lflag = TTYDEF_LFLAG;
|
|
|
|
ttychars(tp);
|
|
|
|
ttsetwater(tp);
|
|
|
|
|
|
|
|
s2 = splserial();
|
|
|
|
|
|
|
|
/* Clear the input ring, and unblock. */
|
|
|
|
sc->sc_rbput = sc->sc_rbget = sc->sc_rbuf;
|
|
|
|
sc->sc_rbavail = sci_rbuf_size;
|
|
|
|
sci_iflush(sc);
|
|
|
|
CLR(sc->sc_rx_flags, RX_ANY_BLOCK);
|
|
|
|
#if 0
|
|
|
|
/* XXX (msaitoh) */
|
|
|
|
sci_hwiflow(sc);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SCI_DEBUG
|
|
|
|
if (sci_debug)
|
|
|
|
scistatus(sc, "sciopen ");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
splx(s2);
|
|
|
|
}
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
error = ttyopen(tp, SCIDIALOUT(dev), ISSET(flag, O_NONBLOCK));
|
|
|
|
if (error)
|
|
|
|
goto bad;
|
|
|
|
|
2000-11-02 03:37:56 +03:00
|
|
|
error = (*tp->t_linesw->l_open)(dev, tp);
|
1999-09-13 14:30:21 +04:00
|
|
|
if (error)
|
|
|
|
goto bad;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
bad:
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2005-12-11 15:16:03 +03:00
|
|
|
sciclose(dev_t dev, int flag, int mode, struct lwp *l)
|
1999-09-13 14:30:21 +04:00
|
|
|
{
|
2008-06-13 17:08:57 +04:00
|
|
|
struct sci_softc *sc = device_lookup_private(&sci_cd, SCIUNIT(dev));
|
1999-09-13 14:30:21 +04:00
|
|
|
struct tty *tp = sc->sc_tty;
|
|
|
|
|
|
|
|
/* XXX This is for cons.c. */
|
|
|
|
if (!ISSET(tp->t_state, TS_ISOPEN))
|
|
|
|
return (0);
|
|
|
|
|
2000-11-02 03:37:56 +03:00
|
|
|
(*tp->t_linesw->l_close)(tp, flag);
|
1999-09-13 14:30:21 +04:00
|
|
|
ttyclose(tp);
|
|
|
|
|
2006-02-20 19:50:36 +03:00
|
|
|
if (!device_is_active(&sc->sc_dev))
|
1999-09-13 14:30:21 +04:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-02-12 18:26:45 +03:00
|
|
|
sciread(dev_t dev, struct uio *uio, int flag)
|
1999-09-13 14:30:21 +04:00
|
|
|
{
|
2008-06-13 17:08:57 +04:00
|
|
|
struct sci_softc *sc = device_lookup_private(&sci_cd, SCIUNIT(dev));
|
1999-09-13 14:30:21 +04:00
|
|
|
struct tty *tp = sc->sc_tty;
|
|
|
|
|
2000-11-02 03:37:56 +03:00
|
|
|
return ((*tp->t_linesw->l_read)(tp, uio, flag));
|
1999-09-13 14:30:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-02-12 18:26:45 +03:00
|
|
|
sciwrite(dev_t dev, struct uio *uio, int flag)
|
1999-09-13 14:30:21 +04:00
|
|
|
{
|
2008-06-13 17:08:57 +04:00
|
|
|
struct sci_softc *sc = device_lookup_private(&sci_cd, SCIUNIT(dev));
|
1999-09-13 14:30:21 +04:00
|
|
|
struct tty *tp = sc->sc_tty;
|
|
|
|
|
2000-11-02 03:37:56 +03:00
|
|
|
return ((*tp->t_linesw->l_write)(tp, uio, flag));
|
1999-09-13 14:30:21 +04:00
|
|
|
}
|
|
|
|
|
2001-05-02 14:32:08 +04:00
|
|
|
int
|
2005-12-11 15:16:03 +03:00
|
|
|
scipoll(dev_t dev, int events, struct lwp *l)
|
2001-05-02 14:32:08 +04:00
|
|
|
{
|
2008-06-13 17:08:57 +04:00
|
|
|
struct sci_softc *sc = device_lookup_private(&sci_cd, SCIUNIT(dev));
|
2001-05-02 14:32:08 +04:00
|
|
|
struct tty *tp = sc->sc_tty;
|
2002-04-28 21:10:32 +04:00
|
|
|
|
2005-12-11 15:16:03 +03:00
|
|
|
return ((*tp->t_linesw->l_poll)(tp, events, l));
|
2001-05-02 14:32:08 +04:00
|
|
|
}
|
|
|
|
|
1999-09-13 14:30:21 +04:00
|
|
|
struct tty *
|
2002-02-12 18:26:45 +03:00
|
|
|
scitty(dev_t dev)
|
1999-09-13 14:30:21 +04:00
|
|
|
{
|
2008-06-13 17:08:57 +04:00
|
|
|
struct sci_softc *sc = device_lookup_private(&sci_cd, SCIUNIT(dev));
|
1999-09-13 14:30:21 +04:00
|
|
|
struct tty *tp = sc->sc_tty;
|
|
|
|
|
|
|
|
return (tp);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2007-03-04 08:59:00 +03:00
|
|
|
sciioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
|
1999-09-13 14:30:21 +04:00
|
|
|
{
|
2008-06-13 17:08:57 +04:00
|
|
|
struct sci_softc *sc = device_lookup_private(&sci_cd, SCIUNIT(dev));
|
1999-09-13 14:30:21 +04:00
|
|
|
struct tty *tp = sc->sc_tty;
|
|
|
|
int error;
|
|
|
|
int s;
|
|
|
|
|
2006-02-20 19:50:36 +03:00
|
|
|
if (!device_is_active(&sc->sc_dev))
|
1999-09-13 14:30:21 +04:00
|
|
|
return (EIO);
|
|
|
|
|
2005-12-11 15:16:03 +03:00
|
|
|
error = (*tp->t_linesw->l_ioctl)(tp, cmd, data, flag, l);
|
2002-03-17 22:40:26 +03:00
|
|
|
if (error != EPASSTHROUGH)
|
1999-09-13 14:30:21 +04:00
|
|
|
return (error);
|
|
|
|
|
2005-12-11 15:16:03 +03:00
|
|
|
error = ttioctl(tp, cmd, data, flag, l);
|
2002-03-17 22:40:26 +03:00
|
|
|
if (error != EPASSTHROUGH)
|
1999-09-13 14:30:21 +04:00
|
|
|
return (error);
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
|
|
|
|
s = splserial();
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case TIOCSBRK:
|
2000-01-07 13:50:14 +03:00
|
|
|
sci_break(sc, 1);
|
1999-09-13 14:30:21 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TIOCCBRK:
|
2000-01-07 13:50:14 +03:00
|
|
|
sci_break(sc, 0);
|
1999-09-13 14:30:21 +04:00
|
|
|
break;
|
2000-01-07 13:50:14 +03:00
|
|
|
|
1999-09-13 14:30:21 +04:00
|
|
|
case TIOCGFLAGS:
|
|
|
|
*(int *)data = sc->sc_swflags;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TIOCSFLAGS:
|
2006-10-02 00:31:49 +04:00
|
|
|
error = kauth_authorize_device_tty(l->l_cred,
|
|
|
|
KAUTH_DEVICE_TTY_PRIVSET, tp);
|
1999-09-13 14:30:21 +04:00
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
sc->sc_swflags = *(int *)data;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2002-03-17 22:40:26 +03:00
|
|
|
error = EPASSTHROUGH;
|
1999-09-13 14:30:21 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
integrate void
|
2002-02-12 18:26:45 +03:00
|
|
|
sci_schedrx(struct sci_softc *sc)
|
1999-09-13 14:30:21 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
sc->sc_rx_ready = 1;
|
|
|
|
|
|
|
|
/* Wake up the poller. */
|
2007-11-19 21:51:36 +03:00
|
|
|
softint_schedule(sc->sc_si);
|
1999-09-13 14:30:21 +04:00
|
|
|
}
|
|
|
|
|
2000-01-07 13:50:14 +03:00
|
|
|
void
|
2002-02-12 18:26:45 +03:00
|
|
|
sci_break(struct sci_softc *sc, int onoff)
|
2000-01-07 13:50:14 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
if (onoff)
|
2000-02-22 04:37:11 +03:00
|
|
|
SHREG_SCSSR &= ~SCSSR_TDRE;
|
2000-01-07 13:50:14 +03:00
|
|
|
else
|
2000-02-22 04:37:11 +03:00
|
|
|
SHREG_SCSSR |= SCSSR_TDRE;
|
2000-01-07 13:50:14 +03:00
|
|
|
|
|
|
|
#if 0 /* XXX */
|
|
|
|
if (!sc->sc_heldchange) {
|
|
|
|
if (sc->sc_tx_busy) {
|
|
|
|
sc->sc_heldtbc = sc->sc_tbc;
|
|
|
|
sc->sc_tbc = 0;
|
|
|
|
sc->sc_heldchange = 1;
|
|
|
|
} else
|
|
|
|
sci_loadchannelregs(sc);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1999-09-13 14:30:21 +04:00
|
|
|
/*
|
|
|
|
* Stop output, e.g., for ^S or output flush.
|
|
|
|
*/
|
|
|
|
void
|
2002-02-12 18:26:45 +03:00
|
|
|
scistop(struct tty *tp, int flag)
|
1999-09-13 14:30:21 +04:00
|
|
|
{
|
2008-06-13 17:08:57 +04:00
|
|
|
struct sci_softc *sc = device_lookup_private(&sci_cd, SCIUNIT(tp->t_dev));
|
1999-09-13 14:30:21 +04:00
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splserial();
|
|
|
|
if (ISSET(tp->t_state, TS_BUSY)) {
|
|
|
|
/* Stop transmitting at the next chunk. */
|
|
|
|
sc->sc_tbc = 0;
|
|
|
|
sc->sc_heldtbc = 0;
|
|
|
|
if (!ISSET(tp->t_state, TS_TTSTOP))
|
|
|
|
SET(tp->t_state, TS_FLUSH);
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-02-12 18:26:45 +03:00
|
|
|
scidiag(void *arg)
|
1999-09-13 14:30:21 +04:00
|
|
|
{
|
|
|
|
struct sci_softc *sc = arg;
|
|
|
|
int overflows, floods;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splserial();
|
|
|
|
overflows = sc->sc_overflows;
|
|
|
|
sc->sc_overflows = 0;
|
|
|
|
floods = sc->sc_floods;
|
|
|
|
sc->sc_floods = 0;
|
|
|
|
sc->sc_errors = 0;
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
log(LOG_WARNING, "%s: %d silo overflow%s, %d ibuf flood%s\n",
|
|
|
|
sc->sc_dev.dv_xname,
|
|
|
|
overflows, overflows == 1 ? "" : "s",
|
|
|
|
floods, floods == 1 ? "" : "s");
|
|
|
|
}
|
|
|
|
|
|
|
|
integrate void
|
2002-02-12 18:26:45 +03:00
|
|
|
sci_rxsoft(struct sci_softc *sc, struct tty *tp)
|
1999-09-13 14:30:21 +04:00
|
|
|
{
|
2006-03-07 13:53:29 +03:00
|
|
|
int (*rint)(int, struct tty *) = tp->t_linesw->l_rint;
|
1999-09-13 14:30:21 +04:00
|
|
|
u_char *get, *end;
|
|
|
|
u_int cc, scc;
|
|
|
|
u_char ssr;
|
|
|
|
int code;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
end = sc->sc_ebuf;
|
|
|
|
get = sc->sc_rbget;
|
|
|
|
scc = cc = sci_rbuf_size - sc->sc_rbavail;
|
|
|
|
|
|
|
|
if (cc == sci_rbuf_size) {
|
|
|
|
sc->sc_floods++;
|
|
|
|
if (sc->sc_errors++ == 0)
|
2000-03-23 09:40:33 +03:00
|
|
|
callout_reset(&sc->sc_diag_ch, 60 * hz, scidiag, sc);
|
1999-09-13 14:30:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
while (cc) {
|
|
|
|
code = get[0];
|
|
|
|
ssr = get[1];
|
|
|
|
if (ISSET(ssr, SCSSR_FER | SCSSR_PER)) {
|
|
|
|
if (ISSET(ssr, SCSSR_FER))
|
|
|
|
SET(code, TTY_FE);
|
|
|
|
if (ISSET(ssr, SCSSR_PER))
|
|
|
|
SET(code, TTY_PE);
|
|
|
|
}
|
|
|
|
if ((*rint)(code, tp) == -1) {
|
|
|
|
/*
|
|
|
|
* The line discipline's buffer is out of space.
|
|
|
|
*/
|
|
|
|
if (!ISSET(sc->sc_rx_flags, RX_TTY_BLOCKED)) {
|
|
|
|
/*
|
|
|
|
* We're either not using flow control, or the
|
|
|
|
* line discipline didn't tell us to block for
|
|
|
|
* some reason. Either way, we have no way to
|
|
|
|
* know when there's more space available, so
|
|
|
|
* just drop the rest of the data.
|
|
|
|
*/
|
|
|
|
get += cc << 1;
|
|
|
|
if (get >= end)
|
|
|
|
get -= sci_rbuf_size << 1;
|
|
|
|
cc = 0;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Don't schedule any more receive processing
|
|
|
|
* until the line discipline tells us there's
|
|
|
|
* space available (through scihwiflow()).
|
|
|
|
* Leave the rest of the data in the input
|
|
|
|
* buffer.
|
|
|
|
*/
|
|
|
|
SET(sc->sc_rx_flags, RX_TTY_OVERFLOWED);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
get += 2;
|
|
|
|
if (get >= end)
|
|
|
|
get = sc->sc_rbuf;
|
|
|
|
cc--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cc != scc) {
|
|
|
|
sc->sc_rbget = get;
|
|
|
|
s = splserial();
|
|
|
|
cc = sc->sc_rbavail += scc - cc;
|
|
|
|
/* Buffers should be ok again, release possible block. */
|
|
|
|
if (cc >= sc->sc_r_lowat) {
|
|
|
|
if (ISSET(sc->sc_rx_flags, RX_IBUF_OVERFLOWED)) {
|
|
|
|
CLR(sc->sc_rx_flags, RX_IBUF_OVERFLOWED);
|
|
|
|
SHREG_SCSCR |= SCSCR_RIE;
|
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
if (ISSET(sc->sc_rx_flags, RX_IBUF_BLOCKED)) {
|
|
|
|
CLR(sc->sc_rx_flags, RX_IBUF_BLOCKED);
|
|
|
|
sci_hwiflow(sc);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
integrate void
|
2009-03-14 18:35:58 +03:00
|
|
|
sci_txsoft(struct sci_softc *sc, struct tty *tp)
|
1999-09-13 14:30:21 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
CLR(tp->t_state, TS_BUSY);
|
|
|
|
if (ISSET(tp->t_state, TS_FLUSH))
|
|
|
|
CLR(tp->t_state, TS_FLUSH);
|
|
|
|
else
|
|
|
|
ndflush(&tp->t_outq, (int)(sc->sc_tba - tp->t_outq.c_cf));
|
2000-11-02 03:37:56 +03:00
|
|
|
(*tp->t_linesw->l_start)(tp);
|
1999-09-13 14:30:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
integrate void
|
2002-02-12 18:26:45 +03:00
|
|
|
sci_stsoft(struct sci_softc *sc, struct tty *tp)
|
1999-09-13 14:30:21 +04:00
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
/* XXX (msaitoh) */
|
|
|
|
u_char msr, delta;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splserial();
|
|
|
|
msr = sc->sc_msr;
|
|
|
|
delta = sc->sc_msr_delta;
|
|
|
|
sc->sc_msr_delta = 0;
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
if (ISSET(delta, sc->sc_msr_dcd)) {
|
|
|
|
/*
|
|
|
|
* Inform the tty layer that carrier detect changed.
|
|
|
|
*/
|
2000-11-02 03:37:56 +03:00
|
|
|
(void) (*tp->t_linesw->l_modem)(tp, ISSET(msr, MSR_DCD));
|
1999-09-13 14:30:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ISSET(delta, sc->sc_msr_cts)) {
|
|
|
|
/* Block or unblock output according to flow control. */
|
|
|
|
if (ISSET(msr, sc->sc_msr_cts)) {
|
|
|
|
sc->sc_tx_stopped = 0;
|
2000-11-02 03:37:56 +03:00
|
|
|
(*tp->t_linesw->l_start)(tp);
|
1999-09-13 14:30:21 +04:00
|
|
|
} else {
|
|
|
|
sc->sc_tx_stopped = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SCI_DEBUG
|
|
|
|
if (sci_debug)
|
|
|
|
scistatus(sc, "sci_stsoft");
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-02-12 18:26:45 +03:00
|
|
|
scisoft(void *arg)
|
1999-09-13 14:30:21 +04:00
|
|
|
{
|
|
|
|
struct sci_softc *sc = arg;
|
|
|
|
struct tty *tp;
|
|
|
|
|
2006-02-20 19:50:36 +03:00
|
|
|
if (!device_is_active(&sc->sc_dev))
|
1999-09-13 14:30:21 +04:00
|
|
|
return;
|
|
|
|
|
2007-07-10 00:51:58 +04:00
|
|
|
tp = sc->sc_tty;
|
1999-09-13 14:30:21 +04:00
|
|
|
|
2007-07-10 00:51:58 +04:00
|
|
|
if (sc->sc_rx_ready) {
|
|
|
|
sc->sc_rx_ready = 0;
|
|
|
|
sci_rxsoft(sc, tp);
|
|
|
|
}
|
1999-09-13 14:30:21 +04:00
|
|
|
|
|
|
|
#if 0
|
2007-07-10 00:51:58 +04:00
|
|
|
if (sc->sc_st_check) {
|
|
|
|
sc->sc_st_check = 0;
|
|
|
|
sci_stsoft(sc, tp);
|
|
|
|
}
|
1999-09-13 14:30:21 +04:00
|
|
|
#endif
|
|
|
|
|
2007-07-10 00:51:58 +04:00
|
|
|
if (sc->sc_tx_done) {
|
|
|
|
sc->sc_tx_done = 0;
|
|
|
|
sci_txsoft(sc, tp);
|
1999-09-13 14:30:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-02-12 18:26:45 +03:00
|
|
|
sciintr(void *arg)
|
1999-09-13 14:30:21 +04:00
|
|
|
{
|
|
|
|
struct sci_softc *sc = arg;
|
|
|
|
u_char *put, *end;
|
|
|
|
u_int cc;
|
|
|
|
u_short ssr;
|
|
|
|
|
2006-02-20 19:50:36 +03:00
|
|
|
if (!device_is_active(&sc->sc_dev))
|
1999-09-13 14:30:21 +04:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
end = sc->sc_ebuf;
|
|
|
|
put = sc->sc_rbput;
|
|
|
|
cc = sc->sc_rbavail;
|
|
|
|
|
2002-05-19 19:10:46 +04:00
|
|
|
do {
|
|
|
|
ssr = SHREG_SCSSR;
|
|
|
|
if (ISSET(ssr, SCSSR_FER)) {
|
|
|
|
SHREG_SCSSR &= ~(SCSSR_ORER | SCSSR_PER | SCSSR_FER);
|
1999-09-13 14:30:21 +04:00
|
|
|
#if defined(DDB) || defined(KGDB)
|
2002-04-26 14:22:53 +04:00
|
|
|
#ifdef SH4
|
2002-05-19 19:10:46 +04:00
|
|
|
if ((SHREG_SCSPTR & SCSPTR_SPB0DT) != 0) {
|
2001-09-10 12:50:33 +04:00
|
|
|
#else
|
2002-05-19 19:10:46 +04:00
|
|
|
if ((SHREG_SCSPDR & SCSPDR_SCP0DT) != 0) {
|
2001-09-10 12:50:33 +04:00
|
|
|
#endif
|
1999-09-13 14:30:21 +04:00
|
|
|
#ifdef DDB
|
2002-05-19 19:10:46 +04:00
|
|
|
if (ISSET(sc->sc_hwflags, SCI_HW_CONSOLE)) {
|
|
|
|
console_debugger();
|
|
|
|
}
|
1999-09-13 14:30:21 +04:00
|
|
|
#endif
|
|
|
|
#ifdef KGDB
|
2002-05-19 19:10:46 +04:00
|
|
|
if (ISSET(sc->sc_hwflags, SCI_HW_KGDB)) {
|
|
|
|
kgdb_connect(1);
|
|
|
|
}
|
2000-02-22 04:37:11 +03:00
|
|
|
#endif
|
2002-05-19 19:10:46 +04:00
|
|
|
}
|
1999-09-13 14:30:21 +04:00
|
|
|
#endif /* DDB || KGDB */
|
2002-05-19 19:10:46 +04:00
|
|
|
}
|
|
|
|
if ((SHREG_SCSSR & SCSSR_RDRF) != 0) {
|
|
|
|
if (cc > 0) {
|
|
|
|
put[0] = SHREG_SCRDR;
|
|
|
|
put[1] = SHREG_SCSSR & 0x00ff;
|
|
|
|
|
|
|
|
put += 2;
|
|
|
|
if (put >= end)
|
|
|
|
put = sc->sc_rbuf;
|
|
|
|
cc--;
|
|
|
|
}
|
1999-09-13 14:30:21 +04:00
|
|
|
|
2000-06-19 13:32:00 +04:00
|
|
|
SHREG_SCSSR &= ~(SCSSR_ORER | SCSSR_FER | SCSSR_PER |
|
2002-05-19 19:10:46 +04:00
|
|
|
SCSSR_RDRF);
|
1999-09-13 14:30:21 +04:00
|
|
|
|
2002-05-19 19:10:46 +04:00
|
|
|
/*
|
|
|
|
* Current string of incoming characters ended because
|
|
|
|
* no more data was available or we ran out of space.
|
|
|
|
* Schedule a receive event if any data was received.
|
|
|
|
* If we're out of space, turn off receive interrupts.
|
|
|
|
*/
|
|
|
|
sc->sc_rbput = put;
|
|
|
|
sc->sc_rbavail = cc;
|
|
|
|
if (!ISSET(sc->sc_rx_flags, RX_TTY_OVERFLOWED))
|
|
|
|
sc->sc_rx_ready = 1;
|
1999-09-13 14:30:21 +04:00
|
|
|
|
2002-05-19 19:10:46 +04:00
|
|
|
/*
|
|
|
|
* See if we are in danger of overflowing a buffer. If
|
|
|
|
* so, use hardware flow control to ease the pressure.
|
|
|
|
*/
|
|
|
|
if (!ISSET(sc->sc_rx_flags, RX_IBUF_BLOCKED) &&
|
|
|
|
cc < sc->sc_r_hiwat) {
|
|
|
|
SET(sc->sc_rx_flags, RX_IBUF_BLOCKED);
|
1999-09-13 14:30:21 +04:00
|
|
|
#if 0
|
2002-05-19 19:10:46 +04:00
|
|
|
sci_hwiflow(sc);
|
1999-09-13 14:30:21 +04:00
|
|
|
#endif
|
2002-05-19 19:10:46 +04:00
|
|
|
}
|
1999-09-13 14:30:21 +04:00
|
|
|
|
2002-05-19 19:10:46 +04:00
|
|
|
/*
|
|
|
|
* If we're out of space, disable receive interrupts
|
|
|
|
* until the queue has drained a bit.
|
|
|
|
*/
|
|
|
|
if (!cc) {
|
|
|
|
SET(sc->sc_rx_flags, RX_IBUF_OVERFLOWED);
|
|
|
|
SHREG_SCSCR &= ~SCSCR_RIE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (SHREG_SCSSR & SCSSR_RDRF) {
|
|
|
|
SHREG_SCSCR &= ~(SCSCR_TIE | SCSCR_RIE);
|
|
|
|
delay(10);
|
|
|
|
SHREG_SCSCR |= SCSCR_TIE | SCSCR_RIE;
|
|
|
|
continue;
|
|
|
|
}
|
2000-02-22 04:37:11 +03:00
|
|
|
}
|
2002-05-19 19:10:46 +04:00
|
|
|
} while (SHREG_SCSSR & SCSSR_RDRF);
|
2002-04-28 21:10:32 +04:00
|
|
|
|
1999-09-13 14:30:21 +04:00
|
|
|
#if 0
|
2000-02-22 04:37:11 +03:00
|
|
|
msr = bus_space_read_1(iot, ioh, sci_msr);
|
|
|
|
delta = msr ^ sc->sc_msr;
|
|
|
|
sc->sc_msr = msr;
|
|
|
|
if (ISSET(delta, sc->sc_msr_mask)) {
|
|
|
|
SET(sc->sc_msr_delta, delta);
|
1999-09-13 14:30:21 +04:00
|
|
|
|
2000-02-22 04:37:11 +03:00
|
|
|
/*
|
|
|
|
* Pulse-per-second clock signal on edge of DCD?
|
|
|
|
*/
|
|
|
|
if (ISSET(delta, sc->sc_ppsmask)) {
|
|
|
|
struct timeval tv;
|
|
|
|
if (ISSET(msr, sc->sc_ppsmask) ==
|
|
|
|
sc->sc_ppsassert) {
|
|
|
|
/* XXX nanotime() */
|
|
|
|
microtime(&tv);
|
|
|
|
TIMEVAL_TO_TIMESPEC(&tv,
|
|
|
|
&sc->ppsinfo.assert_timestamp);
|
|
|
|
if (sc->ppsparam.mode & PPS_OFFSETASSERT) {
|
|
|
|
timespecadd(&sc->ppsinfo.assert_timestamp,
|
1999-09-13 14:30:21 +04:00
|
|
|
&sc->ppsparam.assert_offset,
|
|
|
|
&sc->ppsinfo.assert_timestamp);
|
2000-02-22 04:37:11 +03:00
|
|
|
TIMESPEC_TO_TIMEVAL(&tv, &sc->ppsinfo.assert_timestamp);
|
|
|
|
}
|
1999-09-13 14:30:21 +04:00
|
|
|
|
|
|
|
#ifdef PPS_SYNC
|
2000-02-22 04:37:11 +03:00
|
|
|
if (sc->ppsparam.mode & PPS_HARDPPSONASSERT)
|
|
|
|
hardpps(&tv, tv.tv_usec);
|
1999-09-13 14:30:21 +04:00
|
|
|
#endif
|
2000-02-22 04:37:11 +03:00
|
|
|
sc->ppsinfo.assert_sequence++;
|
|
|
|
sc->ppsinfo.current_mode =
|
|
|
|
sc->ppsparam.mode;
|
|
|
|
|
|
|
|
} else if (ISSET(msr, sc->sc_ppsmask) ==
|
|
|
|
sc->sc_ppsclear) {
|
|
|
|
/* XXX nanotime() */
|
|
|
|
microtime(&tv);
|
|
|
|
TIMEVAL_TO_TIMESPEC(&tv,
|
|
|
|
&sc->ppsinfo.clear_timestamp);
|
|
|
|
if (sc->ppsparam.mode & PPS_OFFSETCLEAR) {
|
|
|
|
timespecadd(&sc->ppsinfo.clear_timestamp,
|
1999-09-13 14:30:21 +04:00
|
|
|
&sc->ppsparam.clear_offset,
|
|
|
|
&sc->ppsinfo.clear_timestamp);
|
2000-02-22 04:37:11 +03:00
|
|
|
TIMESPEC_TO_TIMEVAL(&tv, &sc->ppsinfo.clear_timestamp);
|
|
|
|
}
|
1999-09-13 14:30:21 +04:00
|
|
|
|
|
|
|
#ifdef PPS_SYNC
|
2000-02-22 04:37:11 +03:00
|
|
|
if (sc->ppsparam.mode & PPS_HARDPPSONCLEAR)
|
|
|
|
hardpps(&tv, tv.tv_usec);
|
1999-09-13 14:30:21 +04:00
|
|
|
#endif
|
2000-02-22 04:37:11 +03:00
|
|
|
sc->ppsinfo.clear_sequence++;
|
|
|
|
sc->ppsinfo.current_mode =
|
|
|
|
sc->ppsparam.mode;
|
1999-09-13 14:30:21 +04:00
|
|
|
}
|
2000-02-22 04:37:11 +03:00
|
|
|
}
|
1999-09-13 14:30:21 +04:00
|
|
|
|
2000-02-22 04:37:11 +03:00
|
|
|
/*
|
|
|
|
* Stop output immediately if we lose the output
|
|
|
|
* flow control signal or carrier detect.
|
|
|
|
*/
|
|
|
|
if (ISSET(~msr, sc->sc_msr_mask)) {
|
|
|
|
sc->sc_tbc = 0;
|
|
|
|
sc->sc_heldtbc = 0;
|
1999-09-13 14:30:21 +04:00
|
|
|
#ifdef SCI_DEBUG
|
2000-02-22 04:37:11 +03:00
|
|
|
if (sci_debug)
|
|
|
|
scistatus(sc, "sciintr ");
|
1999-09-13 14:30:21 +04:00
|
|
|
#endif
|
|
|
|
}
|
2000-02-22 04:37:11 +03:00
|
|
|
|
|
|
|
sc->sc_st_check = 1;
|
|
|
|
}
|
1999-09-13 14:30:21 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Done handling any receive interrupts. See if data can be
|
|
|
|
* transmitted as well. Schedule tx done event if no data left
|
|
|
|
* and tty was marked busy.
|
|
|
|
*/
|
|
|
|
if ((SHREG_SCSSR & SCSSR_TDRE) != 0) {
|
|
|
|
/*
|
|
|
|
* If we've delayed a parameter change, do it now, and restart
|
|
|
|
* output.
|
|
|
|
*/
|
|
|
|
if (sc->sc_heldchange) {
|
|
|
|
sc->sc_heldchange = 0;
|
|
|
|
sc->sc_tbc = sc->sc_heldtbc;
|
|
|
|
sc->sc_heldtbc = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Output the next chunk of the contiguous buffer, if any. */
|
|
|
|
if (sc->sc_tbc > 0) {
|
2000-11-23 00:14:25 +03:00
|
|
|
sci_putc(*(sc->sc_tba));
|
1999-09-13 14:30:21 +04:00
|
|
|
sc->sc_tba++;
|
|
|
|
sc->sc_tbc--;
|
|
|
|
} else {
|
|
|
|
/* Disable transmit completion interrupts if necessary. */
|
|
|
|
#if 0
|
|
|
|
if (ISSET(sc->sc_ier, IER_ETXRDY))
|
|
|
|
#endif
|
|
|
|
SHREG_SCSCR &= ~SCSCR_TIE;
|
|
|
|
|
|
|
|
if (sc->sc_tx_busy) {
|
|
|
|
sc->sc_tx_busy = 0;
|
|
|
|
sc->sc_tx_done = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Wake up the poller. */
|
2007-11-19 21:51:36 +03:00
|
|
|
softint_schedule(sc->sc_si);
|
1999-09-13 14:30:21 +04:00
|
|
|
|
|
|
|
#if NRND > 0 && defined(RND_SCI)
|
|
|
|
rnd_add_uint32(&sc->rnd_source, iir | lsr);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
scicnprobe(struct consdev *cp)
|
1999-09-13 14:30:21 +04:00
|
|
|
{
|
|
|
|
int maj;
|
|
|
|
|
|
|
|
/* locate the major number */
|
2002-09-06 17:18:43 +04:00
|
|
|
maj = cdevsw_lookup_major(&sci_cdevsw);
|
1999-09-13 14:30:21 +04:00
|
|
|
|
|
|
|
/* Initialize required fields. */
|
|
|
|
cp->cn_dev = makedev(maj, 0);
|
1999-09-17 05:23:00 +04:00
|
|
|
#ifdef SCICONSOLE
|
|
|
|
cp->cn_pri = CN_REMOTE;
|
|
|
|
#else
|
1999-09-13 14:30:21 +04:00
|
|
|
cp->cn_pri = CN_NORMAL;
|
1999-09-17 05:23:00 +04:00
|
|
|
#endif
|
1999-09-13 14:30:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-02-12 18:26:45 +03:00
|
|
|
scicninit(struct consdev *cp)
|
1999-09-13 14:30:21 +04:00
|
|
|
{
|
|
|
|
|
2000-02-22 04:37:11 +03:00
|
|
|
InitializeSci(scicn_speed);
|
2000-03-27 20:24:08 +04:00
|
|
|
sciisconsole = 1;
|
1999-09-13 14:30:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-02-12 18:26:45 +03:00
|
|
|
scicngetc(dev_t dev)
|
1999-09-13 14:30:21 +04:00
|
|
|
{
|
|
|
|
int c;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splserial();
|
|
|
|
c = sci_getc();
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
return (c);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-02-12 18:26:45 +03:00
|
|
|
scicnputc(dev_t dev, int c)
|
1999-09-13 14:30:21 +04:00
|
|
|
{
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splserial();
|
2000-11-23 00:14:25 +03:00
|
|
|
sci_putc((u_char)c);
|
1999-09-13 14:30:21 +04:00
|
|
|
splx(s);
|
|
|
|
}
|