cx231xx.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008
  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/workqueue.h>
  24. #include <linux/mutex.h>
  25. #include <media/cx2341x.h>
  26. #include <media/videobuf-vmalloc.h>
  27. #include <media/v4l2-device.h>
  28. #include <media/v4l2-ctrls.h>
  29. #include <media/v4l2-fh.h>
  30. #include <media/rc-core.h>
  31. #include <media/ir-kbd-i2c.h>
  32. #include <media/videobuf-dvb.h>
  33. #include "cx231xx-reg.h"
  34. #include "cx231xx-pcb-cfg.h"
  35. #include "cx231xx-conf-reg.h"
  36. #define DRIVER_NAME "cx231xx"
  37. #define PWR_SLEEP_INTERVAL 10
  38. /* I2C addresses for control block in Cx231xx */
  39. #define AFE_DEVICE_ADDRESS 0x60
  40. #define I2S_BLK_DEVICE_ADDRESS 0x98
  41. #define VID_BLK_I2C_ADDRESS 0x88
  42. #define VERVE_I2C_ADDRESS 0x40
  43. #define DIF_USE_BASEBAND 0xFFFFFFFF
  44. /* Boards supported by driver */
  45. #define CX231XX_BOARD_UNKNOWN 0
  46. #define CX231XX_BOARD_CNXT_CARRAERA 1
  47. #define CX231XX_BOARD_CNXT_SHELBY 2
  48. #define CX231XX_BOARD_CNXT_RDE_253S 3
  49. #define CX231XX_BOARD_CNXT_RDU_253S 4
  50. #define CX231XX_BOARD_CNXT_VIDEO_GRABBER 5
  51. #define CX231XX_BOARD_CNXT_RDE_250 6
  52. #define CX231XX_BOARD_CNXT_RDU_250 7
  53. #define CX231XX_BOARD_HAUPPAUGE_EXETER 8
  54. #define CX231XX_BOARD_HAUPPAUGE_USBLIVE2 9
  55. #define CX231XX_BOARD_PV_PLAYTV_USB_HYBRID 10
  56. #define CX231XX_BOARD_PV_XCAPTURE_USB 11
  57. #define CX231XX_BOARD_KWORLD_UB430_USB_HYBRID 12
  58. #define CX231XX_BOARD_ICONBIT_U100 13
  59. #define CX231XX_BOARD_HAUPPAUGE_USB2_FM_PAL 14
  60. #define CX231XX_BOARD_HAUPPAUGE_USB2_FM_NTSC 15
  61. #define CX231XX_BOARD_ELGATO_VIDEO_CAPTURE_V2 16
  62. #define CX231XX_BOARD_OTG102 17
  63. /* Limits minimum and default number of buffers */
  64. #define CX231XX_MIN_BUF 4
  65. #define CX231XX_DEF_BUF 12
  66. #define CX231XX_DEF_VBI_BUF 6
  67. #define VBI_LINE_COUNT 17
  68. #define VBI_LINE_LENGTH 1440
  69. /*Limits the max URB message size */
  70. #define URB_MAX_CTRL_SIZE 80
  71. /* Params for validated field */
  72. #define CX231XX_BOARD_NOT_VALIDATED 1
  73. #define CX231XX_BOARD_VALIDATED 0
  74. /* maximum number of cx231xx boards */
  75. #define CX231XX_MAXBOARDS 8
  76. /* maximum number of frames that can be queued */
  77. #define CX231XX_NUM_FRAMES 5
  78. /* number of buffers for isoc transfers */
  79. #define CX231XX_NUM_BUFS 8
  80. /* number of packets for each buffer
  81. windows requests only 40 packets .. so we better do the same
  82. this is what I found out for all alternate numbers there!
  83. */
  84. #define CX231XX_NUM_PACKETS 40
  85. /* default alternate; 0 means choose the best */
  86. #define CX231XX_PINOUT 0
  87. #define CX231XX_INTERLACED_DEFAULT 1
  88. /* time to wait when stopping the isoc transfer */
  89. #define CX231XX_URB_TIMEOUT \
  90. msecs_to_jiffies(CX231XX_NUM_BUFS * CX231XX_NUM_PACKETS)
  91. #define CX231xx_NORMS (\
  92. V4L2_STD_NTSC_M | V4L2_STD_NTSC_M_JP | V4L2_STD_NTSC_443 | \
  93. V4L2_STD_PAL_BG | V4L2_STD_PAL_DK | V4L2_STD_PAL_I | \
  94. V4L2_STD_PAL_M | V4L2_STD_PAL_N | V4L2_STD_PAL_Nc | \
  95. V4L2_STD_PAL_60 | V4L2_STD_SECAM_L | V4L2_STD_SECAM_DK)
  96. #define SLEEP_S5H1432 30
  97. #define CX23417_OSC_EN 8
  98. #define CX23417_RESET 9
  99. struct cx23417_fmt {
  100. char *name;
  101. u32 fourcc; /* v4l2 format id */
  102. int depth;
  103. int flags;
  104. u32 cxformat;
  105. };
  106. enum cx231xx_mode {
  107. CX231XX_SUSPEND,
  108. CX231XX_ANALOG_MODE,
  109. CX231XX_DIGITAL_MODE,
  110. };
  111. enum cx231xx_std_mode {
  112. CX231XX_TV_AIR = 0,
  113. CX231XX_TV_CABLE
  114. };
  115. enum cx231xx_stream_state {
  116. STREAM_OFF,
  117. STREAM_INTERRUPT,
  118. STREAM_ON,
  119. };
  120. struct cx231xx;
  121. struct cx231xx_isoc_ctl {
  122. /* max packet size of isoc transaction */
  123. int max_pkt_size;
  124. /* number of allocated urbs */
  125. int num_bufs;
  126. /* urb for isoc transfers */
  127. struct urb **urb;
  128. /* transfer buffers for isoc transfer */
  129. char **transfer_buffer;
  130. /* Last buffer command and region */
  131. u8 cmd;
  132. int pos, size, pktsize;
  133. /* Last field: ODD or EVEN? */
  134. int field;
  135. /* Stores incomplete commands */
  136. u32 tmp_buf;
  137. int tmp_buf_len;
  138. /* Stores already requested buffers */
  139. struct cx231xx_buffer *buf;
  140. /* Stores the number of received fields */
  141. int nfields;
  142. /* isoc urb callback */
  143. int (*isoc_copy) (struct cx231xx *dev, struct urb *urb);
  144. };
  145. struct cx231xx_bulk_ctl {
  146. /* max packet size of bulk transaction */
  147. int max_pkt_size;
  148. /* number of allocated urbs */
  149. int num_bufs;
  150. /* urb for bulk transfers */
  151. struct urb **urb;
  152. /* transfer buffers for bulk transfer */
  153. char **transfer_buffer;
  154. /* Last buffer command and region */
  155. u8 cmd;
  156. int pos, size, pktsize;
  157. /* Last field: ODD or EVEN? */
  158. int field;
  159. /* Stores incomplete commands */
  160. u32 tmp_buf;
  161. int tmp_buf_len;
  162. /* Stores already requested buffers */
  163. struct cx231xx_buffer *buf;
  164. /* Stores the number of received fields */
  165. int nfields;
  166. /* bulk urb callback */
  167. int (*bulk_copy) (struct cx231xx *dev, struct urb *urb);
  168. };
  169. struct cx231xx_fmt {
  170. char *name;
  171. u32 fourcc; /* v4l2 format id */
  172. int depth;
  173. int reg;
  174. };
  175. /* buffer for one video frame */
  176. struct cx231xx_buffer {
  177. /* common v4l buffer stuff -- must be first */
  178. struct videobuf_buffer vb;
  179. struct list_head frame;
  180. int top_field;
  181. int receiving;
  182. };
  183. enum ps_package_head {
  184. CX231XX_NEED_ADD_PS_PACKAGE_HEAD = 0,
  185. CX231XX_NONEED_PS_PACKAGE_HEAD
  186. };
  187. struct cx231xx_dmaqueue {
  188. struct list_head active;
  189. struct list_head queued;
  190. wait_queue_head_t wq;
  191. /* Counters to control buffer fill */
  192. int pos;
  193. u8 is_partial_line;
  194. u8 partial_buf[8];
  195. u8 last_sav;
  196. int current_field;
  197. u32 bytes_left_in_line;
  198. u32 lines_completed;
  199. u8 field1_done;
  200. u32 lines_per_field;
  201. /*Mpeg2 control buffer*/
  202. u8 *p_left_data;
  203. u32 left_data_count;
  204. u8 mpeg_buffer_done;
  205. u32 mpeg_buffer_completed;
  206. enum ps_package_head add_ps_package_head;
  207. char ps_head[10];
  208. };
  209. /* inputs */
  210. #define MAX_CX231XX_INPUT 4
  211. enum cx231xx_itype {
  212. CX231XX_VMUX_COMPOSITE1 = 1,
  213. CX231XX_VMUX_SVIDEO,
  214. CX231XX_VMUX_TELEVISION,
  215. CX231XX_VMUX_CABLE,
  216. CX231XX_RADIO,
  217. CX231XX_VMUX_DVB,
  218. CX231XX_VMUX_DEBUG
  219. };
  220. enum cx231xx_v_input {
  221. CX231XX_VIN_1_1 = 0x1,
  222. CX231XX_VIN_2_1,
  223. CX231XX_VIN_3_1,
  224. CX231XX_VIN_4_1,
  225. CX231XX_VIN_1_2 = 0x01,
  226. CX231XX_VIN_2_2,
  227. CX231XX_VIN_3_2,
  228. CX231XX_VIN_1_3 = 0x1,
  229. CX231XX_VIN_2_3,
  230. CX231XX_VIN_3_3,
  231. };
  232. /* cx231xx has two audio inputs: tuner and line in */
  233. enum cx231xx_amux {
  234. /* This is the only entry for cx231xx tuner input */
  235. CX231XX_AMUX_VIDEO, /* cx231xx tuner */
  236. CX231XX_AMUX_LINE_IN, /* Line In */
  237. };
  238. struct cx231xx_reg_seq {
  239. unsigned char bit;
  240. unsigned char val;
  241. int sleep;
  242. };
  243. struct cx231xx_input {
  244. enum cx231xx_itype type;
  245. unsigned int vmux;
  246. enum cx231xx_amux amux;
  247. struct cx231xx_reg_seq *gpio;
  248. };
  249. #define INPUT(nr) (&cx231xx_boards[dev->model].input[nr])
  250. enum cx231xx_decoder {
  251. CX231XX_NODECODER,
  252. CX231XX_AVDECODER
  253. };
  254. enum CX231XX_I2C_MASTER_PORT {
  255. I2C_0 = 0,
  256. I2C_1 = 1,
  257. I2C_2 = 2,
  258. I2C_3 = 3
  259. };
  260. struct cx231xx_board {
  261. char *name;
  262. int vchannels;
  263. int tuner_type;
  264. int tuner_addr;
  265. v4l2_std_id norm; /* tv norm */
  266. /* demod related */
  267. int demod_addr;
  268. u8 demod_xfer_mode; /* 0 - Serial; 1 - parallel */
  269. /* GPIO Pins */
  270. struct cx231xx_reg_seq *dvb_gpio;
  271. struct cx231xx_reg_seq *suspend_gpio;
  272. struct cx231xx_reg_seq *tuner_gpio;
  273. /* Negative means don't use it */
  274. s8 tuner_sif_gpio;
  275. s8 tuner_scl_gpio;
  276. s8 tuner_sda_gpio;
  277. /* PIN ctrl */
  278. u32 ctl_pin_status_mask;
  279. u8 agc_analog_digital_select_gpio;
  280. u32 gpio_pin_status_mask;
  281. /* i2c masters */
  282. u8 tuner_i2c_master;
  283. u8 demod_i2c_master;
  284. u8 ir_i2c_master;
  285. /* for devices with I2C chips for IR */
  286. char *rc_map_name;
  287. unsigned int max_range_640_480:1;
  288. unsigned int has_dvb:1;
  289. unsigned int has_417:1;
  290. unsigned int valid:1;
  291. unsigned int no_alt_vanc:1;
  292. unsigned int external_av:1;
  293. unsigned int dont_use_port_3:1;
  294. unsigned char xclk, i2c_speed;
  295. enum cx231xx_decoder decoder;
  296. int output_mode;
  297. struct cx231xx_input input[MAX_CX231XX_INPUT];
  298. struct cx231xx_input radio;
  299. struct rc_map *ir_codes;
  300. };
  301. /* device states */
  302. enum cx231xx_dev_state {
  303. DEV_INITIALIZED = 0x01,
  304. DEV_DISCONNECTED = 0x02,
  305. };
  306. enum AFE_MODE {
  307. AFE_MODE_LOW_IF,
  308. AFE_MODE_BASEBAND,
  309. AFE_MODE_EU_HI_IF,
  310. AFE_MODE_US_HI_IF,
  311. AFE_MODE_JAPAN_HI_IF
  312. };
  313. enum AUDIO_INPUT {
  314. AUDIO_INPUT_MUTE,
  315. AUDIO_INPUT_LINE,
  316. AUDIO_INPUT_TUNER_TV,
  317. AUDIO_INPUT_SPDIF,
  318. AUDIO_INPUT_TUNER_FM
  319. };
  320. #define CX231XX_AUDIO_BUFS 5
  321. #define CX231XX_NUM_AUDIO_PACKETS 16
  322. #define CX231XX_ISO_NUM_AUDIO_PACKETS 64
  323. /* cx231xx extensions */
  324. #define CX231XX_AUDIO 0x10
  325. #define CX231XX_DVB 0x20
  326. struct cx231xx_audio {
  327. char name[50];
  328. char *transfer_buffer[CX231XX_AUDIO_BUFS];
  329. struct urb *urb[CX231XX_AUDIO_BUFS];
  330. struct usb_device *udev;
  331. unsigned int capture_transfer_done;
  332. struct snd_pcm_substream *capture_pcm_substream;
  333. unsigned int hwptr_done_capture;
  334. struct snd_card *sndcard;
  335. int users, shutdown;
  336. /* locks */
  337. spinlock_t slock;
  338. int alt; /* alternate */
  339. int max_pkt_size; /* max packet size of isoc transaction */
  340. int num_alt; /* Number of alternative settings */
  341. unsigned int *alt_max_pkt_size; /* array of wMaxPacketSize */
  342. u16 end_point_addr;
  343. };
  344. struct cx231xx;
  345. struct cx231xx_fh {
  346. struct v4l2_fh fh;
  347. struct cx231xx *dev;
  348. unsigned int stream_on:1; /* Locks streams */
  349. enum v4l2_buf_type type;
  350. struct videobuf_queue vb_vidq;
  351. /* vbi capture */
  352. struct videobuf_queue vidq;
  353. struct videobuf_queue vbiq;
  354. /* MPEG Encoder specifics ONLY */
  355. atomic_t v4l_reading;
  356. };
  357. /*****************************************************************/
  358. /* set/get i2c */
  359. /* 00--1Mb/s, 01-400kb/s, 10--100kb/s, 11--5Mb/s */
  360. #define I2C_SPEED_1M 0x0
  361. #define I2C_SPEED_400K 0x1
  362. #define I2C_SPEED_100K 0x2
  363. #define I2C_SPEED_5M 0x3
  364. /* 0-- STOP transaction */
  365. #define I2C_STOP 0x0
  366. /* 1-- do not transmit STOP at end of transaction */
  367. #define I2C_NOSTOP 0x1
  368. /* 1--allow slave to insert clock wait states */
  369. #define I2C_SYNC 0x1
  370. struct cx231xx_i2c {
  371. struct cx231xx *dev;
  372. int nr;
  373. /* i2c i/o */
  374. struct i2c_adapter i2c_adap;
  375. struct i2c_client i2c_client;
  376. u32 i2c_rc;
  377. /* different settings for each bus */
  378. u8 i2c_period;
  379. u8 i2c_nostop;
  380. u8 i2c_reserve;
  381. };
  382. struct cx231xx_i2c_xfer_data {
  383. u8 dev_addr;
  384. u8 direction; /* 1 - IN, 0 - OUT */
  385. u8 saddr_len; /* sub address len */
  386. u16 saddr_dat; /* sub addr data */
  387. u8 buf_size; /* buffer size */
  388. u8 *p_buffer; /* pointer to the buffer */
  389. };
  390. struct VENDOR_REQUEST_IN {
  391. u8 bRequest;
  392. u16 wValue;
  393. u16 wIndex;
  394. u16 wLength;
  395. u8 direction;
  396. u8 bData;
  397. u8 *pBuff;
  398. };
  399. struct cx231xx_tvnorm {
  400. char *name;
  401. v4l2_std_id id;
  402. u32 cxiformat;
  403. u32 cxoformat;
  404. };
  405. enum TRANSFER_TYPE {
  406. Raw_Video = 0,
  407. Audio,
  408. Vbi, /* VANC */
  409. Sliced_cc, /* HANC */
  410. TS1_serial_mode,
  411. TS2,
  412. TS1_parallel_mode
  413. } ;
  414. struct cx231xx_video_mode {
  415. /* Isoc control struct */
  416. struct cx231xx_dmaqueue vidq;
  417. struct cx231xx_isoc_ctl isoc_ctl;
  418. struct cx231xx_bulk_ctl bulk_ctl;
  419. /* locks */
  420. spinlock_t slock;
  421. /* usb transfer */
  422. int alt; /* alternate */
  423. int max_pkt_size; /* max packet size of isoc transaction */
  424. int num_alt; /* Number of alternative settings */
  425. unsigned int *alt_max_pkt_size; /* array of wMaxPacketSize */
  426. u16 end_point_addr;
  427. };
  428. /*
  429. struct cx23885_dmaqueue {
  430. struct list_head active;
  431. struct list_head queued;
  432. struct timer_list timeout;
  433. struct btcx_riscmem stopper;
  434. u32 count;
  435. };
  436. */
  437. struct cx231xx_tsport {
  438. struct cx231xx *dev;
  439. int nr;
  440. int sram_chno;
  441. struct videobuf_dvb_frontends frontends;
  442. /* dma queues */
  443. u32 ts_packet_size;
  444. u32 ts_packet_count;
  445. int width;
  446. int height;
  447. /* locks */
  448. spinlock_t slock;
  449. /* registers */
  450. u32 reg_gpcnt;
  451. u32 reg_gpcnt_ctl;
  452. u32 reg_dma_ctl;
  453. u32 reg_lngth;
  454. u32 reg_hw_sop_ctrl;
  455. u32 reg_gen_ctrl;
  456. u32 reg_bd_pkt_status;
  457. u32 reg_sop_status;
  458. u32 reg_fifo_ovfl_stat;
  459. u32 reg_vld_misc;
  460. u32 reg_ts_clk_en;
  461. u32 reg_ts_int_msk;
  462. u32 reg_ts_int_stat;
  463. u32 reg_src_sel;
  464. /* Default register vals */
  465. int pci_irqmask;
  466. u32 dma_ctl_val;
  467. u32 ts_int_msk_val;
  468. u32 gen_ctrl_val;
  469. u32 ts_clk_en_val;
  470. u32 src_sel_val;
  471. u32 vld_misc_val;
  472. u32 hw_sop_ctrl_val;
  473. /* Allow a single tsport to have multiple frontends */
  474. u32 num_frontends;
  475. void *port_priv;
  476. };
  477. /* main device struct */
  478. struct cx231xx {
  479. /* generic device properties */
  480. char name[30]; /* name (including minor) of the device */
  481. int model; /* index in the device_data struct */
  482. int devno; /* marks the number of this device */
  483. struct cx231xx_board board;
  484. /* For I2C IR support */
  485. struct IR_i2c_init_data init_data;
  486. struct i2c_client *ir_i2c_client;
  487. unsigned int stream_on:1; /* Locks streams */
  488. unsigned int vbi_stream_on:1; /* Locks streams for VBI */
  489. unsigned int has_audio_class:1;
  490. unsigned int has_alsa_audio:1;
  491. struct cx231xx_fmt *format;
  492. struct v4l2_device v4l2_dev;
  493. struct v4l2_subdev *sd_cx25840;
  494. struct v4l2_subdev *sd_tuner;
  495. struct v4l2_ctrl_handler ctrl_handler;
  496. struct v4l2_ctrl_handler radio_ctrl_handler;
  497. struct cx2341x_handler mpeg_ctrl_handler;
  498. struct work_struct wq_trigger; /* Trigger to start/stop audio for alsa module */
  499. atomic_t stream_started; /* stream should be running if true */
  500. struct list_head devlist;
  501. int tuner_type; /* type of the tuner */
  502. int tuner_addr; /* tuner address */
  503. /* I2C adapters: Master 1 & 2 (External) & Master 3 (Internal only) */
  504. struct cx231xx_i2c i2c_bus[3];
  505. unsigned int xc_fw_load_done:1;
  506. /* locks */
  507. struct mutex gpio_i2c_lock;
  508. struct mutex i2c_lock;
  509. /* video for linux */
  510. int users; /* user count for exclusive use */
  511. struct video_device *vdev; /* video for linux device struct */
  512. v4l2_std_id norm; /* selected tv norm */
  513. int ctl_freq; /* selected frequency */
  514. unsigned int ctl_ainput; /* selected audio input */
  515. /* frame properties */
  516. int width; /* current frame width */
  517. int height; /* current frame height */
  518. int interlaced; /* 1=interlace fileds, 0=just top fileds */
  519. struct cx231xx_audio adev;
  520. /* states */
  521. enum cx231xx_dev_state state;
  522. struct work_struct request_module_wk;
  523. /* locks */
  524. struct mutex lock;
  525. struct mutex ctrl_urb_lock; /* protects urb_buf */
  526. struct list_head inqueue, outqueue;
  527. wait_queue_head_t open, wait_frame, wait_stream;
  528. struct video_device *vbi_dev;
  529. struct video_device *radio_dev;
  530. unsigned char eedata[256];
  531. struct cx231xx_video_mode video_mode;
  532. struct cx231xx_video_mode vbi_mode;
  533. struct cx231xx_video_mode sliced_cc_mode;
  534. struct cx231xx_video_mode ts1_mode;
  535. atomic_t devlist_count;
  536. struct usb_device *udev; /* the usb device */
  537. char urb_buf[URB_MAX_CTRL_SIZE]; /* urb control msg buffer */
  538. /* helper funcs that call usb_control_msg */
  539. int (*cx231xx_read_ctrl_reg) (struct cx231xx *dev, u8 req, u16 reg,
  540. char *buf, int len);
  541. int (*cx231xx_write_ctrl_reg) (struct cx231xx *dev, u8 req, u16 reg,
  542. char *buf, int len);
  543. int (*cx231xx_send_usb_command) (struct cx231xx_i2c *i2c_bus,
  544. struct cx231xx_i2c_xfer_data *req_data);
  545. int (*cx231xx_gpio_i2c_read) (struct cx231xx *dev, u8 dev_addr,
  546. u8 *buf, u8 len);
  547. int (*cx231xx_gpio_i2c_write) (struct cx231xx *dev, u8 dev_addr,
  548. u8 *buf, u8 len);
  549. int (*cx231xx_set_analog_freq) (struct cx231xx *dev, u32 freq);
  550. int (*cx231xx_reset_analog_tuner) (struct cx231xx *dev);
  551. enum cx231xx_mode mode;
  552. struct cx231xx_dvb *dvb;
  553. /* Cx231xx supported PCB config's */
  554. struct pcb_config current_pcb_config;
  555. u8 current_scenario_idx;
  556. u8 interface_count;
  557. u8 max_iad_interface_count;
  558. /* GPIO related register direction and values */
  559. u32 gpio_dir;
  560. u32 gpio_val;
  561. /* Power Modes */
  562. int power_mode;
  563. /* afe parameters */
  564. enum AFE_MODE afe_mode;
  565. u32 afe_ref_count;
  566. /* video related parameters */
  567. u32 video_input;
  568. u32 active_mode;
  569. u8 vbi_or_sliced_cc_mode; /* 0 - vbi ; 1 - sliced cc mode */
  570. enum cx231xx_std_mode std_mode; /* 0 - Air; 1 - cable */
  571. /*mode: digital=1 or analog=0*/
  572. u8 mode_tv;
  573. u8 USE_ISO;
  574. struct cx231xx_tvnorm encodernorm;
  575. struct cx231xx_tsport ts1, ts2;
  576. struct video_device *v4l_device;
  577. atomic_t v4l_reader_count;
  578. u32 freq;
  579. unsigned int input;
  580. u32 cx23417_mailbox;
  581. u32 __iomem *lmmio;
  582. u8 __iomem *bmmio;
  583. };
  584. extern struct list_head cx231xx_devlist;
  585. #define cx25840_call(cx231xx, o, f, args...) \
  586. v4l2_subdev_call(cx231xx->sd_cx25840, o, f, ##args)
  587. #define tuner_call(cx231xx, o, f, args...) \
  588. v4l2_subdev_call(cx231xx->sd_tuner, o, f, ##args)
  589. #define call_all(dev, o, f, args...) \
  590. v4l2_device_call_until_err(&dev->v4l2_dev, 0, o, f, ##args)
  591. struct cx231xx_ops {
  592. struct list_head next;
  593. char *name;
  594. int id;
  595. int (*init) (struct cx231xx *);
  596. int (*fini) (struct cx231xx *);
  597. };
  598. /* call back functions in dvb module */
  599. int cx231xx_set_analog_freq(struct cx231xx *dev, u32 freq);
  600. int cx231xx_reset_analog_tuner(struct cx231xx *dev);
  601. /* Provided by cx231xx-i2c.c */
  602. void cx231xx_do_i2c_scan(struct cx231xx *dev, struct i2c_client *c);
  603. int cx231xx_i2c_register(struct cx231xx_i2c *bus);
  604. int cx231xx_i2c_unregister(struct cx231xx_i2c *bus);
  605. /* Internal block control functions */
  606. int cx231xx_read_i2c_master(struct cx231xx *dev, u8 dev_addr, u16 saddr,
  607. u8 saddr_len, u32 *data, u8 data_len, int master);
  608. int cx231xx_write_i2c_master(struct cx231xx *dev, u8 dev_addr, u16 saddr,
  609. u8 saddr_len, u32 data, u8 data_len, int master);
  610. int cx231xx_read_i2c_data(struct cx231xx *dev, u8 dev_addr,
  611. u16 saddr, u8 saddr_len, u32 *data, u8 data_len);
  612. int cx231xx_write_i2c_data(struct cx231xx *dev, u8 dev_addr,
  613. u16 saddr, u8 saddr_len, u32 data, u8 data_len);
  614. int cx231xx_reg_mask_write(struct cx231xx *dev, u8 dev_addr, u8 size,
  615. u16 register_address, u8 bit_start, u8 bit_end,
  616. u32 value);
  617. int cx231xx_read_modify_write_i2c_dword(struct cx231xx *dev, u8 dev_addr,
  618. u16 saddr, u32 mask, u32 value);
  619. u32 cx231xx_set_field(u32 field_mask, u32 data);
  620. /*verve r/w*/
  621. void initGPIO(struct cx231xx *dev);
  622. void uninitGPIO(struct cx231xx *dev);
  623. /* afe related functions */
  624. int cx231xx_afe_init_super_block(struct cx231xx *dev, u32 ref_count);
  625. int cx231xx_afe_init_channels(struct cx231xx *dev);
  626. int cx231xx_afe_setup_AFE_for_baseband(struct cx231xx *dev);
  627. int cx231xx_afe_set_input_mux(struct cx231xx *dev, u32 input_mux);
  628. int cx231xx_afe_set_mode(struct cx231xx *dev, enum AFE_MODE mode);
  629. int cx231xx_afe_update_power_control(struct cx231xx *dev,
  630. enum AV_MODE avmode);
  631. int cx231xx_afe_adjust_ref_count(struct cx231xx *dev, u32 video_input);
  632. /* i2s block related functions */
  633. int cx231xx_i2s_blk_initialize(struct cx231xx *dev);
  634. int cx231xx_i2s_blk_update_power_control(struct cx231xx *dev,
  635. enum AV_MODE avmode);
  636. int cx231xx_i2s_blk_set_audio_input(struct cx231xx *dev, u8 audio_input);
  637. /* DIF related functions */
  638. int cx231xx_dif_configure_C2HH_for_low_IF(struct cx231xx *dev, u32 mode,
  639. u32 function_mode, u32 standard);
  640. void cx231xx_set_Colibri_For_LowIF(struct cx231xx *dev, u32 if_freq,
  641. u8 spectral_invert, u32 mode);
  642. u32 cx231xx_Get_Colibri_CarrierOffset(u32 mode, u32 standerd);
  643. void cx231xx_set_DIF_bandpass(struct cx231xx *dev, u32 if_freq,
  644. u8 spectral_invert, u32 mode);
  645. void cx231xx_Setup_AFE_for_LowIF(struct cx231xx *dev);
  646. void reset_s5h1432_demod(struct cx231xx *dev);
  647. void cx231xx_dump_HH_reg(struct cx231xx *dev);
  648. void update_HH_register_after_set_DIF(struct cx231xx *dev);
  649. void cx231xx_dump_SC_reg(struct cx231xx *dev);
  650. int cx231xx_dif_set_standard(struct cx231xx *dev, u32 standard);
  651. int cx231xx_tuner_pre_channel_change(struct cx231xx *dev);
  652. int cx231xx_tuner_post_channel_change(struct cx231xx *dev);
  653. /* video parser functions */
  654. u8 cx231xx_find_next_SAV_EAV(u8 *p_buffer, u32 buffer_size,
  655. u32 *p_bytes_used);
  656. u8 cx231xx_find_boundary_SAV_EAV(u8 *p_buffer, u8 *partial_buf,
  657. u32 *p_bytes_used);
  658. int cx231xx_do_copy(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q,
  659. u8 *p_buffer, u32 bytes_to_copy);
  660. void cx231xx_reset_video_buffer(struct cx231xx *dev,
  661. struct cx231xx_dmaqueue *dma_q);
  662. u8 cx231xx_is_buffer_done(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q);
  663. u32 cx231xx_copy_video_line(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q,
  664. u8 *p_line, u32 length, int field_number);
  665. u32 cx231xx_get_video_line(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q,
  666. u8 sav_eav, u8 *p_buffer, u32 buffer_size);
  667. void cx231xx_swab(u16 *from, u16 *to, u16 len);
  668. /* Provided by cx231xx-core.c */
  669. u32 cx231xx_request_buffers(struct cx231xx *dev, u32 count);
  670. void cx231xx_queue_unusedframes(struct cx231xx *dev);
  671. void cx231xx_release_buffers(struct cx231xx *dev);
  672. /* read from control pipe */
  673. int cx231xx_read_ctrl_reg(struct cx231xx *dev, u8 req, u16 reg,
  674. char *buf, int len);
  675. /* write to control pipe */
  676. int cx231xx_write_ctrl_reg(struct cx231xx *dev, u8 req, u16 reg,
  677. char *buf, int len);
  678. int cx231xx_mode_register(struct cx231xx *dev, u16 address, u32 mode);
  679. int cx231xx_send_vendor_cmd(struct cx231xx *dev,
  680. struct VENDOR_REQUEST_IN *ven_req);
  681. int cx231xx_send_usb_command(struct cx231xx_i2c *i2c_bus,
  682. struct cx231xx_i2c_xfer_data *req_data);
  683. /* Gpio related functions */
  684. int cx231xx_send_gpio_cmd(struct cx231xx *dev, u32 gpio_bit, u8 *gpio_val,
  685. u8 len, u8 request, u8 direction);
  686. int cx231xx_set_gpio_value(struct cx231xx *dev, int pin_number, int pin_value);
  687. int cx231xx_set_gpio_direction(struct cx231xx *dev, int pin_number,
  688. int pin_value);
  689. int cx231xx_gpio_i2c_start(struct cx231xx *dev);
  690. int cx231xx_gpio_i2c_end(struct cx231xx *dev);
  691. int cx231xx_gpio_i2c_write_byte(struct cx231xx *dev, u8 data);
  692. int cx231xx_gpio_i2c_read_byte(struct cx231xx *dev, u8 *buf);
  693. int cx231xx_gpio_i2c_read_ack(struct cx231xx *dev);
  694. int cx231xx_gpio_i2c_write_ack(struct cx231xx *dev);
  695. int cx231xx_gpio_i2c_write_nak(struct cx231xx *dev);
  696. int cx231xx_gpio_i2c_read(struct cx231xx *dev, u8 dev_addr, u8 *buf, u8 len);
  697. int cx231xx_gpio_i2c_write(struct cx231xx *dev, u8 dev_addr, u8 *buf, u8 len);
  698. /* audio related functions */
  699. int cx231xx_set_audio_decoder_input(struct cx231xx *dev,
  700. enum AUDIO_INPUT audio_input);
  701. int cx231xx_capture_start(struct cx231xx *dev, int start, u8 media_type);
  702. int cx231xx_set_video_alternate(struct cx231xx *dev);
  703. int cx231xx_set_alt_setting(struct cx231xx *dev, u8 index, u8 alt);
  704. int is_fw_load(struct cx231xx *dev);
  705. int cx231xx_check_fw(struct cx231xx *dev);
  706. int cx231xx_init_isoc(struct cx231xx *dev, int max_packets,
  707. int num_bufs, int max_pkt_size,
  708. int (*isoc_copy) (struct cx231xx *dev,
  709. struct urb *urb));
  710. int cx231xx_init_bulk(struct cx231xx *dev, int max_packets,
  711. int num_bufs, int max_pkt_size,
  712. int (*bulk_copy) (struct cx231xx *dev,
  713. struct urb *urb));
  714. void cx231xx_stop_TS1(struct cx231xx *dev);
  715. void cx231xx_start_TS1(struct cx231xx *dev);
  716. void cx231xx_uninit_isoc(struct cx231xx *dev);
  717. void cx231xx_uninit_bulk(struct cx231xx *dev);
  718. int cx231xx_set_mode(struct cx231xx *dev, enum cx231xx_mode set_mode);
  719. int cx231xx_unmute_audio(struct cx231xx *dev);
  720. int cx231xx_ep5_bulkout(struct cx231xx *dev, u8 *firmware, u16 size);
  721. void cx231xx_disable656(struct cx231xx *dev);
  722. void cx231xx_enable656(struct cx231xx *dev);
  723. int cx231xx_demod_reset(struct cx231xx *dev);
  724. int cx231xx_gpio_set(struct cx231xx *dev, struct cx231xx_reg_seq *gpio);
  725. /* Device list functions */
  726. void cx231xx_release_resources(struct cx231xx *dev);
  727. void cx231xx_release_analog_resources(struct cx231xx *dev);
  728. int cx231xx_register_analog_devices(struct cx231xx *dev);
  729. void cx231xx_remove_from_devlist(struct cx231xx *dev);
  730. void cx231xx_add_into_devlist(struct cx231xx *dev);
  731. void cx231xx_init_extension(struct cx231xx *dev);
  732. void cx231xx_close_extension(struct cx231xx *dev);
  733. /* hardware init functions */
  734. int cx231xx_dev_init(struct cx231xx *dev);
  735. void cx231xx_dev_uninit(struct cx231xx *dev);
  736. void cx231xx_config_i2c(struct cx231xx *dev);
  737. int cx231xx_config(struct cx231xx *dev);
  738. /* Stream control functions */
  739. int cx231xx_start_stream(struct cx231xx *dev, u32 ep_mask);
  740. int cx231xx_stop_stream(struct cx231xx *dev, u32 ep_mask);
  741. int cx231xx_initialize_stream_xfer(struct cx231xx *dev, u32 media_type);
  742. /* Power control functions */
  743. int cx231xx_set_power_mode(struct cx231xx *dev, enum AV_MODE mode);
  744. int cx231xx_power_suspend(struct cx231xx *dev);
  745. /* chip specific control functions */
  746. int cx231xx_init_ctrl_pin_status(struct cx231xx *dev);
  747. int cx231xx_set_agc_analog_digital_mux_select(struct cx231xx *dev,
  748. u8 analog_or_digital);
  749. int cx231xx_enable_i2c_port_3(struct cx231xx *dev, bool is_port_3);
  750. /* video audio decoder related functions */
  751. void video_mux(struct cx231xx *dev, int index);
  752. int cx231xx_set_video_input_mux(struct cx231xx *dev, u8 input);
  753. int cx231xx_set_decoder_video_input(struct cx231xx *dev, u8 pin_type, u8 input);
  754. int cx231xx_do_mode_ctrl_overrides(struct cx231xx *dev);
  755. int cx231xx_set_audio_input(struct cx231xx *dev, u8 input);
  756. /* Provided by cx231xx-video.c */
  757. int cx231xx_register_extension(struct cx231xx_ops *dev);
  758. void cx231xx_unregister_extension(struct cx231xx_ops *dev);
  759. void cx231xx_init_extension(struct cx231xx *dev);
  760. void cx231xx_close_extension(struct cx231xx *dev);
  761. int cx231xx_querycap(struct file *file, void *priv,
  762. struct v4l2_capability *cap);
  763. int cx231xx_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t);
  764. int cx231xx_s_tuner(struct file *file, void *priv, const struct v4l2_tuner *t);
  765. int cx231xx_g_frequency(struct file *file, void *priv,
  766. struct v4l2_frequency *f);
  767. int cx231xx_s_frequency(struct file *file, void *priv,
  768. const struct v4l2_frequency *f);
  769. int cx231xx_enum_input(struct file *file, void *priv,
  770. struct v4l2_input *i);
  771. int cx231xx_g_input(struct file *file, void *priv, unsigned int *i);
  772. int cx231xx_s_input(struct file *file, void *priv, unsigned int i);
  773. int cx231xx_g_chip_ident(struct file *file, void *fh, struct v4l2_dbg_chip_ident *chip);
  774. int cx231xx_g_register(struct file *file, void *priv,
  775. struct v4l2_dbg_register *reg);
  776. int cx231xx_s_register(struct file *file, void *priv,
  777. const struct v4l2_dbg_register *reg);
  778. /* Provided by cx231xx-cards.c */
  779. extern void cx231xx_pre_card_setup(struct cx231xx *dev);
  780. extern void cx231xx_card_setup(struct cx231xx *dev);
  781. extern struct cx231xx_board cx231xx_boards[];
  782. extern struct usb_device_id cx231xx_id_table[];
  783. extern const unsigned int cx231xx_bcount;
  784. int cx231xx_tuner_callback(void *ptr, int component, int command, int arg);
  785. /* cx23885-417.c */
  786. extern int cx231xx_417_register(struct cx231xx *dev);
  787. extern void cx231xx_417_unregister(struct cx231xx *dev);
  788. /* cx23885-input.c */
  789. #if defined(CONFIG_VIDEO_CX231XX_RC)
  790. int cx231xx_ir_init(struct cx231xx *dev);
  791. void cx231xx_ir_exit(struct cx231xx *dev);
  792. #else
  793. #define cx231xx_ir_init(dev) (0)
  794. #define cx231xx_ir_exit(dev) (0)
  795. #endif
  796. /* printk macros */
  797. #define cx231xx_err(fmt, arg...) do {\
  798. printk(KERN_ERR fmt , ##arg); } while (0)
  799. #define cx231xx_errdev(fmt, arg...) do {\
  800. printk(KERN_ERR "%s: "fmt,\
  801. dev->name , ##arg); } while (0)
  802. #define cx231xx_info(fmt, arg...) do {\
  803. printk(KERN_INFO "%s: "fmt,\
  804. dev->name , ##arg); } while (0)
  805. #define cx231xx_warn(fmt, arg...) do {\
  806. printk(KERN_WARNING "%s: "fmt,\
  807. dev->name , ##arg); } while (0)
  808. static inline unsigned int norm_maxw(struct cx231xx *dev)
  809. {
  810. if (dev->board.max_range_640_480)
  811. return 640;
  812. else
  813. return 720;
  814. }
  815. static inline unsigned int norm_maxh(struct cx231xx *dev)
  816. {
  817. if (dev->board.max_range_640_480)
  818. return 480;
  819. else
  820. return (dev->norm & V4L2_STD_625_50) ? 576 : 480;
  821. }
  822. #endif