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

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [src/] [platform/] [pb926/] [platform.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
/*
2
 * PB926 platform-specific initialisation and setup
3
 *
4
 * Copyright (C) 2007 Bahadir Balban
5
 */
6
#include <l4/generic/platform.h>
7
#include <l4/generic/space.h>
8
#include <l4/generic/irq.h>
9
#include <l4/generic/bootmem.h>
10
#include INC_ARCH(linker.h)
11
#include INC_SUBARCH(mm.h)
12
#include INC_SUBARCH(mmu_ops.h)
13
#include INC_GLUE(memory.h)
14
#include INC_GLUE(mapping.h)
15
#include INC_GLUE(memlayout.h)
16
#include INC_PLAT(offsets.h)
17
#include INC_PLAT(platform.h)
18
#include INC_PLAT(uart.h)
19
#include INC_PLAT(timer.h)
20
#include INC_PLAT(irq.h)
21
#include INC_ARCH(asm.h)
22
#include INC_ARCH(io.h)
23
#include <l4/generic/capability.h>
24
#include <l4/generic/cap-types.h>
25
 
26
/*
27
 * FIXME: This is not a platform specific
28
 * call, we will move this out later
29
 */
30
void device_cap_init(struct kernel_resources *kres, int devtype,
31
                     int devnum, unsigned long base)
32
{
33
        struct capability *cap;
34
 
35
        cap =  alloc_bootmem(sizeof(*cap), 0);
36
        cap_set_devtype(cap, devtype);
37
        cap_set_devnum(cap, devnum);
38
        cap->start = __pfn(base);
39
        cap->end = cap->start + 1;
40
        cap->size = cap->end - cap->start;
41
        link_init(&cap->list);
42
        cap_list_insert(cap, &kres->devmem_free);
43
}
44
 
45
/*
46
 * The devices that are used by the kernel are mapped
47
 * independent of these capabilities, but these provide a
48
 * concise description of what is used by the kernel.
49
 */
50
int platform_setup_device_caps(struct kernel_resources *kres)
51
{
52
        device_cap_init(kres, CAP_DEVTYPE_UART, 1, PLATFORM_UART1_BASE);
53
        device_cap_init(kres, CAP_DEVTYPE_UART, 2, PLATFORM_UART2_BASE);
54
        device_cap_init(kres, CAP_DEVTYPE_UART, 3, PLATFORM_UART3_BASE);
55
        device_cap_init(kres, CAP_DEVTYPE_TIMER, 1, PLATFORM_TIMER1_BASE);
56
        device_cap_init(kres, CAP_DEVTYPE_KEYBOARD, 0, PLATFORM_KEYBOARD0_BASE);
57
        device_cap_init(kres, CAP_DEVTYPE_MOUSE, 0, PLATFORM_MOUSE0_BASE);
58
        device_cap_init(kres, CAP_DEVTYPE_CLCD, 0, PLATFORM_CLCD0_BASE);
59
 
60
        return 0;
61
}
62
 
63
/*
64
 * We will use UART0 for kernel as well as user tasks,
65
 * so map it to kernel and user space
66
 */
67
void init_platform_console(void)
68
{
69
        add_boot_mapping(PLATFORM_UART0_BASE, PLATFORM_CONSOLE_VBASE,
70
                         PAGE_SIZE, MAP_IO_DEFAULT);
71
 
72
        /*
73
         * Map same UART IO area to userspace so that primitive uart-based
74
         * userspace printf can work. Note, this raw mapping is to be
75
         * removed in the future, when file-based io is implemented.
76
         */
77
        add_boot_mapping(PLATFORM_UART0_BASE, USERSPACE_CONSOLE_VBASE,
78
                         PAGE_SIZE, MAP_USR_IO);
79
 
80
        uart_init(PLATFORM_CONSOLE_VBASE);
81
}
82
 
83
/*
84
 * We are using TIMER0 only, so we map TIMER0 base,
85
 * incase any other timer is needed we need to map it
86
 * to userspace or kernel space as needed
87
 */
88
void init_platform_timer(void)
89
{
90
        add_boot_mapping(PLATFORM_TIMER0_BASE, PLATFORM_TIMER0_VBASE,
91
                         PAGE_SIZE, MAP_IO_DEFAULT);
92
 
93
        /* 1 Mhz means can tick up to 1,000,000 times a second */
94
        timer_init(PLATFORM_TIMER0_VBASE, 1000000 / CONFIG_SCHED_TICKS);
95
}
96
 
97
void init_platform_irq_controller()
98
{
99
        add_boot_mapping(PLATFORM_VIC_BASE, PLATFORM_IRQCTRL0_VBASE,
100
                         PAGE_SIZE, MAP_IO_DEFAULT);
101
        add_boot_mapping(PLATFORM_SIC_BASE, PLATFORM_IRQCTRL1_VBASE,
102
                         PAGE_SIZE, MAP_IO_DEFAULT);
103
        irq_controllers_init();
104
}
105
 
106
/* Add userspace devices here as you develop their irq handlers */
107
void init_platform_devices()
108
{
109
        /* TIMER23 */
110
        add_boot_mapping(PLATFORM_TIMER1_BASE, PLATFORM_TIMER1_VBASE,
111
                         PAGE_SIZE, MAP_IO_DEFAULT);
112
 
113
        /* KEYBOARD - KMI0 */
114
        add_boot_mapping(PLATFORM_KEYBOARD0_BASE, PLATFORM_KEYBOARD0_VBASE,
115
                         PAGE_SIZE, MAP_IO_DEFAULT);
116
 
117
        /* MOUSE - KMI1 */
118
        add_boot_mapping(PLATFORM_MOUSE0_BASE, PLATFORM_MOUSE0_VBASE,
119
                         PAGE_SIZE, MAP_IO_DEFAULT);
120
 
121
        /* CLCD */
122
        add_boot_mapping(PLATFORM_CLCD0_BASE, PLATFORM_CLCD0_VBASE,
123
                         PAGE_SIZE, MAP_IO_DEFAULT);
124
}
125
 
126
/* If these bits are off, 32Khz OSC source is used */
127
#define TIMER3_SCTRL_1MHZ       (1 << 21)
128
#define TIMER2_SCTRL_1MHZ       (1 << 19)
129
#define TIMER1_SCTRL_1MHZ       (1 << 17)
130
#define TIMER0_SCTRL_1MHZ       (1 << 15)
131
 
132
/* Set all timers to use 1Mhz OSC clock */
133
void init_timer_osc(void)
134
{
135
        volatile u32 reg;
136
 
137
        add_boot_mapping(PLATFORM_SYSCTRL_BASE, PLATFORM_SYSCTRL_VBASE,
138
                         PAGE_SIZE, MAP_IO_DEFAULT);
139
 
140
        reg = read(SP810_SCCTRL);
141
 
142
        write(reg | TIMER0_SCTRL_1MHZ | TIMER1_SCTRL_1MHZ
143
              | TIMER2_SCTRL_1MHZ | TIMER3_SCTRL_1MHZ,
144
              SP810_SCCTRL);
145
}
146
 
147
void platform_timer_start(void)
148
{
149
        /* Enable irq line for TIMER0 */
150
        irq_enable(IRQ_TIMER0);
151
 
152
        /* Enable timer */
153
        timer_start(PLATFORM_TIMER0_VBASE);
154
}
155
 
156
void platform_init(void)
157
{
158
        init_timer_osc();
159
        init_platform_console();
160
        init_platform_timer();
161
        init_platform_irq_controller();
162
        init_platform_devices();
163
}
164
 

powered by: WebSVN 2.1.0

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