Skip to contentSkip to conversation

simplefb: add clock handling code

PATCH Superseded Hans de Goede 3 participants 11 messages Nov 12, 2014 – Nov 13, 2014

Subsystems (3)

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v5 cover simplefb: add clock handling code

Hi Tomi,

Here is v5 of my simplefb patch-set, this time with an Ack from Grant Likely for the dt-bindings bits, which should end all controversy surrounding that patch.

For changes since the original postings please see the per patch changelogs in the patch commit messages.

Please merge this into your tree for 3.19.

Thanks & Regards,

Hans

#1 lore raw

PATCH v5 1/5 simplefb: Add simplefb MAINTAINERS entry

During the discussion about adding clock handling code to simplefb, it became clear that simplefb currently does not have an active maintainer.

I've discussed this with Stephen Warren <[email protected]>, the original author of simplefb, and with his permisson I'm picking up maintainership of simplefb.

---
 MAINTAINERS | 8 ++++++++
 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
index df82827..7678808 100644
@@ -8442,6 +8442,14 @@ F:	drivers/media/usb/siano/
 F:	drivers/media/usb/siano/
 F:	drivers/media/mmc/siano/
 
+SIMPLEFB FB DRIVER
+M:	Hans de Goede <[email protected]>
+L:	linux-fbdev at vger.kernel.org
+S:	Maintained
+F:	Documentation/devicetree/bindings/video/simple-framebuffer.txt
+F:	drivers/video/fbdev/simplefb.c
+F:	include/linux/platform_data/simplefb.h
+
 SH_VEU V4L2 MEM2MEM DRIVER
 L:	linux-media at vger.kernel.org
 S:	Orphan
Signature · 1 line
2.1.0
#2 lore raw

PATCH v5 2/5 dt-bindings: Add a clocks property to the simple-framebuffer binding

In reply to Hans de Goede

A simple-framebuffer node represents a framebuffer setup by the firmware / bootloader. Such a framebuffer may have a number of clocks in use, add a property to communicate this to the OS.

--
Changes in v2:
-Added Reviewed-by: Mike Turquette <[email protected]> Changes in v3:
-Updated description to make clear simplefb deals with more then just memory Changes in v5:
-Improved clocks property description

---
 .../devicetree/bindings/video/simple-framebuffer.txt         | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/video/simple-framebuffer.txt +9 -3
index 70c26f3..8f35718 100644
@@ -1,8 +1,8 @@
 Simple Framebuffer
 
-A simple frame-buffer describes a raw memory region that may be rendered to,
-with the assumption that the display hardware has already been set up to scan
-out from that buffer.
+A simple frame-buffer describes a frame-buffer setup by firmware or
+the bootloader, with the assumption that the display hardware has already
+been set up to scan out from the memory pointed to by the reg property.
 
 Required properties:
 - compatible: "simple-framebuffer"
@@ -14,6 +14,12 @@ Required properties:
   - r5g6b5 (16-bit pixels, d[15:11]=r, d[10:5]=g, d[4:0]=b).
   - 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.
