blob: 227c0200b70a5bd04fb15be61b4150c77b5ae70a [file] [log] [blame]
Johannes Stezenbach2add87a2005-05-16 21:54:10 -07001/*
Uwe Bugla91b94362009-03-29 08:13:01 -03002 * Linux driver the digital TV devices equipped with B2C2 FlexcopII(b)/III
3 * flexcop-pci.c - covers the PCI part including DMA transfers
4 * see flexcop.c for copyright information
Johannes Stezenbach2add87a2005-05-16 21:54:10 -07005 */
6
7#define FC_LOG_PREFIX "flexcop-pci"
8#include "flexcop-common.h"
9
Johannes Stezenbachc4ee3fd2005-05-16 21:54:15 -070010static int enable_pid_filtering = 1;
Johannes Stezenbach2add87a2005-05-16 21:54:10 -070011module_param(enable_pid_filtering, int, 0444);
Uwe Bugla91b94362009-03-29 08:13:01 -030012MODULE_PARM_DESC(enable_pid_filtering,
13 "enable hardware pid filtering: supported values: 0 (fullts), 1");
Johannes Stezenbach2add87a2005-05-16 21:54:10 -070014
Patrick Boettcher382c5542009-02-23 06:27:16 -030015static int irq_chk_intv = 100;
Patrick Boettcher64221be2005-07-07 17:57:49 -070016module_param(irq_chk_intv, int, 0644);
Patrick Boettcher382c5542009-02-23 06:27:16 -030017MODULE_PARM_DESC(irq_chk_intv, "set the interval for IRQ streaming watchdog.");
Patrick Boettcher64221be2005-07-07 17:57:49 -070018
Johannes Stezenbach2add87a2005-05-16 21:54:10 -070019#ifdef CONFIG_DVB_B2C2_FLEXCOP_DEBUG
20#define dprintk(level,args...) \
21 do { if ((debug & level)) printk(args); } while (0)
22#define DEBSTATUS ""
23#else
24#define dprintk(level,args...)
25#define DEBSTATUS " (debugging is not enabled)"
26#endif
27
Uwe Bugla91b94362009-03-29 08:13:01 -030028#define deb_info(args...) dprintk(0x01, args)
29#define deb_reg(args...) dprintk(0x02, args)
30#define deb_ts(args...) dprintk(0x04, args)
31#define deb_irq(args...) dprintk(0x08, args)
32#define deb_chk(args...) dprintk(0x10, args)
Johannes Stezenbach2add87a2005-05-16 21:54:10 -070033
Douglas Schilling Landgrafff699e62008-04-22 14:41:48 -030034static int debug;
Johannes Stezenbach2add87a2005-05-16 21:54:10 -070035module_param(debug, int, 0644);
Patrick Boettcher382c5542009-02-23 06:27:16 -030036MODULE_PARM_DESC(debug,
37 "set debug level (1=info,2=regs,4=TS,8=irqdma,16=check (|-able))."
Uwe Bugla91b94362009-03-29 08:13:01 -030038 DEBSTATUS);
Johannes Stezenbach2add87a2005-05-16 21:54:10 -070039
40#define DRIVER_VERSION "0.1"
41#define DRIVER_NAME "Technisat/B2C2 FlexCop II/IIb/III Digital TV PCI Driver"
42#define DRIVER_AUTHOR "Patrick Boettcher <patrick.boettcher@desy.de>"
43
44struct flexcop_pci {
45 struct pci_dev *pdev;
46
47#define FC_PCI_INIT 0x01
48#define FC_PCI_DMA_INIT 0x02
49 int init_state;
50
51 void __iomem *io_mem;
52 u32 irq;
Uwe Bugla91b94362009-03-29 08:13:01 -030053 /* buffersize (at least for DMA1, need to be % 188 == 0,
54 * this logic is required */
Johannes Stezenbach2add87a2005-05-16 21:54:10 -070055#define FC_DEFAULT_DMA1_BUFSIZE (1280 * 188)
56#define FC_DEFAULT_DMA2_BUFSIZE (10 * 188)
57 struct flexcop_dma dma[2];
58
59 int active_dma1_addr; /* 0 = addr0 of dma1; 1 = addr1 of dma1 */
Uwe Bugla91b94362009-03-29 08:13:01 -030060 u32 last_dma1_cur_pos;
61 /* position of the pointer last time the timer/packet irq occured */
Johannes Stezenbachc4ee3fd2005-05-16 21:54:15 -070062 int count;
Patrick Boettcher382c5542009-02-23 06:27:16 -030063 int count_prev;
64 int stream_problem;
Johannes Stezenbach2add87a2005-05-16 21:54:10 -070065
Johannes Stezenbach4853f162005-05-16 21:54:15 -070066 spinlock_t irq_lock;
Patrick Boettcher64221be2005-07-07 17:57:49 -070067 unsigned long last_irq;
68
David Howellsc4028952006-11-22 14:57:56 +000069 struct delayed_work irq_check_work;
Johannes Stezenbach2add87a2005-05-16 21:54:10 -070070 struct flexcop_device *fc_dev;
71};
72
Uwe Bugla91b94362009-03-29 08:13:01 -030073static int lastwreg, lastwval, lastrreg, lastrval;
Johannes Stezenbach2add87a2005-05-16 21:54:10 -070074
Uwe Bugla91b94362009-03-29 08:13:01 -030075static flexcop_ibi_value flexcop_pci_read_ibi_reg(struct flexcop_device *fc,
76 flexcop_ibi_register r)
Johannes Stezenbach2add87a2005-05-16 21:54:10 -070077{
78 struct flexcop_pci *fc_pci = fc->bus_specific;
79 flexcop_ibi_value v;
80 v.raw = readl(fc_pci->io_mem + r);
81
82 if (lastrreg != r || lastrval != v.raw) {
83 lastrreg = r; lastrval = v.raw;
Uwe Bugla91b94362009-03-29 08:13:01 -030084 deb_reg("new rd: %3x: %08x\n", r, v.raw);
Johannes Stezenbach2add87a2005-05-16 21:54:10 -070085 }
86
87 return v;
88}
89
Uwe Bugla91b94362009-03-29 08:13:01 -030090static int flexcop_pci_write_ibi_reg(struct flexcop_device *fc,
91 flexcop_ibi_register r, flexcop_ibi_value v)
Johannes Stezenbach2add87a2005-05-16 21:54:10 -070092{
93 struct flexcop_pci *fc_pci = fc->bus_specific;
94
95 if (lastwreg != r || lastwval != v.raw) {
96 lastwreg = r; lastwval = v.raw;
Uwe Bugla91b94362009-03-29 08:13:01 -030097 deb_reg("new wr: %3x: %08x\n", r, v.raw);
Johannes Stezenbach2add87a2005-05-16 21:54:10 -070098 }
99
100 writel(v.raw, fc_pci->io_mem + r);
101 return 0;
102}
103
David Howellsc4028952006-11-22 14:57:56 +0000104static void flexcop_pci_irq_check_work(struct work_struct *work)
Patrick Boettcher64221be2005-07-07 17:57:49 -0700105{
David Howellsc4028952006-11-22 14:57:56 +0000106 struct flexcop_pci *fc_pci =
107 container_of(work, struct flexcop_pci, irq_check_work.work);
Patrick Boettcher64221be2005-07-07 17:57:49 -0700108 struct flexcop_device *fc = fc_pci->fc_dev;
109
Patrick Boettcher382c5542009-02-23 06:27:16 -0300110 if (fc->feedcount) {
Patrick Boettcher64221be2005-07-07 17:57:49 -0700111
Patrick Boettcher382c5542009-02-23 06:27:16 -0300112 if (fc_pci->count == fc_pci->count_prev) {
113 deb_chk("no IRQ since the last check\n");
114 if (fc_pci->stream_problem++ == 3) {
115 struct dvb_demux_feed *feed;
Matthias Schwarzotta27e4fd2009-03-10 13:55:14 -0300116 deb_info("flexcop-pci: stream problem, resetting pid filter\n");
Patrick Boettcher64221be2005-07-07 17:57:49 -0700117
Patrick Boettcher382c5542009-02-23 06:27:16 -0300118 spin_lock_irq(&fc->demux.lock);
119 list_for_each_entry(feed, &fc->demux.feed_list,
Uwe Bugla91b94362009-03-29 08:13:01 -0300120 list_head) {
Patrick Boettcher382c5542009-02-23 06:27:16 -0300121 flexcop_pid_feed_control(fc, feed, 0);
122 }
123
124 list_for_each_entry(feed, &fc->demux.feed_list,
Uwe Bugla91b94362009-03-29 08:13:01 -0300125 list_head) {
Patrick Boettcher382c5542009-02-23 06:27:16 -0300126 flexcop_pid_feed_control(fc, feed, 1);
127 }
128 spin_unlock_irq(&fc->demux.lock);
129
130 fc_pci->stream_problem = 0;
131 }
132 } else {
133 fc_pci->stream_problem = 0;
134 fc_pci->count_prev = fc_pci->count;
135 }
136 }
Patrick Boettcher64221be2005-07-07 17:57:49 -0700137
138 schedule_delayed_work(&fc_pci->irq_check_work,
139 msecs_to_jiffies(irq_chk_intv < 100 ? 100 : irq_chk_intv));
140}
141
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700142/* When PID filtering is turned on, we use the timer IRQ, because small amounts
143 * of data need to be passed to the user space instantly as well. When PID
144 * filtering is turned off, we use the page-change-IRQ */
David Howells7d12e782006-10-05 14:55:46 +0100145static irqreturn_t flexcop_pci_isr(int irq, void *dev_id)
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700146{
147 struct flexcop_pci *fc_pci = dev_id;
148 struct flexcop_device *fc = fc_pci->fc_dev;
Hendrik Borghorst4f210e02007-04-05 14:28:11 -0300149 unsigned long flags;
Patrick Boettcher64221be2005-07-07 17:57:49 -0700150 flexcop_ibi_value v;
Johannes Stezenbach4853f162005-05-16 21:54:15 -0700151 irqreturn_t ret = IRQ_HANDLED;
152
Uwe Bugla91b94362009-03-29 08:13:01 -0300153 spin_lock_irqsave(&fc_pci->irq_lock, flags);
154 v = fc->read_ibi_reg(fc, irq_20c);
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700155
Uwe Bugla91b94362009-03-29 08:13:01 -0300156 /* errors */
Patrick Boettcher64221be2005-07-07 17:57:49 -0700157 if (v.irq_20c.Data_receiver_error)
158 deb_chk("data receiver error\n");
159 if (v.irq_20c.Continuity_error_flag)
160 deb_chk("Contunuity error flag is set\n");
161 if (v.irq_20c.LLC_SNAP_FLAG_set)
162 deb_chk("LLC_SNAP_FLAG_set is set\n");
163 if (v.irq_20c.Transport_Error)
164 deb_chk("Transport error\n");
165
166 if ((fc_pci->count % 1000) == 0)
Uwe Bugla91b94362009-03-29 08:13:01 -0300167 deb_chk("%d valid irq took place so far\n", fc_pci->count);
Patrick Boettcher64221be2005-07-07 17:57:49 -0700168
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700169 if (v.irq_20c.DMA1_IRQ_Status == 1) {
170 if (fc_pci->active_dma1_addr == 0)
Uwe Bugla91b94362009-03-29 08:13:01 -0300171 flexcop_pass_dmx_packets(fc_pci->fc_dev,
172 fc_pci->dma[0].cpu_addr0,
173 fc_pci->dma[0].size / 188);
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700174 else
Uwe Bugla91b94362009-03-29 08:13:01 -0300175 flexcop_pass_dmx_packets(fc_pci->fc_dev,
176 fc_pci->dma[0].cpu_addr1,
177 fc_pci->dma[0].size / 188);
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700178
179 deb_irq("page change to page: %d\n",!fc_pci->active_dma1_addr);
180 fc_pci->active_dma1_addr = !fc_pci->active_dma1_addr;
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700181 /* for the timer IRQ we only can use buffer dmx feeding, because we don't have
182 * complete TS packets when reading from the DMA memory */
Uwe Bugla91b94362009-03-29 08:13:01 -0300183 } else if (v.irq_20c.DMA1_Timer_Status == 1) {
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700184 dma_addr_t cur_addr =
185 fc->read_ibi_reg(fc,dma1_008).dma_0x8.dma_cur_addr << 2;
186 u32 cur_pos = cur_addr - fc_pci->dma[0].dma_addr0;
187
Uwe Bugla91b94362009-03-29 08:13:01 -0300188 deb_irq("%u irq: %08x cur_addr: %llx: cur_pos: %08x, "
189 "last_cur_pos: %08x ",
Randy Dunlap608268b2006-01-23 10:01:59 -0200190 jiffies_to_usecs(jiffies - fc_pci->last_irq),
191 v.raw, (unsigned long long)cur_addr, cur_pos,
192 fc_pci->last_dma1_cur_pos);
Patrick Boettcher64221be2005-07-07 17:57:49 -0700193 fc_pci->last_irq = jiffies;
Johannes Stezenbachc4ee3fd2005-05-16 21:54:15 -0700194
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700195 /* buffer end was reached, restarted from the beginning
196 * pass the data from last_cur_pos to the buffer end to the demux
197 */
198 if (cur_pos < fc_pci->last_dma1_cur_pos) {
Uwe Bugla91b94362009-03-29 08:13:01 -0300199 deb_irq(" end was reached: passing %d bytes ",
200 (fc_pci->dma[0].size*2 - 1) -
201 fc_pci->last_dma1_cur_pos);
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700202 flexcop_pass_dmx_data(fc_pci->fc_dev,
Uwe Bugla91b94362009-03-29 08:13:01 -0300203 fc_pci->dma[0].cpu_addr0 +
204 fc_pci->last_dma1_cur_pos,
205 (fc_pci->dma[0].size*2) -
206 fc_pci->last_dma1_cur_pos);
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700207 fc_pci->last_dma1_cur_pos = 0;
208 }
209
210 if (cur_pos > fc_pci->last_dma1_cur_pos) {
Uwe Bugla91b94362009-03-29 08:13:01 -0300211 deb_irq(" passing %d bytes ",
212 cur_pos - fc_pci->last_dma1_cur_pos);
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700213 flexcop_pass_dmx_data(fc_pci->fc_dev,
Uwe Bugla91b94362009-03-29 08:13:01 -0300214 fc_pci->dma[0].cpu_addr0 +
215 fc_pci->last_dma1_cur_pos,
216 cur_pos - fc_pci->last_dma1_cur_pos);
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700217 }
Johannes Stezenbachc4ee3fd2005-05-16 21:54:15 -0700218 deb_irq("\n");
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700219
220 fc_pci->last_dma1_cur_pos = cur_pos;
Patrick Boettcher64221be2005-07-07 17:57:49 -0700221 fc_pci->count++;
222 } else {
Uwe Bugla91b94362009-03-29 08:13:01 -0300223 deb_irq("isr for flexcop called, "
224 "apparently without reason (%08x)\n", v.raw);
Johannes Stezenbach4853f162005-05-16 21:54:15 -0700225 ret = IRQ_NONE;
Patrick Boettcher64221be2005-07-07 17:57:49 -0700226 }
Johannes Stezenbach4853f162005-05-16 21:54:15 -0700227
Uwe Bugla91b94362009-03-29 08:13:01 -0300228 spin_unlock_irqrestore(&fc_pci->irq_lock, flags);
Johannes Stezenbach4853f162005-05-16 21:54:15 -0700229 return ret;
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700230}
231
232static int flexcop_pci_stream_control(struct flexcop_device *fc, int onoff)
233{
234 struct flexcop_pci *fc_pci = fc->bus_specific;
235 if (onoff) {
Uwe Bugla91b94362009-03-29 08:13:01 -0300236 flexcop_dma_config(fc, &fc_pci->dma[0], FC_DMA_1);
237 flexcop_dma_config(fc, &fc_pci->dma[1], FC_DMA_2);
238 flexcop_dma_config_timer(fc, FC_DMA_1, 0);
239 flexcop_dma_xfer_control(fc, FC_DMA_1,
240 FC_DMA_SUBADDR_0 | FC_DMA_SUBADDR_1, 1);
Patrick Boettcher64221be2005-07-07 17:57:49 -0700241 deb_irq("DMA xfer enabled\n");
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700242
Patrick Boettcher64221be2005-07-07 17:57:49 -0700243 fc_pci->last_dma1_cur_pos = 0;
Uwe Bugla91b94362009-03-29 08:13:01 -0300244 flexcop_dma_control_timer_irq(fc, FC_DMA_1, 1);
Patrick Boettcher64221be2005-07-07 17:57:49 -0700245 deb_irq("IRQ enabled\n");
Patrick Boettcher382c5542009-02-23 06:27:16 -0300246 fc_pci->count_prev = fc_pci->count;
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700247 } else {
Uwe Bugla91b94362009-03-29 08:13:01 -0300248 flexcop_dma_control_timer_irq(fc, FC_DMA_1, 0);
Patrick Boettcher64221be2005-07-07 17:57:49 -0700249 deb_irq("IRQ disabled\n");
250
Uwe Bugla91b94362009-03-29 08:13:01 -0300251 flexcop_dma_xfer_control(fc, FC_DMA_1,
252 FC_DMA_SUBADDR_0 | FC_DMA_SUBADDR_1, 0);
Patrick Boettcher64221be2005-07-07 17:57:49 -0700253 deb_irq("DMA xfer disabled\n");
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700254 }
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700255 return 0;
256}
257
258static int flexcop_pci_dma_init(struct flexcop_pci *fc_pci)
259{
260 int ret;
Uwe Bugla91b94362009-03-29 08:13:01 -0300261 ret = flexcop_dma_allocate(fc_pci->pdev, &fc_pci->dma[0],
262 FC_DEFAULT_DMA1_BUFSIZE);
263 if (ret != 0)
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700264 return ret;
265
Uwe Bugla91b94362009-03-29 08:13:01 -0300266 ret = flexcop_dma_allocate(fc_pci->pdev, &fc_pci->dma[1],
267 FC_DEFAULT_DMA2_BUFSIZE);
268 if (ret != 0) {
Trent Piepho83977032006-05-12 20:36:24 -0300269 flexcop_dma_free(&fc_pci->dma[0]);
270 return ret;
271 }
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700272
Uwe Bugla91b94362009-03-29 08:13:01 -0300273 flexcop_sram_set_dest(fc_pci->fc_dev, FC_SRAM_DEST_MEDIA |
274 FC_SRAM_DEST_NET, FC_SRAM_DEST_TARGET_DMA1);
275 flexcop_sram_set_dest(fc_pci->fc_dev, FC_SRAM_DEST_CAO |
276 FC_SRAM_DEST_CAI, FC_SRAM_DEST_TARGET_DMA2);
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700277 fc_pci->init_state |= FC_PCI_DMA_INIT;
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700278 return ret;
279}
280
281static void flexcop_pci_dma_exit(struct flexcop_pci *fc_pci)
282{
283 if (fc_pci->init_state & FC_PCI_DMA_INIT) {
284 flexcop_dma_free(&fc_pci->dma[0]);
285 flexcop_dma_free(&fc_pci->dma[1]);
286 }
287 fc_pci->init_state &= ~FC_PCI_DMA_INIT;
288}
289
290static int flexcop_pci_init(struct flexcop_pci *fc_pci)
291{
292 int ret;
293 u8 card_rev;
294
295 pci_read_config_byte(fc_pci->pdev, PCI_CLASS_REVISION, &card_rev);
296 info("card revision %x", card_rev);
297
298 if ((ret = pci_enable_device(fc_pci->pdev)) != 0)
299 return ret;
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700300 pci_set_master(fc_pci->pdev);
301
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700302 if ((ret = pci_request_regions(fc_pci->pdev, DRIVER_NAME)) != 0)
303 goto err_pci_disable_device;
304
305 fc_pci->io_mem = pci_iomap(fc_pci->pdev, 0, 0x800);
306
307 if (!fc_pci->io_mem) {
308 err("cannot map io memory\n");
309 ret = -EIO;
310 goto err_pci_release_regions;
311 }
312
313 pci_set_drvdata(fc_pci->pdev, fc_pci);
Hendrik Borghorst4f210e02007-04-05 14:28:11 -0300314 spin_lock_init(&fc_pci->irq_lock);
Patrick Boettcher64221be2005-07-07 17:57:49 -0700315 if ((ret = request_irq(fc_pci->pdev->irq, flexcop_pci_isr,
Thomas Gleixner8076fe32006-07-01 19:29:37 -0700316 IRQF_SHARED, DRIVER_NAME, fc_pci)) != 0)
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700317 goto err_pci_iounmap;
318
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700319 fc_pci->init_state |= FC_PCI_INIT;
Trent Piepho83977032006-05-12 20:36:24 -0300320 return ret;
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700321
322err_pci_iounmap:
323 pci_iounmap(fc_pci->pdev, fc_pci->io_mem);
324 pci_set_drvdata(fc_pci->pdev, NULL);
325err_pci_release_regions:
326 pci_release_regions(fc_pci->pdev);
327err_pci_disable_device:
328 pci_disable_device(fc_pci->pdev);
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700329 return ret;
330}
331
332static void flexcop_pci_exit(struct flexcop_pci *fc_pci)
333{
334 if (fc_pci->init_state & FC_PCI_INIT) {
335 free_irq(fc_pci->pdev->irq, fc_pci);
336 pci_iounmap(fc_pci->pdev, fc_pci->io_mem);
337 pci_set_drvdata(fc_pci->pdev, NULL);
338 pci_release_regions(fc_pci->pdev);
339 pci_disable_device(fc_pci->pdev);
340 }
341 fc_pci->init_state &= ~FC_PCI_INIT;
342}
343
Uwe Bugla91b94362009-03-29 08:13:01 -0300344static int flexcop_pci_probe(struct pci_dev *pdev,
345 const struct pci_device_id *ent)
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700346{
347 struct flexcop_device *fc;
348 struct flexcop_pci *fc_pci;
349 int ret = -ENOMEM;
350
351 if ((fc = flexcop_device_kmalloc(sizeof(struct flexcop_pci))) == NULL) {
352 err("out of memory\n");
353 return -ENOMEM;
354 }
355
Uwe Bugla91b94362009-03-29 08:13:01 -0300356 /* general flexcop init */
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700357 fc_pci = fc->bus_specific;
358 fc_pci->fc_dev = fc;
359
360 fc->read_ibi_reg = flexcop_pci_read_ibi_reg;
361 fc->write_ibi_reg = flexcop_pci_write_ibi_reg;
362 fc->i2c_request = flexcop_i2c_request;
363 fc->get_mac_addr = flexcop_eeprom_check_mac_addr;
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700364 fc->stream_control = flexcop_pci_stream_control;
365
Johannes Stezenbachc4ee3fd2005-05-16 21:54:15 -0700366 if (enable_pid_filtering)
367 info("will use the HW PID filter.");
368 else
369 info("will pass the complete TS to the demuxer.");
370
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700371 fc->pid_filtering = enable_pid_filtering;
372 fc->bus_type = FC_PCI;
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700373 fc->dev = &pdev->dev;
Johannes Stezenbach59a7ad62005-05-16 21:54:16 -0700374 fc->owner = THIS_MODULE;
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700375
Uwe Bugla91b94362009-03-29 08:13:01 -0300376 /* bus specific part */
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700377 fc_pci->pdev = pdev;
378 if ((ret = flexcop_pci_init(fc_pci)) != 0)
379 goto err_kfree;
380
Uwe Bugla91b94362009-03-29 08:13:01 -0300381 /* init flexcop */
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700382 if ((ret = flexcop_device_initialize(fc)) != 0)
383 goto err_pci_exit;
384
Uwe Bugla91b94362009-03-29 08:13:01 -0300385 /* init dma */
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700386 if ((ret = flexcop_pci_dma_init(fc_pci)) != 0)
387 goto err_fc_exit;
388
David Howellsc4028952006-11-22 14:57:56 +0000389 INIT_DELAYED_WORK(&fc_pci->irq_check_work, flexcop_pci_irq_check_work);
Patrick Boettcher64221be2005-07-07 17:57:49 -0700390
Uwe Bugla91b94362009-03-29 08:13:01 -0300391 if (irq_chk_intv > 0)
392 schedule_delayed_work(&fc_pci->irq_check_work,
393 msecs_to_jiffies(irq_chk_intv < 100 ?
394 100 :
395 irq_chk_intv));
Trent Piepho83977032006-05-12 20:36:24 -0300396 return ret;
397
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700398err_fc_exit:
399 flexcop_device_exit(fc);
400err_pci_exit:
401 flexcop_pci_exit(fc_pci);
402err_kfree:
403 flexcop_device_kfree(fc);
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700404 return ret;
405}
406
407/* in theory every _exit function should be called exactly two times,
408 * here and in the bail-out-part of the _init-function
409 */
410static void flexcop_pci_remove(struct pci_dev *pdev)
411{
412 struct flexcop_pci *fc_pci = pci_get_drvdata(pdev);
413
Patrick Boettcher382c5542009-02-23 06:27:16 -0300414 if (irq_chk_intv > 0)
415 cancel_delayed_work(&fc_pci->irq_check_work);
416
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700417 flexcop_pci_dma_exit(fc_pci);
418 flexcop_device_exit(fc_pci->fc_dev);
419 flexcop_pci_exit(fc_pci);
420 flexcop_device_kfree(fc_pci->fc_dev);
421}
422
423static struct pci_device_id flexcop_pci_tbl[] = {
424 { PCI_DEVICE(0x13d0, 0x2103) },
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700425 { },
426};
427
428MODULE_DEVICE_TABLE(pci, flexcop_pci_tbl);
429
430static struct pci_driver flexcop_pci_driver = {
Patrick Boettcher63b5c1c2005-07-07 17:58:30 -0700431 .name = "b2c2_flexcop_pci",
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700432 .id_table = flexcop_pci_tbl,
Patrick Boettcher64221be2005-07-07 17:57:49 -0700433 .probe = flexcop_pci_probe,
434 .remove = flexcop_pci_remove,
Johannes Stezenbach2add87a2005-05-16 21:54:10 -0700435};
436
437static int __init flexcop_pci_module_init(void)
438{
439 return pci_register_driver(&flexcop_pci_driver);
440}
441
442static void __exit flexcop_pci_module_exit(void)
443{
444 pci_unregister_driver(&flexcop_pci_driver);
445}
446
447module_init(flexcop_pci_module_init);
448module_exit(flexcop_pci_module_exit);
449
450MODULE_AUTHOR(DRIVER_AUTHOR);
451MODULE_DESCRIPTION(DRIVER_NAME);
452MODULE_LICENSE("GPL");