All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Warren <swarren@wwwdotorg.org>
To: Steffen Trumtrar <s.trumtrar@pengutronix.de>
Cc: devicetree-discuss@lists.ozlabs.org, linux-fbdev@vger.kernel.org,
	dri-devel@lists.freedesktop.org,
	Tomi Valkeinen <tomi.valkeinen@ti.com>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	linux-media@vger.kernel.org
Subject: Re: [PATCH 1/2 v6] of: add helper to parse display timings
Date: Thu, 04 Oct 2012 12:47:16 -0600	[thread overview]
Message-ID: <506DD9B4.40409@wwwdotorg.org> (raw)
In-Reply-To: <1349373560-11128-2-git-send-email-s.trumtrar@pengutronix.de>

On 10/04/2012 11:59 AM, Steffen Trumtrar wrote:

A patch description would be useful for something like this.

> diff --git a/Documentation/devicetree/bindings/video/display-timings.txt b/Documentation/devicetree/bindings/video/display-timings.txt
> new file mode 100644
...
> +Usage in backend
> +================

Everything before that point in the file looks fine to me.

Everything after this point in the file seems to be Linux-specific
implementation details. Does it really belong in the DT binding
documentation, rather than some Linux-specific documentation file?

> +struct drm_display_mode
> +=======================
> +
> +  +----------+---------------------------------------------+----------+-------+
> +  |          |                                             |          |       |  ↑
> +  |          |                                             |          |       |  |
> +  |          |                                             |          |       |  |
> +  +----------###############################################----------+-------+  |

I suspect the entire horizontal box above (and the entire vertical box
all the way down the left-hand side) should be on the bottom/right
instead of top/left. The reason I think this is because all of
vsync_start, vsync_end, vdisplay have to be referenced to some known
point, which is usually zero or the start of the timing definition, /or/
there would be some value indicating the size of the top marging/porch
in order to say where those other values are referenced to.

> +  |          #   ↑         ↑          ↑                    #          |       |  |
> +  |          #   |         |          |                    #          |       |  |
> +  |          #   |         |          |                    #          |       |  |
> +  |          #   |         |          |                    #          |       |  |
> +  |          #   |         |          |                    #          |       |  |
> +  |          #   |         |          |       hdisplay     #          |       |  |
> +  |          #<--+--------------------+------------------->#          |       |  |
> +  |          #   |         |          |                    #          |       |  |
> +  |          #   |vsync_start         |                    #          |       |  |
> +  |          #   |         |          |                    #          |       |  |
> +  |          #   |         |vsync_end |                    #          |       |  |
> +  |          #   |         |          |vdisplay            #          |       |  |
> +  |          #   |         |          |                    #          |       |  |
> +  |          #   |         |          |                    #          |       |  |
> +  |          #   |         |          |                    #          |       |  | vtotal
> +  |          #   |         |          |                    #          |       |  |
> +  |          #   |         |          |     hsync_start    #          |       |  |
> +  |          #<--+---------+----------+------------------------------>|       |  |
> +  |          #   |         |          |                    #          |       |  |
> +  |          #   |         |          |     hsync_end      #          |       |  |
> +  |          #<--+---------+----------+-------------------------------------->|  |
> +  |          #   |         |          ↓                    #          |       |  |
> +  +----------####|#########|################################----------+-------+  |
> +  |          |   |         |                               |          |       |  |
> +  |          |   |         |                               |          |       |  |
> +  |          |   ↓         |                               |          |       |  |
> +  +----------+-------------+-------------------------------+----------+-------+  |
> +  |          |             |                               |          |       |  |
> +  |          |             |                               |          |       |  |
> +  |          |             ↓                               |          |       |  ↓
> +  +----------+---------------------------------------------+----------+-------+
> +                                   htotal
> +   <------------------------------------------------------------------------->

> diff --git a/drivers/of/of_display_timings.c b/drivers/of/of_display_timings.c

> +static int parse_property(struct device_node *np, char *name,
> +				struct timing_entry *result)

> +	if (cells == 1)
> +		ret = of_property_read_u32_array(np, name, &result->typ, cells);

