cx88.h 16 KB

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