Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame^] | 1 | /* |
| 2 | cx231xx.h - driver for Conexant Cx23100/101/102 USB video capture devices |
| 3 | |
| 4 | Copyright (C) 2008 <srinivasa.deevi at conexant dot com> |
| 5 | Based on em28xx driver |
| 6 | |
| 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 |
| 68 | #define CX231XX_BOARD_VALIDATED 0 |
| 69 | |
| 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 | |
| 85 | |
| 86 | /* default alternate; 0 means choose the best */ |
| 87 | #define CX231XX_PINOUT 0 |
| 88 | |
| 89 | #define CX231XX_INTERLACED_DEFAULT 1 |
| 90 | |
| 91 | |
| 92 | /* time to wait when stopping the isoc transfer */ |
| 93 | #define CX231XX_URB_TIMEOUT msecs_to_jiffies(CX231XX_NUM_BUFS * CX231XX_NUM_PACKETS) |
| 94 | |
| 95 | |
| 96 | enum cx231xx_mode { |
| 97 | CX231XX_SUSPEND, |
| 98 | CX231XX_ANALOG_MODE, |
| 99 | CX231XX_DIGITAL_MODE, |
| 100 | }; |
| 101 | |
| 102 | enum cx231xx_std_mode { |
| 103 | CX231XX_TV_AIR = 0, |
| 104 | CX231XX_TV_CABLE |
| 105 | }; |
| 106 | |
| 107 | enum cx231xx_stream_state { |
| 108 | STREAM_OFF, |
| 109 | STREAM_INTERRUPT, |
| 110 | STREAM_ON, |
| 111 | }; |
| 112 | |
| 113 | struct cx231xx; |
| 114 | |
| 115 | struct cx231xx_usb_isoc_ctl { |
| 116 | /* max packet size of isoc transaction */ |
| 117 | int max_pkt_size; |
| 118 | |
| 119 | /* number of allocated urbs */ |
| 120 | int num_bufs; |
| 121 | |
| 122 | /* urb for isoc transfers */ |
| 123 | struct urb **urb; |
| 124 | |
| 125 | /* transfer buffers for isoc transfer */ |
| 126 | char **transfer_buffer; |
| 127 | |
| 128 | /* Last buffer command and region */ |
| 129 | u8 cmd; |
| 130 | int pos, size, pktsize; |
| 131 | |
| 132 | /* Last field: ODD or EVEN? */ |
| 133 | int field; |
| 134 | |
| 135 | /* Stores incomplete commands */ |
| 136 | u32 tmp_buf; |
| 137 | int tmp_buf_len; |
| 138 | |
| 139 | /* Stores already requested buffers */ |
| 140 | struct cx231xx_buffer *buf; |
| 141 | |
| 142 | /* Stores the number of received fields */ |
| 143 | int nfields; |
| 144 | |
| 145 | /* isoc urb callback */ |
| 146 | int (*isoc_copy) (struct cx231xx *dev, struct urb *urb); |
| 147 | |
| 148 | }; |
| 149 | |
| 150 | |
| 151 | |
| 152 | struct cx231xx_fmt { |
| 153 | char *name; |
| 154 | u32 fourcc; /* v4l2 format id */ |
| 155 | int depth; |
| 156 | int reg; |
| 157 | }; |
| 158 | |
| 159 | /* buffer for one video frame */ |
| 160 | struct cx231xx_buffer { |
| 161 | /* common v4l buffer stuff -- must be first */ |
| 162 | struct videobuf_buffer vb; |
| 163 | |
| 164 | struct list_head frame; |
| 165 | int top_field; |
| 166 | int receiving; |
| 167 | }; |
| 168 | |
| 169 | struct cx231xx_dmaqueue { |
| 170 | struct list_head active; |
| 171 | struct list_head queued; |
| 172 | |
| 173 | wait_queue_head_t wq; |
| 174 | |
| 175 | /* Counters to control buffer fill */ |
| 176 | int pos; |
| 177 | u8 is_partial_line; |
| 178 | u8 partial_buf[8]; |
| 179 | u8 last_sav; |
| 180 | int current_field; |
| 181 | u32 bytes_left_in_line; |
| 182 | u32 lines_completed; |
| 183 | u8 field1_done; |
| 184 | u32 lines_per_field; |
| 185 | }; |
| 186 | |
| 187 | |
| 188 | /* inputs */ |
| 189 | |
| 190 | #define MAX_CX231XX_INPUT 4 |
| 191 | |
| 192 | enum cx231xx_itype { |
| 193 | CX231XX_VMUX_COMPOSITE1 = 1, |
| 194 | CX231XX_VMUX_SVIDEO, |
| 195 | CX231XX_VMUX_TELEVISION, |
| 196 | CX231XX_VMUX_CABLE, |
| 197 | CX231XX_RADIO, |
| 198 | CX231XX_VMUX_DVB, |
| 199 | CX231XX_VMUX_DEBUG |
| 200 | }; |
| 201 | |
| 202 | enum cx231xx_v_input { |
| 203 | CX231XX_VIN_1_1 = 0x1, |
| 204 | CX231XX_VIN_2_1, |
| 205 | CX231XX_VIN_3_1, |
| 206 | CX231XX_VIN_4_1, |
| 207 | CX231XX_VIN_1_2 = 0x01, |
| 208 | CX231XX_VIN_2_2, |
| 209 | CX231XX_VIN_3_2, |
| 210 | CX231XX_VIN_1_3 = 0x1, |
| 211 | CX231XX_VIN_2_3, |
| 212 | CX231XX_VIN_3_3, |
| 213 | }; |
| 214 | |
| 215 | /* cx231xx has two audio inputs: tuner and line in */ |
| 216 | enum cx231xx_amux { |
| 217 | /* This is the only entry for cx231xx tuner input */ |
| 218 | CX231XX_AMUX_VIDEO, /* cx231xx tuner*/ |
| 219 | CX231XX_AMUX_LINE_IN, /* Line In */ |
| 220 | }; |
| 221 | |
| 222 | struct cx231xx_reg_seq { |
| 223 | unsigned char bit; |
| 224 | unsigned char val; |
| 225 | int sleep; |
| 226 | }; |
| 227 | |
| 228 | struct cx231xx_input { |
| 229 | enum cx231xx_itype type; |
| 230 | unsigned int vmux; |
| 231 | enum cx231xx_amux amux; |
| 232 | struct cx231xx_reg_seq *gpio; |
| 233 | }; |
| 234 | |
| 235 | #define INPUT(nr) (&cx231xx_boards[dev->model].input[nr]) |
| 236 | |
| 237 | enum cx231xx_decoder { |
| 238 | CX231XX_NODECODER, |
| 239 | CX231XX_AVDECODER |
| 240 | }; |
| 241 | |
| 242 | typedef enum _I2C_MASTER_PORT |
| 243 | { |
| 244 | I2C_0 =0, |
| 245 | I2C_1 =1, |
| 246 | I2C_2 =2, |
| 247 | I2C_3 =3 |
| 248 | }CX231XX_I2C_MASTER_PORT; |
| 249 | |
| 250 | struct cx231xx_board { |
| 251 | char *name; |
| 252 | int vchannels; |
| 253 | int tuner_type; |
| 254 | int tuner_addr; |
| 255 | v4l2_std_id norm; /* tv norm */ |
| 256 | |
| 257 | /* demod related */ |
| 258 | int demod_addr; |
| 259 | u8 demod_xfer_mode; /* 0 - Serial; 1 - parallel */ |
| 260 | |
| 261 | /* GPIO Pins */ |
| 262 | struct cx231xx_reg_seq *dvb_gpio; |
| 263 | struct cx231xx_reg_seq *suspend_gpio; |
| 264 | struct cx231xx_reg_seq *tuner_gpio; |
| 265 | u8 tuner_sif_gpio; |
| 266 | u8 tuner_scl_gpio; |
| 267 | u8 tuner_sda_gpio; |
| 268 | |
| 269 | /* PIN ctrl */ |
| 270 | u32 ctl_pin_status_mask; |
| 271 | u8 agc_analog_digital_select_gpio; |
| 272 | u32 gpio_pin_status_mask; |
| 273 | |
| 274 | /* i2c masters */ |
| 275 | u8 tuner_i2c_master; |
| 276 | u8 demod_i2c_master; |
| 277 | |
| 278 | unsigned int max_range_640_480:1; |
| 279 | unsigned int has_dvb:1; |
| 280 | unsigned int valid:1; |
| 281 | |
| 282 | unsigned char xclk, i2c_speed; |
| 283 | |
| 284 | enum cx231xx_decoder decoder; |
| 285 | |
| 286 | struct cx231xx_input input[MAX_CX231XX_INPUT]; |
| 287 | struct cx231xx_input radio; |
| 288 | IR_KEYTAB_TYPE *ir_codes; |
| 289 | }; |
| 290 | |
| 291 | /* device states */ |
| 292 | enum cx231xx_dev_state { |
| 293 | DEV_INITIALIZED = 0x01, |
| 294 | DEV_DISCONNECTED = 0x02, |
| 295 | DEV_MISCONFIGURED = 0x04, |
| 296 | }; |
| 297 | |
| 298 | enum AFE_MODE |
| 299 | { |
| 300 | AFE_MODE_LOW_IF, |
| 301 | AFE_MODE_BASEBAND, |
| 302 | AFE_MODE_EU_HI_IF, |
| 303 | AFE_MODE_US_HI_IF, |
| 304 | AFE_MODE_JAPAN_HI_IF |
| 305 | }; |
| 306 | |
| 307 | enum AUDIO_INPUT |
| 308 | { |
| 309 | AUDIO_INPUT_MUTE, |
| 310 | AUDIO_INPUT_LINE, |
| 311 | AUDIO_INPUT_TUNER_TV, |
| 312 | AUDIO_INPUT_SPDIF, |
| 313 | AUDIO_INPUT_TUNER_FM |
| 314 | }; |
| 315 | |
| 316 | #define CX231XX_AUDIO_BUFS 5 |
| 317 | #define CX231XX_NUM_AUDIO_PACKETS 64 |
| 318 | #define CX231XX_CAPTURE_STREAM_EN 1 |
| 319 | #define CX231XX_STOP_AUDIO 0 |
| 320 | #define CX231XX_START_AUDIO 1 |
| 321 | |
| 322 | |
| 323 | /* cx231xx extensions */ |
| 324 | #define CX231XX_AUDIO 0x10 |
| 325 | #define CX231XX_DVB 0x20 |
| 326 | |
| 327 | struct cx231xx_audio { |
| 328 | char name[50]; |
| 329 | char *transfer_buffer[CX231XX_AUDIO_BUFS]; |
| 330 | struct urb *urb[CX231XX_AUDIO_BUFS]; |
| 331 | struct usb_device *udev; |
| 332 | unsigned int capture_transfer_done; |
| 333 | struct snd_pcm_substream *capture_pcm_substream; |
| 334 | |
| 335 | unsigned int hwptr_done_capture; |
| 336 | struct snd_card *sndcard; |
| 337 | |
| 338 | int users, shutdown; |
| 339 | enum cx231xx_stream_state capture_stream; |
| 340 | spinlock_t slock; |
| 341 | |
| 342 | int alt; /* alternate */ |
| 343 | int max_pkt_size; /* max packet size of isoc transaction */ |
| 344 | int num_alt; /* Number of alternative settings */ |
| 345 | unsigned int *alt_max_pkt_size; /* array of wMaxPacketSize */ |
| 346 | u16 end_point_addr; |
| 347 | }; |
| 348 | |
| 349 | struct cx231xx; |
| 350 | |
| 351 | struct cx231xx_fh { |
| 352 | struct cx231xx *dev; |
| 353 | unsigned int stream_on:1; /* Locks streams */ |
| 354 | int radio; |
| 355 | |
| 356 | struct videobuf_queue vb_vidq; |
| 357 | |
| 358 | enum v4l2_buf_type type; |
| 359 | }; |
| 360 | |
| 361 | /**********************************************************************************/ |
| 362 | /* set/get i2c */ |
| 363 | #define I2C_SPEED_1M 0x0 /* 00--1Mb/s, 01-400kb/s, 10--100kb/s, 11--5Mb/s */ |
| 364 | #define I2C_SPEED_400K 0x1 /* 00--1Mb/s, 01-400kb/s, 10--100kb/s, 11--5Mb/s */ |
| 365 | #define I2C_SPEED_100K 0x2 /* 00--1Mb/s, 01-400kb/s, 10--100kb/s, 11--5Mb/s */ |
| 366 | #define I2C_SPEED_5M 0x3 /* 00--1Mb/s, 01-400kb/s, 10--100kb/s, 11--5Mb/s */ |
| 367 | |
| 368 | #define I2C_STOP 0x0 /* 0-- STOP transaction */ |
| 369 | #define I2C_NOSTOP 0x1 /* 1-- do not transmit STOP at end of transaction */ |
| 370 | #define I2C_SYNC 0x1 /* 1--alllow slave to insert clock wait states */ |
| 371 | |
| 372 | struct cx231xx_i2c { |
| 373 | struct cx231xx *dev; |
| 374 | |
| 375 | int nr; |
| 376 | |
| 377 | /* i2c i/o */ |
| 378 | struct i2c_adapter i2c_adap; |
| 379 | struct i2c_algo_bit_data i2c_algo; |
| 380 | struct i2c_client i2c_client; |
| 381 | u32 i2c_rc; |
| 382 | |
| 383 | /* different settings for each bus */ |
| 384 | u8 i2c_period; |
| 385 | u8 i2c_nostop; |
| 386 | u8 i2c_reserve; |
| 387 | }; |
| 388 | |
| 389 | struct cx231xx_i2c_xfer_data{ |
| 390 | u8 dev_addr; |
| 391 | u8 direction; /* 1 - IN, 0 - OUT */ |
| 392 | u8 saddr_len; /* sub address len */ |
| 393 | u16 saddr_dat; /* sub addr data */ |
| 394 | u8 buf_size; /* buffer size */ |
| 395 | u8* p_buffer; /* pointer to the buffer */ |
| 396 | }; |
| 397 | |
| 398 | typedef struct _VENDOR_REQUEST_IN |
| 399 | { |
| 400 | u8 bRequest; |
| 401 | u16 wValue; |
| 402 | u16 wIndex; |
| 403 | u16 wLength; |
| 404 | u8 direction; |
| 405 | u8 bData; |
| 406 | u8 *pBuff; |
| 407 | } VENDOR_REQUEST_IN, *PVENDOR_REQUEST_IN; |
| 408 | |
| 409 | struct cx231xx_ctrl { |
| 410 | struct v4l2_queryctrl v; |
| 411 | u32 off; |
| 412 | u32 reg; |
| 413 | u32 mask; |
| 414 | u32 shift; |
| 415 | }; |
| 416 | |
| 417 | typedef enum{ |
| 418 | Raw_Video = 0, |
| 419 | Audio, |
| 420 | Vbi, /* VANC */ |
| 421 | Sliced_cc, /* HANC */ |
| 422 | TS1_serial_mode, |
| 423 | TS2, |
| 424 | TS1_parallel_mode |
| 425 | }TRANSFER_TYPE; |
| 426 | |
| 427 | struct cx231xx_video_mode { |
| 428 | /* Isoc control struct */ |
| 429 | struct cx231xx_dmaqueue vidq; |
| 430 | struct cx231xx_usb_isoc_ctl isoc_ctl; |
| 431 | spinlock_t slock; |
| 432 | |
| 433 | /* usb transfer */ |
| 434 | int alt; /* alternate */ |
| 435 | int max_pkt_size; /* max packet size of isoc transaction */ |
| 436 | int num_alt; /* Number of alternative settings */ |
| 437 | unsigned int *alt_max_pkt_size; /* array of wMaxPacketSize */ |
| 438 | u16 end_point_addr; |
| 439 | }; |
| 440 | |
| 441 | |
| 442 | /* main device struct */ |
| 443 | struct cx231xx { |
| 444 | /* generic device properties */ |
| 445 | char name[30]; /* name (including minor) of the device */ |
| 446 | int model; /* index in the device_data struct */ |
| 447 | int devno; /* marks the number of this device */ |
| 448 | |
| 449 | struct cx231xx_board board; |
| 450 | |
| 451 | unsigned int stream_on:1; /* Locks streams */ |
| 452 | unsigned int vbi_stream_on:1; /* Locks streams for VBI */ |
| 453 | unsigned int has_audio_class:1; |
| 454 | unsigned int has_alsa_audio:1; |
| 455 | |
| 456 | struct cx231xx_fmt *format; |
| 457 | |
| 458 | struct cx231xx_IR *ir; |
| 459 | |
| 460 | struct list_head devlist; |
| 461 | |
| 462 | int tuner_type; /* type of the tuner */ |
| 463 | int tuner_addr; /* tuner address */ |
| 464 | |
| 465 | /* 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; |
| 469 | |
| 470 | /* video for linux */ |
| 471 | 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 */ |
| 476 | int mute; |
| 477 | int volume; |
| 478 | |
| 479 | /* frame properties */ |
| 480 | 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 */ |
| 485 | |
| 486 | struct cx231xx_audio adev; |
| 487 | |
| 488 | /* states */ |
| 489 | enum cx231xx_dev_state state; |
| 490 | |
| 491 | struct work_struct request_module_wk; |
| 492 | |
| 493 | /* locks */ |
| 494 | struct mutex lock; |
| 495 | struct mutex ctrl_urb_lock; /* protects urb_buf */ |
| 496 | 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 | |
| 503 | 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; |
| 507 | |
| 508 | struct usb_device *udev; /* the usb device */ |
| 509 | char urb_buf[URB_MAX_CTRL_SIZE];/* urb control msg buffer */ |
| 510 | |
| 511 | |
| 512 | /* helper funcs that call usb_control_msg */ |
| 513 | int (*cx231xx_read_ctrl_reg) (struct cx231xx *dev, u8 req, u16 reg, |
| 514 | char *buf, int len); |
| 515 | int (*cx231xx_write_ctrl_reg)(struct cx231xx *dev, u8 req, u16 reg, |
| 516 | char *buf, int len); |
| 517 | int (*cx231xx_send_usb_command)(struct cx231xx_i2c *i2c_bus, |
| 518 | struct cx231xx_i2c_xfer_data *req_data); |
| 519 | int (*cx231xx_gpio_i2c_read)(struct cx231xx *dev, u8 dev_addr, u8 *buf ,u8 len); |
| 520 | int (*cx231xx_gpio_i2c_write)(struct cx231xx *dev, u8 dev_addr, u8 *buf ,u8 len); |
| 521 | |
| 522 | int (*cx231xx_set_analog_freq)(struct cx231xx *dev, u32 freq ) ; |
| 523 | int (*cx231xx_reset_analog_tuner)(struct cx231xx *dev) ; |
| 524 | |
| 525 | enum cx231xx_mode mode; |
| 526 | |
| 527 | struct cx231xx_dvb *dvb; |
| 528 | |
| 529 | /* Cx231xx supported PCB config's */ |
| 530 | struct pcb_config current_pcb_config; |
| 531 | u8 current_scenario_idx; |
| 532 | u8 interface_count; |
| 533 | u8 max_iad_interface_count; |
| 534 | |
| 535 | /* GPIO related register direction and values */ |
| 536 | u32 gpio_dir; |
| 537 | u32 gpio_val; |
| 538 | |
| 539 | /* Power Modes */ |
| 540 | int power_mode; |
| 541 | |
| 542 | /* colibri parameters */ |
| 543 | enum AFE_MODE colibri_mode; |
| 544 | u32 colibri_ref_count; |
| 545 | |
| 546 | /* video related parameters */ |
| 547 | u32 video_input; |
| 548 | u32 active_mode; |
| 549 | u8 vbi_or_sliced_cc_mode; /* 0 - vbi ; 1 - sliced cc mode */ |
| 550 | enum cx231xx_std_mode std_mode; /* 0 - Air; 1 - cable */ |
| 551 | |
| 552 | }; |
| 553 | |
| 554 | struct cx231xx_ops { |
| 555 | struct list_head next; |
| 556 | char *name; |
| 557 | int id; |
| 558 | int (*init)(struct cx231xx *); |
| 559 | int (*fini)(struct cx231xx *); |
| 560 | }; |
| 561 | |
| 562 | /* call back functions in dvb module */ |
| 563 | int cx231xx_set_analog_freq(struct cx231xx *dev, u32 freq ) ; |
| 564 | int cx231xx_reset_analog_tuner(struct cx231xx *dev) ; |
| 565 | |
| 566 | /* Provided by cx231xx-i2c.c */ |
| 567 | void cx231xx_i2c_call_clients(struct cx231xx_i2c *bus, unsigned int cmd, void *arg); |
| 568 | void cx231xx_do_i2c_scan(struct cx231xx *dev, struct i2c_client *c); |
| 569 | int cx231xx_i2c_register(struct cx231xx_i2c *bus); |
| 570 | int cx231xx_i2c_unregister(struct cx231xx_i2c *bus); |
| 571 | |
| 572 | /* Internal block control functions */ |
| 573 | int cx231xx_read_i2c_data(struct cx231xx *dev, u8 dev_addr, |
| 574 | u16 saddr, u8 saddr_len, u32 *data, u8 data_len); |
| 575 | int cx231xx_write_i2c_data(struct cx231xx *dev, u8 dev_addr, |
| 576 | u16 saddr, u8 saddr_len, u32 data, u8 data_len); |
| 577 | int cx231xx_reg_mask_write(struct cx231xx *dev, u8 dev_addr, u8 size, u16 register_address, |
| 578 | u8 bit_start,u8 bit_end, u32 value); |
| 579 | int cx231xx_read_modify_write_i2c_dword(struct cx231xx *dev, u8 dev_addr, |
| 580 | u16 saddr, u32 mask, u32 value); |
| 581 | u32 cx231xx_set_field(u32 field_mask, u32 data); |
| 582 | |
| 583 | /* Colibri related functions */ |
| 584 | int cx231xx_colibri_init_super_block(struct cx231xx *dev, u32 ref_count); |
| 585 | int cx231xx_colibri_init_channels(struct cx231xx *dev); |
| 586 | int cx231xx_colibri_setup_AFE_for_baseband(struct cx231xx *dev); |
| 587 | int cx231xx_colibri_set_input_mux(struct cx231xx *dev, u32 input_mux); |
| 588 | int cx231xx_colibri_set_mode(struct cx231xx *dev, enum AFE_MODE mode); |
| 589 | int cx231xx_colibri_update_power_control(struct cx231xx *dev, AV_MODE avmode); |
| 590 | int cx231xx_colibri_adjust_ref_count(struct cx231xx *dev, u32 video_input); |
| 591 | |
| 592 | /* flatiron related functions */ |
| 593 | int cx231xx_flatiron_initialize(struct cx231xx *dev); |
| 594 | int cx231xx_flatiron_update_power_control(struct cx231xx *dev, AV_MODE avmode); |
| 595 | int cx231xx_flatiron_set_audio_input(struct cx231xx *dev, u8 audio_input); |
| 596 | |
| 597 | /* DIF related functions */ |
| 598 | int cx231xx_dif_configure_C2HH_for_low_IF(struct cx231xx *dev, u32 mode, |
| 599 | u32 function_mode, u32 standard); |
| 600 | int cx231xx_dif_set_standard(struct cx231xx *dev, u32 standard); |
| 601 | int cx231xx_tuner_pre_channel_change(struct cx231xx *dev); |
| 602 | int cx231xx_tuner_post_channel_change(struct cx231xx *dev); |
| 603 | |
| 604 | /* video parser functions */ |
| 605 | u8 cx231xx_find_next_SAV_EAV(u8 *p_buffer, u32 buffer_size, u32 *p_bytes_used); |
| 606 | u8 cx231xx_find_boundary_SAV_EAV(u8 *p_buffer, u8 *partial_buf, u32 *p_bytes_used); |
| 607 | int cx231xx_do_copy(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q, |
| 608 | u8 *p_buffer, u32 bytes_to_copy); |
| 609 | void cx231xx_reset_video_buffer(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q); |
| 610 | u8 cx231xx_is_buffer_done(struct cx231xx *dev,struct cx231xx_dmaqueue *dma_q); |
| 611 | u32 cx231xx_copy_video_line(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q, |
| 612 | u8 *p_line, u32 length, int field_number); |
| 613 | u32 cx231xx_get_video_line(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q, |
| 614 | u8 sav_eav, u8 *p_buffer, u32 buffer_size); |
| 615 | void cx231xx_swab(u16 *from, u16 *to, u16 len); |
| 616 | |
| 617 | /* Provided by cx231xx-core.c */ |
| 618 | |
| 619 | u32 cx231xx_request_buffers(struct cx231xx *dev, u32 count); |
| 620 | void cx231xx_queue_unusedframes(struct cx231xx *dev); |
| 621 | void cx231xx_release_buffers(struct cx231xx *dev); |
| 622 | |
| 623 | /* read from control pipe */ |
| 624 | int cx231xx_read_ctrl_reg(struct cx231xx *dev, u8 req, u16 reg, |
| 625 | char *buf, int len); |
| 626 | |
| 627 | /* write to control pipe */ |
| 628 | int cx231xx_write_ctrl_reg(struct cx231xx *dev, u8 req, u16 reg, |
| 629 | char *buf, int len); |
| 630 | int cx231xx_mode_register(struct cx231xx *dev, u16 address, u32 mode); |
| 631 | |
| 632 | int cx231xx_send_vendor_cmd(struct cx231xx *dev, VENDOR_REQUEST_IN *ven_req); |
| 633 | int cx231xx_send_usb_command(struct cx231xx_i2c *i2c_bus, |
| 634 | struct cx231xx_i2c_xfer_data *req_data); |
| 635 | |
| 636 | /* Gpio related functions */ |
| 637 | int cx231xx_send_gpio_cmd(struct cx231xx *dev, u32 gpio_bit, u8* gpio_val, |
| 638 | u8 len, u8 request, u8 direction); |
| 639 | int cx231xx_set_gpio_bit(struct cx231xx *dev, u32 gpio_bit, u8* gpio_val); |
| 640 | int cx231xx_get_gpio_bit(struct cx231xx *dev, u32 gpio_bit, u8* gpio_val); |
| 641 | int cx231xx_set_gpio_value(struct cx231xx *dev, int pin_number, int pin_value); |
| 642 | int cx231xx_set_gpio_direction(struct cx231xx *dev, int pin_number, int pin_value); |
| 643 | |
| 644 | int cx231xx_gpio_i2c_start(struct cx231xx *dev); |
| 645 | int cx231xx_gpio_i2c_end(struct cx231xx *dev); |
| 646 | int cx231xx_gpio_i2c_write_byte(struct cx231xx *dev, u8 data); |
| 647 | int cx231xx_gpio_i2c_read_byte(struct cx231xx *dev, u8 *buf); |
| 648 | int cx231xx_gpio_i2c_read_ack(struct cx231xx *dev); |
| 649 | int cx231xx_gpio_i2c_write_ack(struct cx231xx *dev); |
| 650 | int cx231xx_gpio_i2c_write_nak(struct cx231xx *dev); |
| 651 | |
| 652 | int cx231xx_gpio_i2c_read(struct cx231xx *dev, u8 dev_addr, u8 *buf ,u8 len); |
| 653 | int cx231xx_gpio_i2c_write(struct cx231xx *dev, u8 dev_addr, u8 *buf ,u8 len); |
| 654 | |
| 655 | /* audio related functions */ |
| 656 | int cx231xx_set_audio_decoder_input(struct cx231xx *dev, enum AUDIO_INPUT audio_input); |
| 657 | |
| 658 | int cx231xx_capture_start(struct cx231xx *dev, int start, u8 media_type); |
| 659 | int cx231xx_resolution_set(struct cx231xx *dev); |
| 660 | int cx231xx_set_video_alternate(struct cx231xx *dev); |
| 661 | int cx231xx_set_alt_setting(struct cx231xx *dev, u8 index, u8 alt); |
| 662 | int cx231xx_init_isoc(struct cx231xx *dev, int max_packets, |
| 663 | int num_bufs, int max_pkt_size, |
| 664 | int (*isoc_copy) (struct cx231xx *dev, struct urb *urb)); |
| 665 | void cx231xx_uninit_isoc(struct cx231xx *dev); |
| 666 | int cx231xx_set_mode(struct cx231xx *dev, enum cx231xx_mode set_mode); |
| 667 | int cx231xx_gpio_set(struct cx231xx *dev, struct cx231xx_reg_seq *gpio); |
| 668 | |
| 669 | /* Device list functions */ |
| 670 | void cx231xx_release_resources(struct cx231xx *dev); |
| 671 | void cx231xx_release_analog_resources(struct cx231xx *dev); |
| 672 | int cx231xx_register_analog_devices(struct cx231xx *dev); |
| 673 | void cx231xx_remove_from_devlist(struct cx231xx *dev); |
| 674 | void cx231xx_add_into_devlist(struct cx231xx *dev); |
| 675 | struct cx231xx *cx231xx_get_device(int minor, |
| 676 | enum v4l2_buf_type *fh_type, int *has_radio); |
| 677 | void cx231xx_init_extension(struct cx231xx *dev); |
| 678 | void cx231xx_close_extension(struct cx231xx *dev); |
| 679 | |
| 680 | /* hardware init functions */ |
| 681 | int cx231xx_dev_init(struct cx231xx *dev); |
| 682 | void cx231xx_dev_uninit(struct cx231xx *dev); |
| 683 | void cx231xx_config_i2c(struct cx231xx *dev); |
| 684 | int cx231xx_config(struct cx231xx *dev); |
| 685 | |
| 686 | /* Stream control functions */ |
| 687 | int cx231xx_start_stream(struct cx231xx *dev, u32 ep_mask); |
| 688 | int cx231xx_stop_stream(struct cx231xx *dev, u32 ep_mask); |
| 689 | |
| 690 | int cx231xx_initialize_stream_xfer(struct cx231xx *dev, u32 media_type); |
| 691 | |
| 692 | /* Power control functions */ |
| 693 | int cx231xx_set_power_mode(struct cx231xx *dev, AV_MODE mode); |
| 694 | int cx231xx_power_suspend(struct cx231xx *dev); |
| 695 | |
| 696 | /* chip specific control functions */ |
| 697 | int cx231xx_init_ctrl_pin_status(struct cx231xx *dev); |
| 698 | int cx231xx_set_agc_analog_digital_mux_select(struct cx231xx *dev, u8 analog_or_digital); |
| 699 | int cx231xx_enable_i2c_for_tuner(struct cx231xx *dev, u8 I2CIndex); |
| 700 | |
| 701 | /* video audio decoder related functions */ |
| 702 | void video_mux(struct cx231xx *dev, int index); |
| 703 | int cx231xx_set_video_input_mux(struct cx231xx *dev, u8 input); |
| 704 | int cx231xx_set_decoder_video_input(struct cx231xx *dev, u8 pin_type, u8 input); |
| 705 | int cx231xx_do_mode_ctrl_overrides(struct cx231xx *dev); |
| 706 | int cx231xx_set_audio_input(struct cx231xx *dev, u8 input); |
| 707 | void get_scale(struct cx231xx *dev, |
| 708 | unsigned int width, unsigned int height, |
| 709 | unsigned int *hscale, unsigned int *vscale); |
| 710 | |
| 711 | /* Provided by cx231xx-video.c */ |
| 712 | int cx231xx_register_extension(struct cx231xx_ops *dev); |
| 713 | void cx231xx_unregister_extension(struct cx231xx_ops *dev); |
| 714 | void cx231xx_init_extension(struct cx231xx *dev); |
| 715 | void cx231xx_close_extension(struct cx231xx *dev); |
| 716 | |
| 717 | /* Provided by cx231xx-cards.c */ |
| 718 | extern void cx231xx_pre_card_setup(struct cx231xx *dev); |
| 719 | extern void cx231xx_card_setup(struct cx231xx *dev); |
| 720 | extern struct cx231xx_board cx231xx_boards[]; |
| 721 | extern struct usb_device_id cx231xx_id_table[]; |
| 722 | extern const unsigned int cx231xx_bcount; |
| 723 | void cx231xx_set_ir(struct cx231xx *dev, struct IR_i2c *ir); |
| 724 | int cx231xx_tuner_callback(void *ptr, int component, int command, int arg); |
| 725 | |
| 726 | /* Provided by cx231xx-input.c */ |
| 727 | int cx231xx_ir_init(struct cx231xx *dev); |
| 728 | int cx231xx_ir_fini(struct cx231xx *dev); |
| 729 | |
| 730 | /* printk macros */ |
| 731 | |
| 732 | #define cx231xx_err(fmt, arg...) do {\ |
| 733 | printk(KERN_ERR fmt , ##arg); } while (0) |
| 734 | |
| 735 | #define cx231xx_errdev(fmt, arg...) do {\ |
| 736 | printk(KERN_ERR "%s: "fmt,\ |
| 737 | dev->name , ##arg); } while (0) |
| 738 | |
| 739 | #define cx231xx_info(fmt, arg...) do {\ |
| 740 | printk(KERN_INFO "%s: "fmt,\ |
| 741 | dev->name , ##arg); } while (0) |
| 742 | #define cx231xx_warn(fmt, arg...) do {\ |
| 743 | printk(KERN_WARNING "%s: "fmt,\ |
| 744 | dev->name , ##arg); } while (0) |
| 745 | |
| 746 | |
| 747 | static inline unsigned int norm_maxw(struct cx231xx *dev) |
| 748 | { |
| 749 | if (dev->board.max_range_640_480) |
| 750 | return 640; |
| 751 | else |
| 752 | return 720; |
| 753 | } |
| 754 | |
| 755 | static inline unsigned int norm_maxh(struct cx231xx *dev) |
| 756 | { |
| 757 | if (dev->board.max_range_640_480) |
| 758 | return 480; |
| 759 | else |
| 760 | return (dev->norm & V4L2_STD_625_50) ? 576 : 480; |
| 761 | } |
| 762 | #endif |