zoran.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  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. #ifndef _BUZ_H_
  27. #define _BUZ_H_
  28. #include <media/v4l2-device.h>
  29. #include <media/v4l2-ctrls.h>
  30. #include <media/v4l2-fh.h>
  31. struct zoran_sync {
  32. unsigned long frame; /* number of buffer that has been free'd */
  33. unsigned long length; /* number of code bytes in buffer (capture only) */
  34. unsigned long seq; /* frame sequence number */
  35. struct timeval timestamp; /* timestamp */
  36. };
  37. #define ZORAN_NAME "ZORAN" /* name of the device */
  38. #define ZR_DEVNAME(zr) ((zr)->name)
  39. #define BUZ_MAX_WIDTH (zr->timing->Wa)
  40. #define BUZ_MAX_HEIGHT (zr->timing->Ha)
  41. #define BUZ_MIN_WIDTH 32 /* never display less than 32 pixels */
  42. #define BUZ_MIN_HEIGHT 24 /* never display less than 24 rows */
  43. #define BUZ_NUM_STAT_COM 4
  44. #define BUZ_MASK_STAT_COM 3
  45. #define BUZ_MAX_FRAME 256 /* Must be a power of 2 */
  46. #define BUZ_MASK_FRAME 255 /* Must be BUZ_MAX_FRAME-1 */
  47. #define BUZ_MAX_INPUT 16
  48. #if VIDEO_MAX_FRAME <= 32
  49. # define V4L_MAX_FRAME 32
  50. #elif VIDEO_MAX_FRAME <= 64
  51. # define V4L_MAX_FRAME 64
  52. #else
  53. # error "Too many video frame buffers to handle"
  54. #endif
  55. #define V4L_MASK_FRAME (V4L_MAX_FRAME - 1)
  56. #define MAX_FRAME (BUZ_MAX_FRAME > VIDEO_MAX_FRAME ? BUZ_MAX_FRAME : VIDEO_MAX_FRAME)
  57. #include "zr36057.h"
  58. enum card_type {
  59. UNKNOWN = -1,
  60. /* Pinnacle/Miro */
  61. DC10_old, /* DC30 like */
  62. DC10_new, /* DC10plus like */
  63. DC10plus,
  64. DC30,
  65. DC30plus,
  66. /* Linux Media Labs */
  67. LML33,
  68. LML33R10,
  69. /* Iomega */
  70. BUZ,
  71. /* AverMedia */
  72. AVS6EYES,
  73. /* total number of cards */
  74. NUM_CARDS
  75. };
  76. enum zoran_codec_mode {
  77. BUZ_MODE_IDLE, /* nothing going on */
  78. BUZ_MODE_MOTION_COMPRESS, /* grabbing frames */
  79. BUZ_MODE_MOTION_DECOMPRESS, /* playing frames */
  80. BUZ_MODE_STILL_COMPRESS, /* still frame conversion */
  81. BUZ_MODE_STILL_DECOMPRESS /* still frame conversion */
  82. };
  83. enum zoran_buffer_state {
  84. BUZ_STATE_USER, /* buffer is owned by application */
  85. BUZ_STATE_PEND, /* buffer is queued in pend[] ready to feed to I/O */
  86. BUZ_STATE_DMA, /* buffer is queued in dma[] for I/O */
  87. BUZ_STATE_DONE /* buffer is ready to return to application */
  88. };
  89. enum zoran_map_mode {
  90. ZORAN_MAP_MODE_RAW,
  91. ZORAN_MAP_MODE_JPG_REC,
  92. #define ZORAN_MAP_MODE_JPG ZORAN_MAP_MODE_JPG_REC
  93. ZORAN_MAP_MODE_JPG_PLAY,
  94. };
  95. enum gpio_type {
  96. ZR_GPIO_JPEG_SLEEP = 0,
  97. ZR_GPIO_JPEG_RESET,
  98. ZR_GPIO_JPEG_FRAME,
  99. ZR_GPIO_VID_DIR,
  100. ZR_GPIO_VID_EN,
  101. ZR_GPIO_VID_RESET,
  102. ZR_GPIO_CLK_SEL1,
  103. ZR_GPIO_CLK_SEL2,
  104. ZR_GPIO_MAX,
  105. };
  106. enum gpcs_type {
  107. GPCS_JPEG_RESET = 0,
  108. GPCS_JPEG_START,
  109. GPCS_MAX,
  110. };
  111. struct zoran_format {
  112. char *name;
  113. __u32 fourcc;
  114. int colorspace;
  115. int depth;
  116. __u32 flags;
  117. __u32 vfespfr;
  118. };
  119. /* flags */
  120. #define ZORAN_FORMAT_COMPRESSED 1<<0
  121. #define ZORAN_FORMAT_OVERLAY 1<<1
  122. #define ZORAN_FORMAT_CAPTURE 1<<2
  123. #define ZORAN_FORMAT_PLAYBACK 1<<3
  124. /* overlay-settings */
  125. struct zoran_overlay_settings {
  126. int is_set;
  127. int x, y, width, height; /* position */
  128. int clipcount; /* position and number of clips */
  129. const struct zoran_format *format; /* overlay format */
  130. };
  131. /* v4l-capture settings */
  132. struct zoran_v4l_settings {
  133. int width, height, bytesperline; /* capture size */
  134. const struct zoran_format *format; /* capture format */
  135. };
  136. /* jpg-capture/-playback settings */
  137. struct zoran_jpg_settings {
  138. int decimation; /* this bit is used to set everything to default */
  139. int HorDcm, VerDcm, TmpDcm; /* capture decimation settings (TmpDcm=1 means both fields) */
  140. int field_per_buff, odd_even; /* field-settings (odd_even=1 (+TmpDcm=1) means top-field-first) */
  141. int img_x, img_y, img_width, img_height; /* crop settings (subframe capture) */
  142. struct v4l2_jpegcompression jpg_comp; /* JPEG-specific capture settings */
  143. };
  144. struct zoran_fh;
  145. struct zoran_mapping {
  146. struct zoran_fh *fh;
  147. atomic_t count;
  148. };
  149. struct zoran_buffer {
  150. struct zoran_mapping *map;
  151. enum zoran_buffer_state state; /* state: unused/pending/dma/done */
  152. struct zoran_sync bs; /* DONE: info to return to application */
  153. union {
  154. struct {
  155. __le32 *frag_tab; /* addresses of frag table */
  156. u32 frag_tab_bus; /* same value cached to save time in ISR */
  157. } jpg;
  158. struct {
  159. char *fbuffer; /* virtual address of frame buffer */
  160. unsigned long fbuffer_phys;/* physical address of frame buffer */
  161. unsigned long fbuffer_bus;/* bus address of frame buffer */
  162. } v4l;
  163. };
  164. };
  165. enum zoran_lock_activity {
  166. ZORAN_FREE, /* free for use */
  167. ZORAN_ACTIVE, /* active but unlocked */
  168. ZORAN_LOCKED, /* locked */
  169. };
  170. /* buffer collections */
  171. struct zoran_buffer_col {
  172. enum zoran_lock_activity active; /* feature currently in use? */
  173. unsigned int num_buffers, buffer_size;
  174. struct zoran_buffer buffer[MAX_FRAME]; /* buffers */
  175. u8 allocated; /* Flag if buffers are allocated */
  176. u8 need_contiguous; /* Flag if contiguous buffers are needed */
  177. /* only applies to jpg buffers, raw buffers are always contiguous */
  178. };
  179. struct zoran;
  180. /* zoran_fh contains per-open() settings */
  181. struct zoran_fh {
  182. struct v4l2_fh fh;
  183. struct zoran *zr;
  184. enum zoran_map_mode map_mode; /* Flag which bufferset will map by next mmap() */
  185. struct zoran_overlay_settings overlay_settings;
  186. u32 *overlay_mask; /* overlay mask */
  187. enum zoran_lock_activity overlay_active;/* feature currently in use? */
  188. struct zoran_buffer_col buffers; /* buffers' info */
  189. struct zoran_v4l_settings v4l_settings; /* structure with a lot of things to play with */
  190. struct zoran_jpg_settings jpg_settings; /* structure with a lot of things to play with */
  191. };
  192. struct card_info {
  193. enum card_type type;
  194. char name[32];
  195. const char *i2c_decoder; /* i2c decoder device */
  196. const unsigned short *addrs_decoder;
  197. const char *i2c_encoder; /* i2c encoder device */
  198. const unsigned short *addrs_encoder;
  199. u16 video_vfe, video_codec; /* videocodec types */
  200. u16 audio_chip; /* audio type */
  201. int inputs; /* number of video inputs */
  202. struct input {
  203. int muxsel;
  204. char name[32];
  205. } input[BUZ_MAX_INPUT];
  206. v4l2_std_id norms;
  207. struct tvnorm *tvn[3]; /* supported TV norms */
  208. u32 jpeg_int; /* JPEG interrupt */
  209. u32 vsync_int; /* VSYNC interrupt */
  210. s8 gpio[ZR_GPIO_MAX];
  211. u8 gpcs[GPCS_MAX];
  212. struct vfe_polarity vfe_pol;
  213. u8 gpio_pol[ZR_GPIO_MAX];
  214. /* is the /GWS line connected? */
  215. u8 gws_not_connected;
  216. /* avs6eyes mux setting */
  217. u8 input_mux;
  218. void (*init) (struct zoran * zr);
  219. };
  220. struct zoran {
  221. struct v4l2_device v4l2_dev;
  222. struct v4l2_ctrl_handler hdl;
  223. struct video_device *video_dev;
  224. struct i2c_adapter i2c_adapter; /* */
  225. struct i2c_algo_bit_data i2c_algo; /* */
  226. u32 i2cbr;
  227. struct v4l2_subdev *decoder; /* video decoder sub-device */
  228. struct v4l2_subdev *encoder; /* video encoder sub-device */
  229. struct videocodec *codec; /* video codec */
  230. struct videocodec *vfe; /* video front end */
  231. struct mutex lock; /* file ops serialize lock */
  232. u8 initialized; /* flag if zoran has been correctly initialized */
  233. int user; /* number of current users */
  234. struct card_info card;
  235. struct tvnorm *timing;
  236. unsigned short id; /* number of this device */
  237. char name[32]; /* name of this device */
  238. struct pci_dev *pci_dev; /* PCI device */
  239. unsigned char revision; /* revision of zr36057 */
  240. unsigned char __iomem *zr36057_mem;/* pointer to mapped IO memory */
  241. spinlock_t spinlock; /* Spinlock */
  242. /* Video for Linux parameters */
  243. int input; /* card's norm and input */
  244. v4l2_std_id norm;
  245. /* Current buffer params */
  246. void *vbuf_base;
  247. int vbuf_height, vbuf_width;
  248. int vbuf_depth;
  249. int vbuf_bytesperline;
  250. struct zoran_overlay_settings overlay_settings;
  251. u32 *overlay_mask; /* overlay mask */
  252. enum zoran_lock_activity overlay_active; /* feature currently in use? */
  253. wait_queue_head_t v4l_capq;
  254. int v4l_overlay_active; /* Overlay grab is activated */
  255. int v4l_memgrab_active; /* Memory grab is activated */
  256. int v4l_grab_frame; /* Frame number being currently grabbed */
  257. #define NO_GRAB_ACTIVE (-1)
  258. unsigned long v4l_grab_seq; /* Number of frames grabbed */
  259. struct zoran_v4l_settings v4l_settings; /* structure with a lot of things to play with */
  260. /* V4L grab queue of frames pending */
  261. unsigned long v4l_pend_head;
  262. unsigned long v4l_pend_tail;
  263. unsigned long v4l_sync_tail;
  264. int v4l_pend[V4L_MAX_FRAME];
  265. struct zoran_buffer_col v4l_buffers; /* V4L buffers' info */
  266. /* Buz MJPEG parameters */
  267. enum zoran_codec_mode codec_mode; /* status of codec */
  268. struct zoran_jpg_settings jpg_settings; /* structure with a lot of things to play with */
  269. wait_queue_head_t jpg_capq; /* wait here for grab to finish */
  270. /* grab queue counts/indices, mask with BUZ_MASK_STAT_COM before using as index */
  271. /* (dma_head - dma_tail) is number active in DMA, must be <= BUZ_NUM_STAT_COM */
  272. /* (value & BUZ_MASK_STAT_COM) corresponds to index in stat_com table */
  273. unsigned long jpg_que_head; /* Index where to put next buffer which is queued */
  274. unsigned long jpg_dma_head; /* Index of next buffer which goes into stat_com */
  275. unsigned long jpg_dma_tail; /* Index of last buffer in stat_com */
  276. unsigned long jpg_que_tail; /* Index of last buffer in queue */
  277. unsigned long jpg_seq_num; /* count of frames since grab/play started */
  278. unsigned long jpg_err_seq; /* last seq_num before error */
  279. unsigned long jpg_err_shift;
  280. unsigned long jpg_queued_num; /* count of frames queued since grab/play started */
  281. /* zr36057's code buffer table */
  282. __le32 *stat_com; /* stat_com[i] is indexed by dma_head/tail & BUZ_MASK_STAT_COM */
  283. /* (value & BUZ_MASK_FRAME) corresponds to index in pend[] queue */
  284. int jpg_pend[BUZ_MAX_FRAME];
  285. /* array indexed by frame number */
  286. struct zoran_buffer_col jpg_buffers; /* MJPEG buffers' info */
  287. /* Additional stuff for testing */
  288. #ifdef CONFIG_PROC_FS
  289. struct proc_dir_entry *zoran_proc;
  290. #else
  291. void *zoran_proc;
  292. #endif
  293. int testing;
  294. int jpeg_error;
  295. int intr_counter_GIRQ1;
  296. int intr_counter_GIRQ0;
  297. int intr_counter_CodRepIRQ;
  298. int intr_counter_JPEGRepIRQ;
  299. int field_counter;
  300. int IRQ1_in;
  301. int IRQ1_out;
  302. int JPEG_in;
  303. int JPEG_out;
  304. int JPEG_0;
  305. int JPEG_1;
  306. int END_event_missed;
  307. int JPEG_missed;
  308. int JPEG_error;
  309. int num_errors;
  310. int JPEG_max_missed;
  311. int JPEG_min_missed;
  312. u32 last_isr;
  313. unsigned long frame_num;
  314. wait_queue_head_t test_q;
  315. };
  316. static inline struct zoran *to_zoran(struct v4l2_device *v4l2_dev)
  317. {
  318. return container_of(v4l2_dev, struct zoran, v4l2_dev);
  319. }
  320. /* There was something called _ALPHA_BUZ that used the PCI address instead of
  321. * the kernel iomapped address for btread/btwrite. */
  322. #define btwrite(dat,adr) writel((dat), zr->zr36057_mem+(adr))
  323. #define btread(adr) readl(zr->zr36057_mem+(adr))
  324. #define btand(dat,adr) btwrite((dat) & btread(adr), adr)
  325. #define btor(dat,adr) btwrite((dat) | btread(adr), adr)
  326. #define btaor(dat,mask,adr) btwrite((dat) | ((mask) & btread(adr)), adr)
  327. #endif