beagle.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  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 BCT_BRETTL4 0x02000F00
  68. #define BEAGLE_NO_EEPROM 0xffffffff
  69. DECLARE_GLOBAL_DATA_PTR;
  70. static struct {
  71. unsigned int device_vendor;
  72. unsigned char revision;
  73. unsigned char content;
  74. char fab_revision[8];
  75. char env_var[16];
  76. char env_setting[64];
  77. } expansion_config;
  78. /*
  79. * Routine: board_init
  80. * Description: Early hardware init.
  81. */
  82. int board_init(void)
  83. {
  84. gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
  85. /* board id for Linux */
  86. gd->bd->bi_arch_number = MACH_TYPE_OMAP3_BEAGLE;
  87. /* boot param addr */
  88. gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
  89. #if defined(CONFIG_STATUS_LED) && defined(STATUS_LED_BOOT)
  90. status_led_set (STATUS_LED_BOOT, STATUS_LED_ON);
  91. #endif
  92. return 0;
  93. }
  94. /*
  95. * Routine: get_board_revision
  96. * Description: Detect if we are running on a Beagle revision Ax/Bx,
  97. * C1/2/3, C4 or xM. This can be done by reading
  98. * the level of GPIO173, GPIO172 and GPIO171. This should
  99. * result in
  100. * GPIO173, GPIO172, GPIO171: 1 1 1 => Ax/Bx
  101. * GPIO173, GPIO172, GPIO171: 1 1 0 => C1/2/3
  102. * GPIO173, GPIO172, GPIO171: 1 0 1 => C4
  103. * GPIO173, GPIO172, GPIO171: 0 0 0 => xM
  104. */
  105. static int get_board_revision(void)
  106. {
  107. int revision;
  108. if (!gpio_request(171, "") &&
  109. !gpio_request(172, "") &&
  110. !gpio_request(173, "")) {
  111. gpio_direction_input(171);
  112. gpio_direction_input(172);
  113. gpio_direction_input(173);
  114. revision = gpio_get_value(173) << 2 |
  115. gpio_get_value(172) << 1 |
  116. gpio_get_value(171);
  117. } else {
  118. printf("Error: unable to acquire board revision GPIOs\n");
  119. revision = -1;
  120. }
  121. return revision;
  122. }
  123. #ifdef CONFIG_SPL_BUILD
  124. /*
  125. * Routine: get_board_mem_timings
  126. * Description: If we use SPL then there is no x-loader nor config header
  127. * so we have to setup the DDR timings ourself on both banks.
  128. */
  129. void get_board_mem_timings(u32 *mcfg, u32 *ctrla, u32 *ctrlb, u32 *rfr_ctrl,
  130. u32 *mr)
  131. {
  132. int pop_mfr, pop_id;
  133. /*
  134. * We need to identify what PoP memory is on the board so that
  135. * we know what timings to use. If we can't identify it then
  136. * we know it's an xM. To map the ID values please see nand_ids.c
  137. */
  138. identify_nand_chip(&pop_mfr, &pop_id);
  139. *mr = MICRON_V_MR_165;
  140. switch (get_board_revision()) {
  141. case REVISION_C4:
  142. if (pop_mfr == NAND_MFR_STMICRO && pop_id == 0xba) {
  143. /* 512MB DDR */
  144. *mcfg = NUMONYX_V_MCFG_165(512 << 20);
  145. *ctrla = NUMONYX_V_ACTIMA_165;
  146. *ctrlb = NUMONYX_V_ACTIMB_165;
  147. *rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
  148. break;
  149. } else if (pop_mfr == NAND_MFR_MICRON && pop_id == 0xba) {
  150. /* Beagleboard Rev C4, 512MB Nand/256MB DDR*/
  151. *mcfg = MICRON_V_MCFG_165(128 << 20);
  152. *ctrla = MICRON_V_ACTIMA_165;
  153. *ctrlb = MICRON_V_ACTIMB_165;
  154. *rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
  155. break;
  156. } else if (pop_mfr == NAND_MFR_MICRON && pop_id == 0xbc) {
  157. /* Beagleboard Rev C5, 256MB DDR */
  158. *mcfg = MICRON_V_MCFG_200(256 << 20);
  159. *ctrla = MICRON_V_ACTIMA_200;
  160. *ctrlb = MICRON_V_ACTIMB_200;
  161. *rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
  162. break;
  163. }
  164. case REVISION_XM_A:
  165. case REVISION_XM_B:
  166. case REVISION_XM_C:
  167. if (pop_mfr == 0) {
  168. /* 256MB DDR */
  169. *mcfg = MICRON_V_MCFG_200(256 << 20);
  170. *ctrla = MICRON_V_ACTIMA_200;
  171. *ctrlb = MICRON_V_ACTIMB_200;
  172. *rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
  173. } else {
  174. /* 512MB DDR */
  175. *mcfg = NUMONYX_V_MCFG_165(512 << 20);
  176. *ctrla = NUMONYX_V_ACTIMA_165;
  177. *ctrlb = NUMONYX_V_ACTIMB_165;
  178. *rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
  179. }
  180. break;
  181. default:
  182. /* Assume 128MB and Micron/165MHz timings to be safe */
  183. *mcfg = MICRON_V_MCFG_165(128 << 20);
  184. *ctrla = MICRON_V_ACTIMA_165;
  185. *ctrlb = MICRON_V_ACTIMB_165;
  186. *rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
  187. }
  188. }
  189. #endif
  190. /*
  191. * Routine: get_expansion_id
  192. * Description: This function checks for expansion board by checking I2C
  193. * bus 1 for the availability of an AT24C01B serial EEPROM.
  194. * returns the device_vendor field from the EEPROM
  195. */
  196. static unsigned int get_expansion_id(void)
  197. {
  198. i2c_set_bus_num(EXPANSION_EEPROM_I2C_BUS);
  199. /* return BEAGLE_NO_EEPROM if eeprom doesn't respond */
  200. if (i2c_probe(EXPANSION_EEPROM_I2C_ADDRESS) == 1) {
  201. i2c_set_bus_num(TWL4030_I2C_BUS);
  202. return BEAGLE_NO_EEPROM;
  203. }
  204. /* read configuration data */
  205. i2c_read(EXPANSION_EEPROM_I2C_ADDRESS, 0, 1, (u8 *)&expansion_config,
  206. sizeof(expansion_config));
  207. i2c_set_bus_num(TWL4030_I2C_BUS);
  208. return expansion_config.device_vendor;
  209. }
  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. /*
  261. * Routine: misc_init_r
  262. * Description: Configure board specific parts
  263. */
  264. int misc_init_r(void)
  265. {
  266. struct gpio *gpio5_base = (struct gpio *)OMAP34XX_GPIO5_BASE;
  267. struct gpio *gpio6_base = (struct gpio *)OMAP34XX_GPIO6_BASE;
  268. struct control_prog_io *prog_io_base = (struct control_prog_io *)OMAP34XX_CTRL_BASE;
  269. /* Enable i2c2 pullup resisters */
  270. writel(~(PRG_I2C2_PULLUPRESX), &prog_io_base->io1);
  271. switch (get_board_revision()) {
  272. case REVISION_AXBX:
  273. printf("Beagle Rev Ax/Bx\n");
  274. setenv("beaglerev", "AxBx");
  275. break;
  276. case REVISION_CX:
  277. printf("Beagle Rev C1/C2/C3\n");
  278. setenv("beaglerev", "Cx");
  279. MUX_BEAGLE_C();
  280. break;
  281. case REVISION_C4:
  282. printf("Beagle Rev C4\n");
  283. setenv("beaglerev", "C4");
  284. MUX_BEAGLE_C();
  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. case REVISION_XM_A:
  292. printf("Beagle xM Rev A\n");
  293. setenv("beaglerev", "xMA");
  294. MUX_BEAGLE_XM();
  295. /* Set VAUX2 to 1.8V for EHCI PHY */
  296. twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
  297. TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
  298. TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
  299. TWL4030_PM_RECEIVER_DEV_GRP_P1);
  300. break;
  301. case REVISION_XM_B:
  302. printf("Beagle xM Rev B\n");
  303. setenv("beaglerev", "xMB");
  304. MUX_BEAGLE_XM();
  305. /* Set VAUX2 to 1.8V for EHCI PHY */
  306. twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
  307. TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
  308. TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
  309. TWL4030_PM_RECEIVER_DEV_GRP_P1);
  310. break;
  311. case REVISION_XM_C:
  312. printf("Beagle xM Rev C\n");
  313. setenv("beaglerev", "xMC");
  314. MUX_BEAGLE_XM();
  315. /* Set VAUX2 to 1.8V for EHCI PHY */
  316. twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
  317. TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
  318. TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
  319. TWL4030_PM_RECEIVER_DEV_GRP_P1);
  320. break;
  321. default:
  322. printf("Beagle unknown 0x%02x\n", get_board_revision());
  323. MUX_BEAGLE_XM();
  324. /* Set VAUX2 to 1.8V for EHCI PHY */
  325. twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
  326. TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
  327. TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
  328. TWL4030_PM_RECEIVER_DEV_GRP_P1);
  329. }
  330. switch (get_expansion_id()) {
  331. case TINCANTOOLS_ZIPPY:
  332. printf("Recognized Tincantools Zippy board (rev %d %s)\n",
  333. expansion_config.revision,
  334. expansion_config.fab_revision);
  335. MUX_TINCANTOOLS_ZIPPY();
  336. setenv("buddy", "zippy");
  337. break;
  338. case TINCANTOOLS_ZIPPY2:
  339. printf("Recognized Tincantools Zippy2 board (rev %d %s)\n",
  340. expansion_config.revision,
  341. expansion_config.fab_revision);
  342. MUX_TINCANTOOLS_ZIPPY();
  343. setenv("buddy", "zippy2");
  344. break;
  345. case TINCANTOOLS_TRAINER:
  346. printf("Recognized Tincantools Trainer board (rev %d %s)\n",
  347. expansion_config.revision,
  348. expansion_config.fab_revision);
  349. MUX_TINCANTOOLS_ZIPPY();
  350. MUX_TINCANTOOLS_TRAINER();
  351. setenv("buddy", "trainer");
  352. break;
  353. case TINCANTOOLS_SHOWDOG:
  354. printf("Recognized Tincantools Showdow board (rev %d %s)\n",
  355. expansion_config.revision,
  356. expansion_config.fab_revision);
  357. /* Place holder for DSS2 definition for showdog lcd */
  358. setenv("defaultdisplay", "showdoglcd");
  359. setenv("buddy", "showdog");
  360. break;
  361. case KBADC_BEAGLEFPGA:
  362. printf("Recognized KBADC Beagle FPGA board\n");
  363. MUX_KBADC_BEAGLEFPGA();
  364. setenv("buddy", "beaglefpga");
  365. break;
  366. case LW_BEAGLETOUCH:
  367. printf("Recognized Liquidware BeagleTouch board\n");
  368. setenv("buddy", "beagletouch");
  369. break;
  370. case BRAINMUX_LCDOG:
  371. printf("Recognized Brainmux LCDog board\n");
  372. setenv("buddy", "lcdog");
  373. break;
  374. case BRAINMUX_LCDOGTOUCH:
  375. printf("Recognized Brainmux LCDog Touch board\n");
  376. setenv("buddy", "lcdogtouch");
  377. break;
  378. case BBTOYS_WIFI:
  379. printf("Recognized BeagleBoardToys WiFi board\n");
  380. MUX_BBTOYS_WIFI()
  381. setenv("buddy", "bbtoys-wifi");
  382. break;;
  383. case BBTOYS_VGA:
  384. printf("Recognized BeagleBoardToys VGA board\n");
  385. break;;
  386. case BBTOYS_LCD:
  387. printf("Recognized BeagleBoardToys LCD board\n");
  388. break;;
  389. case BCT_BRETTL3:
  390. printf("Recognized bct electronic GmbH brettl3 board\n");
  391. break;
  392. case BCT_BRETTL4:
  393. printf("Recognized bct electronic GmbH brettl4 board\n");
  394. break;
  395. case BEAGLE_NO_EEPROM:
  396. printf("No EEPROM on expansion board\n");
  397. setenv("buddy", "none");
  398. break;
  399. default:
  400. printf("Unrecognized expansion board: %x\n",
  401. expansion_config.device_vendor);
  402. setenv("buddy", "unknown");
  403. }
  404. if (expansion_config.content == 1)
  405. setenv(expansion_config.env_var, expansion_config.env_setting);
  406. twl4030_power_init();
  407. switch (get_board_revision()) {
  408. case REVISION_XM_A:
  409. case REVISION_XM_B:
  410. twl4030_led_init(TWL4030_LED_LEDEN_LEDBON);
  411. break;
  412. default:
  413. twl4030_led_init(TWL4030_LED_LEDEN_LEDAON | TWL4030_LED_LEDEN_LEDBON);
  414. break;
  415. }
  416. /* Set GPIO states before they are made outputs */
  417. writel(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1,
  418. &gpio6_base->setdataout);
  419. writel(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 |
  420. GPIO15 | GPIO14 | GPIO13 | GPIO12, &gpio5_base->setdataout);
  421. /* Configure GPIOs to output */
  422. writel(~(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1), &gpio6_base->oe);
  423. writel(~(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 |
  424. GPIO15 | GPIO14 | GPIO13 | GPIO12), &gpio5_base->oe);
  425. dieid_num_r();
  426. beagle_dvi_pup();
  427. beagle_display_init();
  428. omap3_dss_enable();
  429. return 0;
  430. }
  431. /*
  432. * Routine: set_muxconf_regs
  433. * Description: Setting up the configuration Mux registers specific to the
  434. * hardware. Many pins need to be moved from protect to primary
  435. * mode.
  436. */
  437. void set_muxconf_regs(void)
  438. {
  439. MUX_BEAGLE();
  440. }
  441. #if defined(CONFIG_GENERIC_MMC) && !defined(CONFIG_SPL_BUILD)
  442. int board_mmc_init(bd_t *bis)
  443. {
  444. omap_mmc_init(0, 0, 0);
  445. return 0;
  446. }
  447. #endif
  448. #ifdef CONFIG_USB_EHCI
  449. /* Call usb_stop() before starting the kernel */
  450. void show_boot_progress(int val)
  451. {
  452. if (val == BOOTSTAGE_ID_RUN_OS)
  453. usb_stop();
  454. }
  455. static struct omap_usbhs_board_data usbhs_bdata = {
  456. .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY,
  457. .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY,
  458. .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED
  459. };
  460. int ehci_hcd_init(void)
  461. {
  462. return omap_ehci_hcd_init(&usbhs_bdata);
  463. }
  464. int ehci_hcd_stop(void)
  465. {
  466. return omap_ehci_hcd_stop();
  467. }
  468. #endif /* CONFIG_USB_EHCI */