2 * Copyright (C) 2015 Industrial Research Institute for Automation
3 * and Measurements PIAP
5 * Written by Krzysztof Ha?asa.
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License
9 * as published by the Free Software Foundation.
12 #include <linux/delay.h>
13 #include <linux/freezer.h>
14 #include <linux/interrupt.h>
15 #include <linux/kthread.h>
16 #include <linux/mutex.h>
17 #include <linux/pci.h>
18 #include <media/videobuf2-dma-sg.h>
19 #include <linux/videodev2.h>
20 #include <media/v4l2-common.h>
21 #include <media/v4l2-ctrls.h>
22 #include <media/v4l2-device.h>
23 #include <media/v4l2-ioctl.h>
25 #define TYPE_MAX_CHANNELS 0x0F
26 #define TYPE_SECOND_GEN 0x10
28 struct tw686x_format
{
42 __le32 flags_length
; /* 3 MSBits for flags, 13 LSBits for length */
46 struct tw686x_vb2_buf
{
47 struct vb2_v4l2_buffer vb
;
48 struct list_head list
;
51 struct tw686x_video_channel
{
52 struct tw686x_dev
*dev
;
54 struct vb2_queue vidq
;
55 struct list_head vidq_queued
;
56 struct video_device
*device
;
57 struct dma_desc sg_tables
[2];
58 struct tw686x_vb2_buf
*curr_bufs
[2];
59 struct vdma_desc
*sg_descs
[2];
61 struct v4l2_ctrl_handler ctrl_handler
;
62 const struct tw686x_format
*format
;
63 struct mutex vb_mutex
;
65 v4l2_std_id video_standard
;
66 unsigned int width
, height
;
67 enum v4l2_field field
; /* supported TOP, BOTTOM, SEQ_TB and SEQ_BT */
68 unsigned int seq
; /* video field or frame counter */
72 /* global device status */
76 struct v4l2_device v4l2_dev
;
77 struct snd_card
*card
; /* sound card */
79 unsigned int video_active
; /* active video channel mask */
83 struct pci_dev
*pci_dev
;
86 struct task_struct
*video_thread
;
87 wait_queue_head_t video_thread_wait
;
90 struct tw686x_video_channel video_channels
[0];
93 static inline uint32_t reg_read(struct tw686x_dev
*dev
, unsigned int reg
)
95 return readl(dev
->mmio
+ reg
);
98 static inline void reg_write(struct tw686x_dev
*dev
, unsigned int reg
,
101 writel(value
, dev
->mmio
+ reg
);
104 static inline unsigned int max_channels(struct tw686x_dev
*dev
)
106 return dev
->type
& TYPE_MAX_CHANNELS
; /* 4 or 8 channels */
109 static inline unsigned int is_second_gen(struct tw686x_dev
*dev
)
111 /* each channel has its own DMA SG table */
112 return dev
->type
& TYPE_SECOND_GEN
;
115 int tw686x_kh_video_irq(struct tw686x_dev
*dev
);
116 int tw686x_kh_video_init(struct tw686x_dev
*dev
);
117 void tw686x_kh_video_free(struct tw686x_dev
*dev
);