Merge branch 'devel-stable' of master.kernel.org:/home/rmk/linux-2.6-arm
[pandora-kernel.git] / drivers / staging / msm / msm_fb_bl.c
1 /* Copyright (c) 2008-2009, Code Aurora Forum. All rights reserved.
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2 and
5  * only version 2 as published by the Free Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17
18 #include <linux/module.h>
19 #include <linux/moduleparam.h>
20 #include <linux/kernel.h>
21 #include <linux/slab.h>
22 #include <linux/fb.h>
23 #include <linux/string.h>
24 #include <linux/version.h>
25 #include <linux/backlight.h>
26
27 #include "msm_fb.h"
28
29 static int msm_fb_bl_get_brightness(struct backlight_device *pbd)
30 {
31         return pbd->props.brightness;
32 }
33
34 static int msm_fb_bl_update_status(struct backlight_device *pbd)
35 {
36         struct msm_fb_data_type *mfd = bl_get_data(pbd);
37         __u32 bl_lvl;
38
39         bl_lvl = pbd->props.brightness;
40         bl_lvl = mfd->fbi->bl_curve[bl_lvl];
41         msm_fb_set_backlight(mfd, bl_lvl, 1);
42         return 0;
43 }
44
45 static const struct backlight_ops msm_fb_bl_ops = {
46         .get_brightness = msm_fb_bl_get_brightness,
47         .update_status = msm_fb_bl_update_status,
48 };
49
50 void msm_fb_config_backlight(struct msm_fb_data_type *mfd)
51 {
52         struct msm_fb_panel_data *pdata;
53         struct backlight_device *pbd;
54         struct fb_info *fbi;
55         char name[16];
56
57         fbi = mfd->fbi;
58         pdata = (struct msm_fb_panel_data *)mfd->pdev->dev.platform_data;
59
60         if ((pdata) && (pdata->set_backlight)) {
61                 snprintf(name, sizeof(name), "msmfb_bl%d", mfd->index);
62                 pbd =
63                     backlight_device_register(name, fbi->dev, mfd,
64                                               &msm_fb_bl_ops);
65                 if (!IS_ERR(pbd)) {
66                         fbi->bl_dev = pbd;
67                         fb_bl_default_curve(fbi,
68                                             0,
69                                             mfd->panel_info.bl_min,
70                                             mfd->panel_info.bl_max);
71                         pbd->props.max_brightness = FB_BACKLIGHT_LEVELS - 1;
72                         pbd->props.brightness = FB_BACKLIGHT_LEVELS - 1;
73                         backlight_update_status(pbd);
74                 } else {
75                         fbi->bl_dev = NULL;
76                         printk(KERN_ERR "msm_fb: backlight_device_register failed!\n");
77                 }
78         }
79 }