1 |
1275 |
phoenix |
/*
|
2 |
|
|
planb - v4l-compatible frame grabber driver for the PlanB hardware
|
3 |
|
|
|
4 |
|
|
PlanB is used in the 7x00/8x00 series of PowerMacintosh
|
5 |
|
|
Computers as video input DMA controller.
|
6 |
|
|
|
7 |
|
|
Copyright (C) 1998 - 2002 Michel Lanners <mailto:mlan@cpu.lu>
|
8 |
|
|
|
9 |
|
|
Based largely on the old bttv driver by Ralph Metzler
|
10 |
|
|
|
11 |
|
|
Additional debugging and coding by Takashi Oe <mailto:toe@unlserve.unl.edu>
|
12 |
|
|
|
13 |
|
|
For more information, see <http://www.cpu.lu/~mlan/planb.html>
|
14 |
|
|
|
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 |
|
|
|
31 |
|
|
/* $Id: planb.h,v 1.1.1.1 2004-04-15 02:19:42 phoenix Exp $ */
|
32 |
|
|
|
33 |
|
|
#ifndef _PLANB_H_
|
34 |
|
|
#define _PLANB_H_
|
35 |
|
|
|
36 |
|
|
#define PLANB_DEVICE_NAME "Apple PlanB Video-In"
|
37 |
|
|
#define PLANB_VBI_NAME "Apple PlanB VBI"
|
38 |
|
|
#define PLANB_REV "2.11"
|
39 |
|
|
|
40 |
|
|
#define APPLE_VENDOR_ID 0x106b
|
41 |
|
|
#define PLANB_DEV_ID 0x0004
|
42 |
|
|
|
43 |
|
|
#ifdef __KERNEL__
|
44 |
|
|
//#define PLANB_GSCANLINE /* use this if apps have the notion of */
|
45 |
|
|
/* grab buffer scanline */
|
46 |
|
|
/* This should be safe for both PAL and NTSC */
|
47 |
|
|
#define PLANB_MAXPIXELS 768
|
48 |
|
|
#define PLANB_MAXLINES 576
|
49 |
|
|
#define PLANB_NTSC_MAXLINES 480
|
50 |
|
|
|
51 |
|
|
/* Max VBI data buffer size */
|
52 |
|
|
#define VBI_LINESIZE 1024 /* on SAA7196, a line can be max. 1024 pixels */
|
53 |
|
|
#define VBI_START 7 /* VBI starts at line 7 */
|
54 |
|
|
#define VBI_MAXLINES 16 /* 16 lines per field */
|
55 |
|
|
/* We have 2 of these, but return them one at a time */
|
56 |
|
|
#define VBIBUF_SIZE (VBI_LINESIZE * VBI_MAXLINES)
|
57 |
|
|
|
58 |
|
|
#define LINE_OFFSET 1 /* between line 1 and SAA's first valid line */
|
59 |
|
|
|
60 |
|
|
/* Uncomment your preferred norm ;-) */
|
61 |
|
|
#define PLANB_DEF_NORM VIDEO_MODE_PAL
|
62 |
|
|
//#define PLANB_DEF_NORM VIDEO_MODE_NTSC
|
63 |
|
|
//#define PLANB_DEF_NORM VIDEO_MODE_SECAM
|
64 |
|
|
|
65 |
|
|
/* fields settings */
|
66 |
|
|
#define PLANB_SIZE8 0x1 /* 8-bit mono? */
|
67 |
|
|
#define PLANB_SIZE16 0x2 /* 16-bit mode */
|
68 |
|
|
#define PLANB_SIZE32 0x4 /* 32-bit mode */
|
69 |
|
|
#define PLANB_CLIPMASK 0x8 /* hardware clipmasking */
|
70 |
|
|
|
71 |
|
|
/* misc. flags for PlanB DMA operation */
|
72 |
|
|
#define CH_SYNC 0x1 /* synchronize channels (set by ch1;
|
73 |
|
|
cleared by ch2) */
|
74 |
|
|
#define FIELD_SYNC 0x2 /* used for the start of each field
|
75 |
|
|
(0 -> 1 -> 0 for ch1; 0 -> 1 for ch2) */
|
76 |
|
|
#define EVEN_FIELD 0x0 /* even field is detected if unset */
|
77 |
|
|
#define DMA_ABORT 0x2 /* error or just out of sync if set */
|
78 |
|
|
#define ODD_FIELD 0x4 /* odd field is detected if set */
|
79 |
|
|
|
80 |
|
|
/* format info and correspondance */
|
81 |
|
|
struct fmts {
|
82 |
|
|
int bpp; /* bytes per pixel */
|
83 |
|
|
int pb_fmt; /* planb format (DMA engine sub 0x40/0x44 ) */
|
84 |
|
|
int saa_fmt; /* saa format: bit
|
85 |
|
|
SAA7196 sub 0x20: bits FS0 0
|
86 |
|
|
FS1 1
|
87 |
|
|
sub 0x30: bit MCT 4
|
88 |
|
|
LLV 5 */
|
89 |
|
|
};
|
90 |
|
|
|
91 |
|
|
/* This is supposed to match the VIDEO_PALETTE_* defines in
|
92 |
|
|
* struct video_picture in videodev.h */
|
93 |
|
|
static struct fmts palette2fmt[] = {
|
94 |
|
|
{ 0, 0, 0 },
|
95 |
|
|
{ 1, PLANB_SIZE8, 0x33 }, /* VIDEO_PALETTE_GREY */
|
96 |
|
|
{ 0, 0, 0 },
|
97 |
|
|
{ 0, 0, 0 },
|
98 |
|
|
{ 0, 0, 0 },
|
99 |
|
|
{ 4, PLANB_SIZE32, 2 }, /* VIDEO_PALETTE_RGB32 */
|
100 |
|
|
{ 2, PLANB_SIZE16, 0 }, /* VIDEO_PALETTE_RGB555 */
|
101 |
|
|
{ 2, PLANB_SIZE16, 0x21 }, /* VIDEO_PALETTE_YUV422 */
|
102 |
|
|
{ 0, 0, 0 },
|
103 |
|
|
{ 0, 0, 0 },
|
104 |
|
|
{ 0, 0, 0 },
|
105 |
|
|
{ 0, 0, 0 },
|
106 |
|
|
{ 0, 0, 0 },
|
107 |
|
|
{ 0, 0, 0 },
|
108 |
|
|
{ 0, 0, 0 },
|
109 |
|
|
{ 0, 0, 0 },
|
110 |
|
|
{ 0, 0, 0 },
|
111 |
|
|
};
|
112 |
|
|
|
113 |
|
|
#define PLANB_PALETTE_MAX (sizeof palette2fmt / sizeof (struct fmts))
|
114 |
|
|
|
115 |
|
|
/* for capture operations */
|
116 |
|
|
#define MAX_GBUFFERS 2
|
117 |
|
|
/* note PLANB_MAX_FBUF must be divisible by PAGE_SIZE */
|
118 |
|
|
#ifdef PLANB_GSCANLINE
|
119 |
|
|
#define PLANB_MAX_FBUF 0x240000 /* 576 * 1024 * 4 */
|
120 |
|
|
#define TAB_FACTOR (1)
|
121 |
|
|
#else
|
122 |
|
|
#define PLANB_MAX_FBUF 0x1b0000 /* 576 * 768 * 4 */
|
123 |
|
|
#define TAB_FACTOR (2)
|
124 |
|
|
#endif
|
125 |
|
|
#endif /* __KERNEL__ */
|
126 |
|
|
|
127 |
|
|
struct planb_saa_regs {
|
128 |
|
|
unsigned char addr;
|
129 |
|
|
unsigned char val;
|
130 |
|
|
};
|
131 |
|
|
|
132 |
|
|
struct planb_stat_regs {
|
133 |
|
|
unsigned int ch1_stat;
|
134 |
|
|
unsigned int ch2_stat;
|
135 |
|
|
unsigned long ch1_cmdbase;
|
136 |
|
|
unsigned long ch2_cmdbase;
|
137 |
|
|
unsigned int ch1_cmdptr;
|
138 |
|
|
unsigned int ch2_cmdptr;
|
139 |
|
|
unsigned char saa_stat0;
|
140 |
|
|
unsigned char saa_stat1;
|
141 |
|
|
};
|
142 |
|
|
|
143 |
|
|
struct planb_any_regs {
|
144 |
|
|
unsigned int offset;
|
145 |
|
|
unsigned int bytes;
|
146 |
|
|
unsigned char data[128];
|
147 |
|
|
};
|
148 |
|
|
|
149 |
|
|
struct planb_buf_regs {
|
150 |
|
|
unsigned int start;
|
151 |
|
|
unsigned int end;
|
152 |
|
|
};
|
153 |
|
|
|
154 |
|
|
/* planb private ioctls */
|
155 |
|
|
/* Read a saa7196 reg value */
|
156 |
|
|
#define PLANBIOCGSAAREGS _IOWR('v', BASE_VIDIOCPRIVATE, struct planb_saa_regs)
|
157 |
|
|
/* Set a saa7196 reg value */
|
158 |
|
|
#define PLANBIOCSSAAREGS _IOW('v', BASE_VIDIOCPRIVATE + 1, struct planb_saa_regs)
|
159 |
|
|
/* Read planb status */
|
160 |
|
|
#define PLANBIOCGSTAT _IOR('v', BASE_VIDIOCPRIVATE + 2, struct planb_stat_regs)
|
161 |
|
|
/* Get TV/VTR mode */
|
162 |
|
|
#define PLANB_TV_MODE 1
|
163 |
|
|
#define PLANB_VTR_MODE 2
|
164 |
|
|
#define PLANBIOCGMODE _IOR('v', BASE_VIDIOCPRIVATE + 3, int)
|
165 |
|
|
/* Set TV/VTR mode */
|
166 |
|
|
#define PLANBIOCSMODE _IOW('v', BASE_VIDIOCPRIVATE + 4, int)
|
167 |
|
|
|
168 |
|
|
#ifdef PLANB_GSCANLINE
|
169 |
|
|
/* # of bytes per scanline in grab buffer */
|
170 |
|
|
#define PLANBG_GRAB_BPL _IOR('v', BASE_VIDIOCPRIVATE + 5, int)
|
171 |
|
|
#endif
|
172 |
|
|
|
173 |
|
|
/* This doesn't really belong here, but until someone cleans up (or defines
|
174 |
|
|
in the first place ;-) the VBI API, it helps alevt... */
|
175 |
|
|
#define BTTV_VBISIZE _IOR('v', BASE_VIDIOCPRIVATE + 8, int)
|
176 |
|
|
|
177 |
|
|
/* Various debugging IOCTLs */
|
178 |
|
|
#ifdef DEBUG
|
179 |
|
|
/* call wake_up_interruptible() with appropriate actions */
|
180 |
|
|
#define PLANB_INTR_DEBUG _IOW('v', BASE_VIDIOCPRIVATE + 20, int)
|
181 |
|
|
/* investigate which reg does what */
|
182 |
|
|
#define PLANB_INV_REGS _IOWR('v', BASE_VIDIOCPRIVATE + 21, struct planb_any_regs)
|
183 |
|
|
/* Dump DBDMA command buffer from (int) to (int) */
|
184 |
|
|
#define PLANBIOCGDBDMABUF _IOW('v', BASE_VIDIOCPRIVATE + 22, struct planb_buf_regs)
|
185 |
|
|
#endif /* DEBUG */
|
186 |
|
|
|
187 |
|
|
#ifdef __KERNEL__
|
188 |
|
|
|
189 |
|
|
/* Potentially useful macros */
|
190 |
|
|
#define PLANB_SET(x) ((x) << 16 | (x))
|
191 |
|
|
#define PLANB_CLR(x) ((x) << 16)
|
192 |
|
|
|
193 |
|
|
typedef volatile struct dbdma_cmd dbdma_cmd_t;
|
194 |
|
|
typedef volatile struct dbdma_cmd *dbdma_cmd_ptr;
|
195 |
|
|
typedef volatile struct dbdma_regs dbdma_regs_t;
|
196 |
|
|
typedef volatile struct dbdma_regs *dbdma_regs_ptr;
|
197 |
|
|
|
198 |
|
|
typedef struct gbuffer gbuf_t;
|
199 |
|
|
typedef struct gbuffer *gbuf_ptr;
|
200 |
|
|
|
201 |
|
|
/* grab buffer status */
|
202 |
|
|
#define GBUFFER_UNUSED 0x00U
|
203 |
|
|
#define GBUFFER_GRABBING 0x01U
|
204 |
|
|
#define GBUFFER_DONE 0x02U
|
205 |
|
|
|
206 |
|
|
/* planb interrupt status values (0x104: irq status) */
|
207 |
|
|
#define PLANB_CLR_IRQ 0x00 /* clear Plan B interrupt */
|
208 |
|
|
#define PLANB_GEN_IRQ 0x01 /* assert Plan B interrupt */
|
209 |
|
|
#define PLANB_FRM_IRQ 0x0100 /* end of frame */
|
210 |
|
|
|
211 |
|
|
#define PLANB_DUMMY 40 /* # of command buf's allocated for pre-capture seq. */
|
212 |
|
|
|
213 |
|
|
/* This represents the physical register layout */
|
214 |
|
|
struct planb_registers {
|
215 |
|
|
dbdma_regs_t ch1; /* 0x00: video in */
|
216 |
|
|
volatile u32 even; /* 0x40: even field setting */
|
217 |
|
|
volatile u32 odd; /* 0x44; odd field setting */
|
218 |
|
|
u32 pad1[14]; /* empty? */
|
219 |
|
|
dbdma_regs_t ch2; /* 0x80: clipmask out */
|
220 |
|
|
u32 pad2[16]; /* 0xc0: empty? */
|
221 |
|
|
volatile u32 reg3; /* 0x100: ???? */
|
222 |
|
|
volatile u32 intr_stat; /* 0x104: irq status */
|
223 |
|
|
u32 pad3[1]; /* empty? */
|
224 |
|
|
volatile u32 reg5; /* 0x10c: ??? */
|
225 |
|
|
u32 pad4[60]; /* empty? */
|
226 |
|
|
volatile u8 saa_addr; /* 0x200: SAA subadr */
|
227 |
|
|
u8 pad5[3];
|
228 |
|
|
volatile u8 saa_regval; /* SAA7196 write reg. val */
|
229 |
|
|
u8 pad6[3];
|
230 |
|
|
volatile u8 saa_status; /* SAA7196 status byte */
|
231 |
|
|
/* There is more unused stuff here */
|
232 |
|
|
};
|
233 |
|
|
|
234 |
|
|
struct planb_window {
|
235 |
|
|
int x, y;
|
236 |
|
|
ushort width, height;
|
237 |
|
|
ushort bpp, bpl, depth, pad;
|
238 |
|
|
ushort swidth, sheight;
|
239 |
|
|
int norm;
|
240 |
|
|
int interlace;
|
241 |
|
|
u32 color_fmt;
|
242 |
|
|
int chromakey;
|
243 |
|
|
int mode; /* used to switch between TV/VTR modes */
|
244 |
|
|
};
|
245 |
|
|
|
246 |
|
|
struct planb_suspend {
|
247 |
|
|
int overlay;
|
248 |
|
|
int frame;
|
249 |
|
|
struct dbdma_cmd cmd;
|
250 |
|
|
};
|
251 |
|
|
|
252 |
|
|
/* Framebuffer info */
|
253 |
|
|
struct planb_fb {
|
254 |
|
|
unsigned long phys; /* Framebuffer phys. base address */
|
255 |
|
|
int offset; /* offset of pixel 1 */
|
256 |
|
|
};
|
257 |
|
|
|
258 |
|
|
/* DBDMA command buffer descriptor */
|
259 |
|
|
struct dbdma_cmd_buf {
|
260 |
|
|
dbdma_cmd_ptr start;
|
261 |
|
|
dbdma_cmd_ptr jumpaddr; /* where are we called from? */
|
262 |
|
|
unsigned int size;
|
263 |
|
|
unsigned long bus; /* start address as seen from the bus */
|
264 |
|
|
};
|
265 |
|
|
|
266 |
|
|
/* grab buffer descriptor */
|
267 |
|
|
struct gbuffer {
|
268 |
|
|
dbdma_cmd_ptr cap_cmd;
|
269 |
|
|
dbdma_cmd_ptr last_cmd;
|
270 |
|
|
dbdma_cmd_ptr pre_cmd;
|
271 |
|
|
int idx;
|
272 |
|
|
int need_pre_capture;
|
273 |
|
|
int width;
|
274 |
|
|
int height;
|
275 |
|
|
unsigned int fmt;
|
276 |
|
|
int norm_switch;
|
277 |
|
|
#ifndef PLANB_GSCANLINE
|
278 |
|
|
int l_fr_addr_idx;
|
279 |
|
|
int lsize;
|
280 |
|
|
int lnum;
|
281 |
|
|
#endif
|
282 |
|
|
volatile unsigned int *status; /* ptr to status value */
|
283 |
|
|
};
|
284 |
|
|
|
285 |
|
|
struct planb {
|
286 |
|
|
/* the video device: */
|
287 |
|
|
struct video_device video_dev;
|
288 |
|
|
struct video_picture picture; /* Current picture params */
|
289 |
|
|
int vid_user; /* Users on video device */
|
290 |
|
|
void *vid_raw; /* Org. alloc. mem for kfree */
|
291 |
|
|
struct dbdma_cmd_buf vid_cbo; /* odd video dbdma cmd buf */
|
292 |
|
|
struct dbdma_cmd_buf vid_cbe; /* even */
|
293 |
|
|
void *clip_raw;
|
294 |
|
|
struct dbdma_cmd_buf clip_cbo; /* odd clip dbdma cmd buf */
|
295 |
|
|
struct dbdma_cmd_buf clip_cbe; /* even */
|
296 |
|
|
dbdma_cmd_ptr overlay_last1;
|
297 |
|
|
dbdma_cmd_ptr overlay_last2;
|
298 |
|
|
|
299 |
|
|
/* the hardware: */
|
300 |
|
|
volatile struct planb_registers
|
301 |
|
|
*planb_base; /* virt base of planb */
|
302 |
|
|
struct planb_registers *planb_base_bus; /* phys base of planb */
|
303 |
|
|
unsigned int tab_size;
|
304 |
|
|
int maxlines;
|
305 |
|
|
unsigned int irq; /* interrupt number */
|
306 |
|
|
volatile unsigned int intr_mask;
|
307 |
|
|
struct planb_fb fb; /* Framebuffer info */
|
308 |
|
|
|
309 |
|
|
/* generic stuff: */
|
310 |
|
|
void *jump_raw; /* jump buffer raw space */
|
311 |
|
|
dbdma_cmd_ptr jumpbuf; /* same, DBDMA_ALIGN'ed */
|
312 |
|
|
struct semaphore lock;
|
313 |
|
|
int overlay; /* overlay running? */
|
314 |
|
|
struct planb_window win;
|
315 |
|
|
volatile unsigned char *mask; /* Clipmask buffer */
|
316 |
|
|
int suspend;
|
317 |
|
|
wait_queue_head_t suspendq;
|
318 |
|
|
struct planb_suspend suspended;
|
319 |
|
|
int cmd_buff_inited; /* cmd buffer inited? */
|
320 |
|
|
|
321 |
|
|
/* grabbing stuff: */
|
322 |
|
|
int grabbing;
|
323 |
|
|
unsigned int gcount;
|
324 |
|
|
wait_queue_head_t capq;
|
325 |
|
|
int last_fr;
|
326 |
|
|
int prev_last_fr;
|
327 |
|
|
unsigned char **rawbuf;
|
328 |
|
|
int rawbuf_nchunks;
|
329 |
|
|
struct gbuffer gbuf[MAX_GBUFFERS];
|
330 |
|
|
|
331 |
|
|
#ifdef PLANB_GSCANLINE
|
332 |
|
|
int gbytes_per_line;
|
333 |
|
|
#else
|
334 |
|
|
#define MAX_LNUM 576 /* change this if PLANB_MAXLINES or */
|
335 |
|
|
/* PLANB_MAXPIXELS changes */
|
336 |
|
|
unsigned char *l_to_addr[MAX_GBUFFERS][MAX_LNUM];
|
337 |
|
|
int l_to_next_idx[MAX_GBUFFERS][MAX_LNUM];
|
338 |
|
|
int l_to_next_size[MAX_GBUFFERS][MAX_LNUM];
|
339 |
|
|
#endif /* PLANB_GSCANLINE */
|
340 |
|
|
|
341 |
|
|
/* VBI stuff: */
|
342 |
|
|
struct video_device vbi_dev; /* VBI data device */
|
343 |
|
|
int vbi_user; /* Users on vbi device */
|
344 |
|
|
void *vbi_raw;
|
345 |
|
|
struct dbdma_cmd_buf vbi_cbo; /* odd VBI dbdma cmd buf */
|
346 |
|
|
struct dbdma_cmd_buf vbi_cbe; /* even */
|
347 |
|
|
int vbirunning;
|
348 |
|
|
int vbip; /* pointer into VBI buffer */
|
349 |
|
|
unsigned char *vbibuf; /* buffer for VBI data */
|
350 |
|
|
wait_queue_head_t vbiq;
|
351 |
|
|
};
|
352 |
|
|
|
353 |
|
|
#endif /* __KERNEL__ */
|
354 |
|
|
|
355 |
|
|
#endif /* _PLANB_H_ */
|