linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/2] regulator: s5m8767: Use GPIO for controlling Buck9/eMMC
@ 2014-01-24 13:37 Krzysztof Kozlowski
  2014-01-24 13:37 ` [PATCH v3 1/2] " Krzysztof Kozlowski
  2014-01-24 13:37 ` [PATCH v3 2/2] regulator: s5m8767: Document new binding for Buck9 GPIO control Krzysztof Kozlowski
  0 siblings, 2 replies; 8+ messages in thread
From: Krzysztof Kozlowski @ 2014-01-24 13:37 UTC (permalink / raw)
  To: Sangbeom Kim, Liam Girdwood, Mark Brown, Samuel Ortiz, Lee Jones,
	linux-kernel, devicetree, linux-samsung-soc, Sachin Kamat
  Cc: Krzysztof Kozlowski

Hi,


This is third version of patch adding GPIO control over Buck9 regulator
in s5m8767 regulator driver.

Previously the patch was part of larger patchset from which all other patches
were applied.


Changes since v2:
1. Use only one DT property ("s5m8767,pmic-ext-control-gpios");
   suggested by Mark Brown.

Changes since v1:
1. Use ena_gpio of regulator core, as suggested by Mark Brown.


This patchset is based on next tree: next-20140122.

Best regards,
Krzysztof

Krzysztof Kozlowski (2):
  regulator: s5m8767: Use GPIO for controlling Buck9/eMMC
  regulator: s5m8767: Document new binding for Buck9 GPIO control

 .../bindings/regulator/s5m8767-regulator.txt       |   13 ++-
 drivers/regulator/s5m8767.c                        |   87 +++++++++++++++++++-
 include/linux/mfd/samsung/core.h                   |    3 +-
 include/linux/mfd/samsung/s5m8767.h                |    7 ++
 4 files changed, 105 insertions(+), 5 deletions(-)

-- 
1.7.9.5


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v3 1/2] regulator: s5m8767: Use GPIO for controlling Buck9/eMMC
  2014-01-24 13:37 [PATCH v3 0/2] regulator: s5m8767: Use GPIO for controlling Buck9/eMMC Krzysztof Kozlowski
@ 2014-01-24 13:37 ` Krzysztof Kozlowski
  2014-01-24 16:03   ` Lee Jones
  2014-01-27 20:25   ` Mark Brown
  2014-01-24 13:37 ` [PATCH v3 2/2] regulator: s5m8767: Document new binding for Buck9 GPIO control Krzysztof Kozlowski
  1 sibling, 2 replies; 8+ messages in thread
From: Krzysztof Kozlowski @ 2014-01-24 13:37 UTC (permalink / raw)
  To: Sangbeom Kim, Liam Girdwood, Mark Brown, Samuel Ortiz, Lee Jones,
	linux-kernel, devicetree, linux-samsung-soc, Sachin Kamat
  Cc: Krzysztof Kozlowski, Kyungmin Park, Marek Szyprowski,
	Bartlomiej Zolnierkiewicz

Add support for GPIO control (enable/disable) over Buck9. The Buck9
Converter is used as a supply for eMMC Host Controller.

BUCK9EN GPIO of S5M8767 chip may be used by application processor to
enable or disable the Buck9. This has two benefits:
 - It is faster than toggling it over I2C bus.
 - It allows disabling the regulator during suspend to RAM; The AP will
   enable it during resume; Without the patch the regulator supplying
   eMMC must be defined as fixed-regulator.

Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Cc: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Marek Szyprowski <m.szyprowski@samsung.com>
Cc: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
---
 drivers/regulator/s5m8767.c         |   87 +++++++++++++++++++++++++++++++++--
 include/linux/mfd/samsung/core.h    |    3 +-
 include/linux/mfd/samsung/s5m8767.h |    7 +++
 3 files changed, 93 insertions(+), 4 deletions(-)

diff --git a/drivers/regulator/s5m8767.c b/drivers/regulator/s5m8767.c
index d7164bb75d3e..6850a25a41c4 100644
--- a/drivers/regulator/s5m8767.c
+++ b/drivers/regulator/s5m8767.c
@@ -11,11 +11,8 @@
  *
  */
 
