Andre Schwarz | b2de424 | 2008-06-10 09:14:05 +0200 | [diff] [blame] | 1 | /* |
Kumar Gala | 6a6d948 | 2009-07-28 21:49:52 -0500 | [diff] [blame] | 2 | * Copyright (C) Freescale Semiconductor, Inc. 2006. |
Andre Schwarz | b2de424 | 2008-06-10 09:14:05 +0200 | [diff] [blame] | 3 | * |
| 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 | |
Andre Schwarz | ba61a73 | 2009-08-31 16:18:24 +0200 | [diff] [blame] | 37 | #include "../common/mv_common.h" |
Andre Schwarz | b2de424 | 2008-06-10 09:14:05 +0200 | [diff] [blame] | 38 | #include "mvblm7.h" |
| 39 | |
| 40 | int fixed_sdram(void) |
| 41 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 42 | volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR; |
Andre Schwarz | b2de424 | 2008-06-10 09:14:05 +0200 | [diff] [blame] | 43 | u32 msize = 0; |
| 44 | u32 ddr_size; |
| 45 | u32 ddr_size_log2; |
André Schwarz | a8e1d95 | 2009-08-27 14:48:35 +0200 | [diff] [blame] | 46 | char *s = getenv("ddr_size"); |
Andre Schwarz | b2de424 | 2008-06-10 09:14:05 +0200 | [diff] [blame] | 47 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 48 | msize = CONFIG_SYS_DDR_SIZE; |
André Schwarz | a8e1d95 | 2009-08-27 14:48:35 +0200 | [diff] [blame] | 49 | if (s) { |
| 50 | u32 env_ddr_size = simple_strtoul(s, NULL, 10); |
| 51 | if (env_ddr_size == 512) |
| 52 | msize = 512; |
| 53 | } |
| 54 | |
Andre Schwarz | b2de424 | 2008-06-10 09:14:05 +0200 | [diff] [blame] | 55 | for (ddr_size = msize << 20, ddr_size_log2 = 0; |
Wolfgang Denk | 41df50a | 2008-06-28 23:34:37 +0200 | [diff] [blame] | 56 | (ddr_size > 1); |
| 57 | ddr_size = ddr_size >> 1, ddr_size_log2++) { |
Andre Schwarz | b2de424 | 2008-06-10 09:14:05 +0200 | [diff] [blame] | 58 | if (ddr_size & 1) |
| 59 | return -1; |
| 60 | } |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 61 | im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_SDRAM_BASE & 0xfffff000; |
Andre Schwarz | b2de424 | 2008-06-10 09:14:05 +0200 | [diff] [blame] | 62 | im->sysconf.ddrlaw[0].ar = LAWAR_EN | ((ddr_size_log2 - 1) & |
| 63 | LAWAR_SIZE); |
| 64 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 65 | im->ddr.csbnds[0].csbnds = CONFIG_SYS_DDR_CS0_BNDS; |
| 66 | im->ddr.cs_config[0] = CONFIG_SYS_DDR_CS0_CONFIG; |
| 67 | im->ddr.timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0; |
| 68 | im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1; |
| 69 | im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2; |
| 70 | im->ddr.timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3; |
| 71 | im->ddr.sdram_cfg = CONFIG_SYS_DDR_SDRAM_CFG; |
| 72 | im->ddr.sdram_cfg2 = CONFIG_SYS_DDR_SDRAM_CFG2; |
| 73 | im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE; |
André Schwarz | a8e1d95 | 2009-08-27 14:48:35 +0200 | [diff] [blame] | 74 | im->ddr.sdram_mode2 = CONFIG_SYS_DDR_MODE2; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 75 | im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL; |
André Schwarz | a8e1d95 | 2009-08-27 14:48:35 +0200 | [diff] [blame] | 76 | im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_SDRAM_CLK_CNTL; |
Andre Schwarz | b2de424 | 2008-06-10 09:14:05 +0200 | [diff] [blame] | 77 | |
André Schwarz | a8e1d95 | 2009-08-27 14:48:35 +0200 | [diff] [blame] | 78 | asm("sync;isync"); |
| 79 | udelay(600); |
Andre Schwarz | b2de424 | 2008-06-10 09:14:05 +0200 | [diff] [blame] | 80 | |
| 81 | im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN; |
| 82 | |
André Schwarz | a8e1d95 | 2009-08-27 14:48:35 +0200 | [diff] [blame] | 83 | asm("sync;isync"); |
| 84 | udelay(500); |
| 85 | |
| 86 | return msize; |
Andre Schwarz | b2de424 | 2008-06-10 09:14:05 +0200 | [diff] [blame] | 87 | } |
| 88 | |
Becky Bruce | bd99ae7 | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 89 | phys_size_t initdram(int board_type) |
Andre Schwarz | b2de424 | 2008-06-10 09:14:05 +0200 | [diff] [blame] | 90 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 91 | volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR; |
Andre Schwarz | b2de424 | 2008-06-10 09:14:05 +0200 | [diff] [blame] | 92 | u32 msize = 0; |
| 93 | |
| 94 | if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im) |
| 95 | return -1; |
| 96 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 97 | im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_BASE & LAWBAR_BAR; |
Andre Schwarz | b2de424 | 2008-06-10 09:14:05 +0200 | [diff] [blame] | 98 | msize = fixed_sdram(); |
| 99 | |
| 100 | /* return total bus RAM size(bytes) */ |
| 101 | return msize * 1024 * 1024; |
| 102 | } |
| 103 | |
André Schwarz | a8e1d95 | 2009-08-27 14:48:35 +0200 | [diff] [blame] | 104 | int misc_init_r(void) |
Andre Schwarz | b2de424 | 2008-06-10 09:14:05 +0200 | [diff] [blame] | 105 | { |
André Schwarz | a8e1d95 | 2009-08-27 14:48:35 +0200 | [diff] [blame] | 106 | char *s = getenv("reset_env"); |
Andre Schwarz | b2de424 | 2008-06-10 09:14:05 +0200 | [diff] [blame] | 107 | |
André Schwarz | a8e1d95 | 2009-08-27 14:48:35 +0200 | [diff] [blame] | 108 | if (s) { |
| 109 | mv_reset_environment(); |
Andre Schwarz | b2de424 | 2008-06-10 09:14:05 +0200 | [diff] [blame] | 110 | } |
| 111 | |
André Schwarz | a8e1d95 | 2009-08-27 14:48:35 +0200 | [diff] [blame] | 112 | return 0; |
Andre Schwarz | b2de424 | 2008-06-10 09:14:05 +0200 | [diff] [blame] | 113 | } |
| 114 | |
André Schwarz | a8e1d95 | 2009-08-27 14:48:35 +0200 | [diff] [blame] | 115 | int checkboard(void) |
Andre Schwarz | b2de424 | 2008-06-10 09:14:05 +0200 | [diff] [blame] | 116 | { |
André Schwarz | a8e1d95 | 2009-08-27 14:48:35 +0200 | [diff] [blame] | 117 | puts("Board: Matrix Vision mvBlueLYNX-M7\n"); |
| 118 | |
| 119 | return 0; |
Andre Schwarz | b2de424 | 2008-06-10 09:14:05 +0200 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | #ifdef CONFIG_HARD_SPI |
| 123 | int spi_cs_is_valid(unsigned int bus, unsigned int cs) |
| 124 | { |
Wolfgang Denk | 41df50a | 2008-06-28 23:34:37 +0200 | [diff] [blame] | 125 | return bus == 0 && cs == 0; |
Andre Schwarz | b2de424 | 2008-06-10 09:14:05 +0200 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | void spi_cs_activate(struct spi_slave *slave) |
| 129 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 130 | volatile gpio83xx_t *iopd = &((immap_t *)CONFIG_SYS_IMMR)->gpio[0]; |
Andre Schwarz | b2de424 | 2008-06-10 09:14:05 +0200 | [diff] [blame] | 131 | |
Wolfgang Denk | 41df50a | 2008-06-28 23:34:37 +0200 | [diff] [blame] | 132 | iopd->dat &= ~MVBLM7_MMC_CS; |
Andre Schwarz | b2de424 | 2008-06-10 09:14:05 +0200 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | void spi_cs_deactivate(struct spi_slave *slave) |
| 136 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 137 | volatile gpio83xx_t *iopd = &((immap_t *)CONFIG_SYS_IMMR)->gpio[0]; |
Andre Schwarz | b2de424 | 2008-06-10 09:14:05 +0200 | [diff] [blame] | 138 | |
Wolfgang Denk | 41df50a | 2008-06-28 23:34:37 +0200 | [diff] [blame] | 139 | iopd->dat |= ~MVBLM7_MMC_CS; |
Andre Schwarz | b2de424 | 2008-06-10 09:14:05 +0200 | [diff] [blame] | 140 | } |
| 141 | #endif |
| 142 | |
| 143 | #if defined(CONFIG_OF_BOARD_SETUP) |
| 144 | void ft_board_setup(void *blob, bd_t *bd) |
| 145 | { |
| 146 | ft_cpu_setup(blob, bd); |
| 147 | #ifdef CONFIG_PCI |
| 148 | ft_pci_setup(blob, bd); |
| 149 | #endif |
| 150 | } |
| 151 | |
| 152 | #endif |