blob: d82fee7b90fd4eb4d15290e9239eb20413ca7c23 [file] [log] [blame]
Julien May72646d22008-06-23 13:57:52 +02001/*
2 * Copyright (C) 2008 Miromico AG
3 *
4 * Mostly copied form atmel ATNGW100 sources
5 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
Julien May72646d22008-06-23 13:57:52 +02007 */
8
Julien May72646d22008-06-23 13:57:52 +02009#include <common.h>
Ben Warren2f2b6b62008-08-31 22:22:04 -070010#include <netdev.h>
Julien May72646d22008-06-23 13:57:52 +020011
12#include <asm/io.h>
13#include <asm/sdram.h>
14#include <asm/arch/clk.h>
Julien May72646d22008-06-23 13:57:52 +020015#include <asm/arch/hmatrix.h>
Andreas Bießmann94156fa2010-11-04 23:15:30 +000016#include <asm/arch/hardware.h>
Haavard Skinnemoenc6f292f2010-08-12 13:52:54 +070017#include <asm/arch/mmu.h>
Haavard Skinnemoen610b3622008-08-29 21:09:49 +020018#include <asm/arch/portmux.h>
Julien May72646d22008-06-23 13:57:52 +020019
20DECLARE_GLOBAL_DATA_PTR;
21
Haavard Skinnemoenc6f292f2010-08-12 13:52:54 +070022struct mmu_vm_range mmu_vmr_table[CONFIG_SYS_NR_VM_REGIONS] = {
23 {
24 .virt_pgno = CONFIG_SYS_FLASH_BASE >> PAGE_SHIFT,
25 .nr_pages = CONFIG_SYS_FLASH_SIZE >> PAGE_SHIFT,
26 .phys = (CONFIG_SYS_FLASH_BASE >> PAGE_SHIFT)
27 | MMU_VMR_CACHE_NONE,
28 }, {
29 .virt_pgno = CONFIG_SYS_SDRAM_BASE >> PAGE_SHIFT,
30 .nr_pages = EBI_SDRAM_SIZE >> PAGE_SHIFT,
31 .phys = (CONFIG_SYS_SDRAM_BASE >> PAGE_SHIFT)
32 | MMU_VMR_CACHE_WRBACK,
33 },
34};
35
Julien May72646d22008-06-23 13:57:52 +020036static const struct sdram_config sdram_config = {
37 .data_bits = SDRAM_DATA_32BIT,
38 .row_bits = 13,
39 .col_bits = 9,
40 .bank_bits = 2,
41 .cas = 3,
42 .twr = 2,
43 .trc = 7,
44 .trp = 2,
45 .trcd = 2,
46 .tras = 5,
47 .txsr = 5,
48 /* 7.81 us */
49 .refresh_period = (781 * (SDRAMC_BUS_HZ / 1000)) / 100000,
50};
51
Julien May72646d22008-06-23 13:57:52 +020052#ifdef CONFIG_CMD_NET
53int board_eth_init(bd_t *bis)
54{
Andreas Bießmann5807e792010-11-04 23:15:31 +000055 return macb_eth_initialize(0, (void *)ATMEL_BASE_MACB0,
56 bis->bi_phy_id[0]);
Julien May72646d22008-06-23 13:57:52 +020057}
58#endif
59
60int board_early_init_f(void)
61{
62 /* Enable SDRAM in the EBI mux */
63 hmatrix_slave_write(EBI, SFR, HMATRIX_BIT(EBI_SDRAM_ENABLE));
64
Haavard Skinnemoen610b3622008-08-29 21:09:49 +020065 portmux_enable_ebi(32, 23, 0, PORTMUX_DRIVE_HIGH);
66 portmux_enable_usart1(PORTMUX_DRIVE_MIN);
Julien May72646d22008-06-23 13:57:52 +020067
68#if defined(CONFIG_MACB)
Haavard Skinnemoen610b3622008-08-29 21:09:49 +020069 portmux_enable_macb0(PORTMUX_MACB_MII, PORTMUX_DRIVE_HIGH);
Julien May72646d22008-06-23 13:57:52 +020070#endif
71#if defined(CONFIG_MMC)
Haavard Skinnemoen610b3622008-08-29 21:09:49 +020072 portmux_enable_mmci(0, PORTMUX_MMCI_4BIT, PORTMUX_DRIVE_LOW);
Julien May72646d22008-06-23 13:57:52 +020073#endif
74 return 0;
75}
76
77phys_size_t initdram(int board_type)
78{
79 unsigned long expected_size;
80 unsigned long actual_size;
81 void *sdram_base;
82
Haavard Skinnemoen6f161e42010-08-12 13:52:53 +070083 sdram_base = uncached(EBI_SDRAM_BASE);
Julien May72646d22008-06-23 13:57:52 +020084
85 expected_size = sdram_init(sdram_base, &sdram_config);
86 actual_size = get_ram_size(sdram_base, expected_size);
87
Julien May72646d22008-06-23 13:57:52 +020088 if (expected_size != actual_size)
89 printf("Warning: Only %lu of %lu MiB SDRAM is working\n",
90 actual_size >> 20, expected_size >> 20);
91
92 return actual_size;
93}
94
Haavard Skinnemoend6799f72008-08-31 18:46:35 +020095int board_early_init_r(void)
Julien May72646d22008-06-23 13:57:52 +020096{
97 gd->bd->bi_phy_id[0] = 0x01;
Haavard Skinnemoend6799f72008-08-31 18:46:35 +020098 return 0;
Julien May72646d22008-06-23 13:57:52 +020099}
100
Haavard Skinnemoen23ba3ac2008-08-31 18:24:24 +0200101int board_postclk_init(void)
Julien May72646d22008-06-23 13:57:52 +0200102{
103 /* Hammerhead boards uses GCLK3 as 25MHz output to ethernet PHY */
Haavard Skinnemoen7d1d7572008-08-31 18:07:35 +0200104 gclk_enable_output(3, PORTMUX_DRIVE_LOW);
105 gclk_set_rate(3, GCLK_PARENT_OSC0, 25000000);
Haavard Skinnemoen23ba3ac2008-08-31 18:24:24 +0200106 return 0;
Julien May72646d22008-06-23 13:57:52 +0200107}