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