Merge branch 'upstream' of git://lost.foo-projects.org/~ahkok/git/netdev-2.6 into...
[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/init.h>
30 #include <linux/sched.h>
31 #include <linux/ioport.h>
32 #include <linux/serial_reg.h>
33 #include <linux/major.h>
34 #include <linux/kdev_t.h>
35 #include <linux/root_dev.h>
36 #include <linux/pm.h>
37
38 #include <asm/cpu.h>
39 #include <asm/time.h>
40 #include <asm/io.h>
41 #include <asm/bootinfo.h>
42 #include <asm/irq.h>
43 #include <asm/mipsregs.h>
44 #include <asm/reboot.h>
45 #include <asm/traps.h>
46 #include <asm/it8172/it8172.h>
47 #include <asm/it8712.h>
48
49 extern struct resource ioport_resource;
50 #ifdef CONFIG_SERIO_I8042
51 int init_8712_keyboard(void);
52 #endif
53
54 extern int SearchIT8712(void);
55 extern void InitLPCInterface(void);
56 extern char * __init prom_getcmdline(void);
57 extern void it8172_restart(char *command);
58 extern void it8172_halt(void);
59 extern void it8172_power_off(void);
60
61 extern void (*board_time_init)(void);
62 extern void (*board_timer_setup)(struct irqaction *irq);
63 extern void it8172_time_init(void);
64 extern void it8172_timer_setup(struct irqaction *irq);
65
66 #ifdef CONFIG_IT8172_REVC
67 struct {
68     struct resource ram;
69     struct resource pci_mem;
70     struct resource pci_io;
71     struct resource flash;
72     struct resource boot;
73 } it8172_resources = {
74         {
75                 .start  = 0,                            /* to be initted */
76                 .end    = 0,
77                 .name   = "RAM",
78                 .flags  = IORESOURCE_MEM
79         }, {
80                 .start  = 0x10000000,
81                 .end    = 0x13FFFFFF,
82                 .name   = "PCI Mem",
83                 .flags  = IORESOURCE_MEM
84         }, {
85                 .start  = 0x14000000,
86                 .end    = 0x17FFFFFF
87                 .name   = "PCI I/O",
88         }, {
89                 .start  = 0x08000000,
90                 .end    = 0x0CFFFFFF
91                 .name   = "Flash",
92         }, {
93                 .start  = 0x1FC00000,
94                 .end    = 0x1FFFFFFF
95                 .name   = "Boot ROM",
96         }
97 };
98 #else
99 struct {
100     struct resource ram;
101     struct resource pci_mem0;
102     struct resource pci_mem1;
103     struct resource pci_io;
104     struct resource pci_mem2;
105     struct resource pci_mem3;
106     struct resource flash;
107     struct resource boot;
108 } it8172_resources = {
109         {
110                 .start  = 0,                            /* to be initted */
111                 .end    = 0,
112                 .name   = "RAM",
113                 .flags  = IORESOURCE_MEM
114         }, {
115                 .start  = 0x0C000000,
116                 .end    = 0x0FFFFFFF,
117                 .name   = "PCI Mem0",
118                 .flags  = IORESOURCE_MEM
119          }, {
120                 .start  = 0x10000000,
121                 .end    = 0x13FFFFFF,
122                 .name   = "PCI Mem1",
123                 .flags  = IORESOURCE_MEM
124          }, {
125                 .start  = 0x14000000,
126                 .end    = 0x17FFFFFF
127                 .name   = "PCI I/O",
128         }, {
129                 .start  = 0x1A000000,
130                 .end    = 0x1BFFFFFF,
131                 .name   = "PCI Mem2",
132                 .flags  = IORESOURCE_MEM
133         }, {
134                 .start  = 0x1C000000,
135                 .end    = 0x1FBFFFFF,
136                 .name   = "PCI Mem3",
137                 .flags  = IORESOURCE_MEM
138         }, {
139                 .start  = 0x08000000,
140                 .end    = 0x0CFFFFFF
141                 .name   = "Flash",
142         }, {
143                 .start  = 0x1FC00000,
144                 .end    = 0x1FFFFFFF
145                 .name   = "Boot ROM",
146         }
147 };
148 #endif
149
150
151 void __init it8172_init_ram_resource(unsigned long memsize)
152 {
153         it8172_resources.ram.end = memsize;
154 }
155
156 void __init plat_mem_setup(void)
157 {
158         unsigned short dsr;
159         char *argptr;
160
161         argptr = prom_getcmdline();
162 #ifdef CONFIG_SERIAL_CONSOLE
163         if ((argptr = strstr(argptr, "console=")) == NULL) {
164                 argptr = prom_getcmdline();
165                 strcat(argptr, " console=ttyS0,115200");
166         }
167 #endif
168
169         clear_c0_status(ST0_FR);
170
171         board_time_init = it8172_time_init;
172         board_timer_setup = it8172_timer_setup;
173
174         _machine_restart = it8172_restart;
175         _machine_halt = it8172_halt;
176         pm_power_off = it8172_power_off;
177
178         /*
179          * IO/MEM resources.
180          *
181          * revisit this area.
182          */
183         set_io_port_base(KSEG1);
184         ioport_resource.start = it8172_resources.pci_io.start;
185         ioport_resource.end = it8172_resources.pci_io.end;
186 #ifdef CONFIG_IT8172_REVC
187         iomem_resource.start = it8172_resources.pci_mem.start;
188         iomem_resource.end = it8172_resources.pci_mem.end;
189 #else
190         iomem_resource.start = it8172_resources.pci_mem0.start;
191         iomem_resource.end = it8172_resources.pci_mem3.end;
192 #endif
193
194 #ifdef CONFIG_BLK_DEV_INITRD
195         ROOT_DEV = Root_RAM0;
196 #endif
197
198         /*
199          * Pull enabled devices out of standby
200          */
201         IT_IO_READ16(IT_PM_DSR, dsr);
202
203         /*
204          * Fixme: This breaks when these drivers are modules!!!
205          */
206 #ifdef CONFIG_SOUND_IT8172
207         dsr &= ~IT_PM_DSR_ACSB;
208 #else
209         dsr |= IT_PM_DSR_ACSB;
210 #endif
211 #ifdef CONFIG_BLK_DEV_IT8172
212         dsr &= ~IT_PM_DSR_IDESB;
213 #else
214         dsr |= IT_PM_DSR_IDESB;
215 #endif
216         IT_IO_WRITE16(IT_PM_DSR, dsr);
217
218         InitLPCInterface();
219
220 #ifdef CONFIG_MIPS_ITE8172
221         if (SearchIT8712()) {
222                 printk("Found IT8712 Super IO\n");
223                 /* enable IT8712 serial port */
224                 LPCSetConfig(LDN_SERIAL1, 0x30, 0x01); /* enable */
225                 LPCSetConfig(LDN_SERIAL1, 0x23, 0x01); /* clock selection */
226 #ifdef CONFIG_SERIO_I8042
227                 if (init_8712_keyboard()) {
228                         printk("Unable to initialize keyboard\n");
229                         LPCSetConfig(LDN_KEYBOARD, 0x30, 0x0); /* disable keyboard */
230                 } else {
231                         LPCSetConfig(LDN_KEYBOARD, 0x30, 0x1); /* enable keyboard */
232                         LPCSetConfig(LDN_KEYBOARD, 0xf0, 0x2);
233                         LPCSetConfig(LDN_KEYBOARD, 0x71, 0x3);
234
235                         LPCSetConfig(LDN_MOUSE, 0x30, 0x1); /* enable mouse */
236
237                         LPCSetConfig(0x4, 0x30, 0x1);
238                         LPCSetConfig(0x4, 0xf4, LPCGetConfig(0x4, 0xf4) | 0x80);
239
240                         if ((LPCGetConfig(LDN_KEYBOARD, 0x30) == 0) ||
241                                         (LPCGetConfig(LDN_MOUSE, 0x30) == 0))
242                                 printk("Error: keyboard or mouse not enabled\n");
243
244                 }
245 #endif
246         }
247         else {
248                 printk("IT8712 Super IO not found\n");
249         }
250 #endif
251
252 #ifdef CONFIG_IT8172_CIR
253         {
254                 unsigned long data;
255                 //printk("Enabling CIR0\n");
256                 IT_IO_READ16(IT_PM_DSR, data);
257                 data &= ~IT_PM_DSR_CIR0SB;
258                 IT_IO_WRITE16(IT_PM_DSR, data);
259                 //printk("DSR register: %x\n", (unsigned)IT_IO_READ16(IT_PM_DSR, data));
260         }
261 #endif
262 #ifdef CONFIG_IT8172_SCR0
263         {
264                 unsigned i;
265                 /* Enable Smart Card Reader 0 */
266                 /* First power it up */
267                 IT_IO_READ16(IT_PM_DSR, i);
268                 i &= ~IT_PM_DSR_SCR0SB;
269                 IT_IO_WRITE16(IT_PM_DSR, i);
270                 /* Then initialize its registers */
271                 outb(( IT_SCR_SFR_GATE_UART_OFF     << IT_SCR_SFR_GATE_UART_BIT
272                       |IT_SCR_SFR_FET_CHARGE_213_US << IT_SCR_SFR_FET_CHARGE_BIT
273                       |IT_SCR_SFR_CARD_FREQ_3_5_MHZ << IT_SCR_SFR_CARD_FREQ_BIT
274                       |IT_SCR_SFR_FET_ACTIVE_INVERT << IT_SCR_SFR_FET_ACTIVE_BIT
275                       |IT_SCR_SFR_ENABLE_ON         << IT_SCR_SFR_ENABLE_BIT),
276                      IT8172_PCI_IO_BASE + IT_SCR0_BASE + IT_SCR_SFR);
277                 outb(IT_SCR_SCDR_RESET_MODE_ASYNC << IT_SCR_SCDR_RESET_MODE_BIT,
278                      IT8172_PCI_IO_BASE + IT_SCR0_BASE + IT_SCR_SCDR);
279         }
280 #endif /* CONFIG_IT8172_SCR0 */
281 #ifdef CONFIG_IT8172_SCR1
282         {
283                 unsigned i;
284                 /* Enable Smart Card Reader 1 */
285                 /* First power it up */
286                 IT_IO_READ16(IT_PM_DSR, i);
287                 i &= ~IT_PM_DSR_SCR1SB;
288                 IT_IO_WRITE16(IT_PM_DSR, i);
289                 /* Then initialize its registers */
290                 outb(( IT_SCR_SFR_GATE_UART_OFF     << IT_SCR_SFR_GATE_UART_BIT
291                       |IT_SCR_SFR_FET_CHARGE_213_US << IT_SCR_SFR_FET_CHARGE_BIT
292                       |IT_SCR_SFR_CARD_FREQ_3_5_MHZ << IT_SCR_SFR_CARD_FREQ_BIT
293                       |IT_SCR_SFR_FET_ACTIVE_INVERT << IT_SCR_SFR_FET_ACTIVE_BIT
294                       |IT_SCR_SFR_ENABLE_ON         << IT_SCR_SFR_ENABLE_BIT),
295                      IT8172_PCI_IO_BASE + IT_SCR1_BASE + IT_SCR_SFR);
296                 outb(IT_SCR_SCDR_RESET_MODE_ASYNC << IT_SCR_SCDR_RESET_MODE_BIT,
297                      IT8172_PCI_IO_BASE + IT_SCR1_BASE + IT_SCR_SCDR);
298         }
299 #endif /* CONFIG_IT8172_SCR1 */
300 }
301
302 #ifdef CONFIG_SERIO_I8042
303 /*
304  * According to the ITE Special BIOS Note for waking up the
305  * keyboard controller...
306  */
307 static int init_8712_keyboard(void)
308 {
309         unsigned int cmd_port = 0x14000064;
310         unsigned int data_port = 0x14000060;
311                                  ^^^^^^^^^^^
312         Somebody here doesn't grok the concept of io ports.
313
314         unsigned char data;
315         int i;
316
317         outb(0xaa, cmd_port); /* send self-test cmd */
318         i = 0;
319         while (!(inb(cmd_port) & 0x1)) { /* wait output buffer full */
320                 i++;
321                 if (i > 0xffffff)
322                         return 1;
323         }
324
325         data = inb(data_port);
326         outb(0xcb, cmd_port); /* set ps2 mode */
327         while (inb(cmd_port) & 0x2) { /* wait while input buffer full */
328                 i++;
329                 if (i > 0xffffff)
330                         return 1;
331         }
332         outb(0x01, data_port);
333         while (inb(cmd_port) & 0x2) { /* wait while input buffer full */
334                 i++;
335                 if (i > 0xffffff)
336                         return 1;
337         }
338
339         outb(0x60, cmd_port); /* write 8042 command byte */
340         while (inb(cmd_port) & 0x2) { /* wait while input buffer full */
341                 i++;
342                 if (i > 0xffffff)
343                         return 1;
344         }
345         outb(0x45, data_port); /* at interface, keyboard enabled, system flag */
346         while (inb(cmd_port) & 0x2) { /* wait while input buffer full */
347                 i++;
348                 if (i > 0xffffff)
349                         return 1;
350         }
351
352         outb(0xae, cmd_port); /* enable interface */
353         return 0;
354 }
355 #endif