Skip to content

Commit c835ee7

Browse files
committed
backlight: Add suspend/resume support to the backlight core
Add suspend/resume support to the backlight core and enable use of it by appropriate drivers. Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
1 parent 9be1df9 commit c835ee7

4 files changed

Lines changed: 63 additions & 33 deletions

File tree

‎drivers/video/backlight/backlight.c‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ static int fb_notifier_callback(struct notifier_block *self,
4040
if (!bd->ops->check_fb ||
4141
bd->ops->check_fb(evdata->info)) {
4242
bd->props.fb_blank = *(int *)evdata->data;
43+
if (bd->props.fb_blank == FB_BLANK_UNBLANK)
44+
bd->props.state &= ~BL_CORE_FBBLANK;
45+
else
46+
bd->props.state |= BL_CORE_FBBLANK;
4347
backlight_update_status(bd);
4448
}
4549
mutex_unlock(&bd->ops_lock);
@@ -165,6 +169,34 @@ static ssize_t backlight_show_actual_brightness(struct device *dev,
165169

166170
static struct class *backlight_class;
167171

172+
static int backlight_suspend(struct device *dev, pm_message_t state)
173+
{
174+
struct backlight_device *bd = to_backlight_device(dev);
175+
176+
if (bd->ops->options & BL_CORE_SUSPENDRESUME) {
177+
mutex_lock(&bd->ops_lock);
178+
bd->props.state |= BL_CORE_SUSPENDED;
179+
backlight_update_status(bd);
180+
mutex_unlock(&bd->ops_lock);
181+
}
182+
183+
return 0;
184+
}
185+
186+
static int backlight_resume(struct device *dev)
187+
{
188+
struct backlight_device *bd = to_backlight_device(dev);
189+
190+
if (bd->ops->options & BL_CORE_SUSPENDRESUME) {
191+
mutex_lock(&bd->ops_lock);
192+
bd->props.state &= ~BL_CORE_SUSPENDED;
193+
backlight_update_status(bd);
194+
mutex_unlock(&bd->ops_lock);
195+
}
196+
197+
return 0;
198+
}
199+
168200
static void bl_device_release(struct device *dev)
169201
{
170202
struct backlight_device *bd = to_backlight_device(dev);
@@ -281,6 +313,8 @@ static int __init backlight_class_init(void)
281313
}
282314

283315
backlight_class->dev_attrs = bl_device_attributes;
316+
backlight_class->suspend = backlight_suspend;
317+
backlight_class->resume = backlight_resume;
284318
return 0;
285319
}
286320

‎drivers/video/backlight/corgi_bl.c‎

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,20 @@ static struct backlight_properties corgibl_data;
2424
static struct backlight_device *corgi_backlight_device;
2525
static struct generic_bl_info *bl_machinfo;
2626

27-
static unsigned long corgibl_flags;
28-
#define CORGIBL_SUSPENDED 0x01
29-
#define CORGIBL_BATTLOW 0x02
27+
/* Flag to signal when the battery is low */
28+
#define CORGIBL_BATTLOW BL_CORE_DRIVER1
3029

3130
static int corgibl_send_intensity(struct backlight_device *bd)
3231
{
3332
int intensity = bd->props.brightness;
3433

3534
if (bd->props.power != FB_BLANK_UNBLANK)
3635
intensity = 0;
37-
if (bd->props.fb_blank != FB_BLANK_UNBLANK)
36+
if (bd->props.state & BL_CORE_FBBLANK)
3837
intensity = 0;
39-
if (corgibl_flags & CORGIBL_SUSPENDED)
38+
if (bd->props.state & BL_CORE_SUSPENDED)
4039
intensity = 0;
41-
if (corgibl_flags & CORGIBL_BATTLOW)
40+
if (bd->props.state & CORGIBL_BATTLOW)
4241
intensity &= bl_machinfo->limit_mask;
4342

4443
bl_machinfo->set_bl_intensity(intensity);
@@ -51,29 +50,6 @@ static int corgibl_send_intensity(struct backlight_device *bd)
5150
return 0;
5251
}
5352

54-
#ifdef CONFIG_PM
55-
static int corgibl_suspend(struct platform_device *pdev, pm_message_t state)
56-
{
57-
struct backlight_device *bd = platform_get_drvdata(pdev);
58-
59-
corgibl_flags |= CORGIBL_SUSPENDED;
60-
backlight_update_status(bd);
61-
return 0;
62-
}
63-
64-
static int corgibl_resume(struct platform_device *pdev)
65-
{
66-
struct backlight_device *bd = platform_get_drvdata(pdev);
67-
68-
corgibl_flags &= ~CORGIBL_SUSPENDED;
69-
backlight_update_status(bd);
70-
return 0;
71-
}
72-
#else
73-
#define corgibl_suspend NULL
74-
#define corgibl_resume NULL
75-
#endif
76-
7753
static int corgibl_get_intensity(struct backlight_device *bd)
7854
{
7955
return corgibl_intensity;
@@ -85,16 +61,21 @@ static int corgibl_get_intensity(struct backlight_device *bd)
8561
*/
8662
void corgibl_limit_intensity(int limit)
8763
{
64+
struct backlight_device *bd = corgi_backlight_device;
65+
66+
mutex_lock(&bd->ops_lock);
8867
if (limit)
89-
corgibl_flags |= CORGIBL_BATTLOW;
68+
bd->props.state |= CORGIBL_BATTLOW;
9069
else
91-
corgibl_flags &= ~CORGIBL_BATTLOW;
70+
bd->props.state &= ~CORGIBL_BATTLOW;
9271
backlight_update_status(corgi_backlight_device);
72+
mutex_unlock(&bd->ops_lock);
9373
}
9474
EXPORT_SYMBOL(corgibl_limit_intensity);
9575

9676

9777
static struct backlight_ops corgibl_ops = {
78+
.options = BL_CORE_SUSPENDRESUME,
9879
.get_brightness = corgibl_get_intensity,
9980
.update_status = corgibl_send_intensity,
10081
};
@@ -144,8 +125,6 @@ static int corgibl_remove(struct platform_device *pdev)
144125
static struct platform_driver corgibl_driver = {
145126
.probe = corgibl_probe,
146127
.remove = corgibl_remove,
147-
.suspend = corgibl_suspend,
148-
.resume = corgibl_resume,
149128
.driver = {
150129
.name = "generic-bl",
151130
},

‎drivers/video/backlight/mbp_nvidia_bl.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ static int mbp_get_intensity(struct backlight_device *bd)
7070
}
7171

7272
static struct backlight_ops mbp_ops = {
73+
.options = BL_CORE_SUSPENDRESUME,
7374
.get_brightness = mbp_get_intensity,
7475
.update_status = mbp_send_intensity,
7576
};

‎include/linux/backlight.h‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ struct backlight_device;
3131
struct fb_info;
3232

3333
struct backlight_ops {
34+
unsigned int options;
35+
36+
#define BL_CORE_SUSPENDRESUME (1 << 0)
37+
3438
/* Notify the backlight driver some property has changed */
3539
int (*update_status)(struct backlight_device *);
3640
/* Return the current backlight brightness (accounting for power,
@@ -51,7 +55,19 @@ struct backlight_properties {
5155
modes; 4: full off), see FB_BLANK_XXX */
5256
int power;
5357
/* FB Blanking active? (values as for power) */
58+
/* Due to be removed, please use (state & BL_CORE_FBBLANK) */
5459
int fb_blank;
60+
/* Flags used to signal drivers of state changes */
61+
/* Upper 4 bits are reserved for driver internal use */
62+
unsigned int state;
63+
64+
#define BL_CORE_SUSPENDED (1 << 0) /* backlight is suspended */
65+
#define BL_CORE_FBBLANK (1 << 1) /* backlight is under an fb blank event */
66+
#define BL_CORE_DRIVER4 (1 << 28) /* reserved for driver specific use */
67+
#define BL_CORE_DRIVER3 (1 << 29) /* reserved for driver specific use */
68+
#define BL_CORE_DRIVER2 (1 << 30) /* reserved for driver specific use */
69+
#define BL_CORE_DRIVER1 (1 << 31) /* reserved for driver specific use */
70+
5571
};
5672

5773
struct backlight_device {

0 commit comments

Comments
 (0)