Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Dirk Behme | ad9bc8e | 2009-01-28 21:39:58 +0100 | [diff] [blame] | 2 | /* |
Tom Rini | 673283f | 2011-11-18 12:48:09 +0000 | [diff] [blame] | 3 | * (C) Copyright 2004-2011 |
Dirk Behme | ad9bc8e | 2009-01-28 21:39:58 +0100 | [diff] [blame] | 4 | * Texas Instruments, <www.ti.com> |
| 5 | * |
| 6 | * Author : |
| 7 | * Manikandan Pillai <mani.pillai@ti.com> |
| 8 | * |
| 9 | * Derived from Beagle Board and 3430 SDP code by |
| 10 | * Richard Woodruff <r-woodruff2@ti.com> |
| 11 | * Syed Mohammed Khasim <khasim@ti.com> |
Dirk Behme | ad9bc8e | 2009-01-28 21:39:58 +0100 | [diff] [blame] | 12 | */ |
| 13 | #include <common.h> |
Derald D. Woods | 0d43fde | 2017-08-06 00:00:21 -0500 | [diff] [blame] | 14 | #include <dm.h> |
Simon Glass | 9fb625c | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 15 | #include <env.h> |
Simon Glass | 691d719 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 16 | #include <init.h> |
Simon Glass | 90526e9 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 17 | #include <net.h> |
Derald D. Woods | 0d43fde | 2017-08-06 00:00:21 -0500 | [diff] [blame] | 18 | #include <ns16550.h> |
Simon Glass | b03e051 | 2019-11-14 12:57:24 -0700 | [diff] [blame] | 19 | #include <serial.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 20 | #include <asm/global_data.h> |
Dirk Behme | ad9bc8e | 2009-01-28 21:39:58 +0100 | [diff] [blame] | 21 | #include <asm/io.h> |
| 22 | #include <asm/arch/mem.h> |
| 23 | #include <asm/arch/mux.h> |
| 24 | #include <asm/arch/sys_proto.h> |
Vaibhav Hiremath | dcc4f38 | 2011-09-03 21:42:35 -0400 | [diff] [blame] | 25 | #include <asm/arch/mmc_host_def.h> |
Sanjeev Premi | 84c3b63 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 26 | #include <asm/gpio.h> |
Paul Kocialkowski | aac5450 | 2014-11-08 20:55:47 +0100 | [diff] [blame] | 27 | #include <twl4030.h> |
Dirk Behme | ad9bc8e | 2009-01-28 21:39:58 +0100 | [diff] [blame] | 28 | #include <asm/mach-types.h> |
Simon Glass | c05ed00 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 29 | #include <linux/delay.h> |
Masahiro Yamada | 6ae3900 | 2017-11-30 13:45:24 +0900 | [diff] [blame] | 30 | #include <linux/mtd/rawnand.h> |
Dirk Behme | ad9bc8e | 2009-01-28 21:39:58 +0100 | [diff] [blame] | 31 | #include "evm.h" |
| 32 | |
Derald D. Woods | 0d43fde | 2017-08-06 00:00:21 -0500 | [diff] [blame] | 33 | #define OMAP3EVM_GPIO_ETH_RST_GEN1 64 |
| 34 | #define OMAP3EVM_GPIO_ETH_RST_GEN2 7 |
Sriramakrishnan | c068258 | 2011-07-18 09:21:55 -0400 | [diff] [blame] | 35 | |
Derald D. Woods | 5297a95 | 2020-07-18 19:23:04 -0500 | [diff] [blame] | 36 | #define CONFIG_SMC911X_BASE 0x2C000000 |
| 37 | |
John Rigby | 2956532 | 2010-12-20 18:27:51 -0700 | [diff] [blame] | 38 | DECLARE_GLOBAL_DATA_PTR; |
| 39 | |
Dirk Behme | b606ef4 | 2010-12-18 07:40:28 +0100 | [diff] [blame] | 40 | static u32 omap3_evm_version; |
Ajay Kumar Gupta | b5abf64 | 2010-06-10 11:20:49 +0530 | [diff] [blame] | 41 | |
Dirk Behme | b606ef4 | 2010-12-18 07:40:28 +0100 | [diff] [blame] | 42 | u32 get_omap3_evm_rev(void) |
Ajay Kumar Gupta | b5abf64 | 2010-06-10 11:20:49 +0530 | [diff] [blame] | 43 | { |
| 44 | return omap3_evm_version; |
| 45 | } |
| 46 | |
| 47 | static void omap3_evm_get_revision(void) |
| 48 | { |
Derald D. Woods | 5297a95 | 2020-07-18 19:23:04 -0500 | [diff] [blame] | 49 | #if defined(CONFIG_SMC911X) |
Sanjeev Premi | 76ee9a2 | 2010-11-04 16:02:32 -0400 | [diff] [blame] | 50 | /* |
| 51 | * Board revision can be ascertained only by identifying |
| 52 | * the Ethernet chipset. |
| 53 | */ |
Ajay Kumar Gupta | b5abf64 | 2010-06-10 11:20:49 +0530 | [diff] [blame] | 54 | unsigned int smsc_id; |
| 55 | |
| 56 | /* Ethernet PHY ID is stored at ID_REV register */ |
| 57 | smsc_id = readl(CONFIG_SMC911X_BASE + 0x50) & 0xFFFF0000; |
| 58 | printf("Read back SMSC id 0x%x\n", smsc_id); |
| 59 | |
| 60 | switch (smsc_id) { |
| 61 | /* SMSC9115 chipset */ |
| 62 | case 0x01150000: |
| 63 | omap3_evm_version = OMAP3EVM_BOARD_GEN_1; |
| 64 | break; |
| 65 | /* SMSC 9220 chipset */ |
| 66 | case 0x92200000: |
| 67 | default: |
| 68 | omap3_evm_version = OMAP3EVM_BOARD_GEN_2; |
| 69 | } |
Derald D. Woods | 5297a95 | 2020-07-18 19:23:04 -0500 | [diff] [blame] | 70 | #else /* !CONFIG_SMC911X */ |
Sanjeev Premi | 76ee9a2 | 2010-11-04 16:02:32 -0400 | [diff] [blame] | 71 | #if defined(CONFIG_STATIC_BOARD_REV) |
Derald D. Woods | 0d43fde | 2017-08-06 00:00:21 -0500 | [diff] [blame] | 72 | /* Look for static defintion of the board revision */ |
Sanjeev Premi | 76ee9a2 | 2010-11-04 16:02:32 -0400 | [diff] [blame] | 73 | omap3_evm_version = CONFIG_STATIC_BOARD_REV; |
| 74 | #else |
Derald D. Woods | 0d43fde | 2017-08-06 00:00:21 -0500 | [diff] [blame] | 75 | /* Fallback to the default above */ |
Sanjeev Premi | 76ee9a2 | 2010-11-04 16:02:32 -0400 | [diff] [blame] | 76 | omap3_evm_version = OMAP3EVM_BOARD_GEN_2; |
Derald D. Woods | 0d43fde | 2017-08-06 00:00:21 -0500 | [diff] [blame] | 77 | #endif /* CONFIG_STATIC_BOARD_REV */ |
Derald D. Woods | 5297a95 | 2020-07-18 19:23:04 -0500 | [diff] [blame] | 78 | #endif /* CONFIG_SMC911X */ |
Ajay Kumar Gupta | b5abf64 | 2010-06-10 11:20:49 +0530 | [diff] [blame] | 79 | } |
| 80 | |
Derald D. Woods | 0d43fde | 2017-08-06 00:00:21 -0500 | [diff] [blame] | 81 | #if defined(CONFIG_USB_MUSB_GADGET) || defined(CONFIG_USB_MUSB_HOST) |
| 82 | /* MUSB port on OMAP3EVM Rev >= E requires extvbus programming. */ |
Ajay Kumar Gupta | 944a489 | 2010-06-10 11:20:50 +0530 | [diff] [blame] | 83 | u8 omap3_evm_need_extvbus(void) |
| 84 | { |
| 85 | u8 retval = 0; |
| 86 | |
| 87 | if (get_omap3_evm_rev() >= OMAP3EVM_BOARD_GEN_2) |
| 88 | retval = 1; |
| 89 | |
| 90 | return retval; |
| 91 | } |
Derald D. Woods | 0d43fde | 2017-08-06 00:00:21 -0500 | [diff] [blame] | 92 | #endif /* CONFIG_USB_MUSB_{GADGET,HOST} */ |
Ajay Kumar Gupta | 944a489 | 2010-06-10 11:20:50 +0530 | [diff] [blame] | 93 | |
| 94 | /* |
Dirk Behme | ad9bc8e | 2009-01-28 21:39:58 +0100 | [diff] [blame] | 95 | * Routine: board_init |
| 96 | * Description: Early hardware init. |
Tom Rix | 5891151 | 2009-04-01 22:02:20 -0500 | [diff] [blame] | 97 | */ |
Dirk Behme | ad9bc8e | 2009-01-28 21:39:58 +0100 | [diff] [blame] | 98 | int board_init(void) |
| 99 | { |
Dirk Behme | ad9bc8e | 2009-01-28 21:39:58 +0100 | [diff] [blame] | 100 | gpmc_init(); /* in SRAM or SDRAM, finish GPMC */ |
| 101 | /* board id for Linux */ |
| 102 | gd->bd->bi_arch_number = MACH_TYPE_OMAP3EVM; |
| 103 | /* boot param addr */ |
| 104 | gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100); |
| 105 | |
| 106 | return 0; |
| 107 | } |
| 108 | |
Derald D. Woods | c257c96 | 2017-09-02 17:43:05 -0500 | [diff] [blame] | 109 | #if defined(CONFIG_SPL_OS_BOOT) |
| 110 | int spl_start_uboot(void) |
| 111 | { |
| 112 | /* break into full u-boot on 'c' */ |
| 113 | if (serial_tstc() && serial_getc() == 'c') |
| 114 | return 1; |
| 115 | |
| 116 | return 0; |
| 117 | } |
| 118 | #endif /* CONFIG_SPL_OS_BOOT */ |
| 119 | |
Derald D. Woods | 0d43fde | 2017-08-06 00:00:21 -0500 | [diff] [blame] | 120 | #if defined(CONFIG_SPL_BUILD) |
Tom Rini | 673283f | 2011-11-18 12:48:09 +0000 | [diff] [blame] | 121 | /* |
| 122 | * Routine: get_board_mem_timings |
| 123 | * Description: If we use SPL then there is no x-loader nor config header |
| 124 | * so we have to setup the DDR timings ourself on the first bank. This |
| 125 | * provides the timing values back to the function that configures |
| 126 | * the memory. |
| 127 | */ |
Peter Barada | 8c4445d | 2012-11-13 07:40:28 +0000 | [diff] [blame] | 128 | void get_board_mem_timings(struct board_sdrc_timings *timings) |
Tom Rini | 673283f | 2011-11-18 12:48:09 +0000 | [diff] [blame] | 129 | { |
| 130 | int pop_mfr, pop_id; |
| 131 | |
| 132 | /* |
| 133 | * We need to identify what PoP memory is on the board so that |
| 134 | * we know what timings to use. To map the ID values please see |
| 135 | * nand_ids.c |
| 136 | */ |
| 137 | identify_nand_chip(&pop_mfr, &pop_id); |
| 138 | |
| 139 | if (pop_mfr == NAND_MFR_HYNIX && pop_id == 0xbc) { |
| 140 | /* 256MB DDR */ |
Peter Barada | 8c4445d | 2012-11-13 07:40:28 +0000 | [diff] [blame] | 141 | timings->mcfg = HYNIX_V_MCFG_200(256 << 20); |
| 142 | timings->ctrla = HYNIX_V_ACTIMA_200; |
| 143 | timings->ctrlb = HYNIX_V_ACTIMB_200; |
Tom Rini | 673283f | 2011-11-18 12:48:09 +0000 | [diff] [blame] | 144 | } else { |
| 145 | /* 128MB DDR */ |
Peter Barada | 8c4445d | 2012-11-13 07:40:28 +0000 | [diff] [blame] | 146 | timings->mcfg = MICRON_V_MCFG_165(128 << 20); |
| 147 | timings->ctrla = MICRON_V_ACTIMA_165; |
| 148 | timings->ctrlb = MICRON_V_ACTIMB_165; |
Tom Rini | 673283f | 2011-11-18 12:48:09 +0000 | [diff] [blame] | 149 | } |
Peter Barada | 8c4445d | 2012-11-13 07:40:28 +0000 | [diff] [blame] | 150 | timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz; |
| 151 | timings->mr = MICRON_V_MR_165; |
Tom Rini | 673283f | 2011-11-18 12:48:09 +0000 | [diff] [blame] | 152 | } |
Derald D. Woods | 0d43fde | 2017-08-06 00:00:21 -0500 | [diff] [blame] | 153 | #endif /* CONFIG_SPL_BUILD */ |
| 154 | |
Tom Rix | 5891151 | 2009-04-01 22:02:20 -0500 | [diff] [blame] | 155 | /* |
Dirk Behme | ad9bc8e | 2009-01-28 21:39:58 +0100 | [diff] [blame] | 156 | * Routine: misc_init_r |
| 157 | * Description: Init ethernet (done here so udelay works) |
Tom Rix | 5891151 | 2009-04-01 22:02:20 -0500 | [diff] [blame] | 158 | */ |
Dirk Behme | ad9bc8e | 2009-01-28 21:39:58 +0100 | [diff] [blame] | 159 | int misc_init_r(void) |
| 160 | { |
Derald D. Woods | 0d43fde | 2017-08-06 00:00:21 -0500 | [diff] [blame] | 161 | twl4030_power_init(); |
Dirk Behme | ad9bc8e | 2009-01-28 21:39:58 +0100 | [diff] [blame] | 162 | |
Derald D. Woods | 5297a95 | 2020-07-18 19:23:04 -0500 | [diff] [blame] | 163 | #if defined(CONFIG_SMC911X) |
Dirk Behme | ad9bc8e | 2009-01-28 21:39:58 +0100 | [diff] [blame] | 164 | setup_net_chip(); |
| 165 | #endif |
Sanjeev Premi | 76ee9a2 | 2010-11-04 16:02:32 -0400 | [diff] [blame] | 166 | omap3_evm_get_revision(); |
Dirk Behme | ad9bc8e | 2009-01-28 21:39:58 +0100 | [diff] [blame] | 167 | |
Derald D. Woods | 5297a95 | 2020-07-18 19:23:04 -0500 | [diff] [blame] | 168 | #if defined(CONFIG_SMC911X) |
Sanjeev Premi | 6921b31 | 2011-07-18 09:20:15 -0400 | [diff] [blame] | 169 | reset_net_chip(); |
| 170 | #endif |
Paul Kocialkowski | 679f82c | 2015-08-27 19:37:13 +0200 | [diff] [blame] | 171 | omap_die_id_display(); |
Dirk Behme | e6a6a70 | 2009-03-12 19:30:50 +0100 | [diff] [blame] | 172 | |
Derald D. Woods | 5297a95 | 2020-07-18 19:23:04 -0500 | [diff] [blame] | 173 | #if defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET) && \ |
| 174 | !defined(CONFIG_SMC911X) |
Derald D. Woods | 0d43fde | 2017-08-06 00:00:21 -0500 | [diff] [blame] | 175 | omap_die_id_usbethaddr(); |
| 176 | #endif |
Dirk Behme | ad9bc8e | 2009-01-28 21:39:58 +0100 | [diff] [blame] | 177 | return 0; |
| 178 | } |
| 179 | |
Tom Rix | 5891151 | 2009-04-01 22:02:20 -0500 | [diff] [blame] | 180 | /* |
Dirk Behme | ad9bc8e | 2009-01-28 21:39:58 +0100 | [diff] [blame] | 181 | * Routine: set_muxconf_regs |
| 182 | * Description: Setting up the configuration Mux registers specific to the |
| 183 | * hardware. Many pins need to be moved from protect to primary |
| 184 | * mode. |
Tom Rix | 5891151 | 2009-04-01 22:02:20 -0500 | [diff] [blame] | 185 | */ |
Dirk Behme | ad9bc8e | 2009-01-28 21:39:58 +0100 | [diff] [blame] | 186 | void set_muxconf_regs(void) |
| 187 | { |
| 188 | MUX_EVM(); |
| 189 | } |
| 190 | |
Derald D. Woods | 5297a95 | 2020-07-18 19:23:04 -0500 | [diff] [blame] | 191 | #if defined(CONFIG_SMC911X) |
Tom Rix | 5891151 | 2009-04-01 22:02:20 -0500 | [diff] [blame] | 192 | /* |
Dirk Behme | ad9bc8e | 2009-01-28 21:39:58 +0100 | [diff] [blame] | 193 | * Routine: setup_net_chip |
| 194 | * Description: Setting up the configuration GPMC registers specific to the |
| 195 | * Ethernet hardware. |
Tom Rix | 5891151 | 2009-04-01 22:02:20 -0500 | [diff] [blame] | 196 | */ |
Dirk Behme | ad9bc8e | 2009-01-28 21:39:58 +0100 | [diff] [blame] | 197 | static void setup_net_chip(void) |
| 198 | { |
Dirk Behme | 97a099e | 2009-08-08 09:30:21 +0200 | [diff] [blame] | 199 | struct ctrl *ctrl_base = (struct ctrl *)OMAP34XX_CTRL_BASE; |
Dirk Behme | ad9bc8e | 2009-01-28 21:39:58 +0100 | [diff] [blame] | 200 | |
| 201 | /* Configure GPMC registers */ |
Dirk Behme | 8941135 | 2009-08-08 09:30:22 +0200 | [diff] [blame] | 202 | writel(NET_GPMC_CONFIG1, &gpmc_cfg->cs[5].config1); |
| 203 | writel(NET_GPMC_CONFIG2, &gpmc_cfg->cs[5].config2); |
| 204 | writel(NET_GPMC_CONFIG3, &gpmc_cfg->cs[5].config3); |
| 205 | writel(NET_GPMC_CONFIG4, &gpmc_cfg->cs[5].config4); |
| 206 | writel(NET_GPMC_CONFIG5, &gpmc_cfg->cs[5].config5); |
| 207 | writel(NET_GPMC_CONFIG6, &gpmc_cfg->cs[5].config6); |
| 208 | writel(NET_GPMC_CONFIG7, &gpmc_cfg->cs[5].config7); |
Dirk Behme | ad9bc8e | 2009-01-28 21:39:58 +0100 | [diff] [blame] | 209 | |
| 210 | /* Enable off mode for NWE in PADCONF_GPMC_NWE register */ |
| 211 | writew(readw(&ctrl_base ->gpmc_nwe) | 0x0E00, &ctrl_base->gpmc_nwe); |
| 212 | /* Enable off mode for NOE in PADCONF_GPMC_NADV_ALE register */ |
| 213 | writew(readw(&ctrl_base->gpmc_noe) | 0x0E00, &ctrl_base->gpmc_noe); |
| 214 | /* Enable off mode for ALE in PADCONF_GPMC_NADV_ALE register */ |
| 215 | writew(readw(&ctrl_base->gpmc_nadv_ale) | 0x0E00, |
| 216 | &ctrl_base->gpmc_nadv_ale); |
Sanjeev Premi | 6921b31 | 2011-07-18 09:20:15 -0400 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | /** |
| 220 | * Reset the ethernet chip. |
| 221 | */ |
| 222 | static void reset_net_chip(void) |
| 223 | { |
Sriramakrishnan | c068258 | 2011-07-18 09:21:55 -0400 | [diff] [blame] | 224 | int ret; |
| 225 | int rst_gpio; |
Dirk Behme | ad9bc8e | 2009-01-28 21:39:58 +0100 | [diff] [blame] | 226 | |
Sriramakrishnan | c068258 | 2011-07-18 09:21:55 -0400 | [diff] [blame] | 227 | if (get_omap3_evm_rev() == OMAP3EVM_BOARD_GEN_1) { |
| 228 | rst_gpio = OMAP3EVM_GPIO_ETH_RST_GEN1; |
| 229 | } else { |
| 230 | rst_gpio = OMAP3EVM_GPIO_ETH_RST_GEN2; |
| 231 | } |
Dirk Behme | ad9bc8e | 2009-01-28 21:39:58 +0100 | [diff] [blame] | 232 | |
Sanjeev Premi | 84c3b63 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 233 | ret = gpio_request(rst_gpio, ""); |
Sriramakrishnan | c068258 | 2011-07-18 09:21:55 -0400 | [diff] [blame] | 234 | if (ret < 0) { |
| 235 | printf("Unable to get GPIO %d\n", rst_gpio); |
| 236 | return ; |
| 237 | } |
| 238 | |
| 239 | /* Configure as output */ |
Sanjeev Premi | 84c3b63 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 240 | gpio_direction_output(rst_gpio, 0); |
Sriramakrishnan | c068258 | 2011-07-18 09:21:55 -0400 | [diff] [blame] | 241 | |
| 242 | /* Send a pulse on the GPIO pin */ |
Sanjeev Premi | 84c3b63 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 243 | gpio_set_value(rst_gpio, 1); |
Dirk Behme | ad9bc8e | 2009-01-28 21:39:58 +0100 | [diff] [blame] | 244 | udelay(1); |
Sanjeev Premi | 84c3b63 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 245 | gpio_set_value(rst_gpio, 0); |
Dirk Behme | ad9bc8e | 2009-01-28 21:39:58 +0100 | [diff] [blame] | 246 | udelay(1); |
Sanjeev Premi | 84c3b63 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 247 | gpio_set_value(rst_gpio, 1); |
Dirk Behme | ad9bc8e | 2009-01-28 21:39:58 +0100 | [diff] [blame] | 248 | } |
Derald D. Woods | 5297a95 | 2020-07-18 19:23:04 -0500 | [diff] [blame] | 249 | #endif /* CONFIG_SMC911X */ |
Vaibhav Hiremath | dcc4f38 | 2011-09-03 21:42:35 -0400 | [diff] [blame] | 250 | |
Masahiro Yamada | 4aa2ba3 | 2017-05-09 20:31:39 +0900 | [diff] [blame] | 251 | #if defined(CONFIG_MMC) |
Paul Kocialkowski | aac5450 | 2014-11-08 20:55:47 +0100 | [diff] [blame] | 252 | void board_mmc_power_init(void) |
| 253 | { |
| 254 | twl4030_power_mmc_init(0); |
| 255 | } |
Derald D. Woods | 0d43fde | 2017-08-06 00:00:21 -0500 | [diff] [blame] | 256 | #endif /* CONFIG_MMC */ |