backlight: add support for Toppoly TDO35S series to tdo24m lcd driver
[linux-2.6-block.git] / drivers / video / backlight / corgi_bl.c
1 /*
2  *  Backlight Driver for Sharp Zaurus Handhelds (various models)
3  *
4  *  Copyright (c) 2004-2006 Richard Purdie
5  *
6  *  Based on Sharp's 2.4 Backlight Driver
7  *
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.
11  *
12  */
13
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>
19 #include <linux/fb.h>
20 #include <linux/backlight.h>
21
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;
26
27 /* Flag to signal when the battery is low */
28 #define CORGIBL_BATTLOW       BL_CORE_DRIVER1
29
30 static int corgibl_send_intensity(struct backlight_device *bd)
31 {
32         int intensity = bd->props.brightness;
33
34         if (bd->props.power != FB_BLANK_UNBLANK)
35                 intensity = 0;
36         if (bd->props.state & BL_CORE_FBBLANK)
37                 intensity = 0;
38         if (bd->props.state & BL_CORE_SUSPENDED)
39                 intensity = 0;
40         if (bd->props.state & CORGIBL_BATTLOW)
41                 intensity &= bl_machinfo->limit_mask;
42
43         bl_machinfo->set_bl_intensity(intensity);
44
45         corgibl_intensity = intensity;
46
47         if (bl_machinfo->kick_battery)
48                 bl_machinfo->kick_battery();
49
50         return 0;
51 }
52
53 static int corgibl_get_intensity(struct backlight_device *bd)
54 {
55         return corgibl_intensity;
56 }
57
58 /*
59  * Called when the battery is low to limit the backlight intensity.
60  * If limit==0 clear any limit, otherwise limit the intensity
61  */
62 void corgibl_limit_intensity(int limit)
63 {
64         struct backlight_device *bd = corgi_backlight_device;
65
66         mutex_lock(&bd->ops_lock);
67         if (limit)
68                 bd->props.state |= CORGIBL_BATTLOW;
69         else
70                 bd->props.state &= ~CORGIBL_BATTLOW;
71         backlight_update_status(corgi_backlight_device);
72         mutex_unlock(&bd->ops_lock);
73 }
74 EXPORT_SYMBOL(corgibl_limit_intensity);
75
76
77 static struct backlight_ops corgibl_ops = {
78         .options = BL_CORE_SUSPENDRESUME,
79         .get_brightness = corgibl_get_intensity,
80         .update_status  = corgibl_send_intensity,
81 };
82
83 static int corgibl_probe(struct platform_device *pdev)
84 {
85         struct generic_bl_info *machinfo = pdev->dev.platform_data;
86         const char *name = "generic-bl";
87
88         bl_machinfo = machinfo;
89         if (!machinfo->limit_mask)
90                 machinfo->limit_mask = -1;
91
92         if (machinfo->name)
93                 name = machinfo->name;
94
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);
99
100         platform_set_drvdata(pdev, corgi_backlight_device);
101
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);
106
107         printk("Corgi Backlight Driver Initialized.\n");
108         return 0;
109 }
110
111 static int corgibl_remove(struct platform_device *pdev)
112 {
113         struct backlight_device *bd = platform_get_drvdata(pdev);
114
115         corgibl_data.power = 0;
116         corgibl_data.brightness = 0;
117         backlight_update_status(bd);
118
119         backlight_device_unregister(bd);
120
121         printk("Corgi Backlight Driver Unloaded\n");
122         return 0;
123 }
124
125 static struct platform_driver corgibl_driver = {
126         .probe          = corgibl_probe,
127         .remove         = corgibl_remove,
128         .driver         = {
129                 .name   = "generic-bl",
130         },
131 };
132
133 static int __init corgibl_init(void)
134 {
135         return platform_driver_register(&corgibl_driver);
136 }
137
138 static void __exit corgibl_exit(void)
139 {
140         platform_driver_unregister(&corgibl_driver);
141 }
142
143 module_init(corgibl_init);
144 module_exit(corgibl_exit);
145
146 MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>");
147 MODULE_DESCRIPTION("Corgi Backlight Driver");
148 MODULE_LICENSE("GPL");