blob: 79a3a5ac8f1cbf0ae49b662cf7af0ec6c83002eb [file] [log] [blame]
Mythri P K70be8322011-03-10 15:48:48 +05301/*
Mythri P Kd875f992011-09-08 19:06:27 +05302 * hdmi_panel.c
Mythri P K70be8322011-03-10 15:48:48 +05303 *
4 * HDMI library support functions for TI OMAP4 processors.
5 *
6 * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com/
7 * Authors: Mythri P k <mythripk@ti.com>
8 *
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.
12 *
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.
17 *
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/>.
20 */
21
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>
Tomi Valkeinena0b38cc2011-05-11 14:05:07 +030027#include <video/omapdss.h>
Mythri P K70be8322011-03-10 15:48:48 +053028
29#include "dss.h"
30
31static struct {
32 struct mutex hdmi_lock;
33} hdmi;
34
35
36static int hdmi_panel_probe(struct omap_dss_device *dssdev)
37{
38 DSSDBG("ENTER hdmi_panel_probe\n");
39
40 dssdev->panel.config = OMAP_DSS_LCD_TFT |
41 OMAP_DSS_LCD_IVS | OMAP_DSS_LCD_IHS;
42
Tomi Valkeinen2ea51fe2011-08-25 17:07:58 +030043 dssdev->panel.timings = (struct omap_video_timings){640, 480, 25175, 96, 16, 48, 2 , 11, 31};
Mythri P K70be8322011-03-10 15:48:48 +053044
45 DSSDBG("hdmi_panel_probe x_res= %d y_res = %d\n",
46 dssdev->panel.timings.x_res,
47 dssdev->panel.timings.y_res);
48 return 0;
49}
50
51static void hdmi_panel_remove(struct omap_dss_device *dssdev)
52{
53
54}
55
56static int hdmi_panel_enable(struct omap_dss_device *dssdev)
57{
58 int r = 0;
59 DSSDBG("ENTER hdmi_panel_enable\n");
60
61 mutex_lock(&hdmi.hdmi_lock);
62
63 if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
64 r = -EINVAL;
65 goto err;
66 }
67
68 r = omapdss_hdmi_display_enable(dssdev);
69 if (r) {
70 DSSERR("failed to power on\n");
71 goto err;
72 }
73
74 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
75
76err:
77 mutex_unlock(&hdmi.hdmi_lock);
78
79 return r;
80}
81
82static void hdmi_panel_disable(struct omap_dss_device *dssdev)
83{
84 mutex_lock(&hdmi.hdmi_lock);
85
86 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
87 omapdss_hdmi_display_disable(dssdev);
88
89 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
90
91 mutex_unlock(&hdmi.hdmi_lock);
92}
93
94static int hdmi_panel_suspend(struct omap_dss_device *dssdev)
95{
96 int r = 0;
97
98 mutex_lock(&hdmi.hdmi_lock);
99
100 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
101 r = -EINVAL;
102 goto err;
103 }
104
105 dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
106
107 omapdss_hdmi_display_disable(dssdev);
108
109err:
110 mutex_unlock(&hdmi.hdmi_lock);
111
112 return r;
113}
114
115static int hdmi_panel_resume(struct omap_dss_device *dssdev)
116{
117 int r = 0;
118
119 mutex_lock(&hdmi.hdmi_lock);
120
121 if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) {
122 r = -EINVAL;
123 goto err;
124 }
125
126 r = omapdss_hdmi_display_enable(dssdev);
127 if (r) {
128 DSSERR("failed to power on\n");
129 goto err;
130 }
131
132 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
133
134err:
135 mutex_unlock(&hdmi.hdmi_lock);
136
137 return r;
138}
139
140static void hdmi_get_timings(struct omap_dss_device *dssdev,
141 struct omap_video_timings *timings)
142{
143 mutex_lock(&hdmi.hdmi_lock);
144
145 *timings = dssdev->panel.timings;
146
147 mutex_unlock(&hdmi.hdmi_lock);
148}
149
150static void hdmi_set_timings(struct omap_dss_device *dssdev,
151 struct omap_video_timings *timings)
152{
153 DSSDBG("hdmi_set_timings\n");
154
155 mutex_lock(&hdmi.hdmi_lock);
156
157 dssdev->panel.timings = *timings;
Tomi Valkeinenfa70dc52011-08-22 14:57:33 +0300158 omapdss_hdmi_display_set_timing(dssdev);
Mythri P K70be8322011-03-10 15:48:48 +0530159
160 mutex_unlock(&hdmi.hdmi_lock);
161}
162
163static int hdmi_check_timings(struct omap_dss_device *dssdev,
164 struct omap_video_timings *timings)
165{
166 int r = 0;
167
168 DSSDBG("hdmi_check_timings\n");
169
170 mutex_lock(&hdmi.hdmi_lock);
171
172 r = omapdss_hdmi_display_check_timing(dssdev, timings);
173 if (r) {
174 DSSERR("Timing cannot be applied\n");
175 goto err;
176 }
177err:
178 mutex_unlock(&hdmi.hdmi_lock);
179 return r;
180}
181
Tomi Valkeinen47024562011-08-25 17:12:56 +0300182static int hdmi_read_edid(struct omap_dss_device *dssdev, u8 *buf, int len)
183{
184 int r;
185
186 mutex_lock(&hdmi.hdmi_lock);
187
188 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
189 r = omapdss_hdmi_display_enable(dssdev);
190 if (r)
191 goto err;
192 }
193
194 r = omapdss_hdmi_read_edid(buf, len);
195
196 if (dssdev->state == OMAP_DSS_DISPLAY_DISABLED ||
197 dssdev->state == OMAP_DSS_DISPLAY_SUSPENDED)
198 omapdss_hdmi_display_disable(dssdev);
199err:
200 mutex_unlock(&hdmi.hdmi_lock);
201
202 return r;
203}
204
Mythri P K70be8322011-03-10 15:48:48 +0530205static struct omap_dss_driver hdmi_driver = {
206 .probe = hdmi_panel_probe,
207 .remove = hdmi_panel_remove,
208 .enable = hdmi_panel_enable,
209 .disable = hdmi_panel_disable,
210 .suspend = hdmi_panel_suspend,
211 .resume = hdmi_panel_resume,
212 .get_timings = hdmi_get_timings,
213 .set_timings = hdmi_set_timings,
214 .check_timings = hdmi_check_timings,
Tomi Valkeinen47024562011-08-25 17:12:56 +0300215 .read_edid = hdmi_read_edid,
Mythri P K70be8322011-03-10 15:48:48 +0530216 .driver = {
217 .name = "hdmi_panel",
218 .owner = THIS_MODULE,
219 },
220};
221
222int hdmi_panel_init(void)
223{
224 mutex_init(&hdmi.hdmi_lock);
225
226 omap_dss_register_driver(&hdmi_driver);
227
228 return 0;
229}
230
231void hdmi_panel_exit(void)
232{
233 omap_dss_unregister_driver(&hdmi_driver);
234
235}