Skip to contentSkip to conversation

drivers: Add a framework for MUX drivers

PATCH Superseded Pratyush Yadav 3 participants 15 messages Jun 11, 2020 – Aug 6, 2020

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 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.

This series relies on a series that extends the regmap [0].

[0] https://patchwork.ozlabs.org/project/uboot/list/?series=181623

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 (2):
cmd: Add a mux command
sandbox: Enable memio operations in board_init

 arch/sandbox/dts/test.dts     |  25 +++
 board/sandbox/sandbox.c       |   2 +
 cmd/Kconfig                   |   6 +
 cmd/Makefile                  |   1 +
 cmd/mux.c                     | 161 ++++++++++++++++
 common/board_r.c              |  12 ++
 configs/sandbox_defconfig     |   2 +
 drivers/Kconfig               |   2 +
 drivers/Makefile              |   1 +
 drivers/mux/Kconfig           |  25 +++
 drivers/mux/Makefile          |   7 +
 drivers/mux/mmio.c            | 143 +++++++++++++++
 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              |   1 +
 test/dm/mux-mmio.c            | 168 +++++++++++++++++
 19 files changed, 1176 insertions(+)
 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-mmio.c

--
2.27.0

#1 lore raw

PATCH v3 1/6 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.

---
 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 e34a22708c..03a2e5f5ef 100644
@@ -60,6 +60,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 94e8c5da17..76d8500bee 100644
@@ -13,6 +13,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 7837d459f1..066d7d51ff 100644
@@ -70,6 +70,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.27.0
#2 lore raw

PATCH v3 1/6 drivers: Add a new framework for multiplexer devices

Quoted 17 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.

---
 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 ++++++++++++
Quoted 8 lines
 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
#3 lore raw

PATCH v3 2/6 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.

---
 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 fa57fa9b69..aa1f98e851 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>
@@ -334,6 +335,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.27.0
#4 lore raw

PATCH v3 2/6 dm: board: complete the initialization of the muxes in initr_dm()

Quoted 6 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.

Quoted 8 lines
---
 common/board_r.c         | 12 ++++++++++++
 drivers/mux/mux-uclass.c | 23 +++++++++++++++++++++++
 include/mux.h            | 12 ++++++++++++
 3 files changed, 47 insertions(+)
#5 lore raw

PATCH v3 3/6 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.

---
 drivers/mux/Kconfig  |  14 +++++
 drivers/mux/Makefile |   1 +
 drivers/mux/mmio.c   | 143 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 158 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 +143 -0

143 lines not on this page · raw message

Signature · 1 line
2.27.0
#6 lore raw

PATCH v3 3/6 drivers: mux: mmio-based syscon mux controller

Hi Pratyush,

Quoted 10 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.

Quoted 6 lines
---
 drivers/mux/Kconfig  |  14 +++++
 drivers/mux/Makefile |   1 +
 drivers/mux/mmio.c   | 143 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 158 insertions(+)
 create mode 100644 drivers/mux/mmio.c

nit below

