Path: blob/master/arch/mips/pmc-sierra/yosemite/setup.c
15118 views
/*1* Copyright (C) 2003 PMC-Sierra Inc.2* Author: Manish Lachwani ([email protected])3*4* Copyright (C) 2004 by Ralf Baechle ([email protected])5*6* This program is free software; you can redistribute it and/or modify it7* under the terms of the GNU General Public License as published by the8* Free Software Foundation; either version 2 of the License, or (at your9* option) any later version.10*11* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED12* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF13* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN14* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,15* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT16* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF17* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON18* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT19* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF20* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.21*22* You should have received a copy of the GNU General Public License along23* with this program; if not, write to the Free Software Foundation, Inc.,24* 675 Mass Ave, Cambridge, MA 02139, USA.25*/26#include <linux/bcd.h>27#include <linux/init.h>28#include <linux/kernel.h>29#include <linux/types.h>30#include <linux/mm.h>31#include <linux/bootmem.h>32#include <linux/swap.h>33#include <linux/ioport.h>34#include <linux/sched.h>35#include <linux/interrupt.h>36#include <linux/timex.h>37#include <linux/termios.h>38#include <linux/tty.h>39#include <linux/serial.h>40#include <linux/serial_core.h>41#include <linux/serial_8250.h>4243#include <asm/time.h>44#include <asm/bootinfo.h>45#include <asm/page.h>46#include <asm/io.h>47#include <asm/irq.h>48#include <asm/processor.h>49#include <asm/reboot.h>50#include <asm/serial.h>51#include <asm/titan_dep.h>52#include <asm/m48t37.h>5354#include "setup.h"5556unsigned char titan_ge_mac_addr_base[6] = {57// 0x00, 0x03, 0xcc, 0x1d, 0x22, 0x00580x00, 0xe0, 0x04, 0x00, 0x00, 0x2159};6061unsigned long cpu_clock_freq;62unsigned long yosemite_base;6364static struct m48t37_rtc *m48t37_base;6566void __init bus_error_init(void)67{68/* Do nothing */69}707172void read_persistent_clock(struct timespec *ts)73{74unsigned int year, month, day, hour, min, sec;75unsigned long flags;7677spin_lock_irqsave(&rtc_lock, flags);78/* Stop the update to the time */79m48t37_base->control = 0x40;8081year = bcd2bin(m48t37_base->year);82year += bcd2bin(m48t37_base->century) * 100;8384month = bcd2bin(m48t37_base->month);85day = bcd2bin(m48t37_base->date);86hour = bcd2bin(m48t37_base->hour);87min = bcd2bin(m48t37_base->min);88sec = bcd2bin(m48t37_base->sec);8990/* Start the update to the time again */91m48t37_base->control = 0x00;92spin_unlock_irqrestore(&rtc_lock, flags);9394ts->tv_sec = mktime(year, month, day, hour, min, sec);95ts->tv_nsec = 0;96}9798int rtc_mips_set_time(unsigned long tim)99{100struct rtc_time tm;101unsigned long flags;102103/*104* Convert to a more useful format -- note months count from 0105* and years from 1900106*/107rtc_time_to_tm(tim, &tm);108tm.tm_year += 1900;109tm.tm_mon += 1;110111spin_lock_irqsave(&rtc_lock, flags);112/* enable writing */113m48t37_base->control = 0x80;114115/* year */116m48t37_base->year = bin2bcd(tm.tm_year % 100);117m48t37_base->century = bin2bcd(tm.tm_year / 100);118119/* month */120m48t37_base->month = bin2bcd(tm.tm_mon);121122/* day */123m48t37_base->date = bin2bcd(tm.tm_mday);124125/* hour/min/sec */126m48t37_base->hour = bin2bcd(tm.tm_hour);127m48t37_base->min = bin2bcd(tm.tm_min);128m48t37_base->sec = bin2bcd(tm.tm_sec);129130/* day of week -- not really used, but let's keep it up-to-date */131m48t37_base->day = bin2bcd(tm.tm_wday + 1);132133/* disable writing */134m48t37_base->control = 0x00;135spin_unlock_irqrestore(&rtc_lock, flags);136137return 0;138}139140void __init plat_time_init(void)141{142mips_hpt_frequency = cpu_clock_freq / 2;143mips_hpt_frequency = 33000000 * 3 * 5;144}145146unsigned long ocd_base;147148EXPORT_SYMBOL(ocd_base);149150/*151* Common setup before any secondaries are started152*/153154#define TITAN_UART_CLK 3686400155#define TITAN_SERIAL_BASE_BAUD (TITAN_UART_CLK / 16)156#define TITAN_SERIAL_IRQ 4157#define TITAN_SERIAL_BASE 0xfd000008UL158159static void __init py_map_ocd(void)160{161ocd_base = (unsigned long) ioremap(OCD_BASE, OCD_SIZE);162if (!ocd_base)163panic("Mapping OCD failed - game over. Your score is 0.");164165/* Kludge for PMON bug ... */166OCD_WRITE(0x0710, 0x0ffff029);167}168169static void __init py_uart_setup(void)170{171#ifdef CONFIG_SERIAL_8250172struct uart_port up;173174/*175* Register to interrupt zero because we share the interrupt with176* the serial driver which we don't properly support yet.177*/178memset(&up, 0, sizeof(up));179up.membase = (unsigned char *) ioremap(TITAN_SERIAL_BASE, 8);180up.irq = TITAN_SERIAL_IRQ;181up.uartclk = TITAN_UART_CLK;182up.regshift = 0;183up.iotype = UPIO_MEM;184up.flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST;185up.line = 0;186187if (early_serial_setup(&up))188printk(KERN_ERR "Early serial init of port 0 failed\n");189#endif /* CONFIG_SERIAL_8250 */190}191192static void __init py_rtc_setup(void)193{194m48t37_base = ioremap(YOSEMITE_RTC_BASE, YOSEMITE_RTC_SIZE);195if (!m48t37_base)196printk(KERN_ERR "Mapping the RTC failed\n");197}198199/* Not only time init but that's what the hook it's called through is named */200static void __init py_late_time_init(void)201{202py_map_ocd();203py_uart_setup();204py_rtc_setup();205}206207void __init plat_mem_setup(void)208{209late_time_init = py_late_time_init;210211/* Add memory regions */212add_memory_region(0x00000000, 0x10000000, BOOT_MEM_RAM);213214#if 0 /* XXX Crash ... */215OCD_WRITE(RM9000x2_OCD_HTSC,216OCD_READ(RM9000x2_OCD_HTSC) | HYPERTRANSPORT_ENABLE);217218/* Set the BAR. Shifted mode */219OCD_WRITE(RM9000x2_OCD_HTBAR0, HYPERTRANSPORT_BAR0_ADDR);220OCD_WRITE(RM9000x2_OCD_HTMASK0, HYPERTRANSPORT_SIZE0);221#endif222}223224225