26 #include <asm/cacheflush.h>
29 #include <linux/module.h>
32 #include <linux/sched.h>
33 #include <linux/slab.h>
135 if (formats[i].code == code)
154 static unsigned int isp_video_mbus_to_pix(
const struct isp_video *video,
155 const struct v4l2_mbus_framefmt *mbus,
159 unsigned int min_bpl;
162 memset(pix, 0,
sizeof(*pix));
163 pix->
width = mbus->width;
164 pix->
height = mbus->height;
167 if (formats[i].
code == mbus->code)
192 pix->
field = mbus->field;
194 return bpl - min_bpl;
198 struct v4l2_mbus_framefmt *mbus)
202 memset(mbus, 0,
sizeof(*mbus));
203 mbus->width = pix->
width;
204 mbus->height = pix->
height;
214 mbus->code = formats[
i].
code;
216 mbus->field = pix->
field;
226 if (remote ==
NULL ||
231 *pad = remote->
index;
237 static int isp_video_get_graph_data(
struct isp_video *video,
256 if (entity == &video->
video.entity)
270 pipe->
input = far_end;
294 static int isp_video_validate_pipeline(
struct isp_pipeline *pipe)
300 subdev = isp_video_remote_subdev(pipe->
output,
NULL);
306 pad = &subdev->entity.pads[0];
311 if (subdev == &isp->
isp_res.subdev)
340 subdev = isp_video_remote_subdev(video, &pad);
358 return isp_video_mbus_to_pix(video, &
fmt.format, &format->
fmt.
pix);
368 ret = __isp_video_get_format(video, &format);
372 if (vfh->
format.fmt.pix.pixelformat != format.
fmt.
pix.pixelformat ||
375 vfh->
format.fmt.pix.bytesperline != format.
fmt.
pix.bytesperline ||
376 vfh->
format.fmt.pix.sizeimage != format.
fmt.
pix.sizeimage)
386 #define IOMMU_FLAG (IOVMF_ENDIAN_LITTLE | IOVMF_ELSZ_8)
436 unsigned int *nbuffers,
unsigned int *
size)
442 *size = vfh->
format.fmt.pix.sizeimage;
464 struct isp_buffer *buffer = to_isp_buffer(buf);
473 dev_dbg(video->
isp->dev,
"Buffer address must be "
474 "aligned to 32 bytes boundary.\n");
479 buf->
vbuf.bytesused = vfh->
format.fmt.pix.sizeimage;
496 struct isp_buffer *buffer = to_isp_buffer(buf);
504 empty = list_empty(&video->
dmaqueue);
515 video->
ops->queue(video, buffer);
518 start = isp_pipeline_ready(pipe);
521 spin_unlock_irqrestore(&pipe->
lock, flags);
530 .queue_prepare = &isp_video_queue_prepare,
531 .buffer_prepare = &isp_video_buffer_prepare,
532 .buffer_queue = &isp_video_buffer_queue,
533 .buffer_cleanup = &isp_video_buffer_cleanup,
563 spin_unlock_irqrestore(&queue->
irqlock, flags);
570 spin_unlock_irqrestore(&queue->
irqlock, flags);
606 pipe->
state &= ~state;
609 spin_unlock_irqrestore(&pipe->
lock, flags);
616 spin_unlock_irqrestore(&pipe->
lock, flags);
622 return to_isp_buffer(buf);
642 if (!list_empty(&video->
dmaqueue)) {
645 video->
ops->queue(video, buf);
660 struct isp_video *video = video_drvdata(file);
675 isp_video_get_format(
struct file *file,
void *fh,
struct v4l2_format *format)
678 struct isp_video *video = video_drvdata(file);
691 isp_video_set_format(
struct file *file,
void *fh,
struct v4l2_format *format)
694 struct isp_video *video = video_drvdata(file);
695 struct v4l2_mbus_framefmt
fmt;
705 isp_video_pix_to_mbus(&format->
fmt.
pix, &
fmt);
706 isp_video_mbus_to_pix(video, &
fmt, &format->
fmt.
pix);
715 isp_video_try_format(
struct file *file,
void *fh,
struct v4l2_format *format)
717 struct isp_video *video = video_drvdata(file);
726 subdev = isp_video_remote_subdev(video, &pad);
730 isp_video_pix_to_mbus(&format->
fmt.
pix, &
fmt.format);
738 isp_video_mbus_to_pix(video, &
fmt.format, &format->
fmt.
pix);
743 isp_video_cropcap(
struct file *file,
void *fh,
struct v4l2_cropcap *cropcap)
745 struct isp_video *video = video_drvdata(file);
749 subdev = isp_video_remote_subdev(video,
NULL);
761 isp_video_get_crop(
struct file *file,
void *fh,
struct v4l2_crop *crop)
763 struct isp_video *video = video_drvdata(file);
769 subdev = isp_video_remote_subdev(video, &pad);
788 crop->
c.width = format.format.width;
789 crop->
c.height = format.format.height;
795 isp_video_set_crop(
struct file *file,
void *fh,
const struct v4l2_crop *crop)
797 struct isp_video *video = video_drvdata(file);
801 subdev = isp_video_remote_subdev(video,
NULL);
816 struct isp_video *video = video_drvdata(file);
831 isp_video_set_param(
struct file *file,
void *fh,
struct v4l2_streamparm *a)
834 struct isp_video *video = video_drvdata(file);
840 if (a->
parm.
output.timeperframe.denominator == 0)
857 isp_video_querybuf(
struct file *file,
void *fh,
struct v4l2_buffer *
b)
865 isp_video_qbuf(
struct file *file,
void *fh,
struct v4l2_buffer *
b)
873 isp_video_dqbuf(
struct file *file,
void *fh,
struct v4l2_buffer *
b)
881 static int isp_video_check_external_subdevs(
struct isp_video *video,
907 if (source_pad ==
NULL)
910 source = source_pad->
entity;
916 dev_warn(isp->
dev,
"can't find source, failing now\n");
937 memset(&ctrls, 0,
sizeof(ctrls));
943 ctrls.controls = &
ctrl;
947 dev_warn(isp->
dev,
"no pixel rate control in subdev %s\n",
1003 struct isp_video *video = video_drvdata(file);
1006 unsigned long flags;
1009 if (type != video->
type)
1022 pipe = video->
video.entity.pipe
1023 ? to_isp_pipeline(&video->
video.entity) : &video->pipe;
1027 if (video->
isp->pdata->set_constraints)
1028 video->
isp->pdata->set_constraints(video->
isp,
true);
1034 goto err_pipeline_start;
1039 ret = isp_video_check_format(video, vfh);
1041 goto err_check_format;
1046 ret = isp_video_get_graph_data(video, pipe);
1048 goto err_check_format;
1055 ret = isp_video_check_external_subdevs(video, pipe);
1057 goto err_check_format;
1060 ret = isp_video_validate_pipeline(pipe);
1062 goto err_check_format;
1064 pipe->
error =
false;
1069 spin_unlock_irqrestore(&pipe->
lock, flags);
1084 goto err_check_format;
1094 goto err_set_stream;
1098 spin_unlock_irqrestore(&video->
queue->irqlock, flags);
1111 if (video->
isp->pdata->set_constraints)
1112 video->
isp->pdata->set_constraints(video->
isp,
false);
1128 isp_video_streamoff(
struct file *file,
void *fh,
enum v4l2_buf_type type)
1131 struct isp_video *video = video_drvdata(file);
1134 unsigned int streaming;
1135 unsigned long flags;
1137 if (type != video->
type)
1144 streaming = vfh->
queue.streaming;
1159 pipe->
state &= ~state;
1160 spin_unlock_irqrestore(&pipe->
lock, flags);
1168 if (video->
isp->pdata->set_constraints)
1169 video->
isp->pdata->set_constraints(video->
isp,
false);
1178 isp_video_enum_input(
struct file *file,
void *fh,
struct v4l2_input *
input)
1180 if (input->
index > 0)
1190 isp_video_g_input(
struct file *file,
void *fh,
unsigned int *input)
1198 isp_video_s_input(
struct file *file,
void *fh,
unsigned int input)
1200 return input == 0 ? 0 : -
EINVAL;
1204 .vidioc_querycap = isp_video_querycap,
1205 .vidioc_g_fmt_vid_cap = isp_video_get_format,
1206 .vidioc_s_fmt_vid_cap = isp_video_set_format,
1207 .vidioc_try_fmt_vid_cap = isp_video_try_format,
1208 .vidioc_g_fmt_vid_out = isp_video_get_format,
1209 .vidioc_s_fmt_vid_out = isp_video_set_format,
1210 .vidioc_try_fmt_vid_out = isp_video_try_format,
1211 .vidioc_cropcap = isp_video_cropcap,
1212 .vidioc_g_crop = isp_video_get_crop,
1213 .vidioc_s_crop = isp_video_set_crop,
1214 .vidioc_g_parm = isp_video_get_param,
1215 .vidioc_s_parm = isp_video_set_param,
1216 .vidioc_reqbufs = isp_video_reqbufs,
1217 .vidioc_querybuf = isp_video_querybuf,
1218 .vidioc_qbuf = isp_video_qbuf,
1219 .vidioc_dqbuf = isp_video_dqbuf,
1220 .vidioc_streamon = isp_video_streamon,
1221 .vidioc_streamoff = isp_video_streamoff,
1222 .vidioc_enum_input = isp_video_enum_input,
1223 .vidioc_g_input = isp_video_g_input,
1224 .vidioc_s_input = isp_video_s_input,
1231 static int isp_video_open(
struct file *file)
1233 struct isp_video *video = video_drvdata(file);
1237 handle = kzalloc(
sizeof(*handle),
GFP_KERNEL);
1257 &isp_video_queue_ops, video->
isp->dev,
1276 static int isp_video_release(
struct file *file)
1278 struct isp_video *video = video_drvdata(file);
1283 isp_video_streamoff(file, vfh, video->
type);
1301 static unsigned int isp_video_poll(
struct file *file,
poll_table *
wait)
1309 static int isp_video_mmap(
struct file *file,
struct vm_area_struct *vma)
1319 .open = isp_video_open,
1320 .release = isp_video_release,
1321 .poll = isp_video_poll,
1322 .mmap = isp_video_mmap,
1337 switch (video->
type) {
1339 direction =
"output";
1343 direction =
"input";
1364 video->
ops = &isp_video_dummy_ops;
1366 video->
video.fops = &isp_video_fops;
1368 "OMAP3 ISP %s %s", name, direction);
1371 video->
video.ioctl_ops = &isp_video_ioctl_ops;
1374 video_set_drvdata(&video->
video, video);
1390 video->
video.v4l2_dev = vdev;
1402 if (video_is_registered(&video->
video))