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