zoran.h 12 KB

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