cx231xx.h 23 KB

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