All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH RFC v2 0/2] simplefb: Add regulator handling support
@ 2015-10-21  5:58 ` Chen-Yu Tsai
  0 siblings, 0 replies; 28+ messages in thread
From: Chen-Yu Tsai @ 2015-10-21  5:58 UTC (permalink / raw)
  To: Hans de Goede, Jean-Christophe Plagniol-Villard, Tomi Valkeinen,
	Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala
  Cc: Chen-Yu Tsai, linux-fbdev, devicetree, linux-kernel,
	linux-arm-kernel, Mark Brown

Hi everyone,

This is v2 of the simplefb regulator support series. This series adds
regulator claiming and enabling support for simplefb.

Sometimes the simplefb display output path consits of external conversion
chips and/or LCD drivers and backlights. These devices normally have
GPIOs to turn them on and/or bring them out of reset, and regulators
supplying power to them.

While the kernel does not touch unclaimed GPIOs, the regulator core
happily disables unused regulators. Thus we need simplefb to claim
and enable the regulators used throughout the display pipeline.

Instead of the unnamed "vinN-supply" properties, v2 supports any named
regulator supplies under its device node. It will look through its
properties, and claim any regulators by matching "*-supply", as Mark
suggested.

I've not done a generic helper in the regulator core yet, instead doing
the regulator property handling in the simplefb code for now.


Patch 1 adds the regulator properties to the DT binding.

Patch 2 adds code to the simplefb driver to claim and enable regulators.


Regards
ChenYu


Chen-Yu Tsai (2):
  dt-bindings: simplefb: Support a list of regulator supply properties
  simplefb: Claim and enable regulators

 .../bindings/video/simple-framebuffer.txt          |  13 ++-
 drivers/video/fbdev/simplefb.c                     | 122 ++++++++++++++++++++-
 2 files changed, 130 insertions(+), 5 deletions(-)

-- 
2.6.1


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

* [PATCH RFC v2 0/2] simplefb: Add regulator handling support
@ 2015-10-21  5:58 ` Chen-Yu Tsai
  0 siblings, 0 replies; 28+ messages in thread
From: Chen-Yu Tsai @ 2015-10-21  5:58 UTC (permalink / raw)
  To: linux-arm-kernel

Hi everyone,

This is v2 of the simplefb regulator support series. This series adds
regulator claiming and enabling support for simplefb.

Sometimes the simplefb display output path consits of external conversion
chips and/or LCD drivers and backlights. These devices normally have
GPIOs to turn them on and/or bring them out of reset, and regulators
supplying power to them.

While the kernel does not touch unclaimed GPIOs, the regulator core
happily disables unused regulators. Thus we need simplefb to claim
and enable the regulators used throughout the display pipeline.

Instead of the unnamed "vinN-supply" properties, v2 supports any named
regulator supplies under its device node. It will look through its
properties, and claim any regulators by matching "*-supply", as Mark
suggested.

I've not done a generic helper in the regulator core yet, instead doing
the regulator property handling in the simplefb code for now.


Patch 1 adds the regulator properties to the DT binding.

Patch 2 adds code to the simplefb driver to claim and enable regulators.


Regards
ChenYu


Chen-Yu Tsai (2):
  dt-bindings: simplefb: Support a list of regulator supply properties
  simplefb: Claim and enable regulators

 .../bindings/video/simple-framebuffer.txt          |  13 ++-
 drivers/video/fbdev/simplefb.c                     | 122 ++++++++++++++++++++-
 2 files changed, 130 insertions(+), 5 deletions(-)

-- 
2.6.1


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

* [PATCH RFC v2 0/2] simplefb: Add regulator handling support
@ 2015-10-21  5:58 ` Chen-Yu Tsai
  0 siblings, 0 replies; 28+ messages in thread
From: Chen-Yu Tsai @ 2015-10-21  5:58 UTC (permalink / raw)
  To: linux-arm-kernel

Hi everyone,

This is v2 of the simplefb regulator support series. This series adds
regulator claiming and enabling support for simplefb.

Sometimes the simplefb display output path consits of external conversion
chips and/or LCD drivers and backlights. These devices normally have
GPIOs to turn them on and/or bring them out of reset, and regulators
supplying power to them.

While the kernel does not touch unclaimed GPIOs, the regulator core
happily disables unused regulators. Thus we need simplefb to claim
and enable the regulators used throughout the display pipeline.

Instead of the unnamed "vinN-supply" properties, v2 supports any named
regulator supplies under its device node. It will look through its
properties, and claim any regulators by matching "*-supply", as Mark
suggested.

I've not done a generic helper in the regulator core yet, instead doing
the regulator property handling in the simplefb code for now.


Patch 1 adds the regulator properties to the DT binding.

Patch 2 adds code to the simplefb driver to claim and enable regulators.


Regards
ChenYu


Chen-Yu Tsai (2):
  dt-bindings: simplefb: Support a list of regulator supply properties
  simplefb: Claim and enable regulators

 .../bindings/video/simple-framebuffer.txt          |  13 ++-
 drivers/video/fbdev/simplefb.c                     | 122 ++++++++++++++++++++-
 2 files changed, 130 insertions(+), 5 deletions(-)

-- 
2.6.1

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

* [PATCH RFC v2 1/2] dt-bindings: simplefb: Support a list of regulator supply properties
@ 2015-10-21  5:59   ` Chen-Yu Tsai
  0 siblings, 0 replies; 28+ messages in thread
From: Chen-Yu Tsai @ 2015-10-21  5:59 UTC (permalink / raw)
  To: Hans de Goede, Jean-Christophe Plagniol-Villard, Tomi Valkeinen,
	Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala
  Cc: Chen-Yu Tsai, linux-fbdev, devicetree, linux-kernel,
	linux-arm-kernel, Mark Brown

The physical display tied to the framebuffer may have regulators
providing power to it, such as power for LCDs or interface conversion
chips.

The number of regulators in use may vary, but the regulator supply
binding can not be a list. Work around this by adding a "num-supplies"
property to communicate the number of supplies, and a list of 0 ~ N
"vinN-supply" properties for the actual regulator supply.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
 .../devicetree/bindings/video/simple-framebuffer.txt        | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/Documentation/devicetree/bindings/video/simple-framebuffer.txt b/Documentation/devicetree/bindings/video/simple-framebuffer.txt
index 4474ef6e0b95..8c9e9f515c87 100644
--- a/Documentation/devicetree/bindings/video/simple-framebuffer.txt
+++ b/Documentation/devicetree/bindings/video/simple-framebuffer.txt
@@ -47,10 +47,14 @@ Required properties:
   - a8b8g8r8 (32-bit pixels, d[31:24]=a, d[23:16]=b, d[15:8]=g, d[7:0]=r).
 
 Optional properties:
-- clocks : List of clocks used by the framebuffer. Clocks listed here
-           are expected to already be configured correctly. The OS must
-           ensure these clocks are not modified or disabled while the
-           simple framebuffer remains active.
+- clocks : List of clocks used by the framebuffer.
+- *-supply : Any number of regulators used by the framebuffer. These should
+	     be named according to the names in the device's design.
+
+  The above resources are expected to already be configured correctly.
+  The OS must ensure they are not modified or disabled while the simple
+  framebuffer remains active.
+
 - display : phandle pointing to the primary display hardware node
 
 Example:
@@ -68,6 +72,7 @@ chosen {
 		stride = <(1600 * 2)>;
 		format = "r5g6b5";
 		clocks = <&ahb_gates 36>, <&ahb_gates 43>, <&ahb_gates 44>;
+		lcd-supply = <&reg_dc1sw>;
 		display = <&lcdc0>;
 	};
 	stdout-path = "display0";
-- 
2.6.1


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

* [PATCH RFC v2 1/2] dt-bindings: simplefb: Support a list of regulator supply properties
@ 2015-10-21  5:59   ` Chen-Yu Tsai
  0 siblings, 0 replies; 28+ messages in thread
From: Chen-Yu Tsai @ 2015-10-21  5:59 UTC (permalink / raw)
  To: Hans de Goede, Jean-Christophe Plagniol-Villard, Tomi Valkeinen,
	Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala
  Cc: Chen-Yu Tsai, linux-fbdev-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, Mark Brown

The physical display tied to the framebuffer may have regulators
providing power to it, such as power for LCDs or interface conversion
chips.

The number of regulators in use may vary, but the regulator supply
binding can not be a list. Work around this by adding a "num-supplies"
property to communicate the number of supplies, and a list of 0 ~ N
"vinN-supply" properties for the actual regulator supply.

Signed-off-by: Chen-Yu Tsai <wens-jdAy2FN1RRM@public.gmane.org>
---
 .../devicetree/bindings/video/simple-framebuffer.txt        | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/Documentation/devicetree/bindings/video/simple-framebuffer.txt b/Documentation/devicetree/bindings/video/simple-framebuffer.txt
index 4474ef6e0b95..8c9e9f515c87 100644
--- a/Documentation/devicetree/bindings/video/simple-framebuffer.txt
+++ b/Documentation/devicetree/bindings/video/simple-framebuffer.txt
@@ -47,10 +47,14 @@ Required properties:
   - a8b8g8r8 (32-bit pixels, d[31:24]=a, d[23:16]=b, d[15:8]=g, d[7:0]=r).
 
 Optional properties:
-- clocks : List of clocks used by the framebuffer. Clocks listed here
-           are expected to already be configured correctly. The OS must
-           ensure these clocks are not modified or disabled while the
-           simple framebuffer remains active.
+- clocks : List of clocks used by the framebuffer.
+- *-supply : Any number of regulators used by the framebuffer. These should
+	     be named according to the names in the device's design.
+
+  The above resources are expected to already be configured correctly.
+  The OS must ensure they are not modified or disabled while the simple
+  framebuffer remains active.
+
 - display : phandle pointing to the primary display hardware node
 
 Example:
@@ -68,6 +72,7 @@ chosen {
 		stride = <(1600 * 2)>;
 		format = "r5g6b5";
 		clocks = <&ahb_gates 36>, <&ahb_gates 43>, <&ahb_gates 44>;
+		lcd-supply = <&reg_dc1sw>;
 		display = <&lcdc0>;
 	};
 	stdout-path = "display0";
-- 
2.6.1

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH RFC v2 1/2] dt-bindings: simplefb: Support a list of regulator supply properties
@ 2015-10-21  5:59   ` Chen-Yu Tsai
  0 siblings, 0 replies; 28+ messages in thread
From: Chen-Yu Tsai @ 2015-10-21  5:59 UTC (permalink / raw)
  To: linux-arm-kernel

The physical display tied to the framebuffer may have regulators
providing power to it, such as power for LCDs or interface conversion
chips.

The number of regulators in use may vary, but the regulator supply
binding can not be a list. Work around this by adding a "num-supplies"
property to communicate the number of supplies, and a list of 0 ~ N
"vinN-supply" properties for the actual regulator supply.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
 .../devicetree/bindings/video/simple-framebuffer.txt        | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/Documentation/devicetree/bindings/video/simple-framebuffer.txt b/Documentation/devicetree/bindings/video/simple-framebuffer.txt
index 4474ef6e0b95..8c9e9f515c87 100644
--- a/Documentation/devicetree/bindings/video/simple-framebuffer.txt
+++ b/Documentation/devicetree/bindings/video/simple-framebuffer.txt
@@ -47,10 +47,14 @@ Required properties:
   - a8b8g8r8 (32-bit pixels, d[31:24]=a, d[23:16]=b, d[15:8]=g, d[7:0]=r).
 
 Optional properties:
-- clocks : List of clocks used by the framebuffer. Clocks listed here
-           are expected to already be configured correctly. The OS must
-           ensure these clocks are not modified or disabled while the
-           simple framebuffer remains active.
+- clocks : List of clocks used by the framebuffer.
+- *-supply : Any number of regulators used by the framebuffer. These should
+	     be named according to the names in the device's design.
+
+  The above resources are expected to already be configured correctly.
+  The OS must ensure they are not modified or disabled while the simple
+  framebuffer remains active.
+
 - display : phandle pointing to the primary display hardware node
 
 Example:
@@ -68,6 +72,7 @@ chosen {
 		stride = <(1600 * 2)>;
 		format = "r5g6b5";
 		clocks = <&ahb_gates 36>, <&ahb_gates 43>, <&ahb_gates 44>;
+		lcd-supply = <&reg_dc1sw>;
 		display = <&lcdc0>;
 	};
 	stdout-path = "display0";
-- 
2.6.1


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

* [PATCH RFC v2 1/2] dt-bindings: simplefb: Support a list of regulator supply properties
@ 2015-10-21  5:59   ` Chen-Yu Tsai
  0 siblings, 0 replies; 28+ messages in thread
From: Chen-Yu Tsai @ 2015-10-21  5:59 UTC (permalink / raw)
  To: linux-arm-kernel

The physical display tied to the framebuffer may have regulators
providing power to it, such as power for LCDs or interface conversion
chips.

The number of regulators in use may vary, but the regulator supply
binding can not be a list. Work around this by adding a "num-supplies"
property to communicate the number of supplies, and a list of 0 ~ N
"vinN-supply" properties for the actual regulator supply.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
 .../devicetree/bindings/video/simple-framebuffer.txt        | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/Documentation/devicetree/bindings/video/simple-framebuffer.txt b/Documentation/devicetree/bindings/video/simple-framebuffer.txt
index 4474ef6e0b95..8c9e9f515c87 100644
--- a/Documentation/devicetree/bindings/video/simple-framebuffer.txt
+++ b/Documentation/devicetree/bindings/video/simple-framebuffer.txt
@@ -47,10 +47,14 @@ Required properties:
   - a8b8g8r8 (32-bit pixels, d[31:24]=a, d[23:16]=b, d[15:8]=g, d[7:0]=r).
 
 Optional properties:
-- clocks : List of clocks used by the framebuffer. Clocks listed here
-           are expected to already be configured correctly. The OS must
-           ensure these clocks are not modified or disabled while the
-           simple framebuffer remains active.
+- clocks : List of clocks used by the framebuffer.
+- *-supply : Any number of regulators used by the framebuffer. These should
+	     be named according to the names in the device's design.
+
+  The above resources are expected to already be configured correctly.
+  The OS must ensure they are not modified or disabled while the simple
+  framebuffer remains active.
+
 - display : phandle pointing to the primary display hardware node
 
 Example:
@@ -68,6 +72,7 @@ chosen {
 		stride = <(1600 * 2)>;
 		format = "r5g6b5";
 		clocks = <&ahb_gates 36>, <&ahb_gates 43>, <&ahb_gates 44>;
+		lcd-supply = <&reg_dc1sw>;
 		display = <&lcdc0>;
 	};
 	stdout-path = "display0";
-- 
2.6.1

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

* [PATCH RFC v2 2/2] simplefb: Claim and enable regulators
  2015-10-21  5:58 ` Chen-Yu Tsai
  (?)
