From: viresh.kumar@linaro.org (Viresh Kumar)
To: linux-arm-kernel@lists.infradead.org
Subject: [RFC v2 2/6] drivers: boot_constraint: Add support for supply constraints
Date: Wed, 12 Jul 2017 12:04:32 +0530 [thread overview]
Message-ID: <9a0ae6f5bf543373f6a3e51fd6e83706c3cb9683.1499770771.git.viresh.kumar@linaro.org> (raw)
In-Reply-To: <cover.1499770771.git.viresh.kumar@linaro.org>
This patch adds the first constraint type: power-supply.
The constraint is set by setting a voltage range for the respective
regulator device, which will be honored by the regulator core even if
more users turn up. Once the device is probed, the regulator is
released and the constraint is removed.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
drivers/base/boot_constraint.c | 88 +++++++++++++++++++++++++++++++++++++++++
include/linux/boot_constraint.h | 8 +++-
2 files changed, 95 insertions(+), 1 deletion(-)
diff --git a/drivers/base/boot_constraint.c b/drivers/base/boot_constraint.c
index 7dc7b6132765..4e4332751c5f 100644
--- a/drivers/base/boot_constraint.c
+++ b/drivers/base/boot_constraint.c
@@ -15,6 +15,7 @@
#include <linux/export.h>
#include <linux/list.h>
#include <linux/mutex.h>
+#include <linux/regulator/consumer.h>
#include <linux/slab.h>
struct constraint {
@@ -43,6 +44,8 @@ static LIST_HEAD(constraint_devices);
static DEFINE_MUTEX(constraint_devices_mutex);
/* Forward declarations of constraints */
+static int constraint_supply_add(struct constraint *constraint, void *data);
+static void constraint_supply_remove(struct constraint *constraint);
/* Boot constraints core */
@@ -115,6 +118,10 @@ static struct constraint *constraint_allocate(struct constraint_dev *cdev,
void (*remove)(struct constraint *constraint);
switch (type) {
+ case BOOT_CONSTRAINT_SUPPLY:
+ add = constraint_supply_add;
+ remove = constraint_supply_remove;
+ break;
default:
return ERR_PTR(-EINVAL);
}
@@ -217,3 +224,84 @@ void boot_constraints_remove(struct device *dev)
unlock:
mutex_unlock(&constraint_devices_mutex);
}
+
+
+/* Boot constraints */
+
+/* Boot constraint - Supply */
+
+struct constraint_supply {
+ struct boot_constraint_supply_info supply;
+ struct regulator *reg;
+};
+
+static int constraint_supply_add(struct constraint *constraint, void *data)
+{
+ struct boot_constraint_supply_info *supply = data;
+ struct constraint_supply *csupply;
+ struct device *dev = constraint->cdev->dev;
+ int ret;
+
+ csupply = kzalloc(sizeof(*csupply), GFP_KERNEL);
+ if (!csupply)
+ return -ENOMEM;
+
+ csupply->reg = regulator_get(dev, supply->name);
+ if (IS_ERR(csupply->reg)) {
+ ret = PTR_ERR(csupply->reg);
+ if (ret != -EPROBE_DEFER) {
+ dev_err(dev, "regulator_get() failed for %s (%d)\n",
+ supply->name, ret);
+ }
+ goto free;
+ }
+
+ ret = regulator_set_voltage(csupply->reg, supply->u_volt_min,
+ supply->u_volt_max);
+ if (ret) {
+ dev_err(dev, "regulator_set_voltage %s failed (%d)\n",
+ supply->name, ret);
+ goto free_regulator;
+ }
+
+ ret = regulator_enable(csupply->reg);
+ if (ret) {
+ dev_err(dev, "regulator_enable %s failed (%d)\n",
+ supply->name, ret);
+ goto remove_voltage;
+ }
+
+ memcpy(&csupply->supply, supply, sizeof(*supply));
+ csupply->supply.name = kstrdup_const(supply->name, GFP_KERNEL);
+ constraint->private = csupply;
+
+ return 0;
+
+remove_voltage:
+ regulator_set_voltage(csupply->reg, 0, INT_MAX);
+free_regulator:
+ regulator_put(csupply->reg);
+free:
+ kfree(csupply);
+
+ return ret;
+}
+
+static void constraint_supply_remove(struct constraint *constraint)
+{
+ struct constraint_supply *csupply = constraint->private;
+ struct device *dev = constraint->cdev->dev;
+ int ret;
+
+ ret = regulator_disable(csupply->reg);
+ if (ret)
+ dev_err(dev, "regulator_disable failed (%d)\n", ret);
+
+ ret = regulator_set_voltage(csupply->reg, 0, INT_MAX);
+ if (ret)
+ dev_err(dev, "regulator_set_voltage failed (%d)\n", ret);
+
+ regulator_put(csupply->reg);
+ kfree_const(csupply->supply.name);
+ kfree(csupply);
+}
diff --git a/include/linux/boot_constraint.h b/include/linux/boot_constraint.h
index 99f268447f72..110e5eca36c6 100644
--- a/include/linux/boot_constraint.h
+++ b/include/linux/boot_constraint.h
@@ -13,7 +13,13 @@
struct device;
enum boot_constraint_type {
- BOOT_CONSTRAINT_NONE,
+ BOOT_CONSTRAINT_SUPPLY,
+};
+
+struct boot_constraint_supply_info {
+ const char *name;
+ unsigned int u_volt_min;
+ unsigned int u_volt_max;
};
struct boot_constraint_info {
--
2.13.0.71.gd7076ec9c9cb
next prev parent reply other threads:[~2017-07-12 6:34 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-12 6:34 [RFC v2 0/6] drivers: Boot Constraints core Viresh Kumar
2017-07-12 6:34 ` [RFC v2 1/6] drivers: Add boot constraints core Viresh Kumar
2017-07-12 6:34 ` Viresh Kumar [this message]
2017-07-12 6:34 ` [RFC v2 3/6] drivers: boot_constraint: Add boot_constraints_disable kernel parameter Viresh Kumar
2017-07-12 6:34 ` [RFC v2 4/6] drivers: boot_constraint: Add debugfs support Viresh Kumar
2017-07-12 7:18 ` Viresh Kumar
2017-07-12 6:34 ` [RFC v2 5/6] drivers: boot_constraint: Add initial DT bindings Viresh Kumar
2017-07-12 21:28 ` Rob Herring
2017-07-13 2:52 ` Chen-Yu Tsai
2017-07-13 5:09 ` Viresh Kumar
2017-07-13 9:46 ` Chen-Yu Tsai
2017-07-13 9:51 ` Viresh Kumar
2017-07-13 9:36 ` Viresh Kumar
2017-07-17 17:34 ` Rob Herring
2017-07-18 5:58 ` Viresh Kumar
2017-07-12 6:34 ` [RFC v2 6/6] drivers: boot_constraint: Add constraints for OF devices Viresh Kumar
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=9a0ae6f5bf543373f6a3e51fd6e83706c3cb9683.1499770771.git.viresh.kumar@linaro.org \
--to=viresh.kumar@linaro.org \
--cc=linux-arm-kernel@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;
as well as URLs for NNTP newsgroup(s).