xref: /linux/drivers/video/fbdev/core/fb_backlight.c (revision 34dc1baba215b826e454b8d19e4f24adbeb7d00d)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 #include <linux/export.h>
4 #include <linux/fb.h>
5 #include <linux/mutex.h>
6 
7 #if IS_ENABLED(CONFIG_FB_BACKLIGHT)
8 /*
9  * This function generates a linear backlight curve
10  *
11  *     0: off
12  *   1-7: min
13  * 8-127: linear from min to max
14  */
15 void fb_bl_default_curve(struct fb_info *fb_info, u8 off, u8 min, u8 max)
16 {
17 	unsigned int i, flat, count, range = (max - min);
18 
19 	mutex_lock(&fb_info->bl_curve_mutex);
20 
21 	fb_info->bl_curve[0] = off;
22 
23 	for (flat = 1; flat < (FB_BACKLIGHT_LEVELS / 16); ++flat)
24 		fb_info->bl_curve[flat] = min;
25 
26 	count = FB_BACKLIGHT_LEVELS * 15 / 16;
27 	for (i = 0; i < count; ++i)
28 		fb_info->bl_curve[flat + i] = min + (range * (i + 1) / count);
29 
30 	mutex_unlock(&fb_info->bl_curve_mutex);
31 }
32 EXPORT_SYMBOL_GPL(fb_bl_default_curve);
33 #endif
34