ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / mips / ddb5xxx / ddb5074 / setup.c
1 /*
2  *  arch/mips/ddb5074/setup.c -- NEC DDB Vrc-5074 setup routines
3  *
4  *  Copyright (C) 2000 Geert Uytterhoeven <geert@sonycom.com>
5  *                     Sony Software Development Center Europe (SDCE), Brussels
6  */
7 #include <linux/config.h>
8 #include <linux/init.h>
9 #include <linux/kbd_ll.h>
10 #include <linux/kernel.h>
11 #include <linux/kdev_t.h>
12 #include <linux/types.h>
13 #include <linux/sched.h>
14 #include <linux/pci.h>
15 #include <linux/ide.h>
16 #include <linux/ioport.h>
17 #include <linux/irq.h>
18
19 #include <asm/addrspace.h>
20 #include <asm/bcache.h>
21 #include <asm/irq.h>
22 #include <asm/reboot.h>
23 #include <asm/gdb-stub.h>
24 #include <asm/time.h>
25 #include <asm/nile4.h>
26 #include <asm/ddb5xxx/ddb5074.h>
27 #include <asm/ddb5xxx/ddb5xxx.h>
28
29 #ifdef CONFIG_KGDB
30 extern void rs_kgdb_hook(int);
31 extern void breakpoint(void);
32 #endif
33
34 static void (*back_to_prom) (void) = (void (*)(void)) 0xbfc00000;
35
36 static void ddb_machine_restart(char *command)
37 {
38         u32 t;
39
40         /* PCI cold reset */
41         t = nile4_in32(NILE4_PCICTRL + 4);
42         t |= 0x40000000;
43         nile4_out32(NILE4_PCICTRL + 4, t);
44         /* CPU cold reset */
45         t = nile4_in32(NILE4_CPUSTAT);
46         t |= 1;
47         nile4_out32(NILE4_CPUSTAT, t);
48         /* Call the PROM */
49         back_to_prom();
50 }
51
52 static void ddb_machine_halt(void)
53 {
54         printk("DDB Vrc-5074 halted.\n");
55         do {
56         } while (1);
57 }
58
59 static void ddb_machine_power_off(void)
60 {
61         printk("DDB Vrc-5074 halted. Please turn off the power.\n");
62         do {
63         } while (1);
64 }
65
66 extern void ddb_irq_setup(void);
67 extern void rtc_ds1386_init(unsigned long base);
68
69 extern void (*board_timer_setup) (struct irqaction * irq);
70
71 static void __init ddb_timer_init(struct irqaction *irq)
72 {
73         /* set the clock to 1 Hz */
74         nile4_out32(NILE4_T2CTRL, 1000000);
75         /* enable the General-Purpose Timer */
76         nile4_out32(NILE4_T2CTRL + 4, 0x00000001);
77         /* reset timer */
78         nile4_out32(NILE4_T2CNTR, 0);
79         /* enable interrupt */
80         setup_irq(nile4_to_irq(NILE4_INT_GPT), irq);
81         nile4_enable_irq(nile4_to_irq(NILE4_INT_GPT));
82         change_c0_status(ST0_IM,
83                           IE_IRQ0 | IE_IRQ1 | IE_IRQ2 | IE_IRQ3 | IE_IRQ4);
84
85 }
86
87 static void __init ddb_time_init(void)
88 {
89         /* we have ds1396 RTC chip */
90         rtc_ds1386_init(KSEG1ADDR(DDB_PCI_MEM_BASE));
91 }
92
93
94
95 static void __init ddb5074_setup(void)
96 {
97         extern int panic_timeout;
98
99         irq_setup = ddb_irq_setup;
100         set_io_port_base(NILE4_PCI_IO_BASE);
101         isa_slot_offset = NILE4_PCI_MEM_BASE;
102         board_timer_setup = ddb_timer_init;
103         board_time_init = ddb_time_init;
104
105
106         _machine_restart = ddb_machine_restart;
107         _machine_halt = ddb_machine_halt;
108         _machine_power_off = ddb_machine_power_off;
109
110         ddb_out32(DDB_BAR0, 0);
111
112         ddb_set_pmr(DDB_PCIINIT0, DDB_PCICMD_IO, 0, 0x10);
113         ddb_set_pmr(DDB_PCIINIT1, DDB_PCICMD_MEM, DDB_PCI_MEM_BASE , 0x10);
114
115         /* Reboot on panic */
116         panic_timeout = 180;
117 }
118
119 early_initcall(ddb5074_setup);
120
121 #define USE_NILE4_SERIAL        0
122
123 #if USE_NILE4_SERIAL
124 #define ns16550_in(reg)         nile4_in8((reg)*8)
125 #define ns16550_out(reg, val)   nile4_out8((reg)*8, (val))
126 #else
127 #define NS16550_BASE            (NILE4_PCI_IO_BASE+0x03f8)
128 static inline u8 ns16550_in(u32 reg)
129 {
130         return *(volatile u8 *) (NS16550_BASE + reg);
131 }
132
133 static inline void ns16550_out(u32 reg, u8 val)
134 {
135         *(volatile u8 *) (NS16550_BASE + reg) = val;
136 }
137 #endif
138
139 #define NS16550_RBR             0
140 #define NS16550_THR             0
141 #define NS16550_DLL             0
142 #define NS16550_IER             1
143 #define NS16550_DLM             1
144 #define NS16550_FCR             2
145 #define NS16550_IIR             2
146 #define NS16550_LCR             3
147 #define NS16550_MCR             4
148 #define NS16550_LSR             5
149 #define NS16550_MSR             6
150 #define NS16550_SCR             7
151
152 #define NS16550_LSR_DR          0x01    /* Data ready */
153 #define NS16550_LSR_OE          0x02    /* Overrun */
154 #define NS16550_LSR_PE          0x04    /* Parity error */
155 #define NS16550_LSR_FE          0x08    /* Framing error */
156 #define NS16550_LSR_BI          0x10    /* Break */
157 #define NS16550_LSR_THRE        0x20    /* Xmit holding register empty */
158 #define NS16550_LSR_TEMT        0x40    /* Xmitter empty */
159 #define NS16550_LSR_ERR         0x80    /* Error */
160
161
162 void _serinit(void)
163 {
164 #if USE_NILE4_SERIAL
165         ns16550_out(NS16550_LCR, 0x80);
166         ns16550_out(NS16550_DLM, 0x00);
167         ns16550_out(NS16550_DLL, 0x36); /* 9600 baud */
168         ns16550_out(NS16550_LCR, 0x00);
169         ns16550_out(NS16550_LCR, 0x03);
170         ns16550_out(NS16550_FCR, 0x47);
171 #else
172         /* done by PMON */
173 #endif
174 }
175
176 void _putc(char c)
177 {
178         while (!(ns16550_in(NS16550_LSR) & NS16550_LSR_THRE));
179         ns16550_out(NS16550_THR, c);
180         if (c == '\n') {
181                 while (!(ns16550_in(NS16550_LSR) & NS16550_LSR_THRE));
182                 ns16550_out(NS16550_THR, '\r');
183         }
184 }
185
186 void _puts(const char *s)
187 {
188         char c;
189         while ((c = *s++))
190                 _putc(c);
191 }
192
193 char _getc(void)
194 {
195         while (!(ns16550_in(NS16550_LSR) & NS16550_LSR_DR));
196         return ns16550_in(NS16550_RBR);
197 }
198
199 int _testc(void)
200 {
201         return (ns16550_in(NS16550_LSR) & NS16550_LSR_DR) != 0;
202 }
203
204
205 /*
206  *  Hexadecimal 7-segment LED
207  */
208 void ddb5074_led_hex(int hex)
209 {
210         outb(hex, 0x80);
211 }
212
213
214 /*
215  *  LEDs D2 and D3, connected to the GPIO pins of the PMU in the ALi M1543
216  */
217 struct pci_dev *pci_pmu = NULL;
218
219 void ddb5074_led_d2(int on)
220 {
221         u8 t;
222
223         if (pci_pmu) {
224                 pci_read_config_byte(pci_pmu, 0x7e, &t);
225                 if (on)
226                         t &= 0x7f;
227                 else
228                         t |= 0x80;
229                 pci_write_config_byte(pci_pmu, 0x7e, t);
230         }
231 }
232
233 void ddb5074_led_d3(int on)
234 {
235         u8 t;
236
237         if (pci_pmu) {
238                 pci_read_config_byte(pci_pmu, 0x7e, &t);
239                 if (on)
240                         t &= 0xbf;
241                 else
242                         t |= 0x40;
243                 pci_write_config_byte(pci_pmu, 0x7e, t);
244         }
245 }