13 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/errno.h>
18 #include <linux/string.h>
19 #include <linux/wait.h>
20 #include <linux/time.h>
25 #include <linux/videodev2.h>
26 #include <linux/slab.h>
28 #include <asm/pgtable.h>
29 #include <mach/cputype.h>
42 #define VPBE_DISPLAY_DRIVER "vpbe-v4l2"
46 #define VPBE_DEFAULT_NUM_BUFS 3
50 static int venc_is_second_field(
struct vpbe_display *disp_dev)
63 "Error in getting Field ID 0\n");
68 static void vpbe_isr_even_field(
struct vpbe_display *disp_obj,
76 layer->
cur_frm->ts.tv_sec = timevalue.tv_sec;
84 static void vpbe_isr_odd_field(
struct vpbe_display *disp_obj,
112 osd_device->
ops.start_layer(osd_device,
123 static unsigned last_event;
131 if (venc_is_second_field(disp_dev))
152 layer = disp_dev->
dev[
i];
166 vpbe_isr_even_field(disp_dev, layer);
167 vpbe_isr_odd_field(disp_dev, layer);
191 vpbe_isr_even_field(disp_dev, layer);
193 vpbe_isr_odd_field(disp_dev, layer);
217 "vpbe_buffer_prepare\n");
238 "buffer_prepare:offset is \
239 not aligned to 32 bytes\n");
263 *size = layer->
pix_fmt.sizeimage;
287 "vpbe_buffer_queue\n");
311 "vpbe_buffer_release\n");
320 .buf_setup = vpbe_buffer_setup,
321 .buf_prepare = vpbe_buffer_prepare,
322 .buf_queue = vpbe_buffer_queue,
323 .buf_release = vpbe_buffer_release,
328 _vpbe_display_get_other_win_layer(
struct vpbe_display *disp_dev,
336 return disp_dev->
dev[otherwin];
339 static int vpbe_set_osd_display_params(
struct vpbe_display *disp_dev,
350 osd_device->
ops.start_layer(osd_device,
355 ret = osd_device->
ops.enable_layer(osd_device,
359 "Error in enabling osd window layer 0\n");
367 _vpbe_display_get_other_win_layer(disp_dev, layer);
369 ret = osd_device->
ops.enable_layer(osd_device,
373 "Error in enabling osd window layer 1\n");
382 vpbe_disp_calculate_scale_factor(
struct vpbe_display *disp_dev,
384 int expected_xsize,
int expected_ysize)
390 int calculated_xsize;
422 if (pixfmt->
width < expected_xsize) {
426 else if (h_scale >= 4)
430 cfg->
xsize *= h_scale;
431 if (cfg->
xsize < expected_xsize) {
434 calculated_xsize = (cfg->
xsize *
437 if (calculated_xsize <= expected_xsize) {
439 cfg->
xsize = calculated_xsize;
445 else if (h_scale == 4)
451 cfg->
xsize = expected_xsize;
454 if (pixfmt->
height < expected_ysize) {
455 v_scale = expected_ysize / pixfmt->
height;
458 else if (v_scale >= 4)
462 cfg->
ysize *= v_scale;
463 if (cfg->
ysize < expected_ysize) {
464 if ((standard_id & V4L2_STD_625_50)) {
465 calculated_xsize = (cfg->
ysize *
468 if (calculated_xsize <= expected_ysize) {
470 cfg->
ysize = calculated_xsize;
476 else if (v_scale == 4)
482 cfg->
ysize = expected_ysize;
485 "crop display xsize = %d, ysize = %d\n",
489 static void vpbe_disp_adj_position(
struct vpbe_display *disp_dev,
496 cfg->
xpos =
min((
unsigned int)left,
498 cfg->
ypos =
min((
unsigned int)top,
502 "new xpos = %d, ypos = %d\n",
506 static void vpbe_disp_check_window_params(
struct vpbe_display *disp_dev,
511 if ((c->
width == 0) ||
531 static int vpbe_try_format(
struct vpbe_display *disp_dev,
568 if (!pixfmt->
width || (pixfmt->
width < min_width) ||
569 (pixfmt->
width > max_width)) {
574 (pixfmt->
height > max_height)) {
593 static int vpbe_display_g_priority(
struct file *
file,
void *
priv,
604 static int vpbe_display_s_priority(
struct file *
file,
void *
priv,
616 static int vpbe_display_querycap(
struct file *
file,
void *
priv,
631 static int vpbe_display_s_crop(
struct file *
file,
void *
priv,
644 "VIDIOC_S_CROP, layer id = %d\n", layer->
device_id);
656 vpbe_disp_check_window_params(disp_dev, &rect);
658 osd_device->
ops.get_layer_config(osd_device,
661 vpbe_disp_calculate_scale_factor(disp_dev, layer,
664 vpbe_disp_adj_position(disp_dev, layer, rect.
top,
666 ret = osd_device->
ops.set_layer_config(osd_device,
670 "Error in set layer config:\n");
675 osd_device->
ops.set_zoom(osd_device,
679 ret = osd_device->
ops.set_vid_expansion(osd_device,
684 "Error in set vid expansion:\n");
693 osd_device->
ops.set_interpolation_filter(osd_device, 1);
695 osd_device->
ops.set_interpolation_filter(osd_device, 0);
700 static int vpbe_display_g_crop(
struct file *file,
void *priv,
712 "VIDIOC_G_CROP, layer id = %d\n",
719 osd_device->
ops.get_layer_config(osd_device,
729 static int vpbe_display_cropcap(
struct file *file,
void *priv,
747 static int vpbe_display_g_fmt(
struct file *file,
void *priv,
755 "VIDIOC_G_FMT, layer id = %d\n",
769 static int vpbe_display_enum_fmt(
struct file *file,
void *priv,
775 unsigned int index = 0;
778 "VIDIOC_ENUM_FMT, layer id = %d\n",
780 if (fmt->
index > 1) {
787 memset(fmt, 0,
sizeof(*fmt));
801 static int vpbe_display_s_fmt(
struct file *file,
void *priv,
814 "VIDIOC_S_FMT, layer id = %d\n",
827 ret = vpbe_try_format(disp_dev, pixfmt, 1);
837 osd_device->
ops.get_layer_config(osd_device,
854 otherlayer = _vpbe_display_get_other_win_layer(disp_dev,
860 ret = osd_device->
ops.set_layer_config(osd_device,
864 "Error in S_FMT params:\n");
869 osd_device->
ops.get_layer_config(osd_device,
875 static int vpbe_display_try_fmt(
struct file *file,
void *priv,
891 return vpbe_try_format(disp_dev, pixfmt, 0);
901 static int vpbe_display_s_std(
struct file *file,
void *priv,
916 if (
NULL != vpbe_dev->
ops.s_std) {
917 ret = vpbe_dev->
ops.s_std(vpbe_dev, std_id);
920 "Failed to set standard for sub devices\n");
936 static int vpbe_display_g_std(
struct file *file,
void *priv,
959 static int vpbe_display_enum_output(
struct file *file,
void *priv,
970 if (
NULL == vpbe_dev->
ops.enum_outputs)
973 ret = vpbe_dev->
ops.enum_outputs(vpbe_dev, output);
976 "Failed to enumerate outputs\n");
987 static int vpbe_display_s_output(
struct file *file,
void *priv,
1001 if (
NULL == vpbe_dev->
ops.set_output)
1004 ret = vpbe_dev->
ops.set_output(vpbe_dev, i);
1007 "Failed to set output for sub devices\n");
1018 static int vpbe_display_g_output(
struct file *file,
void *priv,
1038 vpbe_display_enum_dv_timings(
struct file *file,
void *priv,
1048 if (
NULL == vpbe_dev->
ops.enum_dv_timings)
1051 ret = vpbe_dev->
ops.enum_dv_timings(vpbe_dev, timings);
1054 "Failed to enumerate dv timings info\n");
1068 vpbe_display_s_dv_timings(
struct file *file,
void *priv,
1086 if (!vpbe_dev->
ops.s_dv_timings)
1089 ret = vpbe_dev->
ops.s_dv_timings(vpbe_dev, timings);
1092 "Failed to set the dv timings info\n");
1110 vpbe_display_g_dv_timings(
struct file *file,
void *priv,
1130 static int vpbe_display_streamoff(
struct file *file,
void *priv,
1140 "VIDIOC_STREAMOFF,layer id = %d\n",
1161 osd_device->
ops.disable_layer(osd_device,
1169 static int vpbe_display_streamon(
struct file *file,
void *priv,
1179 osd_device->
ops.disable_layer(osd_device,
1208 "error in videobuf_streamon\n");
1227 ret = vpbe_set_osd_display_params(disp_dev, layer);
1245 static int vpbe_display_dqbuf(
struct file *file,
void *priv,
1254 "VIDIOC_DQBUF, layer id = %d\n",
1276 static int vpbe_display_qbuf(
struct file *file,
void *priv,
1284 "VIDIOC_QBUF, layer id = %d\n",
1301 static int vpbe_display_querybuf(
struct file *file,
void *priv,
1310 "VIDIOC_QUERYBUF, layer id = %d\n",
1324 static int vpbe_display_reqbufs(
struct file *file,
void *priv,
1372 static int vpbe_display_mmap(
struct file *filep,
struct vm_area_struct *vma)
1391 static unsigned int vpbe_display_poll(
struct file *filep,
poll_table *
wait)
1396 unsigned int err = 0;
1412 static int vpbe_display_open(
struct file *file)
1415 struct vpbe_layer *layer = video_drvdata(file);
1425 "unable to allocate memory for file handle object\n");
1429 "vpbe display open plane = %d\n",
1441 err = osd_device->
ops.request_layer(osd_device,
1447 "Display Manager failed to allocate layer\n");
1460 "vpbe display device opened successfully\n");
1469 static int vpbe_display_release(
struct file *file)
1487 osd_device->
ops.disable_layer(osd_device,
1502 _vpbe_display_get_other_win_layer(disp_dev, layer);
1503 osd_device->
ops.disable_layer(osd_device,
1505 osd_device->
ops.release_layer(osd_device,
1508 osd_device->
ops.disable_layer(osd_device,
1510 osd_device->
ops.release_layer(osd_device,
1526 #ifdef CONFIG_VIDEO_ADV_DEBUG
1527 static int vpbe_display_g_register(
struct file *file,
void *priv,
1534 if (match->
type >= 2) {
1544 static int vpbe_display_s_register(
struct file *file,
void *priv,
1553 .vidioc_querycap = vpbe_display_querycap,
1554 .vidioc_g_fmt_vid_out = vpbe_display_g_fmt,
1555 .vidioc_enum_fmt_vid_out = vpbe_display_enum_fmt,
1556 .vidioc_s_fmt_vid_out = vpbe_display_s_fmt,
1557 .vidioc_try_fmt_vid_out = vpbe_display_try_fmt,
1558 .vidioc_reqbufs = vpbe_display_reqbufs,
1559 .vidioc_querybuf = vpbe_display_querybuf,
1560 .vidioc_qbuf = vpbe_display_qbuf,
1561 .vidioc_dqbuf = vpbe_display_dqbuf,
1562 .vidioc_streamon = vpbe_display_streamon,
1563 .vidioc_streamoff = vpbe_display_streamoff,
1564 .vidioc_cropcap = vpbe_display_cropcap,
1565 .vidioc_g_crop = vpbe_display_g_crop,
1566 .vidioc_s_crop = vpbe_display_s_crop,
1567 .vidioc_g_priority = vpbe_display_g_priority,
1568 .vidioc_s_priority = vpbe_display_s_priority,
1569 .vidioc_s_std = vpbe_display_s_std,
1570 .vidioc_g_std = vpbe_display_g_std,
1571 .vidioc_enum_output = vpbe_display_enum_output,
1572 .vidioc_s_output = vpbe_display_s_output,
1573 .vidioc_g_output = vpbe_display_g_output,
1574 .vidioc_s_dv_timings = vpbe_display_s_dv_timings,
1575 .vidioc_g_dv_timings = vpbe_display_g_dv_timings,
1576 .vidioc_enum_dv_timings = vpbe_display_enum_dv_timings,
1577 #ifdef CONFIG_VIDEO_ADV_DEBUG
1578 .vidioc_g_register = vpbe_display_g_register,
1579 .vidioc_s_register = vpbe_display_s_register,
1585 .open = vpbe_display_open,
1586 .release = vpbe_display_release,
1588 .mmap = vpbe_display_mmap,
1589 .poll = vpbe_display_poll
1597 if (
strcmp(
"vpbe_controller", pdev->
name) == 0)
1598 vpbe_disp->
vpbe_dev = platform_get_drvdata(pdev);
1601 vpbe_disp->
osd_device = platform_get_drvdata(pdev);
1618 if (!disp_dev->
dev[i]) {
1626 vpbe_display_layer = disp_dev->
dev[
i];
1630 vbd->
fops = &vpbe_fops;
1637 if (disp_dev->
vpbe_dev->current_timings.timings_type &
1641 disp_dev->
vpbe_dev->current_timings.std_id;
1646 "DaVinci_VPBE Display_DRIVER_V%d.%d.%d",
1668 "Trying to register VPBE display device.\n");
1670 "layer=%x,layer->video_dev=%x\n",
1671 (
int)vpbe_display_layer,
1674 err = video_register_device(&vpbe_display_layer->
video_dev,
1680 vpbe_display_layer->
disp_dev = disp_dev;
1682 platform_set_drvdata(pdev, disp_dev);
1683 video_set_drvdata(&vpbe_display_layer->
video_dev,
1684 vpbe_display_layer);
1725 err = disp_dev->
vpbe_dev->ops.initialize(&pdev->
dev,
1729 "Error initing vpbe\n");
1736 if (init_vpbe_layer(i, disp_dev, pdev)) {
1745 "Unable to get VENC interrupt resource\n");
1754 "Unable to request interrupt\n");
1760 if (register_device(disp_dev->
dev[i], disp_dev, pdev)) {
1766 printk(
KERN_DEBUG "Successfully completed the probing of vpbe v4l2 device\n");
1774 vpbe_display_layer = disp_dev->
dev[
k];
1776 if (vpbe_display_layer) {
1793 struct vpbe_display *disp_dev = platform_get_drvdata(pdev);
1805 if (
NULL != vpbe_dev->
ops.deinitialize)
1806 vpbe_dev->
ops.deinitialize(&pdev->
dev, vpbe_dev);
1810 vpbe_display_layer = disp_dev->
dev[
i];
1829 .probe = vpbe_display_probe,