zoran.h 16 KB

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