Assuming this is using the firmware interface then yes it's fine. If it is using the i2c directly then it's possible to clash with the GPU driving the camera<div><br></div><div>Gordon<br><br><div class="gmail_quote"><div dir="ltr">On Thu, 20 Dec 2018, 18:33 Eric Anholt, <<a href="mailto:eric@anholt.net">eric@anholt.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Nicolas Saenz Julienne <<a href="mailto:nsaenzjulienne@suse.de" target="_blank">nsaenzjulienne@suse.de</a>> writes:<br>
<br>
> This patch exposes backlight control into userspace by creating a<br>
> backlight device instead of directly accessing the PWM registers.<br>
><br>
> The backlight driver can't go on a separate file as it shares the I2C<br>
> bus & address with the panel.<br>
<br>
I remember some concerns from Gordon about exposing the backlight PWM.<br>
Gordon, care to chime in on this?<br>
<br>
> Signed-off-by: Nicolas Saenz Julienne <<a href="mailto:nsaenzjulienne@suse.de" target="_blank">nsaenzjulienne@suse.de</a>><br>
> ---<br>
> v1 -> v2:<br>
> - Add Kconfig dependency with BACKLIGHT_CLASS_DEVICE<br>
><br>
> drivers/gpu/drm/panel/Kconfig | 1 +<br>
> .../drm/panel/panel-raspberrypi-touchscreen.c | 33 +++++++++++++++++--<br>
> 2 files changed, 32 insertions(+), 2 deletions(-)<br>
><br>
> diff --git a/drivers/gpu/drm/panel/Kconfig b/drivers/gpu/drm/panel/Kconfig<br>
> index 6020c30a33b3..1ce35483f342 100644<br>
> --- a/drivers/gpu/drm/panel/Kconfig<br>
> +++ b/drivers/gpu/drm/panel/Kconfig<br>
> @@ -112,6 +112,7 @@ config DRM_PANEL_PANASONIC_VVX10F034N00<br>
> config DRM_PANEL_RASPBERRYPI_TOUCHSCREEN<br>
> tristate "Raspberry Pi 7-inch touchscreen panel"<br>
> depends on DRM_MIPI_DSI<br>
> + depends on BACKLIGHT_CLASS_DEVICE<br>
> help<br>
> Say Y here if you want to enable support for the Raspberry<br>
> Pi 7" Touchscreen. To compile this driver as a module,<br>
> diff --git a/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c b/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c<br>
> index 2c9c9722734f..838b5c8767bc 100644<br>
> --- a/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c<br>
> +++ b/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c<br>
> @@ -52,6 +52,7 @@<br>
> #include <linux/of_device.h><br>
> #include <linux/of_graph.h><br>
> #include <linux/pm.h><br>
> +#include <linux/backlight.h><br>
> <br>
> #include <drm/drm_panel.h><br>
> #include <drm/drmP.h><br>
> @@ -196,6 +197,7 @@ struct rpi_touchscreen {<br>
> struct drm_panel base;<br>
> struct mipi_dsi_device *dsi;<br>
> struct i2c_client *i2c;<br>
> + struct backlight_device *backlight;<br>
> };<br>
> <br>
> static const struct drm_display_mode rpi_touchscreen_modes[] = {<br>
> @@ -256,7 +258,8 @@ static int rpi_touchscreen_disable(struct drm_panel *panel)<br>
> {<br>
> struct rpi_touchscreen *ts = panel_to_ts(panel);<br>
> <br>
> - rpi_touchscreen_i2c_write(ts, REG_PWM, 0);<br>
> + ts->backlight->props.brightness = 0;<br>
> + backlight_update_status(ts->backlight);<br>
> <br>
> rpi_touchscreen_i2c_write(ts, REG_POWERON, 0);<br>
> udelay(1);<br>
> @@ -300,7 +303,8 @@ static int rpi_touchscreen_enable(struct drm_panel *panel)<br>
> msleep(100);<br>
> <br>
> /* Turn on the backlight. */<br>
> - rpi_touchscreen_i2c_write(ts, REG_PWM, 255);<br>
> + ts->backlight->props.brightness = 255;<br>
> + backlight_update_status(ts->backlight);<br>
> <br>
> /* Default to the same orientation as the closed source<br>
> * firmware used for the panel. Runtime rotation<br>
> @@ -358,12 +362,26 @@ static const struct drm_panel_funcs rpi_touchscreen_funcs = {<br>
> .get_modes = rpi_touchscreen_get_modes,<br>
> };<br>
> <br>
> +static int raspberrypi_bl_update_status(struct backlight_device *bl)<br>
> +{<br>
> + struct rpi_touchscreen *ts = bl_get_data(bl);<br>
> +<br>
> + rpi_touchscreen_i2c_write(ts, REG_PWM, bl->props.brightness);<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static const struct backlight_ops raspberrypi_bl_ops = {<br>
> + .update_status = raspberrypi_bl_update_status,<br>
> +};<br>
> +<br>
> static int rpi_touchscreen_probe(struct i2c_client *i2c,<br>
> const struct i2c_device_id *id)<br>
> {<br>
> struct device *dev = &i2c->dev;<br>
> struct rpi_touchscreen *ts;<br>
> struct device_node *endpoint, *dsi_host_node;<br>
> + struct backlight_properties props;<br>
> struct mipi_dsi_host *host;<br>
> int ret, ver;<br>
> struct mipi_dsi_device_info info = {<br>
> @@ -398,6 +416,17 @@ static int rpi_touchscreen_probe(struct i2c_client *i2c,<br>
> /* Turn off at boot, so we can cleanly sequence powering on. */<br>
> rpi_touchscreen_i2c_write(ts, REG_POWERON, 0);<br>
> <br>
> + memset(&props, 0, sizeof(props));<br>
> + props.type = BACKLIGHT_RAW;<br>
> + props.max_brightness = 255;<br>
> + ts->backlight = devm_backlight_device_register(dev, dev_name(dev), dev,<br>
> + ts, &raspberrypi_bl_ops,<br>
> + &props);<br>
> + if (IS_ERR(ts->backlight)) {<br>
> + dev_err(dev, "Failed to create backlight device\n");<br>
> + return PTR_ERR(ts->backlight);<br>
> + }<br>
> +<br>
> /* Look up the DSI host. It needs to probe before we do. */<br>
> endpoint = of_graph_get_next_endpoint(dev->of_node, NULL);<br>
> dsi_host_node = of_graph_get_remote_port_parent(endpoint);<br>
> -- <br>
> 2.19.2<br>
</blockquote></div></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><span style="color:rgb(136,136,136);font-family:arial,sans-serif;font-size:12.8px;line-height:normal">--</span><br style="color:rgb(136,136,136);font-family:arial,sans-serif;font-size:12.8px;line-height:normal"><span style="color:rgb(136,136,136);font-family:arial,sans-serif;font-size:12.8px;line-height:normal">Director of Software Engineering, Raspberry Pi (Trading) Limited</span><br style="color:rgb(136,136,136);font-family:arial,sans-serif;font-size:12.8px;line-height:normal"><span style="color:rgb(136,136,136);font-family:arial,sans-serif;font-size:12.8px;line-height:normal">t: </span><a href="tel:%2B44%20%280%29%201223%20322633" value="+441223322633" style="color:rgb(17,85,204);font-family:arial,sans-serif;font-size:12.8px;line-height:normal">+44 (0) 1223 322633</a><br style="color:rgb(136,136,136);font-family:arial,sans-serif;font-size:12.8px;line-height:normal"><span style="color:rgb(136,136,136);font-family:arial,sans-serif;font-size:12.8px;line-height:normal">m: </span><a href="tel:%2B44%20%280%29%207450%20946289" value="+447450946289" style="color:rgb(17,85,204);font-family:arial,sans-serif;font-size:12.8px;line-height:normal">+44 (0) 7450 946289</a><br style="color:rgb(136,136,136);font-family:arial,sans-serif;font-size:12.8px;line-height:normal"><span style="color:rgb(136,136,136);font-family:arial,sans-serif;font-size:12.8px;line-height:normal">e: </span><a href="mailto:gordon@raspberrypi.org" style="color:rgb(17,85,204);font-family:arial,sans-serif;font-size:12.8px;line-height:normal">gordon@raspberrypi.org</a><br style="color:rgb(136,136,136);font-family:arial,sans-serif;font-size:12.8px;line-height:normal"><span style="color:rgb(136,136,136);font-family:arial,sans-serif;font-size:12.8px;line-height:normal">w: </span><a href="http://www.raspberrypi.org/" rel="noreferrer" target="_blank" style="color:rgb(17,85,204);font-family:arial,sans-serif;font-size:12.8px;line-height:normal">www.raspberrypi.org</a><br style="color:rgb(136,136,136);font-family:arial,sans-serif;font-size:12.8px;line-height:normal"><div><br><br style="color:rgb(136,136,136);font-family:arial,sans-serif;font-size:12.8px;line-height:normal"></div></div></div>