2000-11-02 03:37:56 +03:00
|
|
|
|
/* $NetBSD: scn.c,v 1.45 2000/11/02 00:42:38 eeh Exp $ */
|
1994-10-26 11:23:50 +03:00
|
|
|
|
|
1995-08-25 11:30:33 +04:00
|
|
|
|
/*
|
1997-03-13 13:24:14 +03:00
|
|
|
|
* Copyright (c) 1996, 1997 Philip L. Budne.
|
1996-10-23 11:52:35 +04:00
|
|
|
|
* Copyright (c) 1993 Philip A. Nelson.
|
|
|
|
|
* Copyright (c) 1991, 1992, 1993
|
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Portions of this software were developed by the Computer Systems
|
|
|
|
|
* Engineering group at Lawrence Berkeley Laboratory under DARPA
|
|
|
|
|
* contract BG 91-66 and contributed to Berkeley.
|
|
|
|
|
*
|
|
|
|
|
* All advertising materials mentioning features or use of this software
|
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
|
* California, Lawrence Berkeley Laboratory.
|
1993-09-10 03:53:45 +04:00
|
|
|
|
*
|
|
|
|
|
* 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. All advertising materials mentioning features or use of this software
|
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
1996-10-23 11:52:35 +04:00
|
|
|
|
* from: @(#)com.c 7.5 (Berkeley) 5/16/91
|
1993-09-10 03:53:45 +04:00
|
|
|
|
*/
|
|
|
|
|
|
1998-07-05 02:18:13 +04:00
|
|
|
|
#include "opt_ddb.h"
|
1993-09-10 03:53:45 +04:00
|
|
|
|
#include "scn.h"
|
|
|
|
|
|
1994-05-17 21:29:34 +04:00
|
|
|
|
#include <sys/param.h>
|
|
|
|
|
#include <sys/systm.h>
|
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
#include <sys/select.h>
|
|
|
|
|
#include <sys/tty.h>
|
|
|
|
|
#include <sys/proc.h>
|
|
|
|
|
#include <sys/user.h>
|
|
|
|
|
#include <sys/file.h>
|
|
|
|
|
#include <sys/uio.h>
|
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
|
#include <sys/types.h>
|
1995-01-19 10:03:35 +03:00
|
|
|
|
#include <sys/device.h>
|
1996-11-24 16:32:53 +03:00
|
|
|
|
#include <sys/malloc.h>
|
1997-03-20 15:03:03 +03:00
|
|
|
|
#ifdef KGDB
|
|
|
|
|
#include <sys/kgdb.h>
|
|
|
|
|
#endif
|
1994-05-17 21:29:34 +04:00
|
|
|
|
|
|
|
|
|
#include <dev/cons.h>
|
|
|
|
|
|
1997-01-11 13:58:12 +03:00
|
|
|
|
#include <machine/autoconf.h>
|
1997-03-20 15:03:03 +03:00
|
|
|
|
#include <machine/conf.h>
|
1993-09-10 03:53:45 +04:00
|
|
|
|
|
|
|
|
|
#include "scnreg.h"
|
1996-10-23 11:52:35 +04:00
|
|
|
|
#include "scnvar.h"
|
1993-09-10 03:53:45 +04:00
|
|
|
|
|
1997-01-11 13:58:12 +03:00
|
|
|
|
static const char scnints[4] = {IR_TTY0, IR_TTY1, IR_TTY2, IR_TTY3};
|
|
|
|
|
static const char rxints[4] = {IR_TTY0RDY, IR_TTY1RDY, IR_TTY2RDY, IR_TTY3RDY};
|
1996-12-23 11:37:07 +03:00
|
|
|
|
|
|
|
|
|
int scnprobe __P((struct device *, struct cfdata *, void *));
|
1996-10-23 11:52:35 +04:00
|
|
|
|
void scnattach __P((struct device *, struct device *, void *));
|
|
|
|
|
int scnparam __P((struct tty *, struct termios *));
|
|
|
|
|
void scnstart __P((struct tty *));
|
|
|
|
|
int scnopen __P((dev_t, int, int, struct proc *));
|
|
|
|
|
int scnclose __P((dev_t, int, int, struct proc *));
|
2000-07-14 12:18:49 +04:00
|
|
|
|
void scncnprobe __P((struct consdev *));
|
1996-10-23 11:52:35 +04:00
|
|
|
|
void scncninit __P((struct consdev *));
|
|
|
|
|
int scncngetc __P((dev_t));
|
|
|
|
|
void scncnputc __P((dev_t, int));
|
|
|
|
|
void scncnpollc __P((dev_t, int));
|
|
|
|
|
int scninit __P((dev_t, int));
|
|
|
|
|
void scncnreinit __P((void *));
|
1996-12-23 11:37:07 +03:00
|
|
|
|
int scnhwiflow __P((struct tty *, int));
|
1996-10-23 11:52:35 +04:00
|
|
|
|
|
|
|
|
|
struct cfattach scn_ca = {sizeof(struct scn_softc), scnprobe, scnattach};
|
1998-01-12 22:51:03 +03:00
|
|
|
|
|
|
|
|
|
extern struct cfdriver scn_cd;
|
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
#ifndef CONSOLE_SPEED
|
|
|
|
|
#define CONSOLE_SPEED TTYDEF_SPEED
|
|
|
|
|
#endif
|
1993-09-10 03:53:45 +04:00
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
#ifndef SCNDEF_CFLAG
|
|
|
|
|
#define SCNDEF_CFLAG TTYDEF_CFLAG
|
|
|
|
|
#endif
|
1995-04-27 11:18:02 +04:00
|
|
|
|
|
1996-11-24 16:32:53 +03:00
|
|
|
|
#ifdef CPU30MHZ
|
1997-02-08 12:34:31 +03:00
|
|
|
|
#define RECOVER() __asm __volatile("bispsrw 0x800" : : : "cc")
|
1996-11-24 16:32:53 +03:00
|
|
|
|
#else
|
|
|
|
|
#define RECOVER()
|
|
|
|
|
#endif
|
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
int scnconsole = SCN_CONSOLE;
|
|
|
|
|
int scndefaultrate = TTYDEF_SPEED;
|
|
|
|
|
int scnconsrate = CONSOLE_SPEED;
|
|
|
|
|
int scnmajor;
|
1996-03-17 04:38:52 +03:00
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
#define SOFTC(UNIT) scn_cd.cd_devs[(UNIT)]
|
1993-09-10 03:53:45 +04:00
|
|
|
|
|
1996-11-24 16:32:53 +03:00
|
|
|
|
static void scnintr __P((void *));
|
1996-12-23 11:37:07 +03:00
|
|
|
|
static void scnrxintr __P((void *));
|
|
|
|
|
static int scn_rxintr __P((struct scn_softc *, int));
|
1996-10-23 11:52:35 +04:00
|
|
|
|
static void scnsoft __P((void *));
|
1997-03-13 13:24:14 +03:00
|
|
|
|
static void scn_setchip __P((struct scn_softc *sc));
|
|
|
|
|
static int scniter __P((int *, int, int*, int*, struct chan *, int));
|
|
|
|
|
static int scn_config __P((int, int, int, u_char, u_char));
|
1997-03-20 15:03:03 +03:00
|
|
|
|
static void scn_rxenable __P((struct scn_softc *));
|
|
|
|
|
static void scn_rxdisable __P((struct scn_softc *));
|
|
|
|
|
static void dcd_int __P((struct scn_softc *, struct tty *, u_char));
|
|
|
|
|
static void scnoverrun __P((int, long *, char *));
|
|
|
|
|
static unsigned char opbits __P((struct scn_softc *, int));
|
1993-09-10 03:53:45 +04:00
|
|
|
|
|
1997-03-01 12:50:44 +03:00
|
|
|
|
static int scnsir = -1; /* s/w intr number */
|
|
|
|
|
#define setsoftscn() softintr(scnsir)
|
|
|
|
|
|
|
|
|
|
#ifdef SCN_TIMING
|
1996-10-23 11:52:35 +04:00
|
|
|
|
/*
|
|
|
|
|
* Keep timing info on latency of software interrupt used by
|
1996-11-24 16:32:53 +03:00
|
|
|
|
* the ringbuf code to empty ring buffer.
|
1996-10-23 11:52:35 +04:00
|
|
|
|
* "getinfo" program reads data from /dev/kemm.
|
|
|
|
|
*/
|
|
|
|
|
static struct timeval tstart;
|
|
|
|
|
#define NJITTER 100
|
|
|
|
|
int scn_njitter = NJITTER;
|
|
|
|
|
int scn_jitter[NJITTER];
|
|
|
|
|
#endif
|
|
|
|
|
|
1997-03-01 12:50:44 +03:00
|
|
|
|
#define SCN_CLOCK 3686400 /* input clock */
|
1996-10-23 11:52:35 +04:00
|
|
|
|
|
1997-03-13 13:24:14 +03:00
|
|
|
|
/* speed table groups ACR[7] */
|
|
|
|
|
#define GRP_A 0
|
|
|
|
|
#define GRP_B ACR_BRG
|
|
|
|
|
|
|
|
|
|
/* combo of MR0[2:0] and ACR[7] */
|
|
|
|
|
#define MODE0A MR0_MODE_0
|
|
|
|
|
#define MODE0B (MR0_MODE_0|ACR_BRG)
|
|
|
|
|
#define MODE1A MR0_MODE_1
|
|
|
|
|
#define MODE1B (MR0_MODE_1|ACR_BRG)
|
|
|
|
|
#define MODE2A MR0_MODE_2
|
|
|
|
|
#define MODE2B (MR0_MODE_2|ACR_BRG)
|
|
|
|
|
|
|
|
|
|
#define ANYMODE -1
|
|
|
|
|
#define DEFMODE(C92) MODE0A /* use MODE4A if 26c92? */
|
|
|
|
|
|
|
|
|
|
/* speed code for Counter/Timer (all modes, groups) */
|
|
|
|
|
#define USE_CT 0xd
|
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
/*
|
1997-03-13 13:24:14 +03:00
|
|
|
|
* Rate table, ordered by speed, then mode.
|
|
|
|
|
* NOTE: ordering of modes must be done carefully!
|
1996-10-23 11:52:35 +04:00
|
|
|
|
*/
|
1997-03-13 13:24:14 +03:00
|
|
|
|
struct tabent {
|
|
|
|
|
int32_t speed;
|
|
|
|
|
int16_t code;
|
|
|
|
|
int16_t mode;
|
|
|
|
|
} table[] = {
|
|
|
|
|
{ 50, 0x0, MODE0A },
|
|
|
|
|
{ 75, 0x0, MODE0B },
|
|
|
|
|
{ 110, 0x1, MODE0A },
|
|
|
|
|
{ 110, 0x1, MODE0B },
|
|
|
|
|
{ 110, 0x1, MODE1A },
|
|
|
|
|
{ 110, 0x1, MODE1B },
|
|
|
|
|
{ 134, 0x2, MODE0A }, /* 134.5 */
|
|
|
|
|
{ 134, 0x2, MODE0B }, /* 134.5 */
|
|
|
|
|
{ 134, 0x2, MODE1A }, /* 134.5 */
|
|
|
|
|
{ 134, 0x2, MODE1B }, /* 134.5 */
|
|
|
|
|
{ 150, 0x3, MODE0A },
|
|
|
|
|
{ 150, 0x3, MODE0A },
|
|
|
|
|
{ 200, 0x3, MODE0A },
|
|
|
|
|
{ 300, 0x4, MODE0A },
|
|
|
|
|
{ 300, 0x4, MODE0B },
|
|
|
|
|
{ 300, 0x0, MODE1A },
|
|
|
|
|
{ 450, 0x0, MODE1B },
|
|
|
|
|
{ 600, 0x5, MODE0A },
|
|
|
|
|
{ 600, 0x5, MODE0B },
|
|
|
|
|
{ 880, 0x1, MODE2A },
|
|
|
|
|
{ 880, 0x1, MODE2B },
|
|
|
|
|
{ 900, 0x3, MODE1B },
|
|
|
|
|
{ 1050, 0x7, MODE0A },
|
|
|
|
|
{ 1050, 0x7, MODE1A },
|
|
|
|
|
{ 1076, 0x2, MODE2A },
|
|
|
|
|
{ 1076, 0x2, MODE2B },
|
|
|
|
|
{ 1200, 0x6, MODE0A },
|
|
|
|
|
{ 1200, 0x6, MODE0B },
|
|
|
|
|
{ 1200, 0x3, MODE1A },
|
|
|
|
|
{ 1800, 0xa, MODE0B },
|
|
|
|
|
{ 1800, 0x4, MODE1A },
|
|
|
|
|
{ 1800, 0x4, MODE1B },
|
|
|
|
|
{ 2000, 0x7, MODE0B },
|
|
|
|
|
{ 2000, 0x7, MODE1B },
|
|
|
|
|
{ 2400, 0x8, MODE0A },
|
|
|
|
|
{ 2400, 0x8, MODE0B },
|
|
|
|
|
{ 3600, 0x5, MODE1A },
|
|
|
|
|
{ 3600, 0x5, MODE1B },
|
|
|
|
|
{ 4800, 0x9, MODE2A },
|
|
|
|
|
{ 4800, 0x9, MODE2B },
|
|
|
|
|
{ 4800, 0x9, MODE0A },
|
|
|
|
|
{ 4800, 0x9, MODE0B },
|
|
|
|
|
{ 7200, 0xa, MODE0A },
|
|
|
|
|
{ 7200, 0x0, MODE2B },
|
|
|
|
|
{ 7200, 0x6, MODE1A },
|
|
|
|
|
{ 7200, 0x6, MODE1B },
|
|
|
|
|
{ 9600, 0xb, MODE2A },
|
|
|
|
|
{ 9600, 0xb, MODE2B },
|
|
|
|
|
{ 9600, 0xb, MODE0A },
|
|
|
|
|
{ 9600, 0xb, MODE0B },
|
|
|
|
|
{ 9600, 0xd, MODE1A }, /* use C/T as entre' to mode1 */
|
|
|
|
|
{ 9600, 0xd, MODE1B }, /* use C/T as entre' to mode1 */
|
|
|
|
|
{ 14400, 0x3, MODE2B },
|
|
|
|
|
{ 14400, 0x8, MODE1A },
|
|
|
|
|
{ 14400, 0x8, MODE1B },
|
|
|
|
|
{ 19200, 0x3, MODE2A },
|
|
|
|
|
{ 19200, 0xc, MODE2B },
|
|
|
|
|
{ 19200, 0xc, MODE0B },
|
|
|
|
|
{ 19200, 0xd, MODE1A }, /* use C/T as entre' to mode1 */
|
|
|
|
|
{ 19200, 0xd, MODE1B }, /* use C/T as entre' to mode1 */
|
|
|
|
|
{ 28800, 0x4, MODE2A },
|
|
|
|
|
{ 28800, 0x4, MODE2B },
|
|
|
|
|
{ 28800, 0x9, MODE1A },
|
|
|
|
|
{ 28800, 0x9, MODE1B },
|
|
|
|
|
{ 38400, 0xc, MODE2A },
|
|
|
|
|
{ 38400, 0xc, MODE0A },
|
|
|
|
|
{ 57600, 0x5, MODE2A },
|
|
|
|
|
{ 57600, 0x5, MODE2B },
|
|
|
|
|
{ 57600, 0xb, MODE1A },
|
|
|
|
|
{ 57600, 0xb, MODE1B },
|
|
|
|
|
{ 115200, 0x6, MODE2A },
|
|
|
|
|
{ 115200, 0x6, MODE2B },
|
|
|
|
|
{ 115200, 0xc, MODE1B },
|
|
|
|
|
{ 230400, 0xc, MODE1A }
|
|
|
|
|
};
|
|
|
|
|
#define TABENTRIES (sizeof(table)/sizeof(table[0]))
|
1996-10-23 11:52:35 +04:00
|
|
|
|
|
|
|
|
|
/*
|
1997-03-13 13:24:14 +03:00
|
|
|
|
* boolean for speed codes which are identical in both A/B BRG groups
|
|
|
|
|
* in all modes
|
1996-10-23 11:52:35 +04:00
|
|
|
|
*/
|
1997-03-13 13:24:14 +03:00
|
|
|
|
static u_char bothgroups[16] = {
|
|
|
|
|
0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1
|
|
|
|
|
};
|
1996-10-23 11:52:35 +04:00
|
|
|
|
|
|
|
|
|
/*
|
1997-03-13 13:24:14 +03:00
|
|
|
|
* Manually constructed divisors table
|
|
|
|
|
* for minimum error (from some of Dave Rand's code)
|
1996-10-23 11:52:35 +04:00
|
|
|
|
*/
|
1997-03-13 13:24:14 +03:00
|
|
|
|
const struct {
|
|
|
|
|
u_int16_t speed;
|
|
|
|
|
u_int16_t div;
|
|
|
|
|
} divs[] = {
|
|
|
|
|
{ 50, 2303 }, /* 2304 is exact?? */
|
|
|
|
|
{ 110, 1047 }, /* Should be 1047.27 */
|
|
|
|
|
{ 134, 857 }, /* Should be 856.505576 */
|
|
|
|
|
{ 1050, 110 }, /* Should be 109.7142857 */
|
|
|
|
|
{ 2000, 57 } /* Should be 57.6 */
|
1996-10-23 11:52:35 +04:00
|
|
|
|
};
|
1997-03-13 13:24:14 +03:00
|
|
|
|
#define DIVS (sizeof(divs)/sizeof(divs[0]))
|
1996-12-23 11:37:07 +03:00
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
/*
|
|
|
|
|
* minor unit bit decode:
|
|
|
|
|
* CxxxUUU
|
|
|
|
|
*
|
|
|
|
|
* C - carrier
|
|
|
|
|
* 0 - delay open until carrier high
|
|
|
|
|
* 1 - allow open with carrier low
|
|
|
|
|
* UUU - unit 0-7
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#define DEV_UNIT(x) (minor(x) & 0x7)
|
|
|
|
|
#define DEV_DIALOUT(x) (minor(x) & 0x80)
|
|
|
|
|
|
|
|
|
|
extern struct tty *constty;
|
|
|
|
|
|
1997-10-22 07:35:56 +04:00
|
|
|
|
/* TRUE and FALSE */
|
|
|
|
|
#ifndef TRUE
|
|
|
|
|
#define TRUE 1
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef FALSE
|
|
|
|
|
#define FALSE 0
|
|
|
|
|
#endif
|
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
#ifdef KGDB
|
1993-09-10 03:53:45 +04:00
|
|
|
|
extern int kgdb_dev;
|
|
|
|
|
extern int kgdb_rate;
|
|
|
|
|
extern int kgdb_debug_init;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
int scnkgdb = -1;
|
1993-09-10 03:53:45 +04:00
|
|
|
|
#endif
|
1997-03-13 13:24:14 +03:00
|
|
|
|
|
|
|
|
|
/* RS-232 configuration routines */
|
1993-09-10 03:53:45 +04:00
|
|
|
|
|
1997-03-13 13:24:14 +03:00
|
|
|
|
/*
|
|
|
|
|
* set chip parameters, or mark for delayed change.
|
|
|
|
|
* called at spltty() or on TxEMPTY interrupt.
|
|
|
|
|
*
|
|
|
|
|
* Reads current values to avoid glitches from redundant sets.
|
|
|
|
|
* Perhaps should save last value set to avoid read/write? NOTE:
|
|
|
|
|
* Would still need to do read if write not needed to advance MR
|
|
|
|
|
* pointer.
|
|
|
|
|
*
|
|
|
|
|
* new 2/97 -plb
|
|
|
|
|
*/
|
1993-09-10 03:53:45 +04:00
|
|
|
|
|
1997-03-13 13:24:14 +03:00
|
|
|
|
static void
|
|
|
|
|
scn_setchip(sc)
|
1996-10-23 11:52:35 +04:00
|
|
|
|
struct scn_softc *sc;
|
1993-09-10 03:53:45 +04:00
|
|
|
|
{
|
1997-03-13 13:24:14 +03:00
|
|
|
|
struct duart *dp;
|
|
|
|
|
u_char acr, csr, mr1, mr2;
|
|
|
|
|
int chan;
|
|
|
|
|
|
|
|
|
|
if (sc->sc_tty && (sc->sc_tty->t_state & TS_BUSY)) {
|
|
|
|
|
sc->sc_heldchanges = 1;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
chan = sc->sc_unit & 1;
|
|
|
|
|
dp = sc->sc_duart;
|
|
|
|
|
if (dp->type == SC26C92) {
|
|
|
|
|
u_char nmr0a, mr0a;
|
|
|
|
|
|
1997-04-21 20:16:16 +04:00
|
|
|
|
/* input rate high enough so 64 bit time watchdog not
|
|
|
|
|
* onerous? */
|
1997-03-13 13:24:14 +03:00
|
|
|
|
if (dp->chan[chan].ispeed >= 1200) {
|
1997-04-21 20:16:16 +04:00
|
|
|
|
/* set FIFO threshold at 6 for other
|
|
|
|
|
* thresholds we could have to set MR1_FFULL
|
|
|
|
|
*/
|
1997-03-13 13:24:14 +03:00
|
|
|
|
dp->chan[chan].mr0 |= MR0_RXWD | MR0_RXINT;
|
|
|
|
|
} else {
|
|
|
|
|
dp->chan[chan].mr0 &= ~(MR0_RXWD | MR0_RXINT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* select BRG mode (MR0A only) */
|
|
|
|
|
nmr0a = dp->chan[0].mr0 | (dp->mode & MR0_MODE);
|
|
|
|
|
|
|
|
|
|
dp->base[CH_CR] = CR_CMD_MR0;
|
|
|
|
|
RECOVER();
|
|
|
|
|
|
|
|
|
|
mr0a = dp->base[CH_MR];
|
|
|
|
|
if (mr0a != nmr0a) {
|
|
|
|
|
dp->base[CH_CR] = CR_CMD_MR0;
|
|
|
|
|
RECOVER();
|
|
|
|
|
dp->base[CH_MR] = nmr0a;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (chan) { /* channel B? */
|
|
|
|
|
u_char mr0b;
|
|
|
|
|
|
|
|
|
|
sc->sc_chbase[CH_CR] = CR_CMD_MR0;
|
|
|
|
|
RECOVER();
|
|
|
|
|
mr0b = dp->base[CH_MR];
|
|
|
|
|
|
|
|
|
|
if (dp->chan[chan].mr0 != mr0b) {
|
|
|
|
|
sc->sc_chbase[CH_CR] = CR_CMD_MR0;
|
|
|
|
|
RECOVER();
|
|
|
|
|
sc->sc_chbase[CH_MR] = dp->chan[chan].mr0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
sc->sc_chbase[CH_CR] = CR_CMD_MR1;
|
|
|
|
|
RECOVER();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mr1 = sc->sc_chbase[CH_MR];
|
|
|
|
|
mr2 = sc->sc_chbase[CH_MR];
|
|
|
|
|
if (mr1 != dp->chan[chan].new_mr1 ||
|
|
|
|
|
mr2 != dp->chan[chan].new_mr2) {
|
|
|
|
|
sc->sc_chbase[CH_CR] = CR_CMD_MR1;
|
|
|
|
|
RECOVER();
|
|
|
|
|
sc->sc_chbase[CH_MR] = dp->chan[chan].new_mr1;
|
|
|
|
|
sc->sc_chbase[CH_MR] = dp->chan[chan].new_mr2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
acr = dp->acr | (dp->mode & ACR_BRG);
|
|
|
|
|
dp->base[DU_ACR] = acr; /* write-only reg! */
|
|
|
|
|
|
|
|
|
|
/* set speed codes */
|
|
|
|
|
csr = (dp->chan[chan].icode<<4) | dp->chan[chan].ocode;
|
|
|
|
|
if (sc->sc_chbase[CH_CSR] != csr) {
|
|
|
|
|
sc->sc_chbase[CH_CSR] = csr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* see if counter/timer in use */
|
|
|
|
|
if (dp->counter &&
|
|
|
|
|
(dp->chan[0].icode == USE_CT || dp->chan[0].ocode == USE_CT ||
|
|
|
|
|
dp->chan[1].icode == USE_CT || dp->chan[1].ocode == USE_CT)) {
|
|
|
|
|
|
|
|
|
|
/* program counter/timer only if necessary */
|
|
|
|
|
if (dp->counter != dp->ocounter) {
|
|
|
|
|
u_int16_t div;
|
|
|
|
|
#ifdef DIVS
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
/* look for precalculated rate, for minimum error */
|
|
|
|
|
for (i = 0; i < DIVS && divs[i].speed <= dp->counter; i++) {
|
|
|
|
|
if (divs[i].speed == dp->counter) {
|
|
|
|
|
div = divs[i].div;
|
|
|
|
|
goto found;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* not found in table; calculate a value (rounding up) */
|
|
|
|
|
div = ((long)SCN_CLOCK/16/2 + dp->counter/2) / dp->counter;
|
|
|
|
|
|
|
|
|
|
found:
|
|
|
|
|
/* halt before loading? may ALWAYS glitch?
|
|
|
|
|
* reload race may only sometimes glitch??
|
|
|
|
|
*/
|
|
|
|
|
dp->base[DU_CTUR] = div >> 8;
|
|
|
|
|
dp->base[DU_CTLR] = div & 255;
|
|
|
|
|
if (dp->ocounter == 0) {
|
|
|
|
|
/* not previously used? */
|
|
|
|
|
u_char temp;
|
|
|
|
|
/* start C/T running */
|
|
|
|
|
temp = dp->base[DU_CSTRT];
|
|
|
|
|
}
|
|
|
|
|
dp->ocounter = dp->counter;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/* counter not in use; mark as free */
|
|
|
|
|
dp->counter = 0;
|
|
|
|
|
}
|
|
|
|
|
sc->sc_heldchanges = 0;
|
1993-09-10 03:53:45 +04:00
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
/*
|
1997-03-13 13:24:14 +03:00
|
|
|
|
* delay a tiny bit to try and avoid tx glitching.
|
|
|
|
|
* I know we're at spltty(), but this is much better than the
|
|
|
|
|
* old version used DELAY((96000 / out_speed) * 10000)
|
|
|
|
|
* -plb
|
1996-10-23 11:52:35 +04:00
|
|
|
|
*/
|
1997-03-13 13:24:14 +03:00
|
|
|
|
DELAY(10);
|
1993-09-10 03:53:45 +04:00
|
|
|
|
}
|
1997-03-13 13:24:14 +03:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* iterator function for speeds.
|
|
|
|
|
* (could be called "findnextcode")
|
|
|
|
|
* Returns sequence of possible speed codes for a given rate.
|
|
|
|
|
* should set index to zero before first call.
|
|
|
|
|
*
|
|
|
|
|
* Could be implemented as a "checkspeed()" function called
|
|
|
|
|
* to evaluate table entries, BUT this allows more variety in
|
|
|
|
|
* use of C/T with fewer table entries.
|
|
|
|
|
*/
|
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
static int
|
1997-03-13 13:24:14 +03:00
|
|
|
|
scniter(index, wanted, counter, mode, other, c92)
|
|
|
|
|
int *index; /* IN/OUT: index */
|
|
|
|
|
int wanted; /* IN: speed wanted */
|
|
|
|
|
int *counter; /* IN/OUT: counter/timer rate */
|
|
|
|
|
int *mode; /* IN/OUT: mode */
|
|
|
|
|
struct chan *other; /* IN: other channel, or NULL */
|
|
|
|
|
int c92; /* IN: true for 26C92 */
|
|
|
|
|
{
|
|
|
|
|
while (*index < TABENTRIES) {
|
|
|
|
|
struct tabent *tp;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
|
1997-03-13 13:24:14 +03:00
|
|
|
|
tp = table + (*index)++;
|
|
|
|
|
if (tp->speed != wanted)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
/* if not a 26C92 only look at MODE0 entries */
|
|
|
|
|
if (!c92 && (tp->mode & MR0_MODE) != MR0_MODE_0)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* check mode;
|
|
|
|
|
* OK if this table entry for current mode, or mode not
|
|
|
|
|
* yet set, or other channel's rates are available in both
|
|
|
|
|
* A and B groups.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (tp->mode == *mode || *mode == ANYMODE ||
|
|
|
|
|
(other != NULL && (tp->mode & MR0_MODE) == (*mode & MR0_MODE) &&
|
|
|
|
|
bothgroups[other->icode] && bothgroups[other->ocode])) {
|
|
|
|
|
/*
|
|
|
|
|
* for future table entries specifying
|
|
|
|
|
* use of counter/timer
|
|
|
|
|
*/
|
|
|
|
|
if (tp->code == USE_CT) {
|
|
|
|
|
if (*counter != wanted && *counter != 0)
|
|
|
|
|
continue; /* counter busy */
|
|
|
|
|
*counter = wanted;
|
|
|
|
|
}
|
|
|
|
|
*mode = tp->mode;
|
|
|
|
|
return tp->code;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* here after returning all applicable table entries */
|
|
|
|
|
/* XXX return sequence of USE_CT with all possible modes?? */
|
|
|
|
|
if ((*index)++ == TABENTRIES) {
|
|
|
|
|
/* Max C/T rate (even on 26C92?) is 57600 */
|
|
|
|
|
if (wanted <= 57600 && (*counter == wanted || *counter == 0)) {
|
|
|
|
|
*counter = wanted;
|
|
|
|
|
return USE_CT;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -1; /* FAIL */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* calculate configuration
|
|
|
|
|
* rewritten 2/97 -plb
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
scn_config(unit, ispeed, ospeed, mr1, mr2)
|
|
|
|
|
int unit;
|
|
|
|
|
int ispeed; /* input speed in bps */
|
|
|
|
|
int ospeed; /* output speed in bps */
|
|
|
|
|
u_char mr1; /* new bits for MR1 */
|
|
|
|
|
u_char mr2; /* new bits for MR2 */
|
1996-10-23 11:52:35 +04:00
|
|
|
|
{
|
|
|
|
|
register struct scn_softc *sc;
|
1997-03-13 13:24:14 +03:00
|
|
|
|
struct duart *dp;
|
|
|
|
|
int chan; /* 0 or 1 */
|
|
|
|
|
int other; /* 1 or 0 */
|
|
|
|
|
int mode;
|
|
|
|
|
int counter;
|
|
|
|
|
int i, o; /* input, output iterator indexes */
|
|
|
|
|
int ic, oc; /* input, output codes */
|
|
|
|
|
struct chan *ocp; /* other duart channel */
|
|
|
|
|
struct tty *otp; /* other channel tty struct */
|
|
|
|
|
int c92; /* true if duart is sc26c92 */
|
1996-12-23 11:37:07 +03:00
|
|
|
|
int s;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
|
|
|
|
|
/* Set up softc pointer. */
|
|
|
|
|
if (unit >= scn_cd.cd_ndevs)
|
|
|
|
|
return ENXIO;
|
|
|
|
|
sc = SOFTC(unit);
|
1997-03-13 13:24:14 +03:00
|
|
|
|
chan = unit & 1;
|
|
|
|
|
other = chan ^ 1;
|
|
|
|
|
dp = sc->sc_duart;
|
|
|
|
|
ocp = &dp->chan[other];
|
|
|
|
|
c92 = (dp->type == SC26C92);
|
|
|
|
|
|
|
|
|
|
/* ugh; keep tty pointers in duart.chan[n].tty? */
|
|
|
|
|
otp = NULL;
|
|
|
|
|
if ((unit ^ 1) < scn_cd.cd_ndevs) {
|
|
|
|
|
struct scn_softc *osc;
|
|
|
|
|
|
|
|
|
|
osc = SOFTC(unit ^ 1);
|
|
|
|
|
if (osc) {
|
|
|
|
|
otp = osc->sc_tty;
|
|
|
|
|
}
|
|
|
|
|
}
|
1996-10-23 11:52:35 +04:00
|
|
|
|
|
|
|
|
|
/*
|
1997-03-13 13:24:14 +03:00
|
|
|
|
* Right now the first combination that works is used.
|
|
|
|
|
* Perhaps it should search entire solution space for "best"
|
|
|
|
|
* combination. For example, use heuristic weighting of mode
|
|
|
|
|
* preferences, and use of counter timer?
|
|
|
|
|
*
|
|
|
|
|
* For example right now with 2681/2692 when default rate is
|
|
|
|
|
* 9600 and other channel is closed setting 19200 will pick
|
|
|
|
|
* mode 0a and use counter/timer. Better solution might be
|
|
|
|
|
* mode 0b, leaving counter/timer free!
|
|
|
|
|
*
|
|
|
|
|
* When other channel is open might want to prefer
|
|
|
|
|
* leaving counter timer free, or not flipping A/B group?
|
|
|
|
|
*/
|
|
|
|
|
if (otp && (otp->t_state & TS_ISOPEN)) {
|
|
|
|
|
/*
|
|
|
|
|
* Other channel open;
|
|
|
|
|
* Find speed codes compatible with current mode/counter.
|
|
|
|
|
*/
|
1996-10-23 11:52:35 +04:00
|
|
|
|
|
1997-03-13 13:24:14 +03:00
|
|
|
|
i = 0;
|
|
|
|
|
for (;;) {
|
|
|
|
|
mode = dp->mode;
|
|
|
|
|
counter = dp->counter;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
|
1997-03-13 13:24:14 +03:00
|
|
|
|
/* NOTE: pass other chan pointer to allow group flipping */
|
|
|
|
|
ic = scniter(&i, ispeed, &counter, &mode, ocp, c92);
|
|
|
|
|
if (ic == -1)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
o = 0;
|
|
|
|
|
if ((oc = scniter(&o, ospeed, &counter,
|
|
|
|
|
&mode, NULL, c92)) != -1) {
|
1996-10-23 11:52:35 +04:00
|
|
|
|
/*
|
1997-03-13 13:24:14 +03:00
|
|
|
|
* take first match
|
|
|
|
|
*
|
|
|
|
|
* Perhaps calculate heuristic "score",
|
|
|
|
|
* save score,codes,mode,counter if score
|
|
|
|
|
* better than previous best?
|
1996-10-23 11:52:35 +04:00
|
|
|
|
*/
|
1997-03-13 13:24:14 +03:00
|
|
|
|
goto gotit;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
1997-03-13 13:24:14 +03:00
|
|
|
|
/* XXX try looping for ospeed? */
|
|
|
|
|
} else {
|
|
|
|
|
/* other channel closed */
|
|
|
|
|
int oo, oi; /* other input, output iterators */
|
|
|
|
|
int oic, ooc; /* other input, output codes */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Here when other channel closed. Finds first
|
|
|
|
|
* combination that will allow other channel to be opened
|
|
|
|
|
* (with defaults) and fits our needs.
|
|
|
|
|
*/
|
|
|
|
|
oi = 0;
|
|
|
|
|
for (;;) {
|
|
|
|
|
mode = ANYMODE;
|
|
|
|
|
counter = 0;
|
|
|
|
|
|
|
|
|
|
oic = scniter(&oi, ocp->ispeed, &counter, &mode, NULL, c92);
|
|
|
|
|
if (oic == -1)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
oo = 0;
|
|
|
|
|
while ((ooc = scniter(&oo, ocp->ospeed, &counter,
|
|
|
|
|
&mode, NULL, c92)) != -1) {
|
|
|
|
|
i = 0;
|
|
|
|
|
while ((ic = scniter(&i, ispeed, &counter,
|
|
|
|
|
&mode, NULL, c92)) != -1) {
|
|
|
|
|
o = 0;
|
|
|
|
|
if ((oc = scniter(&o, ospeed, &counter,
|
|
|
|
|
&mode, NULL, c92)) != -1) {
|
|
|
|
|
/*
|
|
|
|
|
* take first match
|
|
|
|
|
*
|
|
|
|
|
* Perhaps calculate heuristic
|
|
|
|
|
* "score", save
|
|
|
|
|
* score,codes,mode,counter
|
|
|
|
|
* if score better than
|
|
|
|
|
* previous best?
|
|
|
|
|
*/
|
|
|
|
|
s = spltty();
|
|
|
|
|
dp->chan[other].icode = oic;
|
|
|
|
|
dp->chan[other].ocode = ooc;
|
|
|
|
|
goto gotit2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
1996-10-23 11:52:35 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
1997-03-13 13:24:14 +03:00
|
|
|
|
return EINVAL;
|
1993-09-10 03:53:45 +04:00
|
|
|
|
|
1997-03-13 13:24:14 +03:00
|
|
|
|
gotit:
|
|
|
|
|
s = spltty();
|
|
|
|
|
gotit2:
|
|
|
|
|
dp->chan[chan].new_mr1 = mr1;
|
|
|
|
|
dp->chan[chan].new_mr2 = mr2;
|
|
|
|
|
dp->chan[chan].ispeed = ispeed;
|
|
|
|
|
dp->chan[chan].ospeed = ospeed;
|
|
|
|
|
dp->chan[chan].icode = ic;
|
|
|
|
|
dp->chan[chan].ocode = oc;
|
|
|
|
|
if (mode == ANYMODE) /* no mode selected?? */
|
|
|
|
|
mode = DEFMODE(c92);
|
|
|
|
|
dp->mode = mode;
|
|
|
|
|
dp->counter = counter;
|
|
|
|
|
|
|
|
|
|
scn_setchip(sc); /* set chip now, if possible */
|
|
|
|
|
splx(s);
|
1996-10-23 11:52:35 +04:00
|
|
|
|
return (0);
|
|
|
|
|
}
|
1997-03-13 13:24:14 +03:00
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
int
|
1995-01-19 10:03:35 +03:00
|
|
|
|
scnprobe(parent, cf, aux)
|
1996-10-23 11:52:35 +04:00
|
|
|
|
struct device *parent;
|
1996-12-23 11:37:07 +03:00
|
|
|
|
struct cfdata *cf;
|
|
|
|
|
void *aux;
|
1997-01-11 13:58:12 +03:00
|
|
|
|
{
|
|
|
|
|
struct confargs *ca = aux;
|
1996-12-23 11:37:07 +03:00
|
|
|
|
int unit = cf->cf_unit;
|
|
|
|
|
int mr1;
|
1996-11-24 16:32:53 +03:00
|
|
|
|
register volatile u_char *ch_base;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
|
1996-11-24 16:32:53 +03:00
|
|
|
|
/* The pc532 doesn't have more then 8 lines. */
|
|
|
|
|
if (unit >= 8) return(0);
|
|
|
|
|
|
|
|
|
|
/* Now some black magic that should detect a scc26x2 channel. */
|
|
|
|
|
ch_base = (volatile u_char *) SCN_FIRST_MAP_ADR + CH_SZ * unit;
|
|
|
|
|
ch_base[CH_CR] = CR_CMD_RESET_ERR;
|
|
|
|
|
RECOVER();
|
|
|
|
|
ch_base[CH_CR] = CR_CMD_RESET_BRK;
|
|
|
|
|
RECOVER();
|
|
|
|
|
ch_base[CH_CR] = CR_CMD_MR1;
|
|
|
|
|
RECOVER();
|
|
|
|
|
mr1 = ch_base[CH_MR] ^ 0x80;
|
|
|
|
|
ch_base[CH_CR] = CR_CMD_MR1;
|
|
|
|
|
RECOVER();
|
|
|
|
|
ch_base[CH_MR] = mr1;
|
|
|
|
|
ch_base[CH_CR] = CR_CMD_MR1;
|
|
|
|
|
RECOVER();
|
|
|
|
|
if (ch_base[CH_MR] != mr1)
|
|
|
|
|
return(0);
|
|
|
|
|
if (ch_base[CH_MR] == mr1)
|
|
|
|
|
return(0);
|
1997-01-11 13:58:12 +03:00
|
|
|
|
|
|
|
|
|
ca->ca_addr = (int)ch_base;
|
|
|
|
|
if (unit & 1)
|
|
|
|
|
ca->ca_irq = -1;
|
|
|
|
|
else
|
|
|
|
|
ca->ca_irq = scnints[unit >> 1] | (rxints[unit >> 1] << 4);
|
|
|
|
|
|
1996-11-24 16:32:53 +03:00
|
|
|
|
return(1);
|
1996-10-23 11:52:35 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* No need to make scn_rx{en,dis}able too efficient,
|
|
|
|
|
* they're only called on setup, open & close!
|
|
|
|
|
*/
|
|
|
|
|
static __inline void
|
|
|
|
|
scn_rxenable(sc)
|
|
|
|
|
struct scn_softc *sc;
|
|
|
|
|
{
|
1997-03-13 13:24:14 +03:00
|
|
|
|
struct duart *dp;
|
1996-12-23 11:37:07 +03:00
|
|
|
|
int channel;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
|
1997-03-13 13:24:14 +03:00
|
|
|
|
dp = sc->sc_duart;
|
|
|
|
|
channel = sc->sc_unit & 1;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
|
|
|
|
|
/* Outputs wire-ored and connected to ICU input for fast rx interrupt. */
|
|
|
|
|
if (channel == 0)
|
1997-03-13 13:24:14 +03:00
|
|
|
|
dp->opcr |= OPCR_OP4_RXRDYA;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
else
|
1997-03-13 13:24:14 +03:00
|
|
|
|
dp->opcr |= OPCR_OP5_RXRDYB;
|
|
|
|
|
dp->base[DU_OPCR] = dp->opcr;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static __inline void
|
|
|
|
|
scn_rxdisable(sc)
|
|
|
|
|
struct scn_softc *sc;
|
1993-09-10 03:53:45 +04:00
|
|
|
|
{
|
1997-03-13 13:24:14 +03:00
|
|
|
|
struct duart *dp;
|
1996-12-23 11:37:07 +03:00
|
|
|
|
int channel;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
|
1997-03-13 13:24:14 +03:00
|
|
|
|
dp = sc->sc_duart;
|
|
|
|
|
channel = sc->sc_unit & 1;
|
1994-03-08 22:47:51 +03:00
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
/* Outputs wire-ored and connected to ICU input for fast rx interrupt. */
|
|
|
|
|
if (channel == 0)
|
1997-03-13 13:24:14 +03:00
|
|
|
|
dp->opcr &= ~OPCR_OP4_RXRDYA;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
else
|
1997-03-13 13:24:14 +03:00
|
|
|
|
dp->opcr &= ~OPCR_OP5_RXRDYB;
|
|
|
|
|
dp->base[DU_OPCR] = dp->opcr;
|
1993-09-10 03:53:45 +04:00
|
|
|
|
}
|
|
|
|
|
|
1995-01-19 10:03:35 +03:00
|
|
|
|
void
|
1995-04-27 11:18:02 +04:00
|
|
|
|
scnattach(parent, self, aux)
|
1996-10-23 11:52:35 +04:00
|
|
|
|
struct device *parent;
|
|
|
|
|
struct device *self;
|
|
|
|
|
void *aux;
|
1993-09-10 03:53:45 +04:00
|
|
|
|
{
|
1997-01-11 13:58:12 +03:00
|
|
|
|
struct confargs *ca = aux;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
register struct scn_softc *sc;
|
|
|
|
|
register volatile u_char *ch_base;
|
|
|
|
|
register volatile u_char *duart_base;
|
1996-12-23 11:37:07 +03:00
|
|
|
|
long scn_first_adr;
|
|
|
|
|
int channel;
|
|
|
|
|
int speed;
|
1997-01-11 13:58:12 +03:00
|
|
|
|
int s;
|
|
|
|
|
u_char unit;
|
|
|
|
|
u_char duart;
|
|
|
|
|
u_char delim = ':';
|
1997-03-20 15:03:03 +03:00
|
|
|
|
enum scntype scntype = SCNUNK;
|
|
|
|
|
char *duart_type = "Unknown";
|
1996-10-23 11:52:35 +04:00
|
|
|
|
|
|
|
|
|
sc = (void *) self;
|
1997-03-13 13:24:14 +03:00
|
|
|
|
unit = self->dv_unit; /* sc->sc_dev.dv_unit ??? */
|
1996-10-23 11:52:35 +04:00
|
|
|
|
|
|
|
|
|
duart = unit >> 1; /* get chip number */
|
|
|
|
|
channel = unit & 1; /* get channel on chip */
|
|
|
|
|
|
|
|
|
|
/* pick up "flags" (SCN_xxx) from config file */
|
|
|
|
|
if (self->dv_cfdata) /* paranoia */
|
1997-03-13 13:24:14 +03:00
|
|
|
|
sc->sc_swflags = ca->ca_flags;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
else
|
1997-03-13 13:24:14 +03:00
|
|
|
|
sc->sc_swflags = 0;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
|
|
|
|
|
if (unit == scnconsole) /* console? */
|
1997-03-13 13:24:14 +03:00
|
|
|
|
sc->sc_swflags |= SCN_SW_SOFTCAR; /* ignore carrier */
|
1996-10-23 11:52:35 +04:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Precalculate port numbers for speed.
|
|
|
|
|
* Magic numbers in the code (once).
|
|
|
|
|
*
|
|
|
|
|
* XXX get physical addr from "cfdata" (put there from config file)
|
|
|
|
|
* and pass to a map_regs() routine which returns virtual (mapped) addr?
|
|
|
|
|
*/
|
|
|
|
|
scn_first_adr = SCN_FIRST_MAP_ADR; /* to get around a gcc bug. */
|
|
|
|
|
|
|
|
|
|
ch_base = (volatile u_char *) scn_first_adr + CH_SZ * unit;
|
|
|
|
|
duart_base = (volatile u_char *) scn_first_adr + DUART_SZ * duart;
|
|
|
|
|
|
|
|
|
|
if (channel == 0) {
|
1996-12-23 11:37:07 +03:00
|
|
|
|
/* Probe DUART type */
|
|
|
|
|
unsigned char mr1, mr2;
|
|
|
|
|
s = spltty();
|
|
|
|
|
if(unit == scnconsole) {
|
|
|
|
|
ch_base[CH_CR] = CR_DIS_TX;
|
|
|
|
|
delay(5 * 10000);
|
|
|
|
|
}
|
|
|
|
|
ch_base[CH_CR] = CR_CMD_MR1;
|
|
|
|
|
RECOVER();
|
|
|
|
|
mr1 = ch_base[CH_MR];
|
|
|
|
|
mr2 = ch_base[CH_MR];
|
|
|
|
|
ch_base[CH_CR] = CR_CMD_MR1;
|
|
|
|
|
RECOVER();
|
|
|
|
|
ch_base[CH_MR] = 1;
|
|
|
|
|
ch_base[CH_MR] = 0;
|
|
|
|
|
ch_base[CH_CR] = CR_CMD_MR1;
|
|
|
|
|
RECOVER();
|
|
|
|
|
if (ch_base[CH_MR] == 1) {
|
|
|
|
|
/* MR 2 selected */
|
|
|
|
|
ch_base[CH_CR] = CR_CMD_MR0;
|
|
|
|
|
RECOVER();
|
|
|
|
|
/* if 2681, MR2 still selected */
|
|
|
|
|
ch_base[CH_MR] = 1;
|
|
|
|
|
ch_base[CH_CR] = CR_CMD_MR1;
|
|
|
|
|
RECOVER();
|
|
|
|
|
ch_base[CH_MR] = 0; /* MR1 */
|
|
|
|
|
ch_base[CH_MR] = 0; /* MR2 */
|
|
|
|
|
ch_base[CH_CR] = CR_CMD_MR0;
|
|
|
|
|
RECOVER();
|
|
|
|
|
/* if 2681, MR2 still selected */
|
|
|
|
|
if((ch_base[CH_MR] & 1) == 1) {
|
1997-01-11 13:58:12 +03:00
|
|
|
|
duart_type = "sc26c92";
|
1997-03-13 13:24:14 +03:00
|
|
|
|
scntype = SC26C92;
|
1996-12-23 11:37:07 +03:00
|
|
|
|
} else {
|
1997-03-13 13:24:14 +03:00
|
|
|
|
/* 2681 treats as MR1 Select */
|
|
|
|
|
ch_base[CH_CR] = CR_CMD_RTS_OFF;
|
1996-12-23 11:37:07 +03:00
|
|
|
|
RECOVER();
|
|
|
|
|
ch_base[CH_MR] = 1;
|
|
|
|
|
ch_base[CH_MR] = 0;
|
|
|
|
|
ch_base[CH_CR] = CR_CMD_RTS_OFF;
|
|
|
|
|
RECOVER();
|
|
|
|
|
if (ch_base[CH_MR] == 1) {
|
1997-01-11 13:58:12 +03:00
|
|
|
|
duart_type = "scn2681";
|
1997-03-13 13:24:14 +03:00
|
|
|
|
scntype = SCN2681;
|
1996-12-23 11:37:07 +03:00
|
|
|
|
} else {
|
1997-03-13 13:24:14 +03:00
|
|
|
|
duart_type = "scn2692";
|
|
|
|
|
scntype = SCN2692;
|
1996-12-23 11:37:07 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If a 2681, the CR_CMD_MR0 is interpreted as a TX_RESET */
|
|
|
|
|
if(unit == scnconsole) {
|
|
|
|
|
ch_base[CH_CR] = CR_ENA_TX;
|
|
|
|
|
RECOVER();
|
|
|
|
|
}
|
|
|
|
|
ch_base[CH_CR] = CR_CMD_MR1;
|
|
|
|
|
RECOVER();
|
|
|
|
|
ch_base[CH_MR] = mr1;
|
|
|
|
|
ch_base[CH_MR] = mr2;
|
|
|
|
|
splx(s);
|
1997-03-13 13:24:14 +03:00
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
/* Arg 0 is special, so we must pass "unit + 1" */
|
1996-12-23 11:37:07 +03:00
|
|
|
|
intr_establish(scnints[duart], scnintr, (void *) (unit + 1),
|
|
|
|
|
"scn", IPL_TTY, IPL_ZERO, LOW_LEVEL);
|
|
|
|
|
|
1997-01-11 13:58:12 +03:00
|
|
|
|
printf("%c %s", delim, duart_type);
|
|
|
|
|
delim = ',';
|
1996-10-23 11:52:35 +04:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* IPL_ZERO is the right priority for the rx interrupt.
|
|
|
|
|
* Only splhigh() should disable rxints.
|
|
|
|
|
*/
|
1996-12-23 11:37:07 +03:00
|
|
|
|
intr_establish(rxints[duart], scnrxintr, (void *) (unit + 1),
|
|
|
|
|
"scnrx", IPL_ZERO, IPL_RTTY, LOW_LEVEL);
|
1996-10-23 11:52:35 +04:00
|
|
|
|
}
|
|
|
|
|
/* Record unit number, uart */
|
1997-03-13 13:24:14 +03:00
|
|
|
|
sc->sc_unit = unit;
|
|
|
|
|
sc->sc_chbase = ch_base;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
|
|
|
|
|
/* Initialize modem/interrupt bit masks */
|
|
|
|
|
if (channel == 0) {
|
1997-03-13 13:24:14 +03:00
|
|
|
|
sc->sc_duart = malloc(sizeof(struct duart), M_DEVBUF, M_NOWAIT);
|
|
|
|
|
if (sc->sc_duart == NULL)
|
1996-11-24 16:32:53 +03:00
|
|
|
|
panic("scn%d: memory allocation for duart structure failed", unit);
|
1997-03-13 13:24:14 +03:00
|
|
|
|
sc->sc_duart->base = duart_base;
|
|
|
|
|
sc->sc_duart->type = scntype;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
sc->sc_op_rts = OP_RTSA;
|
|
|
|
|
sc->sc_op_dtr = OP_DTRA;
|
|
|
|
|
sc->sc_ip_cts = IP_CTSA;
|
|
|
|
|
sc->sc_ip_dcd = IP_DCDA;
|
|
|
|
|
|
|
|
|
|
sc->sc_tx_int = INT_TXA;
|
|
|
|
|
} else {
|
1997-03-13 13:24:14 +03:00
|
|
|
|
sc->sc_duart = ((struct scn_softc *)SOFTC(unit - 1))->sc_duart;
|
1996-11-24 16:32:53 +03:00
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
sc->sc_op_rts = OP_RTSB;
|
|
|
|
|
sc->sc_op_dtr = OP_DTRB;
|
|
|
|
|
sc->sc_ip_cts = IP_CTSB;
|
|
|
|
|
sc->sc_ip_dcd = IP_DCDB;
|
|
|
|
|
|
|
|
|
|
sc->sc_tx_int = INT_TXB;
|
|
|
|
|
}
|
1993-09-10 03:53:45 +04:00
|
|
|
|
|
1997-03-13 13:24:14 +03:00
|
|
|
|
/* Initialize counters */
|
|
|
|
|
sc->sc_framing_errors = 0;
|
|
|
|
|
sc->sc_fifo_overruns = 0;
|
|
|
|
|
sc->sc_parity_errors = 0;
|
|
|
|
|
sc->sc_breaks = 0;
|
1993-09-10 03:53:45 +04:00
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
if (unit == scnconsole) {
|
|
|
|
|
DELAY(5 * 10000); /* Let the output go out.... */
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
* Set up the hardware to a base state, in particular:
|
|
|
|
|
* o reset transmitter and receiver
|
|
|
|
|
* o set speeds and configurations
|
|
|
|
|
* o receiver interrupts only (RxRDY and BREAK)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
s = spltty();
|
|
|
|
|
/* RTS off... */
|
|
|
|
|
SCN_OP_BIC(sc, sc->sc_op_rts); /* "istop" */
|
|
|
|
|
|
|
|
|
|
ch_base[CH_CR] = CR_DIS_RX | CR_DIS_TX;
|
1996-11-24 16:32:53 +03:00
|
|
|
|
RECOVER();
|
1996-10-23 11:52:35 +04:00
|
|
|
|
ch_base[CH_CR] = CR_CMD_RESET_RX;
|
1996-11-24 16:32:53 +03:00
|
|
|
|
RECOVER();
|
1996-10-23 11:52:35 +04:00
|
|
|
|
ch_base[CH_CR] = CR_CMD_RESET_TX;
|
1996-11-24 16:32:53 +03:00
|
|
|
|
RECOVER();
|
1996-10-23 11:52:35 +04:00
|
|
|
|
ch_base[CH_CR] = CR_CMD_RESET_ERR;
|
1996-11-24 16:32:53 +03:00
|
|
|
|
RECOVER();
|
1996-10-23 11:52:35 +04:00
|
|
|
|
ch_base[CH_CR] = CR_CMD_RESET_BRK;
|
1996-11-24 16:32:53 +03:00
|
|
|
|
RECOVER();
|
1996-10-23 11:52:35 +04:00
|
|
|
|
ch_base[CH_CR] = CR_CMD_MR1;
|
1996-11-24 16:32:53 +03:00
|
|
|
|
RECOVER();
|
1996-10-23 11:52:35 +04:00
|
|
|
|
|
|
|
|
|
/* No receiver control of RTS. */
|
|
|
|
|
ch_base[CH_MR] = 0;
|
|
|
|
|
ch_base[CH_MR] = 0;
|
|
|
|
|
|
|
|
|
|
/* Initialize the uart structure if this is channel A. */
|
|
|
|
|
if (channel == 0) {
|
|
|
|
|
/* Disable all interrupts. */
|
1997-03-13 13:24:14 +03:00
|
|
|
|
duart_base[DU_IMR] = sc->sc_duart->imr = 0;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
|
|
|
|
|
/* Output port config */
|
1997-03-13 13:24:14 +03:00
|
|
|
|
duart_base[DU_OPCR] = sc->sc_duart->opcr = 0;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
|
|
|
|
|
/* Speeds... */
|
1997-03-13 13:24:14 +03:00
|
|
|
|
sc->sc_duart->mode = 0;
|
|
|
|
|
/*
|
|
|
|
|
* Set initial speed to an illegal code that can be changed to
|
|
|
|
|
* any other baud.
|
|
|
|
|
*/
|
|
|
|
|
sc->sc_duart->chan[0].icode = sc->sc_duart->chan[0].ocode = 0x2f;
|
|
|
|
|
sc->sc_duart->chan[1].icode = sc->sc_duart->chan[1].ocode = 0x2f;
|
|
|
|
|
sc->sc_duart->chan[0].ispeed = sc->sc_duart->chan[0].ospeed = 0;
|
|
|
|
|
sc->sc_duart->chan[1].ispeed = sc->sc_duart->chan[1].ospeed = 0;
|
|
|
|
|
|
|
|
|
|
sc->sc_duart->acr = 0;
|
|
|
|
|
sc->sc_duart->acr |= ACR_CT_TCLK1; /* timer mode 1x clk */
|
|
|
|
|
sc->sc_duart->acr |= ACR_DELTA_DCDA; /* Set CD int */
|
1996-10-23 11:52:35 +04:00
|
|
|
|
} else {
|
1997-03-13 13:24:14 +03:00
|
|
|
|
sc->sc_duart->acr |= ACR_DELTA_DCDB; /* Set CD int */
|
1996-10-23 11:52:35 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (scnsir == -1) {
|
|
|
|
|
/* software intr: calls tty code, hence IPL_TTY */
|
1996-12-23 11:37:07 +03:00
|
|
|
|
scnsir = intr_establish(SOFTINT, scnsoft, NULL,
|
|
|
|
|
"softscn", IPL_TTY, IPL_TTY, 0);
|
1996-10-23 11:52:35 +04:00
|
|
|
|
}
|
1993-09-10 03:53:45 +04:00
|
|
|
|
|
1997-03-13 13:24:14 +03:00
|
|
|
|
duart_base[DU_ACR] = (sc->sc_duart->mode & ACR_BRG) | sc->sc_duart->acr;
|
1993-09-10 03:53:45 +04:00
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
if (unit == scnconsole)
|
|
|
|
|
speed = scnconsrate;
|
|
|
|
|
else
|
|
|
|
|
speed = scndefaultrate;
|
|
|
|
|
|
1997-03-13 13:24:14 +03:00
|
|
|
|
scn_config(unit, speed, speed, MR1_PNONE | MR1_CS8, MR2_STOP1);
|
1997-03-20 15:03:03 +03:00
|
|
|
|
if (scnconsole == unit) {
|
1996-10-23 11:52:35 +04:00
|
|
|
|
shutdownhook_establish(scncnreinit, (void *) makedev(scnmajor, unit));
|
1997-03-20 15:03:03 +03:00
|
|
|
|
/* Make sure console can do scncngetc */
|
|
|
|
|
duart_base[DU_OPSET] = (unit & 1) ? (OP_RTSB | OP_DTRB) : (OP_RTSA | OP_DTRA);
|
|
|
|
|
}
|
1996-10-23 11:52:35 +04:00
|
|
|
|
|
|
|
|
|
/* Turn on the receiver and transmitters */
|
|
|
|
|
ch_base[CH_CR] = CR_ENA_RX | CR_ENA_TX;
|
1993-09-10 03:53:45 +04:00
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
/* Set up the interrupts. */
|
1997-03-13 13:24:14 +03:00
|
|
|
|
sc->sc_duart->imr |= INT_IP;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
scn_rxdisable(sc);
|
|
|
|
|
splx(s);
|
1993-09-10 03:53:45 +04:00
|
|
|
|
|
1997-03-13 13:24:14 +03:00
|
|
|
|
if (sc->sc_swflags) {
|
|
|
|
|
printf("%c flags %d", delim, sc->sc_swflags);
|
1997-01-11 13:58:12 +03:00
|
|
|
|
delim = ',';
|
|
|
|
|
}
|
|
|
|
|
|
1993-09-10 03:53:45 +04:00
|
|
|
|
#ifdef KGDB
|
1996-10-23 11:52:35 +04:00
|
|
|
|
if (kgdb_dev == makedev(scnmajor, unit)) {
|
1993-09-10 03:53:45 +04:00
|
|
|
|
if (scnconsole == unit)
|
1997-03-13 13:24:14 +03:00
|
|
|
|
kgdb_dev = NODEV; /* can't debug over console port */
|
1993-09-10 03:53:45 +04:00
|
|
|
|
else {
|
1996-10-23 11:52:35 +04:00
|
|
|
|
scninit(kgdb_dev, kgdb_rate);
|
|
|
|
|
scn_rxenable(sc);
|
|
|
|
|
scnkgdb = DEV_UNIT(kgdb_dev);
|
1997-04-01 20:31:53 +04:00
|
|
|
|
kgdb_attach((int (*) __P((void *)))scncngetc,
|
|
|
|
|
(void (*) __P((void *, int)))scncnputc,
|
|
|
|
|
(void *)kgdb_dev);
|
1993-09-10 03:53:45 +04:00
|
|
|
|
if (kgdb_debug_init) {
|
1997-01-11 13:58:12 +03:00
|
|
|
|
printf("%c ", delim);
|
1993-09-10 03:53:45 +04:00
|
|
|
|
kgdb_connect(1);
|
|
|
|
|
} else
|
1997-01-11 13:58:12 +03:00
|
|
|
|
printf("%c kgdb enabled", delim);
|
|
|
|
|
delim = ',';
|
1993-09-10 03:53:45 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
1996-10-23 11:52:35 +04:00
|
|
|
|
printf("\n");
|
1993-09-10 03:53:45 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
1996-10-23 11:52:35 +04:00
|
|
|
|
int
|
|
|
|
|
scnopen(dev, flag, mode, p)
|
1996-12-23 11:37:07 +03:00
|
|
|
|
dev_t dev;
|
|
|
|
|
int flag;
|
|
|
|
|
int mode;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
struct proc *p;
|
1993-09-10 03:53:45 +04:00
|
|
|
|
{
|
|
|
|
|
register struct tty *tp;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
register int unit = DEV_UNIT(dev);
|
|
|
|
|
register struct scn_softc *sc;
|
1996-12-23 11:37:07 +03:00
|
|
|
|
int error = 0;
|
|
|
|
|
int hwset = 0;
|
|
|
|
|
int s;
|
1994-03-22 03:15:21 +03:00
|
|
|
|
|
1996-03-17 04:38:52 +03:00
|
|
|
|
if (unit >= scn_cd.cd_ndevs)
|
1995-04-27 11:18:02 +04:00
|
|
|
|
return ENXIO;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
sc = SOFTC(unit);
|
1995-04-27 11:18:02 +04:00
|
|
|
|
if (!sc)
|
|
|
|
|
return ENXIO;
|
1994-03-22 03:15:21 +03:00
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
s = spltty();
|
1997-03-13 13:24:14 +03:00
|
|
|
|
if (!sc->sc_tty) {
|
|
|
|
|
tp = sc->sc_tty = ttymalloc();
|
1996-10-23 11:52:35 +04:00
|
|
|
|
tty_attach(tp);
|
1993-09-10 03:53:45 +04:00
|
|
|
|
} else
|
1997-03-13 13:24:14 +03:00
|
|
|
|
tp = sc->sc_tty;
|
1995-04-27 11:18:02 +04:00
|
|
|
|
|
1993-09-10 03:53:45 +04:00
|
|
|
|
tp->t_oproc = scnstart;
|
|
|
|
|
tp->t_param = scnparam;
|
1996-12-23 11:37:07 +03:00
|
|
|
|
tp->t_hwiflow = scnhwiflow;
|
1993-09-10 03:53:45 +04:00
|
|
|
|
tp->t_dev = dev;
|
1996-12-23 11:37:07 +03:00
|
|
|
|
|
1998-03-31 00:10:26 +04:00
|
|
|
|
if ((tp->t_state & TS_ISOPEN) == 0 && tp->t_wopen == 0) {
|
1993-09-10 03:53:45 +04:00
|
|
|
|
ttychars(tp);
|
1994-03-22 03:15:21 +03:00
|
|
|
|
tp->t_iflag = TTYDEF_IFLAG;
|
|
|
|
|
tp->t_oflag = TTYDEF_OFLAG;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
tp->t_cflag = SCNDEF_CFLAG;
|
1996-12-23 11:37:07 +03:00
|
|
|
|
|
|
|
|
|
sc->sc_rx_blocked = 0;
|
|
|
|
|
|
1997-03-13 13:24:14 +03:00
|
|
|
|
if (sc->sc_swflags & SCN_SW_CLOCAL)
|
1994-03-22 03:15:21 +03:00
|
|
|
|
tp->t_cflag |= CLOCAL;
|
1997-03-13 13:24:14 +03:00
|
|
|
|
if (sc->sc_swflags & SCN_SW_CRTSCTS)
|
1996-10-23 11:52:35 +04:00
|
|
|
|
tp->t_cflag |= CCTS_OFLOW | CRTS_IFLOW;
|
1994-03-22 03:15:21 +03:00
|
|
|
|
tp->t_lflag = TTYDEF_LFLAG;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
if (unit == scnconsole)
|
|
|
|
|
tp->t_ispeed = tp->t_ospeed = scnconsrate;
|
|
|
|
|
else
|
|
|
|
|
tp->t_ispeed = tp->t_ospeed = scndefaultrate;
|
1993-09-10 03:53:45 +04:00
|
|
|
|
scnparam(tp, &tp->t_termios);
|
|
|
|
|
ttsetwater(tp);
|
|
|
|
|
|
|
|
|
|
/* Turn on DTR and RTS. */
|
1996-10-23 11:52:35 +04:00
|
|
|
|
SCN_OP_BIS(sc, sc->sc_op_rts | sc->sc_op_dtr);
|
|
|
|
|
|
|
|
|
|
/* enable reciever interrupts */
|
|
|
|
|
scn_rxenable(sc);
|
1996-12-23 11:37:07 +03:00
|
|
|
|
hwset = 1;
|
1993-09-10 03:53:45 +04:00
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
/* set carrier state; */
|
1997-03-13 13:24:14 +03:00
|
|
|
|
if ((sc->sc_swflags & SCN_SW_SOFTCAR) || /* check ttyflags */
|
|
|
|
|
SCN_DCD(sc) || /* check h/w */
|
1996-10-23 11:52:35 +04:00
|
|
|
|
DEV_DIALOUT(dev))
|
|
|
|
|
tp->t_state |= TS_CARR_ON;
|
|
|
|
|
else
|
|
|
|
|
tp->t_state &= ~TS_CARR_ON;
|
1997-03-13 13:24:14 +03:00
|
|
|
|
} else {
|
1996-10-23 11:52:35 +04:00
|
|
|
|
if (tp->t_state & TS_XCLUDE && p->p_ucred->cr_uid != 0) {
|
|
|
|
|
splx(s);
|
|
|
|
|
return (EBUSY);
|
1997-03-13 13:24:14 +03:00
|
|
|
|
} else {
|
1996-10-23 11:52:35 +04:00
|
|
|
|
if (DEV_DIALOUT(dev) && !SCN_DIALOUT(sc)) {
|
|
|
|
|
/* dialout attempt while someone dialed in */
|
|
|
|
|
splx(s);
|
|
|
|
|
return (EBUSY);
|
|
|
|
|
}
|
1997-03-13 13:24:14 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
1996-10-23 11:52:35 +04:00
|
|
|
|
if (DEV_DIALOUT(dev)) {
|
|
|
|
|
/* dialout open and no one dialed in (see above) */
|
|
|
|
|
SCN_SETDIALOUT(sc); /* mark line as dialed out */
|
|
|
|
|
}
|
|
|
|
|
if (flag & O_NONBLOCK) {
|
|
|
|
|
/* Non-blocking open
|
|
|
|
|
*
|
|
|
|
|
* If non-dialout open, and currenly opened for dialout you
|
|
|
|
|
* lose.
|
|
|
|
|
*/
|
|
|
|
|
if (!DEV_DIALOUT(dev) && SCN_DIALOUT(sc)) {
|
|
|
|
|
splx(s);
|
|
|
|
|
return EBUSY;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/* Blocking open
|
|
|
|
|
*
|
|
|
|
|
* This used to be more compact (while loop with lots of nots)
|
|
|
|
|
* but it was incomprehensible.
|
|
|
|
|
*
|
|
|
|
|
* "getty" is the classic case of a program that waits here...
|
|
|
|
|
*/
|
|
|
|
|
for (;;) {
|
|
|
|
|
if (SCN_DIALOUT(sc)) {
|
|
|
|
|
/* Currently opened for dialout. */
|
|
|
|
|
if (DEV_DIALOUT(dev))
|
|
|
|
|
/* No need to wait if dialout open */
|
|
|
|
|
break;
|
|
|
|
|
/*
|
|
|
|
|
* "getty" falls thru and waits while line
|
|
|
|
|
* dialed out.
|
|
|
|
|
*/
|
|
|
|
|
} else {
|
|
|
|
|
/* Not currently opened for dialout. */
|
|
|
|
|
if ((tp->t_cflag & CLOCAL) || /* "local" line? */
|
|
|
|
|
(tp->t_state & TS_CARR_ON)) /* or carrier up */
|
|
|
|
|
break; /* no (more) waiting */
|
1997-03-13 13:24:14 +03:00
|
|
|
|
/*
|
|
|
|
|
*"getty" on modem falls thru and waits for
|
|
|
|
|
* carrier up
|
|
|
|
|
*/
|
1996-10-23 11:52:35 +04:00
|
|
|
|
}
|
|
|
|
|
error = ttysleep(tp, (caddr_t) & tp->t_rawq,
|
1994-03-22 03:15:21 +03:00
|
|
|
|
TTIPRI | PCATCH, ttopen, 0);
|
|
|
|
|
if (error) {
|
1996-10-23 11:52:35 +04:00
|
|
|
|
/* XXX should turn off chip if we're the only
|
|
|
|
|
* waiter */
|
|
|
|
|
|
|
|
|
|
/* XXX drop RTS too? -plb */
|
|
|
|
|
/* XXX dialout state??? -plb */
|
|
|
|
|
SCN_OP_BIC(sc, sc->sc_op_dtr);
|
|
|
|
|
splx(s);
|
1994-03-22 03:15:21 +03:00
|
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
}
|
1996-10-23 11:52:35 +04:00
|
|
|
|
}
|
|
|
|
|
splx(s);
|
|
|
|
|
|
2000-11-02 03:37:56 +03:00
|
|
|
|
error = (*tp->t_linesw->l_open) (dev, tp);
|
1996-12-23 11:37:07 +03:00
|
|
|
|
if (error && hwset) {
|
|
|
|
|
scn_rxdisable(sc);
|
1996-10-23 11:52:35 +04:00
|
|
|
|
SCN_OP_BIC(sc, sc->sc_op_rts | sc->sc_op_dtr);
|
|
|
|
|
}
|
|
|
|
|
return (error);
|
1993-09-10 03:53:45 +04:00
|
|
|
|
}
|
1996-10-23 11:52:35 +04:00
|
|
|
|
|
|
|
|
|
|
1993-09-10 03:53:45 +04:00
|
|
|
|
/*ARGSUSED*/
|
1996-10-23 11:52:35 +04:00
|
|
|
|
int
|
1993-09-10 03:53:45 +04:00
|
|
|
|
scnclose(dev, flag, mode, p)
|
1996-12-23 11:37:07 +03:00
|
|
|
|
dev_t dev;
|
|
|
|
|
int flag;
|
|
|
|
|
int mode;
|
1993-09-10 03:53:45 +04:00
|
|
|
|
struct proc *p;
|
|
|
|
|
{
|
1996-10-23 11:52:35 +04:00
|
|
|
|
register int unit = DEV_UNIT(dev);
|
|
|
|
|
register struct scn_softc *sc = SOFTC(unit);
|
1997-03-13 13:24:14 +03:00
|
|
|
|
register struct tty *tp = sc->sc_tty;
|
1993-09-10 03:53:45 +04:00
|
|
|
|
|
1996-12-23 11:37:07 +03:00
|
|
|
|
if ((tp->t_state & TS_ISOPEN) == 0)
|
1997-03-13 13:24:14 +03:00
|
|
|
|
return 0;
|
1996-12-23 11:37:07 +03:00
|
|
|
|
|
2000-11-02 03:37:56 +03:00
|
|
|
|
(*tp->t_linesw->l_close) (tp, flag);
|
1996-10-23 11:52:35 +04:00
|
|
|
|
|
1993-09-10 03:53:45 +04:00
|
|
|
|
#ifdef KGDB
|
|
|
|
|
/* do not disable interrupts if debugging */
|
|
|
|
|
if (kgdb_dev != makedev(scnmajor, unit))
|
|
|
|
|
#endif
|
1996-10-23 11:52:35 +04:00
|
|
|
|
if ((tp->t_state & TS_ISOPEN) == 0) {
|
|
|
|
|
scn_rxdisable(sc);
|
|
|
|
|
}
|
1997-03-13 13:24:14 +03:00
|
|
|
|
if ((tp->t_cflag & HUPCL) && (sc->sc_swflags & SCN_SW_SOFTCAR) == 0) {
|
1996-10-23 11:52:35 +04:00
|
|
|
|
SCN_OP_BIC(sc, sc->sc_op_dtr);
|
|
|
|
|
/* hold low for 1 second */
|
|
|
|
|
(void) tsleep((caddr_t)sc, TTIPRI, ttclos, hz);
|
1993-09-10 03:53:45 +04:00
|
|
|
|
}
|
1996-10-23 11:52:35 +04:00
|
|
|
|
SCN_CLRDIALOUT(sc);
|
1994-03-08 22:47:51 +03:00
|
|
|
|
ttyclose(tp);
|
1996-10-23 11:52:35 +04:00
|
|
|
|
|
1994-03-11 00:35:48 +03:00
|
|
|
|
#if 0
|
1996-10-23 11:52:35 +04:00
|
|
|
|
if ((tp->t_state & TS_ISOPEN) == 0) {
|
1994-03-11 00:35:48 +03:00
|
|
|
|
ttyfree(tp);
|
1997-03-13 13:24:14 +03:00
|
|
|
|
sc->sc_tty = (struct tty *) NULL;
|
1994-03-11 00:35:48 +03:00
|
|
|
|
}
|
1994-03-08 22:47:51 +03:00
|
|
|
|
#endif
|
1996-10-23 11:52:35 +04:00
|
|
|
|
|
|
|
|
|
return (0);
|
1993-09-10 03:53:45 +04:00
|
|
|
|
}
|
1996-10-23 11:52:35 +04:00
|
|
|
|
|
|
|
|
|
int
|
1993-09-10 03:53:45 +04:00
|
|
|
|
scnread(dev, uio, flag)
|
1996-12-23 11:37:07 +03:00
|
|
|
|
dev_t dev;
|
1993-09-10 03:53:45 +04:00
|
|
|
|
struct uio *uio;
|
1996-12-23 11:37:07 +03:00
|
|
|
|
int flag;
|
1993-09-10 03:53:45 +04:00
|
|
|
|
{
|
1996-10-23 11:52:35 +04:00
|
|
|
|
register struct scn_softc *sc = SOFTC(DEV_UNIT(dev));
|
1997-03-13 13:24:14 +03:00
|
|
|
|
register struct tty *tp = sc->sc_tty;
|
1993-09-10 03:53:45 +04:00
|
|
|
|
|
2000-11-02 03:37:56 +03:00
|
|
|
|
return ((*tp->t_linesw->l_read) (tp, uio, flag));
|
1993-09-10 03:53:45 +04:00
|
|
|
|
}
|
1996-10-23 11:52:35 +04:00
|
|
|
|
|
|
|
|
|
int
|
1993-09-10 03:53:45 +04:00
|
|
|
|
scnwrite(dev, uio, flag)
|
1996-12-23 11:37:07 +03:00
|
|
|
|
dev_t dev;
|
1993-09-10 03:53:45 +04:00
|
|
|
|
struct uio *uio;
|
1996-12-23 11:37:07 +03:00
|
|
|
|
int flag;
|
1993-09-10 03:53:45 +04:00
|
|
|
|
{
|
1996-10-23 11:52:35 +04:00
|
|
|
|
register struct scn_softc *sc = SOFTC(DEV_UNIT(dev));
|
1997-03-13 13:24:14 +03:00
|
|
|
|
register struct tty *tp = sc->sc_tty;
|
1993-09-10 03:53:45 +04:00
|
|
|
|
|
2000-11-02 03:37:56 +03:00
|
|
|
|
return ((*tp->t_linesw->l_write) (tp, uio, flag));
|
1993-09-10 03:53:45 +04:00
|
|
|
|
}
|
|
|
|
|
|
1995-04-27 11:18:02 +04:00
|
|
|
|
struct tty *
|
|
|
|
|
scntty(dev)
|
1996-12-23 11:37:07 +03:00
|
|
|
|
dev_t dev;
|
1995-04-27 11:18:02 +04:00
|
|
|
|
{
|
1996-10-23 11:52:35 +04:00
|
|
|
|
register struct scn_softc *sc = SOFTC(DEV_UNIT(dev));
|
1995-04-27 11:18:02 +04:00
|
|
|
|
|
1997-03-13 13:24:14 +03:00
|
|
|
|
return sc->sc_tty;
|
1995-04-27 11:18:02 +04:00
|
|
|
|
}
|
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
/* Worker routines for interrupt processing */
|
|
|
|
|
static __inline void
|
|
|
|
|
dcd_int(sc, tp, new)
|
|
|
|
|
struct scn_softc *sc;
|
|
|
|
|
struct tty *tp;
|
1996-12-23 11:37:07 +03:00
|
|
|
|
u_char new;
|
1994-04-17 11:52:15 +04:00
|
|
|
|
{
|
1997-03-13 13:24:14 +03:00
|
|
|
|
if (sc->sc_swflags & SCN_SW_SOFTCAR)
|
1996-10-23 11:52:35 +04:00
|
|
|
|
return;
|
1994-04-17 11:52:15 +04:00
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
#if 0
|
|
|
|
|
printf("scn%d: dcd_int ip %x SCN_DCD %x new %x ipcr %x\n",
|
|
|
|
|
sc->unit,
|
1997-03-13 13:24:14 +03:00
|
|
|
|
sc->sc_duart->base[DU_IP],
|
1996-10-23 11:52:35 +04:00
|
|
|
|
SCN_DCD(sc),
|
|
|
|
|
new,
|
1997-03-13 13:24:14 +03:00
|
|
|
|
sc->sc_duart->base[DU_IPCR]
|
1996-10-23 11:52:35 +04:00
|
|
|
|
);
|
|
|
|
|
#endif
|
1993-09-10 03:53:45 +04:00
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
/* XXX set some flag to have some lower (soft) int call line discipline? */
|
1996-12-23 11:37:07 +03:00
|
|
|
|
if (!(*linesw[(u_char) tp->t_line].l_modem) (tp, new == 0? 1: 0)) {
|
1997-03-13 13:24:14 +03:00
|
|
|
|
SCN_OP_BIC(sc, sc->sc_op_rts | sc->sc_op_dtr);
|
1996-12-23 11:37:07 +03:00
|
|
|
|
}
|
1996-10-23 11:52:35 +04:00
|
|
|
|
}
|
1995-04-27 11:18:02 +04:00
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
/*
|
|
|
|
|
* Print out a ring or fifo overrun error message.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
scnoverrun(unit, ptime, what)
|
1996-12-23 11:37:07 +03:00
|
|
|
|
int unit;
|
|
|
|
|
long *ptime;
|
|
|
|
|
char *what;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
{
|
|
|
|
|
if (*ptime != time.tv_sec) {
|
|
|
|
|
*ptime = time.tv_sec;
|
|
|
|
|
log(LOG_WARNING, "scn%d: %s overrun\n", unit, what);
|
|
|
|
|
}
|
|
|
|
|
}
|
1993-09-10 03:53:45 +04:00
|
|
|
|
|
1996-12-23 11:37:07 +03:00
|
|
|
|
/*
|
|
|
|
|
* Try to block or unblock input using hardware flow-control.
|
|
|
|
|
* This is called by kern/tty.c if MDMBUF|CRTSCTS is set, and
|
|
|
|
|
* if this function returns non-zero, the TS_TBLOCK flag will
|
|
|
|
|
* be set or cleared according to the "stop" arg passed.
|
|
|
|
|
*/
|
|
|
|
|
int
|
|
|
|
|
scnhwiflow(tp, stop)
|
|
|
|
|
struct tty *tp;
|
|
|
|
|
int stop;
|
|
|
|
|
{
|
|
|
|
|
int unit = DEV_UNIT(tp->t_dev);
|
|
|
|
|
struct scn_softc *sc = SOFTC(unit);
|
|
|
|
|
int s = splrtty();
|
|
|
|
|
|
|
|
|
|
if (!stop) {
|
|
|
|
|
if (sc->sc_rbput - sc->sc_rbget - 1) {
|
|
|
|
|
setsoftscn();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
splx(s);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
static void
|
1996-11-24 16:32:53 +03:00
|
|
|
|
scnintr(arg)
|
|
|
|
|
void *arg;
|
|
|
|
|
{
|
1996-12-23 11:37:07 +03:00
|
|
|
|
int line1 = (int)arg; /* NOTE: line _ONE_ */
|
1996-10-23 11:52:35 +04:00
|
|
|
|
register struct scn_softc *sc0 = SOFTC(line1 - 1);
|
|
|
|
|
register struct scn_softc *sc1 = SOFTC(line1);
|
1993-09-10 03:53:45 +04:00
|
|
|
|
|
1997-03-13 13:24:14 +03:00
|
|
|
|
register struct tty *tp0 = sc0->sc_tty;
|
|
|
|
|
register struct tty *tp1 = sc1->sc_tty;
|
1993-09-10 03:53:45 +04:00
|
|
|
|
|
1997-03-13 13:24:14 +03:00
|
|
|
|
register struct duart *duart = sc0->sc_duart;
|
1993-09-10 03:53:45 +04:00
|
|
|
|
|
1996-12-23 11:37:07 +03:00
|
|
|
|
char rs_work;
|
|
|
|
|
u_char rs_stat;
|
|
|
|
|
u_char rs_ipcr;
|
1993-09-10 03:53:45 +04:00
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
do {
|
|
|
|
|
/* Loop to pick up ALL pending interrupts for device. */
|
|
|
|
|
rs_work = FALSE;
|
|
|
|
|
rs_stat = duart->base[DU_ISR];
|
1993-09-10 03:53:45 +04:00
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
/* channel a */
|
|
|
|
|
if (tp0 != NULL) {
|
|
|
|
|
if ((rs_stat & INT_TXA) && (tp0->t_state & TS_BUSY)) {
|
|
|
|
|
/* output char done. */
|
|
|
|
|
tp0->t_state &= ~(TS_BUSY | TS_FLUSH);
|
1995-04-27 11:18:02 +04:00
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
/* disable tx ints */
|
1997-03-13 13:24:14 +03:00
|
|
|
|
sc0->sc_duart->imr &= ~sc0->sc_tx_int;
|
|
|
|
|
sc0->sc_duart->base[DU_IMR] = sc0->sc_duart->imr;
|
1995-04-27 11:18:02 +04:00
|
|
|
|
|
1997-03-13 13:24:14 +03:00
|
|
|
|
if (sc0->sc_heldchanges) {
|
|
|
|
|
scn_setchip(sc0);
|
|
|
|
|
}
|
1993-09-10 03:53:45 +04:00
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
(*linesw[tp0->t_line].l_start) (tp0);
|
|
|
|
|
rs_work = TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* channel b */
|
|
|
|
|
if (tp1 != NULL) {
|
|
|
|
|
if ((rs_stat & INT_TXB) && (tp1->t_state & TS_BUSY)) {
|
|
|
|
|
/* output char done. */
|
|
|
|
|
tp1->t_state &= ~(TS_BUSY | TS_FLUSH);
|
1993-09-10 03:53:45 +04:00
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
/* disable tx ints */
|
1997-03-13 13:24:14 +03:00
|
|
|
|
sc1->sc_duart->imr &= ~sc1->sc_tx_int;
|
|
|
|
|
sc1->sc_duart->base[DU_IMR] = sc1->sc_duart->imr;
|
1993-09-10 03:53:45 +04:00
|
|
|
|
|
1997-03-13 13:24:14 +03:00
|
|
|
|
if (sc1->sc_heldchanges) {
|
|
|
|
|
scn_setchip(sc1);
|
|
|
|
|
}
|
1995-08-25 11:30:33 +04:00
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
(*linesw[tp1->t_line].l_start) (tp1);
|
|
|
|
|
rs_work = TRUE;
|
|
|
|
|
}
|
1993-09-10 03:53:45 +04:00
|
|
|
|
}
|
1996-10-23 11:52:35 +04:00
|
|
|
|
if (rs_stat & INT_IP) {
|
|
|
|
|
rs_work = TRUE;
|
|
|
|
|
rs_ipcr = duart->base[DU_IPCR];
|
|
|
|
|
|
1996-11-24 16:32:53 +03:00
|
|
|
|
if (rs_ipcr & IPCR_DELTA_DCDA && tp0 != NULL) {
|
1996-10-23 11:52:35 +04:00
|
|
|
|
dcd_int(sc0, tp0, rs_ipcr & IPCR_DCDA);
|
|
|
|
|
}
|
1996-11-24 16:32:53 +03:00
|
|
|
|
if (rs_ipcr & IPCR_DELTA_DCDB && tp1 != NULL) {
|
1996-10-23 11:52:35 +04:00
|
|
|
|
dcd_int(sc1, tp1, rs_ipcr & IPCR_DCDB);
|
1995-08-25 11:30:33 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
1996-10-23 11:52:35 +04:00
|
|
|
|
} while (rs_work);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Handle rxrdy/ffull interrupt: QUICKLY poll both channels (checking
|
|
|
|
|
* status first) and stash data in a ring buffer. Ring buffer scheme
|
|
|
|
|
* borowed from sparc/zs.c requires NO interlock on data!
|
|
|
|
|
*
|
|
|
|
|
* This interrupt should NOT be included in spltty() mask since it
|
|
|
|
|
* invokes NO tty code! The whole point is to allow tty input as much
|
|
|
|
|
* of the time as possible, while deferring "heavy" character
|
|
|
|
|
* processing until later.
|
|
|
|
|
*
|
|
|
|
|
* see scn.hw.README and scnsoft() for more info.
|
|
|
|
|
*
|
|
|
|
|
* THIS ROUTINE SHOULD BE KEPT AS CLEAN AS POSSIBLE!!
|
|
|
|
|
* IT'S A CANDIDATE FOR RECODING IN ASSEMBLER!!
|
|
|
|
|
*/
|
1997-03-13 13:24:14 +03:00
|
|
|
|
static __inline int
|
1996-12-23 11:37:07 +03:00
|
|
|
|
scn_rxintr(sc, line)
|
|
|
|
|
struct scn_softc *sc;
|
|
|
|
|
int line;
|
|
|
|
|
{
|
1996-10-23 11:52:35 +04:00
|
|
|
|
register char sr;
|
1997-03-13 13:24:14 +03:00
|
|
|
|
register int i, n;
|
1996-12-23 11:37:07 +03:00
|
|
|
|
int work;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
|
1996-12-23 11:37:07 +03:00
|
|
|
|
work = 0;
|
|
|
|
|
i = sc->sc_rbput;
|
|
|
|
|
while (work <= 10) {
|
|
|
|
|
#define SCN_GETCH(SC) \
|
1997-03-13 13:24:14 +03:00
|
|
|
|
sr = (SC)->sc_chbase[CH_SR]; \
|
1996-12-23 11:37:07 +03:00
|
|
|
|
if ((sr & SR_RX_RDY) == 0) \
|
|
|
|
|
break; \
|
|
|
|
|
if (sr & (SR_PARITY | SR_FRAME | SR_BREAK | SR_OVERRUN)) \
|
|
|
|
|
goto exception; \
|
|
|
|
|
work++; \
|
1997-03-13 13:24:14 +03:00
|
|
|
|
(SC)->sc_rbuf[i++ & SCN_RING_MASK] = (SC)->sc_chbase[CH_DAT]
|
1996-12-23 11:37:07 +03:00
|
|
|
|
|
|
|
|
|
SCN_GETCH(sc); SCN_GETCH(sc); SCN_GETCH(sc);
|
1997-03-13 13:24:14 +03:00
|
|
|
|
/* XXX more here if 26C92? -plb */
|
1996-12-23 11:37:07 +03:00
|
|
|
|
continue;
|
|
|
|
|
exception:
|
1996-10-23 11:52:35 +04:00
|
|
|
|
#if defined(DDB)
|
1996-12-23 11:37:07 +03:00
|
|
|
|
if (line == scnconsole && (sr & SR_BREAK)) {
|
|
|
|
|
Debugger();
|
1997-03-13 13:24:14 +03:00
|
|
|
|
sr = sc->sc_chbase[CH_SR];
|
1996-12-23 11:37:07 +03:00
|
|
|
|
}
|
1995-08-31 03:51:40 +04:00
|
|
|
|
#endif
|
1996-10-23 11:52:35 +04:00
|
|
|
|
#if defined(KGDB)
|
1996-12-23 11:37:07 +03:00
|
|
|
|
if (line == scnkgdb && (sr & SR_RX_RDY)) {
|
|
|
|
|
kgdb_connect(1);
|
1997-03-13 13:24:14 +03:00
|
|
|
|
sr = sc->sc_chbase[CH_SR];
|
1996-12-23 11:37:07 +03:00
|
|
|
|
}
|
1995-08-31 03:51:40 +04:00
|
|
|
|
#endif
|
1996-10-23 11:52:35 +04:00
|
|
|
|
work++;
|
1997-03-13 13:24:14 +03:00
|
|
|
|
sc->sc_rbuf[i++ & SCN_RING_MASK] = (sr << 8) | sc->sc_chbase[CH_DAT];
|
|
|
|
|
sc->sc_chbase[CH_CR] = CR_CMD_RESET_ERR; /* resets break? */
|
1996-11-24 16:32:53 +03:00
|
|
|
|
RECOVER();
|
1993-09-10 03:53:45 +04:00
|
|
|
|
}
|
1996-12-23 11:37:07 +03:00
|
|
|
|
/*
|
|
|
|
|
* If ring is getting too full, try to block input.
|
|
|
|
|
*/
|
|
|
|
|
n = i - sc->sc_rbget;
|
|
|
|
|
if (sc->sc_rbhiwat && (n > sc->sc_rbhiwat)) {
|
|
|
|
|
/* If not CRTSCTS sc_rbhiwat is such that this
|
1997-04-21 20:16:16 +04:00
|
|
|
|
* never happens.
|
|
|
|
|
* Clear RTS
|
1996-12-23 11:37:07 +03:00
|
|
|
|
*/
|
1997-04-21 20:16:16 +04:00
|
|
|
|
SCN_OP_BIC(sc, sc->sc_op_rts);
|
1996-12-23 11:37:07 +03:00
|
|
|
|
sc->sc_rx_blocked = 1;
|
|
|
|
|
}
|
|
|
|
|
sc->sc_rbput = i;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
|
1996-12-23 11:37:07 +03:00
|
|
|
|
return work;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
scnrxintr(arg)
|
|
|
|
|
void *arg;
|
|
|
|
|
{
|
|
|
|
|
int work = 0;
|
|
|
|
|
int line1 = (int)arg; /* NOTE: line _ONE_ */
|
|
|
|
|
int line0 = line1 - 1;
|
|
|
|
|
register struct scn_softc *sc0 = SOFTC(line0);
|
|
|
|
|
register struct scn_softc *sc1 = SOFTC(line1);
|
|
|
|
|
|
1997-04-21 20:16:16 +04:00
|
|
|
|
work = scn_rxintr(sc0, line0);
|
|
|
|
|
work += scn_rxintr(sc1, (int)line1);
|
1996-10-23 11:52:35 +04:00
|
|
|
|
if (work > 0) {
|
|
|
|
|
setsoftscn(); /* trigger s/w intr */
|
|
|
|
|
#ifdef SCN_TIMING
|
|
|
|
|
microtime(&tstart);
|
|
|
|
|
#endif
|
1993-09-10 03:53:45 +04:00
|
|
|
|
}
|
1996-10-23 11:52:35 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Here on soft interrupt (at spltty) to empty ring buffers.
|
|
|
|
|
*
|
|
|
|
|
* Dave's original scheme was to use the DUART reciever timeout
|
|
|
|
|
* interrupt. This requires 2692's (which my board doesn't have), and
|
|
|
|
|
* I also liked the idea of using the C/T to generate alternate and/or
|
|
|
|
|
* arbitrary bauds. -plb
|
|
|
|
|
*
|
|
|
|
|
* The ringbuffer code comes from Chris Torek's SPARC 44bsd zs driver
|
|
|
|
|
* (hence the LBL notice on top of this file), DOES NOT require
|
|
|
|
|
* interlocking with interrupt levels!
|
|
|
|
|
*
|
|
|
|
|
* The 44bsd sparc/zs driver reads the ring buffer from a seperate
|
|
|
|
|
* zssoftint, while the SunOS 4.x zs driver appears to use
|
|
|
|
|
* timeout()'s. timeouts seem to be too slow to deal with high data
|
|
|
|
|
* rates. I know, I tried them.
|
|
|
|
|
* -plb.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
scnsoft(arg)
|
1996-12-23 11:37:07 +03:00
|
|
|
|
void *arg;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
{
|
1996-12-23 11:37:07 +03:00
|
|
|
|
int unit;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
#ifdef SCN_TIMING
|
|
|
|
|
struct timeval tend;
|
|
|
|
|
u_long t;
|
|
|
|
|
|
|
|
|
|
microtime(&tend);
|
|
|
|
|
t = (tend.tv_sec - tstart.tv_sec) * 1000000 + (tend.tv_usec - tstart.tv_usec);
|
|
|
|
|
t = (t + tick / 20) / (tick / 10);
|
|
|
|
|
if (t >= NJITTER - 1) {
|
|
|
|
|
t = NJITTER - 1;
|
1993-09-10 03:53:45 +04:00
|
|
|
|
}
|
1996-10-23 11:52:35 +04:00
|
|
|
|
scn_jitter[t]++;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
for (unit = 0; unit < scn_cd.cd_ndevs; unit++) {
|
|
|
|
|
register struct scn_softc *sc;
|
|
|
|
|
register struct tty *tp;
|
|
|
|
|
register int n, get;
|
|
|
|
|
|
|
|
|
|
sc = SOFTC(unit);
|
1997-03-13 13:24:14 +03:00
|
|
|
|
if (sc == NULL) {
|
1997-02-08 12:34:31 +03:00
|
|
|
|
continue;
|
1997-03-13 13:24:14 +03:00
|
|
|
|
}
|
|
|
|
|
tp = sc->sc_tty;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
#ifdef KGDB
|
|
|
|
|
if (tp == NULL) {
|
|
|
|
|
sc->sc_rbget = sc->sc_rbput;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
1994-04-17 11:52:15 +04:00
|
|
|
|
#endif
|
1996-12-23 11:37:07 +03:00
|
|
|
|
if (tp == NULL || tp->t_state & TS_TBLOCK) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
get = sc->sc_rbget;
|
|
|
|
|
|
|
|
|
|
/* NOTE: fetch from rbput is atomic */
|
|
|
|
|
while (get != (n = sc->sc_rbput)) {
|
|
|
|
|
/*
|
1997-03-13 13:24:14 +03:00
|
|
|
|
* Compute the number of interrupts in the receive ring.
|
|
|
|
|
* If the count is overlarge, we lost some events, and
|
|
|
|
|
* must advance to the first valid one. It may get
|
|
|
|
|
* overwritten if more data are arriving, but this is
|
|
|
|
|
* too expensive to check and gains nothing (we already
|
|
|
|
|
* lost out; all we can do at this point is trade one
|
|
|
|
|
* kind of loss for another).
|
|
|
|
|
*/
|
1996-10-23 11:52:35 +04:00
|
|
|
|
n -= get;
|
|
|
|
|
if (n > SCN_RING_SIZE) {
|
|
|
|
|
scnoverrun(unit, &sc->sc_rotime, "ring");
|
|
|
|
|
get += n - SCN_RING_SIZE;
|
|
|
|
|
n = SCN_RING_SIZE;
|
1997-03-13 13:24:14 +03:00
|
|
|
|
sc->sc_ring_overruns++;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
}
|
|
|
|
|
while (--n >= 0) {
|
|
|
|
|
register int c, sr;
|
|
|
|
|
|
1996-12-23 11:37:07 +03:00
|
|
|
|
if (tp->t_state & TS_TBLOCK) {
|
|
|
|
|
sc->sc_rbget = get;
|
|
|
|
|
goto done;
|
|
|
|
|
}
|
1996-10-23 11:52:35 +04:00
|
|
|
|
/* Race to keep ahead of incoming interrupts. */
|
|
|
|
|
c = sc->sc_rbuf[get++ & SCN_RING_MASK];
|
|
|
|
|
|
|
|
|
|
sr = c >> 8; /* extract status */
|
|
|
|
|
c &= 0xff; /* leave just character */
|
|
|
|
|
|
|
|
|
|
if (sr & SR_OVERRUN) {
|
|
|
|
|
scnoverrun(unit, &sc->sc_fotime, "fifo");
|
1997-03-13 13:24:14 +03:00
|
|
|
|
sc->sc_fifo_overruns++;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
}
|
1997-03-13 13:24:14 +03:00
|
|
|
|
if (sr & SR_PARITY) {
|
1996-10-23 11:52:35 +04:00
|
|
|
|
c |= TTY_PE;
|
1997-03-13 13:24:14 +03:00
|
|
|
|
sc->sc_parity_errors++;
|
|
|
|
|
}
|
|
|
|
|
if (sr & SR_FRAME) {
|
1996-10-23 11:52:35 +04:00
|
|
|
|
c |= TTY_FE;
|
1997-03-13 13:24:14 +03:00
|
|
|
|
sc->sc_framing_errors++;
|
|
|
|
|
}
|
1996-10-23 11:52:35 +04:00
|
|
|
|
if (sr & SR_BREAK) {
|
1994-04-17 11:52:15 +04:00
|
|
|
|
#if 0
|
1996-10-23 11:52:35 +04:00
|
|
|
|
/*
|
|
|
|
|
* See DDB_CHECK() comments in
|
|
|
|
|
* scnrxintr()
|
|
|
|
|
*/
|
|
|
|
|
if (unit == scnconsole)
|
|
|
|
|
Debugger();
|
1993-09-10 03:53:45 +04:00
|
|
|
|
#endif
|
1996-10-23 11:52:35 +04:00
|
|
|
|
c = TTY_FE | 0;
|
1997-03-13 13:24:14 +03:00
|
|
|
|
sc->sc_breaks++;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
}
|
2000-11-02 03:37:56 +03:00
|
|
|
|
(*tp->t_linesw->l_rint) (c, tp);
|
1996-12-23 11:37:07 +03:00
|
|
|
|
|
|
|
|
|
if (sc->sc_rx_blocked && n < SCN_RING_THRESH) {
|
1997-04-21 20:16:16 +04:00
|
|
|
|
int s = splrtty();
|
1996-12-23 11:37:07 +03:00
|
|
|
|
sc->sc_rx_blocked = 0;
|
1997-04-21 20:16:16 +04:00
|
|
|
|
SCN_OP_BIS(sc, sc->sc_op_rts);
|
1996-12-23 11:37:07 +03:00
|
|
|
|
splx(s);
|
|
|
|
|
}
|
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
}
|
|
|
|
|
sc->sc_rbget = get;
|
|
|
|
|
}
|
1996-12-23 11:37:07 +03:00
|
|
|
|
done:
|
1993-09-10 03:53:45 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
/* Convert TIOCM_xxx bits to output port bits. */
|
|
|
|
|
static unsigned char
|
|
|
|
|
opbits(sc, tioc_bits)
|
|
|
|
|
struct scn_softc *sc;
|
1996-12-23 11:37:07 +03:00
|
|
|
|
int tioc_bits;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
{
|
|
|
|
|
return ((((tioc_bits) & TIOCM_DTR) ? sc->sc_op_dtr : 0) |
|
|
|
|
|
(((tioc_bits) & TIOCM_RTS) ? sc->sc_op_rts : 0));
|
|
|
|
|
}
|
1993-09-10 03:53:45 +04:00
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
int
|
1994-02-21 09:43:27 +03:00
|
|
|
|
scnioctl(dev, cmd, data, flag, p)
|
1996-12-23 11:37:07 +03:00
|
|
|
|
dev_t dev;
|
1997-03-20 15:03:03 +03:00
|
|
|
|
u_long cmd;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
caddr_t data;
|
1996-12-23 11:37:07 +03:00
|
|
|
|
int flag;
|
1994-02-21 09:43:27 +03:00
|
|
|
|
struct proc *p;
|
1993-09-10 03:53:45 +04:00
|
|
|
|
{
|
1996-10-23 11:52:35 +04:00
|
|
|
|
register int unit = DEV_UNIT(dev);
|
|
|
|
|
register struct scn_softc *sc = SOFTC(unit);
|
1997-03-13 13:24:14 +03:00
|
|
|
|
register struct tty *tp = sc->sc_tty;
|
1993-09-10 03:53:45 +04:00
|
|
|
|
register int error;
|
1994-03-08 22:47:51 +03:00
|
|
|
|
|
2000-11-02 03:37:56 +03:00
|
|
|
|
error = (*tp->t_linesw->l_ioctl) (tp, cmd, data, flag, p);
|
1993-09-10 03:53:45 +04:00
|
|
|
|
if (error >= 0)
|
|
|
|
|
return (error);
|
1994-02-21 09:43:27 +03:00
|
|
|
|
error = ttioctl(tp, cmd, data, flag, p);
|
1993-09-10 03:53:45 +04:00
|
|
|
|
if (error >= 0)
|
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
|
case TIOCSBRK:
|
1997-03-13 13:24:14 +03:00
|
|
|
|
sc->sc_chbase[CH_CR] = CR_CMD_START_BRK;
|
1993-09-10 03:53:45 +04:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TIOCCBRK:
|
1997-03-13 13:24:14 +03:00
|
|
|
|
sc->sc_chbase[CH_CR] = CR_CMD_STOP_BRK;
|
1993-09-10 03:53:45 +04:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TIOCSDTR:
|
1996-10-23 11:52:35 +04:00
|
|
|
|
SCN_OP_BIS(sc, sc->sc_op_dtr | sc->sc_op_rts);
|
1993-09-10 03:53:45 +04:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TIOCCDTR:
|
1996-10-23 11:52:35 +04:00
|
|
|
|
SCN_OP_BIC(sc, sc->sc_op_dtr | sc->sc_op_rts);
|
1993-09-10 03:53:45 +04:00
|
|
|
|
break;
|
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
case TIOCMSET: {
|
|
|
|
|
int s;
|
|
|
|
|
unsigned char sbits, cbits;
|
|
|
|
|
|
|
|
|
|
/* set bits */
|
|
|
|
|
sbits = opbits(sc, *(int *) data);
|
|
|
|
|
|
|
|
|
|
/* get bits to clear */
|
|
|
|
|
cbits = ~sbits & (sc->sc_op_dtr | sc->sc_op_rts);
|
|
|
|
|
|
|
|
|
|
s = spltty();
|
|
|
|
|
if (sbits) {
|
|
|
|
|
SCN_OP_BIS(sc, sbits);
|
|
|
|
|
}
|
|
|
|
|
if (cbits) {
|
|
|
|
|
SCN_OP_BIC(sc, cbits);
|
|
|
|
|
}
|
|
|
|
|
splx(s);
|
|
|
|
|
break;
|
|
|
|
|
}
|
1993-09-10 03:53:45 +04:00
|
|
|
|
|
|
|
|
|
case TIOCMBIS:
|
1996-10-23 11:52:35 +04:00
|
|
|
|
SCN_OP_BIS(sc, opbits(sc, *(int *) data));
|
1993-09-10 03:53:45 +04:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TIOCMBIC:
|
1996-10-23 11:52:35 +04:00
|
|
|
|
SCN_OP_BIC(sc, opbits(sc, *(int *) data));
|
1993-09-10 03:53:45 +04:00
|
|
|
|
break;
|
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
case TIOCMGET: {
|
|
|
|
|
int bits;
|
|
|
|
|
unsigned char ip, op;
|
|
|
|
|
|
|
|
|
|
/* s = spltty(); */
|
1997-03-13 13:24:14 +03:00
|
|
|
|
ip = sc->sc_duart->base[DU_IP];
|
1996-10-23 11:52:35 +04:00
|
|
|
|
/*
|
|
|
|
|
* XXX sigh; cannot get op current state!! even if
|
|
|
|
|
* maintained in private, RTS is done in h/w!!
|
|
|
|
|
*/
|
|
|
|
|
op = 0;
|
|
|
|
|
/* splx(s); */
|
|
|
|
|
|
|
|
|
|
bits = 0;
|
|
|
|
|
if (ip & sc->sc_ip_dcd)
|
|
|
|
|
bits |= TIOCM_CD;
|
|
|
|
|
if (ip & sc->sc_ip_cts)
|
|
|
|
|
bits |= TIOCM_CTS;
|
1993-09-10 03:53:45 +04:00
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
#if 0
|
|
|
|
|
if (op & sc->sc_op_dtr)
|
|
|
|
|
bits |= TIOCM_DTR;
|
|
|
|
|
if (op & sc->sc_op_rts)
|
|
|
|
|
bits |= TIOCM_RTS;
|
|
|
|
|
#endif
|
1994-04-17 11:52:15 +04:00
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
*(int *) data = bits;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case TIOCGFLAGS:{
|
|
|
|
|
int bits = 0;
|
|
|
|
|
|
1997-03-13 13:24:14 +03:00
|
|
|
|
if (sc->sc_swflags & SCN_SW_SOFTCAR)
|
1996-10-23 11:52:35 +04:00
|
|
|
|
bits |= TIOCFLAG_SOFTCAR;
|
1997-03-13 13:24:14 +03:00
|
|
|
|
if (sc->sc_swflags & SCN_SW_CLOCAL)
|
1996-10-23 11:52:35 +04:00
|
|
|
|
bits |= TIOCFLAG_CLOCAL;
|
1997-03-13 13:24:14 +03:00
|
|
|
|
if (sc->sc_swflags & SCN_SW_CRTSCTS)
|
1996-10-23 11:52:35 +04:00
|
|
|
|
bits |= TIOCFLAG_CRTSCTS;
|
1997-03-13 13:24:14 +03:00
|
|
|
|
if (sc->sc_swflags & SCN_SW_MDMBUF)
|
1996-10-23 11:52:35 +04:00
|
|
|
|
bits |= TIOCFLAG_MDMBUF;
|
|
|
|
|
|
|
|
|
|
*(int *) data = bits;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case TIOCSFLAGS:{
|
|
|
|
|
int userbits, driverbits = 0;
|
|
|
|
|
|
|
|
|
|
error = suser(p->p_ucred, &p->p_acflag);
|
|
|
|
|
if (error != 0)
|
|
|
|
|
return (EPERM);
|
|
|
|
|
|
|
|
|
|
userbits = *(int *) data;
|
|
|
|
|
if (userbits & TIOCFLAG_SOFTCAR)
|
|
|
|
|
driverbits |= SCN_SW_SOFTCAR;
|
|
|
|
|
if (userbits & TIOCFLAG_CLOCAL)
|
|
|
|
|
driverbits |= SCN_SW_CLOCAL;
|
|
|
|
|
if (userbits & TIOCFLAG_CRTSCTS)
|
|
|
|
|
driverbits |= SCN_SW_CRTSCTS;
|
|
|
|
|
if (userbits & TIOCFLAG_MDMBUF)
|
|
|
|
|
driverbits |= SCN_SW_MDMBUF;
|
|
|
|
|
|
1997-03-13 13:24:14 +03:00
|
|
|
|
sc->sc_swflags = driverbits;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
1994-04-17 11:52:15 +04:00
|
|
|
|
|
1993-09-10 03:53:45 +04:00
|
|
|
|
default:
|
|
|
|
|
return (ENOTTY);
|
|
|
|
|
}
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
int
|
1993-09-10 03:53:45 +04:00
|
|
|
|
scnparam(tp, t)
|
1996-10-23 11:52:35 +04:00
|
|
|
|
struct tty *tp;
|
|
|
|
|
struct termios *t;
|
1993-09-10 03:53:45 +04:00
|
|
|
|
{
|
1996-12-23 11:37:07 +03:00
|
|
|
|
int cflag = t->c_cflag;
|
|
|
|
|
int unit = DEV_UNIT(tp->t_dev);
|
|
|
|
|
char mr1, mr2;
|
|
|
|
|
int error;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
struct scn_softc *sc = SOFTC(unit);
|
|
|
|
|
|
|
|
|
|
/* Is this a hang up? */
|
|
|
|
|
if (t->c_ospeed == B0) {
|
|
|
|
|
SCN_OP_BIC(sc, sc->sc_op_dtr);
|
|
|
|
|
/* leave DTR down. see comment in scnclose() -plb */
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
mr1 = mr2 = 0;
|
|
|
|
|
|
|
|
|
|
/* Parity? */
|
|
|
|
|
if (cflag & PARENB) {
|
|
|
|
|
if ((cflag & PARODD) == 0)
|
|
|
|
|
mr1 |= MR1_PEVEN;
|
|
|
|
|
else
|
|
|
|
|
mr1 |= MR1_PODD;
|
|
|
|
|
} else
|
|
|
|
|
mr1 |= MR1_PNONE;
|
|
|
|
|
|
|
|
|
|
/* Stop bits. */
|
|
|
|
|
if (cflag & CSTOPB)
|
|
|
|
|
mr2 |= MR2_STOP2;
|
1993-09-10 03:53:45 +04:00
|
|
|
|
else
|
1996-10-23 11:52:35 +04:00
|
|
|
|
mr2 |= MR2_STOP1;
|
|
|
|
|
|
|
|
|
|
/* Data bits. */
|
|
|
|
|
switch (cflag & CSIZE) {
|
|
|
|
|
case CS5:
|
1997-03-13 13:24:14 +03:00
|
|
|
|
mr1 |= MR1_CS5;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
break;
|
|
|
|
|
case CS6:
|
1997-03-13 13:24:14 +03:00
|
|
|
|
mr1 |= MR1_CS6;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
break;
|
|
|
|
|
case CS7:
|
1997-03-13 13:24:14 +03:00
|
|
|
|
mr1 |= MR1_CS7;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
break;
|
|
|
|
|
case CS8:
|
|
|
|
|
default:
|
1997-03-13 13:24:14 +03:00
|
|
|
|
mr1 |= MR1_CS8;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cflag & CCTS_OFLOW)
|
|
|
|
|
mr2 |= MR2_TXCTS;
|
|
|
|
|
|
1996-12-23 11:37:07 +03:00
|
|
|
|
if (cflag & CRTS_IFLOW) {
|
1997-04-21 20:16:16 +04:00
|
|
|
|
mr1 |= MR1_RXRTS;
|
1996-12-23 11:37:07 +03:00
|
|
|
|
sc->sc_rbhiwat = SCN_RING_HIWAT;
|
|
|
|
|
} else {
|
|
|
|
|
sc->sc_rbhiwat = 0;
|
|
|
|
|
}
|
1996-10-23 11:52:35 +04:00
|
|
|
|
|
|
|
|
|
error = scn_config(unit, t->c_ispeed, t->c_ospeed, mr1, mr2);
|
|
|
|
|
|
|
|
|
|
/* If successful, copy to tty */
|
|
|
|
|
if (!error) {
|
|
|
|
|
tp->t_ispeed = t->c_ispeed;
|
|
|
|
|
tp->t_ospeed = t->c_ospeed;
|
|
|
|
|
tp->t_cflag = cflag;
|
|
|
|
|
}
|
|
|
|
|
return (error);
|
1993-09-10 03:53:45 +04:00
|
|
|
|
}
|
1994-02-21 09:43:27 +03:00
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
void
|
1993-09-10 03:53:45 +04:00
|
|
|
|
scnstart(tp)
|
1996-10-23 11:52:35 +04:00
|
|
|
|
struct tty *tp;
|
1993-09-10 03:53:45 +04:00
|
|
|
|
{
|
1996-12-23 11:37:07 +03:00
|
|
|
|
int s, c;
|
|
|
|
|
int unit = DEV_UNIT(tp->t_dev);
|
1996-10-23 11:52:35 +04:00
|
|
|
|
struct scn_softc *sc = SOFTC(unit);
|
|
|
|
|
|
1993-09-10 03:53:45 +04:00
|
|
|
|
s = spltty();
|
1996-10-23 11:52:35 +04:00
|
|
|
|
if (tp->t_state & (TS_BUSY | TS_TTSTOP))
|
1993-09-10 03:53:45 +04:00
|
|
|
|
goto out;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
if (tp->t_outq.c_cc <= tp->t_lowat) {
|
|
|
|
|
if (tp->t_state & TS_ASLEEP) {
|
|
|
|
|
tp->t_state &= ~TS_ASLEEP;
|
|
|
|
|
wakeup((caddr_t) & tp->t_outq);
|
|
|
|
|
}
|
|
|
|
|
if (tp->t_outq.c_cc == 0) /* plb 11/8/95 - from
|
|
|
|
|
* isa/com.c */
|
|
|
|
|
goto out;
|
|
|
|
|
selwakeup(&tp->t_wsel);
|
|
|
|
|
}
|
1994-03-22 03:15:21 +03:00
|
|
|
|
tp->t_state |= TS_BUSY;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
|
1997-04-21 20:16:16 +04:00
|
|
|
|
while (sc->sc_chbase[CH_SR] & SR_TX_RDY) {
|
|
|
|
|
if ((c = getc(&tp->t_outq)) == -1)
|
|
|
|
|
break;
|
|
|
|
|
sc->sc_chbase[CH_DAT] = c;
|
1993-09-10 03:53:45 +04:00
|
|
|
|
}
|
1997-04-21 20:16:16 +04:00
|
|
|
|
sc->sc_duart->base[DU_IMR] = (sc->sc_duart->imr |= sc->sc_tx_int);
|
|
|
|
|
|
1993-09-10 03:53:45 +04:00
|
|
|
|
out:
|
|
|
|
|
splx(s);
|
|
|
|
|
}
|
1996-10-23 11:52:35 +04:00
|
|
|
|
|
1993-09-10 03:53:45 +04:00
|
|
|
|
/*
|
|
|
|
|
* Stop output on a line.
|
|
|
|
|
*/
|
|
|
|
|
/*ARGSUSED*/
|
1996-09-02 10:43:16 +04:00
|
|
|
|
void
|
1993-09-10 03:53:45 +04:00
|
|
|
|
scnstop(tp, flag)
|
1996-10-23 11:52:35 +04:00
|
|
|
|
struct tty *tp;
|
1996-12-23 11:37:07 +03:00
|
|
|
|
int flag;
|
1993-09-10 03:53:45 +04:00
|
|
|
|
{
|
1996-12-23 11:37:07 +03:00
|
|
|
|
int s = spltty();
|
1993-09-10 03:53:45 +04:00
|
|
|
|
|
|
|
|
|
if (tp->t_state & TS_BUSY) {
|
1996-10-23 11:52:35 +04:00
|
|
|
|
if ((tp->t_state & TS_TTSTOP) == 0)
|
1993-09-10 03:53:45 +04:00
|
|
|
|
tp->t_state |= TS_FLUSH;
|
|
|
|
|
}
|
|
|
|
|
splx(s);
|
|
|
|
|
}
|
1996-10-23 11:52:35 +04:00
|
|
|
|
|
1993-09-10 03:53:45 +04:00
|
|
|
|
/*
|
1996-10-23 11:52:35 +04:00
|
|
|
|
* Following are all routines needed for SCN to act as console.
|
1993-09-10 03:53:45 +04:00
|
|
|
|
*/
|
1996-10-23 11:52:35 +04:00
|
|
|
|
#ifdef VERYLOWDEBUG
|
|
|
|
|
/* So the kernel can write in unmapped mode! */
|
|
|
|
|
extern int _mapped;
|
|
|
|
|
#define SCN_BASE (_mapped ? SCN_FIRST_MAP_ADR : SCN_FIRST_ADR)
|
|
|
|
|
#else
|
|
|
|
|
#define SCN_BASE (SCN_FIRST_MAP_ADR)
|
|
|
|
|
#endif
|
1993-09-10 03:53:45 +04:00
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
#define DUADDR(dev) (u_char *)(SCN_BASE + (DEV_UNIT(dev) >> 1) * DUART_SZ)
|
|
|
|
|
#define CHADDR(dev) (u_char *)(SCN_BASE + DEV_UNIT(dev) * CH_SZ)
|
|
|
|
|
|
2000-07-14 12:18:49 +04:00
|
|
|
|
void
|
1993-09-10 03:53:45 +04:00
|
|
|
|
scncnprobe(cp)
|
|
|
|
|
struct consdev *cp;
|
|
|
|
|
{
|
1996-10-23 11:52:35 +04:00
|
|
|
|
/* Locate the major number. */
|
1993-09-10 03:53:45 +04:00
|
|
|
|
for (scnmajor = 0; scnmajor < nchrdev; scnmajor++)
|
|
|
|
|
if (cdevsw[scnmajor].d_open == scnopen)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
/* initialize required fields */
|
1994-03-08 22:47:51 +03:00
|
|
|
|
cp->cn_dev = makedev(scnmajor, SCN_CONSOLE);
|
1993-09-10 03:53:45 +04:00
|
|
|
|
cp->cn_pri = CN_NORMAL;
|
|
|
|
|
}
|
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
void
|
|
|
|
|
scncnreinit(v)
|
1996-12-23 11:37:07 +03:00
|
|
|
|
void *v;
|
1993-09-10 03:53:45 +04:00
|
|
|
|
{
|
1996-12-23 11:37:07 +03:00
|
|
|
|
dev_t dev = (dev_t)v;
|
|
|
|
|
int unit = DEV_UNIT(dev);
|
1996-10-23 11:52:35 +04:00
|
|
|
|
volatile u_char *du_base = DUADDR(dev);
|
1993-09-10 03:53:45 +04:00
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
du_base[DU_OPSET] = (unit & 1) ? (OP_RTSB | OP_DTRB) : (OP_RTSA | OP_DTRA);
|
1993-09-10 03:53:45 +04:00
|
|
|
|
}
|
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
void
|
|
|
|
|
scncninit(cp)
|
|
|
|
|
struct consdev *cp;
|
1993-09-10 03:53:45 +04:00
|
|
|
|
{
|
1996-10-23 11:52:35 +04:00
|
|
|
|
scninit(cp->cn_dev, scnconsrate);
|
|
|
|
|
scnconsole = DEV_UNIT(cp->cn_dev);
|
1993-09-10 03:53:45 +04:00
|
|
|
|
}
|
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
/* Used by scncninit and kgdb startup. */
|
1993-09-10 03:53:45 +04:00
|
|
|
|
int
|
1996-10-23 11:52:35 +04:00
|
|
|
|
scninit(dev, rate)
|
1996-12-23 11:37:07 +03:00
|
|
|
|
dev_t dev;
|
|
|
|
|
int rate;
|
1993-09-10 03:53:45 +04:00
|
|
|
|
{
|
1996-10-23 11:52:35 +04:00
|
|
|
|
volatile u_char *du_base = DUADDR(dev);
|
1996-12-23 11:37:07 +03:00
|
|
|
|
int unit = DEV_UNIT(dev);
|
1994-03-08 22:47:51 +03:00
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
du_base[DU_OPSET] = (unit & 1) ? (OP_RTSB | OP_DTRB) : (OP_RTSA | OP_DTRA);
|
1997-03-13 13:24:14 +03:00
|
|
|
|
scn_config(unit, rate, rate, MR1_PNONE | MR1_CS8, MR2_STOP1);
|
1996-10-23 11:52:35 +04:00
|
|
|
|
return (0);
|
|
|
|
|
}
|
1994-03-08 22:47:51 +03:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Console kernel input character routine.
|
|
|
|
|
*/
|
1996-10-23 11:52:35 +04:00
|
|
|
|
int
|
|
|
|
|
scncngetc(dev)
|
1996-12-23 11:37:07 +03:00
|
|
|
|
dev_t dev;
|
1994-03-08 22:47:51 +03:00
|
|
|
|
{
|
1996-10-23 11:52:35 +04:00
|
|
|
|
volatile u_char *ch_base = CHADDR(dev);
|
1996-12-23 11:37:07 +03:00
|
|
|
|
char c;
|
|
|
|
|
int s = spltty();
|
1996-10-23 11:52:35 +04:00
|
|
|
|
|
1996-12-23 11:37:07 +03:00
|
|
|
|
while ((ch_base[CH_SR] & SR_RX_RDY) == 0);
|
1996-10-23 11:52:35 +04:00
|
|
|
|
c = ch_base[CH_DAT];
|
1994-03-08 22:47:51 +03:00
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
splx(s);
|
|
|
|
|
return c;
|
1995-04-21 22:36:32 +04:00
|
|
|
|
}
|
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
/* The pc532 does not turn off console polling. */
|
|
|
|
|
void
|
|
|
|
|
scncnpollc(dev, on)
|
1996-12-23 11:37:07 +03:00
|
|
|
|
dev_t dev;
|
|
|
|
|
int on;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
{
|
|
|
|
|
}
|
1995-04-21 22:36:32 +04:00
|
|
|
|
|
1994-03-08 22:47:51 +03:00
|
|
|
|
/*
|
|
|
|
|
* Console kernel output character routine.
|
|
|
|
|
*/
|
1996-10-23 11:52:35 +04:00
|
|
|
|
void
|
|
|
|
|
scncnputc(dev, c)
|
1996-12-23 11:37:07 +03:00
|
|
|
|
dev_t dev;
|
2000-07-14 12:18:49 +04:00
|
|
|
|
int c;
|
1996-10-23 11:52:35 +04:00
|
|
|
|
{
|
|
|
|
|
volatile u_char *ch_base = CHADDR(dev);
|
|
|
|
|
volatile u_char *du_base = DUADDR(dev);
|
1996-12-23 11:37:07 +03:00
|
|
|
|
int s = spltty();
|
1994-03-08 22:47:51 +03:00
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
if (c == '\n')
|
|
|
|
|
scncnputc(dev, '\r');
|
1994-03-08 22:47:51 +03:00
|
|
|
|
|
1996-12-23 11:37:07 +03:00
|
|
|
|
while ((ch_base[CH_SR] & SR_TX_RDY) == 0);
|
1996-10-23 11:52:35 +04:00
|
|
|
|
ch_base[CH_DAT] = c;
|
1996-12-23 11:37:07 +03:00
|
|
|
|
while ((ch_base[CH_SR] & SR_TX_RDY) == 0);
|
1996-10-23 11:52:35 +04:00
|
|
|
|
du_base[DU_ISR];
|
1994-03-08 22:47:51 +03:00
|
|
|
|
|
1996-10-23 11:52:35 +04:00
|
|
|
|
splx(s);
|
1994-03-08 22:47:51 +03:00
|
|
|
|
}
|