162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci yuv support 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci Copyright (C) 2007 Ian Armstrong <ian@iarmst.demon.co.uk> 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci */ 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci#include "ivtv-driver.h" 1062306a36Sopenharmony_ci#include "ivtv-udma.h" 1162306a36Sopenharmony_ci#include "ivtv-yuv.h" 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ci/* YUV buffer offsets */ 1462306a36Sopenharmony_ciconst u32 yuv_offset[IVTV_YUV_BUFFERS] = { 1562306a36Sopenharmony_ci 0x001a8600, 1662306a36Sopenharmony_ci 0x00240400, 1762306a36Sopenharmony_ci 0x002d8200, 1862306a36Sopenharmony_ci 0x00370000, 1962306a36Sopenharmony_ci 0x00029000, 2062306a36Sopenharmony_ci 0x000C0E00, 2162306a36Sopenharmony_ci 0x006B0400, 2262306a36Sopenharmony_ci 0x00748200 2362306a36Sopenharmony_ci}; 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_cistatic int ivtv_yuv_prep_user_dma(struct ivtv *itv, struct ivtv_user_dma *dma, 2662306a36Sopenharmony_ci struct ivtv_dma_frame *args) 2762306a36Sopenharmony_ci{ 2862306a36Sopenharmony_ci struct ivtv_dma_page_info y_dma; 2962306a36Sopenharmony_ci struct ivtv_dma_page_info uv_dma; 3062306a36Sopenharmony_ci struct yuv_playback_info *yi = &itv->yuv_info; 3162306a36Sopenharmony_ci u8 frame = yi->draw_frame; 3262306a36Sopenharmony_ci struct yuv_frame_info *f = &yi->new_frame_info[frame]; 3362306a36Sopenharmony_ci int y_pages, uv_pages; 3462306a36Sopenharmony_ci unsigned long y_buffer_offset, uv_buffer_offset; 3562306a36Sopenharmony_ci int y_decode_height, uv_decode_height, y_size; 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_ci y_buffer_offset = IVTV_DECODER_OFFSET + yuv_offset[frame]; 3862306a36Sopenharmony_ci uv_buffer_offset = y_buffer_offset + IVTV_YUV_BUFFER_UV_OFFSET; 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ci y_decode_height = uv_decode_height = f->src_h + f->src_y; 4162306a36Sopenharmony_ci 4262306a36Sopenharmony_ci if (f->offset_y) 4362306a36Sopenharmony_ci y_buffer_offset += 720 * 16; 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_ci if (y_decode_height & 15) 4662306a36Sopenharmony_ci y_decode_height = (y_decode_height + 16) & ~15; 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ci if (uv_decode_height & 31) 4962306a36Sopenharmony_ci uv_decode_height = (uv_decode_height + 32) & ~31; 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_ci y_size = 720 * y_decode_height; 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ci /* Still in USE */ 5462306a36Sopenharmony_ci if (dma->SG_length || dma->page_count) { 5562306a36Sopenharmony_ci IVTV_DEBUG_WARN 5662306a36Sopenharmony_ci ("prep_user_dma: SG_length %d page_count %d still full?\n", 5762306a36Sopenharmony_ci dma->SG_length, dma->page_count); 5862306a36Sopenharmony_ci return -EBUSY; 5962306a36Sopenharmony_ci } 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_ci ivtv_udma_get_page_info (&y_dma, (unsigned long)args->y_source, 720 * y_decode_height); 6262306a36Sopenharmony_ci ivtv_udma_get_page_info (&uv_dma, (unsigned long)args->uv_source, 360 * uv_decode_height); 6362306a36Sopenharmony_ci 6462306a36Sopenharmony_ci /* Pin user pages for DMA Xfer */ 6562306a36Sopenharmony_ci y_pages = pin_user_pages_unlocked(y_dma.uaddr, 6662306a36Sopenharmony_ci y_dma.page_count, &dma->map[0], 0); 6762306a36Sopenharmony_ci uv_pages = 0; /* silence gcc. value is set and consumed only if: */ 6862306a36Sopenharmony_ci if (y_pages == y_dma.page_count) { 6962306a36Sopenharmony_ci uv_pages = pin_user_pages_unlocked(uv_dma.uaddr, 7062306a36Sopenharmony_ci uv_dma.page_count, &dma->map[y_pages], 0); 7162306a36Sopenharmony_ci } 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ci if (y_pages != y_dma.page_count || uv_pages != uv_dma.page_count) { 7462306a36Sopenharmony_ci int rc = -EFAULT; 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ci if (y_pages == y_dma.page_count) { 7762306a36Sopenharmony_ci IVTV_DEBUG_WARN 7862306a36Sopenharmony_ci ("failed to map uv user pages, returned %d expecting %d\n", 7962306a36Sopenharmony_ci uv_pages, uv_dma.page_count); 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ci if (uv_pages >= 0) { 8262306a36Sopenharmony_ci unpin_user_pages(&dma->map[y_pages], uv_pages); 8362306a36Sopenharmony_ci rc = -EFAULT; 8462306a36Sopenharmony_ci } else { 8562306a36Sopenharmony_ci rc = uv_pages; 8662306a36Sopenharmony_ci } 8762306a36Sopenharmony_ci } else { 8862306a36Sopenharmony_ci IVTV_DEBUG_WARN 8962306a36Sopenharmony_ci ("failed to map y user pages, returned %d expecting %d\n", 9062306a36Sopenharmony_ci y_pages, y_dma.page_count); 9162306a36Sopenharmony_ci } 9262306a36Sopenharmony_ci if (y_pages >= 0) { 9362306a36Sopenharmony_ci unpin_user_pages(dma->map, y_pages); 9462306a36Sopenharmony_ci /* 9562306a36Sopenharmony_ci * Inherit the -EFAULT from rc's 9662306a36Sopenharmony_ci * initialization, but allow it to be 9762306a36Sopenharmony_ci * overridden by uv_pages above if it was an 9862306a36Sopenharmony_ci * actual errno. 9962306a36Sopenharmony_ci */ 10062306a36Sopenharmony_ci } else { 10162306a36Sopenharmony_ci rc = y_pages; 10262306a36Sopenharmony_ci } 10362306a36Sopenharmony_ci return rc; 10462306a36Sopenharmony_ci } 10562306a36Sopenharmony_ci 10662306a36Sopenharmony_ci dma->page_count = y_pages + uv_pages; 10762306a36Sopenharmony_ci 10862306a36Sopenharmony_ci /* Fill & map SG List */ 10962306a36Sopenharmony_ci if (ivtv_udma_fill_sg_list (dma, &uv_dma, ivtv_udma_fill_sg_list (dma, &y_dma, 0)) < 0) { 11062306a36Sopenharmony_ci IVTV_DEBUG_WARN("could not allocate bounce buffers for highmem userspace buffers\n"); 11162306a36Sopenharmony_ci unpin_user_pages(dma->map, dma->page_count); 11262306a36Sopenharmony_ci dma->page_count = 0; 11362306a36Sopenharmony_ci return -ENOMEM; 11462306a36Sopenharmony_ci } 11562306a36Sopenharmony_ci dma->SG_length = dma_map_sg(&itv->pdev->dev, dma->SGlist, 11662306a36Sopenharmony_ci dma->page_count, DMA_TO_DEVICE); 11762306a36Sopenharmony_ci 11862306a36Sopenharmony_ci /* Fill SG Array with new values */ 11962306a36Sopenharmony_ci ivtv_udma_fill_sg_array(dma, y_buffer_offset, uv_buffer_offset, y_size); 12062306a36Sopenharmony_ci 12162306a36Sopenharmony_ci /* If we've offset the y plane, ensure top area is blanked */ 12262306a36Sopenharmony_ci if (f->offset_y && yi->blanking_dmaptr) { 12362306a36Sopenharmony_ci dma->SGarray[dma->SG_length].size = cpu_to_le32(720*16); 12462306a36Sopenharmony_ci dma->SGarray[dma->SG_length].src = cpu_to_le32(yi->blanking_dmaptr); 12562306a36Sopenharmony_ci dma->SGarray[dma->SG_length].dst = cpu_to_le32(IVTV_DECODER_OFFSET + yuv_offset[frame]); 12662306a36Sopenharmony_ci dma->SG_length++; 12762306a36Sopenharmony_ci } 12862306a36Sopenharmony_ci 12962306a36Sopenharmony_ci /* Tag SG Array with Interrupt Bit */ 13062306a36Sopenharmony_ci dma->SGarray[dma->SG_length - 1].size |= cpu_to_le32(0x80000000); 13162306a36Sopenharmony_ci 13262306a36Sopenharmony_ci ivtv_udma_sync_for_device(itv); 13362306a36Sopenharmony_ci return 0; 13462306a36Sopenharmony_ci} 13562306a36Sopenharmony_ci 13662306a36Sopenharmony_ci/* We rely on a table held in the firmware - Quick check. */ 13762306a36Sopenharmony_ciint ivtv_yuv_filter_check(struct ivtv *itv) 13862306a36Sopenharmony_ci{ 13962306a36Sopenharmony_ci int i, y, uv; 14062306a36Sopenharmony_ci 14162306a36Sopenharmony_ci for (i = 0, y = 16, uv = 4; i < 16; i++, y += 24, uv += 12) { 14262306a36Sopenharmony_ci if ((read_dec(IVTV_YUV_HORIZONTAL_FILTER_OFFSET + y) != i << 16) || 14362306a36Sopenharmony_ci (read_dec(IVTV_YUV_VERTICAL_FILTER_OFFSET + uv) != i << 16)) { 14462306a36Sopenharmony_ci IVTV_WARN ("YUV filter table not found in firmware.\n"); 14562306a36Sopenharmony_ci return -1; 14662306a36Sopenharmony_ci } 14762306a36Sopenharmony_ci } 14862306a36Sopenharmony_ci return 0; 14962306a36Sopenharmony_ci} 15062306a36Sopenharmony_ci 15162306a36Sopenharmony_cistatic void ivtv_yuv_filter(struct ivtv *itv, int h_filter, int v_filter_1, int v_filter_2) 15262306a36Sopenharmony_ci{ 15362306a36Sopenharmony_ci u32 i, line; 15462306a36Sopenharmony_ci 15562306a36Sopenharmony_ci /* If any filter is -1, then don't update it */ 15662306a36Sopenharmony_ci if (h_filter > -1) { 15762306a36Sopenharmony_ci if (h_filter > 4) 15862306a36Sopenharmony_ci h_filter = 4; 15962306a36Sopenharmony_ci i = IVTV_YUV_HORIZONTAL_FILTER_OFFSET + (h_filter * 384); 16062306a36Sopenharmony_ci for (line = 0; line < 16; line++) { 16162306a36Sopenharmony_ci write_reg(read_dec(i), 0x02804); 16262306a36Sopenharmony_ci write_reg(read_dec(i), 0x0281c); 16362306a36Sopenharmony_ci i += 4; 16462306a36Sopenharmony_ci write_reg(read_dec(i), 0x02808); 16562306a36Sopenharmony_ci write_reg(read_dec(i), 0x02820); 16662306a36Sopenharmony_ci i += 4; 16762306a36Sopenharmony_ci write_reg(read_dec(i), 0x0280c); 16862306a36Sopenharmony_ci write_reg(read_dec(i), 0x02824); 16962306a36Sopenharmony_ci i += 4; 17062306a36Sopenharmony_ci write_reg(read_dec(i), 0x02810); 17162306a36Sopenharmony_ci write_reg(read_dec(i), 0x02828); 17262306a36Sopenharmony_ci i += 4; 17362306a36Sopenharmony_ci write_reg(read_dec(i), 0x02814); 17462306a36Sopenharmony_ci write_reg(read_dec(i), 0x0282c); 17562306a36Sopenharmony_ci i += 8; 17662306a36Sopenharmony_ci write_reg(0, 0x02818); 17762306a36Sopenharmony_ci write_reg(0, 0x02830); 17862306a36Sopenharmony_ci } 17962306a36Sopenharmony_ci IVTV_DEBUG_YUV("h_filter -> %d\n", h_filter); 18062306a36Sopenharmony_ci } 18162306a36Sopenharmony_ci 18262306a36Sopenharmony_ci if (v_filter_1 > -1) { 18362306a36Sopenharmony_ci if (v_filter_1 > 4) 18462306a36Sopenharmony_ci v_filter_1 = 4; 18562306a36Sopenharmony_ci i = IVTV_YUV_VERTICAL_FILTER_OFFSET + (v_filter_1 * 192); 18662306a36Sopenharmony_ci for (line = 0; line < 16; line++) { 18762306a36Sopenharmony_ci write_reg(read_dec(i), 0x02900); 18862306a36Sopenharmony_ci i += 4; 18962306a36Sopenharmony_ci write_reg(read_dec(i), 0x02904); 19062306a36Sopenharmony_ci i += 8; 19162306a36Sopenharmony_ci write_reg(0, 0x02908); 19262306a36Sopenharmony_ci } 19362306a36Sopenharmony_ci IVTV_DEBUG_YUV("v_filter_1 -> %d\n", v_filter_1); 19462306a36Sopenharmony_ci } 19562306a36Sopenharmony_ci 19662306a36Sopenharmony_ci if (v_filter_2 > -1) { 19762306a36Sopenharmony_ci if (v_filter_2 > 4) 19862306a36Sopenharmony_ci v_filter_2 = 4; 19962306a36Sopenharmony_ci i = IVTV_YUV_VERTICAL_FILTER_OFFSET + (v_filter_2 * 192); 20062306a36Sopenharmony_ci for (line = 0; line < 16; line++) { 20162306a36Sopenharmony_ci write_reg(read_dec(i), 0x0290c); 20262306a36Sopenharmony_ci i += 4; 20362306a36Sopenharmony_ci write_reg(read_dec(i), 0x02910); 20462306a36Sopenharmony_ci i += 8; 20562306a36Sopenharmony_ci write_reg(0, 0x02914); 20662306a36Sopenharmony_ci } 20762306a36Sopenharmony_ci IVTV_DEBUG_YUV("v_filter_2 -> %d\n", v_filter_2); 20862306a36Sopenharmony_ci } 20962306a36Sopenharmony_ci} 21062306a36Sopenharmony_ci 21162306a36Sopenharmony_cistatic void ivtv_yuv_handle_horizontal(struct ivtv *itv, struct yuv_frame_info *f) 21262306a36Sopenharmony_ci{ 21362306a36Sopenharmony_ci struct yuv_playback_info *yi = &itv->yuv_info; 21462306a36Sopenharmony_ci u32 reg_2834, reg_2838, reg_283c; 21562306a36Sopenharmony_ci u32 reg_2844, reg_2854, reg_285c; 21662306a36Sopenharmony_ci u32 reg_2864, reg_2874, reg_2890; 21762306a36Sopenharmony_ci u32 reg_2870, reg_2870_base, reg_2870_offset; 21862306a36Sopenharmony_ci int x_cutoff; 21962306a36Sopenharmony_ci int h_filter; 22062306a36Sopenharmony_ci u32 master_width; 22162306a36Sopenharmony_ci 22262306a36Sopenharmony_ci IVTV_DEBUG_WARN 22362306a36Sopenharmony_ci ("Adjust to width %d src_w %d dst_w %d src_x %d dst_x %d\n", 22462306a36Sopenharmony_ci f->tru_w, f->src_w, f->dst_w, f->src_x, f->dst_x); 22562306a36Sopenharmony_ci 22662306a36Sopenharmony_ci /* How wide is the src image */ 22762306a36Sopenharmony_ci x_cutoff = f->src_w + f->src_x; 22862306a36Sopenharmony_ci 22962306a36Sopenharmony_ci /* Set the display width */ 23062306a36Sopenharmony_ci reg_2834 = f->dst_w; 23162306a36Sopenharmony_ci reg_2838 = reg_2834; 23262306a36Sopenharmony_ci 23362306a36Sopenharmony_ci /* Set the display position */ 23462306a36Sopenharmony_ci reg_2890 = f->dst_x; 23562306a36Sopenharmony_ci 23662306a36Sopenharmony_ci /* Index into the image horizontally */ 23762306a36Sopenharmony_ci reg_2870 = 0; 23862306a36Sopenharmony_ci 23962306a36Sopenharmony_ci /* 2870 is normally fudged to align video coords with osd coords. 24062306a36Sopenharmony_ci If running full screen, it causes an unwanted left shift 24162306a36Sopenharmony_ci Remove the fudge if we almost fill the screen. 24262306a36Sopenharmony_ci Gradually adjust the offset to avoid the video 'snapping' 24362306a36Sopenharmony_ci left/right if it gets dragged through this region. 24462306a36Sopenharmony_ci Only do this if osd is full width. */ 24562306a36Sopenharmony_ci if (f->vis_w == 720) { 24662306a36Sopenharmony_ci if ((f->tru_x - f->pan_x > -1) && (f->tru_x - f->pan_x <= 40) && (f->dst_w >= 680)) 24762306a36Sopenharmony_ci reg_2870 = 10 - (f->tru_x - f->pan_x) / 4; 24862306a36Sopenharmony_ci else if ((f->tru_x - f->pan_x < 0) && (f->tru_x - f->pan_x >= -20) && (f->dst_w >= 660)) 24962306a36Sopenharmony_ci reg_2870 = (10 + (f->tru_x - f->pan_x) / 2); 25062306a36Sopenharmony_ci 25162306a36Sopenharmony_ci if (f->dst_w >= f->src_w) 25262306a36Sopenharmony_ci reg_2870 = reg_2870 << 16 | reg_2870; 25362306a36Sopenharmony_ci else 25462306a36Sopenharmony_ci reg_2870 = ((reg_2870 & ~1) << 15) | (reg_2870 & ~1); 25562306a36Sopenharmony_ci } 25662306a36Sopenharmony_ci 25762306a36Sopenharmony_ci if (f->dst_w < f->src_w) 25862306a36Sopenharmony_ci reg_2870 = 0x000d000e - reg_2870; 25962306a36Sopenharmony_ci else 26062306a36Sopenharmony_ci reg_2870 = 0x0012000e - reg_2870; 26162306a36Sopenharmony_ci 26262306a36Sopenharmony_ci /* We're also using 2870 to shift the image left (src_x & negative dst_x) */ 26362306a36Sopenharmony_ci reg_2870_offset = (f->src_x * ((f->dst_w << 21) / f->src_w)) >> 19; 26462306a36Sopenharmony_ci 26562306a36Sopenharmony_ci if (f->dst_w >= f->src_w) { 26662306a36Sopenharmony_ci x_cutoff &= ~1; 26762306a36Sopenharmony_ci master_width = (f->src_w * 0x00200000) / (f->dst_w); 26862306a36Sopenharmony_ci if (master_width * f->dst_w != f->src_w * 0x00200000) 26962306a36Sopenharmony_ci master_width++; 27062306a36Sopenharmony_ci reg_2834 = (reg_2834 << 16) | x_cutoff; 27162306a36Sopenharmony_ci reg_2838 = (reg_2838 << 16) | x_cutoff; 27262306a36Sopenharmony_ci reg_283c = master_width >> 2; 27362306a36Sopenharmony_ci reg_2844 = master_width >> 2; 27462306a36Sopenharmony_ci reg_2854 = master_width; 27562306a36Sopenharmony_ci reg_285c = master_width >> 1; 27662306a36Sopenharmony_ci reg_2864 = master_width >> 1; 27762306a36Sopenharmony_ci 27862306a36Sopenharmony_ci /* We also need to factor in the scaling 27962306a36Sopenharmony_ci (src_w - dst_w) / (src_w / 4) */ 28062306a36Sopenharmony_ci if (f->dst_w > f->src_w) 28162306a36Sopenharmony_ci reg_2870_base = ((f->dst_w - f->src_w)<<16) / (f->src_w <<14); 28262306a36Sopenharmony_ci else 28362306a36Sopenharmony_ci reg_2870_base = 0; 28462306a36Sopenharmony_ci 28562306a36Sopenharmony_ci reg_2870 += (((reg_2870_offset << 14) & 0xFFFF0000) | reg_2870_offset >> 2) + (reg_2870_base << 17 | reg_2870_base); 28662306a36Sopenharmony_ci reg_2874 = 0; 28762306a36Sopenharmony_ci } else if (f->dst_w < f->src_w / 2) { 28862306a36Sopenharmony_ci master_width = (f->src_w * 0x00080000) / f->dst_w; 28962306a36Sopenharmony_ci if (master_width * f->dst_w != f->src_w * 0x00080000) 29062306a36Sopenharmony_ci master_width++; 29162306a36Sopenharmony_ci reg_2834 = (reg_2834 << 16) | x_cutoff; 29262306a36Sopenharmony_ci reg_2838 = (reg_2838 << 16) | x_cutoff; 29362306a36Sopenharmony_ci reg_283c = master_width >> 2; 29462306a36Sopenharmony_ci reg_2844 = master_width >> 1; 29562306a36Sopenharmony_ci reg_2854 = master_width; 29662306a36Sopenharmony_ci reg_285c = master_width >> 1; 29762306a36Sopenharmony_ci reg_2864 = master_width >> 1; 29862306a36Sopenharmony_ci reg_2870 += ((reg_2870_offset << 15) & 0xFFFF0000) | reg_2870_offset; 29962306a36Sopenharmony_ci reg_2870 += (5 - (((f->src_w + f->src_w / 2) - 1) / f->dst_w)) << 16; 30062306a36Sopenharmony_ci reg_2874 = 0x00000012; 30162306a36Sopenharmony_ci } else { 30262306a36Sopenharmony_ci master_width = (f->src_w * 0x00100000) / f->dst_w; 30362306a36Sopenharmony_ci if (master_width * f->dst_w != f->src_w * 0x00100000) 30462306a36Sopenharmony_ci master_width++; 30562306a36Sopenharmony_ci reg_2834 = (reg_2834 << 16) | x_cutoff; 30662306a36Sopenharmony_ci reg_2838 = (reg_2838 << 16) | x_cutoff; 30762306a36Sopenharmony_ci reg_283c = master_width >> 2; 30862306a36Sopenharmony_ci reg_2844 = master_width >> 1; 30962306a36Sopenharmony_ci reg_2854 = master_width; 31062306a36Sopenharmony_ci reg_285c = master_width >> 1; 31162306a36Sopenharmony_ci reg_2864 = master_width >> 1; 31262306a36Sopenharmony_ci reg_2870 += ((reg_2870_offset << 14) & 0xFFFF0000) | reg_2870_offset >> 1; 31362306a36Sopenharmony_ci reg_2870 += (5 - (((f->src_w * 3) - 1) / f->dst_w)) << 16; 31462306a36Sopenharmony_ci reg_2874 = 0x00000001; 31562306a36Sopenharmony_ci } 31662306a36Sopenharmony_ci 31762306a36Sopenharmony_ci /* Select the horizontal filter */ 31862306a36Sopenharmony_ci if (f->src_w == f->dst_w) { 31962306a36Sopenharmony_ci /* An exact size match uses filter 0 */ 32062306a36Sopenharmony_ci h_filter = 0; 32162306a36Sopenharmony_ci } else { 32262306a36Sopenharmony_ci /* Figure out which filter to use */ 32362306a36Sopenharmony_ci h_filter = ((f->src_w << 16) / f->dst_w) >> 15; 32462306a36Sopenharmony_ci h_filter = (h_filter >> 1) + (h_filter & 1); 32562306a36Sopenharmony_ci /* Only an exact size match can use filter 0 */ 32662306a36Sopenharmony_ci h_filter += !h_filter; 32762306a36Sopenharmony_ci } 32862306a36Sopenharmony_ci 32962306a36Sopenharmony_ci write_reg(reg_2834, 0x02834); 33062306a36Sopenharmony_ci write_reg(reg_2838, 0x02838); 33162306a36Sopenharmony_ci IVTV_DEBUG_YUV("Update reg 0x2834 %08x->%08x 0x2838 %08x->%08x\n", 33262306a36Sopenharmony_ci yi->reg_2834, reg_2834, yi->reg_2838, reg_2838); 33362306a36Sopenharmony_ci 33462306a36Sopenharmony_ci write_reg(reg_283c, 0x0283c); 33562306a36Sopenharmony_ci write_reg(reg_2844, 0x02844); 33662306a36Sopenharmony_ci 33762306a36Sopenharmony_ci IVTV_DEBUG_YUV("Update reg 0x283c %08x->%08x 0x2844 %08x->%08x\n", 33862306a36Sopenharmony_ci yi->reg_283c, reg_283c, yi->reg_2844, reg_2844); 33962306a36Sopenharmony_ci 34062306a36Sopenharmony_ci write_reg(0x00080514, 0x02840); 34162306a36Sopenharmony_ci write_reg(0x00100514, 0x02848); 34262306a36Sopenharmony_ci IVTV_DEBUG_YUV("Update reg 0x2840 %08x->%08x 0x2848 %08x->%08x\n", 34362306a36Sopenharmony_ci yi->reg_2840, 0x00080514, yi->reg_2848, 0x00100514); 34462306a36Sopenharmony_ci 34562306a36Sopenharmony_ci write_reg(reg_2854, 0x02854); 34662306a36Sopenharmony_ci IVTV_DEBUG_YUV("Update reg 0x2854 %08x->%08x \n", 34762306a36Sopenharmony_ci yi->reg_2854, reg_2854); 34862306a36Sopenharmony_ci 34962306a36Sopenharmony_ci write_reg(reg_285c, 0x0285c); 35062306a36Sopenharmony_ci write_reg(reg_2864, 0x02864); 35162306a36Sopenharmony_ci IVTV_DEBUG_YUV("Update reg 0x285c %08x->%08x 0x2864 %08x->%08x\n", 35262306a36Sopenharmony_ci yi->reg_285c, reg_285c, yi->reg_2864, reg_2864); 35362306a36Sopenharmony_ci 35462306a36Sopenharmony_ci write_reg(reg_2874, 0x02874); 35562306a36Sopenharmony_ci IVTV_DEBUG_YUV("Update reg 0x2874 %08x->%08x\n", 35662306a36Sopenharmony_ci yi->reg_2874, reg_2874); 35762306a36Sopenharmony_ci 35862306a36Sopenharmony_ci write_reg(reg_2870, 0x02870); 35962306a36Sopenharmony_ci IVTV_DEBUG_YUV("Update reg 0x2870 %08x->%08x\n", 36062306a36Sopenharmony_ci yi->reg_2870, reg_2870); 36162306a36Sopenharmony_ci 36262306a36Sopenharmony_ci write_reg(reg_2890, 0x02890); 36362306a36Sopenharmony_ci IVTV_DEBUG_YUV("Update reg 0x2890 %08x->%08x\n", 36462306a36Sopenharmony_ci yi->reg_2890, reg_2890); 36562306a36Sopenharmony_ci 36662306a36Sopenharmony_ci /* Only update the filter if we really need to */ 36762306a36Sopenharmony_ci if (h_filter != yi->h_filter) { 36862306a36Sopenharmony_ci ivtv_yuv_filter(itv, h_filter, -1, -1); 36962306a36Sopenharmony_ci yi->h_filter = h_filter; 37062306a36Sopenharmony_ci } 37162306a36Sopenharmony_ci} 37262306a36Sopenharmony_ci 37362306a36Sopenharmony_cistatic void ivtv_yuv_handle_vertical(struct ivtv *itv, struct yuv_frame_info *f) 37462306a36Sopenharmony_ci{ 37562306a36Sopenharmony_ci struct yuv_playback_info *yi = &itv->yuv_info; 37662306a36Sopenharmony_ci u32 master_height; 37762306a36Sopenharmony_ci u32 reg_2918, reg_291c, reg_2920, reg_2928; 37862306a36Sopenharmony_ci u32 reg_2930, reg_2934, reg_293c; 37962306a36Sopenharmony_ci u32 reg_2940, reg_2944, reg_294c; 38062306a36Sopenharmony_ci u32 reg_2950, reg_2954, reg_2958, reg_295c; 38162306a36Sopenharmony_ci u32 reg_2960, reg_2964, reg_2968, reg_296c; 38262306a36Sopenharmony_ci u32 reg_289c; 38362306a36Sopenharmony_ci u32 src_major_y, src_minor_y; 38462306a36Sopenharmony_ci u32 src_major_uv, src_minor_uv; 38562306a36Sopenharmony_ci u32 reg_2964_base, reg_2968_base; 38662306a36Sopenharmony_ci int v_filter_1, v_filter_2; 38762306a36Sopenharmony_ci 38862306a36Sopenharmony_ci IVTV_DEBUG_WARN 38962306a36Sopenharmony_ci ("Adjust to height %d src_h %d dst_h %d src_y %d dst_y %d\n", 39062306a36Sopenharmony_ci f->tru_h, f->src_h, f->dst_h, f->src_y, f->dst_y); 39162306a36Sopenharmony_ci 39262306a36Sopenharmony_ci /* What scaling mode is being used... */ 39362306a36Sopenharmony_ci IVTV_DEBUG_YUV("Scaling mode Y: %s\n", 39462306a36Sopenharmony_ci f->interlaced_y ? "Interlaced" : "Progressive"); 39562306a36Sopenharmony_ci 39662306a36Sopenharmony_ci IVTV_DEBUG_YUV("Scaling mode UV: %s\n", 39762306a36Sopenharmony_ci f->interlaced_uv ? "Interlaced" : "Progressive"); 39862306a36Sopenharmony_ci 39962306a36Sopenharmony_ci /* What is the source video being treated as... */ 40062306a36Sopenharmony_ci IVTV_DEBUG_WARN("Source video: %s\n", 40162306a36Sopenharmony_ci f->interlaced ? "Interlaced" : "Progressive"); 40262306a36Sopenharmony_ci 40362306a36Sopenharmony_ci /* We offset into the image using two different index methods, so split 40462306a36Sopenharmony_ci the y source coord into two parts. */ 40562306a36Sopenharmony_ci if (f->src_y < 8) { 40662306a36Sopenharmony_ci src_minor_uv = f->src_y; 40762306a36Sopenharmony_ci src_major_uv = 0; 40862306a36Sopenharmony_ci } else { 40962306a36Sopenharmony_ci src_minor_uv = 8; 41062306a36Sopenharmony_ci src_major_uv = f->src_y - 8; 41162306a36Sopenharmony_ci } 41262306a36Sopenharmony_ci 41362306a36Sopenharmony_ci src_minor_y = src_minor_uv; 41462306a36Sopenharmony_ci src_major_y = src_major_uv; 41562306a36Sopenharmony_ci 41662306a36Sopenharmony_ci if (f->offset_y) 41762306a36Sopenharmony_ci src_minor_y += 16; 41862306a36Sopenharmony_ci 41962306a36Sopenharmony_ci if (f->interlaced_y) 42062306a36Sopenharmony_ci reg_2918 = (f->dst_h << 16) | (f->src_h + src_minor_y); 42162306a36Sopenharmony_ci else 42262306a36Sopenharmony_ci reg_2918 = (f->dst_h << 16) | ((f->src_h + src_minor_y) << 1); 42362306a36Sopenharmony_ci 42462306a36Sopenharmony_ci if (f->interlaced_uv) 42562306a36Sopenharmony_ci reg_291c = (f->dst_h << 16) | ((f->src_h + src_minor_uv) >> 1); 42662306a36Sopenharmony_ci else 42762306a36Sopenharmony_ci reg_291c = (f->dst_h << 16) | (f->src_h + src_minor_uv); 42862306a36Sopenharmony_ci 42962306a36Sopenharmony_ci reg_2964_base = (src_minor_y * ((f->dst_h << 16) / f->src_h)) >> 14; 43062306a36Sopenharmony_ci reg_2968_base = (src_minor_uv * ((f->dst_h << 16) / f->src_h)) >> 14; 43162306a36Sopenharmony_ci 43262306a36Sopenharmony_ci if (f->dst_h / 2 >= f->src_h && !f->interlaced_y) { 43362306a36Sopenharmony_ci master_height = (f->src_h * 0x00400000) / f->dst_h; 43462306a36Sopenharmony_ci if ((f->src_h * 0x00400000) - (master_height * f->dst_h) >= f->dst_h / 2) 43562306a36Sopenharmony_ci master_height++; 43662306a36Sopenharmony_ci reg_2920 = master_height >> 2; 43762306a36Sopenharmony_ci reg_2928 = master_height >> 3; 43862306a36Sopenharmony_ci reg_2930 = master_height; 43962306a36Sopenharmony_ci reg_2940 = master_height >> 1; 44062306a36Sopenharmony_ci reg_2964_base >>= 3; 44162306a36Sopenharmony_ci reg_2968_base >>= 3; 44262306a36Sopenharmony_ci reg_296c = 0x00000000; 44362306a36Sopenharmony_ci } else if (f->dst_h >= f->src_h) { 44462306a36Sopenharmony_ci master_height = (f->src_h * 0x00400000) / f->dst_h; 44562306a36Sopenharmony_ci master_height = (master_height >> 1) + (master_height & 1); 44662306a36Sopenharmony_ci reg_2920 = master_height >> 2; 44762306a36Sopenharmony_ci reg_2928 = master_height >> 2; 44862306a36Sopenharmony_ci reg_2930 = master_height; 44962306a36Sopenharmony_ci reg_2940 = master_height >> 1; 45062306a36Sopenharmony_ci reg_296c = 0x00000000; 45162306a36Sopenharmony_ci if (f->interlaced_y) { 45262306a36Sopenharmony_ci reg_2964_base >>= 3; 45362306a36Sopenharmony_ci } else { 45462306a36Sopenharmony_ci reg_296c++; 45562306a36Sopenharmony_ci reg_2964_base >>= 2; 45662306a36Sopenharmony_ci } 45762306a36Sopenharmony_ci if (f->interlaced_uv) 45862306a36Sopenharmony_ci reg_2928 >>= 1; 45962306a36Sopenharmony_ci reg_2968_base >>= 3; 46062306a36Sopenharmony_ci } else if (f->dst_h >= f->src_h / 2) { 46162306a36Sopenharmony_ci master_height = (f->src_h * 0x00200000) / f->dst_h; 46262306a36Sopenharmony_ci master_height = (master_height >> 1) + (master_height & 1); 46362306a36Sopenharmony_ci reg_2920 = master_height >> 2; 46462306a36Sopenharmony_ci reg_2928 = master_height >> 2; 46562306a36Sopenharmony_ci reg_2930 = master_height; 46662306a36Sopenharmony_ci reg_2940 = master_height; 46762306a36Sopenharmony_ci reg_296c = 0x00000101; 46862306a36Sopenharmony_ci if (f->interlaced_y) { 46962306a36Sopenharmony_ci reg_2964_base >>= 2; 47062306a36Sopenharmony_ci } else { 47162306a36Sopenharmony_ci reg_296c++; 47262306a36Sopenharmony_ci reg_2964_base >>= 1; 47362306a36Sopenharmony_ci } 47462306a36Sopenharmony_ci if (f->interlaced_uv) 47562306a36Sopenharmony_ci reg_2928 >>= 1; 47662306a36Sopenharmony_ci reg_2968_base >>= 2; 47762306a36Sopenharmony_ci } else { 47862306a36Sopenharmony_ci master_height = (f->src_h * 0x00100000) / f->dst_h; 47962306a36Sopenharmony_ci master_height = (master_height >> 1) + (master_height & 1); 48062306a36Sopenharmony_ci reg_2920 = master_height >> 2; 48162306a36Sopenharmony_ci reg_2928 = master_height >> 2; 48262306a36Sopenharmony_ci reg_2930 = master_height; 48362306a36Sopenharmony_ci reg_2940 = master_height; 48462306a36Sopenharmony_ci reg_2964_base >>= 1; 48562306a36Sopenharmony_ci reg_2968_base >>= 2; 48662306a36Sopenharmony_ci reg_296c = 0x00000102; 48762306a36Sopenharmony_ci } 48862306a36Sopenharmony_ci 48962306a36Sopenharmony_ci /* FIXME These registers change depending on scaled / unscaled output 49062306a36Sopenharmony_ci We really need to work out what they should be */ 49162306a36Sopenharmony_ci if (f->src_h == f->dst_h) { 49262306a36Sopenharmony_ci reg_2934 = 0x00020000; 49362306a36Sopenharmony_ci reg_293c = 0x00100000; 49462306a36Sopenharmony_ci reg_2944 = 0x00040000; 49562306a36Sopenharmony_ci reg_294c = 0x000b0000; 49662306a36Sopenharmony_ci } else { 49762306a36Sopenharmony_ci reg_2934 = 0x00000FF0; 49862306a36Sopenharmony_ci reg_293c = 0x00000FF0; 49962306a36Sopenharmony_ci reg_2944 = 0x00000FF0; 50062306a36Sopenharmony_ci reg_294c = 0x00000FF0; 50162306a36Sopenharmony_ci } 50262306a36Sopenharmony_ci 50362306a36Sopenharmony_ci /* The first line to be displayed */ 50462306a36Sopenharmony_ci reg_2950 = 0x00010000 + src_major_y; 50562306a36Sopenharmony_ci if (f->interlaced_y) 50662306a36Sopenharmony_ci reg_2950 += 0x00010000; 50762306a36Sopenharmony_ci reg_2954 = reg_2950 + 1; 50862306a36Sopenharmony_ci 50962306a36Sopenharmony_ci reg_2958 = 0x00010000 + (src_major_y >> 1); 51062306a36Sopenharmony_ci if (f->interlaced_uv) 51162306a36Sopenharmony_ci reg_2958 += 0x00010000; 51262306a36Sopenharmony_ci reg_295c = reg_2958 + 1; 51362306a36Sopenharmony_ci 51462306a36Sopenharmony_ci if (yi->decode_height == 480) 51562306a36Sopenharmony_ci reg_289c = 0x011e0017; 51662306a36Sopenharmony_ci else 51762306a36Sopenharmony_ci reg_289c = 0x01500017; 51862306a36Sopenharmony_ci 51962306a36Sopenharmony_ci if (f->dst_y < 0) 52062306a36Sopenharmony_ci reg_289c = (reg_289c - ((f->dst_y & ~1)<<15))-(f->dst_y >>1); 52162306a36Sopenharmony_ci else 52262306a36Sopenharmony_ci reg_289c = (reg_289c + ((f->dst_y & ~1)<<15))+(f->dst_y >>1); 52362306a36Sopenharmony_ci 52462306a36Sopenharmony_ci /* How much of the source to decode. 52562306a36Sopenharmony_ci Take into account the source offset */ 52662306a36Sopenharmony_ci reg_2960 = ((src_minor_y + f->src_h + src_major_y) - 1) | 52762306a36Sopenharmony_ci (((src_minor_uv + f->src_h + src_major_uv - 1) & ~1) << 15); 52862306a36Sopenharmony_ci 52962306a36Sopenharmony_ci /* Calculate correct value for register 2964 */ 53062306a36Sopenharmony_ci if (f->src_h == f->dst_h) { 53162306a36Sopenharmony_ci reg_2964 = 1; 53262306a36Sopenharmony_ci } else { 53362306a36Sopenharmony_ci reg_2964 = 2 + ((f->dst_h << 1) / f->src_h); 53462306a36Sopenharmony_ci reg_2964 = (reg_2964 >> 1) + (reg_2964 & 1); 53562306a36Sopenharmony_ci } 53662306a36Sopenharmony_ci reg_2968 = (reg_2964 << 16) + reg_2964 + (reg_2964 >> 1); 53762306a36Sopenharmony_ci reg_2964 = (reg_2964 << 16) + reg_2964 + (reg_2964 * 46 / 94); 53862306a36Sopenharmony_ci 53962306a36Sopenharmony_ci /* Okay, we've wasted time working out the correct value, 54062306a36Sopenharmony_ci but if we use it, it fouls the window alignment. 54162306a36Sopenharmony_ci Fudge it to what we want... */ 54262306a36Sopenharmony_ci reg_2964 = 0x00010001 + ((reg_2964 & 0x0000FFFF) - (reg_2964 >> 16)); 54362306a36Sopenharmony_ci reg_2968 = 0x00010001 + ((reg_2968 & 0x0000FFFF) - (reg_2968 >> 16)); 54462306a36Sopenharmony_ci 54562306a36Sopenharmony_ci /* Deviate further from what it should be. I find the flicker headache 54662306a36Sopenharmony_ci inducing so try to reduce it slightly. Leave 2968 as-is otherwise 54762306a36Sopenharmony_ci colours foul. */ 54862306a36Sopenharmony_ci if ((reg_2964 != 0x00010001) && (f->dst_h / 2 <= f->src_h)) 54962306a36Sopenharmony_ci reg_2964 = (reg_2964 & 0xFFFF0000) + ((reg_2964 & 0x0000FFFF) / 2); 55062306a36Sopenharmony_ci 55162306a36Sopenharmony_ci if (!f->interlaced_y) 55262306a36Sopenharmony_ci reg_2964 -= 0x00010001; 55362306a36Sopenharmony_ci if (!f->interlaced_uv) 55462306a36Sopenharmony_ci reg_2968 -= 0x00010001; 55562306a36Sopenharmony_ci 55662306a36Sopenharmony_ci reg_2964 += ((reg_2964_base << 16) | reg_2964_base); 55762306a36Sopenharmony_ci reg_2968 += ((reg_2968_base << 16) | reg_2968_base); 55862306a36Sopenharmony_ci 55962306a36Sopenharmony_ci /* Select the vertical filter */ 56062306a36Sopenharmony_ci if (f->src_h == f->dst_h) { 56162306a36Sopenharmony_ci /* An exact size match uses filter 0/1 */ 56262306a36Sopenharmony_ci v_filter_1 = 0; 56362306a36Sopenharmony_ci v_filter_2 = 1; 56462306a36Sopenharmony_ci } else { 56562306a36Sopenharmony_ci /* Figure out which filter to use */ 56662306a36Sopenharmony_ci v_filter_1 = ((f->src_h << 16) / f->dst_h) >> 15; 56762306a36Sopenharmony_ci v_filter_1 = (v_filter_1 >> 1) + (v_filter_1 & 1); 56862306a36Sopenharmony_ci /* Only an exact size match can use filter 0 */ 56962306a36Sopenharmony_ci v_filter_1 += !v_filter_1; 57062306a36Sopenharmony_ci v_filter_2 = v_filter_1; 57162306a36Sopenharmony_ci } 57262306a36Sopenharmony_ci 57362306a36Sopenharmony_ci write_reg(reg_2934, 0x02934); 57462306a36Sopenharmony_ci write_reg(reg_293c, 0x0293c); 57562306a36Sopenharmony_ci IVTV_DEBUG_YUV("Update reg 0x2934 %08x->%08x 0x293c %08x->%08x\n", 57662306a36Sopenharmony_ci yi->reg_2934, reg_2934, yi->reg_293c, reg_293c); 57762306a36Sopenharmony_ci write_reg(reg_2944, 0x02944); 57862306a36Sopenharmony_ci write_reg(reg_294c, 0x0294c); 57962306a36Sopenharmony_ci IVTV_DEBUG_YUV("Update reg 0x2944 %08x->%08x 0x294c %08x->%08x\n", 58062306a36Sopenharmony_ci yi->reg_2944, reg_2944, yi->reg_294c, reg_294c); 58162306a36Sopenharmony_ci 58262306a36Sopenharmony_ci /* Ensure 2970 is 0 (does it ever change ?) */ 58362306a36Sopenharmony_ci/* write_reg(0,0x02970); */ 58462306a36Sopenharmony_ci/* IVTV_DEBUG_YUV("Update reg 0x2970 %08x->%08x\n", yi->reg_2970, 0); */ 58562306a36Sopenharmony_ci 58662306a36Sopenharmony_ci write_reg(reg_2930, 0x02938); 58762306a36Sopenharmony_ci write_reg(reg_2930, 0x02930); 58862306a36Sopenharmony_ci IVTV_DEBUG_YUV("Update reg 0x2930 %08x->%08x 0x2938 %08x->%08x\n", 58962306a36Sopenharmony_ci yi->reg_2930, reg_2930, yi->reg_2938, reg_2930); 59062306a36Sopenharmony_ci 59162306a36Sopenharmony_ci write_reg(reg_2928, 0x02928); 59262306a36Sopenharmony_ci write_reg(reg_2928 + 0x514, 0x0292C); 59362306a36Sopenharmony_ci IVTV_DEBUG_YUV("Update reg 0x2928 %08x->%08x 0x292c %08x->%08x\n", 59462306a36Sopenharmony_ci yi->reg_2928, reg_2928, yi->reg_292c, reg_2928 + 0x514); 59562306a36Sopenharmony_ci 59662306a36Sopenharmony_ci write_reg(reg_2920, 0x02920); 59762306a36Sopenharmony_ci write_reg(reg_2920 + 0x514, 0x02924); 59862306a36Sopenharmony_ci IVTV_DEBUG_YUV("Update reg 0x2920 %08x->%08x 0x2924 %08x->%08x\n", 59962306a36Sopenharmony_ci yi->reg_2920, reg_2920, yi->reg_2924, reg_2920 + 0x514); 60062306a36Sopenharmony_ci 60162306a36Sopenharmony_ci write_reg(reg_2918, 0x02918); 60262306a36Sopenharmony_ci write_reg(reg_291c, 0x0291C); 60362306a36Sopenharmony_ci IVTV_DEBUG_YUV("Update reg 0x2918 %08x->%08x 0x291C %08x->%08x\n", 60462306a36Sopenharmony_ci yi->reg_2918, reg_2918, yi->reg_291c, reg_291c); 60562306a36Sopenharmony_ci 60662306a36Sopenharmony_ci write_reg(reg_296c, 0x0296c); 60762306a36Sopenharmony_ci IVTV_DEBUG_YUV("Update reg 0x296c %08x->%08x\n", 60862306a36Sopenharmony_ci yi->reg_296c, reg_296c); 60962306a36Sopenharmony_ci 61062306a36Sopenharmony_ci write_reg(reg_2940, 0x02948); 61162306a36Sopenharmony_ci write_reg(reg_2940, 0x02940); 61262306a36Sopenharmony_ci IVTV_DEBUG_YUV("Update reg 0x2940 %08x->%08x 0x2948 %08x->%08x\n", 61362306a36Sopenharmony_ci yi->reg_2940, reg_2940, yi->reg_2948, reg_2940); 61462306a36Sopenharmony_ci 61562306a36Sopenharmony_ci write_reg(reg_2950, 0x02950); 61662306a36Sopenharmony_ci write_reg(reg_2954, 0x02954); 61762306a36Sopenharmony_ci IVTV_DEBUG_YUV("Update reg 0x2950 %08x->%08x 0x2954 %08x->%08x\n", 61862306a36Sopenharmony_ci yi->reg_2950, reg_2950, yi->reg_2954, reg_2954); 61962306a36Sopenharmony_ci 62062306a36Sopenharmony_ci write_reg(reg_2958, 0x02958); 62162306a36Sopenharmony_ci write_reg(reg_295c, 0x0295C); 62262306a36Sopenharmony_ci IVTV_DEBUG_YUV("Update reg 0x2958 %08x->%08x 0x295C %08x->%08x\n", 62362306a36Sopenharmony_ci yi->reg_2958, reg_2958, yi->reg_295c, reg_295c); 62462306a36Sopenharmony_ci 62562306a36Sopenharmony_ci write_reg(reg_2960, 0x02960); 62662306a36Sopenharmony_ci IVTV_DEBUG_YUV("Update reg 0x2960 %08x->%08x \n", 62762306a36Sopenharmony_ci yi->reg_2960, reg_2960); 62862306a36Sopenharmony_ci 62962306a36Sopenharmony_ci write_reg(reg_2964, 0x02964); 63062306a36Sopenharmony_ci write_reg(reg_2968, 0x02968); 63162306a36Sopenharmony_ci IVTV_DEBUG_YUV("Update reg 0x2964 %08x->%08x 0x2968 %08x->%08x\n", 63262306a36Sopenharmony_ci yi->reg_2964, reg_2964, yi->reg_2968, reg_2968); 63362306a36Sopenharmony_ci 63462306a36Sopenharmony_ci write_reg(reg_289c, 0x0289c); 63562306a36Sopenharmony_ci IVTV_DEBUG_YUV("Update reg 0x289c %08x->%08x\n", 63662306a36Sopenharmony_ci yi->reg_289c, reg_289c); 63762306a36Sopenharmony_ci 63862306a36Sopenharmony_ci /* Only update filter 1 if we really need to */ 63962306a36Sopenharmony_ci if (v_filter_1 != yi->v_filter_1) { 64062306a36Sopenharmony_ci ivtv_yuv_filter(itv, -1, v_filter_1, -1); 64162306a36Sopenharmony_ci yi->v_filter_1 = v_filter_1; 64262306a36Sopenharmony_ci } 64362306a36Sopenharmony_ci 64462306a36Sopenharmony_ci /* Only update filter 2 if we really need to */ 64562306a36Sopenharmony_ci if (v_filter_2 != yi->v_filter_2) { 64662306a36Sopenharmony_ci ivtv_yuv_filter(itv, -1, -1, v_filter_2); 64762306a36Sopenharmony_ci yi->v_filter_2 = v_filter_2; 64862306a36Sopenharmony_ci } 64962306a36Sopenharmony_ci} 65062306a36Sopenharmony_ci 65162306a36Sopenharmony_ci/* Modify the supplied coordinate information to fit the visible osd area */ 65262306a36Sopenharmony_cistatic u32 ivtv_yuv_window_setup(struct ivtv *itv, struct yuv_frame_info *f) 65362306a36Sopenharmony_ci{ 65462306a36Sopenharmony_ci struct yuv_frame_info *of = &itv->yuv_info.old_frame_info; 65562306a36Sopenharmony_ci int osd_crop; 65662306a36Sopenharmony_ci u32 osd_scale; 65762306a36Sopenharmony_ci u32 yuv_update = 0; 65862306a36Sopenharmony_ci 65962306a36Sopenharmony_ci /* Sorry, but no negative coords for src */ 66062306a36Sopenharmony_ci if (f->src_x < 0) 66162306a36Sopenharmony_ci f->src_x = 0; 66262306a36Sopenharmony_ci if (f->src_y < 0) 66362306a36Sopenharmony_ci f->src_y = 0; 66462306a36Sopenharmony_ci 66562306a36Sopenharmony_ci /* Can only reduce width down to 1/4 original size */ 66662306a36Sopenharmony_ci if ((osd_crop = f->src_w - 4 * f->dst_w) > 0) { 66762306a36Sopenharmony_ci f->src_x += osd_crop / 2; 66862306a36Sopenharmony_ci f->src_w = (f->src_w - osd_crop) & ~3; 66962306a36Sopenharmony_ci f->dst_w = f->src_w / 4; 67062306a36Sopenharmony_ci f->dst_w += f->dst_w & 1; 67162306a36Sopenharmony_ci } 67262306a36Sopenharmony_ci 67362306a36Sopenharmony_ci /* Can only reduce height down to 1/4 original size */ 67462306a36Sopenharmony_ci if (f->src_h / f->dst_h >= 2) { 67562306a36Sopenharmony_ci /* Overflow may be because we're running progressive, 67662306a36Sopenharmony_ci so force mode switch */ 67762306a36Sopenharmony_ci f->interlaced_y = 1; 67862306a36Sopenharmony_ci /* Make sure we're still within limits for interlace */ 67962306a36Sopenharmony_ci if ((osd_crop = f->src_h - 4 * f->dst_h) > 0) { 68062306a36Sopenharmony_ci /* If we reach here we'll have to force the height. */ 68162306a36Sopenharmony_ci f->src_y += osd_crop / 2; 68262306a36Sopenharmony_ci f->src_h = (f->src_h - osd_crop) & ~3; 68362306a36Sopenharmony_ci f->dst_h = f->src_h / 4; 68462306a36Sopenharmony_ci f->dst_h += f->dst_h & 1; 68562306a36Sopenharmony_ci } 68662306a36Sopenharmony_ci } 68762306a36Sopenharmony_ci 68862306a36Sopenharmony_ci /* If there's nothing to safe to display, we may as well stop now */ 68962306a36Sopenharmony_ci if ((int)f->dst_w <= 2 || (int)f->dst_h <= 2 || 69062306a36Sopenharmony_ci (int)f->src_w <= 2 || (int)f->src_h <= 2) { 69162306a36Sopenharmony_ci return IVTV_YUV_UPDATE_INVALID; 69262306a36Sopenharmony_ci } 69362306a36Sopenharmony_ci 69462306a36Sopenharmony_ci /* Ensure video remains inside OSD area */ 69562306a36Sopenharmony_ci osd_scale = (f->src_h << 16) / f->dst_h; 69662306a36Sopenharmony_ci 69762306a36Sopenharmony_ci if ((osd_crop = f->pan_y - f->dst_y) > 0) { 69862306a36Sopenharmony_ci /* Falls off the upper edge - crop */ 69962306a36Sopenharmony_ci f->src_y += (osd_scale * osd_crop) >> 16; 70062306a36Sopenharmony_ci f->src_h -= (osd_scale * osd_crop) >> 16; 70162306a36Sopenharmony_ci f->dst_h -= osd_crop; 70262306a36Sopenharmony_ci f->dst_y = 0; 70362306a36Sopenharmony_ci } else { 70462306a36Sopenharmony_ci f->dst_y -= f->pan_y; 70562306a36Sopenharmony_ci } 70662306a36Sopenharmony_ci 70762306a36Sopenharmony_ci if ((osd_crop = f->dst_h + f->dst_y - f->vis_h) > 0) { 70862306a36Sopenharmony_ci /* Falls off the lower edge - crop */ 70962306a36Sopenharmony_ci f->dst_h -= osd_crop; 71062306a36Sopenharmony_ci f->src_h -= (osd_scale * osd_crop) >> 16; 71162306a36Sopenharmony_ci } 71262306a36Sopenharmony_ci 71362306a36Sopenharmony_ci osd_scale = (f->src_w << 16) / f->dst_w; 71462306a36Sopenharmony_ci 71562306a36Sopenharmony_ci if ((osd_crop = f->pan_x - f->dst_x) > 0) { 71662306a36Sopenharmony_ci /* Fall off the left edge - crop */ 71762306a36Sopenharmony_ci f->src_x += (osd_scale * osd_crop) >> 16; 71862306a36Sopenharmony_ci f->src_w -= (osd_scale * osd_crop) >> 16; 71962306a36Sopenharmony_ci f->dst_w -= osd_crop; 72062306a36Sopenharmony_ci f->dst_x = 0; 72162306a36Sopenharmony_ci } else { 72262306a36Sopenharmony_ci f->dst_x -= f->pan_x; 72362306a36Sopenharmony_ci } 72462306a36Sopenharmony_ci 72562306a36Sopenharmony_ci if ((osd_crop = f->dst_w + f->dst_x - f->vis_w) > 0) { 72662306a36Sopenharmony_ci /* Falls off the right edge - crop */ 72762306a36Sopenharmony_ci f->dst_w -= osd_crop; 72862306a36Sopenharmony_ci f->src_w -= (osd_scale * osd_crop) >> 16; 72962306a36Sopenharmony_ci } 73062306a36Sopenharmony_ci 73162306a36Sopenharmony_ci if (itv->yuv_info.track_osd) { 73262306a36Sopenharmony_ci /* The OSD can be moved. Track to it */ 73362306a36Sopenharmony_ci f->dst_x += itv->yuv_info.osd_x_offset; 73462306a36Sopenharmony_ci f->dst_y += itv->yuv_info.osd_y_offset; 73562306a36Sopenharmony_ci } 73662306a36Sopenharmony_ci 73762306a36Sopenharmony_ci /* Width & height for both src & dst must be even. 73862306a36Sopenharmony_ci Same for coordinates. */ 73962306a36Sopenharmony_ci f->dst_w &= ~1; 74062306a36Sopenharmony_ci f->dst_x &= ~1; 74162306a36Sopenharmony_ci 74262306a36Sopenharmony_ci f->src_w += f->src_x & 1; 74362306a36Sopenharmony_ci f->src_x &= ~1; 74462306a36Sopenharmony_ci 74562306a36Sopenharmony_ci f->src_w &= ~1; 74662306a36Sopenharmony_ci f->dst_w &= ~1; 74762306a36Sopenharmony_ci 74862306a36Sopenharmony_ci f->dst_h &= ~1; 74962306a36Sopenharmony_ci f->dst_y &= ~1; 75062306a36Sopenharmony_ci 75162306a36Sopenharmony_ci f->src_h += f->src_y & 1; 75262306a36Sopenharmony_ci f->src_y &= ~1; 75362306a36Sopenharmony_ci 75462306a36Sopenharmony_ci f->src_h &= ~1; 75562306a36Sopenharmony_ci f->dst_h &= ~1; 75662306a36Sopenharmony_ci 75762306a36Sopenharmony_ci /* Due to rounding, we may have reduced the output size to <1/4 of 75862306a36Sopenharmony_ci the source. Check again, but this time just resize. Don't change 75962306a36Sopenharmony_ci source coordinates */ 76062306a36Sopenharmony_ci if (f->dst_w < f->src_w / 4) { 76162306a36Sopenharmony_ci f->src_w &= ~3; 76262306a36Sopenharmony_ci f->dst_w = f->src_w / 4; 76362306a36Sopenharmony_ci f->dst_w += f->dst_w & 1; 76462306a36Sopenharmony_ci } 76562306a36Sopenharmony_ci if (f->dst_h < f->src_h / 4) { 76662306a36Sopenharmony_ci f->src_h &= ~3; 76762306a36Sopenharmony_ci f->dst_h = f->src_h / 4; 76862306a36Sopenharmony_ci f->dst_h += f->dst_h & 1; 76962306a36Sopenharmony_ci } 77062306a36Sopenharmony_ci 77162306a36Sopenharmony_ci /* Check again. If there's nothing to safe to display, stop now */ 77262306a36Sopenharmony_ci if ((int)f->dst_w <= 2 || (int)f->dst_h <= 2 || 77362306a36Sopenharmony_ci (int)f->src_w <= 2 || (int)f->src_h <= 2) { 77462306a36Sopenharmony_ci return IVTV_YUV_UPDATE_INVALID; 77562306a36Sopenharmony_ci } 77662306a36Sopenharmony_ci 77762306a36Sopenharmony_ci /* Both x offset & width are linked, so they have to be done together */ 77862306a36Sopenharmony_ci if ((of->dst_w != f->dst_w) || (of->src_w != f->src_w) || 77962306a36Sopenharmony_ci (of->dst_x != f->dst_x) || (of->src_x != f->src_x) || 78062306a36Sopenharmony_ci (of->pan_x != f->pan_x) || (of->vis_w != f->vis_w)) { 78162306a36Sopenharmony_ci yuv_update |= IVTV_YUV_UPDATE_HORIZONTAL; 78262306a36Sopenharmony_ci } 78362306a36Sopenharmony_ci 78462306a36Sopenharmony_ci if ((of->src_h != f->src_h) || (of->dst_h != f->dst_h) || 78562306a36Sopenharmony_ci (of->dst_y != f->dst_y) || (of->src_y != f->src_y) || 78662306a36Sopenharmony_ci (of->pan_y != f->pan_y) || (of->vis_h != f->vis_h) || 78762306a36Sopenharmony_ci (of->lace_mode != f->lace_mode) || 78862306a36Sopenharmony_ci (of->interlaced_y != f->interlaced_y) || 78962306a36Sopenharmony_ci (of->interlaced_uv != f->interlaced_uv)) { 79062306a36Sopenharmony_ci yuv_update |= IVTV_YUV_UPDATE_VERTICAL; 79162306a36Sopenharmony_ci } 79262306a36Sopenharmony_ci 79362306a36Sopenharmony_ci return yuv_update; 79462306a36Sopenharmony_ci} 79562306a36Sopenharmony_ci 79662306a36Sopenharmony_ci/* Update the scaling register to the requested value */ 79762306a36Sopenharmony_civoid ivtv_yuv_work_handler(struct ivtv *itv) 79862306a36Sopenharmony_ci{ 79962306a36Sopenharmony_ci struct yuv_playback_info *yi = &itv->yuv_info; 80062306a36Sopenharmony_ci struct yuv_frame_info f; 80162306a36Sopenharmony_ci int frame = yi->update_frame; 80262306a36Sopenharmony_ci u32 yuv_update; 80362306a36Sopenharmony_ci 80462306a36Sopenharmony_ci IVTV_DEBUG_YUV("Update yuv registers for frame %d\n", frame); 80562306a36Sopenharmony_ci f = yi->new_frame_info[frame]; 80662306a36Sopenharmony_ci 80762306a36Sopenharmony_ci if (yi->track_osd) { 80862306a36Sopenharmony_ci /* Snapshot the osd pan info */ 80962306a36Sopenharmony_ci f.pan_x = yi->osd_x_pan; 81062306a36Sopenharmony_ci f.pan_y = yi->osd_y_pan; 81162306a36Sopenharmony_ci f.vis_w = yi->osd_vis_w; 81262306a36Sopenharmony_ci f.vis_h = yi->osd_vis_h; 81362306a36Sopenharmony_ci } else { 81462306a36Sopenharmony_ci /* Not tracking the osd, so assume full screen */ 81562306a36Sopenharmony_ci f.pan_x = 0; 81662306a36Sopenharmony_ci f.pan_y = 0; 81762306a36Sopenharmony_ci f.vis_w = 720; 81862306a36Sopenharmony_ci f.vis_h = yi->decode_height; 81962306a36Sopenharmony_ci } 82062306a36Sopenharmony_ci 82162306a36Sopenharmony_ci /* Calculate the display window coordinates. Exit if nothing left */ 82262306a36Sopenharmony_ci if (!(yuv_update = ivtv_yuv_window_setup(itv, &f))) 82362306a36Sopenharmony_ci return; 82462306a36Sopenharmony_ci 82562306a36Sopenharmony_ci if (yuv_update & IVTV_YUV_UPDATE_INVALID) { 82662306a36Sopenharmony_ci write_reg(0x01008080, 0x2898); 82762306a36Sopenharmony_ci } else if (yuv_update) { 82862306a36Sopenharmony_ci write_reg(0x00108080, 0x2898); 82962306a36Sopenharmony_ci 83062306a36Sopenharmony_ci if (yuv_update & IVTV_YUV_UPDATE_HORIZONTAL) 83162306a36Sopenharmony_ci ivtv_yuv_handle_horizontal(itv, &f); 83262306a36Sopenharmony_ci 83362306a36Sopenharmony_ci if (yuv_update & IVTV_YUV_UPDATE_VERTICAL) 83462306a36Sopenharmony_ci ivtv_yuv_handle_vertical(itv, &f); 83562306a36Sopenharmony_ci } 83662306a36Sopenharmony_ci yi->old_frame_info = f; 83762306a36Sopenharmony_ci} 83862306a36Sopenharmony_ci 83962306a36Sopenharmony_cistatic void ivtv_yuv_init(struct ivtv *itv) 84062306a36Sopenharmony_ci{ 84162306a36Sopenharmony_ci struct yuv_playback_info *yi = &itv->yuv_info; 84262306a36Sopenharmony_ci 84362306a36Sopenharmony_ci IVTV_DEBUG_YUV("ivtv_yuv_init\n"); 84462306a36Sopenharmony_ci 84562306a36Sopenharmony_ci /* Take a snapshot of the current register settings */ 84662306a36Sopenharmony_ci yi->reg_2834 = read_reg(0x02834); 84762306a36Sopenharmony_ci yi->reg_2838 = read_reg(0x02838); 84862306a36Sopenharmony_ci yi->reg_283c = read_reg(0x0283c); 84962306a36Sopenharmony_ci yi->reg_2840 = read_reg(0x02840); 85062306a36Sopenharmony_ci yi->reg_2844 = read_reg(0x02844); 85162306a36Sopenharmony_ci yi->reg_2848 = read_reg(0x02848); 85262306a36Sopenharmony_ci yi->reg_2854 = read_reg(0x02854); 85362306a36Sopenharmony_ci yi->reg_285c = read_reg(0x0285c); 85462306a36Sopenharmony_ci yi->reg_2864 = read_reg(0x02864); 85562306a36Sopenharmony_ci yi->reg_2870 = read_reg(0x02870); 85662306a36Sopenharmony_ci yi->reg_2874 = read_reg(0x02874); 85762306a36Sopenharmony_ci yi->reg_2898 = read_reg(0x02898); 85862306a36Sopenharmony_ci yi->reg_2890 = read_reg(0x02890); 85962306a36Sopenharmony_ci 86062306a36Sopenharmony_ci yi->reg_289c = read_reg(0x0289c); 86162306a36Sopenharmony_ci yi->reg_2918 = read_reg(0x02918); 86262306a36Sopenharmony_ci yi->reg_291c = read_reg(0x0291c); 86362306a36Sopenharmony_ci yi->reg_2920 = read_reg(0x02920); 86462306a36Sopenharmony_ci yi->reg_2924 = read_reg(0x02924); 86562306a36Sopenharmony_ci yi->reg_2928 = read_reg(0x02928); 86662306a36Sopenharmony_ci yi->reg_292c = read_reg(0x0292c); 86762306a36Sopenharmony_ci yi->reg_2930 = read_reg(0x02930); 86862306a36Sopenharmony_ci yi->reg_2934 = read_reg(0x02934); 86962306a36Sopenharmony_ci yi->reg_2938 = read_reg(0x02938); 87062306a36Sopenharmony_ci yi->reg_293c = read_reg(0x0293c); 87162306a36Sopenharmony_ci yi->reg_2940 = read_reg(0x02940); 87262306a36Sopenharmony_ci yi->reg_2944 = read_reg(0x02944); 87362306a36Sopenharmony_ci yi->reg_2948 = read_reg(0x02948); 87462306a36Sopenharmony_ci yi->reg_294c = read_reg(0x0294c); 87562306a36Sopenharmony_ci yi->reg_2950 = read_reg(0x02950); 87662306a36Sopenharmony_ci yi->reg_2954 = read_reg(0x02954); 87762306a36Sopenharmony_ci yi->reg_2958 = read_reg(0x02958); 87862306a36Sopenharmony_ci yi->reg_295c = read_reg(0x0295c); 87962306a36Sopenharmony_ci yi->reg_2960 = read_reg(0x02960); 88062306a36Sopenharmony_ci yi->reg_2964 = read_reg(0x02964); 88162306a36Sopenharmony_ci yi->reg_2968 = read_reg(0x02968); 88262306a36Sopenharmony_ci yi->reg_296c = read_reg(0x0296c); 88362306a36Sopenharmony_ci yi->reg_2970 = read_reg(0x02970); 88462306a36Sopenharmony_ci 88562306a36Sopenharmony_ci yi->v_filter_1 = -1; 88662306a36Sopenharmony_ci yi->v_filter_2 = -1; 88762306a36Sopenharmony_ci yi->h_filter = -1; 88862306a36Sopenharmony_ci 88962306a36Sopenharmony_ci /* Set some valid size info */ 89062306a36Sopenharmony_ci yi->osd_x_offset = read_reg(0x02a04) & 0x00000FFF; 89162306a36Sopenharmony_ci yi->osd_y_offset = (read_reg(0x02a04) >> 16) & 0x00000FFF; 89262306a36Sopenharmony_ci 89362306a36Sopenharmony_ci /* Bit 2 of reg 2878 indicates current decoder output format 89462306a36Sopenharmony_ci 0 : NTSC 1 : PAL */ 89562306a36Sopenharmony_ci if (read_reg(0x2878) & 4) 89662306a36Sopenharmony_ci yi->decode_height = 576; 89762306a36Sopenharmony_ci else 89862306a36Sopenharmony_ci yi->decode_height = 480; 89962306a36Sopenharmony_ci 90062306a36Sopenharmony_ci if (!itv->osd_info) { 90162306a36Sopenharmony_ci yi->osd_vis_w = 720 - yi->osd_x_offset; 90262306a36Sopenharmony_ci yi->osd_vis_h = yi->decode_height - yi->osd_y_offset; 90362306a36Sopenharmony_ci } else { 90462306a36Sopenharmony_ci /* If no visible size set, assume full size */ 90562306a36Sopenharmony_ci if (!yi->osd_vis_w) 90662306a36Sopenharmony_ci yi->osd_vis_w = 720 - yi->osd_x_offset; 90762306a36Sopenharmony_ci 90862306a36Sopenharmony_ci if (!yi->osd_vis_h) { 90962306a36Sopenharmony_ci yi->osd_vis_h = yi->decode_height - yi->osd_y_offset; 91062306a36Sopenharmony_ci } else if (yi->osd_vis_h + yi->osd_y_offset > yi->decode_height) { 91162306a36Sopenharmony_ci /* If output video standard has changed, requested height may 91262306a36Sopenharmony_ci not be legal */ 91362306a36Sopenharmony_ci IVTV_DEBUG_WARN("Clipping yuv output - fb size (%d) exceeds video standard limit (%d)\n", 91462306a36Sopenharmony_ci yi->osd_vis_h + yi->osd_y_offset, 91562306a36Sopenharmony_ci yi->decode_height); 91662306a36Sopenharmony_ci yi->osd_vis_h = yi->decode_height - yi->osd_y_offset; 91762306a36Sopenharmony_ci } 91862306a36Sopenharmony_ci } 91962306a36Sopenharmony_ci 92062306a36Sopenharmony_ci /* We need a buffer for blanking when Y plane is offset - non-fatal if we can't get one */ 92162306a36Sopenharmony_ci yi->blanking_ptr = kzalloc(720 * 16, GFP_ATOMIC|__GFP_NOWARN); 92262306a36Sopenharmony_ci if (yi->blanking_ptr) { 92362306a36Sopenharmony_ci yi->blanking_dmaptr = dma_map_single(&itv->pdev->dev, 92462306a36Sopenharmony_ci yi->blanking_ptr, 92562306a36Sopenharmony_ci 720 * 16, DMA_TO_DEVICE); 92662306a36Sopenharmony_ci } else { 92762306a36Sopenharmony_ci yi->blanking_dmaptr = 0; 92862306a36Sopenharmony_ci IVTV_DEBUG_WARN("Failed to allocate yuv blanking buffer\n"); 92962306a36Sopenharmony_ci } 93062306a36Sopenharmony_ci 93162306a36Sopenharmony_ci /* Enable YUV decoder output */ 93262306a36Sopenharmony_ci write_reg_sync(0x01, IVTV_REG_VDM); 93362306a36Sopenharmony_ci 93462306a36Sopenharmony_ci set_bit(IVTV_F_I_DECODING_YUV, &itv->i_flags); 93562306a36Sopenharmony_ci atomic_set(&yi->next_dma_frame, 0); 93662306a36Sopenharmony_ci} 93762306a36Sopenharmony_ci 93862306a36Sopenharmony_ci/* Get next available yuv buffer on PVR350 */ 93962306a36Sopenharmony_cistatic void ivtv_yuv_next_free(struct ivtv *itv) 94062306a36Sopenharmony_ci{ 94162306a36Sopenharmony_ci int draw, display; 94262306a36Sopenharmony_ci struct yuv_playback_info *yi = &itv->yuv_info; 94362306a36Sopenharmony_ci 94462306a36Sopenharmony_ci if (atomic_read(&yi->next_dma_frame) == -1) 94562306a36Sopenharmony_ci ivtv_yuv_init(itv); 94662306a36Sopenharmony_ci 94762306a36Sopenharmony_ci draw = atomic_read(&yi->next_fill_frame); 94862306a36Sopenharmony_ci display = atomic_read(&yi->next_dma_frame); 94962306a36Sopenharmony_ci 95062306a36Sopenharmony_ci if (display > draw) 95162306a36Sopenharmony_ci display -= IVTV_YUV_BUFFERS; 95262306a36Sopenharmony_ci 95362306a36Sopenharmony_ci if (draw - display >= yi->max_frames_buffered) 95462306a36Sopenharmony_ci draw = (u8)(draw - 1) % IVTV_YUV_BUFFERS; 95562306a36Sopenharmony_ci else 95662306a36Sopenharmony_ci yi->new_frame_info[draw].update = 0; 95762306a36Sopenharmony_ci 95862306a36Sopenharmony_ci yi->draw_frame = draw; 95962306a36Sopenharmony_ci} 96062306a36Sopenharmony_ci 96162306a36Sopenharmony_ci/* Set up frame according to ivtv_dma_frame parameters */ 96262306a36Sopenharmony_cistatic void ivtv_yuv_setup_frame(struct ivtv *itv, struct ivtv_dma_frame *args) 96362306a36Sopenharmony_ci{ 96462306a36Sopenharmony_ci struct yuv_playback_info *yi = &itv->yuv_info; 96562306a36Sopenharmony_ci u8 frame = yi->draw_frame; 96662306a36Sopenharmony_ci u8 last_frame = (u8)(frame - 1) % IVTV_YUV_BUFFERS; 96762306a36Sopenharmony_ci struct yuv_frame_info *nf = &yi->new_frame_info[frame]; 96862306a36Sopenharmony_ci struct yuv_frame_info *of = &yi->new_frame_info[last_frame]; 96962306a36Sopenharmony_ci int lace_threshold = yi->lace_threshold; 97062306a36Sopenharmony_ci 97162306a36Sopenharmony_ci /* Preserve old update flag in case we're overwriting a queued frame */ 97262306a36Sopenharmony_ci int update = nf->update; 97362306a36Sopenharmony_ci 97462306a36Sopenharmony_ci /* Take a snapshot of the yuv coordinate information */ 97562306a36Sopenharmony_ci nf->src_x = args->src.left; 97662306a36Sopenharmony_ci nf->src_y = args->src.top; 97762306a36Sopenharmony_ci nf->src_w = args->src.width; 97862306a36Sopenharmony_ci nf->src_h = args->src.height; 97962306a36Sopenharmony_ci nf->dst_x = args->dst.left; 98062306a36Sopenharmony_ci nf->dst_y = args->dst.top; 98162306a36Sopenharmony_ci nf->dst_w = args->dst.width; 98262306a36Sopenharmony_ci nf->dst_h = args->dst.height; 98362306a36Sopenharmony_ci nf->tru_x = args->dst.left; 98462306a36Sopenharmony_ci nf->tru_w = args->src_width; 98562306a36Sopenharmony_ci nf->tru_h = args->src_height; 98662306a36Sopenharmony_ci 98762306a36Sopenharmony_ci /* Are we going to offset the Y plane */ 98862306a36Sopenharmony_ci nf->offset_y = (nf->tru_h + nf->src_x < 512 - 16) ? 1 : 0; 98962306a36Sopenharmony_ci 99062306a36Sopenharmony_ci nf->update = 0; 99162306a36Sopenharmony_ci nf->interlaced_y = 0; 99262306a36Sopenharmony_ci nf->interlaced_uv = 0; 99362306a36Sopenharmony_ci nf->delay = 0; 99462306a36Sopenharmony_ci nf->sync_field = 0; 99562306a36Sopenharmony_ci nf->lace_mode = yi->lace_mode & IVTV_YUV_MODE_MASK; 99662306a36Sopenharmony_ci 99762306a36Sopenharmony_ci if (lace_threshold < 0) 99862306a36Sopenharmony_ci lace_threshold = yi->decode_height - 1; 99962306a36Sopenharmony_ci 100062306a36Sopenharmony_ci /* Work out the lace settings */ 100162306a36Sopenharmony_ci switch (nf->lace_mode) { 100262306a36Sopenharmony_ci case IVTV_YUV_MODE_PROGRESSIVE: /* Progressive mode */ 100362306a36Sopenharmony_ci nf->interlaced = 0; 100462306a36Sopenharmony_ci if (nf->tru_h < 512 || (nf->tru_h > 576 && nf->tru_h < 1021)) 100562306a36Sopenharmony_ci nf->interlaced_y = 0; 100662306a36Sopenharmony_ci else 100762306a36Sopenharmony_ci nf->interlaced_y = 1; 100862306a36Sopenharmony_ci 100962306a36Sopenharmony_ci if (nf->tru_h < 1021 && (nf->dst_h >= nf->src_h / 2)) 101062306a36Sopenharmony_ci nf->interlaced_uv = 0; 101162306a36Sopenharmony_ci else 101262306a36Sopenharmony_ci nf->interlaced_uv = 1; 101362306a36Sopenharmony_ci break; 101462306a36Sopenharmony_ci 101562306a36Sopenharmony_ci case IVTV_YUV_MODE_AUTO: 101662306a36Sopenharmony_ci if (nf->tru_h <= lace_threshold || nf->tru_h > 576 || nf->tru_w > 720) { 101762306a36Sopenharmony_ci nf->interlaced = 0; 101862306a36Sopenharmony_ci if ((nf->tru_h < 512) || 101962306a36Sopenharmony_ci (nf->tru_h > 576 && nf->tru_h < 1021) || 102062306a36Sopenharmony_ci (nf->tru_w > 720 && nf->tru_h < 1021)) 102162306a36Sopenharmony_ci nf->interlaced_y = 0; 102262306a36Sopenharmony_ci else 102362306a36Sopenharmony_ci nf->interlaced_y = 1; 102462306a36Sopenharmony_ci if (nf->tru_h < 1021 && (nf->dst_h >= nf->src_h / 2)) 102562306a36Sopenharmony_ci nf->interlaced_uv = 0; 102662306a36Sopenharmony_ci else 102762306a36Sopenharmony_ci nf->interlaced_uv = 1; 102862306a36Sopenharmony_ci } else { 102962306a36Sopenharmony_ci nf->interlaced = 1; 103062306a36Sopenharmony_ci nf->interlaced_y = 1; 103162306a36Sopenharmony_ci nf->interlaced_uv = 1; 103262306a36Sopenharmony_ci } 103362306a36Sopenharmony_ci break; 103462306a36Sopenharmony_ci 103562306a36Sopenharmony_ci case IVTV_YUV_MODE_INTERLACED: /* Interlace mode */ 103662306a36Sopenharmony_ci default: 103762306a36Sopenharmony_ci nf->interlaced = 1; 103862306a36Sopenharmony_ci nf->interlaced_y = 1; 103962306a36Sopenharmony_ci nf->interlaced_uv = 1; 104062306a36Sopenharmony_ci break; 104162306a36Sopenharmony_ci } 104262306a36Sopenharmony_ci 104362306a36Sopenharmony_ci if (memcmp(&yi->old_frame_info_args, nf, sizeof(*nf))) { 104462306a36Sopenharmony_ci yi->old_frame_info_args = *nf; 104562306a36Sopenharmony_ci nf->update = 1; 104662306a36Sopenharmony_ci IVTV_DEBUG_YUV("Requesting reg update for frame %d\n", frame); 104762306a36Sopenharmony_ci } 104862306a36Sopenharmony_ci 104962306a36Sopenharmony_ci nf->update |= update; 105062306a36Sopenharmony_ci nf->sync_field = yi->lace_sync_field; 105162306a36Sopenharmony_ci nf->delay = nf->sync_field != of->sync_field; 105262306a36Sopenharmony_ci} 105362306a36Sopenharmony_ci 105462306a36Sopenharmony_ci/* Frame is complete & ready for display */ 105562306a36Sopenharmony_civoid ivtv_yuv_frame_complete(struct ivtv *itv) 105662306a36Sopenharmony_ci{ 105762306a36Sopenharmony_ci atomic_set(&itv->yuv_info.next_fill_frame, 105862306a36Sopenharmony_ci (itv->yuv_info.draw_frame + 1) % IVTV_YUV_BUFFERS); 105962306a36Sopenharmony_ci} 106062306a36Sopenharmony_ci 106162306a36Sopenharmony_cistatic int ivtv_yuv_udma_frame(struct ivtv *itv, struct ivtv_dma_frame *args) 106262306a36Sopenharmony_ci{ 106362306a36Sopenharmony_ci DEFINE_WAIT(wait); 106462306a36Sopenharmony_ci int rc = 0; 106562306a36Sopenharmony_ci int got_sig = 0; 106662306a36Sopenharmony_ci /* DMA the frame */ 106762306a36Sopenharmony_ci mutex_lock(&itv->udma.lock); 106862306a36Sopenharmony_ci 106962306a36Sopenharmony_ci if ((rc = ivtv_yuv_prep_user_dma(itv, &itv->udma, args)) != 0) { 107062306a36Sopenharmony_ci mutex_unlock(&itv->udma.lock); 107162306a36Sopenharmony_ci return rc; 107262306a36Sopenharmony_ci } 107362306a36Sopenharmony_ci 107462306a36Sopenharmony_ci ivtv_udma_prepare(itv); 107562306a36Sopenharmony_ci prepare_to_wait(&itv->dma_waitq, &wait, TASK_INTERRUPTIBLE); 107662306a36Sopenharmony_ci /* if no UDMA is pending and no UDMA is in progress, then the DMA 107762306a36Sopenharmony_ci is finished */ 107862306a36Sopenharmony_ci while (test_bit(IVTV_F_I_UDMA_PENDING, &itv->i_flags) || 107962306a36Sopenharmony_ci test_bit(IVTV_F_I_UDMA, &itv->i_flags)) { 108062306a36Sopenharmony_ci /* don't interrupt if the DMA is in progress but break off 108162306a36Sopenharmony_ci a still pending DMA. */ 108262306a36Sopenharmony_ci got_sig = signal_pending(current); 108362306a36Sopenharmony_ci if (got_sig && test_and_clear_bit(IVTV_F_I_UDMA_PENDING, &itv->i_flags)) 108462306a36Sopenharmony_ci break; 108562306a36Sopenharmony_ci got_sig = 0; 108662306a36Sopenharmony_ci schedule(); 108762306a36Sopenharmony_ci } 108862306a36Sopenharmony_ci finish_wait(&itv->dma_waitq, &wait); 108962306a36Sopenharmony_ci 109062306a36Sopenharmony_ci /* Unmap Last DMA Xfer */ 109162306a36Sopenharmony_ci ivtv_udma_unmap(itv); 109262306a36Sopenharmony_ci 109362306a36Sopenharmony_ci if (got_sig) { 109462306a36Sopenharmony_ci IVTV_DEBUG_INFO("User stopped YUV UDMA\n"); 109562306a36Sopenharmony_ci mutex_unlock(&itv->udma.lock); 109662306a36Sopenharmony_ci return -EINTR; 109762306a36Sopenharmony_ci } 109862306a36Sopenharmony_ci 109962306a36Sopenharmony_ci ivtv_yuv_frame_complete(itv); 110062306a36Sopenharmony_ci 110162306a36Sopenharmony_ci mutex_unlock(&itv->udma.lock); 110262306a36Sopenharmony_ci return rc; 110362306a36Sopenharmony_ci} 110462306a36Sopenharmony_ci 110562306a36Sopenharmony_ci/* Setup frame according to V4L2 parameters */ 110662306a36Sopenharmony_civoid ivtv_yuv_setup_stream_frame(struct ivtv *itv) 110762306a36Sopenharmony_ci{ 110862306a36Sopenharmony_ci struct yuv_playback_info *yi = &itv->yuv_info; 110962306a36Sopenharmony_ci struct ivtv_dma_frame dma_args; 111062306a36Sopenharmony_ci 111162306a36Sopenharmony_ci ivtv_yuv_next_free(itv); 111262306a36Sopenharmony_ci 111362306a36Sopenharmony_ci /* Copy V4L2 parameters to an ivtv_dma_frame struct... */ 111462306a36Sopenharmony_ci dma_args.y_source = NULL; 111562306a36Sopenharmony_ci dma_args.uv_source = NULL; 111662306a36Sopenharmony_ci dma_args.src.left = 0; 111762306a36Sopenharmony_ci dma_args.src.top = 0; 111862306a36Sopenharmony_ci dma_args.src.width = yi->v4l2_src_w; 111962306a36Sopenharmony_ci dma_args.src.height = yi->v4l2_src_h; 112062306a36Sopenharmony_ci dma_args.dst = yi->main_rect; 112162306a36Sopenharmony_ci dma_args.src_width = yi->v4l2_src_w; 112262306a36Sopenharmony_ci dma_args.src_height = yi->v4l2_src_h; 112362306a36Sopenharmony_ci 112462306a36Sopenharmony_ci /* ... and use the same setup routine as ivtv_yuv_prep_frame */ 112562306a36Sopenharmony_ci ivtv_yuv_setup_frame(itv, &dma_args); 112662306a36Sopenharmony_ci 112762306a36Sopenharmony_ci if (!itv->dma_data_req_offset) 112862306a36Sopenharmony_ci itv->dma_data_req_offset = yuv_offset[yi->draw_frame]; 112962306a36Sopenharmony_ci} 113062306a36Sopenharmony_ci 113162306a36Sopenharmony_ci/* Attempt to dma a frame from a user buffer */ 113262306a36Sopenharmony_ciint ivtv_yuv_udma_stream_frame(struct ivtv *itv, void __user *src) 113362306a36Sopenharmony_ci{ 113462306a36Sopenharmony_ci struct yuv_playback_info *yi = &itv->yuv_info; 113562306a36Sopenharmony_ci struct ivtv_dma_frame dma_args; 113662306a36Sopenharmony_ci int res; 113762306a36Sopenharmony_ci 113862306a36Sopenharmony_ci ivtv_yuv_setup_stream_frame(itv); 113962306a36Sopenharmony_ci 114062306a36Sopenharmony_ci /* We only need to supply source addresses for this */ 114162306a36Sopenharmony_ci dma_args.y_source = src; 114262306a36Sopenharmony_ci dma_args.uv_source = src + 720 * ((yi->v4l2_src_h + 31) & ~31); 114362306a36Sopenharmony_ci /* Wait for frame DMA. Note that serialize_lock is locked, 114462306a36Sopenharmony_ci so to allow other processes to access the driver while 114562306a36Sopenharmony_ci we are waiting unlock first and later lock again. */ 114662306a36Sopenharmony_ci mutex_unlock(&itv->serialize_lock); 114762306a36Sopenharmony_ci res = ivtv_yuv_udma_frame(itv, &dma_args); 114862306a36Sopenharmony_ci mutex_lock(&itv->serialize_lock); 114962306a36Sopenharmony_ci return res; 115062306a36Sopenharmony_ci} 115162306a36Sopenharmony_ci 115262306a36Sopenharmony_ci/* IVTV_IOC_DMA_FRAME ioctl handler */ 115362306a36Sopenharmony_ciint ivtv_yuv_prep_frame(struct ivtv *itv, struct ivtv_dma_frame *args) 115462306a36Sopenharmony_ci{ 115562306a36Sopenharmony_ci int res; 115662306a36Sopenharmony_ci 115762306a36Sopenharmony_ci/* IVTV_DEBUG_INFO("yuv_prep_frame\n"); */ 115862306a36Sopenharmony_ci ivtv_yuv_next_free(itv); 115962306a36Sopenharmony_ci ivtv_yuv_setup_frame(itv, args); 116062306a36Sopenharmony_ci /* Wait for frame DMA. Note that serialize_lock is locked, 116162306a36Sopenharmony_ci so to allow other processes to access the driver while 116262306a36Sopenharmony_ci we are waiting unlock first and later lock again. */ 116362306a36Sopenharmony_ci mutex_unlock(&itv->serialize_lock); 116462306a36Sopenharmony_ci res = ivtv_yuv_udma_frame(itv, args); 116562306a36Sopenharmony_ci mutex_lock(&itv->serialize_lock); 116662306a36Sopenharmony_ci return res; 116762306a36Sopenharmony_ci} 116862306a36Sopenharmony_ci 116962306a36Sopenharmony_civoid ivtv_yuv_close(struct ivtv *itv) 117062306a36Sopenharmony_ci{ 117162306a36Sopenharmony_ci struct yuv_playback_info *yi = &itv->yuv_info; 117262306a36Sopenharmony_ci int h_filter, v_filter_1, v_filter_2; 117362306a36Sopenharmony_ci 117462306a36Sopenharmony_ci IVTV_DEBUG_YUV("ivtv_yuv_close\n"); 117562306a36Sopenharmony_ci mutex_unlock(&itv->serialize_lock); 117662306a36Sopenharmony_ci ivtv_waitq(&itv->vsync_waitq); 117762306a36Sopenharmony_ci mutex_lock(&itv->serialize_lock); 117862306a36Sopenharmony_ci 117962306a36Sopenharmony_ci yi->running = 0; 118062306a36Sopenharmony_ci atomic_set(&yi->next_dma_frame, -1); 118162306a36Sopenharmony_ci atomic_set(&yi->next_fill_frame, 0); 118262306a36Sopenharmony_ci 118362306a36Sopenharmony_ci /* Reset registers we have changed so mpeg playback works */ 118462306a36Sopenharmony_ci 118562306a36Sopenharmony_ci /* If we fully restore this register, the display may remain active. 118662306a36Sopenharmony_ci Restore, but set one bit to blank the video. Firmware will always 118762306a36Sopenharmony_ci clear this bit when needed, so not a problem. */ 118862306a36Sopenharmony_ci write_reg(yi->reg_2898 | 0x01000000, 0x2898); 118962306a36Sopenharmony_ci 119062306a36Sopenharmony_ci write_reg(yi->reg_2834, 0x02834); 119162306a36Sopenharmony_ci write_reg(yi->reg_2838, 0x02838); 119262306a36Sopenharmony_ci write_reg(yi->reg_283c, 0x0283c); 119362306a36Sopenharmony_ci write_reg(yi->reg_2840, 0x02840); 119462306a36Sopenharmony_ci write_reg(yi->reg_2844, 0x02844); 119562306a36Sopenharmony_ci write_reg(yi->reg_2848, 0x02848); 119662306a36Sopenharmony_ci write_reg(yi->reg_2854, 0x02854); 119762306a36Sopenharmony_ci write_reg(yi->reg_285c, 0x0285c); 119862306a36Sopenharmony_ci write_reg(yi->reg_2864, 0x02864); 119962306a36Sopenharmony_ci write_reg(yi->reg_2870, 0x02870); 120062306a36Sopenharmony_ci write_reg(yi->reg_2874, 0x02874); 120162306a36Sopenharmony_ci write_reg(yi->reg_2890, 0x02890); 120262306a36Sopenharmony_ci write_reg(yi->reg_289c, 0x0289c); 120362306a36Sopenharmony_ci 120462306a36Sopenharmony_ci write_reg(yi->reg_2918, 0x02918); 120562306a36Sopenharmony_ci write_reg(yi->reg_291c, 0x0291c); 120662306a36Sopenharmony_ci write_reg(yi->reg_2920, 0x02920); 120762306a36Sopenharmony_ci write_reg(yi->reg_2924, 0x02924); 120862306a36Sopenharmony_ci write_reg(yi->reg_2928, 0x02928); 120962306a36Sopenharmony_ci write_reg(yi->reg_292c, 0x0292c); 121062306a36Sopenharmony_ci write_reg(yi->reg_2930, 0x02930); 121162306a36Sopenharmony_ci write_reg(yi->reg_2934, 0x02934); 121262306a36Sopenharmony_ci write_reg(yi->reg_2938, 0x02938); 121362306a36Sopenharmony_ci write_reg(yi->reg_293c, 0x0293c); 121462306a36Sopenharmony_ci write_reg(yi->reg_2940, 0x02940); 121562306a36Sopenharmony_ci write_reg(yi->reg_2944, 0x02944); 121662306a36Sopenharmony_ci write_reg(yi->reg_2948, 0x02948); 121762306a36Sopenharmony_ci write_reg(yi->reg_294c, 0x0294c); 121862306a36Sopenharmony_ci write_reg(yi->reg_2950, 0x02950); 121962306a36Sopenharmony_ci write_reg(yi->reg_2954, 0x02954); 122062306a36Sopenharmony_ci write_reg(yi->reg_2958, 0x02958); 122162306a36Sopenharmony_ci write_reg(yi->reg_295c, 0x0295c); 122262306a36Sopenharmony_ci write_reg(yi->reg_2960, 0x02960); 122362306a36Sopenharmony_ci write_reg(yi->reg_2964, 0x02964); 122462306a36Sopenharmony_ci write_reg(yi->reg_2968, 0x02968); 122562306a36Sopenharmony_ci write_reg(yi->reg_296c, 0x0296c); 122662306a36Sopenharmony_ci write_reg(yi->reg_2970, 0x02970); 122762306a36Sopenharmony_ci 122862306a36Sopenharmony_ci /* Prepare to restore filters */ 122962306a36Sopenharmony_ci 123062306a36Sopenharmony_ci /* First the horizontal filter */ 123162306a36Sopenharmony_ci if ((yi->reg_2834 & 0x0000FFFF) == (yi->reg_2834 >> 16)) { 123262306a36Sopenharmony_ci /* An exact size match uses filter 0 */ 123362306a36Sopenharmony_ci h_filter = 0; 123462306a36Sopenharmony_ci } else { 123562306a36Sopenharmony_ci /* Figure out which filter to use */ 123662306a36Sopenharmony_ci h_filter = ((yi->reg_2834 << 16) / (yi->reg_2834 >> 16)) >> 15; 123762306a36Sopenharmony_ci h_filter = (h_filter >> 1) + (h_filter & 1); 123862306a36Sopenharmony_ci /* Only an exact size match can use filter 0. */ 123962306a36Sopenharmony_ci h_filter += !h_filter; 124062306a36Sopenharmony_ci } 124162306a36Sopenharmony_ci 124262306a36Sopenharmony_ci /* Now the vertical filter */ 124362306a36Sopenharmony_ci if ((yi->reg_2918 & 0x0000FFFF) == (yi->reg_2918 >> 16)) { 124462306a36Sopenharmony_ci /* An exact size match uses filter 0/1 */ 124562306a36Sopenharmony_ci v_filter_1 = 0; 124662306a36Sopenharmony_ci v_filter_2 = 1; 124762306a36Sopenharmony_ci } else { 124862306a36Sopenharmony_ci /* Figure out which filter to use */ 124962306a36Sopenharmony_ci v_filter_1 = ((yi->reg_2918 << 16) / (yi->reg_2918 >> 16)) >> 15; 125062306a36Sopenharmony_ci v_filter_1 = (v_filter_1 >> 1) + (v_filter_1 & 1); 125162306a36Sopenharmony_ci /* Only an exact size match can use filter 0 */ 125262306a36Sopenharmony_ci v_filter_1 += !v_filter_1; 125362306a36Sopenharmony_ci v_filter_2 = v_filter_1; 125462306a36Sopenharmony_ci } 125562306a36Sopenharmony_ci 125662306a36Sopenharmony_ci /* Now restore the filters */ 125762306a36Sopenharmony_ci ivtv_yuv_filter(itv, h_filter, v_filter_1, v_filter_2); 125862306a36Sopenharmony_ci 125962306a36Sopenharmony_ci /* and clear a few registers */ 126062306a36Sopenharmony_ci write_reg(0, 0x02814); 126162306a36Sopenharmony_ci write_reg(0, 0x0282c); 126262306a36Sopenharmony_ci write_reg(0, 0x02904); 126362306a36Sopenharmony_ci write_reg(0, 0x02910); 126462306a36Sopenharmony_ci 126562306a36Sopenharmony_ci /* Release the blanking buffer */ 126662306a36Sopenharmony_ci if (yi->blanking_ptr) { 126762306a36Sopenharmony_ci kfree(yi->blanking_ptr); 126862306a36Sopenharmony_ci yi->blanking_ptr = NULL; 126962306a36Sopenharmony_ci dma_unmap_single(&itv->pdev->dev, yi->blanking_dmaptr, 127062306a36Sopenharmony_ci 720 * 16, DMA_TO_DEVICE); 127162306a36Sopenharmony_ci } 127262306a36Sopenharmony_ci 127362306a36Sopenharmony_ci /* Invalidate the old dimension information */ 127462306a36Sopenharmony_ci yi->old_frame_info.src_w = 0; 127562306a36Sopenharmony_ci yi->old_frame_info.src_h = 0; 127662306a36Sopenharmony_ci yi->old_frame_info_args.src_w = 0; 127762306a36Sopenharmony_ci yi->old_frame_info_args.src_h = 0; 127862306a36Sopenharmony_ci 127962306a36Sopenharmony_ci /* All done. */ 128062306a36Sopenharmony_ci clear_bit(IVTV_F_I_DECODING_YUV, &itv->i_flags); 128162306a36Sopenharmony_ci} 1282