blob: b9aa801b00a7b29c01c45334dd14d6c7c61bb978 [file] [log] [blame]
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -03001/*
2 * Driver for the Conexant CX25821 PCIe bridge
3 *
Mauro Carvalho Chehabbb4c9a72009-09-13 11:25:45 -03004 * Copyright (C) 2009 Conexant Systems Inc.
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -03005 * 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
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -030024#ifndef CX25821_H_
25#define CX25821_H_
26
27#include <linux/pci.h>
28#include <linux/i2c.h>
29#include <linux/i2c-algo-bit.h>
30#include <linux/interrupt.h>
31#include <linux/delay.h>
32#include <linux/sched.h>
33#include <linux/kdev_t.h>
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -030034
35#include <media/v4l2-common.h>
Mauro Carvalho Chehabbb4c9a72009-09-13 11:25:45 -030036#include <media/v4l2-device.h>
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -030037#include <media/tuner.h>
38#include <media/tveeprom.h>
39#include <media/videobuf-dma-sg.h>
40#include <media/videobuf-dvb.h>
41
42#include "btcx-risc.h"
43#include "cx25821-reg.h"
44#include "cx25821-medusa-reg.h"
45#include "cx25821-sram.h"
46#include "cx25821-audio.h"
47#include "media/cx2341x.h"
48
49#include <linux/version.h>
50#include <linux/mutex.h>
51
52#define CX25821_VERSION_CODE KERNEL_VERSION(0, 0, 106)
53
54#define UNSET (-1U)
55#define NO_SYNC_LINE (-1U)
56
57#define CX25821_MAXBOARDS 2
58
59#define TRUE 1
60#define FALSE 0
61#define LINE_SIZE_D1 1440
62
Palash Bandyopadhyay6d8c2ba2010-07-04 14:15:38 -030063/* Number of decoders and encoders */
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -030064#define MAX_DECODERS 8
65#define MAX_ENCODERS 2
66#define QUAD_DECODERS 4
67#define MAX_CAMERAS 16
68
69/* Max number of inputs by card */
Leonid V. Fedorenchikc7855ee2011-10-22 01:43:56 -030070#define MAX_CX25821_INPUT 8
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -030071#define INPUT(nr) (&cx25821_boards[dev->board].input[nr])
72#define RESOURCE_VIDEO0 1
73#define RESOURCE_VIDEO1 2
74#define RESOURCE_VIDEO2 4
75#define RESOURCE_VIDEO3 8
76#define RESOURCE_VIDEO4 16
77#define RESOURCE_VIDEO5 32
78#define RESOURCE_VIDEO6 64
79#define RESOURCE_VIDEO7 128
80#define RESOURCE_VIDEO8 256
81#define RESOURCE_VIDEO9 512
82#define RESOURCE_VIDEO10 1024
83#define RESOURCE_VIDEO11 2048
84#define RESOURCE_VIDEO_IOCTL 4096
85
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -030086#define BUFFER_TIMEOUT (HZ) /* 0.5 seconds */
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -030087
Leonid V. Fedorenchikc7855ee2011-10-22 01:43:56 -030088#define UNKNOWN_BOARD 0
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -030089#define CX25821_BOARD 1
90
Mauro Carvalho Chehabbb4c9a72009-09-13 11:25:45 -030091/* Currently supported by the driver */
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -030092#define CX25821_NORMS (\
Ruslan Pisareve4115bb2010-09-27 10:01:36 -030093 V4L2_STD_NTSC_M | V4L2_STD_NTSC_M_JP | V4L2_STD_NTSC_M_KR | \
94 V4L2_STD_PAL_BG | V4L2_STD_PAL_DK | V4L2_STD_PAL_I | \
95 V4L2_STD_PAL_M | V4L2_STD_PAL_N | V4L2_STD_PAL_H | \
96 V4L2_STD_PAL_Nc)
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -030097
98#define CX25821_BOARD_CONEXANT_ATHENA10 1
99#define MAX_VID_CHANNEL_NUM 12
100#define VID_CHANNEL_NUM 8
Dan Carpenter567a23f2011-10-13 02:41:41 -0300101#define CX25821_NR_INPUT 2
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300102
103struct cx25821_fmt {
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300104 char *name;
105 u32 fourcc; /* v4l2 format id */
106 int depth;
107 int flags;
108 u32 cxformat;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300109};
110
111struct cx25821_ctrl {
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300112 struct v4l2_queryctrl v;
113 u32 off;
114 u32 reg;
115 u32 mask;
116 u32 shift;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300117};
118
119struct cx25821_tvnorm {
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300120 char *name;
121 v4l2_std_id id;
122 u32 cxiformat;
123 u32 cxoformat;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300124};
125
126struct cx25821_fh {
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300127 struct cx25821_dev *dev;
128 enum v4l2_buf_type type;
129 int radio;
130 u32 resources;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300131
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300132 enum v4l2_priority prio;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300133
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300134 /* video overlay */
135 struct v4l2_window win;
136 struct v4l2_clip *clips;
137 unsigned int nclips;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300138
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300139 /* video capture */
140 struct cx25821_fmt *fmt;
141 unsigned int width, height;
Ruslan Pisareve4115bb2010-09-27 10:01:36 -0300142 int channel_id;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300143
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300144 /* vbi capture */
145 struct videobuf_queue vidq;
146 struct videobuf_queue vbiq;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300147
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300148 /* H264 Encoder specifics ONLY */
149 struct videobuf_queue mpegq;
150 atomic_t v4l_reading;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300151};
152
153enum cx25821_itype {
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300154 CX25821_VMUX_COMPOSITE = 1,
155 CX25821_VMUX_SVIDEO,
156 CX25821_VMUX_DEBUG,
157 CX25821_RADIO,
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300158};
159
160enum cx25821_src_sel_type {
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300161 CX25821_SRC_SEL_EXT_656_VIDEO = 0,
162 CX25821_SRC_SEL_PARALLEL_MPEG_VIDEO
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300163};
164
165/* buffer for one video frame */
166struct cx25821_buffer {
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300167 /* common v4l buffer stuff -- must be first */
168 struct videobuf_buffer vb;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300169
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300170 /* cx25821 specific */
171 unsigned int bpl;
172 struct btcx_riscmem risc;
173 struct cx25821_fmt *fmt;
174 u32 count;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300175};
176
177struct cx25821_input {
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300178 enum cx25821_itype type;
179 unsigned int vmux;
180 u32 gpio0, gpio1, gpio2, gpio3;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300181};
182
Leonid V. Fedorenchik7ae70c82011-09-02 11:55:29 +0800183enum port {
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300184 CX25821_UNDEFINED = 0,
185 CX25821_RAW,
186 CX25821_264
Leonid V. Fedorenchik7ae70c82011-09-02 11:55:29 +0800187};
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300188
189struct cx25821_board {
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300190 char *name;
Leonid V. Fedorenchik7ae70c82011-09-02 11:55:29 +0800191 enum port porta;
192 enum port portb;
193 enum port portc;
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300194 unsigned int tuner_type;
195 unsigned int radio_type;
196 unsigned char tuner_addr;
197 unsigned char radio_addr;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300198
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300199 u32 clk_freq;
Dan Carpenter567a23f2011-10-13 02:41:41 -0300200 struct cx25821_input input[CX25821_NR_INPUT];
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300201};
202
203struct cx25821_subid {
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300204 u16 subvendor;
205 u16 subdevice;
206 u32 card;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300207};
208
209struct cx25821_i2c {
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300210 struct cx25821_dev *dev;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300211
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300212 int nr;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300213
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300214 /* i2c i/o */
215 struct i2c_adapter i2c_adap;
216 struct i2c_algo_bit_data i2c_algo;
217 struct i2c_client i2c_client;
218 u32 i2c_rc;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300219
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300220 /* cx25821 registers used for raw addess */
221 u32 i2c_period;
222 u32 reg_ctrl;
223 u32 reg_stat;
224 u32 reg_addr;
225 u32 reg_rdata;
226 u32 reg_wdata;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300227};
228
229struct cx25821_dmaqueue {
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300230 struct list_head active;
231 struct list_head queued;
232 struct timer_list timeout;
233 struct btcx_riscmem stopper;
234 u32 count;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300235};
236
237struct cx25821_data {
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300238 struct cx25821_dev *dev;
239 struct sram_channel *channel;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300240};
241
Palash Bandyopadhyay6d8c2ba2010-07-04 14:15:38 -0300242struct cx25821_channel {
Ruslan Pisareve4115bb2010-09-27 10:01:36 -0300243 struct v4l2_prio_state prio;
Palash Bandyopadhyay6d8c2ba2010-07-04 14:15:38 -0300244
Ruslan Pisareve4115bb2010-09-27 10:01:36 -0300245 int ctl_bright;
246 int ctl_contrast;
247 int ctl_hue;
248 int ctl_saturation;
249 struct cx25821_data timeout_data;
Palash Bandyopadhyay6d8c2ba2010-07-04 14:15:38 -0300250
Ruslan Pisareve4115bb2010-09-27 10:01:36 -0300251 struct video_device *video_dev;
252 struct cx25821_dmaqueue vidq;
Palash Bandyopadhyay6d8c2ba2010-07-04 14:15:38 -0300253
Ruslan Pisareve4115bb2010-09-27 10:01:36 -0300254 struct sram_channel *sram_channels;
Palash Bandyopadhyay6d8c2ba2010-07-04 14:15:38 -0300255
Ruslan Pisareve4115bb2010-09-27 10:01:36 -0300256 struct mutex lock;
257 int resources;
Palash Bandyopadhyay6d8c2ba2010-07-04 14:15:38 -0300258
Ruslan Pisareve4115bb2010-09-27 10:01:36 -0300259 int pixel_formats;
260 int use_cif_resolution;
261 int cif_width;
Palash Bandyopadhyay6d8c2ba2010-07-04 14:15:38 -0300262};
263
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300264struct cx25821_dev {
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300265 struct list_head devlist;
266 atomic_t refcount;
267 struct v4l2_device v4l2_dev;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300268
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300269 /* pci stuff */
270 struct pci_dev *pci;
271 unsigned char pci_rev, pci_lat;
272 int pci_bus, pci_slot;
273 u32 base_io_addr;
274 u32 __iomem *lmmio;
275 u8 __iomem *bmmio;
276 int pci_irqmask;
277 int hwrevision;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300278
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300279 u32 clk_freq;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300280
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300281 /* I2C adapters: Master 1 & 2 (External) & Master 3 (Internal only) */
282 struct cx25821_i2c i2c_bus[3];
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300283
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300284 int nr;
285 struct mutex lock;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300286
Ruslan Pisareve4115bb2010-09-27 10:01:36 -0300287 struct cx25821_channel channels[MAX_VID_CHANNEL_NUM];
Palash Bandyopadhyay6d8c2ba2010-07-04 14:15:38 -0300288
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300289 /* board details */
290 unsigned int board;
291 char name[32];
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300292
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300293 /* Analog video */
294 u32 resources;
295 unsigned int input;
296 u32 tvaudio;
297 v4l2_std_id tvnorm;
298 unsigned int tuner_type;
299 unsigned char tuner_addr;
300 unsigned int radio_type;
301 unsigned char radio_addr;
302 unsigned int has_radio;
303 unsigned int videc_type;
304 unsigned char videc_addr;
305 unsigned short _max_num_decoders;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300306
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300307 /* Analog Audio Upstream */
308 int _audio_is_running;
309 int _audiopixel_format;
310 int _is_first_audio_frame;
311 int _audiofile_status;
312 int _audio_lines_count;
313 int _audioframe_count;
Leonid V. Fedorenchik6100c572011-09-02 11:55:30 +0800314 int _audio_upstream_channel;
Ruslan Pisareve4115bb2010-09-27 10:01:36 -0300315 int _last_index_irq; /* The last interrupt index processed. */
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300316
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300317 __le32 *_risc_audio_jmp_addr;
318 __le32 *_risc_virt_start_addr;
319 __le32 *_risc_virt_addr;
320 dma_addr_t _risc_phys_addr;
321 dma_addr_t _risc_phys_start_addr;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300322
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300323 unsigned int _audiorisc_size;
324 unsigned int _audiodata_buf_size;
325 __le32 *_audiodata_buf_virt_addr;
326 dma_addr_t _audiodata_buf_phys_addr;
327 char *_audiofilename;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300328
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300329 /* V4l */
330 u32 freq;
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300331 struct video_device *vbi_dev;
332 struct video_device *radio_dev;
333 struct video_device *ioctl_dev;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300334
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300335 spinlock_t slock;
Mauro Carvalho Chehabbb4c9a72009-09-13 11:25:45 -0300336
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300337 /* Video Upstream */
338 int _line_size;
339 int _prog_cnt;
340 int _pixel_format;
341 int _is_first_frame;
342 int _is_running;
343 int _file_status;
344 int _lines_count;
345 int _frame_count;
346 int _channel_upstream_select;
347 unsigned int _risc_size;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300348
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300349 __le32 *_dma_virt_start_addr;
350 __le32 *_dma_virt_addr;
351 dma_addr_t _dma_phys_addr;
352 dma_addr_t _dma_phys_start_addr;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300353
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300354 unsigned int _data_buf_size;
355 __le32 *_data_buf_virt_addr;
356 dma_addr_t _data_buf_phys_addr;
357 char *_filename;
358 char *_defaultname;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300359
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300360 int _line_size_ch2;
361 int _prog_cnt_ch2;
362 int _pixel_format_ch2;
363 int _is_first_frame_ch2;
364 int _is_running_ch2;
365 int _file_status_ch2;
366 int _lines_count_ch2;
367 int _frame_count_ch2;
368 int _channel2_upstream_select;
369 unsigned int _risc_size_ch2;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300370
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300371 __le32 *_dma_virt_start_addr_ch2;
372 __le32 *_dma_virt_addr_ch2;
373 dma_addr_t _dma_phys_addr_ch2;
374 dma_addr_t _dma_phys_start_addr_ch2;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300375
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300376 unsigned int _data_buf_size_ch2;
377 __le32 *_data_buf_virt_addr_ch2;
378 dma_addr_t _data_buf_phys_addr_ch2;
379 char *_filename_ch2;
380 char *_defaultname_ch2;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300381
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300382 /* MPEG Encoder ONLY settings */
383 u32 cx23417_mailbox;
384 struct cx2341x_mpeg_params mpeg_params;
385 struct video_device *v4l_device;
386 atomic_t v4l_reader_count;
387 struct cx25821_tvnorm encodernorm;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300388
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300389 u32 upstream_riscbuf_size;
390 u32 upstream_databuf_size;
391 u32 upstream_riscbuf_size_ch2;
392 u32 upstream_databuf_size_ch2;
393 u32 audio_upstream_riscbuf_size;
394 u32 audio_upstream_databuf_size;
395 int _isNTSC;
396 int _frame_index;
397 int _audioframe_index;
398 struct workqueue_struct *_irq_queues;
399 struct work_struct _irq_work_entry;
400 struct workqueue_struct *_irq_queues_ch2;
401 struct work_struct _irq_work_entry_ch2;
402 struct workqueue_struct *_irq_audio_queues;
403 struct work_struct _audio_work_entry;
404 char *input_filename;
405 char *input_filename_ch2;
406 int _frame_index_ch2;
407 int _isNTSC_ch2;
408 char *vid_stdname_ch2;
409 int pixel_format_ch2;
410 int channel_select_ch2;
411 int command_ch2;
412 char *input_audiofilename;
413 char *vid_stdname;
414 int pixel_format;
415 int channel_select;
416 int command;
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300417 int channel_opened;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300418};
419
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300420struct upstream_user_struct {
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300421 char *input_filename;
422 char *vid_stdname;
423 int pixel_format;
424 int channel_select;
425 int command;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300426};
427
428struct downstream_user_struct {
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300429 char *vid_stdname;
430 int pixel_format;
431 int cif_resolution_enable;
432 int cif_width;
433 int decoder_select;
434 int command;
435 int reg_address;
436 int reg_data;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300437};
438
439extern struct upstream_user_struct *up_data;
440
441static inline struct cx25821_dev *get_cx25821(struct v4l2_device *v4l2_dev)
442{
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300443 return container_of(v4l2_dev, struct cx25821_dev, v4l2_dev);
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300444}
445
446#define cx25821_call_all(dev, o, f, args...) \
Ruslan Pisareve4115bb2010-09-27 10:01:36 -0300447 v4l2_device_call_all(&dev->v4l2_dev, 0, o, f, ##args)
Mauro Carvalho Chehabbb4c9a72009-09-13 11:25:45 -0300448
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300449extern struct list_head cx25821_devlist;
Arnd Bergmann0cd301f2011-03-02 17:15:15 -0300450extern struct mutex cx25821_devlist_mutex;
451
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300452extern struct cx25821_board cx25821_boards[];
453extern struct cx25821_subid cx25821_subids[];
454
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300455#define SRAM_CH00 0 /* Video A */
456#define SRAM_CH01 1 /* Video B */
457#define SRAM_CH02 2 /* Video C */
458#define SRAM_CH03 3 /* Video D */
459#define SRAM_CH04 4 /* Video E */
460#define SRAM_CH05 5 /* Video F */
461#define SRAM_CH06 6 /* Video G */
462#define SRAM_CH07 7 /* Video H */
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300463
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300464#define SRAM_CH08 8 /* Audio A */
465#define SRAM_CH09 9 /* Video Upstream I */
466#define SRAM_CH10 10 /* Video Upstream J */
467#define SRAM_CH11 11 /* Audio Upstream AUD_CHANNEL_B */
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300468
469#define VID_UPSTREAM_SRAM_CHANNEL_I SRAM_CH09
470#define VID_UPSTREAM_SRAM_CHANNEL_J SRAM_CH10
471#define AUDIO_UPSTREAM_SRAM_CHANNEL_B SRAM_CH11
472#define VIDEO_IOCTL_CH 11
473
474struct sram_channel {
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300475 char *name;
476 u32 i;
477 u32 cmds_start;
478 u32 ctrl_start;
479 u32 cdt;
480 u32 fifo_start;
481 u32 fifo_size;
482 u32 ptr1_reg;
483 u32 ptr2_reg;
484 u32 cnt1_reg;
485 u32 cnt2_reg;
486 u32 int_msk;
487 u32 int_stat;
488 u32 int_mstat;
489 u32 dma_ctl;
490 u32 gpcnt_ctl;
491 u32 gpcnt;
492 u32 aud_length;
493 u32 aud_cfg;
494 u32 fld_aud_fifo_en;
495 u32 fld_aud_risc_en;
Mauro Carvalho Chehabbb4c9a72009-09-13 11:25:45 -0300496
Ruslan Pisareve4115bb2010-09-27 10:01:36 -0300497 /* For Upstream Video */
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300498 u32 vid_fmt_ctl;
499 u32 vid_active_ctl1;
500 u32 vid_active_ctl2;
501 u32 vid_cdt_size;
Mauro Carvalho Chehabbb4c9a72009-09-13 11:25:45 -0300502
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300503 u32 vip_ctl;
504 u32 pix_frmt;
505 u32 jumponly;
506 u32 irq_bit;
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300507};
508extern struct sram_channel cx25821_sram_channels[];
509
510#define STATUS_SUCCESS 0
511#define STATUS_UNSUCCESSFUL -1
512
513#define cx_read(reg) readl(dev->lmmio + ((reg)>>2))
514#define cx_write(reg, value) writel((value), dev->lmmio + ((reg)>>2))
515
516#define cx_andor(reg, mask, value) \
Ruslan Pisareve4115bb2010-09-27 10:01:36 -0300517 writel((readl(dev->lmmio+((reg)>>2)) & ~(mask)) |\
518 ((value) & (mask)), dev->lmmio+((reg)>>2))
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300519
520#define cx_set(reg, bit) cx_andor((reg), (bit), (bit))
521#define cx_clear(reg, bit) cx_andor((reg), (bit), 0)
522
523#define Set_GPIO_Bit(Bit) (1 << Bit)
524#define Clear_GPIO_Bit(Bit) (~(1 << Bit))
525
Joe Perches36d89f72010-11-07 17:48:21 -0300526#define CX25821_ERR(fmt, args...) \
527 pr_err("(%d): " fmt, dev->board, ##args)
528#define CX25821_WARN(fmt, args...) \
529 pr_warn("(%d): " fmt, dev->board, ##args)
530#define CX25821_INFO(fmt, args...) \
531 pr_info("(%d): " fmt, dev->board, ##args)
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300532
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300533extern int cx25821_i2c_register(struct cx25821_i2c *bus);
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300534extern void cx25821_card_setup(struct cx25821_dev *dev);
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300535extern int cx25821_ir_init(struct cx25821_dev *dev);
536extern int cx25821_i2c_read(struct cx25821_i2c *bus, u16 reg_addr, int *value);
537extern int cx25821_i2c_write(struct cx25821_i2c *bus, u16 reg_addr, int value);
538extern int cx25821_i2c_unregister(struct cx25821_i2c *bus);
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300539extern void cx25821_gpio_init(struct cx25821_dev *dev);
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300540extern void cx25821_set_gpiopin_direction(struct cx25821_dev *dev,
541 int pin_number, int pin_logic_value);
Mauro Carvalho Chehabbb4c9a72009-09-13 11:25:45 -0300542
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300543extern int medusa_video_init(struct cx25821_dev *dev);
544extern int medusa_set_videostandard(struct cx25821_dev *dev);
545extern void medusa_set_resolution(struct cx25821_dev *dev, int width,
546 int decoder_select);
547extern int medusa_set_brightness(struct cx25821_dev *dev, int brightness,
548 int decoder);
549extern int medusa_set_contrast(struct cx25821_dev *dev, int contrast,
550 int decoder);
551extern int medusa_set_hue(struct cx25821_dev *dev, int hue, int decoder);
552extern int medusa_set_saturation(struct cx25821_dev *dev, int saturation,
553 int decoder);
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300554
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300555extern int cx25821_sram_channel_setup(struct cx25821_dev *dev,
556 struct sram_channel *ch, unsigned int bpl,
557 u32 risc);
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300558
559extern int cx25821_risc_buffer(struct pci_dev *pci, struct btcx_riscmem *risc,
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300560 struct scatterlist *sglist,
561 unsigned int top_offset,
562 unsigned int bottom_offset,
563 unsigned int bpl,
564 unsigned int padding, unsigned int lines);
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300565extern int cx25821_risc_databuffer_audio(struct pci_dev *pci,
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300566 struct btcx_riscmem *risc,
567 struct scatterlist *sglist,
568 unsigned int bpl,
569 unsigned int lines, unsigned int lpi);
570extern void cx25821_free_buffer(struct videobuf_queue *q,
571 struct cx25821_buffer *buf);
572extern int cx25821_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc,
573 u32 reg, u32 mask, u32 value);
574extern void cx25821_sram_channel_dump(struct cx25821_dev *dev,
575 struct sram_channel *ch);
576extern void cx25821_sram_channel_dump_audio(struct cx25821_dev *dev,
577 struct sram_channel *ch);
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300578
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300579extern struct cx25821_dev *cx25821_dev_get(struct pci_dev *pci);
580extern void cx25821_print_irqbits(char *name, char *tag, char **strings,
581 int len, u32 bits, u32 mask);
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300582extern void cx25821_dev_unregister(struct cx25821_dev *dev);
583extern int cx25821_sram_channel_setup_audio(struct cx25821_dev *dev,
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300584 struct sram_channel *ch,
585 unsigned int bpl, u32 risc);
Mauro Carvalho Chehabbb4c9a72009-09-13 11:25:45 -0300586
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300587extern int cx25821_vidupstream_init_ch1(struct cx25821_dev *dev,
588 int channel_select, int pixel_format);
589extern int cx25821_vidupstream_init_ch2(struct cx25821_dev *dev,
590 int channel_select, int pixel_format);
591extern int cx25821_audio_upstream_init(struct cx25821_dev *dev,
592 int channel_select);
Mauro Carvalho Chehabbb4c9a72009-09-13 11:25:45 -0300593extern void cx25821_free_mem_upstream_ch1(struct cx25821_dev *dev);
594extern void cx25821_free_mem_upstream_ch2(struct cx25821_dev *dev);
595extern void cx25821_free_mem_upstream_audio(struct cx25821_dev *dev);
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300596extern void cx25821_start_upstream_video_ch1(struct cx25821_dev *dev,
597 struct upstream_user_struct
598 *up_data);
599extern void cx25821_start_upstream_video_ch2(struct cx25821_dev *dev,
600 struct upstream_user_struct
601 *up_data);
602extern void cx25821_start_upstream_audio(struct cx25821_dev *dev,
603 struct upstream_user_struct *up_data);
Mauro Carvalho Chehabbb4c9a72009-09-13 11:25:45 -0300604extern void cx25821_stop_upstream_video_ch1(struct cx25821_dev *dev);
605extern void cx25821_stop_upstream_video_ch2(struct cx25821_dev *dev);
606extern void cx25821_stop_upstream_audio(struct cx25821_dev *dev);
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300607extern int cx25821_sram_channel_setup_upstream(struct cx25821_dev *dev,
608 struct sram_channel *ch,
609 unsigned int bpl, u32 risc);
610extern void cx25821_set_pixel_format(struct cx25821_dev *dev, int channel,
611 u32 format);
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300612extern void cx25821_videoioctl_unregister(struct cx25821_dev *dev);
613extern struct video_device *cx25821_vdev_init(struct cx25821_dev *dev,
Mauro Carvalho Chehab1a9fc852009-09-13 11:30:11 -0300614 struct pci_dev *pci,
615 struct video_device *template,
616 char *type);
Mauro Carvalho Chehab02b20b02009-09-15 11:33:54 -0300617#endif