OMAPDSS: Remove passive matrix LCD support (part 4)
[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
49 static 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
66 static 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
75 static 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
82 static int sharp_ls_panel_probe(struct omap_dss_device *dssdev)
83 {
84         struct backlight_properties props;
85         struct backlight_device *bl;
86         struct sharp_data *sd;
87         int r;
88
89         dssdev->panel.config = OMAP_DSS_LCD_IVS | OMAP_DSS_LCD_IHS;
90         dssdev->panel.timings = sharp_ls_timings;
91
92         sd = kzalloc(sizeof(*sd), GFP_KERNEL);
93         if (!sd)
94                 return -ENOMEM;
95
96         dev_set_drvdata(&dssdev->dev, sd);
97
98         memset(&props, 0, sizeof(struct backlight_properties));
99         props.max_brightness = dssdev->max_backlight_level;
100         props.type = BACKLIGHT_RAW;
101
102         bl = backlight_device_register("sharp-ls", &dssdev->dev, dssdev,
103                         &sharp_ls_bl_ops, &props);
104         if (IS_ERR(bl)) {
105                 r = PTR_ERR(bl);
106                 kfree(sd);
107                 return r;
108         }
109         sd->bl = bl;
110
111         bl->props.fb_blank = FB_BLANK_UNBLANK;
112         bl->props.power = FB_BLANK_UNBLANK;
113         bl->props.brightness = dssdev->max_backlight_level;
114         r = sharp_ls_bl_update_status(bl);
115         if (r < 0)
116                 dev_err(&dssdev->dev, "failed to set lcd brightness\n");
117
118         return 0;
119 }
120
121 static void __exit sharp_ls_panel_remove(struct omap_dss_device *dssdev)
122 {
123         struct sharp_data *sd = dev_get_drvdata(&dssdev->dev);
124         struct backlight_device *bl = sd->bl;
125
126         bl->props.power = FB_BLANK_POWERDOWN;
127         sharp_ls_bl_update_status(bl);
128         backlight_device_unregister(bl);
129
130         kfree(sd);
131 }
132
133 static int sharp_ls_power_on(struct omap_dss_device *dssdev)
134 {
135         int r = 0;
136
137         if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
138                 return 0;
139
140         r = omapdss_dpi_display_enable(dssdev);
141         if (r)
142                 goto err0;
143
144         /* wait couple of vsyncs until enabling the LCD */
145         msleep(50);
146
147         if (dssdev->platform_enable) {
148                 r = dssdev->platform_enable(dssdev);
149                 if (r)
150                         goto err1;
151         }
152
153         return 0;
154 err1:
155         omapdss_dpi_display_disable(dssdev);
156 err0:
157         return r;
158 }
159
160 static void sharp_ls_power_off(struct omap_dss_device *dssdev)
161 {
162         if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
163                 return;
164
165         if (dssdev->platform_disable)
166                 dssdev->platform_disable(dssdev);
167
168         /* wait at least 5 vsyncs after disabling the LCD */
169
170         msleep(100);
171
172         omapdss_dpi_display_disable(dssdev);
173 }
174
175 static int sharp_ls_panel_enable(struct omap_dss_device *dssdev)
176 {
177         int r;
178         r = sharp_ls_power_on(dssdev);
179         dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
180         return r;
181 }
182
183 static void sharp_ls_panel_disable(struct omap_dss_device *dssdev)
184 {
185         sharp_ls_power_off(dssdev);
186         dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
187 }
188
189 static int sharp_ls_panel_suspend(struct omap_dss_device *dssdev)
190 {
191         sharp_ls_power_off(dssdev);
192         dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
193         return 0;
194 }
195
196 static int sharp_ls_panel_resume(struct omap_dss_device *dssdev)
197 {
198         int r;
199         r = sharp_ls_power_on(dssdev);
200         dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
201         return r;
202 }
203
204 static struct omap_dss_driver sharp_ls_driver = {
205         .probe          = sharp_ls_panel_probe,
206         .remove         = __exit_p(sharp_ls_panel_remove),
207
208         .enable         = sharp_ls_panel_enable,
209         .disable        = sharp_ls_panel_disable,
210         .suspend        = sharp_ls_panel_suspend,
211         .resume         = sharp_ls_panel_resume,
212
213         .driver         = {
214                 .name   = "sharp_ls_panel",
215                 .owner  = THIS_MODULE,
216         },
217 };
218
219 static int __init sharp_ls_panel_drv_init(void)
220 {
221         return omap_dss_register_driver(&sharp_ls_driver);
222 }
223
224 static void __exit sharp_ls_panel_drv_exit(void)
225 {
226         omap_dss_unregister_driver(&sharp_ls_driver);
227 }
228
229 module_init(sharp_ls_panel_drv_init);
230 module_exit(sharp_ls_panel_drv_exit);
231 MODULE_LICENSE("GPL");