Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/video/omap2/omapfb-ioctl.c |
| 3 | * |
| 4 | * Copyright (C) 2008 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 | #include <linux/fb.h> |
| 24 | #include <linux/device.h> |
| 25 | #include <linux/uaccess.h> |
| 26 | #include <linux/platform_device.h> |
| 27 | #include <linux/mm.h> |
| 28 | #include <linux/omapfb.h> |
| 29 | #include <linux/vmalloc.h> |
| 30 | |
| 31 | #include <plat/display.h> |
| 32 | #include <plat/vrfb.h> |
| 33 | #include <plat/vram.h> |
| 34 | |
| 35 | #include "omapfb.h" |
| 36 | |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 37 | static u8 get_mem_idx(struct omapfb_info *ofbi) |
| 38 | { |
| 39 | if (ofbi->id == ofbi->region->id) |
| 40 | return 0; |
| 41 | |
| 42 | return OMAPFB_MEM_IDX_ENABLED | ofbi->region->id; |
| 43 | } |
| 44 | |
| 45 | static struct omapfb2_mem_region *get_mem_region(struct omapfb_info *ofbi, |
| 46 | u8 mem_idx) |
| 47 | { |
| 48 | struct omapfb2_device *fbdev = ofbi->fbdev; |
| 49 | |
| 50 | if (mem_idx & OMAPFB_MEM_IDX_ENABLED) |
| 51 | mem_idx &= OMAPFB_MEM_IDX_MASK; |
| 52 | else |
| 53 | mem_idx = ofbi->id; |
| 54 | |
| 55 | if (mem_idx >= fbdev->num_fbs) |
| 56 | return NULL; |
| 57 | |
Ville Syrjälä | 3d84b65 | 2010-03-17 21:42:06 +0200 | [diff] [blame] | 58 | return &fbdev->regions[mem_idx]; |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 59 | } |
| 60 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 61 | static int omapfb_setup_plane(struct fb_info *fbi, struct omapfb_plane_info *pi) |
| 62 | { |
| 63 | struct omapfb_info *ofbi = FB2OFB(fbi); |
| 64 | struct omapfb2_device *fbdev = ofbi->fbdev; |
| 65 | struct omap_overlay *ovl; |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 66 | struct omap_overlay_info old_info; |
| 67 | struct omapfb2_mem_region *old_rg, *new_rg; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 68 | int r = 0; |
| 69 | |
| 70 | DBG("omapfb_setup_plane\n"); |
| 71 | |
| 72 | if (ofbi->num_overlays != 1) { |
| 73 | r = -EINVAL; |
| 74 | goto out; |
| 75 | } |
| 76 | |
| 77 | /* XXX uses only the first overlay */ |
| 78 | ovl = ofbi->overlays[0]; |
| 79 | |
Ville Syrjälä | 3d84b65 | 2010-03-17 21:42:06 +0200 | [diff] [blame] | 80 | old_rg = ofbi->region; |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 81 | new_rg = get_mem_region(ofbi, pi->mem_idx); |
| 82 | if (!new_rg) { |
| 83 | r = -EINVAL; |
Ville Syrjälä | 3d84b65 | 2010-03-17 21:42:06 +0200 | [diff] [blame] | 84 | goto out; |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 85 | } |
| 86 | |
Ville Syrjälä | 3d84b65 | 2010-03-17 21:42:06 +0200 | [diff] [blame] | 87 | /* Take the locks in a specific order to keep lockdep happy */ |
| 88 | if (old_rg->id < new_rg->id) { |
| 89 | omapfb_get_mem_region(old_rg); |
| 90 | omapfb_get_mem_region(new_rg); |
| 91 | } else if (new_rg->id < old_rg->id) { |
| 92 | omapfb_get_mem_region(new_rg); |
| 93 | omapfb_get_mem_region(old_rg); |
| 94 | } else |
| 95 | omapfb_get_mem_region(old_rg); |
| 96 | |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 97 | if (pi->enabled && !new_rg->size) { |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 98 | /* |
| 99 | * This plane's memory was freed, can't enable it |
| 100 | * until it's reallocated. |
| 101 | */ |
| 102 | r = -EINVAL; |
Ville Syrjälä | 3d84b65 | 2010-03-17 21:42:06 +0200 | [diff] [blame] | 103 | goto put_mem; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 104 | } |
| 105 | |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 106 | ovl->get_overlay_info(ovl, &old_info); |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 107 | |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 108 | if (old_rg != new_rg) { |
| 109 | ofbi->region = new_rg; |
| 110 | set_fb_fix(fbi); |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 111 | } |
| 112 | |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 113 | if (pi->enabled) { |
| 114 | struct omap_overlay_info info; |
| 115 | |
| 116 | r = omapfb_setup_overlay(fbi, ovl, pi->pos_x, pi->pos_y, |
| 117 | pi->out_width, pi->out_height); |
| 118 | if (r) |
| 119 | goto undo; |
| 120 | |
| 121 | ovl->get_overlay_info(ovl, &info); |
| 122 | |
| 123 | if (!info.enabled) { |
| 124 | info.enabled = pi->enabled; |
| 125 | r = ovl->set_overlay_info(ovl, &info); |
| 126 | if (r) |
| 127 | goto undo; |
| 128 | } |
| 129 | } else { |
| 130 | struct omap_overlay_info info; |
| 131 | |
| 132 | ovl->get_overlay_info(ovl, &info); |
| 133 | |
| 134 | info.enabled = pi->enabled; |
| 135 | info.pos_x = pi->pos_x; |
| 136 | info.pos_y = pi->pos_y; |
| 137 | info.out_width = pi->out_width; |
| 138 | info.out_height = pi->out_height; |
| 139 | |
| 140 | r = ovl->set_overlay_info(ovl, &info); |
| 141 | if (r) |
| 142 | goto undo; |
| 143 | } |
| 144 | |
| 145 | if (ovl->manager) |
| 146 | ovl->manager->apply(ovl->manager); |
| 147 | |
Ville Syrjälä | 3d84b65 | 2010-03-17 21:42:06 +0200 | [diff] [blame] | 148 | /* Release the locks in a specific order to keep lockdep happy */ |
| 149 | if (old_rg->id > new_rg->id) { |
| 150 | omapfb_put_mem_region(old_rg); |
| 151 | omapfb_put_mem_region(new_rg); |
| 152 | } else if (new_rg->id > old_rg->id) { |
| 153 | omapfb_put_mem_region(new_rg); |
| 154 | omapfb_put_mem_region(old_rg); |
| 155 | } else |
| 156 | omapfb_put_mem_region(old_rg); |
Ville Syrjälä | 430571d | 2010-03-17 20:43:23 +0200 | [diff] [blame] | 157 | |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 158 | return 0; |
| 159 | |
| 160 | undo: |
| 161 | if (old_rg != new_rg) { |
| 162 | ofbi->region = old_rg; |
| 163 | set_fb_fix(fbi); |
| 164 | } |
| 165 | |
| 166 | ovl->set_overlay_info(ovl, &old_info); |
Ville Syrjälä | 3d84b65 | 2010-03-17 21:42:06 +0200 | [diff] [blame] | 167 | put_mem: |
| 168 | /* Release the locks in a specific order to keep lockdep happy */ |
| 169 | if (old_rg->id > new_rg->id) { |
| 170 | omapfb_put_mem_region(old_rg); |
| 171 | omapfb_put_mem_region(new_rg); |
| 172 | } else if (new_rg->id > old_rg->id) { |
| 173 | omapfb_put_mem_region(new_rg); |
| 174 | omapfb_put_mem_region(old_rg); |
| 175 | } else |
| 176 | omapfb_put_mem_region(old_rg); |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 177 | out: |
| 178 | dev_err(fbdev->dev, "setup_plane failed\n"); |
| 179 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 180 | return r; |
| 181 | } |
| 182 | |
| 183 | static int omapfb_query_plane(struct fb_info *fbi, struct omapfb_plane_info *pi) |
| 184 | { |
| 185 | struct omapfb_info *ofbi = FB2OFB(fbi); |
| 186 | |
| 187 | if (ofbi->num_overlays != 1) { |
| 188 | memset(pi, 0, sizeof(*pi)); |
| 189 | } else { |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 190 | struct omap_overlay *ovl; |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 191 | struct omap_overlay_info *ovli; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 192 | |
| 193 | ovl = ofbi->overlays[0]; |
| 194 | ovli = &ovl->info; |
| 195 | |
| 196 | pi->pos_x = ovli->pos_x; |
| 197 | pi->pos_y = ovli->pos_y; |
| 198 | pi->enabled = ovli->enabled; |
| 199 | pi->channel_out = 0; /* xxx */ |
| 200 | pi->mirror = 0; |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 201 | pi->mem_idx = get_mem_idx(ofbi); |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 202 | pi->out_width = ovli->out_width; |
| 203 | pi->out_height = ovli->out_height; |
| 204 | } |
| 205 | |
| 206 | return 0; |
| 207 | } |
| 208 | |
| 209 | static int omapfb_setup_mem(struct fb_info *fbi, struct omapfb_mem_info *mi) |
| 210 | { |
| 211 | struct omapfb_info *ofbi = FB2OFB(fbi); |
| 212 | struct omapfb2_device *fbdev = ofbi->fbdev; |
| 213 | struct omapfb2_mem_region *rg; |
Ville Syrjälä | 430571d | 2010-03-17 20:43:23 +0200 | [diff] [blame] | 214 | int r = 0, i; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 215 | size_t size; |
| 216 | |
| 217 | if (mi->type > OMAPFB_MEMTYPE_MAX) |
| 218 | return -EINVAL; |
| 219 | |
| 220 | size = PAGE_ALIGN(mi->size); |
| 221 | |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 222 | rg = ofbi->region; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 223 | |
Ville Syrjälä | 3d84b65 | 2010-03-17 21:42:06 +0200 | [diff] [blame] | 224 | down_write_nested(&rg->lock, rg->id); |
Ville Syrjälä | 1ceafc0 | 2010-03-17 21:28:50 +0200 | [diff] [blame^] | 225 | atomic_inc(&rg->lock_count); |
Ville Syrjälä | 430571d | 2010-03-17 20:43:23 +0200 | [diff] [blame] | 226 | |
| 227 | if (atomic_read(&rg->map_count)) { |
| 228 | r = -EBUSY; |
| 229 | goto out; |
| 230 | } |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 231 | |
| 232 | for (i = 0; i < fbdev->num_fbs; i++) { |
| 233 | struct omapfb_info *ofbi2 = FB2OFB(fbdev->fbs[i]); |
| 234 | int j; |
| 235 | |
| 236 | if (ofbi2->region != rg) |
| 237 | continue; |
| 238 | |
| 239 | for (j = 0; j < ofbi2->num_overlays; j++) { |
| 240 | if (ofbi2->overlays[j]->info.enabled) { |
| 241 | r = -EBUSY; |
Ville Syrjälä | 430571d | 2010-03-17 20:43:23 +0200 | [diff] [blame] | 242 | goto out; |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 243 | } |
| 244 | } |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | if (rg->size != size || rg->type != mi->type) { |
| 248 | r = omapfb_realloc_fbmem(fbi, size, mi->type); |
| 249 | if (r) { |
| 250 | dev_err(fbdev->dev, "realloc fbmem failed\n"); |
Ville Syrjälä | 430571d | 2010-03-17 20:43:23 +0200 | [diff] [blame] | 251 | goto out; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 252 | } |
| 253 | } |
| 254 | |
Ville Syrjälä | 430571d | 2010-03-17 20:43:23 +0200 | [diff] [blame] | 255 | out: |
Ville Syrjälä | 1ceafc0 | 2010-03-17 21:28:50 +0200 | [diff] [blame^] | 256 | atomic_dec(&rg->lock_count); |
Ville Syrjälä | 2f642a1 | 2010-03-17 20:58:03 +0200 | [diff] [blame] | 257 | up_write(&rg->lock); |
Ville Syrjälä | 430571d | 2010-03-17 20:43:23 +0200 | [diff] [blame] | 258 | |
| 259 | return r; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | static int omapfb_query_mem(struct fb_info *fbi, struct omapfb_mem_info *mi) |
| 263 | { |
| 264 | struct omapfb_info *ofbi = FB2OFB(fbi); |
| 265 | struct omapfb2_mem_region *rg; |
| 266 | |
Ville Syrjälä | 430571d | 2010-03-17 20:43:23 +0200 | [diff] [blame] | 267 | rg = omapfb_get_mem_region(ofbi->region); |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 268 | memset(mi, 0, sizeof(*mi)); |
| 269 | |
| 270 | mi->size = rg->size; |
| 271 | mi->type = rg->type; |
| 272 | |
Ville Syrjälä | 430571d | 2010-03-17 20:43:23 +0200 | [diff] [blame] | 273 | omapfb_put_mem_region(rg); |
| 274 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 275 | return 0; |
| 276 | } |
| 277 | |
| 278 | static int omapfb_update_window_nolock(struct fb_info *fbi, |
| 279 | u32 x, u32 y, u32 w, u32 h) |
| 280 | { |
| 281 | struct omap_dss_device *display = fb2display(fbi); |
| 282 | u16 dw, dh; |
| 283 | |
| 284 | if (!display) |
| 285 | return 0; |
| 286 | |
| 287 | if (w == 0 || h == 0) |
| 288 | return 0; |
| 289 | |
Tomi Valkeinen | 96adcec | 2010-01-11 13:54:33 +0200 | [diff] [blame] | 290 | display->driver->get_resolution(display, &dw, &dh); |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 291 | |
| 292 | if (x + w > dw || y + h > dh) |
| 293 | return -EINVAL; |
| 294 | |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 295 | return display->driver->update(display, x, y, w, h); |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | /* This function is exported for SGX driver use */ |
| 299 | int omapfb_update_window(struct fb_info *fbi, |
| 300 | u32 x, u32 y, u32 w, u32 h) |
| 301 | { |
| 302 | struct omapfb_info *ofbi = FB2OFB(fbi); |
| 303 | struct omapfb2_device *fbdev = ofbi->fbdev; |
| 304 | int r; |
| 305 | |
Jani Nikula | 27b67c9 | 2010-03-18 10:32:06 +0100 | [diff] [blame] | 306 | if (!lock_fb_info(fbi)) |
| 307 | return -ENODEV; |
Jani Nikula | 238a413 | 2010-03-18 10:32:05 +0100 | [diff] [blame] | 308 | omapfb_lock(fbdev); |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 309 | |
| 310 | r = omapfb_update_window_nolock(fbi, x, y, w, h); |
| 311 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 312 | omapfb_unlock(fbdev); |
Jani Nikula | 238a413 | 2010-03-18 10:32:05 +0100 | [diff] [blame] | 313 | unlock_fb_info(fbi); |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 314 | |
| 315 | return r; |
| 316 | } |
| 317 | EXPORT_SYMBOL(omapfb_update_window); |
| 318 | |
| 319 | static int omapfb_set_update_mode(struct fb_info *fbi, |
| 320 | enum omapfb_update_mode mode) |
| 321 | { |
| 322 | struct omap_dss_device *display = fb2display(fbi); |
| 323 | enum omap_dss_update_mode um; |
| 324 | int r; |
| 325 | |
Tomi Valkeinen | 446f7bf | 2010-01-11 16:12:31 +0200 | [diff] [blame] | 326 | if (!display || !display->driver->set_update_mode) |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 327 | return -EINVAL; |
| 328 | |
| 329 | switch (mode) { |
| 330 | case OMAPFB_UPDATE_DISABLED: |
| 331 | um = OMAP_DSS_UPDATE_DISABLED; |
| 332 | break; |
| 333 | |
| 334 | case OMAPFB_AUTO_UPDATE: |
| 335 | um = OMAP_DSS_UPDATE_AUTO; |
| 336 | break; |
| 337 | |
| 338 | case OMAPFB_MANUAL_UPDATE: |
| 339 | um = OMAP_DSS_UPDATE_MANUAL; |
| 340 | break; |
| 341 | |
| 342 | default: |
| 343 | return -EINVAL; |
| 344 | } |
| 345 | |
Tomi Valkeinen | 446f7bf | 2010-01-11 16:12:31 +0200 | [diff] [blame] | 346 | r = display->driver->set_update_mode(display, um); |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 347 | |
| 348 | return r; |
| 349 | } |
| 350 | |
| 351 | static int omapfb_get_update_mode(struct fb_info *fbi, |
| 352 | enum omapfb_update_mode *mode) |
| 353 | { |
| 354 | struct omap_dss_device *display = fb2display(fbi); |
| 355 | enum omap_dss_update_mode m; |
| 356 | |
Tomi Valkeinen | 446f7bf | 2010-01-11 16:12:31 +0200 | [diff] [blame] | 357 | if (!display) |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 358 | return -EINVAL; |
| 359 | |
Tomi Valkeinen | 446f7bf | 2010-01-11 16:12:31 +0200 | [diff] [blame] | 360 | if (!display->driver->get_update_mode) { |
| 361 | *mode = OMAPFB_AUTO_UPDATE; |
| 362 | return 0; |
| 363 | } |
| 364 | |
| 365 | m = display->driver->get_update_mode(display); |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 366 | |
| 367 | switch (m) { |
| 368 | case OMAP_DSS_UPDATE_DISABLED: |
| 369 | *mode = OMAPFB_UPDATE_DISABLED; |
| 370 | break; |
| 371 | case OMAP_DSS_UPDATE_AUTO: |
| 372 | *mode = OMAPFB_AUTO_UPDATE; |
| 373 | break; |
| 374 | case OMAP_DSS_UPDATE_MANUAL: |
| 375 | *mode = OMAPFB_MANUAL_UPDATE; |
| 376 | break; |
| 377 | default: |
| 378 | BUG(); |
| 379 | } |
| 380 | |
| 381 | return 0; |
| 382 | } |
| 383 | |
| 384 | /* XXX this color key handling is a hack... */ |
| 385 | static struct omapfb_color_key omapfb_color_keys[2]; |
| 386 | |
| 387 | static int _omapfb_set_color_key(struct omap_overlay_manager *mgr, |
| 388 | struct omapfb_color_key *ck) |
| 389 | { |
| 390 | struct omap_overlay_manager_info info; |
| 391 | enum omap_dss_trans_key_type kt; |
| 392 | int r; |
| 393 | |
| 394 | mgr->get_manager_info(mgr, &info); |
| 395 | |
| 396 | if (ck->key_type == OMAPFB_COLOR_KEY_DISABLED) { |
| 397 | info.trans_enabled = false; |
| 398 | omapfb_color_keys[mgr->id] = *ck; |
| 399 | |
| 400 | r = mgr->set_manager_info(mgr, &info); |
| 401 | if (r) |
| 402 | return r; |
| 403 | |
| 404 | r = mgr->apply(mgr); |
| 405 | |
| 406 | return r; |
| 407 | } |
| 408 | |
| 409 | switch (ck->key_type) { |
| 410 | case OMAPFB_COLOR_KEY_GFX_DST: |
| 411 | kt = OMAP_DSS_COLOR_KEY_GFX_DST; |
| 412 | break; |
| 413 | case OMAPFB_COLOR_KEY_VID_SRC: |
| 414 | kt = OMAP_DSS_COLOR_KEY_VID_SRC; |
| 415 | break; |
| 416 | default: |
| 417 | return -EINVAL; |
| 418 | } |
| 419 | |
| 420 | info.default_color = ck->background; |
| 421 | info.trans_key = ck->trans_key; |
| 422 | info.trans_key_type = kt; |
| 423 | info.trans_enabled = true; |
| 424 | |
| 425 | omapfb_color_keys[mgr->id] = *ck; |
| 426 | |
| 427 | r = mgr->set_manager_info(mgr, &info); |
| 428 | if (r) |
| 429 | return r; |
| 430 | |
| 431 | r = mgr->apply(mgr); |
| 432 | |
| 433 | return r; |
| 434 | } |
| 435 | |
| 436 | static int omapfb_set_color_key(struct fb_info *fbi, |
| 437 | struct omapfb_color_key *ck) |
| 438 | { |
| 439 | struct omapfb_info *ofbi = FB2OFB(fbi); |
| 440 | struct omapfb2_device *fbdev = ofbi->fbdev; |
| 441 | int r; |
| 442 | int i; |
| 443 | struct omap_overlay_manager *mgr = NULL; |
| 444 | |
| 445 | omapfb_lock(fbdev); |
| 446 | |
| 447 | for (i = 0; i < ofbi->num_overlays; i++) { |
| 448 | if (ofbi->overlays[i]->manager) { |
| 449 | mgr = ofbi->overlays[i]->manager; |
| 450 | break; |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | if (!mgr) { |
| 455 | r = -EINVAL; |
| 456 | goto err; |
| 457 | } |
| 458 | |
| 459 | r = _omapfb_set_color_key(mgr, ck); |
| 460 | err: |
| 461 | omapfb_unlock(fbdev); |
| 462 | |
| 463 | return r; |
| 464 | } |
| 465 | |
| 466 | static int omapfb_get_color_key(struct fb_info *fbi, |
| 467 | struct omapfb_color_key *ck) |
| 468 | { |
| 469 | struct omapfb_info *ofbi = FB2OFB(fbi); |
| 470 | struct omapfb2_device *fbdev = ofbi->fbdev; |
| 471 | struct omap_overlay_manager *mgr = NULL; |
| 472 | int r = 0; |
| 473 | int i; |
| 474 | |
| 475 | omapfb_lock(fbdev); |
| 476 | |
| 477 | for (i = 0; i < ofbi->num_overlays; i++) { |
| 478 | if (ofbi->overlays[i]->manager) { |
| 479 | mgr = ofbi->overlays[i]->manager; |
| 480 | break; |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | if (!mgr) { |
| 485 | r = -EINVAL; |
| 486 | goto err; |
| 487 | } |
| 488 | |
| 489 | *ck = omapfb_color_keys[mgr->id]; |
| 490 | err: |
| 491 | omapfb_unlock(fbdev); |
| 492 | |
| 493 | return r; |
| 494 | } |
| 495 | |
| 496 | static int omapfb_memory_read(struct fb_info *fbi, |
| 497 | struct omapfb_memory_read *mr) |
| 498 | { |
| 499 | struct omap_dss_device *display = fb2display(fbi); |
| 500 | void *buf; |
| 501 | int r; |
| 502 | |
Tomi Valkeinen | c75d946 | 2010-01-08 16:56:44 +0200 | [diff] [blame] | 503 | if (!display || !display->driver->memory_read) |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 504 | return -ENOENT; |
| 505 | |
| 506 | if (!access_ok(VERIFY_WRITE, mr->buffer, mr->buffer_size)) |
| 507 | return -EFAULT; |
| 508 | |
| 509 | if (mr->w * mr->h * 3 > mr->buffer_size) |
| 510 | return -EINVAL; |
| 511 | |
| 512 | buf = vmalloc(mr->buffer_size); |
| 513 | if (!buf) { |
| 514 | DBG("vmalloc failed\n"); |
| 515 | return -ENOMEM; |
| 516 | } |
| 517 | |
Tomi Valkeinen | c75d946 | 2010-01-08 16:56:44 +0200 | [diff] [blame] | 518 | r = display->driver->memory_read(display, buf, mr->buffer_size, |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 519 | mr->x, mr->y, mr->w, mr->h); |
| 520 | |
| 521 | if (r > 0) { |
| 522 | if (copy_to_user(mr->buffer, buf, mr->buffer_size)) |
| 523 | r = -EFAULT; |
| 524 | } |
| 525 | |
| 526 | vfree(buf); |
| 527 | |
| 528 | return r; |
| 529 | } |
| 530 | |
| 531 | static int omapfb_get_ovl_colormode(struct omapfb2_device *fbdev, |
| 532 | struct omapfb_ovl_colormode *mode) |
| 533 | { |
| 534 | int ovl_idx = mode->overlay_idx; |
| 535 | int mode_idx = mode->mode_idx; |
| 536 | struct omap_overlay *ovl; |
| 537 | enum omap_color_mode supported_modes; |
| 538 | struct fb_var_screeninfo var; |
| 539 | int i; |
| 540 | |
| 541 | if (ovl_idx >= fbdev->num_overlays) |
| 542 | return -ENODEV; |
| 543 | ovl = fbdev->overlays[ovl_idx]; |
| 544 | supported_modes = ovl->supported_modes; |
| 545 | |
| 546 | mode_idx = mode->mode_idx; |
| 547 | |
| 548 | for (i = 0; i < sizeof(supported_modes) * 8; i++) { |
| 549 | if (!(supported_modes & (1 << i))) |
| 550 | continue; |
| 551 | /* |
| 552 | * It's possible that the FB doesn't support a mode |
| 553 | * that is supported by the overlay, so call the |
| 554 | * following here. |
| 555 | */ |
| 556 | if (dss_mode_to_fb_mode(1 << i, &var) < 0) |
| 557 | continue; |
| 558 | |
| 559 | mode_idx--; |
| 560 | if (mode_idx < 0) |
| 561 | break; |
| 562 | } |
| 563 | |
| 564 | if (i == sizeof(supported_modes) * 8) |
| 565 | return -ENOENT; |
| 566 | |
| 567 | mode->bits_per_pixel = var.bits_per_pixel; |
| 568 | mode->nonstd = var.nonstd; |
| 569 | mode->red = var.red; |
| 570 | mode->green = var.green; |
| 571 | mode->blue = var.blue; |
| 572 | mode->transp = var.transp; |
| 573 | |
| 574 | return 0; |
| 575 | } |
| 576 | |
| 577 | static int omapfb_wait_for_go(struct fb_info *fbi) |
| 578 | { |
| 579 | struct omapfb_info *ofbi = FB2OFB(fbi); |
| 580 | int r = 0; |
| 581 | int i; |
| 582 | |
| 583 | for (i = 0; i < ofbi->num_overlays; ++i) { |
| 584 | struct omap_overlay *ovl = ofbi->overlays[i]; |
| 585 | r = ovl->wait_for_go(ovl); |
| 586 | if (r) |
| 587 | break; |
| 588 | } |
| 589 | |
| 590 | return r; |
| 591 | } |
| 592 | |
| 593 | int omapfb_ioctl(struct fb_info *fbi, unsigned int cmd, unsigned long arg) |
| 594 | { |
| 595 | struct omapfb_info *ofbi = FB2OFB(fbi); |
| 596 | struct omapfb2_device *fbdev = ofbi->fbdev; |
| 597 | struct omap_dss_device *display = fb2display(fbi); |
| 598 | |
| 599 | union { |
| 600 | struct omapfb_update_window_old uwnd_o; |
| 601 | struct omapfb_update_window uwnd; |
| 602 | struct omapfb_plane_info plane_info; |
| 603 | struct omapfb_caps caps; |
| 604 | struct omapfb_mem_info mem_info; |
| 605 | struct omapfb_color_key color_key; |
| 606 | struct omapfb_ovl_colormode ovl_colormode; |
| 607 | enum omapfb_update_mode update_mode; |
| 608 | int test_num; |
| 609 | struct omapfb_memory_read memory_read; |
| 610 | struct omapfb_vram_info vram_info; |
| 611 | struct omapfb_tearsync_info tearsync_info; |
Tomi Valkeinen | 6dd2e42 | 2010-01-14 17:32:13 +0200 | [diff] [blame] | 612 | struct omapfb_display_info display_info; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 613 | } p; |
| 614 | |
| 615 | int r = 0; |
| 616 | |
| 617 | switch (cmd) { |
| 618 | case OMAPFB_SYNC_GFX: |
| 619 | DBG("ioctl SYNC_GFX\n"); |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 620 | if (!display || !display->driver->sync) { |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 621 | /* DSS1 never returns an error here, so we neither */ |
| 622 | /*r = -EINVAL;*/ |
| 623 | break; |
| 624 | } |
| 625 | |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 626 | r = display->driver->sync(display); |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 627 | break; |
| 628 | |
| 629 | case OMAPFB_UPDATE_WINDOW_OLD: |
| 630 | DBG("ioctl UPDATE_WINDOW_OLD\n"); |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 631 | if (!display || !display->driver->update) { |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 632 | r = -EINVAL; |
| 633 | break; |
| 634 | } |
| 635 | |
| 636 | if (copy_from_user(&p.uwnd_o, |
| 637 | (void __user *)arg, |
| 638 | sizeof(p.uwnd_o))) { |
| 639 | r = -EFAULT; |
| 640 | break; |
| 641 | } |
| 642 | |
| 643 | r = omapfb_update_window_nolock(fbi, p.uwnd_o.x, p.uwnd_o.y, |
| 644 | p.uwnd_o.width, p.uwnd_o.height); |
| 645 | break; |
| 646 | |
| 647 | case OMAPFB_UPDATE_WINDOW: |
| 648 | DBG("ioctl UPDATE_WINDOW\n"); |
Tomi Valkeinen | 18946f6 | 2010-01-12 14:16:41 +0200 | [diff] [blame] | 649 | if (!display || !display->driver->update) { |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 650 | r = -EINVAL; |
| 651 | break; |
| 652 | } |
| 653 | |
| 654 | if (copy_from_user(&p.uwnd, (void __user *)arg, |
| 655 | sizeof(p.uwnd))) { |
| 656 | r = -EFAULT; |
| 657 | break; |
| 658 | } |
| 659 | |
| 660 | r = omapfb_update_window_nolock(fbi, p.uwnd.x, p.uwnd.y, |
| 661 | p.uwnd.width, p.uwnd.height); |
| 662 | break; |
| 663 | |
| 664 | case OMAPFB_SETUP_PLANE: |
| 665 | DBG("ioctl SETUP_PLANE\n"); |
| 666 | if (copy_from_user(&p.plane_info, (void __user *)arg, |
| 667 | sizeof(p.plane_info))) |
| 668 | r = -EFAULT; |
| 669 | else |
| 670 | r = omapfb_setup_plane(fbi, &p.plane_info); |
| 671 | break; |
| 672 | |
| 673 | case OMAPFB_QUERY_PLANE: |
| 674 | DBG("ioctl QUERY_PLANE\n"); |
| 675 | r = omapfb_query_plane(fbi, &p.plane_info); |
| 676 | if (r < 0) |
| 677 | break; |
| 678 | if (copy_to_user((void __user *)arg, &p.plane_info, |
| 679 | sizeof(p.plane_info))) |
| 680 | r = -EFAULT; |
| 681 | break; |
| 682 | |
| 683 | case OMAPFB_SETUP_MEM: |
| 684 | DBG("ioctl SETUP_MEM\n"); |
| 685 | if (copy_from_user(&p.mem_info, (void __user *)arg, |
| 686 | sizeof(p.mem_info))) |
| 687 | r = -EFAULT; |
| 688 | else |
| 689 | r = omapfb_setup_mem(fbi, &p.mem_info); |
| 690 | break; |
| 691 | |
| 692 | case OMAPFB_QUERY_MEM: |
| 693 | DBG("ioctl QUERY_MEM\n"); |
| 694 | r = omapfb_query_mem(fbi, &p.mem_info); |
| 695 | if (r < 0) |
| 696 | break; |
| 697 | if (copy_to_user((void __user *)arg, &p.mem_info, |
| 698 | sizeof(p.mem_info))) |
| 699 | r = -EFAULT; |
| 700 | break; |
| 701 | |
| 702 | case OMAPFB_GET_CAPS: |
| 703 | DBG("ioctl GET_CAPS\n"); |
| 704 | if (!display) { |
| 705 | r = -EINVAL; |
| 706 | break; |
| 707 | } |
| 708 | |
| 709 | memset(&p.caps, 0, sizeof(p.caps)); |
| 710 | if (display->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE) |
| 711 | p.caps.ctrl |= OMAPFB_CAPS_MANUAL_UPDATE; |
| 712 | if (display->caps & OMAP_DSS_DISPLAY_CAP_TEAR_ELIM) |
| 713 | p.caps.ctrl |= OMAPFB_CAPS_TEARSYNC; |
| 714 | |
| 715 | if (copy_to_user((void __user *)arg, &p.caps, sizeof(p.caps))) |
| 716 | r = -EFAULT; |
| 717 | break; |
| 718 | |
| 719 | case OMAPFB_GET_OVERLAY_COLORMODE: |
| 720 | DBG("ioctl GET_OVERLAY_COLORMODE\n"); |
| 721 | if (copy_from_user(&p.ovl_colormode, (void __user *)arg, |
| 722 | sizeof(p.ovl_colormode))) { |
| 723 | r = -EFAULT; |
| 724 | break; |
| 725 | } |
| 726 | r = omapfb_get_ovl_colormode(fbdev, &p.ovl_colormode); |
| 727 | if (r < 0) |
| 728 | break; |
| 729 | if (copy_to_user((void __user *)arg, &p.ovl_colormode, |
| 730 | sizeof(p.ovl_colormode))) |
| 731 | r = -EFAULT; |
| 732 | break; |
| 733 | |
| 734 | case OMAPFB_SET_UPDATE_MODE: |
| 735 | DBG("ioctl SET_UPDATE_MODE\n"); |
| 736 | if (get_user(p.update_mode, (int __user *)arg)) |
| 737 | r = -EFAULT; |
| 738 | else |
| 739 | r = omapfb_set_update_mode(fbi, p.update_mode); |
| 740 | break; |
| 741 | |
| 742 | case OMAPFB_GET_UPDATE_MODE: |
| 743 | DBG("ioctl GET_UPDATE_MODE\n"); |
| 744 | r = omapfb_get_update_mode(fbi, &p.update_mode); |
| 745 | if (r) |
| 746 | break; |
| 747 | if (put_user(p.update_mode, |
| 748 | (enum omapfb_update_mode __user *)arg)) |
| 749 | r = -EFAULT; |
| 750 | break; |
| 751 | |
| 752 | case OMAPFB_SET_COLOR_KEY: |
| 753 | DBG("ioctl SET_COLOR_KEY\n"); |
| 754 | if (copy_from_user(&p.color_key, (void __user *)arg, |
| 755 | sizeof(p.color_key))) |
| 756 | r = -EFAULT; |
| 757 | else |
| 758 | r = omapfb_set_color_key(fbi, &p.color_key); |
| 759 | break; |
| 760 | |
| 761 | case OMAPFB_GET_COLOR_KEY: |
| 762 | DBG("ioctl GET_COLOR_KEY\n"); |
| 763 | r = omapfb_get_color_key(fbi, &p.color_key); |
| 764 | if (r) |
| 765 | break; |
| 766 | if (copy_to_user((void __user *)arg, &p.color_key, |
| 767 | sizeof(p.color_key))) |
| 768 | r = -EFAULT; |
| 769 | break; |
| 770 | |
| 771 | case OMAPFB_WAITFORVSYNC: |
| 772 | DBG("ioctl WAITFORVSYNC\n"); |
| 773 | if (!display) { |
| 774 | r = -EINVAL; |
| 775 | break; |
| 776 | } |
| 777 | |
Tomi Valkeinen | 3f71cbe | 2010-01-08 17:06:04 +0200 | [diff] [blame] | 778 | r = display->manager->wait_for_vsync(display->manager); |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 779 | break; |
| 780 | |
| 781 | case OMAPFB_WAITFORGO: |
| 782 | DBG("ioctl WAITFORGO\n"); |
| 783 | if (!display) { |
| 784 | r = -EINVAL; |
| 785 | break; |
| 786 | } |
| 787 | |
| 788 | r = omapfb_wait_for_go(fbi); |
| 789 | break; |
| 790 | |
| 791 | /* LCD and CTRL tests do the same thing for backward |
| 792 | * compatibility */ |
| 793 | case OMAPFB_LCD_TEST: |
| 794 | DBG("ioctl LCD_TEST\n"); |
| 795 | if (get_user(p.test_num, (int __user *)arg)) { |
| 796 | r = -EFAULT; |
| 797 | break; |
| 798 | } |
Tomi Valkeinen | 1a75ef4 | 2010-01-08 16:21:28 +0200 | [diff] [blame] | 799 | if (!display || !display->driver->run_test) { |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 800 | r = -EINVAL; |
| 801 | break; |
| 802 | } |
| 803 | |
Tomi Valkeinen | 1a75ef4 | 2010-01-08 16:21:28 +0200 | [diff] [blame] | 804 | r = display->driver->run_test(display, p.test_num); |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 805 | |
| 806 | break; |
| 807 | |
| 808 | case OMAPFB_CTRL_TEST: |
| 809 | DBG("ioctl CTRL_TEST\n"); |
| 810 | if (get_user(p.test_num, (int __user *)arg)) { |
| 811 | r = -EFAULT; |
| 812 | break; |
| 813 | } |
Tomi Valkeinen | 1a75ef4 | 2010-01-08 16:21:28 +0200 | [diff] [blame] | 814 | if (!display || !display->driver->run_test) { |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 815 | r = -EINVAL; |
| 816 | break; |
| 817 | } |
| 818 | |
Tomi Valkeinen | 1a75ef4 | 2010-01-08 16:21:28 +0200 | [diff] [blame] | 819 | r = display->driver->run_test(display, p.test_num); |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 820 | |
| 821 | break; |
| 822 | |
| 823 | case OMAPFB_MEMORY_READ: |
| 824 | DBG("ioctl MEMORY_READ\n"); |
| 825 | |
| 826 | if (copy_from_user(&p.memory_read, (void __user *)arg, |
| 827 | sizeof(p.memory_read))) { |
| 828 | r = -EFAULT; |
| 829 | break; |
| 830 | } |
| 831 | |
| 832 | r = omapfb_memory_read(fbi, &p.memory_read); |
| 833 | |
| 834 | break; |
| 835 | |
| 836 | case OMAPFB_GET_VRAM_INFO: { |
| 837 | unsigned long vram, free, largest; |
| 838 | |
| 839 | DBG("ioctl GET_VRAM_INFO\n"); |
| 840 | |
| 841 | omap_vram_get_info(&vram, &free, &largest); |
| 842 | p.vram_info.total = vram; |
| 843 | p.vram_info.free = free; |
| 844 | p.vram_info.largest_free_block = largest; |
| 845 | |
| 846 | if (copy_to_user((void __user *)arg, &p.vram_info, |
| 847 | sizeof(p.vram_info))) |
| 848 | r = -EFAULT; |
| 849 | break; |
| 850 | } |
| 851 | |
| 852 | case OMAPFB_SET_TEARSYNC: { |
| 853 | DBG("ioctl SET_TEARSYNC\n"); |
| 854 | |
| 855 | if (copy_from_user(&p.tearsync_info, (void __user *)arg, |
| 856 | sizeof(p.tearsync_info))) { |
| 857 | r = -EFAULT; |
| 858 | break; |
| 859 | } |
| 860 | |
Tomi Valkeinen | 225b650 | 2010-01-11 15:11:01 +0200 | [diff] [blame] | 861 | if (!display->driver->enable_te) { |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 862 | r = -ENODEV; |
| 863 | break; |
| 864 | } |
| 865 | |
Tomi Valkeinen | 225b650 | 2010-01-11 15:11:01 +0200 | [diff] [blame] | 866 | r = display->driver->enable_te(display, |
| 867 | !!p.tearsync_info.enabled); |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 868 | |
| 869 | break; |
| 870 | } |
| 871 | |
Tomi Valkeinen | 6dd2e42 | 2010-01-14 17:32:13 +0200 | [diff] [blame] | 872 | case OMAPFB_GET_DISPLAY_INFO: { |
| 873 | u16 xres, yres; |
| 874 | |
| 875 | DBG("ioctl GET_DISPLAY_INFO\n"); |
| 876 | |
| 877 | if (display == NULL) { |
| 878 | r = -ENODEV; |
| 879 | break; |
| 880 | } |
| 881 | |
Tomi Valkeinen | 96adcec | 2010-01-11 13:54:33 +0200 | [diff] [blame] | 882 | display->driver->get_resolution(display, &xres, &yres); |
Tomi Valkeinen | 6dd2e42 | 2010-01-14 17:32:13 +0200 | [diff] [blame] | 883 | |
| 884 | p.display_info.xres = xres; |
| 885 | p.display_info.yres = yres; |
| 886 | p.display_info.width = 0; |
| 887 | p.display_info.height = 0; |
| 888 | |
| 889 | if (copy_to_user((void __user *)arg, &p.display_info, |
| 890 | sizeof(p.display_info))) |
| 891 | r = -EFAULT; |
| 892 | break; |
| 893 | } |
| 894 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 895 | default: |
| 896 | dev_err(fbdev->dev, "Unknown ioctl 0x%x\n", cmd); |
| 897 | r = -EINVAL; |
| 898 | } |
| 899 | |
| 900 | if (r < 0) |
| 901 | DBG("ioctl failed: %d\n", r); |
| 902 | |
| 903 | return r; |
| 904 | } |
| 905 | |
| 906 | |