blob: 2412a0dd0c1312baa732296e895d5d9f1a63eea6 [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>
Tomi Valkeinen7f2bcd02013-08-06 09:41:32 +030029#include <linux/of.h>
Tomi Valkeineneed07e02009-08-07 13:43:20 +030030
Tomi Valkeinena0b38cc2011-05-11 14:05:07 +030031#include <video/omapdss.h>
Tomi Valkeineneed07e02009-08-07 13:43:20 +030032#include "dss.h"
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +030033#include "dss_features.h"
Tomi Valkeineneed07e02009-08-07 13:43:20 +030034
Tomi Valkeinen96adcec2010-01-11 13:54:33 +020035void omapdss_default_get_resolution(struct omap_dss_device *dssdev,
Tomi Valkeineneed07e02009-08-07 13:43:20 +030036 u16 *xres, u16 *yres)
37{
38 *xres = dssdev->panel.timings.x_res;
39 *yres = dssdev->panel.timings.y_res;
40}
Tomi Valkeinen96adcec2010-01-11 13:54:33 +020041EXPORT_SYMBOL(omapdss_default_get_resolution);
Tomi Valkeineneed07e02009-08-07 13:43:20 +030042
Tomi Valkeinena2699502010-01-11 14:33:40 +020043int omapdss_default_get_recommended_bpp(struct omap_dss_device *dssdev)
Tomi Valkeineneed07e02009-08-07 13:43:20 +030044{
Tomi Valkeineneed07e02009-08-07 13:43:20 +030045 switch (dssdev->type) {
46 case OMAP_DISPLAY_TYPE_DPI:
47 if (dssdev->phy.dpi.data_lines == 24)
48 return 24;
49 else
50 return 16;
51
52 case OMAP_DISPLAY_TYPE_DBI:
Tomi Valkeineneed07e02009-08-07 13:43:20 +030053 if (dssdev->ctrl.pixel_size == 24)
54 return 24;
55 else
56 return 16;
Archit Tanejaa3b3cc22011-09-08 18:42:16 +053057 case OMAP_DISPLAY_TYPE_DSI:
58 if (dsi_get_pixel_size(dssdev->panel.dsi_pix_fmt) > 16)
59 return 24;
60 else
61 return 16;
Tomi Valkeineneed07e02009-08-07 13:43:20 +030062 case OMAP_DISPLAY_TYPE_VENC:
63 case OMAP_DISPLAY_TYPE_SDI:
Mythri P Kb1196012011-03-08 17:15:54 +053064 case OMAP_DISPLAY_TYPE_HDMI:
Tomi Valkeinenbc24b8b2013-05-13 13:40:33 +030065 case OMAP_DISPLAY_TYPE_DVI:
Tomi Valkeineneed07e02009-08-07 13:43:20 +030066 return 24;
Tomi Valkeineneed07e02009-08-07 13:43:20 +030067 default:
68 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +030069 return 0;
Tomi Valkeineneed07e02009-08-07 13:43:20 +030070 }
71}
Tomi Valkeinena2699502010-01-11 14:33:40 +020072EXPORT_SYMBOL(omapdss_default_get_recommended_bpp);
Tomi Valkeineneed07e02009-08-07 13:43:20 +030073
Grazvydas Ignotas4b6430f2012-03-15 20:00:23 +020074void omapdss_default_get_timings(struct omap_dss_device *dssdev,
75 struct omap_video_timings *timings)
76{
77 *timings = dssdev->panel.timings;
78}
79EXPORT_SYMBOL(omapdss_default_get_timings);
80
Tomi Valkeineneed07e02009-08-07 13:43:20 +030081int dss_suspend_all_devices(void)
82{
Tomi Valkeinena65c8bd2012-11-16 15:45:26 +020083 struct omap_dss_device *dssdev = NULL;
Tomi Valkeineneed07e02009-08-07 13:43:20 +030084
Tomi Valkeinena65c8bd2012-11-16 15:45:26 +020085 for_each_dss_dev(dssdev) {
86 if (!dssdev->driver)
87 continue;
88
89 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
90 dssdev->driver->disable(dssdev);
91 dssdev->activate_after_resume = true;
92 } else {
93 dssdev->activate_after_resume = false;
94 }
Tomi Valkeineneed07e02009-08-07 13:43:20 +030095 }
96
97 return 0;
98}
99
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300100int dss_resume_all_devices(void)
101{
Tomi Valkeinena65c8bd2012-11-16 15:45:26 +0200102 struct omap_dss_device *dssdev = NULL;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300103
Tomi Valkeinena65c8bd2012-11-16 15:45:26 +0200104 for_each_dss_dev(dssdev) {
105 if (!dssdev->driver)
106 continue;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300107
Tomi Valkeinena65c8bd2012-11-16 15:45:26 +0200108 if (dssdev->activate_after_resume) {
109 dssdev->driver->enable(dssdev);
110 dssdev->activate_after_resume = false;
111 }
112 }
Jani Nikula279fcd42010-03-24 11:59:38 +0100113
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300114 return 0;
115}
116
117void dss_disable_all_devices(void)
118{
Tomi Valkeinena65c8bd2012-11-16 15:45:26 +0200119 struct omap_dss_device *dssdev = NULL;
120
121 for_each_dss_dev(dssdev) {
122 if (!dssdev->driver)
123 continue;
124
125 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
126 dssdev->driver->disable(dssdev);
127 }
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300128}
129
Tomi Valkeinen2e7e3dc2012-11-16 15:45:26 +0200130static LIST_HEAD(panel_list);
131static DEFINE_MUTEX(panel_list_mutex);
132static int disp_num_counter;
133
134int omapdss_register_display(struct omap_dss_device *dssdev)
135{
136 struct omap_dss_driver *drv = dssdev->driver;
Tomi Valkeinen3e22b352013-08-06 09:50:22 +0300137 int id;
Tomi Valkeinen2e7e3dc2012-11-16 15:45:26 +0200138
Tomi Valkeinen3e22b352013-08-06 09:50:22 +0300139 /*
140 * Note: this presumes all the displays are either using DT or non-DT,
141 * which normally should be the case. This also presumes that all
142 * displays either have an DT alias, or none has.
143 */
144
145 if (dssdev->dev->of_node) {
146 id = of_alias_get_id(dssdev->dev->of_node, "display");
147
148 if (id < 0)
149 id = disp_num_counter++;
150 } else {
151 id = disp_num_counter++;
152 }
153
154 snprintf(dssdev->alias, sizeof(dssdev->alias), "display%d", id);
Tomi Valkeinen2e7e3dc2012-11-16 15:45:26 +0200155
Tomi Valkeinen7f2bcd02013-08-06 09:41:32 +0300156 /* Use 'label' property for name, if it exists */
157 if (dssdev->dev->of_node)
158 of_property_read_string(dssdev->dev->of_node, "label",
159 &dssdev->name);
160
161 if (dssdev->name == NULL)
162 dssdev->name = dssdev->alias;
Tomi Valkeinen2e7e3dc2012-11-16 15:45:26 +0200163
164 if (drv && drv->get_resolution == NULL)
165 drv->get_resolution = omapdss_default_get_resolution;
166 if (drv && drv->get_recommended_bpp == NULL)
167 drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
168 if (drv && drv->get_timings == NULL)
169 drv->get_timings = omapdss_default_get_timings;
170
171 mutex_lock(&panel_list_mutex);
172 list_add_tail(&dssdev->panel_list, &panel_list);
173 mutex_unlock(&panel_list_mutex);
174 return 0;
175}
176EXPORT_SYMBOL(omapdss_register_display);
177
178void omapdss_unregister_display(struct omap_dss_device *dssdev)
179{
180 mutex_lock(&panel_list_mutex);
181 list_del(&dssdev->panel_list);
182 mutex_unlock(&panel_list_mutex);
183}
184EXPORT_SYMBOL(omapdss_unregister_display);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300185
Tomi Valkeinend35317a2013-05-03 11:40:54 +0300186struct omap_dss_device *omap_dss_get_device(struct omap_dss_device *dssdev)
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300187{
Tomi Valkeinend35317a2013-05-03 11:40:54 +0300188 if (!try_module_get(dssdev->owner))
189 return NULL;
190
191 if (get_device(dssdev->dev) == NULL) {
192 module_put(dssdev->owner);
193 return NULL;
194 }
195
196 return dssdev;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300197}
198EXPORT_SYMBOL(omap_dss_get_device);
199
200void omap_dss_put_device(struct omap_dss_device *dssdev)
201{
Tomi Valkeinenecc8b372013-02-14 14:17:28 +0200202 put_device(dssdev->dev);
Tomi Valkeinend35317a2013-05-03 11:40:54 +0300203 module_put(dssdev->owner);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300204}
205EXPORT_SYMBOL(omap_dss_put_device);
206
Tomi Valkeinen67b23ca2013-03-15 16:33:29 +0200207/*
208 * ref count of the found device is incremented.
209 * ref count of from-device is decremented.
210 */
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300211struct omap_dss_device *omap_dss_get_next_device(struct omap_dss_device *from)
212{
Tomi Valkeinen67b23ca2013-03-15 16:33:29 +0200213 struct list_head *l;
214 struct omap_dss_device *dssdev;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300215
Tomi Valkeinen67b23ca2013-03-15 16:33:29 +0200216 mutex_lock(&panel_list_mutex);
217
218 if (list_empty(&panel_list)) {
219 dssdev = NULL;
220 goto out;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300221 }
222
Tomi Valkeinen67b23ca2013-03-15 16:33:29 +0200223 if (from == NULL) {
224 dssdev = list_first_entry(&panel_list, struct omap_dss_device,
225 panel_list);
226 omap_dss_get_device(dssdev);
227 goto out;
228 }
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300229
Tomi Valkeinen67b23ca2013-03-15 16:33:29 +0200230 omap_dss_put_device(from);
231
232 list_for_each(l, &panel_list) {
233 dssdev = list_entry(l, struct omap_dss_device, panel_list);
234 if (dssdev == from) {
235 if (list_is_last(l, &panel_list)) {
236 dssdev = NULL;
237 goto out;
238 }
239
240 dssdev = list_entry(l->next, struct omap_dss_device,
241 panel_list);
242 omap_dss_get_device(dssdev);
243 goto out;
244 }
245 }
246
247 WARN(1, "'from' dssdev not found\n");
248
249 dssdev = NULL;
250out:
251 mutex_unlock(&panel_list_mutex);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300252 return dssdev;
253}
254EXPORT_SYMBOL(omap_dss_get_next_device);
255
256struct omap_dss_device *omap_dss_find_device(void *data,
257 int (*match)(struct omap_dss_device *dssdev, void *data))
258{
259 struct omap_dss_device *dssdev = NULL;
260
261 while ((dssdev = omap_dss_get_next_device(dssdev)) != NULL) {
262 if (match(dssdev, data))
263 return dssdev;
264 }
265
266 return NULL;
267}
268EXPORT_SYMBOL(omap_dss_find_device);
269
Tomi Valkeinen6fcd4852013-05-10 13:02:32 +0300270void videomode_to_omap_video_timings(const struct videomode *vm,
271 struct omap_video_timings *ovt)
272{
273 memset(ovt, 0, sizeof(*ovt));
274
Tomi Valkeinend8d789412013-04-10 14:12:14 +0300275 ovt->pixelclock = vm->pixelclock;
Tomi Valkeinen6fcd4852013-05-10 13:02:32 +0300276 ovt->x_res = vm->hactive;
277 ovt->hbp = vm->hback_porch;
278 ovt->hfp = vm->hfront_porch;
279 ovt->hsw = vm->hsync_len;
280 ovt->y_res = vm->vactive;
281 ovt->vbp = vm->vback_porch;
282 ovt->vfp = vm->vfront_porch;
283 ovt->vsw = vm->vsync_len;
284
285 ovt->vsync_level = vm->flags & DISPLAY_FLAGS_VSYNC_HIGH ?
286 OMAPDSS_SIG_ACTIVE_HIGH :
287 OMAPDSS_SIG_ACTIVE_LOW;
288 ovt->hsync_level = vm->flags & DISPLAY_FLAGS_HSYNC_HIGH ?
289 OMAPDSS_SIG_ACTIVE_HIGH :
290 OMAPDSS_SIG_ACTIVE_LOW;
291 ovt->de_level = vm->flags & DISPLAY_FLAGS_DE_HIGH ?
292 OMAPDSS_SIG_ACTIVE_HIGH :
Roel Kluin9b842a42013-10-14 00:44:33 +0200293 OMAPDSS_SIG_ACTIVE_LOW;
Tomi Valkeinen6fcd4852013-05-10 13:02:32 +0300294 ovt->data_pclk_edge = vm->flags & DISPLAY_FLAGS_PIXDATA_POSEDGE ?
295 OMAPDSS_DRIVE_SIG_RISING_EDGE :
296 OMAPDSS_DRIVE_SIG_FALLING_EDGE;
297
298 ovt->sync_pclk_edge = OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES;
299}
300EXPORT_SYMBOL(videomode_to_omap_video_timings);
301
302void omap_video_timings_to_videomode(const struct omap_video_timings *ovt,
303 struct videomode *vm)
304{
305 memset(vm, 0, sizeof(*vm));
306
Tomi Valkeinend8d789412013-04-10 14:12:14 +0300307 vm->pixelclock = ovt->pixelclock;
Tomi Valkeinen6fcd4852013-05-10 13:02:32 +0300308
309 vm->hactive = ovt->x_res;
310 vm->hback_porch = ovt->hbp;
311 vm->hfront_porch = ovt->hfp;
312 vm->hsync_len = ovt->hsw;
313 vm->vactive = ovt->y_res;
314 vm->vback_porch = ovt->vbp;
315 vm->vfront_porch = ovt->vfp;
316 vm->vsync_len = ovt->vsw;
317
318 if (ovt->hsync_level == OMAPDSS_SIG_ACTIVE_HIGH)
319 vm->flags |= DISPLAY_FLAGS_HSYNC_HIGH;
320 else
321 vm->flags |= DISPLAY_FLAGS_HSYNC_LOW;
322
323 if (ovt->vsync_level == OMAPDSS_SIG_ACTIVE_HIGH)
324 vm->flags |= DISPLAY_FLAGS_VSYNC_HIGH;
325 else
326 vm->flags |= DISPLAY_FLAGS_VSYNC_LOW;
327
328 if (ovt->de_level == OMAPDSS_SIG_ACTIVE_HIGH)
329 vm->flags |= DISPLAY_FLAGS_DE_HIGH;
330 else
331 vm->flags |= DISPLAY_FLAGS_DE_LOW;
332
333 if (ovt->data_pclk_edge == OMAPDSS_DRIVE_SIG_RISING_EDGE)
334 vm->flags |= DISPLAY_FLAGS_PIXDATA_POSEDGE;
335 else
336 vm->flags |= DISPLAY_FLAGS_PIXDATA_NEGEDGE;
337}
338EXPORT_SYMBOL(omap_video_timings_to_videomode);