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>
27 #include <linux/slab.h>
29 #include <mach/hardware.h>
30 #include <plat/board.h>
33 #define OMAPBL_MAX_INTENSITY 0xff
35 struct omap_backlight
{
37 int current_intensity
;
40 struct omap_backlight_config
*pdata
;
43 static void inline omapbl_send_intensity(int intensity
)
45 omap_writeb(intensity
, OMAP_PWL_ENABLE
);
48 static void inline 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
);
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);
67 case FB_BLANK_UNBLANK
:
68 omapbl_send_intensity(bl
->current_intensity
);
69 omapbl_send_enable(1);
75 static int omapbl_suspend(struct platform_device
*pdev
, pm_message_t state
)
77 struct backlight_device
*dev
= platform_get_drvdata(pdev
);
78 struct omap_backlight
*bl
= dev_get_drvdata(&dev
->dev
);
80 omapbl_blank(bl
, FB_BLANK_POWERDOWN
);
84 static int omapbl_resume(struct platform_device
*pdev
)
86 struct backlight_device
*dev
= platform_get_drvdata(pdev
);
87 struct omap_backlight
*bl
= dev_get_drvdata(&dev
->dev
);
89 omapbl_blank(bl
, bl
->powermode
);
93 #define omapbl_suspend NULL
94 #define omapbl_resume NULL
97 static int omapbl_set_power(struct backlight_device
*dev
, int state
)
99 struct omap_backlight
*bl
= dev_get_drvdata(&dev
->dev
);
101 omapbl_blank(bl
, state
);
102 bl
->powermode
= state
;
107 static int omapbl_update_status(struct backlight_device
*dev
)
109 struct omap_backlight
*bl
= dev_get_drvdata(&dev
->dev
);
111 if (bl
->current_intensity
!= dev
->props
.brightness
) {
112 if (bl
->powermode
== FB_BLANK_UNBLANK
)
113 omapbl_send_intensity(dev
->props
.brightness
);
114 bl
->current_intensity
= dev
->props
.brightness
;
117 if (dev
->props
.fb_blank
!= bl
->powermode
)
118 omapbl_set_power(dev
, dev
->props
.fb_blank
);
123 static int omapbl_get_intensity(struct backlight_device
*dev
)
125 struct omap_backlight
*bl
= dev_get_drvdata(&dev
->dev
);
126 return bl
->current_intensity
;
129 static const struct backlight_ops omapbl_ops
= {
130 .get_brightness
= omapbl_get_intensity
,
131 .update_status
= omapbl_update_status
,
134 static int omapbl_probe(struct platform_device
*pdev
)
136 struct backlight_properties props
;
137 struct backlight_device
*dev
;
138 struct omap_backlight
*bl
;
139 struct omap_backlight_config
*pdata
= pdev
->dev
.platform_data
;
144 bl
= kzalloc(sizeof(struct omap_backlight
), GFP_KERNEL
);
148 memset(&props
, 0, sizeof(struct backlight_properties
));
149 props
.type
= BACKLIGHT_RAW
;
150 props
.max_brightness
= OMAPBL_MAX_INTENSITY
;
151 dev
= backlight_device_register("omap-bl", &pdev
->dev
, bl
, &omapbl_ops
,
158 bl
->powermode
= FB_BLANK_POWERDOWN
;
159 bl
->current_intensity
= 0;
162 bl
->dev
= &pdev
->dev
;
164 platform_set_drvdata(pdev
, dev
);
166 omap_cfg_reg(PWL
); /* Conflicts with UART3 */
168 dev
->props
.fb_blank
= FB_BLANK_UNBLANK
;
169 dev
->props
.brightness
= pdata
->default_intensity
;
170 omapbl_update_status(dev
);
172 printk(KERN_INFO
"OMAP LCD backlight initialised\n");
177 static int omapbl_remove(struct platform_device
*pdev
)
179 struct backlight_device
*dev
= platform_get_drvdata(pdev
);
180 struct omap_backlight
*bl
= dev_get_drvdata(&dev
->dev
);
182 backlight_device_unregister(dev
);
188 static struct platform_driver omapbl_driver
= {
189 .probe
= omapbl_probe
,
190 .remove
= omapbl_remove
,
191 .suspend
= omapbl_suspend
,
192 .resume
= omapbl_resume
,
198 module_platform_driver(omapbl_driver
);
200 MODULE_AUTHOR("Andrzej Zaborowski <balrog@zabor.org>");
201 MODULE_DESCRIPTION("OMAP LCD Backlight driver");
202 MODULE_LICENSE("GPL");