Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 1 | /* |
| 2 | * omap_vout.c |
| 3 | * |
| 4 | * Copyright (C) 2005-2010 Texas Instruments. |
| 5 | * |
| 6 | * This file is licensed under the terms of the GNU General Public License |
| 7 | * version 2. This program is licensed "as is" without any warranty of any |
| 8 | * kind, whether express or implied. |
| 9 | * |
| 10 | * Leveraged code from the OMAP2 camera driver |
| 11 | * Video-for-Linux (Version 2) camera capture driver for |
| 12 | * the OMAP24xx camera controller. |
| 13 | * |
| 14 | * Author: Andy Lowe (source@mvista.com) |
| 15 | * |
| 16 | * Copyright (C) 2004 MontaVista Software, Inc. |
| 17 | * Copyright (C) 2010 Texas Instruments. |
| 18 | * |
| 19 | * History: |
| 20 | * 20-APR-2006 Khasim Modified VRFB based Rotation, |
| 21 | * The image data is always read from 0 degree |
| 22 | * view and written |
| 23 | * to the virtual space of desired rotation angle |
| 24 | * 4-DEC-2006 Jian Changed to support better memory management |
| 25 | * |
| 26 | * 17-Nov-2008 Hardik Changed driver to use video_ioctl2 |
| 27 | * |
| 28 | * 23-Feb-2010 Vaibhav H Modified to use new DSS2 interface |
| 29 | * |
| 30 | */ |
| 31 | |
| 32 | #include <linux/init.h> |
| 33 | #include <linux/module.h> |
| 34 | #include <linux/vmalloc.h> |
| 35 | #include <linux/sched.h> |
| 36 | #include <linux/types.h> |
| 37 | #include <linux/platform_device.h> |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 38 | #include <linux/irq.h> |
| 39 | #include <linux/videodev2.h> |
| 40 | |
Vaibhav Hiremath | dd880dd | 2010-05-27 08:17:08 -0300 | [diff] [blame] | 41 | #include <media/videobuf-dma-contig.h> |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 42 | #include <media/v4l2-device.h> |
| 43 | #include <media/v4l2-ioctl.h> |
| 44 | |
| 45 | #include <plat/dma.h> |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 46 | #include <plat/vrfb.h> |
Tomi Valkeinen | a0b38cc | 2011-05-11 14:05:07 +0300 | [diff] [blame] | 47 | #include <video/omapdss.h> |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 48 | |
| 49 | #include "omap_voutlib.h" |
| 50 | #include "omap_voutdef.h" |
| 51 | |
| 52 | MODULE_AUTHOR("Texas Instruments"); |
| 53 | MODULE_DESCRIPTION("OMAP Video for Linux Video out driver"); |
| 54 | MODULE_LICENSE("GPL"); |
| 55 | |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 56 | /* Driver Configuration macros */ |
| 57 | #define VOUT_NAME "omap_vout" |
| 58 | |
| 59 | enum omap_vout_channels { |
| 60 | OMAP_VIDEO1, |
| 61 | OMAP_VIDEO2, |
| 62 | }; |
| 63 | |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 64 | static struct videobuf_queue_ops video_vbq_ops; |
| 65 | /* Variables configurable through module params*/ |
| 66 | static u32 video1_numbuffers = 3; |
| 67 | static u32 video2_numbuffers = 3; |
| 68 | static u32 video1_bufsize = OMAP_VOUT_MAX_BUF_SIZE; |
| 69 | static u32 video2_bufsize = OMAP_VOUT_MAX_BUF_SIZE; |
| 70 | static u32 vid1_static_vrfb_alloc; |
| 71 | static u32 vid2_static_vrfb_alloc; |
| 72 | static int debug; |
| 73 | |
| 74 | /* Module parameters */ |
| 75 | module_param(video1_numbuffers, uint, S_IRUGO); |
| 76 | MODULE_PARM_DESC(video1_numbuffers, |
| 77 | "Number of buffers to be allocated at init time for Video1 device."); |
| 78 | |
| 79 | module_param(video2_numbuffers, uint, S_IRUGO); |
| 80 | MODULE_PARM_DESC(video2_numbuffers, |
| 81 | "Number of buffers to be allocated at init time for Video2 device."); |
| 82 | |
| 83 | module_param(video1_bufsize, uint, S_IRUGO); |
| 84 | MODULE_PARM_DESC(video1_bufsize, |
| 85 | "Size of the buffer to be allocated for video1 device"); |
| 86 | |
| 87 | module_param(video2_bufsize, uint, S_IRUGO); |
| 88 | MODULE_PARM_DESC(video2_bufsize, |
| 89 | "Size of the buffer to be allocated for video2 device"); |
| 90 | |
| 91 | module_param(vid1_static_vrfb_alloc, bool, S_IRUGO); |
| 92 | MODULE_PARM_DESC(vid1_static_vrfb_alloc, |
| 93 | "Static allocation of the VRFB buffer for video1 device"); |
| 94 | |
| 95 | module_param(vid2_static_vrfb_alloc, bool, S_IRUGO); |
| 96 | MODULE_PARM_DESC(vid2_static_vrfb_alloc, |
| 97 | "Static allocation of the VRFB buffer for video2 device"); |
| 98 | |
| 99 | module_param(debug, bool, S_IRUGO); |
| 100 | MODULE_PARM_DESC(debug, "Debug level (0-1)"); |
| 101 | |
| 102 | /* list of image formats supported by OMAP2 video pipelines */ |
Jesper Juhl | 0d334f7 | 2011-07-09 18:22:17 -0300 | [diff] [blame] | 103 | static const struct v4l2_fmtdesc omap_formats[] = { |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 104 | { |
| 105 | /* Note: V4L2 defines RGB565 as: |
| 106 | * |
| 107 | * Byte 0 Byte 1 |
| 108 | * g2 g1 g0 r4 r3 r2 r1 r0 b4 b3 b2 b1 b0 g5 g4 g3 |
| 109 | * |
| 110 | * We interpret RGB565 as: |
| 111 | * |
| 112 | * Byte 0 Byte 1 |
| 113 | * g2 g1 g0 b4 b3 b2 b1 b0 r4 r3 r2 r1 r0 g5 g4 g3 |
| 114 | */ |
| 115 | .description = "RGB565, le", |
| 116 | .pixelformat = V4L2_PIX_FMT_RGB565, |
| 117 | }, |
| 118 | { |
| 119 | /* Note: V4L2 defines RGB32 as: RGB-8-8-8-8 we use |
| 120 | * this for RGB24 unpack mode, the last 8 bits are ignored |
| 121 | * */ |
| 122 | .description = "RGB32, le", |
| 123 | .pixelformat = V4L2_PIX_FMT_RGB32, |
| 124 | }, |
| 125 | { |
| 126 | /* Note: V4L2 defines RGB24 as: RGB-8-8-8 we use |
| 127 | * this for RGB24 packed mode |
| 128 | * |
| 129 | */ |
| 130 | .description = "RGB24, le", |
| 131 | .pixelformat = V4L2_PIX_FMT_RGB24, |
| 132 | }, |
| 133 | { |
| 134 | .description = "YUYV (YUV 4:2:2), packed", |
| 135 | .pixelformat = V4L2_PIX_FMT_YUYV, |
| 136 | }, |
| 137 | { |
| 138 | .description = "UYVY, packed", |
| 139 | .pixelformat = V4L2_PIX_FMT_UYVY, |
| 140 | }, |
| 141 | }; |
| 142 | |
| 143 | #define NUM_OUTPUT_FORMATS (ARRAY_SIZE(omap_formats)) |
| 144 | |
| 145 | /* |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 146 | * Function for allocating video buffers |
| 147 | */ |
| 148 | static int omap_vout_allocate_vrfb_buffers(struct omap_vout_device *vout, |
| 149 | unsigned int *count, int startindex) |
| 150 | { |
| 151 | int i, j; |
| 152 | |
| 153 | for (i = 0; i < *count; i++) { |
| 154 | if (!vout->smsshado_virt_addr[i]) { |
| 155 | vout->smsshado_virt_addr[i] = |
| 156 | omap_vout_alloc_buffer(vout->smsshado_size, |
| 157 | &vout->smsshado_phy_addr[i]); |
| 158 | } |
| 159 | if (!vout->smsshado_virt_addr[i] && startindex != -1) { |
| 160 | if (V4L2_MEMORY_MMAP == vout->memory && i >= startindex) |
| 161 | break; |
| 162 | } |
| 163 | if (!vout->smsshado_virt_addr[i]) { |
| 164 | for (j = 0; j < i; j++) { |
| 165 | omap_vout_free_buffer( |
| 166 | vout->smsshado_virt_addr[j], |
| 167 | vout->smsshado_size); |
| 168 | vout->smsshado_virt_addr[j] = 0; |
| 169 | vout->smsshado_phy_addr[j] = 0; |
| 170 | } |
| 171 | *count = 0; |
| 172 | return -ENOMEM; |
| 173 | } |
| 174 | memset((void *) vout->smsshado_virt_addr[i], 0, |
| 175 | vout->smsshado_size); |
| 176 | } |
| 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | /* |
| 181 | * Try format |
| 182 | */ |
| 183 | static int omap_vout_try_format(struct v4l2_pix_format *pix) |
| 184 | { |
| 185 | int ifmt, bpp = 0; |
| 186 | |
| 187 | pix->height = clamp(pix->height, (u32)VID_MIN_HEIGHT, |
| 188 | (u32)VID_MAX_HEIGHT); |
| 189 | pix->width = clamp(pix->width, (u32)VID_MIN_WIDTH, (u32)VID_MAX_WIDTH); |
| 190 | |
| 191 | for (ifmt = 0; ifmt < NUM_OUTPUT_FORMATS; ifmt++) { |
| 192 | if (pix->pixelformat == omap_formats[ifmt].pixelformat) |
| 193 | break; |
| 194 | } |
| 195 | |
| 196 | if (ifmt == NUM_OUTPUT_FORMATS) |
| 197 | ifmt = 0; |
| 198 | |
| 199 | pix->pixelformat = omap_formats[ifmt].pixelformat; |
| 200 | pix->field = V4L2_FIELD_ANY; |
| 201 | pix->priv = 0; |
| 202 | |
| 203 | switch (pix->pixelformat) { |
| 204 | case V4L2_PIX_FMT_YUYV: |
| 205 | case V4L2_PIX_FMT_UYVY: |
| 206 | default: |
| 207 | pix->colorspace = V4L2_COLORSPACE_JPEG; |
| 208 | bpp = YUYV_BPP; |
| 209 | break; |
| 210 | case V4L2_PIX_FMT_RGB565: |
| 211 | case V4L2_PIX_FMT_RGB565X: |
| 212 | pix->colorspace = V4L2_COLORSPACE_SRGB; |
| 213 | bpp = RGB565_BPP; |
| 214 | break; |
| 215 | case V4L2_PIX_FMT_RGB24: |
| 216 | pix->colorspace = V4L2_COLORSPACE_SRGB; |
| 217 | bpp = RGB24_BPP; |
| 218 | break; |
| 219 | case V4L2_PIX_FMT_RGB32: |
| 220 | case V4L2_PIX_FMT_BGR32: |
| 221 | pix->colorspace = V4L2_COLORSPACE_SRGB; |
| 222 | bpp = RGB32_BPP; |
| 223 | break; |
| 224 | } |
| 225 | pix->bytesperline = pix->width * bpp; |
| 226 | pix->sizeimage = pix->bytesperline * pix->height; |
| 227 | |
| 228 | return bpp; |
| 229 | } |
| 230 | |
| 231 | /* |
| 232 | * omap_vout_uservirt_to_phys: This inline function is used to convert user |
| 233 | * space virtual address to physical address. |
| 234 | */ |
| 235 | static u32 omap_vout_uservirt_to_phys(u32 virtp) |
| 236 | { |
| 237 | unsigned long physp = 0; |
| 238 | struct vm_area_struct *vma; |
| 239 | struct mm_struct *mm = current->mm; |
| 240 | |
| 241 | vma = find_vma(mm, virtp); |
| 242 | /* For kernel direct-mapped memory, take the easy way */ |
| 243 | if (virtp >= PAGE_OFFSET) { |
| 244 | physp = virt_to_phys((void *) virtp); |
| 245 | } else if (vma && (vma->vm_flags & VM_IO) && vma->vm_pgoff) { |
| 246 | /* this will catch, kernel-allocated, mmaped-to-usermode |
| 247 | addresses */ |
| 248 | physp = (vma->vm_pgoff << PAGE_SHIFT) + (virtp - vma->vm_start); |
| 249 | } else { |
| 250 | /* otherwise, use get_user_pages() for general userland pages */ |
| 251 | int res, nr_pages = 1; |
| 252 | struct page *pages; |
| 253 | down_read(¤t->mm->mmap_sem); |
| 254 | |
| 255 | res = get_user_pages(current, current->mm, virtp, nr_pages, 1, |
| 256 | 0, &pages, NULL); |
| 257 | up_read(¤t->mm->mmap_sem); |
| 258 | |
| 259 | if (res == nr_pages) { |
| 260 | physp = __pa(page_address(&pages[0]) + |
| 261 | (virtp & ~PAGE_MASK)); |
| 262 | } else { |
| 263 | printk(KERN_WARNING VOUT_NAME |
| 264 | "get_user_pages failed\n"); |
| 265 | return 0; |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | return physp; |
| 270 | } |
| 271 | |
| 272 | /* |
| 273 | * Wakes up the application once the DMA transfer to VRFB space is completed. |
| 274 | */ |
| 275 | static void omap_vout_vrfb_dma_tx_callback(int lch, u16 ch_status, void *data) |
| 276 | { |
| 277 | struct vid_vrfb_dma *t = (struct vid_vrfb_dma *) data; |
| 278 | |
| 279 | t->tx_status = 1; |
| 280 | wake_up_interruptible(&t->wait); |
| 281 | } |
| 282 | |
| 283 | /* |
| 284 | * Release the VRFB context once the module exits |
| 285 | */ |
| 286 | static void omap_vout_release_vrfb(struct omap_vout_device *vout) |
| 287 | { |
| 288 | int i; |
| 289 | |
| 290 | for (i = 0; i < VRFB_NUM_BUFS; i++) |
| 291 | omap_vrfb_release_ctx(&vout->vrfb_context[i]); |
| 292 | |
| 293 | if (vout->vrfb_dma_tx.req_status == DMA_CHAN_ALLOTED) { |
| 294 | vout->vrfb_dma_tx.req_status = DMA_CHAN_NOT_ALLOTED; |
| 295 | omap_free_dma(vout->vrfb_dma_tx.dma_ch); |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | /* |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 300 | * Free the V4L2 buffers |
| 301 | */ |
| 302 | static void omap_vout_free_buffers(struct omap_vout_device *vout) |
| 303 | { |
| 304 | int i, numbuffers; |
| 305 | |
| 306 | /* Allocate memory for the buffers */ |
| 307 | numbuffers = (vout->vid) ? video2_numbuffers : video1_numbuffers; |
| 308 | vout->buffer_size = (vout->vid) ? video2_bufsize : video1_bufsize; |
| 309 | |
| 310 | for (i = 0; i < numbuffers; i++) { |
| 311 | omap_vout_free_buffer(vout->buf_virt_addr[i], |
| 312 | vout->buffer_size); |
| 313 | vout->buf_phy_addr[i] = 0; |
| 314 | vout->buf_virt_addr[i] = 0; |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | /* |
| 319 | * Free VRFB buffers |
| 320 | */ |
| 321 | static void omap_vout_free_vrfb_buffers(struct omap_vout_device *vout) |
| 322 | { |
| 323 | int j; |
| 324 | |
| 325 | for (j = 0; j < VRFB_NUM_BUFS; j++) { |
| 326 | omap_vout_free_buffer(vout->smsshado_virt_addr[j], |
| 327 | vout->smsshado_size); |
| 328 | vout->smsshado_virt_addr[j] = 0; |
| 329 | vout->smsshado_phy_addr[j] = 0; |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | /* |
| 334 | * Allocate the buffers for the VRFB space. Data is copied from V4L2 |
| 335 | * buffers to the VRFB buffers using the DMA engine. |
| 336 | */ |
| 337 | static int omap_vout_vrfb_buffer_setup(struct omap_vout_device *vout, |
| 338 | unsigned int *count, unsigned int startindex) |
| 339 | { |
| 340 | int i; |
| 341 | bool yuv_mode; |
| 342 | |
| 343 | /* Allocate the VRFB buffers only if the buffers are not |
| 344 | * allocated during init time. |
| 345 | */ |
archit taneja | b366888 | 2011-06-14 03:54:46 -0300 | [diff] [blame^] | 346 | if ((is_rotation_enabled(vout)) && !vout->vrfb_static_allocation) |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 347 | if (omap_vout_allocate_vrfb_buffers(vout, count, startindex)) |
| 348 | return -ENOMEM; |
| 349 | |
| 350 | if (vout->dss_mode == OMAP_DSS_COLOR_YUV2 || |
| 351 | vout->dss_mode == OMAP_DSS_COLOR_UYVY) |
| 352 | yuv_mode = true; |
| 353 | else |
| 354 | yuv_mode = false; |
| 355 | |
| 356 | for (i = 0; i < *count; i++) |
| 357 | omap_vrfb_setup(&vout->vrfb_context[i], |
| 358 | vout->smsshado_phy_addr[i], vout->pix.width, |
| 359 | vout->pix.height, vout->bpp, yuv_mode); |
| 360 | |
| 361 | return 0; |
| 362 | } |
| 363 | |
| 364 | /* |
| 365 | * Convert V4L2 rotation to DSS rotation |
| 366 | * V4L2 understand 0, 90, 180, 270. |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 367 | * Convert to 0, 1, 2 and 3 respectively for DSS |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 368 | */ |
| 369 | static int v4l2_rot_to_dss_rot(int v4l2_rotation, |
| 370 | enum dss_rotation *rotation, bool mirror) |
| 371 | { |
| 372 | int ret = 0; |
| 373 | |
| 374 | switch (v4l2_rotation) { |
| 375 | case 90: |
| 376 | *rotation = dss_rotation_90_degree; |
| 377 | break; |
| 378 | case 180: |
| 379 | *rotation = dss_rotation_180_degree; |
| 380 | break; |
| 381 | case 270: |
| 382 | *rotation = dss_rotation_270_degree; |
| 383 | break; |
| 384 | case 0: |
| 385 | *rotation = dss_rotation_0_degree; |
| 386 | break; |
| 387 | default: |
| 388 | ret = -EINVAL; |
| 389 | } |
| 390 | return ret; |
| 391 | } |
| 392 | |
| 393 | /* |
| 394 | * Calculate the buffer offsets from which the streaming should |
| 395 | * start. This offset calculation is mainly required because of |
| 396 | * the VRFB 32 pixels alignment with rotation. |
| 397 | */ |
| 398 | static int omap_vout_calculate_offset(struct omap_vout_device *vout) |
| 399 | { |
| 400 | struct omap_overlay *ovl; |
| 401 | enum dss_rotation rotation; |
| 402 | struct omapvideo_info *ovid; |
| 403 | bool mirroring = vout->mirror; |
| 404 | struct omap_dss_device *cur_display; |
| 405 | struct v4l2_rect *crop = &vout->crop; |
| 406 | struct v4l2_pix_format *pix = &vout->pix; |
| 407 | int *cropped_offset = &vout->cropped_offset; |
| 408 | int vr_ps = 1, ps = 2, temp_ps = 2; |
| 409 | int offset = 0, ctop = 0, cleft = 0, line_length = 0; |
| 410 | |
| 411 | ovid = &vout->vid_info; |
| 412 | ovl = ovid->overlays[0]; |
| 413 | /* get the display device attached to the overlay */ |
| 414 | if (!ovl->manager || !ovl->manager->device) |
| 415 | return -1; |
| 416 | |
| 417 | cur_display = ovl->manager->device; |
| 418 | rotation = calc_rotation(vout); |
| 419 | |
| 420 | if (V4L2_PIX_FMT_YUYV == pix->pixelformat || |
| 421 | V4L2_PIX_FMT_UYVY == pix->pixelformat) { |
archit taneja | b366888 | 2011-06-14 03:54:46 -0300 | [diff] [blame^] | 422 | if (is_rotation_enabled(vout)) { |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 423 | /* |
| 424 | * ps - Actual pixel size for YUYV/UYVY for |
| 425 | * VRFB/Mirroring is 4 bytes |
| 426 | * vr_ps - Virtually pixel size for YUYV/UYVY is |
| 427 | * 2 bytes |
| 428 | */ |
| 429 | ps = 4; |
| 430 | vr_ps = 2; |
| 431 | } else { |
| 432 | ps = 2; /* otherwise the pixel size is 2 byte */ |
| 433 | } |
| 434 | } else if (V4L2_PIX_FMT_RGB32 == pix->pixelformat) { |
| 435 | ps = 4; |
| 436 | } else if (V4L2_PIX_FMT_RGB24 == pix->pixelformat) { |
| 437 | ps = 3; |
| 438 | } |
| 439 | vout->ps = ps; |
| 440 | vout->vr_ps = vr_ps; |
| 441 | |
archit taneja | b366888 | 2011-06-14 03:54:46 -0300 | [diff] [blame^] | 442 | if (is_rotation_enabled(vout)) { |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 443 | line_length = MAX_PIXELS_PER_LINE; |
| 444 | ctop = (pix->height - crop->height) - crop->top; |
| 445 | cleft = (pix->width - crop->width) - crop->left; |
| 446 | } else { |
| 447 | line_length = pix->width; |
| 448 | } |
| 449 | vout->line_length = line_length; |
| 450 | switch (rotation) { |
| 451 | case dss_rotation_90_degree: |
| 452 | offset = vout->vrfb_context[0].yoffset * |
| 453 | vout->vrfb_context[0].bytespp; |
| 454 | temp_ps = ps / vr_ps; |
| 455 | if (mirroring == 0) { |
| 456 | *cropped_offset = offset + line_length * |
| 457 | temp_ps * cleft + crop->top * temp_ps; |
| 458 | } else { |
| 459 | *cropped_offset = offset + line_length * temp_ps * |
| 460 | cleft + crop->top * temp_ps + (line_length * |
| 461 | ((crop->width / (vr_ps)) - 1) * ps); |
| 462 | } |
| 463 | break; |
| 464 | case dss_rotation_180_degree: |
| 465 | offset = ((MAX_PIXELS_PER_LINE * vout->vrfb_context[0].yoffset * |
| 466 | vout->vrfb_context[0].bytespp) + |
| 467 | (vout->vrfb_context[0].xoffset * |
| 468 | vout->vrfb_context[0].bytespp)); |
| 469 | if (mirroring == 0) { |
| 470 | *cropped_offset = offset + (line_length * ps * ctop) + |
| 471 | (cleft / vr_ps) * ps; |
| 472 | |
| 473 | } else { |
| 474 | *cropped_offset = offset + (line_length * ps * ctop) + |
| 475 | (cleft / vr_ps) * ps + (line_length * |
| 476 | (crop->height - 1) * ps); |
| 477 | } |
| 478 | break; |
| 479 | case dss_rotation_270_degree: |
| 480 | offset = MAX_PIXELS_PER_LINE * vout->vrfb_context[0].xoffset * |
| 481 | vout->vrfb_context[0].bytespp; |
| 482 | temp_ps = ps / vr_ps; |
| 483 | if (mirroring == 0) { |
| 484 | *cropped_offset = offset + line_length * |
| 485 | temp_ps * crop->left + ctop * ps; |
| 486 | } else { |
| 487 | *cropped_offset = offset + line_length * |
| 488 | temp_ps * crop->left + ctop * ps + |
| 489 | (line_length * ((crop->width / vr_ps) - 1) * |
| 490 | ps); |
| 491 | } |
| 492 | break; |
| 493 | case dss_rotation_0_degree: |
| 494 | if (mirroring == 0) { |
| 495 | *cropped_offset = (line_length * ps) * |
| 496 | crop->top + (crop->left / vr_ps) * ps; |
| 497 | } else { |
| 498 | *cropped_offset = (line_length * ps) * |
| 499 | crop->top + (crop->left / vr_ps) * ps + |
| 500 | (line_length * (crop->height - 1) * ps); |
| 501 | } |
| 502 | break; |
| 503 | default: |
| 504 | *cropped_offset = (line_length * ps * crop->top) / |
| 505 | vr_ps + (crop->left * ps) / vr_ps + |
| 506 | ((crop->width / vr_ps) - 1) * ps; |
| 507 | break; |
| 508 | } |
| 509 | v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "%s Offset:%x\n", |
| 510 | __func__, *cropped_offset); |
| 511 | return 0; |
| 512 | } |
| 513 | |
| 514 | /* |
| 515 | * Convert V4L2 pixel format to DSS pixel format |
| 516 | */ |
Vaibhav Hiremath | 72fcf2a | 2010-04-11 10:50:23 -0300 | [diff] [blame] | 517 | static int video_mode_to_dss_mode(struct omap_vout_device *vout) |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 518 | { |
| 519 | struct omap_overlay *ovl; |
| 520 | struct omapvideo_info *ovid; |
| 521 | struct v4l2_pix_format *pix = &vout->pix; |
| 522 | enum omap_color_mode mode; |
| 523 | |
| 524 | ovid = &vout->vid_info; |
| 525 | ovl = ovid->overlays[0]; |
| 526 | |
| 527 | switch (pix->pixelformat) { |
| 528 | case 0: |
| 529 | break; |
| 530 | case V4L2_PIX_FMT_YUYV: |
| 531 | mode = OMAP_DSS_COLOR_YUV2; |
| 532 | break; |
| 533 | case V4L2_PIX_FMT_UYVY: |
| 534 | mode = OMAP_DSS_COLOR_UYVY; |
| 535 | break; |
| 536 | case V4L2_PIX_FMT_RGB565: |
| 537 | mode = OMAP_DSS_COLOR_RGB16; |
| 538 | break; |
| 539 | case V4L2_PIX_FMT_RGB24: |
| 540 | mode = OMAP_DSS_COLOR_RGB24P; |
| 541 | break; |
| 542 | case V4L2_PIX_FMT_RGB32: |
| 543 | mode = (ovl->id == OMAP_DSS_VIDEO1) ? |
| 544 | OMAP_DSS_COLOR_RGB24U : OMAP_DSS_COLOR_ARGB32; |
| 545 | break; |
| 546 | case V4L2_PIX_FMT_BGR32: |
| 547 | mode = OMAP_DSS_COLOR_RGBX32; |
| 548 | break; |
| 549 | default: |
| 550 | mode = -EINVAL; |
| 551 | } |
| 552 | return mode; |
| 553 | } |
| 554 | |
| 555 | /* |
| 556 | * Setup the overlay |
| 557 | */ |
archit taneja | a137ac8 | 2011-06-14 03:54:45 -0300 | [diff] [blame] | 558 | static int omapvid_setup_overlay(struct omap_vout_device *vout, |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 559 | struct omap_overlay *ovl, int posx, int posy, int outw, |
| 560 | int outh, u32 addr) |
| 561 | { |
| 562 | int ret = 0; |
| 563 | struct omap_overlay_info info; |
| 564 | int cropheight, cropwidth, pixheight, pixwidth; |
| 565 | |
| 566 | if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0 && |
| 567 | (outw != vout->pix.width || outh != vout->pix.height)) { |
| 568 | ret = -EINVAL; |
| 569 | goto setup_ovl_err; |
| 570 | } |
| 571 | |
| 572 | vout->dss_mode = video_mode_to_dss_mode(vout); |
| 573 | if (vout->dss_mode == -EINVAL) { |
| 574 | ret = -EINVAL; |
| 575 | goto setup_ovl_err; |
| 576 | } |
| 577 | |
| 578 | /* Setup the input plane parameters according to |
| 579 | * rotation value selected. |
| 580 | */ |
archit taneja | b366888 | 2011-06-14 03:54:46 -0300 | [diff] [blame^] | 581 | if (is_rotation_90_or_270(vout)) { |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 582 | cropheight = vout->crop.width; |
| 583 | cropwidth = vout->crop.height; |
| 584 | pixheight = vout->pix.width; |
| 585 | pixwidth = vout->pix.height; |
| 586 | } else { |
| 587 | cropheight = vout->crop.height; |
| 588 | cropwidth = vout->crop.width; |
| 589 | pixheight = vout->pix.height; |
| 590 | pixwidth = vout->pix.width; |
| 591 | } |
| 592 | |
| 593 | ovl->get_overlay_info(ovl, &info); |
| 594 | info.paddr = addr; |
| 595 | info.vaddr = NULL; |
| 596 | info.width = cropwidth; |
| 597 | info.height = cropheight; |
| 598 | info.color_mode = vout->dss_mode; |
| 599 | info.mirror = vout->mirror; |
| 600 | info.pos_x = posx; |
| 601 | info.pos_y = posy; |
| 602 | info.out_width = outw; |
| 603 | info.out_height = outh; |
| 604 | info.global_alpha = vout->win.global_alpha; |
archit taneja | b366888 | 2011-06-14 03:54:46 -0300 | [diff] [blame^] | 605 | if (!is_rotation_enabled(vout)) { |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 606 | info.rotation = 0; |
| 607 | info.rotation_type = OMAP_DSS_ROT_DMA; |
| 608 | info.screen_width = pixwidth; |
| 609 | } else { |
| 610 | info.rotation = vout->rotation; |
| 611 | info.rotation_type = OMAP_DSS_ROT_VRFB; |
| 612 | info.screen_width = 2048; |
| 613 | } |
| 614 | |
| 615 | v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, |
| 616 | "%s enable=%d addr=%x width=%d\n height=%d color_mode=%d\n" |
| 617 | "rotation=%d mirror=%d posx=%d posy=%d out_width = %d \n" |
| 618 | "out_height=%d rotation_type=%d screen_width=%d\n", |
| 619 | __func__, info.enabled, info.paddr, info.width, info.height, |
| 620 | info.color_mode, info.rotation, info.mirror, info.pos_x, |
| 621 | info.pos_y, info.out_width, info.out_height, info.rotation_type, |
| 622 | info.screen_width); |
| 623 | |
| 624 | ret = ovl->set_overlay_info(ovl, &info); |
| 625 | if (ret) |
| 626 | goto setup_ovl_err; |
| 627 | |
| 628 | return 0; |
| 629 | |
| 630 | setup_ovl_err: |
| 631 | v4l2_warn(&vout->vid_dev->v4l2_dev, "setup_overlay failed\n"); |
| 632 | return ret; |
| 633 | } |
| 634 | |
| 635 | /* |
| 636 | * Initialize the overlay structure |
| 637 | */ |
archit taneja | a137ac8 | 2011-06-14 03:54:45 -0300 | [diff] [blame] | 638 | static int omapvid_init(struct omap_vout_device *vout, u32 addr) |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 639 | { |
| 640 | int ret = 0, i; |
| 641 | struct v4l2_window *win; |
| 642 | struct omap_overlay *ovl; |
| 643 | int posx, posy, outw, outh, temp; |
| 644 | struct omap_video_timings *timing; |
| 645 | struct omapvideo_info *ovid = &vout->vid_info; |
| 646 | |
| 647 | win = &vout->win; |
| 648 | for (i = 0; i < ovid->num_overlays; i++) { |
| 649 | ovl = ovid->overlays[i]; |
| 650 | if (!ovl->manager || !ovl->manager->device) |
| 651 | return -EINVAL; |
| 652 | |
| 653 | timing = &ovl->manager->device->panel.timings; |
| 654 | |
| 655 | outw = win->w.width; |
| 656 | outh = win->w.height; |
| 657 | switch (vout->rotation) { |
| 658 | case dss_rotation_90_degree: |
| 659 | /* Invert the height and width for 90 |
| 660 | * and 270 degree rotation |
| 661 | */ |
| 662 | temp = outw; |
| 663 | outw = outh; |
| 664 | outh = temp; |
| 665 | posy = (timing->y_res - win->w.width) - win->w.left; |
| 666 | posx = win->w.top; |
| 667 | break; |
| 668 | |
| 669 | case dss_rotation_180_degree: |
| 670 | posx = (timing->x_res - win->w.width) - win->w.left; |
| 671 | posy = (timing->y_res - win->w.height) - win->w.top; |
| 672 | break; |
| 673 | |
| 674 | case dss_rotation_270_degree: |
| 675 | temp = outw; |
| 676 | outw = outh; |
| 677 | outh = temp; |
| 678 | posy = win->w.left; |
| 679 | posx = (timing->x_res - win->w.height) - win->w.top; |
| 680 | break; |
| 681 | |
| 682 | default: |
| 683 | posx = win->w.left; |
| 684 | posy = win->w.top; |
| 685 | break; |
| 686 | } |
| 687 | |
| 688 | ret = omapvid_setup_overlay(vout, ovl, posx, posy, |
| 689 | outw, outh, addr); |
| 690 | if (ret) |
| 691 | goto omapvid_init_err; |
| 692 | } |
| 693 | return 0; |
| 694 | |
| 695 | omapvid_init_err: |
| 696 | v4l2_warn(&vout->vid_dev->v4l2_dev, "apply_changes failed\n"); |
| 697 | return ret; |
| 698 | } |
| 699 | |
| 700 | /* |
| 701 | * Apply the changes set the go bit of DSS |
| 702 | */ |
archit taneja | a137ac8 | 2011-06-14 03:54:45 -0300 | [diff] [blame] | 703 | static int omapvid_apply_changes(struct omap_vout_device *vout) |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 704 | { |
| 705 | int i; |
| 706 | struct omap_overlay *ovl; |
| 707 | struct omapvideo_info *ovid = &vout->vid_info; |
| 708 | |
| 709 | for (i = 0; i < ovid->num_overlays; i++) { |
| 710 | ovl = ovid->overlays[i]; |
| 711 | if (!ovl->manager || !ovl->manager->device) |
| 712 | return -EINVAL; |
| 713 | ovl->manager->apply(ovl->manager); |
| 714 | } |
| 715 | |
| 716 | return 0; |
| 717 | } |
| 718 | |
archit taneja | a137ac8 | 2011-06-14 03:54:45 -0300 | [diff] [blame] | 719 | static void omap_vout_isr(void *arg, unsigned int irqstatus) |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 720 | { |
| 721 | int ret; |
| 722 | u32 addr, fid; |
| 723 | struct omap_overlay *ovl; |
| 724 | struct timeval timevalue; |
| 725 | struct omapvideo_info *ovid; |
| 726 | struct omap_dss_device *cur_display; |
| 727 | struct omap_vout_device *vout = (struct omap_vout_device *)arg; |
| 728 | |
| 729 | if (!vout->streaming) |
| 730 | return; |
| 731 | |
| 732 | ovid = &vout->vid_info; |
| 733 | ovl = ovid->overlays[0]; |
| 734 | /* get the display device attached to the overlay */ |
| 735 | if (!ovl->manager || !ovl->manager->device) |
| 736 | return; |
| 737 | |
| 738 | cur_display = ovl->manager->device; |
| 739 | |
| 740 | spin_lock(&vout->vbq_lock); |
| 741 | do_gettimeofday(&timevalue); |
| 742 | if (cur_display->type == OMAP_DISPLAY_TYPE_DPI) { |
| 743 | if (!(irqstatus & DISPC_IRQ_VSYNC)) |
| 744 | goto vout_isr_err; |
| 745 | |
| 746 | if (!vout->first_int && (vout->cur_frm != vout->next_frm)) { |
| 747 | vout->cur_frm->ts = timevalue; |
| 748 | vout->cur_frm->state = VIDEOBUF_DONE; |
| 749 | wake_up_interruptible(&vout->cur_frm->done); |
| 750 | vout->cur_frm = vout->next_frm; |
| 751 | } |
| 752 | vout->first_int = 0; |
| 753 | if (list_empty(&vout->dma_queue)) |
| 754 | goto vout_isr_err; |
| 755 | |
| 756 | vout->next_frm = list_entry(vout->dma_queue.next, |
| 757 | struct videobuf_buffer, queue); |
| 758 | list_del(&vout->next_frm->queue); |
| 759 | |
| 760 | vout->next_frm->state = VIDEOBUF_ACTIVE; |
| 761 | |
| 762 | addr = (unsigned long) vout->queued_buf_addr[vout->next_frm->i] |
| 763 | + vout->cropped_offset; |
| 764 | |
| 765 | /* First save the configuration in ovelray structure */ |
| 766 | ret = omapvid_init(vout, addr); |
| 767 | if (ret) |
| 768 | printk(KERN_ERR VOUT_NAME |
| 769 | "failed to set overlay info\n"); |
| 770 | /* Enable the pipeline and set the Go bit */ |
| 771 | ret = omapvid_apply_changes(vout); |
| 772 | if (ret) |
| 773 | printk(KERN_ERR VOUT_NAME "failed to change mode\n"); |
| 774 | } else { |
| 775 | |
| 776 | if (vout->first_int) { |
| 777 | vout->first_int = 0; |
| 778 | goto vout_isr_err; |
| 779 | } |
| 780 | if (irqstatus & DISPC_IRQ_EVSYNC_ODD) |
| 781 | fid = 1; |
| 782 | else if (irqstatus & DISPC_IRQ_EVSYNC_EVEN) |
| 783 | fid = 0; |
| 784 | else |
| 785 | goto vout_isr_err; |
| 786 | |
| 787 | vout->field_id ^= 1; |
| 788 | if (fid != vout->field_id) { |
| 789 | if (0 == fid) |
| 790 | vout->field_id = fid; |
| 791 | |
| 792 | goto vout_isr_err; |
| 793 | } |
| 794 | if (0 == fid) { |
| 795 | if (vout->cur_frm == vout->next_frm) |
| 796 | goto vout_isr_err; |
| 797 | |
| 798 | vout->cur_frm->ts = timevalue; |
| 799 | vout->cur_frm->state = VIDEOBUF_DONE; |
| 800 | wake_up_interruptible(&vout->cur_frm->done); |
| 801 | vout->cur_frm = vout->next_frm; |
| 802 | } else if (1 == fid) { |
| 803 | if (list_empty(&vout->dma_queue) || |
| 804 | (vout->cur_frm != vout->next_frm)) |
| 805 | goto vout_isr_err; |
| 806 | |
| 807 | vout->next_frm = list_entry(vout->dma_queue.next, |
| 808 | struct videobuf_buffer, queue); |
| 809 | list_del(&vout->next_frm->queue); |
| 810 | |
| 811 | vout->next_frm->state = VIDEOBUF_ACTIVE; |
| 812 | addr = (unsigned long) |
| 813 | vout->queued_buf_addr[vout->next_frm->i] + |
| 814 | vout->cropped_offset; |
| 815 | /* First save the configuration in ovelray structure */ |
| 816 | ret = omapvid_init(vout, addr); |
| 817 | if (ret) |
| 818 | printk(KERN_ERR VOUT_NAME |
| 819 | "failed to set overlay info\n"); |
| 820 | /* Enable the pipeline and set the Go bit */ |
| 821 | ret = omapvid_apply_changes(vout); |
| 822 | if (ret) |
| 823 | printk(KERN_ERR VOUT_NAME |
| 824 | "failed to change mode\n"); |
| 825 | } |
| 826 | |
| 827 | } |
| 828 | |
| 829 | vout_isr_err: |
| 830 | spin_unlock(&vout->vbq_lock); |
| 831 | } |
| 832 | |
| 833 | |
| 834 | /* Video buffer call backs */ |
| 835 | |
| 836 | /* |
| 837 | * Buffer setup function is called by videobuf layer when REQBUF ioctl is |
| 838 | * called. This is used to setup buffers and return size and count of |
| 839 | * buffers allocated. After the call to this buffer, videobuf layer will |
| 840 | * setup buffer queue depending on the size and count of buffers |
| 841 | */ |
| 842 | static int omap_vout_buffer_setup(struct videobuf_queue *q, unsigned int *count, |
| 843 | unsigned int *size) |
| 844 | { |
| 845 | int startindex = 0, i, j; |
| 846 | u32 phy_addr = 0, virt_addr = 0; |
| 847 | struct omap_vout_device *vout = q->priv_data; |
| 848 | |
| 849 | if (!vout) |
| 850 | return -EINVAL; |
| 851 | |
| 852 | if (V4L2_BUF_TYPE_VIDEO_OUTPUT != q->type) |
| 853 | return -EINVAL; |
| 854 | |
| 855 | startindex = (vout->vid == OMAP_VIDEO1) ? |
| 856 | video1_numbuffers : video2_numbuffers; |
| 857 | if (V4L2_MEMORY_MMAP == vout->memory && *count < startindex) |
| 858 | *count = startindex; |
| 859 | |
archit taneja | b366888 | 2011-06-14 03:54:46 -0300 | [diff] [blame^] | 860 | if ((is_rotation_enabled(vout)) && *count > VRFB_NUM_BUFS) |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 861 | *count = VRFB_NUM_BUFS; |
| 862 | |
| 863 | /* If rotation is enabled, allocate memory for VRFB space also */ |
archit taneja | b366888 | 2011-06-14 03:54:46 -0300 | [diff] [blame^] | 864 | if (is_rotation_enabled(vout)) |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 865 | if (omap_vout_vrfb_buffer_setup(vout, count, startindex)) |
| 866 | return -ENOMEM; |
| 867 | |
| 868 | if (V4L2_MEMORY_MMAP != vout->memory) |
| 869 | return 0; |
| 870 | |
| 871 | /* Now allocated the V4L2 buffers */ |
| 872 | *size = PAGE_ALIGN(vout->pix.width * vout->pix.height * vout->bpp); |
| 873 | startindex = (vout->vid == OMAP_VIDEO1) ? |
| 874 | video1_numbuffers : video2_numbuffers; |
| 875 | |
Vaibhav Hiremath | 383e4f6 | 2011-04-14 13:42:34 -0300 | [diff] [blame] | 876 | /* Check the size of the buffer */ |
| 877 | if (*size > vout->buffer_size) { |
| 878 | v4l2_err(&vout->vid_dev->v4l2_dev, |
| 879 | "buffer allocation mismatch [%u] [%u]\n", |
| 880 | *size, vout->buffer_size); |
| 881 | return -ENOMEM; |
| 882 | } |
| 883 | |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 884 | for (i = startindex; i < *count; i++) { |
| 885 | vout->buffer_size = *size; |
| 886 | |
| 887 | virt_addr = omap_vout_alloc_buffer(vout->buffer_size, |
| 888 | &phy_addr); |
| 889 | if (!virt_addr) { |
archit taneja | b366888 | 2011-06-14 03:54:46 -0300 | [diff] [blame^] | 890 | if (!is_rotation_enabled(vout)) |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 891 | break; |
| 892 | /* Free the VRFB buffers if no space for V4L2 buffers */ |
| 893 | for (j = i; j < *count; j++) { |
| 894 | omap_vout_free_buffer( |
| 895 | vout->smsshado_virt_addr[j], |
| 896 | vout->smsshado_size); |
| 897 | vout->smsshado_virt_addr[j] = 0; |
| 898 | vout->smsshado_phy_addr[j] = 0; |
| 899 | } |
| 900 | } |
| 901 | vout->buf_virt_addr[i] = virt_addr; |
| 902 | vout->buf_phy_addr[i] = phy_addr; |
| 903 | } |
| 904 | *count = vout->buffer_allocated = i; |
| 905 | |
| 906 | return 0; |
| 907 | } |
| 908 | |
| 909 | /* |
| 910 | * Free the V4L2 buffers additionally allocated than default |
| 911 | * number of buffers and free all the VRFB buffers |
| 912 | */ |
| 913 | static void omap_vout_free_allbuffers(struct omap_vout_device *vout) |
| 914 | { |
| 915 | int num_buffers = 0, i; |
| 916 | |
| 917 | num_buffers = (vout->vid == OMAP_VIDEO1) ? |
| 918 | video1_numbuffers : video2_numbuffers; |
| 919 | |
| 920 | for (i = num_buffers; i < vout->buffer_allocated; i++) { |
| 921 | if (vout->buf_virt_addr[i]) |
| 922 | omap_vout_free_buffer(vout->buf_virt_addr[i], |
| 923 | vout->buffer_size); |
| 924 | |
| 925 | vout->buf_virt_addr[i] = 0; |
| 926 | vout->buf_phy_addr[i] = 0; |
| 927 | } |
| 928 | /* Free the VRFB buffers only if they are allocated |
| 929 | * during reqbufs. Don't free if init time allocated |
| 930 | */ |
| 931 | if (!vout->vrfb_static_allocation) { |
| 932 | for (i = 0; i < VRFB_NUM_BUFS; i++) { |
| 933 | if (vout->smsshado_virt_addr[i]) { |
| 934 | omap_vout_free_buffer( |
| 935 | vout->smsshado_virt_addr[i], |
| 936 | vout->smsshado_size); |
| 937 | vout->smsshado_virt_addr[i] = 0; |
| 938 | vout->smsshado_phy_addr[i] = 0; |
| 939 | } |
| 940 | } |
| 941 | } |
| 942 | vout->buffer_allocated = num_buffers; |
| 943 | } |
| 944 | |
| 945 | /* |
| 946 | * This function will be called when VIDIOC_QBUF ioctl is called. |
| 947 | * It prepare buffers before give out for the display. This function |
| 948 | * converts user space virtual address into physical address if userptr memory |
| 949 | * exchange mechanism is used. If rotation is enabled, it copies entire |
| 950 | * buffer into VRFB memory space before giving it to the DSS. |
| 951 | */ |
| 952 | static int omap_vout_buffer_prepare(struct videobuf_queue *q, |
| 953 | struct videobuf_buffer *vb, |
| 954 | enum v4l2_field field) |
| 955 | { |
Vaibhav Hiremath | dd880dd | 2010-05-27 08:17:08 -0300 | [diff] [blame] | 956 | dma_addr_t dmabuf; |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 957 | struct vid_vrfb_dma *tx; |
| 958 | enum dss_rotation rotation; |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 959 | struct omap_vout_device *vout = q->priv_data; |
| 960 | u32 dest_frame_index = 0, src_element_index = 0; |
| 961 | u32 dest_element_index = 0, src_frame_index = 0; |
| 962 | u32 elem_count = 0, frame_count = 0, pixsize = 2; |
| 963 | |
| 964 | if (VIDEOBUF_NEEDS_INIT == vb->state) { |
| 965 | vb->width = vout->pix.width; |
| 966 | vb->height = vout->pix.height; |
| 967 | vb->size = vb->width * vb->height * vout->bpp; |
| 968 | vb->field = field; |
| 969 | } |
| 970 | vb->state = VIDEOBUF_PREPARED; |
| 971 | /* if user pointer memory mechanism is used, get the physical |
| 972 | * address of the buffer |
| 973 | */ |
| 974 | if (V4L2_MEMORY_USERPTR == vb->memory) { |
| 975 | if (0 == vb->baddr) |
| 976 | return -EINVAL; |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 977 | /* Physical address */ |
Vaibhav Hiremath | dd880dd | 2010-05-27 08:17:08 -0300 | [diff] [blame] | 978 | vout->queued_buf_addr[vb->i] = (u8 *) |
| 979 | omap_vout_uservirt_to_phys(vb->baddr); |
| 980 | } else { |
| 981 | vout->queued_buf_addr[vb->i] = (u8 *)vout->buf_phy_addr[vb->i]; |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 982 | } |
| 983 | |
archit taneja | b366888 | 2011-06-14 03:54:46 -0300 | [diff] [blame^] | 984 | if (!is_rotation_enabled(vout)) |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 985 | return 0; |
Vaibhav Hiremath | dd880dd | 2010-05-27 08:17:08 -0300 | [diff] [blame] | 986 | |
| 987 | dmabuf = vout->buf_phy_addr[vb->i]; |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 988 | /* If rotation is enabled, copy input buffer into VRFB |
| 989 | * memory space using DMA. We are copying input buffer |
| 990 | * into VRFB memory space of desired angle and DSS will |
| 991 | * read image VRFB memory for 0 degree angle |
| 992 | */ |
| 993 | pixsize = vout->bpp * vout->vrfb_bpp; |
| 994 | /* |
| 995 | * DMA transfer in double index mode |
| 996 | */ |
| 997 | |
| 998 | /* Frame index */ |
| 999 | dest_frame_index = ((MAX_PIXELS_PER_LINE * pixsize) - |
| 1000 | (vout->pix.width * vout->bpp)) + 1; |
| 1001 | |
| 1002 | /* Source and destination parameters */ |
| 1003 | src_element_index = 0; |
| 1004 | src_frame_index = 0; |
| 1005 | dest_element_index = 1; |
| 1006 | /* Number of elements per frame */ |
| 1007 | elem_count = vout->pix.width * vout->bpp; |
| 1008 | frame_count = vout->pix.height; |
| 1009 | tx = &vout->vrfb_dma_tx; |
| 1010 | tx->tx_status = 0; |
| 1011 | omap_set_dma_transfer_params(tx->dma_ch, OMAP_DMA_DATA_TYPE_S32, |
| 1012 | (elem_count / 4), frame_count, OMAP_DMA_SYNC_ELEMENT, |
| 1013 | tx->dev_id, 0x0); |
| 1014 | /* src_port required only for OMAP1 */ |
| 1015 | omap_set_dma_src_params(tx->dma_ch, 0, OMAP_DMA_AMODE_POST_INC, |
Vaibhav Hiremath | dd880dd | 2010-05-27 08:17:08 -0300 | [diff] [blame] | 1016 | dmabuf, src_element_index, src_frame_index); |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 1017 | /*set dma source burst mode for VRFB */ |
| 1018 | omap_set_dma_src_burst_mode(tx->dma_ch, OMAP_DMA_DATA_BURST_16); |
| 1019 | rotation = calc_rotation(vout); |
| 1020 | |
| 1021 | /* dest_port required only for OMAP1 */ |
| 1022 | omap_set_dma_dest_params(tx->dma_ch, 0, OMAP_DMA_AMODE_DOUBLE_IDX, |
| 1023 | vout->vrfb_context[vb->i].paddr[0], dest_element_index, |
| 1024 | dest_frame_index); |
| 1025 | /*set dma dest burst mode for VRFB */ |
| 1026 | omap_set_dma_dest_burst_mode(tx->dma_ch, OMAP_DMA_DATA_BURST_16); |
| 1027 | omap_dma_set_global_params(DMA_DEFAULT_ARB_RATE, 0x20, 0); |
| 1028 | |
| 1029 | omap_start_dma(tx->dma_ch); |
| 1030 | interruptible_sleep_on_timeout(&tx->wait, VRFB_TX_TIMEOUT); |
| 1031 | |
| 1032 | if (tx->tx_status == 0) { |
| 1033 | omap_stop_dma(tx->dma_ch); |
| 1034 | return -EINVAL; |
| 1035 | } |
| 1036 | /* Store buffers physical address into an array. Addresses |
| 1037 | * from this array will be used to configure DSS */ |
| 1038 | vout->queued_buf_addr[vb->i] = (u8 *) |
| 1039 | vout->vrfb_context[vb->i].paddr[rotation]; |
| 1040 | return 0; |
| 1041 | } |
| 1042 | |
| 1043 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1044 | * Buffer queue function will be called from the videobuf layer when _QBUF |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 1045 | * ioctl is called. It is used to enqueue buffer, which is ready to be |
| 1046 | * displayed. |
| 1047 | */ |
| 1048 | static void omap_vout_buffer_queue(struct videobuf_queue *q, |
| 1049 | struct videobuf_buffer *vb) |
| 1050 | { |
| 1051 | struct omap_vout_device *vout = q->priv_data; |
| 1052 | |
| 1053 | /* Driver is also maintainig a queue. So enqueue buffer in the driver |
| 1054 | * queue */ |
| 1055 | list_add_tail(&vb->queue, &vout->dma_queue); |
| 1056 | |
| 1057 | vb->state = VIDEOBUF_QUEUED; |
| 1058 | } |
| 1059 | |
| 1060 | /* |
| 1061 | * Buffer release function is called from videobuf layer to release buffer |
| 1062 | * which are already allocated |
| 1063 | */ |
| 1064 | static void omap_vout_buffer_release(struct videobuf_queue *q, |
| 1065 | struct videobuf_buffer *vb) |
| 1066 | { |
| 1067 | struct omap_vout_device *vout = q->priv_data; |
| 1068 | |
| 1069 | vb->state = VIDEOBUF_NEEDS_INIT; |
| 1070 | |
| 1071 | if (V4L2_MEMORY_MMAP != vout->memory) |
| 1072 | return; |
| 1073 | } |
| 1074 | |
| 1075 | /* |
| 1076 | * File operations |
| 1077 | */ |
| 1078 | static void omap_vout_vm_open(struct vm_area_struct *vma) |
| 1079 | { |
| 1080 | struct omap_vout_device *vout = vma->vm_private_data; |
| 1081 | |
| 1082 | v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, |
| 1083 | "vm_open [vma=%08lx-%08lx]\n", vma->vm_start, vma->vm_end); |
| 1084 | vout->mmap_count++; |
| 1085 | } |
| 1086 | |
| 1087 | static void omap_vout_vm_close(struct vm_area_struct *vma) |
| 1088 | { |
| 1089 | struct omap_vout_device *vout = vma->vm_private_data; |
| 1090 | |
| 1091 | v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, |
| 1092 | "vm_close [vma=%08lx-%08lx]\n", vma->vm_start, vma->vm_end); |
| 1093 | vout->mmap_count--; |
| 1094 | } |
| 1095 | |
| 1096 | static struct vm_operations_struct omap_vout_vm_ops = { |
| 1097 | .open = omap_vout_vm_open, |
| 1098 | .close = omap_vout_vm_close, |
| 1099 | }; |
| 1100 | |
| 1101 | static int omap_vout_mmap(struct file *file, struct vm_area_struct *vma) |
| 1102 | { |
| 1103 | int i; |
| 1104 | void *pos; |
| 1105 | unsigned long start = vma->vm_start; |
| 1106 | unsigned long size = (vma->vm_end - vma->vm_start); |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 1107 | struct omap_vout_device *vout = file->private_data; |
| 1108 | struct videobuf_queue *q = &vout->vbq; |
| 1109 | |
| 1110 | v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, |
| 1111 | " %s pgoff=0x%lx, start=0x%lx, end=0x%lx\n", __func__, |
| 1112 | vma->vm_pgoff, vma->vm_start, vma->vm_end); |
| 1113 | |
| 1114 | /* look for the buffer to map */ |
| 1115 | for (i = 0; i < VIDEO_MAX_FRAME; i++) { |
| 1116 | if (NULL == q->bufs[i]) |
| 1117 | continue; |
| 1118 | if (V4L2_MEMORY_MMAP != q->bufs[i]->memory) |
| 1119 | continue; |
| 1120 | if (q->bufs[i]->boff == (vma->vm_pgoff << PAGE_SHIFT)) |
| 1121 | break; |
| 1122 | } |
| 1123 | |
| 1124 | if (VIDEO_MAX_FRAME == i) { |
| 1125 | v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, |
| 1126 | "offset invalid [offset=0x%lx]\n", |
| 1127 | (vma->vm_pgoff << PAGE_SHIFT)); |
| 1128 | return -EINVAL; |
| 1129 | } |
Vaibhav Hiremath | 383e4f6 | 2011-04-14 13:42:34 -0300 | [diff] [blame] | 1130 | /* Check the size of the buffer */ |
| 1131 | if (size > vout->buffer_size) { |
| 1132 | v4l2_err(&vout->vid_dev->v4l2_dev, |
| 1133 | "insufficient memory [%lu] [%u]\n", |
| 1134 | size, vout->buffer_size); |
| 1135 | return -ENOMEM; |
| 1136 | } |
| 1137 | |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 1138 | q->bufs[i]->baddr = vma->vm_start; |
| 1139 | |
| 1140 | vma->vm_flags |= VM_RESERVED; |
| 1141 | vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot); |
| 1142 | vma->vm_ops = &omap_vout_vm_ops; |
| 1143 | vma->vm_private_data = (void *) vout; |
Vaibhav Hiremath | dd880dd | 2010-05-27 08:17:08 -0300 | [diff] [blame] | 1144 | pos = (void *)vout->buf_virt_addr[i]; |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 1145 | vma->vm_pgoff = virt_to_phys((void *)pos) >> PAGE_SHIFT; |
| 1146 | while (size > 0) { |
| 1147 | unsigned long pfn; |
| 1148 | pfn = virt_to_phys((void *) pos) >> PAGE_SHIFT; |
| 1149 | if (remap_pfn_range(vma, start, pfn, PAGE_SIZE, PAGE_SHARED)) |
| 1150 | return -EAGAIN; |
| 1151 | start += PAGE_SIZE; |
| 1152 | pos += PAGE_SIZE; |
| 1153 | size -= PAGE_SIZE; |
| 1154 | } |
| 1155 | vout->mmap_count++; |
| 1156 | v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Exiting %s\n", __func__); |
| 1157 | |
| 1158 | return 0; |
| 1159 | } |
| 1160 | |
| 1161 | static int omap_vout_release(struct file *file) |
| 1162 | { |
| 1163 | unsigned int ret, i; |
| 1164 | struct videobuf_queue *q; |
| 1165 | struct omapvideo_info *ovid; |
| 1166 | struct omap_vout_device *vout = file->private_data; |
| 1167 | |
| 1168 | v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__); |
| 1169 | ovid = &vout->vid_info; |
| 1170 | |
| 1171 | if (!vout) |
| 1172 | return 0; |
| 1173 | |
| 1174 | q = &vout->vbq; |
| 1175 | /* Disable all the overlay managers connected with this interface */ |
| 1176 | for (i = 0; i < ovid->num_overlays; i++) { |
| 1177 | struct omap_overlay *ovl = ovid->overlays[i]; |
| 1178 | if (ovl->manager && ovl->manager->device) { |
| 1179 | struct omap_overlay_info info; |
| 1180 | ovl->get_overlay_info(ovl, &info); |
| 1181 | info.enabled = 0; |
| 1182 | ovl->set_overlay_info(ovl, &info); |
| 1183 | } |
| 1184 | } |
| 1185 | /* Turn off the pipeline */ |
| 1186 | ret = omapvid_apply_changes(vout); |
| 1187 | if (ret) |
| 1188 | v4l2_warn(&vout->vid_dev->v4l2_dev, |
| 1189 | "Unable to apply changes\n"); |
| 1190 | |
| 1191 | /* Free all buffers */ |
| 1192 | omap_vout_free_allbuffers(vout); |
| 1193 | videobuf_mmap_free(q); |
| 1194 | |
| 1195 | /* Even if apply changes fails we should continue |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 1196 | freeing allocated memory */ |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 1197 | if (vout->streaming) { |
| 1198 | u32 mask = 0; |
| 1199 | |
| 1200 | mask = DISPC_IRQ_VSYNC | DISPC_IRQ_EVSYNC_EVEN | |
| 1201 | DISPC_IRQ_EVSYNC_ODD; |
| 1202 | omap_dispc_unregister_isr(omap_vout_isr, vout, mask); |
| 1203 | vout->streaming = 0; |
| 1204 | |
| 1205 | videobuf_streamoff(q); |
| 1206 | videobuf_queue_cancel(q); |
| 1207 | } |
| 1208 | |
| 1209 | if (vout->mmap_count != 0) |
| 1210 | vout->mmap_count = 0; |
| 1211 | |
| 1212 | vout->opened -= 1; |
| 1213 | file->private_data = NULL; |
| 1214 | |
| 1215 | if (vout->buffer_allocated) |
| 1216 | videobuf_mmap_free(q); |
| 1217 | |
| 1218 | v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Exiting %s\n", __func__); |
| 1219 | return ret; |
| 1220 | } |
| 1221 | |
| 1222 | static int omap_vout_open(struct file *file) |
| 1223 | { |
| 1224 | struct videobuf_queue *q; |
| 1225 | struct omap_vout_device *vout = NULL; |
| 1226 | |
| 1227 | vout = video_drvdata(file); |
| 1228 | v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__); |
| 1229 | |
| 1230 | if (vout == NULL) |
| 1231 | return -ENODEV; |
| 1232 | |
| 1233 | /* for now, we only support single open */ |
| 1234 | if (vout->opened) |
| 1235 | return -EBUSY; |
| 1236 | |
| 1237 | vout->opened += 1; |
| 1238 | |
| 1239 | file->private_data = vout; |
| 1240 | vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT; |
| 1241 | |
| 1242 | q = &vout->vbq; |
| 1243 | video_vbq_ops.buf_setup = omap_vout_buffer_setup; |
| 1244 | video_vbq_ops.buf_prepare = omap_vout_buffer_prepare; |
| 1245 | video_vbq_ops.buf_release = omap_vout_buffer_release; |
| 1246 | video_vbq_ops.buf_queue = omap_vout_buffer_queue; |
| 1247 | spin_lock_init(&vout->vbq_lock); |
| 1248 | |
Vaibhav Hiremath | dd880dd | 2010-05-27 08:17:08 -0300 | [diff] [blame] | 1249 | videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev, |
| 1250 | &vout->vbq_lock, vout->type, V4L2_FIELD_NONE, |
Hans Verkuil | e3cfd44 | 2010-09-30 09:18:52 -0300 | [diff] [blame] | 1251 | sizeof(struct videobuf_buffer), vout, NULL); |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 1252 | |
| 1253 | v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Exiting %s\n", __func__); |
| 1254 | return 0; |
| 1255 | } |
| 1256 | |
| 1257 | /* |
| 1258 | * V4L2 ioctls |
| 1259 | */ |
| 1260 | static int vidioc_querycap(struct file *file, void *fh, |
| 1261 | struct v4l2_capability *cap) |
| 1262 | { |
| 1263 | struct omap_vout_device *vout = fh; |
| 1264 | |
| 1265 | strlcpy(cap->driver, VOUT_NAME, sizeof(cap->driver)); |
| 1266 | strlcpy(cap->card, vout->vfd->name, sizeof(cap->card)); |
| 1267 | cap->bus_info[0] = '\0'; |
| 1268 | cap->capabilities = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_OUTPUT; |
| 1269 | |
| 1270 | return 0; |
| 1271 | } |
| 1272 | |
| 1273 | static int vidioc_enum_fmt_vid_out(struct file *file, void *fh, |
| 1274 | struct v4l2_fmtdesc *fmt) |
| 1275 | { |
| 1276 | int index = fmt->index; |
| 1277 | enum v4l2_buf_type type = fmt->type; |
| 1278 | |
| 1279 | fmt->index = index; |
| 1280 | fmt->type = type; |
| 1281 | if (index >= NUM_OUTPUT_FORMATS) |
| 1282 | return -EINVAL; |
| 1283 | |
| 1284 | fmt->flags = omap_formats[index].flags; |
| 1285 | strlcpy(fmt->description, omap_formats[index].description, |
| 1286 | sizeof(fmt->description)); |
| 1287 | fmt->pixelformat = omap_formats[index].pixelformat; |
| 1288 | |
| 1289 | return 0; |
| 1290 | } |
| 1291 | |
| 1292 | static int vidioc_g_fmt_vid_out(struct file *file, void *fh, |
| 1293 | struct v4l2_format *f) |
| 1294 | { |
| 1295 | struct omap_vout_device *vout = fh; |
| 1296 | |
| 1297 | f->fmt.pix = vout->pix; |
| 1298 | return 0; |
| 1299 | |
| 1300 | } |
| 1301 | |
| 1302 | static int vidioc_try_fmt_vid_out(struct file *file, void *fh, |
| 1303 | struct v4l2_format *f) |
| 1304 | { |
| 1305 | struct omap_overlay *ovl; |
| 1306 | struct omapvideo_info *ovid; |
| 1307 | struct omap_video_timings *timing; |
| 1308 | struct omap_vout_device *vout = fh; |
| 1309 | |
| 1310 | ovid = &vout->vid_info; |
| 1311 | ovl = ovid->overlays[0]; |
| 1312 | |
| 1313 | if (!ovl->manager || !ovl->manager->device) |
| 1314 | return -EINVAL; |
| 1315 | /* get the display device attached to the overlay */ |
| 1316 | timing = &ovl->manager->device->panel.timings; |
| 1317 | |
| 1318 | vout->fbuf.fmt.height = timing->y_res; |
| 1319 | vout->fbuf.fmt.width = timing->x_res; |
| 1320 | |
| 1321 | omap_vout_try_format(&f->fmt.pix); |
| 1322 | return 0; |
| 1323 | } |
| 1324 | |
| 1325 | static int vidioc_s_fmt_vid_out(struct file *file, void *fh, |
| 1326 | struct v4l2_format *f) |
| 1327 | { |
| 1328 | int ret, bpp; |
| 1329 | struct omap_overlay *ovl; |
| 1330 | struct omapvideo_info *ovid; |
| 1331 | struct omap_video_timings *timing; |
| 1332 | struct omap_vout_device *vout = fh; |
| 1333 | |
| 1334 | if (vout->streaming) |
| 1335 | return -EBUSY; |
| 1336 | |
| 1337 | mutex_lock(&vout->lock); |
| 1338 | |
| 1339 | ovid = &vout->vid_info; |
| 1340 | ovl = ovid->overlays[0]; |
| 1341 | |
| 1342 | /* get the display device attached to the overlay */ |
| 1343 | if (!ovl->manager || !ovl->manager->device) { |
| 1344 | ret = -EINVAL; |
| 1345 | goto s_fmt_vid_out_exit; |
| 1346 | } |
| 1347 | timing = &ovl->manager->device->panel.timings; |
| 1348 | |
| 1349 | /* We dont support RGB24-packed mode if vrfb rotation |
| 1350 | * is enabled*/ |
archit taneja | b366888 | 2011-06-14 03:54:46 -0300 | [diff] [blame^] | 1351 | if ((is_rotation_enabled(vout)) && |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 1352 | f->fmt.pix.pixelformat == V4L2_PIX_FMT_RGB24) { |
| 1353 | ret = -EINVAL; |
| 1354 | goto s_fmt_vid_out_exit; |
| 1355 | } |
| 1356 | |
| 1357 | /* get the framebuffer parameters */ |
| 1358 | |
archit taneja | b366888 | 2011-06-14 03:54:46 -0300 | [diff] [blame^] | 1359 | if (is_rotation_90_or_270(vout)) { |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 1360 | vout->fbuf.fmt.height = timing->x_res; |
| 1361 | vout->fbuf.fmt.width = timing->y_res; |
| 1362 | } else { |
| 1363 | vout->fbuf.fmt.height = timing->y_res; |
| 1364 | vout->fbuf.fmt.width = timing->x_res; |
| 1365 | } |
| 1366 | |
| 1367 | /* change to samller size is OK */ |
| 1368 | |
| 1369 | bpp = omap_vout_try_format(&f->fmt.pix); |
| 1370 | f->fmt.pix.sizeimage = f->fmt.pix.width * f->fmt.pix.height * bpp; |
| 1371 | |
| 1372 | /* try & set the new output format */ |
| 1373 | vout->bpp = bpp; |
| 1374 | vout->pix = f->fmt.pix; |
| 1375 | vout->vrfb_bpp = 1; |
| 1376 | |
| 1377 | /* If YUYV then vrfb bpp is 2, for others its 1 */ |
| 1378 | if (V4L2_PIX_FMT_YUYV == vout->pix.pixelformat || |
| 1379 | V4L2_PIX_FMT_UYVY == vout->pix.pixelformat) |
| 1380 | vout->vrfb_bpp = 2; |
| 1381 | |
| 1382 | /* set default crop and win */ |
| 1383 | omap_vout_new_format(&vout->pix, &vout->fbuf, &vout->crop, &vout->win); |
| 1384 | |
| 1385 | /* Save the changes in the overlay strcuture */ |
| 1386 | ret = omapvid_init(vout, 0); |
| 1387 | if (ret) { |
| 1388 | v4l2_err(&vout->vid_dev->v4l2_dev, "failed to change mode\n"); |
| 1389 | goto s_fmt_vid_out_exit; |
| 1390 | } |
| 1391 | |
| 1392 | ret = 0; |
| 1393 | |
| 1394 | s_fmt_vid_out_exit: |
| 1395 | mutex_unlock(&vout->lock); |
| 1396 | return ret; |
| 1397 | } |
| 1398 | |
| 1399 | static int vidioc_try_fmt_vid_overlay(struct file *file, void *fh, |
| 1400 | struct v4l2_format *f) |
| 1401 | { |
| 1402 | int ret = 0; |
| 1403 | struct omap_vout_device *vout = fh; |
| 1404 | struct v4l2_window *win = &f->fmt.win; |
| 1405 | |
| 1406 | ret = omap_vout_try_window(&vout->fbuf, win); |
| 1407 | |
| 1408 | if (!ret) { |
| 1409 | if (vout->vid == OMAP_VIDEO1) |
| 1410 | win->global_alpha = 255; |
| 1411 | else |
| 1412 | win->global_alpha = f->fmt.win.global_alpha; |
| 1413 | } |
| 1414 | |
| 1415 | return ret; |
| 1416 | } |
| 1417 | |
| 1418 | static int vidioc_s_fmt_vid_overlay(struct file *file, void *fh, |
| 1419 | struct v4l2_format *f) |
| 1420 | { |
| 1421 | int ret = 0; |
| 1422 | struct omap_overlay *ovl; |
| 1423 | struct omapvideo_info *ovid; |
| 1424 | struct omap_vout_device *vout = fh; |
| 1425 | struct v4l2_window *win = &f->fmt.win; |
| 1426 | |
| 1427 | mutex_lock(&vout->lock); |
| 1428 | ovid = &vout->vid_info; |
| 1429 | ovl = ovid->overlays[0]; |
| 1430 | |
| 1431 | ret = omap_vout_new_window(&vout->crop, &vout->win, &vout->fbuf, win); |
| 1432 | if (!ret) { |
| 1433 | /* Video1 plane does not support global alpha */ |
| 1434 | if (ovl->id == OMAP_DSS_VIDEO1) |
| 1435 | vout->win.global_alpha = 255; |
| 1436 | else |
| 1437 | vout->win.global_alpha = f->fmt.win.global_alpha; |
| 1438 | |
| 1439 | vout->win.chromakey = f->fmt.win.chromakey; |
| 1440 | } |
| 1441 | mutex_unlock(&vout->lock); |
| 1442 | return ret; |
| 1443 | } |
| 1444 | |
| 1445 | static int vidioc_enum_fmt_vid_overlay(struct file *file, void *fh, |
| 1446 | struct v4l2_fmtdesc *fmt) |
| 1447 | { |
| 1448 | int index = fmt->index; |
| 1449 | enum v4l2_buf_type type = fmt->type; |
| 1450 | |
| 1451 | fmt->index = index; |
| 1452 | fmt->type = type; |
| 1453 | if (index >= NUM_OUTPUT_FORMATS) |
| 1454 | return -EINVAL; |
| 1455 | |
| 1456 | fmt->flags = omap_formats[index].flags; |
| 1457 | strlcpy(fmt->description, omap_formats[index].description, |
| 1458 | sizeof(fmt->description)); |
| 1459 | fmt->pixelformat = omap_formats[index].pixelformat; |
| 1460 | return 0; |
| 1461 | } |
| 1462 | |
| 1463 | static int vidioc_g_fmt_vid_overlay(struct file *file, void *fh, |
| 1464 | struct v4l2_format *f) |
| 1465 | { |
| 1466 | u32 key_value = 0; |
| 1467 | struct omap_overlay *ovl; |
| 1468 | struct omapvideo_info *ovid; |
| 1469 | struct omap_vout_device *vout = fh; |
| 1470 | struct omap_overlay_manager_info info; |
| 1471 | struct v4l2_window *win = &f->fmt.win; |
| 1472 | |
| 1473 | ovid = &vout->vid_info; |
| 1474 | ovl = ovid->overlays[0]; |
| 1475 | |
| 1476 | win->w = vout->win.w; |
| 1477 | win->field = vout->win.field; |
| 1478 | win->global_alpha = vout->win.global_alpha; |
| 1479 | |
| 1480 | if (ovl->manager && ovl->manager->get_manager_info) { |
| 1481 | ovl->manager->get_manager_info(ovl->manager, &info); |
| 1482 | key_value = info.trans_key; |
| 1483 | } |
| 1484 | win->chromakey = key_value; |
| 1485 | return 0; |
| 1486 | } |
| 1487 | |
| 1488 | static int vidioc_cropcap(struct file *file, void *fh, |
| 1489 | struct v4l2_cropcap *cropcap) |
| 1490 | { |
| 1491 | struct omap_vout_device *vout = fh; |
| 1492 | struct v4l2_pix_format *pix = &vout->pix; |
| 1493 | |
| 1494 | if (cropcap->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) |
| 1495 | return -EINVAL; |
| 1496 | |
| 1497 | /* Width and height are always even */ |
| 1498 | cropcap->bounds.width = pix->width & ~1; |
| 1499 | cropcap->bounds.height = pix->height & ~1; |
| 1500 | |
| 1501 | omap_vout_default_crop(&vout->pix, &vout->fbuf, &cropcap->defrect); |
| 1502 | cropcap->pixelaspect.numerator = 1; |
| 1503 | cropcap->pixelaspect.denominator = 1; |
| 1504 | return 0; |
| 1505 | } |
| 1506 | |
| 1507 | static int vidioc_g_crop(struct file *file, void *fh, struct v4l2_crop *crop) |
| 1508 | { |
| 1509 | struct omap_vout_device *vout = fh; |
| 1510 | |
| 1511 | if (crop->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) |
| 1512 | return -EINVAL; |
| 1513 | crop->c = vout->crop; |
| 1514 | return 0; |
| 1515 | } |
| 1516 | |
| 1517 | static int vidioc_s_crop(struct file *file, void *fh, struct v4l2_crop *crop) |
| 1518 | { |
| 1519 | int ret = -EINVAL; |
| 1520 | struct omap_vout_device *vout = fh; |
| 1521 | struct omapvideo_info *ovid; |
| 1522 | struct omap_overlay *ovl; |
| 1523 | struct omap_video_timings *timing; |
| 1524 | |
| 1525 | if (vout->streaming) |
| 1526 | return -EBUSY; |
| 1527 | |
| 1528 | mutex_lock(&vout->lock); |
| 1529 | ovid = &vout->vid_info; |
| 1530 | ovl = ovid->overlays[0]; |
| 1531 | |
| 1532 | if (!ovl->manager || !ovl->manager->device) { |
| 1533 | ret = -EINVAL; |
| 1534 | goto s_crop_err; |
| 1535 | } |
| 1536 | /* get the display device attached to the overlay */ |
| 1537 | timing = &ovl->manager->device->panel.timings; |
| 1538 | |
archit taneja | b366888 | 2011-06-14 03:54:46 -0300 | [diff] [blame^] | 1539 | if (is_rotation_90_or_270(vout)) { |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 1540 | vout->fbuf.fmt.height = timing->x_res; |
| 1541 | vout->fbuf.fmt.width = timing->y_res; |
| 1542 | } else { |
| 1543 | vout->fbuf.fmt.height = timing->y_res; |
| 1544 | vout->fbuf.fmt.width = timing->x_res; |
| 1545 | } |
| 1546 | |
| 1547 | if (crop->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) |
| 1548 | ret = omap_vout_new_crop(&vout->pix, &vout->crop, &vout->win, |
| 1549 | &vout->fbuf, &crop->c); |
| 1550 | |
| 1551 | s_crop_err: |
| 1552 | mutex_unlock(&vout->lock); |
| 1553 | return ret; |
| 1554 | } |
| 1555 | |
| 1556 | static int vidioc_queryctrl(struct file *file, void *fh, |
| 1557 | struct v4l2_queryctrl *ctrl) |
| 1558 | { |
| 1559 | int ret = 0; |
| 1560 | |
| 1561 | switch (ctrl->id) { |
| 1562 | case V4L2_CID_ROTATE: |
| 1563 | ret = v4l2_ctrl_query_fill(ctrl, 0, 270, 90, 0); |
| 1564 | break; |
| 1565 | case V4L2_CID_BG_COLOR: |
| 1566 | ret = v4l2_ctrl_query_fill(ctrl, 0, 0xFFFFFF, 1, 0); |
| 1567 | break; |
| 1568 | case V4L2_CID_VFLIP: |
| 1569 | ret = v4l2_ctrl_query_fill(ctrl, 0, 1, 1, 0); |
| 1570 | break; |
| 1571 | default: |
| 1572 | ctrl->name[0] = '\0'; |
| 1573 | ret = -EINVAL; |
| 1574 | } |
| 1575 | return ret; |
| 1576 | } |
| 1577 | |
| 1578 | static int vidioc_g_ctrl(struct file *file, void *fh, struct v4l2_control *ctrl) |
| 1579 | { |
| 1580 | int ret = 0; |
| 1581 | struct omap_vout_device *vout = fh; |
| 1582 | |
| 1583 | switch (ctrl->id) { |
| 1584 | case V4L2_CID_ROTATE: |
| 1585 | ctrl->value = vout->control[0].value; |
| 1586 | break; |
| 1587 | case V4L2_CID_BG_COLOR: |
| 1588 | { |
| 1589 | struct omap_overlay_manager_info info; |
| 1590 | struct omap_overlay *ovl; |
| 1591 | |
| 1592 | ovl = vout->vid_info.overlays[0]; |
| 1593 | if (!ovl->manager || !ovl->manager->get_manager_info) { |
| 1594 | ret = -EINVAL; |
| 1595 | break; |
| 1596 | } |
| 1597 | |
| 1598 | ovl->manager->get_manager_info(ovl->manager, &info); |
| 1599 | ctrl->value = info.default_color; |
| 1600 | break; |
| 1601 | } |
| 1602 | case V4L2_CID_VFLIP: |
| 1603 | ctrl->value = vout->control[2].value; |
| 1604 | break; |
| 1605 | default: |
| 1606 | ret = -EINVAL; |
| 1607 | } |
| 1608 | return ret; |
| 1609 | } |
| 1610 | |
| 1611 | static int vidioc_s_ctrl(struct file *file, void *fh, struct v4l2_control *a) |
| 1612 | { |
| 1613 | int ret = 0; |
| 1614 | struct omap_vout_device *vout = fh; |
| 1615 | |
| 1616 | switch (a->id) { |
| 1617 | case V4L2_CID_ROTATE: |
| 1618 | { |
| 1619 | int rotation = a->value; |
| 1620 | |
| 1621 | mutex_lock(&vout->lock); |
| 1622 | |
| 1623 | if (rotation && vout->pix.pixelformat == V4L2_PIX_FMT_RGB24) { |
| 1624 | mutex_unlock(&vout->lock); |
| 1625 | ret = -EINVAL; |
| 1626 | break; |
| 1627 | } |
| 1628 | |
| 1629 | if (v4l2_rot_to_dss_rot(rotation, &vout->rotation, |
| 1630 | vout->mirror)) { |
| 1631 | mutex_unlock(&vout->lock); |
| 1632 | ret = -EINVAL; |
| 1633 | break; |
| 1634 | } |
| 1635 | |
| 1636 | vout->control[0].value = rotation; |
| 1637 | mutex_unlock(&vout->lock); |
| 1638 | break; |
| 1639 | } |
| 1640 | case V4L2_CID_BG_COLOR: |
| 1641 | { |
| 1642 | struct omap_overlay *ovl; |
| 1643 | unsigned int color = a->value; |
| 1644 | struct omap_overlay_manager_info info; |
| 1645 | |
| 1646 | ovl = vout->vid_info.overlays[0]; |
| 1647 | |
| 1648 | mutex_lock(&vout->lock); |
| 1649 | if (!ovl->manager || !ovl->manager->get_manager_info) { |
| 1650 | mutex_unlock(&vout->lock); |
| 1651 | ret = -EINVAL; |
| 1652 | break; |
| 1653 | } |
| 1654 | |
| 1655 | ovl->manager->get_manager_info(ovl->manager, &info); |
| 1656 | info.default_color = color; |
| 1657 | if (ovl->manager->set_manager_info(ovl->manager, &info)) { |
| 1658 | mutex_unlock(&vout->lock); |
| 1659 | ret = -EINVAL; |
| 1660 | break; |
| 1661 | } |
| 1662 | |
| 1663 | vout->control[1].value = color; |
| 1664 | mutex_unlock(&vout->lock); |
| 1665 | break; |
| 1666 | } |
| 1667 | case V4L2_CID_VFLIP: |
| 1668 | { |
| 1669 | struct omap_overlay *ovl; |
| 1670 | struct omapvideo_info *ovid; |
| 1671 | unsigned int mirror = a->value; |
| 1672 | |
| 1673 | ovid = &vout->vid_info; |
| 1674 | ovl = ovid->overlays[0]; |
| 1675 | |
| 1676 | mutex_lock(&vout->lock); |
| 1677 | |
| 1678 | if (mirror && vout->pix.pixelformat == V4L2_PIX_FMT_RGB24) { |
| 1679 | mutex_unlock(&vout->lock); |
| 1680 | ret = -EINVAL; |
| 1681 | break; |
| 1682 | } |
| 1683 | vout->mirror = mirror; |
| 1684 | vout->control[2].value = mirror; |
| 1685 | mutex_unlock(&vout->lock); |
| 1686 | break; |
| 1687 | } |
| 1688 | default: |
| 1689 | ret = -EINVAL; |
| 1690 | } |
| 1691 | return ret; |
| 1692 | } |
| 1693 | |
| 1694 | static int vidioc_reqbufs(struct file *file, void *fh, |
| 1695 | struct v4l2_requestbuffers *req) |
| 1696 | { |
| 1697 | int ret = 0; |
| 1698 | unsigned int i, num_buffers = 0; |
| 1699 | struct omap_vout_device *vout = fh; |
| 1700 | struct videobuf_queue *q = &vout->vbq; |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 1701 | |
| 1702 | if ((req->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) || (req->count < 0)) |
| 1703 | return -EINVAL; |
| 1704 | /* if memory is not mmp or userptr |
| 1705 | return error */ |
| 1706 | if ((V4L2_MEMORY_MMAP != req->memory) && |
| 1707 | (V4L2_MEMORY_USERPTR != req->memory)) |
| 1708 | return -EINVAL; |
| 1709 | |
| 1710 | mutex_lock(&vout->lock); |
| 1711 | /* Cannot be requested when streaming is on */ |
| 1712 | if (vout->streaming) { |
| 1713 | ret = -EBUSY; |
| 1714 | goto reqbuf_err; |
| 1715 | } |
| 1716 | |
| 1717 | /* If buffers are already allocated free them */ |
| 1718 | if (q->bufs[0] && (V4L2_MEMORY_MMAP == q->bufs[0]->memory)) { |
| 1719 | if (vout->mmap_count) { |
| 1720 | ret = -EBUSY; |
| 1721 | goto reqbuf_err; |
| 1722 | } |
| 1723 | num_buffers = (vout->vid == OMAP_VIDEO1) ? |
| 1724 | video1_numbuffers : video2_numbuffers; |
| 1725 | for (i = num_buffers; i < vout->buffer_allocated; i++) { |
Vaibhav Hiremath | dd880dd | 2010-05-27 08:17:08 -0300 | [diff] [blame] | 1726 | omap_vout_free_buffer(vout->buf_virt_addr[i], |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 1727 | vout->buffer_size); |
| 1728 | vout->buf_virt_addr[i] = 0; |
| 1729 | vout->buf_phy_addr[i] = 0; |
| 1730 | } |
| 1731 | vout->buffer_allocated = num_buffers; |
| 1732 | videobuf_mmap_free(q); |
| 1733 | } else if (q->bufs[0] && (V4L2_MEMORY_USERPTR == q->bufs[0]->memory)) { |
| 1734 | if (vout->buffer_allocated) { |
| 1735 | videobuf_mmap_free(q); |
| 1736 | for (i = 0; i < vout->buffer_allocated; i++) { |
| 1737 | kfree(q->bufs[i]); |
| 1738 | q->bufs[i] = NULL; |
| 1739 | } |
| 1740 | vout->buffer_allocated = 0; |
| 1741 | } |
| 1742 | } |
| 1743 | |
| 1744 | /*store the memory type in data structure */ |
| 1745 | vout->memory = req->memory; |
| 1746 | |
| 1747 | INIT_LIST_HEAD(&vout->dma_queue); |
| 1748 | |
| 1749 | /* call videobuf_reqbufs api */ |
| 1750 | ret = videobuf_reqbufs(q, req); |
| 1751 | if (ret < 0) |
| 1752 | goto reqbuf_err; |
| 1753 | |
| 1754 | vout->buffer_allocated = req->count; |
Vaibhav Hiremath | dd880dd | 2010-05-27 08:17:08 -0300 | [diff] [blame] | 1755 | |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 1756 | reqbuf_err: |
| 1757 | mutex_unlock(&vout->lock); |
| 1758 | return ret; |
| 1759 | } |
| 1760 | |
| 1761 | static int vidioc_querybuf(struct file *file, void *fh, |
| 1762 | struct v4l2_buffer *b) |
| 1763 | { |
| 1764 | struct omap_vout_device *vout = fh; |
| 1765 | |
| 1766 | return videobuf_querybuf(&vout->vbq, b); |
| 1767 | } |
| 1768 | |
| 1769 | static int vidioc_qbuf(struct file *file, void *fh, |
| 1770 | struct v4l2_buffer *buffer) |
| 1771 | { |
| 1772 | struct omap_vout_device *vout = fh; |
| 1773 | struct videobuf_queue *q = &vout->vbq; |
| 1774 | |
| 1775 | if ((V4L2_BUF_TYPE_VIDEO_OUTPUT != buffer->type) || |
| 1776 | (buffer->index >= vout->buffer_allocated) || |
| 1777 | (q->bufs[buffer->index]->memory != buffer->memory)) { |
| 1778 | return -EINVAL; |
| 1779 | } |
| 1780 | if (V4L2_MEMORY_USERPTR == buffer->memory) { |
| 1781 | if ((buffer->length < vout->pix.sizeimage) || |
| 1782 | (0 == buffer->m.userptr)) { |
| 1783 | return -EINVAL; |
| 1784 | } |
| 1785 | } |
| 1786 | |
archit taneja | b366888 | 2011-06-14 03:54:46 -0300 | [diff] [blame^] | 1787 | if ((is_rotation_enabled(vout)) && |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 1788 | vout->vrfb_dma_tx.req_status == DMA_CHAN_NOT_ALLOTED) { |
| 1789 | v4l2_warn(&vout->vid_dev->v4l2_dev, |
| 1790 | "DMA Channel not allocated for Rotation\n"); |
| 1791 | return -EINVAL; |
| 1792 | } |
| 1793 | |
| 1794 | return videobuf_qbuf(q, buffer); |
| 1795 | } |
| 1796 | |
| 1797 | static int vidioc_dqbuf(struct file *file, void *fh, struct v4l2_buffer *b) |
| 1798 | { |
| 1799 | struct omap_vout_device *vout = fh; |
| 1800 | struct videobuf_queue *q = &vout->vbq; |
| 1801 | |
| 1802 | if (!vout->streaming) |
| 1803 | return -EINVAL; |
| 1804 | |
| 1805 | if (file->f_flags & O_NONBLOCK) |
| 1806 | /* Call videobuf_dqbuf for non blocking mode */ |
| 1807 | return videobuf_dqbuf(q, (struct v4l2_buffer *)b, 1); |
| 1808 | else |
| 1809 | /* Call videobuf_dqbuf for blocking mode */ |
| 1810 | return videobuf_dqbuf(q, (struct v4l2_buffer *)b, 0); |
| 1811 | } |
| 1812 | |
| 1813 | static int vidioc_streamon(struct file *file, void *fh, enum v4l2_buf_type i) |
| 1814 | { |
| 1815 | int ret = 0, j; |
| 1816 | u32 addr = 0, mask = 0; |
| 1817 | struct omap_vout_device *vout = fh; |
| 1818 | struct videobuf_queue *q = &vout->vbq; |
| 1819 | struct omapvideo_info *ovid = &vout->vid_info; |
| 1820 | |
| 1821 | mutex_lock(&vout->lock); |
| 1822 | |
| 1823 | if (vout->streaming) { |
| 1824 | ret = -EBUSY; |
| 1825 | goto streamon_err; |
| 1826 | } |
| 1827 | |
| 1828 | ret = videobuf_streamon(q); |
| 1829 | if (ret) |
| 1830 | goto streamon_err; |
| 1831 | |
| 1832 | if (list_empty(&vout->dma_queue)) { |
| 1833 | ret = -EIO; |
| 1834 | goto streamon_err1; |
| 1835 | } |
| 1836 | |
| 1837 | /* Get the next frame from the buffer queue */ |
| 1838 | vout->next_frm = vout->cur_frm = list_entry(vout->dma_queue.next, |
| 1839 | struct videobuf_buffer, queue); |
| 1840 | /* Remove buffer from the buffer queue */ |
| 1841 | list_del(&vout->cur_frm->queue); |
| 1842 | /* Mark state of the current frame to active */ |
| 1843 | vout->cur_frm->state = VIDEOBUF_ACTIVE; |
| 1844 | /* Initialize field_id and started member */ |
| 1845 | vout->field_id = 0; |
| 1846 | |
| 1847 | /* set flag here. Next QBUF will start DMA */ |
| 1848 | vout->streaming = 1; |
| 1849 | |
| 1850 | vout->first_int = 1; |
| 1851 | |
| 1852 | if (omap_vout_calculate_offset(vout)) { |
| 1853 | ret = -EINVAL; |
| 1854 | goto streamon_err1; |
| 1855 | } |
| 1856 | addr = (unsigned long) vout->queued_buf_addr[vout->cur_frm->i] |
| 1857 | + vout->cropped_offset; |
| 1858 | |
| 1859 | mask = DISPC_IRQ_VSYNC | DISPC_IRQ_EVSYNC_EVEN | DISPC_IRQ_EVSYNC_ODD; |
| 1860 | |
| 1861 | omap_dispc_register_isr(omap_vout_isr, vout, mask); |
| 1862 | |
| 1863 | for (j = 0; j < ovid->num_overlays; j++) { |
| 1864 | struct omap_overlay *ovl = ovid->overlays[j]; |
| 1865 | |
| 1866 | if (ovl->manager && ovl->manager->device) { |
| 1867 | struct omap_overlay_info info; |
| 1868 | ovl->get_overlay_info(ovl, &info); |
| 1869 | info.enabled = 1; |
| 1870 | info.paddr = addr; |
| 1871 | if (ovl->set_overlay_info(ovl, &info)) { |
| 1872 | ret = -EINVAL; |
| 1873 | goto streamon_err1; |
| 1874 | } |
| 1875 | } |
| 1876 | } |
| 1877 | |
| 1878 | /* First save the configuration in ovelray structure */ |
| 1879 | ret = omapvid_init(vout, addr); |
| 1880 | if (ret) |
| 1881 | v4l2_err(&vout->vid_dev->v4l2_dev, |
| 1882 | "failed to set overlay info\n"); |
| 1883 | /* Enable the pipeline and set the Go bit */ |
| 1884 | ret = omapvid_apply_changes(vout); |
| 1885 | if (ret) |
| 1886 | v4l2_err(&vout->vid_dev->v4l2_dev, "failed to change mode\n"); |
| 1887 | |
| 1888 | ret = 0; |
| 1889 | |
| 1890 | streamon_err1: |
| 1891 | if (ret) |
| 1892 | ret = videobuf_streamoff(q); |
| 1893 | streamon_err: |
| 1894 | mutex_unlock(&vout->lock); |
| 1895 | return ret; |
| 1896 | } |
| 1897 | |
| 1898 | static int vidioc_streamoff(struct file *file, void *fh, enum v4l2_buf_type i) |
| 1899 | { |
| 1900 | u32 mask = 0; |
| 1901 | int ret = 0, j; |
| 1902 | struct omap_vout_device *vout = fh; |
| 1903 | struct omapvideo_info *ovid = &vout->vid_info; |
| 1904 | |
| 1905 | if (!vout->streaming) |
| 1906 | return -EINVAL; |
| 1907 | |
| 1908 | vout->streaming = 0; |
| 1909 | mask = DISPC_IRQ_VSYNC | DISPC_IRQ_EVSYNC_EVEN | DISPC_IRQ_EVSYNC_ODD; |
| 1910 | |
| 1911 | omap_dispc_unregister_isr(omap_vout_isr, vout, mask); |
| 1912 | |
| 1913 | for (j = 0; j < ovid->num_overlays; j++) { |
| 1914 | struct omap_overlay *ovl = ovid->overlays[j]; |
| 1915 | |
| 1916 | if (ovl->manager && ovl->manager->device) { |
| 1917 | struct omap_overlay_info info; |
| 1918 | |
| 1919 | ovl->get_overlay_info(ovl, &info); |
| 1920 | info.enabled = 0; |
| 1921 | ret = ovl->set_overlay_info(ovl, &info); |
| 1922 | if (ret) |
| 1923 | v4l2_err(&vout->vid_dev->v4l2_dev, |
| 1924 | "failed to update overlay info in streamoff\n"); |
| 1925 | } |
| 1926 | } |
| 1927 | |
| 1928 | /* Turn of the pipeline */ |
| 1929 | ret = omapvid_apply_changes(vout); |
| 1930 | if (ret) |
| 1931 | v4l2_err(&vout->vid_dev->v4l2_dev, "failed to change mode in" |
| 1932 | " streamoff\n"); |
| 1933 | |
| 1934 | INIT_LIST_HEAD(&vout->dma_queue); |
| 1935 | ret = videobuf_streamoff(&vout->vbq); |
| 1936 | |
| 1937 | return ret; |
| 1938 | } |
| 1939 | |
| 1940 | static int vidioc_s_fbuf(struct file *file, void *fh, |
| 1941 | struct v4l2_framebuffer *a) |
| 1942 | { |
| 1943 | int enable = 0; |
| 1944 | struct omap_overlay *ovl; |
| 1945 | struct omapvideo_info *ovid; |
| 1946 | struct omap_vout_device *vout = fh; |
| 1947 | struct omap_overlay_manager_info info; |
| 1948 | enum omap_dss_trans_key_type key_type = OMAP_DSS_COLOR_KEY_GFX_DST; |
| 1949 | |
| 1950 | ovid = &vout->vid_info; |
| 1951 | ovl = ovid->overlays[0]; |
| 1952 | |
| 1953 | /* OMAP DSS doesn't support Source and Destination color |
| 1954 | key together */ |
| 1955 | if ((a->flags & V4L2_FBUF_FLAG_SRC_CHROMAKEY) && |
| 1956 | (a->flags & V4L2_FBUF_FLAG_CHROMAKEY)) |
| 1957 | return -EINVAL; |
| 1958 | /* OMAP DSS Doesn't support the Destination color key |
| 1959 | and alpha blending together */ |
| 1960 | if ((a->flags & V4L2_FBUF_FLAG_CHROMAKEY) && |
| 1961 | (a->flags & V4L2_FBUF_FLAG_LOCAL_ALPHA)) |
| 1962 | return -EINVAL; |
| 1963 | |
| 1964 | if ((a->flags & V4L2_FBUF_FLAG_SRC_CHROMAKEY)) { |
| 1965 | vout->fbuf.flags |= V4L2_FBUF_FLAG_SRC_CHROMAKEY; |
| 1966 | key_type = OMAP_DSS_COLOR_KEY_VID_SRC; |
| 1967 | } else |
| 1968 | vout->fbuf.flags &= ~V4L2_FBUF_FLAG_SRC_CHROMAKEY; |
| 1969 | |
| 1970 | if ((a->flags & V4L2_FBUF_FLAG_CHROMAKEY)) { |
| 1971 | vout->fbuf.flags |= V4L2_FBUF_FLAG_CHROMAKEY; |
| 1972 | key_type = OMAP_DSS_COLOR_KEY_GFX_DST; |
| 1973 | } else |
| 1974 | vout->fbuf.flags &= ~V4L2_FBUF_FLAG_CHROMAKEY; |
| 1975 | |
| 1976 | if (a->flags & (V4L2_FBUF_FLAG_CHROMAKEY | |
| 1977 | V4L2_FBUF_FLAG_SRC_CHROMAKEY)) |
| 1978 | enable = 1; |
| 1979 | else |
| 1980 | enable = 0; |
| 1981 | if (ovl->manager && ovl->manager->get_manager_info && |
| 1982 | ovl->manager->set_manager_info) { |
| 1983 | |
| 1984 | ovl->manager->get_manager_info(ovl->manager, &info); |
| 1985 | info.trans_enabled = enable; |
| 1986 | info.trans_key_type = key_type; |
| 1987 | info.trans_key = vout->win.chromakey; |
| 1988 | |
| 1989 | if (ovl->manager->set_manager_info(ovl->manager, &info)) |
| 1990 | return -EINVAL; |
| 1991 | } |
| 1992 | if (a->flags & V4L2_FBUF_FLAG_LOCAL_ALPHA) { |
| 1993 | vout->fbuf.flags |= V4L2_FBUF_FLAG_LOCAL_ALPHA; |
| 1994 | enable = 1; |
| 1995 | } else { |
| 1996 | vout->fbuf.flags &= ~V4L2_FBUF_FLAG_LOCAL_ALPHA; |
| 1997 | enable = 0; |
| 1998 | } |
| 1999 | if (ovl->manager && ovl->manager->get_manager_info && |
| 2000 | ovl->manager->set_manager_info) { |
| 2001 | ovl->manager->get_manager_info(ovl->manager, &info); |
| 2002 | info.alpha_enabled = enable; |
| 2003 | if (ovl->manager->set_manager_info(ovl->manager, &info)) |
| 2004 | return -EINVAL; |
| 2005 | } |
| 2006 | |
| 2007 | return 0; |
| 2008 | } |
| 2009 | |
| 2010 | static int vidioc_g_fbuf(struct file *file, void *fh, |
| 2011 | struct v4l2_framebuffer *a) |
| 2012 | { |
| 2013 | struct omap_overlay *ovl; |
| 2014 | struct omapvideo_info *ovid; |
| 2015 | struct omap_vout_device *vout = fh; |
| 2016 | struct omap_overlay_manager_info info; |
| 2017 | |
| 2018 | ovid = &vout->vid_info; |
| 2019 | ovl = ovid->overlays[0]; |
| 2020 | |
| 2021 | a->flags = 0x0; |
| 2022 | a->capability = V4L2_FBUF_CAP_LOCAL_ALPHA | V4L2_FBUF_CAP_CHROMAKEY |
| 2023 | | V4L2_FBUF_CAP_SRC_CHROMAKEY; |
| 2024 | |
| 2025 | if (ovl->manager && ovl->manager->get_manager_info) { |
| 2026 | ovl->manager->get_manager_info(ovl->manager, &info); |
| 2027 | if (info.trans_key_type == OMAP_DSS_COLOR_KEY_VID_SRC) |
| 2028 | a->flags |= V4L2_FBUF_FLAG_SRC_CHROMAKEY; |
| 2029 | if (info.trans_key_type == OMAP_DSS_COLOR_KEY_GFX_DST) |
| 2030 | a->flags |= V4L2_FBUF_FLAG_CHROMAKEY; |
| 2031 | } |
| 2032 | if (ovl->manager && ovl->manager->get_manager_info) { |
| 2033 | ovl->manager->get_manager_info(ovl->manager, &info); |
| 2034 | if (info.alpha_enabled) |
| 2035 | a->flags |= V4L2_FBUF_FLAG_LOCAL_ALPHA; |
| 2036 | } |
| 2037 | |
| 2038 | return 0; |
| 2039 | } |
| 2040 | |
| 2041 | static const struct v4l2_ioctl_ops vout_ioctl_ops = { |
| 2042 | .vidioc_querycap = vidioc_querycap, |
| 2043 | .vidioc_enum_fmt_vid_out = vidioc_enum_fmt_vid_out, |
| 2044 | .vidioc_g_fmt_vid_out = vidioc_g_fmt_vid_out, |
| 2045 | .vidioc_try_fmt_vid_out = vidioc_try_fmt_vid_out, |
| 2046 | .vidioc_s_fmt_vid_out = vidioc_s_fmt_vid_out, |
| 2047 | .vidioc_queryctrl = vidioc_queryctrl, |
| 2048 | .vidioc_g_ctrl = vidioc_g_ctrl, |
| 2049 | .vidioc_s_fbuf = vidioc_s_fbuf, |
| 2050 | .vidioc_g_fbuf = vidioc_g_fbuf, |
| 2051 | .vidioc_s_ctrl = vidioc_s_ctrl, |
| 2052 | .vidioc_try_fmt_vid_overlay = vidioc_try_fmt_vid_overlay, |
| 2053 | .vidioc_s_fmt_vid_overlay = vidioc_s_fmt_vid_overlay, |
| 2054 | .vidioc_enum_fmt_vid_overlay = vidioc_enum_fmt_vid_overlay, |
| 2055 | .vidioc_g_fmt_vid_overlay = vidioc_g_fmt_vid_overlay, |
| 2056 | .vidioc_cropcap = vidioc_cropcap, |
| 2057 | .vidioc_g_crop = vidioc_g_crop, |
| 2058 | .vidioc_s_crop = vidioc_s_crop, |
| 2059 | .vidioc_reqbufs = vidioc_reqbufs, |
| 2060 | .vidioc_querybuf = vidioc_querybuf, |
| 2061 | .vidioc_qbuf = vidioc_qbuf, |
| 2062 | .vidioc_dqbuf = vidioc_dqbuf, |
| 2063 | .vidioc_streamon = vidioc_streamon, |
| 2064 | .vidioc_streamoff = vidioc_streamoff, |
| 2065 | }; |
| 2066 | |
| 2067 | static const struct v4l2_file_operations omap_vout_fops = { |
| 2068 | .owner = THIS_MODULE, |
| 2069 | .unlocked_ioctl = video_ioctl2, |
| 2070 | .mmap = omap_vout_mmap, |
| 2071 | .open = omap_vout_open, |
| 2072 | .release = omap_vout_release, |
| 2073 | }; |
| 2074 | |
| 2075 | /* Init functions used during driver initialization */ |
| 2076 | /* Initial setup of video_data */ |
| 2077 | static int __init omap_vout_setup_video_data(struct omap_vout_device *vout) |
| 2078 | { |
| 2079 | struct video_device *vfd; |
| 2080 | struct v4l2_pix_format *pix; |
| 2081 | struct v4l2_control *control; |
| 2082 | struct omap_dss_device *display = |
| 2083 | vout->vid_info.overlays[0]->manager->device; |
| 2084 | |
| 2085 | /* set the default pix */ |
| 2086 | pix = &vout->pix; |
| 2087 | |
| 2088 | /* Set the default picture of QVGA */ |
| 2089 | pix->width = QQVGA_WIDTH; |
| 2090 | pix->height = QQVGA_HEIGHT; |
| 2091 | |
| 2092 | /* Default pixel format is RGB 5-6-5 */ |
| 2093 | pix->pixelformat = V4L2_PIX_FMT_RGB565; |
| 2094 | pix->field = V4L2_FIELD_ANY; |
| 2095 | pix->bytesperline = pix->width * 2; |
| 2096 | pix->sizeimage = pix->bytesperline * pix->height; |
| 2097 | pix->priv = 0; |
| 2098 | pix->colorspace = V4L2_COLORSPACE_JPEG; |
| 2099 | |
| 2100 | vout->bpp = RGB565_BPP; |
| 2101 | vout->fbuf.fmt.width = display->panel.timings.x_res; |
| 2102 | vout->fbuf.fmt.height = display->panel.timings.y_res; |
| 2103 | |
| 2104 | /* Set the data structures for the overlay parameters*/ |
| 2105 | vout->win.global_alpha = 255; |
| 2106 | vout->fbuf.flags = 0; |
| 2107 | vout->fbuf.capability = V4L2_FBUF_CAP_LOCAL_ALPHA | |
| 2108 | V4L2_FBUF_CAP_SRC_CHROMAKEY | V4L2_FBUF_CAP_CHROMAKEY; |
| 2109 | vout->win.chromakey = 0; |
| 2110 | |
| 2111 | omap_vout_new_format(pix, &vout->fbuf, &vout->crop, &vout->win); |
| 2112 | |
| 2113 | /*Initialize the control variables for |
| 2114 | rotation, flipping and background color. */ |
| 2115 | control = vout->control; |
| 2116 | control[0].id = V4L2_CID_ROTATE; |
| 2117 | control[0].value = 0; |
| 2118 | vout->rotation = 0; |
| 2119 | vout->mirror = 0; |
| 2120 | vout->control[2].id = V4L2_CID_HFLIP; |
| 2121 | vout->control[2].value = 0; |
| 2122 | vout->vrfb_bpp = 2; |
| 2123 | |
| 2124 | control[1].id = V4L2_CID_BG_COLOR; |
| 2125 | control[1].value = 0; |
| 2126 | |
| 2127 | /* initialize the video_device struct */ |
| 2128 | vfd = vout->vfd = video_device_alloc(); |
| 2129 | |
| 2130 | if (!vfd) { |
| 2131 | printk(KERN_ERR VOUT_NAME ": could not allocate" |
| 2132 | " video device struct\n"); |
| 2133 | return -ENOMEM; |
| 2134 | } |
| 2135 | vfd->release = video_device_release; |
| 2136 | vfd->ioctl_ops = &vout_ioctl_ops; |
| 2137 | |
| 2138 | strlcpy(vfd->name, VOUT_NAME, sizeof(vfd->name)); |
| 2139 | |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 2140 | vfd->fops = &omap_vout_fops; |
| 2141 | vfd->v4l2_dev = &vout->vid_dev->v4l2_dev; |
| 2142 | mutex_init(&vout->lock); |
| 2143 | |
| 2144 | vfd->minor = -1; |
| 2145 | return 0; |
| 2146 | |
| 2147 | } |
| 2148 | |
| 2149 | /* Setup video buffers */ |
| 2150 | static int __init omap_vout_setup_video_bufs(struct platform_device *pdev, |
| 2151 | int vid_num) |
| 2152 | { |
| 2153 | u32 numbuffers; |
| 2154 | int ret = 0, i, j; |
| 2155 | int image_width, image_height; |
| 2156 | struct video_device *vfd; |
| 2157 | struct omap_vout_device *vout; |
| 2158 | int static_vrfb_allocation = 0, vrfb_num_bufs = VRFB_NUM_BUFS; |
| 2159 | struct v4l2_device *v4l2_dev = platform_get_drvdata(pdev); |
| 2160 | struct omap2video_device *vid_dev = |
| 2161 | container_of(v4l2_dev, struct omap2video_device, v4l2_dev); |
| 2162 | |
| 2163 | vout = vid_dev->vouts[vid_num]; |
| 2164 | vfd = vout->vfd; |
| 2165 | |
| 2166 | numbuffers = (vid_num == 0) ? video1_numbuffers : video2_numbuffers; |
| 2167 | vout->buffer_size = (vid_num == 0) ? video1_bufsize : video2_bufsize; |
| 2168 | dev_info(&pdev->dev, "Buffer Size = %d\n", vout->buffer_size); |
| 2169 | |
| 2170 | for (i = 0; i < numbuffers; i++) { |
| 2171 | vout->buf_virt_addr[i] = |
| 2172 | omap_vout_alloc_buffer(vout->buffer_size, |
| 2173 | (u32 *) &vout->buf_phy_addr[i]); |
| 2174 | if (!vout->buf_virt_addr[i]) { |
| 2175 | numbuffers = i; |
| 2176 | ret = -ENOMEM; |
| 2177 | goto free_buffers; |
| 2178 | } |
| 2179 | } |
| 2180 | |
| 2181 | for (i = 0; i < VRFB_NUM_BUFS; i++) { |
| 2182 | if (omap_vrfb_request_ctx(&vout->vrfb_context[i])) { |
| 2183 | dev_info(&pdev->dev, ": VRFB allocation failed\n"); |
| 2184 | for (j = 0; j < i; j++) |
| 2185 | omap_vrfb_release_ctx(&vout->vrfb_context[j]); |
| 2186 | ret = -ENOMEM; |
| 2187 | goto free_buffers; |
| 2188 | } |
| 2189 | } |
| 2190 | vout->cropped_offset = 0; |
| 2191 | |
| 2192 | /* Calculate VRFB memory size */ |
| 2193 | /* allocate for worst case size */ |
| 2194 | image_width = VID_MAX_WIDTH / TILE_SIZE; |
| 2195 | if (VID_MAX_WIDTH % TILE_SIZE) |
| 2196 | image_width++; |
| 2197 | |
| 2198 | image_width = image_width * TILE_SIZE; |
| 2199 | image_height = VID_MAX_HEIGHT / TILE_SIZE; |
| 2200 | |
| 2201 | if (VID_MAX_HEIGHT % TILE_SIZE) |
| 2202 | image_height++; |
| 2203 | |
| 2204 | image_height = image_height * TILE_SIZE; |
| 2205 | vout->smsshado_size = PAGE_ALIGN(image_width * image_height * 2 * 2); |
| 2206 | |
| 2207 | /* |
| 2208 | * Request and Initialize DMA, for DMA based VRFB transfer |
| 2209 | */ |
| 2210 | vout->vrfb_dma_tx.dev_id = OMAP_DMA_NO_DEVICE; |
| 2211 | vout->vrfb_dma_tx.dma_ch = -1; |
| 2212 | vout->vrfb_dma_tx.req_status = DMA_CHAN_ALLOTED; |
| 2213 | ret = omap_request_dma(vout->vrfb_dma_tx.dev_id, "VRFB DMA TX", |
| 2214 | omap_vout_vrfb_dma_tx_callback, |
| 2215 | (void *) &vout->vrfb_dma_tx, &vout->vrfb_dma_tx.dma_ch); |
| 2216 | if (ret < 0) { |
| 2217 | vout->vrfb_dma_tx.req_status = DMA_CHAN_NOT_ALLOTED; |
| 2218 | dev_info(&pdev->dev, ": failed to allocate DMA Channel for" |
| 2219 | " video%d\n", vfd->minor); |
| 2220 | } |
| 2221 | init_waitqueue_head(&vout->vrfb_dma_tx.wait); |
| 2222 | |
| 2223 | /* Allocate VRFB buffers if selected through bootargs */ |
| 2224 | static_vrfb_allocation = (vid_num == 0) ? |
| 2225 | vid1_static_vrfb_alloc : vid2_static_vrfb_alloc; |
| 2226 | |
| 2227 | /* statically allocated the VRFB buffer is done through |
| 2228 | commands line aruments */ |
| 2229 | if (static_vrfb_allocation) { |
| 2230 | if (omap_vout_allocate_vrfb_buffers(vout, &vrfb_num_bufs, -1)) { |
| 2231 | ret = -ENOMEM; |
| 2232 | goto release_vrfb_ctx; |
| 2233 | } |
| 2234 | vout->vrfb_static_allocation = 1; |
| 2235 | } |
| 2236 | return 0; |
| 2237 | |
| 2238 | release_vrfb_ctx: |
| 2239 | for (j = 0; j < VRFB_NUM_BUFS; j++) |
| 2240 | omap_vrfb_release_ctx(&vout->vrfb_context[j]); |
| 2241 | |
| 2242 | free_buffers: |
| 2243 | for (i = 0; i < numbuffers; i++) { |
| 2244 | omap_vout_free_buffer(vout->buf_virt_addr[i], |
| 2245 | vout->buffer_size); |
| 2246 | vout->buf_virt_addr[i] = 0; |
| 2247 | vout->buf_phy_addr[i] = 0; |
| 2248 | } |
| 2249 | return ret; |
| 2250 | |
| 2251 | } |
| 2252 | |
| 2253 | /* Create video out devices */ |
| 2254 | static int __init omap_vout_create_video_devices(struct platform_device *pdev) |
| 2255 | { |
| 2256 | int ret = 0, k; |
| 2257 | struct omap_vout_device *vout; |
| 2258 | struct video_device *vfd = NULL; |
| 2259 | struct v4l2_device *v4l2_dev = platform_get_drvdata(pdev); |
| 2260 | struct omap2video_device *vid_dev = container_of(v4l2_dev, |
| 2261 | struct omap2video_device, v4l2_dev); |
| 2262 | |
| 2263 | for (k = 0; k < pdev->num_resources; k++) { |
| 2264 | |
Julia Lawall | 2ef17c9 | 2010-05-13 16:59:15 -0300 | [diff] [blame] | 2265 | vout = kzalloc(sizeof(struct omap_vout_device), GFP_KERNEL); |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 2266 | if (!vout) { |
| 2267 | dev_err(&pdev->dev, ": could not allocate memory\n"); |
| 2268 | return -ENOMEM; |
| 2269 | } |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 2270 | |
| 2271 | vout->vid = k; |
| 2272 | vid_dev->vouts[k] = vout; |
| 2273 | vout->vid_dev = vid_dev; |
| 2274 | /* Select video2 if only 1 overlay is controlled by V4L2 */ |
| 2275 | if (pdev->num_resources == 1) |
| 2276 | vout->vid_info.overlays[0] = vid_dev->overlays[k + 2]; |
| 2277 | else |
| 2278 | /* Else select video1 and video2 one by one. */ |
| 2279 | vout->vid_info.overlays[0] = vid_dev->overlays[k + 1]; |
| 2280 | vout->vid_info.num_overlays = 1; |
| 2281 | vout->vid_info.id = k + 1; |
| 2282 | |
| 2283 | /* Setup the default configuration for the video devices |
| 2284 | */ |
| 2285 | if (omap_vout_setup_video_data(vout) != 0) { |
| 2286 | ret = -ENOMEM; |
| 2287 | goto error; |
| 2288 | } |
| 2289 | |
| 2290 | /* Allocate default number of buffers for the video streaming |
| 2291 | * and reserve the VRFB space for rotation |
| 2292 | */ |
| 2293 | if (omap_vout_setup_video_bufs(pdev, k) != 0) { |
| 2294 | ret = -ENOMEM; |
| 2295 | goto error1; |
| 2296 | } |
| 2297 | |
| 2298 | /* Register the Video device with V4L2 |
| 2299 | */ |
| 2300 | vfd = vout->vfd; |
Vaibhav Hiremath | 8f3a307 | 2011-06-16 15:32:07 -0300 | [diff] [blame] | 2301 | if (video_register_device(vfd, VFL_TYPE_GRABBER, -1) < 0) { |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 2302 | dev_err(&pdev->dev, ": Could not register " |
| 2303 | "Video for Linux device\n"); |
| 2304 | vfd->minor = -1; |
| 2305 | ret = -ENODEV; |
| 2306 | goto error2; |
| 2307 | } |
| 2308 | video_set_drvdata(vfd, vout); |
| 2309 | |
| 2310 | /* Configure the overlay structure */ |
| 2311 | ret = omapvid_init(vid_dev->vouts[k], 0); |
| 2312 | if (!ret) |
| 2313 | goto success; |
| 2314 | |
| 2315 | error2: |
| 2316 | omap_vout_release_vrfb(vout); |
| 2317 | omap_vout_free_buffers(vout); |
| 2318 | error1: |
| 2319 | video_device_release(vfd); |
| 2320 | error: |
| 2321 | kfree(vout); |
| 2322 | return ret; |
| 2323 | |
| 2324 | success: |
| 2325 | dev_info(&pdev->dev, ": registered and initialized" |
| 2326 | " video device %d\n", vfd->minor); |
| 2327 | if (k == (pdev->num_resources - 1)) |
| 2328 | return 0; |
| 2329 | } |
| 2330 | |
| 2331 | return -ENODEV; |
| 2332 | } |
| 2333 | /* Driver functions */ |
| 2334 | static void omap_vout_cleanup_device(struct omap_vout_device *vout) |
| 2335 | { |
| 2336 | struct video_device *vfd; |
| 2337 | |
| 2338 | if (!vout) |
| 2339 | return; |
| 2340 | |
| 2341 | vfd = vout->vfd; |
| 2342 | if (vfd) { |
| 2343 | if (!video_is_registered(vfd)) { |
| 2344 | /* |
| 2345 | * The device was never registered, so release the |
| 2346 | * video_device struct directly. |
| 2347 | */ |
| 2348 | video_device_release(vfd); |
| 2349 | } else { |
| 2350 | /* |
| 2351 | * The unregister function will release the video_device |
| 2352 | * struct as well as unregistering it. |
| 2353 | */ |
| 2354 | video_unregister_device(vfd); |
| 2355 | } |
| 2356 | } |
| 2357 | |
| 2358 | omap_vout_release_vrfb(vout); |
| 2359 | omap_vout_free_buffers(vout); |
| 2360 | /* Free the VRFB buffer if allocated |
| 2361 | * init time |
| 2362 | */ |
| 2363 | if (vout->vrfb_static_allocation) |
| 2364 | omap_vout_free_vrfb_buffers(vout); |
| 2365 | |
| 2366 | kfree(vout); |
| 2367 | } |
| 2368 | |
| 2369 | static int omap_vout_remove(struct platform_device *pdev) |
| 2370 | { |
| 2371 | int k; |
| 2372 | struct v4l2_device *v4l2_dev = platform_get_drvdata(pdev); |
| 2373 | struct omap2video_device *vid_dev = container_of(v4l2_dev, struct |
| 2374 | omap2video_device, v4l2_dev); |
| 2375 | |
| 2376 | v4l2_device_unregister(v4l2_dev); |
| 2377 | for (k = 0; k < pdev->num_resources; k++) |
| 2378 | omap_vout_cleanup_device(vid_dev->vouts[k]); |
| 2379 | |
| 2380 | for (k = 0; k < vid_dev->num_displays; k++) { |
| 2381 | if (vid_dev->displays[k]->state != OMAP_DSS_DISPLAY_DISABLED) |
Vaibhav Hiremath | 5ba9bb0 | 2010-05-27 08:17:07 -0300 | [diff] [blame] | 2382 | vid_dev->displays[k]->driver->disable(vid_dev->displays[k]); |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 2383 | |
| 2384 | omap_dss_put_device(vid_dev->displays[k]); |
| 2385 | } |
| 2386 | kfree(vid_dev); |
| 2387 | return 0; |
| 2388 | } |
| 2389 | |
| 2390 | static int __init omap_vout_probe(struct platform_device *pdev) |
| 2391 | { |
| 2392 | int ret = 0, i; |
| 2393 | struct omap_overlay *ovl; |
| 2394 | struct omap_dss_device *dssdev = NULL; |
| 2395 | struct omap_dss_device *def_display; |
| 2396 | struct omap2video_device *vid_dev = NULL; |
| 2397 | |
| 2398 | if (pdev->num_resources == 0) { |
| 2399 | dev_err(&pdev->dev, "probed for an unknown device\n"); |
| 2400 | return -ENODEV; |
| 2401 | } |
| 2402 | |
| 2403 | vid_dev = kzalloc(sizeof(struct omap2video_device), GFP_KERNEL); |
| 2404 | if (vid_dev == NULL) |
| 2405 | return -ENOMEM; |
| 2406 | |
| 2407 | vid_dev->num_displays = 0; |
| 2408 | for_each_dss_dev(dssdev) { |
| 2409 | omap_dss_get_device(dssdev); |
| 2410 | vid_dev->displays[vid_dev->num_displays++] = dssdev; |
| 2411 | } |
| 2412 | |
| 2413 | if (vid_dev->num_displays == 0) { |
| 2414 | dev_err(&pdev->dev, "no displays\n"); |
| 2415 | ret = -EINVAL; |
| 2416 | goto probe_err0; |
| 2417 | } |
| 2418 | |
| 2419 | vid_dev->num_overlays = omap_dss_get_num_overlays(); |
| 2420 | for (i = 0; i < vid_dev->num_overlays; i++) |
| 2421 | vid_dev->overlays[i] = omap_dss_get_overlay(i); |
| 2422 | |
| 2423 | vid_dev->num_managers = omap_dss_get_num_overlay_managers(); |
| 2424 | for (i = 0; i < vid_dev->num_managers; i++) |
| 2425 | vid_dev->managers[i] = omap_dss_get_overlay_manager(i); |
| 2426 | |
| 2427 | /* Get the Video1 overlay and video2 overlay. |
| 2428 | * Setup the Display attached to that overlays |
| 2429 | */ |
| 2430 | for (i = 1; i < vid_dev->num_overlays; i++) { |
| 2431 | ovl = omap_dss_get_overlay(i); |
| 2432 | if (ovl->manager && ovl->manager->device) { |
| 2433 | def_display = ovl->manager->device; |
| 2434 | } else { |
| 2435 | dev_warn(&pdev->dev, "cannot find display\n"); |
| 2436 | def_display = NULL; |
| 2437 | } |
| 2438 | if (def_display) { |
Vaibhav Hiremath | 5ba9bb0 | 2010-05-27 08:17:07 -0300 | [diff] [blame] | 2439 | struct omap_dss_driver *dssdrv = def_display->driver; |
| 2440 | |
| 2441 | ret = dssdrv->enable(def_display); |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 2442 | if (ret) { |
| 2443 | /* Here we are not considering a error |
| 2444 | * as display may be enabled by frame |
| 2445 | * buffer driver |
| 2446 | */ |
| 2447 | dev_warn(&pdev->dev, |
| 2448 | "'%s' Display already enabled\n", |
| 2449 | def_display->name); |
| 2450 | } |
| 2451 | /* set the update mode */ |
| 2452 | if (def_display->caps & |
| 2453 | OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE) { |
Vaibhav Hiremath | 5ba9bb0 | 2010-05-27 08:17:07 -0300 | [diff] [blame] | 2454 | if (dssdrv->enable_te) |
| 2455 | dssdrv->enable_te(def_display, 0); |
| 2456 | if (dssdrv->set_update_mode) |
| 2457 | dssdrv->set_update_mode(def_display, |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 2458 | OMAP_DSS_UPDATE_MANUAL); |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 2459 | } else { |
Vaibhav Hiremath | 5ba9bb0 | 2010-05-27 08:17:07 -0300 | [diff] [blame] | 2460 | if (dssdrv->set_update_mode) |
| 2461 | dssdrv->set_update_mode(def_display, |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 2462 | OMAP_DSS_UPDATE_AUTO); |
| 2463 | } |
| 2464 | } |
| 2465 | } |
| 2466 | |
| 2467 | if (v4l2_device_register(&pdev->dev, &vid_dev->v4l2_dev) < 0) { |
| 2468 | dev_err(&pdev->dev, "v4l2_device_register failed\n"); |
| 2469 | ret = -ENODEV; |
| 2470 | goto probe_err1; |
| 2471 | } |
| 2472 | |
| 2473 | ret = omap_vout_create_video_devices(pdev); |
| 2474 | if (ret) |
| 2475 | goto probe_err2; |
| 2476 | |
| 2477 | for (i = 0; i < vid_dev->num_displays; i++) { |
| 2478 | struct omap_dss_device *display = vid_dev->displays[i]; |
| 2479 | |
Vaibhav Hiremath | 5ba9bb0 | 2010-05-27 08:17:07 -0300 | [diff] [blame] | 2480 | if (display->driver->update) |
| 2481 | display->driver->update(display, 0, 0, |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 2482 | display->panel.timings.x_res, |
| 2483 | display->panel.timings.y_res); |
| 2484 | } |
| 2485 | return 0; |
| 2486 | |
| 2487 | probe_err2: |
| 2488 | v4l2_device_unregister(&vid_dev->v4l2_dev); |
| 2489 | probe_err1: |
| 2490 | for (i = 1; i < vid_dev->num_overlays; i++) { |
| 2491 | def_display = NULL; |
| 2492 | ovl = omap_dss_get_overlay(i); |
| 2493 | if (ovl->manager && ovl->manager->device) |
| 2494 | def_display = ovl->manager->device; |
| 2495 | |
Vaibhav Hiremath | 5ba9bb0 | 2010-05-27 08:17:07 -0300 | [diff] [blame] | 2496 | if (def_display && def_display->driver) |
| 2497 | def_display->driver->disable(def_display); |
Vaibhav Hiremath | 5c7ab63 | 2010-04-11 10:41:49 -0300 | [diff] [blame] | 2498 | } |
| 2499 | probe_err0: |
| 2500 | kfree(vid_dev); |
| 2501 | return ret; |
| 2502 | } |
| 2503 | |
| 2504 | static struct platform_driver omap_vout_driver = { |
| 2505 | .driver = { |
| 2506 | .name = VOUT_NAME, |
| 2507 | }, |
| 2508 | .probe = omap_vout_probe, |
| 2509 | .remove = omap_vout_remove, |
| 2510 | }; |
| 2511 | |
| 2512 | static int __init omap_vout_init(void) |
| 2513 | { |
| 2514 | if (platform_driver_register(&omap_vout_driver) != 0) { |
| 2515 | printk(KERN_ERR VOUT_NAME ":Could not register Video driver\n"); |
| 2516 | return -EINVAL; |
| 2517 | } |
| 2518 | return 0; |
| 2519 | } |
| 2520 | |
| 2521 | static void omap_vout_cleanup(void) |
| 2522 | { |
| 2523 | platform_driver_unregister(&omap_vout_driver); |
| 2524 | } |
| 2525 | |
| 2526 | late_initcall(omap_vout_init); |
| 2527 | module_exit(omap_vout_cleanup); |