calimain.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. */
  24. #include <common.h>
  25. #include <i2c.h>
  26. #include <net.h>
  27. #include <netdev.h>
  28. #include <watchdog.h>
  29. #include <asm/io.h>
  30. #include <asm/arch/hardware.h>
  31. #include <asm/arch/gpio.h>
  32. #include <asm/arch/emif_defs.h>
  33. #include <asm/arch/emac_defs.h>
  34. #include <asm/arch/pinmux_defs.h>
  35. #include <asm/arch/davinci_misc.h>
  36. #include <asm/arch/timer_defs.h>
  37. DECLARE_GLOBAL_DATA_PTR;
  38. #define CALIMAIN_HWVERSION_MASK 0x7f000000
  39. #define CALIMAIN_HWVERSION_SHIFT 24
  40. /* Hardware version pinmux settings */
  41. const struct pinmux_config hwversion_pins[] = {
  42. { pinmux(16), 8, 2 }, /* GP7[15] */
  43. { pinmux(16), 8, 3 }, /* GP7[14] */
  44. { pinmux(16), 8, 4 }, /* GP7[13] */
  45. { pinmux(16), 8, 5 }, /* GP7[12] */
  46. { pinmux(16), 8, 6 }, /* GP7[11] */
  47. { pinmux(16), 8, 7 }, /* GP7[10] */
  48. { pinmux(17), 8, 0 }, /* GP7[9] */
  49. { pinmux(17), 8, 1 } /* GP7[8] */
  50. };
  51. const struct pinmux_resource pinmuxes[] = {
  52. PINMUX_ITEM(uart2_pins_txrx),
  53. PINMUX_ITEM(emac_pins_mii),
  54. PINMUX_ITEM(emac_pins_mdio),
  55. PINMUX_ITEM(emifa_pins_nor),
  56. PINMUX_ITEM(emifa_pins_cs2),
  57. PINMUX_ITEM(emifa_pins_cs3),
  58. };
  59. const int pinmuxes_size = ARRAY_SIZE(pinmuxes);
  60. const struct lpsc_resource lpsc[] = {
  61. { DAVINCI_LPSC_AEMIF }, /* NAND, NOR */
  62. { DAVINCI_LPSC_EMAC }, /* image download */
  63. { DAVINCI_LPSC_UART2 }, /* console */
  64. { DAVINCI_LPSC_GPIO },
  65. };
  66. const int lpsc_size = ARRAY_SIZE(lpsc);
  67. /* read board revision from GPIO7[8..14] */
  68. u32 get_board_rev(void)
  69. {
  70. lpsc_on(DAVINCI_LPSC_GPIO);
  71. if (davinci_configure_pin_mux(hwversion_pins,
  72. ARRAY_SIZE(hwversion_pins)) != 0)
  73. return 0xffffffff;
  74. return (davinci_gpio_bank67->in_data & CALIMAIN_HWVERSION_MASK)
  75. >> CALIMAIN_HWVERSION_SHIFT;
  76. }
  77. /*
  78. * determine the oscillator frequency depending on the board revision
  79. *
  80. * rev 0x00 ... 25 MHz oscillator
  81. * rev 0x01 ... 24 MHz oscillator
  82. */
  83. int calimain_get_osc_freq(void)
  84. {
  85. u32 rev;
  86. int freq;
  87. rev = get_board_rev();
  88. switch (rev) {
  89. case 0x00:
  90. freq = 25000000;
  91. break;
  92. default:
  93. freq = 24000000;
  94. break;
  95. }
  96. return freq;
  97. }
  98. int board_init(void)
  99. {
  100. int val;
  101. #ifndef CONFIG_USE_IRQ
  102. irq_init();
  103. #endif
  104. /* address of boot parameters */
  105. gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
  106. #ifdef CONFIG_DRIVER_TI_EMAC
  107. /* select emac MII mode */
  108. val = readl(&davinci_syscfg_regs->cfgchip3);
  109. val &= ~(1 << 8);
  110. writel(val, &davinci_syscfg_regs->cfgchip3);
  111. #endif /* CONFIG_DRIVER_TI_EMAC */
  112. #ifdef CONFIG_HW_WATCHDOG
  113. davinci_hw_watchdog_enable();
  114. #endif
  115. printf("Input clock frequency: %d Hz\n", calimain_get_osc_freq());
  116. printf("Board revision: %d\n", get_board_rev());
  117. return 0;
  118. }
  119. #ifdef CONFIG_DRIVER_TI_EMAC
  120. /*
  121. * Initializes on-board ethernet controllers.
  122. */
  123. int board_eth_init(bd_t *bis)
  124. {
  125. if (!davinci_emac_initialize()) {
  126. printf("Error: Ethernet init failed!\n");
  127. return -1;
  128. }
  129. return 0;
  130. }
  131. #endif /* CONFIG_DRIVER_TI_EMAC */
  132. #ifdef CONFIG_HW_WATCHDOG
  133. void hw_watchdog_reset(void)
  134. {
  135. davinci_hw_watchdog_reset();
  136. }
  137. #endif