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>
23 #include <asm/hardware/sharpsl_pm.h>
25 #define CORGI_DEFAULT_INTENSITY 0x1f
26 #define CORGI_LIMIT_MASK 0x0b
28 static int corgibl_intensity;
29 static void (*corgibl_mach_set_intensity)(int intensity);
30 static spinlock_t bl_lock = SPIN_LOCK_UNLOCKED;
31 static struct backlight_properties corgibl_data;
32 static struct backlight_device *corgi_backlight_device;
34 static unsigned long corgibl_flags;
35 #define CORGIBL_SUSPENDED 0x01
36 #define CORGIBL_BATTLOW 0x02
38 static int corgibl_send_intensity(struct backlight_device *bd)
41 void (*corgi_kick_batt)(void);
42 int intensity = bd->props->brightness;
44 if (bd->props->power != FB_BLANK_UNBLANK)
46 if (bd->props->fb_blank != FB_BLANK_UNBLANK)
48 if (corgibl_flags & CORGIBL_SUSPENDED)
50 if (corgibl_flags & CORGIBL_BATTLOW)
51 intensity &= CORGI_LIMIT_MASK;
53 spin_lock_irqsave(&bl_lock, flags);
55 corgibl_mach_set_intensity(intensity);
57 spin_unlock_irqrestore(&bl_lock, flags);
59 corgibl_intensity = intensity;
61 corgi_kick_batt = symbol_get(sharpsl_battery_kick);
62 if (corgi_kick_batt) {
64 symbol_put(sharpsl_battery_kick);
71 static int corgibl_suspend(struct platform_device *dev, pm_message_t state)
73 corgibl_flags |= CORGIBL_SUSPENDED;
74 corgibl_send_intensity(corgi_backlight_device);
78 static int corgibl_resume(struct platform_device *dev)
80 corgibl_flags &= ~CORGIBL_SUSPENDED;
81 corgibl_send_intensity(corgi_backlight_device);
85 #define corgibl_suspend NULL
86 #define corgibl_resume NULL
89 static int corgibl_get_intensity(struct backlight_device *bd)
91 return corgibl_intensity;
94 static int corgibl_set_intensity(struct backlight_device *bd)
96 corgibl_send_intensity(corgi_backlight_device);
101 * Called when the battery is low to limit the backlight intensity.
102 * If limit==0 clear any limit, otherwise limit the intensity
104 void corgibl_limit_intensity(int limit)
107 corgibl_flags |= CORGIBL_BATTLOW;
109 corgibl_flags &= ~CORGIBL_BATTLOW;
110 corgibl_send_intensity(corgi_backlight_device);
112 EXPORT_SYMBOL(corgibl_limit_intensity);
115 static struct backlight_properties corgibl_data = {
116 .owner = THIS_MODULE,
117 .get_brightness = corgibl_get_intensity,
118 .update_status = corgibl_set_intensity,
121 static int __init corgibl_probe(struct platform_device *pdev)
123 struct corgibl_machinfo *machinfo = pdev->dev.platform_data;
125 corgibl_data.max_brightness = machinfo->max_intensity;
126 corgibl_mach_set_intensity = machinfo->set_bl_intensity;
128 corgi_backlight_device = backlight_device_register ("corgi-bl",
129 NULL, &corgibl_data);
130 if (IS_ERR (corgi_backlight_device))
131 return PTR_ERR (corgi_backlight_device);
133 corgibl_data.power = FB_BLANK_UNBLANK;
134 corgibl_data.brightness = CORGI_DEFAULT_INTENSITY;
135 corgibl_send_intensity(corgi_backlight_device);
137 printk("Corgi Backlight Driver Initialized.\n");
141 static int corgibl_remove(struct platform_device *dev)
143 backlight_device_unregister(corgi_backlight_device);
145 printk("Corgi Backlight Driver Unloaded\n");
149 static struct platform_driver corgibl_driver = {
150 .probe = corgibl_probe,
151 .remove = corgibl_remove,
152 .suspend = corgibl_suspend,
153 .resume = corgibl_resume,
159 static int __init corgibl_init(void)
161 return platform_driver_register(&corgibl_driver);
164 static void __exit corgibl_exit(void)
166 platform_driver_unregister(&corgibl_driver);
169 module_init(corgibl_init);
170 module_exit(corgibl_exit);
172 MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>");
173 MODULE_DESCRIPTION("Corgi Backlight Driver");
174 MODULE_LICENSE("GPLv2");