Merge master.kernel.org:/pub/scm/linux/kernel/git/jejb/scsi-for-linus-2.6
[deliverable/linux.git] / drivers / video / backlight / corgi_bl.c
1 /*
2 * Backlight Driver for Sharp Corgi
3 *
4 * Copyright (c) 2004-2005 Richard Purdie
5 *
6 * Based on Sharp's 2.4 Backlight Driver
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 */
13
14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/device.h>
18 #include <linux/spinlock.h>
19 #include <linux/fb.h>
20 #include <linux/backlight.h>
21
22 #include <asm/arch/sharpsl.h>
23
24 #define CORGI_DEFAULT_INTENSITY 0x1f
25 #define CORGI_LIMIT_MASK 0x0b
26
27 static int corgibl_powermode = FB_BLANK_UNBLANK;
28 static int current_intensity = 0;
29 static int corgibl_limit = 0;
30 static void (*corgibl_mach_set_intensity)(int intensity);
31 static spinlock_t bl_lock = SPIN_LOCK_UNLOCKED;
32 static struct backlight_properties corgibl_data;
33
34 static void corgibl_send_intensity(int intensity)
35 {
36 unsigned long flags;
37 void (*corgi_kick_batt)(void);
38
39 if (corgibl_powermode != FB_BLANK_UNBLANK) {
40 intensity = 0;
41 } else {
42 if (corgibl_limit)
43 intensity &= CORGI_LIMIT_MASK;
44 }
45
46 spin_lock_irqsave(&bl_lock, flags);
47
48 corgibl_mach_set_intensity(intensity);
49
50 spin_unlock_irqrestore(&bl_lock, flags);
51 }
52
53 static void corgibl_blank(int blank)
54 {
55 switch(blank) {
56
57 case FB_BLANK_NORMAL:
58 case FB_BLANK_VSYNC_SUSPEND:
59 case FB_BLANK_HSYNC_SUSPEND:
60 case FB_BLANK_POWERDOWN:
61 if (corgibl_powermode == FB_BLANK_UNBLANK) {
62 corgibl_send_intensity(0);
63 corgibl_powermode = blank;
64 }
65 break;
66 case FB_BLANK_UNBLANK:
67 if (corgibl_powermode != FB_BLANK_UNBLANK) {
68 corgibl_powermode = blank;
69 corgibl_send_intensity(current_intensity);
70 }
71 break;
72 }
73 }
74
75 #ifdef CONFIG_PM
76 static int corgibl_suspend(struct device *dev, pm_message_t state, u32 level)
77 {
78 if (level == SUSPEND_POWER_DOWN)
79 corgibl_blank(FB_BLANK_POWERDOWN);
80 return 0;
81 }
82
83 static int corgibl_resume(struct device *dev, u32 level)
84 {
85 if (level == RESUME_POWER_ON)
86 corgibl_blank(FB_BLANK_UNBLANK);
87 return 0;
88 }
89 #else
90 #define corgibl_suspend NULL
91 #define corgibl_resume NULL
92 #endif
93
94
95 static int corgibl_set_power(struct backlight_device *bd, int state)
96 {
97 corgibl_blank(state);
98 return 0;
99 }
100
101 static int corgibl_get_power(struct backlight_device *bd)
102 {
103 return corgibl_powermode;
104 }
105
106 static int corgibl_set_intensity(struct backlight_device *bd, int intensity)
107 {
108 if (intensity > corgibl_data.max_brightness)
109 intensity = corgibl_data.max_brightness;
110 corgibl_send_intensity(intensity);
111 current_intensity=intensity;
112 return 0;
113 }
114
115 static int corgibl_get_intensity(struct backlight_device *bd)
116 {
117 return current_intensity;
118 }
119
120 /*
121 * Called when the battery is low to limit the backlight intensity.
122 * If limit==0 clear any limit, otherwise limit the intensity
123 */
124 void corgibl_limit_intensity(int limit)
125 {
126 corgibl_limit = (limit ? 1 : 0);
127 corgibl_send_intensity(current_intensity);
128 }
129 EXPORT_SYMBOL(corgibl_limit_intensity);
130
131
132 static struct backlight_properties corgibl_data = {
133 .owner = THIS_MODULE,
134 .get_power = corgibl_get_power,
135 .set_power = corgibl_set_power,
136 .get_brightness = corgibl_get_intensity,
137 .set_brightness = corgibl_set_intensity,
138 };
139
140 static struct backlight_device *corgi_backlight_device;
141
142 static int __init corgibl_probe(struct device *dev)
143 {
144 struct corgibl_machinfo *machinfo = dev->platform_data;
145
146 corgibl_data.max_brightness = machinfo->max_intensity;
147 corgibl_mach_set_intensity = machinfo->set_bl_intensity;
148
149 corgi_backlight_device = backlight_device_register ("corgi-bl",
150 NULL, &corgibl_data);
151 if (IS_ERR (corgi_backlight_device))
152 return PTR_ERR (corgi_backlight_device);
153
154 corgibl_set_intensity(NULL, CORGI_DEFAULT_INTENSITY);
155 corgibl_limit_intensity(0);
156
157 printk("Corgi Backlight Driver Initialized.\n");
158 return 0;
159 }
160
161 static int corgibl_remove(struct device *dev)
162 {
163 backlight_device_unregister(corgi_backlight_device);
164
165 corgibl_set_intensity(NULL, 0);
166
167 printk("Corgi Backlight Driver Unloaded\n");
168 return 0;
169 }
170
171 static struct device_driver corgibl_driver = {
172 .name = "corgi-bl",
173 .bus = &platform_bus_type,
174 .probe = corgibl_probe,
175 .remove = corgibl_remove,
176 .suspend = corgibl_suspend,
177 .resume = corgibl_resume,
178 };
179
180 static int __init corgibl_init(void)
181 {
182 return driver_register(&corgibl_driver);
183 }
184
185 static void __exit corgibl_exit(void)
186 {
187 driver_unregister(&corgibl_driver);
188 }
189
190 module_init(corgibl_init);
191 module_exit(corgibl_exit);
192
193 MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>");
194 MODULE_DESCRIPTION("Corgi Backlight Driver");
195 MODULE_LICENSE("GPLv2");
This page took 0.03656 seconds and 6 git commands to generate.