From: Philipp Zabel <p.zabel@pengutronix.de>
To: Peter Rosin <peda@axentia.se>
Cc: Rob Herring <robh+dt@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Sakari Ailus <sakari.ailus@iki.fi>,
Steve Longerbeam <slongerbeam@gmail.com>,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel@pengutronix.de, Philipp Zabel <p.zabel@pengutronix.de>
Subject: [RFC 2/2] mux: mmio-based syscon mux controller
Date: Thu, 13 Apr 2017 17:48:12 +0200 [thread overview]
Message-ID: <20170413154812.19597-2-p.zabel@pengutronix.de> (raw)
In-Reply-To: <20170413154812.19597-1-p.zabel@pengutronix.de>
This adds a driver for mmio-based syscon multiplexers controlled by a
single bitfield in a syscon register range.
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
drivers/mux/Kconfig | 13 +++++
drivers/mux/Makefile | 1 +
drivers/mux/mux-syscon.c | 130 +++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 144 insertions(+)
create mode 100644 drivers/mux/mux-syscon.c
diff --git a/drivers/mux/Kconfig b/drivers/mux/Kconfig
index 86668b4d2fc52..a5e6a3b01ac24 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_SYSCON
+ tristate "MMIO bitfield-controlled Multiplexer"
+ depends on OF && MFD_SYSCON
+ help
+ MMIO bitfield-controlled Multiplexer controller.
+
+ The driver builds a single multiplexer controller using a bitfield
+ 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-syscon.
+
endif
diff --git a/drivers/mux/Makefile b/drivers/mux/Makefile
index b00a7d37d2fbe..234309f6655f7 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_SYSCON) += mux-syscon.o
diff --git a/drivers/mux/mux-syscon.c b/drivers/mux/mux-syscon.c
new file mode 100644
index 0000000000000..31cacc61f1439
--- /dev/null
+++ b/drivers/mux/mux-syscon.c
@@ -0,0 +1,130 @@
+/*
+ * syscon 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/err.h>
+#include <linux/mfd/syscon.h>
+#include <linux/module.h>
+#include <linux/mux.h>
+#include <linux/of_platform.h>
+#include <linux/platform_device.h>
+#include <linux/property.h>
+#include <linux/regmap.h>
+
+struct mux_syscon {
+ struct regmap_field *field;
+};
+
+static int mux_syscon_set(struct mux_control *mux, int state)
+{
+ struct mux_syscon *mux_syscon = mux_chip_priv(mux->chip);
+
+ return regmap_field_write(mux_syscon->field, state);
+}
+
+static const struct mux_control_ops mux_syscon_ops = {
+ .set = mux_syscon_set,
+};
+
+static const struct of_device_id mux_syscon_dt_ids[] = {
+ { .compatible = "mmio-mux", },
+ { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, mux_syscon_dt_ids);
+
+static int of_get_reg_field(struct device_node *node, struct reg_field *field)
+{
+ u32 bit_mask;
+ int ret;
+
+ ret = of_property_read_u32(node, "reg", &field->reg);
+ if (ret < 0)
+ return ret;
+
+ ret = of_property_read_u32(node, "bit-mask", &bit_mask);
+ if (ret < 0)
+ return ret;
+
+ ret = of_property_read_u32(node, "bit-shift", &field->lsb);
+ if (ret < 0)
+ return ret;
+
+ field->msb = field->lsb + fls(bit_mask) - 1;
+
+ return 0;
+}
+
+static int mux_syscon_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct mux_chip *mux_chip;
+ struct mux_syscon *mux_syscon;
+ struct regmap *regmap;
+ struct reg_field field;
+ int bits;
+ s32 idle_state;
+ int ret;
+
+ ret = of_get_reg_field(pdev->dev.of_node, &field);
+ if (ret) {
+ dev_err(&pdev->dev, "missing bit-field properties: %d\n", ret);
+ return ret;
+ }
+
+ regmap = syscon_node_to_regmap(pdev->dev.of_node->parent);
+ if (IS_ERR(regmap)) {
+ ret = PTR_ERR(regmap);
+ dev_err(&pdev->dev, "failed to get syscon regmap: %d\n", ret);
+ return ret;
+ }
+
+ mux_chip = devm_mux_chip_alloc(dev, 1, sizeof(*mux_syscon));
+ if (!mux_chip)
+ return -ENOMEM;
+
+ mux_syscon = mux_chip_priv(mux_chip);
+ mux_chip->ops = &mux_syscon_ops;
+
+ mux_syscon->field = devm_regmap_field_alloc(&pdev->dev, regmap, field);
+ if (IS_ERR(mux_syscon->field)) {
+ ret = PTR_ERR(mux_syscon->field);
+ dev_err(&pdev->dev, "failed to regmap bit-field: %d\n", ret);
+ return ret;
+ }
+ bits = 1 + field.msb - field.lsb;
+
+ mux_chip->mux->states = 1 << bits;
+
+ ret = device_property_read_u32(dev, "idle-state", (u32 *)&idle_state);
+ if (ret >= 0 && idle_state != MUX_IDLE_AS_IS) {
+ if (idle_state < 0 || idle_state >= mux_chip->mux->states) {
+ dev_err(dev, "invalid idle-state %u\n", idle_state);
+ return -EINVAL;
+ }
+
+ mux_chip->mux->idle_state = idle_state;
+ }
+
+ regmap_field_read(mux_syscon->field, &mux_chip->mux->cached_state);
+
+ return devm_mux_chip_register(dev, mux_chip);
+}
+
+static struct platform_driver mux_syscon_driver = {
+ .driver = {
+ .name = "mmio-mux",
+ .of_match_table = of_match_ptr(mux_syscon_dt_ids),
+ },
+ .probe = mux_syscon_probe,
+};
+module_platform_driver(mux_syscon_driver);
+
+MODULE_DESCRIPTION("MMIO bitfield-controlled multiplexer driver");
+MODULE_AUTHOR("Philipp Zabel <p.zabel@pengutronix.de>");
+MODULE_LICENSE("GPL v2");
--
2.11.0
next prev parent reply other threads:[~2017-04-13 15:48 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-13 15:48 [RFC 1/2] dt-bindings: add mmio-based syscon mux controller DT bindings Philipp Zabel
2017-04-13 15:48 ` Philipp Zabel [this message]
2017-04-14 1:09 ` [RFC 2/2] mux: mmio-based syscon mux controller Steve Longerbeam
2017-04-19 11:50 ` Philipp Zabel
2017-04-19 11:58 ` Peter Rosin
2017-04-19 15:27 ` Philipp Zabel
2017-04-19 16:23 ` Steve Longerbeam
2017-04-19 16:32 ` Philipp Zabel
2017-04-19 16:42 ` Peter Rosin
2017-04-14 1:03 ` [RFC 1/2] dt-bindings: add mmio-based syscon mux controller DT bindings Steve Longerbeam
2017-04-19 11:47 ` Philipp Zabel
2017-04-18 8:19 ` Philipp Zabel
2017-04-18 10:08 ` Sakari Ailus
2017-04-18 10:34 ` Pavel Machek
2017-04-18 10:55 ` Sakari Ailus
2017-04-18 11:51 ` Pavel Machek
2017-04-18 10:51 ` Philipp Zabel
2017-04-19 22:09 ` Rob Herring
2017-04-20 8:14 ` Philipp Zabel
2017-04-20 11:57 ` Peter Rosin
2017-04-20 13:03 ` Philipp Zabel
2017-04-20 13:39 ` Rob Herring
2017-04-20 13:32 ` Peter Rosin
2017-04-20 14:13 ` Peter Rosin
2017-04-20 14:50 ` Philipp Zabel
2017-04-20 15:01 ` Peter Rosin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170413154812.19597-2-p.zabel@pengutronix.de \
--to=p.zabel@pengutronix.de \
--cc=devicetree@vger.kernel.org \
--cc=kernel@pengutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=peda@axentia.se \
--cc=robh+dt@kernel.org \
--cc=sakari.ailus@iki.fi \
--cc=slongerbeam@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).