blob: 97575219ea8b1a02ebd63bc2da6597df780956ba [file] [log] [blame]
Kumar Gala33d71d22007-08-20 08:50:28 -05001/*
2 * MPC8xx Communication Processor Module.
3 * Copyright (c) 1997 Dan Malek (dmalek@jlc.net)
4 *
5 * This file contains structures and information for the communication
6 * processor channels. Some CPM control and status is available
7 * throught the MPC8xx internal memory map. See immap.h for details.
8 * This file only contains what I need for the moment, not the total
9 * CPM capabilities. I (or someone else) will add definitions as they
10 * are needed. -- Dan
11 *
12 * On the MBX board, EPPC-Bug loads CPM microcode into the first 512
13 * bytes of the DP RAM and relocates the I2C parameter area to the
14 * IDMA1 space. The remaining DP RAM is available for buffer descriptors
15 * or other use.
16 */
17#ifndef __CPM_8XX__
18#define __CPM_8XX__
19
20#include <asm/8xx_immap.h>
21#include <asm/ptrace.h>
Scott Wood15f8c602007-09-28 14:06:16 -050022#include <asm/cpm.h>
Kumar Gala33d71d22007-08-20 08:50:28 -050023
24/* CPM Command register.
25*/
26#define CPM_CR_RST ((ushort)0x8000)
27#define CPM_CR_OPCODE ((ushort)0x0f00)
28#define CPM_CR_CHAN ((ushort)0x00f0)
29#define CPM_CR_FLG ((ushort)0x0001)
30
31/* Some commands (there are more...later)
32*/
33#define CPM_CR_INIT_TRX ((ushort)0x0000)
34#define CPM_CR_INIT_RX ((ushort)0x0001)
35#define CPM_CR_INIT_TX ((ushort)0x0002)
36#define CPM_CR_HUNT_MODE ((ushort)0x0003)
37#define CPM_CR_STOP_TX ((ushort)0x0004)
38#define CPM_CR_GRA_STOP_TX ((ushort)0x0005)
39#define CPM_CR_RESTART_TX ((ushort)0x0006)
40#define CPM_CR_CLOSE_RX_BD ((ushort)0x0007)
41#define CPM_CR_SET_GADDR ((ushort)0x0008)
42#define CPM_CR_SET_TIMER CPM_CR_SET_GADDR
43
44/* Channel numbers.
45*/
46#define CPM_CR_CH_SCC1 ((ushort)0x0000)
47#define CPM_CR_CH_I2C ((ushort)0x0001) /* I2C and IDMA1 */
48#define CPM_CR_CH_SCC2 ((ushort)0x0004)
49#define CPM_CR_CH_SPI ((ushort)0x0005) /* SPI / IDMA2 / Timers */
50#define CPM_CR_CH_TIMER CPM_CR_CH_SPI
51#define CPM_CR_CH_SCC3 ((ushort)0x0008)
52#define CPM_CR_CH_SMC1 ((ushort)0x0009) /* SMC1 / DSP1 */
53#define CPM_CR_CH_SCC4 ((ushort)0x000c)
54#define CPM_CR_CH_SMC2 ((ushort)0x000d) /* SMC2 / DSP2 */
55
56#define mk_cr_cmd(CH, CMD) ((CMD << 8) | (CH << 4))
57
Scott Wood15f8c602007-09-28 14:06:16 -050058#ifndef CONFIG_PPC_CPM_NEW_BINDING
Kumar Gala33d71d22007-08-20 08:50:28 -050059/* The dual ported RAM is multi-functional. Some areas can be (and are
60 * being) used for microcode. There is an area that can only be used
61 * as data ram for buffer descriptors, which is all we use right now.
62 * Currently the first 512 and last 256 bytes are used for microcode.
63 */
64#define CPM_DATAONLY_BASE ((uint)0x0800)
65#define CPM_DATAONLY_SIZE ((uint)0x0700)
66#define CPM_DP_NOSPACE ((uint)0x7fffffff)
Scott Wood15f8c602007-09-28 14:06:16 -050067#endif
Kumar Gala33d71d22007-08-20 08:50:28 -050068
69/* Export the base address of the communication processor registers
70 * and dual port ram.
71 */
Scott Woodfb533d02007-09-14 14:22:36 -050072extern cpm8xx_t __iomem *cpmp; /* Pointer to comm processor */
Scott Wood15f8c602007-09-28 14:06:16 -050073
74#ifdef CONFIG_PPC_CPM_NEW_BINDING
75#define cpm_dpalloc cpm_muram_alloc
76#define cpm_dpfree cpm_muram_free
77#define cpm_dpram_addr cpm_muram_addr
78#define cpm_dpram_phys cpm_muram_dma
79#else
Kumar Gala33d71d22007-08-20 08:50:28 -050080extern unsigned long cpm_dpalloc(uint size, uint align);
81extern int cpm_dpfree(unsigned long offset);
82extern unsigned long cpm_dpalloc_fixed(unsigned long offset, uint size, uint align);
83extern void cpm_dpdump(void);
84extern void *cpm_dpram_addr(unsigned long offset);
85extern uint cpm_dpram_phys(u8* addr);
Scott Wood15f8c602007-09-28 14:06:16 -050086#endif
87
Kumar Gala33d71d22007-08-20 08:50:28 -050088extern void cpm_setbrg(uint brg, uint rate);
89
Kamalesh Babulal4d208262007-11-05 16:11:12 +053090extern void cpm_load_patch(cpm8xx_t *cp);
Kumar Gala33d71d22007-08-20 08:50:28 -050091
92/* Buffer descriptors used by many of the CPM protocols.
93*/
94typedef struct cpm_buf_desc {
95 ushort cbd_sc; /* Status and Control */
96 ushort cbd_datlen; /* Data length in buffer */
97 uint cbd_bufaddr; /* Buffer address in host memory */
98} cbd_t;
99
100#define BD_SC_EMPTY ((ushort)0x8000) /* Receive is empty */
101#define BD_SC_READY ((ushort)0x8000) /* Transmit is ready */
102#define BD_SC_WRAP ((ushort)0x2000) /* Last buffer descriptor */
103#define BD_SC_INTRPT ((ushort)0x1000) /* Interrupt on change */
104#define BD_SC_LAST ((ushort)0x0800) /* Last buffer in frame */
105#define BD_SC_TC ((ushort)0x0400) /* Transmit CRC */
106#define BD_SC_CM ((ushort)0x0200) /* Continous mode */
107#define BD_SC_ID ((ushort)0x0100) /* Rec'd too many idles */
108#define BD_SC_P ((ushort)0x0100) /* xmt preamble */
109#define BD_SC_BR ((ushort)0x0020) /* Break received */
110#define BD_SC_FR ((ushort)0x0010) /* Framing error */
111#define BD_SC_PR ((ushort)0x0008) /* Parity error */
112#define BD_SC_NAK ((ushort)0x0004) /* NAK - did not respond */
113#define BD_SC_OV ((ushort)0x0002) /* Overrun */
114#define BD_SC_UN ((ushort)0x0002) /* Underrun */
115#define BD_SC_CD ((ushort)0x0001) /* ?? */
116#define BD_SC_CL ((ushort)0x0001) /* Collision */
117
118/* Parameter RAM offsets.
119*/
120#define PROFF_SCC1 ((uint)0x0000)
121#define PROFF_IIC ((uint)0x0080)
122#define PROFF_SCC2 ((uint)0x0100)
123#define PROFF_SPI ((uint)0x0180)
124#define PROFF_SCC3 ((uint)0x0200)
125#define PROFF_SMC1 ((uint)0x0280)
126#define PROFF_SCC4 ((uint)0x0300)
127#define PROFF_SMC2 ((uint)0x0380)
128
129/* Define enough so I can at least use the serial port as a UART.
130 * The MBX uses SMC1 as the host serial port.
131 */
132typedef struct smc_uart {
133 ushort smc_rbase; /* Rx Buffer descriptor base address */
134 ushort smc_tbase; /* Tx Buffer descriptor base address */
135 u_char smc_rfcr; /* Rx function code */
136 u_char smc_tfcr; /* Tx function code */
137 ushort smc_mrblr; /* Max receive buffer length */
138 uint smc_rstate; /* Internal */
139 uint smc_idp; /* Internal */
140 ushort smc_rbptr; /* Internal */
141 ushort smc_ibc; /* Internal */
142 uint smc_rxtmp; /* Internal */
143 uint smc_tstate; /* Internal */
144 uint smc_tdp; /* Internal */
145 ushort smc_tbptr; /* Internal */
146 ushort smc_tbc; /* Internal */
147 uint smc_txtmp; /* Internal */
148 ushort smc_maxidl; /* Maximum idle characters */
149 ushort smc_tmpidl; /* Temporary idle counter */
150 ushort smc_brklen; /* Last received break length */
151 ushort smc_brkec; /* rcv'd break condition counter */
152 ushort smc_brkcr; /* xmt break count register */
153 ushort smc_rmask; /* Temporary bit mask */
154 char res1[8]; /* Reserved */
155 ushort smc_rpbase; /* Relocation pointer */
156} smc_uart_t;
157
158/* Function code bits.
159*/
160#define SMC_EB ((u_char)0x10) /* Set big endian byte order */
161
162/* SMC uart mode register.
163*/
164#define SMCMR_REN ((ushort)0x0001)
165#define SMCMR_TEN ((ushort)0x0002)
166#define SMCMR_DM ((ushort)0x000c)
167#define SMCMR_SM_GCI ((ushort)0x0000)
168#define SMCMR_SM_UART ((ushort)0x0020)
169#define SMCMR_SM_TRANS ((ushort)0x0030)
170#define SMCMR_SM_MASK ((ushort)0x0030)
171#define SMCMR_PM_EVEN ((ushort)0x0100) /* Even parity, else odd */
172#define SMCMR_REVD SMCMR_PM_EVEN
173#define SMCMR_PEN ((ushort)0x0200) /* Parity enable */
174#define SMCMR_BS SMCMR_PEN
175#define SMCMR_SL ((ushort)0x0400) /* Two stops, else one */
176#define SMCR_CLEN_MASK ((ushort)0x7800) /* Character length */
177#define smcr_mk_clen(C) (((C) << 11) & SMCR_CLEN_MASK)
178
179/* SMC2 as Centronics parallel printer. It is half duplex, in that
180 * it can only receive or transmit. The parameter ram values for
181 * each direction are either unique or properly overlap, so we can
182 * include them in one structure.
183 */
184typedef struct smc_centronics {
185 ushort scent_rbase;
186 ushort scent_tbase;
187 u_char scent_cfcr;
188 u_char scent_smask;
189 ushort scent_mrblr;
190 uint scent_rstate;
191 uint scent_r_ptr;
192 ushort scent_rbptr;
193 ushort scent_r_cnt;
194 uint scent_rtemp;
195 uint scent_tstate;
196 uint scent_t_ptr;
197 ushort scent_tbptr;
198 ushort scent_t_cnt;
199 uint scent_ttemp;
200 ushort scent_max_sl;
201 ushort scent_sl_cnt;
202 ushort scent_character1;
203 ushort scent_character2;
204 ushort scent_character3;
205 ushort scent_character4;
206 ushort scent_character5;
207 ushort scent_character6;
208 ushort scent_character7;
209 ushort scent_character8;
210 ushort scent_rccm;
211 ushort scent_rccr;
212} smc_cent_t;
213
214/* Centronics Status Mask Register.
215*/
216#define SMC_CENT_F ((u_char)0x08)
217#define SMC_CENT_PE ((u_char)0x04)
218#define SMC_CENT_S ((u_char)0x02)
219
220/* SMC Event and Mask register.
221*/
222#define SMCM_BRKE ((unsigned char)0x40) /* When in UART Mode */
223#define SMCM_BRK ((unsigned char)0x10) /* When in UART Mode */
224#define SMCM_TXE ((unsigned char)0x10) /* When in Transparent Mode */
225#define SMCM_BSY ((unsigned char)0x04)
226#define SMCM_TX ((unsigned char)0x02)
227#define SMCM_RX ((unsigned char)0x01)
228
229/* Baud rate generators.
230*/
231#define CPM_BRG_RST ((uint)0x00020000)
232#define CPM_BRG_EN ((uint)0x00010000)
233#define CPM_BRG_EXTC_INT ((uint)0x00000000)
234#define CPM_BRG_EXTC_CLK2 ((uint)0x00004000)
235#define CPM_BRG_EXTC_CLK6 ((uint)0x00008000)
236#define CPM_BRG_ATB ((uint)0x00002000)
237#define CPM_BRG_CD_MASK ((uint)0x00001ffe)
238#define CPM_BRG_DIV16 ((uint)0x00000001)
239
240/* SI Clock Route Register
241*/
242#define SICR_RCLK_SCC1_BRG1 ((uint)0x00000000)
243#define SICR_TCLK_SCC1_BRG1 ((uint)0x00000000)
244#define SICR_RCLK_SCC2_BRG2 ((uint)0x00000800)
245#define SICR_TCLK_SCC2_BRG2 ((uint)0x00000100)
246#define SICR_RCLK_SCC3_BRG3 ((uint)0x00100000)
247#define SICR_TCLK_SCC3_BRG3 ((uint)0x00020000)
248#define SICR_RCLK_SCC4_BRG4 ((uint)0x18000000)
249#define SICR_TCLK_SCC4_BRG4 ((uint)0x03000000)
250
251/* SCCs.
252*/
253#define SCC_GSMRH_IRP ((uint)0x00040000)
254#define SCC_GSMRH_GDE ((uint)0x00010000)
255#define SCC_GSMRH_TCRC_CCITT ((uint)0x00008000)
256#define SCC_GSMRH_TCRC_BISYNC ((uint)0x00004000)
257#define SCC_GSMRH_TCRC_HDLC ((uint)0x00000000)
258#define SCC_GSMRH_REVD ((uint)0x00002000)
259#define SCC_GSMRH_TRX ((uint)0x00001000)
260#define SCC_GSMRH_TTX ((uint)0x00000800)
261#define SCC_GSMRH_CDP ((uint)0x00000400)
262#define SCC_GSMRH_CTSP ((uint)0x00000200)
263#define SCC_GSMRH_CDS ((uint)0x00000100)
264#define SCC_GSMRH_CTSS ((uint)0x00000080)
265#define SCC_GSMRH_TFL ((uint)0x00000040)
266#define SCC_GSMRH_RFW ((uint)0x00000020)
267#define SCC_GSMRH_TXSY ((uint)0x00000010)
268#define SCC_GSMRH_SYNL16 ((uint)0x0000000c)
269#define SCC_GSMRH_SYNL8 ((uint)0x00000008)
270#define SCC_GSMRH_SYNL4 ((uint)0x00000004)
271#define SCC_GSMRH_RTSM ((uint)0x00000002)
272#define SCC_GSMRH_RSYN ((uint)0x00000001)
273
274#define SCC_GSMRL_SIR ((uint)0x80000000) /* SCC2 only */
275#define SCC_GSMRL_EDGE_NONE ((uint)0x60000000)
276#define SCC_GSMRL_EDGE_NEG ((uint)0x40000000)
277#define SCC_GSMRL_EDGE_POS ((uint)0x20000000)
278#define SCC_GSMRL_EDGE_BOTH ((uint)0x00000000)
279#define SCC_GSMRL_TCI ((uint)0x10000000)
280#define SCC_GSMRL_TSNC_3 ((uint)0x0c000000)
281#define SCC_GSMRL_TSNC_4 ((uint)0x08000000)
282#define SCC_GSMRL_TSNC_14 ((uint)0x04000000)
283#define SCC_GSMRL_TSNC_INF ((uint)0x00000000)
284#define SCC_GSMRL_RINV ((uint)0x02000000)
285#define SCC_GSMRL_TINV ((uint)0x01000000)
286#define SCC_GSMRL_TPL_128 ((uint)0x00c00000)
287#define SCC_GSMRL_TPL_64 ((uint)0x00a00000)
288#define SCC_GSMRL_TPL_48 ((uint)0x00800000)
289#define SCC_GSMRL_TPL_32 ((uint)0x00600000)
290#define SCC_GSMRL_TPL_16 ((uint)0x00400000)
291#define SCC_GSMRL_TPL_8 ((uint)0x00200000)
292#define SCC_GSMRL_TPL_NONE ((uint)0x00000000)
293#define SCC_GSMRL_TPP_ALL1 ((uint)0x00180000)
294#define SCC_GSMRL_TPP_01 ((uint)0x00100000)
295#define SCC_GSMRL_TPP_10 ((uint)0x00080000)
296#define SCC_GSMRL_TPP_ZEROS ((uint)0x00000000)
297#define SCC_GSMRL_TEND ((uint)0x00040000)
298#define SCC_GSMRL_TDCR_32 ((uint)0x00030000)
299#define SCC_GSMRL_TDCR_16 ((uint)0x00020000)
300#define SCC_GSMRL_TDCR_8 ((uint)0x00010000)
301#define SCC_GSMRL_TDCR_1 ((uint)0x00000000)
302#define SCC_GSMRL_RDCR_32 ((uint)0x0000c000)
303#define SCC_GSMRL_RDCR_16 ((uint)0x00008000)
304#define SCC_GSMRL_RDCR_8 ((uint)0x00004000)
305#define SCC_GSMRL_RDCR_1 ((uint)0x00000000)
306#define SCC_GSMRL_RENC_DFMAN ((uint)0x00003000)
307#define SCC_GSMRL_RENC_MANCH ((uint)0x00002000)
308#define SCC_GSMRL_RENC_FM0 ((uint)0x00001000)
309#define SCC_GSMRL_RENC_NRZI ((uint)0x00000800)
310#define SCC_GSMRL_RENC_NRZ ((uint)0x00000000)
311#define SCC_GSMRL_TENC_DFMAN ((uint)0x00000600)
312#define SCC_GSMRL_TENC_MANCH ((uint)0x00000400)
313#define SCC_GSMRL_TENC_FM0 ((uint)0x00000200)
314#define SCC_GSMRL_TENC_NRZI ((uint)0x00000100)
315#define SCC_GSMRL_TENC_NRZ ((uint)0x00000000)
316#define SCC_GSMRL_DIAG_LE ((uint)0x000000c0) /* Loop and echo */
317#define SCC_GSMRL_DIAG_ECHO ((uint)0x00000080)
318#define SCC_GSMRL_DIAG_LOOP ((uint)0x00000040)
319#define SCC_GSMRL_DIAG_NORM ((uint)0x00000000)
320#define SCC_GSMRL_ENR ((uint)0x00000020)
321#define SCC_GSMRL_ENT ((uint)0x00000010)
322#define SCC_GSMRL_MODE_ENET ((uint)0x0000000c)
323#define SCC_GSMRL_MODE_QMC ((uint)0x0000000a)
324#define SCC_GSMRL_MODE_DDCMP ((uint)0x00000009)
325#define SCC_GSMRL_MODE_BISYNC ((uint)0x00000008)
326#define SCC_GSMRL_MODE_V14 ((uint)0x00000007)
327#define SCC_GSMRL_MODE_AHDLC ((uint)0x00000006)
328#define SCC_GSMRL_MODE_PROFIBUS ((uint)0x00000005)
329#define SCC_GSMRL_MODE_UART ((uint)0x00000004)
330#define SCC_GSMRL_MODE_SS7 ((uint)0x00000003)
331#define SCC_GSMRL_MODE_ATALK ((uint)0x00000002)
332#define SCC_GSMRL_MODE_HDLC ((uint)0x00000000)
333
334#define SCC_TODR_TOD ((ushort)0x8000)
335
336/* SCC Event and Mask register.
337*/
338#define SCCM_TXE ((unsigned char)0x10)
339#define SCCM_BSY ((unsigned char)0x04)
340#define SCCM_TX ((unsigned char)0x02)
341#define SCCM_RX ((unsigned char)0x01)
342
343typedef struct scc_param {
344 ushort scc_rbase; /* Rx Buffer descriptor base address */
345 ushort scc_tbase; /* Tx Buffer descriptor base address */
346 u_char scc_rfcr; /* Rx function code */
347 u_char scc_tfcr; /* Tx function code */
348 ushort scc_mrblr; /* Max receive buffer length */
349 uint scc_rstate; /* Internal */
350 uint scc_idp; /* Internal */
351 ushort scc_rbptr; /* Internal */
352 ushort scc_ibc; /* Internal */
353 uint scc_rxtmp; /* Internal */
354 uint scc_tstate; /* Internal */
355 uint scc_tdp; /* Internal */
356 ushort scc_tbptr; /* Internal */
357 ushort scc_tbc; /* Internal */
358 uint scc_txtmp; /* Internal */
359 uint scc_rcrc; /* Internal */
360 uint scc_tcrc; /* Internal */
361} sccp_t;
362
363/* Function code bits.
364*/
365#define SCC_EB ((u_char)0x10) /* Set big endian byte order */
366
367/* CPM Ethernet through SCCx.
368 */
369typedef struct scc_enet {
370 sccp_t sen_genscc;
371 uint sen_cpres; /* Preset CRC */
372 uint sen_cmask; /* Constant mask for CRC */
373 uint sen_crcec; /* CRC Error counter */
374 uint sen_alec; /* alignment error counter */
375 uint sen_disfc; /* discard frame counter */
376 ushort sen_pads; /* Tx short frame pad character */
377 ushort sen_retlim; /* Retry limit threshold */
378 ushort sen_retcnt; /* Retry limit counter */
379 ushort sen_maxflr; /* maximum frame length register */
380 ushort sen_minflr; /* minimum frame length register */
381 ushort sen_maxd1; /* maximum DMA1 length */
382 ushort sen_maxd2; /* maximum DMA2 length */
383 ushort sen_maxd; /* Rx max DMA */
384 ushort sen_dmacnt; /* Rx DMA counter */
385 ushort sen_maxb; /* Max BD byte count */
386 ushort sen_gaddr1; /* Group address filter */
387 ushort sen_gaddr2;
388 ushort sen_gaddr3;
389 ushort sen_gaddr4;
390 uint sen_tbuf0data0; /* Save area 0 - current frame */
391 uint sen_tbuf0data1; /* Save area 1 - current frame */
392 uint sen_tbuf0rba; /* Internal */
393 uint sen_tbuf0crc; /* Internal */
394 ushort sen_tbuf0bcnt; /* Internal */
395 ushort sen_paddrh; /* physical address (MSB) */
396 ushort sen_paddrm;
397 ushort sen_paddrl; /* physical address (LSB) */
398 ushort sen_pper; /* persistence */
399 ushort sen_rfbdptr; /* Rx first BD pointer */
400 ushort sen_tfbdptr; /* Tx first BD pointer */
401 ushort sen_tlbdptr; /* Tx last BD pointer */
402 uint sen_tbuf1data0; /* Save area 0 - current frame */
403 uint sen_tbuf1data1; /* Save area 1 - current frame */
404 uint sen_tbuf1rba; /* Internal */
405 uint sen_tbuf1crc; /* Internal */
406 ushort sen_tbuf1bcnt; /* Internal */
407 ushort sen_txlen; /* Tx Frame length counter */
408 ushort sen_iaddr1; /* Individual address filter */
409 ushort sen_iaddr2;
410 ushort sen_iaddr3;
411 ushort sen_iaddr4;
412 ushort sen_boffcnt; /* Backoff counter */
413
414 /* NOTE: Some versions of the manual have the following items
415 * incorrectly documented. Below is the proper order.
416 */
417 ushort sen_taddrh; /* temp address (MSB) */
418 ushort sen_taddrm;
419 ushort sen_taddrl; /* temp address (LSB) */
420} scc_enet_t;
421
422/* SCC Event register as used by Ethernet.
423*/
424#define SCCE_ENET_GRA ((ushort)0x0080) /* Graceful stop complete */
425#define SCCE_ENET_TXE ((ushort)0x0010) /* Transmit Error */
426#define SCCE_ENET_RXF ((ushort)0x0008) /* Full frame received */
427#define SCCE_ENET_BSY ((ushort)0x0004) /* All incoming buffers full */
428#define SCCE_ENET_TXB ((ushort)0x0002) /* A buffer was transmitted */
429#define SCCE_ENET_RXB ((ushort)0x0001) /* A buffer was received */
430
431/* SCC Mode Register (PMSR) as used by Ethernet.
432*/
433#define SCC_PSMR_HBC ((ushort)0x8000) /* Enable heartbeat */
434#define SCC_PSMR_FC ((ushort)0x4000) /* Force collision */
435#define SCC_PSMR_RSH ((ushort)0x2000) /* Receive short frames */
436#define SCC_PSMR_IAM ((ushort)0x1000) /* Check individual hash */
437#define SCC_PSMR_ENCRC ((ushort)0x0800) /* Ethernet CRC mode */
438#define SCC_PSMR_PRO ((ushort)0x0200) /* Promiscuous mode */
439#define SCC_PSMR_BRO ((ushort)0x0100) /* Catch broadcast pkts */
440#define SCC_PSMR_SBT ((ushort)0x0080) /* Special backoff timer */
441#define SCC_PSMR_LPB ((ushort)0x0040) /* Set Loopback mode */
442#define SCC_PSMR_SIP ((ushort)0x0020) /* Sample Input Pins */
443#define SCC_PSMR_LCW ((ushort)0x0010) /* Late collision window */
444#define SCC_PSMR_NIB22 ((ushort)0x000a) /* Start frame search */
445#define SCC_PSMR_FDE ((ushort)0x0001) /* Full duplex enable */
446
447/* Buffer descriptor control/status used by Ethernet receive.
448*/
449#define BD_ENET_RX_EMPTY ((ushort)0x8000)
450#define BD_ENET_RX_WRAP ((ushort)0x2000)
451#define BD_ENET_RX_INTR ((ushort)0x1000)
452#define BD_ENET_RX_LAST ((ushort)0x0800)
453#define BD_ENET_RX_FIRST ((ushort)0x0400)
454#define BD_ENET_RX_MISS ((ushort)0x0100)
455#define BD_ENET_RX_LG ((ushort)0x0020)
456#define BD_ENET_RX_NO ((ushort)0x0010)
457#define BD_ENET_RX_SH ((ushort)0x0008)
458#define BD_ENET_RX_CR ((ushort)0x0004)
459#define BD_ENET_RX_OV ((ushort)0x0002)
460#define BD_ENET_RX_CL ((ushort)0x0001)
461#define BD_ENET_RX_BC ((ushort)0x0080) /* DA is Broadcast */
462#define BD_ENET_RX_MC ((ushort)0x0040) /* DA is Multicast */
463#define BD_ENET_RX_STATS ((ushort)0x013f) /* All status bits */
464
465/* Buffer descriptor control/status used by Ethernet transmit.
466*/
467#define BD_ENET_TX_READY ((ushort)0x8000)
468#define BD_ENET_TX_PAD ((ushort)0x4000)
469#define BD_ENET_TX_WRAP ((ushort)0x2000)
470#define BD_ENET_TX_INTR ((ushort)0x1000)
471#define BD_ENET_TX_LAST ((ushort)0x0800)
472#define BD_ENET_TX_TC ((ushort)0x0400)
473#define BD_ENET_TX_DEF ((ushort)0x0200)
474#define BD_ENET_TX_HB ((ushort)0x0100)
475#define BD_ENET_TX_LC ((ushort)0x0080)
476#define BD_ENET_TX_RL ((ushort)0x0040)
477#define BD_ENET_TX_RCMASK ((ushort)0x003c)
478#define BD_ENET_TX_UN ((ushort)0x0002)
479#define BD_ENET_TX_CSL ((ushort)0x0001)
480#define BD_ENET_TX_STATS ((ushort)0x03ff) /* All status bits */
481
482/* SCC as UART
483*/
484typedef struct scc_uart {
485 sccp_t scc_genscc;
486 char res1[8]; /* Reserved */
487 ushort scc_maxidl; /* Maximum idle chars */
488 ushort scc_idlc; /* temp idle counter */
489 ushort scc_brkcr; /* Break count register */
490 ushort scc_parec; /* receive parity error counter */
491 ushort scc_frmec; /* receive framing error counter */
492 ushort scc_nosec; /* receive noise counter */
493 ushort scc_brkec; /* receive break condition counter */
494 ushort scc_brkln; /* last received break length */
495 ushort scc_uaddr1; /* UART address character 1 */
496 ushort scc_uaddr2; /* UART address character 2 */
497 ushort scc_rtemp; /* Temp storage */
498 ushort scc_toseq; /* Transmit out of sequence char */
499 ushort scc_char1; /* control character 1 */
500 ushort scc_char2; /* control character 2 */
501 ushort scc_char3; /* control character 3 */
502 ushort scc_char4; /* control character 4 */
503 ushort scc_char5; /* control character 5 */
504 ushort scc_char6; /* control character 6 */
505 ushort scc_char7; /* control character 7 */
506 ushort scc_char8; /* control character 8 */
507 ushort scc_rccm; /* receive control character mask */
508 ushort scc_rccr; /* receive control character register */
509 ushort scc_rlbc; /* receive last break character */
510} scc_uart_t;
511
512/* SCC Event and Mask registers when it is used as a UART.
513*/
514#define UART_SCCM_GLR ((ushort)0x1000)
515#define UART_SCCM_GLT ((ushort)0x0800)
516#define UART_SCCM_AB ((ushort)0x0200)
517#define UART_SCCM_IDL ((ushort)0x0100)
518#define UART_SCCM_GRA ((ushort)0x0080)
519#define UART_SCCM_BRKE ((ushort)0x0040)
520#define UART_SCCM_BRKS ((ushort)0x0020)
521#define UART_SCCM_CCR ((ushort)0x0008)
522#define UART_SCCM_BSY ((ushort)0x0004)
523#define UART_SCCM_TX ((ushort)0x0002)
524#define UART_SCCM_RX ((ushort)0x0001)
525
526/* The SCC PMSR when used as a UART.
527*/
528#define SCU_PSMR_FLC ((ushort)0x8000)
529#define SCU_PSMR_SL ((ushort)0x4000)
530#define SCU_PSMR_CL ((ushort)0x3000)
531#define SCU_PSMR_UM ((ushort)0x0c00)
532#define SCU_PSMR_FRZ ((ushort)0x0200)
533#define SCU_PSMR_RZS ((ushort)0x0100)
534#define SCU_PSMR_SYN ((ushort)0x0080)
535#define SCU_PSMR_DRT ((ushort)0x0040)
536#define SCU_PSMR_PEN ((ushort)0x0010)
537#define SCU_PSMR_RPM ((ushort)0x000c)
538#define SCU_PSMR_REVP ((ushort)0x0008)
539#define SCU_PSMR_TPM ((ushort)0x0003)
540#define SCU_PSMR_TEVP ((ushort)0x0002)
541
542/* CPM Transparent mode SCC.
543 */
544typedef struct scc_trans {
545 sccp_t st_genscc;
546 uint st_cpres; /* Preset CRC */
547 uint st_cmask; /* Constant mask for CRC */
548} scc_trans_t;
549
550#define BD_SCC_TX_LAST ((ushort)0x0800)
551
552/* IIC parameter RAM.
553*/
554typedef struct iic {
555 ushort iic_rbase; /* Rx Buffer descriptor base address */
556 ushort iic_tbase; /* Tx Buffer descriptor base address */
557 u_char iic_rfcr; /* Rx function code */
558 u_char iic_tfcr; /* Tx function code */
559 ushort iic_mrblr; /* Max receive buffer length */
560 uint iic_rstate; /* Internal */
561 uint iic_rdp; /* Internal */
562 ushort iic_rbptr; /* Internal */
563 ushort iic_rbc; /* Internal */
564 uint iic_rxtmp; /* Internal */
565 uint iic_tstate; /* Internal */
566 uint iic_tdp; /* Internal */
567 ushort iic_tbptr; /* Internal */
568 ushort iic_tbc; /* Internal */
569 uint iic_txtmp; /* Internal */
570 char res1[4]; /* Reserved */
571 ushort iic_rpbase; /* Relocation pointer */
572 char res2[2]; /* Reserved */
573} iic_t;
574
575#define BD_IIC_START ((ushort)0x0400)
576
577/* SPI parameter RAM.
578*/
579typedef struct spi {
580 ushort spi_rbase; /* Rx Buffer descriptor base address */
581 ushort spi_tbase; /* Tx Buffer descriptor base address */
582 u_char spi_rfcr; /* Rx function code */
583 u_char spi_tfcr; /* Tx function code */
584 ushort spi_mrblr; /* Max receive buffer length */
585 uint spi_rstate; /* Internal */
586 uint spi_rdp; /* Internal */
587 ushort spi_rbptr; /* Internal */
588 ushort spi_rbc; /* Internal */
589 uint spi_rxtmp; /* Internal */
590 uint spi_tstate; /* Internal */
591 uint spi_tdp; /* Internal */
592 ushort spi_tbptr; /* Internal */
593 ushort spi_tbc; /* Internal */
594 uint spi_txtmp; /* Internal */
595 uint spi_res;
596 ushort spi_rpbase; /* Relocation pointer */
597 ushort spi_res2;
598} spi_t;
599
600/* SPI Mode register.
601*/
602#define SPMODE_LOOP ((ushort)0x4000) /* Loopback */
603#define SPMODE_CI ((ushort)0x2000) /* Clock Invert */
604#define SPMODE_CP ((ushort)0x1000) /* Clock Phase */
605#define SPMODE_DIV16 ((ushort)0x0800) /* BRG/16 mode */
606#define SPMODE_REV ((ushort)0x0400) /* Reversed Data */
607#define SPMODE_MSTR ((ushort)0x0200) /* SPI Master */
608#define SPMODE_EN ((ushort)0x0100) /* Enable */
609#define SPMODE_LENMSK ((ushort)0x00f0) /* character length */
610#define SPMODE_LEN4 ((ushort)0x0030) /* 4 bits per char */
611#define SPMODE_LEN8 ((ushort)0x0070) /* 8 bits per char */
612#define SPMODE_LEN16 ((ushort)0x00f0) /* 16 bits per char */
613#define SPMODE_PMMSK ((ushort)0x000f) /* prescale modulus */
614
615/* SPIE fields */
616#define SPIE_MME 0x20
617#define SPIE_TXE 0x10
618#define SPIE_BSY 0x04
619#define SPIE_TXB 0x02
620#define SPIE_RXB 0x01
621
622/*
623 * RISC Controller Configuration Register definitons
624 */
625#define RCCR_TIME 0x8000 /* RISC Timer Enable */
626#define RCCR_TIMEP(t) (((t) & 0x3F)<<8) /* RISC Timer Period */
627#define RCCR_TIME_MASK 0x00FF /* not RISC Timer related bits */
628
629/* RISC Timer Parameter RAM offset */
630#define PROFF_RTMR ((uint)0x01B0)
631
632typedef struct risc_timer_pram {
633 unsigned short tm_base; /* RISC Timer Table Base Address */
634 unsigned short tm_ptr; /* RISC Timer Table Pointer (internal) */
635 unsigned short r_tmr; /* RISC Timer Mode Register */
636 unsigned short r_tmv; /* RISC Timer Valid Register */
637 unsigned long tm_cmd; /* RISC Timer Command Register */
638 unsigned long tm_cnt; /* RISC Timer Internal Count */
639} rt_pram_t;
640
641/* Bits in RISC Timer Command Register */
642#define TM_CMD_VALID 0x80000000 /* Valid - Enables the timer */
643#define TM_CMD_RESTART 0x40000000 /* Restart - for automatic restart */
644#define TM_CMD_PWM 0x20000000 /* Run in Pulse Width Modulation Mode */
645#define TM_CMD_NUM(n) (((n)&0xF)<<16) /* Timer Number */
646#define TM_CMD_PERIOD(p) ((p)&0xFFFF) /* Timer Period */
647
648/* CPM interrupts. There are nearly 32 interrupts generated by CPM
649 * channels or devices. All of these are presented to the PPC core
650 * as a single interrupt. The CPM interrupt handler dispatches its
651 * own handlers, in a similar fashion to the PPC core handler. We
652 * use the table as defined in the manuals (i.e. no special high
653 * priority and SCC1 == SCCa, etc...).
654 */
655#define CPMVEC_NR 32
656#define CPMVEC_PIO_PC15 ((ushort)0x1f)
657#define CPMVEC_SCC1 ((ushort)0x1e)
658#define CPMVEC_SCC2 ((ushort)0x1d)
659#define CPMVEC_SCC3 ((ushort)0x1c)
660#define CPMVEC_SCC4 ((ushort)0x1b)
661#define CPMVEC_PIO_PC14 ((ushort)0x1a)
662#define CPMVEC_TIMER1 ((ushort)0x19)
663#define CPMVEC_PIO_PC13 ((ushort)0x18)
664#define CPMVEC_PIO_PC12 ((ushort)0x17)
665#define CPMVEC_SDMA_CB_ERR ((ushort)0x16)
666#define CPMVEC_IDMA1 ((ushort)0x15)
667#define CPMVEC_IDMA2 ((ushort)0x14)
668#define CPMVEC_TIMER2 ((ushort)0x12)
669#define CPMVEC_RISCTIMER ((ushort)0x11)
670#define CPMVEC_I2C ((ushort)0x10)
671#define CPMVEC_PIO_PC11 ((ushort)0x0f)
672#define CPMVEC_PIO_PC10 ((ushort)0x0e)
673#define CPMVEC_TIMER3 ((ushort)0x0c)
674#define CPMVEC_PIO_PC9 ((ushort)0x0b)
675#define CPMVEC_PIO_PC8 ((ushort)0x0a)
676#define CPMVEC_PIO_PC7 ((ushort)0x09)
677#define CPMVEC_TIMER4 ((ushort)0x07)
678#define CPMVEC_PIO_PC6 ((ushort)0x06)
679#define CPMVEC_SPI ((ushort)0x05)
680#define CPMVEC_SMC1 ((ushort)0x04)
681#define CPMVEC_SMC2 ((ushort)0x03)
682#define CPMVEC_PIO_PC5 ((ushort)0x02)
683#define CPMVEC_PIO_PC4 ((ushort)0x01)
684#define CPMVEC_ERROR ((ushort)0x00)
685
686/* CPM interrupt configuration vector.
687*/
688#define CICR_SCD_SCC4 ((uint)0x00c00000) /* SCC4 @ SCCd */
689#define CICR_SCC_SCC3 ((uint)0x00200000) /* SCC3 @ SCCc */
690#define CICR_SCB_SCC2 ((uint)0x00040000) /* SCC2 @ SCCb */
691#define CICR_SCA_SCC1 ((uint)0x00000000) /* SCC1 @ SCCa */
joe@perches.com567e9fd2007-12-18 06:30:13 +1100692#define CICR_IRL_MASK ((uint)0x0000e000) /* Core interrupt */
Kumar Gala33d71d22007-08-20 08:50:28 -0500693#define CICR_HP_MASK ((uint)0x00001f00) /* Hi-pri int. */
694#define CICR_IEN ((uint)0x00000080) /* Int. enable */
695#define CICR_SPS ((uint)0x00000001) /* SCC Spread */
696
Scott Woodfb533d02007-09-14 14:22:36 -0500697#define IMAP_ADDR (get_immrbase())
698
Scott Wood663edbd2007-07-16 17:22:01 -0500699#define CPM_PIN_INPUT 0
700#define CPM_PIN_OUTPUT 1
701#define CPM_PIN_PRIMARY 0
702#define CPM_PIN_SECONDARY 2
703#define CPM_PIN_GPIO 4
704#define CPM_PIN_OPENDRAIN 8
705
706enum cpm_port {
707 CPM_PORTA,
708 CPM_PORTB,
709 CPM_PORTC,
710 CPM_PORTD,
711 CPM_PORTE,
712};
713
714void cpm1_set_pin(enum cpm_port port, int pin, int flags);
715
716enum cpm_clk_dir {
717 CPM_CLK_RX,
718 CPM_CLK_TX,
719 CPM_CLK_RTX
720};
721
722enum cpm_clk_target {
723 CPM_CLK_SCC1,
724 CPM_CLK_SCC2,
725 CPM_CLK_SCC3,
726 CPM_CLK_SCC4,
727 CPM_CLK_SMC1,
728 CPM_CLK_SMC2,
729};
730
731enum cpm_clk {
732 CPM_BRG1, /* Baud Rate Generator 1 */
733 CPM_BRG2, /* Baud Rate Generator 2 */
734 CPM_BRG3, /* Baud Rate Generator 3 */
735 CPM_BRG4, /* Baud Rate Generator 4 */
736 CPM_CLK1, /* Clock 1 */
737 CPM_CLK2, /* Clock 2 */
738 CPM_CLK3, /* Clock 3 */
739 CPM_CLK4, /* Clock 4 */
740 CPM_CLK5, /* Clock 5 */
741 CPM_CLK6, /* Clock 6 */
742 CPM_CLK7, /* Clock 7 */
743 CPM_CLK8, /* Clock 8 */
744};
745
746int cpm1_clk_setup(enum cpm_clk_target target, int clock, int mode);
747
Kumar Gala33d71d22007-08-20 08:50:28 -0500748#endif /* __CPM_8XX__ */