blob: f3c16a3e9cf6af4141b251319a3830067930c312 [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 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02007 * SPDX-License-Identifier: GPL-2.0+
Andre Schwarza1293e52008-06-10 09:14:05 +02008 */
9
10#include <common.h>
11#include <ioports.h>
12#include <mpc83xx.h>
13#include <asm/mpc8349_pci.h>
14#include <pci.h>
15#include <spi.h>
16#include <asm/mmu.h>
17#if defined(CONFIG_OF_LIBFDT)
18#include <libfdt.h>
19#endif
20
Andre Schwarz632a6dd2009-08-31 16:18:24 +020021#include "../common/mv_common.h"
Andre Schwarza1293e52008-06-10 09:14:05 +020022#include "mvblm7.h"
23
24int fixed_sdram(void)
25{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020026 volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
Andre Schwarza1293e52008-06-10 09:14:05 +020027 u32 msize = 0;
28 u32 ddr_size;
29 u32 ddr_size_log2;
André Schwarz28887d82009-08-27 14:48:35 +020030 char *s = getenv("ddr_size");
Andre Schwarza1293e52008-06-10 09:14:05 +020031
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020032 msize = CONFIG_SYS_DDR_SIZE;
André Schwarz28887d82009-08-27 14:48:35 +020033 if (s) {
34 u32 env_ddr_size = simple_strtoul(s, NULL, 10);
35 if (env_ddr_size == 512)
36 msize = 512;
37 }
38
Andre Schwarza1293e52008-06-10 09:14:05 +020039 for (ddr_size = msize << 20, ddr_size_log2 = 0;
Wolfgang Denke093a242008-06-28 23:34:37 +020040 (ddr_size > 1);
41 ddr_size = ddr_size >> 1, ddr_size_log2++) {
Andre Schwarza1293e52008-06-10 09:14:05 +020042 if (ddr_size & 1)
43 return -1;
44 }
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020045 im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_SDRAM_BASE & 0xfffff000;
Andre Schwarza1293e52008-06-10 09:14:05 +020046 im->sysconf.ddrlaw[0].ar = LAWAR_EN | ((ddr_size_log2 - 1) &
47 LAWAR_SIZE);
48
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020049 im->ddr.csbnds[0].csbnds = CONFIG_SYS_DDR_CS0_BNDS;
50 im->ddr.cs_config[0] = CONFIG_SYS_DDR_CS0_CONFIG;
51 im->ddr.timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
52 im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
53 im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
54 im->ddr.timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
55 im->ddr.sdram_cfg = CONFIG_SYS_DDR_SDRAM_CFG;
56 im->ddr.sdram_cfg2 = CONFIG_SYS_DDR_SDRAM_CFG2;
57 im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
André Schwarz28887d82009-08-27 14:48:35 +020058 im->ddr.sdram_mode2 = CONFIG_SYS_DDR_MODE2;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020059 im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
André Schwarz28887d82009-08-27 14:48:35 +020060 im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_SDRAM_CLK_CNTL;
Andre Schwarza1293e52008-06-10 09:14:05 +020061
André Schwarz28887d82009-08-27 14:48:35 +020062 asm("sync;isync");
63 udelay(600);
Andre Schwarza1293e52008-06-10 09:14:05 +020064
65 im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
66
André Schwarz28887d82009-08-27 14:48:35 +020067 asm("sync;isync");
68 udelay(500);
69
70 return msize;
Andre Schwarza1293e52008-06-10 09:14:05 +020071}
72
Becky Bruce9973e3c2008-06-09 16:03:40 -050073phys_size_t initdram(int board_type)
Andre Schwarza1293e52008-06-10 09:14:05 +020074{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020075 volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
Andre Schwarza1293e52008-06-10 09:14:05 +020076 u32 msize = 0;
77
78 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
79 return -1;
80
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020081 im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_BASE & LAWBAR_BAR;
Andre Schwarza1293e52008-06-10 09:14:05 +020082 msize = fixed_sdram();
83
84 /* return total bus RAM size(bytes) */
85 return msize * 1024 * 1024;
86}
87
André Schwarz28887d82009-08-27 14:48:35 +020088int misc_init_r(void)
89{
90 char *s = getenv("reset_env");
91
92 if (s) {
93 mv_reset_environment();
94 }
95
96 return 0;
97}
98
Andre Schwarza1293e52008-06-10 09:14:05 +020099int checkboard(void)
100{
Andre Schwarz5ed546f2008-07-02 18:54:08 +0200101 puts("Board: Matrix Vision mvBlueLYNX-M7\n");
Andre Schwarza1293e52008-06-10 09:14:05 +0200102
103 return 0;
104}
105
Andre Schwarza1293e52008-06-10 09:14:05 +0200106#ifdef CONFIG_HARD_SPI
107int spi_cs_is_valid(unsigned int bus, unsigned int cs)
108{
Wolfgang Denke093a242008-06-28 23:34:37 +0200109 return bus == 0 && cs == 0;
Andre Schwarza1293e52008-06-10 09:14:05 +0200110}
111
112void spi_cs_activate(struct spi_slave *slave)
113{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200114 volatile gpio83xx_t *iopd = &((immap_t *)CONFIG_SYS_IMMR)->gpio[0];
Andre Schwarza1293e52008-06-10 09:14:05 +0200115
Wolfgang Denke093a242008-06-28 23:34:37 +0200116 iopd->dat &= ~MVBLM7_MMC_CS;
Andre Schwarza1293e52008-06-10 09:14:05 +0200117}
118
119void spi_cs_deactivate(struct spi_slave *slave)
120{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200121 volatile gpio83xx_t *iopd = &((immap_t *)CONFIG_SYS_IMMR)->gpio[0];
Andre Schwarza1293e52008-06-10 09:14:05 +0200122
Wolfgang Denke093a242008-06-28 23:34:37 +0200123 iopd->dat |= ~MVBLM7_MMC_CS;
Andre Schwarza1293e52008-06-10 09:14:05 +0200124}
125#endif
126
127#if defined(CONFIG_OF_BOARD_SETUP)
128void ft_board_setup(void *blob, bd_t *bd)
129{
130 ft_cpu_setup(blob, bd);
131#ifdef CONFIG_PCI
132 ft_pci_setup(blob, bd);
133#endif
134}
135
136#endif