beagle.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  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. * Enable DVI power
  232. */
  233. static void beagle_dvi_pup(void)
  234. {
  235. uchar val;
  236. switch (get_board_revision()) {
  237. case REVISION_AXBX:
  238. case REVISION_CX:
  239. case REVISION_C4:
  240. case REVISION_XM_A:
  241. gpio_request(170, "");
  242. gpio_direction_output(170, 0);
  243. gpio_set_value(170, 1);
  244. break;
  245. case REVISION_XM_B:
  246. case REVISION_XM_C:
  247. default:
  248. #define GPIODATADIR1 (TWL4030_BASEADD_GPIO+3)
  249. #define GPIODATAOUT1 (TWL4030_BASEADD_GPIO+6)
  250. i2c_read(TWL4030_CHIP_GPIO, GPIODATADIR1, 1, &val, 1);
  251. val |= 4;
  252. i2c_write(TWL4030_CHIP_GPIO, GPIODATADIR1, 1, &val, 1);
  253. i2c_read(TWL4030_CHIP_GPIO, GPIODATAOUT1, 1, &val, 1);
  254. val |= 4;
  255. i2c_write(TWL4030_CHIP_GPIO, GPIODATAOUT1, 1, &val, 1);
  256. break;
  257. }
  258. }
  259. /*
  260. * Routine: misc_init_r
  261. * Description: Configure board specific parts
  262. */
  263. int misc_init_r(void)
  264. {
  265. struct gpio *gpio5_base = (struct gpio *)OMAP34XX_GPIO5_BASE;
  266. struct gpio *gpio6_base = (struct gpio *)OMAP34XX_GPIO6_BASE;
  267. struct control_prog_io *prog_io_base = (struct control_prog_io *)OMAP34XX_CTRL_BASE;
  268. /* Enable i2c2 pullup resisters */
  269. writel(~(PRG_I2C2_PULLUPRESX), &prog_io_base->io1);
  270. switch (get_board_revision()) {
  271. case REVISION_AXBX:
  272. printf("Beagle Rev Ax/Bx\n");
  273. setenv("beaglerev", "AxBx");
  274. break;
  275. case REVISION_CX:
  276. printf("Beagle Rev C1/C2/C3\n");
  277. setenv("beaglerev", "Cx");
  278. MUX_BEAGLE_C();
  279. break;
  280. case REVISION_C4:
  281. printf("Beagle Rev C4\n");
  282. setenv("beaglerev", "C4");
  283. MUX_BEAGLE_C();
  284. /* Set VAUX2 to 1.8V for EHCI PHY */
  285. twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
  286. TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
  287. TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
  288. TWL4030_PM_RECEIVER_DEV_GRP_P1);
  289. break;
  290. case REVISION_XM_A:
  291. printf("Beagle xM Rev A\n");
  292. setenv("beaglerev", "xMA");
  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. break;
  300. case REVISION_XM_B:
  301. printf("Beagle xM Rev B\n");
  302. setenv("beaglerev", "xMB");
  303. MUX_BEAGLE_XM();
  304. /* Set VAUX2 to 1.8V for EHCI PHY */
  305. twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
  306. TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
  307. TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
  308. TWL4030_PM_RECEIVER_DEV_GRP_P1);
  309. break;
  310. case REVISION_XM_C:
  311. printf("Beagle xM Rev C\n");
  312. setenv("beaglerev", "xMC");
  313. MUX_BEAGLE_XM();
  314. /* Set VAUX2 to 1.8V for EHCI PHY */
  315. twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
  316. TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
  317. TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
  318. TWL4030_PM_RECEIVER_DEV_GRP_P1);
  319. break;
  320. default:
  321. printf("Beagle unknown 0x%02x\n", get_board_revision());
  322. MUX_BEAGLE_XM();
  323. /* Set VAUX2 to 1.8V for EHCI PHY */
  324. twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
  325. TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
  326. TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
  327. TWL4030_PM_RECEIVER_DEV_GRP_P1);
  328. }
  329. switch (get_expansion_id()) {
  330. case TINCANTOOLS_ZIPPY:
  331. printf("Recognized Tincantools Zippy board (rev %d %s)\n",
  332. expansion_config.revision,
  333. expansion_config.fab_revision);
  334. MUX_TINCANTOOLS_ZIPPY();
  335. setenv("buddy", "zippy");
  336. break;
  337. case TINCANTOOLS_ZIPPY2:
  338. printf("Recognized Tincantools Zippy2 board (rev %d %s)\n",
  339. expansion_config.revision,
  340. expansion_config.fab_revision);
  341. MUX_TINCANTOOLS_ZIPPY();
  342. setenv("buddy", "zippy2");
  343. break;
  344. case TINCANTOOLS_TRAINER:
  345. printf("Recognized Tincantools Trainer board (rev %d %s)\n",
  346. expansion_config.revision,
  347. expansion_config.fab_revision);
  348. MUX_TINCANTOOLS_ZIPPY();
  349. MUX_TINCANTOOLS_TRAINER();
  350. setenv("buddy", "trainer");
  351. break;
  352. case TINCANTOOLS_SHOWDOG:
  353. printf("Recognized Tincantools Showdow board (rev %d %s)\n",
  354. expansion_config.revision,
  355. expansion_config.fab_revision);
  356. /* Place holder for DSS2 definition for showdog lcd */
  357. setenv("defaultdisplay", "showdoglcd");
  358. setenv("buddy", "showdog");
  359. break;
  360. case KBADC_BEAGLEFPGA:
  361. printf("Recognized KBADC Beagle FPGA board\n");
  362. MUX_KBADC_BEAGLEFPGA();
  363. setenv("buddy", "beaglefpga");
  364. break;
  365. case LW_BEAGLETOUCH:
  366. printf("Recognized Liquidware BeagleTouch board\n");
  367. setenv("buddy", "beagletouch");
  368. break;
  369. case BRAINMUX_LCDOG:
  370. printf("Recognized Brainmux LCDog board\n");
  371. setenv("buddy", "lcdog");
  372. break;
  373. case BRAINMUX_LCDOGTOUCH:
  374. printf("Recognized Brainmux LCDog Touch board\n");
  375. setenv("buddy", "lcdogtouch");
  376. break;
  377. case BBTOYS_WIFI:
  378. printf("Recognized BeagleBoardToys WiFi board\n");
  379. MUX_BBTOYS_WIFI()
  380. setenv("buddy", "bbtoys-wifi");
  381. break;;
  382. case BBTOYS_VGA:
  383. printf("Recognized BeagleBoardToys VGA board\n");
  384. break;;
  385. case BBTOYS_LCD:
  386. printf("Recognized BeagleBoardToys LCD board\n");
  387. break;;
  388. case BCT_BRETTL3:
  389. printf("Recognized bct electronic GmbH brettl3 board\n");
  390. break;
  391. case BEAGLE_NO_EEPROM:
  392. printf("No EEPROM on expansion board\n");
  393. setenv("buddy", "none");
  394. break;
  395. default:
  396. printf("Unrecognized expansion board: %x\n",
  397. expansion_config.device_vendor);
  398. setenv("buddy", "unknown");
  399. }
  400. if (expansion_config.content == 1)
  401. setenv(expansion_config.env_var, expansion_config.env_setting);
  402. twl4030_power_init();
  403. switch (get_board_revision()) {
  404. case REVISION_XM_A:
  405. case REVISION_XM_B:
  406. twl4030_led_init(TWL4030_LED_LEDEN_LEDBON);
  407. break;
  408. default:
  409. twl4030_led_init(TWL4030_LED_LEDEN_LEDAON | TWL4030_LED_LEDEN_LEDBON);
  410. break;
  411. }
  412. /* Set GPIO states before they are made outputs */
  413. writel(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1,
  414. &gpio6_base->setdataout);
  415. writel(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 |
  416. GPIO15 | GPIO14 | GPIO13 | GPIO12, &gpio5_base->setdataout);
  417. /* Configure GPIOs to output */
  418. writel(~(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1), &gpio6_base->oe);
  419. writel(~(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 |
  420. GPIO15 | GPIO14 | GPIO13 | GPIO12), &gpio5_base->oe);
  421. dieid_num_r();
  422. beagle_dvi_pup();
  423. beagle_display_init();
  424. omap3_dss_enable();
  425. return 0;
  426. }
  427. /*
  428. * Routine: set_muxconf_regs
  429. * Description: Setting up the configuration Mux registers specific to the
  430. * hardware. Many pins need to be moved from protect to primary
  431. * mode.
  432. */
  433. void set_muxconf_regs(void)
  434. {
  435. MUX_BEAGLE();
  436. }
  437. #if defined(CONFIG_GENERIC_MMC) && !defined(CONFIG_SPL_BUILD)
  438. int board_mmc_init(bd_t *bis)
  439. {
  440. omap_mmc_init(0, 0, 0);
  441. return 0;
  442. }
  443. #endif
  444. #ifdef CONFIG_USB_EHCI
  445. /* Call usb_stop() before starting the kernel */
  446. void show_boot_progress(int val)
  447. {
  448. if (val == BOOTSTAGE_ID_RUN_OS)
  449. usb_stop();
  450. }
  451. static struct omap_usbhs_board_data usbhs_bdata = {
  452. .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY,
  453. .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY,
  454. .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED
  455. };
  456. int ehci_hcd_init(void)
  457. {
  458. return omap_ehci_hcd_init(&usbhs_bdata);
  459. }
  460. int ehci_hcd_stop(void)
  461. {
  462. return omap_ehci_hcd_stop();
  463. }
  464. #endif /* CONFIG_USB_EHCI */