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