Path: blob/master/arch/mips/txx9/generic/setup_tx4938.c
10818 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 <asm/reboot.h>20#include <asm/traps.h>21#include <asm/txx9irq.h>22#include <asm/txx9tmr.h>23#include <asm/txx9pio.h>24#include <asm/txx9/generic.h>25#include <asm/txx9/ndfmc.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_warning("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{84board_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);197198printk(KERN_INFO "%s -- %dMHz(M%dMHz) CRIR:%08x CCFG:%llx PCFG:%llx\n",199txx9_pcode_str,200(cpuclk + 500000) / 1000000,201(txx9_master_clock + 500000) / 1000000,202(__u32)____raw_readq(&tx4938_ccfgptr->crir),203(unsigned long long)____raw_readq(&tx4938_ccfgptr->ccfg),204(unsigned long long)____raw_readq(&tx4938_ccfgptr->pcfg));205206printk(KERN_INFO "%s SDRAMC --", txx9_pcode_str);207for (i = 0; i < 4; i++) {208__u64 cr = TX4938_SDRAMC_CR(i);209unsigned long base, size;210if (!((__u32)cr & 0x00000400))211continue; /* disabled */212base = (unsigned long)(cr >> 49) << 21;213size = (((unsigned long)(cr >> 33) & 0x7fff) + 1) << 21;214printk(" CR%d:%016llx", i, (unsigned long long)cr);215tx4938_sdram_resource[i].name = "SDRAM";216tx4938_sdram_resource[i].start = base;217tx4938_sdram_resource[i].end = base + size - 1;218tx4938_sdram_resource[i].flags = IORESOURCE_MEM;219request_resource(&iomem_resource, &tx4938_sdram_resource[i]);220}221printk(" TR:%09llx\n",222(unsigned long long)____raw_readq(&tx4938_sdramcptr->tr));223224/* SRAM */225if (txx9_pcode == 0x4938 && ____raw_readq(&tx4938_sramcptr->cr) & 1) {226unsigned int size = TX4938_SRAM_SIZE;227tx4938_sram_resource.name = "SRAM";228tx4938_sram_resource.start =229(____raw_readq(&tx4938_sramcptr->cr) >> (39-11))230& ~(size - 1);231tx4938_sram_resource.end =232tx4938_sram_resource.start + TX4938_SRAM_SIZE - 1;233tx4938_sram_resource.flags = IORESOURCE_MEM;234request_resource(&iomem_resource, &tx4938_sram_resource);235}236237/* TMR */238/* disable all timers */239for (i = 0; i < TX4938_NR_TMR; i++)240txx9_tmr_init(TX4938_TMR_REG(i) & 0xfffffffffULL);241242/* PIO */243txx9_gpio_init(TX4938_PIO_REG & 0xfffffffffULL, 0, TX4938_NUM_PIO);244__raw_writel(0, &tx4938_pioptr->maskcpu);245__raw_writel(0, &tx4938_pioptr->maskext);246247if (txx9_pcode == 0x4938) {248__u64 pcfg = ____raw_readq(&tx4938_ccfgptr->pcfg);249/* set PCIC1 reset */250txx9_set64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIC1RST);251if (pcfg & (TX4938_PCFG_ETH0_SEL | TX4938_PCFG_ETH1_SEL)) {252mdelay(1); /* at least 128 cpu clock */253/* clear PCIC1 reset */254txx9_clear64(&tx4938_ccfgptr->clkctr,255TX4938_CLKCTR_PCIC1RST);256} else {257printk(KERN_INFO "%s: stop PCIC1\n", txx9_pcode_str);258/* stop PCIC1 */259txx9_set64(&tx4938_ccfgptr->clkctr,260TX4938_CLKCTR_PCIC1CKD);261}262if (!(pcfg & TX4938_PCFG_ETH0_SEL)) {263printk(KERN_INFO "%s: stop ETH0\n", txx9_pcode_str);264txx9_set64(&tx4938_ccfgptr->clkctr,265TX4938_CLKCTR_ETH0RST);266txx9_set64(&tx4938_ccfgptr->clkctr,267TX4938_CLKCTR_ETH0CKD);268}269if (!(pcfg & TX4938_PCFG_ETH1_SEL)) {270printk(KERN_INFO "%s: stop ETH1\n", txx9_pcode_str);271txx9_set64(&tx4938_ccfgptr->clkctr,272TX4938_CLKCTR_ETH1RST);273txx9_set64(&tx4938_ccfgptr->clkctr,274TX4938_CLKCTR_ETH1CKD);275}276}277278_machine_restart = tx4938_machine_restart;279board_be_init = tx4938_be_init;280}281282void __init tx4938_time_init(unsigned int tmrnr)283{284if (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_TINTDIS)285txx9_clockevent_init(TX4938_TMR_REG(tmrnr) & 0xfffffffffULL,286TXX9_IRQ_BASE + TX4938_IR_TMR(tmrnr),287TXX9_IMCLK);288}289290void __init tx4938_sio_init(unsigned int sclk, unsigned int cts_mask)291{292int i;293unsigned int ch_mask = 0;294295if (__raw_readq(&tx4938_ccfgptr->pcfg) & TX4938_PCFG_ETH0_SEL)296ch_mask |= 1 << 1; /* disable SIO1 by PCFG setting */297for (i = 0; i < 2; i++) {298if ((1 << i) & ch_mask)299continue;300txx9_sio_init(TX4938_SIO_REG(i) & 0xfffffffffULL,301TXX9_IRQ_BASE + TX4938_IR_SIO(i),302i, sclk, (1 << i) & cts_mask);303}304}305306void __init tx4938_spi_init(int busid)307{308txx9_spi_init(busid, TX4938_SPI_REG & 0xfffffffffULL,309TXX9_IRQ_BASE + TX4938_IR_SPI);310}311312void __init tx4938_ethaddr_init(unsigned char *addr0, unsigned char *addr1)313{314u64 pcfg = __raw_readq(&tx4938_ccfgptr->pcfg);315316if (addr0 && (pcfg & TX4938_PCFG_ETH0_SEL))317txx9_ethaddr_init(TXX9_IRQ_BASE + TX4938_IR_ETH0, addr0);318if (addr1 && (pcfg & TX4938_PCFG_ETH1_SEL))319txx9_ethaddr_init(TXX9_IRQ_BASE + TX4938_IR_ETH1, addr1);320}321322void __init tx4938_mtd_init(int ch)323{324struct physmap_flash_data pdata = {325.width = TX4938_EBUSC_WIDTH(ch) / 8,326};327unsigned long start = txx9_ce_res[ch].start;328unsigned long size = txx9_ce_res[ch].end - start + 1;329330if (!(TX4938_EBUSC_CR(ch) & 0x8))331return; /* disabled */332txx9_physmap_flash_init(ch, start, size, &pdata);333}334335void __init tx4938_ata_init(unsigned int irq, unsigned int shift, int tune)336{337struct platform_device *pdev;338struct resource res[] = {339{340/* .start and .end are filled in later */341.flags = IORESOURCE_MEM,342}, {343.start = irq,344.flags = IORESOURCE_IRQ,345},346};347struct tx4938ide_platform_info pdata = {348.ioport_shift = shift,349/*350* The IDE driver should not change bus timings if other ISA351* devices existed.352*/353.gbus_clock = tune ? txx9_gbus_clock : 0,354};355u64 ebccr;356int i;357358if ((__raw_readq(&tx4938_ccfgptr->pcfg) &359(TX4938_PCFG_ATA_SEL | TX4938_PCFG_NDF_SEL))360!= TX4938_PCFG_ATA_SEL)361return;362for (i = 0; i < 8; i++) {363/* check EBCCRn.ISA, EBCCRn.BSZ, EBCCRn.ME */364ebccr = __raw_readq(&tx4938_ebuscptr->cr[i]);365if ((ebccr & 0x00f00008) == 0x00e00008)366break;367}368if (i == 8)369return;370pdata.ebus_ch = i;371res[0].start = ((ebccr >> 48) << 20) + 0x10000;372res[0].end = res[0].start + 0x20000 - 1;373pdev = platform_device_alloc("tx4938ide", -1);374if (!pdev ||375platform_device_add_resources(pdev, res, ARRAY_SIZE(res)) ||376platform_device_add_data(pdev, &pdata, sizeof(pdata)) ||377platform_device_add(pdev))378platform_device_put(pdev);379}380381void __init tx4938_ndfmc_init(unsigned int hold, unsigned int spw)382{383struct txx9ndfmc_platform_data plat_data = {384.shift = 1,385.gbus_clock = txx9_gbus_clock,386.hold = hold,387.spw = spw,388.ch_mask = 1,389};390unsigned long baseaddr = TX4938_NDFMC_REG & 0xfffffffffULL;391392#ifdef __BIG_ENDIAN393baseaddr += 4;394#endif395if ((__raw_readq(&tx4938_ccfgptr->pcfg) &396(TX4938_PCFG_ATA_SEL|TX4938_PCFG_ISA_SEL|TX4938_PCFG_NDF_SEL)) ==397TX4938_PCFG_NDF_SEL)398txx9_ndfmc_init(baseaddr, &plat_data);399}400401void __init tx4938_dmac_init(int memcpy_chan0, int memcpy_chan1)402{403struct txx9dmac_platform_data plat_data = {404.have_64bit_regs = true,405};406int i;407408for (i = 0; i < 2; i++) {409plat_data.memcpy_chan = i ? memcpy_chan1 : memcpy_chan0;410txx9_dmac_init(i, TX4938_DMA_REG(i) & 0xfffffffffULL,411TXX9_IRQ_BASE + TX4938_IR_DMA(i, 0),412&plat_data);413}414}415416void __init tx4938_aclc_init(void)417{418u64 pcfg = __raw_readq(&tx4938_ccfgptr->pcfg);419420if ((pcfg & TX4938_PCFG_SEL2) &&421!(pcfg & TX4938_PCFG_ETH0_SEL))422txx9_aclc_init(TX4938_ACLC_REG & 0xfffffffffULL,423TXX9_IRQ_BASE + TX4938_IR_ACLC,4241, 0, 1);425}426427void __init tx4938_sramc_init(void)428{429if (tx4938_sram_resource.start)430txx9_sramc_init(&tx4938_sram_resource);431}432433static void __init tx4938_stop_unused_modules(void)434{435__u64 pcfg, rst = 0, ckd = 0;436char buf[128];437438buf[0] = '\0';439local_irq_disable();440pcfg = ____raw_readq(&tx4938_ccfgptr->pcfg);441switch (txx9_pcode) {442case 0x4937:443if (!(pcfg & TX4938_PCFG_SEL2)) {444rst |= TX4938_CLKCTR_ACLRST;445ckd |= TX4938_CLKCTR_ACLCKD;446strcat(buf, " ACLC");447}448break;449case 0x4938:450if (!(pcfg & TX4938_PCFG_SEL2) ||451(pcfg & TX4938_PCFG_ETH0_SEL)) {452rst |= TX4938_CLKCTR_ACLRST;453ckd |= TX4938_CLKCTR_ACLCKD;454strcat(buf, " ACLC");455}456if ((pcfg &457(TX4938_PCFG_ATA_SEL | TX4938_PCFG_ISA_SEL |458TX4938_PCFG_NDF_SEL))459!= TX4938_PCFG_NDF_SEL) {460rst |= TX4938_CLKCTR_NDFRST;461ckd |= TX4938_CLKCTR_NDFCKD;462strcat(buf, " NDFMC");463}464if (!(pcfg & TX4938_PCFG_SPI_SEL)) {465rst |= TX4938_CLKCTR_SPIRST;466ckd |= TX4938_CLKCTR_SPICKD;467strcat(buf, " SPI");468}469break;470}471if (rst | ckd) {472txx9_set64(&tx4938_ccfgptr->clkctr, rst);473txx9_set64(&tx4938_ccfgptr->clkctr, ckd);474}475local_irq_enable();476if (buf[0])477pr_info("%s: stop%s\n", txx9_pcode_str, buf);478}479480static int __init tx4938_late_init(void)481{482if (txx9_pcode != 0x4937 && txx9_pcode != 0x4938)483return -ENODEV;484tx4938_stop_unused_modules();485return 0;486}487late_initcall(tx4938_late_init);488489490