mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Andrey Smirnov <andrew.smirnov@gmail.com>
To: barebox@lists.infradead.org
Cc: Andrey Smirnov <andrew.smirnov@gmail.com>
Subject: [PATCH v3 02/17] regulator: Port basic regmap regulator functions
Date: Tue, 15 Jan 2019 12:25:46 -0800	[thread overview]
Message-ID: <20190115202601.24831-3-andrew.smirnov@gmail.com> (raw)
In-Reply-To: <20190115202601.24831-1-andrew.smirnov@gmail.com>

In order to be able to port Linux driver relying on this API, port
various regmap related regulator function to Barebox.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 drivers/regulator/Makefile  |  2 +-
 drivers/regulator/helpers.c | 87 +++++++++++++++++++++++++++++++++++++
 include/regulator.h         | 11 ++++-
 3 files changed, 98 insertions(+), 2 deletions(-)
 create mode 100644 drivers/regulator/helpers.c

diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index ff5daf9a7d..36ce3e87f7 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -1,4 +1,4 @@
-obj-$(CONFIG_REGULATOR) += core.o
+obj-$(CONFIG_REGULATOR) += core.o helpers.o
 obj-$(CONFIG_REGULATOR_FIXED) += fixed.o
 obj-$(CONFIG_REGULATOR_BCM283X) += bcm2835.o
 obj-$(CONFIG_REGULATOR_PFUZE) += pfuze.o
\ No newline at end of file
diff --git a/drivers/regulator/helpers.c b/drivers/regulator/helpers.c
new file mode 100644
index 0000000000..4495b4403f
--- /dev/null
+++ b/drivers/regulator/helpers.c
@@ -0,0 +1,87 @@
+#include <common.h>
+#include <regmap.h>
+#include <regulator.h>
+
+/**
+ * regulator_is_enabled_regmap - standard is_enabled() for regmap users
+ *
+ * @rdev: regulator to operate on
+ *
+ * Regulators that use regmap for their register I/O can set the
+ * enable_reg and enable_mask fields in their descriptor and then use
+ * this as their is_enabled operation, saving some code.
+ */
+int regulator_is_enabled_regmap(struct regulator_dev *rdev)
+{
+	unsigned int val;
+	int ret;
+
+	ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val);
+	if (ret != 0)
+		return ret;
+
+	val &= rdev->desc->enable_mask;
+
+	if (rdev->desc->enable_is_inverted) {
+		if (rdev->desc->enable_val)
+			return val != rdev->desc->enable_val;
+		return val == 0;
+	} else {
+		if (rdev->desc->enable_val)
+			return val == rdev->desc->enable_val;
+		return val != 0;
+	}
+}
+EXPORT_SYMBOL_GPL(regulator_is_enabled_regmap);
+
+/**
+ * regulator_enable_regmap - standard enable() for regmap users
+ *
+ * @rdev: regulator to operate on
+ *
+ * Regulators that use regmap for their register I/O can set the
+ * enable_reg and enable_mask fields in their descriptor and then use
+ * this as their enable() operation, saving some code.
+ */
+int regulator_enable_regmap(struct regulator_dev *rdev)
+{
+	unsigned int val;
+
+	if (rdev->desc->enable_is_inverted) {
+		val = rdev->desc->disable_val;
+	} else {
+		val = rdev->desc->enable_val;
+		if (!val)
+			val = rdev->desc->enable_mask;
+	}
+
+	return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
+				  rdev->desc->enable_mask, val);
+}
+EXPORT_SYMBOL_GPL(regulator_enable_regmap);
+
+/**
+ * regulator_disable_regmap - standard disable() for regmap users
+ *
+ * @rdev: regulator to operate on
+ *
+ * Regulators that use regmap for their register I/O can set the
+ * enable_reg and enable_mask fields in their descriptor and then use
+ * this as their disable() operation, saving some code.
+ */
+int regulator_disable_regmap(struct regulator_dev *rdev)
+{
+	unsigned int val;
+
+	if (rdev->desc->enable_is_inverted) {
+		val = rdev->desc->enable_val;
+		if (!val)
+			val = rdev->desc->enable_mask;
+	} else {
+		val = rdev->desc->disable_val;
+	}
+
+	return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
+				  rdev->desc->enable_mask, val);
+}
+EXPORT_SYMBOL_GPL(regulator_disable_regmap);
diff --git a/include/regulator.h b/include/regulator.h
index 907073607f..1824e6ea14 100644
--- a/include/regulator.h
+++ b/include/regulator.h
@@ -6,10 +6,17 @@ struct regulator;
 
 struct regulator_desc {
 	const struct regulator_ops *ops;
+
+	unsigned int enable_reg;
+	unsigned int enable_mask;
+	unsigned int enable_val;
+	unsigned int disable_val;
+	bool enable_is_inverted;
 };
 
 struct regulator_dev {
 	const struct regulator_desc *desc;
+	struct regmap *regmap;
 	int boot_on;
 };
 
