zoran.h 16 KB

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