~ubuntu-branches/ubuntu/lucid/skyeye/lucid-proposed

« back to all changes in this revision

Viewing changes to arch/coldfire/mach/skyeye_mach_mcf5272.c

  • Committer: Bazaar Package Importer
  • Author(s): Yu Guanghui
  • Date: 2007-08-07 13:25:49 UTC
  • mfrom: (1.1.2 upstream) (2.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20070807132549-96159k1obat1fxr0
Tags: 1.2.3-1
* New upstream release
* Added NO_BFD=1, don't require libbfd now. (Closes:Bug#423933) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
        skyeye_mach_mcf5272.c - implementation of Coldfire 5272 Processor 
 
3
        Copyright (C) 2003 Skyeye Develop Group
 
4
        for help please send mail to <skyeye-developer@lists.sf.linuxforum.net>
 
5
 
 
6
        This program is free software; you can redistribute it and/or modify
 
7
        it under the terms of the GNU General Public License as published by
 
8
        the Free Software Foundation; either version 2 of the License, or
 
9
        (at your option) any later version.
 
10
 
 
11
        This program is distributed in the hope that it will be useful,
 
12
        but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
        GNU General Public License for more details.
 
15
 
 
16
        You should have received a copy of the GNU General Public License
 
17
        along with this program; if not, write to the Free Software
 
18
        Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
19
 
 
20
*/
 
21
/*
 
22
 * 12/27/2006   Michael.Kang  <blackfin.kang@gmail.com>
 
23
 */
 
24
 
 
25
 
 
26
#include <stdint.h>
 
27
#include <stdio.h>
 
28
 
 
29
#include "../common/memory.h"
 
30
#include "mcf5272.h"
 
31
//#include "tracer.h"
 
32
#include "skyeye_uart.h"
 
33
 
 
34
typedef struct uart_s{
 
35
        uint8_t * umr;
 
36
        uint8_t umr1;
 
37
        uint8_t umr2;
 
38
        uint32_t usr;
 
39
        uint32_t ucsr;
 
40
        uint8_t ucr;
 
41
        uint32_t urb;
 
42
        uint32_t utb;
 
43
        uint32_t uipcr;
 
44
        uint32_t uacr;
 
45
        uint32_t uisr;
 
46
        uint32_t uimr;
 
47
        uint32_t ubg1;
 
48
        uint32_t ubg2;
 
49
        uint32_t ufpd;
 
50
        uint32_t uip;   
 
51
        uint32_t uop1;
 
52
        uint32_t uop0;
 
53
}uart_t;
 
54
 
 
55
typedef struct cs_module_s{
 
56
        uint16_t csar;
 
57
        uint32_t csmr;
 
58
        uint16_t cscr;
 
59
}cs_module_t;
 
60
 
 
61
typedef struct mcf5272_timer_s{
 
62
        uint32_t tmr;
 
63
        uint32_t trr;
 
64
        uint32_t tcap;
 
65
        uint32_t tcn;
 
66
        uint32_t ter;
 
67
}mcf5272_timer_t;
 
68
 
 
69
typedef struct mcf5272_dma_s{
 
70
        uint32_t ivr;
 
71
}mcf5272_dma_t;
 
72
 
 
73
typedef struct mcf5272_ethernet_s{
 
74
        uint32_t ecr;
 
75
        uint32_t eir;
 
76
        uint32_t eimr;
 
77
        uint32_t rdar;
 
78
        uint32_t mscr;
 
79
        uint32_t mmfr;
 
80
        uint32_t rcr;
 
81
        uint32_t tcr;
 
82
        uint32_t htur;
 
83
        uint32_t htlr;
 
84
        uint32_t malr;
 
85
        uint32_t maur;
 
86
        uint32_t erdsr;
 
87
        uint32_t etdst;
 
88
        uint32_t emrbr;
 
89
}mcf5272_ethernet_t;
 
90
 
 
91
typedef struct mcf5272_io_s{
 
92
        unsigned int scr;
 
93
        cs_module_t cs_module[4];
 
94
        unsigned int intbase;
 
95
        unsigned int pllcr;
 
96
        unsigned int ideconfig1;
 
97
        unsigned int ideconfig2;
 
98
        unsigned int dmaconfig;
 
99
        unsigned int dmaroute;
 
100
 
 
101
        unsigned int pacnt; /* Port A Control (r/w) */
 
102
        unsigned int paddr; /* Port A Direction (r/w) */
 
103
        unsigned int padat; /* Port A Data (r/w) */
 
104
        unsigned int pbcnt; /* Port B Control (r/w) */
 
105
        unsigned int pbddr; /* Port B Direction (r/w) */
 
106
        unsigned int pbdat; /* Port B Data (r/w) */
 
107
        unsigned int pcddr; /* Port C Direction (r/w) */
 
108
        unsigned int pcdat; /* Port C Data (r/w) */
 
109
        unsigned int pdcnt; /* Port D Control (r/w) */
 
110
 
 
111
        unsigned int iis2_config;
 
112
 
 
113
        unsigned int data_in_ctrl;
 
114
        
 
115
        unsigned int icr[4];
 
116
        unsigned int isr;
 
117
        unsigned char pivr;
 
118
        unsigned int pmr;
 
119
 
 
120
        mcf5272_dma_t dma[4];
 
121
        mcf5272_timer_t timer[4];
 
122
        uart_t uart[2];
 
123
 
 
124
        mcf5272_ethernet_t ether;
 
125
}mcf5272_io_t;
 
126
 
 
127
static mcf5272_io_t mcf5272_io;
 
128
 
 
129
static char cs_module_write(short size, int offset, unsigned int value);
 
130
static char cs_module_read(unsigned int *result, short size, int offset);
 
131
static char timer_write(short size, int offset, unsigned int value);
 
132
static char timer_read(unsigned int *result, short size, int offset);
 
133
static char uart_write(short size, int offset, unsigned int value);
 
134
static char uart_read(unsigned int *result, short size, int offset);
 
135
 
 
136
static char mcf5272_mbar_write(short size, int offset, unsigned int value){
 
137
        mcf5272_io_t * io = &mcf5272_io;
 
138
        switch(offset){
 
139
                case MCFSIM_SCR:
 
140
                        io->scr = value;
 
141
                        break;
 
142
                case MCFSIM_PIVR:
 
143
                        io->pivr = value;
 
144
                        break;
 
145
                case 0xa:
 
146
                        io->pmr = value;
 
147
                        break;
 
148
                case MCFSIM_PBDDR:
 
149
                        io->pbddr = value;
 
150
                        break;
 
151
                case MCFSIM_PBCNT:
 
152
                        io->pbcnt = value;
 
153
                        break;
 
154
                case MCFSIM_PDCNT:
 
155
                        io->pdcnt = value;
 
156
                        break;
 
157
 
 
158
                case MCF_ECR:
 
159
                        io->ether.ecr = value;
 
160
                        break;
 
161
                case MCF_EIR:
 
162
                        io->ether.eir = value;
 
163
                        break;
 
164
                case MCF_EIMR:
 
165
                        io->ether.eimr = value;
 
166
                        break;
 
167
                case MCF_RDAR:
 
168
                        io->ether.rdar = value;
 
169
                        break;
 
170
                case MCF_MMFR:
 
171
                        io->ether.mmfr = value;
 
172
                        break;
 
173
                case MCF_MSCR:
 
174
                        io->ether.mscr = value;
 
175
                        break;
 
176
                case MCF_RCR:
 
177
                        io->ether.rcr = value;
 
178
                        break;
 
179
                case MCF_TCR:
 
180
                        io->ether.tcr = value;
 
181
                        break;
 
182
                case MCF_MALR:
 
183
                        io->ether.malr = value;
 
184
                        break;
 
185
                case MCF_MAUR:
 
186
                        io->ether.maur = value;
 
187
                        break;
 
188
                case MCF_HTUR:
 
189
                        io->ether.htur = value;
 
190
                        break;
 
191
                case MCF_HTLR:
 
192
                        io->ether.htlr = value;
 
193
                        break;
 
194
                case MCF_ERDSR:
 
195
                        io->ether.erdsr = value;
 
196
                        break;
 
197
                case MCF_ETDSR:
 
198
                        io->ether.etdst = value;
 
199
                        break;
 
200
                case MCF_EMRBR:
 
201
                        io->ether.emrbr = value;
 
202
                        break;
 
203
                default:
 
204
                         if(offset >= 0x20 && offset <= 0x2C){
 
205
                                int index = (offset - 0x20) / 4;
 
206
                                unsigned int old_value = mcf5272_io.icr[index];
 
207
                                int i;
 
208
                                /* IPL is changed only when a 1 is written simultaneously to the corresponding PI bit */
 
209
                                for(i = 31; i > 0; i = i - 4)
 
210
                                        if((value >> i) & 0x1)
 
211
                                                old_value = (value & (0xf << (i - 3))) | (old_value & (~(0xf << (i - 3))));
 
212
                                mcf5272_io.icr[index] = old_value;
 
213
 
 
214
                                return 1;
 
215
                        }
 
216
                        if((offset >= 0x200 && offset <= 0x272))
 
217
                                return timer_write(size, offset, value);
 
218
                        if((offset >= 0x100 && offset <= 0x13C) || (offset >= 0x140 && offset <= 0x17C))
 
219
                                return uart_write(size, offset, value);
 
220
 
 
221
 
 
222
#if 0
 
223
                        if(offset >= 0x80 && offset <= 0xAE)
 
224
                                return cs_module_write(size, offset, value);
 
225
                        if((offset >= 0x140 && offset < 0x154) || (offset >= 0x180 && offset < 0x194))
 
226
                                return timer_write(size, offset, value);
 
227
                        if((offset >= 0x1C0 && offset <= 0x1FC) || (offset >= 0x200 && offset <= 0x23C))
 
228
                                return uart_write(size, offset, value);
 
229
#endif
 
230
                        fprintf(stderr,"Error adress in %s,offset=0x%x,pc=0x%x\n",__FUNCTION__,offset, memory_core.pc);
 
231
                        skyeye_exit(-1);
 
232
                        return 0;
 
233
        }
 
234
}
 
235
static char mcf5272_mbar2_write(short size, int offset, unsigned int value){
 
236
        switch(offset){
 
237
#if 0
 
238
                case 0x4:
 
239
                        mcf5272_io.gpio_out = value;
 
240
                        break;
 
241
                case 0x8:
 
242
                        mcf5272_io.gpio_en = value;
 
243
                        break;
 
244
                case 0xC:
 
245
                        mcf5272_io.gpio_func = value;
 
246
                        break;
 
247
                case 0x14:
 
248
                        mcf5272_io.iis2_config = value;
 
249
                        break;
 
250
                case 0x30:
 
251
                        mcf5272_io.data_in_ctrl = value;
 
252
                        break;
 
253
                case 0xB4:
 
254
                        mcf5272_io.gpio1_out = value;
 
255
                        break;
 
256
                case 0xB8:
 
257
                        mcf5272_io.gpio1_en = value;
 
258
                        break;
 
259
                case 0xBC:
 
260
                        mcf5272_io.gpio1_func = value;
 
261
                        break;
 
262
                case 0x16b:/* INT Base*/
 
263
                        mcf5272_io.intbase = value;
 
264
                        break;
 
265
                case 0x180:
 
266
                        mcf5272_io.pllcr = value;
 
267
                        break;
 
268
                case 0x18C:
 
269
                        mcf5272_io.ideconfig1 = value;
 
270
                        break;
 
271
                case 0x190:
 
272
                        mcf5272_io.ideconfig2 = value;
 
273
                        break;
 
274
                case 0x188:
 
275
                        mcf5272_io.dmaroute = value;
 
276
                        break;
 
277
                case 0x9F:
 
278
                        mcf5272_io.dmaconfig = value;
 
279
                        break;
 
280
                case 0x74:
 
281
                        printf("Warning:register is not implemented\n");
 
282
                        break;
 
283
#endif
 
284
                default:
 
285
                        fprintf(stderr,"Error adress in %s,offset=0x%x\n",__FUNCTION__,offset);
 
286
                        skyeye_exit(-1);
 
287
                        return 0;
 
288
        }
 
289
        return 1;
 
290
}
 
291
static char mcf5272_mbar_read(unsigned int *result, short size, int offset){
 
292
        mcf5272_io_t * io = &mcf5272_io;
 
293
        switch(offset){
 
294
                case MCFSIM_ISR:
 
295
                        *result = io->isr;
 
296
                        break;
 
297
                case MCFSIM_PBDDR:
 
298
                        *result = io->pbddr;
 
299
                        break;
 
300
                case MCFSIM_PBCNT:
 
301
                        *result = io->pbcnt;
 
302
                        break;
 
303
                 case MCFSIM_PDCNT:
 
304
                        *result = io->pdcnt;
 
305
                        break;
 
306
 
 
307
                case MCF_MALR:
 
308
                        *result = io->ether.malr;
 
309
                        break;
 
310
                case MCF_MAUR:
 
311
                        *result = io->ether.maur;
 
312
                        break;
 
313
                default:
 
314
                        if((offset >= 0x100 && offset <= 0x13C) || (offset >= 0x140 && offset <= 0x17C))
 
315
                                return uart_read(result, size, offset);
 
316
                        if((offset >= 0x200 && offset < 0x270))
 
317
                                return timer_read(result, size, offset);
 
318
                        if(offset >= 0x20 && offset <= 0x2C){
 
319
                                int index = offset - 0x20;
 
320
                                return mcf5272_io.icr[index/4];
 
321
                        }
 
322
 
 
323
                        fprintf(stderr,"Error adress in %s,offset=%x\n",__FUNCTION__,offset);
 
324
                        skyeye_exit(-1);
 
325
                        return 0;
 
326
        }
 
327
        return 1;
 
328
}
 
329
 
 
330
static char mcf5272_mbar2_read(unsigned int *result, short size, int offset){
 
331
         switch(offset){
 
332
/*
 
333
                case 0x4:
 
334
                        *result = mcf5272_io.gpio_out;
 
335
                        break;
 
336
                case 0x8:
 
337
                        *result = mcf5272_io.gpio_en;
 
338
                        break;
 
339
                case 0xc:
 
340
                        *result = mcf5272_io.gpio_func;
 
341
                        break;
 
342
*/
 
343
                /* GPIO1 read */
 
344
#if 0
 
345
                case 0xB4:
 
346
                        *result = mcf5272_io.gpio1_out;
 
347
                        break;
 
348
                case 0xB8:
 
349
                        *result = mcf5272_io.gpio1_en;
 
350
                        break;
 
351
                case 0xBC:
 
352
                        *result = mcf5272_io.gpio1_func;
 
353
                        break;
 
354
                case 0x180:
 
355
                        *result = mcf5272_io.pllcr;
 
356
                        return 1;
 
357
#endif
 
358
                default:
 
359
                        fprintf(stderr,"Error adress in %s,offset=%x\n",__FUNCTION__,offset);
 
360
                        skyeye_exit(-1);
 
361
                        return 0;
 
362
        }
 
363
        return 1;
 
364
}
 
365
 
 
366
/* Interrupts go from 0 -> 9 on the 5307, with the 7 external
 
367
 *  autovector only interrupts defined in the autovector interrupt */
 
368
 
 
369
/* ICR:
 
370
 *      +----+----+----+----+----+----+----+----+
 
371
 *      | av | xx | xx |  int level   | int pri |
 
372
 *      +----+----+----+----+----+----+----+----+ 
 
373
 * av -- autovectored, 1=yes 
 
374
 * int level -- interrupt level, 0 -> 7
 
375
 * int pri -- interrupt priority 11(high) -> 00 (low) */
 
376
#define ICR_LEVEL(x)    ((mcf5272_io.icr[(31 - x) / 8] >> (4 * (x % 8))) & 0x7) 
 
377
//#define ICR_PRI(icr)  ((icr) & 0x02)
 
378
//#define ICR_AVEC(icr) ((icr) & 0x80)
 
379
 
 
380
static unsigned int mcf5272_iack_func(unsigned int interrupt_level){
 
381
 
 
382
        unsigned long vector=0;
 
383
        int x;
 
384
        mcf5272_io_t * io = &mcf5272_io;
 
385
        //TRACE("called for interrupt_level=%d\n", interrupt_level);
 
386
        /* Find the _pending_ interrupt with level == interrupt_level */
 
387
        /* INT1_IRQ has highest priority and SWTO_IRQ is lowest priority */
 
388
        for(x = INT1_IRQ; x > SWTO_IRQ; x--) {
 
389
                int icr_avec, icr_level, icr_pri;
 
390
                if(!((io->isr >> x) & 0x1)){
 
391
                        continue;
 
392
                }
 
393
                icr_level = ICR_LEVEL(x);
 
394
                
 
395
                if(icr_level != interrupt_level) continue;
 
396
                /* see p163 of user manual of 5272 */
 
397
                vector = (32 - x) | (io->pivr & 0xe0);  
 
398
                /*
 
399
                if(x != 24)
 
400
                        printf("DBG: in %s, vector=%d\n", __FUNCTION__, vector);
 
401
                */
 
402
                return vector;
 
403
        }
 
404
 
 
405
        //ERR("Inside iack_func, but no interrupt is waiting with level %d\n", interrupt_level);
 
406
        fprintf(stderr, "Inside iack_func, but no interrupt is waiting with level %d\n", interrupt_level);
 
407
        return 0;
 
408
}
 
409
 
 
410
static void interrupt_assert(short number){
 
411
        mcf5272_io_t * io = &mcf5272_io;
 
412
        int level = ICR_LEVEL(number);;
 
413
        /*
 
414
        if(number != 24)
 
415
                printf("DBG:Posting interrupt Number=%d, Level=%d\n", number, level);
 
416
        */
 
417
        //TRACE("Posting interrupt Number=%d, Vector=%d\n", number, vector);
 
418
        /* Post an interrupt */
 
419
        exception_post(level, &mcf5272_iack_func);
 
420
        io->isr |= 0x1 << number;
 
421
        return;
 
422
}
 
423
 
 
424
static void interrupt_withdraw(short number){
 
425
        mcf5272_io_t * io = &mcf5272_io;
 
426
        int icr_level = ICR_LEVEL(number);
 
427
 
 
428
        io->isr &= ~(0x1 << number);
 
429
        /*
 
430
        if(number != 24)
 
431
                printf("DBG:in %s Number=%d, Level=%d\n", __FUNCTION__, number, icr_level);
 
432
        */
 
433
        exception_withdraw(icr_level);
 
434
                //TRACE("Done.\n");
 
435
        return;
 
436
}
 
437
 
 
438
void mcf5272_io_do_cycle(){
 
439
        int i;
 
440
        for(i = 0; i < TIMER_NUM; i++){
 
441
                //mcf5272_timer_t * timer = &mcf5272_io.timer[i];
 
442
                /* check if timer is enbaled */
 
443
                if(mcf5272_io.timer[i].tmr & 0x1){
 
444
                        mcf5272_io.timer[i].tcn++;
 
445
                        /* check if reference interrupt is enabled */
 
446
                        if((mcf5272_io.timer[i].tcn == mcf5272_io.timer[i].trr) && (mcf5272_io.timer[i].tmr & 0x10))
 
447
                        {
 
448
                        
 
449
                                //printf("DBG:tcn=0x%x,trr=0x%x,i=%d\n", mcf5272_io.timer[i].tcn, mcf5272_io.timer[i].trr, i);
 
450
                                /* set REF bit in TER */
 
451
                                mcf5272_io.timer[i].ter |= 0x2;
 
452
                                interrupt_assert(TIMER0_IRQ - i);
 
453
        
 
454
                                /* check if in restart mode */
 
455
                                if(mcf5272_io.timer[i].tmr & 0x8)
 
456
                                        mcf5272_io.timer[i].tcn = 0x0;
 
457
                        }
 
458
                }
 
459
        }
 
460
 
 
461
        if(1){
 
462
                /* UART FIFO full interrupt enabled */
 
463
                struct timeval tv;
 
464
                unsigned char buf;
 
465
                tv.tv_sec = 0;
 
466
                tv.tv_usec = 0;
 
467
 
 
468
                if(skyeye_uart_read(-1, &buf, 1, &tv, NULL) > 0){
 
469
                        mcf5272_io.uart[0].urb = buf;
 
470
                        /* set RXRDY bit in UISR */
 
471
                        mcf5272_io.uart[0].uisr |= 0x2;
 
472
                }
 
473
                /* set TXRDY bit in UISR */
 
474
                mcf5272_io.uart[0].uisr |= 0x1;
 
475
 
 
476
        }
 
477
        
 
478
        /* check if UART Transmitter ready interrupt enabled */
 
479
        if(!(mcf5272_io.isr & UART1_IRQ)){
 
480
                if((mcf5272_io.uart[0].uimr & mcf5272_io.uart[0].uisr))
 
481
                        interrupt_assert(UART1_IRQ);
 
482
        }
 
483
}
 
484
 
 
485
static char cs_module_read(unsigned int *result, short size, int offset){
 
486
        int index = offset - 0x80;
 
487
        int reg_no;
 
488
        if(index >= 0 && index <=8){
 
489
                reg_no = index / 4;
 
490
                index = 0;
 
491
        }
 
492
        if(index >= 0xc && index <= 0x16){
 
493
                reg_no = (index - 0xc)/ 4;
 
494
                index = 1;
 
495
        }
 
496
        if(index >= 0x18 && index <= 0x22){
 
497
                reg_no = (index - 0x18)/4;
 
498
                index = 2;
 
499
        }
 
500
        if(index >= 0x24 && index <= 0x2e){
 
501
                reg_no = (index - 0x24);
 
502
                index = 3;
 
503
        }
 
504
        switch(reg_no){
 
505
/*
 
506
                case CSAR:
 
507
                        *result = mcf5272_io.cs_module[index].csar;
 
508
                        return 1;
 
509
                case CSMR:
 
510
                        *result = mcf5272_io.cs_module[index].csmr;
 
511
                        return 1;
 
512
                case CSCR:
 
513
                        *result = mcf5272_io.cs_module[index].cscr;
 
514
                        return 1;
 
515
*/
 
516
                default:
 
517
                        fprintf(stderr,"Error adress in %s,offset=0x%x\n",__FUNCTION__,offset);
 
518
                        skyeye_exit(-1);
 
519
                        return 0;
 
520
        }
 
521
}
 
522
static char cs_module_write(short size, int offset, unsigned int value){
 
523
        int index = offset - 0x80;
 
524
        int reg_no;
 
525
        if(index >= 0 && index <=8){
 
526
                reg_no = index / 4;
 
527
                index = 0;
 
528
        }
 
529
        if(index >= 0xc && index <= 0x16){
 
530
                reg_no = (index - 0xc)/ 4;
 
531
                index = 1;
 
532
        }
 
533
        if(index >= 0x18 && index <= 0x22){
 
534
                reg_no = (index - 0x18)/4;
 
535
                index = 2;
 
536
        }
 
537
        if(index >= 0x24 && index <= 0x2e){
 
538
                reg_no = (index - 0x24);
 
539
                index = 3;
 
540
        }
 
541
        switch(reg_no){
 
542
/*
 
543
                case CSAR:
 
544
                        mcf5272_io.cs_module[index].csar = value;
 
545
                        return 1;
 
546
                case CSMR:
 
547
                        mcf5272_io.cs_module[index].csmr = value;
 
548
                        return 1;
 
549
                case CSCR:
 
550
                        mcf5272_io.cs_module[index].cscr = value;
 
551
                        return 1;
 
552
*/
 
553
                default:
 
554
                        fprintf(stderr,"Error adress in %s,offset=0x%x\n",__FUNCTION__,offset);
 
555
                        skyeye_exit(-1);
 
556
                        return 0;
 
557
        }
 
558
}
 
559
static char timer_read(unsigned int *result, short size, int offset){
 
560
        int index = (offset - 0x200) / 0x20;
 
561
        offset = offset % 0x20;
 
562
 
 
563
        //printf("DBG: in %s, offset = 0x%x", __FUNCTION__, offset);
 
564
        switch(offset){
 
565
                case 0x0:
 
566
                        *result = mcf5272_io.timer[index].tmr;
 
567
                        return 1;
 
568
                case 0x4:
 
569
                        *result = mcf5272_io.timer[index].trr;
 
570
                        return 1;
 
571
                case 0x8:
 
572
                        *result = mcf5272_io.timer[index].tcap;
 
573
                        return 1;
 
574
                case 0xc:
 
575
                        *result = mcf5272_io.timer[index].tcn;
 
576
                        return 1;
 
577
                case 0x11:
 
578
                        /* write one to clear the corresponding bit */
 
579
                        *result = mcf5272_io.timer[index].ter;
 
580
                        /* clear the corresponding bit in ipr */
 
581
                        //mcf5272_io.ipr &=  ~(0x1 << 9);
 
582
                        interrupt_withdraw(TIMER0_IRQ - index);
 
583
                        return 1;
 
584
                default:
 
585
                        fprintf(stderr,"Error adress in %s,offset=0x%x\n",__FUNCTION__,offset);
 
586
                        skyeye_exit(-1);
 
587
                        return 0;
 
588
        }
 
589
 
 
590
}
 
591
static char timer_write(short size, int offset, unsigned int value){
 
592
        int index = (offset - 0x200) / 0x20;
 
593
        offset = offset % 0x20;
 
594
        //printf("DBG: in %s, offset = 0x%x, value=0x%x\n", __FUNCTION__, offset, value);
 
595
        switch(offset){
 
596
                case 0x0:
 
597
                        mcf5272_io.timer[index].tmr = value;
 
598
                        return 1;
 
599
                case 0x4:
 
600
                        mcf5272_io.timer[index].trr = value;
 
601
                        return 1;
 
602
                case 0x8:
 
603
                        mcf5272_io.timer[index].tcap = value;
 
604
                        return 1;
 
605
                case MCFTIMER_TCN:
 
606
                        mcf5272_io.timer[index].tcn = value;
 
607
                        return 1;
 
608
                case MCFTIMER_TER:
 
609
                        /* write one to clear the corresponding bit */
 
610
                        mcf5272_io.timer[index].ter &= ~(value & 0x3);
 
611
                        /* clear the corresponding bit in ipr */
 
612
                        //mcf5272_io.ipr &=  ~(0x1 << 9);
 
613
                        interrupt_withdraw(TIMER0_IRQ - index);
 
614
                        return 1;
 
615
                default:
 
616
                        fprintf(stderr,"Error adress in %s,offset=0x%x\n",__FUNCTION__,offset);
 
617
                        skyeye_exit(-1);
 
618
                        return 0;
 
619
        }
 
620
 
 
621
}
 
622
static char uart_read(unsigned int *result, short size, int offset){
 
623
        int index;
 
624
        if(offset >= 0x100 && offset <= 0x13C){
 
625
                index = 0;
 
626
                offset = offset - 0x100;
 
627
        }
 
628
        if(offset >= 0x140 && offset <= 0x17C){
 
629
                index = 1;
 
630
                offset = offset - 0x140;
 
631
        }
 
632
        extern struct _memory_core memory_core;
 
633
        /*
 
634
        if(offset != 0x4)
 
635
                printf("DBG: in %s, offset = 0x%x,PC=0x%x\n", __FUNCTION__, offset, memory_core.pc);
 
636
        */
 
637
        switch(offset){
 
638
                case 0x0:
 
639
                        *result = mcf5272_io.uart[index].umr1;
 
640
                        break;
 
641
                case 0x4:
 
642
                        *result = mcf5272_io.uart[index].usr;
 
643
                        break;
 
644
                case 0xC:
 
645
                        *result = mcf5272_io.uart[index].urb;
 
646
                        /* set FFULL bit in USR is zero */
 
647
                        mcf5272_io.uart[index].usr &= ~0x2;
 
648
                        /* set RxRDY bit in USR is zero */
 
649
                        mcf5272_io.uart[index].usr &= ~0x1;
 
650
                        /* check RXIRQ bit in UMR1 */
 
651
                        //if(mcf5272_io.uart[index].umr1 & 0x40)
 
652
                        mcf5272_io.uart[index].uisr &= ~0x2;
 
653
                        break;  
 
654
                case 0x10:
 
655
                        *result = mcf5272_io.uart[index].uipcr;
 
656
                        break;
 
657
                case 0x14:
 
658
                        *result = mcf5272_io.uart[index].uisr;  
 
659
                        mcf5272_io.uart[index].uisr = 0x0;
 
660
                        interrupt_withdraw(UART1_IRQ - index);
 
661
                        break;
 
662
                case 0x18:
 
663
                        *result = mcf5272_io.uart[index].ubg1;
 
664
                        break;
 
665
                case 0x1C:
 
666
                        *result = mcf5272_io.uart[index].ubg2;
 
667
                        break;
 
668
                case 0x34:
 
669
                        *result = mcf5272_io.uart[index].uip;
 
670
                        break;
 
671
                default:
 
672
                        fprintf(stderr,"Error adress in %s,offset=0x%x\n",__FUNCTION__,offset);
 
673
                        skyeye_exit(-1);
 
674
                        return 0;
 
675
        }
 
676
        return 1;
 
677
}
 
678
static char uart_write(short size, int offset, unsigned int value){
 
679
        int index, cmd;
 
680
        char tmp;
 
681
        if(offset >= 0x100 && offset <= 0x13C){
 
682
                index = 0;
 
683
                offset = offset - 0x100;
 
684
        }
 
685
        if(offset >= 0x140 && offset <= 0x17C){
 
686
                index = 1;
 
687
                offset = offset - 0x140;
 
688
        }
 
689
        /*
 
690
        if(offset != 0xc)
 
691
                printf("DBG: in %s, offset = 0x%x, value=0x%x\n", __FUNCTION__, offset, value);
 
692
        */
 
693
        switch(offset){
 
694
                case 0x0:
 
695
                        mcf5272_io.uart[index].umr1 = value;
 
696
                        break;
 
697
                case 0x4:
 
698
                        mcf5272_io.uart[index].ucsr = value;
 
699
                        break;
 
700
                case 0x8:
 
701
                        mcf5272_io.uart[index].ucr = value;
 
702
                        if((value & 0x3) == 0x1) /* Receiver enable */
 
703
                                ;
 
704
 
 
705
                        if(((value >> 2) & 0x3) == 0x1) /* Transmitter enable */
 
706
                                /* set TXRDY bit and TXEMP bit in usr */
 
707
                                mcf5272_io.uart[index].usr |= 0xc;
 
708
 
 
709
                        cmd = (value >> 4) & 0x7;
 
710
                        if (cmd == 0x4) /* Reset error status */
 
711
                                mcf5272_io.uart[index].usr &= 0xf;
 
712
                        break;
 
713
                case 0xc:
 
714
                        mcf5272_io.uart[index].utb = value;
 
715
                        tmp = value & 0xff;
 
716
                        skyeye_uart_write(-1, &tmp, 1, NULL);
 
717
                        /* set TXRDY bit and TXEMP bit in usr */
 
718
                        mcf5272_io.uart[index].usr |= 0xc;
 
719
                        /* set TXRDY bit in usr */
 
720
                        mcf5272_io.uart[index].uisr |= 0x1;
 
721
                        break;
 
722
                case 0x10:
 
723
                        mcf5272_io.uart[index].uacr = value;
 
724
                        break;
 
725
                case 0x14:
 
726
                        mcf5272_io.uart[index].uimr = value;
 
727
                        break;
 
728
                case 0x18:
 
729
                        mcf5272_io.uart[index].ubg1 = value;
 
730
                        break;
 
731
                case 0x1C:
 
732
                        mcf5272_io.uart[index].ubg2 = value;
 
733
                        break;
 
734
                case 0x30:
 
735
                        mcf5272_io.uart[index].ufpd = value;
 
736
                        break;
 
737
                case 0x38:
 
738
                        mcf5272_io.uart[index].uop1 = value;
 
739
                        break;
 
740
                case 0x3C:
 
741
                        mcf5272_io.uart[index].uop0 = value;
 
742
                        break;
 
743
                default:
 
744
                        fprintf(stderr,"Error adress in %s,offset=0x%x\n",__FUNCTION__,offset);
 
745
                        skyeye_exit(-1);
 
746
                        return 0;
 
747
        }
 
748
        return 1;
 
749
}
 
750
void mcf5272_mach_init(void * state, machine_config_t * mach){
 
751
        struct _memory_core * core = (struct _memory_core *)state;
 
752
        machine_config_t * this_mach = mach;
 
753
        core->mbar_read = mcf5272_mbar_read;
 
754
        core->mbar_write = mcf5272_mbar_write;
 
755
        core->mbar2_read = mcf5272_mbar2_read;
 
756
        core->mbar2_write = mcf5272_mbar2_write;
 
757
        /* init io  value */
 
758
        /* fixme, workaround for uClinux */
 
759
        mcf5272_io.pivr = 0x40;
 
760
        /* init mach */
 
761
        if (!this_mach) {
 
762
                exit (-1);
 
763
        }
 
764
        this_mach->mach_io_do_cycle = mcf5272_io_do_cycle;
 
765
#if 0
 
766
        this_mach->mach_io_read_byte = mcf5272_io_read_byte;
 
767
        this_mach->mach_io_read_halfword = mcf5272_io_read_halfword;
 
768
        this_mach->mach_io_read_word = mcf5272_io_read_word;
 
769
        this_mach->mach_io_write_byte = mcf5272_io_write_byte;
 
770
        this_mach->mach_io_write_halfword = mcf5272_io_write_halfword;
 
771
        this_mach->mach_io_write_word = mcf5272_io_write_word;
 
772
        this_mach->mach_io_do_cycle = mcf5272_io_do_cycle;
 
773
        this_mach->mach_set_intr = mcf5272_set_int;
 
774
#endif
 
775
}