1 /* 2 * Description of Z8530 Z85C30 and Z85230 communications chips 3 * 4 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) 5 * Copyright (C) 1998 Alan Cox <alan@redhat.com> 6 */ 7 8 #ifndef _Z8530_H 9 #define _Z8530_H 10 11 #include <linux/tty.h> 12 13 /* Conversion routines to/from brg time constants from/to bits 14 * per second. 15 */ 16 #define BRG_TO_BPS(brg, freq) ((freq) / 2 / ((brg) + 2)) 17 #define BPS_TO_BRG(bps, freq) ((((freq) + (bps)) / (2 * (bps))) - 2) 18 19 /* The Zilog register set */ 20 21 #define FLAG 0x7e 22 23 /* Write Register 0 */ 24 #define R0 0 /* Register selects */ 25 #define R1 1 26 #define R2 2 27 #define R3 3 28 #define R4 4 29 #define R5 5 30 #define R6 6 31 #define R7 7 32 #define R8 8 33 #define R9 9 34 #define R10 10 35 #define R11 11 36 #define R12 12 37 #define R13 13 38 #define R14 14 39 #define R15 15 40 41 #define RPRIME 16 /* Indicate a prime register access on 230 */ 42 43 #define NULLCODE 0 /* Null Code */ 44 #define POINT_HIGH 0x8 /* Select upper half of registers */ 45 #define RES_EXT_INT 0x10 /* Reset Ext. Status Interrupts */ 46 #define SEND_ABORT 0x18 /* HDLC Abort */ 47 #define RES_RxINT_FC 0x20 /* Reset RxINT on First Character */ 48 #define RES_Tx_P 0x28 /* Reset TxINT Pending */ 49 #define ERR_RES 0x30 /* Error Reset */ 50 #define RES_H_IUS 0x38 /* Reset highest IUS */ 51 52 #define RES_Rx_CRC 0x40 /* Reset Rx CRC Checker */ 53 #define RES_Tx_CRC 0x80 /* Reset Tx CRC Checker */ 54 #define RES_EOM_L 0xC0 /* Reset EOM latch */ 55 56 /* Write Register 1 */ 57 58 #define EXT_INT_ENAB 0x1 /* Ext Int Enable */ 59 #define TxINT_ENAB 0x2 /* Tx Int Enable */ 60 #define PAR_SPEC 0x4 /* Parity is special condition */ 61 62 #define RxINT_DISAB 0 /* Rx Int Disable */ 63 #define RxINT_FCERR 0x8 /* Rx Int on First Character Only or Error */ 64 #define INT_ALL_Rx 0x10 /* Int on all Rx Characters or error */ 65 #define INT_ERR_Rx 0x18 /* Int on error only */ 66 67 #define WT_RDY_RT 0x20 /* Wait/Ready on R/T */ 68 #define WT_FN_RDYFN 0x40 /* Wait/FN/Ready FN */ 69 #define WT_RDY_ENAB 0x80 /* Wait/Ready Enable */ 70 71 /* Write Register #2 (Interrupt Vector) */ 72 73 /* Write Register 3 */ 74 75 #define RxENABLE 0x1 /* Rx Enable */ 76 #define SYNC_L_INH 0x2 /* Sync Character Load Inhibit */ 77 #define ADD_SM 0x4 /* Address Search Mode (SDLC) */ 78 #define RxCRC_ENAB 0x8 /* Rx CRC Enable */ 79 #define ENT_HM 0x10 /* Enter Hunt Mode */ 80 #define AUTO_ENAB 0x20 /* Auto Enables */ 81 #define Rx5 0x0 /* Rx 5 Bits/Character */ 82 #define Rx7 0x40 /* Rx 7 Bits/Character */ 83 #define Rx6 0x80 /* Rx 6 Bits/Character */ 84 #define Rx8 0xc0 /* Rx 8 Bits/Character */ 85 86 /* Write Register 4 */ 87 88 #define PAR_ENA 0x1 /* Parity Enable */ 89 #define PAR_EVEN 0x2 /* Parity Even/Odd* */ 90 91 #define SYNC_ENAB 0 /* Sync Modes Enable */ 92 #define SB1 0x4 /* 1 stop bit/char */ 93 #define SB15 0x8 /* 1.5 stop bits/char */ 94 #define SB2 0xc /* 2 stop bits/char */ 95 96 #define MONSYNC 0 /* 8 Bit Sync character */ 97 #define BISYNC 0x10 /* 16 bit sync character */ 98 #define SDLC 0x20 /* SDLC Mode (01111110 Sync Flag) */ 99 #define EXTSYNC 0x30 /* External Sync Mode */ 100 101 #define X1CLK 0x0 /* x1 clock mode */ 102 #define X16CLK 0x40 /* x16 clock mode */ 103 #define X32CLK 0x80 /* x32 clock mode */ 104 #define X64CLK 0xC0 /* x64 clock mode */ 105 106 /* Write Register 5 */ 107 108 #define TxCRC_ENAB 0x1 /* Tx CRC Enable */ 109 #define RTS 0x2 /* RTS */ 110 #define SDLC_CRC 0x4 /* SDLC/CRC-16 */ 111 #define TxENAB 0x8 /* Tx Enable */ 112 #define SND_BRK 0x10 /* Send Break */ 113 #define Tx5 0x0 /* Tx 5 bits (or less)/character */ 114 #define Tx7 0x20 /* Tx 7 bits/character */ 115 #define Tx6 0x40 /* Tx 6 bits/character */ 116 #define Tx8 0x60 /* Tx 8 bits/character */ 117 #define DTR 0x80 /* DTR */ 118 119 /* Write Register 6 (Sync bits 0-7/SDLC Address Field) */ 120 121 /* Write Register 7 (Sync bits 8-15/SDLC 01111110) */ 122 123 /* Write Register 8 (transmit buffer) */ 124 125 /* Write Register 9 (Master interrupt control) */ 126 #define VIS 1 /* Vector Includes Status */ 127 #define NV 2 /* No Vector */ 128 #define DLC 4 /* Disable Lower Chain */ 129 #define MIE 8 /* Master Interrupt Enable */ 130 #define STATHI 0x10 /* Status high */ 131 #define NORESET 0 /* No reset on write to R9 */ 132 #define CHRB 0x40 /* Reset channel B */ 133 #define CHRA 0x80 /* Reset channel A */ 134 #define FHWRES 0xc0 /* Force hardware reset */ 135 136 /* Write Register 10 (misc control bits) */ 137 #define BIT6 1 /* 6 bit/8bit sync */ 138 #define LOOPMODE 2 /* SDLC Loop mode */ 139 #define ABUNDER 4 /* Abort/flag on SDLC xmit underrun */ 140 #define MARKIDLE 8 /* Mark/flag on idle */ 141 #define GAOP 0x10 /* Go active on poll */ 142 #define NRZ 0 /* NRZ mode */ 143 #define NRZI 0x20 /* NRZI mode */ 144 #define FM1 0x40 /* FM1 (transition = 1) */ 145 #define FM0 0x60 /* FM0 (transition = 0) */ 146 #define CRCPS 0x80 /* CRC Preset I/O */ 147 148 /* Write Register 11 (Clock Mode control) */ 149 #define TRxCXT 0 /* TRxC = Xtal output */ 150 #define TRxCTC 1 /* TRxC = Transmit clock */ 151 #define TRxCBR 2 /* TRxC = BR Generator Output */ 152 #define TRxCDP 3 /* TRxC = DPLL output */ 153 #define TRxCOI 4 /* TRxC O/I */ 154 #define TCRTxCP 0 /* Transmit clock = RTxC pin */ 155 #define TCTRxCP 8 /* Transmit clock = TRxC pin */ 156 #define TCBR 0x10 /* Transmit clock = BR Generator output */ 157 #define TCDPLL 0x18 /* Transmit clock = DPLL output */ 158 #define RCRTxCP 0 /* Receive clock = RTxC pin */ 159 #define RCTRxCP 0x20 /* Receive clock = TRxC pin */ 160 #define RCBR 0x40 /* Receive clock = BR Generator output */ 161 #define RCDPLL 0x60 /* Receive clock = DPLL output */ 162 #define RTxCX 0x80 /* RTxC Xtal/No Xtal */ 163 164 /* Write Register 12 (lower byte of baud rate generator time constant) */ 165 166 /* Write Register 13 (upper byte of baud rate generator time constant) */ 167 168 /* Write Register 14 (Misc control bits) */ 169 #define BRENABL 1 /* Baud rate generator enable */ 170 #define BRSRC 2 /* Baud rate generator source */ 171 #define DTRREQ 4 /* DTR/Request function */ 172 #define AUTOECHO 8 /* Auto Echo */ 173 #define LOOPBAK 0x10 /* Local loopback */ 174 #define SEARCH 0x20 /* Enter search mode */ 175 #define RMC 0x40 /* Reset missing clock */ 176 #define DISDPLL 0x60 /* Disable DPLL */ 177 #define SSBR 0x80 /* Set DPLL source = BR generator */ 178 #define SSRTxC 0xa0 /* Set DPLL source = RTxC */ 179 #define SFMM 0xc0 /* Set FM mode */ 180 #define SNRZI 0xe0 /* Set NRZI mode */ 181 182 /* Write Register 15 (external/status interrupt control) */ 183 #define PRIME 1 /* R5' etc register access (Z85C30/230 only) */ 184 #define ZCIE 2 /* Zero count IE */ 185 #define FIFOE 4 /* Z85230 only */ 186 #define DCDIE 8 /* DCD IE */ 187 #define SYNCIE 0x10 /* Sync/hunt IE */ 188 #define CTSIE 0x20 /* CTS IE */ 189 #define TxUIE 0x40 /* Tx Underrun/EOM IE */ 190 #define BRKIE 0x80 /* Break/Abort IE */ 191 192 193 /* Read Register 0 */ 194 #define Rx_CH_AV 0x1 /* Rx Character Available */ 195 #define ZCOUNT 0x2 /* Zero count */ 196 #define Tx_BUF_EMP 0x4 /* Tx Buffer empty */ 197 #define DCD 0x8 /* DCD */ 198 #define SYNC_HUNT 0x10 /* Sync/hunt */ 199 #define CTS 0x20 /* CTS */ 200 #define TxEOM 0x40 /* Tx underrun */ 201 #define BRK_ABRT 0x80 /* Break/Abort */ 202 203 /* Read Register 1 */ 204 #define ALL_SNT 0x1 /* All sent */ 205 /* Residue Data for 8 Rx bits/char programmed */ 206 #define RES3 0x8 /* 0/3 */ 207 #define RES4 0x4 /* 0/4 */ 208 #define RES5 0xc /* 0/5 */ 209 #define RES6 0x2 /* 0/6 */ 210 #define RES7 0xa /* 0/7 */ 211 #define RES8 0x6 /* 0/8 */ 212 #define RES18 0xe /* 1/8 */ 213 #define RES28 0x0 /* 2/8 */ 214 /* Special Rx Condition Interrupts */ 215 #define PAR_ERR 0x10 /* Parity error */ 216 #define Rx_OVR 0x20 /* Rx Overrun Error */ 217 #define CRC_ERR 0x40 /* CRC/Framing Error */ 218 #define END_FR 0x80 /* End of Frame (SDLC) */ 219 220 /* Read Register 2 (channel b only) - Interrupt vector */ 221 222 /* Read Register 3 (interrupt pending register) ch a only */ 223 #define CHBEXT 0x1 /* Channel B Ext/Stat IP */ 224 #define CHBTxIP 0x2 /* Channel B Tx IP */ 225 #define CHBRxIP 0x4 /* Channel B Rx IP */ 226 #define CHAEXT 0x8 /* Channel A Ext/Stat IP */ 227 #define CHATxIP 0x10 /* Channel A Tx IP */ 228 #define CHARxIP 0x20 /* Channel A Rx IP */ 229 230 /* Read Register 8 (receive data register) */ 231 232 /* Read Register 10 (misc status bits) */ 233 #define ONLOOP 2 /* On loop */ 234 #define LOOPSEND 0x10 /* Loop sending */ 235 #define CLK2MIS 0x40 /* Two clocks missing */ 236 #define CLK1MIS 0x80 /* One clock missing */ 237 238 /* Read Register 12 (lower byte of baud rate generator constant) */ 239 240 /* Read Register 13 (upper byte of baud rate generator constant) */ 241 242 /* Read Register 15 (value of WR 15) */ 243 244 245 /* 246 * Interrupt handling functions for this SCC 247 */ 248 249 struct z8530_channel; 250 251 struct z8530_irqhandler 252 { 253 void (*rx)(struct z8530_channel *); 254 void (*tx)(struct z8530_channel *); 255 void (*status)(struct z8530_channel *); 256 }; 257 258 /* 259 * A channel of the Z8530 260 */ 261 262 struct z8530_channel 263 { 264 struct z8530_irqhandler *irqs; /* IRQ handlers */ 265 /* 266 * Synchronous 267 */ 268 u16 count; /* Buyes received */ 269 u16 max; /* Most we can receive this frame */ 270 u16 mtu; /* MTU of the device */ 271 u8 *dptr; /* Pointer into rx buffer */ 272 struct sk_buff *skb; /* Buffer dptr points into */ 273 struct sk_buff *skb2; /* Pending buffer */ 274 u8 status; /* Current DCD */ 275 u8 dcdcheck; /* which bit to check for line */ 276 u8 sync; /* Set if in sync mode */ 277 278 u8 regs[32]; /* Register map for the chip */ 279 u8 pendregs[32]; /* Pending register values */ 280 281 struct sk_buff *tx_skb; /* Buffer being transmitted */ 282 struct sk_buff *tx_next_skb; /* Next transmit buffer */ 283 u8 *tx_ptr; /* Byte pointer into the buffer */ 284 u8 *tx_next_ptr; /* Next pointer to use */ 285 u8 *tx_dma_buf[2]; /* TX flip buffers for DMA */ 286 u8 tx_dma_used; /* Flip buffer usage toggler */ 287 u16 txcount; /* Count of bytes to transmit */ 288 289 void (*rx_function)(struct z8530_channel *, struct sk_buff *); 290 291 /* 292 * Sync DMA 293 */ 294 295 u8 rxdma; /* DMA channels */ 296 u8 txdma; 297 u8 rxdma_on; /* DMA active if flag set */ 298 u8 txdma_on; 299 u8 dma_num; /* Buffer we are DMAing into */ 300 u8 dma_ready; /* Is the other buffer free */ 301 u8 dma_tx; /* TX is to use DMA */ 302 u8 *rx_buf[2]; /* The flip buffers */ 303 304 /* 305 * System 306 */ 307 308 struct z8530_dev *dev; /* Z85230 chip instance we are from */ 309 unsigned long ctrlio; /* I/O ports */ 310 unsigned long dataio; 311 312 /* 313 * For PC we encode this way. 314 */ 315 #define Z8530_PORT_SLEEP 0x80000000 316 #define Z8530_PORT_OF(x) ((x)&0xFFFF) 317 318 u32 rx_overrun; /* Overruns - not done yet */ 319 u32 rx_crc_err; 320 321 /* 322 * Bound device pointers 323 */ 324 325 void *private; /* For our owner */ 326 struct net_device *netdevice; /* Network layer device */ 327 struct net_device_stats stats; /* Network layer statistics */ 328 329 /* 330 * Async features 331 */ 332 333 struct tty_struct *tty; /* Attached terminal */ 334 int line; /* Minor number */ 335 struct termios normal_termios; /* Terminal settings */ 336 struct termios callout_termios; 337 wait_queue_head_t open_wait; /* Tasks waiting to open */ 338 wait_queue_head_t close_wait; /* and for close to end */ 339 unsigned long event; /* Pending events */ 340 int fdcount; /* # of fd on device */ 341 int blocked_open; /* # of blocked opens */ 342 long session; /* Session of opening process */ 343 long pgrp; /* pgrp of opening process */ 344 int x_char; /* XON/XOF char */ 345 unsigned char *xmit_buf; /* Transmit pointer */ 346 int xmit_head; /* Transmit ring */ 347 int xmit_tail; 348 int xmit_cnt; 349 int flags; 350 int timeout; 351 int xmit_fifo_size; /* Transmit FIFO info */ 352 353 int close_delay; /* Do we wait for drain on close ? */ 354 unsigned short closing_wait; 355 356 /* We need to know the current clock divisor 357 * to read the bps rate the chip has currently 358 * loaded. 359 */ 360 361 unsigned char clk_divisor; /* May be 1, 16, 32, or 64 */ 362 int zs_baud; 363 364 int magic; 365 int baud_base; /* Baud parameters */ 366 int custom_divisor; 367 368 369 unsigned char tx_active; /* character is being xmitted */ 370 unsigned char tx_stopped; /* output is suspended */ 371 372 spinlock_t *lock; /* Devicr lock */ 373 }; 374 375 /* 376 * Each Z853x0 device. 377 */ 378 379 struct z8530_dev 380 { 381 char *name; /* Device instance name */ 382 struct z8530_channel chanA; /* SCC channel A */ 383 struct z8530_channel chanB; /* SCC channel B */ 384 int type; 385 #define Z8530 0 /* NMOS dinosaur */ 386 #define Z85C30 1 /* CMOS - better */ 387 #define Z85230 2 /* CMOS with real FIFO */ 388 int irq; /* Interrupt for the device */ 389 int active; /* Soft interrupt enable - the Mac doesn't 390 always have a hard disable on its 8530s... */ 391 spinlock_t lock; 392 }; 393 394 395 /* 396 * Functions 397 */ 398 399 extern u8 z8530_dead_port[]; 400 extern u8 z8530_hdlc_kilostream_85230[]; 401 extern u8 z8530_hdlc_kilostream[]; 402 extern void z8530_interrupt(int, void *, struct pt_regs *); 403 extern void z8530_describe(struct z8530_dev *, char *mapping, unsigned long io); 404 extern int z8530_init(struct z8530_dev *); 405 extern int z8530_shutdown(struct z8530_dev *); 406 extern int z8530_sync_open(struct net_device *, struct z8530_channel *); 407 extern int z8530_sync_close(struct net_device *, struct z8530_channel *); 408 extern int z8530_sync_dma_open(struct net_device *, struct z8530_channel *); 409 extern int z8530_sync_dma_close(struct net_device *, struct z8530_channel *); 410 extern int z8530_sync_txdma_open(struct net_device *, struct z8530_channel *); 411 extern int z8530_sync_txdma_close(struct net_device *, struct z8530_channel *); 412 extern int z8530_channel_load(struct z8530_channel *, u8 *); 413 extern int z8530_queue_xmit(struct z8530_channel *c, struct sk_buff *skb); 414 extern struct net_device_stats *z8530_get_stats(struct z8530_channel *c); 415 extern void z8530_null_rx(struct z8530_channel *c, struct sk_buff *skb); 416 417 418 /* 419 * Standard interrupt vector sets 420 */ 421 422 extern struct z8530_irqhandler z8530_sync, z8530_async, z8530_nop; 423 424 /* 425 * Asynchronous Interfacing 426 */ 427 428 #define SERIAL_MAGIC 0x5301 429 430 /* 431 * The size of the serial xmit buffer is 1 page, or 4096 bytes 432 */ 433 434 #define SERIAL_XMIT_SIZE 4096 435 #define WAKEUP_CHARS 256 436 437 /* 438 * Events are used to schedule things to happen at timer-interrupt 439 * time, instead of at rs interrupt time. 440 */ 441 #define RS_EVENT_WRITE_WAKEUP 0 442 443 /* Internal flags used only by kernel/chr_drv/serial.c */ 444 #define ZILOG_INITIALIZED 0x80000000 /* Serial port was initialized */ 445 #define ZILOG_CALLOUT_ACTIVE 0x40000000 /* Call out device is active */ 446 #define ZILOG_NORMAL_ACTIVE 0x20000000 /* Normal device is active */ 447 #define ZILOG_BOOT_AUTOCONF 0x10000000 /* Autoconfigure port on bootup */ 448 #define ZILOG_CLOSING 0x08000000 /* Serial port is closing */ 449 #define ZILOG_CTS_FLOW 0x04000000 /* Do CTS flow control */ 450 #define ZILOG_CHECK_CD 0x02000000 /* i.e., CLOCAL */ 451 452 #endif /* !(_Z8530_H) */ 453