scsi: use per-cpu buffer for formatting scsi_print_result()
[linux/fpc-iii.git] / drivers / video / backlight / omap1_bl.c
blob546d94df21d53ac436891273828058043acb2c2d
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 #include <linux/module.h>
22 #include <linux/kernel.h>
23 #include <linux/init.h>
24 #include <linux/platform_device.h>
25 #include <linux/fb.h>
26 #include <linux/backlight.h>
27 #include <linux/slab.h>
28 #include <linux/platform_data/omap1_bl.h>
30 #include <mach/hardware.h>
31 #include <mach/mux.h>
33 #define OMAPBL_MAX_INTENSITY 0xff
35 struct omap_backlight {
36 int powermode;
37 int current_intensity;
39 struct device *dev;
40 struct omap_backlight_config *pdata;
43 static inline void omapbl_send_intensity(int intensity)
45 omap_writeb(intensity, OMAP_PWL_ENABLE);
48 static inline void omapbl_send_enable(int enable)
50 omap_writeb(enable, OMAP_PWL_CLK_ENABLE);
53 static void omapbl_blank(struct omap_backlight *bl, int mode)
55 if (bl->pdata->set_power)
56 bl->pdata->set_power(bl->dev, mode);
58 switch (mode) {
59 case FB_BLANK_NORMAL:
60 case FB_BLANK_VSYNC_SUSPEND:
61 case FB_BLANK_HSYNC_SUSPEND:
62 case FB_BLANK_POWERDOWN:
63 omapbl_send_intensity(0);
64 omapbl_send_enable(0);
65 break;
67 case FB_BLANK_UNBLANK:
68 omapbl_send_intensity(bl->current_intensity);
69 omapbl_send_enable(1);
70 break;
74 #ifdef CONFIG_PM_SLEEP
75 static int omapbl_suspend(struct device *dev)
77 struct backlight_device *bl_dev = dev_get_drvdata(dev);
78 struct omap_backlight *bl = bl_get_data(bl_dev);
80 omapbl_blank(bl, FB_BLANK_POWERDOWN);
81 return 0;
84 static int omapbl_resume(struct device *dev)
86 struct backlight_device *bl_dev = dev_get_drvdata(dev);
87 struct omap_backlight *bl = bl_get_data(bl_dev);
89 omapbl_blank(bl, bl->powermode);
90 return 0;
92 #endif
94 static int omapbl_set_power(struct backlight_device *dev, int state)
96 struct omap_backlight *bl = bl_get_data(dev);
98 omapbl_blank(bl, state);
99 bl->powermode = state;
101 return 0;
104 static int omapbl_update_status(struct backlight_device *dev)
106 struct omap_backlight *bl = bl_get_data(dev);
108 if (bl->current_intensity != dev->props.brightness) {
109 if (bl->powermode == FB_BLANK_UNBLANK)
110 omapbl_send_intensity(dev->props.brightness);
111 bl->current_intensity = dev->props.brightness;
114 if (dev->props.fb_blank != bl->powermode)
115 omapbl_set_power(dev, dev->props.fb_blank);
117 return 0;
120 static int omapbl_get_intensity(struct backlight_device *dev)
122 struct omap_backlight *bl = bl_get_data(dev);
124 return bl->current_intensity;
127 static const struct backlight_ops omapbl_ops = {
128 .get_brightness = omapbl_get_intensity,
129 .update_status = omapbl_update_status,
132 static int omapbl_probe(struct platform_device *pdev)
134 struct backlight_properties props;
135 struct backlight_device *dev;
136 struct omap_backlight *bl;
137 struct omap_backlight_config *pdata = dev_get_platdata(&pdev->dev);
139 if (!pdata)
140 return -ENXIO;
142 bl = devm_kzalloc(&pdev->dev, sizeof(struct omap_backlight),
143 GFP_KERNEL);
144 if (unlikely(!bl))
145 return -ENOMEM;
147 memset(&props, 0, sizeof(struct backlight_properties));
148 props.type = BACKLIGHT_RAW;
149 props.max_brightness = OMAPBL_MAX_INTENSITY;
150 dev = devm_backlight_device_register(&pdev->dev, "omap-bl", &pdev->dev,
151 bl, &omapbl_ops, &props);
152 if (IS_ERR(dev))
153 return PTR_ERR(dev);
155 bl->powermode = FB_BLANK_POWERDOWN;
156 bl->current_intensity = 0;
158 bl->pdata = pdata;
159 bl->dev = &pdev->dev;
161 platform_set_drvdata(pdev, dev);
163 omap_cfg_reg(PWL); /* Conflicts with UART3 */
165 dev->props.fb_blank = FB_BLANK_UNBLANK;
166 dev->props.brightness = pdata->default_intensity;
167 omapbl_update_status(dev);
169 dev_info(&pdev->dev, "OMAP LCD backlight initialised\n");
171 return 0;
174 static SIMPLE_DEV_PM_OPS(omapbl_pm_ops, omapbl_suspend, omapbl_resume);
176 static struct platform_driver omapbl_driver = {
177 .probe = omapbl_probe,
178 .driver = {
179 .name = "omap-bl",
180 .pm = &omapbl_pm_ops,
184 module_platform_driver(omapbl_driver);
186 MODULE_AUTHOR("Andrzej Zaborowski <balrog@zabor.org>");
187 MODULE_DESCRIPTION("OMAP LCD Backlight driver");
188 MODULE_LICENSE("GPL");