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