cx231xx.h 22 KB

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