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 | * +--------------------+ |
Tomi Valkeinen | d09c7aa | 2011-11-15 12:04:43 +0200 | [diff] [blame] | 41 | * | info | |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 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 { |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 92 | struct ovl_priv_data ovl_priv_data_array[MAX_DSS_OVERLAYS]; |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame] | 93 | struct mgr_priv_data mgr_priv_data_array[MAX_DSS_MANAGERS]; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 94 | |
| 95 | bool irq_enabled; |
Tomi Valkeinen | d09c7aa | 2011-11-15 12:04:43 +0200 | [diff] [blame] | 96 | } dss_data; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 97 | |
Tomi Valkeinen | d09c7aa | 2011-11-15 12:04:43 +0200 | [diff] [blame] | 98 | /* protects dss_data */ |
Tomi Valkeinen | 063fd70 | 2011-11-15 12:04:10 +0200 | [diff] [blame] | 99 | static spinlock_t data_lock; |
Tomi Valkeinen | 5558db3 | 2011-11-15 14:28:48 +0200 | [diff] [blame] | 100 | /* lock for blocking functions */ |
| 101 | static DEFINE_MUTEX(apply_lock); |
Tomi Valkeinen | 063fd70 | 2011-11-15 12:04:10 +0200 | [diff] [blame] | 102 | |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 103 | static struct ovl_priv_data *get_ovl_priv(struct omap_overlay *ovl) |
| 104 | { |
Tomi Valkeinen | d09c7aa | 2011-11-15 12:04:43 +0200 | [diff] [blame] | 105 | return &dss_data.ovl_priv_data_array[ovl->id]; |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 106 | } |
| 107 | |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame] | 108 | static struct mgr_priv_data *get_mgr_priv(struct omap_overlay_manager *mgr) |
| 109 | { |
Tomi Valkeinen | d09c7aa | 2011-11-15 12:04:43 +0200 | [diff] [blame] | 110 | return &dss_data.mgr_priv_data_array[mgr->id]; |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame] | 111 | } |
| 112 | |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 113 | void dss_apply_init(void) |
| 114 | { |
Tomi Valkeinen | 063fd70 | 2011-11-15 12:04:10 +0200 | [diff] [blame] | 115 | spin_lock_init(&data_lock); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | static bool ovl_manual_update(struct omap_overlay *ovl) |
| 119 | { |
| 120 | return ovl->manager->device->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE; |
| 121 | } |
| 122 | |
| 123 | static bool mgr_manual_update(struct omap_overlay_manager *mgr) |
| 124 | { |
| 125 | return mgr->device->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE; |
| 126 | } |
| 127 | |
| 128 | static int overlay_enabled(struct omap_overlay *ovl) |
| 129 | { |
| 130 | return ovl->info.enabled && ovl->manager && ovl->manager->device; |
| 131 | } |
| 132 | |
| 133 | int dss_mgr_wait_for_go(struct omap_overlay_manager *mgr) |
| 134 | { |
| 135 | unsigned long timeout = msecs_to_jiffies(500); |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame] | 136 | struct mgr_priv_data *mp; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 137 | u32 irq; |
| 138 | int r; |
| 139 | int i; |
| 140 | struct omap_dss_device *dssdev = mgr->device; |
| 141 | |
| 142 | if (!dssdev || dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) |
| 143 | return 0; |
| 144 | |
| 145 | if (mgr_manual_update(mgr)) |
| 146 | return 0; |
| 147 | |
Tomi Valkeinen | bc1a951 | 2011-11-15 11:20:13 +0200 | [diff] [blame] | 148 | irq = dispc_mgr_get_vsync_irq(mgr->id); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 149 | |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame] | 150 | mp = get_mgr_priv(mgr); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 151 | i = 0; |
| 152 | while (1) { |
| 153 | unsigned long flags; |
| 154 | bool shadow_dirty, dirty; |
| 155 | |
Tomi Valkeinen | 063fd70 | 2011-11-15 12:04:10 +0200 | [diff] [blame] | 156 | spin_lock_irqsave(&data_lock, flags); |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame] | 157 | dirty = mp->dirty; |
| 158 | shadow_dirty = mp->shadow_dirty; |
Tomi Valkeinen | 063fd70 | 2011-11-15 12:04:10 +0200 | [diff] [blame] | 159 | spin_unlock_irqrestore(&data_lock, flags); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 160 | |
| 161 | if (!dirty && !shadow_dirty) { |
| 162 | r = 0; |
| 163 | break; |
| 164 | } |
| 165 | |
| 166 | /* 4 iterations is the worst case: |
| 167 | * 1 - initial iteration, dirty = true (between VFP and VSYNC) |
| 168 | * 2 - first VSYNC, dirty = true |
| 169 | * 3 - dirty = false, shadow_dirty = true |
| 170 | * 4 - shadow_dirty = false */ |
| 171 | if (i++ == 3) { |
| 172 | DSSERR("mgr(%d)->wait_for_go() not finishing\n", |
| 173 | mgr->id); |
| 174 | r = 0; |
| 175 | break; |
| 176 | } |
| 177 | |
| 178 | r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout); |
| 179 | if (r == -ERESTARTSYS) |
| 180 | break; |
| 181 | |
| 182 | if (r) { |
| 183 | DSSERR("mgr(%d)->wait_for_go() timeout\n", mgr->id); |
| 184 | break; |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | return r; |
| 189 | } |
| 190 | |
| 191 | int dss_mgr_wait_for_go_ovl(struct omap_overlay *ovl) |
| 192 | { |
| 193 | unsigned long timeout = msecs_to_jiffies(500); |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 194 | struct ovl_priv_data *op; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 195 | struct omap_dss_device *dssdev; |
| 196 | u32 irq; |
| 197 | int r; |
| 198 | int i; |
| 199 | |
| 200 | if (!ovl->manager) |
| 201 | return 0; |
| 202 | |
| 203 | dssdev = ovl->manager->device; |
| 204 | |
| 205 | if (!dssdev || dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) |
| 206 | return 0; |
| 207 | |
| 208 | if (ovl_manual_update(ovl)) |
| 209 | return 0; |
| 210 | |
Tomi Valkeinen | bc1a951 | 2011-11-15 11:20:13 +0200 | [diff] [blame] | 211 | irq = dispc_mgr_get_vsync_irq(ovl->manager->id); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 212 | |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 213 | op = get_ovl_priv(ovl); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 214 | i = 0; |
| 215 | while (1) { |
| 216 | unsigned long flags; |
| 217 | bool shadow_dirty, dirty; |
| 218 | |
Tomi Valkeinen | 063fd70 | 2011-11-15 12:04:10 +0200 | [diff] [blame] | 219 | spin_lock_irqsave(&data_lock, flags); |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 220 | dirty = op->dirty; |
| 221 | shadow_dirty = op->shadow_dirty; |
Tomi Valkeinen | 063fd70 | 2011-11-15 12:04:10 +0200 | [diff] [blame] | 222 | spin_unlock_irqrestore(&data_lock, flags); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 223 | |
| 224 | if (!dirty && !shadow_dirty) { |
| 225 | r = 0; |
| 226 | break; |
| 227 | } |
| 228 | |
| 229 | /* 4 iterations is the worst case: |
| 230 | * 1 - initial iteration, dirty = true (between VFP and VSYNC) |
| 231 | * 2 - first VSYNC, dirty = true |
| 232 | * 3 - dirty = false, shadow_dirty = true |
| 233 | * 4 - shadow_dirty = false */ |
| 234 | if (i++ == 3) { |
| 235 | DSSERR("ovl(%d)->wait_for_go() not finishing\n", |
| 236 | ovl->id); |
| 237 | r = 0; |
| 238 | break; |
| 239 | } |
| 240 | |
| 241 | r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout); |
| 242 | if (r == -ERESTARTSYS) |
| 243 | break; |
| 244 | |
| 245 | if (r) { |
| 246 | DSSERR("ovl(%d)->wait_for_go() timeout\n", ovl->id); |
| 247 | break; |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | return r; |
| 252 | } |
| 253 | |
Tomi Valkeinen | f6a5e08 | 2011-11-15 11:47:39 +0200 | [diff] [blame] | 254 | static int dss_ovl_write_regs(struct omap_overlay *ovl) |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 255 | { |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 256 | struct ovl_priv_data *op; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 257 | struct omap_overlay_info *oi; |
| 258 | bool ilace, replication; |
| 259 | int r; |
| 260 | |
Tomi Valkeinen | f6a5e08 | 2011-11-15 11:47:39 +0200 | [diff] [blame] | 261 | DSSDBGF("%d", ovl->id); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 262 | |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 263 | op = get_ovl_priv(ovl); |
| 264 | oi = &op->info; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 265 | |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 266 | if (!op->enabled) { |
Tomi Valkeinen | f6a5e08 | 2011-11-15 11:47:39 +0200 | [diff] [blame] | 267 | dispc_ovl_enable(ovl->id, 0); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 268 | return 0; |
| 269 | } |
| 270 | |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 271 | replication = dss_use_replication(ovl->manager->device, oi->color_mode); |
| 272 | |
| 273 | ilace = ovl->manager->device->type == OMAP_DISPLAY_TYPE_VENC; |
| 274 | |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 275 | dispc_ovl_set_channel_out(ovl->id, op->channel); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 276 | |
Tomi Valkeinen | f6a5e08 | 2011-11-15 11:47:39 +0200 | [diff] [blame] | 277 | r = dispc_ovl_setup(ovl->id, oi, ilace, replication); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 278 | if (r) { |
| 279 | /* this shouldn't happen */ |
Tomi Valkeinen | f6a5e08 | 2011-11-15 11:47:39 +0200 | [diff] [blame] | 280 | DSSERR("dispc_ovl_setup failed for ovl %d\n", ovl->id); |
| 281 | dispc_ovl_enable(ovl->id, 0); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 282 | return r; |
| 283 | } |
| 284 | |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 285 | 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] | 286 | |
Tomi Valkeinen | f6a5e08 | 2011-11-15 11:47:39 +0200 | [diff] [blame] | 287 | dispc_ovl_enable(ovl->id, 1); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 288 | |
| 289 | return 0; |
| 290 | } |
| 291 | |
Tomi Valkeinen | f6a5e08 | 2011-11-15 11:47:39 +0200 | [diff] [blame] | 292 | static void dss_mgr_write_regs(struct omap_overlay_manager *mgr) |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 293 | { |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame] | 294 | struct mgr_priv_data *mp; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 295 | struct omap_overlay_manager_info *mi; |
| 296 | |
Tomi Valkeinen | f6a5e08 | 2011-11-15 11:47:39 +0200 | [diff] [blame] | 297 | DSSDBGF("%d", mgr->id); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 298 | |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame] | 299 | mp = get_mgr_priv(mgr); |
| 300 | mi = &mp->info; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 301 | |
Tomi Valkeinen | f6a5e08 | 2011-11-15 11:47:39 +0200 | [diff] [blame] | 302 | dispc_mgr_setup(mgr->id, mi); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 303 | } |
| 304 | |
Tomi Valkeinen | f6a5e08 | 2011-11-15 11:47:39 +0200 | [diff] [blame] | 305 | /* dss_write_regs() tries to write values from cache to shadow registers. |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 306 | * It writes only to those managers/overlays that are not busy. |
| 307 | * returns 0 if everything could be written to shadow registers. |
| 308 | * returns 1 if not everything could be written to shadow registers. */ |
Tomi Valkeinen | f6a5e08 | 2011-11-15 11:47:39 +0200 | [diff] [blame] | 309 | static int dss_write_regs(void) |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 310 | { |
Tomi Valkeinen | f6a5e08 | 2011-11-15 11:47:39 +0200 | [diff] [blame] | 311 | struct omap_overlay *ovl; |
| 312 | struct omap_overlay_manager *mgr; |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 313 | struct ovl_priv_data *op; |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame] | 314 | struct mgr_priv_data *mp; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 315 | const int num_ovls = dss_feat_get_num_ovls(); |
| 316 | const int num_mgrs = dss_feat_get_num_mgrs(); |
| 317 | int i; |
| 318 | int r; |
| 319 | bool mgr_busy[MAX_DSS_MANAGERS]; |
| 320 | bool mgr_go[MAX_DSS_MANAGERS]; |
| 321 | bool busy; |
| 322 | |
| 323 | r = 0; |
| 324 | busy = false; |
| 325 | |
| 326 | for (i = 0; i < num_mgrs; i++) { |
| 327 | mgr_busy[i] = dispc_mgr_go_busy(i); |
| 328 | mgr_go[i] = false; |
| 329 | } |
| 330 | |
| 331 | /* Commit overlay settings */ |
| 332 | for (i = 0; i < num_ovls; ++i) { |
Tomi Valkeinen | f6a5e08 | 2011-11-15 11:47:39 +0200 | [diff] [blame] | 333 | ovl = omap_dss_get_overlay(i); |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 334 | op = get_ovl_priv(ovl); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 335 | |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 336 | if (!op->dirty) |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 337 | continue; |
| 338 | |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame] | 339 | mp = get_mgr_priv(ovl->manager); |
| 340 | |
| 341 | if (mp->manual_update && !mp->do_manual_update) |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 342 | continue; |
| 343 | |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 344 | if (mgr_busy[op->channel]) { |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 345 | busy = true; |
| 346 | continue; |
| 347 | } |
| 348 | |
Tomi Valkeinen | f6a5e08 | 2011-11-15 11:47:39 +0200 | [diff] [blame] | 349 | r = dss_ovl_write_regs(ovl); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 350 | if (r) |
Tomi Valkeinen | f6a5e08 | 2011-11-15 11:47:39 +0200 | [diff] [blame] | 351 | DSSERR("dss_ovl_write_regs %d failed\n", i); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 352 | |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 353 | op->dirty = false; |
| 354 | op->shadow_dirty = true; |
| 355 | mgr_go[op->channel] = true; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | /* Commit manager settings */ |
| 359 | for (i = 0; i < num_mgrs; ++i) { |
Tomi Valkeinen | f6a5e08 | 2011-11-15 11:47:39 +0200 | [diff] [blame] | 360 | mgr = omap_dss_get_overlay_manager(i); |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame] | 361 | mp = get_mgr_priv(mgr); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 362 | |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame] | 363 | if (!mp->dirty) |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 364 | continue; |
| 365 | |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame] | 366 | if (mp->manual_update && !mp->do_manual_update) |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 367 | continue; |
| 368 | |
| 369 | if (mgr_busy[i]) { |
| 370 | busy = true; |
| 371 | continue; |
| 372 | } |
| 373 | |
Tomi Valkeinen | f6a5e08 | 2011-11-15 11:47:39 +0200 | [diff] [blame] | 374 | dss_mgr_write_regs(mgr); |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame] | 375 | mp->dirty = false; |
| 376 | mp->shadow_dirty = true; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 377 | mgr_go[i] = true; |
| 378 | } |
| 379 | |
| 380 | /* set GO */ |
| 381 | for (i = 0; i < num_mgrs; ++i) { |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame] | 382 | mgr = omap_dss_get_overlay_manager(i); |
| 383 | mp = get_mgr_priv(mgr); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 384 | |
| 385 | if (!mgr_go[i]) |
| 386 | continue; |
| 387 | |
| 388 | /* We don't need GO with manual update display. LCD iface will |
| 389 | * always be turned off after frame, and new settings will be |
| 390 | * taken in to use at next update */ |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame] | 391 | if (!mp->manual_update) |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 392 | dispc_mgr_go(i); |
| 393 | } |
| 394 | |
| 395 | if (busy) |
| 396 | r = 1; |
| 397 | else |
| 398 | r = 0; |
| 399 | |
| 400 | return r; |
| 401 | } |
| 402 | |
| 403 | void dss_mgr_start_update(struct omap_overlay_manager *mgr) |
| 404 | { |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame] | 405 | struct mgr_priv_data *mp = get_mgr_priv(mgr); |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 406 | struct ovl_priv_data *op; |
Tomi Valkeinen | 07e327c | 2011-11-05 10:59:59 +0200 | [diff] [blame] | 407 | struct omap_overlay *ovl; |
Tomi Valkeinen | e0a2aa5b | 2011-11-15 14:32:57 +0200 | [diff] [blame] | 408 | unsigned long flags; |
| 409 | |
| 410 | spin_lock_irqsave(&data_lock, flags); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 411 | |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame] | 412 | mp->do_manual_update = true; |
Tomi Valkeinen | f6a5e08 | 2011-11-15 11:47:39 +0200 | [diff] [blame] | 413 | dss_write_regs(); |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame] | 414 | mp->do_manual_update = false; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 415 | |
Tomi Valkeinen | 07e327c | 2011-11-05 10:59:59 +0200 | [diff] [blame] | 416 | list_for_each_entry(ovl, &mgr->overlays, list) { |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 417 | op = get_ovl_priv(ovl); |
| 418 | op->shadow_dirty = false; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 419 | } |
| 420 | |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame] | 421 | mp->shadow_dirty = false; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 422 | |
Tomi Valkeinen | 7797c6d | 2011-11-04 10:22:46 +0200 | [diff] [blame] | 423 | dispc_mgr_enable(mgr->id, true); |
Tomi Valkeinen | e0a2aa5b | 2011-11-15 14:32:57 +0200 | [diff] [blame] | 424 | |
| 425 | spin_unlock_irqrestore(&data_lock, flags); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 426 | } |
| 427 | |
Tomi Valkeinen | dbce016 | 2011-11-15 11:18:12 +0200 | [diff] [blame] | 428 | static void dss_apply_irq_handler(void *data, u32 mask); |
| 429 | |
| 430 | static void dss_register_vsync_isr(void) |
| 431 | { |
Tomi Valkeinen | bc1a951 | 2011-11-15 11:20:13 +0200 | [diff] [blame] | 432 | const int num_mgrs = dss_feat_get_num_mgrs(); |
Tomi Valkeinen | dbce016 | 2011-11-15 11:18:12 +0200 | [diff] [blame] | 433 | u32 mask; |
Tomi Valkeinen | bc1a951 | 2011-11-15 11:20:13 +0200 | [diff] [blame] | 434 | int r, i; |
Tomi Valkeinen | dbce016 | 2011-11-15 11:18:12 +0200 | [diff] [blame] | 435 | |
Tomi Valkeinen | bc1a951 | 2011-11-15 11:20:13 +0200 | [diff] [blame] | 436 | mask = 0; |
| 437 | for (i = 0; i < num_mgrs; ++i) |
| 438 | mask |= dispc_mgr_get_vsync_irq(i); |
Tomi Valkeinen | dbce016 | 2011-11-15 11:18:12 +0200 | [diff] [blame] | 439 | |
| 440 | r = omap_dispc_register_isr(dss_apply_irq_handler, NULL, mask); |
| 441 | WARN_ON(r); |
| 442 | |
Tomi Valkeinen | d09c7aa | 2011-11-15 12:04:43 +0200 | [diff] [blame] | 443 | dss_data.irq_enabled = true; |
Tomi Valkeinen | dbce016 | 2011-11-15 11:18:12 +0200 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | static void dss_unregister_vsync_isr(void) |
| 447 | { |
Tomi Valkeinen | bc1a951 | 2011-11-15 11:20:13 +0200 | [diff] [blame] | 448 | const int num_mgrs = dss_feat_get_num_mgrs(); |
Tomi Valkeinen | dbce016 | 2011-11-15 11:18:12 +0200 | [diff] [blame] | 449 | u32 mask; |
Tomi Valkeinen | bc1a951 | 2011-11-15 11:20:13 +0200 | [diff] [blame] | 450 | int r, i; |
Tomi Valkeinen | dbce016 | 2011-11-15 11:18:12 +0200 | [diff] [blame] | 451 | |
Tomi Valkeinen | bc1a951 | 2011-11-15 11:20:13 +0200 | [diff] [blame] | 452 | mask = 0; |
| 453 | for (i = 0; i < num_mgrs; ++i) |
| 454 | mask |= dispc_mgr_get_vsync_irq(i); |
Tomi Valkeinen | dbce016 | 2011-11-15 11:18:12 +0200 | [diff] [blame] | 455 | |
| 456 | r = omap_dispc_unregister_isr(dss_apply_irq_handler, NULL, mask); |
| 457 | WARN_ON(r); |
| 458 | |
Tomi Valkeinen | d09c7aa | 2011-11-15 12:04:43 +0200 | [diff] [blame] | 459 | dss_data.irq_enabled = false; |
Tomi Valkeinen | dbce016 | 2011-11-15 11:18:12 +0200 | [diff] [blame] | 460 | } |
| 461 | |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 462 | static void dss_apply_irq_handler(void *data, u32 mask) |
| 463 | { |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 464 | struct omap_overlay *ovl; |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame] | 465 | struct omap_overlay_manager *mgr; |
| 466 | struct mgr_priv_data *mp; |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 467 | struct ovl_priv_data *op; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 468 | const int num_ovls = dss_feat_get_num_ovls(); |
| 469 | const int num_mgrs = dss_feat_get_num_mgrs(); |
| 470 | int i, r; |
| 471 | bool mgr_busy[MAX_DSS_MANAGERS]; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 472 | |
| 473 | for (i = 0; i < num_mgrs; i++) |
| 474 | mgr_busy[i] = dispc_mgr_go_busy(i); |
| 475 | |
Tomi Valkeinen | 063fd70 | 2011-11-15 12:04:10 +0200 | [diff] [blame] | 476 | spin_lock(&data_lock); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 477 | |
| 478 | for (i = 0; i < num_ovls; ++i) { |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 479 | ovl = omap_dss_get_overlay(i); |
| 480 | op = get_ovl_priv(ovl); |
| 481 | if (!mgr_busy[op->channel]) |
| 482 | op->shadow_dirty = false; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | for (i = 0; i < num_mgrs; ++i) { |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame] | 486 | mgr = omap_dss_get_overlay_manager(i); |
| 487 | mp = get_mgr_priv(mgr); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 488 | if (!mgr_busy[i]) |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame] | 489 | mp->shadow_dirty = false; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 490 | } |
| 491 | |
Tomi Valkeinen | f6a5e08 | 2011-11-15 11:47:39 +0200 | [diff] [blame] | 492 | r = dss_write_regs(); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 493 | if (r == 1) |
| 494 | goto end; |
| 495 | |
| 496 | /* re-read busy flags */ |
| 497 | for (i = 0; i < num_mgrs; i++) |
| 498 | mgr_busy[i] = dispc_mgr_go_busy(i); |
| 499 | |
| 500 | /* keep running as long as there are busy managers, so that |
| 501 | * we can collect overlay-applied information */ |
| 502 | for (i = 0; i < num_mgrs; ++i) { |
| 503 | if (mgr_busy[i]) |
| 504 | goto end; |
| 505 | } |
| 506 | |
Tomi Valkeinen | dbce016 | 2011-11-15 11:18:12 +0200 | [diff] [blame] | 507 | dss_unregister_vsync_isr(); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 508 | |
| 509 | end: |
Tomi Valkeinen | 063fd70 | 2011-11-15 12:04:10 +0200 | [diff] [blame] | 510 | spin_unlock(&data_lock); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 511 | } |
| 512 | |
Tomi Valkeinen | 5738b63 | 2011-11-15 13:37:33 +0200 | [diff] [blame] | 513 | static void omap_dss_mgr_apply_ovl(struct omap_overlay *ovl) |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 514 | { |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 515 | struct ovl_priv_data *op; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 516 | |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 517 | op = get_ovl_priv(ovl); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 518 | |
| 519 | if (ovl->manager_changed) { |
| 520 | ovl->manager_changed = false; |
| 521 | ovl->info_dirty = true; |
| 522 | } |
| 523 | |
| 524 | if (!overlay_enabled(ovl)) { |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 525 | if (op->enabled) { |
| 526 | op->enabled = false; |
| 527 | op->dirty = true; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 528 | } |
Tomi Valkeinen | 5738b63 | 2011-11-15 13:37:33 +0200 | [diff] [blame] | 529 | return; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | if (!ovl->info_dirty) |
Tomi Valkeinen | 5738b63 | 2011-11-15 13:37:33 +0200 | [diff] [blame] | 533 | return; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 534 | |
| 535 | ovl->info_dirty = false; |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 536 | op->dirty = true; |
| 537 | op->info = ovl->info; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 538 | |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 539 | op->channel = ovl->manager->id; |
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->enabled = true; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | static void omap_dss_mgr_apply_mgr(struct omap_overlay_manager *mgr) |
| 545 | { |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame] | 546 | struct mgr_priv_data *mp; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 547 | |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame] | 548 | mp = get_mgr_priv(mgr); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 549 | |
| 550 | if (mgr->device_changed) { |
| 551 | mgr->device_changed = false; |
| 552 | mgr->info_dirty = true; |
| 553 | } |
| 554 | |
| 555 | if (!mgr->info_dirty) |
| 556 | return; |
| 557 | |
| 558 | if (!mgr->device) |
| 559 | return; |
| 560 | |
| 561 | mgr->info_dirty = false; |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame] | 562 | mp->dirty = true; |
| 563 | mp->info = mgr->info; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 564 | |
Tomi Valkeinen | af3d64b | 2011-11-15 12:02:03 +0200 | [diff] [blame] | 565 | mp->manual_update = mgr_manual_update(mgr); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | static void omap_dss_mgr_apply_ovl_fifos(struct omap_overlay *ovl) |
| 569 | { |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 570 | struct ovl_priv_data *op; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 571 | struct omap_dss_device *dssdev; |
| 572 | u32 size, burst_size; |
| 573 | |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 574 | op = get_ovl_priv(ovl); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 575 | |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 576 | if (!op->enabled) |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 577 | return; |
| 578 | |
| 579 | dssdev = ovl->manager->device; |
| 580 | |
| 581 | size = dispc_ovl_get_fifo_size(ovl->id); |
| 582 | |
| 583 | burst_size = dispc_ovl_get_burst_size(ovl->id); |
| 584 | |
| 585 | switch (dssdev->type) { |
| 586 | case OMAP_DISPLAY_TYPE_DPI: |
| 587 | case OMAP_DISPLAY_TYPE_DBI: |
| 588 | case OMAP_DISPLAY_TYPE_SDI: |
| 589 | case OMAP_DISPLAY_TYPE_VENC: |
| 590 | case OMAP_DISPLAY_TYPE_HDMI: |
| 591 | default_get_overlay_fifo_thresholds(ovl->id, size, |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 592 | burst_size, &op->fifo_low, |
| 593 | &op->fifo_high); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 594 | break; |
| 595 | #ifdef CONFIG_OMAP2_DSS_DSI |
| 596 | case OMAP_DISPLAY_TYPE_DSI: |
| 597 | dsi_get_overlay_fifo_thresholds(ovl->id, size, |
Tomi Valkeinen | c10c6f0 | 2011-11-15 11:56:57 +0200 | [diff] [blame] | 598 | burst_size, &op->fifo_low, |
| 599 | &op->fifo_high); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 600 | break; |
| 601 | #endif |
| 602 | default: |
| 603 | BUG(); |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | int omap_dss_mgr_apply(struct omap_overlay_manager *mgr) |
| 608 | { |
Tomi Valkeinen | 07e327c | 2011-11-05 10:59:59 +0200 | [diff] [blame] | 609 | int r; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 610 | unsigned long flags; |
Tomi Valkeinen | 07e327c | 2011-11-05 10:59:59 +0200 | [diff] [blame] | 611 | struct omap_overlay *ovl; |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 612 | |
| 613 | DSSDBG("omap_dss_mgr_apply(%s)\n", mgr->name); |
| 614 | |
| 615 | r = dispc_runtime_get(); |
| 616 | if (r) |
| 617 | return r; |
| 618 | |
Tomi Valkeinen | 063fd70 | 2011-11-15 12:04:10 +0200 | [diff] [blame] | 619 | spin_lock_irqsave(&data_lock, flags); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 620 | |
| 621 | /* Configure overlays */ |
Tomi Valkeinen | 07e327c | 2011-11-05 10:59:59 +0200 | [diff] [blame] | 622 | list_for_each_entry(ovl, &mgr->overlays, list) |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 623 | omap_dss_mgr_apply_ovl(ovl); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 624 | |
| 625 | /* Configure manager */ |
| 626 | omap_dss_mgr_apply_mgr(mgr); |
| 627 | |
| 628 | /* Configure overlay fifos */ |
Tomi Valkeinen | 07e327c | 2011-11-05 10:59:59 +0200 | [diff] [blame] | 629 | list_for_each_entry(ovl, &mgr->overlays, list) |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 630 | omap_dss_mgr_apply_ovl_fifos(ovl); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 631 | |
| 632 | r = 0; |
Tomi Valkeinen | 04f6643 | 2011-11-07 15:04:01 +0200 | [diff] [blame] | 633 | if (mgr->enabled && !mgr_manual_update(mgr)) { |
Tomi Valkeinen | d09c7aa | 2011-11-15 12:04:43 +0200 | [diff] [blame] | 634 | if (!dss_data.irq_enabled) |
Tomi Valkeinen | dbce016 | 2011-11-15 11:18:12 +0200 | [diff] [blame] | 635 | dss_register_vsync_isr(); |
Tomi Valkeinen | 18135ea | 2011-11-04 09:35:59 +0200 | [diff] [blame] | 636 | |
Tomi Valkeinen | f6a5e08 | 2011-11-15 11:47:39 +0200 | [diff] [blame] | 637 | dss_write_regs(); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 638 | } |
| 639 | |
Tomi Valkeinen | 063fd70 | 2011-11-15 12:04:10 +0200 | [diff] [blame] | 640 | spin_unlock_irqrestore(&data_lock, flags); |
Tomi Valkeinen | 58f25548 | 2011-11-04 09:48:54 +0200 | [diff] [blame] | 641 | |
| 642 | dispc_runtime_put(); |
| 643 | |
| 644 | return r; |
| 645 | } |
| 646 | |
Tomi Valkeinen | 7797c6d | 2011-11-04 10:22:46 +0200 | [diff] [blame] | 647 | void dss_mgr_enable(struct omap_overlay_manager *mgr) |
| 648 | { |
Tomi Valkeinen | 5558db3 | 2011-11-15 14:28:48 +0200 | [diff] [blame] | 649 | mutex_lock(&apply_lock); |
| 650 | |
Tomi Valkeinen | 9a147a6 | 2011-11-09 15:30:11 +0200 | [diff] [blame^] | 651 | if (!mgr_manual_update(mgr)) |
| 652 | dispc_mgr_enable(mgr->id, true); |
Tomi Valkeinen | be72917 | 2011-11-04 10:30:47 +0200 | [diff] [blame] | 653 | mgr->enabled = true; |
Tomi Valkeinen | 5558db3 | 2011-11-15 14:28:48 +0200 | [diff] [blame] | 654 | |
| 655 | mutex_unlock(&apply_lock); |
Tomi Valkeinen | 7797c6d | 2011-11-04 10:22:46 +0200 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | void dss_mgr_disable(struct omap_overlay_manager *mgr) |
| 659 | { |
Tomi Valkeinen | 5558db3 | 2011-11-15 14:28:48 +0200 | [diff] [blame] | 660 | mutex_lock(&apply_lock); |
| 661 | |
Tomi Valkeinen | 9a147a6 | 2011-11-09 15:30:11 +0200 | [diff] [blame^] | 662 | if (!mgr_manual_update(mgr)) |
| 663 | dispc_mgr_enable(mgr->id, false); |
Tomi Valkeinen | be72917 | 2011-11-04 10:30:47 +0200 | [diff] [blame] | 664 | mgr->enabled = false; |
Tomi Valkeinen | 5558db3 | 2011-11-15 14:28:48 +0200 | [diff] [blame] | 665 | |
| 666 | mutex_unlock(&apply_lock); |
Tomi Valkeinen | 7797c6d | 2011-11-04 10:22:46 +0200 | [diff] [blame] | 667 | } |
| 668 | |
Tomi Valkeinen | eb70d73 | 2011-11-15 12:15:18 +0200 | [diff] [blame] | 669 | int dss_mgr_set_info(struct omap_overlay_manager *mgr, |
| 670 | struct omap_overlay_manager_info *info) |
| 671 | { |
Tomi Valkeinen | e0a2aa5b | 2011-11-15 14:32:57 +0200 | [diff] [blame] | 672 | unsigned long flags; |
| 673 | |
| 674 | spin_lock_irqsave(&data_lock, flags); |
| 675 | |
Tomi Valkeinen | eb70d73 | 2011-11-15 12:15:18 +0200 | [diff] [blame] | 676 | mgr->info = *info; |
Tomi Valkeinen | eb70d73 | 2011-11-15 12:15:18 +0200 | [diff] [blame] | 677 | mgr->info_dirty = true; |
| 678 | |
Tomi Valkeinen | e0a2aa5b | 2011-11-15 14:32:57 +0200 | [diff] [blame] | 679 | spin_unlock_irqrestore(&data_lock, flags); |
| 680 | |
Tomi Valkeinen | eb70d73 | 2011-11-15 12:15:18 +0200 | [diff] [blame] | 681 | return 0; |
| 682 | } |
| 683 | |
| 684 | void dss_mgr_get_info(struct omap_overlay_manager *mgr, |
| 685 | struct omap_overlay_manager_info *info) |
| 686 | { |
Tomi Valkeinen | e0a2aa5b | 2011-11-15 14:32:57 +0200 | [diff] [blame] | 687 | unsigned long flags; |
| 688 | |
| 689 | spin_lock_irqsave(&data_lock, flags); |
| 690 | |
Tomi Valkeinen | eb70d73 | 2011-11-15 12:15:18 +0200 | [diff] [blame] | 691 | *info = mgr->info; |
Tomi Valkeinen | e0a2aa5b | 2011-11-15 14:32:57 +0200 | [diff] [blame] | 692 | |
| 693 | spin_unlock_irqrestore(&data_lock, flags); |
Tomi Valkeinen | eb70d73 | 2011-11-15 12:15:18 +0200 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | int dss_mgr_set_device(struct omap_overlay_manager *mgr, |
| 697 | struct omap_dss_device *dssdev) |
| 698 | { |
| 699 | int r; |
Tomi Valkeinen | eb70d73 | 2011-11-15 12:15:18 +0200 | [diff] [blame] | 700 | |
Tomi Valkeinen | 5558db3 | 2011-11-15 14:28:48 +0200 | [diff] [blame] | 701 | mutex_lock(&apply_lock); |
| 702 | |
Tomi Valkeinen | eb70d73 | 2011-11-15 12:15:18 +0200 | [diff] [blame] | 703 | if (dssdev->manager) { |
| 704 | DSSERR("display '%s' already has a manager '%s'\n", |
| 705 | dssdev->name, dssdev->manager->name); |
Tomi Valkeinen | 5558db3 | 2011-11-15 14:28:48 +0200 | [diff] [blame] | 706 | r = -EINVAL; |
| 707 | goto err; |
Tomi Valkeinen | eb70d73 | 2011-11-15 12:15:18 +0200 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | if ((mgr->supported_displays & dssdev->type) == 0) { |
| 711 | DSSERR("display '%s' does not support manager '%s'\n", |
| 712 | dssdev->name, mgr->name); |
Tomi Valkeinen | 5558db3 | 2011-11-15 14:28:48 +0200 | [diff] [blame] | 713 | r = -EINVAL; |
| 714 | goto err; |
Tomi Valkeinen | eb70d73 | 2011-11-15 12:15:18 +0200 | [diff] [blame] | 715 | } |
| 716 | |
Tomi Valkeinen | eb70d73 | 2011-11-15 12:15:18 +0200 | [diff] [blame] | 717 | dssdev->manager = mgr; |
| 718 | mgr->device = dssdev; |
| 719 | mgr->device_changed = true; |
| 720 | |
Tomi Valkeinen | 5558db3 | 2011-11-15 14:28:48 +0200 | [diff] [blame] | 721 | mutex_unlock(&apply_lock); |
| 722 | |
Tomi Valkeinen | eb70d73 | 2011-11-15 12:15:18 +0200 | [diff] [blame] | 723 | return 0; |
Tomi Valkeinen | 5558db3 | 2011-11-15 14:28:48 +0200 | [diff] [blame] | 724 | err: |
| 725 | mutex_unlock(&apply_lock); |
| 726 | return r; |
Tomi Valkeinen | eb70d73 | 2011-11-15 12:15:18 +0200 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | int dss_mgr_unset_device(struct omap_overlay_manager *mgr) |
| 730 | { |
Tomi Valkeinen | 5558db3 | 2011-11-15 14:28:48 +0200 | [diff] [blame] | 731 | int r; |
| 732 | |
| 733 | mutex_lock(&apply_lock); |
| 734 | |
Tomi Valkeinen | eb70d73 | 2011-11-15 12:15:18 +0200 | [diff] [blame] | 735 | if (!mgr->device) { |
| 736 | DSSERR("failed to unset display, display not set.\n"); |
Tomi Valkeinen | 5558db3 | 2011-11-15 14:28:48 +0200 | [diff] [blame] | 737 | r = -EINVAL; |
| 738 | goto err; |
Tomi Valkeinen | eb70d73 | 2011-11-15 12:15:18 +0200 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | /* |
| 742 | * Don't allow currently enabled displays to have the overlay manager |
| 743 | * pulled out from underneath them |
| 744 | */ |
Tomi Valkeinen | 5558db3 | 2011-11-15 14:28:48 +0200 | [diff] [blame] | 745 | if (mgr->device->state != OMAP_DSS_DISPLAY_DISABLED) { |
| 746 | r = -EINVAL; |
| 747 | goto err; |
| 748 | } |
Tomi Valkeinen | eb70d73 | 2011-11-15 12:15:18 +0200 | [diff] [blame] | 749 | |
| 750 | mgr->device->manager = NULL; |
| 751 | mgr->device = NULL; |
| 752 | mgr->device_changed = true; |
| 753 | |
Tomi Valkeinen | 5558db3 | 2011-11-15 14:28:48 +0200 | [diff] [blame] | 754 | mutex_unlock(&apply_lock); |
| 755 | |
Tomi Valkeinen | eb70d73 | 2011-11-15 12:15:18 +0200 | [diff] [blame] | 756 | return 0; |
Tomi Valkeinen | 5558db3 | 2011-11-15 14:28:48 +0200 | [diff] [blame] | 757 | err: |
| 758 | mutex_unlock(&apply_lock); |
| 759 | return r; |
Tomi Valkeinen | eb70d73 | 2011-11-15 12:15:18 +0200 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | |
| 763 | |
Tomi Valkeinen | f77b307 | 2011-11-15 12:11:11 +0200 | [diff] [blame] | 764 | int dss_ovl_set_info(struct omap_overlay *ovl, |
| 765 | struct omap_overlay_info *info) |
| 766 | { |
Tomi Valkeinen | e0a2aa5b | 2011-11-15 14:32:57 +0200 | [diff] [blame] | 767 | unsigned long flags; |
| 768 | |
| 769 | spin_lock_irqsave(&data_lock, flags); |
| 770 | |
Tomi Valkeinen | f77b307 | 2011-11-15 12:11:11 +0200 | [diff] [blame] | 771 | ovl->info = *info; |
Tomi Valkeinen | f77b307 | 2011-11-15 12:11:11 +0200 | [diff] [blame] | 772 | ovl->info_dirty = true; |
| 773 | |
Tomi Valkeinen | e0a2aa5b | 2011-11-15 14:32:57 +0200 | [diff] [blame] | 774 | spin_unlock_irqrestore(&data_lock, flags); |
| 775 | |
Tomi Valkeinen | f77b307 | 2011-11-15 12:11:11 +0200 | [diff] [blame] | 776 | return 0; |
| 777 | } |
| 778 | |
| 779 | void dss_ovl_get_info(struct omap_overlay *ovl, |
| 780 | struct omap_overlay_info *info) |
| 781 | { |
Tomi Valkeinen | e0a2aa5b | 2011-11-15 14:32:57 +0200 | [diff] [blame] | 782 | unsigned long flags; |
| 783 | |
| 784 | spin_lock_irqsave(&data_lock, flags); |
| 785 | |
Tomi Valkeinen | f77b307 | 2011-11-15 12:11:11 +0200 | [diff] [blame] | 786 | *info = ovl->info; |
Tomi Valkeinen | e0a2aa5b | 2011-11-15 14:32:57 +0200 | [diff] [blame] | 787 | |
| 788 | spin_unlock_irqrestore(&data_lock, flags); |
Tomi Valkeinen | f77b307 | 2011-11-15 12:11:11 +0200 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | int dss_ovl_set_manager(struct omap_overlay *ovl, |
| 792 | struct omap_overlay_manager *mgr) |
| 793 | { |
Tomi Valkeinen | 5558db3 | 2011-11-15 14:28:48 +0200 | [diff] [blame] | 794 | int r; |
| 795 | |
Tomi Valkeinen | f77b307 | 2011-11-15 12:11:11 +0200 | [diff] [blame] | 796 | if (!mgr) |
| 797 | return -EINVAL; |
| 798 | |
Tomi Valkeinen | 5558db3 | 2011-11-15 14:28:48 +0200 | [diff] [blame] | 799 | mutex_lock(&apply_lock); |
| 800 | |
Tomi Valkeinen | f77b307 | 2011-11-15 12:11:11 +0200 | [diff] [blame] | 801 | if (ovl->manager) { |
| 802 | DSSERR("overlay '%s' already has a manager '%s'\n", |
| 803 | ovl->name, ovl->manager->name); |
Tomi Valkeinen | 5558db3 | 2011-11-15 14:28:48 +0200 | [diff] [blame] | 804 | r = -EINVAL; |
| 805 | goto err; |
Tomi Valkeinen | f77b307 | 2011-11-15 12:11:11 +0200 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | if (ovl->info.enabled) { |
| 809 | DSSERR("overlay has to be disabled to change the manager\n"); |
Tomi Valkeinen | 5558db3 | 2011-11-15 14:28:48 +0200 | [diff] [blame] | 810 | r = -EINVAL; |
| 811 | goto err; |
Tomi Valkeinen | f77b307 | 2011-11-15 12:11:11 +0200 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | ovl->manager = mgr; |
| 815 | list_add_tail(&ovl->list, &mgr->overlays); |
| 816 | ovl->manager_changed = true; |
| 817 | |
| 818 | /* XXX: When there is an overlay on a DSI manual update display, and |
| 819 | * the overlay is first disabled, then moved to tv, and enabled, we |
| 820 | * seem to get SYNC_LOST_DIGIT error. |
| 821 | * |
| 822 | * Waiting doesn't seem to help, but updating the manual update display |
| 823 | * after disabling the overlay seems to fix this. This hints that the |
| 824 | * overlay is perhaps somehow tied to the LCD output until the output |
| 825 | * is updated. |
| 826 | * |
| 827 | * Userspace workaround for this is to update the LCD after disabling |
| 828 | * the overlay, but before moving the overlay to TV. |
| 829 | */ |
| 830 | |
Tomi Valkeinen | 5558db3 | 2011-11-15 14:28:48 +0200 | [diff] [blame] | 831 | mutex_unlock(&apply_lock); |
| 832 | |
Tomi Valkeinen | f77b307 | 2011-11-15 12:11:11 +0200 | [diff] [blame] | 833 | return 0; |
Tomi Valkeinen | 5558db3 | 2011-11-15 14:28:48 +0200 | [diff] [blame] | 834 | err: |
| 835 | mutex_unlock(&apply_lock); |
| 836 | return r; |
Tomi Valkeinen | f77b307 | 2011-11-15 12:11:11 +0200 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | int dss_ovl_unset_manager(struct omap_overlay *ovl) |
| 840 | { |
Tomi Valkeinen | 5558db3 | 2011-11-15 14:28:48 +0200 | [diff] [blame] | 841 | int r; |
| 842 | |
| 843 | mutex_lock(&apply_lock); |
| 844 | |
Tomi Valkeinen | f77b307 | 2011-11-15 12:11:11 +0200 | [diff] [blame] | 845 | if (!ovl->manager) { |
| 846 | DSSERR("failed to detach overlay: manager not set\n"); |
Tomi Valkeinen | 5558db3 | 2011-11-15 14:28:48 +0200 | [diff] [blame] | 847 | r = -EINVAL; |
| 848 | goto err; |
Tomi Valkeinen | f77b307 | 2011-11-15 12:11:11 +0200 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | if (ovl->info.enabled) { |
| 852 | DSSERR("overlay has to be disabled to unset the manager\n"); |
Tomi Valkeinen | 5558db3 | 2011-11-15 14:28:48 +0200 | [diff] [blame] | 853 | r = -EINVAL; |
| 854 | goto err; |
Tomi Valkeinen | f77b307 | 2011-11-15 12:11:11 +0200 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | ovl->manager = NULL; |
| 858 | list_del(&ovl->list); |
| 859 | ovl->manager_changed = true; |
| 860 | |
Tomi Valkeinen | 5558db3 | 2011-11-15 14:28:48 +0200 | [diff] [blame] | 861 | mutex_unlock(&apply_lock); |
| 862 | |
Tomi Valkeinen | f77b307 | 2011-11-15 12:11:11 +0200 | [diff] [blame] | 863 | return 0; |
Tomi Valkeinen | 5558db3 | 2011-11-15 14:28:48 +0200 | [diff] [blame] | 864 | err: |
| 865 | mutex_unlock(&apply_lock); |
| 866 | return r; |
Tomi Valkeinen | f77b307 | 2011-11-15 12:11:11 +0200 | [diff] [blame] | 867 | } |
| 868 | |