Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / video / fbdev / core / fb_backlight.c
blob6fdaa9f81be90c413868bdd8f10d025bbb6a8ecd
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 #include <linux/export.h>
4 #include <linux/fb.h>
5 #include <linux/mutex.h>
7 #if IS_ENABLED(CONFIG_FB_BACKLIGHT)
8 /*
9 * This function generates a linear backlight curve
11 * 0: off
12 * 1-7: min
13 * 8-127: linear from min to max
15 void fb_bl_default_curve(struct fb_info *fb_info, u8 off, u8 min, u8 max)
17 unsigned int i, flat, count, range = (max - min);
19 mutex_lock(&fb_info->bl_curve_mutex);
21 fb_info->bl_curve[0] = off;
23 for (flat = 1; flat < (FB_BACKLIGHT_LEVELS / 16); ++flat)
24 fb_info->bl_curve[flat] = min;
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);
30 mutex_unlock(&fb_info->bl_curve_mutex);
32 EXPORT_SYMBOL_GPL(fb_bl_default_curve);
34 struct backlight_device *fb_bl_device(struct fb_info *info)
36 return info->bl_dev;
38 EXPORT_SYMBOL(fb_bl_device);
39 #endif