Merge rsync://rsync.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[linux-2.6] / arch / mips / tx4927 / common / tx4927_setup.c
1 /*
2  * Author: MontaVista Software, Inc.
3  *         source@mvista.com
4  *
5  * Copyright 2001-2002 MontaVista Software Inc.
6  *
7  *  This program is free software; you can redistribute it and/or modify it
8  *  under the terms of the GNU General Public License as published by the
9  *  Free Software Foundation; either version 2 of the License, or (at your
10  *  option) any later version.
11  *
12  *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
13  *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
14  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
15  *  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
16  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
17  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
18  *  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
19  *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
20  *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
21  *  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22  *
23  *  You should have received a copy of the GNU General Public License along
24  *  with this program; if not, write to the Free Software Foundation, Inc.,
25  *  675 Mass Ave, Cambridge, MA 02139, USA.
26  */
27 #include <linux/errno.h>
28 #include <linux/init.h>
29 #include <linux/kernel_stat.h>
30 #include <linux/module.h>
31 #include <linux/signal.h>
32 #include <linux/sched.h>
33 #include <linux/types.h>
34 #include <linux/interrupt.h>
35 #include <linux/ioport.h>
36 #include <linux/timex.h>
37 #include <linux/slab.h>
38 #include <linux/random.h>
39 #include <linux/irq.h>
40 #include <linux/bitops.h>
41 #include <asm/bootinfo.h>
42 #include <asm/io.h>
43 #include <asm/irq.h>
44 #include <asm/mipsregs.h>
45 #include <asm/system.h>
46 #include <asm/time.h>
47 #include <asm/tx4927/tx4927.h>
48
49
50 #undef DEBUG
51
52 void __init tx4927_time_init(void);
53 void dump_cp0(char *key);
54
55
56 void __init plat_mem_setup(void)
57 {
58         board_time_init = tx4927_time_init;
59
60 #ifdef CONFIG_TOSHIBA_RBTX4927
61         {
62                 extern void toshiba_rbtx4927_setup(void);
63                 toshiba_rbtx4927_setup();
64         }
65 #endif
66 }
67
68 void __init tx4927_time_init(void)
69 {
70
71 #ifdef CONFIG_TOSHIBA_RBTX4927
72         {
73                 extern void toshiba_rbtx4927_time_init(void);
74                 toshiba_rbtx4927_time_init();
75         }
76 #endif
77
78         return;
79 }
80
81
82 void __init plat_timer_setup(struct irqaction *irq)
83 {
84         u32 count;
85         u32 c1;
86         u32 c2;
87
88         setup_irq(TX4927_IRQ_CPU_TIMER, irq);
89
90         /* to generate the first timer interrupt */
91         c1 = read_c0_count();
92         count = c1 + (mips_hpt_frequency / HZ);
93         write_c0_compare(count);
94         c2 = read_c0_count();
95
96 #ifdef CONFIG_TOSHIBA_RBTX4927
97         {
98                 extern void toshiba_rbtx4927_timer_setup(struct irqaction
99                                                          *irq);
100                 toshiba_rbtx4927_timer_setup(irq);
101         }
102 #endif
103
104         return;
105 }
106
107
108 #ifdef DEBUG
109 void print_cp0(char *key, int num, char *name, u32 val)
110 {
111         printk("%s cp0:%02d:%s=0x%08x\n", key, num, name, val);
112         return;
113 }
114
115 void
116 dump_cp0(char *key)
117 {
118         if (key == NULL)
119                 key = "";
120
121         print_cp0(key, 0, "INDEX   ", read_c0_index());
122         print_cp0(key, 2, "ENTRYLO1", read_c0_entrylo0());
123         print_cp0(key, 3, "ENTRYLO2", read_c0_entrylo1());
124         print_cp0(key, 4, "CONTEXT ", read_c0_context());
125         print_cp0(key, 5, "PAGEMASK", read_c0_pagemask());
126         print_cp0(key, 6, "WIRED   ", read_c0_wired());
127         //print_cp0(key, 8, "BADVADDR",  read_c0_badvaddr());
128         print_cp0(key, 9, "COUNT   ", read_c0_count());
129         print_cp0(key, 10, "ENTRYHI ", read_c0_entryhi());
130         print_cp0(key, 11, "COMPARE ", read_c0_compare());
131         print_cp0(key, 12, "STATUS  ", read_c0_status());
132         print_cp0(key, 13, "CAUSE   ", read_c0_cause() & 0xffff87ff);
133         print_cp0(key, 16, "CONFIG  ", read_c0_config());
134         return;
135 }
136
137 void print_pic(char *key, u32 reg, char *name)
138 {
139         printk("%s pic:0x%08x:%s=0x%08x\n", key, reg, name,
140                TX4927_RD(reg));
141         return;
142 }
143
144
145 void dump_pic(char *key)
146 {
147         if (key == NULL)
148                 key = "";
149
150         print_pic(key, 0xff1ff600, "IRDEN    ");
151         print_pic(key, 0xff1ff604, "IRDM0    ");
152         print_pic(key, 0xff1ff608, "IRDM1    ");
153
154         print_pic(key, 0xff1ff610, "IRLVL0   ");
155         print_pic(key, 0xff1ff614, "IRLVL1   ");
156         print_pic(key, 0xff1ff618, "IRLVL2   ");
157         print_pic(key, 0xff1ff61c, "IRLVL3   ");
158         print_pic(key, 0xff1ff620, "IRLVL4   ");
159         print_pic(key, 0xff1ff624, "IRLVL5   ");
160         print_pic(key, 0xff1ff628, "IRLVL6   ");
161         print_pic(key, 0xff1ff62c, "IRLVL7   ");
162
163         print_pic(key, 0xff1ff640, "IRMSK    ");
164         print_pic(key, 0xff1ff660, "IREDC    ");
165         print_pic(key, 0xff1ff680, "IRPND    ");
166         print_pic(key, 0xff1ff6a0, "IRCS     ");
167
168         print_pic(key, 0xff1ff514, "IRFLAG1  ");        /* don't read IRLAG0 -- it hangs system */
169
170         print_pic(key, 0xff1ff518, "IRPOL    ");
171         print_pic(key, 0xff1ff51c, "IRRCNT   ");
172         print_pic(key, 0xff1ff520, "IRMASKINT");
173         print_pic(key, 0xff1ff524, "IRMASKEXT");
174
175         return;
176 }
177
178
179 void print_addr(char *hdr, char *key, u32 addr)
180 {
181         printk("%s %s:0x%08x=0x%08x\n", hdr, key, addr, TX4927_RD(addr));
182         return;
183 }
184
185
186 void dump_180(char *key)
187 {
188         u32 i;
189
190         for (i = 0x80000180; i < 0x80000180 + 0x80; i += 4) {
191                 print_addr("180", key, i);
192         }
193         return;
194 }
195
196
197 void dump_eh0(char *key)
198 {
199         int i;
200         extern unsigned long exception_handlers[];
201
202         for (i = (int) exception_handlers;
203              i < (int) (exception_handlers + 20); i += 4) {
204                 print_addr("eh0", key, i);
205         }
206
207         return;
208 }
209
210 void pk0(void)
211 {
212         volatile u32 val;
213
214         __asm__ __volatile__("ori %0, $26, 0":"=r"(val)
215             );
216         printk("k0=[0x%08x]\n", val);
217 }
218 #endif