Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
TENART Antoine | 7a5eb65 | 2013-07-02 12:06:00 +0200 | [diff] [blame] | 2 | /* |
| 3 | * evm.c |
| 4 | * |
| 5 | * Copyright (C) 2013, Adeneo Embedded <www.adeneo-embedded.com> |
| 6 | * Antoine Tenart, <atenart@adeneo-embedded.com> |
TENART Antoine | 7a5eb65 | 2013-07-02 12:06:00 +0200 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
Alex Kiernan | 9c21549 | 2018-04-01 09:22:38 +0000 | [diff] [blame] | 10 | #include <environment.h> |
TENART Antoine | 7a5eb65 | 2013-07-02 12:06:00 +0200 | [diff] [blame] | 11 | #include <spl.h> |
| 12 | #include <asm/cache.h> |
| 13 | #include <asm/io.h> |
| 14 | #include <asm/arch/clock.h> |
| 15 | #include <asm/arch/cpu.h> |
| 16 | #include <asm/arch/ddr_defs.h> |
| 17 | #include <asm/arch/hardware.h> |
| 18 | #include <asm/arch/sys_proto.h> |
| 19 | #include <asm/arch/mmc_host_def.h> |
| 20 | #include <asm/arch/mem.h> |
| 21 | #include <asm/arch/mux.h> |
| 22 | |
| 23 | DECLARE_GLOBAL_DATA_PTR; |
| 24 | |
| 25 | int board_init(void) |
| 26 | { |
Tom Rini | b05ee2f | 2017-05-16 14:46:39 -0400 | [diff] [blame] | 27 | gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100; |
Tom Rini | 28bfc1b | 2017-05-16 14:46:37 -0400 | [diff] [blame] | 28 | #if defined(CONFIG_NAND) |
| 29 | gpmc_init(); |
| 30 | #endif |
TENART Antoine | 7a5eb65 | 2013-07-02 12:06:00 +0200 | [diff] [blame] | 31 | return 0; |
| 32 | } |
| 33 | |
Tom Rini | c3cf899 | 2017-05-10 12:01:02 -0400 | [diff] [blame] | 34 | int board_eth_init(bd_t *bis) |
| 35 | { |
| 36 | uint8_t mac_addr[6]; |
| 37 | uint32_t mac_hi, mac_lo; |
| 38 | struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE; |
| 39 | |
Simon Glass | 399a9ce | 2017-08-03 12:22:14 -0600 | [diff] [blame] | 40 | if (!eth_env_get_enetaddr("ethaddr", mac_addr)) { |
Tom Rini | c3cf899 | 2017-05-10 12:01:02 -0400 | [diff] [blame] | 41 | printf("<ethaddr> not set. Reading from E-fuse\n"); |
| 42 | /* try reading mac address from efuse */ |
| 43 | mac_lo = readl(&cdev->macid0l); |
| 44 | mac_hi = readl(&cdev->macid0h); |
| 45 | mac_addr[0] = mac_hi & 0xFF; |
| 46 | mac_addr[1] = (mac_hi & 0xFF00) >> 8; |
| 47 | mac_addr[2] = (mac_hi & 0xFF0000) >> 16; |
| 48 | mac_addr[3] = (mac_hi & 0xFF000000) >> 24; |
| 49 | mac_addr[4] = mac_lo & 0xFF; |
| 50 | mac_addr[5] = (mac_lo & 0xFF00) >> 8; |
| 51 | |
| 52 | if (is_valid_ethaddr(mac_addr)) |
Simon Glass | 8551d55 | 2017-08-03 12:22:11 -0600 | [diff] [blame] | 53 | eth_env_set_enetaddr("ethaddr", mac_addr); |
Tom Rini | c3cf899 | 2017-05-10 12:01:02 -0400 | [diff] [blame] | 54 | else |
| 55 | printf("Unable to read MAC address. Set <ethaddr>\n"); |
| 56 | } |
| 57 | |
Bartosz Golaszewski | 2cedf75 | 2019-07-24 10:12:07 +0200 | [diff] [blame] | 58 | return 0; |
Tom Rini | c3cf899 | 2017-05-10 12:01:02 -0400 | [diff] [blame] | 59 | } |
| 60 | |
TENART Antoine | 7a5eb65 | 2013-07-02 12:06:00 +0200 | [diff] [blame] | 61 | #ifdef CONFIG_SPL_BUILD |
TENART Antoine | 7a5eb65 | 2013-07-02 12:06:00 +0200 | [diff] [blame] | 62 | static struct module_pin_mux mmc_pin_mux[] = { |
| 63 | { OFFSET(pincntl157), PULLDOWN_EN | PULLUDDIS | MODE(0x0) }, |
| 64 | { OFFSET(pincntl158), PULLDOWN_EN | PULLUDEN | MODE(0x0) }, |
| 65 | { OFFSET(pincntl159), PULLUP_EN | PULLUDDIS | MODE(0x0) }, |
| 66 | { OFFSET(pincntl160), PULLUP_EN | PULLUDDIS | MODE(0x0) }, |
| 67 | { OFFSET(pincntl161), PULLUP_EN | PULLUDDIS | MODE(0x0) }, |
| 68 | { OFFSET(pincntl162), PULLUP_EN | PULLUDDIS | MODE(0x0) }, |
| 69 | { OFFSET(pincntl163), PULLUP_EN | PULLUDDIS | MODE(0x0) }, |
| 70 | { -1 }, |
| 71 | }; |
| 72 | |
Tom Rini | fbb2552 | 2017-05-16 14:46:35 -0400 | [diff] [blame] | 73 | void set_uart_mux_conf(void) {} |
TENART Antoine | 7a5eb65 | 2013-07-02 12:06:00 +0200 | [diff] [blame] | 74 | |
Tom Rini | fbb2552 | 2017-05-16 14:46:35 -0400 | [diff] [blame] | 75 | void set_mux_conf_regs(void) |
| 76 | { |
| 77 | configure_module_pin_mux(mmc_pin_mux); |
| 78 | } |
TENART Antoine | 7a5eb65 | 2013-07-02 12:06:00 +0200 | [diff] [blame] | 79 | |
| 80 | /* |
Tom Rini | fbb2552 | 2017-05-16 14:46:35 -0400 | [diff] [blame] | 81 | * EMIF Paramters. Refer the EMIF register documentation and the |
| 82 | * memory datasheet for details. This is for 796 MHz. |
TENART Antoine | 7a5eb65 | 2013-07-02 12:06:00 +0200 | [diff] [blame] | 83 | */ |
Tom Rini | fbb2552 | 2017-05-16 14:46:35 -0400 | [diff] [blame] | 84 | #define EMIF_TIM1 0x1779C9FE |
| 85 | #define EMIF_TIM2 0x50608074 |
| 86 | #define EMIF_TIM3 0x009F857F |
| 87 | #define EMIF_SDREF 0x10001841 |
| 88 | #define EMIF_SDCFG 0x62A73832 |
| 89 | #define EMIF_PHYCFG 0x00000110 |
| 90 | static const struct emif_regs ddr3_emif_regs = { |
| 91 | .sdram_config = EMIF_SDCFG, |
| 92 | .ref_ctrl = EMIF_SDREF, |
| 93 | .sdram_tim1 = EMIF_TIM1, |
| 94 | .sdram_tim2 = EMIF_TIM2, |
| 95 | .sdram_tim3 = EMIF_TIM3, |
| 96 | .emif_ddr_phy_ctlr_1 = EMIF_PHYCFG, |
TENART Antoine | 7a5eb65 | 2013-07-02 12:06:00 +0200 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | static const struct cmd_control ddr3_ctrl = { |
| 100 | .cmd0csratio = 0x100, |
TENART Antoine | 7a5eb65 | 2013-07-02 12:06:00 +0200 | [diff] [blame] | 101 | .cmd0iclkout = 0x001, |
TENART Antoine | 7a5eb65 | 2013-07-02 12:06:00 +0200 | [diff] [blame] | 102 | .cmd1csratio = 0x100, |
TENART Antoine | 7a5eb65 | 2013-07-02 12:06:00 +0200 | [diff] [blame] | 103 | .cmd1iclkout = 0x001, |
TENART Antoine | 7a5eb65 | 2013-07-02 12:06:00 +0200 | [diff] [blame] | 104 | .cmd2csratio = 0x100, |
TENART Antoine | 7a5eb65 | 2013-07-02 12:06:00 +0200 | [diff] [blame] | 105 | .cmd2iclkout = 0x001, |
| 106 | }; |
| 107 | |
Tom Rini | fbb2552 | 2017-05-16 14:46:35 -0400 | [diff] [blame] | 108 | /* These values are obtained from the CCS app */ |
| 109 | #define RD_DQS_GATE (0x1B3) |
| 110 | #define RD_DQS (0x35) |
| 111 | #define WR_DQS (0x93) |
| 112 | static struct ddr_data ddr3_data = { |
| 113 | .datardsratio0 = ((RD_DQS<<10) | (RD_DQS<<0)), |
| 114 | .datawdsratio0 = ((WR_DQS<<10) | (WR_DQS<<0)), |
| 115 | .datawiratio0 = ((0x20<<10) | 0x20<<0), |
| 116 | .datagiratio0 = ((0x20<<10) | 0x20<<0), |
| 117 | .datafwsratio0 = ((RD_DQS_GATE<<10) | (RD_DQS_GATE<<0)), |
| 118 | .datawrsratio0 = (((WR_DQS+0x40)<<10) | ((WR_DQS+0x40)<<0)), |
TENART Antoine | 7a5eb65 | 2013-07-02 12:06:00 +0200 | [diff] [blame] | 119 | }; |
| 120 | |
Tom Rini | fbb2552 | 2017-05-16 14:46:35 -0400 | [diff] [blame] | 121 | static const struct dmm_lisa_map_regs evm_lisa_map_regs = { |
| 122 | .dmm_lisa_map_0 = 0x00000000, |
| 123 | .dmm_lisa_map_1 = 0x00000000, |
| 124 | .dmm_lisa_map_2 = 0x80640300, |
| 125 | .dmm_lisa_map_3 = 0xC0640320, |
TENART Antoine | 7a5eb65 | 2013-07-02 12:06:00 +0200 | [diff] [blame] | 126 | }; |
| 127 | |
TENART Antoine | 7a5eb65 | 2013-07-02 12:06:00 +0200 | [diff] [blame] | 128 | void sdram_init(void) |
| 129 | { |
Tom Rini | fbb2552 | 2017-05-16 14:46:35 -0400 | [diff] [blame] | 130 | /* |
| 131 | * Pass in our DDR3 config information and that we have 2 EMIFs to |
| 132 | * configure. |
| 133 | */ |
| 134 | config_ddr(&ddr3_data, &ddr3_ctrl, &ddr3_emif_regs, |
| 135 | &evm_lisa_map_regs, 2); |
TENART Antoine | 7a5eb65 | 2013-07-02 12:06:00 +0200 | [diff] [blame] | 136 | } |
| 137 | #endif /* CONFIG_SPL_BUILD */ |