Merge branch '2021-10-19-assorted-changes'

- Assorted minor fixes and a new GPIO driver
diff --git a/MAINTAINERS b/MAINTAINERS
index 71f468c..8845c6f 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -756,6 +756,7 @@
 F:	include/linux/libfdt*
 F:	cmd/fdt.c
 F:	common/fdt_support.c
+F:	scripts/dtc-version.sh
 
 FREEBSD
 M:	Rafal Jaworowski <raj@semihalf.com>
diff --git a/Makefile b/Makefile
index f911f70..6f2474b 100644
--- a/Makefile
+++ b/Makefile
@@ -299,9 +299,7 @@
 # have older compilers as their default, so we make it explicit for
 # these that our host tools are GNU11 (i.e. C11 w/ GNU extensions).
 CSTD_FLAG := -std=gnu11
-ifeq ($(HOSTOS),linux)
 KBUILD_HOSTCFLAGS += $(CSTD_FLAG)
-endif
 
 ifeq ($(HOSTOS),cygwin)
 KBUILD_HOSTCFLAGS	+= -ansi
@@ -415,7 +413,13 @@
 PYTHON		?= python
 PYTHON2		= python2
 PYTHON3		?= python3
-DTC		?= $(objtree)/scripts/dtc/dtc
+
+# The devicetree compiler and pylibfdt are automatically built unless DTC is
+# provided. If DTC is provided, it is assumed the pylibfdt is available too.
+DTC_INTREE	:= $(objtree)/scripts/dtc/dtc
+DTC		?= $(DTC_INTREE)
+DTC_MIN_VERSION	:= 010406
+
 CHECK		= sparse
 
 CHECKFLAGS     := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
@@ -1954,9 +1958,29 @@
 
 endif
 
+# Check dtc and pylibfdt, if DTC is provided, else build them
 PHONY += scripts_dtc
 scripts_dtc: scripts_basic
-	$(Q)$(MAKE) $(build)=scripts/dtc
+	$(Q)if test "$(DTC)" = "$(DTC_INTREE)"; then \
+		$(MAKE) $(build)=scripts/dtc; \
+	else \
+		if ! $(DTC) -v >/dev/null; then \
+			echo '*** Failed to check dtc version: $(DTC)'; \
+			false; \
+		else \
+			if test "$(call dtc-version)" -lt $(DTC_MIN_VERSION); then \
+				echo '*** Your dtc is too old, please upgrade to dtc $(DTC_MIN_VERSION) or newer'; \
+				false; \
+			else \
+				if [ -n "$(CONFIG_PYLIBFDT)" ]; then \
+					if ! echo "import libfdt" | $(PYTHON3) 2>/dev/null; then \
+						echo '*** pylibfdt does not seem to be available with $(PYTHON3)'; \
+						false; \
+					fi; \
+				fi; \
+			fi; \
+		fi; \
+	fi
 
 # ---------------------------------------------------------------------------
 quiet_cmd_cpp_lds = LDS     $@
diff --git a/board/armltd/total_compute/total_compute.c b/board/armltd/total_compute/total_compute.c
index b7eaab0..b7772f7 100644
--- a/board/armltd/total_compute/total_compute.c
+++ b/board/armltd/total_compute/total_compute.c
@@ -59,6 +59,9 @@
 	gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
 	gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
 
+	gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
+	gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE;
+
 	return 0;
 }
 
diff --git a/configs/am335x_evm_defconfig b/configs/am335x_evm_defconfig
index 0f938e7..4dc5d0f 100644
--- a/configs/am335x_evm_defconfig
+++ b/configs/am335x_evm_defconfig
@@ -48,6 +48,7 @@
 CONFIG_BOOTCOUNT_LIMIT=y
 CONFIG_CLK=y
 CONFIG_CLK_CDCE9XX=y
+CONFIG_CLK_TI_CTRL=y
 CONFIG_DFU_TFTP=y
 CONFIG_DFU_MMC=y
 CONFIG_DFU_NAND=y
