overo.c 10.0 KB

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