ipam390.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. /*
  2. * (C) Heiko Schocher, DENX Software Engineering, hs@denx.de.
  3. * Based on:
  4. * U-Boot:board/davinci/da8xxevm/da850evm.c
  5. *
  6. * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
  7. *
  8. * Based on da830evm.c. Original Copyrights follow:
  9. *
  10. * Copyright (C) 2009 Nick Thompson, GE Fanuc, Ltd. <nick.thompson@gefanuc.com>
  11. * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
  12. *
  13. * SPDX-License-Identifier: GPL-2.0+
  14. */
  15. #include <common.h>
  16. #include <i2c.h>
  17. #include <net.h>
  18. #include <netdev.h>
  19. #include <spi.h>
  20. #include <spi_flash.h>
  21. #include <asm/arch/hardware.h>
  22. #include <asm/ti-common/davinci_nand.h>
  23. #include <asm/arch/emac_defs.h>
  24. #include <asm/arch/pinmux_defs.h>
  25. #include <asm/io.h>
  26. #include <asm/arch/davinci_misc.h>
  27. #include <linux/errno.h>
  28. #include <asm/gpio.h>
  29. #include <hwconfig.h>
  30. #include <bootstage.h>
  31. DECLARE_GLOBAL_DATA_PTR;
  32. #ifdef CONFIG_DRIVER_TI_EMAC
  33. #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
  34. #define HAS_RMII 1
  35. #else
  36. #define HAS_RMII 0
  37. #endif
  38. #endif /* CONFIG_DRIVER_TI_EMAC */
  39. void dsp_lpsc_on(unsigned domain, unsigned int id)
  40. {
  41. dv_reg_p mdstat, mdctl, ptstat, ptcmd;
  42. struct davinci_psc_regs *psc_regs;
  43. psc_regs = davinci_psc0_regs;
  44. mdstat = &psc_regs->psc0.mdstat[id];
  45. mdctl = &psc_regs->psc0.mdctl[id];
  46. ptstat = &psc_regs->ptstat;
  47. ptcmd = &psc_regs->ptcmd;
  48. while (*ptstat & (0x1 << domain))
  49. ;
  50. if ((*mdstat & 0x1f) == 0x03)
  51. return; /* Already on and enabled */
  52. *mdctl |= 0x03;
  53. *ptcmd = 0x1 << domain;
  54. while (*ptstat & (0x1 << domain))
  55. ;
  56. while ((*mdstat & 0x1f) != 0x03)
  57. ; /* Probably an overkill... */
  58. }
  59. static void dspwake(void)
  60. {
  61. unsigned *resetvect = (unsigned *)DAVINCI_L3CBARAM_BASE;
  62. u32 val;
  63. /* if the device is ARM only, return */
  64. if ((readl(CHIP_REV_ID_REG) & 0x3f) == 0x10)
  65. return;
  66. if (hwconfig_subarg_cmp_f("dsp", "wake", "no", NULL))
  67. return;
  68. *resetvect++ = 0x1E000; /* DSP Idle */
  69. /* clear out the next 10 words as NOP */
  70. memset(resetvect, 0, sizeof(unsigned) * 10);
  71. /* setup the DSP reset vector */
  72. writel(DAVINCI_L3CBARAM_BASE, HOST1CFG);
  73. dsp_lpsc_on(1, DAVINCI_LPSC_GEM);
  74. val = readl(PSC0_MDCTL + (15 * 4));
  75. val |= 0x100;
  76. writel(val, (PSC0_MDCTL + (15 * 4)));
  77. }
  78. int misc_init_r(void)
  79. {
  80. dspwake();
  81. return 0;
  82. }
  83. static const struct pinmux_config gpio_pins[] = {
  84. /* GP7[14] selects bootmode*/
  85. { pinmux(16), 8, 3 }, /* GP7[14] */
  86. };
  87. const struct pinmux_resource pinmuxes[] = {
  88. #ifdef CONFIG_DRIVER_TI_EMAC
  89. PINMUX_ITEM(emac_pins_mdio),
  90. #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
  91. PINMUX_ITEM(emac_pins_rmii),
  92. #else
  93. PINMUX_ITEM(emac_pins_mii),
  94. #endif
  95. #endif
  96. PINMUX_ITEM(uart2_pins_txrx),
  97. PINMUX_ITEM(uart2_pins_rtscts),
  98. PINMUX_ITEM(uart0_pins_txrx),
  99. PINMUX_ITEM(uart0_pins_rtscts),
  100. #ifdef CONFIG_NAND_DAVINCI
  101. PINMUX_ITEM(emifa_pins_cs3),
  102. PINMUX_ITEM(emifa_pins_nand),
  103. #endif
  104. PINMUX_ITEM(gpio_pins),
  105. };
  106. const int pinmuxes_size = ARRAY_SIZE(pinmuxes);
  107. const struct lpsc_resource lpsc[] = {
  108. { DAVINCI_LPSC_AEMIF }, /* NAND, NOR */
  109. { DAVINCI_LPSC_EMAC }, /* image download */
  110. { DAVINCI_LPSC_UART2 }, /* console */
  111. { DAVINCI_LPSC_UART0 }, /* console */
  112. { DAVINCI_LPSC_GPIO },
  113. };
  114. const int lpsc_size = ARRAY_SIZE(lpsc);
  115. #ifndef CONFIG_DA850_EVM_MAX_CPU_CLK
  116. #define CONFIG_DA850_EVM_MAX_CPU_CLK 300000000
  117. #endif
  118. #define REV_AM18X_EVM 0x100
  119. /*
  120. * get_board_rev() - setup to pass kernel board revision information
  121. * Returns:
  122. * bit[0-3] Maximum cpu clock rate supported by onboard SoC
  123. * 0000b - 300 MHz
  124. * 0001b - 372 MHz
  125. * 0010b - 408 MHz
  126. * 0011b - 456 MHz
  127. */
  128. u32 get_board_rev(void)
  129. {
  130. char *s;
  131. u32 maxcpuclk = CONFIG_DA850_EVM_MAX_CPU_CLK;
  132. u32 rev = 0;
  133. s = getenv("maxcpuclk");
  134. if (s)
  135. maxcpuclk = simple_strtoul(s, NULL, 10);
  136. if (maxcpuclk >= 456000000)
  137. rev = 3;
  138. else if (maxcpuclk >= 408000000)
  139. rev = 2;
  140. else if (maxcpuclk >= 372000000)
  141. rev = 1;
  142. #ifdef CONFIG_DA850_AM18X_EVM
  143. rev |= REV_AM18X_EVM;
  144. #endif
  145. return rev;
  146. }
  147. int board_early_init_f(void)
  148. {
  149. /*
  150. * Power on required peripherals
  151. * ARM does not have access by default to PSC0 and PSC1
  152. * assuming here that the DSP bootloader has set the IOPU
  153. * such that PSC access is available to ARM
  154. */
  155. if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc)))
  156. return 1;
  157. return 0;
  158. }
  159. int board_init(void)
  160. {
  161. #ifndef CONFIG_USE_IRQ
  162. irq_init();
  163. #endif
  164. /* arch number of the board */
  165. gd->bd->bi_arch_number = MACH_TYPE_DAVINCI_DA850_EVM;
  166. /* address of boot parameters */
  167. gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
  168. /* setup the SUSPSRC for ARM to control emulation suspend */
  169. writel(readl(&davinci_syscfg_regs->suspsrc) &
  170. ~(DAVINCI_SYSCFG_SUSPSRC_EMAC | DAVINCI_SYSCFG_SUSPSRC_I2C |
  171. DAVINCI_SYSCFG_SUSPSRC_SPI1 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 |
  172. DAVINCI_SYSCFG_SUSPSRC_UART0),
  173. &davinci_syscfg_regs->suspsrc);
  174. /* configure pinmux settings */
  175. if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes)))
  176. return 1;
  177. #ifdef CONFIG_DRIVER_TI_EMAC
  178. davinci_emac_mii_mode_sel(HAS_RMII);
  179. #endif /* CONFIG_DRIVER_TI_EMAC */
  180. /* enable the console UART */
  181. writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST |
  182. DAVINCI_UART_PWREMU_MGMT_UTRST),
  183. #if (CONFIG_SYS_NS16550_COM1 == DAVINCI_UART0_BASE)
  184. &davinci_uart0_ctrl_regs->pwremu_mgmt);
  185. #else
  186. &davinci_uart2_ctrl_regs->pwremu_mgmt);
  187. #endif
  188. return 0;
  189. }
  190. #ifdef CONFIG_DRIVER_TI_EMAC
  191. /*
  192. * Initializes on-board ethernet controllers.
  193. */
  194. int board_eth_init(bd_t *bis)
  195. {
  196. if (!davinci_emac_initialize()) {
  197. printf("Error: Ethernet init failed!\n");
  198. return -1;
  199. }
  200. return 0;
  201. }
  202. #endif /* CONFIG_DRIVER_TI_EMAC */
  203. static int init_led(int gpio, char *name, int val)
  204. {
  205. int ret;
  206. ret = gpio_request(gpio, name);
  207. if (ret)
  208. return -1;
  209. ret = gpio_direction_output(gpio, val);
  210. if (ret)
  211. return -1;
  212. return gpio;
  213. }
  214. #define LED_ON 0
  215. #define LED_OFF 1
  216. #if !defined(CONFIG_SPL_BUILD)
  217. #ifdef CONFIG_SHOW_BOOT_PROGRESS
  218. void show_boot_progress(int status)
  219. {
  220. static int red;
  221. static int green;
  222. if (red == 0)
  223. red = init_led(CONFIG_IPAM390_GPIO_LED_RED, "red", LED_ON);
  224. if (red != CONFIG_IPAM390_GPIO_LED_RED)
  225. return;
  226. if (green == 0)
  227. green = init_led(CONFIG_IPAM390_GPIO_LED_GREEN, "green",
  228. LED_OFF);
  229. if (green != CONFIG_IPAM390_GPIO_LED_GREEN)
  230. return;
  231. switch (status) {
  232. case BOOTSTAGE_ID_RUN_OS:
  233. /*
  234. * set normal state
  235. * LED Red : on
  236. * LED green: off
  237. */
  238. gpio_set_value(red, LED_ON);
  239. gpio_set_value(green, LED_OFF);
  240. break;
  241. case BOOTSTAGE_ID_MAIN_LOOP:
  242. /*
  243. * U-Boot operation
  244. * LED Red : on
  245. * LED green: on
  246. */
  247. gpio_set_value(red, LED_ON);
  248. gpio_set_value(green, LED_ON);
  249. break;
  250. }
  251. }
  252. #endif
  253. #endif
  254. #ifdef CONFIG_SPL_OS_BOOT
  255. int spl_start_uboot(void)
  256. {
  257. int ret;
  258. int bootmode = 0;
  259. /*
  260. * GP7[14] selects bootmode:
  261. * 1: boot linux
  262. * 0: boot u-boot
  263. * if error accessing gpio boot U-Boot
  264. *
  265. * SPL bootmode
  266. * 0: boot linux
  267. * 1: boot u-boot
  268. */
  269. ret = gpio_request(CONFIG_IPAM390_GPIO_BOOTMODE , "bootmode");
  270. if (ret)
  271. bootmode = 1;
  272. if (!bootmode) {
  273. ret = gpio_direction_input(CONFIG_IPAM390_GPIO_BOOTMODE);
  274. if (ret)
  275. bootmode = 1;
  276. }
  277. if (!bootmode)
  278. ret = gpio_get_value(CONFIG_IPAM390_GPIO_BOOTMODE);
  279. if (!bootmode)
  280. if (ret == 0)
  281. bootmode = 1;
  282. /*
  283. * LED red : on
  284. * LED green: off
  285. */
  286. init_led(CONFIG_IPAM390_GPIO_LED_RED, "red", LED_ON);
  287. init_led(CONFIG_IPAM390_GPIO_LED_GREEN, "green", LED_OFF);
  288. return bootmode;
  289. }
  290. #endif