Skip to contentSkip to conversation

drivers: Add a framework for MUX drivers

PATCH New Pratyush Yadav 3 participants 19 messages Oct 16, 2020 – Oct 28, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v4 cover drivers: Add a framework for MUX drivers

Hi,

This series is a re-roll of Jean-Jacques' earlier effort. It adds a new minimalistic subsystem that handles multiplexer controllers. It provides the same API as Linux and mux drivers should be portable with a minimum effort. This series also includes a port of the Linux's mmio-mux driver and an emulated mux driver for sandbox testing.

Travis CI run: https://travis-ci.org/github/prati0100/uboot/builds/736133605

Changes in v4:
- Drop the call to sandbox_set_enable_memio(). Use an emulated mux driver to test the default state instead.

Other changes are mentioned in individual patches.

Changes in v3:
- Add a new command called 'mux' that allows listing, selecting, and deselecting muxes on the fly.
- Move call to dm_mux_init() to initr_dm_devices().
- Enable mmio operations in sandbox on board_init() to dm_mux_init() can initialize muxes to their idle state and allow the tests to pass.
- Add help for CONFIG_MULTIPLEXER.
- Change dev_err() in mmio_mux_probe() to log_msg_ret() or log_err().
- Add comments on static functions in mux-class.c
- Make mux_uclass_post_probe() static.
- Make dm_mux_init() return an integer to signal failure.
- Change ifdef of mux-internal.h to _HUX_INTERNAL_H.
- Remove unused include from mux-internal.h
- Remove comments for non-existent members in struct mux_chip.
- Add missing comments for some members in struct mux_control.
- Add missing comments for some functions in mux.h
- Split up the mux_mmio test into two parts. More would lead to a lot of boilerplate.
- Change ut_assertok(IS_ERR(ptr)) to ut_assertok_ptr(ptr).
- Fix mis-spellings and capitalize comments.
- Rebase on latest master.

Changes in v2:
- Fixed warning in mux_of_xlate_default()
- Improved documentation
- Fixed SPL build
- insert the mux initialization in init_sequence_r[], just before the console is initialized as its serial port may be muxed
- moved the definition of dm_mux_init() in this commit
- Call sandbox_set_enable_memio(true) before running the test

Jean-Jacques Hiblot (4):
drivers: Add a new framework for multiplexer devices
dm: board: complete the initialization of the muxes in initr_dm()
drivers: mux: mmio-based syscon mux controller
test: Add tests for the multiplexer framework

Pratyush Yadav (3):
Kconfig: Increase the pre-relocation memory
cmd: Add a mux command
test: mux-cmd: Add tests for the 'mux' command

 Kconfig                       |   2 +-
 arch/sandbox/dts/test.dts     |  33 ++++
 cmd/Kconfig                   |   6 +
 cmd/Makefile                  |   1 +
 cmd/mux.c                     | 183 +++++++++++++++++++
 common/board_r.c              |  12 ++
 configs/sandbox_defconfig     |   3 +
 drivers/Kconfig               |   2 +
 drivers/Makefile              |   1 +
 drivers/mux/Kconfig           |  25 +++
 drivers/mux/Makefile          |   7 +
 drivers/mux/mmio.c            | 141 ++++++++++++++
 drivers/mux/mux-uclass.c      | 334 ++++++++++++++++++++++++++++++++++
 include/dm/uclass-id.h        |   1 +
 include/dt-bindings/mux/mux.h |  17 ++
 include/mux-internal.h        | 109 +++++++++++
 include/mux.h                 | 159 ++++++++++++++++
 test/dm/Makefile              |   3 +
 test/dm/mux-cmd.c             | 177 ++++++++++++++++++
 test/dm/mux-emul.c            | 105 +++++++++++
 test/dm/mux-mmio.c            | 138 ++++++++++++++
 21 files changed, 1458 insertions(+), 1 deletion(-)
 create mode 100644 cmd/mux.c
 create mode 100644 drivers/mux/Kconfig
 create mode 100644 drivers/mux/Makefile
 create mode 100644 drivers/mux/mmio.c
 create mode 100644 drivers/mux/mux-uclass.c
 create mode 100644 include/dt-bindings/mux/mux.h
 create mode 100644 include/mux-internal.h
 create mode 100644 include/mux.h
 create mode 100644 test/dm/mux-cmd.c
 create mode 100644 test/dm/mux-emul.c
 create mode 100644 test/dm/mux-mmio.c

--
2.28.0

#1 lore raw

PATCH v4 1/7 drivers: Add a new framework for multiplexer devices

From: Jean-Jacques Hiblot <[email protected]>

Add a new subsystem that handles multiplexer controllers. The API is the same as in Linux.

---

Notes:
No changes on v4.

 drivers/Kconfig               |   2 +
 drivers/Makefile              |   1 +
 drivers/mux/Kconfig           |  11 ++
 drivers/mux/Makefile          |   6 +
 drivers/mux/mux-uclass.c      | 311 ++++++++++++++++++++++++++++++++++
 include/dm/uclass-id.h        |   1 +
 include/dt-bindings/mux/mux.h |  17 ++
 include/mux-internal.h        | 109 ++++++++++++
 include/mux.h                 | 147 ++++++++++++++++
 9 files changed, 605 insertions(+)
 create mode 100644 drivers/mux/Kconfig
 create mode 100644 drivers/mux/Makefile
 create mode 100644 drivers/mux/mux-uclass.c
 create mode 100644 include/dt-bindings/mux/mux.h
 create mode 100644 include/mux-internal.h
 create mode 100644 include/mux.h
drivers/Kconfig +2 -0
index 613669cb38..ed8a39c994 100644
@@ -64,6 +64,8 @@ source "drivers/mmc/Kconfig"
 
 source "drivers/mtd/Kconfig"
 
