cx231xx.h 29 KB

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