cx231xx.h 29 KB

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