overo.c 10 KB

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