Re: [PATCHv14 3/7] video: add of helper for display timings/videomode
On Fri, Nov 23, 2012 at 03:49:37PM +0530, Leela Krishna Amudala wrote: > Hello Steffen, > > On Fri, Nov 23, 2012 at 2:34 PM, Steffen Trumtrar > wrote: > > This adds support for reading display timings from DT into a struct > > display_timings. The of_display_timing implementation supports multiple > > subnodes. All children are read into an array, that can be queried. > > > > If no native mode is specified, the first subnode will be used. > > > > For cases, where the graphics drivers knows, there can be only one > > mode description or where the driver only supports one mode, a helper > > function of_get_videomode is added, that gets a struct videomode from DT. > > (As this function is implemented in an expensive fashion, it should only > > be used in the aforementioned case). > > > > This also demonstrates how of_display_timings may be utilized. > > > > Signed-off-by: Steffen Trumtrar > > Signed-off-by: Philipp Zabel > > Acked-by: Stephen Warren > > Reviewed-by: Thierry Reding > > Acked-by: Thierry Reding > > Tested-by: Thierry Reding > > Tested-by: Philipp Zabel > > Reviewed-by: Laurent Pinchart > > Acked-by: Laurent Pinchart > > --- > > .../devicetree/bindings/video/display-timings.txt | 107 ++ > > drivers/video/Kconfig | 15 ++ > > drivers/video/Makefile |2 + > > drivers/video/of_display_timing.c | 223 > > > > drivers/video/of_videomode.c | 48 + > > include/linux/of_display_timings.h | 20 ++ > > include/linux/of_videomode.h | 18 ++ > > 7 files changed, 433 insertions(+) > > create mode 100644 > > Documentation/devicetree/bindings/video/display-timings.txt > > create mode 100644 drivers/video/of_display_timing.c > > create mode 100644 drivers/video/of_videomode.c > > create mode 100644 include/linux/of_display_timings.h > > create mode 100644 include/linux/of_videomode.h > > > > <<>> > > > diff --git a/drivers/video/of_display_timing.c > > b/drivers/video/of_display_timing.c > > new file mode 100644 > > index 000..645f43d > > --- /dev/null > > +++ b/drivers/video/of_display_timing.c > > @@ -0,0 +1,223 @@ > > +/* > > + * OF helpers for parsing display timings > > + * > > + * Copyright (c) 2012 Steffen Trumtrar , > > Pengutronix > > + * > > + * based on of_videomode.c by Sascha Hauer > > + * > > + * This file is released under the GPLv2 > > + */ > > +#include > > +#include > > +#include > > +#include > > + > > +/** > > + * parse_property - parse timing_entry from device_node > > + * @np: device_node with the property > > + * @name: name of the property > > + * @result: will be set to the return value > > + * > > + * DESCRIPTION: > > + * Every display_timing can be specified with either just the typical > > value or > > + * a range consisting of min/typ/max. This function helps handling this > > + **/ > > +static int parse_property(const struct device_node *np, const char *name, > > + struct timing_entry *result) > > +{ > > + struct property *prop; > > + int length, cells, 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); > > + if (cells == 1) { > > + ret = of_property_read_u32(np, name, &result->typ); > > + result->min = result->typ; > > + result->max = result->typ; > > + } else if (cells == 3) { > > + ret = of_property_read_u32_array(np, name, &result->min, > > cells); > > + } else { > > + pr_err("%s: illegal timing specification in %s\n", __func__, > > + name); > > + return -EINVAL; > > + } > > + > > + return ret; > > +} > > + > > +/** > > + * of_get_display_timing - parse display_timing entry from device_node > > + * @np: device_node with the properties > > + **/ > > +static struct display_timing *of_get_display_timing(const struct > > device_node > > + *np) > > +{ > > + struct display_timing *dt; > > + int ret = 0; > > + > > + dt = kzalloc(sizeof(*dt), GFP_KERNEL); > > + if (!dt) { > > + pr_err("%s: could not allocate display_timing struct\n", > > + __func__); > > + return NULL; > > + } > > + > > + ret |= parse_property(np, "hback-porch", &dt->hback_porch); > > + ret |= parse_property(np, "hfront-porch", &dt->hfront_porch); > > + ret |= parse_property(np, "hactive", &dt->hactive); > > + ret |= parse_property(np, "hsync-len", &dt->hsync_len); > > + ret |= parse_property(np, "vback-porch", &dt->vback_porch); > > + ret |= parse_property(n
Re: [PATCHv14 3/7] video: add of helper for display timings/videomode
Hello Steffen, On Fri, Nov 23, 2012 at 2:34 PM, Steffen Trumtrar wrote: > This adds support for reading display timings from DT into a struct > display_timings. The of_display_timing implementation supports multiple > subnodes. All children are read into an array, that can be queried. > > If no native mode is specified, the first subnode will be used. > > For cases, where the graphics drivers knows, there can be only one > mode description or where the driver only supports one mode, a helper > function of_get_videomode is added, that gets a struct videomode from DT. > (As this function is implemented in an expensive fashion, it should only > be used in the aforementioned case). > > This also demonstrates how of_display_timings may be utilized. > > Signed-off-by: Steffen Trumtrar > Signed-off-by: Philipp Zabel > Acked-by: Stephen Warren > Reviewed-by: Thierry Reding > Acked-by: Thierry Reding > Tested-by: Thierry Reding > Tested-by: Philipp Zabel > Reviewed-by: Laurent Pinchart > Acked-by: Laurent Pinchart > --- > .../devicetree/bindings/video/display-timings.txt | 107 ++ > drivers/video/Kconfig | 15 ++ > drivers/video/Makefile |2 + > drivers/video/of_display_timing.c | 223 > > drivers/video/of_videomode.c | 48 + > include/linux/of_display_timings.h | 20 ++ > include/linux/of_videomode.h | 18 ++ > 7 files changed, 433 insertions(+) > create mode 100644 > Documentation/devicetree/bindings/video/display-timings.txt > create mode 100644 drivers/video/of_display_timing.c > create mode 100644 drivers/video/of_videomode.c > create mode 100644 include/linux/of_display_timings.h > create mode 100644 include/linux/of_videomode.h > <<>> > diff --git a/drivers/video/of_display_timing.c > b/drivers/video/of_display_timing.c > new file mode 100644 > index 000..645f43d > --- /dev/null > +++ b/drivers/video/of_display_timing.c > @@ -0,0 +1,223 @@ > +/* > + * OF helpers for parsing display timings > + * > + * Copyright (c) 2012 Steffen Trumtrar , > Pengutronix > + * > + * based on of_videomode.c by Sascha Hauer > + * > + * This file is released under the GPLv2 > + */ > +#include > +#include > +#include > +#include > + > +/** > + * parse_property - parse timing_entry from device_node > + * @np: device_node with the property > + * @name: name of the property > + * @result: will be set to the return value > + * > + * DESCRIPTION: > + * Every display_timing can be specified with either just the typical value > or > + * a range consisting of min/typ/max. This function helps handling this > + **/ > +static int parse_property(const struct device_node *np, const char *name, > + struct timing_entry *result) > +{ > + struct property *prop; > + int length, cells, 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); > + if (cells == 1) { > + ret = of_property_read_u32(np, name, &result->typ); > + result->min = result->typ; > + result->max = result->typ; > + } else if (cells == 3) { > + ret = of_property_read_u32_array(np, name, &result->min, > cells); > + } else { > + pr_err("%s: illegal timing specification in %s\n", __func__, > + name); > + return -EINVAL; > + } > + > + return ret; > +} > + > +/** > + * of_get_display_timing - parse display_timing entry from device_node > + * @np: device_node with the properties > + **/ > +static struct display_timing *of_get_display_timing(const struct device_node > + *np) > +{ > + struct display_timing *dt; > + int ret = 0; > + > + dt = kzalloc(sizeof(*dt), GFP_KERNEL); > + if (!dt) { > + pr_err("%s: could not allocate display_timing struct\n", > + __func__); > + return NULL; > + } > + > + ret |= parse_property(np, "hback-porch", &dt->hback_porch); > + ret |= parse_property(np, "hfront-porch", &dt->hfront_porch); > + ret |= parse_property(np, "hactive", &dt->hactive); > + ret |= parse_property(np, "hsync-len", &dt->hsync_len); > + ret |= parse_property(np, "vback-porch", &dt->vback_porch); > + ret |= parse_property(np, "vfront-porch", &dt->vfront_porch); > + ret |= parse_property(np, "vactive", &dt->vactive); > + ret |= parse_property(np, "vsync-len", &dt->vsync_len); > + ret |= parse_property(np, "clock-frequency", &dt->pixelclock); > + > + of_property_read_u32(np, "vsync-active", &dt->vsync_pol_active); > + of_property
[PATCHv14 3/7] video: add of helper for display timings/videomode
This adds support for reading display timings from DT into a struct display_timings. The of_display_timing implementation supports multiple subnodes. All children are read into an array, that can be queried. If no native mode is specified, the first subnode will be used. For cases, where the graphics drivers knows, there can be only one mode description or where the driver only supports one mode, a helper function of_get_videomode is added, that gets a struct videomode from DT. (As this function is implemented in an expensive fashion, it should only be used in the aforementioned case). This also demonstrates how of_display_timings may be utilized. Signed-off-by: Steffen Trumtrar Signed-off-by: Philipp Zabel Acked-by: Stephen Warren Reviewed-by: Thierry Reding Acked-by: Thierry Reding Tested-by: Thierry Reding Tested-by: Philipp Zabel Reviewed-by: Laurent Pinchart Acked-by: Laurent Pinchart --- .../devicetree/bindings/video/display-timings.txt | 107 ++ drivers/video/Kconfig | 15 ++ drivers/video/Makefile |2 + drivers/video/of_display_timing.c | 223 drivers/video/of_videomode.c | 48 + include/linux/of_display_timings.h | 20 ++ include/linux/of_videomode.h | 18 ++ 7 files changed, 433 insertions(+) create mode 100644 Documentation/devicetree/bindings/video/display-timings.txt create mode 100644 drivers/video/of_display_timing.c create mode 100644 drivers/video/of_videomode.c create mode 100644 include/linux/of_display_timings.h create mode 100644 include/linux/of_videomode.h diff --git a/Documentation/devicetree/bindings/video/display-timings.txt b/Documentation/devicetree/bindings/video/display-timings.txt new file mode 100644 index 000..2b25d58 --- /dev/null +++ b/Documentation/devicetree/bindings/video/display-timings.txt @@ -0,0 +1,107 @@ +display-timings bindings + + +display-timings node + + +required properties: + - none + +optional properties: + - native-mode: The native mode for the display, in case multiple modes are + provided. When omitted, assume the first node is the native. + +timings subnode +--- + +required properties: + - hactive, vactive: Display resolution + - hfront-porch, hback-porch, hsync-len: Horizontal Display timing parameters + in pixels + vfront-porch, vback-porch, vsync-len: Vertical display timing parameters in + lines + - clock-frequency: display clock in Hz + +optional properties: + - hsync-active: Hsync pulse is active low/high/ignored + - vsync-active: Vsync pulse is active low/high/ignored + - de-active: Data-Enable pulse is active low/high/ignored + - pixelclk-inverted: pixelclock is inverted (active on falling edge)/ + non-inverted (active on rising edge)/ +ignored (ignore property) + - interlaced (bool): boolean to enable interlaced mode + - doublescan (bool): boolean to enable doublescan mode + - doubleclk (bool) + +All the optional properties that are not bool follow the following logic: +<1>: high active +<0>: low active +omitted: not used on hardware + +There are different ways of describing the capabilities of a display. The devicetree +representation corresponds to the one commonly found in datasheets for displays. +If a display supports multiple signal timings, the native-mode can be specified. + +The parameters are defined as + + +--+-+--+---+ + | |↑| | | + | ||vback_porch | | | + | |↓| | | + +--###--+---+ + | #↑# | | + | #|# | | + | hback #|# hfront | hsync | + | porch #| hactive # porch | len | + |<>#<---+--->#<>|<->| + | #|# | | + | #|vactive # | | + | #|# | | + | #↓# | | + +--###--+---+ + | |↑| | | + | ||vfront_porch| | | + | |