blob: 1f6c5be65a5539200bf51d140df327cb11608667 [file] [log] [blame]
Sri Deevie0d3baf2009-03-03 14:37:50 -03001/*
2 cx231xx.h - driver for Conexant Cx23100/101/102 USB video capture devices
3
4 Copyright (C) 2008 <srinivasa.deevi at conexant dot com>
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -03005 Based on em28xx driver
Sri Deevie0d3baf2009-03-03 14:37:50 -03006
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22#ifndef _CX231XX_H
23#define _CX231XX_H
24
25#include <linux/videodev2.h>
26#include <media/videobuf-vmalloc.h>
27
28#include <linux/i2c.h>
29#include <linux/i2c-algo-bit.h>
30#include <linux/mutex.h>
31#include <media/ir-kbd-i2c.h>
32#if defined(CONFIG_VIDEO_CX231XX_DVB) || defined(CONFIG_VIDEO_CX231XX_DVB_MODULE)
33#include <media/videobuf-dvb.h>
34#endif
35
36#include "cx231xx-reg.h"
37#include "cx231xx-pcb-config.h"
38#include "cx231xx-conf-reg.h"
39
40#define CX231XX_VERSION_CODE KERNEL_VERSION(0, 1, 0)
41#define DRIVER_NAME "cx231xx"
42#define PWR_SLEEP_INTERVAL 5
43
44/* I2C addresses for control block in Cx231xx */
45#define Colibri_DEVICE_ADDRESS 0x60
46#define Flatrion_DEVICE_ADDRESS 0x98
47#define HAMMERHEAD_I2C_ADDRESS 0x88
48#define DIF_USE_BASEBAND 0xFFFFFFFF
49
50/* Boards supported by driver */
51#define CX231XX_BOARD_UNKNOWN 0
52#define CX231XX_BOARD_CNXT_RDE_250 1
53#define CX231XX_BOARD_CNXT_RDU_250 2
54
55/* Limits minimum and default number of buffers */
56#define CX231XX_MIN_BUF 4
57#define CX231XX_DEF_BUF 12
58#define CX231XX_DEF_VBI_BUF 6
59
60#define VBI_LINE_COUNT 17
61#define VBI_LINE_LENGTH 1440
62
63/*Limits the max URB message size */
64#define URB_MAX_CTRL_SIZE 80
65
66/* Params for validated field */
67#define CX231XX_BOARD_NOT_VALIDATED 1
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -030068#define CX231XX_BOARD_VALIDATED 0
Sri Deevie0d3baf2009-03-03 14:37:50 -030069
70/* maximum number of cx231xx boards */
71#define CX231XX_MAXBOARDS 8
72
73/* maximum number of frames that can be queued */
74#define CX231XX_NUM_FRAMES 5
75
76/* number of buffers for isoc transfers */
77#define CX231XX_NUM_BUFS 8
78
79/* number of packets for each buffer
80 windows requests only 40 packets .. so we better do the same
81 this is what I found out for all alternate numbers there!
82 */
83#define CX231XX_NUM_PACKETS 40
84
Sri Deevie0d3baf2009-03-03 14:37:50 -030085/* default alternate; 0 means choose the best */
86#define CX231XX_PINOUT 0
87
88#define CX231XX_INTERLACED_DEFAULT 1
89
Sri Deevie0d3baf2009-03-03 14:37:50 -030090/* time to wait when stopping the isoc transfer */
91#define CX231XX_URB_TIMEOUT msecs_to_jiffies(CX231XX_NUM_BUFS * CX231XX_NUM_PACKETS)
92
Sri Deevie0d3baf2009-03-03 14:37:50 -030093enum cx231xx_mode {
94 CX231XX_SUSPEND,
95 CX231XX_ANALOG_MODE,
96 CX231XX_DIGITAL_MODE,
97};
98
99enum cx231xx_std_mode {
100 CX231XX_TV_AIR = 0,
101 CX231XX_TV_CABLE
102};
103
104enum cx231xx_stream_state {
105 STREAM_OFF,
106 STREAM_INTERRUPT,
107 STREAM_ON,
108};
109
110struct cx231xx;
111
112struct cx231xx_usb_isoc_ctl {
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300113 /* max packet size of isoc transaction */
114 int max_pkt_size;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300115
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300116 /* number of allocated urbs */
117 int num_bufs;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300118
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300119 /* urb for isoc transfers */
120 struct urb **urb;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300121
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300122 /* transfer buffers for isoc transfer */
123 char **transfer_buffer;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300124
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300125 /* Last buffer command and region */
126 u8 cmd;
127 int pos, size, pktsize;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300128
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300129 /* Last field: ODD or EVEN? */
130 int field;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300131
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300132 /* Stores incomplete commands */
133 u32 tmp_buf;
134 int tmp_buf_len;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300135
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300136 /* Stores already requested buffers */
137 struct cx231xx_buffer *buf;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300138
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300139 /* Stores the number of received fields */
140 int nfields;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300141
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300142 /* isoc urb callback */
143 int (*isoc_copy) (struct cx231xx * dev, struct urb * urb);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300144
145};
146
Sri Deevie0d3baf2009-03-03 14:37:50 -0300147struct cx231xx_fmt {
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300148 char *name;
149 u32 fourcc; /* v4l2 format id */
150 int depth;
151 int reg;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300152};
153
154/* buffer for one video frame */
155struct cx231xx_buffer {
156 /* common v4l buffer stuff -- must be first */
157 struct videobuf_buffer vb;
158
159 struct list_head frame;
160 int top_field;
161 int receiving;
162};
163
164struct cx231xx_dmaqueue {
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300165 struct list_head active;
166 struct list_head queued;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300167
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300168 wait_queue_head_t wq;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300169
170 /* Counters to control buffer fill */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300171 int pos;
172 u8 is_partial_line;
173 u8 partial_buf[8];
174 u8 last_sav;
175 int current_field;
176 u32 bytes_left_in_line;
177 u32 lines_completed;
178 u8 field1_done;
179 u32 lines_per_field;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300180};
181
Sri Deevie0d3baf2009-03-03 14:37:50 -0300182/* inputs */
183
184#define MAX_CX231XX_INPUT 4
185
186enum cx231xx_itype {
187 CX231XX_VMUX_COMPOSITE1 = 1,
188 CX231XX_VMUX_SVIDEO,
189 CX231XX_VMUX_TELEVISION,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300190 CX231XX_VMUX_CABLE,
191 CX231XX_RADIO,
192 CX231XX_VMUX_DVB,
Sri Deevie0d3baf2009-03-03 14:37:50 -0300193 CX231XX_VMUX_DEBUG
194};
195
196enum cx231xx_v_input {
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300197 CX231XX_VIN_1_1 = 0x1,
198 CX231XX_VIN_2_1,
199 CX231XX_VIN_3_1,
200 CX231XX_VIN_4_1,
201 CX231XX_VIN_1_2 = 0x01,
202 CX231XX_VIN_2_2,
203 CX231XX_VIN_3_2,
204 CX231XX_VIN_1_3 = 0x1,
205 CX231XX_VIN_2_3,
206 CX231XX_VIN_3_3,
Sri Deevie0d3baf2009-03-03 14:37:50 -0300207};
208
209/* cx231xx has two audio inputs: tuner and line in */
210enum cx231xx_amux {
211 /* This is the only entry for cx231xx tuner input */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300212 CX231XX_AMUX_VIDEO, /* cx231xx tuner */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300213 CX231XX_AMUX_LINE_IN, /* Line In */
214};
215
216struct cx231xx_reg_seq {
217 unsigned char bit;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300218 unsigned char val;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300219 int sleep;
220};
221
222struct cx231xx_input {
223 enum cx231xx_itype type;
224 unsigned int vmux;
225 enum cx231xx_amux amux;
226 struct cx231xx_reg_seq *gpio;
227};
228
229#define INPUT(nr) (&cx231xx_boards[dev->model].input[nr])
230
231enum cx231xx_decoder {
232 CX231XX_NODECODER,
233 CX231XX_AVDECODER
234};
235
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300236typedef enum _I2C_MASTER_PORT {
237 I2C_0 = 0,
238 I2C_1 = 1,
239 I2C_2 = 2,
240 I2C_3 = 3
241} CX231XX_I2C_MASTER_PORT;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300242
243struct cx231xx_board {
244 char *name;
245 int vchannels;
246 int tuner_type;
247 int tuner_addr;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300248 v4l2_std_id norm; /* tv norm */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300249
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300250 /* demod related */
251 int demod_addr;
252 u8 demod_xfer_mode; /* 0 - Serial; 1 - parallel */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300253
254 /* GPIO Pins */
255 struct cx231xx_reg_seq *dvb_gpio;
256 struct cx231xx_reg_seq *suspend_gpio;
257 struct cx231xx_reg_seq *tuner_gpio;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300258 u8 tuner_sif_gpio;
259 u8 tuner_scl_gpio;
260 u8 tuner_sda_gpio;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300261
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300262 /* PIN ctrl */
263 u32 ctl_pin_status_mask;
264 u8 agc_analog_digital_select_gpio;
265 u32 gpio_pin_status_mask;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300266
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300267 /* i2c masters */
268 u8 tuner_i2c_master;
269 u8 demod_i2c_master;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300270
271 unsigned int max_range_640_480:1;
272 unsigned int has_dvb:1;
273 unsigned int valid:1;
274
275 unsigned char xclk, i2c_speed;
276
277 enum cx231xx_decoder decoder;
278
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300279 struct cx231xx_input input[MAX_CX231XX_INPUT];
280 struct cx231xx_input radio;
281 IR_KEYTAB_TYPE *ir_codes;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300282};
283
284/* device states */
285enum cx231xx_dev_state {
286 DEV_INITIALIZED = 0x01,
287 DEV_DISCONNECTED = 0x02,
288 DEV_MISCONFIGURED = 0x04,
289};
290
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300291enum AFE_MODE {
292 AFE_MODE_LOW_IF,
293 AFE_MODE_BASEBAND,
294 AFE_MODE_EU_HI_IF,
295 AFE_MODE_US_HI_IF,
296 AFE_MODE_JAPAN_HI_IF
Sri Deevie0d3baf2009-03-03 14:37:50 -0300297};
298
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300299enum AUDIO_INPUT {
300 AUDIO_INPUT_MUTE,
301 AUDIO_INPUT_LINE,
302 AUDIO_INPUT_TUNER_TV,
303 AUDIO_INPUT_SPDIF,
304 AUDIO_INPUT_TUNER_FM
Sri Deevie0d3baf2009-03-03 14:37:50 -0300305};
306
307#define CX231XX_AUDIO_BUFS 5
308#define CX231XX_NUM_AUDIO_PACKETS 64
309#define CX231XX_CAPTURE_STREAM_EN 1
310#define CX231XX_STOP_AUDIO 0
311#define CX231XX_START_AUDIO 1
312
Sri Deevie0d3baf2009-03-03 14:37:50 -0300313/* cx231xx extensions */
314#define CX231XX_AUDIO 0x10
315#define CX231XX_DVB 0x20
316
317struct cx231xx_audio {
318 char name[50];
319 char *transfer_buffer[CX231XX_AUDIO_BUFS];
320 struct urb *urb[CX231XX_AUDIO_BUFS];
321 struct usb_device *udev;
322 unsigned int capture_transfer_done;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300323 struct snd_pcm_substream *capture_pcm_substream;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300324
325 unsigned int hwptr_done_capture;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300326 struct snd_card *sndcard;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300327
328 int users, shutdown;
329 enum cx231xx_stream_state capture_stream;
330 spinlock_t slock;
331
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300332 int alt; /* alternate */
333 int max_pkt_size; /* max packet size of isoc transaction */
334 int num_alt; /* Number of alternative settings */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300335 unsigned int *alt_max_pkt_size; /* array of wMaxPacketSize */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300336 u16 end_point_addr;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300337};
338
339struct cx231xx;
340
341struct cx231xx_fh {
342 struct cx231xx *dev;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300343 unsigned int stream_on:1; /* Locks streams */
344 int radio;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300345
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300346 struct videobuf_queue vb_vidq;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300347
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300348 enum v4l2_buf_type type;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300349};
350
351/**********************************************************************************/
352/* set/get i2c */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300353#define I2C_SPEED_1M 0x0 /* 00--1Mb/s, 01-400kb/s, 10--100kb/s, 11--5Mb/s */
354#define I2C_SPEED_400K 0x1 /* 00--1Mb/s, 01-400kb/s, 10--100kb/s, 11--5Mb/s */
355#define I2C_SPEED_100K 0x2 /* 00--1Mb/s, 01-400kb/s, 10--100kb/s, 11--5Mb/s */
356#define I2C_SPEED_5M 0x3 /* 00--1Mb/s, 01-400kb/s, 10--100kb/s, 11--5Mb/s */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300357
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300358#define I2C_STOP 0x0 /* 0-- STOP transaction */
359#define I2C_NOSTOP 0x1 /* 1-- do not transmit STOP at end of transaction */
360#define I2C_SYNC 0x1 /* 1--alllow slave to insert clock wait states */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300361
362struct cx231xx_i2c {
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300363 struct cx231xx *dev;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300364
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300365 int nr;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300366
367 /* i2c i/o */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300368 struct i2c_adapter i2c_adap;
369 struct i2c_algo_bit_data i2c_algo;
370 struct i2c_client i2c_client;
371 u32 i2c_rc;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300372
373 /* different settings for each bus */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300374 u8 i2c_period;
375 u8 i2c_nostop;
376 u8 i2c_reserve;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300377};
378
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300379struct cx231xx_i2c_xfer_data {
380 u8 dev_addr;
381 u8 direction; /* 1 - IN, 0 - OUT */
382 u8 saddr_len; /* sub address len */
383 u16 saddr_dat; /* sub addr data */
384 u8 buf_size; /* buffer size */
385 u8 *p_buffer; /* pointer to the buffer */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300386};
387
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300388typedef struct _VENDOR_REQUEST_IN {
389 u8 bRequest;
390 u16 wValue;
391 u16 wIndex;
392 u16 wLength;
393 u8 direction;
394 u8 bData;
395 u8 *pBuff;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300396} VENDOR_REQUEST_IN, *PVENDOR_REQUEST_IN;
397
398struct cx231xx_ctrl {
399 struct v4l2_queryctrl v;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300400 u32 off;
401 u32 reg;
402 u32 mask;
403 u32 shift;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300404};
405
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300406typedef enum {
407 Raw_Video = 0,
408 Audio,
409 Vbi, /* VANC */
410 Sliced_cc, /* HANC */
411 TS1_serial_mode,
412 TS2,
413 TS1_parallel_mode
414} TRANSFER_TYPE;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300415
416struct cx231xx_video_mode {
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300417 /* Isoc control struct */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300418 struct cx231xx_dmaqueue vidq;
419 struct cx231xx_usb_isoc_ctl isoc_ctl;
420 spinlock_t slock;
421
422 /* usb transfer */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300423 int alt; /* alternate */
424 int max_pkt_size; /* max packet size of isoc transaction */
425 int num_alt; /* Number of alternative settings */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300426 unsigned int *alt_max_pkt_size; /* array of wMaxPacketSize */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300427 u16 end_point_addr;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300428};
429
Sri Deevie0d3baf2009-03-03 14:37:50 -0300430/* main device struct */
431struct cx231xx {
432 /* generic device properties */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300433 char name[30]; /* name (including minor) of the device */
434 int model; /* index in the device_data struct */
435 int devno; /* marks the number of this device */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300436
437 struct cx231xx_board board;
438
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300439 unsigned int stream_on:1; /* Locks streams */
440 unsigned int vbi_stream_on:1; /* Locks streams for VBI */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300441 unsigned int has_audio_class:1;
442 unsigned int has_alsa_audio:1;
443
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300444 struct cx231xx_fmt *format;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300445
446 struct cx231xx_IR *ir;
447
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300448 struct list_head devlist;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300449
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300450 int tuner_type; /* type of the tuner */
451 int tuner_addr; /* tuner address */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300452
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300453 /* I2C adapters: Master 1 & 2 (External) & Master 3 (Internal only) */
454 struct cx231xx_i2c i2c_bus[3];
455 unsigned int xc_fw_load_done:1;
456 struct mutex gpio_i2c_lock;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300457
458 /* video for linux */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300459 int users; /* user count for exclusive use */
460 struct video_device *vdev; /* video for linux device struct */
461 v4l2_std_id norm; /* selected tv norm */
462 int ctl_freq; /* selected frequency */
463 unsigned int ctl_ainput; /* selected audio input */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300464 int mute;
465 int volume;
466
467 /* frame properties */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300468 int width; /* current frame width */
469 int height; /* current frame height */
470 unsigned hscale; /* horizontal scale factor (see datasheet) */
471 unsigned vscale; /* vertical scale factor (see datasheet) */
472 int interlaced; /* 1=interlace fileds, 0=just top fileds */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300473
474 struct cx231xx_audio adev;
475
476 /* states */
477 enum cx231xx_dev_state state;
478
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300479 struct work_struct request_module_wk;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300480
481 /* locks */
482 struct mutex lock;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300483 struct mutex ctrl_urb_lock; /* protects urb_buf */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300484 struct list_head inqueue, outqueue;
485 wait_queue_head_t open, wait_frame, wait_stream;
486 struct video_device *vbi_dev;
487 struct video_device *radio_dev;
488
489 unsigned char eedata[256];
490
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300491 struct cx231xx_video_mode video_mode;
492 struct cx231xx_video_mode vbi_mode;
493 struct cx231xx_video_mode sliced_cc_mode;
494 struct cx231xx_video_mode ts1_mode;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300495
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300496 struct usb_device *udev; /* the usb device */
497 char urb_buf[URB_MAX_CTRL_SIZE]; /* urb control msg buffer */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300498
499 /* helper funcs that call usb_control_msg */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300500 int (*cx231xx_read_ctrl_reg) (struct cx231xx * dev, u8 req, u16 reg,
Sri Deevie0d3baf2009-03-03 14:37:50 -0300501 char *buf, int len);
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300502 int (*cx231xx_write_ctrl_reg) (struct cx231xx * dev, u8 req, u16 reg,
503 char *buf, int len);
504 int (*cx231xx_send_usb_command) (struct cx231xx_i2c * i2c_bus,
505 struct cx231xx_i2c_xfer_data *
506 req_data);
507 int (*cx231xx_gpio_i2c_read) (struct cx231xx * dev, u8 dev_addr,
508 u8 * buf, u8 len);
509 int (*cx231xx_gpio_i2c_write) (struct cx231xx * dev, u8 dev_addr,
510 u8 * buf, u8 len);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300511
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300512 int (*cx231xx_set_analog_freq) (struct cx231xx * dev, u32 freq);
513 int (*cx231xx_reset_analog_tuner) (struct cx231xx * dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300514
515 enum cx231xx_mode mode;
516
517 struct cx231xx_dvb *dvb;
518
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300519 /* Cx231xx supported PCB config's */
520 struct pcb_config current_pcb_config;
521 u8 current_scenario_idx;
522 u8 interface_count;
523 u8 max_iad_interface_count;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300524
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300525 /* GPIO related register direction and values */
526 u32 gpio_dir;
527 u32 gpio_val;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300528
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300529 /* Power Modes */
530 int power_mode;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300531
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300532 /* colibri parameters */
533 enum AFE_MODE colibri_mode;
534 u32 colibri_ref_count;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300535
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300536 /* video related parameters */
537 u32 video_input;
538 u32 active_mode;
539 u8 vbi_or_sliced_cc_mode; /* 0 - vbi ; 1 - sliced cc mode */
540 enum cx231xx_std_mode std_mode; /* 0 - Air; 1 - cable */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300541
542};
543
544struct cx231xx_ops {
545 struct list_head next;
546 char *name;
547 int id;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300548 int (*init) (struct cx231xx *);
549 int (*fini) (struct cx231xx *);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300550};
551
552/* call back functions in dvb module */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300553int cx231xx_set_analog_freq(struct cx231xx *dev, u32 freq);
554int cx231xx_reset_analog_tuner(struct cx231xx *dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300555
556/* Provided by cx231xx-i2c.c */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300557void cx231xx_i2c_call_clients(struct cx231xx_i2c *bus, unsigned int cmd,
558 void *arg);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300559void cx231xx_do_i2c_scan(struct cx231xx *dev, struct i2c_client *c);
560int cx231xx_i2c_register(struct cx231xx_i2c *bus);
561int cx231xx_i2c_unregister(struct cx231xx_i2c *bus);
562
563/* Internal block control functions */
564int cx231xx_read_i2c_data(struct cx231xx *dev, u8 dev_addr,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300565 u16 saddr, u8 saddr_len, u32 * data, u8 data_len);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300566int cx231xx_write_i2c_data(struct cx231xx *dev, u8 dev_addr,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300567 u16 saddr, u8 saddr_len, u32 data, u8 data_len);
568int cx231xx_reg_mask_write(struct cx231xx *dev, u8 dev_addr, u8 size,
569 u16 register_address, u8 bit_start, u8 bit_end,
570 u32 value);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300571int cx231xx_read_modify_write_i2c_dword(struct cx231xx *dev, u8 dev_addr,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300572 u16 saddr, u32 mask, u32 value);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300573u32 cx231xx_set_field(u32 field_mask, u32 data);
574
575/* Colibri related functions */
576int cx231xx_colibri_init_super_block(struct cx231xx *dev, u32 ref_count);
577int cx231xx_colibri_init_channels(struct cx231xx *dev);
578int cx231xx_colibri_setup_AFE_for_baseband(struct cx231xx *dev);
579int cx231xx_colibri_set_input_mux(struct cx231xx *dev, u32 input_mux);
580int cx231xx_colibri_set_mode(struct cx231xx *dev, enum AFE_MODE mode);
581int cx231xx_colibri_update_power_control(struct cx231xx *dev, AV_MODE avmode);
582int cx231xx_colibri_adjust_ref_count(struct cx231xx *dev, u32 video_input);
583
584/* flatiron related functions */
585int cx231xx_flatiron_initialize(struct cx231xx *dev);
586int cx231xx_flatiron_update_power_control(struct cx231xx *dev, AV_MODE avmode);
587int cx231xx_flatiron_set_audio_input(struct cx231xx *dev, u8 audio_input);
588
589/* DIF related functions */
590int cx231xx_dif_configure_C2HH_for_low_IF(struct cx231xx *dev, u32 mode,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300591 u32 function_mode, u32 standard);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300592int cx231xx_dif_set_standard(struct cx231xx *dev, u32 standard);
593int cx231xx_tuner_pre_channel_change(struct cx231xx *dev);
594int cx231xx_tuner_post_channel_change(struct cx231xx *dev);
595
596/* video parser functions */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300597u8 cx231xx_find_next_SAV_EAV(u8 * p_buffer, u32 buffer_size,
598 u32 * p_bytes_used);
599u8 cx231xx_find_boundary_SAV_EAV(u8 * p_buffer, u8 * partial_buf,
600 u32 * p_bytes_used);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300601int cx231xx_do_copy(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300602 u8 * p_buffer, u32 bytes_to_copy);
603void cx231xx_reset_video_buffer(struct cx231xx *dev,
604 struct cx231xx_dmaqueue *dma_q);
605u8 cx231xx_is_buffer_done(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q);
606u32 cx231xx_copy_video_line(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q,
607 u8 * p_line, u32 length, int field_number);
608u32 cx231xx_get_video_line(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q,
609 u8 sav_eav, u8 * p_buffer, u32 buffer_size);
610void cx231xx_swab(u16 * from, u16 * to, u16 len);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300611
612/* Provided by cx231xx-core.c */
613
614u32 cx231xx_request_buffers(struct cx231xx *dev, u32 count);
615void cx231xx_queue_unusedframes(struct cx231xx *dev);
616void cx231xx_release_buffers(struct cx231xx *dev);
617
618/* read from control pipe */
619int cx231xx_read_ctrl_reg(struct cx231xx *dev, u8 req, u16 reg,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300620 char *buf, int len);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300621
622/* write to control pipe */
623int cx231xx_write_ctrl_reg(struct cx231xx *dev, u8 req, u16 reg,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300624 char *buf, int len);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300625int cx231xx_mode_register(struct cx231xx *dev, u16 address, u32 mode);
626
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300627int cx231xx_send_vendor_cmd(struct cx231xx *dev, VENDOR_REQUEST_IN * ven_req);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300628int cx231xx_send_usb_command(struct cx231xx_i2c *i2c_bus,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300629 struct cx231xx_i2c_xfer_data *req_data);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300630
631/* Gpio related functions */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300632int cx231xx_send_gpio_cmd(struct cx231xx *dev, u32 gpio_bit, u8 * gpio_val,
633 u8 len, u8 request, u8 direction);
634int cx231xx_set_gpio_bit(struct cx231xx *dev, u32 gpio_bit, u8 * gpio_val);
635int cx231xx_get_gpio_bit(struct cx231xx *dev, u32 gpio_bit, u8 * gpio_val);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300636int cx231xx_set_gpio_value(struct cx231xx *dev, int pin_number, int pin_value);
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300637int cx231xx_set_gpio_direction(struct cx231xx *dev, int pin_number,
638 int pin_value);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300639
640int cx231xx_gpio_i2c_start(struct cx231xx *dev);
641int cx231xx_gpio_i2c_end(struct cx231xx *dev);
642int cx231xx_gpio_i2c_write_byte(struct cx231xx *dev, u8 data);
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300643int cx231xx_gpio_i2c_read_byte(struct cx231xx *dev, u8 * buf);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300644int cx231xx_gpio_i2c_read_ack(struct cx231xx *dev);
645int cx231xx_gpio_i2c_write_ack(struct cx231xx *dev);
646int cx231xx_gpio_i2c_write_nak(struct cx231xx *dev);
647
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300648int cx231xx_gpio_i2c_read(struct cx231xx *dev, u8 dev_addr, u8 * buf, u8 len);
649int cx231xx_gpio_i2c_write(struct cx231xx *dev, u8 dev_addr, u8 * buf, u8 len);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300650
651/* audio related functions */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300652int cx231xx_set_audio_decoder_input(struct cx231xx *dev,
653 enum AUDIO_INPUT audio_input);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300654
655int cx231xx_capture_start(struct cx231xx *dev, int start, u8 media_type);
656int cx231xx_resolution_set(struct cx231xx *dev);
657int cx231xx_set_video_alternate(struct cx231xx *dev);
658int cx231xx_set_alt_setting(struct cx231xx *dev, u8 index, u8 alt);
659int cx231xx_init_isoc(struct cx231xx *dev, int max_packets,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300660 int num_bufs, int max_pkt_size,
661 int (*isoc_copy) (struct cx231xx * dev,
662 struct urb * urb));
Sri Deevie0d3baf2009-03-03 14:37:50 -0300663void cx231xx_uninit_isoc(struct cx231xx *dev);
664int cx231xx_set_mode(struct cx231xx *dev, enum cx231xx_mode set_mode);
665int cx231xx_gpio_set(struct cx231xx *dev, struct cx231xx_reg_seq *gpio);
666
667/* Device list functions */
668void cx231xx_release_resources(struct cx231xx *dev);
669void cx231xx_release_analog_resources(struct cx231xx *dev);
670int cx231xx_register_analog_devices(struct cx231xx *dev);
671void cx231xx_remove_from_devlist(struct cx231xx *dev);
672void cx231xx_add_into_devlist(struct cx231xx *dev);
673struct cx231xx *cx231xx_get_device(int minor,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300674 enum v4l2_buf_type *fh_type, int *has_radio);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300675void cx231xx_init_extension(struct cx231xx *dev);
676void cx231xx_close_extension(struct cx231xx *dev);
677
678/* hardware init functions */
679int cx231xx_dev_init(struct cx231xx *dev);
680void cx231xx_dev_uninit(struct cx231xx *dev);
681void cx231xx_config_i2c(struct cx231xx *dev);
682int cx231xx_config(struct cx231xx *dev);
683
684/* Stream control functions */
685int cx231xx_start_stream(struct cx231xx *dev, u32 ep_mask);
686int cx231xx_stop_stream(struct cx231xx *dev, u32 ep_mask);
687
688int cx231xx_initialize_stream_xfer(struct cx231xx *dev, u32 media_type);
689
690/* Power control functions */
691int cx231xx_set_power_mode(struct cx231xx *dev, AV_MODE mode);
692int cx231xx_power_suspend(struct cx231xx *dev);
693
694/* chip specific control functions */
695int cx231xx_init_ctrl_pin_status(struct cx231xx *dev);
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300696int cx231xx_set_agc_analog_digital_mux_select(struct cx231xx *dev,
697 u8 analog_or_digital);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300698int cx231xx_enable_i2c_for_tuner(struct cx231xx *dev, u8 I2CIndex);
699
700/* video audio decoder related functions */
701void video_mux(struct cx231xx *dev, int index);
702int cx231xx_set_video_input_mux(struct cx231xx *dev, u8 input);
703int cx231xx_set_decoder_video_input(struct cx231xx *dev, u8 pin_type, u8 input);
704int cx231xx_do_mode_ctrl_overrides(struct cx231xx *dev);
705int cx231xx_set_audio_input(struct cx231xx *dev, u8 input);
706void get_scale(struct cx231xx *dev,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300707 unsigned int width, unsigned int height,
708 unsigned int *hscale, unsigned int *vscale);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300709
710/* Provided by cx231xx-video.c */
711int cx231xx_register_extension(struct cx231xx_ops *dev);
712void cx231xx_unregister_extension(struct cx231xx_ops *dev);
713void cx231xx_init_extension(struct cx231xx *dev);
714void cx231xx_close_extension(struct cx231xx *dev);
715
716/* Provided by cx231xx-cards.c */
717extern void cx231xx_pre_card_setup(struct cx231xx *dev);
718extern void cx231xx_card_setup(struct cx231xx *dev);
719extern struct cx231xx_board cx231xx_boards[];
720extern struct usb_device_id cx231xx_id_table[];
721extern const unsigned int cx231xx_bcount;
722void cx231xx_set_ir(struct cx231xx *dev, struct IR_i2c *ir);
723int cx231xx_tuner_callback(void *ptr, int component, int command, int arg);
724
725/* Provided by cx231xx-input.c */
726int cx231xx_ir_init(struct cx231xx *dev);
727int cx231xx_ir_fini(struct cx231xx *dev);
728
729/* printk macros */
730
731#define cx231xx_err(fmt, arg...) do {\
732 printk(KERN_ERR fmt , ##arg); } while (0)
733
734#define cx231xx_errdev(fmt, arg...) do {\
735 printk(KERN_ERR "%s: "fmt,\
736 dev->name , ##arg); } while (0)
737
738#define cx231xx_info(fmt, arg...) do {\
739 printk(KERN_INFO "%s: "fmt,\
740 dev->name , ##arg); } while (0)
741#define cx231xx_warn(fmt, arg...) do {\
742 printk(KERN_WARNING "%s: "fmt,\
743 dev->name , ##arg); } while (0)
744
Sri Deevie0d3baf2009-03-03 14:37:50 -0300745static inline unsigned int norm_maxw(struct cx231xx *dev)
746{
747 if (dev->board.max_range_640_480)
748 return 640;
749 else
750 return 720;
751}
752
753static inline unsigned int norm_maxh(struct cx231xx *dev)
754{
755 if (dev->board.max_range_640_480)
756 return 480;
757 else
758 return (dev->norm & V4L2_STD_625_50) ? 576 : 480;
759}
760#endif