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> |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 29 | #include <linux/platform_device.h> |
| 30 | #include <linux/delay.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 31 | #include <linux/slab.h> |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 32 | |
Tomi Valkeinen | a0b38cc | 2011-05-11 14:05:07 +0300 | [diff] [blame] | 33 | #include <video/omapdss.h> |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 34 | |
| 35 | #include "dss.h" |
Archit Taneja | a0acb55 | 2010-09-15 19:20:00 +0530 | [diff] [blame] | 36 | #include "dss_features.h" |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 37 | |
| 38 | static int num_overlays; |
Tomi Valkeinen | 5845234 | 2011-11-05 10:39:59 +0200 | [diff] [blame] | 39 | static struct omap_overlay *overlays; |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 40 | |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 41 | int omap_dss_get_num_overlays(void) |
| 42 | { |
| 43 | return num_overlays; |
| 44 | } |
| 45 | EXPORT_SYMBOL(omap_dss_get_num_overlays); |
| 46 | |
| 47 | struct omap_overlay *omap_dss_get_overlay(int num) |
| 48 | { |
Tomi Valkeinen | 5845234 | 2011-11-05 10:39:59 +0200 | [diff] [blame] | 49 | if (num >= num_overlays) |
| 50 | return NULL; |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 51 | |
Tomi Valkeinen | 5845234 | 2011-11-05 10:39:59 +0200 | [diff] [blame] | 52 | return &overlays[num]; |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 53 | } |
| 54 | EXPORT_SYMBOL(omap_dss_get_overlay); |
| 55 | |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 56 | void dss_init_overlays(struct platform_device *pdev) |
| 57 | { |
| 58 | int i, r; |
| 59 | |
Tomi Valkeinen | 5845234 | 2011-11-05 10:39:59 +0200 | [diff] [blame] | 60 | num_overlays = dss_feat_get_num_ovls(); |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 61 | |
Tomi Valkeinen | 5845234 | 2011-11-05 10:39:59 +0200 | [diff] [blame] | 62 | overlays = kzalloc(sizeof(struct omap_overlay) * num_overlays, |
| 63 | GFP_KERNEL); |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 64 | |
Tomi Valkeinen | 5845234 | 2011-11-05 10:39:59 +0200 | [diff] [blame] | 65 | BUG_ON(overlays == NULL); |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 66 | |
Tomi Valkeinen | 5845234 | 2011-11-05 10:39:59 +0200 | [diff] [blame] | 67 | for (i = 0; i < num_overlays; ++i) { |
| 68 | struct omap_overlay *ovl = &overlays[i]; |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 69 | |
| 70 | switch (i) { |
| 71 | case 0: |
| 72 | ovl->name = "gfx"; |
| 73 | ovl->id = OMAP_DSS_GFX; |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 74 | break; |
| 75 | case 1: |
| 76 | ovl->name = "vid1"; |
| 77 | ovl->id = OMAP_DSS_VIDEO1; |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 78 | break; |
| 79 | case 2: |
| 80 | ovl->name = "vid2"; |
| 81 | ovl->id = OMAP_DSS_VIDEO2; |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 82 | break; |
Archit Taneja | b8c095b | 2011-09-13 18:20:33 +0530 | [diff] [blame] | 83 | case 3: |
| 84 | ovl->name = "vid3"; |
| 85 | ovl->id = OMAP_DSS_VIDEO3; |
Archit Taneja | b8c095b | 2011-09-13 18:20:33 +0530 | [diff] [blame] | 86 | break; |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 87 | } |
| 88 | |
Tomi Valkeinen | aaa874a | 2011-11-15 16:37:53 +0200 | [diff] [blame] | 89 | ovl->is_enabled = &dss_ovl_is_enabled; |
| 90 | ovl->enable = &dss_ovl_enable; |
| 91 | ovl->disable = &dss_ovl_disable; |
Tomi Valkeinen | f77b307 | 2011-11-15 12:11:11 +0200 | [diff] [blame] | 92 | ovl->set_manager = &dss_ovl_set_manager; |
| 93 | ovl->unset_manager = &dss_ovl_unset_manager; |
| 94 | ovl->set_overlay_info = &dss_ovl_set_info; |
| 95 | ovl->get_overlay_info = &dss_ovl_get_info; |
Tomi Valkeinen | 550a8f6 | 2011-11-04 13:00:10 +0200 | [diff] [blame] | 96 | ovl->wait_for_go = &dss_mgr_wait_for_go_ovl; |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 97 | |
Tomi Valkeinen | 67019db | 2011-08-15 15:18:15 +0300 | [diff] [blame] | 98 | ovl->caps = dss_feat_get_overlay_caps(ovl->id); |
Archit Taneja | a0acb55 | 2010-09-15 19:20:00 +0530 | [diff] [blame] | 99 | ovl->supported_modes = |
| 100 | dss_feat_get_supported_color_modes(ovl->id); |
| 101 | |
Tomi Valkeinen | 9169151 | 2012-08-06 14:40:00 +0300 | [diff] [blame] | 102 | r = dss_overlay_kobj_init(ovl, pdev); |
Tomi Valkeinen | 5845234 | 2011-11-05 10:39:59 +0200 | [diff] [blame] | 103 | if (r) |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 104 | DSSERR("failed to create sysfs file\n"); |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 105 | } |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | /* connect overlays to the new device, if not already connected. if force |
| 109 | * selected, connect always. */ |
| 110 | void dss_recheck_connections(struct omap_dss_device *dssdev, bool force) |
| 111 | { |
| 112 | int i; |
| 113 | struct omap_overlay_manager *lcd_mgr; |
| 114 | struct omap_overlay_manager *tv_mgr; |
Sumit Semwal | 18faa1b | 2010-12-02 11:27:14 +0000 | [diff] [blame] | 115 | struct omap_overlay_manager *lcd2_mgr = NULL; |
Chandrabhanu Mahapatra | e86d456 | 2012-06-29 10:43:13 +0530 | [diff] [blame] | 116 | struct omap_overlay_manager *lcd3_mgr = NULL; |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 117 | struct omap_overlay_manager *mgr = NULL; |
| 118 | |
Tomi Valkeinen | 0df8ad7 | 2012-06-25 11:20:13 +0300 | [diff] [blame] | 119 | lcd_mgr = omap_dss_get_overlay_manager(OMAP_DSS_CHANNEL_LCD); |
| 120 | tv_mgr = omap_dss_get_overlay_manager(OMAP_DSS_CHANNEL_DIGIT); |
Chandrabhanu Mahapatra | e86d456 | 2012-06-29 10:43:13 +0530 | [diff] [blame] | 121 | if (dss_has_feature(FEAT_MGR_LCD3)) |
| 122 | lcd3_mgr = omap_dss_get_overlay_manager(OMAP_DSS_CHANNEL_LCD3); |
Sumit Semwal | 18faa1b | 2010-12-02 11:27:14 +0000 | [diff] [blame] | 123 | if (dss_has_feature(FEAT_MGR_LCD2)) |
Tomi Valkeinen | 0df8ad7 | 2012-06-25 11:20:13 +0300 | [diff] [blame] | 124 | lcd2_mgr = omap_dss_get_overlay_manager(OMAP_DSS_CHANNEL_LCD2); |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 125 | |
Chandrabhanu Mahapatra | e86d456 | 2012-06-29 10:43:13 +0530 | [diff] [blame] | 126 | if (dssdev->channel == OMAP_DSS_CHANNEL_LCD3) { |
| 127 | if (!lcd3_mgr->device || force) { |
| 128 | if (lcd3_mgr->device) |
| 129 | lcd3_mgr->unset_device(lcd3_mgr); |
| 130 | lcd3_mgr->set_device(lcd3_mgr, dssdev); |
| 131 | mgr = lcd3_mgr; |
| 132 | } |
| 133 | } else if (dssdev->channel == OMAP_DSS_CHANNEL_LCD2) { |
Sumit Semwal | 18faa1b | 2010-12-02 11:27:14 +0000 | [diff] [blame] | 134 | if (!lcd2_mgr->device || force) { |
| 135 | if (lcd2_mgr->device) |
| 136 | lcd2_mgr->unset_device(lcd2_mgr); |
| 137 | lcd2_mgr->set_device(lcd2_mgr, dssdev); |
| 138 | mgr = lcd2_mgr; |
| 139 | } |
Mythri P K | b119601 | 2011-03-08 17:15:54 +0530 | [diff] [blame] | 140 | } else if (dssdev->type != OMAP_DISPLAY_TYPE_VENC |
| 141 | && dssdev->type != OMAP_DISPLAY_TYPE_HDMI) { |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 142 | if (!lcd_mgr->device || force) { |
| 143 | if (lcd_mgr->device) |
| 144 | lcd_mgr->unset_device(lcd_mgr); |
| 145 | lcd_mgr->set_device(lcd_mgr, dssdev); |
| 146 | mgr = lcd_mgr; |
| 147 | } |
| 148 | } |
| 149 | |
Mythri P K | b119601 | 2011-03-08 17:15:54 +0530 | [diff] [blame] | 150 | if (dssdev->type == OMAP_DISPLAY_TYPE_VENC |
| 151 | || dssdev->type == OMAP_DISPLAY_TYPE_HDMI) { |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 152 | if (!tv_mgr->device || force) { |
| 153 | if (tv_mgr->device) |
| 154 | tv_mgr->unset_device(tv_mgr); |
| 155 | tv_mgr->set_device(tv_mgr, dssdev); |
| 156 | mgr = tv_mgr; |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | if (mgr) { |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 161 | dispc_runtime_get(); |
| 162 | |
Archit Taneja | a0acb55 | 2010-09-15 19:20:00 +0530 | [diff] [blame] | 163 | for (i = 0; i < dss_feat_get_num_ovls(); i++) { |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 164 | struct omap_overlay *ovl; |
| 165 | ovl = omap_dss_get_overlay(i); |
| 166 | if (!ovl->manager || force) { |
| 167 | if (ovl->manager) |
Tomi Valkeinen | f77b307 | 2011-11-15 12:11:11 +0200 | [diff] [blame] | 168 | ovl->unset_manager(ovl); |
| 169 | ovl->set_manager(ovl, mgr); |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 170 | } |
| 171 | } |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 172 | |
| 173 | dispc_runtime_put(); |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 174 | } |
| 175 | } |
| 176 | |
| 177 | void dss_uninit_overlays(struct platform_device *pdev) |
| 178 | { |
Tomi Valkeinen | 5845234 | 2011-11-05 10:39:59 +0200 | [diff] [blame] | 179 | int i; |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 180 | |
Tomi Valkeinen | 5845234 | 2011-11-05 10:39:59 +0200 | [diff] [blame] | 181 | for (i = 0; i < num_overlays; ++i) { |
| 182 | struct omap_overlay *ovl = &overlays[i]; |
Tomi Valkeinen | 9169151 | 2012-08-06 14:40:00 +0300 | [diff] [blame] | 183 | dss_overlay_kobj_uninit(ovl); |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 184 | } |
| 185 | |
Tomi Valkeinen | 5845234 | 2011-11-05 10:39:59 +0200 | [diff] [blame] | 186 | kfree(overlays); |
| 187 | overlays = NULL; |
Tomi Valkeinen | eed07e0 | 2009-08-07 13:43:20 +0300 | [diff] [blame] | 188 | num_overlays = 0; |
| 189 | } |
| 190 | |
Tomi Valkeinen | 54540d4 | 2011-12-13 13:18:52 +0200 | [diff] [blame] | 191 | int dss_ovl_simple_check(struct omap_overlay *ovl, |
| 192 | const struct omap_overlay_info *info) |
| 193 | { |
| 194 | if (info->paddr == 0) { |
| 195 | DSSERR("check_overlay: paddr cannot be 0\n"); |
| 196 | return -EINVAL; |
| 197 | } |
| 198 | |
| 199 | if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0) { |
| 200 | if (info->out_width != 0 && info->width != info->out_width) { |
| 201 | DSSERR("check_overlay: overlay %d doesn't support " |
| 202 | "scaling\n", ovl->id); |
| 203 | return -EINVAL; |
| 204 | } |
| 205 | |
| 206 | if (info->out_height != 0 && info->height != info->out_height) { |
| 207 | DSSERR("check_overlay: overlay %d doesn't support " |
| 208 | "scaling\n", ovl->id); |
| 209 | return -EINVAL; |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | if ((ovl->supported_modes & info->color_mode) == 0) { |
| 214 | DSSERR("check_overlay: overlay %d doesn't support mode %d\n", |
| 215 | ovl->id, info->color_mode); |
| 216 | return -EINVAL; |
| 217 | } |
| 218 | |
| 219 | if (info->zorder >= omap_dss_get_num_overlays()) { |
| 220 | DSSERR("check_overlay: zorder %d too high\n", info->zorder); |
| 221 | return -EINVAL; |
| 222 | } |
| 223 | |
Chandrabhanu Mahapatra | 65e006f | 2012-05-11 19:19:55 +0530 | [diff] [blame] | 224 | if (dss_feat_rotation_type_supported(info->rotation_type) == 0) { |
| 225 | DSSERR("check_overlay: rotation type %d not supported\n", |
| 226 | info->rotation_type); |
| 227 | return -EINVAL; |
| 228 | } |
| 229 | |
Tomi Valkeinen | 54540d4 | 2011-12-13 13:18:52 +0200 | [diff] [blame] | 230 | return 0; |
| 231 | } |
| 232 | |
Archit Taneja | 228b213 | 2012-04-27 01:22:28 +0530 | [diff] [blame] | 233 | int dss_ovl_check(struct omap_overlay *ovl, struct omap_overlay_info *info, |
| 234 | const struct omap_video_timings *mgr_timings) |
Tomi Valkeinen | 6ac48d1 | 2011-12-08 10:32:37 +0200 | [diff] [blame] | 235 | { |
| 236 | u16 outw, outh; |
| 237 | u16 dw, dh; |
| 238 | |
Archit Taneja | 228b213 | 2012-04-27 01:22:28 +0530 | [diff] [blame] | 239 | dw = mgr_timings->x_res; |
| 240 | dh = mgr_timings->y_res; |
Tomi Valkeinen | 6ac48d1 | 2011-12-08 10:32:37 +0200 | [diff] [blame] | 241 | |
| 242 | if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0) { |
| 243 | outw = info->width; |
| 244 | outh = info->height; |
| 245 | } else { |
| 246 | if (info->out_width == 0) |
| 247 | outw = info->width; |
| 248 | else |
| 249 | outw = info->out_width; |
| 250 | |
| 251 | if (info->out_height == 0) |
| 252 | outh = info->height; |
| 253 | else |
| 254 | outh = info->out_height; |
| 255 | } |
| 256 | |
| 257 | if (dw < info->pos_x + outw) { |
| 258 | DSSERR("overlay %d horizontally not inside the display area " |
| 259 | "(%d + %d >= %d)\n", |
| 260 | ovl->id, info->pos_x, outw, dw); |
| 261 | return -EINVAL; |
| 262 | } |
| 263 | |
| 264 | if (dh < info->pos_y + outh) { |
| 265 | DSSERR("overlay %d vertically not inside the display area " |
| 266 | "(%d + %d >= %d)\n", |
| 267 | ovl->id, info->pos_y, outh, dh); |
| 268 | return -EINVAL; |
| 269 | } |
| 270 | |
| 271 | return 0; |
| 272 | } |
Archit Taneja | 6c6f510 | 2012-06-25 14:58:48 +0530 | [diff] [blame] | 273 | |
| 274 | /* |
| 275 | * Checks if replication logic should be used. Only use when overlay is in |
| 276 | * RGB12U or RGB16 mode, and video port width interface is 18bpp or 24bpp |
| 277 | */ |
| 278 | bool dss_ovl_use_replication(struct dss_lcd_mgr_config config, |
| 279 | enum omap_color_mode mode) |
| 280 | { |
| 281 | if (mode != OMAP_DSS_COLOR_RGB12U && mode != OMAP_DSS_COLOR_RGB16) |
| 282 | return false; |
| 283 | |
| 284 | return config.video_port_width > 16; |
| 285 | } |