@ 2015-10-21  5:59   ` Chen-Yu Tsai
  -1 siblings, 0 replies; 28+ messages in thread
From: Chen-Yu Tsai @ 2015-10-21  5:59 UTC (permalink / raw)
  To: Hans de Goede, Jean-Christophe Plagniol-Villard, Tomi Valkeinen,
	Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala
  Cc: Chen-Yu Tsai, linux-fbdev, devicetree, linux-kernel,
	linux-arm-kernel, Mark Brown

This claims and enables regulators listed in the simple framebuffer dt
node. This is needed so that regulators powering the display pipeline
and external hardware, described in the device node and known by the
kernel code, will remain properly enabled.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
 drivers/video/fbdev/simplefb.c | 122 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 121 insertions(+), 1 deletion(-)

diff --git a/drivers/video/fbdev/simplefb.c b/drivers/video/fbdev/simplefb.c
index 52c5c7e63b52..c4ee10d83a70 100644
--- a/drivers/video/fbdev/simplefb.c
+++ b/drivers/video/fbdev/simplefb.c
@@ -28,7 +28,10 @@
 #include <linux/platform_device.h>
 #include <linux/clk.h>
 #include <linux/clk-provider.h>
+#include <linux/of.h>
 #include <linux/of_platform.h>
+#include <linux/parser.h>
+#include <linux/regulator/consumer.h>
 
 static struct fb_fix_screeninfo simplefb_fix = {
 	.id		= "simple",
@@ -174,6 +177,10 @@ struct simplefb_par {
 	int clk_count;
 	struct clk **clks;
 #endif
+#if defined CONFIG_OF && defined CONFIG_REGULATOR
+	u32 regulator_count;
+	struct regulator **regulators;
+#endif
 };
 
 #if defined CONFIG_OF && defined CONFIG_COMMON_CLK
@@ -269,6 +276,112 @@ static int simplefb_clocks_init(struct simplefb_par *par,
 static void simplefb_clocks_destroy(struct simplefb_par *par) { }
 #endif
 
+#if defined CONFIG_OF && defined CONFIG_REGULATOR
+
+#define SUPPLY_SUFFIX "-supply"
+
+/*
+ * Regulator handling code.
+ *
+ * Here we handle the num-supplies and vin*-supply properties of our
+ * "simple-framebuffer" dt node. This is necessary so that we can make sure
+ * that any regulators needed by the display hardware that the bootloader
+ * set up for us (and for which it provided a simplefb dt node), stay up,
+ * for the life of the simplefb driver.
+ *
+ * When the driver unloads, we cleanly disable, and then release the
+ * regulators.
+ *
+ * We only complain about errors here, no action is taken as the most likely
+ * error can only happen due to a mismatch between the bootloader which set
+ * up simplefb, and the regulator definitions in the device tree. Chances are
+ * that there are no adverse effects, and if there are, a clean teardown of
+ * the fb probe will not help us much either. So just complain and carry on,
+ * and hope that the user actually gets a working fb at the end of things.
+ */
+static int simplefb_regulators_init(struct simplefb_par *par,
+	struct platform_device *pdev)
+{
+	struct device_node *np = pdev->dev.of_node;
+	struct property *prop;
+	struct regulator *regulator;
+	const char *p;
+	int count = 0, i = 0, ret;
+
+	if (dev_get_platdata(&pdev->dev) || !np)
+		return 0;
+
+	/* Count the number of regulator supplies */
+	for_each_property_of_node(np, prop) {
+		p = strstr(prop->name, SUPPLY_SUFFIX);
+		if (p && p != prop->name)
+			count++;
+	}
+
+	if (!count)
+		return 0;
+
+	par->regulators = devm_kcalloc(&pdev->dev, count,
+				       sizeof(struct regulator *), GFP_KERNEL);
+	if (!par->regulators)
+		return -ENOMEM;
+
+	/* Get all the regulators */
+	for_each_property_of_node(np, prop) {
+		char name[32]; /* 32 is max size of property name */
+
+		p = strstr(prop->name, SUPPLY_SUFFIX);
+		if (p && p != prop->name)
+			continue;
+
+		strlcpy(name, prop->name,
+			strlen(prop->name) - sizeof(SUPPLY_SUFFIX) + 1);
+		regulator = devm_regulator_get_optional(&pdev->dev, name);
+		if (IS_ERR(regulator)) {
+			if (PTR_ERR(regulator) == -EPROBE_DEFER)
+				return -EPROBE_DEFER;
+			dev_err(&pdev->dev, "regulator %s not found: %ld\n",
+				name, PTR_ERR(regulator));
+			continue;
+		}
+		par->regulators[i++] = regulator;
+	}
+	par->regulator_count = i;
+
+	/* Enable all the regulators */
+	for (i = 0; i < par->regulator_count; i++) {
+		if (par->regulators[i]) {
+			ret = regulator_enable(par->regulators[i]);
+			if (ret) {
+				dev_err(&pdev->dev,
+					"failed to enable regulator %d: %d\n",
+					i, ret);
+				devm_regulator_put(par->regulators[i]);
+				par->regulators[i] = NULL;
+			}
+		}
+	}
+
+	return 0;
+}
+
+static void simplefb_regulators_destroy(struct simplefb_par *par)
+{
+	int i;
+
+	if (!par->regulators)
+		return;
+
+	for (i = 0; i < par->regulator_count; i++)
+		if (par->regulators[i])
+			regulator_disable(par->regulators[i]);
+}
+#else
+static int simplefb_regulators_init(struct simplefb_par *par,
+	struct platform_device *pdev) { return 0; }
+static void simplefb_regulators_destroy(struct simplefb_par *par) { }
+#endif
+
 static int simplefb_probe(struct platform_device *pdev)
 {
 	int ret;
@@ -340,6 +453,10 @@ static int simplefb_probe(struct platform_device *pdev)
 	if (ret < 0)
 		goto error_unmap;
 
+	ret = simplefb_regulators_init(par, pdev);
+	if (ret < 0)
+		goto error_clocks;
+
 	dev_info(&pdev->dev, "framebuffer at 0x%lx, 0x%x bytes, mapped to 0x%p\n",
 			     info->fix.smem_start, info->fix.smem_len,
 			     info->screen_base);
@@ -351,13 +468,15 @@ static int simplefb_probe(struct platform_device *pdev)
 	ret = register_framebuffer(info);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "Unable to register simplefb: %d\n", ret);
-		goto error_clocks;
+		goto error_regulators;
 	}
 
 	dev_info(&pdev->dev, "fb%d: simplefb registered!\n", info->node);
 
 	return 0;
 
+error_regulators:
+	simplefb_regulators_destroy(par);
 error_clocks:
 	simplefb_clocks_destroy(par);
 error_unmap:
@@ -373,6 +492,7 @@ static int simplefb_remove(struct platform_device *pdev)
 	struct simplefb_par *par = info->par;
 
 	unregister_framebuffer(info);
+	simplefb_regulators_destroy(par);
 	simplefb_clocks_destroy(par);
 	framebuffer_release(info);
 
-- 
2.6.1


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

* [PATCH RFC v2 2/2] simplefb: Claim and enable regulators
@ 2015-10-21  5:59   ` Chen-Yu Tsai
  0 siblings, 0 replies; 28+ messages in thread
From: Chen-Yu Tsai @ 2015-10-21  5:59 UTC (permalink / raw)
  To: linux-arm-kernel

This claims and enables regulators listed in the simple framebuffer dt
node. This is needed so that regulators powering the display pipeline
and external hardware, described in the device node and known by the
kernel code, will remain properly enabled.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
 drivers/video/fbdev/simplefb.c | 122 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 121 insertions(+), 1 deletion(-)

diff --git a/drivers/video/fbdev/simplefb.c b/drivers/video/fbdev/simplefb.c
index 52c5c7e63b52..c4ee10d83a70 100644
--- a/drivers/video/fbdev/simplefb.c
+++ b/drivers/video/fbdev/simplefb.c
@@ -28,7 +28,10 @@
 #include <linux/platform_device.h>
 #include <linux/clk.h>
 #include <linux/clk-provider.h>
+#include <linux/of.h>
 #include <linux/of_platform.h>
