blob: 2f7cee985cdddea5e75178da51ce875525f255ce [file] [log] [blame]
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001/*
2 * linux/drivers/video/omap2/dss/overlay.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 "OVERLAY"
24
25#include <linux/kernel.h>
26#include <linux/module.h>
27#include <linux/err.h>
28#include <linux/sysfs.h>
Tomi Valkeineneed07e02009-08-07 13:43:20 +030029#include <linux/platform_device.h>
30#include <linux/delay.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090031#include <linux/slab.h>
Tomi Valkeineneed07e02009-08-07 13:43:20 +030032
Tomi Valkeinena0b38cc2011-05-11 14:05:07 +030033#include <video/omapdss.h>
Tomi Valkeineneed07e02009-08-07 13:43:20 +030034
35#include "dss.h"
Archit Tanejaa0acb552010-09-15 19:20:00 +053036#include "dss_features.h"
Tomi Valkeineneed07e02009-08-07 13:43:20 +030037
38static int num_overlays;
Tomi Valkeinen58452342011-11-05 10:39:59 +020039static struct omap_overlay *overlays;
Tomi Valkeineneed07e02009-08-07 13:43:20 +030040
Tomi Valkeineneed07e02009-08-07 13:43:20 +030041int omap_dss_get_num_overlays(void)
42{
43 return num_overlays;
44}
45EXPORT_SYMBOL(omap_dss_get_num_overlays);
46
47struct omap_overlay *omap_dss_get_overlay(int num)
48{
Tomi Valkeinen58452342011-11-05 10:39:59 +020049 if (num >= num_overlays)
50 return NULL;
Tomi Valkeineneed07e02009-08-07 13:43:20 +030051
Tomi Valkeinen58452342011-11-05 10:39:59 +020052 return &overlays[num];
Tomi Valkeineneed07e02009-08-07 13:43:20 +030053}
54EXPORT_SYMBOL(omap_dss_get_overlay);
55
Tomi Valkeineneed07e02009-08-07 13:43:20 +030056void dss_init_overlays(struct platform_device *pdev)
57{
58 int i, r;
59
Tomi Valkeinen58452342011-11-05 10:39:59 +020060 num_overlays = dss_feat_get_num_ovls();
Tomi Valkeineneed07e02009-08-07 13:43:20 +030061
Tomi Valkeinen58452342011-11-05 10:39:59 +020062 overlays = kzalloc(sizeof(struct omap_overlay) * num_overlays,
63 GFP_KERNEL);
Tomi Valkeineneed07e02009-08-07 13:43:20 +030064
Tomi Valkeinen58452342011-11-05 10:39:59 +020065 BUG_ON(overlays == NULL);
Tomi Valkeineneed07e02009-08-07 13:43:20 +030066
Tomi Valkeinen58452342011-11-05 10:39:59 +020067 for (i = 0; i < num_overlays; ++i) {
68 struct omap_overlay *ovl = &overlays[i];
Tomi Valkeineneed07e02009-08-07 13:43:20 +030069
70 switch (i) {
71 case 0:
72 ovl->name = "gfx";
73 ovl->id = OMAP_DSS_GFX;
Tomi Valkeineneed07e02009-08-07 13:43:20 +030074 break;
75 case 1:
76 ovl->name = "vid1";
77 ovl->id = OMAP_DSS_VIDEO1;
Tomi Valkeineneed07e02009-08-07 13:43:20 +030078 break;
79 case 2:
80 ovl->name = "vid2";
81 ovl->id = OMAP_DSS_VIDEO2;
Tomi Valkeineneed07e02009-08-07 13:43:20 +030082 break;
Archit Tanejab8c095b2011-09-13 18:20:33 +053083 case 3:
84 ovl->name = "vid3";
85 ovl->id = OMAP_DSS_VIDEO3;
Archit Tanejab8c095b2011-09-13 18:20:33 +053086 break;
Tomi Valkeineneed07e02009-08-07 13:43:20 +030087 }
88
Tomi Valkeinen67019db2011-08-15 15:18:15 +030089 ovl->caps = dss_feat_get_overlay_caps(ovl->id);
Archit Tanejaa0acb552010-09-15 19:20:00 +053090 ovl->supported_modes =
91 dss_feat_get_supported_color_modes(ovl->id);
92
Tomi Valkeinen91691512012-08-06 14:40:00 +030093 r = dss_overlay_kobj_init(ovl, pdev);
Tomi Valkeinen58452342011-11-05 10:39:59 +020094 if (r)
Tomi Valkeineneed07e02009-08-07 13:43:20 +030095 DSSERR("failed to create sysfs file\n");
Tomi Valkeineneed07e02009-08-07 13:43:20 +030096 }
Tomi Valkeineneed07e02009-08-07 13:43:20 +030097}
98
Tomi Valkeineneed07e02009-08-07 13:43:20 +030099void dss_uninit_overlays(struct platform_device *pdev)
100{
Tomi Valkeinen58452342011-11-05 10:39:59 +0200101 int i;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300102
Tomi Valkeinen58452342011-11-05 10:39:59 +0200103 for (i = 0; i < num_overlays; ++i) {
104 struct omap_overlay *ovl = &overlays[i];
Tomi Valkeinen91691512012-08-06 14:40:00 +0300105 dss_overlay_kobj_uninit(ovl);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300106 }
107
Tomi Valkeinen58452342011-11-05 10:39:59 +0200108 kfree(overlays);
109 overlays = NULL;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300110 num_overlays = 0;
111}
112
Tomi Valkeinen54540d42011-12-13 13:18:52 +0200113int dss_ovl_simple_check(struct omap_overlay *ovl,
114 const struct omap_overlay_info *info)
115{
Tomi Valkeinen54540d42011-12-13 13:18:52 +0200116 if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0) {
117 if (info->out_width != 0 && info->width != info->out_width) {
118 DSSERR("check_overlay: overlay %d doesn't support "
119 "scaling\n", ovl->id);
120 return -EINVAL;
121 }
122
123 if (info->out_height != 0 && info->height != info->out_height) {
124 DSSERR("check_overlay: overlay %d doesn't support "
125 "scaling\n", ovl->id);
126 return -EINVAL;
127 }
128 }
129
130 if ((ovl->supported_modes & info->color_mode) == 0) {
131 DSSERR("check_overlay: overlay %d doesn't support mode %d\n",
132 ovl->id, info->color_mode);
133 return -EINVAL;
134 }
135
136 if (info->zorder >= omap_dss_get_num_overlays()) {
137 DSSERR("check_overlay: zorder %d too high\n", info->zorder);
138 return -EINVAL;
139 }
140
Chandrabhanu Mahapatra65e006f2012-05-11 19:19:55 +0530141 if (dss_feat_rotation_type_supported(info->rotation_type) == 0) {
142 DSSERR("check_overlay: rotation type %d not supported\n",
143 info->rotation_type);
144 return -EINVAL;
145 }
146
Tomi Valkeinen54540d42011-12-13 13:18:52 +0200147 return 0;
148}
149
Archit Taneja228b2132012-04-27 01:22:28 +0530150int dss_ovl_check(struct omap_overlay *ovl, struct omap_overlay_info *info,
151 const struct omap_video_timings *mgr_timings)
Tomi Valkeinen6ac48d12011-12-08 10:32:37 +0200152{
153 u16 outw, outh;
154 u16 dw, dh;
155
Archit Taneja228b2132012-04-27 01:22:28 +0530156 dw = mgr_timings->x_res;
157 dh = mgr_timings->y_res;
Tomi Valkeinen6ac48d12011-12-08 10:32:37 +0200158
159 if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0) {
160 outw = info->width;
161 outh = info->height;
162 } else {
163 if (info->out_width == 0)
164 outw = info->width;
165 else
166 outw = info->out_width;
167
168 if (info->out_height == 0)
169 outh = info->height;
170 else
171 outh = info->out_height;
172 }
173
174 if (dw < info->pos_x + outw) {
175 DSSERR("overlay %d horizontally not inside the display area "
176 "(%d + %d >= %d)\n",
177 ovl->id, info->pos_x, outw, dw);
178 return -EINVAL;
179 }
180
181 if (dh < info->pos_y + outh) {
182 DSSERR("overlay %d vertically not inside the display area "
183 "(%d + %d >= %d)\n",
184 ovl->id, info->pos_y, outh, dh);
185 return -EINVAL;
186 }
187
188 return 0;
189}
Archit Taneja6c6f5102012-06-25 14:58:48 +0530190
191/*
192 * Checks if replication logic should be used. Only use when overlay is in
193 * RGB12U or RGB16 mode, and video port width interface is 18bpp or 24bpp
194 */
195bool dss_ovl_use_replication(struct dss_lcd_mgr_config config,
196 enum omap_color_mode mode)
197{
198 if (mode != OMAP_DSS_COLOR_RGB12U && mode != OMAP_DSS_COLOR_RGB16)
199 return false;
200
201 return config.video_port_width > 16;
202}