Should that branch not just set result->min/max to typ as well?
Presumably it'd prevent any code that interprets struct timing_entry
from having to check if those values were 0 or not?

> +	else if (cells == 3)
> +		ret = of_property_read_u32_array(np, name, &result->min, cells);

> +struct display_timings *of_get_display_timing_list(struct device_node *np)

> +	entry = of_parse_phandle(timings_np, "default-timing", 0);
> +
> +	if (!entry) {
> +		pr_info("%s: no default-timing specified\n", __func__);
> +		entry = of_find_node_by_name(np, "timing");

I don't think you want to require the node have an explicit name; I
don't recall the DT binding documentation making that a requirement.
Instead, can't you either just leave the default unset, or pick the
first DT child node, irrespective of name?

> +	if (!entry) {
> +		pr_info("%s: no timing specifications given\n", __func__);
> +		return disp;
> +	}

The DT bindings don't state that it's mandatory to have some timing
specified, although I agree that it makes sense in practice.

> +	for_each_child_of_node(timings_np, entry) {
> +		struct signal_timing *st;
> +
> +		st = of_get_display_timing(entry);
> +
> +		if (!st)
> +			continue;

I wonder if that shouldn't be an error?

> +		if (strcmp(default_timing, entry->full_name) == 0)
> +			disp->default_timing = disp->num_timings;

Hmm. Why not compare the node pointers rather than the name? Also, if
the parsing failed, then this can lead to default_timing being
uninitialized anyway...

> +		disp->timings[disp->num_timings] = st;
> +		disp->num_timings++;
> +	}

> +	if (disp->num_timings >= 0)
> +		pr_info("%s: got %d timings. Using timing #%d as default\n", __func__,
> +			disp->num_timings , disp->default_timing + 1);
> +	else
> +		pr_info("%s: no timings specified\n", __func__);

The message in the else clause is not necessarily true; there may have
been some specified, but they just couldn't be parsed.

> +int of_display_timings_exists(struct device_node *np)
> +{
> +	struct device_node *timings_np;
> +	struct device_node *default_np;
> +
> +	if (!np)
> +		return -EINVAL;
> +
> +	timings_np = of_parse_phandle(np, "display-timings", 0);
> +
> +	if (!timings_np)
> +		return -EINVAL;
> +
> +	default_np = of_parse_phandle(np, "default-timing", 0);
> +
> +	if (default_np)
> +		return 0;

If this function checks that a default-timing property exists, shouldn't
the function be named of_display_default_timing_exists()?

WARNING: multiple messages have this Message-ID (diff)
From: Stephen Warren <swarren@wwwdotorg.org>
To: Steffen Trumtrar <s.trumtrar@pengutronix.de>
Cc: devicetree-discuss@lists.ozlabs.org, linux-fbdev@vger.kernel.org,
	dri-devel@lists.freedesktop.org,
	Tomi Valkeinen <tomi.valkeinen@ti.com>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	linux-media@vger.kernel.org
Subject: Re: [PATCH 1/2 v6] of: add helper to parse display timings
Date: Thu, 04 Oct 2012 18:47:16 +0000	[thread overview]
Message-ID: <506DD9B4.40409@wwwdotorg.org> (raw)
In-Reply-To: <1349373560-11128-2-git-send-email-s.trumtrar@pengutronix.de>

On 10/04/2012 11:59 AM, Steffen Trumtrar wrote:

A patch description would be useful for something like this.

> diff --git a/Documentation/devicetree/bindings/video/display-timings.txt b/Documentation/devicetree/bindings/video/display-timings.txt
> new file mode 100644
...
> +Usage in backend
> +========

Everything before that point in the file looks fine to me.

Everything after this point in the file seems to be Linux-specific
implementation details. Does it really belong in the DT binding
documentation, rather than some Linux-specific documentation file?

> +struct drm_display_mode
> +===========> +
> +  +----------+---------------------------------------------+----------+-------+
> +  |          |                                             |          |       |  ↑
> +  |          |                                             |          |       |  |
> +  |          |                                             |          |       |  |
> +  +----------###############################################----------+-------+  |

I suspect the entire horizontal box above (and the entire vertical box
all the way down the left-hand side) should be on the bottom/right
instead of top/left. The reason I think this is because all of
vsync_start, vsync_end, vdisplay have to be referenced to some known
point, which is usually zero or the start of the timing definition, /or/
there would be some value indicating the size of the top marging/porch
in order to say where those other values are referenced to.

> +  |          #   ↑         ↑          ↑                    #          |       |  |
> +  |          #   |         |          |                    #          |       |  |
> +  |          #   |         |          |                    #          |       |  |
> +  |          #   |         |          |                    #          |       |  |
> +  |          #   |         |          |                    #          |       |  |
> +  |          #   |         |          |       hdisplay     #          |       |  |
> +  |          #<--+--------------------+------------------->#          |       |  |
> +  |          #   |         |          |                    #          |       |  |
> +  |          #   |vsync_start         |                    #          |       |  |
> +  |          #   |         |          |                    #          |       |  |
> +  |          #   |         |vsync_end |                    #          |       |  |
> +  |          #   |         |          |vdisplay            #          |       |  |
> +  |          #   |         |          |                    #          |       |  |
> +  |          #   |         |          |                    #          |       |  |
> +  |          #   |         |          |                    #          |       |  | vtotal
> +  |          #   |         |          |                    #          |       |  |
> +  |          #   |         |          |     hsync_start    #          |       |  |
> +  |          #<--+---------+----------+------------------------------>|       |  |
> +  |          #   |         |          |                    #          |       |  |
> +  |          #   |         |          |     hsync_end      #          |       |  |
> +  |          #<--+---------+----------+-------------------------------------->|  |
> +  |          #   |         |          ↓                    #          |       |  |
> +  +----------####|#########|################################----------+-------+  |
> +  |          |   |         |                               |          |       |  |
> +  |          |   |         |                               |          |       |  |
> +  |          |   ↓         |                               |          |       |  |
> +  +----------+-------------+-------------------------------+----------+-------+  |
> +  |          |             |                               |          |       |  |
> +  |          |             |                               |          |       |  |
> +  |          |             ↓                               |          |       |  ↓
> +  +----------+---------------------------------------------+----------+-------+
> +                                   htotal
> +   <------------------------------------------------------------------------->

> diff --git a/drivers/of/of_display_timings.c b/drivers/of/of_display_timings.c

> +static int parse_property(struct device_node *np, char *name,
> +				struct timing_entry *result)

> +	if (cells = 1)
> +		ret = of_property_read_u32_array(np, name, &result->typ, cells);

Should that branch not just set result->min/max to typ as well?
Presumably it'd prevent any code that interprets struct timing_entry
from having to check if those values were 0 or not?

> +	else if (cells = 3)
> +		ret = of_property_read_u32_array(np, name, &result->min, cells);

> +struct display_timings *of_get_display_timing_list(struct device_node *np)

> +	entry = of_parse_phandle(timings_np, "default-timing", 0);
> +
> +	if (!entry) {
> +		pr_info("%s: no default-timing specified\n", __func__);
> +		entry = of_find_node_by_name(np, "timing");

I don't think you want to require the node have an explicit name; I
don't recall the DT binding documentation making that a requirement.
Instead, can't you either just leave the default unset, or pick the
first DT child node, irrespective of name?

> +	if (!entry) {
> +		pr_info("%s: no timing specifications given\n", __func__);
> +		return disp;
> +	}

The DT bindings don't state that it's mandatory to have some timing
specified, although I agree that it makes sense in practice.

> +	for_each_child_of_node(timings_np, entry) {
> +		struct signal_timing *st;
> +
> +		st = of_get_display_timing(entry);
> +
> +		if (!st)
> +			continue;

I wonder if that shouldn't be an error?

> +		if (strcmp(default_timing, entry->full_name) = 0)
> +			disp->default_timing = disp->num_timings;

Hmm. Why not compare the node pointers rather than the name? Also, if
the parsing failed, then this can lead to default_timing being
uninitialized anyway...

> +		disp->timings[disp->num_timings] = st;
> +		disp->num_timings++;
> +	}

> +	if (disp->num_timings >= 0)
> +		pr_info("%s: got %d timings. Using timing #%d as default\n", __func__,
> +			disp->num_timings , disp->default_timing + 1);
> +	else
> +		pr_info("%s: no timings specified\n", __func__);

The message in the else clause is not necessarily true; there may have
been some specified, but they just couldn't be parsed.

> +int of_display_timings_exists(struct device_node *np)
> +{
> +	struct device_node *timings_np;
> +	struct device_node *default_np;
> +
> +	if (!np)
> +		return -EINVAL;
> +
> +	timings_np = of_parse_phandle(np, "display-timings", 0);
> +
> +	if (!timings_np)
> +		return -EINVAL;
> +
> +	default_np = of_parse_phandle(np, "default-timing", 0);
> +
> +	if (default_np)
> +		return 0;

If this function checks that a default-timing property exists, shouldn't
the function be named of_display_default_timing_exists()?

  reply	other threads:[~2012-10-04 18:47 UTC|newest]

Thread overview: 103+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-04 17:59 [PATCH 0/2 v6] of: add display helper Steffen Trumtrar
2012-10-04 17:59 ` Steffen Trumtrar
2012-10-04 17:59 ` Steffen Trumtrar
2012-10-04 17:59 ` [PATCH 1/2 v6] of: add helper to parse display timings Steffen Trumtrar
2012-10-04 17:59   ` Steffen Trumtrar
2012-10-04 17:59   ` Steffen Trumtrar
2012-10-04 18:47   ` Stephen Warren [this message]
2012-10-04 18:47     ` Stephen Warren
     [not found]     ` <506DD9B4.40409-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2012-10-05 16:16       ` Steffen Trumtrar
2012-10-05 16:16         ` Steffen Trumtrar
2012-10-05 16:16         ` Steffen Trumtrar
2012-10-05 16:21         ` Stephen Warren
2012-10-05 16:21           ` Stephen Warren
2012-10-05 16:38           ` Steffen Trumtrar
2012-10-05 16:38             ` Steffen Trumtrar
2012-10-07 13:38             ` Laurent Pinchart
2012-10-07 13:38               ` Laurent Pinchart
2012-10-08  7:34               ` Steffen Trumtrar
2012-10-08  7:34                 ` Steffen Trumtrar
     [not found]   ` <1349373560-11128-2-git-send-email-s.trumtrar-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2012-10-04 21:35     ` Guennadi Liakhovetski
2012-10-04 21:35       ` Guennadi Liakhovetski
2012-10-04 21:35       ` Guennadi Liakhovetski
2012-10-05  7:17       ` Robert Schwebel
2012-10-05  7:17         ` Robert Schwebel
2012-10-05 16:17       ` Stephen Warren
2012-10-05 16:17         ` Stephen Warren
2012-10-08  8:25         ` Guennadi Liakhovetski
2012-10-08  8:25           ` Guennadi Liakhovetski
2012-10-08  9:01           ` Tomi Valkeinen
2012-10-08  9:01             ` Tomi Valkeinen
2012-10-08 12:04             ` Laurent Pinchart
2012-10-08 12:04               ` Laurent Pinchart
2012-10-08 12:20               ` Tomi Valkeinen
2012-10-08 12:20                 ` Tomi Valkeinen
2012-10-08 16:12                 ` Stephen Warren
2012-10-08 16:12                   ` Stephen Warren
2012-10-08 16:12                   ` Stephen Warren
2012-10-08 16:34             ` Mitch Bradley
2012-10-08 16:34               ` Mitch Bradley
2012-10-08 16:34               ` Mitch Bradley
2012-10-08 16:10           ` Stephen Warren
2012-10-08 16:10             ` Stephen Warren
2012-10-08 17:33             ` Laurent Pinchart
2012-10-08 17:33               ` Laurent Pinchart
     [not found]       ` <Pine.LNX.4.64.1210042307300.3744-0199iw4Nj15frtckUFj5Ag@public.gmane.org>
2012-10-05 16:28         ` Steffen Trumtrar
2012-10-05 16:28           ` Steffen Trumtrar
2012-10-05 16:28           ` Steffen Trumtrar
2012-10-08  7:07   ` Tomi Valkeinen
2012-10-08  7:07     ` Tomi Valkeinen
2012-10-08  7:12     ` Tomi Valkeinen
2012-10-08  7:12       ` Tomi Valkeinen
2012-10-08  7:49     ` Steffen Trumtrar
2012-10-08  7:49       ` Steffen Trumtrar
     [not found]       ` <20121008074921.GB20800-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2012-10-11 19:31         ` Thierry Reding
2012-10-11 19:31           ` Thierry Reding
2012-10-11 19:31           ` Thierry Reding
2012-10-12  7:21           ` Steffen Trumtrar
2012-10-12  7:21             ` Steffen Trumtrar
2012-10-20 10:58   ` Thierry Reding
2012-10-20 10:58     ` Thierry Reding
2012-10-20 19:59   ` Thierry Reding
2012-10-20 19:59     ` Thierry Reding
2012-10-22  7:40     ` Steffen Trumtrar
2012-10-22  7:40       ` Steffen Trumtrar
2012-10-04 17:59 ` [PATCH 2/2 v6] of: add generic videomode description Steffen Trumtrar
2012-10-04 17:59   ` Steffen Trumtrar
2012-10-04 17:59   ` Steffen Trumtrar
2012-10-04 18:51   ` Stephen Warren
2012-10-04 18:51     ` Stephen Warren
2012-10-05 15:51     ` Steffen Trumtrar
2012-10-05 15:51       ` Steffen Trumtrar
2012-10-07 13:38       ` Laurent Pinchart
2012-10-07 13:38         ` Laurent Pinchart
2012-10-20 10:45         ` Thierry Reding
2012-10-20 10:45           ` Thierry Reding
2012-10-08  7:21   ` Tomi Valkeinen
2012-10-08  7:21     ` Tomi Valkeinen
2012-10-08  7:57     ` Steffen Trumtrar
2012-10-08  7:57       ` Steffen Trumtrar
2012-10-08 12:19       ` Laurent Pinchart
2012-10-08 12:19         ` Laurent Pinchart
2012-10-08 12:13   ` Laurent Pinchart
2012-10-08 12:13     ` Laurent Pinchart
2012-10-08 12:48     ` Steffen Trumtrar
2012-10-08 12:48       ` Steffen Trumtrar
2012-10-08 20:52       ` Laurent Pinchart
2012-10-08 20:52         ` Laurent Pinchart
2012-10-09  7:26         ` Steffen Trumtrar
2012-10-09  7:26           ` Steffen Trumtrar
     [not found]           ` <20121009072608.GA2519-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2012-10-20 10:54             ` Thierry Reding
2012-10-20 10:54               ` Thierry Reding
2012-10-20 10:54               ` Thierry Reding
2012-10-20 11:04   ` Thierry Reding
2012-10-20 11:04     ` Thierry Reding
2012-10-22  7:35     ` Steffen Trumtrar
2012-10-22  7:35       ` Steffen Trumtrar
     [not found] ` <1349373560-11128-1-git-send-email-s.trumtrar-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2012-10-15 10:54   ` [PATCH 0/2 v6] of: add display helper Leela Krishna Amudala
2012-10-15 10:55     ` Leela Krishna Amudala
2012-10-15 10:54     ` Leela Krishna Amudala
2012-10-15 14:17     ` Steffen Trumtrar
2012-10-15 14:17       ` Steffen Trumtrar
2012-10-20 11:35       ` Thierry Reding
2012-10-20 11:35         ` Thierry Reding

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=506DD9B4.40409@wwwdotorg.org \
    --to=swarren@wwwdotorg.org \
    --cc=devicetree-discuss@lists.ozlabs.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-fbdev@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=s.trumtrar@pengutronix.de \
    --cc=tomi.valkeinen@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.