calimain.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * Copyright (C) 2011 OMICRON electronics GmbH
  3. *
  4. * Based on da850evm.c. Original Copyrights follow:
  5. *
  6. * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
  7. * Copyright (C) 2009 Nick Thompson, GE Fanuc, Ltd. <nick.thompson@gefanuc.com>
  8. * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
  9. *
  10. * SPDX-License-Identifier: GPL-2.0+
  11. */
  12. #include <common.h>
  13. #include <i2c.h>
  14. #include <net.h>
  15. #include <netdev.h>
  16. #include <watchdog.h>
  17. #include <asm/io.h>
  18. #include <asm/arch/hardware.h>
  19. #include <asm/arch/gpio.h>
  20. #include <asm/ti-common/davinci_nand.h>
  21. #include <asm/arch/emac_defs.h>
  22. #include <asm/arch/pinmux_defs.h>
  23. #include <asm/arch/davinci_misc.h>
  24. #include <asm/arch/timer_defs.h>
  25. DECLARE_GLOBAL_DATA_PTR;
  26. #define CALIMAIN_HWVERSION_MASK 0x7f000000
  27. #define CALIMAIN_HWVERSION_SHIFT 24
  28. /* Hardware version pinmux settings */
  29. const struct pinmux_config hwversion_pins[] = {
  30. { pinmux(16), 8, 2 }, /* GP7[15] */
  31. { pinmux(16), 8, 3 }, /* GP7[14] */
  32. { pinmux(16), 8, 4 }, /* GP7[13] */
  33. { pinmux(16), 8, 5 }, /* GP7[12] */
  34. { pinmux(16), 8, 6 }, /* GP7[11] */
  35. { pinmux(16), 8, 7 }, /* GP7[10] */
  36. { pinmux(17), 8, 0 }, /* GP7[9] */
  37. { pinmux(17), 8, 1 } /* GP7[8] */
  38. };
  39. const struct pinmux_resource pinmuxes[] = {
  40. PINMUX_ITEM(uart2_pins_txrx),
  41. PINMUX_ITEM(emac_pins_mii),
  42. PINMUX_ITEM(emac_pins_mdio),
  43. PINMUX_ITEM(emifa_pins_nor),
  44. PINMUX_ITEM(emifa_pins_cs2),
  45. PINMUX_ITEM(emifa_pins_cs3),
  46. };
  47. const int pinmuxes_size = ARRAY_SIZE(pinmuxes);
  48. const struct lpsc_resource lpsc[] = {
  49. { DAVINCI_LPSC_AEMIF }, /* NAND, NOR */
  50. { DAVINCI_LPSC_EMAC }, /* image download */
  51. { DAVINCI_LPSC_UART2 }, /* console */
  52. { DAVINCI_LPSC_GPIO },
  53. };
  54. const int lpsc_size = ARRAY_SIZE(lpsc);
  55. /* read board revision from GPIO7[8..14] */
  56. u32 get_board_rev(void)
  57. {
  58. lpsc_on(DAVINCI_LPSC_GPIO);
  59. if (davinci_configure_pin_mux(hwversion_pins,
  60. ARRAY_SIZE(hwversion_pins)) != 0)
  61. return 0xffffffff;
  62. return (davinci_gpio_bank67->in_data & CALIMAIN_HWVERSION_MASK)
  63. >> CALIMAIN_HWVERSION_SHIFT;
  64. }
  65. /*
  66. * determine the oscillator frequency depending on the board revision
  67. *
  68. * rev 0x00 ... 25 MHz oscillator
  69. * rev 0x01 ... 24 MHz oscillator
  70. */
  71. int calimain_get_osc_freq(void)
  72. {
  73. u32 rev;
  74. int freq;
  75. rev = get_board_rev();
  76. switch (rev) {
  77. case 0x00:
  78. freq = 25000000;
  79. break;
  80. default:
  81. freq = 24000000;
  82. break;
  83. }
  84. return freq;
  85. }
  86. int board_init(void)
  87. {
  88. int val;
  89. #ifndef CONFIG_USE_IRQ
  90. irq_init();
  91. #endif
  92. /* address of boot parameters */
  93. gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
  94. #ifdef CONFIG_DRIVER_TI_EMAC
  95. /* select emac MII mode */
  96. val = readl(&davinci_syscfg_regs->cfgchip3);
  97. val &= ~(1 << 8);
  98. writel(val, &davinci_syscfg_regs->cfgchip3);
  99. #endif /* CONFIG_DRIVER_TI_EMAC */
  100. #ifdef CONFIG_HW_WATCHDOG
  101. davinci_hw_watchdog_enable();
  102. #endif
  103. printf("Input clock frequency: %d Hz\n", calimain_get_osc_freq());
  104. printf("Board revision: %d\n", get_board_rev());
  105. return 0;
  106. }
  107. #ifdef CONFIG_DRIVER_TI_EMAC
  108. /*
  109. * Initializes on-board ethernet controllers.
  110. */
  111. int board_eth_init(bd_t *bis)
  112. {
  113. if (!davinci_emac_initialize()) {
  114. printf("Error: Ethernet init failed!\n");
  115. return -1;
  116. }
  117. return 0;
  118. }
  119. #endif /* CONFIG_DRIVER_TI_EMAC */
  120. #ifdef CONFIG_HW_WATCHDOG
  121. void hw_watchdog_reset(void)
  122. {
  123. davinci_hw_watchdog_reset();
  124. }
  125. #endif