2 * drivers/video/backlight/omap_bl.c
4 * Backlight driver for OMAP based boards.
6 * Copyright (c) 2006 Andrzej Zaborowski <balrog@zabor.org>
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.
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.
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
23 #include <linux/module.h>
24 #include <linux/kernel.h>
25 #include <linux/init.h>
26 #include <linux/platform_device.h>
28 #include <linux/backlight.h>
30 #include <asm/arch/hardware.h>
31 #include <asm/arch/board.h>
32 #include <asm/arch/mux.h>
34 #define OMAPBL_MAX_INTENSITY 0xff
36 struct omap_backlight {
38 int current_intensity;
41 struct omap_backlight_config *pdata;
44 static void inline omapbl_send_intensity(int intensity)
46 omap_writeb(intensity, OMAP_PWL_ENABLE);
49 static void inline omapbl_send_enable(int enable)
51 omap_writeb(enable, OMAP_PWL_CLK_ENABLE);
54 static void omapbl_blank(struct omap_backlight *bl, int mode)
56 if (bl->pdata->set_power)
57 bl->pdata->set_power(bl->dev, mode);
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);
68 case FB_BLANK_UNBLANK:
69 omapbl_send_intensity(bl->current_intensity);
70 omapbl_send_enable(1);
76 static int omapbl_suspend(struct platform_device *pdev, pm_message_t state)
78 struct backlight_device *dev = platform_get_drvdata(pdev);
79 struct omap_backlight *bl = dev_get_drvdata(&dev->dev);
81 omapbl_blank(bl, FB_BLANK_POWERDOWN);
85 static int omapbl_resume(struct platform_device *pdev)
87 struct backlight_device *dev = platform_get_drvdata(pdev);
88 struct omap_backlight *bl = dev_get_drvdata(&dev->dev);
90 omapbl_blank(bl, bl->powermode);
94 #define omapbl_suspend NULL
95 #define omapbl_resume NULL
98 static int omapbl_set_power(struct backlight_device *dev, int state)
100 struct omap_backlight *bl = dev_get_drvdata(&dev->dev);
102 omapbl_blank(bl, state);
103 bl->powermode = state;
108 static int omapbl_update_status(struct backlight_device *dev)
110 struct omap_backlight *bl = dev_get_drvdata(&dev->dev);
112 if (bl->current_intensity != dev->props.brightness) {
113 if (dev->props.brightness < 0)
114 return -EPERM; /* Leave current_intensity untouched */
116 if (bl->powermode == FB_BLANK_UNBLANK)
117 omapbl_send_intensity(dev->props.brightness);
118 bl->current_intensity = dev->props.brightness;
121 if (dev->props.fb_blank != bl->powermode)
122 omapbl_set_power(dev, dev->props.fb_blank);
128 static int omapbl_get_intensity(struct backlight_device *dev)
130 struct omap_backlight *bl = dev_get_drvdata(&dev->dev);
131 return bl->current_intensity;
134 static struct backlight_ops omapbl_ops = {
135 .get_brightness = omapbl_get_intensity,
136 .update_status = omapbl_update_status,
140 static int omapbl_probe(struct platform_device *pdev)
142 struct backlight_device *dev;
143 struct omap_backlight *bl;
144 struct omap_backlight_config *pdata = pdev->dev.platform_data;
149 omapbl_ops.check_fb = pdata->check_fb;
151 bl = kzalloc(sizeof(struct omap_backlight), GFP_KERNEL);
155 dev = backlight_device_register("omap-bl", &pdev->dev,
162 bl->powermode = FB_BLANK_POWERDOWN;
163 bl->current_intensity = 0;
166 bl->dev = &pdev->dev;
168 platform_set_drvdata(pdev, dev);
170 omap_cfg_reg(PWL); /* Conflicts with UART3 */
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);
177 printk(KERN_INFO "OMAP LCD backlight initialised\n");
182 static int omapbl_remove(struct platform_device *pdev)
184 struct backlight_device *dev = platform_get_drvdata(pdev);
185 struct omap_backlight *bl = dev_get_drvdata(&dev->dev);
187 backlight_device_unregister(dev);
193 static struct platform_driver omapbl_driver = {
194 .probe = omapbl_probe,
195 .remove = omapbl_remove,
196 .suspend = omapbl_suspend,
197 .resume = omapbl_resume,
203 static int __init omapbl_init(void)
205 return platform_driver_register(&omapbl_driver);
208 static void __exit omapbl_exit(void)
210 platform_driver_unregister(&omapbl_driver);
213 module_init(omapbl_init);
214 module_exit(omapbl_exit);
216 MODULE_AUTHOR("Andrzej Zaborowski <balrog@zabor.org>");
217 MODULE_DESCRIPTION("OMAP LCD Backlight driver");
218 MODULE_LICENSE("GPL");