-#include <linux/bug.h>
 #include <linux/err.h>
-#include <linux/gpio.h>
 #include <linux/of_gpio.h>
-#include <linux/slab.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/regulator/driver.h>
@@ -483,6 +480,65 @@ static struct regulator_desc regulators[] = {
 	s5m8767_regulator_desc(BUCK9),
 };
 
+/*
+ * Enable GPIO control over BUCK9 in regulator_config for that regulator.
+ */
+static void s5m8767_regulator_config_ext_control(struct s5m8767_info *s5m8767,
+		struct sec_regulator_data *rdata,
+		struct regulator_config *config)
+{
+	int i, mode = 0;
+
+	if (rdata->id != S5M8767_BUCK9)
+		return;
+
+	/* Check if opmode for regulator matches S5M8767_ENCTRL_USE_GPIO */
+	for (i = 0; i < s5m8767->num_regulators; i++) {
+		const struct sec_opmode_data *opmode = &s5m8767->opmode[i];
+		if (opmode->id == rdata->id) {
+			mode = s5m8767_opmode_reg[rdata->id][opmode->mode];
+			break;
+		}
+	}
+	if (mode != S5M8767_ENCTRL_USE_GPIO) {
+		dev_warn(s5m8767->dev,
+				"ext-control for %s: mismatched op_mode (%x), ignoring\n",
+				rdata->reg_node->name, mode);
+		return;
+	}
+
+	if (!gpio_is_valid(rdata->ext_control_gpio)) {
+		dev_warn(s5m8767->dev,
+				"ext-control for %s: GPIO not valid, ignoring\n",
+				rdata->reg_node->name);
+		return;
+	}
+
+	config->ena_gpio = rdata->ext_control_gpio;
+	config->ena_gpio_flags = GPIOF_OUT_INIT_HIGH;
+}
+
+/*
+ * Turn on GPIO control over BUCK9.
+ */
+static int s5m8767_enable_ext_control(struct s5m8767_info *s5m8767,
+		struct regulator_dev *rdev)
+{
+	int ret, reg, enable_ctrl;
+
+	if (rdev_get_id(rdev) != S5M8767_BUCK9)
+		return -EINVAL;
+
+	ret = s5m8767_get_register(rdev, &reg, &enable_ctrl);
+	if (ret)
+		return ret;
+
+	return regmap_update_bits(s5m8767->iodev->regmap_pmic,
+			reg, S5M8767_ENCTRL_MASK,
+			S5M8767_ENCTRL_USE_GPIO << S5M8767_ENCTRL_SHIFT);
+}
+
+
 #ifdef CONFIG_OF
 static int s5m8767_pmic_dt_parse_dvs_gpio(struct sec_pmic_dev *iodev,
 			struct sec_platform_data *pdata,
@@ -520,6 +576,16 @@ static int s5m8767_pmic_dt_parse_ds_gpio(struct sec_pmic_dev *iodev,
 	return 0;
 }
 
+static void s5m8767_pmic_dt_parse_ext_control_gpio(struct sec_pmic_dev *iodev,
+		struct sec_regulator_data *rdata,
+		struct device_node *reg_np)
+{
+	rdata->ext_control_gpio = of_get_named_gpio(reg_np,
+			"s5m8767,pmic-ext-control-gpios", 0);
+	if (!gpio_is_valid(rdata->ext_control_gpio))
+		rdata->ext_control_gpio = 0;
+}
+
 static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev,
 					struct sec_platform_data *pdata)
 {
@@ -574,6 +640,8 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev,
 			continue;
 		}
 
+		s5m8767_pmic_dt_parse_ext_control_gpio(iodev, rdata, reg_np);
+
 		rdata->id = i;
 		rdata->initdata = of_get_regulator_init_data(
 						&pdev->dev, reg_np);
@@ -940,6 +1008,9 @@ static int s5m8767_pmic_probe(struct platform_device *pdev)
 		config.driver_data = s5m8767;
 		config.regmap = iodev->regmap_pmic;
 		config.of_node = pdata->regulators[i].reg_node;
