beagle.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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. #define pr_debug(fmt, args...) debug(fmt, ##args)
  54. #define TWL4030_I2C_BUS 0
  55. #define EXPANSION_EEPROM_I2C_BUS 1
  56. #define EXPANSION_EEPROM_I2C_ADDRESS 0x50
  57. #define TINCANTOOLS_ZIPPY 0x01000100
  58. #define TINCANTOOLS_ZIPPY2 0x02000100
  59. #define TINCANTOOLS_TRAINER 0x04000100
  60. #define TINCANTOOLS_SHOWDOG 0x03000100
  61. #define KBADC_BEAGLEFPGA 0x01000600
  62. #define LW_BEAGLETOUCH 0x01000700
  63. #define BRAINMUX_LCDOG 0x01000800
  64. #define BRAINMUX_LCDOGTOUCH 0x02000800
  65. #define BBTOYS_WIFI 0x01000B00
  66. #define BBTOYS_VGA 0x02000B00
  67. #define BBTOYS_LCD 0x03000B00
  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. int get_board_revision(void)
  106. {
  107. int revision;
  108. if (!omap_request_gpio(171) &&
  109. !omap_request_gpio(172) &&
  110. !omap_request_gpio(173)) {
  111. omap_set_gpio_direction(171, 1);
  112. omap_set_gpio_direction(172, 1);
  113. omap_set_gpio_direction(173, 1);
  114. revision = omap_get_gpio_datain(173) << 2 |
  115. omap_get_gpio_datain(172) << 1 |
  116. omap_get_gpio_datain(171);
  117. omap_free_gpio(171);
  118. omap_free_gpio(172);
  119. omap_free_gpio(173);
  120. } else {
  121. printf("Error: unable to acquire board revision GPIOs\n");
  122. revision = -1;
  123. }
  124. return revision;
  125. }
  126. /*
  127. * Routine: get_expansion_id
  128. * Description: This function checks for expansion board by checking I2C
  129. * bus 1 for the availability of an AT24C01B serial EEPROM.
  130. * returns the device_vendor field from the EEPROM
  131. */
  132. unsigned int get_expansion_id(void)
  133. {
  134. i2c_set_bus_num(EXPANSION_EEPROM_I2C_BUS);
  135. /* return BEAGLE_NO_EEPROM if eeprom doesn't respond */
  136. if (i2c_probe(EXPANSION_EEPROM_I2C_ADDRESS) == 1) {
  137. i2c_set_bus_num(TWL4030_I2C_BUS);
  138. return BEAGLE_NO_EEPROM;
  139. }
  140. /* read configuration data */
  141. i2c_read(EXPANSION_EEPROM_I2C_ADDRESS, 0, 1, (u8 *)&expansion_config,
  142. sizeof(expansion_config));
  143. i2c_set_bus_num(TWL4030_I2C_BUS);
  144. return expansion_config.device_vendor;
  145. }
  146. /*
  147. * Routine: misc_init_r
  148. * Description: Configure board specific parts
  149. */
  150. int misc_init_r(void)
  151. {
  152. struct gpio *gpio5_base = (struct gpio *)OMAP34XX_GPIO5_BASE;
  153. struct gpio *gpio6_base = (struct gpio *)OMAP34XX_GPIO6_BASE;
  154. struct control_prog_io *prog_io_base = (struct control_prog_io *)OMAP34XX_CTRL_BASE;
  155. /* Enable i2c2 pullup resisters */
  156. writel(~(PRG_I2C2_PULLUPRESX), &prog_io_base->io1);
  157. switch (get_board_revision()) {
  158. case REVISION_AXBX:
  159. printf("Beagle Rev Ax/Bx\n");
  160. setenv("beaglerev", "AxBx");
  161. break;
  162. case REVISION_CX:
  163. printf("Beagle Rev C1/C2/C3\n");
  164. setenv("beaglerev", "Cx");
  165. MUX_BEAGLE_C();
  166. break;
  167. case REVISION_C4:
  168. printf("Beagle Rev C4\n");
  169. setenv("beaglerev", "C4");
  170. MUX_BEAGLE_C();
  171. /* Set VAUX2 to 1.8V for EHCI PHY */
  172. twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
  173. TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
  174. TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
  175. TWL4030_PM_RECEIVER_DEV_GRP_P1);
  176. break;
  177. case REVISION_XM_A:
  178. printf("Beagle xM Rev A\n");
  179. setenv("beaglerev", "xMA");
  180. MUX_BEAGLE_XM();
  181. /* Set VAUX2 to 1.8V for EHCI PHY */
  182. twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
  183. TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
  184. TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
  185. TWL4030_PM_RECEIVER_DEV_GRP_P1);
  186. break;
  187. case REVISION_XM_B:
  188. printf("Beagle xM Rev B\n");
  189. setenv("beaglerev", "xMB");
  190. MUX_BEAGLE_XM();
  191. /* Set VAUX2 to 1.8V for EHCI PHY */
  192. twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
  193. TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
  194. TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
  195. TWL4030_PM_RECEIVER_DEV_GRP_P1);
  196. break;
  197. default:
  198. printf("Beagle unknown 0x%02x\n", get_board_revision());
  199. MUX_BEAGLE_XM();
  200. /* Set VAUX2 to 1.8V for EHCI PHY */
  201. twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
  202. TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
  203. TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
  204. TWL4030_PM_RECEIVER_DEV_GRP_P1);
  205. }
  206. switch (get_expansion_id()) {
  207. case TINCANTOOLS_ZIPPY:
  208. printf("Recognized Tincantools Zippy board (rev %d %s)\n",
  209. expansion_config.revision,
  210. expansion_config.fab_revision);
  211. MUX_TINCANTOOLS_ZIPPY();
  212. setenv("buddy", "zippy");
  213. break;
  214. case TINCANTOOLS_ZIPPY2:
  215. printf("Recognized Tincantools Zippy2 board (rev %d %s)\n",
  216. expansion_config.revision,
  217. expansion_config.fab_revision);
  218. MUX_TINCANTOOLS_ZIPPY();
  219. setenv("buddy", "zippy2");
  220. break;
  221. case TINCANTOOLS_TRAINER:
  222. printf("Recognized Tincantools Trainer board (rev %d %s)\n",
  223. expansion_config.revision,
  224. expansion_config.fab_revision);
  225. MUX_TINCANTOOLS_ZIPPY();
  226. MUX_TINCANTOOLS_TRAINER();
  227. setenv("buddy", "trainer");
  228. break;
  229. case TINCANTOOLS_SHOWDOG:
  230. printf("Recognized Tincantools Showdow board (rev %d %s)\n",
  231. expansion_config.revision,
  232. expansion_config.fab_revision);
  233. /* Place holder for DSS2 definition for showdog lcd */
  234. setenv("defaultdisplay", "showdoglcd");
  235. setenv("buddy", "showdog");
  236. break;
  237. case KBADC_BEAGLEFPGA:
  238. printf("Recognized KBADC Beagle FPGA board\n");
  239. MUX_KBADC_BEAGLEFPGA();
  240. setenv("buddy", "beaglefpga");
  241. break;
  242. case LW_BEAGLETOUCH:
  243. printf("Recognized Liquidware BeagleTouch board\n");
  244. setenv("buddy", "beagletouch");
  245. break;
  246. case BRAINMUX_LCDOG:
  247. printf("Recognized Brainmux LCDog board\n");
  248. setenv("buddy", "lcdog");
  249. break;
  250. case BRAINMUX_LCDOGTOUCH:
  251. printf("Recognized Brainmux LCDog Touch board\n");
  252. setenv("buddy", "lcdogtouch");
  253. break;
  254. case BBTOYS_WIFI:
  255. printf("Recognized BeagleBoardToys WiFi board\n");
  256. MUX_BBTOYS_WIFI()
  257. setenv("buddy", "bbtoys-wifi");
  258. break;;
  259. case BBTOYS_VGA:
  260. printf("Recognized BeagleBoardToys VGA board\n");
  261. break;;
  262. case BBTOYS_LCD:
  263. printf("Recognized BeagleBoardToys LCD board\n");
  264. break;;
  265. case BEAGLE_NO_EEPROM:
  266. printf("No EEPROM on expansion board\n");
  267. setenv("buddy", "none");
  268. break;
  269. default:
  270. printf("Unrecognized expansion board: %x\n",
  271. expansion_config.device_vendor);
  272. setenv("buddy", "unknown");
  273. }
  274. if (expansion_config.content == 1)
  275. setenv(expansion_config.env_var, expansion_config.env_setting);
  276. twl4030_power_init();
  277. twl4030_led_init(TWL4030_LED_LEDEN_LEDAON | TWL4030_LED_LEDEN_LEDBON);
  278. /* Configure GPIOs to output */
  279. writel(~(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1), &gpio6_base->oe);
  280. writel(~(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 |
  281. GPIO15 | GPIO14 | GPIO13 | GPIO12), &gpio5_base->oe);
  282. /* Set GPIOs */
  283. writel(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1,
  284. &gpio6_base->setdataout);
  285. writel(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 |
  286. GPIO15 | GPIO14 | GPIO13 | GPIO12, &gpio5_base->setdataout);
  287. dieid_num_r();
  288. return 0;
  289. }
  290. /*
  291. * Routine: set_muxconf_regs
  292. * Description: Setting up the configuration Mux registers specific to the
  293. * hardware. Many pins need to be moved from protect to primary
  294. * mode.
  295. */
  296. void set_muxconf_regs(void)
  297. {
  298. MUX_BEAGLE();
  299. }
  300. #ifdef CONFIG_GENERIC_MMC
  301. int board_mmc_init(bd_t *bis)
  302. {
  303. omap_mmc_init(0);
  304. return 0;
  305. }
  306. #endif
  307. #ifdef CONFIG_USB_EHCI
  308. #define GPIO_PHY_RESET 147
  309. /* Reset is needed otherwise the kernel-driver will throw an error. */
  310. int ehci_hcd_stop(void)
  311. {
  312. pr_debug("Resetting OMAP3 EHCI\n");
  313. omap_set_gpio_dataout(GPIO_PHY_RESET, 0);
  314. writel(OMAP_UHH_SYSCONFIG_SOFTRESET, OMAP3_UHH_BASE + OMAP_UHH_SYSCONFIG);
  315. return 0;
  316. }
  317. /* Call usb_stop() before starting the kernel */
  318. void show_boot_progress(int val)
  319. {
  320. if(val == 15)
  321. usb_stop();
  322. }
  323. /*
  324. * Initialize the OMAP3 EHCI controller and PHY on the BeagleBoard.
  325. * Based on "drivers/usb/host/ehci-omap.c" from Linux 2.6.37.
  326. * See there for additional Copyrights.
  327. */
  328. int ehci_hcd_init(void)
  329. {
  330. pr_debug("Initializing OMAP3 ECHI\n");
  331. /* Put the PHY in RESET */
  332. omap_request_gpio(GPIO_PHY_RESET);
  333. omap_set_gpio_direction(GPIO_PHY_RESET, 0);
  334. omap_set_gpio_dataout(GPIO_PHY_RESET, 0);
  335. /* Hold the PHY in RESET for enough time till DIR is high */
  336. /* Refer: ISSUE1 */
  337. udelay(10);
  338. struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
  339. /* Enable USBHOST_L3_ICLK (USBHOST_MICLK) */
  340. sr32(&prcm_base->iclken_usbhost, 0, 1, 1);
  341. /*
  342. * Enable USBHOST_48M_FCLK (USBHOST_FCLK1)
  343. * and USBHOST_120M_FCLK (USBHOST_FCLK2)
  344. */
  345. sr32(&prcm_base->fclken_usbhost, 0, 2, 3);
  346. /* Enable USBTTL_ICLK */
  347. sr32(&prcm_base->iclken3_core, 2, 1, 1);
  348. /* Enable USBTTL_FCLK */
  349. sr32(&prcm_base->fclken3_core, 2, 1, 1);
  350. pr_debug("USB clocks enabled\n");
  351. /* perform TLL soft reset, and wait until reset is complete */
  352. writel(OMAP_USBTLL_SYSCONFIG_SOFTRESET,
  353. OMAP3_USBTLL_BASE + OMAP_USBTLL_SYSCONFIG);
  354. /* Wait for TLL reset to complete */
  355. while (!(readl(OMAP3_USBTLL_BASE + OMAP_USBTLL_SYSSTATUS)
  356. & OMAP_USBTLL_SYSSTATUS_RESETDONE));
  357. pr_debug("TLL reset done\n");
  358. writel(OMAP_USBTLL_SYSCONFIG_ENAWAKEUP |
  359. OMAP_USBTLL_SYSCONFIG_SIDLEMODE |
  360. OMAP_USBTLL_SYSCONFIG_CACTIVITY,
  361. OMAP3_USBTLL_BASE + OMAP_USBTLL_SYSCONFIG);
  362. /* Put UHH in NoIdle/NoStandby mode */
  363. writel(OMAP_UHH_SYSCONFIG_ENAWAKEUP
  364. | OMAP_UHH_SYSCONFIG_SIDLEMODE
  365. | OMAP_UHH_SYSCONFIG_CACTIVITY
  366. | OMAP_UHH_SYSCONFIG_MIDLEMODE,
  367. OMAP3_UHH_BASE + OMAP_UHH_SYSCONFIG);
  368. /* setup burst configurations */
  369. writel(OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN
  370. | OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN
  371. | OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN,
  372. OMAP3_UHH_BASE + OMAP_UHH_HOSTCONFIG);
  373. /*
  374. * Refer ISSUE1:
  375. * Hold the PHY in RESET for enough time till
  376. * PHY is settled and ready
  377. */
  378. udelay(10);
  379. omap_set_gpio_dataout(GPIO_PHY_RESET, 1);
  380. hccr = (struct ehci_hccr *)(OMAP3_EHCI_BASE);
  381. hcor = (struct ehci_hcor *)(OMAP3_EHCI_BASE + 0x10);
  382. pr_debug("OMAP3 EHCI init done\n");
  383. return 0;
  384. }
  385. #endif /* CONFIG_USB_EHCI */