On Sun, Aug 23, 2020 at 12:45:11PM +0200, Sam Ravnborg wrote: > Add get and set operations to incapsualte access to backlight brightness. > > One easy win is that the get/set operations can be used when backlight > is not included in the configuration, resulting in simpler code with > less ifdef's and thus more readable code. > > The backlight_enable_brightness() update the brightness and enable > the backlight. > > The backlight_update_brightness() force the brightness update and > typical usage is to set brightness after registering a backlight device. > > Signed-off-by: Sam Ravnborg <sam@xxxxxxxxxxxx> > Cc: Lee Jones <lee.jones@xxxxxxxxxx> > Cc: Daniel Thompson <daniel.thompson@xxxxxxxxxx> > Cc: Jingoo Han <jingoohan1@xxxxxxxxx> Reviewed-by: Daniel Thompson <daniel.thompson@xxxxxxxxxx> > --- > include/linux/backlight.h | 74 +++++++++++++++++++++++++++++++++++++++ > 1 file changed, 74 insertions(+) > > diff --git a/include/linux/backlight.h b/include/linux/backlight.h > index 93a47a6cf681..e390444bed13 100644 > --- a/include/linux/backlight.h > +++ b/include/linux/backlight.h > @@ -492,6 +492,80 @@ static inline int backlight_get_brightness(const struct backlight_device *bd) > return bd->props.brightness; > } > > +/** > + * backlight_get_actual_brightness - Returns the actual brightness > + * > + * On failure a negative error code is returned. > + */ > +static inline int backlight_get_actual_brightness(struct backlight_device *bd) > +{ > + if (bd && bd->ops && bd->ops->get_brightness) > + return bd->ops->get_brightness(bd); > + else > + return -EINVAL; > +} > + > +/** > + * backlight_get_max_brightness - Returns maximum brightness > + * > + * This helper operation is preferred over direct access to > + * &backlight_properties.max_brightness > + * > + * Returns 0 if backlight_device is NULL > + */ > + > +static inline int backlight_get_max_brightness(const struct backlight_device *bd) > +{ > + if (bd) > + return bd->props.max_brightness; > + else > + return 0; > +} > + > +/** > + * backlight_set_brightness - Set the brightness to the specified value > + * > + * This helper operation is preferred over direct assignment to > + * &backlight_properties.brightness. > + * > + * If backlight_device is NULL then silently exit. > + */ > +static inline void backlight_set_brightness(struct backlight_device *bd, int brightness) > +{ > + if (bd) > + bd->props.brightness = brightness; > +} > + > +/** > + * backlight_update_brightness - Update the brightness to the specified value > + * > + * Update brightness and force an update. > + * > + * If backlight_device is NULL then silently exit. > + */ > +static inline void backlight_update_brightness(struct backlight_device *bd, int brightness) > +{ > + if (bd) { > + bd->props.brightness = brightness; > + backlight_update_status(bd); > + } > +} > + > +/** > + * backlight_enable_brightness - Enable backligt using specified brightness > + * > + * Enable brightness using the specified brightness. > + * > + * If backlight_device is NULL then silently exit. > + */ > +static inline void backlight_enable_brightness(struct backlight_device *bd, int brightness) > +{ > + if (bd) { > + bd->props.brightness = brightness; > + backlight_enable(bd); > + } > +} > + > struct backlight_device * > backlight_device_register(const char *name, struct device *dev, void *devdata, > const struct backlight_ops *ops, > -- > 2.25.1 > _______________________________________________ dri-devel mailing list dri-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/dri-devel