cx88.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. /*
  2. *
  3. * v4l2 device driver for cx2388x based TV cards
  4. *
  5. * (c) 2003,04 Gerd Knorr <kraxel@bytesex.org> [SUSE Labs]
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. #include <linux/pci.h>
  22. #include <linux/i2c.h>
  23. #include <linux/i2c-algo-bit.h>
  24. #include <linux/videodev2.h>
  25. #include <linux/kdev_t.h>
  26. #include <media/tuner.h>
  27. #include <media/tveeprom.h>
  28. #include <media/audiochip.h>
  29. #include <media/video-buf.h>
  30. #include <media/video-buf-dvb.h>
  31. #include "btcx-risc.h"
  32. #include "cx88-reg.h"
  33. #include <linux/version.h>
  34. #define CX88_VERSION_CODE KERNEL_VERSION(0,0,5)
  35. #ifndef TRUE
  36. # define TRUE (1==1)
  37. #endif
  38. #ifndef FALSE
  39. # define FALSE (1==0)
  40. #endif
  41. #define UNSET (-1U)
  42. #define CX88_MAXBOARDS 8
  43. /* Max number of inputs by card */
  44. #define MAX_CX88_INPUT 8
  45. /* ----------------------------------------------------------- */
  46. /* defines and enums */
  47. #define FORMAT_FLAGS_PACKED 0x01
  48. #define FORMAT_FLAGS_PLANAR 0x02
  49. #define VBI_LINE_COUNT 17
  50. #define VBI_LINE_LENGTH 2048
  51. /* need "shadow" registers for some write-only ones ... */
  52. #define SHADOW_AUD_VOL_CTL 1
  53. #define SHADOW_AUD_BAL_CTL 2
  54. #define SHADOW_MAX 2
  55. /* FM Radio deemphasis type */
  56. enum cx88_deemph_type {
  57. FM_NO_DEEMPH = 0,
  58. FM_DEEMPH_50,
  59. FM_DEEMPH_75
  60. };
  61. /* ----------------------------------------------------------- */
  62. /* tv norms */
  63. struct cx88_tvnorm {
  64. char *name;
  65. v4l2_std_id id;
  66. u32 cxiformat;
  67. u32 cxoformat;
  68. };
  69. static unsigned int inline norm_maxw(struct cx88_tvnorm *norm)
  70. {
  71. return (norm->id & V4L2_STD_625_50) ? 768 : 640;
  72. }
  73. static unsigned int inline norm_maxh(struct cx88_tvnorm *norm)
  74. {
  75. return (norm->id & V4L2_STD_625_50) ? 576 : 480;
  76. }
  77. /* ----------------------------------------------------------- */
  78. /* static data */
  79. struct cx8800_fmt {
  80. char *name;
  81. u32 fourcc; /* v4l2 format id */
  82. int depth;
  83. int flags;
  84. u32 cxformat;
  85. };
  86. struct cx88_ctrl {
  87. struct v4l2_queryctrl v;
  88. u32 off;
  89. u32 reg;
  90. u32 sreg;
  91. u32 mask;
  92. u32 shift;
  93. };
  94. /* ----------------------------------------------------------- */
  95. /* SRAM memory management data (see cx88-core.c) */
  96. #define SRAM_CH21 0 /* video */
  97. #define SRAM_CH22 1
  98. #define SRAM_CH23 2
  99. #define SRAM_CH24 3 /* vbi */
  100. #define SRAM_CH25 4 /* audio */
  101. #define SRAM_CH26 5
  102. #define SRAM_CH28 6 /* mpeg */
  103. /* more */
  104. struct sram_channel {
  105. char *name;
  106. u32 cmds_start;
  107. u32 ctrl_start;
  108. u32 cdt;
  109. u32 fifo_start;
  110. u32 fifo_size;
  111. u32 ptr1_reg;
  112. u32 ptr2_reg;
  113. u32 cnt1_reg;
  114. u32 cnt2_reg;
  115. };
  116. extern struct sram_channel cx88_sram_channels[];
  117. /* ----------------------------------------------------------- */
  118. /* card configuration */
  119. #define CX88_BOARD_NOAUTO UNSET
  120. #define CX88_BOARD_UNKNOWN 0
  121. #define CX88_BOARD_HAUPPAUGE 1
  122. #define CX88_BOARD_GDI 2
  123. #define CX88_BOARD_PIXELVIEW 3
  124. #define CX88_BOARD_ATI_WONDER_PRO 4
  125. #define CX88_BOARD_WINFAST2000XP_EXPERT 5
  126. #define CX88_BOARD_AVERTV_STUDIO_303 6
  127. #define CX88_BOARD_MSI_TVANYWHERE_MASTER 7
  128. #define CX88_BOARD_WINFAST_DV2000 8
  129. #define CX88_BOARD_LEADTEK_PVR2000 9
  130. #define CX88_BOARD_IODATA_GVVCP3PCI 10
  131. #define CX88_BOARD_PROLINK_PLAYTVPVR 11
  132. #define CX88_BOARD_ASUS_PVR_416 12
  133. #define CX88_BOARD_MSI_TVANYWHERE 13
  134. #define CX88_BOARD_KWORLD_DVB_T 14
  135. #define CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1 15
  136. #define CX88_BOARD_KWORLD_LTV883 16
  137. #define CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q 17
  138. #define CX88_BOARD_HAUPPAUGE_DVB_T1 18
  139. #define CX88_BOARD_CONEXANT_DVB_T1 19
  140. #define CX88_BOARD_PROVIDEO_PV259 20
  141. #define CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS 21
  142. #define CX88_BOARD_PCHDTV_HD3000 22
  143. #define CX88_BOARD_DNTV_LIVE_DVB_T 23
  144. #define CX88_BOARD_HAUPPAUGE_ROSLYN 24
  145. #define CX88_BOARD_DIGITALLOGIC_MEC 25
  146. #define CX88_BOARD_IODATA_GVBCTV7E 26
  147. #define CX88_BOARD_PIXELVIEW_PLAYTV_ULTRA_PRO 27
  148. #define CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_T 28
  149. #define CX88_BOARD_ADSTECH_DVB_T_PCI 29
  150. #define CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1 30
  151. #define CX88_BOARD_DVICO_FUSIONHDTV_5_GOLD 31
  152. #define CX88_BOARD_AVERMEDIA_ULTRATV_MC_550 32
  153. #define CX88_BOARD_KWORLD_VSTREAM_EXPERT_DVD 33
  154. #define CX88_BOARD_ATI_HDTVWONDER 34
  155. #define CX88_BOARD_WINFAST_DTV1000 35
  156. #define CX88_BOARD_AVERTV_303 36
  157. enum cx88_itype {
  158. CX88_VMUX_COMPOSITE1 = 1,
  159. CX88_VMUX_COMPOSITE2,
  160. CX88_VMUX_COMPOSITE3,
  161. CX88_VMUX_COMPOSITE4,
  162. CX88_VMUX_SVIDEO,
  163. CX88_VMUX_TELEVISION,
  164. CX88_VMUX_CABLE,
  165. CX88_VMUX_DVB,
  166. CX88_VMUX_DEBUG,
  167. CX88_RADIO,
  168. };
  169. struct cx88_input {
  170. enum cx88_itype type;
  171. unsigned int vmux;
  172. u32 gpio0, gpio1, gpio2, gpio3;
  173. };
  174. struct cx88_board {
  175. char *name;
  176. unsigned int tuner_type;
  177. unsigned int radio_type;
  178. unsigned char tuner_addr;
  179. unsigned char radio_addr;
  180. int tda9887_conf;
  181. struct cx88_input input[MAX_CX88_INPUT];
  182. struct cx88_input radio;
  183. unsigned int blackbird:1;
  184. unsigned int dvb:1;
  185. };
  186. struct cx88_subid {
  187. u16 subvendor;
  188. u16 subdevice;
  189. u32 card;
  190. };
  191. #define INPUT(nr) (&cx88_boards[core->board].input[nr])
  192. /* ----------------------------------------------------------- */
  193. /* device / file handle status */
  194. #define RESOURCE_OVERLAY 1
  195. #define RESOURCE_VIDEO 2
  196. #define RESOURCE_VBI 4
  197. #define BUFFER_TIMEOUT (HZ/2) /* 0.5 seconds */
  198. /* buffer for one video frame */
  199. struct cx88_buffer {
  200. /* common v4l buffer stuff -- must be first */
  201. struct videobuf_buffer vb;
  202. /* cx88 specific */
  203. unsigned int bpl;
  204. struct btcx_riscmem risc;
  205. struct cx8800_fmt *fmt;
  206. u32 count;
  207. };
  208. struct cx88_dmaqueue {
  209. struct list_head active;
  210. struct list_head queued;
  211. struct timer_list timeout;
  212. struct btcx_riscmem stopper;
  213. u32 count;
  214. };
  215. struct cx88_core {
  216. struct list_head devlist;
  217. atomic_t refcount;
  218. /* board name */
  219. int nr;
  220. char name[32];
  221. /* pci stuff */
  222. int pci_bus;
  223. int pci_slot;
  224. u32 __iomem *lmmio;
  225. u8 __iomem *bmmio;
  226. u32 shadow[SHADOW_MAX];
  227. int pci_irqmask;
  228. /* i2c i/o */
  229. struct i2c_adapter i2c_adap;
  230. struct i2c_algo_bit_data i2c_algo;
  231. struct i2c_client i2c_client;
  232. u32 i2c_state, i2c_rc;
  233. /* config info -- analog */
  234. unsigned int board;
  235. unsigned int tuner_type;
  236. unsigned int radio_type;
  237. unsigned char tuner_addr;
  238. unsigned char radio_addr;
  239. unsigned int tda9887_conf;
  240. unsigned int has_radio;
  241. /* config info -- dvb */
  242. struct dvb_pll_desc *pll_desc;
  243. unsigned int pll_addr;
  244. /* state info */
  245. struct task_struct *kthread;
  246. struct cx88_tvnorm *tvnorm;
  247. u32 tvaudio;
  248. u32 audiomode_manual;
  249. u32 audiomode_current;
  250. u32 input;
  251. u32 astat;
  252. u32 use_nicam;
  253. /* IR remote control state */
  254. struct cx88_IR *ir;
  255. struct semaphore lock;
  256. /* various v4l controls */
  257. u32 freq;
  258. };
  259. struct cx8800_dev;
  260. struct cx8802_dev;
  261. /* ----------------------------------------------------------- */
  262. /* function 0: video stuff */
  263. struct cx8800_fh {
  264. struct cx8800_dev *dev;
  265. enum v4l2_buf_type type;
  266. int radio;
  267. unsigned int resources;
  268. /* video overlay */
  269. struct v4l2_window win;
  270. struct v4l2_clip *clips;
  271. unsigned int nclips;
  272. /* video capture */
  273. struct cx8800_fmt *fmt;
  274. unsigned int width,height;
  275. struct videobuf_queue vidq;
  276. /* vbi capture */
  277. struct videobuf_queue vbiq;
  278. };
  279. struct cx8800_suspend_state {
  280. int disabled;
  281. };
  282. struct cx8800_dev {
  283. struct cx88_core *core;
  284. struct list_head devlist;
  285. spinlock_t slock;
  286. /* various device info */
  287. unsigned int resources;
  288. struct video_device *video_dev;
  289. struct video_device *vbi_dev;
  290. struct video_device *radio_dev;
  291. /* pci i/o */
  292. struct pci_dev *pci;
  293. unsigned char pci_rev,pci_lat;
  294. /* capture queues */
  295. struct cx88_dmaqueue vidq;
  296. struct cx88_dmaqueue vbiq;
  297. /* various v4l controls */
  298. /* other global state info */
  299. struct cx8800_suspend_state state;
  300. };
  301. /* ----------------------------------------------------------- */
  302. /* function 1: audio/alsa stuff */
  303. /* =============> moved to cx88-alsa.c <====================== */
  304. /* ----------------------------------------------------------- */
  305. /* function 2: mpeg stuff */
  306. struct cx8802_fh {
  307. struct cx8802_dev *dev;
  308. struct videobuf_queue mpegq;
  309. };
  310. struct cx8802_suspend_state {
  311. int disabled;
  312. };
  313. /* TODO: move this to struct v4l2_mpeg_compression ? */
  314. struct blackbird_dnr {
  315. u32 mode;
  316. u32 type;
  317. u32 spatial;
  318. u32 temporal;
  319. };
  320. struct cx8802_dev {
  321. struct cx88_core *core;
  322. spinlock_t slock;
  323. /* pci i/o */
  324. struct pci_dev *pci;
  325. unsigned char pci_rev,pci_lat;
  326. /* dma queues */
  327. struct cx88_dmaqueue mpegq;
  328. u32 ts_packet_size;
  329. u32 ts_packet_count;
  330. /* other global state info */
  331. struct cx8802_suspend_state state;
  332. /* for blackbird only */
  333. struct list_head devlist;
  334. struct video_device *mpeg_dev;
  335. u32 mailbox;
  336. int width;
  337. int height;
  338. /* for dvb only */
  339. struct videobuf_dvb dvb;
  340. void* fe_handle;
  341. int (*fe_release)(void *handle);
  342. /* for switching modulation types */
  343. unsigned char ts_gen_cntrl;
  344. /* mpeg params */
  345. struct v4l2_mpeg_compression params;
  346. struct blackbird_dnr dnr_params;
  347. };
  348. /* ----------------------------------------------------------- */
  349. #define cx_read(reg) readl(core->lmmio + ((reg)>>2))
  350. #define cx_write(reg,value) writel((value), core->lmmio + ((reg)>>2))
  351. #define cx_writeb(reg,value) writeb((value), core->bmmio + (reg))
  352. #define cx_andor(reg,mask,value) \
  353. writel((readl(core->lmmio+((reg)>>2)) & ~(mask)) |\
  354. ((value) & (mask)), core->lmmio+((reg)>>2))
  355. #define cx_set(reg,bit) cx_andor((reg),(bit),(bit))
  356. #define cx_clear(reg,bit) cx_andor((reg),(bit),0)
  357. #define cx_wait(d) { if (need_resched()) schedule(); else udelay(d); }
  358. /* shadow registers */
  359. #define cx_sread(sreg) (core->shadow[sreg])
  360. #define cx_swrite(sreg,reg,value) \
  361. (core->shadow[sreg] = value, \
  362. writel(core->shadow[sreg], core->lmmio + ((reg)>>2)))
  363. #define cx_sandor(sreg,reg,mask,value) \
  364. (core->shadow[sreg] = (core->shadow[sreg] & ~(mask)) | ((value) & (mask)), \
  365. writel(core->shadow[sreg], core->lmmio + ((reg)>>2)))
  366. /* ----------------------------------------------------------- */
  367. /* cx88-core.c */
  368. extern void cx88_print_irqbits(char *name, char *tag, char **strings,
  369. u32 bits, u32 mask);
  370. extern void cx88_print_ioctl(char *name, unsigned int cmd);
  371. extern int cx88_core_irq(struct cx88_core *core, u32 status);
  372. extern void cx88_wakeup(struct cx88_core *core,
  373. struct cx88_dmaqueue *q, u32 count);
  374. extern void cx88_shutdown(struct cx88_core *core);
  375. extern int cx88_reset(struct cx88_core *core);
  376. extern int
  377. cx88_risc_buffer(struct pci_dev *pci, struct btcx_riscmem *risc,
  378. struct scatterlist *sglist,
  379. unsigned int top_offset, unsigned int bottom_offset,
  380. unsigned int bpl, unsigned int padding, unsigned int lines);
  381. extern int
  382. cx88_risc_databuffer(struct pci_dev *pci, struct btcx_riscmem *risc,
  383. struct scatterlist *sglist, unsigned int bpl,
  384. unsigned int lines);
  385. extern int
  386. cx88_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc,
  387. u32 reg, u32 mask, u32 value);
  388. extern void
  389. cx88_free_buffer(struct pci_dev *pci, struct cx88_buffer *buf);
  390. extern void cx88_risc_disasm(struct cx88_core *core,
  391. struct btcx_riscmem *risc);
  392. extern int cx88_sram_channel_setup(struct cx88_core *core,
  393. struct sram_channel *ch,
  394. unsigned int bpl, u32 risc);
  395. extern void cx88_sram_channel_dump(struct cx88_core *core,
  396. struct sram_channel *ch);
  397. extern int cx88_set_scale(struct cx88_core *core, unsigned int width,
  398. unsigned int height, enum v4l2_field field);
  399. extern int cx88_set_tvnorm(struct cx88_core *core, struct cx88_tvnorm *norm);
  400. extern struct video_device *cx88_vdev_init(struct cx88_core *core,
  401. struct pci_dev *pci,
  402. struct video_device *template,
  403. char *type);
  404. extern struct cx88_core* cx88_core_get(struct pci_dev *pci);
  405. extern void cx88_core_put(struct cx88_core *core,
  406. struct pci_dev *pci);
  407. /* ----------------------------------------------------------- */
  408. /* cx88-vbi.c */
  409. void cx8800_vbi_fmt(struct cx8800_dev *dev, struct v4l2_format *f);
  410. /*
  411. int cx8800_start_vbi_dma(struct cx8800_dev *dev,
  412. struct cx88_dmaqueue *q,
  413. struct cx88_buffer *buf);
  414. */
  415. int cx8800_stop_vbi_dma(struct cx8800_dev *dev);
  416. int cx8800_restart_vbi_queue(struct cx8800_dev *dev,
  417. struct cx88_dmaqueue *q);
  418. void cx8800_vbi_timeout(unsigned long data);
  419. extern struct videobuf_queue_ops cx8800_vbi_qops;
  420. /* ----------------------------------------------------------- */
  421. /* cx88-i2c.c */
  422. extern int cx88_i2c_init(struct cx88_core *core, struct pci_dev *pci);
  423. extern void cx88_call_i2c_clients(struct cx88_core *core,
  424. unsigned int cmd, void *arg);
  425. /* ----------------------------------------------------------- */
  426. /* cx88-cards.c */
  427. extern struct cx88_board cx88_boards[];
  428. extern const unsigned int cx88_bcount;
  429. extern struct cx88_subid cx88_subids[];
  430. extern const unsigned int cx88_idcount;
  431. extern void cx88_card_list(struct cx88_core *core, struct pci_dev *pci);
  432. extern void cx88_card_setup(struct cx88_core *core);
  433. /* ----------------------------------------------------------- */
  434. /* cx88-tvaudio.c */
  435. #define WW_NONE 1
  436. #define WW_BTSC 2
  437. #define WW_BG 3
  438. #define WW_DK 4
  439. #define WW_I 5
  440. #define WW_L 6
  441. #define WW_EIAJ 7
  442. #define WW_I2SPT 8
  443. #define WW_FM 9
  444. void cx88_set_tvaudio(struct cx88_core *core);
  445. void cx88_newstation(struct cx88_core *core);
  446. void cx88_get_stereo(struct cx88_core *core, struct v4l2_tuner *t);
  447. void cx88_set_stereo(struct cx88_core *core, u32 mode, int manual);
  448. int cx88_audio_thread(void *data);
  449. int cx88_detect_nicam(struct cx88_core *core);
  450. /* ----------------------------------------------------------- */
  451. /* cx88-input.c */
  452. int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci);
  453. int cx88_ir_fini(struct cx88_core *core);
  454. void cx88_ir_irq(struct cx88_core *core);
  455. /* ----------------------------------------------------------- */
  456. /* cx88-mpeg.c */
  457. int cx8802_buf_prepare(struct cx8802_dev *dev, struct cx88_buffer *buf,
  458. enum v4l2_field field);
  459. void cx8802_buf_queue(struct cx8802_dev *dev, struct cx88_buffer *buf);
  460. void cx8802_cancel_buffers(struct cx8802_dev *dev);
  461. int cx8802_init_common(struct cx8802_dev *dev);
  462. void cx8802_fini_common(struct cx8802_dev *dev);
  463. int cx8802_suspend_common(struct pci_dev *pci_dev, pm_message_t state);
  464. int cx8802_resume_common(struct pci_dev *pci_dev);
  465. /* ----------------------------------------------------------- */
  466. /* cx88-video.c */
  467. extern int cx88_do_ioctl(struct inode *inode, struct file *file, int radio,
  468. struct cx88_core *core, unsigned int cmd,
  469. void *arg, v4l2_kioctl driver_ioctl);
  470. /* ----------------------------------------------------------- */
  471. /* cx88-blackbird.c */
  472. extern int (*cx88_ioctl_hook)(struct inode *inode, struct file *file,
  473. unsigned int cmd, void *arg);
  474. extern unsigned int (*cx88_ioctl_translator)(unsigned int cmd);
  475. void blackbird_set_params(struct cx8802_dev *dev,
  476. struct v4l2_mpeg_compression *params);
  477. void blackbird_set_dnr_params(struct cx8802_dev *dev,
  478. struct blackbird_dnr* dnr_params);
  479. /*
  480. * Local variables:
  481. * c-basic-offset: 8
  482. * End:
  483. * kate: eol "unix"; indent-width 3; remove-trailing-space on; replace-trailing-space-save on; tab-width 8; replace-tabs off; space-indent off; mixed-indent off
  484. */