2 * Backlight Driver for Sharp Corgi
4 * Copyright (c) 2004-2005 Richard Purdie
6 * Based on Sharp's 2.4 Backlight Driver
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.
14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/platform_device.h>
18 #include <linux/spinlock.h>
20 #include <linux/backlight.h>
22 #include <asm/arch/sharpsl.h>
24 #define CORGI_DEFAULT_INTENSITY 0x1f
25 #define CORGI_LIMIT_MASK 0x0b
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;
34 static void corgibl_send_intensity(int intensity)
37 void (*corgi_kick_batt)(void);
39 if (corgibl_powermode != FB_BLANK_UNBLANK) {
43 intensity &= CORGI_LIMIT_MASK;
46 spin_lock_irqsave(&bl_lock, flags);
48 corgibl_mach_set_intensity(intensity);
50 spin_unlock_irqrestore(&bl_lock, flags);
53 static void corgibl_blank(int blank)
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;
66 case FB_BLANK_UNBLANK:
67 if (corgibl_powermode != FB_BLANK_UNBLANK) {
68 corgibl_powermode = blank;
69 corgibl_send_intensity(current_intensity);
76 static int corgibl_suspend(struct device *dev, pm_message_t state)
78 corgibl_blank(FB_BLANK_POWERDOWN);
82 static int corgibl_resume(struct device *dev)
84 corgibl_blank(FB_BLANK_UNBLANK);
88 #define corgibl_suspend NULL
89 #define corgibl_resume NULL
93 static int corgibl_set_power(struct backlight_device *bd, int state)
99 static int corgibl_get_power(struct backlight_device *bd)
101 return corgibl_powermode;
104 static int corgibl_set_intensity(struct backlight_device *bd, int intensity)
106 if (intensity > corgibl_data.max_brightness)
107 intensity = corgibl_data.max_brightness;
108 corgibl_send_intensity(intensity);
109 current_intensity=intensity;
113 static int corgibl_get_intensity(struct backlight_device *bd)
115 return current_intensity;
119 * Called when the battery is low to limit the backlight intensity.
120 * If limit==0 clear any limit, otherwise limit the intensity
122 void corgibl_limit_intensity(int limit)
124 corgibl_limit = (limit ? 1 : 0);
125 corgibl_send_intensity(current_intensity);
127 EXPORT_SYMBOL(corgibl_limit_intensity);
130 static struct backlight_properties corgibl_data = {
131 .owner = THIS_MODULE,
132 .get_power = corgibl_get_power,
133 .set_power = corgibl_set_power,
134 .get_brightness = corgibl_get_intensity,
135 .set_brightness = corgibl_set_intensity,
138 static struct backlight_device *corgi_backlight_device;
140 static int __init corgibl_probe(struct device *dev)
142 struct corgibl_machinfo *machinfo = dev->platform_data;
144 corgibl_data.max_brightness = machinfo->max_intensity;
145 corgibl_mach_set_intensity = machinfo->set_bl_intensity;
147 corgi_backlight_device = backlight_device_register ("corgi-bl",
148 NULL, &corgibl_data);
149 if (IS_ERR (corgi_backlight_device))
150 return PTR_ERR (corgi_backlight_device);
152 corgibl_set_intensity(NULL, CORGI_DEFAULT_INTENSITY);
153 corgibl_limit_intensity(0);
155 printk("Corgi Backlight Driver Initialized.\n");
159 static int corgibl_remove(struct device *dev)
161 backlight_device_unregister(corgi_backlight_device);
163 corgibl_set_intensity(NULL, 0);
165 printk("Corgi Backlight Driver Unloaded\n");
169 static struct device_driver corgibl_driver = {
171 .bus = &platform_bus_type,
172 .probe = corgibl_probe,
173 .remove = corgibl_remove,
174 .suspend = corgibl_suspend,
175 .resume = corgibl_resume,
178 static int __init corgibl_init(void)
180 return driver_register(&corgibl_driver);
183 static void __exit corgibl_exit(void)
185 driver_unregister(&corgibl_driver);
188 module_init(corgibl_init);
189 module_exit(corgibl_exit);
191 MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>");
192 MODULE_DESCRIPTION("Corgi Backlight Driver");
193 MODULE_LICENSE("GPLv2");