beagle.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2004-2011
  4. * Texas Instruments, <www.ti.com>
  5. *
  6. * Author :
  7. * Sunil Kumar <sunilsaini05@gmail.com>
  8. * Shashi Ranjan <shashiranjanmca05@gmail.com>
  9. *
  10. * Derived from Beagle Board and 3430 SDP code by
  11. * Richard Woodruff <r-woodruff2@ti.com>
  12. * Syed Mohammed Khasim <khasim@ti.com>
  13. *
  14. */
  15. #include <common.h>
  16. #include <bootstage.h>
  17. #include <dm.h>
  18. #include <env.h>
  19. #include <init.h>
  20. #include <net.h>
  21. #include <ns16550.h>
  22. #include <serial.h>
  23. #ifdef CONFIG_LED_STATUS
  24. #include <status_led.h>
  25. #endif
  26. #include <twl4030.h>
  27. #include <asm/global_data.h>
  28. #include <linux/mtd/rawnand.h>
  29. #include <asm/io.h>
  30. #include <asm/arch/mmc_host_def.h>
  31. #include <asm/arch/mux.h>
  32. #include <asm/arch/mem.h>
  33. #include <asm/arch/sys_proto.h>
  34. #include <asm/gpio.h>
  35. #include <asm/mach-types.h>
  36. #include <asm/omap_musb.h>
  37. #include <linux/errno.h>
  38. #include <linux/usb/ch9.h>
  39. #include <linux/usb/gadget.h>
  40. #include <linux/usb/musb.h>
  41. #include "beagle.h"
  42. #include <command.h>
  43. #define TWL4030_I2C_BUS 0
  44. #define EXPANSION_EEPROM_I2C_BUS 1
  45. #define EXPANSION_EEPROM_I2C_ADDRESS 0x50
  46. #define TINCANTOOLS_ZIPPY 0x01000100
  47. #define TINCANTOOLS_ZIPPY2 0x02000100
  48. #define TINCANTOOLS_TRAINER 0x04000100
  49. #define TINCANTOOLS_SHOWDOG 0x03000100
  50. #define KBADC_BEAGLEFPGA 0x01000600
  51. #define LW_BEAGLETOUCH 0x01000700
  52. #define BRAINMUX_LCDOG 0x01000800
  53. #define BRAINMUX_LCDOGTOUCH 0x02000800
  54. #define BBTOYS_WIFI 0x01000B00
  55. #define BBTOYS_VGA 0x02000B00
  56. #define BBTOYS_LCD 0x03000B00
  57. #define BCT_BRETTL3 0x01000F00
  58. #define BCT_BRETTL4 0x02000F00
  59. #define LSR_COM6L_ADPT 0x01001300
  60. #define BEAGLE_NO_EEPROM 0xffffffff
  61. DECLARE_GLOBAL_DATA_PTR;
  62. static struct {
  63. unsigned int device_vendor;
  64. unsigned char revision;
  65. unsigned char content;
  66. char fab_revision[8];
  67. char env_var[16];
  68. char env_setting[64];
  69. } expansion_config;
  70. /*
  71. * Routine: board_init
  72. * Description: Early hardware init.
  73. */
  74. int board_init(void)
  75. {
  76. gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
  77. /* board id for Linux */
  78. gd->bd->bi_arch_number = MACH_TYPE_OMAP3_BEAGLE;
  79. /* boot param addr */
  80. gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
  81. #if defined(CONFIG_LED_STATUS) && defined(CONFIG_LED_STATUS_BOOT_ENABLE)
  82. status_led_set(CONFIG_LED_STATUS_BOOT, CONFIG_LED_STATUS_ON);
  83. #endif
  84. return 0;
  85. }
  86. #if defined(CONFIG_SPL_OS_BOOT)
  87. int spl_start_uboot(void)
  88. {
  89. /* break into full u-boot on 'c' */
  90. if (serial_tstc() && serial_getc() == 'c')
  91. return 1;
  92. return 0;
  93. }
  94. #endif /* CONFIG_SPL_OS_BOOT */
  95. /*
  96. * Routine: get_board_revision
  97. * Description: Detect if we are running on a Beagle revision Ax/Bx,
  98. * C1/2/3, C4, xM Ax/Bx or xM Cx. 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 1 0 => xM Cx
  105. * GPIO173, GPIO172, GPIO171: 0 0 0 => xM Ax/Bx
  106. */
  107. static int get_board_revision(void)
  108. {
  109. static int revision = -1;
  110. if (revision == -1) {
  111. if (!gpio_request(171, "rev0") &&
  112. !gpio_request(172, "rev1") &&
  113. !gpio_request(173, "rev2")) {
  114. gpio_direction_input(171);
  115. gpio_direction_input(172);
  116. gpio_direction_input(173);
  117. revision = gpio_get_value(173) << 2 |
  118. gpio_get_value(172) << 1 |
  119. gpio_get_value(171);
  120. } else {
  121. printf("Error: unable to acquire board revision GPIOs\n");
  122. }
  123. }
  124. return revision;
  125. }
  126. #ifdef CONFIG_SPL_BUILD
  127. /*
  128. * Routine: get_board_mem_timings
  129. * Description: If we use SPL then there is no x-loader nor config header
  130. * so we have to setup the DDR timings ourself on both banks.
  131. */
  132. void get_board_mem_timings(struct board_sdrc_timings *timings)
  133. {
  134. int pop_mfr, pop_id;
  135. /*
  136. * We need to identify what PoP memory is on the board so that
  137. * we know what timings to use. If we can't identify it then
  138. * we know it's an xM. To map the ID values please see nand_ids.c
  139. */
  140. identify_nand_chip(&pop_mfr, &pop_id);
  141. timings->mr = MICRON_V_MR_165;
  142. switch (get_board_revision()) {
  143. case REVISION_C4:
  144. if (pop_mfr == NAND_MFR_STMICRO && pop_id == 0xba) {
  145. /* 512MB DDR */
  146. timings->mcfg = NUMONYX_V_MCFG_165(512 << 20);
  147. timings->ctrla = NUMONYX_V_ACTIMA_165;
  148. timings->ctrlb = NUMONYX_V_ACTIMB_165;
  149. timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
  150. break;
  151. } else if (pop_mfr == NAND_MFR_MICRON && pop_id == 0xba) {
  152. /* Beagleboard Rev C4, 512MB Nand/256MB DDR*/
  153. timings->mcfg = MICRON_V_MCFG_165(128 << 20);
  154. timings->ctrla = MICRON_V_ACTIMA_165;
  155. timings->ctrlb = MICRON_V_ACTIMB_165;
  156. timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
  157. break;
  158. } else if (pop_mfr == NAND_MFR_MICRON && pop_id == 0xbc) {
  159. /* Beagleboard Rev C5, 256MB DDR */
  160. timings->mcfg = MICRON_V_MCFG_200(256 << 20);
  161. timings->ctrla = MICRON_V_ACTIMA_200;
  162. timings->ctrlb = MICRON_V_ACTIMB_200;
  163. timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
  164. break;
  165. }
  166. case REVISION_XM_AB:
  167. case REVISION_XM_C:
  168. if (pop_mfr == 0) {
  169. /* 256MB DDR */
  170. timings->mcfg = MICRON_V_MCFG_200(256 << 20);
  171. timings->ctrla = MICRON_V_ACTIMA_200;
  172. timings->ctrlb = MICRON_V_ACTIMB_200;
  173. timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
  174. } else {
  175. /* 512MB DDR */
  176. timings->mcfg = NUMONYX_V_MCFG_165(512 << 20);
  177. timings->ctrla = NUMONYX_V_ACTIMA_165;
  178. timings->ctrlb = NUMONYX_V_ACTIMB_165;
  179. timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
  180. }
  181. break;
  182. default:
  183. /* Assume 128MB and Micron/165MHz timings to be safe */
  184. timings->mcfg = MICRON_V_MCFG_165(128 << 20);
  185. timings->ctrla = MICRON_V_ACTIMA_165;
  186. timings->ctrlb = MICRON_V_ACTIMB_165;
  187. timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
  188. }
  189. }
  190. #endif
  191. /*
  192. * Routine: get_expansion_id
  193. * Description: This function checks for expansion board by checking I2C
  194. * bus 1 for the availability of an AT24C01B serial EEPROM.
  195. * returns the device_vendor field from the EEPROM
  196. */
  197. static unsigned int get_expansion_id(void)
  198. {
  199. i2c_set_bus_num(EXPANSION_EEPROM_I2C_BUS);
  200. /* return BEAGLE_NO_EEPROM if eeprom doesn't respond */
  201. if (i2c_probe(EXPANSION_EEPROM_I2C_ADDRESS) == 1) {
  202. i2c_set_bus_num(TWL4030_I2C_BUS);
  203. return BEAGLE_NO_EEPROM;
  204. }
  205. /* read configuration data */
  206. i2c_read(EXPANSION_EEPROM_I2C_ADDRESS, 0, 1, (u8 *)&expansion_config,
  207. sizeof(expansion_config));
  208. /* retry reading configuration data with 16bit addressing */
  209. if ((expansion_config.device_vendor == 0xFFFFFF00) ||
  210. (expansion_config.device_vendor == 0xFFFFFFFF)) {
  211. printf("EEPROM is blank or 8bit addressing failed: retrying with 16bit:\n");
  212. i2c_read(EXPANSION_EEPROM_I2C_ADDRESS, 0, 2, (u8 *)&expansion_config,
  213. sizeof(expansion_config));
  214. }
  215. i2c_set_bus_num(TWL4030_I2C_BUS);
  216. return expansion_config.device_vendor;
  217. }
  218. #ifdef CONFIG_VIDEO_OMAP3
  219. /*
  220. * Configure DSS to display background color on DVID
  221. * Configure VENC to display color bar on S-Video
  222. */
  223. static void beagle_display_init(void)
  224. {
  225. omap3_dss_venc_config(&venc_config_std_tv, VENC_HEIGHT, VENC_WIDTH);
  226. switch (get_board_revision()) {
  227. case REVISION_AXBX:
  228. case REVISION_CX:
  229. case REVISION_C4:
  230. omap3_dss_panel_config(&dvid_cfg);
  231. break;
  232. case REVISION_XM_AB:
  233. case REVISION_XM_C:
  234. default:
  235. omap3_dss_panel_config(&dvid_cfg_xm);
  236. break;
  237. }
  238. }
  239. /*
  240. * Enable DVI power
  241. */
  242. static void beagle_dvi_pup(void)
  243. {
  244. uchar val;
  245. switch (get_board_revision()) {
  246. case REVISION_AXBX:
  247. case REVISION_CX:
  248. case REVISION_C4:
  249. gpio_request(170, "dvi");
  250. gpio_direction_output(170, 0);
  251. gpio_set_value(170, 1);
  252. break;
  253. case REVISION_XM_AB:
  254. case REVISION_XM_C:
  255. default:
  256. #define GPIODATADIR1 (TWL4030_BASEADD_GPIO+3)
  257. #define GPIODATAOUT1 (TWL4030_BASEADD_GPIO+6)
  258. i2c_read(TWL4030_CHIP_GPIO, GPIODATADIR1, 1, &val, 1);
  259. val |= 4;
  260. i2c_write(TWL4030_CHIP_GPIO, GPIODATADIR1, 1, &val, 1);
  261. i2c_read(TWL4030_CHIP_GPIO, GPIODATAOUT1, 1, &val, 1);
  262. val |= 4;
  263. i2c_write(TWL4030_CHIP_GPIO, GPIODATAOUT1, 1, &val, 1);
  264. break;
  265. }
  266. }
  267. #endif
  268. /*
  269. * Routine: misc_init_r
  270. * Description: Configure board specific parts
  271. */
  272. int misc_init_r(void)
  273. {
  274. struct gpio *gpio5_base = (struct gpio *)OMAP34XX_GPIO5_BASE;
  275. struct gpio *gpio6_base = (struct gpio *)OMAP34XX_GPIO6_BASE;
  276. struct control_prog_io *prog_io_base = (struct control_prog_io *)OMAP34XX_CTRL_BASE;
  277. bool generate_fake_mac = false;
  278. u32 value;
  279. /* Enable i2c2 pullup resisters */
  280. value = readl(&prog_io_base->io1);
  281. value &= ~(PRG_I2C2_PULLUPRESX);
  282. writel(value, &prog_io_base->io1);
  283. switch (get_board_revision()) {
  284. case REVISION_AXBX:
  285. printf("Beagle Rev Ax/Bx\n");
  286. env_set("beaglerev", "AxBx");
  287. break;
  288. case REVISION_CX:
  289. printf("Beagle Rev C1/C2/C3\n");
  290. env_set("beaglerev", "Cx");
  291. MUX_BEAGLE_C();
  292. break;
  293. case REVISION_C4:
  294. printf("Beagle Rev C4\n");
  295. env_set("beaglerev", "C4");
  296. MUX_BEAGLE_C();
  297. /* Set VAUX2 to 1.8V for EHCI PHY */
  298. twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
  299. TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
  300. TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
  301. TWL4030_PM_RECEIVER_DEV_GRP_P1);
  302. break;
  303. case REVISION_XM_AB:
  304. printf("Beagle xM Rev A/B\n");
  305. env_set("beaglerev", "xMAB");
  306. MUX_BEAGLE_XM();
  307. /* Set VAUX2 to 1.8V for EHCI PHY */
  308. twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
  309. TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
  310. TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
  311. TWL4030_PM_RECEIVER_DEV_GRP_P1);
  312. generate_fake_mac = true;
  313. break;
  314. case REVISION_XM_C:
  315. printf("Beagle xM Rev C\n");
  316. env_set("beaglerev", "xMC");
  317. MUX_BEAGLE_XM();
  318. /* Set VAUX2 to 1.8V for EHCI PHY */
  319. twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
  320. TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
  321. TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
  322. TWL4030_PM_RECEIVER_DEV_GRP_P1);
  323. generate_fake_mac = true;
  324. break;
  325. default:
  326. printf("Beagle unknown 0x%02x\n", get_board_revision());
  327. MUX_BEAGLE_XM();
  328. /* Set VAUX2 to 1.8V for EHCI PHY */
  329. twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
  330. TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
  331. TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
  332. TWL4030_PM_RECEIVER_DEV_GRP_P1);
  333. generate_fake_mac = true;
  334. }
  335. switch (get_expansion_id()) {
  336. case TINCANTOOLS_ZIPPY:
  337. printf("Recognized Tincantools Zippy board (rev %d %s)\n",
  338. expansion_config.revision,
  339. expansion_config.fab_revision);
  340. MUX_TINCANTOOLS_ZIPPY();
  341. env_set("buddy", "zippy");
  342. break;
  343. case TINCANTOOLS_ZIPPY2:
  344. printf("Recognized Tincantools Zippy2 board (rev %d %s)\n",
  345. expansion_config.revision,
  346. expansion_config.fab_revision);
  347. MUX_TINCANTOOLS_ZIPPY();
  348. env_set("buddy", "zippy2");
  349. break;
  350. case TINCANTOOLS_TRAINER:
  351. printf("Recognized Tincantools Trainer board (rev %d %s)\n",
  352. expansion_config.revision,
  353. expansion_config.fab_revision);
  354. MUX_TINCANTOOLS_ZIPPY();
  355. MUX_TINCANTOOLS_TRAINER();
  356. env_set("buddy", "trainer");
  357. break;
  358. case TINCANTOOLS_SHOWDOG:
  359. printf("Recognized Tincantools Showdow board (rev %d %s)\n",
  360. expansion_config.revision,
  361. expansion_config.fab_revision);
  362. /* Place holder for DSS2 definition for showdog lcd */
  363. env_set("defaultdisplay", "showdoglcd");
  364. env_set("buddy", "showdog");
  365. break;
  366. case KBADC_BEAGLEFPGA:
  367. printf("Recognized KBADC Beagle FPGA board\n");
  368. MUX_KBADC_BEAGLEFPGA();
  369. env_set("buddy", "beaglefpga");
  370. break;
  371. case LW_BEAGLETOUCH:
  372. printf("Recognized Liquidware BeagleTouch board\n");
  373. env_set("buddy", "beagletouch");
  374. break;
  375. case BRAINMUX_LCDOG:
  376. printf("Recognized Brainmux LCDog board\n");
  377. env_set("buddy", "lcdog");
  378. break;
  379. case BRAINMUX_LCDOGTOUCH:
  380. printf("Recognized Brainmux LCDog Touch board\n");
  381. env_set("buddy", "lcdogtouch");
  382. break;
  383. case BBTOYS_WIFI:
  384. printf("Recognized BeagleBoardToys WiFi board\n");
  385. MUX_BBTOYS_WIFI()
  386. env_set("buddy", "bbtoys-wifi");
  387. break;
  388. case BBTOYS_VGA:
  389. printf("Recognized BeagleBoardToys VGA board\n");
  390. break;
  391. case BBTOYS_LCD:
  392. printf("Recognized BeagleBoardToys LCD board\n");
  393. break;
  394. case BCT_BRETTL3:
  395. printf("Recognized bct electronic GmbH brettl3 board\n");
  396. break;
  397. case BCT_BRETTL4:
  398. printf("Recognized bct electronic GmbH brettl4 board\n");
  399. break;
  400. case LSR_COM6L_ADPT:
  401. printf("Recognized LSR COM6L Adapter Board\n");
  402. MUX_BBTOYS_WIFI()
  403. env_set("buddy", "lsr-com6l-adpt");
  404. break;
  405. case BEAGLE_NO_EEPROM:
  406. printf("No EEPROM on expansion board\n");
  407. env_set("buddy", "none");
  408. break;
  409. default:
  410. printf("Unrecognized expansion board: %x\n",
  411. expansion_config.device_vendor);
  412. env_set("buddy", "unknown");
  413. }
  414. if (expansion_config.content == 1)
  415. env_set(expansion_config.env_var, expansion_config.env_setting);
  416. twl4030_power_init();
  417. switch (get_board_revision()) {
  418. case REVISION_XM_AB:
  419. twl4030_led_init(TWL4030_LED_LEDEN_LEDBON);
  420. break;
  421. default:
  422. twl4030_led_init(TWL4030_LED_LEDEN_LEDAON | TWL4030_LED_LEDEN_LEDBON);
  423. break;
  424. }
  425. /* Set GPIO states before they are made outputs */
  426. writel(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1,
  427. &gpio6_base->setdataout);
  428. writel(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 |
  429. GPIO15 | GPIO14 | GPIO13 | GPIO12, &gpio5_base->setdataout);
  430. /* Configure GPIOs to output */
  431. writel(~(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1), &gpio6_base->oe);
  432. writel(~(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 |
  433. GPIO15 | GPIO14 | GPIO13 | GPIO12), &gpio5_base->oe);
  434. omap_die_id_display();
  435. #ifdef CONFIG_VIDEO_OMAP3
  436. beagle_dvi_pup();
  437. beagle_display_init();
  438. omap3_dss_enable();
  439. #endif
  440. if (generate_fake_mac)
  441. omap_die_id_usbethaddr();
  442. #if defined(CONFIG_MTDIDS_DEFAULT) && defined(CONFIG_MTDPARTS_DEFAULT)
  443. if (strlen(CONFIG_MTDIDS_DEFAULT))
  444. env_set("mtdids", CONFIG_MTDIDS_DEFAULT);
  445. if (strlen(CONFIG_MTDPARTS_DEFAULT))
  446. env_set("mtdparts", CONFIG_MTDPARTS_DEFAULT);
  447. #endif
  448. return 0;
  449. }
  450. /*
  451. * Routine: set_muxconf_regs
  452. * Description: Setting up the configuration Mux registers specific to the
  453. * hardware. Many pins need to be moved from protect to primary
  454. * mode.
  455. */
  456. void set_muxconf_regs(void)
  457. {
  458. MUX_BEAGLE();
  459. }
  460. #if defined(CONFIG_MMC)
  461. int board_mmc_init(struct bd_info *bis)
  462. {
  463. return omap_mmc_init(0, 0, 0, -1, -1);
  464. }
  465. #endif
  466. #if defined(CONFIG_MMC)
  467. void board_mmc_power_init(void)
  468. {
  469. twl4030_power_mmc_init(0);
  470. }
  471. #endif