Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1// SPDX-License-Identifier: GPL-2.0-or-later
2
3#include <linux/backlight.h>
4#include <linux/export.h>
5#include <linux/fb.h>
6#include <linux/mutex.h>
7
8#if IS_ENABLED(CONFIG_FB_BACKLIGHT)
9/*
10 * This function generates a linear backlight curve
11 *
12 * 0: off
13 * 1-7: min
14 * 8-127: linear from min to max
15 */
16void fb_bl_default_curve(struct fb_info *fb_info, u8 off, u8 min, u8 max)
17{
18 unsigned int i, flat, count, range = (max - min);
19
20 mutex_lock(&fb_info->bl_curve_mutex);
21
22 fb_info->bl_curve[0] = off;
23
24 for (flat = 1; flat < (FB_BACKLIGHT_LEVELS / 16); ++flat)
25 fb_info->bl_curve[flat] = min;
26
27 count = FB_BACKLIGHT_LEVELS * 15 / 16;
28 for (i = 0; i < count; ++i)
29 fb_info->bl_curve[flat + i] = min + (range * (i + 1) / count);
30
31 mutex_unlock(&fb_info->bl_curve_mutex);
32}
33EXPORT_SYMBOL_GPL(fb_bl_default_curve);
34
35struct backlight_device *fb_bl_device(struct fb_info *info)
36{
37 return info->bl_dev;
38}
39EXPORT_SYMBOL(fb_bl_device);
40
41void fb_bl_notify_blank(struct fb_info *info, int old_blank)
42{
43 bool on = info->blank == FB_BLANK_UNBLANK;
44 bool prev_on = old_blank == FB_BLANK_UNBLANK;
45
46 if (info->bl_dev)
47 backlight_notify_blank(info->bl_dev, info->device, on, prev_on);
48 else
49 backlight_notify_blank_all(info->device, on, prev_on);
50}
51#endif