overo.c 11 KB

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