overo.c 10 KB

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