zs.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. /*
  2. * drivers/tc/zs.h: Definitions for the DECstation Z85C30 serial driver.
  3. *
  4. * Adapted from drivers/sbus/char/sunserial.h by Paul Mackerras.
  5. * Adapted from drivers/macintosh/macserial.h by Harald Koerfgen.
  6. *
  7. * Copyright (C) 1996 Paul Mackerras (Paul.Mackerras@cs.anu.edu.au)
  8. * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
  9. * Copyright (C) 2004 Maciej W. Rozycki
  10. */
  11. #ifndef _DECSERIAL_H
  12. #define _DECSERIAL_H
  13. #include <asm/dec/serial.h>
  14. #define NUM_ZSREGS 16
  15. struct serial_struct {
  16. int type;
  17. int line;
  18. int port;
  19. int irq;
  20. int flags;
  21. int xmit_fifo_size;
  22. int custom_divisor;
  23. int baud_base;
  24. unsigned short close_delay;
  25. char reserved_char[2];
  26. int hub6;
  27. unsigned short closing_wait; /* time to wait before closing */
  28. unsigned short closing_wait2; /* no longer used... */
  29. int reserved[4];
  30. };
  31. /*
  32. * For the close wait times, 0 means wait forever for serial port to
  33. * flush its output. 65535 means don't wait at all.
  34. */
  35. #define ZILOG_CLOSING_WAIT_INF 0
  36. #define ZILOG_CLOSING_WAIT_NONE 65535
  37. /*
  38. * Definitions for ZILOG_struct (and serial_struct) flags field
  39. */
  40. #define ZILOG_HUP_NOTIFY 0x0001 /* Notify getty on hangups and closes
  41. on the callout port */
  42. #define ZILOG_FOURPORT 0x0002 /* Set OU1, OUT2 per AST Fourport settings */
  43. #define ZILOG_SAK 0x0004 /* Secure Attention Key (Orange book) */
  44. #define ZILOG_SPLIT_TERMIOS 0x0008 /* Separate termios for dialin/callout */
  45. #define ZILOG_SPD_MASK 0x0030
  46. #define ZILOG_SPD_HI 0x0010 /* Use 56000 instead of 38400 bps */
  47. #define ZILOG_SPD_VHI 0x0020 /* Use 115200 instead of 38400 bps */
  48. #define ZILOG_SPD_CUST 0x0030 /* Use user-specified divisor */
  49. #define ZILOG_SKIP_TEST 0x0040 /* Skip UART test during autoconfiguration */
  50. #define ZILOG_AUTO_IRQ 0x0080 /* Do automatic IRQ during autoconfiguration */
  51. #define ZILOG_SESSION_LOCKOUT 0x0100 /* Lock out cua opens based on session */
  52. #define ZILOG_PGRP_LOCKOUT 0x0200 /* Lock out cua opens based on pgrp */
  53. #define ZILOG_CALLOUT_NOHUP 0x0400 /* Don't do hangups for cua device */
  54. #define ZILOG_FLAGS 0x0FFF /* Possible legal ZILOG flags */
  55. #define ZILOG_USR_MASK 0x0430 /* Legal flags that non-privileged
  56. * users can set or reset */
  57. /* Internal flags used only by kernel/chr_drv/serial.c */
  58. #define ZILOG_INITIALIZED 0x80000000 /* Serial port was initialized */
  59. #define ZILOG_CALLOUT_ACTIVE 0x40000000 /* Call out device is active */
  60. #define ZILOG_NORMAL_ACTIVE 0x20000000 /* Normal device is active */
  61. #define ZILOG_BOOT_AUTOCONF 0x10000000 /* Autoconfigure port on bootup */
  62. #define ZILOG_CLOSING 0x08000000 /* Serial port is closing */
  63. #define ZILOG_CTS_FLOW 0x04000000 /* Do CTS flow control */
  64. #define ZILOG_CHECK_CD 0x02000000 /* i.e., CLOCAL */
  65. /* Software state per channel */
  66. #ifdef __KERNEL__
  67. /*
  68. * This is our internal structure for each serial port's state.
  69. *
  70. * Many fields are paralleled by the structure used by the serial_struct
  71. * structure.
  72. *
  73. * For definitions of the flags field, see tty.h
  74. */
  75. struct dec_zschannel {
  76. volatile unsigned char *control;
  77. volatile unsigned char *data;
  78. /* Current write register values */
  79. unsigned char curregs[NUM_ZSREGS];
  80. };
  81. struct dec_serial {
  82. struct dec_serial *zs_next; /* For IRQ servicing chain. */
  83. struct dec_zschannel *zs_channel; /* Channel registers. */
  84. struct dec_zschannel *zs_chan_a; /* A side registers. */
  85. unsigned char read_reg_zero;
  86. struct dec_serial_hook *hook; /* Hook on this channel. */
  87. int tty_break; /* Set on BREAK condition. */
  88. int is_cons; /* Is this our console. */
  89. int tx_active; /* Char is being xmitted. */
  90. int tx_stopped; /* Output is suspended. */
  91. /*
  92. * We need to know the current clock divisor
  93. * to read the bps rate the chip has currently loaded.
  94. */
  95. int clk_divisor; /* May be 1, 16, 32, or 64. */
  96. int zs_baud;
  97. char change_needed;
  98. int magic;
  99. int baud_base;
  100. int port;
  101. int irq;
  102. int flags; /* Defined in tty.h. */
  103. int type; /* UART type. */
  104. struct tty_struct *tty;
  105. int read_status_mask;
  106. int ignore_status_mask;
  107. int timeout;
  108. int xmit_fifo_size;
  109. int custom_divisor;
  110. int x_char; /* XON/XOFF character. */
  111. int close_delay;
  112. unsigned short closing_wait;
  113. unsigned short closing_wait2;
  114. unsigned long event;
  115. unsigned long last_active;
  116. int line;
  117. int count; /* # of fds on device. */
  118. int blocked_open; /* # of blocked opens. */
  119. unsigned char *xmit_buf;
  120. int xmit_head;
  121. int xmit_tail;
  122. int xmit_cnt;
  123. struct tq_struct tqueue;
  124. struct tq_struct tqueue_hangup;
  125. wait_queue_head_t open_wait;
  126. wait_queue_head_t close_wait;
  127. };
  128. #define SERIAL_MAGIC 0x5301
  129. /*
  130. * The size of the serial xmit buffer is 1 page, or 4096 bytes
  131. */
  132. #define SERIAL_XMIT_SIZE 4096
  133. /*
  134. * Events are used to schedule things to happen at timer-interrupt
  135. * time, instead of at rs interrupt time.
  136. */
  137. #define RS_EVENT_WRITE_WAKEUP 0
  138. #endif /* __KERNEL__ */
  139. /* Conversion routines to/from brg time constants from/to bits
  140. * per second.
  141. */
  142. #define BRG_TO_BPS(brg, freq) ((freq) / 2 / ((brg) + 2))
  143. #define BPS_TO_BRG(bps, freq) ((((freq) + (bps)) / (2 * (bps))) - 2)
  144. /* The Zilog register set */
  145. #define FLAG 0x7e
  146. /* Write Register 0 */
  147. #define R0 0 /* Register selects */
  148. #define R1 1
  149. #define R2 2
  150. #define R3 3
  151. #define R4 4
  152. #define R5 5
  153. #define R6 6
  154. #define R7 7
  155. #define R8 8
  156. #define R9 9
  157. #define R10 10
  158. #define R11 11
  159. #define R12 12
  160. #define R13 13
  161. #define R14 14
  162. #define R15 15
  163. #define NULLCODE 0 /* Null Code */
  164. #define POINT_HIGH 0x8 /* Select upper half of registers */
  165. #define RES_EXT_INT 0x10 /* Reset Ext. Status Interrupts */
  166. #define SEND_ABORT 0x18 /* HDLC Abort */
  167. #define RES_RxINT_FC 0x20 /* Reset RxINT on First Character */
  168. #define RES_Tx_P 0x28 /* Reset TxINT Pending */
  169. #define ERR_RES 0x30 /* Error Reset */
  170. #define RES_H_IUS 0x38 /* Reset highest IUS */
  171. #define RES_Rx_CRC 0x40 /* Reset Rx CRC Checker */
  172. #define RES_Tx_CRC 0x80 /* Reset Tx CRC Checker */
  173. #define RES_EOM_L 0xC0 /* Reset EOM latch */
  174. /* Write Register 1 */
  175. #define EXT_INT_ENAB 0x1 /* Ext Int Enable */
  176. #define TxINT_ENAB 0x2 /* Tx Int Enable */
  177. #define PAR_SPEC 0x4 /* Parity is special condition */
  178. #define RxINT_DISAB 0 /* Rx Int Disable */
  179. #define RxINT_FCERR 0x8 /* Rx Int on First Character Only or Error */
  180. #define RxINT_ALL 0x10 /* Int on all Rx Characters or error */
  181. #define RxINT_ERR 0x18 /* Int on error only */
  182. #define RxINT_MASK 0x18
  183. #define WT_RDY_RT 0x20 /* Wait/Ready on R/T */
  184. #define WT_FN_RDYFN 0x40 /* Wait/FN/Ready FN */
  185. #define WT_RDY_ENAB 0x80 /* Wait/Ready Enable */
  186. /* Write Register #2 (Interrupt Vector) */
  187. /* Write Register 3 */
  188. #define RxENABLE 0x1 /* Rx Enable */
  189. #define SYNC_L_INH 0x2 /* Sync Character Load Inhibit */
  190. #define ADD_SM 0x4 /* Address Search Mode (SDLC) */
  191. #define RxCRC_ENAB 0x8 /* Rx CRC Enable */
  192. #define ENT_HM 0x10 /* Enter Hunt Mode */
  193. #define AUTO_ENAB 0x20 /* Auto Enables */
  194. #define Rx5 0x0 /* Rx 5 Bits/Character */
  195. #define Rx7 0x40 /* Rx 7 Bits/Character */
  196. #define Rx6 0x80 /* Rx 6 Bits/Character */
  197. #define Rx8 0xc0 /* Rx 8 Bits/Character */
  198. #define RxNBITS_MASK 0xc0
  199. /* Write Register 4 */
  200. #define PAR_ENA 0x1 /* Parity Enable */
  201. #define PAR_EVEN 0x2 /* Parity Even/Odd* */
  202. #define SYNC_ENAB 0 /* Sync Modes Enable */
  203. #define SB1 0x4 /* 1 stop bit/char */
  204. #define SB15 0x8 /* 1.5 stop bits/char */
  205. #define SB2 0xc /* 2 stop bits/char */
  206. #define SB_MASK 0xc
  207. #define MONSYNC 0 /* 8 Bit Sync character */
  208. #define BISYNC 0x10 /* 16 bit sync character */
  209. #define SDLC 0x20 /* SDLC Mode (01111110 Sync Flag) */
  210. #define EXTSYNC 0x30 /* External Sync Mode */
  211. #define X1CLK 0x0 /* x1 clock mode */
  212. #define X16CLK 0x40 /* x16 clock mode */
  213. #define X32CLK 0x80 /* x32 clock mode */
  214. #define X64CLK 0xC0 /* x64 clock mode */
  215. #define XCLK_MASK 0xC0
  216. /* Write Register 5 */
  217. #define TxCRC_ENAB 0x1 /* Tx CRC Enable */
  218. #define RTS 0x2 /* RTS */
  219. #define SDLC_CRC 0x4 /* SDLC/CRC-16 */
  220. #define TxENAB 0x8 /* Tx Enable */
  221. #define SND_BRK 0x10 /* Send Break */
  222. #define Tx5 0x0 /* Tx 5 bits (or less)/character */
  223. #define Tx7 0x20 /* Tx 7 bits/character */
  224. #define Tx6 0x40 /* Tx 6 bits/character */
  225. #define Tx8 0x60 /* Tx 8 bits/character */
  226. #define TxNBITS_MASK 0x60
  227. #define DTR 0x80 /* DTR */
  228. /* Write Register 6 (Sync bits 0-7/SDLC Address Field) */
  229. /* Write Register 7 (Sync bits 8-15/SDLC 01111110) */
  230. /* Write Register 8 (transmit buffer) */
  231. /* Write Register 9 (Master interrupt control) */
  232. #define VIS 1 /* Vector Includes Status */
  233. #define NV 2 /* No Vector */
  234. #define DLC 4 /* Disable Lower Chain */
  235. #define MIE 8 /* Master Interrupt Enable */
  236. #define STATHI 0x10 /* Status high */
  237. #define SOFTACK 0x20 /* Software Interrupt Acknowledge */
  238. #define NORESET 0 /* No reset on write to R9 */
  239. #define CHRB 0x40 /* Reset channel B */
  240. #define CHRA 0x80 /* Reset channel A */
  241. #define FHWRES 0xc0 /* Force hardware reset */
  242. /* Write Register 10 (misc control bits) */
  243. #define BIT6 1 /* 6 bit/8bit sync */
  244. #define LOOPMODE 2 /* SDLC Loop mode */
  245. #define ABUNDER 4 /* Abort/flag on SDLC xmit underrun */
  246. #define MARKIDLE 8 /* Mark/flag on idle */
  247. #define GAOP 0x10 /* Go active on poll */
  248. #define NRZ 0 /* NRZ mode */
  249. #define NRZI 0x20 /* NRZI mode */
  250. #define FM1 0x40 /* FM1 (transition = 1) */
  251. #define FM0 0x60 /* FM0 (transition = 0) */
  252. #define CRCPS 0x80 /* CRC Preset I/O */
  253. /* Write Register 11 (Clock Mode control) */
  254. #define TRxCXT 0 /* TRxC = Xtal output */
  255. #define TRxCTC 1 /* TRxC = Transmit clock */
  256. #define TRxCBR 2 /* TRxC = BR Generator Output */
  257. #define TRxCDP 3 /* TRxC = DPLL output */
  258. #define TRxCOI 4 /* TRxC O/I */
  259. #define TCRTxCP 0 /* Transmit clock = RTxC pin */
  260. #define TCTRxCP 8 /* Transmit clock = TRxC pin */
  261. #define TCBR 0x10 /* Transmit clock = BR Generator output */
  262. #define TCDPLL 0x18 /* Transmit clock = DPLL output */
  263. #define RCRTxCP 0 /* Receive clock = RTxC pin */
  264. #define RCTRxCP 0x20 /* Receive clock = TRxC pin */
  265. #define RCBR 0x40 /* Receive clock = BR Generator output */
  266. #define RCDPLL 0x60 /* Receive clock = DPLL output */
  267. #define RTxCX 0x80 /* RTxC Xtal/No Xtal */
  268. /* Write Register 12 (lower byte of baud rate generator time constant) */
  269. /* Write Register 13 (upper byte of baud rate generator time constant) */
  270. /* Write Register 14 (Misc control bits) */
  271. #define BRENABL 1 /* Baud rate generator enable */
  272. #define BRSRC 2 /* Baud rate generator source */
  273. #define DTRREQ 4 /* DTR/Request function */
  274. #define AUTOECHO 8 /* Auto Echo */
  275. #define LOOPBAK 0x10 /* Local loopback */
  276. #define SEARCH 0x20 /* Enter search mode */
  277. #define RMC 0x40 /* Reset missing clock */
  278. #define DISDPLL 0x60 /* Disable DPLL */
  279. #define SSBR 0x80 /* Set DPLL source = BR generator */
  280. #define SSRTxC 0xa0 /* Set DPLL source = RTxC */
  281. #define SFMM 0xc0 /* Set FM mode */
  282. #define SNRZI 0xe0 /* Set NRZI mode */
  283. /* Write Register 15 (external/status interrupt control) */
  284. #define ZCIE 2 /* Zero count IE */
  285. #define DCDIE 8 /* DCD IE */
  286. #define SYNCIE 0x10 /* Sync/hunt IE */
  287. #define CTSIE 0x20 /* CTS IE */
  288. #define TxUIE 0x40 /* Tx Underrun/EOM IE */
  289. #define BRKIE 0x80 /* Break/Abort IE */
  290. /* Read Register 0 */
  291. #define Rx_CH_AV 0x1 /* Rx Character Available */
  292. #define ZCOUNT 0x2 /* Zero count */
  293. #define Tx_BUF_EMP 0x4 /* Tx Buffer empty */
  294. #define DCD 0x8 /* DCD */
  295. #define SYNC_HUNT 0x10 /* Sync/hunt */
  296. #define CTS 0x20 /* CTS */
  297. #define TxEOM 0x40 /* Tx underrun */
  298. #define BRK_ABRT 0x80 /* Break/Abort */
  299. /* Read Register 1 */
  300. #define ALL_SNT 0x1 /* All sent */
  301. /* Residue Data for 8 Rx bits/char programmed */
  302. #define RES3 0x8 /* 0/3 */
  303. #define RES4 0x4 /* 0/4 */
  304. #define RES5 0xc /* 0/5 */
  305. #define RES6 0x2 /* 0/6 */
  306. #define RES7 0xa /* 0/7 */
  307. #define RES8 0x6 /* 0/8 */
  308. #define RES18 0xe /* 1/8 */
  309. #define RES28 0x0 /* 2/8 */
  310. /* Special Rx Condition Interrupts */
  311. #define PAR_ERR 0x10 /* Parity error */
  312. #define Rx_OVR 0x20 /* Rx Overrun Error */
  313. #define FRM_ERR 0x40 /* CRC/Framing Error */
  314. #define END_FR 0x80 /* End of Frame (SDLC) */
  315. /* Read Register 2 (channel b only) - Interrupt vector */
  316. /* Read Register 3 (interrupt pending register) ch a only */
  317. #define CHBEXT 0x1 /* Channel B Ext/Stat IP */
  318. #define CHBTxIP 0x2 /* Channel B Tx IP */
  319. #define CHBRxIP 0x4 /* Channel B Rx IP */
  320. #define CHAEXT 0x8 /* Channel A Ext/Stat IP */
  321. #define CHATxIP 0x10 /* Channel A Tx IP */
  322. #define CHARxIP 0x20 /* Channel A Rx IP */
  323. /* Read Register 8 (receive data register) */
  324. /* Read Register 10 (misc status bits) */
  325. #define ONLOOP 2 /* On loop */
  326. #define LOOPSEND 0x10 /* Loop sending */
  327. #define CLK2MIS 0x40 /* Two clocks missing */
  328. #define CLK1MIS 0x80 /* One clock missing */
  329. /* Read Register 12 (lower byte of baud rate generator constant) */
  330. /* Read Register 13 (upper byte of baud rate generator constant) */
  331. /* Read Register 15 (value of WR 15) */
  332. /* Misc macros */
  333. #define ZS_CLEARERR(channel) (write_zsreg(channel, 0, ERR_RES))
  334. #define ZS_CLEARFIFO(channel) do { volatile unsigned char garbage; \
  335. garbage = read_zsdata(channel); \
  336. garbage = read_zsdata(channel); \
  337. garbage = read_zsdata(channel); \
  338. } while(0)
  339. #endif /* !(_DECSERIAL_H) */