beagle.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. /*
  2. * (C) Copyright 2004-2011
  3. * Texas Instruments, <www.ti.com>
  4. *
  5. * Author :
  6. * Sunil Kumar <sunilsaini05@gmail.com>
  7. * Shashi Ranjan <shashiranjanmca05@gmail.com>
  8. *
  9. * Derived from Beagle Board and 3430 SDP code by
  10. * Richard Woodruff <r-woodruff2@ti.com>
  11. * Syed Mohammed Khasim <khasim@ti.com>
  12. *
  13. *
  14. * See file CREDITS for list of people who contributed to this
  15. * project.
  16. *
  17. * This program is free software; you can redistribute it and/or
  18. * modify it under the terms of the GNU General Public License as
  19. * published by the Free Software Foundation; either version 2 of
  20. * the License, or (at your option) any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU General Public License
  28. * along with this program; if not, write to the Free Software
  29. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  30. * MA 02111-1307 USA
  31. */
  32. #include <common.h>
  33. #ifdef CONFIG_STATUS_LED
  34. #include <status_led.h>
  35. #endif
  36. #include <twl4030.h>
  37. #include <linux/mtd/nand.h>
  38. #include <asm/io.h>
  39. #include <asm/arch/mmc_host_def.h>
  40. #include <asm/arch/mux.h>
  41. #include <asm/arch/mem.h>
  42. #include <asm/arch/sys_proto.h>
  43. #include <asm/gpio.h>
  44. #include <asm/mach-types.h>
  45. #include "beagle.h"
  46. #include <command.h>
  47. #ifdef CONFIG_USB_EHCI
  48. #include <usb.h>
  49. #include <asm/ehci-omap.h>
  50. #endif
  51. #define TWL4030_I2C_BUS 0
  52. #define EXPANSION_EEPROM_I2C_BUS 1
  53. #define EXPANSION_EEPROM_I2C_ADDRESS 0x50
  54. #define TINCANTOOLS_ZIPPY 0x01000100
  55. #define TINCANTOOLS_ZIPPY2 0x02000100
  56. #define TINCANTOOLS_TRAINER 0x04000100
  57. #define TINCANTOOLS_SHOWDOG 0x03000100
  58. #define KBADC_BEAGLEFPGA 0x01000600
  59. #define LW_BEAGLETOUCH 0x01000700
  60. #define BRAINMUX_LCDOG 0x01000800
  61. #define BRAINMUX_LCDOGTOUCH 0x02000800
  62. #define BBTOYS_WIFI 0x01000B00
  63. #define BBTOYS_VGA 0x02000B00
  64. #define BBTOYS_LCD 0x03000B00
  65. #define BCT_BRETTL3 0x01000F00
  66. #define BCT_BRETTL4 0x02000F00
  67. #define BEAGLE_NO_EEPROM 0xffffffff
  68. DECLARE_GLOBAL_DATA_PTR;
  69. static struct {
  70. unsigned int device_vendor;
  71. unsigned char revision;
  72. unsigned char content;
  73. char fab_revision[8];
  74. char env_var[16];
  75. char env_setting[64];
  76. } expansion_config;
  77. /*
  78. * Routine: board_init
  79. * Description: Early hardware init.
  80. */
  81. int board_init(void)
  82. {
  83. gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
  84. /* board id for Linux */
  85. gd->bd->bi_arch_number = MACH_TYPE_OMAP3_BEAGLE;
  86. /* boot param addr */
  87. gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
  88. #if defined(CONFIG_STATUS_LED) && defined(STATUS_LED_BOOT)
  89. status_led_set (STATUS_LED_BOOT, STATUS_LED_ON);
  90. #endif
  91. return 0;
  92. }
  93. /*
  94. * Routine: get_board_revision
  95. * Description: Detect if we are running on a Beagle revision Ax/Bx,
  96. * C1/2/3, C4 or xM. This can be done by reading
  97. * the level of GPIO173, GPIO172 and GPIO171. This should
  98. * result in
  99. * GPIO173, GPIO172, GPIO171: 1 1 1 => Ax/Bx
  100. * GPIO173, GPIO172, GPIO171: 1 1 0 => C1/2/3
  101. * GPIO173, GPIO172, GPIO171: 1 0 1 => C4
  102. * GPIO173, GPIO172, GPIO171: 0 0 0 => xM
  103. */
  104. static int get_board_revision(void)
  105. {
  106. int revision;
  107. if (!gpio_request(171, "") &&
  108. !gpio_request(172, "") &&
  109. !gpio_request(173, "")) {
  110. gpio_direction_input(171);
  111. gpio_direction_input(172);
  112. gpio_direction_input(173);
  113. revision = gpio_get_value(173) << 2 |
  114. gpio_get_value(172) << 1 |
  115. gpio_get_value(171);
  116. } else {
  117. printf("Error: unable to acquire board revision GPIOs\n");
  118. revision = -1;
  119. }
  120. return revision;
  121. }
  122. #ifdef CONFIG_SPL_BUILD
  123. /*
  124. * Routine: get_board_mem_timings
  125. * Description: If we use SPL then there is no x-loader nor config header
  126. * so we have to setup the DDR timings ourself on both banks.
  127. */
  128. void get_board_mem_timings(u32 *mcfg, u32 *ctrla, u32 *ctrlb, u32 *rfr_ctrl,
  129. u32 *mr)
  130. {
  131. int pop_mfr, pop_id;
  132. /*
  133. * We need to identify what PoP memory is on the board so that
  134. * we know what timings to use. If we can't identify it then
  135. * we know it's an xM. To map the ID values please see nand_ids.c
  136. */
  137. identify_nand_chip(&pop_mfr, &pop_id);
  138. *mr = MICRON_V_MR_165;
  139. switch (get_board_revision()) {
  140. case REVISION_C4:
  141. if (pop_mfr == NAND_MFR_STMICRO && pop_id == 0xba) {
  142. /* 512MB DDR */
  143. *mcfg = NUMONYX_V_MCFG_165(512 << 20);
  144. *ctrla = NUMONYX_V_ACTIMA_165;
  145. *ctrlb = NUMONYX_V_ACTIMB_165;
  146. *rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
  147. break;
  148. } else if (pop_mfr == NAND_MFR_MICRON && pop_id == 0xba) {
  149. /* Beagleboard Rev C4, 512MB Nand/256MB DDR*/
  150. *mcfg = MICRON_V_MCFG_165(128 << 20);
  151. *ctrla = MICRON_V_ACTIMA_165;
  152. *ctrlb = MICRON_V_ACTIMB_165;
  153. *rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
  154. break;
  155. } else if (pop_mfr == NAND_MFR_MICRON && pop_id == 0xbc) {
  156. /* Beagleboard Rev C5, 256MB DDR */
  157. *mcfg = MICRON_V_MCFG_200(256 << 20);
  158. *ctrla = MICRON_V_ACTIMA_200;
  159. *ctrlb = MICRON_V_ACTIMB_200;
  160. *rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
  161. break;
  162. }
  163. case REVISION_XM_A:
  164. case REVISION_XM_B:
  165. case REVISION_XM_C:
  166. if (pop_mfr == 0) {
  167. /* 256MB DDR */
  168. *mcfg = MICRON_V_MCFG_200(256 << 20);
  169. *ctrla = MICRON_V_ACTIMA_200;
  170. *ctrlb = MICRON_V_ACTIMB_200;
  171. *rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
  172. } else {
  173. /* 512MB DDR */
  174. *mcfg = NUMONYX_V_MCFG_165(512 << 20);
  175. *ctrla = NUMONYX_V_ACTIMA_165;
  176. *ctrlb = NUMONYX_V_ACTIMB_165;
  177. *rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
  178. }
  179. break;
  180. default:
  181. /* Assume 128MB and Micron/165MHz timings to be safe */
  182. *mcfg = MICRON_V_MCFG_165(128 << 20);
  183. *ctrla = MICRON_V_ACTIMA_165;
  184. *ctrlb = MICRON_V_ACTIMB_165;
  185. *rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
  186. }
  187. }
  188. #endif
  189. /*
  190. * Routine: get_expansion_id
  191. * Description: This function checks for expansion board by checking I2C
  192. * bus 1 for the availability of an AT24C01B serial EEPROM.
  193. * returns the device_vendor field from the EEPROM
  194. */
  195. static unsigned int get_expansion_id(void)
  196. {
  197. i2c_set_bus_num(EXPANSION_EEPROM_I2C_BUS);
  198. /* return BEAGLE_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 BEAGLE_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. #ifdef CONFIG_VIDEO_OMAP3
  210. /*
  211. * Configure DSS to display background color on DVID
  212. * Configure VENC to display color bar on S-Video
  213. */
  214. static void beagle_display_init(void)
  215. {
  216. omap3_dss_venc_config(&venc_config_std_tv, VENC_HEIGHT, VENC_WIDTH);
  217. switch (get_board_revision()) {
  218. case REVISION_AXBX:
  219. case REVISION_CX:
  220. case REVISION_C4:
  221. omap3_dss_panel_config(&dvid_cfg);
  222. break;
  223. case REVISION_XM_A:
  224. case REVISION_XM_B:
  225. case REVISION_XM_C:
  226. default:
  227. omap3_dss_panel_config(&dvid_cfg_xm);
  228. break;
  229. }
  230. }
  231. /*
  232. * Enable DVI power
  233. */
  234. static void beagle_dvi_pup(void)
  235. {
  236. uchar val;
  237. switch (get_board_revision()) {
  238. case REVISION_AXBX:
  239. case REVISION_CX:
  240. case REVISION_C4:
  241. case REVISION_XM_A:
  242. gpio_request(170, "");
  243. gpio_direction_output(170, 0);
  244. gpio_set_value(170, 1);
  245. break;
  246. case REVISION_XM_B:
  247. case REVISION_XM_C:
  248. default:
  249. #define GPIODATADIR1 (TWL4030_BASEADD_GPIO+3)
  250. #define GPIODATAOUT1 (TWL4030_BASEADD_GPIO+6)
  251. i2c_read(TWL4030_CHIP_GPIO, GPIODATADIR1, 1, &val, 1);
  252. val |= 4;
  253. i2c_write(TWL4030_CHIP_GPIO, GPIODATADIR1, 1, &val, 1);
  254. i2c_read(TWL4030_CHIP_GPIO, GPIODATAOUT1, 1, &val, 1);
  255. val |= 4;
  256. i2c_write(TWL4030_CHIP_GPIO, GPIODATAOUT1, 1, &val, 1);
  257. break;
  258. }
  259. }
  260. #endif
  261. /*
  262. * Routine: misc_init_r
  263. * Description: Configure board specific parts
  264. */
  265. int misc_init_r(void)
  266. {
  267. struct gpio *gpio5_base = (struct gpio *)OMAP34XX_GPIO5_BASE;
  268. struct gpio *gpio6_base = (struct gpio *)OMAP34XX_GPIO6_BASE;
  269. struct control_prog_io *prog_io_base = (struct control_prog_io *)OMAP34XX_CTRL_BASE;
  270. /* Enable i2c2 pullup resisters */
  271. writel(~(PRG_I2C2_PULLUPRESX), &prog_io_base->io1);
  272. switch (get_board_revision()) {
  273. case REVISION_AXBX:
  274. printf("Beagle Rev Ax/Bx\n");
  275. setenv("beaglerev", "AxBx");
  276. break;
  277. case REVISION_CX:
  278. printf("Beagle Rev C1/C2/C3\n");
  279. setenv("beaglerev", "Cx");
  280. MUX_BEAGLE_C();
  281. break;
  282. case REVISION_C4:
  283. printf("Beagle Rev C4\n");
  284. setenv("beaglerev", "C4");
  285. MUX_BEAGLE_C();
  286. /* Set VAUX2 to 1.8V for EHCI PHY */
  287. twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
  288. TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
  289. TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
  290. TWL4030_PM_RECEIVER_DEV_GRP_P1);
  291. break;
  292. case REVISION_XM_A:
  293. printf("Beagle xM Rev A\n");
  294. setenv("beaglerev", "xMA");
  295. MUX_BEAGLE_XM();
  296. /* Set VAUX2 to 1.8V for EHCI PHY */
  297. twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
  298. TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
  299. TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
  300. TWL4030_PM_RECEIVER_DEV_GRP_P1);
  301. break;
  302. case REVISION_XM_B:
  303. printf("Beagle xM Rev B\n");
  304. setenv("beaglerev", "xMB");
  305. MUX_BEAGLE_XM();
  306. /* Set VAUX2 to 1.8V for EHCI PHY */
  307. twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
  308. TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
  309. TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
  310. TWL4030_PM_RECEIVER_DEV_GRP_P1);
  311. break;
  312. case REVISION_XM_C:
  313. printf("Beagle xM Rev C\n");
  314. setenv("beaglerev", "xMC");
  315. MUX_BEAGLE_XM();
  316. /* Set VAUX2 to 1.8V for EHCI PHY */
  317. twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
  318. TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
  319. TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
  320. TWL4030_PM_RECEIVER_DEV_GRP_P1);
  321. break;
  322. default:
  323. printf("Beagle unknown 0x%02x\n", get_board_revision());
  324. MUX_BEAGLE_XM();
  325. /* Set VAUX2 to 1.8V for EHCI PHY */
  326. twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
  327. TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
  328. TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
  329. TWL4030_PM_RECEIVER_DEV_GRP_P1);
  330. }
  331. switch (get_expansion_id()) {
  332. case TINCANTOOLS_ZIPPY:
  333. printf("Recognized Tincantools Zippy board (rev %d %s)\n",
  334. expansion_config.revision,
  335. expansion_config.fab_revision);
  336. MUX_TINCANTOOLS_ZIPPY();
  337. setenv("buddy", "zippy");
  338. break;
  339. case TINCANTOOLS_ZIPPY2:
  340. printf("Recognized Tincantools Zippy2 board (rev %d %s)\n",
  341. expansion_config.revision,
  342. expansion_config.fab_revision);
  343. MUX_TINCANTOOLS_ZIPPY();
  344. setenv("buddy", "zippy2");
  345. break;
  346. case TINCANTOOLS_TRAINER:
  347. printf("Recognized Tincantools Trainer board (rev %d %s)\n",
  348. expansion_config.revision,
  349. expansion_config.fab_revision);
  350. MUX_TINCANTOOLS_ZIPPY();
  351. MUX_TINCANTOOLS_TRAINER();
  352. setenv("buddy", "trainer");
  353. break;
  354. case TINCANTOOLS_SHOWDOG:
  355. printf("Recognized Tincantools Showdow board (rev %d %s)\n",
  356. expansion_config.revision,
  357. expansion_config.fab_revision);
  358. /* Place holder for DSS2 definition for showdog lcd */
  359. setenv("defaultdisplay", "showdoglcd");
  360. setenv("buddy", "showdog");
  361. break;
  362. case KBADC_BEAGLEFPGA:
  363. printf("Recognized KBADC Beagle FPGA board\n");
  364. MUX_KBADC_BEAGLEFPGA();
  365. setenv("buddy", "beaglefpga");
  366. break;
  367. case LW_BEAGLETOUCH:
  368. printf("Recognized Liquidware BeagleTouch board\n");
  369. setenv("buddy", "beagletouch");
  370. break;
  371. case BRAINMUX_LCDOG:
  372. printf("Recognized Brainmux LCDog board\n");
  373. setenv("buddy", "lcdog");
  374. break;
  375. case BRAINMUX_LCDOGTOUCH:
  376. printf("Recognized Brainmux LCDog Touch board\n");
  377. setenv("buddy", "lcdogtouch");
  378. break;
  379. case BBTOYS_WIFI:
  380. printf("Recognized BeagleBoardToys WiFi board\n");
  381. MUX_BBTOYS_WIFI()
  382. setenv("buddy", "bbtoys-wifi");
  383. break;;
  384. case BBTOYS_VGA:
  385. printf("Recognized BeagleBoardToys VGA board\n");
  386. break;;
  387. case BBTOYS_LCD:
  388. printf("Recognized BeagleBoardToys LCD board\n");
  389. break;;
  390. case BCT_BRETTL3:
  391. printf("Recognized bct electronic GmbH brettl3 board\n");
  392. break;
  393. case BCT_BRETTL4:
  394. printf("Recognized bct electronic GmbH brettl4 board\n");
  395. break;
  396. case BEAGLE_NO_EEPROM:
  397. printf("No EEPROM on expansion board\n");
  398. setenv("buddy", "none");
  399. break;
  400. default:
  401. printf("Unrecognized expansion board: %x\n",
  402. expansion_config.device_vendor);
  403. setenv("buddy", "unknown");
  404. }
  405. if (expansion_config.content == 1)
  406. setenv(expansion_config.env_var, expansion_config.env_setting);
  407. twl4030_power_init();
  408. switch (get_board_revision()) {
  409. case REVISION_XM_A:
  410. case REVISION_XM_B:
  411. twl4030_led_init(TWL4030_LED_LEDEN_LEDBON);
  412. break;
  413. default:
  414. twl4030_led_init(TWL4030_LED_LEDEN_LEDAON | TWL4030_LED_LEDEN_LEDBON);
  415. break;
  416. }
  417. /* Set GPIO states before they are made outputs */
  418. writel(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1,
  419. &gpio6_base->setdataout);
  420. writel(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 |
  421. GPIO15 | GPIO14 | GPIO13 | GPIO12, &gpio5_base->setdataout);
  422. /* Configure GPIOs to output */
  423. writel(~(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1), &gpio6_base->oe);
  424. writel(~(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 |
  425. GPIO15 | GPIO14 | GPIO13 | GPIO12), &gpio5_base->oe);
  426. dieid_num_r();
  427. #ifdef CONFIG_VIDEO_OMAP3
  428. beagle_dvi_pup();
  429. beagle_display_init();
  430. omap3_dss_enable();
  431. #endif
  432. return 0;
  433. }
  434. /*
  435. * Routine: set_muxconf_regs
  436. * Description: Setting up the configuration Mux registers specific to the
  437. * hardware. Many pins need to be moved from protect to primary
  438. * mode.
  439. */
  440. void set_muxconf_regs(void)
  441. {
  442. MUX_BEAGLE();
  443. }
  444. #if defined(CONFIG_GENERIC_MMC) && !defined(CONFIG_SPL_BUILD)
  445. int board_mmc_init(bd_t *bis)
  446. {
  447. omap_mmc_init(0, 0, 0);
  448. return 0;
  449. }
  450. #endif
  451. #ifdef CONFIG_USB_EHCI
  452. /* Call usb_stop() before starting the kernel */
  453. void show_boot_progress(int val)
  454. {
  455. if (val == BOOTSTAGE_ID_RUN_OS)
  456. usb_stop();
  457. }
  458. static struct omap_usbhs_board_data usbhs_bdata = {
  459. .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY,
  460. .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY,
  461. .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED
  462. };
  463. int ehci_hcd_init(void)
  464. {
  465. return omap_ehci_hcd_init(&usbhs_bdata);
  466. }
  467. int ehci_hcd_stop(void)
  468. {
  469. return omap_ehci_hcd_stop();
  470. }
  471. #endif /* CONFIG_USB_EHCI */