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 <linux/pci.h>
23 #include <linux/i2c-algo-bit.h>
24 #include <media/v4l2-device.h>
25 #include <media/v4l2-ctrls.h>
26 #include <media/videobuf2-core.h>
27 #include <media/videobuf2-v4l2.h>
28 #include <media/videobuf2-dma-contig.h>
31 #define ZR_NORM_NTSC 1
32 #define ZR_NORM_SECAM 2
35 /* common v4l buffer stuff -- must be first */
36 struct vb2_v4l2_buffer vbuf
;
37 struct list_head queue
;
40 static inline struct zr_buffer
*vb2_to_zr_buffer(struct vb2_buffer
*vb
)
42 struct vb2_v4l2_buffer
*vbuf
= to_vb2_v4l2_buffer(vb
);
44 return container_of(vbuf
, struct zr_buffer
, vbuf
);
47 #define ZORAN_NAME "ZORAN" /* name of the device */
49 #define ZR_DEVNAME(zr) ((zr)->name)
51 #define BUZ_MAX_WIDTH (zr->timing->wa)
52 #define BUZ_MAX_HEIGHT (zr->timing->ha)
53 #define BUZ_MIN_WIDTH 32 /* never display less than 32 pixels */
54 #define BUZ_MIN_HEIGHT 24 /* never display less than 24 rows */
56 #define BUZ_NUM_STAT_COM 4
57 #define BUZ_MASK_STAT_COM 3
59 #define BUZ_MAX_INPUT 16
67 DC10_OLD
, /* DC30 like */
68 DC10_NEW
, /* DC10_PLUS like */
73 /* Linux Media Labs */
83 /* total number of cards */
87 enum zoran_codec_mode
{
88 BUZ_MODE_IDLE
, /* nothing going on */
89 BUZ_MODE_MOTION_COMPRESS
, /* grabbing frames */
90 BUZ_MODE_MOTION_DECOMPRESS
, /* playing frames */
91 BUZ_MODE_STILL_COMPRESS
, /* still frame conversion */
92 BUZ_MODE_STILL_DECOMPRESS
/* still frame conversion */
98 ZORAN_MAP_MODE_JPG_REC
,
99 ZORAN_MAP_MODE_JPG_PLAY
,
103 ZR_GPIO_JPEG_SLEEP
= 0,
120 struct zoran_format
{
130 #define ZORAN_FORMAT_COMPRESSED BIT(0)
131 #define ZORAN_FORMAT_OVERLAY BIT(1)
132 #define ZORAN_FORMAT_CAPTURE BIT(2)
133 #define ZORAN_FORMAT_PLAYBACK BIT(3)
135 /* v4l-capture settings */
136 struct zoran_v4l_settings
{
137 int width
, height
, bytesperline
; /* capture size */
138 const struct zoran_format
*format
; /* capture format */
141 /* jpg-capture/-playback settings */
142 struct zoran_jpg_settings
{
143 /* this bit is used to set everything to default */
145 /* capture decimation settings (tmp_dcm=1 means both fields) */
146 int hor_dcm
, ver_dcm
, tmp_dcm
;
147 /* field-settings (odd_even=1 (+tmp_dcm=1) means top-field-first) */
148 int field_per_buff
, odd_even
;
149 /* crop settings (subframe capture) */
150 int img_x
, img_y
, img_width
, img_height
;
151 /* JPEG-specific capture settings */
152 struct v4l2_jpegcompression jpg_comp
;
157 /* zoran_fh contains per-open() settings */
166 const char *i2c_decoder
; /* i2c decoder device */
167 const unsigned short *addrs_decoder
;
168 const char *i2c_encoder
; /* i2c encoder device */
169 const unsigned short *addrs_encoder
;
170 u16 video_vfe
, video_codec
; /* videocodec types */
171 u16 audio_chip
; /* audio type */
173 int inputs
; /* number of video inputs */
177 } input
[BUZ_MAX_INPUT
];
180 const struct tvnorm
*tvn
[3]; /* supported TV norms */
182 u32 jpeg_int
; /* JPEG interrupt */
183 u32 vsync_int
; /* VSYNC interrupt */
184 s8 gpio
[ZR_GPIO_MAX
];
187 struct vfe_polarity vfe_pol
;
188 u8 gpio_pol
[ZR_GPIO_MAX
];
190 /* is the /GWS line connected? */
191 u8 gws_not_connected
;
193 /* avs6eyes mux setting */
196 void (*init
)(struct zoran
*zr
);
200 struct v4l2_device v4l2_dev
;
201 struct v4l2_ctrl_handler hdl
;
202 struct video_device
*video_dev
;
205 struct i2c_adapter i2c_adapter
; /* */
206 struct i2c_algo_bit_data i2c_algo
; /* */
209 struct v4l2_subdev
*decoder
; /* video decoder sub-device */
210 struct v4l2_subdev
*encoder
; /* video encoder sub-device */
212 struct videocodec
*codec
; /* video codec */
213 struct videocodec
*vfe
; /* video front end */
215 struct mutex lock
; /* file ops serialize lock */
217 u8 initialized
; /* flag if zoran has been correctly initialized */
218 struct card_info card
;
219 const struct tvnorm
*timing
;
221 unsigned short id
; /* number of this device */
222 char name
[40]; /* name of this device */
223 struct pci_dev
*pci_dev
; /* PCI device */
224 unsigned char revision
; /* revision of zr36057 */
225 unsigned char __iomem
*zr36057_mem
;/* pointer to mapped IO memory */
227 spinlock_t spinlock
; /* Spinlock */
229 /* Video for Linux parameters */
230 int input
; /* card's norm and input */
233 /* Current buffer params */
234 unsigned int buffer_size
;
236 struct zoran_v4l_settings v4l_settings
; /* structure with a lot of things to play with */
238 /* Buz MJPEG parameters */
239 enum zoran_codec_mode codec_mode
; /* status of codec */
240 struct zoran_jpg_settings jpg_settings
; /* structure with a lot of things to play with */
242 /* grab queue counts/indices, mask with BUZ_MASK_STAT_COM before using as index */
243 /* (dma_head - dma_tail) is number active in DMA, must be <= BUZ_NUM_STAT_COM */
244 /* (value & BUZ_MASK_STAT_COM) corresponds to index in stat_com table */
245 unsigned long jpg_que_head
; /* Index where to put next buffer which is queued */
246 unsigned long jpg_dma_head
; /* Index of next buffer which goes into stat_com */
247 unsigned long jpg_dma_tail
; /* Index of last buffer in stat_com */
248 unsigned long jpg_que_tail
; /* Index of last buffer in queue */
249 unsigned long jpg_seq_num
; /* count of frames since grab/play started */
250 unsigned long jpg_err_seq
; /* last seq_num before error */
251 unsigned long jpg_err_shift
;
252 unsigned long jpg_queued_num
; /* count of frames queued since grab/play started */
255 /* zr36057's code buffer table */
256 /* stat_com[i] is indexed by dma_head/tail & BUZ_MASK_STAT_COM */
259 /* Additional stuff for testing */
260 unsigned int ghost_int
;
261 int intr_counter_GIRQ1
;
262 int intr_counter_GIRQ0
;
263 int intr_counter_cod_rep_irq
;
264 int intr_counter_jpeg_rep_irq
;
272 int end_event_missed
;
278 unsigned int prepared
;
282 unsigned long frame_num
;
289 enum zoran_map_mode map_mode
;
290 struct list_head queued_bufs
;
291 spinlock_t queued_bufs_lock
; /* Protects queued_bufs */
292 struct zr_buffer
*inuse
[BUZ_NUM_STAT_COM
* 2];
293 struct dentry
*dbgfs_dir
;
296 static inline struct zoran
*to_zoran(struct v4l2_device
*v4l2_dev
)
298 return container_of(v4l2_dev
, struct zoran
, v4l2_dev
);
302 * There was something called _ALPHA_BUZ that used the PCI address instead of
303 * the kernel iomapped address for btread/btwrite.
305 #define btwrite(dat, adr) writel((dat), zr->zr36057_mem + (adr))
306 #define btread(adr) readl(zr->zr36057_mem + (adr))
308 #define btand(dat, adr) btwrite((dat) & btread(adr), (adr))
309 #define btor(dat, adr) btwrite((dat) | btread(adr), (adr))
310 #define btaor(dat, mask, adr) btwrite((dat) | ((mask) & btread(adr)), (adr))
317 #define zrdev_dbg(zr, format, args...) \
318 pci_dbg((zr)->pci_dev, format, ##args) \
320 #define zrdev_err(zr, format, args...) \
321 pci_err((zr)->pci_dev, format, ##args) \
323 #define zrdev_info(zr, format, args...) \
324 pci_info((zr)->pci_dev, format, ##args) \
326 int zoran_queue_init(struct zoran *zr, struct vb2_queue *vq, int dir);
327 void zoran_queue_exit(struct zoran
*zr
);
328 int zr_set_buf(struct zoran
*zr
);