Quoted 85 lines
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 +46 -0
new file mode 100644
index 0000000000..573e599dd1
@@ -0,0 +1,143 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * MMIO register bitfield-controlled multiplexer driver
+ * Based on the linux mmio multiplexer driver
+ *
+ * Copyright (C) 2017 Pengutronix, Philipp Zabel <[email protected]>
+ * Copyright (C) 2019 Texas Instrument, Jean-jacques Hiblot <[email protected]>
+ */
+#include <common.h>
+#include <dm.h>
+#include <mux-internal.h>
+#include <regmap.h>
+#include <syscon.h>
+#include <dm/device.h>
+#include <dm/read.h>
+#include <dm/devres.h>
+#include <dt-bindings/mux/mux.h>
+#include <linux/bitops.h>
+
+static int mux_mmio_set(struct mux_control *mux, int state)
+{
+       struct regmap_field **fields = dev_get_priv(mux->dev);
+
+       return regmap_field_write(fields[mux_control_get_index(mux)], state);
+}
+
+static const struct mux_control_ops mux_mmio_ops = {
+       .set = mux_mmio_set,
+};
+
+static const struct udevice_id mmio_mux_of_match[] = {
+       { .compatible = "mmio-mux" },
+       { /* sentinel */ },
+};
+
+static int mmio_mux_probe(struct udevice *dev)
+{
+       struct regmap_field **fields;
+       struct mux_chip *mux_chip = dev_get_uclass_priv(dev);
+       struct regmap *regmap;
+       u32 *mux_reg_masks;
+       u32 *idle_states;
+       int num_fields;
+       int ret;
+       int i;
+

drivers/mux/mmio.c line 56

Quoted 10 lines
drivers/mux/mmio.c new file +10 -0
+       regmap = syscon_node_to_regmap(dev_ofnode(dev->parent));
+       if (IS_ERR(regmap)) {
+               ret = PTR_ERR(regmap);
+               dev_err(dev, "failed to get regmap: %d\n", ret);
+               return ret;
+       }
+
+       num_fields = dev_read_size(dev, "mux-reg-masks");
+       if (num_fields < 0)
+               return log_msg_ret("mux-reg-masks missing or invalid", -EINVAL);

It occurred to me at some point that all we really need here is a short string, like "mux-reg-masks" since we only need to find the unique string within the function (which logging automatically records). If we use very long strings then enabling the message logging will cause a very large increase in code size.

Regards,
Simon

#7 lore raw

PATCH v3 4/6 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
---
 cmd/Kconfig  |   6 ++
 cmd/Makefile |   1 +
 cmd/mux.c    | 161 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 168 insertions(+)
 create mode 100644 cmd/mux.c
cmd/Kconfig +6 -0
index 192b3b262f..5e78f373d6 100644
@@ -1128,6 +1128,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 974ad48b0a..8c680420e1 100644
@@ -99,6 +99,7 @@ obj-$(CONFIG_CMD_MTDPARTS) += mtdparts.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 +161 -0

161 lines not on this page · raw message

Signature · 1 line
2.27.0
#8 lore raw

PATCH v3 4/6 cmd: Add a mux command

Quoted 58 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
Quoted 7 lines
---
 cmd/Kconfig  |   6 ++
 cmd/Makefile |   1 +
 cmd/mux.c    | 161 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 168 insertions(+)
 create mode 100644 cmd/mux.c

Please can you add a patch with a test for this? See ut_assert_nextline(), etc. and my 'memory search' series.

#9 lore raw

PATCH v3 5/6 sandbox: Enable memio operations in board_init

In reply to Pratyush Yadav

initr_dm_devices() is called somewhere after board_init(). It can be used by drivers to initialize devices to some default bootup state. Those devices might use mmio read/write operations to perform the initialization.

One such example is the mux devices. The mux framework initializes the muxes to their default state after idle state in mux_uclass_post_probe(). One type of mux controller is the MMIO mux controller. Initializing a MMIO mux to idle state can require a mmio read and write operation.

With memio disabled, the reads return 0 and the writes go off into the void. This makes it impossible to initialize muxes to their idle state on boot, and consequentially makes it impossible to test that in sandbox.

These same initializations work fine on actual hardware (tested on TI J721E EVM). So, enable memio operations on boot so devices like mux can perform whatever initialization they need. state_reset_for_test() will disable it before running tests so tests still need to enable memio manually.

---
 board/sandbox/sandbox.c | 2 ++
 1 file changed, 2 insertions(+)
board/sandbox/sandbox.c +2 -0
index 1372003018..d7eb207822 100644
@@ -55,6 +55,8 @@ int board_init(void)
 	if (IS_ENABLED(CONFIG_LED))
 		led_default_state();
 
+	sandbox_set_enable_memio(true);
+
 	return 0;
 }
 
Signature · 1 line
2.27.0
#10 lore raw

PATCH v3 5/6 sandbox: Enable memio operations in board_init

Hi Pratyush,

Quoted 17 lines · Pratyush Yadav

initr_dm_devices() is called somewhere after board_init(). It can be used by drivers to initialize devices to some default bootup state. Those devices might use mmio read/write operations to perform the initialization.

One such example is the mux devices. The mux framework initializes the muxes to their default state after idle state in mux_uclass_post_probe(). One type of mux controller is the MMIO mux controller. Initializing a MMIO mux to idle state can require a mmio read and write operation.

With memio disabled, the reads return 0 and the writes go off into the void. This makes it impossible to initialize muxes to their idle state on boot, and consequentially makes it impossible to test that in sandbox.

Quoted 5 lines

These same initializations work fine on actual hardware (tested on TI J721E EVM). So, enable memio operations on boot so devices like mux can perform whatever initialization they need. state_reset_for_test() will disable it before running tests so tests still need to enable memio manually.

We have a similar issue with PCI and we only enable it when needed. Can we do something similar here?

Quoted 20 lines
---
 board/sandbox/sandbox.c | 2 ++
 1 file changed, 2 insertions(+)
board/sandbox/sandbox.c +2 -1
index 1372003018..d7eb207822 100644
@@ -55,6 +55,8 @@ int board_init(void)
        if (IS_ENABLED(CONFIG_LED))
                led_default_state();
 
+       sandbox_set_enable_memio(true);
+
        return 0;
 }
 
--
Quoted 2 lines

2.27.0

Regards,
Simon

#11 lore raw

PATCH v3 5/6 sandbox: Enable memio operations in board_init

Hi Simon,

Quoted 20 lines · Simon Glass

Hi Pratyush,

Quoted 17 lines · Pratyush Yadav

initr_dm_devices() is called somewhere after board_init(). It can be used by drivers to initialize devices to some default bootup state. Those devices might use mmio read/write operations to perform the initialization.

One such example is the mux devices. The mux framework initializes the muxes to their default state after idle state in mux_uclass_post_probe(). One type of mux controller is the MMIO mux controller. Initializing a MMIO mux to idle state can require a mmio read and write operation.

With memio disabled, the reads return 0 and the writes go off into the void. This makes it impossible to initialize muxes to their idle state on boot, and consequentially makes it impossible to test that in sandbox.

