OMAPDSS: DPI: Maintain our own timings field in driver data
[linux-3.10.git] / drivers / video / omap2 / displays / panel-sharp-ls037v7dw01.c
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>
23 #include <linux/backlight.h>
24 #include <linux/fb.h>
25 #include <linux/err.h>
26 #include <linux/slab.h>
27
28 #include <video/omapdss.h>
29
30 struct sharp_data {
31         struct backlight_device *bl;
32 };
33
34 static 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         .vsync_level    = OMAPDSS_SIG_ACTIVE_LOW,
49         .hsync_level    = OMAPDSS_SIG_ACTIVE_LOW,
50         .data_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE,
51         .de_level       = OMAPDSS_SIG_ACTIVE_HIGH,
52         .sync_pclk_edge = OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES,
53 };
54
55 static int sharp_ls_bl_update_status(struct backlight_device *bl)
56 {
57         struct omap_dss_device *dssdev = dev_get_drvdata(&bl->dev);
58         int level;
59
60         if (!dssdev->set_backlight)
61                 return -EINVAL;
62
63         if (bl->props.fb_blank == FB_BLANK_UNBLANK &&
64                         bl->props.power == FB_BLANK_UNBLANK)
65                 level = bl->props.brightness;
66         else
67                 level = 0;
68
69         return dssdev->set_backlight(dssdev, level);
70 }
71
72 static int sharp_ls_bl_get_brightness(struct backlight_device *bl)
73 {
74         if (bl->props.fb_blank == FB_BLANK_UNBLANK &&
75                         bl->props.power == FB_BLANK_UNBLANK)
76                 return bl->props.brightness;
77
78         return 0;
79 }
80
81 static const struct backlight_ops sharp_ls_bl_ops = {
82         .get_brightness = sharp_ls_bl_get_brightness,
83         .update_status  = sharp_ls_bl_update_status,
84 };
85
86
87
88 static int sharp_ls_panel_probe(struct omap_dss_device *dssdev)
89 {
90         struct backlight_properties props;
91         struct backlight_device *bl;
92         struct sharp_data *sd;
93         int r;
94
95         dssdev->panel.timings = sharp_ls_timings;
96
97         sd = kzalloc(sizeof(*sd), GFP_KERNEL);
98         if (!sd)
99                 return -ENOMEM;
100
101         dev_set_drvdata(&dssdev->dev, sd);
102
103         memset(&props, 0, sizeof(struct backlight_properties));
104         props.max_brightness = dssdev->max_backlight_level;
105         props.type = BACKLIGHT_RAW;
106
107         bl = backlight_device_register("sharp-ls", &dssdev->dev, dssdev,
108                         &sharp_ls_bl_ops, &props);
109         if (IS_ERR(bl)) {
110                 r = PTR_ERR(bl);
111                 kfree(sd);
112                 return r;
113         }
114         sd->bl = bl;
115
116         bl->props.fb_blank = FB_BLANK_UNBLANK;
117         bl->props.power = FB_BLANK_UNBLANK;
118         bl->props.brightness = dssdev->max_backlight_level;
119         r = sharp_ls_bl_update_status(bl);
120         if (r < 0)
121                 dev_err(&dssdev->dev, "failed to set lcd brightness\n");
122
123         return 0;
124 }
125
126 static void __exit sharp_ls_panel_remove(struct omap_dss_device *dssdev)
127 {
128         struct sharp_data *sd = dev_get_drvdata(&dssdev->dev);
129         struct backlight_device *bl = sd->bl;
130
131         bl->props.power = FB_BLANK_POWERDOWN;
132         sharp_ls_bl_update_status(bl);
133         backlight_device_unregister(bl);
134
135         kfree(sd);
136 }
137
138 static int sharp_ls_power_on(struct omap_dss_device *dssdev)
139 {
140         int r = 0;
141
142         if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
143                 return 0;
144
145         omapdss_dpi_set_timings(dssdev, &dssdev->panel.timings);
146
147         r = omapdss_dpi_display_enable(dssdev);
148         if (r)
149                 goto err0;
150
151         /* wait couple of vsyncs until enabling the LCD */
152         msleep(50);
153
154         if (dssdev->platform_enable) {
155                 r = dssdev->platform_enable(dssdev);
156                 if (r)
157                         goto err1;
158         }
159
160         return 0;
161 err1:
162         omapdss_dpi_display_disable(dssdev);
163 err0:
164         return r;
165 }
166
167 static void sharp_ls_power_off(struct omap_dss_device *dssdev)
168 {
169         if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
170                 return;
171
172         if (dssdev->platform_disable)
173                 dssdev->platform_disable(dssdev);
174
175         /* wait at least 5 vsyncs after disabling the LCD */
176
177         msleep(100);
178
179         omapdss_dpi_display_disable(dssdev);
180 }
181
182 static int sharp_ls_panel_enable(struct omap_dss_device *dssdev)
183 {
184         int r;
185         r = sharp_ls_power_on(dssdev);
186         dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
187         return r;
188 }
189
190 static void sharp_ls_panel_disable(struct omap_dss_device *dssdev)
191 {
192         sharp_ls_power_off(dssdev);
193         dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
194 }
195
196 static int sharp_ls_panel_suspend(struct omap_dss_device *dssdev)
197 {
198         sharp_ls_power_off(dssdev);
199         dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
200         return 0;
201 }
202
203 static int sharp_ls_panel_resume(struct omap_dss_device *dssdev)
204 {
205         int r;
206         r = sharp_ls_power_on(dssdev);
207         dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
208         return r;
209 }
210
211 static struct omap_dss_driver sharp_ls_driver = {
212         .probe          = sharp_ls_panel_probe,
213         .remove         = __exit_p(sharp_ls_panel_remove),
214
215         .enable         = sharp_ls_panel_enable,
216         .disable        = sharp_ls_panel_disable,
217         .suspend        = sharp_ls_panel_suspend,
218         .resume         = sharp_ls_panel_resume,
219
220         .driver         = {
221                 .name   = "sharp_ls_panel",
222                 .owner  = THIS_MODULE,
223         },
224 };
225
226 static int __init sharp_ls_panel_drv_init(void)
227 {
228         return omap_dss_register_driver(&sharp_ls_driver);
229 }
230
231 static void __exit sharp_ls_panel_drv_exit(void)
232 {
233         omap_dss_unregister_driver(&sharp_ls_driver);
234 }
235
236 module_init(sharp_ls_panel_drv_init);
237 module_exit(sharp_ls_panel_drv_exit);
238 MODULE_LICENSE("GPL");