Commit 2b61d46e authored by Laurent Pinchart's avatar Laurent Pinchart Committed by Mauro Carvalho Chehab

[media] soc_camera: Use soc_camera_device::sizeimage to compute buffer sizes

Instead of computing the buffer size manually in the videobuf queue
setup and buffer prepare callbacks, use the previously negotiated
soc_camera_device::sizeimage value.
Signed-off-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: default avatarGuennadi Liakhovetski <g.liakhovetski@gmx.de>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 584943aa
...@@ -260,7 +260,7 @@ static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt, ...@@ -260,7 +260,7 @@ static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
struct soc_camera_host *ici = to_soc_camera_host(icd->parent); struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
struct atmel_isi *isi = ici->priv; struct atmel_isi *isi = ici->priv;
unsigned long size; unsigned long size;
int ret, bytes_per_line; int ret;
/* Reset ISI */ /* Reset ISI */
ret = atmel_isi_wait_status(isi, WAIT_ISI_RESET); ret = atmel_isi_wait_status(isi, WAIT_ISI_RESET);
...@@ -271,13 +271,7 @@ static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt, ...@@ -271,13 +271,7 @@ static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
/* Disable all interrupts */ /* Disable all interrupts */
isi_writel(isi, ISI_INTDIS, ~0UL); isi_writel(isi, ISI_INTDIS, ~0UL);
bytes_per_line = soc_mbus_bytes_per_line(icd->user_width, size = icd->sizeimage;
icd->current_fmt->host_fmt);
if (bytes_per_line < 0)
return bytes_per_line;
size = bytes_per_line * icd->user_height;
if (!*nbuffers || *nbuffers > MAX_BUFFER_NUM) if (!*nbuffers || *nbuffers > MAX_BUFFER_NUM)
*nbuffers = MAX_BUFFER_NUM; *nbuffers = MAX_BUFFER_NUM;
...@@ -316,13 +310,8 @@ static int buffer_prepare(struct vb2_buffer *vb) ...@@ -316,13 +310,8 @@ static int buffer_prepare(struct vb2_buffer *vb)
struct atmel_isi *isi = ici->priv; struct atmel_isi *isi = ici->priv;
unsigned long size; unsigned long size;
struct isi_dma_desc *desc; struct isi_dma_desc *desc;
int bytes_per_line = soc_mbus_bytes_per_line(icd->user_width,
icd->current_fmt->host_fmt);
if (bytes_per_line < 0)
return bytes_per_line;
size = bytes_per_line * icd->user_height; size = icd->sizeimage;
if (vb2_plane_size(vb, 0) < size) { if (vb2_plane_size(vb, 0) < size) {
dev_err(icd->parent, "%s data will not fit into plane (%lu < %lu)\n", dev_err(icd->parent, "%s data will not fit into plane (%lu < %lu)\n",
......
...@@ -126,13 +126,8 @@ static int mx1_videobuf_setup(struct videobuf_queue *vq, unsigned int *count, ...@@ -126,13 +126,8 @@ static int mx1_videobuf_setup(struct videobuf_queue *vq, unsigned int *count,
unsigned int *size) unsigned int *size)
{ {
struct soc_camera_device *icd = vq->priv_data; struct soc_camera_device *icd = vq->priv_data;
int bytes_per_line = soc_mbus_bytes_per_line(icd->user_width,
icd->current_fmt->host_fmt);
if (bytes_per_line < 0) *size = icd->sizeimage;
return bytes_per_line;
*size = bytes_per_line * icd->user_height;
if (!*count) if (!*count)
*count = 32; *count = 32;
...@@ -171,11 +166,6 @@ static int mx1_videobuf_prepare(struct videobuf_queue *vq, ...@@ -171,11 +166,6 @@ static int mx1_videobuf_prepare(struct videobuf_queue *vq,
struct soc_camera_device *icd = vq->priv_data; struct soc_camera_device *icd = vq->priv_data;
struct mx1_buffer *buf = container_of(vb, struct mx1_buffer, vb); struct mx1_buffer *buf = container_of(vb, struct mx1_buffer, vb);
int ret; int ret;
int bytes_per_line = soc_mbus_bytes_per_line(icd->user_width,
icd->current_fmt->host_fmt);
if (bytes_per_line < 0)
return bytes_per_line;
dev_dbg(icd->parent, "%s (vb=0x%p) 0x%08lx %d\n", __func__, dev_dbg(icd->parent, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
vb, vb->baddr, vb->bsize); vb, vb->baddr, vb->bsize);
...@@ -202,7 +192,7 @@ static int mx1_videobuf_prepare(struct videobuf_queue *vq, ...@@ -202,7 +192,7 @@ static int mx1_videobuf_prepare(struct videobuf_queue *vq,
vb->state = VIDEOBUF_NEEDS_INIT; vb->state = VIDEOBUF_NEEDS_INIT;
} }
vb->size = bytes_per_line * vb->height; vb->size = icd->sizeimage;
if (0 != vb->baddr && vb->bsize < vb->size) { if (0 != vb->baddr && vb->bsize < vb->size) {
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
......
...@@ -538,8 +538,6 @@ static int mx2_videobuf_setup(struct vb2_queue *vq, ...@@ -538,8 +538,6 @@ static int mx2_videobuf_setup(struct vb2_queue *vq,
struct soc_camera_device *icd = soc_camera_from_vb2q(vq); struct soc_camera_device *icd = soc_camera_from_vb2q(vq);
struct soc_camera_host *ici = to_soc_camera_host(icd->parent); struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
struct mx2_camera_dev *pcdev = ici->priv; struct mx2_camera_dev *pcdev = ici->priv;
int bytes_per_line = soc_mbus_bytes_per_line(icd->user_width,
icd->current_fmt->host_fmt);
dev_dbg(icd->parent, "count=%d, size=%d\n", *count, sizes[0]); dev_dbg(icd->parent, "count=%d, size=%d\n", *count, sizes[0]);
...@@ -547,12 +545,9 @@ static int mx2_videobuf_setup(struct vb2_queue *vq, ...@@ -547,12 +545,9 @@ static int mx2_videobuf_setup(struct vb2_queue *vq,
if (fmt != NULL) if (fmt != NULL)
return -ENOTTY; return -ENOTTY;
if (bytes_per_line < 0)
return bytes_per_line;
alloc_ctxs[0] = pcdev->alloc_ctx; alloc_ctxs[0] = pcdev->alloc_ctx;
sizes[0] = bytes_per_line * icd->user_height; sizes[0] = icd->sizeimage;
if (0 == *count) if (0 == *count)
*count = 32; *count = 32;
...@@ -568,16 +563,11 @@ static int mx2_videobuf_setup(struct vb2_queue *vq, ...@@ -568,16 +563,11 @@ static int mx2_videobuf_setup(struct vb2_queue *vq,
static int mx2_videobuf_prepare(struct vb2_buffer *vb) static int mx2_videobuf_prepare(struct vb2_buffer *vb)
{ {
struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2_queue); struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2_queue);
int bytes_per_line = soc_mbus_bytes_per_line(icd->user_width,
icd->current_fmt->host_fmt);
int ret = 0; int ret = 0;
dev_dbg(icd->parent, "%s (vb=0x%p) 0x%p %lu\n", __func__, dev_dbg(icd->parent, "%s (vb=0x%p) 0x%p %lu\n", __func__,
vb, vb2_plane_vaddr(vb, 0), vb2_get_plane_payload(vb, 0)); vb, vb2_plane_vaddr(vb, 0), vb2_get_plane_payload(vb, 0));
if (bytes_per_line < 0)
return bytes_per_line;
#ifdef DEBUG #ifdef DEBUG
/* /*
* This can be useful if you want to see if we actually fill * This can be useful if you want to see if we actually fill
...@@ -587,7 +577,7 @@ static int mx2_videobuf_prepare(struct vb2_buffer *vb) ...@@ -587,7 +577,7 @@ static int mx2_videobuf_prepare(struct vb2_buffer *vb)
0xaa, vb2_get_plane_payload(vb, 0)); 0xaa, vb2_get_plane_payload(vb, 0));
#endif #endif
vb2_set_plane_payload(vb, 0, bytes_per_line * icd->user_height); vb2_set_plane_payload(vb, 0, icd->sizeimage);
if (vb2_plane_vaddr(vb, 0) && if (vb2_plane_vaddr(vb, 0) &&
vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0)) { vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0)) {
ret = -EINVAL; ret = -EINVAL;
......
...@@ -199,8 +199,6 @@ static int mx3_videobuf_setup(struct vb2_queue *vq, ...@@ -199,8 +199,6 @@ static int mx3_videobuf_setup(struct vb2_queue *vq,
struct soc_camera_device *icd = soc_camera_from_vb2q(vq); struct soc_camera_device *icd = soc_camera_from_vb2q(vq);
struct soc_camera_host *ici = to_soc_camera_host(icd->parent); struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
struct mx3_camera_dev *mx3_cam = ici->priv; struct mx3_camera_dev *mx3_cam = ici->priv;
int bytes_per_line;
unsigned int height;
if (!mx3_cam->idmac_channel[0]) if (!mx3_cam->idmac_channel[0])
return -EINVAL; return -EINVAL;
...@@ -208,21 +206,21 @@ static int mx3_videobuf_setup(struct vb2_queue *vq, ...@@ -208,21 +206,21 @@ static int mx3_videobuf_setup(struct vb2_queue *vq,
if (fmt) { if (fmt) {
const struct soc_camera_format_xlate *xlate = soc_camera_xlate_by_fourcc(icd, const struct soc_camera_format_xlate *xlate = soc_camera_xlate_by_fourcc(icd,
fmt->fmt.pix.pixelformat); fmt->fmt.pix.pixelformat);
int bytes_per_line;
if (!xlate) if (!xlate)
return -EINVAL; return -EINVAL;
bytes_per_line = soc_mbus_bytes_per_line(fmt->fmt.pix.width, bytes_per_line = soc_mbus_bytes_per_line(fmt->fmt.pix.width,
xlate->host_fmt); xlate->host_fmt);
height = fmt->fmt.pix.height;
} else {
/* Called from VIDIOC_REQBUFS or in compatibility mode */
bytes_per_line = soc_mbus_bytes_per_line(icd->user_width,
icd->current_fmt->host_fmt);
height = icd->user_height;
}
if (bytes_per_line < 0) if (bytes_per_line < 0)
return bytes_per_line; return bytes_per_line;
sizes[0] = bytes_per_line * height; sizes[0] = bytes_per_line * fmt->fmt.pix.height;
} else {
/* Called from VIDIOC_REQBUFS or in compatibility mode */
sizes[0] = icd->sizeimage;
}
alloc_ctxs[0] = mx3_cam->alloc_ctx; alloc_ctxs[0] = mx3_cam->alloc_ctx;
...@@ -274,7 +272,7 @@ static void mx3_videobuf_queue(struct vb2_buffer *vb) ...@@ -274,7 +272,7 @@ static void mx3_videobuf_queue(struct vb2_buffer *vb)
BUG_ON(bytes_per_line <= 0); BUG_ON(bytes_per_line <= 0);
new_size = bytes_per_line * icd->user_height; new_size = icd->sizeimage;
if (vb2_plane_size(vb, 0) < new_size) { if (vb2_plane_size(vb, 0) < new_size) {
dev_err(icd->parent, "Buffer #%d too small (%lu < %zu)\n", dev_err(icd->parent, "Buffer #%d too small (%lu < %zu)\n",
......
...@@ -206,15 +206,10 @@ static int omap1_videobuf_setup(struct videobuf_queue *vq, unsigned int *count, ...@@ -206,15 +206,10 @@ static int omap1_videobuf_setup(struct videobuf_queue *vq, unsigned int *count,
unsigned int *size) unsigned int *size)
{ {
struct soc_camera_device *icd = vq->priv_data; struct soc_camera_device *icd = vq->priv_data;
int bytes_per_line = soc_mbus_bytes_per_line(icd->user_width,
icd->current_fmt->host_fmt);
struct soc_camera_host *ici = to_soc_camera_host(icd->parent); struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
struct omap1_cam_dev *pcdev = ici->priv; struct omap1_cam_dev *pcdev = ici->priv;
if (bytes_per_line < 0) *size = icd->sizeimage;
return bytes_per_line;
*size = bytes_per_line * icd->user_height;
if (!*count || *count < OMAP1_CAMERA_MIN_BUF_COUNT(pcdev->vb_mode)) if (!*count || *count < OMAP1_CAMERA_MIN_BUF_COUNT(pcdev->vb_mode))
*count = OMAP1_CAMERA_MIN_BUF_COUNT(pcdev->vb_mode); *count = OMAP1_CAMERA_MIN_BUF_COUNT(pcdev->vb_mode);
...@@ -256,15 +251,10 @@ static int omap1_videobuf_prepare(struct videobuf_queue *vq, ...@@ -256,15 +251,10 @@ static int omap1_videobuf_prepare(struct videobuf_queue *vq,
{ {
struct soc_camera_device *icd = vq->priv_data; struct soc_camera_device *icd = vq->priv_data;
struct omap1_cam_buf *buf = container_of(vb, struct omap1_cam_buf, vb); struct omap1_cam_buf *buf = container_of(vb, struct omap1_cam_buf, vb);
int bytes_per_line = soc_mbus_bytes_per_line(icd->user_width,
icd->current_fmt->host_fmt);
struct soc_camera_host *ici = to_soc_camera_host(icd->parent); struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
struct omap1_cam_dev *pcdev = ici->priv; struct omap1_cam_dev *pcdev = ici->priv;
int ret; int ret;
if (bytes_per_line < 0)
return bytes_per_line;
WARN_ON(!list_empty(&vb->queue)); WARN_ON(!list_empty(&vb->queue));
BUG_ON(NULL == icd->current_fmt); BUG_ON(NULL == icd->current_fmt);
...@@ -281,7 +271,7 @@ static int omap1_videobuf_prepare(struct videobuf_queue *vq, ...@@ -281,7 +271,7 @@ static int omap1_videobuf_prepare(struct videobuf_queue *vq,
vb->state = VIDEOBUF_NEEDS_INIT; vb->state = VIDEOBUF_NEEDS_INIT;
} }
vb->size = bytes_per_line * vb->height; vb->size = icd->sizeimage;
if (vb->baddr && vb->bsize < vb->size) { if (vb->baddr && vb->bsize < vb->size) {
ret = -EINVAL; ret = -EINVAL;
......
...@@ -241,15 +241,10 @@ static int pxa_videobuf_setup(struct videobuf_queue *vq, unsigned int *count, ...@@ -241,15 +241,10 @@ static int pxa_videobuf_setup(struct videobuf_queue *vq, unsigned int *count,
unsigned int *size) unsigned int *size)
{ {
struct soc_camera_device *icd = vq->priv_data; struct soc_camera_device *icd = vq->priv_data;
int bytes_per_line = soc_mbus_bytes_per_line(icd->user_width,
icd->current_fmt->host_fmt);
if (bytes_per_line < 0)
return bytes_per_line;
dev_dbg(icd->parent, "count=%d, size=%d\n", *count, *size); dev_dbg(icd->parent, "count=%d, size=%d\n", *count, *size);
*size = bytes_per_line * icd->user_height; *size = icd->sizeimage;
if (0 == *count) if (0 == *count)
*count = 32; *count = 32;
...@@ -435,11 +430,6 @@ static int pxa_videobuf_prepare(struct videobuf_queue *vq, ...@@ -435,11 +430,6 @@ static int pxa_videobuf_prepare(struct videobuf_queue *vq,
struct pxa_buffer *buf = container_of(vb, struct pxa_buffer, vb); struct pxa_buffer *buf = container_of(vb, struct pxa_buffer, vb);
int ret; int ret;
int size_y, size_u = 0, size_v = 0; int size_y, size_u = 0, size_v = 0;
int bytes_per_line = soc_mbus_bytes_per_line(icd->user_width,
icd->current_fmt->host_fmt);
if (bytes_per_line < 0)
return bytes_per_line;
dev_dbg(dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__, dev_dbg(dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
vb, vb->baddr, vb->bsize); vb, vb->baddr, vb->bsize);
...@@ -474,7 +464,7 @@ static int pxa_videobuf_prepare(struct videobuf_queue *vq, ...@@ -474,7 +464,7 @@ static int pxa_videobuf_prepare(struct videobuf_queue *vq,
vb->state = VIDEOBUF_NEEDS_INIT; vb->state = VIDEOBUF_NEEDS_INIT;
} }
vb->size = bytes_per_line * vb->height; vb->size = icd->sizeimage;
if (0 != vb->baddr && vb->bsize < vb->size) { if (0 != vb->baddr && vb->bsize < vb->size) {
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
......
...@@ -210,27 +210,25 @@ static int sh_mobile_ceu_videobuf_setup(struct vb2_queue *vq, ...@@ -210,27 +210,25 @@ static int sh_mobile_ceu_videobuf_setup(struct vb2_queue *vq,
struct soc_camera_device *icd = container_of(vq, struct soc_camera_device, vb2_vidq); struct soc_camera_device *icd = container_of(vq, struct soc_camera_device, vb2_vidq);
struct soc_camera_host *ici = to_soc_camera_host(icd->parent); struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
struct sh_mobile_ceu_dev *pcdev = ici->priv; struct sh_mobile_ceu_dev *pcdev = ici->priv;
int bytes_per_line;
unsigned int height;
if (fmt) { if (fmt) {
const struct soc_camera_format_xlate *xlate = soc_camera_xlate_by_fourcc(icd, const struct soc_camera_format_xlate *xlate = soc_camera_xlate_by_fourcc(icd,
fmt->fmt.pix.pixelformat); fmt->fmt.pix.pixelformat);
int bytes_per_line;
if (!xlate) if (!xlate)
return -EINVAL; return -EINVAL;
bytes_per_line = soc_mbus_bytes_per_line(fmt->fmt.pix.width, bytes_per_line = soc_mbus_bytes_per_line(fmt->fmt.pix.width,
xlate->host_fmt); xlate->host_fmt);
height = fmt->fmt.pix.height;
} else {
/* Called from VIDIOC_REQBUFS or in compatibility mode */
bytes_per_line = soc_mbus_bytes_per_line(icd->user_width,
icd->current_fmt->host_fmt);
height = icd->user_height;
}
if (bytes_per_line < 0) if (bytes_per_line < 0)
return bytes_per_line; return bytes_per_line;
sizes[0] = bytes_per_line * height; sizes[0] = bytes_per_line * fmt->fmt.pix.height;
} else {
/* Called from VIDIOC_REQBUFS or in compatibility mode */
sizes[0] = icd->sizeimage;
}
alloc_ctxs[0] = pcdev->alloc_ctx; alloc_ctxs[0] = pcdev->alloc_ctx;
...@@ -377,13 +375,8 @@ static void sh_mobile_ceu_videobuf_queue(struct vb2_buffer *vb) ...@@ -377,13 +375,8 @@ static void sh_mobile_ceu_videobuf_queue(struct vb2_buffer *vb)
struct sh_mobile_ceu_dev *pcdev = ici->priv; struct sh_mobile_ceu_dev *pcdev = ici->priv;
struct sh_mobile_ceu_buffer *buf = to_ceu_vb(vb); struct sh_mobile_ceu_buffer *buf = to_ceu_vb(vb);
unsigned long size; unsigned long size;
int bytes_per_line = soc_mbus_bytes_per_line(icd->user_width,
icd->current_fmt->host_fmt);
if (bytes_per_line < 0)
goto error;
size = icd->user_height * bytes_per_line; size = icd->sizeimage;
if (vb2_plane_size(vb, 0) < size) { if (vb2_plane_size(vb, 0) < size) {
dev_err(icd->parent, "Buffer #%d too small (%lu < %lu)\n", dev_err(icd->parent, "Buffer #%d too small (%lu < %lu)\n",
......
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