+#include <linux/parser.h>
+#include <linux/regulator/consumer.h>
 
 static struct fb_fix_screeninfo simplefb_fix = {
 	.id		= "simple",
@@ -174,6 +177,10 @@ struct simplefb_par {
 	int clk_count;
 	struct clk **clks;
 #endif
+#if defined CONFIG_OF && defined CONFIG_REGULATOR
+	u32 regulator_count;
+	struct regulator **regulators;
+#endif
 };
 
 #if defined CONFIG_OF && defined CONFIG_COMMON_CLK
@@ -269,6 +276,112 @@ static int simplefb_clocks_init(struct simplefb_par *par,
 static void simplefb_clocks_destroy(struct simplefb_par *par) { }
 #endif
 
+#if defined CONFIG_OF && defined CONFIG_REGULATOR
+
+#define SUPPLY_SUFFIX "-supply"
+
+/*
+ * Regulator handling code.
+ *
+ * Here we handle the num-supplies and vin*-supply properties of our
+ * "simple-framebuffer" dt node. This is necessary so that we can make sure
+ * that any regulators needed by the display hardware that the bootloader
+ * set up for us (and for which it provided a simplefb dt node), stay up,
+ * for the life of the simplefb driver.
+ *
+ * When the driver unloads, we cleanly disable, and then release the
+ * regulators.
+ *
+ * We only complain about errors here, no action is taken as the most likely
+ * error can only happen due to a mismatch between the bootloader which set
+ * up simplefb, and the regulator definitions in the device tree. Chances are
+ * that there are no adverse effects, and if there are, a clean teardown of
+ * the fb probe will not help us much either. So just complain and carry on,
+ * and hope that the user actually gets a working fb at the end of things.
+ */
+static int simplefb_regulators_init(struct simplefb_par *par,
+	struct platform_device *pdev)
+{
+	struct device_node *np = pdev->dev.of_node;
+	struct property *prop;
+	struct regulator *regulator;
+	const char *p;
+	int count = 0, i = 0, ret;
+
+	if (dev_get_platdata(&pdev->dev) || !np)
+		return 0;
+
+	/* Count the number of regulator supplies */
+	for_each_property_of_node(np, prop) {
+		p = strstr(prop->name, SUPPLY_SUFFIX);
+		if (p && p != prop->name)
+			count++;
+	}
+
+	if (!count)
+		return 0;
+
+	par->regulators = devm_kcalloc(&pdev->dev, count,
+				       sizeof(struct regulator *), GFP_KERNEL);
+	if (!par->regulators)
+		return -ENOMEM;
+
+	/* Get all the regulators */
+	for_each_property_of_node(np, prop) {
+		char name[32]; /* 32 is max size of property name */
+
+		p = strstr(prop->name, SUPPLY_SUFFIX);
+		if (p && p != prop->name)
+			continue;
+
+		strlcpy(name, prop->name,
+			strlen(prop->name) - sizeof(SUPPLY_SUFFIX) + 1);
+		regulator = devm_regulator_get_optional(&pdev->dev, name);
+		if (IS_ERR(regulator)) {
+			if (PTR_ERR(regulator) = -EPROBE_DEFER)
+				return -EPROBE_DEFER;
+			dev_err(&pdev->dev, "regulator %s not found: %ld\n",
+				name, PTR_ERR(regulator));
+			continue;
+		}
+		par->regulators[i++] = regulator;
+	}
+	par->regulator_count = i;
+
+	/* Enable all the regulators */
+	for (i = 0; i < par->regulator_count; i++) {
+		if (par->regulators[i]) {
+			ret = regulator_enable(par->regulators[i]);
+			if (ret) {
+				dev_err(&pdev->dev,
+					"failed to enable regulator %d: %d\n",
+					i, ret);
+				devm_regulator_put(par->regulators[i]);
+				par->regulators[i] = NULL;
+			}
+		}
+	}
+
+	return 0;
+}
+
+static void simplefb_regulators_destroy(struct simplefb_par *par)
+{
+	int i;
+
+	if (!par->regulators)
+		return;
+
+	for (i = 0; i < par->regulator_count; i++)
+		if (par->regulators[i])
+			regulator_disable(par->regulators[i]);
+}
+#else
+static int simplefb_regulators_init(struct simplefb_par *par,
+	struct platform_device *pdev) { return 0; }
+static void simplefb_regulators_destroy(struct simplefb_par *par) { }
+#endif
+
 static int simplefb_probe(struct platform_device *pdev)
 {
 	int ret;
@@ -340,6 +453,10 @@ static int simplefb_probe(struct platform_device *pdev)
 	if (ret < 0)
 		goto error_unmap;
 
+	ret = simplefb_regulators_init(par, pdev);
+	if (ret < 0)
+		goto error_clocks;
+
 	dev_info(&pdev->dev, "framebuffer at 0x%lx, 0x%x bytes, mapped to 0x%p\n",
 			     info->fix.smem_start, info->fix.smem_len,
 			     info->screen_base);
@@ -351,13 +468,15 @@ static int simplefb_probe(struct platform_device *pdev)
 	ret = register_framebuffer(info);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "Unable to register simplefb: %d\n", ret);
-		goto error_clocks;
+		goto error_regulators;
 	}
 
 	dev_info(&pdev->dev, "fb%d: simplefb registered!\n", info->node);
 
 	return 0;
 
+error_regulators:
+	simplefb_regulators_destroy(par);
 error_clocks:
 	simplefb_clocks_destroy(par);
 error_unmap:
@@ -373,6 +492,7 @@ static int simplefb_remove(struct platform_device *pdev)
 	struct simplefb_par *par = info->par;
 
 	unregister_framebuffer(info);
+	simplefb_regulators_destroy(par);
 	simplefb_clocks_destroy(par);
 	framebuffer_release(info);
 
-- 
2.6.1


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

* [PATCH RFC v2 2/2] simplefb: Claim and enable regulators
@ 2015-10-21  5:59   ` Chen-Yu Tsai
  0 siblings, 0 replies; 28+ messages in thread
From: Chen-Yu Tsai @ 2015-10-21  5:59 UTC (permalink / raw)
  To: linux-arm-kernel

This claims and enables regulators listed in the simple framebuffer dt
node. This is needed so that regulators powering the display pipeline
and external hardware, described in the device node and known by the
kernel code, will remain properly enabled.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
 drivers/video/fbdev/simplefb.c | 122 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 121 insertions(+), 1 deletion(-)

diff --git a/drivers/video/fbdev/simplefb.c b/drivers/video/fbdev/simplefb.c
index 52c5c7e63b52..c4ee10d83a70 100644
--- a/drivers/video/fbdev/simplefb.c
+++ b/drivers/video/fbdev/simplefb.c
@@ -28,7 +28,10 @@
 #include <linux/platform_device.h>
 #include <linux/clk.h>
 #include <linux/clk-provider.h>
+#include <linux/of.h>
 #include <linux/of_platform.h>
+#include <linux/parser.h>
+#include <linux/regulator/consumer.h>
 
 static struct fb_fix_screeninfo simplefb_fix = {
 	.id		= "simple",
@@ -174,6 +177,10 @@ struct simplefb_par {
 	int clk_count;
 	struct clk **clks;
 #endif
+#if defined CONFIG_OF && defined CONFIG_REGULATOR
+	u32 regulator_count;
+	struct regulator **regulators;
+#endif
 };
 
 #if defined CONFIG_OF && defined CONFIG_COMMON_CLK
@@ -269,6 +276,112 @@ static int simplefb_clocks_init(struct simplefb_par *par,
 static void simplefb_clocks_destroy(struct simplefb_par *par) { }
 #endif
 
+#if defined CONFIG_OF && defined CONFIG_REGULATOR
+
+#define SUPPLY_SUFFIX "-supply"
+
+/*
+ * Regulator handling code.
+ *
+ * Here we handle the num-supplies and vin*-supply properties of our
+ * "simple-framebuffer" dt node. This is necessary so that we can make sure
+ * that any regulators needed by the display hardware that the bootloader
+ * set up for us (and for which it provided a simplefb dt node), stay up,
+ * for the life of the simplefb driver.
+ *
+ * When the driver unloads, we cleanly disable, and then release the
+ * regulators.
+ *
+ * We only complain about errors here, no action is taken as the most likely
+ * error can only happen due to a mismatch between the bootloader which set
+ * up simplefb, and the regulator definitions in the device tree. Chances are
+ * that there are no adverse effects, and if there are, a clean teardown of
+ * the fb probe will not help us much either. So just complain and carry on,
+ * and hope that the user actually gets a working fb at the end of things.
+ */
+static int simplefb_regulators_init(struct simplefb_par *par,
+	struct platform_device *pdev)
+{
+	struct device_node *np = pdev->dev.of_node;
+	struct property *prop;
+	struct regulator *regulator;
+	const char *p;
+	int count = 0, i = 0, ret;
+
+	if (dev_get_platdata(&pdev->dev) || !np)
+		return 0;
+
+	/* Count the number of regulator supplies */
+	for_each_property_of_node(np, prop) {
+		p = strstr(prop->name, SUPPLY_SUFFIX);
+		if (p && p != prop->name)
+			count++;
+	}
+
+	if (!count)
+		return 0;
+
+	par->regulators = devm_kcalloc(&pdev->dev, count,
+				       sizeof(struct regulator *), GFP_KERNEL);
+	if (!par->regulators)
+		return -ENOMEM;
+
+	/* Get all the regulators */
+	for_each_property_of_node(np, prop) {
+		char name[32]; /* 32 is max size of property name */
+
+		p = strstr(prop->name, SUPPLY_SUFFIX);
+		if (p && p != prop->name)
+			continue;
+
+		strlcpy(name, prop->name,
+			strlen(prop->name) - sizeof(SUPPLY_SUFFIX) + 1);
+		regulator = devm_regulator_get_optional(&pdev->dev, name);
+		if (IS_ERR(regulator)) {
+			if (PTR_ERR(regulator) == -EPROBE_DEFER)
+				return -EPROBE_DEFER;
+			dev_err(&pdev->dev, "regulator %s not found: %ld\n",
+				name, PTR_ERR(regulator));
+			continue;
+		}
+		par->regulators[i++] = regulator;
+	}
+	par->regulator_count = i;
+
+	/* Enable all the regulators */
+	for (i = 0; i < par->regulator_count; i++) {
+		if (par->regulators[i]) {
+			ret = regulator_enable(par->regulators[i]);
+			if (ret) {
+				dev_err(&pdev->dev,
+					"failed to enable regulator %d: %d\n",
+					i, ret);
+				devm_regulator_put(par->regulators[i]);
+				par->regulators[i] = NULL;
+			}
+		}
+	}
+
+	return 0;
+}
+
+static void simplefb_regulators_destroy(struct simplefb_par *par)
+{
+	int i;
+
+	if (!par->regulators)
+		return;
+
+	for (i = 0; i < par->regulator_count; i++)
+		if (par->regulators[i])
+			regulator_disable(par->regulators[i]);
+}
+#else
+static int simplefb_regulators_init(struct simplefb_par *par,
+	struct platform_device *pdev) { return 0; }
+static void simplefb_regulators_destroy(struct simplefb_par *par) { }
+#endif
+
 static int simplefb_probe(struct platform_device *pdev)
 {
 	int ret;
@@ -340,6 +453,10 @@ static int simplefb_probe(struct platform_device *pdev)
 	if (ret < 0)
 		goto error_unmap;
 
+	ret = simplefb_regulators_init(par, pdev);
+	if (ret < 0)
+		goto error_clocks;
+
 	dev_info(&pdev->dev, "framebuffer at 0x%lx, 0x%x bytes, mapped to 0x%p\n",
 			     info->fix.smem_start, info->fix.smem_len,
 			     info->screen_base);
@@ -351,13 +468,15 @@ static int simplefb_probe(struct platform_device *pdev)
 	ret = register_framebuffer(info);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "Unable to register simplefb: %d\n", ret);
-		goto error_clocks;
+		goto error_regulators;
 	}
 
 	dev_info(&pdev->dev, "fb%d: simplefb registered!\n", info->node);
 
 	return 0;
 
+error_regulators:
+	simplefb_regulators_destroy(par);
 error_clocks:
 	simplefb_clocks_destroy(par);
 error_unmap:
@@ -373,6 +492,7 @@ static int simplefb_remove(struct platform_device *pdev)
 	struct simplefb_par *par = info->par;
 
 	unregister_framebuffer(info);
+	simplefb_regulators_destroy(par);
 	simplefb_clocks_destroy(par);
 	framebuffer_release(info);
 
-- 
2.6.1

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

* Re: [PATCH RFC v2 1/2] dt-bindings: simplefb: Support a list of regulator supply properties
@ 2015-10-21  7:50     ` Hans de Goede
  0 siblings, 0 replies; 28+ messages in thread
From: Hans de Goede @ 2015-10-21  7:50 UTC (permalink / raw)
  To: Chen-Yu Tsai, Jean-Christophe Plagniol-Villard, Tomi Valkeinen,
	Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala
  Cc: linux-fbdev, devicetree, linux-kernel, linux-arm-kernel, Mark Brown

Hi,

On 21-10-15 07:59, Chen-Yu Tsai wrote:
> The physical display tied to the framebuffer may have regulators
> providing power to it, such as power for LCDs or interface conversion
> chips.
>
> The number of regulators in use may vary, but the regulator supply
> binding can not be a list. Work around this by adding a "num-supplies"
> property to communicate the number of supplies, and a list of 0 ~ N
> "vinN-supply" properties for the actual regulator supply.

This bit of the commit message is no longer accurate. Other then that
this patch looks good to me:

Reviewed-by: Hans de Goede <hdegoede@redhat.com>

Regards,

Hans


>
> Signed-off-by: Chen-Yu Tsai <wens@csie.org>
> ---
>   .../devicetree/bindings/video/simple-framebuffer.txt        | 13 +++++++++----
>   1 file changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/Documentation/devicetree/bindings/video/simple-framebuffer.txt b/Documentation/devicetree/bindings/video/simple-framebuffer.txt
> index 4474ef6e0b95..8c9e9f515c87 100644
> --- a/Documentation/devicetree/bindings/video/simple-framebuffer.txt
> +++ b/Documentation/devicetree/bindings/video/simple-framebuffer.txt
> @@ -47,10 +47,14 @@ Required properties:
>     - a8b8g8r8 (32-bit pixels, d[31:24]=a, d[23:16]=b, d[15:8]=g, d[7:0]=r).
>
>   Optional properties:
> -- clocks : List of clocks used by the framebuffer. Clocks listed here
> -           are expected to already be configured correctly. The OS must
> -           ensure these clocks are not modified or disabled while the
> -           simple framebuffer remains active.
> +- clocks : List of clocks used by the framebuffer.
> +- *-supply : Any number of regulators used by the framebuffer. These should
> +	     be named according to the names in the device's design.
> +
> +  The above resources are expected to already be configured correctly.
> +  The OS must ensure they are not modified or disabled while the simple
> +  framebuffer remains active.
> +
>   - display : phandle pointing to the primary display hardware node
>
>   Example:
> @@ -68,6 +72,7 @@ chosen {
>   		stride = <(1600 * 2)>;
>   		format = "r5g6b5";
>   		clocks = <&ahb_gates 36>, <&ahb_gates 43>, <&ahb_gates 44>;
> +		lcd-supply = <&reg_dc1sw>;
>   		display = <&lcdc0>;
>   	};
>   	stdout-path = "display0";
>

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

* Re: [PATCH RFC v2 1/2] dt-bindings: simplefb: Support a list of regulator supply properties
@ 2015-10-21  7:50     ` Hans de Goede
  0 siblings, 0 replies; 28+ messages in thread
From: Hans de Goede @ 2015-10-21  7:50 UTC (permalink / raw)
  To: Chen-Yu Tsai, Jean-Christophe Plagniol-Villard, Tomi Valkeinen,
	Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala
  Cc: linux-fbdev-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, Mark Brown

Hi,

On 21-10-15 07:59, Chen-Yu Tsai wrote:
> The physical display tied to the framebuffer may have regulators
> providing power to it, such as power for LCDs or interface conversion
> chips.
>
> The number of regulators in use may vary, but the regulator supply
> binding can not be a list. Work around this by adding a "num-supplies"
> property to communicate the number of supplies, and a list of 0 ~ N
> "vinN-supply" properties for the actual regulator supply.

This bit of the commit message is no longer accurate. Other then that
this patch looks good to me:

Reviewed-by: Hans de Goede <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>

Regards,

Hans


>
> Signed-off-by: Chen-Yu Tsai <wens-jdAy2FN1RRM@public.gmane.org>
> ---
>   .../devicetree/bindings/video/simple-framebuffer.txt        | 13 +++++++++----
>   1 file changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/Documentation/devicetree/bindings/video/simple-framebuffer.txt b/Documentation/devicetree/bindings/video/simple-framebuffer.txt
> index 4474ef6e0b95..8c9e9f515c87 100644
> --- a/Documentation/devicetree/bindings/video/simple-framebuffer.txt
> +++ b/Documentation/devicetree/bindings/video/simple-framebuffer.txt
> @@ -47,10 +47,14 @@ Required properties:
>     - a8b8g8r8 (32-bit pixels, d[31:24]=a, d[23:16]=b, d[15:8]=g, d[7:0]=r).
>
>   Optional properties:
> -- clocks : List of clocks used by the framebuffer. Clocks listed here
> -           are expected to already be configured correctly. The OS must
> -           ensure these clocks are not modified or disabled while the
> -           simple framebuffer remains active.
> +- clocks : List of clocks used by the framebuffer.
> +- *-supply : Any number of regulators used by the framebuffer. These should
> +	     be named according to the names in the device's design.
> +
> +  The above resources are expected to already be configured correctly.
> +  The OS must ensure they are not modified or disabled while the simple
> +  framebuffer remains active.
> +
>   - display : phandle pointing to the primary display hardware node
>
>   Example:
> @@ -68,6 +72,7 @@ chosen {
>   		stride = <(1600 * 2)>;
>   		format = "r5g6b5";
>   		clocks = <&ahb_gates 36>, <&ahb_gates 43>, <&ahb_gates 44>;
> +		lcd-supply = <&reg_dc1sw>;
>   		display = <&lcdc0>;
>   	};
>   	stdout-path = "display0";
>
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH RFC v2 1/2] dt-bindings: simplefb: Support a list of regulator supply properties
@ 2015-10-21  7:50     ` Hans de Goede
  0 siblings, 0 replies; 28+ messages in thread
From: Hans de Goede @ 2015-10-21  7:50 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,

On 21-10-15 07:59, Chen-Yu Tsai wrote:
> The physical display tied to the framebuffer may have regulators
> providing power to it, such as power for LCDs or interface conversion
> chips.
>
> The number of regulators in use may vary, but the regulator supply
> binding can not be a list. Work around this by adding a "num-supplies"
> property to communicate the number of supplies, and a list of 0 ~ N
> "vinN-supply" properties for the actual regulator supply.

This bit of the commit message is no longer accurate. Other then that
this patch looks good to me:

Reviewed-by: Hans de Goede <hdegoede@redhat.com>

Regards,

Hans


>
> Signed-off-by: Chen-Yu Tsai <wens@csie.org>
> ---
>   .../devicetree/bindings/video/simple-framebuffer.txt        | 13 +++++++++----
>   1 file changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/Documentation/devicetree/bindings/video/simple-framebuffer.txt b/Documentation/devicetree/bindings/video/simple-framebuffer.txt
> index 4474ef6e0b95..8c9e9f515c87 100644
> --- a/Documentation/devicetree/bindings/video/simple-framebuffer.txt
> +++ b/Documentation/devicetree/bindings/video/simple-framebuffer.txt
> @@ -47,10 +47,14 @@ Required properties:
>     - a8b8g8r8 (32-bit pixels, d[31:24]=a, d[23:16]=b, d[15:8]=g, d[7:0]=r).
>
>   Optional properties:
> -- clocks : List of clocks used by the framebuffer. Clocks listed here
> -           are expected to already be configured correctly. The OS must
> -           ensure these clocks are not modified or disabled while the
> -           simple framebuffer remains active.
> +- clocks : List of clocks used by the framebuffer.
> +- *-supply : Any number of regulators used by the framebuffer. These should
> +	     be named according to the names in the device's design.
> +
> +  The above resources are expected to already be configured correctly.
> +  The OS must ensure they are not modified or disabled while the simple
> +  framebuffer remains active.
> +
>   - display : phandle pointing to the primary display hardware node
>
>   Example:
> @@ -68,6 +72,7 @@ chosen {
>   		stride = <(1600 * 2)>;
>   		format = "r5g6b5";
>   		clocks = <&ahb_gates 36>, <&ahb_gates 43>, <&ahb_gates 44>;
> +		lcd-supply = <&reg_dc1sw>;
>   		display = <&lcdc0>;
>   	};
>   	stdout-path = "display0";
>

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

* [PATCH RFC v2 1/2] dt-bindings: simplefb: Support a list of regulator supply properties
@ 2015-10-21  7:50     ` Hans de Goede
  0 siblings, 0 replies; 28+ messages in thread
From: Hans de Goede @ 2015-10-21  7:50 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,

On 21-10-15 07:59, Chen-Yu Tsai wrote:
> The physical display tied to the framebuffer may have regulators
> providing power to it, such as power for LCDs or interface conversion
> chips.
>
> The number of regulators in use may vary, but the regulator supply
> binding can not be a list. Work around this by adding a "num-supplies"
> property to communicate the number of supplies, and a list of 0 ~ N
> "vinN-supply" properties for the actual regulator supply.

This bit of the commit message is no longer accurate. Other then that
this patch looks good to me:

Reviewed-by: Hans de Goede <hdegoede@redhat.com>

Regards,

Hans


>
> Signed-off-by: Chen-Yu Tsai <wens@csie.org>
> ---
>   .../devicetree/bindings/video/simple-framebuffer.txt        | 13 +++++++++----
>   1 file changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/Documentation/devicetree/bindings/video/simple-framebuffer.txt b/Documentation/devicetree/bindings/video/simple-framebuffer.txt
> index 4474ef6e0b95..8c9e9f515c87 100644
> --- a/Documentation/devicetree/bindings/video/simple-framebuffer.txt
> +++ b/Documentation/devicetree/bindings/video/simple-framebuffer.txt
> @@ -47,10 +47,14 @@ Required properties:
>     - a8b8g8r8 (32-bit pixels, d[31:24]=a, d[23:16]=b, d[15:8]=g, d[7:0]=r).
>
>   Optional properties:
> -- clocks : List of clocks used by the framebuffer. Clocks listed here
> -           are expected to already be configured correctly. The OS must
> -           ensure these clocks are not modified or disabled while the
> -           simple framebuffer remains active.
> +- clocks : List of clocks used by the framebuffer.
> +- *-supply : Any number of regulators used by the framebuffer. These should
> +	     be named according to the names in the device's design.
> +
> +  The above resources are expected to already be configured correctly.
> +  The OS must ensure they are not modified or disabled while the simple
> +  framebuffer remains active.
> +
>   - display : phandle pointing to the primary display hardware node
>
>   Example:
> @@ -68,6 +72,7 @@ chosen {
>   		stride = <(1600 * 2)>;
>   		format = "r5g6b5";
>   		clocks = <&ahb_gates 36>, <&ahb_gates 43>, <&ahb_gates 44>;
> +		lcd-supply = <&reg_dc1sw>;
>   		display = <&lcdc0>;
>   	};
>   	stdout-path = "display0";
>

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

* Re: [PATCH RFC v2 2/2] simplefb: Claim and enable regulators
  2015-10-21  5:59   ` Chen-Yu Tsai
  (?)
@ 2015-10-21  7:54     ` Hans de Goede
  -1 siblings, 0 replies; 28+ messages in thread
From: Hans de Goede @ 2015-10-21  7:54 UTC (permalink / raw)
  To: Chen-Yu Tsai, Jean-Christophe Plagniol-Villard, Tomi Valkeinen,
	Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala
  Cc: linux-fbdev, devicetree, linux-kernel, linux-arm-kernel, Mark Brown

Hi,

On 21-10-15 07:59, Chen-Yu Tsai wrote:
> This claims and enables regulators listed in the simple framebuffer dt
> node. This is needed so that regulators powering the display pipeline
> and external hardware, described in the device node and known by the
> kernel code, will remain properly enabled.
>
> Signed-off-by: Chen-Yu Tsai <wens@csie.org>
> ---
>   drivers/video/fbdev/simplefb.c | 122 ++++++++++++++++++++++++++++++++++++++++-
>   1 file changed, 121 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/video/fbdev/simplefb.c b/drivers/video/fbdev/simplefb.c
> index 52c5c7e63b52..c4ee10d83a70 100644
> --- a/drivers/video/fbdev/simplefb.c
> +++ b/drivers/video/fbdev/simplefb.c
> @@ -28,7 +28,10 @@
>   #include <linux/platform_device.h>
>   #include <linux/clk.h>
>   #include <linux/clk-provider.h>
> +#include <linux/of.h>
>   #include <linux/of_platform.h>
> +#include <linux/parser.h>
> +#include <linux/regulator/consumer.h>
>
>   static struct fb_fix_screeninfo simplefb_fix = {
>   	.id		= "simple",
> @@ -174,6 +177,10 @@ struct simplefb_par {
>   	int clk_count;
>   	struct clk **clks;
>   #endif
> +#if defined CONFIG_OF && defined CONFIG_REGULATOR
> +	u32 regulator_count;
> +	struct regulator **regulators;
> +#endif
>   };
>
>   #if defined CONFIG_OF && defined CONFIG_COMMON_CLK
> @@ -269,6 +276,112 @@ static int simplefb_clocks_init(struct simplefb_par *par,
>   static void simplefb_clocks_destroy(struct simplefb_par *par) { }
>   #endif
>
> +#if defined CONFIG_OF && defined CONFIG_REGULATOR
> +
> +#define SUPPLY_SUFFIX "-supply"
> +
> +/*
> + * Regulator handling code.
> + *
> + * Here we handle the num-supplies and vin*-supply properties of our
> + * "simple-framebuffer" dt node. This is necessary so that we can make sure
> + * that any regulators needed by the display hardware that the bootloader
> + * set up for us (and for which it provided a simplefb dt node), stay up,
> + * for the life of the simplefb driver.
> + *
> + * When the driver unloads, we cleanly disable, and then release the
> + * regulators.
> + *
> + * We only complain about errors here, no action is taken as the most likely
> + * error can only happen due to a mismatch between the bootloader which set
> + * up simplefb, and the regulator definitions in the device tree. Chances are
> + * that there are no adverse effects, and if there are, a clean teardown of
> + * the fb probe will not help us much either. So just complain and carry on,
> + * and hope that the user actually gets a working fb at the end of things.
> + */
> +static int simplefb_regulators_init(struct simplefb_par *par,
> +	struct platform_device *pdev)
> +{
> +	struct device_node *np = pdev->dev.of_node;
> +	struct property *prop;
> +	struct regulator *regulator;
> +	const char *p;
> +	int count = 0, i = 0, ret;
> +
> +	if (dev_get_platdata(&pdev->dev) || !np)
> +		return 0;
> +
> +	/* Count the number of regulator supplies */
> +	for_each_property_of_node(np, prop) {
> +		p = strstr(prop->name, SUPPLY_SUFFIX);
> +		if (p && p != prop->name)
> +			count++;
> +	}
> +
> +	if (!count)
> +		return 0;
> +
> +	par->regulators = devm_kcalloc(&pdev->dev, count,
> +				       sizeof(struct regulator *), GFP_KERNEL);
> +	if (!par->regulators)
> +		return -ENOMEM;
> +
> +	/* Get all the regulators */
> +	for_each_property_of_node(np, prop) {
> +		char name[32]; /* 32 is max size of property name */
> +
> +		p = strstr(prop->name, SUPPLY_SUFFIX);
> +		if (p && p != prop->name)
> +			continue;
> +
> +		strlcpy(name, prop->name,
> +			strlen(prop->name) - sizeof(SUPPLY_SUFFIX) + 1);
> +		regulator = devm_regulator_get_optional(&pdev->dev, name);
> +		if (IS_ERR(regulator)) {
> +			if (PTR_ERR(regulator) == -EPROBE_DEFER)
> +				return -EPROBE_DEFER;
> +			dev_err(&pdev->dev, "regulator %s not found: %ld\n",
> +				name, PTR_ERR(regulator));
> +			continue;
> +		}
> +		par->regulators[i++] = regulator;

So you only fill slots when the regulator_get has succeeded

> +	}
> +	par->regulator_count = i;

and regulator_count now is the amount of successfully gotten regulators
(which may be different from count).

> +
> +	/* Enable all the regulators */
> +	for (i = 0; i < par->regulator_count; i++) {
> +		if (par->regulators[i]) {

That means that this "if" is not necessary, it will always be true.

> +			ret = regulator_enable(par->regulators[i]);
> +			if (ret) {
> +				dev_err(&pdev->dev,
> +					"failed to enable regulator %d: %d\n",
> +					i, ret);
> +				devm_regulator_put(par->regulators[i]);
> +				par->regulators[i] = NULL;
> +			}
> +		}
> +	}
> +
> +	return 0;
> +}
> +
> +static void simplefb_regulators_destroy(struct simplefb_par *par)
> +{
> +	int i;
> +
> +	if (!par->regulators)
> +		return;
> +
> +	for (i = 0; i < par->regulator_count; i++)
> +		if (par->regulators[i])

And idem for this if.

Other then that this patch looks good and is:

Reviewed-by: Hans de Goede <hdegoede@redhat.com>

Regards,

Hans


> +			regulator_disable(par->regulators[i]);
> +}
> +#else
> +static int simplefb_regulators_init(struct simplefb_par *par,
> +	struct platform_device *pdev) { return 0; }
> +static void simplefb_regulators_destroy(struct simplefb_par *par) { }
> +#endif
> +
>   static int simplefb_probe(struct platform_device *pdev)
>   {
>   	int ret;
> @@ -340,6 +453,10 @@ static int simplefb_probe(struct platform_device *pdev)
>   	if (ret < 0)
>   		goto error_unmap;
>
> +	ret = simplefb_regulators_init(par, pdev);
> +	if (ret < 0)
> +		goto error_clocks;
> +
>   	dev_info(&pdev->dev, "framebuffer at 0x%lx, 0x%x bytes, mapped to 0x%p\n",
>   			     info->fix.smem_start, info->fix.smem_len,
>   			     info->screen_base);
> @@ -351,13 +468,15 @@ static int simplefb_probe(struct platform_device *pdev)
>   	ret = register_framebuffer(info);
>   	if (ret < 0) {
>   		dev_err(&pdev->dev, "Unable to register simplefb: %d\n", ret);
> -		goto error_clocks;
> +		goto error_regulators;
>   	}
>
>   	dev_info(&pdev->dev, "fb%d: simplefb registered!\n", info->node);
>
>   	return 0;
>
> +error_regulators:
> +	simplefb_regulators_destroy(par);
>   error_clocks:
>   	simplefb_clocks_destroy(par);
>   error_unmap:
> @@ -373,6 +492,7 @@ static int simplefb_remove(struct platform_device *pdev)
>   	struct simplefb_par *par = info->par;
>
>   	unregister_framebuffer(info);
> +	simplefb_regulators_destroy(par);
>   	simplefb_clocks_destroy(par);
>   	framebuffer_release(info);
>
>

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

* Re: [PATCH RFC v2 2/2] simplefb: Claim and enable regulators
@ 2015-10-21  7:54     ` Hans de Goede
  0 siblings, 0 replies; 28+ messages in thread
From: Hans de Goede @ 2015-10-21  7:54 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,

On 21-10-15 07:59, Chen-Yu Tsai wrote:
> This claims and enables regulators listed in the simple framebuffer dt
> node. This is needed so that regulators powering the display pipeline
> and external hardware, described in the device node and known by the
> kernel code, will remain properly enabled.
>
> Signed-off-by: Chen-Yu Tsai <wens@csie.org>
> ---
>   drivers/video/fbdev/simplefb.c | 122 ++++++++++++++++++++++++++++++++++++++++-
>   1 file changed, 121 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/video/fbdev/simplefb.c b/drivers/video/fbdev/simplefb.c
> index 52c5c7e63b52..c4ee10d83a70 100644
> --- a/drivers/video/fbdev/simplefb.c
> +++ b/drivers/video/fbdev/simplefb.c
> @@ -28,7 +28,10 @@
>   #include <linux/platform_device.h>
>   #include <linux/clk.h>
>   #include <linux/clk-provider.h>
> +#include <linux/of.h>
>   #include <linux/of_platform.h>
> +#include <linux/parser.h>
> +#include <linux/regulator/consumer.h>
>
>   static struct fb_fix_screeninfo simplefb_fix = {
>   	.id		= "simple",
> @@ -174,6 +177,10 @@ struct simplefb_par {
>   	int clk_count;
>   	struct clk **clks;
>   #endif
> +#if defined CONFIG_OF && defined CONFIG_REGULATOR
> +	u32 regulator_count;
> +	struct regulator **regulators;
> +#endif
>   };
>
>   #if defined CONFIG_OF && defined CONFIG_COMMON_CLK
> @@ -269,6 +276,112 @@ static int simplefb_clocks_init(struct simplefb_par *par,
>   static void simplefb_clocks_destroy(struct simplefb_par *par) { }
>   #endif
>
> +#if defined CONFIG_OF && defined CONFIG_REGULATOR
> +
> +#define SUPPLY_SUFFIX "-supply"
> +
> +/*
> + * Regulator handling code.
> + *
> + * Here we handle the num-supplies and vin*-supply properties of our
> + * "simple-framebuffer" dt node. This is necessary so that we can make sure
> + * that any regulators needed by the display hardware that the bootloader
> + * set up for us (and for which it provided a simplefb dt node), stay up,
> + * for the life of the simplefb driver.
> + *
> + * When the driver unloads, we cleanly disable, and then release the
> + * regulators.
> + *
> + * We only complain about errors here, no action is taken as the most likely
> + * error can only happen due to a mismatch between the bootloader which set
> + * up simplefb, and the regulator definitions in the device tree. Chances are
> + * that there are no adverse effects, and if there are, a clean teardown of
> + * the fb probe will not help us much either. So just complain and carry on,
> + * and hope that the user actually gets a working fb at the end of things.
> + */
> +static int simplefb_regulators_init(struct simplefb_par *par,
> +	struct platform_device *pdev)
> +{
> +	struct device_node *np = pdev->dev.of_node;
> +	struct property *prop;
> +	struct regulator *regulator;
> +	const char *p;
> +	int count = 0, i = 0, ret;
> +
> +	if (dev_get_platdata(&pdev->dev) || !np)
> +		return 0;
> +
> +	/* Count the number of regulator supplies */
> +	for_each_property_of_node(np, prop) {
> +		p = strstr(prop->name, SUPPLY_SUFFIX);
> +		if (p && p != prop->name)
> +			count++;
> +	}
> +
> +	if (!count)
> +		return 0;
> +
> +	par->regulators = devm_kcalloc(&pdev->dev, count,
> +				       sizeof(struct regulator *), GFP_KERNEL);
> +	if (!par->regulators)
> +		return -ENOMEM;
> +
> +	/* Get all the regulators */
> +	for_each_property_of_node(np, prop) {
> +		char name[32]; /* 32 is max size of property name */
> +
> +		p = strstr(prop->name, SUPPLY_SUFFIX);
> +		if (p && p != prop->name)
> +			continue;
> +
> +		strlcpy(name, prop->name,
> +			strlen(prop->name) - sizeof(SUPPLY_SUFFIX) + 1);
> +		regulator = devm_regulator_get_optional(&pdev->dev, name);
> +		if (IS_ERR(regulator)) {
> +			if (PTR_ERR(regulator) = -EPROBE_DEFER)
> +				return -EPROBE_DEFER;
> +			dev_err(&pdev->dev, "regulator %s not found: %ld\n",
> +				name, PTR_ERR(regulator));
> +			continue;
> +		}
> +		par->regulators[i++] = regulator;

So you only fill slots when the regulator_get has succeeded

> +	}
> +	par->regulator_count = i;

and regulator_count now is the amount of successfully gotten regulators
(which may be different from count).

> +
> +	/* Enable all the regulators */
> +	for (i = 0; i < par->regulator_count; i++) {
> +		if (par->regulators[i]) {

That means that this "if" is not necessary, it will always be true.

> +			ret = regulator_enable(par->regulators[i]);
> +			if (ret) {
> +				dev_err(&pdev->dev,
> +					"failed to enable regulator %d: %d\n",
> +					i, ret);
> +				devm_regulator_put(par->regulators[i]);
> +				par->regulators[i] = NULL;
> +			}
> +		}
> +	}
> +
> +	return 0;
> +}
> +
> +static void simplefb_regulators_destroy(struct simplefb_par *par)
> +{
> +	int i;
> +
> +	if (!par->regulators)
> +		return;
> +
> +	for (i = 0; i < par->regulator_count; i++)
> +		if (par->regulators[i])

And idem for this if.

Other then that this patch looks good and is:

Reviewed-by: Hans de Goede <hdegoede@redhat.com>

Regards,

Hans


> +			regulator_disable(par->regulators[i]);
> +}
> +#else
> +static int simplefb_regulators_init(struct simplefb_par *par,
> +	struct platform_device *pdev) { return 0; }
> +static void simplefb_regulators_destroy(struct simplefb_par *par) { }
> +#endif
> +
>   static int simplefb_probe(struct platform_device *pdev)
>   {
>   	int ret;
> @@ -340,6 +453,10 @@ static int simplefb_probe(struct platform_device *pdev)
>   	if (ret < 0)
>   		goto error_unmap;
>
> +	ret = simplefb_regulators_init(par, pdev);
> +	if (ret < 0)
> +		goto error_clocks;
> +
>   	dev_info(&pdev->dev, "framebuffer at 0x%lx, 0x%x bytes, mapped to 0x%p\n",
>   			     info->fix.smem_start, info->fix.smem_len,
>   			     info->screen_base);
> @@ -351,13 +468,15 @@ static int simplefb_probe(struct platform_device *pdev)
>   	ret = register_framebuffer(info);
>   	if (ret < 0) {
>   		dev_err(&pdev->dev, "Unable to register simplefb: %d\n", ret);
> -		goto error_clocks;
> +		goto error_regulators;
>   	}
>
>   	dev_info(&pdev->dev, "fb%d: simplefb registered!\n", info->node);
>
>   	return 0;
>
> +error_regulators:
> +	simplefb_regulators_destroy(par);
>   error_clocks:
>   	simplefb_clocks_destroy(par);
>   error_unmap:
> @@ -373,6 +492,7 @@ static int simplefb_remove(struct platform_device *pdev)
>   	struct simplefb_par *par = info->par;
>
>   	unregister_framebuffer(info);
> +	simplefb_regulators_destroy(par);
>   	simplefb_clocks_destroy(par);
>   	framebuffer_release(info);
>
>

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

* [PATCH RFC v2 2/2] simplefb: Claim and enable regulators
@ 2015-10-21  7:54     ` Hans de Goede
  0 siblings, 0 replies; 28+ messages in thread
From: Hans de Goede @ 2015-10-21  7:54 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,

On 21-10-15 07:59, Chen-Yu Tsai wrote:
> This claims and enables regulators listed in the simple framebuffer dt
> node. This is needed so that regulators powering the display pipeline
> and external hardware, described in the device node and known by the
> kernel code, will remain properly enabled.
>
> Signed-off-by: Chen-Yu Tsai <wens@csie.org>
> ---
>   drivers/video/fbdev/simplefb.c | 122 ++++++++++++++++++++++++++++++++++++++++-
>   1 file changed, 121 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/video/fbdev/simplefb.c b/drivers/video/fbdev/simplefb.c
> index 52c5c7e63b52..c4ee10d83a70 100644
> --- a/drivers/video/fbdev/simplefb.c
> +++ b/drivers/video/fbdev/simplefb.c
> @@ -28,7 +28,10 @@
>   #include <linux/platform_device.h>
>   #include <linux/clk.h>
>   #include <linux/clk-provider.h>
> +#include <linux/of.h>
>   #include <linux/of_platform.h>
> +#include <linux/parser.h>
> +#include <linux/regulator/consumer.h>
>
>   static struct fb_fix_screeninfo simplefb_fix = {
>   	.id		= "simple",
> @@ -174,6 +177,10 @@ struct simplefb_par {
>   	int clk_count;
>   	struct clk **clks;
>   #endif
> +#if defined CONFIG_OF && defined CONFIG_REGULATOR
> +	u32 regulator_count;
> +	struct regulator **regulators;
> +#endif
>   };
>
>   #if defined CONFIG_OF && defined CONFIG_COMMON_CLK
> @@ -269,6 +276,112 @@ static int simplefb_clocks_init(struct simplefb_par *par,
>   static void simplefb_clocks_destroy(struct simplefb_par *par) { }
>   #endif
>
> +#if defined CONFIG_OF && defined CONFIG_REGULATOR
> +
> +#define SUPPLY_SUFFIX "-supply"
> +
> +/*
> + * Regulator handling code.
> + *
> + * Here we handle the num-supplies and vin*-supply properties of our
> + * "simple-framebuffer" dt node. This is necessary so that we can make sure
> + * that any regulators needed by the display hardware that the bootloader
> + * set up for us (and for which it provided a simplefb dt node), stay up,
> + * for the life of the simplefb driver.
> + *
> + * When the driver unloads, we cleanly disable, and then release the
> + * regulators.
> + *
> + * We only complain about errors here, no action is taken as the most likely
> + * error can only happen due to a mismatch between the bootloader which set
> + * up simplefb, and the regulator definitions in the device tree. Chances are
> + * that there are no adverse effects, and if there are, a clean teardown of
> + * the fb probe will not help us much either. So just complain and carry on,
> + * and hope that the user actually gets a working fb at the end of things.
> + */
> +static int simplefb_regulators_init(struct simplefb_par *par,
> +	struct platform_device *pdev)
> +{
> +	struct device_node *np = pdev->dev.of_node;
> +	struct property *prop;
> +	struct regulator *regulator;
> +	const char *p;
> +	int count = 0, i = 0, ret;
> +
> +	if (dev_get_platdata(&pdev->dev) || !np)
> +		return 0;
> +
> +	/* Count the number of regulator supplies */
> +	for_each_property_of_node(np, prop) {
> +		p = strstr(prop->name, SUPPLY_SUFFIX);
> +		if (p && p != prop->name)
> +			count++;
> +	}
> +
> +	if (!count)
> +		return 0;
> +
> +	par->regulators = devm_kcalloc(&pdev->dev, count,
> +				       sizeof(struct regulator *), GFP_KERNEL);
> +	if (!par->regulators)
> +		return -ENOMEM;
> +
> +	/* Get all the regulators */
> +	for_each_property_of_node(np, prop) {
> +		char name[32]; /* 32 is max size of property name */
> +
> +		p = strstr(prop->name, SUPPLY_SUFFIX);
> +		if (p && p != prop->name)
> +			continue;
> +
> +		strlcpy(name, prop->name,
> +			strlen(prop->name) - sizeof(SUPPLY_SUFFIX) + 1);
> +		regulator = devm_regulator_get_optional(&pdev->dev, name);
> +		if (IS_ERR(regulator)) {
> +			if (PTR_ERR(regulator) == -EPROBE_DEFER)
> +				return -EPROBE_DEFER;
> +			dev_err(&pdev->dev, "regulator %s not found: %ld\n",
> +				name, PTR_ERR(regulator));
> +			continue;
> +		}
> +		par->regulators[i++] = regulator;

So you only fill slots when the regulator_get has succeeded

> +	}
> +	par->regulator_count = i;

and regulator_count now is the amount of successfully gotten regulators
(which may be different from count).

> +
> +	/* Enable all the regulators */
> +	for (i = 0; i < par->regulator_count; i++) {
> +		if (par->regulators[i]) {

That means that this "if" is not necessary, it will always be true.

> +			ret = regulator_enable(par->regulators[i]);
> +			if (ret) {
> +				dev_err(&pdev->dev,
> +					"failed to enable regulator %d: %d\n",
> +					i, ret);
> +				devm_regulator_put(par->regulators[i]);
> +				par->regulators[i] = NULL;
> +			}
> +		}
> +	}
> +
> +	return 0;
> +}
> +
> +static void simplefb_regulators_destroy(struct simplefb_par *par)
> +{
> +	int i;
> +
> +	if (!par->regulators)
> +		return;
> +
> +	for (i = 0; i < par->regulator_count; i++)
> +		if (par->regulators[i])

And idem for this if.

Other then that this patch looks good and is:

Reviewed-by: Hans de Goede <hdegoede@redhat.com>

Regards,

Hans


> +			regulator_disable(par->regulators[i]);
> +}
> +#else
> +static int simplefb_regulators_init(struct simplefb_par *par,
> +	struct platform_device *pdev) { return 0; }
> +static void simplefb_regulators_destroy(struct simplefb_par *par) { }
> +#endif
> +
>   static int simplefb_probe(struct platform_device *pdev)
>   {
>   	int ret;
> @@ -340,6 +453,10 @@ static int simplefb_probe(struct platform_device *pdev)
>   	if (ret < 0)
>   		goto error_unmap;
>
> +	ret = simplefb_regulators_init(par, pdev);
> +	if (ret < 0)
> +		goto error_clocks;
> +
>   	dev_info(&pdev->dev, "framebuffer at 0x%lx, 0x%x bytes, mapped to 0x%p\n",
>   			     info->fix.smem_start, info->fix.smem_len,
>   			     info->screen_base);
> @@ -351,13 +468,15 @@ static int simplefb_probe(struct platform_device *pdev)
>   	ret = register_framebuffer(info);
>   	if (ret < 0) {
>   		dev_err(&pdev->dev, "Unable to register simplefb: %d\n", ret);
> -		goto error_clocks;
> +		goto error_regulators;
>   	}
>
>   	dev_info(&pdev->dev, "fb%d: simplefb registered!\n", info->node);
>
>   	return 0;
>
> +error_regulators:
> +	simplefb_regulators_destroy(par);
>   error_clocks:
>   	simplefb_clocks_destroy(par);
>   error_unmap:
> @@ -373,6 +492,7 @@ static int simplefb_remove(struct platform_device *pdev)
>   	struct simplefb_par *par = info->par;
>
>   	unregister_framebuffer(info);
> +	simplefb_regulators_destroy(par);
>   	simplefb_clocks_destroy(par);
>   	framebuffer_release(info);
>
>

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

* Re: [PATCH RFC v2 2/2] simplefb: Claim and enable regulators
  2015-10-21  7:54     ` Hans de Goede
  (?)
@ 2015-10-21  8:04       ` Chen-Yu Tsai
  -1 siblings, 0 replies; 28+ messages in thread
From: Chen-Yu Tsai @ 2015-10-21  8:04 UTC (permalink / raw)
  To: Hans de Goede
  Cc: Chen-Yu Tsai, Jean-Christophe Plagniol-Villard, Tomi Valkeinen,
	Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala,
	linux-fbdev, devicetree, linux-kernel, linux-arm-kernel,
	Mark Brown

Hi,

On Wed, Oct 21, 2015 at 3:54 PM, Hans de Goede <hdegoede@redhat.com> wrote:
> Hi,
>
>
> On 21-10-15 07:59, Chen-Yu Tsai wrote:
>>
>> This claims and enables regulators listed in the simple framebuffer dt
>> node. This is needed so that regulators powering the display pipeline
>> and external hardware, described in the device node and known by the
>> kernel code, will remain properly enabled.
>>
>> Signed-off-by: Chen-Yu Tsai <wens@csie.org>
>> ---
>>   drivers/video/fbdev/simplefb.c | 122
>> ++++++++++++++++++++++++++++++++++++++++-
>>   1 file changed, 121 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/video/fbdev/simplefb.c
>> b/drivers/video/fbdev/simplefb.c
>> index 52c5c7e63b52..c4ee10d83a70 100644
>> --- a/drivers/video/fbdev/simplefb.c
>> +++ b/drivers/video/fbdev/simplefb.c
>> @@ -28,7 +28,10 @@
>>   #include <linux/platform_device.h>
>>   #include <linux/clk.h>
>>   #include <linux/clk-provider.h>
>> +#include <linux/of.h>
>>   #include <linux/of_platform.h>
>> +#include <linux/parser.h>
>> +#include <linux/regulator/consumer.h>
>>
>>   static struct fb_fix_screeninfo simplefb_fix = {
>>         .id             = "simple",
>> @@ -174,6 +177,10 @@ struct simplefb_par {
>>         int clk_count;
>>         struct clk **clks;
>>   #endif
>> +#if defined CONFIG_OF && defined CONFIG_REGULATOR
>> +       u32 regulator_count;
>> +       struct regulator **regulators;
>> +#endif
>>   };
>>
>>   #if defined CONFIG_OF && defined CONFIG_COMMON_CLK
>> @@ -269,6 +276,112 @@ static int simplefb_clocks_init(struct simplefb_par
>> *par,
>>   static void simplefb_clocks_destroy(struct simplefb_par *par) { }
>>   #endif
>>
>> +#if defined CONFIG_OF && defined CONFIG_REGULATOR
>> +
>> +#define SUPPLY_SUFFIX "-supply"
>> +
>> +/*
>> + * Regulator handling code.
>> + *
>> + * Here we handle the num-supplies and vin*-supply properties of our
>> + * "simple-framebuffer" dt node. This is necessary so that we can make
>> sure
>> + * that any regulators needed by the display hardware that the bootloader
>> + * set up for us (and for which it provided a simplefb dt node), stay up,
>> + * for the life of the simplefb driver.
>> + *
>> + * When the driver unloads, we cleanly disable, and then release the
>> + * regulators.
>> + *
>> + * We only complain about errors here, no action is taken as the most
>> likely
>> + * error can only happen due to a mismatch between the bootloader which
>> set
>> + * up simplefb, and the regulator definitions in the device tree. Chances
>> are
>> + * that there are no adverse effects, and if there are, a clean teardown
>> of
>> + * the fb probe will not help us much either. So just complain and carry
>> on,
>> + * and hope that the user actually gets a working fb at the end of
>> things.
>> + */
>> +static int simplefb_regulators_init(struct simplefb_par *par,
>> +       struct platform_device *pdev)
>> +{
>> +       struct device_node *np = pdev->dev.of_node;
>> +       struct property *prop;
>> +       struct regulator *regulator;
>> +       const char *p;
>> +       int count = 0, i = 0, ret;
>> +
>> +       if (dev_get_platdata(&pdev->dev) || !np)
>> +               return 0;
>> +
>> +       /* Count the number of regulator supplies */
>> +       for_each_property_of_node(np, prop) {
>> +               p = strstr(prop->name, SUPPLY_SUFFIX);
>> +               if (p && p != prop->name)
>> +                       count++;
>> +       }
>> +
>> +       if (!count)
>> +               return 0;
>> +
>> +       par->regulators = devm_kcalloc(&pdev->dev, count,
>> +                                      sizeof(struct regulator *),
>> GFP_KERNEL);
>> +       if (!par->regulators)
>> +               return -ENOMEM;
>> +
>> +       /* Get all the regulators */
>> +       for_each_property_of_node(np, prop) {
>> +               char name[32]; /* 32 is max size of property name */
>> +
>> +               p = strstr(prop->name, SUPPLY_SUFFIX);
>> +               if (p && p != prop->name)
>> +                       continue;
>> +
>> +               strlcpy(name, prop->name,
>> +                       strlen(prop->name) - sizeof(SUPPLY_SUFFIX) + 1);
>> +               regulator = devm_regulator_get_optional(&pdev->dev, name);
>> +               if (IS_ERR(regulator)) {
>> +                       if (PTR_ERR(regulator) == -EPROBE_DEFER)
>> +                               return -EPROBE_DEFER;
>> +                       dev_err(&pdev->dev, "regulator %s not found:
>> %ld\n",
>> +                               name, PTR_ERR(regulator));
>> +                       continue;
>> +               }
>> +               par->regulators[i++] = regulator;
>
>
> So you only fill slots when the regulator_get has succeeded
>
>> +       }
>> +       par->regulator_count = i;
>
>
> and regulator_count now is the amount of successfully gotten regulators
> (which may be different from count).
>
>> +
>> +       /* Enable all the regulators */
>> +       for (i = 0; i < par->regulator_count; i++) {
>> +               if (par->regulators[i]) {
>
>
> That means that this "if" is not necessary, it will always be true.

Right. This is leftover code from the first version. I'll remove it.

>> +                       ret = regulator_enable(par->regulators[i]);
>> +                       if (ret) {
>> +                               dev_err(&pdev->dev,
>> +                                       "failed to enable regulator %d:
>> %d\n",
>> +                                       i, ret);
>> +                               devm_regulator_put(par->regulators[i]);
>> +                               par->regulators[i] = NULL;

Note here.

>> +                       }
>> +               }
>> +       }
>> +
>> +       return 0;
>> +}
>> +
>> +static void simplefb_regulators_destroy(struct simplefb_par *par)
>> +{
>> +       int i;
>> +
>> +       if (!par->regulators)
>> +               return;
>> +
>> +       for (i = 0; i < par->regulator_count; i++)
>> +               if (par->regulators[i])
>
>
> And idem for this if.

This is still needed, since if we fail to enable any regulator, we just
ignore it, call regulator_put() on it, and forget about it (set the entry
to NULL). See the noted place above.

>
> Other then that this patch looks good and is:
>
> Reviewed-by: Hans de Goede <hdegoede@redhat.com>

Thanks. I'll wait a bit before sending the next version, in case Mark has
some comments on the regulator usage.


Regards
ChenYu

>> +                       regulator_disable(par->regulators[i]);
>> +}
>> +#else
>> +static int simplefb_regulators_init(struct simplefb_par *par,
>> +       struct platform_device *pdev) { return 0; }
>> +static void simplefb_regulators_destroy(struct simplefb_par *par) { }
>> +#endif
>> +
>>   static int simplefb_probe(struct platform_device *pdev)
>>   {
>>         int ret;
>> @@ -340,6 +453,10 @@ static int simplefb_probe(struct platform_device
>> *pdev)
>>         if (ret < 0)
>>                 goto error_unmap;
>>
>> +       ret = simplefb_regulators_init(par, pdev);
>> +       if (ret < 0)
>> +               goto error_clocks;
>> +
>>         dev_info(&pdev->dev, "framebuffer at 0x%lx, 0x%x bytes, mapped to
>> 0x%p\n",
>>                              info->fix.smem_start, info->fix.smem_len,
>>                              info->screen_base);
>> @@ -351,13 +468,15 @@ static int simplefb_probe(struct platform_device
>> *pdev)
>>         ret = register_framebuffer(info);
>>         if (ret < 0) {
>>                 dev_err(&pdev->dev, "Unable to register simplefb: %d\n",
>> ret);
>> -               goto error_clocks;
>> +               goto error_regulators;
>>         }
>>
>>         dev_info(&pdev->dev, "fb%d: simplefb registered!\n", info->node);
>>
>>         return 0;
>>
>> +error_regulators:
>> +       simplefb_regulators_destroy(par);
>>   error_clocks:
>>         simplefb_clocks_destroy(par);
>>   error_unmap:
>> @@ -373,6 +492,7 @@ static int simplefb_remove(struct platform_device
>> *pdev)
>>         struct simplefb_par *par = info->par;
>>
>>         unregister_framebuffer(info);
>> +       simplefb_regulators_destroy(par);
>>         simplefb_clocks_destroy(par);
>>         framebuffer_release(info);
>>
>>
>

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

* Re: [PATCH RFC v2 2/2] simplefb: Claim and enable regulators
@ 2015-10-21  8:04       ` Chen-Yu Tsai
  0 siblings, 0 replies; 28+ messages in thread
From: Chen-Yu Tsai @ 2015-10-21  8:04 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,

On Wed, Oct 21, 2015 at 3:54 PM, Hans de Goede <hdegoede@redhat.com> wrote:
> Hi,
>
>
> On 21-10-15 07:59, Chen-Yu Tsai wrote:
>>
>> This claims and enables regulators listed in the simple framebuffer dt
>> node. This is needed so that regulators powering the display pipeline
>> and external hardware, described in the device node and known by the
>> kernel code, will remain properly enabled.
>>
>> Signed-off-by: Chen-Yu Tsai <wens@csie.org>
>> ---
>>   drivers/video/fbdev/simplefb.c | 122
>> ++++++++++++++++++++++++++++++++++++++++-
>>   1 file changed, 121 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/video/fbdev/simplefb.c
>> b/drivers/video/fbdev/simplefb.c
>> index 52c5c7e63b52..c4ee10d83a70 100644
>> --- a/drivers/video/fbdev/simplefb.c
>> +++ b/drivers/video/fbdev/simplefb.c
>> @@ -28,7 +28,10 @@
>>   #include <linux/platform_device.h>
>>   #include <linux/clk.h>
>>   #include <linux/clk-provider.h>
>> +#include <linux/of.h>
>>   #include <linux/of_platform.h>
>> +#include <linux/parser.h>
>> +#include <linux/regulator/consumer.h>
>>
>>   static struct fb_fix_screeninfo simplefb_fix = {
>>         .id             = "simple",
>> @@ -174,6 +177,10 @@ struct simplefb_par {
>>         int clk_count;
>>         struct clk **clks;
>>   #endif
>> +#if defined CONFIG_OF && defined CONFIG_REGULATOR
>> +       u32 regulator_count;
>> +       struct regulator **regulators;
>> +#endif
>>   };
>>
>>   #if defined CONFIG_OF && defined CONFIG_COMMON_CLK
>> @@ -269,6 +276,112 @@ static int simplefb_clocks_init(struct simplefb_par
>> *par,
>>   static void simplefb_clocks_destroy(struct simplefb_par *par) { }
>>   #endif
>>
>> +#if defined CONFIG_OF && defined CONFIG_REGULATOR
>> +
>> +#define SUPPLY_SUFFIX "-supply"
>> +
>> +/*
>> + * Regulator handling code.
>> + *
>> + * Here we handle the num-supplies and vin*-supply properties of our
>> + * "simple-framebuffer" dt node. This is necessary so that we can make
>> sure
>> + * that any regulators needed by the display hardware that the bootloader
>> + * set up for us (and for which it provided a simplefb dt node), stay up,
>> + * for the life of the simplefb driver.
>> + *
>> + * When the driver unloads, we cleanly disable, and then release the
>> + * regulators.
>> + *
>> + * We only complain about errors here, no action is taken as the most
>> likely
>> + * error can only happen due to a mismatch between the bootloader which
>> set
>> + * up simplefb, and the regulator definitions in the device tree. Chances
>> are
>> + * that there are no adverse effects, and if there are, a clean teardown
>> of
>> + * the fb probe will not help us much either. So just complain and carry
>> on,
>> + * and hope that the user actually gets a working fb at the end of
>> things.
>> + */
>> +static int simplefb_regulators_init(struct simplefb_par *par,
>> +       struct platform_device *pdev)
>> +{
>> +       struct device_node *np = pdev->dev.of_node;
>> +       struct property *prop;
>> +       struct regulator *regulator;
>> +       const char *p;
>> +       int count = 0, i = 0, ret;
>> +
>> +       if (dev_get_platdata(&pdev->dev) || !np)
>> +               return 0;
>> +
>> +       /* Count the number of regulator supplies */
>> +       for_each_property_of_node(np, prop) {
>> +               p = strstr(prop->name, SUPPLY_SUFFIX);
>> +               if (p && p != prop->name)
>> +                       count++;
>> +       }
>> +
>> +       if (!count)
>> +               return 0;
>> +
>> +       par->regulators = devm_kcalloc(&pdev->dev, count,
>> +                                      sizeof(struct regulator *),
>> GFP_KERNEL);
>> +       if (!par->regulators)
>> +               return -ENOMEM;
>> +
>> +       /* Get all the regulators */
>> +       for_each_property_of_node(np, prop) {
>> +               char name[32]; /* 32 is max size of property name */
>> +
>> +               p = strstr(prop->name, SUPPLY_SUFFIX);
>> +               if (p && p != prop->name)
>> +                       continue;
>> +
>> +               strlcpy(name, prop->name,
>> +                       strlen(prop->name) - sizeof(SUPPLY_SUFFIX) + 1);
>> +               regulator = devm_regulator_get_optional(&pdev->dev, name);
>> +               if (IS_ERR(regulator)) {
>> +                       if (PTR_ERR(regulator) = -EPROBE_DEFER)
>> +                               return -EPROBE_DEFER;
>> +                       dev_err(&pdev->dev, "regulator %s not found:
>> %ld\n",
>> +                               name, PTR_ERR(regulator));
>> +                       continue;
>> +               }
>> +               par->regulators[i++] = regulator;
>
>
> So you only fill slots when the regulator_get has succeeded
>
>> +       }
>> +       par->regulator_count = i;
>
>
> and regulator_count now is the amount of successfully gotten regulators
> (which may be different from count).
>
>> +
>> +       /* Enable all the regulators */
>> +       for (i = 0; i < par->regulator_count; i++) {
>> +               if (par->regulators[i]) {
>
>
> That means that this "if" is not necessary, it will always be true.

Right. This is leftover code from the first version. I'll remove it.

>> +                       ret = regulator_enable(par->regulators[i]);
>> +                       if (ret) {
>> +                               dev_err(&pdev->dev,
>> +                                       "failed to enable regulator %d:
>> %d\n",
>> +                                       i, ret);
>> +                               devm_regulator_put(par->regulators[i]);
>> +                               par->regulators[i] = NULL;

Note here.

>> +                       }
>> +               }
>> +       }
>> +
>> +       return 0;
>> +}
>> +
>> +static void simplefb_regulators_destroy(struct simplefb_par *par)
>> +{
>> +       int i;
>> +
>> +       if (!par->regulators)
>> +               return;
>> +
>> +       for (i = 0; i < par->regulator_count; i++)
>> +               if (par->regulators[i])
>
>
> And idem for this if.

This is still needed, since if we fail to enable any regulator, we just
ignore it, call regulator_put() on it, and forget about it (set the entry
to NULL). See the noted place above.

>
> Other then that this patch looks good and is:
>
> Reviewed-by: Hans de Goede <hdegoede@redhat.com>

Thanks. I'll wait a bit before sending the next version, in case Mark has
some comments on the regulator usage.


Regards
ChenYu

>> +                       regulator_disable(par->regulators[i]);
>> +}
>> +#else
>> +static int simplefb_regulators_init(struct simplefb_par *par,
>> +       struct platform_device *pdev) { return 0; }
>> +static void simplefb_regulators_destroy(struct simplefb_par *par) { }
>> +#endif
>> +
>>   static int simplefb_probe(struct platform_device *pdev)
>>   {
>>         int ret;
>> @@ -340,6 +453,10 @@ static int simplefb_probe(struct platform_device
>> *pdev)
>>         if (ret < 0)
>>                 goto error_unmap;
>>
>> +       ret = simplefb_regulators_init(par, pdev);
>> +       if (ret < 0)
>> +               goto error_clocks;
>> +
>>         dev_info(&pdev->dev, "framebuffer at 0x%lx, 0x%x bytes, mapped to
>> 0x%p\n",
>>                              info->fix.smem_start, info->fix.smem_len,
>>                              info->screen_base);
>> @@ -351,13 +468,15 @@ static int simplefb_probe(struct platform_device
>> *pdev)
>>         ret = register_framebuffer(info);
>>         if (ret < 0) {
>>                 dev_err(&pdev->dev, "Unable to register simplefb: %d\n",
>> ret);
>> -               goto error_clocks;
>> +               goto error_regulators;
>>         }
>>
>>         dev_info(&pdev->dev, "fb%d: simplefb registered!\n", info->node);
>>
>>         return 0;
>>
>> +error_regulators:
>> +       simplefb_regulators_destroy(par);
>>   error_clocks:
>>         simplefb_clocks_destroy(par);
>>   error_unmap:
>> @@ -373,6 +492,7 @@ static int simplefb_remove(struct platform_device
>> *pdev)
>>         struct simplefb_par *par = info->par;
>>
>>         unregister_framebuffer(info);
>> +       simplefb_regulators_destroy(par);
>>         simplefb_clocks_destroy(par);
>>         framebuffer_release(info);
>>
>>
>

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

* [PATCH RFC v2 2/2] simplefb: Claim and enable regulators
@ 2015-10-21  8:04       ` Chen-Yu Tsai
  0 siblings, 0 replies; 28+ messages in thread
From: Chen-Yu Tsai @ 2015-10-21  8:04 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,

On Wed, Oct 21, 2015 at 3:54 PM, Hans de Goede <hdegoede@redhat.com> wrote:
> Hi,
>
>
> On 21-10-15 07:59, Chen-Yu Tsai wrote:
>>
>> This claims and enables regulators listed in the simple framebuffer dt
>> node. This is needed so that regulators powering the display pipeline
>> and external hardware, described in the device node and known by the
>> kernel code, will remain properly enabled.
>>
>> Signed-off-by: Chen-Yu Tsai <wens@csie.org>
>> ---
>>   drivers/video/fbdev/simplefb.c | 122
>> ++++++++++++++++++++++++++++++++++++++++-
>>   1 file changed, 121 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/video/fbdev/simplefb.c
>> b/drivers/video/fbdev/simplefb.c
>> index 52c5c7e63b52..c4ee10d83a70 100644
>> --- a/drivers/video/fbdev/simplefb.c
>> +++ b/drivers/video/fbdev/simplefb.c
>> @@ -28,7 +28,10 @@
>>   #include <linux/platform_device.h>
>>   #include <linux/clk.h>
>>   #include <linux/clk-provider.h>
>> +#include <linux/of.h>
>>   #include <linux/of_platform.h>
>> +#include <linux/parser.h>
>> +#include <linux/regulator/consumer.h>
>>
>>   static struct fb_fix_screeninfo simplefb_fix = {
>>         .id             = "simple",
>> @@ -174,6 +177,10 @@ struct simplefb_par {
>>         int clk_count;
>>         struct clk **clks;
>>   #endif
>> +#if defined CONFIG_OF && defined CONFIG_REGULATOR
>> +       u32 regulator_count;
>> +       struct regulator **regulators;
>> +#endif
>>   };
>>
>>   #if defined CONFIG_OF && defined CONFIG_COMMON_CLK
>> @@ -269,6 +276,112 @@ static int simplefb_clocks_init(struct simplefb_par
>> *par,
>>   static void simplefb_clocks_destroy(struct simplefb_par *par) { }
>>   #endif
>>
>> +#if defined CONFIG_OF && defined CONFIG_REGULATOR
>> +
>> +#define SUPPLY_SUFFIX "-supply"
>> +
>> +/*
>> + * Regulator handling code.
>> + *
>> + * Here we handle the num-supplies and vin*-supply properties of our
>> + * "simple-framebuffer" dt node. This is necessary so that we can make
>> sure
>> + * that any regulators needed by the display hardware that the bootloader
>> + * set up for us (and for which it provided a simplefb dt node), stay up,
>> + * for the life of the simplefb driver.
>> + *
>> + * When the driver unloads, we cleanly disable, and then release the
>> + * regulators.
>> + *
>> + * We only complain about errors here, no action is taken as the most
>> likely
>> + * error can only happen due to a mismatch between the bootloader which
>> set
>> + * up simplefb, and the regulator definitions in the device tree. Chances
>> are
>> + * that there are no adverse effects, and if there are, a clean teardown
>> of
>> + * the fb probe will not help us much either. So just complain and carry
>> on,
>> + * and hope that the user actually gets a working fb at the end of
>> things.
>> + */
>> +static int simplefb_regulators_init(struct simplefb_par *par,
>> +       struct platform_device *pdev)
>> +{
>> +       struct device_node *np = pdev->dev.of_node;
>> +       struct property *prop;
>> +       struct regulator *regulator;
>> +       const char *p;
>> +       int count = 0, i = 0, ret;
>> +
>> +       if (dev_get_platdata(&pdev->dev) || !np)
>> +               return 0;
>> +
>> +       /* Count the number of regulator supplies */
>> +       for_each_property_of_node(np, prop) {
>> +               p = strstr(prop->name, SUPPLY_SUFFIX);
>> +               if (p && p != prop->name)
>> +                       count++;
>> +       }
>> +
>> +       if (!count)
>> +               return 0;
>> +
>> +       par->regulators = devm_kcalloc(&pdev->dev, count,
>> +                                      sizeof(struct regulator *),
>> GFP_KERNEL);
>> +       if (!par->regulators)
>> +               return -ENOMEM;
>> +
>> +       /* Get all the regulators */
>> +       for_each_property_of_node(np, prop) {
>> +               char name[32]; /* 32 is max size of property name */
>> +
>> +               p = strstr(prop->name, SUPPLY_SUFFIX);
>> +               if (p && p != prop->name)
>> +                       continue;
>> +
>> +               strlcpy(name, prop->name,
>> +                       strlen(prop->name) - sizeof(SUPPLY_SUFFIX) + 1);
>> +               regulator = devm_regulator_get_optional(&pdev->dev, name);
>> +               if (IS_ERR(regulator)) {
>> +                       if (PTR_ERR(regulator) == -EPROBE_DEFER)
>> +                               return -EPROBE_DEFER;
>> +                       dev_err(&pdev->dev, "regulator %s not found:
>> %ld\n",
>> +                               name, PTR_ERR(regulator));
>> +                       continue;
>> +               }
>> +               par->regulators[i++] = regulator;
>
>
> So you only fill slots when the regulator_get has succeeded
>
>> +       }
>> +       par->regulator_count = i;
>
>
> and regulator_count now is the amount of successfully gotten regulators
> (which may be different from count).
>
>> +
>> +       /* Enable all the regulators */
>> +       for (i = 0; i < par->regulator_count; i++) {
>> +               if (par->regulators[i]) {
>
>
> That means that this "if" is not necessary, it will always be true.

Right. This is leftover code from the first version. I'll remove it.

>> +                       ret = regulator_enable(par->regulators[i]);
>> +                       if (ret) {
>> +                               dev_err(&pdev->dev,
>> +                                       "failed to enable regulator %d:
>> %d\n",
>> +                                       i, ret);
>> +                               devm_regulator_put(par->regulators[i]);
>> +                               par->regulators[i] = NULL;

Note here.

>> +                       }
>> +               }
>> +       }
>> +
>> +       return 0;
>> +}
>> +
>> +static void simplefb_regulators_destroy(struct simplefb_par *par)
>> +{
>> +       int i;
>> +
>> +       if (!par->regulators)
>> +               return;
>> +
>> +       for (i = 0; i < par->regulator_count; i++)
>> +               if (par->regulators[i])
>
>
> And idem for this if.

This is still needed, since if we fail to enable any regulator, we just
ignore it, call regulator_put() on it, and forget about it (set the entry
to NULL). See the noted place above.

>
> Other then that this patch looks good and is:
>
> Reviewed-by: Hans de Goede <hdegoede@redhat.com>

Thanks. I'll wait a bit before sending the next version, in case Mark has
some comments on the regulator usage.


Regards
ChenYu

>> +                       regulator_disable(par->regulators[i]);
>> +}
>> +#else
>> +static int simplefb_regulators_init(struct simplefb_par *par,
>> +       struct platform_device *pdev) { return 0; }
>> +static void simplefb_regulators_destroy(struct simplefb_par *par) { }
>> +#endif
>> +
>>   static int simplefb_probe(struct platform_device *pdev)
>>   {
>>         int ret;
>> @@ -340,6 +453,10 @@ static int simplefb_probe(struct platform_device
>> *pdev)
>>         if (ret < 0)
>>                 goto error_unmap;
>>
>> +       ret = simplefb_regulators_init(par, pdev);
>> +       if (ret < 0)
>> +               goto error_clocks;
>> +
>>         dev_info(&pdev->dev, "framebuffer at 0x%lx, 0x%x bytes, mapped to
>> 0x%p\n",
>>                              info->fix.smem_start, info->fix.smem_len,
>>                              info->screen_base);
>> @@ -351,13 +468,15 @@ static int simplefb_probe(struct platform_device
>> *pdev)
>>         ret = register_framebuffer(info);
>>         if (ret < 0) {
>>                 dev_err(&pdev->dev, "Unable to register simplefb: %d\n",
>> ret);
>> -               goto error_clocks;
>> +               goto error_regulators;
>>         }
>>
>>         dev_info(&pdev->dev, "fb%d: simplefb registered!\n", info->node);
>>
>>         return 0;
>>
>> +error_regulators:
>> +       simplefb_regulators_destroy(par);
>>   error_clocks:
>>         simplefb_clocks_destroy(par);
>>   error_unmap:
>> @@ -373,6 +492,7 @@ static int simplefb_remove(struct platform_device
>> *pdev)
>>         struct simplefb_par *par = info->par;
>>
>>         unregister_framebuffer(info);
>> +       simplefb_regulators_destroy(par);
>>         simplefb_clocks_destroy(par);
>>         framebuffer_release(info);
>>
>>
>

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

* Re: [PATCH RFC v2 2/2] simplefb: Claim and enable regulators
  2015-10-21  8:04       ` Chen-Yu Tsai
  (?)
  (?)
@ 2015-10-21  8:09         ` Hans de Goede
  -1 siblings, 0 replies; 28+ messages in thread
From: Hans de Goede @ 2015-10-21  8:09 UTC (permalink / raw)
  To: Chen-Yu Tsai
  Cc: Jean-Christophe Plagniol-Villard, Tomi Valkeinen, Rob Herring,
	Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, linux-fbdev,
	devicetree, linux-kernel, linux-arm-kernel, Mark Brown

Hi,

On 21-10-15 10:04, Chen-Yu Tsai wrote:
> Hi,
>
> On Wed, Oct 21, 2015 at 3:54 PM, Hans de Goede <hdegoede@redhat.com> wrote:
>> Hi,
>>
>>
>> On 21-10-15 07:59, Chen-Yu Tsai wrote:
>>>
>>> This claims and enables regulators listed in the simple framebuffer dt
>>> node. This is needed so that regulators powering the display pipeline
>>> and external hardware, described in the device node and known by the
>>> kernel code, will remain properly enabled.
>>>
>>> Signed-off-by: Chen-Yu Tsai <wens@csie.org>
>>> ---
>>>    drivers/video/fbdev/simplefb.c | 122
>>> ++++++++++++++++++++++++++++++++++++++++-
>>>    1 file changed, 121 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/video/fbdev/simplefb.c
>>> b/drivers/video/fbdev/simplefb.c
>>> index 52c5c7e63b52..c4ee10d83a70 100644
>>> --- a/drivers/video/fbdev/simplefb.c
>>> +++ b/drivers/video/fbdev/simplefb.c
>>> @@ -28,7 +28,10 @@
>>>    #include <linux/platform_device.h>
>>>    #include <linux/clk.h>
>>>    #include <linux/clk-provider.h>
>>> +#include <linux/of.h>
>>>    #include <linux/of_platform.h>
>>> +#include <linux/parser.h>
>>> +#include <linux/regulator/consumer.h>
>>>
>>>    static struct fb_fix_screeninfo simplefb_fix = {
>>>          .id             = "simple",
>>> @@ -174,6 +177,10 @@ struct simplefb_par {
>>>          int clk_count;
>>>          struct clk **clks;
>>>    #endif
>>> +#if defined CONFIG_OF && defined CONFIG_REGULATOR
>>> +       u32 regulator_count;
>>> +       struct regulator **regulators;
>>> +#endif
>>>    };
>>>
>>>    #if defined CONFIG_OF && defined CONFIG_COMMON_CLK
>>> @@ -269,6 +276,112 @@ static int simplefb_clocks_init(struct simplefb_par
>>> *par,
>>>    static void simplefb_clocks_destroy(struct simplefb_par *par) { }
>>>    #endif
>>>
>>> +#if defined CONFIG_OF && defined CONFIG_REGULATOR
>>> +
>>> +#define SUPPLY_SUFFIX "-supply"
>>> +
>>> +/*
>>> + * Regulator handling code.
>>> + *
>>> + * Here we handle the num-supplies and vin*-supply properties of our
>>> + * "simple-framebuffer" dt node. This is necessary so that we can make
>>> sure
>>> + * that any regulators needed by the display hardware that the bootloader
>>> + * set up for us (and for which it provided a simplefb dt node), stay up,
>>> + * for the life of the simplefb driver.
>>> + *
>>> + * When the driver unloads, we cleanly disable, and then release the
>>> + * regulators.
>>> + *
>>> + * We only complain about errors here, no action is taken as the most
>>> likely
>>> + * error can only happen due to a mismatch between the bootloader which
>>> set
>>> + * up simplefb, and the regulator definitions in the device tree. Chances
>>> are
>>> + * that there are no adverse effects, and if there are, a clean teardown
>>> of
>>> + * the fb probe will not help us much either. So just complain and carry
>>> on,
>>> + * and hope that the user actually gets a working fb at the end of
>>> things.
>>> + */
>>> +static int simplefb_regulators_init(struct simplefb_par *par,
>>> +       struct platform_device *pdev)
>>> +{
>>> +       struct device_node *np = pdev->dev.of_node;
>>> +       struct property *prop;
>>> +       struct regulator *regulator;
>>> +       const char *p;
>>> +       int count = 0, i = 0, ret;
>>> +
>>> +       if (dev_get_platdata(&pdev->dev) || !np)
>>> +               return 0;
>>> +
>>> +       /* Count the number of regulator supplies */
>>> +       for_each_property_of_node(np, prop) {
>>> +               p = strstr(prop->name, SUPPLY_SUFFIX);
>>> +               if (p && p != prop->name)
>>> +                       count++;
>>> +       }
>>> +
>>> +       if (!count)
>>> +               return 0;
>>> +
>>> +       par->regulators = devm_kcalloc(&pdev->dev, count,
>>> +                                      sizeof(struct regulator *),
>>> GFP_KERNEL);
>>> +       if (!par->regulators)
>>> +               return -ENOMEM;
>>> +
>>> +       /* Get all the regulators */
>>> +       for_each_property_of_node(np, prop) {
>>> +               char name[32]; /* 32 is max size of property name */
>>> +
>>> +               p = strstr(prop->name, SUPPLY_SUFFIX);
>>> +               if (p && p != prop->name)
>>> +                       continue;
>>> +
>>> +               strlcpy(name, prop->name,
>>> +                       strlen(prop->name) - sizeof(SUPPLY_SUFFIX) + 1);
>>> +               regulator = devm_regulator_get_optional(&pdev->dev, name);
>>> +               if (IS_ERR(regulator)) {
>>> +                       if (PTR_ERR(regulator) == -EPROBE_DEFER)
>>> +                               return -EPROBE_DEFER;
>>> +                       dev_err(&pdev->dev, "regulator %s not found:
>>> %ld\n",
>>> +                               name, PTR_ERR(regulator));
>>> +                       continue;
>>> +               }
>>> +               par->regulators[i++] = regulator;
>>
>>
>> So you only fill slots when the regulator_get has succeeded
>>
>>> +       }
>>> +       par->regulator_count = i;
>>
>>
>> and regulator_count now is the amount of successfully gotten regulators
>> (which may be different from count).
>>
>>> +
>>> +       /* Enable all the regulators */
>>> +       for (i = 0; i < par->regulator_count; i++) {
>>> +               if (par->regulators[i]) {
>>
>>
>> That means that this "if" is not necessary, it will always be true.
>
> Right. This is leftover code from the first version. I'll remove it.
>
>>> +                       ret = regulator_enable(par->regulators[i]);
>>> +                       if (ret) {
>>> +                               dev_err(&pdev->dev,
>>> +                                       "failed to enable regulator %d:
>>> %d\n",
>>> +                                       i, ret);
>>> +                               devm_regulator_put(par->regulators[i]);
>>> +                               par->regulators[i] = NULL;
>
> Note here.
>
>>> +                       }
>>> +               }
>>> +       }
>>> +
>>> +       return 0;
>>> +}
>>> +
>>> +static void simplefb_regulators_destroy(struct simplefb_par *par)
>>> +{
>>> +       int i;
>>> +
>>> +       if (!par->regulators)
>>> +               return;
>>> +
>>> +       for (i = 0; i < par->regulator_count; i++)
>>> +               if (par->regulators[i])
>>
>>
>> And idem for this if.
>
> This is still needed, since if we fail to enable any regulator, we just
> ignore it, call regulator_put() on it, and forget about it (set the entry
> to NULL). See the noted place above.

Ah right, ok lets keep that in then :)

Regards,

Hans

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

* Re: [PATCH RFC v2 2/2] simplefb: Claim and enable regulators
@ 2015-10-21  8:09         ` Hans de Goede
  0 siblings, 0 replies; 28+ messages in thread
From: Hans de Goede @ 2015-10-21  8:09 UTC (permalink / raw)
  To: Chen-Yu Tsai
  Cc: Mark Rutland, devicetree, linux-fbdev, Pawel Moll, Ian Campbell,
	Mark Brown, linux-kernel, Rob Herring, Tomi Valkeinen,
	Kumar Gala, Jean-Christophe Plagniol-Villard, linux-arm-kernel

Hi,

On 21-10-15 10:04, Chen-Yu Tsai wrote:
> Hi,
>
> On Wed, Oct 21, 2015 at 3:54 PM, Hans de Goede <hdegoede@redhat.com> wrote:
>> Hi,
>>
>>
>> On 21-10-15 07:59, Chen-Yu Tsai wrote:
>>>
>>> This claims and enables regulators listed in the simple framebuffer dt
>>> node. This is needed so that regulators powering the display pipeline
>>> and external hardware, described in the device node and known by the
>>> kernel code, will remain properly enabled.
>>>
>>> Signed-off-by: Chen-Yu Tsai <wens@csie.org>
>>> ---
>>>    drivers/video/fbdev/simplefb.c | 122
>>> ++++++++++++++++++++++++++++++++++++++++-
>>>    1 file changed, 121 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/video/fbdev/simplefb.c
>>> b/drivers/video/fbdev/simplefb.c
>>> index 52c5c7e63b52..c4ee10d83a70 100644
>>> --- a/drivers/video/fbdev/simplefb.c
>>> +++ b/drivers/video/fbdev/simplefb.c
>>> @@ -28,7 +28,10 @@
>>>    #include <linux/platform_device.h>
>>>    #include <linux/clk.h>
>>>    #include <linux/clk-provider.h>
>>> +#include <linux/of.h>
>>>    #include <linux/of_platform.h>
>>> +#include <linux/parser.h>
>>> +#include <linux/regulator/consumer.h>
>>>
>>>    static struct fb_fix_screeninfo simplefb_fix = {
>>>          .id             = "simple",
>>> @@ -174,6 +177,10 @@ struct simplefb_par {
>>>          int clk_count;
>>>          struct clk **clks;
>>>    #endif
>>> +#if defined CONFIG_OF && defined CONFIG_REGULATOR
>>> +       u32 regulator_count;
>>> +       struct regulator **regulators;
>>> +#endif
>>>    };
>>>
>>>    #if defined CONFIG_OF && defined CONFIG_COMMON_CLK
>>> @@ -269,6 +276,112 @@ static int simplefb_clocks_init(struct simplefb_par
>>> *par,
>>>    static void simplefb_clocks_destroy(struct simplefb_par *par) { }
>>>    #endif
>>>
>>> +#if defined CONFIG_OF && defined CONFIG_REGULATOR
>>> +
>>> +#define SUPPLY_SUFFIX "-supply"
>>> +
>>> +/*
>>> + * Regulator handling code.
>>> + *
>>> + * Here we handle the num-supplies and vin*-supply properties of our
>>> + * "simple-framebuffer" dt node. This is necessary so that we can make
>>> sure
>>> + * that any regulators needed by the display hardware that the bootloader
>>> + * set up for us (and for which it provided a simplefb dt node), stay up,
>>> + * for the life of the simplefb driver.
>>> + *
>>> + * When the driver unloads, we cleanly disable, and then release the
>>> + * regulators.
>>> + *
>>> + * We only complain about errors here, no action is taken as the most
>>> likely
>>> + * error can only happen due to a mismatch between the bootloader which
>>> set
>>> + * up simplefb, and the regulator definitions in the device tree. Chances
>>> are
>>> + * that there are no adverse effects, and if there are, a clean teardown
>>> of
>>> + * the fb probe will not help us much either. So just complain and carry
>>> on,
>>> + * and hope that the user actually gets a working fb at the end of
>>> things.
>>> + */
>>> +static int simplefb_regulators_init(struct simplefb_par *par,
>>> +       struct platform_device *pdev)
>>> +{
>>> +       struct device_node *np = pdev->dev.of_node;
>>> +       struct property *prop;
>>> +       struct regulator *regulator;
>>> +       const char *p;
>>> +       int count = 0, i = 0, ret;
>>> +
>>> +       if (dev_get_platdata(&pdev->dev) || !np)
>>> +               return 0;
>>> +
>>> +       /* Count the number of regulator supplies */
>>> +       for_each_property_of_node(np, prop) {
>>> +               p = strstr(prop->name, SUPPLY_SUFFIX);
>>> +               if (p && p != prop->name)
>>> +                       count++;
>>> +       }
>>> +
>>> +       if (!count)
>>> +               return 0;
>>> +
>>> +       par->regulators = devm_kcalloc(&pdev->dev, count,
>>> +                                      sizeof(struct regulator *),
>>> GFP_KERNEL);
>>> +       if (!par->regulators)
>>> +               return -ENOMEM;
>>> +
>>> +       /* Get all the regulators */
>>> +       for_each_property_of_node(np, prop) {
>>> +               char name[32]; /* 32 is max size of property name */
>>> +
>>> +               p = strstr(prop->name, SUPPLY_SUFFIX);
>>> +               if (p && p != prop->name)
>>> +                       continue;
>>> +
>>> +               strlcpy(name, prop->name,
>>> +                       strlen(prop->name) - sizeof(SUPPLY_SUFFIX) + 1);
>>> +               regulator = devm_regulator_get_optional(&pdev->dev, name);
>>> +               if (IS_ERR(regulator)) {
>>> +                       if (PTR_ERR(regulator) == -EPROBE_DEFER)
>>> +                               return -EPROBE_DEFER;
>>> +                       dev_err(&pdev->dev, "regulator %s not found:
>>> %ld\n",
>>> +                               name, PTR_ERR(regulator));
>>> +                       continue;
>>> +               }
>>> +               par->regulators[i++] = regulator;
>>
>>
>> So you only fill slots when the regulator_get has succeeded
>>
>>> +       }
>>> +       par->regulator_count = i;
>>
>>
>> and regulator_count now is the amount of successfully gotten regulators
>> (which may be different from count).
>>
>>> +
>>> +       /* Enable all the regulators */
>>> +       for (i = 0; i < par->regulator_count; i++) {
>>> +               if (par->regulators[i]) {
>>
>>
>> That means that this "if" is not necessary, it will always be true.
>
> Right. This is leftover code from the first version. I'll remove it.
>
>>> +                       ret = regulator_enable(par->regulators[i]);
>>> +                       if (ret) {
>>> +                               dev_err(&pdev->dev,
>>> +                                       "failed to enable regulator %d:
>>> %d\n",
>>> +                                       i, ret);
>>> +                               devm_regulator_put(par->regulators[i]);
>>> +                               par->regulators[i] = NULL;
>
> Note here.
>
>>> +                       }
>>> +               }
>>> +       }
>>> +
>>> +       return 0;
>>> +}
>>> +
>>> +static void simplefb_regulators_destroy(struct simplefb_par *par)
>>> +{
>>> +       int i;
>>> +
>>> +       if (!par->regulators)
>>> +               return;
>>> +
>>> +       for (i = 0; i < par->regulator_count; i++)
>>> +               if (par->regulators[i])
>>
>>
>> And idem for this if.
>
> This is still needed, since if we fail to enable any regulator, we just
> ignore it, call regulator_put() on it, and forget about it (set the entry
> to NULL). See the noted place above.

Ah right, ok lets keep that in then :)

Regards,

Hans

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

* Re: [PATCH RFC v2 2/2] simplefb: Claim and enable regulators
@ 2015-10-21  8:09         ` Hans de Goede
  0 siblings, 0 replies; 28+ messages in thread
From: Hans de Goede @ 2015-10-21  8:09 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,

On 21-10-15 10:04, Chen-Yu Tsai wrote:
> Hi,
>
> On Wed, Oct 21, 2015 at 3:54 PM, Hans de Goede <hdegoede@redhat.com> wrote:
>> Hi,
>>
>>
>> On 21-10-15 07:59, Chen-Yu Tsai wrote:
>>>
>>> This claims and enables regulators listed in the simple framebuffer dt
>>> node. This is needed so that regulators powering the display pipeline
>>> and external hardware, described in the device node and known by the
>>> kernel code, will remain properly enabled.
>>>
>>> Signed-off-by: Chen-Yu Tsai <wens@csie.org>
>>> ---
>>>    drivers/video/fbdev/simplefb.c | 122
>>> ++++++++++++++++++++++++++++++++++++++++-
>>>    1 file changed, 121 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/video/fbdev/simplefb.c
>>> b/drivers/video/fbdev/simplefb.c
>>> index 52c5c7e63b52..c4ee10d83a70 100644
>>> --- a/drivers/video/fbdev/simplefb.c
>>> +++ b/drivers/video/fbdev/simplefb.c
>>> @@ -28,7 +28,10 @@
>>>    #include <linux/platform_device.h>
>>>    #include <linux/clk.h>
>>>    #include <linux/clk-provider.h>
>>> +#include <linux/of.h>
>>>    #include <linux/of_platform.h>
>>> +#include <linux/parser.h>
>>> +#include <linux/regulator/consumer.h>
>>>
>>>    static struct fb_fix_screeninfo simplefb_fix = {
>>>          .id             = "simple",
>>> @@ -174,6 +177,10 @@ struct simplefb_par {
>>>          int clk_count;
>>>          struct clk **clks;
>>>    #endif
>>> +#if defined CONFIG_OF && defined CONFIG_REGULATOR
>>> +       u32 regulator_count;
>>> +       struct regulator **regulators;
>>> +#endif
>>>    };
>>>
>>>    #if defined CONFIG_OF && defined CONFIG_COMMON_CLK
>>> @@ -269,6 +276,112 @@ static int simplefb_clocks_init(struct simplefb_par
>>> *par,
>>>    static void simplefb_clocks_destroy(struct simplefb_par *par) { }
>>>    #endif
>>>
>>> +#if defined CONFIG_OF && defined CONFIG_REGULATOR
>>> +
>>> +#define SUPPLY_SUFFIX "-supply"
>>> +
>>> +/*
>>> + * Regulator handling code.
>>> + *
>>> + * Here we handle the num-supplies and vin*-supply properties of our
>>> + * "simple-framebuffer" dt node. This is necessary so that we can make
>>> sure
>>> + * that any regulators needed by the display hardware that the bootloader
>>> + * set up for us (and for which it provided a simplefb dt node), stay up,
>>> + * for the life of the simplefb driver.
>>> + *
>>> + * When the driver unloads, we cleanly disable, and then release the
>>> + * regulators.
>>> + *
>>> + * We only complain about errors here, no action is taken as the most
>>> likely
>>> + * error can only happen due to a mismatch between the bootloader which
>>> set
>>> + * up simplefb, and the regulator definitions in the device tree. Chances
>>> are
>>> + * that there are no adverse effects, and if there are, a clean teardown
>>> of
>>> + * the fb probe will not help us much either. So just complain and carry
>>> on,
>>> + * and hope that the user actually gets a working fb at the end of
>>> things.
>>> + */
>>> +static int simplefb_regulators_init(struct simplefb_par *par,
>>> +       struct platform_device *pdev)
>>> +{
>>> +       struct device_node *np = pdev->dev.of_node;
>>> +       struct property *prop;
>>> +       struct regulator *regulator;
>>> +       const char *p;
>>> +       int count = 0, i = 0, ret;
>>> +
>>> +       if (dev_get_platdata(&pdev->dev) || !np)
>>> +               return 0;
>>> +
>>> +       /* Count the number of regulator supplies */
>>> +       for_each_property_of_node(np, prop) {
>>> +               p = strstr(prop->name, SUPPLY_SUFFIX);
>>> +               if (p && p != prop->name)
>>> +                       count++;
>>> +       }
>>> +
>>> +       if (!count)
>>> +               return 0;
>>> +
>>> +       par->regulators = devm_kcalloc(&pdev->dev, count,
>>> +                                      sizeof(struct regulator *),
>>> GFP_KERNEL);
>>> +       if (!par->regulators)
>>> +               return -ENOMEM;
>>> +
>>> +       /* Get all the regulators */
>>> +       for_each_property_of_node(np, prop) {
>>> +               char name[32]; /* 32 is max size of property name */
>>> +
>>> +               p = strstr(prop->name, SUPPLY_SUFFIX);
>>> +               if (p && p != prop->name)
>>> +                       continue;
>>> +
>>> +               strlcpy(name, prop->name,
>>> +                       strlen(prop->name) - sizeof(SUPPLY_SUFFIX) + 1);
>>> +               regulator = devm_regulator_get_optional(&pdev->dev, name);
>>> +               if (IS_ERR(regulator)) {
>>> +                       if (PTR_ERR(regulator) = -EPROBE_DEFER)
>>> +                               return -EPROBE_DEFER;
>>> +                       dev_err(&pdev->dev, "regulator %s not found:
>>> %ld\n",
>>> +                               name, PTR_ERR(regulator));
>>> +                       continue;
>>> +               }
>>> +               par->regulators[i++] = regulator;
>>
>>
>> So you only fill slots when the regulator_get has succeeded
>>
>>> +       }
>>> +       par->regulator_count = i;
>>
>>
>> and regulator_count now is the amount of successfully gotten regulators
>> (which may be different from count).
>>
>>> +
>>> +       /* Enable all the regulators */
>>> +       for (i = 0; i < par->regulator_count; i++) {
>>> +               if (par->regulators[i]) {
>>
>>
>> That means that this "if" is not necessary, it will always be true.
>
> Right. This is leftover code from the first version. I'll remove it.
>
>>> +                       ret = regulator_enable(par->regulators[i]);
>>> +                       if (ret) {
>>> +                               dev_err(&pdev->dev,
>>> +                                       "failed to enable regulator %d:
>>> %d\n",
>>> +                                       i, ret);
>>> +                               devm_regulator_put(par->regulators[i]);
>>> +                               par->regulators[i] = NULL;
>
> Note here.
>
>>> +                       }
>>> +               }
>>> +       }
>>> +
>>> +       return 0;
>>> +}
>>> +
>>> +static void simplefb_regulators_destroy(struct simplefb_par *par)
>>> +{
>>> +       int i;
>>> +
>>> +       if (!par->regulators)
>>> +               return;
>>> +
>>> +       for (i = 0; i < par->regulator_count; i++)
>>> +               if (par->regulators[i])
>>
>>
>> And idem for this if.
>
> This is still needed, since if we fail to enable any regulator, we just
> ignore it, call regulator_put() on it, and forget about it (set the entry
> to NULL). See the noted place above.

Ah right, ok lets keep that in then :)

Regards,

Hans

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

* [PATCH RFC v2 2/2] simplefb: Claim and enable regulators
@ 2015-10-21  8:09         ` Hans de Goede
  0 siblings, 0 replies; 28+ messages in thread
From: Hans de Goede @ 2015-10-21  8:09 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,

On 21-10-15 10:04, Chen-Yu Tsai wrote:
> Hi,
>
> On Wed, Oct 21, 2015 at 3:54 PM, Hans de Goede <hdegoede@redhat.com> wrote:
>> Hi,
>>
>>
>> On 21-10-15 07:59, Chen-Yu Tsai wrote:
>>>
>>> This claims and enables regulators listed in the simple framebuffer dt
>>> node. This is needed so that regulators powering the display pipeline
>>> and external hardware, described in the device node and known by the
>>> kernel code, will remain properly enabled.
>>>
>>> Signed-off-by: Chen-Yu Tsai <wens@csie.org>
>>> ---
>>>    drivers/video/fbdev/simplefb.c | 122
>>> ++++++++++++++++++++++++++++++++++++++++-
>>>    1 file changed, 121 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/video/fbdev/simplefb.c
>>> b/drivers/video/fbdev/simplefb.c
>>> index 52c5c7e63b52..c4ee10d83a70 100644
>>> --- a/drivers/video/fbdev/simplefb.c
>>> +++ b/drivers/video/fbdev/simplefb.c
>>> @@ -28,7 +28,10 @@
>>>    #include <linux/platform_device.h>
>>>    #include <linux/clk.h>
>>>    #include <linux/clk-provider.h>
>>> +#include <linux/of.h>
>>>    #include <linux/of_platform.h>
>>> +#include <linux/parser.h>
>>> +#include <linux/regulator/consumer.h>
>>>
>>>    static struct fb_fix_screeninfo simplefb_fix = {
>>>          .id             = "simple",
>>> @@ -174,6 +177,10 @@ struct simplefb_par {
>>>          int clk_count;
>>>          struct clk **clks;
>>>    #endif
>>> +#if defined CONFIG_OF && defined CONFIG_REGULATOR
>>> +       u32 regulator_count;
>>> +       struct regulator **regulators;
>>> +#endif
>>>    };
>>>
>>>    #if defined CONFIG_OF && defined CONFIG_COMMON_CLK
>>> @@ -269,6 +276,112 @@ static int simplefb_clocks_init(struct simplefb_par
>>> *par,
>>>    static void simplefb_clocks_destroy(struct simplefb_par *par) { }
>>>    #endif
>>>
>>> +#if defined CONFIG_OF && defined CONFIG_REGULATOR
>>> +
>>> +#define SUPPLY_SUFFIX "-supply"
>>> +
>>> +/*
>>> + * Regulator handling code.
>>> + *
>>> + * Here we handle the num-supplies and vin*-supply properties of our
>>> + * "simple-framebuffer" dt node. This is necessary so that we can make
>>> sure
>>> + * that any regulators needed by the display hardware that the bootloader
>>> + * set up for us (and for which it provided a simplefb dt node), stay up,
>>> + * for the life of the simplefb driver.
>>> + *
>>> + * When the driver unloads, we cleanly disable, and then release the
>>> + * regulators.
>>> + *
>>> + * We only complain about errors here, no action is taken as the most
>>> likely
>>> + * error can only happen due to a mismatch between the bootloader which
>>> set
>>> + * up simplefb, and the regulator definitions in the device tree. Chances
>>> are
>>> + * that there are no adverse effects, and if there are, a clean teardown
>>> of
>>> + * the fb probe will not help us much either. So just complain and carry
>>> on,
>>> + * and hope that the user actually gets a working fb at the end of
>>> things.
>>> + */
>>> +static int simplefb_regulators_init(struct simplefb_par *par,
>>> +       struct platform_device *pdev)
>>> +{
>>> +       struct device_node *np = pdev->dev.of_node;
>>> +       struct property *prop;
>>> +       struct regulator *regulator;
>>> +       const char *p;
>>> +       int count = 0, i = 0, ret;
>>> +
>>> +       if (dev_get_platdata(&pdev->dev) || !np)
>>> +               return 0;
>>> +
>>> +       /* Count the number of regulator supplies */
>>> +       for_each_property_of_node(np, prop) {
>>> +               p = strstr(prop->name, SUPPLY_SUFFIX);
>>> +               if (p && p != prop->name)
>>> +                       count++;
>>> +       }
>>> +
>>> +       if (!count)
>>> +               return 0;
>>> +
>>> +       par->regulators = devm_kcalloc(&pdev->dev, count,
>>> +                                      sizeof(struct regulator *),
>>> GFP_KERNEL);
>>> +       if (!par->regulators)
>>> +               return -ENOMEM;
>>> +
>>> +       /* Get all the regulators */
>>> +       for_each_property_of_node(np, prop) {
>>> +               char name[32]; /* 32 is max size of property name */
>>> +
>>> +               p = strstr(prop->name, SUPPLY_SUFFIX);
>>> +               if (p && p != prop->name)
>>> +                       continue;
>>> +
>>> +               strlcpy(name, prop->name,
>>> +                       strlen(prop->name) - sizeof(SUPPLY_SUFFIX) + 1);
>>> +               regulator = devm_regulator_get_optional(&pdev->dev, name);
>>> +               if (IS_ERR(regulator)) {
>>> +                       if (PTR_ERR(regulator) == -EPROBE_DEFER)
>>> +                               return -EPROBE_DEFER;
>>> +                       dev_err(&pdev->dev, "regulator %s not found:
>>> %ld\n",
>>> +                               name, PTR_ERR(regulator));
>>> +                       continue;
>>> +               }
>>> +               par->regulators[i++] = regulator;
>>
>>
>> So you only fill slots when the regulator_get has succeeded
>>
>>> +       }
>>> +       par->regulator_count = i;
>>
>>
>> and regulator_count now is the amount of successfully gotten regulators
>> (which may be different from count).
>>
>>> +
>>> +       /* Enable all the regulators */
>>> +       for (i = 0; i < par->regulator_count; i++) {
>>> +               if (par->regulators[i]) {
>>
>>
>> That means that this "if" is not necessary, it will always be true.
>
> Right. This is leftover code from the first version. I'll remove it.
>
>>> +                       ret = regulator_enable(par->regulators[i]);
>>> +                       if (ret) {
>>> +                               dev_err(&pdev->dev,
>>> +                                       "failed to enable regulator %d:
>>> %d\n",
>>> +                                       i, ret);
>>> +                               devm_regulator_put(par->regulators[i]);
>>> +                               par->regulators[i] = NULL;
>
> Note here.
>
>>> +                       }
>>> +               }
>>> +       }
>>> +
>>> +       return 0;
>>> +}
>>> +
>>> +static void simplefb_regulators_destroy(struct simplefb_par *par)
>>> +{
>>> +       int i;
>>> +
>>> +       if (!par->regulators)
>>> +               return;
>>> +
>>> +       for (i = 0; i < par->regulator_count; i++)
>>> +               if (par->regulators[i])
>>
>>
>> And idem for this if.
>
> This is still needed, since if we fail to enable any regulator, we just
> ignore it, call regulator_put() on it, and forget about it (set the entry
> to NULL). See the noted place above.

Ah right, ok lets keep that in then :)

Regards,

Hans

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

* Re: [PATCH RFC v2 0/2] simplefb: Add regulator handling support
  2015-10-21  5:58 ` Chen-Yu Tsai
  (?)
  (?)
@ 2015-10-22 16:53   ` Mark Brown
  -1 siblings, 0 replies; 28+ messages in thread
From: Mark Brown @ 2015-10-22 16:53 UTC (permalink / raw)
  To: Chen-Yu Tsai
  Cc: Hans de Goede, Jean-Christophe Plagniol-Villard, Tomi Valkeinen,
	Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala,
	linux-fbdev, devicetree, linux-kernel, linux-arm-kernel

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

On Wed, Oct 21, 2015 at 01:58:59PM +0800, Chen-Yu Tsai wrote:
> Hi everyone,
> 
> This is v2 of the simplefb regulator support series. This series adds
> regulator claiming and enabling support for simplefb.

This approach seems reasonable

Acked-by: Mark Brown <broonie@kernel.org>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

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

* Re: [PATCH RFC v2 0/2] simplefb: Add regulator handling support
@ 2015-10-22 16:53   ` Mark Brown
  0 siblings, 0 replies; 28+ messages in thread
From: Mark Brown @ 2015-10-22 16:53 UTC (permalink / raw)
  To: Chen-Yu Tsai
  Cc: Mark Rutland, devicetree, linux-fbdev, Pawel Moll, Ian Campbell,
	linux-kernel, Rob Herring, Hans de Goede, Tomi Valkeinen,
	Kumar Gala, Jean-Christophe Plagniol-Villard, linux-arm-kernel


[-- Attachment #1.1: Type: text/plain, Size: 292 bytes --]

On Wed, Oct 21, 2015 at 01:58:59PM +0800, Chen-Yu Tsai wrote:
> Hi everyone,
> 
> This is v2 of the simplefb regulator support series. This series adds
> regulator claiming and enabling support for simplefb.

This approach seems reasonable

Acked-by: Mark Brown <broonie@kernel.org>

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH RFC v2 0/2] simplefb: Add regulator handling support
@ 2015-10-22 16:53   ` Mark Brown
  0 siblings, 0 replies; 28+ messages in thread
From: Mark Brown @ 2015-10-22 16:53 UTC (permalink / raw)
  To: linux-arm-kernel

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

On Wed, Oct 21, 2015 at 01:58:59PM +0800, Chen-Yu Tsai wrote:
> Hi everyone,
> 
> This is v2 of the simplefb regulator support series. This series adds
> regulator claiming and enabling support for simplefb.

This approach seems reasonable

Acked-by: Mark Brown <broonie@kernel.org>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

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

* [PATCH RFC v2 0/2] simplefb: Add regulator handling support
@ 2015-10-22 16:53   ` Mark Brown
  0 siblings, 0 replies; 28+ messages in thread
From: Mark Brown @ 2015-10-22 16:53 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Oct 21, 2015 at 01:58:59PM +0800, Chen-Yu Tsai wrote:
> Hi everyone,
> 
> This is v2 of the simplefb regulator support series. This series adds
> regulator claiming and enabling support for simplefb.

This approach seems reasonable

Acked-by: Mark Brown <broonie@kernel.org>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20151023/c92cc1cc/attachment.sig>

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

end of thread, other threads:[~2015-10-22 23:35 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-21  5:58 [PATCH RFC v2 0/2] simplefb: Add regulator handling support Chen-Yu Tsai
2015-10-21  5:58 ` Chen-Yu Tsai
2015-10-21  5:58 ` Chen-Yu Tsai
2015-10-21  5:59 ` [PATCH RFC v2 1/2] dt-bindings: simplefb: Support a list of regulator supply properties Chen-Yu Tsai
2015-10-21  5:59   ` Chen-Yu Tsai
2015-10-21  5:59   ` Chen-Yu Tsai
2015-10-21  5:59   ` Chen-Yu Tsai
2015-10-21  7:50   ` Hans de Goede
2015-10-21  7:50     ` Hans de Goede
2015-10-21  7:50     ` Hans de Goede
2015-10-21  7:50     ` Hans de Goede
2015-10-21  5:59 ` [PATCH RFC v2 2/2] simplefb: Claim and enable regulators Chen-Yu Tsai
2015-10-21  5:59   ` Chen-Yu Tsai
2015-10-21  5:59   ` Chen-Yu Tsai
2015-10-21  7:54   ` Hans de Goede
2015-10-21  7:54     ` Hans de Goede
2015-10-21  7:54     ` Hans de Goede
2015-10-21  8:04     ` Chen-Yu Tsai
2015-10-21  8:04       ` Chen-Yu Tsai
2015-10-21  8:04       ` Chen-Yu Tsai
2015-10-21  8:09       ` Hans de Goede
2015-10-21  8:09         ` Hans de Goede
2015-10-21  8:09         ` Hans de Goede
2015-10-21  8:09         ` Hans de Goede
2015-10-22 16:53 ` [PATCH RFC v2 0/2] simplefb: Add regulator handling support Mark Brown
2015-10-22 16:53   ` Mark Brown
2015-10-22 16:53   ` Mark Brown
2015-10-22 16:53   ` Mark Brown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.