bttvp.h 14 KB

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