mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrzej Hajda <a.hajda@samsung.com>
To: linux-kernel@vger.kernel.org (open list)
Cc: Andrzej Hajda <a.hajda@samsung.com>,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Mike Turquette <mturquette@linaro.org>,
	Russell King <linux@arm.linux.org.uk>,
	Linus Walleij <linus.walleij@linaro.org>,
	Alexandre Courbot <gnurou@gmail.com>,
	Thierry Reding <thierry.reding@gmail.com>,
	Inki Dae <inki.dae@samsung.com>,
	Kishon Vijay Abraham I <kishon@ti.com>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@kernel.org>,
	Grant Likely <grant.likely@linaro.org>,
	Rob Herring <robh+dt@kernel.org>,
	linux-arm-kernel@lists.infradead.org (moderated list:ARM/CLKDEV
	SUPPORT), linux-gpio@vger.kernel.org (open list:GPIO SUBSYSTEM),
	dri-devel@lists.freedesktop.org (open list:DRM PANEL DRIVERS),
	linux-samsung-soc@vger.kernel.org (moderated list:ARM/S5P EXYNOS
	AR...),
	devicetree@vger.kernel.org (open list:OPEN FIRMWARE AND...),
	boris.brezillon@free-electrons.com
Subject: [RFC 04/15] regulator: add restrack support
Date: Wed, 10 Dec 2014 16:48:22 +0100	[thread overview]
Message-ID: <1418226513-14105-5-git-send-email-a.hajda@samsung.com> (raw)
In-Reply-To: <1418226513-14105-1-git-send-email-a.hajda@samsung.com>

Regulators supports various methods of lookup.
The patch adds restrack support only to DT based regulators.

Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
---
 drivers/regulator/core.c           | 77 ++++++++++++++++++++++++++++++++++++++
 include/linux/regulator/consumer.h | 10 +++++
 include/linux/restrack.h           |  1 +
 3 files changed, 88 insertions(+)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index cd87c0c..5641e85 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -32,6 +32,7 @@
 #include <linux/regulator/driver.h>
 #include <linux/regulator/machine.h>
 #include <linux/module.h>
+#include <linux/restrack.h>
 
 #define CREATE_TRACE_POINTS
 #include <trace/events/regulator.h>
@@ -3733,6 +3734,10 @@ add_dev:
 	rdev_init_debugfs(rdev);
 out:
 	mutex_unlock(&regulator_list_mutex);
+
+	if (rdev->dev.of_node)
+		restrack_up(RESTRACK_TYPE_REGULATOR, rdev->dev.of_node, rdev);
+
 	return rdev;
 
 unset_supplies:
@@ -3767,6 +3772,9 @@ void regulator_unregister(struct regulator_dev *rdev)
 	if (rdev == NULL)
 		return;
 
