exynos5-dt-types.c 4.2 KB

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