Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 Atmel Corporation |
| 3 | * |
| 4 | * See file CREDITS for list of people who contributed to this |
| 5 | * project. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License as |
| 9 | * published by the Free Software Foundation; either version 2 of |
| 10 | * the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 20 | * MA 02111-1307 USA |
| 21 | */ |
| 22 | #include <common.h> |
Ben Warren | 89973f8 | 2008-08-31 22:22:04 -0700 | [diff] [blame] | 23 | #include <netdev.h> |
Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 24 | |
| 25 | #include <asm/io.h> |
| 26 | #include <asm/sdram.h> |
| 27 | #include <asm/arch/clk.h> |
| 28 | #include <asm/arch/gpio.h> |
| 29 | #include <asm/arch/hmatrix.h> |
Haavard Skinnemoen | ab0df36 | 2008-08-29 21:09:49 +0200 | [diff] [blame] | 30 | #include <asm/arch/portmux.h> |
Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 31 | #include <lcd.h> |
| 32 | |
Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 33 | DECLARE_GLOBAL_DATA_PTR; |
| 34 | |
| 35 | static const struct sdram_config sdram_config = { |
| 36 | .data_bits = SDRAM_DATA_16BIT, |
| 37 | .row_bits = 13, |
| 38 | .col_bits = 9, |
| 39 | .bank_bits = 2, |
| 40 | .cas = 3, |
| 41 | .twr = 2, |
| 42 | .trc = 6, |
| 43 | .trp = 2, |
| 44 | .trcd = 2, |
| 45 | .tras = 6, |
| 46 | .txsr = 6, |
| 47 | /* 15.6 us */ |
| 48 | .refresh_period = (156 * (SDRAMC_BUS_HZ / 1000)) / 10000, |
| 49 | }; |
| 50 | |
| 51 | int board_early_init_f(void) |
| 52 | { |
| 53 | /* Enable SDRAM in the EBI mux */ |
| 54 | hmatrix_slave_write(EBI, SFR, HMATRIX_BIT(EBI_SDRAM_ENABLE)); |
| 55 | |
Haavard Skinnemoen | ab0df36 | 2008-08-29 21:09:49 +0200 | [diff] [blame] | 56 | /* Enable 26 address bits and NCS2 */ |
| 57 | portmux_enable_ebi(16, 26, PORTMUX_EBI_CS(2), PORTMUX_DRIVE_HIGH); |
| 58 | portmux_enable_usart1(PORTMUX_DRIVE_MIN); |
Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 59 | |
| 60 | /* de-assert "force sys reset" pin */ |
Haavard Skinnemoen | ab0df36 | 2008-08-29 21:09:49 +0200 | [diff] [blame] | 61 | portmux_select_gpio(PORTMUX_PORT_D, 1 << 15, |
| 62 | PORTMUX_DIR_OUTPUT | PORTMUX_INIT_HIGH); |
Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 63 | |
| 64 | /* init custom i/o */ |
| 65 | /* cpu type inputs */ |
Haavard Skinnemoen | ab0df36 | 2008-08-29 21:09:49 +0200 | [diff] [blame] | 66 | portmux_select_gpio(PORTMUX_PORT_E, (1 << 19) | (1 << 20) | (1 << 23), |
| 67 | PORTMUX_DIR_INPUT); |
Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 68 | /* main board type inputs */ |
Haavard Skinnemoen | ab0df36 | 2008-08-29 21:09:49 +0200 | [diff] [blame] | 69 | portmux_select_gpio(PORTMUX_PORT_B, (1 << 19) | (1 << 29), |
| 70 | PORTMUX_DIR_INPUT); |
Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 71 | /* DEBUG input (use weak pullup) */ |
Haavard Skinnemoen | ab0df36 | 2008-08-29 21:09:49 +0200 | [diff] [blame] | 72 | portmux_select_gpio(PORTMUX_PORT_E, 1 << 21, |
| 73 | PORTMUX_DIR_INPUT | PORTMUX_PULL_UP); |
Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 74 | |
| 75 | /* are we suppressing the console ? */ |
Haavard Skinnemoen | ab0df36 | 2008-08-29 21:09:49 +0200 | [diff] [blame] | 76 | if (gpio_get_value(GPIO_PIN_PE(21)) == 1) |
Mark Jackson | a69a423 | 2008-10-03 11:48:57 +0100 | [diff] [blame] | 77 | gd->flags |= (GD_FLG_SILENT | GD_FLG_DISABLE_CONSOLE); |
Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 78 | |
| 79 | /* reset phys */ |
Haavard Skinnemoen | ab0df36 | 2008-08-29 21:09:49 +0200 | [diff] [blame] | 80 | portmux_select_gpio(PORTMUX_PORT_E, 1 << 24, PORTMUX_DIR_INPUT); |
| 81 | portmux_select_gpio(PORTMUX_PORT_C, 1 << 18, |
| 82 | PORTMUX_DIR_OUTPUT | PORTMUX_INIT_HIGH); |
Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 83 | |
Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 84 | udelay(5000); |
| 85 | |
| 86 | /* release phys reset */ |
Haavard Skinnemoen | ab0df36 | 2008-08-29 21:09:49 +0200 | [diff] [blame] | 87 | gpio_set_value(GPIO_PIN_PC(18), 0); /* PHY RESET (Release) */ |
Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 88 | |
| 89 | #if defined(CONFIG_MACB) |
| 90 | /* init macb0 pins */ |
Haavard Skinnemoen | ab0df36 | 2008-08-29 21:09:49 +0200 | [diff] [blame] | 91 | portmux_enable_macb0(PORTMUX_MACB_MII, PORTMUX_DRIVE_HIGH); |
| 92 | portmux_enable_macb1(PORTMUX_MACB_MII, PORTMUX_DRIVE_HIGH); |
Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 93 | #endif |
| 94 | |
| 95 | #if defined(CONFIG_MMC) |
Haavard Skinnemoen | ab0df36 | 2008-08-29 21:09:49 +0200 | [diff] [blame] | 96 | portmux_enable_mmci(0, PORTMUX_MMCI_4BIT, PORTMUX_DRIVE_LOW); |
Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 97 | #endif |
| 98 | |
| 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | phys_size_t initdram(int board_type) |
| 103 | { |
| 104 | unsigned long expected_size; |
| 105 | unsigned long actual_size; |
| 106 | void *sdram_base; |
| 107 | |
| 108 | sdram_base = map_physmem(EBI_SDRAM_BASE, EBI_SDRAM_SIZE, MAP_NOCACHE); |
| 109 | |
| 110 | expected_size = sdram_init(sdram_base, &sdram_config); |
| 111 | actual_size = get_ram_size(sdram_base, expected_size); |
| 112 | |
| 113 | unmap_physmem(sdram_base, EBI_SDRAM_SIZE); |
| 114 | |
| 115 | if (expected_size != actual_size) |
| 116 | printf("Warning: Only %lu of %lu MiB SDRAM is working\n", |
| 117 | actual_size >> 20, expected_size >> 20); |
| 118 | |
| 119 | return actual_size; |
| 120 | } |
| 121 | |
Haavard Skinnemoen | 25e6854 | 2008-08-31 18:46:35 +0200 | [diff] [blame] | 122 | int board_early_init_r(void) |
Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 123 | { |
| 124 | gd->bd->bi_phy_id[0] = 0x01; |
| 125 | gd->bd->bi_phy_id[1] = 0x03; |
Haavard Skinnemoen | 25e6854 | 2008-08-31 18:46:35 +0200 | [diff] [blame] | 126 | return 0; |
Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 127 | } |
| 128 | |
Mark Jackson | 8053488 | 2008-11-24 12:10:56 +0000 | [diff] [blame^] | 129 | int board_postclk_init(void) |
| 130 | { |
| 131 | /* Use GCLK0 as 10MHz output */ |
| 132 | gclk_enable_output(0, PORTMUX_DRIVE_LOW); |
| 133 | gclk_set_rate(0, GCLK_PARENT_OSC0, 10000000); |
| 134 | return 0; |
| 135 | } |
| 136 | |
Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 137 | /* SPI chip select control */ |
| 138 | #ifdef CONFIG_ATMEL_SPI |
| 139 | #include <spi.h> |
| 140 | |
| 141 | int spi_cs_is_valid(unsigned int bus, unsigned int cs) |
| 142 | { |
| 143 | return (bus == 0) && (cs == 0); |
| 144 | } |
| 145 | |
| 146 | void spi_cs_activate(struct spi_slave *slave) |
| 147 | { |
| 148 | } |
| 149 | |
| 150 | void spi_cs_deactivate(struct spi_slave *slave) |
| 151 | { |
| 152 | } |
| 153 | #endif /* CONFIG_ATMEL_SPI */ |
| 154 | |
| 155 | #ifdef CONFIG_CMD_NET |
Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 156 | int board_eth_init(bd_t *bi) |
| 157 | { |
| 158 | macb_eth_initialize(0, (void *)MACB0_BASE, bi->bi_phy_id[0]); |
| 159 | macb_eth_initialize(1, (void *)MACB1_BASE, bi->bi_phy_id[1]); |
| 160 | |
| 161 | return 0; |
| 162 | } |
| 163 | #endif |