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