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

« back to all changes in this revision

Viewing changes to arch/arm/mach/skyeye_mach_s3c44b0.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_s3c44b0.c - define machine s3c44b0 for skyeye
3
 
        Copyright (C) 2003 Skyeye Develop Group
4
 
        for help please send mail to <skyeye-developer@lists.gro.clinux.org>
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
 
 * 7/19/2003    init this file.
23
 
 *              should be completed. who can do it?
24
 
 *              walimis <wlm@student.dlut.edu.cn> 
25
 
 *              
26
 
 * */
27
 
 
28
 
#include "armdefs.h"
29
 
#include "s3c44b0.h"
30
 
//zzc:2005-1-1
31
 
#ifdef __CYGWIN__
32
 
//chy 2005-07-28
33
 
#include <time.h>
34
 
//teawater add DBCT_TEST_SPEED 2005.10.04---------------------------------------
35
 
/*struct timeval
36
 
{
37
 
  int tv_sec;
38
 
  int tv_usec;
39
 
};*/
40
 
//AJ2D--------------------------------------------------------------------------
41
 
#endif
42
 
 
43
 
/* 2007-01-18 added by Anthony Lee : for new uart device frame */
44
 
#include "skyeye_uart.h"
45
 
 
46
 
void s3c44b0_io_write_word (ARMul_State * state, ARMword addr, ARMword data);
47
 
ARMword s3c44b0_io_read_word (ARMul_State * state, ARMword addr);
48
 
 
49
 
/* s3c44b0 Internal IO Registers
50
 
 * */
51
 
 
52
 
typedef struct s3c44b0_io
53
 
{
54
 
        /*System Manager control */
55
 
        ARMword syscfg;
56
 
 
57
 
        /*Interrupt Controller Registers */
58
 
        ARMword intcon;
59
 
        ARMword intpnd;
60
 
        ARMword intmod;
61
 
        ARMword intmsk;
62
 
        ARMword i_pslv;
63
 
        ARMword i_pmst;
64
 
        ARMword i_cslv;
65
 
        ARMword i_cmst;
66
 
        ARMword i_ispr;
67
 
        ARMword i_ispc;
68
 
        ARMword f_ispr;
69
 
        ARMword f_ispc;
70
 
 
71
 
        /*UART Registers */
72
 
        ARMword ulcon0;
73
 
        ARMword ulcon1;
74
 
        ARMword ucon0;
75
 
        ARMword ucon1;
76
 
        ARMword ufcon0;
77
 
        ARMword ufcon1;
78
 
        ARMword umcon0;
79
 
        ARMword umcon1;
80
 
        ARMword utrstat0;
81
 
        ARMword utrstat1;
82
 
        ARMword uerstat0;
83
 
        ARMword uerstat1;
84
 
        ARMword ufstat0;
85
 
        ARMword ufstat1;
86
 
        ARMword umstat0;
87
 
        ARMword umstat1;
88
 
        ARMword utxh0;
89
 
        ARMword utxh1;
90
 
        ARMword urxh0;
91
 
        ARMword urxh1;
92
 
        ARMword ubrdiv0;
93
 
        ARMword ubrdiv1;
94
 
 
95
 
        /*Timers Registers */
96
 
        ARMword tcfg0;
97
 
        ARMword tcfg1;
98
 
        ARMword tcon;
99
 
        int tcntb[TIMER_NUM];
100
 
        int tcnt[TIMER_NUM];
101
 
        int tcmpb[TIMER_NUM];   /*timer5 has no tcmpb register. */
102
 
        int tcmp[TIMER_NUM];    /*timer5 has no tcmpb register. */
103
 
        int tcnto[TIMER_NUM];
104
 
 
105
 
} s3c44b0_io_t;
106
 
 
107
 
static s3c44b0_io_t s3c44b0_io;
108
 
 
109
 
#define io s3c44b0_io
110
 
 
111
 
/*some defines*/
112
 
#define ENABLE_IRQ      ~io.intcon & 0x2
113
 
