Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1632819 > unrolled thread

[RFC v3 1/2] dt-bindings: add mmio-based syscon mux controller DT bindings

Started byPhilipp Zabel <p.zabel@pengutronix.de>
First post2017-04-28 14:00 +0200
Last post2017-05-05 22:00 +0200
Articles 4 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [RFC v3 1/2] dt-bindings: add mmio-based syscon mux controller DT bindings Philipp Zabel <p.zabel@pengutronix.de> - 2017-04-28 14:00 +0200
    [RFC v3 2/2] mux: mmio-based syscon mux controller Philipp Zabel <p.zabel@pengutronix.de> - 2017-04-28 14:00 +0200
      Re: [RFC v3 2/2] mux: mmio-based syscon mux controller Philipp Zabel <p.zabel@pengutronix.de> - 2017-05-08 10:20 +0200
    Re: [RFC v3 1/2] dt-bindings: add mmio-based syscon mux controller  DT bindings Rob Herring <robh@kernel.org> - 2017-05-05 22:00 +0200

#1632819 — [RFC v3 1/2] dt-bindings: add mmio-based syscon mux controller DT bindings

FromPhilipp Zabel <p.zabel@pengutronix.de>
Date2017-04-28 14:00 +0200
Subject[RFC v3 1/2] dt-bindings: add mmio-based syscon mux controller DT bindings
Message-ID<tBcJ4-6Ni-1@gated-at.bofh.it>
This adds device tree binding documentation for mmio-based syscon
multiplexers controlled by a bitfieldis in a syscon register range.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
Changes since v2:
 - Updated multi-mux DT binding description
 - Removed superfluous @3 from example
---
 Documentation/devicetree/bindings/mux/mmio-mux.txt | 60 ++++++++++++++++++++++
 1 file changed, 60 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mux/mmio-mux.txt

diff --git a/Documentation/devicetree/bindings/mux/mmio-mux.txt b/Documentation/devicetree/bindings/mux/mmio-mux.txt
new file mode 100644
index 0000000000000..a9bfb4d8b6ac8
--- /dev/null
+++ b/Documentation/devicetree/bindings/mux/mmio-mux.txt
@@ -0,0 +1,60 @@
+MMIO register bitfield-based multiplexer controller bindings
+
+Define register bitfields to be used to control multiplexers. The parent
+device tree node must be a syscon node to provide register access.
+
+Required properties:
+- compatible : "mmio-mux"
+- #mux-control-cells : <1>
+- mux-reg-masks : an array of register offset and pre-shifted bitfield mask
+                  pairs, each describing a single mux control.
+* Standard mux-controller bindings as decribed in mux-controller.txt
+
+Optional properties:
+- idle-states : if present, the state the muxes will have when idle. The
+		special state MUX_IDLE_AS_IS is the default.
+
+The multiplexer state of each multiplexer is defined as the value of the
+bitfield described by the corresponding register offset and bitfield mask pair
+in the mux-reg-masks array, accessed through the parent syscon.
+
+Example:
+
+	syscon {
+		compatible = "syscon";
+
+		mux: mux-controller {
+			compatible = "mmio-mux";
+			#mux-control-cells = <1>;
+
+			mux-reg-masks = <0x3 0x30>, /* 0: reg 0x3, bits 5:4 */
+					<0x3 0x40>, /* 1: reg 0x3, bit 6 */
+			idle-states = <MUX_IDLE_AS_IS>, <0>;
+		};
+	};
+
+	video-mux {
+		compatible = "video-mux";
+		mux-controls = <&mux 0>;
+
+		ports {
+			/* inputs 0..3 */
+			port@0 {
+				reg = <0>;
+			};
+			port@1 {
+				reg = <1>;
+			};
+			port@2 {
+				reg = <2>;
+			};
+			port@3 {
+				reg = <3>;
+			};
+
+			/* output */
+			port@4 {
+				reg = <4>;
+			};
+		};
+	};
-- 
2.11.0

[toc] | [next] | [standalone]


#1632820 — [RFC v3 2/2] mux: mmio-based syscon mux controller

