2 * linux/drivers/video/omap2/dss/display.c
4 * Copyright (C) 2009 Nokia Corporation
5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
7 * Some code and ideas taken from drivers/video/omap/ driver
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.
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
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/>.
23 #define DSS_SUBSYS_NAME "DISPLAY"
25 #include <linux/kernel.h>
26 #include <linux/module.h>
27 #include <linux/jiffies.h>
28 #include <linux/platform_device.h>
30 #include <video/omapdss.h>
32 #include "dss_features.h"
34 static ssize_t display_enabled_show(struct device *dev,
35 struct device_attribute *attr, char *buf)
37 struct omap_dss_device *dssdev = to_dss_device(dev);
38 bool enabled = dssdev->state != OMAP_DSS_DISPLAY_DISABLED;
40 return snprintf(buf, PAGE_SIZE, "%d\n", enabled);
43 static ssize_t display_enabled_store(struct device *dev,
44 struct device_attribute *attr,
45 const char *buf, size_t size)
47 struct omap_dss_device *dssdev = to_dss_device(dev);
51 r = strtobool(buf, &enabled);
55 if (enabled != (dssdev->state != OMAP_DSS_DISPLAY_DISABLED)) {
57 r = dssdev->driver->enable(dssdev);
61 dssdev->driver->disable(dssdev);
68 static ssize_t display_tear_show(struct device *dev,
69 struct device_attribute *attr, char *buf)
71 struct omap_dss_device *dssdev = to_dss_device(dev);
72 return snprintf(buf, PAGE_SIZE, "%d\n",
73 dssdev->driver->get_te ?
74 dssdev->driver->get_te(dssdev) : 0);
77 static ssize_t display_tear_store(struct device *dev,
78 struct device_attribute *attr, const char *buf, size_t size)
80 struct omap_dss_device *dssdev = to_dss_device(dev);
84 if (!dssdev->driver->enable_te || !dssdev->driver->get_te)
87 r = strtobool(buf, &te);
91 r = dssdev->driver->enable_te(dssdev, te);
98 static ssize_t display_timings_show(struct device *dev,
99 struct device_attribute *attr, char *buf)
101 struct omap_dss_device *dssdev = to_dss_device(dev);
102 struct omap_video_timings t;
104 if (!dssdev->driver->get_timings)
107 dssdev->driver->get_timings(dssdev, &t);
109 return snprintf(buf, PAGE_SIZE, "%u,%u/%u/%u/%u,%u/%u/%u/%u\n",
111 t.x_res, t.hfp, t.hbp, t.hsw,
112 t.y_res, t.vfp, t.vbp, t.vsw);
115 static ssize_t display_timings_store(struct device *dev,
116 struct device_attribute *attr, const char *buf, size_t size)
118 struct omap_dss_device *dssdev = to_dss_device(dev);
119 struct omap_video_timings t = dssdev->panel.timings;
122 if (!dssdev->driver->set_timings || !dssdev->driver->check_timings)
126 #ifdef CONFIG_OMAP2_DSS_VENC
127 if (strncmp("pal", buf, 3) == 0) {
128 t = omap_dss_pal_timings;
130 } else if (strncmp("ntsc", buf, 4) == 0) {
131 t = omap_dss_ntsc_timings;
135 if (!found && sscanf(buf, "%u,%hu/%hu/%hu/%hu,%hu/%hu/%hu/%hu",
137 &t.x_res, &t.hfp, &t.hbp, &t.hsw,
138 &t.y_res, &t.vfp, &t.vbp, &t.vsw) != 9)
141 r = dssdev->driver->check_timings(dssdev, &t);
145 dssdev->driver->disable(dssdev);
146 dssdev->driver->set_timings(dssdev, &t);
147 r = dssdev->driver->enable(dssdev);
154 static ssize_t display_rotate_show(struct device *dev,
155 struct device_attribute *attr, char *buf)
157 struct omap_dss_device *dssdev = to_dss_device(dev);
159 if (!dssdev->driver->get_rotate)
161 rotate = dssdev->driver->get_rotate(dssdev);
162 return snprintf(buf, PAGE_SIZE, "%u\n", rotate);
165 static ssize_t display_rotate_store(struct device *dev,
166 struct device_attribute *attr, const char *buf, size_t size)
168 struct omap_dss_device *dssdev = to_dss_device(dev);
171 if (!dssdev->driver->set_rotate || !dssdev->driver->get_rotate)
174 r = kstrtoint(buf, 0, &rot);
178 r = dssdev->driver->set_rotate(dssdev, rot);
185 static ssize_t display_mirror_show(struct device *dev,
186 struct device_attribute *attr, char *buf)
188 struct omap_dss_device *dssdev = to_dss_device(dev);
190 if (!dssdev->driver->get_mirror)
192 mirror = dssdev->driver->get_mirror(dssdev);
193 return snprintf(buf, PAGE_SIZE, "%u\n", mirror);
196 static ssize_t display_mirror_store(struct device *dev,
197 struct device_attribute *attr, const char *buf, size_t size)
199 struct omap_dss_device *dssdev = to_dss_device(dev);
203 if (!dssdev->driver->set_mirror || !dssdev->driver->get_mirror)
206 r = strtobool(buf, &mirror);
210 r = dssdev->driver->set_mirror(dssdev, mirror);
217 static ssize_t display_wss_show(struct device *dev,
218 struct device_attribute *attr, char *buf)
220 struct omap_dss_device *dssdev = to_dss_device(dev);
223 if (!dssdev->driver->get_wss)
226 wss = dssdev->driver->get_wss(dssdev);
228 return snprintf(buf, PAGE_SIZE, "0x%05x\n", wss);
231 static ssize_t display_wss_store(struct device *dev,
232 struct device_attribute *attr, const char *buf, size_t size)
234 struct omap_dss_device *dssdev = to_dss_device(dev);
238 if (!dssdev->driver->get_wss || !dssdev->driver->set_wss)
241 r = kstrtou32(buf, 0, &wss);
248 r = dssdev->driver->set_wss(dssdev, wss);
255 static DEVICE_ATTR(enabled, S_IRUGO|S_IWUSR,
256 display_enabled_show, display_enabled_store);
257 static DEVICE_ATTR(tear_elim, S_IRUGO|S_IWUSR,
258 display_tear_show, display_tear_store);
259 static DEVICE_ATTR(timings, S_IRUGO|S_IWUSR,
260 display_timings_show, display_timings_store);
261 static DEVICE_ATTR(rotate, S_IRUGO|S_IWUSR,
262 display_rotate_show, display_rotate_store);
263 static DEVICE_ATTR(mirror, S_IRUGO|S_IWUSR,
264 display_mirror_show, display_mirror_store);
265 static DEVICE_ATTR(wss, S_IRUGO|S_IWUSR,
266 display_wss_show, display_wss_store);
268 static struct device_attribute *display_sysfs_attrs[] = {
278 void omapdss_default_get_resolution(struct omap_dss_device *dssdev,
279 u16 *xres, u16 *yres)
281 *xres = dssdev->panel.timings.x_res;
282 *yres = dssdev->panel.timings.y_res;
284 EXPORT_SYMBOL(omapdss_default_get_resolution);
286 int omapdss_default_get_recommended_bpp(struct omap_dss_device *dssdev)
288 switch (dssdev->type) {
289 case OMAP_DISPLAY_TYPE_DPI:
290 if (dssdev->phy.dpi.data_lines == 24)
295 case OMAP_DISPLAY_TYPE_DBI:
296 if (dssdev->ctrl.pixel_size == 24)
300 case OMAP_DISPLAY_TYPE_DSI:
301 if (dsi_get_pixel_size(dssdev->panel.dsi_pix_fmt) > 16)
305 case OMAP_DISPLAY_TYPE_VENC:
306 case OMAP_DISPLAY_TYPE_SDI:
307 case OMAP_DISPLAY_TYPE_HDMI:
314 EXPORT_SYMBOL(omapdss_default_get_recommended_bpp);
316 void omapdss_default_get_timings(struct omap_dss_device *dssdev,
317 struct omap_video_timings *timings)
319 *timings = dssdev->panel.timings;
321 EXPORT_SYMBOL(omapdss_default_get_timings);
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
328 static int dss_init_connections(struct omap_dss_device *dssdev, bool force)
330 struct omap_overlay_manager *mgr;
333 WARN_ON(dssdev->manager);
335 mgr = omap_dss_get_overlay_manager(dssdev->channel);
337 if (mgr->device && !force)
341 mgr->unset_device(mgr);
343 r = mgr->set_device(mgr, dssdev);
345 DSSERR("failed to set initial manager\n");
349 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
350 struct omap_overlay *ovl = omap_dss_get_overlay(i);
352 if (!ovl->manager || force) {
354 ovl->unset_manager(ovl);
356 r = ovl->set_manager(ovl, mgr);
358 DSSERR("failed to set initial overlay\n");
367 static void dss_uninit_connections(struct omap_dss_device *dssdev)
370 dssdev->manager->unset_device(dssdev->manager);
373 int dss_init_device(struct platform_device *pdev,
374 struct omap_dss_device *dssdev)
376 struct device_attribute *attr;
378 const char *def_disp_name = dss_get_default_display_name();
381 force = def_disp_name && strcmp(def_disp_name, dssdev->name) == 0;
382 dss_init_connections(dssdev, force);
384 /* create device sysfs files */
386 while ((attr = display_sysfs_attrs[i++]) != NULL) {
387 r = device_create_file(&dssdev->dev, attr);
389 for (i = i - 2; i >= 0; i--) {
390 attr = display_sysfs_attrs[i];
391 device_remove_file(&dssdev->dev, attr);
394 dss_uninit_connections(dssdev);
396 DSSERR("failed to create sysfs file\n");
401 /* create display? sysfs links */
402 r = sysfs_create_link(&pdev->dev.kobj, &dssdev->dev.kobj,
403 dev_name(&dssdev->dev));
405 while ((attr = display_sysfs_attrs[i++]) != NULL)
406 device_remove_file(&dssdev->dev, attr);
408 dss_uninit_connections(dssdev);
410 DSSERR("failed to create sysfs display link\n");
417 void dss_uninit_device(struct platform_device *pdev,
418 struct omap_dss_device *dssdev)
420 struct device_attribute *attr;
423 sysfs_remove_link(&pdev->dev.kobj, dev_name(&dssdev->dev));
425 while ((attr = display_sysfs_attrs[i++]) != NULL)
426 device_remove_file(&dssdev->dev, attr);
428 dss_uninit_connections(dssdev);
431 static int dss_suspend_device(struct device *dev, void *data)
434 struct omap_dss_device *dssdev = to_dss_device(dev);
436 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
437 dssdev->activate_after_resume = false;
441 if (!dssdev->driver->suspend) {
442 DSSERR("display '%s' doesn't implement suspend\n",
447 r = dssdev->driver->suspend(dssdev);
451 dssdev->activate_after_resume = true;
456 int dss_suspend_all_devices(void)
459 struct bus_type *bus = dss_get_bus();
461 r = bus_for_each_dev(bus, NULL, NULL, dss_suspend_device);
463 /* resume all displays that were suspended */
464 dss_resume_all_devices();
471 static int dss_resume_device(struct device *dev, void *data)
474 struct omap_dss_device *dssdev = to_dss_device(dev);
476 if (dssdev->activate_after_resume && dssdev->driver->resume) {
477 r = dssdev->driver->resume(dssdev);
482 dssdev->activate_after_resume = false;
487 int dss_resume_all_devices(void)
489 struct bus_type *bus = dss_get_bus();
491 return bus_for_each_dev(bus, NULL, NULL, dss_resume_device);
494 static int dss_disable_device(struct device *dev, void *data)
496 struct omap_dss_device *dssdev = to_dss_device(dev);
498 if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED)
499 dssdev->driver->disable(dssdev);
504 void dss_disable_all_devices(void)
506 struct bus_type *bus = dss_get_bus();
507 bus_for_each_dev(bus, NULL, NULL, dss_disable_device);
511 void omap_dss_get_device(struct omap_dss_device *dssdev)
513 get_device(&dssdev->dev);
515 EXPORT_SYMBOL(omap_dss_get_device);
517 void omap_dss_put_device(struct omap_dss_device *dssdev)
519 put_device(&dssdev->dev);
521 EXPORT_SYMBOL(omap_dss_put_device);
523 /* ref count of the found device is incremented. ref count
524 * of from-device is decremented. */
525 struct omap_dss_device *omap_dss_get_next_device(struct omap_dss_device *from)
528 struct device *dev_start = NULL;
529 struct omap_dss_device *dssdev = NULL;
531 int match(struct device *dev, void *data)
537 dev_start = &from->dev;
538 dev = bus_find_device(dss_get_bus(), dev_start, NULL, match);
540 dssdev = to_dss_device(dev);
542 put_device(&from->dev);
546 EXPORT_SYMBOL(omap_dss_get_next_device);
548 struct omap_dss_device *omap_dss_find_device(void *data,
549 int (*match)(struct omap_dss_device *dssdev, void *data))
551 struct omap_dss_device *dssdev = NULL;
553 while ((dssdev = omap_dss_get_next_device(dssdev)) != NULL) {
554 if (match(dssdev, data))
560 EXPORT_SYMBOL(omap_dss_find_device);
562 int omap_dss_start_device(struct omap_dss_device *dssdev)
564 if (!dssdev->driver) {
565 DSSDBG("no driver\n");
569 if (!try_module_get(dssdev->dev.driver->owner)) {
575 EXPORT_SYMBOL(omap_dss_start_device);
577 void omap_dss_stop_device(struct omap_dss_device *dssdev)
579 module_put(dssdev->dev.driver->owner);
581 EXPORT_SYMBOL(omap_dss_stop_device);