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;
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->set_timings(dssdev, &t);
150 static ssize_t display_rotate_show(struct device *dev,
151 struct device_attribute *attr, char *buf)
153 struct omap_dss_device *dssdev = to_dss_device(dev);
155 if (!dssdev->driver->get_rotate)
157 rotate = dssdev->driver->get_rotate(dssdev);
158 return snprintf(buf, PAGE_SIZE, "%u\n", rotate);
161 static ssize_t display_rotate_store(struct device *dev,
162 struct device_attribute *attr, const char *buf, size_t size)
164 struct omap_dss_device *dssdev = to_dss_device(dev);
167 if (!dssdev->driver->set_rotate || !dssdev->driver->get_rotate)
170 r = kstrtoint(buf, 0, &rot);
174 r = dssdev->driver->set_rotate(dssdev, rot);
181 static ssize_t display_mirror_show(struct device *dev,
182 struct device_attribute *attr, char *buf)
184 struct omap_dss_device *dssdev = to_dss_device(dev);
186 if (!dssdev->driver->get_mirror)
188 mirror = dssdev->driver->get_mirror(dssdev);
189 return snprintf(buf, PAGE_SIZE, "%u\n", mirror);
192 static ssize_t display_mirror_store(struct device *dev,
193 struct device_attribute *attr, const char *buf, size_t size)
195 struct omap_dss_device *dssdev = to_dss_device(dev);
199 if (!dssdev->driver->set_mirror || !dssdev->driver->get_mirror)
202 r = strtobool(buf, &mirror);
206 r = dssdev->driver->set_mirror(dssdev, mirror);
213 static ssize_t display_wss_show(struct device *dev,
214 struct device_attribute *attr, char *buf)
216 struct omap_dss_device *dssdev = to_dss_device(dev);
219 if (!dssdev->driver->get_wss)
222 wss = dssdev->driver->get_wss(dssdev);
224 return snprintf(buf, PAGE_SIZE, "0x%05x\n", wss);
227 static ssize_t display_wss_store(struct device *dev,
228 struct device_attribute *attr, const char *buf, size_t size)
230 struct omap_dss_device *dssdev = to_dss_device(dev);
234 if (!dssdev->driver->get_wss || !dssdev->driver->set_wss)
237 r = kstrtou32(buf, 0, &wss);
244 r = dssdev->driver->set_wss(dssdev, wss);
251 #include <linux/ctype.h>
253 static ssize_t display_dss_gamma_store(struct device *dev,
254 struct device_attribute *attr, const char *buf, size_t size)
256 struct omap_dss_device *dssdev = to_dss_device(dev);
257 unsigned int table[256];
261 for (i = 0; i < 256; ) {
262 table[i++] = simple_strtoul(buf, &end, 0);
263 while (isspace(*end))
270 if (i == 1 && table[0] == 0)
271 dispc_set_gamma_table(NULL, 0);
273 dev_err(dev, "not enough gamma values supplied (%d)\n", i);
274 dispc_set_gamma_table(NULL, 0);
276 dispc_set_gamma_table(table, 256 * 4);
278 dispc_mgr_go(dssdev->manager->id);
283 static DEVICE_ATTR(enabled, S_IRUGO|S_IWUSR,
284 display_enabled_show, display_enabled_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);
295 static DEVICE_ATTR(dss_gamma, S_IRUGO|S_IWUSR,
296 NULL, display_dss_gamma_store);
298 static struct device_attribute *display_sysfs_attrs[] = {
308 void omapdss_default_get_resolution(struct omap_dss_device *dssdev,
309 u16 *xres, u16 *yres)
311 *xres = dssdev->panel.timings.x_res;
312 *yres = dssdev->panel.timings.y_res;
314 EXPORT_SYMBOL(omapdss_default_get_resolution);
316 void default_get_overlay_fifo_thresholds(enum omap_plane plane,
317 u32 fifo_size, u32 burst_size,
318 u32 *fifo_low, u32 *fifo_high)
320 unsigned buf_unit = dss_feat_get_buffer_size_unit();
322 *fifo_high = fifo_size - buf_unit;
323 *fifo_low = fifo_size - burst_size;
326 int omapdss_default_get_recommended_bpp(struct omap_dss_device *dssdev)
328 switch (dssdev->type) {
329 case OMAP_DISPLAY_TYPE_DPI:
330 if (dssdev->phy.dpi.data_lines == 24)
335 case OMAP_DISPLAY_TYPE_DBI:
336 if (dssdev->ctrl.pixel_size == 24)
340 case OMAP_DISPLAY_TYPE_DSI:
341 if (dsi_get_pixel_size(dssdev->panel.dsi_pix_fmt) > 16)
345 case OMAP_DISPLAY_TYPE_VENC:
346 case OMAP_DISPLAY_TYPE_SDI:
347 case OMAP_DISPLAY_TYPE_HDMI:
353 EXPORT_SYMBOL(omapdss_default_get_recommended_bpp);
355 void omapdss_default_get_timings(struct omap_dss_device *dssdev,
356 struct omap_video_timings *timings)
358 *timings = dssdev->panel.timings;
360 EXPORT_SYMBOL(omapdss_default_get_timings);
362 /* Checks if replication logic should be used. Only use for active matrix,
363 * when overlay is in RGB12U or RGB16 mode, and LCD interface is
365 bool dss_use_replication(struct omap_dss_device *dssdev,
366 enum omap_color_mode mode)
370 if (mode != OMAP_DSS_COLOR_RGB12U && mode != OMAP_DSS_COLOR_RGB16)
373 if (dssdev->type == OMAP_DISPLAY_TYPE_DPI &&
374 (dssdev->panel.config & OMAP_DSS_LCD_TFT) == 0)
377 switch (dssdev->type) {
378 case OMAP_DISPLAY_TYPE_DPI:
379 bpp = dssdev->phy.dpi.data_lines;
381 case OMAP_DISPLAY_TYPE_HDMI:
382 case OMAP_DISPLAY_TYPE_VENC:
383 case OMAP_DISPLAY_TYPE_SDI:
386 case OMAP_DISPLAY_TYPE_DBI:
387 bpp = dssdev->ctrl.pixel_size;
389 case OMAP_DISPLAY_TYPE_DSI:
390 bpp = dsi_get_pixel_size(dssdev->panel.dsi_pix_fmt);
399 void dss_init_device(struct platform_device *pdev,
400 struct omap_dss_device *dssdev)
402 struct device_attribute *attr;
406 switch (dssdev->type) {
407 #ifdef CONFIG_OMAP2_DSS_DPI
408 case OMAP_DISPLAY_TYPE_DPI:
409 r = dpi_init_display(dssdev);
412 #ifdef CONFIG_OMAP2_DSS_RFBI
413 case OMAP_DISPLAY_TYPE_DBI:
414 r = rfbi_init_display(dssdev);
417 #ifdef CONFIG_OMAP2_DSS_VENC
418 case OMAP_DISPLAY_TYPE_VENC:
419 r = venc_init_display(dssdev);
422 #ifdef CONFIG_OMAP2_DSS_SDI
423 case OMAP_DISPLAY_TYPE_SDI:
424 r = sdi_init_display(dssdev);
427 #ifdef CONFIG_OMAP2_DSS_DSI
428 case OMAP_DISPLAY_TYPE_DSI:
429 r = dsi_init_display(dssdev);
432 case OMAP_DISPLAY_TYPE_HDMI:
433 r = hdmi_init_display(dssdev);
436 DSSERR("Support for display '%s' not compiled in.\n",
442 DSSERR("failed to init display %s\n", dssdev->name);
446 /* create device sysfs files */
448 while ((attr = display_sysfs_attrs[i++]) != NULL) {
449 r = device_create_file(&dssdev->dev, attr);
451 DSSERR("failed to create sysfs file\n");
454 if (dssdev->channel == OMAP_DSS_CHANNEL_LCD) {
455 r = device_create_file(&dssdev->dev, &dev_attr_dss_gamma);
457 DSSERR("failed to create sysfs file\n");
460 /* create display? sysfs links */
461 r = sysfs_create_link(&pdev->dev.kobj, &dssdev->dev.kobj,
462 dev_name(&dssdev->dev));
464 DSSERR("failed to create sysfs display link\n");
467 void dss_uninit_device(struct platform_device *pdev,
468 struct omap_dss_device *dssdev)
470 struct device_attribute *attr;
473 sysfs_remove_link(&pdev->dev.kobj, dev_name(&dssdev->dev));
475 while ((attr = display_sysfs_attrs[i++]) != NULL)
476 device_remove_file(&dssdev->dev, attr);
479 dssdev->manager->unset_device(dssdev->manager);
482 static int dss_suspend_device(struct device *dev, void *data)
485 struct omap_dss_device *dssdev = to_dss_device(dev);
487 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
488 dssdev->activate_after_resume = false;
492 if (!dssdev->driver->suspend) {
493 DSSERR("display '%s' doesn't implement suspend\n",
498 r = dssdev->driver->suspend(dssdev);
502 dssdev->activate_after_resume = true;
507 int dss_suspend_all_devices(void)
510 struct bus_type *bus = dss_get_bus();
512 r = bus_for_each_dev(bus, NULL, NULL, dss_suspend_device);
514 /* resume all displays that were suspended */
515 dss_resume_all_devices();
522 static int dss_resume_device(struct device *dev, void *data)
525 struct omap_dss_device *dssdev = to_dss_device(dev);
527 if (dssdev->activate_after_resume && dssdev->driver->resume) {
528 r = dssdev->driver->resume(dssdev);
533 dssdev->activate_after_resume = false;
538 int dss_resume_all_devices(void)
540 struct bus_type *bus = dss_get_bus();
542 return bus_for_each_dev(bus, NULL, NULL, dss_resume_device);
545 static int dss_disable_device(struct device *dev, void *data)
547 struct omap_dss_device *dssdev = to_dss_device(dev);
549 if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED)
550 dssdev->driver->disable(dssdev);
555 void dss_disable_all_devices(void)
557 struct bus_type *bus = dss_get_bus();
558 bus_for_each_dev(bus, NULL, NULL, dss_disable_device);
562 void omap_dss_get_device(struct omap_dss_device *dssdev)
564 get_device(&dssdev->dev);
566 EXPORT_SYMBOL(omap_dss_get_device);
568 void omap_dss_put_device(struct omap_dss_device *dssdev)
570 put_device(&dssdev->dev);
572 EXPORT_SYMBOL(omap_dss_put_device);
574 /* ref count of the found device is incremented. ref count
575 * of from-device is decremented. */
576 struct omap_dss_device *omap_dss_get_next_device(struct omap_dss_device *from)
579 struct device *dev_start = NULL;
580 struct omap_dss_device *dssdev = NULL;
582 int match(struct device *dev, void *data)
588 dev_start = &from->dev;
589 dev = bus_find_device(dss_get_bus(), dev_start, NULL, match);
591 dssdev = to_dss_device(dev);
593 put_device(&from->dev);
597 EXPORT_SYMBOL(omap_dss_get_next_device);
599 struct omap_dss_device *omap_dss_find_device(void *data,
600 int (*match)(struct omap_dss_device *dssdev, void *data))
602 struct omap_dss_device *dssdev = NULL;
604 while ((dssdev = omap_dss_get_next_device(dssdev)) != NULL) {
605 if (match(dssdev, data))
611 EXPORT_SYMBOL(omap_dss_find_device);
613 int omap_dss_start_device(struct omap_dss_device *dssdev)
615 if (!dssdev->driver) {
616 DSSDBG("no driver\n");
620 if (!try_module_get(dssdev->dev.driver->owner)) {
626 EXPORT_SYMBOL(omap_dss_start_device);
628 void omap_dss_stop_device(struct omap_dss_device *dssdev)
630 module_put(dssdev->dev.driver->owner);
632 EXPORT_SYMBOL(omap_dss_stop_device);