beagle.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  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 pr_debug(fmt, args...) debug(fmt, ##args)
  52. #define TWL4030_I2C_BUS 0
  53. #define EXPANSION_EEPROM_I2C_BUS 1
  54. #define EXPANSION_EEPROM_I2C_ADDRESS 0x50
  55. #define TINCANTOOLS_ZIPPY 0x01000100
  56. #define TINCANTOOLS_ZIPPY2 0x02000100
  57. #define TINCANTOOLS_TRAINER 0x04000100
  58. #define TINCANTOOLS_SHOWDOG 0x03000100
  59. #define KBADC_BEAGLEFPGA 0x01000600
  60. #define LW_BEAGLETOUCH 0x01000700
  61. #define BRAINMUX_LCDOG 0x01000800
  62. #define BRAINMUX_LCDOGTOUCH 0x02000800
  63. #define BBTOYS_WIFI 0x01000B00
  64. #define BBTOYS_VGA 0x02000B00
  65. #define BBTOYS_LCD 0x03000B00
  66. #define BCT_BRETTL3 0x01000F00
  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. 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. 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. /*
  210. * Configure DSS to display background color on DVID
  211. * Configure VENC to display color bar on S-Video
  212. */
  213. void beagle_display_init(void)
  214. {
  215. omap3_dss_venc_config(&venc_config_std_tv, VENC_HEIGHT, VENC_WIDTH);
  216. switch (get_board_revision()) {
  217. case REVISION_AXBX:
  218. case REVISION_CX:
  219. case REVISION_C4:
  220. omap3_dss_panel_config(&dvid_cfg);
  221. break;
  222. case REVISION_XM_A:
  223. case REVISION_XM_B:
  224. case REVISION_XM_C:
  225. default:
  226. omap3_dss_panel_config(&dvid_cfg_xm);
  227. break;
  228. }
  229. }
  230. /*
  231. * Routine: misc_init_r
  232. * Description: Configure board specific parts
  233. */
  234. int misc_init_r(void)
  235. {
  236. struct gpio *gpio5_base = (struct gpio *)OMAP34XX_GPIO5_BASE;
  237. struct gpio *gpio6_base = (struct gpio *)OMAP34XX_GPIO6_BASE;
  238. struct control_prog_io *prog_io_base = (struct control_prog_io *)OMAP34XX_CTRL_BASE;
  239. /* Enable i2c2 pullup resisters */
  240. writel(~(PRG_I2C2_PULLUPRESX), &prog_io_base->io1);
  241. switch (get_board_revision()) {
  242. case REVISION_AXBX:
  243. printf("Beagle Rev Ax/Bx\n");
  244. setenv("beaglerev", "AxBx");
  245. break;
  246. case REVISION_CX:
  247. printf("Beagle Rev C1/C2/C3\n");
  248. setenv("beaglerev", "Cx");
  249. MUX_BEAGLE_C();
  250. break;
  251. case REVISION_C4:
  252. printf("Beagle Rev C4\n");
  253. setenv("beaglerev", "C4");
  254. MUX_BEAGLE_C();
  255. /* Set VAUX2 to 1.8V for EHCI PHY */
  256. twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
  257. TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
  258. TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
  259. TWL4030_PM_RECEIVER_DEV_GRP_P1);
  260. break;
  261. case REVISION_XM_A:
  262. printf("Beagle xM Rev A\n");
  263. setenv("beaglerev", "xMA");
  264. MUX_BEAGLE_XM();
  265. /* Set VAUX2 to 1.8V for EHCI PHY */
  266. twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
  267. TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
  268. TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
  269. TWL4030_PM_RECEIVER_DEV_GRP_P1);
  270. break;
  271. case REVISION_XM_B:
  272. printf("Beagle xM Rev B\n");
  273. setenv("beaglerev", "xMB");
  274. MUX_BEAGLE_XM();
  275. /* Set VAUX2 to 1.8V for EHCI PHY */
  276. twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
  277. TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
  278. TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
  279. TWL4030_PM_RECEIVER_DEV_GRP_P1);
  280. break;
  281. case REVISION_XM_C:
  282. printf("Beagle xM Rev C\n");
  283. setenv("beaglerev", "xMC");
  284. MUX_BEAGLE_XM();
  285. /* Set VAUX2 to 1.8V for EHCI PHY */
  286. twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
  287. TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
  288. TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
  289. TWL4030_PM_RECEIVER_DEV_GRP_P1);
  290. break;
  291. default:
  292. printf("Beagle unknown 0x%02x\n", get_board_revision());
  293. MUX_BEAGLE_XM();
  294. /* Set VAUX2 to 1.8V for EHCI PHY */
  295. twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
  296. TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
  297. TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
  298. TWL4030_PM_RECEIVER_DEV_GRP_P1);
  299. }
  300. switch (get_expansion_id()) {
  301. case TINCANTOOLS_ZIPPY:
  302. printf("Recognized Tincantools Zippy board (rev %d %s)\n",
  303. expansion_config.revision,
  304. expansion_config.fab_revision);
  305. MUX_TINCANTOOLS_ZIPPY();
  306. setenv("buddy", "zippy");
  307. break;
  308. case TINCANTOOLS_ZIPPY2:
  309. printf("Recognized Tincantools Zippy2 board (rev %d %s)\n",
  310. expansion_config.revision,
  311. expansion_config.fab_revision);
  312. MUX_TINCANTOOLS_ZIPPY();
  313. setenv("buddy", "zippy2");
  314. break;
  315. case TINCANTOOLS_TRAINER:
  316. printf("Recognized Tincantools Trainer board (rev %d %s)\n",
  317. expansion_config.revision,
  318. expansion_config.fab_revision);
  319. MUX_TINCANTOOLS_ZIPPY();
  320. MUX_TINCANTOOLS_TRAINER();
  321. setenv("buddy", "trainer");
  322. break;
  323. case TINCANTOOLS_SHOWDOG:
  324. printf("Recognized Tincantools Showdow board (rev %d %s)\n",
  325. expansion_config.revision,
  326. expansion_config.fab_revision);
  327. /* Place holder for DSS2 definition for showdog lcd */
  328. setenv("defaultdisplay", "showdoglcd");
  329. setenv("buddy", "showdog");
  330. break;
  331. case KBADC_BEAGLEFPGA:
  332. printf("Recognized KBADC Beagle FPGA board\n");
  333. MUX_KBADC_BEAGLEFPGA();
  334. setenv("buddy", "beaglefpga");
  335. break;
  336. case LW_BEAGLETOUCH:
  337. printf("Recognized Liquidware BeagleTouch board\n");
  338. setenv("buddy", "beagletouch");
  339. break;
  340. case BRAINMUX_LCDOG:
  341. printf("Recognized Brainmux LCDog board\n");
  342. setenv("buddy", "lcdog");
  343. break;
  344. case BRAINMUX_LCDOGTOUCH:
  345. printf("Recognized Brainmux LCDog Touch board\n");
  346. setenv("buddy", "lcdogtouch");
  347. break;
  348. case BBTOYS_WIFI:
  349. printf("Recognized BeagleBoardToys WiFi board\n");
  350. MUX_BBTOYS_WIFI()
  351. setenv("buddy", "bbtoys-wifi");
  352. break;;
  353. case BBTOYS_VGA:
  354. printf("Recognized BeagleBoardToys VGA board\n");
  355. break;;
  356. case BBTOYS_LCD:
  357. printf("Recognized BeagleBoardToys LCD board\n");
  358. break;;
  359. case BCT_BRETTL3:
  360. printf("Recognized bct electronic GmbH brettl3 board\n");
  361. break;
  362. case BEAGLE_NO_EEPROM:
  363. printf("No EEPROM on expansion board\n");
  364. setenv("buddy", "none");
  365. break;
  366. default:
  367. printf("Unrecognized expansion board: %x\n",
  368. expansion_config.device_vendor);
  369. setenv("buddy", "unknown");
  370. }
  371. if (expansion_config.content == 1)
  372. setenv(expansion_config.env_var, expansion_config.env_setting);
  373. twl4030_power_init();
  374. switch (get_board_revision()) {
  375. case REVISION_XM_A:
  376. case REVISION_XM_B:
  377. twl4030_led_init(TWL4030_LED_LEDEN_LEDBON);
  378. break;
  379. default:
  380. twl4030_led_init(TWL4030_LED_LEDEN_LEDAON | TWL4030_LED_LEDEN_LEDBON);
  381. break;
  382. }
  383. /* Set GPIO states before they are made outputs */
  384. writel(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1,
  385. &gpio6_base->setdataout);
  386. writel(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 |
  387. GPIO15 | GPIO14 | GPIO13 | GPIO12, &gpio5_base->setdataout);
  388. /* Configure GPIOs to output */
  389. writel(~(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1), &gpio6_base->oe);
  390. writel(~(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 |
  391. GPIO15 | GPIO14 | GPIO13 | GPIO12), &gpio5_base->oe);
  392. dieid_num_r();
  393. beagle_display_init();
  394. omap3_dss_enable();
  395. return 0;
  396. }
  397. /*
  398. * Routine: set_muxconf_regs
  399. * Description: Setting up the configuration Mux registers specific to the
  400. * hardware. Many pins need to be moved from protect to primary
  401. * mode.
  402. */
  403. void set_muxconf_regs(void)
  404. {
  405. MUX_BEAGLE();
  406. }
  407. #if defined(CONFIG_GENERIC_MMC) && !defined(CONFIG_SPL_BUILD)
  408. int board_mmc_init(bd_t *bis)
  409. {
  410. omap_mmc_init(0);
  411. return 0;
  412. }
  413. #endif
  414. #ifdef CONFIG_USB_EHCI
  415. /* Call usb_stop() before starting the kernel */
  416. void show_boot_progress(int val)
  417. {
  418. if(val == 15)
  419. usb_stop();
  420. }
  421. static struct omap_usbhs_board_data usbhs_bdata = {
  422. .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY,
  423. .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY,
  424. .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED
  425. };
  426. int ehci_hcd_init(void)
  427. {
  428. return omap_ehci_hcd_init(&usbhs_bdata);
  429. }
  430. int ehci_hcd_stop(void)
  431. {
  432. return omap_ehci_hcd_stop();
  433. }
  434. #endif /* CONFIG_USB_EHCI */
  435. #ifndef CONFIG_SPL_BUILD
  436. /*
  437. * This command returns the status of the user button on beagle xM
  438. * Input - none
  439. * Returns - 1 if button is held down
  440. * 0 if button is not held down
  441. */
  442. int do_userbutton(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  443. {
  444. int button = 0;
  445. int gpio;
  446. /*
  447. * pass address parameter as argv[0] (aka command name),
  448. * and all remaining args
  449. */
  450. switch (get_board_revision()) {
  451. case REVISION_AXBX:
  452. case REVISION_CX:
  453. case REVISION_C4:
  454. gpio = 7;
  455. break;
  456. case REVISION_XM_A:
  457. case REVISION_XM_B:
  458. case REVISION_XM_C:
  459. default:
  460. gpio = 4;
  461. break;
  462. }
  463. gpio_request(gpio, "");
  464. gpio_direction_input(gpio);
  465. printf("The user button is currently ");
  466. if (gpio_get_value(gpio))
  467. {
  468. button = 1;
  469. printf("PRESSED.\n");
  470. }
  471. else
  472. {
  473. button = 0;
  474. printf("NOT pressed.\n");
  475. }
  476. return !button;
  477. }
  478. /* -------------------------------------------------------------------- */
  479. U_BOOT_CMD(
  480. userbutton, CONFIG_SYS_MAXARGS, 1, do_userbutton,
  481. "Return the status of the BeagleBoard USER button",
  482. ""
  483. );
  484. #endif