pmac_zilog.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. #ifndef __PMAC_ZILOG_H__
  2. #define __PMAC_ZILOG_H__
  3. /*
  4. * At most 2 ESCCs with 2 ports each
  5. */
  6. #define MAX_ZS_PORTS 4
  7. /*
  8. * We wrap our port structure around the generic uart_port.
  9. */
  10. #define NUM_ZSREGS 17
  11. struct uart_pmac_port {
  12. struct uart_port port;
  13. struct uart_pmac_port *mate;
  14. #ifdef CONFIG_PPC_PMAC
  15. /* macio_dev for the escc holding this port (maybe be null on
  16. * early inited port)
  17. */
  18. struct macio_dev *dev;
  19. /* device node to this port, this points to one of 2 childs
  20. * of "escc" node (ie. ch-a or ch-b)
  21. */
  22. struct device_node *node;
  23. #else
  24. struct platform_device *pdev;
  25. #endif
  26. /* Port type as obtained from device tree (IRDA, modem, ...) */
  27. int port_type;
  28. u8 curregs[NUM_ZSREGS];
  29. unsigned int flags;
  30. #define PMACZILOG_FLAG_IS_CONS 0x00000001
  31. #define PMACZILOG_FLAG_IS_KGDB 0x00000002
  32. #define PMACZILOG_FLAG_MODEM_STATUS 0x00000004
  33. #define PMACZILOG_FLAG_IS_CHANNEL_A 0x00000008
  34. #define PMACZILOG_FLAG_REGS_HELD 0x00000010
  35. #define PMACZILOG_FLAG_TX_STOPPED 0x00000020
  36. #define PMACZILOG_FLAG_TX_ACTIVE 0x00000040
  37. #define PMACZILOG_FLAG_IS_IRDA 0x00000100
  38. #define PMACZILOG_FLAG_IS_INTMODEM 0x00000200
  39. #define PMACZILOG_FLAG_HAS_DMA 0x00000400
  40. #define PMACZILOG_FLAG_RSRC_REQUESTED 0x00000800
  41. #define PMACZILOG_FLAG_IS_OPEN 0x00002000
  42. #define PMACZILOG_FLAG_IS_EXTCLK 0x00008000
  43. #define PMACZILOG_FLAG_BREAK 0x00010000
  44. unsigned char parity_mask;
  45. unsigned char prev_status;
  46. volatile u8 __iomem *control_reg;
  47. volatile u8 __iomem *data_reg;
  48. #ifdef CONFIG_PPC_PMAC
  49. unsigned int tx_dma_irq;
  50. unsigned int rx_dma_irq;
  51. volatile struct dbdma_regs __iomem *tx_dma_regs;
  52. volatile struct dbdma_regs __iomem *rx_dma_regs;
  53. #endif
  54. unsigned char irq_name[8];
  55. struct ktermios termios_cache;
  56. };
  57. #define to_pmz(p) ((struct uart_pmac_port *)(p))
  58. static inline struct uart_pmac_port *pmz_get_port_A(struct uart_pmac_port *uap)
  59. {
  60. if (uap->flags & PMACZILOG_FLAG_IS_CHANNEL_A)
  61. return uap;
  62. return uap->mate;
  63. }
  64. /*
  65. * Register accessors. Note that we don't need to enforce a recovery
  66. * delay on PCI PowerMac hardware, it's dealt in HW by the MacIO chip,
  67. * though if we try to use this driver on older machines, we might have
  68. * to add it back
  69. */
  70. static inline u8 read_zsreg(struct uart_pmac_port *port, u8 reg)
  71. {
  72. if (reg != 0)
  73. writeb(reg, port->control_reg);
  74. return readb(port->control_reg);
  75. }
  76. static inline void write_zsreg(struct uart_pmac_port *port, u8 reg, u8 value)
  77. {
  78. if (reg != 0)
  79. writeb(reg, port->control_reg);
  80. writeb(value, port->control_reg);
  81. }
  82. static inline u8 read_zsdata(struct uart_pmac_port *port)
  83. {
  84. return readb(port->data_reg);
  85. }
  86. static inline void write_zsdata(struct uart_pmac_port *port, u8 data)
  87. {
  88. writeb(data, port->data_reg);
  89. }
  90. static inline void zssync(struct uart_pmac_port *port)
  91. {
  92. (void)readb(port->control_reg);
  93. }
  94. /* Conversion routines to/from brg time constants from/to bits
  95. * per second.
  96. */
  97. #define BRG_TO_BPS(brg, freq) ((freq) / 2 / ((brg) + 2))
  98. #define BPS_TO_BRG(bps, freq) ((((freq) + (bps)) / (2 * (bps))) - 2)
  99. #define ZS_CLOCK 3686400 /* Z8530 RTxC input clock rate */
  100. /* The Zilog register set */
  101. #define FLAG 0x7e
  102. /* Write Register 0 */
  103. #define R0 0 /* Register selects */
  104. #define R1 1
  105. #define R2 2
  106. #define R3 3
  107. #define R4 4
  108. #define R5 5
  109. #define R6 6
  110. #define R7 7
  111. #define R8 8
  112. #define R9 9
  113. #define R10 10
  114. #define R11 11
  115. #define R12 12
  116. #define R13 13
  117. #define R14 14
  118. #define R15 15
  119. #define R7P 16
  120. #define NULLCODE 0 /* Null Code */
  121. #define POINT_HIGH 0x8 /* Select upper half of registers */
  122. #define RES_EXT_INT 0x10 /* Reset Ext. Status Interrupts */
  123. #define SEND_ABORT 0x18 /* HDLC Abort */
  124. #define RES_RxINT_FC 0x20 /* Reset RxINT on First Character */
  125. #define RES_Tx_P 0x28 /* Reset TxINT Pending */
  126. #define ERR_RES 0x30 /* Error Reset */
  127. #define RES_H_IUS 0x38 /* Reset highest IUS */
  128. #define RES_Rx_CRC 0x40 /* Reset Rx CRC Checker */
  129. #define RES_Tx_CRC 0x80 /* Reset Tx CRC Checker */
  130. #define RES_EOM_L 0xC0 /* Reset EOM latch */
  131. /* Write Register 1 */
  132. #define EXT_INT_ENAB 0x1 /* Ext Int Enable */
  133. #define TxINT_ENAB 0x2 /* Tx Int Enable */
  134. #define PAR_SPEC 0x4 /* Parity is special condition */
  135. #define RxINT_DISAB 0 /* Rx Int Disable */
  136. #define RxINT_FCERR 0x8 /* Rx Int on First Character Only or Error */
  137. #define INT_ALL_Rx 0x10 /* Int on all Rx Characters or error */
  138. #define INT_ERR_Rx 0x18 /* Int on error only */
  139. #define RxINT_MASK 0x18
  140. #define WT_RDY_RT 0x20 /* W/Req reflects recv if 1, xmit if 0 */
  141. #define WT_FN_RDYFN 0x40 /* W/Req pin is DMA request if 1, wait if 0 */
  142. #define WT_RDY_ENAB 0x80 /* Enable W/Req pin */
  143. /* Write Register #2 (Interrupt Vector) */
  144. /* Write Register 3 */
  145. #define RxENABLE 0x1 /* Rx Enable */
  146. #define SYNC_L_INH 0x2 /* Sync Character Load Inhibit */
  147. #define ADD_SM 0x4 /* Address Search Mode (SDLC) */
  148. #define RxCRC_ENAB 0x8 /* Rx CRC Enable */
  149. #define ENT_HM 0x10 /* Enter Hunt Mode */
  150. #define AUTO_ENAB 0x20 /* Auto Enables */
  151. #define Rx5 0x0 /* Rx 5 Bits/Character */
  152. #define Rx7 0x40 /* Rx 7 Bits/Character */
  153. #define Rx6 0x80 /* Rx 6 Bits/Character */
  154. #define Rx8 0xc0 /* Rx 8 Bits/Character */
  155. #define RxN_MASK 0xc0
  156. /* Write Register 4 */
  157. #define PAR_ENAB 0x1 /* Parity Enable */
  158. #define PAR_EVEN 0x2 /* Parity Even/Odd* */
  159. #define SYNC_ENAB 0 /* Sync Modes Enable */
  160. #define SB1 0x4 /* 1 stop bit/char */
  161. #define SB15 0x8 /* 1.5 stop bits/char */
  162. #define SB2 0xc /* 2 stop bits/char */
  163. #define SB_MASK 0xc
  164. #define MONSYNC 0 /* 8 Bit Sync character */
  165. #define BISYNC 0x10 /* 16 bit sync character */
  166. #define SDLC 0x20 /* SDLC Mode (01111110 Sync Flag) */
  167. #define EXTSYNC 0x30 /* External Sync Mode */
  168. #define X1CLK 0x0 /* x1 clock mode */
  169. #define X16CLK 0x40 /* x16 clock mode */
  170. #define X32CLK 0x80 /* x32 clock mode */
  171. #define X64CLK 0xC0 /* x64 clock mode */
  172. #define XCLK_MASK 0xC0
  173. /* Write Register 5 */
  174. #define TxCRC_ENAB 0x1 /* Tx CRC Enable */
  175. #define RTS 0x2 /* RTS */
  176. #define SDLC_CRC 0x4 /* SDLC/CRC-16 */
  177. #define TxENABLE 0x8 /* Tx Enable */
  178. #define SND_BRK 0x10 /* Send Break */
  179. #define Tx5 0x0 /* Tx 5 bits (or less)/character */
  180. #define Tx7 0x20 /* Tx 7 bits/character */
  181. #define Tx6 0x40 /* Tx 6 bits/character */
  182. #define Tx8 0x60 /* Tx 8 bits/character */
  183. #define TxN_MASK 0x60
  184. #define DTR 0x80 /* DTR */
  185. /* Write Register 6 (Sync bits 0-7/SDLC Address Field) */
  186. /* Write Register 7 (Sync bits 8-15/SDLC 01111110) */
  187. /* Write Register 7' (Some enhanced feature control) */
  188. #define ENEXREAD 0x40 /* Enable read of some write registers */
  189. /* Write Register 8 (transmit buffer) */
  190. /* Write Register 9 (Master interrupt control) */
  191. #define VIS 1 /* Vector Includes Status */
  192. #define NV 2 /* No Vector */
  193. #define DLC 4 /* Disable Lower Chain */
  194. #define MIE 8 /* Master Interrupt Enable */
  195. #define STATHI 0x10 /* Status high */
  196. #define NORESET 0 /* No reset on write to R9 */
  197. #define CHRB 0x40 /* Reset channel B */
  198. #define CHRA 0x80 /* Reset channel A */
  199. #define FHWRES 0xc0 /* Force hardware reset */
  200. /* Write Register 10 (misc control bits) */
  201. #define BIT6 1 /* 6 bit/8bit sync */
  202. #define LOOPMODE 2 /* SDLC Loop mode */
  203. #define ABUNDER 4 /* Abort/flag on SDLC xmit underrun */
  204. #define MARKIDLE 8 /* Mark/flag on idle */
  205. #define GAOP 0x10 /* Go active on poll */
  206. #define NRZ 0 /* NRZ mode */
  207. #define NRZI 0x20 /* NRZI mode */
  208. #define FM1 0x40 /* FM1 (transition = 1) */
  209. #define FM0 0x60 /* FM0 (transition = 0) */
  210. #define CRCPS 0x80 /* CRC Preset I/O */
  211. /* Write Register 11 (Clock Mode control) */
  212. #define TRxCXT 0 /* TRxC = Xtal output */
  213. #define TRxCTC 1 /* TRxC = Transmit clock */
  214. #define TRxCBR 2 /* TRxC = BR Generator Output */
  215. #define TRxCDP 3 /* TRxC = DPLL output */
  216. #define TRxCOI 4 /* TRxC O/I */
  217. #define TCRTxCP 0 /* Transmit clock = RTxC pin */
  218. #define TCTRxCP 8 /* Transmit clock = TRxC pin */
  219. #define TCBR 0x10 /* Transmit clock = BR Generator output */
  220. #define TCDPLL 0x18 /* Transmit clock = DPLL output */
  221. #define RCRTxCP 0 /* Receive clock = RTxC pin */
  222. #define RCTRxCP 0x20 /* Receive clock = TRxC pin */
  223. #define RCBR 0x40 /* Receive clock = BR Generator output */
  224. #define RCDPLL 0x60 /* Receive clock = DPLL output */
  225. #define RTxCX 0x80 /* RTxC Xtal/No Xtal */
  226. /* Write Register 12 (lower byte of baud rate generator time constant) */
  227. /* Write Register 13 (upper byte of baud rate generator time constant) */
  228. /* Write Register 14 (Misc control bits) */
  229. #define BRENAB 1 /* Baud rate generator enable */
  230. #define BRSRC 2 /* Baud rate generator source */
  231. #define DTRREQ 4 /* DTR/Request function */
  232. #define AUTOECHO 8 /* Auto Echo */
  233. #define LOOPBAK 0x10 /* Local loopback */
  234. #define SEARCH 0x20 /* Enter search mode */
  235. #define RMC 0x40 /* Reset missing clock */
  236. #define DISDPLL 0x60 /* Disable DPLL */
  237. #define SSBR 0x80 /* Set DPLL source = BR generator */
  238. #define SSRTxC 0xa0 /* Set DPLL source = RTxC */
  239. #define SFMM 0xc0 /* Set FM mode */
  240. #define SNRZI 0xe0 /* Set NRZI mode */
  241. /* Write Register 15 (external/status interrupt control) */
  242. #define EN85C30 1 /* Enable some 85c30-enhanced registers */
  243. #define ZCIE 2 /* Zero count IE */
  244. #define ENSTFIFO 4 /* Enable status FIFO (SDLC) */
  245. #define DCDIE 8 /* DCD IE */
  246. #define SYNCIE 0x10 /* Sync/hunt IE */
  247. #define CTSIE 0x20 /* CTS IE */
  248. #define TxUIE 0x40 /* Tx Underrun/EOM IE */
  249. #define BRKIE 0x80 /* Break/Abort IE */
  250. /* Read Register 0 */
  251. #define Rx_CH_AV 0x1 /* Rx Character Available */
  252. #define ZCOUNT 0x2 /* Zero count */
  253. #define Tx_BUF_EMP 0x4 /* Tx Buffer empty */
  254. #define DCD 0x8 /* DCD */
  255. #define SYNC_HUNT 0x10 /* Sync/hunt */
  256. #define CTS 0x20 /* CTS */
  257. #define TxEOM 0x40 /* Tx underrun */
  258. #define BRK_ABRT 0x80 /* Break/Abort */
  259. /* Read Register 1 */
  260. #define ALL_SNT 0x1 /* All sent */
  261. /* Residue Data for 8 Rx bits/char programmed */
  262. #define RES3 0x8 /* 0/3 */
  263. #define RES4 0x4 /* 0/4 */
  264. #define RES5 0xc /* 0/5 */
  265. #define RES6 0x2 /* 0/6 */
  266. #define RES7 0xa /* 0/7 */
  267. #define RES8 0x6 /* 0/8 */
  268. #define RES18 0xe /* 1/8 */
  269. #define RES28 0x0 /* 2/8 */
  270. /* Special Rx Condition Interrupts */
  271. #define PAR_ERR 0x10 /* Parity error */
  272. #define Rx_OVR 0x20 /* Rx Overrun Error */
  273. #define CRC_ERR 0x40 /* CRC/Framing Error */
  274. #define END_FR 0x80 /* End of Frame (SDLC) */
  275. /* Read Register 2 (channel b only) - Interrupt vector */
  276. #define CHB_Tx_EMPTY 0x00
  277. #define CHB_EXT_STAT 0x02
  278. #define CHB_Rx_AVAIL 0x04
  279. #define CHB_SPECIAL 0x06
  280. #define CHA_Tx_EMPTY 0x08
  281. #define CHA_EXT_STAT 0x0a
  282. #define CHA_Rx_AVAIL 0x0c
  283. #define CHA_SPECIAL 0x0e
  284. #define STATUS_MASK 0x06
  285. /* Read Register 3 (interrupt pending register) ch a only */
  286. #define CHBEXT 0x1 /* Channel B Ext/Stat IP */
  287. #define CHBTxIP 0x2 /* Channel B Tx IP */
  288. #define CHBRxIP 0x4 /* Channel B Rx IP */
  289. #define CHAEXT 0x8 /* Channel A Ext/Stat IP */
  290. #define CHATxIP 0x10 /* Channel A Tx IP */
  291. #define CHARxIP 0x20 /* Channel A Rx IP */
  292. /* Read Register 8 (receive data register) */
  293. /* Read Register 10 (misc status bits) */
  294. #define ONLOOP 2 /* On loop */
  295. #define LOOPSEND 0x10 /* Loop sending */
  296. #define CLK2MIS 0x40 /* Two clocks missing */
  297. #define CLK1MIS 0x80 /* One clock missing */
  298. /* Read Register 12 (lower byte of baud rate generator constant) */
  299. /* Read Register 13 (upper byte of baud rate generator constant) */
  300. /* Read Register 15 (value of WR 15) */
  301. /* Misc macros */
  302. #define ZS_CLEARERR(port) (write_zsreg(port, 0, ERR_RES))
  303. #define ZS_CLEARFIFO(port) do { volatile unsigned char garbage; \
  304. garbage = read_zsdata(port); \
  305. garbage = read_zsdata(port); \
  306. garbage = read_zsdata(port); \
  307. } while(0)
  308. #define ZS_IS_CONS(UP) ((UP)->flags & PMACZILOG_FLAG_IS_CONS)
  309. #define ZS_IS_KGDB(UP) ((UP)->flags & PMACZILOG_FLAG_IS_KGDB)
  310. #define ZS_IS_CHANNEL_A(UP) ((UP)->flags & PMACZILOG_FLAG_IS_CHANNEL_A)
  311. #define ZS_REGS_HELD(UP) ((UP)->flags & PMACZILOG_FLAG_REGS_HELD)
  312. #define ZS_TX_STOPPED(UP) ((UP)->flags & PMACZILOG_FLAG_TX_STOPPED)
  313. #define ZS_TX_ACTIVE(UP) ((UP)->flags & PMACZILOG_FLAG_TX_ACTIVE)
  314. #define ZS_WANTS_MODEM_STATUS(UP) ((UP)->flags & PMACZILOG_FLAG_MODEM_STATUS)
  315. #define ZS_IS_IRDA(UP) ((UP)->flags & PMACZILOG_FLAG_IS_IRDA)
  316. #define ZS_IS_INTMODEM(UP) ((UP)->flags & PMACZILOG_FLAG_IS_INTMODEM)
  317. #define ZS_HAS_DMA(UP) ((UP)->flags & PMACZILOG_FLAG_HAS_DMA)
  318. #define ZS_IS_OPEN(UP) ((UP)->flags & PMACZILOG_FLAG_IS_OPEN)
  319. #define ZS_IS_EXTCLK(UP) ((UP)->flags & PMACZILOG_FLAG_IS_EXTCLK)
  320. #endif /* __PMAC_ZILOG_H__ */