Johannes Stezenbach | 2add87a | 2005-05-16 21:54:10 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of linux driver the digital TV devices equipped with B2C2 FlexcopII(b)/III |
| 3 | * |
| 4 | * flexcop-pci.c - covers the PCI part including DMA transfers. |
| 5 | * |
| 6 | * see flexcop.c for copyright information. |
| 7 | */ |
| 8 | |
| 9 | #define FC_LOG_PREFIX "flexcop-pci" |
| 10 | #include "flexcop-common.h" |
| 11 | |
Johannes Stezenbach | c4ee3fd | 2005-05-16 21:54:15 -0700 | [diff] [blame] | 12 | static int enable_pid_filtering = 1; |
Johannes Stezenbach | 2add87a | 2005-05-16 21:54:10 -0700 | [diff] [blame] | 13 | module_param(enable_pid_filtering, int, 0444); |
| 14 | MODULE_PARM_DESC(enable_pid_filtering, "enable hardware pid filtering: supported values: 0 (fullts), 1"); |
| 15 | |
Patrick Boettcher | 382c554 | 2009-02-23 06:27:16 -0300 | [diff] [blame^] | 16 | static int irq_chk_intv = 100; |
Patrick Boettcher | 64221be | 2005-07-07 17:57:49 -0700 | [diff] [blame] | 17 | module_param(irq_chk_intv, int, 0644); |
Patrick Boettcher | 382c554 | 2009-02-23 06:27:16 -0300 | [diff] [blame^] | 18 | MODULE_PARM_DESC(irq_chk_intv, "set the interval for IRQ streaming watchdog."); |
Patrick Boettcher | 64221be | 2005-07-07 17:57:49 -0700 | [diff] [blame] | 19 | |
Johannes Stezenbach | 2add87a | 2005-05-16 21:54:10 -0700 | [diff] [blame] | 20 | #ifdef CONFIG_DVB_B2C2_FLEXCOP_DEBUG |
| 21 | #define dprintk(level,args...) \ |
| 22 | do { if ((debug & level)) printk(args); } while (0) |
| 23 | #define DEBSTATUS "" |
| 24 | #else |
| 25 | #define dprintk(level,args...) |
| 26 | #define DEBSTATUS " (debugging is not enabled)" |
| 27 | #endif |
| 28 | |
| 29 | #define deb_info(args...) dprintk(0x01,args) |
| 30 | #define deb_reg(args...) dprintk(0x02,args) |
| 31 | #define deb_ts(args...) dprintk(0x04,args) |
| 32 | #define deb_irq(args...) dprintk(0x08,args) |
Patrick Boettcher | 64221be | 2005-07-07 17:57:49 -0700 | [diff] [blame] | 33 | #define deb_chk(args...) dprintk(0x10,args) |
Johannes Stezenbach | 2add87a | 2005-05-16 21:54:10 -0700 | [diff] [blame] | 34 | |
Douglas Schilling Landgraf | ff699e6 | 2008-04-22 14:41:48 -0300 | [diff] [blame] | 35 | static int debug; |
Johannes Stezenbach | 2add87a | 2005-05-16 21:54:10 -0700 | [diff] [blame] | 36 | module_param(debug, int, 0644); |
Patrick Boettcher | 382c554 | 2009-02-23 06:27:16 -0300 | [diff] [blame^] | 37 | MODULE_PARM_DESC(debug, |
| 38 | "set debug level (1=info,2=regs,4=TS,8=irqdma,16=check (|-able))." |
| 39 | DEBSTATUS); |
Johannes Stezenbach | 2add87a | 2005-05-16 21:54:10 -0700 | [diff] [blame] | 40 | |
| 41 | #define DRIVER_VERSION "0.1" |
| 42 | #define DRIVER_NAME "Technisat/B2C2 FlexCop II/IIb/III Digital TV PCI Driver" |
| 43 | #define DRIVER_AUTHOR "Patrick Boettcher <patrick.boettcher@desy.de>" |
| 44 | |
| 45 | struct flexcop_pci { |
| 46 | struct pci_dev *pdev; |
| 47 | |
| 48 | #define FC_PCI_INIT 0x01 |
| 49 | #define FC_PCI_DMA_INIT 0x02 |
| 50 | int init_state; |
| 51 | |
| 52 | void __iomem *io_mem; |
| 53 | u32 irq; |
| 54 | /* buffersize (at least for DMA1, need to be % 188 == 0, |
Johannes Stezenbach | c4ee3fd | 2005-05-16 21:54:15 -0700 | [diff] [blame] | 55 | * this logic is required */ |
Johannes Stezenbach | 2add87a | 2005-05-16 21:54:10 -0700 | [diff] [blame] | 56 | #define FC_DEFAULT_DMA1_BUFSIZE (1280 * 188) |
| 57 | #define FC_DEFAULT_DMA2_BUFSIZE (10 * 188) |
| 58 | struct flexcop_dma dma[2]; |
| 59 | |
| 60 | int active_dma1_addr; /* 0 = addr0 of dma1; 1 = addr1 of dma1 */ |
| 61 | u32 last_dma1_cur_pos; /* position of the pointer last time the timer/packet irq occured */ |
Johannes Stezenbach | c4ee3fd | 2005-05-16 21:54:15 -0700 | [diff] [blame] | 62 | int count; |
Patrick Boettcher | 382c554 | 2009-02-23 06:27:16 -0300 | [diff] [blame^] | 63 | int count_prev; |
| 64 | int stream_problem; |
Johannes Stezenbach | 2add87a | 2005-05-16 21:54:10 -0700 | [diff] [blame] | 65 | |
Johannes Stezenbach | 4853f16 | 2005-05-16 21:54:15 -0700 | [diff] [blame] | 66 | spinlock_t irq_lock; |
| 67 | |
Patrick Boettcher | 64221be | 2005-07-07 17:57:49 -0700 | [diff] [blame] | 68 | unsigned long last_irq; |
| 69 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 70 | struct delayed_work irq_check_work; |
Patrick Boettcher | 64221be | 2005-07-07 17:57:49 -0700 | [diff] [blame] | 71 | |
Johannes Stezenbach | 2add87a | 2005-05-16 21:54:10 -0700 | [diff] [blame] | 72 | struct flexcop_device *fc_dev; |
| 73 | }; |
| 74 | |
| 75 | static int lastwreg,lastwval,lastrreg,lastrval; |
| 76 | |
| 77 | static flexcop_ibi_value flexcop_pci_read_ibi_reg (struct flexcop_device *fc, flexcop_ibi_register r) |
| 78 | { |
| 79 | struct flexcop_pci *fc_pci = fc->bus_specific; |
| 80 | flexcop_ibi_value v; |
| 81 | v.raw = readl(fc_pci->io_mem + r); |
| 82 | |
| 83 | if (lastrreg != r || lastrval != v.raw) { |
| 84 | lastrreg = r; lastrval = v.raw; |
| 85 | deb_reg("new rd: %3x: %08x\n",r,v.raw); |
| 86 | } |
| 87 | |
| 88 | return v; |
| 89 | } |
| 90 | |
| 91 | static int flexcop_pci_write_ibi_reg(struct flexcop_device *fc, flexcop_ibi_register r, flexcop_ibi_value v) |
| 92 | { |
| 93 | struct flexcop_pci *fc_pci = fc->bus_specific; |
| 94 | |
| 95 | if (lastwreg != r || lastwval != v.raw) { |
| 96 | lastwreg = r; lastwval = v.raw; |
| 97 | deb_reg("new wr: %3x: %08x\n",r,v.raw); |
| 98 | } |
| 99 | |
| 100 | writel(v.raw, fc_pci->io_mem + r); |
| 101 | return 0; |
| 102 | } |
| 103 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 104 | static void flexcop_pci_irq_check_work(struct work_struct *work) |
Patrick Boettcher | 64221be | 2005-07-07 17:57:49 -0700 | [diff] [blame] | 105 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 106 | struct flexcop_pci *fc_pci = |
| 107 | container_of(work, struct flexcop_pci, irq_check_work.work); |
Patrick Boettcher | 64221be | 2005-07-07 17:57:49 -0700 | [diff] [blame] | 108 | struct flexcop_device *fc = fc_pci->fc_dev; |
| 109 | |
Patrick Boettcher | 382c554 | 2009-02-23 06:27:16 -0300 | [diff] [blame^] | 110 | if (fc->feedcount) { |
Patrick Boettcher | 64221be | 2005-07-07 17:57:49 -0700 | [diff] [blame] | 111 | |
Patrick Boettcher | 382c554 | 2009-02-23 06:27:16 -0300 | [diff] [blame^] | 112 | 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; |
Patrick Boettcher | 64221be | 2005-07-07 17:57:49 -0700 | [diff] [blame] | 116 | |
Patrick Boettcher | 382c554 | 2009-02-23 06:27:16 -0300 | [diff] [blame^] | 117 | spin_lock_irq(&fc->demux.lock); |
| 118 | list_for_each_entry(feed, &fc->demux.feed_list, |
| 119 | list_head) { |
| 120 | flexcop_pid_feed_control(fc, feed, 0); |
| 121 | } |
| 122 | |
| 123 | list_for_each_entry(feed, &fc->demux.feed_list, |
| 124 | list_head) { |
| 125 | flexcop_pid_feed_control(fc, feed, 1); |
| 126 | } |
| 127 | spin_unlock_irq(&fc->demux.lock); |
| 128 | |
| 129 | fc_pci->stream_problem = 0; |
| 130 | } |
| 131 | } else { |
| 132 | fc_pci->stream_problem = 0; |
| 133 | fc_pci->count_prev = fc_pci->count; |
| 134 | } |
| 135 | } |
Patrick Boettcher | 64221be | 2005-07-07 17:57:49 -0700 | [diff] [blame] | 136 | |
| 137 | schedule_delayed_work(&fc_pci->irq_check_work, |
| 138 | msecs_to_jiffies(irq_chk_intv < 100 ? 100 : irq_chk_intv)); |
| 139 | } |
| 140 | |
Johannes Stezenbach | 2add87a | 2005-05-16 21:54:10 -0700 | [diff] [blame] | 141 | /* When PID filtering is turned on, we use the timer IRQ, because small amounts |
| 142 | * of data need to be passed to the user space instantly as well. When PID |
| 143 | * filtering is turned off, we use the page-change-IRQ */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 144 | static irqreturn_t flexcop_pci_isr(int irq, void *dev_id) |
Johannes Stezenbach | 2add87a | 2005-05-16 21:54:10 -0700 | [diff] [blame] | 145 | { |
| 146 | struct flexcop_pci *fc_pci = dev_id; |
| 147 | struct flexcop_device *fc = fc_pci->fc_dev; |
Hendrik Borghorst | 4f210e0 | 2007-04-05 14:28:11 -0300 | [diff] [blame] | 148 | unsigned long flags; |
Patrick Boettcher | 64221be | 2005-07-07 17:57:49 -0700 | [diff] [blame] | 149 | flexcop_ibi_value v; |
Johannes Stezenbach | 4853f16 | 2005-05-16 21:54:15 -0700 | [diff] [blame] | 150 | irqreturn_t ret = IRQ_HANDLED; |
| 151 | |
Hendrik Borghorst | 4f210e0 | 2007-04-05 14:28:11 -0300 | [diff] [blame] | 152 | spin_lock_irqsave(&fc_pci->irq_lock,flags); |
Johannes Stezenbach | 2add87a | 2005-05-16 21:54:10 -0700 | [diff] [blame] | 153 | |
Patrick Boettcher | 64221be | 2005-07-07 17:57:49 -0700 | [diff] [blame] | 154 | v = fc->read_ibi_reg(fc,irq_20c); |
| 155 | |
| 156 | /* errors */ |
| 157 | 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) |
| 167 | deb_chk("%d valid irq took place so far\n",fc_pci->count); |
| 168 | |
Johannes Stezenbach | 2add87a | 2005-05-16 21:54:10 -0700 | [diff] [blame] | 169 | if (v.irq_20c.DMA1_IRQ_Status == 1) { |
| 170 | if (fc_pci->active_dma1_addr == 0) |
| 171 | flexcop_pass_dmx_packets(fc_pci->fc_dev,fc_pci->dma[0].cpu_addr0,fc_pci->dma[0].size / 188); |
| 172 | else |
| 173 | flexcop_pass_dmx_packets(fc_pci->fc_dev,fc_pci->dma[0].cpu_addr1,fc_pci->dma[0].size / 188); |
| 174 | |
| 175 | deb_irq("page change to page: %d\n",!fc_pci->active_dma1_addr); |
| 176 | fc_pci->active_dma1_addr = !fc_pci->active_dma1_addr; |
| 177 | } else if (v.irq_20c.DMA1_Timer_Status == 1) { |
| 178 | /* for the timer IRQ we only can use buffer dmx feeding, because we don't have |
| 179 | * complete TS packets when reading from the DMA memory */ |
| 180 | dma_addr_t cur_addr = |
| 181 | fc->read_ibi_reg(fc,dma1_008).dma_0x8.dma_cur_addr << 2; |
| 182 | u32 cur_pos = cur_addr - fc_pci->dma[0].dma_addr0; |
| 183 | |
Randy Dunlap | 608268b | 2006-01-23 10:01:59 -0200 | [diff] [blame] | 184 | deb_irq("%u irq: %08x cur_addr: %llx: cur_pos: %08x, last_cur_pos: %08x ", |
| 185 | jiffies_to_usecs(jiffies - fc_pci->last_irq), |
| 186 | v.raw, (unsigned long long)cur_addr, cur_pos, |
| 187 | fc_pci->last_dma1_cur_pos); |
Patrick Boettcher | 64221be | 2005-07-07 17:57:49 -0700 | [diff] [blame] | 188 | fc_pci->last_irq = jiffies; |
Johannes Stezenbach | c4ee3fd | 2005-05-16 21:54:15 -0700 | [diff] [blame] | 189 | |
Johannes Stezenbach | 2add87a | 2005-05-16 21:54:10 -0700 | [diff] [blame] | 190 | /* buffer end was reached, restarted from the beginning |
| 191 | * pass the data from last_cur_pos to the buffer end to the demux |
| 192 | */ |
| 193 | if (cur_pos < fc_pci->last_dma1_cur_pos) { |
Johannes Stezenbach | c4ee3fd | 2005-05-16 21:54:15 -0700 | [diff] [blame] | 194 | deb_irq(" end was reached: passing %d bytes ",(fc_pci->dma[0].size*2 - 1) - fc_pci->last_dma1_cur_pos); |
Johannes Stezenbach | 2add87a | 2005-05-16 21:54:10 -0700 | [diff] [blame] | 195 | flexcop_pass_dmx_data(fc_pci->fc_dev, |
| 196 | fc_pci->dma[0].cpu_addr0 + fc_pci->last_dma1_cur_pos, |
Johannes Stezenbach | c4ee3fd | 2005-05-16 21:54:15 -0700 | [diff] [blame] | 197 | (fc_pci->dma[0].size*2) - fc_pci->last_dma1_cur_pos); |
Johannes Stezenbach | 2add87a | 2005-05-16 21:54:10 -0700 | [diff] [blame] | 198 | fc_pci->last_dma1_cur_pos = 0; |
| 199 | } |
| 200 | |
| 201 | if (cur_pos > fc_pci->last_dma1_cur_pos) { |
Johannes Stezenbach | c4ee3fd | 2005-05-16 21:54:15 -0700 | [diff] [blame] | 202 | deb_irq(" passing %d bytes ",cur_pos - fc_pci->last_dma1_cur_pos); |
Johannes Stezenbach | 2add87a | 2005-05-16 21:54:10 -0700 | [diff] [blame] | 203 | flexcop_pass_dmx_data(fc_pci->fc_dev, |
| 204 | fc_pci->dma[0].cpu_addr0 + fc_pci->last_dma1_cur_pos, |
| 205 | cur_pos - fc_pci->last_dma1_cur_pos); |
| 206 | } |
Johannes Stezenbach | c4ee3fd | 2005-05-16 21:54:15 -0700 | [diff] [blame] | 207 | deb_irq("\n"); |
Johannes Stezenbach | 2add87a | 2005-05-16 21:54:10 -0700 | [diff] [blame] | 208 | |
| 209 | fc_pci->last_dma1_cur_pos = cur_pos; |
Patrick Boettcher | 64221be | 2005-07-07 17:57:49 -0700 | [diff] [blame] | 210 | fc_pci->count++; |
| 211 | } else { |
| 212 | deb_irq("isr for flexcop called, apparently without reason (%08x)\n",v.raw); |
Johannes Stezenbach | 4853f16 | 2005-05-16 21:54:15 -0700 | [diff] [blame] | 213 | ret = IRQ_NONE; |
Patrick Boettcher | 64221be | 2005-07-07 17:57:49 -0700 | [diff] [blame] | 214 | } |
Johannes Stezenbach | 4853f16 | 2005-05-16 21:54:15 -0700 | [diff] [blame] | 215 | |
Hendrik Borghorst | 4f210e0 | 2007-04-05 14:28:11 -0300 | [diff] [blame] | 216 | spin_unlock_irqrestore(&fc_pci->irq_lock,flags); |
Johannes Stezenbach | 2add87a | 2005-05-16 21:54:10 -0700 | [diff] [blame] | 217 | |
Johannes Stezenbach | 4853f16 | 2005-05-16 21:54:15 -0700 | [diff] [blame] | 218 | return ret; |
Johannes Stezenbach | 2add87a | 2005-05-16 21:54:10 -0700 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | static int flexcop_pci_stream_control(struct flexcop_device *fc, int onoff) |
| 222 | { |
| 223 | struct flexcop_pci *fc_pci = fc->bus_specific; |
| 224 | if (onoff) { |
Patrick Boettcher | 64221be | 2005-07-07 17:57:49 -0700 | [diff] [blame] | 225 | flexcop_dma_config(fc,&fc_pci->dma[0],FC_DMA_1); |
| 226 | flexcop_dma_config(fc,&fc_pci->dma[1],FC_DMA_2); |
Johannes Stezenbach | 2add87a | 2005-05-16 21:54:10 -0700 | [diff] [blame] | 227 | |
Patrick Boettcher | 64221be | 2005-07-07 17:57:49 -0700 | [diff] [blame] | 228 | flexcop_dma_config_timer(fc,FC_DMA_1,0); |
Johannes Stezenbach | 2add87a | 2005-05-16 21:54:10 -0700 | [diff] [blame] | 229 | |
Patrick Boettcher | 64221be | 2005-07-07 17:57:49 -0700 | [diff] [blame] | 230 | flexcop_dma_xfer_control(fc,FC_DMA_1,FC_DMA_SUBADDR_0 | FC_DMA_SUBADDR_1,1); |
| 231 | deb_irq("DMA xfer enabled\n"); |
Johannes Stezenbach | 2add87a | 2005-05-16 21:54:10 -0700 | [diff] [blame] | 232 | |
Patrick Boettcher | 64221be | 2005-07-07 17:57:49 -0700 | [diff] [blame] | 233 | fc_pci->last_dma1_cur_pos = 0; |
| 234 | flexcop_dma_control_timer_irq(fc,FC_DMA_1,1); |
| 235 | deb_irq("IRQ enabled\n"); |
| 236 | |
Patrick Boettcher | 382c554 | 2009-02-23 06:27:16 -0300 | [diff] [blame^] | 237 | fc_pci->count_prev = fc_pci->count; |
| 238 | |
Patrick Boettcher | 64221be | 2005-07-07 17:57:49 -0700 | [diff] [blame] | 239 | // fc_pci->active_dma1_addr = 0; |
| 240 | // flexcop_dma_control_size_irq(fc,FC_DMA_1,1); |
| 241 | |
Johannes Stezenbach | 2add87a | 2005-05-16 21:54:10 -0700 | [diff] [blame] | 242 | } else { |
Patrick Boettcher | 64221be | 2005-07-07 17:57:49 -0700 | [diff] [blame] | 243 | flexcop_dma_control_timer_irq(fc,FC_DMA_1,0); |
| 244 | deb_irq("IRQ disabled\n"); |
| 245 | |
| 246 | // flexcop_dma_control_size_irq(fc,FC_DMA_1,0); |
| 247 | |
| 248 | flexcop_dma_xfer_control(fc,FC_DMA_1,FC_DMA_SUBADDR_0 | FC_DMA_SUBADDR_1,0); |
| 249 | deb_irq("DMA xfer disabled\n"); |
Johannes Stezenbach | 2add87a | 2005-05-16 21:54:10 -0700 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | return 0; |
| 253 | } |
| 254 | |
| 255 | static int flexcop_pci_dma_init(struct flexcop_pci *fc_pci) |
| 256 | { |
| 257 | int ret; |
| 258 | if ((ret = flexcop_dma_allocate(fc_pci->pdev,&fc_pci->dma[0],FC_DEFAULT_DMA1_BUFSIZE)) != 0) |
| 259 | return ret; |
| 260 | |
Trent Piepho | 8397703 | 2006-05-12 20:36:24 -0300 | [diff] [blame] | 261 | if ((ret = flexcop_dma_allocate(fc_pci->pdev,&fc_pci->dma[1],FC_DEFAULT_DMA2_BUFSIZE)) != 0) { |
| 262 | flexcop_dma_free(&fc_pci->dma[0]); |
| 263 | return ret; |
| 264 | } |
Johannes Stezenbach | 2add87a | 2005-05-16 21:54:10 -0700 | [diff] [blame] | 265 | |
| 266 | flexcop_sram_set_dest(fc_pci->fc_dev,FC_SRAM_DEST_MEDIA | FC_SRAM_DEST_NET, FC_SRAM_DEST_TARGET_DMA1); |
| 267 | flexcop_sram_set_dest(fc_pci->fc_dev,FC_SRAM_DEST_CAO | FC_SRAM_DEST_CAI, FC_SRAM_DEST_TARGET_DMA2); |
| 268 | |
| 269 | fc_pci->init_state |= FC_PCI_DMA_INIT; |
Patrick Boettcher | 64221be | 2005-07-07 17:57:49 -0700 | [diff] [blame] | 270 | |
Johannes Stezenbach | 2add87a | 2005-05-16 21:54:10 -0700 | [diff] [blame] | 271 | return ret; |
| 272 | } |
| 273 | |
| 274 | static void flexcop_pci_dma_exit(struct flexcop_pci *fc_pci) |
| 275 | { |
| 276 | if (fc_pci->init_state & FC_PCI_DMA_INIT) { |
| 277 | flexcop_dma_free(&fc_pci->dma[0]); |
| 278 | flexcop_dma_free(&fc_pci->dma[1]); |
| 279 | } |
| 280 | fc_pci->init_state &= ~FC_PCI_DMA_INIT; |
| 281 | } |
| 282 | |
| 283 | static int flexcop_pci_init(struct flexcop_pci *fc_pci) |
| 284 | { |
| 285 | int ret; |
| 286 | u8 card_rev; |
| 287 | |
| 288 | pci_read_config_byte(fc_pci->pdev, PCI_CLASS_REVISION, &card_rev); |
| 289 | info("card revision %x", card_rev); |
| 290 | |
| 291 | if ((ret = pci_enable_device(fc_pci->pdev)) != 0) |
| 292 | return ret; |
| 293 | |
| 294 | pci_set_master(fc_pci->pdev); |
| 295 | |
| 296 | /* enable interrupts */ |
| 297 | // pci_write_config_dword(pdev, 0x6c, 0x8000); |
| 298 | |
| 299 | if ((ret = pci_request_regions(fc_pci->pdev, DRIVER_NAME)) != 0) |
| 300 | goto err_pci_disable_device; |
| 301 | |
| 302 | fc_pci->io_mem = pci_iomap(fc_pci->pdev, 0, 0x800); |
| 303 | |
| 304 | if (!fc_pci->io_mem) { |
| 305 | err("cannot map io memory\n"); |
| 306 | ret = -EIO; |
| 307 | goto err_pci_release_regions; |
| 308 | } |
| 309 | |
| 310 | pci_set_drvdata(fc_pci->pdev, fc_pci); |
Hendrik Borghorst | 4f210e0 | 2007-04-05 14:28:11 -0300 | [diff] [blame] | 311 | spin_lock_init(&fc_pci->irq_lock); |
Patrick Boettcher | 64221be | 2005-07-07 17:57:49 -0700 | [diff] [blame] | 312 | if ((ret = request_irq(fc_pci->pdev->irq, flexcop_pci_isr, |
Thomas Gleixner | 8076fe3 | 2006-07-01 19:29:37 -0700 | [diff] [blame] | 313 | IRQF_SHARED, DRIVER_NAME, fc_pci)) != 0) |
Johannes Stezenbach | 2add87a | 2005-05-16 21:54:10 -0700 | [diff] [blame] | 314 | goto err_pci_iounmap; |
| 315 | |
Johannes Stezenbach | 2add87a | 2005-05-16 21:54:10 -0700 | [diff] [blame] | 316 | fc_pci->init_state |= FC_PCI_INIT; |
Trent Piepho | 8397703 | 2006-05-12 20:36:24 -0300 | [diff] [blame] | 317 | return ret; |
Johannes Stezenbach | 2add87a | 2005-05-16 21:54:10 -0700 | [diff] [blame] | 318 | |
| 319 | err_pci_iounmap: |
| 320 | pci_iounmap(fc_pci->pdev, fc_pci->io_mem); |
| 321 | pci_set_drvdata(fc_pci->pdev, NULL); |
| 322 | err_pci_release_regions: |
| 323 | pci_release_regions(fc_pci->pdev); |
| 324 | err_pci_disable_device: |
| 325 | pci_disable_device(fc_pci->pdev); |
Johannes Stezenbach | 2add87a | 2005-05-16 21:54:10 -0700 | [diff] [blame] | 326 | return ret; |
| 327 | } |
| 328 | |
| 329 | static void flexcop_pci_exit(struct flexcop_pci *fc_pci) |
| 330 | { |
| 331 | if (fc_pci->init_state & FC_PCI_INIT) { |
| 332 | free_irq(fc_pci->pdev->irq, fc_pci); |
| 333 | pci_iounmap(fc_pci->pdev, fc_pci->io_mem); |
| 334 | pci_set_drvdata(fc_pci->pdev, NULL); |
| 335 | pci_release_regions(fc_pci->pdev); |
| 336 | pci_disable_device(fc_pci->pdev); |
| 337 | } |
| 338 | fc_pci->init_state &= ~FC_PCI_INIT; |
| 339 | } |
| 340 | |
| 341 | |
| 342 | static int flexcop_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 343 | { |
| 344 | struct flexcop_device *fc; |
| 345 | struct flexcop_pci *fc_pci; |
| 346 | int ret = -ENOMEM; |
| 347 | |
| 348 | if ((fc = flexcop_device_kmalloc(sizeof(struct flexcop_pci))) == NULL) { |
| 349 | err("out of memory\n"); |
| 350 | return -ENOMEM; |
| 351 | } |
| 352 | |
| 353 | /* general flexcop init */ |
| 354 | fc_pci = fc->bus_specific; |
| 355 | fc_pci->fc_dev = fc; |
| 356 | |
| 357 | fc->read_ibi_reg = flexcop_pci_read_ibi_reg; |
| 358 | fc->write_ibi_reg = flexcop_pci_write_ibi_reg; |
| 359 | fc->i2c_request = flexcop_i2c_request; |
| 360 | fc->get_mac_addr = flexcop_eeprom_check_mac_addr; |
| 361 | |
| 362 | fc->stream_control = flexcop_pci_stream_control; |
| 363 | |
Johannes Stezenbach | c4ee3fd | 2005-05-16 21:54:15 -0700 | [diff] [blame] | 364 | if (enable_pid_filtering) |
| 365 | info("will use the HW PID filter."); |
| 366 | else |
| 367 | info("will pass the complete TS to the demuxer."); |
| 368 | |
Johannes Stezenbach | 2add87a | 2005-05-16 21:54:10 -0700 | [diff] [blame] | 369 | fc->pid_filtering = enable_pid_filtering; |
| 370 | fc->bus_type = FC_PCI; |
| 371 | |
| 372 | fc->dev = &pdev->dev; |
Johannes Stezenbach | 59a7ad6 | 2005-05-16 21:54:16 -0700 | [diff] [blame] | 373 | fc->owner = THIS_MODULE; |
Johannes Stezenbach | 2add87a | 2005-05-16 21:54:10 -0700 | [diff] [blame] | 374 | |
| 375 | /* bus specific part */ |
| 376 | fc_pci->pdev = pdev; |
| 377 | if ((ret = flexcop_pci_init(fc_pci)) != 0) |
| 378 | goto err_kfree; |
| 379 | |
| 380 | /* init flexcop */ |
| 381 | if ((ret = flexcop_device_initialize(fc)) != 0) |
| 382 | goto err_pci_exit; |
| 383 | |
| 384 | /* init dma */ |
| 385 | if ((ret = flexcop_pci_dma_init(fc_pci)) != 0) |
| 386 | goto err_fc_exit; |
| 387 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 388 | INIT_DELAYED_WORK(&fc_pci->irq_check_work, flexcop_pci_irq_check_work); |
Patrick Boettcher | 64221be | 2005-07-07 17:57:49 -0700 | [diff] [blame] | 389 | |
Patrick Boettcher | 382c554 | 2009-02-23 06:27:16 -0300 | [diff] [blame^] | 390 | if (irq_chk_intv > 0) |
| 391 | schedule_delayed_work(&fc_pci->irq_check_work, |
| 392 | msecs_to_jiffies(irq_chk_intv < 100 ? 100 : irq_chk_intv)); |
| 393 | |
Trent Piepho | 8397703 | 2006-05-12 20:36:24 -0300 | [diff] [blame] | 394 | return ret; |
| 395 | |
Johannes Stezenbach | 2add87a | 2005-05-16 21:54:10 -0700 | [diff] [blame] | 396 | err_fc_exit: |
| 397 | flexcop_device_exit(fc); |
| 398 | err_pci_exit: |
| 399 | flexcop_pci_exit(fc_pci); |
| 400 | err_kfree: |
| 401 | flexcop_device_kfree(fc); |
Johannes Stezenbach | 2add87a | 2005-05-16 21:54:10 -0700 | [diff] [blame] | 402 | return ret; |
| 403 | } |
| 404 | |
| 405 | /* in theory every _exit function should be called exactly two times, |
| 406 | * here and in the bail-out-part of the _init-function |
| 407 | */ |
| 408 | static void flexcop_pci_remove(struct pci_dev *pdev) |
| 409 | { |
| 410 | struct flexcop_pci *fc_pci = pci_get_drvdata(pdev); |
| 411 | |
Patrick Boettcher | 382c554 | 2009-02-23 06:27:16 -0300 | [diff] [blame^] | 412 | if (irq_chk_intv > 0) |
| 413 | cancel_delayed_work(&fc_pci->irq_check_work); |
| 414 | |
Johannes Stezenbach | 2add87a | 2005-05-16 21:54:10 -0700 | [diff] [blame] | 415 | flexcop_pci_dma_exit(fc_pci); |
| 416 | flexcop_device_exit(fc_pci->fc_dev); |
| 417 | flexcop_pci_exit(fc_pci); |
| 418 | flexcop_device_kfree(fc_pci->fc_dev); |
| 419 | } |
| 420 | |
| 421 | static struct pci_device_id flexcop_pci_tbl[] = { |
| 422 | { PCI_DEVICE(0x13d0, 0x2103) }, |
Patrick Boettcher | 64221be | 2005-07-07 17:57:49 -0700 | [diff] [blame] | 423 | /* { PCI_DEVICE(0x13d0, 0x2200) }, ? */ |
Johannes Stezenbach | 2add87a | 2005-05-16 21:54:10 -0700 | [diff] [blame] | 424 | { }, |
| 425 | }; |
| 426 | |
| 427 | MODULE_DEVICE_TABLE(pci, flexcop_pci_tbl); |
| 428 | |
| 429 | static struct pci_driver flexcop_pci_driver = { |
Patrick Boettcher | 63b5c1c | 2005-07-07 17:58:30 -0700 | [diff] [blame] | 430 | .name = "b2c2_flexcop_pci", |
Johannes Stezenbach | 2add87a | 2005-05-16 21:54:10 -0700 | [diff] [blame] | 431 | .id_table = flexcop_pci_tbl, |
Patrick Boettcher | 64221be | 2005-07-07 17:57:49 -0700 | [diff] [blame] | 432 | .probe = flexcop_pci_probe, |
| 433 | .remove = flexcop_pci_remove, |
Johannes Stezenbach | 2add87a | 2005-05-16 21:54:10 -0700 | [diff] [blame] | 434 | }; |
| 435 | |
| 436 | static int __init flexcop_pci_module_init(void) |
| 437 | { |
| 438 | return pci_register_driver(&flexcop_pci_driver); |
| 439 | } |
| 440 | |
| 441 | static void __exit flexcop_pci_module_exit(void) |
| 442 | { |
| 443 | pci_unregister_driver(&flexcop_pci_driver); |
| 444 | } |
| 445 | |
| 446 | module_init(flexcop_pci_module_init); |
| 447 | module_exit(flexcop_pci_module_exit); |
| 448 | |
| 449 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 450 | MODULE_DESCRIPTION(DRIVER_NAME); |
| 451 | MODULE_LICENSE("GPL"); |