]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/video/backlight/omap_bl.c
ARM: OMAP: osk+mistral backlight, power, driver specific
[linux-2.6-omap-h63xx.git] / drivers / video / backlight / omap_bl.c
1 /*
2  * drivers/video/backlight/omap_bl.c
3  *
4  * Backlight driver for OMAP based boards.
5  *
6  * Copyright (c) 2006 Andrzej Zaborowski  <balrog@zabor.org>
7  *
8  * This package is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This package is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this package; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22
23 #include <linux/module.h>
24 #include <linux/kernel.h>
25 #include <linux/init.h>
26 #include <linux/platform_device.h>
27 #include <linux/fb.h>
28 #include <linux/backlight.h>
29
30 #include <asm/arch/hardware.h>
31 #include <asm/arch/board.h>
32 #include <asm/arch/mux.h>
33
34 #define OMAPBL_MAX_INTENSITY            0xff
35
36 struct omap_backlight {
37         int powermode;
38         int current_intensity;
39
40         struct device *dev;
41         struct omap_backlight_config *pdata;
42 };
43
44 static void inline omapbl_send_intensity(int intensity)
45 {
46         omap_writeb(intensity, OMAP_PWL_ENABLE);
47 }
48
49 static void inline omapbl_send_enable(int enable)
50 {
51         omap_writeb(enable, OMAP_PWL_CLK_ENABLE);
52 }
53
54 static void omapbl_blank(struct omap_backlight *bl, int mode)
55 {
56         if (bl->pdata->set_power)
57                 bl->pdata->set_power(bl->dev, mode);
58
59         switch (mode) {
60         case FB_BLANK_NORMAL:
61         case FB_BLANK_VSYNC_SUSPEND:
62         case FB_BLANK_HSYNC_SUSPEND:
63         case FB_BLANK_POWERDOWN:
64                 omapbl_send_intensity(0);
65                 omapbl_send_enable(0);
66                 break;
67
68         case FB_BLANK_UNBLANK:
69                 omapbl_send_intensity(bl->current_intensity);
70                 omapbl_send_enable(1);
71                 break;
72         }
73 }
74
75 #ifdef CONFIG_PM
76 static int omapbl_suspend(struct platform_device *pdev, pm_message_t state)
77 {
78         struct backlight_device *dev = platform_get_drvdata(pdev);
79         struct omap_backlight *bl = class_get_devdata(&dev->class_dev);
80
81         omapbl_blank(bl, FB_BLANK_POWERDOWN);
82         return 0;
83 }
84
85 static int omapbl_resume(struct platform_device *pdev)
86 {
87         struct backlight_device *dev = platform_get_drvdata(pdev);
88         struct omap_backlight *bl = class_get_devdata(&dev->class_dev);
89
90         omapbl_blank(bl, bl->powermode);
91         return 0;
92 }
93 #else
94 #define omapbl_suspend  NULL
95 #define omapbl_resume   NULL
96 #endif
97
98 static int omapbl_set_power(struct backlight_device *dev, int state)
99 {
100         struct omap_backlight *bl = class_get_devdata(&dev->class_dev);
101
102         omapbl_blank(bl, state);
103         bl->powermode = state;
104
105         return 0;
106 }
107
108 static int omapbl_update_status(struct backlight_device *dev)
109 {
110         struct omap_backlight *bl = class_get_devdata(&dev->class_dev);
111
112         if (bl->current_intensity != dev->props->brightness) {
113                 if (dev->props->brightness < 0)
114                         return -EPERM;  /* Leave current_intensity untouched */
115
116                 if (bl->powermode == FB_BLANK_UNBLANK)
117                         omapbl_send_intensity(dev->props->brightness);
118                 bl->current_intensity = dev->props->brightness;
119         }
120
121         if (dev->props->fb_blank != bl->powermode)
122                 omapbl_set_power(dev, dev->props->fb_blank);
123
124         return 0;
125 }
126
127 static int omapbl_get_intensity(struct backlight_device *dev)
128 {
129         struct omap_backlight *bl = class_get_devdata(&dev->class_dev);
130         return bl->current_intensity;
131 }
132
133 static struct backlight_properties omapbl_data = {
134         .owner          = THIS_MODULE,
135         .get_brightness = omapbl_get_intensity,
136         .update_status  = omapbl_update_status,
137         .max_brightness = OMAPBL_MAX_INTENSITY,
138 };
139
140 static int omapbl_probe(struct platform_device *pdev)
141 {
142         struct backlight_device *dev;
143         struct omap_backlight *bl;
144         struct omap_backlight_config *pdata = pdev->dev.platform_data;
145
146         if (!pdata)
147                 return -ENXIO;
148
149         omapbl_data.check_fb = pdata->check_fb;
150
151         bl = kzalloc(sizeof(struct omap_backlight), GFP_KERNEL);
152         if (unlikely(!bl))
153                 return -ENOMEM;
154
155         /* REVISIT backlight API glitch:  we can't associate the
156          * class device with "pdev" ... probably pass &pdev->dev
157          * instead of a string.
158          */
159
160         dev = backlight_device_register("omap-bl", bl, &omapbl_data);
161         if (IS_ERR(dev)) {
162                 kfree(bl);
163                 return PTR_ERR(dev);
164         }
165
166         bl->powermode = FB_BLANK_POWERDOWN;
167         bl->current_intensity = 0;
168
169         bl->pdata = pdata;
170         bl->dev = &pdev->dev;
171
172         platform_set_drvdata(pdev, dev);
173
174         omap_cfg_reg(PWL);      /* Conflicts with UART3 */
175
176         omapbl_data.fb_blank = FB_BLANK_UNBLANK;
177         omapbl_data.brightness = pdata->default_intensity;
178         omapbl_update_status(dev);
179
180         printk(KERN_INFO "OMAP LCD backlight initialised\n");
181
182         return 0;
183 }
184
185 static int omapbl_remove(struct platform_device *pdev)
186 {
187         struct backlight_device *dev = platform_get_drvdata(pdev);
188         struct omap_backlight *bl = class_get_devdata(&dev->class_dev);
189
190         backlight_device_unregister(dev);
191         kfree(bl);
192
193         return 0;
194 }
195
196 static struct platform_driver omapbl_driver = {
197         .probe          = omapbl_probe,
198         .remove         = omapbl_remove,
199         .suspend        = omapbl_suspend,
200         .resume         = omapbl_resume,
201         .driver         = {
202                 .name   = "omap-bl",
203         },
204 };
205
206 static int __init omapbl_init(void)
207 {
208         return platform_driver_register(&omapbl_driver);
209 }
210
211 static void __exit omapbl_exit(void)
212 {
213         platform_driver_unregister(&omapbl_driver);
214 }
215
216 module_init(omapbl_init);
217 module_exit(omapbl_exit);
218
219 MODULE_AUTHOR("Andrzej Zaborowski <balrog@zabor.org>");
220 MODULE_DESCRIPTION("OMAP LCD Backlight driver");
221 MODULE_LICENSE("GPL");