diff mbox

[v2] Input: Make ADS7846 independent on regulator

Message ID AANLkTimTW6v3N9aRA0h15SWXbBc_W0dhpf5rEeqBqGbf@mail.gmail.com (mailing list archive)
State Rejected
Headers show

Commit Message

Linus Walleij Oct. 5, 2010, 10:09 p.m. UTC
None
diff mbox

Patch

diff --git a/include/linux/regulator/consumer.h
b/include/linux/regulator/consumer.h
index ebd7472..6ee7fdc 100644
--- a/include/linux/regulator/consumer.h
+++ b/include/linux/regulator/consumer.h
@@ -36,6 +36,7 @@ 
 #define __LINUX_REGULATOR_CONSUMER_H_

 #include <linux/device.h>
+#include <linux/err.h>

 /*
  * Regulator operating modes.
@@ -297,4 +298,23 @@  static inline void regulator_set_drvdata(struct
regulator *regulator,

 #endif

+/*
+ * Try to get a regulator, if it fails, no big deal.
+ * This wrapper function is intended to be used for code
+ * where regulator control is optional for the particular
+ * consumer, but still the regulator framework may be in
+ * use for other things in the platform.
+ */
+static inline struct regulator *regulator_try_get(struct device *dev,
+	const char *id)
+{
+	struct regulator *reg = regulator_get(dev, id);
+
+	/* It's just that this regulator is not (yet) defined */
+	if (IS_ERR(reg) && PTR_ERR(reg) == -ENODEV)
+		return NULL;
+
+	return reg;
+}
+
 #endif
-- 
1.7.2.3

From: Linus Walleij <linus.walleij@stericsson.com>
Date: Wed, 6 Oct 2010 00:04:25 +0200
Subject: [PATCH 2/2] regulator: handle NULL regulators in core

If the user has selected to use regulator_try_get() to fetch
regulators, we bail out of consumer operations if the regulator
happens to be NULL.

Signed-off-by: Linus Walleij <linus.walleij@stericsson.com>
---
 drivers/regulator/core.c |   64 +++++++++++++++++++++++++++++++++++++++------
 1 files changed, 55 insertions(+), 9 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index cc8b337..989e4e4 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1337,9 +1337,12 @@  static int _regulator_enable(struct regulator_dev *rdev)
  */
 int regulator_enable(struct regulator *regulator)
 {
-	struct regulator_dev *rdev = regulator->rdev;
+	struct regulator_dev *rdev;
 	int ret = 0;

+	if (regulator == NULL)
+		return 0;
+	rdev = regulator->rdev;
 	mutex_lock(&rdev->mutex);
 	ret = _regulator_enable(rdev);
 	mutex_unlock(&rdev->mutex);
@@ -1406,9 +1409,12 @@  static int _regulator_disable(struct regulator_dev *rdev)
  */
 int regulator_disable(struct regulator *regulator)
 {
-	struct regulator_dev *rdev = regulator->rdev;
+	struct regulator_dev *rdev;
 	int ret = 0;

+	if (regulator == NULL)
+		return 0;
+	rdev = regulator->rdev;
 	mutex_lock(&rdev->mutex);
 	ret = _regulator_disable(rdev);
 	mutex_unlock(&rdev->mutex);
@@ -1456,6 +1462,8 @@  int regulator_force_disable(struct regulator *regulator)
 {
 	int ret;

+	if (regulator == NULL)
+		return 0;
 	mutex_lock(&regulator->rdev->mutex);
 	regulator->uA_load = 0;
 	ret = _regulator_force_disable(regulator->rdev);
@@ -1489,6 +1497,8 @@  int regulator_is_enabled(struct regulator *regulator)
 {
 	int ret;

+	if (regulator == NULL)
+		return 1;
 	mutex_lock(&regulator->rdev->mutex);
 	ret = _regulator_is_enabled(regulator->rdev);
 	mutex_unlock(&regulator->rdev->mutex);
@@ -1507,8 +1517,11 @@  EXPORT_SYMBOL_GPL(regulator_is_enabled);
  */
 int regulator_count_voltages(struct regulator *regulator)
 {
-	struct regulator_dev	*rdev = regulator->rdev;
+	struct regulator_dev	*rdev;

+	if (regulator == NULL)
+		return 0;
+	rdev = regulator->rdev;
 	return rdev->desc->n_voltages ? : -EINVAL;
 }
 EXPORT_SYMBOL_GPL(regulator_count_voltages);
@@ -1525,10 +1538,15 @@  EXPORT_SYMBOL_GPL(regulator_count_voltages);
  */
 int regulator_list_voltage(struct regulator *regulator, unsigned selector)
 {
-	struct regulator_dev	*rdev = regulator->rdev;
-	struct regulator_ops	*ops = rdev->desc->ops;
+	struct regulator_dev	*rdev;
+	struct regulator_ops	*ops;
 	int			ret;

+	if (regulator == NULL)
+		return 0;
+	rdev = regulator->rdev;
+	ops = rdev->desc->ops;
+
 	if (!ops->list_voltage || selector >= rdev->desc->n_voltages)
 		return -EINVAL;

@@ -1561,6 +1579,8 @@  int regulator_is_supported_voltage(struct
regulator *regulator,
 {
 	int i, voltages, ret;

+	if (regulator == NULL)
+		return 0;
 	ret = regulator_count_voltages(regulator);
 	if (ret < 0)