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>
33 static ssize_t display_enabled_show(struct device *dev,
34 struct device_attribute *attr, char *buf)
36 struct omap_dss_device *dssdev = to_dss_device(dev);
37 bool enabled = dssdev->state != OMAP_DSS_DISPLAY_DISABLED;
39 return snprintf(buf, PAGE_SIZE, "%d\n", enabled);
42 static ssize_t display_enabled_store(struct device *dev,
43 struct device_attribute *attr,
44 const char *buf, size_t size)
46 struct omap_dss_device *dssdev = to_dss_device(dev);
49 enabled = simple_strtoul(buf, NULL, 10);
51 if (enabled != (dssdev->state != OMAP_DSS_DISPLAY_DISABLED)) {
53 r = dssdev->driver->enable(dssdev);
57 dssdev->driver->disable(dssdev);
64 static ssize_t display_upd_mode_show(struct device *dev,
65 struct device_attribute *attr, char *buf)
67 struct omap_dss_device *dssdev = to_dss_device(dev);
68 enum omap_dss_update_mode mode = OMAP_DSS_UPDATE_AUTO;
69 if (dssdev->driver->get_update_mode)
70 mode = dssdev->driver->get_update_mode(dssdev);
71 return snprintf(buf, PAGE_SIZE, "%d\n", mode);
74 static ssize_t display_upd_mode_store(struct device *dev,
75 struct device_attribute *attr,
76 const char *buf, size_t size)
78 struct omap_dss_device *dssdev = to_dss_device(dev);
80 enum omap_dss_update_mode mode;
82 if (!dssdev->driver->set_update_mode)
85 val = simple_strtoul(buf, NULL, 10);
88 case OMAP_DSS_UPDATE_DISABLED:
89 case OMAP_DSS_UPDATE_AUTO:
90 case OMAP_DSS_UPDATE_MANUAL:
91 mode = (enum omap_dss_update_mode)val;
97 r = dssdev->driver->set_update_mode(dssdev, mode);
104 static ssize_t display_tear_show(struct device *dev,
105 struct device_attribute *attr, char *buf)
107 struct omap_dss_device *dssdev = to_dss_device(dev);
108 return snprintf(buf, PAGE_SIZE, "%d\n",
109 dssdev->driver->get_te ?
110 dssdev->driver->get_te(dssdev) : 0);
113 static ssize_t display_tear_store(struct device *dev,
114 struct device_attribute *attr, const char *buf, size_t size)
116 struct omap_dss_device *dssdev = to_dss_device(dev);
120 if (!dssdev->driver->enable_te || !dssdev->driver->get_te)
123 te = simple_strtoul(buf, NULL, 0);
125 r = dssdev->driver->enable_te(dssdev, te);
132 static ssize_t display_timings_show(struct device *dev,
133 struct device_attribute *attr, char *buf)
135 struct omap_dss_device *dssdev = to_dss_device(dev);
136 struct omap_video_timings t;
138 if (!dssdev->driver->get_timings)
141 dssdev->driver->get_timings(dssdev, &t);
143 return snprintf(buf, PAGE_SIZE, "%u,%u/%u/%u/%u,%u/%u/%u/%u\n",
145 t.x_res, t.hfp, t.hbp, t.hsw,
146 t.y_res, t.vfp, t.vbp, t.vsw);
149 static ssize_t display_timings_store(struct device *dev,
150 struct device_attribute *attr, const char *buf, size_t size)
152 struct omap_dss_device *dssdev = to_dss_device(dev);
153 struct omap_video_timings t;
156 if (!dssdev->driver->set_timings || !dssdev->driver->check_timings)
160 #ifdef CONFIG_OMAP2_DSS_VENC
161 if (strncmp("pal", buf, 3) == 0) {
162 t = omap_dss_pal_timings;
164 } else if (strncmp("ntsc", buf, 4) == 0) {
165 t = omap_dss_ntsc_timings;
169 if (!found && sscanf(buf, "%u,%hu/%hu/%hu/%hu,%hu/%hu/%hu/%hu",
171 &t.x_res, &t.hfp, &t.hbp, &t.hsw,
172 &t.y_res, &t.vfp, &t.vbp, &t.vsw) != 9)
175 r = dssdev->driver->check_timings(dssdev, &t);
179 dssdev->driver->set_timings(dssdev, &t);
184 static ssize_t display_rotate_show(struct device *dev,
185 struct device_attribute *attr, char *buf)
187 struct omap_dss_device *dssdev = to_dss_device(dev);
189 if (!dssdev->driver->get_rotate)
191 rotate = dssdev->driver->get_rotate(dssdev);
192 return snprintf(buf, PAGE_SIZE, "%u\n", rotate);
195 static ssize_t display_rotate_store(struct device *dev,
196 struct device_attribute *attr, const char *buf, size_t size)
198 struct omap_dss_device *dssdev = to_dss_device(dev);
202 if (!dssdev->driver->set_rotate || !dssdev->driver->get_rotate)
205 rot = simple_strtoul(buf, NULL, 0);
207 r = dssdev->driver->set_rotate(dssdev, rot);
214 static ssize_t display_mirror_show(struct device *dev,
215 struct device_attribute *attr, char *buf)
217 struct omap_dss_device *dssdev = to_dss_device(dev);
219 if (!dssdev->driver->get_mirror)
221 mirror = dssdev->driver->get_mirror(dssdev);
222 return snprintf(buf, PAGE_SIZE, "%u\n", mirror);
225 static ssize_t display_mirror_store(struct device *dev,
226 struct device_attribute *attr, const char *buf, size_t size)
228 struct omap_dss_device *dssdev = to_dss_device(dev);
229 unsigned long mirror;
232 if (!dssdev->driver->set_mirror || !dssdev->driver->get_mirror)
235 mirror = simple_strtoul(buf, NULL, 0);
237 r = dssdev->driver->set_mirror(dssdev, mirror);
244 static ssize_t display_wss_show(struct device *dev,
245 struct device_attribute *attr, char *buf)
247 struct omap_dss_device *dssdev = to_dss_device(dev);
250 if (!dssdev->driver->get_wss)
253 wss = dssdev->driver->get_wss(dssdev);
255 return snprintf(buf, PAGE_SIZE, "0x%05x\n", wss);
258 static ssize_t display_wss_store(struct device *dev,
259 struct device_attribute *attr, const char *buf, size_t size)
261 struct omap_dss_device *dssdev = to_dss_device(dev);
265 if (!dssdev->driver->get_wss || !dssdev->driver->set_wss)
268 if (strict_strtoul(buf, 0, &wss))
274 r = dssdev->driver->set_wss(dssdev, wss);
281 static DEVICE_ATTR(enabled, S_IRUGO|S_IWUSR,
282 display_enabled_show, display_enabled_store);
283 static DEVICE_ATTR(update_mode, S_IRUGO|S_IWUSR,
284 display_upd_mode_show, display_upd_mode_store);
285 static DEVICE_ATTR(tear_elim, S_IRUGO|S_IWUSR,
286 display_tear_show, display_tear_store);
287 static DEVICE_ATTR(timings, S_IRUGO|S_IWUSR,
288 display_timings_show, display_timings_store);
289 static DEVICE_ATTR(rotate, S_IRUGO|S_IWUSR,
290 display_rotate_show, display_rotate_store);
291 static DEVICE_ATTR(mirror, S_IRUGO|S_IWUSR,
292 display_mirror_show, display_mirror_store);
293 static DEVICE_ATTR(wss, S_IRUGO|S_IWUSR,
294 display_wss_show, display_wss_store);
296 static struct device_attribute *display_sysfs_attrs[] = {
298 &dev_attr_update_mode,
307 void omapdss_default_get_resolution(struct omap_dss_device *dssdev,
308 u16 *xres, u16 *yres)
310 *xres = dssdev->panel.timings.x_res;
311 *yres = dssdev->panel.timings.y_res;
313 EXPORT_SYMBOL(omapdss_default_get_resolution);
315 void default_get_overlay_fifo_thresholds(enum omap_plane plane,
316 u32 fifo_size, enum omap_burst_size *burst_size,
317 u32 *fifo_low, u32 *fifo_high)
319 unsigned burst_size_bytes;
321 *burst_size = OMAP_DSS_BURST_16x32;
322 burst_size_bytes = 16 * 32 / 8;
324 *fifo_high = fifo_size - 1;
325 *fifo_low = fifo_size - burst_size_bytes;
328 int omapdss_default_get_recommended_bpp(struct omap_dss_device *dssdev)
330 switch (dssdev->type) {
331 case OMAP_DISPLAY_TYPE_DPI:
332 if (dssdev->phy.dpi.data_lines == 24)
337 case OMAP_DISPLAY_TYPE_DBI:
338 case OMAP_DISPLAY_TYPE_DSI:
339 if (dssdev->ctrl.pixel_size == 24)
343 case OMAP_DISPLAY_TYPE_VENC:
344 case OMAP_DISPLAY_TYPE_SDI:
345 case OMAP_DISPLAY_TYPE_HDMI:
351 EXPORT_SYMBOL(omapdss_default_get_recommended_bpp);
353 /* Checks if replication logic should be used. Only use for active matrix,
354 * when overlay is in RGB12U or RGB16 mode, and LCD interface is
356 bool dss_use_replication(struct omap_dss_device *dssdev,
357 enum omap_color_mode mode)
361 if (mode != OMAP_DSS_COLOR_RGB12U && mode != OMAP_DSS_COLOR_RGB16)
364 if (dssdev->type == OMAP_DISPLAY_TYPE_DPI &&
365 (dssdev->panel.config & OMAP_DSS_LCD_TFT) == 0)
368 switch (dssdev->type) {
369 case OMAP_DISPLAY_TYPE_DPI:
370 bpp = dssdev->phy.dpi.data_lines;
372 case OMAP_DISPLAY_TYPE_HDMI:
373 case OMAP_DISPLAY_TYPE_VENC:
374 case OMAP_DISPLAY_TYPE_SDI:
377 case OMAP_DISPLAY_TYPE_DBI:
378 case OMAP_DISPLAY_TYPE_DSI:
379 bpp = dssdev->ctrl.pixel_size;
388 void dss_init_device(struct platform_device *pdev,
389 struct omap_dss_device *dssdev)
391 struct device_attribute *attr;
395 switch (dssdev->type) {
396 #ifdef CONFIG_OMAP2_DSS_DPI
397 case OMAP_DISPLAY_TYPE_DPI:
398 r = dpi_init_display(dssdev);
401 #ifdef CONFIG_OMAP2_DSS_RFBI
402 case OMAP_DISPLAY_TYPE_DBI:
403 r = rfbi_init_display(dssdev);
406 #ifdef CONFIG_OMAP2_DSS_VENC
407 case OMAP_DISPLAY_TYPE_VENC:
408 r = venc_init_display(dssdev);
411 #ifdef CONFIG_OMAP2_DSS_SDI
412 case OMAP_DISPLAY_TYPE_SDI:
413 r = sdi_init_display(dssdev);
416 #ifdef CONFIG_OMAP2_DSS_DSI
417 case OMAP_DISPLAY_TYPE_DSI:
418 r = dsi_init_display(dssdev);
421 case OMAP_DISPLAY_TYPE_HDMI:
422 r = hdmi_init_display(dssdev);
425 DSSERR("Support for display '%s' not compiled in.\n",
431 DSSERR("failed to init display %s\n", dssdev->name);
435 /* create device sysfs files */
437 while ((attr = display_sysfs_attrs[i++]) != NULL) {
438 r = device_create_file(&dssdev->dev, attr);
440 DSSERR("failed to create sysfs file\n");
443 /* create display? sysfs links */
444 r = sysfs_create_link(&pdev->dev.kobj, &dssdev->dev.kobj,
445 dev_name(&dssdev->dev));
447 DSSERR("failed to create sysfs display link\n");
450 void dss_uninit_device(struct platform_device *pdev,
451 struct omap_dss_device *dssdev)
453 struct device_attribute *attr;
456 sysfs_remove_link(&pdev->dev.kobj, dev_name(&dssdev->dev));
458 while ((attr = display_sysfs_attrs[i++]) != NULL)
459 device_remove_file(&dssdev->dev, attr);
462 dssdev->manager->unset_device(dssdev->manager);
465 static int dss_suspend_device(struct device *dev, void *data)
468 struct omap_dss_device *dssdev = to_dss_device(dev);
470 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
471 dssdev->activate_after_resume = false;
475 if (!dssdev->driver->suspend) {
476 DSSERR("display '%s' doesn't implement suspend\n",
481 r = dssdev->driver->suspend(dssdev);
485 dssdev->activate_after_resume = true;
490 int dss_suspend_all_devices(void)
493 struct bus_type *bus = dss_get_bus();
495 r = bus_for_each_dev(bus, NULL, NULL, dss_suspend_device);
497 /* resume all displays that were suspended */
498 dss_resume_all_devices();
505 static int dss_resume_device(struct device *dev, void *data)
508 struct omap_dss_device *dssdev = to_dss_device(dev);
510 if (dssdev->activate_after_resume && dssdev->driver->resume) {
511 r = dssdev->driver->resume(dssdev);
516 dssdev->activate_after_resume = false;
521 int dss_resume_all_devices(void)
523 struct bus_type *bus = dss_get_bus();
525 return bus_for_each_dev(bus, NULL, NULL, dss_resume_device);
528 static int dss_disable_device(struct device *dev, void *data)
530 struct omap_dss_device *dssdev = to_dss_device(dev);
532 if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED)
533 dssdev->driver->disable(dssdev);
538 void dss_disable_all_devices(void)
540 struct bus_type *bus = dss_get_bus();
541 bus_for_each_dev(bus, NULL, NULL, dss_disable_device);
545 void omap_dss_get_device(struct omap_dss_device *dssdev)
547 get_device(&dssdev->dev);
549 EXPORT_SYMBOL(omap_dss_get_device);
551 void omap_dss_put_device(struct omap_dss_device *dssdev)
553 put_device(&dssdev->dev);
555 EXPORT_SYMBOL(omap_dss_put_device);
557 /* ref count of the found device is incremented. ref count
558 * of from-device is decremented. */
559 struct omap_dss_device *omap_dss_get_next_device(struct omap_dss_device *from)
562 struct device *dev_start = NULL;
563 struct omap_dss_device *dssdev = NULL;
565 int match(struct device *dev, void *data)
571 dev_start = &from->dev;
572 dev = bus_find_device(dss_get_bus(), dev_start, NULL, match);
574 dssdev = to_dss_device(dev);
576 put_device(&from->dev);
580 EXPORT_SYMBOL(omap_dss_get_next_device);
582 struct omap_dss_device *omap_dss_find_device(void *data,
583 int (*match)(struct omap_dss_device *dssdev, void *data))
585 struct omap_dss_device *dssdev = NULL;
587 while ((dssdev = omap_dss_get_next_device(dssdev)) != NULL) {
588 if (match(dssdev, data))
594 EXPORT_SYMBOL(omap_dss_find_device);
596 int omap_dss_start_device(struct omap_dss_device *dssdev)
598 if (!dssdev->driver) {
599 DSSDBG("no driver\n");
603 if (!try_module_get(dssdev->dev.driver->owner)) {
609 EXPORT_SYMBOL(omap_dss_start_device);
611 void omap_dss_stop_device(struct omap_dss_device *dssdev)
613 module_put(dssdev->dev.driver->owner);
615 EXPORT_SYMBOL(omap_dss_stop_device);