board: amlogic: odroid: add runtime detection of the N2/N2+/C4/HC4 variants
authorMarek Szyprowski <m.szyprowski@samsung.com>
Wed, 3 Feb 2021 14:36:14 +0000 (15:36 +0100)
committerMarek Szyprowski <m.szyprowski@samsung.com>
Mon, 15 Nov 2021 14:18:27 +0000 (15:18 +0100)
Use the ADC channel 1 to check the hardware revision of the board and
detect the N2 vs. N2+ and the C4 vs. HC4 variants. Each of them use
different dtb file, so adjust fdtfile environment variable to the
detected variant.

The ADC min/max values for each variant are taken from the vendor code,
adjusted to the 12-bit ADC driver operation mode (vendor code use 10-bit
mode).

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Change-Id: I702a531c24b0fa9bdc1618defa1e0cc2b55c81c5

board/amlogic/odroid-n2/odroid-n2.c
configs/odroid-c4_defconfig
include/samsung/tizen_amlogic.h

index 2135457edd97938927c7e70859a4537d138a79dc..b3a355ae3aa8bd73fdab3e563d3e5c6a2d4bee34 100644 (file)
@@ -105,6 +105,82 @@ static int odroid_detect_variant(void)
        return 0;
 }
 
+/* Variant detection is based on ADC RAW values for channel 1 */
+static struct meson_odroid_boards {
+       unsigned int soc_id;
+       unsigned int adc_min;
+       unsigned int adc_max;
+       char *variant;
+} boards[] = {
+       /* OdroidN2 rev 2018,7,23 */
+       { MESON_SOC_ID_G12B, 80 * 4,  90 * 4, "n2" },
+       /* OdroidN2 rev 2018,12,6 */
+       { MESON_SOC_ID_G12B, 160 * 4, 170 * 4, "n2" },
+       /* OdroidN2 rev 2019,1,17 */
+       { MESON_SOC_ID_G12B, 245 * 4, 255 * 4, "n2" },
+       /* OdroidN2 rev 2019,2,7 */
+       { MESON_SOC_ID_G12B, 330 * 4, 350 * 4, "n2" },
+       /* OdroidN2plus rev 2019,11,20 */
+       { MESON_SOC_ID_G12B, 410 * 4, 430 * 4, "n2_plus" },
+       /* OdroidC4 rev 2020,01,29 */
+       { MESON_SOC_ID_SM1,   80 * 4, 100 * 4, "c4" },
+       /* OdroidHC4 rev 2019,12,10 */
+       { MESON_SOC_ID_SM1,  300 * 4, 320 * 4, "hc4" },
+       /* OdroidC4 rev 2019,11,29 */
+       { MESON_SOC_ID_SM1,  335 * 4, 345 * 4, "c4" },
+       /* OdroidHC4 rev 2020,8,7 */
+       { MESON_SOC_ID_SM1,  590 * 4, 610 * 4, "hc4" },
+};
+
+static void odroid_set_fdtfile(char *soc, char *variant)
+{
+       char s[128];
+
+       snprintf(s, sizeof(s), "meson64_odroid%s.dtb", variant);
+       env_set("fdtfile", s);
+
+       snprintf(s, sizeof(s), "meson-%s-odroid-%s.dtb", soc, variant);
+       env_set("fdtfile2", s);
+}
+
+static int odroid_detect_variant(void)
+{
+       char *variant = "", *soc = "";
+       unsigned int adcval = 0;
+       int ret, i, soc_id = 0;
+
+       if (of_machine_is_compatible("amlogic,sm1")) {
+               soc_id = MESON_SOC_ID_SM1;
+               soc = "sm1";
+       } else if (of_machine_is_compatible("amlogic,g12b")) {
+               soc_id = MESON_SOC_ID_G12B;
+               soc = "g12b";
+       } else {
+               return -1;
+       }
+
+       ret = adc_channel_single_shot("adc@9000", ODROID_HW_VS_ADC_CHANNEL,
+                                     &adcval);
+       if (ret)
+               return ret;
+
+       for (i = 0 ; i < ARRAY_SIZE(boards) ; ++i) {
+               if (soc_id == boards[i].soc_id &&
+                   adcval >= boards[i].adc_min &&
+                   adcval < boards[i].adc_max) {
+                       variant = boards[i].variant;
+                       break;
+               }
+       }
+
+       printf("Board variant: %s\n", variant);
+       env_set("variant", variant);
+
+       odroid_set_fdtfile(soc, variant);
+
+       return 0;
+}
+
 int misc_init_r(void)
 {
        u8 mac_addr[MAC_ADDR_LEN];
index 19c738a906d4dd25f506757d477faf7d4205ebee..4497d5d0ee58a4a9e128d04206bd5e40c975ccce 100644 (file)
@@ -39,6 +39,8 @@ CONFIG_ENV_FAT_FILE="params-c4.bin"
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
 CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG=y
 CONFIG_NET_RANDOM_ETHADDR=y
+CONFIG_ADC=y
+CONFIG_SARADC_MESON=y
 CONFIG_BUTTON=y
 CONFIG_BUTTON_GPIO=y
 CONFIG_DFU_MMC=y
index 2d08853d7264d9b779ab63ccf003ed0ef3e7c25e..655a0ee52d876f9683b1f2ca142b4ea5a736f905 100644 (file)
 #define DFU_ALT_SYSTEM                         \
        "Image.gz fat -1 1;"                    \
        "meson64_odroidn2.dtb fat -1 1;"        \
+       "meson64_odroidn2_plus.dtb fat -1 1;"   \
        "meson64_odroidc4.dtb fat -1 1;"        \
+       "meson64_odroidhc4.dtb fat -1 1;"       \
        "kvim3_linux.dtb fat -1 1;"             \
        "kvim3l_linux.dtb fat -1 1;"            \
        "meson-g12b-odroid-n2.dtb fat -1 1;"    \
+       "meson-g12b-odroid-n2_plus.dtb fat -1 1;" \
        "meson-sm1-odroid-c4.dtb fat -1 1;"     \
+       "meson-sm1-odroid-hc4.dtb fat -1 1;"    \
        "meson-g12b-a311d-khadas-vim3.dtb fat -1 1;" \
        "meson-sm1-khadas-vim3l.dtb fat -1 1;"  \
        "boot.scr.uimg fat -1 1;"               \