cx231xx.h 21 KB

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