z85230.h 13 KB

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