]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/media/pci/cx25821/cx25821.h
[media] cx25821: embed video_device, clean up some kernel log spam
[karo-tx-linux.git] / drivers / media / pci / cx25821 / cx25821.h
1 /*
2  *  Driver for the Conexant CX25821 PCIe bridge
3  *
4  *  Copyright (C) 2009 Conexant Systems Inc.
5  *  Authors  <shu.lin@conexant.com>, <hiep.huynh@conexant.com>
6  *  Based on Steven Toth <stoth@linuxtv.org> cx23885 driver
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  *
17  *  GNU General Public License for more details.
18  *
19  *  You should have received a copy of the GNU General Public License
20  *  along with this program; if not, write to the Free Software
21  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  */
23
24 #ifndef CX25821_H_
25 #define CX25821_H_
26
27 #include <linux/pci.h>
28 #include <linux/i2c.h>
29 #include <linux/interrupt.h>
30 #include <linux/delay.h>
31 #include <linux/sched.h>
32 #include <linux/kdev_t.h>
33
34 #include <media/v4l2-common.h>
35 #include <media/v4l2-device.h>
36 #include <media/videobuf-dma-sg.h>
37
38 #include "btcx-risc.h"
39 #include "cx25821-reg.h"
40 #include "cx25821-medusa-reg.h"
41 #include "cx25821-sram.h"
42 #include "cx25821-audio.h"
43
44 #include <linux/version.h>
45 #include <linux/mutex.h>
46
47 #define CX25821_VERSION_CODE KERNEL_VERSION(0, 0, 106)
48
49 #define UNSET (-1U)
50 #define NO_SYNC_LINE (-1U)
51
52 #define CX25821_MAXBOARDS 2
53
54 #define TRUE    1
55 #define FALSE   0
56 #define LINE_SIZE_D1    1440
57
58 /* Number of decoders and encoders */
59 #define MAX_DECODERS            8
60 #define MAX_ENCODERS            2
61 #define QUAD_DECODERS           4
62 #define MAX_CAMERAS             16
63
64 /* Max number of inputs by card */
65 #define MAX_CX25821_INPUT     8
66 #define INPUT(nr) (&cx25821_boards[dev->board].input[nr])
67 #define RESOURCE_VIDEO0       1
68 #define RESOURCE_VIDEO1       2
69 #define RESOURCE_VIDEO2       4
70 #define RESOURCE_VIDEO3       8
71 #define RESOURCE_VIDEO4       16
72 #define RESOURCE_VIDEO5       32
73 #define RESOURCE_VIDEO6       64
74 #define RESOURCE_VIDEO7       128
75 #define RESOURCE_VIDEO8       256
76 #define RESOURCE_VIDEO9       512
77 #define RESOURCE_VIDEO10      1024
78 #define RESOURCE_VIDEO11      2048
79
80 #define BUFFER_TIMEOUT     (HZ) /* 0.5 seconds */
81
82 #define UNKNOWN_BOARD        0
83 #define CX25821_BOARD        1
84
85 /* Currently supported by the driver */
86 #define CX25821_NORMS (\
87         V4L2_STD_NTSC_M |  V4L2_STD_NTSC_M_JP | V4L2_STD_NTSC_M_KR | \
88         V4L2_STD_PAL_BG |  V4L2_STD_PAL_DK    |  V4L2_STD_PAL_I    | \
89         V4L2_STD_PAL_M  |  V4L2_STD_PAL_N     |  V4L2_STD_PAL_H    | \
90         V4L2_STD_PAL_Nc)
91
92 #define CX25821_BOARD_CONEXANT_ATHENA10 1
93 #define MAX_VID_CHANNEL_NUM     12
94 #define VID_CHANNEL_NUM 8
95 #define CX25821_NR_INPUT 2
96
97 struct cx25821_fmt {
98         char *name;
99         u32 fourcc;             /* v4l2 format id */
100         int depth;
101         int flags;
102         u32 cxformat;
103 };
104
105 struct cx25821_ctrl {
106         struct v4l2_queryctrl v;
107         u32 off;
108         u32 reg;
109         u32 mask;
110         u32 shift;
111 };
112
113 struct cx25821_tvnorm {
114         char *name;
115         v4l2_std_id id;
116         u32 cxiformat;
117         u32 cxoformat;
118 };
119
120 struct cx25821_fh {
121         struct cx25821_dev *dev;
122         enum v4l2_buf_type type;
123         u32 resources;
124
125         enum v4l2_priority prio;
126
127         /* video capture */
128         const struct cx25821_fmt *fmt;
129         unsigned int width, height;
130         int channel_id;
131         struct videobuf_queue vidq;
132 };
133
134 enum cx25821_itype {
135         CX25821_VMUX_COMPOSITE = 1,
136         CX25821_VMUX_SVIDEO,
137         CX25821_VMUX_DEBUG,
138 };
139
140 enum cx25821_src_sel_type {
141         CX25821_SRC_SEL_EXT_656_VIDEO = 0,
142         CX25821_SRC_SEL_PARALLEL_MPEG_VIDEO
143 };
144
145 /* buffer for one video frame */
146 struct cx25821_buffer {
147         /* common v4l buffer stuff -- must be first */
148         struct videobuf_buffer vb;
149
150         /* cx25821 specific */
151         unsigned int bpl;
152         struct btcx_riscmem risc;
153         const struct cx25821_fmt *fmt;
154         u32 count;
155 };
156
157 struct cx25821_input {
158         enum cx25821_itype type;
159         unsigned int vmux;
160         u32 gpio0, gpio1, gpio2, gpio3;
161 };
162
163 enum port {
164         CX25821_UNDEFINED = 0,
165         CX25821_RAW,
166         CX25821_264
167 };
168
169 struct cx25821_board {
170         const char *name;
171         enum port porta;
172         enum port portb;
173         enum port portc;
174
175         u32 clk_freq;
176         struct cx25821_input input[CX25821_NR_INPUT];
177 };
178
179 struct cx25821_i2c {
180         struct cx25821_dev *dev;
181
182         int nr;
183
184         /* i2c i/o */
185         struct i2c_adapter i2c_adap;
186         struct i2c_client i2c_client;
187         u32 i2c_rc;
188
189         /* cx25821 registers used for raw addess */
190         u32 i2c_period;
191         u32 reg_ctrl;
192         u32 reg_stat;
193         u32 reg_addr;
194         u32 reg_rdata;
195         u32 reg_wdata;
196 };
197
198 struct cx25821_dmaqueue {
199         struct list_head active;
200         struct list_head queued;
201         struct timer_list timeout;
202         struct btcx_riscmem stopper;
203         u32 count;
204 };
205
206 struct cx25821_data {
207         struct cx25821_dev *dev;
208         const struct sram_channel *channel;
209 };
210
211 struct cx25821_channel {
212         struct v4l2_prio_state prio;
213
214         int ctl_bright;
215         int ctl_contrast;
216         int ctl_hue;
217         int ctl_saturation;
218         struct cx25821_data timeout_data;
219
220         struct video_device vdev;
221         struct cx25821_dmaqueue vidq;
222
223         const struct sram_channel *sram_channels;
224
225         struct mutex lock;
226         int resources;
227
228         int pixel_formats;
229         int use_cif_resolution;
230         int cif_width;
231 };
232
233 struct snd_card;
234
235 struct cx25821_dev {
236         struct v4l2_device v4l2_dev;
237
238         /* pci stuff */
239         struct pci_dev *pci;
240         unsigned char pci_rev, pci_lat;
241         int pci_bus, pci_slot;
242         u32 base_io_addr;
243         u32 __iomem *lmmio;
244         u8 __iomem *bmmio;
245         int pci_irqmask;
246         int hwrevision;
247         /* used by cx25821-alsa */
248         struct snd_card *card;
249
250         u32 clk_freq;
251
252         /* I2C adapters: Master 1 & 2 (External) & Master 3 (Internal only) */
253         struct cx25821_i2c i2c_bus[3];
254
255         int nr;
256         struct mutex lock;
257
258         struct cx25821_channel channels[MAX_VID_CHANNEL_NUM];
259
260         /* board details */
261         unsigned int board;
262         char name[32];
263
264         /* Analog video */
265         u32 resources;
266         unsigned int input;
267         v4l2_std_id tvnorm;
268         unsigned short _max_num_decoders;
269
270         /* Analog Audio Upstream */
271         int _audio_is_running;
272         int _audiopixel_format;
273         int _is_first_audio_frame;
274         int _audiofile_status;
275         int _audio_lines_count;
276         int _audioframe_count;
277         int _audio_upstream_channel;
278         int _last_index_irq;    /* The last interrupt index processed. */
279
280         __le32 *_risc_audio_jmp_addr;
281         __le32 *_risc_virt_start_addr;
282         __le32 *_risc_virt_addr;
283         dma_addr_t _risc_phys_addr;
284         dma_addr_t _risc_phys_start_addr;
285
286         unsigned int _audiorisc_size;
287         unsigned int _audiodata_buf_size;
288         __le32 *_audiodata_buf_virt_addr;
289         dma_addr_t _audiodata_buf_phys_addr;
290         char *_audiofilename;
291
292         /* V4l */
293         spinlock_t slock;
294
295         /* Video Upstream */
296         int _line_size;
297         int _prog_cnt;
298         int _pixel_format;
299         int _is_first_frame;
300         int _is_running;
301         int _file_status;
302         int _lines_count;
303         int _frame_count;
304         int _channel_upstream_select;
305         unsigned int _risc_size;
306
307         __le32 *_dma_virt_start_addr;
308         __le32 *_dma_virt_addr;
309         dma_addr_t _dma_phys_addr;
310         dma_addr_t _dma_phys_start_addr;
311
312         unsigned int _data_buf_size;
313         __le32 *_data_buf_virt_addr;
314         dma_addr_t _data_buf_phys_addr;
315         char *_filename;
316         char *_defaultname;
317
318         int _line_size_ch2;
319         int _prog_cnt_ch2;
320         int _pixel_format_ch2;
321         int _is_first_frame_ch2;
322         int _is_running_ch2;
323         int _file_status_ch2;
324         int _lines_count_ch2;
325         int _frame_count_ch2;
326         int _channel2_upstream_select;
327         unsigned int _risc_size_ch2;
328
329         __le32 *_dma_virt_start_addr_ch2;
330         __le32 *_dma_virt_addr_ch2;
331         dma_addr_t _dma_phys_addr_ch2;
332         dma_addr_t _dma_phys_start_addr_ch2;
333
334         unsigned int _data_buf_size_ch2;
335         __le32 *_data_buf_virt_addr_ch2;
336         dma_addr_t _data_buf_phys_addr_ch2;
337         char *_filename_ch2;
338         char *_defaultname_ch2;
339
340         u32 upstream_riscbuf_size;
341         u32 upstream_databuf_size;
342         u32 upstream_riscbuf_size_ch2;
343         u32 upstream_databuf_size_ch2;
344         u32 audio_upstream_riscbuf_size;
345         u32 audio_upstream_databuf_size;
346         int _isNTSC;
347         int _frame_index;
348         int _audioframe_index;
349         struct workqueue_struct *_irq_queues;
350         struct work_struct _irq_work_entry;
351         struct workqueue_struct *_irq_queues_ch2;
352         struct work_struct _irq_work_entry_ch2;
353         struct workqueue_struct *_irq_audio_queues;
354         struct work_struct _audio_work_entry;
355         char *input_filename;
356         char *input_filename_ch2;
357         int _frame_index_ch2;
358         int _isNTSC_ch2;
359         char *vid_stdname_ch2;
360         int pixel_format_ch2;
361         int channel_select_ch2;
362         int command_ch2;
363         char *input_audiofilename;
364         char *vid_stdname;
365         int pixel_format;
366         int channel_select;
367         int command;
368         int channel_opened;
369 };
370
371 struct upstream_user_struct {
372         char *input_filename;
373         char *vid_stdname;
374         int pixel_format;
375         int channel_select;
376         int command;
377 };
378
379 struct downstream_user_struct {
380         char *vid_stdname;
381         int pixel_format;
382         int cif_resolution_enable;
383         int cif_width;
384         int decoder_select;
385         int command;
386         int reg_address;
387         int reg_data;
388 };
389
390 extern struct upstream_user_struct *up_data;
391
392 static inline struct cx25821_dev *get_cx25821(struct v4l2_device *v4l2_dev)
393 {
394         return container_of(v4l2_dev, struct cx25821_dev, v4l2_dev);
395 }
396
397 #define cx25821_call_all(dev, o, f, args...) \
398         v4l2_device_call_all(&dev->v4l2_dev, 0, o, f, ##args)
399
400 extern struct cx25821_board cx25821_boards[];
401
402 #define SRAM_CH00  0            /* Video A */
403 #define SRAM_CH01  1            /* Video B */
404 #define SRAM_CH02  2            /* Video C */
405 #define SRAM_CH03  3            /* Video D */
406 #define SRAM_CH04  4            /* Video E */
407 #define SRAM_CH05  5            /* Video F */
408 #define SRAM_CH06  6            /* Video G */
409 #define SRAM_CH07  7            /* Video H */
410
411 #define SRAM_CH08  8            /* Audio A */
412 #define SRAM_CH09  9            /* Video Upstream I */
413 #define SRAM_CH10  10           /* Video Upstream J */
414 #define SRAM_CH11  11           /* Audio Upstream AUD_CHANNEL_B */
415
416 #define VID_UPSTREAM_SRAM_CHANNEL_I     SRAM_CH09
417 #define VID_UPSTREAM_SRAM_CHANNEL_J     SRAM_CH10
418 #define AUDIO_UPSTREAM_SRAM_CHANNEL_B   SRAM_CH11
419
420 struct sram_channel {
421         char *name;
422         u32 i;
423         u32 cmds_start;
424         u32 ctrl_start;
425         u32 cdt;
426         u32 fifo_start;
427         u32 fifo_size;
428         u32 ptr1_reg;
429         u32 ptr2_reg;
430         u32 cnt1_reg;
431         u32 cnt2_reg;
432         u32 int_msk;
433         u32 int_stat;
434         u32 int_mstat;
435         u32 dma_ctl;
436         u32 gpcnt_ctl;
437         u32 gpcnt;
438         u32 aud_length;
439         u32 aud_cfg;
440         u32 fld_aud_fifo_en;
441         u32 fld_aud_risc_en;
442
443         /* For Upstream Video */
444         u32 vid_fmt_ctl;
445         u32 vid_active_ctl1;
446         u32 vid_active_ctl2;
447         u32 vid_cdt_size;
448
449         u32 vip_ctl;
450         u32 pix_frmt;
451         u32 jumponly;
452         u32 irq_bit;
453 };
454
455 extern const struct sram_channel cx25821_sram_channels[];
456
457 #define STATUS_SUCCESS         0
458 #define STATUS_UNSUCCESSFUL    -1
459
460 #define cx_read(reg)             readl(dev->lmmio + ((reg)>>2))
461 #define cx_write(reg, value)     writel((value), dev->lmmio + ((reg)>>2))
462
463 #define cx_andor(reg, mask, value) \
464         writel((readl(dev->lmmio+((reg)>>2)) & ~(mask)) |\
465         ((value) & (mask)), dev->lmmio+((reg)>>2))
466
467 #define cx_set(reg, bit)          cx_andor((reg), (bit), (bit))
468 #define cx_clear(reg, bit)        cx_andor((reg), (bit), 0)
469
470 #define Set_GPIO_Bit(Bit)                       (1 << Bit)
471 #define Clear_GPIO_Bit(Bit)                     (~(1 << Bit))
472
473 #define CX25821_ERR(fmt, args...)                       \
474         pr_err("(%d): " fmt, dev->board, ##args)
475 #define CX25821_WARN(fmt, args...)                      \
476         pr_warn("(%d): " fmt, dev->board, ##args)
477 #define CX25821_INFO(fmt, args...)                      \
478         pr_info("(%d): " fmt, dev->board, ##args)
479
480 extern int cx25821_i2c_register(struct cx25821_i2c *bus);
481 extern int cx25821_i2c_read(struct cx25821_i2c *bus, u16 reg_addr, int *value);
482 extern int cx25821_i2c_write(struct cx25821_i2c *bus, u16 reg_addr, int value);
483 extern int cx25821_i2c_unregister(struct cx25821_i2c *bus);
484 extern void cx25821_gpio_init(struct cx25821_dev *dev);
485 extern void cx25821_set_gpiopin_direction(struct cx25821_dev *dev,
486                                           int pin_number, int pin_logic_value);
487
488 extern int medusa_video_init(struct cx25821_dev *dev);
489 extern int medusa_set_videostandard(struct cx25821_dev *dev);
490 extern void medusa_set_resolution(struct cx25821_dev *dev, int width,
491                                   int decoder_select);
492 extern int medusa_set_brightness(struct cx25821_dev *dev, int brightness,
493                                  int decoder);
494 extern int medusa_set_contrast(struct cx25821_dev *dev, int contrast,
495                                int decoder);
496 extern int medusa_set_hue(struct cx25821_dev *dev, int hue, int decoder);
497 extern int medusa_set_saturation(struct cx25821_dev *dev, int saturation,
498                                  int decoder);
499
500 extern int cx25821_sram_channel_setup(struct cx25821_dev *dev,
501                                       const struct sram_channel *ch, unsigned int bpl,
502                                       u32 risc);
503
504 extern int cx25821_risc_buffer(struct pci_dev *pci, struct btcx_riscmem *risc,
505                                struct scatterlist *sglist,
506                                unsigned int top_offset,
507                                unsigned int bottom_offset,
508                                unsigned int bpl,
509                                unsigned int padding, unsigned int lines);
510 extern int cx25821_risc_databuffer_audio(struct pci_dev *pci,
511                                          struct btcx_riscmem *risc,
512                                          struct scatterlist *sglist,
513                                          unsigned int bpl,
514                                          unsigned int lines, unsigned int lpi);
515 extern void cx25821_free_buffer(struct videobuf_queue *q,
516                                 struct cx25821_buffer *buf);
517 extern int cx25821_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc,
518                                 u32 reg, u32 mask, u32 value);
519 extern void cx25821_sram_channel_dump(struct cx25821_dev *dev,
520                                       const struct sram_channel *ch);
521 extern void cx25821_sram_channel_dump_audio(struct cx25821_dev *dev,
522                                             const struct sram_channel *ch);
523
524 extern struct cx25821_dev *cx25821_dev_get(struct pci_dev *pci);
525 extern void cx25821_print_irqbits(char *name, char *tag, char **strings,
526                                   int len, u32 bits, u32 mask);
527 extern void cx25821_dev_unregister(struct cx25821_dev *dev);
528 extern int cx25821_sram_channel_setup_audio(struct cx25821_dev *dev,
529                                             const struct sram_channel *ch,
530                                             unsigned int bpl, u32 risc);
531
532 extern int cx25821_vidupstream_init_ch1(struct cx25821_dev *dev,
533                                         int channel_select, int pixel_format);
534 extern int cx25821_vidupstream_init_ch2(struct cx25821_dev *dev,
535                                         int channel_select, int pixel_format);
536 extern int cx25821_audio_upstream_init(struct cx25821_dev *dev,
537                                        int channel_select);
538 extern void cx25821_free_mem_upstream_ch1(struct cx25821_dev *dev);
539 extern void cx25821_free_mem_upstream_ch2(struct cx25821_dev *dev);
540 extern void cx25821_free_mem_upstream_audio(struct cx25821_dev *dev);
541 extern void cx25821_start_upstream_video_ch1(struct cx25821_dev *dev,
542                                              struct upstream_user_struct
543                                              *up_data);
544 extern void cx25821_start_upstream_video_ch2(struct cx25821_dev *dev,
545                                              struct upstream_user_struct
546                                              *up_data);
547 extern void cx25821_start_upstream_audio(struct cx25821_dev *dev,
548                                          struct upstream_user_struct *up_data);
549 extern void cx25821_stop_upstream_video_ch1(struct cx25821_dev *dev);
550 extern void cx25821_stop_upstream_video_ch2(struct cx25821_dev *dev);
551 extern void cx25821_stop_upstream_audio(struct cx25821_dev *dev);
552 extern int cx25821_sram_channel_setup_upstream(struct cx25821_dev *dev,
553                                                const struct sram_channel *ch,
554                                                unsigned int bpl, u32 risc);
555 extern void cx25821_set_pixel_format(struct cx25821_dev *dev, int channel,
556                                      u32 format);
557
558 #endif