diff --git a/doc/build/gcc.rst b/doc/build/gcc.rst
index 0cdc307..6c4b4ad 100644
--- a/doc/build/gcc.rst
+++ b/doc/build/gcc.rst
@@ -120,6 +120,27 @@
 * O=<dir> - generate all output files in directory <dir>, including .config
 * V=1 - verbose build
 
+Devicetree compiler
+~~~~~~~~~~~~~~~~~~~
+
+Boards that use `CONFIG_OF_CONTROL` (i.e. almost all of them) need the
+devicetree compiler (dtc). Those with `CONFIG_PYLIBFDT` need pylibfdt, a Python
+library for accessing devicetree data. Suitable versions of these are included
+in the U-Boot tree in `scripts/dtc` and built automatically as needed.
+
+To use the system versions of these, use the DTC parameter, for example
+
+.. code-block:: bash
+
+    DTC=/usr/bin/dtc make
+
+In this case, dtc and pylibfdt are not built. The build checks that the version
+of dtc is new enough. It also makes sure that pylibfdt is present, if needed
+(see `scripts_dtc` in the Makefile).
+
+Note that the :doc:`tools` are always built with the included version of libfdt
+so it is not possible to build U-Boot tools with a system libfdt, at present.
+
 Other build targets
 ~~~~~~~~~~~~~~~~~~~
 
