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