beagle.c 14 KB

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