+source "drivers/mux/Kconfig"
+
 source "drivers/net/Kconfig"
 
 source "drivers/nvme/Kconfig"
drivers/Makefile +1 -0
index 9eb51453e5..33f1d536cd 100644
@@ -14,6 +14,7 @@ obj-$(CONFIG_$(SPL_TPL_)INPUT) += input/
 obj-$(CONFIG_$(SPL_TPL_)LED) += led/
 obj-$(CONFIG_$(SPL_TPL_)MMC_SUPPORT) += mmc/
 obj-y += mtd/
+obj-$(CONFIG_$(SPL_)MULTIPLEXER) += mux/
 obj-$(CONFIG_$(SPL_TPL_)PCH_SUPPORT) += pch/
 obj-$(CONFIG_$(SPL_TPL_)PCI) += pci/
 obj-$(CONFIG_$(SPL_TPL_)PHY) += phy/
drivers/mux/Kconfig new file +11 -0
new file mode 100644
index 0000000000..35c1c5673c
@@ -0,0 +1,11 @@
+menu "Multiplexer drivers"
+
+config MULTIPLEXER
+	bool "Multiplexer Support"
+	depends on DM
+	help
+	 The mux framework is a minimalistic subsystem that handles multiplexer
+	 controllers. It provides the same API as Linux and mux drivers should
+	 be portable with a minimum effort.
+
+endmenu
drivers/mux/Makefile new file +6 -0
new file mode 100644
index 0000000000..351e4363d3
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# (C) Copyright 2019
+# Jean-Jacques Hiblot <[email protected]>
+
+obj-$(CONFIG_$(SPL_)MULTIPLEXER) += mux-uclass.o
drivers/mux/mux-uclass.c new file +311 -0

311 lines not on this page · raw message

include/dm/uclass-id.h +1 -0
index 88f10c4622..17542de2f3 100644
@@ -71,6 +71,7 @@ enum uclass_id {
 	UCLASS_MMC,		/* SD / MMC card or chip */
 	UCLASS_MOD_EXP,		/* RSA Mod Exp device */
 	UCLASS_MTD,		/* Memory Technology Device (MTD) device */
+	UCLASS_MUX,		/* Multiplexer device */
 	UCLASS_NOP,		/* No-op devices */
 	UCLASS_NORTHBRIDGE,	/* Intel Northbridge / SDRAM controller */
 	UCLASS_NVME,		/* NVM Express device */
include/dt-bindings/mux/mux.h new file +17 -0
new file mode 100644
index 0000000000..042719218d
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * This header provides constants for most Multiplexer bindings.
+ *
+ * Most Multiplexer bindings specify an idle state. In most cases, the
+ * the multiplexer can be left as is when idle, and in some cases it can
+ * disconnect the input/output and leave the multiplexer in a high
+ * impedance state.
+ */
+
+#ifndef _DT_BINDINGS_MUX_MUX_H
+#define _DT_BINDINGS_MUX_MUX_H
+
+#define MUX_IDLE_AS_IS      (-1)
+#define MUX_IDLE_DISCONNECT (-2)
+
+#endif
include/mux-internal.h new file +109 -0

109 lines not on this page · raw message

include/mux.h new file +147 -0

147 lines not on this page · raw message

Signature · 1 line
2.28.0
#2 lore raw

PATCH v4 1/7 drivers: Add a new framework for multiplexer devices

Quoted 8 lines · Pratyush Yadav

From: Jean-Jacques Hiblot <[email protected]>

Add a new subsystem that handles multiplexer controllers. The API is the same as in Linux.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20201028/d5bc17db/attachment.sig>
#3 lore raw

PATCH v4 2/7 dm: board: complete the initialization of the muxes in initr_dm()

In reply to Pratyush Yadav

From: Jean-Jacques Hiblot <[email protected]>

This will probe the multiplexer devices that have a "u-boot,mux-autoprobe" property. As a consequence they will be put in their idle state.

---

Notes:
No changes in v4.

 common/board_r.c         | 12 ++++++++++++
 drivers/mux/mux-uclass.c | 23 +++++++++++++++++++++++
 include/mux.h            | 12 ++++++++++++
 3 files changed, 47 insertions(+)
common/board_r.c +12 -0
index 9b2fec701a..b9217b2e27 100644
@@ -46,6 +46,7 @@
 #include <miiphy.h>
 #endif
 #include <mmc.h>
+#include <mux.h>
 #include <nand.h>
 #include <of_live.h>
 #include <onenand_uboot.h>
@@ -341,6 +342,17 @@ static int initr_dm_devices(void)
 			return ret;
 	}
 
+	if (IS_ENABLED(CONFIG_MULTIPLEXER)) {
+		/*
+		 * Initialize the multiplexer controls to their default state.
+		 * This must be done early as other drivers may unknowingly
+		 * rely on it.
+		 */
+		ret = dm_mux_init();
+		if (ret)
+			return ret;
+	}
+
 	return 0;
 }
 
drivers/mux/mux-uclass.c +23 -0
index 3c89e0a389..3dad466101 100644
@@ -303,6 +303,29 @@ static int mux_uclass_post_probe(struct udevice *dev)
 	return 0;
 }
 