+		if (pdata->regulators[i].ext_control_gpio)
+			s5m8767_regulator_config_ext_control(s5m8767,
+					&pdata->regulators[i], &config);
 
 		rdev[i] = devm_regulator_register(&pdev->dev, &regulators[id],
 						  &config);
@@ -949,6 +1020,16 @@ static int s5m8767_pmic_probe(struct platform_device *pdev)
 					id);
 			return ret;
 		}
+
+		if (pdata->regulators[i].ext_control_gpio) {
+			ret = s5m8767_enable_ext_control(s5m8767, rdev[i]);
+			if (ret < 0) {
+				dev_err(s5m8767->dev,
+						"failed to enable gpio control over %s: %d\n",
+						rdev[i]->desc->name, ret);
+				return ret;
+			}
+		}
 	}
 
 	return 0;
diff --git a/include/linux/mfd/samsung/core.h b/include/linux/mfd/samsung/core.h
index 41c9bde410c5..55510444b9fd 100644
--- a/include/linux/mfd/samsung/core.h
+++ b/include/linux/mfd/samsung/core.h
@@ -119,7 +119,8 @@ struct sec_platform_data {
 struct sec_regulator_data {
 	int				id;
 	struct regulator_init_data	*initdata;
-	struct device_node *reg_node;
+	struct device_node		*reg_node;
+	int				ext_control_gpio;
 };
 
 /*
diff --git a/include/linux/mfd/samsung/s5m8767.h b/include/linux/mfd/samsung/s5m8767.h
index 2ab0b0f03641..243b58fec33d 100644
--- a/include/linux/mfd/samsung/s5m8767.h
+++ b/include/linux/mfd/samsung/s5m8767.h
@@ -183,10 +183,17 @@ enum s5m8767_regulators {
 	S5M8767_REG_MAX,
 };
 
+/* LDO_EN/BUCK_EN field in registers */
 #define S5M8767_ENCTRL_SHIFT		6
 #define S5M8767_ENCTRL_MASK		(0x3 << S5M8767_ENCTRL_SHIFT)
 
 /*
+ * LDO_EN/BUCK_EN register value for controlling this Buck or LDO
+ * by GPIO (PWREN, BUCKEN).
+ */
+#define S5M8767_ENCTRL_USE_GPIO		0x1
+
+/*
  * Values for BUCK_RAMP field in DVS_RAMP register, matching raw values
  * in mV/us.
  */
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v3 2/2] regulator: s5m8767: Document new binding for Buck9 GPIO control
  2014-01-24 13:37 [PATCH v3 0/2] regulator: s5m8767: Use GPIO for controlling Buck9/eMMC Krzysztof Kozlowski
  2014-01-24 13:37 ` [PATCH v3 1/2] " Krzysztof Kozlowski
@ 2014-01-24 13:37 ` Krzysztof Kozlowski
  2014-01-27 20:25   ` Mark Brown
  1 sibling, 1 reply; 8+ messages in thread
From: Krzysztof Kozlowski @ 2014-01-24 13:37 UTC (permalink / raw)
  To: Sangbeom Kim, Liam Girdwood, Mark Brown, Samuel Ortiz, Lee Jones,
	linux-kernel, devicetree, linux-samsung-soc, Sachin Kamat
  Cc: Krzysztof Kozlowski, Kyungmin Park, Marek Szyprowski,
	Bartlomiej Zolnierkiewicz

Add documentation for new binding for controlling (enable/disable) the
Buck9 Converter by GPIO (BUCK9EN).

Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Cc: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Marek Szyprowski <m.szyprowski@samsung.com>
Cc: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
---
 .../bindings/regulator/s5m8767-regulator.txt       |   13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/regulator/s5m8767-regulator.txt b/Documentation/devicetree/bindings/regulator/s5m8767-regulator.txt
index fc6b38f035bd..d290988ed975 100644
--- a/Documentation/devicetree/bindings/regulator/s5m8767-regulator.txt
+++ b/Documentation/devicetree/bindings/regulator/s5m8767-regulator.txt
@@ -69,13 +69,16 @@ sub-node should be of the format as listed below.
 		};
 	};
 The above regulator entries are defined in regulator bindings documentation
-except op_mode description.
+except these properties:
 	- op_mode: describes the different operating modes of the LDO's with
 		power mode change in SOC. The different possible values are,
 		0 - always off mode
 		1 - on in normal mode
 		2 - low power mode
 		3 - suspend mode
+	- s5m8767,pmic-ext-control-gpios: (optional) GPIO specifier for one
+		GPIO controlling this regulator (enable/disable); This is
+		valid only for buck9.
 
 The following are the names of the regulators that the s5m8767 pmic block
 supports. Note: The 'n' in LDOn and BUCKn represents the LDO or BUCK number
@@ -148,5 +151,13 @@ Example:
 				regulator-always-on;
 				regulator-boot-on;
 			};
+
+			vemmc_reg: BUCK9 {
+				regulator-name = "VMEM_VDD_2.8V";
+				regulator-min-microvolt = <2800000>;
+				regulator-max-microvolt = <2800000>;
+				op_mode = <3>; /* Standby Mode */
+				s5m8767,pmic-ext-control-gpios = <&gpk0 2 0>;
+			};
 		};
 	};
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v3 1/2] regulator: s5m8767: Use GPIO for controlling Buck9/eMMC
  2014-01-24 13:37 ` [PATCH v3 1/2] " Krzysztof Kozlowski