#define ENABLE_FIQ      ~io.intcon & 0x1
114
 
 
115
 
static void
116
 
s3c44b0_update_int (ARMul_State * state)
117
 
{
118
 
        ARMword requests = io.intpnd & (~io.intmsk & INT_MASK_INIT);
119
 
        state->NfiqSig = (requests & io.intmod) ? LOW : HIGH;
120
 
        state->NirqSig = (requests & ~io.intmod) ? LOW : HIGH;
121
 
}
122
 
static void
123
 
s3c44b0_set_interrupt (unsigned int irq)
124
 
{
125
 
        /*if (ENABLE_IRQ){
126
 
           io.i_ispr =  (1 << interrupt);
127
 
           } */
128
 
        if (ENABLE_IRQ | ENABLE_FIQ) {
129
 
                io.intpnd |= (1 << irq);
130
 
        }
131
 
}
132
 
static void
133
 
s3c44b0_io_reset (ARMul_State * state)
134
 
{
135
 
        memset (&s3c44b0_io, 0, sizeof (s3c44b0_io));
136
 
        io.syscfg = 0x01;
137
 
        /*Interrupt register reset */
138
 
        io.intcon = 0x7;
139
 
        io.intmsk = INT_MASK_INIT;
140
 
        io.i_pslv = 0x1b1b1b1b;
141
 
        io.i_pmst = 0x00001f1b;
142
 
        io.i_cslv = 0x1b1b1b1b;
143
 
        io.i_cmst = 0x0000001b;
144
 
        io.i_ispr = 0x0;
145
 
        io.i_ispc = 0x0;
146
 
         /*UART*/ io.utrstat0 = io.utrstat1 = 0x6;
147
 
}
148
 
 
149
 
/* test timer register tcon's bit.
150
 
 * */
151
 
static int
152
 
timer_op (int n, int op)
153
 
{
154
 
        if (n == 0)
155
 
                return TIMER_OP (io.tcon, n, op);
156
 
        else {
157
 
                if (n == 5 && op == TIMER_OP_RELOAD)
158
 
                        return TIMER_OP (io.tcon, n + 1, op - 1);
159
 
                else
160
 
                        return TIMER_OP (io.tcon, n + 1, op);
161
 
        }
162
 
}
163
 
 
164
 
/* get timer interrupt num.
165
 
 * */
166
 
static
167
 
get_timer_int (int i)
168
 
{
169
 
        switch (i) {
170
 
        case 0:
171
 
                return TIMER_INT (0);
172
 
                break;
173
 
        case 1:
174
 
                return TIMER_INT (1);
175
 
                break;
176
 
        case 2:
177
 
                return TIMER_INT (2);
178
 
                break;
179
 
        case 3:
180
 
                return TIMER_INT (3);
181
 
                break;
182
 
        case 4:
183
 
                return TIMER_INT (4);
184
 
                break;
185
 
        case 5:
186
 
                return TIMER_INT (5);
187
 
                break;
188
 
        }
189
 
}
190
 
 
191
 
 
192
 
/*s3c44b0 io_do_cycle*/
193
 
void
194
 
s3c44b0_io_do_cycle (ARMul_State * state)
195
 
