Commit 4b25524c authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab

[media] pms: update to the latest V4L2 frameworks

Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 5be4fe63
...@@ -30,15 +30,19 @@ ...@@ -30,15 +30,19 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
#include <linux/isa.h>
#include <asm/io.h> #include <asm/io.h>
#include <linux/videodev2.h> #include <linux/videodev2.h>
#include <media/v4l2-common.h> #include <media/v4l2-common.h>
#include <media/v4l2-ioctl.h> #include <media/v4l2-ioctl.h>
#include <media/v4l2-ctrls.h>
#include <media/v4l2-fh.h>
#include <media/v4l2-event.h>
#include <media/v4l2-device.h> #include <media/v4l2-device.h>
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
MODULE_VERSION("0.0.4"); MODULE_VERSION("0.0.5");
#define MOTOROLA 1 #define MOTOROLA 1
#define PHILIPS2 2 /* SAA7191 */ #define PHILIPS2 2 /* SAA7191 */
...@@ -55,11 +59,11 @@ struct i2c_info { ...@@ -55,11 +59,11 @@ struct i2c_info {
struct pms { struct pms {
struct v4l2_device v4l2_dev; struct v4l2_device v4l2_dev;
struct video_device vdev; struct video_device vdev;
struct v4l2_ctrl_handler hdl;
int height; int height;
int width; int width;
int depth; int depth;
int input; int input;
s32 brightness, saturation, hue, contrast;
struct mutex lock; struct mutex lock;
int i2c_count; int i2c_count;
struct i2c_info i2cinfo[64]; struct i2c_info i2cinfo[64];
...@@ -72,8 +76,6 @@ struct pms { ...@@ -72,8 +76,6 @@ struct pms {
void __iomem *mem; void __iomem *mem;
}; };
static struct pms pms_card;
/* /*
* I/O ports and Shared Memory * I/O ports and Shared Memory
*/ */
...@@ -676,8 +678,10 @@ static int pms_querycap(struct file *file, void *priv, ...@@ -676,8 +678,10 @@ static int pms_querycap(struct file *file, void *priv,
strlcpy(vcap->driver, dev->v4l2_dev.name, sizeof(vcap->driver)); strlcpy(vcap->driver, dev->v4l2_dev.name, sizeof(vcap->driver));
strlcpy(vcap->card, "Mediavision PMS", sizeof(vcap->card)); strlcpy(vcap->card, "Mediavision PMS", sizeof(vcap->card));
strlcpy(vcap->bus_info, "ISA", sizeof(vcap->bus_info)); snprintf(vcap->bus_info, sizeof(vcap->bus_info),
vcap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE; "ISA:%s", dev->v4l2_dev.name);
vcap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE;
vcap->capabilities = vcap->device_caps | V4L2_CAP_DEVICE_CAPS;
return 0; return 0;
} }
...@@ -716,11 +720,9 @@ static int pms_s_input(struct file *file, void *fh, unsigned int inp) ...@@ -716,11 +720,9 @@ static int pms_s_input(struct file *file, void *fh, unsigned int inp)
if (inp > 3) if (inp > 3)
return -EINVAL; return -EINVAL;
mutex_lock(&dev->lock);
dev->input = inp; dev->input = inp;
pms_videosource(dev, inp & 1); pms_videosource(dev, inp & 1);
pms_vcrinput(dev, inp >> 1); pms_vcrinput(dev, inp >> 1);
mutex_unlock(&dev->lock);
return 0; return 0;
} }
...@@ -738,7 +740,6 @@ static int pms_s_std(struct file *file, void *fh, v4l2_std_id *std) ...@@ -738,7 +740,6 @@ static int pms_s_std(struct file *file, void *fh, v4l2_std_id *std)
int ret = 0; int ret = 0;
dev->std = *std; dev->std = *std;
mutex_lock(&dev->lock);
if (dev->std & V4L2_STD_NTSC) { if (dev->std & V4L2_STD_NTSC) {
pms_framerate(dev, 30); pms_framerate(dev, 30);
pms_secamcross(dev, 0); pms_secamcross(dev, 0);
...@@ -762,81 +763,31 @@ static int pms_s_std(struct file *file, void *fh, v4l2_std_id *std) ...@@ -762,81 +763,31 @@ static int pms_s_std(struct file *file, void *fh, v4l2_std_id *std)
pms_format(dev, 0); pms_format(dev, 0);
break; break;
}*/ }*/
mutex_unlock(&dev->lock);
return 0;
}
static int pms_queryctrl(struct file *file, void *priv,
struct v4l2_queryctrl *qc)
{
switch (qc->id) {
case V4L2_CID_BRIGHTNESS:
return v4l2_ctrl_query_fill(qc, 0, 255, 1, 139);
case V4L2_CID_CONTRAST:
return v4l2_ctrl_query_fill(qc, 0, 255, 1, 70);
case V4L2_CID_SATURATION:
return v4l2_ctrl_query_fill(qc, 0, 255, 1, 64);
case V4L2_CID_HUE:
return v4l2_ctrl_query_fill(qc, 0, 255, 1, 0);
}
return -EINVAL;
}
static int pms_g_ctrl(struct file *file, void *priv,
struct v4l2_control *ctrl)
{
struct pms *dev = video_drvdata(file);
int ret = 0;
switch (ctrl->id) {
case V4L2_CID_BRIGHTNESS:
ctrl->value = dev->brightness;
break;
case V4L2_CID_CONTRAST:
ctrl->value = dev->contrast;
break;
case V4L2_CID_SATURATION:
ctrl->value = dev->saturation;
break;
case V4L2_CID_HUE:
ctrl->value = dev->hue;
break;
default:
ret = -EINVAL;
break;
}
return ret; return ret;
} }
static int pms_s_ctrl(struct file *file, void *priv, static int pms_s_ctrl(struct v4l2_ctrl *ctrl)
struct v4l2_control *ctrl)
{ {
struct pms *dev = video_drvdata(file); struct pms *dev = container_of(ctrl->handler, struct pms, hdl);
int ret = 0; int ret = 0;
mutex_lock(&dev->lock);
switch (ctrl->id) { switch (ctrl->id) {
case V4L2_CID_BRIGHTNESS: case V4L2_CID_BRIGHTNESS:
dev->brightness = ctrl->value; pms_brightness(dev, ctrl->val);
pms_brightness(dev, dev->brightness);
break; break;
case V4L2_CID_CONTRAST: case V4L2_CID_CONTRAST:
dev->contrast = ctrl->value; pms_contrast(dev, ctrl->val);
pms_contrast(dev, dev->contrast);
break; break;
case V4L2_CID_SATURATION: case V4L2_CID_SATURATION:
dev->saturation = ctrl->value; pms_saturation(dev, ctrl->val);
pms_saturation(dev, dev->saturation);
break; break;
case V4L2_CID_HUE: case V4L2_CID_HUE:
dev->hue = ctrl->value; pms_hue(dev, ctrl->val);
pms_hue(dev, dev->hue);
break; break;
default: default:
ret = -EINVAL; ret = -EINVAL;
break; break;
} }
mutex_unlock(&dev->lock);
return ret; return ret;
} }
...@@ -884,13 +835,11 @@ static int pms_s_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *fm ...@@ -884,13 +835,11 @@ static int pms_s_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *fm
if (ret) if (ret)
return ret; return ret;
mutex_lock(&dev->lock);
dev->width = pix->width; dev->width = pix->width;
dev->height = pix->height; dev->height = pix->height;
dev->depth = (pix->pixelformat == V4L2_PIX_FMT_RGB555) ? 15 : 16; dev->depth = (pix->pixelformat == V4L2_PIX_FMT_RGB555) ? 15 : 16;
pms_resolution(dev, dev->width, dev->height); pms_resolution(dev, dev->width, dev->height);
/* Ok we figured out what to use from our wide choice */ /* Ok we figured out what to use from our wide choice */
mutex_unlock(&dev->lock);
return 0; return 0;
} }
...@@ -901,7 +850,7 @@ static int pms_enum_fmt_vid_cap(struct file *file, void *fh, struct v4l2_fmtdesc ...@@ -901,7 +850,7 @@ static int pms_enum_fmt_vid_cap(struct file *file, void *fh, struct v4l2_fmtdesc
"RGB 5:5:5", V4L2_PIX_FMT_RGB555, "RGB 5:5:5", V4L2_PIX_FMT_RGB555,
{ 0, 0, 0, 0 } { 0, 0, 0, 0 }
}, },
{ 0, 0, 0, { 1, 0, 0,
"RGB 5:6:5", V4L2_PIX_FMT_RGB565, "RGB 5:6:5", V4L2_PIX_FMT_RGB565,
{ 0, 0, 0, 0 } { 0, 0, 0, 0 }
}, },
...@@ -922,14 +871,26 @@ static ssize_t pms_read(struct file *file, char __user *buf, ...@@ -922,14 +871,26 @@ static ssize_t pms_read(struct file *file, char __user *buf,
struct pms *dev = video_drvdata(file); struct pms *dev = video_drvdata(file);
int len; int len;
mutex_lock(&dev->lock);
len = pms_capture(dev, buf, (dev->depth == 15), count); len = pms_capture(dev, buf, (dev->depth == 15), count);
mutex_unlock(&dev->lock);
return len; return len;
} }
static unsigned int pms_poll(struct file *file, struct poll_table_struct *wait)
{
struct v4l2_fh *fh = file->private_data;
unsigned int res = POLLIN | POLLRDNORM;
if (v4l2_event_pending(fh))
res |= POLLPRI;
poll_wait(file, &fh->wait, wait);
return res;
}
static const struct v4l2_file_operations pms_fops = { static const struct v4l2_file_operations pms_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.open = v4l2_fh_open,
.release = v4l2_fh_release,
.poll = pms_poll,
.unlocked_ioctl = video_ioctl2, .unlocked_ioctl = video_ioctl2,
.read = pms_read, .read = pms_read,
}; };
...@@ -941,13 +902,12 @@ static const struct v4l2_ioctl_ops pms_ioctl_ops = { ...@@ -941,13 +902,12 @@ static const struct v4l2_ioctl_ops pms_ioctl_ops = {
.vidioc_enum_input = pms_enum_input, .vidioc_enum_input = pms_enum_input,
.vidioc_g_std = pms_g_std, .vidioc_g_std = pms_g_std,
.vidioc_s_std = pms_s_std, .vidioc_s_std = pms_s_std,
.vidioc_queryctrl = pms_queryctrl,
.vidioc_g_ctrl = pms_g_ctrl,
.vidioc_s_ctrl = pms_s_ctrl,
.vidioc_enum_fmt_vid_cap = pms_enum_fmt_vid_cap, .vidioc_enum_fmt_vid_cap = pms_enum_fmt_vid_cap,
.vidioc_g_fmt_vid_cap = pms_g_fmt_vid_cap, .vidioc_g_fmt_vid_cap = pms_g_fmt_vid_cap,
.vidioc_s_fmt_vid_cap = pms_s_fmt_vid_cap, .vidioc_s_fmt_vid_cap = pms_s_fmt_vid_cap,
.vidioc_try_fmt_vid_cap = pms_try_fmt_vid_cap, .vidioc_try_fmt_vid_cap = pms_try_fmt_vid_cap,
.vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
.vidioc_unsubscribe_event = v4l2_event_unsubscribe,
}; };
/* /*
...@@ -1068,76 +1028,125 @@ static int enable; ...@@ -1068,76 +1028,125 @@ static int enable;
module_param(enable, int, 0); module_param(enable, int, 0);
#endif #endif
static int __init pms_init(void) static const struct v4l2_ctrl_ops pms_ctrl_ops = {
.s_ctrl = pms_s_ctrl,
};
static int pms_probe(struct device *pdev, unsigned int card)
{ {
struct pms *dev = &pms_card; struct pms *dev;
struct v4l2_device *v4l2_dev = &dev->v4l2_dev; struct v4l2_device *v4l2_dev;
struct v4l2_ctrl_handler *hdl;
int res; int res;
strlcpy(v4l2_dev->name, "pms", sizeof(v4l2_dev->name));
v4l2_info(v4l2_dev, "Mediavision Pro Movie Studio driver 0.03\n");
#ifndef MODULE #ifndef MODULE
if (!enable) { if (!enable) {
v4l2_err(v4l2_dev, pr_err("PMS: not enabled, use pms.enable=1 to probe\n");
"PMS: not enabled, use pms.enable=1 to probe\n");
return -ENODEV; return -ENODEV;
} }
#endif #endif
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
if (dev == NULL)
return -ENOMEM;
dev->decoder = PHILIPS2; dev->decoder = PHILIPS2;
dev->io = io_port; dev->io = io_port;
dev->data = io_port + 1; dev->data = io_port + 1;
v4l2_dev = &dev->v4l2_dev;
hdl = &dev->hdl;
res = v4l2_device_register(pdev, v4l2_dev);
if (res < 0) {
v4l2_err(v4l2_dev, "Could not register v4l2_device\n");
goto free_dev;
}
v4l2_info(v4l2_dev, "Mediavision Pro Movie Studio driver 0.05\n");
if (init_mediavision(dev)) { res = init_mediavision(dev);
if (res) {
v4l2_err(v4l2_dev, "Board not found.\n"); v4l2_err(v4l2_dev, "Board not found.\n");
return -ENODEV; goto free_io;
} }
res = v4l2_device_register(NULL, v4l2_dev); v4l2_ctrl_handler_init(hdl, 4);
if (res < 0) { v4l2_ctrl_new_std(hdl, &pms_ctrl_ops,
v4l2_err(v4l2_dev, "Could not register v4l2_device\n"); V4L2_CID_BRIGHTNESS, 0, 255, 1, 139);
return res; v4l2_ctrl_new_std(hdl, &pms_ctrl_ops,
V4L2_CID_CONTRAST, 0, 255, 1, 70);
v4l2_ctrl_new_std(hdl, &pms_ctrl_ops,
V4L2_CID_SATURATION, 0, 255, 1, 64);
v4l2_ctrl_new_std(hdl, &pms_ctrl_ops,
V4L2_CID_HUE, 0, 255, 1, 0);
if (hdl->error) {
res = hdl->error;
goto free_hdl;
} }
mutex_init(&dev->lock);
strlcpy(dev->vdev.name, v4l2_dev->name, sizeof(dev->vdev.name)); strlcpy(dev->vdev.name, v4l2_dev->name, sizeof(dev->vdev.name));
dev->vdev.v4l2_dev = v4l2_dev; dev->vdev.v4l2_dev = v4l2_dev;
dev->vdev.ctrl_handler = hdl;
dev->vdev.fops = &pms_fops; dev->vdev.fops = &pms_fops;
dev->vdev.ioctl_ops = &pms_ioctl_ops; dev->vdev.ioctl_ops = &pms_ioctl_ops;
dev->vdev.release = video_device_release_empty; dev->vdev.release = video_device_release_empty;
dev->vdev.lock = &dev->lock;
dev->vdev.tvnorms = V4L2_STD_NTSC | V4L2_STD_PAL | V4L2_STD_SECAM;
set_bit(V4L2_FL_USE_FH_PRIO, &dev->vdev.flags);
video_set_drvdata(&dev->vdev, dev); video_set_drvdata(&dev->vdev, dev);
mutex_init(&dev->lock);
dev->std = V4L2_STD_NTSC_M; dev->std = V4L2_STD_NTSC_M;
dev->height = 240; dev->height = 240;
dev->width = 320; dev->width = 320;
dev->depth = 15; dev->depth = 16;
dev->brightness = 139;
dev->contrast = 70;
dev->hue = 0;
dev->saturation = 64;
pms_swsense(dev, 75); pms_swsense(dev, 75);
pms_resolution(dev, 320, 240); pms_resolution(dev, 320, 240);
pms_videosource(dev, 0); pms_videosource(dev, 0);
pms_vcrinput(dev, 0); pms_vcrinput(dev, 0);
if (video_register_device(&dev->vdev, VFL_TYPE_GRABBER, video_nr) < 0) { v4l2_ctrl_handler_setup(hdl);
res = video_register_device(&dev->vdev, VFL_TYPE_GRABBER, video_nr);
if (res >= 0)
return 0;
free_hdl:
v4l2_ctrl_handler_free(hdl);
v4l2_device_unregister(&dev->v4l2_dev); v4l2_device_unregister(&dev->v4l2_dev);
free_io:
release_region(dev->io, 3); release_region(dev->io, 3);
release_region(0x9a01, 1); release_region(0x9a01, 1);
iounmap(dev->mem); iounmap(dev->mem);
return -EINVAL; free_dev:
} kfree(dev);
return 0; return res;
} }
static void __exit pms_exit(void) static int pms_remove(struct device *pdev, unsigned int card)
{ {
struct pms *dev = &pms_card; struct pms *dev = dev_get_drvdata(pdev);
video_unregister_device(&dev->vdev); video_unregister_device(&dev->vdev);
v4l2_ctrl_handler_free(&dev->hdl);
release_region(dev->io, 3); release_region(dev->io, 3);
release_region(0x9a01, 1); release_region(0x9a01, 1);
iounmap(dev->mem); iounmap(dev->mem);
return 0;
}
static struct isa_driver pms_driver = {
.probe = pms_probe,
.remove = pms_remove,
.driver = {
.name = "pms",
},
};
static int __init pms_init(void)
{
return isa_register_driver(&pms_driver, 1);
}
static void __exit pms_exit(void)
{
isa_unregister_driver(&pms_driver);
} }
module_init(pms_init); module_init(pms_init);
......
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