c39d1d6968cdec1c2ccc31ed00cd40b1da8cd97f
[linux-flexiantxendom0-3.2.10.git] / arch / mips / ite-boards / generic / it8172_setup.c
1 /*
2  *
3  * BRIEF MODULE DESCRIPTION
4  *      IT8172/QED5231 board setup.
5  *
6  * Copyright 2000 MontaVista Software Inc.
7  * Author: MontaVista Software, Inc.
8  *              ppopov@mvista.com or source@mvista.com
9  *
10  *  This program is free software; you can redistribute  it and/or modify it
11  *  under  the terms of  the GNU General  Public License as published by the
12  *  Free Software Foundation;  either version 2 of the  License, or (at your
13  *  option) any later version.
14  *
15  *  THIS  SOFTWARE  IS PROVIDED   ``AS  IS'' AND   ANY  EXPRESS OR IMPLIED
16  *  WARRANTIES,   INCLUDING, BUT NOT  LIMITED  TO, THE IMPLIED WARRANTIES OF
17  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
18  *  NO  EVENT  SHALL   THE AUTHOR  BE    LIABLE FOR ANY   DIRECT, INDIRECT,
19  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  *  NOT LIMITED   TO, PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS OF
21  *  USE, DATA,  OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
22  *  ANY THEORY OF LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT
23  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  *  You should have received a copy of the  GNU General Public License along
27  *  with this program; if not, write  to the Free Software Foundation, Inc.,
28  *  675 Mass Ave, Cambridge, MA 02139, USA.
29  */
30 #include <linux/config.h>
31 #include <linux/init.h>
32 #include <linux/sched.h>
33 #include <linux/ioport.h>
34 #include <linux/console.h>
35 #include <linux/mc146818rtc.h>
36 #include <linux/serial_reg.h>
37 #include <linux/root_dev.h>
38
39 #include <asm/cpu.h>
40 #include <asm/bootinfo.h>
41 #include <asm/irq.h>
42 #include <asm/mipsregs.h>
43 #include <asm/reboot.h>
44 #include <asm/it8172/it8172.h>
45 #include <asm/it8712.h>
46 #ifdef CONFIG_PC_KEYB
47 #include <asm/keyboard.h>
48 #endif
49
50 #if defined(CONFIG_SERIAL_CONSOLE) || defined(CONFIG_PROM_CONSOLE)
51 extern void console_setup(char *, int *);
52 char serial_console[20];
53 #endif
54
55 extern struct rtc_ops it8172_rtc_ops;
56 extern struct resource ioport_resource;
57 extern unsigned long mips_io_port_base;
58 #ifdef CONFIG_BLK_DEV_IDE
59 extern struct ide_ops std_ide_ops;
60 extern struct ide_ops *ide_ops;
61 #endif
62 #ifdef CONFIG_PC_KEYB
63 extern struct kbd_ops std_kbd_ops;
64 int init_8712_keyboard(void);
65 #endif
66
67 extern int SearchIT8712(void);
68 extern void InitLPCInterface(void);
69 extern char * __init prom_getcmdline(void);
70 extern void it8172_restart(char *command);
71 extern void it8172_halt(void);
72 extern void it8172_power_off(void);
73
74 #ifdef CONFIG_IT8172_REVC
75 struct {
76     struct resource ram;
77     struct resource pci_mem;
78     struct resource pci_io;
79     struct resource flash;
80     struct resource boot;
81 } it8172_resources = {
82     { "RAM",           0,          0,          IORESOURCE_MEM }, /* to be initted */
83     { "PCI Mem",       0x10000000, 0x13FFFFFF, IORESOURCE_MEM },
84     { "PCI I/O",       0x14000000, 0x17FFFFFF                 },
85     { "Flash",         0x08000000, 0x0CFFFFFF                 },
86     { "Boot ROM",      0x1FC00000, 0x1FFFFFFF                 }
87 };
88 #else
89 struct {
90     struct resource ram;
91     struct resource pci_mem0;
92     struct resource pci_mem1;
93     struct resource pci_io;
94     struct resource pci_mem2;
95     struct resource pci_mem3;
96     struct resource flash;
97     struct resource boot;
98 } it8172_resources = {
99     { "RAM",           0,          0,          IORESOURCE_MEM }, /* to be initted */
100     { "PCI Mem0",      0x0C000000, 0x0FFFFFFF, IORESOURCE_MEM },
101     { "PCI Mem1",      0x10000000, 0x13FFFFFF, IORESOURCE_MEM },
102     { "PCI I/O",       0x14000000, 0x17FFFFFF                 },
103     { "PCI Mem2",      0x1A000000, 0x1BFFFFFF, IORESOURCE_MEM },
104     { "PCI Mem3",      0x1C000000, 0x1FBFFFFF, IORESOURCE_MEM },
105     { "Flash",         0x08000000, 0x0CFFFFFF                 },
106     { "Boot ROM",      0x1FC00000, 0x1FFFFFFF                 }
107 };
108 #endif
109
110
111 void __init it8172_init_ram_resource(unsigned long memsize)
112 {
113         it8172_resources.ram.end = memsize;
114 }
115
116 void __init it8172_setup(void)
117 {
118         unsigned short dsr;
119         char *argptr;
120
121         argptr = prom_getcmdline();
122 #ifdef CONFIG_SERIAL_CONSOLE
123         if ((argptr = strstr(argptr, "console=")) == NULL) {
124                 argptr = prom_getcmdline();
125                 strcat(argptr, " console=ttyS0,115200");
126         }
127 #endif    
128
129         clear_cp0_status(ST0_FR);
130         rtc_ops = &it8172_rtc_ops;
131
132         _machine_restart = it8172_restart;
133         _machine_halt = it8172_halt;
134         _machine_power_off = it8172_power_off;
135
136         /*
137         * IO/MEM resources. 
138         *
139         * revisit this area.
140         */
141         mips_io_port_base = KSEG1;
142         ioport_resource.start = it8172_resources.pci_io.start;
143         ioport_resource.end = it8172_resources.pci_io.end;
144 #ifdef CONFIG_IT8172_REVC
145         iomem_resource.start = it8172_resources.pci_mem.start;
146         iomem_resource.end = it8172_resources.pci_mem.end;
147 #else
148         iomem_resource.start = it8172_resources.pci_mem0.start;
149         iomem_resource.end = it8172_resources.pci_mem3.end;
150 #endif
151
152 #ifdef CONFIG_BLK_DEV_INITRD
153         ROOT_DEV = Root_RAM0;
154 #endif
155
156         /*
157          * Pull enabled devices out of standby
158          */
159         IT_IO_READ16(IT_PM_DSR, dsr);
160 #ifdef CONFIG_SOUND_IT8172
161         dsr &= ~IT_PM_DSR_ACSB;
162 #else
163         dsr |= IT_PM_DSR_ACSB;
164 #endif  
165 #ifdef CONFIG_BLK_DEV_IT8172
166         dsr &= ~IT_PM_DSR_IDESB;
167         ide_ops = &std_ide_ops;
168 #else
169         dsr |= IT_PM_DSR_IDESB;
170 #endif
171         IT_IO_WRITE16(IT_PM_DSR, dsr);
172
173 #ifdef CONFIG_FB
174         conswitchp = &dummy_con;
175 #endif
176
177         InitLPCInterface();
178
179 #ifdef CONFIG_MIPS_ITE8172
180         if (SearchIT8712()) {
181                 printk("Found IT8712 Super IO\n");
182                 // enable IT8712 serial port
183                 LPCSetConfig(LDN_SERIAL1, 0x30, 0x01); /* enable */
184                 LPCSetConfig(LDN_SERIAL1, 0x23, 0x01); /* clock selection */
185 #ifdef CONFIG_PC_KEYB
186                 if (init_8712_keyboard()) {
187                         printk("Unable to initialize keyboard\n");
188                         LPCSetConfig(LDN_KEYBOARD, 0x30, 0x0); /* disable keyboard */
189                 }
190                 else {
191                         LPCSetConfig(LDN_KEYBOARD, 0x30, 0x1); /* enable keyboard */
192                         LPCSetConfig(LDN_KEYBOARD, 0xf0, 0x2);
193                         LPCSetConfig(LDN_KEYBOARD, 0x71, 0x3);
194
195                         LPCSetConfig(LDN_MOUSE, 0x30, 0x1); /* enable mouse */
196
197                         LPCSetConfig(0x4, 0x30, 0x1);
198                         LPCSetConfig(0x4, 0xf4, LPCGetConfig(0x4, 0xf4) | 0x80);
199
200                         if ((LPCGetConfig(LDN_KEYBOARD, 0x30) == 0) || 
201                                         (LPCGetConfig(LDN_MOUSE, 0x30) == 0)) 
202                                 printk("Error: keyboard or mouse not enabled\n");
203
204                         kbd_ops = &std_kbd_ops;
205                 }
206 #endif
207         }
208         else {
209                 printk("IT8712 Super IO not found\n");
210         }
211 #endif
212
213 #ifdef CONFIG_IT8172_CIR
214         {
215                 unsigned long data;
216                 //printk("Enabling CIR0\n");
217                 IT_IO_READ16(IT_PM_DSR, data);
218                 data &= ~IT_PM_DSR_CIR0SB;
219                 IT_IO_WRITE16(IT_PM_DSR, data);
220                 //printk("DSR register: %x\n", (unsigned)IT_IO_READ16(IT_PM_DSR, data));
221         }
222 #endif
223 #ifdef CONFIG_IT8172_SCR0
224         {
225                 unsigned i; 
226                 /* Enable Smart Card Reader 0 */
227                 /* First power it up */
228                 IT_IO_READ16(IT_PM_DSR, i);
229                 i &= ~IT_PM_DSR_SCR0SB;
230                 IT_IO_WRITE16(IT_PM_DSR, i);
231                 /* Then initialize its registers */
232                 outb(( IT_SCR_SFR_GATE_UART_OFF     << IT_SCR_SFR_GATE_UART_BIT
233                       |IT_SCR_SFR_FET_CHARGE_213_US << IT_SCR_SFR_FET_CHARGE_BIT
234                       |IT_SCR_SFR_CARD_FREQ_3_5_MHZ << IT_SCR_SFR_CARD_FREQ_BIT
235                       |IT_SCR_SFR_FET_ACTIVE_INVERT << IT_SCR_SFR_FET_ACTIVE_BIT
236                       |IT_SCR_SFR_ENABLE_ON         << IT_SCR_SFR_ENABLE_BIT),
237                      IT8172_PCI_IO_BASE + IT_SCR0_BASE + IT_SCR_SFR);
238                 outb(IT_SCR_SCDR_RESET_MODE_ASYNC << IT_SCR_SCDR_RESET_MODE_BIT,
239                      IT8172_PCI_IO_BASE + IT_SCR0_BASE + IT_SCR_SCDR);
240         }
241 #endif /* CONFIG_IT8172_SCR0 */
242 #ifdef CONFIG_IT8172_SCR1
243         {
244                 unsigned i; 
245                 /* Enable Smart Card Reader 1 */
246                 /* First power it up */
247                 IT_IO_READ16(IT_PM_DSR, i);
248                 i &= ~IT_PM_DSR_SCR1SB;
249                 IT_IO_WRITE16(IT_PM_DSR, i);
250                 /* Then initialize its registers */
251                 outb(( IT_SCR_SFR_GATE_UART_OFF     << IT_SCR_SFR_GATE_UART_BIT
252                       |IT_SCR_SFR_FET_CHARGE_213_US << IT_SCR_SFR_FET_CHARGE_BIT
253                       |IT_SCR_SFR_CARD_FREQ_3_5_MHZ << IT_SCR_SFR_CARD_FREQ_BIT
254                       |IT_SCR_SFR_FET_ACTIVE_INVERT << IT_SCR_SFR_FET_ACTIVE_BIT
255                       |IT_SCR_SFR_ENABLE_ON         << IT_SCR_SFR_ENABLE_BIT),
256                      IT8172_PCI_IO_BASE + IT_SCR1_BASE + IT_SCR_SFR);
257                 outb(IT_SCR_SCDR_RESET_MODE_ASYNC << IT_SCR_SCDR_RESET_MODE_BIT,
258                      IT8172_PCI_IO_BASE + IT_SCR1_BASE + IT_SCR_SCDR);
259         }
260 #endif /* CONFIG_IT8172_SCR1 */
261 }
262
263
264 #ifdef CONFIG_PC_KEYB
265 /*
266  * According to the ITE Special BIOS Note for waking up the 
267  * keyboard controller...
268  */
269 int init_8712_keyboard()
270 {
271         unsigned int cmd_port = 0x14000064;
272         unsigned int data_port = 0x14000060;
273         unsigned char data;
274         int i;
275
276         outb(0xaa, cmd_port); /* send self-test cmd */
277         i = 0;
278         while (!(inb(cmd_port) & 0x1)) { /* wait output buffer full */
279                 i++;
280                 if (i > 0xffffff)
281                         return 1;
282         }
283
284         data = inb(data_port);
285         outb(0xcb, cmd_port); /* set ps2 mode */
286         while (inb(cmd_port) & 0x2) { /* wait while input buffer full */
287                 i++;
288                 if (i > 0xffffff)
289                         return 1;
290         }
291         outb(0x01, data_port);
292         while (inb(cmd_port) & 0x2) { /* wait while input buffer full */
293                 i++;
294                 if (i > 0xffffff)
295                         return 1;
296         }
297
298         outb(0x60, cmd_port); /* write 8042 command byte */
299         while (inb(cmd_port) & 0x2) { /* wait while input buffer full */
300                 i++;
301                 if (i > 0xffffff)
302                         return 1;
303         }
304         outb(0x45, data_port); /* at interface, keyboard enabled, system flag */
305         while (inb(cmd_port) & 0x2) { /* wait while input buffer full */
306                 i++;
307                 if (i > 0xffffff)
308                         return 1;
309         }
310
311         outb(0xae, cmd_port); /* enable interface */
312         return 0;
313 }
314 #endif