[media] v4l: vsp1: bru: Make the background color configurable
authorLaurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Wed, 28 May 2014 01:46:30 +0000 (22:46 -0300)
committerMauro Carvalho Chehab <m.chehab@samsung.com>
Thu, 17 Jul 2014 15:44:59 +0000 (12:44 -0300)
Expose the background color to userspace through the V4L2_CID_BG_COLOR
control.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
drivers/media/platform/vsp1/vsp1_bru.c
drivers/media/platform/vsp1/vsp1_bru.h

index 86b32bca408d314542fd08af90660c68e3d40a24..a0c1984c733ea55b125d712cb2148fc8e1ae4a7d 100644 (file)
@@ -37,6 +37,32 @@ static inline void vsp1_bru_write(struct vsp1_bru *bru, u32 reg, u32 data)
        vsp1_write(bru->entity.vsp1, reg, data);
 }
 
+/* -----------------------------------------------------------------------------
+ * Controls
+ */
+
+static int bru_s_ctrl(struct v4l2_ctrl *ctrl)
+{
+       struct vsp1_bru *bru =
+               container_of(ctrl->handler, struct vsp1_bru, ctrls);
+
+       if (!vsp1_entity_is_streaming(&bru->entity))
+               return 0;
+
+       switch (ctrl->id) {
+       case V4L2_CID_BG_COLOR:
+               vsp1_bru_write(bru, VI6_BRU_VIRRPF_COL, ctrl->val |
+                              (0xff << VI6_BRU_VIRRPF_COL_A_SHIFT));
+               break;
+       }
+
+       return 0;
+}
+
+static const struct v4l2_ctrl_ops bru_ctrl_ops = {
+       .s_ctrl = bru_s_ctrl,
+};
+
 /* -----------------------------------------------------------------------------
  * V4L2 Subdevice Core Operations
  */
@@ -48,6 +74,11 @@ static int bru_s_stream(struct v4l2_subdev *subdev, int enable)
        struct v4l2_mbus_framefmt *format;
        unsigned int flags;
        unsigned int i;
+       int ret;
+
+       ret = vsp1_entity_set_streaming(&bru->entity, enable);
+       if (ret < 0)
+               return ret;
 
        if (!enable)
                return 0;
@@ -68,15 +99,11 @@ static int bru_s_stream(struct v4l2_subdev *subdev, int enable)
                       flags & V4L2_PIX_FMT_FLAG_PREMUL_ALPHA ?
                       0 : VI6_BRU_INCTRL_NRM);
 
-       /* Set the background position to cover the whole output image and
-        * set its color to opaque black.
-        */
+       /* Set the background position to cover the whole output image. */
        vsp1_bru_write(bru, VI6_BRU_VIRRPF_SIZE,
                       (format->width << VI6_BRU_VIRRPF_SIZE_HSIZE_SHIFT) |
                       (format->height << VI6_BRU_VIRRPF_SIZE_VSIZE_SHIFT));
        vsp1_bru_write(bru, VI6_BRU_VIRRPF_LOC, 0);
-       vsp1_bru_write(bru, VI6_BRU_VIRRPF_COL,
-                      0xff << VI6_BRU_VIRRPF_COL_A_SHIFT);
 
        /* Route BRU input 1 as SRC input to the ROP unit and configure the ROP
         * unit with a NOP operation to make BRU input 1 available as the
@@ -407,5 +434,19 @@ struct vsp1_bru *vsp1_bru_create(struct vsp1_device *vsp1)
 
        vsp1_entity_init_formats(subdev, NULL);
 
+       /* Initialize the control handler. */
+       v4l2_ctrl_handler_init(&bru->ctrls, 1);
+       v4l2_ctrl_new_std(&bru->ctrls, &bru_ctrl_ops, V4L2_CID_BG_COLOR,
+                         0, 0xffffff, 1, 0);
+
+       bru->entity.subdev.ctrl_handler = &bru->ctrls;
+
+       if (bru->ctrls.error) {
+               dev_err(vsp1->dev, "bru: failed to initialize controls\n");
+               ret = bru->ctrls.error;
+               vsp1_entity_destroy(&bru->entity);
+               return ERR_PTR(ret);
+       }
+
        return bru;
 }
index 5b03479c59822d9749efe9c219d32464d6f9fb0b..16b1c6554911110583628d8ba4036e68ef5b2879 100644 (file)
@@ -14,6 +14,7 @@
 #define __VSP1_BRU_H__
 
 #include <media/media-entity.h>
+#include <media/v4l2-ctrls.h>
 #include <media/v4l2-subdev.h>
 
 #include "vsp1_entity.h"
@@ -27,6 +28,8 @@ struct vsp1_rwpf;
 struct vsp1_bru {
        struct vsp1_entity entity;
 
+       struct v4l2_ctrl_handler ctrls;
+
        struct {
                struct vsp1_rwpf *rpf;
                struct v4l2_rect compose;