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/device.h>
18 #include <linux/spinlock.h>
20 #include <linux/backlight.h>
22 #include <asm/mach-types.h>
23 #include <asm/arch/sharpsl.h>
25 #define CORGI_DEFAULT_INTENSITY 0x1f
26 #define CORGI_LIMIT_MASK 0x0b
28 static int corgibl_powermode = FB_BLANK_UNBLANK;
29 static int current_intensity = 0;
30 static int corgibl_limit = 0;
31 static void (*corgibl_mach_set_intensity)(int intensity);
32 static spinlock_t bl_lock = SPIN_LOCK_UNLOCKED;
33 static struct backlight_properties corgibl_data;
35 static void corgibl_send_intensity(int intensity)
38 void (*corgi_kick_batt)(void);
40 if (corgibl_powermode != FB_BLANK_UNBLANK) {
44 intensity &= CORGI_LIMIT_MASK;
47 spin_lock_irqsave(&bl_lock, flags);
49 corgibl_mach_set_intensity(intensity);
51 spin_unlock_irqrestore(&bl_lock, flags);
54 static void corgibl_blank(int blank)
59 case FB_BLANK_VSYNC_SUSPEND:
60 case FB_BLANK_HSYNC_SUSPEND:
61 case FB_BLANK_POWERDOWN:
62 if (corgibl_powermode == FB_BLANK_UNBLANK) {
63 corgibl_send_intensity(0);
64 corgibl_powermode = blank;
67 case FB_BLANK_UNBLANK:
68 if (corgibl_powermode != FB_BLANK_UNBLANK) {
69 corgibl_powermode = blank;
70 corgibl_send_intensity(current_intensity);
77 static int corgibl_suspend(struct device *dev, pm_message_t state, u32 level)
79 if (level == SUSPEND_POWER_DOWN)
80 corgibl_blank(FB_BLANK_POWERDOWN);
84 static int corgibl_resume(struct device *dev, u32 level)
86 if (level == RESUME_POWER_ON)
87 corgibl_blank(FB_BLANK_UNBLANK);
91 #define corgibl_suspend NULL
92 #define corgibl_resume NULL
96 static int corgibl_set_power(struct backlight_device *bd, int state)
102 static int corgibl_get_power(struct backlight_device *bd)
104 return corgibl_powermode;
107 static int corgibl_set_intensity(struct backlight_device *bd, int intensity)
109 if (intensity > corgibl_data.max_brightness)
110 intensity = corgibl_data.max_brightness;
111 corgibl_send_intensity(intensity);
112 current_intensity=intensity;
116 static int corgibl_get_intensity(struct backlight_device *bd)
118 return current_intensity;
122 * Called when the battery is low to limit the backlight intensity.
123 * If limit==0 clear any limit, otherwise limit the intensity
125 void corgibl_limit_intensity(int limit)
127 corgibl_limit = (limit ? 1 : 0);
128 corgibl_send_intensity(current_intensity);
130 EXPORT_SYMBOL(corgibl_limit_intensity);
133 static struct backlight_properties corgibl_data = {
134 .owner = THIS_MODULE,
135 .get_power = corgibl_get_power,
136 .set_power = corgibl_set_power,
137 .get_brightness = corgibl_get_intensity,
138 .set_brightness = corgibl_set_intensity,
141 static struct backlight_device *corgi_backlight_device;
143 static int __init corgibl_probe(struct device *dev)
145 struct corgibl_machinfo *machinfo = dev->platform_data;
147 corgibl_data.max_brightness = machinfo->max_intensity;
148 corgibl_mach_set_intensity = machinfo->set_bl_intensity;
150 corgi_backlight_device = backlight_device_register ("corgi-bl",
151 NULL, &corgibl_data);
152 if (IS_ERR (corgi_backlight_device))
153 return PTR_ERR (corgi_backlight_device);
155 corgibl_set_intensity(NULL, CORGI_DEFAULT_INTENSITY);
156 corgibl_limit_intensity(0);
158 printk("Corgi Backlight Driver Initialized.\n");
162 static int corgibl_remove(struct device *dev)
164 backlight_device_unregister(corgi_backlight_device);
166 corgibl_set_intensity(NULL, 0);
168 printk("Corgi Backlight Driver Unloaded\n");
172 static struct device_driver corgibl_driver = {
174 .bus = &platform_bus_type,
175 .probe = corgibl_probe,
176 .remove = corgibl_remove,
177 .suspend = corgibl_suspend,
178 .resume = corgibl_resume,
181 static int __init corgibl_init(void)
183 return driver_register(&corgibl_driver);
186 static void __exit corgibl_exit(void)
188 driver_unregister(&corgibl_driver);
191 module_init(corgibl_init);
192 module_exit(corgibl_exit);
194 MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>");
195 MODULE_DESCRIPTION("Corgi Backlight Driver");
196 MODULE_LICENSE("GPLv2");