blob: 72ac058a56d3ca64617530db73c6ef88ffb9f00c [file] [log] [blame]
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001/*
2 * linux/drivers/video/omap2/dss/display.c
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
6 *
7 * Some code and ideas taken from drivers/video/omap/ driver
8 * by Imre Deak.
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published by
12 * the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
18 *
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23#define DSS_SUBSYS_NAME "DISPLAY"
24
25#include <linux/kernel.h>
26#include <linux/module.h>
27#include <linux/jiffies.h>
Tomi Valkeineneed07e02009-08-07 13:43:20 +030028#include <linux/platform_device.h>
29
Tomi Valkeinena0b38cc2011-05-11 14:05:07 +030030#include <video/omapdss.h>
Tomi Valkeineneed07e02009-08-07 13:43:20 +030031#include "dss.h"
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +030032#include "dss_features.h"
Tomi Valkeineneed07e02009-08-07 13:43:20 +030033
Tomi Valkeinen96adcec2010-01-11 13:54:33 +020034void omapdss_default_get_resolution(struct omap_dss_device *dssdev,
Tomi Valkeineneed07e02009-08-07 13:43:20 +030035 u16 *xres, u16 *yres)
36{
37 *xres = dssdev->panel.timings.x_res;
38 *yres = dssdev->panel.timings.y_res;
39}
Tomi Valkeinen96adcec2010-01-11 13:54:33 +020040EXPORT_SYMBOL(omapdss_default_get_resolution);
Tomi Valkeineneed07e02009-08-07 13:43:20 +030041
Tomi Valkeinena2699502010-01-11 14:33:40 +020042int omapdss_default_get_recommended_bpp(struct omap_dss_device *dssdev)
Tomi Valkeineneed07e02009-08-07 13:43:20 +030043{
Tomi Valkeineneed07e02009-08-07 13:43:20 +030044 switch (dssdev->type) {
45 case OMAP_DISPLAY_TYPE_DPI:
46 if (dssdev->phy.dpi.data_lines == 24)
47 return 24;
48 else
49 return 16;
50
51 case OMAP_DISPLAY_TYPE_DBI:
Tomi Valkeineneed07e02009-08-07 13:43:20 +030052 if (dssdev->ctrl.pixel_size == 24)
53 return 24;
54 else
55 return 16;
Archit Tanejaa3b3cc22011-09-08 18:42:16 +053056 case OMAP_DISPLAY_TYPE_DSI:
57 if (dsi_get_pixel_size(dssdev->panel.dsi_pix_fmt) > 16)
58 return 24;
59 else
60 return 16;
Tomi Valkeineneed07e02009-08-07 13:43:20 +030061 case OMAP_DISPLAY_TYPE_VENC:
62 case OMAP_DISPLAY_TYPE_SDI:
Mythri P Kb1196012011-03-08 17:15:54 +053063 case OMAP_DISPLAY_TYPE_HDMI:
Tomi Valkeineneed07e02009-08-07 13:43:20 +030064 return 24;
Tomi Valkeineneed07e02009-08-07 13:43:20 +030065 default:
66 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +030067 return 0;
Tomi Valkeineneed07e02009-08-07 13:43:20 +030068 }
69}
Tomi Valkeinena2699502010-01-11 14:33:40 +020070EXPORT_SYMBOL(omapdss_default_get_recommended_bpp);
Tomi Valkeineneed07e02009-08-07 13:43:20 +030071
Grazvydas Ignotas4b6430f2012-03-15 20:00:23 +020072void omapdss_default_get_timings(struct omap_dss_device *dssdev,
73 struct omap_video_timings *timings)
74{
75 *timings = dssdev->panel.timings;
76}
77EXPORT_SYMBOL(omapdss_default_get_timings);
78
Tomi Valkeineneed07e02009-08-07 13:43:20 +030079static int dss_suspend_device(struct device *dev, void *data)
80{
Tomi Valkeineneed07e02009-08-07 13:43:20 +030081 struct omap_dss_device *dssdev = to_dss_device(dev);
82
83 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
84 dssdev->activate_after_resume = false;
85 return 0;
86 }
87
Tomi Valkeinen998c3362012-05-30 13:26:00 +030088 dssdev->driver->disable(dssdev);
Tomi Valkeineneed07e02009-08-07 13:43:20 +030089
90 dssdev->activate_after_resume = true;
91
92 return 0;
93}
94
95int dss_suspend_all_devices(void)
96{
97 int r;
98 struct bus_type *bus = dss_get_bus();
99
100 r = bus_for_each_dev(bus, NULL, NULL, dss_suspend_device);
101 if (r) {
102 /* resume all displays that were suspended */
103 dss_resume_all_devices();
104 return r;
105 }
106
107 return 0;
108}
109
110static int dss_resume_device(struct device *dev, void *data)
111{
112 int r;
113 struct omap_dss_device *dssdev = to_dss_device(dev);
114
Tomi Valkeinen998c3362012-05-30 13:26:00 +0300115 if (dssdev->activate_after_resume) {
116 r = dssdev->driver->enable(dssdev);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300117 if (r)
118 return r;
119 }
120
121 dssdev->activate_after_resume = false;
122
123 return 0;
124}
125
126int dss_resume_all_devices(void)
127{
128 struct bus_type *bus = dss_get_bus();
129
130 return bus_for_each_dev(bus, NULL, NULL, dss_resume_device);
131}
132
133static int dss_disable_device(struct device *dev, void *data)
134{
135 struct omap_dss_device *dssdev = to_dss_device(dev);
Jani Nikula279fcd42010-03-24 11:59:38 +0100136
137 if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED)
138 dssdev->driver->disable(dssdev);
139
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300140 return 0;
141}
142
143void dss_disable_all_devices(void)
144{
145 struct bus_type *bus = dss_get_bus();
146 bus_for_each_dev(bus, NULL, NULL, dss_disable_device);
147}
148
149
150void omap_dss_get_device(struct omap_dss_device *dssdev)
151{
152 get_device(&dssdev->dev);
153}
154EXPORT_SYMBOL(omap_dss_get_device);
155
156void omap_dss_put_device(struct omap_dss_device *dssdev)
157{
158 put_device(&dssdev->dev);
159}
160EXPORT_SYMBOL(omap_dss_put_device);
161
162/* ref count of the found device is incremented. ref count
163 * of from-device is decremented. */
164struct omap_dss_device *omap_dss_get_next_device(struct omap_dss_device *from)
165{
166 struct device *dev;
167 struct device *dev_start = NULL;
168 struct omap_dss_device *dssdev = NULL;
169
170 int match(struct device *dev, void *data)
171 {
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300172 return 1;
173 }
174
175 if (from)
176 dev_start = &from->dev;
177 dev = bus_find_device(dss_get_bus(), dev_start, NULL, match);
178 if (dev)
179 dssdev = to_dss_device(dev);
180 if (from)
181 put_device(&from->dev);
182
183 return dssdev;
184}
185EXPORT_SYMBOL(omap_dss_get_next_device);
186
187struct omap_dss_device *omap_dss_find_device(void *data,
188 int (*match)(struct omap_dss_device *dssdev, void *data))
189{
190 struct omap_dss_device *dssdev = NULL;
191
192 while ((dssdev = omap_dss_get_next_device(dssdev)) != NULL) {
193 if (match(dssdev, data))
194 return dssdev;
195 }
196
197 return NULL;
198}
199EXPORT_SYMBOL(omap_dss_find_device);
200
201int omap_dss_start_device(struct omap_dss_device *dssdev)
202{
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300203 if (!dssdev->driver) {
204 DSSDBG("no driver\n");
Tomi Valkeinene020f9a2010-02-17 13:36:48 +0200205 return -ENODEV;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300206 }
207
208 if (!try_module_get(dssdev->dev.driver->owner)) {
Tomi Valkeinene020f9a2010-02-17 13:36:48 +0200209 return -ENODEV;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300210 }
211
212 return 0;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300213}
214EXPORT_SYMBOL(omap_dss_start_device);
215
216void omap_dss_stop_device(struct omap_dss_device *dssdev)
217{
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300218 module_put(dssdev->dev.driver->owner);
219}
220EXPORT_SYMBOL(omap_dss_stop_device);
221
Tomi Valkeinen6fcd4852013-05-10 13:02:32 +0300222void videomode_to_omap_video_timings(const struct videomode *vm,
223 struct omap_video_timings *ovt)
224{
225 memset(ovt, 0, sizeof(*ovt));
226
227 ovt->pixel_clock = vm->pixelclock / 1000;
228 ovt->x_res = vm->hactive;
229 ovt->hbp = vm->hback_porch;
230 ovt->hfp = vm->hfront_porch;
231 ovt->hsw = vm->hsync_len;
232 ovt->y_res = vm->vactive;
233 ovt->vbp = vm->vback_porch;
234 ovt->vfp = vm->vfront_porch;
235 ovt->vsw = vm->vsync_len;
236
237 ovt->vsync_level = vm->flags & DISPLAY_FLAGS_VSYNC_HIGH ?
238 OMAPDSS_SIG_ACTIVE_HIGH :
239 OMAPDSS_SIG_ACTIVE_LOW;
240 ovt->hsync_level = vm->flags & DISPLAY_FLAGS_HSYNC_HIGH ?
241 OMAPDSS_SIG_ACTIVE_HIGH :
242 OMAPDSS_SIG_ACTIVE_LOW;
243 ovt->de_level = vm->flags & DISPLAY_FLAGS_DE_HIGH ?
244 OMAPDSS_SIG_ACTIVE_HIGH :
245 OMAPDSS_SIG_ACTIVE_HIGH;
246 ovt->data_pclk_edge = vm->flags & DISPLAY_FLAGS_PIXDATA_POSEDGE ?
247 OMAPDSS_DRIVE_SIG_RISING_EDGE :
248 OMAPDSS_DRIVE_SIG_FALLING_EDGE;
249
250 ovt->sync_pclk_edge = OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES;
251}
252EXPORT_SYMBOL(videomode_to_omap_video_timings);
253
254void omap_video_timings_to_videomode(const struct omap_video_timings *ovt,
255 struct videomode *vm)
256{
257 memset(vm, 0, sizeof(*vm));
258
259 vm->pixelclock = ovt->pixel_clock * 1000;
260
261 vm->hactive = ovt->x_res;
262 vm->hback_porch = ovt->hbp;
263 vm->hfront_porch = ovt->hfp;
264 vm->hsync_len = ovt->hsw;
265 vm->vactive = ovt->y_res;
266 vm->vback_porch = ovt->vbp;
267 vm->vfront_porch = ovt->vfp;
268 vm->vsync_len = ovt->vsw;
269
270 if (ovt->hsync_level == OMAPDSS_SIG_ACTIVE_HIGH)
271 vm->flags |= DISPLAY_FLAGS_HSYNC_HIGH;
272 else
273 vm->flags |= DISPLAY_FLAGS_HSYNC_LOW;
274
275 if (ovt->vsync_level == OMAPDSS_SIG_ACTIVE_HIGH)
276 vm->flags |= DISPLAY_FLAGS_VSYNC_HIGH;
277 else
278 vm->flags |= DISPLAY_FLAGS_VSYNC_LOW;
279
280 if (ovt->de_level == OMAPDSS_SIG_ACTIVE_HIGH)
281 vm->flags |= DISPLAY_FLAGS_DE_HIGH;
282 else
283 vm->flags |= DISPLAY_FLAGS_DE_LOW;
284
285 if (ovt->data_pclk_edge == OMAPDSS_DRIVE_SIG_RISING_EDGE)
286 vm->flags |= DISPLAY_FLAGS_PIXDATA_POSEDGE;
287 else
288 vm->flags |= DISPLAY_FLAGS_PIXDATA_NEGEDGE;
289}
290EXPORT_SYMBOL(omap_video_timings_to_videomode);