zoran.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. /*
  2. * zoran - Iomega Buz driver
  3. *
  4. * Copyright (C) 1999 Rainer Johanni <Rainer@Johanni.de>
  5. *
  6. * based on
  7. *
  8. * zoran.0.0.3 Copyright (C) 1998 Dave Perks <dperks@ibm.net>
  9. *
  10. * and
  11. *
  12. * bttv - Bt848 frame grabber driver
  13. * Copyright (C) 1996,97,98 Ralph Metzler (rjkm@thp.uni-koeln.de)
  14. * & Marcus Metzler (mocm@thp.uni-koeln.de)
  15. *
  16. * This program is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License as published by
  18. * the Free Software Foundation; either version 2 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program; if not, write to the Free Software
  28. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  29. */
  30. #ifndef _BUZ_H_
  31. #define _BUZ_H_
  32. #include <media/v4l2-device.h>
  33. #define ZORAN_VIDMODE_PAL 0
  34. #define ZORAN_VIDMODE_NTSC 1
  35. #define ZORAN_VIDMODE_SECAM 2
  36. struct zoran_requestbuffers {
  37. unsigned long count; /* Number of buffers for MJPEG grabbing */
  38. unsigned long size; /* Size PER BUFFER in bytes */
  39. };
  40. struct zoran_sync {
  41. unsigned long frame; /* number of buffer that has been free'd */
  42. unsigned long length; /* number of code bytes in buffer (capture only) */
  43. unsigned long seq; /* frame sequence number */
  44. struct timeval timestamp; /* timestamp */
  45. };
  46. struct zoran_status {
  47. int input; /* Input channel, has to be set prior to BUZIOC_G_STATUS */
  48. int signal; /* Returned: 1 if valid video signal detected */
  49. int norm; /* Returned: ZORAN_VIDMODE_PAL or ZORAN_VIDMODE_NTSC */
  50. int color; /* Returned: 1 if color signal detected */
  51. };
  52. struct zoran_params {
  53. /* The following parameters can only be queried */
  54. int major_version; /* Major version number of driver */
  55. int minor_version; /* Minor version number of driver */
  56. /* Main control parameters */
  57. int input; /* Input channel: 0 = Composite, 1 = S-VHS */
  58. int norm; /* Norm: ZORAN_VIDMODE_PAL or ZORAN_VIDMODE_NTSC */
  59. int decimation; /* decimation of captured video,
  60. * enlargement of video played back.
  61. * Valid values are 1, 2, 4 or 0.
  62. * 0 is a special value where the user
  63. * has full control over video scaling */
  64. /* The following parameters only have to be set if decimation==0,
  65. * for other values of decimation they provide the data how the image is captured */
  66. int HorDcm; /* Horizontal decimation: 1, 2 or 4 */
  67. int VerDcm; /* Vertical decimation: 1 or 2 */
  68. int TmpDcm; /* Temporal decimation: 1 or 2,
  69. * if TmpDcm==2 in capture every second frame is dropped,
  70. * in playback every frame is played twice */
  71. int field_per_buff; /* Number of fields per buffer: 1 or 2 */
  72. int img_x; /* start of image in x direction */
  73. int img_y; /* start of image in y direction */
  74. int img_width; /* image width BEFORE decimation,
  75. * must be a multiple of HorDcm*16 */
  76. int img_height; /* image height BEFORE decimation,
  77. * must be a multiple of VerDcm*8 */
  78. /* --- End of parameters for decimation==0 only --- */
  79. /* JPEG control parameters */
  80. int quality; /* Measure for quality of compressed images.
  81. * Scales linearly with the size of the compressed images.
  82. * Must be beetween 0 and 100, 100 is a compression
  83. * ratio of 1:4 */
  84. int odd_even; /* Which field should come first ??? */
  85. int APPn; /* Number of APP segment to be written, must be 0..15 */
  86. int APP_len; /* Length of data in JPEG APPn segment */
  87. char APP_data[60]; /* Data in the JPEG APPn segment. */
  88. int COM_len; /* Length of data in JPEG COM segment */
  89. char COM_data[60]; /* Data in JPEG COM segment */
  90. unsigned long jpeg_markers; /* Which markers should go into the JPEG output.
  91. * Unless you exactly know what you do, leave them untouched.
  92. * Inluding less markers will make the resulting code
  93. * smaller, but there will be fewer applications
  94. * which can read it.
  95. * The presence of the APP and COM marker is
  96. * influenced by APP0_len and COM_len ONLY! */
  97. #define JPEG_MARKER_DHT (1<<3) /* Define Huffman Tables */
  98. #define JPEG_MARKER_DQT (1<<4) /* Define Quantization Tables */
  99. #define JPEG_MARKER_DRI (1<<5) /* Define Restart Interval */
  100. #define JPEG_MARKER_COM (1<<6) /* Comment segment */
  101. #define JPEG_MARKER_APP (1<<7) /* App segment, driver will allways use APP0 */
  102. int VFIFO_FB; /* Flag for enabling Video Fifo Feedback.
  103. * If this flag is turned on and JPEG decompressing
  104. * is going to the screen, the decompress process
  105. * is stopped every time the Video Fifo is full.
  106. * This enables a smooth decompress to the screen
  107. * but the video output signal will get scrambled */
  108. /* Misc */
  109. char reserved[312]; /* Makes 512 bytes for this structure */
  110. };
  111. /*
  112. Private IOCTL to set up for displaying MJPEG
  113. */
  114. #define BUZIOC_G_PARAMS _IOR ('v', BASE_VIDIOC_PRIVATE+0, struct zoran_params)
  115. #define BUZIOC_S_PARAMS _IOWR('v', BASE_VIDIOC_PRIVATE+1, struct zoran_params)
  116. #define BUZIOC_REQBUFS _IOWR('v', BASE_VIDIOC_PRIVATE+2, struct zoran_requestbuffers)
  117. #define BUZIOC_QBUF_CAPT _IOW ('v', BASE_VIDIOC_PRIVATE+3, int)
  118. #define BUZIOC_QBUF_PLAY _IOW ('v', BASE_VIDIOC_PRIVATE+4, int)
  119. #define BUZIOC_SYNC _IOR ('v', BASE_VIDIOC_PRIVATE+5, struct zoran_sync)
  120. #define BUZIOC_G_STATUS _IOWR('v', BASE_VIDIOC_PRIVATE+6, struct zoran_status)
  121. #ifdef __KERNEL__
  122. #define MAJOR_VERSION 0 /* driver major version */
  123. #define MINOR_VERSION 10 /* driver minor version */
  124. #define RELEASE_VERSION 0 /* release version */
  125. #define ZORAN_NAME "ZORAN" /* name of the device */
  126. #define ZR_DEVNAME(zr) ((zr)->name)
  127. #define BUZ_MAX_WIDTH (zr->timing->Wa)
  128. #define BUZ_MAX_HEIGHT (zr->timing->Ha)
  129. #define BUZ_MIN_WIDTH 32 /* never display less than 32 pixels */
  130. #define BUZ_MIN_HEIGHT 24 /* never display less than 24 rows */
  131. #define BUZ_NUM_STAT_COM 4
  132. #define BUZ_MASK_STAT_COM 3
  133. #define BUZ_MAX_FRAME 256 /* Must be a power of 2 */
  134. #define BUZ_MASK_FRAME 255 /* Must be BUZ_MAX_FRAME-1 */
  135. #define BUZ_MAX_INPUT 16
  136. #if VIDEO_MAX_FRAME <= 32
  137. # define V4L_MAX_FRAME 32
  138. #elif VIDEO_MAX_FRAME <= 64
  139. # define V4L_MAX_FRAME 64
  140. #else
  141. # error "Too many video frame buffers to handle"
  142. #endif
  143. #define V4L_MASK_FRAME (V4L_MAX_FRAME - 1)
  144. #define MAX_FRAME (BUZ_MAX_FRAME > VIDEO_MAX_FRAME ? BUZ_MAX_FRAME : VIDEO_MAX_FRAME)
  145. #include "zr36057.h"
  146. enum card_type {
  147. UNKNOWN = -1,
  148. /* Pinnacle/Miro */
  149. DC10_old, /* DC30 like */
  150. DC10_new, /* DC10plus like */
  151. DC10plus,
  152. DC30,
  153. DC30plus,
  154. /* Linux Media Labs */
  155. LML33,
  156. LML33R10,
  157. /* Iomega */
  158. BUZ,
  159. /* AverMedia */
  160. AVS6EYES,
  161. /* total number of cards */
  162. NUM_CARDS
  163. };
  164. enum zoran_codec_mode {
  165. BUZ_MODE_IDLE, /* nothing going on */
  166. BUZ_MODE_MOTION_COMPRESS, /* grabbing frames */
  167. BUZ_MODE_MOTION_DECOMPRESS, /* playing frames */
  168. BUZ_MODE_STILL_COMPRESS, /* still frame conversion */
  169. BUZ_MODE_STILL_DECOMPRESS /* still frame conversion */
  170. };
  171. enum zoran_buffer_state {
  172. BUZ_STATE_USER, /* buffer is owned by application */
  173. BUZ_STATE_PEND, /* buffer is queued in pend[] ready to feed to I/O */
  174. BUZ_STATE_DMA, /* buffer is queued in dma[] for I/O */
  175. BUZ_STATE_DONE /* buffer is ready to return to application */
  176. };
  177. enum zoran_map_mode {
  178. ZORAN_MAP_MODE_RAW,
  179. ZORAN_MAP_MODE_JPG_REC,
  180. #define ZORAN_MAP_MODE_JPG ZORAN_MAP_MODE_JPG_REC
  181. ZORAN_MAP_MODE_JPG_PLAY,
  182. };
  183. enum gpio_type {
  184. ZR_GPIO_JPEG_SLEEP = 0,
  185. ZR_GPIO_JPEG_RESET,
  186. ZR_GPIO_JPEG_FRAME,
  187. ZR_GPIO_VID_DIR,
  188. ZR_GPIO_VID_EN,
  189. ZR_GPIO_VID_RESET,
  190. ZR_GPIO_CLK_SEL1,
  191. ZR_GPIO_CLK_SEL2,
  192. ZR_GPIO_MAX,
  193. };
  194. enum gpcs_type {
  195. GPCS_JPEG_RESET = 0,
  196. GPCS_JPEG_START,
  197. GPCS_MAX,
  198. };
  199. struct zoran_format {
  200. char *name;
  201. __u32 fourcc;
  202. int colorspace;
  203. int depth;
  204. __u32 flags;
  205. __u32 vfespfr;
  206. };
  207. /* flags */
  208. #define ZORAN_FORMAT_COMPRESSED 1<<0
  209. #define ZORAN_FORMAT_OVERLAY 1<<1
  210. #define ZORAN_FORMAT_CAPTURE 1<<2
  211. #define ZORAN_FORMAT_PLAYBACK 1<<3
  212. /* overlay-settings */
  213. struct zoran_overlay_settings {
  214. int is_set;
  215. int x, y, width, height; /* position */
  216. int clipcount; /* position and number of clips */
  217. const struct zoran_format *format; /* overlay format */
  218. };
  219. /* v4l-capture settings */
  220. struct zoran_v4l_settings {
  221. int width, height, bytesperline; /* capture size */
  222. const struct zoran_format *format; /* capture format */
  223. };
  224. /* jpg-capture/-playback settings */
  225. struct zoran_jpg_settings {
  226. int decimation; /* this bit is used to set everything to default */
  227. int HorDcm, VerDcm, TmpDcm; /* capture decimation settings (TmpDcm=1 means both fields) */
  228. int field_per_buff, odd_even; /* field-settings (odd_even=1 (+TmpDcm=1) means top-field-first) */
  229. int img_x, img_y, img_width, img_height; /* crop settings (subframe capture) */
  230. struct v4l2_jpegcompression jpg_comp; /* JPEG-specific capture settings */
  231. };
  232. struct zoran_mapping {
  233. struct file *file;
  234. int count;
  235. };
  236. struct zoran_buffer {
  237. struct zoran_mapping *map;
  238. enum zoran_buffer_state state; /* state: unused/pending/dma/done */
  239. struct zoran_sync bs; /* DONE: info to return to application */
  240. union {
  241. struct {
  242. __le32 *frag_tab; /* addresses of frag table */
  243. u32 frag_tab_bus; /* same value cached to save time in ISR */
  244. } jpg;
  245. struct {
  246. char *fbuffer; /* virtual address of frame buffer */
  247. unsigned long fbuffer_phys;/* physical address of frame buffer */
  248. unsigned long fbuffer_bus;/* bus address of frame buffer */
  249. } v4l;
  250. };
  251. };
  252. enum zoran_lock_activity {
  253. ZORAN_FREE, /* free for use */
  254. ZORAN_ACTIVE, /* active but unlocked */
  255. ZORAN_LOCKED, /* locked */
  256. };
  257. /* buffer collections */
  258. struct zoran_buffer_col {
  259. enum zoran_lock_activity active; /* feature currently in use? */
  260. unsigned int num_buffers, buffer_size;
  261. struct zoran_buffer buffer[MAX_FRAME]; /* buffers */
  262. u8 allocated; /* Flag if buffers are allocated */
  263. u8 need_contiguous; /* Flag if contiguous buffers are needed */
  264. /* only applies to jpg buffers, raw buffers are always contiguous */
  265. };
  266. struct zoran;
  267. /* zoran_fh contains per-open() settings */
  268. struct zoran_fh {
  269. struct zoran *zr;
  270. enum zoran_map_mode map_mode; /* Flag which bufferset will map by next mmap() */
  271. struct zoran_overlay_settings overlay_settings;
  272. u32 *overlay_mask; /* overlay mask */
  273. enum zoran_lock_activity overlay_active;/* feature currently in use? */
  274. struct zoran_buffer_col buffers; /* buffers' info */
  275. struct zoran_v4l_settings v4l_settings; /* structure with a lot of things to play with */
  276. struct zoran_jpg_settings jpg_settings; /* structure with a lot of things to play with */
  277. };
  278. struct card_info {
  279. enum card_type type;
  280. char name[32];
  281. const char *i2c_decoder; /* i2c decoder device */
  282. const char *mod_decoder; /* i2c decoder module */
  283. const unsigned short *addrs_decoder;
  284. const char *i2c_encoder; /* i2c encoder device */
  285. const char *mod_encoder; /* i2c encoder module */
  286. const unsigned short *addrs_encoder;
  287. u16 video_vfe, video_codec; /* videocodec types */
  288. u16 audio_chip; /* audio type */
  289. int inputs; /* number of video inputs */
  290. struct input {
  291. int muxsel;
  292. char name[32];
  293. } input[BUZ_MAX_INPUT];
  294. v4l2_std_id norms;
  295. struct tvnorm *tvn[3]; /* supported TV norms */
  296. u32 jpeg_int; /* JPEG interrupt */
  297. u32 vsync_int; /* VSYNC interrupt */
  298. s8 gpio[ZR_GPIO_MAX];
  299. u8 gpcs[GPCS_MAX];
  300. struct vfe_polarity vfe_pol;
  301. u8 gpio_pol[ZR_GPIO_MAX];
  302. /* is the /GWS line conected? */
  303. u8 gws_not_connected;
  304. /* avs6eyes mux setting */
  305. u8 input_mux;
  306. void (*init) (struct zoran * zr);
  307. };
  308. struct zoran {
  309. struct v4l2_device v4l2_dev;
  310. struct video_device *video_dev;
  311. struct i2c_adapter i2c_adapter; /* */
  312. struct i2c_algo_bit_data i2c_algo; /* */
  313. u32 i2cbr;
  314. struct v4l2_subdev *decoder; /* video decoder sub-device */
  315. struct v4l2_subdev *encoder; /* video encoder sub-device */
  316. struct videocodec *codec; /* video codec */
  317. struct videocodec *vfe; /* video front end */
  318. struct mutex resource_lock; /* prevent evil stuff */
  319. u8 initialized; /* flag if zoran has been correctly initalized */
  320. int user; /* number of current users */
  321. struct card_info card;
  322. struct tvnorm *timing;
  323. unsigned short id; /* number of this device */
  324. char name[32]; /* name of this device */
  325. struct pci_dev *pci_dev; /* PCI device */
  326. unsigned char revision; /* revision of zr36057 */
  327. unsigned char __iomem *zr36057_mem;/* pointer to mapped IO memory */
  328. spinlock_t spinlock; /* Spinlock */
  329. /* Video for Linux parameters */
  330. int input; /* card's norm and input */
  331. v4l2_std_id norm;
  332. /* Current buffer params */
  333. void *vbuf_base;
  334. int vbuf_height, vbuf_width;
  335. int vbuf_depth;
  336. int vbuf_bytesperline;
  337. struct zoran_overlay_settings overlay_settings;
  338. u32 *overlay_mask; /* overlay mask */
  339. enum zoran_lock_activity overlay_active; /* feature currently in use? */
  340. wait_queue_head_t v4l_capq;
  341. int v4l_overlay_active; /* Overlay grab is activated */
  342. int v4l_memgrab_active; /* Memory grab is activated */
  343. int v4l_grab_frame; /* Frame number being currently grabbed */
  344. #define NO_GRAB_ACTIVE (-1)
  345. unsigned long v4l_grab_seq; /* Number of frames grabbed */
  346. struct zoran_v4l_settings v4l_settings; /* structure with a lot of things to play with */
  347. /* V4L grab queue of frames pending */
  348. unsigned long v4l_pend_head;
  349. unsigned long v4l_pend_tail;
  350. unsigned long v4l_sync_tail;
  351. int v4l_pend[V4L_MAX_FRAME];
  352. struct zoran_buffer_col v4l_buffers; /* V4L buffers' info */
  353. /* Buz MJPEG parameters */
  354. enum zoran_codec_mode codec_mode; /* status of codec */
  355. struct zoran_jpg_settings jpg_settings; /* structure with a lot of things to play with */
  356. wait_queue_head_t jpg_capq; /* wait here for grab to finish */
  357. /* grab queue counts/indices, mask with BUZ_MASK_STAT_COM before using as index */
  358. /* (dma_head - dma_tail) is number active in DMA, must be <= BUZ_NUM_STAT_COM */
  359. /* (value & BUZ_MASK_STAT_COM) corresponds to index in stat_com table */
  360. unsigned long jpg_que_head; /* Index where to put next buffer which is queued */
  361. unsigned long jpg_dma_head; /* Index of next buffer which goes into stat_com */
  362. unsigned long jpg_dma_tail; /* Index of last buffer in stat_com */
  363. unsigned long jpg_que_tail; /* Index of last buffer in queue */
  364. unsigned long jpg_seq_num; /* count of frames since grab/play started */
  365. unsigned long jpg_err_seq; /* last seq_num before error */
  366. unsigned long jpg_err_shift;
  367. unsigned long jpg_queued_num; /* count of frames queued since grab/play started */
  368. /* zr36057's code buffer table */
  369. __le32 *stat_com; /* stat_com[i] is indexed by dma_head/tail & BUZ_MASK_STAT_COM */
  370. /* (value & BUZ_MASK_FRAME) corresponds to index in pend[] queue */
  371. int jpg_pend[BUZ_MAX_FRAME];
  372. /* array indexed by frame number */
  373. struct zoran_buffer_col jpg_buffers; /* MJPEG buffers' info */
  374. /* Additional stuff for testing */
  375. #ifdef CONFIG_PROC_FS
  376. struct proc_dir_entry *zoran_proc;
  377. #else
  378. void *zoran_proc;
  379. #endif
  380. int testing;
  381. int jpeg_error;
  382. int intr_counter_GIRQ1;
  383. int intr_counter_GIRQ0;
  384. int intr_counter_CodRepIRQ;
  385. int intr_counter_JPEGRepIRQ;
  386. int field_counter;
  387. int IRQ1_in;
  388. int IRQ1_out;
  389. int JPEG_in;
  390. int JPEG_out;
  391. int JPEG_0;
  392. int JPEG_1;
  393. int END_event_missed;
  394. int JPEG_missed;
  395. int JPEG_error;
  396. int num_errors;
  397. int JPEG_max_missed;
  398. int JPEG_min_missed;
  399. u32 last_isr;
  400. unsigned long frame_num;
  401. wait_queue_head_t test_q;
  402. };
  403. static inline struct zoran *to_zoran(struct v4l2_device *v4l2_dev)
  404. {
  405. return container_of(v4l2_dev, struct zoran, v4l2_dev);
  406. }
  407. /* There was something called _ALPHA_BUZ that used the PCI address instead of
  408. * the kernel iomapped address for btread/btwrite. */
  409. #define btwrite(dat,adr) writel((dat), zr->zr36057_mem+(adr))
  410. #define btread(adr) readl(zr->zr36057_mem+(adr))
  411. #define btand(dat,adr) btwrite((dat) & btread(adr), adr)
  412. #define btor(dat,adr) btwrite((dat) | btread(adr), adr)
  413. #define btaor(dat,mask,adr) btwrite((dat) | ((mask) & btread(adr)), adr)
  414. #endif /* __kernel__ */
  415. #endif