]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/video/backlight/omap_bl.c
OMAP2EVM: twl4030 keypad Kconfig dependency fix
[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 = dev_get_drvdata(&dev->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 = dev_get_drvdata(&dev->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 = dev_get_drvdata(&dev->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 = dev_get_drvdata(&dev->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
128 static int omapbl_get_intensity(struct backlight_device *dev)
129 {
130         struct omap_backlight *bl = dev_get_drvdata(&dev->dev);
131         return bl->current_intensity;
132 }
133
134 static struct backlight_ops omapbl_ops = {
135         .get_brightness = omapbl_get_intensity,
136         .update_status  = omapbl_update_status,
137 };
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_ops.check_fb = pdata->check_fb;
150
151         bl = kzalloc(sizeof(struct omap_backlight), GFP_KERNEL);
152         if (unlikely(!bl))
153                 return -ENOMEM;
154
155         dev = backlight_device_register("omap-bl", &pdev->dev,
156                         bl, &omapbl_ops);
157         if (IS_ERR(dev)) {
158                 kfree(bl);
159                 return PTR_ERR(dev);
160         }
161
162         bl->powermode = FB_BLANK_POWERDOWN;
163         bl->current_intensity = 0;
164
165         bl->pdata = pdata;
166         bl->dev = &pdev->dev;
167
168         platform_set_drvdata(pdev, dev);
169
170         omap_cfg_reg(PWL);      /* Conflicts with UART3 */
171
172         dev->props.fb_blank = FB_BLANK_UNBLANK;
173         dev->props.max_brightness = OMAPBL_MAX_INTENSITY;
174         dev->props.brightness = pdata->default_intensity;
175         omapbl_update_status(dev);
176
177         printk(KERN_INFO "OMAP LCD backlight initialised\n");
178
179         return 0;
180 }
181
182 static int omapbl_remove(struct platform_device *pdev)
183 {
184         struct backlight_device *dev = platform_get_drvdata(pdev);
185         struct omap_backlight *bl = dev_get_drvdata(&dev->dev);
186
187         backlight_device_unregister(dev);
188         kfree(bl);
189
190         return 0;
191 }
192
193 static struct platform_driver omapbl_driver = {
194         .probe          = omapbl_probe,
195         .remove         = omapbl_remove,
196         .suspend        = omapbl_suspend,
197         .resume         = omapbl_resume,
198         .driver         = {
199                 .name   = "omap-bl",
200         },
201 };
202
203 static int __init omapbl_init(void)
204 {
205         return platform_driver_register(&omapbl_driver);
206 }
207
208 static void __exit omapbl_exit(void)
209 {
210         platform_driver_unregister(&omapbl_driver);
211 }
212
213 module_init(omapbl_init);
214 module_exit(omapbl_exit);
215
216 MODULE_AUTHOR("Andrzej Zaborowski <balrog@zabor.org>");
217 MODULE_DESCRIPTION("OMAP LCD Backlight driver");
218 MODULE_LICENSE("GPL");