linux-samsung-soc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Sam Ravnborg <sam@ravnborg.org>
Cc: dri-devel@lists.freedesktop.org,
	Thierry Reding <thierry.reding@gmail.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Abhinav Kumar <abhinavk@codeaurora.org>,
	Andrzej Hajda <a.hajda@samsung.com>,
	Benjamin Gaignard <benjamin.gaignard@linaro.org>,
	Boris Brezillon <boris.brezillon@collabora.com>,
	Daniel Vetter <daniel@ffwll.ch>, David Airlie <airlied@linux.ie>,
	Jagan Teki <jagan@amarulasolutions.com>,
	Jitao Shi <jitao.shi@mediatek.com>,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org,
	linux-renesas-soc@vger.kernel.org,
	linux-rockchip@lists.infradead.org,
	linux-samsung-soc@vger.kernel.org, linux-tegra@vger.kernel.org,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Maxime Ripard <mripard@kernel.org>,
	Neil Armstrong <narmstrong@baylibre.com>,
	NXP Linux Team <linux-imx@nxp.com>,
	Pengutronix Kernel Team <kernel@pengutronix.de>,
	Purism Kernel Team <kernel@puri.sm>, Sean Paul <sean@poorly.run>,
	Stefan Agner <stefan@agner.ch>,
	Tomi Valkeinen <tomi.valkeinen@ti.com>,
	Maxime Ripard <maxime.ripard@bootlin.com>
Subject: Re: [PATCH v2 02/25] drm/panel: add backlight support
Date: Mon, 9 Dec 2019 02:55:54 +0200	[thread overview]
Message-ID: <20191209005554.GK14311@pendragon.ideasonboard.com> (raw)
In-Reply-To: <20191207140353.23967-3-sam@ravnborg.org>

Hi Sam,

Thank you for the patch.

On Sat, Dec 07, 2019 at 03:03:30PM +0100, Sam Ravnborg wrote:
> Panels often supports backlight as specified in a device tree.

s/supports/support/

> Update the drm_panel infrastructure to support this to
> simplify the drivers.
> 
> With this the panel driver just needs to add the following to the
> probe() function:
> 
>     err = drm_panel_of_backlight(panel);
>     if (err)
>             return err;
> 
> Then drm_panel will handle all the rest.
> 
> There is one caveat with the backlight support.
> If drm_panel_(enable|disable) are called multiple times
> in row then backlight_(enable|disable) will be called multiple times.

s/in row/in a row/

