Lines Matching +full:sd +full:- +full:lines
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)");
69 struct v4l2_subdev sd; member
97 static inline struct saa711x_state *to_state(struct v4l2_subdev *sd) in to_state() argument
99 return container_of(sd, struct saa711x_state, sd); in to_state()
104 return &container_of(ctrl->handler, struct saa711x_state, hdl)->sd; in to_sd()
107 /* ----------------------------------------------------------------------- */
109 static inline int saa711x_write(struct v4l2_subdev *sd, u8 reg, u8 value) in saa711x_write() argument
111 struct i2c_client *client = v4l2_get_subdevdata(sd); in saa711x_write()
154 static int saa711x_writeregs(struct v4l2_subdev *sd, const unsigned char *regs) in saa711x_writeregs() argument
156 struct saa711x_state *state = to_state(sd); in saa711x_writeregs()
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()
166 if (saa711x_write(sd, reg, data) < 0) in saa711x_writeregs()
167 return -1; in saa711x_writeregs()
169 v4l2_dbg(1, debug, sd, "tried to access reserved reg 0x%02x\n", reg); in saa711x_writeregs()
175 static inline int saa711x_read(struct v4l2_subdev *sd, u8 reg) in saa711x_read() argument
177 struct i2c_client *client = v4l2_get_subdevdata(sd); in saa711x_read()
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 */
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 */
417 R_F0_LFCO_PER_LINE, 0xad, /* Set PLL Register. 60hz 525 lines per frame, 27 MHz */
495 R_F0_LFCO_PER_LINE, 0xb0, /* Set PLL Register. 50hz 625 lines per frame, 27 MHz */
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 */
544 /* note: 2 x zoom ensures that VBI lines have same length as video lines. */
625 /* PLL2 lock detection settings: 71 lines 50% phase error */
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()
750 static int saa711x_s_clock_freq(struct v4l2_subdev *sd, u32 freq) in saa711x_s_clock_freq() argument
752 struct saa711x_state *state = to_state(sd); in saa711x_s_clock_freq()
760 if (!saa711x_has_reg(state->ident, R_30_AUD_MAST_CLK_CYCLES_PER_FIELD)) in saa711x_s_clock_freq()
763 v4l2_dbg(1, debug, sd, "set audio clock freq: %d\n", freq); 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()
794 saa711x_write(sd, R_38_CLK_RATIO_AMXCLK_TO_ASCLK, 0x03); 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()
796 saa711x_write(sd, R_3A_AUD_CLK_GEN_BASIC_SETUP, acc); in saa711x_s_clock_freq()
798 saa711x_write(sd, R_30_AUD_MAST_CLK_CYCLES_PER_FIELD, acpf & 0xff); in saa711x_s_clock_freq()
799 saa711x_write(sd, R_30_AUD_MAST_CLK_CYCLES_PER_FIELD+1, in saa711x_s_clock_freq()
801 saa711x_write(sd, R_30_AUD_MAST_CLK_CYCLES_PER_FIELD+2, in saa711x_s_clock_freq()
804 saa711x_write(sd, R_34_AUD_MAST_CLK_NOMINAL_INC, acni & 0xff); in saa711x_s_clock_freq()
805 saa711x_write(sd, R_34_AUD_MAST_CLK_NOMINAL_INC+1, (acni >> 8) & 0xff); in saa711x_s_clock_freq()
806 saa711x_write(sd, R_34_AUD_MAST_CLK_NOMINAL_INC+2, (acni >> 16) & 0x3f); in saa711x_s_clock_freq()
807 state->audclk_freq = freq; in saa711x_s_clock_freq()
813 struct v4l2_subdev *sd = to_sd(ctrl); in saa711x_g_volatile_ctrl() local
814 struct saa711x_state *state = to_state(sd); in saa711x_g_volatile_ctrl()
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()
821 saa711x_read(sd, R_0F_CHROMA_GAIN_CNTL) & 0x7f; in saa711x_g_volatile_ctrl()
829 struct v4l2_subdev *sd = to_sd(ctrl); in saa711x_s_ctrl() local
830 struct saa711x_state *state = to_state(sd); in saa711x_s_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()
864 static int saa711x_set_size(struct v4l2_subdev *sd, int width, int height) in saa711x_set_size() argument
866 struct saa711x_state *state = to_state(sd); in saa711x_set_size()
870 int is_50hz = state->std & V4L2_STD_625_50; in saa711x_set_size()
873 v4l2_dbg(1, debug, sd, "decoder set size to %ix%i\n", width, height); 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()
882 /* Decoder only supports 720 columns and 480 or 576 lines */ 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()
899 saa711x_write(sd, R_CC_B_HORIZ_OUTPUT_WINDOW_LENGTH, in saa711x_set_size()
901 saa711x_write(sd, R_CD_B_HORIZ_OUTPUT_WINDOW_LENGTH_MSB, in saa711x_set_size()
909 res += (VRES_60HZ - 480) >> 1; in saa711x_set_size()
912 saa711x_write(sd, R_CE_B_VERT_OUTPUT_WINDOW_LENGTH, in saa711x_set_size()
914 saa711x_write(sd, R_CF_B_VERT_OUTPUT_WINDOW_LENGTH_MSB, in saa711x_set_size()
925 saa711x_write(sd, R_D0_B_HORIZ_PRESCALING, in saa711x_set_size()
928 v4l2_dbg(1, debug, sd, "Hpsc: 0x%05x, Hfsc: 0x%05x\n", HPSC, HFSC); in saa711x_set_size()
929 /* write H fine-scaling (luminance) */ in saa711x_set_size()
930 saa711x_write(sd, R_D8_B_HORIZ_LUMA_SCALING_INC, in saa711x_set_size()
932 saa711x_write(sd, R_D9_B_HORIZ_LUMA_SCALING_INC_MSB, in saa711x_set_size()
934 /* write H fine-scaling (chrominance) in saa711x_set_size()
936 saa711x_write(sd, R_DC_B_HORIZ_CHROMA_SCALING, in saa711x_set_size()
938 saa711x_write(sd, R_DD_B_HORIZ_CHROMA_SCALING_MSB, in saa711x_set_size()
942 v4l2_dbg(1, debug, sd, "Vsrc: %d, Vscy: 0x%05x\n", Vsrc, VSCY); in saa711x_set_size()
945 saa711x_write(sd, R_D5_B_LUMA_CONTRAST_CNTL, in saa711x_set_size()
947 saa711x_write(sd, R_D6_B_CHROMA_SATURATION_CNTL, in saa711x_set_size()
950 /* write V fine-scaling (luminance) */ in saa711x_set_size()
951 saa711x_write(sd, R_E0_B_VERT_LUMA_SCALING_INC, in saa711x_set_size()
953 saa711x_write(sd, R_E1_B_VERT_LUMA_SCALING_INC_MSB, in saa711x_set_size()
955 /* write V fine-scaling (chrominance) */ in saa711x_set_size()
956 saa711x_write(sd, R_E2_B_VERT_CHROMA_SCALING_INC, in saa711x_set_size()
958 saa711x_write(sd, R_E3_B_VERT_CHROMA_SCALING_INC_MSB, in saa711x_set_size()
961 saa711x_writeregs(sd, saa7115_cfg_reset_scaler); in saa711x_set_size()
964 saa711x_write(sd, R_80_GLOBAL_CNTL_1, in saa711x_set_size()
965 saa711x_read(sd, R_80_GLOBAL_CNTL_1) | 0x20); in saa711x_set_size()
970 static void saa711x_set_v4lstd(struct v4l2_subdev *sd, v4l2_std_id std) in saa711x_set_v4lstd() argument
972 struct saa711x_state *state = to_state(sd); 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()
990 u8 reg = saa711x_read(sd, R_08_SYNC_CNTL); in saa711x_set_v4lstd()
993 saa711x_write(sd, R_08_SYNC_CNTL, reg); in saa711x_set_v4lstd()
995 saa711x_writeregs(sd, saa7115_cfg_60hz_video); in saa711x_set_v4lstd()
997 saa711x_set_size(sd, 720, 480); 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()
1001 u8 reg = saa711x_read(sd, R_08_SYNC_CNTL); in saa711x_set_v4lstd()
1003 saa711x_write(sd, R_08_SYNC_CNTL, reg); in saa711x_set_v4lstd()
1005 saa711x_writeregs(sd, saa7115_cfg_50hz_video); in saa711x_set_v4lstd()
1007 saa711x_set_size(sd, 720, 576); in saa711x_set_v4lstd()
1010 /* Register 0E - Bits D6-D4 on NO-AUTO mode in saa711x_set_v4lstd()
1012 50 Hz / 625 lines 60 Hz / 525 lines 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()
1021 u8 reg = saa711x_read(sd, R_0E_CHROMA_CNTL_1) & 0x8f; in saa711x_set_v4lstd()
1034 saa711x_write(sd, R_0E_CHROMA_CNTL_1, reg); in saa711x_set_v4lstd()
1037 int taskb = saa711x_read(sd, R_80_GLOBAL_CNTL_1) & 0x10; in saa711x_set_v4lstd()
1039 if (taskb && state->ident == SAA7114) in saa711x_set_v4lstd()
1040 saa711x_writeregs(sd, saa7115_cfg_vbi_on); in saa711x_set_v4lstd()
1043 saa711x_s_clock_freq(sd, state->audclk_freq); in saa711x_set_v4lstd()
1048 static void saa711x_set_lcr(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *fmt) in saa711x_set_lcr() argument
1050 struct saa711x_state *state = to_state(sd); in saa711x_set_lcr()
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()
1079 /* first clear lines that cannot be captured */ 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()
1125 saa711x_writeregs(sd, fmt == NULL ? in saa711x_set_lcr()
1130 static int saa711x_g_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *sliced) in saa711x_g_sliced_fmt() argument
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()
1144 if (saa711x_read(sd, R_80_GLOBAL_CNTL_1) & 0x10) 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()
1157 static int saa711x_s_raw_fmt(struct v4l2_subdev *sd, struct v4l2_vbi_format *fmt) in saa711x_s_raw_fmt() argument
1159 saa711x_set_lcr(sd, NULL); in saa711x_s_raw_fmt()
1163 static int saa711x_s_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *fmt) in saa711x_s_sliced_fmt() argument
1165 saa711x_set_lcr(sd, fmt); in saa711x_s_sliced_fmt()
1169 static int saa711x_set_fmt(struct v4l2_subdev *sd, in saa711x_set_fmt() argument
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
1190 static int saa711x_decode_vbi_line(struct v4l2_subdev *sd, struct v4l2_decode_vbi_line *vbi) in saa711x_decode_vbi_line() argument
1192 struct saa711x_state *state = to_state(sd); in saa711x_decode_vbi_line()
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
1257 struct saa711x_state *state = to_state(sd); in saa711x_g_tuner()
1260 if (state->radio) in saa711x_g_tuner()
1262 status = saa711x_read(sd, R_1F_STATUS_BYTE_2_VD_DEC); in saa711x_g_tuner()
1264 v4l2_dbg(1, debug, sd, "status: 0x%02x\n", status); in saa711x_g_tuner()
1265 vt->signal = ((status & (1 << 6)) == 0) ? 0xffff : 0x0; in saa711x_g_tuner()
1269 static int saa711x_s_std(struct v4l2_subdev *sd, v4l2_std_id std) in saa711x_s_std() argument
1271 struct saa711x_state *state = to_state(sd); in saa711x_s_std()
1273 state->radio = 0; in saa711x_s_std()
1274 saa711x_set_v4lstd(sd, std); in saa711x_s_std()
1278 static int saa711x_s_radio(struct v4l2_subdev *sd) in saa711x_s_radio() argument
1280 struct saa711x_state *state = to_state(sd); in saa711x_s_radio()
1282 state->radio = 1; in saa711x_s_radio()
1286 static int saa711x_s_routing(struct v4l2_subdev *sd, in saa711x_s_routing() argument
1289 struct saa711x_state *state = to_state(sd); in saa711x_s_routing()
1290 u8 mask = (state->ident <= SAA7111A) ? 0xf8 : 0xf0; in saa711x_s_routing()
1292 v4l2_dbg(1, debug, sd, "decoder set input %d output %d\n", 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()
1306 v4l2_dbg(1, debug, sd, "now setting %s input %s output\n", 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()
1316 saa711x_write(sd, R_10_CHROMA_CNTL_2, in saa711x_s_routing()
1317 (saa711x_read(sd, R_10_CHROMA_CNTL_2) & 0x3f) | in saa711x_s_routing()
1319 saa711x_write(sd, R_13_RT_X_PORT_OUT_CNTL, in saa711x_s_routing()
1320 (saa711x_read(sd, R_13_RT_X_PORT_OUT_CNTL) & 0xf0) | in saa711x_s_routing()
1325 saa711x_write(sd, R_02_INPUT_CNTL_1, in saa711x_s_routing()
1326 (saa711x_read(sd, R_02_INPUT_CNTL_1) & mask) | in saa711x_s_routing()
1329 /* bypass chrominance trap for S-Video modes */ in saa711x_s_routing()
1330 saa711x_write(sd, R_09_LUMA_CNTL, in saa711x_s_routing()
1331 (saa711x_read(sd, R_09_LUMA_CNTL) & 0x7f) | 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()
1337 saa711x_write(sd, R_83_X_PORT_I_O_ENA_AND_OUT_CLK, in saa711x_s_routing()
1338 (saa711x_read(sd, R_83_X_PORT_I_O_ENA_AND_OUT_CLK) & 0xfe) | in saa711x_s_routing()
1339 (state->output & 0x01)); in saa711x_s_routing()
1341 if (state->ident > SAA7111A) { in saa711x_s_routing()
1343 saa711x_write(sd, R_85_I_PORT_SIGNAL_POLAR, 0x20); in saa711x_s_routing()
1345 saa711x_write(sd, R_85_I_PORT_SIGNAL_POLAR, 0x21); in saa711x_s_routing()
1350 static int saa711x_s_gpio(struct v4l2_subdev *sd, u32 val) in saa711x_s_gpio() argument
1352 struct saa711x_state *state = to_state(sd); in saa711x_s_gpio()
1354 if (state->ident > SAA7111A) in saa711x_s_gpio()
1355 return -EINVAL; in saa711x_s_gpio()
1356 saa711x_write(sd, 0x11, (saa711x_read(sd, 0x11) & 0x7f) | in saa711x_s_gpio()
1361 static int saa711x_s_stream(struct v4l2_subdev *sd, int enable) in saa711x_s_stream() argument
1363 struct saa711x_state *state = to_state(sd); in saa711x_s_stream()
1365 v4l2_dbg(1, debug, sd, "%s output\n", in saa711x_s_stream()
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()
1377 static int saa711x_s_crystal_freq(struct v4l2_subdev *sd, u32 freq, u32 flags) in saa711x_s_crystal_freq() argument
1379 struct saa711x_state *state = to_state(sd); in saa711x_s_crystal_freq()
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()
1392 static int saa711x_reset(struct v4l2_subdev *sd, u32 val) in saa711x_reset() argument
1394 v4l2_dbg(1, debug, sd, "decoder RESET\n"); in saa711x_reset()
1395 saa711x_writeregs(sd, saa7115_cfg_reset_scaler); in saa711x_reset()
1399 static int saa711x_g_vbi_data(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_data *data) in saa711x_g_vbi_data() argument
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()
1406 if (saa711x_read(sd, 0x6b) & 0xc0) 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()
1414 if (saa711x_read(sd, 0x66) & 0x30) 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()
1421 if (saa711x_read(sd, 0x66) & 0xc0) 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()
1431 static int saa711x_querystd(struct v4l2_subdev *sd, v4l2_std_id *std) in saa711x_querystd() argument
1433 struct saa711x_state *state = to_state(sd); in saa711x_querystd()
1442 reg1f = saa711x_read(sd, R_1F_STATUS_BYTE_2_VD_DEC); in saa711x_querystd()
1444 if (state->ident == SAA7115) { in saa711x_querystd()
1445 reg1e = saa711x_read(sd, R_1E_STATUS_BYTE_1_VD_DEC); in saa711x_querystd()
1447 v4l2_dbg(1, debug, sd, "Status byte 1 (0x1e)=0x%02x\n", reg1e); in saa711x_querystd()
1472 v4l2_dbg(1, debug, sd, "Status byte 2 (0x1f)=0x%02x\n", reg1f); in saa711x_querystd()
1486 v4l2_dbg(1, debug, sd, "detected std mask = %08Lx\n", *std); in saa711x_querystd()
1491 static int saa711x_g_input_status(struct v4l2_subdev *sd, u32 *status) in saa711x_g_input_status() argument
1493 struct saa711x_state *state = to_state(sd); in saa711x_g_input_status()
1498 if (state->ident == SAA7115) in saa711x_g_input_status()
1499 reg1e = saa711x_read(sd, R_1E_STATUS_BYTE_1_VD_DEC); in saa711x_g_input_status()
1500 reg1f = saa711x_read(sd, R_1F_STATUS_BYTE_2_VD_DEC); in saa711x_g_input_status()
1507 static int saa711x_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) in saa711x_g_register() argument
1509 reg->val = saa711x_read(sd, reg->reg & 0xff); in saa711x_g_register()
1510 reg->size = 1; in saa711x_g_register()
1514 static int saa711x_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg) in saa711x_s_register() argument
1516 saa711x_write(sd, reg->reg & 0xff, reg->val & 0xff); in saa711x_s_register()
1521 static int saa711x_log_status(struct v4l2_subdev *sd) in saa711x_log_status() argument
1523 struct saa711x_state *state = to_state(sd); in saa711x_log_status()
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()
1531 reg1f = saa711x_read(sd, R_1F_STATUS_BYTE_2_VD_DEC); in saa711x_log_status()
1533 v4l2_info(sd, "Video signal: %s\n", signalOk ? "ok" : "bad"); in saa711x_log_status()
1534 v4l2_info(sd, "Frequency: %s\n", (reg1f & 0x20) ? "60 Hz" : "50 Hz"); in saa711x_log_status()
1539 reg1e = saa711x_read(sd, R_1E_STATUS_BYTE_1_VD_DEC); in saa711x_log_status()
1540 reg1f = saa711x_read(sd, R_1F_STATUS_BYTE_2_VD_DEC); 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()
1549 v4l2_info(sd, "Video signal: %s\n", signalOk ? (vcr ? "VCR" : "broadcast/DVD") : "bad"); in saa711x_log_status()
1550 v4l2_info(sd, "Frequency: %s\n", (reg1f & 0x20) ? "60 Hz" : "50 Hz"); in saa711x_log_status()
1554 v4l2_info(sd, "Detected format: NTSC\n"); in saa711x_log_status()
1557 v4l2_info(sd, "Detected format: PAL\n"); in saa711x_log_status()
1560 v4l2_info(sd, "Detected format: SECAM\n"); in saa711x_log_status()
1563 v4l2_info(sd, "Detected format: BW/No color\n"); 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() local
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()
1642 work = saa711x_read(sd, R_08_SYNC_CNTL); in saa711x_write_platform_data()
1644 work |= ((*data->saa7113_r08_htc) << SAA7113_R_08_HTC_OFFSET); in saa711x_write_platform_data()
1645 saa711x_write(sd, R_08_SYNC_CNTL, work); in saa711x_write_platform_data()
1648 if (data->saa7113_r10_vrln) { in saa711x_write_platform_data()
1649 work = saa711x_read(sd, R_10_CHROMA_CNTL_2); in saa711x_write_platform_data()
1651 if (*data->saa7113_r10_vrln) in saa711x_write_platform_data()
1653 saa711x_write(sd, R_10_CHROMA_CNTL_2, work); in saa711x_write_platform_data()
1656 if (data->saa7113_r10_ofts) { in saa711x_write_platform_data()
1657 work = saa711x_read(sd, R_10_CHROMA_CNTL_2); in saa711x_write_platform_data()
1659 work |= (*data->saa7113_r10_ofts << SAA7113_R_10_OFTS_OFFSET); in saa711x_write_platform_data()
1660 saa711x_write(sd, R_10_CHROMA_CNTL_2, work); in saa711x_write_platform_data()
1663 if (data->saa7113_r12_rts0) { in saa711x_write_platform_data()
1664 work = saa711x_read(sd, R_12_RT_SIGNAL_CNTL); 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()
1671 saa711x_write(sd, R_12_RT_SIGNAL_CNTL, work); in saa711x_write_platform_data()
1674 if (data->saa7113_r12_rts1) { in saa711x_write_platform_data()
1675 work = saa711x_read(sd, R_12_RT_SIGNAL_CNTL); in saa711x_write_platform_data()
1677 work |= (*data->saa7113_r12_rts1 << SAA7113_R_12_RTS1_OFFSET); in saa711x_write_platform_data()
1678 saa711x_write(sd, R_12_RT_SIGNAL_CNTL, work); in saa711x_write_platform_data()
1681 if (data->saa7113_r13_adlsb) { in saa711x_write_platform_data()
1682 work = saa711x_read(sd, R_13_RT_X_PORT_OUT_CNTL); in saa711x_write_platform_data()
1684 if (*data->saa7113_r13_adlsb) in saa711x_write_platform_data()
1686 saa711x_write(sd, R_13_RT_X_PORT_OUT_CNTL, work); 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()
1811 struct v4l2_subdev *sd; in saa711x_probe() local
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()
1840 v4l2_i2c_subdev_init(sd, client, &saa711x_ops); 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()
1890 v4l2_dbg(1, debug, sd, "writing init values\n"); 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()
1898 saa711x_writeregs(sd, saa7111_init); in saa711x_probe()
1901 saa711x_writeregs(sd, gm7113c_init); in saa711x_probe()
1904 if (pdata && pdata->saa7113_force_gm7113c_init) in saa711x_probe()
1905 saa711x_writeregs(sd, gm7113c_init); in saa711x_probe()
1907 saa711x_writeregs(sd, saa7113_init); in saa711x_probe()
1910 state->crystal_freq = SAA7115_FREQ_32_11_MHZ; in saa711x_probe()
1911 saa711x_writeregs(sd, saa7115_init_auto_input); in saa711x_probe()
1913 if (state->ident > SAA7111A && state->ident != GM7113C) in saa711x_probe()
1914 saa711x_writeregs(sd, saa7115_init_misc); in saa711x_probe()
1919 saa711x_set_v4lstd(sd, V4L2_STD_NTSC); in saa711x_probe()
1922 v4l2_dbg(1, debug, sd, "status: (1E) 0x%02x, (1F) 0x%02x\n", in saa711x_probe()
1923 saa711x_read(sd, R_1E_STATUS_BYTE_1_VD_DEC), in saa711x_probe()
1924 saa711x_read(sd, R_1F_STATUS_BYTE_2_VD_DEC)); in saa711x_probe()
1928 /* ----------------------------------------------------------------------- */
1932 struct v4l2_subdev *sd = i2c_get_clientdata(client); in saa711x_remove() local
1934 v4l2_device_unregister_subdev(sd); in saa711x_remove()
1935 v4l2_ctrl_handler_free(sd->ctrl_handler); in saa711x_remove()