cx231xx.h 28 KB

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