exynos5-dt-types: add board detection for Odroid XU3/XU3L/XU4.
This commit adds additional file with implementation of board
detection code for Odroid-XU3/XU4.
The detection depends on compatible found in fdt:
- "samsung,exynos5" - uses Exynos5 generic code
- "samsung,odroidxu3" - try detect XU3 revision
There are few revisions of Odroid XU3/XU4, each can be detected
by checking the value of channel 9 of built-in ADC:
Rev ADC Board
0.1 0 XU3 0.1
0.2 372 XU3 0.2 | XU3L - no DISPLAYPORT
0.3 1280 XU4 0.1
The detection code depends on the ADC+10% value.
Implementation of functions:
- set_board_type() - read ADC and set type
- get_board_rev() - returns board revision: 1..3
- get_board_type() - returns board type string
Additional functions with return values of bool:
- board_is_generic() - true if found compatible "samsung,exynos5"
but not "samsung,odroidxu3"
- board_is_odroidxu3() - true if found compatible "samsung,odroidxu3"
and one of XU3 revision.
- board_is_odroidxu4() - true if found compatible "samsung,odroidxu3"
and XU4 revision.
After I2C controller init, the get_board_type() can check
if the XU3 board is a "Lite" variant, by probing chip
0x40 on I2C0 (INA231 - exists only on non-lite).
This is useful for setting fdt file name at misc_init_r().
Enabled configs:
- CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
- CONFIG_ODROID_REV_AIN
- CONFIG_REVISION_TAG
- CONFIG_BOARD_TYPES
Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>
Cc: Simon Glass <sjg@chromium.org>
Tested-by: Anand Moon <linux.amoon@gmail.com>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>
diff --git a/board/samsung/common/Makefile b/board/samsung/common/Makefile
index 6cbd906..ef1a8f3 100644
--- a/board/samsung/common/Makefile
+++ b/board/samsung/common/Makefile
@@ -11,5 +11,8 @@
ifndef CONFIG_SPL_BUILD
obj-$(CONFIG_BOARD_COMMON) += board.o
-obj-$(CONFIG_EXYNOS5_DT) += exynos5-dt.o
+ifdef CONFIG_EXYNOS5_DT
+obj-y += exynos5-dt.o
+obj-$(CONFIG_BOARD_TYPES) += exynos5-dt-types.o
+endif
endif
diff --git a/board/samsung/common/exynos5-dt-types.c b/board/samsung/common/exynos5-dt-types.c
new file mode 100644
index 0000000..48fd1f7
--- /dev/null
+++ b/board/samsung/common/exynos5-dt-types.c
@@ -0,0 +1,196 @@
+/*
+ * Copyright (C) 2015 Samsung Electronics
+ * Przemyslaw Marczak <p.marczak@samsung.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <common.h>
+#include <adc.h>
+#include <dm.h>
+#include <errno.h>
+#include <fdtdec.h>
+#include <power/pmic.h>
+#include <power/regulator.h>
+#include <power/s2mps11.h>
+#include <samsung/exynos5-dt-types.h>
+#include <samsung/misc.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+static const struct udevice_id board_ids[] = {
+ { .compatible = "samsung,odroidxu3", .data = EXYNOS5_BOARD_ODROID_XU3 },
+ { .compatible = "samsung,exynos5", .data = EXYNOS5_BOARD_GENERIC },
+ { },
+};
+
+/**
+ * Odroix XU3/4 board revisions:
+ * Rev ADCmax Board
+ * 0.1 0 XU3 0.1
+ * 0.2 410 XU3 0.2 | XU3L - no DISPLAYPORT (probe I2C0:0x40 / INA231)
+ * 0.3 1408 XU4 0.1
+ * Use +10 % for ADC value tolerance.
+ */
+struct odroid_rev_info odroid_info[] = {
+ { EXYNOS5_BOARD_ODROID_XU3_REV01, 1, 10, "xu3" },
+ { EXYNOS5_BOARD_ODROID_XU3_REV02, 2, 410, "xu3" },
+ { EXYNOS5_BOARD_ODROID_XU4_REV01, 1, 1408, "xu4" },
+ { EXYNOS5_BOARD_ODROID_UNKNOWN, 0, 4095, "unknown" },
+};
+
+static unsigned int odroid_get_rev(void)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(odroid_info); i++) {
+ if (odroid_info[i].board_type == gd->board_type)
+ return odroid_info[i].board_rev;
+ }
+
+ return 0;
+}
+
+static int odroid_get_board_type(void)
+{
+ unsigned int adcval;
+ int ret, i;
+
+ ret = adc_channel_single_shot("adc", CONFIG_ODROID_REV_AIN, &adcval);
+ if (ret)
+ goto rev_default;
+
+ for (i = 0; i < ARRAY_SIZE(odroid_info); i++) {
+ /* ADC tolerance: +20 % */
+ if (adcval < odroid_info[i].adc_val)
+ return odroid_info[i].board_type;
+ }
+
+rev_default:
+ return EXYNOS5_BOARD_ODROID_XU3;
+}
+
+/**
+ * odroid_get_type_str - returns pointer to one of the board type string.
+ * Board types: "xu3", "xu3-lite", "xu4". However the "xu3lite" can be
+ * detected only when the i2c controller is ready to use. Fortunately,
+ * XU3 and XU3L are compatible, and the information about board lite
+ * revision is needed before booting the linux, to set proper environment
+ * variable: $fdtfile.
+ */
+static const char *odroid_get_type_str(void)
+{
+ const char *type_xu3l = "xu3-lite";
+ struct udevice *dev, *chip;
+ int i, ret;
+
+ if (gd->board_type != EXYNOS5_BOARD_ODROID_XU3_REV02)
+ goto exit;
+
+ ret = pmic_get("s2mps11", &dev);
+ if (ret)
+ goto exit;
+
+ /* Enable LDO26: 3.0V */
+ ret = pmic_reg_write(dev, S2MPS11_REG_L26CTRL,
+ S2MPS11_LDO26_ENABLE);
+ if (ret)
+ goto exit;
+
+ /* Check XU3Lite by probe INA231 I2C0:0x40 */
+ ret = uclass_get_device(UCLASS_I2C, 0, &dev);
+ if (ret)
+ goto exit;
+
+ ret = dm_i2c_probe(dev, 0x40, 0x0, &chip);
+ if (ret)
+ return type_xu3l;
+
+exit:
+ for (i = 0; i < ARRAY_SIZE(odroid_info); i++) {
+ if (odroid_info[i].board_type == gd->board_type)
+ return odroid_info[i].name;
+ }
+
+ return NULL;
+}
+
+bool board_is_odroidxu3(void)
+{
+ if (gd->board_type >= EXYNOS5_BOARD_ODROID_XU3 &&
+ gd->board_type <= EXYNOS5_BOARD_ODROID_XU3_REV02)
+ return true;
+
+ return false;
+}
+
+bool board_is_odroidxu4(void)
+{
+ if (gd->board_type == EXYNOS5_BOARD_ODROID_XU4_REV01)
+ return true;
+
+ return false;
+}
+
+bool board_is_generic(void)
+{
+ if (gd->board_type == EXYNOS5_BOARD_GENERIC)
+ return true;
+
+ return false;
+}
+
+/**
+ * get_board_rev() - return detected board revision.
+ *
+ * @return: return board revision number for XU3 or 0 for generic
+ */
+u32 get_board_rev(void)
+{
+ if (board_is_generic())
+ return 0;
+
+ return odroid_get_rev();
+}
+
+/**
+ * get_board_type() - returns board type string.
+ *
+ * @return: return board type string for XU3 or empty string for generic
+ */
+const char *get_board_type(void)
+{
+ const char *generic = "";
+
+ if (board_is_generic())
+ return generic;
+
+ return odroid_get_type_str();
+}
+
+/**
+ * set_board_type() - set board type in gd->board_type.
+ * As default type set EXYNOS5_BOARD_GENERIC, if detect Odroid,
+ * then set its proper type.
+ */
+void set_board_type(void)
+{
+ const struct udevice_id *of_match = board_ids;
+ int ret;
+
+ gd->board_type = EXYNOS5_BOARD_GENERIC;
+
+ while (of_match->compatible) {
+ ret = fdt_node_check_compatible(gd->fdt_blob, 0,
+ of_match->compatible);
+ if (ret)
+ of_match++;
+
+ gd->board_type = of_match->data;
+ break;
+ }
+
+ /* If Odroid, then check its revision */
+ if (board_is_odroidxu3())
+ gd->board_type = odroid_get_board_type();
+}
diff --git a/board/samsung/common/exynos5-dt.c b/board/samsung/common/exynos5-dt.c
index 4250f72..4d9e151 100644
--- a/board/samsung/common/exynos5-dt.c
+++ b/board/samsung/common/exynos5-dt.c
@@ -27,7 +27,10 @@
#include <power/pmic.h>
#include <power/max77686_pmic.h>
#include <power/regulator.h>
+#include <power/s2mps11.h>
#include <power/s5m8767.h>
+#include <samsung/exynos5-dt-types.h>
+#include <samsung/misc.h>
#include <tmu.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -335,15 +338,24 @@
#ifdef CONFIG_SET_DFU_ALT_INFO
char *get_dfu_alt_system(char *interface, char *devstr)
{
+ char *info = "Not supported!";
+
+ if (board_is_odroidxu4())
+ return info;
+
return getenv("dfu_alt_system");
}
char *get_dfu_alt_boot(char *interface, char *devstr)
{
+ char *info = "Not supported!";
struct mmc *mmc;
char *alt_boot;
int dev_num;
+ if (board_is_odroidxu4())
+ return info;
+
dev_num = simple_strtoul(devstr, NULL, 10);
mmc = find_mmc_device(dev_num);
diff --git a/configs/odroid-xu3_defconfig b/configs/odroid-xu3_defconfig
index 780dcab..4ab91fa 100644
--- a/configs/odroid-xu3_defconfig
+++ b/configs/odroid-xu3_defconfig
@@ -16,3 +16,5 @@
CONFIG_USB=y
CONFIG_DM_USB=y
CONFIG_VIDEO_BRIDGE=y
+CONFIG_ADC=y
+CONFIG_ADC_EXYNOS=y
diff --git a/include/configs/odroid_xu3.h b/include/configs/odroid_xu3.h
index 3c70158..648e48b 100644
--- a/include/configs/odroid_xu3.h
+++ b/include/configs/odroid_xu3.h
@@ -94,6 +94,8 @@
"boot.scr fat 0 1;" \
"boot.cmd fat 0 1;" \
"exynos5422-odroidxu3.dtb fat 0 1;" \
+ "exynos5422-odroidxu3-lite.dtb fat 0 1;" \
+ "exynos5422-odroidxu4.dtb fat 0 1;" \
"boot part 0 1;" \
"root part 0 2\0"
@@ -113,9 +115,19 @@
/* Enable: board/samsung/common/misc.c to use set_dfu_alt_info() */
#define CONFIG_MISC_COMMON
+#define CONFIG_MISC_INIT_R
#define CONFIG_SET_DFU_ALT_INFO
#define CONFIG_SET_DFU_ALT_BUF_LEN (SZ_1K)
+/* Set soc_rev, soc_id, board_rev, boardname, fdtfile */
+#define CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
+#define CONFIG_ODROID_REV_AIN 9
+#define CONFIG_REVISION_TAG
+#define CONFIG_BOARD_TYPES
+
+#undef CONFIG_SYS_BOARD
+#define CONFIG_SYS_BOARD "odroid"
+
/* Define new extra env settings, including DFU settings */
#undef CONFIG_EXTRA_ENV_SETTINGS
#define CONFIG_EXTRA_ENV_SETTINGS \
diff --git a/include/samsung/exynos5-dt-types.h b/include/samsung/exynos5-dt-types.h
new file mode 100644
index 0000000..479e2e7
--- /dev/null
+++ b/include/samsung/exynos5-dt-types.h
@@ -0,0 +1,27 @@
+#ifndef _EXYNOS5_DT_H_
+#define _EXYNOS5_DT_H_
+
+enum {
+ EXYNOS5_BOARD_GENERIC,
+
+ EXYNOS5_BOARD_ODROID_XU3,
+ EXYNOS5_BOARD_ODROID_XU3_REV01,
+ EXYNOS5_BOARD_ODROID_XU3_REV02,
+ EXYNOS5_BOARD_ODROID_XU4_REV01,
+ EXYNOS5_BOARD_ODROID_UNKNOWN,
+
+ EXYNOS5_BOARD_COUNT,
+};
+
+struct odroid_rev_info {
+ int board_type;
+ int board_rev;
+ int adc_val;
+ const char *name;
+};
+
+bool board_is_generic(void);
+bool board_is_odroidxu3(void);
+bool board_is_odroidxu4(void);
+
+#endif