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 #include <linux/module.h>
13 #include <linux/kernel.h>
14 #include <linux/init.h>
15 #include <linux/platform_device.h>
16 #include <linux/mutex.h>
18 #include <linux/backlight.h>
20 static int genericbl_intensity
;
21 static struct backlight_device
*generic_backlight_device
;
22 static struct generic_bl_info
*bl_machinfo
;
24 /* Flag to signal when the battery is low */
25 #define GENERICBL_BATTLOW BL_CORE_DRIVER1
27 static int genericbl_send_intensity(struct backlight_device
*bd
)
29 int intensity
= bd
->props
.brightness
;
31 if (bd
->props
.power
!= FB_BLANK_UNBLANK
)
33 if (bd
->props
.state
& BL_CORE_FBBLANK
)
35 if (bd
->props
.state
& BL_CORE_SUSPENDED
)
37 if (bd
->props
.state
& GENERICBL_BATTLOW
)
38 intensity
&= bl_machinfo
->limit_mask
;
40 bl_machinfo
->set_bl_intensity(intensity
);
42 genericbl_intensity
= intensity
;
44 if (bl_machinfo
->kick_battery
)
45 bl_machinfo
->kick_battery();
50 static int genericbl_get_intensity(struct backlight_device
*bd
)
52 return genericbl_intensity
;
56 * Called when the battery is low to limit the backlight intensity.
57 * If limit==0 clear any limit, otherwise limit the intensity
59 void genericbl_limit_intensity(int limit
)
61 struct backlight_device
*bd
= generic_backlight_device
;
63 mutex_lock(&bd
->ops_lock
);
65 bd
->props
.state
|= GENERICBL_BATTLOW
;
67 bd
->props
.state
&= ~GENERICBL_BATTLOW
;
68 backlight_update_status(generic_backlight_device
);
69 mutex_unlock(&bd
->ops_lock
);
71 EXPORT_SYMBOL(genericbl_limit_intensity
);
73 static const struct backlight_ops genericbl_ops
= {
74 .options
= BL_CORE_SUSPENDRESUME
,
75 .get_brightness
= genericbl_get_intensity
,
76 .update_status
= genericbl_send_intensity
,
79 static int genericbl_probe(struct platform_device
*pdev
)
81 struct backlight_properties props
;
82 struct generic_bl_info
*machinfo
= pdev
->dev
.platform_data
;
83 const char *name
= "generic-bl";
84 struct backlight_device
*bd
;
86 bl_machinfo
= machinfo
;
87 if (!machinfo
->limit_mask
)
88 machinfo
->limit_mask
= -1;
91 name
= machinfo
->name
;
93 memset(&props
, 0, sizeof(struct backlight_properties
));
94 props
.type
= BACKLIGHT_RAW
;
95 props
.max_brightness
= machinfo
->max_intensity
;
96 bd
= backlight_device_register(name
, &pdev
->dev
, NULL
, &genericbl_ops
,
101 platform_set_drvdata(pdev
, bd
);
103 bd
->props
.power
= FB_BLANK_UNBLANK
;
104 bd
->props
.brightness
= machinfo
->default_intensity
;
105 backlight_update_status(bd
);
107 generic_backlight_device
= bd
;
109 printk("Generic Backlight Driver Initialized.\n");
113 static int genericbl_remove(struct platform_device
*pdev
)
115 struct backlight_device
*bd
= platform_get_drvdata(pdev
);
118 bd
->props
.brightness
= 0;
119 backlight_update_status(bd
);
121 backlight_device_unregister(bd
);
123 printk("Generic Backlight Driver Unloaded\n");
127 static struct platform_driver genericbl_driver
= {
128 .probe
= genericbl_probe
,
129 .remove
= genericbl_remove
,
131 .name
= "generic-bl",
135 module_platform_driver(genericbl_driver
);
137 MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>");
138 MODULE_DESCRIPTION("Generic Backlight Driver");
139 MODULE_LICENSE("GPL");