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