Lines Matching +full:gain +full:- +full:scaling +full:- +full:n
1 // SPDX-License-Identifier: GPL-2.0-only
6 #include <media/drv-intf/saa7146_vv.h>
26 hyo = vv->standard->v_offset; in calculate_hxo_and_hyo()
27 hxo = vv->standard->h_offset; in calculate_hxo_and_hyo()
36 /* helper functions for the calculation of the horizontal- and vertical
37 scaling registers, clip-format-register etc ...
38 these functions take pointers to the (most-likely read-out
39 original-values) and manipulate them according to the requested
43 /* hps_coeff used for CXY and CXUV; scale 1/1 -> scale 1/64 */
63 /* table of attenuation values for horizontal scaling */
75 /* vertical scale & gain */ in calculate_h_scale_registers()
82 return -EINVAL; in calculate_h_scale_registers()
85 /* mask out vanity-bit */ in calculate_h_scale_registers()
88 /* calculate prescale-(xspc)-value: [n .. 1/2) : 1 in calculate_h_scale_registers()
100 /* if flip_lr-bit is set, number of pixels after in calculate_h_scale_registers()
125 cxy = hps_h_coeff_tab[min(xpsc - 1, 63)].hps_coeff; in calculate_h_scale_registers()
153 for horizontal scaling */ in calculate_h_scale_registers()
154 h_atten = hps_h_coeff_tab[min(xpsc - 1, 63)].weight_sum; in calculate_h_scale_registers()
164 /* the horizontal scaling increment controls the UV filter in calculate_h_scale_registers()
185 *hps_h_prescale |= (dcgx << 27) | ((xpsc-1) << 18) | (xacm << 17) | (cxy << 8) | (cxuv << 0); in calculate_h_scale_registers()
209 /* table of attenuation values for vertical scaling */
218 /* vertical scaling */ in calculate_v_scale_registers()
220 /* vertical scale & gain */ in calculate_v_scale_registers()
228 return -EINVAL; in calculate_v_scale_registers()
232 if scaling is between 1 and 1/2 (both fields used) in calculate_v_scale_registers()
233 or scaling is between 1/2 and 1/4 (if only one field is used) */ in calculate_v_scale_registers()
253 /* calculate scaling increment */ in calculate_v_scale_registers()
255 ysci = ((1024 * in_y) / (out_y + 1)) - 1024; in calculate_v_scale_registers()
268 /* calculate scaling increment */ in calculate_v_scale_registers()
269 ysci = (((10 * 1024 * (in_y - out_y - 1)) / in_y) + 9) / 10; in calculate_v_scale_registers()
275 to the prescale value, e.g. [n .. 1/2) : 0 in calculate_v_scale_registers()
282 yacl = ( ysci / (1024 - ysci) ); in calculate_v_scale_registers()
288 /* get best match in the table of attenuations for vertical scaling */ in calculate_v_scale_registers()
308 /* simple bubble-sort algorithm with duplicate elimination */
311 struct saa7146_vv *vv = dev->vv_data; in saa7146_set_window()
313 int source = vv->current_hps_source; in saa7146_set_window()
314 int sync = vv->current_hps_sync; in saa7146_set_window()
319 hps_v_scale = 0; /* all bits get set by the function-call */ in saa7146_set_window()
321 …calculate_v_scale_registers(dev, field, vv->standard->v_field*2, height, &hps_v_scale, &hps_v_gain… in saa7146_set_window()
327 …calculate_h_scale_registers(dev, vv->standard->h_pixels, width, vv->hflip, &hps_ctrl, &hps_v_gain,… in saa7146_set_window()
340 /* upload shadow-ram registers */ in saa7146_set_window()
356 /* select input-source */
359 struct saa7146_vv *vv = dev->vv_data; in saa7146_set_hps_source_and_sync()
372 vv->current_hps_source = source; in saa7146_set_hps_source_and_sync()
373 vv->current_hps_sync = sync; in saa7146_set_hps_source_and_sync()
386 where = (which-1)*0x18; in saa7146_write_out_dma()
388 saa7146_write(dev, where, vdma->base_odd); in saa7146_write_out_dma()
389 saa7146_write(dev, where+0x04, vdma->base_even); in saa7146_write_out_dma()
390 saa7146_write(dev, where+0x08, vdma->prot_addr); in saa7146_write_out_dma()
391 saa7146_write(dev, where+0x0c, vdma->pitch); in saa7146_write_out_dma()
392 saa7146_write(dev, where+0x10, vdma->base_page); in saa7146_write_out_dma()
393 saa7146_write(dev, where+0x14, vdma->num_line_byte); in saa7146_write_out_dma()
396 saa7146_write(dev, MC2, (MASK_02<<(which-1))|(MASK_18<<(which-1))); in saa7146_write_out_dma()
398 printk("vdma%d.base_even: 0x%08x\n", which,vdma->base_even); in saa7146_write_out_dma()
399 printk("vdma%d.base_odd: 0x%08x\n", which,vdma->base_odd); in saa7146_write_out_dma()
400 printk("vdma%d.prot_addr: 0x%08x\n", which,vdma->prot_addr); in saa7146_write_out_dma()
401 printk("vdma%d.base_page: 0x%08x\n", which,vdma->base_page); in saa7146_write_out_dma()
402 printk("vdma%d.pitch: 0x%08x\n", which,vdma->pitch); in saa7146_write_out_dma()
403 printk("vdma%d.num_line_byte: 0x%08x\n", which,vdma->num_line_byte); in saa7146_write_out_dma()
409 struct saa7146_vv *vv = dev->vv_data; in calculate_video_dma_grab_packed()
410 struct v4l2_pix_format *pix = &vv->video_fmt; in calculate_video_dma_grab_packed()
412 struct saa7146_format *sfmt = saa7146_format_by_fourcc(dev, pix->pixelformat); in calculate_video_dma_grab_packed()
414 int width = pix->width; in calculate_video_dma_grab_packed()
415 int height = pix->height; in calculate_video_dma_grab_packed()
416 int bytesperline = pix->bytesperline; in calculate_video_dma_grab_packed()
417 enum v4l2_field field = pix->field; in calculate_video_dma_grab_packed()
419 int depth = sfmt->depth; in calculate_video_dma_grab_packed()
421 DEB_CAP("[size=%dx%d,fields=%s]\n", in calculate_video_dma_grab_packed()
429 vdma1.num_line_byte = ((vv->standard->v_field<<16) + vv->standard->h_pixels); in calculate_video_dma_grab_packed()
430 vdma1.base_page = buf->pt[0].dma | ME1 | sfmt->swap; in calculate_video_dma_grab_packed()
432 if( 0 != vv->vflip ) { in calculate_video_dma_grab_packed()
433 vdma1.prot_addr = buf->pt[0].offset; in calculate_video_dma_grab_packed()
434 vdma1.base_even = buf->pt[0].offset+(vdma1.pitch/2)*height; in calculate_video_dma_grab_packed()
435 vdma1.base_odd = vdma1.base_even - (vdma1.pitch/2); in calculate_video_dma_grab_packed()
437 vdma1.base_even = buf->pt[0].offset; in calculate_video_dma_grab_packed()
439 vdma1.prot_addr = buf->pt[0].offset+(vdma1.pitch/2)*height; in calculate_video_dma_grab_packed()
445 if ( vv->last_field == V4L2_FIELD_TOP ) { in calculate_video_dma_grab_packed()
448 } else if ( vv->last_field == V4L2_FIELD_BOTTOM ) { in calculate_video_dma_grab_packed()
462 if( 0 != vv->vflip ) { in calculate_video_dma_grab_packed()
463 vdma1.pitch *= -1; in calculate_video_dma_grab_packed()
472 struct v4l2_pix_format *pix = &vv->video_fmt; in calc_planar_422()
473 int height = pix->height; in calc_planar_422()
474 int width = pix->width; in calc_planar_422()
476 vdma2->pitch = width; in calc_planar_422()
477 vdma3->pitch = width; in calc_planar_422()
481 if( 0 != vv->vflip ) { in calc_planar_422()
482 vdma2->prot_addr = buf->pt[1].offset; in calc_planar_422()
483 vdma2->base_even = ((vdma2->pitch/2)*height)+buf->pt[1].offset; in calc_planar_422()
484 vdma2->base_odd = vdma2->base_even - (vdma2->pitch/2); in calc_planar_422()
486 vdma3->prot_addr = buf->pt[2].offset; in calc_planar_422()
487 vdma3->base_even = ((vdma3->pitch/2)*height)+buf->pt[2].offset; in calc_planar_422()
488 vdma3->base_odd = vdma3->base_even - (vdma3->pitch/2); in calc_planar_422()
490 vdma3->base_even = buf->pt[2].offset; in calc_planar_422()
491 vdma3->base_odd = vdma3->base_even + (vdma3->pitch/2); in calc_planar_422()
492 vdma3->prot_addr = (vdma3->pitch/2)*height+buf->pt[2].offset; in calc_planar_422()
494 vdma2->base_even = buf->pt[1].offset; in calc_planar_422()
495 vdma2->base_odd = vdma2->base_even + (vdma2->pitch/2); in calc_planar_422()
496 vdma2->prot_addr = (vdma2->pitch/2)*height+buf->pt[1].offset; in calc_planar_422()
504 struct v4l2_pix_format *pix = &vv->video_fmt; in calc_planar_420()
505 int height = pix->height; in calc_planar_420()
506 int width = pix->width; in calc_planar_420()
508 vdma2->pitch = width/2; in calc_planar_420()
509 vdma3->pitch = width/2; in calc_planar_420()
511 if( 0 != vv->vflip ) { in calc_planar_420()
512 vdma2->prot_addr = buf->pt[2].offset; in calc_planar_420()
513 vdma2->base_even = ((vdma2->pitch/2)*height)+buf->pt[2].offset; in calc_planar_420()
514 vdma2->base_odd = vdma2->base_even - (vdma2->pitch/2); in calc_planar_420()
516 vdma3->prot_addr = buf->pt[1].offset; in calc_planar_420()
517 vdma3->base_even = ((vdma3->pitch/2)*height)+buf->pt[1].offset; in calc_planar_420()
518 vdma3->base_odd = vdma3->base_even - (vdma3->pitch/2); in calc_planar_420()
521 vdma3->base_even = buf->pt[2].offset; in calc_planar_420()
522 vdma3->base_odd = vdma3->base_even + (vdma3->pitch); in calc_planar_420()
523 vdma3->prot_addr = (vdma3->pitch/2)*height+buf->pt[2].offset; in calc_planar_420()
525 vdma2->base_even = buf->pt[1].offset; in calc_planar_420()
526 vdma2->base_odd = vdma2->base_even + (vdma2->pitch); in calc_planar_420()
527 vdma2->prot_addr = (vdma2->pitch/2)*height+buf->pt[1].offset; in calc_planar_420()
534 struct saa7146_vv *vv = dev->vv_data; in calculate_video_dma_grab_planar()
535 struct v4l2_pix_format *pix = &vv->video_fmt; in calculate_video_dma_grab_planar()
539 struct saa7146_format *sfmt = saa7146_format_by_fourcc(dev, pix->pixelformat); in calculate_video_dma_grab_planar()
541 int width = pix->width; in calculate_video_dma_grab_planar()
542 int height = pix->height; in calculate_video_dma_grab_planar()
543 enum v4l2_field field = pix->field; in calculate_video_dma_grab_planar()
545 if (WARN_ON(!buf->pt[0].dma) || in calculate_video_dma_grab_planar()
546 WARN_ON(!buf->pt[1].dma) || in calculate_video_dma_grab_planar()
547 WARN_ON(!buf->pt[2].dma)) in calculate_video_dma_grab_planar()
548 return -1; in calculate_video_dma_grab_planar()
550 DEB_CAP("[size=%dx%d,fields=%s]\n", in calculate_video_dma_grab_planar()
556 most likely wrong, this version here only works for page-aligned in calculate_video_dma_grab_planar()
557 buffers, modifications to the pagetable-functions are necessary...*/ in calculate_video_dma_grab_planar()
560 vdma1.num_line_byte = ((vv->standard->v_field<<16) + vv->standard->h_pixels); in calculate_video_dma_grab_planar()
561 vdma1.base_page = buf->pt[0].dma | ME1; in calculate_video_dma_grab_planar()
563 if( 0 != vv->vflip ) { in calculate_video_dma_grab_planar()
564 vdma1.prot_addr = buf->pt[0].offset; in calculate_video_dma_grab_planar()
565 vdma1.base_even = ((vdma1.pitch/2)*height)+buf->pt[0].offset; in calculate_video_dma_grab_planar()
566 vdma1.base_odd = vdma1.base_even - (vdma1.pitch/2); in calculate_video_dma_grab_planar()
568 vdma1.base_even = buf->pt[0].offset; in calculate_video_dma_grab_planar()
570 vdma1.prot_addr = (vdma1.pitch/2)*height+buf->pt[0].offset; in calculate_video_dma_grab_planar()
574 vdma2.base_page = buf->pt[1].dma | ME1; in calculate_video_dma_grab_planar()
577 vdma3.base_page = buf->pt[2].dma | ME1; in calculate_video_dma_grab_planar()
579 switch( sfmt->depth ) { in calculate_video_dma_grab_planar()
589 return -1; in calculate_video_dma_grab_planar()
621 if( 0 != vv->vflip ) { in calculate_video_dma_grab_planar()
622 vdma1.pitch *= -1; in calculate_video_dma_grab_planar()
623 vdma2.pitch *= -1; in calculate_video_dma_grab_planar()
624 vdma3.pitch *= -1; in calculate_video_dma_grab_planar()
628 if( (sfmt->flags & FORMAT_BYTE_SWAP) != 0 ) { in calculate_video_dma_grab_planar()
640 struct saa7146_vv *vv = dev->vv_data; in program_capture_engine()
643 unsigned long e_wait = vv->current_hps_sync == SAA7146_HPS_SYNC_PORT_A ? CMD_E_FID_A : CMD_E_FID_B; in program_capture_engine()
644 unsigned long o_wait = vv->current_hps_sync == SAA7146_HPS_SYNC_PORT_A ? CMD_O_FID_A : CMD_O_FID_B; in program_capture_engine()
654 /* turn on video-dma1 */ in program_capture_engine()
659 /* turn on video-dma2 */ in program_capture_engine()
664 /* turn on video-dma3 */ in program_capture_engine()
671 if ( vv->last_field == V4L2_FIELD_INTERLACED ) { in program_capture_engine()
674 } else if ( vv->last_field == V4L2_FIELD_TOP ) { in program_capture_engine()
675 WRITE_RPS0(CMD_PAUSE | (vv->current_hps_sync == SAA7146_HPS_SYNC_PORT_A ? MASK_10 : MASK_09)); in program_capture_engine()
677 } else if ( vv->last_field == V4L2_FIELD_BOTTOM ) { in program_capture_engine()
678 WRITE_RPS0(CMD_PAUSE | (vv->current_hps_sync == SAA7146_HPS_SYNC_PORT_A ? MASK_10 : MASK_09)); in program_capture_engine()
682 /* turn off video-dma1 */ in program_capture_engine()
687 /* turn off video-dma2 */ in program_capture_engine()
692 /* turn off video-dma3 */ in program_capture_engine()
713 /* upload clipping-registers*/ in saa7146_disable_clipping()
723 struct saa7146_vv *vv = dev->vv_data; in saa7146_set_capture()
724 struct v4l2_pix_format *pix = &vv->video_fmt; in saa7146_set_capture()
725 struct saa7146_format *sfmt = saa7146_format_by_fourcc(dev, pix->pixelformat); in saa7146_set_capture()
728 DEB_CAP("buf:%p, next:%p\n", buf, next); in saa7146_set_capture()
733 DEB_CAP("forcing sync to new frame\n"); in saa7146_set_capture()
737 saa7146_set_window(dev, pix->width, pix->height, pix->field); in saa7146_set_capture()
738 saa7146_set_output_format(dev, sfmt->trans); in saa7146_set_capture()
741 if ( vv->last_field == V4L2_FIELD_INTERLACED ) { in saa7146_set_capture()
742 } else if ( vv->last_field == V4L2_FIELD_TOP ) { in saa7146_set_capture()
743 vv->last_field = V4L2_FIELD_BOTTOM; in saa7146_set_capture()
744 } else if ( vv->last_field == V4L2_FIELD_BOTTOM ) { in saa7146_set_capture()
745 vv->last_field = V4L2_FIELD_TOP; in saa7146_set_capture()
748 if( 0 != IS_PLANAR(sfmt->trans)) { in saa7146_set_capture()
757 printk("vdma%d.base_even: 0x%08x\n", 1,saa7146_read(dev,BASE_EVEN1)); in saa7146_set_capture()
758 printk("vdma%d.base_odd: 0x%08x\n", 1,saa7146_read(dev,BASE_ODD1)); in saa7146_set_capture()
759 printk("vdma%d.prot_addr: 0x%08x\n", 1,saa7146_read(dev,PROT_ADDR1)); in saa7146_set_capture()
760 printk("vdma%d.base_page: 0x%08x\n", 1,saa7146_read(dev,BASE_PAGE1)); in saa7146_set_capture()
761 printk("vdma%d.pitch: 0x%08x\n", 1,saa7146_read(dev,PITCH1)); in saa7146_set_capture()
762 printk("vdma%d.num_line_byte: 0x%08x\n", 1,saa7146_read(dev,NUM_LINE_BYTE1)); in saa7146_set_capture()
763 printk("vdma%d => vptr : 0x%08x\n", 1,saa7146_read(dev,PCI_VDP1)); in saa7146_set_capture()
766 /* write the address of the rps-program */ in saa7146_set_capture()
767 saa7146_write(dev, RPS_ADDR0, dev->d_rps0.dma_handle); in saa7146_set_capture()