overo.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  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 <dm.h>
  17. #include <ns16550.h>
  18. #include <netdev.h>
  19. #include <twl4030.h>
  20. #include <linux/mtd/nand.h>
  21. #include <asm/io.h>
  22. #include <asm/arch/mmc_host_def.h>
  23. #include <asm/arch/mux.h>
  24. #include <asm/arch/mem.h>
  25. #include <asm/arch/sys_proto.h>
  26. #include <asm/gpio.h>
  27. #include <asm/mach-types.h>
  28. #include "overo.h"
  29. #ifdef CONFIG_USB_EHCI
  30. #include <usb.h>
  31. #include <asm/ehci-omap.h>
  32. #endif
  33. DECLARE_GLOBAL_DATA_PTR;
  34. #define TWL4030_I2C_BUS 0
  35. #define EXPANSION_EEPROM_I2C_BUS 2
  36. #define EXPANSION_EEPROM_I2C_ADDRESS 0x51
  37. #define GUMSTIX_EMPTY_EEPROM 0x0
  38. #define GUMSTIX_SUMMIT 0x01000200
  39. #define GUMSTIX_TOBI 0x02000200
  40. #define GUMSTIX_TOBI_DUO 0x03000200
  41. #define GUMSTIX_PALO35 0x04000200
  42. #define GUMSTIX_PALO43 0x05000200
  43. #define GUMSTIX_CHESTNUT43 0x06000200
  44. #define GUMSTIX_PINTO 0x07000200
  45. #define GUMSTIX_GALLOP43 0x08000200
  46. #define GUMSTIX_ALTO35 0x09000200
  47. #define GUMSTIX_STAGECOACH 0x0A000200
  48. #define GUMSTIX_THUMBO 0x0B000200
  49. #define GUMSTIX_TURTLECORE 0x0C000200
  50. #define GUMSTIX_ARBOR43C 0x0D000200
  51. #define ETTUS_USRP_E 0x01000300
  52. #define GUMSTIX_NO_EEPROM 0xffffffff
  53. static struct {
  54. unsigned int device_vendor;
  55. unsigned char revision;
  56. unsigned char content;
  57. char fab_revision[8];
  58. char env_var[16];
  59. char env_setting[64];
  60. } expansion_config = {0x0};
  61. static const struct ns16550_platdata overo_serial = {
  62. OMAP34XX_UART3,
  63. 2,
  64. V_NS16550_CLK
  65. };
  66. U_BOOT_DEVICE(overo_uart) = {
  67. "serial_omap",
  68. &overo_serial
  69. };
  70. /*
  71. * Routine: board_init
  72. * Description: Early hardware init.
  73. */
  74. int board_init(void)
  75. {
  76. gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
  77. /* board id for Linux */
  78. gd->bd->bi_arch_number = MACH_TYPE_OVERO;
  79. /* boot param addr */
  80. gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
  81. return 0;
  82. }
  83. /*
  84. * Routine: get_board_revision
  85. * Description: Returns the board revision
  86. */
  87. int get_board_revision(void)
  88. {
  89. int revision;
  90. #ifdef CONFIG_SYS_I2C_OMAP34XX
  91. unsigned char data;
  92. /* board revisions <= R2410 connect 4030 irq_1 to gpio112 */
  93. /* these boards should return a revision number of 0 */
  94. /* the code below forces a 4030 RTC irq to ensure that gpio112 is low */
  95. i2c_set_bus_num(TWL4030_I2C_BUS);
  96. data = 0x01;
  97. i2c_write(0x4B, 0x29, 1, &data, 1);
  98. data = 0x0c;
  99. i2c_write(0x4B, 0x2b, 1, &data, 1);
  100. i2c_read(0x4B, 0x2a, 1, &data, 1);
  101. #endif
  102. if (!gpio_request(112, "") &&
  103. !gpio_request(113, "") &&
  104. !gpio_request(115, "")) {
  105. gpio_direction_input(112);
  106. gpio_direction_input(113);
  107. gpio_direction_input(115);
  108. revision = gpio_get_value(115) << 2 |
  109. gpio_get_value(113) << 1 |
  110. gpio_get_value(112);
  111. } else {
  112. puts("Error: unable to acquire board revision GPIOs\n");
  113. revision = -1;
  114. }
  115. return revision;
  116. }
  117. #ifdef CONFIG_SPL_BUILD
  118. /*
  119. * Routine: get_board_mem_timings
  120. * Description: If we use SPL then there is no x-loader nor config header
  121. * so we have to setup the DDR timings ourself on both banks.
  122. */
  123. void get_board_mem_timings(struct board_sdrc_timings *timings)
  124. {
  125. timings->mr = MICRON_V_MR_165;
  126. switch (get_board_revision()) {
  127. case REVISION_0: /* Micron 1286MB/256MB, 1/2 banks of 128MB */
  128. timings->mcfg = MICRON_V_MCFG_165(128 << 20);
  129. timings->ctrla = MICRON_V_ACTIMA_165;
  130. timings->ctrlb = MICRON_V_ACTIMB_165;
  131. timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
  132. break;
  133. case REVISION_1: /* Micron 256MB/512MB, 1/2 banks of 256MB */
  134. case REVISION_4:
  135. timings->mcfg = MICRON_V_MCFG_200(256 << 20);
  136. timings->ctrla = MICRON_V_ACTIMA_200;
  137. timings->ctrlb = MICRON_V_ACTIMB_200;
  138. timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
  139. break;
  140. case REVISION_2: /* Hynix 256MB/512MB, 1/2 banks of 256MB */
  141. timings->mcfg = HYNIX_V_MCFG_200(256 << 20);
  142. timings->ctrla = HYNIX_V_ACTIMA_200;
  143. timings->ctrlb = HYNIX_V_ACTIMB_200;
  144. timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
  145. break;
  146. case REVISION_3: /* Micron 512MB/1024MB, 1/2 banks of 512MB */
  147. timings->mcfg = MCFG(512 << 20, 15);
  148. timings->ctrla = MICRON_V_ACTIMA_200;
  149. timings->ctrlb = MICRON_V_ACTIMB_200;
  150. timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
  151. break;
  152. default:
  153. timings->mcfg = MICRON_V_MCFG_165(128 << 20);
  154. timings->ctrla = MICRON_V_ACTIMA_165;
  155. timings->ctrlb = MICRON_V_ACTIMB_165;
  156. timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
  157. }
  158. }
  159. #endif
  160. /*
  161. * Routine: get_sdio2_config
  162. * Description: Return information about the wifi module connection
  163. * Returns 0 if the module connects though a level translator
  164. * Returns 1 if the module connects directly
  165. */
  166. int get_sdio2_config(void)
  167. {
  168. int sdio_direct;
  169. if (!gpio_request(130, "") && !gpio_request(139, "")) {
  170. gpio_direction_output(130, 0);
  171. gpio_direction_input(139);
  172. sdio_direct = 1;
  173. gpio_set_value(130, 0);
  174. if (gpio_get_value(139) == 0) {
  175. gpio_set_value(130, 1);
  176. if (gpio_get_value(139) == 1)
  177. sdio_direct = 0;
  178. }
  179. gpio_direction_input(130);
  180. } else {
  181. puts("Error: unable to acquire sdio2 clk GPIOs\n");
  182. sdio_direct = -1;
  183. }
  184. return sdio_direct;
  185. }
  186. /*
  187. * Routine: get_expansion_id
  188. * Description: This function checks for expansion board by checking I2C
  189. * bus 2 for the availability of an AT24C01B serial EEPROM.
  190. * returns the device_vendor field from the EEPROM
  191. */
  192. unsigned int get_expansion_id(void)
  193. {
  194. if (expansion_config.device_vendor != 0x0)
  195. return expansion_config.device_vendor;
  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. unsigned int expansion_id;
  215. twl4030_power_init();
  216. twl4030_led_init(TWL4030_LED_LEDEN_LEDAON | TWL4030_LED_LEDEN_LEDBON);
  217. printf("Board revision: %d\n", get_board_revision());
  218. switch (get_sdio2_config()) {
  219. case 0:
  220. puts("Tranceiver detected on mmc2\n");
  221. MUX_OVERO_SDIO2_TRANSCEIVER();
  222. break;
  223. case 1:
  224. puts("Direct connection on mmc2\n");
  225. MUX_OVERO_SDIO2_DIRECT();
  226. break;
  227. default:
  228. puts("Unable to detect mmc2 connection type\n");
  229. }
  230. expansion_id = get_expansion_id();
  231. switch (expansion_id) {
  232. case GUMSTIX_SUMMIT:
  233. printf("Recognized Summit expansion board (rev %d %s)\n",
  234. expansion_config.revision,
  235. expansion_config.fab_revision);
  236. MUX_GUMSTIX();
  237. setenv("defaultdisplay", "dvi");
  238. setenv("expansionname", "summit");
  239. break;
  240. case GUMSTIX_TOBI:
  241. printf("Recognized Tobi expansion board (rev %d %s)\n",
  242. expansion_config.revision,
  243. expansion_config.fab_revision);
  244. MUX_GUMSTIX();
  245. setenv("defaultdisplay", "dvi");
  246. setenv("expansionname", "tobi");
  247. break;
  248. case GUMSTIX_TOBI_DUO:
  249. printf("Recognized Tobi Duo expansion board (rev %d %s)\n",
  250. expansion_config.revision,
  251. expansion_config.fab_revision);
  252. MUX_GUMSTIX();
  253. break;
  254. case GUMSTIX_PALO35:
  255. printf("Recognized Palo35 expansion board (rev %d %s)\n",
  256. expansion_config.revision,
  257. expansion_config.fab_revision);
  258. MUX_GUMSTIX();
  259. setenv("defaultdisplay", "lcd35");
  260. break;
  261. case GUMSTIX_PALO43:
  262. printf("Recognized Palo43 expansion board (rev %d %s)\n",
  263. expansion_config.revision,
  264. expansion_config.fab_revision);
  265. MUX_GUMSTIX();
  266. setenv("defaultdisplay", "lcd43");
  267. setenv("expansionname", "palo43");
  268. break;
  269. case GUMSTIX_CHESTNUT43:
  270. printf("Recognized Chestnut43 expansion board (rev %d %s)\n",
  271. expansion_config.revision,
  272. expansion_config.fab_revision);
  273. MUX_GUMSTIX();
  274. setenv("defaultdisplay", "lcd43");
  275. setenv("expansionname", "chestnut43");
  276. break;
  277. case GUMSTIX_PINTO:
  278. printf("Recognized Pinto expansion board (rev %d %s)\n",
  279. expansion_config.revision,
  280. expansion_config.fab_revision);
  281. MUX_GUMSTIX();
  282. break;
  283. case GUMSTIX_GALLOP43:
  284. printf("Recognized Gallop43 expansion board (rev %d %s)\n",
  285. expansion_config.revision,
  286. expansion_config.fab_revision);
  287. MUX_GUMSTIX();
  288. setenv("defaultdisplay", "lcd43");
  289. setenv("expansionname", "gallop43");
  290. break;
  291. case GUMSTIX_ALTO35:
  292. printf("Recognized Alto35 expansion board (rev %d %s)\n",
  293. expansion_config.revision,
  294. expansion_config.fab_revision);
  295. MUX_GUMSTIX();
  296. MUX_ALTO35();
  297. setenv("defaultdisplay", "lcd35");
  298. setenv("expansionname", "alto35");
  299. break;
  300. case GUMSTIX_STAGECOACH:
  301. printf("Recognized Stagecoach expansion board (rev %d %s)\n",
  302. expansion_config.revision,
  303. expansion_config.fab_revision);
  304. MUX_GUMSTIX();
  305. break;
  306. case GUMSTIX_THUMBO:
  307. printf("Recognized Thumbo expansion board (rev %d %s)\n",
  308. expansion_config.revision,
  309. expansion_config.fab_revision);
  310. MUX_GUMSTIX();
  311. break;
  312. case GUMSTIX_TURTLECORE:
  313. printf("Recognized Turtlecore expansion board (rev %d %s)\n",
  314. expansion_config.revision,
  315. expansion_config.fab_revision);
  316. MUX_GUMSTIX();
  317. break;
  318. case GUMSTIX_ARBOR43C:
  319. printf("Recognized Arbor43C expansion board (rev %d %s)\n",
  320. expansion_config.revision,
  321. expansion_config.fab_revision);
  322. MUX_GUMSTIX();
  323. MUX_ARBOR43C();
  324. setenv("defaultdisplay", "lcd43");
  325. break;
  326. case ETTUS_USRP_E:
  327. printf("Recognized Ettus Research USRP-E (rev %d %s)\n",
  328. expansion_config.revision,
  329. expansion_config.fab_revision);
  330. MUX_GUMSTIX();
  331. MUX_USRP_E();
  332. setenv("defaultdisplay", "dvi");
  333. break;
  334. case GUMSTIX_NO_EEPROM:
  335. case GUMSTIX_EMPTY_EEPROM:
  336. puts("No or empty EEPROM on expansion board\n");
  337. MUX_GUMSTIX();
  338. setenv("expansionname", "tobi");
  339. break;
  340. default:
  341. printf("Unrecognized expansion board 0x%08x\n", expansion_id);
  342. break;
  343. }
  344. if (expansion_config.content == 1)
  345. setenv(expansion_config.env_var, expansion_config.env_setting);
  346. dieid_num_r();
  347. if (get_cpu_family() == CPU_OMAP34XX)
  348. setenv("boardname", "overo");
  349. else
  350. setenv("boardname", "overo-storm");
  351. return 0;
  352. }
  353. /*
  354. * Routine: set_muxconf_regs
  355. * Description: Setting up the configuration Mux registers specific to the
  356. * hardware. Many pins need to be moved from protect to primary
  357. * mode.
  358. */
  359. void set_muxconf_regs(void)
  360. {
  361. MUX_OVERO();
  362. }
  363. #if defined(CONFIG_CMD_NET) && !defined(CONFIG_SPL_BUILD)
  364. /* GPMC definitions for LAN9221 chips on Tobi expansion boards */
  365. static const u32 gpmc_lan_config[] = {
  366. NET_LAN9221_GPMC_CONFIG1,
  367. NET_LAN9221_GPMC_CONFIG2,
  368. NET_LAN9221_GPMC_CONFIG3,
  369. NET_LAN9221_GPMC_CONFIG4,
  370. NET_LAN9221_GPMC_CONFIG5,
  371. NET_LAN9221_GPMC_CONFIG6,
  372. /*CONFIG7- computed as params */
  373. };
  374. /*
  375. * Routine: setup_net_chip
  376. * Description: Setting up the configuration GPMC registers specific to the
  377. * Ethernet hardware.
  378. */
  379. static void setup_net_chip(void)
  380. {
  381. struct ctrl *ctrl_base = (struct ctrl *)OMAP34XX_CTRL_BASE;
  382. /* Enable off mode for NWE in PADCONF_GPMC_NWE register */
  383. writew(readw(&ctrl_base ->gpmc_nwe) | 0x0E00, &ctrl_base->gpmc_nwe);
  384. /* Enable off mode for NOE in PADCONF_GPMC_NADV_ALE register */
  385. writew(readw(&ctrl_base->gpmc_noe) | 0x0E00, &ctrl_base->gpmc_noe);
  386. /* Enable off mode for ALE in PADCONF_GPMC_NADV_ALE register */
  387. writew(readw(&ctrl_base->gpmc_nadv_ale) | 0x0E00,
  388. &ctrl_base->gpmc_nadv_ale);
  389. }
  390. /*
  391. * Routine: reset_net_chip
  392. * Description: Reset the Ethernet hardware.
  393. */
  394. static void reset_net_chip(void)
  395. {
  396. /* Make GPIO 64 as output pin and send a magic pulse through it */
  397. if (!gpio_request(64, "")) {
  398. gpio_direction_output(64, 0);
  399. gpio_set_value(64, 1);
  400. udelay(1);
  401. gpio_set_value(64, 0);
  402. udelay(1);
  403. gpio_set_value(64, 1);
  404. }
  405. }
  406. int board_eth_init(bd_t *bis)
  407. {
  408. unsigned int expansion_id;
  409. int rc = 0;
  410. #ifdef CONFIG_SMC911X
  411. expansion_id = get_expansion_id();
  412. switch (expansion_id) {
  413. case GUMSTIX_TOBI_DUO:
  414. /* second lan chip */
  415. enable_gpmc_cs_config(gpmc_lan_config, &gpmc_cfg->cs[4],
  416. 0x2B000000, GPMC_SIZE_16M);
  417. /* no break */
  418. case GUMSTIX_TOBI:
  419. case GUMSTIX_CHESTNUT43:
  420. case GUMSTIX_STAGECOACH:
  421. case GUMSTIX_NO_EEPROM:
  422. case GUMSTIX_EMPTY_EEPROM:
  423. /* first lan chip */
  424. enable_gpmc_cs_config(gpmc_lan_config, &gpmc_cfg->cs[5],
  425. 0x2C000000, GPMC_SIZE_16M);
  426. setup_net_chip();
  427. reset_net_chip();
  428. rc = smc911x_initialize(0, CONFIG_SMC911X_BASE);
  429. break;
  430. default:
  431. break;
  432. }
  433. #endif
  434. return rc;
  435. }
  436. #endif
  437. #if defined(CONFIG_GENERIC_MMC) && !defined(CONFIG_SPL_BUILD)
  438. int board_mmc_init(bd_t *bis)
  439. {
  440. return omap_mmc_init(0, 0, 0, -1, -1);
  441. }
  442. #endif
  443. #if defined(CONFIG_GENERIC_MMC)
  444. void board_mmc_power_init(void)
  445. {
  446. twl4030_power_mmc_init(0);
  447. }
  448. #endif
  449. #if defined(CONFIG_USB_EHCI) && !defined(CONFIG_SPL_BUILD)
  450. static struct omap_usbhs_board_data usbhs_bdata = {
  451. .port_mode[0] = OMAP_USBHS_PORT_MODE_UNUSED,
  452. .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY,
  453. .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED
  454. };
  455. #define GUMSTIX_GPIO_USBH_CPEN 168
  456. int ehci_hcd_init(int index, enum usb_init_type init,
  457. struct ehci_hccr **hccr, struct ehci_hcor **hcor)
  458. {
  459. /* Enable USB power */
  460. if (!gpio_request(GUMSTIX_GPIO_USBH_CPEN, "usbh_cpen"))
  461. gpio_direction_output(GUMSTIX_GPIO_USBH_CPEN, 1);
  462. return omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
  463. }
  464. int ehci_hcd_stop(void)
  465. {
  466. /* Disable USB power */
  467. gpio_set_value(GUMSTIX_GPIO_USBH_CPEN, 0);
  468. gpio_free(GUMSTIX_GPIO_USBH_CPEN);
  469. return omap_ehci_hcd_stop();
  470. }
  471. #endif /* CONFIG_USB_EHCI */