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 static unsigned long corgibl_flags;
28 #define CORGIBL_SUSPENDED 0x01
29 #define CORGIBL_BATTLOW 0x02
31 static int corgibl_send_intensity(struct backlight_device *bd)
33 int intensity = bd->props.brightness;
35 if (bd->props.power != FB_BLANK_UNBLANK)
37 if (bd->props.fb_blank != FB_BLANK_UNBLANK)
39 if (corgibl_flags & CORGIBL_SUSPENDED)
41 if (corgibl_flags & CORGIBL_BATTLOW)
42 intensity &= bl_machinfo->limit_mask;
44 bl_machinfo->set_bl_intensity(intensity);
46 corgibl_intensity = intensity;
48 if (bl_machinfo->kick_battery)
49 bl_machinfo->kick_battery();
55 static int corgibl_suspend(struct platform_device *pdev, pm_message_t state)
57 struct backlight_device *bd = platform_get_drvdata(pdev);
59 corgibl_flags |= CORGIBL_SUSPENDED;
60 backlight_update_status(bd);
64 static int corgibl_resume(struct platform_device *pdev)
66 struct backlight_device *bd = platform_get_drvdata(pdev);
68 corgibl_flags &= ~CORGIBL_SUSPENDED;
69 backlight_update_status(bd);
73 #define corgibl_suspend NULL
74 #define corgibl_resume NULL
77 static int corgibl_get_intensity(struct backlight_device *bd)
79 return corgibl_intensity;
83 * Called when the battery is low to limit the backlight intensity.
84 * If limit==0 clear any limit, otherwise limit the intensity
86 void corgibl_limit_intensity(int limit)
89 corgibl_flags |= CORGIBL_BATTLOW;
91 corgibl_flags &= ~CORGIBL_BATTLOW;
92 backlight_update_status(corgi_backlight_device);
94 EXPORT_SYMBOL(corgibl_limit_intensity);
97 static struct backlight_ops corgibl_ops = {
98 .get_brightness = corgibl_get_intensity,
99 .update_status = corgibl_send_intensity,
102 static int corgibl_probe(struct platform_device *pdev)
104 struct generic_bl_info *machinfo = pdev->dev.platform_data;
105 const char *name = "generic-bl";
107 bl_machinfo = machinfo;
108 if (!machinfo->limit_mask)
109 machinfo->limit_mask = -1;
112 name = machinfo->name;
114 corgi_backlight_device = backlight_device_register (name,
115 &pdev->dev, NULL, &corgibl_ops);
116 if (IS_ERR (corgi_backlight_device))
117 return PTR_ERR (corgi_backlight_device);
119 platform_set_drvdata(pdev, corgi_backlight_device);
121 corgi_backlight_device->props.max_brightness = machinfo->max_intensity;
122 corgi_backlight_device->props.power = FB_BLANK_UNBLANK;
123 corgi_backlight_device->props.brightness = machinfo->default_intensity;
124 backlight_update_status(corgi_backlight_device);
126 printk("Corgi Backlight Driver Initialized.\n");
130 static int corgibl_remove(struct platform_device *pdev)
132 struct backlight_device *bd = platform_get_drvdata(pdev);
134 corgibl_data.power = 0;
135 corgibl_data.brightness = 0;
136 backlight_update_status(bd);
138 backlight_device_unregister(bd);
140 printk("Corgi Backlight Driver Unloaded\n");
144 static struct platform_driver corgibl_driver = {
145 .probe = corgibl_probe,
146 .remove = corgibl_remove,
147 .suspend = corgibl_suspend,
148 .resume = corgibl_resume,
150 .name = "generic-bl",
154 static int __init corgibl_init(void)
156 return platform_driver_register(&corgibl_driver);
159 static void __exit corgibl_exit(void)
161 platform_driver_unregister(&corgibl_driver);
164 module_init(corgibl_init);
165 module_exit(corgibl_exit);
167 MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>");
168 MODULE_DESCRIPTION("Corgi Backlight Driver");
169 MODULE_LICENSE("GPL");