zoran.h 12 KB

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