Lines Matching refs:pluto
6 * based on pluto2.c 1.10 - http://instinct-wp8.no-ip.org/pluto/
97 struct pluto {
128 static inline struct pluto *feed_to_pluto(struct dvb_demux_feed *feed)
130 return container_of(feed->demux, struct pluto, demux);
133 static inline struct pluto *frontend_to_pluto(struct dvb_frontend *fe)
135 return container_of(fe->dvb, struct pluto, dvb_adapter);
138 static inline u32 pluto_readreg(struct pluto *pluto, u32 reg)
140 return readl(&pluto->io_mem[reg]);
143 static inline void pluto_writereg(struct pluto *pluto, u32 reg, u32 val)
145 writel(val, &pluto->io_mem[reg]);
148 static inline void pluto_rw(struct pluto *pluto, u32 reg, u32 mask, u32 bits)
150 u32 val = readl(&pluto->io_mem[reg]);
153 writel(val, &pluto->io_mem[reg]);
156 static void pluto_write_tscr(struct pluto *pluto, u32 val)
162 pluto_writereg(pluto, REG_TSCR, val);
167 struct pluto *pluto = data;
170 pluto_rw(pluto, REG_SLCS, SLCS_SDA, SLCS_SDA);
172 pluto_rw(pluto, REG_SLCS, SLCS_SDA, 0);
177 struct pluto *pluto = data;
180 pluto_rw(pluto, REG_SLCS, SLCS_SCL, SLCS_SCL);
182 pluto_rw(pluto, REG_SLCS, SLCS_SCL, 0);
184 if ((state) && (pluto->i2cbug == 0)) {
185 pluto->i2cbug = 1;
187 if ((!state) && (pluto->i2cbug == 1))
188 pluto_setsda(pluto, 1);
189 pluto->i2cbug = 0;
195 struct pluto *pluto = data;
197 return pluto_readreg(pluto, REG_SLCS) & SLCS_SDA;
202 struct pluto *pluto = data;
204 return pluto_readreg(pluto, REG_SLCS) & SLCS_SCL;
207 static void pluto_reset_frontend(struct pluto *pluto, int reenable)
209 u32 val = pluto_readreg(pluto, REG_MISC);
213 pluto_writereg(pluto, REG_MISC, val);
217 pluto_writereg(pluto, REG_MISC, val);
221 static void pluto_reset_ts(struct pluto *pluto, int reenable)
223 u32 val = pluto_readreg(pluto, REG_TSCR);
227 pluto_write_tscr(pluto, val);
231 pluto_write_tscr(pluto, val);
235 static void pluto_set_dma_addr(struct pluto *pluto)
237 pluto_writereg(pluto, REG_PCAR, pluto->dma_addr);
240 static int __devinit pluto_dma_map(struct pluto *pluto)
242 pluto->dma_addr = pci_map_single(pluto->pdev, pluto->dma_buf,
245 return pci_dma_mapping_error(pluto->pdev, pluto->dma_addr);
248 static void pluto_dma_unmap(struct pluto *pluto)
250 pci_unmap_single(pluto->pdev, pluto->dma_addr,
256 struct pluto *pluto = feed_to_pluto(f);
259 if (pluto->users++ == 0)
260 pluto_rw(pluto, REG_PIDn(0), PID0_AFIL | PID0_NOFIL, 0);
263 pluto_rw(pluto, REG_PIDn(f->index), PIDn_ENP | PIDn_PID, PIDn_ENP | f->pid);
264 else if (pluto->full_ts_users++ == 0)
265 pluto_rw(pluto, REG_PIDn(0), PID0_NOFIL, PID0_NOFIL);
272 struct pluto *pluto = feed_to_pluto(f);
275 if (--pluto->users == 0)
276 pluto_rw(pluto, REG_PIDn(0), PID0_AFIL, PID0_AFIL);
279 pluto_rw(pluto, REG_PIDn(f->index), PIDn_ENP | PIDn_PID, 0x1fff);
280 else if (--pluto->full_ts_users == 0)
281 pluto_rw(pluto, REG_PIDn(0), PID0_NOFIL, 0);
286 static void pluto_dma_end(struct pluto *pluto, unsigned int nbpackets)
290 pci_dma_sync_single_for_cpu(pluto->pdev, pluto->dma_addr,
295 while (pluto->dma_buf[i] == 0x47)
299 pluto_reset_ts(pluto, 1);
300 dev_printk(KERN_DEBUG, &pluto->pdev->dev, "resetting TS because of invalid packet counter\n");
304 dvb_dmx_swfilter_packets(&pluto->demux, pluto->dma_buf, nbpackets);
308 memset(pluto->dma_buf, 0, nbpackets * 188);
311 pluto_set_dma_addr(pluto);
314 pci_dma_sync_single_for_device(pluto->pdev, pluto->dma_addr,
320 struct pluto *pluto = dev_id;
324 tscr = pluto_readreg(pluto, REG_TSCR);
329 if (pluto->dead == 0)
330 dev_err(&pluto->pdev->dev, "card has hung or been ejected.\n");
332 pluto->dead = 1;
338 pluto_dma_end(pluto, (tscr & TSCR_NBPACKETS) >> 24);
341 pluto->overflow++;
342 if (pluto->overflow) {
343 dev_err(&pluto->pdev->dev, "overflow irq (%d)\n",
344 pluto->overflow);
345 pluto_reset_ts(pluto, 1);
346 pluto->overflow = 0;
349 pluto->overflow++;
353 pluto_write_tscr(pluto, tscr | TSCR_IACK);
358 static void __devinit pluto_enable_irqs(struct pluto *pluto)
360 u32 val = pluto_readreg(pluto, REG_TSCR);
369 pluto_write_tscr(pluto, val);
372 static void pluto_disable_irqs(struct pluto *pluto)
374 u32 val = pluto_readreg(pluto, REG_TSCR);
381 pluto_write_tscr(pluto, val);
384 static int __devinit pluto_hw_init(struct pluto *pluto)
386 pluto_reset_frontend(pluto, 1);
389 pluto_rw(pluto, REG_MISC, MISC_ALED, MISC_ALED);
393 pluto_rw(pluto, REG_PIDn(0), PID0_END, PID0_END);
395 pluto_rw(pluto, REG_PIDn(0), PID0_END, 0);
398 pluto_dma_map(pluto);
399 pluto_set_dma_addr(pluto);
402 pluto_enable_irqs(pluto);
405 pluto_reset_ts(pluto, 1);
410 static void pluto_hw_exit(struct pluto *pluto)
413 pluto_disable_irqs(pluto);
415 pluto_reset_ts(pluto, 0);
418 pluto_rw(pluto, REG_MISC, MISC_ALED | MISC_LED1 | MISC_LED0, MISC_LED1);
421 pluto_dma_unmap(pluto);
423 pluto_reset_frontend(pluto, 0);
438 struct pluto *pluto = frontend_to_pluto(fe);
486 ret = i2c_transfer(&pluto->i2c_adap, &msg, 1);
498 struct pluto *pluto = frontend_to_pluto(fe);
500 return request_firmware(fw, name, &pluto->pdev->dev);
513 static int __devinit frontend_init(struct pluto *pluto)
517 pluto->fe = tda10046_attach(&pluto2_fe_config, &pluto->i2c_adap);
518 if (!pluto->fe) {
519 dev_err(&pluto->pdev->dev, "could not attach frontend\n");
522 pluto->fe->ops.tuner_ops.set_params = lg_tdtpe001p_tuner_set_params;
524 ret = dvb_register_frontend(&pluto->dvb_adapter, pluto->fe);
526 if (pluto->fe->ops.release)
527 pluto->fe->ops.release(pluto->fe);
534 static void __devinit pluto_read_rev(struct pluto *pluto)
536 u32 val = pluto_readreg(pluto, REG_MISC) & MISC_DVR;
537 dev_info(&pluto->pdev->dev, "board revision %d.%d\n",
541 static void __devinit pluto_read_mac(struct pluto *pluto, u8 *mac)
543 u32 val = pluto_readreg(pluto, REG_MMAC);
547 val = pluto_readreg(pluto, REG_IMAC);
551 val = pluto_readreg(pluto, REG_LMAC);
555 dev_info(&pluto->pdev->dev, "MAC %pM\n", mac);
558 static int __devinit pluto_read_serial(struct pluto *pluto)
560 struct pci_dev *pdev = pluto->pdev;
589 struct pluto *pluto;
595 pluto = kzalloc(sizeof(struct pluto), GFP_KERNEL);
596 if (!pluto)
599 pluto->pdev = pdev;
618 pluto->io_mem = pci_iomap(pdev, 0, 0x40);
619 if (!pluto->io_mem) {
624 pci_set_drvdata(pdev, pluto);
626 ret = request_irq(pdev->irq, pluto_irq, IRQF_SHARED, DRIVER_NAME, pluto);
630 ret = pluto_hw_init(pluto);
635 i2c_set_adapdata(&pluto->i2c_adap, pluto);
636 strcpy(pluto->i2c_adap.name, DRIVER_NAME);
637 pluto->i2c_adap.owner = THIS_MODULE;
638 pluto->i2c_adap.class = I2C_CLASS_TV_DIGITAL;
639 pluto->i2c_adap.dev.parent = &pdev->dev;
640 pluto->i2c_adap.algo_data = &pluto->i2c_bit;
641 pluto->i2c_bit.data = pluto;
642 pluto->i2c_bit.setsda = pluto_setsda;
643 pluto->i2c_bit.setscl = pluto_setscl;
644 pluto->i2c_bit.getsda = pluto_getsda;
645 pluto->i2c_bit.getscl = pluto_getscl;
646 pluto->i2c_bit.udelay = 10;
647 pluto->i2c_bit.timeout = 10;
650 pluto_setsda(pluto, 1);
651 pluto_setscl(pluto, 1);
653 ret = i2c_bit_add_bus(&pluto->i2c_adap);
658 ret = dvb_register_adapter(&pluto->dvb_adapter, DRIVER_NAME,
663 dvb_adapter = &pluto->dvb_adapter;
665 pluto_read_rev(pluto);
666 pluto_read_serial(pluto);
667 pluto_read_mac(pluto, dvb_adapter->proposed_mac);
669 dvbdemux = &pluto->demux;
682 pluto->hw_frontend.source = DMX_FRONTEND_0;
683 pluto->mem_frontend.source = DMX_MEMORY_FE;
684 pluto->dmxdev.filternum = NHWFILTERS;
685 pluto->dmxdev.demux = dmx;
687 ret = dvb_dmxdev_init(&pluto->dmxdev, dvb_adapter);
691 ret = dmx->add_frontend(dmx, &pluto->hw_frontend);
695 ret = dmx->add_frontend(dmx, &pluto->mem_frontend);
699 ret = dmx->connect_frontend(dmx, &pluto->hw_frontend);
703 ret = frontend_init(pluto);
707 dvb_net_init(dvb_adapter, &pluto->dvbnet, dmx);
714 dmx->remove_frontend(dmx, &pluto->mem_frontend);
716 dmx->remove_frontend(dmx, &pluto->hw_frontend);
718 dvb_dmxdev_release(&pluto->dmxdev);
724 i2c_del_adapter(&pluto->i2c_adap);
726 pluto_hw_exit(pluto);
728 free_irq(pdev->irq, pluto);
730 pci_iounmap(pdev, pluto->io_mem);
737 kfree(pluto);
743 struct pluto *pluto = pci_get_drvdata(pdev);
744 struct dvb_adapter *dvb_adapter = &pluto->dvb_adapter;
745 struct dvb_demux *dvbdemux = &pluto->demux;
749 dvb_net_release(&pluto->dvbnet);
750 if (pluto->fe)
751 dvb_unregister_frontend(pluto->fe);
754 dmx->remove_frontend(dmx, &pluto->mem_frontend);
755 dmx->remove_frontend(dmx, &pluto->hw_frontend);
756 dvb_dmxdev_release(&pluto->dmxdev);
759 i2c_del_adapter(&pluto->i2c_adap);
760 pluto_hw_exit(pluto);
761 free_irq(pdev->irq, pluto);
762 pci_iounmap(pdev, pluto->io_mem);
766 kfree(pluto);