drivers: Add a framework for MUX drivers
Subsystems (2)
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
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
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.
Signed-off-by Jean-Jacques Hiblot <[email protected]>Signed-off-by Pratyush Yadav <[email protected]>--- 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
PATCH v3 2/6 dm: board: complete the initialization of the muxes in initr_dm()
In reply to Pratyush YadavFrom: 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
@@ -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
@@ -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
@@ -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
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
Signed-off-by Jean-Jacques Hiblot <[email protected]>Signed-off-by Pratyush Yadav <[email protected]>--- common/board_r.c | 12 ++++++++++++ drivers/mux/mux-uclass.c | 23 +++++++++++++++++++++++ include/mux.h | 12 ++++++++++++ 3 files changed, 47 insertions(+)
PATCH v3 3/6 drivers: mux: mmio-based syscon mux controller
In reply to Pratyush YadavFrom: 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
@@ -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
@@ -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
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.Signed-off-by Jean-Jacques Hiblot <[email protected]>Reviewed-by Simon Glass <[email protected]>Signed-off-by Pratyush Yadav <[email protected]>
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@@ -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 + endmenudrivers/mux/Makefile +1
-0@@ -4,3 +4,4 @@ # Jean-Jacques Hiblot <[email protected]> obj-$(CONFIG_$(SPL_)MULTIPLEXER) += mux-uclass.o +obj-$(CONFIG_$(SPL_)MUX_MMIO) += mmio.odrivers/mux/mmio.c new file +46
-0@@ -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
PATCH v3 4/6 cmd: Add a mux command
In reply to Pratyush YadavThis 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 0x4Select: 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 0x4Deselect: 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
@@ -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
@@ -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
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 0x100another-mux-controller:
ID Selected Current State Idle State Num States 0 no 0x1 0x1 0x4 1 no 0x2 0x2 0x4Select: 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 0x4Deselect: 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
Signed-off-by Pratyush Yadav <[email protected]>--- 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.
PATCH v3 5/6 sandbox: Enable memio operations in board_init
In reply to Pratyush Yadavinitr_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
@@ -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
PATCH v3 5/6 sandbox: Enable memio operations in board_init
Hi Pratyush,
Quoted 17 lines · Pratyush Yadav
initr_dm_devices()is called somewhere afterboard_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
Signed-off-by Pratyush Yadav <[email protected]>--- board/sandbox/sandbox.c | 2 ++ 1 file changed, 2 insertions(+)board/sandbox/sandbox.c +2
-1@@ -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
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 afterboard_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
Signed-off-by Pratyush Yadav <[email protected]>--- board/sandbox/sandbox.c | 2 ++ 1 file changed, 2 insertions(+)board/sandbox/sandbox.c +2
-0@@ -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
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 afterboard_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
PATCH v3 6/6 test: Add tests for the multiplexer framework
In reply to Pratyush YadavFrom: 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
@@ -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
@@ -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
@@ -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
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.
Signed-off-by Jean-Jacques Hiblot <[email protected]>Reviewed-by Simon Glass <[email protected]>Signed-off-by Pratyush Yadav <[email protected]>--- 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>