Lines Matching +full:non +full:- +full:standard
1 // SPDX-License-Identifier: GPL-2.0-only
15 * Karicheri Muralidharan <m-[email protected]>
26 #include <linux/v4l2-mediabus.h>
30 #include <media/media-entity.h>
31 #include <media/v4l2-async.h>
32 #include <media/v4l2-common.h>
33 #include <media/v4l2-ctrls.h>
34 #include <media/v4l2-device.h>
35 #include <media/v4l2-fwnode.h>
36 #include <media/v4l2-mediabus.h>
48 MODULE_PARM_DESC(debug, "Debug level (0-1)");
54 /* enum tvp514x_std - enum for supported standards */
62 * struct tvp514x_std_info - Structure to store standard information
66 * @standard: v4l2 standard structure information
72 struct v4l2_standard standard; member
79 * struct tvp514x_decoder - TVP5146/47 decoder object
85 * @streaming: TVP5146/47 decoder streaming - enabled or disabled.
89 * @current_std: Current standard
195 /* 10-bit BT.656 */
220 .description = "8-bit UYVY 4:2:2 Format",
226 * Supported standards -
232 /* Standard: STD_NTSC_MJ */
237 .standard = {
244 /* Standard: STD_PAL_BDGHIN */
250 .standard = {
258 /* Standard: need to add for additional standard */
269 return &container_of(ctrl->handler, struct tvp514x_decoder, hdl)->sd; in to_sd()
274 * tvp514x_read_reg() - Read a value from a register in an TVP5146/47.
278 * Returns value read if successful, or non-zero (-1) otherwise.
301 * dump_reg() - dump the register content of TVP5146/47.
314 * tvp514x_write_reg() - Write a value to a register in TVP5146/47
320 * Returns zero if successful, or non-zero otherwise.
347 * Initializes a list of TVP5146/47 registers:-
352 * Returns zero if successful, or non-zero otherwise.
360 for (; next->token != TOK_TERM; next++) { in tvp514x_write_regs()
361 if (next->token == TOK_DELAY) { in tvp514x_write_regs()
362 msleep(next->val); in tvp514x_write_regs()
366 if (next->token == TOK_SKIP) in tvp514x_write_regs()
369 err = tvp514x_write_reg(sd, next->reg, (u8) next->val); in tvp514x_write_regs()
379 * tvp514x_query_current_std() : Query the current standard detected by TVP5146/47
382 * Returns the current standard detected by TVP5146/47, STD_INVALID if there is no
383 * standard detected.
391 /* use the standard status register */ in tvp514x_query_current_std()
394 /* use the standard register itself */ in tvp514x_query_current_std()
459 * tvp514x_configure() - Configure the TVP5146/47 registers
463 * Returns zero if successful, or non-zero otherwise.
472 tvp514x_write_regs(sd, decoder->tvp514x_regs); in tvp514x_configure()
483 * tvp514x_detect() - Detect if an tvp514x is present, and if so which revision.
484 * @sd: pointer to standard V4L2 sub-device structure
514 return -ENODEV; in tvp514x_detect()
517 decoder->ver = rom_ver; in tvp514x_detect()
519 v4l2_info(sd, "%s (Version - 0x%.2x) found at 0x%x (%s)\n", in tvp514x_detect()
520 client->name, decoder->ver, in tvp514x_detect()
521 client->addr << 1, client->adapter->name); in tvp514x_detect()
526 * tvp514x_querystd() - V4L2 decoder interface handler for querystd
527 * @sd: pointer to standard V4L2 sub-device structure
528 * @std_id: standard V4L2 std_id ioctl enum
530 * Returns the current standard detected by TVP5146/47. If no active input is
541 return -EINVAL; in tvp514x_querystd()
543 /* To query the standard the TVP514x must power on the ADCs. */ in tvp514x_querystd()
544 if (!decoder->streaming) { in tvp514x_querystd()
549 /* query the current standard */ in tvp514x_querystd()
556 input_sel = decoder->input; in tvp514x_querystd()
591 return -EINVAL; in tvp514x_querystd()
600 *std_id &= decoder->std_list[current_std].standard.id; in tvp514x_querystd()
603 decoder->std_list[current_std].standard.name); in tvp514x_querystd()
608 * tvp514x_s_std() - V4L2 decoder interface handler for s_std
609 * @sd: pointer to standard V4L2 sub-device structure
610 * @std_id: standard V4L2 v4l2_std_id ioctl enum
612 * If std_id is supported, sets the requested standard. Otherwise, returns
613 * -EINVAL
620 for (i = 0; i < decoder->num_stds; i++) in tvp514x_s_std()
621 if (std_id & decoder->std_list[i].standard.id) in tvp514x_s_std()
624 if ((i == decoder->num_stds) || (i == STD_INVALID)) in tvp514x_s_std()
625 return -EINVAL; in tvp514x_s_std()
628 decoder->std_list[i].video_std); in tvp514x_s_std()
632 decoder->current_std = i; in tvp514x_s_std()
633 decoder->tvp514x_regs[REG_VIDEO_STD].val = in tvp514x_s_std()
634 decoder->std_list[i].video_std; in tvp514x_s_std()
636 v4l2_dbg(1, debug, sd, "Standard set to: %s\n", in tvp514x_s_std()
637 decoder->std_list[i].standard.name); in tvp514x_s_std()
642 * tvp514x_s_routing() - V4L2 decoder interface handler for s_routing
643 * @sd: pointer to standard V4L2 sub-device structure
648 * If index is valid, selects the requested input. Otherwise, returns -EINVAL if
663 return -EINVAL; in tvp514x_s_routing()
679 decoder->tvp514x_regs[REG_INPUT_SEL].val = input_sel; in tvp514x_s_routing()
680 decoder->tvp514x_regs[REG_OUTPUT_FORMATTER1].val = output_sel; in tvp514x_s_routing()
681 decoder->input = input; in tvp514x_s_routing()
682 decoder->output = output; in tvp514x_s_routing()
690 * tvp514x_s_ctrl() - V4L2 decoder interface handler for s_ctrl
694 * value in HW. Otherwise, returns -EINVAL if the control is not supported.
700 int err = -EINVAL, value; in tvp514x_s_ctrl()
702 value = ctrl->val; in tvp514x_s_ctrl()
704 switch (ctrl->id) { in tvp514x_s_ctrl()
708 decoder->tvp514x_regs[REG_BRIGHTNESS].val = value; in tvp514x_s_ctrl()
713 decoder->tvp514x_regs[REG_CONTRAST].val = value; in tvp514x_s_ctrl()
718 decoder->tvp514x_regs[REG_SATURATION].val = value; in tvp514x_s_ctrl()
723 else if (value == -180) in tvp514x_s_ctrl()
727 decoder->tvp514x_regs[REG_HUE].val = value; in tvp514x_s_ctrl()
732 decoder->tvp514x_regs[REG_AFE_GAIN_CTRL].val = value; in tvp514x_s_ctrl()
736 v4l2_dbg(1, debug, sd, "Set Control: ID - %d - %d\n", in tvp514x_s_ctrl()
737 ctrl->id, ctrl->val); in tvp514x_s_ctrl()
753 if (ival->which != V4L2_SUBDEV_FORMAT_ACTIVE) in tvp514x_get_frame_interval()
754 return -EINVAL; in tvp514x_get_frame_interval()
756 /* get the current standard */ in tvp514x_get_frame_interval()
757 current_std = decoder->current_std; in tvp514x_get_frame_interval()
759 ival->interval = in tvp514x_get_frame_interval()
760 decoder->std_list[current_std].standard.frameperiod; in tvp514x_get_frame_interval()
778 if (ival->which != V4L2_SUBDEV_FORMAT_ACTIVE) in tvp514x_set_frame_interval()
779 return -EINVAL; in tvp514x_set_frame_interval()
781 timeperframe = &ival->interval; in tvp514x_set_frame_interval()
783 /* get the current standard */ in tvp514x_set_frame_interval()
784 current_std = decoder->current_std; in tvp514x_set_frame_interval()
787 decoder->std_list[current_std].standard.frameperiod; in tvp514x_set_frame_interval()
793 * tvp514x_s_stream() - V4L2 decoder i/f handler for s_stream
794 * @sd: pointer to standard V4L2 sub-device structure
804 if (decoder->streaming == enable) in tvp514x_s_stream()
816 decoder->streaming = enable; in tvp514x_s_stream()
822 err = tvp514x_write_regs(sd, decoder->int_seq); in tvp514x_s_stream()
838 decoder->streaming = enable; in tvp514x_s_stream()
842 err = -ENODEV; in tvp514x_s_stream()
854 * tvp514x_enum_mbus_code() - V4L2 decoder interface handler for enum_mbus_code
855 * @sd: pointer to standard V4L2 sub-device structure
865 u32 pad = code->pad; in tvp514x_enum_mbus_code()
866 u32 index = code->index; in tvp514x_enum_mbus_code()
869 code->index = index; in tvp514x_enum_mbus_code()
870 code->pad = pad; in tvp514x_enum_mbus_code()
873 return -EINVAL; in tvp514x_enum_mbus_code()
875 code->code = MEDIA_BUS_FMT_UYVY8_2X8; in tvp514x_enum_mbus_code()
881 * tvp514x_get_pad_format() - V4L2 decoder interface handler for get pad format
882 * @sd: pointer to standard V4L2 sub-device structure
893 __u32 which = format->which; in tvp514x_get_pad_format()
895 if (format->pad) in tvp514x_get_pad_format()
896 return -EINVAL; in tvp514x_get_pad_format()
899 format->format = decoder->format; in tvp514x_get_pad_format()
903 format->format.code = MEDIA_BUS_FMT_UYVY8_2X8; in tvp514x_get_pad_format()
904 format->format.width = tvp514x_std_list[decoder->current_std].width; in tvp514x_get_pad_format()
905 format->format.height = tvp514x_std_list[decoder->current_std].height; in tvp514x_get_pad_format()
906 format->format.colorspace = V4L2_COLORSPACE_SMPTE170M; in tvp514x_get_pad_format()
907 format->format.field = V4L2_FIELD_INTERLACED; in tvp514x_get_pad_format()
913 * tvp514x_set_pad_format() - V4L2 decoder interface handler for set pad format
914 * @sd: pointer to standard V4L2 sub-device structure
926 if (fmt->format.field != V4L2_FIELD_INTERLACED || in tvp514x_set_pad_format()
927 fmt->format.code != MEDIA_BUS_FMT_UYVY8_2X8 || in tvp514x_set_pad_format()
928 fmt->format.colorspace != V4L2_COLORSPACE_SMPTE170M || in tvp514x_set_pad_format()
929 fmt->format.width != tvp514x_std_list[decoder->current_std].width || in tvp514x_set_pad_format()
930 fmt->format.height != tvp514x_std_list[decoder->current_std].height) in tvp514x_set_pad_format()
931 return -EINVAL; in tvp514x_set_pad_format()
933 decoder->format = fmt->format; in tvp514x_set_pad_format()
963 /* Default to NTSC 8-bit YUV 422 */
987 if (!IS_ENABLED(CONFIG_OF) || !client->dev.of_node) in tvp514x_get_pdata()
988 return client->dev.platform_data; in tvp514x_get_pdata()
990 endpoint = of_graph_get_endpoint_by_regs(client->dev.of_node, 0, -1); in tvp514x_get_pdata()
997 pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL); in tvp514x_get_pdata()
1004 pdata->hs_polarity = 1; in tvp514x_get_pdata()
1007 pdata->vs_polarity = 1; in tvp514x_get_pdata()
1010 pdata->clk_polarity = 1; in tvp514x_get_pdata()
1018 * tvp514x_probe() - decoder driver i2c probe handler
1033 dev_err(&client->dev, "No platform data\n"); in tvp514x_probe()
1034 return -EINVAL; in tvp514x_probe()
1038 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) in tvp514x_probe()
1039 return -EIO; in tvp514x_probe()
1041 decoder = devm_kzalloc(&client->dev, sizeof(*decoder), GFP_KERNEL); in tvp514x_probe()
1043 return -ENOMEM; in tvp514x_probe()
1048 memcpy(decoder->tvp514x_regs, tvp514x_reg_list_default, in tvp514x_probe()
1051 decoder->int_seq = i2c_get_match_data(client); in tvp514x_probe()
1054 decoder->pdata = pdata; in tvp514x_probe()
1061 decoder->tvp514x_regs[REG_OUTPUT_FORMATTER2].val |= in tvp514x_probe()
1062 (decoder->pdata->clk_polarity << 1); in tvp514x_probe()
1063 decoder->tvp514x_regs[REG_SYNC_CONTROL].val |= in tvp514x_probe()
1064 ((decoder->pdata->hs_polarity << 2) | in tvp514x_probe()
1065 (decoder->pdata->vs_polarity << 3)); in tvp514x_probe()
1066 /* Set default standard to auto */ in tvp514x_probe()
1067 decoder->tvp514x_regs[REG_VIDEO_STD].val = in tvp514x_probe()
1071 sd = &decoder->sd; in tvp514x_probe()
1075 decoder->pad.flags = MEDIA_PAD_FL_SOURCE; in tvp514x_probe()
1076 decoder->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in tvp514x_probe()
1077 decoder->sd.entity.function = MEDIA_ENT_F_ATV_DECODER; in tvp514x_probe()
1079 ret = media_entity_pads_init(&decoder->sd.entity, 1, &decoder->pad); in tvp514x_probe()
1082 sd->name); in tvp514x_probe()
1086 v4l2_ctrl_handler_init(&decoder->hdl, 5); in tvp514x_probe()
1087 v4l2_ctrl_new_std(&decoder->hdl, &tvp514x_ctrl_ops, in tvp514x_probe()
1089 v4l2_ctrl_new_std(&decoder->hdl, &tvp514x_ctrl_ops, in tvp514x_probe()
1091 v4l2_ctrl_new_std(&decoder->hdl, &tvp514x_ctrl_ops, in tvp514x_probe()
1093 v4l2_ctrl_new_std(&decoder->hdl, &tvp514x_ctrl_ops, in tvp514x_probe()
1094 V4L2_CID_HUE, -180, 180, 180, 0); in tvp514x_probe()
1095 v4l2_ctrl_new_std(&decoder->hdl, &tvp514x_ctrl_ops, in tvp514x_probe()
1097 sd->ctrl_handler = &decoder->hdl; in tvp514x_probe()
1098 if (decoder->hdl.error) { in tvp514x_probe()
1099 ret = decoder->hdl.error; in tvp514x_probe()
1102 v4l2_ctrl_handler_setup(&decoder->hdl); in tvp514x_probe()
1104 ret = v4l2_async_register_subdev(&decoder->sd); in tvp514x_probe()
1106 v4l2_info(sd, "%s decoder driver registered !!\n", sd->name); in tvp514x_probe()
1110 v4l2_ctrl_handler_free(&decoder->hdl); in tvp514x_probe()
1111 media_entity_cleanup(&decoder->sd.entity); in tvp514x_probe()
1117 * tvp514x_remove() - decoder driver i2c remove handler
1128 v4l2_async_unregister_subdev(&decoder->sd); in tvp514x_remove()
1129 media_entity_cleanup(&decoder->sd.entity); in tvp514x_remove()
1130 v4l2_ctrl_handler_free(&decoder->hdl); in tvp514x_remove()
1179 * I2C Device Table -
1181 * name - Name of the actual device/chip.
1182 * driver_data - Driver data