Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 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> |
| 29 | #include <linux/kobject.h> |
| 30 | #include <linux/platform_device.h> |
| 31 | #include <linux/delay.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 32 | #include <linux/slab.h> |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 33 | |
Tomi Valkeinen | a0b38cc | 2011-05-11 14:05:07 +0300 | [diff] [blame] | 34 | #include <video/omapdss.h> |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 35 | #include <plat/cpu.h> |
| 36 | |
| 37 | #include "dss.h" |
Archit Taneja | a0acb55 | 2010-09-15 19:20:00 +0530 | [diff] [blame] | 38 | #include "dss_features.h" |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 39 | |
| 40 | static int num_overlays; |
| 41 | static struct list_head overlay_list; |
| 42 | |
| 43 | static ssize_t overlay_name_show(struct omap_overlay *ovl, char *buf) |
| 44 | { |
| 45 | return snprintf(buf, PAGE_SIZE, "%s\n", ovl->name); |
| 46 | } |
| 47 | |
| 48 | static ssize_t overlay_manager_show(struct omap_overlay *ovl, char *buf) |
| 49 | { |
| 50 | return snprintf(buf, PAGE_SIZE, "%s\n", |
| 51 | ovl->manager ? ovl->manager->name : "<none>"); |
| 52 | } |
| 53 | |
| 54 | static ssize_t overlay_manager_store(struct omap_overlay *ovl, const char *buf, |
| 55 | size_t size) |
| 56 | { |
| 57 | int i, r; |
| 58 | struct omap_overlay_manager *mgr = NULL; |
| 59 | struct omap_overlay_manager *old_mgr; |
| 60 | int len = size; |
| 61 | |
| 62 | if (buf[size-1] == '\n') |
| 63 | --len; |
| 64 | |
| 65 | if (len > 0) { |
| 66 | for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) { |
| 67 | mgr = omap_dss_get_overlay_manager(i); |
| 68 | |
Archit Taneja | f3c77d6 | 2010-08-02 15:14:11 +0200 | [diff] [blame] | 69 | if (sysfs_streq(buf, mgr->name)) |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 70 | break; |
| 71 | |
| 72 | mgr = NULL; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | if (len > 0 && mgr == NULL) |
| 77 | return -EINVAL; |
| 78 | |
| 79 | if (mgr) |
| 80 | DSSDBG("manager %s found\n", mgr->name); |
| 81 | |
| 82 | if (mgr == ovl->manager) |
| 83 | return size; |
| 84 | |
| 85 | old_mgr = ovl->manager; |
| 86 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 87 | r = dispc_runtime_get(); |
| 88 | if (r) |
| 89 | return r; |
| 90 | |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 91 | /* detach old manager */ |
| 92 | if (old_mgr) { |
| 93 | r = ovl->unset_manager(ovl); |
| 94 | if (r) { |
| 95 | DSSERR("detach failed\n"); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 96 | goto err; |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | r = old_mgr->apply(old_mgr); |
| 100 | if (r) |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 101 | goto err; |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | if (mgr) { |
| 105 | r = ovl->set_manager(ovl, mgr); |
| 106 | if (r) { |
| 107 | DSSERR("Failed to attach overlay\n"); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 108 | goto err; |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | r = mgr->apply(mgr); |
| 112 | if (r) |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 113 | goto err; |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 114 | } |
| 115 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 116 | dispc_runtime_put(); |
| 117 | |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 118 | return size; |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 119 | |
| 120 | err: |
| 121 | dispc_runtime_put(); |
| 122 | return r; |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | static ssize_t overlay_input_size_show(struct omap_overlay *ovl, char *buf) |
| 126 | { |
| 127 | return snprintf(buf, PAGE_SIZE, "%d,%d\n", |
| 128 | ovl->info.width, ovl->info.height); |
| 129 | } |
| 130 | |
| 131 | static ssize_t overlay_screen_width_show(struct omap_overlay *ovl, char *buf) |
| 132 | { |
| 133 | return snprintf(buf, PAGE_SIZE, "%d\n", ovl->info.screen_width); |
| 134 | } |
| 135 | |
| 136 | static ssize_t overlay_position_show(struct omap_overlay *ovl, char *buf) |
| 137 | { |
| 138 | return snprintf(buf, PAGE_SIZE, "%d,%d\n", |
| 139 | ovl->info.pos_x, ovl->info.pos_y); |
| 140 | } |
| 141 | |
| 142 | static ssize_t overlay_position_store(struct omap_overlay *ovl, |
| 143 | const char *buf, size_t size) |
| 144 | { |
| 145 | int r; |
| 146 | char *last; |
| 147 | struct omap_overlay_info info; |
| 148 | |
| 149 | ovl->get_overlay_info(ovl, &info); |
| 150 | |
| 151 | info.pos_x = simple_strtoul(buf, &last, 10); |
| 152 | ++last; |
| 153 | if (last - buf >= size) |
| 154 | return -EINVAL; |
| 155 | |
| 156 | info.pos_y = simple_strtoul(last, &last, 10); |
| 157 | |
| 158 | r = ovl->set_overlay_info(ovl, &info); |
| 159 | if (r) |
| 160 | return r; |
| 161 | |
| 162 | if (ovl->manager) { |
| 163 | r = ovl->manager->apply(ovl->manager); |
| 164 | if (r) |
| 165 | return r; |
| 166 | } |
| 167 | |
| 168 | return size; |
| 169 | } |
| 170 | |
| 171 | static ssize_t overlay_output_size_show(struct omap_overlay *ovl, char *buf) |
| 172 | { |
| 173 | return snprintf(buf, PAGE_SIZE, "%d,%d\n", |
| 174 | ovl->info.out_width, ovl->info.out_height); |
| 175 | } |
| 176 | |
| 177 | static ssize_t overlay_output_size_store(struct omap_overlay *ovl, |
| 178 | const char *buf, size_t size) |
| 179 | { |
| 180 | int r; |
| 181 | char *last; |
| 182 | struct omap_overlay_info info; |
| 183 | |
| 184 | ovl->get_overlay_info(ovl, &info); |
| 185 | |
| 186 | info.out_width = simple_strtoul(buf, &last, 10); |
| 187 | ++last; |
| 188 | if (last - buf >= size) |
| 189 | return -EINVAL; |
| 190 | |
| 191 | info.out_height = simple_strtoul(last, &last, 10); |
| 192 | |
| 193 | r = ovl->set_overlay_info(ovl, &info); |
| 194 | if (r) |
| 195 | return r; |
| 196 | |
| 197 | if (ovl->manager) { |
| 198 | r = ovl->manager->apply(ovl->manager); |
| 199 | if (r) |
| 200 | return r; |
| 201 | } |
| 202 | |
| 203 | return size; |
| 204 | } |
| 205 | |
| 206 | static ssize_t overlay_enabled_show(struct omap_overlay *ovl, char *buf) |
| 207 | { |
| 208 | return snprintf(buf, PAGE_SIZE, "%d\n", ovl->info.enabled); |
| 209 | } |
| 210 | |
| 211 | static ssize_t overlay_enabled_store(struct omap_overlay *ovl, const char *buf, |
| 212 | size_t size) |
| 213 | { |
Tomi Valkeinen | e3502ce | 2011-04-04 15:40:23 +0300 | [diff] [blame] | 214 | int r, enable; |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 215 | struct omap_overlay_info info; |
| 216 | |
| 217 | ovl->get_overlay_info(ovl, &info); |
| 218 | |
Tomi Valkeinen | e3502ce | 2011-04-04 15:40:23 +0300 | [diff] [blame] | 219 | r = kstrtoint(buf, 0, &enable); |
| 220 | if (r) |
| 221 | return r; |
| 222 | |
| 223 | info.enabled = !!enable; |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 224 | |
| 225 | r = ovl->set_overlay_info(ovl, &info); |
| 226 | if (r) |
| 227 | return r; |
| 228 | |
| 229 | if (ovl->manager) { |
| 230 | r = ovl->manager->apply(ovl->manager); |
| 231 | if (r) |
| 232 | return r; |
| 233 | } |
| 234 | |
| 235 | return size; |
| 236 | } |
| 237 | |
| 238 | static ssize_t overlay_global_alpha_show(struct omap_overlay *ovl, char *buf) |
| 239 | { |
| 240 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 241 | ovl->info.global_alpha); |
| 242 | } |
| 243 | |
| 244 | static ssize_t overlay_global_alpha_store(struct omap_overlay *ovl, |
| 245 | const char *buf, size_t size) |
| 246 | { |
| 247 | int r; |
Tomi Valkeinen | e3502ce | 2011-04-04 15:40:23 +0300 | [diff] [blame] | 248 | u8 alpha; |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 249 | struct omap_overlay_info info; |
| 250 | |
Tomi Valkeinen | 332e9d7 | 2011-05-27 14:22:16 +0300 | [diff] [blame] | 251 | if (!dss_has_feature(FEAT_GLOBAL_ALPHA)) |
| 252 | return -ENODEV; |
| 253 | |
Tomi Valkeinen | e3502ce | 2011-04-04 15:40:23 +0300 | [diff] [blame] | 254 | r = kstrtou8(buf, 0, &alpha); |
| 255 | if (r) |
| 256 | return r; |
| 257 | |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 258 | ovl->get_overlay_info(ovl, &info); |
| 259 | |
| 260 | /* Video1 plane does not support global alpha |
| 261 | * to always make it 255 completely opaque |
| 262 | */ |
Archit Taneja | a0acb55 | 2010-09-15 19:20:00 +0530 | [diff] [blame] | 263 | if (!dss_has_feature(FEAT_GLOBAL_ALPHA_VID1) && |
| 264 | ovl->id == OMAP_DSS_VIDEO1) |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 265 | info.global_alpha = 255; |
| 266 | else |
Tomi Valkeinen | e3502ce | 2011-04-04 15:40:23 +0300 | [diff] [blame] | 267 | info.global_alpha = alpha; |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 268 | |
| 269 | r = ovl->set_overlay_info(ovl, &info); |
| 270 | if (r) |
| 271 | return r; |
| 272 | |
| 273 | if (ovl->manager) { |
| 274 | r = ovl->manager->apply(ovl->manager); |
| 275 | if (r) |
| 276 | return r; |
| 277 | } |
| 278 | |
| 279 | return size; |
| 280 | } |
| 281 | |
Rajkumar N | fd28a39 | 2010-11-04 12:28:42 +0100 | [diff] [blame] | 282 | static ssize_t overlay_pre_mult_alpha_show(struct omap_overlay *ovl, |
| 283 | char *buf) |
| 284 | { |
| 285 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 286 | ovl->info.pre_mult_alpha); |
| 287 | } |
| 288 | |
| 289 | static ssize_t overlay_pre_mult_alpha_store(struct omap_overlay *ovl, |
| 290 | const char *buf, size_t size) |
| 291 | { |
| 292 | int r; |
Tomi Valkeinen | e3502ce | 2011-04-04 15:40:23 +0300 | [diff] [blame] | 293 | u8 alpha; |
Rajkumar N | fd28a39 | 2010-11-04 12:28:42 +0100 | [diff] [blame] | 294 | struct omap_overlay_info info; |
| 295 | |
Tomi Valkeinen | e3502ce | 2011-04-04 15:40:23 +0300 | [diff] [blame] | 296 | r = kstrtou8(buf, 0, &alpha); |
| 297 | if (r) |
| 298 | return r; |
| 299 | |
Rajkumar N | fd28a39 | 2010-11-04 12:28:42 +0100 | [diff] [blame] | 300 | ovl->get_overlay_info(ovl, &info); |
| 301 | |
| 302 | /* only GFX and Video2 plane support pre alpha multiplied |
| 303 | * set zero for Video1 plane |
| 304 | */ |
| 305 | if (!dss_has_feature(FEAT_GLOBAL_ALPHA_VID1) && |
| 306 | ovl->id == OMAP_DSS_VIDEO1) |
| 307 | info.pre_mult_alpha = 0; |
| 308 | else |
Tomi Valkeinen | e3502ce | 2011-04-04 15:40:23 +0300 | [diff] [blame] | 309 | info.pre_mult_alpha = alpha; |
Rajkumar N | fd28a39 | 2010-11-04 12:28:42 +0100 | [diff] [blame] | 310 | |
| 311 | r = ovl->set_overlay_info(ovl, &info); |
| 312 | if (r) |
| 313 | return r; |
| 314 | |
| 315 | if (ovl->manager) { |
| 316 | r = ovl->manager->apply(ovl->manager); |
| 317 | if (r) |
| 318 | return r; |
| 319 | } |
| 320 | |
| 321 | return size; |
| 322 | } |
| 323 | |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 324 | struct overlay_attribute { |
| 325 | struct attribute attr; |
| 326 | ssize_t (*show)(struct omap_overlay *, char *); |
| 327 | ssize_t (*store)(struct omap_overlay *, const char *, size_t); |
| 328 | }; |
| 329 | |
| 330 | #define OVERLAY_ATTR(_name, _mode, _show, _store) \ |
| 331 | struct overlay_attribute overlay_attr_##_name = \ |
| 332 | __ATTR(_name, _mode, _show, _store) |
| 333 | |
| 334 | static OVERLAY_ATTR(name, S_IRUGO, overlay_name_show, NULL); |
| 335 | static OVERLAY_ATTR(manager, S_IRUGO|S_IWUSR, |
| 336 | overlay_manager_show, overlay_manager_store); |
| 337 | static OVERLAY_ATTR(input_size, S_IRUGO, overlay_input_size_show, NULL); |
| 338 | static OVERLAY_ATTR(screen_width, S_IRUGO, overlay_screen_width_show, NULL); |
| 339 | static OVERLAY_ATTR(position, S_IRUGO|S_IWUSR, |
| 340 | overlay_position_show, overlay_position_store); |
| 341 | static OVERLAY_ATTR(output_size, S_IRUGO|S_IWUSR, |
| 342 | overlay_output_size_show, overlay_output_size_store); |
| 343 | static OVERLAY_ATTR(enabled, S_IRUGO|S_IWUSR, |
| 344 | overlay_enabled_show, overlay_enabled_store); |
| 345 | static OVERLAY_ATTR(global_alpha, S_IRUGO|S_IWUSR, |
| 346 | overlay_global_alpha_show, overlay_global_alpha_store); |
Rajkumar N | fd28a39 | 2010-11-04 12:28:42 +0100 | [diff] [blame] | 347 | static OVERLAY_ATTR(pre_mult_alpha, S_IRUGO|S_IWUSR, |
| 348 | overlay_pre_mult_alpha_show, |
| 349 | overlay_pre_mult_alpha_store); |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 350 | |
| 351 | static struct attribute *overlay_sysfs_attrs[] = { |
| 352 | &overlay_attr_name.attr, |
| 353 | &overlay_attr_manager.attr, |
| 354 | &overlay_attr_input_size.attr, |
| 355 | &overlay_attr_screen_width.attr, |
| 356 | &overlay_attr_position.attr, |
| 357 | &overlay_attr_output_size.attr, |
| 358 | &overlay_attr_enabled.attr, |
| 359 | &overlay_attr_global_alpha.attr, |
Rajkumar N | fd28a39 | 2010-11-04 12:28:42 +0100 | [diff] [blame] | 360 | &overlay_attr_pre_mult_alpha.attr, |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 361 | NULL |
| 362 | }; |
| 363 | |
| 364 | static ssize_t overlay_attr_show(struct kobject *kobj, struct attribute *attr, |
| 365 | char *buf) |
| 366 | { |
| 367 | struct omap_overlay *overlay; |
| 368 | struct overlay_attribute *overlay_attr; |
| 369 | |
| 370 | overlay = container_of(kobj, struct omap_overlay, kobj); |
| 371 | overlay_attr = container_of(attr, struct overlay_attribute, attr); |
| 372 | |
| 373 | if (!overlay_attr->show) |
| 374 | return -ENOENT; |
| 375 | |
| 376 | return overlay_attr->show(overlay, buf); |
| 377 | } |
| 378 | |
| 379 | static ssize_t overlay_attr_store(struct kobject *kobj, struct attribute *attr, |
| 380 | const char *buf, size_t size) |
| 381 | { |
| 382 | struct omap_overlay *overlay; |
| 383 | struct overlay_attribute *overlay_attr; |
| 384 | |
| 385 | overlay = container_of(kobj, struct omap_overlay, kobj); |
| 386 | overlay_attr = container_of(attr, struct overlay_attribute, attr); |
| 387 | |
| 388 | if (!overlay_attr->store) |
| 389 | return -ENOENT; |
| 390 | |
| 391 | return overlay_attr->store(overlay, buf, size); |
| 392 | } |
| 393 | |
Emese Revfy | 52cf25d | 2010-01-19 02:58:23 +0100 | [diff] [blame] | 394 | static const struct sysfs_ops overlay_sysfs_ops = { |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 395 | .show = overlay_attr_show, |
| 396 | .store = overlay_attr_store, |
| 397 | }; |
| 398 | |
| 399 | static struct kobj_type overlay_ktype = { |
| 400 | .sysfs_ops = &overlay_sysfs_ops, |
| 401 | .default_attrs = overlay_sysfs_attrs, |
| 402 | }; |
| 403 | |
| 404 | /* Check if overlay parameters are compatible with display */ |
| 405 | int dss_check_overlay(struct omap_overlay *ovl, struct omap_dss_device *dssdev) |
| 406 | { |
| 407 | struct omap_overlay_info *info; |
| 408 | u16 outw, outh; |
| 409 | u16 dw, dh; |
| 410 | |
| 411 | if (!dssdev) |
| 412 | return 0; |
| 413 | |
| 414 | if (!ovl->info.enabled) |
| 415 | return 0; |
| 416 | |
| 417 | info = &ovl->info; |
| 418 | |
| 419 | if (info->paddr == 0) { |
| 420 | DSSDBG("check_overlay failed: paddr 0\n"); |
| 421 | return -EINVAL; |
| 422 | } |
| 423 | |
Tomi Valkeinen | 96adcec | 2010-01-11 13:54:33 +0200 | [diff] [blame] | 424 | dssdev->driver->get_resolution(dssdev, &dw, &dh); |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 425 | |
| 426 | DSSDBG("check_overlay %d: (%d,%d %dx%d -> %dx%d) disp (%dx%d)\n", |
| 427 | ovl->id, |
| 428 | info->pos_x, info->pos_y, |
| 429 | info->width, info->height, |
| 430 | info->out_width, info->out_height, |
| 431 | dw, dh); |
| 432 | |
| 433 | if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0) { |
| 434 | outw = info->width; |
| 435 | outh = info->height; |
| 436 | } else { |
| 437 | if (info->out_width == 0) |
| 438 | outw = info->width; |
| 439 | else |
| 440 | outw = info->out_width; |
| 441 | |
| 442 | if (info->out_height == 0) |
| 443 | outh = info->height; |
| 444 | else |
| 445 | outh = info->out_height; |
| 446 | } |
| 447 | |
| 448 | if (dw < info->pos_x + outw) { |
| 449 | DSSDBG("check_overlay failed 1: %d < %d + %d\n", |
| 450 | dw, info->pos_x, outw); |
| 451 | return -EINVAL; |
| 452 | } |
| 453 | |
| 454 | if (dh < info->pos_y + outh) { |
| 455 | DSSDBG("check_overlay failed 2: %d < %d + %d\n", |
| 456 | dh, info->pos_y, outh); |
| 457 | return -EINVAL; |
| 458 | } |
| 459 | |
| 460 | if ((ovl->supported_modes & info->color_mode) == 0) { |
| 461 | DSSERR("overlay doesn't support mode %d\n", info->color_mode); |
| 462 | return -EINVAL; |
| 463 | } |
| 464 | |
| 465 | return 0; |
| 466 | } |
| 467 | |
| 468 | static int dss_ovl_set_overlay_info(struct omap_overlay *ovl, |
| 469 | struct omap_overlay_info *info) |
| 470 | { |
| 471 | int r; |
| 472 | struct omap_overlay_info old_info; |
| 473 | |
| 474 | old_info = ovl->info; |
| 475 | ovl->info = *info; |
| 476 | |
| 477 | if (ovl->manager) { |
| 478 | r = dss_check_overlay(ovl, ovl->manager->device); |
| 479 | if (r) { |
| 480 | ovl->info = old_info; |
| 481 | return r; |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | ovl->info_dirty = true; |
| 486 | |
| 487 | return 0; |
| 488 | } |
| 489 | |
| 490 | static void dss_ovl_get_overlay_info(struct omap_overlay *ovl, |
| 491 | struct omap_overlay_info *info) |
| 492 | { |
| 493 | *info = ovl->info; |
| 494 | } |
| 495 | |
| 496 | static int dss_ovl_wait_for_go(struct omap_overlay *ovl) |
| 497 | { |
| 498 | return dss_mgr_wait_for_go_ovl(ovl); |
| 499 | } |
| 500 | |
| 501 | static int omap_dss_set_manager(struct omap_overlay *ovl, |
| 502 | struct omap_overlay_manager *mgr) |
| 503 | { |
| 504 | if (!mgr) |
| 505 | return -EINVAL; |
| 506 | |
| 507 | if (ovl->manager) { |
| 508 | DSSERR("overlay '%s' already has a manager '%s'\n", |
| 509 | ovl->name, ovl->manager->name); |
| 510 | return -EINVAL; |
| 511 | } |
| 512 | |
| 513 | if (ovl->info.enabled) { |
| 514 | DSSERR("overlay has to be disabled to change the manager\n"); |
| 515 | return -EINVAL; |
| 516 | } |
| 517 | |
| 518 | ovl->manager = mgr; |
Tomi Valkeinen | 8fa8031 | 2011-08-16 12:56:19 +0300 | [diff] [blame] | 519 | ovl->manager_changed = true; |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 520 | |
Tomi Valkeinen | d792eec | 2010-05-20 15:13:12 +0300 | [diff] [blame] | 521 | /* XXX: When there is an overlay on a DSI manual update display, and |
| 522 | * the overlay is first disabled, then moved to tv, and enabled, we |
| 523 | * seem to get SYNC_LOST_DIGIT error. |
| 524 | * |
| 525 | * Waiting doesn't seem to help, but updating the manual update display |
| 526 | * after disabling the overlay seems to fix this. This hints that the |
| 527 | * overlay is perhaps somehow tied to the LCD output until the output |
| 528 | * is updated. |
| 529 | * |
| 530 | * Userspace workaround for this is to update the LCD after disabling |
| 531 | * the overlay, but before moving the overlay to TV. |
| 532 | */ |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 533 | |
| 534 | return 0; |
| 535 | } |
| 536 | |
| 537 | static int omap_dss_unset_manager(struct omap_overlay *ovl) |
| 538 | { |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 539 | if (!ovl->manager) { |
| 540 | DSSERR("failed to detach overlay: manager not set\n"); |
| 541 | return -EINVAL; |
| 542 | } |
| 543 | |
| 544 | if (ovl->info.enabled) { |
| 545 | DSSERR("overlay has to be disabled to unset the manager\n"); |
| 546 | return -EINVAL; |
| 547 | } |
| 548 | |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 549 | ovl->manager = NULL; |
Tomi Valkeinen | 8fa8031 | 2011-08-16 12:56:19 +0300 | [diff] [blame] | 550 | ovl->manager_changed = true; |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 551 | |
| 552 | return 0; |
| 553 | } |
| 554 | |
| 555 | int omap_dss_get_num_overlays(void) |
| 556 | { |
| 557 | return num_overlays; |
| 558 | } |
| 559 | EXPORT_SYMBOL(omap_dss_get_num_overlays); |
| 560 | |
| 561 | struct omap_overlay *omap_dss_get_overlay(int num) |
| 562 | { |
| 563 | int i = 0; |
| 564 | struct omap_overlay *ovl; |
| 565 | |
| 566 | list_for_each_entry(ovl, &overlay_list, list) { |
| 567 | if (i++ == num) |
| 568 | return ovl; |
| 569 | } |
| 570 | |
| 571 | return NULL; |
| 572 | } |
| 573 | EXPORT_SYMBOL(omap_dss_get_overlay); |
| 574 | |
| 575 | static void omap_dss_add_overlay(struct omap_overlay *overlay) |
| 576 | { |
| 577 | ++num_overlays; |
| 578 | list_add_tail(&overlay->list, &overlay_list); |
| 579 | } |
| 580 | |
Archit Taneja | a0acb55 | 2010-09-15 19:20:00 +0530 | [diff] [blame] | 581 | static struct omap_overlay *dispc_overlays[MAX_DSS_OVERLAYS]; |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 582 | |
| 583 | void dss_overlay_setup_dispc_manager(struct omap_overlay_manager *mgr) |
| 584 | { |
Archit Taneja | a0acb55 | 2010-09-15 19:20:00 +0530 | [diff] [blame] | 585 | mgr->num_overlays = dss_feat_get_num_ovls(); |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 586 | mgr->overlays = dispc_overlays; |
| 587 | } |
| 588 | |
| 589 | #ifdef L4_EXAMPLE |
| 590 | static struct omap_overlay *l4_overlays[1]; |
| 591 | void dss_overlay_setup_l4_manager(struct omap_overlay_manager *mgr) |
| 592 | { |
| 593 | mgr->num_overlays = 1; |
| 594 | mgr->overlays = l4_overlays; |
| 595 | } |
| 596 | #endif |
| 597 | |
| 598 | void dss_init_overlays(struct platform_device *pdev) |
| 599 | { |
| 600 | int i, r; |
| 601 | |
| 602 | INIT_LIST_HEAD(&overlay_list); |
| 603 | |
| 604 | num_overlays = 0; |
| 605 | |
Archit Taneja | a0acb55 | 2010-09-15 19:20:00 +0530 | [diff] [blame] | 606 | for (i = 0; i < dss_feat_get_num_ovls(); ++i) { |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 607 | struct omap_overlay *ovl; |
| 608 | ovl = kzalloc(sizeof(*ovl), GFP_KERNEL); |
| 609 | |
| 610 | BUG_ON(ovl == NULL); |
| 611 | |
| 612 | switch (i) { |
| 613 | case 0: |
| 614 | ovl->name = "gfx"; |
| 615 | ovl->id = OMAP_DSS_GFX; |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 616 | ovl->info.global_alpha = 255; |
| 617 | break; |
| 618 | case 1: |
| 619 | ovl->name = "vid1"; |
| 620 | ovl->id = OMAP_DSS_VIDEO1; |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 621 | ovl->info.global_alpha = 255; |
| 622 | break; |
| 623 | case 2: |
| 624 | ovl->name = "vid2"; |
| 625 | ovl->id = OMAP_DSS_VIDEO2; |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 626 | ovl->info.global_alpha = 255; |
| 627 | break; |
| 628 | } |
| 629 | |
| 630 | ovl->set_manager = &omap_dss_set_manager; |
| 631 | ovl->unset_manager = &omap_dss_unset_manager; |
| 632 | ovl->set_overlay_info = &dss_ovl_set_overlay_info; |
| 633 | ovl->get_overlay_info = &dss_ovl_get_overlay_info; |
| 634 | ovl->wait_for_go = &dss_ovl_wait_for_go; |
| 635 | |
Tomi Valkeinen | 67019db | 2011-08-15 15:18:15 +0300 | [diff] [blame^] | 636 | ovl->caps = dss_feat_get_overlay_caps(ovl->id); |
Archit Taneja | a0acb55 | 2010-09-15 19:20:00 +0530 | [diff] [blame] | 637 | ovl->supported_modes = |
| 638 | dss_feat_get_supported_color_modes(ovl->id); |
| 639 | |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 640 | omap_dss_add_overlay(ovl); |
| 641 | |
| 642 | r = kobject_init_and_add(&ovl->kobj, &overlay_ktype, |
| 643 | &pdev->dev.kobj, "overlay%d", i); |
| 644 | |
| 645 | if (r) { |
| 646 | DSSERR("failed to create sysfs file\n"); |
| 647 | continue; |
| 648 | } |
| 649 | |
| 650 | dispc_overlays[i] = ovl; |
| 651 | } |
| 652 | |
| 653 | #ifdef L4_EXAMPLE |
| 654 | { |
| 655 | struct omap_overlay *ovl; |
| 656 | ovl = kzalloc(sizeof(*ovl), GFP_KERNEL); |
| 657 | |
| 658 | BUG_ON(ovl == NULL); |
| 659 | |
| 660 | ovl->name = "l4"; |
| 661 | ovl->supported_modes = OMAP_DSS_COLOR_RGB24U; |
| 662 | |
| 663 | ovl->set_manager = &omap_dss_set_manager; |
| 664 | ovl->unset_manager = &omap_dss_unset_manager; |
| 665 | ovl->set_overlay_info = &dss_ovl_set_overlay_info; |
| 666 | ovl->get_overlay_info = &dss_ovl_get_overlay_info; |
| 667 | |
| 668 | omap_dss_add_overlay(ovl); |
| 669 | |
| 670 | r = kobject_init_and_add(&ovl->kobj, &overlay_ktype, |
| 671 | &pdev->dev.kobj, "overlayl4"); |
| 672 | |
| 673 | if (r) |
| 674 | DSSERR("failed to create sysfs file\n"); |
| 675 | |
| 676 | l4_overlays[0] = ovl; |
| 677 | } |
| 678 | #endif |
| 679 | } |
| 680 | |
| 681 | /* connect overlays to the new device, if not already connected. if force |
| 682 | * selected, connect always. */ |
| 683 | void dss_recheck_connections(struct omap_dss_device *dssdev, bool force) |
| 684 | { |
| 685 | int i; |
| 686 | struct omap_overlay_manager *lcd_mgr; |
| 687 | struct omap_overlay_manager *tv_mgr; |
Sumit Semwal | 18faa1b | 2010-12-02 11:27:14 +0000 | [diff] [blame] | 688 | struct omap_overlay_manager *lcd2_mgr = NULL; |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 689 | struct omap_overlay_manager *mgr = NULL; |
| 690 | |
| 691 | lcd_mgr = omap_dss_get_overlay_manager(OMAP_DSS_OVL_MGR_LCD); |
| 692 | tv_mgr = omap_dss_get_overlay_manager(OMAP_DSS_OVL_MGR_TV); |
Sumit Semwal | 18faa1b | 2010-12-02 11:27:14 +0000 | [diff] [blame] | 693 | if (dss_has_feature(FEAT_MGR_LCD2)) |
| 694 | lcd2_mgr = omap_dss_get_overlay_manager(OMAP_DSS_OVL_MGR_LCD2); |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 695 | |
Sumit Semwal | 18faa1b | 2010-12-02 11:27:14 +0000 | [diff] [blame] | 696 | if (dssdev->channel == OMAP_DSS_CHANNEL_LCD2) { |
| 697 | if (!lcd2_mgr->device || force) { |
| 698 | if (lcd2_mgr->device) |
| 699 | lcd2_mgr->unset_device(lcd2_mgr); |
| 700 | lcd2_mgr->set_device(lcd2_mgr, dssdev); |
| 701 | mgr = lcd2_mgr; |
| 702 | } |
Mythri P K | b119601 | 2011-03-08 17:15:54 +0530 | [diff] [blame] | 703 | } else if (dssdev->type != OMAP_DISPLAY_TYPE_VENC |
| 704 | && dssdev->type != OMAP_DISPLAY_TYPE_HDMI) { |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 705 | if (!lcd_mgr->device || force) { |
| 706 | if (lcd_mgr->device) |
| 707 | lcd_mgr->unset_device(lcd_mgr); |
| 708 | lcd_mgr->set_device(lcd_mgr, dssdev); |
| 709 | mgr = lcd_mgr; |
| 710 | } |
| 711 | } |
| 712 | |
Mythri P K | b119601 | 2011-03-08 17:15:54 +0530 | [diff] [blame] | 713 | if (dssdev->type == OMAP_DISPLAY_TYPE_VENC |
| 714 | || dssdev->type == OMAP_DISPLAY_TYPE_HDMI) { |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 715 | if (!tv_mgr->device || force) { |
| 716 | if (tv_mgr->device) |
| 717 | tv_mgr->unset_device(tv_mgr); |
| 718 | tv_mgr->set_device(tv_mgr, dssdev); |
| 719 | mgr = tv_mgr; |
| 720 | } |
| 721 | } |
| 722 | |
| 723 | if (mgr) { |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 724 | dispc_runtime_get(); |
| 725 | |
Archit Taneja | a0acb55 | 2010-09-15 19:20:00 +0530 | [diff] [blame] | 726 | for (i = 0; i < dss_feat_get_num_ovls(); i++) { |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 727 | struct omap_overlay *ovl; |
| 728 | ovl = omap_dss_get_overlay(i); |
| 729 | if (!ovl->manager || force) { |
| 730 | if (ovl->manager) |
| 731 | omap_dss_unset_manager(ovl); |
| 732 | omap_dss_set_manager(ovl, mgr); |
| 733 | } |
| 734 | } |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 735 | |
| 736 | dispc_runtime_put(); |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 737 | } |
| 738 | } |
| 739 | |
| 740 | void dss_uninit_overlays(struct platform_device *pdev) |
| 741 | { |
| 742 | struct omap_overlay *ovl; |
| 743 | |
| 744 | while (!list_empty(&overlay_list)) { |
| 745 | ovl = list_first_entry(&overlay_list, |
| 746 | struct omap_overlay, list); |
| 747 | list_del(&ovl->list); |
| 748 | kobject_del(&ovl->kobj); |
| 749 | kobject_put(&ovl->kobj); |
| 750 | kfree(ovl); |
| 751 | } |
| 752 | |
| 753 | num_overlays = 0; |
| 754 | } |
| 755 | |