69 #include <linux/module.h>
70 #include <linux/slab.h>
80 static u32 numbuffers = 3;
114 static struct vpfe_config_params config_params = {
117 .min_bufsize = 720 * 480 * 2,
118 .device_bufsize = 720 * 576 * 2,
122 static struct ccdc_hw_device *ccdc_dev;
134 static const struct vpfe_pixel_format vpfe_pix_fmts[] = {
139 .description =
"Bayer GrRBGb 8bit A-Law compr.",
148 .description =
"Bayer GrRBGb - 16bit",
157 .description =
"Bayer GrRBGb 8bit DPCM compr.",
166 .description =
"YCbCr 4:2:2 Interleaved UYVY",
175 .description =
"YCbCr 4:2:2 Interleaved YUYV",
184 .description =
"Y/CbCr 4:2:0 - Semi planar",
195 static const struct vpfe_pixel_format *vpfe_lookup_pix_format(
u32 pix_format)
199 for (i = 0; i <
ARRAY_SIZE(vpfe_pix_fmts); i++) {
200 if (pix_format == vpfe_pix_fmts[i].fmtdesc.pixelformat)
201 return &vpfe_pix_fmts[
i];
215 BUG_ON(!dev->hw_ops.open);
216 BUG_ON(!dev->hw_ops.enable);
217 BUG_ON(!dev->hw_ops.set_hw_if_params);
218 BUG_ON(!dev->hw_ops.configure);
219 BUG_ON(!dev->hw_ops.set_buftype);
220 BUG_ON(!dev->hw_ops.get_buftype);
221 BUG_ON(!dev->hw_ops.enum_pix);
222 BUG_ON(!dev->hw_ops.set_frame_format);
223 BUG_ON(!dev->hw_ops.get_frame_format);
224 BUG_ON(!dev->hw_ops.get_pixel_format);
225 BUG_ON(!dev->hw_ops.set_pixel_format);
226 BUG_ON(!dev->hw_ops.set_image_window);
227 BUG_ON(!dev->hw_ops.get_image_window);
228 BUG_ON(!dev->hw_ops.get_line_length);
229 BUG_ON(!dev->hw_ops.getfid);
232 if (
NULL == ccdc_cfg) {
291 static int vpfe_get_ccdc_image_format(
struct vpfe_device *vpfe_dev,
300 ccdc_dev->hw_ops.get_image_window(&image_win);
301 f->
fmt.
pix.width = image_win.width;
302 f->
fmt.
pix.height = image_win.height;
303 f->
fmt.
pix.bytesperline = ccdc_dev->hw_ops.get_line_length();
306 buf_type = ccdc_dev->hw_ops.get_buftype();
307 f->
fmt.
pix.pixelformat = ccdc_dev->hw_ops.get_pixel_format();
308 frm_fmt = ccdc_dev->hw_ops.get_frame_format();
317 v4l2_err(&vpfe_dev->v4l2_dev,
"Invalid buf_type\n");
321 v4l2_err(&vpfe_dev->v4l2_dev,
"Invalid frm_fmt\n");
331 static int vpfe_config_ccdc_image_format(
struct vpfe_device *vpfe_dev)
336 if (ccdc_dev->hw_ops.set_pixel_format(
337 vpfe_dev->fmt.fmt.pix.pixelformat) < 0) {
339 "couldn't set pix format in ccdc\n");
343 ccdc_dev->hw_ops.set_image_window(&vpfe_dev->crop);
345 switch (vpfe_dev->fmt.fmt.pix.field) {
348 ret = ccdc_dev->hw_ops.set_buftype(
356 ret = ccdc_dev->hw_ops.set_buftype(
365 ret = ccdc_dev->hw_ops.set_frame_format(frm_fmt);
378 static int vpfe_config_image_format(
struct vpfe_device *vpfe_dev,
381 struct vpfe_subdev_info *sdinfo = vpfe_dev->current_subdev;
382 struct v4l2_mbus_framefmt mbus_fmt;
386 for (i = 0; i <
ARRAY_SIZE(vpfe_standards); i++) {
387 if (vpfe_standards[i].std_id & *std_id) {
388 vpfe_dev->std_info.active_pixels =
390 vpfe_dev->std_info.active_lines =
392 vpfe_dev->std_info.frame_format =
394 vpfe_dev->std_index =
i;
400 v4l2_err(&vpfe_dev->v4l2_dev,
"standard not supported\n");
404 vpfe_dev->crop.top = 0;
405 vpfe_dev->crop.left = 0;
406 vpfe_dev->crop.width = vpfe_dev->std_info.active_pixels;
407 vpfe_dev->crop.height = vpfe_dev->std_info.active_lines;
408 pix->
width = vpfe_dev->crop.width;
409 pix->
height = vpfe_dev->crop.height;
412 if (vpfe_dev->std_info.frame_format) {
416 v4l2_fill_mbus_format(&mbus_fmt, pix,
422 v4l2_fill_mbus_format(&mbus_fmt, pix,
428 sdinfo->grp_id, video, g_mbus_fmt, &mbus_fmt);
432 "error in getting g_mbus_fmt from sub device\n");
435 v4l2_fill_pix_format(pix, &mbus_fmt);
440 ret = vpfe_config_ccdc_image_format(vpfe_dev);
452 static int vpfe_initialize_device(
struct vpfe_device *vpfe_dev)
457 vpfe_dev->current_input = 0;
460 vpfe_dev->std_index = 0;
463 ret = vpfe_config_image_format(vpfe_dev,
464 &vpfe_standards[vpfe_dev->std_index].
std_id);
470 if (
NULL == ccdc_dev) {
471 v4l2_err(&vpfe_dev->v4l2_dev,
"ccdc device not registered\n");
476 if (!try_module_get(ccdc_dev->owner)) {
477 v4l2_err(&vpfe_dev->v4l2_dev,
"Couldn't lock ccdc module\n");
481 ret = ccdc_dev->hw_ops.open(vpfe_dev->pdev);
483 vpfe_dev->initialized = 1;
486 if (vpfe_dev->cfg->clr_intr)
487 vpfe_dev->cfg->clr_intr(-1);
498 static int vpfe_open(
struct file *
file)
500 struct vpfe_device *vpfe_dev = video_drvdata(file);
505 if (!vpfe_dev->cfg->num_subdevs) {
506 v4l2_err(&vpfe_dev->v4l2_dev,
"No decoder registered\n");
514 "unable to allocate memory for file handle object\n");
519 fh->vpfe_dev = vpfe_dev;
522 if (!vpfe_dev->initialized) {
523 if (vpfe_initialize_device(vpfe_dev)) {
539 static void vpfe_schedule_next_buffer(
struct vpfe_device *vpfe_dev)
543 vpfe_dev->next_frm =
list_entry(vpfe_dev->dma_queue.next,
545 list_del(&vpfe_dev->next_frm->queue);
549 ccdc_dev->hw_ops.setfbaddr(addr);
552 static void vpfe_schedule_bottom_field(
struct vpfe_device *vpfe_dev)
557 addr += vpfe_dev->field_off;
558 ccdc_dev->hw_ops.setfbaddr(addr);
561 static void vpfe_process_buffer_complete(
struct vpfe_device *vpfe_dev)
566 vpfe_dev->cur_frm->ts = timevalue;
568 vpfe_dev->cur_frm->size = vpfe_dev->fmt.fmt.pix.sizeimage;
570 vpfe_dev->cur_frm = vpfe_dev->next_frm;
576 struct vpfe_device *vpfe_dev =
dev_id;
580 v4l2_dbg(1,
debug, &vpfe_dev->v4l2_dev,
"\nStarting vpfe_isr...\n");
581 field = vpfe_dev->fmt.fmt.pix.field;
584 if (!vpfe_dev->started)
588 if (
NULL != ccdc_dev->hw_ops.reset)
589 ccdc_dev->hw_ops.reset();
594 "frame format is progressive...\n");
595 if (vpfe_dev->cur_frm != vpfe_dev->next_frm)
596 vpfe_process_buffer_complete(vpfe_dev);
601 fid = ccdc_dev->hw_ops.getfid();
604 vpfe_dev->field_id ^= 1;
605 v4l2_dbg(1,
debug, &vpfe_dev->v4l2_dev,
"field id = %x:%x.\n",
606 fid, vpfe_dev->field_id);
607 if (fid == vpfe_dev->field_id) {
614 if (vpfe_dev->cur_frm != vpfe_dev->next_frm)
615 vpfe_process_buffer_complete(vpfe_dev);
622 vpfe_schedule_bottom_field(vpfe_dev);
632 spin_lock(&vpfe_dev->dma_queue_lock);
633 if (!list_empty(&vpfe_dev->dma_queue) &&
634 vpfe_dev->cur_frm == vpfe_dev->next_frm)
635 vpfe_schedule_next_buffer(vpfe_dev);
636 spin_unlock(&vpfe_dev->dma_queue_lock);
637 }
else if (fid == 0) {
642 vpfe_dev->field_id =
fid;
645 if (vpfe_dev->cfg->clr_intr)
646 vpfe_dev->cfg->clr_intr(irq);
652 static irqreturn_t vdint1_isr(
int irq,
void *dev_id)
654 struct vpfe_device *vpfe_dev =
dev_id;
656 v4l2_dbg(1,
debug, &vpfe_dev->v4l2_dev,
"\nInside vdint1_isr...\n");
659 if (!vpfe_dev->started) {
660 if (vpfe_dev->cfg->clr_intr)
661 vpfe_dev->cfg->clr_intr(irq);
665 spin_lock(&vpfe_dev->dma_queue_lock);
667 !list_empty(&vpfe_dev->dma_queue) &&
668 vpfe_dev->cur_frm == vpfe_dev->next_frm)
669 vpfe_schedule_next_buffer(vpfe_dev);
670 spin_unlock(&vpfe_dev->dma_queue_lock);
672 if (vpfe_dev->cfg->clr_intr)
673 vpfe_dev->cfg->clr_intr(irq);
678 static void vpfe_detach_irq(
struct vpfe_device *vpfe_dev)
682 frame_format = ccdc_dev->hw_ops.get_frame_format();
684 free_irq(vpfe_dev->ccdc_irq1, vpfe_dev);
687 static int vpfe_attach_irq(
struct vpfe_device *vpfe_dev)
691 frame_format = ccdc_dev->hw_ops.get_frame_format();
693 return request_irq(vpfe_dev->ccdc_irq1, vdint1_isr,
701 static void vpfe_stop_ccdc_capture(
struct vpfe_device *vpfe_dev)
703 vpfe_dev->started = 0;
704 ccdc_dev->hw_ops.enable(0);
705 if (ccdc_dev->hw_ops.enable_out_to_sdram)
706 ccdc_dev->hw_ops.enable_out_to_sdram(0);
713 static int vpfe_release(
struct file *file)
715 struct vpfe_device *vpfe_dev = video_drvdata(file);
717 struct vpfe_subdev_info *sdinfo;
725 if (fh->io_allowed) {
726 if (vpfe_dev->started) {
727 sdinfo = vpfe_dev->current_subdev;
733 "stream off failed in subdev\n");
734 vpfe_stop_ccdc_capture(vpfe_dev);
735 vpfe_detach_irq(vpfe_dev);
738 vpfe_dev->io_usrs = 0;
739 vpfe_dev->numbuffers = config_params.numbuffers;
747 if (!vpfe_dev->usrs) {
748 vpfe_dev->initialized = 0;
749 if (ccdc_dev->hw_ops.close)
750 ccdc_dev->hw_ops.close(vpfe_dev->pdev);
751 module_put(ccdc_dev->owner);
764 static int vpfe_mmap(
struct file *file,
struct vm_area_struct *vma)
767 struct vpfe_device *vpfe_dev = video_drvdata(file);
777 static unsigned int vpfe_poll(
struct file *file,
poll_table *
wait)
779 struct vpfe_device *vpfe_dev = video_drvdata(file);
783 if (vpfe_dev->started)
785 &vpfe_dev->buffer_queue, wait);
793 .release = vpfe_release,
816 static const struct vpfe_pixel_format *
817 vpfe_check_format(
struct vpfe_device *vpfe_dev,
821 const struct vpfe_pixel_format *vpfe_pix_fmt;
825 vpfe_pix_fmt = vpfe_lookup_pix_format(pixfmt->
pixelformat);
826 if (
NULL == vpfe_pix_fmt) {
831 pixfmt->
pixelformat = vpfe_dev->fmt.fmt.pix.pixelformat;
832 vpfe_pix_fmt = vpfe_lookup_pix_format(pixfmt->
pixelformat);
838 while (ccdc_dev->hw_ops.enum_pix(&pix, temp) >= 0) {
839 if (vpfe_pix_fmt->fmtdesc.pixelformat == pix) {
848 pixfmt->
pixelformat = vpfe_dev->fmt.fmt.pix.pixelformat;
853 vpfe_pix_fmt = vpfe_lookup_pix_format(pixfmt->
pixelformat);
859 pixfmt->
field = vpfe_dev->fmt.fmt.pix.field;
866 if (vpfe_dev->fmt.fmt.pix.field != pixfmt->
field) {
871 switch (pixfmt->
field) {
875 if (!vpfe_dev->std_info.frame_format)
879 if (vpfe_dev->std_info.frame_format)
885 pixfmt->
field = vpfe_dev->fmt.fmt.pix.field;
895 max_width = vpfe_dev->std_info.active_pixels;
896 max_height = vpfe_dev->std_info.active_lines;
899 v4l2_info(&vpfe_dev->v4l2_dev,
"width = %d, height = %d, bpp = %d\n",
921 v4l2_info(&vpfe_dev->v4l2_dev,
"adjusted width = %d, height ="
922 " %d, bpp = %d, bytesperline = %d, sizeimage = %d\n",
928 static int vpfe_querycap(
struct file *file,
void *
priv,
931 struct vpfe_device *vpfe_dev = video_drvdata(file);
935 cap->
version = VPFE_CAPTURE_VERSION_CODE;
943 static int vpfe_g_fmt_vid_cap(
struct file *file,
void *
priv,
946 struct vpfe_device *vpfe_dev = video_drvdata(file);
949 v4l2_dbg(1,
debug, &vpfe_dev->v4l2_dev,
"vpfe_g_fmt_vid_cap\n");
951 *fmt = vpfe_dev->
fmt;
955 static int vpfe_enum_fmt_vid_cap(
struct file *file,
void *
priv,
958 struct vpfe_device *vpfe_dev = video_drvdata(file);
959 const struct vpfe_pixel_format *pix_fmt;
963 v4l2_dbg(1,
debug, &vpfe_dev->v4l2_dev,
"vpfe_enum_fmt_vid_cap\n");
965 if (ccdc_dev->hw_ops.enum_pix(&pix, fmt->
index) < 0)
969 pix_fmt = vpfe_lookup_pix_format(pix);
970 if (
NULL != pix_fmt) {
971 temp_index = fmt->
index;
972 *fmt = pix_fmt->fmtdesc;
973 fmt->
index = temp_index;
979 static int vpfe_s_fmt_vid_cap(
struct file *file,
void *priv,
982 struct vpfe_device *vpfe_dev = video_drvdata(file);
983 const struct vpfe_pixel_format *pix_fmts;
986 v4l2_dbg(1,
debug, &vpfe_dev->v4l2_dev,
"vpfe_s_fmt_vid_cap\n");
989 if (vpfe_dev->started) {
990 v4l2_err(&vpfe_dev->v4l2_dev,
"Streaming is started\n");
995 pix_fmts = vpfe_check_format(vpfe_dev, &fmt->
fmt.
pix);
997 if (
NULL == pix_fmts)
1006 vpfe_detach_irq(vpfe_dev);
1007 vpfe_dev->fmt = *
fmt;
1009 ret = vpfe_config_ccdc_image_format(vpfe_dev);
1014 static int vpfe_try_fmt_vid_cap(
struct file *file,
void *priv,
1017 struct vpfe_device *vpfe_dev = video_drvdata(file);
1018 const struct vpfe_pixel_format *pix_fmts;
1020 v4l2_dbg(1,
debug, &vpfe_dev->v4l2_dev,
"vpfe_try_fmt_vid_cap\n");
1022 pix_fmts = vpfe_check_format(vpfe_dev, &f->
fmt.
pix);
1023 if (
NULL == pix_fmts)
1032 static int vpfe_get_subdev_input_index(
struct vpfe_device *vpfe_dev,
1034 int *subdev_input_index,
1035 int app_input_index)
1037 struct vpfe_config *
cfg = vpfe_dev->cfg;
1038 struct vpfe_subdev_info *sdinfo;
1041 for (i = 0; i < cfg->num_subdevs; i++) {
1042 sdinfo = &cfg->sub_devs[
i];
1043 if (app_input_index < (j + sdinfo->num_inputs)) {
1045 *subdev_input_index = app_input_index -
j;
1048 j += sdinfo->num_inputs;
1058 static int vpfe_get_app_input_index(
struct vpfe_device *vpfe_dev,
1059 int *app_input_index)
1061 struct vpfe_config *cfg = vpfe_dev->cfg;
1062 struct vpfe_subdev_info *sdinfo;
1065 for (i = 0; i < cfg->num_subdevs; i++) {
1066 sdinfo = &cfg->sub_devs[
i];
1067 if (!
strcmp(sdinfo->name, vpfe_dev->current_subdev->name)) {
1068 if (vpfe_dev->current_input >= sdinfo->num_inputs)
1070 *app_input_index = j + vpfe_dev->current_input;
1073 j += sdinfo->num_inputs;
1078 static int vpfe_enum_input(
struct file *file,
void *priv,
1081 struct vpfe_device *vpfe_dev = video_drvdata(file);
1082 struct vpfe_subdev_info *sdinfo;
1085 v4l2_dbg(1,
debug, &vpfe_dev->v4l2_dev,
"vpfe_enum_input\n");
1087 if (vpfe_get_subdev_input_index(vpfe_dev,
1091 v4l2_err(&vpfe_dev->v4l2_dev,
"input information not found"
1092 " for the subdev\n");
1095 sdinfo = &vpfe_dev->cfg->sub_devs[
subdev];
1100 static int vpfe_g_input(
struct file *file,
void *priv,
unsigned int *index)
1102 struct vpfe_device *vpfe_dev = video_drvdata(file);
1106 return vpfe_get_app_input_index(vpfe_dev, index);
1110 static int vpfe_s_input(
struct file *file,
void *priv,
unsigned int index)
1112 struct vpfe_device *vpfe_dev = video_drvdata(file);
1113 struct vpfe_subdev_info *sdinfo;
1114 int subdev_index, inp_index;
1115 struct vpfe_route *route;
1129 if (vpfe_dev->started) {
1130 v4l2_err(&vpfe_dev->v4l2_dev,
"Streaming is on\n");
1134 ret = vpfe_get_subdev_input_index(vpfe_dev,
1139 v4l2_err(&vpfe_dev->v4l2_dev,
"invalid input index\n");
1143 sdinfo = &vpfe_dev->cfg->sub_devs[subdev_index];
1144 route = &sdinfo->routes[inp_index];
1145 if (route && sdinfo->can_route) {
1146 input = route->input;
1151 video, s_routing, input, output, 0);
1155 "vpfe_doioctl:error in setting input in decoder\n");
1159 vpfe_dev->current_subdev = sdinfo;
1160 vpfe_dev->current_input =
index;
1161 vpfe_dev->std_index = 0;
1164 ret = ccdc_dev->hw_ops.set_hw_if_params(&sdinfo->ccdc_if_params);
1169 ret = vpfe_config_image_format(vpfe_dev,
1170 &vpfe_standards[vpfe_dev->std_index].
std_id);
1176 static int vpfe_querystd(
struct file *file,
void *priv,
v4l2_std_id *std_id)
1178 struct vpfe_device *vpfe_dev = video_drvdata(file);
1179 struct vpfe_subdev_info *sdinfo;
1185 sdinfo = vpfe_dev->current_subdev;
1190 video, querystd, std_id);
1195 static int vpfe_s_std(
struct file *file,
void *priv,
v4l2_std_id *std_id)
1197 struct vpfe_device *vpfe_dev = video_drvdata(file);
1198 struct vpfe_subdev_info *sdinfo;
1208 sdinfo = vpfe_dev->current_subdev;
1210 if (vpfe_dev->started) {
1211 v4l2_err(&vpfe_dev->v4l2_dev,
"streaming is started\n");
1217 core, s_std, *std_id);
1219 v4l2_err(&vpfe_dev->v4l2_dev,
"Failed to set standard\n");
1222 ret = vpfe_config_image_format(vpfe_dev, std_id);
1229 static int vpfe_g_std(
struct file *file,
void *priv,
v4l2_std_id *std_id)
1231 struct vpfe_device *vpfe_dev = video_drvdata(file);
1235 *std_id = vpfe_standards[vpfe_dev->std_index].
std_id;
1242 unsigned int *
count,
1246 struct vpfe_device *vpfe_dev = fh->vpfe_dev;
1248 v4l2_dbg(1,
debug, &vpfe_dev->v4l2_dev,
"vpfe_buffer_setup\n");
1249 *size = vpfe_dev->fmt.fmt.pix.sizeimage;
1251 vpfe_dev->fmt.fmt.pix.sizeimage > config_params.device_bufsize)
1252 *size = config_params.device_bufsize;
1254 if (*count < config_params.min_numbuffers)
1255 *count = config_params.min_numbuffers;
1257 "count=%d, size=%d\n", *count, *size);
1266 struct vpfe_device *vpfe_dev = fh->vpfe_dev;
1270 v4l2_dbg(1,
debug, &vpfe_dev->v4l2_dev,
"vpfe_buffer_prepare\n");
1274 vb->
width = vpfe_dev->fmt.fmt.pix.width;
1275 vb->
height = vpfe_dev->fmt.fmt.pix.height;
1276 vb->
size = vpfe_dev->fmt.fmt.pix.sizeimage;
1285 if (!
ALIGN(addr, 32))
1298 struct vpfe_device *vpfe_dev = fh->vpfe_dev;
1299 unsigned long flags;
1301 v4l2_dbg(1,
debug, &vpfe_dev->v4l2_dev,
"vpfe_buffer_queue\n");
1306 spin_unlock_irqrestore(&vpfe_dev->dma_queue_lock, flags);
1316 struct vpfe_device *vpfe_dev = fh->vpfe_dev;
1317 unsigned long flags;
1319 v4l2_dbg(1,
debug, &vpfe_dev->v4l2_dev,
"vpfe_videobuf_release\n");
1326 INIT_LIST_HEAD(&vpfe_dev->dma_queue);
1327 spin_unlock_irqrestore(&vpfe_dev->dma_queue_lock, flags);
1333 .buf_setup = vpfe_videobuf_setup,
1334 .buf_prepare = vpfe_videobuf_prepare,
1335 .buf_queue = vpfe_videobuf_queue,
1336 .buf_release = vpfe_videobuf_release,
1343 static int vpfe_reqbufs(
struct file *file,
void *priv,
1346 struct vpfe_device *vpfe_dev = video_drvdata(file);
1353 v4l2_err(&vpfe_dev->v4l2_dev,
"Invalid buffer type\n");
1361 if (vpfe_dev->io_usrs != 0) {
1362 v4l2_err(&vpfe_dev->v4l2_dev,
"Only one IO user allowed\n");
1367 vpfe_dev->memory = req_buf->
memory;
1369 &vpfe_videobuf_qops,
1373 vpfe_dev->fmt.fmt.pix.field,
1378 vpfe_dev->io_usrs = 1;
1379 INIT_LIST_HEAD(&vpfe_dev->dma_queue);
1386 static int vpfe_querybuf(
struct file *file,
void *priv,
1389 struct vpfe_device *vpfe_dev = video_drvdata(file);
1394 v4l2_err(&vpfe_dev->v4l2_dev,
"Invalid buf type\n");
1399 v4l2_err(&vpfe_dev->v4l2_dev,
"Invalid memory\n");
1406 static int vpfe_qbuf(
struct file *file,
void *priv,
1409 struct vpfe_device *vpfe_dev = video_drvdata(file);
1415 v4l2_err(&vpfe_dev->v4l2_dev,
"Invalid buf type\n");
1423 if (!fh->io_allowed) {
1424 v4l2_err(&vpfe_dev->v4l2_dev,
"fh->io_allowed\n");
1430 static int vpfe_dqbuf(
struct file *file,
void *priv,
1433 struct vpfe_device *vpfe_dev = video_drvdata(file);
1438 v4l2_err(&vpfe_dev->v4l2_dev,
"Invalid buf type\n");
1445 static int vpfe_queryctrl(
struct file *file,
void *priv,
1448 struct vpfe_device *vpfe_dev = video_drvdata(file);
1449 struct vpfe_subdev_info *sdinfo;
1451 sdinfo = vpfe_dev->current_subdev;
1454 core, queryctrl, qctrl);
1458 static int vpfe_g_ctrl(
struct file *file,
void *priv,
struct v4l2_control *
ctrl)
1460 struct vpfe_device *vpfe_dev = video_drvdata(file);
1461 struct vpfe_subdev_info *sdinfo;
1463 sdinfo = vpfe_dev->current_subdev;
1466 core, g_ctrl, ctrl);
1469 static int vpfe_s_ctrl(
struct file *file,
void *priv,
struct v4l2_control *
ctrl)
1471 struct vpfe_device *vpfe_dev = video_drvdata(file);
1472 struct vpfe_subdev_info *sdinfo;
1474 sdinfo = vpfe_dev->current_subdev;
1477 core, s_ctrl, ctrl);
1484 static void vpfe_calculate_offsets(
struct vpfe_device *vpfe_dev)
1488 v4l2_dbg(1,
debug, &vpfe_dev->v4l2_dev,
"vpfe_calculate_offsets\n");
1490 ccdc_dev->hw_ops.get_image_window(&image_win);
1491 vpfe_dev->field_off = image_win.height * image_win.width;
1495 static void vpfe_start_ccdc_capture(
struct vpfe_device *vpfe_dev)
1497 ccdc_dev->hw_ops.enable(1);
1498 if (ccdc_dev->hw_ops.enable_out_to_sdram)
1499 ccdc_dev->hw_ops.enable_out_to_sdram(1);
1500 vpfe_dev->started = 1;
1508 static int vpfe_streamon(
struct file *file,
void *priv,
1511 struct vpfe_device *vpfe_dev = video_drvdata(file);
1513 struct vpfe_subdev_info *sdinfo;
1520 v4l2_err(&vpfe_dev->v4l2_dev,
"Invalid buf type\n");
1525 if (!fh->io_allowed) {
1526 v4l2_err(&vpfe_dev->v4l2_dev,
"fh->io_allowed\n");
1530 sdinfo = vpfe_dev->current_subdev;
1532 video, s_stream, 1);
1535 v4l2_err(&vpfe_dev->v4l2_dev,
"stream on failed in subdev\n");
1540 if (list_empty(&vpfe_dev->buffer_queue.stream)) {
1541 v4l2_err(&vpfe_dev->v4l2_dev,
"buffer queue is empty\n");
1555 vpfe_dev->next_frm =
list_entry(vpfe_dev->dma_queue.next,
1557 vpfe_dev->cur_frm = vpfe_dev->next_frm;
1559 list_del(&vpfe_dev->cur_frm->queue);
1563 vpfe_dev->field_id = 0;
1567 vpfe_calculate_offsets(vpfe_dev);
1569 if (vpfe_attach_irq(vpfe_dev) < 0) {
1571 "Error in attaching interrupt handle\n");
1575 if (ccdc_dev->hw_ops.configure() < 0) {
1577 "Error in configuring ccdc\n");
1581 ccdc_dev->hw_ops.setfbaddr((
unsigned long)(addr));
1582 vpfe_start_ccdc_capture(vpfe_dev);
1592 static int vpfe_streamoff(
struct file *file,
void *priv,
1595 struct vpfe_device *vpfe_dev = video_drvdata(file);
1597 struct vpfe_subdev_info *sdinfo;
1600 v4l2_dbg(1,
debug, &vpfe_dev->v4l2_dev,
"vpfe_streamoff\n");
1603 v4l2_err(&vpfe_dev->v4l2_dev,
"Invalid buf type\n");
1608 if (!fh->io_allowed) {
1609 v4l2_err(&vpfe_dev->v4l2_dev,
"fh->io_allowed\n");
1614 if (!vpfe_dev->started) {
1615 v4l2_err(&vpfe_dev->v4l2_dev,
"device started\n");
1623 vpfe_stop_ccdc_capture(vpfe_dev);
1624 vpfe_detach_irq(vpfe_dev);
1626 sdinfo = vpfe_dev->current_subdev;
1628 video, s_stream, 0);
1631 v4l2_err(&vpfe_dev->v4l2_dev,
"stream off failed in subdev\n");
1637 static int vpfe_cropcap(
struct file *file,
void *priv,
1640 struct vpfe_device *vpfe_dev = video_drvdata(file);
1644 if (vpfe_dev->std_index >=
ARRAY_SIZE(vpfe_standards))
1650 vpfe_standards[vpfe_dev->std_index].
width;
1652 vpfe_standards[vpfe_dev->std_index].
height;
1657 static int vpfe_g_crop(
struct file *file,
void *priv,
1660 struct vpfe_device *vpfe_dev = video_drvdata(file);
1664 crop->
c = vpfe_dev->crop;
1668 static int vpfe_s_crop(
struct file *file,
void *priv,
1671 struct vpfe_device *vpfe_dev = video_drvdata(file);
1677 if (vpfe_dev->started) {
1680 "Cannot change crop when streaming is ON\n");
1688 if (rect.
top < 0 || rect.
left < 0) {
1690 "doesn't support negative values for top & left\n");
1700 vpfe_dev->std_info.active_pixels) ||
1702 vpfe_dev->std_info.active_lines)) {
1703 v4l2_err(&vpfe_dev->v4l2_dev,
"Error in S_CROP params\n");
1707 ccdc_dev->hw_ops.set_image_window(&rect);
1708 vpfe_dev->fmt.fmt.pix.width = rect.
width;
1709 vpfe_dev->fmt.fmt.pix.height = rect.
height;
1710 vpfe_dev->fmt.fmt.pix.bytesperline =
1711 ccdc_dev->hw_ops.get_line_length();
1712 vpfe_dev->fmt.fmt.pix.sizeimage =
1713 vpfe_dev->fmt.fmt.pix.bytesperline *
1714 vpfe_dev->fmt.fmt.pix.height;
1715 vpfe_dev->crop = rect;
1722 static long vpfe_param_handler(
struct file *file,
void *priv,
1723 bool valid_prio,
int cmd,
void *
param)
1725 struct vpfe_device *vpfe_dev = video_drvdata(file);
1728 v4l2_dbg(2,
debug, &vpfe_dev->v4l2_dev,
"vpfe_param_handler\n");
1730 if (vpfe_dev->started) {
1733 "device already started\n");
1744 "VPFE_CMD_S_CCDC_RAW_PARAMS: experimental ioctl\n");
1745 if (ccdc_dev->hw_ops.set_params) {
1746 ret = ccdc_dev->hw_ops.set_params(param);
1749 "Error setting parameters in CCDC\n");
1752 ret = vpfe_get_ccdc_image_format(vpfe_dev,
1756 "Invalid image format at CCDC\n");
1762 "VPFE_CMD_S_CCDC_RAW_PARAMS not supported\n");
1776 .vidioc_querycap = vpfe_querycap,
1777 .vidioc_g_fmt_vid_cap = vpfe_g_fmt_vid_cap,
1778 .vidioc_enum_fmt_vid_cap = vpfe_enum_fmt_vid_cap,
1779 .vidioc_s_fmt_vid_cap = vpfe_s_fmt_vid_cap,
1780 .vidioc_try_fmt_vid_cap = vpfe_try_fmt_vid_cap,
1781 .vidioc_enum_input = vpfe_enum_input,
1782 .vidioc_g_input = vpfe_g_input,
1783 .vidioc_s_input = vpfe_s_input,
1784 .vidioc_querystd = vpfe_querystd,
1785 .vidioc_s_std = vpfe_s_std,
1786 .vidioc_g_std = vpfe_g_std,
1787 .vidioc_queryctrl = vpfe_queryctrl,
1788 .vidioc_g_ctrl = vpfe_g_ctrl,
1789 .vidioc_s_ctrl = vpfe_s_ctrl,
1790 .vidioc_reqbufs = vpfe_reqbufs,
1791 .vidioc_querybuf = vpfe_querybuf,
1792 .vidioc_qbuf = vpfe_qbuf,
1793 .vidioc_dqbuf = vpfe_dqbuf,
1794 .vidioc_streamon = vpfe_streamon,
1795 .vidioc_streamoff = vpfe_streamoff,
1796 .vidioc_cropcap = vpfe_cropcap,
1797 .vidioc_g_crop = vpfe_g_crop,
1798 .vidioc_s_crop = vpfe_s_crop,
1799 .vidioc_default = vpfe_param_handler,
1802 static struct vpfe_device *vpfe_initialize(
void)
1804 struct vpfe_device *vpfe_dev;
1807 if ((numbuffers > 0) &&
1808 (numbuffers < config_params.min_numbuffers))
1809 numbuffers = config_params.min_numbuffers;
1815 if (
bufsize < config_params.min_bufsize)
1816 bufsize = config_params.min_bufsize;
1818 config_params.numbuffers = numbuffers;
1821 config_params.device_bufsize =
bufsize;
1824 vpfe_dev = kzalloc(
sizeof(*vpfe_dev),
GFP_KERNEL);
1836 struct vpfe_subdev_info *sdinfo;
1837 struct vpfe_config *vpfe_cfg;
1839 struct vpfe_device *vpfe_dev;
1843 int num_subdevs = 0;
1846 vpfe_dev = vpfe_initialize();
1850 "Failed to allocate memory for vpfe_dev\n");
1854 vpfe_dev->pdev = &pdev->
dev;
1856 if (
NULL == pdev->
dev.platform_data) {
1857 v4l2_err(pdev->
dev.driver,
"Unable to get vpfe config\n");
1859 goto probe_free_dev_mem;
1862 vpfe_cfg = pdev->
dev.platform_data;
1863 vpfe_dev->cfg = vpfe_cfg;
1864 if (
NULL == vpfe_cfg->ccdc ||
1865 NULL == vpfe_cfg->card_name ||
1866 NULL == vpfe_cfg->sub_devs) {
1867 v4l2_err(pdev->
dev.driver,
"null ptr in vpfe_cfg\n");
1869 goto probe_free_dev_mem;
1874 if (
NULL == ccdc_cfg) {
1876 "Memory allocation failed for ccdc_cfg\n");
1877 goto probe_free_lock;
1887 "Unable to get interrupt for VINT0\n");
1889 goto probe_free_ccdc_cfg_mem;
1891 vpfe_dev->ccdc_irq0 = res1->
start;
1897 "Unable to get interrupt for VINT1\n");
1899 goto probe_free_ccdc_cfg_mem;
1901 vpfe_dev->ccdc_irq1 = res1->
start;
1904 "vpfe_capture0", vpfe_dev);
1907 v4l2_err(pdev->
dev.driver,
"Unable to request interrupt\n");
1908 goto probe_free_ccdc_cfg_mem;
1915 v4l2_err(pdev->
dev.driver,
"Unable to alloc video device\n");
1916 goto probe_out_release_irq;
1921 vfd->
fops = &vpfe_fops;
1925 vfd->
v4l2_dev = &vpfe_dev->v4l2_dev;
1929 (VPFE_CAPTURE_VERSION_CODE >> 16) & 0xff,
1930 (VPFE_CAPTURE_VERSION_CODE >> 8) & 0xff,
1931 (VPFE_CAPTURE_VERSION_CODE) & 0xff);
1933 vpfe_dev->video_dev = vfd;
1938 "Unable to register v4l2 device.\n");
1939 goto probe_out_video_release;
1941 v4l2_info(&vpfe_dev->v4l2_dev,
"v4l2 device registered\n");
1947 vpfe_dev->numbuffers = config_params.numbuffers;
1953 "trying to register vpfe device.\n");
1955 "video_dev=%x\n", (
int)&vpfe_dev->video_dev);
1957 ret = video_register_device(vpfe_dev->video_dev,
1962 "Unable to register video device.\n");
1963 goto probe_out_v4l2_unregister;
1966 v4l2_info(&vpfe_dev->v4l2_dev,
"video device registered\n");
1968 platform_set_drvdata(pdev, vpfe_dev);
1970 video_set_drvdata(vpfe_dev->video_dev, vpfe_dev);
1972 num_subdevs = vpfe_cfg->num_subdevs;
1975 if (
NULL == vpfe_dev->sd) {
1977 "unable to allocate memory for subdevice pointers\n");
1979 goto probe_out_video_unregister;
1982 for (i = 0; i < num_subdevs; i++) {
1985 sdinfo = &vpfe_cfg->sub_devs[
i];
1991 &sdinfo->board_info,
1993 if (vpfe_dev->sd[i]) {
1995 "v4l2 sub device %s registered\n",
1997 vpfe_dev->sd[
i]->grp_id = sdinfo->grp_id;
1999 for (j = 0; j < sdinfo->num_inputs; j++) {
2000 inps = &sdinfo->inputs[
j];
2005 "v4l2 sub device %s register fails\n",
2012 vpfe_dev->current_subdev = &vpfe_cfg->sub_devs[0];
2019 kfree(vpfe_dev->sd);
2020 probe_out_video_unregister:
2022 probe_out_v4l2_unregister:
2024 probe_out_video_release:
2025 if (!video_is_registered(vpfe_dev->video_dev))
2027 probe_out_release_irq:
2028 free_irq(vpfe_dev->ccdc_irq0, vpfe_dev);
2029 probe_free_ccdc_cfg_mem:
2043 struct vpfe_device *vpfe_dev = platform_get_drvdata(pdev);
2047 free_irq(vpfe_dev->ccdc_irq0, vpfe_dev);
2048 kfree(vpfe_dev->sd);
2056 static int vpfe_suspend(
struct device *
dev)
2061 static int vpfe_resume(
struct device *
dev)
2066 static const struct dev_pm_ops vpfe_dev_pm_ops = {
2067 .suspend = vpfe_suspend,
2068 .resume = vpfe_resume,
2075 .pm = &vpfe_dev_pm_ops,
2077 .probe = vpfe_probe,