{
196
 
        int i;
197
 
        /*Timer */
198
 
        for (i = 0; i < TIMER_NUM; i++) {
199
 
                if (timer_op (i, TIMER_OP_START)) {
200
 
                        if (io.tcnt[i] > 0) {
201
 
                                io.tcnt[i]--;
202
 
                                io.tcmp[i]--;
203
 
                        }
204
 
                        if (io.tcnt[i] == 0) {
205
 
                                if (timer_op (i, TIMER_OP_RELOAD)) {
206
 
                                        io.tcnt[i] = io.tcntb[i];
207
 
                                        io.tcmp[i] = io.tcmpb[i];
208
 
                                        io.tcnto[i] = io.tcntb[i];
209
 
                                        s3c44b0_set_interrupt (get_timer_int
210
 
                                                               (i));
211
 
                                        s3c44b0_update_int (state);
212
 
                                }
213
 
                                //s3c44b0_set_interrupt(get_timer_int(i));
214
 
                                //s3c44b0_update_int(state);
215
 
                        }
216
 
                }
217
 
        }
218
 
         /*UART*/ if (!(io.intpnd & INT_URXD0) || !(io.intpnd & INT_URXD1)) {
219
 
                /* 2007-01-18 modified by Anthony Lee : for new uart device frame */
220
 
                struct timeval tv;
221
 
                unsigned char buf;
222
 
 
223
 
                tv.tv_sec = 0;
224
 
                tv.tv_usec = 0;
225
 
 
226
 
                if(skyeye_uart_read(-1, &buf, 1, &tv, NULL) > 0)
227
 
                {
228
 
                        io.urxh0 = io.urxh1 = (int) buf;
229
 
                        io.utrstat0 |= UART_LSR_DR;
230
 
                        io.utrstat1 |= UART_LSR_DR;
231
 
                        if ((io.ucon0 & 0x3) == 0x1) {
232
 
                                s3c44b0_set_interrupt (INT_URXD0);
233
 
                                s3c44b0_update_int (state);
234
 
                                return;
235
 
                        }
236
 
                        if ((io.ucon1 & 0x3) == 0x1) {
237
 
                                s3c44b0_set_interrupt (INT_URXD1);
238
 
                                s3c44b0_update_int (state);
239
 
                                return;
240
 
                        }
241
 
                }
242
 
        }
243
 
//      s3c44b0_update_int(state);
244
 
}
245
 
 
246
 
 
247
 
/* IO Read Routine
248
 
 * */
249
 
ARMword
250
 
s3c44b0_io_read_byte (ARMul_State * state, ARMword addr)
251
 
{
252
 
        s3c44b0_io_read_word (state, addr);
253
 
        /*printf("SKYEYE: s3c44b0_io_read_byte error\n");
254
 
           exit(-1); */
255
 
}
256
 
 
257
 
ARMword
258
 
s3c44b0_io_read_halfword (ARMul_State * state, ARMword addr)
259
 
{
260
 
        s3c44b0_io_read_word (state, addr);
261
 
        /*printf("SKYEYE: s3c44b0_io_read_halfword error\n");
262
 
           exit(-1); */
263
 
}
264
 
 
265
 
ARMword
266
 
s3c44b0_io_read_word (ARMul_State * state, ARMword addr)
267
 
