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 static int genericbl_send_intensity(struct backlight_device
*bd
)
26 int intensity
= bd
->props
.brightness
;
28 if (bd
->props
.power
!= FB_BLANK_UNBLANK
)
30 if (bd
->props
.state
& BL_CORE_FBBLANK
)
32 if (bd
->props
.state
& BL_CORE_SUSPENDED
)
35 bl_machinfo
->set_bl_intensity(intensity
);
37 genericbl_intensity
= intensity
;
39 if (bl_machinfo
->kick_battery
)
40 bl_machinfo
->kick_battery();
45 static int genericbl_get_intensity(struct backlight_device
*bd
)
47 return genericbl_intensity
;
50 static const struct backlight_ops genericbl_ops
= {
51 .options
= BL_CORE_SUSPENDRESUME
,
52 .get_brightness
= genericbl_get_intensity
,
53 .update_status
= genericbl_send_intensity
,
56 static int genericbl_probe(struct platform_device
*pdev
)
58 struct backlight_properties props
;
59 struct generic_bl_info
*machinfo
= dev_get_platdata(&pdev
->dev
);
60 const char *name
= "generic-bl";
61 struct backlight_device
*bd
;
63 bl_machinfo
= machinfo
;
64 if (!machinfo
->limit_mask
)
65 machinfo
->limit_mask
= -1;
68 name
= machinfo
->name
;
70 memset(&props
, 0, sizeof(struct backlight_properties
));
71 props
.type
= BACKLIGHT_RAW
;
72 props
.max_brightness
= machinfo
->max_intensity
;
73 bd
= devm_backlight_device_register(&pdev
->dev
, name
, &pdev
->dev
,
74 NULL
, &genericbl_ops
, &props
);
78 platform_set_drvdata(pdev
, bd
);
80 bd
->props
.power
= FB_BLANK_UNBLANK
;
81 bd
->props
.brightness
= machinfo
->default_intensity
;
82 backlight_update_status(bd
);
84 generic_backlight_device
= bd
;
86 dev_info(&pdev
->dev
, "Generic Backlight Driver Initialized.\n");
90 static int genericbl_remove(struct platform_device
*pdev
)
92 struct backlight_device
*bd
= platform_get_drvdata(pdev
);
95 bd
->props
.brightness
= 0;
96 backlight_update_status(bd
);
98 dev_info(&pdev
->dev
, "Generic Backlight Driver Unloaded\n");
102 static struct platform_driver genericbl_driver
= {
103 .probe
= genericbl_probe
,
104 .remove
= genericbl_remove
,
106 .name
= "generic-bl",
110 module_platform_driver(genericbl_driver
);
112 MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>");
113 MODULE_DESCRIPTION("Generic Backlight Driver");
114 MODULE_LICENSE("GPL");