bttvp.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. /*
  2. bttv - Bt848 frame grabber driver
  3. bttv's *private* header file -- nobody other than bttv itself
  4. should ever include this file.
  5. (c) 2000-2002 Gerd Knorr <kraxel@bytesex.org>
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. #ifndef _BTTVP_H_
  19. #define _BTTVP_H_
  20. #include <linux/types.h>
  21. #include <linux/wait.h>
  22. #include <linux/i2c.h>
  23. #include <linux/i2c-algo-bit.h>
  24. #include <linux/pci.h>
  25. #include <linux/input.h>
  26. #include <linux/mutex.h>
  27. #include <linux/scatterlist.h>
  28. #include <asm/io.h>
  29. #include <media/v4l2-common.h>
  30. #include <linux/device.h>
  31. #include <media/videobuf-dma-sg.h>
  32. #include <media/tveeprom.h>
  33. #include <media/rc-core.h>
  34. #include <media/ir-kbd-i2c.h>
  35. #include "bt848.h"
  36. #include "bttv.h"
  37. #include "btcx-risc.h"
  38. #ifdef __KERNEL__
  39. #define FORMAT_FLAGS_DITHER 0x01
  40. #define FORMAT_FLAGS_PACKED 0x02
  41. #define FORMAT_FLAGS_PLANAR 0x04
  42. #define FORMAT_FLAGS_RAW 0x08
  43. #define FORMAT_FLAGS_CrCb 0x10
  44. #define RISC_SLOT_O_VBI 4
  45. #define RISC_SLOT_O_FIELD 6
  46. #define RISC_SLOT_E_VBI 10
  47. #define RISC_SLOT_E_FIELD 12
  48. #define RISC_SLOT_LOOP 14
  49. #define RESOURCE_OVERLAY 1
  50. #define RESOURCE_VIDEO_STREAM 2
  51. #define RESOURCE_VBI 4
  52. #define RESOURCE_VIDEO_READ 8
  53. #define RAW_LINES 640
  54. #define RAW_BPL 1024
  55. #define UNSET (-1U)
  56. /* Min. value in VDELAY register. */
  57. #define MIN_VDELAY 2
  58. /* Even to get Cb first, odd for Cr. */
  59. #define MAX_HDELAY (0x3FF & -2)
  60. /* Limits scaled width, which must be a multiple of 4. */
  61. #define MAX_HACTIVE (0x3FF & -4)
  62. #define BTTV_NORMS (\
  63. V4L2_STD_PAL | V4L2_STD_PAL_N | \
  64. V4L2_STD_PAL_Nc | V4L2_STD_SECAM | \
  65. V4L2_STD_NTSC | V4L2_STD_PAL_M | \
  66. V4L2_STD_PAL_60)
  67. /* ---------------------------------------------------------- */
  68. struct bttv_tvnorm {
  69. int v4l2_id;
  70. char *name;
  71. u32 Fsc;
  72. u16 swidth, sheight; /* scaled standard width, height */
  73. u16 totalwidth;
  74. u8 adelay, bdelay, iform;
  75. u32 scaledtwidth;
  76. u16 hdelayx1, hactivex1;
  77. u16 vdelay;
  78. u8 vbipack;
  79. u16 vtotal;
  80. int sram;
  81. /* ITU-R frame line number of the first VBI line we can
  82. capture, of the first and second field. The last possible line
  83. is determined by cropcap.bounds. */
  84. u16 vbistart[2];
  85. /* Horizontally this counts fCLKx1 samples following the leading
  86. edge of the horizontal sync pulse, vertically ITU-R frame line
  87. numbers of the first field times two (2, 4, 6, ... 524 or 624). */
  88. struct v4l2_cropcap cropcap;
  89. };
  90. extern const struct bttv_tvnorm bttv_tvnorms[];
  91. struct bttv_format {
  92. char *name;
  93. int fourcc; /* video4linux 2 */
  94. int btformat; /* BT848_COLOR_FMT_* */
  95. int btswap; /* BT848_COLOR_CTL_* */
  96. int depth; /* bit/pixel */
  97. int flags;
  98. int hshift,vshift; /* for planar modes */
  99. };
  100. struct bttv_ir {
  101. struct rc_dev *dev;
  102. struct timer_list timer;
  103. char name[32];
  104. char phys[32];
  105. /* Usual gpio signalling */
  106. u32 mask_keycode;
  107. u32 mask_keydown;
  108. u32 mask_keyup;
  109. u32 polling;
  110. u32 last_gpio;
  111. int shift_by;
  112. int start; // What should RC5_START() be
  113. int addr; // What RC5_ADDR() should be.
  114. int rc5_remote_gap;
  115. /* RC5 gpio */
  116. bool rc5_gpio; /* Is RC5 legacy GPIO enabled? */
  117. u32 last_bit; /* last raw bit seen */
  118. u32 code; /* raw code under construction */
  119. struct timeval base_time; /* time of last seen code */
  120. bool active; /* building raw code */
  121. };
  122. /* ---------------------------------------------------------- */
  123. struct bttv_geometry {
  124. u8 vtc,crop,comb;
  125. u16 width,hscale,hdelay;
  126. u16 sheight,vscale,vdelay,vtotal;
  127. };
  128. struct bttv_buffer {
  129. /* common v4l buffer stuff -- must be first */
  130. struct videobuf_buffer vb;
  131. /* bttv specific */
  132. const struct bttv_format *fmt;
  133. unsigned int tvnorm;
  134. int btformat;
  135. int btswap;
  136. struct bttv_geometry geo;
  137. struct btcx_riscmem top;
  138. struct btcx_riscmem bottom;
  139. struct v4l2_rect crop;
  140. unsigned int vbi_skip[2];
  141. unsigned int vbi_count[2];
  142. };
  143. struct bttv_buffer_set {
  144. struct bttv_buffer *top; /* top field buffer */
  145. struct bttv_buffer *bottom; /* bottom field buffer */
  146. unsigned int top_irq;
  147. unsigned int frame_irq;
  148. };
  149. struct bttv_overlay {
  150. unsigned int tvnorm;
  151. struct v4l2_rect w;
  152. enum v4l2_field field;
  153. struct v4l2_clip *clips;
  154. int nclips;
  155. int setup_ok;
  156. };
  157. struct bttv_vbi_fmt {
  158. struct v4l2_vbi_format fmt;
  159. /* fmt.start[] and count[] refer to this video standard. */
  160. const struct bttv_tvnorm *tvnorm;
  161. /* Earliest possible start of video capturing with this
  162. v4l2_vbi_format, in struct bttv_crop.rect units. */
  163. __s32 end;
  164. };
  165. /* bttv-vbi.c */
  166. void bttv_vbi_fmt_reset(struct bttv_vbi_fmt *f, unsigned int norm);
  167. struct bttv_crop {
  168. /* A cropping rectangle in struct bttv_tvnorm.cropcap units. */
  169. struct v4l2_rect rect;
  170. /* Scaled image size limits with this crop rect. Divide
  171. max_height, but not min_height, by two when capturing
  172. single fields. See also bttv_crop_reset() and
  173. bttv_crop_adjust() in bttv-driver.c. */
  174. __s32 min_scaled_width;
  175. __s32 min_scaled_height;
  176. __s32 max_scaled_width;
  177. __s32 max_scaled_height;
  178. };
  179. struct bttv_fh {
  180. struct bttv *btv;
  181. int resources;
  182. #ifdef VIDIOC_G_PRIORITY
  183. enum v4l2_priority prio;
  184. #endif
  185. enum v4l2_buf_type type;
  186. /* video capture */
  187. struct videobuf_queue cap;
  188. const struct bttv_format *fmt;
  189. int width;
  190. int height;
  191. /* video overlay */
  192. const struct bttv_format *ovfmt;
  193. struct bttv_overlay ov;
  194. /* Application called VIDIOC_S_CROP. */
  195. int do_crop;
  196. /* vbi capture */
  197. struct videobuf_queue vbi;
  198. /* Current VBI capture window as seen through this fh (cannot
  199. be global for compatibility with earlier drivers). Protected
  200. by struct bttv.lock and struct bttv_fh.vbi.lock. */
  201. struct bttv_vbi_fmt vbi_fmt;
  202. };
  203. /* ---------------------------------------------------------- */
  204. /* bttv-risc.c */
  205. /* risc code generators - capture */
  206. int bttv_risc_packed(struct bttv *btv, struct btcx_riscmem *risc,
  207. struct scatterlist *sglist,
  208. unsigned int offset, unsigned int bpl,
  209. unsigned int pitch, unsigned int skip_lines,
  210. unsigned int store_lines);
  211. /* control dma register + risc main loop */
  212. void bttv_set_dma(struct bttv *btv, int override);
  213. int bttv_risc_init_main(struct bttv *btv);
  214. int bttv_risc_hook(struct bttv *btv, int slot, struct btcx_riscmem *risc,
  215. int irqflags);
  216. /* capture buffer handling */
  217. int bttv_buffer_risc(struct bttv *btv, struct bttv_buffer *buf);
  218. int bttv_buffer_activate_video(struct bttv *btv,
  219. struct bttv_buffer_set *set);
  220. int bttv_buffer_activate_vbi(struct bttv *btv,
  221. struct bttv_buffer *vbi);
  222. void bttv_dma_free(struct videobuf_queue *q, struct bttv *btv,
  223. struct bttv_buffer *buf);
  224. /* overlay handling */
  225. int bttv_overlay_risc(struct bttv *btv, struct bttv_overlay *ov,
  226. const struct bttv_format *fmt,
  227. struct bttv_buffer *buf);
  228. /* ---------------------------------------------------------- */
  229. /* bttv-vbi.c */
  230. int bttv_try_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *f);
  231. int bttv_g_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *f);
  232. int bttv_s_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *f);
  233. extern struct videobuf_queue_ops bttv_vbi_qops;
  234. /* ---------------------------------------------------------- */
  235. /* bttv-gpio.c */
  236. extern struct bus_type bttv_sub_bus_type;
  237. int bttv_sub_add_device(struct bttv_core *core, char *name);
  238. int bttv_sub_del_devices(struct bttv_core *core);
  239. /* ---------------------------------------------------------- */
  240. /* bttv-cards.c */
  241. extern int no_overlay;
  242. /* ---------------------------------------------------------- */
  243. /* bttv-input.c */
  244. extern void init_bttv_i2c_ir(struct bttv *btv);
  245. extern int fini_bttv_i2c(struct bttv *btv);
  246. /* ---------------------------------------------------------- */
  247. /* bttv-driver.c */
  248. /* insmod options */
  249. extern unsigned int bttv_verbose;
  250. extern unsigned int bttv_debug;
  251. extern unsigned int bttv_gpio;
  252. extern void bttv_gpio_tracking(struct bttv *btv, char *comment);
  253. extern int init_bttv_i2c(struct bttv *btv);
  254. #define dprintk(fmt, ...) \
  255. do { \
  256. if (bttv_debug >= 1) \
  257. pr_debug(fmt, ##__VA_ARGS__); \
  258. } while (0)
  259. #define dprintk_cont(fmt, ...) \
  260. do { \
  261. if (bttv_debug >= 1) \
  262. pr_cont(fmt, ##__VA_ARGS__); \
  263. } while (0)
  264. #define d2printk(fmt, ...) \
  265. do { \
  266. if (bttv_debug >= 2) \
  267. printk(fmt, ##__VA_ARGS__); \
  268. } while (0)
  269. #define BTTV_MAX_FBUF 0x208000
  270. #define BTTV_TIMEOUT msecs_to_jiffies(500) /* 0.5 seconds */
  271. #define BTTV_FREE_IDLE msecs_to_jiffies(1000) /* one second */
  272. struct bttv_pll_info {
  273. unsigned int pll_ifreq; /* PLL input frequency */
  274. unsigned int pll_ofreq; /* PLL output frequency */
  275. unsigned int pll_crystal; /* Crystal used for input */
  276. unsigned int pll_current; /* Currently programmed ofreq */
  277. };
  278. /* for gpio-connected remote control */
  279. struct bttv_input {
  280. struct input_dev *dev;
  281. char name[32];
  282. char phys[32];
  283. u32 mask_keycode;
  284. u32 mask_keydown;
  285. };
  286. struct bttv_suspend_state {
  287. u32 gpio_enable;
  288. u32 gpio_data;
  289. int disabled;
  290. int loop_irq;
  291. struct bttv_buffer_set video;
  292. struct bttv_buffer *vbi;
  293. };
  294. struct bttv {
  295. struct bttv_core c;
  296. /* pci device config */
  297. unsigned short id;
  298. unsigned char revision;
  299. unsigned char __iomem *bt848_mmio; /* pointer to mmio */
  300. /* card configuration info */
  301. unsigned int cardid; /* pci subsystem id (bt878 based ones) */
  302. unsigned int tuner_type; /* tuner chip type */
  303. unsigned int tda9887_conf;
  304. unsigned int svhs, dig;
  305. unsigned int has_saa6588:1;
  306. struct bttv_pll_info pll;
  307. int triton1;
  308. int gpioirq;
  309. int use_i2c_hw;
  310. /* old gpio interface */
  311. int shutdown;
  312. void (*volume_gpio)(struct bttv *btv, __u16 volume);
  313. void (*audio_mode_gpio)(struct bttv *btv, struct v4l2_tuner *tuner, int set);
  314. /* new gpio interface */
  315. spinlock_t gpio_lock;
  316. /* i2c layer */
  317. struct i2c_algo_bit_data i2c_algo;
  318. struct i2c_client i2c_client;
  319. int i2c_state, i2c_rc;
  320. int i2c_done;
  321. wait_queue_head_t i2c_queue;
  322. struct v4l2_subdev *sd_msp34xx;
  323. struct v4l2_subdev *sd_tvaudio;
  324. /* video4linux (1) */
  325. struct video_device *video_dev;
  326. struct video_device *radio_dev;
  327. struct video_device *vbi_dev;
  328. /* infrared remote */
  329. int has_remote;
  330. struct bttv_ir *remote;
  331. /* I2C remote data */
  332. struct IR_i2c_init_data init_data;
  333. /* locking */
  334. spinlock_t s_lock;
  335. struct mutex lock;
  336. int resources;
  337. #ifdef VIDIOC_G_PRIORITY
  338. struct v4l2_prio_state prio;
  339. #endif
  340. /* video state */
  341. unsigned int input;
  342. unsigned int audio;
  343. unsigned int mute;
  344. unsigned long freq;
  345. unsigned int tvnorm;
  346. int hue, contrast, bright, saturation;
  347. struct v4l2_framebuffer fbuf;
  348. unsigned int field_count;
  349. /* various options */
  350. int opt_combfilter;
  351. int opt_lumafilter;
  352. int opt_automute;
  353. int opt_chroma_agc;
  354. int opt_adc_crush;
  355. int opt_vcr_hack;
  356. int opt_whitecrush_upper;
  357. int opt_whitecrush_lower;
  358. int opt_uv_ratio;
  359. int opt_full_luma_range;
  360. int opt_coring;
  361. /* radio data/state */
  362. int has_radio;
  363. int radio_user;
  364. /* miro/pinnacle + Aimslab VHX
  365. philips matchbox (tea5757 radio tuner) support */
  366. int has_matchbox;
  367. int mbox_we;
  368. int mbox_data;
  369. int mbox_clk;
  370. int mbox_most;
  371. int mbox_mask;
  372. /* ISA stuff (Terratec Active Radio Upgrade) */
  373. int mbox_ior;
  374. int mbox_iow;
  375. int mbox_csel;
  376. /* risc memory management data
  377. - must acquire s_lock before changing these
  378. - only the irq handler is supported to touch top + bottom + vcurr */
  379. struct btcx_riscmem main;
  380. struct bttv_buffer *screen; /* overlay */
  381. struct list_head capture; /* video capture queue */
  382. struct list_head vcapture; /* vbi capture queue */
  383. struct bttv_buffer_set curr; /* active buffers */
  384. struct bttv_buffer *cvbi; /* active vbi buffer */
  385. int loop_irq;
  386. int new_input;
  387. unsigned long cap_ctl;
  388. unsigned long dma_on;
  389. struct timer_list timeout;
  390. struct bttv_suspend_state state;
  391. /* stats */
  392. unsigned int errors;
  393. unsigned int framedrop;
  394. unsigned int irq_total;
  395. unsigned int irq_me;
  396. unsigned int users;
  397. struct bttv_fh init;
  398. /* used to make dvb-bt8xx autoloadable */
  399. struct work_struct request_module_wk;
  400. /* Default (0) and current (1) video capturing and overlay
  401. cropping parameters in bttv_tvnorm.cropcap units. Protected
  402. by bttv.lock. */
  403. struct bttv_crop crop[2];
  404. /* Earliest possible start of video capturing in
  405. bttv_tvnorm.cropcap line units. Set by check_alloc_btres()
  406. and free_btres(). Protected by bttv.lock. */
  407. __s32 vbi_end;
  408. /* Latest possible end of VBI capturing (= crop[x].rect.top when
  409. VIDEO_RESOURCES are locked). Set by check_alloc_btres()
  410. and free_btres(). Protected by bttv.lock. */
  411. __s32 crop_start;
  412. };
  413. static inline struct bttv *to_bttv(struct v4l2_device *v4l2_dev)
  414. {
  415. return container_of(v4l2_dev, struct bttv, c.v4l2_dev);
  416. }
  417. /* our devices */
  418. #define BTTV_MAX 32
  419. extern unsigned int bttv_num;
  420. extern struct bttv *bttvs[BTTV_MAX];
  421. static inline unsigned int bttv_muxsel(const struct bttv *btv,
  422. unsigned int input)
  423. {
  424. return (bttv_tvcards[btv->c.type].muxsel >> (input * 2)) & 3;
  425. }
  426. #endif
  427. #define btwrite(dat,adr) writel((dat), btv->bt848_mmio+(adr))
  428. #define btread(adr) readl(btv->bt848_mmio+(adr))
  429. #define btand(dat,adr) btwrite((dat) & btread(adr), adr)
  430. #define btor(dat,adr) btwrite((dat) | btread(adr), adr)
  431. #define btaor(dat,mask,adr) btwrite((dat) | ((mask) & btread(adr)), adr)
  432. #endif /* _BTTVP_H_ */
  433. /*
  434. * Local variables:
  435. * c-basic-offset: 8
  436. * End:
  437. */