@@ -39,7 +46,9 @@ void regulators_print(void);
 struct regulator *regulator_get(struct device_d *, const char *);
 int regulator_enable(struct regulator *);
 int regulator_disable(struct regulator *);
-
+int regulator_is_enabled_regmap(struct regulator_dev *);
+int regulator_enable_regmap(struct regulator_dev *);
+int regulator_disable_regmap(struct regulator_dev *);
 #else
 
 static inline struct regulator *regulator_get(struct device_d *dev, const char *id)
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2019-01-15 20:26 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-15 20:25 [PATCH v3 00/17] PCIe support for i.MX7 Andrey Smirnov
2019-01-15 20:25 ` [PATCH v3 01/17] regulator: Convert drivers to use struct regulator_desc Andrey Smirnov
2019-01-15 20:25 ` Andrey Smirnov [this message]
2019-01-15 20:25 ` [PATCH v3 03/17] regulator: Add support for setting regulator's voltage Andrey Smirnov
2019-01-15 20:25 ` [PATCH v3 04/17] base: driver: Drop redundant list_empty() check Andrey Smirnov
2019-01-15 20:25 ` [PATCH v3 05/17] regulator: Assume probe deferral instead of missing regulator Andrey Smirnov
2019-01-15 20:25 ` [PATCH v3 06/17] regulator: Port ANATOP driver from Linux Andrey Smirnov
2019-01-16  2:10   ` Andrey Smirnov
2019-01-15 20:25 ` [PATCH v3 07/17] drivers: base: Port power management code " Andrey Smirnov
2019-01-15 20:25 ` [PATCH v3 08/17] soc: imx: Add GPCv2 power gating driver Andrey Smirnov
2019-01-15 20:25 ` [PATCH v3 09/17] reset: Add i.MX7 SRC reset driver Andrey Smirnov
2019-01-15 20:25 ` [PATCH v3 10/17] reset: Mark local functions as static Andrey Smirnov
2019-01-15 20:25 ` [PATCH v3 11/17] PCI: imx6: Add code to support i.MX7D Andrey Smirnov
2019-01-15 20:25 ` [PATCH v3 12/17] PCI: imx6: Allow probe deferral by reset GPIO Andrey Smirnov
2019-01-15 20:25 ` [PATCH v3 13/17] PCI: imx6: Do not wait for speed change on i.MX7 Andrey Smirnov
2019-01-15 20:25 ` [PATCH v3 14/17] PCI: imx6: Do not switch speed if Gen2 is disabled Andrey Smirnov
2019-01-15 20:25 ` [PATCH v3 15/17] PCI: imx6: Fix spelling mistake: "contol" -> "control" Andrey Smirnov
2019-01-15 20:26 ` [PATCH v3 16/17] PCI: imx6: Drop unnecessary root_bus_nr setting Andrey Smirnov
2019-01-15 20:26 ` [PATCH v3 17/17] PCI: imx6: Port imx6_pcie_ltssm_enable() Andrey Smirnov

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=20190115202601.24831-3-andrew.smirnov@gmail.com \
    --to=andrew.smirnov@gmail.com \
    --cc=barebox@lists.infradead.org \
    /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