Merge git://git.infradead.org/~dwmw2/cafe-2.6
[sfrench/cifs-2.6.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/init.h>
21 #include <linux/sched.h>
22 #include <linux/ioport.h>
23 #include <linux/irq.h>
24 #include <linux/mm.h>
25 #include <linux/delay.h>
26 #include <linux/interrupt.h>
27 #include <linux/serial_pnx8xxx.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 pnx8550_time_init(void);
53 extern void rs_kgdb_hook(int tty_no);
54 extern void prom_printf(char *fmt, ...);
55 extern char *prom_getcmdline(void);
56
57 struct resource standard_io_resources[] = {
58         {
59                 .start  = 0x00,
60                 .end    = 0x1f,
61                 .name   = "dma1",
62                 .flags  = IORESOURCE_BUSY
63         }, {
64                 .start  = 0x40,
65                 .end    = 0x5f,
66                 .name   = "timer",
67                 .flags  = IORESOURCE_BUSY
68         }, {
69                 .start  = 0x80,
70                 .end    = 0x8f,
71                 .name   = "dma page reg",
72                 .flags  = IORESOURCE_BUSY
73         }, {
74                 .start  = 0xc0,
75                 .end    = 0xdf,
76                 .name   = "dma2",
77                 .flags  = IORESOURCE_BUSY
78         },
79 };
80
81 #define STANDARD_IO_RESOURCES (sizeof(standard_io_resources)/sizeof(struct resource))
82
83 extern struct resource pci_io_resource;
84 extern struct resource pci_mem_resource;
85
86 /* Return the total size of DRAM-memory, (RANK0 + RANK1) */
87 unsigned long get_system_mem_size(void)
88 {
89         /* Read IP2031_RANK0_ADDR_LO */
90         unsigned long dram_r0_lo = inl(PCI_BASE | 0x65010);
91         /* Read IP2031_RANK1_ADDR_HI */
92         unsigned long dram_r1_hi = inl(PCI_BASE | 0x65018);
93
94         return dram_r1_hi - dram_r0_lo + 1;
95 }
96
97 int pnx8550_console_port = -1;
98
99 void __init plat_mem_setup(void)
100 {
101         int i;
102         char* argptr;
103
104         board_setup();  /* board specific setup */
105
106         _machine_restart = pnx8550_machine_restart;
107         _machine_halt = pnx8550_machine_halt;
108         pm_power_off = pnx8550_machine_power_off;
109
110         board_time_init = pnx8550_time_init;
111
112         /* Clear the Global 2 Register, PCI Inta Output Enable Registers
113            Bit 1:Enable DAC Powerdown
114           -> 0:DACs are enabled and are working normally
115              1:DACs are powerdown
116            Bit 0:Enable of PCI inta output
117           -> 0 = Disable PCI inta output
118              1 = Enable PCI inta output
119         */
120         PNX8550_GLB2_ENAB_INTA_O = 0;
121
122         /* IO/MEM resources. */
123         set_io_port_base(KSEG1);
124         ioport_resource.start = 0;
125         ioport_resource.end = ~0;
126         iomem_resource.start = 0;
127         iomem_resource.end = ~0;
128
129         /* Request I/O space for devices on this board */
130         for (i = 0; i < STANDARD_IO_RESOURCES; i++)
131                 request_resource(&ioport_resource, standard_io_resources + i);
132
133         /* Place the Mode Control bit for GPIO pin 16 in primary function */
134         /* Pin 16 is used by UART1, UA1_TX                                */
135         outl((PNX8550_GPIO_MODE_PRIMOP << PNX8550_GPIO_MC_16_BIT) |
136                         (PNX8550_GPIO_MODE_PRIMOP << PNX8550_GPIO_MC_17_BIT),
137                         PNX8550_GPIO_MC1);
138
139         argptr = prom_getcmdline();
140         if ((argptr = strstr(argptr, "console=ttyS")) != NULL) {
141                 argptr += strlen("console=ttyS");
142                 pnx8550_console_port = *argptr == '0' ? 0 : 1;
143
144                 /* We must initialize the UART (console) before prom_printf */
145                 /* Set LCR to 8-bit and BAUD to 38400 (no 5)                */
146                 ip3106_lcr(UART_BASE, pnx8550_console_port) =
147                         PNX8XXX_UART_LCR_8BIT;
148                 ip3106_baud(UART_BASE, pnx8550_console_port) = 5;
149         }
150
151 #ifdef CONFIG_KGDB
152         argptr = prom_getcmdline();
153         if ((argptr = strstr(argptr, "kgdb=ttyS")) != NULL) {
154                 int line;
155                 argptr += strlen("kgdb=ttyS");
156                 line = *argptr == '0' ? 0 : 1;
157                 rs_kgdb_hook(line);
158                 prom_printf("KGDB: Using ttyS%i for session, "
159                                 "please connect your debugger\n", line ? 1 : 0);
160         }
161 #endif
162         return;
163 }