cx23885.h 8.1 KB

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