bttvp.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. /*
  2. $Id: bttvp.h,v 1.21 2005/07/15 21:44:14 mchehab Exp $
  3. bttv - Bt848 frame grabber driver
  4. bttv's *private* header file -- nobody other than bttv itself
  5. should ever include this file.
  6. (c) 2000-2002 Gerd Knorr <kraxel@bytesex.org>
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19. #ifndef _BTTVP_H_
  20. #define _BTTVP_H_
  21. #include <linux/version.h>
  22. #define BTTV_VERSION_CODE KERNEL_VERSION(0,9,16)
  23. #include <linux/types.h>
  24. #include <linux/wait.h>
  25. #include <linux/i2c.h>
  26. #include <linux/i2c-algo-bit.h>
  27. #include <linux/videodev.h>
  28. #include <linux/pci.h>
  29. #include <linux/input.h>
  30. #include <asm/scatterlist.h>
  31. #include <asm/io.h>
  32. #include <linux/device.h>
  33. #include <media/video-buf.h>
  34. #include <media/audiochip.h>
  35. #include <media/tuner.h>
  36. #include <media/tveeprom.h>
  37. #include <media/ir-common.h>
  38. #include "bt848.h"
  39. #include "bttv.h"
  40. #include "btcx-risc.h"
  41. #ifdef __KERNEL__
  42. #define FORMAT_FLAGS_DITHER 0x01
  43. #define FORMAT_FLAGS_PACKED 0x02
  44. #define FORMAT_FLAGS_PLANAR 0x04
  45. #define FORMAT_FLAGS_RAW 0x08
  46. #define FORMAT_FLAGS_CrCb 0x10
  47. #define RISC_SLOT_O_VBI 4
  48. #define RISC_SLOT_O_FIELD 6
  49. #define RISC_SLOT_E_VBI 10
  50. #define RISC_SLOT_E_FIELD 12
  51. #define RISC_SLOT_LOOP 14
  52. #define RESOURCE_OVERLAY 1
  53. #define RESOURCE_VIDEO 2
  54. #define RESOURCE_VBI 4
  55. #define RAW_LINES 640
  56. #define RAW_BPL 1024
  57. #define UNSET (-1U)
  58. /* ---------------------------------------------------------- */
  59. struct bttv_tvnorm {
  60. int v4l2_id;
  61. char *name;
  62. u32 Fsc;
  63. u16 swidth, sheight; /* scaled standard width, height */
  64. u16 totalwidth;
  65. u8 adelay, bdelay, iform;
  66. u32 scaledtwidth;
  67. u16 hdelayx1, hactivex1;
  68. u16 vdelay;
  69. u8 vbipack;
  70. u16 vtotal;
  71. int sram;
  72. };
  73. extern const struct bttv_tvnorm bttv_tvnorms[];
  74. struct bttv_format {
  75. char *name;
  76. int palette; /* video4linux 1 */
  77. int fourcc; /* video4linux 2 */
  78. int btformat; /* BT848_COLOR_FMT_* */
  79. int btswap; /* BT848_COLOR_CTL_* */
  80. int depth; /* bit/pixel */
  81. int flags;
  82. int hshift,vshift; /* for planar modes */
  83. };
  84. /* ---------------------------------------------------------- */
  85. struct bttv_geometry {
  86. u8 vtc,crop,comb;
  87. u16 width,hscale,hdelay;
  88. u16 sheight,vscale,vdelay,vtotal;
  89. };
  90. struct bttv_buffer {
  91. /* common v4l buffer stuff -- must be first */
  92. struct videobuf_buffer vb;
  93. /* bttv specific */
  94. const struct bttv_format *fmt;
  95. int tvnorm;
  96. int btformat;
  97. int btswap;
  98. struct bttv_geometry geo;
  99. struct btcx_riscmem top;
  100. struct btcx_riscmem bottom;
  101. };
  102. struct bttv_buffer_set {
  103. struct bttv_buffer *top; /* top field buffer */
  104. struct bttv_buffer *bottom; /* bottom field buffer */
  105. unsigned int top_irq;
  106. unsigned int frame_irq;
  107. };
  108. struct bttv_overlay {
  109. int tvnorm;
  110. struct v4l2_rect w;
  111. enum v4l2_field field;
  112. struct v4l2_clip *clips;
  113. int nclips;
  114. int setup_ok;
  115. };
  116. struct bttv_fh {
  117. struct bttv *btv;
  118. int resources;
  119. #ifdef VIDIOC_G_PRIORITY
  120. enum v4l2_priority prio;
  121. #endif
  122. enum v4l2_buf_type type;
  123. /* video capture */
  124. struct videobuf_queue cap;
  125. const struct bttv_format *fmt;
  126. int width;
  127. int height;
  128. /* current settings */
  129. const struct bttv_format *ovfmt;
  130. struct bttv_overlay ov;
  131. /* video overlay */
  132. struct videobuf_queue vbi;
  133. int lines;
  134. };
  135. /* ---------------------------------------------------------- */
  136. /* bttv-risc.c */
  137. /* risc code generators - capture */
  138. int bttv_risc_packed(struct bttv *btv, struct btcx_riscmem *risc,
  139. struct scatterlist *sglist,
  140. unsigned int offset, unsigned int bpl,
  141. unsigned int pitch, unsigned int lines);
  142. /* control dma register + risc main loop */
  143. void bttv_set_dma(struct bttv *btv, int override);
  144. int bttv_risc_init_main(struct bttv *btv);
  145. int bttv_risc_hook(struct bttv *btv, int slot, struct btcx_riscmem *risc,
  146. int irqflags);
  147. /* capture buffer handling */
  148. int bttv_buffer_risc(struct bttv *btv, struct bttv_buffer *buf);
  149. int bttv_buffer_activate_video(struct bttv *btv,
  150. struct bttv_buffer_set *set);
  151. int bttv_buffer_activate_vbi(struct bttv *btv,
  152. struct bttv_buffer *vbi);
  153. void bttv_dma_free(struct bttv *btv, struct bttv_buffer *buf);
  154. /* overlay handling */
  155. int bttv_overlay_risc(struct bttv *btv, struct bttv_overlay *ov,
  156. const struct bttv_format *fmt,
  157. struct bttv_buffer *buf);
  158. /* ---------------------------------------------------------- */
  159. /* bttv-vbi.c */
  160. void bttv_vbi_try_fmt(struct bttv_fh *fh, struct v4l2_format *f);
  161. void bttv_vbi_get_fmt(struct bttv_fh *fh, struct v4l2_format *f);
  162. void bttv_vbi_setlines(struct bttv_fh *fh, struct bttv *btv, int lines);
  163. extern struct videobuf_queue_ops bttv_vbi_qops;
  164. /* ---------------------------------------------------------- */
  165. /* bttv-gpio.c */
  166. extern struct bus_type bttv_sub_bus_type;
  167. int bttv_sub_add_device(struct bttv_core *core, char *name);
  168. int bttv_sub_del_devices(struct bttv_core *core);
  169. void bttv_gpio_irq(struct bttv_core *core);
  170. /* ---------------------------------------------------------- */
  171. /* bttv-driver.c */
  172. /* insmod options */
  173. extern unsigned int bttv_verbose;
  174. extern unsigned int bttv_debug;
  175. extern unsigned int bttv_gpio;
  176. extern void bttv_gpio_tracking(struct bttv *btv, char *comment);
  177. extern int init_bttv_i2c(struct bttv *btv);
  178. extern int fini_bttv_i2c(struct bttv *btv);
  179. #define vprintk if (bttv_verbose) printk
  180. #define dprintk if (bttv_debug >= 1) printk
  181. #define d2printk if (bttv_debug >= 2) printk
  182. #define BTTV_MAX_FBUF 0x208000
  183. #define VBIBUF_SIZE (2048*VBI_MAXLINES*2)
  184. #define BTTV_TIMEOUT (HZ/2) /* 0.5 seconds */
  185. #define BTTV_FREE_IDLE (HZ) /* one second */
  186. struct bttv_pll_info {
  187. unsigned int pll_ifreq; /* PLL input frequency */
  188. unsigned int pll_ofreq; /* PLL output frequency */
  189. unsigned int pll_crystal; /* Crystal used for input */
  190. unsigned int pll_current; /* Currently programmed ofreq */
  191. };
  192. /* for gpio-connected remote control */
  193. struct bttv_input {
  194. struct input_dev dev;
  195. struct ir_input_state ir;
  196. char name[32];
  197. char phys[32];
  198. u32 mask_keycode;
  199. u32 mask_keydown;
  200. };
  201. struct bttv_suspend_state {
  202. u32 gpio_enable;
  203. u32 gpio_data;
  204. int disabled;
  205. int loop_irq;
  206. struct bttv_buffer_set video;
  207. struct bttv_buffer *vbi;
  208. };
  209. struct bttv {
  210. struct bttv_core c;
  211. /* pci device config */
  212. unsigned short id;
  213. unsigned char revision;
  214. unsigned char __iomem *bt848_mmio; /* pointer to mmio */
  215. /* card configuration info */
  216. unsigned int cardid; /* pci subsystem id (bt878 based ones) */
  217. unsigned int tuner_type; /* tuner chip type */
  218. unsigned int pinnacle_id;
  219. unsigned int svhs;
  220. struct bttv_pll_info pll;
  221. int triton1;
  222. int gpioirq;
  223. int use_i2c_hw;
  224. /* old gpio interface */
  225. wait_queue_head_t gpioq;
  226. int shutdown;
  227. void (*audio_hook)(struct bttv *btv, struct video_audio *v, int set);
  228. /* new gpio interface */
  229. spinlock_t gpio_lock;
  230. /* i2c layer */
  231. struct i2c_algo_bit_data i2c_algo;
  232. struct i2c_client i2c_client;
  233. int i2c_state, i2c_rc;
  234. int i2c_done;
  235. wait_queue_head_t i2c_queue;
  236. /* video4linux (1) */
  237. struct video_device *video_dev;
  238. struct video_device *radio_dev;
  239. struct video_device *vbi_dev;
  240. /* infrared remote */
  241. int has_remote;
  242. struct bttv_input *remote;
  243. /* locking */
  244. spinlock_t s_lock;
  245. struct semaphore lock;
  246. int resources;
  247. struct semaphore reslock;
  248. #ifdef VIDIOC_G_PRIORITY
  249. struct v4l2_prio_state prio;
  250. #endif
  251. /* video state */
  252. unsigned int input;
  253. unsigned int audio;
  254. unsigned long freq;
  255. int tvnorm,hue,contrast,bright,saturation;
  256. struct v4l2_framebuffer fbuf;
  257. unsigned int field_count;
  258. /* various options */
  259. int opt_combfilter;
  260. int opt_lumafilter;
  261. int opt_automute;
  262. int opt_chroma_agc;
  263. int opt_adc_crush;
  264. int opt_vcr_hack;
  265. int opt_whitecrush_upper;
  266. int opt_whitecrush_lower;
  267. int opt_uv_ratio;
  268. int opt_full_luma_range;
  269. int opt_coring;
  270. /* radio data/state */
  271. int has_radio;
  272. int radio_user;
  273. /* miro/pinnacle + Aimslab VHX
  274. philips matchbox (tea5757 radio tuner) support */
  275. int has_matchbox;
  276. int mbox_we;
  277. int mbox_data;
  278. int mbox_clk;
  279. int mbox_most;
  280. int mbox_mask;
  281. /* ISA stuff (Terratec Active Radio Upgrade) */
  282. int mbox_ior;
  283. int mbox_iow;
  284. int mbox_csel;
  285. /* risc memory management data
  286. - must aquire s_lock before changing these
  287. - only the irq handler is supported to touch top + bottom + vcurr */
  288. struct btcx_riscmem main;
  289. struct bttv_buffer *screen; /* overlay */
  290. struct list_head capture; /* video capture queue */
  291. struct list_head vcapture; /* vbi capture queue */
  292. struct bttv_buffer_set curr; /* active buffers */
  293. struct bttv_buffer *cvbi; /* active vbi buffer */
  294. int loop_irq;
  295. int new_input;
  296. unsigned long cap_ctl;
  297. unsigned long dma_on;
  298. struct timer_list timeout;
  299. struct bttv_suspend_state state;
  300. /* stats */
  301. unsigned int errors;
  302. unsigned int framedrop;
  303. unsigned int irq_total;
  304. unsigned int irq_me;
  305. unsigned int users;
  306. struct bttv_fh init;
  307. };
  308. /* our devices */
  309. #define BTTV_MAX 16
  310. extern unsigned int bttv_num;
  311. extern struct bttv bttvs[BTTV_MAX];
  312. /* private ioctls */
  313. #define BTTV_VERSION _IOR('v' , BASE_VIDIOCPRIVATE+6, int)
  314. #define BTTV_VBISIZE _IOR('v' , BASE_VIDIOCPRIVATE+8, int)
  315. #endif
  316. #define btwrite(dat,adr) writel((dat), btv->bt848_mmio+(adr))
  317. #define btread(adr) readl(btv->bt848_mmio+(adr))
  318. #define btand(dat,adr) btwrite((dat) & btread(adr), adr)
  319. #define btor(dat,adr) btwrite((dat) | btread(adr), adr)
  320. #define btaor(dat,mask,adr) btwrite((dat) | ((mask) & btread(adr)), adr)
  321. #endif /* _BTTVP_H_ */
  322. /*
  323. * Local variables:
  324. * c-basic-offset: 8
  325. * End:
  326. */