{
268
 
        ARMword data = -1;
269
 
        switch (addr) {
270
 
        case SYSCFG:
271
 
                data = io.syscfg;
272
 
                printf ("%s (addr = 0x%08x), pc:%x, NumInstrs:%x\n",
273
 
                        __FUNCTION__, addr, state->pc, state->NumInstrs);
274
 
                //printf("instr:%x\n",state->loaded);
275
 
                break;
276
 
                /*Interrupt */
277
 
        case INTCON:
278
 
                data = io.intcon;
279
 
                break;
280
 
        case INTMOD:
281
 
                data = io.intmod;
282
 
                break;
283
 
        case INTPND:
284
 
                data = io.intpnd;
285
 
                break;
286
 
        case INTMSK:
287
 
                data = io.intmsk;
288
 
                break;
289
 
        case I_PSLV:
290
 
                data = io.i_pslv;
291
 
                break;
292
 
        case I_PMST:
293
 
                data = io.i_pmst;
294
 
                break;
295
 
        case I_CSLV:
296
 
                data = io.i_cslv;
297
 
                break;
298
 
        case I_CMST:
299
 
                data = io.i_cmst;
300
 
                break;
301
 
        case I_ISPR:
302
 
                {
303
 
                        /*find which interrupt is pending */
304
 
                        int i;
305
 
                        for (i = 0; i < 26; i++) {
306
 
                                if (io.intpnd & (1 << i))
307
 
                                        break;
308
 
                        }
309
 
                        if (i < 26) {
310
 
                                data = (1 << i);
311
 
                        }
312
 
                        else
313
 
                                data = 0;
314
 
 
315
 
                }
316
 
                //data = io.i_ispr;
317
 
                break;
318
 
        case I_ISPC:
319
 
                data = io.i_ispc;
320
 
                break;
321
 
        case F_ISPR:
322
 
                data = io.f_ispr;
323
 
                break;
324
 
        case F_ISPC:
325
 
                data = io.f_ispc;
326
 
                break;
327
 
 
328
 
         /*UART*/ case ULCON0:
329
 
                data = io.ulcon0;
330
 
                break;
331
 
        case ULCON1:
332
 
                data = io.ulcon1;
333
 
                break;
334
 
        case UCON0:
335
 
                data = io.ucon0;
336
 
                break;
337
 
        case UCON1:
338
 
                data = io.ucon1;
339
 
                break;
340
 
        case UFCON0:
341
 
                data = io.ufcon0;
342
 
                break;
343
 
        case UFCON1:
344
 
                data = io.ufcon1;
345
 
                break;
346
 
        case UMCON0:
347
 
                data = io.umcon0;
348
 
                break;
349
 
        case UMCON1:
350
 
                data = io.umcon1;
351
 
                break;
352
 
        case UTRSTAT0:
353
 
                data = io.utrstat0;
354
 
                break;
355
 
        case UTRSTAT1:
356
 
                data = io.utrstat1;
357
 
                break;
358
 
        case UERSTAT0:
359
 
                data = io.uerstat0;
360
 
                break;
361
 
        case UERSTAT1:
362
 
                data = io.uerstat1;
363
 
                break;
364
 
        case UFSTAT0:
365
 
                data = io.ufstat0;
366
 
                break;
367
 
        case UFSTAT1:
368
 
                data = io.ufstat1;
369
 
                break;
370
 
        case UMSTAT0:
371
 
                data = io.umstat0;
372
 
                break;
373
 
        case UMSTAT1:
374
 
                data = io.umstat1;
375
 
                break;
376
 
        case URXH0:
377
 
                data = io.urxh0;
378
 
                io.utrstat0 &= ~UART_LSR_DR;
379
 
                break;
380
 
        case URXH1:
381
 
                data = io.urxh1;
382
 
                io.utrstat1 &= ~UART_LSR_DR;
383
 
                break;
384
 
        case UBRDIV0:
385
 
                data = io.ubrdiv0;
386
 
                break;
387
 
        case UBRDIV1:
388
 
                data = io.ubrdiv1;
389
 
                break;
390
 
 
391
 
                /*Timer */
392
 
        case TCFG0:
393
 
                data = io.tcfg0;
394
 
                break;
395
 
        case TCFG1:
396
 
                data = io.tcfg1;
397
 
                break;
398
 
        case TCON:
399
 
                data = io.tcon;
400
 
                break;
401
 
        case TCNTB0:
402
 
        case TCMPB0:
403
 
        case TCNTO0:
404
 
        case TCNTB1:
405
 
        case TCMPB1:
406
 
        case TCNTO1:
407
 
        case TCNTB2:
408
 
        case TCMPB2:
409
 
        case TCNTO2:
410
 
        case TCNTB3:
411
 
        case TCMPB3:
412
 
        case TCNTO3:
413
 
        case TCNTB4:
414
 
        case TCMPB4:
415
 
        case TCNTO4:
416
 
        case TCNTB5:
417
 
        case TCNTO5:
418
 
                break;
419
 
        default:
420
 
                SKYEYE_DBG ("%s (addr = 0x%08x)\n", __FUNCTION__, addr);
421
 
                break;
422
 
        }
423
 
        return data;
424
 
}
425
 
 
426
 
/* IO Write Routine
427
 
 * */
428
 
void
429
 
s3c44b0_io_write_byte (ARMul_State * state, ARMword addr, ARMword data)
430
 
{
431
 
        s3c44b0_io_write_word (state, addr, data);
432
 
        /*printf("SKYEYE: s3c44b0_io_write_byte error\n");
433
 
           exit(-1); */
434
 
}
435
 
 
436
 
