Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
overlay.c
Go to the documentation of this file.
1 /*
2  * linux/drivers/video/omap2/dss/overlay.c
3  *
4  * Copyright (C) 2009 Nokia Corporation
5  * Author: Tomi Valkeinen <[email protected]>
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>
29 #include <linux/platform_device.h>
30 #include <linux/delay.h>
31 #include <linux/slab.h>
32 
33 #include <video/omapdss.h>
34 
35 #include "dss.h"
36 #include "dss_features.h"
37 
38 static int num_overlays;
39 static struct omap_overlay *overlays;
40 
41 static inline struct omap_dss_device *dss_ovl_get_device(struct omap_overlay *ovl)
42 {
43  return ovl->manager ?
44  (ovl->manager->output ? ovl->manager->output->device : NULL) :
45  NULL;
46 }
47 
49 {
50  return num_overlays;
51 }
53 
55 {
56  if (num >= num_overlays)
57  return NULL;
58 
59  return &overlays[num];
60 }
62 
64 {
65  int i, r;
66 
67  num_overlays = dss_feat_get_num_ovls();
68 
69  overlays = kzalloc(sizeof(struct omap_overlay) * num_overlays,
70  GFP_KERNEL);
71 
72  BUG_ON(overlays == NULL);
73 
74  for (i = 0; i < num_overlays; ++i) {
75  struct omap_overlay *ovl = &overlays[i];
76 
77  switch (i) {
78  case 0:
79  ovl->name = "gfx";
80  ovl->id = OMAP_DSS_GFX;
81  break;
82  case 1:
83  ovl->name = "vid1";
84  ovl->id = OMAP_DSS_VIDEO1;
85  break;
86  case 2:
87  ovl->name = "vid2";
88  ovl->id = OMAP_DSS_VIDEO2;
89  break;
90  case 3:
91  ovl->name = "vid3";
92  ovl->id = OMAP_DSS_VIDEO3;
93  break;
94  }
95 
97  ovl->enable = &dss_ovl_enable;
98  ovl->disable = &dss_ovl_disable;
104  ovl->get_device = &dss_ovl_get_device;
105 
106  ovl->caps = dss_feat_get_overlay_caps(ovl->id);
107  ovl->supported_modes =
109 
110  r = dss_overlay_kobj_init(ovl, pdev);
111  if (r)
112  DSSERR("failed to create sysfs file\n");
113  }
114 }
115 
117 {
118  int i;
119 
120  for (i = 0; i < num_overlays; ++i) {
121  struct omap_overlay *ovl = &overlays[i];
123  }
124 
125  kfree(overlays);
126  overlays = NULL;
127  num_overlays = 0;
128 }
129 
131  const struct omap_overlay_info *info)
132 {
133  if (info->paddr == 0) {
134  DSSERR("check_overlay: paddr cannot be 0\n");
135  return -EINVAL;
136  }
137 
138  if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0) {
139  if (info->out_width != 0 && info->width != info->out_width) {
140  DSSERR("check_overlay: overlay %d doesn't support "
141  "scaling\n", ovl->id);
142  return -EINVAL;
143  }
144 
145  if (info->out_height != 0 && info->height != info->out_height) {
146  DSSERR("check_overlay: overlay %d doesn't support "
147  "scaling\n", ovl->id);
148  return -EINVAL;
149  }
150  }
151 
152  if ((ovl->supported_modes & info->color_mode) == 0) {
153  DSSERR("check_overlay: overlay %d doesn't support mode %d\n",
154  ovl->id, info->color_mode);
155  return -EINVAL;
156  }
157 
158  if (info->zorder >= omap_dss_get_num_overlays()) {
159  DSSERR("check_overlay: zorder %d too high\n", info->zorder);
160  return -EINVAL;
161  }
162 
164  DSSERR("check_overlay: rotation type %d not supported\n",
165  info->rotation_type);
166  return -EINVAL;
167  }
168 
169  return 0;
170 }
171 
173  const struct omap_video_timings *mgr_timings)
174 {
175  u16 outw, outh;
176  u16 dw, dh;
177 
178  dw = mgr_timings->x_res;
179  dh = mgr_timings->y_res;
180 
181  if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0) {
182  outw = info->width;
183  outh = info->height;
184  } else {
185  if (info->out_width == 0)
186  outw = info->width;
187  else
188  outw = info->out_width;
189 
190  if (info->out_height == 0)
191  outh = info->height;
192  else
193  outh = info->out_height;
194  }
195 
196  if (dw < info->pos_x + outw) {
197  DSSERR("overlay %d horizontally not inside the display area "
198  "(%d + %d >= %d)\n",
199  ovl->id, info->pos_x, outw, dw);
200  return -EINVAL;
201  }
202 
203  if (dh < info->pos_y + outh) {
204  DSSERR("overlay %d vertically not inside the display area "
205  "(%d + %d >= %d)\n",
206  ovl->id, info->pos_y, outh, dh);
207  return -EINVAL;
208  }
209 
210  return 0;
211 }
212 
213 /*
214  * Checks if replication logic should be used. Only use when overlay is in
215  * RGB12U or RGB16 mode, and video port width interface is 18bpp or 24bpp
216  */
218  enum omap_color_mode mode)
219 {
220  if (mode != OMAP_DSS_COLOR_RGB12U && mode != OMAP_DSS_COLOR_RGB16)
221  return false;
222 
223  return config.video_port_width > 16;
224 }