OMAP: DSS2: don't power off a panel twice
[linux-2.6-block.git] / drivers / video / omap2 / displays / panel-sharp-lq043t1dg01.c
1 /*
2  * LCD panel driver for Sharp LQ043T1DG01
3  *
4  * Copyright (C) 2009 Texas Instruments Inc
5  * Author: Vaibhav Hiremath <hvaibhav@ti.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/err.h>
24
25 #include <plat/display.h>
26
27 static struct omap_video_timings sharp_lq_timings = {
28         .x_res = 480,
29         .y_res = 272,
30
31         .pixel_clock    = 9000,
32
33         .hsw            = 42,
34         .hfp            = 3,
35         .hbp            = 2,
36
37         .vsw            = 11,
38         .vfp            = 3,
39         .vbp            = 2,
40 };
41
42 static int sharp_lq_panel_power_on(struct omap_dss_device *dssdev)
43 {
44         int r;
45
46         if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
47                 return 0;
48
49         r = omapdss_dpi_display_enable(dssdev);
50         if (r)
51                 goto err0;
52
53         /* wait couple of vsyncs until enabling the LCD */
54         msleep(50);
55
56         if (dssdev->platform_enable) {
57                 r = dssdev->platform_enable(dssdev);
58                 if (r)
59                         goto err1;
60         }
61
62         return 0;
63 err1:
64         omapdss_dpi_display_disable(dssdev);
65 err0:
66         return r;
67 }
68
69 static void sharp_lq_panel_power_off(struct omap_dss_device *dssdev)
70 {
71         if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
72                 return;
73
74         if (dssdev->platform_disable)
75                 dssdev->platform_disable(dssdev);
76
77         /* wait at least 5 vsyncs after disabling the LCD */
78         msleep(100);
79
80         omapdss_dpi_display_disable(dssdev);
81 }
82
83 static int sharp_lq_panel_probe(struct omap_dss_device *dssdev)
84 {
85
86         dssdev->panel.config = OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_IVS |
87                 OMAP_DSS_LCD_IHS | OMAP_DSS_LCD_IEO;
88         dssdev->panel.acb = 0x0;
89         dssdev->panel.timings = sharp_lq_timings;
90
91         return 0;
92 }
93
94 static void sharp_lq_panel_remove(struct omap_dss_device *dssdev)
95 {
96 }
97
98 static int sharp_lq_panel_enable(struct omap_dss_device *dssdev)
99 {
100         int r = 0;
101
102         r = sharp_lq_panel_power_on(dssdev);
103         if (r)
104                 return r;
105
106         dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
107
108         return 0;
109 }
110
111 static void sharp_lq_panel_disable(struct omap_dss_device *dssdev)
112 {
113         sharp_lq_panel_power_off(dssdev);
114
115         dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
116 }
117
118 static int sharp_lq_panel_suspend(struct omap_dss_device *dssdev)
119 {
120         sharp_lq_panel_power_off(dssdev);
121         dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
122         return 0;
123 }
124
125 static int sharp_lq_panel_resume(struct omap_dss_device *dssdev)
126 {
127         int r = 0;
128
129         r = sharp_lq_panel_power_on(dssdev);
130         if (r)
131                 return r;
132
133         dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
134
135         return 0;
136 }
137
138 static struct omap_dss_driver sharp_lq_driver = {
139         .probe          = sharp_lq_panel_probe,
140         .remove         = sharp_lq_panel_remove,
141
142         .enable         = sharp_lq_panel_enable,
143         .disable        = sharp_lq_panel_disable,
144         .suspend        = sharp_lq_panel_suspend,
145         .resume         = sharp_lq_panel_resume,
146
147         .driver         = {
148                 .name   = "sharp_lq_panel",
149                 .owner  = THIS_MODULE,
150         },
151 };
152
153 static int __init sharp_lq_panel_drv_init(void)
154 {
155         return omap_dss_register_driver(&sharp_lq_driver);
156 }
157
158 static void __exit sharp_lq_panel_drv_exit(void)
159 {
160         omap_dss_unregister_driver(&sharp_lq_driver);
161 }
162
163 module_init(sharp_lq_panel_drv_init);
164 module_exit(sharp_lq_panel_drv_exit);
165 MODULE_LICENSE("GPL");