void
437
 
s3c44b0_io_write_halfword (ARMul_State * state, ARMword addr, ARMword data)
438
 
{
439
 
        s3c44b0_io_write_word (state, addr, data);
440
 
        printf ("SKYEYE: s3c44b0_io_write_halfword error\n");
441
 
        skyeye_exit (-1);
442
 
}
443
 
 
444
 
void
445
 
s3c44b0_io_write_word (ARMul_State * state, ARMword addr, ARMword data)
446
 
{
447
 
        switch (addr) {
448
 
        case SYSCFG:
449
 
                io.syscfg = data;
450
 
                break;
451
 
 
452
 
                /*Interrupt */
453
 
        case INTCON:
454
 
                io.intcon = data;
455
 
                break;
456
 
                /*case INTPND:          
457
 
                   break; */
458
 
        case INTMOD:
459
 
                io.intmod = data;
460
 
                break;
461
 
        case INTMSK:
462
 
                io.intmsk = data;
463
 
                break;
464
 
        case I_PSLV:
465
 
                io.i_pslv = data;
466
 
                break;
467
 
        case I_PMST:
468
 
                io.i_pmst = data;
469
 
                break;
470
 
        case I_CSLV:
471
 
                io.i_cslv = data;
472
 
                break;
473
 
        case I_CMST:
474
 
                io.i_cmst = data;
475
 
                break;
476
 
                /*case I_ISPR:      
477
 
                   io.i_ispr = data;
478
 
                   break; */
479
 
        case I_ISPC:
480
 
                io.intpnd &= (~data & INT_MASK_INIT);
481
 
                //io.i_ispr = 0;
482
 
                //s3c44b0_update_int(state);
483
 
                break;
484
 
                /*case F_ISPR:      
485
 
                   io.f_ispr = data;
486
 
                   break; */
487
 
        case F_ISPC:
488
 
                io.intpnd &= (~data & INT_MASK_INIT);
489
 
                //s3c44b0_update_int(state);
490
 
                break;
491
 
         /*UART*/ case ULCON0:
492
 
                io.ulcon0 = data;
493
 
                break;
494
 
        case ULCON1:
495
 
                io.ulcon1 = data;
496
 
                break;
497
 
        case UCON0:
498
 
                io.ucon0 = data;
499
 
                break;
500
 
        case UCON1:
501
 
                io.ucon1 = data;
502
 
                break;
503
 
        case UFCON0:
504
 
                io.ufcon0 = data;
505
 
                break;
506
 
        case UFCON1:
507
 
                io.ufcon1 = data;
508
 
                break;
509
 
        case UMCON0:
510
 
                io.umcon0 = data;
511
 
                break;
512
 
        case UMCON1:
513
 
                io.umcon1 = data;
514
 
                break;
515
 
                /*read only */
516
 
                /*case UTRSTAT0:          
517
 
                   io.utrstat0 = data;
518
 
                   break;
519
 
                   case UTRSTAT1:          
520
 
                   io.utrstat1 = data;
521
 
                   break;
522
 
                   case UERSTAT0:          
523
 
                   io.uerstat0 = data;
524
 
                   break;
525
 
                   case UERSTAT1:          
526
 
                   io.uerstat1 = data;
527
 
                   break;
528
 
                   case UFSTAT0:          
529
 
                   io.ufstat0 = data;
530
 
                   break;
531
 
                   case UFSTAT1:          
532
 
                   io.ufstat1 = data;
533
 
                   break;
534
 
                   case UMSTAT0:          
535
 
                   io.umstat0 = data;
536
 
                   break;
537
 
                   case UMSTAT1:          
538
 
                   io.umstat1 = data;
539
 
                   break; */
540
 
        case UTXH0:
541
 
                {
542
 
                        char c = data;
543
 
 
544
 
                        /* 2007-01-18 modified by Anthony Lee : for new uart device frame */
545
 
                        skyeye_uart_write(-1, &c, 1, NULL);
546
 
 
547
 
                        io.utrstat0 |= UART_LSR_THRE | UART_LSR_TEMT;
548
 
                        if ((io.ucon0 & 0xc) == 0x04) {
549
 
                                s3c44b0_set_interrupt (INT_UTXD0);
550
 
                                s3c44b0_update_int (state);
551
 
                        }
552
 
 
553
 
                }
554
 
                break;
555
 
        case UTXH1:
556
 
                io.utxh1 = data;
557
 
                break;
558
 
        case URXH0:
559
 
                io.urxh0 = data;
560
 
                break;
561
 
        case URXH1:
562
 
                io.urxh1 = data;
563
 
                break;
564
 
        case UBRDIV0:
565
 
                io.ubrdiv0 = data;
566
 
                break;
567
 
        case UBRDIV1:
568
 
                io.ubrdiv1 = data;
569
 
                break;
570
 
                /*Timer */
571
 
        case TCFG0:
572
 
                io.tcfg0 = data;
573
 
                break;
574
 
        case TCFG1:
575
 
                io.tcfg1 = data;
576
 
                break;
577
 
        case TCON:
578
 
                io.tcon = data;
579
 
                {
580
 
                        int i;
581
 
                        int rel;
582
 
                        for (i = 0; i < TIMER_NUM; i++) {
583
 
                                rel = timer_op (i, TIMER_OP_MANUAL);
584
 
                                //if(timer_op(i, TIMER_OP_MANUAL)){
585
 
                                if (rel) {
586
 
                                        io.tcnt[i] = io.tcntb[i];
587
 
                                        io.tcmp[i] = io.tcmpb[i];
588
 
                                        io.tcnto[i] = io.tcntb[i];
589
 
                                }
590
 
                        }
591
 
                }
592
 
                break;
593
 
        case TCNTB0:
594
 
        case TCNTB1:
595
 
        case TCNTB2:
596
 
        case TCNTB3:
597
 
        case TCNTB4:
598
 
                {
599
 
                        int n = (addr - TCNTB0) / 12;
600
 
                        io.tcntb[n] = data * 480;
601
 
                }
602
 
        case TCMPB0:
603
 
        case TCMPB1:
604
 
        case TCMPB2:
605
 
        case TCMPB3:
606
 
        case TCMPB4:
607
 
                {
608
 
                        int n = (addr - TCNTB0) / 12;
609
 
                        io.tcmpb[n] = data;
610
 
                }
611
 
                break;
612
 
        case TCNTB5:
613
 
                io.tcntb[5] = data;     //* 480;
614
 
                break;
615
 
        default:
616
 
                SKYEYE_DBG ("%s(0x%08x) = 0x%08x\n", __FUNCTION__, addr,
617
 
                            data);
618
 
                break;
619
 
 
620
 
        }
621
 
}
622
 
 
623
 
void
624
 
s3c44b0_mach_init (ARMul_State * state, machine_config_t * this_mach)
625
 
{
626
 
        ARMul_SelectProcessor (state, ARM_v4_Prop);
627
 
        state->lateabtSig = HIGH;
628
 
 
629
 
        state->Reg[1] = 178;
630
 
 
631
 
        this_mach->mach_io_do_cycle = s3c44b0_io_do_cycle;
632
 
        this_mach->mach_io_reset = s3c44b0_io_reset;
633
 
        this_mach->mach_io_read_word = s3c44b0_io_read_word;
634
 
        this_mach->mach_io_read_halfword = s3c44b0_io_read_halfword;
635
 
        this_mach->mach_io_read_byte = s3c44b0_io_read_byte;
636
 
        this_mach->mach_io_write_word = s3c44b0_io_write_word;
637
 
        this_mach->mach_io_write_halfword = s3c44b0_io_write_halfword;
638
 
        this_mach->mach_io_write_byte = s3c44b0_io_write_byte;
639
 
        this_mach->mach_update_int = s3c44b0_update_int;
640
 
 
641
 
        /* 2007-01-28 : added by Anthony Lee */
642
 
        this_mach->state = (void *) state;
643
 
}