diff --git a/doc/device-tree-bindings/gpio/gpio-max7320.txt b/doc/device-tree-bindings/gpio/gpio-max7320.txt
new file mode 100644
index 0000000..87b703b
--- /dev/null
+++ b/doc/device-tree-bindings/gpio/gpio-max7320.txt
@@ -0,0 +1,36 @@
+* MAX7320 I/O expanders
+
+The original maxim 7320 i/o expander offers 8 bit push/pull outputs.
+There exists some clones which offers 16 bit.
+
+Required Properties:
+
+  - compatible: should be one of the following.
+    - "maxim,max7320"
+
+  - reg: I2C slave address.
+
+  - gpio-controller: Marks the device node as a gpio controller.
+  - #gpio-cells: Should be 2. The first cell is the GPIO number and the second
+    cell specifies GPIO flags, as defined in <dt-bindings/gpio/gpio.h>. Only the
+    GPIO_ACTIVE_HIGH and GPIO_ACTIVE_LOW flags are supported.
+
+Optional Properties:
+
+   - ngpios: tell the driver how many gpios the device offers.
+     if the property is omitted, 8bit (original maxim) is assumed.
+
+Please refer to gpio.txt in this directory for details of the common GPIO
+bindings used by client devices.
+
+Example: MAX7320 I/O expander node
+
+	ledgpio: max7320@5d {
+		status = "okay";
+		compatible = "maxim,max7320";
+		reg = <0x5d>;
+		#gpio-cells = <2>;
+		gpio-controller;
+		ngpios = <16>;
+	};
+
diff --git a/drivers/clk/clk_fixed_rate.c b/drivers/clk/clk_fixed_rate.c
index e0dc4ab..c5a2a42 100644
--- a/drivers/clk/clk_fixed_rate.c
+++ b/drivers/clk/clk_fixed_rate.c
@@ -26,6 +26,7 @@
 const struct clk_ops clk_fixed_rate_ops = {
 	.get_rate = clk_fixed_rate_get_rate,
 	.enable = dummy_enable,
+	.disable = dummy_enable,
 };
 
 void clk_fixed_rate_ofdata_to_plat_(struct udevice *dev,
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index f0439e2..40abc33 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -183,6 +183,14 @@
 	help
 	  Support for the LPC32XX GPIO driver.
 
+config MAX7320_GPIO
+	bool "MAX7320 I2C GPIO Expander driver"
+	depends on DM_GPIO && DM_I2C
+	help
+	 Support for MAX7320 I2C 8/16-bit GPIO expander.
+	 original maxim device has 8 push/pull outputs,
+	 some clones offers 16bit.
+
 config MCP230XX_GPIO
 	bool "MCP230XX GPIO driver"
 	depends on DM
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index a9dc546..3c851b3 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -68,3 +68,4 @@
 obj-$(CONFIG_NX_GPIO)		+= nx_gpio.o
 obj-$(CONFIG_SIFIVE_GPIO)	+= sifive-gpio.o
 obj-$(CONFIG_NOMADIK_GPIO)	+= nmk_gpio.o
+obj-$(CONFIG_MAX7320_GPIO)	+= max7320_gpio.o
diff --git a/drivers/gpio/max7320_gpio.c b/drivers/gpio/max7320_gpio.c
new file mode 100644
index 0000000..647aed9
--- /dev/null
+++ b/drivers/gpio/max7320_gpio.c
@@ -0,0 +1,113 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * max7320 I2C GPIO EXPANDER DRIVER
+ *
+ * Copyright (C) 2021 Hannes Schmelzer <oe5hpm@oevsv.at>
+ * B&R Industrial Automation GmbH - http://www.br-automation.com
+ *
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <i2c.h>
+#include <asm-generic/gpio.h>
+#include <linux/bitops.h>
+
+struct max7320_chip {
+	u32 outreg;
+};
+
+static int max7320_direction_output(struct udevice *dev,
+				    unsigned int offset, int value)
+{
+	struct max7320_chip *plat = dev_get_plat(dev);
+	struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
+	struct dm_i2c_chip *chip = dev_get_parent_plat(dev);
+
+	int ret;
+
+	if (value)
+		plat->outreg |= BIT(offset);
+	else
+		plat->outreg &= ~BIT(offset);
+
+	ret = dm_i2c_write(dev,
+			   plat->outreg & 0xff,
+			   (uint8_t *)&plat->outreg + 1,
+			   uc_priv->gpio_count > 8 ? 1 : 0);
+	if (ret)
+		printf("%s i2c write failed to addr %x\n", __func__,
+		       chip->chip_addr);
+
+	return ret;
+}
+
+static int max7320_get_value(struct udevice *dev, unsigned int offset)
+{
+	struct max7320_chip *plat = dev_get_plat(dev);
+
+	return (plat->outreg >> offset) & 0x1;
+}
+
+static int max7320_set_value(struct udevice *dev, unsigned int offset,
+			     int value)
+{
+	return max7320_direction_output(dev, offset, value);
+}
+
+static int max7320_get_function(struct udevice *dev, unsigned int offset)
+{
+	return GPIOF_OUTPUT;
+}
+
+static int max7320_ofdata_plat(struct udevice *dev)
+{
+	struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
+
+	uc_priv->gpio_count = dev_read_u32_default(dev, "ngpios", 8);
+	if (uc_priv->gpio_count > 16) {
+		printf("%s: max7320 doesn't support more than 16 gpios!",
+		       __func__);
+		return -EINVAL;
+	}
+
+	uc_priv->bank_name = fdt_getprop(gd->fdt_blob, dev_of_offset(dev),
+					 "gpio-bank-name", NULL);
+	if (!uc_priv->bank_name)
+		uc_priv->bank_name = fdt_get_name(gd->fdt_blob,
+						  dev_of_offset(dev), NULL);
+
+	return 0;
+}
+
+static int max7320_gpio_probe(struct udevice  *dev)
+{
+	struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
+
+	debug("%s GPIO controller with %d gpios probed\n",
+	      uc_priv->bank_name, uc_priv->gpio_count);
+
+	return 0;
+}
+
+static const struct dm_gpio_ops max7320_gpio_ops = {
+	.direction_output	= max7320_direction_output,
+	.set_value		= max7320_set_value,
+	.get_value		= max7320_get_value,
+	.get_function		= max7320_get_function,
+};
+
+static const struct udevice_id max7320_gpio_ids[] = {
+	{ .compatible = "maxim,max7320" },
+	{ }
+};
+
+U_BOOT_DRIVER(gpio_max7320) = {
+	.name		= "gpio_max7320",
+	.id		= UCLASS_GPIO,
+	.ops		= &max7320_gpio_ops,
+	.of_match	= max7320_gpio_ids,
+	.of_to_plat	= max7320_ofdata_plat,
+	.probe		= max7320_gpio_probe,
+	.plat_auto	= sizeof(struct max7320_chip),
+};
diff --git a/dts/Kconfig b/dts/Kconfig
index fc41305..90c7a1c 100644
--- a/dts/Kconfig
+++ b/dts/Kconfig
@@ -5,9 +5,6 @@
 config SUPPORT_OF_CONTROL
 	bool
 
-config DTC
-	bool
-
 config PYLIBFDT
 	bool
 
@@ -42,7 +39,6 @@
 
 config OF_CONTROL
 	bool "Run-time configuration via Device Tree"
-	select DTC
 	select OF_LIBFDT if !OF_PLATDATA
 	select OF_REAL if !OF_PLATDATA
 	help
diff --git a/include/configs/total_compute.h b/include/configs/total_compute.h
index bbeedaf..933a145 100644
--- a/include/configs/total_compute.h
+++ b/include/configs/total_compute.h
@@ -30,6 +30,9 @@
 #define PHYS_SDRAM_1_SIZE	0x80000000 - DRAM_SEC_SIZE
 #define CONFIG_SYS_SDRAM_BASE	PHYS_SDRAM_1
 
+#define PHYS_SDRAM_2		0x8080000000
+#define PHYS_SDRAM_2_SIZE	0x180000000
+
 #define CONFIG_SYS_MMC_MAX_BLK_COUNT		127
 
 #define CONFIG_EXTRA_ENV_SETTINGS	\
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index a745cc4..09506cb 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -148,6 +148,7 @@
 
 # added for U-Boot
 binutils-version = $(shell $(CONFIG_SHELL) $(srctree)/scripts/binutils-version.sh $(AS))
+dtc-version = $(shell $(CONFIG_SHELL) $(srctree)/scripts/dtc-version.sh $(DTC))
 
 # cc-ldoption
 # Usage: ldflags += $(call cc-ldoption, -Wl$(comma)--hash-style=both)
diff --git a/scripts/Makefile b/scripts/Makefile
index e7b353f..cfe9fef 100644
--- a/scripts/Makefile
+++ b/scripts/Makefile
@@ -10,4 +10,3 @@
 
 # Let clean descend into subdirs
 subdir-	+= basic kconfig
-subdir-$(CONFIG_DTC)	+= dtc
diff --git a/scripts/dtc-version.sh b/scripts/dtc-version.sh
new file mode 100755
index 0000000..bfb514e
--- /dev/null
+++ b/scripts/dtc-version.sh
@@ -0,0 +1,27 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0+
+#
+# dtc-version dtc-command
+#
+# Prints the dtc version of `dtc-command' in a canonical 6-digit form
+# such as `010404'  for dtc 1.4.4
+#
+
+dtc="$*"
+
+if [ ${#dtc} -eq 0 ]; then
+	echo "Error: No dtc command specified"
+	printf "Usage:\n\t$0 <dtc-command>\n"
+	exit 1
+fi
+
+if ! which $dtc >/dev/null ; then
+	echo "Error: Cannot find dtc: $dtc"
+	exit 1
+fi
+
+MAJOR=$($dtc -v | head -1 | awk '{print $NF}' | cut -d . -f 1)
+MINOR=$($dtc -v | head -1 | awk '{print $NF}' | cut -d . -f 2)
+PATCH=$($dtc -v | head -1 | awk '{print $NF}' | cut -d . -f 3 | cut -d - -f 1)
+
+printf "%02d%02d%02d\\n" $MAJOR $MINOR $PATCH
diff --git a/tools/Makefile b/tools/Makefile
index 999fd46..b45219e 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -295,8 +295,7 @@
 		-I$(srctree)/tools \
 		-DUSE_HOSTCC \
 		-D__KERNEL_STRICT_NAMES \
-		-D_GNU_SOURCE \
-		-std=gnu99
+		-D_GNU_SOURCE
 
 __build:	$(LOGO-y)