FromPhilipp Zabel <p.zabel@pengutronix.de>
Date2017-04-28 14:00 +0200
Subject[RFC v3 2/2] mux: mmio-based syscon mux controller
Message-ID<tBcJ4-6Ni-5@gated-at.bofh.it>
In reply to#1632819
This adds a driver for mmio-based syscon multiplexers controlled by
bitfields in a syscon register range.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
Changes since v2:
 - Updated CONFIG description to multi-mux
 - Use mux_control_get_index instead of open-coding it
 - Read mux-reg-masks and idle-states values in a single loop using
   individual read_u32_index calls instead of using read_u32_array
 - Verify bitmask
---
 drivers/mux/Kconfig    |  13 +++++
 drivers/mux/Makefile   |   1 +
 drivers/mux/mux-mmio.c | 140 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 154 insertions(+)
 create mode 100644 drivers/mux/mux-mmio.c

diff --git a/drivers/mux/Kconfig b/drivers/mux/Kconfig
index 34b8284d6d29e..50e7c5d557a05 100644
--- a/drivers/mux/Kconfig
+++ b/drivers/mux/Kconfig
@@ -43,4 +43,17 @@ config MUX_GPIO
 	  To compile the driver as a module, choose M here: the module will
 	  be called mux-gpio.
 
+config MUX_MMIO
+	tristate "MMIO register bitfield-controlled Multiplexer"
+	depends on OF && MFD_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.
+
+	  To compile the driver as a module, choose M here: the module will
+	  be called mux-mmio.
+
 endif
diff --git a/drivers/mux/Makefile b/drivers/mux/Makefile
index b00a7d37d2fbe..6bac5b0fea137 100644
--- a/drivers/mux/Makefile
+++ b/drivers/mux/Makefile
@@ -5,3 +5,4 @@
 obj-$(CONFIG_MULTIPLEXER)	+= mux-core.o
 obj-$(CONFIG_MUX_ADG792A)	+= mux-adg792a.o
 obj-$(CONFIG_MUX_GPIO)		+= mux-gpio.o
