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. * 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_sync {
  34. unsigned long frame; /* number of buffer that has been free'd */
  35. unsigned long length; /* number of code bytes in buffer (capture only) */
  36. unsigned long seq; /* frame sequence number */
  37. struct timeval timestamp; /* timestamp */
  38. };
  39. #define ZORAN_NAME "ZORAN" /* name of the device */
  40. #define ZR_DEVNAME(zr) ((zr)->name)
  41. #define BUZ_MAX_WIDTH (zr->timing->Wa)
  42. #define BUZ_MAX_HEIGHT (zr->timing->Ha)
  43. #define BUZ_MIN_WIDTH 32 /* never display less than 32 pixels */
  44. #define BUZ_MIN_HEIGHT 24 /* never display less than 24 rows */
  45. #define BUZ_NUM_STAT_COM 4
  46. #define BUZ_MASK_STAT_COM 3
  47. #define BUZ_MAX_FRAME 256 /* Must be a power of 2 */
  48. #define BUZ_MASK_FRAME 255 /* Must be BUZ_MAX_FRAME-1 */
  49. #define BUZ_MAX_INPUT 16
  50. #if VIDEO_MAX_FRAME <= 32
  51. # define V4L_MAX_FRAME 32
  52. #elif VIDEO_MAX_FRAME <= 64
  53. # define V4L_MAX_FRAME 64
  54. #else
  55. # error "Too many video frame buffers to handle"
  56. #endif
  57. #define V4L_MASK_FRAME (V4L_MAX_FRAME - 1)
  58. #define MAX_FRAME (BUZ_MAX_FRAME > VIDEO_MAX_FRAME ? BUZ_MAX_FRAME : VIDEO_MAX_FRAME)
  59. #include "zr36057.h"
  60. enum card_type {
  61. UNKNOWN = -1,
  62. /* Pinnacle/Miro */
  63. DC10_old, /* DC30 like */
  64. DC10_new, /* DC10plus like */
  65. DC10plus,
  66. DC30,
  67. DC30plus,
  68. /* Linux Media Labs */
  69. LML33,
  70. LML33R10,
  71. /* Iomega */
  72. BUZ,
  73. /* AverMedia */
  74. AVS6EYES,
  75. /* total number of cards */
  76. NUM_CARDS
  77. };
  78. enum zoran_codec_mode {
  79. BUZ_MODE_IDLE, /* nothing going on */
  80. BUZ_MODE_MOTION_COMPRESS, /* grabbing frames */
  81. BUZ_MODE_MOTION_DECOMPRESS, /* playing frames */
  82. BUZ_MODE_STILL_COMPRESS, /* still frame conversion */
  83. BUZ_MODE_STILL_DECOMPRESS /* still frame conversion */
  84. };
  85. enum zoran_buffer_state {
  86. BUZ_STATE_USER, /* buffer is owned by application */
  87. BUZ_STATE_PEND, /* buffer is queued in pend[] ready to feed to I/O */
  88. BUZ_STATE_DMA, /* buffer is queued in dma[] for I/O */
  89. BUZ_STATE_DONE /* buffer is ready to return to application */
  90. };
  91. enum zoran_map_mode {
  92. ZORAN_MAP_MODE_RAW,
  93. ZORAN_MAP_MODE_JPG_REC,
  94. #define ZORAN_MAP_MODE_JPG ZORAN_MAP_MODE_JPG_REC
  95. ZORAN_MAP_MODE_JPG_PLAY,
  96. };
  97. enum gpio_type {
  98. ZR_GPIO_JPEG_SLEEP = 0,
  99. ZR_GPIO_JPEG_RESET,
  100. ZR_GPIO_JPEG_FRAME,
  101. ZR_GPIO_VID_DIR,
  102. ZR_GPIO_VID_EN,
  103. ZR_GPIO_VID_RESET,
  104. ZR_GPIO_CLK_SEL1,
  105. ZR_GPIO_CLK_SEL2,
  106. ZR_GPIO_MAX,
  107. };
  108. enum gpcs_type {
  109. GPCS_JPEG_RESET = 0,
  110. GPCS_JPEG_START,
  111. GPCS_MAX,
  112. };
  113. struct zoran_format {
  114. char *name;
  115. __u32 fourcc;
  116. int colorspace;
  117. int depth;
  118. __u32 flags;
  119. __u32 vfespfr;
  120. };
  121. /* flags */
  122. #define ZORAN_FORMAT_COMPRESSED 1<<0
  123. #define ZORAN_FORMAT_OVERLAY 1<<1
  124. #define ZORAN_FORMAT_CAPTURE 1<<2
  125. #define ZORAN_FORMAT_PLAYBACK 1<<3
  126. /* overlay-settings */
  127. struct zoran_overlay_settings {
  128. int is_set;
  129. int x, y, width, height; /* position */
  130. int clipcount; /* position and number of clips */
  131. const struct zoran_format *format; /* overlay format */
  132. };
  133. /* v4l-capture settings */
  134. struct zoran_v4l_settings {
  135. int width, height, bytesperline; /* capture size */
  136. const struct zoran_format *format; /* capture format */
  137. };
  138. /* jpg-capture/-playback settings */
  139. struct zoran_jpg_settings {
  140. int decimation; /* this bit is used to set everything to default */
  141. int HorDcm, VerDcm, TmpDcm; /* capture decimation settings (TmpDcm=1 means both fields) */
  142. int field_per_buff, odd_even; /* field-settings (odd_even=1 (+TmpDcm=1) means top-field-first) */
  143. int img_x, img_y, img_width, img_height; /* crop settings (subframe capture) */
  144. struct v4l2_jpegcompression jpg_comp; /* JPEG-specific capture settings */
  145. };
  146. struct zoran_mapping {
  147. struct file *file;
  148. int count;
  149. };
  150. struct zoran_buffer {
  151. struct zoran_mapping *map;
  152. enum zoran_buffer_state state; /* state: unused/pending/dma/done */
  153. struct zoran_sync bs; /* DONE: info to return to application */
  154. union {
  155. struct {
  156. __le32 *frag_tab; /* addresses of frag table */
  157. u32 frag_tab_bus; /* same value cached to save time in ISR */
  158. } jpg;
  159. struct {
  160. char *fbuffer; /* virtual address of frame buffer */
  161. unsigned long fbuffer_phys;/* physical address of frame buffer */
  162. unsigned long fbuffer_bus;/* bus address of frame buffer */
  163. } v4l;
  164. };
  165. };
  166. enum zoran_lock_activity {
  167. ZORAN_FREE, /* free for use */
  168. ZORAN_ACTIVE, /* active but unlocked */
  169. ZORAN_LOCKED, /* locked */
  170. };
  171. /* buffer collections */
  172. struct zoran_buffer_col {
  173. enum zoran_lock_activity active; /* feature currently in use? */
  174. unsigned int num_buffers, buffer_size;
  175. struct zoran_buffer buffer[MAX_FRAME]; /* buffers */
  176. u8 allocated; /* Flag if buffers are allocated */
  177. u8 need_contiguous; /* Flag if contiguous buffers are needed */
  178. /* only applies to jpg buffers, raw buffers are always contiguous */
  179. };
  180. struct zoran;
  181. /* zoran_fh contains per-open() settings */
  182. struct zoran_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 video_device *video_dev;
  223. struct i2c_adapter i2c_adapter; /* */
  224. struct i2c_algo_bit_data i2c_algo; /* */
  225. u32 i2cbr;
  226. struct v4l2_subdev *decoder; /* video decoder sub-device */
  227. struct v4l2_subdev *encoder; /* video encoder sub-device */
  228. struct videocodec *codec; /* video codec */
  229. struct videocodec *vfe; /* video front end */
  230. struct mutex resource_lock; /* prevent evil stuff */
  231. struct mutex other_lock; /* please merge with above */
  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