Dirk Behme | 9d0fc81 | 2009-01-28 21:39:57 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Maintainer : Steve Sakoman <steve@sakoman.com> |
| 3 | * |
| 4 | * Derived from Beagle Board, 3430 SDP, and OMAP3EVM code by |
| 5 | * Richard Woodruff <r-woodruff2@ti.com> |
| 6 | * Syed Mohammed Khasim <khasim@ti.com> |
| 7 | * Sunil Kumar <sunilsaini05@gmail.com> |
| 8 | * Shashi Ranjan <shashiranjanmca05@gmail.com> |
| 9 | * |
| 10 | * (C) Copyright 2004-2008 |
| 11 | * Texas Instruments, <www.ti.com> |
| 12 | * |
| 13 | * See file CREDITS for list of people who contributed to this |
| 14 | * project. |
| 15 | * |
| 16 | * This program is free software; you can redistribute it and/or |
| 17 | * modify it under the terms of the GNU General Public License as |
| 18 | * published by the Free Software Foundation; either version 2 of |
| 19 | * the License, or (at your option) any later version. |
| 20 | * |
| 21 | * This program is distributed in the hope that it will be useful, |
| 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 | * GNU General Public License for more details. |
| 25 | * |
| 26 | * You should have received a copy of the GNU General Public License |
| 27 | * along with this program; if not, write to the Free Software |
| 28 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 29 | * MA 02111-1307 USA |
| 30 | */ |
| 31 | #include <common.h> |
Olof Johansson | df38262 | 2009-09-29 10:22:45 -0400 | [diff] [blame] | 32 | #include <netdev.h> |
Tom Rix | 2c15513 | 2009-06-28 12:52:30 -0500 | [diff] [blame] | 33 | #include <twl4030.h> |
Dirk Behme | 9d0fc81 | 2009-01-28 21:39:57 +0100 | [diff] [blame] | 34 | #include <asm/io.h> |
Steve Sakoman | cd7c572 | 2010-09-19 21:21:07 -0700 | [diff] [blame] | 35 | #include <asm/arch/mmc_host_def.h> |
Dirk Behme | 9d0fc81 | 2009-01-28 21:39:57 +0100 | [diff] [blame] | 36 | #include <asm/arch/mux.h> |
Olof Johansson | df38262 | 2009-09-29 10:22:45 -0400 | [diff] [blame] | 37 | #include <asm/arch/mem.h> |
Dirk Behme | 9d0fc81 | 2009-01-28 21:39:57 +0100 | [diff] [blame] | 38 | #include <asm/arch/sys_proto.h> |
Philip Balister | 5213d24 | 2011-09-14 13:32:22 -0400 | [diff] [blame] | 39 | #include <asm/arch/omap_gpmc.h> |
Sanjeev Premi | 84c3b63 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 40 | #include <asm/gpio.h> |
Dirk Behme | 9d0fc81 | 2009-01-28 21:39:57 +0100 | [diff] [blame] | 41 | #include <asm/mach-types.h> |
| 42 | #include "overo.h" |
| 43 | |
John Rigby | 2956532 | 2010-12-20 18:27:51 -0700 | [diff] [blame] | 44 | DECLARE_GLOBAL_DATA_PTR; |
| 45 | |
Steve Sakoman | d64b5b8 | 2010-09-20 08:05:14 -0700 | [diff] [blame] | 46 | #define TWL4030_I2C_BUS 0 |
| 47 | #define EXPANSION_EEPROM_I2C_BUS 2 |
| 48 | #define EXPANSION_EEPROM_I2C_ADDRESS 0x51 |
| 49 | |
| 50 | #define GUMSTIX_SUMMIT 0x01000200 |
| 51 | #define GUMSTIX_TOBI 0x02000200 |
| 52 | #define GUMSTIX_TOBI_DUO 0x03000200 |
| 53 | #define GUMSTIX_PALO35 0x04000200 |
| 54 | #define GUMSTIX_PALO43 0x05000200 |
| 55 | #define GUMSTIX_CHESTNUT43 0x06000200 |
| 56 | #define GUMSTIX_PINTO 0x07000200 |
| 57 | #define GUMSTIX_GALLOP43 0x08000200 |
| 58 | |
| 59 | #define ETTUS_USRP_E 0x01000300 |
| 60 | |
| 61 | #define GUMSTIX_NO_EEPROM 0xffffffff |
| 62 | |
| 63 | static struct { |
| 64 | unsigned int device_vendor; |
| 65 | unsigned char revision; |
| 66 | unsigned char content; |
| 67 | char fab_revision[8]; |
| 68 | char env_var[16]; |
| 69 | char env_setting[64]; |
| 70 | } expansion_config; |
| 71 | |
Olof Johansson | df38262 | 2009-09-29 10:22:45 -0400 | [diff] [blame] | 72 | #if defined(CONFIG_CMD_NET) |
| 73 | static void setup_net_chip(void); |
| 74 | #endif |
| 75 | |
Steve Sakoman | ba9a11e | 2010-08-12 21:07:02 -0700 | [diff] [blame] | 76 | /* GPMC definitions for LAN9221 chips on Tobi expansion boards */ |
| 77 | static const u32 gpmc_lan_config[] = { |
| 78 | NET_LAN9221_GPMC_CONFIG1, |
| 79 | NET_LAN9221_GPMC_CONFIG2, |
| 80 | NET_LAN9221_GPMC_CONFIG3, |
| 81 | NET_LAN9221_GPMC_CONFIG4, |
| 82 | NET_LAN9221_GPMC_CONFIG5, |
| 83 | NET_LAN9221_GPMC_CONFIG6, |
| 84 | /*CONFIG7- computed as params */ |
| 85 | }; |
| 86 | |
Tom Rix | 5891151 | 2009-04-01 22:02:20 -0500 | [diff] [blame] | 87 | /* |
Dirk Behme | 9d0fc81 | 2009-01-28 21:39:57 +0100 | [diff] [blame] | 88 | * Routine: board_init |
| 89 | * Description: Early hardware init. |
Tom Rix | 5891151 | 2009-04-01 22:02:20 -0500 | [diff] [blame] | 90 | */ |
Dirk Behme | 9d0fc81 | 2009-01-28 21:39:57 +0100 | [diff] [blame] | 91 | int board_init(void) |
| 92 | { |
Dirk Behme | 9d0fc81 | 2009-01-28 21:39:57 +0100 | [diff] [blame] | 93 | gpmc_init(); /* in SRAM or SDRAM, finish GPMC */ |
| 94 | /* board id for Linux */ |
| 95 | gd->bd->bi_arch_number = MACH_TYPE_OVERO; |
| 96 | /* boot param addr */ |
| 97 | gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100); |
| 98 | |
| 99 | return 0; |
| 100 | } |
| 101 | |
Tom Rix | 5891151 | 2009-04-01 22:02:20 -0500 | [diff] [blame] | 102 | /* |
Steve Sakoman | c2d5b34 | 2010-08-12 15:13:02 -0700 | [diff] [blame] | 103 | * Routine: get_board_revision |
| 104 | * Description: Returns the board revision |
| 105 | */ |
| 106 | int get_board_revision(void) |
| 107 | { |
| 108 | int revision; |
| 109 | |
Sanjeev Premi | 84c3b63 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 110 | if (!gpio_request(112, "") && |
| 111 | !gpio_request(113, "") && |
| 112 | !gpio_request(115, "")) { |
Steve Sakoman | c2d5b34 | 2010-08-12 15:13:02 -0700 | [diff] [blame] | 113 | |
Sanjeev Premi | 84c3b63 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 114 | gpio_direction_input(112); |
| 115 | gpio_direction_input(113); |
| 116 | gpio_direction_input(115); |
Steve Sakoman | c2d5b34 | 2010-08-12 15:13:02 -0700 | [diff] [blame] | 117 | |
Sanjeev Premi | 84c3b63 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 118 | revision = gpio_get_value(115) << 2 | |
| 119 | gpio_get_value(113) << 1 | |
| 120 | gpio_get_value(112); |
Steve Sakoman | c2d5b34 | 2010-08-12 15:13:02 -0700 | [diff] [blame] | 121 | |
Sanjeev Premi | 84c3b63 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 122 | gpio_free(112); |
| 123 | gpio_free(113); |
| 124 | gpio_free(115); |
Steve Sakoman | c2d5b34 | 2010-08-12 15:13:02 -0700 | [diff] [blame] | 125 | } else { |
| 126 | printf("Error: unable to acquire board revision GPIOs\n"); |
| 127 | revision = -1; |
| 128 | } |
| 129 | |
| 130 | return revision; |
| 131 | } |
| 132 | |
| 133 | /* |
Steve Sakoman | a06e162 | 2010-08-24 10:37:29 -0700 | [diff] [blame] | 134 | * Routine: get_sdio2_config |
| 135 | * Description: Return information about the wifi module connection |
| 136 | * Returns 0 if the module connects though a level translator |
| 137 | * Returns 1 if the module connects directly |
| 138 | */ |
| 139 | int get_sdio2_config(void) |
| 140 | { |
| 141 | int sdio_direct; |
| 142 | |
Sanjeev Premi | 84c3b63 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 143 | if (!gpio_request(130, "") && !gpio_request(139, "")) { |
Steve Sakoman | a06e162 | 2010-08-24 10:37:29 -0700 | [diff] [blame] | 144 | |
Sanjeev Premi | 84c3b63 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 145 | gpio_direction_output(130, 0); |
| 146 | gpio_direction_input(139); |
Steve Sakoman | a06e162 | 2010-08-24 10:37:29 -0700 | [diff] [blame] | 147 | |
| 148 | sdio_direct = 1; |
Sanjeev Premi | 84c3b63 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 149 | gpio_set_value(130, 0); |
| 150 | if (gpio_get_value(139) == 0) { |
| 151 | gpio_set_value(130, 1); |
| 152 | if (gpio_get_value(139) == 1) |
Steve Sakoman | a06e162 | 2010-08-24 10:37:29 -0700 | [diff] [blame] | 153 | sdio_direct = 0; |
| 154 | } |
| 155 | |
Sanjeev Premi | 84c3b63 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 156 | gpio_free(130); |
| 157 | gpio_free(139); |
Steve Sakoman | a06e162 | 2010-08-24 10:37:29 -0700 | [diff] [blame] | 158 | } else { |
| 159 | printf("Error: unable to acquire sdio2 clk GPIOs\n"); |
| 160 | sdio_direct = -1; |
| 161 | } |
| 162 | |
| 163 | return sdio_direct; |
| 164 | } |
| 165 | |
| 166 | /* |
Steve Sakoman | d64b5b8 | 2010-09-20 08:05:14 -0700 | [diff] [blame] | 167 | * Routine: get_expansion_id |
| 168 | * Description: This function checks for expansion board by checking I2C |
| 169 | * bus 2 for the availability of an AT24C01B serial EEPROM. |
| 170 | * returns the device_vendor field from the EEPROM |
| 171 | */ |
| 172 | unsigned int get_expansion_id(void) |
| 173 | { |
| 174 | i2c_set_bus_num(EXPANSION_EEPROM_I2C_BUS); |
| 175 | |
| 176 | /* return GUMSTIX_NO_EEPROM if eeprom doesn't respond */ |
| 177 | if (i2c_probe(EXPANSION_EEPROM_I2C_ADDRESS) == 1) { |
| 178 | i2c_set_bus_num(TWL4030_I2C_BUS); |
| 179 | return GUMSTIX_NO_EEPROM; |
| 180 | } |
| 181 | |
| 182 | /* read configuration data */ |
| 183 | i2c_read(EXPANSION_EEPROM_I2C_ADDRESS, 0, 1, (u8 *)&expansion_config, |
| 184 | sizeof(expansion_config)); |
| 185 | |
| 186 | i2c_set_bus_num(TWL4030_I2C_BUS); |
| 187 | |
| 188 | return expansion_config.device_vendor; |
| 189 | } |
| 190 | |
| 191 | /* |
Dirk Behme | 9d0fc81 | 2009-01-28 21:39:57 +0100 | [diff] [blame] | 192 | * Routine: misc_init_r |
| 193 | * Description: Configure board specific parts |
Tom Rix | 5891151 | 2009-04-01 22:02:20 -0500 | [diff] [blame] | 194 | */ |
Dirk Behme | 9d0fc81 | 2009-01-28 21:39:57 +0100 | [diff] [blame] | 195 | int misc_init_r(void) |
| 196 | { |
Tom Rix | 2c15513 | 2009-06-28 12:52:30 -0500 | [diff] [blame] | 197 | twl4030_power_init(); |
Grazvydas Ignotas | ead39d7 | 2009-12-10 17:10:21 +0200 | [diff] [blame] | 198 | twl4030_led_init(TWL4030_LED_LEDEN_LEDAON | TWL4030_LED_LEDEN_LEDBON); |
Dirk Behme | 9d0fc81 | 2009-01-28 21:39:57 +0100 | [diff] [blame] | 199 | |
Olof Johansson | df38262 | 2009-09-29 10:22:45 -0400 | [diff] [blame] | 200 | #if defined(CONFIG_CMD_NET) |
| 201 | setup_net_chip(); |
| 202 | #endif |
| 203 | |
Steve Sakoman | c2d5b34 | 2010-08-12 15:13:02 -0700 | [diff] [blame] | 204 | printf("Board revision: %d\n", get_board_revision()); |
Steve Sakoman | a06e162 | 2010-08-24 10:37:29 -0700 | [diff] [blame] | 205 | |
| 206 | switch (get_sdio2_config()) { |
| 207 | case 0: |
| 208 | printf("Tranceiver detected on mmc2\n"); |
| 209 | MUX_OVERO_SDIO2_TRANSCEIVER(); |
| 210 | break; |
| 211 | case 1: |
| 212 | printf("Direct connection on mmc2\n"); |
| 213 | MUX_OVERO_SDIO2_DIRECT(); |
| 214 | break; |
| 215 | default: |
| 216 | printf("Unable to detect mmc2 connection type\n"); |
| 217 | } |
| 218 | |
Steve Sakoman | d64b5b8 | 2010-09-20 08:05:14 -0700 | [diff] [blame] | 219 | switch (get_expansion_id()) { |
| 220 | case GUMSTIX_SUMMIT: |
| 221 | printf("Recognized Summit expansion board (rev %d %s)\n", |
| 222 | expansion_config.revision, |
| 223 | expansion_config.fab_revision); |
| 224 | setenv("defaultdisplay", "dvi"); |
| 225 | break; |
| 226 | case GUMSTIX_TOBI: |
| 227 | printf("Recognized Tobi expansion board (rev %d %s)\n", |
| 228 | expansion_config.revision, |
| 229 | expansion_config.fab_revision); |
| 230 | setenv("defaultdisplay", "dvi"); |
| 231 | break; |
| 232 | case GUMSTIX_TOBI_DUO: |
| 233 | printf("Recognized Tobi Duo expansion board (rev %d %s)\n", |
| 234 | expansion_config.revision, |
| 235 | expansion_config.fab_revision); |
Philip Balister | 8f7109b | 2011-10-11 11:23:22 +0000 | [diff] [blame^] | 236 | /* second lan chip */ |
| 237 | enable_gpmc_cs_config(gpmc_lan_config, &gpmc_cfg->cs[4], |
| 238 | 0x2B000000, GPMC_SIZE_16M); |
Steve Sakoman | d64b5b8 | 2010-09-20 08:05:14 -0700 | [diff] [blame] | 239 | break; |
| 240 | case GUMSTIX_PALO35: |
| 241 | printf("Recognized Palo35 expansion board (rev %d %s)\n", |
| 242 | expansion_config.revision, |
| 243 | expansion_config.fab_revision); |
| 244 | setenv("defaultdisplay", "lcd35"); |
| 245 | break; |
| 246 | case GUMSTIX_PALO43: |
| 247 | printf("Recognized Palo43 expansion board (rev %d %s)\n", |
| 248 | expansion_config.revision, |
| 249 | expansion_config.fab_revision); |
| 250 | setenv("defaultdisplay", "lcd43"); |
| 251 | break; |
| 252 | case GUMSTIX_CHESTNUT43: |
| 253 | printf("Recognized Chestnut43 expansion board (rev %d %s)\n", |
| 254 | expansion_config.revision, |
| 255 | expansion_config.fab_revision); |
| 256 | setenv("defaultdisplay", "lcd43"); |
| 257 | break; |
| 258 | case GUMSTIX_PINTO: |
| 259 | printf("Recognized Pinto expansion board (rev %d %s)\n", |
| 260 | expansion_config.revision, |
| 261 | expansion_config.fab_revision); |
| 262 | break; |
| 263 | case GUMSTIX_GALLOP43: |
| 264 | printf("Recognized Gallop43 expansion board (rev %d %s)\n", |
| 265 | expansion_config.revision, |
| 266 | expansion_config.fab_revision); |
| 267 | setenv("defaultdisplay", "lcd43"); |
| 268 | break; |
| 269 | case ETTUS_USRP_E: |
| 270 | printf("Recognized Ettus Research USRP-E (rev %d %s)\n", |
| 271 | expansion_config.revision, |
| 272 | expansion_config.fab_revision); |
| 273 | MUX_USRP_E(); |
| 274 | setenv("defaultdisplay", "dvi"); |
| 275 | break; |
| 276 | case GUMSTIX_NO_EEPROM: |
| 277 | printf("No EEPROM on expansion board\n"); |
| 278 | break; |
| 279 | default: |
| 280 | printf("Unrecognized expansion board\n"); |
| 281 | } |
| 282 | |
| 283 | if (expansion_config.content == 1) |
| 284 | setenv(expansion_config.env_var, expansion_config.env_setting); |
| 285 | |
Dirk Behme | e6a6a70 | 2009-03-12 19:30:50 +0100 | [diff] [blame] | 286 | dieid_num_r(); |
| 287 | |
Dirk Behme | 9d0fc81 | 2009-01-28 21:39:57 +0100 | [diff] [blame] | 288 | return 0; |
| 289 | } |
| 290 | |
Tom Rix | 5891151 | 2009-04-01 22:02:20 -0500 | [diff] [blame] | 291 | /* |
Dirk Behme | 9d0fc81 | 2009-01-28 21:39:57 +0100 | [diff] [blame] | 292 | * Routine: set_muxconf_regs |
| 293 | * Description: Setting up the configuration Mux registers specific to the |
| 294 | * hardware. Many pins need to be moved from protect to primary |
| 295 | * mode. |
Tom Rix | 5891151 | 2009-04-01 22:02:20 -0500 | [diff] [blame] | 296 | */ |
Dirk Behme | 9d0fc81 | 2009-01-28 21:39:57 +0100 | [diff] [blame] | 297 | void set_muxconf_regs(void) |
| 298 | { |
| 299 | MUX_OVERO(); |
| 300 | } |
Olof Johansson | df38262 | 2009-09-29 10:22:45 -0400 | [diff] [blame] | 301 | |
| 302 | #if defined(CONFIG_CMD_NET) |
| 303 | /* |
| 304 | * Routine: setup_net_chip |
| 305 | * Description: Setting up the configuration GPMC registers specific to the |
| 306 | * Ethernet hardware. |
| 307 | */ |
| 308 | static void setup_net_chip(void) |
| 309 | { |
| 310 | struct ctrl *ctrl_base = (struct ctrl *)OMAP34XX_CTRL_BASE; |
| 311 | |
Steve Sakoman | ba9a11e | 2010-08-12 21:07:02 -0700 | [diff] [blame] | 312 | /* first lan chip */ |
| 313 | enable_gpmc_cs_config(gpmc_lan_config, &gpmc_cfg->cs[5], 0x2C000000, |
| 314 | GPMC_SIZE_16M); |
| 315 | |
Olof Johansson | df38262 | 2009-09-29 10:22:45 -0400 | [diff] [blame] | 316 | /* Enable off mode for NWE in PADCONF_GPMC_NWE register */ |
| 317 | writew(readw(&ctrl_base ->gpmc_nwe) | 0x0E00, &ctrl_base->gpmc_nwe); |
| 318 | /* Enable off mode for NOE in PADCONF_GPMC_NADV_ALE register */ |
| 319 | writew(readw(&ctrl_base->gpmc_noe) | 0x0E00, &ctrl_base->gpmc_noe); |
| 320 | /* Enable off mode for ALE in PADCONF_GPMC_NADV_ALE register */ |
| 321 | writew(readw(&ctrl_base->gpmc_nadv_ale) | 0x0E00, |
| 322 | &ctrl_base->gpmc_nadv_ale); |
| 323 | |
| 324 | /* Make GPIO 64 as output pin and send a magic pulse through it */ |
Sanjeev Premi | 84c3b63 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 325 | if (!gpio_request(64, "")) { |
| 326 | gpio_direction_output(64, 0); |
| 327 | gpio_set_value(64, 1); |
Olof Johansson | df38262 | 2009-09-29 10:22:45 -0400 | [diff] [blame] | 328 | udelay(1); |
Sanjeev Premi | 84c3b63 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 329 | gpio_set_value(64, 0); |
Olof Johansson | df38262 | 2009-09-29 10:22:45 -0400 | [diff] [blame] | 330 | udelay(1); |
Sanjeev Premi | 84c3b63 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 331 | gpio_set_value(64, 1); |
Olof Johansson | df38262 | 2009-09-29 10:22:45 -0400 | [diff] [blame] | 332 | } |
| 333 | } |
| 334 | #endif |
| 335 | |
| 336 | int board_eth_init(bd_t *bis) |
| 337 | { |
| 338 | int rc = 0; |
| 339 | #ifdef CONFIG_SMC911X |
| 340 | rc = smc911x_initialize(0, CONFIG_SMC911X_BASE); |
| 341 | #endif |
| 342 | return rc; |
| 343 | } |
Steve Sakoman | cd7c572 | 2010-09-19 21:21:07 -0700 | [diff] [blame] | 344 | |
| 345 | #ifdef CONFIG_GENERIC_MMC |
| 346 | int board_mmc_init(bd_t *bis) |
| 347 | { |
| 348 | omap_mmc_init(0); |
| 349 | return 0; |
| 350 | } |
| 351 | #endif |