1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
|
#include "u.h"
#include "../port/lib.h"
#include "mem.h"
#include "dat.h"
#include "fns.h"
#include "io.h"
#include "../port/error.h"
/*
*
* mcc.c
*
* This is the driver for the Multi-Channel Communications Controller
* of the MPC8260. This version is constructed for the EST SBC8260 to
* handle data from an interface to an offboard T1 framer. The driver
* supports MCC2 + TDM A:2 (channel 128) which is connected to the
* external interface.
*
* Neville Chandler
* Lucent Technologies - Bell Labs
* March 2001
*
*/
#define PKT_LEN 40
#define MPC82XX_INIT_DELAY 0x10000
#define HPIC 0xFC000000
#define HPIA 0xFC000010
#define HPID_A 0xFC000020
#define HPID 0xFC000030
#include "mcc2.h"
static ssize_t mcc2_read( struct file *, char *, size_t, loff_t * );
static ssize_t mcc2_write( struct file *, const char *, size_t, loff_t *);
static loff_t mcc2_lseek( struct file *, loff_t, int );
static int mcc2_release( struct inode *, struct file * );
static ssize_t mcc2_ioctl( struct inode *, struct file *, unsigned int, unsigned long );
//static ssize_t mcc2_ioctl( struct inode *, struct file *, unsigned int, char * );
void MPC82xxCpmInit( void );
void PortInit( void );
void PortSelectPin( unsigned short );
void InitMemAlloc( void );
void HeapCreate( U32, U32, U32, U32, char *);
void HeapCreate( U32, U32, U32, U32, char *);
void *HeapSearchMem( U32, U32);
void *HeapAllocMem( U32, U32);
void HeapFreeMem( U32, void *);
void InitLinkedList( void );
boolean DwCreateList( ListDB * );
void *DwMalloc( U32 );
void DwFree( U32, void * );
void ppc_irq_dispatch_handler(struct pt_regs *regs, int irq);
#define NR_MASK_WORDS ((NR_IRQS + 31) / 32)
extern int ppc_spurious_interrupts;
extern int ppc_second_irq;
extern struct irqaction *ppc_irq_action[NR_IRQS];
extern unsigned int ppc_local_bh_count[NR_CPUS];
extern unsigned int ppc_local_irq_count[NR_CPUS];
extern unsigned int ppc_cached_irq_mask[NR_MASK_WORDS];
extern unsigned int ppc_lost_interrupts[NR_MASK_WORDS];
extern atomic_t ppc_n_lost_interrupts;
//static void disp_led( unsigned char );
void Mcc2Init( void );
void MccDisable( unsigned char );
void MccEnable( unsigned char, unsigned char, unsigned char );
void MccRiscCmd( unsigned char, dwv_RISC_OPCODE, unsigned char );
boolean MccTest( void );
int MccTxBuffer( unsigned char, unsigned char, char *, unsigned short, unsigned short );
extern U32 PpcDisable( void );
extern void PpcMsrRestore( U32 );
static int mcc2_major = MCC_MAJOR;
static BOOLEAN insertBD_T( BD_PFIFO *, BD_P );
static BOOLEAN removBD_T( BD_PFIFO *, BD_P * );
BOOLEAN empty(volatile register FIFO *);
int insert( FIFO *, char * );
int remove( FIFO *, char ** );
void AppInit( void );
#define physaddr(ADDR) (0x60020000 | ((ADDR) << 23) | (2 << 18))
mcc_iorw_t mcc_iorw;
#if 0
typedef struct mcc_io {
unsigned int cmd;
unsigned int address;
unsigned int *buf;
int ind;
int nbytes;
siramctl_t SiRam;
cpmux_t CpMux;
mcc_t Mcc_T;
iop8260_t Io_Ports;
} mcc_iorw_t;
#endif
static void
ioctl_parm( unsigned int loop_mode )
{
/* Setup the SIMODE Register */
Si2Regs->SiAmr = SIxMR_SAD_BANK0_FIRST_HALF | /* SADx */
loop_mode | /* SDMx */
SIxMR_NO_BIT_RX_SYNC_DELAY | /* RFSDx */
SIxMR_DSC_CH_DATA_CLK_EQU | /* DSCx */
SIxMR_CRT_SPEPARATE_PINS | /* CRTx */
SIxMR_SLx_NORMAL_OPERATION | /* SLx */
SIxMR_CE_TX_RISING_RX_FALLING | /* CEx */
SIxMR_FE_FALLING_EDGE | /* FEx */
SIxMR_GM_GCI_SCIT_MODE | /* GMx */
SIxMR_NO_BIT_TX_SYNC_DELAY; /* TFSDx */
}
#if 0
static void
disp_led( unsigned char byte )
{
//int i;
*leds = byte;
//for(i=0; i<1000; i++);
}
#endif
static ssize_t
mcc2_ioctl( struct inode *inode, struct file *file,
unsigned int ioctl_cmd, // IOCTL number
unsigned long param )
// char *param ) // IOCTL parameter
{
static unsigned char mode;
char cp, *cptr;
void *vptr;
unsigned long *lptr;
int i, j;
unsigned int ld;
unsigned long lng;
volatile immap_t *Mmap;
cptr = (char *)param;
mode = (unsigned char)*cptr;
Mmap = ((volatile immap_t *)IMAP_ADDR);
switch(ioctl_cmd)
{
case IOCTL_SET_MODE:
//mode = (unsigned char)*param;
mode = ((mcc_iorw_t *)param)->cmd;
switch( mode )
{
case NORMAL_OPERATION:
/* Setup the SIMODE Register */
D( printk("mcc2_ioctl: ioctl set NORMAL_OPERATION mode\n"); )
ioctl_parm( (unsigned int)SIxMR_SDM_NORMAL_OPERATION ); /* SDMx */
break;
case AUTOMATIC_ECHO:
/* Setup the SIMODE Register */
D( printk("mcc2_ioctl: ioctl set AUTOMATIC_ECHO mode\n"); )
ioctl_parm( (unsigned int)SIxMR_SDM_AUTOMATIC_ECHO ); /* SDMx */
break;
case INTERNAL_LOOPBACK:
/* Setup the SIMODE Register */
D( printk("mcc2_ioctl: ioctl set INTERNAL_LOOPBACK mode\n"); )
ioctl_parm( (unsigned int)SIxMR_SDM_INTERNAL_LOOPBACK ); /* SDMx */
break;
case LOOPBACK_CONTROL:
/* Setup the SIMODE Register */
D( printk("mcc2_ioctl: ioctl set LOOPBACK_CONTROL mode\n"); )
ioctl_parm( (unsigned int)SIxMR_SDM_LOOPBACK_CONTROL ); /* SDMx */
break;
default:
printk("mcc2_ioctl: Error, unrecognized ioctl parameter, device operation unchanged.\n");
break;
}
break;
case IOCTL_RWX_MODE:
mode = ((mcc_iorw_t *)param)->cmd;
switch(mode)
{
case HPI_RD:
lng = (long)(((mcc_iorw_t *)param)->address);
lptr = ((unsigned long *)lng);
vptr = (void *)lptr;
if (copy_to_user( (((mcc_iorw_t *)param)->buf), (void *)vptr, (((mcc_iorw_t *)param)->nbytes))) {
printk("mcc2_ioctl: Failed during read from hpi.\n");
return -EFAULT;
}
break;
case HPI_WR:
lng = (long)(((mcc_iorw_t *)param)->address);
lptr = ((unsigned long *)lng);
vptr = (void *)lptr;
if (copy_from_user( (void *)vptr, (((mcc_iorw_t *)param)->buf), (((mcc_iorw_t *)param)->nbytes))) {
printk("mcc2_ioctl: Failed during write to hpi\n");
return -EFAULT;
}
break;
case FPGA_RD:
lng = (long)(((mcc_iorw_t *)param)->address);
lptr = ((unsigned long *)lng);
vptr = (void *)lptr;
if (copy_to_user( (((mcc_iorw_t *)param)->buf), (void *)vptr, (((mcc_iorw_t *)param)->nbytes))) {
printk("mcc2_ioctl: Failed during read from FPGA.\n");
return -EFAULT;
}
break;
case FPGA_WR:
lng = (long)(((mcc_iorw_t *)param)->address);
lptr = ((unsigned long *)lng);
vptr = (void *)lptr;
if (copy_from_user( (void *)vptr, (((mcc_iorw_t *)param)->buf), (((mcc_iorw_t *)param)->nbytes))) {
printk("mcc2_ioctl: Failed during write to FPGA\n");
return -EFAULT;
}
break;
case MEM_MODR:
cptr = (char *)Mmap;
cptr += ((mcc_iorw_t *)param)->address;
if (copy_to_user( (((mcc_iorw_t *)param)->buf), (void *)cptr, (((mcc_iorw_t *)param)->nbytes))) {
printk("mcc2_ioctl: Failed during read of read-modify memory\n");
return -EFAULT;
}
break;
case MEM_MODW:
cptr = (char *)Mmap;
cptr += ((mcc_iorw_t *)param)->address;
if (copy_from_user( (void *)cptr, (((mcc_iorw_t *)param)->buf), (((mcc_iorw_t *)param)->nbytes))) {
printk("mcc2_ioctl: Failed during modify of read-modify memory\n");
return -EFAULT;
}
break;
case IO_PORTS:
break;
case SI_RAM_CTL1:
break;
case SI_RAM_CTL2:
if (copy_to_user( (void *)param, (siramctl_t *)&(Mmap->im_siramctl2), sizeof(siramctl_t))) {
printk("mcc2_ioctl: Failed to copy SI_RAM_CTL2 struct\n");
return -EFAULT;
}
break;
default:
break;
}
break;
default:
//if (copy_to_user((void *)param, &mode, sizeof(mode)))
printk("We are at the end ...\n");
return -EFAULT;
break;
}
break;
default:
break;
}
return 0;
}
////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////
static ssize_t
mcc2_open( struct inode *inode, struct file *file )
{
MOD_INC_USE_COUNT;
return 0;
}
////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////
static int
mcc2_release( struct inode *inode, struct file *file )
{
MOD_DEC_USE_COUNT;
return 0;
}
#ifndef MODULE
////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////
long
mcc2_init( long mem_start, long mem_end )
{
if ((mcc2_major = register_chrdev(MCC_MAJOR, MCC_NAME, &mcc2_fops)))
printk("mcc2_init: Unable to get major for mcc2 device %d\n", MCC_MAJOR);
else {
//MPC82xxSiuInit();
MPC82xxCpmInit();
}
return mem_start;
}
#else
|