imx: kontron-sl-mx8mm: Add support for Kontron Electronics SoM SL i.MX8MM OSM-S

This adds support for the Kontron Electronics SoM SL i.MX8MM OSM-S
and the matching baseboard BL i.MX8MM OSM-S.

The SoM hardware complies to the Open Standard Module (OSM) 1.0
specification, size S (https://sget.org/standards/osm).

The existing board configuration for the non-OSM SoM is reused and
allows to detect the SoM variant at runtime.

Signed-off-by: Frieder Schrempf <frieder.schrempf@kontron.de>
Reviewed-by: Fabio Estevam <festevam@denx.de>
diff --git a/board/kontron/sl-mx8mm/sl-mx8mm.c b/board/kontron/sl-mx8mm/sl-mx8mm.c
index 6e73ede..6411301 100644
--- a/board/kontron/sl-mx8mm/sl-mx8mm.c
+++ b/board/kontron/sl-mx8mm/sl-mx8mm.c
@@ -123,7 +123,12 @@
 
 int board_late_init(void)
 {
-	env_set("som_type", "sl");
+	if (!fdt_node_check_compatible(gd->fdt_blob, 0, "kontron,imx8mm-n802x-som") ||
+	    !fdt_node_check_compatible(gd->fdt_blob, 0, "kontron,imx8mm-osm-s")) {
+		env_set("som_type", "osm-s");
+	else
+		env_set("som_type", "sl");
+
 	return 0;
 }
 
diff --git a/board/kontron/sl-mx8mm/spl.c b/board/kontron/sl-mx8mm/spl.c
index 403ab9a..8e7d017 100644
--- a/board/kontron/sl-mx8mm/spl.c
+++ b/board/kontron/sl-mx8mm/spl.c
@@ -29,6 +29,7 @@
 
 enum {
 	BOARD_TYPE_KTN_N801X,
+	BOARD_TYPE_KTN_N802X,
 	BOARD_TYPE_MAX
 };
 
@@ -110,11 +111,24 @@
 
 int do_board_detect(void)
 {
-	gd->board_type = BOARD_TYPE_KTN_N801X;
-	printf("Kontron SL i.MX8MM (N801X) module, %u GB RAM detected\n",
-	       (unsigned int)gd->ram_size);
+	struct udevice *udev;
 
 	/*
+	 * Check for the RTC on the OSM module.
+	 */
+	imx_iomux_v3_setup_multiple_pads(i2c1_pads, ARRAY_SIZE(i2c1_pads));
+
+	if (i2c_get_chip_for_busnum(0, 0x52, 0, &udev) == 0) {
+		gd->board_type = BOARD_TYPE_KTN_N802X;
+		printf("Kontron OSM-S i.MX8MM (N802X) module, %u GB RAM detected\n",
+		       (unsigned int)gd->ram_size);
+	} else {
+		gd->board_type = BOARD_TYPE_KTN_N801X;
+		printf("Kontron SL i.MX8MM (N801X) module, %u GB RAM detected\n",
+		       (unsigned int)gd->ram_size);
+	}
+
+	/*
 	 * Check the I2C PMIC to detect the deprecated SoM with DA9063.
 	 */
 	imx_iomux_v3_setup_multiple_pads(i2c1_pads, ARRAY_SIZE(i2c1_pads));
@@ -135,6 +149,11 @@
 	     !strcmp(name, "imx8mm-kontron-bl")))
 		return 0;
 
+	if (gd->board_type == BOARD_TYPE_KTN_N802X && is_imx8mm() &&
+	    (!strcmp(name, "imx8mm-kontron-n802x-s") ||
+	     !strcmp(name, "imx8mm-kontron-bl-osm-s")))
+		return 0;
+
 	return -1;
 }