OMAP: DSS2: don't power off a panel twice
[linux-2.6-block.git] / drivers / video / omap2 / displays / panel-sharp-ls037v7dw01.c
CommitLineData
3b8f29b4
TV
1/*
2 * LCD panel driver for Sharp LS037V7DW01
3 *
4 * Copyright (C) 2008 Nokia Corporation
5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published by
9 * the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <linux/module.h>
21#include <linux/delay.h>
22#include <linux/device.h>
2b88c5bc
VH
23#include <linux/backlight.h>
24#include <linux/fb.h>
3b8f29b4 25#include <linux/err.h>
2b88c5bc 26#include <linux/slab.h>
3b8f29b4
TV
27
28#include <plat/display.h>
29
2b88c5bc
VH
30struct sharp_data {
31 struct backlight_device *bl;
32};
33
3b8f29b4
TV
34static struct omap_video_timings sharp_ls_timings = {
35 .x_res = 480,
36 .y_res = 640,
37
38 .pixel_clock = 19200,
39
40 .hsw = 2,
41 .hfp = 1,
42 .hbp = 28,
43
44 .vsw = 1,
45 .vfp = 1,
46 .vbp = 1,
47};
48
2b88c5bc
VH
49static int sharp_ls_bl_update_status(struct backlight_device *bl)
50{
51 struct omap_dss_device *dssdev = dev_get_drvdata(&bl->dev);
52 int level;
53
54 if (!dssdev->set_backlight)
55 return -EINVAL;
56
57 if (bl->props.fb_blank == FB_BLANK_UNBLANK &&
58 bl->props.power == FB_BLANK_UNBLANK)
59 level = bl->props.brightness;
60 else
61 level = 0;
62
63 return dssdev->set_backlight(dssdev, level);
64}
65
66static int sharp_ls_bl_get_brightness(struct backlight_device *bl)
67{
68 if (bl->props.fb_blank == FB_BLANK_UNBLANK &&
69 bl->props.power == FB_BLANK_UNBLANK)
70 return bl->props.brightness;
71
72 return 0;
73}
74
75static const struct backlight_ops sharp_ls_bl_ops = {
76 .get_brightness = sharp_ls_bl_get_brightness,
77 .update_status = sharp_ls_bl_update_status,
78};
79
80
81
3b8f29b4
TV
82static int sharp_ls_panel_probe(struct omap_dss_device *dssdev)
83{
2b88c5bc
VH
84 struct backlight_properties props;
85 struct backlight_device *bl;
86 struct sharp_data *sd;
87 int r;
88
3b8f29b4
TV
89 dssdev->panel.config = OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_IVS |
90 OMAP_DSS_LCD_IHS;
91 dssdev->panel.acb = 0x28;
92 dssdev->panel.timings = sharp_ls_timings;
93
2b88c5bc
VH
94 sd = kzalloc(sizeof(*sd), GFP_KERNEL);
95 if (!sd)
96 return -ENOMEM;
97
98 dev_set_drvdata(&dssdev->dev, sd);
99
100 memset(&props, 0, sizeof(struct backlight_properties));
101 props.max_brightness = dssdev->max_backlight_level;
102
103 bl = backlight_device_register("sharp-ls", &dssdev->dev, dssdev,
104 &sharp_ls_bl_ops, &props);
105 if (IS_ERR(bl)) {
106 r = PTR_ERR(bl);
107 kfree(sd);
108 return r;
109 }
110 sd->bl = bl;
111
112 bl->props.fb_blank = FB_BLANK_UNBLANK;
113 bl->props.power = FB_BLANK_UNBLANK;
114 bl->props.brightness = dssdev->max_backlight_level;
115 r = sharp_ls_bl_update_status(bl);
116 if (r < 0)
117 dev_err(&dssdev->dev, "failed to set lcd brightness\n");
118
3b8f29b4
TV
119 return 0;
120}
121
122static void sharp_ls_panel_remove(struct omap_dss_device *dssdev)
123{
2b88c5bc
VH
124 struct sharp_data *sd = dev_get_drvdata(&dssdev->dev);
125 struct backlight_device *bl = sd->bl;
126
127 bl->props.power = FB_BLANK_POWERDOWN;
128 sharp_ls_bl_update_status(bl);
129 backlight_device_unregister(bl);
130
131 kfree(sd);
3b8f29b4
TV
132}
133
37ac60e4 134static int sharp_ls_power_on(struct omap_dss_device *dssdev)
3b8f29b4 135{
3b8f29b4
TV
136 int r = 0;
137
18016e35
SM
138 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
139 return 0;
140
37ac60e4
TV
141 r = omapdss_dpi_display_enable(dssdev);
142 if (r)
143 goto err0;
144
3b8f29b4
TV
145 /* wait couple of vsyncs until enabling the LCD */
146 msleep(50);
147
37ac60e4 148 if (dssdev->platform_enable) {
3b8f29b4 149 r = dssdev->platform_enable(dssdev);
37ac60e4
TV
150 if (r)
151 goto err1;
152 }
3b8f29b4 153
37ac60e4
TV
154 return 0;
155err1:
156 omapdss_dpi_display_disable(dssdev);
157err0:
3b8f29b4
TV
158 return r;
159}
160
37ac60e4 161static void sharp_ls_power_off(struct omap_dss_device *dssdev)
3b8f29b4 162{
18016e35
SM
163 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
164 return;
165
3b8f29b4
TV
166 if (dssdev->platform_disable)
167 dssdev->platform_disable(dssdev);
168
3b8f29b4
TV
169 /* wait at least 5 vsyncs after disabling the LCD */
170
171 msleep(100);
37ac60e4
TV
172
173 omapdss_dpi_display_disable(dssdev);
174}
175
176static int sharp_ls_panel_enable(struct omap_dss_device *dssdev)
177{
178 int r;
179 r = sharp_ls_power_on(dssdev);
180 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
181 return r;
182}
183
184static void sharp_ls_panel_disable(struct omap_dss_device *dssdev)
185{
186 sharp_ls_power_off(dssdev);
187 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
3b8f29b4
TV
188}
189
190static int sharp_ls_panel_suspend(struct omap_dss_device *dssdev)
191{
37ac60e4
TV
192 sharp_ls_power_off(dssdev);
193 dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
3b8f29b4
TV
194 return 0;
195}
196
197static int sharp_ls_panel_resume(struct omap_dss_device *dssdev)
198{
37ac60e4
TV
199 int r;
200 r = sharp_ls_power_on(dssdev);
201 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
202 return r;
3b8f29b4
TV
203}
204
205static struct omap_dss_driver sharp_ls_driver = {
206 .probe = sharp_ls_panel_probe,
207 .remove = sharp_ls_panel_remove,
208
209 .enable = sharp_ls_panel_enable,
210 .disable = sharp_ls_panel_disable,
211 .suspend = sharp_ls_panel_suspend,
212 .resume = sharp_ls_panel_resume,
213
214 .driver = {
215 .name = "sharp_ls_panel",
216 .owner = THIS_MODULE,
217 },
218};
219
220static int __init sharp_ls_panel_drv_init(void)
221{
222 return omap_dss_register_driver(&sharp_ls_driver);
223}
224
225static void __exit sharp_ls_panel_drv_exit(void)
226{
227 omap_dss_unregister_driver(&sharp_ls_driver);
228}
229
230module_init(sharp_ls_panel_drv_init);
231module_exit(sharp_ls_panel_drv_exit);
232MODULE_LICENSE("GPL");