57 static int valid_service_line(
int field,
int line,
int is_pal)
59 return (is_pal && line >= 6 && (line != 23 || field == 0)) ||
60 (!is_pal && line >= 10 && line < 22);
63 static u16 select_service_from_set(
int field,
int line,
u16 set,
int is_pal)
68 set =
set & valid_set;
69 if (
set == 0 || !valid_service_line(field, line, is_pal)) {
84 for (i = 0; i < 32; i++) {
97 for (f = 0; f < 2; f++) {
98 for (l = 0; l < 24; l++) {
108 for (f = 0; f < 2; f++) {
109 for (l = 0; l < 24; l++) {
120 for (f = 0; f < 2; f++) {
121 for (l = 0; l < 24; l++) {
138 int single_step = (speed == 1 || speed == -1);
141 if (speed == 0) speed = 1000;
144 if (speed == itv->
speed && !single_step)
147 if (single_step && (speed < 0) == (itv->
speed < 0)) {
155 speed = speed < 0 ? -1000 : 1000;
157 data[0] = (speed > 1000 || speed < -1000) ? 0x80000000 : 0;
158 data[0] |= (speed > 1000 || speed < -1500) ? 0x40000000 : 0;
159 data[1] = (speed < 0);
160 data[2] = speed < 0 ? 3 : 7;
166 if (speed == 1500 || speed == -1500) data[0] |= 1;
167 else if (speed == 2000 || speed == -2000) data[0] |= 2;
168 else if (speed > -1000 && speed < 0) data[0] |= (-1000 / speed);
169 else if (speed < 1000 && speed > 0) data[0] |= (1000 / speed);
182 got_sig = signal_pending(
current);
195 IVTV_DEBUG_INFO(
"Setting Speed to 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
196 data[0], data[1], data[2], data[3], data[4], data[5], data[6]);
199 speed = (speed < 0) ? -1 : 1;
206 static int ivtv_validate_speed(
int cur_speed,
int new_speed)
208 int fact = new_speed < 0 ? -1 : 1;
214 new_speed = -new_speed;
216 cur_speed = -cur_speed;
218 if (cur_speed <= new_speed) {
219 if (new_speed > 1500)
221 if (new_speed > 1000)
225 if (new_speed >= 2000)
227 if (new_speed >= 1500)
229 if (new_speed >= 1000)
234 if (new_speed == 1 || new_speed == 1000)
235 return fact * new_speed;
238 new_speed = 1000 / new_speed;
239 if (1000 / cur_speed == new_speed)
240 new_speed += (cur_speed <
s) ? -1 : 1;
241 if (new_speed > 60)
return 1000 / (fact * 60);
242 return 1000 / (fact * new_speed);
257 if (dc->
start.speed < 0)
261 if (dc->
start.speed != 500 && dc->
start.speed != 1500)
325 struct ivtv *itv = fh2id(fh)->itv;
345 static int ivtv_g_fmt_vid_cap(
struct file *file,
void *fh,
struct v4l2_format *fmt)
348 struct ivtv *itv =
id->itv;
369 static int ivtv_g_fmt_vbi_cap(
struct file *file,
void *fh,
struct v4l2_format *fmt)
371 struct ivtv *itv = fh2id(fh)->itv;
378 vbifmt->
start[0] = itv->
vbi.start[0];
379 vbifmt->
start[1] = itv->
vbi.start[1];
387 static int ivtv_g_fmt_sliced_vbi_cap(
struct file *file,
void *fh,
struct v4l2_format *fmt)
391 struct ivtv *itv =
id->itv;
410 static int ivtv_g_fmt_vid_out(
struct file *file,
void *fh,
struct v4l2_format *fmt)
413 struct ivtv *itv =
id->itv;
442 1080 * ((pixfmt->
height + 31) & ~31);
451 static int ivtv_g_fmt_vid_out_overlay(
struct file *file,
void *fh,
struct v4l2_format *fmt)
453 struct ivtv *itv = fh2id(fh)->itv;
464 winfmt->
w.top = winfmt->
w.left = 0;
470 static int ivtv_try_fmt_sliced_vbi_out(
struct file *file,
void *fh,
struct v4l2_format *fmt)
472 return ivtv_g_fmt_sliced_vbi_out(file, fh, fmt);
475 static int ivtv_try_fmt_vid_cap(
struct file *file,
void *fh,
struct v4l2_format *fmt)
478 struct ivtv *itv =
id->itv;
492 ivtv_g_fmt_vid_cap(file, fh, fmt);
498 static int ivtv_try_fmt_vbi_cap(
struct file *file,
void *fh,
struct v4l2_format *fmt)
500 return ivtv_g_fmt_vbi_cap(file, fh, fmt);
503 static int ivtv_try_fmt_sliced_vbi_cap(
struct file *file,
void *fh,
struct v4l2_format *fmt)
507 struct ivtv *itv =
id->itv;
510 return ivtv_g_fmt_sliced_vbi_cap(file, fh, fmt);
519 check_service_set(vbifmt, itv->
is_50hz);
524 static int ivtv_try_fmt_vid_out(
struct file *file,
void *fh,
struct v4l2_format *fmt)
529 int field = fmt->
fmt.
pix.field;
530 int ret = ivtv_g_fmt_vid_out(file, fh, fmt);
558 static int ivtv_try_fmt_vid_out_overlay(
struct file *file,
void *fh,
struct v4l2_format *fmt)
560 struct ivtv *itv = fh2id(fh)->itv;
562 u8 global_alpha = fmt->
fmt.
win.global_alpha;
566 ivtv_g_fmt_vid_out_overlay(file, fh, fmt);
567 fmt->
fmt.
win.chromakey = chromakey;
568 fmt->
fmt.
win.global_alpha = global_alpha;
572 static int ivtv_s_fmt_sliced_vbi_out(
struct file *file,
void *fh,
struct v4l2_format *fmt)
574 return ivtv_g_fmt_sliced_vbi_out(file, fh, fmt);
577 static int ivtv_s_fmt_vid_cap(
struct file *file,
void *fh,
struct v4l2_format *fmt)
580 struct ivtv *itv =
id->itv;
581 struct v4l2_mbus_framefmt mbus_fmt;
582 int ret = ivtv_try_fmt_vid_cap(file, fh, fmt);
583 int w = fmt->
fmt.
pix.width;
584 int h = fmt->
fmt.
pix.height;
589 if (itv->
cxhdl.width == w && itv->
cxhdl.height == h)
599 mbus_fmt.width = fmt->
fmt.
pix.width;
603 return ivtv_g_fmt_vid_cap(file, fh, fmt);
606 static int ivtv_s_fmt_vbi_cap(
struct file *file,
void *fh,
struct v4l2_format *fmt)
608 struct ivtv *itv = fh2id(fh)->itv;
612 itv->
vbi.sliced_in->service_set = 0;
615 return ivtv_g_fmt_vbi_cap(file, fh, fmt);
618 static int ivtv_s_fmt_sliced_vbi_cap(
struct file *file,
void *fh,
struct v4l2_format *fmt)
622 struct ivtv *itv =
id->itv;
623 int ret = ivtv_try_fmt_sliced_vbi_cap(file, fh, fmt);
628 check_service_set(vbifmt, itv->
is_50hz);
633 memcpy(itv->
vbi.sliced_in, vbifmt,
sizeof(*itv->
vbi.sliced_in));
637 static int ivtv_s_fmt_vid_out(
struct file *file,
void *fh,
struct v4l2_format *fmt)
640 struct ivtv *itv =
id->itv;
642 int ret = ivtv_try_fmt_vid_out(file, fh, fmt);
657 switch (fmt->
fmt.
pix.field) {
682 static int ivtv_s_fmt_vid_out_overlay(
struct file *file,
void *fh,
struct v4l2_format *fmt)
684 struct ivtv *itv = fh2id(fh)->itv;
685 int ret = ivtv_try_fmt_vid_out_overlay(file, fh, fmt);
697 struct ivtv *itv = fh2id(fh)->itv;
713 #ifdef CONFIG_VIDEO_ADV_DEBUG
714 static int ivtv_itvc(
struct ivtv *itv,
unsigned int cmd,
void *
arg)
741 struct ivtv *itv = fh2id(fh)->itv;
751 static int ivtv_s_register(
struct file *file,
void *fh,
struct v4l2_dbg_register *reg)
753 struct ivtv *itv = fh2id(fh)->itv;
764 static int ivtv_querycap(
struct file *file,
void *fh,
struct v4l2_capability *vcap)
767 struct ivtv *itv =
id->itv;
778 static int ivtv_enumaudio(
struct file *file,
void *fh,
struct v4l2_audio *
vin)
780 struct ivtv *itv = fh2id(fh)->itv;
785 static int ivtv_g_audio(
struct file *file,
void *fh,
struct v4l2_audio *
vin)
787 struct ivtv *itv = fh2id(fh)->itv;
793 static int ivtv_s_audio(
struct file *file,
void *fh,
const struct v4l2_audio *vout)
795 struct ivtv *itv = fh2id(fh)->itv;
806 static int ivtv_enumaudout(
struct file *file,
void *fh,
struct v4l2_audioout *
vin)
808 struct ivtv *itv = fh2id(fh)->itv;
814 static int ivtv_g_audout(
struct file *file,
void *fh,
struct v4l2_audioout *
vin)
816 struct ivtv *itv = fh2id(fh)->itv;
822 static int ivtv_s_audout(
struct file *file,
void *fh,
const struct v4l2_audioout *vout)
824 struct ivtv *itv = fh2id(fh)->itv;
831 static int ivtv_enum_input(
struct file *file,
void *fh,
struct v4l2_input *
vin)
833 struct ivtv *itv = fh2id(fh)->itv;
839 static int ivtv_enum_output(
struct file *file,
void *fh,
struct v4l2_output *vout)
841 struct ivtv *itv = fh2id(fh)->itv;
846 static int ivtv_cropcap(
struct file *file,
void *fh,
struct v4l2_cropcap *cropcap)
849 struct ivtv *itv =
id->itv;
853 streamtype =
id->type;
858 cropcap->
bounds.width = 720;
868 cropcap->
bounds.width = 720;
883 static int ivtv_s_crop(
struct file *file,
void *fh,
const struct v4l2_crop *crop)
886 struct ivtv *itv =
id->itv;
890 streamtype =
id->type;
899 crop->
c.width, crop->
c.height, crop->
c.left, crop->
c.top)) {
909 static int ivtv_g_crop(
struct file *file,
void *fh,
struct v4l2_crop *crop)
912 struct ivtv *itv =
id->itv;
916 streamtype =
id->type;
929 static int ivtv_enum_fmt_vid_cap(
struct file *file,
void *fh,
struct v4l2_fmtdesc *fmt)
941 struct ivtv *itv = fh2id(fh)->itv;
955 static int ivtv_enum_fmt_vid_out(
struct file *file,
void *fh,
struct v4l2_fmtdesc *fmt)
967 struct ivtv *itv = fh2id(fh)->itv;
981 static int ivtv_g_input(
struct file *file,
void *fh,
unsigned int *i)
983 struct ivtv *itv = fh2id(fh)->itv;
992 struct ivtv *itv = fh2id(fh)->itv;
1021 itv->
streams[i].vdev->tvnorms = std;
1033 static int ivtv_g_output(
struct file *file,
void *fh,
unsigned int *i)
1035 struct ivtv *itv = fh2id(fh)->itv;
1045 static int ivtv_s_output(
struct file *file,
void *fh,
unsigned int outp)
1047 struct ivtv *itv = fh2id(fh)->itv;
1049 if (outp >= itv->
card->nof_outputs)
1062 itv->
card->video_outputs[outp].video_output, 0);
1067 static int ivtv_g_frequency(
struct file *file,
void *fh,
struct v4l2_frequency *
vf)
1069 struct ivtv *itv = fh2id(fh)->itv;
1072 if (s->
vdev->vfl_dir)
1083 struct ivtv *itv = fh2id(fh)->itv;
1086 if (s->
vdev->vfl_dir)
1098 static int ivtv_g_std(
struct file *file,
void *fh,
v4l2_std_id *
std)
1100 struct ivtv *itv = fh2id(fh)->itv;
1112 itv->
cxhdl.width = 720;
1116 itv->
vbi.start[1] = itv->
is_50hz ? 318 : 273;
1119 itv->
vbi.sliced_decoder_line_size = itv->
is_60hz ? 272 : 284;
1144 for (f = 0; f < 4; f++) {
1155 IVTV_WARN(
"Mode change failed to sync to decoder\n");
1173 struct ivtv *itv = fh2id(fh)->itv;
1178 if (*std == itv->
std)
1190 (
unsigned long long)itv->
std);
1199 static int ivtv_s_tuner(
struct file *file,
void *fh,
struct v4l2_tuner *vt)
1202 struct ivtv *itv =
id->itv;
1212 static int ivtv_g_tuner(
struct file *file,
void *fh,
struct v4l2_tuner *vt)
1214 struct ivtv *itv = fh2id(fh)->itv;
1230 struct ivtv *itv = fh2id(fh)->itv;
1235 for (f = 0; f < 2; f++) {
1236 for (l = 0; l < 24; l++) {
1237 if (valid_service_line(f, l, itv->
is_50hz))
1256 for (f = 0; f < 2; f++)
1257 for (l = 0; l < 24; l++)
1263 static int ivtv_g_enc_index(
struct file *file,
void *fh,
struct v4l2_enc_idx *
idx)
1265 struct ivtv *itv = fh2id(fh)->itv;
1278 for (i = 0; i <
entries; i++) {
1289 static int ivtv_encoder_cmd(
struct file *file,
void *fh,
struct v4l2_encoder_cmd *enc)
1292 struct ivtv *itv =
id->itv;
1341 static int ivtv_try_encoder_cmd(
struct file *file,
void *fh,
struct v4l2_encoder_cmd *enc)
1343 struct ivtv *itv = fh2id(fh)->itv;
1373 struct ivtv *itv = fh2id(fh)->itv;
1406 data[0] |= (
read_reg(0x2a00) >> 7) & 0x40;
1407 pixfmt = (data[0] >> 3) & 0xf;
1409 fb->
fmt.pixelformat = pixel_format[pixfmt];
1413 fb->
fmt.bytesperline = fb->
fmt.width;
1418 fb->
fmt.bytesperline *= 2;
1421 fb->
fmt.bytesperline *= 2;
1422 fb->
fmt.sizeimage = fb->
fmt.bytesperline * fb->
fmt.height;
1438 if (pixfmt == 1 || pixfmt > 4)
1442 if (pixfmt == 2 || pixfmt == 3)
1449 if (pixfmt == 2 || pixfmt == 3)
1458 static int ivtv_s_fbuf(
struct file *file,
void *fh,
const struct v4l2_framebuffer *fb)
1461 struct ivtv *itv =
id->itv;
1478 static int ivtv_overlay(
struct file *file,
void *fh,
unsigned int on)
1481 struct ivtv *itv =
id->itv;
1493 switch (sub->
type) {
1504 static int ivtv_log_status(
struct file *file,
void *fh)
1506 struct ivtv *itv = fh2id(fh)->itv;
1523 IVTV_INFO(
"Video Input: %s\n", vidin.name);
1524 IVTV_INFO(
"Audio Input: %s%s\n", audin.name,
1530 static const char *
const output_modes[5] = {
1537 static const char *
const alpha_mode[4] = {
1543 static const char *
const pixel_format[16] = {
1564 IVTV_INFO(
"Video Output: %s\n", vidout.name);
1567 IVTV_INFO(
"Output Mode: %s\n", output_modes[mode]);
1569 data[0] |= (
read_reg(0x2a00) >> 7) & 0x40;
1570 IVTV_INFO(
"Overlay: %s, Alpha: %s, Pixel Format: %s\n",
1571 data[0] & 1 ?
"On" :
"Off",
1572 alpha_mode[(data[0] >> 1) & 0x3],
1573 pixel_format[(data[0] >> 3) & 0xf]);
1584 IVTV_INFO(
"Stream %s: status 0x%04lx, %d%% of %d KiB (%d buffers) in use\n", s->
name, s->
s_flags,
1589 IVTV_INFO(
"Read MPG/VBI: %lld/%lld bytes\n",
1595 static int ivtv_decoder_cmd(
struct file *file,
void *fh,
struct v4l2_decoder_cmd *dec)
1598 struct ivtv *itv =
id->itv;
1601 return ivtv_video_command(itv,
id, dec,
false);
1604 static int ivtv_try_decoder_cmd(
struct file *file,
void *fh,
struct v4l2_decoder_cmd *dec)
1607 struct ivtv *itv =
id->itv;
1610 return ivtv_video_command(itv,
id, dec,
true);
1613 static int ivtv_decoder_ioctls(
struct file *filp,
unsigned int cmd,
void *arg)
1616 struct ivtv *itv =
id->itv;
1619 unsigned long iarg = (
unsigned long)arg;
1684 memset(&dc, 0,
sizeof(dc));
1686 return ivtv_video_command(itv,
id, &dc, 0);
1693 memset(&dc, 0,
sizeof(dc));
1696 return ivtv_video_command(itv,
id, &dc, 0);
1703 memset(&dc, 0,
sizeof(dc));
1705 return ivtv_video_command(itv,
id, &dc, 0);
1712 memset(&dc, 0,
sizeof(dc));
1714 return ivtv_video_command(itv,
id, &dc, 0);
1728 return ivtv_video_command(itv,
id, dc,
try);
1738 memset(ev, 0,
sizeof(*ev));
1768 if (signal_pending(
current)) {
1806 static long ivtv_default(
struct file *file,
void *fh,
bool valid_prio,
1809 struct ivtv *itv = fh2id(fh)->itv;
1831 if ((val == 0 && itv->
options.newi2c) || (val & 0x01))
1853 return ivtv_decoder_ioctls(file, cmd, (
void *)arg);
1862 .vidioc_querycap = ivtv_querycap,
1863 .vidioc_s_audio = ivtv_s_audio,
1864 .vidioc_g_audio = ivtv_g_audio,
1865 .vidioc_enumaudio = ivtv_enumaudio,
1866 .vidioc_s_audout = ivtv_s_audout,
1867 .vidioc_g_audout = ivtv_g_audout,
1868 .vidioc_enum_input = ivtv_enum_input,
1869 .vidioc_enum_output = ivtv_enum_output,
1870 .vidioc_enumaudout = ivtv_enumaudout,
1871 .vidioc_cropcap = ivtv_cropcap,
1872 .vidioc_s_crop = ivtv_s_crop,
1873 .vidioc_g_crop = ivtv_g_crop,
1874 .vidioc_g_input = ivtv_g_input,
1876 .vidioc_g_output = ivtv_g_output,
1877 .vidioc_s_output = ivtv_s_output,
1878 .vidioc_g_frequency = ivtv_g_frequency,
1880 .vidioc_s_tuner = ivtv_s_tuner,
1881 .vidioc_g_tuner = ivtv_g_tuner,
1882 .vidioc_g_enc_index = ivtv_g_enc_index,
1883 .vidioc_g_fbuf = ivtv_g_fbuf,
1884 .vidioc_s_fbuf = ivtv_s_fbuf,
1885 .vidioc_g_std = ivtv_g_std,
1887 .vidioc_overlay = ivtv_overlay,
1888 .vidioc_log_status = ivtv_log_status,
1889 .vidioc_enum_fmt_vid_cap = ivtv_enum_fmt_vid_cap,
1890 .vidioc_encoder_cmd = ivtv_encoder_cmd,
1891 .vidioc_try_encoder_cmd = ivtv_try_encoder_cmd,
1892 .vidioc_decoder_cmd = ivtv_decoder_cmd,
1893 .vidioc_try_decoder_cmd = ivtv_try_decoder_cmd,
1894 .vidioc_enum_fmt_vid_out = ivtv_enum_fmt_vid_out,
1895 .vidioc_g_fmt_vid_cap = ivtv_g_fmt_vid_cap,
1896 .vidioc_g_fmt_vbi_cap = ivtv_g_fmt_vbi_cap,
1897 .vidioc_g_fmt_sliced_vbi_cap = ivtv_g_fmt_sliced_vbi_cap,
1898 .vidioc_g_fmt_vid_out = ivtv_g_fmt_vid_out,
1899 .vidioc_g_fmt_vid_out_overlay = ivtv_g_fmt_vid_out_overlay,
1900 .vidioc_g_fmt_sliced_vbi_out = ivtv_g_fmt_sliced_vbi_out,
1901 .vidioc_s_fmt_vid_cap = ivtv_s_fmt_vid_cap,
1902 .vidioc_s_fmt_vbi_cap = ivtv_s_fmt_vbi_cap,
1903 .vidioc_s_fmt_sliced_vbi_cap = ivtv_s_fmt_sliced_vbi_cap,
1904 .vidioc_s_fmt_vid_out = ivtv_s_fmt_vid_out,
1905 .vidioc_s_fmt_vid_out_overlay = ivtv_s_fmt_vid_out_overlay,
1906 .vidioc_s_fmt_sliced_vbi_out = ivtv_s_fmt_sliced_vbi_out,
1907 .vidioc_try_fmt_vid_cap = ivtv_try_fmt_vid_cap,
1908 .vidioc_try_fmt_vbi_cap = ivtv_try_fmt_vbi_cap,
1909 .vidioc_try_fmt_sliced_vbi_cap = ivtv_try_fmt_sliced_vbi_cap,
1910 .vidioc_try_fmt_vid_out = ivtv_try_fmt_vid_out,
1911 .vidioc_try_fmt_vid_out_overlay = ivtv_try_fmt_vid_out_overlay,
1912 .vidioc_try_fmt_sliced_vbi_out = ivtv_try_fmt_sliced_vbi_out,
1913 .vidioc_g_sliced_vbi_cap = ivtv_g_sliced_vbi_cap,
1914 .vidioc_g_chip_ident = ivtv_g_chip_ident,
1915 #ifdef CONFIG_VIDEO_ADV_DEBUG
1916 .vidioc_g_register = ivtv_g_register,
1917 .vidioc_s_register = ivtv_s_register,
1919 .vidioc_default = ivtv_default,
1920 .vidioc_subscribe_event = ivtv_subscribe_event,