]> git.saurik.com Git - apple/xnu.git/blob - osfmk/ppc/scc_8530.h
7c7a5d4d0049d6887a288a7a16732d8c5c5df2f5
[apple/xnu.git] / osfmk / ppc / scc_8530.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 /*
24 * @OSF_COPYRIGHT@
25 */
26 /*
27 * @APPLE_FREE_COPYRIGHT@
28 */
29 /*
30 * Mach Operating System
31 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
32 * All Rights Reserved.
33 *
34 * Permission to use, copy, modify and distribute this software and its
35 * documentation is hereby granted, provided that both the copyright
36 * notice and this permission notice appear in all copies of the
37 * software, derivative works or modified versions, and any portions
38 * thereof, and that both notices appear in supporting documentation.
39 *
40 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
41 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
42 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
43 *
44 * Carnegie Mellon requests users of this software to return to
45 *
46 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
47 * School of Computer Science
48 * Carnegie Mellon University
49 * Pittsburgh PA 15213-3890
50 *
51 * any improvements or extensions that they make and grant Carnegie Mellon
52 * the rights to redistribute these changes.
53 */
54 /*
55 */
56 /*
57 * File: scc_8530.h
58 * Author: Alessandro Forin, Carnegie Mellon University
59 * Date: 6/91
60 *
61 * Definitions for the Zilog Z8530 SCC serial line chip
62 */
63
64 #ifndef _SCC_8530_H_
65 #define _SCC_8530_H_
66
67 /*
68 * Register map, needs definition of the alignment
69 * used on the specific machine.
70 * #define the 'scc_register_t' data type before
71 * including this header file. For restrictions on
72 * access modes define the set/get_datum macros.
73 * We provide defaults ifnot.
74 */
75
76
77 #define SCC_CHANNEL_A 1
78 #define SCC_CHANNEL_B 0
79
80 #define SCC_MODEM SCC_CHANNEL_A
81 #define SCC_PRINTER SCC_CHANNEL_B
82
83 #define SCC_DATA_OFFSET 4
84
85 typedef unsigned char *scc_regmap_t;
86
87 extern void powermac_scc_set_datum(scc_regmap_t regs, unsigned int offset, unsigned char value);
88 extern unsigned char powermac_scc_get_datum(scc_regmap_t regs, unsigned int offset);
89
90 #define scc_set_datum(regs, d, v) powermac_scc_set_datum(regs, (d), (v))
91 #define scc_get_datum(regs, d,v) (v) = powermac_scc_get_datum(regs, (d));
92
93 #define scc_init_reg(regs,chan) { \
94 char tmp; \
95 scc_get_datum(regs, ((chan)<<1),tmp); \
96 scc_get_datum(regs, ((chan)<<1),tmp); \
97 }
98
99 #define scc_read_reg(regs,chan,reg,val) { \
100 scc_set_datum(regs, ((chan)<<1),reg); \
101 scc_get_datum(regs, ((chan)<<1),val); \
102 }
103
104 #define scc_read_reg_zero(regs,chan,val) { \
105 scc_get_datum(regs, ((chan)<<1),val); \
106 }
107
108 #define scc_write_reg(regs,chan,reg,val) { \
109 scc_set_datum(regs, ((chan)<<1),reg); \
110 scc_set_datum(regs, ((chan)<<1),val); \
111 }
112
113 #define scc_write_reg_zero(regs,chan,val) { \
114 scc_set_datum(regs, ((chan)<<1),val); \
115 }
116
117 #define scc_read_data(regs,chan,val) { \
118 scc_get_datum(regs, ((chan)<<1)+SCC_DATA_OFFSET,val); \
119 }
120
121 #define scc_write_data(regs,chan,val) { \
122 scc_set_datum(regs, ((chan)<<1)+SCC_DATA_OFFSET,val); \
123 }
124
125
126 /*
127 * Addressable registers
128 */
129
130 #define SCC_RR0 0 /* status register */
131 #define SCC_RR1 1 /* special receive conditions */
132 #define SCC_RR2 2 /* (modified) interrupt vector */
133 #define SCC_RR3 3 /* interrupts pending (cha A only) */
134 #define SCC_RR8 8 /* recv buffer (alias for data) */
135 #define SCC_RR10 10 /* sdlc status */
136 #define SCC_RR12 12 /* BRG constant, low part */
137 #define SCC_RR13 13 /* BRG constant, high part */
138 #define SCC_RR15 15 /* interrupts currently enabled */
139
140 #define SCC_WR0 0 /* reg select, and commands */
141 #define SCC_WR1 1 /* interrupt and DMA enables */
142 #define SCC_WR2 2 /* interrupt vector */
143 #define SCC_WR3 3 /* receiver params and enables */
144 #define SCC_WR4 4 /* clock/char/parity params */
145 #define SCC_WR5 5 /* xmit params and enables */
146 #define SCC_WR6 6 /* synchr SYNCH/address */
147 #define SCC_WR7 7 /* synchr SYNCH/flag */
148 #define SCC_WR8 8 /* xmit buffer (alias for data) */
149 #define SCC_WR9 9 /* vectoring and resets */
150 #define SCC_WR10 10 /* synchr params */
151 #define SCC_WR11 11 /* clocking definitions */
152 #define SCC_WR12 12 /* BRG constant, low part */
153 #define SCC_WR13 13 /* BRG constant, high part */
154 #define SCC_WR14 14 /* BRG enables and commands */
155 #define SCC_WR15 15 /* interrupt enables */
156
157 /*
158 * Read registers defines
159 */
160
161 #define SCC_RR0_BREAK 0x80 /* break detected (rings twice), or */
162 #define SCC_RR0_ABORT 0x80 /* abort (synchr) */
163 #define SCC_RR0_TX_UNDERRUN 0x40 /* xmit buffer empty/end of message */
164 #define SCC_RR0_CTS 0x20 /* clear-to-send pin active (sampled
165 only on intr and after RESI cmd */
166 #define SCC_RR0_SYNCH 0x10 /* SYNCH found/still hunting */
167 #define SCC_RR0_DCD 0x08 /* carrier-detect (same as CTS) */
168 #define SCC_RR0_TX_EMPTY 0x04 /* xmit buffer empty */
169 #define SCC_RR0_ZERO_COUNT 0x02 /* ? */
170 #define SCC_RR0_RX_AVAIL 0x01 /* recv fifo not empty */
171
172 #define SCC_RR1_EOF 0x80 /* end-of-frame, SDLC mode */
173 #define SCC_RR1_CRC_ERR 0x40 /* incorrect CRC or.. */
174 #define SCC_RR1_FRAME_ERR 0x40 /* ..bad frame */
175 #define SCC_RR1_RX_OVERRUN 0x20 /* rcv fifo overflow */
176 #define SCC_RR1_PARITY_ERR 0x10 /* incorrect parity in data */
177 #define SCC_RR1_RESIDUE0 0x08
178 #define SCC_RR1_RESIDUE1 0x04
179 #define SCC_RR1_RESIDUE2 0x02
180 #define SCC_RR1_ALL_SENT 0x01
181
182 /* RR2 contains the interrupt vector unmodified (channel A) or
183 modified as follows (channel B, if vector-include-status) */
184
185 #define SCC_RR2_STATUS(val) ((val)&0xe) /* 11/7/95 used to be 0xf */
186
187 #define SCC_RR2_B_XMIT_DONE 0x0
188 #define SCC_RR2_B_EXT_STATUS 0x2
189 #define SCC_RR2_B_RECV_DONE 0x4
190 #define SCC_RR2_B_RECV_SPECIAL 0x6
191 #define SCC_RR2_A_XMIT_DONE 0x8
192 #define SCC_RR2_A_EXT_STATUS 0xa
193 #define SCC_RR2_A_RECV_DONE 0xc
194 #define SCC_RR2_A_RECV_SPECIAL 0xe
195
196 /* Interrupts pending, to be read from channel A only (B raz) */
197 #define SCC_RR3_zero 0xc0
198 #define SCC_RR3_RX_IP_A 0x20
199 #define SCC_RR3_TX_IP_A 0x10
200 #define SCC_RR3_EXT_IP_A 0x08
201 #define SCC_RR3_RX_IP_B 0x04
202 #define SCC_RR3_TX_IP_B 0x02
203 #define SCC_RR3_EXT_IP_B 0x01
204
205 /* RR8 is the receive data buffer, a 3 deep FIFO */
206 #define SCC_RECV_BUFFER SCC_RR8
207 #define SCC_RECV_FIFO_DEEP 3
208
209 #define SCC_RR10_1CLKS 0x80
210 #define SCC_RR10_2CLKS 0x40
211 #define SCC_RR10_zero 0x2d
212 #define SCC_RR10_LOOP_SND 0x10
213 #define SCC_RR10_ON_LOOP 0x02
214
215 /* RR12/RR13 hold the timing base, upper byte in RR13 */
216
217 #define scc_get_timing_base(scc,chan,val) { \
218 register char tmp; \
219 scc_read_reg(scc,chan,SCC_RR12,val);\
220 scc_read_reg(scc,chan,SCC_RR13,tmp);\
221 (val) = ((val)<<8)|(tmp&0xff);\
222 }
223
224 #define SCC_RR15_BREAK_IE 0x80
225 #define SCC_RR15_TX_UNDERRUN_IE 0x40
226 #define SCC_RR15_CTS_IE 0x20
227 #define SCC_RR15_SYNCH_IE 0x10
228 #define SCC_RR15_DCD_IE 0x08
229 #define SCC_RR15_zero 0x05
230 #define SCC_RR15_ZERO_COUNT_IE 0x02
231
232
233 /*
234 * Write registers defines
235 */
236
237 /* WR0 is used for commands too */
238 #define SCC_RESET_TXURUN_LATCH 0xc0
239 #define SCC_RESET_TX_CRC 0x80
240 #define SCC_RESET_RX_CRC 0x40
241 #define SCC_RESET_HIGHEST_IUS 0x38 /* channel A only */
242 #define SCC_RESET_ERROR 0x30
243 #define SCC_RESET_TX_IP 0x28
244 #define SCC_IE_NEXT_CHAR 0x20
245 #define SCC_SEND_SDLC_ABORT 0x18
246 #define SCC_RESET_EXT_IP 0x10
247
248 #define SCC_WR1_DMA_ENABLE 0x80 /* dma control */
249 #define SCC_WR1_DMA_MODE 0x40 /* drive ~req for DMA controller */
250 #define SCC_WR1_DMA_RECV_DATA 0x20 /* from wire to host memory */
251 /* interrupt enable/conditions */
252 #define SCC_WR1_RXI_SPECIAL_O 0x18 /* on special only */
253 #define SCC_WR1_RXI_ALL_CHAR 0x10 /* on each char, or special */
254 #define SCC_WR1_RXI_FIRST_CHAR 0x08 /* on first char, or special */
255 #define SCC_WR1_RXI_DISABLE 0x00 /* never on recv */
256 #define SCC_WR1_PARITY_IE 0x04 /* on parity errors */
257 #define SCC_WR1_TX_IE 0x02
258 #define SCC_WR1_EXT_IE 0x01
259
260 /* WR2 is common and contains the interrupt vector (high nibble) */
261
262 #define SCC_WR3_RX_8_BITS 0xc0
263 #define SCC_WR3_RX_6_BITS 0x80
264 #define SCC_WR3_RX_7_BITS 0x40
265 #define SCC_WR3_RX_5_BITS 0x00
266 #define SCC_WR3_AUTO_ENABLE 0x20
267 #define SCC_WR3_HUNT_MODE 0x10
268 #define SCC_WR3_RX_CRC_ENABLE 0x08
269 #define SCC_WR3_SDLC_SRCH 0x04
270 #define SCC_WR3_INHIBIT_SYNCH 0x02
271 #define SCC_WR3_RX_ENABLE 0x01
272
273 /* Should be re-written after reset */
274 #define SCC_WR4_CLK_x64 0xc0 /* clock divide factor */
275 #define SCC_WR4_CLK_x32 0x80
276 #define SCC_WR4_CLK_x16 0x40
277 #define SCC_WR4_CLK_x1 0x00
278 #define SCC_WR4_EXT_SYNCH_MODE 0x30 /* synch modes */
279 #define SCC_WR4_SDLC_MODE 0x20
280 #define SCC_WR4_16BIT_SYNCH 0x10
281 #define SCC_WR4_8BIT_SYNCH 0x00
282 #define SCC_WR4_2_STOP 0x0c /* asynch modes */
283 #define SCC_WR4_1_5_STOP 0x08
284 #define SCC_WR4_1_STOP 0x04
285 #define SCC_WR4_SYNCH_MODE 0x00
286 #define SCC_WR4_EVEN_PARITY 0x02
287 #define SCC_WR4_PARITY_ENABLE 0x01
288
289 #define SCC_WR5_DTR 0x80 /* drive DTR pin */
290 #define SCC_WR5_TX_8_BITS 0x60
291 #define SCC_WR5_TX_6_BITS 0x40
292 #define SCC_WR5_TX_7_BITS 0x20
293 #define SCC_WR5_TX_5_BITS 0x00
294 #define SCC_WR5_SEND_BREAK 0x10
295 #define SCC_WR5_TX_ENABLE 0x08
296 #define SCC_WR5_CRC_16 0x04 /* CRC if non zero, .. */
297 #define SCC_WR5_SDLC 0x00 /* ..SDLC otherwise */
298 #define SCC_WR5_RTS 0x02 /* drive RTS pin */
299 #define SCC_WR5_TX_CRC_ENABLE 0x01
300
301 /* Registers WR6 and WR7 are for synch modes data, with among other things: */
302
303 #define SCC_WR6_BISYNCH_12 0x0f
304 #define SCC_WR6_SDLC_RANGE_MASK 0x0f
305 #define SCC_WR7_SDLC_FLAG 0x7e
306
307 /* Register WR7' (prime) controls some ESCC features */
308 #define SCC_WR7P_RX_FIFO 0x08 /* Enable interrupt on FIFO 1/2 full */
309
310 /* WR8 is the transmit data buffer (no FIFO) */
311 #define SCC_XMT_BUFFER SCC_WR8
312
313 #define SCC_WR9_HW_RESET 0xc0 /* force hardware reset */
314 #define SCC_WR9_RESET_CHA_A 0x80
315 #define SCC_WR9_RESET_CHA_B 0x40
316 #define SCC_WR9_NON_VECTORED 0x20 /* mbz for Zilog chip */
317 #define SCC_WR9_STATUS_HIGH 0x10
318 #define SCC_WR9_MASTER_IE 0x08
319 #define SCC_WR9_DLC 0x04 /* disable-lower-chain */
320 #define SCC_WR9_NV 0x02 /* no vector */
321 #define SCC_WR9_VIS 0x01 /* vector-includes-status */
322
323 #define SCC_WR10_CRC_PRESET 0x80
324 #define SCC_WR10_FM0 0x60
325 #define SCC_WR10_FM1 0x40
326 #define SCC_WR10_NRZI 0x20
327 #define SCC_WR10_NRZ 0x00
328 #define SCC_WR10_ACTIVE_ON_POLL 0x10
329 #define SCC_WR10_MARK_IDLE 0x08 /* flag if zero */
330 #define SCC_WR10_ABORT_ON_URUN 0x04 /* flag if zero */
331 #define SCC_WR10_LOOP_MODE 0x02
332 #define SCC_WR10_6BIT_SYNCH 0x01
333 #define SCC_WR10_8BIT_SYNCH 0x00
334
335 #define SCC_WR11_RTxC_XTAL 0x80 /* RTxC pin is input (ext oscill) */
336 #define SCC_WR11_RCLK_DPLL 0x60 /* clock received data on dpll */
337 #define SCC_WR11_RCLK_BAUDR 0x40 /* .. on BRG */
338 #define SCC_WR11_RCLK_TRc_PIN 0x20 /* .. on TRxC pin */
339 #define SCC_WR11_RCLK_RTc_PIN 0x00 /* .. on RTxC pin */
340 #define SCC_WR11_XTLK_DPLL 0x18
341 #define SCC_WR11_XTLK_BAUDR 0x10
342 #define SCC_WR11_XTLK_TRc_PIN 0x08
343 #define SCC_WR11_XTLK_RTc_PIN 0x00
344 #define SCC_WR11_TRc_OUT 0x04 /* drive TRxC pin as output from..*/
345 #define SCC_WR11_TRcOUT_DPLL 0x03 /* .. the dpll */
346 #define SCC_WR11_TRcOUT_BAUDR 0x02 /* .. the BRG */
347 #define SCC_WR11_TRcOUT_XMTCLK 0x01 /* .. the xmit clock */
348 #define SCC_WR11_TRcOUT_XTAL 0x00 /* .. the external oscillator */
349
350 /* WR12/WR13 are for timing base preset */
351 #define scc_set_timing_base(scc,chan,val) { \
352 scc_write_reg(scc,chan,SCC_RR12,val);\
353 scc_write_reg(scc,chan,SCC_RR13,(val)>>8);\
354 }
355
356 /* More commands in this register */
357 #define SCC_WR14_NRZI_MODE 0xe0 /* synch modulations */
358 #define SCC_WR14_FM_MODE 0xc0
359 #define SCC_WR14_RTc_SOURCE 0xa0 /* clock is from pin .. */
360 #define SCC_WR14_BAUDR_SOURCE 0x80 /* .. or internal BRG */
361 #define SCC_WR14_DISABLE_DPLL 0x60
362 #define SCC_WR14_RESET_CLKMISS 0x40
363 #define SCC_WR14_SEARCH_MODE 0x20
364 /* ..and more bitsy */
365 #define SCC_WR14_LOCAL_LOOPB 0x10
366 #define SCC_WR14_AUTO_ECHO 0x08
367 #define SCC_WR14_DTR_REQUEST 0x04
368 #define SCC_WR14_BAUDR_SRC 0x02
369 #define SCC_WR14_BAUDR_ENABLE 0x01
370
371 #define SCC_WR15_BREAK_IE 0x80
372 #define SCC_WR15_TX_UNDERRUN_IE 0x40
373 #define SCC_WR15_CTS_IE 0x20
374 #define SCC_WR15_SYNCHUNT_IE 0x10
375 #define SCC_WR15_DCD_IE 0x08
376 #define SCC_WR15_zero 0x05
377 #define SCC_WR15_ZERO_COUNT_IE 0x02
378 #define SCC_WR15_ENABLE_ESCC 0x01 /* Enable some ESCC registers */
379
380 #define NSCC_LINE 2 /* How many lines are support per 8530 */
381 /*
382 * Driver status
383 */
384
385 #define SCC_FLAGS_DMA_PAUSED 0x00001 /* DMA has been paused because of XON/XOFF */
386 #define SCC_FLAGS_DMA_TX_BUSY 0x00002 /* On going DMA operation.. */
387
388 struct scc_softreg {
389 unsigned char wr1;
390 unsigned char wr4;
391 unsigned char wr5;
392 unsigned char wr14;
393
394 unsigned long speed;
395 unsigned long flags;
396 unsigned long dma_flags;
397 };
398
399
400 struct scc_softc {
401 scc_regmap_t regs;
402 struct scc_dma_ops *dma_ops;
403
404 /* software copy of some write regs, for reg |= */
405 struct scc_softreg softr[NSCC_LINE];
406
407 int flags;
408 int modem[NSCC_LINE]; /* Mach modem bits (TM_DTR etc). */
409 int dcd_timer[NSCC_LINE];
410 int dma_initted;
411
412 char polling_mode;
413 char probed_once;
414
415 boolean_t full_modem;
416 };
417
418 #define DCD_TIMEOUT 4
419
420 typedef struct scc_softc *scc_softc_t;
421 extern struct scc_softc scc_softc[];
422
423 #endif /*_SCC_8530_H_*/