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/bootmem.h>
50 #include <linux/blk.h>
51
52 #include "setup.h"
53
54 unsigned long cpu_clock;
55 unsigned long yosemite_base;
56
bus_error_init(void)57 void __init bus_error_init(void)
58 {
59 /* Do nothing */
60 }
61
m48t37y_get_time(void)62 unsigned long m48t37y_get_time(void)
63 {
64 unsigned char *rtc_base = YOSEMITE_RTC_BASE;
65 unsigned int year, month, day, hour, min, sec;
66
67 /* Stop the update to the time */
68 rtc_base[0x7ff8] = 0x40;
69
70 year = CONV_BCD_TO_BIN(rtc_base[0x7fff]);
71 year += CONV_BCD_TO_BIN(rtc_base[0x7fff1]) * 100;
72
73 month = CONV_BCD_TO_BIN(rtc_base[0x7ffe]);
74 day = CONV_BCD_TO_BIN(rtc_base[0x7ffd]);
75 hour = CONV_BCD_TO_BIN(rtc_base[0x7ffb]);
76 min = CONV_BCD_TO_BIN(rtc_base[0x7ffa]);
77 sec = CONV_BCD_TO_BIN(rtc_base[0x7ff9]);
78
79 /* Start the update to the time again */
80 rtc_base[0x7ff8] = 0x00;
81
82 return mktime(year, month, day, hour, min, sec);
83 }
84
m48t37y_set_time(unsigned long sec)85 int m48t37y_set_time(unsigned long sec)
86 {
87 unsigned char *rtc_base = YOSEMITE_RTC_BASE;
88 unsigned int year, month, day, hour, min, sec;
89
90 struct rtc_time tm;
91
92 /* convert to a more useful format -- note months count from 0 */
93 to_tm(sec, &tm);
94 tm.tm_mon += 1;
95
96 /* enable writing */
97 rtc_base[0x7ff8] = 0x80;
98
99 /* year */
100 rtc_base[0x7fff] = CONV_BIN_TO_BCD(tm.tm_year % 100);
101 rtc_base[0x7ff1] = CONV_BIN_TO_BCD(tm.tm_year / 100);
102
103 /* month */
104 rtc_base[0x7ffe] = CONV_BIN_TO_BCD(tm.tm_mon);
105
106 /* day */
107 rtc_base[0x7ffd] = CONV_BIN_TO_BCD(tm.tm_mday);
108
109 /* hour/min/sec */
110 rtc_base[0x7ffb] = CONV_BIN_TO_BCD(tm.tm_hour);
111 rtc_base[0x7ffa] = CONV_BIN_TO_BCD(tm.tm_min);
112 rtc_base[0x7ff9] = CONV_BIN_TO_BCD(tm.tm_sec);
113
114 /* day of week -- not really used, but let's keep it up-to-date */
115 rtc_base[0x7ffc] = CONV_BIN_TO_BCD(tm.tm_wday + 1);
116
117 /* disable writing */
118 rtc_base[0x7ff8] = 0x00;
119
120 return 0;
121 }
122
yosemite_timer_setup(struct irqaction * irq)123 void yosemite_timer_setup(struct irqaction *irq)
124 {
125 setup_irq(6, irq);
126 }
127
yosemite_time_init(void)128 void yosemite_time_init(void)
129 {
130 mips_counter_frequency = cpu_clock / 2;
131 board_timer_setup = yosemite_timer_setup;
132
133 rtc_get_time = m48t37y_get_time;
134 rtc_set_time = m48t37y_set_time;
135 }
136
pmc_yosemite_setup(void)137 void __init pmc_yosemite_setup(void)
138 {
139 unsigned long val = 0;
140
141 printk("PMC-Sierra Yosemite Board Setup \n");
142 board_time_init = yosemite_time_init;
143
144 /* Add memory regions */
145 add_memory_region(0x00000000, 0x10000000, BOOT_MEM_RAM);
146 add_memory_region(0x10000000, 0x10000000, BOOT_MEM_RAM);
147
148 /* Setup the HT controller */
149 val = *(volatile u_int32_t *)(HYPERTRANSPORT_CONFIG_REG);
150 val |= HYPERTRANSPORT_ENABLE;
151 *(volatile u_int32_t *)(HYPERTRANSPORT_CONFIG_REG) = val;
152
153 /* Set the BAR. Shifted mode */
154 *(volatile u_int32_t *)(HYPERTRANSPORT_BAR0_REG) = HYPERTRANSPORT_BAR0_ADDR;
155 *(volatile u_int32_t *)(HYPERTRANSPORT_SIZE0_REG) = HYPERTRANSPORT_SIZE0;
156 }
157
158
159