Path: blob/master/arch/m68k/platform/532x/config.c
10819 views
/***************************************************************************/12/*3* linux/arch/m68knommu/platform/532x/config.c4*5* Copyright (C) 1999-2002, Greg Ungerer ([email protected])6* Copyright (C) 2000, Lineo (www.lineo.com)7* Yaroslav Vinogradov [email protected]8* Copyright Freescale Semiconductor, Inc 20069* Copyright (c) 2006, emlix, Sebastian Hess <[email protected]>10*11* This program is free software; you can redistribute it and/or modify12* it under the terms of the GNU General Public License as published by13* the Free Software Foundation; either version 2 of the License, or14* (at your option) any later version.15*/1617/***************************************************************************/1819#include <linux/kernel.h>20#include <linux/param.h>21#include <linux/init.h>22#include <linux/io.h>23#include <linux/spi/spi.h>24#include <linux/gpio.h>25#include <asm/machdep.h>26#include <asm/coldfire.h>27#include <asm/mcfsim.h>28#include <asm/mcfuart.h>29#include <asm/mcfdma.h>30#include <asm/mcfwdebug.h>31#include <asm/mcfqspi.h>3233/***************************************************************************/3435static struct mcf_platform_uart m532x_uart_platform[] = {36{37.mapbase = MCFUART_BASE1,38.irq = MCFINT_VECBASE + MCFINT_UART0,39},40{41.mapbase = MCFUART_BASE2,42.irq = MCFINT_VECBASE + MCFINT_UART1,43},44{45.mapbase = MCFUART_BASE3,46.irq = MCFINT_VECBASE + MCFINT_UART2,47},48{ },49};5051static struct platform_device m532x_uart = {52.name = "mcfuart",53.id = 0,54.dev.platform_data = m532x_uart_platform,55};5657static struct resource m532x_fec_resources[] = {58{59.start = 0xfc030000,60.end = 0xfc0307ff,61.flags = IORESOURCE_MEM,62},63{64.start = 64 + 36,65.end = 64 + 36,66.flags = IORESOURCE_IRQ,67},68{69.start = 64 + 40,70.end = 64 + 40,71.flags = IORESOURCE_IRQ,72},73{74.start = 64 + 42,75.end = 64 + 42,76.flags = IORESOURCE_IRQ,77},78};7980static struct platform_device m532x_fec = {81.name = "fec",82.id = 0,83.num_resources = ARRAY_SIZE(m532x_fec_resources),84.resource = m532x_fec_resources,85};8687#if defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE)88static struct resource m532x_qspi_resources[] = {89{90.start = MCFQSPI_IOBASE,91.end = MCFQSPI_IOBASE + MCFQSPI_IOSIZE - 1,92.flags = IORESOURCE_MEM,93},94{95.start = MCFINT_VECBASE + MCFINT_QSPI,96.end = MCFINT_VECBASE + MCFINT_QSPI,97.flags = IORESOURCE_IRQ,98},99};100101#define MCFQSPI_CS0 84102#define MCFQSPI_CS1 85103#define MCFQSPI_CS2 86104105static int m532x_cs_setup(struct mcfqspi_cs_control *cs_control)106{107int status;108109status = gpio_request(MCFQSPI_CS0, "MCFQSPI_CS0");110if (status) {111pr_debug("gpio_request for MCFQSPI_CS0 failed\n");112goto fail0;113}114status = gpio_direction_output(MCFQSPI_CS0, 1);115if (status) {116pr_debug("gpio_direction_output for MCFQSPI_CS0 failed\n");117goto fail1;118}119120status = gpio_request(MCFQSPI_CS1, "MCFQSPI_CS1");121if (status) {122pr_debug("gpio_request for MCFQSPI_CS1 failed\n");123goto fail1;124}125status = gpio_direction_output(MCFQSPI_CS1, 1);126if (status) {127pr_debug("gpio_direction_output for MCFQSPI_CS1 failed\n");128goto fail2;129}130131status = gpio_request(MCFQSPI_CS2, "MCFQSPI_CS2");132if (status) {133pr_debug("gpio_request for MCFQSPI_CS2 failed\n");134goto fail2;135}136status = gpio_direction_output(MCFQSPI_CS2, 1);137if (status) {138pr_debug("gpio_direction_output for MCFQSPI_CS2 failed\n");139goto fail3;140}141142return 0;143144fail3:145gpio_free(MCFQSPI_CS2);146fail2:147gpio_free(MCFQSPI_CS1);148fail1:149gpio_free(MCFQSPI_CS0);150fail0:151return status;152}153154static void m532x_cs_teardown(struct mcfqspi_cs_control *cs_control)155{156gpio_free(MCFQSPI_CS2);157gpio_free(MCFQSPI_CS1);158gpio_free(MCFQSPI_CS0);159}160161static void m532x_cs_select(struct mcfqspi_cs_control *cs_control,162u8 chip_select, bool cs_high)163{164gpio_set_value(MCFQSPI_CS0 + chip_select, cs_high);165}166167static void m532x_cs_deselect(struct mcfqspi_cs_control *cs_control,168u8 chip_select, bool cs_high)169{170gpio_set_value(MCFQSPI_CS0 + chip_select, !cs_high);171}172173static struct mcfqspi_cs_control m532x_cs_control = {174.setup = m532x_cs_setup,175.teardown = m532x_cs_teardown,176.select = m532x_cs_select,177.deselect = m532x_cs_deselect,178};179180static struct mcfqspi_platform_data m532x_qspi_data = {181.bus_num = 0,182.num_chipselect = 3,183.cs_control = &m532x_cs_control,184};185186static struct platform_device m532x_qspi = {187.name = "mcfqspi",188.id = 0,189.num_resources = ARRAY_SIZE(m532x_qspi_resources),190.resource = m532x_qspi_resources,191.dev.platform_data = &m532x_qspi_data,192};193194static void __init m532x_qspi_init(void)195{196/* setup QSPS pins for QSPI with gpio CS control */197writew(0x01f0, MCF_GPIO_PAR_QSPI);198}199#endif /* defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE) */200201202static struct platform_device *m532x_devices[] __initdata = {203&m532x_uart,204&m532x_fec,205#if defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE)206&m532x_qspi,207#endif208};209210/***************************************************************************/211212static void __init m532x_uart_init_line(int line, int irq)213{214if (line == 0) {215/* GPIO initialization */216MCF_GPIO_PAR_UART |= 0x000F;217} else if (line == 1) {218/* GPIO initialization */219MCF_GPIO_PAR_UART |= 0x0FF0;220}221}222223static void __init m532x_uarts_init(void)224{225const int nrlines = ARRAY_SIZE(m532x_uart_platform);226int line;227228for (line = 0; (line < nrlines); line++)229m532x_uart_init_line(line, m532x_uart_platform[line].irq);230}231/***************************************************************************/232233static void __init m532x_fec_init(void)234{235/* Set multi-function pins to ethernet mode for fec0 */236MCF_GPIO_PAR_FECI2C |= (MCF_GPIO_PAR_FECI2C_PAR_MDC_EMDC |237MCF_GPIO_PAR_FECI2C_PAR_MDIO_EMDIO);238MCF_GPIO_PAR_FEC = (MCF_GPIO_PAR_FEC_PAR_FEC_7W_FEC |239MCF_GPIO_PAR_FEC_PAR_FEC_MII_FEC);240}241242/***************************************************************************/243244static void m532x_cpu_reset(void)245{246local_irq_disable();247__raw_writeb(MCF_RCR_SWRESET, MCF_RCR);248}249250/***************************************************************************/251252void __init config_BSP(char *commandp, int size)253{254#if !defined(CONFIG_BOOTPARAM)255/* Copy command line from FLASH to local buffer... */256memcpy(commandp, (char *) 0x4000, 4);257if(strncmp(commandp, "kcl ", 4) == 0){258memcpy(commandp, (char *) 0x4004, size);259commandp[size-1] = 0;260} else {261memset(commandp, 0, size);262}263#endif264265#ifdef CONFIG_BDM_DISABLE266/*267* Disable the BDM clocking. This also turns off most of the rest of268* the BDM device. This is good for EMC reasons. This option is not269* incompatible with the memory protection option.270*/271wdebug(MCFDEBUG_CSR, MCFDEBUG_CSR_PSTCLK);272#endif273}274275/***************************************************************************/276277static int __init init_BSP(void)278{279m532x_uarts_init();280m532x_fec_init();281#if defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE)282m532x_qspi_init();283#endif284platform_add_devices(m532x_devices, ARRAY_SIZE(m532x_devices));285return 0;286}287288arch_initcall(init_BSP);289290/***************************************************************************/291/* Board initialization */292/***************************************************************************/293/*294* PLL min/max specifications295*/296#define MAX_FVCO 500000 /* KHz */297#define MAX_FSYS 80000 /* KHz */298#define MIN_FSYS 58333 /* KHz */299#define FREF 16000 /* KHz */300301302#define MAX_MFD 135 /* Multiplier */303#define MIN_MFD 88 /* Multiplier */304#define BUSDIV 6 /* Divider */305306/*307* Low Power Divider specifications308*/309#define MIN_LPD (1 << 0) /* Divider (not encoded) */310#define MAX_LPD (1 << 15) /* Divider (not encoded) */311#define DEFAULT_LPD (1 << 1) /* Divider (not encoded) */312313#define SYS_CLK_KHZ 80000314#define SYSTEM_PERIOD 12.5315/*316* SDRAM Timing Parameters317*/318#define SDRAM_BL 8 /* # of beats in a burst */319#define SDRAM_TWR 2 /* in clocks */320#define SDRAM_CASL 2.5 /* CASL in clocks */321#define SDRAM_TRCD 2 /* in clocks */322#define SDRAM_TRP 2 /* in clocks */323#define SDRAM_TRFC 7 /* in clocks */324#define SDRAM_TREFI 7800 /* in ns */325326#define EXT_SRAM_ADDRESS (0xC0000000)327#define FLASH_ADDRESS (0x00000000)328#define SDRAM_ADDRESS (0x40000000)329330#define NAND_FLASH_ADDRESS (0xD0000000)331332int sys_clk_khz = 0;333int sys_clk_mhz = 0;334335void wtm_init(void);336void scm_init(void);337void gpio_init(void);338void fbcs_init(void);339void sdramc_init(void);340int clock_pll (int fsys, int flags);341int clock_limp (int);342int clock_exit_limp (void);343int get_sys_clock (void);344345asmlinkage void __init sysinit(void)346{347sys_clk_khz = clock_pll(0, 0);348sys_clk_mhz = sys_clk_khz/1000;349350wtm_init();351scm_init();352gpio_init();353fbcs_init();354sdramc_init();355}356357void wtm_init(void)358{359/* Disable watchdog timer */360MCF_WTM_WCR = 0;361}362363#define MCF_SCM_BCR_GBW (0x00000100)364#define MCF_SCM_BCR_GBR (0x00000200)365366void scm_init(void)367{368/* All masters are trusted */369MCF_SCM_MPR = 0x77777777;370371/* Allow supervisor/user, read/write, and trusted/untrusted372access to all slaves */373MCF_SCM_PACRA = 0;374MCF_SCM_PACRB = 0;375MCF_SCM_PACRC = 0;376MCF_SCM_PACRD = 0;377MCF_SCM_PACRE = 0;378MCF_SCM_PACRF = 0;379380/* Enable bursts */381MCF_SCM_BCR = (MCF_SCM_BCR_GBR | MCF_SCM_BCR_GBW);382}383384385void fbcs_init(void)386{387MCF_GPIO_PAR_CS = 0x0000003E;388389/* Latch chip select */390MCF_FBCS1_CSAR = 0x10080000;391392MCF_FBCS1_CSCR = 0x002A3780;393MCF_FBCS1_CSMR = (MCF_FBCS_CSMR_BAM_2M | MCF_FBCS_CSMR_V);394395/* Initialize latch to drive signals to inactive states */396*((u16 *)(0x10080000)) = 0xFFFF;397398/* External SRAM */399MCF_FBCS1_CSAR = EXT_SRAM_ADDRESS;400MCF_FBCS1_CSCR = (MCF_FBCS_CSCR_PS_16401| MCF_FBCS_CSCR_AA402| MCF_FBCS_CSCR_SBM403| MCF_FBCS_CSCR_WS(1));404MCF_FBCS1_CSMR = (MCF_FBCS_CSMR_BAM_512K405| MCF_FBCS_CSMR_V);406407/* Boot Flash connected to FBCS0 */408MCF_FBCS0_CSAR = FLASH_ADDRESS;409MCF_FBCS0_CSCR = (MCF_FBCS_CSCR_PS_16410| MCF_FBCS_CSCR_BEM411| MCF_FBCS_CSCR_AA412| MCF_FBCS_CSCR_SBM413| MCF_FBCS_CSCR_WS(7));414MCF_FBCS0_CSMR = (MCF_FBCS_CSMR_BAM_32M415| MCF_FBCS_CSMR_V);416}417418void sdramc_init(void)419{420/*421* Check to see if the SDRAM has already been initialized422* by a run control tool423*/424if (!(MCF_SDRAMC_SDCR & MCF_SDRAMC_SDCR_REF)) {425/* SDRAM chip select initialization */426427/* Initialize SDRAM chip select */428MCF_SDRAMC_SDCS0 = (0429| MCF_SDRAMC_SDCS_BA(SDRAM_ADDRESS)430| MCF_SDRAMC_SDCS_CSSZ(MCF_SDRAMC_SDCS_CSSZ_32MBYTE));431432/*433* Basic configuration and initialization434*/435MCF_SDRAMC_SDCFG1 = (0436| MCF_SDRAMC_SDCFG1_SRD2RW((int)((SDRAM_CASL + 2) + 0.5 ))437| MCF_SDRAMC_SDCFG1_SWT2RD(SDRAM_TWR + 1)438| MCF_SDRAMC_SDCFG1_RDLAT((int)((SDRAM_CASL*2) + 2))439| MCF_SDRAMC_SDCFG1_ACT2RW((int)((SDRAM_TRCD ) + 0.5))440| MCF_SDRAMC_SDCFG1_PRE2ACT((int)((SDRAM_TRP ) + 0.5))441| MCF_SDRAMC_SDCFG1_REF2ACT((int)(((SDRAM_TRFC) ) + 0.5))442| MCF_SDRAMC_SDCFG1_WTLAT(3));443MCF_SDRAMC_SDCFG2 = (0444| MCF_SDRAMC_SDCFG2_BRD2PRE(SDRAM_BL/2 + 1)445| MCF_SDRAMC_SDCFG2_BWT2RW(SDRAM_BL/2 + SDRAM_TWR)446| MCF_SDRAMC_SDCFG2_BRD2WT((int)((SDRAM_CASL+SDRAM_BL/2-1.0)+0.5))447| MCF_SDRAMC_SDCFG2_BL(SDRAM_BL-1));448449450/*451* Precharge and enable write to SDMR452*/453MCF_SDRAMC_SDCR = (0454| MCF_SDRAMC_SDCR_MODE_EN455| MCF_SDRAMC_SDCR_CKE456| MCF_SDRAMC_SDCR_DDR457| MCF_SDRAMC_SDCR_MUX(1)458| MCF_SDRAMC_SDCR_RCNT((int)(((SDRAM_TREFI/(SYSTEM_PERIOD*64)) - 1) + 0.5))459| MCF_SDRAMC_SDCR_PS_16460| MCF_SDRAMC_SDCR_IPALL);461462/*463* Write extended mode register464*/465MCF_SDRAMC_SDMR = (0466| MCF_SDRAMC_SDMR_BNKAD_LEMR467| MCF_SDRAMC_SDMR_AD(0x0)468| MCF_SDRAMC_SDMR_CMD);469470/*471* Write mode register and reset DLL472*/473MCF_SDRAMC_SDMR = (0474| MCF_SDRAMC_SDMR_BNKAD_LMR475| MCF_SDRAMC_SDMR_AD(0x163)476| MCF_SDRAMC_SDMR_CMD);477478/*479* Execute a PALL command480*/481MCF_SDRAMC_SDCR |= MCF_SDRAMC_SDCR_IPALL;482483/*484* Perform two REF cycles485*/486MCF_SDRAMC_SDCR |= MCF_SDRAMC_SDCR_IREF;487MCF_SDRAMC_SDCR |= MCF_SDRAMC_SDCR_IREF;488489/*490* Write mode register and clear reset DLL491*/492MCF_SDRAMC_SDMR = (0493| MCF_SDRAMC_SDMR_BNKAD_LMR494| MCF_SDRAMC_SDMR_AD(0x063)495| MCF_SDRAMC_SDMR_CMD);496497/*498* Enable auto refresh and lock SDMR499*/500MCF_SDRAMC_SDCR &= ~MCF_SDRAMC_SDCR_MODE_EN;501MCF_SDRAMC_SDCR |= (0502| MCF_SDRAMC_SDCR_REF503| MCF_SDRAMC_SDCR_DQS_OE(0xC));504}505}506507void gpio_init(void)508{509/* Enable UART0 pins */510MCF_GPIO_PAR_UART = ( 0511| MCF_GPIO_PAR_UART_PAR_URXD0512| MCF_GPIO_PAR_UART_PAR_UTXD0);513514/* Initialize TIN3 as a GPIO output to enable the write515half of the latch */516MCF_GPIO_PAR_TIMER = 0x00;517__raw_writeb(0x08, MCFGPIO_PDDR_TIMER);518__raw_writeb(0x00, MCFGPIO_PCLRR_TIMER);519520}521522int clock_pll(int fsys, int flags)523{524int fref, temp, fout, mfd;525u32 i;526527fref = FREF;528529if (fsys == 0) {530/* Return current PLL output */531mfd = MCF_PLL_PFDR;532533return (fref * mfd / (BUSDIV * 4));534}535536/* Check bounds of requested system clock */537if (fsys > MAX_FSYS)538fsys = MAX_FSYS;539if (fsys < MIN_FSYS)540fsys = MIN_FSYS;541542/* Multiplying by 100 when calculating the temp value,543and then dividing by 100 to calculate the mfd allows544for exact values without needing to include floating545point libraries. */546temp = 100 * fsys / fref;547mfd = 4 * BUSDIV * temp / 100;548549/* Determine the output frequency for selected values */550fout = (fref * mfd / (BUSDIV * 4));551552/*553* Check to see if the SDRAM has already been initialized.554* If it has then the SDRAM needs to be put into self refresh555* mode before reprogramming the PLL.556*/557if (MCF_SDRAMC_SDCR & MCF_SDRAMC_SDCR_REF)558/* Put SDRAM into self refresh mode */559MCF_SDRAMC_SDCR &= ~MCF_SDRAMC_SDCR_CKE;560561/*562* Initialize the PLL to generate the new system clock frequency.563* The device must be put into LIMP mode to reprogram the PLL.564*/565566/* Enter LIMP mode */567clock_limp(DEFAULT_LPD);568569/* Reprogram PLL for desired fsys */570MCF_PLL_PODR = (0571| MCF_PLL_PODR_CPUDIV(BUSDIV/3)572| MCF_PLL_PODR_BUSDIV(BUSDIV));573574MCF_PLL_PFDR = mfd;575576/* Exit LIMP mode */577clock_exit_limp();578579/*580* Return the SDRAM to normal operation if it is in use.581*/582if (MCF_SDRAMC_SDCR & MCF_SDRAMC_SDCR_REF)583/* Exit self refresh mode */584MCF_SDRAMC_SDCR |= MCF_SDRAMC_SDCR_CKE;585586/* Errata - workaround for SDRAM opeartion after exiting LIMP mode */587MCF_SDRAMC_LIMP_FIX = MCF_SDRAMC_REFRESH;588589/* wait for DQS logic to relock */590for (i = 0; i < 0x200; i++)591;592593return fout;594}595596int clock_limp(int div)597{598u32 temp;599600/* Check bounds of divider */601if (div < MIN_LPD)602div = MIN_LPD;603if (div > MAX_LPD)604div = MAX_LPD;605606/* Save of the current value of the SSIDIV so we don't607overwrite the value*/608temp = (MCF_CCM_CDR & MCF_CCM_CDR_SSIDIV(0xF));609610/* Apply the divider to the system clock */611MCF_CCM_CDR = ( 0612| MCF_CCM_CDR_LPDIV(div)613| MCF_CCM_CDR_SSIDIV(temp));614615MCF_CCM_MISCCR |= MCF_CCM_MISCCR_LIMP;616617return (FREF/(3*(1 << div)));618}619620int clock_exit_limp(void)621{622int fout;623624/* Exit LIMP mode */625MCF_CCM_MISCCR = (MCF_CCM_MISCCR & ~ MCF_CCM_MISCCR_LIMP);626627/* Wait for PLL to lock */628while (!(MCF_CCM_MISCCR & MCF_CCM_MISCCR_PLL_LOCK))629;630631fout = get_sys_clock();632633return fout;634}635636int get_sys_clock(void)637{638int divider;639640/* Test to see if device is in LIMP mode */641if (MCF_CCM_MISCCR & MCF_CCM_MISCCR_LIMP) {642divider = MCF_CCM_CDR & MCF_CCM_CDR_LPDIV(0xF);643return (FREF/(2 << divider));644}645else646return ((FREF * MCF_PLL_PFDR) / (BUSDIV * 4));647}648649650