Skip to content

Commit 479da1f

Browse files
notroLee Jones
authored andcommitted
backlight: Add backlight_device_get_by_name()
Add a way to lookup a backlight device based on its name. Will be used by a USB display gadget getting the name from configfs. Signed-off-by: Noralf Trønnes <[email protected]> Reviewed-by: Sam Ravnborg <[email protected]> Reviewed-by: Daniel Thompson <[email protected]> Acked-by: Jingoo Han <[email protected]> Signed-off-by: Lee Jones <[email protected]>
1 parent 62a1d3f commit 479da1f

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

drivers/video/backlight/backlight.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,27 @@ struct backlight_device *backlight_device_get_by_type(enum backlight_type type)
432432
}
433433
EXPORT_SYMBOL(backlight_device_get_by_type);
434434

435+
/**
436+
* backlight_device_get_by_name - Get backlight device by name
437+
* @name: Device name
438+
*
439+
* This function looks up a backlight device by its name. It obtains a reference
440+
* on the backlight device and it is the caller's responsibility to drop the
441+
* reference by calling backlight_put().
442+
*
443+
* Returns:
444+
* A pointer to the backlight device if found, otherwise NULL.
445+
*/
446+
struct backlight_device *backlight_device_get_by_name(const char *name)
447+
{
448+
struct device *dev;
449+
450+
dev = class_find_device_by_name(backlight_class, name);
451+
452+
return dev ? to_backlight_device(dev) : NULL;
453+
}
454+
EXPORT_SYMBOL(backlight_device_get_by_name);
455+
435456
/**
436457
* backlight_device_unregister - unregisters a backlight device object.
437458
* @bd: the backlight device object to be unregistered and freed.

include/linux/backlight.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ extern void backlight_force_update(struct backlight_device *bd,
190190
extern int backlight_register_notifier(struct notifier_block *nb);
191191
extern int backlight_unregister_notifier(struct notifier_block *nb);
192192
extern struct backlight_device *backlight_device_get_by_type(enum backlight_type type);
193+
struct backlight_device *backlight_device_get_by_name(const char *name);
193194
extern int backlight_device_set_brightness(struct backlight_device *bd, unsigned long brightness);
194195

195196
#define to_backlight_device(obj) container_of(obj, struct backlight_device, dev)

0 commit comments

Comments
 (0)