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