beagle.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  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. * Routine: misc_init_r
  149. * Description: Configure board specific parts
  150. */
  151. int misc_init_r(void)
  152. {
  153. struct gpio *gpio5_base = (struct gpio *)OMAP34XX_GPIO5_BASE;
  154. struct gpio *gpio6_base = (struct gpio *)OMAP34XX_GPIO6_BASE;
  155. struct control_prog_io *prog_io_base = (struct control_prog_io *)OMAP34XX_CTRL_BASE;
  156. /* Enable i2c2 pullup resisters */
  157. writel(~(PRG_I2C2_PULLUPRESX), &prog_io_base->io1);
  158. switch (get_board_revision()) {
  159. case REVISION_AXBX:
  160. printf("Beagle Rev Ax/Bx\n");
  161. setenv("beaglerev", "AxBx");
  162. break;
  163. case REVISION_CX:
  164. printf("Beagle Rev C1/C2/C3\n");
  165. setenv("beaglerev", "Cx");
  166. MUX_BEAGLE_C();
  167. break;
  168. case REVISION_C4:
  169. printf("Beagle Rev C4\n");
  170. setenv("beaglerev", "C4");
  171. MUX_BEAGLE_C();
  172. /* Set VAUX2 to 1.8V for EHCI PHY */
  173. twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
  174. TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
  175. TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
  176. TWL4030_PM_RECEIVER_DEV_GRP_P1);
  177. break;
  178. case REVISION_XM_A:
  179. printf("Beagle xM Rev A\n");
  180. setenv("beaglerev", "xMA");
  181. MUX_BEAGLE_XM();
  182. /* Set VAUX2 to 1.8V for EHCI PHY */
  183. twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
  184. TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
  185. TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
  186. TWL4030_PM_RECEIVER_DEV_GRP_P1);
  187. break;
  188. case REVISION_XM_B:
  189. printf("Beagle xM Rev B\n");
  190. setenv("beaglerev", "xMB");
  191. MUX_BEAGLE_XM();
  192. /* Set VAUX2 to 1.8V for EHCI PHY */
  193. twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
  194. TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
  195. TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
  196. TWL4030_PM_RECEIVER_DEV_GRP_P1);
  197. break;
  198. case REVISION_XM_C:
  199. printf("Beagle xM Rev C\n");
  200. setenv("beaglerev", "xMC");
  201. MUX_BEAGLE_XM();
  202. /* Set VAUX2 to 1.8V for EHCI PHY */
  203. twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
  204. TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
  205. TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
  206. TWL4030_PM_RECEIVER_DEV_GRP_P1);
  207. break;
  208. default:
  209. printf("Beagle unknown 0x%02x\n", get_board_revision());
  210. MUX_BEAGLE_XM();
  211. /* Set VAUX2 to 1.8V for EHCI PHY */
  212. twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
  213. TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
  214. TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
  215. TWL4030_PM_RECEIVER_DEV_GRP_P1);
  216. }
  217. switch (get_expansion_id()) {
  218. case TINCANTOOLS_ZIPPY:
  219. printf("Recognized Tincantools Zippy board (rev %d %s)\n",
  220. expansion_config.revision,
  221. expansion_config.fab_revision);
  222. MUX_TINCANTOOLS_ZIPPY();
  223. setenv("buddy", "zippy");
  224. break;
  225. case TINCANTOOLS_ZIPPY2:
  226. printf("Recognized Tincantools Zippy2 board (rev %d %s)\n",
  227. expansion_config.revision,
  228. expansion_config.fab_revision);
  229. MUX_TINCANTOOLS_ZIPPY();
  230. setenv("buddy", "zippy2");
  231. break;
  232. case TINCANTOOLS_TRAINER:
  233. printf("Recognized Tincantools Trainer board (rev %d %s)\n",
  234. expansion_config.revision,
  235. expansion_config.fab_revision);
  236. MUX_TINCANTOOLS_ZIPPY();
  237. MUX_TINCANTOOLS_TRAINER();
  238. setenv("buddy", "trainer");
  239. break;
  240. case TINCANTOOLS_SHOWDOG:
  241. printf("Recognized Tincantools Showdow board (rev %d %s)\n",
  242. expansion_config.revision,
  243. expansion_config.fab_revision);
  244. /* Place holder for DSS2 definition for showdog lcd */
  245. setenv("defaultdisplay", "showdoglcd");
  246. setenv("buddy", "showdog");
  247. break;
  248. case KBADC_BEAGLEFPGA:
  249. printf("Recognized KBADC Beagle FPGA board\n");
  250. MUX_KBADC_BEAGLEFPGA();
  251. setenv("buddy", "beaglefpga");
  252. break;
  253. case LW_BEAGLETOUCH:
  254. printf("Recognized Liquidware BeagleTouch board\n");
  255. setenv("buddy", "beagletouch");
  256. break;
  257. case BRAINMUX_LCDOG:
  258. printf("Recognized Brainmux LCDog board\n");
  259. setenv("buddy", "lcdog");
  260. break;
  261. case BRAINMUX_LCDOGTOUCH:
  262. printf("Recognized Brainmux LCDog Touch board\n");
  263. setenv("buddy", "lcdogtouch");
  264. break;
  265. case BBTOYS_WIFI:
  266. printf("Recognized BeagleBoardToys WiFi board\n");
  267. MUX_BBTOYS_WIFI()
  268. setenv("buddy", "bbtoys-wifi");
  269. break;;
  270. case BBTOYS_VGA:
  271. printf("Recognized BeagleBoardToys VGA board\n");
  272. break;;
  273. case BBTOYS_LCD:
  274. printf("Recognized BeagleBoardToys LCD board\n");
  275. break;;
  276. case BEAGLE_NO_EEPROM:
  277. printf("No EEPROM on expansion board\n");
  278. setenv("buddy", "none");
  279. break;
  280. default:
  281. printf("Unrecognized expansion board: %x\n",
  282. expansion_config.device_vendor);
  283. setenv("buddy", "unknown");
  284. }
  285. if (expansion_config.content == 1)
  286. setenv(expansion_config.env_var, expansion_config.env_setting);
  287. twl4030_power_init();
  288. twl4030_led_init(TWL4030_LED_LEDEN_LEDAON | TWL4030_LED_LEDEN_LEDBON);
  289. /* Set GPIO states before they are made outputs */
  290. writel(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1,
  291. &gpio6_base->setdataout);
  292. writel(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 |
  293. GPIO15 | GPIO14 | GPIO13 | GPIO12, &gpio5_base->setdataout);
  294. /* Configure GPIOs to output */
  295. writel(~(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1), &gpio6_base->oe);
  296. writel(~(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 |
  297. GPIO15 | GPIO14 | GPIO13 | GPIO12), &gpio5_base->oe);
  298. dieid_num_r();
  299. return 0;
  300. }
  301. /*
  302. * Routine: set_muxconf_regs
  303. * Description: Setting up the configuration Mux registers specific to the
  304. * hardware. Many pins need to be moved from protect to primary
  305. * mode.
  306. */
  307. void set_muxconf_regs(void)
  308. {
  309. MUX_BEAGLE();
  310. }
  311. #ifdef CONFIG_GENERIC_MMC
  312. int board_mmc_init(bd_t *bis)
  313. {
  314. omap_mmc_init(0);
  315. return 0;
  316. }
  317. #endif
  318. #ifdef CONFIG_USB_EHCI
  319. #define GPIO_PHY_RESET 147
  320. /* Reset is needed otherwise the kernel-driver will throw an error. */
  321. int ehci_hcd_stop(void)
  322. {
  323. pr_debug("Resetting OMAP3 EHCI\n");
  324. omap_set_gpio_dataout(GPIO_PHY_RESET, 0);
  325. writel(OMAP_UHH_SYSCONFIG_SOFTRESET, OMAP3_UHH_BASE + OMAP_UHH_SYSCONFIG);
  326. /* disable USB clocks */
  327. struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
  328. sr32(&prcm_base->iclken_usbhost, 0, 1, 0);
  329. sr32(&prcm_base->fclken_usbhost, 0, 2, 0);
  330. sr32(&prcm_base->iclken3_core, 2, 1, 0);
  331. sr32(&prcm_base->fclken3_core, 2, 1, 0);
  332. return 0;
  333. }
  334. /* Call usb_stop() before starting the kernel */
  335. void show_boot_progress(int val)
  336. {
  337. if(val == 15)
  338. usb_stop();
  339. }
  340. /*
  341. * Initialize the OMAP3 EHCI controller and PHY on the BeagleBoard.
  342. * Based on "drivers/usb/host/ehci-omap.c" from Linux 2.6.37.
  343. * See there for additional Copyrights.
  344. */
  345. int ehci_hcd_init(void)
  346. {
  347. pr_debug("Initializing OMAP3 ECHI\n");
  348. /* Put the PHY in RESET */
  349. omap_request_gpio(GPIO_PHY_RESET);
  350. omap_set_gpio_direction(GPIO_PHY_RESET, 0);
  351. omap_set_gpio_dataout(GPIO_PHY_RESET, 0);
  352. /* Hold the PHY in RESET for enough time till DIR is high */
  353. /* Refer: ISSUE1 */
  354. udelay(10);
  355. struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
  356. /* Enable USBHOST_L3_ICLK (USBHOST_MICLK) */
  357. sr32(&prcm_base->iclken_usbhost, 0, 1, 1);
  358. /*
  359. * Enable USBHOST_48M_FCLK (USBHOST_FCLK1)
  360. * and USBHOST_120M_FCLK (USBHOST_FCLK2)
  361. */
  362. sr32(&prcm_base->fclken_usbhost, 0, 2, 3);
  363. /* Enable USBTTL_ICLK */
  364. sr32(&prcm_base->iclken3_core, 2, 1, 1);
  365. /* Enable USBTTL_FCLK */
  366. sr32(&prcm_base->fclken3_core, 2, 1, 1);
  367. pr_debug("USB clocks enabled\n");
  368. /* perform TLL soft reset, and wait until reset is complete */
  369. writel(OMAP_USBTLL_SYSCONFIG_SOFTRESET,
  370. OMAP3_USBTLL_BASE + OMAP_USBTLL_SYSCONFIG);
  371. /* Wait for TLL reset to complete */
  372. while (!(readl(OMAP3_USBTLL_BASE + OMAP_USBTLL_SYSSTATUS)
  373. & OMAP_USBTLL_SYSSTATUS_RESETDONE));
  374. pr_debug("TLL reset done\n");
  375. writel(OMAP_USBTLL_SYSCONFIG_ENAWAKEUP |
  376. OMAP_USBTLL_SYSCONFIG_SIDLEMODE |
  377. OMAP_USBTLL_SYSCONFIG_CACTIVITY,
  378. OMAP3_USBTLL_BASE + OMAP_USBTLL_SYSCONFIG);
  379. /* Put UHH in NoIdle/NoStandby mode */
  380. writel(OMAP_UHH_SYSCONFIG_ENAWAKEUP
  381. | OMAP_UHH_SYSCONFIG_SIDLEMODE
  382. | OMAP_UHH_SYSCONFIG_CACTIVITY
  383. | OMAP_UHH_SYSCONFIG_MIDLEMODE,
  384. OMAP3_UHH_BASE + OMAP_UHH_SYSCONFIG);
  385. /* setup burst configurations */
  386. writel(OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN
  387. | OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN
  388. | OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN,
  389. OMAP3_UHH_BASE + OMAP_UHH_HOSTCONFIG);
  390. /*
  391. * Refer ISSUE1:
  392. * Hold the PHY in RESET for enough time till
  393. * PHY is settled and ready
  394. */
  395. udelay(10);
  396. omap_set_gpio_dataout(GPIO_PHY_RESET, 1);
  397. hccr = (struct ehci_hccr *)(OMAP3_EHCI_BASE);
  398. hcor = (struct ehci_hcor *)(OMAP3_EHCI_BASE + 0x10);
  399. pr_debug("OMAP3 EHCI init done\n");
  400. return 0;
  401. }
  402. #endif /* CONFIG_USB_EHCI */
  403. /*
  404. * This command returns the status of the user button on beagle xM
  405. * Input - none
  406. * Returns - 1 if button is held down
  407. * 0 if button is not held down
  408. */
  409. int do_userbutton (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  410. {
  411. int button = 0;
  412. int gpio;
  413. /*
  414. * pass address parameter as argv[0] (aka command name),
  415. * and all remaining args
  416. */
  417. switch (get_board_revision()) {
  418. case REVISION_AXBX:
  419. case REVISION_CX:
  420. case REVISION_C4:
  421. gpio = 7;
  422. break;
  423. case REVISION_XM_A:
  424. case REVISION_XM_B:
  425. case REVISION_XM_C:
  426. default:
  427. gpio = 4;
  428. break;
  429. }
  430. omap_request_gpio(gpio);
  431. omap_set_gpio_direction(gpio, 1);
  432. printf("The user button is currently ");
  433. if(omap_get_gpio_datain(gpio))
  434. {
  435. button = 1;
  436. printf("PRESSED.\n");
  437. }
  438. else
  439. {
  440. button = 0;
  441. printf("NOT pressed.\n");
  442. }
  443. omap_free_gpio(gpio);
  444. return !button;
  445. }
  446. /* -------------------------------------------------------------------- */
  447. U_BOOT_CMD(
  448. userbutton, CONFIG_SYS_MAXARGS, 1, do_userbutton,
  449. "Return the status of the BeagleBoard USER button",
  450. ""
  451. );