blob: ba83ec3bfc8c4f47a5dd40865787bc96df745e52 [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
Tomi Valkeinen2e7e3dc2012-11-16 15:45:26 +0200149static LIST_HEAD(panel_list);
150static DEFINE_MUTEX(panel_list_mutex);
151static int disp_num_counter;
152
153int omapdss_register_display(struct omap_dss_device *dssdev)
154{
155 struct omap_dss_driver *drv = dssdev->driver;
156
157 snprintf(dssdev->alias, sizeof(dssdev->alias),
158 "display%d", disp_num_counter++);
159
160 if (drv && drv->get_resolution == NULL)
161 drv->get_resolution = omapdss_default_get_resolution;
162 if (drv && drv->get_recommended_bpp == NULL)
163 drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
164 if (drv && drv->get_timings == NULL)
165 drv->get_timings = omapdss_default_get_timings;
166
167 mutex_lock(&panel_list_mutex);
168 list_add_tail(&dssdev->panel_list, &panel_list);
169 mutex_unlock(&panel_list_mutex);
170 return 0;
171}
172EXPORT_SYMBOL(omapdss_register_display);
173
174void omapdss_unregister_display(struct omap_dss_device *dssdev)
175{
176 mutex_lock(&panel_list_mutex);
177 list_del(&dssdev->panel_list);
178 mutex_unlock(&panel_list_mutex);
179}
180EXPORT_SYMBOL(omapdss_unregister_display);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300181
182void omap_dss_get_device(struct omap_dss_device *dssdev)
183{
184 get_device(&dssdev->dev);
185}
186EXPORT_SYMBOL(omap_dss_get_device);
187
188void omap_dss_put_device(struct omap_dss_device *dssdev)
189{
190 put_device(&dssdev->dev);
191}
192EXPORT_SYMBOL(omap_dss_put_device);
193
Tomi Valkeinen67b23ca2013-03-15 16:33:29 +0200194/*
195 * ref count of the found device is incremented.
196 * ref count of from-device is decremented.
197 */
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300198struct omap_dss_device *omap_dss_get_next_device(struct omap_dss_device *from)
199{
Tomi Valkeinen67b23ca2013-03-15 16:33:29 +0200200 struct list_head *l;
201 struct omap_dss_device *dssdev;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300202
Tomi Valkeinen67b23ca2013-03-15 16:33:29 +0200203 mutex_lock(&panel_list_mutex);
204
205 if (list_empty(&panel_list)) {
206 dssdev = NULL;
207 goto out;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300208 }
209
Tomi Valkeinen67b23ca2013-03-15 16:33:29 +0200210 if (from == NULL) {
211 dssdev = list_first_entry(&panel_list, struct omap_dss_device,
212 panel_list);
213 omap_dss_get_device(dssdev);
214 goto out;
215 }
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300216
Tomi Valkeinen67b23ca2013-03-15 16:33:29 +0200217 omap_dss_put_device(from);
218
219 list_for_each(l, &panel_list) {
220 dssdev = list_entry(l, struct omap_dss_device, panel_list);
221 if (dssdev == from) {
222 if (list_is_last(l, &panel_list)) {
223 dssdev = NULL;
224 goto out;
225 }
226
227 dssdev = list_entry(l->next, struct omap_dss_device,
228 panel_list);
229 omap_dss_get_device(dssdev);
230 goto out;
231 }
232 }
233
234 WARN(1, "'from' dssdev not found\n");
235
236 dssdev = NULL;
237out:
238 mutex_unlock(&panel_list_mutex);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300239 return dssdev;
240}
241EXPORT_SYMBOL(omap_dss_get_next_device);
242
243struct omap_dss_device *omap_dss_find_device(void *data,
244 int (*match)(struct omap_dss_device *dssdev, void *data))
245{
246 struct omap_dss_device *dssdev = NULL;
247
248 while ((dssdev = omap_dss_get_next_device(dssdev)) != NULL) {
249 if (match(dssdev, data))
250 return dssdev;
251 }
252
253 return NULL;
254}
255EXPORT_SYMBOL(omap_dss_find_device);
256
257int omap_dss_start_device(struct omap_dss_device *dssdev)
258{
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300259 if (!dssdev->driver) {
260 DSSDBG("no driver\n");
Tomi Valkeinene020f9a2010-02-17 13:36:48 +0200261 return -ENODEV;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300262 }
263
264 if (!try_module_get(dssdev->dev.driver->owner)) {
Tomi Valkeinene020f9a2010-02-17 13:36:48 +0200265 return -ENODEV;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300266 }
267
268 return 0;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300269}
270EXPORT_SYMBOL(omap_dss_start_device);
271
272void omap_dss_stop_device(struct omap_dss_device *dssdev)
273{
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300274 module_put(dssdev->dev.driver->owner);
275}
276EXPORT_SYMBOL(omap_dss_stop_device);
277
Tomi Valkeinen6fcd4852013-05-10 13:02:32 +0300278void videomode_to_omap_video_timings(const struct videomode *vm,
279 struct omap_video_timings *ovt)
280{
281 memset(ovt, 0, sizeof(*ovt));
282
283 ovt->pixel_clock = vm->pixelclock / 1000;
284 ovt->x_res = vm->hactive;
285 ovt->hbp = vm->hback_porch;
286 ovt->hfp = vm->hfront_porch;
287 ovt->hsw = vm->hsync_len;
288 ovt->y_res = vm->vactive;
289 ovt->vbp = vm->vback_porch;
290 ovt->vfp = vm->vfront_porch;
291 ovt->vsw = vm->vsync_len;
292
293 ovt->vsync_level = vm->flags & DISPLAY_FLAGS_VSYNC_HIGH ?
294 OMAPDSS_SIG_ACTIVE_HIGH :
295 OMAPDSS_SIG_ACTIVE_LOW;
296 ovt->hsync_level = vm->flags & DISPLAY_FLAGS_HSYNC_HIGH ?
297 OMAPDSS_SIG_ACTIVE_HIGH :
298 OMAPDSS_SIG_ACTIVE_LOW;
299 ovt->de_level = vm->flags & DISPLAY_FLAGS_DE_HIGH ?
300 OMAPDSS_SIG_ACTIVE_HIGH :
301 OMAPDSS_SIG_ACTIVE_HIGH;
302 ovt->data_pclk_edge = vm->flags & DISPLAY_FLAGS_PIXDATA_POSEDGE ?
303 OMAPDSS_DRIVE_SIG_RISING_EDGE :
304 OMAPDSS_DRIVE_SIG_FALLING_EDGE;
305
306 ovt->sync_pclk_edge = OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES;
307}
308EXPORT_SYMBOL(videomode_to_omap_video_timings);
309
310void omap_video_timings_to_videomode(const struct omap_video_timings *ovt,
311 struct videomode *vm)
312{
313 memset(vm, 0, sizeof(*vm));
314
315 vm->pixelclock = ovt->pixel_clock * 1000;
316
317 vm->hactive = ovt->x_res;
318 vm->hback_porch = ovt->hbp;
319 vm->hfront_porch = ovt->hfp;
320 vm->hsync_len = ovt->hsw;
321 vm->vactive = ovt->y_res;
322 vm->vback_porch = ovt->vbp;
323 vm->vfront_porch = ovt->vfp;
324 vm->vsync_len = ovt->vsw;
325
326 if (ovt->hsync_level == OMAPDSS_SIG_ACTIVE_HIGH)
327 vm->flags |= DISPLAY_FLAGS_HSYNC_HIGH;
328 else
329 vm->flags |= DISPLAY_FLAGS_HSYNC_LOW;
330
331 if (ovt->vsync_level == OMAPDSS_SIG_ACTIVE_HIGH)
332 vm->flags |= DISPLAY_FLAGS_VSYNC_HIGH;
333 else
334 vm->flags |= DISPLAY_FLAGS_VSYNC_LOW;
335
336 if (ovt->de_level == OMAPDSS_SIG_ACTIVE_HIGH)
337 vm->flags |= DISPLAY_FLAGS_DE_HIGH;
338 else
339 vm->flags |= DISPLAY_FLAGS_DE_LOW;
340
341 if (ovt->data_pclk_edge == OMAPDSS_DRIVE_SIG_RISING_EDGE)
342 vm->flags |= DISPLAY_FLAGS_PIXDATA_POSEDGE;
343 else
344 vm->flags |= DISPLAY_FLAGS_PIXDATA_NEGEDGE;
345}
346EXPORT_SYMBOL(omap_video_timings_to_videomode);