overo.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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>
  32. #include <netdev.h>
  33. #include <twl4030.h>
  34. #include <asm/io.h>
  35. #include <asm/arch/mmc_host_def.h>
  36. #include <asm/arch/mux.h>
  37. #include <asm/arch/mem.h>
  38. #include <asm/arch/sys_proto.h>
  39. #include <asm/arch/gpio.h>
  40. #include <asm/mach-types.h>
  41. #include "overo.h"
  42. DECLARE_GLOBAL_DATA_PTR;
  43. #define TWL4030_I2C_BUS 0
  44. #define EXPANSION_EEPROM_I2C_BUS 2
  45. #define EXPANSION_EEPROM_I2C_ADDRESS 0x51
  46. #define GUMSTIX_SUMMIT 0x01000200
  47. #define GUMSTIX_TOBI 0x02000200
  48. #define GUMSTIX_TOBI_DUO 0x03000200
  49. #define GUMSTIX_PALO35 0x04000200
  50. #define GUMSTIX_PALO43 0x05000200
  51. #define GUMSTIX_CHESTNUT43 0x06000200
  52. #define GUMSTIX_PINTO 0x07000200
  53. #define GUMSTIX_GALLOP43 0x08000200
  54. #define ETTUS_USRP_E 0x01000300
  55. #define GUMSTIX_NO_EEPROM 0xffffffff
  56. static struct {
  57. unsigned int device_vendor;
  58. unsigned char revision;
  59. unsigned char content;
  60. char fab_revision[8];
  61. char env_var[16];
  62. char env_setting[64];
  63. } expansion_config;
  64. #if defined(CONFIG_CMD_NET)
  65. static void setup_net_chip(void);
  66. #endif
  67. /* GPMC definitions for LAN9221 chips on Tobi expansion boards */
  68. static const u32 gpmc_lan_config[] = {
  69. NET_LAN9221_GPMC_CONFIG1,
  70. NET_LAN9221_GPMC_CONFIG2,
  71. NET_LAN9221_GPMC_CONFIG3,
  72. NET_LAN9221_GPMC_CONFIG4,
  73. NET_LAN9221_GPMC_CONFIG5,
  74. NET_LAN9221_GPMC_CONFIG6,
  75. /*CONFIG7- computed as params */
  76. };
  77. /*
  78. * Routine: board_init
  79. * Description: Early hardware init.
  80. */
  81. int board_init(void)
  82. {
  83. gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
  84. /* board id for Linux */
  85. gd->bd->bi_arch_number = MACH_TYPE_OVERO;
  86. /* boot param addr */
  87. gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
  88. return 0;
  89. }
  90. /*
  91. * Routine: get_board_revision
  92. * Description: Returns the board revision
  93. */
  94. int get_board_revision(void)
  95. {
  96. int revision;
  97. if (!omap_request_gpio(112) &&
  98. !omap_request_gpio(113) &&
  99. !omap_request_gpio(115)) {
  100. omap_set_gpio_direction(112, 1);
  101. omap_set_gpio_direction(113, 1);
  102. omap_set_gpio_direction(115, 1);
  103. revision = omap_get_gpio_datain(115) << 2 |
  104. omap_get_gpio_datain(113) << 1 |
  105. omap_get_gpio_datain(112);
  106. omap_free_gpio(112);
  107. omap_free_gpio(113);
  108. omap_free_gpio(115);
  109. } else {
  110. printf("Error: unable to acquire board revision GPIOs\n");
  111. revision = -1;
  112. }
  113. return revision;
  114. }
  115. /*
  116. * Routine: get_sdio2_config
  117. * Description: Return information about the wifi module connection
  118. * Returns 0 if the module connects though a level translator
  119. * Returns 1 if the module connects directly
  120. */
  121. int get_sdio2_config(void)
  122. {
  123. int sdio_direct;
  124. if (!omap_request_gpio(130) && !omap_request_gpio(139)) {
  125. omap_set_gpio_direction(130, 0);
  126. omap_set_gpio_direction(139, 1);
  127. sdio_direct = 1;
  128. omap_set_gpio_dataout(130, 0);
  129. if (omap_get_gpio_datain(139) == 0) {
  130. omap_set_gpio_dataout(130, 1);
  131. if (omap_get_gpio_datain(139) == 1)
  132. sdio_direct = 0;
  133. }
  134. omap_free_gpio(130);
  135. omap_free_gpio(139);
  136. } else {
  137. printf("Error: unable to acquire sdio2 clk GPIOs\n");
  138. sdio_direct = -1;
  139. }
  140. return sdio_direct;
  141. }
  142. /*
  143. * Routine: get_expansion_id
  144. * Description: This function checks for expansion board by checking I2C
  145. * bus 2 for the availability of an AT24C01B serial EEPROM.
  146. * returns the device_vendor field from the EEPROM
  147. */
  148. unsigned int get_expansion_id(void)
  149. {
  150. i2c_set_bus_num(EXPANSION_EEPROM_I2C_BUS);
  151. /* return GUMSTIX_NO_EEPROM if eeprom doesn't respond */
  152. if (i2c_probe(EXPANSION_EEPROM_I2C_ADDRESS) == 1) {
  153. i2c_set_bus_num(TWL4030_I2C_BUS);
  154. return GUMSTIX_NO_EEPROM;
  155. }
  156. /* read configuration data */
  157. i2c_read(EXPANSION_EEPROM_I2C_ADDRESS, 0, 1, (u8 *)&expansion_config,
  158. sizeof(expansion_config));
  159. i2c_set_bus_num(TWL4030_I2C_BUS);
  160. return expansion_config.device_vendor;
  161. }
  162. /*
  163. * Routine: misc_init_r
  164. * Description: Configure board specific parts
  165. */
  166. int misc_init_r(void)
  167. {
  168. twl4030_power_init();
  169. twl4030_led_init(TWL4030_LED_LEDEN_LEDAON | TWL4030_LED_LEDEN_LEDBON);
  170. #if defined(CONFIG_CMD_NET)
  171. setup_net_chip();
  172. #endif
  173. printf("Board revision: %d\n", get_board_revision());
  174. switch (get_sdio2_config()) {
  175. case 0:
  176. printf("Tranceiver detected on mmc2\n");
  177. MUX_OVERO_SDIO2_TRANSCEIVER();
  178. break;
  179. case 1:
  180. printf("Direct connection on mmc2\n");
  181. MUX_OVERO_SDIO2_DIRECT();
  182. break;
  183. default:
  184. printf("Unable to detect mmc2 connection type\n");
  185. }
  186. switch (get_expansion_id()) {
  187. case GUMSTIX_SUMMIT:
  188. printf("Recognized Summit expansion board (rev %d %s)\n",
  189. expansion_config.revision,
  190. expansion_config.fab_revision);
  191. setenv("defaultdisplay", "dvi");
  192. break;
  193. case GUMSTIX_TOBI:
  194. printf("Recognized Tobi expansion board (rev %d %s)\n",
  195. expansion_config.revision,
  196. expansion_config.fab_revision);
  197. setenv("defaultdisplay", "dvi");
  198. break;
  199. case GUMSTIX_TOBI_DUO:
  200. printf("Recognized Tobi Duo expansion board (rev %d %s)\n",
  201. expansion_config.revision,
  202. expansion_config.fab_revision);
  203. break;
  204. case GUMSTIX_PALO35:
  205. printf("Recognized Palo35 expansion board (rev %d %s)\n",
  206. expansion_config.revision,
  207. expansion_config.fab_revision);
  208. setenv("defaultdisplay", "lcd35");
  209. break;
  210. case GUMSTIX_PALO43:
  211. printf("Recognized Palo43 expansion board (rev %d %s)\n",
  212. expansion_config.revision,
  213. expansion_config.fab_revision);
  214. setenv("defaultdisplay", "lcd43");
  215. break;
  216. case GUMSTIX_CHESTNUT43:
  217. printf("Recognized Chestnut43 expansion board (rev %d %s)\n",
  218. expansion_config.revision,
  219. expansion_config.fab_revision);
  220. setenv("defaultdisplay", "lcd43");
  221. break;
  222. case GUMSTIX_PINTO:
  223. printf("Recognized Pinto expansion board (rev %d %s)\n",
  224. expansion_config.revision,
  225. expansion_config.fab_revision);
  226. break;
  227. case GUMSTIX_GALLOP43:
  228. printf("Recognized Gallop43 expansion board (rev %d %s)\n",
  229. expansion_config.revision,
  230. expansion_config.fab_revision);
  231. setenv("defaultdisplay", "lcd43");
  232. break;
  233. case ETTUS_USRP_E:
  234. printf("Recognized Ettus Research USRP-E (rev %d %s)\n",
  235. expansion_config.revision,
  236. expansion_config.fab_revision);
  237. MUX_USRP_E();
  238. setenv("defaultdisplay", "dvi");
  239. break;
  240. case GUMSTIX_NO_EEPROM:
  241. printf("No EEPROM on expansion board\n");
  242. break;
  243. default:
  244. printf("Unrecognized expansion board\n");
  245. }
  246. if (expansion_config.content == 1)
  247. setenv(expansion_config.env_var, expansion_config.env_setting);
  248. dieid_num_r();
  249. return 0;
  250. }
  251. /*
  252. * Routine: set_muxconf_regs
  253. * Description: Setting up the configuration Mux registers specific to the
  254. * hardware. Many pins need to be moved from protect to primary
  255. * mode.
  256. */
  257. void set_muxconf_regs(void)
  258. {
  259. MUX_OVERO();
  260. }
  261. #if defined(CONFIG_CMD_NET)
  262. /*
  263. * Routine: setup_net_chip
  264. * Description: Setting up the configuration GPMC registers specific to the
  265. * Ethernet hardware.
  266. */
  267. static void setup_net_chip(void)
  268. {
  269. struct ctrl *ctrl_base = (struct ctrl *)OMAP34XX_CTRL_BASE;
  270. /* first lan chip */
  271. enable_gpmc_cs_config(gpmc_lan_config, &gpmc_cfg->cs[5], 0x2C000000,
  272. GPMC_SIZE_16M);
  273. /* second lan chip */
  274. enable_gpmc_cs_config(gpmc_lan_config, &gpmc_cfg->cs[4], 0x2B000000,
  275. GPMC_SIZE_16M);
  276. /* Enable off mode for NWE in PADCONF_GPMC_NWE register */
  277. writew(readw(&ctrl_base ->gpmc_nwe) | 0x0E00, &ctrl_base->gpmc_nwe);
  278. /* Enable off mode for NOE in PADCONF_GPMC_NADV_ALE register */
  279. writew(readw(&ctrl_base->gpmc_noe) | 0x0E00, &ctrl_base->gpmc_noe);
  280. /* Enable off mode for ALE in PADCONF_GPMC_NADV_ALE register */
  281. writew(readw(&ctrl_base->gpmc_nadv_ale) | 0x0E00,
  282. &ctrl_base->gpmc_nadv_ale);
  283. /* Make GPIO 64 as output pin and send a magic pulse through it */
  284. if (!omap_request_gpio(64)) {
  285. omap_set_gpio_direction(64, 0);
  286. omap_set_gpio_dataout(64, 1);
  287. udelay(1);
  288. omap_set_gpio_dataout(64, 0);
  289. udelay(1);
  290. omap_set_gpio_dataout(64, 1);
  291. }
  292. }
  293. #endif
  294. int board_eth_init(bd_t *bis)
  295. {
  296. int rc = 0;
  297. #ifdef CONFIG_SMC911X
  298. rc = smc911x_initialize(0, CONFIG_SMC911X_BASE);
  299. #endif
  300. return rc;
  301. }
  302. #ifdef CONFIG_GENERIC_MMC
  303. int board_mmc_init(bd_t *bis)
  304. {
  305. omap_mmc_init(0);
  306. return 0;
  307. }
  308. #endif