cx88.h 16 KB

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