planb.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /*
  2. planb - PlanB frame grabber driver
  3. PlanB is used in the 7x00/8x00 series of PowerMacintosh
  4. Computers as video input DMA controller.
  5. Copyright (C) 1998 Michel Lanners (mlan@cpu.lu)
  6. Based largely on the bttv driver by Ralph Metzler (rjkm@thp.uni-koeln.de)
  7. Additional debugging and coding by Takashi Oe (toe@unlserve.unl.edu)
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20. /* $Id: planb.h,v 1.13 1999/05/03 19:28:56 mlan Exp $ */
  21. #ifndef _PLANB_H_
  22. #define _PLANB_H_
  23. #ifdef __KERNEL__
  24. #include <asm/dbdma.h>
  25. #include "saa7196.h"
  26. #endif /* __KERNEL__ */
  27. #define PLANB_DEVICE_NAME "Apple PlanB Video-In"
  28. #define PLANB_REV "1.0"
  29. #ifdef __KERNEL__
  30. //#define PLANB_GSCANLINE /* use this if apps have the notion of */
  31. /* grab buffer scanline */
  32. /* This should be safe for both PAL and NTSC */
  33. #define PLANB_MAXPIXELS 768
  34. #define PLANB_MAXLINES 576
  35. #define PLANB_NTSC_MAXLINES 480
  36. /* Uncomment your preferred norm ;-) */
  37. #define PLANB_DEF_NORM VIDEO_MODE_PAL
  38. //#define PLANB_DEF_NORM VIDEO_MODE_NTSC
  39. //#define PLANB_DEF_NORM VIDEO_MODE_SECAM
  40. /* fields settings */
  41. #define PLANB_GRAY 0x1 /* 8-bit mono? */
  42. #define PLANB_COLOUR15 0x2 /* 16-bit mode */
  43. #define PLANB_COLOUR32 0x4 /* 32-bit mode */
  44. #define PLANB_CLIPMASK 0x8 /* hardware clipmasking */
  45. /* misc. flags for PlanB DMA operation */
  46. #define CH_SYNC 0x1 /* synchronize channels (set by ch1;
  47. cleared by ch2) */
  48. #define FIELD_SYNC 0x2 /* used for the start of each field
  49. (0 -> 1 -> 0 for ch1; 0 -> 1 for ch2) */
  50. #define EVEN_FIELD 0x0 /* even field is detected if unset */
  51. #define DMA_ABORT 0x2 /* error or just out of sync if set */
  52. #define ODD_FIELD 0x4 /* odd field is detected if set */
  53. /* for capture operations */
  54. #define MAX_GBUFFERS 2
  55. /* note PLANB_MAX_FBUF must be divisible by PAGE_SIZE */
  56. #ifdef PLANB_GSCANLINE
  57. #define PLANB_MAX_FBUF 0x240000 /* 576 * 1024 * 4 */
  58. #define TAB_FACTOR (1)
  59. #else
  60. #define PLANB_MAX_FBUF 0x1b0000 /* 576 * 768 * 4 */
  61. #define TAB_FACTOR (2)
  62. #endif
  63. #endif /* __KERNEL__ */
  64. struct planb_saa_regs {
  65. unsigned char addr;
  66. unsigned char val;
  67. };
  68. struct planb_stat_regs {
  69. unsigned int ch1_stat;
  70. unsigned int ch2_stat;
  71. unsigned char saa_stat0;
  72. unsigned char saa_stat1;
  73. };
  74. struct planb_any_regs {
  75. unsigned int offset;
  76. unsigned int bytes;
  77. unsigned char data[128];
  78. };
  79. /* planb private ioctls */
  80. #define PLANBIOCGSAAREGS _IOWR('v', BASE_VIDIOCPRIVATE, struct planb_saa_regs) /* Read a saa7196 reg value */
  81. #define PLANBIOCSSAAREGS _IOW('v', BASE_VIDIOCPRIVATE + 1, struct planb_saa_regs) /* Set a saa7196 reg value */
  82. #define PLANBIOCGSTAT _IOR('v', BASE_VIDIOCPRIVATE + 2, struct planb_stat_regs) /* Read planb status */
  83. #define PLANB_TV_MODE 1
  84. #define PLANB_VTR_MODE 2
  85. #define PLANBIOCGMODE _IOR('v', BASE_VIDIOCPRIVATE + 3, int) /* Get TV/VTR mode */
  86. #define PLANBIOCSMODE _IOW('v', BASE_VIDIOCPRIVATE + 4, int) /* Set TV/VTR mode */
  87. #ifdef PLANB_GSCANLINE
  88. #define PLANBG_GRAB_BPL _IOR('v', BASE_VIDIOCPRIVATE + 5, int) /* # of bytes per scanline in grab buffer */
  89. #endif
  90. /* call wake_up_interruptible() with appropriate actions */
  91. #define PLANB_INTR_DEBUG _IOW('v', BASE_VIDIOCPRIVATE + 20, int)
  92. /* investigate which reg does what */
  93. #define PLANB_INV_REGS _IOWR('v', BASE_VIDIOCPRIVATE + 21, struct planb_any_regs)
  94. #ifdef __KERNEL__
  95. /* Potentially useful macros */
  96. #define PLANB_SET(x) ((x) << 16 | (x))
  97. #define PLANB_CLR(x) ((x) << 16)
  98. /* This represents the physical register layout */
  99. struct planb_registers {
  100. volatile struct dbdma_regs ch1; /* 0x00: video in */
  101. volatile unsigned int even; /* 0x40: even field setting */
  102. volatile unsigned int odd; /* 0x44; odd field setting */
  103. unsigned int pad1[14]; /* empty? */
  104. volatile struct dbdma_regs ch2; /* 0x80: clipmask out */
  105. unsigned int pad2[16]; /* 0xc0: empty? */
  106. volatile unsigned int reg3; /* 0x100: ???? */
  107. volatile unsigned int intr_stat; /* 0x104: irq status */
  108. #define PLANB_CLR_IRQ 0x00 /* clear Plan B interrupt */
  109. #define PLANB_GEN_IRQ 0x01 /* assert Plan B interrupt */
  110. #define PLANB_FRM_IRQ 0x0100 /* end of frame */
  111. unsigned int pad3[1]; /* empty? */
  112. volatile unsigned int reg5; /* 0x10c: ??? */
  113. unsigned int pad4[60]; /* empty? */
  114. volatile unsigned char saa_addr; /* 0x200: SAA subadr */
  115. char pad5[3];
  116. volatile unsigned char saa_regval; /* SAA7196 write reg. val */
  117. char pad6[3];
  118. volatile unsigned char saa_status; /* SAA7196 status byte */
  119. /* There is more unused stuff here */
  120. };
  121. struct planb_window {
  122. int x, y;
  123. ushort width, height;
  124. ushort bpp, bpl, depth, pad;
  125. ushort swidth, sheight;
  126. int norm;
  127. int interlace;
  128. u32 color_fmt;
  129. int chromakey;
  130. int mode; /* used to switch between TV/VTR modes */
  131. };
  132. struct planb_suspend {
  133. int overlay;
  134. int frame;
  135. struct dbdma_cmd cmd;
  136. };
  137. struct planb {
  138. struct video_device video_dev;
  139. struct video_picture picture; /* Current picture params */
  140. struct video_audio audio_dev; /* Current audio params */
  141. volatile struct planb_registers *planb_base; /* virt base of planb */
  142. struct planb_registers *planb_base_phys; /* phys base of planb */
  143. void *priv_space; /* Org. alloc. mem for kfree */
  144. int user;
  145. unsigned int tab_size;
  146. int maxlines;
  147. struct semaphore lock;
  148. unsigned int irq; /* interrupt number */
  149. volatile unsigned int intr_mask;
  150. int overlay; /* overlay running? */
  151. struct planb_window win;
  152. unsigned long frame_buffer_phys; /* We need phys for DMA */
  153. int offset; /* offset of pixel 1 */
  154. volatile struct dbdma_cmd *ch1_cmd; /* Video In DMA cmd buffer */
  155. volatile struct dbdma_cmd *ch2_cmd; /* Clip Out DMA cmd buffer */
  156. volatile struct dbdma_cmd *overlay_last1;
  157. volatile struct dbdma_cmd *overlay_last2;
  158. unsigned long ch1_cmd_phys;
  159. volatile unsigned char *mask; /* Clipmask buffer */
  160. int suspend;
  161. wait_queue_head_t suspendq;
  162. struct planb_suspend suspended;
  163. int cmd_buff_inited; /* cmd buffer inited? */
  164. int grabbing;
  165. unsigned int gcount;
  166. wait_queue_head_t capq;
  167. int last_fr;
  168. int prev_last_fr;
  169. unsigned char **rawbuf;
  170. int rawbuf_size;
  171. int gbuf_idx[MAX_GBUFFERS];
  172. volatile struct dbdma_cmd *cap_cmd[MAX_GBUFFERS];
  173. volatile struct dbdma_cmd *last_cmd[MAX_GBUFFERS];
  174. volatile struct dbdma_cmd *pre_cmd[MAX_GBUFFERS];
  175. int need_pre_capture[MAX_GBUFFERS];
  176. #define PLANB_DUMMY 40 /* # of command buf's allocated for pre-capture seq. */
  177. int gwidth[MAX_GBUFFERS], gheight[MAX_GBUFFERS];
  178. unsigned int gfmt[MAX_GBUFFERS];
  179. int gnorm_switch[MAX_GBUFFERS];
  180. volatile unsigned int *frame_stat;
  181. #define GBUFFER_UNUSED 0x00U
  182. #define GBUFFER_GRABBING 0x01U
  183. #define GBUFFER_DONE 0x02U
  184. #ifdef PLANB_GSCANLINE
  185. int gbytes_per_line;
  186. #else
  187. #define MAX_LNUM 431 /* change this if PLANB_MAXLINES or */
  188. /* PLANB_MAXPIXELS changes */
  189. int l_fr_addr_idx[MAX_GBUFFERS];
  190. unsigned char *l_to_addr[MAX_GBUFFERS][MAX_LNUM];
  191. int l_to_next_idx[MAX_GBUFFERS][MAX_LNUM];
  192. int l_to_next_size[MAX_GBUFFERS][MAX_LNUM];
  193. int lsize[MAX_GBUFFERS], lnum[MAX_GBUFFERS];
  194. #endif
  195. };
  196. #endif /* __KERNEL__ */
  197. #endif /* _PLANB_H_ */