cx231xx.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996
  1. /*
  2. cx231xx.h - driver for Conexant Cx23100/101/102 USB video capture devices
  3. Copyright (C) 2008 <srinivasa.deevi at conexant dot com>
  4. Based on em28xx driver
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. */
  17. #ifndef _CX231XX_H
  18. #define _CX231XX_H
  19. #include <linux/videodev2.h>
  20. #include <linux/types.h>
  21. #include <linux/ioctl.h>
  22. #include <linux/i2c.h>
  23. #include <linux/i2c-algo-bit.h>
  24. #include <linux/mutex.h>
  25. #include <media/cx2341x.h>
  26. #include <media/videobuf-vmalloc.h>
  27. #include <media/v4l2-device.h>
  28. #include <media/ir-core.h>
  29. #if defined(CONFIG_VIDEO_CX231XX_DVB) || \
  30. defined(CONFIG_VIDEO_CX231XX_DVB_MODULE)
  31. #include <media/videobuf-dvb.h>
  32. #endif
  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 5
  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. /* Limits minimum and default number of buffers */
  55. #define CX231XX_MIN_BUF 4
  56. #define CX231XX_DEF_BUF 12
  57. #define CX231XX_DEF_VBI_BUF 6
  58. #define VBI_LINE_COUNT 17
  59. #define VBI_LINE_LENGTH 1440
  60. /*Limits the max URB message size */
  61. #define URB_MAX_CTRL_SIZE 80
  62. /* Params for validated field */
  63. #define CX231XX_BOARD_NOT_VALIDATED 1
  64. #define CX231XX_BOARD_VALIDATED 0
  65. /* maximum number of cx231xx boards */
  66. #define CX231XX_MAXBOARDS 8
  67. /* maximum number of frames that can be queued */
  68. #define CX231XX_NUM_FRAMES 5
  69. /* number of buffers for isoc transfers */
  70. #define CX231XX_NUM_BUFS 8
  71. /* number of packets for each buffer
  72. windows requests only 40 packets .. so we better do the same
  73. this is what I found out for all alternate numbers there!
  74. */
  75. #define CX231XX_NUM_PACKETS 40
  76. /* default alternate; 0 means choose the best */
  77. #define CX231XX_PINOUT 0
  78. #define CX231XX_INTERLACED_DEFAULT 1
  79. /* time to wait when stopping the isoc transfer */
  80. #define CX231XX_URB_TIMEOUT \
  81. msecs_to_jiffies(CX231XX_NUM_BUFS * CX231XX_NUM_PACKETS)
  82. #define CX231xx_NORMS (\
  83. V4L2_STD_NTSC_M | V4L2_STD_NTSC_M_JP | V4L2_STD_NTSC_443 | \
  84. V4L2_STD_PAL_BG | V4L2_STD_PAL_DK | V4L2_STD_PAL_I | \
  85. V4L2_STD_PAL_M | V4L2_STD_PAL_N | V4L2_STD_PAL_Nc | \
  86. V4L2_STD_PAL_60 | V4L2_STD_SECAM_L | V4L2_STD_SECAM_DK)
  87. #define CX231xx_VERSION_CODE KERNEL_VERSION(0, 0, 2)
  88. #define SLEEP_S5H1432 30
  89. #define CX23417_OSC_EN 8
  90. #define CX23417_RESET 9
  91. struct cx23417_fmt {
  92. char *name;
  93. u32 fourcc; /* v4l2 format id */
  94. int depth;
  95. int flags;
  96. u32 cxformat;
  97. };
  98. enum cx231xx_mode {
  99. CX231XX_SUSPEND,
  100. CX231XX_ANALOG_MODE,
  101. CX231XX_DIGITAL_MODE,
  102. };
  103. enum cx231xx_std_mode {
  104. CX231XX_TV_AIR = 0,
  105. CX231XX_TV_CABLE
  106. };
  107. enum cx231xx_stream_state {
  108. STREAM_OFF,
  109. STREAM_INTERRUPT,
  110. STREAM_ON,
  111. };
  112. struct cx231xx;
  113. struct cx231xx_isoc_ctl {
  114. /* max packet size of isoc transaction */
  115. int max_pkt_size;
  116. /* number of allocated urbs */
  117. int num_bufs;
  118. /* urb for isoc transfers */
  119. struct urb **urb;
  120. /* transfer buffers for isoc transfer */
  121. char **transfer_buffer;
  122. /* Last buffer command and region */
  123. u8 cmd;
  124. int pos, size, pktsize;
  125. /* Last field: ODD or EVEN? */
  126. int field;
  127. /* Stores incomplete commands */
  128. u32 tmp_buf;
  129. int tmp_buf_len;
  130. /* Stores already requested buffers */
  131. struct cx231xx_buffer *buf;
  132. /* Stores the number of received fields */
  133. int nfields;
  134. /* isoc urb callback */
  135. int (*isoc_copy) (struct cx231xx *dev, struct urb *urb);
  136. };
  137. struct cx231xx_bulk_ctl {
  138. /* max packet size of bulk transaction */
  139. int max_pkt_size;
  140. /* number of allocated urbs */
  141. int num_bufs;
  142. /* urb for bulk transfers */
  143. struct urb **urb;
  144. /* transfer buffers for bulk transfer */
  145. char **transfer_buffer;
  146. /* Last buffer command and region */
  147. u8 cmd;
  148. int pos, size, pktsize;
  149. /* Last field: ODD or EVEN? */
  150. int field;
  151. /* Stores incomplete commands */
  152. u32 tmp_buf;
  153. int tmp_buf_len;
  154. /* Stores already requested buffers */
  155. struct cx231xx_buffer *buf;
  156. /* Stores the number of received fields */
  157. int nfields;
  158. /* bulk urb callback */
  159. int (*bulk_copy) (struct cx231xx *dev, struct urb *urb);
  160. };
  161. struct cx231xx_fmt {
  162. char *name;
  163. u32 fourcc; /* v4l2 format id */
  164. int depth;
  165. int reg;
  166. };
  167. /* buffer for one video frame */
  168. struct cx231xx_buffer {
  169. /* common v4l buffer stuff -- must be first */
  170. struct videobuf_buffer vb;
  171. struct list_head frame;
  172. int top_field;
  173. int receiving;
  174. };
  175. enum ps_package_head {
  176. CX231XX_NEED_ADD_PS_PACKAGE_HEAD = 0,
  177. CX231XX_NONEED_PS_PACKAGE_HEAD
  178. };
  179. struct cx231xx_dmaqueue {
  180. struct list_head active;
  181. struct list_head queued;
  182. wait_queue_head_t wq;
  183. /* Counters to control buffer fill */
  184. int pos;
  185. u8 is_partial_line;
  186. u8 partial_buf[8];
  187. u8 last_sav;
  188. int current_field;
  189. u32 bytes_left_in_line;
  190. u32 lines_completed;
  191. u8 field1_done;
  192. u32 lines_per_field;
  193. /*Mpeg2 control buffer*/
  194. u8 *p_left_data;
  195. u32 left_data_count;
  196. u8 mpeg_buffer_done;
  197. u32 mpeg_buffer_completed;
  198. enum ps_package_head add_ps_package_head;
  199. char ps_head[10];
  200. };
  201. /* inputs */
  202. #define MAX_CX231XX_INPUT 4
  203. enum cx231xx_itype {
  204. CX231XX_VMUX_COMPOSITE1 = 1,
  205. CX231XX_VMUX_SVIDEO,
  206. CX231XX_VMUX_TELEVISION,
  207. CX231XX_VMUX_CABLE,
  208. CX231XX_RADIO,
  209. CX231XX_VMUX_DVB,
  210. CX231XX_VMUX_DEBUG
  211. };
  212. enum cx231xx_v_input {
  213. CX231XX_VIN_1_1 = 0x1,
  214. CX231XX_VIN_2_1,
  215. CX231XX_VIN_3_1,
  216. CX231XX_VIN_4_1,
  217. CX231XX_VIN_1_2 = 0x01,
  218. CX231XX_VIN_2_2,
  219. CX231XX_VIN_3_2,
  220. CX231XX_VIN_1_3 = 0x1,
  221. CX231XX_VIN_2_3,
  222. CX231XX_VIN_3_3,
  223. };
  224. /* cx231xx has two audio inputs: tuner and line in */
  225. enum cx231xx_amux {
  226. /* This is the only entry for cx231xx tuner input */
  227. CX231XX_AMUX_VIDEO, /* cx231xx tuner */
  228. CX231XX_AMUX_LINE_IN, /* Line In */
  229. };
  230. struct cx231xx_reg_seq {
  231. unsigned char bit;
  232. unsigned char val;
  233. int sleep;
  234. };
  235. struct cx231xx_input {
  236. enum cx231xx_itype type;
  237. unsigned int vmux;
  238. enum cx231xx_amux amux;
  239. struct cx231xx_reg_seq *gpio;
  240. };
  241. #define INPUT(nr) (&cx231xx_boards[dev->model].input[nr])
  242. enum cx231xx_decoder {
  243. CX231XX_NODECODER,
  244. CX231XX_AVDECODER
  245. };
  246. enum CX231XX_I2C_MASTER_PORT {
  247. I2C_0 = 0,
  248. I2C_1 = 1,
  249. I2C_2 = 2,
  250. I2C_3 = 3
  251. };
  252. struct cx231xx_board {
  253. char *name;
  254. int vchannels;
  255. int tuner_type;
  256. int tuner_addr;
  257. v4l2_std_id norm; /* tv norm */
  258. /* demod related */
  259. int demod_addr;
  260. u8 demod_xfer_mode; /* 0 - Serial; 1 - parallel */
  261. /* GPIO Pins */
  262. struct cx231xx_reg_seq *dvb_gpio;
  263. struct cx231xx_reg_seq *suspend_gpio;
  264. struct cx231xx_reg_seq *tuner_gpio;
  265. u8 tuner_sif_gpio;
  266. u8 tuner_scl_gpio;
  267. u8 tuner_sda_gpio;
  268. /* PIN ctrl */
  269. u32 ctl_pin_status_mask;
  270. u8 agc_analog_digital_select_gpio;
  271. u32 gpio_pin_status_mask;
  272. /* i2c masters */
  273. u8 tuner_i2c_master;
  274. u8 demod_i2c_master;
  275. unsigned int max_range_640_480:1;
  276. unsigned int has_dvb:1;
  277. unsigned int valid:1;
  278. unsigned char xclk, i2c_speed;
  279. enum cx231xx_decoder decoder;
  280. struct cx231xx_input input[MAX_CX231XX_INPUT];
  281. struct cx231xx_input radio;
  282. struct ir_scancode_table *ir_codes;
  283. };
  284. /* device states */
  285. enum cx231xx_dev_state {
  286. DEV_INITIALIZED = 0x01,
  287. DEV_DISCONNECTED = 0x02,
  288. DEV_MISCONFIGURED = 0x04,
  289. };
  290. enum AFE_MODE {
  291. AFE_MODE_LOW_IF,
  292. AFE_MODE_BASEBAND,
  293. AFE_MODE_EU_HI_IF,
  294. AFE_MODE_US_HI_IF,
  295. AFE_MODE_JAPAN_HI_IF
  296. };
  297. enum AUDIO_INPUT {
  298. AUDIO_INPUT_MUTE,
  299. AUDIO_INPUT_LINE,
  300. AUDIO_INPUT_TUNER_TV,
  301. AUDIO_INPUT_SPDIF,
  302. AUDIO_INPUT_TUNER_FM
  303. };
  304. #define CX231XX_AUDIO_BUFS 5
  305. #define CX231XX_NUM_AUDIO_PACKETS 16
  306. #define CX231XX_ISO_NUM_AUDIO_PACKETS 64
  307. #define CX231XX_CAPTURE_STREAM_EN 1
  308. #define CX231XX_STOP_AUDIO 0
  309. #define CX231XX_START_AUDIO 1
  310. /* cx231xx extensions */
  311. #define CX231XX_AUDIO 0x10
  312. #define CX231XX_DVB 0x20
  313. struct cx231xx_audio {
  314. char name[50];
  315. char *transfer_buffer[CX231XX_AUDIO_BUFS];
  316. struct urb *urb[CX231XX_AUDIO_BUFS];
  317. struct usb_device *udev;
  318. unsigned int capture_transfer_done;
  319. struct snd_pcm_substream *capture_pcm_substream;
  320. unsigned int hwptr_done_capture;
  321. struct snd_card *sndcard;
  322. int users, shutdown;
  323. enum cx231xx_stream_state capture_stream;
  324. /* locks */
  325. spinlock_t slock;
  326. int alt; /* alternate */
  327. int max_pkt_size; /* max packet size of isoc transaction */
  328. int num_alt; /* Number of alternative settings */
  329. unsigned int *alt_max_pkt_size; /* array of wMaxPacketSize */
  330. u16 end_point_addr;
  331. };
  332. struct cx231xx;
  333. struct cx231xx_fh {
  334. struct cx231xx *dev;
  335. unsigned int stream_on:1; /* Locks streams */
  336. int radio;
  337. struct videobuf_queue vb_vidq;
  338. enum v4l2_buf_type type;
  339. /*following is copyed from cx23885.h*/
  340. u32 resources;
  341. /* video overlay */
  342. struct v4l2_window win;
  343. struct v4l2_clip *clips;
  344. unsigned int nclips;
  345. /* video capture */
  346. struct cx23417_fmt *fmt;
  347. unsigned int width, height;
  348. /* vbi capture */
  349. struct videobuf_queue vidq;
  350. struct videobuf_queue vbiq;
  351. /* MPEG Encoder specifics ONLY */
  352. atomic_t v4l_reading;
  353. };
  354. /*****************************************************************/
  355. /* set/get i2c */
  356. /* 00--1Mb/s, 01-400kb/s, 10--100kb/s, 11--5Mb/s */
  357. #define I2C_SPEED_1M 0x0
  358. #define I2C_SPEED_400K 0x1
  359. #define I2C_SPEED_100K 0x2
  360. #define I2C_SPEED_5M 0x3
  361. /* 0-- STOP transaction */
  362. #define I2C_STOP 0x0
  363. /* 1-- do not transmit STOP at end of transaction */
  364. #define I2C_NOSTOP 0x1
  365. /* 1--alllow slave to insert clock wait states */
  366. #define I2C_SYNC 0x1
  367. struct cx231xx_i2c {
  368. struct cx231xx *dev;
  369. int nr;
  370. /* i2c i/o */
  371. struct i2c_adapter i2c_adap;
  372. struct i2c_algo_bit_data i2c_algo;
  373. struct i2c_client i2c_client;
  374. u32 i2c_rc;
  375. /* different settings for each bus */
  376. u8 i2c_period;
  377. u8 i2c_nostop;
  378. u8 i2c_reserve;
  379. };
  380. struct cx231xx_i2c_xfer_data {
  381. u8 dev_addr;
  382. u8 direction; /* 1 - IN, 0 - OUT */
  383. u8 saddr_len; /* sub address len */
  384. u16 saddr_dat; /* sub addr data */
  385. u8 buf_size; /* buffer size */
  386. u8 *p_buffer; /* pointer to the buffer */
  387. };
  388. struct VENDOR_REQUEST_IN {
  389. u8 bRequest;
  390. u16 wValue;
  391. u16 wIndex;
  392. u16 wLength;
  393. u8 direction;
  394. u8 bData;
  395. u8 *pBuff;
  396. };
  397. struct cx231xx_tvnorm {
  398. char *name;
  399. v4l2_std_id id;
  400. u32 cxiformat;
  401. u32 cxoformat;
  402. };
  403. struct cx231xx_ctrl {
  404. struct v4l2_queryctrl v;
  405. u32 off;
  406. u32 reg;
  407. u32 mask;
  408. u32 shift;
  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. /*
  434. struct cx23885_dmaqueue {
  435. struct list_head active;
  436. struct list_head queued;
  437. struct timer_list timeout;
  438. struct btcx_riscmem stopper;
  439. u32 count;
  440. };
  441. */
  442. struct cx231xx_tsport {
  443. struct cx231xx *dev;
  444. int nr;
  445. int sram_chno;
  446. struct videobuf_dvb_frontends frontends;
  447. /* dma queues */
  448. u32 ts_packet_size;
  449. u32 ts_packet_count;
  450. int width;
  451. int height;
  452. /* locks */
  453. spinlock_t slock;
  454. /* registers */
  455. u32 reg_gpcnt;
  456. u32 reg_gpcnt_ctl;
  457. u32 reg_dma_ctl;
  458. u32 reg_lngth;
  459. u32 reg_hw_sop_ctrl;
  460. u32 reg_gen_ctrl;
  461. u32 reg_bd_pkt_status;
  462. u32 reg_sop_status;
  463. u32 reg_fifo_ovfl_stat;
  464. u32 reg_vld_misc;
  465. u32 reg_ts_clk_en;
  466. u32 reg_ts_int_msk;
  467. u32 reg_ts_int_stat;
  468. u32 reg_src_sel;
  469. /* Default register vals */
  470. int pci_irqmask;
  471. u32 dma_ctl_val;
  472. u32 ts_int_msk_val;
  473. u32 gen_ctrl_val;
  474. u32 ts_clk_en_val;
  475. u32 src_sel_val;
  476. u32 vld_misc_val;
  477. u32 hw_sop_ctrl_val;
  478. /* Allow a single tsport to have multiple frontends */
  479. u32 num_frontends;
  480. void *port_priv;
  481. };
  482. /* main device struct */
  483. struct cx231xx {
  484. /* generic device properties */
  485. char name[30]; /* name (including minor) of the device */
  486. int model; /* index in the device_data struct */
  487. int devno; /* marks the number of this device */
  488. struct cx231xx_board board;
  489. unsigned int stream_on:1; /* Locks streams */
  490. unsigned int vbi_stream_on:1; /* Locks streams for VBI */
  491. unsigned int has_audio_class:1;
  492. unsigned int has_alsa_audio:1;
  493. struct cx231xx_fmt *format;
  494. struct v4l2_device v4l2_dev;
  495. struct v4l2_subdev *sd_cx25840;
  496. struct v4l2_subdev *sd_tuner;
  497. struct cx231xx_IR *ir;
  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. unsigned int xc_fw_load_done:1;
  504. /* locks */
  505. struct mutex gpio_i2c_lock;
  506. struct mutex i2c_lock;
  507. /* video for linux */
  508. int users; /* user count for exclusive use */
  509. struct video_device *vdev; /* video for linux device struct */
  510. v4l2_std_id norm; /* selected tv norm */
  511. int ctl_freq; /* selected frequency */
  512. unsigned int ctl_ainput; /* selected audio input */
  513. int mute;
  514. int volume;
  515. /* frame properties */
  516. int width; /* current frame width */
  517. int height; /* current frame height */
  518. unsigned hscale; /* horizontal scale factor (see datasheet) */
  519. unsigned vscale; /* vertical scale factor (see datasheet) */
  520. int interlaced; /* 1=interlace fileds, 0=just top fileds */
  521. struct cx231xx_audio adev;
  522. /* states */
  523. enum cx231xx_dev_state state;
  524. struct work_struct request_module_wk;
  525. /* locks */
  526. struct mutex lock;
  527. struct mutex ctrl_urb_lock; /* protects urb_buf */
  528. struct list_head inqueue, outqueue;
  529. wait_queue_head_t open, wait_frame, wait_stream;
  530. struct video_device *vbi_dev;
  531. struct video_device *radio_dev;
  532. unsigned char eedata[256];
  533. struct cx231xx_video_mode video_mode;
  534. struct cx231xx_video_mode vbi_mode;
  535. struct cx231xx_video_mode sliced_cc_mode;
  536. struct cx231xx_video_mode ts1_mode;
  537. atomic_t devlist_count;
  538. struct usb_device *udev; /* the usb device */
  539. char urb_buf[URB_MAX_CTRL_SIZE]; /* urb control msg buffer */
  540. /* helper funcs that call usb_control_msg */
  541. int (*cx231xx_read_ctrl_reg) (struct cx231xx *dev, u8 req, u16 reg,
  542. char *buf, int len);
  543. int (*cx231xx_write_ctrl_reg) (struct cx231xx *dev, u8 req, u16 reg,
  544. char *buf, int len);
  545. int (*cx231xx_send_usb_command) (struct cx231xx_i2c *i2c_bus,
  546. struct cx231xx_i2c_xfer_data *req_data);
  547. int (*cx231xx_gpio_i2c_read) (struct cx231xx *dev, u8 dev_addr,
  548. u8 *buf, u8 len);
  549. int (*cx231xx_gpio_i2c_write) (struct cx231xx *dev, u8 dev_addr,
  550. u8 *buf, u8 len);
  551. int (*cx231xx_set_analog_freq) (struct cx231xx *dev, u32 freq);
  552. int (*cx231xx_reset_analog_tuner) (struct cx231xx *dev);
  553. enum cx231xx_mode mode;
  554. struct cx231xx_dvb *dvb;
  555. /* Cx231xx supported PCB config's */
  556. struct pcb_config current_pcb_config;
  557. u8 current_scenario_idx;
  558. u8 interface_count;
  559. u8 max_iad_interface_count;
  560. /* GPIO related register direction and values */
  561. u32 gpio_dir;
  562. u32 gpio_val;
  563. /* Power Modes */
  564. int power_mode;
  565. /* afe parameters */
  566. enum AFE_MODE afe_mode;
  567. u32 afe_ref_count;
  568. /* video related parameters */
  569. u32 video_input;
  570. u32 active_mode;
  571. u8 vbi_or_sliced_cc_mode; /* 0 - vbi ; 1 - sliced cc mode */
  572. enum cx231xx_std_mode std_mode; /* 0 - Air; 1 - cable */
  573. /*mode: digital=1 or analog=0*/
  574. u8 mode_tv;
  575. u8 USE_ISO;
  576. struct cx231xx_tvnorm encodernorm;
  577. struct cx231xx_tsport ts1, ts2;
  578. struct cx2341x_mpeg_params mpeg_params;
  579. struct video_device *v4l_device;
  580. atomic_t v4l_reader_count;
  581. u32 freq;
  582. unsigned int input;
  583. u32 cx23417_mailbox;
  584. u32 __iomem *lmmio;
  585. u8 __iomem *bmmio;
  586. };
  587. extern struct list_head cx231xx_devlist;
  588. #define cx25840_call(cx231xx, o, f, args...) \
  589. v4l2_subdev_call(cx231xx->sd_cx25840, o, f, ##args)
  590. #define tuner_call(cx231xx, o, f, args...) \
  591. v4l2_subdev_call(cx231xx->sd_tuner, o, f, ##args)
  592. #define call_all(dev, o, f, args...) \
  593. v4l2_device_call_until_err(&dev->v4l2_dev, 0, o, f, ##args)
  594. struct cx231xx_ops {
  595. struct list_head next;
  596. char *name;
  597. int id;
  598. int (*init) (struct cx231xx *);
  599. int (*fini) (struct cx231xx *);
  600. };
  601. /* call back functions in dvb module */
  602. int cx231xx_set_analog_freq(struct cx231xx *dev, u32 freq);
  603. int cx231xx_reset_analog_tuner(struct cx231xx *dev);
  604. /* Provided by cx231xx-i2c.c */
  605. void cx231xx_do_i2c_scan(struct cx231xx *dev, struct i2c_client *c);
  606. int cx231xx_i2c_register(struct cx231xx_i2c *bus);
  607. int cx231xx_i2c_unregister(struct cx231xx_i2c *bus);
  608. /* Internal block control functions */
  609. int cx231xx_read_i2c_master(struct cx231xx *dev, u8 dev_addr, u16 saddr,
  610. u8 saddr_len, u32 *data, u8 data_len, int master);
  611. int cx231xx_write_i2c_master(struct cx231xx *dev, u8 dev_addr, u16 saddr,
  612. u8 saddr_len, u32 data, u8 data_len, int master);
  613. int cx231xx_read_i2c_data(struct cx231xx *dev, u8 dev_addr,
  614. u16 saddr, u8 saddr_len, u32 *data, u8 data_len);
  615. int cx231xx_write_i2c_data(struct cx231xx *dev, u8 dev_addr,
  616. u16 saddr, u8 saddr_len, u32 data, u8 data_len);
  617. int cx231xx_reg_mask_write(struct cx231xx *dev, u8 dev_addr, u8 size,
  618. u16 register_address, u8 bit_start, u8 bit_end,
  619. u32 value);
  620. int cx231xx_read_modify_write_i2c_dword(struct cx231xx *dev, u8 dev_addr,
  621. u16 saddr, u32 mask, u32 value);
  622. u32 cx231xx_set_field(u32 field_mask, u32 data);
  623. /*verve r/w*/
  624. void initGPIO(struct cx231xx *dev);
  625. void uninitGPIO(struct cx231xx *dev);
  626. /* afe related functions */
  627. int cx231xx_afe_init_super_block(struct cx231xx *dev, u32 ref_count);
  628. int cx231xx_afe_init_channels(struct cx231xx *dev);
  629. int cx231xx_afe_setup_AFE_for_baseband(struct cx231xx *dev);
  630. int cx231xx_afe_set_input_mux(struct cx231xx *dev, u32 input_mux);
  631. int cx231xx_afe_set_mode(struct cx231xx *dev, enum AFE_MODE mode);
  632. int cx231xx_afe_update_power_control(struct cx231xx *dev,
  633. enum AV_MODE avmode);
  634. int cx231xx_afe_adjust_ref_count(struct cx231xx *dev, u32 video_input);
  635. /* i2s block related functions */
  636. int cx231xx_i2s_blk_initialize(struct cx231xx *dev);
  637. int cx231xx_i2s_blk_update_power_control(struct cx231xx *dev,
  638. enum AV_MODE avmode);
  639. int cx231xx_i2s_blk_set_audio_input(struct cx231xx *dev, u8 audio_input);
  640. /* DIF related functions */
  641. int cx231xx_dif_configure_C2HH_for_low_IF(struct cx231xx *dev, u32 mode,
  642. u32 function_mode, u32 standard);
  643. void cx231xx_set_Colibri_For_LowIF(struct cx231xx *dev, u32 if_freq,
  644. u8 spectral_invert, u32 mode);
  645. u32 cx231xx_Get_Colibri_CarrierOffset(u32 mode, u32 standerd);
  646. void cx231xx_set_DIF_bandpass(struct cx231xx *dev, u32 if_freq,
  647. u8 spectral_invert, u32 mode);
  648. void cx231xx_Setup_AFE_for_LowIF(struct cx231xx *dev);
  649. void reset_s5h1432_demod(struct cx231xx *dev);
  650. void cx231xx_dump_HH_reg(struct cx231xx *dev);
  651. void update_HH_register_after_set_DIF(struct cx231xx *dev);
  652. void cx231xx_dump_SC_reg(struct cx231xx *dev);
  653. int cx231xx_dif_set_standard(struct cx231xx *dev, u32 standard);
  654. int cx231xx_tuner_pre_channel_change(struct cx231xx *dev);
  655. int cx231xx_tuner_post_channel_change(struct cx231xx *dev);
  656. /* video parser functions */
  657. u8 cx231xx_find_next_SAV_EAV(u8 *p_buffer, u32 buffer_size,
  658. u32 *p_bytes_used);
  659. u8 cx231xx_find_boundary_SAV_EAV(u8 *p_buffer, u8 *partial_buf,
  660. u32 *p_bytes_used);
  661. int cx231xx_do_copy(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q,
  662. u8 *p_buffer, u32 bytes_to_copy);
  663. void cx231xx_reset_video_buffer(struct cx231xx *dev,
  664. struct cx231xx_dmaqueue *dma_q);
  665. u8 cx231xx_is_buffer_done(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q);
  666. u32 cx231xx_copy_video_line(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q,
  667. u8 *p_line, u32 length, int field_number);
  668. u32 cx231xx_get_video_line(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q,
  669. u8 sav_eav, u8 *p_buffer, u32 buffer_size);
  670. void cx231xx_swab(u16 *from, u16 *to, u16 len);
  671. /* Provided by cx231xx-core.c */
  672. u32 cx231xx_request_buffers(struct cx231xx *dev, u32 count);
  673. void cx231xx_queue_unusedframes(struct cx231xx *dev);
  674. void cx231xx_release_buffers(struct cx231xx *dev);
  675. /* read from control pipe */
  676. int cx231xx_read_ctrl_reg(struct cx231xx *dev, u8 req, u16 reg,
  677. char *buf, int len);
  678. /* write to control pipe */
  679. int cx231xx_write_ctrl_reg(struct cx231xx *dev, u8 req, u16 reg,
  680. char *buf, int len);
  681. int cx231xx_mode_register(struct cx231xx *dev, u16 address, u32 mode);
  682. int cx231xx_send_vendor_cmd(struct cx231xx *dev,
  683. struct VENDOR_REQUEST_IN *ven_req);
  684. int cx231xx_send_usb_command(struct cx231xx_i2c *i2c_bus,
  685. struct cx231xx_i2c_xfer_data *req_data);
  686. /* Gpio related functions */
  687. int cx231xx_send_gpio_cmd(struct cx231xx *dev, u32 gpio_bit, u8 *gpio_val,
  688. u8 len, u8 request, u8 direction);
  689. int cx231xx_set_gpio_bit(struct cx231xx *dev, u32 gpio_bit, u8 *gpio_val);
  690. int cx231xx_get_gpio_bit(struct cx231xx *dev, u32 gpio_bit, u8 *gpio_val);
  691. int cx231xx_set_gpio_value(struct cx231xx *dev, int pin_number, int pin_value);
  692. int cx231xx_set_gpio_direction(struct cx231xx *dev, int pin_number,
  693. int pin_value);
  694. int cx231xx_gpio_i2c_start(struct cx231xx *dev);
  695. int cx231xx_gpio_i2c_end(struct cx231xx *dev);
  696. int cx231xx_gpio_i2c_write_byte(struct cx231xx *dev, u8 data);
  697. int cx231xx_gpio_i2c_read_byte(struct cx231xx *dev, u8 *buf);
  698. int cx231xx_gpio_i2c_read_ack(struct cx231xx *dev);
  699. int cx231xx_gpio_i2c_write_ack(struct cx231xx *dev);
  700. int cx231xx_gpio_i2c_write_nak(struct cx231xx *dev);
  701. int cx231xx_gpio_i2c_read(struct cx231xx *dev, u8 dev_addr, u8 *buf, u8 len);
  702. int cx231xx_gpio_i2c_write(struct cx231xx *dev, u8 dev_addr, u8 *buf, u8 len);
  703. /* audio related functions */
  704. int cx231xx_set_audio_decoder_input(struct cx231xx *dev,
  705. enum AUDIO_INPUT audio_input);
  706. int cx231xx_capture_start(struct cx231xx *dev, int start, u8 media_type);
  707. int cx231xx_resolution_set(struct cx231xx *dev);
  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_for_tuner(struct cx231xx *dev, u8 I2CIndex);
  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. /* Provided by cx231xx-cards.c */
  768. extern void cx231xx_pre_card_setup(struct cx231xx *dev);
  769. extern void cx231xx_card_setup(struct cx231xx *dev);
  770. extern struct cx231xx_board cx231xx_boards[];
  771. extern struct usb_device_id cx231xx_id_table[];
  772. extern const unsigned int cx231xx_bcount;
  773. void cx231xx_register_i2c_ir(struct cx231xx *dev);
  774. int cx231xx_tuner_callback(void *ptr, int component, int command, int arg);
  775. /* Provided by cx231xx-input.c */
  776. int cx231xx_ir_init(struct cx231xx *dev);
  777. int cx231xx_ir_fini(struct cx231xx *dev);
  778. /* cx23885-417.c */
  779. extern int cx231xx_417_register(struct cx231xx *dev);
  780. extern void cx231xx_417_unregister(struct cx231xx *dev);
  781. /* printk macros */
  782. #define cx231xx_err(fmt, arg...) do {\
  783. printk(KERN_ERR fmt , ##arg); } while (0)
  784. #define cx231xx_errdev(fmt, arg...) do {\
  785. printk(KERN_ERR "%s: "fmt,\
  786. dev->name , ##arg); } while (0)
  787. #define cx231xx_info(fmt, arg...) do {\
  788. printk(KERN_INFO "%s: "fmt,\
  789. dev->name , ##arg); } while (0)
  790. #define cx231xx_warn(fmt, arg...) do {\
  791. printk(KERN_WARNING "%s: "fmt,\
  792. dev->name , ##arg); } while (0)
  793. static inline unsigned int norm_maxw(struct cx231xx *dev)
  794. {
  795. if (dev->board.max_range_640_480)
  796. return 640;
  797. else
  798. return 720;
  799. }
  800. static inline unsigned int norm_maxh(struct cx231xx *dev)
  801. {
  802. if (dev->board.max_range_640_480)
  803. return 480;
  804. else
  805. return (dev->norm & V4L2_STD_625_50) ? 576 : 480;
  806. }
  807. #endif