| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 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> | 
|  | 30 | #include <linux/types.h> | 
|  | 31 | #include <linux/mm.h> | 
|  | 32 | #include <linux/bootmem.h> | 
|  | 33 | #include <linux/swap.h> | 
|  | 34 | #include <linux/ioport.h> | 
|  | 35 | #include <linux/sched.h> | 
|  | 36 | #include <linux/interrupt.h> | 
|  | 37 | #include <linux/timex.h> | 
|  | 38 | #include <linux/termios.h> | 
|  | 39 | #include <linux/tty.h> | 
|  | 40 | #include <linux/serial.h> | 
|  | 41 | #include <linux/serial_core.h> | 
| Yinghai Lu | b187f18 | 2007-07-18 00:49:10 -0700 | [diff] [blame] | 42 | #include <linux/serial_8250.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 |  | 
|  | 44 | #include <asm/time.h> | 
|  | 45 | #include <asm/bootinfo.h> | 
|  | 46 | #include <asm/page.h> | 
|  | 47 | #include <asm/io.h> | 
|  | 48 | #include <asm/irq.h> | 
|  | 49 | #include <asm/processor.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | #include <asm/reboot.h> | 
|  | 51 | #include <asm/serial.h> | 
|  | 52 | #include <asm/titan_dep.h> | 
|  | 53 | #include <asm/m48t37.h> | 
|  | 54 |  | 
|  | 55 | #include "setup.h" | 
|  | 56 |  | 
|  | 57 | unsigned char titan_ge_mac_addr_base[6] = { | 
|  | 58 | // 0x00, 0x03, 0xcc, 0x1d, 0x22, 0x00 | 
|  | 59 | 0x00, 0xe0, 0x04, 0x00, 0x00, 0x21 | 
|  | 60 | }; | 
|  | 61 |  | 
| Ralf Baechle | 348c913 | 2007-07-28 11:46:15 +0100 | [diff] [blame] | 62 | unsigned long cpu_clock_freq; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | unsigned long yosemite_base; | 
|  | 64 |  | 
|  | 65 | static struct m48t37_rtc *m48t37_base; | 
|  | 66 |  | 
|  | 67 | void __init bus_error_init(void) | 
|  | 68 | { | 
|  | 69 | /* Do nothing */ | 
|  | 70 | } | 
|  | 71 |  | 
|  | 72 |  | 
| Ralf Baechle | 4b55048 | 2007-10-11 23:46:08 +0100 | [diff] [blame] | 73 | unsigned long read_persistent_clock(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | { | 
|  | 75 | unsigned int year, month, day, hour, min, sec; | 
| Atsushi Nemoto | 53c2df2 | 2005-11-03 01:01:15 +0900 | [diff] [blame] | 76 | unsigned long flags; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 |  | 
| Atsushi Nemoto | 53c2df2 | 2005-11-03 01:01:15 +0900 | [diff] [blame] | 78 | spin_lock_irqsave(&rtc_lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | /* Stop the update to the time */ | 
|  | 80 | m48t37_base->control = 0x40; | 
|  | 81 |  | 
| Adrian Bunk | 02112db | 2008-10-18 20:28:44 -0700 | [diff] [blame] | 82 | year = bcd2bin(m48t37_base->year); | 
|  | 83 | year += bcd2bin(m48t37_base->century) * 100; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 |  | 
| Adrian Bunk | 02112db | 2008-10-18 20:28:44 -0700 | [diff] [blame] | 85 | month = bcd2bin(m48t37_base->month); | 
|  | 86 | day = bcd2bin(m48t37_base->date); | 
|  | 87 | hour = bcd2bin(m48t37_base->hour); | 
|  | 88 | min = bcd2bin(m48t37_base->min); | 
|  | 89 | sec = bcd2bin(m48t37_base->sec); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 |  | 
|  | 91 | /* Start the update to the time again */ | 
|  | 92 | m48t37_base->control = 0x00; | 
| Atsushi Nemoto | 53c2df2 | 2005-11-03 01:01:15 +0900 | [diff] [blame] | 93 | spin_unlock_irqrestore(&rtc_lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 |  | 
|  | 95 | return mktime(year, month, day, hour, min, sec); | 
|  | 96 | } | 
|  | 97 |  | 
| Ralf Baechle | 4b55048 | 2007-10-11 23:46:08 +0100 | [diff] [blame] | 98 | int rtc_mips_set_time(unsigned long tim) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | { | 
|  | 100 | struct rtc_time tm; | 
| Atsushi Nemoto | 53c2df2 | 2005-11-03 01:01:15 +0900 | [diff] [blame] | 101 | unsigned long flags; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 |  | 
| Ralf Baechle | 90b0234 | 2007-10-11 23:46:09 +0100 | [diff] [blame] | 103 | /* | 
|  | 104 | * Convert to a more useful format -- note months count from 0 | 
|  | 105 | * and years from 1900 | 
|  | 106 | */ | 
|  | 107 | rtc_time_to_tm(tim, &tm); | 
|  | 108 | tm.tm_year += 1900; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | tm.tm_mon += 1; | 
|  | 110 |  | 
| Atsushi Nemoto | 53c2df2 | 2005-11-03 01:01:15 +0900 | [diff] [blame] | 111 | spin_lock_irqsave(&rtc_lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | /* enable writing */ | 
|  | 113 | m48t37_base->control = 0x80; | 
|  | 114 |  | 
|  | 115 | /* year */ | 
| Adrian Bunk | 02112db | 2008-10-18 20:28:44 -0700 | [diff] [blame] | 116 | m48t37_base->year = bin2bcd(tm.tm_year % 100); | 
|  | 117 | m48t37_base->century = bin2bcd(tm.tm_year / 100); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 |  | 
|  | 119 | /* month */ | 
| Adrian Bunk | 02112db | 2008-10-18 20:28:44 -0700 | [diff] [blame] | 120 | m48t37_base->month = bin2bcd(tm.tm_mon); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 |  | 
|  | 122 | /* day */ | 
| Adrian Bunk | 02112db | 2008-10-18 20:28:44 -0700 | [diff] [blame] | 123 | m48t37_base->date = bin2bcd(tm.tm_mday); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 |  | 
|  | 125 | /* hour/min/sec */ | 
| Adrian Bunk | 02112db | 2008-10-18 20:28:44 -0700 | [diff] [blame] | 126 | m48t37_base->hour = bin2bcd(tm.tm_hour); | 
|  | 127 | m48t37_base->min = bin2bcd(tm.tm_min); | 
|  | 128 | m48t37_base->sec = bin2bcd(tm.tm_sec); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 |  | 
|  | 130 | /* day of week -- not really used, but let's keep it up-to-date */ | 
| Adrian Bunk | 02112db | 2008-10-18 20:28:44 -0700 | [diff] [blame] | 131 | m48t37_base->day = bin2bcd(tm.tm_wday + 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 |  | 
|  | 133 | /* disable writing */ | 
|  | 134 | m48t37_base->control = 0x00; | 
| Atsushi Nemoto | 53c2df2 | 2005-11-03 01:01:15 +0900 | [diff] [blame] | 135 | spin_unlock_irqrestore(&rtc_lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 |  | 
|  | 137 | return 0; | 
|  | 138 | } | 
|  | 139 |  | 
| Ralf Baechle | 4b55048 | 2007-10-11 23:46:08 +0100 | [diff] [blame] | 140 | void __init plat_time_init(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | { | 
| Ralf Baechle | 348c913 | 2007-07-28 11:46:15 +0100 | [diff] [blame] | 142 | mips_hpt_frequency = cpu_clock_freq / 2; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | mips_hpt_frequency = 33000000 * 3 * 5; | 
|  | 144 | } | 
|  | 145 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | unsigned long ocd_base; | 
|  | 147 |  | 
|  | 148 | EXPORT_SYMBOL(ocd_base); | 
|  | 149 |  | 
|  | 150 | /* | 
|  | 151 | * Common setup before any secondaries are started | 
|  | 152 | */ | 
|  | 153 |  | 
|  | 154 | #define TITAN_UART_CLK		3686400 | 
|  | 155 | #define TITAN_SERIAL_BASE_BAUD	(TITAN_UART_CLK / 16) | 
|  | 156 | #define TITAN_SERIAL_IRQ	4 | 
|  | 157 | #define TITAN_SERIAL_BASE	0xfd000008UL | 
|  | 158 |  | 
|  | 159 | static void __init py_map_ocd(void) | 
|  | 160 | { | 
|  | 161 | ocd_base = (unsigned long) ioremap(OCD_BASE, OCD_SIZE); | 
|  | 162 | if (!ocd_base) | 
|  | 163 | panic("Mapping OCD failed - game over.  Your score is 0."); | 
|  | 164 |  | 
|  | 165 | /* Kludge for PMON bug ... */ | 
|  | 166 | OCD_WRITE(0x0710, 0x0ffff029); | 
|  | 167 | } | 
|  | 168 |  | 
|  | 169 | static void __init py_uart_setup(void) | 
|  | 170 | { | 
| Mathieu Desnoyers | 811d944 | 2007-02-03 23:16:51 -0500 | [diff] [blame] | 171 | #ifdef CONFIG_SERIAL_8250 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | struct uart_port up; | 
|  | 173 |  | 
|  | 174 | /* | 
|  | 175 | * Register to interrupt zero because we share the interrupt with | 
|  | 176 | * the serial driver which we don't properly support yet. | 
|  | 177 | */ | 
|  | 178 | memset(&up, 0, sizeof(up)); | 
|  | 179 | up.membase      = (unsigned char *) ioremap(TITAN_SERIAL_BASE, 8); | 
|  | 180 | up.irq          = TITAN_SERIAL_IRQ; | 
|  | 181 | up.uartclk      = TITAN_UART_CLK; | 
|  | 182 | up.regshift     = 0; | 
|  | 183 | up.iotype       = UPIO_MEM; | 
| Russell King | 59a675b | 2006-02-05 10:52:29 +0000 | [diff] [blame] | 184 | up.flags        = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | up.line         = 0; | 
|  | 186 |  | 
|  | 187 | if (early_serial_setup(&up)) | 
|  | 188 | printk(KERN_ERR "Early serial init of port 0 failed\n"); | 
| Mathieu Desnoyers | 811d944 | 2007-02-03 23:16:51 -0500 | [diff] [blame] | 189 | #endif /* CONFIG_SERIAL_8250 */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | } | 
|  | 191 |  | 
|  | 192 | static void __init py_rtc_setup(void) | 
|  | 193 | { | 
|  | 194 | m48t37_base = ioremap(YOSEMITE_RTC_BASE, YOSEMITE_RTC_SIZE); | 
|  | 195 | if (!m48t37_base) | 
|  | 196 | printk(KERN_ERR "Mapping the RTC failed\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | } | 
|  | 198 |  | 
|  | 199 | /* Not only time init but that's what the hook it's called through is named */ | 
|  | 200 | static void __init py_late_time_init(void) | 
|  | 201 | { | 
|  | 202 | py_map_ocd(); | 
|  | 203 | py_uart_setup(); | 
|  | 204 | py_rtc_setup(); | 
|  | 205 | } | 
|  | 206 |  | 
| Ralf Baechle | 2925aba | 2006-06-18 01:32:22 +0100 | [diff] [blame] | 207 | void __init plat_mem_setup(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | late_time_init = py_late_time_init; | 
|  | 210 |  | 
|  | 211 | /* Add memory regions */ | 
|  | 212 | add_memory_region(0x00000000, 0x10000000, BOOT_MEM_RAM); | 
|  | 213 |  | 
|  | 214 | #if 0 /* XXX Crash ...  */ | 
|  | 215 | OCD_WRITE(RM9000x2_OCD_HTSC, | 
|  | 216 | OCD_READ(RM9000x2_OCD_HTSC) | HYPERTRANSPORT_ENABLE); | 
|  | 217 |  | 
|  | 218 | /* Set the BAR. Shifted mode */ | 
|  | 219 | OCD_WRITE(RM9000x2_OCD_HTBAR0, HYPERTRANSPORT_BAR0_ADDR); | 
|  | 220 | OCD_WRITE(RM9000x2_OCD_HTMASK0, HYPERTRANSPORT_SIZE0); | 
|  | 221 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | } |