On Sun, Aug 02, 2020 at 01:06:17PM +0200, Sam Ravnborg wrote: > Add get and set operations to incapsualte access to backlight properties. > > One easy win is that the get/set operatiosn 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 set/get methods hides some of the confusing power states, limiting > the power state to either ON or OFF for the drivers. > > Signed-off-by: Sam Ravnborg <sam@xxxxxxxxxxxx> > Cc: Lee Jones <lee.jones@xxxxxxxxxx> > Cc: Daniel Thompson <daniel.thompson@xxxxxxxxxx> > Cc: Jingoo Han <jingoohan1@xxxxxxxxx> > --- > include/linux/backlight.h | 72 +++++++++++++++++++++++++++++++++++++++ > 1 file changed, 72 insertions(+) > > diff --git a/include/linux/backlight.h b/include/linux/backlight.h > index d683c053ec09..882ceea45ace 100644 > --- a/include/linux/backlight.h > +++ b/include/linux/backlight.h > @@ -474,6 +474,78 @@ 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; Looking at the drivers I think including a call to backlight_update_status would simplify a lot of code. > +} > + > +/** > + * backlight_set_power_on - Set power state to ON. > + * > + * This helper operation is preferred over direct assignment to > + * backlight_properties.power. > + * > + * If backlight_device is NULL then silently exit. > + */ > +static inline void backlight_set_power_on(struct backlight_device *bd) > +{ > + if (bd) > + bd->props.power = FB_BLANK_UNBLANK; > +} > + > +/** > + * backlight_set_power_off - Set power state to OFF. > + * > + * This helper operation is preferred over direct assignment to > + * backlight_properties.power. > + * > + * If backlight_device is NULL then silently exit. > + */ > +static inline void backlight_set_power_off(struct backlight_device *bd) I'm not clear why we need these two above? I thought the long-term plan is only use backlight_enable/disable and then remove the tri-state power handling once everyone is converted over? Or maybe I'm just confused about the goal here ... -Daniel > +{ > + if (bd) > + bd->props.power = FB_BLANK_POWERDOWN; > +} > + > struct backlight_device * > backlight_device_register(const char *name, struct device *dev, void *devdata, > const struct backlight_ops *ops, > -- > 2.25.1 > -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list dri-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/dri-devel