Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Frederik Kriewitz | 9939650 | 2009-08-23 12:56:42 +0200 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2004-2008 |
| 4 | * Texas Instruments, <www.ti.com> |
| 5 | * |
| 6 | * Author : |
| 7 | * Sunil Kumar <sunilsaini05@gmail.com> |
| 8 | * Shashi Ranjan <shashiranjanmca05@gmail.com> |
| 9 | * |
| 10 | * (C) Copyright 2009 |
| 11 | * Frederik Kriewitz <frederik@kriewitz.eu> |
| 12 | * |
| 13 | * Derived from Beagle Board and 3430 SDP code by |
| 14 | * Richard Woodruff <r-woodruff2@ti.com> |
| 15 | * Syed Mohammed Khasim <khasim@ti.com> |
| 16 | * |
Frederik Kriewitz | 9939650 | 2009-08-23 12:56:42 +0200 | [diff] [blame] | 17 | */ |
| 18 | #include <common.h> |
Anthoine Bourgeois | cf84a82 | 2015-01-02 00:35:43 +0100 | [diff] [blame] | 19 | #include <dm.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 20 | #include <env.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 21 | #include <init.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 22 | #include <malloc.h> |
Anthoine Bourgeois | cf84a82 | 2015-01-02 00:35:43 +0100 | [diff] [blame] | 23 | #include <ns16550.h> |
Frederik Kriewitz | 9939650 | 2009-08-23 12:56:42 +0200 | [diff] [blame] | 24 | #include <twl4030.h> |
| 25 | #include <asm/io.h> |
Tom Rini | bde8eea | 2011-09-03 21:52:45 -0400 | [diff] [blame] | 26 | #include <asm/arch/mmc_host_def.h> |
Frederik Kriewitz | 9939650 | 2009-08-23 12:56:42 +0200 | [diff] [blame] | 27 | #include <asm/arch/mux.h> |
| 28 | #include <asm/arch/sys_proto.h> |
| 29 | #include <asm/arch/mem.h> |
| 30 | #include <asm/mach-types.h> |
| 31 | #include "devkit8000.h" |
Simon Schwarz | bbb57cb | 2012-03-15 04:01:40 +0000 | [diff] [blame] | 32 | #include <asm/gpio.h> |
Frederik Kriewitz | 9939650 | 2009-08-23 12:56:42 +0200 | [diff] [blame] | 33 | #ifdef CONFIG_DRIVER_DM9000 |
| 34 | #include <net.h> |
| 35 | #include <netdev.h> |
| 36 | #endif |
| 37 | |
| 38 | DECLARE_GLOBAL_DATA_PTR; |
| 39 | |
Thomas Weber | 30e219a | 2011-12-13 05:54:17 +0000 | [diff] [blame] | 40 | static u32 gpmc_net_config[GPMC_MAX_REG] = { |
| 41 | NET_GPMC_CONFIG1, |
| 42 | NET_GPMC_CONFIG2, |
| 43 | NET_GPMC_CONFIG3, |
| 44 | NET_GPMC_CONFIG4, |
| 45 | NET_GPMC_CONFIG5, |
| 46 | NET_GPMC_CONFIG6, |
| 47 | 0 |
| 48 | }; |
| 49 | |
Anthoine Bourgeois | cf84a82 | 2015-01-02 00:35:43 +0100 | [diff] [blame] | 50 | static const struct ns16550_platdata devkit8000_serial = { |
Adam Ford | d1e22fa | 2016-03-07 21:08:49 -0600 | [diff] [blame] | 51 | .base = OMAP34XX_UART3, |
| 52 | .reg_shift = 2, |
Heiko Schocher | 06f108e | 2017-01-18 08:05:49 +0100 | [diff] [blame] | 53 | .clock = V_NS16550_CLK, |
| 54 | .fcr = UART_FCR_DEFVAL, |
Anthoine Bourgeois | cf84a82 | 2015-01-02 00:35:43 +0100 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | U_BOOT_DEVICE(devkit8000_uart) = { |
Thomas Chou | 52ac443 | 2015-11-19 21:48:12 +0800 | [diff] [blame] | 58 | "ns16550_serial", |
Anthoine Bourgeois | cf84a82 | 2015-01-02 00:35:43 +0100 | [diff] [blame] | 59 | &devkit8000_serial |
| 60 | }; |
| 61 | |
Frederik Kriewitz | 9939650 | 2009-08-23 12:56:42 +0200 | [diff] [blame] | 62 | /* |
| 63 | * Routine: board_init |
| 64 | * Description: Early hardware init. |
| 65 | */ |
| 66 | int board_init(void) |
| 67 | { |
| 68 | gpmc_init(); /* in SRAM or SDRAM, finish GPMC */ |
| 69 | /* board id for Linux */ |
| 70 | gd->bd->bi_arch_number = MACH_TYPE_DEVKIT8000; |
| 71 | /* boot param addr */ |
| 72 | gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100); |
| 73 | |
| 74 | return 0; |
| 75 | } |
| 76 | |
Simon Schwarz | 23cced1 | 2012-03-15 04:01:37 +0000 | [diff] [blame] | 77 | /* Configure GPMC registers for DM9000 */ |
| 78 | static void gpmc_dm9000_config(void) |
| 79 | { |
| 80 | enable_gpmc_cs_config(gpmc_net_config, &gpmc_cfg->cs[6], |
| 81 | CONFIG_DM9000_BASE, GPMC_SIZE_16M); |
| 82 | } |
| 83 | |
Frederik Kriewitz | 9939650 | 2009-08-23 12:56:42 +0200 | [diff] [blame] | 84 | /* |
| 85 | * Routine: misc_init_r |
| 86 | * Description: Configure board specific parts |
| 87 | */ |
| 88 | int misc_init_r(void) |
| 89 | { |
| 90 | struct ctrl_id *id_base = (struct ctrl_id *)OMAP34XX_ID_L4_IO_BASE; |
| 91 | #ifdef CONFIG_DRIVER_DM9000 |
| 92 | uchar enetaddr[6]; |
| 93 | u32 die_id_0; |
| 94 | #endif |
| 95 | |
| 96 | twl4030_power_init(); |
| 97 | #ifdef CONFIG_TWL4030_LED |
Grazvydas Ignotas | 17887bf | 2009-12-10 17:10:21 +0200 | [diff] [blame] | 98 | twl4030_led_init(TWL4030_LED_LEDEN_LEDAON | TWL4030_LED_LEDEN_LEDBON); |
Frederik Kriewitz | 9939650 | 2009-08-23 12:56:42 +0200 | [diff] [blame] | 99 | #endif |
| 100 | |
| 101 | #ifdef CONFIG_DRIVER_DM9000 |
| 102 | /* Configure GPMC registers for DM9000 */ |
Thomas Weber | 30e219a | 2011-12-13 05:54:17 +0000 | [diff] [blame] | 103 | enable_gpmc_cs_config(gpmc_net_config, &gpmc_cfg->cs[6], |
| 104 | CONFIG_DM9000_BASE, GPMC_SIZE_16M); |
Frederik Kriewitz | 9939650 | 2009-08-23 12:56:42 +0200 | [diff] [blame] | 105 | |
| 106 | /* Use OMAP DIE_ID as MAC address */ |
Simon Glass | 399a9ce | 2017-08-03 12:22:14 -0600 | [diff] [blame] | 107 | if (!eth_env_get_enetaddr("ethaddr", enetaddr)) { |
Frederik Kriewitz | 9939650 | 2009-08-23 12:56:42 +0200 | [diff] [blame] | 108 | printf("ethaddr not set, using Die ID\n"); |
| 109 | die_id_0 = readl(&id_base->die_id_0); |
| 110 | enetaddr[0] = 0x02; /* locally administered */ |
| 111 | enetaddr[1] = readl(&id_base->die_id_1) & 0xff; |
| 112 | enetaddr[2] = (die_id_0 & 0xff000000) >> 24; |
| 113 | enetaddr[3] = (die_id_0 & 0x00ff0000) >> 16; |
| 114 | enetaddr[4] = (die_id_0 & 0x0000ff00) >> 8; |
| 115 | enetaddr[5] = (die_id_0 & 0x000000ff); |
Simon Glass | 8551d55 | 2017-08-03 12:22:11 -0600 | [diff] [blame] | 116 | eth_env_set_enetaddr("ethaddr", enetaddr); |
Frederik Kriewitz | 9939650 | 2009-08-23 12:56:42 +0200 | [diff] [blame] | 117 | } |
| 118 | #endif |
| 119 | |
Paul Kocialkowski | 6bc318e | 2015-08-27 19:37:13 +0200 | [diff] [blame] | 120 | omap_die_id_display(); |
Frederik Kriewitz | 9939650 | 2009-08-23 12:56:42 +0200 | [diff] [blame] | 121 | |
| 122 | return 0; |
| 123 | } |
| 124 | |
| 125 | /* |
| 126 | * Routine: set_muxconf_regs |
| 127 | * Description: Setting up the configuration Mux registers specific to the |
| 128 | * hardware. Many pins need to be moved from protect to primary |
| 129 | * mode. |
| 130 | */ |
| 131 | void set_muxconf_regs(void) |
| 132 | { |
| 133 | MUX_DEVKIT8000(); |
| 134 | } |
| 135 | |
Masahiro Yamada | 0a78017 | 2017-05-09 20:31:39 +0900 | [diff] [blame] | 136 | #if defined(CONFIG_MMC) |
Tom Rini | bde8eea | 2011-09-03 21:52:45 -0400 | [diff] [blame] | 137 | int board_mmc_init(bd_t *bis) |
| 138 | { |
Nikita Kiryanov | 4be9dbc | 2012-12-03 02:19:47 +0000 | [diff] [blame] | 139 | return omap_mmc_init(0, 0, 0, -1, -1); |
Tom Rini | bde8eea | 2011-09-03 21:52:45 -0400 | [diff] [blame] | 140 | } |
| 141 | #endif |
| 142 | |
Masahiro Yamada | 0a78017 | 2017-05-09 20:31:39 +0900 | [diff] [blame] | 143 | #if defined(CONFIG_MMC) |
Paul Kocialkowski | 6955989 | 2014-11-08 20:55:47 +0100 | [diff] [blame] | 144 | void board_mmc_power_init(void) |
| 145 | { |
| 146 | twl4030_power_mmc_init(0); |
| 147 | } |
| 148 | #endif |
| 149 | |
Simon Schwarz | 7ae359c | 2011-09-14 15:32:17 -0400 | [diff] [blame] | 150 | #if defined(CONFIG_DRIVER_DM9000) & !defined(CONFIG_SPL_BUILD) |
Frederik Kriewitz | 9939650 | 2009-08-23 12:56:42 +0200 | [diff] [blame] | 151 | /* |
| 152 | * Routine: board_eth_init |
| 153 | * Description: Setting up the Ethernet hardware. |
| 154 | */ |
| 155 | int board_eth_init(bd_t *bis) |
| 156 | { |
| 157 | return dm9000_initialize(bis); |
| 158 | } |
| 159 | #endif |
Tom Rini | 05800b9 | 2011-11-18 12:48:06 +0000 | [diff] [blame] | 160 | |
Simon Schwarz | 23cced1 | 2012-03-15 04:01:37 +0000 | [diff] [blame] | 161 | #ifdef CONFIG_SPL_OS_BOOT |
| 162 | /* |
Robert P. J. Day | c5b1e5d | 2016-09-07 14:27:59 -0400 | [diff] [blame] | 163 | * Do board specific preparation before SPL |
Simon Schwarz | 23cced1 | 2012-03-15 04:01:37 +0000 | [diff] [blame] | 164 | * Linux boot |
| 165 | */ |
| 166 | void spl_board_prepare_for_linux(void) |
| 167 | { |
| 168 | gpmc_dm9000_config(); |
| 169 | } |
| 170 | |
Simon Schwarz | bbb57cb | 2012-03-15 04:01:40 +0000 | [diff] [blame] | 171 | /* |
| 172 | * devkit8000 specific implementation of spl_start_uboot() |
| 173 | * |
| 174 | * RETURN |
| 175 | * 0 if the button is not pressed |
| 176 | * 1 if the button is pressed |
| 177 | */ |
| 178 | int spl_start_uboot(void) |
| 179 | { |
| 180 | int val = 0; |
Stefano Babic | f51b4c7 | 2013-02-23 00:53:26 +0000 | [diff] [blame] | 181 | if (!gpio_request(SPL_OS_BOOT_KEY, "U-Boot key")) { |
| 182 | gpio_direction_input(SPL_OS_BOOT_KEY); |
| 183 | val = gpio_get_value(SPL_OS_BOOT_KEY); |
| 184 | gpio_free(SPL_OS_BOOT_KEY); |
Simon Schwarz | bbb57cb | 2012-03-15 04:01:40 +0000 | [diff] [blame] | 185 | } |
| 186 | return !val; |
| 187 | } |
Simon Schwarz | 23cced1 | 2012-03-15 04:01:37 +0000 | [diff] [blame] | 188 | #endif |
| 189 | |
Tom Rini | 05800b9 | 2011-11-18 12:48:06 +0000 | [diff] [blame] | 190 | /* |
| 191 | * Routine: get_board_mem_timings |
| 192 | * Description: If we use SPL then there is no x-loader nor config header |
| 193 | * so we have to setup the DDR timings ourself on the first bank. This |
| 194 | * provides the timing values back to the function that configures |
| 195 | * the memory. We have either one or two banks of 128MB DDR. |
| 196 | */ |
Peter Barada | edb5c2f | 2012-11-13 07:40:28 +0000 | [diff] [blame] | 197 | void get_board_mem_timings(struct board_sdrc_timings *timings) |
Tom Rini | 05800b9 | 2011-11-18 12:48:06 +0000 | [diff] [blame] | 198 | { |
| 199 | /* General SDRC config */ |
Peter Barada | edb5c2f | 2012-11-13 07:40:28 +0000 | [diff] [blame] | 200 | timings->mcfg = MICRON_V_MCFG_165(128 << 20); |
| 201 | timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz; |
Tom Rini | 05800b9 | 2011-11-18 12:48:06 +0000 | [diff] [blame] | 202 | |
| 203 | /* AC timings */ |
Peter Barada | edb5c2f | 2012-11-13 07:40:28 +0000 | [diff] [blame] | 204 | timings->ctrla = MICRON_V_ACTIMA_165; |
| 205 | timings->ctrlb = MICRON_V_ACTIMB_165; |
Tom Rini | 05800b9 | 2011-11-18 12:48:06 +0000 | [diff] [blame] | 206 | |
Peter Barada | edb5c2f | 2012-11-13 07:40:28 +0000 | [diff] [blame] | 207 | timings->mr = MICRON_V_MR_165; |
Tom Rini | 05800b9 | 2011-11-18 12:48:06 +0000 | [diff] [blame] | 208 | } |