zoran.h 16 KB

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