Merge tag 'v3.3.7' into 3.3/master
[zen-stable.git] / drivers / video / omap2 / dss / hdmi_panel.c
blob533d5dc634d256374a22b9a2da8a8eb0453f9a34
1 /*
2 * hdmi_panel.c
4 * HDMI library support functions for TI OMAP4 processors.
6 * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com/
7 * Authors: Mythri P k <mythripk@ti.com>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License version 2 as published by
11 * the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * more details.
18 * You should have received a copy of the GNU General Public License along with
19 * this program. If not, see <http://www.gnu.org/licenses/>.
22 #include <linux/kernel.h>
23 #include <linux/err.h>
24 #include <linux/io.h>
25 #include <linux/mutex.h>
26 #include <linux/module.h>
27 #include <video/omapdss.h>
28 #include <linux/slab.h>
30 #include "dss.h"
32 static struct {
33 struct mutex hdmi_lock;
34 } hdmi;
37 static int hdmi_panel_probe(struct omap_dss_device *dssdev)
39 DSSDBG("ENTER hdmi_panel_probe\n");
41 dssdev->panel.config = OMAP_DSS_LCD_TFT |
42 OMAP_DSS_LCD_IVS | OMAP_DSS_LCD_IHS;
44 dssdev->panel.timings = (struct omap_video_timings){640, 480, 25175, 96, 16, 48, 2 , 11, 31};
46 DSSDBG("hdmi_panel_probe x_res= %d y_res = %d\n",
47 dssdev->panel.timings.x_res,
48 dssdev->panel.timings.y_res);
49 return 0;
52 static void hdmi_panel_remove(struct omap_dss_device *dssdev)
57 static int hdmi_panel_enable(struct omap_dss_device *dssdev)
59 int r = 0;
60 DSSDBG("ENTER hdmi_panel_enable\n");
62 mutex_lock(&hdmi.hdmi_lock);
64 if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
65 r = -EINVAL;
66 goto err;
69 r = omapdss_hdmi_display_enable(dssdev);
70 if (r) {
71 DSSERR("failed to power on\n");
72 goto err;
75 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
77 err:
78 mutex_unlock(&hdmi.hdmi_lock);
80 return r;
83 static void hdmi_panel_disable(struct omap_dss_device *dssdev)
85 mutex_lock(&hdmi.hdmi_lock);
87 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
88 omapdss_hdmi_display_disable(dssdev);
90 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
92 mutex_unlock(&hdmi.hdmi_lock);
95 static int hdmi_panel_suspend(struct omap_dss_device *dssdev)
97 int r = 0;
99 mutex_lock(&hdmi.hdmi_lock);
101 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
102 r = -EINVAL;
103 goto err;
106 dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
108 omapdss_hdmi_display_disable(dssdev);
110 err:
111 mutex_unlock(&hdmi.hdmi_lock);
113 return r;
116 static int hdmi_panel_resume(struct omap_dss_device *dssdev)
118 int r = 0;
120 mutex_lock(&hdmi.hdmi_lock);
122 if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) {
123 r = -EINVAL;
124 goto err;
127 r = omapdss_hdmi_display_enable(dssdev);
128 if (r) {
129 DSSERR("failed to power on\n");
130 goto err;
133 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
135 err:
136 mutex_unlock(&hdmi.hdmi_lock);
138 return r;
141 static void hdmi_get_timings(struct omap_dss_device *dssdev,
142 struct omap_video_timings *timings)
144 mutex_lock(&hdmi.hdmi_lock);
146 *timings = dssdev->panel.timings;
148 mutex_unlock(&hdmi.hdmi_lock);
151 static void hdmi_set_timings(struct omap_dss_device *dssdev,
152 struct omap_video_timings *timings)
154 DSSDBG("hdmi_set_timings\n");
156 mutex_lock(&hdmi.hdmi_lock);
158 dssdev->panel.timings = *timings;
159 omapdss_hdmi_display_set_timing(dssdev);
161 mutex_unlock(&hdmi.hdmi_lock);
164 static int hdmi_check_timings(struct omap_dss_device *dssdev,
165 struct omap_video_timings *timings)
167 int r = 0;
169 DSSDBG("hdmi_check_timings\n");
171 mutex_lock(&hdmi.hdmi_lock);
173 r = omapdss_hdmi_display_check_timing(dssdev, timings);
175 mutex_unlock(&hdmi.hdmi_lock);
176 return r;
179 static int hdmi_read_edid(struct omap_dss_device *dssdev, u8 *buf, int len)
181 int r;
183 mutex_lock(&hdmi.hdmi_lock);
185 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
186 r = omapdss_hdmi_display_enable(dssdev);
187 if (r)
188 goto err;
191 r = omapdss_hdmi_read_edid(buf, len);
193 if (dssdev->state == OMAP_DSS_DISPLAY_DISABLED ||
194 dssdev->state == OMAP_DSS_DISPLAY_SUSPENDED)
195 omapdss_hdmi_display_disable(dssdev);
196 err:
197 mutex_unlock(&hdmi.hdmi_lock);
199 return r;
202 static bool hdmi_detect(struct omap_dss_device *dssdev)
204 int r;
206 mutex_lock(&hdmi.hdmi_lock);
208 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
209 r = omapdss_hdmi_display_enable(dssdev);
210 if (r)
211 goto err;
214 r = omapdss_hdmi_detect();
216 if (dssdev->state == OMAP_DSS_DISPLAY_DISABLED ||
217 dssdev->state == OMAP_DSS_DISPLAY_SUSPENDED)
218 omapdss_hdmi_display_disable(dssdev);
219 err:
220 mutex_unlock(&hdmi.hdmi_lock);
222 return r;
225 static struct omap_dss_driver hdmi_driver = {
226 .probe = hdmi_panel_probe,
227 .remove = hdmi_panel_remove,
228 .enable = hdmi_panel_enable,
229 .disable = hdmi_panel_disable,
230 .suspend = hdmi_panel_suspend,
231 .resume = hdmi_panel_resume,
232 .get_timings = hdmi_get_timings,
233 .set_timings = hdmi_set_timings,
234 .check_timings = hdmi_check_timings,
235 .read_edid = hdmi_read_edid,
236 .detect = hdmi_detect,
237 .driver = {
238 .name = "hdmi_panel",
239 .owner = THIS_MODULE,
243 int hdmi_panel_init(void)
245 mutex_init(&hdmi.hdmi_lock);
247 omap_dss_register_driver(&hdmi_driver);
249 return 0;
252 void hdmi_panel_exit(void)
254 omap_dss_unregister_driver(&hdmi_driver);