[PATCH v3 3/6] drivers: mux: mmio-based syscon mux controller
Simon Glass
sjg at chromium.org
Wed Jun 17 05:12:10 CEST 2020
Hi Pratyush,
On Thu, 11 Jun 2020 at 13:45, Pratyush Yadav <p.yadav at ti.com> wrote:
>
> From: Jean-Jacques Hiblot <jjhiblot at ti.com>
>
> 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 <jjhiblot at ti.com>
> Reviewed-by: Simon Glass <sjg at chromium.org>
> Signed-off-by: Pratyush Yadav <p.yadav at ti.com>
> ---
> 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
Reviewed-by: Simon Glass <sjg at chromium.org>
nit below
>
> diff --git a/drivers/mux/Kconfig b/drivers/mux/Kconfig
> index 35c1c5673c..f15ee4f833 100644
> --- a/drivers/mux/Kconfig
> +++ b/drivers/mux/Kconfig
> @@ -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
> diff --git a/drivers/mux/Makefile b/drivers/mux/Makefile
> index 351e4363d3..78ebf04c7a 100644
> --- a/drivers/mux/Makefile
> +++ b/drivers/mux/Makefile
> @@ -4,3 +4,4 @@
> # Jean-Jacques Hiblot <jjhiblot at ti.com>
>
> obj-$(CONFIG_$(SPL_)MULTIPLEXER) += mux-uclass.o
> +obj-$(CONFIG_$(SPL_)MUX_MMIO) += mmio.o
> diff --git a/drivers/mux/mmio.c b/drivers/mux/mmio.c
> new file mode 100644
> index 0000000000..573e599dd1
> --- /dev/null
> +++ b/drivers/mux/mmio.c
> @@ -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 <kernel at pengutronix.de>
> + * Copyright (C) 2019 Texas Instrument, Jean-jacques Hiblot <jjhiblot at ti.com>
> + */
> +#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;
> +
> + 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
More information about the U-Boot
mailing list