T Tomi Valkeinen #
Message details and related content
On Wed, 2012-09-19 at 10:20 +0200, Steffen Trumtrar wrote:
quoted hunk
This patch adds a helper function for parsing videomodes from the devicetree. The videomode can be either converted to a struct drm_display_mode or a struct fb_videomode. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Steffen Trumtrar <redacted> --- Hi! changes since v3: - print error messages - free alloced memory - general cleanup Regards Steffen .../devicetree/bindings/video/displaymode | 74 +++++ drivers/of/Kconfig | 5 + drivers/of/Makefile | 1 + drivers/of/of_videomode.c | 283 ++++++++++++++++++++ include/linux/of_videomode.h | 56 ++++ 5 files changed, 419 insertions(+) create mode 100644 Documentation/devicetree/bindings/video/displaymode create mode 100644 drivers/of/of_videomode.c create mode 100644 include/linux/of_videomode.hdiff --git a/Documentation/devicetree/bindings/video/displaymode b/Documentation/devicetree/bindings/video/displaymode new file mode 100644 index 0000000..990ca52 --- /dev/null +++ b/Documentation/devicetree/bindings/video/displaymode@@ -0,0 +1,74 @@ +videomode bindings +================== + +Required properties: + - hactive, vactive: Display resolution + - hfront-porch, hback-porch, hsync-len: Horizontal Display timing parameters
Why is this needed? If the prop->min is higher than prop->typ, isn't
that an error in the DT data, and should be rejected when parsing?
quoted hunk
+ +/* read property into new mode_property */ +static int of_video_parse_property(struct device_node *np, char *name, + struct mode_property *result) +{ + struct property *prop; + int length; + int cells; + int ret; + + prop = of_find_property(np, name, &length); + if (!prop) { + pr_err("%s: could not find property %s\n", __func__, + name); + return -EINVAL; + } + + cells = length / sizeof(u32); + + memset(result, 0, sizeof(*result)); + + ret = of_property_read_u32_array(np, name, &result->min, cells); + + return ret;
Ah, I guess this is the reason for the of_video_get_value... Wouldn't it
be cleaner to be more explicit here? If there's one cell, it's the
typical value, otherwise if there are 3 cells, they are min/typ/max,
else it's an error. And I think the above also trashes memory if there
happens to be 4+ cells.
quoted hunk
+} + +static int of_video_free(struct display *disp) +{ + int i; + + for (i=0; i<disp->num_modes; i++) + kfree(disp->modes[i]); + kfree(disp->modes); + + return 0; +} + +int videomode_to_display_mode(struct display *disp, struct drm_display_mode *dmode, int index) +{ + struct videomode *vm; + + memset(dmode, 0, sizeof(*dmode)); + + if (index > disp->num_modes) { + pr_err("%s: wrong index: %d from %d\n", __func__, index, disp->num_modes); + return -EINVAL; + } + + vm = disp->modes[index]; + + dmode->hdisplay = of_video_get_value(&vm->hactive); + dmode->hsync_start = of_video_get_value(&vm->hactive) + of_video_get_value(&vm->hfront_porch); + dmode->hsync_end = of_video_get_value(&vm->hactive) + of_video_get_value(&vm->hfront_porch) + + of_video_get_value(&vm->hsync_len); + dmode->htotal = of_video_get_value(&vm->hactive) + of_video_get_value(&vm->hfront_porch) + + of_video_get_value(&vm->hsync_len) + of_video_get_value(&vm->hback_porch); + + dmode->vdisplay = of_video_get_value(&vm->vactive); + dmode->vsync_start = of_video_get_value(&vm->vactive) + of_video_get_value(&vm->vfront_porch); + dmode->vsync_end = of_video_get_value(&vm->vactive) + of_video_get_value(&vm->vfront_porch) + + of_video_get_value(&vm->vsync_len); + dmode->vtotal = of_video_get_value(&vm->vactive) + of_video_get_value(&vm->vfront_porch) + + of_video_get_value(&vm->vsync_len) + of_video_get_value(&vm->vback_porch); +
This and of_get_display_mode() do not handle errors from
of_get_video_modes() nor from videomode_to_xxx_mode(). And I don't see a
reason for the if (fbmode) check (and the same for dmode), as there's no
reason to call these functions except to get the video modes.
quoted hunk
+} +EXPORT_SYMBOL_GPL(of_get_fb_videomode);diff --git a/include/linux/of_videomode.h b/include/linux/of_videomode.h new file mode 100644 index 0000000..5571ce3 --- /dev/null +++ b/include/linux/of_videomode.h@@ -0,0 +1,56 @@ +/* + * Copyright 2012 Sascha Hauer <s.hauer@pengutronix.de> + * Copyright 2012 Steffen Trumtrar <s.trumtrar@pengutronix.de> + * + * OF helpers for videomodes. + * + * This file is released under the GPLv2 + */ + +#ifndef __LINUX_OF_VIDEOMODE_H +#define __LINUX_OF_VIDEOMODE_H + +#define OF_MODE_SELECTION -1 + +struct mode_property { + u32 min; + u32 typ; + u32 max; +}; + +struct display { + u32 width_mm; + u32 height_mm; + struct videomode **modes; + int default_mode; + int num_modes; +}; + +/* describe videomode in terms of hardware parameters */ +struct videomode { + struct mode_property hback_porch; + struct mode_property hfront_porch;
I think the names display and videomode are a bit too generic here, and could clash with names from kernel drivers. Also, the videomode is not really a videomode, but a "template" (or something) for videomode. A real videomode doesn't have min & max values, only the actual value. Perhaps these should be prefixed with "of_"? Then again, they are not really of specific either... Tomi