2 * Backlight Driver for Sharp Zaurus Handhelds (various models)
4 * Copyright (c) 2004-2006 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/mutex.h>
20 #include <linux/backlight.h>
22 static int corgibl_intensity;
23 static struct backlight_properties corgibl_data;
24 static struct backlight_device *corgi_backlight_device;
25 static struct generic_bl_info *bl_machinfo;
27 /* Flag to signal when the battery is low */
28 #define CORGIBL_BATTLOW BL_CORE_DRIVER1
30 static int corgibl_send_intensity(struct backlight_device *bd)
32 int intensity = bd->props.brightness;
34 if (bd->props.power != FB_BLANK_UNBLANK)
36 if (bd->props.state & BL_CORE_FBBLANK)
38 if (bd->props.state & BL_CORE_SUSPENDED)
40 if (bd->props.state & CORGIBL_BATTLOW)
41 intensity &= bl_machinfo->limit_mask;
43 bl_machinfo->set_bl_intensity(intensity);
45 corgibl_intensity = intensity;
47 if (bl_machinfo->kick_battery)
48 bl_machinfo->kick_battery();
53 static int corgibl_get_intensity(struct backlight_device *bd)
55 return corgibl_intensity;
59 * Called when the battery is low to limit the backlight intensity.
60 * If limit==0 clear any limit, otherwise limit the intensity
62 void corgibl_limit_intensity(int limit)
64 struct backlight_device *bd = corgi_backlight_device;
66 mutex_lock(&bd->ops_lock);
68 bd->props.state |= CORGIBL_BATTLOW;
70 bd->props.state &= ~CORGIBL_BATTLOW;
71 backlight_update_status(corgi_backlight_device);
72 mutex_unlock(&bd->ops_lock);
74 EXPORT_SYMBOL(corgibl_limit_intensity);
77 static struct backlight_ops corgibl_ops = {
78 .options = BL_CORE_SUSPENDRESUME,
79 .get_brightness = corgibl_get_intensity,
80 .update_status = corgibl_send_intensity,
83 static int corgibl_probe(struct platform_device *pdev)
85 struct generic_bl_info *machinfo = pdev->dev.platform_data;
86 const char *name = "generic-bl";
88 bl_machinfo = machinfo;
89 if (!machinfo->limit_mask)
90 machinfo->limit_mask = -1;
93 name = machinfo->name;
95 corgi_backlight_device = backlight_device_register (name,
96 &pdev->dev, NULL, &corgibl_ops);
97 if (IS_ERR (corgi_backlight_device))
98 return PTR_ERR (corgi_backlight_device);
100 platform_set_drvdata(pdev, corgi_backlight_device);
102 corgi_backlight_device->props.max_brightness = machinfo->max_intensity;
103 corgi_backlight_device->props.power = FB_BLANK_UNBLANK;
104 corgi_backlight_device->props.brightness = machinfo->default_intensity;
105 backlight_update_status(corgi_backlight_device);
107 printk("Corgi Backlight Driver Initialized.\n");
111 static int corgibl_remove(struct platform_device *pdev)
113 struct backlight_device *bd = platform_get_drvdata(pdev);
115 corgibl_data.power = 0;
116 corgibl_data.brightness = 0;
117 backlight_update_status(bd);
119 backlight_device_unregister(bd);
121 printk("Corgi Backlight Driver Unloaded\n");
125 static struct platform_driver corgibl_driver = {
126 .probe = corgibl_probe,
127 .remove = corgibl_remove,
129 .name = "generic-bl",
133 static int __init corgibl_init(void)
135 return platform_driver_register(&corgibl_driver);
138 static void __exit corgibl_exit(void)
140 platform_driver_unregister(&corgibl_driver);
143 module_init(corgibl_init);
144 module_exit(corgibl_exit);
146 MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>");
147 MODULE_DESCRIPTION("Corgi Backlight Driver");
148 MODULE_LICENSE("GPL");