zoran.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  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. #define MAX_KMALLOC_MEM (128*1024)
  141. #include "zr36057.h"
  142. enum card_type {
  143. UNKNOWN = -1,
  144. /* Pinnacle/Miro */
  145. DC10_old, /* DC30 like */
  146. DC10_new, /* DC10plus like */
  147. DC10plus,
  148. DC30,
  149. DC30plus,
  150. /* Linux Media Labs */
  151. LML33,
  152. LML33R10,
  153. /* Iomega */
  154. BUZ,
  155. /* AverMedia */
  156. AVS6EYES,
  157. /* total number of cards */
  158. NUM_CARDS
  159. };
  160. enum zoran_codec_mode {
  161. BUZ_MODE_IDLE, /* nothing going on */
  162. BUZ_MODE_MOTION_COMPRESS, /* grabbing frames */
  163. BUZ_MODE_MOTION_DECOMPRESS, /* playing frames */
  164. BUZ_MODE_STILL_COMPRESS, /* still frame conversion */
  165. BUZ_MODE_STILL_DECOMPRESS /* still frame conversion */
  166. };
  167. enum zoran_buffer_state {
  168. BUZ_STATE_USER, /* buffer is owned by application */
  169. BUZ_STATE_PEND, /* buffer is queued in pend[] ready to feed to I/O */
  170. BUZ_STATE_DMA, /* buffer is queued in dma[] for I/O */
  171. BUZ_STATE_DONE /* buffer is ready to return to application */
  172. };
  173. enum zoran_map_mode {
  174. ZORAN_MAP_MODE_RAW,
  175. ZORAN_MAP_MODE_JPG_REC,
  176. #define ZORAN_MAP_MODE_JPG ZORAN_MAP_MODE_JPG_REC
  177. ZORAN_MAP_MODE_JPG_PLAY,
  178. };
  179. enum gpio_type {
  180. GPIO_JPEG_SLEEP = 0,
  181. GPIO_JPEG_RESET,
  182. GPIO_JPEG_FRAME,
  183. GPIO_VID_DIR,
  184. GPIO_VID_EN,
  185. GPIO_VID_RESET,
  186. GPIO_CLK_SEL1,
  187. GPIO_CLK_SEL2,
  188. GPIO_MAX,
  189. };
  190. enum gpcs_type {
  191. GPCS_JPEG_RESET = 0,
  192. GPCS_JPEG_START,
  193. GPCS_MAX,
  194. };
  195. struct zoran_format {
  196. char *name;
  197. #ifdef CONFIG_VIDEO_V4L1_COMPAT
  198. int palette;
  199. #endif
  200. #ifdef CONFIG_VIDEO_V4L2
  201. __u32 fourcc;
  202. int colorspace;
  203. #endif
  204. int depth;
  205. __u32 flags;
  206. __u32 vfespfr;
  207. };
  208. /* flags */
  209. #define ZORAN_FORMAT_COMPRESSED 1<<0
  210. #define ZORAN_FORMAT_OVERLAY 1<<1
  211. #define ZORAN_FORMAT_CAPTURE 1<<2
  212. #define ZORAN_FORMAT_PLAYBACK 1<<3
  213. /* overlay-settings */
  214. struct zoran_overlay_settings {
  215. int is_set;
  216. int x, y, width, height; /* position */
  217. int clipcount; /* position and number of clips */
  218. const struct zoran_format *format; /* overlay format */
  219. };
  220. /* v4l-capture settings */
  221. struct zoran_v4l_settings {
  222. int width, height, bytesperline; /* capture size */
  223. const struct zoran_format *format; /* capture format */
  224. };
  225. /* whoops, this one is undeclared if !v4l2 */
  226. #ifndef CONFIG_VIDEO_V4L2
  227. struct v4l2_jpegcompression {
  228. int quality;
  229. int APPn;
  230. int APP_len;
  231. char APP_data[60];
  232. int COM_len;
  233. char COM_data[60];
  234. __u32 jpeg_markers;
  235. __u8 reserved[116];
  236. };
  237. #endif
  238. /* jpg-capture/-playback settings */
  239. struct zoran_jpg_settings {
  240. int decimation; /* this bit is used to set everything to default */
  241. int HorDcm, VerDcm, TmpDcm; /* capture decimation settings (TmpDcm=1 means both fields) */
  242. int field_per_buff, odd_even; /* field-settings (odd_even=1 (+TmpDcm=1) means top-field-first) */
  243. int img_x, img_y, img_width, img_height; /* crop settings (subframe capture) */
  244. struct v4l2_jpegcompression jpg_comp; /* JPEG-specific capture settings */
  245. };
  246. struct zoran_mapping {
  247. struct file *file;
  248. int count;
  249. };
  250. struct zoran_jpg_buffer {
  251. struct zoran_mapping *map;
  252. u32 *frag_tab; /* addresses of frag table */
  253. u32 frag_tab_bus; /* same value cached to save time in ISR */
  254. enum zoran_buffer_state state; /* non-zero if corresponding buffer is in use in grab queue */
  255. struct zoran_sync bs; /* DONE: info to return to application */
  256. };
  257. struct zoran_v4l_buffer {
  258. struct zoran_mapping *map;
  259. char *fbuffer; /* virtual address of frame buffer */
  260. unsigned long fbuffer_phys; /* physical address of frame buffer */
  261. unsigned long fbuffer_bus; /* bus address of frame buffer */
  262. enum zoran_buffer_state state; /* state: unused/pending/done */
  263. struct zoran_sync bs; /* DONE: info to return to application */
  264. };
  265. enum zoran_lock_activity {
  266. ZORAN_FREE, /* free for use */
  267. ZORAN_ACTIVE, /* active but unlocked */
  268. ZORAN_LOCKED, /* locked */
  269. };
  270. /* buffer collections */
  271. struct zoran_jpg_struct {
  272. enum zoran_lock_activity active; /* feature currently in use? */
  273. struct zoran_jpg_buffer buffer[BUZ_MAX_FRAME]; /* buffers */
  274. int num_buffers, buffer_size;
  275. u8 allocated; /* Flag if buffers are allocated */
  276. u8 ready_to_be_freed; /* hack - see zoran_driver.c */
  277. u8 need_contiguous; /* Flag if contiguous buffers are needed */
  278. };
  279. struct zoran_v4l_struct {
  280. enum zoran_lock_activity active; /* feature currently in use? */
  281. struct zoran_v4l_buffer buffer[VIDEO_MAX_FRAME]; /* buffers */
  282. int num_buffers, buffer_size;
  283. u8 allocated; /* Flag if buffers are allocated */
  284. u8 ready_to_be_freed; /* hack - see zoran_driver.c */
  285. };
  286. struct zoran;
  287. /* zoran_fh contains per-open() settings */
  288. struct zoran_fh {
  289. struct zoran *zr;
  290. enum zoran_map_mode map_mode; /* Flag which bufferset will map by next mmap() */
  291. struct zoran_overlay_settings overlay_settings;
  292. u32 *overlay_mask; /* overlay mask */
  293. enum zoran_lock_activity overlay_active; /* feature currently in use? */
  294. struct zoran_v4l_settings v4l_settings; /* structure with a lot of things to play with */
  295. struct zoran_v4l_struct v4l_buffers; /* V4L buffers' info */
  296. struct zoran_jpg_settings jpg_settings; /* structure with a lot of things to play with */
  297. struct zoran_jpg_struct jpg_buffers; /* MJPEG buffers' info */
  298. };
  299. struct card_info {
  300. enum card_type type;
  301. char name[32];
  302. u16 i2c_decoder, i2c_encoder; /* I2C types */
  303. u16 video_vfe, video_codec; /* videocodec types */
  304. u16 audio_chip; /* audio type */
  305. u16 vendor_id, device_id; /* subsystem vendor/device ID */
  306. int inputs; /* number of video inputs */
  307. struct input {
  308. int muxsel;
  309. char name[32];
  310. } input[BUZ_MAX_INPUT];
  311. int norms;
  312. struct tvnorm *tvn[3]; /* supported TV norms */
  313. u32 jpeg_int; /* JPEG interrupt */
  314. u32 vsync_int; /* VSYNC interrupt */
  315. s8 gpio[GPIO_MAX];
  316. u8 gpcs[GPCS_MAX];
  317. struct vfe_polarity vfe_pol;
  318. u8 gpio_pol[GPIO_MAX];
  319. /* is the /GWS line conected? */
  320. u8 gws_not_connected;
  321. /* avs6eyes mux setting */
  322. u8 input_mux;
  323. void (*init) (struct zoran * zr);
  324. };
  325. struct zoran {
  326. struct video_device *video_dev;
  327. struct i2c_adapter i2c_adapter; /* */
  328. struct i2c_algo_bit_data i2c_algo; /* */
  329. u32 i2cbr;
  330. struct i2c_client *decoder; /* video decoder i2c client */
  331. struct i2c_client *encoder; /* video encoder i2c client */
  332. struct videocodec *codec; /* video codec */
  333. struct videocodec *vfe; /* video front end */
  334. struct mutex resource_lock; /* prevent evil stuff */
  335. u8 initialized; /* flag if zoran has been correctly initalized */
  336. int user; /* number of current users */
  337. struct card_info card;
  338. struct tvnorm *timing;
  339. unsigned short id; /* number of this device */
  340. char name[32]; /* name of this device */
  341. struct pci_dev *pci_dev; /* PCI device */
  342. unsigned char revision; /* revision of zr36057 */
  343. unsigned int zr36057_adr; /* bus address of IO mem returned by PCI BIOS */
  344. unsigned char __iomem *zr36057_mem;/* pointer to mapped IO memory */
  345. spinlock_t spinlock; /* Spinlock */
  346. /* Video for Linux parameters */
  347. int input, norm; /* card's norm and input - norm=VIDEO_MODE_* */
  348. int hue, saturation, contrast, brightness; /* Current picture params */
  349. struct video_buffer buffer; /* Current buffer params */
  350. struct zoran_overlay_settings overlay_settings;
  351. u32 *overlay_mask; /* overlay mask */
  352. enum zoran_lock_activity overlay_active; /* feature currently in use? */
  353. wait_queue_head_t v4l_capq;
  354. int v4l_overlay_active; /* Overlay grab is activated */
  355. int v4l_memgrab_active; /* Memory grab is activated */
  356. int v4l_grab_frame; /* Frame number being currently grabbed */
  357. #define NO_GRAB_ACTIVE (-1)
  358. unsigned long v4l_grab_seq; /* Number of frames grabbed */
  359. struct zoran_v4l_settings v4l_settings; /* structure with a lot of things to play with */
  360. /* V4L grab queue of frames pending */
  361. unsigned long v4l_pend_head;
  362. unsigned long v4l_pend_tail;
  363. unsigned long v4l_sync_tail;
  364. int v4l_pend[V4L_MAX_FRAME];
  365. struct zoran_v4l_struct v4l_buffers; /* V4L buffers' info */
  366. /* Buz MJPEG parameters */
  367. enum zoran_codec_mode codec_mode; /* status of codec */
  368. struct zoran_jpg_settings jpg_settings; /* structure with a lot of things to play with */
  369. wait_queue_head_t jpg_capq; /* wait here for grab to finish */
  370. /* grab queue counts/indices, mask with BUZ_MASK_STAT_COM before using as index */
  371. /* (dma_head - dma_tail) is number active in DMA, must be <= BUZ_NUM_STAT_COM */
  372. /* (value & BUZ_MASK_STAT_COM) corresponds to index in stat_com table */
  373. unsigned long jpg_que_head; /* Index where to put next buffer which is queued */
  374. unsigned long jpg_dma_head; /* Index of next buffer which goes into stat_com */
  375. unsigned long jpg_dma_tail; /* Index of last buffer in stat_com */
  376. unsigned long jpg_que_tail; /* Index of last buffer in queue */
  377. unsigned long jpg_seq_num; /* count of frames since grab/play started */
  378. unsigned long jpg_err_seq; /* last seq_num before error */
  379. unsigned long jpg_err_shift;
  380. unsigned long jpg_queued_num; /* count of frames queued since grab/play started */
  381. /* zr36057's code buffer table */
  382. u32 *stat_com; /* stat_com[i] is indexed by dma_head/tail & BUZ_MASK_STAT_COM */
  383. /* (value & BUZ_MASK_FRAME) corresponds to index in pend[] queue */
  384. int jpg_pend[BUZ_MAX_FRAME];
  385. /* array indexed by frame number */
  386. struct zoran_jpg_struct jpg_buffers; /* MJPEG buffers' info */
  387. /* Additional stuff for testing */
  388. #ifdef CONFIG_PROC_FS
  389. struct proc_dir_entry *zoran_proc;
  390. #else
  391. void *zoran_proc;
  392. #endif
  393. int testing;
  394. int jpeg_error;
  395. int intr_counter_GIRQ1;
  396. int intr_counter_GIRQ0;
  397. int intr_counter_CodRepIRQ;
  398. int intr_counter_JPEGRepIRQ;
  399. int field_counter;
  400. int IRQ1_in;
  401. int IRQ1_out;
  402. int JPEG_in;
  403. int JPEG_out;
  404. int JPEG_0;
  405. int JPEG_1;
  406. int END_event_missed;
  407. int JPEG_missed;
  408. int JPEG_error;
  409. int num_errors;
  410. int JPEG_max_missed;
  411. int JPEG_min_missed;
  412. u32 last_isr;
  413. unsigned long frame_num;
  414. wait_queue_head_t test_q;
  415. };
  416. /*The following should be done in more portable way. It depends on define
  417. of _ALPHA_BUZ in the Makefile.*/
  418. #ifdef _ALPHA_BUZ
  419. #define btwrite(dat,adr) writel((dat), zr->zr36057_adr+(adr))
  420. #define btread(adr) readl(zr->zr36057_adr+(adr))
  421. #else
  422. #define btwrite(dat,adr) writel((dat), zr->zr36057_mem+(adr))
  423. #define btread(adr) readl(zr->zr36057_mem+(adr))
  424. #endif
  425. #define btand(dat,adr) btwrite((dat) & btread(adr), adr)
  426. #define btor(dat,adr) btwrite((dat) | btread(adr), adr)
  427. #define btaor(dat,mask,adr) btwrite((dat) | ((mask) & btread(adr)), adr)
  428. #endif /* __kernel__ */
  429. #endif