linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Krzysztof Kozlowski <k.kozlowski@samsung.com>
To: Samuel Ortiz <sameo@linux.intel.com>,
	Lee Jones <lee.jones@linaro.org>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@kernel.org>,
	linux-kernel@vger.kernel.org, Ben Dooks <ben-linux@fluff.org>,
	Kukjin Kim <kgene.kim@samsung.com>,
	Russell King <linux@arm.linux.org.uk>,
	linux-arm-kernel@lists.infradead.org,
	linux-samsung-soc@vger.kernel.org, devicetree@vger.kernel.org
Cc: Kyungmin Park <kyungmin.park@samsung.com>,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>,
	Javier Martinez Canillas <javier.martinez@collabora.co.uk>,
	Chanwoo Choi <cw00.choi@samsung.com>,
	Krzysztof Kozlowski <k.kozlowski@samsung.com>
Subject: [PATCH v3 10/14] regulator: max77686: Add GPIO control
Date: Thu, 30 Oct 2014 12:20:49 +0100	[thread overview]
Message-ID: <1414668053-31370-11-git-send-email-k.kozlowski@samsung.com> (raw)
In-Reply-To: <1414668053-31370-1-git-send-email-k.kozlowski@samsung.com>

Add enable control over GPIO for regulators supporting this: LDO20,
LDO21, LDO22, buck8 and buck9.

This is needed for proper (and full) configuration of the Maxim 77686
PMIC without creating redundant 'regulator-fixed' entries.

Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
---
 drivers/regulator/max77686.c | 83 +++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 78 insertions(+), 5 deletions(-)

diff --git a/drivers/regulator/max77686.c b/drivers/regulator/max77686.c
index 2c276d147c90..9108cde069fe 100644
--- a/drivers/regulator/max77686.c
+++ b/drivers/regulator/max77686.c
@@ -26,6 +26,7 @@
 #include <linux/bug.h>
 #include <linux/err.h>
 #include <linux/gpio.h>
+#include <linux/of_gpio.h>
 #include <linux/slab.h>
 #include <linux/platform_device.h>
 #include <linux/regulator/driver.h>
@@ -46,6 +47,11 @@
 #define MAX77686_DVS_UVSTEP	12500
 
 /*
+ * Value for configuring buck[89] and LDO{20,21,22} as GPIO control.
+ * It is the same as 'off' for other regulators.
+ */
+#define MAX77686_GPIO_CONTROL		0x0
+/*
  * Values used for configuring LDOs and bucks.
  * Forcing low power mode: LDO1, 3-5, 9, 13, 17-26
  */
@@ -82,6 +88,9 @@ enum max77686_ramp_rate {
 };
 
 struct max77686_data {
+	/* GPIO control over regulators */
+	int gpio[MAX77686_REGULATORS];
+
 	/* Array indexed by regulator id */
 	unsigned int opmode[MAX77686_REGULATORS];
 	bool missing_of_node;
@@ -101,6 +110,25 @@ static unsigned int max77686_get_opmode_shift(int id)
 	}
 }
 
