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