ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / mips / pmc-sierra / yosemite / setup.c
1 /*
2  *  arch/mips/pmc-sierra/yosemite/setup.c
3  *
4  *  Copyright (C) 2003 PMC-Sierra Inc.
5  *  Author: Manish Lachwani (lachwani@pmc-sierra.com)
6  *
7  *  This program is free software; you can redistribute  it and/or modify it
8  *  under  the terms of  the GNU General  Public License as published by the
9  *  Free Software Foundation;  either version 2 of the  License, or (at your
10  *  option) any later version.
11  *
12  *  THIS  SOFTWARE  IS PROVIDED   ``AS  IS'' AND   ANY  EXPRESS OR IMPLIED
13  *  WARRANTIES,   INCLUDING, BUT NOT  LIMITED  TO, THE IMPLIED WARRANTIES OF
14  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
15  *  NO  EVENT  SHALL   THE AUTHOR  BE    LIABLE FOR ANY   DIRECT, INDIRECT,
16  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
17  *  NOT LIMITED   TO, PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS OF
18  *  USE, DATA,  OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19  *  ANY THEORY OF LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT
20  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
21  *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22  *
23  *  You should have received a copy of the  GNU General Public License along
24  *  with this program; if not, write  to the Free Software Foundation, Inc.,
25  *  675 Mass Ave, Cambridge, MA 02139, USA.
26  */
27
28 #include <linux/init.h>
29 #include <linux/kernel.h>
30 #include <linux/types.h>
31 #include <linux/mc146818rtc.h>
32 #include <linux/mm.h>
33 #include <linux/swap.h>
34 #include <linux/ioport.h>
35 #include <linux/sched.h>
36 #include <linux/interrupt.h>
37 #include <linux/pci.h>
38 #include <linux/timex.h>
39 #include <linux/vmalloc.h>
40 #include <asm/time.h>
41 #include <asm/bootinfo.h>
42 #include <asm/page.h>
43 #include <asm/bootinfo.h>
44 #include <asm/io.h>
45 #include <asm/irq.h>
46 #include <asm/processor.h>
47 #include <asm/ptrace.h>
48 #include <asm/reboot.h>
49 #include <linux/version.h>
50 #include <linux/bootmem.h>
51 #include <linux/blk.h>
52
53 #include "setup.h"
54
55 unsigned long cpu_clock;
56 unsigned long yosemite_base;
57
58 void __init bus_error_init(void) 
59
60         /* Do nothing */ 
61 }
62
63 unsigned long m48t37y_get_time(void)
64 {
65         unsigned char   *rtc_base = YOSEMITE_RTC_BASE;
66         unsigned int    year, month, day, hour, min, sec;
67
68         /* Stop the update to the time */
69         rtc_base[0x7ff8] = 0x40;
70
71         year = CONV_BCD_TO_BIN(rtc_base[0x7fff]);
72         year += CONV_BCD_TO_BIN(rtc_base[0x7fff1]) * 100;
73
74         month = CONV_BCD_TO_BIN(rtc_base[0x7ffe]);
75         day = CONV_BCD_TO_BIN(rtc_base[0x7ffd]);
76         hour = CONV_BCD_TO_BIN(rtc_base[0x7ffb]);
77         min = CONV_BCD_TO_BIN(rtc_base[0x7ffa]);
78         sec = CONV_BCD_TO_BIN(rtc_base[0x7ff9]);
79
80         /* Start the update to the time again */
81         rtc_base[0x7ff8] = 0x00;
82
83         return mktime(year, month, day, hour, min, sec);
84 }
85
86 int m48t37y_set_time(unsigned long sec)
87 {
88         unsigned char   *rtc_base = YOSEMITE_RTC_BASE;
89         unsigned int    year, month, day, hour, min, sec;
90
91         struct rtc_time tm;
92
93         /* convert to a more useful format -- note months count from 0 */
94         to_tm(sec, &tm);
95         tm.tm_mon += 1;
96
97         /* enable writing */
98         rtc_base[0x7ff8] = 0x80;
99
100         /* year */
101         rtc_base[0x7fff] = CONV_BIN_TO_BCD(tm.tm_year % 100);
102         rtc_base[0x7ff1] = CONV_BIN_TO_BCD(tm.tm_year / 100);
103
104         /* month */
105         rtc_base[0x7ffe] = CONV_BIN_TO_BCD(tm.tm_mon);
106
107         /* day */
108         rtc_base[0x7ffd] = CONV_BIN_TO_BCD(tm.tm_mday);
109
110         /* hour/min/sec */
111         rtc_base[0x7ffb] = CONV_BIN_TO_BCD(tm.tm_hour);
112         rtc_base[0x7ffa] = CONV_BIN_TO_BCD(tm.tm_min);
113         rtc_base[0x7ff9] = CONV_BIN_TO_BCD(tm.tm_sec);
114
115         /* day of week -- not really used, but let's keep it up-to-date */
116         rtc_base[0x7ffc] = CONV_BIN_TO_BCD(tm.tm_wday + 1);
117
118         /* disable writing */
119         rtc_base[0x7ff8] = 0x00;
120
121         return 0;
122 }
123
124 void yosemite_timer_setup(struct irqaction *irq)
125 {
126         setup_irq(6, irq);
127 }
128
129 void yosemite_time_init(void)
130 {
131         mips_counter_frequency = cpu_clock / 2;
132         board_timer_setup = yosemite_timer_setup;
133
134         rtc_get_time = m48t37y_get_time;
135         rtc_set_time = m48t37y_set_time;
136 }
137
138 static int __init pmc_yosemite_setup(void)
139 {
140         unsigned long   val = 0;
141
142         printk("PMC-Sierra Yosemite Board Setup  \n");
143         board_time_init = yosemite_time_init;
144
145         /* Add memory regions */
146         add_memory_region(0x00000000, 0x10000000, BOOT_MEM_RAM);
147         add_memory_region(0x10000000, 0x10000000, BOOT_MEM_RAM);
148
149         /* Setup the HT controller */
150         val = *(volatile uint32_t *)(HYPERTRANSPORT_CONFIG_REG);
151         val |= HYPERTRANSPORT_ENABLE;
152         *(volatile uint32_t *)(HYPERTRANSPORT_CONFIG_REG) = val;
153
154         /* Set the BAR. Shifted mode */
155         *(volatile uint32_t *)(HYPERTRANSPORT_BAR0_REG) = HYPERTRANSPORT_BAR0_ADDR;
156         *(volatile uint32_t *)(HYPERTRANSPORT_SIZE0_REG) = HYPERTRANSPORT_SIZE0;
157
158 #ifdef CONFIG_PCI
159         ioport_resource.start = 0xe0000000;
160         ioport_resource.end   = 0xe0000000 + 0x20000000 - 1;
161         iomem_resource.start  = 0xc0000000;
162         iomem_resource.end    = 0xc0000000 + 0x20000000 - 1;
163
164         pci_scan_bus(0, &titan_pci_ops, NULL);
165 #endif
166
167         return 0;
168 }
169
170 early_initcall(pmc_yosemite_setup);