1 // SPDX-License-Identifier: GPL-2.0-only
3 * Generic Backlight Driver
5 * Copyright (c) 2004-2008 Richard Purdie
8 #include <linux/module.h>
9 #include <linux/kernel.h>
10 #include <linux/init.h>
11 #include <linux/platform_device.h>
12 #include <linux/mutex.h>
14 #include <linux/backlight.h>
16 static int genericbl_intensity
;
17 static struct backlight_device
*generic_backlight_device
;
18 static struct generic_bl_info
*bl_machinfo
;
20 static int genericbl_send_intensity(struct backlight_device
*bd
)
22 int intensity
= bd
->props
.brightness
;
24 if (bd
->props
.power
!= FB_BLANK_UNBLANK
)
26 if (bd
->props
.state
& BL_CORE_FBBLANK
)
28 if (bd
->props
.state
& BL_CORE_SUSPENDED
)
31 bl_machinfo
->set_bl_intensity(intensity
);
33 genericbl_intensity
= intensity
;
35 if (bl_machinfo
->kick_battery
)
36 bl_machinfo
->kick_battery();
41 static int genericbl_get_intensity(struct backlight_device
*bd
)
43 return genericbl_intensity
;
46 static const struct backlight_ops genericbl_ops
= {
47 .options
= BL_CORE_SUSPENDRESUME
,
48 .get_brightness
= genericbl_get_intensity
,
49 .update_status
= genericbl_send_intensity
,
52 static int genericbl_probe(struct platform_device
*pdev
)
54 struct backlight_properties props
;
55 struct generic_bl_info
*machinfo
= dev_get_platdata(&pdev
->dev
);
56 const char *name
= "generic-bl";
57 struct backlight_device
*bd
;
59 bl_machinfo
= machinfo
;
60 if (!machinfo
->limit_mask
)
61 machinfo
->limit_mask
= -1;
64 name
= machinfo
->name
;
66 memset(&props
, 0, sizeof(struct backlight_properties
));
67 props
.type
= BACKLIGHT_RAW
;
68 props
.max_brightness
= machinfo
->max_intensity
;
69 bd
= devm_backlight_device_register(&pdev
->dev
, name
, &pdev
->dev
,
70 NULL
, &genericbl_ops
, &props
);
74 platform_set_drvdata(pdev
, bd
);
76 bd
->props
.power
= FB_BLANK_UNBLANK
;
77 bd
->props
.brightness
= machinfo
->default_intensity
;
78 backlight_update_status(bd
);
80 generic_backlight_device
= bd
;
82 dev_info(&pdev
->dev
, "Generic Backlight Driver Initialized.\n");
86 static int genericbl_remove(struct platform_device
*pdev
)
88 struct backlight_device
*bd
= platform_get_drvdata(pdev
);
91 bd
->props
.brightness
= 0;
92 backlight_update_status(bd
);
94 dev_info(&pdev
->dev
, "Generic Backlight Driver Unloaded\n");
98 static struct platform_driver genericbl_driver
= {
99 .probe
= genericbl_probe
,
100 .remove
= genericbl_remove
,
102 .name
= "generic-bl",
106 module_platform_driver(genericbl_driver
);
108 MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>");
109 MODULE_DESCRIPTION("Generic Backlight Driver");
110 MODULE_LICENSE("GPL");