+	if (rdev->dev.of_node)
+		restrack_down(RESTRACK_TYPE_REGULATOR, rdev->dev.of_node, rdev);
+
 	if (rdev->supply) {
 		while (rdev->use_count--)
 			regulator_disable(rdev->supply);
@@ -3971,6 +3979,75 @@ static const struct file_operations supply_map_fops = {
 #endif
 };
 
+struct regulator_restrack_desc {
+	struct regulator **ptr;
+	const char *name;
+	struct restrack_desc desc;
+};
+
+static int regulator_restrack_init(struct device *dev,
+		struct restrack_desc *desc)
+{
+	struct regulator_restrack_desc *rd = restrack_desc_to_rd(rd, desc);
+
+	desc->if_id = of_get_regulator(dev, rd->name);
+	return PTR_ERR_OR_ZERO(desc->if_id);
+}
+
+static void regulator_restrack_destroy(struct device *dev,
+		struct restrack_desc *desc)
+{
+	struct regulator_restrack_desc *rd = restrack_desc_to_rd(rd, desc);
+
+	of_node_put(desc->if_id);
+	kfree(rd);
+}
+
+static int regulator_restrack_ifup(struct device *dev,
+		struct restrack_desc *desc, void *data)
+{
+	struct regulator_restrack_desc *rd = restrack_desc_to_rd(rd, desc);
+
+	*rd->ptr = regulator_get(dev, rd->name);
+	return PTR_ERR_OR_ZERO(*rd->ptr);
+}
+
+static void regulator_restrack_ifdown(struct device *dev,
+		struct restrack_desc *desc, void *data)
+{
+	struct regulator_restrack_desc *rd = restrack_desc_to_rd(rd, desc);
+
+	regulator_put(*rd->ptr);
+	*rd->ptr = ERR_PTR(-EPROBE_DEFER);
+}
+
+static const struct restrack_ops regulator_restrack_ops = {
+	.if_type = RESTRACK_TYPE_REGULATOR,
+	.init = regulator_restrack_init,
+	.destroy = regulator_restrack_destroy,
+	.if_up = regulator_restrack_ifup,
+	.if_down = regulator_restrack_ifdown,
+};
+
+/**
+ * regulator_restrack_desc - regulator resource descriptor allocator
+ * @regulator: pointer to variable which will be set to regulator handle
+ * @name: name of regulator
+ *
+ * The function creates resource description for regulator, which shall be used
+ * by *restrack_register functions.
+ */
+struct restrack_desc *regulator_restrack_desc(struct regulator **regulator,
+		const char *name)
+{
+	struct regulator_restrack_desc *rd;
+
+	RESTRACK_DESC_ALLOC(rd, regulator_restrack_ops, regulator, name);
+
+	return rd ? &rd->desc : ERR_PTR(-ENOMEM);
+}
+EXPORT_SYMBOL_GPL(regulator_restrack_desc);
+
 static int __init regulator_init(void)
 {
 	int ret;
diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h
index f540b14..69e71ebb 100644
--- a/include/linux/regulator/consumer.h
+++ b/include/linux/regulator/consumer.h
@@ -551,4 +551,14 @@ static inline int regulator_is_supported_voltage_tol(struct regulator *regulator
 					      target_uV + tol_uV);
 }
 
+struct restrack_desc;
+struct restrack_desc *regulator_restrack_desc(struct regulator **regulator,
+		const char *supply);
+
+static inline struct restrack_desc *
+regulator_bulk_restrack_desc(struct regulator_bulk_data *data)
+{
+	return regulator_restrack_desc(&data->consumer, data->supply);
+}
+
 #endif
diff --git a/include/linux/restrack.h b/include/linux/restrack.h
index af5b617..4e4eec6 100644
--- a/include/linux/restrack.h
+++ b/include/linux/restrack.h
@@ -4,6 +4,7 @@
 #include <linux/track.h>
 
 #define RESTRACK_TYPE_DRM_PANEL 1
+#define RESTRACK_TYPE_REGULATOR 2
 
 struct device;
 struct restrack_ctx;
-- 
1.9.1


  parent reply	other threads:[~2014-12-10 15:52 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-10 15:48 [RFC 00/15] Resource tracking/allocation framework Andrzej Hajda
2014-12-10 15:48 ` [RFC 01/15] drivers/base: add track framework Andrzej Hajda
2014-12-12 16:36   ` Mark Brown
2014-12-12 23:12     ` AH
2014-12-15 12:55       ` Mark Brown
2014-12-15 14:00         ` Andrzej Hajda
2014-12-10 15:48 ` [RFC 02/15] drivers/base: add restrack framework Andrzej Hajda
2014-12-12 16:52   ` Mark Brown
2014-12-15  8:28     ` Andrzej Hajda
2014-12-15 11:38       ` Mark Brown
2014-12-10 15:48 ` [RFC 03/15] drm/panel: add restrack support Andrzej Hajda
2014-12-10 15:48 ` Andrzej Hajda [this message]
2014-12-10 16:07   ` [RFC 04/15] regulator: " Mark Brown
2014-12-11 10:49     ` Andrzej Hajda
2014-12-11 12:58       ` Mark Brown
2014-12-11 13:43         ` Russell King - ARM Linux
2014-12-12  8:22           ` Andrzej Hajda
2014-12-10 15:48 ` [RFC 05/15] gpio: move DT parsing code to separate functions Andrzej Hajda
2015-01-13  6:17   ` Linus Walleij
2014-12-10 15:48 ` [RFC 06/15] gpio: add restrack support Andrzej Hajda
2014-12-10 15:48 ` [RFC 07/15] clk: add DT parsing function Andrzej Hajda
2015-01-13 19:24   ` Mike Turquette
2014-12-10 15:48 ` [RFC 08/15] clk: add restrack support Andrzej Hajda
2015-01-13 19:25   ` Mike Turquette
2014-12-10 15:48 ` [RFC 09/15] phy: " Andrzej Hajda
2014-12-10 15:48 ` [RFC 10/15] drm/exynos/dsi: simplify hotplug code Andrzej Hajda
2014-12-10 15:48 ` [RFC 11/15] drm/exynos/dsi: convert to restrack API Andrzej Hajda
2014-12-10 15:48 ` [RFC 12/15] drm/exynos/dpi: use common of_graph functions Andrzej Hajda
2014-12-10 15:48 ` [RFC 13/15] drm/exynos/dpi: convert to restrack API Andrzej Hajda
2014-12-10 15:48 ` [RFC 14/15] drm/panel/ld9040: do not power off panel on removal Andrzej Hajda
2014-12-10 15:48 ` [RFC 15/15] drm/panel/ld9040: convert to restrack API Andrzej Hajda
2014-12-10 16:16 ` [RFC 00/15] Resource tracking/allocation framework Russell King - ARM Linux
     [not found]   ` <CA+tnuKYSDZ0mtzQ_g1QjovJwG01OgPjSXuozEBXQsEZv_2o-=w@mail.gmail.com>
2014-12-10 17:39     ` Russell King - ARM Linux

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=1418226513-14105-5-git-send-email-a.hajda@samsung.com \
    --to=a.hajda@samsung.com \
    --cc=boris.brezillon@free-electrons.com \
    --cc=broonie@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gnurou@gmail.com \
    --cc=grant.likely@linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=inki.dae@samsung.com \
    --cc=kishon@ti.com \
    --cc=lgirdwood@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=m.szyprowski@samsung.com \
    --cc=mturquette@linaro.org \
    --cc=robh+dt@kernel.org \
    --cc=thierry.reding@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

all inboxes | Powered by JetHome®