Path: blob/master/arch/mips/txx9/generic/setup_tx4927.c
26481 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_warn("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{82mips_set_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);184185pr_info("%s -- %dMHz(M%dMHz) CRIR:%08x CCFG:%llx PCFG:%llx\n",186txx9_pcode_str, (cpuclk + 500000) / 1000000,187(txx9_master_clock + 500000) / 1000000,188(__u32)____raw_readq(&tx4927_ccfgptr->crir),189____raw_readq(&tx4927_ccfgptr->ccfg),190____raw_readq(&tx4927_ccfgptr->pcfg));191192pr_info("%s SDRAMC --", txx9_pcode_str);193for (i = 0; i < 4; i++) {194__u64 cr = TX4927_SDRAMC_CR(i);195unsigned long base, size;196if (!((__u32)cr & 0x00000400))197continue; /* disabled */198base = (unsigned long)(cr >> 49) << 21;199size = (((unsigned long)(cr >> 33) & 0x7fff) + 1) << 21;200pr_cont(" CR%d:%016llx", i, cr);201tx4927_sdram_resource[i].name = "SDRAM";202tx4927_sdram_resource[i].start = base;203tx4927_sdram_resource[i].end = base + size - 1;204tx4927_sdram_resource[i].flags = IORESOURCE_MEM;205request_resource(&iomem_resource, &tx4927_sdram_resource[i]);206}207pr_cont(" TR:%09llx\n", ____raw_readq(&tx4927_sdramcptr->tr));208209/* TMR */210/* disable all timers */211for (i = 0; i < TX4927_NR_TMR; i++)212txx9_tmr_init(TX4927_TMR_REG(i) & 0xfffffffffULL);213214/* PIO */215__raw_writel(0, &tx4927_pioptr->maskcpu);216__raw_writel(0, &tx4927_pioptr->maskext);217218_machine_restart = tx4927_machine_restart;219board_be_init = tx4927_be_init;220}221222void __init tx4927_time_init(unsigned int tmrnr)223{224if (____raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_TINTDIS)225txx9_clockevent_init(TX4927_TMR_REG(tmrnr) & 0xfffffffffULL,226TXX9_IRQ_BASE + TX4927_IR_TMR(tmrnr),227TXX9_IMCLK);228}229230void __init tx4927_sio_init(unsigned int sclk, unsigned int cts_mask)231{232int i;233234for (i = 0; i < 2; i++)235txx9_sio_init(TX4927_SIO_REG(i) & 0xfffffffffULL,236TXX9_IRQ_BASE + TX4927_IR_SIO(i),237i, sclk, (1 << i) & cts_mask);238}239240void __init tx4927_mtd_init(int ch)241{242struct physmap_flash_data pdata = {243.width = TX4927_EBUSC_WIDTH(ch) / 8,244};245unsigned long start = txx9_ce_res[ch].start;246unsigned long size = txx9_ce_res[ch].end - start + 1;247248if (!(TX4927_EBUSC_CR(ch) & 0x8))249return; /* disabled */250txx9_physmap_flash_init(ch, start, size, &pdata);251}252253void __init tx4927_dmac_init(int memcpy_chan)254{255struct txx9dmac_platform_data plat_data = {256.memcpy_chan = memcpy_chan,257.have_64bit_regs = true,258};259260txx9_dmac_init(0, TX4927_DMA_REG & 0xfffffffffULL,261TXX9_IRQ_BASE + TX4927_IR_DMA(0), &plat_data);262}263264void __init tx4927_aclc_init(unsigned int dma_chan_out,265unsigned int dma_chan_in)266{267u64 pcfg = __raw_readq(&tx4927_ccfgptr->pcfg);268__u64 dmasel_mask = 0, dmasel = 0;269unsigned long flags;270271if (!(pcfg & TX4927_PCFG_SEL2))272return;273/* setup DMASEL (playback:ACLC ch0, capture:ACLC ch1) */274switch (dma_chan_out) {275case 0:276dmasel_mask |= TX4927_PCFG_DMASEL0_MASK;277dmasel |= TX4927_PCFG_DMASEL0_ACL0;278break;279case 2:280dmasel_mask |= TX4927_PCFG_DMASEL2_MASK;281dmasel |= TX4927_PCFG_DMASEL2_ACL0;282break;283default:284return;285}286switch (dma_chan_in) {287case 1:288dmasel_mask |= TX4927_PCFG_DMASEL1_MASK;289dmasel |= TX4927_PCFG_DMASEL1_ACL1;290break;291case 3:292dmasel_mask |= TX4927_PCFG_DMASEL3_MASK;293dmasel |= TX4927_PCFG_DMASEL3_ACL1;294break;295default:296return;297}298local_irq_save(flags);299txx9_clear64(&tx4927_ccfgptr->pcfg, dmasel_mask);300txx9_set64(&tx4927_ccfgptr->pcfg, dmasel);301local_irq_restore(flags);302txx9_aclc_init(TX4927_ACLC_REG & 0xfffffffffULL,303TXX9_IRQ_BASE + TX4927_IR_ACLC,3040, dma_chan_out, dma_chan_in);305}306307static void __init tx4927_stop_unused_modules(void)308{309__u64 pcfg, rst = 0, ckd = 0;310char buf[128];311312buf[0] = '\0';313local_irq_disable();314pcfg = ____raw_readq(&tx4927_ccfgptr->pcfg);315if (!(pcfg & TX4927_PCFG_SEL2)) {316rst |= TX4927_CLKCTR_ACLRST;317ckd |= TX4927_CLKCTR_ACLCKD;318strcat(buf, " ACLC");319}320if (rst | ckd) {321txx9_set64(&tx4927_ccfgptr->clkctr, rst);322txx9_set64(&tx4927_ccfgptr->clkctr, ckd);323}324local_irq_enable();325if (buf[0])326pr_info("%s: stop%s\n", txx9_pcode_str, buf);327}328329static int __init tx4927_late_init(void)330{331if (txx9_pcode != 0x4927)332return -ENODEV;333tx4927_stop_unused_modules();334return 0;335}336late_initcall(tx4927_late_init);337338339