Commit 899eb84c authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab

[media] go7007: drop struct go7007_file

Remove struct go7007_file: all fields contained in that struct are moved to
the go7007 struct since they are really global values. The lock has just
been deleted (what's the point of a per-fh lock??).
Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent b95dd82c
...@@ -141,14 +141,6 @@ struct go7007_buffer { ...@@ -141,14 +141,6 @@ struct go7007_buffer {
int mapped; int mapped;
}; };
struct go7007_file {
struct v4l2_fh fh;
struct go7007 *go;
struct mutex lock;
int buf_count;
struct go7007_buffer *bufs;
};
#define GO7007_RATIO_1_1 0 #define GO7007_RATIO_1_1 0
#define GO7007_RATIO_4_3 1 #define GO7007_RATIO_4_3 1
#define GO7007_RATIO_16_9 2 #define GO7007_RATIO_16_9 2
...@@ -242,6 +234,9 @@ struct go7007 { ...@@ -242,6 +234,9 @@ struct go7007 {
u32 next_seq; u32 next_seq;
struct list_head stream; struct list_head stream;
wait_queue_head_t frame_waitq; wait_queue_head_t frame_waitq;
int buf_count;
struct go7007_buffer *bufs;
struct v4l2_fh *bufs_owner;
/* Audio streaming */ /* Audio streaming */
void (*audio_deliver)(struct go7007 *go, u8 *buf, int length); void (*audio_deliver)(struct go7007 *go, u8 *buf, int length);
......
...@@ -88,41 +88,19 @@ static int go7007_streamoff(struct go7007 *go) ...@@ -88,41 +88,19 @@ static int go7007_streamoff(struct go7007 *go)
return 0; return 0;
} }
static int go7007_open(struct file *file)
{
struct go7007 *go = video_get_drvdata(video_devdata(file));
struct go7007_file *gofh;
if (go->status != STATUS_ONLINE)
return -EBUSY;
gofh = kzalloc(sizeof(struct go7007_file), GFP_KERNEL);
if (gofh == NULL)
return -ENOMEM;
gofh->go = go;
mutex_init(&gofh->lock);
gofh->buf_count = 0;
file->private_data = gofh;
v4l2_fh_init(&gofh->fh, video_devdata(file));
v4l2_fh_add(&gofh->fh);
return 0;
}
static int go7007_release(struct file *file) static int go7007_release(struct file *file)
{ {
struct go7007_file *gofh = file->private_data; struct go7007 *go = video_drvdata(file);
struct go7007 *go = gofh->go;
if (gofh->buf_count > 0) { if (file->private_data == go->bufs_owner && go->buf_count > 0) {
go7007_streamoff(go); go7007_streamoff(go);
go->in_use = 0; go->in_use = 0;
kfree(gofh->bufs); kfree(go->bufs);
gofh->buf_count = 0; go->bufs = NULL;
go->buf_count = 0;
go->bufs_owner = NULL;
} }
v4l2_fh_del(&gofh->fh); return v4l2_fh_release(file);
v4l2_fh_exit(&gofh->fh);
kfree(gofh);
file->private_data = NULL;
return 0;
} }
static bool valid_pixelformat(u32 pixelformat) static bool valid_pixelformat(u32 pixelformat)
...@@ -428,7 +406,7 @@ static int clip_to_modet_map(struct go7007 *go, int region, ...@@ -428,7 +406,7 @@ static int clip_to_modet_map(struct go7007 *go, int region,
static int vidioc_querycap(struct file *file, void *priv, static int vidioc_querycap(struct file *file, void *priv,
struct v4l2_capability *cap) struct v4l2_capability *cap)
{ {
struct go7007 *go = ((struct go7007_file *) priv)->go; struct go7007 *go = video_drvdata(file);
strlcpy(cap->driver, "go7007", sizeof(cap->driver)); strlcpy(cap->driver, "go7007", sizeof(cap->driver));
strlcpy(cap->card, go->name, sizeof(cap->card)); strlcpy(cap->card, go->name, sizeof(cap->card));
...@@ -480,7 +458,7 @@ static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv, ...@@ -480,7 +458,7 @@ static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
static int vidioc_g_fmt_vid_cap(struct file *file, void *priv, static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
struct v4l2_format *fmt) struct v4l2_format *fmt)
{ {
struct go7007 *go = ((struct go7007_file *) priv)->go; struct go7007 *go = video_drvdata(file);
fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
fmt->fmt.pix.width = go->width; fmt->fmt.pix.width = go->width;
...@@ -497,7 +475,7 @@ static int vidioc_g_fmt_vid_cap(struct file *file, void *priv, ...@@ -497,7 +475,7 @@ static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
struct v4l2_format *fmt) struct v4l2_format *fmt)
{ {
struct go7007 *go = ((struct go7007_file *) priv)->go; struct go7007 *go = video_drvdata(file);
return set_capture_size(go, fmt, 1); return set_capture_size(go, fmt, 1);
} }
...@@ -505,7 +483,7 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, ...@@ -505,7 +483,7 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
struct v4l2_format *fmt) struct v4l2_format *fmt)
{ {
struct go7007 *go = ((struct go7007_file *) priv)->go; struct go7007 *go = video_drvdata(file);
if (go->streaming) if (go->streaming)
return -EBUSY; return -EBUSY;
...@@ -516,8 +494,7 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, ...@@ -516,8 +494,7 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
static int vidioc_reqbufs(struct file *file, void *priv, static int vidioc_reqbufs(struct file *file, void *priv,
struct v4l2_requestbuffers *req) struct v4l2_requestbuffers *req)
{ {
struct go7007_file *gofh = priv; struct go7007 *go = video_drvdata(file);
struct go7007 *go = gofh->go;
int retval = -EBUSY; int retval = -EBUSY;
unsigned int count, i; unsigned int count, i;
...@@ -528,20 +505,19 @@ static int vidioc_reqbufs(struct file *file, void *priv, ...@@ -528,20 +505,19 @@ static int vidioc_reqbufs(struct file *file, void *priv,
req->memory != V4L2_MEMORY_MMAP) req->memory != V4L2_MEMORY_MMAP)
return -EINVAL; return -EINVAL;
mutex_lock(&gofh->lock); for (i = 0; i < go->buf_count; ++i)
for (i = 0; i < gofh->buf_count; ++i) if (go->bufs[i].mapped > 0)
if (gofh->bufs[i].mapped > 0)
goto unlock_and_return; goto unlock_and_return;
set_formatting(go); set_formatting(go);
mutex_lock(&go->hw_lock); mutex_lock(&go->hw_lock);
if (go->in_use > 0 && gofh->buf_count == 0) { if (go->in_use > 0 && go->buf_count == 0) {
mutex_unlock(&go->hw_lock); mutex_unlock(&go->hw_lock);
goto unlock_and_return; goto unlock_and_return;
} }
if (gofh->buf_count > 0) if (go->buf_count > 0)
kfree(gofh->bufs); kfree(go->bufs);
retval = -ENOMEM; retval = -ENOMEM;
count = req->count; count = req->count;
...@@ -551,29 +527,30 @@ static int vidioc_reqbufs(struct file *file, void *priv, ...@@ -551,29 +527,30 @@ static int vidioc_reqbufs(struct file *file, void *priv,
if (count > 32) if (count > 32)
count = 32; count = 32;
gofh->bufs = kcalloc(count, sizeof(struct go7007_buffer), go->bufs = kcalloc(count, sizeof(struct go7007_buffer),
GFP_KERNEL); GFP_KERNEL);
if (!gofh->bufs) { if (!go->bufs) {
mutex_unlock(&go->hw_lock); mutex_unlock(&go->hw_lock);
goto unlock_and_return; goto unlock_and_return;
} }
for (i = 0; i < count; ++i) { for (i = 0; i < count; ++i) {
gofh->bufs[i].go = go; go->bufs[i].go = go;
gofh->bufs[i].index = i; go->bufs[i].index = i;
gofh->bufs[i].state = BUF_STATE_IDLE; go->bufs[i].state = BUF_STATE_IDLE;
gofh->bufs[i].mapped = 0; go->bufs[i].mapped = 0;
} }
go->in_use = 1; go->in_use = 1;
go->bufs_owner = file->private_data;
} else { } else {
go->in_use = 0; go->in_use = 0;
go->bufs_owner = NULL;
} }
gofh->buf_count = count; go->buf_count = count;
mutex_unlock(&go->hw_lock); mutex_unlock(&go->hw_lock);
mutex_unlock(&gofh->lock);
memset(req, 0, sizeof(*req)); memset(req, 0, sizeof(*req));
...@@ -584,14 +561,13 @@ static int vidioc_reqbufs(struct file *file, void *priv, ...@@ -584,14 +561,13 @@ static int vidioc_reqbufs(struct file *file, void *priv,
return 0; return 0;
unlock_and_return: unlock_and_return:
mutex_unlock(&gofh->lock);
return retval; return retval;
} }
static int vidioc_querybuf(struct file *file, void *priv, static int vidioc_querybuf(struct file *file, void *priv,
struct v4l2_buffer *buf) struct v4l2_buffer *buf)
{ {
struct go7007_file *gofh = priv; struct go7007 *go = video_drvdata(file);
int retval = -EINVAL; int retval = -EINVAL;
unsigned int index; unsigned int index;
...@@ -600,15 +576,14 @@ static int vidioc_querybuf(struct file *file, void *priv, ...@@ -600,15 +576,14 @@ static int vidioc_querybuf(struct file *file, void *priv,
index = buf->index; index = buf->index;
mutex_lock(&gofh->lock); if (index >= go->buf_count)
if (index >= gofh->buf_count)
goto unlock_and_return; goto unlock_and_return;
memset(buf, 0, sizeof(*buf)); memset(buf, 0, sizeof(*buf));
buf->index = index; buf->index = index;
buf->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buf->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
switch (gofh->bufs[index].state) { switch (go->bufs[index].state) {
case BUF_STATE_QUEUED: case BUF_STATE_QUEUED:
buf->flags = V4L2_BUF_FLAG_QUEUED; buf->flags = V4L2_BUF_FLAG_QUEUED;
break; break;
...@@ -619,24 +594,21 @@ static int vidioc_querybuf(struct file *file, void *priv, ...@@ -619,24 +594,21 @@ static int vidioc_querybuf(struct file *file, void *priv,
buf->flags = 0; buf->flags = 0;
} }
if (gofh->bufs[index].mapped) if (go->bufs[index].mapped)
buf->flags |= V4L2_BUF_FLAG_MAPPED; buf->flags |= V4L2_BUF_FLAG_MAPPED;
buf->memory = V4L2_MEMORY_MMAP; buf->memory = V4L2_MEMORY_MMAP;
buf->m.offset = index * GO7007_BUF_SIZE; buf->m.offset = index * GO7007_BUF_SIZE;
buf->length = GO7007_BUF_SIZE; buf->length = GO7007_BUF_SIZE;
mutex_unlock(&gofh->lock);
return 0; return 0;
unlock_and_return: unlock_and_return:
mutex_unlock(&gofh->lock);
return retval; return retval;
} }
static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf) static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
{ {
struct go7007_file *gofh = priv; struct go7007 *go = video_drvdata(file);
struct go7007 *go = gofh->go;
struct go7007_buffer *gobuf; struct go7007_buffer *gobuf;
unsigned long flags; unsigned long flags;
int retval = -EINVAL; int retval = -EINVAL;
...@@ -646,11 +618,10 @@ static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf) ...@@ -646,11 +618,10 @@ static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
buf->memory != V4L2_MEMORY_MMAP) buf->memory != V4L2_MEMORY_MMAP)
return retval; return retval;
mutex_lock(&gofh->lock); if (buf->index >= go->buf_count)
if (buf->index >= gofh->buf_count)
goto unlock_and_return; goto unlock_and_return;
gobuf = &gofh->bufs[buf->index]; gobuf = &go->bufs[buf->index];
if (!gobuf->mapped) if (!gobuf->mapped)
goto unlock_and_return; goto unlock_and_return;
...@@ -687,20 +658,17 @@ static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf) ...@@ -687,20 +658,17 @@ static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
spin_lock_irqsave(&go->spinlock, flags); spin_lock_irqsave(&go->spinlock, flags);
list_add_tail(&gobuf->stream, &go->stream); list_add_tail(&gobuf->stream, &go->stream);
spin_unlock_irqrestore(&go->spinlock, flags); spin_unlock_irqrestore(&go->spinlock, flags);
mutex_unlock(&gofh->lock);
return 0; return 0;
unlock_and_return: unlock_and_return:
mutex_unlock(&gofh->lock);
return retval; return retval;
} }
static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf) static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
{ {
struct go7007_file *gofh = priv; struct go7007 *go = video_drvdata(file);
struct go7007 *go = gofh->go;
struct go7007_buffer *gobuf; struct go7007_buffer *gobuf;
int retval = -EINVAL; int retval = -EINVAL;
unsigned long flags; unsigned long flags;
...@@ -712,7 +680,6 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf) ...@@ -712,7 +680,6 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
if (buf->memory != V4L2_MEMORY_MMAP) if (buf->memory != V4L2_MEMORY_MMAP)
return retval; return retval;
mutex_lock(&gofh->lock);
if (list_empty(&go->stream)) if (list_empty(&go->stream))
goto unlock_and_return; goto unlock_and_return;
gobuf = list_entry(go->stream.next, gobuf = list_entry(go->stream.next,
...@@ -756,25 +723,21 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf) ...@@ -756,25 +723,21 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
buf->length = GO7007_BUF_SIZE; buf->length = GO7007_BUF_SIZE;
buf->reserved = gobuf->modet_active; buf->reserved = gobuf->modet_active;
mutex_unlock(&gofh->lock);
return 0; return 0;
unlock_and_return: unlock_and_return:
mutex_unlock(&gofh->lock);
return retval; return retval;
} }
static int vidioc_streamon(struct file *file, void *priv, static int vidioc_streamon(struct file *file, void *priv,
enum v4l2_buf_type type) enum v4l2_buf_type type)
{ {
struct go7007_file *gofh = priv; struct go7007 *go = video_drvdata(file);
struct go7007 *go = gofh->go;
int retval = 0; int retval = 0;
if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE) if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
return -EINVAL; return -EINVAL;
mutex_lock(&gofh->lock);
mutex_lock(&go->hw_lock); mutex_lock(&go->hw_lock);
if (!go->streaming) { if (!go->streaming) {
...@@ -787,7 +750,6 @@ static int vidioc_streamon(struct file *file, void *priv, ...@@ -787,7 +750,6 @@ static int vidioc_streamon(struct file *file, void *priv,
retval = 0; retval = 0;
} }
mutex_unlock(&go->hw_lock); mutex_unlock(&go->hw_lock);
mutex_unlock(&gofh->lock);
call_all(&go->v4l2_dev, video, s_stream, 1); call_all(&go->v4l2_dev, video, s_stream, 1);
v4l2_ctrl_grab(go->mpeg_video_gop_size, true); v4l2_ctrl_grab(go->mpeg_video_gop_size, true);
v4l2_ctrl_grab(go->mpeg_video_gop_closure, true); v4l2_ctrl_grab(go->mpeg_video_gop_closure, true);
...@@ -800,14 +762,11 @@ static int vidioc_streamon(struct file *file, void *priv, ...@@ -800,14 +762,11 @@ static int vidioc_streamon(struct file *file, void *priv,
static int vidioc_streamoff(struct file *file, void *priv, static int vidioc_streamoff(struct file *file, void *priv,
enum v4l2_buf_type type) enum v4l2_buf_type type)
{ {
struct go7007_file *gofh = priv; struct go7007 *go = video_drvdata(file);
struct go7007 *go = gofh->go;
if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE) if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
return -EINVAL; return -EINVAL;
mutex_lock(&gofh->lock);
go7007_streamoff(go); go7007_streamoff(go);
mutex_unlock(&gofh->lock);
call_all(&go->v4l2_dev, video, s_stream, 0); call_all(&go->v4l2_dev, video, s_stream, 0);
return 0; return 0;
...@@ -816,7 +775,7 @@ static int vidioc_streamoff(struct file *file, void *priv, ...@@ -816,7 +775,7 @@ static int vidioc_streamoff(struct file *file, void *priv,
static int vidioc_g_parm(struct file *filp, void *priv, static int vidioc_g_parm(struct file *filp, void *priv,
struct v4l2_streamparm *parm) struct v4l2_streamparm *parm)
{ {
struct go7007 *go = ((struct go7007_file *) priv)->go; struct go7007 *go = video_drvdata(filp);
struct v4l2_fract timeperframe = { struct v4l2_fract timeperframe = {
.numerator = 1001 * go->fps_scale, .numerator = 1001 * go->fps_scale,
.denominator = go->sensor_framerate, .denominator = go->sensor_framerate,
...@@ -835,7 +794,7 @@ static int vidioc_g_parm(struct file *filp, void *priv, ...@@ -835,7 +794,7 @@ static int vidioc_g_parm(struct file *filp, void *priv,
static int vidioc_s_parm(struct file *filp, void *priv, static int vidioc_s_parm(struct file *filp, void *priv,
struct v4l2_streamparm *parm) struct v4l2_streamparm *parm)
{ {
struct go7007 *go = ((struct go7007_file *) priv)->go; struct go7007 *go = video_drvdata(filp);
unsigned int n, d; unsigned int n, d;
if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
...@@ -865,7 +824,7 @@ static int vidioc_s_parm(struct file *filp, void *priv, ...@@ -865,7 +824,7 @@ static int vidioc_s_parm(struct file *filp, void *priv,
static int vidioc_enum_framesizes(struct file *filp, void *priv, static int vidioc_enum_framesizes(struct file *filp, void *priv,
struct v4l2_frmsizeenum *fsize) struct v4l2_frmsizeenum *fsize)
{ {
struct go7007 *go = ((struct go7007_file *) priv)->go; struct go7007 *go = video_drvdata(filp);
int width, height; int width, height;
if (fsize->index > 2) if (fsize->index > 2)
...@@ -884,7 +843,7 @@ static int vidioc_enum_framesizes(struct file *filp, void *priv, ...@@ -884,7 +843,7 @@ static int vidioc_enum_framesizes(struct file *filp, void *priv,
static int vidioc_enum_frameintervals(struct file *filp, void *priv, static int vidioc_enum_frameintervals(struct file *filp, void *priv,
struct v4l2_frmivalenum *fival) struct v4l2_frmivalenum *fival)
{ {
struct go7007 *go = ((struct go7007_file *) priv)->go; struct go7007 *go = video_drvdata(filp);
int width, height; int width, height;
int i; int i;
...@@ -911,7 +870,7 @@ static int vidioc_enum_frameintervals(struct file *filp, void *priv, ...@@ -911,7 +870,7 @@ static int vidioc_enum_frameintervals(struct file *filp, void *priv,
static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *std) static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *std)
{ {
struct go7007 *go = ((struct go7007_file *) priv)->go; struct go7007 *go = video_drvdata(file);
*std = go->std; *std = go->std;
return 0; return 0;
...@@ -946,7 +905,7 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id std) ...@@ -946,7 +905,7 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id std)
static int vidioc_querystd(struct file *file, void *priv, v4l2_std_id *std) static int vidioc_querystd(struct file *file, void *priv, v4l2_std_id *std)
{ {
struct go7007 *go = ((struct go7007_file *) priv)->go; struct go7007 *go = video_drvdata(file);
return call_all(&go->v4l2_dev, video, querystd, std); return call_all(&go->v4l2_dev, video, querystd, std);
} }
...@@ -954,7 +913,7 @@ static int vidioc_querystd(struct file *file, void *priv, v4l2_std_id *std) ...@@ -954,7 +913,7 @@ static int vidioc_querystd(struct file *file, void *priv, v4l2_std_id *std)
static int vidioc_enum_input(struct file *file, void *priv, static int vidioc_enum_input(struct file *file, void *priv,
struct v4l2_input *inp) struct v4l2_input *inp)
{ {
struct go7007 *go = ((struct go7007_file *) priv)->go; struct go7007 *go = video_drvdata(file);
if (inp->index >= go->board_info->num_inputs) if (inp->index >= go->board_info->num_inputs)
return -EINVAL; return -EINVAL;
...@@ -985,7 +944,7 @@ static int vidioc_enum_input(struct file *file, void *priv, ...@@ -985,7 +944,7 @@ static int vidioc_enum_input(struct file *file, void *priv,
static int vidioc_g_input(struct file *file, void *priv, unsigned int *input) static int vidioc_g_input(struct file *file, void *priv, unsigned int *input)
{ {
struct go7007 *go = ((struct go7007_file *) priv)->go; struct go7007 *go = video_drvdata(file);
*input = go->input; *input = go->input;
...@@ -1059,7 +1018,7 @@ static int vidioc_s_input(struct file *file, void *priv, unsigned int input) ...@@ -1059,7 +1018,7 @@ static int vidioc_s_input(struct file *file, void *priv, unsigned int input)
static int vidioc_g_tuner(struct file *file, void *priv, static int vidioc_g_tuner(struct file *file, void *priv,
struct v4l2_tuner *t) struct v4l2_tuner *t)
{ {
struct go7007 *go = ((struct go7007_file *) priv)->go; struct go7007 *go = video_drvdata(file);
if (t->index != 0) if (t->index != 0)
return -EINVAL; return -EINVAL;
...@@ -1071,7 +1030,7 @@ static int vidioc_g_tuner(struct file *file, void *priv, ...@@ -1071,7 +1030,7 @@ static int vidioc_g_tuner(struct file *file, void *priv,
static int vidioc_s_tuner(struct file *file, void *priv, static int vidioc_s_tuner(struct file *file, void *priv,
const struct v4l2_tuner *t) const struct v4l2_tuner *t)
{ {
struct go7007 *go = ((struct go7007_file *) priv)->go; struct go7007 *go = video_drvdata(file);
if (t->index != 0) if (t->index != 0)
return -EINVAL; return -EINVAL;
...@@ -1082,7 +1041,7 @@ static int vidioc_s_tuner(struct file *file, void *priv, ...@@ -1082,7 +1041,7 @@ static int vidioc_s_tuner(struct file *file, void *priv,
static int vidioc_g_frequency(struct file *file, void *priv, static int vidioc_g_frequency(struct file *file, void *priv,
struct v4l2_frequency *f) struct v4l2_frequency *f)
{ {
struct go7007 *go = ((struct go7007_file *) priv)->go; struct go7007 *go = video_drvdata(file);
if (f->tuner) if (f->tuner)
return -EINVAL; return -EINVAL;
...@@ -1093,7 +1052,7 @@ static int vidioc_g_frequency(struct file *file, void *priv, ...@@ -1093,7 +1052,7 @@ static int vidioc_g_frequency(struct file *file, void *priv,
static int vidioc_s_frequency(struct file *file, void *priv, static int vidioc_s_frequency(struct file *file, void *priv,
const struct v4l2_frequency *f) const struct v4l2_frequency *f)
{ {
struct go7007 *go = ((struct go7007_file *) priv)->go; struct go7007 *go = video_drvdata(file);
if (f->tuner) if (f->tuner)
return -EINVAL; return -EINVAL;
...@@ -1103,7 +1062,7 @@ static int vidioc_s_frequency(struct file *file, void *priv, ...@@ -1103,7 +1062,7 @@ static int vidioc_s_frequency(struct file *file, void *priv,
static int vidioc_log_status(struct file *file, void *priv) static int vidioc_log_status(struct file *file, void *priv)
{ {
struct go7007 *go = ((struct go7007_file *) priv)->go; struct go7007 *go = video_drvdata(file);
v4l2_ctrl_log_status(file, priv); v4l2_ctrl_log_status(file, priv);
return call_all(&go->v4l2_dev, core, log_status); return call_all(&go->v4l2_dev, core, log_status);
...@@ -1112,7 +1071,7 @@ static int vidioc_log_status(struct file *file, void *priv) ...@@ -1112,7 +1071,7 @@ static int vidioc_log_status(struct file *file, void *priv)
static int vidioc_cropcap(struct file *file, void *priv, static int vidioc_cropcap(struct file *file, void *priv,
struct v4l2_cropcap *cropcap) struct v4l2_cropcap *cropcap)
{ {
struct go7007 *go = ((struct go7007_file *) priv)->go; struct go7007 *go = video_drvdata(file);
if (cropcap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) if (cropcap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
return -EINVAL; return -EINVAL;
...@@ -1156,7 +1115,7 @@ static int vidioc_cropcap(struct file *file, void *priv, ...@@ -1156,7 +1115,7 @@ static int vidioc_cropcap(struct file *file, void *priv,
static int vidioc_g_crop(struct file *file, void *priv, struct v4l2_crop *crop) static int vidioc_g_crop(struct file *file, void *priv, struct v4l2_crop *crop)
{ {
struct go7007 *go = ((struct go7007_file *) priv)->go; struct go7007 *go = video_drvdata(file);
if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
return -EINVAL; return -EINVAL;
...@@ -1280,52 +1239,44 @@ static struct vm_operations_struct go7007_vm_ops = { ...@@ -1280,52 +1239,44 @@ static struct vm_operations_struct go7007_vm_ops = {
static int go7007_mmap(struct file *file, struct vm_area_struct *vma) static int go7007_mmap(struct file *file, struct vm_area_struct *vma)
{ {
struct go7007_file *gofh = file->private_data; struct go7007 *go = video_drvdata(file);
unsigned int index; unsigned int index;
if (gofh->go->status != STATUS_ONLINE) if (go->status != STATUS_ONLINE)
return -EIO; return -EIO;
if (!(vma->vm_flags & VM_SHARED)) if (!(vma->vm_flags & VM_SHARED))
return -EINVAL; /* only support VM_SHARED mapping */ return -EINVAL; /* only support VM_SHARED mapping */
if (vma->vm_end - vma->vm_start != GO7007_BUF_SIZE) if (vma->vm_end - vma->vm_start != GO7007_BUF_SIZE)
return -EINVAL; /* must map exactly one full buffer */ return -EINVAL; /* must map exactly one full buffer */
mutex_lock(&gofh->lock);
index = vma->vm_pgoff / GO7007_BUF_PAGES; index = vma->vm_pgoff / GO7007_BUF_PAGES;
if (index >= gofh->buf_count) { if (index >= go->buf_count)
mutex_unlock(&gofh->lock);
return -EINVAL; /* trying to map beyond requested buffers */ return -EINVAL; /* trying to map beyond requested buffers */
} if (index * GO7007_BUF_PAGES != vma->vm_pgoff)
if (index * GO7007_BUF_PAGES != vma->vm_pgoff) {
mutex_unlock(&gofh->lock);
return -EINVAL; /* offset is not aligned on buffer boundary */ return -EINVAL; /* offset is not aligned on buffer boundary */
} if (go->bufs[index].mapped > 0)
if (gofh->bufs[index].mapped > 0) {
mutex_unlock(&gofh->lock);
return -EBUSY; return -EBUSY;
} go->bufs[index].mapped = 1;
gofh->bufs[index].mapped = 1; go->bufs[index].user_addr = vma->vm_start;
gofh->bufs[index].user_addr = vma->vm_start;
vma->vm_ops = &go7007_vm_ops; vma->vm_ops = &go7007_vm_ops;
vma->vm_flags |= VM_DONTEXPAND; vma->vm_flags |= VM_DONTEXPAND;
vma->vm_flags &= ~VM_IO; vma->vm_flags &= ~VM_IO;
vma->vm_private_data = &gofh->bufs[index]; vma->vm_private_data = &go->bufs[index];
mutex_unlock(&gofh->lock);
return 0; return 0;
} }
static unsigned int go7007_poll(struct file *file, poll_table *wait) static unsigned int go7007_poll(struct file *file, poll_table *wait)
{ {
unsigned long req_events = poll_requested_events(wait); unsigned long req_events = poll_requested_events(wait);
struct go7007_file *gofh = file->private_data; struct go7007 *go = video_drvdata(file);
struct go7007_buffer *gobuf; struct go7007_buffer *gobuf;
unsigned int res = v4l2_ctrl_poll(file, wait); unsigned int res = v4l2_ctrl_poll(file, wait);
if (!(req_events & (POLLIN | POLLRDNORM))) if (!(req_events & (POLLIN | POLLRDNORM)))
return res; return res;
if (list_empty(&gofh->go->stream)) if (list_empty(&go->stream))
return POLLERR; return POLLERR;
gobuf = list_entry(gofh->go->stream.next, struct go7007_buffer, stream); gobuf = list_entry(go->stream.next, struct go7007_buffer, stream);
poll_wait(file, &gofh->go->frame_waitq, wait); poll_wait(file, &go->frame_waitq, wait);
if (gobuf->state == BUF_STATE_DONE) if (gobuf->state == BUF_STATE_DONE)
return res | POLLIN | POLLRDNORM; return res | POLLIN | POLLRDNORM;
return res; return res;
...@@ -1338,7 +1289,7 @@ static void go7007_vfl_release(struct video_device *vfd) ...@@ -1338,7 +1289,7 @@ static void go7007_vfl_release(struct video_device *vfd)
static struct v4l2_file_operations go7007_fops = { static struct v4l2_file_operations go7007_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.open = go7007_open, .open = v4l2_fh_open,
.release = go7007_release, .release = go7007_release,
.ioctl = video_ioctl2, .ioctl = video_ioctl2,
.read = go7007_read, .read = go7007_read,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment