Path: blob/master/arch/mips/txx9/generic/setup_tx4927.c
10818 views
/*1* TX4927 setup routines2* Based on linux/arch/mips/txx9/rbtx4938/setup.c,3* and RBTX49xx patch from CELF patch archive.4*5* 2003-2005 (c) MontaVista Software, Inc.6* (C) Copyright TOSHIBA CORPORATION 2000-2001, 2004-20077*8* This file is subject to the terms and conditions of the GNU General Public9* License. See the file "COPYING" in the main directory of this archive10* for more details.11*/12#include <linux/init.h>13#include <linux/ioport.h>14#include <linux/delay.h>15#include <linux/param.h>16#include <linux/ptrace.h>17#include <linux/mtd/physmap.h>18#include <asm/reboot.h>19#include <asm/traps.h>20#include <asm/txx9irq.h>21#include <asm/txx9tmr.h>22#include <asm/txx9pio.h>23#include <asm/txx9/generic.h>24#include <asm/txx9/dmac.h>25#include <asm/txx9/tx4927.h>2627static void __init tx4927_wdr_init(void)28{29/* report watchdog reset status */30if (____raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_WDRST)31pr_warning("Watchdog reset detected at 0x%lx\n",32read_c0_errorepc());33/* clear WatchDogReset (W1C) */34tx4927_ccfg_set(TX4927_CCFG_WDRST);35/* do reset on watchdog */36tx4927_ccfg_set(TX4927_CCFG_WR);37}3839void __init tx4927_wdt_init(void)40{41txx9_wdt_init(TX4927_TMR_REG(2) & 0xfffffffffULL);42}4344static void tx4927_machine_restart(char *command)45{46local_irq_disable();47pr_emerg("Rebooting (with %s watchdog reset)...\n",48(____raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_WDREXEN) ?49"external" : "internal");50/* clear watchdog status */51tx4927_ccfg_set(TX4927_CCFG_WDRST); /* W1C */52txx9_wdt_now(TX4927_TMR_REG(2) & 0xfffffffffULL);53while (!(____raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_WDRST))54;55mdelay(10);56if (____raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_WDREXEN) {57pr_emerg("Rebooting (with internal watchdog reset)...\n");58/* External WDRST failed. Do internal watchdog reset */59tx4927_ccfg_clear(TX4927_CCFG_WDREXEN);60}61/* fallback */62(*_machine_halt)();63}6465void show_registers(struct pt_regs *regs);66static int tx4927_be_handler(struct pt_regs *regs, int is_fixup)67{68int data = regs->cp0_cause & 4;69console_verbose();70pr_err("%cBE exception at %#lx\n", data ? 'D' : 'I', regs->cp0_epc);71pr_err("ccfg:%llx, toea:%llx\n",72(unsigned long long)____raw_readq(&tx4927_ccfgptr->ccfg),73(unsigned long long)____raw_readq(&tx4927_ccfgptr->toea));74#ifdef CONFIG_PCI75tx4927_report_pcic_status();76#endif77show_registers(regs);78panic("BusError!");79}80static void __init tx4927_be_init(void)81{82board_be_handler = tx4927_be_handler;83}8485static struct resource tx4927_sdram_resource[4];8687void __init tx4927_setup(void)88{89int i;90__u32 divmode;91unsigned int cpuclk = 0;92u64 ccfg;9394txx9_reg_res_init(TX4927_REV_PCODE(), TX4927_REG_BASE,95TX4927_REG_SIZE);96set_c0_config(TX49_CONF_CWFON);9798/* SDRAMC,EBUSC are configured by PROM */99for (i = 0; i < 8; i++) {100if (!(TX4927_EBUSC_CR(i) & 0x8))101continue; /* disabled */102txx9_ce_res[i].start = (unsigned long)TX4927_EBUSC_BA(i);103txx9_ce_res[i].end =104txx9_ce_res[i].start + TX4927_EBUSC_SIZE(i) - 1;105request_resource(&iomem_resource, &txx9_ce_res[i]);106}107108/* clocks */109ccfg = ____raw_readq(&tx4927_ccfgptr->ccfg);110if (txx9_master_clock) {111/* calculate gbus_clock and cpu_clock from master_clock */112divmode = (__u32)ccfg & TX4927_CCFG_DIVMODE_MASK;113switch (divmode) {114case TX4927_CCFG_DIVMODE_8:115case TX4927_CCFG_DIVMODE_10:116case TX4927_CCFG_DIVMODE_12:117case TX4927_CCFG_DIVMODE_16:118txx9_gbus_clock = txx9_master_clock * 4; break;119default:120txx9_gbus_clock = txx9_master_clock;121}122switch (divmode) {123case TX4927_CCFG_DIVMODE_2:124case TX4927_CCFG_DIVMODE_8:125cpuclk = txx9_gbus_clock * 2; break;126case TX4927_CCFG_DIVMODE_2_5:127case TX4927_CCFG_DIVMODE_10:128cpuclk = txx9_gbus_clock * 5 / 2; break;129case TX4927_CCFG_DIVMODE_3:130case TX4927_CCFG_DIVMODE_12:131cpuclk = txx9_gbus_clock * 3; break;132case TX4927_CCFG_DIVMODE_4:133case TX4927_CCFG_DIVMODE_16:134cpuclk = txx9_gbus_clock * 4; break;135}136txx9_cpu_clock = cpuclk;137} else {138if (txx9_cpu_clock == 0)139txx9_cpu_clock = 200000000; /* 200MHz */140/* calculate gbus_clock and master_clock from cpu_clock */141cpuclk = txx9_cpu_clock;142divmode = (__u32)ccfg & TX4927_CCFG_DIVMODE_MASK;143switch (divmode) {144case TX4927_CCFG_DIVMODE_2:145case TX4927_CCFG_DIVMODE_8:146txx9_gbus_clock = cpuclk / 2; break;147case TX4927_CCFG_DIVMODE_2_5:148case TX4927_CCFG_DIVMODE_10:149txx9_gbus_clock = cpuclk * 2 / 5; break;150case TX4927_CCFG_DIVMODE_3:151case TX4927_CCFG_DIVMODE_12:152txx9_gbus_clock = cpuclk / 3; break;153case TX4927_CCFG_DIVMODE_4:154case TX4927_CCFG_DIVMODE_16:155txx9_gbus_clock = cpuclk / 4; break;156}157switch (divmode) {158case TX4927_CCFG_DIVMODE_8:159case TX4927_CCFG_DIVMODE_10:160case TX4927_CCFG_DIVMODE_12:161case TX4927_CCFG_DIVMODE_16:162txx9_master_clock = txx9_gbus_clock / 4; break;163default:164txx9_master_clock = txx9_gbus_clock;165}166}167/* change default value to udelay/mdelay take reasonable time */168loops_per_jiffy = txx9_cpu_clock / HZ / 2;169170/* CCFG */171tx4927_wdr_init();172/* clear BusErrorOnWrite flag (W1C) */173tx4927_ccfg_set(TX4927_CCFG_BEOW);174/* enable Timeout BusError */175if (txx9_ccfg_toeon)176tx4927_ccfg_set(TX4927_CCFG_TOE);177178/* DMA selection */179txx9_clear64(&tx4927_ccfgptr->pcfg, TX4927_PCFG_DMASEL_ALL);180181/* Use external clock for external arbiter */182if (!(____raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_PCIARB))183txx9_clear64(&tx4927_ccfgptr->pcfg, TX4927_PCFG_PCICLKEN_ALL);184185printk(KERN_INFO "%s -- %dMHz(M%dMHz) CRIR:%08x CCFG:%llx PCFG:%llx\n",186txx9_pcode_str,187(cpuclk + 500000) / 1000000,188(txx9_master_clock + 500000) / 1000000,189(__u32)____raw_readq(&tx4927_ccfgptr->crir),190(unsigned long long)____raw_readq(&tx4927_ccfgptr->ccfg),191(unsigned long long)____raw_readq(&tx4927_ccfgptr->pcfg));192193printk(KERN_INFO "%s SDRAMC --", txx9_pcode_str);194for (i = 0; i < 4; i++) {195__u64 cr = TX4927_SDRAMC_CR(i);196unsigned long base, size;197if (!((__u32)cr & 0x00000400))198continue; /* disabled */199base = (unsigned long)(cr >> 49) << 21;200size = (((unsigned long)(cr >> 33) & 0x7fff) + 1) << 21;201printk(" CR%d:%016llx", i, (unsigned long long)cr);202tx4927_sdram_resource[i].name = "SDRAM";203tx4927_sdram_resource[i].start = base;204tx4927_sdram_resource[i].end = base + size - 1;205tx4927_sdram_resource[i].flags = IORESOURCE_MEM;206request_resource(&iomem_resource, &tx4927_sdram_resource[i]);207}208printk(" TR:%09llx\n",209(unsigned long long)____raw_readq(&tx4927_sdramcptr->tr));210211/* TMR */212/* disable all timers */213for (i = 0; i < TX4927_NR_TMR; i++)214txx9_tmr_init(TX4927_TMR_REG(i) & 0xfffffffffULL);215216/* PIO */217txx9_gpio_init(TX4927_PIO_REG & 0xfffffffffULL, 0, TX4927_NUM_PIO);218__raw_writel(0, &tx4927_pioptr->maskcpu);219__raw_writel(0, &tx4927_pioptr->maskext);220221_machine_restart = tx4927_machine_restart;222board_be_init = tx4927_be_init;223}224225void __init tx4927_time_init(unsigned int tmrnr)226{227if (____raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_TINTDIS)228txx9_clockevent_init(TX4927_TMR_REG(tmrnr) & 0xfffffffffULL,229TXX9_IRQ_BASE + TX4927_IR_TMR(tmrnr),230TXX9_IMCLK);231}232233void __init tx4927_sio_init(unsigned int sclk, unsigned int cts_mask)234{235int i;236237for (i = 0; i < 2; i++)238txx9_sio_init(TX4927_SIO_REG(i) & 0xfffffffffULL,239TXX9_IRQ_BASE + TX4927_IR_SIO(i),240i, sclk, (1 << i) & cts_mask);241}242243void __init tx4927_mtd_init(int ch)244{245struct physmap_flash_data pdata = {246.width = TX4927_EBUSC_WIDTH(ch) / 8,247};248unsigned long start = txx9_ce_res[ch].start;249unsigned long size = txx9_ce_res[ch].end - start + 1;250251if (!(TX4927_EBUSC_CR(ch) & 0x8))252return; /* disabled */253txx9_physmap_flash_init(ch, start, size, &pdata);254}255256void __init tx4927_dmac_init(int memcpy_chan)257{258struct txx9dmac_platform_data plat_data = {259.memcpy_chan = memcpy_chan,260.have_64bit_regs = true,261};262263txx9_dmac_init(0, TX4927_DMA_REG & 0xfffffffffULL,264TXX9_IRQ_BASE + TX4927_IR_DMA(0), &plat_data);265}266267void __init tx4927_aclc_init(unsigned int dma_chan_out,268unsigned int dma_chan_in)269{270u64 pcfg = __raw_readq(&tx4927_ccfgptr->pcfg);271__u64 dmasel_mask = 0, dmasel = 0;272unsigned long flags;273274if (!(pcfg & TX4927_PCFG_SEL2))275return;276/* setup DMASEL (playback:ACLC ch0, capture:ACLC ch1) */277switch (dma_chan_out) {278case 0:279dmasel_mask |= TX4927_PCFG_DMASEL0_MASK;280dmasel |= TX4927_PCFG_DMASEL0_ACL0;281break;282case 2:283dmasel_mask |= TX4927_PCFG_DMASEL2_MASK;284dmasel |= TX4927_PCFG_DMASEL2_ACL0;285break;286default:287return;288}289switch (dma_chan_in) {290case 1:291dmasel_mask |= TX4927_PCFG_DMASEL1_MASK;292dmasel |= TX4927_PCFG_DMASEL1_ACL1;293break;294case 3:295dmasel_mask |= TX4927_PCFG_DMASEL3_MASK;296dmasel |= TX4927_PCFG_DMASEL3_ACL1;297break;298default:299return;300}301local_irq_save(flags);302txx9_clear64(&tx4927_ccfgptr->pcfg, dmasel_mask);303txx9_set64(&tx4927_ccfgptr->pcfg, dmasel);304local_irq_restore(flags);305txx9_aclc_init(TX4927_ACLC_REG & 0xfffffffffULL,306TXX9_IRQ_BASE + TX4927_IR_ACLC,3070, dma_chan_out, dma_chan_in);308}309310static void __init tx4927_stop_unused_modules(void)311{312__u64 pcfg, rst = 0, ckd = 0;313char buf[128];314315buf[0] = '\0';316local_irq_disable();317pcfg = ____raw_readq(&tx4927_ccfgptr->pcfg);318if (!(pcfg & TX4927_PCFG_SEL2)) {319rst |= TX4927_CLKCTR_ACLRST;320ckd |= TX4927_CLKCTR_ACLCKD;321strcat(buf, " ACLC");322}323if (rst | ckd) {324txx9_set64(&tx4927_ccfgptr->clkctr, rst);325txx9_set64(&tx4927_ccfgptr->clkctr, ckd);326}327local_irq_enable();328if (buf[0])329pr_info("%s: stop%s\n", txx9_pcode_str, buf);330}331332static int __init tx4927_late_init(void)333{334if (txx9_pcode != 0x4927)335return -ENODEV;336tx4927_stop_unused_modules();337return 0;338}339late_initcall(tx4927_late_init);340341342