initial commit with v3.6.7
[linux-3.6.7-moxart.git] / drivers / video / backlight / omap1_bl.c
blobbfdc5fbeaa116aa7e919c191eac4dcac2f3985bc
1 /*
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 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
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 #include <linux/slab.h>
31 #include <mach/hardware.h>
32 #include <plat/board.h>
33 #include <plat/mux.h>
35 #define OMAPBL_MAX_INTENSITY 0xff
37 struct omap_backlight {
38 int powermode;
39 int current_intensity;
41 struct device *dev;
42 struct omap_backlight_config *pdata;
45 static void inline omapbl_send_intensity(int intensity)
47 omap_writeb(intensity, OMAP_PWL_ENABLE);
50 static void inline omapbl_send_enable(int enable)
52 omap_writeb(enable, OMAP_PWL_CLK_ENABLE);
55 static void omapbl_blank(struct omap_backlight *bl, int mode)
57 if (bl->pdata->set_power)
58 bl->pdata->set_power(bl->dev, mode);
60 switch (mode) {
61 case FB_BLANK_NORMAL:
62 case FB_BLANK_VSYNC_SUSPEND:
63 case FB_BLANK_HSYNC_SUSPEND:
64 case FB_BLANK_POWERDOWN:
65 omapbl_send_intensity(0);
66 omapbl_send_enable(0);
67 break;
69 case FB_BLANK_UNBLANK:
70 omapbl_send_intensity(bl->current_intensity);
71 omapbl_send_enable(1);
72 break;
76 #ifdef CONFIG_PM
77 static int omapbl_suspend(struct platform_device *pdev, pm_message_t state)
79 struct backlight_device *dev = platform_get_drvdata(pdev);
80 struct omap_backlight *bl = dev_get_drvdata(&dev->dev);
82 omapbl_blank(bl, FB_BLANK_POWERDOWN);
83 return 0;
86 static int omapbl_resume(struct platform_device *pdev)
88 struct backlight_device *dev = platform_get_drvdata(pdev);
89 struct omap_backlight *bl = dev_get_drvdata(&dev->dev);
91 omapbl_blank(bl, bl->powermode);
92 return 0;
94 #else
95 #define omapbl_suspend NULL
96 #define omapbl_resume NULL
97 #endif
99 static int omapbl_set_power(struct backlight_device *dev, int state)
101 struct omap_backlight *bl = dev_get_drvdata(&dev->dev);
103 omapbl_blank(bl, state);
104 bl->powermode = state;
106 return 0;
109 static int omapbl_update_status(struct backlight_device *dev)
111 struct omap_backlight *bl = dev_get_drvdata(&dev->dev);
113 if (bl->current_intensity != dev->props.brightness) {
114 if (bl->powermode == FB_BLANK_UNBLANK)
115 omapbl_send_intensity(dev->props.brightness);
116 bl->current_intensity = dev->props.brightness;
119 if (dev->props.fb_blank != bl->powermode)
120 omapbl_set_power(dev, dev->props.fb_blank);
122 return 0;
125 static int omapbl_get_intensity(struct backlight_device *dev)
127 struct omap_backlight *bl = dev_get_drvdata(&dev->dev);
128 return bl->current_intensity;
131 static const struct backlight_ops omapbl_ops = {
132 .get_brightness = omapbl_get_intensity,
133 .update_status = omapbl_update_status,
136 static int omapbl_probe(struct platform_device *pdev)
138 struct backlight_properties props;
139 struct backlight_device *dev;
140 struct omap_backlight *bl;
141 struct omap_backlight_config *pdata = pdev->dev.platform_data;
143 if (!pdata)
144 return -ENXIO;
146 bl = devm_kzalloc(&pdev->dev, sizeof(struct omap_backlight),
147 GFP_KERNEL);
148 if (unlikely(!bl))
149 return -ENOMEM;
151 memset(&props, 0, sizeof(struct backlight_properties));
152 props.type = BACKLIGHT_RAW;
153 props.max_brightness = OMAPBL_MAX_INTENSITY;
154 dev = backlight_device_register("omap-bl", &pdev->dev, bl, &omapbl_ops,
155 &props);
156 if (IS_ERR(dev))
157 return PTR_ERR(dev);
159 bl->powermode = FB_BLANK_POWERDOWN;
160 bl->current_intensity = 0;
162 bl->pdata = pdata;
163 bl->dev = &pdev->dev;
165 platform_set_drvdata(pdev, dev);
167 omap_cfg_reg(PWL); /* Conflicts with UART3 */
169 dev->props.fb_blank = FB_BLANK_UNBLANK;
170 dev->props.brightness = pdata->default_intensity;
171 omapbl_update_status(dev);
173 pr_info("OMAP LCD backlight initialised\n");
175 return 0;
178 static int omapbl_remove(struct platform_device *pdev)
180 struct backlight_device *dev = platform_get_drvdata(pdev);
182 backlight_device_unregister(dev);
184 return 0;
187 static struct platform_driver omapbl_driver = {
188 .probe = omapbl_probe,
189 .remove = omapbl_remove,
190 .suspend = omapbl_suspend,
191 .resume = omapbl_resume,
192 .driver = {
193 .name = "omap-bl",
197 module_platform_driver(omapbl_driver);
199 MODULE_AUTHOR("Andrzej Zaborowski <balrog@zabor.org>");
200 MODULE_DESCRIPTION("OMAP LCD Backlight driver");
201 MODULE_LICENSE("GPL");