1 /*
2 * $Id: cx88.h,v 1.40 2004/11/03 09:04:51 kraxel Exp $
3 *
4 * v4l2 device driver for cx2388x based TV cards
5 *
6 * (c) 2003,04 Gerd Knorr <kraxel@bytesex.org> [SUSE Labs]
7 *
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 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include <linux/pci.h>
24 #include <linux/i2c.h>
25 #include <linux/i2c-algo-bit.h>
26 #include <linux/videodev.h>
27 #include <linux/kdev_t.h>
28
29 #include <media/tuner.h>
30 #include <media/audiochip.h>
31 #include <media/video-buf.h>
32 #include <media/video-buf-dvb.h>
33
34 #include "btcx-risc.h"
35 #include "cx88-reg.h"
36
37 #include <linux/version.h>
38 #define CX88_VERSION_CODE KERNEL_VERSION(0,0,4)
39
40 #ifndef TRUE
41 # define TRUE (1==1)
42 #endif
43 #ifndef FALSE
44 # define FALSE (1==0)
45 #endif
46 #define UNSET (-1U)
47
48 #define CX88_MAXBOARDS 8
49
50 /* ----------------------------------------------------------- */
51 /* defines and enums */
52
53 #define V4L2_I2C_CLIENTS 1
54
55 #define FORMAT_FLAGS_PACKED 0x01
56 #define FORMAT_FLAGS_PLANAR 0x02
57
58 #define VBI_LINE_COUNT 17
59 #define VBI_LINE_LENGTH 2048
60
61 /* need "shadow" registers for some write-only ones ... */
62 #define SHADOW_AUD_VOL_CTL 1
63 #define SHADOW_AUD_BAL_CTL 2
64 #define SHADOW_MAX 2
65
66 /* ----------------------------------------------------------- */
67 /* tv norms */
68
69 struct cx88_tvnorm {
70 char *name;
71 v4l2_std_id id;
72 u32 cxiformat;
73 u32 cxoformat;
74 };
75
76 static unsigned int inline norm_maxw(struct cx88_tvnorm *norm)
77 {
78 return (norm->id & V4L2_STD_625_50) ? 768 : 640;
79 // return (norm->id & V4L2_STD_625_50) ? 720 : 640;
80 }
81
82 static unsigned int inline norm_maxh(struct cx88_tvnorm *norm)
83 {
84 return (norm->id & V4L2_STD_625_50) ? 576 : 480;
85 }
86
87 /* ----------------------------------------------------------- */
88 /* static data */
89
90 struct cx8800_fmt {
91 char *name;
92 u32 fourcc; /* v4l2 format id */
93 int depth;
94 int flags;
95 u32 cxformat;
96 };
97
98 struct cx88_ctrl {
99 struct v4l2_queryctrl v;
100 u32 off;
101 u32 reg;
102 u32 sreg;
103 u32 mask;
104 u32 shift;
105 };
106
107 /* ----------------------------------------------------------- */
108 /* SRAM memory management data (see cx88-core.c) */
109
110 #define SRAM_CH21 0 /* video */
111 #define SRAM_CH22 1
112 #define SRAM_CH23 2
113 #define SRAM_CH24 3 /* vbi */
114 #define SRAM_CH25 4 /* audio */
115 #define SRAM_CH26 5
116 #define SRAM_CH28 6 /* mpeg */
117 /* more */
118
119 struct sram_channel {
120 char *name;
121 u32 cmds_start;
122 u32 ctrl_start;
123 u32 cdt;
124 u32 fifo_start;
125 u32 fifo_size;
126 u32 ptr1_reg;
127 u32 ptr2_reg;
128 u32 cnt1_reg;
129 u32 cnt2_reg;
130 };
131 extern struct sram_channel cx88_sram_channels[];
132
133 /* ----------------------------------------------------------- */
134 /* card configuration */
135
136 #define CX88_BOARD_NOAUTO UNSET
137 #define CX88_BOARD_UNKNOWN 0
138 #define CX88_BOARD_HAUPPAUGE 1
139 #define CX88_BOARD_GDI 2
140 #define CX88_BOARD_PIXELVIEW 3
141 #define CX88_BOARD_ATI_WONDER_PRO 4
142 #define CX88_BOARD_WINFAST2000XP 5
143 #define CX88_BOARD_AVERTV_303 6
144 #define CX88_BOARD_MSI_TVANYWHERE_MASTER 7
145 #define CX88_BOARD_WINFAST_DV2000 8
146 #define CX88_BOARD_LEADTEK_PVR2000 9
147 #define CX88_BOARD_IODATA_GVVCP3PCI 10
148 #define CX88_BOARD_PROLINK_PLAYTVPVR 11
149 #define CX88_BOARD_ASUS_PVR_416 12
150 #define CX88_BOARD_MSI_TVANYWHERE 13
151 #define CX88_BOARD_KWORLD_DVB_T 14
152 #define CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1 15
153 #define CX88_BOARD_KWORLD_LTV883 16
154 #define CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD 17
155 #define CX88_BOARD_HAUPPAUGE_DVB_T1 18
156 #define CX88_BOARD_CONEXANT_DVB_T1 19
157 #define CX88_BOARD_PROVIDEO_PV259 20
158 #define CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS 21
159
160 enum cx88_itype {
161 CX88_VMUX_COMPOSITE1 = 1,
162 CX88_VMUX_COMPOSITE2,
163 CX88_VMUX_COMPOSITE3,
164 CX88_VMUX_COMPOSITE4,
165 CX88_VMUX_SVIDEO,
166 CX88_VMUX_TELEVISION,
167 CX88_VMUX_CABLE,
168 CX88_VMUX_DVB,
169 CX88_VMUX_DEBUG,
170 CX88_RADIO,
171 };
172
173 struct cx88_input {
174 enum cx88_itype type;
175 unsigned int vmux;
176 u32 gpio0, gpio1, gpio2, gpio3;
177 };
178
179 struct cx88_board {
180 char *name;
181 unsigned int tuner_type;
182 int tda9887_conf;
183 struct cx88_input input[8];
184 struct cx88_input radio;
185 int blackbird:1;
186 int dvb:1;
187 };
188
189 struct cx88_subid {
190 u16 subvendor;
191 u16 subdevice;
192 u32 card;
193 };
194
195 #define INPUT(nr) (&cx88_boards[core->board].input[nr])
196
197 /* ----------------------------------------------------------- */
198 /* device / file handle status */
199
200 #define RESOURCE_OVERLAY 1
201 #define RESOURCE_VIDEO 2
202 #define RESOURCE_VBI 4
203
204 #define BUFFER_TIMEOUT (HZ/2) /* 0.5 seconds */
205 //#define BUFFER_TIMEOUT (HZ*2)
206
207 /* buffer for one video frame */
208 struct cx88_buffer {
209 /* common v4l buffer stuff -- must be first */
210 struct videobuf_buffer vb;
211
212 /* cx88 specific */
213 unsigned int bpl;
214 struct btcx_riscmem risc;
215 struct cx8800_fmt *fmt;
216 u32 count;
217 };
218
219 struct cx88_dmaqueue {
220 struct list_head active;
221 struct list_head queued;
222 struct timer_list timeout;
223 struct btcx_riscmem stopper;
224 u32 count;
225 };
226
227 struct cx88_core {
228 struct list_head devlist;
229 atomic_t refcount;
230
231 /* board name */
232 int nr;
233 char name[32];
234
235 /* pci stuff */
236 int pci_bus;
237 int pci_slot;
238 u32 __iomem *lmmio;
239 u8 __iomem *bmmio;
240 u32 shadow[SHADOW_MAX];
241
242 /* i2c i/o */
243 struct i2c_adapter i2c_adap;
244 struct i2c_algo_bit_data i2c_algo;
245 struct i2c_client i2c_client;
246 u32 i2c_state, i2c_rc;
247
248 /* config info -- analog */
249 unsigned int board;
250 unsigned int tuner_type;
251 unsigned int tda9887_conf;
252 unsigned int has_radio;
253
254 /* config info -- dvb */
255 unsigned int pll_type;
256 unsigned int pll_addr;
257 unsigned int demod_addr;
258
259 /* state info */
260 struct task_struct *kthread;
261 struct cx88_tvnorm *tvnorm;
262 u32 tvaudio;
263 u32 input;
264 u32 astat;
265 };
266
267 struct cx8800_dev;
268 struct cx8802_dev;
269
270 /* ----------------------------------------------------------- */
271 /* function 0: video stuff */
272
273 struct cx8800_fh {
274 struct cx8800_dev *dev;
275 enum v4l2_buf_type type;
276 int radio;
277 unsigned int resources;
278
279 /* video overlay */
280 struct v4l2_window win;
281 struct v4l2_clip *clips;
282 unsigned int nclips;
283
284 /* video capture */
285 struct cx8800_fmt *fmt;
286 unsigned int width,height;
287 struct videobuf_queue vidq;
288
289 /* vbi capture */
290 struct videobuf_queue vbiq;
291 };
292
293 struct cx8800_suspend_state {
294 int disabled;
295 };
296
297 struct cx8800_dev {
298 struct cx88_core *core;
299 struct list_head devlist;
300 struct semaphore lock;
301 spinlock_t slock;
302
303 /* various device info */
304 unsigned int resources;
305 struct video_device *video_dev;
306 struct video_device *vbi_dev;
307 struct video_device *radio_dev;
308
309 /* pci i/o */
310 struct pci_dev *pci;
311 unsigned char pci_rev,pci_lat;
312
313 #if 0
314 /* video overlay */
315 struct v4l2_framebuffer fbuf;
316 struct cx88_buffer *screen;
317 #endif
318
319 /* capture queues */
320 struct cx88_dmaqueue vidq;
321 struct cx88_dmaqueue vbiq;
322
323 /* various v4l controls */
324 u32 freq;
325
326 /* other global state info */
327 struct cx8800_suspend_state state;
328 };
329
330 /* ----------------------------------------------------------- */
331 /* function 1: audio/alsa stuff */
332
333 struct cx8801_dev {
334 struct cx88_core *core;
335
336 /* pci i/o */
337 struct pci_dev *pci;
338 unsigned char pci_rev,pci_lat;
339 };
340
341 /* ----------------------------------------------------------- */
342 /* function 2: mpeg stuff */
343
344 struct cx8802_fh {
345 struct cx8802_dev *dev;
346 struct videobuf_queue mpegq;
347 };
348
349 struct cx8802_suspend_state {
350 int disabled;
351 };
352
353 struct cx8802_dev {
354 struct cx88_core *core;
355 struct semaphore lock;
356 spinlock_t slock;
357
358 /* pci i/o */
359 struct pci_dev *pci;
360 unsigned char pci_rev,pci_lat;
361
362 /* dma queues */
363 struct cx88_dmaqueue mpegq;
364 u32 ts_packet_size;
365 u32 ts_packet_count;
366
367 /* other global state info */
368 struct cx8802_suspend_state state;
369
370 /* for blackbird only */
371 struct list_head devlist;
372 struct video_device *mpeg_dev;
373 u32 mailbox;
374
375 /* for dvb only */
376 struct videobuf_dvb dvb;
377 void* fe_handle;
378 int (*fe_release)(void *handle);
379 };
380
381 /* ----------------------------------------------------------- */
382
383 #define cx_read(reg) readl(core->lmmio + ((reg)>>2))
384 #define cx_write(reg,value) writel((value), core->lmmio + ((reg)>>2))
385 #define cx_writeb(reg,value) writeb((value), core->bmmio + (reg))
386
387 #define cx_andor(reg,mask,value) \
388 writel((readl(core->lmmio+((reg)>>2)) & ~(mask)) |\
389 ((value) & (mask)), core->lmmio+((reg)>>2))
390 #define cx_set(reg,bit) cx_andor((reg),(bit),(bit))
391 #define cx_clear(reg,bit) cx_andor((reg),(bit),0)
392
393 #define cx_wait(d) { if (need_resched()) schedule(); else udelay(d); }
394
395 /* shadow registers */
396 #define cx_sread(sreg) (core->shadow[sreg])
397 #define cx_swrite(sreg,reg,value) \
398 (core->shadow[sreg] = value, \
399 writel(core->shadow[sreg], core->lmmio + ((reg)>>2)))
400 #define cx_sandor(sreg,reg,mask,value) \
401 (core->shadow[sreg] = (core->shadow[sreg] & ~(mask)) | ((value) & (mask)), \
402 writel(core->shadow[sreg], core->lmmio + ((reg)>>2)))
403
404 /* ----------------------------------------------------------- */
405 /* cx88-core.c */
406
407 extern char *cx88_pci_irqs[32];
408 extern char *cx88_vid_irqs[32];
409 extern char *cx88_mpeg_irqs[32];
410 extern void cx88_print_irqbits(char *name, char *tag, char **strings,
411 u32 bits, u32 mask);
412 extern void cx88_print_ioctl(char *name, unsigned int cmd);
413
414 extern void cx88_irq(struct cx88_core *core, u32 status, u32 mask);
415 extern void cx88_wakeup(struct cx88_core *core,
416 struct cx88_dmaqueue *q, u32 count);
417 extern void cx88_shutdown(struct cx88_core *core);
418 extern int cx88_reset(struct cx88_core *core);
419
420 extern int
421 cx88_risc_buffer(struct pci_dev *pci, struct btcx_riscmem *risc,
422 struct scatterlist *sglist,
423 unsigned int top_offset, unsigned int bottom_offset,
424 unsigned int bpl, unsigned int padding, unsigned int lines);
425 extern int
426 cx88_risc_databuffer(struct pci_dev *pci, struct btcx_riscmem *risc,
427 struct scatterlist *sglist, unsigned int bpl,
428 unsigned int lines);
429 extern int
430 cx88_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc,
431 u32 reg, u32 mask, u32 value);
432 extern void
433 cx88_free_buffer(struct pci_dev *pci, struct cx88_buffer *buf);
434
435 extern void cx88_risc_disasm(struct cx88_core *core,
436 struct btcx_riscmem *risc);
437 extern int cx88_sram_channel_setup(struct cx88_core *core,
438 struct sram_channel *ch,
439 unsigned int bpl, u32 risc);
440 extern void cx88_sram_channel_dump(struct cx88_core *core,
441 struct sram_channel *ch);
442
443 extern int cx88_set_scale(struct cx88_core *core, unsigned int width,
444 unsigned int height, enum v4l2_field field);
445 extern int cx88_set_tvnorm(struct cx88_core *core, struct cx88_tvnorm *norm);
446
447 extern struct video_device *cx88_vdev_init(struct cx88_core *core,
448 struct pci_dev *pci,
449 struct video_device *template,
450 char *type);
451 extern struct cx88_core* cx88_core_get(struct pci_dev *pci);
452 extern void cx88_core_put(struct cx88_core *core,
453 struct pci_dev *pci);
454
455 /* ----------------------------------------------------------- */
456 /* cx88-vbi.c */
457
458 void cx8800_vbi_fmt(struct cx8800_dev *dev, struct v4l2_format *f);
459 int cx8800_start_vbi_dma(struct cx8800_dev *dev,
460 struct cx88_dmaqueue *q,
461 struct cx88_buffer *buf);
462 int cx8800_stop_vbi_dma(struct cx8800_dev *dev);
463 int cx8800_restart_vbi_queue(struct cx8800_dev *dev,
464 struct cx88_dmaqueue *q);
465 void cx8800_vbi_timeout(unsigned long data);
466
467 extern struct videobuf_queue_ops cx8800_vbi_qops;
468
469 /* ----------------------------------------------------------- */
470 /* cx88-i2c.c */
471
472 extern int cx88_i2c_init(struct cx88_core *core, struct pci_dev *pci);
473 extern void cx88_call_i2c_clients(struct cx88_core *core,
474 unsigned int cmd, void *arg);
475
476
477 /* ----------------------------------------------------------- */
478 /* cx88-cards.c */
479
480 extern struct cx88_board cx88_boards[];
481 extern const unsigned int cx88_bcount;
482
483 extern struct cx88_subid cx88_subids[];
484 extern const unsigned int cx88_idcount;
485
486 extern void cx88_card_list(struct cx88_core *core, struct pci_dev *pci);
487 extern void cx88_card_setup(struct cx88_core *core);
488
489 /* ----------------------------------------------------------- */
490 /* cx88-tvaudio.c */
491
492 #define WW_NONE 1
493 #define WW_BTSC 2
494 #define WW_NICAM_I 3
495 #define WW_NICAM_BGDKL 4
496 #define WW_A1 5
497 #define WW_A2_BG 6
498 #define WW_A2_DK 7
499 #define WW_A2_M 8
500 #define WW_EIAJ 9
501 #define WW_SYSTEM_L_AM 10
502 #define WW_I2SPT 11
503 #define WW_FM 12
504
505 void cx88_set_tvaudio(struct cx88_core *core);
506 void cx88_get_stereo(struct cx88_core *core, struct v4l2_tuner *t);
507 void cx88_set_stereo(struct cx88_core *core, u32 mode);
508 int cx88_audio_thread(void *data);
509
510 /* ----------------------------------------------------------- */
511 /* cx88-mpeg.c */
512
513 int cx8802_buf_prepare(struct cx8802_dev *dev, struct cx88_buffer *buf);
514 void cx8802_buf_queue(struct cx8802_dev *dev, struct cx88_buffer *buf);
515 void cx8802_cancel_buffers(struct cx8802_dev *dev);
516
517 int cx8802_init_common(struct cx8802_dev *dev);
518 void cx8802_fini_common(struct cx8802_dev *dev);
519
520 int cx8802_suspend_common(struct pci_dev *pci_dev, u32 state);
521 int cx8802_resume_common(struct pci_dev *pci_dev);
522
523 /*
524 * Local variables:
525 * c-basic-offset: 8
526 * End:
527 */
528
|
This page was automatically generated by the
LXR engine.
|