blob: b58c1b902661d4359ee12a9b72b2c618129260bc [file] [log] [blame]
Andre Schwarza1293e52008-06-10 09:14:05 +02001/*
Kumar Gala4c2e3da2009-07-28 21:49:52 -05002 * Copyright (C) Freescale Semiconductor, Inc. 2006.
Andre Schwarza1293e52008-06-10 09:14:05 +02003 *
4 * (C) Copyright 2008
5 * Andre Schwarz, Matrix Vision GmbH, andre.schwarz@matrix-vision.de
6 *
7 * See file CREDITS for list of people who contributed to this
8 * project.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS for A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 * MA 02111-1307 USA
24 */
25
26#include <common.h>
27#include <ioports.h>
28#include <mpc83xx.h>
29#include <asm/mpc8349_pci.h>
30#include <pci.h>
31#include <spi.h>
32#include <asm/mmu.h>
33#if defined(CONFIG_OF_LIBFDT)
34#include <libfdt.h>
35#endif
36
37#include "mvblm7.h"
38
39int fixed_sdram(void)
40{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020041 volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
Andre Schwarza1293e52008-06-10 09:14:05 +020042 u32 msize = 0;
43 u32 ddr_size;
44 u32 ddr_size_log2;
André Schwarz28887d82009-08-27 14:48:35 +020045 char *s = getenv("ddr_size");
Andre Schwarza1293e52008-06-10 09:14:05 +020046
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020047 msize = CONFIG_SYS_DDR_SIZE;
André Schwarz28887d82009-08-27 14:48:35 +020048 if (s) {
49 u32 env_ddr_size = simple_strtoul(s, NULL, 10);
50 if (env_ddr_size == 512)
51 msize = 512;
52 }
53
Andre Schwarza1293e52008-06-10 09:14:05 +020054 for (ddr_size = msize << 20, ddr_size_log2 = 0;
Wolfgang Denke093a242008-06-28 23:34:37 +020055 (ddr_size > 1);
56 ddr_size = ddr_size >> 1, ddr_size_log2++) {
Andre Schwarza1293e52008-06-10 09:14:05 +020057 if (ddr_size & 1)
58 return -1;
59 }
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020060 im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_SDRAM_BASE & 0xfffff000;
Andre Schwarza1293e52008-06-10 09:14:05 +020061 im->sysconf.ddrlaw[0].ar = LAWAR_EN | ((ddr_size_log2 - 1) &
62 LAWAR_SIZE);
63
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020064 im->ddr.csbnds[0].csbnds = CONFIG_SYS_DDR_CS0_BNDS;
65 im->ddr.cs_config[0] = CONFIG_SYS_DDR_CS0_CONFIG;
66 im->ddr.timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
67 im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
68 im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
69 im->ddr.timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
70 im->ddr.sdram_cfg = CONFIG_SYS_DDR_SDRAM_CFG;
71 im->ddr.sdram_cfg2 = CONFIG_SYS_DDR_SDRAM_CFG2;
72 im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
André Schwarz28887d82009-08-27 14:48:35 +020073 im->ddr.sdram_mode2 = CONFIG_SYS_DDR_MODE2;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020074 im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
André Schwarz28887d82009-08-27 14:48:35 +020075 im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_SDRAM_CLK_CNTL;
Andre Schwarza1293e52008-06-10 09:14:05 +020076
André Schwarz28887d82009-08-27 14:48:35 +020077 asm("sync;isync");
78 udelay(600);
Andre Schwarza1293e52008-06-10 09:14:05 +020079
80 im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
81
André Schwarz28887d82009-08-27 14:48:35 +020082 asm("sync;isync");
83 udelay(500);
84
85 return msize;
Andre Schwarza1293e52008-06-10 09:14:05 +020086}
87
Becky Bruce9973e3c2008-06-09 16:03:40 -050088phys_size_t initdram(int board_type)
Andre Schwarza1293e52008-06-10 09:14:05 +020089{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020090 volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
Andre Schwarza1293e52008-06-10 09:14:05 +020091 u32 msize = 0;
92
93 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
94 return -1;
95
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020096 im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_BASE & LAWBAR_BAR;
Andre Schwarza1293e52008-06-10 09:14:05 +020097 msize = fixed_sdram();
98
99 /* return total bus RAM size(bytes) */
100 return msize * 1024 * 1024;
101}
102
André Schwarz28887d82009-08-27 14:48:35 +0200103int misc_init_r(void)
104{
105 char *s = getenv("reset_env");
106
107 if (s) {
108 mv_reset_environment();
109 }
110
111 return 0;
112}
113
Andre Schwarza1293e52008-06-10 09:14:05 +0200114int checkboard(void)
115{
Andre Schwarz5ed546f2008-07-02 18:54:08 +0200116 puts("Board: Matrix Vision mvBlueLYNX-M7\n");
Andre Schwarza1293e52008-06-10 09:14:05 +0200117
118 return 0;
119}
120
Andre Schwarza1293e52008-06-10 09:14:05 +0200121#ifdef CONFIG_HARD_SPI
122int spi_cs_is_valid(unsigned int bus, unsigned int cs)
123{
Wolfgang Denke093a242008-06-28 23:34:37 +0200124 return bus == 0 && cs == 0;
Andre Schwarza1293e52008-06-10 09:14:05 +0200125}
126
127void spi_cs_activate(struct spi_slave *slave)
128{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200129 volatile gpio83xx_t *iopd = &((immap_t *)CONFIG_SYS_IMMR)->gpio[0];
Andre Schwarza1293e52008-06-10 09:14:05 +0200130
Wolfgang Denke093a242008-06-28 23:34:37 +0200131 iopd->dat &= ~MVBLM7_MMC_CS;
Andre Schwarza1293e52008-06-10 09:14:05 +0200132}
133
134void spi_cs_deactivate(struct spi_slave *slave)
135{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200136 volatile gpio83xx_t *iopd = &((immap_t *)CONFIG_SYS_IMMR)->gpio[0];
Andre Schwarza1293e52008-06-10 09:14:05 +0200137
Wolfgang Denke093a242008-06-28 23:34:37 +0200138 iopd->dat |= ~MVBLM7_MMC_CS;
Andre Schwarza1293e52008-06-10 09:14:05 +0200139}
140#endif
141
142#if defined(CONFIG_OF_BOARD_SETUP)
143void ft_board_setup(void *blob, bd_t *bd)
144{
145 ft_cpu_setup(blob, bd);
146#ifdef CONFIG_PCI
147 ft_pci_setup(blob, bd);
148#endif
149}
150
151#endif