blob: b957242dcd5e642784ec84705547a93962fc1e7a [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>
Trent Piepho409d84f2007-10-04 05:28:45 -030030#include <media/videobuf-dma-sg.h>
31#include <media/videobuf-dvb.h>
Steven Tothd19770e2007-03-11 20:44:05 -030032
33#include "btcx-risc.h"
34#include "cx23885-reg.h"
35
36#include <linux/version.h>
37#include <linux/mutex.h>
38
Steven Toth047646b2007-03-20 15:33:53 -030039#define CX23885_VERSION_CODE KERNEL_VERSION(0,0,1)
Steven Tothd19770e2007-03-11 20:44:05 -030040
41#define UNSET (-1U)
42
43#define CX23885_MAXBOARDS 8
44
Steven Tothd19770e2007-03-11 20:44:05 -030045/* Max number of inputs by card */
46#define MAX_CX23885_INPUT 8
47
Steven Tothd19770e2007-03-11 20:44:05 -030048#define BUFFER_TIMEOUT (HZ) /* 0.5 seconds */
49
50#define CX23885_BOARD_NOAUTO UNSET
51#define CX23885_BOARD_UNKNOWN 0
52#define CX23885_BOARD_HAUPPAUGE_HVR1800lp 1
53#define CX23885_BOARD_HAUPPAUGE_HVR1800 2
Steven Totha77743b2007-08-22 21:01:20 -030054#define CX23885_BOARD_HAUPPAUGE_HVR1250 3
Michael Krufky9bc37ca2007-09-08 15:17:13 -030055#define CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP 4
Steven Tothd1987d52007-12-18 01:57:06 -030056#define CX23885_BOARD_HAUPPAUGE_HVR1500Q 5
Michael Krufky07b4a832007-12-18 01:09:11 -030057#define CX23885_BOARD_HAUPPAUGE_HVR1500 6
Steven Tothd19770e2007-03-11 20:44:05 -030058
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
Steven Toth579f1162007-09-08 15:07:02 -030072enum cx23885_src_sel_type {
73 CX23885_SRC_SEL_EXT_656_VIDEO = 0,
74 CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO
75};
76
Steven Tothd19770e2007-03-11 20:44:05 -030077/* buffer for one video frame */
78struct cx23885_buffer {
79 /* common v4l buffer stuff -- must be first */
80 struct videobuf_buffer vb;
81
82 /* cx23885 specific */
83 unsigned int bpl;
84 struct btcx_riscmem risc;
85 struct cx23885_fmt *fmt;
86 u32 count;
87};
88
89struct cx23885_input {
90 enum cx23885_itype type;
91 unsigned int vmux;
92 u32 gpio0, gpio1, gpio2, gpio3;
93};
94
Steven Toth661c7e42007-09-06 16:07:49 -030095typedef enum {
96 CX23885_MPEG_UNDEFINED = 0,
97 CX23885_MPEG_DVB
98} port_t;
99
Steven Tothd19770e2007-03-11 20:44:05 -0300100struct cx23885_board {
101 char *name;
Steven Toth661c7e42007-09-06 16:07:49 -0300102 port_t portb, portc;
Steven Tothc7712612008-01-10 02:24:27 -0300103
104 /* Vendors can and do run the PCIe bridge at different
105 * clock rates, driven physically by crystals on the PCBs.
106 * The core has to accomodate this. This allows the user
107 * to add new boards with new frequencys. The value is
108 * expressed in Hz.
109 *
110 * The core framework will default this value based on
111 * current designs, but it can vary.
112 */
113 u32 clk_freq;
Steven Tothd19770e2007-03-11 20:44:05 -0300114 struct cx23885_input input[MAX_CX23885_INPUT];
115};
116
117struct cx23885_subid {
118 u16 subvendor;
119 u16 subdevice;
120 u32 card;
121};
122
123struct cx23885_i2c {
124 struct cx23885_dev *dev;
125
126 int nr;
127
128 /* i2c i/o */
129 struct i2c_adapter i2c_adap;
130 struct i2c_algo_bit_data i2c_algo;
131 struct i2c_client i2c_client;
132 u32 i2c_rc;
133
134 /* 885 registers used for raw addess */
135 u32 i2c_period;
136 u32 reg_ctrl;
137 u32 reg_stat;
138 u32 reg_addr;
139 u32 reg_rdata;
140 u32 reg_wdata;
141};
142
143struct cx23885_dmaqueue {
144 struct list_head active;
145 struct list_head queued;
146 struct timer_list timeout;
147 struct btcx_riscmem stopper;
148 u32 count;
149};
150
151struct cx23885_tsport {
152 struct cx23885_dev *dev;
153
154 int nr;
155 int sram_chno;
156
157 struct videobuf_dvb dvb;
158
159 /* dma queues */
160 struct cx23885_dmaqueue mpegq;
161 u32 ts_packet_size;
162 u32 ts_packet_count;
163
164 int width;
165 int height;
166
167 spinlock_t slock;
168
169 /* registers */
170 u32 reg_gpcnt;
171 u32 reg_gpcnt_ctl;
172 u32 reg_dma_ctl;
173 u32 reg_lngth;
174 u32 reg_hw_sop_ctrl;
175 u32 reg_gen_ctrl;
176 u32 reg_bd_pkt_status;
177 u32 reg_sop_status;
178 u32 reg_fifo_ovfl_stat;
179 u32 reg_vld_misc;
180 u32 reg_ts_clk_en;
181 u32 reg_ts_int_msk;
Steven Totha6a3f142007-09-08 21:31:56 -0300182 u32 reg_ts_int_stat;
Steven Toth579f1162007-09-08 15:07:02 -0300183 u32 reg_src_sel;
Steven Tothd19770e2007-03-11 20:44:05 -0300184
185 /* Default register vals */
186 int pci_irqmask;
187 u32 dma_ctl_val;
188 u32 ts_int_msk_val;
189 u32 gen_ctrl_val;
190 u32 ts_clk_en_val;
Steven Toth579f1162007-09-08 15:07:02 -0300191 u32 src_sel_val;
Steven Tothd19770e2007-03-11 20:44:05 -0300192};
193
194struct cx23885_dev {
195 struct list_head devlist;
196 atomic_t refcount;
197
198 /* pci stuff */
199 struct pci_dev *pci;
200 unsigned char pci_rev, pci_lat;
201 int pci_bus, pci_slot;
202 u32 __iomem *lmmio;
203 u8 __iomem *bmmio;
Steven Tothd19770e2007-03-11 20:44:05 -0300204 int pci_irqmask;
Steven Toth0ac58812008-01-10 02:06:35 -0300205 int hwrevision;
Steven Tothd19770e2007-03-11 20:44:05 -0300206
Steven Tothc7712612008-01-10 02:24:27 -0300207 /* This valud is board specific and is used to configure the
208 * AV core so we see nice clean and stable video and audio. */
209 u32 clk_freq;
210
Michael Krufky44a64812007-03-20 23:00:18 -0300211 /* I2C adapters: Master 1 & 2 (External) & Master 3 (Internal only) */
Steven Tothd19770e2007-03-11 20:44:05 -0300212 struct cx23885_i2c i2c_bus[3];
213
214 int nr;
215 struct mutex lock;
216
217 /* board details */
218 unsigned int board;
219 char name[32];
220
Steven Totha6a3f142007-09-08 21:31:56 -0300221 struct cx23885_tsport ts1, ts2;
Steven Tothd19770e2007-03-11 20:44:05 -0300222
223 /* sram configuration */
224 struct sram_channel *sram_channels;
Steven Tothe133be02007-03-19 19:22:41 -0300225
226 enum {
227 CX23885_BRIDGE_UNDEFINED = 0,
228 CX23885_BRIDGE_885 = 885,
229 CX23885_BRIDGE_887 = 887,
230 } bridge;
Steven Tothd19770e2007-03-11 20:44:05 -0300231};
232
233#define SRAM_CH01 0 /* Video A */
234#define SRAM_CH02 1 /* VBI A */
235#define SRAM_CH03 2 /* Video B */
236#define SRAM_CH04 3 /* Transport via B */
237#define SRAM_CH05 4 /* VBI B */
238#define SRAM_CH06 5 /* Video C */
239#define SRAM_CH07 6 /* Transport via C */
240#define SRAM_CH08 7 /* Audio Internal A */
241#define SRAM_CH09 8 /* Audio Internal B */
242#define SRAM_CH10 9 /* Audio External */
243#define SRAM_CH11 10 /* COMB_3D_N */
244#define SRAM_CH12 11 /* Comb 3D N1 */
245#define SRAM_CH13 12 /* Comb 3D N2 */
246#define SRAM_CH14 13 /* MOE Vid */
247#define SRAM_CH15 14 /* MOE RSLT */
248
249struct sram_channel {
250 char *name;
251 u32 cmds_start;
252 u32 ctrl_start;
253 u32 cdt;
254 u32 fifo_start;;
255 u32 fifo_size;
256 u32 ptr1_reg;
257 u32 ptr2_reg;
258 u32 cnt1_reg;
259 u32 cnt2_reg;
260 u32 jumponly;
261};
262
263/* ----------------------------------------------------------- */
264
265#define cx_read(reg) readl(dev->lmmio + ((reg)>>2))
266#define cx_write(reg,value) writel((value), dev->lmmio + ((reg)>>2))
267
268#define cx_andor(reg,mask,value) \
269 writel((readl(dev->lmmio+((reg)>>2)) & ~(mask)) |\
270 ((value) & (mask)), dev->lmmio+((reg)>>2))
271
272#define cx_set(reg,bit) cx_andor((reg),(bit),(bit))
273#define cx_clear(reg,bit) cx_andor((reg),(bit),0)
274
Steven Tothd19770e2007-03-11 20:44:05 -0300275/* ----------------------------------------------------------- */
276/* cx23885-cards.c */
277
278extern struct cx23885_board cx23885_boards[];
279extern const unsigned int cx23885_bcount;
280
281extern struct cx23885_subid cx23885_subids[];
282extern const unsigned int cx23885_idcount;
283
284extern void cx23885_card_list(struct cx23885_dev *dev);
Steven Totha6a3f142007-09-08 21:31:56 -0300285extern int cx23885_ir_init(struct cx23885_dev *dev);
286extern void cx23885_gpio_setup(struct cx23885_dev *dev);
Steven Tothd19770e2007-03-11 20:44:05 -0300287extern void cx23885_card_setup(struct cx23885_dev *dev);
288extern void cx23885_card_setup_pre_i2c(struct cx23885_dev *dev);
289
290extern int cx23885_dvb_register(struct cx23885_tsport *port);
291extern int cx23885_dvb_unregister(struct cx23885_tsport *port);
292
Michael Krufky44a64812007-03-20 23:00:18 -0300293extern int cx23885_buf_prepare(struct videobuf_queue *q,
294 struct cx23885_tsport *port,
295 struct cx23885_buffer *buf,
296 enum v4l2_field field);
Steven Tothd19770e2007-03-11 20:44:05 -0300297
Michael Krufky44a64812007-03-20 23:00:18 -0300298extern void cx23885_buf_queue(struct cx23885_tsport *port,
299 struct cx23885_buffer *buf);
300extern void cx23885_free_buffer(struct videobuf_queue *q,
301 struct cx23885_buffer *buf);
Steven Tothd19770e2007-03-11 20:44:05 -0300302
303/* ----------------------------------------------------------- */
304/* cx23885-i2c.c */
305extern int cx23885_i2c_register(struct cx23885_i2c *bus);
306extern int cx23885_i2c_unregister(struct cx23885_i2c *bus);
Michael Krufky44a64812007-03-20 23:00:18 -0300307extern void cx23885_call_i2c_clients(struct cx23885_i2c *bus, unsigned int cmd,
308 void *arg);
Steven Tothd19770e2007-03-11 20:44:05 -0300309
310/*
311 * Local variables:
312 * c-basic-offset: 8
313 * End:
314 * 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
315 */