bttvp.h 15 KB

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