+/*
+ * When regulator is configured for GPIO control then it
+ * replaces "normal" mode. Any change from low power mode to normal
+ * should actually change to GPIO control.
+ * Map normal mode to proper value for such regulators.
+ */
+static int max77686_map_normal_mode(struct max77686_data *max77686, int id)
+{
+	switch (id) {
+	case MAX77686_BUCK8:
+	case MAX77686_BUCK9:
+	case MAX77686_LDO20 ... MAX77686_LDO22:
+		if (gpio_is_valid(max77686->gpio[id]))
+			return MAX77686_GPIO_CONTROL;
+	}
+
+	return MAX77686_NORMAL;
+}
+
 /* Some BUCKs and LDOs supports Normal[ON/OFF] mode during suspend */
 static int max77686_set_suspend_disable(struct regulator_dev *rdev)
 {
@@ -137,7 +165,7 @@ static int max77686_set_suspend_mode(struct regulator_dev *rdev,
 		val = MAX77686_LDO_LOWPOWER_PWRREQ;
 		break;
 	case REGULATOR_MODE_NORMAL:			/* ON in Normal Mode */
-		val = MAX77686_NORMAL;
+		val = max77686_map_normal_mode(max77686, id);
 		break;
 	default:
 		pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n",
@@ -161,7 +189,7 @@ static int max77686_ldo_set_suspend_mode(struct regulator_dev *rdev,
 {
 	unsigned int val;
 	struct max77686_data *max77686 = rdev_get_drvdata(rdev);
-	int ret;
+	int ret, id = rdev_get_id(rdev);
 
 	switch (mode) {
 	case REGULATOR_MODE_STANDBY:			/* switch off */
@@ -171,7 +199,7 @@ static int max77686_ldo_set_suspend_mode(struct regulator_dev *rdev,
 		val = MAX77686_LDO_LOWPOWER_PWRREQ;
 		break;
 	case REGULATOR_MODE_NORMAL:			/* ON in Normal Mode */
-		val = MAX77686_NORMAL;
+		val = max77686_map_normal_mode(max77686, id);
 		break;
 	default:
 		pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n",
@@ -185,7 +213,7 @@ static int max77686_ldo_set_suspend_mode(struct regulator_dev *rdev,
 	if (ret)
 		return ret;
 
-	max77686->opmode[rdev_get_id(rdev)] = val;
+	max77686->opmode[id] = val;
 	return 0;
 }
 
@@ -198,7 +226,7 @@ static int max77686_enable(struct regulator_dev *rdev)
 	shift = max77686_get_opmode_shift(id);
 
 	if (max77686->opmode[id] == MAX77686_OFF_PWRREQ)
-		max77686->opmode[id] = MAX77686_NORMAL;
+		max77686->opmode[id] = max77686_map_normal_mode(max77686, id);
 
 	return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
 				  rdev->desc->enable_mask,
@@ -436,6 +464,33 @@ static const struct regulator_desc regulators[] = {
 	regulator_desc_buck(9),
 };
 
+static int max77686_enable_gpio_control(struct regulator_dev *rdev)
+{
+	return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
+					rdev->desc->enable_mask,
+					MAX77686_GPIO_CONTROL);
+}
+
+static void max77686_pmic_dt_parse_gpio_control(struct platform_device *pdev,
+					int *gpio)
+{
+	struct device_node *np = pdev->dev.of_node;
+	int i;
+
+	/*
+	 * 0 is a valid GPIO so initialize all GPIOs to negative value
+	 * to indicate that GPIO control won't be used for this regulator.
+	 */
+	for (i = 0; i < MAX77686_REGULATORS; i++)
+		gpio[i] = -EINVAL;
+
+	gpio[MAX77686_LDO20] = of_get_named_gpio(np, "ldo20-gpio", 0);
+	gpio[MAX77686_LDO21] = of_get_named_gpio(np, "ldo21-gpio", 0);
+	gpio[MAX77686_LDO22] = of_get_named_gpio(np, "ldo22-gpio", 0);
+	gpio[MAX77686_BUCK8] = of_get_named_gpio(np, "buck8-gpio", 0);
+	gpio[MAX77686_BUCK9] = of_get_named_gpio(np, "buck9-gpio", 0);
+}
+
 static int max77686_pmic_probe(struct platform_device *pdev)
 {
 	struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent);
@@ -467,12 +522,17 @@ static int max77686_pmic_probe(struct platform_device *pdev)
 	config.dev = &pdev->dev;
 	config.regmap = iodev->regmap;
 	config.driver_data = max77686;
+	config.ena_gpio_flags = GPIOF_OUT_INIT_HIGH;
+	config.ena_gpio_initialized = true;
 	platform_set_drvdata(pdev, max77686);
 
+	max77686_pmic_dt_parse_gpio_control(pdev, max77686->gpio);
+
 	for (i = 0; i < MAX77686_REGULATORS; i++) {
 		struct regulator_dev *rdev;
 		int id = regulators[i].id;
 
+		config.ena_gpio = max77686->gpio[id];
 		max77686->opmode[id] = MAX77686_NORMAL;
 
 		rdev = devm_regulator_register(&pdev->dev,
@@ -485,6 +545,19 @@ static int max77686_pmic_probe(struct platform_device *pdev)
 				of_node_put(pdev->dev.of_node);
 			return ret;
 		}
+
+		if (gpio_is_valid(config.ena_gpio)) {
+			int ret = max77686_enable_gpio_control(rdev);
+
+			if (ret < 0) {
+				dev_err(&pdev->dev,
+					"regulator enable ext control failed for %d\n",
+					i);
+				if (max77686->missing_of_node)
+					of_node_put(pdev->dev.of_node);
+				return ret;
+			}
+		}
 	}
 
 	return 0;
-- 
1.9.1


  parent reply	other threads:[~2014-10-30 11:22 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-30 11:20 [PATCH v3 00/14] regulator: max77686: Add GPIO control Krzysztof Kozlowski
2014-10-30 11:20 ` [PATCH v3 01/14] mfd: max77686/802: Map regulator driver to its own of_node Krzysztof Kozlowski
2014-10-31 12:23   ` Mark Brown
2014-10-31 13:07     ` Krzysztof Kozlowski
2014-10-31 18:06       ` Mark Brown
2014-10-30 11:20 ` [PATCH v3 02/14] mfd/regulator: dt-bindings: max77686: Document of_compatible for regulator Krzysztof Kozlowski
2014-11-03 17:00   ` Lee Jones
2014-11-04  7:53     ` Krzysztof Kozlowski
2014-10-30 11:20 ` [PATCH v3 03/14] regulator: dt-bindings: max77802: " Krzysztof Kozlowski
2014-10-30 11:20 ` [PATCH v3 04/14] regulator: max77686: Consistently index opmode array by rdev id Krzysztof Kozlowski
2014-10-30 11:20 ` [RFT v3 05/14] regulator: max77802: Don't ignore return value of current opmode Krzysztof Kozlowski
2014-10-30 11:42   ` Javier Martinez Canillas
2014-10-30 11:20 ` [RFT v3 06/14] regulator: max77802: Remove support for board files Krzysztof Kozlowski
2014-10-30 11:50   ` Javier Martinez Canillas
2014-10-30 12:10     ` Krzysztof Kozlowski
2014-10-30 12:21       ` Javier Martinez Canillas
2014-10-30 12:30         ` Krzysztof Kozlowski
2014-10-30 12:42           ` Javier Martinez Canillas
2014-10-30 12:53             ` Krzysztof Kozlowski
2014-10-30 14:02               ` Javier Martinez Canillas
2014-10-30 11:20 ` [PATCH v3 07/14] regulator: max77686: " Krzysztof Kozlowski
2014-10-30 11:20 ` [PATCH v3 08/14] mfd: max77686/802: " Krzysztof Kozlowski
2014-11-03 17:01   ` Lee Jones
2014-11-04  7:51     ` Krzysztof Kozlowski
2014-11-04  8:07       ` Lee Jones
2014-10-30 11:20 ` [PATCH v3 09/14] regulator: max77686: Initialize opmode explicitly to normal mode Krzysztof Kozlowski
2014-10-30 11:20 ` Krzysztof Kozlowski [this message]
2014-10-30 11:20 ` [PATCH v3 11/14] mfd/regulator: dt-bindings: max77686: Document gpio properties Krzysztof Kozlowski
2014-10-30 11:20 ` [PATCH v3 12/14] ARM: dts: exynos4412-trats: Switch max77686 regulators to GPIO control Krzysztof Kozlowski
2014-10-30 11:20 ` [PATCH v3 13/14] ARM: dts: exynos5420-peach: Update to new max77802 regulator compatible Krzysztof Kozlowski
2014-10-30 11:20 ` [PATCH v3 14/14] ARM: dts: exynos5800-peach: " Krzysztof Kozlowski

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=1414668053-31370-11-git-send-email-k.kozlowski@samsung.com \
    --to=k.kozlowski@samsung.com \
    --cc=b.zolnierkie@samsung.com \
    --cc=ben-linux@fluff.org \
    --cc=broonie@kernel.org \
    --cc=cw00.choi@samsung.com \
    --cc=devicetree@vger.kernel.org \
    --cc=javier.martinez@collabora.co.uk \
    --cc=kgene.kim@samsung.com \
    --cc=kyungmin.park@samsung.com \
    --cc=lee.jones@linaro.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.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=sameo@linux.intel.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).