blob: c2dfc8c50057baad8be69900ba27f9a11434108b [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"
32
Tomi Valkeineneed07e02009-08-07 13:43:20 +030033static ssize_t display_enabled_show(struct device *dev,
34 struct device_attribute *attr, char *buf)
35{
36 struct omap_dss_device *dssdev = to_dss_device(dev);
37 bool enabled = dssdev->state != OMAP_DSS_DISPLAY_DISABLED;
38
39 return snprintf(buf, PAGE_SIZE, "%d\n", enabled);
40}
41
42static ssize_t display_enabled_store(struct device *dev,
43 struct device_attribute *attr,
44 const char *buf, size_t size)
45{
46 struct omap_dss_device *dssdev = to_dss_device(dev);
Tomi Valkeinene3502ce2011-04-04 15:40:23 +030047 int r, enabled;
Tomi Valkeineneed07e02009-08-07 13:43:20 +030048
Tomi Valkeinene3502ce2011-04-04 15:40:23 +030049 r = kstrtoint(buf, 0, &enabled);
50 if (r)
51 return r;
52
53 enabled = !!enabled;
Tomi Valkeineneed07e02009-08-07 13:43:20 +030054
55 if (enabled != (dssdev->state != OMAP_DSS_DISPLAY_DISABLED)) {
56 if (enabled) {
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +020057 r = dssdev->driver->enable(dssdev);
Tomi Valkeineneed07e02009-08-07 13:43:20 +030058 if (r)
59 return r;
60 } else {
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +020061 dssdev->driver->disable(dssdev);
Tomi Valkeineneed07e02009-08-07 13:43:20 +030062 }
63 }
64
65 return size;
66}
67
68static ssize_t display_upd_mode_show(struct device *dev,
69 struct device_attribute *attr, char *buf)
70{
71 struct omap_dss_device *dssdev = to_dss_device(dev);
72 enum omap_dss_update_mode mode = OMAP_DSS_UPDATE_AUTO;
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +020073 if (dssdev->driver->get_update_mode)
74 mode = dssdev->driver->get_update_mode(dssdev);
Tomi Valkeineneed07e02009-08-07 13:43:20 +030075 return snprintf(buf, PAGE_SIZE, "%d\n", mode);
76}
77
78static ssize_t display_upd_mode_store(struct device *dev,
79 struct device_attribute *attr,
80 const char *buf, size_t size)
81{
82 struct omap_dss_device *dssdev = to_dss_device(dev);
83 int val, r;
84 enum omap_dss_update_mode mode;
85
Ville Syrjälä825f50b2010-03-02 21:30:52 +020086 if (!dssdev->driver->set_update_mode)
87 return -EINVAL;
88
Tomi Valkeinene3502ce2011-04-04 15:40:23 +030089 r = kstrtoint(buf, 0, &val);
90 if (r)
91 return r;
Tomi Valkeineneed07e02009-08-07 13:43:20 +030092
93 switch (val) {
94 case OMAP_DSS_UPDATE_DISABLED:
95 case OMAP_DSS_UPDATE_AUTO:
96 case OMAP_DSS_UPDATE_MANUAL:
97 mode = (enum omap_dss_update_mode)val;
98 break;
99 default:
100 return -EINVAL;
101 }
102
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +0200103 r = dssdev->driver->set_update_mode(dssdev, mode);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300104 if (r)
105 return r;
106
107 return size;
108}
109
110static ssize_t display_tear_show(struct device *dev,
111 struct device_attribute *attr, char *buf)
112{
113 struct omap_dss_device *dssdev = to_dss_device(dev);
114 return snprintf(buf, PAGE_SIZE, "%d\n",
Tomi Valkeinen225b6502010-01-11 15:11:01 +0200115 dssdev->driver->get_te ?
116 dssdev->driver->get_te(dssdev) : 0);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300117}
118
119static ssize_t display_tear_store(struct device *dev,
120 struct device_attribute *attr, const char *buf, size_t size)
121{
122 struct omap_dss_device *dssdev = to_dss_device(dev);
Tomi Valkeinene3502ce2011-04-04 15:40:23 +0300123 int te, r;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300124
Tomi Valkeinen225b6502010-01-11 15:11:01 +0200125 if (!dssdev->driver->enable_te || !dssdev->driver->get_te)
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300126 return -ENOENT;
127
Tomi Valkeinene3502ce2011-04-04 15:40:23 +0300128 r = kstrtoint(buf, 0, &te);
129 if (r)
130 return r;
131
132 te = !!te;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300133
Tomi Valkeinen225b6502010-01-11 15:11:01 +0200134 r = dssdev->driver->enable_te(dssdev, te);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300135 if (r)
136 return r;
137
138 return size;
139}
140
141static ssize_t display_timings_show(struct device *dev,
142 struct device_attribute *attr, char *buf)
143{
144 struct omap_dss_device *dssdev = to_dss_device(dev);
145 struct omap_video_timings t;
146
Tomi Valkeinen69b20482010-01-20 12:11:25 +0200147 if (!dssdev->driver->get_timings)
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300148 return -ENOENT;
149
Tomi Valkeinen69b20482010-01-20 12:11:25 +0200150 dssdev->driver->get_timings(dssdev, &t);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300151
152 return snprintf(buf, PAGE_SIZE, "%u,%u/%u/%u/%u,%u/%u/%u/%u\n",
153 t.pixel_clock,
154 t.x_res, t.hfp, t.hbp, t.hsw,
155 t.y_res, t.vfp, t.vbp, t.vsw);
156}
157
158static ssize_t display_timings_store(struct device *dev,
159 struct device_attribute *attr, const char *buf, size_t size)
160{
161 struct omap_dss_device *dssdev = to_dss_device(dev);
162 struct omap_video_timings t;
163 int r, found;
164
Tomi Valkeinen69b20482010-01-20 12:11:25 +0200165 if (!dssdev->driver->set_timings || !dssdev->driver->check_timings)
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300166 return -ENOENT;
167
168 found = 0;
169#ifdef CONFIG_OMAP2_DSS_VENC
170 if (strncmp("pal", buf, 3) == 0) {
171 t = omap_dss_pal_timings;
172 found = 1;
173 } else if (strncmp("ntsc", buf, 4) == 0) {
174 t = omap_dss_ntsc_timings;
175 found = 1;
176 }
177#endif
178 if (!found && sscanf(buf, "%u,%hu/%hu/%hu/%hu,%hu/%hu/%hu/%hu",
179 &t.pixel_clock,
180 &t.x_res, &t.hfp, &t.hbp, &t.hsw,
181 &t.y_res, &t.vfp, &t.vbp, &t.vsw) != 9)
182 return -EINVAL;
183
Tomi Valkeinen69b20482010-01-20 12:11:25 +0200184 r = dssdev->driver->check_timings(dssdev, &t);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300185 if (r)
186 return r;
187
Tomi Valkeinen69b20482010-01-20 12:11:25 +0200188 dssdev->driver->set_timings(dssdev, &t);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300189
190 return size;
191}
192
193static ssize_t display_rotate_show(struct device *dev,
194 struct device_attribute *attr, char *buf)
195{
196 struct omap_dss_device *dssdev = to_dss_device(dev);
197 int rotate;
Tomi Valkeinen87424e12010-01-08 16:52:48 +0200198 if (!dssdev->driver->get_rotate)
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300199 return -ENOENT;
Tomi Valkeinen87424e12010-01-08 16:52:48 +0200200 rotate = dssdev->driver->get_rotate(dssdev);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300201 return snprintf(buf, PAGE_SIZE, "%u\n", rotate);
202}
203
204static ssize_t display_rotate_store(struct device *dev,
205 struct device_attribute *attr, const char *buf, size_t size)
206{
207 struct omap_dss_device *dssdev = to_dss_device(dev);
Tomi Valkeinene3502ce2011-04-04 15:40:23 +0300208 int rot, r;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300209
Tomi Valkeinen87424e12010-01-08 16:52:48 +0200210 if (!dssdev->driver->set_rotate || !dssdev->driver->get_rotate)
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300211 return -ENOENT;
212
Tomi Valkeinene3502ce2011-04-04 15:40:23 +0300213 r = kstrtoint(buf, 0, &rot);
214 if (r)
215 return r;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300216
Tomi Valkeinen87424e12010-01-08 16:52:48 +0200217 r = dssdev->driver->set_rotate(dssdev, rot);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300218 if (r)
219 return r;
220
221 return size;
222}
223
224static ssize_t display_mirror_show(struct device *dev,
225 struct device_attribute *attr, char *buf)
226{
227 struct omap_dss_device *dssdev = to_dss_device(dev);
228 int mirror;
Tomi Valkeinen8d8aa612010-01-08 16:30:33 +0200229 if (!dssdev->driver->get_mirror)
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300230 return -ENOENT;
Tomi Valkeinen8d8aa612010-01-08 16:30:33 +0200231 mirror = dssdev->driver->get_mirror(dssdev);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300232 return snprintf(buf, PAGE_SIZE, "%u\n", mirror);
233}
234
235static ssize_t display_mirror_store(struct device *dev,
236 struct device_attribute *attr, const char *buf, size_t size)
237{
238 struct omap_dss_device *dssdev = to_dss_device(dev);
Tomi Valkeinene3502ce2011-04-04 15:40:23 +0300239 int mirror, r;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300240
Tomi Valkeinen8d8aa612010-01-08 16:30:33 +0200241 if (!dssdev->driver->set_mirror || !dssdev->driver->get_mirror)
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300242 return -ENOENT;
243
Tomi Valkeinene3502ce2011-04-04 15:40:23 +0300244 r = kstrtoint(buf, 0, &mirror);
245 if (r)
246 return r;
247
248 mirror = !!mirror;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300249
Tomi Valkeinen8d8aa612010-01-08 16:30:33 +0200250 r = dssdev->driver->set_mirror(dssdev, mirror);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300251 if (r)
252 return r;
253
254 return size;
255}
256
257static ssize_t display_wss_show(struct device *dev,
258 struct device_attribute *attr, char *buf)
259{
260 struct omap_dss_device *dssdev = to_dss_device(dev);
261 unsigned int wss;
262
Tomi Valkeinen36511312010-01-19 15:53:16 +0200263 if (!dssdev->driver->get_wss)
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300264 return -ENOENT;
265
Tomi Valkeinen36511312010-01-19 15:53:16 +0200266 wss = dssdev->driver->get_wss(dssdev);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300267
268 return snprintf(buf, PAGE_SIZE, "0x%05x\n", wss);
269}
270
271static ssize_t display_wss_store(struct device *dev,
272 struct device_attribute *attr, const char *buf, size_t size)
273{
274 struct omap_dss_device *dssdev = to_dss_device(dev);
Tomi Valkeinene3502ce2011-04-04 15:40:23 +0300275 u32 wss;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300276 int r;
277
Tomi Valkeinen36511312010-01-19 15:53:16 +0200278 if (!dssdev->driver->get_wss || !dssdev->driver->set_wss)
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300279 return -ENOENT;
280
Tomi Valkeinene3502ce2011-04-04 15:40:23 +0300281 r = kstrtou32(buf, 0, &wss);
282 if (r)
283 return r;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300284
285 if (wss > 0xfffff)
286 return -EINVAL;
287
Tomi Valkeinen36511312010-01-19 15:53:16 +0200288 r = dssdev->driver->set_wss(dssdev, wss);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300289 if (r)
290 return r;
291
292 return size;
293}
294
295static DEVICE_ATTR(enabled, S_IRUGO|S_IWUSR,
296 display_enabled_show, display_enabled_store);
297static DEVICE_ATTR(update_mode, S_IRUGO|S_IWUSR,
298 display_upd_mode_show, display_upd_mode_store);
299static DEVICE_ATTR(tear_elim, S_IRUGO|S_IWUSR,
300 display_tear_show, display_tear_store);
301static DEVICE_ATTR(timings, S_IRUGO|S_IWUSR,
302 display_timings_show, display_timings_store);
303static DEVICE_ATTR(rotate, S_IRUGO|S_IWUSR,
304 display_rotate_show, display_rotate_store);
305static DEVICE_ATTR(mirror, S_IRUGO|S_IWUSR,
306 display_mirror_show, display_mirror_store);
307static DEVICE_ATTR(wss, S_IRUGO|S_IWUSR,
308 display_wss_show, display_wss_store);
309
310static struct device_attribute *display_sysfs_attrs[] = {
311 &dev_attr_enabled,
312 &dev_attr_update_mode,
313 &dev_attr_tear_elim,
314 &dev_attr_timings,
315 &dev_attr_rotate,
316 &dev_attr_mirror,
317 &dev_attr_wss,
318 NULL
319};
320
Tomi Valkeinen96adcec2010-01-11 13:54:33 +0200321void omapdss_default_get_resolution(struct omap_dss_device *dssdev,
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300322 u16 *xres, u16 *yres)
323{
324 *xres = dssdev->panel.timings.x_res;
325 *yres = dssdev->panel.timings.y_res;
326}
Tomi Valkeinen96adcec2010-01-11 13:54:33 +0200327EXPORT_SYMBOL(omapdss_default_get_resolution);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300328
329void default_get_overlay_fifo_thresholds(enum omap_plane plane,
330 u32 fifo_size, enum omap_burst_size *burst_size,
331 u32 *fifo_low, u32 *fifo_high)
332{
333 unsigned burst_size_bytes;
334
335 *burst_size = OMAP_DSS_BURST_16x32;
336 burst_size_bytes = 16 * 32 / 8;
337
338 *fifo_high = fifo_size - 1;
339 *fifo_low = fifo_size - burst_size_bytes;
340}
341
Tomi Valkeinena2699502010-01-11 14:33:40 +0200342int omapdss_default_get_recommended_bpp(struct omap_dss_device *dssdev)
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300343{
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300344 switch (dssdev->type) {
345 case OMAP_DISPLAY_TYPE_DPI:
346 if (dssdev->phy.dpi.data_lines == 24)
347 return 24;
348 else
349 return 16;
350
351 case OMAP_DISPLAY_TYPE_DBI:
352 case OMAP_DISPLAY_TYPE_DSI:
353 if (dssdev->ctrl.pixel_size == 24)
354 return 24;
355 else
356 return 16;
357 case OMAP_DISPLAY_TYPE_VENC:
358 case OMAP_DISPLAY_TYPE_SDI:
Mythri P Kb1196012011-03-08 17:15:54 +0530359 case OMAP_DISPLAY_TYPE_HDMI:
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300360 return 24;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300361 default:
362 BUG();
363 }
364}
Tomi Valkeinena2699502010-01-11 14:33:40 +0200365EXPORT_SYMBOL(omapdss_default_get_recommended_bpp);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300366
367/* Checks if replication logic should be used. Only use for active matrix,
368 * when overlay is in RGB12U or RGB16 mode, and LCD interface is
369 * 18bpp or 24bpp */
370bool dss_use_replication(struct omap_dss_device *dssdev,
371 enum omap_color_mode mode)
372{
373 int bpp;
374
375 if (mode != OMAP_DSS_COLOR_RGB12U && mode != OMAP_DSS_COLOR_RGB16)
376 return false;
377
378 if (dssdev->type == OMAP_DISPLAY_TYPE_DPI &&
379 (dssdev->panel.config & OMAP_DSS_LCD_TFT) == 0)
380 return false;
381
382 switch (dssdev->type) {
383 case OMAP_DISPLAY_TYPE_DPI:
384 bpp = dssdev->phy.dpi.data_lines;
385 break;
Mythri P Kb1196012011-03-08 17:15:54 +0530386 case OMAP_DISPLAY_TYPE_HDMI:
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300387 case OMAP_DISPLAY_TYPE_VENC:
388 case OMAP_DISPLAY_TYPE_SDI:
389 bpp = 24;
390 break;
391 case OMAP_DISPLAY_TYPE_DBI:
392 case OMAP_DISPLAY_TYPE_DSI:
393 bpp = dssdev->ctrl.pixel_size;
394 break;
395 default:
396 BUG();
397 }
398
399 return bpp > 16;
400}
401
402void dss_init_device(struct platform_device *pdev,
403 struct omap_dss_device *dssdev)
404{
405 struct device_attribute *attr;
406 int i;
407 int r;
408
409 switch (dssdev->type) {
Roger Quadrosb4d78bf2010-03-17 13:35:19 +0100410#ifdef CONFIG_OMAP2_DSS_DPI
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300411 case OMAP_DISPLAY_TYPE_DPI:
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300412 r = dpi_init_display(dssdev);
413 break;
Roger Quadrosb4d78bf2010-03-17 13:35:19 +0100414#endif
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300415#ifdef CONFIG_OMAP2_DSS_RFBI
416 case OMAP_DISPLAY_TYPE_DBI:
417 r = rfbi_init_display(dssdev);
418 break;
419#endif
420#ifdef CONFIG_OMAP2_DSS_VENC
421 case OMAP_DISPLAY_TYPE_VENC:
422 r = venc_init_display(dssdev);
423 break;
424#endif
425#ifdef CONFIG_OMAP2_DSS_SDI
426 case OMAP_DISPLAY_TYPE_SDI:
427 r = sdi_init_display(dssdev);
428 break;
429#endif
430#ifdef CONFIG_OMAP2_DSS_DSI
431 case OMAP_DISPLAY_TYPE_DSI:
432 r = dsi_init_display(dssdev);
433 break;
434#endif
Mythri P Kc3198a52011-03-12 12:04:27 +0530435 case OMAP_DISPLAY_TYPE_HDMI:
436 r = hdmi_init_display(dssdev);
437 break;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300438 default:
Tomi Valkeinene528e3a2011-02-24 13:59:13 +0200439 DSSERR("Support for display '%s' not compiled in.\n",
440 dssdev->name);
441 return;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300442 }
443
444 if (r) {
445 DSSERR("failed to init display %s\n", dssdev->name);
446 return;
447 }
448
449 /* create device sysfs files */
450 i = 0;
451 while ((attr = display_sysfs_attrs[i++]) != NULL) {
452 r = device_create_file(&dssdev->dev, attr);
453 if (r)
454 DSSERR("failed to create sysfs file\n");
455 }
456
457 /* create display? sysfs links */
458 r = sysfs_create_link(&pdev->dev.kobj, &dssdev->dev.kobj,
459 dev_name(&dssdev->dev));
460 if (r)
461 DSSERR("failed to create sysfs display link\n");
462}
463
464void dss_uninit_device(struct platform_device *pdev,
465 struct omap_dss_device *dssdev)
466{
467 struct device_attribute *attr;
468 int i = 0;
469
470 sysfs_remove_link(&pdev->dev.kobj, dev_name(&dssdev->dev));
471
472 while ((attr = display_sysfs_attrs[i++]) != NULL)
473 device_remove_file(&dssdev->dev, attr);
474
475 if (dssdev->manager)
476 dssdev->manager->unset_device(dssdev->manager);
477}
478
479static int dss_suspend_device(struct device *dev, void *data)
480{
481 int r;
482 struct omap_dss_device *dssdev = to_dss_device(dev);
483
484 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
485 dssdev->activate_after_resume = false;
486 return 0;
487 }
488
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200489 if (!dssdev->driver->suspend) {
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300490 DSSERR("display '%s' doesn't implement suspend\n",
491 dssdev->name);
492 return -ENOSYS;
493 }
494
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200495 r = dssdev->driver->suspend(dssdev);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300496 if (r)
497 return r;
498
499 dssdev->activate_after_resume = true;
500
501 return 0;
502}
503
504int dss_suspend_all_devices(void)
505{
506 int r;
507 struct bus_type *bus = dss_get_bus();
508
509 r = bus_for_each_dev(bus, NULL, NULL, dss_suspend_device);
510 if (r) {
511 /* resume all displays that were suspended */
512 dss_resume_all_devices();
513 return r;
514 }
515
516 return 0;
517}
518
519static int dss_resume_device(struct device *dev, void *data)
520{
521 int r;
522 struct omap_dss_device *dssdev = to_dss_device(dev);
523
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200524 if (dssdev->activate_after_resume && dssdev->driver->resume) {
525 r = dssdev->driver->resume(dssdev);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300526 if (r)
527 return r;
528 }
529
530 dssdev->activate_after_resume = false;
531
532 return 0;
533}
534
535int dss_resume_all_devices(void)
536{
537 struct bus_type *bus = dss_get_bus();
538
539 return bus_for_each_dev(bus, NULL, NULL, dss_resume_device);
540}
541
542static int dss_disable_device(struct device *dev, void *data)
543{
544 struct omap_dss_device *dssdev = to_dss_device(dev);
Jani Nikula279fcd42010-03-24 11:59:38 +0100545
546 if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED)
547 dssdev->driver->disable(dssdev);
548
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300549 return 0;
550}
551
552void dss_disable_all_devices(void)
553{
554 struct bus_type *bus = dss_get_bus();
555 bus_for_each_dev(bus, NULL, NULL, dss_disable_device);
556}
557
558
559void omap_dss_get_device(struct omap_dss_device *dssdev)
560{
561 get_device(&dssdev->dev);
562}
563EXPORT_SYMBOL(omap_dss_get_device);
564
565void omap_dss_put_device(struct omap_dss_device *dssdev)
566{
567 put_device(&dssdev->dev);
568}
569EXPORT_SYMBOL(omap_dss_put_device);
570
571/* ref count of the found device is incremented. ref count
572 * of from-device is decremented. */
573struct omap_dss_device *omap_dss_get_next_device(struct omap_dss_device *from)
574{
575 struct device *dev;
576 struct device *dev_start = NULL;
577 struct omap_dss_device *dssdev = NULL;
578
579 int match(struct device *dev, void *data)
580 {
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300581 return 1;
582 }
583
584 if (from)
585 dev_start = &from->dev;
586 dev = bus_find_device(dss_get_bus(), dev_start, NULL, match);
587 if (dev)
588 dssdev = to_dss_device(dev);
589 if (from)
590 put_device(&from->dev);
591
592 return dssdev;
593}
594EXPORT_SYMBOL(omap_dss_get_next_device);
595
596struct omap_dss_device *omap_dss_find_device(void *data,
597 int (*match)(struct omap_dss_device *dssdev, void *data))
598{
599 struct omap_dss_device *dssdev = NULL;
600
601 while ((dssdev = omap_dss_get_next_device(dssdev)) != NULL) {
602 if (match(dssdev, data))
603 return dssdev;
604 }
605
606 return NULL;
607}
608EXPORT_SYMBOL(omap_dss_find_device);
609
610int omap_dss_start_device(struct omap_dss_device *dssdev)
611{
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300612 if (!dssdev->driver) {
613 DSSDBG("no driver\n");
Tomi Valkeinene020f9a2010-02-17 13:36:48 +0200614 return -ENODEV;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300615 }
616
617 if (!try_module_get(dssdev->dev.driver->owner)) {
Tomi Valkeinene020f9a2010-02-17 13:36:48 +0200618 return -ENODEV;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300619 }
620
621 return 0;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300622}
623EXPORT_SYMBOL(omap_dss_start_device);
624
625void omap_dss_stop_device(struct omap_dss_device *dssdev)
626{
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300627 module_put(dssdev->dev.driver->owner);
628}
629EXPORT_SYMBOL(omap_dss_stop_device);
630