overo.c 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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. * SPDX-License-Identifier: GPL-2.0+
  14. */
  15. #include <common.h>
  16. #include <netdev.h>
  17. #include <twl4030.h>
  18. #include <linux/mtd/nand.h>
  19. #include <asm/io.h>
  20. #include <asm/arch/mmc_host_def.h>
  21. #include <asm/arch/mux.h>
  22. #include <asm/arch/mem.h>
  23. #include <asm/arch/sys_proto.h>
  24. #include <asm/gpio.h>
  25. #include <asm/mach-types.h>
  26. #include "overo.h"
  27. DECLARE_GLOBAL_DATA_PTR;
  28. #define TWL4030_I2C_BUS 0
  29. #define EXPANSION_EEPROM_I2C_BUS 2
  30. #define EXPANSION_EEPROM_I2C_ADDRESS 0x51
  31. #define GUMSTIX_SUMMIT 0x01000200
  32. #define GUMSTIX_TOBI 0x02000200
  33. #define GUMSTIX_TOBI_DUO 0x03000200
  34. #define GUMSTIX_PALO35 0x04000200
  35. #define GUMSTIX_PALO43 0x05000200
  36. #define GUMSTIX_CHESTNUT43 0x06000200
  37. #define GUMSTIX_PINTO 0x07000200
  38. #define GUMSTIX_GALLOP43 0x08000200
  39. #define ETTUS_USRP_E 0x01000300
  40. #define GUMSTIX_NO_EEPROM 0xffffffff
  41. static struct {
  42. unsigned int device_vendor;
  43. unsigned char revision;
  44. unsigned char content;
  45. char fab_revision[8];
  46. char env_var[16];
  47. char env_setting[64];
  48. } expansion_config;
  49. #if defined(CONFIG_CMD_NET)
  50. static void setup_net_chip(void);
  51. #endif
  52. /* GPMC definitions for LAN9221 chips on Tobi expansion boards */
  53. static const u32 gpmc_lan_config[] = {
  54. NET_LAN9221_GPMC_CONFIG1,
  55. NET_LAN9221_GPMC_CONFIG2,
  56. NET_LAN9221_GPMC_CONFIG3,
  57. NET_LAN9221_GPMC_CONFIG4,
  58. NET_LAN9221_GPMC_CONFIG5,
  59. NET_LAN9221_GPMC_CONFIG6,
  60. /*CONFIG7- computed as params */
  61. };
  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_OVERO;
  71. /* boot param addr */
  72. gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
  73. return 0;
  74. }
  75. /*
  76. * Routine: get_board_revision
  77. * Description: Returns the board revision
  78. */
  79. int get_board_revision(void)
  80. {
  81. int revision;
  82. #ifdef CONFIG_SYS_I2C_OMAP34XX
  83. unsigned char data;
  84. /* board revisions <= R2410 connect 4030 irq_1 to gpio112 */
  85. /* these boards should return a revision number of 0 */
  86. /* the code below forces a 4030 RTC irq to ensure that gpio112 is low */
  87. i2c_set_bus_num(TWL4030_I2C_BUS);
  88. data = 0x01;
  89. i2c_write(0x4B, 0x29, 1, &data, 1);
  90. data = 0x0c;
  91. i2c_write(0x4B, 0x2b, 1, &data, 1);
  92. i2c_read(0x4B, 0x2a, 1, &data, 1);
  93. #endif
  94. if (!gpio_request(112, "") &&
  95. !gpio_request(113, "") &&
  96. !gpio_request(115, "")) {
  97. gpio_direction_input(112);
  98. gpio_direction_input(113);
  99. gpio_direction_input(115);
  100. revision = gpio_get_value(115) << 2 |
  101. gpio_get_value(113) << 1 |
  102. gpio_get_value(112);
  103. } else {
  104. puts("Error: unable to acquire board revision GPIOs\n");
  105. revision = -1;
  106. }
  107. return revision;
  108. }
  109. #ifdef CONFIG_SPL_BUILD
  110. /*
  111. * Routine: get_board_mem_timings
  112. * Description: If we use SPL then there is no x-loader nor config header
  113. * so we have to setup the DDR timings ourself on both banks.
  114. */
  115. void get_board_mem_timings(struct board_sdrc_timings *timings)
  116. {
  117. timings->mr = MICRON_V_MR_165;
  118. switch (get_board_revision()) {
  119. case REVISION_0: /* Micron 1286MB/256MB, 1/2 banks of 128MB */
  120. timings->mcfg = MICRON_V_MCFG_165(128 << 20);
  121. timings->ctrla = MICRON_V_ACTIMA_165;
  122. timings->ctrlb = MICRON_V_ACTIMB_165;
  123. timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
  124. break;
  125. case REVISION_1: /* Micron 256MB/512MB, 1/2 banks of 256MB */
  126. timings->mcfg = MICRON_V_MCFG_200(256 << 20);
  127. timings->ctrla = MICRON_V_ACTIMA_200;
  128. timings->ctrlb = MICRON_V_ACTIMB_200;
  129. timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
  130. break;
  131. case REVISION_2: /* Hynix 256MB/512MB, 1/2 banks of 256MB */
  132. timings->mcfg = HYNIX_V_MCFG_200(256 << 20);
  133. timings->ctrla = HYNIX_V_ACTIMA_200;
  134. timings->ctrlb = HYNIX_V_ACTIMB_200;
  135. timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
  136. break;
  137. case REVISION_3: /* Micron 512MB/1024MB, 1/2 banks of 512MB */
  138. timings->mcfg = MCFG(512 << 20, 15);
  139. timings->ctrla = MICRON_V_ACTIMA_200;
  140. timings->ctrlb = MICRON_V_ACTIMB_200;
  141. timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
  142. break;
  143. default:
  144. timings->mcfg = MICRON_V_MCFG_165(128 << 20);
  145. timings->ctrla = MICRON_V_ACTIMA_165;
  146. timings->ctrlb = MICRON_V_ACTIMB_165;
  147. timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
  148. }
  149. }
  150. #endif
  151. /*
  152. * Routine: get_sdio2_config
  153. * Description: Return information about the wifi module connection
  154. * Returns 0 if the module connects though a level translator
  155. * Returns 1 if the module connects directly
  156. */
  157. int get_sdio2_config(void)
  158. {
  159. int sdio_direct;
  160. if (!gpio_request(130, "") && !gpio_request(139, "")) {
  161. gpio_direction_output(130, 0);
  162. gpio_direction_input(139);
  163. sdio_direct = 1;
  164. gpio_set_value(130, 0);
  165. if (gpio_get_value(139) == 0) {
  166. gpio_set_value(130, 1);
  167. if (gpio_get_value(139) == 1)
  168. sdio_direct = 0;
  169. }
  170. gpio_direction_input(130);
  171. } else {
  172. puts("Error: unable to acquire sdio2 clk GPIOs\n");
  173. sdio_direct = -1;
  174. }
  175. return sdio_direct;
  176. }
  177. /*
  178. * Routine: get_expansion_id
  179. * Description: This function checks for expansion board by checking I2C
  180. * bus 2 for the availability of an AT24C01B serial EEPROM.
  181. * returns the device_vendor field from the EEPROM
  182. */
  183. unsigned int get_expansion_id(void)
  184. {
  185. i2c_set_bus_num(EXPANSION_EEPROM_I2C_BUS);
  186. /* return GUMSTIX_NO_EEPROM if eeprom doesn't respond */
  187. if (i2c_probe(EXPANSION_EEPROM_I2C_ADDRESS) == 1) {
  188. i2c_set_bus_num(TWL4030_I2C_BUS);
  189. return GUMSTIX_NO_EEPROM;
  190. }
  191. /* read configuration data */
  192. i2c_read(EXPANSION_EEPROM_I2C_ADDRESS, 0, 1, (u8 *)&expansion_config,
  193. sizeof(expansion_config));
  194. i2c_set_bus_num(TWL4030_I2C_BUS);
  195. return expansion_config.device_vendor;
  196. }
  197. /*
  198. * Routine: misc_init_r
  199. * Description: Configure board specific parts
  200. */
  201. int misc_init_r(void)
  202. {
  203. twl4030_power_init();
  204. twl4030_led_init(TWL4030_LED_LEDEN_LEDAON | TWL4030_LED_LEDEN_LEDBON);
  205. #if defined(CONFIG_CMD_NET)
  206. setup_net_chip();
  207. #endif
  208. printf("Board revision: %d\n", get_board_revision());
  209. switch (get_sdio2_config()) {
  210. case 0:
  211. puts("Tranceiver detected on mmc2\n");
  212. MUX_OVERO_SDIO2_TRANSCEIVER();
  213. break;
  214. case 1:
  215. puts("Direct connection on mmc2\n");
  216. MUX_OVERO_SDIO2_DIRECT();
  217. break;
  218. default:
  219. puts("Unable to detect mmc2 connection type\n");
  220. }
  221. switch (get_expansion_id()) {
  222. case GUMSTIX_SUMMIT:
  223. printf("Recognized Summit expansion board (rev %d %s)\n",
  224. expansion_config.revision,
  225. expansion_config.fab_revision);
  226. setenv("defaultdisplay", "dvi");
  227. break;
  228. case GUMSTIX_TOBI:
  229. printf("Recognized Tobi expansion board (rev %d %s)\n",
  230. expansion_config.revision,
  231. expansion_config.fab_revision);
  232. setenv("defaultdisplay", "dvi");
  233. break;
  234. case GUMSTIX_TOBI_DUO:
  235. printf("Recognized Tobi Duo expansion board (rev %d %s)\n",
  236. expansion_config.revision,
  237. expansion_config.fab_revision);
  238. /* second lan chip */
  239. enable_gpmc_cs_config(gpmc_lan_config, &gpmc_cfg->cs[4],
  240. 0x2B000000, GPMC_SIZE_16M);
  241. break;
  242. case GUMSTIX_PALO35:
  243. printf("Recognized Palo35 expansion board (rev %d %s)\n",
  244. expansion_config.revision,
  245. expansion_config.fab_revision);
  246. setenv("defaultdisplay", "lcd35");
  247. break;
  248. case GUMSTIX_PALO43:
  249. printf("Recognized Palo43 expansion board (rev %d %s)\n",
  250. expansion_config.revision,
  251. expansion_config.fab_revision);
  252. setenv("defaultdisplay", "lcd43");
  253. break;
  254. case GUMSTIX_CHESTNUT43:
  255. printf("Recognized Chestnut43 expansion board (rev %d %s)\n",
  256. expansion_config.revision,
  257. expansion_config.fab_revision);
  258. setenv("defaultdisplay", "lcd43");
  259. break;
  260. case GUMSTIX_PINTO:
  261. printf("Recognized Pinto expansion board (rev %d %s)\n",
  262. expansion_config.revision,
  263. expansion_config.fab_revision);
  264. break;
  265. case GUMSTIX_GALLOP43:
  266. printf("Recognized Gallop43 expansion board (rev %d %s)\n",
  267. expansion_config.revision,
  268. expansion_config.fab_revision);
  269. setenv("defaultdisplay", "lcd43");
  270. break;
  271. case ETTUS_USRP_E:
  272. printf("Recognized Ettus Research USRP-E (rev %d %s)\n",
  273. expansion_config.revision,
  274. expansion_config.fab_revision);
  275. MUX_USRP_E();
  276. setenv("defaultdisplay", "dvi");
  277. break;
  278. case GUMSTIX_NO_EEPROM:
  279. puts("No EEPROM on expansion board\n");
  280. break;
  281. default:
  282. puts("Unrecognized expansion board\n");
  283. }
  284. if (expansion_config.content == 1)
  285. setenv(expansion_config.env_var, expansion_config.env_setting);
  286. dieid_num_r();
  287. return 0;
  288. }
  289. /*
  290. * Routine: set_muxconf_regs
  291. * Description: Setting up the configuration Mux registers specific to the
  292. * hardware. Many pins need to be moved from protect to primary
  293. * mode.
  294. */
  295. void set_muxconf_regs(void)
  296. {
  297. MUX_OVERO();
  298. }
  299. #if defined(CONFIG_CMD_NET)
  300. /*
  301. * Routine: setup_net_chip
  302. * Description: Setting up the configuration GPMC registers specific to the
  303. * Ethernet hardware.
  304. */
  305. static void setup_net_chip(void)
  306. {
  307. struct ctrl *ctrl_base = (struct ctrl *)OMAP34XX_CTRL_BASE;
  308. /* first lan chip */
  309. enable_gpmc_cs_config(gpmc_lan_config, &gpmc_cfg->cs[5], 0x2C000000,
  310. GPMC_SIZE_16M);
  311. /* Enable off mode for NWE in PADCONF_GPMC_NWE register */
  312. writew(readw(&ctrl_base ->gpmc_nwe) | 0x0E00, &ctrl_base->gpmc_nwe);
  313. /* Enable off mode for NOE in PADCONF_GPMC_NADV_ALE register */
  314. writew(readw(&ctrl_base->gpmc_noe) | 0x0E00, &ctrl_base->gpmc_noe);
  315. /* Enable off mode for ALE in PADCONF_GPMC_NADV_ALE register */
  316. writew(readw(&ctrl_base->gpmc_nadv_ale) | 0x0E00,
  317. &ctrl_base->gpmc_nadv_ale);
  318. /* Make GPIO 64 as output pin and send a magic pulse through it */
  319. if (!gpio_request(64, "")) {
  320. gpio_direction_output(64, 0);
  321. gpio_set_value(64, 1);
  322. udelay(1);
  323. gpio_set_value(64, 0);
  324. udelay(1);
  325. gpio_set_value(64, 1);
  326. }
  327. }
  328. #endif
  329. int board_eth_init(bd_t *bis)
  330. {
  331. int rc = 0;
  332. #ifdef CONFIG_SMC911X
  333. rc = smc911x_initialize(0, CONFIG_SMC911X_BASE);
  334. #endif
  335. return rc;
  336. }
  337. #if defined(CONFIG_GENERIC_MMC) && !defined(CONFIG_SPL_BUILD)
  338. int board_mmc_init(bd_t *bis)
  339. {
  340. return omap_mmc_init(0, 0, 0, -1, -1);
  341. }
  342. #endif