From 0bf0f713d6e6b9f1c510d598c29ac17812a4eea5 Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Wed, 13 Jul 2011 04:28:27 -0300 Subject: [media] vivi: let vb2_poll handle events The vb2_poll function now tests for events and sets POLLPRI accordingly. So there it is no longer necessary to test for it in the vivi driver. Signed-off-by: Hans Verkuil Signed-off-by: Hans de Goede Signed-off-by: Mauro Carvalho Chehab --- drivers/media/video/vivi.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'drivers/media/video/vivi.c') diff --git a/drivers/media/video/vivi.c b/drivers/media/video/vivi.c index 5e8b0710105b..b456d3ed1197 100644 --- a/drivers/media/video/vivi.c +++ b/drivers/media/video/vivi.c @@ -1039,17 +1039,10 @@ static unsigned int vivi_poll(struct file *file, struct poll_table_struct *wait) { struct vivi_dev *dev = video_drvdata(file); - struct v4l2_fh *fh = file->private_data; struct vb2_queue *q = &dev->vb_vidq; - unsigned int res; dprintk(dev, 1, "%s\n", __func__); - res = vb2_poll(q, file, wait); - if (v4l2_event_pending(fh)) - res |= POLLPRI; - else - poll_wait(file, &fh->wait, wait); - return res; + return vb2_poll(q, file, wait); } static int vivi_close(struct file *file) -- cgit v1.2.3 From c520331a52094182d6682fa7d6f630bdfbfc2974 Mon Sep 17 00:00:00 2001 From: Sakari Ailus Date: Fri, 5 Aug 2011 06:38:05 -0300 Subject: [media] vivi: Add an integer menu test control Add an integer menu test control for the vivi driver. Signed-off-by: Sakari Ailus Acked-by: Laurent Pinchart Signed-off-by: Mauro Carvalho Chehab --- drivers/media/video/vivi.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'drivers/media/video/vivi.c') diff --git a/drivers/media/video/vivi.c b/drivers/media/video/vivi.c index b456d3ed1197..ff39eb2f2d7b 100644 --- a/drivers/media/video/vivi.c +++ b/drivers/media/video/vivi.c @@ -177,6 +177,7 @@ struct vivi_dev { struct v4l2_ctrl *menu; struct v4l2_ctrl *string; struct v4l2_ctrl *bitmask; + struct v4l2_ctrl *int_menu; spinlock_t slock; struct mutex mutex; @@ -503,6 +504,10 @@ static void vivi_fillbuff(struct vivi_dev *dev, struct vivi_buffer *buf) dev->boolean->cur.val, dev->menu->qmenu[dev->menu->cur.val], dev->string->cur.string); + snprintf(str, sizeof(str), " integer_menu %lld, value %d ", + dev->int_menu->qmenu_int[dev->int_menu->cur.val], + dev->int_menu->cur.val); + gen_text(dev, vbuf, line++ * 16, 16, str); mutex_unlock(&dev->ctrl_handler.lock); gen_text(dev, vbuf, line++ * 16, 16, str); if (dev->button_pressed) { @@ -1158,6 +1163,22 @@ static const struct v4l2_ctrl_config vivi_ctrl_bitmask = { .step = 0, }; +static const s64 vivi_ctrl_int_menu_values[] = { + 1, 1, 2, 3, 5, 8, 13, 21, 42, +}; + +static const struct v4l2_ctrl_config vivi_ctrl_int_menu = { + .ops = &vivi_ctrl_ops, + .id = VIVI_CID_CUSTOM_BASE + 7, + .name = "Integer menu", + .type = V4L2_CTRL_TYPE_INTEGER_MENU, + .min = 1, + .max = 8, + .def = 4, + .menu_skip_mask = 0x02, + .qmenu_int = vivi_ctrl_int_menu_values, +}; + static const struct v4l2_file_operations vivi_fops = { .owner = THIS_MODULE, .open = v4l2_fh_open, @@ -1268,6 +1289,7 @@ static int __init vivi_create_instance(int inst) dev->menu = v4l2_ctrl_new_custom(hdl, &vivi_ctrl_menu, NULL); dev->string = v4l2_ctrl_new_custom(hdl, &vivi_ctrl_string, NULL); dev->bitmask = v4l2_ctrl_new_custom(hdl, &vivi_ctrl_bitmask, NULL); + dev->int_menu = v4l2_ctrl_new_custom(hdl, &vivi_ctrl_int_menu, NULL); if (hdl->error) { ret = hdl->error; goto unreg_dev; -- cgit v1.2.3 From f70cfc7f182bf4605449cad4d665febf012c6f6b Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Thu, 19 Apr 2012 11:44:18 -0300 Subject: [media] vivi: fix duplicate line This was inadvertently introduced when the integer menu control was added. Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab --- drivers/media/video/vivi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/media/video/vivi.c') diff --git a/drivers/media/video/vivi.c b/drivers/media/video/vivi.c index ff39eb2f2d7b..d64d482f4f6b 100644 --- a/drivers/media/video/vivi.c +++ b/drivers/media/video/vivi.c @@ -504,12 +504,12 @@ static void vivi_fillbuff(struct vivi_dev *dev, struct vivi_buffer *buf) dev->boolean->cur.val, dev->menu->qmenu[dev->menu->cur.val], dev->string->cur.string); + gen_text(dev, vbuf, line++ * 16, 16, str); snprintf(str, sizeof(str), " integer_menu %lld, value %d ", dev->int_menu->qmenu_int[dev->int_menu->cur.val], dev->int_menu->cur.val); gen_text(dev, vbuf, line++ * 16, 16, str); mutex_unlock(&dev->ctrl_handler.lock); - gen_text(dev, vbuf, line++ * 16, 16, str); if (dev->button_pressed) { dev->button_pressed--; snprintf(str, sizeof(str), " button pressed!"); -- cgit v1.2.3 From 77e7c4e624404c6edb5686b3d5f873c6008ed6b0 Mon Sep 17 00:00:00 2001 From: Sakari Ailus Date: Tue, 24 Jan 2012 21:05:34 -0300 Subject: [media] v4l: Allow changing control handler lock Allow choosing the lock used by the control handler. This may be handy sometimes when a driver providing multiple subdevs does not want to use several locks to serialise its functions. Signed-off-by: Sakari Ailus Signed-off-by: Mauro Carvalho Chehab --- drivers/media/video/adp1653.c | 8 ++++---- drivers/media/video/v4l2-ctrls.c | 39 ++++++++++++++++++++------------------- drivers/media/video/vivi.c | 4 ++-- include/media/v4l2-ctrls.h | 9 ++++++--- 4 files changed, 32 insertions(+), 28 deletions(-) (limited to 'drivers/media/video/vivi.c') diff --git a/drivers/media/video/adp1653.c b/drivers/media/video/adp1653.c index 24afc99d26e4..57e87090388d 100644 --- a/drivers/media/video/adp1653.c +++ b/drivers/media/video/adp1653.c @@ -281,19 +281,19 @@ adp1653_init_device(struct adp1653_flash *flash) return -EIO; } - mutex_lock(&flash->ctrls.lock); + mutex_lock(flash->ctrls.lock); /* Reset faults before reading new ones. */ flash->fault = 0; rval = adp1653_get_fault(flash); - mutex_unlock(&flash->ctrls.lock); + mutex_unlock(flash->ctrls.lock); if (rval > 0) { dev_err(&client->dev, "faults detected: 0x%1.1x\n", rval); return -EIO; } - mutex_lock(&flash->ctrls.lock); + mutex_lock(flash->ctrls.lock); rval = adp1653_update_hw(flash); - mutex_unlock(&flash->ctrls.lock); + mutex_unlock(flash->ctrls.lock); if (rval) { dev_err(&client->dev, "adp1653_update_hw failed at %s\n", __func__); diff --git a/drivers/media/video/v4l2-ctrls.c b/drivers/media/video/v4l2-ctrls.c index edb2a6a066ca..e5531ace5ee7 100644 --- a/drivers/media/video/v4l2-ctrls.c +++ b/drivers/media/video/v4l2-ctrls.c @@ -1177,7 +1177,8 @@ static inline int handler_set_err(struct v4l2_ctrl_handler *hdl, int err) int v4l2_ctrl_handler_init(struct v4l2_ctrl_handler *hdl, unsigned nr_of_controls_hint) { - mutex_init(&hdl->lock); + hdl->lock = &hdl->_lock; + mutex_init(hdl->lock); INIT_LIST_HEAD(&hdl->ctrls); INIT_LIST_HEAD(&hdl->ctrl_refs); hdl->nr_of_buckets = 1 + nr_of_controls_hint / 8; @@ -1198,7 +1199,7 @@ void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl) if (hdl == NULL || hdl->buckets == NULL) return; - mutex_lock(&hdl->lock); + mutex_lock(hdl->lock); /* Free all nodes */ list_for_each_entry_safe(ref, next_ref, &hdl->ctrl_refs, node) { list_del(&ref->node); @@ -1215,7 +1216,7 @@ void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl) hdl->buckets = NULL; hdl->cached = NULL; hdl->error = 0; - mutex_unlock(&hdl->lock); + mutex_unlock(hdl->lock); } EXPORT_SYMBOL(v4l2_ctrl_handler_free); @@ -1280,9 +1281,9 @@ static struct v4l2_ctrl_ref *find_ref_lock( struct v4l2_ctrl_ref *ref = NULL; if (hdl) { - mutex_lock(&hdl->lock); + mutex_lock(hdl->lock); ref = find_ref(hdl, id); - mutex_unlock(&hdl->lock); + mutex_unlock(hdl->lock); } return ref; } @@ -1329,7 +1330,7 @@ static int handler_new_ref(struct v4l2_ctrl_handler *hdl, INIT_LIST_HEAD(&new_ref->node); - mutex_lock(&hdl->lock); + mutex_lock(hdl->lock); /* Add immediately at the end of the list if the list is empty, or if the last element in the list has a lower ID. @@ -1359,7 +1360,7 @@ insert_in_hash: hdl->buckets[bucket] = new_ref; unlock: - mutex_unlock(&hdl->lock); + mutex_unlock(hdl->lock); return 0; } @@ -1445,9 +1446,9 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl, kfree(ctrl); return NULL; } - mutex_lock(&hdl->lock); + mutex_lock(hdl->lock); list_add_tail(&ctrl->node, &hdl->ctrls); - mutex_unlock(&hdl->lock); + mutex_unlock(hdl->lock); return ctrl; } @@ -1564,7 +1565,7 @@ int v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl, return 0; if (hdl->error) return hdl->error; - mutex_lock(&add->lock); + mutex_lock(add->lock); list_for_each_entry(ref, &add->ctrl_refs, node) { struct v4l2_ctrl *ctrl = ref->ctrl; @@ -1578,7 +1579,7 @@ int v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl, if (ret) break; } - mutex_unlock(&add->lock); + mutex_unlock(add->lock); return ret; } EXPORT_SYMBOL(v4l2_ctrl_add_handler); @@ -1742,11 +1743,11 @@ void v4l2_ctrl_handler_log_status(struct v4l2_ctrl_handler *hdl, len = strlen(prefix); if (len && prefix[len - 1] != ' ') colon = ": "; - mutex_lock(&hdl->lock); + mutex_lock(hdl->lock); list_for_each_entry(ctrl, &hdl->ctrls, node) if (!(ctrl->flags & V4L2_CTRL_FLAG_DISABLED)) log_ctrl(ctrl, prefix, colon); - mutex_unlock(&hdl->lock); + mutex_unlock(hdl->lock); } EXPORT_SYMBOL(v4l2_ctrl_handler_log_status); @@ -1758,7 +1759,7 @@ int v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl) if (hdl == NULL) return 0; - mutex_lock(&hdl->lock); + mutex_lock(hdl->lock); list_for_each_entry(ctrl, &hdl->ctrls, node) ctrl->done = false; @@ -1783,7 +1784,7 @@ int v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl) if (ret) break; } - mutex_unlock(&hdl->lock); + mutex_unlock(hdl->lock); return ret; } EXPORT_SYMBOL(v4l2_ctrl_handler_setup); @@ -1798,7 +1799,7 @@ int v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc) if (hdl == NULL) return -EINVAL; - mutex_lock(&hdl->lock); + mutex_lock(hdl->lock); /* Try to find it */ ref = find_ref(hdl, id); @@ -1823,7 +1824,7 @@ int v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc) break; } } - mutex_unlock(&hdl->lock); + mutex_unlock(hdl->lock); if (!ref) return -EINVAL; @@ -2000,7 +2001,7 @@ static int prepare_ext_ctrls(struct v4l2_ctrl_handler *hdl, belong to the same cluster. */ /* This has to be done with the handler lock taken. */ - mutex_lock(&hdl->lock); + mutex_lock(hdl->lock); /* First zero the helper field in the master control references */ for (i = 0; i < cs->count; i++) @@ -2022,7 +2023,7 @@ static int prepare_ext_ctrls(struct v4l2_ctrl_handler *hdl, /* Point the mref helper to the current helper struct. */ mref->helper = h; } - mutex_unlock(&hdl->lock); + mutex_unlock(hdl->lock); return 0; } diff --git a/drivers/media/video/vivi.c b/drivers/media/video/vivi.c index d64d482f4f6b..6f2e354a242d 100644 --- a/drivers/media/video/vivi.c +++ b/drivers/media/video/vivi.c @@ -485,7 +485,7 @@ static void vivi_fillbuff(struct vivi_dev *dev, struct vivi_buffer *buf) gen_text(dev, vbuf, line++ * 16, 16, str); gain = v4l2_ctrl_g_ctrl(dev->gain); - mutex_lock(&dev->ctrl_handler.lock); + mutex_lock(dev->ctrl_handler.lock); snprintf(str, sizeof(str), " brightness %3d, contrast %3d, saturation %3d, hue %d ", dev->brightness->cur.val, dev->contrast->cur.val, @@ -509,7 +509,7 @@ static void vivi_fillbuff(struct vivi_dev *dev, struct vivi_buffer *buf) dev->int_menu->qmenu_int[dev->int_menu->cur.val], dev->int_menu->cur.val); gen_text(dev, vbuf, line++ * 16, 16, str); - mutex_unlock(&dev->ctrl_handler.lock); + mutex_unlock(dev->ctrl_handler.lock); if (dev->button_pressed) { dev->button_pressed--; snprintf(str, sizeof(str), " button pressed!"); diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h index c6f6b4c2c5f2..dde6fbacc271 100644 --- a/include/media/v4l2-ctrls.h +++ b/include/media/v4l2-ctrls.h @@ -167,7 +167,9 @@ struct v4l2_ctrl_ref { /** struct v4l2_ctrl_handler - The control handler keeps track of all the * controls: both the controls owned by the handler and those inherited * from other handlers. + * @_lock: Default for "lock". * @lock: Lock to control access to this handler and its controls. + * May be replaced by the user right after init. * @ctrls: The list of controls owned by this handler. * @ctrl_refs: The list of control references. * @cached: The last found control reference. It is common that the same @@ -178,7 +180,8 @@ struct v4l2_ctrl_ref { * @error: The error code of the first failed control addition. */ struct v4l2_ctrl_handler { - struct mutex lock; + struct mutex _lock; + struct mutex *lock; struct list_head ctrls; struct list_head ctrl_refs; struct v4l2_ctrl_ref *cached; @@ -455,7 +458,7 @@ void v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed); */ static inline void v4l2_ctrl_lock(struct v4l2_ctrl *ctrl) { - mutex_lock(&ctrl->handler->lock); + mutex_lock(ctrl->handler->lock); } /** v4l2_ctrl_lock() - Helper function to unlock the handler @@ -464,7 +467,7 @@ static inline void v4l2_ctrl_lock(struct v4l2_ctrl *ctrl) */ static inline void v4l2_ctrl_unlock(struct v4l2_ctrl *ctrl) { - mutex_unlock(&ctrl->handler->lock); + mutex_unlock(ctrl->handler->lock); } /** v4l2_ctrl_g_ctrl() - Helper function to get the control's value from within a driver. -- cgit v1.2.3 From 3d51dca2a951330ec60fac705316cf3d82988e29 Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Wed, 2 May 2012 03:15:11 -0300 Subject: [media] vivi: add more pixelformats This is very useful for testing whether userspace can handle the various formats correctly. Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab --- drivers/media/video/vivi.c | 165 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 135 insertions(+), 30 deletions(-) (limited to 'drivers/media/video/vivi.c') diff --git a/drivers/media/video/vivi.c b/drivers/media/video/vivi.c index 6f2e354a242d..5e457452a6e1 100644 --- a/drivers/media/video/vivi.c +++ b/drivers/media/video/vivi.c @@ -94,6 +94,16 @@ static struct vivi_fmt formats[] = { .fourcc = V4L2_PIX_FMT_UYVY, .depth = 16, }, + { + .name = "4:2:2, packed, YVYU", + .fourcc = V4L2_PIX_FMT_YVYU, + .depth = 16, + }, + { + .name = "4:2:2, packed, VYUY", + .fourcc = V4L2_PIX_FMT_VYUY, + .depth = 16, + }, { .name = "RGB565 (LE)", .fourcc = V4L2_PIX_FMT_RGB565, /* gggbbbbb rrrrrggg */ @@ -114,6 +124,26 @@ static struct vivi_fmt formats[] = { .fourcc = V4L2_PIX_FMT_RGB555X, /* arrrrrgg gggbbbbb */ .depth = 16, }, + { + .name = "RGB24 (LE)", + .fourcc = V4L2_PIX_FMT_RGB24, /* rgb */ + .depth = 24, + }, + { + .name = "RGB24 (BE)", + .fourcc = V4L2_PIX_FMT_BGR24, /* bgr */ + .depth = 24, + }, + { + .name = "RGB32 (LE)", + .fourcc = V4L2_PIX_FMT_RGB32, /* argb */ + .depth = 32, + }, + { + .name = "RGB32 (BE)", + .fourcc = V4L2_PIX_FMT_BGR32, /* bgra */ + .depth = 32, + }, }; static struct vivi_fmt *get_format(struct v4l2_format *f) @@ -204,8 +234,9 @@ struct vivi_dev { enum v4l2_field field; unsigned int field_count; - u8 bars[9][3]; - u8 line[MAX_WIDTH * 4]; + u8 bars[9][3]; + u8 line[MAX_WIDTH * 8]; + unsigned int pixelsize; }; /* ------------------------------------------------------------------ @@ -284,6 +315,8 @@ static void precalculate_bars(struct vivi_dev *dev) switch (dev->fmt->fourcc) { case V4L2_PIX_FMT_YUYV: case V4L2_PIX_FMT_UYVY: + case V4L2_PIX_FMT_YVYU: + case V4L2_PIX_FMT_VYUY: is_yuv = 1; break; case V4L2_PIX_FMT_RGB565: @@ -298,6 +331,11 @@ static void precalculate_bars(struct vivi_dev *dev) g >>= 3; b >>= 3; break; + case V4L2_PIX_FMT_RGB24: + case V4L2_PIX_FMT_BGR24: + case V4L2_PIX_FMT_RGB32: + case V4L2_PIX_FMT_BGR32: + break; } if (is_yuv) { @@ -317,7 +355,8 @@ static void precalculate_bars(struct vivi_dev *dev) #define TSTAMP_INPUT_X 10 #define TSTAMP_MIN_X (54 + TSTAMP_INPUT_X) -static void gen_twopix(struct vivi_dev *dev, u8 *buf, int colorpos) +/* 'odd' is true for pixels 1, 3, 5, etc. and false for pixels 0, 2, 4, etc. */ +static void gen_twopix(struct vivi_dev *dev, u8 *buf, int colorpos, bool odd) { u8 r_y, g_u, b_v; int color; @@ -327,46 +366,56 @@ static void gen_twopix(struct vivi_dev *dev, u8 *buf, int colorpos) g_u = dev->bars[colorpos][1]; /* G or precalculated U */ b_v = dev->bars[colorpos][2]; /* B or precalculated V */ - for (color = 0; color < 4; color++) { + for (color = 0; color < dev->pixelsize; color++) { p = buf + color; switch (dev->fmt->fourcc) { case V4L2_PIX_FMT_YUYV: switch (color) { case 0: - case 2: *p = r_y; break; case 1: - *p = g_u; - break; - case 3: - *p = b_v; + *p = odd ? b_v : g_u; break; } break; case V4L2_PIX_FMT_UYVY: switch (color) { + case 0: + *p = odd ? b_v : g_u; + break; case 1: - case 3: *p = r_y; break; + } + break; + case V4L2_PIX_FMT_YVYU: + switch (color) { + case 0: + *p = r_y; + break; + case 1: + *p = odd ? g_u : b_v; + break; + } + break; + case V4L2_PIX_FMT_VYUY: + switch (color) { case 0: - *p = g_u; + *p = odd ? g_u : b_v; break; - case 2: - *p = b_v; + case 1: + *p = r_y; break; } break; case V4L2_PIX_FMT_RGB565: switch (color) { case 0: - case 2: *p = (g_u << 5) | b_v; break; case 1: - case 3: *p = (r_y << 3) | (g_u >> 3); break; } @@ -374,11 +423,9 @@ static void gen_twopix(struct vivi_dev *dev, u8 *buf, int colorpos) case V4L2_PIX_FMT_RGB565X: switch (color) { case 0: - case 2: *p = (r_y << 3) | (g_u >> 3); break; case 1: - case 3: *p = (g_u << 5) | b_v; break; } @@ -386,11 +433,9 @@ static void gen_twopix(struct vivi_dev *dev, u8 *buf, int colorpos) case V4L2_PIX_FMT_RGB555: switch (color) { case 0: - case 2: *p = (g_u << 5) | b_v; break; case 1: - case 3: *p = (r_y << 2) | (g_u >> 3); break; } @@ -398,15 +443,71 @@ static void gen_twopix(struct vivi_dev *dev, u8 *buf, int colorpos) case V4L2_PIX_FMT_RGB555X: switch (color) { case 0: - case 2: *p = (r_y << 2) | (g_u >> 3); break; case 1: - case 3: *p = (g_u << 5) | b_v; break; } break; + case V4L2_PIX_FMT_RGB24: + switch (color) { + case 0: + *p = r_y; + break; + case 1: + *p = g_u; + break; + case 2: + *p = b_v; + break; + } + break; + case V4L2_PIX_FMT_BGR24: + switch (color) { + case 0: + *p = b_v; + break; + case 1: + *p = g_u; + break; + case 2: + *p = r_y; + break; + } + break; + case V4L2_PIX_FMT_RGB32: + switch (color) { + case 0: + *p = 0; + break; + case 1: + *p = r_y; + break; + case 2: + *p = g_u; + break; + case 3: + *p = b_v; + break; + } + break; + case V4L2_PIX_FMT_BGR32: + switch (color) { + case 0: + *p = b_v; + break; + case 1: + *p = g_u; + break; + case 2: + *p = r_y; + break; + case 3: + *p = 0; + break; + } + break; } } } @@ -415,10 +516,10 @@ static void precalculate_line(struct vivi_dev *dev) { int w; - for (w = 0; w < dev->width * 2; w += 2) { - int colorpos = (w / (dev->width / 8) % 8); + for (w = 0; w < dev->width * 2; w++) { + int colorpos = w / (dev->width / 8) % 8; - gen_twopix(dev, dev->line + w * 2, colorpos); + gen_twopix(dev, dev->line + w * dev->pixelsize, colorpos, w & 1); } } @@ -434,7 +535,7 @@ static void gen_text(struct vivi_dev *dev, char *basep, /* Print stream time */ for (line = y; line < y + 16; line++) { int j = 0; - char *pos = basep + line * dev->width * 2 + x * 2; + char *pos = basep + line * dev->width * dev->pixelsize + x * dev->pixelsize; char *s; for (s = text; *s; s++) { @@ -444,9 +545,9 @@ static void gen_text(struct vivi_dev *dev, char *basep, for (i = 0; i < 7; i++, j++) { /* Draw white font on black background */ if (chr & (1 << (7 - i))) - gen_twopix(dev, pos + j * 2, WHITE); + gen_twopix(dev, pos + j * dev->pixelsize, WHITE, (x+y) & 1); else - gen_twopix(dev, pos + j * 2, TEXT_BLACK); + gen_twopix(dev, pos + j * dev->pixelsize, TEXT_BLACK, (x+y) & 1); } } } @@ -467,7 +568,9 @@ static void vivi_fillbuff(struct vivi_dev *dev, struct vivi_buffer *buf) return; for (h = 0; h < hmax; h++) - memcpy(vbuf + h * wmax * 2, dev->line + (dev->mv_count % wmax) * 2, wmax * 2); + memcpy(vbuf + h * wmax * dev->pixelsize, + dev->line + (dev->mv_count % wmax) * dev->pixelsize, + wmax * dev->pixelsize); /* Updates stream time */ @@ -662,7 +765,7 @@ static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt, struct vivi_dev *dev = vb2_get_drv_priv(vq); unsigned long size; - size = dev->width * dev->height * 2; + size = dev->width * dev->height * dev->pixelsize; if (0 == *nbuffers) *nbuffers = 32; @@ -726,7 +829,7 @@ static int buffer_prepare(struct vb2_buffer *vb) dev->height < 32 || dev->height > MAX_HEIGHT) return -EINVAL; - size = dev->width * dev->height * 2; + size = dev->width * dev->height * dev->pixelsize; if (vb2_plane_size(vb, 0) < size) { dprintk(dev, 1, "%s data will not fit into plane (%lu < %lu)\n", __func__, vb2_plane_size(vb, 0), size); @@ -920,6 +1023,7 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, } dev->fmt = get_format(f); + dev->pixelsize = dev->fmt->depth / 8; dev->width = f->fmt.pix.width; dev->height = f->fmt.pix.height; dev->field = f->fmt.pix.field; @@ -1266,6 +1370,7 @@ static int __init vivi_create_instance(int inst) dev->fmt = &formats[0]; dev->width = 640; dev->height = 480; + dev->pixelsize = dev->fmt->depth / 8; hdl = &dev->ctrl_handler; v4l2_ctrl_handler_init(hdl, 11); dev->volume = v4l2_ctrl_new_std(hdl, &vivi_ctrl_ops, -- cgit v1.2.3 From 7088f4df4c489811f6a5ad9a883b7dd259adfb6a Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Wed, 2 May 2012 03:33:52 -0300 Subject: [media] vivi: add the alpha component control Useful to set the alpha component for the pixel formats with an alpha channel. Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab --- drivers/media/video/vivi.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'drivers/media/video/vivi.c') diff --git a/drivers/media/video/vivi.c b/drivers/media/video/vivi.c index 5e457452a6e1..0960d7f0d394 100644 --- a/drivers/media/video/vivi.c +++ b/drivers/media/video/vivi.c @@ -200,6 +200,7 @@ struct vivi_dev { struct v4l2_ctrl *gain; }; struct v4l2_ctrl *volume; + struct v4l2_ctrl *alpha; struct v4l2_ctrl *button; struct v4l2_ctrl *boolean; struct v4l2_ctrl *int32; @@ -237,6 +238,7 @@ struct vivi_dev { u8 bars[9][3]; u8 line[MAX_WIDTH * 8]; unsigned int pixelsize; + u8 alpha_component; }; /* ------------------------------------------------------------------ @@ -359,6 +361,7 @@ static void precalculate_bars(struct vivi_dev *dev) static void gen_twopix(struct vivi_dev *dev, u8 *buf, int colorpos, bool odd) { u8 r_y, g_u, b_v; + u8 alpha = dev->alpha_component; int color; u8 *p; @@ -436,14 +439,14 @@ static void gen_twopix(struct vivi_dev *dev, u8 *buf, int colorpos, bool odd) *p = (g_u << 5) | b_v; break; case 1: - *p = (r_y << 2) | (g_u >> 3); + *p = (alpha & 0x80) | (r_y << 2) | (g_u >> 3); break; } break; case V4L2_PIX_FMT_RGB555X: switch (color) { case 0: - *p = (r_y << 2) | (g_u >> 3); + *p = (alpha & 0x80) | (r_y << 2) | (g_u >> 3); break; case 1: *p = (g_u << 5) | b_v; @@ -479,7 +482,7 @@ static void gen_twopix(struct vivi_dev *dev, u8 *buf, int colorpos, bool odd) case V4L2_PIX_FMT_RGB32: switch (color) { case 0: - *p = 0; + *p = alpha; break; case 1: *p = r_y; @@ -504,7 +507,7 @@ static void gen_twopix(struct vivi_dev *dev, u8 *buf, int colorpos, bool odd) *p = r_y; break; case 3: - *p = 0; + *p = alpha; break; } break; @@ -595,8 +598,9 @@ static void vivi_fillbuff(struct vivi_dev *dev, struct vivi_buffer *buf) dev->saturation->cur.val, dev->hue->cur.val); gen_text(dev, vbuf, line++ * 16, 16, str); - snprintf(str, sizeof(str), " autogain %d, gain %3d, volume %3d ", - dev->autogain->cur.val, gain, dev->volume->cur.val); + snprintf(str, sizeof(str), " autogain %d, gain %3d, volume %3d, alpha 0x%02x ", + dev->autogain->cur.val, gain, dev->volume->cur.val, + dev->alpha->cur.val); gen_text(dev, vbuf, line++ * 16, 16, str); snprintf(str, sizeof(str), " int32 %d, int64 %lld, bitmask %08x ", dev->int32->cur.val, @@ -1125,8 +1129,15 @@ static int vivi_s_ctrl(struct v4l2_ctrl *ctrl) { struct vivi_dev *dev = container_of(ctrl->handler, struct vivi_dev, ctrl_handler); - if (ctrl == dev->button) - dev->button_pressed = 30; + switch (ctrl->id) { + case V4L2_CID_ALPHA_COMPONENT: + dev->alpha_component = ctrl->val; + break; + default: + if (ctrl == dev->button) + dev->button_pressed = 30; + break; + } return 0; } @@ -1387,6 +1398,8 @@ static int __init vivi_create_instance(int inst) V4L2_CID_AUTOGAIN, 0, 1, 1, 1); dev->gain = v4l2_ctrl_new_std(hdl, &vivi_ctrl_ops, V4L2_CID_GAIN, 0, 255, 1, 100); + dev->alpha = v4l2_ctrl_new_std(hdl, &vivi_ctrl_ops, + V4L2_CID_ALPHA_COMPONENT, 0, 255, 1, 0); dev->button = v4l2_ctrl_new_custom(hdl, &vivi_ctrl_button, NULL); dev->int32 = v4l2_ctrl_new_custom(hdl, &vivi_ctrl_int32, NULL); dev->int64 = v4l2_ctrl_new_custom(hdl, &vivi_ctrl_int64, NULL); -- cgit v1.2.3