2 * tw68 driver common header file
4 * Much of this code is derived from the cx88 and sa7134 drivers, which
5 * were in turn derived from the bt87x driver. The original work was by
6 * Gerd Knorr; more recently the code was enhanced by Mauro Carvalho Chehab,
7 * Hans Verkuil, Andy Walls and many others. Their work is gratefully
8 * acknowledged. Full credit goes to them - any problems within this code
11 * Copyright (C) 2009 William M. Brack
13 * Refactored and updated to the latest v4l core frameworks:
15 * Copyright (C) 2014 Hans Verkuil <hverkuil@xs4all.nl>
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
28 #include <linux/pci.h>
29 #include <linux/videodev2.h>
30 #include <linux/notifier.h>
31 #include <linux/delay.h>
32 #include <linux/mutex.h>
35 #include <media/v4l2-common.h>
36 #include <media/v4l2-ioctl.h>
37 #include <media/v4l2-ctrls.h>
38 #include <media/v4l2-device.h>
39 #include <media/videobuf2-v4l2.h>
40 #include <media/videobuf2-dma-sg.h>
46 #define TW68_NORMS ( \
47 V4L2_STD_NTSC | V4L2_STD_PAL | V4L2_STD_SECAM | \
48 V4L2_STD_PAL_M | V4L2_STD_PAL_Nc | V4L2_STD_PAL_60)
50 #define TW68_VID_INTS (TW68_FFERR | TW68_PABORT | TW68_DMAPERR | \
51 TW68_FFOF | TW68_DMAPI)
52 /* TW6800 chips have trouble with these, so we don't set them for that chip */
53 #define TW68_VID_INTSX (TW68_FDMIS | TW68_HLOCK | TW68_VLOCK)
55 #define TW68_I2C_INTS (TW68_SBERR | TW68_SBDONE | TW68_SBERR2 | \
58 enum tw68_decoder_type
{
65 /* ----------------------------------------------------------- */
82 u32 h_delay0
; /* for TW6800 */
92 /* Techwell specific */
103 /* ----------------------------------------------------------- */
104 /* card configuration */
106 #define TW68_BOARD_NOAUTO UNSET
107 #define TW68_BOARD_UNKNOWN 0
108 #define TW68_BOARD_GENERIC_6802 1
110 #define TW68_MAXBOARDS 16
111 #define TW68_INPUT_MAX 4
113 /* ----------------------------------------------------------- */
114 /* device / file handle status */
116 #define BUFFER_TIMEOUT msecs_to_jiffies(500) /* 0.5 seconds */
118 struct tw68_dev
; /* forward delclaration */
120 /* buffer for one video/vbi/ts frame */
122 struct vb2_v4l2_buffer vb
;
123 struct list_head list
;
133 u32 fourcc
; /* v4l2 format id */
139 /* global device status */
144 struct v4l2_device v4l2_dev
;
146 /* various device info */
147 enum tw68_decoder_type vdecoder
;
148 struct video_device vdev
;
149 struct v4l2_ctrl_handler hdl
;
154 unsigned char pci_rev
, pci_lat
;
158 /* The irq mask to be used will depend upon the chip type */
162 const struct tw68_format
*fmt
;
163 unsigned width
, height
;
166 struct vb2_queue vidq
;
167 struct list_head active
;
170 /* various v4l controls */
171 const struct tw68_tvnorm
*tvnorm
; /* video */
176 /* ----------------------------------------------------------- */
178 #define tw_readl(reg) readl(dev->lmmio + ((reg) >> 2))
179 #define tw_readb(reg) readb(dev->bmmio + (reg))
180 #define tw_writel(reg, value) writel((value), dev->lmmio + ((reg) >> 2))
181 #define tw_writeb(reg, value) writeb((value), dev->bmmio + (reg))
183 #define tw_andorl(reg, mask, value) \
184 writel((readl(dev->lmmio+((reg)>>2)) & ~(mask)) |\
185 ((value) & (mask)), dev->lmmio+((reg)>>2))
186 #define tw_andorb(reg, mask, value) \
187 writeb((readb(dev->bmmio + (reg)) & ~(mask)) |\
188 ((value) & (mask)), dev->bmmio+(reg))
189 #define tw_setl(reg, bit) tw_andorl((reg), (bit), (bit))
190 #define tw_setb(reg, bit) tw_andorb((reg), (bit), (bit))
191 #define tw_clearl(reg, bit) \
192 writel((readl(dev->lmmio + ((reg) >> 2)) & ~(bit)), \
193 dev->lmmio + ((reg) >> 2))
194 #define tw_clearb(reg, bit) \
195 writeb((readb(dev->bmmio+(reg)) & ~(bit)), \
198 #define tw_wait(us) { udelay(us); }
200 /* ----------------------------------------------------------- */
203 void tw68_set_tvnorm_hw(struct tw68_dev
*dev
);
205 int tw68_video_init1(struct tw68_dev
*dev
);
206 int tw68_video_init2(struct tw68_dev
*dev
, int video_nr
);
207 void tw68_irq_video_done(struct tw68_dev
*dev
, unsigned long status
);
208 int tw68_video_start_dma(struct tw68_dev
*dev
, struct tw68_buf
*buf
);
210 /* ----------------------------------------------------------- */
213 int tw68_risc_buffer(struct pci_dev
*pci
, struct tw68_buf
*buf
,
214 struct scatterlist
*sglist
, unsigned int top_offset
,
215 unsigned int bottom_offset
, unsigned int bpl
,
216 unsigned int padding
, unsigned int lines
);