blob: 1e587306215f53cf016d9b1249a128df23154b45 [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);
Archit Tanejaa14909e2012-06-21 13:21:02 +0530119 struct omap_video_timings t = dssdev->panel.timings;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300120 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 Valkeinenb82fe7f2012-09-05 14:09:33 +0300145 dssdev->driver->disable(dssdev);
Tomi Valkeinen69b20482010-01-20 12:11:25 +0200146 dssdev->driver->set_timings(dssdev, &t);
Tomi Valkeinenb82fe7f2012-09-05 14:09:33 +0300147 r = dssdev->driver->enable(dssdev);
148 if (r)
149 return r;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300150
151 return size;
152}
153
154static ssize_t display_rotate_show(struct device *dev,
155 struct device_attribute *attr, char *buf)
156{
157 struct omap_dss_device *dssdev = to_dss_device(dev);
158 int rotate;
Tomi Valkeinen87424e12010-01-08 16:52:48 +0200159 if (!dssdev->driver->get_rotate)
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300160 return -ENOENT;
Tomi Valkeinen87424e12010-01-08 16:52:48 +0200161 rotate = dssdev->driver->get_rotate(dssdev);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300162 return snprintf(buf, PAGE_SIZE, "%u\n", rotate);
163}
164
165static ssize_t display_rotate_store(struct device *dev,
166 struct device_attribute *attr, const char *buf, size_t size)
167{
168 struct omap_dss_device *dssdev = to_dss_device(dev);
Tomi Valkeinene3502ce2011-04-04 15:40:23 +0300169 int rot, r;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300170
Tomi Valkeinen87424e12010-01-08 16:52:48 +0200171 if (!dssdev->driver->set_rotate || !dssdev->driver->get_rotate)
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300172 return -ENOENT;
173
Tomi Valkeinene3502ce2011-04-04 15:40:23 +0300174 r = kstrtoint(buf, 0, &rot);
175 if (r)
176 return r;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300177
Tomi Valkeinen87424e12010-01-08 16:52:48 +0200178 r = dssdev->driver->set_rotate(dssdev, rot);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300179 if (r)
180 return r;
181
182 return size;
183}
184
185static ssize_t display_mirror_show(struct device *dev,
186 struct device_attribute *attr, char *buf)
187{
188 struct omap_dss_device *dssdev = to_dss_device(dev);
189 int mirror;
Tomi Valkeinen8d8aa612010-01-08 16:30:33 +0200190 if (!dssdev->driver->get_mirror)
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300191 return -ENOENT;
Tomi Valkeinen8d8aa612010-01-08 16:30:33 +0200192 mirror = dssdev->driver->get_mirror(dssdev);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300193 return snprintf(buf, PAGE_SIZE, "%u\n", mirror);
194}
195
196static ssize_t display_mirror_store(struct device *dev,
197 struct device_attribute *attr, const char *buf, size_t size)
198{
199 struct omap_dss_device *dssdev = to_dss_device(dev);
Tomi Valkeinene3a26ae2011-08-15 15:55:55 +0300200 int r;
201 bool mirror;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300202
Tomi Valkeinen8d8aa612010-01-08 16:30:33 +0200203 if (!dssdev->driver->set_mirror || !dssdev->driver->get_mirror)
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300204 return -ENOENT;
205
Tomi Valkeinene3a26ae2011-08-15 15:55:55 +0300206 r = strtobool(buf, &mirror);
Tomi Valkeinene3502ce2011-04-04 15:40:23 +0300207 if (r)
208 return r;
209
Tomi Valkeinen8d8aa612010-01-08 16:30:33 +0200210 r = dssdev->driver->set_mirror(dssdev, mirror);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300211 if (r)
212 return r;
213
214 return size;
215}
216
217static ssize_t display_wss_show(struct device *dev,
218 struct device_attribute *attr, char *buf)
219{
220 struct omap_dss_device *dssdev = to_dss_device(dev);
221 unsigned int wss;
222
Tomi Valkeinen36511312010-01-19 15:53:16 +0200223 if (!dssdev->driver->get_wss)
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300224 return -ENOENT;
225
Tomi Valkeinen36511312010-01-19 15:53:16 +0200226 wss = dssdev->driver->get_wss(dssdev);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300227
228 return snprintf(buf, PAGE_SIZE, "0x%05x\n", wss);
229}
230
231static ssize_t display_wss_store(struct device *dev,
232 struct device_attribute *attr, const char *buf, size_t size)
233{
234 struct omap_dss_device *dssdev = to_dss_device(dev);
Tomi Valkeinene3502ce2011-04-04 15:40:23 +0300235 u32 wss;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300236 int r;
237
Tomi Valkeinen36511312010-01-19 15:53:16 +0200238 if (!dssdev->driver->get_wss || !dssdev->driver->set_wss)
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300239 return -ENOENT;
240
Tomi Valkeinene3502ce2011-04-04 15:40:23 +0300241 r = kstrtou32(buf, 0, &wss);
242 if (r)
243 return r;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300244
245 if (wss > 0xfffff)
246 return -EINVAL;
247
Tomi Valkeinen36511312010-01-19 15:53:16 +0200248 r = dssdev->driver->set_wss(dssdev, wss);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300249 if (r)
250 return r;
251
252 return size;
253}
254
255static DEVICE_ATTR(enabled, S_IRUGO|S_IWUSR,
256 display_enabled_show, display_enabled_store);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300257static DEVICE_ATTR(tear_elim, S_IRUGO|S_IWUSR,
258 display_tear_show, display_tear_store);
259static DEVICE_ATTR(timings, S_IRUGO|S_IWUSR,
260 display_timings_show, display_timings_store);
261static DEVICE_ATTR(rotate, S_IRUGO|S_IWUSR,
262 display_rotate_show, display_rotate_store);
263static DEVICE_ATTR(mirror, S_IRUGO|S_IWUSR,
264 display_mirror_show, display_mirror_store);
265static DEVICE_ATTR(wss, S_IRUGO|S_IWUSR,
266 display_wss_show, display_wss_store);
267
268static struct device_attribute *display_sysfs_attrs[] = {
269 &dev_attr_enabled,
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300270 &dev_attr_tear_elim,
271 &dev_attr_timings,
272 &dev_attr_rotate,
273 &dev_attr_mirror,
274 &dev_attr_wss,
275 NULL
276};
277
Tomi Valkeinen96adcec2010-01-11 13:54:33 +0200278void omapdss_default_get_resolution(struct omap_dss_device *dssdev,
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300279 u16 *xres, u16 *yres)
280{
281 *xres = dssdev->panel.timings.x_res;
282 *yres = dssdev->panel.timings.y_res;
283}
Tomi Valkeinen96adcec2010-01-11 13:54:33 +0200284EXPORT_SYMBOL(omapdss_default_get_resolution);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300285
Tomi Valkeinena2699502010-01-11 14:33:40 +0200286int omapdss_default_get_recommended_bpp(struct omap_dss_device *dssdev)
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300287{
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300288 switch (dssdev->type) {
289 case OMAP_DISPLAY_TYPE_DPI:
290 if (dssdev->phy.dpi.data_lines == 24)
291 return 24;
292 else
293 return 16;
294
295 case OMAP_DISPLAY_TYPE_DBI:
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300296 if (dssdev->ctrl.pixel_size == 24)
297 return 24;
298 else
299 return 16;
Archit Tanejaa3b3cc22011-09-08 18:42:16 +0530300 case OMAP_DISPLAY_TYPE_DSI:
301 if (dsi_get_pixel_size(dssdev->panel.dsi_pix_fmt) > 16)
302 return 24;
303 else
304 return 16;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300305 case OMAP_DISPLAY_TYPE_VENC:
306 case OMAP_DISPLAY_TYPE_SDI:
Mythri P Kb1196012011-03-08 17:15:54 +0530307 case OMAP_DISPLAY_TYPE_HDMI:
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300308 return 24;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300309 default:
310 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300311 return 0;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300312 }
313}
Tomi Valkeinena2699502010-01-11 14:33:40 +0200314EXPORT_SYMBOL(omapdss_default_get_recommended_bpp);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300315
Grazvydas Ignotas4b6430f2012-03-15 20:00:23 +0200316void omapdss_default_get_timings(struct omap_dss_device *dssdev,
317 struct omap_video_timings *timings)
318{
319 *timings = dssdev->panel.timings;
320}
321EXPORT_SYMBOL(omapdss_default_get_timings);
322
Tomi Valkeinen5eeb55f2012-09-07 15:48:45 +0300323/*
324 * Connect dssdev to a manager if the manager is free or if force is specified.
325 * Connect all overlays to that manager if they are free or if force is
326 * specified.
327 */
328static int dss_init_connections(struct omap_dss_device *dssdev, bool force)
329{
Archit Taneja32248272012-09-10 14:34:16 +0530330 struct omap_dss_output *out;
Tomi Valkeinen5eeb55f2012-09-07 15:48:45 +0300331 struct omap_overlay_manager *mgr;
332 int i, r;
333
Archit Taneja32248272012-09-10 14:34:16 +0530334 out = omapdss_get_output_from_dssdev(dssdev);
335
336 WARN_ON(dssdev->output);
337 WARN_ON(out->device);
338
339 r = omapdss_output_set_device(out, dssdev);
340 if (r) {
341 DSSERR("failed to connect output to new device\n");
342 return r;
343 }
Tomi Valkeinen5eeb55f2012-09-07 15:48:45 +0300344
345 mgr = omap_dss_get_overlay_manager(dssdev->channel);
346
Archit Taneja32248272012-09-10 14:34:16 +0530347 if (mgr->output && !force)
Tomi Valkeinen5eeb55f2012-09-07 15:48:45 +0300348 return 0;
349
Archit Taneja32248272012-09-10 14:34:16 +0530350 if (mgr->output)
351 mgr->unset_output(mgr);
Tomi Valkeinen5eeb55f2012-09-07 15:48:45 +0300352
Archit Taneja32248272012-09-10 14:34:16 +0530353 r = mgr->set_output(mgr, out);
Tomi Valkeinen5eeb55f2012-09-07 15:48:45 +0300354 if (r) {
Archit Taneja32248272012-09-10 14:34:16 +0530355 DSSERR("failed to connect manager to output of new device\n");
356
357 /* remove the output-device connection we just made */
358 omapdss_output_unset_device(out);
Tomi Valkeinen5eeb55f2012-09-07 15:48:45 +0300359 return r;
360 }
361
362 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
363 struct omap_overlay *ovl = omap_dss_get_overlay(i);
364
365 if (!ovl->manager || force) {
366 if (ovl->manager)
367 ovl->unset_manager(ovl);
368
369 r = ovl->set_manager(ovl, mgr);
370 if (r) {
371 DSSERR("failed to set initial overlay\n");
372 return r;
373 }
374 }
375 }
376
377 return 0;
378}
379
380static void dss_uninit_connections(struct omap_dss_device *dssdev)
381{
Archit Taneja32248272012-09-10 14:34:16 +0530382 if (dssdev->output) {
383 struct omap_overlay_manager *mgr = dssdev->output->manager;
384
385 if (mgr)
386 mgr->unset_output(mgr);
387
388 omapdss_output_unset_device(dssdev->output);
389 }
Tomi Valkeinen5eeb55f2012-09-07 15:48:45 +0300390}
391
Tomi Valkeinen47eb6762012-09-07 15:44:30 +0300392int dss_init_device(struct platform_device *pdev,
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300393 struct omap_dss_device *dssdev)
394{
395 struct device_attribute *attr;
Tomi Valkeinen47eb6762012-09-07 15:44:30 +0300396 int i, r;
Tomi Valkeinen5eeb55f2012-09-07 15:48:45 +0300397 const char *def_disp_name = dss_get_default_display_name();
398 bool force;
399
400 force = def_disp_name && strcmp(def_disp_name, dssdev->name) == 0;
401 dss_init_connections(dssdev, force);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300402
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300403 /* create device sysfs files */
404 i = 0;
405 while ((attr = display_sysfs_attrs[i++]) != NULL) {
406 r = device_create_file(&dssdev->dev, attr);
Tomi Valkeinen47eb6762012-09-07 15:44:30 +0300407 if (r) {
408 for (i = i - 2; i >= 0; i--) {
409 attr = display_sysfs_attrs[i];
410 device_remove_file(&dssdev->dev, attr);
411 }
412
Tomi Valkeinen5eeb55f2012-09-07 15:48:45 +0300413 dss_uninit_connections(dssdev);
414
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300415 DSSERR("failed to create sysfs file\n");
Tomi Valkeinen47eb6762012-09-07 15:44:30 +0300416 return r;
417 }
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300418 }
419
420 /* create display? sysfs links */
421 r = sysfs_create_link(&pdev->dev.kobj, &dssdev->dev.kobj,
422 dev_name(&dssdev->dev));
Tomi Valkeinen47eb6762012-09-07 15:44:30 +0300423 if (r) {
424 while ((attr = display_sysfs_attrs[i++]) != NULL)
425 device_remove_file(&dssdev->dev, attr);
426
Tomi Valkeinen5eeb55f2012-09-07 15:48:45 +0300427 dss_uninit_connections(dssdev);
428
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300429 DSSERR("failed to create sysfs display link\n");
Tomi Valkeinen47eb6762012-09-07 15:44:30 +0300430 return r;
431 }
432
433 return 0;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300434}
435
436void dss_uninit_device(struct platform_device *pdev,
437 struct omap_dss_device *dssdev)
438{
439 struct device_attribute *attr;
440 int i = 0;
441
442 sysfs_remove_link(&pdev->dev.kobj, dev_name(&dssdev->dev));
443
444 while ((attr = display_sysfs_attrs[i++]) != NULL)
445 device_remove_file(&dssdev->dev, attr);
446
Tomi Valkeinen5eeb55f2012-09-07 15:48:45 +0300447 dss_uninit_connections(dssdev);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300448}
449
450static int dss_suspend_device(struct device *dev, void *data)
451{
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300452 struct omap_dss_device *dssdev = to_dss_device(dev);
453
454 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
455 dssdev->activate_after_resume = false;
456 return 0;
457 }
458
Tomi Valkeinen998c3362012-05-30 13:26:00 +0300459 dssdev->driver->disable(dssdev);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300460
461 dssdev->activate_after_resume = true;
462
463 return 0;
464}
465
466int dss_suspend_all_devices(void)
467{
468 int r;
469 struct bus_type *bus = dss_get_bus();
470
471 r = bus_for_each_dev(bus, NULL, NULL, dss_suspend_device);
472 if (r) {
473 /* resume all displays that were suspended */
474 dss_resume_all_devices();
475 return r;
476 }
477
478 return 0;
479}
480
481static int dss_resume_device(struct device *dev, void *data)
482{
483 int r;
484 struct omap_dss_device *dssdev = to_dss_device(dev);
485
Tomi Valkeinen998c3362012-05-30 13:26:00 +0300486 if (dssdev->activate_after_resume) {
487 r = dssdev->driver->enable(dssdev);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300488 if (r)
489 return r;
490 }
491
492 dssdev->activate_after_resume = false;
493
494 return 0;
495}
496
497int dss_resume_all_devices(void)
498{
499 struct bus_type *bus = dss_get_bus();
500
501 return bus_for_each_dev(bus, NULL, NULL, dss_resume_device);
502}
503
504static int dss_disable_device(struct device *dev, void *data)
505{
506 struct omap_dss_device *dssdev = to_dss_device(dev);
Jani Nikula279fcd42010-03-24 11:59:38 +0100507
508 if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED)
509 dssdev->driver->disable(dssdev);
510
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300511 return 0;
512}
513
514void dss_disable_all_devices(void)
515{
516 struct bus_type *bus = dss_get_bus();
517 bus_for_each_dev(bus, NULL, NULL, dss_disable_device);
518}
519
520
521void omap_dss_get_device(struct omap_dss_device *dssdev)
522{
523 get_device(&dssdev->dev);
524}
525EXPORT_SYMBOL(omap_dss_get_device);
526
527void omap_dss_put_device(struct omap_dss_device *dssdev)
528{
529 put_device(&dssdev->dev);
530}
531EXPORT_SYMBOL(omap_dss_put_device);
532
533/* ref count of the found device is incremented. ref count
534 * of from-device is decremented. */
535struct omap_dss_device *omap_dss_get_next_device(struct omap_dss_device *from)
536{
537 struct device *dev;
538 struct device *dev_start = NULL;
539 struct omap_dss_device *dssdev = NULL;
540
541 int match(struct device *dev, void *data)
542 {
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300543 return 1;
544 }
545
546 if (from)
547 dev_start = &from->dev;
548 dev = bus_find_device(dss_get_bus(), dev_start, NULL, match);
549 if (dev)
550 dssdev = to_dss_device(dev);
551 if (from)
552 put_device(&from->dev);
553
554 return dssdev;
555}
556EXPORT_SYMBOL(omap_dss_get_next_device);
557
558struct omap_dss_device *omap_dss_find_device(void *data,
559 int (*match)(struct omap_dss_device *dssdev, void *data))
560{
561 struct omap_dss_device *dssdev = NULL;
562
563 while ((dssdev = omap_dss_get_next_device(dssdev)) != NULL) {
564 if (match(dssdev, data))
565 return dssdev;
566 }
567
568 return NULL;
569}
570EXPORT_SYMBOL(omap_dss_find_device);
571
572int omap_dss_start_device(struct omap_dss_device *dssdev)
573{
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300574 if (!dssdev->driver) {
575 DSSDBG("no driver\n");
Tomi Valkeinene020f9a2010-02-17 13:36:48 +0200576 return -ENODEV;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300577 }
578
579 if (!try_module_get(dssdev->dev.driver->owner)) {
Tomi Valkeinene020f9a2010-02-17 13:36:48 +0200580 return -ENODEV;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300581 }
582
583 return 0;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300584}
585EXPORT_SYMBOL(omap_dss_start_device);
586
587void omap_dss_stop_device(struct omap_dss_device *dssdev)
588{
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300589 module_put(dssdev->dev.driver->owner);
590}
591EXPORT_SYMBOL(omap_dss_stop_device);
592