cx231xx.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  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. I2C_0 = 0,
  185. I2C_1 = 1,
  186. I2C_2 = 2,
  187. I2C_3 = 3
  188. } CX231XX_I2C_MASTER_PORT;
  189. struct cx231xx_board {
  190. char *name;
  191. int vchannels;
  192. int tuner_type;
  193. int tuner_addr;
  194. v4l2_std_id norm; /* tv norm */
  195. /* demod related */
  196. int demod_addr;
  197. u8 demod_xfer_mode; /* 0 - Serial; 1 - parallel */
  198. /* GPIO Pins */
  199. struct cx231xx_reg_seq *dvb_gpio;
  200. struct cx231xx_reg_seq *suspend_gpio;
  201. struct cx231xx_reg_seq *tuner_gpio;
  202. u8 tuner_sif_gpio;
  203. u8 tuner_scl_gpio;
  204. u8 tuner_sda_gpio;
  205. /* PIN ctrl */
  206. u32 ctl_pin_status_mask;
  207. u8 agc_analog_digital_select_gpio;
  208. u32 gpio_pin_status_mask;
  209. /* i2c masters */
  210. u8 tuner_i2c_master;
  211. u8 demod_i2c_master;
  212. unsigned int max_range_640_480:1;
  213. unsigned int has_dvb:1;
  214. unsigned int valid:1;
  215. unsigned char xclk, i2c_speed;
  216. enum cx231xx_decoder decoder;
  217. struct cx231xx_input input[MAX_CX231XX_INPUT];
  218. struct cx231xx_input radio;
  219. IR_KEYTAB_TYPE *ir_codes;
  220. };
  221. /* device states */
  222. enum cx231xx_dev_state {
  223. DEV_INITIALIZED = 0x01,
  224. DEV_DISCONNECTED = 0x02,
  225. DEV_MISCONFIGURED = 0x04,
  226. };
  227. enum AFE_MODE {
  228. AFE_MODE_LOW_IF,
  229. AFE_MODE_BASEBAND,
  230. AFE_MODE_EU_HI_IF,
  231. AFE_MODE_US_HI_IF,
  232. AFE_MODE_JAPAN_HI_IF
  233. };
  234. enum AUDIO_INPUT {
  235. AUDIO_INPUT_MUTE,
  236. AUDIO_INPUT_LINE,
  237. AUDIO_INPUT_TUNER_TV,
  238. AUDIO_INPUT_SPDIF,
  239. AUDIO_INPUT_TUNER_FM
  240. };
  241. #define CX231XX_AUDIO_BUFS 5
  242. #define CX231XX_NUM_AUDIO_PACKETS 64
  243. #define CX231XX_CAPTURE_STREAM_EN 1
  244. #define CX231XX_STOP_AUDIO 0
  245. #define CX231XX_START_AUDIO 1
  246. /* cx231xx extensions */
  247. #define CX231XX_AUDIO 0x10
  248. #define CX231XX_DVB 0x20
  249. struct cx231xx_audio {
  250. char name[50];
  251. char *transfer_buffer[CX231XX_AUDIO_BUFS];
  252. struct urb *urb[CX231XX_AUDIO_BUFS];
  253. struct usb_device *udev;
  254. unsigned int capture_transfer_done;
  255. struct snd_pcm_substream *capture_pcm_substream;
  256. unsigned int hwptr_done_capture;
  257. struct snd_card *sndcard;
  258. int users, shutdown;
  259. enum cx231xx_stream_state capture_stream;
  260. spinlock_t slock;
  261. int alt; /* alternate */
  262. int max_pkt_size; /* max packet size of isoc transaction */
  263. int num_alt; /* Number of alternative settings */
  264. unsigned int *alt_max_pkt_size; /* array of wMaxPacketSize */
  265. u16 end_point_addr;
  266. };
  267. struct cx231xx;
  268. struct cx231xx_fh {
  269. struct cx231xx *dev;
  270. unsigned int stream_on:1; /* Locks streams */
  271. int radio;
  272. struct videobuf_queue vb_vidq;
  273. enum v4l2_buf_type type;
  274. };
  275. /**********************************************************************************/
  276. /* set/get i2c */
  277. #define I2C_SPEED_1M 0x0 /* 00--1Mb/s, 01-400kb/s, 10--100kb/s, 11--5Mb/s */
  278. #define I2C_SPEED_400K 0x1 /* 00--1Mb/s, 01-400kb/s, 10--100kb/s, 11--5Mb/s */
  279. #define I2C_SPEED_100K 0x2 /* 00--1Mb/s, 01-400kb/s, 10--100kb/s, 11--5Mb/s */
  280. #define I2C_SPEED_5M 0x3 /* 00--1Mb/s, 01-400kb/s, 10--100kb/s, 11--5Mb/s */
  281. #define I2C_STOP 0x0 /* 0-- STOP transaction */
  282. #define I2C_NOSTOP 0x1 /* 1-- do not transmit STOP at end of transaction */
  283. #define I2C_SYNC 0x1 /* 1--alllow slave to insert clock wait states */
  284. struct cx231xx_i2c {
  285. struct cx231xx *dev;
  286. int nr;
  287. /* i2c i/o */
  288. struct i2c_adapter i2c_adap;
  289. struct i2c_algo_bit_data i2c_algo;
  290. struct i2c_client i2c_client;
  291. u32 i2c_rc;
  292. /* different settings for each bus */
  293. u8 i2c_period;
  294. u8 i2c_nostop;
  295. u8 i2c_reserve;
  296. };
  297. struct cx231xx_i2c_xfer_data {
  298. u8 dev_addr;
  299. u8 direction; /* 1 - IN, 0 - OUT */
  300. u8 saddr_len; /* sub address len */
  301. u16 saddr_dat; /* sub addr data */
  302. u8 buf_size; /* buffer size */
  303. u8 *p_buffer; /* pointer to the buffer */
  304. };
  305. typedef struct _VENDOR_REQUEST_IN {
  306. u8 bRequest;
  307. u16 wValue;
  308. u16 wIndex;
  309. u16 wLength;
  310. u8 direction;
  311. u8 bData;
  312. u8 *pBuff;
  313. } VENDOR_REQUEST_IN, *PVENDOR_REQUEST_IN;
  314. struct cx231xx_ctrl {
  315. struct v4l2_queryctrl v;
  316. u32 off;
  317. u32 reg;
  318. u32 mask;
  319. u32 shift;
  320. };
  321. typedef enum {
  322. Raw_Video = 0,
  323. Audio,
  324. Vbi, /* VANC */
  325. Sliced_cc, /* HANC */
  326. TS1_serial_mode,
  327. TS2,
  328. TS1_parallel_mode
  329. } TRANSFER_TYPE;
  330. struct cx231xx_video_mode {
  331. /* Isoc control struct */
  332. struct cx231xx_dmaqueue vidq;
  333. struct cx231xx_usb_isoc_ctl isoc_ctl;
  334. spinlock_t slock;
  335. /* usb transfer */
  336. int alt; /* alternate */
  337. int max_pkt_size; /* max packet size of isoc transaction */
  338. int num_alt; /* Number of alternative settings */
  339. unsigned int *alt_max_pkt_size; /* array of wMaxPacketSize */
  340. u16 end_point_addr;
  341. };
  342. /* main device struct */
  343. struct cx231xx {
  344. /* generic device properties */
  345. char name[30]; /* name (including minor) of the device */
  346. int model; /* index in the device_data struct */
  347. int devno; /* marks the number of this device */
  348. struct cx231xx_board board;
  349. unsigned int stream_on:1; /* Locks streams */
  350. unsigned int vbi_stream_on:1; /* Locks streams for VBI */
  351. unsigned int has_audio_class:1;
  352. unsigned int has_alsa_audio:1;
  353. struct cx231xx_fmt *format;
  354. struct cx231xx_IR *ir;
  355. struct list_head devlist;
  356. int tuner_type; /* type of the tuner */
  357. int tuner_addr; /* tuner address */
  358. /* I2C adapters: Master 1 & 2 (External) & Master 3 (Internal only) */
  359. struct cx231xx_i2c i2c_bus[3];
  360. unsigned int xc_fw_load_done:1;
  361. struct mutex gpio_i2c_lock;
  362. /* video for linux */
  363. int users; /* user count for exclusive use */
  364. struct video_device *vdev; /* video for linux device struct */
  365. v4l2_std_id norm; /* selected tv norm */
  366. int ctl_freq; /* selected frequency */
  367. unsigned int ctl_ainput; /* selected audio input */
  368. int mute;
  369. int volume;
  370. /* frame properties */
  371. int width; /* current frame width */
  372. int height; /* current frame height */
  373. unsigned hscale; /* horizontal scale factor (see datasheet) */
  374. unsigned vscale; /* vertical scale factor (see datasheet) */
  375. int interlaced; /* 1=interlace fileds, 0=just top fileds */
  376. struct cx231xx_audio adev;
  377. /* states */
  378. enum cx231xx_dev_state state;
  379. struct work_struct request_module_wk;
  380. /* locks */
  381. struct mutex lock;
  382. struct mutex ctrl_urb_lock; /* protects urb_buf */
  383. struct list_head inqueue, outqueue;
  384. wait_queue_head_t open, wait_frame, wait_stream;
  385. struct video_device *vbi_dev;
  386. struct video_device *radio_dev;
  387. unsigned char eedata[256];
  388. struct cx231xx_video_mode video_mode;
  389. struct cx231xx_video_mode vbi_mode;
  390. struct cx231xx_video_mode sliced_cc_mode;
  391. struct cx231xx_video_mode ts1_mode;
  392. struct usb_device *udev; /* the usb device */
  393. char urb_buf[URB_MAX_CTRL_SIZE]; /* urb control msg buffer */
  394. /* helper funcs that call usb_control_msg */
  395. int (*cx231xx_read_ctrl_reg) (struct cx231xx *dev, u8 req, u16 reg,
  396. char *buf, int len);
  397. int (*cx231xx_write_ctrl_reg) (struct cx231xx *dev, u8 req, u16 reg,
  398. char *buf, int len);
  399. int (*cx231xx_send_usb_command) (struct cx231xx_i2c *i2c_bus,
  400. struct cx231xx_i2c_xfer_data *req_data);
  401. int (*cx231xx_gpio_i2c_read) (struct cx231xx *dev, u8 dev_addr,
  402. u8 *buf, u8 len);
  403. int (*cx231xx_gpio_i2c_write) (struct cx231xx *dev, u8 dev_addr,
  404. u8 *buf, u8 len);
  405. int (*cx231xx_set_analog_freq) (struct cx231xx *dev, u32 freq);
  406. int (*cx231xx_reset_analog_tuner) (struct cx231xx *dev);
  407. enum cx231xx_mode mode;
  408. struct cx231xx_dvb *dvb;
  409. /* Cx231xx supported PCB config's */
  410. struct pcb_config current_pcb_config;
  411. u8 current_scenario_idx;
  412. u8 interface_count;
  413. u8 max_iad_interface_count;
  414. /* GPIO related register direction and values */
  415. u32 gpio_dir;
  416. u32 gpio_val;
  417. /* Power Modes */
  418. int power_mode;
  419. /* colibri parameters */
  420. enum AFE_MODE colibri_mode;
  421. u32 colibri_ref_count;
  422. /* video related parameters */
  423. u32 video_input;
  424. u32 active_mode;
  425. u8 vbi_or_sliced_cc_mode; /* 0 - vbi ; 1 - sliced cc mode */
  426. enum cx231xx_std_mode std_mode; /* 0 - Air; 1 - cable */
  427. };
  428. struct cx231xx_ops {
  429. struct list_head next;
  430. char *name;
  431. int id;
  432. int (*init) (struct cx231xx *);
  433. int (*fini) (struct cx231xx *);
  434. };
  435. /* call back functions in dvb module */
  436. int cx231xx_set_analog_freq(struct cx231xx *dev, u32 freq);
  437. int cx231xx_reset_analog_tuner(struct cx231xx *dev);
  438. /* Provided by cx231xx-i2c.c */
  439. void cx231xx_i2c_call_clients(struct cx231xx_i2c *bus, unsigned int cmd,
  440. void *arg);
  441. void cx231xx_do_i2c_scan(struct cx231xx *dev, struct i2c_client *c);
  442. int cx231xx_i2c_register(struct cx231xx_i2c *bus);
  443. int cx231xx_i2c_unregister(struct cx231xx_i2c *bus);
  444. /* Internal block control functions */
  445. int cx231xx_read_i2c_data(struct cx231xx *dev, u8 dev_addr,
  446. u16 saddr, u8 saddr_len, u32 *data, u8 data_len);
  447. int cx231xx_write_i2c_data(struct cx231xx *dev, u8 dev_addr,
  448. u16 saddr, u8 saddr_len, u32 data, u8 data_len);
  449. int cx231xx_reg_mask_write(struct cx231xx *dev, u8 dev_addr, u8 size,
  450. u16 register_address, u8 bit_start, u8 bit_end,
  451. 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,
  475. u32 *p_bytes_used);
  476. u8 cx231xx_find_boundary_SAV_EAV(u8 *p_buffer, u8 *partial_buf,
  477. u32 *p_bytes_used);
  478. int cx231xx_do_copy(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q,
  479. u8 *p_buffer, u32 bytes_to_copy);
  480. void cx231xx_reset_video_buffer(struct cx231xx *dev,
  481. struct cx231xx_dmaqueue *dma_q);
  482. u8 cx231xx_is_buffer_done(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q);
  483. u32 cx231xx_copy_video_line(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q,
  484. u8 *p_line, u32 length, int field_number);
  485. u32 cx231xx_get_video_line(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q,
  486. u8 sav_eav, u8 *p_buffer, u32 buffer_size);
  487. void cx231xx_swab(u16 *from, u16 *to, u16 len);
  488. /* Provided by cx231xx-core.c */
  489. u32 cx231xx_request_buffers(struct cx231xx *dev, u32 count);
  490. void cx231xx_queue_unusedframes(struct cx231xx *dev);
  491. void cx231xx_release_buffers(struct cx231xx *dev);
  492. /* read from control pipe */
  493. int cx231xx_read_ctrl_reg(struct cx231xx *dev, u8 req, u16 reg,
  494. char *buf, int len);
  495. /* write to control pipe */
  496. int cx231xx_write_ctrl_reg(struct cx231xx *dev, u8 req, u16 reg,
  497. char *buf, int len);
  498. int cx231xx_mode_register(struct cx231xx *dev, u16 address, u32 mode);
  499. int cx231xx_send_vendor_cmd(struct cx231xx *dev, VENDOR_REQUEST_IN *ven_req);
  500. int cx231xx_send_usb_command(struct cx231xx_i2c *i2c_bus,
  501. struct cx231xx_i2c_xfer_data *req_data);
  502. /* Gpio related functions */
  503. int cx231xx_send_gpio_cmd(struct cx231xx *dev, u32 gpio_bit, u8 *gpio_val,
  504. u8 len, u8 request, u8 direction);
  505. int cx231xx_set_gpio_bit(struct cx231xx *dev, u32 gpio_bit, u8 *gpio_val);
  506. int cx231xx_get_gpio_bit(struct cx231xx *dev, u32 gpio_bit, u8 *gpio_val);
  507. int cx231xx_set_gpio_value(struct cx231xx *dev, int pin_number, int pin_value);
  508. int cx231xx_set_gpio_direction(struct cx231xx *dev, int pin_number,
  509. int pin_value);
  510. int cx231xx_gpio_i2c_start(struct cx231xx *dev);
  511. int cx231xx_gpio_i2c_end(struct cx231xx *dev);
  512. int cx231xx_gpio_i2c_write_byte(struct cx231xx *dev, u8 data);
  513. int cx231xx_gpio_i2c_read_byte(struct cx231xx *dev, u8 *buf);
  514. int cx231xx_gpio_i2c_read_ack(struct cx231xx *dev);
  515. int cx231xx_gpio_i2c_write_ack(struct cx231xx *dev);
  516. int cx231xx_gpio_i2c_write_nak(struct cx231xx *dev);
  517. int cx231xx_gpio_i2c_read(struct cx231xx *dev, u8 dev_addr, u8 *buf, u8 len);
  518. int cx231xx_gpio_i2c_write(struct cx231xx *dev, u8 dev_addr, u8 *buf, u8 len);
  519. /* audio related functions */
  520. int cx231xx_set_audio_decoder_input(struct cx231xx *dev,
  521. enum AUDIO_INPUT audio_input);
  522. int cx231xx_capture_start(struct cx231xx *dev, int start, u8 media_type);
  523. int cx231xx_resolution_set(struct cx231xx *dev);
  524. int cx231xx_set_video_alternate(struct cx231xx *dev);
  525. int cx231xx_set_alt_setting(struct cx231xx *dev, u8 index, u8 alt);
  526. int cx231xx_init_isoc(struct cx231xx *dev, int max_packets,
  527. int num_bufs, int max_pkt_size,
  528. int (*isoc_copy) (struct cx231xx *dev,
  529. struct urb *urb));
  530. void cx231xx_uninit_isoc(struct cx231xx *dev);
  531. int cx231xx_set_mode(struct cx231xx *dev, enum cx231xx_mode set_mode);
  532. int cx231xx_gpio_set(struct cx231xx *dev, struct cx231xx_reg_seq *gpio);
  533. /* Device list functions */
  534. void cx231xx_release_resources(struct cx231xx *dev);
  535. void cx231xx_release_analog_resources(struct cx231xx *dev);
  536. int cx231xx_register_analog_devices(struct cx231xx *dev);
  537. void cx231xx_remove_from_devlist(struct cx231xx *dev);
  538. void cx231xx_add_into_devlist(struct cx231xx *dev);
  539. struct cx231xx *cx231xx_get_device(int minor,
  540. enum v4l2_buf_type *fh_type, int *has_radio);
  541. void cx231xx_init_extension(struct cx231xx *dev);
  542. void cx231xx_close_extension(struct cx231xx *dev);
  543. /* hardware init functions */
  544. int cx231xx_dev_init(struct cx231xx *dev);
  545. void cx231xx_dev_uninit(struct cx231xx *dev);
  546. void cx231xx_config_i2c(struct cx231xx *dev);
  547. int cx231xx_config(struct cx231xx *dev);
  548. /* Stream control functions */
  549. int cx231xx_start_stream(struct cx231xx *dev, u32 ep_mask);
  550. int cx231xx_stop_stream(struct cx231xx *dev, u32 ep_mask);
  551. int cx231xx_initialize_stream_xfer(struct cx231xx *dev, u32 media_type);
  552. /* Power control functions */
  553. int cx231xx_set_power_mode(struct cx231xx *dev, AV_MODE mode);
  554. int cx231xx_power_suspend(struct cx231xx *dev);
  555. /* chip specific control functions */
  556. int cx231xx_init_ctrl_pin_status(struct cx231xx *dev);
  557. int cx231xx_set_agc_analog_digital_mux_select(struct cx231xx *dev,
  558. u8 analog_or_digital);
  559. int cx231xx_enable_i2c_for_tuner(struct cx231xx *dev, u8 I2CIndex);
  560. /* video audio decoder related functions */
  561. void video_mux(struct cx231xx *dev, int index);
  562. int cx231xx_set_video_input_mux(struct cx231xx *dev, u8 input);
  563. int cx231xx_set_decoder_video_input(struct cx231xx *dev, u8 pin_type, u8 input);
  564. int cx231xx_do_mode_ctrl_overrides(struct cx231xx *dev);
  565. int cx231xx_set_audio_input(struct cx231xx *dev, u8 input);
  566. void get_scale(struct cx231xx *dev,
  567. unsigned int width, unsigned int height,
  568. unsigned int *hscale, unsigned int *vscale);
  569. /* Provided by cx231xx-video.c */
  570. int cx231xx_register_extension(struct cx231xx_ops *dev);
  571. void cx231xx_unregister_extension(struct cx231xx_ops *dev);
  572. void cx231xx_init_extension(struct cx231xx *dev);
  573. void cx231xx_close_extension(struct cx231xx *dev);
  574. /* Provided by cx231xx-cards.c */
  575. extern void cx231xx_pre_card_setup(struct cx231xx *dev);
  576. extern void cx231xx_card_setup(struct cx231xx *dev);
  577. extern struct cx231xx_board cx231xx_boards[];
  578. extern struct usb_device_id cx231xx_id_table[];
  579. extern const unsigned int cx231xx_bcount;
  580. void cx231xx_set_ir(struct cx231xx *dev, struct IR_i2c *ir);
  581. int cx231xx_tuner_callback(void *ptr, int component, int command, int arg);
  582. /* Provided by cx231xx-input.c */
  583. int cx231xx_ir_init(struct cx231xx *dev);
  584. int cx231xx_ir_fini(struct cx231xx *dev);
  585. /* printk macros */
  586. #define cx231xx_err(fmt, arg...) do {\
  587. printk(KERN_ERR fmt , ##arg); } while (0)
  588. #define cx231xx_errdev(fmt, arg...) do {\
  589. printk(KERN_ERR "%s: "fmt,\
  590. dev->name , ##arg); } while (0)
  591. #define cx231xx_info(fmt, arg...) do {\
  592. printk(KERN_INFO "%s: "fmt,\
  593. dev->name , ##arg); } while (0)
  594. #define cx231xx_warn(fmt, arg...) do {\
  595. printk(KERN_WARNING "%s: "fmt,\
  596. dev->name , ##arg); } while (0)
  597. static inline unsigned int norm_maxw(struct cx231xx *dev)
  598. {
  599. if (dev->board.max_range_640_480)
  600. return 640;
  601. else
  602. return 720;
  603. }
  604. static inline unsigned int norm_maxh(struct cx231xx *dev)
  605. {
  606. if (dev->board.max_range_640_480)
  607. return 480;
  608. else
  609. return (dev->norm & V4L2_STD_625_50) ? 576 : 480;
  610. }
  611. #endif