tricorder.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. * (C) Copyright 2012
  3. * Corscience GmbH & Co. KG, <www.corscience.de>
  4. * Thomas Weber <weber@corscience.de>
  5. * Sunil Kumar <sunilsaini05@gmail.com>
  6. * Shashi Ranjan <shashiranjanmca05@gmail.com>
  7. *
  8. * Derived from Devkit8000 code by
  9. * Frederik Kriewitz <frederik@kriewitz.eu>
  10. *
  11. * SPDX-License-Identifier: GPL-2.0+
  12. */
  13. #include <common.h>
  14. #include <twl4030.h>
  15. #include <asm/io.h>
  16. #include <asm/gpio.h>
  17. #include <asm/arch/mmc_host_def.h>
  18. #include <asm/arch/mux.h>
  19. #include <asm/arch/sys_proto.h>
  20. #include <asm/arch/mem.h>
  21. #include "tricorder.h"
  22. #include "tricorder-eeprom.h"
  23. DECLARE_GLOBAL_DATA_PTR;
  24. /*
  25. * Routine: board_init
  26. * Description: Early hardware init.
  27. */
  28. int board_init(void)
  29. {
  30. gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
  31. /* boot param addr */
  32. gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
  33. return 0;
  34. }
  35. /**
  36. * get_eeprom - read the eeprom
  37. *
  38. * @eeprom - pointer to a eeprom struct to fill
  39. *
  40. * This function will panic() on wrong EEPROM content
  41. */
  42. static void get_eeprom(struct tricorder_eeprom *eeprom)
  43. {
  44. int ret;
  45. if (!eeprom)
  46. panic("No eeprom given!\n");
  47. ret = gpio_request(7, "BMS");
  48. if (ret)
  49. panic("gpio: requesting BMS pin failed\n");
  50. ret = gpio_direction_input(7);
  51. if (ret)
  52. panic("gpio: set BMS as input failed\n");
  53. ret = gpio_get_value(7);
  54. if (ret < 0)
  55. panic("gpio: get BMS pin state failed\n");
  56. gpio_free(7);
  57. if (ret == 0) {
  58. /* BMS is _not_ set, do the EEPROM check */
  59. ret = tricorder_get_eeprom(0x51, eeprom);
  60. if (!ret) {
  61. if (strncmp(eeprom->board_name, "CS10411", 7) != 0)
  62. panic("Wrong board name '%.*s'\n",
  63. sizeof(eeprom->board_name),
  64. eeprom->board_name);
  65. if (eeprom->board_version[0] < 'D')
  66. panic("Wrong board version '%.*s'\n",
  67. sizeof(eeprom->board_version),
  68. eeprom->board_version);
  69. } else {
  70. panic("Could not get board revision\n");
  71. }
  72. } else {
  73. memset(eeprom, 0, TRICORDER_EEPROM_SIZE);
  74. }
  75. }
  76. /**
  77. * print_hwversion - print out a HW version string
  78. *
  79. * @eeprom - pointer to the eeprom
  80. */
  81. static void print_hwversion(struct tricorder_eeprom *eeprom)
  82. {
  83. size_t len;
  84. if (!eeprom)
  85. panic("No eeprom given!");
  86. printf("Board %.*s:%.*s serial %.*s",
  87. sizeof(eeprom->board_name), eeprom->board_name,
  88. sizeof(eeprom->board_version), eeprom->board_version,
  89. sizeof(eeprom->board_serial), eeprom->board_serial);
  90. len = strnlen(eeprom->interface_version,
  91. sizeof(eeprom->interface_version));
  92. if (len > 0)
  93. printf(" HW interface version %.*s",
  94. sizeof(eeprom->interface_version),
  95. eeprom->interface_version);
  96. puts("\n");
  97. }
  98. /*
  99. * Routine: misc_init_r
  100. * Description: Configure board specific parts
  101. */
  102. int misc_init_r(void)
  103. {
  104. struct tricorder_eeprom eeprom;
  105. get_eeprom(&eeprom);
  106. print_hwversion(&eeprom);
  107. twl4030_power_init();
  108. status_led_set(0, CONFIG_LED_STATUS_ON);
  109. status_led_set(1, CONFIG_LED_STATUS_ON);
  110. status_led_set(2, CONFIG_LED_STATUS_ON);
  111. omap_die_id_display();
  112. return 0;
  113. }
  114. /*
  115. * Routine: set_muxconf_regs
  116. * Description: Setting up the configuration Mux registers specific to the
  117. * hardware. Many pins need to be moved from protect to primary
  118. * mode.
  119. */
  120. void set_muxconf_regs(void)
  121. {
  122. MUX_TRICORDER();
  123. }
  124. #if defined(CONFIG_MMC)
  125. int board_mmc_init(bd_t *bis)
  126. {
  127. return omap_mmc_init(0, 0, 0, -1, -1);
  128. }
  129. #endif
  130. #if defined(CONFIG_MMC)
  131. void board_mmc_power_init(void)
  132. {
  133. twl4030_power_mmc_init(0);
  134. }
  135. #endif
  136. /*
  137. * Routine: get_board_mem_timings
  138. * Description: If we use SPL then there is no x-loader nor config header
  139. * so we have to setup the DDR timings ourself on the first bank. This
  140. * provides the timing values back to the function that configures
  141. * the memory. We have either one or two banks of 128MB DDR.
  142. */
  143. void get_board_mem_timings(struct board_sdrc_timings *timings)
  144. {
  145. struct tricorder_eeprom eeprom;
  146. get_eeprom(&eeprom);
  147. /* General SDRC config */
  148. if (eeprom.board_version[0] > 'D') {
  149. /* use optimized timings for our SDRAM device */
  150. timings->mcfg = MCFG((256 << 20), 14);
  151. #define MT46H64M32_TDAL 6 /* Twr/Tck + Trp/tck */
  152. /* 15/6 + 18/6 = 5.5 -> 6 */
  153. #define MT46H64M32_TDPL 3 /* 15/6 = 2.5 -> 3 (Twr) */
  154. #define MT46H64M32_TRRD 2 /* 12/6 = 2 */
  155. #define MT46H64M32_TRCD 3 /* 18/6 = 3 */
  156. #define MT46H64M32_TRP 3 /* 18/6 = 3 */
  157. #define MT46H64M32_TRAS 7 /* 42/6 = 7 */
  158. #define MT46H64M32_TRC 10 /* 60/6 = 10 */
  159. #define MT46H64M32_TRFC 12 /* 72/6 = 12 */
  160. timings->ctrla = ACTIM_CTRLA(MT46H64M32_TRFC, MT46H64M32_TRC,
  161. MT46H64M32_TRAS, MT46H64M32_TRP,
  162. MT46H64M32_TRCD, MT46H64M32_TRRD,
  163. MT46H64M32_TDPL,
  164. MT46H64M32_TDAL);
  165. #define MT46H64M32_TWTR 1
  166. #define MT46H64M32_TCKE 1
  167. #define MT46H64M32_XSR 19 /* 112.5/6 = 18.75 => ~19 */
  168. #define MT46H64M32_TXP 1
  169. timings->ctrlb = ACTIM_CTRLB(MT46H64M32_TWTR, MT46H64M32_TCKE,
  170. MT46H64M32_TXP, MT46H64M32_XSR);
  171. timings->mr = MICRON_V_MR_165;
  172. timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
  173. } else {
  174. /* use conservative beagleboard timings as default */
  175. timings->mcfg = MICRON_V_MCFG_165(128 << 20);
  176. timings->ctrla = MICRON_V_ACTIMA_165;
  177. timings->ctrlb = MICRON_V_ACTIMB_165;
  178. timings->mr = MICRON_V_MR_165;
  179. timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
  180. }
  181. }