@ 2014-01-24 16:03   ` Lee Jones
  2014-01-27 20:25   ` Mark Brown
  1 sibling, 0 replies; 8+ messages in thread
From: Lee Jones @ 2014-01-24 16:03 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Sangbeom Kim, Liam Girdwood, Mark Brown, Samuel Ortiz,
	linux-kernel, devicetree, linux-samsung-soc, Sachin Kamat,
	Kyungmin Park, Marek Szyprowski, Bartlomiej Zolnierkiewicz

On Fri, 24 Jan 2014, Krzysztof Kozlowski wrote:

> Add support for GPIO control (enable/disable) over Buck9. The Buck9
> Converter is used as a supply for eMMC Host Controller.
> 
> BUCK9EN GPIO of S5M8767 chip may be used by application processor to
> enable or disable the Buck9. This has two benefits:
>  - It is faster than toggling it over I2C bus.
>  - It allows disabling the regulator during suspend to RAM; The AP will
>    enable it during resume; Without the patch the regulator supplying
>    eMMC must be defined as fixed-regulator.
> 
> Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
> Cc: Kyungmin Park <kyungmin.park@samsung.com>
> Cc: Marek Szyprowski <m.szyprowski@samsung.com>
> Cc: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
> ---
>  drivers/regulator/s5m8767.c         |   87 +++++++++++++++++++++++++++++++++--
>  include/linux/mfd/samsung/core.h    |    3 +-
>  include/linux/mfd/samsung/s5m8767.h |    7 +++
>  3 files changed, 93 insertions(+), 4 deletions(-)

For the MFD changes:
  Acked-by: Lee Jones <lee.jones@linaro.org>

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3 1/2] regulator: s5m8767: Use GPIO for controlling Buck9/eMMC
  2014-01-24 13:37 ` [PATCH v3 1/2] " Krzysztof Kozlowski
  2014-01-24 16:03   ` Lee Jones
@ 2014-01-27 20:25   ` Mark Brown
  2014-02-07 12:40     ` Krzysztof Kozlowski
  1 sibling, 1 reply; 8+ messages in thread
From: Mark Brown @ 2014-01-27 20:25 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Sangbeom Kim, Liam Girdwood, Samuel Ortiz, Lee Jones,
	linux-kernel, devicetree, linux-samsung-soc, Sachin Kamat,
	Kyungmin Park, Marek Szyprowski, Bartlomiej Zolnierkiewicz