Quoted 8 lines
Quoted 5 lines

These same initializations work fine on actual hardware (tested on TI J721E EVM). So, enable memio operations on boot so devices like mux can perform whatever initialization they need. state_reset_for_test() will disable it before running tests so tests still need to enable memio manually.

We have a similar issue with PCI and we only enable it when needed. Can we do something similar here?

I went and looked, but I can't figure out how we do it for PCI. Any pointers?

Quoted 18 lines
Quoted 18 lines
---
 board/sandbox/sandbox.c | 2 ++
 1 file changed, 2 insertions(+)
board/sandbox/sandbox.c +2 -0
index 1372003018..d7eb207822 100644
@@ -55,6 +55,8 @@ int board_init(void)
        if (IS_ENABLED(CONFIG_LED))
                led_default_state();
 
+       sandbox_set_enable_memio(true);
+
        return 0;
 }
Signature · 3 lines
Regards,
Pratyush Yadav
Texas Instruments India
#12 lore raw

PATCH v3 5/6 sandbox: Enable memio operations in board_init

Hi Pratyush,

Quoted 30 lines · Pratyush Yadav

Hi Simon,

Quoted 26 lines · Simon Glass

Hi Pratyush,

Quoted 22 lines · Pratyush Yadav

initr_dm_devices() is called somewhere after board_init(). It can be used by drivers to initialize devices to some default bootup state. Those devices might use mmio read/write operations to perform the initialization.

One such example is the mux devices. The mux framework initializes the muxes to their default state after idle state in mux_uclass_post_probe(). One type of mux controller is the MMIO mux controller. Initializing a MMIO mux to idle state can require a mmio read and write operation.

With memio disabled, the reads return 0 and the writes go off into the void. This makes it impossible to initialize muxes to their idle state on boot, and consequentially makes it impossible to test that in sandbox.

These same initializations work fine on actual hardware (tested on TI J721E EVM). So, enable memio operations on boot so devices like mux can perform whatever initialization they need. state_reset_for_test() will disable it before running tests so tests still need to enable memio manually.

Quoted 5 lines
Quoted 2 lines

We have a similar issue with PCI and we only enable it when needed. Can we do something similar here?

I went and looked, but I can't figure out how we do it for PCI. Any pointers?

Yes it is enable_pci_map in arch/sandbox/cpu/cpu.c

Regards,
Simon

#13 lore raw

PATCH v3 6/6 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. The test uses a mmio-based multiplexer.

---
 arch/sandbox/dts/test.dts |  25 ++++++
 configs/sandbox_defconfig |   2 +
 test/dm/Makefile          |   1 +
 test/dm/mux-mmio.c        | 168 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 196 insertions(+)
 create mode 100644 test/dm/mux-mmio.c
arch/sandbox/dts/test.dts +25 -0
index e8701d2603..750779d20f 100644
@@ -2,6 +2,7 @@
 
 #include <dt-bindings/gpio/gpio.h>
 #include <dt-bindings/gpio/sandbox-gpio.h>
+#include <dt-bindings/mux/mux.h>
 
 / {
 	model = "sandbox";
@@ -115,6 +116,11 @@
 		int64-value = /bits/ 64 <0x1111222233334444>;
 		int-array = <5678 9123 4567>;
 		interrupts-extended = <&irq 3 0>;
+
+		mux-controls = <&muxcontroller0 0>, <&muxcontroller0 1>,
+			       <&muxcontroller0 2>, <&muxcontroller0 3>;
+		mux-control-names = "mux0", "mux1", "mux2", "mux3";
+		mux-syscon = <&syscon3>;
 	};
 
 	another-test {
@@ -158,6 +164,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 {
@@ -787,6 +796,22 @@
 			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;
+		};
+	};
+
 	timer {
 		compatible = "sandbox,timer";
 		clock-frequency = <1000000>;
configs/sandbox_defconfig +2 -0
index 5b7569319b..c301d11992 100644
@@ -154,6 +154,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 +1 -0
index 6c18fd04ce..d7ab7e27f7 100644
@@ -54,6 +54,7 @@ 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_DM_USB) += usb.o
 obj-$(CONFIG_DM_PMIC) += pmic.o
 obj-$(CONFIG_DM_REGULATOR) += regulator.o
test/dm/mux-mmio.c new file +168 -0

168 lines not on this page · raw message

Signature · 1 line
2.27.0
#14 lore raw

PATCH v3 6/6 test: Add tests for the multiplexer framework

Quoted 10 lines · Pratyush Yadav

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

Provide tests to check the behavior of the multiplexer framework. The test uses a mmio-based multiplexer.

---
 arch/sandbox/dts/test.dts |  25 ++++++

The changes in the test.dts file don't apply at all. While I think I see where they're supposed to go, I want to be sure that you can run and pass these tests as well. When I was testing this series with the regmap series I saw a number of pytest failures, and I only bisected down to the first one that I reported. So please at minimum rebase this series on 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/20200806/6a185ed3/attachment.sig>