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