beagle.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. /*
  2. * (C) Copyright 2004-2008
  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 <asm/io.h>
  38. #include <asm/arch/mmc_host_def.h>
  39. #include <asm/arch/mux.h>
  40. #include <asm/arch/sys_proto.h>
  41. #include <asm/arch/gpio.h>
  42. #include <asm/mach-types.h>
  43. #ifdef CONFIG_USB_EHCI
  44. #include <usb.h>
  45. #include <asm/arch/clocks.h>
  46. #include <asm/arch/clocks_omap3.h>
  47. #include <asm/arch/ehci_omap3.h>
  48. /* from drivers/usb/host/ehci-core.h */
  49. extern struct ehci_hccr *hccr;
  50. extern volatile struct ehci_hcor *hcor;
  51. #endif
  52. #include "beagle.h"
  53. #include <command.h>
  54. #define pr_debug(fmt, args...) debug(fmt, ##args)
  55. #define TWL4030_I2C_BUS 0
  56. #define EXPANSION_EEPROM_I2C_BUS 1
  57. #define EXPANSION_EEPROM_I2C_ADDRESS 0x50
  58. #define TINCANTOOLS_ZIPPY 0x01000100
  59. #define TINCANTOOLS_ZIPPY2 0x02000100
  60. #define TINCANTOOLS_TRAINER 0x04000100
  61. #define TINCANTOOLS_SHOWDOG 0x03000100
  62. #define KBADC_BEAGLEFPGA 0x01000600
  63. #define LW_BEAGLETOUCH 0x01000700
  64. #define BRAINMUX_LCDOG 0x01000800
  65. #define BRAINMUX_LCDOGTOUCH 0x02000800
  66. #define BBTOYS_WIFI 0x01000B00
  67. #define BBTOYS_VGA 0x02000B00
  68. #define BBTOYS_LCD 0x03000B00
  69. #define BEAGLE_NO_EEPROM 0xffffffff
  70. DECLARE_GLOBAL_DATA_PTR;
  71. static struct {
  72. unsigned int device_vendor;
  73. unsigned char revision;
  74. unsigned char content;
  75. char fab_revision[8];
  76. char env_var[16];
  77. char env_setting[64];
  78. } expansion_config;
  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_OMAP3_BEAGLE;
  88. /* boot param addr */
  89. gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
  90. #if defined(CONFIG_STATUS_LED) && defined(STATUS_LED_BOOT)
  91. status_led_set (STATUS_LED_BOOT, STATUS_LED_ON);
  92. #endif
  93. return 0;
  94. }
  95. /*
  96. * Routine: get_board_revision
  97. * Description: Detect if we are running on a Beagle revision Ax/Bx,
  98. * C1/2/3, C4 or xM. This can be done by reading
  99. * the level of GPIO173, GPIO172 and GPIO171. This should
  100. * result in
  101. * GPIO173, GPIO172, GPIO171: 1 1 1 => Ax/Bx
  102. * GPIO173, GPIO172, GPIO171: 1 1 0 => C1/2/3
  103. * GPIO173, GPIO172, GPIO171: 1 0 1 => C4
  104. * GPIO173, GPIO172, GPIO171: 0 0 0 => xM
  105. */
  106. int get_board_revision(void)
  107. {
  108. int revision;
  109. if (!omap_request_gpio(171) &&
  110. !omap_request_gpio(172) &&
  111. !omap_request_gpio(173)) {
  112. omap_set_gpio_direction(171, 1);
  113. omap_set_gpio_direction(172, 1);
  114. omap_set_gpio_direction(173, 1);
  115. revision = omap_get_gpio_datain(173) << 2 |
  116. omap_get_gpio_datain(172) << 1 |
  117. omap_get_gpio_datain(171);
  118. omap_free_gpio(171);
  119. omap_free_gpio(172);
  120. omap_free_gpio(173);
  121. } else {
  122. printf("Error: unable to acquire board revision GPIOs\n");
  123. revision = -1;
  124. }
  125. return revision;
  126. }
  127. /*
  128. * Routine: get_expansion_id
  129. * Description: This function checks for expansion board by checking I2C
  130. * bus 1 for the availability of an AT24C01B serial EEPROM.
  131. * returns the device_vendor field from the EEPROM
  132. */
  133. unsigned int get_expansion_id(void)
  134. {
  135. i2c_set_bus_num(EXPANSION_EEPROM_I2C_BUS);
  136. /* return BEAGLE_NO_EEPROM if eeprom doesn't respond */
  137. if (i2c_probe(EXPANSION_EEPROM_I2C_ADDRESS) == 1) {
  138. i2c_set_bus_num(TWL4030_I2C_BUS);
  139. return BEAGLE_NO_EEPROM;
  140. }
  141. /* read configuration data */
  142. i2c_read(EXPANSION_EEPROM_I2C_ADDRESS, 0, 1, (u8 *)&expansion_config,
  143. sizeof(expansion_config));
  144. i2c_set_bus_num(TWL4030_I2C_BUS);
  145. return expansion_config.device_vendor;
  146. }
  147. /*
  148. * Configure DSS to display background color on DVID
  149. * Configure VENC to display color bar on S-Video
  150. */
  151. void beagle_display_init(void)
  152. {
  153. omap3_dss_venc_config(&venc_config_std_tv, VENC_HEIGHT, VENC_WIDTH);
  154. switch (get_board_revision()) {
  155. case REVISION_AXBX:
  156. case REVISION_CX:
  157. case REVISION_C4:
  158. omap3_dss_panel_config(&dvid_cfg);
  159. break;
  160. case REVISION_XM_A:
  161. case REVISION_XM_B:
  162. case REVISION_XM_C:
  163. default:
  164. omap3_dss_panel_config(&dvid_cfg_xm);
  165. break;
  166. }
  167. }
  168. /*
  169. * Routine: misc_init_r
  170. * Description: Configure board specific parts
  171. */
  172. int misc_init_r(void)
  173. {
  174. struct gpio *gpio5_base = (struct gpio *)OMAP34XX_GPIO5_BASE;
  175. struct gpio *gpio6_base = (struct gpio *)OMAP34XX_GPIO6_BASE;
  176. struct control_prog_io *prog_io_base = (struct control_prog_io *)OMAP34XX_CTRL_BASE;
  177. /* Enable i2c2 pullup resisters */
  178. writel(~(PRG_I2C2_PULLUPRESX), &prog_io_base->io1);
  179. switch (get_board_revision()) {
  180. case REVISION_AXBX:
  181. printf("Beagle Rev Ax/Bx\n");
  182. setenv("beaglerev", "AxBx");
  183. break;
  184. case REVISION_CX:
  185. printf("Beagle Rev C1/C2/C3\n");
  186. setenv("beaglerev", "Cx");
  187. MUX_BEAGLE_C();
  188. break;
  189. case REVISION_C4:
  190. printf("Beagle Rev C4\n");
  191. setenv("beaglerev", "C4");
  192. MUX_BEAGLE_C();
  193. /* Set VAUX2 to 1.8V for EHCI PHY */
  194. twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
  195. TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
  196. TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
  197. TWL4030_PM_RECEIVER_DEV_GRP_P1);
  198. break;
  199. case REVISION_XM_A:
  200. printf("Beagle xM Rev A\n");
  201. setenv("beaglerev", "xMA");
  202. MUX_BEAGLE_XM();
  203. /* Set VAUX2 to 1.8V for EHCI PHY */
  204. twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
  205. TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
  206. TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
  207. TWL4030_PM_RECEIVER_DEV_GRP_P1);
  208. break;
  209. case REVISION_XM_B:
  210. printf("Beagle xM Rev B\n");
  211. setenv("beaglerev", "xMB");
  212. MUX_BEAGLE_XM();
  213. /* Set VAUX2 to 1.8V for EHCI PHY */
  214. twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
  215. TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
  216. TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
  217. TWL4030_PM_RECEIVER_DEV_GRP_P1);
  218. break;
  219. case REVISION_XM_C:
  220. printf("Beagle xM Rev C\n");
  221. setenv("beaglerev", "xMC");
  222. MUX_BEAGLE_XM();
  223. /* Set VAUX2 to 1.8V for EHCI PHY */
  224. twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
  225. TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
  226. TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
  227. TWL4030_PM_RECEIVER_DEV_GRP_P1);
  228. break;
  229. default:
  230. printf("Beagle unknown 0x%02x\n", get_board_revision());
  231. MUX_BEAGLE_XM();
  232. /* Set VAUX2 to 1.8V for EHCI PHY */
  233. twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
  234. TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
  235. TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
  236. TWL4030_PM_RECEIVER_DEV_GRP_P1);
  237. }
  238. switch (get_expansion_id()) {
  239. case TINCANTOOLS_ZIPPY:
  240. printf("Recognized Tincantools Zippy board (rev %d %s)\n",
  241. expansion_config.revision,
  242. expansion_config.fab_revision);
  243. MUX_TINCANTOOLS_ZIPPY();
  244. setenv("buddy", "zippy");
  245. break;
  246. case TINCANTOOLS_ZIPPY2:
  247. printf("Recognized Tincantools Zippy2 board (rev %d %s)\n",
  248. expansion_config.revision,
  249. expansion_config.fab_revision);
  250. MUX_TINCANTOOLS_ZIPPY();
  251. setenv("buddy", "zippy2");
  252. break;
  253. case TINCANTOOLS_TRAINER:
  254. printf("Recognized Tincantools Trainer board (rev %d %s)\n",
  255. expansion_config.revision,
  256. expansion_config.fab_revision);
  257. MUX_TINCANTOOLS_ZIPPY();
  258. MUX_TINCANTOOLS_TRAINER();
  259. setenv("buddy", "trainer");
  260. break;
  261. case TINCANTOOLS_SHOWDOG:
  262. printf("Recognized Tincantools Showdow board (rev %d %s)\n",
  263. expansion_config.revision,
  264. expansion_config.fab_revision);
  265. /* Place holder for DSS2 definition for showdog lcd */
  266. setenv("defaultdisplay", "showdoglcd");
  267. setenv("buddy", "showdog");
  268. break;
  269. case KBADC_BEAGLEFPGA:
  270. printf("Recognized KBADC Beagle FPGA board\n");
  271. MUX_KBADC_BEAGLEFPGA();
  272. setenv("buddy", "beaglefpga");
  273. break;
  274. case LW_BEAGLETOUCH:
  275. printf("Recognized Liquidware BeagleTouch board\n");
  276. setenv("buddy", "beagletouch");
  277. break;
  278. case BRAINMUX_LCDOG:
  279. printf("Recognized Brainmux LCDog board\n");
  280. setenv("buddy", "lcdog");
  281. break;
  282. case BRAINMUX_LCDOGTOUCH:
  283. printf("Recognized Brainmux LCDog Touch board\n");
  284. setenv("buddy", "lcdogtouch");
  285. break;
  286. case BBTOYS_WIFI:
  287. printf("Recognized BeagleBoardToys WiFi board\n");
  288. MUX_BBTOYS_WIFI()
  289. setenv("buddy", "bbtoys-wifi");
  290. break;;
  291. case BBTOYS_VGA:
  292. printf("Recognized BeagleBoardToys VGA board\n");
  293. break;;
  294. case BBTOYS_LCD:
  295. printf("Recognized BeagleBoardToys LCD board\n");
  296. break;;
  297. case BEAGLE_NO_EEPROM:
  298. printf("No EEPROM on expansion board\n");
  299. setenv("buddy", "none");
  300. break;
  301. default:
  302. printf("Unrecognized expansion board: %x\n",
  303. expansion_config.device_vendor);
  304. setenv("buddy", "unknown");
  305. }
  306. if (expansion_config.content == 1)
  307. setenv(expansion_config.env_var, expansion_config.env_setting);
  308. twl4030_power_init();
  309. twl4030_led_init(TWL4030_LED_LEDEN_LEDAON | TWL4030_LED_LEDEN_LEDBON);
  310. /* Set GPIO states before they are made outputs */
  311. writel(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1,
  312. &gpio6_base->setdataout);
  313. writel(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 |
  314. GPIO15 | GPIO14 | GPIO13 | GPIO12, &gpio5_base->setdataout);
  315. /* Configure GPIOs to output */
  316. writel(~(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1), &gpio6_base->oe);
  317. writel(~(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 |
  318. GPIO15 | GPIO14 | GPIO13 | GPIO12), &gpio5_base->oe);
  319. dieid_num_r();
  320. beagle_display_init();
  321. omap3_dss_enable();
  322. return 0;
  323. }
  324. /*
  325. * Routine: set_muxconf_regs
  326. * Description: Setting up the configuration Mux registers specific to the
  327. * hardware. Many pins need to be moved from protect to primary
  328. * mode.
  329. */
  330. void set_muxconf_regs(void)
  331. {
  332. MUX_BEAGLE();
  333. }
  334. #ifdef CONFIG_GENERIC_MMC
  335. int board_mmc_init(bd_t *bis)
  336. {
  337. omap_mmc_init(0);
  338. return 0;
  339. }
  340. #endif
  341. #ifdef CONFIG_USB_EHCI
  342. #define GPIO_PHY_RESET 147
  343. /* Reset is needed otherwise the kernel-driver will throw an error. */
  344. int ehci_hcd_stop(void)
  345. {
  346. pr_debug("Resetting OMAP3 EHCI\n");
  347. omap_set_gpio_dataout(GPIO_PHY_RESET, 0);
  348. writel(OMAP_UHH_SYSCONFIG_SOFTRESET, OMAP3_UHH_BASE + OMAP_UHH_SYSCONFIG);
  349. /* disable USB clocks */
  350. struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
  351. sr32(&prcm_base->iclken_usbhost, 0, 1, 0);
  352. sr32(&prcm_base->fclken_usbhost, 0, 2, 0);
  353. sr32(&prcm_base->iclken3_core, 2, 1, 0);
  354. sr32(&prcm_base->fclken3_core, 2, 1, 0);
  355. return 0;
  356. }
  357. /* Call usb_stop() before starting the kernel */
  358. void show_boot_progress(int val)
  359. {
  360. if(val == 15)
  361. usb_stop();
  362. }
  363. /*
  364. * Initialize the OMAP3 EHCI controller and PHY on the BeagleBoard.
  365. * Based on "drivers/usb/host/ehci-omap.c" from Linux 2.6.37.
  366. * See there for additional Copyrights.
  367. */
  368. int ehci_hcd_init(void)
  369. {
  370. pr_debug("Initializing OMAP3 ECHI\n");
  371. /* Put the PHY in RESET */
  372. omap_request_gpio(GPIO_PHY_RESET);
  373. omap_set_gpio_direction(GPIO_PHY_RESET, 0);
  374. omap_set_gpio_dataout(GPIO_PHY_RESET, 0);
  375. /* Hold the PHY in RESET for enough time till DIR is high */
  376. /* Refer: ISSUE1 */
  377. udelay(10);
  378. struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
  379. /* Enable USBHOST_L3_ICLK (USBHOST_MICLK) */
  380. sr32(&prcm_base->iclken_usbhost, 0, 1, 1);
  381. /*
  382. * Enable USBHOST_48M_FCLK (USBHOST_FCLK1)
  383. * and USBHOST_120M_FCLK (USBHOST_FCLK2)
  384. */
  385. sr32(&prcm_base->fclken_usbhost, 0, 2, 3);
  386. /* Enable USBTTL_ICLK */
  387. sr32(&prcm_base->iclken3_core, 2, 1, 1);
  388. /* Enable USBTTL_FCLK */
  389. sr32(&prcm_base->fclken3_core, 2, 1, 1);
  390. pr_debug("USB clocks enabled\n");
  391. /* perform TLL soft reset, and wait until reset is complete */
  392. writel(OMAP_USBTLL_SYSCONFIG_SOFTRESET,
  393. OMAP3_USBTLL_BASE + OMAP_USBTLL_SYSCONFIG);
  394. /* Wait for TLL reset to complete */
  395. while (!(readl(OMAP3_USBTLL_BASE + OMAP_USBTLL_SYSSTATUS)
  396. & OMAP_USBTLL_SYSSTATUS_RESETDONE));
  397. pr_debug("TLL reset done\n");
  398. writel(OMAP_USBTLL_SYSCONFIG_ENAWAKEUP |
  399. OMAP_USBTLL_SYSCONFIG_SIDLEMODE |
  400. OMAP_USBTLL_SYSCONFIG_CACTIVITY,
  401. OMAP3_USBTLL_BASE + OMAP_USBTLL_SYSCONFIG);
  402. /* Put UHH in NoIdle/NoStandby mode */
  403. writel(OMAP_UHH_SYSCONFIG_ENAWAKEUP
  404. | OMAP_UHH_SYSCONFIG_SIDLEMODE
  405. | OMAP_UHH_SYSCONFIG_CACTIVITY
  406. | OMAP_UHH_SYSCONFIG_MIDLEMODE,
  407. OMAP3_UHH_BASE + OMAP_UHH_SYSCONFIG);
  408. /* setup burst configurations */
  409. writel(OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN
  410. | OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN
  411. | OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN,
  412. OMAP3_UHH_BASE + OMAP_UHH_HOSTCONFIG);
  413. /*
  414. * Refer ISSUE1:
  415. * Hold the PHY in RESET for enough time till
  416. * PHY is settled and ready
  417. */
  418. udelay(10);
  419. omap_set_gpio_dataout(GPIO_PHY_RESET, 1);
  420. hccr = (struct ehci_hccr *)(OMAP3_EHCI_BASE);
  421. hcor = (struct ehci_hcor *)(OMAP3_EHCI_BASE + 0x10);
  422. pr_debug("OMAP3 EHCI init done\n");
  423. return 0;
  424. }
  425. #endif /* CONFIG_USB_EHCI */
  426. /*
  427. * This command returns the status of the user button on beagle xM
  428. * Input - none
  429. * Returns - 1 if button is held down
  430. * 0 if button is not held down
  431. */
  432. int do_userbutton (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  433. {
  434. int button = 0;
  435. int gpio;
  436. /*
  437. * pass address parameter as argv[0] (aka command name),
  438. * and all remaining args
  439. */
  440. switch (get_board_revision()) {
  441. case REVISION_AXBX:
  442. case REVISION_CX:
  443. case REVISION_C4:
  444. gpio = 7;
  445. break;
  446. case REVISION_XM_A:
  447. case REVISION_XM_B:
  448. case REVISION_XM_C:
  449. default:
  450. gpio = 4;
  451. break;
  452. }
  453. omap_request_gpio(gpio);
  454. omap_set_gpio_direction(gpio, 1);
  455. printf("The user button is currently ");
  456. if(omap_get_gpio_datain(gpio))
  457. {
  458. button = 1;
  459. printf("PRESSED.\n");
  460. }
  461. else
  462. {
  463. button = 0;
  464. printf("NOT pressed.\n");
  465. }
  466. omap_free_gpio(gpio);
  467. return !button;
  468. }
  469. /* -------------------------------------------------------------------- */
  470. U_BOOT_CMD(
  471. userbutton, CONFIG_SYS_MAXARGS, 1, do_userbutton,
  472. "Return the status of the BeagleBoard USER button",
  473. ""
  474. );