All of lore.kernel.org
 help / color / mirror / Atom feed
From: Boris BREZILLON <boris.brezillon@free-electrons.com>
To: Thierry Reding <thierry.reding@gmail.com>
Cc: Randy Dunlap <rdunlap@infradead.org>,
	David Airlie <airlied@linux.ie>,
	Jean-Jacques Hiblot <jjhiblot@traphandler.com>,
	Nicolas Ferre <nicolas.ferre@atmel.com>,
	dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH 1/2] drm/panel: add support for simple-panel description definition using DT
Date: Mon, 12 May 2014 15:02:31 +0200	[thread overview]
Message-ID: <5370C667.6060106@free-electrons.com> (raw)
In-Reply-To: <1399645002-18000-2-git-send-email-boris.brezillon@free-electrons.com>


On 09/05/2014 16:16, Boris BREZILLON wrote:
> Currently, the only way to add new panel descriptions to the simple panel
> driver is to add new entries in the platform_of_match table.
>
> Add support for panel description retrieval from the DT.
>
> Signed-off-by: Boris BREZILLON <boris.brezillon@free-electrons.com>
> ---
>  drivers/gpu/drm/panel/Kconfig        |  1 +
>  drivers/gpu/drm/panel/panel-simple.c | 70 ++++++++++++++++++++++++++++++++++++
>  2 files changed, 71 insertions(+)
>
> diff --git a/drivers/gpu/drm/panel/Kconfig b/drivers/gpu/drm/panel/Kconfig
> index 4ec874d..4fe3d48 100644
> --- a/drivers/gpu/drm/panel/Kconfig
> +++ b/drivers/gpu/drm/panel/Kconfig
> @@ -1,6 +1,7 @@
>  config DRM_PANEL
>  	bool
>  	depends on DRM
> +	select VIDEOMODE_HELPERS
>  	help
>  	  Panel registration and lookup framework.
>  
> diff --git a/drivers/gpu/drm/panel/panel-simple.c b/drivers/gpu/drm/panel/panel-simple.c
> index 309f29e..fcf648d 100644
> --- a/drivers/gpu/drm/panel/panel-simple.c
> +++ b/drivers/gpu/drm/panel/panel-simple.c
> @@ -33,6 +33,10 @@
>  #include <drm/drm_mipi_dsi.h>
>  #include <drm/drm_panel.h>
>  
> +#include <video/display_timing.h>
> +#include <video/of_display_timing.h>
> +#include <video/videomode.h>
> +
>  struct panel_desc {
>  	const struct drm_display_mode *modes;
>  	unsigned int num_modes;
> @@ -168,6 +172,61 @@ static const struct drm_panel_funcs panel_simple_funcs = {
>  	.get_modes = panel_simple_get_modes,
>  };
>  
> +static struct panel_desc *of_panel_desc_init(struct device *dev)
> +{
> +	struct display_timings *timings;
> +	struct panel_desc *desc;
> +	u32 width, height;
> +	int err;
> +	int i;
> +
> +	err = of_property_read_u32(dev->of_node, "width", &width);
> +	if (err)
> +		return ERR_PTR(err);
> +
> +	err = of_property_read_u32(dev->of_node, "height", &height);
> +	if (err)
> +		return ERR_PTR(err);
> +
> +	desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL);
> +	if (!desc)
> +		return ERR_PTR(-ENOMEM);
> +
> +	timings = of_get_display_timings(dev->of_node);
> +	if (timings) {
> +		struct drm_display_mode *modes =
> +				devm_kzalloc(dev,
> +					     timings->num_timings *
> +					     sizeof(*desc->modes),
> +					     GFP_KERNEL);
> +
> +		if (!modes)
> +			return ERR_PTR(-ENOMEM);
> +
> +		for (i = 0; i < timings->num_timings; i++) {
> +			struct videomode vm;
> +
> +			if (videomode_from_timings(timings, &vm, i))
> +				break;
> +
> +			drm_display_mode_from_videomode(&vm, modes + i);
> +
> +			modes[i].type = DRM_MODE_TYPE_DRIVER;
> +
> +			if (timings->native_mode == i)
> +				modes[i].type |= DRM_MODE_TYPE_PREFERRED;
> +			desc->num_modes++;
> +		}

Oops, I forgot to add:
                          desc->modes = modes;

> +
> +		kfree(timings);
> +	}
> +
> +	desc->size.width = width;
> +	desc->size.height = height;
> +
> +	return desc;
> +}
> +
>  static int panel_simple_probe(struct device *dev, const struct panel_desc *desc)
>  {
>  	struct device_node *backlight, *ddc;
> @@ -178,6 +237,17 @@ static int panel_simple_probe(struct device *dev, const struct panel_desc *desc)
>  	if (!panel)
>  		return -ENOMEM;
>  
> +	if (!desc) {
> +		desc = of_panel_desc_init(dev);
> +		/*
> +		 * Do not fail on DT panel desc retrieval error because
> +		 * some systems do not need a panel description to work
> +		 * properly.
> +		 */
> +		if (IS_ERR(desc))
> +			desc = NULL;
> +	}
> +
>  	panel->enabled = false;
>  	panel->desc = desc;
>  

-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com


  reply	other threads:[~2014-05-12 13:02 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-09 14:16 [RFC PATCH 0/2] drm/panel: add simple-panel description using DT Boris BREZILLON
2014-05-09 14:16 ` [RFC PATCH 1/2] drm/panel: add support for simple-panel description definition " Boris BREZILLON
2014-05-12 13:02   ` Boris BREZILLON [this message]
2014-05-09 14:16 ` [RFC PATCH 2/2] drm/panel: update simple-panel DT bindings doc with panel desc properties Boris BREZILLON
2014-05-13  7:53   ` Thierry Reding
2014-05-13  7:53     ` Thierry Reding
2014-05-13  7:51 ` [RFC PATCH 0/2] drm/panel: add simple-panel description using DT Thierry Reding
2014-05-13  7:51   ` Thierry Reding
2014-05-13  9:09   ` Andrzej Hajda
2014-05-13  9:20     ` Thierry Reding
2014-05-13  9:20       ` Thierry Reding
2014-05-16  7:29   ` Boris BREZILLON

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=5370C667.6060106@free-electrons.com \
    --to=boris.brezillon@free-electrons.com \
    --cc=airlied@linux.ie \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jjhiblot@traphandler.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nicolas.ferre@atmel.com \
    --cc=rdunlap@infradead.org \
    --cc=thierry.reding@gmail.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.