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