linux/drivers/staging/media/zoran/zoran.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: GPL-2.0-or-later */
   2/*
   3 * zoran - Iomega Buz driver
   4 *
   5 * Copyright (C) 1999 Rainer Johanni <Rainer@Johanni.de>
   6 *
   7 * based on
   8 *
   9 * zoran.0.0.3 Copyright (C) 1998 Dave Perks <dperks@ibm.net>
  10 *
  11 * and
  12 *
  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)
  16 */
  17
  18#ifndef _BUZ_H_
  19#define _BUZ_H_
  20
  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>
  26
  27#define ZR_NORM_PAL 0
  28#define ZR_NORM_NTSC 1
  29#define ZR_NORM_SECAM 2
  30
  31struct zr_buffer {
  32        /* common v4l buffer stuff -- must be first */
  33        struct vb2_v4l2_buffer          vbuf;
  34        struct list_head                queue;
  35};
  36
  37static inline struct zr_buffer *vb2_to_zr_buffer(struct vb2_buffer *vb)
  38{
  39        struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
  40
  41        return container_of(vbuf, struct zr_buffer, vbuf);
  42}
  43
  44#define ZORAN_NAME    "ZORAN"   /* name of the device */
  45
  46#define ZR_DEVNAME(zr) ((zr)->name)
  47
  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 */
  52
  53#define BUZ_NUM_STAT_COM    4
  54#define BUZ_MASK_STAT_COM   3
  55
  56#define BUZ_MAX_FRAME     256   /* Must be a power of 2 */
  57#define BUZ_MASK_FRAME    255   /* Must be BUZ_MAX_FRAME-1 */
  58
  59#define BUZ_MAX_INPUT       16
  60
  61#if VIDEO_MAX_FRAME <= 32
  62#   define   V4L_MAX_FRAME   32
  63#elif VIDEO_MAX_FRAME <= 64
  64#   define   V4L_MAX_FRAME   64
  65#else
  66#   error   "Too many video frame buffers to handle"
  67#endif
  68#define   V4L_MASK_FRAME   (V4L_MAX_FRAME - 1)
  69
  70#define MAX_FRAME (BUZ_MAX_FRAME > VIDEO_MAX_FRAME ? BUZ_MAX_FRAME : VIDEO_MAX_FRAME)
  71
  72#include "zr36057.h"
  73
  74enum card_type {
  75        UNKNOWN = -1,
  76
  77        /* Pinnacle/Miro */
  78        DC10_OLD,               /* DC30 like */
  79        DC10_NEW,               /* DC10_PLUS like */
  80        DC10_PLUS,
  81        DC30,
  82        DC30_PLUS,
  83
  84        /* Linux Media Labs */
  85        LML33,
  86        LML33R10,
  87
  88        /* Iomega */
  89        BUZ,
  90
  91        /* AverMedia */
  92        AVS6EYES,
  93
  94        /* total number of cards */
  95        NUM_CARDS
  96};
  97
  98enum 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 */
 104};
 105
 106enum zoran_map_mode {
 107        ZORAN_MAP_MODE_NONE,
 108        ZORAN_MAP_MODE_RAW,
 109        ZORAN_MAP_MODE_JPG_REC,
 110        ZORAN_MAP_MODE_JPG_PLAY,
 111};
 112
 113enum gpio_type {
 114        ZR_GPIO_JPEG_SLEEP = 0,
 115        ZR_GPIO_JPEG_RESET,
 116        ZR_GPIO_JPEG_FRAME,
 117        ZR_GPIO_VID_DIR,
 118        ZR_GPIO_VID_EN,
 119        ZR_GPIO_VID_RESET,
 120        ZR_GPIO_CLK_SEL1,
 121        ZR_GPIO_CLK_SEL2,
 122        ZR_GPIO_MAX,
 123};
 124
 125enum gpcs_type {
 126        GPCS_JPEG_RESET = 0,
 127        GPCS_JPEG_START,
 128        GPCS_MAX,
 129};
 130
 131struct zoran_format {
 132        char *name;
 133        __u32 fourcc;
 134        int colorspace;
 135        int depth;
 136        __u32 flags;
 137        __u32 vfespfr;
 138};
 139
 140/* flags */
 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)
 145
 146/* v4l-capture settings */
 147struct zoran_v4l_settings {
 148        int width, height, bytesperline;        /* capture size */
 149        const struct zoran_format *format;      /* capture format */
 150};
 151
 152/* jpg-capture/-playback settings */
 153struct 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 */
 159};
 160
 161struct zoran;
 162
 163/* zoran_fh contains per-open() settings */
 164struct zoran_fh {
 165        struct v4l2_fh fh;
 166        struct zoran *zr;
 167};
 168
 169struct card_info {
 170        enum card_type type;
 171        char name[32];
 172        const char *i2c_decoder;        /* i2c decoder device */
 173        const unsigned short *addrs_decoder;
 174        const char *i2c_encoder;        /* i2c encoder device */
 175        const unsigned short *addrs_encoder;
 176        u16 video_vfe, video_codec;                     /* videocodec types */
 177        u16 audio_chip;                                 /* audio type */
 178
 179        int inputs;             /* number of video inputs */
 180        struct input {
 181                int muxsel;
 182                char name[32];
 183        } input[BUZ_MAX_INPUT];
 184
 185        v4l2_std_id norms;
 186        const struct tvnorm *tvn[3];    /* supported TV norms */
 187
 188        u32 jpeg_int;           /* JPEG interrupt */
 189        u32 vsync_int;          /* VSYNC interrupt */
 190        s8 gpio[ZR_GPIO_MAX];
 191        u8 gpcs[GPCS_MAX];
 192
 193        struct vfe_polarity vfe_pol;
 194        u8 gpio_pol[ZR_GPIO_MAX];
 195
 196        /* is the /GWS line connected? */
 197        u8 gws_not_connected;
 198
 199        /* avs6eyes mux setting */
 200        u8 input_mux;
 201
 202        void (*init)(struct zoran *zr);
 203};
 204
 205struct zoran {
 206        struct v4l2_device v4l2_dev;
 207        struct v4l2_ctrl_handler hdl;
 208        struct video_device *video_dev;
 209        struct vb2_queue vq;
 210
 211        struct i2c_adapter i2c_adapter; /* */
 212        struct i2c_algo_bit_data i2c_algo;      /* */
 213        u32 i2cbr;
 214
 215        struct v4l2_subdev *decoder;    /* video decoder sub-device */
 216        struct v4l2_subdev *encoder;    /* video encoder sub-device */
 217
 218        struct videocodec *codec;       /* video codec */
 219        struct videocodec *vfe; /* video front end */
 220
 221        struct mutex lock;      /* file ops serialize lock */
 222
 223        u8 initialized;         /* flag if zoran has been correctly initialized */
 224        struct card_info card;
 225        const struct tvnorm *timing;
 226
 227        unsigned short id;      /* number of this device */
 228        char name[32];          /* name of this device */
 229        struct pci_dev *pci_dev;        /* PCI device */
 230        unsigned char revision; /* revision of zr36057 */
 231        unsigned char __iomem *zr36057_mem;/* pointer to mapped IO memory */
 232
 233        spinlock_t spinlock;    /* Spinlock */
 234
 235        /* Video for Linux parameters */
 236        int input;      /* card's norm and input */
 237        v4l2_std_id norm;
 238
 239        /* Current buffer params */
 240        unsigned int buffer_size;
 241
 242        struct zoran_v4l_settings v4l_settings; /* structure with a lot of things to play with */
 243
 244        /* Buz MJPEG parameters */
 245        enum zoran_codec_mode codec_mode;       /* status of codec */
 246        struct zoran_jpg_settings jpg_settings; /* structure with a lot of things to play with */
 247
 248        /* grab queue counts/indices, mask with BUZ_MASK_STAT_COM before using as index */
 249        /* (dma_head - dma_tail) is number active in DMA, must be <= BUZ_NUM_STAT_COM */
 250        /* (value & BUZ_MASK_STAT_COM) corresponds to index in stat_com table */
 251        unsigned long jpg_que_head;     /* Index where to put next buffer which is queued */
 252        unsigned long jpg_dma_head;     /* Index of next buffer which goes into stat_com */
 253        unsigned long jpg_dma_tail;     /* Index of last buffer in stat_com */
 254        unsigned long jpg_que_tail;     /* Index of last buffer in queue */
 255        unsigned long jpg_seq_num;      /* count of frames since grab/play started */
 256        unsigned long jpg_err_seq;      /* last seq_num before error */
 257        unsigned long jpg_err_shift;
 258        unsigned long jpg_queued_num;   /* count of frames queued since grab/play started */
 259        unsigned long vbseq;
 260
 261        /* zr36057's code buffer table */
 262        __le32 *stat_com;               /* stat_com[i] is indexed by dma_head/tail & BUZ_MASK_STAT_COM */
 263
 264        /* Additional stuff for testing */
 265        unsigned int ghost_int;
 266        int intr_counter_GIRQ1;
 267        int intr_counter_GIRQ0;
 268        int intr_counter_cod_rep_irq;
 269        int intr_counter_jpeg_rep_irq;
 270        int field_counter;
 271        int irq1_in;
 272        int irq1_out;
 273        int jpeg_in;
 274        int jpeg_out;
 275        int JPEG_0;
 276        int JPEG_1;
 277        int end_event_missed;
 278        int jpeg_missed;
 279        int jpeg_error;
 280        int num_errors;
 281        int jpeg_max_missed;
 282        int jpeg_min_missed;
 283        unsigned int prepared;
 284        unsigned int queued;
 285
 286        u32 last_isr;
 287        unsigned long frame_num;
 288        int running;
 289        int buf_in_reserve;
 290
 291        dma_addr_t p_sc;
 292        __le32 *stat_comb;
 293        dma_addr_t p_scb;
 294        enum zoran_map_mode map_mode;
 295        struct list_head queued_bufs;
 296        spinlock_t queued_bufs_lock; /* Protects queued_bufs */
 297        struct zr_buffer *inuse[BUZ_NUM_STAT_COM * 2];
 298};
 299
 300static inline struct zoran *to_zoran(struct v4l2_device *v4l2_dev)
 301{
 302        return container_of(v4l2_dev, struct zoran, v4l2_dev);
 303}
 304
 305/* There was something called _ALPHA_BUZ that used the PCI address instead of
 306 * the kernel iomapped address for btread/btwrite.  */
 307#define btwrite(dat, adr)    writel((dat), zr->zr36057_mem + (adr))
 308#define btread(adr)         readl(zr->zr36057_mem + (adr))
 309
 310#define btand(dat, adr)      btwrite((dat) & btread(adr), adr)
 311#define btor(dat, adr)       btwrite((dat) | btread(adr), adr)
 312#define btaor(dat, mask, adr) btwrite((dat) | ((mask) & btread(adr)), adr)
 313
 314#endif
 315
 316int zoran_queue_init(struct zoran *zr, struct vb2_queue *vq);
 317void zoran_queue_exit(struct zoran *zr);
 318int zr_set_buf(struct zoran *zr);
 319