+
 Example:
 
 	framebuffer {
Signature · 1 line
2.1.0
#3 lore raw

PATCH v5 3/5 simplefb: formalize pseudo palette handling

In reply to Hans de Goede

From: Luc Verhaegen <[email protected]>

Add a proper struct describing simplefb private data, with the palette in there, instead of directly storing the palette in the fb_info->par pointer.

--
Changes in v5:
-Improved commit message

---
 drivers/video/fbdev/simplefb.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/video/fbdev/simplefb.c +12 -3
index 210f3a0..ec112c1 100644
@@ -41,6 +41,8 @@ static struct fb_var_screeninfo simplefb_var = {
 	.vmode		= FB_VMODE_NONINTERLACED,
 };
 
+#define PSEUDO_PALETTE_SIZE 16
+
 static int simplefb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
 			      u_int transp, struct fb_info *info)
 {
@@ -50,7 +52,7 @@ static int simplefb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
 	u32 cb = blue >> (16 - info->var.blue.length);
 	u32 value;
 
-	if (regno >= 16)
+	if (regno >= PSEUDO_PALETTE_SIZE)
 		return -EINVAL;
 
 	value = (cr << info->var.red.offset) |
@@ -163,11 +165,16 @@ static int simplefb_parse_pd(struct platform_device *pdev,
 	return 0;
 }
 
+struct simplefb_par {
+	u32 palette[PSEUDO_PALETTE_SIZE];
+};
+
 static int simplefb_probe(struct platform_device *pdev)
 {
 	int ret;
 	struct simplefb_params params;
 	struct fb_info *info;
+	struct simplefb_par *par;
 	struct resource *mem;
 
 	if (fb_get_options("simplefb", NULL))
@@ -188,11 +195,13 @@ static int simplefb_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	info = framebuffer_alloc(sizeof(u32) * 16, &pdev->dev);
+	info = framebuffer_alloc(sizeof(struct simplefb_par), &pdev->dev);
 	if (!info)
 		return -ENOMEM;
 	platform_set_drvdata(pdev, info);
 
+	par = info->par;
+
 	info->fix = simplefb_fix;
 	info->fix.smem_start = mem->start;
 	info->fix.smem_len = resource_size(mem);
@@ -225,7 +234,7 @@ static int simplefb_probe(struct platform_device *pdev)
 		framebuffer_release(info);
 		return -ENODEV;
 	}
-	info->pseudo_palette = (void *)(info + 1);
+	info->pseudo_palette = par->palette;
 
 	dev_info(&pdev->dev, "framebuffer at 0x%lx, 0x%x bytes, mapped to 0x%p\n",
 			     info->fix.smem_start, info->fix.smem_len,
Signature · 1 line
2.1.0
#4 lore raw

PATCH v5 4/5 simplefb: add goto error path to probe

In reply to Hans de Goede

From: Luc Verhaegen <[email protected]>

Use the usual kernel style of goto error_foo to free resources on probe error. This is a preparation patch for adding clocks support.

While at it also update ioremap_wc error return from ENODEV to ENOMEM.

--
Changes in v5:
-Improved commit message

---
 drivers/video/fbdev/simplefb.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
drivers/video/fbdev/simplefb.c +11 -7
index ec112c1..cdcf1fe 100644
@@ -220,8 +220,8 @@ static int simplefb_probe(struct platform_device *pdev)
 
 	info->apertures = alloc_apertures(1);
 	if (!info->apertures) {
-		framebuffer_release(info);
-		return -ENOMEM;
+		ret = -ENOMEM;
+		goto error_fb_release;
 	}
 	info->apertures->ranges[0].base = info->fix.smem_start;
 	info->apertures->ranges[0].size = info->fix.smem_len;
@@ -231,8 +231,8 @@ static int simplefb_probe(struct platform_device *pdev)
 	info->screen_base = ioremap_wc(info->fix.smem_start,
 				       info->fix.smem_len);
 	if (!info->screen_base) {
-		framebuffer_release(info);
-		return -ENODEV;
+		ret = -ENOMEM;
+		goto error_fb_release;
 	}
 	info->pseudo_palette = par->palette;
 
@@ -247,14 +247,18 @@ 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);
-		iounmap(info->screen_base);
-		framebuffer_release(info);
-		return ret;
+		goto error_unmap;
 	}
 
 	dev_info(&pdev->dev, "fb%d: simplefb registered!\n", info->node);
 
 	return 0;
+
+error_unmap:
+	iounmap(info->screen_base);
+error_fb_release:
+	framebuffer_release(info);
+	return ret;
 }
 
 static int simplefb_remove(struct platform_device *pdev)
Signature · 1 line
2.1.0
#5 lore raw

PATCH v5 5/5 simplefb: add clock handling code

In reply to Hans de Goede

From: Luc Verhaegen <[email protected]>

This claims and enables clocks listed in the simple framebuffer dt node. This is needed so that the display engine, in case the required clocks are known by the kernel code and are described in the dt, will remain properly enabled.

--
Changes in v4:
-change clks from linkedlist to dynamic allocated array -propagate EPROBE_DEFER up from simplefb_clocks_init to simplefb_probe

---
 drivers/video/fbdev/simplefb.c | 101 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 100 insertions(+), 1 deletion(-)
drivers/video/fbdev/simplefb.c +100 -1
index cdcf1fe..cd96edd 100644
@@ -26,6 +26,7 @@
 #include <linux/module.h>
 #include <linux/platform_data/simplefb.h>
 #include <linux/platform_device.h>
