blob: 669a81fdf58ef3775c677030408ab264c26ef176 [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 Valkeinenbc24b8b2013-05-13 13:40:33 +030064 case OMAP_DISPLAY_TYPE_DVI:
Tomi Valkeineneed07e02009-08-07 13:43:20 +030065 return 24;
Tomi Valkeineneed07e02009-08-07 13:43:20 +030066 default:
67 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +030068 return 0;
Tomi Valkeineneed07e02009-08-07 13:43:20 +030069 }
70}
Tomi Valkeinena2699502010-01-11 14:33:40 +020071EXPORT_SYMBOL(omapdss_default_get_recommended_bpp);
Tomi Valkeineneed07e02009-08-07 13:43:20 +030072
Grazvydas Ignotas4b6430f2012-03-15 20:00:23 +020073void omapdss_default_get_timings(struct omap_dss_device *dssdev,
74 struct omap_video_timings *timings)
75{
76 *timings = dssdev->panel.timings;
77}
78EXPORT_SYMBOL(omapdss_default_get_timings);
79
Tomi Valkeineneed07e02009-08-07 13:43:20 +030080int dss_suspend_all_devices(void)
81{
Tomi Valkeinena65c8bd2012-11-16 15:45:26 +020082 struct omap_dss_device *dssdev = NULL;
Tomi Valkeineneed07e02009-08-07 13:43:20 +030083
Tomi Valkeinena65c8bd2012-11-16 15:45:26 +020084 for_each_dss_dev(dssdev) {
85 if (!dssdev->driver)
86 continue;
87
88 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
89 dssdev->driver->disable(dssdev);
90 dssdev->activate_after_resume = true;
91 } else {
92 dssdev->activate_after_resume = false;
93 }
Tomi Valkeineneed07e02009-08-07 13:43:20 +030094 }
95
96 return 0;
97}
98
Tomi Valkeineneed07e02009-08-07 13:43:20 +030099int dss_resume_all_devices(void)
100{
Tomi Valkeinena65c8bd2012-11-16 15:45:26 +0200101 struct omap_dss_device *dssdev = NULL;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300102
Tomi Valkeinena65c8bd2012-11-16 15:45:26 +0200103 for_each_dss_dev(dssdev) {
104 if (!dssdev->driver)
105 continue;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300106
Tomi Valkeinena65c8bd2012-11-16 15:45:26 +0200107 if (dssdev->activate_after_resume) {
108 dssdev->driver->enable(dssdev);
109 dssdev->activate_after_resume = false;
110 }
111 }
Jani Nikula279fcd42010-03-24 11:59:38 +0100112
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300113 return 0;
114}
115
116void dss_disable_all_devices(void)
117{
Tomi Valkeinena65c8bd2012-11-16 15:45:26 +0200118 struct omap_dss_device *dssdev = NULL;
119
120 for_each_dss_dev(dssdev) {
121 if (!dssdev->driver)
122 continue;
123
124 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
125 dssdev->driver->disable(dssdev);
126 }
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300127}
128
Tomi Valkeinen2e7e3dc2012-11-16 15:45:26 +0200129static LIST_HEAD(panel_list);
130static DEFINE_MUTEX(panel_list_mutex);
131static int disp_num_counter;
132
133int omapdss_register_display(struct omap_dss_device *dssdev)
134{
135 struct omap_dss_driver *drv = dssdev->driver;
136
137 snprintf(dssdev->alias, sizeof(dssdev->alias),
138 "display%d", disp_num_counter++);
139
140 if (drv && drv->get_resolution == NULL)
141 drv->get_resolution = omapdss_default_get_resolution;
142 if (drv && drv->get_recommended_bpp == NULL)
143 drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
144 if (drv && drv->get_timings == NULL)
145 drv->get_timings = omapdss_default_get_timings;
146
147 mutex_lock(&panel_list_mutex);
148 list_add_tail(&dssdev->panel_list, &panel_list);
149 mutex_unlock(&panel_list_mutex);
150 return 0;
151}
152EXPORT_SYMBOL(omapdss_register_display);
153
154void omapdss_unregister_display(struct omap_dss_device *dssdev)
155{
156 mutex_lock(&panel_list_mutex);
157 list_del(&dssdev->panel_list);
158 mutex_unlock(&panel_list_mutex);
159}
160EXPORT_SYMBOL(omapdss_unregister_display);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300161
Tomi Valkeinend35317a2013-05-03 11:40:54 +0300162struct omap_dss_device *omap_dss_get_device(struct omap_dss_device *dssdev)
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300163{
Tomi Valkeinend35317a2013-05-03 11:40:54 +0300164 if (!try_module_get(dssdev->owner))
165 return NULL;
166
167 if (get_device(dssdev->dev) == NULL) {
168 module_put(dssdev->owner);
169 return NULL;
170 }
171
172 return dssdev;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300173}
174EXPORT_SYMBOL(omap_dss_get_device);
175
176void omap_dss_put_device(struct omap_dss_device *dssdev)
177{
Tomi Valkeinenecc8b372013-02-14 14:17:28 +0200178 put_device(dssdev->dev);
Tomi Valkeinend35317a2013-05-03 11:40:54 +0300179 module_put(dssdev->owner);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300180}
181EXPORT_SYMBOL(omap_dss_put_device);
182
Tomi Valkeinen67b23ca2013-03-15 16:33:29 +0200183/*
184 * ref count of the found device is incremented.
185 * ref count of from-device is decremented.
186 */
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300187struct omap_dss_device *omap_dss_get_next_device(struct omap_dss_device *from)
188{
Tomi Valkeinen67b23ca2013-03-15 16:33:29 +0200189 struct list_head *l;
190 struct omap_dss_device *dssdev;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300191
Tomi Valkeinen67b23ca2013-03-15 16:33:29 +0200192 mutex_lock(&panel_list_mutex);
193
194 if (list_empty(&panel_list)) {
195 dssdev = NULL;
196 goto out;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300197 }
198
Tomi Valkeinen67b23ca2013-03-15 16:33:29 +0200199 if (from == NULL) {
200 dssdev = list_first_entry(&panel_list, struct omap_dss_device,
201 panel_list);
202 omap_dss_get_device(dssdev);
203 goto out;
204 }
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300205
Tomi Valkeinen67b23ca2013-03-15 16:33:29 +0200206 omap_dss_put_device(from);
207
208 list_for_each(l, &panel_list) {
209 dssdev = list_entry(l, struct omap_dss_device, panel_list);
210 if (dssdev == from) {
211 if (list_is_last(l, &panel_list)) {
212 dssdev = NULL;
213 goto out;
214 }
215
216 dssdev = list_entry(l->next, struct omap_dss_device,
217 panel_list);
218 omap_dss_get_device(dssdev);
219 goto out;
220 }
221 }
222
223 WARN(1, "'from' dssdev not found\n");
224
225 dssdev = NULL;
226out:
227 mutex_unlock(&panel_list_mutex);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300228 return dssdev;
229}
230EXPORT_SYMBOL(omap_dss_get_next_device);
231
232struct omap_dss_device *omap_dss_find_device(void *data,
233 int (*match)(struct omap_dss_device *dssdev, void *data))
234{
235 struct omap_dss_device *dssdev = NULL;
236
237 while ((dssdev = omap_dss_get_next_device(dssdev)) != NULL) {
238 if (match(dssdev, data))
239 return dssdev;
240 }
241
242 return NULL;
243}
244EXPORT_SYMBOL(omap_dss_find_device);
245
Tomi Valkeinen6fcd4852013-05-10 13:02:32 +0300246void videomode_to_omap_video_timings(const struct videomode *vm,
247 struct omap_video_timings *ovt)
248{
249 memset(ovt, 0, sizeof(*ovt));
250
251 ovt->pixel_clock = vm->pixelclock / 1000;
252 ovt->x_res = vm->hactive;
253 ovt->hbp = vm->hback_porch;
254 ovt->hfp = vm->hfront_porch;
255 ovt->hsw = vm->hsync_len;
256 ovt->y_res = vm->vactive;
257 ovt->vbp = vm->vback_porch;
258 ovt->vfp = vm->vfront_porch;
259 ovt->vsw = vm->vsync_len;
260
261 ovt->vsync_level = vm->flags & DISPLAY_FLAGS_VSYNC_HIGH ?
262 OMAPDSS_SIG_ACTIVE_HIGH :
263 OMAPDSS_SIG_ACTIVE_LOW;
264 ovt->hsync_level = vm->flags & DISPLAY_FLAGS_HSYNC_HIGH ?
265 OMAPDSS_SIG_ACTIVE_HIGH :
266 OMAPDSS_SIG_ACTIVE_LOW;
267 ovt->de_level = vm->flags & DISPLAY_FLAGS_DE_HIGH ?
268 OMAPDSS_SIG_ACTIVE_HIGH :
Roel Kluin9b842a42013-10-14 00:44:33 +0200269 OMAPDSS_SIG_ACTIVE_LOW;
Tomi Valkeinen6fcd4852013-05-10 13:02:32 +0300270 ovt->data_pclk_edge = vm->flags & DISPLAY_FLAGS_PIXDATA_POSEDGE ?
271 OMAPDSS_DRIVE_SIG_RISING_EDGE :
272 OMAPDSS_DRIVE_SIG_FALLING_EDGE;
273
274 ovt->sync_pclk_edge = OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES;
275}
276EXPORT_SYMBOL(videomode_to_omap_video_timings);
277
278void omap_video_timings_to_videomode(const struct omap_video_timings *ovt,
279 struct videomode *vm)
280{
281 memset(vm, 0, sizeof(*vm));
282
283 vm->pixelclock = ovt->pixel_clock * 1000;
284
285 vm->hactive = ovt->x_res;
286 vm->hback_porch = ovt->hbp;
287 vm->hfront_porch = ovt->hfp;
288 vm->hsync_len = ovt->hsw;
289 vm->vactive = ovt->y_res;
290 vm->vback_porch = ovt->vbp;
291 vm->vfront_porch = ovt->vfp;
292 vm->vsync_len = ovt->vsw;
293
294 if (ovt->hsync_level == OMAPDSS_SIG_ACTIVE_HIGH)
295 vm->flags |= DISPLAY_FLAGS_HSYNC_HIGH;
296 else
297 vm->flags |= DISPLAY_FLAGS_HSYNC_LOW;
298
299 if (ovt->vsync_level == OMAPDSS_SIG_ACTIVE_HIGH)
300 vm->flags |= DISPLAY_FLAGS_VSYNC_HIGH;
301 else
302 vm->flags |= DISPLAY_FLAGS_VSYNC_LOW;
303
304 if (ovt->de_level == OMAPDSS_SIG_ACTIVE_HIGH)
305 vm->flags |= DISPLAY_FLAGS_DE_HIGH;
306 else
307 vm->flags |= DISPLAY_FLAGS_DE_LOW;
308
309 if (ovt->data_pclk_edge == OMAPDSS_DRIVE_SIG_RISING_EDGE)
310 vm->flags |= DISPLAY_FLAGS_PIXDATA_POSEDGE;
311 else
312 vm->flags |= DISPLAY_FLAGS_PIXDATA_NEGEDGE;
313}
314EXPORT_SYMBOL(omap_video_timings_to_videomode);