public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Eric Anholt <eric@anholt.net>
To: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>,
	Thierry Reding <thierry.reding@gmail.com>
Cc: afaerber@suse.de, agraf@suse.de,
	linux-rpi-kernel@lists.infradead.org, stefan.wahren@i2se.com,
	Nicolas Saenz Julienne <nsaenzjulienne@suse.de>,
	David Airlie <airlied@linux.ie>,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	Gordon Hollingworth <gordon@raspberrypi.org>
Subject: Re: [PATCH v2] drm/panel: rpi-touchscreen: Add backlight support
Date: Thu, 20 Dec 2018 10:32:55 -0800	[thread overview]
Message-ID: <87tvj8dp60.fsf@anholt.net> (raw)
In-Reply-To: <20181219112033.31064-1-nsaenzjulienne@suse.de>

[-- Attachment #1: Type: text/plain, Size: 4514 bytes --]

Nicolas Saenz Julienne <nsaenzjulienne@suse.de> writes:

> This patch exposes backlight control into userspace by creating a
> backlight device instead of directly accessing the PWM registers.
>
> The backlight driver can't go on a separate file as it shares the I2C
> bus & address with the panel.

I remember some concerns from Gordon about exposing the backlight PWM.
Gordon, care to chime in on this?

> Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
> ---
> v1 -> v2:
>   - Add Kconfig dependency with BACKLIGHT_CLASS_DEVICE
>
>  drivers/gpu/drm/panel/Kconfig                 |  1 +
>  .../drm/panel/panel-raspberrypi-touchscreen.c | 33 +++++++++++++++++--
>  2 files changed, 32 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/panel/Kconfig b/drivers/gpu/drm/panel/Kconfig
> index 6020c30a33b3..1ce35483f342 100644
> --- a/drivers/gpu/drm/panel/Kconfig
> +++ b/drivers/gpu/drm/panel/Kconfig
> @@ -112,6 +112,7 @@ config DRM_PANEL_PANASONIC_VVX10F034N00
>  config DRM_PANEL_RASPBERRYPI_TOUCHSCREEN
>  	tristate "Raspberry Pi 7-inch touchscreen panel"
>  	depends on DRM_MIPI_DSI
> +	depends on BACKLIGHT_CLASS_DEVICE
>  	help
>  	  Say Y here if you want to enable support for the Raspberry
>  	  Pi 7" Touchscreen.  To compile this driver as a module,
> diff --git a/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c b/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c
> index 2c9c9722734f..838b5c8767bc 100644
> --- a/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c
> +++ b/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c
> @@ -52,6 +52,7 @@
>  #include <linux/of_device.h>
>  #include <linux/of_graph.h>
>  #include <linux/pm.h>
> +#include <linux/backlight.h>
>  
>  #include <drm/drm_panel.h>
>  #include <drm/drmP.h>
> @@ -196,6 +197,7 @@ struct rpi_touchscreen {
>  	struct drm_panel base;
>  	struct mipi_dsi_device *dsi;
>  	struct i2c_client *i2c;
> +	struct backlight_device *backlight;
>  };
>  
>  static const struct drm_display_mode rpi_touchscreen_modes[] = {
> @@ -256,7 +258,8 @@ static int rpi_touchscreen_disable(struct drm_panel *panel)
>  {
>  	struct rpi_touchscreen *ts = panel_to_ts(panel);
>  
> -	rpi_touchscreen_i2c_write(ts, REG_PWM, 0);
> +	ts->backlight->props.brightness = 0;
> +	backlight_update_status(ts->backlight);
>  
>  	rpi_touchscreen_i2c_write(ts, REG_POWERON, 0);
>  	udelay(1);
> @@ -300,7 +303,8 @@ static int rpi_touchscreen_enable(struct drm_panel *panel)
>  	msleep(100);
>  
>  	/* Turn on the backlight. */
> -	rpi_touchscreen_i2c_write(ts, REG_PWM, 255);
> +	ts->backlight->props.brightness = 255;
> +	backlight_update_status(ts->backlight);
>  
>  	/* Default to the same orientation as the closed source
>  	 * firmware used for the panel.  Runtime rotation
> @@ -358,12 +362,26 @@ static const struct drm_panel_funcs rpi_touchscreen_funcs = {
>  	.get_modes = rpi_touchscreen_get_modes,
>  };
>  
> +static int raspberrypi_bl_update_status(struct backlight_device *bl)
> +{
> +	struct rpi_touchscreen *ts = bl_get_data(bl);
> +
> +	rpi_touchscreen_i2c_write(ts, REG_PWM, bl->props.brightness);
> +
> +	return 0;
> +}
> +
> +static const struct backlight_ops raspberrypi_bl_ops = {
> +	.update_status = raspberrypi_bl_update_status,
> +};
> +
>  static int rpi_touchscreen_probe(struct i2c_client *i2c,
>  				 const struct i2c_device_id *id)
>  {
>  	struct device *dev = &i2c->dev;
>  	struct rpi_touchscreen *ts;
>  	struct device_node *endpoint, *dsi_host_node;
> +	struct backlight_properties props;
>  	struct mipi_dsi_host *host;
>  	int ret, ver;
>  	struct mipi_dsi_device_info info = {
> @@ -398,6 +416,17 @@ static int rpi_touchscreen_probe(struct i2c_client *i2c,
>  	/* Turn off at boot, so we can cleanly sequence powering on. */
>  	rpi_touchscreen_i2c_write(ts, REG_POWERON, 0);
>  
> +	memset(&props, 0, sizeof(props));
> +	props.type = BACKLIGHT_RAW;
> +	props.max_brightness = 255;
> +	ts->backlight = devm_backlight_device_register(dev, dev_name(dev), dev,
> +						       ts, &raspberrypi_bl_ops,
> +						       &props);
> +	if (IS_ERR(ts->backlight)) {
> +		dev_err(dev, "Failed to create backlight device\n");
> +		return PTR_ERR(ts->backlight);
> +	}
> +
>  	/* Look up the DSI host.  It needs to probe before we do. */
>  	endpoint = of_graph_get_next_endpoint(dev->of_node, NULL);
>  	dsi_host_node = of_graph_get_remote_port_parent(endpoint);
> -- 
> 2.19.2

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

  reply	other threads:[~2018-12-20 18:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-19 11:20 [PATCH v2] drm/panel: rpi-touchscreen: Add backlight support Nicolas Saenz Julienne
2018-12-20 18:32 ` Eric Anholt [this message]
     [not found]   ` <CAPLZx4kd9RZtUKySDhk9RHOWPL2P=GG_g0GP3NweZ-UR-a3MSQ@mail.gmail.com>
2018-12-20 19:06     ` Nicolas Saenz Julienne

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=87tvj8dp60.fsf@anholt.net \
    --to=eric@anholt.net \
    --cc=afaerber@suse.de \
    --cc=agraf@suse.de \
    --cc=airlied@linux.ie \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gordon@raspberrypi.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=nsaenzjulienne@suse.de \
    --cc=stefan.wahren@i2se.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox