tricorder.c 5.2 KB

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