2 * atari_SCC.h: Definitions for the Am8530 Serial Communications Controller
4 * Copyright 1994 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive
16 #include <linux/delay.h>
18 /* Special configuration ioctls for the Atari SCC5380 Serial
19 * Communications Controller
22 /* ioctl command codes */
24 #define TIOCGATSCC 0x54c0 /* get SCC configuration */
25 #define TIOCSATSCC 0x54c1 /* set SCC configuration */
26 #define TIOCDATSCC 0x54c2 /* reset configuration to defaults */
34 /* baud_bases for the common clocks in the Atari. These are the real
35 * frequencies divided by 16.
38 #define SCC_BAUD_BASE_TIMC 19200 /* 0.3072 MHz from TT-MFP, Timer C */
39 #define SCC_BAUD_BASE_BCLK 153600 /* 2.4576 MHz */
40 #define SCC_BAUD_BASE_PCLK4 229500 /* 3.6720 MHz */
41 #define SCC_BAUD_BASE_PCLK 503374 /* 8.0539763 MHz */
42 #define SCC_BAUD_BASE_NONE 0 /* for not connected or unused
45 /* The SCC clock configuration structure */
47 struct scc_clock_config
{
48 unsigned RTxC_base
; /* base_baud of RTxC */
49 unsigned TRxC_base
; /* base_baud of TRxC */
50 unsigned PCLK_base
; /* base_baud of PCLK, both channels! */
52 unsigned clksrc
; /* CLK_RTxC, CLK_TRxC or CLK_PCLK */
53 unsigned divisor
; /* divisor for base baud, valid values:
55 } baud_table
[17]; /* For 50, 75, 110, 135, 150, 200, 300,
56 * 600, 1200, 1800, 2400, 4800, 9600,
57 * 19200, 38400, 57600 and 115200 bps.
58 * The last two could be replaced by
59 * other rates > 38400 if they're not
64 /* The following divisors are valid:
66 * - CLK_RTxC: 1 or even (1, 2 and 4 are the direct modes, > 4 use
69 * - CLK_TRxC: 1, 2 or 4 (no BRG, only direct modes possible)
71 * - CLK_PCLK: >= 4 and even (no direct modes, only BRG)
77 volatile unsigned char *ctrlp
;
78 volatile unsigned char *datap
;
79 int x_char
; /* xon/xoff character */
82 struct scc_port
*port_a
; /* Reference to port A and B */
83 struct scc_port
*port_b
; /* structs for reg access */
86 #define SCC_MAGIC 0x52696368
88 /***********************************************************************/
92 /***********************************************************************/
94 /* The SCC documentation gives no explicit names to the registers,
95 * they're just called WR0..15 and RR0..15. To make the source code
96 * better readable and make the transparent write reg read access (see
97 * below) possible, I christen them here with self-invented names.
98 * Note that (real) read registers are assigned numbers 16..31. WR7'
102 #define COMMAND_REG 0 /* wo */
103 #define INT_AND_DMA_REG 1 /* wo */
104 #define INT_VECTOR_REG 2 /* rw, common to both channels */
105 #define RX_CTRL_REG 3 /* rw */
106 #define AUX1_CTRL_REG 4 /* rw */
107 #define TX_CTRL_REG 5 /* rw */
108 #define SYNC_ADR_REG 6 /* wo */
109 #define SYNC_CHAR_REG 7 /* wo */
110 #define SDLC_OPTION_REG 33 /* wo */
111 #define TX_DATA_REG 8 /* wo */
112 #define MASTER_INT_CTRL 9 /* wo, common to both channels */
113 #define AUX2_CTRL_REG 10 /* rw */
114 #define CLK_CTRL_REG 11 /* wo */
115 #define TIMER_LOW_REG 12 /* rw */
116 #define TIMER_HIGH_REG 13 /* rw */
117 #define DPLL_CTRL_REG 14 /* wo */
118 #define INT_CTRL_REG 15 /* rw */
120 #define STATUS_REG 16 /* ro */
121 #define SPCOND_STATUS_REG 17 /* wo */
122 /* RR2 is WR2 for Channel A, Channel B gives vector + current status: */
123 #define CURR_VECTOR_REG 18 /* Ch. B only, Ch. A for rw */
124 #define INT_PENDING_REG 19 /* Channel A only! */
125 /* RR4 is WR4, if b6(MR7') == 1 */
126 /* RR5 is WR5, if b6(MR7') == 1 */
127 #define FS_FIFO_LOW_REG 22 /* ro */
128 #define FS_FIFO_HIGH_REG 23 /* ro */
129 #define RX_DATA_REG 24 /* ro */
130 /* RR9 is WR3, if b6(MR7') == 1 */
131 #define DPLL_STATUS_REG 26 /* ro */
132 /* RR11 is WR10, if b6(MR7') == 1 */
135 /* RR14 not present */
139 /***********************************************************************/
141 /* Register Values */
143 /***********************************************************************/
146 /* WR0: COMMAND_REG "CR" */
148 #define CR_RX_CRC_RESET 0x40
149 #define CR_TX_CRC_RESET 0x80
150 #define CR_TX_UNDERRUN_RESET 0xc0
152 #define CR_EXTSTAT_RESET 0x10
153 #define CR_SEND_ABORT 0x18
154 #define CR_ENAB_INT_NEXT_RX 0x20
155 #define CR_TX_PENDING_RESET 0x28
156 #define CR_ERROR_RESET 0x30
157 #define CR_HIGHEST_IUS_RESET 0x38
160 /* WR1: INT_AND_DMA_REG "IDR" */
162 #define IDR_EXTSTAT_INT_ENAB 0x01
163 #define IDR_TX_INT_ENAB 0x02
164 #define IDR_PARERR_AS_SPCOND 0x04
166 #define IDR_RX_INT_DISAB 0x00
167 #define IDR_RX_INT_FIRST 0x08
168 #define IDR_RX_INT_ALL 0x10
169 #define IDR_RX_INT_SPCOND 0x18
170 #define IDR_RX_INT_MASK 0x18
172 #define IDR_WAITREQ_RX 0x20
173 #define IDR_WAITREQ_IS_REQ 0x40
174 #define IDR_WAITREQ_ENAB 0x80
177 /* WR3: RX_CTRL_REG "RCR" */
179 #define RCR_RX_ENAB 0x01
180 #define RCR_DISCARD_SYNC_CHARS 0x02
181 #define RCR_ADDR_SEARCH 0x04
182 #define RCR_CRC_ENAB 0x08
183 #define RCR_SEARCH_MODE 0x10
184 #define RCR_AUTO_ENAB_MODE 0x20
186 #define RCR_CHSIZE_MASK 0xc0
187 #define RCR_CHSIZE_5 0x00
188 #define RCR_CHSIZE_6 0x40
189 #define RCR_CHSIZE_7 0x80
190 #define RCR_CHSIZE_8 0xc0
193 /* WR4: AUX1_CTRL_REG "A1CR" */
195 #define A1CR_PARITY_MASK 0x03
196 #define A1CR_PARITY_NONE 0x00
197 #define A1CR_PARITY_ODD 0x01
198 #define A1CR_PARITY_EVEN 0x03
200 #define A1CR_MODE_MASK 0x0c
201 #define A1CR_MODE_SYNCR 0x00
202 #define A1CR_MODE_ASYNC_1 0x04
203 #define A1CR_MODE_ASYNC_15 0x08
204 #define A1CR_MODE_ASYNC_2 0x0c
206 #define A1CR_SYNCR_MODE_MASK 0x30
207 #define A1CR_SYNCR_MONOSYNC 0x00
208 #define A1CR_SYNCR_BISYNC 0x10
209 #define A1CR_SYNCR_SDLC 0x20
210 #define A1CR_SYNCR_EXTCSYNC 0x30
212 #define A1CR_CLKMODE_MASK 0xc0
213 #define A1CR_CLKMODE_x1 0x00
214 #define A1CR_CLKMODE_x16 0x40
215 #define A1CR_CLKMODE_x32 0x80
216 #define A1CR_CLKMODE_x64 0xc0
219 /* WR5: TX_CTRL_REG "TCR" */
221 #define TCR_TX_CRC_ENAB 0x01
223 #define TCR_USE_CRC_CCITT 0x00
224 #define TCR_USE_CRC_16 0x04
225 #define TCR_TX_ENAB 0x08
226 #define TCR_SEND_BREAK 0x10
228 #define TCR_CHSIZE_MASK 0x60
229 #define TCR_CHSIZE_5 0x00
230 #define TCR_CHSIZE_6 0x20
231 #define TCR_CHSIZE_7 0x40
232 #define TCR_CHSIZE_8 0x60
237 /* WR7': SLDC_OPTION_REG "SOR" */
239 #define SOR_AUTO_TX_ENAB 0x01
240 #define SOR_AUTO_EOM_RESET 0x02
241 #define SOR_AUTO_RTS_MODE 0x04
242 #define SOR_NRZI_DISAB_HIGH 0x08
243 #define SOR_ALT_DTRREQ_TIMING 0x10
244 #define SOR_READ_CRC_CHARS 0x20
245 #define SOR_EXTENDED_REG_ACCESS 0x40
248 /* WR9: MASTER_INT_CTRL "MIC" */
250 #define MIC_VEC_INCL_STAT 0x01
251 #define MIC_NO_VECTOR 0x02
252 #define MIC_DISAB_LOWER_CHAIN 0x04
253 #define MIC_MASTER_INT_ENAB 0x08
254 #define MIC_STATUS_HIGH 0x10
255 #define MIC_IGN_INTACK 0x20
257 #define MIC_NO_RESET 0x00
258 #define MIC_CH_A_RESET 0x40
259 #define MIC_CH_B_RESET 0x80
260 #define MIC_HARD_RESET 0xc0
263 /* WR10: AUX2_CTRL_REG "A2CR" */
265 #define A2CR_SYNC_6 0x01
266 #define A2CR_LOOP_MODE 0x02
267 #define A2CR_ABORT_ON_UNDERRUN 0x04
268 #define A2CR_MARK_IDLE 0x08
269 #define A2CR_GO_ACTIVE_ON_POLL 0x10
271 #define A2CR_CODING_MASK 0x60
272 #define A2CR_CODING_NRZ 0x00
273 #define A2CR_CODING_NRZI 0x20
274 #define A2CR_CODING_FM1 0x40
275 #define A2CR_CODING_FM0 0x60
277 #define A2CR_PRESET_CRC_1 0x80
280 /* WR11: CLK_CTRL_REG "CCR" */
282 #define CCR_TRxCOUT_MASK 0x03
283 #define CCR_TRxCOUT_XTAL 0x00
284 #define CCR_TRxCOUT_TXCLK 0x01
285 #define CCR_TRxCOUT_BRG 0x02
286 #define CCR_TRxCOUT_DPLL 0x03
288 #define CCR_TRxC_OUTPUT 0x04
290 #define CCR_TXCLK_MASK 0x18
291 #define CCR_TXCLK_RTxC 0x00
292 #define CCR_TXCLK_TRxC 0x08
293 #define CCR_TXCLK_BRG 0x10
294 #define CCR_TXCLK_DPLL 0x18
296 #define CCR_RXCLK_MASK 0x60
297 #define CCR_RXCLK_RTxC 0x00
298 #define CCR_RXCLK_TRxC 0x20
299 #define CCR_RXCLK_BRG 0x40
300 #define CCR_RXCLK_DPLL 0x60
302 #define CCR_RTxC_XTAL 0x80
305 /* WR14: DPLL_CTRL_REG "DCR" */
307 #define DCR_BRG_ENAB 0x01
308 #define DCR_BRG_USE_PCLK 0x02
309 #define DCR_DTRREQ_IS_REQ 0x04
310 #define DCR_AUTO_ECHO 0x08
311 #define DCR_LOCAL_LOOPBACK 0x10
313 #define DCR_DPLL_EDGE_SEARCH 0x20
314 #define DCR_DPLL_ERR_RESET 0x40
315 #define DCR_DPLL_DISAB 0x60
316 #define DCR_DPLL_CLK_BRG 0x80
317 #define DCR_DPLL_CLK_RTxC 0xa0
318 #define DCR_DPLL_FM 0xc0
319 #define DCR_DPLL_NRZI 0xe0
322 /* WR15: INT_CTRL_REG "ICR" */
324 #define ICR_OPTIONREG_SELECT 0x01
325 #define ICR_ENAB_BRG_ZERO_INT 0x02
326 #define ICR_USE_FS_FIFO 0x04
327 #define ICR_ENAB_DCD_INT 0x08
328 #define ICR_ENAB_SYNC_INT 0x10
329 #define ICR_ENAB_CTS_INT 0x20
330 #define ICR_ENAB_UNDERRUN_INT 0x40
331 #define ICR_ENAB_BREAK_INT 0x80
334 /* RR0: STATUS_REG "SR" */
336 #define SR_CHAR_AVAIL 0x01
337 #define SR_BRG_ZERO 0x02
338 #define SR_TX_BUF_EMPTY 0x04
340 #define SR_SYNC_ABORT 0x10
342 #define SR_TX_UNDERRUN 0x40
343 #define SR_BREAK 0x80
346 /* RR1: SPCOND_STATUS_REG "SCSR" */
348 #define SCSR_ALL_SENT 0x01
349 #define SCSR_RESIDUAL_MASK 0x0e
350 #define SCSR_PARITY_ERR 0x10
351 #define SCSR_RX_OVERRUN 0x20
352 #define SCSR_CRC_FRAME_ERR 0x40
353 #define SCSR_END_OF_FRAME 0x80
356 /* RR3: INT_PENDING_REG "IPR" */
358 #define IPR_B_EXTSTAT 0x01
359 #define IPR_B_TX 0x02
360 #define IPR_B_RX 0x04
361 #define IPR_A_EXTSTAT 0x08
362 #define IPR_A_TX 0x10
363 #define IPR_A_RX 0x20
366 /* RR7: FS_FIFO_HIGH_REG "FFHR" */
368 #define FFHR_CNT_MASK 0x3f
369 #define FFHR_IS_FROM_FIFO 0x40
370 #define FFHR_FIFO_OVERRUN 0x80
373 /* RR10: DPLL_STATUS_REG "DSR" */
375 #define DSR_ON_LOOP 0x02
376 #define DSR_ON_LOOP_SENDING 0x10
377 #define DSR_TWO_CLK_MISSING 0x40
378 #define DSR_ONE_CLK_MISSING 0x80
380 /***********************************************************************/
382 /* Register Access */
384 /***********************************************************************/
387 /* The SCC needs 3.5 PCLK cycles recovery time between to register
388 * accesses. PCLK runs with 8 MHz on an Atari, so this delay is 3.5 *
389 * 125 ns = 437.5 ns. This is too short for udelay().
390 * 10/16/95: A tstb mfp.par_dt_reg takes 600ns (sure?) and thus should be
394 #define scc_reg_delay() \
396 if (MACH_IS_MVME16x || MACH_IS_BVME6000 || MACH_IS_MVME147) \
397 __asm__ __volatile__ ( " nop; nop"); \
398 else if (MACH_IS_ATARI) \
399 __asm__ __volatile__ ( "tstb %0" : : "g" (*_scc_del) : "cc" );\
402 static unsigned char scc_shadow
[2][16];
404 /* The following functions should relax the somehow complicated
405 * register access of the SCC. _SCCwrite() stores all written values
406 * (except for WR0 and WR8) in shadow registers for later recall. This
407 * removes the burden of remembering written values as needed. The
408 * extra work of storing the value doesn't count, since a delay is
409 * needed after a SCC access anyway. Additionally, _SCCwrite() manages
410 * writes to WR0 and WR8 differently, because these can be accessed
411 * directly with less overhead. Another special case are WR7 and WR7'.
412 * _SCCwrite automatically checks what of this registers is selected
413 * and changes b0 of WR15 if needed.
415 * _SCCread() for standard read registers is straightforward, except
416 * for RR2 (split into two "virtual" registers: one for the value
417 * written to WR2 (from the shadow) and one for the vector including
418 * status from RR2, Ch. B) and RR3. The latter must be read from
419 * Channel A, because it reads as all zeros on Ch. B. RR0 and RR8 can
420 * be accessed directly as before.
422 * The two inline function contain complicated switch statements. But
423 * I rely on regno and final_delay being constants, so gcc can reduce
424 * the whole stuff to just some assembler statements.
426 * _SCCwrite and _SCCread aren't intended to be used directly under
427 * normal circumstances. The macros SCCread[_ND] and SCCwrite[_ND] are
428 * for that purpose. They assume that a local variable 'port' is
429 * declared and pointing to the port's scc_struct entry. The
430 * variants with "_NB" appended should be used if no other SCC
431 * accesses follow immediately (within 0.5 usecs). They just skip the
434 * Please note that accesses to SCC registers should only take place
435 * when interrupts are turned off (at least if SCC interrupts are
436 * enabled). Otherwise, an interrupt could interfere with the
437 * two-stage accessing process.
442 static __inline__
void _SCCwrite(
443 struct scc_port
*port
,
444 unsigned char *shadow
,
445 volatile unsigned char *_scc_del
,
447 unsigned char val
, int final_delay
)
452 /* WR0 can be written directly without pointing */
457 /* For WR7, first set b0 of WR15 to 0, if needed */
458 if (shadow
[INT_CTRL_REG
] & ICR_OPTIONREG_SELECT
) {
460 shadow
[INT_CTRL_REG
] &= ~ICR_OPTIONREG_SELECT
;
462 *port
->ctrlp
= shadow
[INT_CTRL_REG
];
467 case SDLC_OPTION_REG
:
468 /* For WR7', first set b0 of WR15 to 1, if needed */
469 if (!(shadow
[INT_CTRL_REG
] & ICR_OPTIONREG_SELECT
)) {
471 shadow
[INT_CTRL_REG
] |= ICR_OPTIONREG_SELECT
;
473 *port
->ctrlp
= shadow
[INT_CTRL_REG
];
477 shadow
[8] = val
; /* WR7' shadowed at WR8 */
482 case TX_DATA_REG
: /* WR8 */
483 /* TX_DATA_REG can be accessed directly on some h/w */
484 if (MACH_IS_MVME16x
|| MACH_IS_BVME6000
|| MACH_IS_MVME147
)
486 *port
->ctrlp
= regno
;
494 case MASTER_INT_CTRL
:
495 *port
->ctrlp
= regno
;
496 val
&= 0x3f; /* bits 6..7 are the reset commands */
497 scc_shadow
[0][regno
] = val
;
503 *port
->ctrlp
= regno
;
504 val
&= 0x1f; /* bits 5..7 are the DPLL commands */
514 *port
->ctrlp
= regno
;
521 printk( "Bad SCC write access to WR%d\n", regno
);
531 static __inline__
unsigned char _SCCread(
532 struct scc_port
*port
,
533 unsigned char *shadow
,
534 volatile unsigned char *_scc_del
,
535 int regno
, int final_delay
)
541 /* --- real read registers --- */
546 case INT_PENDING_REG
:
547 /* RR3: read only from Channel A! */
552 /* RR8 can be accessed directly on some h/w */
553 if (MACH_IS_MVME16x
|| MACH_IS_BVME6000
|| MACH_IS_MVME147
)
563 case CURR_VECTOR_REG
:
564 /* RR2 (vector including status) from Ch. B */
568 /* --- reading write registers: access the shadow --- */
571 return shadow
[regno
]; /* no final delay! */
573 /* WR7' is special, because it is shadowed at the place of WR8 */
574 case SDLC_OPTION_REG
:
575 return shadow
[8]; /* no final delay! */
577 /* WR9 is special too, because it is common for both channels */
578 case MASTER_INT_CTRL
:
579 return scc_shadow
[0][9]; /* no final delay! */
582 printk( "Bad SCC read access to %cR%d\n", (regno
& 16) ? 'R' : 'W',
586 case SPCOND_STATUS_REG
:
587 case FS_FIFO_LOW_REG
:
588 case FS_FIFO_HIGH_REG
:
589 case DPLL_STATUS_REG
:
591 *port
->ctrlp
= regno
& 0x0f;
603 #define SCC_ACCESS_INIT(port) \
604 unsigned char *_scc_shadow = &scc_shadow[port->channel][0]
606 #define SCCwrite(reg,val) _SCCwrite(port,_scc_shadow,scc_del,(reg),(val),1)
607 #define SCCwrite_NB(reg,val) _SCCwrite(port,_scc_shadow,scc_del,(reg),(val),0)
608 #define SCCread(reg) _SCCread(port,_scc_shadow,scc_del,(reg),1)
609 #define SCCread_NB(reg) _SCCread(port,_scc_shadow,scc_del,(reg),0)
611 #define SCCmod(reg,and,or) SCCwrite((reg),(SCCread(reg)&(and))|(or))