aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/platform/davinci
diff options
context:
space:
mode:
authorPrabhakar Lad <prabhakar.csengg@gmail.com>2014-10-12 16:40:37 -0400
committerMauro Carvalho Chehab <mchehab@osg.samsung.com>2014-10-28 14:09:08 -0400
commit4bb1231a5f3262eec8d879386b88b4d48082fd46 (patch)
tree8f6898ac689973ad9c41f3086f62aa798c9ff324 /drivers/media/platform/davinci
parent266c9c2d33ec8382470affe1eef90cd757dfefdd (diff)
[media] media: davinci: vpbe: use fh handling provided by v4l
this patch converts the driver to use fh handling provided by the v4l core instead of driver doing it. Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Diffstat (limited to 'drivers/media/platform/davinci')
-rw-r--r--drivers/media/platform/davinci/vpbe_display.c189
1 files changed, 65 insertions, 124 deletions
diff --git a/drivers/media/platform/davinci/vpbe_display.c b/drivers/media/platform/davinci/vpbe_display.c
index fc3bdb6afafe..970242caad4d 100644
--- a/drivers/media/platform/davinci/vpbe_display.c
+++ b/drivers/media/platform/davinci/vpbe_display.c
@@ -628,8 +628,8 @@ static int vpbe_try_format(struct vpbe_display *disp_dev,
628static int vpbe_display_querycap(struct file *file, void *priv, 628static int vpbe_display_querycap(struct file *file, void *priv,
629 struct v4l2_capability *cap) 629 struct v4l2_capability *cap)
630{ 630{
631 struct vpbe_fh *fh = file->private_data; 631 struct vpbe_layer *layer = video_drvdata(file);
632 struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev; 632 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
633 633
634 cap->version = VPBE_DISPLAY_VERSION_CODE; 634 cap->version = VPBE_DISPLAY_VERSION_CODE;
635 cap->device_caps = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING; 635 cap->device_caps = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING;
@@ -646,9 +646,8 @@ static int vpbe_display_querycap(struct file *file, void *priv,
646static int vpbe_display_s_crop(struct file *file, void *priv, 646static int vpbe_display_s_crop(struct file *file, void *priv,
647 const struct v4l2_crop *crop) 647 const struct v4l2_crop *crop)
648{ 648{
649 struct vpbe_fh *fh = file->private_data; 649 struct vpbe_layer *layer = video_drvdata(file);
650 struct vpbe_layer *layer = fh->layer; 650 struct vpbe_display *disp_dev = layer->disp_dev;
651 struct vpbe_display *disp_dev = fh->disp_dev;
652 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev; 651 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
653 struct osd_layer_config *cfg = &layer->layer_info.config; 652 struct osd_layer_config *cfg = &layer->layer_info.config;
654 struct osd_state *osd_device = disp_dev->osd_device; 653 struct osd_state *osd_device = disp_dev->osd_device;
@@ -715,11 +714,10 @@ static int vpbe_display_s_crop(struct file *file, void *priv,
715static int vpbe_display_g_crop(struct file *file, void *priv, 714static int vpbe_display_g_crop(struct file *file, void *priv,
716 struct v4l2_crop *crop) 715 struct v4l2_crop *crop)
717{ 716{
718 struct vpbe_fh *fh = file->private_data; 717 struct vpbe_layer *layer = video_drvdata(file);
719 struct vpbe_layer *layer = fh->layer;
720 struct osd_layer_config *cfg = &layer->layer_info.config; 718 struct osd_layer_config *cfg = &layer->layer_info.config;
721 struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev; 719 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
722 struct osd_state *osd_device = fh->disp_dev->osd_device; 720 struct osd_state *osd_device = layer->disp_dev->osd_device;
723 struct v4l2_rect *rect = &crop->c; 721 struct v4l2_rect *rect = &crop->c;
724 722
725 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, 723 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
@@ -743,8 +741,8 @@ static int vpbe_display_g_crop(struct file *file, void *priv,
743static int vpbe_display_cropcap(struct file *file, void *priv, 741static int vpbe_display_cropcap(struct file *file, void *priv,
744 struct v4l2_cropcap *cropcap) 742 struct v4l2_cropcap *cropcap)
745{ 743{
746 struct vpbe_fh *fh = file->private_data; 744 struct vpbe_layer *layer = video_drvdata(file);
747 struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev; 745 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
748 746
749 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_CROPCAP ioctl\n"); 747 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_CROPCAP ioctl\n");
750 748
@@ -761,9 +759,8 @@ static int vpbe_display_cropcap(struct file *file, void *priv,
761static int vpbe_display_g_fmt(struct file *file, void *priv, 759static int vpbe_display_g_fmt(struct file *file, void *priv,
762 struct v4l2_format *fmt) 760 struct v4l2_format *fmt)
763{ 761{
764 struct vpbe_fh *fh = file->private_data; 762 struct vpbe_layer *layer = video_drvdata(file);
765 struct vpbe_layer *layer = fh->layer; 763 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
766 struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
767 764
768 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, 765 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
769 "VIDIOC_G_FMT, layer id = %d\n", 766 "VIDIOC_G_FMT, layer id = %d\n",
@@ -783,9 +780,8 @@ static int vpbe_display_g_fmt(struct file *file, void *priv,
783static int vpbe_display_enum_fmt(struct file *file, void *priv, 780static int vpbe_display_enum_fmt(struct file *file, void *priv,
784 struct v4l2_fmtdesc *fmt) 781 struct v4l2_fmtdesc *fmt)
785{ 782{
786 struct vpbe_fh *fh = file->private_data; 783 struct vpbe_layer *layer = video_drvdata(file);
787 struct vpbe_layer *layer = fh->layer; 784 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
788 struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
789 unsigned int index = 0; 785 unsigned int index = 0;
790 786
791 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, 787 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
@@ -815,9 +811,8 @@ static int vpbe_display_enum_fmt(struct file *file, void *priv,
815static int vpbe_display_s_fmt(struct file *file, void *priv, 811static int vpbe_display_s_fmt(struct file *file, void *priv,
816 struct v4l2_format *fmt) 812 struct v4l2_format *fmt)
817{ 813{
818 struct vpbe_fh *fh = file->private_data; 814 struct vpbe_layer *layer = video_drvdata(file);
819 struct vpbe_layer *layer = fh->layer; 815 struct vpbe_display *disp_dev = layer->disp_dev;
820 struct vpbe_display *disp_dev = fh->disp_dev;
821 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev; 816 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
822 struct osd_layer_config *cfg = &layer->layer_info.config; 817 struct osd_layer_config *cfg = &layer->layer_info.config;
823 struct v4l2_pix_format *pixfmt = &fmt->fmt.pix; 818 struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
@@ -904,9 +899,9 @@ static int vpbe_display_s_fmt(struct file *file, void *priv,
904static int vpbe_display_try_fmt(struct file *file, void *priv, 899static int vpbe_display_try_fmt(struct file *file, void *priv,
905 struct v4l2_format *fmt) 900 struct v4l2_format *fmt)
906{ 901{
907 struct vpbe_fh *fh = file->private_data; 902 struct vpbe_layer *layer = video_drvdata(file);
908 struct vpbe_display *disp_dev = fh->disp_dev; 903 struct vpbe_display *disp_dev = layer->disp_dev;
909 struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev; 904 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
910 struct v4l2_pix_format *pixfmt = &fmt->fmt.pix; 905 struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
911 906
912 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_TRY_FMT\n"); 907 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_TRY_FMT\n");
@@ -930,9 +925,8 @@ static int vpbe_display_try_fmt(struct file *file, void *priv,
930static int vpbe_display_s_std(struct file *file, void *priv, 925static int vpbe_display_s_std(struct file *file, void *priv,
931 v4l2_std_id std_id) 926 v4l2_std_id std_id)
932{ 927{
933 struct vpbe_fh *fh = priv; 928 struct vpbe_layer *layer = video_drvdata(file);
934 struct vpbe_layer *layer = fh->layer; 929 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
935 struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
936 int ret; 930 int ret;
937 931
938 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_S_STD\n"); 932 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_S_STD\n");
@@ -965,8 +959,8 @@ static int vpbe_display_s_std(struct file *file, void *priv,
965static int vpbe_display_g_std(struct file *file, void *priv, 959static int vpbe_display_g_std(struct file *file, void *priv,
966 v4l2_std_id *std_id) 960 v4l2_std_id *std_id)
967{ 961{
968 struct vpbe_fh *fh = priv; 962 struct vpbe_layer *layer = video_drvdata(file);
969 struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev; 963 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
970 964
971 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_G_STD\n"); 965 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_G_STD\n");
972 966
@@ -988,8 +982,8 @@ static int vpbe_display_g_std(struct file *file, void *priv,
988static int vpbe_display_enum_output(struct file *file, void *priv, 982static int vpbe_display_enum_output(struct file *file, void *priv,
989 struct v4l2_output *output) 983 struct v4l2_output *output)
990{ 984{
991 struct vpbe_fh *fh = priv; 985 struct vpbe_layer *layer = video_drvdata(file);
992 struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev; 986 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
993 int ret; 987 int ret;
994 988
995 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_ENUM_OUTPUT\n"); 989 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_ENUM_OUTPUT\n");
@@ -1016,9 +1010,8 @@ static int vpbe_display_enum_output(struct file *file, void *priv,
1016static int vpbe_display_s_output(struct file *file, void *priv, 1010static int vpbe_display_s_output(struct file *file, void *priv,
1017 unsigned int i) 1011 unsigned int i)
1018{ 1012{
1019 struct vpbe_fh *fh = priv; 1013 struct vpbe_layer *layer = video_drvdata(file);
1020 struct vpbe_layer *layer = fh->layer; 1014 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
1021 struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
1022 int ret; 1015 int ret;
1023 1016
1024 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_S_OUTPUT\n"); 1017 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_S_OUTPUT\n");
@@ -1047,8 +1040,8 @@ static int vpbe_display_s_output(struct file *file, void *priv,
1047static int vpbe_display_g_output(struct file *file, void *priv, 1040static int vpbe_display_g_output(struct file *file, void *priv,
1048 unsigned int *i) 1041 unsigned int *i)
1049{ 1042{
1050 struct vpbe_fh *fh = priv; 1043 struct vpbe_layer *layer = video_drvdata(file);
1051 struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev; 1044 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
1052 1045
1053 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_G_OUTPUT\n"); 1046 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_G_OUTPUT\n");
1054 /* Get the standard from the current encoder */ 1047 /* Get the standard from the current encoder */
@@ -1067,8 +1060,8 @@ static int
1067vpbe_display_enum_dv_timings(struct file *file, void *priv, 1060vpbe_display_enum_dv_timings(struct file *file, void *priv,
1068 struct v4l2_enum_dv_timings *timings) 1061 struct v4l2_enum_dv_timings *timings)
1069{ 1062{
1070 struct vpbe_fh *fh = priv; 1063 struct vpbe_layer *layer = video_drvdata(file);
1071 struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev; 1064 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
1072 int ret; 1065 int ret;
1073 1066
1074 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_ENUM_DV_TIMINGS\n"); 1067 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_ENUM_DV_TIMINGS\n");
@@ -1097,9 +1090,8 @@ static int
1097vpbe_display_s_dv_timings(struct file *file, void *priv, 1090vpbe_display_s_dv_timings(struct file *file, void *priv,
1098 struct v4l2_dv_timings *timings) 1091 struct v4l2_dv_timings *timings)
1099{ 1092{
1100 struct vpbe_fh *fh = priv; 1093 struct vpbe_layer *layer = video_drvdata(file);
1101 struct vpbe_layer *layer = fh->layer; 1094 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
1102 struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
1103 int ret; 1095 int ret;
1104 1096
1105 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_S_DV_TIMINGS\n"); 1097 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_S_DV_TIMINGS\n");
@@ -1135,8 +1127,8 @@ static int
1135vpbe_display_g_dv_timings(struct file *file, void *priv, 1127vpbe_display_g_dv_timings(struct file *file, void *priv,
1136 struct v4l2_dv_timings *dv_timings) 1128 struct v4l2_dv_timings *dv_timings)
1137{ 1129{
1138 struct vpbe_fh *fh = priv; 1130 struct vpbe_layer *layer = video_drvdata(file);
1139 struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev; 1131 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
1140 1132
1141 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_G_DV_TIMINGS\n"); 1133 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_G_DV_TIMINGS\n");
1142 1134
@@ -1155,10 +1147,9 @@ vpbe_display_g_dv_timings(struct file *file, void *priv,
1155static int vpbe_display_streamoff(struct file *file, void *priv, 1147static int vpbe_display_streamoff(struct file *file, void *priv,
1156 enum v4l2_buf_type buf_type) 1148 enum v4l2_buf_type buf_type)
1157{ 1149{
1158 struct vpbe_fh *fh = file->private_data; 1150 struct vpbe_layer *layer = video_drvdata(file);
1159 struct vpbe_layer *layer = fh->layer; 1151 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
1160 struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev; 1152 struct osd_state *osd_device = layer->disp_dev->osd_device;
1161 struct osd_state *osd_device = fh->disp_dev->osd_device;
1162 int ret; 1153 int ret;
1163 1154
1164 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, 1155 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
@@ -1170,12 +1161,6 @@ static int vpbe_display_streamoff(struct file *file, void *priv,
1170 return -EINVAL; 1161 return -EINVAL;
1171 } 1162 }
1172 1163
1173 /* If io is allowed for this file handle, return error */
1174 if (!fh->io_allowed) {
1175 v4l2_err(&vpbe_dev->v4l2_dev, "No io_allowed\n");
1176 return -EACCES;
1177 }
1178
1179 /* If streaming is not started, return error */ 1164 /* If streaming is not started, return error */
1180 if (!layer->started) { 1165 if (!layer->started) {
1181 v4l2_err(&vpbe_dev->v4l2_dev, "streaming not started in layer" 1166 v4l2_err(&vpbe_dev->v4l2_dev, "streaming not started in layer"
@@ -1194,10 +1179,9 @@ static int vpbe_display_streamoff(struct file *file, void *priv,
1194static int vpbe_display_streamon(struct file *file, void *priv, 1179static int vpbe_display_streamon(struct file *file, void *priv,
1195 enum v4l2_buf_type buf_type) 1180 enum v4l2_buf_type buf_type)
1196{ 1181{
1197 struct vpbe_fh *fh = file->private_data; 1182 struct vpbe_layer *layer = video_drvdata(file);
1198 struct vpbe_layer *layer = fh->layer; 1183 struct vpbe_display *disp_dev = layer->disp_dev;
1199 struct vpbe_display *disp_dev = fh->disp_dev; 1184 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
1200 struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
1201 struct osd_state *osd_device = disp_dev->osd_device; 1185 struct osd_state *osd_device = disp_dev->osd_device;
1202 int ret; 1186 int ret;
1203 1187
@@ -1212,11 +1196,6 @@ static int vpbe_display_streamon(struct file *file, void *priv,
1212 return -EINVAL; 1196 return -EINVAL;
1213 } 1197 }
1214 1198
1215 /* If file handle is not allowed IO, return error */
1216 if (!fh->io_allowed) {
1217 v4l2_err(&vpbe_dev->v4l2_dev, "No io_allowed\n");
1218 return -EACCES;
1219 }
1220 /* If Streaming is already started, return error */ 1199 /* If Streaming is already started, return error */
1221 if (layer->started) { 1200 if (layer->started) {
1222 v4l2_err(&vpbe_dev->v4l2_dev, "layer is already streaming\n"); 1201 v4l2_err(&vpbe_dev->v4l2_dev, "layer is already streaming\n");
@@ -1239,9 +1218,8 @@ static int vpbe_display_streamon(struct file *file, void *priv,
1239static int vpbe_display_dqbuf(struct file *file, void *priv, 1218static int vpbe_display_dqbuf(struct file *file, void *priv,
1240 struct v4l2_buffer *buf) 1219 struct v4l2_buffer *buf)
1241{ 1220{
1242 struct vpbe_fh *fh = file->private_data; 1221 struct vpbe_layer *layer = video_drvdata(file);
1243 struct vpbe_layer *layer = fh->layer; 1222 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
1244 struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
1245 int ret; 1223 int ret;
1246 1224
1247 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, 1225 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
@@ -1252,11 +1230,6 @@ static int vpbe_display_dqbuf(struct file *file, void *priv,
1252 v4l2_err(&vpbe_dev->v4l2_dev, "Invalid buffer type\n"); 1230 v4l2_err(&vpbe_dev->v4l2_dev, "Invalid buffer type\n");
1253 return -EINVAL; 1231 return -EINVAL;
1254 } 1232 }
1255 /* If this file handle is not allowed to do IO, return error */
1256 if (!fh->io_allowed) {
1257 v4l2_err(&vpbe_dev->v4l2_dev, "No io_allowed\n");
1258 return -EACCES;
1259 }
1260 if (file->f_flags & O_NONBLOCK) 1233 if (file->f_flags & O_NONBLOCK)
1261 /* Call videobuf_dqbuf for non blocking mode */ 1234 /* Call videobuf_dqbuf for non blocking mode */
1262 ret = vb2_dqbuf(&layer->buffer_queue, buf, 1); 1235 ret = vb2_dqbuf(&layer->buffer_queue, buf, 1);
@@ -1270,9 +1243,8 @@ static int vpbe_display_dqbuf(struct file *file, void *priv,
1270static int vpbe_display_qbuf(struct file *file, void *priv, 1243static int vpbe_display_qbuf(struct file *file, void *priv,
1271 struct v4l2_buffer *p) 1244 struct v4l2_buffer *p)
1272{ 1245{
1273 struct vpbe_fh *fh = file->private_data; 1246 struct vpbe_layer *layer = video_drvdata(file);
1274 struct vpbe_layer *layer = fh->layer; 1247 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
1275 struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
1276 1248
1277 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, 1249 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
1278 "VIDIOC_QBUF, layer id = %d\n", 1250 "VIDIOC_QBUF, layer id = %d\n",
@@ -1283,21 +1255,14 @@ static int vpbe_display_qbuf(struct file *file, void *priv,
1283 return -EINVAL; 1255 return -EINVAL;
1284 } 1256 }
1285 1257
1286 /* If this file handle is not allowed to do IO, return error */
1287 if (!fh->io_allowed) {
1288 v4l2_err(&vpbe_dev->v4l2_dev, "No io_allowed\n");
1289 return -EACCES;
1290 }
1291
1292 return vb2_qbuf(&layer->buffer_queue, p); 1258 return vb2_qbuf(&layer->buffer_queue, p);
1293} 1259}
1294 1260
1295static int vpbe_display_querybuf(struct file *file, void *priv, 1261static int vpbe_display_querybuf(struct file *file, void *priv,
1296 struct v4l2_buffer *buf) 1262 struct v4l2_buffer *buf)
1297{ 1263{
1298 struct vpbe_fh *fh = file->private_data; 1264 struct vpbe_layer *layer = video_drvdata(file);
1299 struct vpbe_layer *layer = fh->layer; 1265 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
1300 struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
1301 1266
1302 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, 1267 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
1303 "VIDIOC_QUERYBUF, layer id = %d\n", 1268 "VIDIOC_QUERYBUF, layer id = %d\n",
@@ -1314,9 +1279,8 @@ static int vpbe_display_querybuf(struct file *file, void *priv,
1314static int vpbe_display_reqbufs(struct file *file, void *priv, 1279static int vpbe_display_reqbufs(struct file *file, void *priv,
1315 struct v4l2_requestbuffers *req_buf) 1280 struct v4l2_requestbuffers *req_buf)
1316{ 1281{
1317 struct vpbe_fh *fh = file->private_data; 1282 struct vpbe_layer *layer = video_drvdata(file);
1318 struct vpbe_layer *layer = fh->layer; 1283 struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
1319 struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
1320 1284
1321 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "vpbe_display_reqbufs\n"); 1285 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "vpbe_display_reqbufs\n");
1322 1286
@@ -1330,8 +1294,6 @@ static int vpbe_display_reqbufs(struct file *file, void *priv,
1330 v4l2_err(&vpbe_dev->v4l2_dev, "not IO user\n"); 1294 v4l2_err(&vpbe_dev->v4l2_dev, "not IO user\n");
1331 return -EBUSY; 1295 return -EBUSY;
1332 } 1296 }
1333 /* Set io allowed member of file handle to TRUE */
1334 fh->io_allowed = 1;
1335 /* Increment io usrs member of layer object to 1 */ 1297 /* Increment io usrs member of layer object to 1 */
1336 layer->io_usrs = 1; 1298 layer->io_usrs = 1;
1337 /* Store type of memory requested in layer object */ 1299 /* Store type of memory requested in layer object */
@@ -1347,30 +1309,22 @@ static int vpbe_display_reqbufs(struct file *file, void *priv,
1347 */ 1309 */
1348static int vpbe_display_open(struct file *file) 1310static int vpbe_display_open(struct file *file)
1349{ 1311{
1350 struct vpbe_fh *fh = NULL;
1351 struct vpbe_layer *layer = video_drvdata(file); 1312 struct vpbe_layer *layer = video_drvdata(file);
1352 struct video_device *vdev = video_devdata(file);
1353 struct vpbe_display *disp_dev = layer->disp_dev; 1313 struct vpbe_display *disp_dev = layer->disp_dev;
1354 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev; 1314 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
1355 struct osd_state *osd_device = disp_dev->osd_device; 1315 struct osd_state *osd_device = disp_dev->osd_device;
1356 int err; 1316 int err;
1357 1317
1358 /* Allocate memory for the file handle object */ 1318 /* creating context for file descriptor */
1359 fh = kmalloc(sizeof(struct vpbe_fh), GFP_KERNEL); 1319 err = v4l2_fh_open(file);
1360 if (fh == NULL) { 1320 if (err) {
1361 v4l2_err(&vpbe_dev->v4l2_dev, 1321 v4l2_err(&vpbe_dev->v4l2_dev, "v4l2_fh_open failed\n");
1362 "unable to allocate memory for file handle object\n"); 1322 return err;
1363 return -ENOMEM;
1364 } 1323 }
1365 v4l2_fh_init(&fh->fh, vdev);
1366 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
1367 "vpbe display open plane = %d\n",
1368 layer->device_id);
1369 1324
1370 /* store pointer to fh in private_data member of filep */ 1325 /* leaving if layer is already initialized */
1371 file->private_data = fh; 1326 if (!v4l2_fh_is_singular_file(file))
1372 fh->layer = layer; 1327 return err;
1373 fh->disp_dev = disp_dev;
1374 1328
1375 if (!layer->usrs) { 1329 if (!layer->usrs) {
1376 if (mutex_lock_interruptible(&layer->opslock)) 1330 if (mutex_lock_interruptible(&layer->opslock))
@@ -1383,15 +1337,12 @@ static int vpbe_display_open(struct file *file)
1383 /* Couldn't get layer */ 1337 /* Couldn't get layer */
1384 v4l2_err(&vpbe_dev->v4l2_dev, 1338 v4l2_err(&vpbe_dev->v4l2_dev,
1385 "Display Manager failed to allocate layer\n"); 1339 "Display Manager failed to allocate layer\n");
1386 kfree(fh); 1340 v4l2_fh_release(file);
1387 return -EINVAL; 1341 return -EINVAL;
1388 } 1342 }
1389 } 1343 }
1390 /* Increment layer usrs counter */ 1344 /* Increment layer usrs counter */
1391 layer->usrs++; 1345 layer->usrs++;
1392 /* Set io_allowed member to false */
1393 fh->io_allowed = 0;
1394 v4l2_fh_add(&fh->fh);
1395 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, 1346 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
1396 "vpbe display device opened successfully\n"); 1347 "vpbe display device opened successfully\n");
1397 return 0; 1348 return 0;
@@ -1404,26 +1355,21 @@ static int vpbe_display_open(struct file *file)
1404 */ 1355 */
1405static int vpbe_display_release(struct file *file) 1356static int vpbe_display_release(struct file *file)
1406{ 1357{
1407 /* Get the layer object and file handle object */ 1358 struct vpbe_layer *layer = video_drvdata(file);
1408 struct vpbe_fh *fh = file->private_data;
1409 struct vpbe_layer *layer = fh->layer;
1410 struct osd_layer_config *cfg = &layer->layer_info.config; 1359 struct osd_layer_config *cfg = &layer->layer_info.config;
1411 struct vpbe_display *disp_dev = fh->disp_dev; 1360 struct vpbe_display *disp_dev = layer->disp_dev;
1412 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev; 1361 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
1413 struct osd_state *osd_device = disp_dev->osd_device; 1362 struct osd_state *osd_device = disp_dev->osd_device;
1414 1363
1415 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "vpbe_display_release\n"); 1364 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "vpbe_display_release\n");
1416 1365
1417 mutex_lock(&layer->opslock); 1366 mutex_lock(&layer->opslock);
1418 /* if this instance is doing IO */ 1367 /* Reset io_usrs member of layer object */
1419 if (fh->io_allowed) { 1368 layer->io_usrs = 0;
1420 /* Reset io_usrs member of layer object */
1421 layer->io_usrs = 0;
1422 1369
1423 osd_device->ops.disable_layer(osd_device, 1370 osd_device->ops.disable_layer(osd_device,
1424 layer->layer_info.id); 1371 layer->layer_info.id);
1425 layer->started = 0; 1372 layer->started = 0;
1426 }
1427 1373
1428 /* Decrement layer usrs counter */ 1374 /* Decrement layer usrs counter */
1429 layer->usrs--; 1375 layer->usrs--;
@@ -1444,14 +1390,9 @@ static int vpbe_display_release(struct file *file)
1444 layer->layer_info.id); 1390 layer->layer_info.id);
1445 } 1391 }
1446 1392
1447 v4l2_fh_del(&fh->fh); 1393 _vb2_fop_release(file, NULL);
1448 v4l2_fh_exit(&fh->fh);
1449 file->private_data = NULL;
1450 mutex_unlock(&layer->opslock); 1394 mutex_unlock(&layer->opslock);
1451 1395
1452 /* Free memory allocated to file handle object */
1453 kfree(fh);
1454
1455 disp_dev->cbcr_ofst = 0; 1396 disp_dev->cbcr_ofst = 0;
1456 1397
1457 return 0; 1398 return 0;