+#include <linux/clk-provider.h>
 
 static struct fb_fix_screeninfo simplefb_fix = {
 	.id		= "simple",
@@ -167,8 +168,98 @@ static int simplefb_parse_pd(struct platform_device *pdev,
 
 struct simplefb_par {
 	u32 palette[PSEUDO_PALETTE_SIZE];
+	int clk_count;
+	struct clk **clks;
 };
 
+/*
+ * Clock handling code.
+ *
+ * Here we handle the clocks property of our "simple-framebuffer" dt node.
+ * This is necessary so that we can make sure that any clocks needed by
+ * the display engine 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 clocks.
+ *
+ * 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 clock 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_clocks_init(struct simplefb_par *par, struct platform_device *pdev)
+{
+	struct device_node *np = pdev->dev.of_node;
+	struct clk *clock;
+	int i, ret;
+
+	if (dev_get_platdata(&pdev->dev) || !np)
+		return 0;
+
+	par->clk_count = of_clk_get_parent_count(np);
+	if (par->clk_count <= 0)
+		return 0;
+
+	par->clks = kcalloc(par->clk_count, sizeof(struct clk *), GFP_KERNEL);
+	if (!par->clks)
+		return -ENOMEM;
+
+	for (i = 0; i < par->clk_count; i++) {
+		clock = of_clk_get(np, i);
+		if (IS_ERR(clock)) {
+			if (PTR_ERR(clock) == -EPROBE_DEFER) {
+				while (--i >= 0) {
+					if (par->clks[i])
+						clk_put(par->clks[i]);
+				}
+				kfree(par->clks);
+				return -EPROBE_DEFER;
+			}
+			dev_err(&pdev->dev, "%s: clock %d not found: %ld\n",
+				__func__, i, PTR_ERR(clock));
+			continue;
+		}
+		par->clks[i] = clock;
+	}
+
+	for (i = 0; i < par->clk_count; i++) {
+		if (par->clks[i]) {
+			ret = clk_prepare_enable(par->clks[i]);
+			if (ret) {
+				dev_err(&pdev->dev,
+					"%s: failed to enable clock %d: %d\n",
+					__func__, i, ret);
+				clk_put(par->clks[i]);
+				par->clks[i] = NULL;
+			}
+		}
+	}
+
+	return 0;
+}
+
+static void
+simplefb_clocks_destroy(struct simplefb_par *par)
+{
+	int i;
+
+	if (!par->clks)
+		return;
+
+	for (i = 0; i < par->clk_count; i++) {
+		if (par->clks[i]) {
+			clk_disable_unprepare(par->clks[i]);
+			clk_put(par->clks[i]);
+		}
+	}
+
+	kfree(par->clks);
+}
+
 static int simplefb_probe(struct platform_device *pdev)
 {
 	int ret;
@@ -236,6 +327,10 @@ static int simplefb_probe(struct platform_device *pdev)
 	}
 	info->pseudo_palette = par->palette;
 
+	ret = simplefb_clocks_init(par, pdev);
+	if (ret < 0)
+		goto error_unmap;
+
 	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);
@@ -247,13 +342,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_unmap;
+		goto error_clocks;
 	}
 
 	dev_info(&pdev->dev, "fb%d: simplefb registered!\n", info->node);
 
 	return 0;
 
+error_clocks:
+	simplefb_clocks_destroy(par);
 error_unmap:
 	iounmap(info->screen_base);
 error_fb_release:
@@ -264,8 +361,10 @@ error_fb_release:
 static int simplefb_remove(struct platform_device *pdev)
 {
 	struct fb_info *info = platform_get_drvdata(pdev);
+	struct simplefb_par *par = info->par;
 
 	unregister_framebuffer(info);
+	simplefb_clocks_destroy(par);
 	framebuffer_release(info);
 
 	return 0;
Signature · 1 line
2.1.0
#6 lore raw

v5 cover simplefb: add clock handling code

In reply to Hans de Goede
Quoted 10 lines · Hans de Goede

Hi Tomi,

Here is v5 of my simplefb patch-set, this time with an Ack from Grant Likely for the dt-bindings bits, which should end all controversy surrounding that patch.

For changes since the original postings please see the per patch changelogs in the patch commit messages.

Please merge this into your tree for 3.19.

Hi Tomi,

I'm discussing this with Rob today. Please hold off 24 hours before merging. If you don't hear anything to the contrary by tomorrow then go ahead and merge.

g.

#7 lore raw

v5 cover simplefb: add clock handling code

Quoted 10 lines · Grant Likely
Quoted 9 lines · Hans de Goede

Hi Tomi,

Here is v5 of my simplefb patch-set, this time with an Ack from Grant Likely for the dt-bindings bits, which should end all controversy surrounding that patch.

For changes since the original postings please see the per patch changelogs in the patch commit messages.

Quoted 7 lines
Quoted 1 line

Please merge this into your tree for 3.19.

Hi Tomi,

I'm discussing this with Rob today. Please hold off 24 hours before merging. If you don't hear anything to the contrary by tomorrow then go ahead and merge.

I just talked to Rob. All is good, you can apply.

g.

#8 lore raw

v5 cover simplefb: add clock handling code

Quoted 13 lines · Grant Likely
Quoted 12 lines · Grant Likely
Quoted 10 lines · Hans de Goede

Hi Tomi,

Here is v5 of my simplefb patch-set, this time with an Ack from Grant Likely for the dt-bindings bits, which should end all controversy surrounding that patch.

For changes since the original postings please see the per patch changelogs in the patch commit messages.

Please merge this into your tree for 3.19.

Quoted 7 lines
Quoted 5 lines

Hi Tomi,

I'm discussing this with Rob today. Please hold off 24 hours before merging. If you don't hear anything to the contrary by tomorrow then go ahead and merge.

I just talked to Rob. All is good, you can apply.

Ok. I'll apply tomorrow if there are no more comments during the night for the new series, and the compilation issue has been solved.

Tomi

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20141113/5957f252/attachment.sig>

#9 lore raw

v5 cover simplefb: add clock handling code

In reply to Hans de Goede
Quoted 10 lines · Hans de Goede

Hi Tomi,

Here is v5 of my simplefb patch-set, this time with an Ack from Grant Likely for the dt-bindings bits, which should end all controversy surrounding that patch.

For changes since the original postings please see the per patch changelogs in the patch commit messages.

Please merge this into your tree for 3.19.

I applied this and the "dt-bindings: simplefb: Specify node location and handoff related properties" v3 series to my test branch, compiled for x64 and:

drivers/video/fbdev/simplefb.c: In function ?simplefb_clocks_init?:
drivers/video/fbdev/simplefb.c:204:2: error: implicit declaration of function ?of_clk_get_parent_count? [-Werror=implicit-function-declaration]
par->clk_count = of_clk_get_parent_count(np);
^
In file included from include/linux/i2c.h:33:0,
from include/uapi/linux/fb.h:5,
from include/linux/fb.h:5,
from drivers/video/fbdev/simplefb.c:24:
drivers/video/fbdev/simplefb.c: In function ?simplefb_init?:
drivers/video/fbdev/simplefb.c:399:25: error: ?of_chosen? undeclared (first use in this function)

  for_each_child_of_node(of_chosen, np) {
                         ^
include/linux/of.h:736:33: note: in definition of macro
?for_each_child_of_node?
  for (child = of_get_next_child(parent, NULL); child != NULL; \
                                 ^
drivers/video/fbdev/simplefb.c:399:25: note: each undeclared identifier
is reported only once for each function it appears in
  for_each_child_of_node(of_chosen, np) {
                         ^
include/linux/of.h:736:33: note: in definition of macro
?for_each_child_of_node?
  for (child = of_get_next_child(parent, NULL); child != NULL; \
                                 ^

We need "depends on OF"?

Tomi

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20141113/dec60d24/attachment.sig>

#10 lore raw

v5 cover simplefb: add clock handling code

Hi,

Quoted 43 lines · Tomi Valkeinen
Quoted 10 lines · Hans de Goede

Hi Tomi,

Here is v5 of my simplefb patch-set, this time with an Ack from Grant Likely for the dt-bindings bits, which should end all controversy surrounding that patch.

For changes since the original postings please see the per patch changelogs in the patch commit messages.

Please merge this into your tree for 3.19.

I applied this and the "dt-bindings: simplefb: Specify node location and handoff related properties" v3 series to my test branch, compiled for x64 and:

drivers/video/fbdev/simplefb.c: In function ?simplefb_clocks_init?:
drivers/video/fbdev/simplefb.c:204:2: error: implicit declaration of function ?of_clk_get_parent_count? [-Werror=implicit-function-declaration]
par->clk_count = of_clk_get_parent_count(np);
^
In file included from include/linux/i2c.h:33:0,
from include/uapi/linux/fb.h:5,
from include/linux/fb.h:5,
from drivers/video/fbdev/simplefb.c:24:
drivers/video/fbdev/simplefb.c: In function ?simplefb_init?:
drivers/video/fbdev/simplefb.c:399:25: error: ?of_chosen? undeclared (first use in this function)

  for_each_child_of_node(of_chosen, np) {
                         ^
include/linux/of.h:736:33: note: in definition of macro
?for_each_child_of_node?
  for (child = of_get_next_child(parent, NULL); child != NULL; \
                                 ^
drivers/video/fbdev/simplefb.c:399:25: note: each undeclared identifier
is reported only once for each function it appears in
  for_each_child_of_node(of_chosen, np) {
                         ^
include/linux/of.h:736:33: note: in definition of macro
?for_each_child_of_node?
  for (child = of_get_next_child(parent, NULL); child != NULL; \
                                 ^
Quoted 1 line

We need "depends on OF"?

Good catch!

So a quick-grep through the entire kernel sources has thought me that apparently simplefb is used on non devicetree / of platforms through platform-device instantiation, using the trick of naming the platform-device the same as the driver to get the driver to bind.

So the answer to your compile breakage is to make the relevant code bits be #ifdef CONFIG_OF

I'll respin the offending patch (5/5) in the "simplefb: add clock handling code" series, and I'll respin the entire second series, as I need to also address your comment on the example in the bindings there.

I hope to be able to post a re-spun version of both later tonight.

Regards,

Hans

Quoted 4 lines

Tomi