0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef _BTTVP_H_
0014 #define _BTTVP_H_
0015
0016 #include <linux/types.h>
0017 #include <linux/wait.h>
0018 #include <linux/i2c.h>
0019 #include <linux/i2c-algo-bit.h>
0020 #include <linux/pci.h>
0021 #include <linux/input.h>
0022 #include <linux/mutex.h>
0023 #include <linux/scatterlist.h>
0024 #include <linux/device.h>
0025 #include <asm/io.h>
0026 #include <media/v4l2-common.h>
0027 #include <media/v4l2-ctrls.h>
0028 #include <media/v4l2-fh.h>
0029 #include <media/videobuf-dma-sg.h>
0030 #include <media/tveeprom.h>
0031 #include <media/rc-core.h>
0032 #include <media/i2c/ir-kbd-i2c.h>
0033 #include <media/drv-intf/tea575x.h>
0034
0035 #include "bt848.h"
0036 #include "bttv.h"
0037 #include "btcx-risc.h"
0038
0039 #ifdef __KERNEL__
0040
0041 #define FORMAT_FLAGS_DITHER 0x01
0042 #define FORMAT_FLAGS_PACKED 0x02
0043 #define FORMAT_FLAGS_PLANAR 0x04
0044 #define FORMAT_FLAGS_RAW 0x08
0045 #define FORMAT_FLAGS_CrCb 0x10
0046
0047 #define RISC_SLOT_O_VBI 4
0048 #define RISC_SLOT_O_FIELD 6
0049 #define RISC_SLOT_E_VBI 10
0050 #define RISC_SLOT_E_FIELD 12
0051 #define RISC_SLOT_LOOP 14
0052
0053 #define RESOURCE_OVERLAY 1
0054 #define RESOURCE_VIDEO_STREAM 2
0055 #define RESOURCE_VBI 4
0056 #define RESOURCE_VIDEO_READ 8
0057
0058 #define RAW_LINES 640
0059 #define RAW_BPL 1024
0060
0061 #define UNSET (-1U)
0062
0063
0064 #define MIN_VDELAY 2
0065
0066 #define MAX_HDELAY (0x3FF & -2)
0067
0068 #define MAX_HACTIVE (0x3FF & -4)
0069
0070 #define BTTV_NORMS (\
0071 V4L2_STD_PAL | V4L2_STD_PAL_N | \
0072 V4L2_STD_PAL_Nc | V4L2_STD_SECAM | \
0073 V4L2_STD_NTSC | V4L2_STD_PAL_M | \
0074 V4L2_STD_PAL_60)
0075
0076
0077 struct bttv_tvnorm {
0078 int v4l2_id;
0079 char *name;
0080 u32 Fsc;
0081 u16 swidth, sheight;
0082 u16 totalwidth;
0083 u8 adelay, bdelay, iform;
0084 u32 scaledtwidth;
0085 u16 hdelayx1, hactivex1;
0086 u16 vdelay;
0087 u8 vbipack;
0088 u16 vtotal;
0089 int sram;
0090
0091
0092
0093 u16 vbistart[2];
0094
0095
0096
0097 struct v4l2_cropcap cropcap;
0098 };
0099 extern const struct bttv_tvnorm bttv_tvnorms[];
0100
0101 struct bttv_format {
0102 int fourcc;
0103 int btformat;
0104 int btswap;
0105 int depth;
0106 int flags;
0107 int hshift,vshift;
0108 };
0109
0110 struct bttv_ir {
0111 struct rc_dev *dev;
0112 struct bttv *btv;
0113 struct timer_list timer;
0114
0115 char name[32];
0116 char phys[32];
0117
0118
0119 u32 mask_keycode;
0120 u32 mask_keydown;
0121 u32 mask_keyup;
0122 u32 polling;
0123 u32 last_gpio;
0124 int shift_by;
0125 int rc5_remote_gap;
0126
0127
0128 bool rc5_gpio;
0129 u32 last_bit;
0130 u32 code;
0131 ktime_t base_time;
0132 bool active;
0133 };
0134
0135
0136
0137
0138 struct bttv_geometry {
0139 u8 vtc,crop,comb;
0140 u16 width,hscale,hdelay;
0141 u16 sheight,vscale,vdelay,vtotal;
0142 };
0143
0144 struct bttv_buffer {
0145
0146 struct videobuf_buffer vb;
0147
0148
0149 const struct bttv_format *fmt;
0150 unsigned int tvnorm;
0151 int btformat;
0152 int btswap;
0153 struct bttv_geometry geo;
0154 struct btcx_riscmem top;
0155 struct btcx_riscmem bottom;
0156 struct v4l2_rect crop;
0157 unsigned int vbi_skip[2];
0158 unsigned int vbi_count[2];
0159 };
0160
0161 struct bttv_buffer_set {
0162 struct bttv_buffer *top;
0163 struct bttv_buffer *bottom;
0164 unsigned int top_irq;
0165 unsigned int frame_irq;
0166 };
0167
0168 struct bttv_overlay {
0169 unsigned int tvnorm;
0170 struct v4l2_rect w;
0171 enum v4l2_field field;
0172 struct v4l2_clip *clips;
0173 int nclips;
0174 int setup_ok;
0175 };
0176
0177 struct bttv_vbi_fmt {
0178 struct v4l2_vbi_format fmt;
0179
0180
0181 const struct bttv_tvnorm *tvnorm;
0182
0183
0184
0185 __s32 end;
0186 };
0187
0188
0189 void bttv_vbi_fmt_reset(struct bttv_vbi_fmt *f, unsigned int norm);
0190
0191 struct bttv_crop {
0192
0193 struct v4l2_rect rect;
0194
0195
0196
0197
0198
0199 __s32 min_scaled_width;
0200 __s32 min_scaled_height;
0201 __s32 max_scaled_width;
0202 __s32 max_scaled_height;
0203 };
0204
0205 struct bttv_fh {
0206
0207 struct v4l2_fh fh;
0208
0209 struct bttv *btv;
0210 int resources;
0211 enum v4l2_buf_type type;
0212
0213
0214 struct videobuf_queue cap;
0215 const struct bttv_format *fmt;
0216 int width;
0217 int height;
0218
0219
0220 const struct bttv_format *ovfmt;
0221 struct bttv_overlay ov;
0222
0223
0224 int do_crop;
0225
0226
0227 struct videobuf_queue vbi;
0228
0229
0230
0231 struct bttv_vbi_fmt vbi_fmt;
0232 };
0233
0234
0235
0236
0237
0238 int bttv_risc_packed(struct bttv *btv, struct btcx_riscmem *risc,
0239 struct scatterlist *sglist,
0240 unsigned int offset, unsigned int bpl,
0241 unsigned int pitch, unsigned int skip_lines,
0242 unsigned int store_lines);
0243
0244
0245 void bttv_set_dma(struct bttv *btv, int override);
0246 int bttv_risc_init_main(struct bttv *btv);
0247 int bttv_risc_hook(struct bttv *btv, int slot, struct btcx_riscmem *risc,
0248 int irqflags);
0249
0250
0251 int bttv_buffer_risc(struct bttv *btv, struct bttv_buffer *buf);
0252 int bttv_buffer_activate_video(struct bttv *btv,
0253 struct bttv_buffer_set *set);
0254 int bttv_buffer_activate_vbi(struct bttv *btv,
0255 struct bttv_buffer *vbi);
0256 void bttv_dma_free(struct videobuf_queue *q, struct bttv *btv,
0257 struct bttv_buffer *buf);
0258
0259
0260 int bttv_overlay_risc(struct bttv *btv, struct bttv_overlay *ov,
0261 const struct bttv_format *fmt,
0262 struct bttv_buffer *buf);
0263
0264
0265
0266
0267
0268 int bttv_try_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *f);
0269 int bttv_g_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *f);
0270 int bttv_s_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *f);
0271
0272 extern const struct videobuf_queue_ops bttv_vbi_qops;
0273
0274
0275
0276
0277 extern struct bus_type bttv_sub_bus_type;
0278 int bttv_sub_add_device(struct bttv_core *core, char *name);
0279 int bttv_sub_del_devices(struct bttv_core *core);
0280
0281
0282
0283
0284 extern int no_overlay;
0285
0286
0287
0288
0289 extern void init_bttv_i2c_ir(struct bttv *btv);
0290
0291
0292
0293 extern int init_bttv_i2c(struct bttv *btv);
0294 extern int fini_bttv_i2c(struct bttv *btv);
0295
0296
0297
0298
0299
0300 extern unsigned int bttv_verbose;
0301 extern unsigned int bttv_debug;
0302 extern unsigned int bttv_gpio;
0303 extern void bttv_gpio_tracking(struct bttv *btv, char *comment);
0304
0305 #define dprintk(fmt, ...) \
0306 do { \
0307 if (bttv_debug >= 1) \
0308 pr_debug(fmt, ##__VA_ARGS__); \
0309 } while (0)
0310 #define dprintk_cont(fmt, ...) \
0311 do { \
0312 if (bttv_debug >= 1) \
0313 pr_cont(fmt, ##__VA_ARGS__); \
0314 } while (0)
0315 #define d2printk(fmt, ...) \
0316 do { \
0317 if (bttv_debug >= 2) \
0318 printk(fmt, ##__VA_ARGS__); \
0319 } while (0)
0320
0321 #define BTTV_MAX_FBUF 0x208000
0322 #define BTTV_TIMEOUT msecs_to_jiffies(500)
0323 #define BTTV_FREE_IDLE msecs_to_jiffies(1000)
0324
0325
0326 struct bttv_pll_info {
0327 unsigned int pll_ifreq;
0328 unsigned int pll_ofreq;
0329 unsigned int pll_crystal;
0330 unsigned int pll_current;
0331 };
0332
0333
0334 struct bttv_input {
0335 struct input_dev *dev;
0336 char name[32];
0337 char phys[32];
0338 u32 mask_keycode;
0339 u32 mask_keydown;
0340 };
0341
0342 struct bttv_suspend_state {
0343 u32 gpio_enable;
0344 u32 gpio_data;
0345 int disabled;
0346 int loop_irq;
0347 struct bttv_buffer_set video;
0348 struct bttv_buffer *vbi;
0349 };
0350
0351 struct bttv_tea575x_gpio {
0352 u8 data, clk, wren, most;
0353 };
0354
0355 struct bttv {
0356 struct bttv_core c;
0357
0358
0359 unsigned short id;
0360 unsigned char revision;
0361 unsigned char __iomem *bt848_mmio;
0362
0363
0364 unsigned int cardid;
0365 unsigned int tuner_type;
0366 unsigned int tda9887_conf;
0367 unsigned int svhs, dig;
0368 unsigned int has_saa6588:1;
0369 struct bttv_pll_info pll;
0370 int triton1;
0371 int gpioirq;
0372
0373 int use_i2c_hw;
0374
0375
0376 int shutdown;
0377
0378 void (*volume_gpio)(struct bttv *btv, __u16 volume);
0379 void (*audio_mode_gpio)(struct bttv *btv, struct v4l2_tuner *tuner, int set);
0380
0381
0382 spinlock_t gpio_lock;
0383
0384
0385 struct i2c_algo_bit_data i2c_algo;
0386 struct i2c_client i2c_client;
0387 int i2c_state, i2c_rc;
0388 int i2c_done;
0389 wait_queue_head_t i2c_queue;
0390 struct v4l2_subdev *sd_msp34xx;
0391 struct v4l2_subdev *sd_tvaudio;
0392 struct v4l2_subdev *sd_tda7432;
0393
0394
0395 struct video_device video_dev;
0396 struct video_device radio_dev;
0397 struct video_device vbi_dev;
0398
0399
0400 struct v4l2_ctrl_handler ctrl_handler;
0401 struct v4l2_ctrl_handler radio_ctrl_handler;
0402
0403
0404 int has_remote;
0405 struct bttv_ir *remote;
0406
0407
0408 struct IR_i2c_init_data init_data;
0409
0410
0411 spinlock_t s_lock;
0412 struct mutex lock;
0413 int resources;
0414
0415
0416 unsigned int input;
0417 unsigned int audio_input;
0418 unsigned int mute;
0419 unsigned long tv_freq;
0420 unsigned int tvnorm;
0421 v4l2_std_id std;
0422 int hue, contrast, bright, saturation;
0423 struct v4l2_framebuffer fbuf;
0424 unsigned int field_count;
0425
0426
0427 int opt_combfilter;
0428 int opt_automute;
0429 int opt_vcr_hack;
0430 int opt_uv_ratio;
0431
0432
0433 int has_radio;
0434 int has_radio_tuner;
0435 int radio_user;
0436 int radio_uses_msp_demodulator;
0437 unsigned long radio_freq;
0438
0439
0440
0441 int has_tea575x;
0442 struct bttv_tea575x_gpio tea_gpio;
0443 struct snd_tea575x tea;
0444
0445
0446 int mbox_ior;
0447 int mbox_iow;
0448 int mbox_csel;
0449
0450
0451 char sw_status[4];
0452
0453
0454
0455
0456 struct btcx_riscmem main;
0457 struct bttv_buffer *screen;
0458 struct list_head capture;
0459 struct list_head vcapture;
0460 struct bttv_buffer_set curr;
0461 struct bttv_buffer *cvbi;
0462 int loop_irq;
0463 int new_input;
0464
0465 unsigned long cap_ctl;
0466 unsigned long dma_on;
0467 struct timer_list timeout;
0468 struct bttv_suspend_state state;
0469
0470
0471 unsigned int errors;
0472 unsigned int framedrop;
0473 unsigned int irq_total;
0474 unsigned int irq_me;
0475
0476 unsigned int users;
0477 struct bttv_fh init;
0478
0479
0480 struct work_struct request_module_wk;
0481
0482
0483
0484
0485 struct bttv_crop crop[2];
0486
0487
0488
0489
0490 __s32 vbi_end;
0491
0492
0493
0494
0495 __s32 crop_start;
0496 };
0497
0498 static inline struct bttv *to_bttv(struct v4l2_device *v4l2_dev)
0499 {
0500 return container_of(v4l2_dev, struct bttv, c.v4l2_dev);
0501 }
0502
0503
0504 #define BTTV_MAX 32
0505 extern unsigned int bttv_num;
0506 extern struct bttv *bttvs[BTTV_MAX];
0507
0508 static inline unsigned int bttv_muxsel(const struct bttv *btv,
0509 unsigned int input)
0510 {
0511 return (bttv_tvcards[btv->c.type].muxsel >> (input * 2)) & 3;
0512 }
0513
0514 #endif
0515
0516 #define btwrite(dat,adr) writel((dat), btv->bt848_mmio+(adr))
0517 #define btread(adr) readl(btv->bt848_mmio+(adr))
0518
0519 #define btand(dat,adr) btwrite((dat) & btread(adr), adr)
0520 #define btor(dat,adr) btwrite((dat) | btread(adr), adr)
0521 #define btaor(dat,mask,adr) btwrite((dat) | ((mask) & btread(adr)), adr)
0522
0523 #endif