Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 87 additions & 45 deletions drivers/staging/vc04_services/bcm2835-isp/bcm2835-v4l2-isp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1006,15 +1006,32 @@ static int bcm2835_isp_node_s_selection(struct file *file, void *fh,
if (!s->r.width || !s->r.height)
return -EINVAL;

/* Adjust the crop window if goes outside the frame dimensions. */
s->r.left = min((unsigned int)max(s->r.left, 0),
node->q_data.width - MIN_DIM);
s->r.top = min((unsigned int)max(s->r.top, 0),
node->q_data.height - MIN_DIM);
s->r.width = max(min(s->r.width, node->q_data.width - s->r.left),
MIN_DIM);
s->r.height = max(min(s->r.height, node->q_data.height - s->r.top),
MIN_DIM);
/* We can only set crop on the input. */
switch (s->target) {
case V4L2_SEL_TGT_CROP:
/*
* Adjust the crop window if it goes outside of the frame
* dimensions.
*/
s->r.left = min((unsigned int)max(s->r.left, 0),
node->q_data.width - MIN_DIM);
s->r.top = min((unsigned int)max(s->r.top, 0),
node->q_data.height - MIN_DIM);
s->r.width = max(min(s->r.width,
node->q_data.width - s->r.left), MIN_DIM);
s->r.height = max(min(s->r.height,
node->q_data.height - s->r.top), MIN_DIM);
break;
case V4L2_SEL_TGT_CROP_DEFAULT:
/* Default (i.e. no) crop window. */
s->r.left = 0;
s->r.top = 0;
s->r.width = node->q_data.width;
s->r.height = node->q_data.height;
break;
default:
return -EINVAL;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switch case?


crop.rect.x = s->r.left;
crop.rect.y = s->r.top;
Expand All @@ -1029,33 +1046,40 @@ static int bcm2835_isp_node_s_selection(struct file *file, void *fh,
static int bcm2835_isp_node_g_selection(struct file *file, void *fh,
struct v4l2_selection *s)
{
struct mmal_parameter_crop crop;
struct bcm2835_isp_node *node = video_drvdata(file);
struct bcm2835_isp_dev *dev = node_get_dev(node);
struct vchiq_mmal_port *port = get_port_data(node);
struct mmal_parameter_crop crop;
struct bcm2835_isp_dev *dev = node_get_dev(node);
u32 crop_size = sizeof(crop);
int ret;

/* This return value is required for V4L2 compliance. */
if (node_is_stats(node))
return -ENOTTY;

/* We can only return out an input crop. */
if (s->target != V4L2_SEL_TGT_CROP)
return -EINVAL;

ret = vchiq_mmal_port_parameter_get(dev->mmal_instance, port,
MMAL_PARAMETER_CROP,
&crop, &crop_size);
if (!ret)
return -EINVAL;

s->r.left = crop.rect.x;
s->r.top = crop.rect.y;
s->r.width = crop.rect.width;
s->r.height = crop.rect.height;
switch (s->target) {
case V4L2_SEL_TGT_CROP:
ret = vchiq_mmal_port_parameter_get(dev->mmal_instance, port,
MMAL_PARAMETER_CROP,
&crop, &crop_size);
if (!ret) {
s->r.left = crop.rect.x;
s->r.top = crop.rect.y;
s->r.width = crop.rect.width;
s->r.height = crop.rect.height;
}
break;
case V4L2_SEL_TGT_CROP_DEFAULT:
case V4L2_SEL_TGT_CROP_BOUNDS:
/* Default (i.e. no) crop window. */
s->r.left = 0;
s->r.top = 0;
s->r.width = node->q_data.width;
s->r.height = node->q_data.height;
ret = 0;
break;
default:
ret = -EINVAL;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And again, switch / case


return 0;
return ret;
}

static int bcm3285_isp_subscribe_event(struct v4l2_fh *fh,
Expand Down Expand Up @@ -1218,6 +1242,8 @@ static int register_node(struct bcm2835_isp_dev *dev,
node->vfl_dir = VFL_DIR_RX;
node->name = "stats";
v4l2_disable_ioctl(&node->vfd, VIDIOC_S_CTRL);
v4l2_disable_ioctl(&node->vfd, VIDIOC_S_SELECTION);
v4l2_disable_ioctl(&node->vfd, VIDIOC_G_SELECTION);
break;
}

Expand Down Expand Up @@ -1269,21 +1295,6 @@ static int register_node(struct bcm2835_isp_dev *dev,
}
node->queue_init = true;

/* Define the device names */
snprintf(vfd->name, sizeof(node->vfd.name), "%s-%s%d", BCM2835_ISP_NAME,
node->name, node->id);

ret = video_register_device(vfd, VFL_TYPE_GRABBER, video_nr + index);
if (ret) {
v4l2_err(&dev->v4l2_dev,
"Failed to register video %s[%d] device node\n",
node->name, node->id);
return ret;
}

node->registered = true;
video_set_drvdata(vfd, node);

/* Set some controls and defaults, but only on the VIDEO_OUTPUT node. */
if (node_is_output(node)) {
unsigned int i;
Expand All @@ -1298,7 +1309,12 @@ static int register_node(struct bcm2835_isp_dev *dev,
.step = 1,
};

v4l2_ctrl_handler_init(&dev->ctrl_handler, 4);
ret = v4l2_ctrl_handler_init(&dev->ctrl_handler, 12);
if (ret) {
v4l2_err(&dev->v4l2_dev, "ctrl_handler init failed (%d)\n",
ret);
return ret;
}

dev->r_gain = 1000;
dev->b_gain = 1000;
Expand All @@ -1324,13 +1340,39 @@ static int register_node(struct bcm2835_isp_dev *dev,
}

node->vfd.ctrl_handler = &dev->ctrl_handler;
if (dev->ctrl_handler.error) {
ret = dev->ctrl_handler.error;
v4l2_err(&dev->v4l2_dev, "controls init failed (%d)\n",
ret);
v4l2_ctrl_handler_free(&dev->ctrl_handler);
goto ctrl_cleanup;
}
}

/* Define the device names */
snprintf(vfd->name, sizeof(node->vfd.name), "%s-%s%d", BCM2835_ISP_NAME,
node->name, node->id);

ret = video_register_device(vfd, VFL_TYPE_GRABBER, video_nr + index);
if (ret) {
v4l2_err(&dev->v4l2_dev,
"Failed to register video %s[%d] device node\n",
node->name, node->id);
goto ctrl_cleanup;
}

node->registered = true;
video_set_drvdata(vfd, node);

v4l2_info(&dev->v4l2_dev,
"Device node %s[%d] registered as /dev/video%d\n",
node->name, node->id, vfd->num);

return 0;

ctrl_cleanup:
v4l2_ctrl_handler_free(&dev->ctrl_handler);
return ret;
}

/* Unregister one of the /dev/video<N> nodes associated with the ISP. */
Expand Down
4 changes: 2 additions & 2 deletions include/uapi/linux/bcm2835-isp.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
*/
struct bcm2835_isp_rational {
__s32 num;
__s32 den;
__u32 den;
};

/**
Expand Down Expand Up @@ -140,7 +140,7 @@ struct bcm2835_isp_black_level {
__u16 black_level_r;
__u16 black_level_g;
__u16 black_level_b;
__u8 pad_[2]; /* Unused */
__u8 padding[2]; /* Unused */
};

/**
Expand Down