Lines Matching +full:ignore +full:- +full:power +full:- +full:on +full:- +full:sel

1 // SPDX-License-Identifier: GPL-2.0
3 // tvp5150 - Texas Instruments TVP5150A/AM1 and TVP5151 video decoder driver
7 #include <dt-bindings/media/tvp5150.h>
18 #include <media/v4l2-async.h>
19 #include <media/v4l2-device.h>
20 #include <media/v4l2-event.h>
21 #include <media/v4l2-ctrls.h>
22 #include <media/v4l2-fwnode.h>
23 #include <media/v4l2-mc.h>
24 #include <media/v4l2-rect.h>
45 #define TVP5150_MAX_CONNECTORS 3 /* Check dt-bindings for more information */
54 MODULE_PARM_DESC(debug, "Debug level (0-2)");
105 return &container_of(ctrl->handler, struct tvp5150, hdl)->sd; in to_sd()
113 ret = regmap_read(decoder->regmap, addr, &val); in tvp5150_read()
127 dprintk0(sd->dev, "too much data to dump\n"); in dump_reg_range()
132 len = (end - i > max_line) ? max_line : end - i; in dump_reg_range()
137 dprintk0(sd->dev, "%s reg %02x = %*ph\n", s, i, len, buf); in dump_reg_range()
143 dprintk0(sd->dev, "tvp5150: Video input source selection #1 = 0x%02x\n", in tvp5150_log_status()
145 dprintk0(sd->dev, "tvp5150: Analog channel controls = 0x%02x\n", in tvp5150_log_status()
147 dprintk0(sd->dev, "tvp5150: Operation mode controls = 0x%02x\n", in tvp5150_log_status()
149 dprintk0(sd->dev, "tvp5150: Miscellaneous controls = 0x%02x\n", in tvp5150_log_status()
151 dprintk0(sd->dev, "tvp5150: Autoswitch mask= 0x%02x\n", in tvp5150_log_status()
153 dprintk0(sd->dev, "tvp5150: Color killer threshold control = 0x%02x\n", in tvp5150_log_status()
155 dprintk0(sd->dev, "tvp5150: Luminance processing controls #1 #2 and #3 = %02x %02x %02x\n", in tvp5150_log_status()
159 dprintk0(sd->dev, "tvp5150: Brightness control = 0x%02x\n", in tvp5150_log_status()
161 dprintk0(sd->dev, "tvp5150: Color saturation control = 0x%02x\n", in tvp5150_log_status()
163 dprintk0(sd->dev, "tvp5150: Hue control = 0x%02x\n", in tvp5150_log_status()
165 dprintk0(sd->dev, "tvp5150: Contrast control = 0x%02x\n", in tvp5150_log_status()
167 dprintk0(sd->dev, "tvp5150: Outputs and data rates select = 0x%02x\n", in tvp5150_log_status()
169 dprintk0(sd->dev, "tvp5150: Configuration shared pins = 0x%02x\n", in tvp5150_log_status()
171 dprintk0(sd->dev, "tvp5150: Active video cropping start = 0x%02x%02x\n", in tvp5150_log_status()
174 dprintk0(sd->dev, "tvp5150: Active video cropping stop = 0x%02x%02x\n", in tvp5150_log_status()
177 dprintk0(sd->dev, "tvp5150: Genlock/RTC = 0x%02x\n", in tvp5150_log_status()
179 dprintk0(sd->dev, "tvp5150: Horizontal sync start = 0x%02x\n", in tvp5150_log_status()
181 dprintk0(sd->dev, "tvp5150: Vertical blanking start = 0x%02x\n", in tvp5150_log_status()
183 dprintk0(sd->dev, "tvp5150: Vertical blanking stop = 0x%02x\n", in tvp5150_log_status()
185 dprintk0(sd->dev, "tvp5150: Chrominance processing control #1 and #2 = %02x %02x\n", in tvp5150_log_status()
188 dprintk0(sd->dev, "tvp5150: Interrupt reset register B = 0x%02x\n", in tvp5150_log_status()
190 dprintk0(sd->dev, "tvp5150: Interrupt enable register B = 0x%02x\n", in tvp5150_log_status()
192 dprintk0(sd->dev, "tvp5150: Interrupt configuration register B = 0x%02x\n", in tvp5150_log_status()
194 dprintk0(sd->dev, "tvp5150: Video standard = 0x%02x\n", in tvp5150_log_status()
196 dprintk0(sd->dev, "tvp5150: Chroma gain factor: Cb=0x%02x Cr=0x%02x\n", in tvp5150_log_status()
199 dprintk0(sd->dev, "tvp5150: Macrovision on counter = 0x%02x\n", in tvp5150_log_status()
201 dprintk0(sd->dev, "tvp5150: Macrovision off counter = 0x%02x\n", in tvp5150_log_status()
203 dprintk0(sd->dev, "tvp5150: ITU-R BT.656.%d timing(TVP5150AM1 only)\n", in tvp5150_log_status()
205 dprintk0(sd->dev, "tvp5150: Device ID = %02x%02x\n", in tvp5150_log_status()
208 dprintk0(sd->dev, "tvp5150: ROM version = (hex) %02x.%02x\n", in tvp5150_log_status()
211 dprintk0(sd->dev, "tvp5150: Vertical line count = 0x%02x%02x\n", in tvp5150_log_status()
214 dprintk0(sd->dev, "tvp5150: Interrupt status register B = 0x%02x\n", in tvp5150_log_status()
216 dprintk0(sd->dev, "tvp5150: Interrupt active register B = 0x%02x\n", in tvp5150_log_status()
218 dprintk0(sd->dev, "tvp5150: Status regs #1 to #5 = %02x %02x %02x %02x %02x\n", in tvp5150_log_status()
230 dprintk0(sd->dev, "tvp5150: Teletext filter enable = 0x%02x\n", in tvp5150_log_status()
232 dprintk0(sd->dev, "tvp5150: Interrupt status register A = 0x%02x\n", in tvp5150_log_status()
234 dprintk0(sd->dev, "tvp5150: Interrupt enable register A = 0x%02x\n", in tvp5150_log_status()
236 dprintk0(sd->dev, "tvp5150: Interrupt configuration = 0x%02x\n", in tvp5150_log_status()
238 dprintk0(sd->dev, "tvp5150: VDP status register = 0x%02x\n", in tvp5150_log_status()
240 dprintk0(sd->dev, "tvp5150: FIFO word count = 0x%02x\n", in tvp5150_log_status()
242 dprintk0(sd->dev, "tvp5150: FIFO interrupt threshold = 0x%02x\n", in tvp5150_log_status()
244 dprintk0(sd->dev, "tvp5150: FIFO reset = 0x%02x\n", in tvp5150_log_status()
246 dprintk0(sd->dev, "tvp5150: Line number interrupt = 0x%02x\n", in tvp5150_log_status()
248 dprintk0(sd->dev, "tvp5150: Pixel alignment register = 0x%02x%02x\n", in tvp5150_log_status()
251 dprintk0(sd->dev, "tvp5150: FIFO output control = 0x%02x\n", in tvp5150_log_status()
253 dprintk0(sd->dev, "tvp5150: Full field enable = 0x%02x\n", in tvp5150_log_status()
255 dprintk0(sd->dev, "tvp5150: Full field mode register = 0x%02x\n", in tvp5150_log_status()
287 if ((decoder->dev_id == 0x5150 && decoder->rom_ver == 0x0400) || in tvp5150_selmux()
288 (decoder->dev_id == 0x5151 && decoder->rom_ver == 0x0100)) { in tvp5150_selmux()
289 if (!decoder->enable) in tvp5150_selmux()
293 switch (decoder->input) { in tvp5150_selmux()
305 dev_dbg_lvl(sd->dev, 1, debug, in tvp5150_selmux()
307 decoder->input == 0 ? "aip1a" : in tvp5150_selmux()
308 decoder->input == 2 ? "aip1b" : "svideo", in tvp5150_selmux()
309 decoder->output == 0 ? "normal" : "black-frame-gen", in tvp5150_selmux()
312 regmap_write(decoder->regmap, TVP5150_OP_MODE_CTL, opmode); in tvp5150_selmux()
313 regmap_write(decoder->regmap, TVP5150_VD_IN_SRC_SEL_1, input); in tvp5150_selmux()
317 * S-Video we output the vertical lock (VLK) signal on FID/GLCO/VLK/HVLK in tvp5150_selmux()
319 * field indicator (FID) signal on FID/GLCO/VLK/HVLK and set in tvp5150_selmux()
323 if (decoder->input == TVP5150_SVIDEO) in tvp5150_selmux()
327 regmap_update_bits(decoder->regmap, TVP5150_MISC_CTL, mask, val); in tvp5150_selmux()
490 }, { /* Non documented, but initialized on WinTV USB2 */
514 * and so on. There are 16 possible locations from 0 to 15.
551 [5] = {0x0b0, /* Teletext, NTSC-J, NABTS System D */
602 while (regs->reg != 0xff) { in tvp5150_write_inittab()
603 regmap_write(decoder->regmap, regs->reg, regs->value); in tvp5150_write_inittab()
612 struct regmap *map = decoder->regmap; in tvp5150_vdp_init()
627 if (!regs->type.vbi_type) in tvp5150_vdp_init()
630 regmap_write(map, TVP5150_CONF_RAM_ADDR_HIGH, regs->reg >> 8); in tvp5150_vdp_init()
631 regmap_write(map, TVP5150_CONF_RAM_ADDR_LOW, regs->reg); in tvp5150_vdp_init()
635 regs->values[i]); in tvp5150_vdp_init()
640 /* Fills VBI capabilities based on i2c_vbi_ram_value struct */
646 dev_dbg_lvl(sd->dev, 1, debug, "g_sliced_vbi_cap\n"); in tvp5150_g_sliced_vbi_cap()
652 if (!regs->type.vbi_type) in tvp5150_g_sliced_vbi_cap()
655 for (line = regs->type.ini_line; in tvp5150_g_sliced_vbi_cap()
656 line <= regs->type.end_line; in tvp5150_g_sliced_vbi_cap()
658 cap->service_lines[0][line] |= regs->type.vbi_type; in tvp5150_g_sliced_vbi_cap()
660 cap->service_set |= regs->type.vbi_type; in tvp5150_g_sliced_vbi_cap()
666 * type - one of tvp5150_vbi_types
667 * line - line to gather data
670 * bit 7: enable filtering null bytes on CC
672 * bit 5: don't allow data with errors on FIFO
683 v4l2_std_id std = decoder->norm; in tvp5150_set_vbi()
688 dev_err(sd->dev, "VBI can't be configured without knowing number of lines\n"); in tvp5150_set_vbi()
701 if (!regs->type.vbi_type) in tvp5150_set_vbi()
704 if ((type & regs->type.vbi_type) && in tvp5150_set_vbi()
705 (line >= regs->type.ini_line) && in tvp5150_set_vbi()
706 (line <= regs->type.end_line)) in tvp5150_set_vbi()
712 reg = ((line - 6) << 1) + TVP5150_LINE_MODE_INI; in tvp5150_set_vbi()
715 regmap_write(decoder->regmap, reg, type); in tvp5150_set_vbi()
718 regmap_write(decoder->regmap, reg + 1, type); in tvp5150_set_vbi()
726 v4l2_std_id std = decoder->norm; in tvp5150_get_vbi()
732 dev_err(sd->dev, "VBI can't be configured without knowing number of lines\n"); in tvp5150_get_vbi()
742 reg = ((line - 6) << 1) + TVP5150_LINE_MODE_INI; in tvp5150_get_vbi()
747 dev_err(sd->dev, "%s: failed with error = %d\n", in tvp5150_get_vbi()
782 dev_dbg_lvl(sd->dev, 1, debug, "Set video std register to %d.\n", fmt); in tvp5150_set_std()
783 regmap_write(decoder->regmap, TVP5150_VIDEO_STD, fmt); in tvp5150_set_std()
791 *std = decoder->norm; in tvp5150_g_std()
799 struct tvp5150_connector *cur_con = decoder->cur_connector; in tvp5150_s_std()
802 if (decoder->norm == std) in tvp5150_s_std()
805 /* In case of no of-connectors are available no limitations are made */ in tvp5150_s_std()
806 if (!decoder->connectors_num) in tvp5150_s_std()
809 supported_stds = cur_con->base.connector.analog.sdtv_stds; in tvp5150_s_std()
816 return -EINVAL; in tvp5150_s_std()
820 decoder->rect.height = TVP5150_V_MAX_525_60; in tvp5150_s_std()
822 decoder->rect.height = TVP5150_V_MAX_OTHERS; in tvp5150_s_std()
825 decoder->norm = supported_stds & std; in tvp5150_s_std()
857 if (decoder->irq) in query_lock()
858 return decoder->lock; in query_lock()
860 regmap_read(decoder->regmap, TVP5150_STATUS_REG_1, &status); in query_lock()
881 struct regmap *map = decoder->regmap; in tvp5150_isr()
892 decoder->lock = !!(status & TVP5150_INT_A_LOCK_STATUS); in tvp5150_isr()
893 dev_dbg_lvl(decoder->sd.dev, 1, debug, in tvp5150_isr()
895 decoder->lock ? "ck" : "ss"); in tvp5150_isr()
896 v4l2_subdev_notify_event(&decoder->sd, &tvp5150_ev_fmt); in tvp5150_isr()
898 decoder->lock ? decoder->oe : 0); in tvp5150_isr()
918 struct regmap *map = decoder->regmap; in tvp5150_reset()
923 if (decoder->irq) { in tvp5150_reset()
944 v4l2_ctrl_handler_setup(&decoder->hdl); in tvp5150_reset()
957 if (decoder->norm == V4L2_STD_ALL) in tvp5150_enable()
960 std = decoder->norm; in tvp5150_enable()
967 * (non-BT.656) additionally enable the sync outputs. in tvp5150_enable()
969 switch (decoder->mbus_type) { in tvp5150_enable()
971 /* 8-bit 4:2:2 YUV with discrete sync output */ in tvp5150_enable()
972 regmap_update_bits(decoder->regmap, TVP5150_DATA_RATE_SEL, in tvp5150_enable()
974 decoder->oe = TVP5150_MISC_CTL_YCBCR_OE | in tvp5150_enable()
979 decoder->oe = TVP5150_MISC_CTL_YCBCR_OE | in tvp5150_enable()
983 return -EINVAL; in tvp5150_enable()
994 switch (ctrl->id) { in tvp5150_s_ctrl()
996 regmap_write(decoder->regmap, TVP5150_BRIGHT_CTL, ctrl->val); in tvp5150_s_ctrl()
999 regmap_write(decoder->regmap, TVP5150_CONTRAST_CTL, ctrl->val); in tvp5150_s_ctrl()
1002 regmap_write(decoder->regmap, TVP5150_SATURATION_CTL, in tvp5150_s_ctrl()
1003 ctrl->val); in tvp5150_s_ctrl()
1006 regmap_write(decoder->regmap, TVP5150_HUE_CTL, ctrl->val); in tvp5150_s_ctrl()
1009 decoder->enable = ctrl->val ? false : true; in tvp5150_s_ctrl()
1013 return -EINVAL; in tvp5150_s_ctrl()
1019 crop->top = 0; in tvp5150_set_default()
1020 crop->left = 0; in tvp5150_set_default()
1021 crop->width = TVP5150_H_MAX; in tvp5150_set_default()
1023 crop->height = TVP5150_V_MAX_525_60; in tvp5150_set_default()
1025 crop->height = TVP5150_V_MAX_OTHERS; in tvp5150_set_default()
1035 return &decoder->rect; in tvp5150_get_pad_crop()
1038 return v4l2_subdev_get_try_crop(&decoder->sd, sd_state, pad); in tvp5150_get_pad_crop()
1040 return ERR_PTR(-EINVAL); in tvp5150_get_pad_crop()
1043 return ERR_PTR(-EINVAL); in tvp5150_get_pad_crop()
1054 if (!format || (format->pad != TVP5150_PAD_VID_OUT)) in tvp5150_fill_fmt()
1055 return -EINVAL; in tvp5150_fill_fmt()
1057 f = &format->format; in tvp5150_fill_fmt()
1059 f->width = decoder->rect.width; in tvp5150_fill_fmt()
1060 f->height = decoder->rect.height / 2; in tvp5150_fill_fmt()
1062 f->code = TVP5150_MBUS_FMT; in tvp5150_fill_fmt()
1063 f->field = TVP5150_FIELD; in tvp5150_fill_fmt()
1064 f->colorspace = TVP5150_COLORSPACE; in tvp5150_fill_fmt()
1066 dev_dbg_lvl(sd->dev, 1, debug, "width = %d, height = %d\n", f->width, in tvp5150_fill_fmt()
1067 f->height); in tvp5150_fill_fmt()
1076 /* Calculate height based on current standard */ in tvp5150_get_hmax()
1077 if (decoder->norm == V4L2_STD_ALL) in tvp5150_get_hmax()
1080 std = decoder->norm; in tvp5150_get_hmax()
1092 regmap_write(decoder->regmap, TVP5150_VERT_BLANKING_START, rect->top); in tvp5150_set_hw_selection()
1093 regmap_write(decoder->regmap, TVP5150_VERT_BLANKING_STOP, in tvp5150_set_hw_selection()
1094 rect->top + rect->height - hmax); in tvp5150_set_hw_selection()
1095 regmap_write(decoder->regmap, TVP5150_ACT_VD_CROP_ST_MSB, in tvp5150_set_hw_selection()
1096 rect->left >> TVP5150_CROP_SHIFT); in tvp5150_set_hw_selection()
1097 regmap_write(decoder->regmap, TVP5150_ACT_VD_CROP_ST_LSB, in tvp5150_set_hw_selection()
1098 rect->left | (1 << TVP5150_CROP_SHIFT)); in tvp5150_set_hw_selection()
1099 regmap_write(decoder->regmap, TVP5150_ACT_VD_CROP_STP_MSB, in tvp5150_set_hw_selection()
1100 (rect->left + rect->width - TVP5150_MAX_CROP_LEFT) >> in tvp5150_set_hw_selection()
1102 regmap_write(decoder->regmap, TVP5150_ACT_VD_CROP_STP_LSB, in tvp5150_set_hw_selection()
1103 rect->left + rect->width - TVP5150_MAX_CROP_LEFT); in tvp5150_set_hw_selection()
1108 struct v4l2_subdev_selection *sel) in tvp5150_set_selection() argument
1111 struct v4l2_rect *rect = &sel->r; in tvp5150_set_selection()
1115 if (sel->target != V4L2_SEL_TGT_CROP) in tvp5150_set_selection()
1116 return -EINVAL; in tvp5150_set_selection()
1118 dev_dbg_lvl(sd->dev, 1, debug, "%s left=%d, top=%d, width=%d, height=%d\n", in tvp5150_set_selection()
1119 __func__, rect->left, rect->top, rect->width, rect->height); in tvp5150_set_selection()
1122 rect->left = clamp(rect->left, 0, TVP5150_MAX_CROP_LEFT); in tvp5150_set_selection()
1123 rect->top = clamp(rect->top, 0, TVP5150_MAX_CROP_TOP); in tvp5150_set_selection()
1128 * - width = 2 due to UYVY colorspace in tvp5150_set_selection()
1129 * - height, image = no special alignment in tvp5150_set_selection()
1131 v4l_bound_align_image(&rect->width, in tvp5150_set_selection()
1132 TVP5150_H_MAX - TVP5150_MAX_CROP_LEFT - rect->left, in tvp5150_set_selection()
1133 TVP5150_H_MAX - rect->left, 1, &rect->height, in tvp5150_set_selection()
1134 hmax - TVP5150_MAX_CROP_TOP - rect->top, in tvp5150_set_selection()
1135 hmax - rect->top, 0, 0); in tvp5150_set_selection()
1138 sel->which == V4L2_SUBDEV_FORMAT_TRY) in tvp5150_set_selection()
1141 crop = tvp5150_get_pad_crop(decoder, sd_state, sel->pad, sel->which); in tvp5150_set_selection()
1149 if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE && in tvp5150_set_selection()
1160 struct v4l2_subdev_selection *sel) in tvp5150_get_selection() argument
1166 switch (sel->target) { in tvp5150_get_selection()
1168 sel->r.left = 0; in tvp5150_get_selection()
1169 sel->r.top = 0; in tvp5150_get_selection()
1170 sel->r.width = TVP5150_H_MAX; in tvp5150_get_selection()
1172 /* Calculate height based on current standard */ in tvp5150_get_selection()
1173 if (decoder->norm == V4L2_STD_ALL) in tvp5150_get_selection()
1176 std = decoder->norm; in tvp5150_get_selection()
1178 sel->r.height = TVP5150_V_MAX_525_60; in tvp5150_get_selection()
1180 sel->r.height = TVP5150_V_MAX_OTHERS; in tvp5150_get_selection()
1183 crop = tvp5150_get_pad_crop(decoder, sd_state, sel->pad, in tvp5150_get_selection()
1184 sel->which); in tvp5150_get_selection()
1187 sel->r = *crop; in tvp5150_get_selection()
1190 return -EINVAL; in tvp5150_get_selection()
1200 cfg->type = decoder->mbus_type; in tvp5150_get_mbus_config()
1201 cfg->bus.parallel.flags = V4L2_MBUS_MASTER in tvp5150_get_mbus_config()
1219 * Reset selection to maximum on subdev_open() if autodetection is on in tvp5150_init_cfg()
1222 if (decoder->norm == V4L2_STD_ALL) { in tvp5150_init_cfg()
1224 if (std != decoder->detected_norm) { in tvp5150_init_cfg()
1225 decoder->detected_norm = std; in tvp5150_init_cfg()
1226 tvp5150_set_default(std, &decoder->rect); in tvp5150_init_cfg()
1237 if (code->pad || code->index) in tvp5150_enum_mbus_code()
1238 return -EINVAL; in tvp5150_enum_mbus_code()
1240 code->code = TVP5150_MBUS_FMT; in tvp5150_enum_mbus_code()
1250 if (fse->index >= 8 || fse->code != TVP5150_MBUS_FMT) in tvp5150_enum_frame_size()
1251 return -EINVAL; in tvp5150_enum_frame_size()
1253 fse->code = TVP5150_MBUS_FMT; in tvp5150_enum_frame_size()
1254 fse->min_width = decoder->rect.width; in tvp5150_enum_frame_size()
1255 fse->max_width = decoder->rect.width; in tvp5150_enum_frame_size()
1256 fse->min_height = decoder->rect.height / 2; in tvp5150_enum_frame_size()
1257 fse->max_height = decoder->rect.height / 2; in tvp5150_enum_frame_size()
1273 return -EINVAL; in tvp5150_set_link()
1275 link->flags = flags; in tvp5150_set_link()
1276 link->reverse->flags = link->flags; in tvp5150_set_link()
1287 for (i = 0; i < TVP5150_NUM_PADS - 1; i++) { in tvp5150_disable_all_input_links()
1288 connector_pad = media_pad_remote_pad_first(&decoder->pads[i]); in tvp5150_disable_all_input_links()
1292 err = tvp5150_set_link(connector_pad, &decoder->pads[i], 0); in tvp5150_disable_all_input_links()
1310 &decoder->pads[tvp5150_pad->index ^ 1]; in tvp5150_link_setup()
1320 if (tvp5150_pad->flags & MEDIA_PAD_FL_SOURCE) in tvp5150_link_setup()
1324 for (i = 0; i < decoder->connectors_num; i++) { in tvp5150_link_setup()
1325 if (remote->entity == &decoder->connectors[i].ent) { in tvp5150_link_setup()
1326 v4l2c = &decoder->connectors[i].base; in tvp5150_link_setup()
1327 is_svideo = v4l2c->type == V4L2_CONN_SVIDEO; in tvp5150_link_setup()
1332 dev_dbg_lvl(sd->dev, 1, debug, "link setup '%s':%d->'%s':%d[%d]", in tvp5150_link_setup()
1333 remote->entity->name, remote->index, in tvp5150_link_setup()
1334 tvp5150_pad->entity->name, tvp5150_pad->index, in tvp5150_link_setup()
1337 dev_dbg_lvl(sd->dev, 1, debug, in tvp5150_link_setup()
1338 "link setup '%s':%d->'%s':%d[%d]", in tvp5150_link_setup()
1339 remote->entity->name, remote->index, in tvp5150_link_setup()
1340 other_tvp5150_pad->entity->name, in tvp5150_link_setup()
1341 other_tvp5150_pad->index, in tvp5150_link_setup()
1347 * comp-connector1 --\ in tvp5150_link_setup()
1348 * |---> AIP1A in tvp5150_link_setup()
1350 * svideo-connector -| in tvp5150_link_setup()
1352 * |---> AIP1B in tvp5150_link_setup()
1353 * comp-connector2 --/ in tvp5150_link_setup()
1355 * We can't rely on user space that the current connector gets disabled in tvp5150_link_setup()
1357 * connector links to be on the safe side. in tvp5150_link_setup()
1363 tvp5150_s_routing(sd, is_svideo ? TVP5150_SVIDEO : tvp5150_pad->index, in tvp5150_link_setup()
1372 * S-Video connector is conneted to both ports AIP1A and AIP1B. in tvp5150_link_setup()
1373 * Both links must be enabled in one-shot regardless which link in tvp5150_link_setup()
1383 if (!decoder->connectors_num) in tvp5150_link_setup()
1387 decoder->cur_connector = in tvp5150_link_setup()
1391 * Do nothing if the new connector supports the same tv-norms as in tvp5150_link_setup()
1394 v4l2ca = &decoder->cur_connector->base.connector.analog; in tvp5150_link_setup()
1395 new_norm = decoder->norm & v4l2ca->sdtv_stds; in tvp5150_link_setup()
1396 if (decoder->norm == new_norm) in tvp5150_link_setup()
1400 * Fallback to the new connector tv-norms if we can't find any in tvp5150_link_setup()
1401 * common between the current tv-norm and the new one. in tvp5150_link_setup()
1403 tvp5150_s_std(sd, new_norm ? new_norm : v4l2ca->sdtv_stds); in tvp5150_link_setup()
1421 if (decoder->irq) in tvp5150_runtime_suspend()
1423 return regmap_update_bits(decoder->regmap, in tvp5150_runtime_suspend()
1434 if (decoder->irq) in tvp5150_runtime_resume()
1436 return regmap_update_bits(decoder->regmap, in tvp5150_runtime_resume()
1453 ret = pm_runtime_resume_and_get(sd->dev); in tvp5150_s_stream()
1460 if (decoder->irq) in tvp5150_s_stream()
1461 val = decoder->lock ? decoder->oe : 0; in tvp5150_s_stream()
1463 val = decoder->oe; in tvp5150_s_stream()
1465 v4l2_subdev_notify_event(&decoder->sd, &tvp5150_ev_fmt); in tvp5150_s_stream()
1467 pm_runtime_put(sd->dev); in tvp5150_s_stream()
1470 regmap_update_bits(decoder->regmap, TVP5150_MISC_CTL, mask, val); in tvp5150_s_stream()
1480 decoder->input = input; in tvp5150_s_routing()
1481 decoder->output = output; in tvp5150_s_routing()
1484 decoder->enable = false; in tvp5150_s_routing()
1486 decoder->enable = true; in tvp5150_s_routing()
1504 if (fmt->sample_format == V4L2_PIX_FMT_GREY) in tvp5150_s_raw_fmt()
1505 regmap_write(decoder->regmap, TVP5150_LUMA_PROC_CTL_1, 0x70); in tvp5150_s_raw_fmt()
1506 if (fmt->count[0] == 18 && fmt->count[1] == 18) { in tvp5150_s_raw_fmt()
1507 regmap_write(decoder->regmap, TVP5150_VERT_BLANKING_START, in tvp5150_s_raw_fmt()
1509 regmap_write(decoder->regmap, TVP5150_VERT_BLANKING_STOP, 0x01); in tvp5150_s_raw_fmt()
1519 if (svbi->service_set != 0) { in tvp5150_s_sliced_fmt()
1521 svbi->service_lines[1][i] = 0; in tvp5150_s_sliced_fmt()
1522 svbi->service_lines[0][i] = in tvp5150_s_sliced_fmt()
1523 tvp5150_set_vbi(sd, svbi->service_lines[0][i], in tvp5150_s_sliced_fmt()
1527 regmap_write(decoder->regmap, TVP5150_FIFO_OUT_CTRL, 1); in tvp5150_s_sliced_fmt()
1530 regmap_write(decoder->regmap, TVP5150_FIFO_OUT_CTRL, 0); in tvp5150_s_sliced_fmt()
1533 regmap_write(decoder->regmap, TVP5150_FULL_FIELD_ENA, 0); in tvp5150_s_sliced_fmt()
1537 regmap_write(decoder->regmap, i, 0xff); in tvp5150_s_sliced_fmt()
1546 memset(svbi->service_lines, 0, sizeof(svbi->service_lines)); in tvp5150_g_sliced_fmt()
1549 svbi->service_lines[0][i] = in tvp5150_g_sliced_fmt()
1551 mask |= svbi->service_lines[0][i]; in tvp5150_g_sliced_fmt()
1553 svbi->service_set = mask; in tvp5150_g_sliced_fmt()
1562 res = tvp5150_read(sd, reg->reg & 0xff); in tvp5150_g_register()
1564 dev_err(sd->dev, "%s: failed with error = %d\n", __func__, res); in tvp5150_g_register()
1568 reg->val = res; in tvp5150_g_register()
1569 reg->size = 1; in tvp5150_g_register()
1577 return regmap_write(decoder->regmap, reg->reg & 0xff, reg->val & 0xff); in tvp5150_s_register()
1584 switch (sub->type) { in tvp5150_subscribe_event()
1590 return -EINVAL; in tvp5150_subscribe_event()
1598 vt->signal = ((status & 0x04) && (status & 0x02)) ? 0xffff : 0x0; in tvp5150_g_tuner()
1613 for (i = 0; i < decoder->connectors_num; i++) { in tvp5150_registered()
1614 struct media_entity *con = &decoder->connectors[i].ent; in tvp5150_registered()
1615 struct media_pad *pad = &decoder->connectors[i].pad; in tvp5150_registered()
1617 &decoder->connectors[i].base; in tvp5150_registered()
1620 unsigned int port = link->fwnode_link.remote_port; in tvp5150_registered()
1622 bool is_svideo = v4l2c->type == V4L2_CONN_SVIDEO; in tvp5150_registered()
1624 pad->flags = MEDIA_PAD_FL_SOURCE; in tvp5150_registered()
1629 ret = media_device_register_entity(sd->v4l2_dev->mdev, con); in tvp5150_registered()
1633 ret = media_create_pad_link(con, 0, &sd->entity, port, flags); in tvp5150_registered()
1643 port = link->fwnode_link.remote_port; in tvp5150_registered()
1644 ret = media_create_pad_link(con, 0, &sd->entity, port, in tvp5150_registered()
1652 decoder->input = in tvp5150_registered()
1658 decoder->cur_connector = &decoder->connectors[i]; in tvp5150_registered()
1659 tvp5150_s_std(sd, v4l2c->connector.analog.sdtv_stds); in tvp5150_registered()
1666 for (i = 0; i < decoder->connectors_num; i++) { in tvp5150_registered()
1667 media_device_unregister_entity(&decoder->connectors[i].ent); in tvp5150_registered()
1668 media_entity_cleanup(&decoder->connectors[i].ent); in tvp5150_registered()
1678 return pm_runtime_resume_and_get(sd->dev); in tvp5150_open()
1683 pm_runtime_put(sd->dev); in tvp5150_close()
1688 /* ----------------------------------------------------------------------- */
1828 struct v4l2_subdev *sd = &core->sd; in tvp5150_detect_version()
1834 * Read consequent registers - TVP5150_MSB_DEV_ID, TVP5150_LSB_DEV_ID, in tvp5150_detect_version()
1837 res = regmap_bulk_read(core->regmap, TVP5150_MSB_DEV_ID, regs, 4); in tvp5150_detect_version()
1839 dev_err(&c->dev, "reading ID registers failed: %d\n", res); in tvp5150_detect_version()
1843 core->dev_id = (regs[0] << 8) | regs[1]; in tvp5150_detect_version()
1844 core->rom_ver = (regs[2] << 8) | regs[3]; in tvp5150_detect_version()
1846 dev_info(sd->dev, "tvp%04x (%u.%u) chip found @ 0x%02x (%s)\n", in tvp5150_detect_version()
1847 core->dev_id, regs[2], regs[3], c->addr << 1, in tvp5150_detect_version()
1848 c->adapter->name); in tvp5150_detect_version()
1850 if (core->dev_id == 0x5150 && core->rom_ver == 0x0321) { in tvp5150_detect_version()
1851 dev_info(sd->dev, "tvp5150a detected.\n"); in tvp5150_detect_version()
1852 } else if (core->dev_id == 0x5150 && core->rom_ver == 0x0400) { in tvp5150_detect_version()
1853 dev_info(sd->dev, "tvp5150am1 detected.\n"); in tvp5150_detect_version()
1855 /* ITU-T BT.656.4 timing */ in tvp5150_detect_version()
1856 regmap_write(core->regmap, TVP5150_REV_SELECT, 0); in tvp5150_detect_version()
1857 } else if (core->dev_id == 0x5151 && core->rom_ver == 0x0100) { in tvp5150_detect_version()
1858 dev_info(sd->dev, "tvp5151 detected.\n"); in tvp5150_detect_version()
1860 dev_info(sd->dev, "*** unknown tvp%04x chip detected.\n", in tvp5150_detect_version()
1861 core->dev_id); in tvp5150_detect_version()
1872 pdn_gpio = devm_gpiod_get_optional(&c->dev, "pdn", GPIOD_OUT_HIGH); in tvp5150_init()
1878 /* Delay time between power supplies active and reset */ in tvp5150_init()
1882 reset_gpio = devm_gpiod_get_optional(&c->dev, "reset", GPIOD_OUT_HIGH); in tvp5150_init()
1900 struct v4l2_subdev *sd = &decoder->sd; in tvp5150_mc_init()
1903 sd->entity.ops = &tvp5150_sd_media_ops; in tvp5150_mc_init()
1904 sd->entity.function = MEDIA_ENT_F_ATV_DECODER; in tvp5150_mc_init()
1906 for (i = 0; i < TVP5150_NUM_PADS - 1; i++) { in tvp5150_mc_init()
1907 decoder->pads[i].flags = MEDIA_PAD_FL_SINK; in tvp5150_mc_init()
1908 decoder->pads[i].sig_type = PAD_SIGNAL_ANALOG; in tvp5150_mc_init()
1911 decoder->pads[i].flags = MEDIA_PAD_FL_SOURCE; in tvp5150_mc_init()
1912 decoder->pads[i].sig_type = PAD_SIGNAL_DV; in tvp5150_mc_init()
1914 return media_entity_pads_init(&sd->entity, TVP5150_NUM_PADS, in tvp5150_mc_init()
1915 decoder->pads); in tvp5150_mc_init()
1928 struct device *dev = decoder->sd.dev; in tvp5150_validate_connectors()
1933 if (!decoder->connectors_num) { in tvp5150_validate_connectors()
1935 return -ENODEV; in tvp5150_validate_connectors()
1938 for (i = 0; i < decoder->connectors_num; i++) { in tvp5150_validate_connectors()
1942 tvpc = &decoder->connectors[i]; in tvp5150_validate_connectors()
1943 v4l2c = &tvpc->base; in tvp5150_validate_connectors()
1945 if (v4l2c->type == V4L2_CONN_COMPOSITE) { in tvp5150_validate_connectors()
1946 if (v4l2c->nr_of_links != 1) { in tvp5150_validate_connectors()
1948 return -EINVAL; in tvp5150_validate_connectors()
1953 return -EINVAL; in tvp5150_validate_connectors()
1955 if (link0->fwnode_link.remote_id == 1) { in tvp5150_validate_connectors()
1957 return -EINVAL; in tvp5150_validate_connectors()
1961 if (v4l2c->type == V4L2_CONN_SVIDEO) { in tvp5150_validate_connectors()
1962 if (v4l2c->nr_of_links != 2) { in tvp5150_validate_connectors()
1964 return -EINVAL; in tvp5150_validate_connectors()
1969 return -EINVAL; in tvp5150_validate_connectors()
1972 if (link0->fwnode_link.remote_port == in tvp5150_validate_connectors()
1973 link1->fwnode_link.remote_port) { in tvp5150_validate_connectors()
1975 return -EINVAL; in tvp5150_validate_connectors()
1979 if (!(v4l2c->connector.analog.sdtv_stds & TVP5150_STD_MASK)) { in tvp5150_validate_connectors()
1980 dev_err(dev, "Unsupported tv-norm on connector %s\n", in tvp5150_validate_connectors()
1981 v4l2c->name); in tvp5150_validate_connectors()
1982 return -EINVAL; in tvp5150_validate_connectors()
1991 struct device *dev = decoder->sd.dev; in tvp5150_parse_dt()
2006 return -EINVAL; in tvp5150_parse_dt()
2011 * tvp-5150 port@0 (AIP1A) in tvp5150_parse_dt()
2012 * endpoint@0 -----------> Comp0-Con port in tvp5150_parse_dt()
2013 * endpoint@1 --------+--> Svideo-Con port in tvp5150_parse_dt()
2014 * tvp-5150 port@1 (AIP1B) | in tvp5150_parse_dt()
2015 * endpoint@1 --------+ in tvp5150_parse_dt()
2016 * endpoint@0 -----------> Comp1-Con port in tvp5150_parse_dt()
2017 * tvp-5150 port@2 in tvp5150_parse_dt()
2018 * endpoint (video bitstream output at YOUT[0-7] parallel bus) in tvp5150_parse_dt()
2022 unsigned int next_connector = decoder->connectors_num; in tvp5150_parse_dt()
2027 dev_dbg(dev, "Ignore connector on port@%u/ep@%u\n", in tvp5150_parse_dt()
2032 tvpc = &decoder->connectors[next_connector]; in tvp5150_parse_dt()
2033 v4l2c = &tvpc->base; in tvp5150_parse_dt()
2042 decoder->connectors_num++; in tvp5150_parse_dt()
2046 tvpc = &decoder->connectors[i]; in tvp5150_parse_dt()
2047 v4l2c = &tvpc->base; in tvp5150_parse_dt()
2048 if (v4l2c->type == V4L2_CONN_SVIDEO) in tvp5150_parse_dt()
2062 for (i = 0; i < decoder->connectors_num; i++) { in tvp5150_parse_dt()
2063 tvpc = &decoder->connectors[i]; in tvp5150_parse_dt()
2064 v4l2c = &tvpc->base; in tvp5150_parse_dt()
2065 tvpc->ent.flags = MEDIA_ENT_FL_CONNECTOR; in tvp5150_parse_dt()
2066 tvpc->ent.function = v4l2c->type == V4L2_CONN_SVIDEO ? in tvp5150_parse_dt()
2068 tvpc->ent.name = devm_kasprintf(dev, GFP_KERNEL, "%s %s", in tvp5150_parse_dt()
2069 v4l2c->name, v4l2c->label ? in tvp5150_parse_dt()
2070 v4l2c->label : ""); in tvp5150_parse_dt()
2075 ret = -EINVAL; in tvp5150_parse_dt()
2089 ret = -EINVAL; in tvp5150_parse_dt()
2093 decoder->mbus_type = bus_cfg.bus_type; in tvp5150_parse_dt()
2101 v4l2_fwnode_connector_free(&decoder->connectors[i].base); in tvp5150_parse_dt()
2115 struct device_node *np = c->dev.of_node; in tvp5150_probe()
2121 if (!i2c_check_functionality(c->adapter, in tvp5150_probe()
2123 return -EIO; in tvp5150_probe()
2129 core = devm_kzalloc(&c->dev, sizeof(*core), GFP_KERNEL); in tvp5150_probe()
2131 return -ENOMEM; in tvp5150_probe()
2137 core->regmap = map; in tvp5150_probe()
2138 sd = &core->sd; in tvp5150_probe()
2140 sd->internal_ops = &tvp5150_internal_ops; in tvp5150_probe()
2141 sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS; in tvp5150_probe()
2146 dev_err(sd->dev, "DT parsing error: %d\n", res); in tvp5150_probe()
2151 core->mbus_type = V4L2_MBUS_BT656; in tvp5150_probe()
2167 for (i = 0; i < core->connectors_num; i++) { in tvp5150_probe()
2170 v4l2c = &core->connectors[i].base; in tvp5150_probe()
2171 core->norm |= v4l2c->connector.analog.sdtv_stds; in tvp5150_probe()
2174 if (!core->connectors_num) in tvp5150_probe()
2175 core->norm = V4L2_STD_ALL; in tvp5150_probe()
2177 core->detected_norm = V4L2_STD_UNKNOWN; in tvp5150_probe()
2178 core->input = TVP5150_COMPOSITE1; in tvp5150_probe()
2179 core->enable = true; in tvp5150_probe()
2181 v4l2_ctrl_handler_init(&core->hdl, 5); in tvp5150_probe()
2182 v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops, in tvp5150_probe()
2184 v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops, in tvp5150_probe()
2186 v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops, in tvp5150_probe()
2188 v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops, in tvp5150_probe()
2189 V4L2_CID_HUE, -128, 127, 1, 0); in tvp5150_probe()
2190 v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops, in tvp5150_probe()
2193 v4l2_ctrl_new_std_menu_items(&core->hdl, &tvp5150_ctrl_ops, in tvp5150_probe()
2195 ARRAY_SIZE(tvp5150_test_patterns) - 1, in tvp5150_probe()
2197 sd->ctrl_handler = &core->hdl; in tvp5150_probe()
2198 if (core->hdl.error) { in tvp5150_probe()
2199 res = core->hdl.error; in tvp5150_probe()
2203 tvp5150_set_default(tvp5150_read_std(sd), &core->rect); in tvp5150_probe()
2205 core->irq = c->irq; in tvp5150_probe()
2207 if (c->irq) { in tvp5150_probe()
2208 res = devm_request_threaded_irq(&c->dev, c->irq, NULL, in tvp5150_probe()
2222 pm_runtime_set_active(&c->dev); in tvp5150_probe()
2223 pm_runtime_enable(&c->dev); in tvp5150_probe()
2224 pm_runtime_idle(&c->dev); in tvp5150_probe()
2229 v4l2_ctrl_handler_free(&core->hdl); in tvp5150_probe()
2239 dev_dbg_lvl(sd->dev, 1, debug, in tvp5150_remove()
2240 "tvp5150.c: removing tvp5150 adapter on address 0x%x\n", in tvp5150_remove()
2241 c->addr << 1); in tvp5150_remove()
2243 for (i = 0; i < decoder->connectors_num; i++) in tvp5150_remove()
2244 v4l2_fwnode_connector_free(&decoder->connectors[i].base); in tvp5150_remove()
2245 for (i = 0; i < decoder->connectors_num; i++) { in tvp5150_remove()
2246 media_device_unregister_entity(&decoder->connectors[i].ent); in tvp5150_remove()
2247 media_entity_cleanup(&decoder->connectors[i].ent); in tvp5150_remove()
2250 v4l2_ctrl_handler_free(&decoder->hdl); in tvp5150_remove()
2251 pm_runtime_disable(&c->dev); in tvp5150_remove()
2252 pm_runtime_set_suspended(&c->dev); in tvp5150_remove()
2255 /* ----------------------------------------------------------------------- */