exynos5-dt-types.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2015 Samsung Electronics
  4. * Przemyslaw Marczak <p.marczak@samsung.com>
  5. */
  6. #include <common.h>
  7. #include <adc.h>
  8. #include <dm.h>
  9. #include <errno.h>
  10. #include <fdtdec.h>
  11. #include <power/pmic.h>
  12. #include <power/regulator.h>
  13. #include <power/s2mps11.h>
  14. #include <samsung/exynos5-dt-types.h>
  15. #include <samsung/misc.h>
  16. DECLARE_GLOBAL_DATA_PTR;
  17. static const struct udevice_id board_ids[] = {
  18. { .compatible = "samsung,odroidxu3", .data = EXYNOS5_BOARD_ODROID_XU3 },
  19. { .compatible = "samsung,exynos5", .data = EXYNOS5_BOARD_GENERIC },
  20. { },
  21. };
  22. /**
  23. * Odroix XU3/XU4/HC1/HC2 board revisions (from HC1+_HC2_MAIN_REV0.1_20171017.pdf):
  24. * Rev ADCmax Board
  25. * 0.1 0 XU3 0.1
  26. * 0.2 372 XU3 0.2 | XU3L - no DISPLAYPORT (probe I2C0:0x40 / INA231)
  27. * 0.3 1280 XU4 0.1
  28. * 0.4 739 XU4 0.2
  29. * 0.5 1016 XU4+Air0.1 (Passive cooling)
  30. * 0.6 1309 XU4-HC1 0.1
  31. * 0.7 1470 XU4-HC1+ 0.1 (HC2)
  32. * Use +1% for ADC value tolerance in the array below, the code loops until
  33. * the measured ADC value is lower than then ADCmax from the array.
  34. */
  35. struct odroid_rev_info odroid_info[] = {
  36. { EXYNOS5_BOARD_ODROID_XU3_REV01, 1, 10, "xu3" },
  37. { EXYNOS5_BOARD_ODROID_XU3_REV02, 2, 375, "xu3" },
  38. { EXYNOS5_BOARD_ODROID_XU4_REV01, 1, 1293, "xu4" },
  39. { EXYNOS5_BOARD_ODROID_HC1_REV01, 1, 1322, "hc1" },
  40. { EXYNOS5_BOARD_ODROID_HC2_REV01, 1, 1484, "hc1" },
  41. { EXYNOS5_BOARD_ODROID_UNKNOWN, 0, 4095, "unknown" },
  42. };
  43. static unsigned int odroid_get_rev(void)
  44. {
  45. int i;
  46. for (i = 0; i < ARRAY_SIZE(odroid_info); i++) {
  47. if (odroid_info[i].board_type == gd->board_type)
  48. return odroid_info[i].board_rev;
  49. }
  50. return 0;
  51. }
  52. static int odroid_get_board_type(void)
  53. {
  54. unsigned int adcval;
  55. int ret, i;
  56. ret = adc_channel_single_shot("adc", CONFIG_ODROID_REV_AIN, &adcval);
  57. if (ret)
  58. goto rev_default;
  59. for (i = 0; i < ARRAY_SIZE(odroid_info); i++) {
  60. /* ADC tolerance: +1% */
  61. if (adcval < odroid_info[i].adc_val)
  62. return odroid_info[i].board_type;
  63. }
  64. rev_default:
  65. return EXYNOS5_BOARD_ODROID_XU3;
  66. }
  67. /**
  68. * odroid_get_type_str - returns pointer to one of the board type string.
  69. * Board types: "xu3", "xu3-lite", "xu4". However the "xu3lite" can be
  70. * detected only when the i2c controller is ready to use. Fortunately,
  71. * XU3 and XU3L are compatible, and the information about board lite
  72. * revision is needed before booting the linux, to set proper environment
  73. * variable: $fdtfile.
  74. */
  75. static const char *odroid_get_type_str(void)
  76. {
  77. const char *type_xu3l = "xu3-lite";
  78. struct udevice *dev, *chip;
  79. int i, ret;
  80. if (gd->board_type != EXYNOS5_BOARD_ODROID_XU3_REV02)
  81. goto exit;
  82. ret = pmic_get("s2mps11", &dev);
  83. if (ret)
  84. goto exit;
  85. /* Enable LDO26: 3.0V */
  86. ret = pmic_reg_write(dev, S2MPS11_REG_L26CTRL,
  87. S2MPS11_LDO26_ENABLE);
  88. if (ret)
  89. goto exit;
  90. /* Check XU3Lite by probe INA231 I2C0:0x40 */
  91. ret = uclass_get_device(UCLASS_I2C, 0, &dev);
  92. if (ret)
  93. goto exit;
  94. ret = dm_i2c_probe(dev, 0x40, 0x0, &chip);
  95. if (ret)
  96. return type_xu3l;
  97. exit:
  98. for (i = 0; i < ARRAY_SIZE(odroid_info); i++) {
  99. if (odroid_info[i].board_type == gd->board_type)
  100. return odroid_info[i].name;
  101. }
  102. return NULL;
  103. }
  104. bool board_is_odroidxu3(void)
  105. {
  106. if (gd->board_type >= EXYNOS5_BOARD_ODROID_XU3 &&
  107. gd->board_type <= EXYNOS5_BOARD_ODROID_XU3_REV02)
  108. return true;
  109. return false;
  110. }
  111. bool board_is_odroidxu4(void)
  112. {
  113. if (gd->board_type == EXYNOS5_BOARD_ODROID_XU4_REV01)
  114. return true;
  115. return false;
  116. }
  117. bool board_is_odroidhc1(void)
  118. {
  119. if (gd->board_type == EXYNOS5_BOARD_ODROID_HC1_REV01)
  120. return true;
  121. return false;
  122. }
  123. bool board_is_odroidhc2(void)
  124. {
  125. if (gd->board_type == EXYNOS5_BOARD_ODROID_HC2_REV01)
  126. return true;
  127. return false;
  128. }
  129. bool board_is_generic(void)
  130. {
  131. if (gd->board_type == EXYNOS5_BOARD_GENERIC)
  132. return true;
  133. return false;
  134. }
  135. /**
  136. * get_board_rev() - return detected board revision.
  137. *
  138. * @return: return board revision number for XU3 or 0 for generic
  139. */
  140. u32 get_board_rev(void)
  141. {
  142. if (board_is_generic())
  143. return 0;
  144. return odroid_get_rev();
  145. }
  146. /**
  147. * get_board_type() - returns board type string.
  148. *
  149. * @return: return board type string for XU3 or empty string for generic
  150. */
  151. const char *get_board_type(void)
  152. {
  153. const char *generic = "";
  154. if (board_is_generic())
  155. return generic;
  156. return odroid_get_type_str();
  157. }
  158. /**
  159. * set_board_type() - set board type in gd->board_type.
  160. * As default type set EXYNOS5_BOARD_GENERIC, if detect Odroid,
  161. * then set its proper type.
  162. */
  163. void set_board_type(void)
  164. {
  165. const struct udevice_id *of_match = board_ids;
  166. int ret;
  167. gd->board_type = EXYNOS5_BOARD_GENERIC;
  168. while (of_match->compatible) {
  169. ret = fdt_node_check_compatible(gd->fdt_blob, 0,
  170. of_match->compatible);
  171. if (ret)
  172. of_match++;
  173. gd->board_type = of_match->data;
  174. break;
  175. }
  176. /* If Odroid, then check its revision */
  177. if (board_is_odroidxu3())
  178. gd->board_type = odroid_get_board_type();
  179. }