blob: b6472fc88a991cb3a53aa3d8cae9e2077ace4f29 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (C) 2003 PMC-Sierra Inc.
3 * Author: Manish Lachwani (lachwani@pmc-sierra.com)
4 *
5 * Copyright (C) 2004 by Ralf Baechle (ralf@linux-mips.org)
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#include <linux/bcd.h>
28#include <linux/init.h>
29#include <linux/kernel.h>
Paul Gortmakerf9ded5692012-02-28 19:24:46 -050030#include <linux/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/types.h>
32#include <linux/mm.h>
33#include <linux/bootmem.h>
34#include <linux/swap.h>
35#include <linux/ioport.h>
36#include <linux/sched.h>
37#include <linux/interrupt.h>
38#include <linux/timex.h>
39#include <linux/termios.h>
40#include <linux/tty.h>
41#include <linux/serial.h>
42#include <linux/serial_core.h>
Yinghai Lub187f182007-07-18 00:49:10 -070043#include <linux/serial_8250.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45#include <asm/time.h>
46#include <asm/bootinfo.h>
47#include <asm/page.h>
48#include <asm/io.h>
49#include <asm/irq.h>
50#include <asm/processor.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#include <asm/reboot.h>
52#include <asm/serial.h>
53#include <asm/titan_dep.h>
54#include <asm/m48t37.h>
55
56#include "setup.h"
57
58unsigned char titan_ge_mac_addr_base[6] = {
59 // 0x00, 0x03, 0xcc, 0x1d, 0x22, 0x00
60 0x00, 0xe0, 0x04, 0x00, 0x00, 0x21
61};
62
Ralf Baechle348c9132007-07-28 11:46:15 +010063unsigned long cpu_clock_freq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064unsigned long yosemite_base;
65
66static struct m48t37_rtc *m48t37_base;
67
68void __init bus_error_init(void)
69{
70 /* Do nothing */
71}
72
73
Martin Schwidefskyd4f587c2009-08-14 15:47:31 +020074void read_persistent_clock(struct timespec *ts)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075{
76 unsigned int year, month, day, hour, min, sec;
Atsushi Nemoto53c2df22005-11-03 01:01:15 +090077 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Atsushi Nemoto53c2df22005-11-03 01:01:15 +090079 spin_lock_irqsave(&rtc_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 /* Stop the update to the time */
81 m48t37_base->control = 0x40;
82
Adrian Bunk02112db2008-10-18 20:28:44 -070083 year = bcd2bin(m48t37_base->year);
84 year += bcd2bin(m48t37_base->century) * 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
Adrian Bunk02112db2008-10-18 20:28:44 -070086 month = bcd2bin(m48t37_base->month);
87 day = bcd2bin(m48t37_base->date);
88 hour = bcd2bin(m48t37_base->hour);
89 min = bcd2bin(m48t37_base->min);
90 sec = bcd2bin(m48t37_base->sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92 /* Start the update to the time again */
93 m48t37_base->control = 0x00;
Atsushi Nemoto53c2df22005-11-03 01:01:15 +090094 spin_unlock_irqrestore(&rtc_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
Martin Schwidefskyd4f587c2009-08-14 15:47:31 +020096 ts->tv_sec = mktime(year, month, day, hour, min, sec);
97 ts->tv_nsec = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098}
99
Ralf Baechle4b550482007-10-11 23:46:08 +0100100int rtc_mips_set_time(unsigned long tim)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101{
102 struct rtc_time tm;
Atsushi Nemoto53c2df22005-11-03 01:01:15 +0900103 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
Ralf Baechle90b02342007-10-11 23:46:09 +0100105 /*
106 * Convert to a more useful format -- note months count from 0
107 * and years from 1900
108 */
109 rtc_time_to_tm(tim, &tm);
110 tm.tm_year += 1900;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 tm.tm_mon += 1;
112
Atsushi Nemoto53c2df22005-11-03 01:01:15 +0900113 spin_lock_irqsave(&rtc_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 /* enable writing */
115 m48t37_base->control = 0x80;
116
117 /* year */
Adrian Bunk02112db2008-10-18 20:28:44 -0700118 m48t37_base->year = bin2bcd(tm.tm_year % 100);
119 m48t37_base->century = bin2bcd(tm.tm_year / 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
121 /* month */
Adrian Bunk02112db2008-10-18 20:28:44 -0700122 m48t37_base->month = bin2bcd(tm.tm_mon);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
124 /* day */
Adrian Bunk02112db2008-10-18 20:28:44 -0700125 m48t37_base->date = bin2bcd(tm.tm_mday);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
127 /* hour/min/sec */
Adrian Bunk02112db2008-10-18 20:28:44 -0700128 m48t37_base->hour = bin2bcd(tm.tm_hour);
129 m48t37_base->min = bin2bcd(tm.tm_min);
130 m48t37_base->sec = bin2bcd(tm.tm_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
132 /* day of week -- not really used, but let's keep it up-to-date */
Adrian Bunk02112db2008-10-18 20:28:44 -0700133 m48t37_base->day = bin2bcd(tm.tm_wday + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
135 /* disable writing */
136 m48t37_base->control = 0x00;
Atsushi Nemoto53c2df22005-11-03 01:01:15 +0900137 spin_unlock_irqrestore(&rtc_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
139 return 0;
140}
141
Ralf Baechle4b550482007-10-11 23:46:08 +0100142void __init plat_time_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143{
Ralf Baechle348c9132007-07-28 11:46:15 +0100144 mips_hpt_frequency = cpu_clock_freq / 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145mips_hpt_frequency = 33000000 * 3 * 5;
146}
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148unsigned long ocd_base;
149
150EXPORT_SYMBOL(ocd_base);
151
152/*
153 * Common setup before any secondaries are started
154 */
155
156#define TITAN_UART_CLK 3686400
157#define TITAN_SERIAL_BASE_BAUD (TITAN_UART_CLK / 16)
158#define TITAN_SERIAL_IRQ 4
159#define TITAN_SERIAL_BASE 0xfd000008UL
160
161static void __init py_map_ocd(void)
162{
163 ocd_base = (unsigned long) ioremap(OCD_BASE, OCD_SIZE);
164 if (!ocd_base)
165 panic("Mapping OCD failed - game over. Your score is 0.");
166
167 /* Kludge for PMON bug ... */
168 OCD_WRITE(0x0710, 0x0ffff029);
169}
170
171static void __init py_uart_setup(void)
172{
Mathieu Desnoyers811d9442007-02-03 23:16:51 -0500173#ifdef CONFIG_SERIAL_8250
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 struct uart_port up;
175
176 /*
177 * Register to interrupt zero because we share the interrupt with
178 * the serial driver which we don't properly support yet.
179 */
180 memset(&up, 0, sizeof(up));
181 up.membase = (unsigned char *) ioremap(TITAN_SERIAL_BASE, 8);
182 up.irq = TITAN_SERIAL_IRQ;
183 up.uartclk = TITAN_UART_CLK;
184 up.regshift = 0;
185 up.iotype = UPIO_MEM;
Russell King59a675b2006-02-05 10:52:29 +0000186 up.flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 up.line = 0;
188
189 if (early_serial_setup(&up))
190 printk(KERN_ERR "Early serial init of port 0 failed\n");
Mathieu Desnoyers811d9442007-02-03 23:16:51 -0500191#endif /* CONFIG_SERIAL_8250 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192}
193
194static void __init py_rtc_setup(void)
195{
196 m48t37_base = ioremap(YOSEMITE_RTC_BASE, YOSEMITE_RTC_SIZE);
197 if (!m48t37_base)
198 printk(KERN_ERR "Mapping the RTC failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199}
200
201/* Not only time init but that's what the hook it's called through is named */
202static void __init py_late_time_init(void)
203{
204 py_map_ocd();
205 py_uart_setup();
206 py_rtc_setup();
207}
208
Ralf Baechle2925aba2006-06-18 01:32:22 +0100209void __init plat_mem_setup(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 late_time_init = py_late_time_init;
212
213 /* Add memory regions */
214 add_memory_region(0x00000000, 0x10000000, BOOT_MEM_RAM);
215
216#if 0 /* XXX Crash ... */
217 OCD_WRITE(RM9000x2_OCD_HTSC,
218 OCD_READ(RM9000x2_OCD_HTSC) | HYPERTRANSPORT_ENABLE);
219
220 /* Set the BAR. Shifted mode */
221 OCD_WRITE(RM9000x2_OCD_HTBAR0, HYPERTRANSPORT_BAR0_ADDR);
222 OCD_WRITE(RM9000x2_OCD_HTMASK0, HYPERTRANSPORT_SIZE0);
223#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224}