Commit | Line | Data |
---|---|---|
d00ba726 RP |
1 | /* |
2 | * Generic Backlight Driver | |
3 | * | |
4 | * Copyright (c) 2004-2008 Richard Purdie | |
5 | * | |
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. | |
9 | * | |
10 | */ | |
11 | ||
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> | |
17 | #include <linux/fb.h> | |
18 | #include <linux/backlight.h> | |
19 | ||
20 | static int genericbl_intensity; | |
21 | static struct backlight_device *generic_backlight_device; | |
22 | static struct generic_bl_info *bl_machinfo; | |
23 | ||
24 | /* Flag to signal when the battery is low */ | |
25 | #define GENERICBL_BATTLOW BL_CORE_DRIVER1 | |
26 | ||
27 | static int genericbl_send_intensity(struct backlight_device *bd) | |
28 | { | |
29 | int intensity = bd->props.brightness; | |
30 | ||
31 | if (bd->props.power != FB_BLANK_UNBLANK) | |
32 | intensity = 0; | |
33 | if (bd->props.state & BL_CORE_FBBLANK) | |
34 | intensity = 0; | |
35 | if (bd->props.state & BL_CORE_SUSPENDED) | |
36 | intensity = 0; | |
37 | if (bd->props.state & GENERICBL_BATTLOW) | |
38 | intensity &= bl_machinfo->limit_mask; | |
39 | ||
40 | bl_machinfo->set_bl_intensity(intensity); | |
41 | ||
42 | genericbl_intensity = intensity; | |
43 | ||
44 | if (bl_machinfo->kick_battery) | |
45 | bl_machinfo->kick_battery(); | |
46 | ||
47 | return 0; | |
48 | } | |
49 | ||
50 | static int genericbl_get_intensity(struct backlight_device *bd) | |
51 | { | |
52 | return genericbl_intensity; | |
53 | } | |
54 | ||
9905a43b | 55 | static const struct backlight_ops genericbl_ops = { |
d00ba726 RP |
56 | .options = BL_CORE_SUSPENDRESUME, |
57 | .get_brightness = genericbl_get_intensity, | |
58 | .update_status = genericbl_send_intensity, | |
59 | }; | |
60 | ||
61 | static int genericbl_probe(struct platform_device *pdev) | |
62 | { | |
a19a6ee6 | 63 | struct backlight_properties props; |
c512794c | 64 | struct generic_bl_info *machinfo = dev_get_platdata(&pdev->dev); |
d00ba726 RP |
65 | const char *name = "generic-bl"; |
66 | struct backlight_device *bd; | |
67 | ||
68 | bl_machinfo = machinfo; | |
69 | if (!machinfo->limit_mask) | |
70 | machinfo->limit_mask = -1; | |
71 | ||
72 | if (machinfo->name) | |
73 | name = machinfo->name; | |
74 | ||
a19a6ee6 | 75 | memset(&props, 0, sizeof(struct backlight_properties)); |
bb7ca747 | 76 | props.type = BACKLIGHT_RAW; |
a19a6ee6 | 77 | props.max_brightness = machinfo->max_intensity; |
de2efd2a JH |
78 | bd = devm_backlight_device_register(&pdev->dev, name, &pdev->dev, |
79 | NULL, &genericbl_ops, &props); | |
933bd9b3 JH |
80 | if (IS_ERR(bd)) |
81 | return PTR_ERR(bd); | |
d00ba726 RP |
82 | |
83 | platform_set_drvdata(pdev, bd); | |
84 | ||
d00ba726 RP |
85 | bd->props.power = FB_BLANK_UNBLANK; |
86 | bd->props.brightness = machinfo->default_intensity; | |
87 | backlight_update_status(bd); | |
88 | ||
89 | generic_backlight_device = bd; | |
90 | ||
8ab5aa67 | 91 | dev_info(&pdev->dev, "Generic Backlight Driver Initialized.\n"); |
d00ba726 RP |
92 | return 0; |
93 | } | |
94 | ||
95 | static int genericbl_remove(struct platform_device *pdev) | |
96 | { | |
97 | struct backlight_device *bd = platform_get_drvdata(pdev); | |
98 | ||
99 | bd->props.power = 0; | |
100 | bd->props.brightness = 0; | |
101 | backlight_update_status(bd); | |
102 | ||
8ab5aa67 | 103 | dev_info(&pdev->dev, "Generic Backlight Driver Unloaded\n"); |
d00ba726 RP |
104 | return 0; |
105 | } | |
106 | ||
107 | static struct platform_driver genericbl_driver = { | |
108 | .probe = genericbl_probe, | |
109 | .remove = genericbl_remove, | |
110 | .driver = { | |
111 | .name = "generic-bl", | |
112 | }, | |
113 | }; | |
114 | ||
81178e02 | 115 | module_platform_driver(genericbl_driver); |
d00ba726 RP |
116 | |
117 | MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>"); | |
118 | MODULE_DESCRIPTION("Generic Backlight Driver"); | |
119 | MODULE_LICENSE("GPL"); |