Lines Matching +full:standard +full:- +full:vt

1 // SPDX-License-Identifier: GPL-2.0+
2 // saa711x - Philips SAA711x video decoder driver
23 // Copyright (c) 2005-2006 Mauro Carvalho Chehab <mchehab@kernel.org>
33 #include <media/v4l2-device.h>
34 #include <media/v4l2-ctrls.h>
35 #include <media/v4l2-mc.h>
49 MODULE_PARM_DESC(debug, "Debug level (0-1)");
104 return &container_of(ctrl->handler, struct saa711x_state, hdl)->sd; in to_sd()
107 /* ----------------------------------------------------------------------- */
164 filled with 0 - seems better not to touch on they */ in saa711x_writeregs()
165 if (saa711x_has_reg(state->ident, reg)) { in saa711x_writeregs()
167 return -1; in saa711x_writeregs()
182 /* ----------------------------------------------------------------------- */
205 R_0B_LUMA_CONTRAST_CNTL, 0x47, /* 0b - CONT=1.109 */
208 R_0E_CHROMA_CNTL_1, 0x01, /* 0e - CDTO=0, CSTD=0, DCCF=0,
211 R_10_CHROMA_CNTL_2, 0x48, /* 10 - OFTS=1, HDEL=0, VRLN=1, YDEL=0 */
212 R_11_MODE_DELAY_CNTL, 0x1c, /* 11 - GPSW=0, CM99=0, FECO=0, COMPO=1,
214 R_12_RT_SIGNAL_CNTL, 0x00, /* 12 - output control 2 */
215 R_13_RT_X_PORT_OUT_CNTL, 0x00, /* 13 - output control 3 */
240 R_06_H_SYNC_START, 0x89, /* Illegal value -119,
241 * min. value = -108 (0x94) */
306 /* Front-End Part */
312 R_06_H_SYNC_START, 0xeb, /* horiz sync begin = -21 */
313 R_07_H_SYNC_STOP, 0xe0, /* horiz sync stop = -17 */
315 R_0A_LUMA_BRIGHT_CNTL, 0x80, /* was 0x88. decoder brightness, 0x80 is itu standard */
316 R_0B_LUMA_CONTRAST_CNTL, 0x44, /* was 0x48. decoder contrast, 0x44 is itu standard */
317 R_0C_CHROMA_SAT_CNTL, 0x40, /* was 0x47. decoder saturation, 0x40 is itu standard */
323 R_13_RT_X_PORT_OUT_CNTL, 0x80, /* ITU656 standard mode, RTCO output enable RTCE */
343 R_87_I_PORT_I_O_ENA_OUT_CLK_AND_GATED, 0x00, /* disable I-port output */
346 R_87_I_PORT_I_O_ENA_OUT_CLK_AND_GATED, 0x01, /* enable I-port output */
363 R_5A_V_OFF_FOR_SLICER, 0x06, /* standard 60hz value for ITU656 line counting */
436 R_5A_V_OFF_FOR_SLICER, 0x03, /* standard 50hz value */
510 R_87_I_PORT_I_O_ENA_OUT_CLK_AND_GATED, 0x01, /* Enable I-port output */
520 R_87_I_PORT_I_O_ENA_OUT_CLK_AND_GATED, 0x01, /* Enable I-port output */
659 R_02_INPUT_CNTL_1, 0xc4, /* input tuner -> input 4, amplifier active */
737 return -1; in saa711x_decode_wss()
745 return -1; in saa711x_decode_wss()
760 if (!saa711x_has_reg(state->ident, R_30_AUD_MAST_CLK_CYCLES_PER_FIELD)) in saa711x_s_clock_freq()
767 return -EINVAL; in saa711x_s_clock_freq()
770 hz = (state->std & V4L2_STD_525_60) ? 5994 : 5000; in saa711x_s_clock_freq()
778 do_div(f, state->crystal_freq); in saa711x_s_clock_freq()
780 if (state->ucgc) { in saa711x_s_clock_freq()
781 acpf = acpf * state->cgcdiv / 16; in saa711x_s_clock_freq()
782 acni = acni * state->cgcdiv / 16; in saa711x_s_clock_freq()
784 if (state->cgcdiv == 3) in saa711x_s_clock_freq()
787 if (state->apll) in saa711x_s_clock_freq()
790 if (state->double_asclk) { in saa711x_s_clock_freq()
795 saa711x_write(sd, R_39_CLK_RATIO_ASCLK_TO_ALRCLK, 0x10 << state->double_asclk); in saa711x_s_clock_freq()
807 state->audclk_freq = freq; in saa711x_s_clock_freq()
816 switch (ctrl->id) { in saa711x_g_volatile_ctrl()
819 if (state->agc->val) in saa711x_g_volatile_ctrl()
820 state->gain->val = in saa711x_g_volatile_ctrl()
832 switch (ctrl->id) { in saa711x_s_ctrl()
834 saa711x_write(sd, R_0A_LUMA_BRIGHT_CNTL, ctrl->val); in saa711x_s_ctrl()
838 saa711x_write(sd, R_0B_LUMA_CONTRAST_CNTL, ctrl->val); in saa711x_s_ctrl()
842 saa711x_write(sd, R_0C_CHROMA_SAT_CNTL, ctrl->val); in saa711x_s_ctrl()
846 saa711x_write(sd, R_0D_CHROMA_HUE_CNTL, ctrl->val); in saa711x_s_ctrl()
851 if (state->agc->val) in saa711x_s_ctrl()
852 saa711x_write(sd, R_0F_CHROMA_GAIN_CNTL, state->gain->val); in saa711x_s_ctrl()
854 saa711x_write(sd, R_0F_CHROMA_GAIN_CNTL, state->gain->val | 0x80); in saa711x_s_ctrl()
858 return -EINVAL; in saa711x_s_ctrl()
870 int is_50hz = state->std & V4L2_STD_625_50; in saa711x_set_size()
877 return -EINVAL; in saa711x_set_size()
879 return -EINVAL; in saa711x_set_size()
881 if (!saa711x_has_reg(state->ident, R_D0_B_HORIZ_PRESCALING)) { in saa711x_set_size()
884 return -EINVAL; in saa711x_set_size()
886 return -EINVAL; in saa711x_set_size()
889 state->width = width; in saa711x_set_size()
890 state->height = height; in saa711x_set_size()
892 if (!saa711x_has_reg(state->ident, R_CC_B_HORIZ_OUTPUT_WINDOW_LENGTH)) in saa711x_set_size()
909 res += (VRES_60HZ - 480) >> 1; in saa711x_set_size()
929 /* write H fine-scaling (luminance) */ in saa711x_set_size()
934 /* write H fine-scaling (chrominance) in saa711x_set_size()
950 /* write V fine-scaling (luminance) */ in saa711x_set_size()
955 /* write V fine-scaling (chrominance) */ in saa711x_set_size()
974 /* Prevent unnecessary standard changes. During a standard in saa711x_set_v4lstd()
975 change the I-Port is temporarily disabled. Any devices in saa711x_set_v4lstd()
980 side-effect here. */ in saa711x_set_v4lstd()
981 if (std == state->std) in saa711x_set_v4lstd()
984 state->std = std; in saa711x_set_v4lstd()
986 // This works for NTSC-M, SECAM-L and the 50Hz PAL variants. in saa711x_set_v4lstd()
988 v4l2_dbg(1, debug, sd, "decoder set standard 60 Hz\n"); in saa711x_set_v4lstd()
989 if (state->ident == GM7113C) { in saa711x_set_v4lstd()
999 v4l2_dbg(1, debug, sd, "decoder set standard 50 Hz\n"); in saa711x_set_v4lstd()
1000 if (state->ident == GM7113C) { in saa711x_set_v4lstd()
1010 /* Register 0E - Bits D6-D4 on NO-AUTO mode in saa711x_set_v4lstd()
1015 010 Combination-PAL N (3.58MHz) NTSC 4.43 (60 Hz) in saa711x_set_v4lstd()
1017 100 reserved NTSC-Japan (3.58MHz) in saa711x_set_v4lstd()
1019 if (state->ident <= SAA7113 || in saa711x_set_v4lstd()
1020 state->ident == GM7113C) { in saa711x_set_v4lstd()
1039 if (taskb && state->ident == SAA7114) in saa711x_set_v4lstd()
1043 saa711x_s_clock_freq(sd, state->audclk_freq); in saa711x_set_v4lstd()
1051 int is_50hz = (state->std & V4L2_STD_625_50); in saa711x_set_lcr()
1057 if (!saa711x_has_reg(state->ident, R_41_LCR_BASE)) in saa711x_set_lcr()
1061 /* SAA7113 and SAA7118 also should support VBI - Need testing */ in saa711x_set_lcr()
1062 if (state->ident != SAA7115) in saa711x_set_lcr()
1082 fmt->service_lines[0][i] = in saa711x_set_lcr()
1083 fmt->service_lines[1][i] = 0; in saa711x_set_lcr()
1087 fmt->service_lines[0][i] = in saa711x_set_lcr()
1088 fmt->service_lines[1][i] = 0; in saa711x_set_lcr()
1090 fmt->service_lines[0][i] = in saa711x_set_lcr()
1091 fmt->service_lines[1][i] = 0; in saa711x_set_lcr()
1098 switch (fmt->service_lines[1-x][i]) { in saa711x_set_lcr()
1121 saa711x_write(sd, i - 2 + R_41_LCR_BASE, lcr[i]); in saa711x_set_lcr()
1141 memset(sliced->service_lines, 0, sizeof(sliced->service_lines)); in saa711x_g_sliced_fmt()
1142 sliced->service_set = 0; in saa711x_g_sliced_fmt()
1147 u8 v = saa711x_read(sd, i - 2 + R_41_LCR_BASE); in saa711x_g_sliced_fmt()
1149 sliced->service_lines[0][i] = lcr2vbi[v >> 4]; in saa711x_g_sliced_fmt()
1150 sliced->service_lines[1][i] = lcr2vbi[v & 0xf]; in saa711x_g_sliced_fmt()
1151 sliced->service_set |= in saa711x_g_sliced_fmt()
1152 sliced->service_lines[0][i] | sliced->service_lines[1][i]; in saa711x_g_sliced_fmt()
1173 struct v4l2_mbus_framefmt *fmt = &format->format; in saa711x_set_fmt()
1175 if (format->pad || fmt->code != MEDIA_BUS_FMT_FIXED) in saa711x_set_fmt()
1176 return -EINVAL; in saa711x_set_fmt()
1177 fmt->field = V4L2_FIELD_INTERLACED; in saa711x_set_fmt()
1178 fmt->colorspace = V4L2_COLORSPACE_SMPTE170M; in saa711x_set_fmt()
1179 if (format->which == V4L2_SUBDEV_FORMAT_TRY) in saa711x_set_fmt()
1181 return saa711x_set_size(sd, fmt->width, fmt->height); in saa711x_set_fmt()
1188 headers. The vbi->p pointer points to the R_5E_SDID byte right after the SAV
1196 u8 *p = vbi->p; in saa711x_decode_vbi_line()
1200 vbi->type = 0; /* mark result as a failure */ in saa711x_decode_vbi_line()
1204 if (state->std & V4L2_STD_525_60) in saa711x_decode_vbi_line()
1209 vbi->p = p; in saa711x_decode_vbi_line()
1211 /* calculate field and line number of the VBI packet (1-23) */ in saa711x_decode_vbi_line()
1212 vbi->is_second_field = ((id1 & 0x40) != 0); in saa711x_decode_vbi_line()
1213 vbi->line = (id1 & 0x3f) << 3; in saa711x_decode_vbi_line()
1214 vbi->line |= (id2 & 0x70) >> 4; in saa711x_decode_vbi_line()
1227 vbi->type = V4L2_SLICED_TELETEXT_B; in saa711x_decode_vbi_line()
1232 vbi->type = V4L2_SLICED_CAPTION_525; in saa711x_decode_vbi_line()
1236 if (wss == -1) in saa711x_decode_vbi_line()
1240 vbi->type = V4L2_SLICED_WSS_625; in saa711x_decode_vbi_line()
1245 vbi->type = V4L2_SLICED_VPS; in saa711x_decode_vbi_line()
1255 static int saa711x_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt) in saa711x_g_tuner() argument
1260 if (state->radio) in saa711x_g_tuner()
1265 vt->signal = ((status & (1 << 6)) == 0) ? 0xffff : 0x0; in saa711x_g_tuner()
1273 state->radio = 0; in saa711x_s_std()
1282 state->radio = 1; in saa711x_s_radio()
1290 u8 mask = (state->ident <= SAA7111A) ? 0xf8 : 0xf0; in saa711x_s_routing()
1296 if ((state->ident <= SAA7113 || in saa711x_s_routing()
1297 state->ident == GM7113C) && in saa711x_s_routing()
1300 return -EINVAL; in saa711x_s_routing()
1303 return -EINVAL; in saa711x_s_routing()
1304 if (state->input == input && state->output == output) in saa711x_s_routing()
1307 (input >= SAA7115_SVIDEO0) ? "S-Video" : "Composite", in saa711x_s_routing()
1309 state->input = input; in saa711x_s_routing()
1312 if (state->ident <= SAA7111A) { in saa711x_s_routing()
1314 input -= 2; in saa711x_s_routing()
1329 /* bypass chrominance trap for S-Video modes */ in saa711x_s_routing()
1332 (state->input >= SAA7115_SVIDEO0 ? 0x80 : 0x0)); in saa711x_s_routing()
1334 state->output = output; in saa711x_s_routing()
1335 if (state->ident == SAA7114 || in saa711x_s_routing()
1336 state->ident == SAA7115) { in saa711x_s_routing()
1339 (state->output & 0x01)); in saa711x_s_routing()
1341 if (state->ident > SAA7111A) { in saa711x_s_routing()
1354 if (state->ident > SAA7111A) in saa711x_s_gpio()
1355 return -EINVAL; in saa711x_s_gpio()
1368 if (state->enable == enable) in saa711x_s_stream()
1370 state->enable = enable; in saa711x_s_stream()
1371 if (!saa711x_has_reg(state->ident, R_87_I_PORT_I_O_ENA_OUT_CLK_AND_GATED)) in saa711x_s_stream()
1373 saa711x_write(sd, R_87_I_PORT_I_O_ENA_OUT_CLK_AND_GATED, state->enable); in saa711x_s_stream()
1382 return -EINVAL; in saa711x_s_crystal_freq()
1383 state->crystal_freq = freq; in saa711x_s_crystal_freq()
1384 state->double_asclk = flags & SAA7115_FREQ_FL_DOUBLE_ASCLK; in saa711x_s_crystal_freq()
1385 state->cgcdiv = (flags & SAA7115_FREQ_FL_CGCDIV) ? 3 : 4; in saa711x_s_crystal_freq()
1386 state->ucgc = flags & SAA7115_FREQ_FL_UCGC; in saa711x_s_crystal_freq()
1387 state->apll = flags & SAA7115_FREQ_FL_APLL; in saa711x_s_crystal_freq()
1388 saa711x_s_clock_freq(sd, state->audclk_freq); in saa711x_s_crystal_freq()
1402 so data->field 0 maps to the saa7115 even field, in saa711x_g_vbi_data()
1404 switch (data->id) { in saa711x_g_vbi_data()
1407 return -EIO; in saa711x_g_vbi_data()
1408 data->data[0] = saa711x_read(sd, 0x6c); in saa711x_g_vbi_data()
1409 data->data[1] = saa711x_read(sd, 0x6d); in saa711x_g_vbi_data()
1412 if (data->field == 0) { in saa711x_g_vbi_data()
1415 return -EIO; in saa711x_g_vbi_data()
1416 data->data[0] = saa711x_read(sd, 0x69); in saa711x_g_vbi_data()
1417 data->data[1] = saa711x_read(sd, 0x6a); in saa711x_g_vbi_data()
1422 return -EIO; in saa711x_g_vbi_data()
1423 data->data[0] = saa711x_read(sd, 0x67); in saa711x_g_vbi_data()
1424 data->data[1] = saa711x_read(sd, 0x68); in saa711x_g_vbi_data()
1427 return -EINVAL; in saa711x_g_vbi_data()
1444 if (state->ident == SAA7115) { in saa711x_querystd()
1457 * other PAL standard. in saa711x_querystd()
1498 if (state->ident == SAA7115) in saa711x_g_input_status()
1509 reg->val = saa711x_read(sd, reg->reg & 0xff); in saa711x_g_register()
1510 reg->size = 1; in saa711x_g_register()
1516 saa711x_write(sd, reg->reg & 0xff, reg->val & 0xff); in saa711x_s_register()
1528 v4l2_info(sd, "Audio frequency: %d Hz\n", state->audclk_freq); in saa711x_log_status()
1529 if (state->ident != SAA7115) { in saa711x_log_status()
1545 if (state->input >= 6) in saa711x_log_status()
1546 v4l2_info(sd, "Input: S-Video %d\n", state->input - 6); in saa711x_log_status()
1548 v4l2_info(sd, "Input: Composite %d\n", state->input); in saa711x_log_status()
1566 v4l2_info(sd, "Width, Height: %d, %d\n", state->width, state->height); in saa711x_log_status()
1567 v4l2_ctrl_handler_log_status(&state->hdl, sd->name); in saa711x_log_status()
1571 /* ----------------------------------------------------------------------- */
1629 /* ----------------------------------------------------------------------- */
1634 struct v4l2_subdev *sd = &state->sd; in saa711x_write_platform_data()
1637 if (state->ident != GM7113C && in saa711x_write_platform_data()
1638 state->ident != SAA7113) in saa711x_write_platform_data()
1641 if (data->saa7113_r08_htc) { in saa711x_write_platform_data()
1644 work |= ((*data->saa7113_r08_htc) << SAA7113_R_08_HTC_OFFSET); in saa711x_write_platform_data()
1648 if (data->saa7113_r10_vrln) { in saa711x_write_platform_data()
1651 if (*data->saa7113_r10_vrln) in saa711x_write_platform_data()
1656 if (data->saa7113_r10_ofts) { in saa711x_write_platform_data()
1659 work |= (*data->saa7113_r10_ofts << SAA7113_R_10_OFTS_OFFSET); in saa711x_write_platform_data()
1663 if (data->saa7113_r12_rts0) { in saa711x_write_platform_data()
1666 work |= (*data->saa7113_r12_rts0 << SAA7113_R_12_RTS0_OFFSET); in saa711x_write_platform_data()
1670 WARN_ON(*data->saa7113_r12_rts0 == SAA7113_RTS_DOT_IN); in saa711x_write_platform_data()
1674 if (data->saa7113_r12_rts1) { in saa711x_write_platform_data()
1677 work |= (*data->saa7113_r12_rts1 << SAA7113_R_12_RTS1_OFFSET); in saa711x_write_platform_data()
1681 if (data->saa7113_r13_adlsb) { in saa711x_write_platform_data()
1684 if (*data->saa7113_r13_adlsb) in saa711x_write_platform_data()
1691 * saa711x_detect_chip - Detects the saa711x (or clone) variant
1697 * if 'id' is NULL or id->driver_data is equal to 1, it auto-probes
1699 * If the tuner is not found, it returns -ENODEV.
1700 * If auto-detection is disabled and the tuner doesn't match what it was
1701 * required, it returns -EINVAL and fills 'name'.
1713 autodetect = !id || id->driver_data == 1; in saa711x_detect_chip()
1721 name[i] += 'a' - '9' - 1; in saa711x_detect_chip()
1730 if (!autodetect && strcmp(name, id->name)) in saa711x_detect_chip()
1731 return -EINVAL; in saa711x_detect_chip()
1751 "WARNING: Philips/NXP chip unknown - Falling back to saa7111\n"); in saa711x_detect_chip()
1776 if (!autodetect && strcmp(name, id->name)) in saa711x_detect_chip()
1777 return -EINVAL; in saa711x_detect_chip()
1781 name, 16, chip_ver, client->addr << 1); in saa711x_detect_chip()
1790 if (!autodetect && strcmp(name, id->name)) in saa711x_detect_chip()
1791 return -EINVAL; in saa711x_detect_chip()
1795 name, 16, chip_ver, client->addr << 1); in saa711x_detect_chip()
1797 /* CJC7113 seems to be SAA7113-compatible */ in saa711x_detect_chip()
1803 16, chip_ver, client->addr << 1); in saa711x_detect_chip()
1804 return -ENODEV; in saa711x_detect_chip()
1821 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) in saa711x_probe()
1822 return -EIO; in saa711x_probe()
1825 if (ident == -EINVAL) { in saa711x_probe()
1828 name, id->name); in saa711x_probe()
1829 return -ENODEV; in saa711x_probe()
1834 strscpy(client->name, name, sizeof(client->name)); in saa711x_probe()
1836 state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL); in saa711x_probe()
1838 return -ENOMEM; in saa711x_probe()
1839 sd = &state->sd; in saa711x_probe()
1843 state->pads[SAA711X_PAD_IF_INPUT].flags = MEDIA_PAD_FL_SINK; in saa711x_probe()
1844 state->pads[SAA711X_PAD_IF_INPUT].sig_type = PAD_SIGNAL_ANALOG; in saa711x_probe()
1845 state->pads[SAA711X_PAD_VID_OUT].flags = MEDIA_PAD_FL_SOURCE; in saa711x_probe()
1846 state->pads[SAA711X_PAD_VID_OUT].sig_type = PAD_SIGNAL_DV; in saa711x_probe()
1848 sd->entity.function = MEDIA_ENT_F_ATV_DECODER; in saa711x_probe()
1850 ret = media_entity_pads_init(&sd->entity, SAA711X_NUM_PADS, in saa711x_probe()
1851 state->pads); in saa711x_probe()
1857 client->addr << 1, client->adapter->name); in saa711x_probe()
1858 hdl = &state->hdl; in saa711x_probe()
1868 V4L2_CID_HUE, -128, 127, 1, 0); in saa711x_probe()
1869 state->agc = v4l2_ctrl_new_std(hdl, &saa711x_ctrl_ops, in saa711x_probe()
1871 state->gain = v4l2_ctrl_new_std(hdl, &saa711x_ctrl_ops, in saa711x_probe()
1873 sd->ctrl_handler = hdl; in saa711x_probe()
1874 if (hdl->error) { in saa711x_probe()
1875 int err = hdl->error; in saa711x_probe()
1880 v4l2_ctrl_auto_cluster(2, &state->agc, 0, true); in saa711x_probe()
1882 state->input = -1; in saa711x_probe()
1883 state->output = SAA7115_IPORT_ON; in saa711x_probe()
1884 state->enable = 1; in saa711x_probe()
1885 state->radio = 0; in saa711x_probe()
1886 state->ident = ident; in saa711x_probe()
1888 state->audclk_freq = 48000; in saa711x_probe()
1893 state->crystal_freq = SAA7115_FREQ_24_576_MHZ; in saa711x_probe()
1894 pdata = client->dev.platform_data; in saa711x_probe()
1895 switch (state->ident) { in saa711x_probe()
1904 if (pdata && pdata->saa7113_force_gm7113c_init) in saa711x_probe()
1910 state->crystal_freq = SAA7115_FREQ_32_11_MHZ; in saa711x_probe()
1913 if (state->ident > SAA7111A && state->ident != GM7113C) in saa711x_probe()
1928 /* ----------------------------------------------------------------------- */
1935 v4l2_ctrl_handler_free(sd->ctrl_handler); in saa711x_remove()