board.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * board.c
  4. *
  5. * (C) Copyright 2016
  6. * Heiko Schocher, DENX Software Engineering, hs@denx.de.
  7. *
  8. * Based on:
  9. * Board functions for TI AM335X based boards
  10. *
  11. * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
  12. */
  13. #include <common.h>
  14. #include <errno.h>
  15. #include <spl.h>
  16. #include <asm/arch/cpu.h>
  17. #include <asm/arch/hardware.h>
  18. #include <asm/arch/omap.h>
  19. #include <asm/arch/ddr_defs.h>
  20. #include <asm/arch/clock.h>
  21. #include <asm/arch/gpio.h>
  22. #include <asm/arch/mmc_host_def.h>
  23. #include <asm/arch/sys_proto.h>
  24. #include <asm/arch/mem.h>
  25. #include <asm/io.h>
  26. #include <asm/emif.h>
  27. #include <asm/gpio.h>
  28. #include <i2c.h>
  29. #include <miiphy.h>
  30. #include <cpsw.h>
  31. #include <power/tps65217.h>
  32. #include <environment.h>
  33. #include <watchdog.h>
  34. #include <environment.h>
  35. #include "mmc.h"
  36. #include "board.h"
  37. DECLARE_GLOBAL_DATA_PTR;
  38. #if defined(CONFIG_SPL_BUILD) || \
  39. (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_DM_ETH))
  40. static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
  41. #endif
  42. static struct shc_eeprom __attribute__((section(".data"))) header;
  43. static int shc_eeprom_valid;
  44. /*
  45. * Read header information from EEPROM into global structure.
  46. */
  47. static int read_eeprom(void)
  48. {
  49. /* Check if baseboard eeprom is available */
  50. if (i2c_probe(CONFIG_SYS_I2C_EEPROM_ADDR)) {
  51. puts("Could not probe the EEPROM; something fundamentally wrong on the I2C bus.\n");
  52. return -ENODEV;
  53. }
  54. /* read the eeprom using i2c */
  55. if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 2, (uchar *)&header,
  56. sizeof(header))) {
  57. puts("Could not read the EEPROM; something fundamentally wrong on the I2C bus.\n");
  58. return -EIO;
  59. }
  60. if (header.magic != HDR_MAGIC) {
  61. printf("Incorrect magic number (0x%x) in EEPROM\n",
  62. header.magic);
  63. return -EIO;
  64. }
  65. shc_eeprom_valid = 1;
  66. return 0;
  67. }
  68. static void shc_request_gpio(void)
  69. {
  70. gpio_request(LED_PWR_BL_GPIO, "LED PWR BL");
  71. gpio_request(LED_PWR_RD_GPIO, "LED PWR RD");
  72. gpio_request(RESET_GPIO, "reset");
  73. gpio_request(WIFI_REGEN_GPIO, "WIFI REGEN");
  74. gpio_request(WIFI_RST_GPIO, "WIFI rst");
  75. gpio_request(ZIGBEE_RST_GPIO, "ZigBee rst");
  76. gpio_request(BIDCOS_RST_GPIO, "BIDCOS rst");
  77. gpio_request(ENOC_RST_GPIO, "ENOC rst");
  78. #if defined CONFIG_B_SAMPLE
  79. gpio_request(LED_PWR_GN_GPIO, "LED PWR GN");
  80. gpio_request(LED_CONN_BL_GPIO, "LED CONN BL");
  81. gpio_request(LED_CONN_RD_GPIO, "LED CONN RD");
  82. gpio_request(LED_CONN_GN_GPIO, "LED CONN GN");
  83. #else
  84. gpio_request(LED_LAN_BL_GPIO, "LED LAN BL");
  85. gpio_request(LED_LAN_RD_GPIO, "LED LAN RD");
  86. gpio_request(LED_CLOUD_BL_GPIO, "LED CLOUD BL");
  87. gpio_request(LED_CLOUD_RD_GPIO, "LED CLOUD RD");
  88. gpio_request(LED_PWM_GPIO, "LED PWM");
  89. gpio_request(Z_WAVE_RST_GPIO, "Z WAVE rst");
  90. #endif
  91. gpio_request(BACK_BUTTON_GPIO, "Back button");
  92. gpio_request(FRONT_BUTTON_GPIO, "Front button");
  93. }
  94. /*
  95. * Function which forces all installed modules into running state for ICT
  96. * testing. Called by SPL.
  97. */
  98. static void __maybe_unused force_modules_running(void)
  99. {
  100. /* Wi-Fi power regulator enable - high = enabled */
  101. gpio_direction_output(WIFI_REGEN_GPIO, 1);
  102. /*
  103. * Wait for Wi-Fi power regulator to reach a stable voltage
  104. * (soft-start time, max. 350 µs)
  105. */
  106. __udelay(350);
  107. /* Wi-Fi module reset - high = running */
  108. gpio_direction_output(WIFI_RST_GPIO, 1);
  109. /* ZigBee reset - high = running */
  110. gpio_direction_output(ZIGBEE_RST_GPIO, 1);
  111. /* BidCos reset - high = running */
  112. gpio_direction_output(BIDCOS_RST_GPIO, 1);
  113. #if !defined(CONFIG_B_SAMPLE)
  114. /* Z-Wave reset - high = running */
  115. gpio_direction_output(Z_WAVE_RST_GPIO, 1);
  116. #endif
  117. /* EnOcean reset - low = running */
  118. gpio_direction_output(ENOC_RST_GPIO, 0);
  119. }
  120. /*
  121. * Function which forces all installed modules into reset - to be released by
  122. * the OS, called by SPL
  123. */
  124. static void __maybe_unused force_modules_reset(void)
  125. {
  126. /* Wi-Fi module reset - low = reset */
  127. gpio_direction_output(WIFI_RST_GPIO, 0);
  128. /* Wi-Fi power regulator enable - low = disabled */
  129. gpio_direction_output(WIFI_REGEN_GPIO, 0);
  130. /* ZigBee reset - low = reset */
  131. gpio_direction_output(ZIGBEE_RST_GPIO, 0);
  132. /* BidCos reset - low = reset */
  133. /*gpio_direction_output(BIDCOS_RST_GPIO, 0);*/
  134. #if !defined(CONFIG_B_SAMPLE)
  135. /* Z-Wave reset - low = reset */
  136. gpio_direction_output(Z_WAVE_RST_GPIO, 0);
  137. #endif
  138. /* EnOcean reset - high = reset*/
  139. gpio_direction_output(ENOC_RST_GPIO, 1);
  140. }
  141. /*
  142. * Function to set the LEDs in the state "Bootloader booting"
  143. */
  144. static void __maybe_unused leds_set_booting(void)
  145. {
  146. #if defined(CONFIG_B_SAMPLE)
  147. /* Turn all red LEDs on */
  148. gpio_direction_output(LED_PWR_RD_GPIO, 1);
  149. gpio_direction_output(LED_CONN_RD_GPIO, 1);
  150. #else /* All other SHCs starting with B2-Sample */
  151. /* Set the PWM GPIO */
  152. gpio_direction_output(LED_PWM_GPIO, 1);
  153. /* Turn all red LEDs on */
  154. gpio_direction_output(LED_PWR_RD_GPIO, 1);
  155. gpio_direction_output(LED_LAN_RD_GPIO, 1);
  156. gpio_direction_output(LED_CLOUD_RD_GPIO, 1);
  157. #endif
  158. }
  159. /*
  160. * Function to set the LEDs in the state "Bootloader error"
  161. */
  162. static void leds_set_failure(int state)
  163. {
  164. #if defined(CONFIG_B_SAMPLE)
  165. /* Turn all blue and green LEDs off */
  166. gpio_set_value(LED_PWR_BL_GPIO, 0);
  167. gpio_set_value(LED_PWR_GN_GPIO, 0);
  168. gpio_set_value(LED_CONN_BL_GPIO, 0);
  169. gpio_set_value(LED_CONN_GN_GPIO, 0);
  170. /* Turn all red LEDs to 'state' */
  171. gpio_set_value(LED_PWR_RD_GPIO, state);
  172. gpio_set_value(LED_CONN_RD_GPIO, state);
  173. #else /* All other SHCs starting with B2-Sample */
  174. /* Set the PWM GPIO */
  175. gpio_direction_output(LED_PWM_GPIO, 1);
  176. /* Turn all blue LEDs off */
  177. gpio_set_value(LED_PWR_BL_GPIO, 0);
  178. gpio_set_value(LED_LAN_BL_GPIO, 0);
  179. gpio_set_value(LED_CLOUD_BL_GPIO, 0);
  180. /* Turn all red LEDs to 'state' */
  181. gpio_set_value(LED_PWR_RD_GPIO, state);
  182. gpio_set_value(LED_LAN_RD_GPIO, state);
  183. gpio_set_value(LED_CLOUD_RD_GPIO, state);
  184. #endif
  185. }
  186. /*
  187. * Function to set the LEDs in the state "Bootloader finished"
  188. */
  189. static void leds_set_finish(void)
  190. {
  191. #if defined(CONFIG_B_SAMPLE)
  192. /* Turn all LEDs off */
  193. gpio_set_value(LED_PWR_BL_GPIO, 0);
  194. gpio_set_value(LED_PWR_RD_GPIO, 0);
  195. gpio_set_value(LED_PWR_GN_GPIO, 0);
  196. gpio_set_value(LED_CONN_BL_GPIO, 0);
  197. gpio_set_value(LED_CONN_RD_GPIO, 0);
  198. gpio_set_value(LED_CONN_GN_GPIO, 0);
  199. #else /* All other SHCs starting with B2-Sample */
  200. /* Turn all LEDs off */
  201. gpio_set_value(LED_PWR_BL_GPIO, 0);
  202. gpio_set_value(LED_PWR_RD_GPIO, 0);
  203. gpio_set_value(LED_LAN_BL_GPIO, 0);
  204. gpio_set_value(LED_LAN_RD_GPIO, 0);
  205. gpio_set_value(LED_CLOUD_BL_GPIO, 0);
  206. gpio_set_value(LED_CLOUD_RD_GPIO, 0);
  207. /* Turn off the PWM GPIO and mux it to EHRPWM */
  208. gpio_set_value(LED_PWM_GPIO, 0);
  209. enable_shc_board_pwm_pin_mux();
  210. #endif
  211. }
  212. static void check_button_status(void)
  213. {
  214. ulong value;
  215. gpio_direction_input(FRONT_BUTTON_GPIO);
  216. value = gpio_get_value(FRONT_BUTTON_GPIO);
  217. if (value == 0) {
  218. printf("front button activated !\n");
  219. env_set("harakiri", "1");
  220. }
  221. }
  222. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  223. #ifdef CONFIG_SPL_OS_BOOT
  224. int spl_start_uboot(void)
  225. {
  226. return 1;
  227. }
  228. #endif
  229. static void shc_board_early_init(void)
  230. {
  231. shc_request_gpio();
  232. # ifdef CONFIG_SHC_ICT
  233. /* Force all modules into enabled state for ICT testing */
  234. force_modules_running();
  235. # else
  236. /* Force all modules to enter Reset state until released by the OS */
  237. force_modules_reset();
  238. # endif
  239. leds_set_booting();
  240. }
  241. #define MPU_SPREADING_PERMILLE 18 /* Spread 1.8 percent */
  242. #define OSC (V_OSCK/1000000)
  243. /* Bosch: Predivider must be fixed to 4, so N = 4-1 */
  244. #define MPUPLL_N (4-1)
  245. /* Bosch: Fref = 24 MHz / (N+1) = 24 MHz / 4 = 6 MHz */
  246. #define MPUPLL_FREF (OSC / (MPUPLL_N + 1))
  247. const struct dpll_params dpll_ddr_shc = {
  248. 400, OSC-1, 1, -1, -1, -1, -1};
  249. const struct dpll_params *get_dpll_ddr_params(void)
  250. {
  251. return &dpll_ddr_shc;
  252. }
  253. /*
  254. * As we enabled downspread SSC with 1.8%, the values needed to be corrected
  255. * such that the 20% overshoot will not lead to too high frequencies.
  256. * In all cases, this is achieved by subtracting one from M (6 MHz less).
  257. * Example: 600 MHz CPU
  258. * Step size: 24 MHz OSC, N = 4 (fix) --> Fref = 6 MHz
  259. * 600 MHz - 6 MHz (1x Fref) = 594 MHz
  260. * SSC: 594 MHz * 1.8% = 10.7 MHz SSC
  261. * Overshoot: 10.7 MHz * 20 % = 2.2 MHz
  262. * --> Fmax = 594 MHz + 2.2 MHz = 596.2 MHz, lower than 600 MHz --> OK!
  263. */
  264. const struct dpll_params dpll_mpu_shc_opp100 = {
  265. 99, MPUPLL_N, 1, -1, -1, -1, -1};
  266. void am33xx_spl_board_init(void)
  267. {
  268. int sil_rev;
  269. int mpu_vdd;
  270. puts(BOARD_ID_STR);
  271. /*
  272. * Set CORE Frequency to OPP100
  273. * Hint: DCDC3 (CORE) defaults to 1.100V (for OPP100)
  274. */
  275. do_setup_dpll(&dpll_core_regs, &dpll_core_opp100);
  276. sil_rev = readl(&cdev->deviceid) >> 28;
  277. if (sil_rev < 2) {
  278. puts("We do not support Silicon Revisions below 2.0!\n");
  279. return;
  280. }
  281. dpll_mpu_opp100.m = am335x_get_efuse_mpu_max_freq(cdev);
  282. if (i2c_probe(TPS65217_CHIP_PM))
  283. return;
  284. /*
  285. * Retrieve the CPU max frequency by reading the efuse
  286. * SHC-Default: 600 MHz
  287. */
  288. switch (dpll_mpu_opp100.m) {
  289. case MPUPLL_M_1000:
  290. mpu_vdd = TPS65217_DCDC_VOLT_SEL_1325MV;
  291. break;
  292. case MPUPLL_M_800:
  293. mpu_vdd = TPS65217_DCDC_VOLT_SEL_1275MV;
  294. break;
  295. case MPUPLL_M_720:
  296. mpu_vdd = TPS65217_DCDC_VOLT_SEL_1200MV;
  297. break;
  298. case MPUPLL_M_600:
  299. mpu_vdd = TPS65217_DCDC_VOLT_SEL_1100MV;
  300. break;
  301. case MPUPLL_M_300:
  302. mpu_vdd = TPS65217_DCDC_VOLT_SEL_950MV;
  303. break;
  304. default:
  305. puts("Cannot determine the frequency, failing!\n");
  306. return;
  307. }
  308. if (tps65217_voltage_update(TPS65217_DEFDCDC2, mpu_vdd)) {
  309. puts("tps65217_voltage_update failure\n");
  310. return;
  311. }
  312. /* Set MPU Frequency to what we detected */
  313. printf("MPU reference clock runs at %d MHz\n", MPUPLL_FREF);
  314. printf("Setting MPU clock to %d MHz\n", MPUPLL_FREF *
  315. dpll_mpu_shc_opp100.m);
  316. do_setup_dpll(&dpll_mpu_regs, &dpll_mpu_shc_opp100);
  317. /* Enable Spread Spectrum for this freq to be clean on EMI side */
  318. set_mpu_spreadspectrum(MPU_SPREADING_PERMILLE);
  319. /*
  320. * Using the default voltages for the PMIC (TPS65217D)
  321. * LS1 = 1.8V (VDD_1V8)
  322. * LS2 = 3.3V (VDD_3V3A)
  323. * LDO1 = 1.8V (VIO and VRTC)
  324. * LDO2 = 3.3V (VDD_3V3AUX)
  325. */
  326. shc_board_early_init();
  327. }
  328. void set_uart_mux_conf(void)
  329. {
  330. enable_uart0_pin_mux();
  331. }
  332. void set_mux_conf_regs(void)
  333. {
  334. enable_shc_board_pin_mux();
  335. }
  336. const struct ctrl_ioregs ioregs_evmsk = {
  337. .cm0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
  338. .cm1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
  339. .cm2ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
  340. .dt0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
  341. .dt1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
  342. };
  343. static const struct ddr_data ddr3_shc_data = {
  344. .datardsratio0 = MT41K256M16HA125E_RD_DQS,
  345. .datawdsratio0 = MT41K256M16HA125E_WR_DQS,
  346. .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
  347. .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
  348. };
  349. static const struct cmd_control ddr3_shc_cmd_ctrl_data = {
  350. .cmd0csratio = MT41K256M16HA125E_RATIO,
  351. .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
  352. .cmd1csratio = MT41K256M16HA125E_RATIO,
  353. .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
  354. .cmd2csratio = MT41K256M16HA125E_RATIO,
  355. .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
  356. };
  357. static struct emif_regs ddr3_shc_emif_reg_data = {
  358. .sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
  359. .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
  360. .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
  361. .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
  362. .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
  363. .zq_config = MT41K256M16HA125E_ZQ_CFG,
  364. .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY |
  365. PHY_EN_DYN_PWRDN,
  366. };
  367. void sdram_init(void)
  368. {
  369. /* Configure the DDR3 RAM */
  370. config_ddr(400, &ioregs_evmsk, &ddr3_shc_data,
  371. &ddr3_shc_cmd_ctrl_data, &ddr3_shc_emif_reg_data, 0);
  372. }
  373. #endif
  374. /*
  375. * Basic board specific setup. Pinmux has been handled already.
  376. */
  377. int board_init(void)
  378. {
  379. #if defined(CONFIG_HW_WATCHDOG)
  380. hw_watchdog_init();
  381. #endif
  382. i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
  383. if (read_eeprom() < 0)
  384. puts("EEPROM Content Invalid.\n");
  385. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  386. #if defined(CONFIG_NOR) || defined(CONFIG_NAND)
  387. gpmc_init();
  388. #endif
  389. shc_request_gpio();
  390. return 0;
  391. }
  392. #ifdef CONFIG_BOARD_LATE_INIT
  393. int board_late_init(void)
  394. {
  395. check_button_status();
  396. #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
  397. if (shc_eeprom_valid)
  398. if (is_valid_ethaddr(header.mac_addr))
  399. eth_env_set_enetaddr("ethaddr", header.mac_addr);
  400. #endif
  401. return 0;
  402. }
  403. #endif
  404. #ifndef CONFIG_DM_ETH
  405. #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
  406. (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
  407. static void cpsw_control(int enabled)
  408. {
  409. /* VTP can be added here */
  410. return;
  411. }
  412. static struct cpsw_slave_data cpsw_slaves[] = {
  413. {
  414. .slave_reg_ofs = 0x208,
  415. .sliver_reg_ofs = 0xd80,
  416. .phy_addr = 0,
  417. },
  418. {
  419. .slave_reg_ofs = 0x308,
  420. .sliver_reg_ofs = 0xdc0,
  421. .phy_addr = 1,
  422. },
  423. };
  424. static struct cpsw_platform_data cpsw_data = {
  425. .mdio_base = CPSW_MDIO_BASE,
  426. .cpsw_base = CPSW_BASE,
  427. .mdio_div = 0xff,
  428. .channels = 8,
  429. .cpdma_reg_ofs = 0x800,
  430. .slaves = 1,
  431. .slave_data = cpsw_slaves,
  432. .ale_reg_ofs = 0xd00,
  433. .ale_entries = 1024,
  434. .host_port_reg_ofs = 0x108,
  435. .hw_stats_reg_ofs = 0x900,
  436. .bd_ram_ofs = 0x2000,
  437. .mac_control = (1 << 5),
  438. .control = cpsw_control,
  439. .host_port_num = 0,
  440. .version = CPSW_CTRL_VERSION_2,
  441. };
  442. #endif
  443. /*
  444. * This function will:
  445. * Read the eFuse for MAC addresses, and set ethaddr/eth1addr/usbnet_devaddr
  446. * in the environment
  447. * Perform fixups to the PHY present on certain boards. We only need this
  448. * function in:
  449. * - SPL with either CPSW or USB ethernet support
  450. * - Full U-Boot, with either CPSW or USB ethernet
  451. * Build in only these cases to avoid warnings about unused variables
  452. * when we build an SPL that has neither option but full U-Boot will.
  453. */
  454. #if ((defined(CONFIG_SPL_ETH_SUPPORT) || \
  455. defined(CONFIG_SPL_USB_ETHER)) && \
  456. defined(CONFIG_SPL_BUILD)) || \
  457. ((defined(CONFIG_DRIVER_TI_CPSW) || \
  458. defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET)) && \
  459. !defined(CONFIG_SPL_BUILD))
  460. int board_eth_init(bd_t *bis)
  461. {
  462. int rv, n = 0;
  463. uint8_t mac_addr[6];
  464. uint32_t mac_hi, mac_lo;
  465. /* try reading mac address from efuse */
  466. mac_lo = readl(&cdev->macid0l);
  467. mac_hi = readl(&cdev->macid0h);
  468. mac_addr[0] = mac_hi & 0xFF;
  469. mac_addr[1] = (mac_hi & 0xFF00) >> 8;
  470. mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
  471. mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
  472. mac_addr[4] = mac_lo & 0xFF;
  473. mac_addr[5] = (mac_lo & 0xFF00) >> 8;
  474. #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
  475. (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
  476. if (!env_get("ethaddr")) {
  477. printf("<ethaddr> not set. Validating first E-fuse MAC\n");
  478. if (is_valid_ethaddr(mac_addr))
  479. eth_env_set_enetaddr("ethaddr", mac_addr);
  480. }
  481. writel(MII_MODE_ENABLE, &cdev->miisel);
  482. cpsw_slaves[0].phy_if = PHY_INTERFACE_MODE_MII;
  483. cpsw_slaves[1].phy_if = cpsw_slaves[0].phy_if;
  484. rv = cpsw_register(&cpsw_data);
  485. if (rv < 0)
  486. printf("Error %d registering CPSW switch\n", rv);
  487. else
  488. n += rv;
  489. #endif
  490. #if defined(CONFIG_USB_ETHER) && \
  491. (!defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_USB_ETHER))
  492. if (is_valid_ethaddr(mac_addr))
  493. eth_env_set_enetaddr("usbnet_devaddr", mac_addr);
  494. rv = usb_eth_initialize(bis);
  495. if (rv < 0)
  496. printf("Error %d registering USB_ETHER\n", rv);
  497. else
  498. n += rv;
  499. #endif
  500. return n;
  501. }
  502. #endif
  503. #endif /* CONFIG_DM_ETH */
  504. #ifdef CONFIG_SHOW_BOOT_PROGRESS
  505. static void bosch_check_reset_pin(void)
  506. {
  507. if (readl(GPIO1_BASE + OMAP_GPIO_IRQSTATUS_SET_0) & RESET_MASK) {
  508. printf("Resetting ...\n");
  509. writel(RESET_MASK, GPIO1_BASE + OMAP_GPIO_IRQSTATUS_SET_0);
  510. disable_interrupts();
  511. reset_cpu(0);
  512. /*NOTREACHED*/
  513. }
  514. }
  515. static void hang_bosch(const char *cause, int code)
  516. {
  517. int lv;
  518. gpio_direction_input(RESET_GPIO);
  519. /* Enable reset pin interrupt on falling edge */
  520. writel(RESET_MASK, GPIO1_BASE + OMAP_GPIO_IRQSTATUS_SET_0);
  521. writel(RESET_MASK, GPIO1_BASE + OMAP_GPIO_FALLINGDETECT);
  522. enable_interrupts();
  523. puts(cause);
  524. for (;;) {
  525. for (lv = 0; lv < code; lv++) {
  526. bosch_check_reset_pin();
  527. leds_set_failure(1);
  528. __udelay(150 * 1000);
  529. leds_set_failure(0);
  530. __udelay(150 * 1000);
  531. }
  532. #if defined(BLINK_CODE)
  533. __udelay(300 * 1000);
  534. #endif
  535. }
  536. }
  537. void show_boot_progress(int val)
  538. {
  539. switch (val) {
  540. case BOOTSTAGE_ID_NEED_RESET:
  541. hang_bosch("need reset", 4);
  542. break;
  543. }
  544. }
  545. #endif
  546. void arch_preboot_os(void)
  547. {
  548. leds_set_finish();
  549. }
  550. #if defined(CONFIG_MMC)
  551. int board_mmc_init(bd_t *bis)
  552. {
  553. int ret;
  554. /* Bosch: Do not enable 52MHz for eMMC device to avoid EMI */
  555. ret = omap_mmc_init(0, MMC_MODE_HS_52MHz, 26000000, -1, -1);
  556. if (ret)
  557. return ret;
  558. ret = omap_mmc_init(1, MMC_MODE_HS_52MHz, 26000000, -1, -1);
  559. return ret;
  560. }
  561. #endif