blob: 2c6e2bc5e207ed20481be0b0b452b8680bf7fb87 [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 Valkeineneed07e02009-08-07 13:43:20 +030034static ssize_t display_enabled_show(struct device *dev,
35 struct device_attribute *attr, char *buf)
36{
37 struct omap_dss_device *dssdev = to_dss_device(dev);
38 bool enabled = dssdev->state != OMAP_DSS_DISPLAY_DISABLED;
39
40 return snprintf(buf, PAGE_SIZE, "%d\n", enabled);
41}
42
43static ssize_t display_enabled_store(struct device *dev,
44 struct device_attribute *attr,
45 const char *buf, size_t size)
46{
47 struct omap_dss_device *dssdev = to_dss_device(dev);
Tomi Valkeinene3a26ae2011-08-15 15:55:55 +030048 int r;
49 bool enabled;
Tomi Valkeineneed07e02009-08-07 13:43:20 +030050
Tomi Valkeinene3a26ae2011-08-15 15:55:55 +030051 r = strtobool(buf, &enabled);
Tomi Valkeinene3502ce2011-04-04 15:40:23 +030052 if (r)
53 return r;
54
Tomi Valkeineneed07e02009-08-07 13:43:20 +030055 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
Tomi Valkeineneed07e02009-08-07 13:43:20 +030068static ssize_t display_tear_show(struct device *dev,
69 struct device_attribute *attr, char *buf)
70{
71 struct omap_dss_device *dssdev = to_dss_device(dev);
72 return snprintf(buf, PAGE_SIZE, "%d\n",
Tomi Valkeinen225b6502010-01-11 15:11:01 +020073 dssdev->driver->get_te ?
74 dssdev->driver->get_te(dssdev) : 0);
Tomi Valkeineneed07e02009-08-07 13:43:20 +030075}
76
77static ssize_t display_tear_store(struct device *dev,
78 struct device_attribute *attr, const char *buf, size_t size)
79{
80 struct omap_dss_device *dssdev = to_dss_device(dev);
Tomi Valkeinene3a26ae2011-08-15 15:55:55 +030081 int r;
82 bool te;
Tomi Valkeineneed07e02009-08-07 13:43:20 +030083
Tomi Valkeinen225b6502010-01-11 15:11:01 +020084 if (!dssdev->driver->enable_te || !dssdev->driver->get_te)
Tomi Valkeineneed07e02009-08-07 13:43:20 +030085 return -ENOENT;
86
Tomi Valkeinene3a26ae2011-08-15 15:55:55 +030087 r = strtobool(buf, &te);
Tomi Valkeinene3502ce2011-04-04 15:40:23 +030088 if (r)
89 return r;
90
Tomi Valkeinen225b6502010-01-11 15:11:01 +020091 r = dssdev->driver->enable_te(dssdev, te);
Tomi Valkeineneed07e02009-08-07 13:43:20 +030092 if (r)
93 return r;
94
95 return size;
96}
97
98static ssize_t display_timings_show(struct device *dev,
99 struct device_attribute *attr, char *buf)
100{
101 struct omap_dss_device *dssdev = to_dss_device(dev);
102 struct omap_video_timings t;
103
Tomi Valkeinen69b20482010-01-20 12:11:25 +0200104 if (!dssdev->driver->get_timings)
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300105 return -ENOENT;
106
Tomi Valkeinen69b20482010-01-20 12:11:25 +0200107 dssdev->driver->get_timings(dssdev, &t);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300108
109 return snprintf(buf, PAGE_SIZE, "%u,%u/%u/%u/%u,%u/%u/%u/%u\n",
110 t.pixel_clock,
111 t.x_res, t.hfp, t.hbp, t.hsw,
112 t.y_res, t.vfp, t.vbp, t.vsw);
113}
114
115static ssize_t display_timings_store(struct device *dev,
116 struct device_attribute *attr, const char *buf, size_t size)
117{
118 struct omap_dss_device *dssdev = to_dss_device(dev);
119 struct omap_video_timings t;
120 int r, found;
121
Tomi Valkeinen69b20482010-01-20 12:11:25 +0200122 if (!dssdev->driver->set_timings || !dssdev->driver->check_timings)
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300123 return -ENOENT;
124
125 found = 0;
126#ifdef CONFIG_OMAP2_DSS_VENC
127 if (strncmp("pal", buf, 3) == 0) {
128 t = omap_dss_pal_timings;
129 found = 1;
130 } else if (strncmp("ntsc", buf, 4) == 0) {
131 t = omap_dss_ntsc_timings;
132 found = 1;
133 }
134#endif
135 if (!found && sscanf(buf, "%u,%hu/%hu/%hu/%hu,%hu/%hu/%hu/%hu",
136 &t.pixel_clock,
137 &t.x_res, &t.hfp, &t.hbp, &t.hsw,
138 &t.y_res, &t.vfp, &t.vbp, &t.vsw) != 9)
139 return -EINVAL;
140
Tomi Valkeinen69b20482010-01-20 12:11:25 +0200141 r = dssdev->driver->check_timings(dssdev, &t);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300142 if (r)
143 return r;
144
Tomi Valkeinen69b20482010-01-20 12:11:25 +0200145 dssdev->driver->set_timings(dssdev, &t);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300146
147 return size;
148}
149
150static ssize_t display_rotate_show(struct device *dev,
151 struct device_attribute *attr, char *buf)
152{
153 struct omap_dss_device *dssdev = to_dss_device(dev);
154 int rotate;
Tomi Valkeinen87424e12010-01-08 16:52:48 +0200155 if (!dssdev->driver->get_rotate)
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300156 return -ENOENT;
Tomi Valkeinen87424e12010-01-08 16:52:48 +0200157 rotate = dssdev->driver->get_rotate(dssdev);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300158 return snprintf(buf, PAGE_SIZE, "%u\n", rotate);
159}
160
161static ssize_t display_rotate_store(struct device *dev,
162 struct device_attribute *attr, const char *buf, size_t size)
163{
164 struct omap_dss_device *dssdev = to_dss_device(dev);
Tomi Valkeinene3502ce2011-04-04 15:40:23 +0300165 int rot, r;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300166
Tomi Valkeinen87424e12010-01-08 16:52:48 +0200167 if (!dssdev->driver->set_rotate || !dssdev->driver->get_rotate)
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300168 return -ENOENT;
169
Tomi Valkeinene3502ce2011-04-04 15:40:23 +0300170 r = kstrtoint(buf, 0, &rot);
171 if (r)
172 return r;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300173
Tomi Valkeinen87424e12010-01-08 16:52:48 +0200174 r = dssdev->driver->set_rotate(dssdev, rot);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300175 if (r)
176 return r;
177
178 return size;
179}
180
181static ssize_t display_mirror_show(struct device *dev,
182 struct device_attribute *attr, char *buf)
183{
184 struct omap_dss_device *dssdev = to_dss_device(dev);
185 int mirror;
Tomi Valkeinen8d8aa612010-01-08 16:30:33 +0200186 if (!dssdev->driver->get_mirror)
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300187 return -ENOENT;
Tomi Valkeinen8d8aa612010-01-08 16:30:33 +0200188 mirror = dssdev->driver->get_mirror(dssdev);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300189 return snprintf(buf, PAGE_SIZE, "%u\n", mirror);
190}
191
192static ssize_t display_mirror_store(struct device *dev,
193 struct device_attribute *attr, const char *buf, size_t size)
194{
195 struct omap_dss_device *dssdev = to_dss_device(dev);
Tomi Valkeinene3a26ae2011-08-15 15:55:55 +0300196 int r;
197 bool mirror;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300198
Tomi Valkeinen8d8aa612010-01-08 16:30:33 +0200199 if (!dssdev->driver->set_mirror || !dssdev->driver->get_mirror)
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300200 return -ENOENT;
201
Tomi Valkeinene3a26ae2011-08-15 15:55:55 +0300202 r = strtobool(buf, &mirror);
Tomi Valkeinene3502ce2011-04-04 15:40:23 +0300203 if (r)
204 return r;
205
Tomi Valkeinen8d8aa612010-01-08 16:30:33 +0200206 r = dssdev->driver->set_mirror(dssdev, mirror);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300207 if (r)
208 return r;
209
210 return size;
211}
212
213static ssize_t display_wss_show(struct device *dev,
214 struct device_attribute *attr, char *buf)
215{
216 struct omap_dss_device *dssdev = to_dss_device(dev);
217 unsigned int wss;
218
Tomi Valkeinen36511312010-01-19 15:53:16 +0200219 if (!dssdev->driver->get_wss)
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300220 return -ENOENT;
221
Tomi Valkeinen36511312010-01-19 15:53:16 +0200222 wss = dssdev->driver->get_wss(dssdev);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300223
224 return snprintf(buf, PAGE_SIZE, "0x%05x\n", wss);
225}
226
227static ssize_t display_wss_store(struct device *dev,
228 struct device_attribute *attr, const char *buf, size_t size)
229{
230 struct omap_dss_device *dssdev = to_dss_device(dev);
Tomi Valkeinene3502ce2011-04-04 15:40:23 +0300231 u32 wss;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300232 int r;
233
Tomi Valkeinen36511312010-01-19 15:53:16 +0200234 if (!dssdev->driver->get_wss || !dssdev->driver->set_wss)
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300235 return -ENOENT;
236
Tomi Valkeinene3502ce2011-04-04 15:40:23 +0300237 r = kstrtou32(buf, 0, &wss);
238 if (r)
239 return r;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300240
241 if (wss > 0xfffff)
242 return -EINVAL;
243
Tomi Valkeinen36511312010-01-19 15:53:16 +0200244 r = dssdev->driver->set_wss(dssdev, wss);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300245 if (r)
246 return r;
247
248 return size;
249}
250
251static DEVICE_ATTR(enabled, S_IRUGO|S_IWUSR,
252 display_enabled_show, display_enabled_store);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300253static DEVICE_ATTR(tear_elim, S_IRUGO|S_IWUSR,
254 display_tear_show, display_tear_store);
255static DEVICE_ATTR(timings, S_IRUGO|S_IWUSR,
256 display_timings_show, display_timings_store);
257static DEVICE_ATTR(rotate, S_IRUGO|S_IWUSR,
258 display_rotate_show, display_rotate_store);
259static DEVICE_ATTR(mirror, S_IRUGO|S_IWUSR,
260 display_mirror_show, display_mirror_store);
261static DEVICE_ATTR(wss, S_IRUGO|S_IWUSR,
262 display_wss_show, display_wss_store);
263
264static struct device_attribute *display_sysfs_attrs[] = {
265 &dev_attr_enabled,
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300266 &dev_attr_tear_elim,
267 &dev_attr_timings,
268 &dev_attr_rotate,
269 &dev_attr_mirror,
270 &dev_attr_wss,
271 NULL
272};
273
Tomi Valkeinen96adcec2010-01-11 13:54:33 +0200274void omapdss_default_get_resolution(struct omap_dss_device *dssdev,
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300275 u16 *xres, u16 *yres)
276{
277 *xres = dssdev->panel.timings.x_res;
278 *yres = dssdev->panel.timings.y_res;
279}
Tomi Valkeinen96adcec2010-01-11 13:54:33 +0200280EXPORT_SYMBOL(omapdss_default_get_resolution);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300281
282void default_get_overlay_fifo_thresholds(enum omap_plane plane,
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +0300283 u32 fifo_size, u32 burst_size,
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300284 u32 *fifo_low, u32 *fifo_high)
285{
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +0300286 unsigned buf_unit = dss_feat_get_buffer_size_unit();
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300287
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +0300288 *fifo_high = fifo_size - buf_unit;
289 *fifo_low = fifo_size - burst_size;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300290}
291
Tomi Valkeinena2699502010-01-11 14:33:40 +0200292int omapdss_default_get_recommended_bpp(struct omap_dss_device *dssdev)
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300293{
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300294 switch (dssdev->type) {
295 case OMAP_DISPLAY_TYPE_DPI:
296 if (dssdev->phy.dpi.data_lines == 24)
297 return 24;
298 else
299 return 16;
300
301 case OMAP_DISPLAY_TYPE_DBI:
302 case OMAP_DISPLAY_TYPE_DSI:
303 if (dssdev->ctrl.pixel_size == 24)
304 return 24;
305 else
306 return 16;
307 case OMAP_DISPLAY_TYPE_VENC:
308 case OMAP_DISPLAY_TYPE_SDI:
Mythri P Kb1196012011-03-08 17:15:54 +0530309 case OMAP_DISPLAY_TYPE_HDMI:
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300310 return 24;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300311 default:
312 BUG();
313 }
314}
Tomi Valkeinena2699502010-01-11 14:33:40 +0200315EXPORT_SYMBOL(omapdss_default_get_recommended_bpp);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300316
317/* Checks if replication logic should be used. Only use for active matrix,
318 * when overlay is in RGB12U or RGB16 mode, and LCD interface is
319 * 18bpp or 24bpp */
320bool dss_use_replication(struct omap_dss_device *dssdev,
321 enum omap_color_mode mode)
322{
323 int bpp;
324
325 if (mode != OMAP_DSS_COLOR_RGB12U && mode != OMAP_DSS_COLOR_RGB16)
326 return false;
327
328 if (dssdev->type == OMAP_DISPLAY_TYPE_DPI &&
329 (dssdev->panel.config & OMAP_DSS_LCD_TFT) == 0)
330 return false;
331
332 switch (dssdev->type) {
333 case OMAP_DISPLAY_TYPE_DPI:
334 bpp = dssdev->phy.dpi.data_lines;
335 break;
Mythri P Kb1196012011-03-08 17:15:54 +0530336 case OMAP_DISPLAY_TYPE_HDMI:
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300337 case OMAP_DISPLAY_TYPE_VENC:
338 case OMAP_DISPLAY_TYPE_SDI:
339 bpp = 24;
340 break;
341 case OMAP_DISPLAY_TYPE_DBI:
342 case OMAP_DISPLAY_TYPE_DSI:
343 bpp = dssdev->ctrl.pixel_size;
344 break;
345 default:
346 BUG();
347 }
348
349 return bpp > 16;
350}
351
352void dss_init_device(struct platform_device *pdev,
353 struct omap_dss_device *dssdev)
354{
355 struct device_attribute *attr;
356 int i;
357 int r;
358
359 switch (dssdev->type) {
Roger Quadrosb4d78bf2010-03-17 13:35:19 +0100360#ifdef CONFIG_OMAP2_DSS_DPI
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300361 case OMAP_DISPLAY_TYPE_DPI:
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300362 r = dpi_init_display(dssdev);
363 break;
Roger Quadrosb4d78bf2010-03-17 13:35:19 +0100364#endif
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300365#ifdef CONFIG_OMAP2_DSS_RFBI
366 case OMAP_DISPLAY_TYPE_DBI:
367 r = rfbi_init_display(dssdev);
368 break;
369#endif
370#ifdef CONFIG_OMAP2_DSS_VENC
371 case OMAP_DISPLAY_TYPE_VENC:
372 r = venc_init_display(dssdev);
373 break;
374#endif
375#ifdef CONFIG_OMAP2_DSS_SDI
376 case OMAP_DISPLAY_TYPE_SDI:
377 r = sdi_init_display(dssdev);
378 break;
379#endif
380#ifdef CONFIG_OMAP2_DSS_DSI
381 case OMAP_DISPLAY_TYPE_DSI:
382 r = dsi_init_display(dssdev);
383 break;
384#endif
Mythri P Kc3198a52011-03-12 12:04:27 +0530385 case OMAP_DISPLAY_TYPE_HDMI:
386 r = hdmi_init_display(dssdev);
387 break;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300388 default:
Tomi Valkeinene528e3a2011-02-24 13:59:13 +0200389 DSSERR("Support for display '%s' not compiled in.\n",
390 dssdev->name);
391 return;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300392 }
393
394 if (r) {
395 DSSERR("failed to init display %s\n", dssdev->name);
396 return;
397 }
398
399 /* create device sysfs files */
400 i = 0;
401 while ((attr = display_sysfs_attrs[i++]) != NULL) {
402 r = device_create_file(&dssdev->dev, attr);
403 if (r)
404 DSSERR("failed to create sysfs file\n");
405 }
406
407 /* create display? sysfs links */
408 r = sysfs_create_link(&pdev->dev.kobj, &dssdev->dev.kobj,
409 dev_name(&dssdev->dev));
410 if (r)
411 DSSERR("failed to create sysfs display link\n");
412}
413
414void dss_uninit_device(struct platform_device *pdev,
415 struct omap_dss_device *dssdev)
416{
417 struct device_attribute *attr;
418 int i = 0;
419
420 sysfs_remove_link(&pdev->dev.kobj, dev_name(&dssdev->dev));
421
422 while ((attr = display_sysfs_attrs[i++]) != NULL)
423 device_remove_file(&dssdev->dev, attr);
424
425 if (dssdev->manager)
426 dssdev->manager->unset_device(dssdev->manager);
427}
428
429static int dss_suspend_device(struct device *dev, void *data)
430{
431 int r;
432 struct omap_dss_device *dssdev = to_dss_device(dev);
433
434 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
435 dssdev->activate_after_resume = false;
436 return 0;
437 }
438
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200439 if (!dssdev->driver->suspend) {
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300440 DSSERR("display '%s' doesn't implement suspend\n",
441 dssdev->name);
442 return -ENOSYS;
443 }
444
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200445 r = dssdev->driver->suspend(dssdev);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300446 if (r)
447 return r;
448
449 dssdev->activate_after_resume = true;
450
451 return 0;
452}
453
454int dss_suspend_all_devices(void)
455{
456 int r;
457 struct bus_type *bus = dss_get_bus();
458
459 r = bus_for_each_dev(bus, NULL, NULL, dss_suspend_device);
460 if (r) {
461 /* resume all displays that were suspended */
462 dss_resume_all_devices();
463 return r;
464 }
465
466 return 0;
467}
468
469static int dss_resume_device(struct device *dev, void *data)
470{
471 int r;
472 struct omap_dss_device *dssdev = to_dss_device(dev);
473
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200474 if (dssdev->activate_after_resume && dssdev->driver->resume) {
475 r = dssdev->driver->resume(dssdev);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300476 if (r)
477 return r;
478 }
479
480 dssdev->activate_after_resume = false;
481
482 return 0;
483}
484
485int dss_resume_all_devices(void)
486{
487 struct bus_type *bus = dss_get_bus();
488
489 return bus_for_each_dev(bus, NULL, NULL, dss_resume_device);
490}
491
492static int dss_disable_device(struct device *dev, void *data)
493{
494 struct omap_dss_device *dssdev = to_dss_device(dev);
Jani Nikula279fcd42010-03-24 11:59:38 +0100495
496 if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED)
497 dssdev->driver->disable(dssdev);
498
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300499 return 0;
500}
501
502void dss_disable_all_devices(void)
503{
504 struct bus_type *bus = dss_get_bus();
505 bus_for_each_dev(bus, NULL, NULL, dss_disable_device);
506}
507
508
509void omap_dss_get_device(struct omap_dss_device *dssdev)
510{
511 get_device(&dssdev->dev);
512}
513EXPORT_SYMBOL(omap_dss_get_device);
514
515void omap_dss_put_device(struct omap_dss_device *dssdev)
516{
517 put_device(&dssdev->dev);
518}
519EXPORT_SYMBOL(omap_dss_put_device);
520
521/* ref count of the found device is incremented. ref count
522 * of from-device is decremented. */
523struct omap_dss_device *omap_dss_get_next_device(struct omap_dss_device *from)
524{
525 struct device *dev;
526 struct device *dev_start = NULL;
527 struct omap_dss_device *dssdev = NULL;
528
529 int match(struct device *dev, void *data)
530 {
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300531 return 1;
532 }
533
534 if (from)
535 dev_start = &from->dev;
536 dev = bus_find_device(dss_get_bus(), dev_start, NULL, match);
537 if (dev)
538 dssdev = to_dss_device(dev);
539 if (from)
540 put_device(&from->dev);
541
542 return dssdev;
543}
544EXPORT_SYMBOL(omap_dss_get_next_device);
545
546struct omap_dss_device *omap_dss_find_device(void *data,
547 int (*match)(struct omap_dss_device *dssdev, void *data))
548{
549 struct omap_dss_device *dssdev = NULL;
550
551 while ((dssdev = omap_dss_get_next_device(dssdev)) != NULL) {
552 if (match(dssdev, data))
553 return dssdev;
554 }
555
556 return NULL;
557}
558EXPORT_SYMBOL(omap_dss_find_device);
559
560int omap_dss_start_device(struct omap_dss_device *dssdev)
561{
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300562 if (!dssdev->driver) {
563 DSSDBG("no driver\n");
Tomi Valkeinene020f9a2010-02-17 13:36:48 +0200564 return -ENODEV;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300565 }
566
567 if (!try_module_get(dssdev->dev.driver->owner)) {
Tomi Valkeinene020f9a2010-02-17 13:36:48 +0200568 return -ENODEV;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300569 }
570
571 return 0;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300572}
573EXPORT_SYMBOL(omap_dss_start_device);
574
575void omap_dss_stop_device(struct omap_dss_device *dssdev)
576{
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300577 module_put(dssdev->dev.driver->owner);
578}
579EXPORT_SYMBOL(omap_dss_stop_device);
580