Hi Neil, Le mercredi 05 juillet 2023 à 15:57 +0200, Neil Armstrong a écrit : > On 03/07/2023 23:47, Paul Cercueil wrote: > > Register a backlight device to be able to switch between all the > > gamma > > levels. > > > > Signed-off-by: Paul Cercueil <paul@xxxxxxxxxxxxxxx> > > --- > > drivers/gpu/drm/panel/panel-samsung-ld9040.c | 40 > > ++++++++++++++++++++ > > 1 file changed, 40 insertions(+) > > > > diff --git a/drivers/gpu/drm/panel/panel-samsung-ld9040.c > > b/drivers/gpu/drm/panel/panel-samsung-ld9040.c > > index 7fd9444b42c5..b4f87d6244cb 100644 > > --- a/drivers/gpu/drm/panel/panel-samsung-ld9040.c > > +++ b/drivers/gpu/drm/panel/panel-samsung-ld9040.c > > @@ -8,6 +8,7 @@ > > * Andrzej Hajda <a.hajda@xxxxxxxxxxx> > > */ > > > > +#include <linux/backlight.h> > > #include <linux/delay.h> > > #include <linux/gpio/consumer.h> > > #include <linux/module.h> > > @@ -311,8 +312,40 @@ static int ld9040_parse_dt(struct ld9040 *ctx) > > return 0; > > } > > > > +static int ld9040_bl_update_status(struct backlight_device *dev) > > +{ > > + struct ld9040 *ctx = dev_get_drvdata(&dev->dev); > > + > > + ctx->brightness = dev->props.brightness; > > + ld9040_brightness_set(ctx); > > + > > + return 0; > > +} > > + > > +static int ld9040_bl_get_intensity(struct backlight_device *dev) > > +{ > > + if (dev->props.fb_blank == FB_BLANK_UNBLANK && > > + dev->props.power == FB_BLANK_UNBLANK) > > + return dev->props.brightness; > > + > > + return 0; > > +} > > You can totally drop the _get_brightness. The current behaviour is to return 0 when the framebuffer is blanked. A few drivers do that so I thought it was the norm; and the backlight core doesn't do that by default (and just uses dev->props.brightness). It is not clear to me if that's the preferred behaviour. The "backlight_get_brightness" function in backlight.h seems to suggest that the current behaviour is correct, unless it is not supposed to be used in the backlight_ops.get_brightness() callback. Then in that case some other drivers get it wrong too. Cheers, -Paul > Neil > > > + > > +static const struct backlight_ops ld9040_bl_ops = { > > + .get_brightness = ld9040_bl_get_intensity, > > + .update_status = ld9040_bl_update_status, > > +}; > > + > > +static const struct backlight_properties ld9040_bl_props = { > > + .type = BACKLIGHT_RAW, > > + .scale = BACKLIGHT_SCALE_NON_LINEAR, > > + .max_brightness = ARRAY_SIZE(ld9040_gammas) - 1, > > + .brightness = ARRAY_SIZE(ld9040_gammas) - 1, > > +}; > > + > > static int ld9040_probe(struct spi_device *spi) > > { > > + struct backlight_device *bldev; > > struct device *dev = &spi->dev; > > struct ld9040 *ctx; > > int ret; > > @@ -354,6 +387,13 @@ static int ld9040_probe(struct spi_device > > *spi) > > drm_panel_init(&ctx->panel, dev, &ld9040_drm_funcs, > > DRM_MODE_CONNECTOR_DPI); > > > > + > > + bldev = devm_backlight_device_register(dev, dev_name(dev), > > dev, > > + ctx, &ld9040_bl_ops, > > + &ld9040_bl_props); > > + if (IS_ERR(bldev)) > > + return PTR_ERR(bldev); > > + > > drm_panel_add(&ctx->panel); > > > > return 0; >