+int dm_mux_init(void)
+{
+	struct uclass *uc;
+	struct udevice *dev;
+	int ret;
+
+	ret = uclass_get(UCLASS_MUX, &uc);
+	if (ret < 0) {
+		log_debug("unable to get MUX uclass\n");
+		return ret;
+	}
+	uclass_foreach_dev(dev, uc) {
+		if (dev_read_bool(dev, "u-boot,mux-autoprobe")) {
+			ret = device_probe(dev);
+			if (ret)
+				log_debug("unable to probe device %s\n",
+					  dev->name);
+		}
+	}
+
+	return 0;
+}
+
 UCLASS_DRIVER(mux) = {
 	.id		= UCLASS_MUX,
 	.name		= "mux",
include/mux.h +12 -0
index 85eb7d42fc..23844f480a 100644
@@ -109,6 +109,13 @@ void mux_control_put(struct mux_control *mux);
  */
 struct mux_control *devm_mux_control_get(struct udevice *dev,
 					 const char *mux_name);
+/**
+ * dm_mux_init() - Initialize the multiplexer controls to their default state.
+ *
+ * Return: 0 if OK, -errno otherwise.
+ */
+int dm_mux_init(void);
+
 #else
 unsigned int mux_control_states(struct mux_control *mux)
 {
@@ -142,6 +149,11 @@ struct mux_control *devm_mux_control_get(struct udevice *dev,
 {
 	return NULL;
 }
+
+int dm_mux_init(void)
+{
+	return -ENOSYS;
+}
 #endif
 
 #endif
Signature · 1 line
2.28.0
#4 lore raw

PATCH v4 2/7 dm: board: complete the initialization of the muxes in initr_dm()

Quoted 8 lines · Pratyush Yadav

From: Jean-Jacques Hiblot <[email protected]>

This will probe the multiplexer devices that have a "u-boot,mux-autoprobe" property. As a consequence they will be put in their idle state.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20201028/97c566d3/attachment.sig>
#5 lore raw

PATCH v4 3/7 drivers: mux: mmio-based syscon mux controller

In reply to Pratyush Yadav

From: Jean-Jacques Hiblot <[email protected]>

This adds a driver for mmio-based syscon multiplexers controlled by bitfields in a syscon register range.
This is heavily based on the linux mmio-mux driver.

---

Notes:
Changes in v4:

- Make strings in log messages smaller to reduce memory footprint.

 drivers/mux/Kconfig  |  14 +++++
 drivers/mux/Makefile |   1 +
 drivers/mux/mmio.c   | 141 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 156 insertions(+)
 create mode 100644 drivers/mux/mmio.c
drivers/mux/Kconfig +14 -0
index 35c1c5673c..f15ee4f833 100644
@@ -8,4 +8,18 @@ config MULTIPLEXER
 	 controllers. It provides the same API as Linux and mux drivers should
 	 be portable with a minimum effort.
 
+if MULTIPLEXER
+
+config MUX_MMIO
+	bool "MMIO register bitfield-controlled Multiplexer"
+	depends on MULTIPLEXER && SYSCON
+	help
+	  MMIO register bitfield-controlled Multiplexer controller.
+
+	  The driver builds multiplexer controllers for bitfields in a syscon
+	  register. For N bit wide bitfields, there will be 2^N possible
+	  multiplexer states.
+
+endif
+
 endmenu
drivers/mux/Makefile +1 -0
index 351e4363d3..78ebf04c7a 100644
@@ -4,3 +4,4 @@
 # Jean-Jacques Hiblot <[email protected]>
 
 obj-$(CONFIG_$(SPL_)MULTIPLEXER) += mux-uclass.o
+obj-$(CONFIG_$(SPL_)MUX_MMIO) += mmio.o
drivers/mux/mmio.c new file +141 -0

141 lines not on this page · raw message

Signature · 1 line
2.28.0
#6 lore raw

PATCH v4 3/7 drivers: mux: mmio-based syscon mux controller

Quoted 9 lines · Pratyush Yadav

From: Jean-Jacques Hiblot <[email protected]>

This adds a driver for mmio-based syscon multiplexers controlled by bitfields in a syscon register range.
This is heavily based on the linux mmio-mux driver.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20201028/26f11fb6/attachment.sig>
#7 lore raw

PATCH v4 4/7 Kconfig: Increase the pre-relocation memory

In reply to Pratyush Yadav

The memory is close to full and adding a syscon node in test.dts makes it go over the limit and makes malloc() fail on startup.

---

Notes:
New in v4.

 Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Kconfig +1 -1
index 520679f57e..b2165c1c49 100644
@@ -196,7 +196,7 @@ config SYS_MALLOC_F_LEN
 	hex "Size of malloc() pool before relocation"
 	depends on SYS_MALLOC_F
 	default 0x1000 if AM33XX
-	default 0x2800 if SANDBOX
+	default 0x4000 if SANDBOX
 	default 0x2000 if (ARCH_IMX8 || ARCH_IMX8M || ARCH_MX7 || \
 			   ARCH_MX7ULP || ARCH_MX6 || ARCH_MX5 || \
 			   ARCH_LS1012A || ARCH_LS1021A || ARCH_LS1043A || \
Signature · 1 line
2.28.0
#8 lore raw

PATCH v4 4/7 Kconfig: Increase the pre-relocation memory

Quoted 4 lines · Pratyush Yadav

The memory is close to full and adding a syscon node in test.dts makes it go over the limit and makes malloc() fail on startup.

Quoted 9 lines

---

Notes:
New in v4.

 Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
#9 lore raw

PATCH v4 4/7 Kconfig: Increase the pre-relocation memory

In reply to Pratyush Yadav
Quoted 5 lines · Pratyush Yadav

The memory is close to full and adding a syscon node in test.dts makes it go over the limit and makes malloc() fail on startup.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20201028/e5b04807/attachment.sig>
#10 lore raw

PATCH v4 5/7 test: Add tests for the multiplexer framework

In reply to Pratyush Yadav

From: Jean-Jacques Hiblot <[email protected]>

Provide tests to check the behavior of the multiplexer framework.

Two sets of tests are added. One is using an emulated multiplexer driver that can be used to test basic functionality like select, deselect, etc. The other is using the mmio mux which adds tests specific to it.

---

Notes:
Changes in v4:

- Add an emulated mux driver that makes it easier to test some basic functionality. It is used to test basic things like setting default state, and simple set/unset functionality. The MMIO test is still kept around for testing the mmio mux driver.

- Add a node for the emulated mux driver in test.dts

- Drop dm_test_mux_mmio_default_state(). This functionality is exercised by the emulated mux test.

- Drop some unused includes from mux-mmio.c

- s/DM_TESTF/UT_TESTF/g

 arch/sandbox/dts/test.dts |  33 +++++++++
 configs/sandbox_defconfig |   2 +
 test/dm/Makefile          |   2 +
 test/dm/mux-emul.c        | 105 +++++++++++++++++++++++++++++
 test/dm/mux-mmio.c        | 138 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 280 insertions(+)
 create mode 100644 test/dm/mux-emul.c
 create mode 100644 test/dm/mux-mmio.c
arch/sandbox/dts/test.dts +33 -0
index fa84b2c10f..70ccb4951a 100644
@@ -3,6 +3,7 @@
 #include <dt-bindings/gpio/gpio.h>
 #include <dt-bindings/gpio/sandbox-gpio.h>
 #include <dt-bindings/pinctrl/sandbox-pinmux.h>
+#include <dt-bindings/mux/mux.h>
 
 / {
 	model = "sandbox";
@@ -133,6 +134,12 @@
 		interrupts-extended = <&irq 3 0>;
 		acpi,name = "GHIJ";
 		phandle-value = <&gpio_c 10>, <0xFFFFFFFF 20>, <&gpio_a 30>;
+
+		mux-controls = <&muxcontroller0 0>, <&muxcontroller0 1>,
+			       <&muxcontroller0 2>, <&muxcontroller0 3>,
+			       <&muxcontroller1>;
+		mux-control-names = "mux0", "mux1", "mux2", "mux3", "mux4";
+		mux-syscon = <&syscon3>;
 	};
 
 	junk {
@@ -170,6 +177,9 @@
 		compatible = "denx,u-boot-fdt-test";
 		ping-expect = <3>;
 		ping-add = <3>;
+
+		mux-controls = <&muxcontroller0 0>;
+		mux-control-names = "mux0";
 	};
 
 	phy_provider0: gen_phy at 0 {
@@ -884,6 +894,29 @@
 			0x58 8>;
 	};
 
+	syscon3: syscon at 3 {
+		compatible = "simple-mfd", "syscon";
+		reg = <0x000100 0x10>;
+
+		muxcontroller0: a-mux-controller {
+			compatible = "mmio-mux";
+			#mux-control-cells = <1>;
+
+			mux-reg-masks = <0x0 0x30>, /* 0: reg 0x0, bits 5:4 */
+					<0xc 0x1E>, /* 1: reg 0xc, bits 4:1 */
+					<0x4 0xFF>; /* 2: reg 0x4, bits 7:0 */
+			idle-states = <MUX_IDLE_AS_IS>, <0x02>, <0x73>;
+			u-boot,mux-autoprobe;
+		};
+	};
+
+	muxcontroller1: emul-mux-controller {
+		compatible = "mux-emul";
+		#mux-control-cells = <0>;
+		u-boot,mux-autoprobe;
+		idle-state = <0xabcd>;
+	};
+
 	timer at 0 {
 		compatible = "sandbox,timer";
 		clock-frequency = <1000000>;
configs/sandbox_defconfig +2 -0
index 6ac2919977..f3c4883032 100644
@@ -179,6 +179,8 @@ CONFIG_SPI_FLASH_SPANSION=y
 CONFIG_SPI_FLASH_STMICRO=y
 CONFIG_SPI_FLASH_SST=y
 CONFIG_SPI_FLASH_WINBOND=y
+CONFIG_MULTIPLEXER=y
+CONFIG_MUX_MMIO=y
 CONFIG_DM_ETH=y
 CONFIG_NVME=y
 CONFIG_PCI=y
test/dm/Makefile +2 -0
index e2b0798388..93484b48eb 100644
@@ -57,6 +57,8 @@ obj-$(CONFIG_DM_SPI_FLASH) += sf.o
 obj-$(CONFIG_SMEM) += smem.o
 obj-$(CONFIG_DM_SPI) += spi.o
 obj-y += syscon.o
+obj-$(CONFIG_MUX_MMIO) += mux-mmio.o
+obj-$(CONFIG_MULTIPLEXER) += mux-emul.o
 obj-$(CONFIG_DM_USB) += usb.o
 obj-$(CONFIG_DM_PMIC) += pmic.o
 obj-$(CONFIG_DM_REGULATOR) += regulator.o
test/dm/mux-emul.c new file +105 -0

105 lines not on this page · raw message

test/dm/mux-mmio.c new file +138 -0

138 lines not on this page · raw message

Signature · 1 line
2.28.0
#11 lore raw

PATCH v4 5/7 test: Add tests for the multiplexer framework

Hi Pratyush,

Quoted 30 lines · Pratyush Yadav

From: Jean-Jacques Hiblot <[email protected]>

Provide tests to check the behavior of the multiplexer framework.

Two sets of tests are added. One is using an emulated multiplexer driver that can be used to test basic functionality like select, deselect, etc. The other is using the mmio mux which adds tests specific to it.

---

Notes:
Changes in v4:

- Add an emulated mux driver that makes it easier to test some basic functionality. It is used to test basic things like setting default state, and simple set/unset functionality. The MMIO test is still kept around for testing the mmio mux driver.

- Add a node for the emulated mux driver in test.dts

- Drop dm_test_mux_mmio_default_state(). This functionality is exercised by the emulated mux test.

- Drop some unused includes from mux-mmio.c

- s/DM_TESTF/UT_TESTF/g

Quoted 9 lines
 arch/sandbox/dts/test.dts |  33 +++++++++
 configs/sandbox_defconfig |   2 +
 test/dm/Makefile          |   2 +
 test/dm/mux-emul.c        | 105 +++++++++++++++++++++++++++++
 test/dm/mux-mmio.c        | 138 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 280 insertions(+)
 create mode 100644 test/dm/mux-emul.c
 create mode 100644 test/dm/mux-mmio.c

nits below

Quoted 108 lines
arch/sandbox/dts/test.dts +33 -0
index fa84b2c10f..70ccb4951a 100644
@@ -3,6 +3,7 @@
 #include <dt-bindings/gpio/gpio.h>
 #include <dt-bindings/gpio/sandbox-gpio.h>
 #include <dt-bindings/pinctrl/sandbox-pinmux.h>
+#include <dt-bindings/mux/mux.h>
 
 / {
        model = "sandbox";
@@ -133,6 +134,12 @@
                interrupts-extended = <&irq 3 0>;
                acpi,name = "GHIJ";
                phandle-value = <&gpio_c 10>, <0xFFFFFFFF 20>, <&gpio_a 30>;
+
+               mux-controls = <&muxcontroller0 0>, <&muxcontroller0 1>,
+                              <&muxcontroller0 2>, <&muxcontroller0 3>,
+                              <&muxcontroller1>;
+               mux-control-names = "mux0", "mux1", "mux2", "mux3", "mux4";
+               mux-syscon = <&syscon3>;
        };
 
        junk {
@@ -170,6 +177,9 @@
                compatible = "denx,u-boot-fdt-test";
                ping-expect = <3>;
                ping-add = <3>;
+
+               mux-controls = <&muxcontroller0 0>;
+               mux-control-names = "mux0";
        };
 
        phy_provider0: gen_phy at 0 {
@@ -884,6 +894,29 @@
                        0x58 8>;
        };
 
+       syscon3: syscon at 3 {
+               compatible = "simple-mfd", "syscon";
+               reg = <0x000100 0x10>;
+
+               muxcontroller0: a-mux-controller {
+                       compatible = "mmio-mux";
+                       #mux-control-cells = <1>;
+
+                       mux-reg-masks = <0x0 0x30>, /* 0: reg 0x0, bits 5:4 */
+                                       <0xc 0x1E>, /* 1: reg 0xc, bits 4:1 */
+                                       <0x4 0xFF>; /* 2: reg 0x4, bits 7:0 */
+                       idle-states = <MUX_IDLE_AS_IS>, <0x02>, <0x73>;
+                       u-boot,mux-autoprobe;
+               };
+       };
+
+       muxcontroller1: emul-mux-controller {
+               compatible = "mux-emul";
+               #mux-control-cells = <0>;
+               u-boot,mux-autoprobe;
+               idle-state = <0xabcd>;
+       };
+
        timer at 0 {
                compatible = "sandbox,timer";
                clock-frequency = <1000000>;
configs/sandbox_defconfig +2 -0
index 6ac2919977..f3c4883032 100644
@@ -179,6 +179,8 @@ CONFIG_SPI_FLASH_SPANSION=y
 CONFIG_SPI_FLASH_STMICRO=y
 CONFIG_SPI_FLASH_SST=y
 CONFIG_SPI_FLASH_WINBOND=y
+CONFIG_MULTIPLEXER=y
+CONFIG_MUX_MMIO=y
 CONFIG_DM_ETH=y
 CONFIG_NVME=y
 CONFIG_PCI=y
test/dm/Makefile +2 -0
index e2b0798388..93484b48eb 100644
@@ -57,6 +57,8 @@ obj-$(CONFIG_DM_SPI_FLASH) += sf.o
 obj-$(CONFIG_SMEM) += smem.o
 obj-$(CONFIG_DM_SPI) += spi.o
 obj-y += syscon.o
+obj-$(CONFIG_MUX_MMIO) += mux-mmio.o
+obj-$(CONFIG_MULTIPLEXER) += mux-emul.o
 obj-$(CONFIG_DM_USB) += usb.o
 obj-$(CONFIG_DM_PMIC) += pmic.o
 obj-$(CONFIG_DM_REGULATOR) += regulator.o
test/dm/mux-emul.c new file +11 -0
new file mode 100644
index 0000000000..141fd4d908
@@ -0,0 +1,105 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2020 Texas Instruments Incorporated - http://www.ti.com/
+ * Pratyush Yadav <[email protected]>
+ */
+#include <common.h>
+#include <dm.h>
+#include <mux.h>
+#include <mux-internal.h>
+#include <dm/test.h>
+#include <test/ut.h>

test/dm/mux-emul.c line 21

Quoted 10 lines
test/dm/mux-emul.c new file +10 -0
+
+struct mux_emul_priv {
+       u32 state;
+};
+
+static int mux_emul_set(struct mux_control *mux, int state)
+{
+       struct mux_emul_priv *priv = dev_get_priv(mux->dev);
+
+       priv->state = state;

blank line before last return

test/dm/mux-emul.c line 24

Quoted 3 lines
test/dm/mux-emul.c new file +3 -0
+       return 0;
+}
+

Regards,
Simon

#12 lore raw

PATCH v4 5/7 test: Add tests for the multiplexer framework

In reply to Pratyush Yadav
Quoted 11 lines · Pratyush Yadav

From: Jean-Jacques Hiblot <[email protected]>

Provide tests to check the behavior of the multiplexer framework.

Two sets of tests are added. One is using an emulated multiplexer driver that can be used to test basic functionality like select, deselect, etc. The other is using the mmio mux which adds tests specific to it.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20201028/13343517/attachment.sig>
#13 lore raw

PATCH v4 6/7 cmd: Add a mux command

In reply to Pratyush Yadav

This command lets the user list, select, and deselect mux controllers introduced with the mux framework on the fly. It has 3 subcommands:
list, select, and deselect.

List: Lists all the mux present on the system. The muxes are listed for each chip. The chip is identified by its device name. Each chip can have a number of mux controllers. Each is listed in sequence and is assigned a sequential ID based on its position in the mux chip. It lists details like ID, whether the mux is currently selected or not, the current state, the idle state, and the number of states.

A sample output would look something like:

=> mux list
a-mux-controller:

	ID	Selected	Current State	Idle State	Num States
	0	no        	unknown   	as-is     	0x4
	1	no        	0x2       	0x2       	0x10
	2	no        	0x73      	0x73      	0x100

another-mux-controller:

	ID	Selected	Current State	Idle State	Num States
        0       no              0x1             0x1             0x4
        1       no              0x2             0x2             0x4

Select: Selects a given mux and puts it in the specified state. This subcommand takes 3 arguments: mux chip, mux ID, state to set the mux in. The arguments mux chip and mux ID are used to identify which mux needs to be selected, and then it is selected to the given state. The mux needs to be deselected before it can be selected again in another state. The state should be a hexadecimal number.

For example:
=> mux list
a-mux-controller:

        ID      Selected        Current State   Idle State      Num States
        0       no              0x1             0x1             0x4
        1       no              0x1             0x1             0x4
=> mux select a-mux-controller 0 0x3
=> mux list
a-mux-controller:
        ID      Selected        Current State   Idle State      Num States
        0       yes             0x3             0x1             0x4
        1       no              0x1             0x1             0x4

Deselect: Deselects a given mux and puts it in its idle state. This subcommand takes 2 arguments: the mux chip and mux ID to identify which mux needs to be deselected. So in the above example, we can deselect mux 0 using:

=> mux deselect a-mux-controller 0
=> mux list
a-mux-controller:

        ID      Selected        Current State   Idle State      Num States
        0       no              0x1             0x1             0x4
        1       no              0x1             0x1             0x4

---

Notes:
Changes in v4:

- Use spaces to print columns in 'mux list' instead of tabs. Tabs don't work well with ut_assert_nextline() because it calls membuff_readline() down the call chain and tells it to consider characters below the space character as EOL. This means ut_assert_nextline() can only assert for the next column not the next line if a command is using tabs.

 cmd/Kconfig  |   6 ++
 cmd/Makefile |   1 +
 cmd/mux.c    | 183 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 190 insertions(+)
 create mode 100644 cmd/mux.c
cmd/Kconfig +6 -0
index a3166e4f31..a25d6d62d0 100644
@@ -1073,6 +1073,12 @@ config CMD_MTD
 	help
 	  MTD commands support.
 
+config CMD_MUX
+	bool "mux"
+	depends on MULTIPLEXER
+	help
+	 List, select, and deselect mux controllers on the fly.
+
 config CMD_NAND
 	bool "nand"
 	default y if NAND_SUNXI
cmd/Makefile +1 -0
index 19a891633f..79a57b8482 100644
@@ -104,6 +104,7 @@ obj-$(CONFIG_CMD_CLONE) += clone.o
 ifneq ($(CONFIG_CMD_NAND)$(CONFIG_CMD_SF),)
 obj-y += legacy-mtd-utils.o
 endif
+obj-$(CONFIG_CMD_MUX) += mux.o
 obj-$(CONFIG_CMD_NAND) += nand.o
 obj-$(CONFIG_CMD_NET) += net.o
 obj-$(CONFIG_CMD_NVEDIT_EFI) += nvedit_efi.o
cmd/mux.c new file +183 -0

183 lines not on this page · raw message

Signature · 1 line
2.28.0
#14 lore raw

PATCH v4 6/7 cmd: Add a mux command

Hi Pratyush,

Quoted 71 lines · Pratyush Yadav

This command lets the user list, select, and deselect mux controllers introduced with the mux framework on the fly. It has 3 subcommands:
list, select, and deselect.

List: Lists all the mux present on the system. The muxes are listed for each chip. The chip is identified by its device name. Each chip can have a number of mux controllers. Each is listed in sequence and is assigned a sequential ID based on its position in the mux chip. It lists details like ID, whether the mux is currently selected or not, the current state, the idle state, and the number of states.

A sample output would look something like:

=> mux list
a-mux-controller:

        ID      Selected        Current State   Idle State      Num States
        0       no              unknown         as-is           0x4
        1       no              0x2             0x2             0x10
        2       no              0x73            0x73            0x100

another-mux-controller:

        ID      Selected        Current State   Idle State      Num States
        0       no              0x1             0x1             0x4
        1       no              0x2             0x2             0x4

Select: Selects a given mux and puts it in the specified state. This subcommand takes 3 arguments: mux chip, mux ID, state to set the mux in. The arguments mux chip and mux ID are used to identify which mux needs to be selected, and then it is selected to the given state. The mux needs to be deselected before it can be selected again in another state. The state should be a hexadecimal number.

For example:
=> mux list
a-mux-controller:

        ID      Selected        Current State   Idle State      Num States
        0       no              0x1             0x1             0x4
        1       no              0x1             0x1             0x4
=> mux select a-mux-controller 0 0x3
=> mux list
a-mux-controller:
        ID      Selected        Current State   Idle State      Num States
        0       yes             0x3             0x1             0x4
        1       no              0x1             0x1             0x4

Deselect: Deselects a given mux and puts it in its idle state. This subcommand takes 2 arguments: the mux chip and mux ID to identify which mux needs to be deselected. So in the above example, we can deselect mux 0 using:

=> mux deselect a-mux-controller 0
=> mux list
a-mux-controller:

        ID      Selected        Current State   Idle State      Num States
        0       no              0x1             0x1             0x4
        1       no              0x1             0x1             0x4

---

Notes:
Changes in v4:

- Use spaces to print columns in 'mux list' instead of tabs. Tabs don't work well with ut_assert_nextline() because it calls membuff_readline() down the call chain and tells it to consider characters below the space character as EOL. This means ut_assert_nextline() can only assert for the next column not the next line if a command is using tabs.

Quoted 5 lines
 cmd/Kconfig  |   6 ++
 cmd/Makefile |   1 +
 cmd/mux.c    | 183 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 190 insertions(+)
 create mode 100644 cmd/mux.c

A few comments below.

Quoted 54 lines
cmd/Kconfig +6 -0
index a3166e4f31..a25d6d62d0 100644
@@ -1073,6 +1073,12 @@ config CMD_MTD
        help
          MTD commands support.
 
+config CMD_MUX
+       bool "mux"
+       depends on MULTIPLEXER
+       help
+        List, select, and deselect mux controllers on the fly.
+
 config CMD_NAND
        bool "nand"
        default y if NAND_SUNXI
cmd/Makefile +1 -0
index 19a891633f..79a57b8482 100644
@@ -104,6 +104,7 @@ obj-$(CONFIG_CMD_CLONE) += clone.o
 ifneq ($(CONFIG_CMD_NAND)$(CONFIG_CMD_SF),)
 obj-y += legacy-mtd-utils.o
 endif
+obj-$(CONFIG_CMD_MUX) += mux.o
 obj-$(CONFIG_CMD_NAND) += nand.o
 obj-$(CONFIG_CMD_NET) += net.o
 obj-$(CONFIG_CMD_NVEDIT_EFI) += nvedit_efi.o
cmd/mux.c new file +18 -0
new file mode 100644
index 0000000000..3a0839ec1f
@@ -0,0 +1,183 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * List, select, and deselect mux controllers on the fly.
+ *
+ * Copyright (c) 2020 Texas Instruments Inc.
+ * Author: Pratyush Yadav <[email protected]>
+ */
+
+#include <common.h>
+#include <command.h>
+#include <errno.h>
+#include <dm.h>
+#include <mux.h>
+#include <mux-internal.h>
+#include <linux/err.h>
+#include <dt-bindings/mux/mux.h>
+
+#define COLUMN_SIZE 16

cmd/mux.c line 28

Quoted 10 lines
cmd/mux.c new file +10 -0
+
+/*
+ * Print a member of a column. The total size of the text printed, including
+ * trailing whitespace, will always be COLUMN_SIZE.
+ */
+#define PRINT_COLUMN(fmt, args...) do {                                        \
+       char buf[COLUMN_SIZE + 1];                                      \
+       snprintf(buf, COLUMN_SIZE + 1, fmt, ##args);                    \
+       printf("%-*s", COLUMN_SIZE, buf);                               \
+} while (0)

This blows out the code size. How about a static function instead?

cmd/mux.c line 34

Quoted 6 lines
cmd/mux.c new file +6 -0
+
+/*
+ * Find a mux based on its device name in argv[1] and index in the chip in
+ * argv[2].
+ */
+static struct mux_control *cmd_mux_find(char *const argv[])

Is it worth having a pointer here? You could return the argument as an int and have a struct mux_control** param here. Up to you.

Quoted 49 lines
cmd/mux.c new file +49 -0
+{
+       struct udevice *dev;
+       struct mux_chip *chip;
+       int ret;
+       unsigned long id;
+
+       ret = strict_strtoul(argv[2], 10, &id);
+       if (ret)
+               return ERR_PTR(ret);
+
+       ret = uclass_get_device_by_name(UCLASS_MUX, argv[1], &dev);
+       if (ret)
+               return ERR_PTR(ret);
+
+       chip = dev_get_uclass_priv(dev);
+       if (!chip)
+               return ERR_PTR(ret);
+
+       if (id >= chip->controllers)
+               return ERR_PTR(-EINVAL);
+
+       return &chip->mux[id];
+}
+
+/*
+ * Print the details of a mux. The columns printed correspond to: "Selected",
+ * "Current State", "Idle State", and "Num States".
+ */
+static void print_mux(struct mux_control *mux)
+{
+       PRINT_COLUMN("%s", mux->in_use ? "yes" : "no");
+
+       if (mux->cached_state == MUX_IDLE_AS_IS)
+               PRINT_COLUMN("%s", "unknown");
+       else
+               PRINT_COLUMN("0x%x", mux->cached_state);
+
+       if (mux->idle_state == MUX_IDLE_AS_IS)
+               PRINT_COLUMN("%s", "as-is");
+       else if (mux->idle_state == MUX_IDLE_DISCONNECT)
+               PRINT_COLUMN("%s", "disconnect");
+       else
+               PRINT_COLUMN("0x%x", mux->idle_state);
+
+       PRINT_COLUMN("0x%x", mux->states);
+
+       printf("\n");
+}
+

cmd/mux.c line 93

Quoted 10 lines
cmd/mux.c new file +10 -0
+static int do_mux_list(struct cmd_tbl *cmdtp, int flag, int argc,
+                      char *const argv[])
+{
+       struct udevice *dev;
+       struct mux_chip *chip;
+       int j;
+
+       for (uclass_first_device(UCLASS_MUX, &dev);
+            dev;
+            uclass_next_device(&dev)) {

uclass_for_each_device() or similar

cmd/mux.c line 99

Quoted 6 lines
cmd/mux.c new file +6 -0
+               chip = dev_get_uclass_priv(dev);
+               if (!chip) {
+                       dev_err(dev, "can't find mux chip\n");
+                       continue;
+               }
+

Regards,
Simon

#15 lore raw

PATCH v4 6/7 cmd: Add a mux command

In reply to Pratyush Yadav
Quoted 53 lines · Pratyush Yadav

This command lets the user list, select, and deselect mux controllers introduced with the mux framework on the fly. It has 3 subcommands:
list, select, and deselect.

List: Lists all the mux present on the system. The muxes are listed for each chip. The chip is identified by its device name. Each chip can have a number of mux controllers. Each is listed in sequence and is assigned a sequential ID based on its position in the mux chip. It lists details like ID, whether the mux is currently selected or not, the current state, the idle state, and the number of states.

A sample output would look something like:

=> mux list
a-mux-controller:

	ID	Selected	Current State	Idle State	Num States
	0	no        	unknown   	as-is     	0x4
	1	no        	0x2       	0x2       	0x10
	2	no        	0x73      	0x73      	0x100

another-mux-controller:

	ID	Selected	Current State	Idle State	Num States
        0       no              0x1             0x1             0x4
        1       no              0x2             0x2             0x4

Select: Selects a given mux and puts it in the specified state. This subcommand takes 3 arguments: mux chip, mux ID, state to set the mux in. The arguments mux chip and mux ID are used to identify which mux needs to be selected, and then it is selected to the given state. The mux needs to be deselected before it can be selected again in another state. The state should be a hexadecimal number.

For example:
=> mux list
a-mux-controller:

        ID      Selected        Current State   Idle State      Num States
        0       no              0x1             0x1             0x4
        1       no              0x1             0x1             0x4
=> mux select a-mux-controller 0 0x3
=> mux list
a-mux-controller:
        ID      Selected        Current State   Idle State      Num States
        0       yes             0x3             0x1             0x4
        1       no              0x1             0x1             0x4

Deselect: Deselects a given mux and puts it in its idle state. This subcommand takes 2 arguments: the mux chip and mux ID to identify which mux needs to be deselected. So in the above example, we can deselect mux 0 using:

=> mux deselect a-mux-controller 0
=> mux list
a-mux-controller:

Quoted 6 lines
        ID      Selected        Current State   Idle State      Num States
        0       no              0x1             0x1             0x4
        1       no              0x1             0x1             0x4

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20201028/08ca1586/attachment.sig>
#16 lore raw

PATCH v4 7/7 test: mux-cmd: Add tests for the 'mux' command

In reply to Pratyush Yadav

Tests tests run the three mux subcommands: list, select, and deselect, and verify that the commands do what we expect.

---

Notes:
New in v4.

 configs/sandbox_defconfig |   1 +
 test/dm/Makefile          |   1 +
 test/dm/mux-cmd.c         | 177 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 179 insertions(+)
 create mode 100644 test/dm/mux-cmd.c
configs/sandbox_defconfig +1 -0
index f3c4883032..e573ae075b 100644
@@ -55,6 +55,7 @@ CONFIG_CMD_GPT_RENAME=y
 CONFIG_CMD_IDE=y
 CONFIG_CMD_I2C=y
 CONFIG_CMD_LSBLK=y
+CONFIG_CMD_MUX=y
 CONFIG_CMD_OSD=y
 CONFIG_CMD_PCI=y
 CONFIG_CMD_READ=y
test/dm/Makefile +1 -0
index 93484b48eb..8b3d77e34e 100644
@@ -34,6 +34,7 @@ obj-y += irq.o
 obj-$(CONFIG_LED) += led.o
 obj-$(CONFIG_DM_MAILBOX) += mailbox.o
 obj-$(CONFIG_DM_MMC) += mmc.o
+obj-$(CONFIG_CMD_MUX) += mux-cmd.o
 obj-y += fdtdec.o
 obj-y += ofnode.o
 obj-y += ofread.o
test/dm/mux-cmd.c new file +177 -0

177 lines not on this page · raw message

Signature · 1 line
2.28.0
#17 lore raw

PATCH v4 7/7 test: mux-cmd: Add tests for the 'mux' command

Hi Pratyush,

Quoted 51 lines · Pratyush Yadav

Tests tests run the three mux subcommands: list, select, and deselect, and verify that the commands do what we expect.

---

Notes:
New in v4.

 configs/sandbox_defconfig |   1 +
 test/dm/Makefile          |   1 +
 test/dm/mux-cmd.c         | 177 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 179 insertions(+)
 create mode 100644 test/dm/mux-cmd.c
configs/sandbox_defconfig +1 -0
index f3c4883032..e573ae075b 100644
@@ -55,6 +55,7 @@ CONFIG_CMD_GPT_RENAME=y
 CONFIG_CMD_IDE=y
 CONFIG_CMD_I2C=y
 CONFIG_CMD_LSBLK=y
+CONFIG_CMD_MUX=y
 CONFIG_CMD_OSD=y
 CONFIG_CMD_PCI=y
 CONFIG_CMD_READ=y
test/dm/Makefile +1 -0
index 93484b48eb..8b3d77e34e 100644
@@ -34,6 +34,7 @@ obj-y += irq.o
 obj-$(CONFIG_LED) += led.o
 obj-$(CONFIG_DM_MAILBOX) += mailbox.o
 obj-$(CONFIG_DM_MMC) += mmc.o
+obj-$(CONFIG_CMD_MUX) += mux-cmd.o
 obj-y += fdtdec.o
 obj-y += ofnode.o
 obj-y += ofread.o
test/dm/mux-cmd.c new file +5 -0
new file mode 100644
index 0000000000..11c237b5da
@@ -0,0 +1,177 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020 Texas Instruments Inc.
+ * Pratyush Yadav <[email protected]>
+ */

test/dm/mux-cmd.c line 15

Quoted 10 lines
test/dm/mux-cmd.c new file +10 -0
+#include <common.h>
+#include <dm.h>
+#include <mux.h>
+#include <mux-internal.h>
+#include <dt-bindings/mux/mux.h>
+#include <asm/test.h>
+#include <dm/test.h>
+#include <test/ut.h>
+#include <console.h>
+#include <rand.h>

Check header order

#18 lore raw

PATCH v4 7/7 test: mux-cmd: Add tests for the 'mux' command

In reply to Pratyush Yadav
Quoted 5 lines · Pratyush Yadav

Tests tests run the three mux subcommands: list, select, and deselect, and verify that the commands do what we expect.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20201028/60ff6565/attachment.sig>