2002-10-23 13:10:23 +04:00
|
|
|
/* $NetBSD: mfc.c,v 1.32 2002/10/23 09:10:34 jdolecek Exp $ */
|
1995-03-02 05:23:50 +03:00
|
|
|
|
1994-12-28 12:24:55 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1994 Michael L. Hitch
|
|
|
|
* Copyright (c) 1982, 1990 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.
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2001-05-30 19:24:23 +04:00
|
|
|
#include "opt_kgdb.h"
|
|
|
|
|
2002-01-28 12:56:43 +03:00
|
|
|
#include <sys/cdefs.h>
|
2002-10-23 13:10:23 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: mfc.c,v 1.32 2002/10/23 09:10:34 jdolecek Exp $");
|
2002-01-28 12:56:43 +03:00
|
|
|
|
1994-12-28 12:24:55 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/tty.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/queue.h>
|
2002-09-06 17:18:43 +04:00
|
|
|
#include <sys/conf.h>
|
1994-12-28 12:24:55 +03:00
|
|
|
#include <machine/cpu.h>
|
|
|
|
#include <amiga/amiga/device.h>
|
1995-02-12 22:18:33 +03:00
|
|
|
#include <amiga/amiga/isr.h>
|
1994-12-28 12:24:55 +03:00
|
|
|
#include <amiga/amiga/custom.h>
|
|
|
|
#include <amiga/amiga/cia.h>
|
|
|
|
#include <amiga/amiga/cc.h>
|
1995-02-12 22:18:33 +03:00
|
|
|
#include <amiga/dev/zbusvar.h>
|
1994-12-28 12:24:55 +03:00
|
|
|
|
|
|
|
#include <dev/cons.h>
|
|
|
|
|
|
|
|
#include "mfcs.h"
|
|
|
|
|
1995-09-29 16:51:30 +03:00
|
|
|
#ifndef SEROBUF_SIZE
|
1994-12-28 12:24:55 +03:00
|
|
|
#define SEROBUF_SIZE 128
|
1995-09-29 16:51:30 +03:00
|
|
|
#endif
|
|
|
|
#ifndef SERIBUF_SIZE
|
1994-12-28 12:24:55 +03:00
|
|
|
#define SERIBUF_SIZE 1024
|
1995-09-29 16:51:30 +03:00
|
|
|
#endif
|
1994-12-28 12:24:55 +03:00
|
|
|
|
1995-02-12 22:18:33 +03:00
|
|
|
#define splser() spl6()
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 68581 DUART registers
|
|
|
|
*/
|
1994-12-28 12:24:55 +03:00
|
|
|
struct mfc_regs {
|
|
|
|
volatile u_char du_mr1a;
|
|
|
|
#define du_mr2a du_mr1a
|
|
|
|
u_char pad0;
|
|
|
|
volatile u_char du_csra;
|
|
|
|
#define du_sra du_csra
|
|
|
|
u_char pad2;
|
|
|
|
volatile u_char du_cra;
|
|
|
|
u_char pad4;
|
|
|
|
volatile u_char du_tba;
|
|
|
|
#define du_rba du_tba
|
|
|
|
u_char pad6;
|
|
|
|
volatile u_char du_acr;
|
|
|
|
#define du_ipcr du_acr
|
|
|
|
u_char pad8;
|
|
|
|
volatile u_char du_imr;
|
|
|
|
#define du_isr du_imr
|
|
|
|
u_char pad10;
|
|
|
|
volatile u_char du_ctur;
|
|
|
|
#define du_cmsb du_ctur
|
|
|
|
u_char pad12;
|
|
|
|
volatile u_char du_ctlr;
|
|
|
|
#define du_clsb du_ctlr
|
|
|
|
u_char pad14;
|
|
|
|
volatile u_char du_mr1b;
|
|
|
|
#define du_mr2b du_mr1b
|
|
|
|
u_char pad16;
|
|
|
|
volatile u_char du_csrb;
|
|
|
|
#define du_srb du_csrb
|
|
|
|
u_char pad18;
|
|
|
|
volatile u_char du_crb;
|
|
|
|
u_char pad20;
|
|
|
|
volatile u_char du_tbb;
|
|
|
|
#define du_rbb du_tbb
|
|
|
|
u_char pad22;
|
|
|
|
volatile u_char du_ivr;
|
|
|
|
u_char pad24;
|
|
|
|
volatile u_char du_opcr;
|
|
|
|
#define du_ip du_opcr
|
|
|
|
u_char pad26;
|
|
|
|
volatile u_char du_btst;
|
|
|
|
#define du_strc du_btst
|
|
|
|
u_char pad28;
|
|
|
|
volatile u_char du_btrst;
|
|
|
|
#define du_stpc du_btrst
|
|
|
|
u_char pad30;
|
|
|
|
};
|
|
|
|
|
1995-02-12 22:18:33 +03:00
|
|
|
/*
|
|
|
|
* 68681 DUART serial port registers
|
|
|
|
*/
|
1994-12-28 12:24:55 +03:00
|
|
|
struct duart_regs {
|
|
|
|
volatile u_char ch_mr1;
|
|
|
|
#define ch_mr2 ch_mr1
|
|
|
|
u_char pad0;
|
|
|
|
volatile u_char ch_csr;
|
|
|
|
#define ch_sr ch_csr
|
|
|
|
u_char pad1;
|
|
|
|
volatile u_char ch_cr;
|
|
|
|
u_char pad2;
|
|
|
|
volatile u_char ch_tb;
|
|
|
|
#define ch_rb ch_tb
|
|
|
|
u_char pad3;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct mfc_softc {
|
|
|
|
struct device sc_dev;
|
1995-02-12 22:18:33 +03:00
|
|
|
struct isr sc_isr;
|
1994-12-28 12:24:55 +03:00
|
|
|
struct mfc_regs *sc_regs;
|
|
|
|
u_long clk_frq;
|
|
|
|
u_short ct_val;
|
|
|
|
u_char ct_usecnt;
|
|
|
|
u_char imask;
|
|
|
|
u_char mfc_iii;
|
|
|
|
u_char last_ip;
|
|
|
|
};
|
|
|
|
|
1995-02-12 22:18:33 +03:00
|
|
|
#if NMFCS > 0
|
1994-12-28 12:24:55 +03:00
|
|
|
struct mfcs_softc {
|
|
|
|
struct device sc_dev;
|
1995-07-04 22:06:40 +04:00
|
|
|
struct tty *sc_tty;
|
1994-12-28 12:24:55 +03:00
|
|
|
struct duart_regs *sc_duart;
|
|
|
|
struct mfc_regs *sc_regs;
|
|
|
|
struct mfc_softc *sc_mfc;
|
1995-11-30 03:56:23 +03:00
|
|
|
int swflags;
|
1994-12-28 12:24:55 +03:00
|
|
|
long flags; /* XXX */
|
|
|
|
#define CT_USED 1 /* CT in use */
|
|
|
|
u_short *rptr, *wptr, incnt, ovfl;
|
|
|
|
u_short inbuf[SERIBUF_SIZE];
|
|
|
|
char *ptr, *end;
|
|
|
|
char outbuf[SEROBUF_SIZE];
|
1995-11-30 03:56:23 +03:00
|
|
|
struct vbl_node vbl_node;
|
1994-12-28 12:24:55 +03:00
|
|
|
};
|
1995-02-12 22:18:33 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if NMFCP > 0
|
|
|
|
struct mfcp_softc {
|
|
|
|
};
|
|
|
|
#endif
|
1994-12-28 12:24:55 +03:00
|
|
|
|
|
|
|
struct mfc_args {
|
|
|
|
struct zbus_args zargs;
|
|
|
|
char *subdev;
|
|
|
|
char unit;
|
|
|
|
};
|
|
|
|
|
2002-01-26 16:40:52 +03:00
|
|
|
int mfcprint(void *auxp, const char *);
|
|
|
|
void mfcattach(struct device *, struct device *, void *);
|
|
|
|
int mfcmatch(struct device *, struct cfdata *, void *);
|
1996-04-22 01:10:48 +04:00
|
|
|
|
1995-02-12 22:18:33 +03:00
|
|
|
#if NMFCS > 0
|
2002-01-26 16:40:52 +03:00
|
|
|
int mfcsmatch(struct device *, struct cfdata *, void *);
|
|
|
|
void mfcsattach(struct device *, struct device *, void *);
|
|
|
|
int mfcsparam( struct tty *, struct termios *);
|
|
|
|
int mfcshwiflow(struct tty *, int);
|
|
|
|
void mfcsstart(struct tty *);
|
|
|
|
int mfcsmctl(dev_t, int, int);
|
|
|
|
void mfcsxintr(int);
|
|
|
|
void mfcseint(int, int);
|
|
|
|
void mfcsmint(register int);
|
1995-02-12 22:18:33 +03:00
|
|
|
#endif
|
1996-04-22 01:10:48 +04:00
|
|
|
|
1995-02-12 22:18:33 +03:00
|
|
|
#if NMFCP > 0
|
2002-01-26 16:40:52 +03:00
|
|
|
void mfcpattach(struct device *, struct device *, void *);
|
|
|
|
int mfcpmatch(struct device *, struct cfdata *, void *);
|
1995-02-12 22:18:33 +03:00
|
|
|
#endif
|
2002-01-26 16:40:52 +03:00
|
|
|
int mfcintr(void *);
|
1994-12-28 12:24:55 +03:00
|
|
|
|
2002-10-02 08:55:47 +04:00
|
|
|
CFATTACH_DECL(mfc, sizeof(struct mfc_softc),
|
|
|
|
mfcmatch, mfcattach, NULL, NULL);
|
1996-03-17 04:16:48 +03:00
|
|
|
|
1995-02-12 22:18:33 +03:00
|
|
|
#if NMFCS > 0
|
2002-10-02 08:55:47 +04:00
|
|
|
CFATTACH_DECL(mfcs, sizeof(struct mfcs_softc),
|
|
|
|
mfcsmatch, mfcsattach, NULL, NULL);
|
1996-03-17 04:16:48 +03:00
|
|
|
|
1998-01-12 13:39:01 +03:00
|
|
|
extern struct cfdriver mfcs_cd;
|
1995-02-12 22:18:33 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if NMFCP > 0
|
2002-10-02 08:55:47 +04:00
|
|
|
CFATTACH_DECL(mfcp, sizeof(struct mfcp_softc),
|
|
|
|
mfcpmatch, mfcpattach, NULL, NULL);
|
1995-02-12 22:18:33 +03:00
|
|
|
#endif
|
1994-12-28 12:24:55 +03:00
|
|
|
|
2002-09-06 17:18:43 +04:00
|
|
|
dev_type_open(mfcsopen);
|
|
|
|
dev_type_close(mfcsclose);
|
|
|
|
dev_type_read(mfcsread);
|
|
|
|
dev_type_write(mfcswrite);
|
|
|
|
dev_type_ioctl(mfcsioctl);
|
|
|
|
dev_type_stop(mfcsstop);
|
|
|
|
dev_type_tty(mfcstty);
|
|
|
|
dev_type_poll(mfcspoll);
|
|
|
|
|
|
|
|
const struct cdevsw mfcs_cdevsw = {
|
|
|
|
mfcsopen, mfcsclose, mfcsread, mfcswrite, mfcsioctl,
|
2002-10-23 13:10:23 +04:00
|
|
|
mfcsstop, mfcstty, mfcspoll, nommap, ttykqfilter, D_TTY
|
2002-09-06 17:18:43 +04:00
|
|
|
};
|
1996-04-22 01:10:48 +04:00
|
|
|
|
1994-12-28 12:24:55 +03:00
|
|
|
int mfcs_active;
|
|
|
|
int mfcsdefaultrate = 38400 /*TTYDEF_SPEED*/;
|
1995-11-30 03:56:23 +03:00
|
|
|
#define SWFLAGS(dev) (sc->swflags | (((dev) & 0x80) == 0 ? TIOCFLAG_SOFTCAR : 0))
|
1994-12-28 12:24:55 +03:00
|
|
|
|
1995-04-03 00:38:09 +04:00
|
|
|
#ifdef notyet
|
|
|
|
/*
|
|
|
|
* MultiFaceCard III, II+ (not supported yet), and
|
|
|
|
* SerialMaster 500+ (not supported yet)
|
|
|
|
* baud rate tables for BRG set 1 [not used yet]
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct speedtab mfcs3speedtab1[] = {
|
1996-04-22 01:10:48 +04:00
|
|
|
{ 0, 0 },
|
|
|
|
{ 100, 0x00 },
|
|
|
|
{ 220, 0x11 },
|
|
|
|
{ 600, 0x44 },
|
|
|
|
{ 1200, 0x55 },
|
|
|
|
{ 2400, 0x66 },
|
|
|
|
{ 4800, 0x88 },
|
|
|
|
{ 9600, 0x99 },
|
|
|
|
{ 19200, 0xbb },
|
|
|
|
{ 115200, 0xcc },
|
|
|
|
{ -1, -1 }
|
1995-04-03 00:38:09 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* MultiFaceCard II, I, and SerialMaster 500
|
|
|
|
* baud rate tables for BRG set 1 [not used yet]
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct speedtab mfcs2speedtab1[] = {
|
1996-04-22 01:10:48 +04:00
|
|
|
{ 0, 0 },
|
|
|
|
{ 50, 0x00 },
|
|
|
|
{ 110, 0x11 },
|
|
|
|
{ 300, 0x44 },
|
|
|
|
{ 600, 0x55 },
|
|
|
|
{ 1200, 0x66 },
|
|
|
|
{ 2400, 0x88 },
|
|
|
|
{ 4800, 0x99 },
|
|
|
|
{ 9600, 0xbb },
|
|
|
|
{ 38400, 0xcc },
|
|
|
|
{ -1, -1 }
|
1995-04-03 00:38:09 +04:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* MultiFaceCard III, II+ (not supported yet), and
|
|
|
|
* SerialMaster 500+ (not supported yet)
|
|
|
|
* baud rate tables for BRG set 2
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct speedtab mfcs3speedtab2[] = {
|
1996-04-22 01:10:48 +04:00
|
|
|
{ 0, 0 },
|
|
|
|
{ 150, 0x00 },
|
|
|
|
{ 200, 0x11 },
|
|
|
|
{ 300, 0x33 },
|
|
|
|
{ 600, 0x44 },
|
|
|
|
{ 1200, 0x55 },
|
|
|
|
{ 2400, 0x66 },
|
|
|
|
{ 4800, 0x88 },
|
|
|
|
{ 9600, 0x99 },
|
|
|
|
{ 19200, 0xbb },
|
|
|
|
{ 38400, 0xcc },
|
|
|
|
{ -1, -1 }
|
1994-12-28 12:24:55 +03:00
|
|
|
};
|
|
|
|
|
1995-04-03 00:38:09 +04:00
|
|
|
/*
|
|
|
|
* MultiFaceCard II, I, and SerialMaster 500
|
|
|
|
* baud rate tables for BRG set 2
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct speedtab mfcs2speedtab2[] = {
|
1996-04-22 01:10:48 +04:00
|
|
|
{ 0, 0 },
|
|
|
|
{ 75, 0x00 },
|
|
|
|
{ 100, 0x11 },
|
|
|
|
{ 150, 0x33 },
|
|
|
|
{ 300, 0x44 },
|
|
|
|
{ 600, 0x55 },
|
|
|
|
{ 1200, 0x66 },
|
|
|
|
{ 2400, 0x88 },
|
|
|
|
{ 4800, 0x99 },
|
|
|
|
{ 9600, 0xbb },
|
|
|
|
{ 19200, 0xcc },
|
|
|
|
{ -1, -1 }
|
1994-12-28 12:24:55 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if we are an bsc/Alf Data MultFaceCard (I, II, and III)
|
|
|
|
*/
|
|
|
|
int
|
2002-01-26 16:40:52 +03:00
|
|
|
mfcmatch(struct device *pdp, struct cfdata *cfp, void *auxp)
|
1994-12-28 12:24:55 +03:00
|
|
|
{
|
|
|
|
struct zbus_args *zap;
|
|
|
|
|
|
|
|
zap = auxp;
|
|
|
|
if (zap->manid == 2092 &&
|
|
|
|
(zap->prodid == 16 || zap->prodid == 17 || zap->prodid == 18))
|
1995-02-12 22:18:33 +03:00
|
|
|
|
1994-12-28 12:24:55 +03:00
|
|
|
return(1);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-01-26 16:40:52 +03:00
|
|
|
mfcattach(struct device *pdp, struct device *dp, void *auxp)
|
1994-12-28 12:24:55 +03:00
|
|
|
{
|
|
|
|
struct mfc_softc *scc;
|
|
|
|
struct zbus_args *zap;
|
|
|
|
struct mfc_args ma;
|
|
|
|
int unit;
|
|
|
|
struct mfc_regs *rp;
|
|
|
|
|
|
|
|
zap = auxp;
|
1995-02-12 22:18:33 +03:00
|
|
|
|
1996-10-13 07:05:43 +04:00
|
|
|
printf ("\n");
|
1994-12-28 12:24:55 +03:00
|
|
|
|
|
|
|
scc = (struct mfc_softc *)dp;
|
|
|
|
unit = scc->sc_dev.dv_unit;
|
|
|
|
scc->sc_regs = rp = zap->va;
|
|
|
|
if (zap->prodid == 18)
|
|
|
|
scc->mfc_iii = 3;
|
|
|
|
scc->clk_frq = scc->mfc_iii ? 230400 : 115200;
|
|
|
|
|
|
|
|
rp->du_opcr = 0x00; /* configure output port? */
|
|
|
|
rp->du_btrst = 0x0f; /* clear modem lines */
|
|
|
|
rp->du_ivr = 0; /* IVR */
|
|
|
|
rp->du_imr = 0; /* IMR */
|
|
|
|
rp->du_acr = 0xe0; /* baud rate generate set 2 */
|
|
|
|
rp->du_ctur = 0;
|
|
|
|
rp->du_ctlr = 4;
|
|
|
|
rp->du_csra = 0xcc; /* clock select = 38400 */
|
|
|
|
rp->du_cra = 0x10; /* reset mode register ptr */
|
|
|
|
rp->du_cra = 0x20;
|
|
|
|
rp->du_cra = 0x30;
|
|
|
|
rp->du_cra = 0x40;
|
|
|
|
rp->du_mr1a = 0x93; /* MRA1 */
|
|
|
|
rp->du_mr2a = 0x17; /* MRA2 */
|
|
|
|
rp->du_csrb = 0xcc; /* clock select = 38400 */
|
|
|
|
rp->du_crb = 0x10; /* reset mode register ptr */
|
|
|
|
rp->du_crb = 0x20;
|
|
|
|
rp->du_crb = 0x30;
|
|
|
|
rp->du_crb = 0x40;
|
|
|
|
rp->du_mr1b = 0x93; /* MRB1 */
|
|
|
|
rp->du_mr2b = 0x17; /* MRB2 */
|
|
|
|
rp->du_cra = 0x05; /* enable A Rx & Tx */
|
|
|
|
rp->du_crb = 0x05; /* enable B Rx & Tx */
|
|
|
|
|
1995-02-12 22:18:33 +03:00
|
|
|
scc->sc_isr.isr_intr = mfcintr;
|
|
|
|
scc->sc_isr.isr_arg = scc;
|
|
|
|
scc->sc_isr.isr_ipl = 6;
|
|
|
|
add_isr(&scc->sc_isr);
|
1994-12-28 12:24:55 +03:00
|
|
|
|
|
|
|
/* configure ports */
|
|
|
|
bcopy(zap, &ma.zargs, sizeof(struct zbus_args));
|
|
|
|
ma.subdev = "mfcs";
|
|
|
|
ma.unit = unit * 2;
|
|
|
|
config_found(dp, &ma, mfcprint);
|
|
|
|
ma.unit = unit * 2 + 1;
|
|
|
|
config_found(dp, &ma, mfcprint);
|
|
|
|
ma.subdev = "mfcp";
|
|
|
|
ma.unit = unit;
|
|
|
|
config_found(dp, &ma, mfcprint);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1995-02-12 22:18:33 +03:00
|
|
|
*
|
1994-12-28 12:24:55 +03:00
|
|
|
*/
|
|
|
|
int
|
2002-01-26 16:40:52 +03:00
|
|
|
mfcsmatch(struct device *pdp, struct cfdata *cfp, void *auxp)
|
1994-12-28 12:24:55 +03:00
|
|
|
{
|
|
|
|
struct mfc_args *ma;
|
|
|
|
|
|
|
|
ma = auxp;
|
|
|
|
if (strcmp(ma->subdev, "mfcs") == 0)
|
|
|
|
return (1);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-01-26 16:40:52 +03:00
|
|
|
mfcsattach(struct device *pdp, struct device *dp, void *auxp)
|
1994-12-28 12:24:55 +03:00
|
|
|
{
|
|
|
|
int unit;
|
|
|
|
struct mfcs_softc *sc;
|
|
|
|
struct mfc_softc *scc;
|
|
|
|
struct mfc_args *ma;
|
|
|
|
struct mfc_regs *rp;
|
|
|
|
|
|
|
|
sc = (struct mfcs_softc *) dp;
|
|
|
|
scc = (struct mfc_softc *) pdp;
|
|
|
|
ma = auxp;
|
|
|
|
|
|
|
|
if (dp) {
|
1996-10-13 07:05:43 +04:00
|
|
|
printf (": input fifo %d output fifo %d\n", SERIBUF_SIZE,
|
1994-12-28 12:24:55 +03:00
|
|
|
SEROBUF_SIZE);
|
|
|
|
alloc_sicallback();
|
|
|
|
}
|
|
|
|
|
|
|
|
unit = ma->unit;
|
|
|
|
mfcs_active |= 1 << unit;
|
|
|
|
sc->rptr = sc->wptr = sc->inbuf;
|
|
|
|
sc->sc_mfc = scc;
|
|
|
|
sc->sc_regs = rp = scc->sc_regs;
|
|
|
|
sc->sc_duart = (struct duart_regs *) ((unit & 1) ? &rp->du_mr1b :
|
|
|
|
&rp->du_mr1a);
|
|
|
|
/*
|
|
|
|
* should have only one vbl routine to handle all ports?
|
|
|
|
*/
|
1995-11-30 03:56:23 +03:00
|
|
|
sc->vbl_node.function = (void (*) (void *)) mfcsmint;
|
|
|
|
sc->vbl_node.data = (void *) unit;
|
|
|
|
add_vbl_function(&sc->vbl_node, 1, (void *) unit);
|
1994-12-28 12:24:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* print diag if pnp is NULL else just extra
|
|
|
|
*/
|
|
|
|
int
|
2002-01-26 16:40:52 +03:00
|
|
|
mfcprint(void *auxp, const char *pnp)
|
1994-12-28 12:24:55 +03:00
|
|
|
{
|
|
|
|
if (pnp == NULL)
|
|
|
|
return(UNCONF);
|
|
|
|
return(QUIET);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-01-26 16:40:52 +03:00
|
|
|
mfcsopen(dev_t dev, int flag, int mode, struct proc *p)
|
1994-12-28 12:24:55 +03:00
|
|
|
{
|
|
|
|
struct tty *tp;
|
1995-07-04 22:06:40 +04:00
|
|
|
struct mfcs_softc *sc;
|
1994-12-28 12:24:55 +03:00
|
|
|
int unit, error, s;
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
unit = dev & 0x1f;
|
|
|
|
|
1996-03-17 04:16:48 +03:00
|
|
|
if (unit >= mfcs_cd.cd_ndevs || (mfcs_active & (1 << unit)) == 0)
|
1994-12-28 12:24:55 +03:00
|
|
|
return (ENXIO);
|
1996-03-17 04:16:48 +03:00
|
|
|
sc = mfcs_cd.cd_devs[unit];
|
1994-12-28 12:24:55 +03:00
|
|
|
|
|
|
|
s = spltty();
|
|
|
|
|
1995-07-04 22:06:40 +04:00
|
|
|
if (sc->sc_tty)
|
|
|
|
tp = sc->sc_tty;
|
1996-06-06 08:47:31 +04:00
|
|
|
else {
|
1995-07-04 22:06:40 +04:00
|
|
|
tp = sc->sc_tty = ttymalloc();
|
1996-06-06 08:47:31 +04:00
|
|
|
tty_attach(tp);
|
|
|
|
}
|
1994-12-28 12:24:55 +03:00
|
|
|
|
|
|
|
tp->t_oproc = (void (*) (struct tty *)) mfcsstart;
|
|
|
|
tp->t_param = mfcsparam;
|
|
|
|
tp->t_dev = dev;
|
|
|
|
tp->t_hwiflow = mfcshwiflow;
|
|
|
|
|
1998-09-01 06:30:29 +04:00
|
|
|
if ((tp->t_state & TS_ISOPEN) == 0 && tp->t_wopen == 0) {
|
1994-12-28 12:24:55 +03:00
|
|
|
ttychars(tp);
|
|
|
|
if (tp->t_ispeed == 0) {
|
|
|
|
/*
|
|
|
|
* only when cleared do we reset to defaults.
|
|
|
|
*/
|
|
|
|
tp->t_iflag = TTYDEF_IFLAG;
|
|
|
|
tp->t_oflag = TTYDEF_OFLAG;
|
|
|
|
tp->t_cflag = TTYDEF_CFLAG;
|
|
|
|
tp->t_lflag = TTYDEF_LFLAG;
|
|
|
|
tp->t_ispeed = tp->t_ospeed = mfcsdefaultrate;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* do these all the time
|
|
|
|
*/
|
1995-11-30 03:56:23 +03:00
|
|
|
if (sc->swflags & TIOCFLAG_CLOCAL)
|
1994-12-28 12:24:55 +03:00
|
|
|
tp->t_cflag |= CLOCAL;
|
1995-11-30 03:56:23 +03:00
|
|
|
if (sc->swflags & TIOCFLAG_CRTSCTS)
|
1994-12-28 12:24:55 +03:00
|
|
|
tp->t_cflag |= CRTSCTS;
|
1995-11-30 03:56:23 +03:00
|
|
|
if (sc->swflags & TIOCFLAG_MDMBUF)
|
1994-12-28 12:24:55 +03:00
|
|
|
tp->t_cflag |= MDMBUF;
|
|
|
|
mfcsparam(tp, &tp->t_termios);
|
|
|
|
ttsetwater(tp);
|
1995-02-12 22:18:33 +03:00
|
|
|
|
1994-12-28 12:24:55 +03:00
|
|
|
(void)mfcsmctl(dev, TIOCM_DTR | TIOCM_RTS, DMSET);
|
1995-02-12 22:18:33 +03:00
|
|
|
if ((SWFLAGS(dev) & TIOCFLAG_SOFTCAR) ||
|
1994-12-28 12:24:55 +03:00
|
|
|
(mfcsmctl(dev, 0, DMGET) & TIOCM_CD))
|
|
|
|
tp->t_state |= TS_CARR_ON;
|
|
|
|
else
|
|
|
|
tp->t_state &= ~TS_CARR_ON;
|
|
|
|
} else if (tp->t_state & TS_XCLUDE && p->p_ucred->cr_uid != 0) {
|
|
|
|
splx(s);
|
|
|
|
return(EBUSY);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if NONBLOCK requested, ignore carrier
|
|
|
|
*/
|
|
|
|
if (flag & O_NONBLOCK)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* block waiting for carrier
|
|
|
|
*/
|
|
|
|
while ((tp->t_state & TS_CARR_ON) == 0 && (tp->t_cflag & CLOCAL) == 0) {
|
1998-09-01 06:30:29 +04:00
|
|
|
tp->t_wopen++;
|
1995-02-12 22:18:33 +03:00
|
|
|
error = ttysleep(tp, (caddr_t)&tp->t_rawq,
|
1994-12-28 12:24:55 +03:00
|
|
|
TTIPRI | PCATCH, ttopen, 0);
|
1998-09-01 06:30:29 +04:00
|
|
|
tp->t_wopen--;
|
1994-12-28 12:24:55 +03:00
|
|
|
if (error) {
|
|
|
|
splx(s);
|
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
done:
|
|
|
|
/* This is a way to handle lost XON characters */
|
|
|
|
if ((flag & O_TRUNC) && (tp->t_state & TS_TTSTOP)) {
|
|
|
|
tp->t_state &= ~TS_TTSTOP;
|
|
|
|
ttstart (tp);
|
|
|
|
}
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
/*
|
|
|
|
* Reset the tty pointer, as there could have been a dialout
|
|
|
|
* use of the tty with a dialin open waiting.
|
|
|
|
*/
|
|
|
|
tp->t_dev = dev;
|
2001-01-13 05:09:27 +03:00
|
|
|
return tp->t_linesw->l_open(dev, tp);
|
1994-12-28 12:24:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
int
|
2002-01-26 16:40:52 +03:00
|
|
|
mfcsclose(dev_t dev, int flag, int mode, struct proc *p)
|
1994-12-28 12:24:55 +03:00
|
|
|
{
|
|
|
|
struct tty *tp;
|
|
|
|
int unit;
|
1996-03-17 04:16:48 +03:00
|
|
|
struct mfcs_softc *sc = mfcs_cd.cd_devs[dev & 31];
|
1994-12-28 12:24:55 +03:00
|
|
|
struct mfc_softc *scc= sc->sc_mfc;
|
|
|
|
|
|
|
|
unit = dev & 31;
|
|
|
|
|
1995-07-04 22:06:40 +04:00
|
|
|
tp = sc->sc_tty;
|
2001-01-13 05:09:27 +03:00
|
|
|
tp->t_linesw->l_close(tp, flag);
|
1994-12-28 12:24:55 +03:00
|
|
|
sc->sc_duart->ch_cr = 0x70; /* stop break */
|
|
|
|
|
|
|
|
scc->imask &= ~(0x7 << ((unit & 1) * 4));
|
|
|
|
scc->sc_regs->du_imr = scc->imask;
|
|
|
|
if (sc->flags & CT_USED) {
|
|
|
|
--scc->ct_usecnt;
|
|
|
|
sc->flags &= ~CT_USED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the device is closed, it's close, no matter whether we deal with
|
|
|
|
* modem control signals nor not.
|
|
|
|
*/
|
|
|
|
#if 0
|
1998-09-01 06:30:29 +04:00
|
|
|
if (tp->t_cflag & HUPCL || tp->t_wopen != 0 ||
|
1994-12-28 12:24:55 +03:00
|
|
|
(tp->t_state & TS_ISOPEN) == 0)
|
|
|
|
#endif
|
|
|
|
(void) mfcsmctl(dev, 0, DMSET);
|
|
|
|
ttyclose(tp);
|
|
|
|
#if not_yet
|
|
|
|
if (tp != &mfcs_cons) {
|
1995-11-30 03:56:23 +03:00
|
|
|
remove_vbl_function(&sc->vbl_node);
|
1994-12-28 12:24:55 +03:00
|
|
|
ttyfree(tp);
|
1995-07-04 22:06:40 +04:00
|
|
|
sc->sc_tty = (struct tty *) NULL;
|
1994-12-28 12:24:55 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-01-26 16:40:52 +03:00
|
|
|
mfcsread(dev_t dev, struct uio *uio, int flag)
|
1994-12-28 12:24:55 +03:00
|
|
|
{
|
1996-03-17 04:16:48 +03:00
|
|
|
struct mfcs_softc *sc = mfcs_cd.cd_devs[dev & 31];
|
1995-07-04 22:06:40 +04:00
|
|
|
struct tty *tp = sc->sc_tty;
|
|
|
|
if (tp == NULL)
|
1994-12-28 12:24:55 +03:00
|
|
|
return(ENXIO);
|
2001-01-13 05:09:27 +03:00
|
|
|
return tp->t_linesw->l_read(tp, uio, flag);
|
1994-12-28 12:24:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-01-26 16:40:52 +03:00
|
|
|
mfcswrite(dev_t dev, struct uio *uio, int flag)
|
1994-12-28 12:24:55 +03:00
|
|
|
{
|
1996-03-17 04:16:48 +03:00
|
|
|
struct mfcs_softc *sc = mfcs_cd.cd_devs[dev & 31];
|
1995-07-04 22:06:40 +04:00
|
|
|
struct tty *tp = sc->sc_tty;
|
1994-12-28 12:24:55 +03:00
|
|
|
|
1995-07-04 22:06:40 +04:00
|
|
|
if (tp == NULL)
|
1994-12-28 12:24:55 +03:00
|
|
|
return(ENXIO);
|
2001-01-13 05:09:27 +03:00
|
|
|
return tp->t_linesw->l_write(tp, uio, flag);
|
1994-12-28 12:24:55 +03:00
|
|
|
}
|
1995-04-23 22:24:21 +04:00
|
|
|
|
2001-05-02 14:32:08 +04:00
|
|
|
int
|
2002-01-26 16:40:52 +03:00
|
|
|
mfcspoll(dev_t dev, int events, struct proc *p)
|
2001-05-02 14:32:08 +04:00
|
|
|
{
|
|
|
|
struct mfcs_softc *sc = mfcs_cd.cd_devs[dev & 31];
|
|
|
|
struct tty *tp = sc->sc_tty;
|
|
|
|
|
|
|
|
if (tp == NULL)
|
|
|
|
return(ENXIO);
|
|
|
|
return ((*tp->t_linesw->l_poll)(tp, events, p));
|
|
|
|
}
|
|
|
|
|
1995-04-23 22:24:21 +04:00
|
|
|
struct tty *
|
2002-01-26 16:40:52 +03:00
|
|
|
mfcstty(dev_t dev)
|
1995-04-23 22:24:21 +04:00
|
|
|
{
|
1996-03-17 04:16:48 +03:00
|
|
|
struct mfcs_softc *sc = mfcs_cd.cd_devs[dev & 31];
|
1995-07-04 22:06:40 +04:00
|
|
|
|
|
|
|
return (sc->sc_tty);
|
1995-04-23 22:24:21 +04:00
|
|
|
}
|
|
|
|
|
1994-12-28 12:24:55 +03:00
|
|
|
int
|
2002-01-26 16:40:52 +03:00
|
|
|
mfcsioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
|
1994-12-28 12:24:55 +03:00
|
|
|
{
|
|
|
|
register struct tty *tp;
|
|
|
|
register int error;
|
1996-03-17 04:16:48 +03:00
|
|
|
struct mfcs_softc *sc = mfcs_cd.cd_devs[dev & 31];
|
1994-12-28 12:24:55 +03:00
|
|
|
|
1995-07-04 22:06:40 +04:00
|
|
|
tp = sc->sc_tty;
|
1994-12-28 12:24:55 +03:00
|
|
|
if (!tp)
|
|
|
|
return ENXIO;
|
|
|
|
|
2001-01-13 05:09:27 +03:00
|
|
|
error = tp->t_linesw->l_ioctl(tp, cmd, data, flag, p);
|
2002-03-17 22:40:26 +03:00
|
|
|
if (error != EPASSTHROUGH)
|
1994-12-28 12:24:55 +03:00
|
|
|
return(error);
|
|
|
|
|
|
|
|
error = ttioctl(tp, cmd, data, flag, p);
|
2002-03-17 22:40:26 +03:00
|
|
|
if (error != EPASSTHROUGH)
|
1994-12-28 12:24:55 +03:00
|
|
|
return(error);
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case TIOCSBRK:
|
|
|
|
sc->sc_duart->ch_cr = 0x60; /* start break */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TIOCCBRK:
|
|
|
|
sc->sc_duart->ch_cr = 0x70; /* stop break */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TIOCSDTR:
|
|
|
|
(void) mfcsmctl(dev, TIOCM_DTR | TIOCM_RTS, DMBIS);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TIOCCDTR:
|
|
|
|
(void) mfcsmctl(dev, TIOCM_DTR | TIOCM_RTS, DMBIC);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TIOCMSET:
|
|
|
|
(void) mfcsmctl(dev, *(int *) data, DMSET);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TIOCMBIS:
|
|
|
|
(void) mfcsmctl(dev, *(int *) data, DMBIS);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TIOCMBIC:
|
|
|
|
(void) mfcsmctl(dev, *(int *) data, DMBIC);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TIOCMGET:
|
|
|
|
*(int *)data = mfcsmctl(dev, 0, DMGET);
|
|
|
|
break;
|
|
|
|
case TIOCGFLAGS:
|
|
|
|
*(int *)data = SWFLAGS(dev);
|
|
|
|
break;
|
|
|
|
case TIOCSFLAGS:
|
1995-02-12 22:18:33 +03:00
|
|
|
error = suser(p->p_ucred, &p->p_acflag);
|
1994-12-28 12:24:55 +03:00
|
|
|
if (error != 0)
|
1995-02-12 22:18:33 +03:00
|
|
|
return(EPERM);
|
1994-12-28 12:24:55 +03:00
|
|
|
|
1995-11-30 03:56:23 +03:00
|
|
|
sc->swflags = *(int *)data;
|
|
|
|
sc->swflags &= /* only allow valid flags */
|
1994-12-28 12:24:55 +03:00
|
|
|
(TIOCFLAG_SOFTCAR | TIOCFLAG_CLOCAL | TIOCFLAG_CRTSCTS);
|
1995-04-03 00:38:09 +04:00
|
|
|
/* XXXX need to change duart parameters? */
|
1994-12-28 12:24:55 +03:00
|
|
|
break;
|
|
|
|
default:
|
2002-03-17 22:40:26 +03:00
|
|
|
return(EPASSTHROUGH);
|
1994-12-28 12:24:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-01-26 16:40:52 +03:00
|
|
|
mfcsparam(struct tty *tp, struct termios *t)
|
1994-12-28 12:24:55 +03:00
|
|
|
{
|
1996-04-22 01:10:48 +04:00
|
|
|
int cflag, unit, ospeed;
|
1996-03-17 04:16:48 +03:00
|
|
|
struct mfcs_softc *sc = mfcs_cd.cd_devs[tp->t_dev & 31];
|
1994-12-28 12:24:55 +03:00
|
|
|
struct mfc_softc *scc= sc->sc_mfc;
|
1995-02-12 22:18:33 +03:00
|
|
|
|
1994-12-28 12:24:55 +03:00
|
|
|
cflag = t->c_cflag;
|
|
|
|
unit = tp->t_dev & 31;
|
|
|
|
if (sc->flags & CT_USED) {
|
|
|
|
--scc->ct_usecnt;
|
|
|
|
sc->flags &= ~CT_USED;
|
|
|
|
}
|
1995-04-03 00:38:09 +04:00
|
|
|
ospeed = ttspeedtab(t->c_ospeed, scc->mfc_iii ? mfcs3speedtab2 :
|
|
|
|
mfcs2speedtab2);
|
1994-12-28 12:24:55 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If Baud Rate Generator can't generate requested speed,
|
|
|
|
* try to use the counter/timer.
|
|
|
|
*/
|
|
|
|
if (ospeed < 0 && (scc->clk_frq % t->c_ospeed) == 0) {
|
|
|
|
ospeed = scc->clk_frq / t->c_ospeed; /* divisor */
|
|
|
|
if (scc->ct_usecnt > 0 && scc->ct_val != ospeed)
|
|
|
|
ospeed = -1;
|
|
|
|
else {
|
|
|
|
scc->sc_regs->du_ctur = ospeed >> 8;
|
|
|
|
scc->sc_regs->du_ctlr = ospeed;
|
|
|
|
scc->ct_val = ospeed;
|
|
|
|
++scc->ct_usecnt;
|
|
|
|
sc->flags |= CT_USED;
|
|
|
|
ospeed = 0xdd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* XXXX 68681 duart could handle split speeds */
|
|
|
|
if (ospeed < 0 || (t->c_ispeed && t->c_ispeed != t->c_ospeed))
|
|
|
|
return(EINVAL);
|
|
|
|
|
1995-04-03 00:38:09 +04:00
|
|
|
/* XXXX handle parity, character size, stop bits, flow control */
|
|
|
|
|
1995-02-12 22:18:33 +03:00
|
|
|
/*
|
1994-12-28 12:24:55 +03:00
|
|
|
* copy to tty
|
|
|
|
*/
|
|
|
|
tp->t_ispeed = t->c_ispeed;
|
|
|
|
tp->t_ospeed = t->c_ospeed;
|
|
|
|
tp->t_cflag = cflag;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* enable interrupts
|
|
|
|
*/
|
|
|
|
scc->imask |= (0x2 << ((unit & 1) * 4)) | 0x80;
|
|
|
|
scc->sc_regs->du_imr = scc->imask;
|
|
|
|
#if defined(DEBUG) && 0
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("mfcsparam: speed %d => %x ct %d imask %x cflag %x\n",
|
1994-12-28 12:24:55 +03:00
|
|
|
t->c_ospeed, ospeed, scc->ct_val, scc->imask, cflag);
|
|
|
|
#endif
|
|
|
|
if (ospeed == 0)
|
|
|
|
(void)mfcsmctl(tp->t_dev, 0, DMSET); /* hang up line */
|
|
|
|
else {
|
1995-02-12 22:18:33 +03:00
|
|
|
/*
|
1994-12-28 12:24:55 +03:00
|
|
|
* (re)enable DTR
|
|
|
|
* and set baud rate. (8 bit mode)
|
|
|
|
*/
|
|
|
|
(void)mfcsmctl(tp->t_dev, TIOCM_DTR | TIOCM_RTS, DMSET);
|
|
|
|
sc->sc_duart->ch_csr = ospeed;
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
1996-04-22 01:10:48 +04:00
|
|
|
int
|
2002-01-26 16:40:52 +03:00
|
|
|
mfcshwiflow(struct tty *tp, int flag)
|
1994-12-28 12:24:55 +03:00
|
|
|
{
|
1996-03-17 04:16:48 +03:00
|
|
|
struct mfcs_softc *sc = mfcs_cd.cd_devs[tp->t_dev & 31];
|
1994-12-28 12:24:55 +03:00
|
|
|
int unit = tp->t_dev & 1;
|
|
|
|
|
|
|
|
if (flag)
|
|
|
|
sc->sc_regs->du_btrst = 1 << unit;
|
|
|
|
else
|
|
|
|
sc->sc_regs->du_btst = 1 << unit;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1996-04-22 01:10:48 +04:00
|
|
|
void
|
2002-01-26 16:40:52 +03:00
|
|
|
mfcsstart(struct tty *tp)
|
1994-12-28 12:24:55 +03:00
|
|
|
{
|
|
|
|
int cc, s, unit;
|
1996-03-17 04:16:48 +03:00
|
|
|
struct mfcs_softc *sc = mfcs_cd.cd_devs[tp->t_dev & 31];
|
1994-12-28 12:24:55 +03:00
|
|
|
struct mfc_softc *scc= sc->sc_mfc;
|
|
|
|
|
|
|
|
if ((tp->t_state & TS_ISOPEN) == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
unit = tp->t_dev & 1;
|
|
|
|
|
1995-02-12 22:18:33 +03:00
|
|
|
s = splser();
|
1994-12-28 12:24:55 +03:00
|
|
|
if (tp->t_state & (TS_TIMEOUT | TS_TTSTOP))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
cc = tp->t_outq.c_cc;
|
|
|
|
if (cc <= tp->t_lowat) {
|
|
|
|
if (tp->t_state & TS_ASLEEP) {
|
|
|
|
tp->t_state &= ~TS_ASLEEP;
|
|
|
|
wakeup((caddr_t) & tp->t_outq);
|
|
|
|
}
|
|
|
|
selwakeup(&tp->t_wsel);
|
|
|
|
}
|
|
|
|
if (cc == 0 || (tp->t_state & TS_BUSY))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We only do bulk transfers if using CTSRTS flow control, not for
|
|
|
|
* (probably sloooow) ixon/ixoff devices.
|
|
|
|
*/
|
|
|
|
if ((tp->t_cflag & CRTSCTS) == 0)
|
|
|
|
cc = 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Limit the amount of output we do in one burst
|
|
|
|
* to prevent hogging the CPU.
|
|
|
|
*/
|
|
|
|
if (cc > SEROBUF_SIZE)
|
|
|
|
cc = SEROBUF_SIZE;
|
|
|
|
cc = q_to_b(&tp->t_outq, sc->outbuf, cc);
|
|
|
|
if (cc > 0) {
|
|
|
|
tp->t_state |= TS_BUSY;
|
|
|
|
|
|
|
|
sc->ptr = sc->outbuf;
|
|
|
|
sc->end = sc->outbuf + cc;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get first character out, then have TBE-interrupts blow out
|
|
|
|
* further characters, until buffer is empty, and TS_BUSY gets
|
1995-02-12 22:18:33 +03:00
|
|
|
* cleared.
|
1994-12-28 12:24:55 +03:00
|
|
|
*/
|
|
|
|
sc->sc_duart->ch_tb = *sc->ptr++;
|
|
|
|
scc->imask |= 1 << (unit * 4);
|
|
|
|
sc->sc_regs->du_imr = scc->imask;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stop output on a line.
|
|
|
|
*/
|
|
|
|
/*ARGSUSED*/
|
1996-09-02 10:43:16 +04:00
|
|
|
void
|
2002-01-26 16:40:52 +03:00
|
|
|
mfcsstop(struct tty *tp, int flag)
|
1994-12-28 12:24:55 +03:00
|
|
|
{
|
|
|
|
int s;
|
|
|
|
|
1995-02-12 22:18:33 +03:00
|
|
|
s = splser();
|
1994-12-28 12:24:55 +03:00
|
|
|
if (tp->t_state & TS_BUSY) {
|
|
|
|
if ((tp->t_state & TS_TTSTOP) == 0)
|
|
|
|
tp->t_state |= TS_FLUSH;
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-01-26 16:40:52 +03:00
|
|
|
mfcsmctl(dev_t dev, int bits, int how)
|
1994-12-28 12:24:55 +03:00
|
|
|
{
|
|
|
|
int unit, s;
|
1996-04-22 01:10:48 +04:00
|
|
|
u_char ub = 0;
|
1996-03-17 04:16:48 +03:00
|
|
|
struct mfcs_softc *sc = mfcs_cd.cd_devs[dev & 31];
|
1994-12-28 12:24:55 +03:00
|
|
|
|
|
|
|
unit = dev & 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* convert TIOCM* mask into CIA mask
|
|
|
|
* which is active low
|
|
|
|
*/
|
|
|
|
if (how != DMGET) {
|
|
|
|
/*
|
|
|
|
* need to save current state of DTR & RTS ?
|
|
|
|
*/
|
|
|
|
if (bits & TIOCM_DTR)
|
|
|
|
ub |= 0x04 << unit;
|
|
|
|
if (bits & TIOCM_RTS)
|
|
|
|
ub |= 0x01 << unit;
|
|
|
|
}
|
1995-02-12 22:18:33 +03:00
|
|
|
s = splser();
|
1994-12-28 12:24:55 +03:00
|
|
|
switch (how) {
|
|
|
|
case DMSET:
|
|
|
|
sc->sc_regs->du_btst = ub;
|
1995-04-03 00:38:09 +04:00
|
|
|
sc->sc_regs->du_btrst = ub ^ (0x05 << unit);
|
1994-12-28 12:24:55 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DMBIC:
|
|
|
|
sc->sc_regs->du_btrst = ub;
|
|
|
|
ub = ~sc->sc_regs->du_ip;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DMBIS:
|
|
|
|
sc->sc_regs->du_btst = ub;
|
|
|
|
ub = ~sc->sc_regs->du_ip;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DMGET:
|
|
|
|
ub = ~sc->sc_regs->du_ip;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
(void)splx(s);
|
|
|
|
|
1995-04-03 00:38:09 +04:00
|
|
|
/* XXXX should keep DTR & RTS states in softc? */
|
1994-12-28 12:24:55 +03:00
|
|
|
bits = TIOCM_DTR | TIOCM_RTS;
|
|
|
|
if (ub & (1 << unit))
|
|
|
|
bits |= TIOCM_CTS;
|
|
|
|
if (ub & (4 << unit))
|
|
|
|
bits |= TIOCM_DSR;
|
|
|
|
if (ub & (0x10 << unit))
|
|
|
|
bits |= TIOCM_CD;
|
1995-04-03 00:38:09 +04:00
|
|
|
/* XXXX RI is not supported on all boards */
|
1994-12-28 12:24:55 +03:00
|
|
|
if (sc->sc_regs->pad26 & (1 << unit))
|
|
|
|
bits |= TIOCM_RI;
|
|
|
|
|
|
|
|
return(bits);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1995-02-12 22:18:33 +03:00
|
|
|
* Level 6 interrupt processing for the MultiFaceCard 68681 DUART
|
1994-12-28 12:24:55 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
2002-01-26 16:40:52 +03:00
|
|
|
mfcintr(void *arg)
|
1995-02-12 22:18:33 +03:00
|
|
|
{
|
1996-04-22 01:10:48 +04:00
|
|
|
struct mfc_softc *scc = arg;
|
1994-12-28 12:24:55 +03:00
|
|
|
struct mfcs_softc *sc;
|
|
|
|
struct mfc_regs *regs;
|
1995-02-12 22:18:33 +03:00
|
|
|
struct tty *tp;
|
|
|
|
int istat, unit;
|
|
|
|
u_short c;
|
|
|
|
|
|
|
|
regs = scc->sc_regs;
|
|
|
|
istat = regs->du_isr & scc->imask;
|
|
|
|
if (istat == 0)
|
|
|
|
return (0);
|
|
|
|
unit = scc->sc_dev.dv_unit * 2;
|
|
|
|
if (istat & 0x02) { /* channel A receive interrupt */
|
1996-03-17 04:16:48 +03:00
|
|
|
sc = mfcs_cd.cd_devs[unit];
|
1995-02-12 22:18:33 +03:00
|
|
|
while (1) {
|
|
|
|
c = regs->du_sra << 8;
|
|
|
|
if ((c & 0x0100) == 0)
|
|
|
|
break;
|
|
|
|
c |= regs->du_rba;
|
|
|
|
if (sc->incnt == SERIBUF_SIZE)
|
|
|
|
++sc->ovfl;
|
|
|
|
else {
|
|
|
|
*sc->wptr++ = c;
|
|
|
|
if (sc->wptr == sc->inbuf + SERIBUF_SIZE)
|
|
|
|
sc->wptr = sc->inbuf;
|
|
|
|
++sc->incnt;
|
|
|
|
if (sc->incnt > SERIBUF_SIZE - 16)
|
|
|
|
regs->du_btrst = 1;
|
1994-12-28 12:24:55 +03:00
|
|
|
}
|
1995-02-12 22:18:33 +03:00
|
|
|
if (c & 0x1000)
|
|
|
|
regs->du_cra = 0x40;
|
1994-12-28 12:24:55 +03:00
|
|
|
}
|
1995-02-12 22:18:33 +03:00
|
|
|
}
|
|
|
|
if (istat & 0x20) { /* channel B receive interrupt */
|
1996-03-17 04:16:48 +03:00
|
|
|
sc = mfcs_cd.cd_devs[unit + 1];
|
1995-02-12 22:18:33 +03:00
|
|
|
while (1) {
|
|
|
|
c = regs->du_srb << 8;
|
|
|
|
if ((c & 0x0100) == 0)
|
|
|
|
break;
|
|
|
|
c |= regs->du_rbb;
|
|
|
|
if (sc->incnt == SERIBUF_SIZE)
|
|
|
|
++sc->ovfl;
|
|
|
|
else {
|
|
|
|
*sc->wptr++ = c;
|
|
|
|
if (sc->wptr == sc->inbuf + SERIBUF_SIZE)
|
|
|
|
sc->wptr = sc->inbuf;
|
|
|
|
++sc->incnt;
|
|
|
|
if (sc->incnt > SERIBUF_SIZE - 16)
|
|
|
|
regs->du_btrst = 2;
|
1994-12-28 12:24:55 +03:00
|
|
|
}
|
1995-02-12 22:18:33 +03:00
|
|
|
if (c & 0x1000)
|
|
|
|
regs->du_crb = 0x40;
|
1994-12-28 12:24:55 +03:00
|
|
|
}
|
1995-02-12 22:18:33 +03:00
|
|
|
}
|
|
|
|
if (istat & 0x01) { /* channel A transmit interrupt */
|
1996-03-17 04:16:48 +03:00
|
|
|
sc = mfcs_cd.cd_devs[unit];
|
1995-07-04 22:06:40 +04:00
|
|
|
tp = sc->sc_tty;
|
1995-02-12 22:18:33 +03:00
|
|
|
if (sc->ptr == sc->end) {
|
|
|
|
tp->t_state &= ~(TS_BUSY | TS_FLUSH);
|
|
|
|
scc->imask &= ~0x01;
|
|
|
|
regs->du_imr = scc->imask;
|
2001-01-13 05:09:27 +03:00
|
|
|
add_sicallback (tp->t_linesw ?
|
2000-11-02 03:26:35 +03:00
|
|
|
(sifunc_t)tp->t_linesw->l_start
|
1995-10-09 18:19:58 +03:00
|
|
|
: (sifunc_t)mfcsstart, tp, NULL);
|
1995-02-12 22:18:33 +03:00
|
|
|
|
1994-12-28 12:24:55 +03:00
|
|
|
}
|
1995-02-12 22:18:33 +03:00
|
|
|
else
|
|
|
|
regs->du_tba = *sc->ptr++;
|
|
|
|
}
|
|
|
|
if (istat & 0x10) { /* channel B transmit interrupt */
|
1996-03-17 04:16:48 +03:00
|
|
|
sc = mfcs_cd.cd_devs[unit + 1];
|
1995-07-04 22:06:40 +04:00
|
|
|
tp = sc->sc_tty;
|
1995-02-12 22:18:33 +03:00
|
|
|
if (sc->ptr == sc->end) {
|
|
|
|
tp->t_state &= ~(TS_BUSY | TS_FLUSH);
|
|
|
|
scc->imask &= ~0x10;
|
|
|
|
regs->du_imr = scc->imask;
|
2001-01-13 05:09:27 +03:00
|
|
|
add_sicallback (tp->t_linesw ?
|
2000-11-02 03:26:35 +03:00
|
|
|
(sifunc_t)tp->t_linesw->l_start
|
1995-10-09 18:19:58 +03:00
|
|
|
: (sifunc_t)mfcsstart, tp, NULL);
|
1994-12-28 12:24:55 +03:00
|
|
|
}
|
1995-02-12 22:18:33 +03:00
|
|
|
else
|
|
|
|
regs->du_tbb = *sc->ptr++;
|
1994-12-28 12:24:55 +03:00
|
|
|
}
|
1995-02-12 22:18:33 +03:00
|
|
|
if (istat & 0x80) { /* input port change interrupt */
|
|
|
|
c = regs->du_ipcr;
|
1996-10-13 07:05:43 +04:00
|
|
|
printf ("%s: ipcr %02x", scc->sc_dev.dv_xname, c);
|
1995-02-12 22:18:33 +03:00
|
|
|
}
|
|
|
|
return(1);
|
1994-12-28 12:24:55 +03:00
|
|
|
}
|
|
|
|
|
1996-04-22 01:10:48 +04:00
|
|
|
void
|
2002-01-26 16:40:52 +03:00
|
|
|
mfcsxintr(int unit)
|
1994-12-28 12:24:55 +03:00
|
|
|
{
|
|
|
|
int s1, s2, ovfl;
|
1996-03-17 04:16:48 +03:00
|
|
|
struct mfcs_softc *sc = mfcs_cd.cd_devs[unit];
|
1995-07-04 22:06:40 +04:00
|
|
|
struct tty *tp = sc->sc_tty;
|
1994-12-28 12:24:55 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure we're not interrupted by another
|
|
|
|
* vbl, but allow level6 ints
|
|
|
|
*/
|
|
|
|
s1 = spltty();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* pass along any acumulated information
|
|
|
|
* while input is not blocked
|
|
|
|
*/
|
|
|
|
while (sc->incnt && (tp->t_state & TS_TBLOCK) == 0) {
|
1995-02-12 22:18:33 +03:00
|
|
|
/*
|
1994-12-28 12:24:55 +03:00
|
|
|
* no collision with ser_fastint()
|
|
|
|
*/
|
|
|
|
mfcseint(unit, *sc->rptr++);
|
|
|
|
|
|
|
|
ovfl = 0;
|
|
|
|
/* lock against mfcs_fastint() */
|
1995-02-12 22:18:33 +03:00
|
|
|
s2 = splser();
|
1994-12-28 12:24:55 +03:00
|
|
|
--sc->incnt;
|
|
|
|
if (sc->rptr == sc->inbuf + SERIBUF_SIZE)
|
|
|
|
sc->rptr = sc->inbuf;
|
|
|
|
if (sc->ovfl != 0) {
|
|
|
|
ovfl = sc->ovfl;
|
|
|
|
sc->ovfl = 0;
|
|
|
|
}
|
|
|
|
splx(s2);
|
|
|
|
if (ovfl != 0)
|
|
|
|
log(LOG_WARNING, "%s: %d buffer overflow!\n",
|
|
|
|
sc->sc_dev.dv_xname, ovfl);
|
|
|
|
}
|
|
|
|
if (sc->incnt == 0 && (tp->t_state & TS_TBLOCK) == 0) {
|
1995-04-03 00:38:09 +04:00
|
|
|
sc->sc_regs->du_btst = 1 << unit; /* XXXX */
|
1994-12-28 12:24:55 +03:00
|
|
|
}
|
|
|
|
splx(s1);
|
|
|
|
}
|
|
|
|
|
1996-04-22 01:10:48 +04:00
|
|
|
void
|
2002-01-26 16:40:52 +03:00
|
|
|
mfcseint(int unit, int stat)
|
1994-12-28 12:24:55 +03:00
|
|
|
{
|
1996-03-17 04:16:48 +03:00
|
|
|
struct mfcs_softc *sc = mfcs_cd.cd_devs[unit];
|
1994-12-28 12:24:55 +03:00
|
|
|
struct tty *tp;
|
|
|
|
u_char ch;
|
|
|
|
int c;
|
|
|
|
|
1995-07-04 22:06:40 +04:00
|
|
|
tp = sc->sc_tty;
|
1994-12-28 12:24:55 +03:00
|
|
|
ch = stat & 0xff;
|
|
|
|
c = ch;
|
|
|
|
|
|
|
|
if ((tp->t_state & TS_ISOPEN) == 0) {
|
|
|
|
#ifdef KGDB
|
2002-09-06 17:18:43 +04:00
|
|
|
extern const struct cdevsw ser_cdevsw;
|
|
|
|
int maj;
|
|
|
|
|
1994-12-28 12:24:55 +03:00
|
|
|
/* we don't care about parity errors */
|
2002-09-06 17:18:43 +04:00
|
|
|
maj = cdevsw_lookup_major(&ser_cdevsw);
|
|
|
|
if (kgdb_dev == makedev(maj, unit) && c == FRAME_END)
|
1994-12-28 12:24:55 +03:00
|
|
|
kgdb_connect(0); /* trap into kgdb */
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for break and (if enabled) parity error.
|
|
|
|
*/
|
|
|
|
if (stat & 0xc000)
|
|
|
|
c |= TTY_FE;
|
|
|
|
else if (stat & 0x2000)
|
|
|
|
c |= TTY_PE;
|
|
|
|
|
|
|
|
if (stat & 0x1000)
|
1995-02-12 22:18:33 +03:00
|
|
|
log(LOG_WARNING, "%s: fifo overflow\n",
|
1996-03-17 04:16:48 +03:00
|
|
|
((struct mfcs_softc *)mfcs_cd.cd_devs[unit])->sc_dev.dv_xname);
|
1994-12-28 12:24:55 +03:00
|
|
|
|
2001-01-13 05:09:27 +03:00
|
|
|
tp->t_linesw->l_rint(c, tp);
|
1994-12-28 12:24:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This interrupt is periodically invoked in the vertical blank
|
|
|
|
* interrupt. It's used to keep track of the modem control lines
|
|
|
|
* and (new with the fast_int code) to move accumulated data
|
|
|
|
* up into the tty layer.
|
|
|
|
*/
|
|
|
|
void
|
2002-01-26 16:40:52 +03:00
|
|
|
mfcsmint(int unit)
|
1994-12-28 12:24:55 +03:00
|
|
|
{
|
|
|
|
struct tty *tp;
|
1996-03-17 04:16:48 +03:00
|
|
|
struct mfcs_softc *sc = mfcs_cd.cd_devs[unit];
|
1994-12-28 12:24:55 +03:00
|
|
|
u_char stat, last, istat;
|
|
|
|
|
1995-07-04 22:06:40 +04:00
|
|
|
tp = sc->sc_tty;
|
1994-12-28 12:24:55 +03:00
|
|
|
if (!tp)
|
|
|
|
return;
|
|
|
|
|
1998-09-01 06:30:29 +04:00
|
|
|
if ((tp->t_state & TS_ISOPEN) == 0 && tp->t_wopen == 0) {
|
1994-12-28 12:24:55 +03:00
|
|
|
sc->rptr = sc->wptr = sc->inbuf;
|
|
|
|
sc->incnt = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* empty buffer
|
|
|
|
*/
|
|
|
|
mfcsxintr(unit);
|
|
|
|
|
|
|
|
stat = ~sc->sc_regs->du_ip;
|
|
|
|
last = sc->sc_mfc->last_ip;
|
|
|
|
sc->sc_mfc->last_ip = stat;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* check whether any interesting signal changed state
|
|
|
|
*/
|
|
|
|
istat = stat ^ last;
|
|
|
|
|
|
|
|
if ((istat & (0x10 << (unit & 1))) && /* CD changed */
|
|
|
|
(SWFLAGS(tp->t_dev) & TIOCFLAG_SOFTCAR) == 0) {
|
|
|
|
if (stat & (0x10 << (unit & 1)))
|
2001-01-13 05:09:27 +03:00
|
|
|
tp->t_linesw->l_modem(tp, 1);
|
|
|
|
else if (tp->t_linesw->l_modem(tp, 0) == 0) {
|
1994-12-28 12:24:55 +03:00
|
|
|
sc->sc_regs->du_btrst = 0x0a << (unit & 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|