Enric Balletbo i Serra | 8a3f6bb | 2010-10-14 16:54:59 -0400 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2010 |
| 3 | * ISEE 2007 SL, <www.iseebcn.com> |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Enric Balletbo i Serra | 8a3f6bb | 2010-10-14 16:54:59 -0400 | [diff] [blame] | 6 | */ |
| 7 | #include <common.h> |
Enric Balletbo i Serra | f3b4bc4 | 2015-01-28 15:01:32 +0100 | [diff] [blame] | 8 | #include <status_led.h> |
Simon Glass | b3f4ca1 | 2014-10-22 21:37:15 -0600 | [diff] [blame] | 9 | #include <dm.h> |
| 10 | #include <ns16550.h> |
Enric Balletbo i Serra | 8a3f6bb | 2010-10-14 16:54:59 -0400 | [diff] [blame] | 11 | #include <twl4030.h> |
Javier Martinez Canillas | 77eea28 | 2012-12-27 01:35:56 +0000 | [diff] [blame] | 12 | #include <netdev.h> |
Ladislav Michl | fe9f628 | 2016-07-12 20:28:34 +0200 | [diff] [blame] | 13 | #include <spl.h> |
Sanjeev Premi | 84c3b63 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 14 | #include <asm/gpio.h> |
Javier Martinez Canillas | 77eea28 | 2012-12-27 01:35:56 +0000 | [diff] [blame] | 15 | #include <asm/io.h> |
Enric Balletbo i Serra | 8a3f6bb | 2010-10-14 16:54:59 -0400 | [diff] [blame] | 16 | #include <asm/arch/mem.h> |
Enric Balletbo i Serra | f49d7b6 | 2010-11-04 15:34:33 -0400 | [diff] [blame] | 17 | #include <asm/arch/mmc_host_def.h> |
Enric Balletbo i Serra | 8a3f6bb | 2010-10-14 16:54:59 -0400 | [diff] [blame] | 18 | #include <asm/arch/mux.h> |
| 19 | #include <asm/arch/sys_proto.h> |
| 20 | #include <asm/mach-types.h> |
Ladislav Michl | a5debaa | 2016-07-12 20:28:33 +0200 | [diff] [blame] | 21 | #include <linux/mtd/mtd.h> |
Ladislav Michl | 97ee706 | 2016-07-12 20:28:31 +0200 | [diff] [blame] | 22 | #include <linux/mtd/nand.h> |
| 23 | #include <linux/mtd/nand.h> |
| 24 | #include <linux/mtd/onenand.h> |
| 25 | #include <jffs2/load_kernel.h> |
Ladislav Michl | 568b471 | 2017-01-09 11:21:06 +0100 | [diff] [blame] | 26 | #include <mtd_node.h> |
| 27 | #include <fdt_support.h> |
Javier Martinez Canillas | 77eea28 | 2012-12-27 01:35:56 +0000 | [diff] [blame] | 28 | #include "igep00x0.h" |
Enric Balletbo i Serra | 8a3f6bb | 2010-10-14 16:54:59 -0400 | [diff] [blame] | 29 | |
John Rigby | 2956532 | 2010-12-20 18:27:51 -0700 | [diff] [blame] | 30 | DECLARE_GLOBAL_DATA_PTR; |
| 31 | |
Simon Glass | b3f4ca1 | 2014-10-22 21:37:15 -0600 | [diff] [blame] | 32 | static const struct ns16550_platdata igep_serial = { |
Adam Ford | 2f6ed3b | 2016-03-07 21:08:49 -0600 | [diff] [blame] | 33 | .base = OMAP34XX_UART3, |
| 34 | .reg_shift = 2, |
Heiko Schocher | 17fa032 | 2017-01-18 08:05:49 +0100 | [diff] [blame] | 35 | .clock = V_NS16550_CLK, |
| 36 | .fcr = UART_FCR_DEFVAL, |
Simon Glass | b3f4ca1 | 2014-10-22 21:37:15 -0600 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | U_BOOT_DEVICE(igep_uart) = { |
Thomas Chou | c7b9686 | 2015-11-19 21:48:12 +0800 | [diff] [blame] | 40 | "ns16550_serial", |
Simon Glass | b3f4ca1 | 2014-10-22 21:37:15 -0600 | [diff] [blame] | 41 | &igep_serial |
| 42 | }; |
| 43 | |
Enric Balletbo i Serra | 8a3f6bb | 2010-10-14 16:54:59 -0400 | [diff] [blame] | 44 | /* |
| 45 | * Routine: board_init |
| 46 | * Description: Early hardware init. |
| 47 | */ |
| 48 | int board_init(void) |
| 49 | { |
Ladislav Michl | 97ee706 | 2016-07-12 20:28:31 +0200 | [diff] [blame] | 50 | int loops = 100; |
| 51 | |
| 52 | /* find out flash memory type, assume NAND first */ |
| 53 | gpmc_cs0_flash = MTD_DEV_TYPE_NAND; |
| 54 | gpmc_init(); |
| 55 | |
| 56 | /* Issue a RESET and then READID */ |
| 57 | writeb(NAND_CMD_RESET, &gpmc_cfg->cs[0].nand_cmd); |
| 58 | writeb(NAND_CMD_STATUS, &gpmc_cfg->cs[0].nand_cmd); |
| 59 | while ((readl(&gpmc_cfg->cs[0].nand_dat) & NAND_STATUS_READY) |
| 60 | != NAND_STATUS_READY) { |
| 61 | udelay(1); |
| 62 | if (--loops == 0) { |
| 63 | gpmc_cs0_flash = MTD_DEV_TYPE_ONENAND; |
| 64 | gpmc_init(); /* reinitialize for OneNAND */ |
| 65 | break; |
| 66 | } |
| 67 | } |
| 68 | |
Enric Balletbo i Serra | 8a3f6bb | 2010-10-14 16:54:59 -0400 | [diff] [blame] | 69 | /* boot param addr */ |
| 70 | gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100); |
| 71 | |
Uri Mashiach | 2d8d190 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 72 | #if defined(CONFIG_LED_STATUS) && defined(CONFIG_LED_STATUS_BOOT_ENABLE) |
| 73 | status_led_set(CONFIG_LED_STATUS_BOOT, CONFIG_LED_STATUS_ON); |
Enric Balletbo i Serra | f3b4bc4 | 2015-01-28 15:01:32 +0100 | [diff] [blame] | 74 | #endif |
| 75 | |
Enric Balletbo i Serra | 8a3f6bb | 2010-10-14 16:54:59 -0400 | [diff] [blame] | 76 | return 0; |
| 77 | } |
| 78 | |
Javier Martinez Canillas | d271a61 | 2012-07-28 01:19:34 +0000 | [diff] [blame] | 79 | #ifdef CONFIG_SPL_BUILD |
| 80 | /* |
Javier Martinez Canillas | d271a61 | 2012-07-28 01:19:34 +0000 | [diff] [blame] | 81 | * Routine: get_board_mem_timings |
| 82 | * Description: If we use SPL then there is no x-loader nor config header |
| 83 | * so we have to setup the DDR timings ourself on both banks. |
| 84 | */ |
Peter Barada | 8c4445d | 2012-11-13 07:40:28 +0000 | [diff] [blame] | 85 | void get_board_mem_timings(struct board_sdrc_timings *timings) |
Javier Martinez Canillas | d271a61 | 2012-07-28 01:19:34 +0000 | [diff] [blame] | 86 | { |
Ladislav Michl | 97ee706 | 2016-07-12 20:28:31 +0200 | [diff] [blame] | 87 | int mfr, id, err = identify_nand_chip(&mfr, &id); |
Javier Martinez Canillas | d271a61 | 2012-07-28 01:19:34 +0000 | [diff] [blame] | 88 | |
Ladislav Michl | 97ee706 | 2016-07-12 20:28:31 +0200 | [diff] [blame] | 89 | timings->mr = MICRON_V_MR_165; |
Ladislav Michl | 4fa72bd | 2016-11-04 12:59:46 +0100 | [diff] [blame] | 90 | if (!err) { |
| 91 | switch (mfr) { |
| 92 | case NAND_MFR_HYNIX: |
| 93 | timings->mcfg = HYNIX_V_MCFG_200(256 << 20); |
| 94 | timings->ctrla = HYNIX_V_ACTIMA_200; |
| 95 | timings->ctrlb = HYNIX_V_ACTIMB_200; |
| 96 | break; |
| 97 | case NAND_MFR_MICRON: |
| 98 | timings->mcfg = MICRON_V_MCFG_200(256 << 20); |
| 99 | timings->ctrla = MICRON_V_ACTIMA_200; |
| 100 | timings->ctrlb = MICRON_V_ACTIMB_200; |
| 101 | break; |
| 102 | default: |
| 103 | /* Should not happen... */ |
| 104 | break; |
| 105 | } |
Peter Barada | 8c4445d | 2012-11-13 07:40:28 +0000 | [diff] [blame] | 106 | timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz; |
Ladislav Michl | 97ee706 | 2016-07-12 20:28:31 +0200 | [diff] [blame] | 107 | gpmc_cs0_flash = MTD_DEV_TYPE_NAND; |
| 108 | } else { |
| 109 | if (get_cpu_family() == CPU_OMAP34XX) { |
| 110 | timings->mcfg = NUMONYX_V_MCFG_165(256 << 20); |
| 111 | timings->ctrla = NUMONYX_V_ACTIMA_165; |
| 112 | timings->ctrlb = NUMONYX_V_ACTIMB_165; |
| 113 | timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz; |
| 114 | } else { |
| 115 | timings->mcfg = NUMONYX_V_MCFG_200(256 << 20); |
| 116 | timings->ctrla = NUMONYX_V_ACTIMA_200; |
| 117 | timings->ctrlb = NUMONYX_V_ACTIMB_200; |
| 118 | timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz; |
| 119 | } |
| 120 | gpmc_cs0_flash = MTD_DEV_TYPE_ONENAND; |
Javier Martinez Canillas | d271a61 | 2012-07-28 01:19:34 +0000 | [diff] [blame] | 121 | } |
Javier Martinez Canillas | d271a61 | 2012-07-28 01:19:34 +0000 | [diff] [blame] | 122 | } |
Ladislav Michl | fe9f628 | 2016-07-12 20:28:34 +0200 | [diff] [blame] | 123 | |
| 124 | #ifdef CONFIG_SPL_OS_BOOT |
| 125 | int spl_start_uboot(void) |
| 126 | { |
| 127 | /* break into full u-boot on 'c' */ |
| 128 | if (serial_tstc() && serial_getc() == 'c') |
| 129 | return 1; |
| 130 | |
| 131 | return 0; |
| 132 | } |
| 133 | #endif |
Javier Martinez Canillas | d271a61 | 2012-07-28 01:19:34 +0000 | [diff] [blame] | 134 | #endif |
| 135 | |
Ladislav Michl | 97ee706 | 2016-07-12 20:28:31 +0200 | [diff] [blame] | 136 | int onenand_board_init(struct mtd_info *mtd) |
| 137 | { |
| 138 | if (gpmc_cs0_flash == MTD_DEV_TYPE_ONENAND) { |
| 139 | struct onenand_chip *this = mtd->priv; |
| 140 | this->base = (void *)CONFIG_SYS_ONENAND_BASE; |
| 141 | return 0; |
| 142 | } |
| 143 | return 1; |
| 144 | } |
| 145 | |
Javier Martinez Canillas | 77eea28 | 2012-12-27 01:35:56 +0000 | [diff] [blame] | 146 | #if defined(CONFIG_CMD_NET) |
Ladislav Michl | 6ed75ba | 2016-01-04 23:07:59 +0100 | [diff] [blame] | 147 | static void reset_net_chip(int gpio) |
| 148 | { |
| 149 | if (!gpio_request(gpio, "eth nrst")) { |
| 150 | gpio_direction_output(gpio, 1); |
| 151 | udelay(1); |
| 152 | gpio_set_value(gpio, 0); |
| 153 | udelay(40); |
| 154 | gpio_set_value(gpio, 1); |
| 155 | mdelay(10); |
| 156 | } |
| 157 | } |
| 158 | |
Enric Balletbo i Serra | 8a3f6bb | 2010-10-14 16:54:59 -0400 | [diff] [blame] | 159 | /* |
| 160 | * Routine: setup_net_chip |
| 161 | * Description: Setting up the configuration GPMC registers specific to the |
| 162 | * Ethernet hardware. |
| 163 | */ |
Enric Balletbo i Serra | 8a3f6bb | 2010-10-14 16:54:59 -0400 | [diff] [blame] | 164 | static void setup_net_chip(void) |
| 165 | { |
| 166 | struct ctrl *ctrl_base = (struct ctrl *)OMAP34XX_CTRL_BASE; |
Ladislav Michl | b0c4763 | 2016-07-12 20:28:28 +0200 | [diff] [blame] | 167 | static const u32 gpmc_lan_config[] = { |
| 168 | NET_LAN9221_GPMC_CONFIG1, |
| 169 | NET_LAN9221_GPMC_CONFIG2, |
| 170 | NET_LAN9221_GPMC_CONFIG3, |
| 171 | NET_LAN9221_GPMC_CONFIG4, |
| 172 | NET_LAN9221_GPMC_CONFIG5, |
| 173 | NET_LAN9221_GPMC_CONFIG6, |
| 174 | }; |
Enric Balletbo i Serra | 8a3f6bb | 2010-10-14 16:54:59 -0400 | [diff] [blame] | 175 | |
Ladislav Michl | 6ed75ba | 2016-01-04 23:07:59 +0100 | [diff] [blame] | 176 | enable_gpmc_cs_config(gpmc_lan_config, &gpmc_cfg->cs[5], |
| 177 | CONFIG_SMC911X_BASE, GPMC_SIZE_16M); |
Enric Balletbo i Serra | 8a3f6bb | 2010-10-14 16:54:59 -0400 | [diff] [blame] | 178 | |
| 179 | /* Enable off mode for NWE in PADCONF_GPMC_NWE register */ |
| 180 | writew(readw(&ctrl_base->gpmc_nwe) | 0x0E00, &ctrl_base->gpmc_nwe); |
| 181 | /* Enable off mode for NOE in PADCONF_GPMC_NADV_ALE register */ |
| 182 | writew(readw(&ctrl_base->gpmc_noe) | 0x0E00, &ctrl_base->gpmc_noe); |
| 183 | /* Enable off mode for ALE in PADCONF_GPMC_NADV_ALE register */ |
| 184 | writew(readw(&ctrl_base->gpmc_nadv_ale) | 0x0E00, |
| 185 | &ctrl_base->gpmc_nadv_ale); |
| 186 | |
Ladislav Michl | 6ed75ba | 2016-01-04 23:07:59 +0100 | [diff] [blame] | 187 | reset_net_chip(64); |
Enric Balletbo i Serra | 8a3f6bb | 2010-10-14 16:54:59 -0400 | [diff] [blame] | 188 | } |
Ladislav Michl | b0c4763 | 2016-07-12 20:28:28 +0200 | [diff] [blame] | 189 | |
| 190 | int board_eth_init(bd_t *bis) |
| 191 | { |
| 192 | #ifdef CONFIG_SMC911X |
| 193 | return smc911x_initialize(0, CONFIG_SMC911X_BASE); |
| 194 | #else |
| 195 | return 0; |
| 196 | #endif |
| 197 | } |
Javier Martinez Canillas | 77eea28 | 2012-12-27 01:35:56 +0000 | [diff] [blame] | 198 | #else |
| 199 | static inline void setup_net_chip(void) {} |
Enric Balletbo i Serra | 8a3f6bb | 2010-10-14 16:54:59 -0400 | [diff] [blame] | 200 | #endif |
| 201 | |
Jean-Jacques Hiblot | d5abcf9 | 2017-02-01 11:39:14 +0100 | [diff] [blame] | 202 | #if defined(CONFIG_GENERIC_MMC) |
Enric Balletbo i Serra | f49d7b6 | 2010-11-04 15:34:33 -0400 | [diff] [blame] | 203 | int board_mmc_init(bd_t *bis) |
| 204 | { |
Nikita Kiryanov | e3913f5 | 2012-12-03 02:19:47 +0000 | [diff] [blame] | 205 | return omap_mmc_init(0, 0, 0, -1, -1); |
Enric Balletbo i Serra | f49d7b6 | 2010-11-04 15:34:33 -0400 | [diff] [blame] | 206 | } |
| 207 | #endif |
| 208 | |
Paul Kocialkowski | aac5450 | 2014-11-08 20:55:47 +0100 | [diff] [blame] | 209 | #if defined(CONFIG_GENERIC_MMC) |
| 210 | void board_mmc_power_init(void) |
| 211 | { |
| 212 | twl4030_power_mmc_init(0); |
| 213 | } |
| 214 | #endif |
| 215 | |
Ladislav Michl | 568b471 | 2017-01-09 11:21:06 +0100 | [diff] [blame] | 216 | #ifdef CONFIG_OF_BOARD_SETUP |
Ladislav Michl | e4290aa | 2017-02-19 00:24:49 +0100 | [diff] [blame] | 217 | static int ft_enable_by_compatible(void *blob, char *compat, int enable) |
| 218 | { |
| 219 | int off = fdt_node_offset_by_compatible(blob, -1, compat); |
| 220 | if (off < 0) |
| 221 | return off; |
| 222 | |
| 223 | if (enable) |
| 224 | fdt_status_okay(blob, off); |
| 225 | else |
| 226 | fdt_status_disabled(blob, off); |
| 227 | |
| 228 | return 0; |
| 229 | } |
| 230 | |
Ladislav Michl | 568b471 | 2017-01-09 11:21:06 +0100 | [diff] [blame] | 231 | int ft_board_setup(void *blob, bd_t *bd) |
| 232 | { |
| 233 | #ifdef CONFIG_FDT_FIXUP_PARTITIONS |
| 234 | static struct node_info nodes[] = { |
| 235 | { "ti,omap2-nand", MTD_DEV_TYPE_NAND, }, |
| 236 | { "ti,omap2-onenand", MTD_DEV_TYPE_ONENAND, }, |
| 237 | }; |
| 238 | |
| 239 | fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes)); |
| 240 | #endif |
Ladislav Michl | e4290aa | 2017-02-19 00:24:49 +0100 | [diff] [blame] | 241 | ft_enable_by_compatible(blob, "ti,omap2-nand", |
| 242 | gpmc_cs0_flash == MTD_DEV_TYPE_NAND); |
| 243 | ft_enable_by_compatible(blob, "ti,omap2-onenand", |
| 244 | gpmc_cs0_flash == MTD_DEV_TYPE_ONENAND); |
| 245 | |
Ladislav Michl | 568b471 | 2017-01-09 11:21:06 +0100 | [diff] [blame] | 246 | return 0; |
| 247 | } |
| 248 | #endif |
| 249 | |
Javier Martinez Canillas | a2fa28b | 2013-08-07 17:53:19 +0200 | [diff] [blame] | 250 | void set_fdt(void) |
| 251 | { |
| 252 | switch (gd->bd->bi_arch_number) { |
| 253 | case MACH_TYPE_IGEP0020: |
Enric Balletbò i Serra | 4037224 | 2015-09-07 08:28:09 +0200 | [diff] [blame] | 254 | setenv("fdtfile", "omap3-igep0020.dtb"); |
Javier Martinez Canillas | a2fa28b | 2013-08-07 17:53:19 +0200 | [diff] [blame] | 255 | break; |
| 256 | case MACH_TYPE_IGEP0030: |
Enric Balletbò i Serra | 4037224 | 2015-09-07 08:28:09 +0200 | [diff] [blame] | 257 | setenv("fdtfile", "omap3-igep0030.dtb"); |
Javier Martinez Canillas | a2fa28b | 2013-08-07 17:53:19 +0200 | [diff] [blame] | 258 | break; |
| 259 | } |
| 260 | } |
| 261 | |
Enric Balletbo i Serra | 8a3f6bb | 2010-10-14 16:54:59 -0400 | [diff] [blame] | 262 | /* |
| 263 | * Routine: misc_init_r |
| 264 | * Description: Configure board specific parts |
| 265 | */ |
| 266 | int misc_init_r(void) |
| 267 | { |
| 268 | twl4030_power_init(); |
| 269 | |
Enric Balletbo i Serra | 8a3f6bb | 2010-10-14 16:54:59 -0400 | [diff] [blame] | 270 | setup_net_chip(); |
Enric Balletbo i Serra | 8a3f6bb | 2010-10-14 16:54:59 -0400 | [diff] [blame] | 271 | |
Paul Kocialkowski | 679f82c | 2015-08-27 19:37:13 +0200 | [diff] [blame] | 272 | omap_die_id_display(); |
Enric Balletbo i Serra | 8a3f6bb | 2010-10-14 16:54:59 -0400 | [diff] [blame] | 273 | |
Javier Martinez Canillas | a2fa28b | 2013-08-07 17:53:19 +0200 | [diff] [blame] | 274 | set_fdt(); |
| 275 | |
Enric Balletbo i Serra | 8a3f6bb | 2010-10-14 16:54:59 -0400 | [diff] [blame] | 276 | return 0; |
| 277 | } |
| 278 | |
Ladislav Michl | a5debaa | 2016-07-12 20:28:33 +0200 | [diff] [blame] | 279 | void board_mtdparts_default(const char **mtdids, const char **mtdparts) |
| 280 | { |
| 281 | struct mtd_info *mtd = get_mtd_device(NULL, 0); |
| 282 | if (mtd) { |
| 283 | static char ids[24]; |
| 284 | static char parts[48]; |
| 285 | const char *linux_name = "omap2-nand"; |
| 286 | if (strncmp(mtd->name, "onenand0", 8) == 0) |
| 287 | linux_name = "omap2-onenand"; |
| 288 | snprintf(ids, sizeof(ids), "%s=%s", mtd->name, linux_name); |
| 289 | snprintf(parts, sizeof(parts), "mtdparts=%s:%dk(SPL),-(UBI)", |
| 290 | linux_name, 4 * mtd->erasesize >> 10); |
| 291 | *mtdids = ids; |
| 292 | *mtdparts = parts; |
| 293 | } |
| 294 | } |
| 295 | |
Enric Balletbo i Serra | 8a3f6bb | 2010-10-14 16:54:59 -0400 | [diff] [blame] | 296 | /* |
| 297 | * Routine: set_muxconf_regs |
| 298 | * Description: Setting up the configuration Mux registers specific to the |
| 299 | * hardware. Many pins need to be moved from protect to primary |
| 300 | * mode. |
| 301 | */ |
| 302 | void set_muxconf_regs(void) |
| 303 | { |
| 304 | MUX_DEFAULT(); |
Javier Martinez Canillas | 77eea28 | 2012-12-27 01:35:56 +0000 | [diff] [blame] | 305 | |
| 306 | #if (CONFIG_MACH_TYPE == MACH_TYPE_IGEP0020) |
| 307 | MUX_IGEP0020(); |
| 308 | #endif |
| 309 | |
| 310 | #if (CONFIG_MACH_TYPE == MACH_TYPE_IGEP0030) |
| 311 | MUX_IGEP0030(); |
| 312 | #endif |
Enric Balletbo i Serra | 8a3f6bb | 2010-10-14 16:54:59 -0400 | [diff] [blame] | 313 | } |