Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v5.1 1536 lines 42 kB view raw
1/* 2 * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/ 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public License as 6 * published by the Free Software Foundation version 2. 7 * 8 * This program is distributed WITHOUT ANY WARRANTY of any 9 * kind, whether express or implied; without even the implied warranty 10 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 */ 13#include <linux/kernel.h> 14#include <linux/init.h> 15#include <linux/module.h> 16#include <linux/errno.h> 17#include <linux/interrupt.h> 18#include <linux/string.h> 19#include <linux/wait.h> 20#include <linux/time.h> 21#include <linux/platform_device.h> 22#include <linux/irq.h> 23#include <linux/mm.h> 24#include <linux/mutex.h> 25#include <linux/videodev2.h> 26#include <linux/slab.h> 27 28#include <asm/pgtable.h> 29 30#ifdef CONFIG_ARCH_DAVINCI 31#include <mach/cputype.h> 32#endif 33 34#include <media/v4l2-dev.h> 35#include <media/v4l2-common.h> 36#include <media/v4l2-ioctl.h> 37#include <media/v4l2-device.h> 38#include <media/davinci/vpbe_display.h> 39#include <media/davinci/vpbe_types.h> 40#include <media/davinci/vpbe.h> 41#include <media/davinci/vpbe_venc.h> 42#include <media/davinci/vpbe_osd.h> 43#include "vpbe_venc_regs.h" 44 45#define VPBE_DISPLAY_DRIVER "vpbe-v4l2" 46 47static int debug; 48 49#define VPBE_DEFAULT_NUM_BUFS 3 50 51module_param(debug, int, 0644); 52 53static int vpbe_set_osd_display_params(struct vpbe_display *disp_dev, 54 struct vpbe_layer *layer); 55 56static int venc_is_second_field(struct vpbe_display *disp_dev) 57{ 58 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev; 59 int ret, val; 60 61 ret = v4l2_subdev_call(vpbe_dev->venc, 62 core, 63 ioctl, 64 VENC_GET_FLD, 65 &val); 66 if (ret < 0) { 67 v4l2_err(&vpbe_dev->v4l2_dev, 68 "Error in getting Field ID 0\n"); 69 return 1; 70 } 71 return val; 72} 73 74static void vpbe_isr_even_field(struct vpbe_display *disp_obj, 75 struct vpbe_layer *layer) 76{ 77 if (layer->cur_frm == layer->next_frm) 78 return; 79 80 layer->cur_frm->vb.vb2_buf.timestamp = ktime_get_ns(); 81 vb2_buffer_done(&layer->cur_frm->vb.vb2_buf, VB2_BUF_STATE_DONE); 82 /* Make cur_frm pointing to next_frm */ 83 layer->cur_frm = layer->next_frm; 84} 85 86static void vpbe_isr_odd_field(struct vpbe_display *disp_obj, 87 struct vpbe_layer *layer) 88{ 89 struct osd_state *osd_device = disp_obj->osd_device; 90 unsigned long addr; 91 92 spin_lock(&disp_obj->dma_queue_lock); 93 if (list_empty(&layer->dma_queue) || 94 (layer->cur_frm != layer->next_frm)) { 95 spin_unlock(&disp_obj->dma_queue_lock); 96 return; 97 } 98 /* 99 * one field is displayed configure 100 * the next frame if it is available 101 * otherwise hold on current frame 102 * Get next from the buffer queue 103 */ 104 layer->next_frm = list_entry(layer->dma_queue.next, 105 struct vpbe_disp_buffer, list); 106 /* Remove that from the buffer queue */ 107 list_del(&layer->next_frm->list); 108 spin_unlock(&disp_obj->dma_queue_lock); 109 /* Mark state of the frame to active */ 110 layer->next_frm->vb.vb2_buf.state = VB2_BUF_STATE_ACTIVE; 111 addr = vb2_dma_contig_plane_dma_addr(&layer->next_frm->vb.vb2_buf, 0); 112 osd_device->ops.start_layer(osd_device, 113 layer->layer_info.id, 114 addr, 115 disp_obj->cbcr_ofst); 116} 117 118/* interrupt service routine */ 119static irqreturn_t venc_isr(int irq, void *arg) 120{ 121 struct vpbe_display *disp_dev = (struct vpbe_display *)arg; 122 struct vpbe_layer *layer; 123 static unsigned last_event; 124 unsigned event = 0; 125 int fid; 126 int i; 127 128 if (!arg || !disp_dev->dev[0]) 129 return IRQ_HANDLED; 130 131 if (venc_is_second_field(disp_dev)) 132 event |= VENC_SECOND_FIELD; 133 else 134 event |= VENC_FIRST_FIELD; 135 136 if (event == (last_event & ~VENC_END_OF_FRAME)) { 137 /* 138 * If the display is non-interlaced, then we need to flag the 139 * end-of-frame event at every interrupt regardless of the 140 * value of the FIDST bit. We can conclude that the display is 141 * non-interlaced if the value of the FIDST bit is unchanged 142 * from the previous interrupt. 143 */ 144 event |= VENC_END_OF_FRAME; 145 } else if (event == VENC_SECOND_FIELD) { 146 /* end-of-frame for interlaced display */ 147 event |= VENC_END_OF_FRAME; 148 } 149 last_event = event; 150 151 for (i = 0; i < VPBE_DISPLAY_MAX_DEVICES; i++) { 152 layer = disp_dev->dev[i]; 153 154 if (!vb2_start_streaming_called(&layer->buffer_queue)) 155 continue; 156 157 if (layer->layer_first_int) { 158 layer->layer_first_int = 0; 159 continue; 160 } 161 /* Check the field format */ 162 if ((V4L2_FIELD_NONE == layer->pix_fmt.field) && 163 (event & VENC_END_OF_FRAME)) { 164 /* Progressive mode */ 165 166 vpbe_isr_even_field(disp_dev, layer); 167 vpbe_isr_odd_field(disp_dev, layer); 168 } else { 169 /* Interlaced mode */ 170 171 layer->field_id ^= 1; 172 if (event & VENC_FIRST_FIELD) 173 fid = 0; 174 else 175 fid = 1; 176 177 /* 178 * If field id does not match with store 179 * field id 180 */ 181 if (fid != layer->field_id) { 182 /* Make them in sync */ 183 layer->field_id = fid; 184 continue; 185 } 186 /* 187 * device field id and local field id are 188 * in sync. If this is even field 189 */ 190 if (0 == fid) 191 vpbe_isr_even_field(disp_dev, layer); 192 else /* odd field */ 193 vpbe_isr_odd_field(disp_dev, layer); 194 } 195 } 196 197 return IRQ_HANDLED; 198} 199 200/* 201 * vpbe_buffer_prepare() 202 * This is the callback function called from vb2_qbuf() function 203 * the buffer is prepared and user space virtual address is converted into 204 * physical address 205 */ 206static int vpbe_buffer_prepare(struct vb2_buffer *vb) 207{ 208 struct vb2_queue *q = vb->vb2_queue; 209 struct vpbe_layer *layer = vb2_get_drv_priv(q); 210 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev; 211 unsigned long addr; 212 213 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, 214 "vpbe_buffer_prepare\n"); 215 216 vb2_set_plane_payload(vb, 0, layer->pix_fmt.sizeimage); 217 if (vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0)) 218 return -EINVAL; 219 220 addr = vb2_dma_contig_plane_dma_addr(vb, 0); 221 if (!IS_ALIGNED(addr, 8)) { 222 v4l2_err(&vpbe_dev->v4l2_dev, 223 "buffer_prepare:offset is not aligned to 32 bytes\n"); 224 return -EINVAL; 225 } 226 return 0; 227} 228 229/* 230 * vpbe_buffer_setup() 231 * This function allocates memory for the buffers 232 */ 233static int 234vpbe_buffer_queue_setup(struct vb2_queue *vq, 235 unsigned int *nbuffers, unsigned int *nplanes, 236 unsigned int sizes[], struct device *alloc_devs[]) 237 238{ 239 /* Get the file handle object and layer object */ 240 struct vpbe_layer *layer = vb2_get_drv_priv(vq); 241 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev; 242 243 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "vpbe_buffer_setup\n"); 244 245 /* Store number of buffers allocated in numbuffer member */ 246 if (vq->num_buffers + *nbuffers < VPBE_DEFAULT_NUM_BUFS) 247 *nbuffers = VPBE_DEFAULT_NUM_BUFS - vq->num_buffers; 248 249 if (*nplanes) 250 return sizes[0] < layer->pix_fmt.sizeimage ? -EINVAL : 0; 251 252 *nplanes = 1; 253 sizes[0] = layer->pix_fmt.sizeimage; 254 255 return 0; 256} 257 258/* 259 * vpbe_buffer_queue() 260 * This function adds the buffer to DMA queue 261 */ 262static void vpbe_buffer_queue(struct vb2_buffer *vb) 263{ 264 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); 265 /* Get the file handle object and layer object */ 266 struct vpbe_disp_buffer *buf = container_of(vbuf, 267 struct vpbe_disp_buffer, vb); 268 struct vpbe_layer *layer = vb2_get_drv_priv(vb->vb2_queue); 269 struct vpbe_display *disp = layer->disp_dev; 270 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev; 271 unsigned long flags; 272 273 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, 274 "vpbe_buffer_queue\n"); 275 276 /* add the buffer to the DMA queue */ 277 spin_lock_irqsave(&disp->dma_queue_lock, flags); 278 list_add_tail(&buf->list, &layer->dma_queue); 279 spin_unlock_irqrestore(&disp->dma_queue_lock, flags); 280} 281 282static int vpbe_start_streaming(struct vb2_queue *vq, unsigned int count) 283{ 284 struct vpbe_layer *layer = vb2_get_drv_priv(vq); 285 struct osd_state *osd_device = layer->disp_dev->osd_device; 286 int ret; 287 288 osd_device->ops.disable_layer(osd_device, layer->layer_info.id); 289 290 /* Get the next frame from the buffer queue */ 291 layer->next_frm = layer->cur_frm = list_entry(layer->dma_queue.next, 292 struct vpbe_disp_buffer, list); 293 /* Remove buffer from the buffer queue */ 294 list_del(&layer->cur_frm->list); 295 /* Mark state of the current frame to active */ 296 layer->cur_frm->vb.vb2_buf.state = VB2_BUF_STATE_ACTIVE; 297 /* Initialize field_id and started member */ 298 layer->field_id = 0; 299 300 /* Set parameters in OSD and VENC */ 301 ret = vpbe_set_osd_display_params(layer->disp_dev, layer); 302 if (ret < 0) { 303 struct vpbe_disp_buffer *buf, *tmp; 304 305 vb2_buffer_done(&layer->cur_frm->vb.vb2_buf, 306 VB2_BUF_STATE_QUEUED); 307 list_for_each_entry_safe(buf, tmp, &layer->dma_queue, list) { 308 list_del(&buf->list); 309 vb2_buffer_done(&buf->vb.vb2_buf, 310 VB2_BUF_STATE_QUEUED); 311 } 312 313 return ret; 314 } 315 316 /* 317 * if request format is yuv420 semiplanar, need to 318 * enable both video windows 319 */ 320 layer->layer_first_int = 1; 321 322 return ret; 323} 324 325static void vpbe_stop_streaming(struct vb2_queue *vq) 326{ 327 struct vpbe_layer *layer = vb2_get_drv_priv(vq); 328 struct osd_state *osd_device = layer->disp_dev->osd_device; 329 struct vpbe_display *disp = layer->disp_dev; 330 unsigned long flags; 331 332 if (!vb2_is_streaming(vq)) 333 return; 334 335 osd_device->ops.disable_layer(osd_device, layer->layer_info.id); 336 337 /* release all active buffers */ 338 spin_lock_irqsave(&disp->dma_queue_lock, flags); 339 if (layer->cur_frm == layer->next_frm) { 340 vb2_buffer_done(&layer->cur_frm->vb.vb2_buf, 341 VB2_BUF_STATE_ERROR); 342 } else { 343 if (layer->cur_frm) 344 vb2_buffer_done(&layer->cur_frm->vb.vb2_buf, 345 VB2_BUF_STATE_ERROR); 346 if (layer->next_frm) 347 vb2_buffer_done(&layer->next_frm->vb.vb2_buf, 348 VB2_BUF_STATE_ERROR); 349 } 350 351 while (!list_empty(&layer->dma_queue)) { 352 layer->next_frm = list_entry(layer->dma_queue.next, 353 struct vpbe_disp_buffer, list); 354 list_del(&layer->next_frm->list); 355 vb2_buffer_done(&layer->next_frm->vb.vb2_buf, 356 VB2_BUF_STATE_ERROR); 357 } 358 spin_unlock_irqrestore(&disp->dma_queue_lock, flags); 359} 360 361static const struct vb2_ops video_qops = { 362 .queue_setup = vpbe_buffer_queue_setup, 363 .wait_prepare = vb2_ops_wait_prepare, 364 .wait_finish = vb2_ops_wait_finish, 365 .buf_prepare = vpbe_buffer_prepare, 366 .start_streaming = vpbe_start_streaming, 367 .stop_streaming = vpbe_stop_streaming, 368 .buf_queue = vpbe_buffer_queue, 369}; 370 371static 372struct vpbe_layer* 373_vpbe_display_get_other_win_layer(struct vpbe_display *disp_dev, 374 struct vpbe_layer *layer) 375{ 376 enum vpbe_display_device_id thiswin, otherwin; 377 thiswin = layer->device_id; 378 379 otherwin = (thiswin == VPBE_DISPLAY_DEVICE_0) ? 380 VPBE_DISPLAY_DEVICE_1 : VPBE_DISPLAY_DEVICE_0; 381 return disp_dev->dev[otherwin]; 382} 383 384static int vpbe_set_osd_display_params(struct vpbe_display *disp_dev, 385 struct vpbe_layer *layer) 386{ 387 struct osd_layer_config *cfg = &layer->layer_info.config; 388 struct osd_state *osd_device = disp_dev->osd_device; 389 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev; 390 unsigned long addr; 391 int ret; 392 393 addr = vb2_dma_contig_plane_dma_addr(&layer->cur_frm->vb.vb2_buf, 0); 394 /* Set address in the display registers */ 395 osd_device->ops.start_layer(osd_device, 396 layer->layer_info.id, 397 addr, 398 disp_dev->cbcr_ofst); 399 400 ret = osd_device->ops.enable_layer(osd_device, 401 layer->layer_info.id, 0); 402 if (ret < 0) { 403 v4l2_err(&vpbe_dev->v4l2_dev, 404 "Error in enabling osd window layer 0\n"); 405 return -1; 406 } 407 408 /* Enable the window */ 409 layer->layer_info.enable = 1; 410 if (cfg->pixfmt == PIXFMT_NV12) { 411 struct vpbe_layer *otherlayer = 412 _vpbe_display_get_other_win_layer(disp_dev, layer); 413 414 ret = osd_device->ops.enable_layer(osd_device, 415 otherlayer->layer_info.id, 1); 416 if (ret < 0) { 417 v4l2_err(&vpbe_dev->v4l2_dev, 418 "Error in enabling osd window layer 1\n"); 419 return -1; 420 } 421 otherlayer->layer_info.enable = 1; 422 } 423 return 0; 424} 425 426static void 427vpbe_disp_calculate_scale_factor(struct vpbe_display *disp_dev, 428 struct vpbe_layer *layer, 429 int expected_xsize, int expected_ysize) 430{ 431 struct display_layer_info *layer_info = &layer->layer_info; 432 struct v4l2_pix_format *pixfmt = &layer->pix_fmt; 433 struct osd_layer_config *cfg = &layer->layer_info.config; 434 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev; 435 int calculated_xsize; 436 int h_exp = 0; 437 int v_exp = 0; 438 int h_scale; 439 int v_scale; 440 441 v4l2_std_id standard_id = vpbe_dev->current_timings.std_id; 442 443 /* 444 * Application initially set the image format. Current display 445 * size is obtained from the vpbe display controller. expected_xsize 446 * and expected_ysize are set through S_SELECTION ioctl. Based on this, 447 * driver will calculate the scale factors for vertical and 448 * horizontal direction so that the image is displayed scaled 449 * and expanded. Application uses expansion to display the image 450 * in a square pixel. Otherwise it is displayed using displays 451 * pixel aspect ratio.It is expected that application chooses 452 * the crop coordinates for cropped or scaled display. if crop 453 * size is less than the image size, it is displayed cropped or 454 * it is displayed scaled and/or expanded. 455 * 456 * to begin with, set the crop window same as expected. Later we 457 * will override with scaled window size 458 */ 459 460 cfg->xsize = pixfmt->width; 461 cfg->ysize = pixfmt->height; 462 layer_info->h_zoom = ZOOM_X1; /* no horizontal zoom */ 463 layer_info->v_zoom = ZOOM_X1; /* no horizontal zoom */ 464 layer_info->h_exp = H_EXP_OFF; /* no horizontal zoom */ 465 layer_info->v_exp = V_EXP_OFF; /* no horizontal zoom */ 466 467 if (pixfmt->width < expected_xsize) { 468 h_scale = vpbe_dev->current_timings.xres / pixfmt->width; 469 if (h_scale < 2) 470 h_scale = 1; 471 else if (h_scale >= 4) 472 h_scale = 4; 473 else 474 h_scale = 2; 475 cfg->xsize *= h_scale; 476 if (cfg->xsize < expected_xsize) { 477 if ((standard_id & V4L2_STD_525_60) || 478 (standard_id & V4L2_STD_625_50)) { 479 calculated_xsize = (cfg->xsize * 480 VPBE_DISPLAY_H_EXP_RATIO_N) / 481 VPBE_DISPLAY_H_EXP_RATIO_D; 482 if (calculated_xsize <= expected_xsize) { 483 h_exp = 1; 484 cfg->xsize = calculated_xsize; 485 } 486 } 487 } 488 if (h_scale == 2) 489 layer_info->h_zoom = ZOOM_X2; 490 else if (h_scale == 4) 491 layer_info->h_zoom = ZOOM_X4; 492 if (h_exp) 493 layer_info->h_exp = H_EXP_9_OVER_8; 494 } else { 495 /* no scaling, only cropping. Set display area to crop area */ 496 cfg->xsize = expected_xsize; 497 } 498 499 if (pixfmt->height < expected_ysize) { 500 v_scale = expected_ysize / pixfmt->height; 501 if (v_scale < 2) 502 v_scale = 1; 503 else if (v_scale >= 4) 504 v_scale = 4; 505 else 506 v_scale = 2; 507 cfg->ysize *= v_scale; 508 if (cfg->ysize < expected_ysize) { 509 if ((standard_id & V4L2_STD_625_50)) { 510 calculated_xsize = (cfg->ysize * 511 VPBE_DISPLAY_V_EXP_RATIO_N) / 512 VPBE_DISPLAY_V_EXP_RATIO_D; 513 if (calculated_xsize <= expected_ysize) { 514 v_exp = 1; 515 cfg->ysize = calculated_xsize; 516 } 517 } 518 } 519 if (v_scale == 2) 520 layer_info->v_zoom = ZOOM_X2; 521 else if (v_scale == 4) 522 layer_info->v_zoom = ZOOM_X4; 523 if (v_exp) 524 layer_info->v_exp = V_EXP_6_OVER_5; 525 } else { 526 /* no scaling, only cropping. Set display area to crop area */ 527 cfg->ysize = expected_ysize; 528 } 529 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, 530 "crop display xsize = %d, ysize = %d\n", 531 cfg->xsize, cfg->ysize); 532} 533 534static void vpbe_disp_adj_position(struct vpbe_display *disp_dev, 535 struct vpbe_layer *layer, 536 int top, int left) 537{ 538 struct osd_layer_config *cfg = &layer->layer_info.config; 539 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev; 540 541 cfg->xpos = min((unsigned int)left, 542 vpbe_dev->current_timings.xres - cfg->xsize); 543 cfg->ypos = min((unsigned int)top, 544 vpbe_dev->current_timings.yres - cfg->ysize); 545 546 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, 547 "new xpos = %d, ypos = %d\n", 548 cfg->xpos, cfg->ypos); 549} 550 551static void vpbe_disp_check_window_params(struct vpbe_display *disp_dev, 552 struct v4l2_rect *c) 553{ 554 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev; 555 556 if ((c->width == 0) || 557 ((c->width + c->left) > vpbe_dev->current_timings.xres)) 558 c->width = vpbe_dev->current_timings.xres - c->left; 559 560 if ((c->height == 0) || ((c->height + c->top) > 561 vpbe_dev->current_timings.yres)) 562 c->height = vpbe_dev->current_timings.yres - c->top; 563 564 /* window height must be even for interlaced display */ 565 if (vpbe_dev->current_timings.interlaced) 566 c->height &= (~0x01); 567 568} 569 570/* 571 * vpbe_try_format() 572 * If user application provides width and height, and have bytesperline set 573 * to zero, driver calculates bytesperline and sizeimage based on hardware 574 * limits. 575 */ 576static int vpbe_try_format(struct vpbe_display *disp_dev, 577 struct v4l2_pix_format *pixfmt, int check) 578{ 579 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev; 580 int min_height = 1; 581 int min_width = 32; 582 int max_height; 583 int max_width; 584 int bpp; 585 586 if ((pixfmt->pixelformat != V4L2_PIX_FMT_UYVY) && 587 (pixfmt->pixelformat != V4L2_PIX_FMT_NV12)) 588 /* choose default as V4L2_PIX_FMT_UYVY */ 589 pixfmt->pixelformat = V4L2_PIX_FMT_UYVY; 590 591 /* Check the field format */ 592 if ((pixfmt->field != V4L2_FIELD_INTERLACED) && 593 (pixfmt->field != V4L2_FIELD_NONE)) { 594 if (vpbe_dev->current_timings.interlaced) 595 pixfmt->field = V4L2_FIELD_INTERLACED; 596 else 597 pixfmt->field = V4L2_FIELD_NONE; 598 } 599 600 if (pixfmt->field == V4L2_FIELD_INTERLACED) 601 min_height = 2; 602 603 if (pixfmt->pixelformat == V4L2_PIX_FMT_NV12) 604 bpp = 1; 605 else 606 bpp = 2; 607 608 max_width = vpbe_dev->current_timings.xres; 609 max_height = vpbe_dev->current_timings.yres; 610 611 min_width /= bpp; 612 613 if (!pixfmt->width || (pixfmt->width < min_width) || 614 (pixfmt->width > max_width)) { 615 pixfmt->width = vpbe_dev->current_timings.xres; 616 } 617 618 if (!pixfmt->height || (pixfmt->height < min_height) || 619 (pixfmt->height > max_height)) { 620 pixfmt->height = vpbe_dev->current_timings.yres; 621 } 622 623 if (pixfmt->bytesperline < (pixfmt->width * bpp)) 624 pixfmt->bytesperline = pixfmt->width * bpp; 625 626 /* Make the bytesperline 32 byte aligned */ 627 pixfmt->bytesperline = ((pixfmt->width * bpp + 31) & ~31); 628 629 if (pixfmt->pixelformat == V4L2_PIX_FMT_NV12) 630 pixfmt->sizeimage = pixfmt->bytesperline * pixfmt->height + 631 (pixfmt->bytesperline * pixfmt->height >> 1); 632 else 633 pixfmt->sizeimage = pixfmt->bytesperline * pixfmt->height; 634 635 return 0; 636} 637 638static int vpbe_display_querycap(struct file *file, void *priv, 639 struct v4l2_capability *cap) 640{ 641 struct vpbe_layer *layer = video_drvdata(file); 642 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev; 643 644 cap->device_caps = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING; 645 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS; 646 snprintf(cap->driver, sizeof(cap->driver), "%s", 647 dev_name(vpbe_dev->pdev)); 648 snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s", 649 dev_name(vpbe_dev->pdev)); 650 strscpy(cap->card, vpbe_dev->cfg->module_name, sizeof(cap->card)); 651 652 return 0; 653} 654 655static int vpbe_display_s_selection(struct file *file, void *priv, 656 struct v4l2_selection *sel) 657{ 658 struct vpbe_layer *layer = video_drvdata(file); 659 struct vpbe_display *disp_dev = layer->disp_dev; 660 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev; 661 struct osd_layer_config *cfg = &layer->layer_info.config; 662 struct osd_state *osd_device = disp_dev->osd_device; 663 struct v4l2_rect rect = sel->r; 664 int ret; 665 666 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, 667 "VIDIOC_S_SELECTION, layer id = %d\n", layer->device_id); 668 669 if (sel->type != V4L2_BUF_TYPE_VIDEO_OUTPUT || 670 sel->target != V4L2_SEL_TGT_CROP) 671 return -EINVAL; 672 673 if (rect.top < 0) 674 rect.top = 0; 675 if (rect.left < 0) 676 rect.left = 0; 677 678 vpbe_disp_check_window_params(disp_dev, &rect); 679 680 osd_device->ops.get_layer_config(osd_device, 681 layer->layer_info.id, cfg); 682 683 vpbe_disp_calculate_scale_factor(disp_dev, layer, 684 rect.width, 685 rect.height); 686 vpbe_disp_adj_position(disp_dev, layer, rect.top, 687 rect.left); 688 ret = osd_device->ops.set_layer_config(osd_device, 689 layer->layer_info.id, cfg); 690 if (ret < 0) { 691 v4l2_err(&vpbe_dev->v4l2_dev, 692 "Error in set layer config:\n"); 693 return -EINVAL; 694 } 695 696 /* apply zooming and h or v expansion */ 697 osd_device->ops.set_zoom(osd_device, 698 layer->layer_info.id, 699 layer->layer_info.h_zoom, 700 layer->layer_info.v_zoom); 701 ret = osd_device->ops.set_vid_expansion(osd_device, 702 layer->layer_info.h_exp, 703 layer->layer_info.v_exp); 704 if (ret < 0) { 705 v4l2_err(&vpbe_dev->v4l2_dev, 706 "Error in set vid expansion:\n"); 707 return -EINVAL; 708 } 709 710 if ((layer->layer_info.h_zoom != ZOOM_X1) || 711 (layer->layer_info.v_zoom != ZOOM_X1) || 712 (layer->layer_info.h_exp != H_EXP_OFF) || 713 (layer->layer_info.v_exp != V_EXP_OFF)) 714 /* Enable expansion filter */ 715 osd_device->ops.set_interpolation_filter(osd_device, 1); 716 else 717 osd_device->ops.set_interpolation_filter(osd_device, 0); 718 719 sel->r = rect; 720 return 0; 721} 722 723static int vpbe_display_g_selection(struct file *file, void *priv, 724 struct v4l2_selection *sel) 725{ 726 struct vpbe_layer *layer = video_drvdata(file); 727 struct osd_layer_config *cfg = &layer->layer_info.config; 728 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev; 729 struct osd_state *osd_device = layer->disp_dev->osd_device; 730 struct v4l2_rect *rect = &sel->r; 731 732 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, 733 "VIDIOC_G_SELECTION, layer id = %d\n", 734 layer->device_id); 735 736 if (sel->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) 737 return -EINVAL; 738 739 switch (sel->target) { 740 case V4L2_SEL_TGT_CROP: 741 osd_device->ops.get_layer_config(osd_device, 742 layer->layer_info.id, cfg); 743 rect->top = cfg->ypos; 744 rect->left = cfg->xpos; 745 rect->width = cfg->xsize; 746 rect->height = cfg->ysize; 747 break; 748 case V4L2_SEL_TGT_CROP_DEFAULT: 749 case V4L2_SEL_TGT_CROP_BOUNDS: 750 rect->left = 0; 751 rect->top = 0; 752 rect->width = vpbe_dev->current_timings.xres; 753 rect->height = vpbe_dev->current_timings.yres; 754 break; 755 default: 756 return -EINVAL; 757 } 758 759 return 0; 760} 761 762static int vpbe_display_g_pixelaspect(struct file *file, void *priv, 763 int type, struct v4l2_fract *f) 764{ 765 struct vpbe_layer *layer = video_drvdata(file); 766 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev; 767 768 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_CROPCAP ioctl\n"); 769 770 if (type != V4L2_BUF_TYPE_VIDEO_OUTPUT) 771 return -EINVAL; 772 773 *f = vpbe_dev->current_timings.aspect; 774 return 0; 775} 776 777static int vpbe_display_g_fmt(struct file *file, void *priv, 778 struct v4l2_format *fmt) 779{ 780 struct vpbe_layer *layer = video_drvdata(file); 781 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev; 782 783 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, 784 "VIDIOC_G_FMT, layer id = %d\n", 785 layer->device_id); 786 787 /* If buffer type is video output */ 788 if (V4L2_BUF_TYPE_VIDEO_OUTPUT != fmt->type) { 789 v4l2_err(&vpbe_dev->v4l2_dev, "invalid type\n"); 790 return -EINVAL; 791 } 792 /* Fill in the information about format */ 793 fmt->fmt.pix = layer->pix_fmt; 794 795 return 0; 796} 797 798static int vpbe_display_enum_fmt(struct file *file, void *priv, 799 struct v4l2_fmtdesc *fmt) 800{ 801 struct vpbe_layer *layer = video_drvdata(file); 802 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev; 803 unsigned int index = 0; 804 805 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, 806 "VIDIOC_ENUM_FMT, layer id = %d\n", 807 layer->device_id); 808 if (fmt->index > 1) { 809 v4l2_err(&vpbe_dev->v4l2_dev, "Invalid format index\n"); 810 return -EINVAL; 811 } 812 813 /* Fill in the information about format */ 814 index = fmt->index; 815 memset(fmt, 0, sizeof(*fmt)); 816 fmt->index = index; 817 fmt->type = V4L2_BUF_TYPE_VIDEO_OUTPUT; 818 if (index == 0) { 819 strscpy(fmt->description, "YUV 4:2:2 - UYVY", 820 sizeof(fmt->description)); 821 fmt->pixelformat = V4L2_PIX_FMT_UYVY; 822 } else { 823 strscpy(fmt->description, "Y/CbCr 4:2:0", 824 sizeof(fmt->description)); 825 fmt->pixelformat = V4L2_PIX_FMT_NV12; 826 } 827 828 return 0; 829} 830 831static int vpbe_display_s_fmt(struct file *file, void *priv, 832 struct v4l2_format *fmt) 833{ 834 struct vpbe_layer *layer = video_drvdata(file); 835 struct vpbe_display *disp_dev = layer->disp_dev; 836 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev; 837 struct osd_layer_config *cfg = &layer->layer_info.config; 838 struct v4l2_pix_format *pixfmt = &fmt->fmt.pix; 839 struct osd_state *osd_device = disp_dev->osd_device; 840 int ret; 841 842 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, 843 "VIDIOC_S_FMT, layer id = %d\n", 844 layer->device_id); 845 846 if (vb2_is_busy(&layer->buffer_queue)) 847 return -EBUSY; 848 849 if (V4L2_BUF_TYPE_VIDEO_OUTPUT != fmt->type) { 850 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "invalid type\n"); 851 return -EINVAL; 852 } 853 /* Check for valid pixel format */ 854 ret = vpbe_try_format(disp_dev, pixfmt, 1); 855 if (ret) 856 return ret; 857 858 /* YUV420 is requested, check availability of the 859 other video window */ 860 861 layer->pix_fmt = *pixfmt; 862 if (pixfmt->pixelformat == V4L2_PIX_FMT_NV12) { 863 struct vpbe_layer *otherlayer; 864 865 otherlayer = _vpbe_display_get_other_win_layer(disp_dev, layer); 866 /* if other layer is available, only 867 * claim it, do not configure it 868 */ 869 ret = osd_device->ops.request_layer(osd_device, 870 otherlayer->layer_info.id); 871 if (ret < 0) { 872 v4l2_err(&vpbe_dev->v4l2_dev, 873 "Display Manager failed to allocate layer\n"); 874 return -EBUSY; 875 } 876 } 877 878 /* Get osd layer config */ 879 osd_device->ops.get_layer_config(osd_device, 880 layer->layer_info.id, cfg); 881 /* Store the pixel format in the layer object */ 882 cfg->xsize = pixfmt->width; 883 cfg->ysize = pixfmt->height; 884 cfg->line_length = pixfmt->bytesperline; 885 cfg->ypos = 0; 886 cfg->xpos = 0; 887 cfg->interlaced = vpbe_dev->current_timings.interlaced; 888 889 if (V4L2_PIX_FMT_UYVY == pixfmt->pixelformat) 890 cfg->pixfmt = PIXFMT_YCBCRI; 891 892 /* Change of the default pixel format for both video windows */ 893 if (V4L2_PIX_FMT_NV12 == pixfmt->pixelformat) { 894 struct vpbe_layer *otherlayer; 895 cfg->pixfmt = PIXFMT_NV12; 896 otherlayer = _vpbe_display_get_other_win_layer(disp_dev, 897 layer); 898 otherlayer->layer_info.config.pixfmt = PIXFMT_NV12; 899 } 900 901 /* Set the layer config in the osd window */ 902 ret = osd_device->ops.set_layer_config(osd_device, 903 layer->layer_info.id, cfg); 904 if (ret < 0) { 905 v4l2_err(&vpbe_dev->v4l2_dev, 906 "Error in S_FMT params:\n"); 907 return -EINVAL; 908 } 909 910 /* Readback and fill the local copy of current pix format */ 911 osd_device->ops.get_layer_config(osd_device, 912 layer->layer_info.id, cfg); 913 914 return 0; 915} 916 917static int vpbe_display_try_fmt(struct file *file, void *priv, 918 struct v4l2_format *fmt) 919{ 920 struct vpbe_layer *layer = video_drvdata(file); 921 struct vpbe_display *disp_dev = layer->disp_dev; 922 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev; 923 struct v4l2_pix_format *pixfmt = &fmt->fmt.pix; 924 925 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_TRY_FMT\n"); 926 927 if (V4L2_BUF_TYPE_VIDEO_OUTPUT != fmt->type) { 928 v4l2_err(&vpbe_dev->v4l2_dev, "invalid type\n"); 929 return -EINVAL; 930 } 931 932 /* Check for valid field format */ 933 return vpbe_try_format(disp_dev, pixfmt, 0); 934 935} 936 937/* 938 * vpbe_display_s_std - Set the given standard in the encoder 939 * 940 * Sets the standard if supported by the current encoder. Return the status. 941 * 0 - success & -EINVAL on error 942 */ 943static int vpbe_display_s_std(struct file *file, void *priv, 944 v4l2_std_id std_id) 945{ 946 struct vpbe_layer *layer = video_drvdata(file); 947 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev; 948 int ret; 949 950 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_S_STD\n"); 951 952 if (vb2_is_busy(&layer->buffer_queue)) 953 return -EBUSY; 954 955 if (vpbe_dev->ops.s_std) { 956 ret = vpbe_dev->ops.s_std(vpbe_dev, std_id); 957 if (ret) { 958 v4l2_err(&vpbe_dev->v4l2_dev, 959 "Failed to set standard for sub devices\n"); 960 return -EINVAL; 961 } 962 } else { 963 return -EINVAL; 964 } 965 966 return 0; 967} 968 969/* 970 * vpbe_display_g_std - Get the standard in the current encoder 971 * 972 * Get the standard in the current encoder. Return the status. 0 - success 973 * -EINVAL on error 974 */ 975static int vpbe_display_g_std(struct file *file, void *priv, 976 v4l2_std_id *std_id) 977{ 978 struct vpbe_layer *layer = video_drvdata(file); 979 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev; 980 981 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_G_STD\n"); 982 983 /* Get the standard from the current encoder */ 984 if (vpbe_dev->current_timings.timings_type & VPBE_ENC_STD) { 985 *std_id = vpbe_dev->current_timings.std_id; 986 return 0; 987 } 988 989 return -EINVAL; 990} 991 992/* 993 * vpbe_display_enum_output - enumerate outputs 994 * 995 * Enumerates the outputs available at the vpbe display 996 * returns the status, -EINVAL if end of output list 997 */ 998static int vpbe_display_enum_output(struct file *file, void *priv, 999 struct v4l2_output *output) 1000{ 1001 struct vpbe_layer *layer = video_drvdata(file); 1002 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev; 1003 int ret; 1004 1005 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_ENUM_OUTPUT\n"); 1006 1007 /* Enumerate outputs */ 1008 if (!vpbe_dev->ops.enum_outputs) 1009 return -EINVAL; 1010 1011 ret = vpbe_dev->ops.enum_outputs(vpbe_dev, output); 1012 if (ret) { 1013 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, 1014 "Failed to enumerate outputs\n"); 1015 return -EINVAL; 1016 } 1017 1018 return 0; 1019} 1020 1021/* 1022 * vpbe_display_s_output - Set output to 1023 * the output specified by the index 1024 */ 1025static int vpbe_display_s_output(struct file *file, void *priv, 1026 unsigned int i) 1027{ 1028 struct vpbe_layer *layer = video_drvdata(file); 1029 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev; 1030 int ret; 1031 1032 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_S_OUTPUT\n"); 1033 1034 if (vb2_is_busy(&layer->buffer_queue)) 1035 return -EBUSY; 1036 1037 if (!vpbe_dev->ops.set_output) 1038 return -EINVAL; 1039 1040 ret = vpbe_dev->ops.set_output(vpbe_dev, i); 1041 if (ret) { 1042 v4l2_err(&vpbe_dev->v4l2_dev, 1043 "Failed to set output for sub devices\n"); 1044 return -EINVAL; 1045 } 1046 1047 return 0; 1048} 1049 1050/* 1051 * vpbe_display_g_output - Get output from subdevice 1052 * for a given by the index 1053 */ 1054static int vpbe_display_g_output(struct file *file, void *priv, 1055 unsigned int *i) 1056{ 1057 struct vpbe_layer *layer = video_drvdata(file); 1058 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev; 1059 1060 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_G_OUTPUT\n"); 1061 /* Get the standard from the current encoder */ 1062 *i = vpbe_dev->current_out_index; 1063 1064 return 0; 1065} 1066 1067/* 1068 * vpbe_display_enum_dv_timings - Enumerate the dv timings 1069 * 1070 * enum the timings in the current encoder. Return the status. 0 - success 1071 * -EINVAL on error 1072 */ 1073static int 1074vpbe_display_enum_dv_timings(struct file *file, void *priv, 1075 struct v4l2_enum_dv_timings *timings) 1076{ 1077 struct vpbe_layer *layer = video_drvdata(file); 1078 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev; 1079 int ret; 1080 1081 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_ENUM_DV_TIMINGS\n"); 1082 1083 /* Enumerate outputs */ 1084 if (!vpbe_dev->ops.enum_dv_timings) 1085 return -EINVAL; 1086 1087 ret = vpbe_dev->ops.enum_dv_timings(vpbe_dev, timings); 1088 if (ret) { 1089 v4l2_err(&vpbe_dev->v4l2_dev, 1090 "Failed to enumerate dv timings info\n"); 1091 return -EINVAL; 1092 } 1093 1094 return 0; 1095} 1096 1097/* 1098 * vpbe_display_s_dv_timings - Set the dv timings 1099 * 1100 * Set the timings in the current encoder. Return the status. 0 - success 1101 * -EINVAL on error 1102 */ 1103static int 1104vpbe_display_s_dv_timings(struct file *file, void *priv, 1105 struct v4l2_dv_timings *timings) 1106{ 1107 struct vpbe_layer *layer = video_drvdata(file); 1108 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev; 1109 int ret; 1110 1111 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_S_DV_TIMINGS\n"); 1112 1113 if (vb2_is_busy(&layer->buffer_queue)) 1114 return -EBUSY; 1115 1116 /* Set the given standard in the encoder */ 1117 if (!vpbe_dev->ops.s_dv_timings) 1118 return -EINVAL; 1119 1120 ret = vpbe_dev->ops.s_dv_timings(vpbe_dev, timings); 1121 if (ret) { 1122 v4l2_err(&vpbe_dev->v4l2_dev, 1123 "Failed to set the dv timings info\n"); 1124 return -EINVAL; 1125 } 1126 1127 return 0; 1128} 1129 1130/* 1131 * vpbe_display_g_dv_timings - Set the dv timings 1132 * 1133 * Get the timings in the current encoder. Return the status. 0 - success 1134 * -EINVAL on error 1135 */ 1136static int 1137vpbe_display_g_dv_timings(struct file *file, void *priv, 1138 struct v4l2_dv_timings *dv_timings) 1139{ 1140 struct vpbe_layer *layer = video_drvdata(file); 1141 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev; 1142 1143 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_G_DV_TIMINGS\n"); 1144 1145 /* Get the given standard in the encoder */ 1146 1147 if (vpbe_dev->current_timings.timings_type & 1148 VPBE_ENC_DV_TIMINGS) { 1149 *dv_timings = vpbe_dev->current_timings.dv_timings; 1150 } else { 1151 return -EINVAL; 1152 } 1153 1154 return 0; 1155} 1156 1157/* 1158 * vpbe_display_open() 1159 * It creates object of file handle structure and stores it in private_data 1160 * member of filepointer 1161 */ 1162static int vpbe_display_open(struct file *file) 1163{ 1164 struct vpbe_layer *layer = video_drvdata(file); 1165 struct vpbe_display *disp_dev = layer->disp_dev; 1166 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev; 1167 struct osd_state *osd_device = disp_dev->osd_device; 1168 int err; 1169 1170 /* creating context for file descriptor */ 1171 err = v4l2_fh_open(file); 1172 if (err) { 1173 v4l2_err(&vpbe_dev->v4l2_dev, "v4l2_fh_open failed\n"); 1174 return err; 1175 } 1176 1177 /* leaving if layer is already initialized */ 1178 if (!v4l2_fh_is_singular_file(file)) 1179 return err; 1180 1181 if (!layer->usrs) { 1182 if (mutex_lock_interruptible(&layer->opslock)) 1183 return -ERESTARTSYS; 1184 /* First claim the layer for this device */ 1185 err = osd_device->ops.request_layer(osd_device, 1186 layer->layer_info.id); 1187 mutex_unlock(&layer->opslock); 1188 if (err < 0) { 1189 /* Couldn't get layer */ 1190 v4l2_err(&vpbe_dev->v4l2_dev, 1191 "Display Manager failed to allocate layer\n"); 1192 v4l2_fh_release(file); 1193 return -EINVAL; 1194 } 1195 } 1196 /* Increment layer usrs counter */ 1197 layer->usrs++; 1198 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, 1199 "vpbe display device opened successfully\n"); 1200 return 0; 1201} 1202 1203/* 1204 * vpbe_display_release() 1205 * This function deletes buffer queue, frees the buffers and the davinci 1206 * display file * handle 1207 */ 1208static int vpbe_display_release(struct file *file) 1209{ 1210 struct vpbe_layer *layer = video_drvdata(file); 1211 struct osd_layer_config *cfg = &layer->layer_info.config; 1212 struct vpbe_display *disp_dev = layer->disp_dev; 1213 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev; 1214 struct osd_state *osd_device = disp_dev->osd_device; 1215 1216 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "vpbe_display_release\n"); 1217 1218 mutex_lock(&layer->opslock); 1219 1220 osd_device->ops.disable_layer(osd_device, 1221 layer->layer_info.id); 1222 /* Decrement layer usrs counter */ 1223 layer->usrs--; 1224 /* If this file handle has initialize encoder device, reset it */ 1225 if (!layer->usrs) { 1226 if (cfg->pixfmt == PIXFMT_NV12) { 1227 struct vpbe_layer *otherlayer; 1228 otherlayer = 1229 _vpbe_display_get_other_win_layer(disp_dev, layer); 1230 osd_device->ops.disable_layer(osd_device, 1231 otherlayer->layer_info.id); 1232 osd_device->ops.release_layer(osd_device, 1233 otherlayer->layer_info.id); 1234 } 1235 osd_device->ops.disable_layer(osd_device, 1236 layer->layer_info.id); 1237 osd_device->ops.release_layer(osd_device, 1238 layer->layer_info.id); 1239 } 1240 1241 _vb2_fop_release(file, NULL); 1242 mutex_unlock(&layer->opslock); 1243 1244 disp_dev->cbcr_ofst = 0; 1245 1246 return 0; 1247} 1248 1249/* vpbe capture ioctl operations */ 1250static const struct v4l2_ioctl_ops vpbe_ioctl_ops = { 1251 .vidioc_querycap = vpbe_display_querycap, 1252 .vidioc_g_fmt_vid_out = vpbe_display_g_fmt, 1253 .vidioc_enum_fmt_vid_out = vpbe_display_enum_fmt, 1254 .vidioc_s_fmt_vid_out = vpbe_display_s_fmt, 1255 .vidioc_try_fmt_vid_out = vpbe_display_try_fmt, 1256 1257 .vidioc_reqbufs = vb2_ioctl_reqbufs, 1258 .vidioc_create_bufs = vb2_ioctl_create_bufs, 1259 .vidioc_querybuf = vb2_ioctl_querybuf, 1260 .vidioc_qbuf = vb2_ioctl_qbuf, 1261 .vidioc_dqbuf = vb2_ioctl_dqbuf, 1262 .vidioc_streamon = vb2_ioctl_streamon, 1263 .vidioc_streamoff = vb2_ioctl_streamoff, 1264 .vidioc_expbuf = vb2_ioctl_expbuf, 1265 1266 .vidioc_g_pixelaspect = vpbe_display_g_pixelaspect, 1267 .vidioc_g_selection = vpbe_display_g_selection, 1268 .vidioc_s_selection = vpbe_display_s_selection, 1269 1270 .vidioc_s_std = vpbe_display_s_std, 1271 .vidioc_g_std = vpbe_display_g_std, 1272 1273 .vidioc_enum_output = vpbe_display_enum_output, 1274 .vidioc_s_output = vpbe_display_s_output, 1275 .vidioc_g_output = vpbe_display_g_output, 1276 1277 .vidioc_s_dv_timings = vpbe_display_s_dv_timings, 1278 .vidioc_g_dv_timings = vpbe_display_g_dv_timings, 1279 .vidioc_enum_dv_timings = vpbe_display_enum_dv_timings, 1280}; 1281 1282static const struct v4l2_file_operations vpbe_fops = { 1283 .owner = THIS_MODULE, 1284 .open = vpbe_display_open, 1285 .release = vpbe_display_release, 1286 .unlocked_ioctl = video_ioctl2, 1287 .mmap = vb2_fop_mmap, 1288 .poll = vb2_fop_poll, 1289}; 1290 1291static int vpbe_device_get(struct device *dev, void *data) 1292{ 1293 struct platform_device *pdev = to_platform_device(dev); 1294 struct vpbe_display *vpbe_disp = data; 1295 1296 if (strcmp("vpbe_controller", pdev->name) == 0) 1297 vpbe_disp->vpbe_dev = platform_get_drvdata(pdev); 1298 1299 if (strstr(pdev->name, "vpbe-osd")) 1300 vpbe_disp->osd_device = platform_get_drvdata(pdev); 1301 1302 return 0; 1303} 1304 1305static int init_vpbe_layer(int i, struct vpbe_display *disp_dev, 1306 struct platform_device *pdev) 1307{ 1308 struct vpbe_layer *vpbe_display_layer = NULL; 1309 struct video_device *vbd = NULL; 1310 1311 /* Allocate memory for four plane display objects */ 1312 disp_dev->dev[i] = kzalloc(sizeof(*disp_dev->dev[i]), GFP_KERNEL); 1313 if (!disp_dev->dev[i]) 1314 return -ENOMEM; 1315 1316 spin_lock_init(&disp_dev->dev[i]->irqlock); 1317 mutex_init(&disp_dev->dev[i]->opslock); 1318 1319 /* Get the pointer to the layer object */ 1320 vpbe_display_layer = disp_dev->dev[i]; 1321 vbd = &vpbe_display_layer->video_dev; 1322 /* Initialize field of video device */ 1323 vbd->release = video_device_release_empty; 1324 vbd->fops = &vpbe_fops; 1325 vbd->ioctl_ops = &vpbe_ioctl_ops; 1326 vbd->minor = -1; 1327 vbd->v4l2_dev = &disp_dev->vpbe_dev->v4l2_dev; 1328 vbd->lock = &vpbe_display_layer->opslock; 1329 vbd->vfl_dir = VFL_DIR_TX; 1330 1331 if (disp_dev->vpbe_dev->current_timings.timings_type & 1332 VPBE_ENC_STD) 1333 vbd->tvnorms = (V4L2_STD_525_60 | V4L2_STD_625_50); 1334 1335 snprintf(vbd->name, sizeof(vbd->name), 1336 "DaVinci_VPBE Display_DRIVER_V%d.%d.%d", 1337 (VPBE_DISPLAY_VERSION_CODE >> 16) & 0xff, 1338 (VPBE_DISPLAY_VERSION_CODE >> 8) & 0xff, 1339 (VPBE_DISPLAY_VERSION_CODE) & 0xff); 1340 1341 vpbe_display_layer->device_id = i; 1342 1343 vpbe_display_layer->layer_info.id = 1344 ((i == VPBE_DISPLAY_DEVICE_0) ? WIN_VID0 : WIN_VID1); 1345 1346 1347 return 0; 1348} 1349 1350static int register_device(struct vpbe_layer *vpbe_display_layer, 1351 struct vpbe_display *disp_dev, 1352 struct platform_device *pdev) 1353{ 1354 int err; 1355 1356 v4l2_info(&disp_dev->vpbe_dev->v4l2_dev, 1357 "Trying to register VPBE display device.\n"); 1358 v4l2_info(&disp_dev->vpbe_dev->v4l2_dev, 1359 "layer=%p,layer->video_dev=%p\n", 1360 vpbe_display_layer, 1361 &vpbe_display_layer->video_dev); 1362 1363 vpbe_display_layer->video_dev.queue = &vpbe_display_layer->buffer_queue; 1364 err = video_register_device(&vpbe_display_layer->video_dev, 1365 VFL_TYPE_GRABBER, 1366 -1); 1367 if (err) 1368 return -ENODEV; 1369 1370 vpbe_display_layer->disp_dev = disp_dev; 1371 /* set the driver data in platform device */ 1372 platform_set_drvdata(pdev, disp_dev); 1373 video_set_drvdata(&vpbe_display_layer->video_dev, 1374 vpbe_display_layer); 1375 1376 return 0; 1377} 1378 1379 1380 1381/* 1382 * vpbe_display_probe() 1383 * This function creates device entries by register itself to the V4L2 driver 1384 * and initializes fields of each layer objects 1385 */ 1386static int vpbe_display_probe(struct platform_device *pdev) 1387{ 1388 struct vpbe_display *disp_dev; 1389 struct v4l2_device *v4l2_dev; 1390 struct resource *res = NULL; 1391 struct vb2_queue *q; 1392 int k; 1393 int i; 1394 int err; 1395 int irq; 1396 1397 printk(KERN_DEBUG "vpbe_display_probe\n"); 1398 /* Allocate memory for vpbe_display */ 1399 disp_dev = devm_kzalloc(&pdev->dev, sizeof(*disp_dev), GFP_KERNEL); 1400 if (!disp_dev) 1401 return -ENOMEM; 1402 1403 spin_lock_init(&disp_dev->dma_queue_lock); 1404 /* 1405 * Scan all the platform devices to find the vpbe 1406 * controller device and get the vpbe_dev object 1407 */ 1408 err = bus_for_each_dev(&platform_bus_type, NULL, disp_dev, 1409 vpbe_device_get); 1410 if (err < 0) 1411 return err; 1412 1413 v4l2_dev = &disp_dev->vpbe_dev->v4l2_dev; 1414 /* Initialize the vpbe display controller */ 1415 if (disp_dev->vpbe_dev->ops.initialize) { 1416 err = disp_dev->vpbe_dev->ops.initialize(&pdev->dev, 1417 disp_dev->vpbe_dev); 1418 if (err) { 1419 v4l2_err(v4l2_dev, "Error initing vpbe\n"); 1420 err = -ENOMEM; 1421 goto probe_out; 1422 } 1423 } 1424 1425 for (i = 0; i < VPBE_DISPLAY_MAX_DEVICES; i++) { 1426 if (init_vpbe_layer(i, disp_dev, pdev)) { 1427 err = -ENODEV; 1428 goto probe_out; 1429 } 1430 } 1431 1432 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 1433 if (!res) { 1434 v4l2_err(v4l2_dev, "Unable to get VENC interrupt resource\n"); 1435 err = -ENODEV; 1436 goto probe_out; 1437 } 1438 1439 irq = res->start; 1440 err = devm_request_irq(&pdev->dev, irq, venc_isr, 0, 1441 VPBE_DISPLAY_DRIVER, disp_dev); 1442 if (err) { 1443 v4l2_err(v4l2_dev, "VPBE IRQ request failed\n"); 1444 goto probe_out; 1445 } 1446 1447 for (i = 0; i < VPBE_DISPLAY_MAX_DEVICES; i++) { 1448 /* initialize vb2 queue */ 1449 q = &disp_dev->dev[i]->buffer_queue; 1450 memset(q, 0, sizeof(*q)); 1451 q->type = V4L2_BUF_TYPE_VIDEO_OUTPUT; 1452 q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF; 1453 q->drv_priv = disp_dev->dev[i]; 1454 q->ops = &video_qops; 1455 q->mem_ops = &vb2_dma_contig_memops; 1456 q->buf_struct_size = sizeof(struct vpbe_disp_buffer); 1457 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; 1458 q->min_buffers_needed = 1; 1459 q->lock = &disp_dev->dev[i]->opslock; 1460 q->dev = disp_dev->vpbe_dev->pdev; 1461 err = vb2_queue_init(q); 1462 if (err) { 1463 v4l2_err(v4l2_dev, "vb2_queue_init() failed\n"); 1464 goto probe_out; 1465 } 1466 1467 INIT_LIST_HEAD(&disp_dev->dev[i]->dma_queue); 1468 1469 if (register_device(disp_dev->dev[i], disp_dev, pdev)) { 1470 err = -ENODEV; 1471 goto probe_out; 1472 } 1473 } 1474 1475 v4l2_dbg(1, debug, v4l2_dev, 1476 "Successfully completed the probing of vpbe v4l2 device\n"); 1477 1478 return 0; 1479 1480probe_out: 1481 for (k = 0; k < VPBE_DISPLAY_MAX_DEVICES; k++) { 1482 /* Unregister video device */ 1483 if (disp_dev->dev[k]) { 1484 video_unregister_device(&disp_dev->dev[k]->video_dev); 1485 kfree(disp_dev->dev[k]); 1486 } 1487 } 1488 return err; 1489} 1490 1491/* 1492 * vpbe_display_remove() 1493 * It un-register hardware layer from V4L2 driver 1494 */ 1495static int vpbe_display_remove(struct platform_device *pdev) 1496{ 1497 struct vpbe_layer *vpbe_display_layer; 1498 struct vpbe_display *disp_dev = platform_get_drvdata(pdev); 1499 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev; 1500 int i; 1501 1502 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "vpbe_display_remove\n"); 1503 1504 /* deinitialize the vpbe display controller */ 1505 if (vpbe_dev->ops.deinitialize) 1506 vpbe_dev->ops.deinitialize(&pdev->dev, vpbe_dev); 1507 /* un-register device */ 1508 for (i = 0; i < VPBE_DISPLAY_MAX_DEVICES; i++) { 1509 /* Get the pointer to the layer object */ 1510 vpbe_display_layer = disp_dev->dev[i]; 1511 /* Unregister video device */ 1512 video_unregister_device(&vpbe_display_layer->video_dev); 1513 1514 } 1515 for (i = 0; i < VPBE_DISPLAY_MAX_DEVICES; i++) { 1516 kfree(disp_dev->dev[i]); 1517 disp_dev->dev[i] = NULL; 1518 } 1519 1520 return 0; 1521} 1522 1523static struct platform_driver vpbe_display_driver = { 1524 .driver = { 1525 .name = VPBE_DISPLAY_DRIVER, 1526 .bus = &platform_bus_type, 1527 }, 1528 .probe = vpbe_display_probe, 1529 .remove = vpbe_display_remove, 1530}; 1531 1532module_platform_driver(vpbe_display_driver); 1533 1534MODULE_DESCRIPTION("TI DM644x/DM355/DM365 VPBE Display controller"); 1535MODULE_LICENSE("GPL"); 1536MODULE_AUTHOR("Texas Instruments");