calimain.c 3.2 KB

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