overo.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  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/rawnand.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_HCD
  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. .base = OMAP34XX_UART3,
  63. .reg_shift = 2,
  64. .clock = V_NS16550_CLK,
  65. .fcr = UART_FCR_DEFVAL,
  66. };
  67. U_BOOT_DEVICE(overo_uart) = {
  68. "ns16550_serial",
  69. &overo_serial
  70. };
  71. /*
  72. * Routine: get_sdio2_config
  73. * Description: Return information about the wifi module connection
  74. * Returns 0 if the module connects though a level translator
  75. * Returns 1 if the module connects directly
  76. */
  77. int get_sdio2_config(void)
  78. {
  79. int sdio_direct;
  80. if (!gpio_request(130, "") && !gpio_request(139, "")) {
  81. gpio_direction_output(130, 0);
  82. gpio_direction_input(139);
  83. sdio_direct = 1;
  84. gpio_set_value(130, 0);
  85. if (gpio_get_value(139) == 0) {
  86. gpio_set_value(130, 1);
  87. if (gpio_get_value(139) == 1)
  88. sdio_direct = 0;
  89. }
  90. gpio_direction_input(130);
  91. } else {
  92. puts("Error: unable to acquire sdio2 clk GPIOs\n");
  93. sdio_direct = -1;
  94. }
  95. return sdio_direct;
  96. }
  97. /*
  98. * Routine: get_expansion_id
  99. * Description: This function checks for expansion board by checking I2C
  100. * bus 2 for the availability of an AT24C01B serial EEPROM.
  101. * returns the device_vendor field from the EEPROM
  102. */
  103. unsigned int get_expansion_id(void)
  104. {
  105. if (expansion_config.device_vendor != 0x0)
  106. return expansion_config.device_vendor;
  107. i2c_set_bus_num(EXPANSION_EEPROM_I2C_BUS);
  108. /* return GUMSTIX_NO_EEPROM if eeprom doesn't respond */
  109. if (i2c_probe(EXPANSION_EEPROM_I2C_ADDRESS) == 1) {
  110. i2c_set_bus_num(TWL4030_I2C_BUS);
  111. return GUMSTIX_NO_EEPROM;
  112. }
  113. /* read configuration data */
  114. i2c_read(EXPANSION_EEPROM_I2C_ADDRESS, 0, 1, (u8 *)&expansion_config,
  115. sizeof(expansion_config));
  116. i2c_set_bus_num(TWL4030_I2C_BUS);
  117. return expansion_config.device_vendor;
  118. }
  119. /*
  120. * Routine: misc_init_r
  121. * Description: Configure board specific parts
  122. */
  123. int misc_init_r(void)
  124. {
  125. unsigned int expansion_id;
  126. twl4030_power_init();
  127. twl4030_led_init(TWL4030_LED_LEDEN_LEDAON | TWL4030_LED_LEDEN_LEDBON);
  128. printf("Board revision: %d\n", get_board_revision());
  129. switch (get_sdio2_config()) {
  130. case 0:
  131. puts("Tranceiver detected on mmc2\n");
  132. MUX_OVERO_SDIO2_TRANSCEIVER();
  133. break;
  134. case 1:
  135. puts("Direct connection on mmc2\n");
  136. MUX_OVERO_SDIO2_DIRECT();
  137. break;
  138. default:
  139. puts("Unable to detect mmc2 connection type\n");
  140. }
  141. expansion_id = get_expansion_id();
  142. switch (expansion_id) {
  143. case GUMSTIX_SUMMIT:
  144. printf("Recognized Summit expansion board (rev %d %s)\n",
  145. expansion_config.revision,
  146. expansion_config.fab_revision);
  147. MUX_GUMSTIX();
  148. env_set("defaultdisplay", "dvi");
  149. env_set("expansionname", "summit");
  150. break;
  151. case GUMSTIX_TOBI:
  152. printf("Recognized Tobi expansion board (rev %d %s)\n",
  153. expansion_config.revision,
  154. expansion_config.fab_revision);
  155. MUX_GUMSTIX();
  156. env_set("defaultdisplay", "dvi");
  157. env_set("expansionname", "tobi");
  158. break;
  159. case GUMSTIX_TOBI_DUO:
  160. printf("Recognized Tobi Duo expansion board (rev %d %s)\n",
  161. expansion_config.revision,
  162. expansion_config.fab_revision);
  163. MUX_GUMSTIX();
  164. env_set("expansionname", "tobiduo");
  165. break;
  166. case GUMSTIX_PALO35:
  167. printf("Recognized Palo35 expansion board (rev %d %s)\n",
  168. expansion_config.revision,
  169. expansion_config.fab_revision);
  170. MUX_GUMSTIX();
  171. env_set("defaultdisplay", "lcd35");
  172. env_set("expansionname", "palo35");
  173. break;
  174. case GUMSTIX_PALO43:
  175. printf("Recognized Palo43 expansion board (rev %d %s)\n",
  176. expansion_config.revision,
  177. expansion_config.fab_revision);
  178. MUX_GUMSTIX();
  179. env_set("defaultdisplay", "lcd43");
  180. env_set("expansionname", "palo43");
  181. break;
  182. case GUMSTIX_CHESTNUT43:
  183. printf("Recognized Chestnut43 expansion board (rev %d %s)\n",
  184. expansion_config.revision,
  185. expansion_config.fab_revision);
  186. MUX_GUMSTIX();
  187. env_set("defaultdisplay", "lcd43");
  188. env_set("expansionname", "chestnut43");
  189. break;
  190. case GUMSTIX_PINTO:
  191. printf("Recognized Pinto expansion board (rev %d %s)\n",
  192. expansion_config.revision,
  193. expansion_config.fab_revision);
  194. MUX_GUMSTIX();
  195. break;
  196. case GUMSTIX_GALLOP43:
  197. printf("Recognized Gallop43 expansion board (rev %d %s)\n",
  198. expansion_config.revision,
  199. expansion_config.fab_revision);
  200. MUX_GUMSTIX();
  201. env_set("defaultdisplay", "lcd43");
  202. env_set("expansionname", "gallop43");
  203. break;
  204. case GUMSTIX_ALTO35:
  205. printf("Recognized Alto35 expansion board (rev %d %s)\n",
  206. expansion_config.revision,
  207. expansion_config.fab_revision);
  208. MUX_GUMSTIX();
  209. MUX_ALTO35();
  210. env_set("defaultdisplay", "lcd35");
  211. env_set("expansionname", "alto35");
  212. break;
  213. case GUMSTIX_STAGECOACH:
  214. printf("Recognized Stagecoach expansion board (rev %d %s)\n",
  215. expansion_config.revision,
  216. expansion_config.fab_revision);
  217. MUX_GUMSTIX();
  218. break;
  219. case GUMSTIX_THUMBO:
  220. printf("Recognized Thumbo expansion board (rev %d %s)\n",
  221. expansion_config.revision,
  222. expansion_config.fab_revision);
  223. MUX_GUMSTIX();
  224. break;
  225. case GUMSTIX_TURTLECORE:
  226. printf("Recognized Turtlecore expansion board (rev %d %s)\n",
  227. expansion_config.revision,
  228. expansion_config.fab_revision);
  229. MUX_GUMSTIX();
  230. break;
  231. case GUMSTIX_ARBOR43C:
  232. printf("Recognized Arbor43C expansion board (rev %d %s)\n",
  233. expansion_config.revision,
  234. expansion_config.fab_revision);
  235. MUX_GUMSTIX();
  236. MUX_ARBOR43C();
  237. env_set("defaultdisplay", "lcd43");
  238. env_set("expansionname", "arbor43c");
  239. break;
  240. case ETTUS_USRP_E:
  241. printf("Recognized Ettus Research USRP-E (rev %d %s)\n",
  242. expansion_config.revision,
  243. expansion_config.fab_revision);
  244. MUX_GUMSTIX();
  245. MUX_USRP_E();
  246. env_set("defaultdisplay", "dvi");
  247. break;
  248. case GUMSTIX_NO_EEPROM:
  249. case GUMSTIX_EMPTY_EEPROM:
  250. puts("No or empty EEPROM on expansion board\n");
  251. MUX_GUMSTIX();
  252. env_set("expansionname", "tobi");
  253. break;
  254. default:
  255. printf("Unrecognized expansion board 0x%08x\n", expansion_id);
  256. break;
  257. }
  258. if (expansion_config.content == 1)
  259. env_set(expansion_config.env_var, expansion_config.env_setting);
  260. omap_die_id_display();
  261. if (get_cpu_family() == CPU_OMAP34XX)
  262. env_set("boardname", "overo");
  263. else
  264. env_set("boardname", "overo-storm");
  265. return 0;
  266. }
  267. #if defined(CONFIG_CMD_NET)
  268. /* GPMC definitions for LAN9221 chips on Tobi expansion boards */
  269. static const u32 gpmc_lan_config[] = {
  270. NET_LAN9221_GPMC_CONFIG1,
  271. NET_LAN9221_GPMC_CONFIG2,
  272. NET_LAN9221_GPMC_CONFIG3,
  273. NET_LAN9221_GPMC_CONFIG4,
  274. NET_LAN9221_GPMC_CONFIG5,
  275. NET_LAN9221_GPMC_CONFIG6,
  276. /*CONFIG7- computed as params */
  277. };
  278. /*
  279. * Routine: setup_net_chip
  280. * Description: Setting up the configuration GPMC registers specific to the
  281. * Ethernet hardware.
  282. */
  283. static void setup_net_chip(void)
  284. {
  285. struct ctrl *ctrl_base = (struct ctrl *)OMAP34XX_CTRL_BASE;
  286. /* Enable off mode for NWE in PADCONF_GPMC_NWE register */
  287. writew(readw(&ctrl_base ->gpmc_nwe) | 0x0E00, &ctrl_base->gpmc_nwe);
  288. /* Enable off mode for NOE in PADCONF_GPMC_NADV_ALE register */
  289. writew(readw(&ctrl_base->gpmc_noe) | 0x0E00, &ctrl_base->gpmc_noe);
  290. /* Enable off mode for ALE in PADCONF_GPMC_NADV_ALE register */
  291. writew(readw(&ctrl_base->gpmc_nadv_ale) | 0x0E00,
  292. &ctrl_base->gpmc_nadv_ale);
  293. }
  294. /*
  295. * Routine: reset_net_chip
  296. * Description: Reset the Ethernet hardware.
  297. */
  298. static void reset_net_chip(void)
  299. {
  300. /* Make GPIO 64 as output pin and send a magic pulse through it */
  301. if (!gpio_request(64, "")) {
  302. gpio_direction_output(64, 0);
  303. gpio_set_value(64, 1);
  304. udelay(1);
  305. gpio_set_value(64, 0);
  306. udelay(1);
  307. gpio_set_value(64, 1);
  308. }
  309. }
  310. int board_eth_init(bd_t *bis)
  311. {
  312. unsigned int expansion_id;
  313. int rc = 0;
  314. #ifdef CONFIG_SMC911X
  315. expansion_id = get_expansion_id();
  316. switch (expansion_id) {
  317. case GUMSTIX_TOBI_DUO:
  318. /* second lan chip */
  319. enable_gpmc_cs_config(gpmc_lan_config, &gpmc_cfg->cs[4],
  320. 0x2B000000, GPMC_SIZE_16M);
  321. /* no break */
  322. case GUMSTIX_TOBI:
  323. case GUMSTIX_CHESTNUT43:
  324. case GUMSTIX_STAGECOACH:
  325. case GUMSTIX_NO_EEPROM:
  326. case GUMSTIX_EMPTY_EEPROM:
  327. /* first lan chip */
  328. enable_gpmc_cs_config(gpmc_lan_config, &gpmc_cfg->cs[5],
  329. 0x2C000000, GPMC_SIZE_16M);
  330. setup_net_chip();
  331. reset_net_chip();
  332. rc = smc911x_initialize(0, CONFIG_SMC911X_BASE);
  333. break;
  334. default:
  335. break;
  336. }
  337. #endif
  338. return rc;
  339. }
  340. #endif
  341. #if defined(CONFIG_MMC)
  342. int board_mmc_init(bd_t *bis)
  343. {
  344. return omap_mmc_init(0, 0, 0, -1, -1);
  345. }
  346. #endif
  347. #if defined(CONFIG_MMC)
  348. void board_mmc_power_init(void)
  349. {
  350. twl4030_power_mmc_init(0);
  351. }
  352. #endif
  353. #if defined(CONFIG_USB_EHCI_HCD)
  354. static struct omap_usbhs_board_data usbhs_bdata = {
  355. .port_mode[0] = OMAP_USBHS_PORT_MODE_UNUSED,
  356. .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY,
  357. .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED
  358. };
  359. #define GUMSTIX_GPIO_USBH_CPEN 168
  360. int ehci_hcd_init(int index, enum usb_init_type init,
  361. struct ehci_hccr **hccr, struct ehci_hcor **hcor)
  362. {
  363. /* Enable USB power */
  364. if (!gpio_request(GUMSTIX_GPIO_USBH_CPEN, "usbh_cpen"))
  365. gpio_direction_output(GUMSTIX_GPIO_USBH_CPEN, 1);
  366. return omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
  367. }
  368. int ehci_hcd_stop(void)
  369. {
  370. /* Disable USB power */
  371. gpio_set_value(GUMSTIX_GPIO_USBH_CPEN, 0);
  372. gpio_free(GUMSTIX_GPIO_USBH_CPEN);
  373. return omap_ehci_hcd_stop();
  374. }
  375. #endif /* CONFIG_USB_EHCI_HCD */