pmac_zilog.h 12 KB

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