OMAPDSS: AnalogTV: Add ops
[deliverable/linux.git] / drivers / video / omap2 / dss / overlay.c
CommitLineData
eed07e0e
TV
1/*
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>
eed07e0e
TV
29#include <linux/platform_device.h>
30#include <linux/delay.h>
5a0e3ad6 31#include <linux/slab.h>
eed07e0e 32
a0b38cc4 33#include <video/omapdss.h>
eed07e0e
TV
34
35#include "dss.h"
a0acb557 36#include "dss_features.h"
eed07e0e
TV
37
38static int num_overlays;
58452341 39static struct omap_overlay *overlays;
eed07e0e 40
eed07e0e
TV
41int 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{
58452341
TV
49 if (num >= num_overlays)
50 return NULL;
eed07e0e 51
58452341 52 return &overlays[num];
eed07e0e
TV
53}
54EXPORT_SYMBOL(omap_dss_get_overlay);
55
eed07e0e
TV
56void dss_init_overlays(struct platform_device *pdev)
57{
58 int i, r;
59
58452341 60 num_overlays = dss_feat_get_num_ovls();
eed07e0e 61
58452341
TV
62 overlays = kzalloc(sizeof(struct omap_overlay) * num_overlays,
63 GFP_KERNEL);
eed07e0e 64
58452341 65 BUG_ON(overlays == NULL);
eed07e0e 66
58452341
TV
67 for (i = 0; i < num_overlays; ++i) {
68 struct omap_overlay *ovl = &overlays[i];
eed07e0e
TV
69
70 switch (i) {
71 case 0:
72 ovl->name = "gfx";
73 ovl->id = OMAP_DSS_GFX;
eed07e0e
TV
74 break;
75 case 1:
76 ovl->name = "vid1";
77 ovl->id = OMAP_DSS_VIDEO1;
eed07e0e
TV
78 break;
79 case 2:
80 ovl->name = "vid2";
81 ovl->id = OMAP_DSS_VIDEO2;
eed07e0e 82 break;
b8c095b4
AT
83 case 3:
84 ovl->name = "vid3";
85 ovl->id = OMAP_DSS_VIDEO3;
b8c095b4 86 break;
eed07e0e
TV
87 }
88
67019db8 89 ovl->caps = dss_feat_get_overlay_caps(ovl->id);
a0acb557
AT
90 ovl->supported_modes =
91 dss_feat_get_supported_color_modes(ovl->id);
92
91691516 93 r = dss_overlay_kobj_init(ovl, pdev);
58452341 94 if (r)
eed07e0e 95 DSSERR("failed to create sysfs file\n");
eed07e0e 96 }
eed07e0e
TV
97}
98
eed07e0e
TV
99void dss_uninit_overlays(struct platform_device *pdev)
100{
58452341
TV
101 int i;
102
103 for (i = 0; i < num_overlays; ++i) {
104 struct omap_overlay *ovl = &overlays[i];
91691516 105 dss_overlay_kobj_uninit(ovl);
eed07e0e
TV
106 }
107
58452341
TV
108 kfree(overlays);
109 overlays = NULL;
eed07e0e
TV
110 num_overlays = 0;
111}
112
54540d41
TV
113int dss_ovl_simple_check(struct omap_overlay *ovl,
114 const struct omap_overlay_info *info)
115{
116 if (info->paddr == 0) {
117 DSSERR("check_overlay: paddr cannot be 0\n");
118 return -EINVAL;
119 }
120
121 if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0) {
122 if (info->out_width != 0 && info->width != info->out_width) {
123 DSSERR("check_overlay: overlay %d doesn't support "
124 "scaling\n", ovl->id);
125 return -EINVAL;
126 }
127
128 if (info->out_height != 0 && info->height != info->out_height) {
129 DSSERR("check_overlay: overlay %d doesn't support "
130 "scaling\n", ovl->id);
131 return -EINVAL;
132 }
133 }
134
135 if ((ovl->supported_modes & info->color_mode) == 0) {
136 DSSERR("check_overlay: overlay %d doesn't support mode %d\n",
137 ovl->id, info->color_mode);
138 return -EINVAL;
139 }
140
141 if (info->zorder >= omap_dss_get_num_overlays()) {
142 DSSERR("check_overlay: zorder %d too high\n", info->zorder);
143 return -EINVAL;
144 }
145
65e006ff
CM
146 if (dss_feat_rotation_type_supported(info->rotation_type) == 0) {
147 DSSERR("check_overlay: rotation type %d not supported\n",
148 info->rotation_type);
149 return -EINVAL;
150 }
151
54540d41
TV
152 return 0;
153}
154
228b2134
AT
155int dss_ovl_check(struct omap_overlay *ovl, struct omap_overlay_info *info,
156 const struct omap_video_timings *mgr_timings)
6ac48d1e
TV
157{
158 u16 outw, outh;
159 u16 dw, dh;
160
228b2134
AT
161 dw = mgr_timings->x_res;
162 dh = mgr_timings->y_res;
6ac48d1e
TV
163
164 if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0) {
165 outw = info->width;
166 outh = info->height;
167 } else {
168 if (info->out_width == 0)
169 outw = info->width;
170 else
171 outw = info->out_width;
172
173 if (info->out_height == 0)
174 outh = info->height;
175 else
176 outh = info->out_height;
177 }
178
179 if (dw < info->pos_x + outw) {
180 DSSERR("overlay %d horizontally not inside the display area "
181 "(%d + %d >= %d)\n",
182 ovl->id, info->pos_x, outw, dw);
183 return -EINVAL;
184 }
185
186 if (dh < info->pos_y + outh) {
187 DSSERR("overlay %d vertically not inside the display area "
188 "(%d + %d >= %d)\n",
189 ovl->id, info->pos_y, outh, dh);
190 return -EINVAL;
191 }
192
193 return 0;
194}
6c6f510a
AT
195
196/*
197 * Checks if replication logic should be used. Only use when overlay is in
198 * RGB12U or RGB16 mode, and video port width interface is 18bpp or 24bpp
199 */
200bool dss_ovl_use_replication(struct dss_lcd_mgr_config config,
201 enum omap_color_mode mode)
202{
203 if (mode != OMAP_DSS_COLOR_RGB12U && mode != OMAP_DSS_COLOR_RGB16)
204 return false;
205
206 return config.video_port_width > 16;
207}
This page took 0.216322 seconds and 5 git commands to generate.