cx231xx.h 22 KB

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