24 #include <linux/slab.h>
28 #include <linux/list.h>
29 #include <linux/i2c.h>
30 #include <linux/module.h>
36 #define DRIVER_NAME "timb-video"
38 #define TIMBLOGIWIN_NAME "Timberdale Video-In"
39 #define TIMBLOGIW_VERSION_CODE 0x04
41 #define TIMBLOGIW_LINES_PER_DESC 44
42 #define TIMBLOGIW_MAX_VIDEO_MEM 16
44 #define TIMBLOGIW_HAS_DECODER(lw) (lw->pdata.encoder.module_name)
98 return norm->
width * 2;
104 return norm->
height * timblogiw_bytes_per_line(norm);
110 for (i = 0; i <
ARRAY_SIZE(timblogiw_tvnorms); i++)
111 if (timblogiw_tvnorms[i].std & std)
112 return timblogiw_tvnorms +
i;
118 static void timblogiw_dma_cb(
void *
data)
140 if (!list_empty(&fh->
capture)) {
149 static bool timblogiw_dma_filter_fn(
struct dma_chan *
chan,
void *filter_param)
156 static int timblogiw_g_fmt(
struct file *
file,
void *
priv,
160 struct timblogiw *lw = video_get_drvdata(vdev);
173 format->
fmt.
pix.bytesperline = timblogiw_bytes_per_line(fh->
cur_norm);
182 static int timblogiw_try_fmt(
struct file *file,
void *priv,
189 "%s - width=%d, height=%d, pixelformat=%d, field=%d\n"
190 "bytes per line %d, size image: %d, colorspace: %d\n",
207 static int timblogiw_s_fmt(
struct file *file,
void *priv,
211 struct timblogiw *lw = video_get_drvdata(vdev);
218 err = timblogiw_try_fmt(file, priv, format);
223 dev_err(&vdev->
dev,
"%s queue busy\n", __func__);
236 static int timblogiw_querycap(
struct file *file,
void *priv,
242 memset(cap, 0,
sizeof(*cap));
253 static int timblogiw_enum_fmt(
struct file *file,
void *priv,
262 memset(fmt, 0,
sizeof(*fmt));
272 static int timblogiw_g_parm(
struct file *file,
void *priv,
285 static int timblogiw_reqbufs(
struct file *file,
void *priv,
296 static int timblogiw_querybuf(
struct file *file,
void *priv,
307 static int timblogiw_qbuf(
struct file *file,
void *priv,
struct v4l2_buffer *
b)
317 static int timblogiw_dqbuf(
struct file *file,
void *priv,
328 static int timblogiw_g_std(
struct file *file,
void *priv,
v4l2_std_id *std)
339 static int timblogiw_s_std(
struct file *file,
void *priv,
v4l2_std_id *std)
342 struct timblogiw *lw = video_get_drvdata(vdev);
354 fh->
cur_norm = timblogiw_get_norm(*std);
361 static int timblogiw_enuminput(
struct file *file,
void *priv,
378 for (i = 0; i <
ARRAY_SIZE(timblogiw_tvnorms); i++)
379 inp->
std |= timblogiw_tvnorms[i].
std;
384 static int timblogiw_g_input(
struct file *file,
void *priv,
396 static int timblogiw_s_input(
struct file *file,
void *priv,
unsigned int input)
407 static int timblogiw_streamon(
struct file *file,
void *priv,
unsigned int type)
415 dev_dbg(&vdev->
dev,
"%s - No capture device\n", __func__);
423 static int timblogiw_streamoff(
struct file *file,
void *priv,
437 static int timblogiw_querystd(
struct file *file,
void *priv,
v4l2_std_id *std)
440 struct timblogiw *lw = video_get_drvdata(vdev);
453 static int timblogiw_enum_framesizes(
struct file *file,
void *priv,
459 dev_dbg(&vdev->
dev,
"%s - index: %d, format: %d\n", __func__,
462 if ((fsize->
index != 0) ||
480 *size = timblogiw_frame_size(fh->
cur_norm);
513 timblogiw_bytes_per_line(fh->
cur_norm);
523 for (i = 0, size = 0; size <
data_size; i++) {
525 size += bytes_per_desc;
527 (bytes_per_desc - (size - data_size)) :
552 timblogiw_bytes_per_line(fh->
cur_norm);
554 sg_elems = timblogiw_frame_size(fh->
cur_norm) / bytes_per_desc;
556 (timblogiw_frame_size(fh->
cur_norm) % bytes_per_desc) ? 1 : 0;
567 desc = dmaengine_prep_slave_sg(fh->
chan,
572 list_del_init(&vb->
queue);
601 .buf_setup = buffer_setup,
602 .buf_prepare = buffer_prepare,
603 .buf_queue = buffer_queue,
604 .buf_release = buffer_release,
609 static int timblogiw_open(
struct file *file)
612 struct timblogiw *lw = video_get_drvdata(vdev);
633 lw->
pdata.i2c_adapter);
645 dev_err(&vdev->
dev,
"Failed to get encoder: %s\n",
646 lw->
pdata.encoder.module_name);
659 timblogiw_querystd(file, fh, &std);
660 fh->
cur_norm = timblogiw_get_norm(std);
673 dev_err(&vdev->
dev,
"Failed to get DMA channel\n");
692 static int timblogiw_close(
struct file *file)
695 struct timblogiw *lw = video_get_drvdata(vdev);
713 static ssize_t timblogiw_read(
struct file *file,
char __user *data,
714 size_t count, loff_t *ppos)
725 static unsigned int timblogiw_poll(
struct file *file,
736 static int timblogiw_mmap(
struct file *file,
struct vm_area_struct *vma)
749 .vidioc_querycap = timblogiw_querycap,
750 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
751 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
752 .vidioc_try_fmt_vid_cap = timblogiw_try_fmt,
753 .vidioc_s_fmt_vid_cap = timblogiw_s_fmt,
754 .vidioc_g_parm = timblogiw_g_parm,
755 .vidioc_reqbufs = timblogiw_reqbufs,
756 .vidioc_querybuf = timblogiw_querybuf,
757 .vidioc_qbuf = timblogiw_qbuf,
758 .vidioc_dqbuf = timblogiw_dqbuf,
759 .vidioc_g_std = timblogiw_g_std,
760 .vidioc_s_std = timblogiw_s_std,
761 .vidioc_enum_input = timblogiw_enuminput,
762 .vidioc_g_input = timblogiw_g_input,
763 .vidioc_s_input = timblogiw_s_input,
764 .vidioc_streamon = timblogiw_streamon,
765 .vidioc_streamoff = timblogiw_streamoff,
766 .vidioc_querystd = timblogiw_querystd,
767 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
772 .open = timblogiw_open,
773 .release = timblogiw_close,
775 .mmap = timblogiw_mmap,
776 .read = timblogiw_read,
777 .poll = timblogiw_poll,
782 .fops = &timblogiw_fops,
783 .ioctl_ops = &timblogiw_ioctl_ops,
801 if (!pdata->
encoder.module_name)
810 if (pdev->
dev.parent)
811 lw->
dev = pdev->
dev.parent;
828 platform_set_drvdata(pdev, lw);
833 dev_err(&pdev->
dev,
"Error reg video: %d\n", err);
841 platform_set_drvdata(pdev,
NULL);
846 dev_err(&pdev->
dev,
"Failed to register: %d\n", err);
853 struct timblogiw *lw = platform_get_drvdata(pdev);
861 platform_set_drvdata(pdev,
NULL);
871 .probe = timblogiw_probe,