Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 Texas Instruments |
| 3 | * Author: Tomi Valkeinen <tomi.valkeinen@ti.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 as published by |
| 7 | * the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along with |
| 15 | * this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | */ |
| 17 | |
| 18 | #define DSS_SUBSYS_NAME "APPLY" |
| 19 | |
| 20 | #include <linux/kernel.h> |
| 21 | #include <linux/slab.h> |
| 22 | #include <linux/spinlock.h> |
| 23 | #include <linux/jiffies.h> |
| 24 | |
| 25 | #include <video/omapdss.h> |
| 26 | |
| 27 | #include "dss.h" |
| 28 | #include "dss_features.h" |
| 29 | |
| 30 | /* |
| 31 | * We have 4 levels of cache for the dispc settings. First two are in SW and |
| 32 | * the latter two in HW. |
| 33 | * |
| 34 | * +--------------------+ |
| 35 | * |overlay/manager_info| |
| 36 | * +--------------------+ |
| 37 | * v |
| 38 | * apply() |
| 39 | * v |
| 40 | * +--------------------+ |
| 41 | * | dss_cache | |
| 42 | * +--------------------+ |
| 43 | * v |
Tomi Valkeinen | f6a5e08 | 2011-11-15 11:47:39 +0200 | [diff] [blame] | 44 | * write_regs() |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 45 | * v |
| 46 | * +--------------------+ |
| 47 | * | shadow registers | |
| 48 | * +--------------------+ |
| 49 | * v |
| 50 | * VFP or lcd/digit_enable |
| 51 | * v |
| 52 | * +--------------------+ |
| 53 | * | registers | |
| 54 | * +--------------------+ |
| 55 | */ |
| 56 | |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 57 | struct ovl_priv_data { |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 58 | /* If true, cache changed, but not written to shadow registers. Set |
| 59 | * in apply(), cleared when registers written. */ |
| 60 | bool dirty; |
| 61 | /* If true, shadow registers contain changed values not yet in real |
| 62 | * registers. Set when writing to shadow registers, cleared at |
| 63 | * VSYNC/EVSYNC */ |
| 64 | bool shadow_dirty; |
| 65 | |
| 66 | bool enabled; |
| 67 | |
| 68 | struct omap_overlay_info info; |
| 69 | |
| 70 | enum omap_channel channel; |
| 71 | |
| 72 | u32 fifo_low; |
| 73 | u32 fifo_high; |
| 74 | }; |
| 75 | |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame^] | 76 | struct mgr_priv_data { |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 77 | /* If true, cache changed, but not written to shadow registers. Set |
| 78 | * in apply(), cleared when registers written. */ |
| 79 | bool dirty; |
| 80 | /* If true, shadow registers contain changed values not yet in real |
| 81 | * registers. Set when writing to shadow registers, cleared at |
| 82 | * VSYNC/EVSYNC */ |
| 83 | bool shadow_dirty; |
| 84 | |
| 85 | struct omap_overlay_manager_info info; |
| 86 | |
| 87 | bool manual_update; |
| 88 | bool do_manual_update; |
| 89 | }; |
| 90 | |
| 91 | static struct { |
| 92 | spinlock_t lock; |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 93 | struct ovl_priv_data ovl_priv_data_array[MAX_DSS_OVERLAYS]; |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame^] | 94 | struct mgr_priv_data mgr_priv_data_array[MAX_DSS_MANAGERS]; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 95 | |
| 96 | bool irq_enabled; |
| 97 | } dss_cache; |
| 98 | |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 99 | static struct ovl_priv_data *get_ovl_priv(struct omap_overlay *ovl) |
| 100 | { |
| 101 | return &dss_cache.ovl_priv_data_array[ovl->id]; |
| 102 | } |
| 103 | |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame^] | 104 | static struct mgr_priv_data *get_mgr_priv(struct omap_overlay_manager *mgr) |
| 105 | { |
| 106 | return &dss_cache.mgr_priv_data_array[mgr->id]; |
| 107 | } |
| 108 | |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 109 | void dss_apply_init(void) |
| 110 | { |
| 111 | spin_lock_init(&dss_cache.lock); |
| 112 | } |
| 113 | |
| 114 | static bool ovl_manual_update(struct omap_overlay *ovl) |
| 115 | { |
| 116 | return ovl->manager->device->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE; |
| 117 | } |
| 118 | |
| 119 | static bool mgr_manual_update(struct omap_overlay_manager *mgr) |
| 120 | { |
| 121 | return mgr->device->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE; |
| 122 | } |
| 123 | |
| 124 | static int overlay_enabled(struct omap_overlay *ovl) |
| 125 | { |
| 126 | return ovl->info.enabled && ovl->manager && ovl->manager->device; |
| 127 | } |
| 128 | |
| 129 | int dss_mgr_wait_for_go(struct omap_overlay_manager *mgr) |
| 130 | { |
| 131 | unsigned long timeout = msecs_to_jiffies(500); |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame^] | 132 | struct mgr_priv_data *mp; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 133 | u32 irq; |
| 134 | int r; |
| 135 | int i; |
| 136 | struct omap_dss_device *dssdev = mgr->device; |
| 137 | |
| 138 | if (!dssdev || dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) |
| 139 | return 0; |
| 140 | |
| 141 | if (mgr_manual_update(mgr)) |
| 142 | return 0; |
| 143 | |
Tomi Valkeinen | bc1a951 | 2011-11-15 11:20:13 +0200 | [diff] [blame] | 144 | irq = dispc_mgr_get_vsync_irq(mgr->id); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 145 | |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame^] | 146 | mp = get_mgr_priv(mgr); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 147 | i = 0; |
| 148 | while (1) { |
| 149 | unsigned long flags; |
| 150 | bool shadow_dirty, dirty; |
| 151 | |
| 152 | spin_lock_irqsave(&dss_cache.lock, flags); |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame^] | 153 | dirty = mp->dirty; |
| 154 | shadow_dirty = mp->shadow_dirty; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 155 | spin_unlock_irqrestore(&dss_cache.lock, flags); |
| 156 | |
| 157 | if (!dirty && !shadow_dirty) { |
| 158 | r = 0; |
| 159 | break; |
| 160 | } |
| 161 | |
| 162 | /* 4 iterations is the worst case: |
| 163 | * 1 - initial iteration, dirty = true (between VFP and VSYNC) |
| 164 | * 2 - first VSYNC, dirty = true |
| 165 | * 3 - dirty = false, shadow_dirty = true |
| 166 | * 4 - shadow_dirty = false */ |
| 167 | if (i++ == 3) { |
| 168 | DSSERR("mgr(%d)->wait_for_go() not finishing\n", |
| 169 | mgr->id); |
| 170 | r = 0; |
| 171 | break; |
| 172 | } |
| 173 | |
| 174 | r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout); |
| 175 | if (r == -ERESTARTSYS) |
| 176 | break; |
| 177 | |
| 178 | if (r) { |
| 179 | DSSERR("mgr(%d)->wait_for_go() timeout\n", mgr->id); |
| 180 | break; |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | return r; |
| 185 | } |
| 186 | |
| 187 | int dss_mgr_wait_for_go_ovl(struct omap_overlay *ovl) |
| 188 | { |
| 189 | unsigned long timeout = msecs_to_jiffies(500); |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 190 | struct ovl_priv_data *op; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 191 | struct omap_dss_device *dssdev; |
| 192 | u32 irq; |
| 193 | int r; |
| 194 | int i; |
| 195 | |
| 196 | if (!ovl->manager) |
| 197 | return 0; |
| 198 | |
| 199 | dssdev = ovl->manager->device; |
| 200 | |
| 201 | if (!dssdev || dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) |
| 202 | return 0; |
| 203 | |
| 204 | if (ovl_manual_update(ovl)) |
| 205 | return 0; |
| 206 | |
Tomi Valkeinen | bc1a951 | 2011-11-15 11:20:13 +0200 | [diff] [blame] | 207 | irq = dispc_mgr_get_vsync_irq(ovl->manager->id); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 208 | |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 209 | op = get_ovl_priv(ovl); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 210 | i = 0; |
| 211 | while (1) { |
| 212 | unsigned long flags; |
| 213 | bool shadow_dirty, dirty; |
| 214 | |
| 215 | spin_lock_irqsave(&dss_cache.lock, flags); |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 216 | dirty = op->dirty; |
| 217 | shadow_dirty = op->shadow_dirty; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 218 | spin_unlock_irqrestore(&dss_cache.lock, flags); |
| 219 | |
| 220 | if (!dirty && !shadow_dirty) { |
| 221 | r = 0; |
| 222 | break; |
| 223 | } |
| 224 | |
| 225 | /* 4 iterations is the worst case: |
| 226 | * 1 - initial iteration, dirty = true (between VFP and VSYNC) |
| 227 | * 2 - first VSYNC, dirty = true |
| 228 | * 3 - dirty = false, shadow_dirty = true |
| 229 | * 4 - shadow_dirty = false */ |
| 230 | if (i++ == 3) { |
| 231 | DSSERR("ovl(%d)->wait_for_go() not finishing\n", |
| 232 | ovl->id); |
| 233 | r = 0; |
| 234 | break; |
| 235 | } |
| 236 | |
| 237 | r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout); |
| 238 | if (r == -ERESTARTSYS) |
| 239 | break; |
| 240 | |
| 241 | if (r) { |
| 242 | DSSERR("ovl(%d)->wait_for_go() timeout\n", ovl->id); |
| 243 | break; |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | return r; |
| 248 | } |
| 249 | |
Tomi Valkeinen | f6a5e08 | 2011-11-15 11:47:39 +0200 | [diff] [blame] | 250 | static int dss_ovl_write_regs(struct omap_overlay *ovl) |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 251 | { |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 252 | struct ovl_priv_data *op; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 253 | struct omap_overlay_info *oi; |
| 254 | bool ilace, replication; |
| 255 | int r; |
| 256 | |
Tomi Valkeinen | f6a5e08 | 2011-11-15 11:47:39 +0200 | [diff] [blame] | 257 | DSSDBGF("%d", ovl->id); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 258 | |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 259 | op = get_ovl_priv(ovl); |
| 260 | oi = &op->info; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 261 | |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 262 | if (!op->enabled) { |
Tomi Valkeinen | f6a5e08 | 2011-11-15 11:47:39 +0200 | [diff] [blame] | 263 | dispc_ovl_enable(ovl->id, 0); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 264 | return 0; |
| 265 | } |
| 266 | |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 267 | replication = dss_use_replication(ovl->manager->device, oi->color_mode); |
| 268 | |
| 269 | ilace = ovl->manager->device->type == OMAP_DISPLAY_TYPE_VENC; |
| 270 | |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 271 | dispc_ovl_set_channel_out(ovl->id, op->channel); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 272 | |
Tomi Valkeinen | f6a5e08 | 2011-11-15 11:47:39 +0200 | [diff] [blame] | 273 | r = dispc_ovl_setup(ovl->id, oi, ilace, replication); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 274 | if (r) { |
| 275 | /* this shouldn't happen */ |
Tomi Valkeinen | f6a5e08 | 2011-11-15 11:47:39 +0200 | [diff] [blame] | 276 | DSSERR("dispc_ovl_setup failed for ovl %d\n", ovl->id); |
| 277 | dispc_ovl_enable(ovl->id, 0); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 278 | return r; |
| 279 | } |
| 280 | |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 281 | dispc_ovl_set_fifo_threshold(ovl->id, op->fifo_low, op->fifo_high); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 282 | |
Tomi Valkeinen | f6a5e08 | 2011-11-15 11:47:39 +0200 | [diff] [blame] | 283 | dispc_ovl_enable(ovl->id, 1); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 284 | |
| 285 | return 0; |
| 286 | } |
| 287 | |
Tomi Valkeinen | f6a5e08 | 2011-11-15 11:47:39 +0200 | [diff] [blame] | 288 | static void dss_mgr_write_regs(struct omap_overlay_manager *mgr) |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 289 | { |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame^] | 290 | struct mgr_priv_data *mp; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 291 | struct omap_overlay_manager_info *mi; |
| 292 | |
Tomi Valkeinen | f6a5e08 | 2011-11-15 11:47:39 +0200 | [diff] [blame] | 293 | DSSDBGF("%d", mgr->id); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 294 | |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame^] | 295 | mp = get_mgr_priv(mgr); |
| 296 | mi = &mp->info; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 297 | |
Tomi Valkeinen | f6a5e08 | 2011-11-15 11:47:39 +0200 | [diff] [blame] | 298 | dispc_mgr_setup(mgr->id, mi); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 299 | } |
| 300 | |
Tomi Valkeinen | f6a5e08 | 2011-11-15 11:47:39 +0200 | [diff] [blame] | 301 | /* dss_write_regs() tries to write values from cache to shadow registers. |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 302 | * It writes only to those managers/overlays that are not busy. |
| 303 | * returns 0 if everything could be written to shadow registers. |
| 304 | * returns 1 if not everything could be written to shadow registers. */ |
Tomi Valkeinen | f6a5e08 | 2011-11-15 11:47:39 +0200 | [diff] [blame] | 305 | static int dss_write_regs(void) |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 306 | { |
Tomi Valkeinen | f6a5e08 | 2011-11-15 11:47:39 +0200 | [diff] [blame] | 307 | struct omap_overlay *ovl; |
| 308 | struct omap_overlay_manager *mgr; |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 309 | struct ovl_priv_data *op; |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame^] | 310 | struct mgr_priv_data *mp; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 311 | const int num_ovls = dss_feat_get_num_ovls(); |
| 312 | const int num_mgrs = dss_feat_get_num_mgrs(); |
| 313 | int i; |
| 314 | int r; |
| 315 | bool mgr_busy[MAX_DSS_MANAGERS]; |
| 316 | bool mgr_go[MAX_DSS_MANAGERS]; |
| 317 | bool busy; |
| 318 | |
| 319 | r = 0; |
| 320 | busy = false; |
| 321 | |
| 322 | for (i = 0; i < num_mgrs; i++) { |
| 323 | mgr_busy[i] = dispc_mgr_go_busy(i); |
| 324 | mgr_go[i] = false; |
| 325 | } |
| 326 | |
| 327 | /* Commit overlay settings */ |
| 328 | for (i = 0; i < num_ovls; ++i) { |
Tomi Valkeinen | f6a5e08 | 2011-11-15 11:47:39 +0200 | [diff] [blame] | 329 | ovl = omap_dss_get_overlay(i); |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 330 | op = get_ovl_priv(ovl); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 331 | |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 332 | if (!op->dirty) |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 333 | continue; |
| 334 | |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame^] | 335 | mp = get_mgr_priv(ovl->manager); |
| 336 | |
| 337 | if (mp->manual_update && !mp->do_manual_update) |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 338 | continue; |
| 339 | |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 340 | if (mgr_busy[op->channel]) { |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 341 | busy = true; |
| 342 | continue; |
| 343 | } |
| 344 | |
Tomi Valkeinen | f6a5e08 | 2011-11-15 11:47:39 +0200 | [diff] [blame] | 345 | r = dss_ovl_write_regs(ovl); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 346 | if (r) |
Tomi Valkeinen | f6a5e08 | 2011-11-15 11:47:39 +0200 | [diff] [blame] | 347 | DSSERR("dss_ovl_write_regs %d failed\n", i); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 348 | |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 349 | op->dirty = false; |
| 350 | op->shadow_dirty = true; |
| 351 | mgr_go[op->channel] = true; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | /* Commit manager settings */ |
| 355 | for (i = 0; i < num_mgrs; ++i) { |
Tomi Valkeinen | f6a5e08 | 2011-11-15 11:47:39 +0200 | [diff] [blame] | 356 | mgr = omap_dss_get_overlay_manager(i); |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame^] | 357 | mp = get_mgr_priv(mgr); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 358 | |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame^] | 359 | if (!mp->dirty) |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 360 | continue; |
| 361 | |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame^] | 362 | if (mp->manual_update && !mp->do_manual_update) |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 363 | continue; |
| 364 | |
| 365 | if (mgr_busy[i]) { |
| 366 | busy = true; |
| 367 | continue; |
| 368 | } |
| 369 | |
Tomi Valkeinen | f6a5e08 | 2011-11-15 11:47:39 +0200 | [diff] [blame] | 370 | dss_mgr_write_regs(mgr); |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame^] | 371 | mp->dirty = false; |
| 372 | mp->shadow_dirty = true; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 373 | mgr_go[i] = true; |
| 374 | } |
| 375 | |
| 376 | /* set GO */ |
| 377 | for (i = 0; i < num_mgrs; ++i) { |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame^] | 378 | mgr = omap_dss_get_overlay_manager(i); |
| 379 | mp = get_mgr_priv(mgr); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 380 | |
| 381 | if (!mgr_go[i]) |
| 382 | continue; |
| 383 | |
| 384 | /* We don't need GO with manual update display. LCD iface will |
| 385 | * always be turned off after frame, and new settings will be |
| 386 | * taken in to use at next update */ |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame^] | 387 | if (!mp->manual_update) |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 388 | dispc_mgr_go(i); |
| 389 | } |
| 390 | |
| 391 | if (busy) |
| 392 | r = 1; |
| 393 | else |
| 394 | r = 0; |
| 395 | |
| 396 | return r; |
| 397 | } |
| 398 | |
| 399 | void dss_mgr_start_update(struct omap_overlay_manager *mgr) |
| 400 | { |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame^] | 401 | struct mgr_priv_data *mp = get_mgr_priv(mgr); |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 402 | struct ovl_priv_data *op; |
Tomi Valkeinen | 07e327c | 2011-11-05 10:59:59 +0200 | [diff] [blame] | 403 | struct omap_overlay *ovl; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 404 | |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame^] | 405 | mp->do_manual_update = true; |
Tomi Valkeinen | f6a5e08 | 2011-11-15 11:47:39 +0200 | [diff] [blame] | 406 | dss_write_regs(); |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame^] | 407 | mp->do_manual_update = false; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 408 | |
Tomi Valkeinen | 07e327c | 2011-11-05 10:59:59 +0200 | [diff] [blame] | 409 | list_for_each_entry(ovl, &mgr->overlays, list) { |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 410 | op = get_ovl_priv(ovl); |
| 411 | op->shadow_dirty = false; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 412 | } |
| 413 | |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame^] | 414 | mp->shadow_dirty = false; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 415 | |
Tomi Valkeinen | 7797c6d | 2011-11-04 10:22:46 +0200 | [diff] [blame] | 416 | dispc_mgr_enable(mgr->id, true); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 417 | } |
| 418 | |
Tomi Valkeinen | dbce016 | 2011-11-15 11:18:12 +0200 | [diff] [blame] | 419 | static void dss_apply_irq_handler(void *data, u32 mask); |
| 420 | |
| 421 | static void dss_register_vsync_isr(void) |
| 422 | { |
Tomi Valkeinen | bc1a951 | 2011-11-15 11:20:13 +0200 | [diff] [blame] | 423 | const int num_mgrs = dss_feat_get_num_mgrs(); |
Tomi Valkeinen | dbce016 | 2011-11-15 11:18:12 +0200 | [diff] [blame] | 424 | u32 mask; |
Tomi Valkeinen | bc1a951 | 2011-11-15 11:20:13 +0200 | [diff] [blame] | 425 | int r, i; |
Tomi Valkeinen | dbce016 | 2011-11-15 11:18:12 +0200 | [diff] [blame] | 426 | |
Tomi Valkeinen | bc1a951 | 2011-11-15 11:20:13 +0200 | [diff] [blame] | 427 | mask = 0; |
| 428 | for (i = 0; i < num_mgrs; ++i) |
| 429 | mask |= dispc_mgr_get_vsync_irq(i); |
Tomi Valkeinen | dbce016 | 2011-11-15 11:18:12 +0200 | [diff] [blame] | 430 | |
| 431 | r = omap_dispc_register_isr(dss_apply_irq_handler, NULL, mask); |
| 432 | WARN_ON(r); |
| 433 | |
| 434 | dss_cache.irq_enabled = true; |
| 435 | } |
| 436 | |
| 437 | static void dss_unregister_vsync_isr(void) |
| 438 | { |
Tomi Valkeinen | bc1a951 | 2011-11-15 11:20:13 +0200 | [diff] [blame] | 439 | const int num_mgrs = dss_feat_get_num_mgrs(); |
Tomi Valkeinen | dbce016 | 2011-11-15 11:18:12 +0200 | [diff] [blame] | 440 | u32 mask; |
Tomi Valkeinen | bc1a951 | 2011-11-15 11:20:13 +0200 | [diff] [blame] | 441 | int r, i; |
Tomi Valkeinen | dbce016 | 2011-11-15 11:18:12 +0200 | [diff] [blame] | 442 | |
Tomi Valkeinen | bc1a951 | 2011-11-15 11:20:13 +0200 | [diff] [blame] | 443 | mask = 0; |
| 444 | for (i = 0; i < num_mgrs; ++i) |
| 445 | mask |= dispc_mgr_get_vsync_irq(i); |
Tomi Valkeinen | dbce016 | 2011-11-15 11:18:12 +0200 | [diff] [blame] | 446 | |
| 447 | r = omap_dispc_unregister_isr(dss_apply_irq_handler, NULL, mask); |
| 448 | WARN_ON(r); |
| 449 | |
| 450 | dss_cache.irq_enabled = false; |
| 451 | } |
| 452 | |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 453 | static void dss_apply_irq_handler(void *data, u32 mask) |
| 454 | { |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 455 | struct omap_overlay *ovl; |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame^] | 456 | struct omap_overlay_manager *mgr; |
| 457 | struct mgr_priv_data *mp; |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 458 | struct ovl_priv_data *op; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 459 | const int num_ovls = dss_feat_get_num_ovls(); |
| 460 | const int num_mgrs = dss_feat_get_num_mgrs(); |
| 461 | int i, r; |
| 462 | bool mgr_busy[MAX_DSS_MANAGERS]; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 463 | |
| 464 | for (i = 0; i < num_mgrs; i++) |
| 465 | mgr_busy[i] = dispc_mgr_go_busy(i); |
| 466 | |
| 467 | spin_lock(&dss_cache.lock); |
| 468 | |
| 469 | for (i = 0; i < num_ovls; ++i) { |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 470 | ovl = omap_dss_get_overlay(i); |
| 471 | op = get_ovl_priv(ovl); |
| 472 | if (!mgr_busy[op->channel]) |
| 473 | op->shadow_dirty = false; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | for (i = 0; i < num_mgrs; ++i) { |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame^] | 477 | mgr = omap_dss_get_overlay_manager(i); |
| 478 | mp = get_mgr_priv(mgr); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 479 | if (!mgr_busy[i]) |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame^] | 480 | mp->shadow_dirty = false; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 481 | } |
| 482 | |
Tomi Valkeinen | f6a5e08 | 2011-11-15 11:47:39 +0200 | [diff] [blame] | 483 | r = dss_write_regs(); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 484 | if (r == 1) |
| 485 | goto end; |
| 486 | |
| 487 | /* re-read busy flags */ |
| 488 | for (i = 0; i < num_mgrs; i++) |
| 489 | mgr_busy[i] = dispc_mgr_go_busy(i); |
| 490 | |
| 491 | /* keep running as long as there are busy managers, so that |
| 492 | * we can collect overlay-applied information */ |
| 493 | for (i = 0; i < num_mgrs; ++i) { |
| 494 | if (mgr_busy[i]) |
| 495 | goto end; |
| 496 | } |
| 497 | |
Tomi Valkeinen | dbce016 | 2011-11-15 11:18:12 +0200 | [diff] [blame] | 498 | dss_unregister_vsync_isr(); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 499 | |
| 500 | end: |
| 501 | spin_unlock(&dss_cache.lock); |
| 502 | } |
| 503 | |
| 504 | static int omap_dss_mgr_apply_ovl(struct omap_overlay *ovl) |
| 505 | { |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 506 | struct ovl_priv_data *op; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 507 | struct omap_dss_device *dssdev; |
| 508 | |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 509 | op = get_ovl_priv(ovl); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 510 | |
| 511 | if (ovl->manager_changed) { |
| 512 | ovl->manager_changed = false; |
| 513 | ovl->info_dirty = true; |
| 514 | } |
| 515 | |
| 516 | if (!overlay_enabled(ovl)) { |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 517 | if (op->enabled) { |
| 518 | op->enabled = false; |
| 519 | op->dirty = true; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 520 | } |
| 521 | return 0; |
| 522 | } |
| 523 | |
| 524 | if (!ovl->info_dirty) |
| 525 | return 0; |
| 526 | |
| 527 | dssdev = ovl->manager->device; |
| 528 | |
| 529 | if (dss_check_overlay(ovl, dssdev)) { |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 530 | if (op->enabled) { |
| 531 | op->enabled = false; |
| 532 | op->dirty = true; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 533 | } |
| 534 | return -EINVAL; |
| 535 | } |
| 536 | |
| 537 | ovl->info_dirty = false; |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 538 | op->dirty = true; |
| 539 | op->info = ovl->info; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 540 | |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 541 | op->channel = ovl->manager->id; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 542 | |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 543 | op->enabled = true; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 544 | |
| 545 | return 0; |
| 546 | } |
| 547 | |
| 548 | static void omap_dss_mgr_apply_mgr(struct omap_overlay_manager *mgr) |
| 549 | { |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame^] | 550 | struct mgr_priv_data *mp; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 551 | |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame^] | 552 | mp = get_mgr_priv(mgr); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 553 | |
| 554 | if (mgr->device_changed) { |
| 555 | mgr->device_changed = false; |
| 556 | mgr->info_dirty = true; |
| 557 | } |
| 558 | |
| 559 | if (!mgr->info_dirty) |
| 560 | return; |
| 561 | |
| 562 | if (!mgr->device) |
| 563 | return; |
| 564 | |
| 565 | mgr->info_dirty = false; |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame^] | 566 | mp->dirty = true; |
| 567 | mp->info = mgr->info; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 568 | |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame^] | 569 | mp->manual_update = mgr_manual_update(mgr); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | static void omap_dss_mgr_apply_ovl_fifos(struct omap_overlay *ovl) |
| 573 | { |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 574 | struct ovl_priv_data *op; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 575 | struct omap_dss_device *dssdev; |
| 576 | u32 size, burst_size; |
| 577 | |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 578 | op = get_ovl_priv(ovl); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 579 | |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 580 | if (!op->enabled) |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 581 | return; |
| 582 | |
| 583 | dssdev = ovl->manager->device; |
| 584 | |
| 585 | size = dispc_ovl_get_fifo_size(ovl->id); |
| 586 | |
| 587 | burst_size = dispc_ovl_get_burst_size(ovl->id); |
| 588 | |
| 589 | switch (dssdev->type) { |
| 590 | case OMAP_DISPLAY_TYPE_DPI: |
| 591 | case OMAP_DISPLAY_TYPE_DBI: |
| 592 | case OMAP_DISPLAY_TYPE_SDI: |
| 593 | case OMAP_DISPLAY_TYPE_VENC: |
| 594 | case OMAP_DISPLAY_TYPE_HDMI: |
| 595 | default_get_overlay_fifo_thresholds(ovl->id, size, |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 596 | burst_size, &op->fifo_low, |
| 597 | &op->fifo_high); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 598 | break; |
| 599 | #ifdef CONFIG_OMAP2_DSS_DSI |
| 600 | case OMAP_DISPLAY_TYPE_DSI: |
| 601 | dsi_get_overlay_fifo_thresholds(ovl->id, size, |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 602 | burst_size, &op->fifo_low, |
| 603 | &op->fifo_high); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 604 | break; |
| 605 | #endif |
| 606 | default: |
| 607 | BUG(); |
| 608 | } |
| 609 | } |
| 610 | |
| 611 | int omap_dss_mgr_apply(struct omap_overlay_manager *mgr) |
| 612 | { |
Tomi Valkeinen | 07e327c | 2011-11-05 10:59:59 +0200 | [diff] [blame] | 613 | int r; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 614 | unsigned long flags; |
Tomi Valkeinen | 07e327c | 2011-11-05 10:59:59 +0200 | [diff] [blame] | 615 | struct omap_overlay *ovl; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 616 | |
| 617 | DSSDBG("omap_dss_mgr_apply(%s)\n", mgr->name); |
| 618 | |
| 619 | r = dispc_runtime_get(); |
| 620 | if (r) |
| 621 | return r; |
| 622 | |
| 623 | spin_lock_irqsave(&dss_cache.lock, flags); |
| 624 | |
| 625 | /* Configure overlays */ |
Tomi Valkeinen | 07e327c | 2011-11-05 10:59:59 +0200 | [diff] [blame] | 626 | list_for_each_entry(ovl, &mgr->overlays, list) |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 627 | omap_dss_mgr_apply_ovl(ovl); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 628 | |
| 629 | /* Configure manager */ |
| 630 | omap_dss_mgr_apply_mgr(mgr); |
| 631 | |
| 632 | /* Configure overlay fifos */ |
Tomi Valkeinen | 07e327c | 2011-11-05 10:59:59 +0200 | [diff] [blame] | 633 | list_for_each_entry(ovl, &mgr->overlays, list) |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 634 | omap_dss_mgr_apply_ovl_fifos(ovl); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 635 | |
| 636 | r = 0; |
Tomi Valkeinen | 04f6643 | 2011-11-07 15:04:01 +0200 | [diff] [blame] | 637 | if (mgr->enabled && !mgr_manual_update(mgr)) { |
Tomi Valkeinen | dbce016 | 2011-11-15 11:18:12 +0200 | [diff] [blame] | 638 | if (!dss_cache.irq_enabled) |
| 639 | dss_register_vsync_isr(); |
Tomi Valkeinen | 18135ea | 2011-11-04 09:35:59 +0200 | [diff] [blame] | 640 | |
Tomi Valkeinen | f6a5e08 | 2011-11-15 11:47:39 +0200 | [diff] [blame] | 641 | dss_write_regs(); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 642 | } |
| 643 | |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 644 | spin_unlock_irqrestore(&dss_cache.lock, flags); |
| 645 | |
| 646 | dispc_runtime_put(); |
| 647 | |
| 648 | return r; |
| 649 | } |
| 650 | |
Tomi Valkeinen | 7797c6d | 2011-11-04 10:22:46 +0200 | [diff] [blame] | 651 | void dss_mgr_enable(struct omap_overlay_manager *mgr) |
| 652 | { |
| 653 | dispc_mgr_enable(mgr->id, true); |
Tomi Valkeinen | be72917 | 2011-11-04 10:30:47 +0200 | [diff] [blame] | 654 | mgr->enabled = true; |
Tomi Valkeinen | 7797c6d | 2011-11-04 10:22:46 +0200 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | void dss_mgr_disable(struct omap_overlay_manager *mgr) |
| 658 | { |
| 659 | dispc_mgr_enable(mgr->id, false); |
Tomi Valkeinen | be72917 | 2011-11-04 10:30:47 +0200 | [diff] [blame] | 660 | mgr->enabled = false; |
Tomi Valkeinen | 7797c6d | 2011-11-04 10:22:46 +0200 | [diff] [blame] | 661 | } |
| 662 | |