Merge branch 'devel' of master.kernel.org:/home/rmk/linux-2.6-arm
[linux-2.6] / arch / sh / boards / se / 7751 / setup.c
1 /*
2  * linux/arch/sh/kernel/setup_7751se.c
3  *
4  * Copyright (C) 2000  Kazumoto Kojima
5  *
6  * Hitachi SolutionEngine Support.
7  *
8  * Modified for 7751 Solution Engine by
9  * Ian da Silva and Jeremy Siegel, 2001.
10  */
11 #include <linux/init.h>
12 #include <asm/machvec.h>
13 #include <asm/se7751.h>
14 #include <asm/io.h>
15
16 void heartbeat_7751se(void);
17 void init_7751se_IRQ(void);
18
19 #ifdef CONFIG_SH_KGDB
20 #include <asm/kgdb.h>
21 static int kgdb_uart_setup(void);
22 static struct kgdb_sermap kgdb_uart_sermap = 
23 { "ttyS", 0, kgdb_uart_setup, NULL };
24 #endif
25  
26 /*
27  * Initialize the board
28  */
29 static void __init sh7751se_setup(char **cmdline_p)
30 {
31         /* Call init_smsc() replacement to set up SuperIO. */
32         /* XXX: RTC setting comes here */
33 #ifdef CONFIG_SH_KGDB
34         kgdb_register_sermap(&kgdb_uart_sermap);
35 #endif
36 }
37
38 /*********************************************************************
39  * Currently a hack (e.g. does not interact well w/serial.c, lots of *
40  * hardcoded stuff) but may be useful if SCI/F needs debugging.      *
41  * Mostly copied from x86 code (see files asm-i386/kgdb_local.h and  *
42  * arch/i386/lib/kgdb_serial.c).                                     *
43  *********************************************************************/
44
45 #ifdef CONFIG_SH_KGDB
46 #include <linux/types.h>
47 #include <linux/serial.h>
48 #include <linux/serialP.h>
49 #include <linux/serial_reg.h>
50
51 #define COM1_PORT 0x3f8  /* Base I/O address */
52 #define COM1_IRQ  4      /* IRQ not used yet */
53 #define COM2_PORT 0x2f8  /* Base I/O address */
54 #define COM2_IRQ  3      /* IRQ not used yet */
55
56 #define SB_CLOCK 1843200 /* Serial baud clock */
57 #define SB_BASE (SB_CLOCK/16)
58 #define SB_MCR UART_MCR_OUT2 | UART_MCR_DTR | UART_MCR_RTS
59
60 struct uart_port {
61         int base;
62 };
63 #define UART_NPORTS 2
64 struct uart_port uart_ports[] = {
65         { COM1_PORT },
66         { COM2_PORT },
67 };
68 struct uart_port *kgdb_uart_port;
69
70 #define UART_IN(reg)    inb_p(kgdb_uart_port->base + reg)
71 #define UART_OUT(reg,v) outb_p((v), kgdb_uart_port->base + reg)
72
73 /* Basic read/write functions for the UART */
74 #define UART_LSR_RXCERR    (UART_LSR_BI | UART_LSR_FE | UART_LSR_PE)
75 static int kgdb_uart_getchar(void)
76 {
77         int lsr;
78         int c = -1;
79
80         while (c == -1) {
81                 lsr = UART_IN(UART_LSR);
82                 if (lsr & UART_LSR_DR) 
83                         c = UART_IN(UART_RX);
84                 if ((lsr & UART_LSR_RXCERR))
85                         c = -1;
86         }
87         return c;
88 }
89
90 static void kgdb_uart_putchar(int c)
91 {
92         while ((UART_IN(UART_LSR) & UART_LSR_THRE) == 0)
93                 ;
94         UART_OUT(UART_TX, c);
95 }
96
97 /*
98  * Initialize UART to configured/requested values.
99  * (But we don't interrupts yet, or interact w/serial.c)
100  */
101 static int kgdb_uart_setup(void)
102 {
103         int port;
104         int lcr = 0;
105         int bdiv = 0;
106
107         if (kgdb_portnum >= UART_NPORTS) {
108                 KGDB_PRINTK("uart port %d invalid.\n", kgdb_portnum);
109                 return -1;
110         }
111
112         kgdb_uart_port = &uart_ports[kgdb_portnum];
113
114         /* Init sequence from gdb_hook_interrupt */
115         UART_IN(UART_RX);
116         UART_OUT(UART_IER, 0);
117
118         UART_IN(UART_RX);       /* Serial driver comments say */
119         UART_IN(UART_IIR);      /* this clears interrupt regs */
120         UART_IN(UART_MSR);
121
122         /* Figure basic LCR values */
123         switch (kgdb_bits) {
124         case '7':
125                 lcr |= UART_LCR_WLEN7;
126                 break;
127         default: case '8': 
128                 lcr |= UART_LCR_WLEN8;
129                 break;
130         }
131         switch (kgdb_parity) {
132         case 'O':
133                 lcr |= UART_LCR_PARITY;
134                 break;
135         case 'E':
136                 lcr |= (UART_LCR_PARITY | UART_LCR_EPAR);
137                 break;
138         default: break;
139         }
140
141         /* Figure the baud rate divisor */
142         bdiv = (SB_BASE/kgdb_baud);
143         
144         /* Set the baud rate and LCR values */
145         UART_OUT(UART_LCR, (lcr | UART_LCR_DLAB));
146         UART_OUT(UART_DLL, (bdiv & 0xff));
147         UART_OUT(UART_DLM, ((bdiv >> 8) & 0xff));
148         UART_OUT(UART_LCR, lcr);
149
150         /* Set the MCR */
151         UART_OUT(UART_MCR, SB_MCR);
152
153         /* Turn off FIFOs for now */
154         UART_OUT(UART_FCR, 0);
155
156         /* Setup complete: initialize function pointers */
157         kgdb_getchar = kgdb_uart_getchar;
158         kgdb_putchar = kgdb_uart_putchar;
159
160         return 0;
161 }
162 #endif /* CONFIG_SH_KGDB */
163
164
165 /*
166  * The Machine Vector
167  */
168
169 struct sh_machine_vector mv_7751se __initmv = {
170         .mv_name                = "7751 SolutionEngine",
171         .mv_setup               = sh7751se_setup,
172         .mv_nr_irqs             = 72,
173
174         .mv_inb                 = sh7751se_inb,
175         .mv_inw                 = sh7751se_inw,
176         .mv_inl                 = sh7751se_inl,
177         .mv_outb                = sh7751se_outb,
178         .mv_outw                = sh7751se_outw,
179         .mv_outl                = sh7751se_outl,
180
181         .mv_inb_p               = sh7751se_inb_p,
182         .mv_inw_p               = sh7751se_inw,
183         .mv_inl_p               = sh7751se_inl,
184         .mv_outb_p              = sh7751se_outb_p,
185         .mv_outw_p              = sh7751se_outw,
186         .mv_outl_p              = sh7751se_outl,
187
188         .mv_insl                = sh7751se_insl,
189         .mv_outsl               = sh7751se_outsl,
190
191         .mv_init_irq            = init_7751se_IRQ,
192 #ifdef CONFIG_HEARTBEAT
193         .mv_heartbeat           = heartbeat_7751se,
194 #endif
195 };
196 ALIAS_MV(7751se)