2 * Generic Backlight Driver
4 * Copyright (c) 2004-2008 Richard Purdie
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
12 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/platform_device.h>
18 #include <linux/mutex.h>
20 #include <linux/backlight.h>
22 static int genericbl_intensity
;
23 static struct backlight_device
*generic_backlight_device
;
24 static struct generic_bl_info
*bl_machinfo
;
26 /* Flag to signal when the battery is low */
27 #define GENERICBL_BATTLOW BL_CORE_DRIVER1
29 static int genericbl_send_intensity(struct backlight_device
*bd
)
31 int intensity
= bd
->props
.brightness
;
33 if (bd
->props
.power
!= FB_BLANK_UNBLANK
)
35 if (bd
->props
.state
& BL_CORE_FBBLANK
)
37 if (bd
->props
.state
& BL_CORE_SUSPENDED
)
39 if (bd
->props
.state
& GENERICBL_BATTLOW
)
40 intensity
&= bl_machinfo
->limit_mask
;
42 bl_machinfo
->set_bl_intensity(intensity
);
44 genericbl_intensity
= intensity
;
46 if (bl_machinfo
->kick_battery
)
47 bl_machinfo
->kick_battery();
52 static int genericbl_get_intensity(struct backlight_device
*bd
)
54 return genericbl_intensity
;
58 * Called when the battery is low to limit the backlight intensity.
59 * If limit==0 clear any limit, otherwise limit the intensity
61 void genericbl_limit_intensity(int limit
)
63 struct backlight_device
*bd
= generic_backlight_device
;
65 mutex_lock(&bd
->ops_lock
);
67 bd
->props
.state
|= GENERICBL_BATTLOW
;
69 bd
->props
.state
&= ~GENERICBL_BATTLOW
;
70 backlight_update_status(generic_backlight_device
);
71 mutex_unlock(&bd
->ops_lock
);
73 EXPORT_SYMBOL(genericbl_limit_intensity
);
75 static const struct backlight_ops genericbl_ops
= {
76 .options
= BL_CORE_SUSPENDRESUME
,
77 .get_brightness
= genericbl_get_intensity
,
78 .update_status
= genericbl_send_intensity
,
81 static int genericbl_probe(struct platform_device
*pdev
)
83 struct backlight_properties props
;
84 struct generic_bl_info
*machinfo
= pdev
->dev
.platform_data
;
85 const char *name
= "generic-bl";
86 struct backlight_device
*bd
;
88 bl_machinfo
= machinfo
;
89 if (!machinfo
->limit_mask
)
90 machinfo
->limit_mask
= -1;
93 name
= machinfo
->name
;
95 memset(&props
, 0, sizeof(struct backlight_properties
));
96 props
.type
= BACKLIGHT_RAW
;
97 props
.max_brightness
= machinfo
->max_intensity
;
98 bd
= backlight_device_register(name
, &pdev
->dev
, NULL
, &genericbl_ops
,
103 platform_set_drvdata(pdev
, bd
);
105 bd
->props
.power
= FB_BLANK_UNBLANK
;
106 bd
->props
.brightness
= machinfo
->default_intensity
;
107 backlight_update_status(bd
);
109 generic_backlight_device
= bd
;
111 pr_info("Generic Backlight Driver Initialized.\n");
115 static int genericbl_remove(struct platform_device
*pdev
)
117 struct backlight_device
*bd
= platform_get_drvdata(pdev
);
120 bd
->props
.brightness
= 0;
121 backlight_update_status(bd
);
123 backlight_device_unregister(bd
);
125 pr_info("Generic Backlight Driver Unloaded\n");
129 static struct platform_driver genericbl_driver
= {
130 .probe
= genericbl_probe
,
131 .remove
= genericbl_remove
,
133 .name
= "generic-bl",
137 module_platform_driver(genericbl_driver
);
139 MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>");
140 MODULE_DESCRIPTION("Generic Backlight Driver");
141 MODULE_LICENSE("GPL");