OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [arch/] [m68k/] [bvme6000/] [config.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/*
2
 *  arch/m68k/bvme6000/config.c
3
 *
4
 *  Copyright (C) 1997 Richard Hirst [richard@sleepie.demon.co.uk]
5
 *
6
 * Based on:
7
 *
8
 *  linux/amiga/config.c
9
 *
10
 *  Copyright (C) 1993 Hamish Macdonald
11
 *
12
 * This file is subject to the terms and conditions of the GNU General Public
13
 * License.  See the file README.legal in the main directory of this archive
14
 * for more details.
15
 */
16
 
17
#include <linux/types.h>
18
#include <linux/kernel.h>
19
#include <linux/mm.h>
20
#include <linux/tty.h>
21
#include <linux/console.h>
22
#include <linux/linkage.h>
23
#include <linux/init.h>
24
#include <linux/major.h>
25
#include <linux/rtc.h>
26
 
27
#include <asm/bootinfo.h>
28
#include <asm/system.h>
29
#include <asm/pgtable.h>
30
#include <asm/setup.h>
31
#include <asm/irq.h>
32
#include <asm/traps.h>
33
#include <asm/rtc.h>
34
#include <asm/machdep.h>
35
#include <asm/bvme6000hw.h>
36
 
37
extern void bvme6000_process_int (int level, struct pt_regs *regs);
38
extern void bvme6000_init_IRQ (void);
39
extern void bvme6000_free_irq (unsigned int, void *);
40
extern int  bvme6000_get_irq_list (char *);
41
extern void bvme6000_enable_irq (unsigned int);
42
extern void bvme6000_disable_irq (unsigned int);
43
static void bvme6000_get_model(char *model);
44
static int  bvme6000_get_hardware_list(char *buffer);
45
extern int  bvme6000_request_irq(unsigned int irq, void (*handler)(int, void *, struct pt_regs *), unsigned long flags, const char *devname, void *dev_id);
46
extern void bvme6000_sched_init(void (*handler)(int, void *, struct pt_regs *));
47
extern int  bvme6000_keyb_init(void);
48
extern int  bvme6000_kbdrate (struct kbd_repeat *);
49
extern unsigned long bvme6000_gettimeoffset (void);
50
extern void bvme6000_gettod (int *year, int *mon, int *day, int *hour,
51
                           int *min, int *sec);
52
extern int bvme6000_hwclk (int, struct rtc_time *);
53
extern int bvme6000_set_clock_mmss (unsigned long);
54
extern void bvme6000_check_partition (struct gendisk *hd, unsigned int dev);
55
extern void bvme6000_mksound( unsigned int count, unsigned int ticks );
56
extern void bvme6000_reset (void);
57
extern void bvme6000_waitbut(void);
58
void bvme6000_set_vectors (void);
59
 
60
static unsigned char bcd2bin (unsigned char b);
61
static unsigned char bin2bcd (unsigned char b);
62
 
63
/* Save tick handler routine pointer, will point to do_timer() in
64
 * kernel/sched.c, called via bvme6000_process_int() */
65
 
66
static void (*tick_handler)(int, void *, struct pt_regs *);
67
 
68
 
69
int bvme6000_parse_bootinfo(const struct bi_record *bi)
70
{
71
        if (bi->tag == BI_VME_TYPE)
72
                return 0;
73
        else
74
                return 1;
75
}
76
 
77
int bvme6000_kbdrate (struct kbd_repeat *k)
78
{
79
        return 0;
80
}
81
 
82
void bvme6000_mksound( unsigned int count, unsigned int ticks )
83
{
84
}
85
 
86
void bvme6000_reset()
87
{
88
        volatile PitRegsPtr pit = (PitRegsPtr)BVME_PIT_BASE;
89
 
90
        printk ("\r\n\nCalled bvme6000_reset\r\n"
91
                        "\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r");
92
        /* The string of returns is to delay the reset until the whole
93
         * message is output. */
94
        /* Enable the watchdog, via PIT port C bit 4 */
95
 
96
        pit->pcddr      |= 0x10;        /* WDOG enable */
97
 
98
        while(1)
99
                ;
100
}
101
 
102
static void bvme6000_get_model(char *model)
103
{
104
    sprintf(model, "BVME%d000", m68k_cputype == CPU_68060 ? 6 : 4);
105
}
106
 
107
 
108
/* No hardware options on BVME6000? */
109
 
110
static int bvme6000_get_hardware_list(char *buffer)
111
{
112
    *buffer = '\0';
113
    return 0;
114
}
115
 
116
 
117
void __init config_bvme6000(void)
118
{
119
    volatile PitRegsPtr pit = (PitRegsPtr)BVME_PIT_BASE;
120
 
121
    /* Board type is only set by newer versions of vmelilo/tftplilo */
122
    if (!vme_brdtype) {
123
        if (m68k_cputype == CPU_68060)
124
            vme_brdtype = VME_TYPE_BVME6000;
125
        else
126
            vme_brdtype = VME_TYPE_BVME4000;
127
    }
128
#if 0
129
    /* Call bvme6000_set_vectors() so ABORT will work, along with BVMBug
130
     * debugger.  Note trap_init() will splat the abort vector, but
131
     * bvme6000_init_IRQ() will put it back again.  Hopefully. */
132
 
133
    bvme6000_set_vectors();
134
#endif
135
 
136
    mach_max_dma_address = 0xffffffff;
137
    mach_sched_init      = bvme6000_sched_init;
138
#ifdef CONFIG_VT
139
    mach_keyb_init       = bvme6000_keyb_init;
140
    mach_kbdrate         = bvme6000_kbdrate;
141
#endif
142
    mach_init_IRQ        = bvme6000_init_IRQ;
143
    mach_gettimeoffset   = bvme6000_gettimeoffset;
144
    mach_gettod          = bvme6000_gettod;
145
    mach_hwclk           = bvme6000_hwclk;
146
    mach_set_clock_mmss  = bvme6000_set_clock_mmss;
147
/*  mach_mksound         = bvme6000_mksound; */
148
    mach_reset           = bvme6000_reset;
149
    mach_free_irq        = bvme6000_free_irq;
150
    mach_process_int     = bvme6000_process_int;
151
    mach_get_irq_list    = bvme6000_get_irq_list;
152
    mach_request_irq     = bvme6000_request_irq;
153
    enable_irq           = bvme6000_enable_irq;
154
    disable_irq          = bvme6000_disable_irq;
155
    mach_get_model       = bvme6000_get_model;
156
    mach_get_hardware_list = bvme6000_get_hardware_list;
157
 
158
    printk ("Board is %sconfigured as a System Controller\n",
159
                *config_reg_ptr & BVME_CONFIG_SW1 ? "" : "not ");
160
 
161
    /* Now do the PIT configuration */
162
 
163
    pit->pgcr   = 0x00; /* Unidirectional 8 bit, no handshake for now */
164
    pit->psrr   = 0x18; /* PIACK and PIRQ fucntions enabled */
165
    pit->pacr   = 0x00; /* Sub Mode 00, H2 i/p, no DMA */
166
    pit->padr   = 0x00; /* Just to be tidy! */
167
    pit->paddr  = 0x00; /* All inputs for now (safest) */
168
    pit->pbcr   = 0x80; /* Sub Mode 1x, H4 i/p, no DMA */
169
    pit->pbdr   = 0xbc | (*config_reg_ptr & BVME_CONFIG_SW1 ? 0 : 0x40);
170
                        /* PRI, SYSCON?, Level3, SCC clks from xtal */
171
    pit->pbddr  = 0xf3; /* Mostly outputs */
172
    pit->pcdr   = 0x01; /* PA transceiver disabled */
173
    pit->pcddr  = 0x03; /* WDOG disable */
174
 
175
    /* Disable snooping for Ethernet and VME accesses */
176
 
177
    bvme_acr_addrctl = 0;
178
}
179
 
180
 
181
void bvme6000_abort_int (int irq, void *dev_id, struct pt_regs *fp)
182
{
183
        unsigned long *new = (unsigned long *)vectors;
184
        unsigned long *old = (unsigned long *)0xf8000000;
185
 
186
        /* Wait for button release */
187
        while (*(volatile unsigned char *)BVME_LOCAL_IRQ_STAT & BVME_ABORT_STATUS)
188
                ;
189
 
190
        *(new+4) = *(old+4);            /* Illegal instruction */
191
        *(new+9) = *(old+9);            /* Trace */
192
        *(new+47) = *(old+47);          /* Trap #15 */
193
        *(new+0x1f) = *(old+0x1f);      /* ABORT switch */
194
}
195
 
196
 
197
static void bvme6000_timer_int (int irq, void *dev_id, struct pt_regs *fp)
198
{
199
    volatile RtcPtr_t rtc = (RtcPtr_t)BVME_RTC_BASE;
200
    unsigned char msr = rtc->msr & 0xc0;
201
 
202
    rtc->msr = msr | 0x20;              /* Ack the interrupt */
203
 
204
    tick_handler(irq, dev_id, fp);
205
}
206
 
207
/*
208
 * Set up the RTC timer 1 to mode 2, so T1 output toggles every 5ms
209
 * (40000 x 125ns).  It will interrupt every 10ms, when T1 goes low.
210
 * So, when reading the elapsed time, you should read timer1,
211
 * subtract it from 39999, and then add 40000 if T1 is high.
212
 * That gives you the number of 125ns ticks in to the 10ms period,
213
 * so divide by 8 to get the microsecond result.
214
 */
215
 
216
void bvme6000_sched_init (void (*timer_routine)(int, void *, struct pt_regs *))
217
{
218
    volatile RtcPtr_t rtc = (RtcPtr_t)BVME_RTC_BASE;
219
    unsigned char msr = rtc->msr & 0xc0;
220
 
221
    rtc->msr = 0;        /* Ensure timer registers accessible */
222
 
223
    tick_handler = timer_routine;
224
    if (request_irq(BVME_IRQ_RTC, bvme6000_timer_int, 0,
225
                                "timer", bvme6000_timer_int))
226
        panic ("Couldn't register timer int");
227
 
228
    rtc->t1cr_omr = 0x04;       /* Mode 2, ext clk */
229
    rtc->t1msb = 39999 >> 8;
230
    rtc->t1lsb = 39999 & 0xff;
231
    rtc->irr_icr1 &= 0xef;      /* Route timer 1 to INTR pin */
232
    rtc->msr = 0x40;            /* Access int.cntrl, etc */
233
    rtc->pfr_icr0 = 0x80;       /* Just timer 1 ints enabled */
234
    rtc->irr_icr1 = 0;
235
    rtc->t1cr_omr = 0x0a;       /* INTR+T1 active lo, push-pull */
236
    rtc->t0cr_rtmr &= 0xdf;     /* Stop timers in standby */
237
    rtc->msr = 0;                /* Access timer 1 control */
238
    rtc->t1cr_omr = 0x05;       /* Mode 2, ext clk, GO */
239
 
240
    rtc->msr = msr;
241
 
242
    if (request_irq(BVME_IRQ_ABORT, bvme6000_abort_int, 0,
243
                                "abort", bvme6000_abort_int))
244
        panic ("Couldn't register abort int");
245
}
246
 
247
 
248
/* This is always executed with interrupts disabled.  */
249
 
250
/*
251
 * NOTE:  Don't accept any readings within 5us of rollover, as
252
 * the T1INT bit may be a little slow getting set.  There is also
253
 * a fault in the chip, meaning that reads may produce invalid
254
 * results...
255
 */
256
 
257
unsigned long bvme6000_gettimeoffset (void)
258
{
259
    volatile RtcPtr_t rtc = (RtcPtr_t)BVME_RTC_BASE;
260
    volatile PitRegsPtr pit = (PitRegsPtr)BVME_PIT_BASE;
261
    unsigned char msr = rtc->msr & 0xc0;
262
    unsigned char t1int, t1op;
263
    unsigned long v = 800000, ov;
264
 
265
    rtc->msr = 0;        /* Ensure timer registers accessible */
266
 
267
    do {
268
        ov = v;
269
        t1int = rtc->msr & 0x20;
270
        t1op  = pit->pcdr & 0x04;
271
        rtc->t1cr_omr |= 0x40;          /* Latch timer1 */
272
        v = rtc->t1msb << 8;            /* Read timer1 */
273
        v |= rtc->t1lsb;                /* Read timer1 */
274
    } while (t1int != (rtc->msr & 0x20) ||
275
                t1op != (pit->pcdr & 0x04) ||
276
                        abs(ov-v) > 80 ||
277
                                v > 39960);
278
 
279
    v = 39999 - v;
280
    if (!t1op)                          /* If in second half cycle.. */
281
        v += 40000;
282
    v /= 8;                             /* Convert ticks to microseconds */
283
    if (t1int)
284
        v += 10000;                     /* Int pending, + 10ms */
285
    rtc->msr = msr;
286
 
287
    return v;
288
}
289
 
290
extern void bvme6000_gettod (int *year, int *mon, int *day, int *hour,
291
                           int *min, int *sec)
292
{
293
        volatile RtcPtr_t rtc = (RtcPtr_t)BVME_RTC_BASE;
294
        unsigned char msr = rtc->msr & 0xc0;
295
 
296
        rtc->msr = 0;            /* Ensure clock accessible */
297
 
298
        do {    /* Loop until we get a reading with a stable seconds field */
299
                *sec = bcd2bin (rtc->bcd_sec);
300
                *min = bcd2bin (rtc->bcd_min);
301
                *hour = bcd2bin (rtc->bcd_hr);
302
                *day = bcd2bin (rtc->bcd_dom);
303
                *mon = bcd2bin (rtc->bcd_mth);
304
                *year = bcd2bin (rtc->bcd_year);
305
        } while (bcd2bin (rtc->bcd_sec) != *sec);
306
 
307
        rtc->msr = msr;
308
}
309
 
310
static unsigned char bcd2bin (unsigned char b)
311
{
312
        return ((b>>4)*10 + (b&15));
313
}
314
 
315
static unsigned char bin2bcd (unsigned char b)
316
{
317
        return (((b/10)*16) + (b%10));
318
}
319
 
320
 
321
/*
322
 * Looks like op is non-zero for setting the clock, and zero for
323
 * reading the clock.
324
 *
325
 *  struct hwclk_time {
326
 *         unsigned        sec;       0..59
327
 *         unsigned        min;       0..59
328
 *         unsigned        hour;      0..23
329
 *         unsigned        day;       1..31
330
 *         unsigned        mon;       0..11
331
 *         unsigned        year;      00...
332
 *         int             wday;      0..6, 0 is Sunday, -1 means unknown/don't set
333
 * };
334
 */
335
 
336
int bvme6000_hwclk(int op, struct rtc_time *t)
337
{
338
        volatile RtcPtr_t rtc = (RtcPtr_t)BVME_RTC_BASE;
339
        unsigned char msr = rtc->msr & 0xc0;
340
 
341
        rtc->msr = 0x40;        /* Ensure clock and real-time-mode-register
342
                                 * are accessible */
343
        if (op)
344
        {       /* Write.... */
345
                rtc->t0cr_rtmr = t->tm_year%4;
346
                rtc->bcd_tenms = 0;
347
                rtc->bcd_sec = bin2bcd(t->tm_sec);
348
                rtc->bcd_min = bin2bcd(t->tm_min);
349
                rtc->bcd_hr  = bin2bcd(t->tm_hour);
350
                rtc->bcd_dom = bin2bcd(t->tm_mday);
351
                rtc->bcd_mth = bin2bcd(t->tm_mon + 1);
352
                rtc->bcd_year = bin2bcd(t->tm_year%100);
353
                if (t->tm_wday >= 0)
354
                        rtc->bcd_dow = bin2bcd(t->tm_wday+1);
355
                rtc->t0cr_rtmr = t->tm_year%4 | 0x08;
356
        }
357
        else
358
        {       /* Read....  */
359
                do {
360
                        t->tm_sec  = bcd2bin(rtc->bcd_sec);
361
                        t->tm_min  = bcd2bin(rtc->bcd_min);
362
                        t->tm_hour = bcd2bin(rtc->bcd_hr);
363
                        t->tm_mday = bcd2bin(rtc->bcd_dom);
364
                        t->tm_mon  = bcd2bin(rtc->bcd_mth)-1;
365
                        t->tm_year = bcd2bin(rtc->bcd_year);
366
                        if (t->tm_year < 70)
367
                                t->tm_year += 100;
368
                        t->tm_wday = bcd2bin(rtc->bcd_dow)-1;
369
                } while (t->tm_sec != bcd2bin(rtc->bcd_sec));
370
        }
371
 
372
        rtc->msr = msr;
373
 
374
        return 0;
375
}
376
 
377
/*
378
 * Set the minutes and seconds from seconds value 'nowtime'.  Fail if
379
 * clock is out by > 30 minutes.  Logic lifted from atari code.
380
 * Algorithm is to wait for the 10ms register to change, and then to
381
 * wait a short while, and then set it.
382
 */
383
 
384
int bvme6000_set_clock_mmss (unsigned long nowtime)
385
{
386
        int retval = 0;
387
        short real_seconds = nowtime % 60, real_minutes = (nowtime / 60) % 60;
388
        unsigned char rtc_minutes, rtc_tenms;
389
        volatile RtcPtr_t rtc = (RtcPtr_t)BVME_RTC_BASE;
390
        unsigned char msr = rtc->msr & 0xc0;
391
        unsigned long flags;
392
        volatile int i;
393
 
394
        rtc->msr = 0;            /* Ensure clock accessible */
395
        rtc_minutes = bcd2bin (rtc->bcd_min);
396
 
397
        if ((rtc_minutes < real_minutes
398
                ? real_minutes - rtc_minutes
399
                        : rtc_minutes - real_minutes) < 30)
400
        {
401
                save_flags(flags);
402
                cli();
403
                rtc_tenms = rtc->bcd_tenms;
404
                while (rtc_tenms == rtc->bcd_tenms)
405
                        ;
406
                for (i = 0; i < 1000; i++)
407
                        ;
408
                rtc->bcd_min = bin2bcd(real_minutes);
409
                rtc->bcd_sec = bin2bcd(real_seconds);
410
                restore_flags(flags);
411
        }
412
        else
413
                retval = -1;
414
 
415
        rtc->msr = msr;
416
 
417
        return retval;
418
}
419
 
420
 
421
int bvme6000_keyb_init (void)
422
{
423
        return 0;
424
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.