+obj-$(CONFIG_MUX_MMIO)		+= mux-mmio.o
diff --git a/drivers/mux/mux-mmio.c b/drivers/mux/mux-mmio.c
new file mode 100644
index 0000000000000..d2477d62d6eed
--- /dev/null
+++ b/drivers/mux/mux-mmio.c
@@ -0,0 +1,140 @@
+/*
+ * MMIO register bitfield-controlled multiplexer driver
+ *
+ * Copyright (C) 2017 Pengutronix, Philipp Zabel <kernel@pengutronix.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/bitops.h>
+#include <linux/err.h>
+#include <linux/mfd/syscon.h>
+#include <linux/module.h>
+#include <linux/mux/driver.h>
+#include <linux/of_platform.h>
+#include <linux/platform_device.h>
+#include <linux/property.h>
+#include <linux/regmap.h>
+
+static int mux_mmio_set(struct mux_control *mux, int state)
+{
+	struct regmap_field **fields = mux_chip_priv(mux->chip);
+
+	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 of_device_id mux_mmio_dt_ids[] = {
+	{ .compatible = "mmio-mux", },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, mux_mmio_dt_ids);
+
+static int mux_mmio_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct device_node *np = dev->of_node;
+	struct regmap_field **fields;
+	struct mux_chip *mux_chip;
+	struct regmap *regmap;
+	int num_fields;
+	int ret;
+	int i;
+
+	regmap = syscon_node_to_regmap(np->parent);
+	if (IS_ERR(regmap)) {
+		ret = PTR_ERR(regmap);
+		dev_err(dev, "failed to get regmap: %d\n", ret);
+		return ret;
+	}
+
+	ret = of_property_count_u32_elems(np, "mux-reg-masks");
+	if (ret == 0 || ret % 2)
+		ret = -EINVAL;
+	if (ret < 0) {
+		dev_err(dev, "mux-reg-masks property missing or invalid: %d\n",
+			ret);
+		return ret;
+	}
+	num_fields = ret / 2;
+
+	mux_chip = devm_mux_chip_alloc(dev, num_fields, num_fields *
+				       sizeof(*fields));
+	if (IS_ERR(mux_chip))
+		return PTR_ERR(mux_chip);
+
+	fields = mux_chip_priv(mux_chip);
+
+	for (i = 0; i < num_fields; i++) {
+		struct mux_control *mux = &mux_chip->mux[i];
+		struct reg_field field;
+		s32 idle_state = MUX_IDLE_AS_IS;
+		u32 reg, mask;
+		int bits;
+
+		ret = of_property_read_u32_index(np, "mux-reg-masks",
+						 2 * i, &reg);
+		if (!ret)
+			ret = of_property_read_u32_index(np, "mux-reg-masks",
+							 2 * i + 1, &mask);
+		if (ret < 0) {
+			dev_err(dev, "bitfield %d: failed to read mux-reg-masks property: %d\n",
+				i, ret);
+			return ret;
+		}
+
+		field.reg = reg;
+		field.msb = fls(mask) - 1;
+		field.lsb = ffs(mask) - 1;
+
+		if (mask != GENMASK(field.msb, field.lsb)) {
+			dev_err(dev, "bitfield %d: invalid mask 0x%x\n",
+				i, mask);
+			return -EINVAL;
+		}
+
+		fields[i] = devm_regmap_field_alloc(dev, regmap, field);
+		if (IS_ERR(fields[i])) {
+			ret = PTR_ERR(fields[i]);
+			dev_err(dev, "bitfield %d: failed allocate: %d\n",
+				i, ret);
+			return ret;
+		}
+
+		bits = 1 + field.msb - field.lsb;
+		mux->states = 1 << bits;
+
+		of_property_read_u32_index(np, "idle-states", i, &idle_state);
+		if (idle_state != MUX_IDLE_AS_IS) {
+			if (idle_state < 0 || idle_state >= mux->states) {
+				dev_err(dev, "bitfield: %d: out of range idle state %d\n",
+					i, idle_state);
+				return -EINVAL;
+			}
+
+			mux->idle_state = idle_state;
+		}
+	}
+
+	mux_chip->ops = &mux_mmio_ops;
+
+	return devm_mux_chip_register(dev, mux_chip);
+}
+
+static struct platform_driver mux_mmio_driver = {
+	.driver = {
+		.name = "mmio-mux",
+		.of_match_table	= of_match_ptr(mux_mmio_dt_ids),
+	},
+	.probe = mux_mmio_probe,
+};
+module_platform_driver(mux_mmio_driver);
+
+MODULE_DESCRIPTION("MMIO register bitfield-controlled multiplexer driver");
+MODULE_AUTHOR("Philipp Zabel <p.zabel@pengutronix.de>");
+MODULE_LICENSE("GPL v2");
-- 
2.11.0

[toc] | [prev] | [next] | [standalone]


#1637294 — Re: [RFC v3 2/2] mux: mmio-based syscon mux controller

FromPhilipp Zabel <p.zabel@pengutronix.de>
Date2017-05-08 10:20 +0200
SubjectRe: [RFC v3 2/2] mux: mmio-based syscon mux controller
Message-ID<tEM3E-1q2-11@gated-at.bofh.it>
In reply to#1632820
Hi Peter,

On Mon, 2017-05-08 at 10:00 +0200, Peter Rosin wrote:
> Hi Philipp,
> 
> With the ack on the bindings in place, I'm going to pile these
> two patches on top of my mux series when I send v15 next week (or
> whenever v4.12-rc1 is out). There are a pair of nitpicks that I'm
> going to fix myself, so no need for a resend.

Yes, please. While at it, could you also fix my "bitfieldis" typo in the
commit description of patch 1.

> Thank you very much for making use of the new code, I hope the
> "3rd party interest" will help getting the mux series merged...

Thanks to Sakari for pointing it out in the video-mux review.

regards
Philipp

[toc] | [prev] | [next] | [standalone]


#1636692 — Re: [RFC v3 1/2] dt-bindings: add mmio-based syscon mux controller DT bindings

FromRob Herring <robh@kernel.org>
Date2017-05-05 22:00 +0200
SubjectRe: [RFC v3 1/2] dt-bindings: add mmio-based syscon mux controller DT bindings
Message-ID<tDRyp-6eu-3@gated-at.bofh.it>
In reply to#1632819
On Fri, Apr 28, 2017 at 01:52:03PM +0200, Philipp Zabel wrote:
> This adds device tree binding documentation for mmio-based syscon
> multiplexers controlled by a bitfieldis in a syscon register range.
> 
> Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
> ---
> Changes since v2:
>  - Updated multi-mux DT binding description
>  - Removed superfluous @3 from example
> ---
>  Documentation/devicetree/bindings/mux/mmio-mux.txt | 60 ++++++++++++++++++++++
>  1 file changed, 60 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/mux/mmio-mux.txt

Acked-by: Rob Herring <robh@kernel.org>

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web