aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/tvp514x.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video/tvp514x.c')
-rw-r--r--drivers/media/video/tvp514x.c223
1 files changed, 40 insertions, 183 deletions
diff --git a/drivers/media/video/tvp514x.c b/drivers/media/video/tvp514x.c
index e826114b7fb8..71c73fa0d68c 100644
--- a/drivers/media/video/tvp514x.c
+++ b/drivers/media/video/tvp514x.c
@@ -88,9 +88,6 @@ static int tvp514x_s_stream(struct v4l2_subdev *sd, int enable);
88 * @pdata: Board specific 88 * @pdata: Board specific
89 * @ver: Chip version 89 * @ver: Chip version
90 * @streaming: TVP5146/47 decoder streaming - enabled or disabled. 90 * @streaming: TVP5146/47 decoder streaming - enabled or disabled.
91 * @pix: Current pixel format
92 * @num_fmts: Number of formats
93 * @fmt_list: Format list
94 * @current_std: Current standard 91 * @current_std: Current standard
95 * @num_stds: Number of standards 92 * @num_stds: Number of standards
96 * @std_list: Standards list 93 * @std_list: Standards list
@@ -105,13 +102,9 @@ struct tvp514x_decoder {
105 int ver; 102 int ver;
106 int streaming; 103 int streaming;
107 104
108 struct v4l2_pix_format pix;
109 int num_fmts;
110 const struct v4l2_fmtdesc *fmt_list;
111
112 enum tvp514x_std current_std; 105 enum tvp514x_std current_std;
113 int num_stds; 106 int num_stds;
114 struct tvp514x_std_info *std_list; 107 const struct tvp514x_std_info *std_list;
115 /* Input and Output Routing parameters */ 108 /* Input and Output Routing parameters */
116 u32 input; 109 u32 input;
117 u32 output; 110 u32 output;
@@ -203,27 +196,12 @@ static struct tvp514x_reg tvp514x_reg_list_default[] = {
203}; 196};
204 197
205/** 198/**
206 * List of image formats supported by TVP5146/47 decoder
207 * Currently we are using 8 bit mode only, but can be
208 * extended to 10/20 bit mode.
209 */
210static const struct v4l2_fmtdesc tvp514x_fmt_list[] = {
211 {
212 .index = 0,
213 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
214 .flags = 0,
215 .description = "8-bit UYVY 4:2:2 Format",
216 .pixelformat = V4L2_PIX_FMT_UYVY,
217 },
218};
219
220/**
221 * Supported standards - 199 * Supported standards -
222 * 200 *
223 * Currently supports two standards only, need to add support for rest of the 201 * Currently supports two standards only, need to add support for rest of the
224 * modes, like SECAM, etc... 202 * modes, like SECAM, etc...
225 */ 203 */
226static struct tvp514x_std_info tvp514x_std_list[] = { 204static const struct tvp514x_std_info tvp514x_std_list[] = {
227 /* Standard: STD_NTSC_MJ */ 205 /* Standard: STD_NTSC_MJ */
228 [STD_NTSC_MJ] = { 206 [STD_NTSC_MJ] = {
229 .width = NTSC_NUM_ACTIVE_PIXELS, 207 .width = NTSC_NUM_ACTIVE_PIXELS,
@@ -366,13 +344,13 @@ static int tvp514x_write_regs(struct v4l2_subdev *sd,
366} 344}
367 345
368/** 346/**
369 * tvp514x_get_current_std() : Get the current standard detected by TVP5146/47 347 * tvp514x_query_current_std() : Query the current standard detected by TVP5146/47
370 * @sd: ptr to v4l2_subdev struct 348 * @sd: ptr to v4l2_subdev struct
371 * 349 *
372 * Get current standard detected by TVP5146/47, STD_INVALID if there is no 350 * Returns the current standard detected by TVP5146/47, STD_INVALID if there is no
373 * standard detected. 351 * standard detected.
374 */ 352 */
375static enum tvp514x_std tvp514x_get_current_std(struct v4l2_subdev *sd) 353static enum tvp514x_std tvp514x_query_current_std(struct v4l2_subdev *sd)
376{ 354{
377 u8 std, std_status; 355 u8 std, std_status;
378 356
@@ -518,7 +496,7 @@ static int tvp514x_detect(struct v4l2_subdev *sd,
518 * @std_id: standard V4L2 std_id ioctl enum 496 * @std_id: standard V4L2 std_id ioctl enum
519 * 497 *
520 * Returns the current standard detected by TVP5146/47. If no active input is 498 * Returns the current standard detected by TVP5146/47. If no active input is
521 * detected, returns -EINVAL 499 * detected then *std_id is set to 0 and the function returns 0.
522 */ 500 */
523static int tvp514x_querystd(struct v4l2_subdev *sd, v4l2_std_id *std_id) 501static int tvp514x_querystd(struct v4l2_subdev *sd, v4l2_std_id *std_id)
524{ 502{
@@ -530,10 +508,12 @@ static int tvp514x_querystd(struct v4l2_subdev *sd, v4l2_std_id *std_id)
530 if (std_id == NULL) 508 if (std_id == NULL)
531 return -EINVAL; 509 return -EINVAL;
532 510
533 /* get the current standard */ 511 *std_id = V4L2_STD_UNKNOWN;
534 current_std = tvp514x_get_current_std(sd); 512
513 /* query the current standard */
514 current_std = tvp514x_query_current_std(sd);
535 if (current_std == STD_INVALID) 515 if (current_std == STD_INVALID)
536 return -EINVAL; 516 return 0;
537 517
538 input_sel = decoder->input; 518 input_sel = decoder->input;
539 519
@@ -575,12 +555,11 @@ static int tvp514x_querystd(struct v4l2_subdev *sd, v4l2_std_id *std_id)
575 /* check whether signal is locked */ 555 /* check whether signal is locked */
576 sync_lock_status = tvp514x_read_reg(sd, REG_STATUS1); 556 sync_lock_status = tvp514x_read_reg(sd, REG_STATUS1);
577 if (lock_mask != (sync_lock_status & lock_mask)) 557 if (lock_mask != (sync_lock_status & lock_mask))
578 return -EINVAL; /* No input detected */ 558 return 0; /* No input detected */
579 559
580 decoder->current_std = current_std;
581 *std_id = decoder->std_list[current_std].standard.id; 560 *std_id = decoder->std_list[current_std].standard.id;
582 561
583 v4l2_dbg(1, debug, sd, "Current STD: %s", 562 v4l2_dbg(1, debug, sd, "Current STD: %s\n",
584 decoder->std_list[current_std].standard.name); 563 decoder->std_list[current_std].standard.name);
585 return 0; 564 return 0;
586} 565}
@@ -614,7 +593,7 @@ static int tvp514x_s_std(struct v4l2_subdev *sd, v4l2_std_id std_id)
614 decoder->tvp514x_regs[REG_VIDEO_STD].val = 593 decoder->tvp514x_regs[REG_VIDEO_STD].val =
615 decoder->std_list[i].video_std; 594 decoder->std_list[i].video_std;
616 595
617 v4l2_dbg(1, debug, sd, "Standard set to: %s", 596 v4l2_dbg(1, debug, sd, "Standard set to: %s\n",
618 decoder->std_list[i].standard.name); 597 decoder->std_list[i].standard.name);
619 return 0; 598 return 0;
620} 599}
@@ -637,7 +616,6 @@ static int tvp514x_s_routing(struct v4l2_subdev *sd,
637 int err; 616 int err;
638 enum tvp514x_input input_sel; 617 enum tvp514x_input input_sel;
639 enum tvp514x_output output_sel; 618 enum tvp514x_output output_sel;
640 enum tvp514x_std current_std = STD_INVALID;
641 u8 sync_lock_status, lock_mask; 619 u8 sync_lock_status, lock_mask;
642 int try_count = LOCK_RETRY_COUNT; 620 int try_count = LOCK_RETRY_COUNT;
643 621
@@ -721,11 +699,6 @@ static int tvp514x_s_routing(struct v4l2_subdev *sd,
721 /* Allow decoder to sync up with new input */ 699 /* Allow decoder to sync up with new input */
722 msleep(LOCK_RETRY_DELAY); 700 msleep(LOCK_RETRY_DELAY);
723 701
724 /* get the current standard for future reference */
725 current_std = tvp514x_get_current_std(sd);
726 if (current_std == STD_INVALID)
727 continue;
728
729 sync_lock_status = tvp514x_read_reg(sd, 702 sync_lock_status = tvp514x_read_reg(sd,
730 REG_STATUS1); 703 REG_STATUS1);
731 if (lock_mask == (sync_lock_status & lock_mask)) 704 if (lock_mask == (sync_lock_status & lock_mask))
@@ -733,15 +706,13 @@ static int tvp514x_s_routing(struct v4l2_subdev *sd,
733 break; 706 break;
734 } 707 }
735 708
736 if ((current_std == STD_INVALID) || (try_count < 0)) 709 if (try_count < 0)
737 return -EINVAL; 710 return -EINVAL;
738 711
739 decoder->current_std = current_std;
740 decoder->input = input; 712 decoder->input = input;
741 decoder->output = output; 713 decoder->output = output;
742 714
743 v4l2_dbg(1, debug, sd, "Input set to: %d, std : %d", 715 v4l2_dbg(1, debug, sd, "Input set to: %d\n", input_sel);
744 input_sel, current_std);
745 716
746 return 0; 717 return 0;
747} 718}
@@ -794,7 +765,7 @@ tvp514x_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qctrl)
794 return err; 765 return err;
795 } 766 }
796 767
797 v4l2_dbg(1, debug, sd, "Query Control:%s: Min - %d, Max - %d, Def - %d", 768 v4l2_dbg(1, debug, sd, "Query Control:%s: Min - %d, Max - %d, Def - %d\n",
798 qctrl->name, qctrl->minimum, qctrl->maximum, 769 qctrl->name, qctrl->minimum, qctrl->maximum,
799 qctrl->default_value); 770 qctrl->default_value);
800 771
@@ -851,7 +822,7 @@ tvp514x_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
851 return -EINVAL; 822 return -EINVAL;
852 } 823 }
853 824
854 v4l2_dbg(1, debug, sd, "Get Control: ID - %d - %d", 825 v4l2_dbg(1, debug, sd, "Get Control: ID - %d - %d\n",
855 ctrl->id, ctrl->value); 826 ctrl->id, ctrl->value);
856 return 0; 827 return 0;
857} 828}
@@ -951,7 +922,7 @@ tvp514x_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
951 return err; 922 return err;
952 } 923 }
953 924
954 v4l2_dbg(1, debug, sd, "Set Control: ID - %d - %d", 925 v4l2_dbg(1, debug, sd, "Set Control: ID - %d - %d\n",
955 ctrl->id, ctrl->value); 926 ctrl->id, ctrl->value);
956 927
957 return err; 928 return err;
@@ -967,44 +938,33 @@ tvp514x_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
967static int 938static int
968tvp514x_enum_fmt_cap(struct v4l2_subdev *sd, struct v4l2_fmtdesc *fmt) 939tvp514x_enum_fmt_cap(struct v4l2_subdev *sd, struct v4l2_fmtdesc *fmt)
969{ 940{
970 struct tvp514x_decoder *decoder = to_decoder(sd); 941 if (fmt == NULL || fmt->index)
971 int index;
972
973 if (fmt == NULL)
974 return -EINVAL;
975
976 index = fmt->index;
977 if ((index >= decoder->num_fmts) || (index < 0))
978 /* Index out of bound */
979 return -EINVAL; 942 return -EINVAL;
980 943
981 if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 944 if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
982 /* only capture is supported */ 945 /* only capture is supported */
983 return -EINVAL; 946 return -EINVAL;
984 947
985 memcpy(fmt, &decoder->fmt_list[index], 948 /* only one format */
986 sizeof(struct v4l2_fmtdesc)); 949 fmt->flags = 0;
987 950 strlcpy(fmt->description, "8-bit UYVY 4:2:2 Format",
988 v4l2_dbg(1, debug, sd, "Current FMT: index - %d (%s)", 951 sizeof(fmt->description));
989 decoder->fmt_list[index].index, 952 fmt->pixelformat = V4L2_PIX_FMT_UYVY;
990 decoder->fmt_list[index].description);
991 return 0; 953 return 0;
992} 954}
993 955
994/** 956/**
995 * tvp514x_try_fmt_cap() - V4L2 decoder interface handler for try_fmt 957 * tvp514x_fmt_cap() - V4L2 decoder interface handler for try/s/g_fmt
996 * @sd: pointer to standard V4L2 sub-device structure 958 * @sd: pointer to standard V4L2 sub-device structure
997 * @f: pointer to standard V4L2 VIDIOC_TRY_FMT ioctl structure 959 * @f: pointer to standard V4L2 VIDIOC_TRY_FMT ioctl structure
998 * 960 *
999 * Implement the VIDIOC_TRY_FMT ioctl for the CAPTURE buffer type. This 961 * Implement the VIDIOC_TRY/S/G_FMT ioctl for the CAPTURE buffer type. This
1000 * ioctl is used to negotiate the image capture size and pixel format 962 * ioctl is used to negotiate the image capture size and pixel format.
1001 * without actually making it take effect.
1002 */ 963 */
1003static int 964static int
1004tvp514x_try_fmt_cap(struct v4l2_subdev *sd, struct v4l2_format *f) 965tvp514x_fmt_cap(struct v4l2_subdev *sd, struct v4l2_format *f)
1005{ 966{
1006 struct tvp514x_decoder *decoder = to_decoder(sd); 967 struct tvp514x_decoder *decoder = to_decoder(sd);
1007 int ifmt;
1008 struct v4l2_pix_format *pix; 968 struct v4l2_pix_format *pix;
1009 enum tvp514x_std current_std; 969 enum tvp514x_std current_std;
1010 970
@@ -1012,106 +972,30 @@ tvp514x_try_fmt_cap(struct v4l2_subdev *sd, struct v4l2_format *f)
1012 return -EINVAL; 972 return -EINVAL;
1013 973
1014 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 974 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1015 /* only capture is supported */ 975 return -EINVAL;
1016 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1017 976
1018 pix = &f->fmt.pix; 977 pix = &f->fmt.pix;
1019 978
1020 /* Calculate height and width based on current standard */ 979 /* Calculate height and width based on current standard */
1021 current_std = tvp514x_get_current_std(sd); 980 current_std = decoder->current_std;
1022 if (current_std == STD_INVALID)
1023 return -EINVAL;
1024 981
1025 decoder->current_std = current_std; 982 pix->pixelformat = V4L2_PIX_FMT_UYVY;
1026 pix->width = decoder->std_list[current_std].width; 983 pix->width = decoder->std_list[current_std].width;
1027 pix->height = decoder->std_list[current_std].height; 984 pix->height = decoder->std_list[current_std].height;
1028
1029 for (ifmt = 0; ifmt < decoder->num_fmts; ifmt++) {
1030 if (pix->pixelformat ==
1031 decoder->fmt_list[ifmt].pixelformat)
1032 break;
1033 }
1034 if (ifmt == decoder->num_fmts)
1035 /* None of the format matched, select default */
1036 ifmt = 0;
1037 pix->pixelformat = decoder->fmt_list[ifmt].pixelformat;
1038
1039 pix->field = V4L2_FIELD_INTERLACED; 985 pix->field = V4L2_FIELD_INTERLACED;
1040 pix->bytesperline = pix->width * 2; 986 pix->bytesperline = pix->width * 2;
1041 pix->sizeimage = pix->bytesperline * pix->height; 987 pix->sizeimage = pix->bytesperline * pix->height;
1042 pix->colorspace = V4L2_COLORSPACE_SMPTE170M; 988 pix->colorspace = V4L2_COLORSPACE_SMPTE170M;
1043 pix->priv = 0; 989 pix->priv = 0;
1044 990
1045 v4l2_dbg(1, debug, sd, "Try FMT: pixelformat - %s, bytesperline - %d" 991 v4l2_dbg(1, debug, sd, "FMT: bytesperline - %d"
1046 "Width - %d, Height - %d", 992 "Width - %d, Height - %d\n",
1047 decoder->fmt_list[ifmt].description, pix->bytesperline, 993 pix->bytesperline,
1048 pix->width, pix->height); 994 pix->width, pix->height);
1049 return 0; 995 return 0;
1050} 996}
1051 997
1052/** 998/**
1053 * tvp514x_s_fmt_cap() - V4L2 decoder interface handler for s_fmt
1054 * @sd: pointer to standard V4L2 sub-device structure
1055 * @f: pointer to standard V4L2 VIDIOC_S_FMT ioctl structure
1056 *
1057 * If the requested format is supported, configures the HW to use that
1058 * format, returns error code if format not supported or HW can't be
1059 * correctly configured.
1060 */
1061static int
1062tvp514x_s_fmt_cap(struct v4l2_subdev *sd, struct v4l2_format *f)
1063{
1064 struct tvp514x_decoder *decoder = to_decoder(sd);
1065 struct v4l2_pix_format *pix;
1066 int rval;
1067
1068 if (f == NULL)
1069 return -EINVAL;
1070
1071 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1072 /* only capture is supported */
1073 return -EINVAL;
1074
1075 pix = &f->fmt.pix;
1076 rval = tvp514x_try_fmt_cap(sd, f);
1077 if (rval)
1078 return rval;
1079
1080 decoder->pix = *pix;
1081
1082 return rval;
1083}
1084
1085/**
1086 * tvp514x_g_fmt_cap() - V4L2 decoder interface handler for tvp514x_g_fmt_cap
1087 * @sd: pointer to standard V4L2 sub-device structure
1088 * @f: pointer to standard V4L2 v4l2_format structure
1089 *
1090 * Returns the decoder's current pixel format in the v4l2_format
1091 * parameter.
1092 */
1093static int
1094tvp514x_g_fmt_cap(struct v4l2_subdev *sd, struct v4l2_format *f)
1095{
1096 struct tvp514x_decoder *decoder = to_decoder(sd);
1097
1098 if (f == NULL)
1099 return -EINVAL;
1100
1101 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1102 /* only capture is supported */
1103 return -EINVAL;
1104
1105 f->fmt.pix = decoder->pix;
1106
1107 v4l2_dbg(1, debug, sd, "Current FMT: bytesperline - %d"
1108 "Width - %d, Height - %d",
1109 decoder->pix.bytesperline,
1110 decoder->pix.width, decoder->pix.height);
1111 return 0;
1112}
1113
1114/**
1115 * tvp514x_g_parm() - V4L2 decoder interface handler for g_parm 999 * tvp514x_g_parm() - V4L2 decoder interface handler for g_parm
1116 * @sd: pointer to standard V4L2 sub-device structure 1000 * @sd: pointer to standard V4L2 sub-device structure
1117 * @a: pointer to standard V4L2 VIDIOC_G_PARM ioctl structure 1001 * @a: pointer to standard V4L2 VIDIOC_G_PARM ioctl structure
@@ -1132,15 +1016,8 @@ tvp514x_g_parm(struct v4l2_subdev *sd, struct v4l2_streamparm *a)
1132 /* only capture is supported */ 1016 /* only capture is supported */
1133 return -EINVAL; 1017 return -EINVAL;
1134 1018
1135 memset(a, 0, sizeof(*a));
1136 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1137
1138 /* get the current standard */ 1019 /* get the current standard */
1139 current_std = tvp514x_get_current_std(sd); 1020 current_std = decoder->current_std;
1140 if (current_std == STD_INVALID)
1141 return -EINVAL;
1142
1143 decoder->current_std = current_std;
1144 1021
1145 cparm = &a->parm.capture; 1022 cparm = &a->parm.capture;
1146 cparm->capability = V4L2_CAP_TIMEPERFRAME; 1023 cparm->capability = V4L2_CAP_TIMEPERFRAME;
@@ -1175,11 +1052,7 @@ tvp514x_s_parm(struct v4l2_subdev *sd, struct v4l2_streamparm *a)
1175 timeperframe = &a->parm.capture.timeperframe; 1052 timeperframe = &a->parm.capture.timeperframe;
1176 1053
1177 /* get the current standard */ 1054 /* get the current standard */
1178 current_std = tvp514x_get_current_std(sd); 1055 current_std = decoder->current_std;
1179 if (current_std == STD_INVALID)
1180 return -EINVAL;
1181
1182 decoder->current_std = current_std;
1183 1056
1184 *timeperframe = 1057 *timeperframe =
1185 decoder->std_list[current_std].standard.frameperiod; 1058 decoder->std_list[current_std].standard.frameperiod;
@@ -1259,9 +1132,9 @@ static const struct v4l2_subdev_video_ops tvp514x_video_ops = {
1259 .s_routing = tvp514x_s_routing, 1132 .s_routing = tvp514x_s_routing,
1260 .querystd = tvp514x_querystd, 1133 .querystd = tvp514x_querystd,
1261 .enum_fmt = tvp514x_enum_fmt_cap, 1134 .enum_fmt = tvp514x_enum_fmt_cap,
1262 .g_fmt = tvp514x_g_fmt_cap, 1135 .g_fmt = tvp514x_fmt_cap,
1263 .try_fmt = tvp514x_try_fmt_cap, 1136 .try_fmt = tvp514x_fmt_cap,
1264 .s_fmt = tvp514x_s_fmt_cap, 1137 .s_fmt = tvp514x_fmt_cap,
1265 .g_parm = tvp514x_g_parm, 1138 .g_parm = tvp514x_g_parm,
1266 .s_parm = tvp514x_s_parm, 1139 .s_parm = tvp514x_s_parm,
1267 .s_stream = tvp514x_s_stream, 1140 .s_stream = tvp514x_s_stream,
@@ -1274,22 +1147,6 @@ static const struct v4l2_subdev_ops tvp514x_ops = {
1274 1147
1275static struct tvp514x_decoder tvp514x_dev = { 1148static struct tvp514x_decoder tvp514x_dev = {
1276 .streaming = 0, 1149 .streaming = 0,
1277
1278 .fmt_list = tvp514x_fmt_list,
1279 .num_fmts = ARRAY_SIZE(tvp514x_fmt_list),
1280
1281 .pix = {
1282 /* Default to NTSC 8-bit YUV 422 */
1283 .width = NTSC_NUM_ACTIVE_PIXELS,
1284 .height = NTSC_NUM_ACTIVE_LINES,
1285 .pixelformat = V4L2_PIX_FMT_UYVY,
1286 .field = V4L2_FIELD_INTERLACED,
1287 .bytesperline = NTSC_NUM_ACTIVE_PIXELS * 2,
1288 .sizeimage =
1289 NTSC_NUM_ACTIVE_PIXELS * 2 * NTSC_NUM_ACTIVE_LINES,
1290 .colorspace = V4L2_COLORSPACE_SMPTE170M,
1291 },
1292
1293 .current_std = STD_NTSC_MJ, 1150 .current_std = STD_NTSC_MJ,
1294 .std_list = tvp514x_std_list, 1151 .std_list = tvp514x_std_list,
1295 .num_stds = ARRAY_SIZE(tvp514x_std_list), 1152 .num_stds = ARRAY_SIZE(tvp514x_std_list),