Path: blob/master/arch/mips/txx9/generic/setup_tx4938.c
26481 views
/*1* TX4938/4937 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 <linux/platform_device.h>19#include <linux/platform_data/txx9/ndfmc.h>20#include <asm/reboot.h>21#include <asm/traps.h>22#include <asm/txx9irq.h>23#include <asm/txx9tmr.h>24#include <asm/txx9pio.h>25#include <asm/txx9/generic.h>26#include <asm/txx9/dmac.h>27#include <asm/txx9/tx4938.h>2829static void __init tx4938_wdr_init(void)30{31/* report watchdog reset status */32if (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_WDRST)33pr_warn("Watchdog reset detected at 0x%lx\n",34read_c0_errorepc());35/* clear WatchDogReset (W1C) */36tx4938_ccfg_set(TX4938_CCFG_WDRST);37/* do reset on watchdog */38tx4938_ccfg_set(TX4938_CCFG_WR);39}4041void __init tx4938_wdt_init(void)42{43txx9_wdt_init(TX4938_TMR_REG(2) & 0xfffffffffULL);44}4546static void tx4938_machine_restart(char *command)47{48local_irq_disable();49pr_emerg("Rebooting (with %s watchdog reset)...\n",50(____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_WDREXEN) ?51"external" : "internal");52/* clear watchdog status */53tx4938_ccfg_set(TX4938_CCFG_WDRST); /* W1C */54txx9_wdt_now(TX4938_TMR_REG(2) & 0xfffffffffULL);55while (!(____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_WDRST))56;57mdelay(10);58if (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_WDREXEN) {59pr_emerg("Rebooting (with internal watchdog reset)...\n");60/* External WDRST failed. Do internal watchdog reset */61tx4938_ccfg_clear(TX4938_CCFG_WDREXEN);62}63/* fallback */64(*_machine_halt)();65}6667void show_registers(struct pt_regs *regs);68static int tx4938_be_handler(struct pt_regs *regs, int is_fixup)69{70int data = regs->cp0_cause & 4;71console_verbose();72pr_err("%cBE exception at %#lx\n", data ? 'D' : 'I', regs->cp0_epc);73pr_err("ccfg:%llx, toea:%llx\n",74(unsigned long long)____raw_readq(&tx4938_ccfgptr->ccfg),75(unsigned long long)____raw_readq(&tx4938_ccfgptr->toea));76#ifdef CONFIG_PCI77tx4927_report_pcic_status();78#endif79show_registers(regs);80panic("BusError!");81}82static void __init tx4938_be_init(void)83{84mips_set_be_handler(tx4938_be_handler);85}8687static struct resource tx4938_sdram_resource[4];88static struct resource tx4938_sram_resource;8990#define TX4938_SRAM_SIZE 0x8009192void __init tx4938_setup(void)93{94int i;95__u32 divmode;96unsigned int cpuclk = 0;97u64 ccfg;9899txx9_reg_res_init(TX4938_REV_PCODE(), TX4938_REG_BASE,100TX4938_REG_SIZE);101set_c0_config(TX49_CONF_CWFON);102103/* SDRAMC,EBUSC are configured by PROM */104for (i = 0; i < 8; i++) {105if (!(TX4938_EBUSC_CR(i) & 0x8))106continue; /* disabled */107txx9_ce_res[i].start = (unsigned long)TX4938_EBUSC_BA(i);108txx9_ce_res[i].end =109txx9_ce_res[i].start + TX4938_EBUSC_SIZE(i) - 1;110request_resource(&iomem_resource, &txx9_ce_res[i]);111}112113/* clocks */114ccfg = ____raw_readq(&tx4938_ccfgptr->ccfg);115if (txx9_master_clock) {116/* calculate gbus_clock and cpu_clock from master_clock */117divmode = (__u32)ccfg & TX4938_CCFG_DIVMODE_MASK;118switch (divmode) {119case TX4938_CCFG_DIVMODE_8:120case TX4938_CCFG_DIVMODE_10:121case TX4938_CCFG_DIVMODE_12:122case TX4938_CCFG_DIVMODE_16:123case TX4938_CCFG_DIVMODE_18:124txx9_gbus_clock = txx9_master_clock * 4; break;125default:126txx9_gbus_clock = txx9_master_clock;127}128switch (divmode) {129case TX4938_CCFG_DIVMODE_2:130case TX4938_CCFG_DIVMODE_8:131cpuclk = txx9_gbus_clock * 2; break;132case TX4938_CCFG_DIVMODE_2_5:133case TX4938_CCFG_DIVMODE_10:134cpuclk = txx9_gbus_clock * 5 / 2; break;135case TX4938_CCFG_DIVMODE_3:136case TX4938_CCFG_DIVMODE_12:137cpuclk = txx9_gbus_clock * 3; break;138case TX4938_CCFG_DIVMODE_4:139case TX4938_CCFG_DIVMODE_16:140cpuclk = txx9_gbus_clock * 4; break;141case TX4938_CCFG_DIVMODE_4_5:142case TX4938_CCFG_DIVMODE_18:143cpuclk = txx9_gbus_clock * 9 / 2; break;144}145txx9_cpu_clock = cpuclk;146} else {147if (txx9_cpu_clock == 0)148txx9_cpu_clock = 300000000; /* 300MHz */149/* calculate gbus_clock and master_clock from cpu_clock */150cpuclk = txx9_cpu_clock;151divmode = (__u32)ccfg & TX4938_CCFG_DIVMODE_MASK;152switch (divmode) {153case TX4938_CCFG_DIVMODE_2:154case TX4938_CCFG_DIVMODE_8:155txx9_gbus_clock = cpuclk / 2; break;156case TX4938_CCFG_DIVMODE_2_5:157case TX4938_CCFG_DIVMODE_10:158txx9_gbus_clock = cpuclk * 2 / 5; break;159case TX4938_CCFG_DIVMODE_3:160case TX4938_CCFG_DIVMODE_12:161txx9_gbus_clock = cpuclk / 3; break;162case TX4938_CCFG_DIVMODE_4:163case TX4938_CCFG_DIVMODE_16:164txx9_gbus_clock = cpuclk / 4; break;165case TX4938_CCFG_DIVMODE_4_5:166case TX4938_CCFG_DIVMODE_18:167txx9_gbus_clock = cpuclk * 2 / 9; break;168}169switch (divmode) {170case TX4938_CCFG_DIVMODE_8:171case TX4938_CCFG_DIVMODE_10:172case TX4938_CCFG_DIVMODE_12:173case TX4938_CCFG_DIVMODE_16:174case TX4938_CCFG_DIVMODE_18:175txx9_master_clock = txx9_gbus_clock / 4; break;176default:177txx9_master_clock = txx9_gbus_clock;178}179}180/* change default value to udelay/mdelay take reasonable time */181loops_per_jiffy = txx9_cpu_clock / HZ / 2;182183/* CCFG */184tx4938_wdr_init();185/* clear BusErrorOnWrite flag (W1C) */186tx4938_ccfg_set(TX4938_CCFG_BEOW);187/* enable Timeout BusError */188if (txx9_ccfg_toeon)189tx4938_ccfg_set(TX4938_CCFG_TOE);190191/* DMA selection */192txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_DMASEL_ALL);193194/* Use external clock for external arbiter */195if (!(____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_PCIARB))196txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_PCICLKEN_ALL);197198pr_info("%s -- %dMHz(M%dMHz) CRIR:%08x CCFG:%llx PCFG:%llx\n",199txx9_pcode_str, (cpuclk + 500000) / 1000000,200(txx9_master_clock + 500000) / 1000000,201(__u32)____raw_readq(&tx4938_ccfgptr->crir),202____raw_readq(&tx4938_ccfgptr->ccfg),203____raw_readq(&tx4938_ccfgptr->pcfg));204205pr_info("%s SDRAMC --", txx9_pcode_str);206for (i = 0; i < 4; i++) {207__u64 cr = TX4938_SDRAMC_CR(i);208unsigned long base, size;209if (!((__u32)cr & 0x00000400))210continue; /* disabled */211base = (unsigned long)(cr >> 49) << 21;212size = (((unsigned long)(cr >> 33) & 0x7fff) + 1) << 21;213pr_cont(" CR%d:%016llx", i, cr);214tx4938_sdram_resource[i].name = "SDRAM";215tx4938_sdram_resource[i].start = base;216tx4938_sdram_resource[i].end = base + size - 1;217tx4938_sdram_resource[i].flags = IORESOURCE_MEM;218request_resource(&iomem_resource, &tx4938_sdram_resource[i]);219}220pr_cont(" TR:%09llx\n", ____raw_readq(&tx4938_sdramcptr->tr));221222/* SRAM */223if (txx9_pcode == 0x4938 && ____raw_readq(&tx4938_sramcptr->cr) & 1) {224unsigned int size = TX4938_SRAM_SIZE;225tx4938_sram_resource.name = "SRAM";226tx4938_sram_resource.start =227(____raw_readq(&tx4938_sramcptr->cr) >> (39-11))228& ~(size - 1);229tx4938_sram_resource.end =230tx4938_sram_resource.start + TX4938_SRAM_SIZE - 1;231tx4938_sram_resource.flags = IORESOURCE_MEM;232request_resource(&iomem_resource, &tx4938_sram_resource);233}234235/* TMR */236/* disable all timers */237for (i = 0; i < TX4938_NR_TMR; i++)238txx9_tmr_init(TX4938_TMR_REG(i) & 0xfffffffffULL);239240/* PIO */241__raw_writel(0, &tx4938_pioptr->maskcpu);242__raw_writel(0, &tx4938_pioptr->maskext);243244if (txx9_pcode == 0x4938) {245__u64 pcfg = ____raw_readq(&tx4938_ccfgptr->pcfg);246/* set PCIC1 reset */247txx9_set64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIC1RST);248if (pcfg & (TX4938_PCFG_ETH0_SEL | TX4938_PCFG_ETH1_SEL)) {249mdelay(1); /* at least 128 cpu clock */250/* clear PCIC1 reset */251txx9_clear64(&tx4938_ccfgptr->clkctr,252TX4938_CLKCTR_PCIC1RST);253} else {254pr_info("%s: stop PCIC1\n", txx9_pcode_str);255/* stop PCIC1 */256txx9_set64(&tx4938_ccfgptr->clkctr,257TX4938_CLKCTR_PCIC1CKD);258}259if (!(pcfg & TX4938_PCFG_ETH0_SEL)) {260pr_info("%s: stop ETH0\n", txx9_pcode_str);261txx9_set64(&tx4938_ccfgptr->clkctr,262TX4938_CLKCTR_ETH0RST);263txx9_set64(&tx4938_ccfgptr->clkctr,264TX4938_CLKCTR_ETH0CKD);265}266if (!(pcfg & TX4938_PCFG_ETH1_SEL)) {267pr_info("%s: stop ETH1\n", txx9_pcode_str);268txx9_set64(&tx4938_ccfgptr->clkctr,269TX4938_CLKCTR_ETH1RST);270txx9_set64(&tx4938_ccfgptr->clkctr,271TX4938_CLKCTR_ETH1CKD);272}273}274275_machine_restart = tx4938_machine_restart;276board_be_init = tx4938_be_init;277}278279void __init tx4938_time_init(unsigned int tmrnr)280{281if (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_TINTDIS)282txx9_clockevent_init(TX4938_TMR_REG(tmrnr) & 0xfffffffffULL,283TXX9_IRQ_BASE + TX4938_IR_TMR(tmrnr),284TXX9_IMCLK);285}286287void __init tx4938_sio_init(unsigned int sclk, unsigned int cts_mask)288{289int i;290unsigned int ch_mask = 0;291292if (__raw_readq(&tx4938_ccfgptr->pcfg) & TX4938_PCFG_ETH0_SEL)293ch_mask |= 1 << 1; /* disable SIO1 by PCFG setting */294for (i = 0; i < 2; i++) {295if ((1 << i) & ch_mask)296continue;297txx9_sio_init(TX4938_SIO_REG(i) & 0xfffffffffULL,298TXX9_IRQ_BASE + TX4938_IR_SIO(i),299i, sclk, (1 << i) & cts_mask);300}301}302303void __init tx4938_spi_init(int busid)304{305txx9_spi_init(busid, TX4938_SPI_REG & 0xfffffffffULL,306TXX9_IRQ_BASE + TX4938_IR_SPI);307}308309void __init tx4938_ethaddr_init(unsigned char *addr0, unsigned char *addr1)310{311u64 pcfg = __raw_readq(&tx4938_ccfgptr->pcfg);312313if (addr0 && (pcfg & TX4938_PCFG_ETH0_SEL))314txx9_ethaddr_init(TXX9_IRQ_BASE + TX4938_IR_ETH0, addr0);315if (addr1 && (pcfg & TX4938_PCFG_ETH1_SEL))316txx9_ethaddr_init(TXX9_IRQ_BASE + TX4938_IR_ETH1, addr1);317}318319void __init tx4938_mtd_init(int ch)320{321struct physmap_flash_data pdata = {322.width = TX4938_EBUSC_WIDTH(ch) / 8,323};324unsigned long start = txx9_ce_res[ch].start;325unsigned long size = txx9_ce_res[ch].end - start + 1;326327if (!(TX4938_EBUSC_CR(ch) & 0x8))328return; /* disabled */329txx9_physmap_flash_init(ch, start, size, &pdata);330}331332void __init tx4938_ata_init(unsigned int irq, unsigned int shift, int tune)333{334struct platform_device *pdev;335struct resource res[] = {336{337/* .start and .end are filled in later */338.flags = IORESOURCE_MEM,339}, {340.start = irq,341.flags = IORESOURCE_IRQ,342},343};344struct tx4938ide_platform_info pdata = {345.ioport_shift = shift,346/*347* The IDE driver should not change bus timings if other ISA348* devices existed.349*/350.gbus_clock = tune ? txx9_gbus_clock : 0,351};352u64 ebccr;353int i;354355if ((__raw_readq(&tx4938_ccfgptr->pcfg) &356(TX4938_PCFG_ATA_SEL | TX4938_PCFG_NDF_SEL))357!= TX4938_PCFG_ATA_SEL)358return;359for (i = 0; i < 8; i++) {360/* check EBCCRn.ISA, EBCCRn.BSZ, EBCCRn.ME */361ebccr = __raw_readq(&tx4938_ebuscptr->cr[i]);362if ((ebccr & 0x00f00008) == 0x00e00008)363break;364}365if (i == 8)366return;367pdata.ebus_ch = i;368res[0].start = ((ebccr >> 48) << 20) + 0x10000;369res[0].end = res[0].start + 0x20000 - 1;370pdev = platform_device_alloc("tx4938ide", -1);371if (!pdev ||372platform_device_add_resources(pdev, res, ARRAY_SIZE(res)) ||373platform_device_add_data(pdev, &pdata, sizeof(pdata)) ||374platform_device_add(pdev))375platform_device_put(pdev);376}377378void __init tx4938_ndfmc_init(unsigned int hold, unsigned int spw)379{380struct txx9ndfmc_platform_data plat_data = {381.shift = 1,382.gbus_clock = txx9_gbus_clock,383.hold = hold,384.spw = spw,385.ch_mask = 1,386};387unsigned long baseaddr = TX4938_NDFMC_REG & 0xfffffffffULL;388389#ifdef __BIG_ENDIAN390baseaddr += 4;391#endif392if ((__raw_readq(&tx4938_ccfgptr->pcfg) &393(TX4938_PCFG_ATA_SEL|TX4938_PCFG_ISA_SEL|TX4938_PCFG_NDF_SEL)) ==394TX4938_PCFG_NDF_SEL)395txx9_ndfmc_init(baseaddr, &plat_data);396}397398void __init tx4938_dmac_init(int memcpy_chan0, int memcpy_chan1)399{400struct txx9dmac_platform_data plat_data = {401.have_64bit_regs = true,402};403int i;404405for (i = 0; i < 2; i++) {406plat_data.memcpy_chan = i ? memcpy_chan1 : memcpy_chan0;407txx9_dmac_init(i, TX4938_DMA_REG(i) & 0xfffffffffULL,408TXX9_IRQ_BASE + TX4938_IR_DMA(i, 0),409&plat_data);410}411}412413void __init tx4938_aclc_init(void)414{415u64 pcfg = __raw_readq(&tx4938_ccfgptr->pcfg);416417if ((pcfg & TX4938_PCFG_SEL2) &&418!(pcfg & TX4938_PCFG_ETH0_SEL))419txx9_aclc_init(TX4938_ACLC_REG & 0xfffffffffULL,420TXX9_IRQ_BASE + TX4938_IR_ACLC,4211, 0, 1);422}423424void __init tx4938_sramc_init(void)425{426if (tx4938_sram_resource.start)427txx9_sramc_init(&tx4938_sram_resource);428}429430static void __init tx4938_stop_unused_modules(void)431{432__u64 pcfg, rst = 0, ckd = 0;433char buf[128];434435buf[0] = '\0';436local_irq_disable();437pcfg = ____raw_readq(&tx4938_ccfgptr->pcfg);438switch (txx9_pcode) {439case 0x4937:440if (!(pcfg & TX4938_PCFG_SEL2)) {441rst |= TX4938_CLKCTR_ACLRST;442ckd |= TX4938_CLKCTR_ACLCKD;443strcat(buf, " ACLC");444}445break;446case 0x4938:447if (!(pcfg & TX4938_PCFG_SEL2) ||448(pcfg & TX4938_PCFG_ETH0_SEL)) {449rst |= TX4938_CLKCTR_ACLRST;450ckd |= TX4938_CLKCTR_ACLCKD;451strcat(buf, " ACLC");452}453if ((pcfg &454(TX4938_PCFG_ATA_SEL | TX4938_PCFG_ISA_SEL |455TX4938_PCFG_NDF_SEL))456!= TX4938_PCFG_NDF_SEL) {457rst |= TX4938_CLKCTR_NDFRST;458ckd |= TX4938_CLKCTR_NDFCKD;459strcat(buf, " NDFMC");460}461if (!(pcfg & TX4938_PCFG_SPI_SEL)) {462rst |= TX4938_CLKCTR_SPIRST;463ckd |= TX4938_CLKCTR_SPICKD;464strcat(buf, " SPI");465}466break;467}468if (rst | ckd) {469txx9_set64(&tx4938_ccfgptr->clkctr, rst);470txx9_set64(&tx4938_ccfgptr->clkctr, ckd);471}472local_irq_enable();473if (buf[0])474pr_info("%s: stop%s\n", txx9_pcode_str, buf);475}476477static int __init tx4938_late_init(void)478{479if (txx9_pcode != 0x4937 && txx9_pcode != 0x4938)480return -ENODEV;481tx4938_stop_unused_modules();482return 0;483}484late_initcall(tx4938_late_init);485486487