blob: 6284a90d6fe3f0389ca868e4549ce99d6bbcdd9e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
/*
* Copyright (C) 2015 Industrial Research Institute for Automation
* and Measurements PIAP
*
* Written by Krzysztof Ha?asa.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License
* as published by the Free Software Foundation.
*/
#include <linux/delay.h>
#include <linux/freezer.h>
#include <linux/interrupt.h>
#include <linux/kthread.h>
#include <linux/mutex.h>
#include <linux/pci.h>
#include <media/videobuf2-dma-sg.h>
#include <linux/videodev2.h>
#include <media/v4l2-common.h>
#include <media/v4l2-ctrls.h>
#include <media/v4l2-device.h>
#include <media/v4l2-ioctl.h>
#define TYPE_MAX_CHANNELS 0x0F
#define TYPE_SECOND_GEN 0x10
struct tw686x_format {
char *name;
unsigned int fourcc;
unsigned int depth;
unsigned int mode;
};
struct dma_desc {
dma_addr_t phys;
void *virt;
unsigned int size;
};
struct vdma_desc {
__le32 flags_length; /* 3 MSBits for flags, 13 LSBits for length */
__le32 phys;
};
struct tw686x_vb2_buf {
struct vb2_v4l2_buffer vb;
struct list_head list;
};
struct tw686x_video_channel {
struct tw686x_dev *dev;
struct vb2_queue vidq;
struct list_head vidq_queued;
struct video_device *device;
struct dma_desc sg_tables[2];
struct tw686x_vb2_buf *curr_bufs[2];
struct vdma_desc *sg_descs[2];
struct v4l2_ctrl_handler ctrl_handler;
const struct tw686x_format *format;
struct mutex vb_mutex;
spinlock_t qlock;
v4l2_std_id video_standard;
unsigned int width, height;
enum v4l2_field field; /* supported TOP, BOTTOM, SEQ_TB and SEQ_BT */
unsigned int seq; /* video field or frame counter */
unsigned int ch;
};
/* global device status */
struct tw686x_dev {
spinlock_t irq_lock;
struct v4l2_device v4l2_dev;
struct snd_card *card; /* sound card */
unsigned int video_active; /* active video channel mask */
char name[32];
unsigned int type;
struct pci_dev *pci_dev;
__u32 __iomem *mmio;
struct task_struct *video_thread;
wait_queue_head_t video_thread_wait;
u32 dma_requests;
struct tw686x_video_channel video_channels[0];
};
static inline uint32_t reg_read(struct tw686x_dev *dev, unsigned int reg)
{
return readl(dev->mmio + reg);
}
static inline void reg_write(struct tw686x_dev *dev, unsigned int reg,
uint32_t value)
{
writel(value, dev->mmio + reg);
}
static inline unsigned int max_channels(struct tw686x_dev *dev)
{
return dev->type & TYPE_MAX_CHANNELS; /* 4 or 8 channels */
}
static inline unsigned int is_second_gen(struct tw686x_dev *dev)
{
/* each channel has its own DMA SG table */
return dev->type & TYPE_SECOND_GEN;
}
int tw686x_kh_video_irq(struct tw686x_dev *dev);
int tw686x_kh_video_init(struct tw686x_dev *dev);
void tw686x_kh_video_free(struct tw686x_dev *dev);
|