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 <media/v4l2-device.h>
22 #include <media/v4l2-ctrls.h>
23 #include <media/videobuf2-core.h>
24 #include <media/videobuf2-v4l2.h>
25 #include <media/videobuf2-dma-contig.h>
28 #define ZR_NORM_NTSC 1
29 #define ZR_NORM_SECAM 2
32 /* common v4l buffer stuff -- must be first */
33 struct vb2_v4l2_buffer vbuf;
34 struct list_head queue;
37 static inline struct zr_buffer *vb2_to_zr_buffer(struct vb2_buffer *vb)
39 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
41 return container_of(vbuf, struct zr_buffer, vbuf);
44 #define ZORAN_NAME "ZORAN" /* name of the device */
46 #define ZR_DEVNAME(zr) ((zr)->name)
48 #define BUZ_MAX_WIDTH (zr->timing->wa)
49 #define BUZ_MAX_HEIGHT (zr->timing->ha)
50 #define BUZ_MIN_WIDTH 32 /* never display less than 32 pixels */
51 #define BUZ_MIN_HEIGHT 24 /* never display less than 24 rows */
53 #define BUZ_NUM_STAT_COM 4
54 #define BUZ_MASK_STAT_COM 3
56 #define BUZ_MAX_FRAME 256 /* Must be a power of 2 */
57 #define BUZ_MASK_FRAME 255 /* Must be BUZ_MAX_FRAME-1 */
59 #define BUZ_MAX_INPUT 16
61 #if VIDEO_MAX_FRAME <= 32
62 # define V4L_MAX_FRAME 32
63 #elif VIDEO_MAX_FRAME <= 64
64 # define V4L_MAX_FRAME 64
66 # error "Too many video frame buffers to handle"
68 #define V4L_MASK_FRAME (V4L_MAX_FRAME - 1)
70 #define MAX_FRAME (BUZ_MAX_FRAME > VIDEO_MAX_FRAME ? BUZ_MAX_FRAME : VIDEO_MAX_FRAME)
78 DC10_OLD, /* DC30 like */
79 DC10_NEW, /* DC10_PLUS like */
84 /* Linux Media Labs */
94 /* total number of cards */
98 enum zoran_codec_mode {
99 BUZ_MODE_IDLE, /* nothing going on */
100 BUZ_MODE_MOTION_COMPRESS, /* grabbing frames */
101 BUZ_MODE_MOTION_DECOMPRESS, /* playing frames */
102 BUZ_MODE_STILL_COMPRESS, /* still frame conversion */
103 BUZ_MODE_STILL_DECOMPRESS /* still frame conversion */
106 enum zoran_map_mode {
109 ZORAN_MAP_MODE_JPG_REC,
110 ZORAN_MAP_MODE_JPG_PLAY,
114 ZR_GPIO_JPEG_SLEEP = 0,
131 struct zoran_format {
141 #define ZORAN_FORMAT_COMPRESSED BIT(0)
142 #define ZORAN_FORMAT_OVERLAY BIT(1)
143 #define ZORAN_FORMAT_CAPTURE BIT(2)
144 #define ZORAN_FORMAT_PLAYBACK BIT(3)
146 /* v4l-capture settings */
147 struct zoran_v4l_settings {
148 int width, height, bytesperline; /* capture size */
149 const struct zoran_format *format; /* capture format */
152 /* jpg-capture/-playback settings */
153 struct zoran_jpg_settings {
154 int decimation; /* this bit is used to set everything to default */
155 int hor_dcm, ver_dcm, tmp_dcm; /* capture decimation settings (tmp_dcm=1 means both fields) */
156 int field_per_buff, odd_even; /* field-settings (odd_even=1 (+tmp_dcm=1) means top-field-first) */
157 int img_x, img_y, img_width, img_height; /* crop settings (subframe capture) */
158 struct v4l2_jpegcompression jpg_comp; /* JPEG-specific capture settings */
164 /* zoran_fh contains per-open() settings */
173 const char *i2c_decoder; /* i2c decoder device */
174 const unsigned short *addrs_decoder;
175 const char *i2c_encoder; /* i2c encoder device */
176 const unsigned short *addrs_encoder;
177 u16 video_vfe, video_codec; /* videocodec types */
178 u16 audio_chip; /* audio type */
180 int inputs; /* number of video inputs */
184 } input[BUZ_MAX_INPUT];
187 const struct tvnorm *tvn[3]; /* supported TV norms */
189 u32 jpeg_int; /* JPEG interrupt */
190 u32 vsync_int; /* VSYNC interrupt */
191 s8 gpio[ZR_GPIO_MAX];
194 struct vfe_polarity vfe_pol;
195 u8 gpio_pol[ZR_GPIO_MAX];
197 /* is the /GWS line connected? */
198 u8 gws_not_connected;
200 /* avs6eyes mux setting */
203 void (*init)(struct zoran *zr);
207 struct v4l2_device v4l2_dev;
208 struct v4l2_ctrl_handler hdl;
209 struct video_device *video_dev;
212 struct i2c_adapter i2c_adapter; /* */
213 struct i2c_algo_bit_data i2c_algo; /* */
216 struct v4l2_subdev *decoder; /* video decoder sub-device */
217 struct v4l2_subdev *encoder; /* video encoder sub-device */
219 struct videocodec *codec; /* video codec */
220 struct videocodec *vfe; /* video front end */
222 struct mutex lock; /* file ops serialize lock */
224 u8 initialized; /* flag if zoran has been correctly initialized */
225 struct card_info card;
226 const struct tvnorm *timing;
228 unsigned short id; /* number of this device */
229 char name[32]; /* name of this device */
230 struct pci_dev *pci_dev; /* PCI device */
231 unsigned char revision; /* revision of zr36057 */
232 unsigned char __iomem *zr36057_mem;/* pointer to mapped IO memory */
234 spinlock_t spinlock; /* Spinlock */
236 /* Video for Linux parameters */
237 int input; /* card's norm and input */
240 /* Current buffer params */
241 unsigned int buffer_size;
243 struct zoran_v4l_settings v4l_settings; /* structure with a lot of things to play with */
245 /* Buz MJPEG parameters */
246 enum zoran_codec_mode codec_mode; /* status of codec */
247 struct zoran_jpg_settings jpg_settings; /* structure with a lot of things to play with */
249 /* grab queue counts/indices, mask with BUZ_MASK_STAT_COM before using as index */
250 /* (dma_head - dma_tail) is number active in DMA, must be <= BUZ_NUM_STAT_COM */
251 /* (value & BUZ_MASK_STAT_COM) corresponds to index in stat_com table */
252 unsigned long jpg_que_head; /* Index where to put next buffer which is queued */
253 unsigned long jpg_dma_head; /* Index of next buffer which goes into stat_com */
254 unsigned long jpg_dma_tail; /* Index of last buffer in stat_com */
255 unsigned long jpg_que_tail; /* Index of last buffer in queue */
256 unsigned long jpg_seq_num; /* count of frames since grab/play started */
257 unsigned long jpg_err_seq; /* last seq_num before error */
258 unsigned long jpg_err_shift;
259 unsigned long jpg_queued_num; /* count of frames queued since grab/play started */
262 /* zr36057's code buffer table */
263 __le32 *stat_com; /* stat_com[i] is indexed by dma_head/tail & BUZ_MASK_STAT_COM */
265 /* Additional stuff for testing */
266 unsigned int ghost_int;
267 int intr_counter_GIRQ1;
268 int intr_counter_GIRQ0;
269 int intr_counter_cod_rep_irq;
270 int intr_counter_jpeg_rep_irq;
278 int end_event_missed;
284 unsigned int prepared;
288 unsigned long frame_num;
295 enum zoran_map_mode map_mode;
296 struct list_head queued_bufs;
297 spinlock_t queued_bufs_lock; /* Protects queued_bufs */
298 struct zr_buffer *inuse[BUZ_NUM_STAT_COM * 2];
301 static inline struct zoran *to_zoran(struct v4l2_device *v4l2_dev)
303 return container_of(v4l2_dev, struct zoran, v4l2_dev);
306 /* There was something called _ALPHA_BUZ that used the PCI address instead of
307 * the kernel iomapped address for btread/btwrite. */
308 #define btwrite(dat, adr) writel((dat), zr->zr36057_mem + (adr))
309 #define btread(adr) readl(zr->zr36057_mem + (adr))
311 #define btand(dat, adr) btwrite((dat) & btread(adr), adr)
312 #define btor(dat, adr) btwrite((dat) | btread(adr), adr)
313 #define btaor(dat, mask, adr) btwrite((dat) | ((mask) & btread(adr)), adr)
317 int zoran_queue_init(struct zoran *zr, struct vb2_queue *vq, int dir);
318 void zoran_queue_exit(struct zoran *zr);
319 int zr_set_buf(struct zoran *zr);