Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  *  tw68 driver common header file
0004  *
0005  *  Much of this code is derived from the cx88 and sa7134 drivers, which
0006  *  were in turn derived from the bt87x driver.  The original work was by
0007  *  Gerd Knorr; more recently the code was enhanced by Mauro Carvalho Chehab,
0008  *  Hans Verkuil, Andy Walls and many others.  Their work is gratefully
0009  *  acknowledged.  Full credit goes to them - any problems within this code
0010  *  are mine.
0011  *
0012  *  Copyright (C) 2009  William M. Brack
0013  *
0014  *  Refactored and updated to the latest v4l core frameworks:
0015  *
0016  *  Copyright (C) 2014 Hans Verkuil <hverkuil@xs4all.nl>
0017  */
0018 
0019 #include <linux/pci.h>
0020 #include <linux/videodev2.h>
0021 #include <linux/notifier.h>
0022 #include <linux/delay.h>
0023 #include <linux/mutex.h>
0024 #include <linux/io.h>
0025 
0026 #include <media/v4l2-common.h>
0027 #include <media/v4l2-ioctl.h>
0028 #include <media/v4l2-ctrls.h>
0029 #include <media/v4l2-device.h>
0030 #include <media/videobuf2-v4l2.h>
0031 #include <media/videobuf2-dma-sg.h>
0032 
0033 #include "tw68-reg.h"
0034 
0035 #define UNSET   (-1U)
0036 
0037 #define TW68_NORMS ( \
0038     V4L2_STD_NTSC    | V4L2_STD_PAL       | V4L2_STD_SECAM    | \
0039     V4L2_STD_PAL_M   | V4L2_STD_PAL_Nc    | V4L2_STD_PAL_60)
0040 
0041 #define TW68_VID_INTS   (TW68_FFERR | TW68_PABORT | TW68_DMAPERR | \
0042              TW68_FFOF   | TW68_DMAPI)
0043 /* TW6800 chips have trouble with these, so we don't set them for that chip */
0044 #define TW68_VID_INTSX  (TW68_FDMIS | TW68_HLOCK | TW68_VLOCK)
0045 
0046 #define TW68_I2C_INTS   (TW68_SBERR | TW68_SBDONE | TW68_SBERR2  | \
0047              TW68_SBDONE2)
0048 
0049 enum tw68_decoder_type {
0050     TW6800,
0051     TW6801,
0052     TW6804,
0053     TWXXXX,
0054 };
0055 
0056 /* ----------------------------------------------------------- */
0057 /* static data                                                 */
0058 
0059 struct tw68_tvnorm {
0060     char        *name;
0061     v4l2_std_id id;
0062 
0063     /* video decoder */
0064     u32 sync_control;
0065     u32 luma_control;
0066     u32 chroma_ctrl1;
0067     u32 chroma_gain;
0068     u32 chroma_ctrl2;
0069     u32 vgate_misc;
0070 
0071     /* video scaler */
0072     u32 h_delay;
0073     u32 h_delay0;   /* for TW6800 */
0074     u32 h_start;
0075     u32 h_stop;
0076     u32 v_delay;
0077     u32 video_v_start;
0078     u32 video_v_stop;
0079     u32 vbi_v_start_0;
0080     u32 vbi_v_stop_0;
0081     u32 vbi_v_start_1;
0082 
0083     /* Techwell specific */
0084     u32 format;
0085 };
0086 
0087 struct tw68_format {
0088     u32 fourcc;
0089     u32 depth;
0090     u32 twformat;
0091 };
0092 
0093 /* ----------------------------------------------------------- */
0094 /* card configuration                     */
0095 
0096 #define TW68_BOARD_NOAUTO       UNSET
0097 #define TW68_BOARD_UNKNOWN      0
0098 #define TW68_BOARD_GENERIC_6802     1
0099 
0100 #define TW68_MAXBOARDS          16
0101 #define TW68_INPUT_MAX          4
0102 
0103 /* ----------------------------------------------------------- */
0104 /* device / file handle status                                 */
0105 
0106 #define BUFFER_TIMEOUT  msecs_to_jiffies(500)   /* 0.5 seconds */
0107 
0108 struct tw68_dev;    /* forward delclaration */
0109 
0110 /* buffer for one video/vbi/ts frame */
0111 struct tw68_buf {
0112     struct vb2_v4l2_buffer vb;
0113     struct list_head list;
0114 
0115     unsigned int   size;
0116     __le32         *cpu;
0117     __le32         *jmp;
0118     dma_addr_t     dma;
0119 };
0120 
0121 struct tw68_fmt {
0122     char            *name;
0123     u32         fourcc; /* v4l2 format id */
0124     int         depth;
0125     int         flags;
0126     u32         twformat;
0127 };
0128 
0129 /* global device status */
0130 struct tw68_dev {
0131     struct mutex        lock;
0132     spinlock_t      slock;
0133     u16         instance;
0134     struct v4l2_device  v4l2_dev;
0135 
0136     /* various device info */
0137     enum tw68_decoder_type  vdecoder;
0138     struct video_device vdev;
0139     struct v4l2_ctrl_handler hdl;
0140 
0141     /* pci i/o */
0142     char            *name;
0143     struct pci_dev      *pci;
0144     unsigned char       pci_rev, pci_lat;
0145     u32         __iomem *lmmio;
0146     u8          __iomem *bmmio;
0147     u32         pci_irqmask;
0148     /* The irq mask to be used will depend upon the chip type */
0149     u32         board_virqmask;
0150 
0151     /* video capture */
0152     const struct tw68_format *fmt;
0153     unsigned        width, height;
0154     unsigned        seqnr;
0155     unsigned        field;
0156     struct vb2_queue    vidq;
0157     struct list_head    active;
0158 
0159     /* various v4l controls */
0160     const struct tw68_tvnorm *tvnorm;   /* video */
0161 
0162     int         input;
0163 };
0164 
0165 /* ----------------------------------------------------------- */
0166 
0167 #define tw_readl(reg)       readl(dev->lmmio + ((reg) >> 2))
0168 #define tw_readb(reg)       readb(dev->bmmio + (reg))
0169 #define tw_writel(reg, value)   writel((value), dev->lmmio + ((reg) >> 2))
0170 #define tw_writeb(reg, value)   writeb((value), dev->bmmio + (reg))
0171 
0172 #define tw_andorl(reg, mask, value) \
0173         writel((readl(dev->lmmio+((reg)>>2)) & ~(mask)) |\
0174         ((value) & (mask)), dev->lmmio+((reg)>>2))
0175 #define tw_andorb(reg, mask, value) \
0176         writeb((readb(dev->bmmio + (reg)) & ~(mask)) |\
0177         ((value) & (mask)), dev->bmmio+(reg))
0178 #define tw_setl(reg, bit)   tw_andorl((reg), (bit), (bit))
0179 #define tw_setb(reg, bit)   tw_andorb((reg), (bit), (bit))
0180 #define tw_clearl(reg, bit) \
0181         writel((readl(dev->lmmio + ((reg) >> 2)) & ~(bit)), \
0182         dev->lmmio + ((reg) >> 2))
0183 #define tw_clearb(reg, bit) \
0184         writeb((readb(dev->bmmio+(reg)) & ~(bit)), \
0185         dev->bmmio + (reg))
0186 
0187 #define tw_wait(us) { udelay(us); }
0188 
0189 /* ----------------------------------------------------------- */
0190 /* tw68-video.c                                                */
0191 
0192 void tw68_set_tvnorm_hw(struct tw68_dev *dev);
0193 
0194 int tw68_video_init1(struct tw68_dev *dev);
0195 int tw68_video_init2(struct tw68_dev *dev, int video_nr);
0196 void tw68_irq_video_done(struct tw68_dev *dev, unsigned long status);
0197 int tw68_video_start_dma(struct tw68_dev *dev, struct tw68_buf *buf);
0198 
0199 /* ----------------------------------------------------------- */
0200 /* tw68-risc.c                                                 */
0201 
0202 int tw68_risc_buffer(struct pci_dev *pci, struct tw68_buf *buf,
0203     struct scatterlist *sglist, unsigned int top_offset,
0204     unsigned int bottom_offset, unsigned int bpl,
0205     unsigned int padding, unsigned int lines);