According to diffs from Waldi Raven:
Make speed/clock-source selection smarter. This makes the baudrates more accurate and allows speeds upto 115k baud.
This commit is contained in:
parent
27a11d1735
commit
d8cb2b8dfa
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: zs.c,v 1.5 1995/05/14 15:55:51 leo Exp $ */
|
||||
/* $NetBSD: zs.c,v 1.6 1995/05/28 19:50:26 leo Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1995 L. Weppelman (Atari modifications)
|
||||
|
@ -94,7 +94,7 @@ struct zs_softc {
|
|||
/*
|
||||
* Define the registers for a closed port
|
||||
*/
|
||||
u_char zs_init_regs[16] = {
|
||||
static u_char zs_init_regs[16] = {
|
||||
/* 0 */ 0,
|
||||
/* 1 */ 0,
|
||||
/* 2 */ 0x60,
|
||||
|
@ -113,6 +113,58 @@ u_char zs_init_regs[16] = {
|
|||
/* 15 */ 0
|
||||
};
|
||||
|
||||
/*
|
||||
* Define the machine dependant clock frequencies
|
||||
* If BRgen feeds sender/receiver we always use a
|
||||
* divisor 16, therefor the division by 16 can as
|
||||
* well be done here.
|
||||
*/
|
||||
static u_long zs_freqs_tt[] = {
|
||||
/*
|
||||
* Atari TT, RTxCB is generated by TT-MFP timer C,
|
||||
* which is set to 307.2KHz during initialisation
|
||||
* and never changed afterwards.
|
||||
*/
|
||||
PCLK/16, /* BRgen, PCLK, divisor 16 */
|
||||
229500, /* BRgen, RTxCA, divisor 16 */
|
||||
3672000, /* RTxCA, from PCLK4 */
|
||||
0, /* TRxCA, external */
|
||||
|
||||
PCLK/16, /* BRgen, PCLK, divisor 16 */
|
||||
19200, /* BRgen, RTxCB, divisor 16 */
|
||||
307200, /* RTxCB, from TT-MFP TCO */
|
||||
2457600 /* TRxCB, from BCLK */
|
||||
};
|
||||
static u_long zs_freqs_falcon[] = {
|
||||
/*
|
||||
* Atari Falcon, XXX no specs available, this might be wrong
|
||||
*/
|
||||
PCLK/16, /* BRgen, PCLK, divisor 16 */
|
||||
229500, /* BRgen, RTxCA, divisor 16 */
|
||||
3672000, /* RTxCA, ??? */
|
||||
0, /* TRxCA, external */
|
||||
|
||||
PCLK/16, /* BRgen, PCLK, divisor 16 */
|
||||
229500, /* BRgen, RTxCB, divisor 16 */
|
||||
3672000, /* RTxCB, ??? */
|
||||
2457600 /* TRxCB, ??? */
|
||||
};
|
||||
static u_long zs_freqs_generic[] = {
|
||||
/*
|
||||
* other machines, assume only PCLK is available
|
||||
*/
|
||||
PCLK/16, /* BRgen, PCLK, divisor 16 */
|
||||
0, /* BRgen, RTxCA, divisor 16 */
|
||||
0, /* RTxCA, unknown */
|
||||
0, /* TRxCA, unknown */
|
||||
|
||||
PCLK/16, /* BRgen, PCLK, divisor 16 */
|
||||
0, /* BRgen, RTxCB, divisor 16 */
|
||||
0, /* RTxCB, unknown */
|
||||
0 /* TRxCB, unknown */
|
||||
};
|
||||
static u_long *zs_frequencies;
|
||||
|
||||
/* Definition of the driver for autoconfig. */
|
||||
static int zsmatch __P((struct device *, struct cfdata *, void *));
|
||||
static void zsattach __P((struct device *, struct device *, void *));
|
||||
|
@ -127,19 +179,20 @@ static int zsrint __P((struct zs_chanstate *, volatile struct zschan *));
|
|||
static int zsxint __P((struct zs_chanstate *, volatile struct zschan *));
|
||||
static int zssint __P((struct zs_chanstate *, volatile struct zschan *));
|
||||
|
||||
struct zs_chanstate *zslist;
|
||||
static struct zs_chanstate *zslist;
|
||||
|
||||
/* Routines called from other code. */
|
||||
static void zsstart __P((struct tty *));
|
||||
void zsstop __P((struct tty *, int));
|
||||
static int zsparam __P((struct tty *, struct termios *));
|
||||
static int zsbaudrate __P((int, int, int *, int *, int *, int *));
|
||||
|
||||
/* Routines purely local to this driver. */
|
||||
static void zs_reset __P((volatile struct zschan *, int, int));
|
||||
static int zs_modem __P((struct zs_chanstate *, int, int));
|
||||
static void zs_loadchannelregs __P((volatile struct zschan *, u_char *));
|
||||
|
||||
int zsshortcuts; /* number of "shortcut" software interrupts */
|
||||
static int zsshortcuts; /* number of "shortcut" software interrupts */
|
||||
|
||||
static int
|
||||
zsmatch(pdp, cfp, auxp)
|
||||
|
@ -194,10 +247,27 @@ void *aux;
|
|||
zs_loadchannelregs(&addr->zs_chan[ZS_CHAN_B], zs_init_regs);
|
||||
|
||||
if(machineid & ATARI_TT) {
|
||||
/*
|
||||
* ininitialise TT-MFP timer C: 307200Hz
|
||||
* timer C and D share one control register:
|
||||
* bits 0-2 control timer D
|
||||
* bits 4-6 control timer C
|
||||
*/
|
||||
int cr = MFP2->mf_tcdcr & 7;
|
||||
MFP2->mf_tcdcr = cr; /* stop timer C */
|
||||
MFP2->mf_tcdr = 1; /* counter 1 */
|
||||
cr |= T_Q004 << 4; /* divisor 4 */
|
||||
MFP2->mf_tcdcr = cr; /* start timer C */
|
||||
/*
|
||||
* enable scc related interrupts
|
||||
*/
|
||||
SCU->sys_mask |= SCU_SCC;
|
||||
|
||||
zs_frequencies = zs_freqs_tt;
|
||||
} else if (machineid & ATARI_FALCON) {
|
||||
zs_frequencies = zs_freqs_falcon;
|
||||
} else {
|
||||
zs_frequencies = zs_freqs_generic;
|
||||
}
|
||||
|
||||
/* link into interrupt list with order (A,B) (B=A+1) */
|
||||
|
@ -881,32 +951,33 @@ register struct termios *t;
|
|||
int unit = ZS_UNIT(tp->t_dev);
|
||||
struct zs_softc *zi = zscd.cd_devs[unit >> 1];
|
||||
register struct zs_chanstate *cs = &zi->zi_cs[unit & 1];
|
||||
int cdiv, clkm, brgm, tcon;
|
||||
register int tmp, tmp5, cflag, s;
|
||||
|
||||
tmp = t->c_ospeed;
|
||||
if(tmp < 0 || (t->c_ispeed && t->c_ispeed != tmp))
|
||||
tmp = t->c_ospeed;
|
||||
tmp5 = t->c_ispeed;
|
||||
if(tmp < 0 || (tmp5 && tmp5 != tmp))
|
||||
return(EINVAL);
|
||||
if(tmp == 0) {
|
||||
/* stty 0 => drop DTR and RTS */
|
||||
zs_modem(cs, 0, DMSET);
|
||||
return(0);
|
||||
}
|
||||
tmp = BPS_TO_TCONST(PCLK / 16, tmp);
|
||||
if(tmp < 2)
|
||||
tmp = zsbaudrate(unit, tmp, &cdiv, &clkm, &brgm, &tcon);
|
||||
if (tmp < 0)
|
||||
return(EINVAL);
|
||||
tp->t_ispeed = tp->t_ospeed = tmp;
|
||||
|
||||
cflag = t->c_cflag;
|
||||
tp->t_ispeed = tp->t_ospeed = TCONST_TO_BPS(PCLK / 16, tmp);
|
||||
tp->t_cflag = cflag;
|
||||
cflag = tp->t_cflag = t->c_cflag;
|
||||
if (cflag & CSTOPB)
|
||||
cdiv |= ZSWR4_TWOSB;
|
||||
else
|
||||
cdiv |= ZSWR4_ONESB;
|
||||
if (!(cflag & PARODD))
|
||||
cdiv |= ZSWR4_EVENP;
|
||||
if (cflag & PARENB)
|
||||
cdiv |= ZSWR4_PARENB;
|
||||
|
||||
/*
|
||||
* Block interrupts so that state will not
|
||||
* be altered until we are done setting it up.
|
||||
*/
|
||||
s = splzs();
|
||||
cs->cs_preg[12] = tmp;
|
||||
cs->cs_preg[13] = tmp >> 8;
|
||||
cs->cs_preg[1] = ZSWR1_RIE | ZSWR1_TIE | ZSWR1_SIE;
|
||||
switch(cflag & CSIZE) {
|
||||
case CS5:
|
||||
tmp = ZSWR3_RX_5;
|
||||
|
@ -926,6 +997,23 @@ register struct termios *t;
|
|||
tmp5 = ZSWR5_TX_8;
|
||||
break;
|
||||
}
|
||||
tmp |= ZSWR3_RX_ENABLE;
|
||||
tmp5 |= ZSWR5_TX_ENABLE | ZSWR5_DTR | ZSWR5_RTS;
|
||||
|
||||
/*
|
||||
* Block interrupts so that state will not
|
||||
* be altered until we are done setting it up.
|
||||
*/
|
||||
s = splzs();
|
||||
cs->cs_preg[4] = cdiv;
|
||||
cs->cs_preg[11] = clkm;
|
||||
cs->cs_preg[12] = tcon;
|
||||
cs->cs_preg[13] = tcon >> 8;
|
||||
cs->cs_preg[14] = brgm;
|
||||
cs->cs_preg[1] = ZSWR1_RIE | ZSWR1_TIE | ZSWR1_SIE;
|
||||
cs->cs_preg[9] = ZSWR9_MASTER_IE | ZSWR9_VECTOR_INCL_STAT;
|
||||
cs->cs_preg[10] = ZSWR10_NRZ;
|
||||
cs->cs_preg[15] = ZSWR15_BREAK_IE | ZSWR15_DCD_IE;
|
||||
|
||||
/*
|
||||
* Output hardware flow control on the chip is horrendous: if
|
||||
|
@ -933,22 +1021,9 @@ register struct termios *t;
|
|||
* can only do this when the carrier is on.
|
||||
*/
|
||||
if(cflag & CCTS_OFLOW && cs->cs_zc->zc_csr & ZSRR0_DCD)
|
||||
tmp |= ZSWR3_HFC | ZSWR3_RX_ENABLE;
|
||||
else tmp |= ZSWR3_RX_ENABLE;
|
||||
tmp |= ZSWR3_HFC;
|
||||
cs->cs_preg[3] = tmp;
|
||||
cs->cs_preg[5] = tmp5 | ZSWR5_TX_ENABLE | ZSWR5_DTR | ZSWR5_RTS;
|
||||
|
||||
tmp = ZSWR4_CLK_X16 | (cflag & CSTOPB ? ZSWR4_TWOSB : ZSWR4_ONESB);
|
||||
if((cflag & PARODD) == 0)
|
||||
tmp |= ZSWR4_EVENP;
|
||||
if (cflag & PARENB)
|
||||
tmp |= ZSWR4_PARENB;
|
||||
cs->cs_preg[4] = tmp;
|
||||
cs->cs_preg[9] = ZSWR9_MASTER_IE | ZSWR9_VECTOR_INCL_STAT;
|
||||
cs->cs_preg[10] = ZSWR10_NRZ;
|
||||
cs->cs_preg[11] = ZSWR11_TXCLK_BAUD | ZSWR11_RXCLK_BAUD;
|
||||
cs->cs_preg[14] = ZSWR14_BAUD_FROM_PCLK | ZSWR14_BAUD_ENA;
|
||||
cs->cs_preg[15] = ZSWR15_BREAK_IE | ZSWR15_DCD_IE;
|
||||
cs->cs_preg[5] = tmp5;
|
||||
|
||||
/*
|
||||
* If nothing is being transmitted, set up new current values,
|
||||
|
@ -959,8 +1034,7 @@ register struct termios *t;
|
|||
cs->cs_heldtbc = cs->cs_tbc;
|
||||
cs->cs_tbc = 0;
|
||||
cs->cs_heldchange = 1;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
bcopy((caddr_t)cs->cs_preg, (caddr_t)cs->cs_creg, 16);
|
||||
zs_loadchannelregs(cs->cs_zc, cs->cs_creg);
|
||||
}
|
||||
|
@ -969,6 +1043,81 @@ register struct termios *t;
|
|||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* search for the best matching baudrate
|
||||
*/
|
||||
static int
|
||||
zsbaudrate(unit, wanted, divisor, clockmode, brgenmode, timeconst)
|
||||
int unit, wanted, *divisor, *clockmode, *brgenmode, *timeconst;
|
||||
{
|
||||
int bestdiff, bestbps, source;
|
||||
|
||||
unit = (unit & 1) << 2;
|
||||
for (source = 0; source < 4; ++source) {
|
||||
long freq = zs_frequencies[unit + source];
|
||||
int diff, bps, div, clkm, brgm, tcon;
|
||||
switch (source) {
|
||||
case 0: /* BRgen, PCLK */
|
||||
brgm = ZSWR14_BAUD_ENA|ZSWR14_BAUD_FROM_PCLK;
|
||||
break;
|
||||
case 1: /* BRgen, RTxC */
|
||||
brgm = ZSWR14_BAUD_ENA;
|
||||
break;
|
||||
case 2: /* RTxC */
|
||||
clkm = ZSWR11_RXCLK_RTXC|ZSWR11_TXCLK_RTXC;
|
||||
break;
|
||||
case 3: /* TRxC */
|
||||
clkm = ZSWR11_RXCLK_TRXC|ZSWR11_TXCLK_TRXC;
|
||||
break;
|
||||
}
|
||||
switch (source) {
|
||||
case 0:
|
||||
case 1:
|
||||
div = ZSWR4_CLK_X16;
|
||||
clkm = ZSWR11_RXCLK_BAUD|ZSWR11_TXCLK_BAUD;
|
||||
tcon = BPS_TO_TCONST(freq, wanted);
|
||||
if (tcon < 0)
|
||||
tcon = 0;
|
||||
bps = TCONST_TO_BPS(freq, tcon);
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
{ int b1 = freq / 16, d1 = abs(b1 - wanted);
|
||||
int b2 = freq / 32, d2 = abs(b2 - wanted);
|
||||
int b3 = freq / 64, d3 = abs(b3 - wanted);
|
||||
|
||||
if (d1 < d2 && d1 < d3) {
|
||||
div = ZSWR4_CLK_X16;
|
||||
bps = b1;
|
||||
} else if (d2 < d3 && d2 < d1) {
|
||||
div = ZSWR4_CLK_X32;
|
||||
bps = b2;
|
||||
} else {
|
||||
div = ZSWR4_CLK_X64;
|
||||
bps = b3;
|
||||
}
|
||||
brgm = tcon = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
diff = abs(bps - wanted);
|
||||
if (!source || diff < bestdiff) {
|
||||
*divisor = div;
|
||||
*clockmode = clkm;
|
||||
*brgenmode = brgm;
|
||||
*timeconst = tcon;
|
||||
bestbps = bps;
|
||||
bestdiff = diff;
|
||||
if (diff == 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* Allow deviations upto 5% */
|
||||
if (20 * bestdiff > wanted)
|
||||
return -1;
|
||||
return bestbps;
|
||||
}
|
||||
|
||||
/*
|
||||
* Raise or lower modem control (DTR/RTS) signals. If a character is
|
||||
* in transmission, the change is deferred.
|
||||
|
|
Loading…
Reference in New Issue