macserial.h 14 KB

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