2 * Backlight driver for OMAP based boards.
4 * Copyright (c) 2006 Andrzej Zaborowski <balrog@zabor.org>
6 * This package is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This package is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this package; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <linux/module.h>
22 #include <linux/kernel.h>
23 #include <linux/init.h>
24 #include <linux/platform_device.h>
26 #include <linux/backlight.h>
28 #include <mach/hardware.h>
29 #include <mach/board.h>
32 #define OMAPBL_MAX_INTENSITY 0xff
34 struct omap_backlight {
36 int current_intensity;
39 struct omap_backlight_config *pdata;
42 static void inline omapbl_send_intensity(int intensity)
44 omap_writeb(intensity, OMAP_PWL_ENABLE);
47 static void inline omapbl_send_enable(int enable)
49 omap_writeb(enable, OMAP_PWL_CLK_ENABLE);
52 static void omapbl_blank(struct omap_backlight *bl, int mode)
54 if (bl->pdata->set_power)
55 bl->pdata->set_power(bl->dev, mode);
59 case FB_BLANK_VSYNC_SUSPEND:
60 case FB_BLANK_HSYNC_SUSPEND:
61 case FB_BLANK_POWERDOWN:
62 omapbl_send_intensity(0);
63 omapbl_send_enable(0);
66 case FB_BLANK_UNBLANK:
67 omapbl_send_intensity(bl->current_intensity);
68 omapbl_send_enable(1);
74 static int omapbl_suspend(struct platform_device *pdev, pm_message_t state)
76 struct backlight_device *dev = platform_get_drvdata(pdev);
77 struct omap_backlight *bl = dev_get_drvdata(&dev->dev);
79 omapbl_blank(bl, FB_BLANK_POWERDOWN);
83 static int omapbl_resume(struct platform_device *pdev)
85 struct backlight_device *dev = platform_get_drvdata(pdev);
86 struct omap_backlight *bl = dev_get_drvdata(&dev->dev);
88 omapbl_blank(bl, bl->powermode);
92 #define omapbl_suspend NULL
93 #define omapbl_resume NULL
96 static int omapbl_set_power(struct backlight_device *dev, int state)
98 struct omap_backlight *bl = dev_get_drvdata(&dev->dev);
100 omapbl_blank(bl, state);
101 bl->powermode = state;
106 static int omapbl_update_status(struct backlight_device *dev)
108 struct omap_backlight *bl = dev_get_drvdata(&dev->dev);
110 if (bl->current_intensity != dev->props.brightness) {
111 if (bl->powermode == FB_BLANK_UNBLANK)
112 omapbl_send_intensity(dev->props.brightness);
113 bl->current_intensity = dev->props.brightness;
116 if (dev->props.fb_blank != bl->powermode)
117 omapbl_set_power(dev, dev->props.fb_blank);
122 static int omapbl_get_intensity(struct backlight_device *dev)
124 struct omap_backlight *bl = dev_get_drvdata(&dev->dev);
125 return bl->current_intensity;
128 static struct backlight_ops omapbl_ops = {
129 .get_brightness = omapbl_get_intensity,
130 .update_status = omapbl_update_status,
133 static int omapbl_probe(struct platform_device *pdev)
135 struct backlight_device *dev;
136 struct omap_backlight *bl;
137 struct omap_backlight_config *pdata = pdev->dev.platform_data;
142 omapbl_ops.check_fb = pdata->check_fb;
144 bl = kzalloc(sizeof(struct omap_backlight), GFP_KERNEL);
148 dev = backlight_device_register("omap-bl", &pdev->dev, bl, &omapbl_ops);
154 bl->powermode = FB_BLANK_POWERDOWN;
155 bl->current_intensity = 0;
158 bl->dev = &pdev->dev;
160 platform_set_drvdata(pdev, dev);
162 omap_cfg_reg(PWL); /* Conflicts with UART3 */
164 dev->props.fb_blank = FB_BLANK_UNBLANK;
165 dev->props.max_brightness = OMAPBL_MAX_INTENSITY;
166 dev->props.brightness = pdata->default_intensity;
167 omapbl_update_status(dev);
169 printk(KERN_INFO "OMAP LCD backlight initialised\n");
174 static int omapbl_remove(struct platform_device *pdev)
176 struct backlight_device *dev = platform_get_drvdata(pdev);
177 struct omap_backlight *bl = dev_get_drvdata(&dev->dev);
179 backlight_device_unregister(dev);
185 static struct platform_driver omapbl_driver = {
186 .probe = omapbl_probe,
187 .remove = omapbl_remove,
188 .suspend = omapbl_suspend,
189 .resume = omapbl_resume,
195 static int __init omapbl_init(void)
197 return platform_driver_register(&omapbl_driver);
200 static void __exit omapbl_exit(void)
202 platform_driver_unregister(&omapbl_driver);
205 module_init(omapbl_init);
206 module_exit(omapbl_exit);
208 MODULE_AUTHOR("Andrzej Zaborowski <balrog@zabor.org>");
209 MODULE_DESCRIPTION("OMAP LCD Backlight driver");
210 MODULE_LICENSE("GPL");