cx23885.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. /*
  2. * Driver for the Conexant CX23885 PCIe bridge
  3. *
  4. * Copyright (c) 2006 Steven Toth <stoth@hauppauge.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. *
  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/kdev_t.h>
  25. #include <media/v4l2-common.h>
  26. #include <media/tuner.h>
  27. #include <media/tveeprom.h>
  28. #include <media/videobuf-dma-sg.h>
  29. #include <media/videobuf-dvb.h>
  30. #include "btcx-risc.h"
  31. #include "cx23885-reg.h"
  32. #include <linux/version.h>
  33. #include <linux/mutex.h>
  34. #define CX23885_VERSION_CODE KERNEL_VERSION(0,0,1)
  35. #define UNSET (-1U)
  36. #define CX23885_MAXBOARDS 8
  37. /* Max number of inputs by card */
  38. #define MAX_CX23885_INPUT 8
  39. #define BUFFER_TIMEOUT (HZ) /* 0.5 seconds */
  40. #define CX23885_BOARD_NOAUTO UNSET
  41. #define CX23885_BOARD_UNKNOWN 0
  42. #define CX23885_BOARD_HAUPPAUGE_HVR1800lp 1
  43. #define CX23885_BOARD_HAUPPAUGE_HVR1800 2
  44. #define CX23885_BOARD_HAUPPAUGE_HVR1250 3
  45. #define CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP 4
  46. enum cx23885_itype {
  47. CX23885_VMUX_COMPOSITE1 = 1,
  48. CX23885_VMUX_COMPOSITE2,
  49. CX23885_VMUX_COMPOSITE3,
  50. CX23885_VMUX_COMPOSITE4,
  51. CX23885_VMUX_SVIDEO,
  52. CX23885_VMUX_TELEVISION,
  53. CX23885_VMUX_CABLE,
  54. CX23885_VMUX_DVB,
  55. CX23885_VMUX_DEBUG,
  56. CX23885_RADIO,
  57. };
  58. enum cx23885_src_sel_type {
  59. CX23885_SRC_SEL_EXT_656_VIDEO = 0,
  60. CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO
  61. };
  62. /* buffer for one video frame */
  63. struct cx23885_buffer {
  64. /* common v4l buffer stuff -- must be first */
  65. struct videobuf_buffer vb;
  66. /* cx23885 specific */
  67. unsigned int bpl;
  68. struct btcx_riscmem risc;
  69. struct cx23885_fmt *fmt;
  70. u32 count;
  71. };
  72. struct cx23885_input {
  73. enum cx23885_itype type;
  74. unsigned int vmux;
  75. u32 gpio0, gpio1, gpio2, gpio3;
  76. };
  77. typedef enum {
  78. CX23885_MPEG_UNDEFINED = 0,
  79. CX23885_MPEG_DVB
  80. } port_t;
  81. struct cx23885_board {
  82. char *name;
  83. port_t portb, portc;
  84. struct cx23885_input input[MAX_CX23885_INPUT];
  85. };
  86. struct cx23885_subid {
  87. u16 subvendor;
  88. u16 subdevice;
  89. u32 card;
  90. };
  91. struct cx23885_i2c {
  92. struct cx23885_dev *dev;
  93. int nr;
  94. /* i2c i/o */
  95. struct i2c_adapter i2c_adap;
  96. struct i2c_algo_bit_data i2c_algo;
  97. struct i2c_client i2c_client;
  98. u32 i2c_rc;
  99. /* 885 registers used for raw addess */
  100. u32 i2c_period;
  101. u32 reg_ctrl;
  102. u32 reg_stat;
  103. u32 reg_addr;
  104. u32 reg_rdata;
  105. u32 reg_wdata;
  106. };
  107. struct cx23885_dmaqueue {
  108. struct list_head active;
  109. struct list_head queued;
  110. struct timer_list timeout;
  111. struct btcx_riscmem stopper;
  112. u32 count;
  113. };
  114. struct cx23885_tsport {
  115. struct cx23885_dev *dev;
  116. int nr;
  117. int sram_chno;
  118. struct videobuf_dvb dvb;
  119. /* dma queues */
  120. struct cx23885_dmaqueue mpegq;
  121. u32 ts_packet_size;
  122. u32 ts_packet_count;
  123. int width;
  124. int height;
  125. spinlock_t slock;
  126. /* registers */
  127. u32 reg_gpcnt;
  128. u32 reg_gpcnt_ctl;
  129. u32 reg_dma_ctl;
  130. u32 reg_lngth;
  131. u32 reg_hw_sop_ctrl;
  132. u32 reg_gen_ctrl;
  133. u32 reg_bd_pkt_status;
  134. u32 reg_sop_status;
  135. u32 reg_fifo_ovfl_stat;
  136. u32 reg_vld_misc;
  137. u32 reg_ts_clk_en;
  138. u32 reg_ts_int_msk;
  139. u32 reg_ts_int_stat;
  140. u32 reg_src_sel;
  141. /* Default register vals */
  142. int pci_irqmask;
  143. u32 dma_ctl_val;
  144. u32 ts_int_msk_val;
  145. u32 gen_ctrl_val;
  146. u32 ts_clk_en_val;
  147. u32 src_sel_val;
  148. };
  149. struct cx23885_dev {
  150. struct list_head devlist;
  151. atomic_t refcount;
  152. /* pci stuff */
  153. struct pci_dev *pci;
  154. unsigned char pci_rev, pci_lat;
  155. int pci_bus, pci_slot;
  156. u32 __iomem *lmmio;
  157. u8 __iomem *bmmio;
  158. int pci_irqmask;
  159. /* I2C adapters: Master 1 & 2 (External) & Master 3 (Internal only) */
  160. struct cx23885_i2c i2c_bus[3];
  161. int nr;
  162. struct mutex lock;
  163. /* board details */
  164. unsigned int board;
  165. char name[32];
  166. struct cx23885_tsport ts1, ts2;
  167. /* sram configuration */
  168. struct sram_channel *sram_channels;
  169. enum {
  170. CX23885_BRIDGE_UNDEFINED = 0,
  171. CX23885_BRIDGE_885 = 885,
  172. CX23885_BRIDGE_887 = 887,
  173. } bridge;
  174. };
  175. #define SRAM_CH01 0 /* Video A */
  176. #define SRAM_CH02 1 /* VBI A */
  177. #define SRAM_CH03 2 /* Video B */
  178. #define SRAM_CH04 3 /* Transport via B */
  179. #define SRAM_CH05 4 /* VBI B */
  180. #define SRAM_CH06 5 /* Video C */
  181. #define SRAM_CH07 6 /* Transport via C */
  182. #define SRAM_CH08 7 /* Audio Internal A */
  183. #define SRAM_CH09 8 /* Audio Internal B */
  184. #define SRAM_CH10 9 /* Audio External */
  185. #define SRAM_CH11 10 /* COMB_3D_N */
  186. #define SRAM_CH12 11 /* Comb 3D N1 */
  187. #define SRAM_CH13 12 /* Comb 3D N2 */
  188. #define SRAM_CH14 13 /* MOE Vid */
  189. #define SRAM_CH15 14 /* MOE RSLT */
  190. struct sram_channel {
  191. char *name;
  192. u32 cmds_start;
  193. u32 ctrl_start;
  194. u32 cdt;
  195. u32 fifo_start;;
  196. u32 fifo_size;
  197. u32 ptr1_reg;
  198. u32 ptr2_reg;
  199. u32 cnt1_reg;
  200. u32 cnt2_reg;
  201. u32 jumponly;
  202. };
  203. /* ----------------------------------------------------------- */
  204. #define cx_read(reg) readl(dev->lmmio + ((reg)>>2))
  205. #define cx_write(reg,value) writel((value), dev->lmmio + ((reg)>>2))
  206. #define cx_andor(reg,mask,value) \
  207. writel((readl(dev->lmmio+((reg)>>2)) & ~(mask)) |\
  208. ((value) & (mask)), dev->lmmio+((reg)>>2))
  209. #define cx_set(reg,bit) cx_andor((reg),(bit),(bit))
  210. #define cx_clear(reg,bit) cx_andor((reg),(bit),0)
  211. extern int cx23885_sram_channel_setup(struct cx23885_dev *dev,
  212. struct sram_channel *ch,
  213. unsigned int bpl, u32 risc);
  214. /* ----------------------------------------------------------- */
  215. /* cx23885-cards.c */
  216. extern struct cx23885_board cx23885_boards[];
  217. extern const unsigned int cx23885_bcount;
  218. extern struct cx23885_subid cx23885_subids[];
  219. extern const unsigned int cx23885_idcount;
  220. extern void cx23885_card_list(struct cx23885_dev *dev);
  221. extern int cx23885_ir_init(struct cx23885_dev *dev);
  222. extern void cx23885_gpio_setup(struct cx23885_dev *dev);
  223. extern void cx23885_card_setup(struct cx23885_dev *dev);
  224. extern void cx23885_card_setup_pre_i2c(struct cx23885_dev *dev);
  225. extern int cx23885_dvb_register(struct cx23885_tsport *port);
  226. extern int cx23885_dvb_unregister(struct cx23885_tsport *port);
  227. extern int cx23885_buf_prepare(struct videobuf_queue *q,
  228. struct cx23885_tsport *port,
  229. struct cx23885_buffer *buf,
  230. enum v4l2_field field);
  231. extern void cx23885_buf_queue(struct cx23885_tsport *port,
  232. struct cx23885_buffer *buf);
  233. extern void cx23885_free_buffer(struct videobuf_queue *q,
  234. struct cx23885_buffer *buf);
  235. /* ----------------------------------------------------------- */
  236. /* cx23885-i2c.c */
  237. extern int cx23885_i2c_register(struct cx23885_i2c *bus);
  238. extern int cx23885_i2c_unregister(struct cx23885_i2c *bus);
  239. extern void cx23885_call_i2c_clients(struct cx23885_i2c *bus, unsigned int cmd,
  240. void *arg);
  241. /*
  242. * Local variables:
  243. * c-basic-offset: 8
  244. * End:
  245. * 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
  246. */