1 /*
2 *
3 * By Dustin McIntire (dustin@sensoria.com) (c)2001
4 *
5 * Setup and IRQ handling code for the HD64465 companion chip.
6 * by Greg Banks <gbanks@pocketpenguins.com>
7 * Copyright (c) 2000 PocketPenguins Inc
8 *
9 * Derived from setup_hd64465.c which bore the message:
10 * Greg Banks <gbanks@pocketpenguins.com>
11 * Copyright (c) 2000 PocketPenguins Inc and
12 * Copyright (C) 2000 YAEGASHI Takeshi
13 * and setup_cqreek.c which bore message:
14 * Copyright (C) 2000 Niibe Yutaka
15 *
16 * May be copied or modified under the terms of the GNU General Public
17 * License. See linux/COPYING for more information.
18 *
19 * Setup and IRQ functions for a Hitachi Big Sur Evaluation Board.
20 *
21 */
22
23 #include <linux/config.h>
24 #include <linux/sched.h>
25 #include <linux/module.h>
26 #include <linux/kernel.h>
27 #include <linux/param.h>
28 #include <linux/ioport.h>
29 #include <linux/interrupt.h>
30 #include <linux/init.h>
31 #include <linux/irq.h>
32
33 #include <asm/io.h>
34 #include <asm/irq.h>
35 #include <asm/bitops.h>
36
37 #include <asm/io_keywest.h>
38 #include <asm/hd64465.h>
39 #include <asm/keywest.h>
40
41 //#define KEYWEST_DEBUG 3
42 #undef KEYWEST_DEBUG
43
44 //LED
45 #define ALPHA_LED 0xb1ffe038
46
47 #ifdef KEYWEST_DEBUG
48 #define DPRINTK(args...) printk(args)
49 #define DIPRINTK(n, args...) if (KEYWEST_DEBUG>(n)) printk(args)
50 #else
51 #define DPRINTK(args...)
52 #define DIPRINTK(n, args...)
53 #endif /* KEYWEST_DEBUG */
54
55 #ifdef CONFIG_HD64465
56 extern int hd64465_irq_demux(int irq);
57 #endif /* CONFIG_HD64465 */
58
59 extern void keywest_alpha(int i, char ch);
60
keywest_irq_demux(int irq)61 int keywest_irq_demux(int irq)
62 {
63 int demux_irq = irq;
64
65 #ifdef CONFIG_HD64465
66 demux_irq = hd64465_irq_demux(demux_irq);
67 #endif /* CONFIG_HD64465 */
68
69 #ifndef CONFIG_SH_GENERIC
70 demux_irq = ipr_irq_demux(demux_irq);
71 #endif
72
73 return demux_irq;
74 }
75
76
init_keywest_IRQ(void)77 void __init init_keywest_IRQ(void)
78 {
79 if (!MACH_KEYWEST) return;
80
81 }
82
keywest_puts(const char * s)83 void keywest_puts(const char* s)
84 {
85 int n = 0;
86
87 while (*s) { keywest_alpha(n++, *s++); }
88 while (n < 8) { keywest_alpha(n++, ' '); }
89 }
90 EXPORT_SYMBOL(keywest_puts);
91
keywest_printf(const char * fmt,...)92 void keywest_printf(const char* fmt, ...)
93 {
94 char buffer[32];
95 va_list ap;
96
97 va_start(ap, fmt);
98 vsprintf(buffer, fmt, ap);
99 va_end(ap);
100 keywest_puts(buffer);
101 }
102 EXPORT_SYMBOL(keywest_printf);
103
tahoe_init(void)104 static void tahoe_init(void)
105 {
106 #ifdef CONFIG_HD64465
107 if (inw(HD64465_REG_SDID) != HD64465_SDID) {
108 printk("Tahoe board is not present.\n");
109
110 return;
111 }
112
113 printk("Hitachi HD64465 chip support (%d.%d)\n",
114 inw(HD64465_REG_SRR) >> 8, inw(HD64465_REG_SRR) & 0xFF);
115
116 outw(~0, HD64465_REG_NIMR);
117 //outw(0x03, HD64465_REG_SPLLCR);
118 #ifdef CONFIG_VT
119 outw(inw(HD64465_REG_SMSCR) & (~HD64465_SMSCR_PS2ST), HD64465_REG_SMSCR); /* PS2 */
120 //outw(inw(HD64465_REG_SMSCR) & (~HD64465_SMSCR_KBCST), HD64465_REG_SMSCR); /* keyboard */
121 #endif
122 #ifdef CONFIG_SERIAL
123 outw(inw(HD64465_REG_SMSCR) & (~HD64465_SMSCR_UARTST), HD64465_REG_SMSCR); /* UART */
124 #endif
125 #ifdef CONFIG_PARPORT
126 outw(inw(HD64465_REG_SMSCR) & (~HD64465_SMSCR_PPST), HD64465_REG_SMSCR); /* PARPORT */
127 #endif
128
129 #ifdef CONFIG_PCMCIA
130 outw(inw(HD64465_REG_SMSCR) & (~HD64465_SMSCR_PC0ST), HD64465_REG_SMSCR); /* PC0 */
131 outw(inw(HD64465_REG_SMSCR) & (~HD64465_SMSCR_PC1ST), HD64465_REG_SMSCR); /* PC1 */
132
133 /* turn on PCMCIA area 5 and 6 in BCR1 */
134 * (unsigned short *) 0xffffff60 |= 0x3;
135
136 /* must put both area 5 and 6 into 8 or 16 bit mode in BCR2 */
137 * (unsigned short *) 0xffffff62 &= ~0x3c00;
138 * (unsigned short *) 0xffffff62 |= 0x2800; /* 16 bit mode */
139
140 /* setup all the PCMCIA dual purpose pins to be PCMCIA pins */
141 * (unsigned short *) 0xa4000108 = 0x0000; /* port E, all pins */
142 * (unsigned short *) 0xa400010a = 0x0000; /* port F, all pins */
143 * (unsigned short *) 0xa400010c = 0x0000; /* port G, all pins */
144
145 /* put the PCMCIA interrupts into edge triggered mode */
146 // BAD * (unsigned short *) 0xb0005004 |= 0x6000;
147
148 #endif
149
150 /* 0x3c00*/
151 * (unsigned short *) 0xa400010e &= ~0x3f00; /* port H, pins 4, 5 & 6 */
152
153 printk("Hitachi HD64465 configured at 0x%x on irq %d\n",
154 CONFIG_HD64465_IOBASE, HD64465_IRQ_BASE);
155 #endif
156 }
157
keywest_init(void)158 static void keywest_init(void)
159 {
160 keywest_printf("%s", "Key West");
161 #ifdef CONFIG_PCI
162 /*
163 * make sure these pins are in PCI mode (PINT)
164 */
165 * (unsigned short *) 0xa4000104 = 0xaaaa; /* port C, all inputs */
166 * (unsigned short *) 0xa4000108 = 0x0000; /* port E, all pins */
167 * (unsigned short *) 0xa4000110 = 0x0000; /* port J, all pins */
168 #ifndef CONFIG_PCMCIA
169 * (unsigned short *) 0xffffff62 |= 0x3c00; /* Area 5/6 in 32 bit mode */
170
171 /* Make sure Area 5 & 6 are in PCI mode */
172 * (unsigned short *) 0xffffff60 &= ~0x3; /* 5 & 6 as normal memory *
173 * (unsigned short *) 0xffffff60 &= ~0x1e0; /* ordinary memory 5 & 6 */
174 #endif
175 #endif
176 }
177
setup_keywest(void)178 int __init setup_keywest(void)
179 {
180 static int done = 0; /* run this only once */
181
182 if (!MACH_KEYWEST || done) return 0;
183 done = 1;
184
185 keywest_init();
186 tahoe_init();
187 #if defined (CONFIG_HD64465) && defined (CONFIG_SERIAL)
188 /* remap IO ports for first ISA serial port to HD64465 UART */
189 mach_port_map(0x3f8, 8, CONFIG_HD64465_IOBASE + 0x8000, 1);
190 #endif /* CONFIG_HD64465 && CONFIG_SERIAL */
191
192 return 0;
193 }
194
keywest_alpha(int i,char ch)195 void keywest_alpha(int i, char ch)
196 {
197 volatile unsigned char *alpha = (unsigned char *)ALPHA_LED;
198 *(alpha + i) = ch;
199 }
200
201 #if 0 //keywest board(rev.4) not support status LED
202 void keywest_led_on()
203 {
204 volatile unsigned char *led = (unsigned char *)STATUS_LED;
205 *led = 0x82;
206 }
207
208 void keywest_led_off()
209 {
210 volatile unsigned char *led = (unsigned char *)STATUS_LED;
211 *led = 0x02;
212 }
213 #endif
214
215 module_init(setup_keywest);
216