[-- Attachment #1: Type: text/plain, Size: 215 bytes --]

On Fri, Jan 24, 2014 at 02:37:57PM +0100, Krzysztof Kozlowski wrote:
> Add support for GPIO control (enable/disable) over Buck9. The Buck9
> Converter is used as a supply for eMMC Host Controller.

Applied, thanks.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3 2/2] regulator: s5m8767: Document new binding for Buck9 GPIO control
  2014-01-24 13:37 ` [PATCH v3 2/2] regulator: s5m8767: Document new binding for Buck9 GPIO control Krzysztof Kozlowski
@ 2014-01-27 20:25   ` Mark Brown
  0 siblings, 0 replies; 8+ messages in thread
From: Mark Brown @ 2014-01-27 20:25 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Sangbeom Kim, Liam Girdwood, Samuel Ortiz, Lee Jones,
	linux-kernel, devicetree, linux-samsung-soc, Sachin Kamat,
	Kyungmin Park, Marek Szyprowski, Bartlomiej Zolnierkiewicz

[-- Attachment #1: Type: text/plain, Size: 197 bytes --]

On Fri, Jan 24, 2014 at 02:37:58PM +0100, Krzysztof Kozlowski wrote:
> Add documentation for new binding for controlling (enable/disable) the
> Buck9 Converter by GPIO (BUCK9EN).

Applied, thanks.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3 1/2] regulator: s5m8767: Use GPIO for controlling Buck9/eMMC
  2014-01-27 20:25   ` Mark Brown
@ 2014-02-07 12:40     ` Krzysztof Kozlowski
  2014-02-07 12:52       ` Mark Brown
  0 siblings, 1 reply; 8+ messages in thread
From: Krzysztof Kozlowski @ 2014-02-07 12:40 UTC (permalink / raw)
  To: Mark Brown
  Cc: Sangbeom Kim, Liam Girdwood, Samuel Ortiz, Lee Jones,
	linux-kernel, devicetree, linux-samsung-soc, Sachin Kamat,
	Kyungmin Park, Marek Szyprowski, Bartlomiej Zolnierkiewicz

Hi Mark,

On Mon, 2014-01-27 at 20:25 +0000, Mark Brown wrote:
> On Fri, Jan 24, 2014 at 02:37:57PM +0100, Krzysztof Kozlowski wrote:
> > Add support for GPIO control (enable/disable) over Buck9. The Buck9
> > Converter is used as a supply for eMMC Host Controller.
> 
> Applied, thanks.

I can't find these patches in your tree. Did you applied them or am I
missing something?

Best regards,
Krzysztof


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3 1/2] regulator: s5m8767: Use GPIO for controlling Buck9/eMMC
  2014-02-07 12:40     ` Krzysztof Kozlowski
@ 2014-02-07 12:52       ` Mark Brown
  0 siblings, 0 replies; 8+ messages in thread
From: Mark Brown @ 2014-02-07 12:52 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Sangbeom Kim, Liam Girdwood, Samuel Ortiz, Lee Jones,
	linux-kernel, devicetree, linux-samsung-soc, Sachin Kamat,
	Kyungmin Park, Marek Szyprowski, Bartlomiej Zolnierkiewicz

[-- Attachment #1: Type: text/plain, Size: 183 bytes --]

On Fri, Feb 07, 2014 at 01:40:33PM +0100, Krzysztof Kozlowski wrote:

> I can't find these patches in your tree. Did you applied them or am I
> missing something?

They're there now.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-02-07 12:52 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-24 13:37 [PATCH v3 0/2] regulator: s5m8767: Use GPIO for controlling Buck9/eMMC Krzysztof Kozlowski
2014-01-24 13:37 ` [PATCH v3 1/2] " Krzysztof Kozlowski
2014-01-24 16:03   ` Lee Jones
2014-01-27 20:25   ` Mark Brown
2014-02-07 12:40     ` Krzysztof Kozlowski
2014-02-07 12:52       ` Mark Brown
2014-01-24 13:37 ` [PATCH v3 2/2] regulator: s5m8767: Document new binding for Buck9 GPIO control Krzysztof Kozlowski
2014-01-27 20:25   ` Mark Brown

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).