> The above will happen when a panel drivers unconditionally
> calls drm_panel_disable() in their shutdown() function,
> whan the panel is already disabled and then shutdown() is called.
> 
> Reading the backlight code it seems safe to call
> the backlight_(enable|disable) several times.
> 
> v3:
> - Improve comments, fix grammar (Laurent)
> - Do not fail in drm_panel_of_backlight() if no DT support (Laurent)
> - Log if backlight_(enable|disable) fails (Laurent)
> - Improve drm_panel_of_backlight() docs
> - Updated changelog with backlight analysis (triggered by Laurent)
> 
> v2:
> - Drop test of CONFIG_DRM_PANEL in header-file (Laurent)
> - do not enable backlight if ->enable() returns an error
> 
> Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
> Cc: Thierry Reding <thierry.reding@gmail.com>
> Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> Cc: Maxime Ripard <maxime.ripard@bootlin.com>
> Cc: Sean Paul <sean@poorly.run>
> Cc: David Airlie <airlied@linux.ie>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> ---
>  drivers/gpu/drm/drm_panel.c | 58 ++++++++++++++++++++++++++++++++++++-
>  include/drm/drm_panel.h     | 25 ++++++++++++++++
>  2 files changed, 82 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/drm_panel.c b/drivers/gpu/drm/drm_panel.c
> index 4ab7229fb22b..c312d5eb214d 100644
> --- a/drivers/gpu/drm/drm_panel.c
> +++ b/drivers/gpu/drm/drm_panel.c
> @@ -21,11 +21,13 @@
>   * DEALINGS IN THE SOFTWARE.
>   */
>  
> +#include <linux/backlight.h>
>  #include <linux/err.h>
>  #include <linux/module.h>
>  
>  #include <drm/drm_crtc.h>
>  #include <drm/drm_panel.h>
> +#include <drm/drm_print.h>
>  
>  static DEFINE_MUTEX(panel_lock);
>  static LIST_HEAD(panel_list);
> @@ -196,11 +198,20 @@ EXPORT_SYMBOL(drm_panel_unprepare);
>   */
>  int drm_panel_enable(struct drm_panel *panel)
>  {
> +	int ret = 0;
> +
>  	if (!panel)
>  		return -EINVAL;
>  
>  	if (panel->funcs && panel->funcs->enable)
> -		return panel->funcs->enable(panel);
> +		ret = panel->funcs->enable(panel);
> +
> +	if (ret < 0)
> +		return ret;

You can move this within the above if () block and avoid initializing
ret to 0:

	if (panel->funcs && panel->funcs->enable) {
		ret = panel->funcs->enable(panel);
		if (ret < 0)
			return ret;
	}

With these small issues addressed,

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> +	ret = backlight_enable(panel->backlight);
> +	if (ret < 0)
> +		DRM_DEV_INFO(panel->dev, "failed to enable backlight: %d\n", ret);
>  
>  	return 0;
>  }
> @@ -218,9 +229,15 @@ EXPORT_SYMBOL(drm_panel_enable);
>   */
>  int drm_panel_disable(struct drm_panel *panel)
>  {
> +	int ret;
> +
>  	if (!panel)
>  		return -EINVAL;
>  
> +	ret = backlight_disable(panel->backlight);
> +	if (ret < 0)
> +		DRM_DEV_INFO(panel->dev, "failed to disable backlight: %d\n", ret);
> +
>  	if (panel->funcs && panel->funcs->disable)
>  		return panel->funcs->disable(panel);
>  
> @@ -289,6 +306,45 @@ struct drm_panel *of_drm_find_panel(const struct device_node *np)
>  EXPORT_SYMBOL(of_drm_find_panel);
>  #endif
>  
> +#ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
> +/**
> + * drm_panel_of_backlight - use backlight device node for backlight
> + * @panel: DRM panel
> + *
> + * Use this function to enable backlight handling if your panel
> + * uses device tree and has a backlight phandle.
> + *
> + * When the panel is enabled backlight will be enabled after a
> + * successfull call to &drm_panel_funcs.enable()
> + *
> + * When the panel is disabled backlight will be disabled before the
> + * call to &drm_panel_funcs.disable().
> + *
> + * A typical implementation for a panel driver supporting device tree
> + * will call this function at probe time. Backlight will then be handled
> + * transparently without requiring any intervention from the driver.
> + * drm_panel_of_backlight() must be called after the call to drm_panel_init().
> + *
> + * Return: 0 on success or a negative error code on failure.
> + */
> +int drm_panel_of_backlight(struct drm_panel *panel)
> +{
> +	struct backlight_device *backlight;
> +
> +	if (!panel || !panel->dev)
> +		return -EINVAL;
> +
> +	backlight = devm_of_find_backlight(panel->dev);
> +
> +	if (IS_ERR(backlight))
> +                return PTR_ERR(backlight);
> +
> +	panel->backlight = backlight;
> +	return 0;
> +}
> +EXPORT_SYMBOL(drm_panel_of_backlight);
> +#endif
> +
>  MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>");
>  MODULE_DESCRIPTION("DRM panel infrastructure");
>  MODULE_LICENSE("GPL and additional rights");
> diff --git a/include/drm/drm_panel.h b/include/drm/drm_panel.h
> index d71655b2634c..c751c9b17df0 100644
> --- a/include/drm/drm_panel.h
> +++ b/include/drm/drm_panel.h
> @@ -28,6 +28,7 @@
>  #include <linux/errno.h>
>  #include <linux/list.h>
>  
> +struct backlight_device;
>  struct device_node;
>  struct drm_connector;
>  struct drm_device;
> @@ -59,6 +60,10 @@ struct display_timing;
>   *
>   * To save power when no video data is transmitted, a driver can power down
>   * the panel. This is the job of the .unprepare() function.
> + *
> + * Backlight can be handled automatically if configured using
> + * drm_panel_of_backlight(). Then the driver does not need to implement the
> + * functionality to enable/disable backlight.
>   */
>  struct drm_panel_funcs {
>  	/**
> @@ -146,6 +151,17 @@ struct drm_panel {
>  	 */
>  	struct device *dev;
>  
> +	/**
> +	 * @backlight:
> +	 *
> +	 * Backlight device, used to turn on backlight after the call
> +	 * to enable(), and to turn off backlight before the call to
> +	 * disable().
> +	 * backlight is set by drm_panel_of_backlight() and drivers
> +	 * shall not assign it.
> +	 */
> +	struct backlight_device *backlight;
> +
>  	/**
>  	 * @funcs:
>  	 *
> @@ -197,4 +213,13 @@ static inline struct drm_panel *of_drm_find_panel(const struct device_node *np)
>  }
>  #endif
>  
> +#if IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE)
> +int drm_panel_of_backlight(struct drm_panel *panel);
> +#else
> +static inline int drm_panel_of_backlight(struct drm_panel *panel)
> +{
> +	return 0;
> +}
> +#endif
> +
>  #endif

-- 
Regards,

Laurent Pinchart

  reply	other threads:[~2019-12-09  0:56 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-07 14:03 [PATCH v2 0/25] drm/panel infrastructure + backlight update Sam Ravnborg
2019-12-07 14:03 ` [PATCH v2 01/25] drm/drm_panel: no error when no callback Sam Ravnborg
2019-12-09  0:50   ` Laurent Pinchart
2019-12-07 14:03 ` [PATCH v2 02/25] drm/panel: add backlight support Sam Ravnborg
2019-12-09  0:55   ` Laurent Pinchart [this message]
2019-12-13 13:30   ` Linus Walleij
2019-12-07 14:03 ` [PATCH v2 03/25] drm/panel: simple: use drm_panel " Sam Ravnborg
2019-12-07 14:03 ` [PATCH v2 04/25] drm: get drm_bridge_panel connector via helper Sam Ravnborg
2019-12-07 14:03 ` [PATCH v2 05/25] drm/panel: add drm_connector argument to get_modes() Sam Ravnborg
2019-12-07 14:03 ` [PATCH v2 07/25] drm/panel: drop drm_device from drm_panel Sam Ravnborg
2019-12-07 14:03 ` [PATCH v2 08/25] drm/panel: feiyang-fy07024di26a30d: use drm_panel backlight support Sam Ravnborg
2019-12-07 14:03 ` [PATCH v2 09/25] drm/panel: ilitek-ili9881c: " Sam Ravnborg
2019-12-07 14:03 ` [PATCH v2 10/25] drm/panel: innolux-p079zca: " Sam Ravnborg
2019-12-07 14:03 ` [PATCH v2 11/25] drm/panel: kingdisplay-kd097d04: " Sam Ravnborg
2019-12-07 14:03 ` [PATCH v2 12/25] drm/panel: lvds: " Sam Ravnborg
2019-12-07 14:03 ` [PATCH v2 13/25] drm/panel: olimex-lcd-olinuxino: " Sam Ravnborg
2019-12-07 14:03 ` [PATCH v2 14/25] drm/panel: osd-osd101t2587-53ts: " Sam Ravnborg
2019-12-07 14:03 ` [PATCH v2 15/25] drm/panel: panasonic-vvx10f034n00: " Sam Ravnborg
2019-12-07 14:03 ` [PATCH v2 16/25] drm/panel: raydium-rm68200: " Sam Ravnborg
2019-12-07 14:03 ` [PATCH v2 17/25] drm/panel: rocktech-jh057n00900: " Sam Ravnborg
2019-12-07 14:03 ` [PATCH v2 18/25] drm/panel: ronbo-rb070d30: " Sam Ravnborg
2019-12-07 14:03 ` [PATCH v2 19/25] drm/panel: seiko-43wvf1g: " Sam Ravnborg
2019-12-07 14:03 ` [PATCH v2 20/25] drm/panel: sharp-lq101r1sx01: " Sam Ravnborg
2019-12-07 14:03 ` [PATCH v2 21/25] drm/panel: sharp-ls043t1le01: " Sam Ravnborg
2019-12-07 14:03 ` [PATCH v2 22/25] drm/panel: sitronix-st7701: " Sam Ravnborg
2019-12-07 14:03 ` [PATCH v2 23/25] drm/panel: sitronix-st7789v: " Sam Ravnborg
2019-12-07 14:03 ` [PATCH v2 24/25] drm/panel: tpo-td028ttec1: " Sam Ravnborg
2019-12-07 14:03 ` [PATCH v2 25/25] drm/panel: tpo-tpg110: " Sam Ravnborg
2019-12-09 22:04 ` [PATCH v2 0/25] drm/panel infrastructure + backlight update Sam Ravnborg

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=20191209005554.GK14311@pendragon.ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=a.hajda@samsung.com \
    --cc=abhinavk@codeaurora.org \
    --cc=airlied@linux.ie \
    --cc=benjamin.gaignard@linaro.org \
    --cc=boris.brezillon@collabora.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jagan@amarulasolutions.com \
    --cc=jitao.shi@mediatek.com \
    --cc=kernel@pengutronix.de \
    --cc=kernel@puri.sm \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-imx@nxp.com \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=maxime.ripard@bootlin.com \
    --cc=mripard@kernel.org \
    --cc=narmstrong@baylibre.com \
    --cc=sam@ravnborg.org \
    --cc=sean@poorly.run \
    --cc=stefan@agner.ch \
    --cc=thierry.reding@gmail.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).