Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * v4l2 device driver for cx2388x based TV cards
0004  *
0005  * (c) 2003,04 Gerd Knorr <kraxel@bytesex.org> [SUSE Labs]
0006  */
0007 
0008 #ifndef CX88_H
0009 #define CX88_H
0010 
0011 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
0012 
0013 #include <linux/pci.h>
0014 #include <linux/i2c.h>
0015 #include <linux/i2c-algo-bit.h>
0016 #include <linux/videodev2.h>
0017 #include <linux/kdev_t.h>
0018 #include <linux/refcount.h>
0019 
0020 #include <media/v4l2-device.h>
0021 #include <media/v4l2-fh.h>
0022 #include <media/tuner.h>
0023 #include <media/tveeprom.h>
0024 #include <media/videobuf2-dma-sg.h>
0025 #include <media/drv-intf/cx2341x.h>
0026 #include <media/videobuf2-dvb.h>
0027 #include <media/i2c/ir-kbd-i2c.h>
0028 #include <media/i2c/wm8775.h>
0029 
0030 #include "cx88-reg.h"
0031 #include "xc2028.h"
0032 
0033 #include <linux/mutex.h>
0034 
0035 #define CX88_VERSION "1.0.0"
0036 
0037 #define UNSET (-1U)
0038 
0039 #define CX88_MAXBOARDS 8
0040 
0041 /* Max number of inputs by card */
0042 #define MAX_CX88_INPUT 8
0043 
0044 /* ----------------------------------------------------------- */
0045 /* defines and enums                                           */
0046 
0047 /* Currently unsupported by the driver: PAL/H, NTSC/Kr, SECAM/LC */
0048 #define CX88_NORMS (V4L2_STD_ALL        \
0049             & ~V4L2_STD_PAL_H       \
0050             & ~V4L2_STD_NTSC_M_KR   \
0051             & ~V4L2_STD_SECAM_LC)
0052 
0053 #define FORMAT_FLAGS_PACKED       0x01
0054 #define FORMAT_FLAGS_PLANAR       0x02
0055 
0056 #define VBI_LINE_PAL_COUNT              18
0057 #define VBI_LINE_NTSC_COUNT             12
0058 #define VBI_LINE_LENGTH           2048
0059 
0060 #define AUD_RDS_LINES            4
0061 
0062 /* need "shadow" registers for some write-only ones ... */
0063 #define SHADOW_AUD_VOL_CTL           1
0064 #define SHADOW_AUD_BAL_CTL           2
0065 #define SHADOW_MAX                   3
0066 
0067 /* FM Radio deemphasis type */
0068 enum cx88_deemph_type {
0069     FM_NO_DEEMPH = 0,
0070     FM_DEEMPH_50,
0071     FM_DEEMPH_75
0072 };
0073 
0074 enum cx88_board_type {
0075     CX88_BOARD_NONE = 0,
0076     CX88_MPEG_DVB,
0077     CX88_MPEG_BLACKBIRD
0078 };
0079 
0080 enum cx8802_board_access {
0081     CX8802_DRVCTL_SHARED    = 1,
0082     CX8802_DRVCTL_EXCLUSIVE = 2,
0083 };
0084 
0085 /* ----------------------------------------------------------- */
0086 /* tv norms                                                    */
0087 
0088 static inline unsigned int norm_maxw(v4l2_std_id norm)
0089 {
0090     return 720;
0091 }
0092 
0093 static inline unsigned int norm_maxh(v4l2_std_id norm)
0094 {
0095     return (norm & V4L2_STD_525_60) ? 480 : 576;
0096 }
0097 
0098 /* ----------------------------------------------------------- */
0099 /* static data                                                 */
0100 
0101 struct cx8800_fmt {
0102     u32   fourcc;          /* v4l2 format id */
0103     int   depth;
0104     int   flags;
0105     u32   cxformat;
0106 };
0107 
0108 /* ----------------------------------------------------------- */
0109 /* SRAM memory management data (see cx88-core.c)               */
0110 
0111 #define SRAM_CH21 0   /* video */
0112 #define SRAM_CH22 1
0113 #define SRAM_CH23 2
0114 #define SRAM_CH24 3   /* vbi   */
0115 #define SRAM_CH25 4   /* audio */
0116 #define SRAM_CH26 5
0117 #define SRAM_CH28 6   /* mpeg */
0118 #define SRAM_CH27 7   /* audio rds */
0119 /* more */
0120 
0121 struct sram_channel {
0122     const char *name;
0123     u32  cmds_start;
0124     u32  ctrl_start;
0125     u32  cdt;
0126     u32  fifo_start;
0127     u32  fifo_size;
0128     u32  ptr1_reg;
0129     u32  ptr2_reg;
0130     u32  cnt1_reg;
0131     u32  cnt2_reg;
0132 };
0133 
0134 extern const struct sram_channel cx88_sram_channels[];
0135 
0136 /* ----------------------------------------------------------- */
0137 /* card configuration                                          */
0138 
0139 #define CX88_BOARD_NOAUTO               UNSET
0140 #define CX88_BOARD_UNKNOWN                  0
0141 #define CX88_BOARD_HAUPPAUGE                1
0142 #define CX88_BOARD_GDI                      2
0143 #define CX88_BOARD_PIXELVIEW                3
0144 #define CX88_BOARD_ATI_WONDER_PRO           4
0145 #define CX88_BOARD_WINFAST2000XP_EXPERT     5
0146 #define CX88_BOARD_AVERTV_STUDIO_303        6
0147 #define CX88_BOARD_MSI_TVANYWHERE_MASTER    7
0148 #define CX88_BOARD_WINFAST_DV2000           8
0149 #define CX88_BOARD_LEADTEK_PVR2000          9
0150 #define CX88_BOARD_IODATA_GVVCP3PCI        10
0151 #define CX88_BOARD_PROLINK_PLAYTVPVR       11
0152 #define CX88_BOARD_ASUS_PVR_416            12
0153 #define CX88_BOARD_MSI_TVANYWHERE          13
0154 #define CX88_BOARD_KWORLD_DVB_T            14
0155 #define CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1 15
0156 #define CX88_BOARD_KWORLD_LTV883           16
0157 #define CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q  17
0158 #define CX88_BOARD_HAUPPAUGE_DVB_T1        18
0159 #define CX88_BOARD_CONEXANT_DVB_T1         19
0160 #define CX88_BOARD_PROVIDEO_PV259          20
0161 #define CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS 21
0162 #define CX88_BOARD_PCHDTV_HD3000           22
0163 #define CX88_BOARD_DNTV_LIVE_DVB_T         23
0164 #define CX88_BOARD_HAUPPAUGE_ROSLYN        24
0165 #define CX88_BOARD_DIGITALLOGIC_MEC        25
0166 #define CX88_BOARD_IODATA_GVBCTV7E         26
0167 #define CX88_BOARD_PIXELVIEW_PLAYTV_ULTRA_PRO 27
0168 #define CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_T  28
0169 #define CX88_BOARD_ADSTECH_DVB_T_PCI          29
0170 #define CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1  30
0171 #define CX88_BOARD_DVICO_FUSIONHDTV_5_GOLD 31
0172 #define CX88_BOARD_AVERMEDIA_ULTRATV_MC_550 32
0173 #define CX88_BOARD_KWORLD_VSTREAM_EXPERT_DVD 33
0174 #define CX88_BOARD_ATI_HDTVWONDER          34
0175 #define CX88_BOARD_WINFAST_DTV1000         35
0176 #define CX88_BOARD_AVERTV_303              36
0177 #define CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1  37
0178 #define CX88_BOARD_HAUPPAUGE_NOVASE2_S1    38
0179 #define CX88_BOARD_KWORLD_DVBS_100         39
0180 #define CX88_BOARD_HAUPPAUGE_HVR1100       40
0181 #define CX88_BOARD_HAUPPAUGE_HVR1100LP     41
0182 #define CX88_BOARD_DNTV_LIVE_DVB_T_PRO     42
0183 #define CX88_BOARD_KWORLD_DVB_T_CX22702    43
0184 #define CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL 44
0185 #define CX88_BOARD_KWORLD_HARDWARE_MPEG_TV_XPERT 45
0186 #define CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_HYBRID 46
0187 #define CX88_BOARD_PCHDTV_HD5500           47
0188 #define CX88_BOARD_KWORLD_MCE200_DELUXE    48
0189 #define CX88_BOARD_PIXELVIEW_PLAYTV_P7000  49
0190 #define CX88_BOARD_NPGTECH_REALTV_TOP10FM  50
0191 #define CX88_BOARD_WINFAST_DTV2000H        51
0192 #define CX88_BOARD_GENIATECH_DVBS          52
0193 #define CX88_BOARD_HAUPPAUGE_HVR3000       53
0194 #define CX88_BOARD_NORWOOD_MICRO           54
0195 #define CX88_BOARD_TE_DTV_250_OEM_SWANN    55
0196 #define CX88_BOARD_HAUPPAUGE_HVR1300       56
0197 #define CX88_BOARD_ADSTECH_PTV_390         57
0198 #define CX88_BOARD_PINNACLE_PCTV_HD_800i   58
0199 #define CX88_BOARD_DVICO_FUSIONHDTV_5_PCI_NANO 59
0200 #define CX88_BOARD_PINNACLE_HYBRID_PCTV    60
0201 #define CX88_BOARD_WINFAST_TV2000_XP_GLOBAL 61
0202 #define CX88_BOARD_POWERCOLOR_REAL_ANGEL   62
0203 #define CX88_BOARD_GENIATECH_X8000_MT      63
0204 #define CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PRO 64
0205 #define CX88_BOARD_DVICO_FUSIONHDTV_7_GOLD 65
0206 #define CX88_BOARD_PROLINK_PV_8000GT       66
0207 #define CX88_BOARD_KWORLD_ATSC_120         67
0208 #define CX88_BOARD_HAUPPAUGE_HVR4000       68
0209 #define CX88_BOARD_HAUPPAUGE_HVR4000LITE   69
0210 #define CX88_BOARD_TEVII_S460              70
0211 #define CX88_BOARD_OMICOM_SS4_PCI          71
0212 #define CX88_BOARD_TBS_8920                72
0213 #define CX88_BOARD_TEVII_S420              73
0214 #define CX88_BOARD_PROLINK_PV_GLOBAL_XTREME 74
0215 #define CX88_BOARD_PROF_7300               75
0216 #define CX88_BOARD_SATTRADE_ST4200         76
0217 #define CX88_BOARD_TBS_8910                77
0218 #define CX88_BOARD_PROF_6200               78
0219 #define CX88_BOARD_TERRATEC_CINERGY_HT_PCI_MKII 79
0220 #define CX88_BOARD_HAUPPAUGE_IRONLY        80
0221 #define CX88_BOARD_WINFAST_DTV1800H        81
0222 #define CX88_BOARD_WINFAST_DTV2000H_J      82
0223 #define CX88_BOARD_PROF_7301               83
0224 #define CX88_BOARD_SAMSUNG_SMT_7020        84
0225 #define CX88_BOARD_TWINHAN_VP1027_DVBS     85
0226 #define CX88_BOARD_TEVII_S464              86
0227 #define CX88_BOARD_WINFAST_DTV2000H_PLUS   87
0228 #define CX88_BOARD_WINFAST_DTV1800H_XC4000 88
0229 #define CX88_BOARD_WINFAST_TV2000_XP_GLOBAL_6F36 89
0230 #define CX88_BOARD_WINFAST_TV2000_XP_GLOBAL_6F43 90
0231 #define CX88_BOARD_NOTONLYTV_LV3H          91
0232 
0233 enum cx88_itype {
0234     CX88_VMUX_COMPOSITE1 = 1,
0235     CX88_VMUX_COMPOSITE2,
0236     CX88_VMUX_COMPOSITE3,
0237     CX88_VMUX_COMPOSITE4,
0238     CX88_VMUX_SVIDEO,
0239     CX88_VMUX_TELEVISION,
0240     CX88_VMUX_CABLE,
0241     CX88_VMUX_DVB,
0242     CX88_VMUX_DEBUG,
0243     CX88_RADIO,
0244 };
0245 
0246 struct cx88_input {
0247     enum cx88_itype type;
0248     u32             gpio0, gpio1, gpio2, gpio3;
0249     unsigned int    vmux:2;
0250     unsigned int    audioroute:4;
0251 };
0252 
0253 enum cx88_audio_chip {
0254     CX88_AUDIO_WM8775 = 1,
0255     CX88_AUDIO_TVAUDIO,
0256 };
0257 
0258 struct cx88_board {
0259     const char              *name;
0260     unsigned int            tuner_type;
0261     unsigned int        radio_type;
0262     unsigned char       tuner_addr;
0263     unsigned char       radio_addr;
0264     int                     tda9887_conf;
0265     struct cx88_input       input[MAX_CX88_INPUT];
0266     struct cx88_input       radio;
0267     enum cx88_board_type    mpeg;
0268     enum cx88_audio_chip    audio_chip;
0269     int         num_frontends;
0270 
0271     /* Used for I2S devices */
0272     int         i2sinputcntl;
0273 };
0274 
0275 struct cx88_subid {
0276     u16     subvendor;
0277     u16     subdevice;
0278     u32     card;
0279 };
0280 
0281 enum cx88_tvaudio {
0282     WW_NONE = 1,
0283     WW_BTSC,
0284     WW_BG,
0285     WW_DK,
0286     WW_I,
0287     WW_L,
0288     WW_EIAJ,
0289     WW_I2SPT,
0290     WW_FM,
0291     WW_I2SADC,
0292     WW_M
0293 };
0294 
0295 #define INPUT(nr) (core->board.input[nr])
0296 
0297 /* ----------------------------------------------------------- */
0298 /* device / file handle status                                 */
0299 
0300 #define RESOURCE_OVERLAY       1
0301 #define RESOURCE_VIDEO         2
0302 #define RESOURCE_VBI           4
0303 
0304 #define BUFFER_TIMEOUT     msecs_to_jiffies(2000)
0305 
0306 struct cx88_riscmem {
0307     unsigned int   size;
0308     __le32         *cpu;
0309     __le32         *jmp;
0310     dma_addr_t     dma;
0311 };
0312 
0313 /* buffer for one video frame */
0314 struct cx88_buffer {
0315     /* common v4l buffer stuff -- must be first */
0316     struct vb2_v4l2_buffer vb;
0317     struct list_head       list;
0318 
0319     /* cx88 specific */
0320     unsigned int           bpl;
0321     struct cx88_riscmem    risc;
0322 };
0323 
0324 struct cx88_dmaqueue {
0325     struct list_head       active;
0326     u32                    count;
0327 };
0328 
0329 struct cx8800_dev;
0330 struct cx8802_dev;
0331 
0332 struct cx88_core {
0333     struct list_head           devlist;
0334     refcount_t         refcount;
0335 
0336     /* board name */
0337     int                        nr;
0338     char                       name[32];
0339     u32            model;
0340 
0341     /* pci stuff */
0342     int                        pci_bus;
0343     int                        pci_slot;
0344     u32                        __iomem *lmmio;
0345     u8                         __iomem *bmmio;
0346     u32                        shadow[SHADOW_MAX];
0347     int                        pci_irqmask;
0348 
0349     /* i2c i/o */
0350     struct i2c_adapter         i2c_adap;
0351     struct i2c_algo_bit_data   i2c_algo;
0352     struct i2c_client          i2c_client;
0353     u32                        i2c_state, i2c_rc;
0354 
0355     /* config info -- analog */
0356     struct v4l2_device     v4l2_dev;
0357     struct v4l2_ctrl_handler   video_hdl;
0358     struct v4l2_ctrl       *chroma_agc;
0359     struct v4l2_ctrl_handler   audio_hdl;
0360     struct v4l2_subdev     *sd_wm8775;
0361     struct i2c_client      *i2c_rtc;
0362     unsigned int               boardnr;
0363     struct cx88_board      board;
0364 
0365     /* Supported V4L _STD_ tuner formats */
0366     unsigned int               tuner_formats;
0367 
0368     /* config info -- dvb */
0369 #if IS_ENABLED(CONFIG_VIDEO_CX88_DVB)
0370     int (*prev_set_voltage)(struct dvb_frontend *fe,
0371                     enum fe_sec_voltage voltage);
0372 #endif
0373     void    (*gate_ctrl)(struct cx88_core *core, int open);
0374 
0375     /* state info */
0376     struct task_struct         *kthread;
0377     v4l2_std_id                tvnorm;
0378     unsigned int           width, height;
0379     unsigned int           field;
0380     enum cx88_tvaudio          tvaudio;
0381     u32                        audiomode_manual;
0382     u32                        audiomode_current;
0383     u32                        input;
0384     u32                        last_analog_input;
0385     u32                        astat;
0386     u32            use_nicam;
0387     unsigned long          last_change;
0388 
0389     /* IR remote control state */
0390     struct cx88_IR             *ir;
0391 
0392     /* I2C remote data */
0393     struct IR_i2c_init_data    init_data;
0394     struct wm8775_platform_data wm8775_data;
0395 
0396     struct mutex               lock;
0397     /* various v4l controls */
0398     u32                        freq;
0399 
0400     /*
0401      * cx88-video needs to access cx8802 for hybrid tuner pll access and
0402      * for vb2_is_busy() checks.
0403      */
0404     struct cx8802_dev          *dvbdev;
0405     /* cx88-blackbird needs to access cx8800 for vb2_is_busy() checks */
0406     struct cx8800_dev          *v4ldev;
0407     enum cx88_board_type       active_type_id;
0408     int            active_ref;
0409     int            active_fe_id;
0410 };
0411 
0412 static inline struct cx88_core *to_core(struct v4l2_device *v4l2_dev)
0413 {
0414     return container_of(v4l2_dev, struct cx88_core, v4l2_dev);
0415 }
0416 
0417 #define call_hw(core, grpid, o, f, args...) \
0418     do {                            \
0419         if (!core->i2c_rc) {                \
0420             if (core->gate_ctrl)            \
0421                 core->gate_ctrl(core, 1);   \
0422             v4l2_device_call_all(&core->v4l2_dev,   \
0423                          grpid, o, f, ##args); \
0424             if (core->gate_ctrl)            \
0425                 core->gate_ctrl(core, 0);   \
0426         }                       \
0427     } while (0)
0428 
0429 #define call_all(core, o, f, args...) call_hw(core, 0, o, f, ##args)
0430 
0431 #define WM8775_GID      (1 << 0)
0432 
0433 #define wm8775_s_ctrl(core, id, val) \
0434     do {                                \
0435         struct v4l2_ctrl *ctrl_ =               \
0436             v4l2_ctrl_find(core->sd_wm8775->ctrl_handler, id);\
0437         if (ctrl_ && !core->i2c_rc) {               \
0438             if (core->gate_ctrl)                \
0439                 core->gate_ctrl(core, 1);       \
0440             v4l2_ctrl_s_ctrl(ctrl_, val);           \
0441             if (core->gate_ctrl)                \
0442                 core->gate_ctrl(core, 0);       \
0443         }                           \
0444     } while (0)
0445 
0446 #define wm8775_g_ctrl(core, id) \
0447     ({                              \
0448         struct v4l2_ctrl *ctrl_ =               \
0449             v4l2_ctrl_find(core->sd_wm8775->ctrl_handler, id);\
0450         s32 val = 0;                        \
0451         if (ctrl_ && !core->i2c_rc) {               \
0452             if (core->gate_ctrl)                \
0453                 core->gate_ctrl(core, 1);       \
0454             val = v4l2_ctrl_g_ctrl(ctrl_);          \
0455             if (core->gate_ctrl)                \
0456                 core->gate_ctrl(core, 0);       \
0457         }                           \
0458         val;                            \
0459     })
0460 
0461 /* ----------------------------------------------------------- */
0462 /* function 0: video stuff                                     */
0463 
0464 struct cx8800_suspend_state {
0465     int                        disabled;
0466 };
0467 
0468 struct cx8800_dev {
0469     struct cx88_core           *core;
0470     spinlock_t                 slock;
0471 
0472     /* various device info */
0473     unsigned int               resources;
0474     struct video_device        video_dev;
0475     struct video_device        vbi_dev;
0476     struct video_device        radio_dev;
0477 
0478     /* pci i/o */
0479     struct pci_dev             *pci;
0480     unsigned char              pci_rev, pci_lat;
0481 
0482     const struct cx8800_fmt    *fmt;
0483 
0484     /* capture queues */
0485     struct cx88_dmaqueue       vidq;
0486     struct vb2_queue           vb2_vidq;
0487     struct cx88_dmaqueue       vbiq;
0488     struct vb2_queue           vb2_vbiq;
0489 
0490     /* various v4l controls */
0491 
0492     /* other global state info */
0493     struct cx8800_suspend_state state;
0494 };
0495 
0496 /* ----------------------------------------------------------- */
0497 /* function 1: audio/alsa stuff                                */
0498 /* =============> moved to cx88-alsa.c <====================== */
0499 
0500 /* ----------------------------------------------------------- */
0501 /* function 2: mpeg stuff                                      */
0502 
0503 struct cx8802_suspend_state {
0504     int                        disabled;
0505 };
0506 
0507 struct cx8802_driver {
0508     struct cx88_core *core;
0509 
0510     /* List of drivers attached to device */
0511     struct list_head drvlist;
0512 
0513     /* Type of driver and access required */
0514     enum cx88_board_type type_id;
0515     enum cx8802_board_access hw_access;
0516 
0517     /* MPEG 8802 internal only */
0518     int (*suspend)(struct pci_dev *pci_dev, pm_message_t state);
0519     int (*resume)(struct pci_dev *pci_dev);
0520 
0521     /* Callers to the following functions must hold core->lock */
0522 
0523     /* MPEG 8802 -> mini driver - Driver probe and configuration */
0524     int (*probe)(struct cx8802_driver *drv);
0525     int (*remove)(struct cx8802_driver *drv);
0526 
0527     /* MPEG 8802 -> mini driver - Access for hardware control */
0528     int (*advise_acquire)(struct cx8802_driver *drv);
0529     int (*advise_release)(struct cx8802_driver *drv);
0530 
0531     /* MPEG 8802 <- mini driver - Access for hardware control */
0532     int (*request_acquire)(struct cx8802_driver *drv);
0533     int (*request_release)(struct cx8802_driver *drv);
0534 };
0535 
0536 struct cx8802_dev {
0537     struct cx88_core           *core;
0538     spinlock_t                 slock;
0539 
0540     /* pci i/o */
0541     struct pci_dev             *pci;
0542     unsigned char              pci_rev, pci_lat;
0543 
0544     /* dma queues */
0545     struct cx88_dmaqueue       mpegq;
0546     struct vb2_queue           vb2_mpegq;
0547     u32                        ts_packet_size;
0548     u32                        ts_packet_count;
0549 
0550     /* other global state info */
0551     struct cx8802_suspend_state state;
0552 
0553     /* for blackbird only */
0554     struct list_head           devlist;
0555 #if IS_ENABLED(CONFIG_VIDEO_CX88_BLACKBIRD)
0556     struct video_device        mpeg_dev;
0557     u32                        mailbox;
0558 
0559     /* mpeg params */
0560     struct cx2341x_handler     cxhdl;
0561 
0562 #endif
0563 
0564 #if IS_ENABLED(CONFIG_VIDEO_CX88_DVB)
0565     /* for dvb only */
0566     struct vb2_dvb_frontends frontends;
0567 #endif
0568 
0569 #if IS_ENABLED(CONFIG_VIDEO_CX88_VP3054)
0570     /* For VP3045 secondary I2C bus support */
0571     struct vp3054_i2c_state    *vp3054;
0572 #endif
0573     /* for switching modulation types */
0574     unsigned char              ts_gen_cntrl;
0575 
0576     /* List of attached drivers; must hold core->lock to access */
0577     struct list_head       drvlist;
0578 
0579     struct work_struct     request_module_wk;
0580 };
0581 
0582 /* ----------------------------------------------------------- */
0583 
0584 #define cx_read(reg)             readl(core->lmmio + ((reg) >> 2))
0585 #define cx_write(reg, value)     writel((value), core->lmmio + ((reg) >> 2))
0586 #define cx_writeb(reg, value)    writeb((value), core->bmmio + (reg))
0587 
0588 #define cx_andor(reg, mask, value) \
0589     writel((readl(core->lmmio + ((reg) >> 2)) & ~(mask)) |\
0590     ((value) & (mask)), core->lmmio + ((reg) >> 2))
0591 #define cx_set(reg, bit)         cx_andor((reg), (bit), (bit))
0592 #define cx_clear(reg, bit)       cx_andor((reg), (bit), 0)
0593 
0594 #define cx_wait(d) { if (need_resched()) schedule(); else udelay(d); }
0595 
0596 /* shadow registers */
0597 #define cx_sread(sreg)          (core->shadow[sreg])
0598 #define cx_swrite(sreg, reg, value) \
0599     (core->shadow[sreg] = value, \
0600     writel(core->shadow[sreg], core->lmmio + ((reg) >> 2)))
0601 #define cx_sandor(sreg, reg, mask, value) \
0602     (core->shadow[sreg] = (core->shadow[sreg] & ~(mask)) | \
0603                    ((value) & (mask)), \
0604                 writel(core->shadow[sreg], \
0605                        core->lmmio + ((reg) >> 2)))
0606 
0607 /* ----------------------------------------------------------- */
0608 /* cx88-core.c                                                 */
0609 
0610 extern unsigned int cx88_core_debug;
0611 
0612 void cx88_print_irqbits(const char *tag, const char *strings[],
0613             int len, u32 bits, u32 mask);
0614 
0615 int cx88_core_irq(struct cx88_core *core, u32 status);
0616 void cx88_wakeup(struct cx88_core *core,
0617          struct cx88_dmaqueue *q, u32 count);
0618 void cx88_shutdown(struct cx88_core *core);
0619 int cx88_reset(struct cx88_core *core);
0620 
0621 extern int
0622 cx88_risc_buffer(struct pci_dev *pci, struct cx88_riscmem *risc,
0623          struct scatterlist *sglist,
0624          unsigned int top_offset, unsigned int bottom_offset,
0625          unsigned int bpl, unsigned int padding, unsigned int lines);
0626 extern int
0627 cx88_risc_databuffer(struct pci_dev *pci, struct cx88_riscmem *risc,
0628              struct scatterlist *sglist, unsigned int bpl,
0629              unsigned int lines, unsigned int lpi);
0630 
0631 void cx88_risc_disasm(struct cx88_core *core,
0632               struct cx88_riscmem *risc);
0633 int cx88_sram_channel_setup(struct cx88_core *core,
0634                 const struct sram_channel *ch,
0635                 unsigned int bpl, u32 risc);
0636 void cx88_sram_channel_dump(struct cx88_core *core,
0637                 const struct sram_channel *ch);
0638 
0639 int cx88_set_scale(struct cx88_core *core, unsigned int width,
0640            unsigned int height, enum v4l2_field field);
0641 int cx88_set_tvnorm(struct cx88_core *core, v4l2_std_id norm);
0642 
0643 void cx88_vdev_init(struct cx88_core *core,
0644             struct pci_dev *pci,
0645             struct video_device *vfd,
0646             const struct video_device *template_,
0647             const char *type);
0648 struct cx88_core *cx88_core_get(struct pci_dev *pci);
0649 void cx88_core_put(struct cx88_core *core,
0650            struct pci_dev *pci);
0651 
0652 int cx88_start_audio_dma(struct cx88_core *core);
0653 int cx88_stop_audio_dma(struct cx88_core *core);
0654 
0655 /* ----------------------------------------------------------- */
0656 /* cx88-vbi.c                                                  */
0657 
0658 /* Can be used as g_vbi_fmt, try_vbi_fmt and s_vbi_fmt */
0659 int cx8800_vbi_fmt(struct file *file, void *priv,
0660            struct v4l2_format *f);
0661 
0662 void cx8800_stop_vbi_dma(struct cx8800_dev *dev);
0663 int cx8800_restart_vbi_queue(struct cx8800_dev *dev, struct cx88_dmaqueue *q);
0664 
0665 extern const struct vb2_ops cx8800_vbi_qops;
0666 
0667 /* ----------------------------------------------------------- */
0668 /* cx88-i2c.c                                                  */
0669 
0670 int cx88_i2c_init(struct cx88_core *core, struct pci_dev *pci);
0671 
0672 /* ----------------------------------------------------------- */
0673 /* cx88-cards.c                                                */
0674 
0675 int cx88_tuner_callback(void *dev, int component, int command, int arg);
0676 int cx88_get_resources(const struct cx88_core *core,
0677                struct pci_dev *pci);
0678 struct cx88_core *cx88_core_create(struct pci_dev *pci, int nr);
0679 void cx88_setup_xc3028(struct cx88_core *core, struct xc2028_ctrl *ctl);
0680 
0681 /* ----------------------------------------------------------- */
0682 /* cx88-tvaudio.c                                              */
0683 
0684 void cx88_set_tvaudio(struct cx88_core *core);
0685 void cx88_newstation(struct cx88_core *core);
0686 void cx88_get_stereo(struct cx88_core *core, struct v4l2_tuner *t);
0687 void cx88_set_stereo(struct cx88_core *core, u32 mode, int manual);
0688 int cx88_audio_thread(void *data);
0689 
0690 int cx8802_register_driver(struct cx8802_driver *drv);
0691 int cx8802_unregister_driver(struct cx8802_driver *drv);
0692 
0693 /* Caller must hold core->lock */
0694 struct cx8802_driver *cx8802_get_driver(struct cx8802_dev *dev,
0695                     enum cx88_board_type btype);
0696 
0697 /* ----------------------------------------------------------- */
0698 /* cx88-dsp.c                                                  */
0699 
0700 s32 cx88_dsp_detect_stereo_sap(struct cx88_core *core);
0701 
0702 /* ----------------------------------------------------------- */
0703 /* cx88-input.c                                                */
0704 
0705 int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci);
0706 int cx88_ir_fini(struct cx88_core *core);
0707 void cx88_ir_irq(struct cx88_core *core);
0708 int cx88_ir_start(struct cx88_core *core);
0709 void cx88_ir_stop(struct cx88_core *core);
0710 void cx88_i2c_init_ir(struct cx88_core *core);
0711 
0712 /* ----------------------------------------------------------- */
0713 /* cx88-mpeg.c                                                 */
0714 
0715 int cx8802_buf_prepare(struct vb2_queue *q, struct cx8802_dev *dev,
0716                struct cx88_buffer *buf);
0717 void cx8802_buf_queue(struct cx8802_dev *dev, struct cx88_buffer *buf);
0718 void cx8802_cancel_buffers(struct cx8802_dev *dev);
0719 int cx8802_start_dma(struct cx8802_dev    *dev,
0720              struct cx88_dmaqueue *q,
0721              struct cx88_buffer   *buf);
0722 
0723 /* ----------------------------------------------------------- */
0724 /* cx88-video.c*/
0725 int cx88_enum_input(struct cx88_core *core, struct v4l2_input *i);
0726 int cx88_set_freq(struct cx88_core  *core, const struct v4l2_frequency *f);
0727 int cx88_video_mux(struct cx88_core *core, unsigned int input);
0728 int cx88_querycap(struct file *file, struct cx88_core *core,
0729           struct v4l2_capability *cap);
0730 
0731 #endif