1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * zoran - Iomega Buz driver
5 * Copyright (C) 1999 Rainer Johanni <Rainer@Johanni.de>
9 * zoran.0.0.3 Copyright (C) 1998 Dave Perks <dperks@ibm.net>
13 * bttv - Bt848 frame grabber driver
14 * Copyright (C) 1996,97,98 Ralph Metzler (rjkm@thp.uni-koeln.de)
15 * & Marcus Metzler (mocm@thp.uni-koeln.de)
21 #include <linux/debugfs.h>
22 #include <media/v4l2-device.h>
23 #include <media/v4l2-ctrls.h>
24 #include <media/videobuf2-core.h>
25 #include <media/videobuf2-v4l2.h>
26 #include <media/videobuf2-dma-contig.h>
29 #define ZR_NORM_NTSC 1
30 #define ZR_NORM_SECAM 2
33 /* common v4l buffer stuff -- must be first */
34 struct vb2_v4l2_buffer vbuf;
35 struct list_head queue;
38 static inline struct zr_buffer *vb2_to_zr_buffer(struct vb2_buffer *vb)
40 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
42 return container_of(vbuf, struct zr_buffer, vbuf);
45 #define ZORAN_NAME "ZORAN" /* name of the device */
47 #define ZR_DEVNAME(zr) ((zr)->name)
49 #define BUZ_MAX_WIDTH (zr->timing->wa)
50 #define BUZ_MAX_HEIGHT (zr->timing->ha)
51 #define BUZ_MIN_WIDTH 32 /* never display less than 32 pixels */
52 #define BUZ_MIN_HEIGHT 24 /* never display less than 24 rows */
54 #define BUZ_NUM_STAT_COM 4
55 #define BUZ_MASK_STAT_COM 3
57 #define BUZ_MAX_INPUT 16
65 DC10_OLD, /* DC30 like */
66 DC10_NEW, /* DC10_PLUS like */
71 /* Linux Media Labs */
81 /* total number of cards */
85 enum zoran_codec_mode {
86 BUZ_MODE_IDLE, /* nothing going on */
87 BUZ_MODE_MOTION_COMPRESS, /* grabbing frames */
88 BUZ_MODE_MOTION_DECOMPRESS, /* playing frames */
89 BUZ_MODE_STILL_COMPRESS, /* still frame conversion */
90 BUZ_MODE_STILL_DECOMPRESS /* still frame conversion */
96 ZORAN_MAP_MODE_JPG_REC,
97 ZORAN_MAP_MODE_JPG_PLAY,
101 ZR_GPIO_JPEG_SLEEP = 0,
118 struct zoran_format {
128 #define ZORAN_FORMAT_COMPRESSED BIT(0)
129 #define ZORAN_FORMAT_OVERLAY BIT(1)
130 #define ZORAN_FORMAT_CAPTURE BIT(2)
131 #define ZORAN_FORMAT_PLAYBACK BIT(3)
133 /* v4l-capture settings */
134 struct zoran_v4l_settings {
135 int width, height, bytesperline; /* capture size */
136 const struct zoran_format *format; /* capture format */
139 /* jpg-capture/-playback settings */
140 struct zoran_jpg_settings {
141 int decimation; /* this bit is used to set everything to default */
142 int hor_dcm, ver_dcm, tmp_dcm; /* capture decimation settings (tmp_dcm=1 means both fields) */
143 int field_per_buff, odd_even; /* field-settings (odd_even=1 (+tmp_dcm=1) means top-field-first) */
144 int img_x, img_y, img_width, img_height; /* crop settings (subframe capture) */
145 struct v4l2_jpegcompression jpg_comp; /* JPEG-specific capture settings */
150 /* zoran_fh contains per-open() settings */
159 const char *i2c_decoder; /* i2c decoder device */
160 const unsigned short *addrs_decoder;
161 const char *i2c_encoder; /* i2c encoder device */
162 const unsigned short *addrs_encoder;
163 u16 video_vfe, video_codec; /* videocodec types */
164 u16 audio_chip; /* audio type */
166 int inputs; /* number of video inputs */
170 } input[BUZ_MAX_INPUT];
173 const struct tvnorm *tvn[3]; /* supported TV norms */
175 u32 jpeg_int; /* JPEG interrupt */
176 u32 vsync_int; /* VSYNC interrupt */
177 s8 gpio[ZR_GPIO_MAX];
180 struct vfe_polarity vfe_pol;
181 u8 gpio_pol[ZR_GPIO_MAX];
183 /* is the /GWS line connected? */
184 u8 gws_not_connected;
186 /* avs6eyes mux setting */
189 void (*init)(struct zoran *zr);
193 struct v4l2_device v4l2_dev;
194 struct v4l2_ctrl_handler hdl;
195 struct video_device *video_dev;
198 struct i2c_adapter i2c_adapter; /* */
199 struct i2c_algo_bit_data i2c_algo; /* */
202 struct v4l2_subdev *decoder; /* video decoder sub-device */
203 struct v4l2_subdev *encoder; /* video encoder sub-device */
205 struct videocodec *codec; /* video codec */
206 struct videocodec *vfe; /* video front end */
208 struct mutex lock; /* file ops serialize lock */
210 u8 initialized; /* flag if zoran has been correctly initialized */
211 struct card_info card;
212 const struct tvnorm *timing;
214 unsigned short id; /* number of this device */
215 char name[32]; /* name of this device */
216 struct pci_dev *pci_dev; /* PCI device */
217 unsigned char revision; /* revision of zr36057 */
218 unsigned char __iomem *zr36057_mem;/* pointer to mapped IO memory */
220 spinlock_t spinlock; /* Spinlock */
222 /* Video for Linux parameters */
223 int input; /* card's norm and input */
226 /* Current buffer params */
227 unsigned int buffer_size;
229 struct zoran_v4l_settings v4l_settings; /* structure with a lot of things to play with */
231 /* Buz MJPEG parameters */
232 enum zoran_codec_mode codec_mode; /* status of codec */
233 struct zoran_jpg_settings jpg_settings; /* structure with a lot of things to play with */
235 /* grab queue counts/indices, mask with BUZ_MASK_STAT_COM before using as index */
236 /* (dma_head - dma_tail) is number active in DMA, must be <= BUZ_NUM_STAT_COM */
237 /* (value & BUZ_MASK_STAT_COM) corresponds to index in stat_com table */
238 unsigned long jpg_que_head; /* Index where to put next buffer which is queued */
239 unsigned long jpg_dma_head; /* Index of next buffer which goes into stat_com */
240 unsigned long jpg_dma_tail; /* Index of last buffer in stat_com */
241 unsigned long jpg_que_tail; /* Index of last buffer in queue */
242 unsigned long jpg_seq_num; /* count of frames since grab/play started */
243 unsigned long jpg_err_seq; /* last seq_num before error */
244 unsigned long jpg_err_shift;
245 unsigned long jpg_queued_num; /* count of frames queued since grab/play started */
248 /* zr36057's code buffer table */
249 __le32 *stat_com; /* stat_com[i] is indexed by dma_head/tail & BUZ_MASK_STAT_COM */
251 /* Additional stuff for testing */
252 unsigned int ghost_int;
253 int intr_counter_GIRQ1;
254 int intr_counter_GIRQ0;
255 int intr_counter_cod_rep_irq;
256 int intr_counter_jpeg_rep_irq;
264 int end_event_missed;
270 unsigned int prepared;
274 unsigned long frame_num;
281 enum zoran_map_mode map_mode;
282 struct list_head queued_bufs;
283 spinlock_t queued_bufs_lock; /* Protects queued_bufs */
284 struct zr_buffer *inuse[BUZ_NUM_STAT_COM * 2];
285 struct dentry *dbgfs_dir;
288 static inline struct zoran *to_zoran(struct v4l2_device *v4l2_dev)
290 return container_of(v4l2_dev, struct zoran, v4l2_dev);
293 /* There was something called _ALPHA_BUZ that used the PCI address instead of
294 * the kernel iomapped address for btread/btwrite. */
295 #define btwrite(dat, adr) writel((dat), zr->zr36057_mem + (adr))
296 #define btread(adr) readl(zr->zr36057_mem + (adr))
298 #define btand(dat, adr) btwrite((dat) & btread(adr), adr)
299 #define btor(dat, adr) btwrite((dat) | btread(adr), adr)
300 #define btaor(dat, mask, adr) btwrite((dat) | ((mask) & btread(adr)), adr)
304 int zoran_queue_init(struct zoran *zr, struct vb2_queue *vq, int dir);
305 void zoran_queue_exit(struct zoran *zr);
306 int zr_set_buf(struct zoran *zr);