Merge rsync://rsync.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[pandora-kernel.git] / arch / mips / philips / pnx8550 / common / setup.c
1 /*
2  *
3  * 2.6 port, Embedded Alley Solutions, Inc
4  *
5  *  Based on Per Hallsmark, per.hallsmark@mvista.com
6  *
7  *  This program is free software; you can distribute it and/or modify it
8  *  under the terms of the GNU General Public License (Version 2) as
9  *  published by the Free Software Foundation.
10  *
11  *  This program is distributed in the hope it will be useful, but WITHOUT
12  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  *  for more details.
15  *
16  *  You should have received a copy of the GNU General Public License along
17  *  with this program; if not, write to the Free Software Foundation, Inc.,
18  *  59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
19  */
20 #include <linux/config.h>
21 #include <linux/init.h>
22 #include <linux/sched.h>
23 #include <linux/ioport.h>
24 #include <linux/mm.h>
25 #include <linux/delay.h>
26 #include <linux/interrupt.h>
27 #include <linux/serial_ip3106.h>
28 #include <linux/pm.h>
29
30 #include <asm/cpu.h>
31 #include <asm/bootinfo.h>
32 #include <asm/irq.h>
33 #include <asm/mipsregs.h>
34 #include <asm/reboot.h>
35 #include <asm/pgtable.h>
36 #include <asm/time.h>
37
38 #include <glb.h>
39 #include <int.h>
40 #include <pci.h>
41 #include <uart.h>
42 #include <nand.h>
43
44 extern void prom_printf(char *fmt, ...);
45
46 extern void __init board_setup(void);
47 extern void pnx8550_machine_restart(char *);
48 extern void pnx8550_machine_halt(void);
49 extern void pnx8550_machine_power_off(void);
50 extern struct resource ioport_resource;
51 extern struct resource iomem_resource;
52 extern void (*board_time_init)(void);
53 extern void pnx8550_time_init(void);
54 extern void (*board_timer_setup)(struct irqaction *irq);
55 extern void pnx8550_timer_setup(struct irqaction *irq);
56 extern void rs_kgdb_hook(int tty_no);
57 extern void prom_printf(char *fmt, ...);
58 extern char *prom_getcmdline(void);
59
60 struct resource standard_io_resources[] = {
61         {
62                 .start  = .0x00,
63                 .end    = 0x1f,
64                 .name   = "dma1",
65                 .flags  = IORESOURCE_BUSY
66         }, {
67                 .start  = 0x40,
68                 .end    = 0x5f,
69                 .name   = "timer",
70                 .flags  = IORESOURCE_BUSY
71         }, {
72                 .start  = 0x80,
73                 .end    = 0x8f,
74                 .name   = "dma page reg",
75                 .flags  = IORESOURCE_BUSY
76         }, {
77                 .start  = 0xc0,
78                 .end    = 0xdf,
79                 .name   = "dma2",
80                 .flags  = IORESOURCE_BUSY
81         },
82 };
83
84 #define STANDARD_IO_RESOURCES (sizeof(standard_io_resources)/sizeof(struct resource))
85
86 extern struct resource pci_io_resource;
87 extern struct resource pci_mem_resource;
88
89 /* Return the total size of DRAM-memory, (RANK0 + RANK1) */
90 unsigned long get_system_mem_size(void)
91 {
92         /* Read IP2031_RANK0_ADDR_LO */
93         unsigned long dram_r0_lo = inl(PCI_BASE | 0x65010);
94         /* Read IP2031_RANK1_ADDR_HI */
95         unsigned long dram_r1_hi = inl(PCI_BASE | 0x65018);
96
97         return dram_r1_hi - dram_r0_lo + 1;
98 }
99
100 int pnx8550_console_port = -1;
101
102 void __init plat_mem_setup(void)
103 {
104         int i;
105         char* argptr;
106
107         board_setup();  /* board specific setup */
108
109         _machine_restart = pnx8550_machine_restart;
110         _machine_halt = pnx8550_machine_halt;
111         pm_power_off = pnx8550_machine_power_off;
112
113         board_time_init = pnx8550_time_init;
114         board_timer_setup = pnx8550_timer_setup;
115
116         /* Clear the Global 2 Register, PCI Inta Output Enable Registers
117            Bit 1:Enable DAC Powerdown
118           -> 0:DACs are enabled and are working normally
119              1:DACs are powerdown
120            Bit 0:Enable of PCI inta output
121           -> 0 = Disable PCI inta output
122              1 = Enable PCI inta output
123         */
124         PNX8550_GLB2_ENAB_INTA_O = 0;
125
126         /* IO/MEM resources. */
127         set_io_port_base(KSEG1);
128         ioport_resource.start = 0;
129         ioport_resource.end = ~0;
130         iomem_resource.start = 0;
131         iomem_resource.end = ~0;
132
133         /* Request I/O space for devices on this board */
134         for (i = 0; i < STANDARD_IO_RESOURCES; i++)
135                 request_resource(&ioport_resource, standard_io_resources + i);
136
137         /* Place the Mode Control bit for GPIO pin 16 in primary function */
138         /* Pin 16 is used by UART1, UA1_TX                                */
139         outl((PNX8550_GPIO_MODE_PRIMOP << PNX8550_GPIO_MC_16_BIT) |
140                         (PNX8550_GPIO_MODE_PRIMOP << PNX8550_GPIO_MC_17_BIT),
141                         PNX8550_GPIO_MC1);
142
143         argptr = prom_getcmdline();
144         if ((argptr = strstr(argptr, "console=ttyS")) != NULL) {
145                 argptr += strlen("console=ttyS");
146                 pnx8550_console_port = *argptr == '0' ? 0 : 1;
147
148                 /* We must initialize the UART (console) before prom_printf */
149                 /* Set LCR to 8-bit and BAUD to 38400 (no 5)                */
150                 ip3106_lcr(UART_BASE, pnx8550_console_port) =
151                         IP3106_UART_LCR_8BIT;
152                 ip3106_baud(UART_BASE, pnx8550_console_port) = 5;
153         }
154
155 #ifdef CONFIG_KGDB
156         argptr = prom_getcmdline();
157         if ((argptr = strstr(argptr, "kgdb=ttyS")) != NULL) {
158                 int line;
159                 argptr += strlen("kgdb=ttyS");
160                 line = *argptr == '0' ? 0 : 1;
161                 rs_kgdb_hook(line);
162                 prom_printf("KGDB: Using ttyS%i for session, "
163                                 "please connect your debugger\n", line ? 1 : 0);
164         }
165 #endif
166         return;
167 }