]> asedeno.scripts.mit.edu Git - linux.git/blob - drivers/staging/media/tw686x-kh/tw686x-kh.h
Merge tag 'pstore-v4.8' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux
[linux.git] / drivers / staging / media / tw686x-kh / tw686x-kh.h
1 /*
2  * Copyright (C) 2015 Industrial Research Institute for Automation
3  * and Measurements PIAP
4  *
5  * Written by Krzysztof Ha?asa.
6  *
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.
10  */
11
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>
24
25 #define TYPE_MAX_CHANNELS 0x0F
26 #define TYPE_SECOND_GEN   0x10
27
28 struct tw686x_format {
29         char *name;
30         unsigned int fourcc;
31         unsigned int depth;
32         unsigned int mode;
33 };
34
35 struct dma_desc {
36         dma_addr_t phys;
37         void *virt;
38         unsigned int size;
39 };
40
41 struct vdma_desc {
42         __le32 flags_length;    /* 3 MSBits for flags, 13 LSBits for length */
43         __le32 phys;
44 };
45
46 struct tw686x_vb2_buf {
47         struct vb2_v4l2_buffer vb;
48         struct list_head list;
49 };
50
51 struct tw686x_video_channel {
52         struct tw686x_dev *dev;
53
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         void *alloc_ctx;
60         struct vdma_desc *sg_descs[2];
61
62         struct v4l2_ctrl_handler ctrl_handler;
63         const struct tw686x_format *format;
64         struct mutex vb_mutex;
65         spinlock_t qlock;
66         v4l2_std_id video_standard;
67         unsigned int width, height;
68         enum v4l2_field field; /* supported TOP, BOTTOM, SEQ_TB and SEQ_BT */
69         unsigned int seq;              /* video field or frame counter */
70         unsigned int ch;
71 };
72
73 /* global device status */
74 struct tw686x_dev {
75         spinlock_t irq_lock;
76
77         struct v4l2_device v4l2_dev;
78         struct snd_card *card;  /* sound card */
79
80         unsigned int video_active;      /* active video channel mask */
81
82         char name[32];
83         unsigned int type;
84         struct pci_dev *pci_dev;
85         __u32 __iomem *mmio;
86
87         struct task_struct *video_thread;
88         wait_queue_head_t video_thread_wait;
89         u32 dma_requests;
90
91         struct tw686x_video_channel video_channels[0];
92 };
93
94 static inline uint32_t reg_read(struct tw686x_dev *dev, unsigned int reg)
95 {
96         return readl(dev->mmio + reg);
97 }
98
99 static inline void reg_write(struct tw686x_dev *dev, unsigned int reg,
100                              uint32_t value)
101 {
102         writel(value, dev->mmio + reg);
103 }
104
105 static inline unsigned int max_channels(struct tw686x_dev *dev)
106 {
107         return dev->type & TYPE_MAX_CHANNELS; /* 4 or 8 channels */
108 }
109
110 static inline unsigned int is_second_gen(struct tw686x_dev *dev)
111 {
112         /* each channel has its own DMA SG table */
113         return dev->type & TYPE_SECOND_GEN;
114 }
115
116 int tw686x_kh_video_irq(struct tw686x_dev *dev);
117 int tw686x_kh_video_init(struct tw686x_dev *dev);
118 void tw686x_kh_video_free(struct tw686x_dev *dev);