blob: 17d4d1a800ce010732ffa641cee0101afe7a0f36 [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>
Sri Deevib1196122009-03-20 23:33:48 -030026#include <linux/types.h>
27#include <linux/ioctl.h>
Sri Deevie0d3baf2009-03-03 14:37:50 -030028#include <linux/i2c.h>
29#include <linux/i2c-algo-bit.h>
30#include <linux/mutex.h>
Sri Deevib1196122009-03-20 23:33:48 -030031
32
33#include <media/videobuf-vmalloc.h>
34#include <media/v4l2-device.h>
Sri Deevie0d3baf2009-03-03 14:37:50 -030035#include <media/ir-kbd-i2c.h>
Sri Deevib9255172009-03-04 17:49:01 -030036#if defined(CONFIG_VIDEO_CX231XX_DVB) || \
37 defined(CONFIG_VIDEO_CX231XX_DVB_MODULE)
Sri Deevie0d3baf2009-03-03 14:37:50 -030038#include <media/videobuf-dvb.h>
39#endif
40
41#include "cx231xx-reg.h"
Sri Deevi6e4f5742009-03-10 21:16:26 -030042#include "cx231xx-pcb-cfg.h"
Sri Deevie0d3baf2009-03-03 14:37:50 -030043#include "cx231xx-conf-reg.h"
44
Sri Deevie0d3baf2009-03-03 14:37:50 -030045#define DRIVER_NAME "cx231xx"
46#define PWR_SLEEP_INTERVAL 5
47
48/* I2C addresses for control block in Cx231xx */
Sri Deeviecc67d12009-03-21 22:00:20 -030049#define AFE_DEVICE_ADDRESS 0x60
50#define I2S_BLK_DEVICE_ADDRESS 0x98
51#define VID_BLK_I2C_ADDRESS 0x88
Sri Deevie0d3baf2009-03-03 14:37:50 -030052#define DIF_USE_BASEBAND 0xFFFFFFFF
53
54/* Boards supported by driver */
55#define CX231XX_BOARD_UNKNOWN 0
56#define CX231XX_BOARD_CNXT_RDE_250 1
57#define CX231XX_BOARD_CNXT_RDU_250 2
58
59/* Limits minimum and default number of buffers */
60#define CX231XX_MIN_BUF 4
61#define CX231XX_DEF_BUF 12
62#define CX231XX_DEF_VBI_BUF 6
63
64#define VBI_LINE_COUNT 17
65#define VBI_LINE_LENGTH 1440
66
67/*Limits the max URB message size */
68#define URB_MAX_CTRL_SIZE 80
69
70/* Params for validated field */
71#define CX231XX_BOARD_NOT_VALIDATED 1
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -030072#define CX231XX_BOARD_VALIDATED 0
Sri Deevie0d3baf2009-03-03 14:37:50 -030073
74/* maximum number of cx231xx boards */
75#define CX231XX_MAXBOARDS 8
76
77/* maximum number of frames that can be queued */
78#define CX231XX_NUM_FRAMES 5
79
80/* number of buffers for isoc transfers */
81#define CX231XX_NUM_BUFS 8
82
83/* number of packets for each buffer
84 windows requests only 40 packets .. so we better do the same
85 this is what I found out for all alternate numbers there!
86 */
87#define CX231XX_NUM_PACKETS 40
88
Sri Deevie0d3baf2009-03-03 14:37:50 -030089/* default alternate; 0 means choose the best */
90#define CX231XX_PINOUT 0
91
92#define CX231XX_INTERLACED_DEFAULT 1
93
Sri Deevie0d3baf2009-03-03 14:37:50 -030094/* time to wait when stopping the isoc transfer */
Sri Deevib9255172009-03-04 17:49:01 -030095#define CX231XX_URB_TIMEOUT \
96 msecs_to_jiffies(CX231XX_NUM_BUFS * CX231XX_NUM_PACKETS)
Sri Deevie0d3baf2009-03-03 14:37:50 -030097
Sri Deevie0d3baf2009-03-03 14:37:50 -030098enum cx231xx_mode {
99 CX231XX_SUSPEND,
100 CX231XX_ANALOG_MODE,
101 CX231XX_DIGITAL_MODE,
102};
103
104enum cx231xx_std_mode {
105 CX231XX_TV_AIR = 0,
106 CX231XX_TV_CABLE
107};
108
109enum cx231xx_stream_state {
110 STREAM_OFF,
111 STREAM_INTERRUPT,
112 STREAM_ON,
113};
114
115struct cx231xx;
116
117struct cx231xx_usb_isoc_ctl {
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300118 /* max packet size of isoc transaction */
119 int max_pkt_size;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300120
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300121 /* number of allocated urbs */
122 int num_bufs;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300123
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300124 /* urb for isoc transfers */
125 struct urb **urb;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300126
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300127 /* transfer buffers for isoc transfer */
128 char **transfer_buffer;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300129
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300130 /* Last buffer command and region */
131 u8 cmd;
132 int pos, size, pktsize;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300133
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300134 /* Last field: ODD or EVEN? */
135 int field;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300136
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300137 /* Stores incomplete commands */
138 u32 tmp_buf;
139 int tmp_buf_len;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300140
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300141 /* Stores already requested buffers */
142 struct cx231xx_buffer *buf;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300143
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300144 /* Stores the number of received fields */
145 int nfields;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300146
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300147 /* isoc urb callback */
Mauro Carvalho Chehabcde43622009-03-03 13:31:36 -0300148 int (*isoc_copy) (struct cx231xx *dev, struct urb *urb);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300149};
150
Sri Deevie0d3baf2009-03-03 14:37:50 -0300151struct cx231xx_fmt {
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300152 char *name;
153 u32 fourcc; /* v4l2 format id */
154 int depth;
155 int reg;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300156};
157
158/* buffer for one video frame */
159struct cx231xx_buffer {
160 /* common v4l buffer stuff -- must be first */
161 struct videobuf_buffer vb;
162
163 struct list_head frame;
164 int top_field;
165 int receiving;
166};
167
168struct cx231xx_dmaqueue {
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300169 struct list_head active;
170 struct list_head queued;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300171
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300172 wait_queue_head_t wq;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300173
174 /* Counters to control buffer fill */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300175 int pos;
176 u8 is_partial_line;
177 u8 partial_buf[8];
178 u8 last_sav;
179 int current_field;
180 u32 bytes_left_in_line;
181 u32 lines_completed;
182 u8 field1_done;
183 u32 lines_per_field;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300184};
185
Sri Deevie0d3baf2009-03-03 14:37:50 -0300186/* inputs */
187
188#define MAX_CX231XX_INPUT 4
189
190enum cx231xx_itype {
191 CX231XX_VMUX_COMPOSITE1 = 1,
192 CX231XX_VMUX_SVIDEO,
193 CX231XX_VMUX_TELEVISION,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300194 CX231XX_VMUX_CABLE,
195 CX231XX_RADIO,
196 CX231XX_VMUX_DVB,
Sri Deevie0d3baf2009-03-03 14:37:50 -0300197 CX231XX_VMUX_DEBUG
198};
199
200enum cx231xx_v_input {
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300201 CX231XX_VIN_1_1 = 0x1,
202 CX231XX_VIN_2_1,
203 CX231XX_VIN_3_1,
204 CX231XX_VIN_4_1,
205 CX231XX_VIN_1_2 = 0x01,
206 CX231XX_VIN_2_2,
207 CX231XX_VIN_3_2,
208 CX231XX_VIN_1_3 = 0x1,
209 CX231XX_VIN_2_3,
210 CX231XX_VIN_3_3,
Sri Deevie0d3baf2009-03-03 14:37:50 -0300211};
212
213/* cx231xx has two audio inputs: tuner and line in */
214enum cx231xx_amux {
215 /* This is the only entry for cx231xx tuner input */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300216 CX231XX_AMUX_VIDEO, /* cx231xx tuner */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300217 CX231XX_AMUX_LINE_IN, /* Line In */
218};
219
220struct cx231xx_reg_seq {
221 unsigned char bit;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300222 unsigned char val;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300223 int sleep;
224};
225
226struct cx231xx_input {
227 enum cx231xx_itype type;
228 unsigned int vmux;
229 enum cx231xx_amux amux;
230 struct cx231xx_reg_seq *gpio;
231};
232
233#define INPUT(nr) (&cx231xx_boards[dev->model].input[nr])
234
235enum cx231xx_decoder {
236 CX231XX_NODECODER,
237 CX231XX_AVDECODER
238};
239
Sri Deevib9255172009-03-04 17:49:01 -0300240enum CX231XX_I2C_MASTER_PORT {
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300241 I2C_0 = 0,
242 I2C_1 = 1,
243 I2C_2 = 2,
244 I2C_3 = 3
Sri Deevib9255172009-03-04 17:49:01 -0300245};
Sri Deevie0d3baf2009-03-03 14:37:50 -0300246
247struct cx231xx_board {
248 char *name;
249 int vchannels;
250 int tuner_type;
251 int tuner_addr;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300252 v4l2_std_id norm; /* tv norm */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300253
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300254 /* demod related */
255 int demod_addr;
256 u8 demod_xfer_mode; /* 0 - Serial; 1 - parallel */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300257
258 /* GPIO Pins */
259 struct cx231xx_reg_seq *dvb_gpio;
260 struct cx231xx_reg_seq *suspend_gpio;
261 struct cx231xx_reg_seq *tuner_gpio;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300262 u8 tuner_sif_gpio;
263 u8 tuner_scl_gpio;
264 u8 tuner_sda_gpio;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300265
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300266 /* PIN ctrl */
267 u32 ctl_pin_status_mask;
268 u8 agc_analog_digital_select_gpio;
269 u32 gpio_pin_status_mask;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300270
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300271 /* i2c masters */
272 u8 tuner_i2c_master;
273 u8 demod_i2c_master;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300274
275 unsigned int max_range_640_480:1;
276 unsigned int has_dvb:1;
277 unsigned int valid:1;
278
279 unsigned char xclk, i2c_speed;
280
281 enum cx231xx_decoder decoder;
282
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300283 struct cx231xx_input input[MAX_CX231XX_INPUT];
284 struct cx231xx_input radio;
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300285 struct ir_scancode_table *ir_codes;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300286};
287
288/* device states */
289enum cx231xx_dev_state {
290 DEV_INITIALIZED = 0x01,
291 DEV_DISCONNECTED = 0x02,
292 DEV_MISCONFIGURED = 0x04,
293};
294
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300295enum AFE_MODE {
296 AFE_MODE_LOW_IF,
297 AFE_MODE_BASEBAND,
298 AFE_MODE_EU_HI_IF,
299 AFE_MODE_US_HI_IF,
300 AFE_MODE_JAPAN_HI_IF
Sri Deevie0d3baf2009-03-03 14:37:50 -0300301};
302
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300303enum AUDIO_INPUT {
304 AUDIO_INPUT_MUTE,
305 AUDIO_INPUT_LINE,
306 AUDIO_INPUT_TUNER_TV,
307 AUDIO_INPUT_SPDIF,
308 AUDIO_INPUT_TUNER_FM
Sri Deevie0d3baf2009-03-03 14:37:50 -0300309};
310
311#define CX231XX_AUDIO_BUFS 5
312#define CX231XX_NUM_AUDIO_PACKETS 64
313#define CX231XX_CAPTURE_STREAM_EN 1
314#define CX231XX_STOP_AUDIO 0
315#define CX231XX_START_AUDIO 1
316
Sri Deevie0d3baf2009-03-03 14:37:50 -0300317/* cx231xx extensions */
318#define CX231XX_AUDIO 0x10
319#define CX231XX_DVB 0x20
320
321struct cx231xx_audio {
322 char name[50];
323 char *transfer_buffer[CX231XX_AUDIO_BUFS];
324 struct urb *urb[CX231XX_AUDIO_BUFS];
325 struct usb_device *udev;
326 unsigned int capture_transfer_done;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300327 struct snd_pcm_substream *capture_pcm_substream;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300328
329 unsigned int hwptr_done_capture;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300330 struct snd_card *sndcard;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300331
332 int users, shutdown;
333 enum cx231xx_stream_state capture_stream;
334 spinlock_t slock;
335
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300336 int alt; /* alternate */
337 int max_pkt_size; /* max packet size of isoc transaction */
338 int num_alt; /* Number of alternative settings */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300339 unsigned int *alt_max_pkt_size; /* array of wMaxPacketSize */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300340 u16 end_point_addr;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300341};
342
343struct cx231xx;
344
345struct cx231xx_fh {
346 struct cx231xx *dev;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300347 unsigned int stream_on:1; /* Locks streams */
348 int radio;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300349
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300350 struct videobuf_queue vb_vidq;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300351
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300352 enum v4l2_buf_type type;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300353};
354
Sri Deevib9255172009-03-04 17:49:01 -0300355/*****************************************************************/
Sri Deevie0d3baf2009-03-03 14:37:50 -0300356/* set/get i2c */
Sri Deevib9255172009-03-04 17:49:01 -0300357/* 00--1Mb/s, 01-400kb/s, 10--100kb/s, 11--5Mb/s */
358#define I2C_SPEED_1M 0x0
359#define I2C_SPEED_400K 0x1
360#define I2C_SPEED_100K 0x2
361#define I2C_SPEED_5M 0x3
Sri Deevie0d3baf2009-03-03 14:37:50 -0300362
Sri Deevib9255172009-03-04 17:49:01 -0300363/* 0-- STOP transaction */
364#define I2C_STOP 0x0
365/* 1-- do not transmit STOP at end of transaction */
366#define I2C_NOSTOP 0x1
367/* 1--alllow slave to insert clock wait states */
368#define I2C_SYNC 0x1
Sri Deevie0d3baf2009-03-03 14:37:50 -0300369
370struct cx231xx_i2c {
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300371 struct cx231xx *dev;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300372
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300373 int nr;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300374
375 /* i2c i/o */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300376 struct i2c_adapter i2c_adap;
377 struct i2c_algo_bit_data i2c_algo;
378 struct i2c_client i2c_client;
379 u32 i2c_rc;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300380
381 /* different settings for each bus */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300382 u8 i2c_period;
383 u8 i2c_nostop;
384 u8 i2c_reserve;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300385};
386
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300387struct cx231xx_i2c_xfer_data {
388 u8 dev_addr;
389 u8 direction; /* 1 - IN, 0 - OUT */
390 u8 saddr_len; /* sub address len */
391 u16 saddr_dat; /* sub addr data */
392 u8 buf_size; /* buffer size */
393 u8 *p_buffer; /* pointer to the buffer */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300394};
395
Sri Deevi6e4f5742009-03-10 21:16:26 -0300396struct VENDOR_REQUEST_IN {
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300397 u8 bRequest;
398 u16 wValue;
399 u16 wIndex;
400 u16 wLength;
401 u8 direction;
402 u8 bData;
403 u8 *pBuff;
Sri Deevib9255172009-03-04 17:49:01 -0300404};
Sri Deevie0d3baf2009-03-03 14:37:50 -0300405
406struct cx231xx_ctrl {
407 struct v4l2_queryctrl v;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300408 u32 off;
409 u32 reg;
410 u32 mask;
411 u32 shift;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300412};
413
Sri Deevi6e4f5742009-03-10 21:16:26 -0300414enum TRANSFER_TYPE {
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300415 Raw_Video = 0,
416 Audio,
417 Vbi, /* VANC */
418 Sliced_cc, /* HANC */
419 TS1_serial_mode,
420 TS2,
421 TS1_parallel_mode
Sri Deevib9255172009-03-04 17:49:01 -0300422} ;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300423
424struct cx231xx_video_mode {
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300425 /* Isoc control struct */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300426 struct cx231xx_dmaqueue vidq;
427 struct cx231xx_usb_isoc_ctl isoc_ctl;
428 spinlock_t slock;
429
430 /* usb transfer */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300431 int alt; /* alternate */
432 int max_pkt_size; /* max packet size of isoc transaction */
433 int num_alt; /* Number of alternative settings */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300434 unsigned int *alt_max_pkt_size; /* array of wMaxPacketSize */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300435 u16 end_point_addr;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300436};
437
Sri Deevie0d3baf2009-03-03 14:37:50 -0300438/* main device struct */
439struct cx231xx {
440 /* generic device properties */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300441 char name[30]; /* name (including minor) of the device */
442 int model; /* index in the device_data struct */
443 int devno; /* marks the number of this device */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300444
445 struct cx231xx_board board;
446
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300447 unsigned int stream_on:1; /* Locks streams */
448 unsigned int vbi_stream_on:1; /* Locks streams for VBI */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300449 unsigned int has_audio_class:1;
450 unsigned int has_alsa_audio:1;
451
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300452 struct cx231xx_fmt *format;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300453
Sri Deevib1196122009-03-20 23:33:48 -0300454 struct v4l2_device v4l2_dev;
455 struct v4l2_subdev *sd_cx25840;
456 struct v4l2_subdev *sd_tuner;
457
Sri Deevie0d3baf2009-03-03 14:37:50 -0300458 struct cx231xx_IR *ir;
459
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300460 struct list_head devlist;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300461
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300462 int tuner_type; /* type of the tuner */
463 int tuner_addr; /* tuner address */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300464
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300465 /* I2C adapters: Master 1 & 2 (External) & Master 3 (Internal only) */
466 struct cx231xx_i2c i2c_bus[3];
467 unsigned int xc_fw_load_done:1;
468 struct mutex gpio_i2c_lock;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300469
470 /* video for linux */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300471 int users; /* user count for exclusive use */
472 struct video_device *vdev; /* video for linux device struct */
473 v4l2_std_id norm; /* selected tv norm */
474 int ctl_freq; /* selected frequency */
475 unsigned int ctl_ainput; /* selected audio input */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300476 int mute;
477 int volume;
478
479 /* frame properties */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300480 int width; /* current frame width */
481 int height; /* current frame height */
482 unsigned hscale; /* horizontal scale factor (see datasheet) */
483 unsigned vscale; /* vertical scale factor (see datasheet) */
484 int interlaced; /* 1=interlace fileds, 0=just top fileds */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300485
486 struct cx231xx_audio adev;
487
488 /* states */
489 enum cx231xx_dev_state state;
490
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300491 struct work_struct request_module_wk;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300492
493 /* locks */
494 struct mutex lock;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300495 struct mutex ctrl_urb_lock; /* protects urb_buf */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300496 struct list_head inqueue, outqueue;
497 wait_queue_head_t open, wait_frame, wait_stream;
498 struct video_device *vbi_dev;
499 struct video_device *radio_dev;
500
501 unsigned char eedata[256];
502
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300503 struct cx231xx_video_mode video_mode;
504 struct cx231xx_video_mode vbi_mode;
505 struct cx231xx_video_mode sliced_cc_mode;
506 struct cx231xx_video_mode ts1_mode;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300507
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300508 struct usb_device *udev; /* the usb device */
509 char urb_buf[URB_MAX_CTRL_SIZE]; /* urb control msg buffer */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300510
511 /* helper funcs that call usb_control_msg */
Mauro Carvalho Chehabcde43622009-03-03 13:31:36 -0300512 int (*cx231xx_read_ctrl_reg) (struct cx231xx *dev, u8 req, u16 reg,
Sri Deevie0d3baf2009-03-03 14:37:50 -0300513 char *buf, int len);
Mauro Carvalho Chehabcde43622009-03-03 13:31:36 -0300514 int (*cx231xx_write_ctrl_reg) (struct cx231xx *dev, u8 req, u16 reg,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300515 char *buf, int len);
Mauro Carvalho Chehabcde43622009-03-03 13:31:36 -0300516 int (*cx231xx_send_usb_command) (struct cx231xx_i2c *i2c_bus,
Sri Deevib9255172009-03-04 17:49:01 -0300517 struct cx231xx_i2c_xfer_data *req_data);
Mauro Carvalho Chehabcde43622009-03-03 13:31:36 -0300518 int (*cx231xx_gpio_i2c_read) (struct cx231xx *dev, u8 dev_addr,
519 u8 *buf, u8 len);
520 int (*cx231xx_gpio_i2c_write) (struct cx231xx *dev, u8 dev_addr,
521 u8 *buf, u8 len);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300522
Mauro Carvalho Chehabcde43622009-03-03 13:31:36 -0300523 int (*cx231xx_set_analog_freq) (struct cx231xx *dev, u32 freq);
524 int (*cx231xx_reset_analog_tuner) (struct cx231xx *dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300525
526 enum cx231xx_mode mode;
527
528 struct cx231xx_dvb *dvb;
529
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300530 /* Cx231xx supported PCB config's */
531 struct pcb_config current_pcb_config;
532 u8 current_scenario_idx;
533 u8 interface_count;
534 u8 max_iad_interface_count;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300535
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300536 /* GPIO related register direction and values */
537 u32 gpio_dir;
538 u32 gpio_val;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300539
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300540 /* Power Modes */
541 int power_mode;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300542
Sri Deeviecc67d12009-03-21 22:00:20 -0300543 /* afe parameters */
544 enum AFE_MODE afe_mode;
545 u32 afe_ref_count;
Sri Deevie0d3baf2009-03-03 14:37:50 -0300546
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300547 /* video related parameters */
548 u32 video_input;
549 u32 active_mode;
550 u8 vbi_or_sliced_cc_mode; /* 0 - vbi ; 1 - sliced cc mode */
551 enum cx231xx_std_mode std_mode; /* 0 - Air; 1 - cable */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300552
553};
554
Sri Deevib1196122009-03-20 23:33:48 -0300555#define cx25840_call(cx231xx, o, f, args...) \
556 v4l2_subdev_call(cx231xx->sd_cx25840, o, f, ##args)
557#define tuner_call(cx231xx, o, f, args...) \
558 v4l2_subdev_call(cx231xx->sd_tuner, o, f, ##args)
559#define call_all(dev, o, f, args...) \
560 v4l2_device_call_until_err(&dev->v4l2_dev, 0, o, f, ##args)
561
Sri Deevie0d3baf2009-03-03 14:37:50 -0300562struct cx231xx_ops {
563 struct list_head next;
564 char *name;
565 int id;
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300566 int (*init) (struct cx231xx *);
567 int (*fini) (struct cx231xx *);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300568};
569
570/* call back functions in dvb module */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300571int cx231xx_set_analog_freq(struct cx231xx *dev, u32 freq);
572int cx231xx_reset_analog_tuner(struct cx231xx *dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300573
574/* Provided by cx231xx-i2c.c */
Sri Deevie0d3baf2009-03-03 14:37:50 -0300575void cx231xx_do_i2c_scan(struct cx231xx *dev, struct i2c_client *c);
576int cx231xx_i2c_register(struct cx231xx_i2c *bus);
577int cx231xx_i2c_unregister(struct cx231xx_i2c *bus);
578
579/* Internal block control functions */
580int cx231xx_read_i2c_data(struct cx231xx *dev, u8 dev_addr,
Mauro Carvalho Chehabcde43622009-03-03 13:31:36 -0300581 u16 saddr, u8 saddr_len, u32 *data, u8 data_len);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300582int cx231xx_write_i2c_data(struct cx231xx *dev, u8 dev_addr,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300583 u16 saddr, u8 saddr_len, u32 data, u8 data_len);
584int cx231xx_reg_mask_write(struct cx231xx *dev, u8 dev_addr, u8 size,
585 u16 register_address, u8 bit_start, u8 bit_end,
586 u32 value);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300587int cx231xx_read_modify_write_i2c_dword(struct cx231xx *dev, u8 dev_addr,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300588 u16 saddr, u32 mask, u32 value);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300589u32 cx231xx_set_field(u32 field_mask, u32 data);
590
Sri Deeviecc67d12009-03-21 22:00:20 -0300591/* afe related functions */
592int cx231xx_afe_init_super_block(struct cx231xx *dev, u32 ref_count);
593int cx231xx_afe_init_channels(struct cx231xx *dev);
594int cx231xx_afe_setup_AFE_for_baseband(struct cx231xx *dev);
595int cx231xx_afe_set_input_mux(struct cx231xx *dev, u32 input_mux);
596int cx231xx_afe_set_mode(struct cx231xx *dev, enum AFE_MODE mode);
597int cx231xx_afe_update_power_control(struct cx231xx *dev,
Sri Deevi6e4f5742009-03-10 21:16:26 -0300598 enum AV_MODE avmode);
Sri Deeviecc67d12009-03-21 22:00:20 -0300599int cx231xx_afe_adjust_ref_count(struct cx231xx *dev, u32 video_input);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300600
Sri Deeviecc67d12009-03-21 22:00:20 -0300601/* i2s block related functions */
602int cx231xx_i2s_blk_initialize(struct cx231xx *dev);
603int cx231xx_i2s_blk_update_power_control(struct cx231xx *dev,
Sri Deevi6e4f5742009-03-10 21:16:26 -0300604 enum AV_MODE avmode);
Sri Deeviecc67d12009-03-21 22:00:20 -0300605int cx231xx_i2s_blk_set_audio_input(struct cx231xx *dev, u8 audio_input);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300606
607/* DIF related functions */
608int cx231xx_dif_configure_C2HH_for_low_IF(struct cx231xx *dev, u32 mode,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300609 u32 function_mode, u32 standard);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300610int cx231xx_dif_set_standard(struct cx231xx *dev, u32 standard);
611int cx231xx_tuner_pre_channel_change(struct cx231xx *dev);
612int cx231xx_tuner_post_channel_change(struct cx231xx *dev);
613
614/* video parser functions */
Mauro Carvalho Chehabcde43622009-03-03 13:31:36 -0300615u8 cx231xx_find_next_SAV_EAV(u8 *p_buffer, u32 buffer_size,
616 u32 *p_bytes_used);
617u8 cx231xx_find_boundary_SAV_EAV(u8 *p_buffer, u8 *partial_buf,
618 u32 *p_bytes_used);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300619int cx231xx_do_copy(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q,
Mauro Carvalho Chehabcde43622009-03-03 13:31:36 -0300620 u8 *p_buffer, u32 bytes_to_copy);
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300621void cx231xx_reset_video_buffer(struct cx231xx *dev,
622 struct cx231xx_dmaqueue *dma_q);
623u8 cx231xx_is_buffer_done(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q);
624u32 cx231xx_copy_video_line(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q,
Mauro Carvalho Chehabcde43622009-03-03 13:31:36 -0300625 u8 *p_line, u32 length, int field_number);
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300626u32 cx231xx_get_video_line(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q,
Mauro Carvalho Chehabcde43622009-03-03 13:31:36 -0300627 u8 sav_eav, u8 *p_buffer, u32 buffer_size);
628void cx231xx_swab(u16 *from, u16 *to, u16 len);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300629
630/* Provided by cx231xx-core.c */
631
632u32 cx231xx_request_buffers(struct cx231xx *dev, u32 count);
633void cx231xx_queue_unusedframes(struct cx231xx *dev);
634void cx231xx_release_buffers(struct cx231xx *dev);
635
636/* read from control pipe */
637int cx231xx_read_ctrl_reg(struct cx231xx *dev, u8 req, u16 reg,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300638 char *buf, int len);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300639
640/* write to control pipe */
641int cx231xx_write_ctrl_reg(struct cx231xx *dev, u8 req, u16 reg,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300642 char *buf, int len);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300643int cx231xx_mode_register(struct cx231xx *dev, u16 address, u32 mode);
644
Sri Deevib9255172009-03-04 17:49:01 -0300645int cx231xx_send_vendor_cmd(struct cx231xx *dev,
646 struct VENDOR_REQUEST_IN *ven_req);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300647int cx231xx_send_usb_command(struct cx231xx_i2c *i2c_bus,
Sri Deevib9255172009-03-04 17:49:01 -0300648 struct cx231xx_i2c_xfer_data *req_data);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300649
650/* Gpio related functions */
Mauro Carvalho Chehabcde43622009-03-03 13:31:36 -0300651int cx231xx_send_gpio_cmd(struct cx231xx *dev, u32 gpio_bit, u8 *gpio_val,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300652 u8 len, u8 request, u8 direction);
Mauro Carvalho Chehabcde43622009-03-03 13:31:36 -0300653int cx231xx_set_gpio_bit(struct cx231xx *dev, u32 gpio_bit, u8 *gpio_val);
654int cx231xx_get_gpio_bit(struct cx231xx *dev, u32 gpio_bit, u8 *gpio_val);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300655int cx231xx_set_gpio_value(struct cx231xx *dev, int pin_number, int pin_value);
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300656int cx231xx_set_gpio_direction(struct cx231xx *dev, int pin_number,
657 int pin_value);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300658
659int cx231xx_gpio_i2c_start(struct cx231xx *dev);
660int cx231xx_gpio_i2c_end(struct cx231xx *dev);
661int cx231xx_gpio_i2c_write_byte(struct cx231xx *dev, u8 data);
Mauro Carvalho Chehabcde43622009-03-03 13:31:36 -0300662int cx231xx_gpio_i2c_read_byte(struct cx231xx *dev, u8 *buf);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300663int cx231xx_gpio_i2c_read_ack(struct cx231xx *dev);
664int cx231xx_gpio_i2c_write_ack(struct cx231xx *dev);
665int cx231xx_gpio_i2c_write_nak(struct cx231xx *dev);
666
Mauro Carvalho Chehabcde43622009-03-03 13:31:36 -0300667int cx231xx_gpio_i2c_read(struct cx231xx *dev, u8 dev_addr, u8 *buf, u8 len);
668int cx231xx_gpio_i2c_write(struct cx231xx *dev, u8 dev_addr, u8 *buf, u8 len);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300669
670/* audio related functions */
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300671int cx231xx_set_audio_decoder_input(struct cx231xx *dev,
672 enum AUDIO_INPUT audio_input);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300673
674int cx231xx_capture_start(struct cx231xx *dev, int start, u8 media_type);
675int cx231xx_resolution_set(struct cx231xx *dev);
676int cx231xx_set_video_alternate(struct cx231xx *dev);
677int cx231xx_set_alt_setting(struct cx231xx *dev, u8 index, u8 alt);
678int cx231xx_init_isoc(struct cx231xx *dev, int max_packets,
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300679 int num_bufs, int max_pkt_size,
Mauro Carvalho Chehabcde43622009-03-03 13:31:36 -0300680 int (*isoc_copy) (struct cx231xx *dev,
681 struct urb *urb));
Sri Deevie0d3baf2009-03-03 14:37:50 -0300682void cx231xx_uninit_isoc(struct cx231xx *dev);
683int cx231xx_set_mode(struct cx231xx *dev, enum cx231xx_mode set_mode);
684int cx231xx_gpio_set(struct cx231xx *dev, struct cx231xx_reg_seq *gpio);
685
686/* Device list functions */
687void cx231xx_release_resources(struct cx231xx *dev);
688void cx231xx_release_analog_resources(struct cx231xx *dev);
689int cx231xx_register_analog_devices(struct cx231xx *dev);
690void cx231xx_remove_from_devlist(struct cx231xx *dev);
691void cx231xx_add_into_devlist(struct cx231xx *dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300692void cx231xx_init_extension(struct cx231xx *dev);
693void cx231xx_close_extension(struct cx231xx *dev);
694
695/* hardware init functions */
696int cx231xx_dev_init(struct cx231xx *dev);
697void cx231xx_dev_uninit(struct cx231xx *dev);
698void cx231xx_config_i2c(struct cx231xx *dev);
699int cx231xx_config(struct cx231xx *dev);
700
701/* Stream control functions */
702int cx231xx_start_stream(struct cx231xx *dev, u32 ep_mask);
703int cx231xx_stop_stream(struct cx231xx *dev, u32 ep_mask);
704
705int cx231xx_initialize_stream_xfer(struct cx231xx *dev, u32 media_type);
706
707/* Power control functions */
Sri Deevi6e4f5742009-03-10 21:16:26 -0300708int cx231xx_set_power_mode(struct cx231xx *dev, enum AV_MODE mode);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300709int cx231xx_power_suspend(struct cx231xx *dev);
710
711/* chip specific control functions */
712int cx231xx_init_ctrl_pin_status(struct cx231xx *dev);
Mauro Carvalho Chehab84b5dbf2009-03-03 06:14:34 -0300713int cx231xx_set_agc_analog_digital_mux_select(struct cx231xx *dev,
714 u8 analog_or_digital);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300715int cx231xx_enable_i2c_for_tuner(struct cx231xx *dev, u8 I2CIndex);
716
717/* video audio decoder related functions */
718void video_mux(struct cx231xx *dev, int index);
719int cx231xx_set_video_input_mux(struct cx231xx *dev, u8 input);
720int cx231xx_set_decoder_video_input(struct cx231xx *dev, u8 pin_type, u8 input);
721int cx231xx_do_mode_ctrl_overrides(struct cx231xx *dev);
722int cx231xx_set_audio_input(struct cx231xx *dev, u8 input);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300723
724/* Provided by cx231xx-video.c */
725int cx231xx_register_extension(struct cx231xx_ops *dev);
726void cx231xx_unregister_extension(struct cx231xx_ops *dev);
727void cx231xx_init_extension(struct cx231xx *dev);
728void cx231xx_close_extension(struct cx231xx *dev);
729
730/* Provided by cx231xx-cards.c */
731extern void cx231xx_pre_card_setup(struct cx231xx *dev);
732extern void cx231xx_card_setup(struct cx231xx *dev);
733extern struct cx231xx_board cx231xx_boards[];
734extern struct usb_device_id cx231xx_id_table[];
735extern const unsigned int cx231xx_bcount;
Jean Delvarec668f322009-05-13 16:48:50 -0300736void cx231xx_register_i2c_ir(struct cx231xx *dev);
Sri Deevie0d3baf2009-03-03 14:37:50 -0300737int cx231xx_tuner_callback(void *ptr, int component, int command, int arg);
738
739/* Provided by cx231xx-input.c */
740int cx231xx_ir_init(struct cx231xx *dev);
741int cx231xx_ir_fini(struct cx231xx *dev);
742
743/* printk macros */
744
745#define cx231xx_err(fmt, arg...) do {\
746 printk(KERN_ERR fmt , ##arg); } while (0)
747
748#define cx231xx_errdev(fmt, arg...) do {\
749 printk(KERN_ERR "%s: "fmt,\
750 dev->name , ##arg); } while (0)
751
752#define cx231xx_info(fmt, arg...) do {\
753 printk(KERN_INFO "%s: "fmt,\
754 dev->name , ##arg); } while (0)
755#define cx231xx_warn(fmt, arg...) do {\
756 printk(KERN_WARNING "%s: "fmt,\
757 dev->name , ##arg); } while (0)
758
Sri Deevie0d3baf2009-03-03 14:37:50 -0300759static inline unsigned int norm_maxw(struct cx231xx *dev)
760{
761 if (dev->board.max_range_640_480)
762 return 640;
763 else
764 return 720;
765}
766
767static inline unsigned int norm_maxh(struct cx231xx *dev)
768{
769 if (dev->board.max_range_640_480)
770 return 480;
771 else
772 return (dev->norm & V4L2_STD_625_50) ? 576 : 480;
773}
774#endif