cx231xx.h 28 KB

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