Beispiel #1
0
int ttpci_budget_debiwrite(struct budget *budget, u32 config, int addr,
			   int count, u32 value, int uselocks, int nobusyloop)
{
	struct saa7146_dev *saa = budget->dev;
	unsigned long flags = 0;
	int result;

	if (count > 4 || count <= 0)
		return 0;

	if (uselocks)
		spin_lock_irqsave(&budget->debilock, flags);

	if ((result = saa7146_wait_for_debi_done(saa, nobusyloop)) < 0) {
		if (uselocks)
			spin_unlock_irqrestore(&budget->debilock, flags);
		return result;
	}

	saa7146_write(saa, DEBI_COMMAND, (count << 17) | 0x00000 | (addr & 0xffff));
	saa7146_write(saa, DEBI_CONFIG, config);
	saa7146_write(saa, DEBI_PAGE, 0);
	saa7146_write(saa, DEBI_AD, value);
	saa7146_write(saa, MC2, (2 << 16) | 2);

	if ((result = saa7146_wait_for_debi_done(saa, nobusyloop)) < 0) {
		if (uselocks)
			spin_unlock_irqrestore(&budget->debilock, flags);
		return result;
	}

	if (uselocks)
		spin_unlock_irqrestore(&budget->debilock, flags);
	return 0;
}
Beispiel #2
0
static int vbi_open(struct saa7146_dev *dev, struct file *file)
{
    struct saa7146_fh *fh = file->private_data;

    u32 arbtr_ctrl	= saa7146_read(dev, PCI_BT_V1);
    int ret = 0;

    DEB_VBI(("dev:%p, fh:%p\n",dev,fh));

    ret = saa7146_res_get(fh, RESOURCE_DMA3_BRS);
    if (0 == ret) {
        DEB_S(("cannot get vbi RESOURCE_DMA3_BRS resource\n"));
        return -EBUSY;
    }

    /* adjust arbitrition control for video dma 3 */
    arbtr_ctrl &= ~0x1f0000;
    arbtr_ctrl |=  0x1d0000;
    saa7146_write(dev, PCI_BT_V1, arbtr_ctrl);
    saa7146_write(dev, MC2, (MASK_04|MASK_20));

    memset(&fh->vbi_fmt,0,sizeof(fh->vbi_fmt));

    fh->vbi_fmt.sampling_rate	= 27000000;
    fh->vbi_fmt.offset		= 248; /* todo */
    fh->vbi_fmt.samples_per_line	= vbi_pixel_to_capture;
    fh->vbi_fmt.sample_format	= V4L2_PIX_FMT_GREY;

    fh->vbi_fmt.start[0] = 5;
    fh->vbi_fmt.count[0] = 16;
    fh->vbi_fmt.start[1] = 312;
    fh->vbi_fmt.count[1] = 16;

    videobuf_queue_sg_init(&fh->vbi_q, &vbi_qops,
                           &dev->pci->dev, &dev->slock,
                           V4L2_BUF_TYPE_VBI_CAPTURE,
                           V4L2_FIELD_SEQ_TB,
                           sizeof(struct saa7146_buf),
                           file);

    init_timer(&fh->vbi_read_timeout);
    fh->vbi_read_timeout.function = vbi_read_timeout;
    fh->vbi_read_timeout.data = (unsigned long)file;

    /* initialize the brs */
    if ( 0 != (SAA7146_USE_PORT_B_FOR_VBI & dev->ext_vv_data->flags)) {
        saa7146_write(dev, BRS_CTRL, MASK_30|MASK_29 | (7 << 19));
    } else {
        saa7146_write(dev, BRS_CTRL, 0x00000001);

        if (0 != (ret = vbi_workaround(dev))) {
            DEB_VBI(("vbi workaround failed!\n"));
            /* return ret;*/
        }
    }

    /* upload brs register */
    saa7146_write(dev, MC2, (MASK_08|MASK_24));
    return 0;
}
Beispiel #3
0
static int std_callback(struct saa7146_dev *dev, struct saa7146_standard *standard)
{
	struct mxb *mxb = (struct mxb *)dev->ext_priv;

	if (V4L2_STD_PAL_I == standard->id) {
		v4l2_std_id std = V4L2_STD_PAL_I;

		DEB_D(("VIDIOC_S_STD: setting mxb for PAL_I.\n"));
		/* set the 7146 gpio register -- I don't know what this does exactly */
		saa7146_write(dev, GPIO_CTRL, 0x00404050);
		/* unset the 7111 gpio register -- I don't know what this does exactly */
		saa7111a_call(mxb, core, s_gpio, 0);
		tuner_call(mxb, core, s_std, std);
	} else {
		v4l2_std_id std = V4L2_STD_PAL_BG;

		DEB_D(("VIDIOC_S_STD: setting mxb for PAL/NTSC/SECAM.\n"));
		/* set the 7146 gpio register -- I don't know what this does exactly */
		saa7146_write(dev, GPIO_CTRL, 0x00404050);
		/* set the 7111 gpio register -- I don't know what this does exactly */
		saa7111a_call(mxb, core, s_gpio, 1);
		tuner_call(mxb, core, s_std, std);
	}
	return 0;
}
static int std_callback(struct saa7146_dev *dev, struct saa7146_standard *standard)
{
    struct mxb *mxb = (struct mxb *)dev->ext_priv;

    if (V4L2_STD_PAL_I == standard->id) {
        v4l2_std_id std = V4L2_STD_PAL_I;

        DEB_D("VIDIOC_S_STD: setting mxb for PAL_I\n");

        saa7146_write(dev, GPIO_CTRL, 0x00404050);

        saa7111a_call(mxb, core, s_gpio, 0);
        tuner_call(mxb, core, s_std, std);
    } else {
        v4l2_std_id std = V4L2_STD_PAL_BG;

        DEB_D("VIDIOC_S_STD: setting mxb for PAL/NTSC/SECAM\n");

        saa7146_write(dev, GPIO_CTRL, 0x00404050);

        saa7111a_call(mxb, core, s_gpio, 1);
        tuner_call(mxb, core, s_std, std);
    }
    return 0;
}
Beispiel #5
0
static void vbi_stop(struct saa7146_fh *fh, struct file *file)
{
	struct saa7146_dev *dev = fh->dev;
	struct saa7146_vv *vv = dev->vv_data;
	unsigned long flags;
	DEB_VBI("dev:%p, fh:%p\n", dev, fh);

	spin_lock_irqsave(&dev->slock,flags);

	/* disable rps1  */
	saa7146_write(dev, MC1, MASK_29);

	/* disable rps1 irqs */
	SAA7146_IER_DISABLE(dev, MASK_28);

	/* shut down dma 3 transfers */
	saa7146_write(dev, MC1, MASK_20);

	if (vv->vbi_dmaq.curr)
		saa7146_buffer_finish(dev, &vv->vbi_dmaq, VIDEOBUF_DONE);

	videobuf_queue_cancel(&fh->vbi_q);

	vv->vbi_streaming = NULL;

	del_timer(&vv->vbi_dmaq.timeout);
	del_timer(&vv->vbi_read_timeout);

	spin_unlock_irqrestore(&dev->slock, flags);
}
static void saa7146_set_vbi_capture(struct saa7146_dev *dev, struct saa7146_buf *buf, struct saa7146_buf *next)
{
	struct saa7146_vv *vv = dev->vv_data;

	struct saa7146_video_dma vdma3;

	int count = 0;
	unsigned long e_wait = vv->current_hps_sync == SAA7146_HPS_SYNC_PORT_A ? CMD_E_FID_A : CMD_E_FID_B;
	unsigned long o_wait = vv->current_hps_sync == SAA7146_HPS_SYNC_PORT_A ? CMD_O_FID_A : CMD_O_FID_B;

	vdma3.base_even	= buf->pt[2].offset;
	vdma3.base_odd	= buf->pt[2].offset + 16 * vbi_pixel_to_capture;
	vdma3.prot_addr	= buf->pt[2].offset + 16 * 2 * vbi_pixel_to_capture;
	vdma3.pitch	= vbi_pixel_to_capture;
	vdma3.base_page	= buf->pt[2].dma | ME1;
	vdma3.num_line_byte = (16 << 16) | vbi_pixel_to_capture;

	saa7146_write_out_dma(dev, 3, &vdma3);

	/* write beginning of rps-program */
	count = 0;

	/* wait for o_fid_a/b / e_fid_a/b toggle only if bit 1 is not set */

	/* we don't wait here for the first field anymore. this is different from the video
	   capture and might cause that the first buffer is only half filled (with only
	   one field). but since this is some sort of streaming data, this is not that negative.
	   but by doing this, we can use the whole engine from videobuf-dma-sg.c... */

	/* set bit 1 */
	WRITE_RPS1(CMD_WR_REG | (1 << 8) | (MC2/4));
	WRITE_RPS1(MASK_28 | MASK_12);

	/* turn on video-dma3 */
	WRITE_RPS1(CMD_WR_REG_MASK | (MC1/4));
	WRITE_RPS1(MASK_04 | MASK_20);			/* => mask */
	WRITE_RPS1(MASK_04 | MASK_20);			/* => values */

	/* wait for o_fid_a/b / e_fid_a/b toggle */
	WRITE_RPS1(CMD_PAUSE | o_wait);
	WRITE_RPS1(CMD_PAUSE | e_wait);

	/* generate interrupt */
	WRITE_RPS1(CMD_INTERRUPT);

	/* stop */
	WRITE_RPS1(CMD_STOP);

	/* enable rps1 irqs */
	SAA7146_IER_ENABLE(dev, MASK_28);

	/* write the address of the rps-program */
	saa7146_write(dev, RPS_ADDR1, dev->d_rps1.dma_handle);

	/* turn on rps */
	saa7146_write(dev, MC1, (MASK_13 | MASK_29));
}
Beispiel #7
0
static void saa7146_set_vbi_capture(struct saa7146_dev *dev, struct saa7146_buf *buf, struct saa7146_buf *next)
{
	struct saa7146_vv *vv = dev->vv_data;

	struct saa7146_video_dma vdma3;

	int count = 0;
	unsigned long e_wait = vv->current_hps_sync == SAA7146_HPS_SYNC_PORT_A ? CMD_E_FID_A : CMD_E_FID_B;
	unsigned long o_wait = vv->current_hps_sync == SAA7146_HPS_SYNC_PORT_A ? CMD_O_FID_A : CMD_O_FID_B;


	vdma3.base_even	= buf->pt[2].offset;
	vdma3.base_odd	= buf->pt[2].offset + 16 * vbi_pixel_to_capture;
	vdma3.prot_addr	= buf->pt[2].offset + 16 * 2 * vbi_pixel_to_capture;
	vdma3.pitch	= vbi_pixel_to_capture;
	vdma3.base_page	= buf->pt[2].dma | ME1;
	vdma3.num_line_byte = (16 << 16) | vbi_pixel_to_capture;

	saa7146_write_out_dma(dev, 3, &vdma3);

	
	count = 0;

	

	


	
	WRITE_RPS1(CMD_WR_REG | (1 << 8) | (MC2/4));
	WRITE_RPS1(MASK_28 | MASK_12);

	
	WRITE_RPS1(CMD_WR_REG_MASK | (MC1/4));
	WRITE_RPS1(MASK_04 | MASK_20);			
	WRITE_RPS1(MASK_04 | MASK_20);			

	
	WRITE_RPS1(CMD_PAUSE | o_wait);
	WRITE_RPS1(CMD_PAUSE | e_wait);

	
	WRITE_RPS1(CMD_INTERRUPT);

	
	WRITE_RPS1(CMD_STOP);

	
	SAA7146_IER_ENABLE(dev, MASK_28);

	
	saa7146_write(dev, RPS_ADDR1, dev->d_rps1.dma_handle);

	
	saa7146_write(dev, MC1, (MASK_13 | MASK_29));
}
static int video_end(struct saa7146_fh *fh, struct file *file)
{
	struct saa7146_dev *dev = fh->dev;
	struct saa7146_vv *vv = dev->vv_data;
	struct saa7146_format *fmt = NULL;
	unsigned long flags;
	unsigned int resource;
	u32 dmas = 0;
	DEB_EE(("dev:%p, fh:%p\n",dev,fh));

	if ((vv->video_status & STATUS_CAPTURE) != STATUS_CAPTURE) {
		DEB_S(("not capturing.\n"));
		return 0;
	}

	if (vv->video_fh != fh) {
		DEB_S(("capturing, but in another open.\n"));
		return -EBUSY;
	}

	fmt = format_by_fourcc(dev,fh->video_fmt.pixelformat);
	/* we need to have a valid format set here */
	BUG_ON(NULL == fmt);

	if (0 != (fmt->flags & FORMAT_IS_PLANAR)) {
		resource = RESOURCE_DMA1_HPS|RESOURCE_DMA2_CLP|RESOURCE_DMA3_BRS;
		dmas = MASK_22 | MASK_21 | MASK_20;
	} else {
		resource = RESOURCE_DMA1_HPS;
		dmas = MASK_22;
	}
	spin_lock_irqsave(&dev->slock,flags);

	/* disable rps0  */
	saa7146_write(dev, MC1, MASK_28);

	/* disable rps0 irqs */
	SAA7146_IER_DISABLE(dev, MASK_27);

	/* shut down all used video dma transfers */
	saa7146_write(dev, MC1, dmas);

	spin_unlock_irqrestore(&dev->slock, flags);

	vv->video_fh = NULL;
	vv->video_status = 0;

	saa7146_res_free(fh, resource);

	if (vv->ov_suspend != NULL) {
		saa7146_start_preview(vv->ov_suspend);
		vv->ov_suspend = NULL;
	}

	return 0;
}
Beispiel #9
0
static int vbi_open(struct saa7146_dev *dev, struct file *file)
{
	struct saa7146_fh *fh = file->private_data;
	struct saa7146_vv *vv = fh->dev->vv_data;

	u32 arbtr_ctrl	= saa7146_read(dev, PCI_BT_V1);
	int ret = 0;

	DEB_VBI("dev:%p, fh:%p\n", dev, fh);

	ret = saa7146_res_get(fh, RESOURCE_DMA3_BRS);
	if (0 == ret) {
		DEB_S("cannot get vbi RESOURCE_DMA3_BRS resource\n");
		return -EBUSY;
	}

	/* adjust arbitrition control for video dma 3 */
	arbtr_ctrl &= ~0x1f0000;
	arbtr_ctrl |=  0x1d0000;
	saa7146_write(dev, PCI_BT_V1, arbtr_ctrl);
	saa7146_write(dev, MC2, (MASK_04|MASK_20));

	videobuf_queue_sg_init(&fh->vbi_q, &vbi_qops,
			    &dev->pci->dev, &dev->slock,
			    V4L2_BUF_TYPE_VBI_CAPTURE,
			    V4L2_FIELD_SEQ_TB, // FIXME: does this really work?
			    sizeof(struct saa7146_buf),
			    file, &dev->v4l2_lock);

	vv->vbi_read_timeout.function = vbi_read_timeout;
	vv->vbi_read_timeout.data = (unsigned long)file;

	/* initialize the brs */
	if ( 0 != (SAA7146_USE_PORT_B_FOR_VBI & dev->ext_vv_data->flags)) {
		saa7146_write(dev, BRS_CTRL, MASK_30|MASK_29 | (7 << 19));
	} else {
		saa7146_write(dev, BRS_CTRL, 0x00000001);

		if (0 != (ret = vbi_workaround(dev))) {
			DEB_VBI("vbi workaround failed!\n");
			/* return ret;*/
		}
	}

	/* upload brs register */
	saa7146_write(dev, MC2, (MASK_08|MASK_24));
	return 0;
}
static int video_begin(struct saa7146_fh *fh)
{
	struct saa7146_dev *dev = fh->dev;
	struct saa7146_vv *vv = dev->vv_data;
	struct saa7146_format *fmt = NULL;
	unsigned int resource;
	int ret = 0, err = 0;

	DEB_EE(("dev:%p, fh:%p\n",dev,fh));

	if ((vv->video_status & STATUS_CAPTURE) != 0) {
		if (vv->video_fh == fh) {
			DEB_S(("already capturing.\n"));
			return 0;
		}
		DEB_S(("already capturing in another open.\n"));
		return -EBUSY;
	}

	if ((vv->video_status & STATUS_OVERLAY) != 0) {
		DEB_S(("warning: suspending overlay video for streaming capture.\n"));
		vv->ov_suspend = vv->video_fh;
		err = saa7146_stop_preview(vv->video_fh); /* side effect: video_status is now 0, video_fh is NULL */
		if (0 != err) {
			DEB_D(("suspending video failed. aborting\n"));
			return err;
		}
	}

	fmt = format_by_fourcc(dev,fh->video_fmt.pixelformat);
	/* we need to have a valid format set here */
	BUG_ON(NULL == fmt);

	if (0 != (fmt->flags & FORMAT_IS_PLANAR)) {
		resource = RESOURCE_DMA1_HPS|RESOURCE_DMA2_CLP|RESOURCE_DMA3_BRS;
	} else {
		resource = RESOURCE_DMA1_HPS;
	}

	ret = saa7146_res_get(fh, resource);
	if (0 == ret) {
		DEB_S(("cannot get capture resource %d\n",resource));
		if (vv->ov_suspend != NULL) {
			saa7146_start_preview(vv->ov_suspend);
			vv->ov_suspend = NULL;
		}
		return -EBUSY;
	}

	/* clear out beginning of streaming bit (rps register 0)*/
	saa7146_write(dev, MC2, MASK_27 );

	/* enable rps0 irqs */
	SAA7146_IER_ENABLE(dev, MASK_27);

	vv->video_fh = fh;
	vv->video_status = STATUS_CAPTURE;

	return 0;
}
Beispiel #11
0
/* interrupt handler */
static irqreturn_t interrupt_hw(int irq, void *dev_id)
{
	struct saa7146_dev *dev = dev_id;
	u32 isr;
	u32 ack_isr;

	/* read out the interrupt status register */
	ack_isr = isr = saa7146_read(dev, ISR);

	/* is this our interrupt? */
	if ( 0 == isr ) {
		/* nope, some other device */
		return IRQ_NONE;
	}

	if (dev->ext) {
		if (dev->ext->irq_mask & isr) {
			if (dev->ext->irq_func)
				dev->ext->irq_func(dev, &isr);
			isr &= ~dev->ext->irq_mask;
		}
	}
	if (0 != (isr & (MASK_27))) {
		DEB_INT(("irq: RPS0 (0x%08x).\n",isr));
		if (dev->vv_data && dev->vv_callback)
			dev->vv_callback(dev,isr);
		isr &= ~MASK_27;
	}
	if (0 != (isr & (MASK_28))) {
		if (dev->vv_data && dev->vv_callback)
			dev->vv_callback(dev,isr);
		isr &= ~MASK_28;
	}
	if (0 != (isr & (MASK_16|MASK_17))) {
		SAA7146_IER_DISABLE(dev, MASK_16|MASK_17);
		/* only wake up if we expect something */
		if (0 != dev->i2c_op) {
			dev->i2c_op = 0;
			wake_up(&dev->i2c_wq);
		} else {
			u32 psr = saa7146_read(dev, PSR);
			u32 ssr = saa7146_read(dev, SSR);
#ifdef CONFIG_DEBUG_PRINTK
			printk(KERN_WARNING "%s: unexpected i2c irq: isr %08x psr %08x ssr %08x\n",
			       dev->name, isr, psr, ssr);
#else
			;
#endif
		}
		isr &= ~(MASK_16|MASK_17);
	}
	if( 0 != isr ) {
		ERR(("warning: interrupt enabled, but not handled properly.(0x%08x)\n",isr));
		ERR(("disabling interrupt source(s)!\n"));
		SAA7146_IER_DISABLE(dev,isr);
	}
	saa7146_write(dev, ISR, ack_isr);
	return IRQ_HANDLED;
}
Beispiel #12
0
static int stop_ts_capture(struct budget *budget)
{
	dprintk(2, "budget: %p\n", budget);

	saa7146_write(budget->dev, MC1, MASK_20);	// DMA3 off
	SAA7146_IER_DISABLE(budget->dev, MASK_10);
	return 0;
}
static irqreturn_t interrupt_hw(int irq, void *dev_id)
{
	struct saa7146_dev *dev = dev_id;
	u32 isr;
	u32 ack_isr;

	
	ack_isr = isr = saa7146_read(dev, ISR);

	
	if ( 0 == isr ) {
		
		return IRQ_NONE;
	}

	if (dev->ext) {
		if (dev->ext->irq_mask & isr) {
			if (dev->ext->irq_func)
				dev->ext->irq_func(dev, &isr);
			isr &= ~dev->ext->irq_mask;
		}
	}
	if (0 != (isr & (MASK_27))) {
		DEB_INT("irq: RPS0 (0x%08x)\n", isr);
		if (dev->vv_data && dev->vv_callback)
			dev->vv_callback(dev,isr);
		isr &= ~MASK_27;
	}
	if (0 != (isr & (MASK_28))) {
		if (dev->vv_data && dev->vv_callback)
			dev->vv_callback(dev,isr);
		isr &= ~MASK_28;
	}
	if (0 != (isr & (MASK_16|MASK_17))) {
		SAA7146_IER_DISABLE(dev, MASK_16|MASK_17);
		
		if (0 != dev->i2c_op) {
			dev->i2c_op = 0;
			wake_up(&dev->i2c_wq);
		} else {
			u32 psr = saa7146_read(dev, PSR);
			u32 ssr = saa7146_read(dev, SSR);
			pr_warn("%s: unexpected i2c irq: isr %08x psr %08x ssr %08x\n",
				dev->name, isr, psr, ssr);
		}
		isr &= ~(MASK_16|MASK_17);
	}
	if( 0 != isr ) {
		ERR("warning: interrupt enabled, but not handled properly.(0x%08x)\n",
		    isr);
		ERR("disabling interrupt source(s)!\n");
		SAA7146_IER_DISABLE(dev,isr);
	}
	saa7146_write(dev, ISR, ack_isr);
	return IRQ_HANDLED;
}
Beispiel #14
0
static int ttpci_budget_debiwrite_nolock(struct budget *budget, u32 config,
		int addr, int count, u32 value, int nobusyloop)
{
	struct saa7146_dev *saa = budget->dev;
	int result;

	result = saa7146_wait_for_debi_done(saa, nobusyloop);
	if (result < 0)
		return result;

	saa7146_write(saa, DEBI_COMMAND, (count << 17) | 0x00000 | (addr & 0xffff));
	saa7146_write(saa, DEBI_CONFIG, config);
	saa7146_write(saa, DEBI_PAGE, 0);
	saa7146_write(saa, DEBI_AD, value);
	saa7146_write(saa, MC2, (2 << 16) | 2);

	result = saa7146_wait_for_debi_done(saa, nobusyloop);
	return result < 0 ? result : 0;
}
Beispiel #15
0
void saa7146_setgpio(struct saa7146_dev *dev, int port, u32 data)
{
    u32 value = 0;

    BUG_ON(port > 3);

    value = saa7146_read(dev, GPIO_CTRL);
    value &= ~(0xff << (8*port));
    value |= (data << (8*port));
    saa7146_write(dev, GPIO_CTRL, value);
}
static int stop_ts_capture(struct budget *budget)
{
	DEB_EE(("budget: %p\n",budget));

        if (--budget->feeding)
                return budget->feeding;

        saa7146_write(budget->dev, MC1, MASK_20); // DMA3 off
	IER_DISABLE(budget->dev, MASK_10);
        return 0;
}
Beispiel #17
0
static void saa7146_remove_one(struct pci_dev *pdev)
{
    struct v4l2_device *v4l2_dev = pci_get_drvdata(pdev);
    struct saa7146_dev *dev = to_saa7146_dev(v4l2_dev);
    struct {
        void *addr;
        dma_addr_t dma;
    } dev_map[] = {
        { dev->d_i2c.cpu_addr, dev->d_i2c.dma_handle },
        { dev->d_rps1.cpu_addr, dev->d_rps1.dma_handle },
        { dev->d_rps0.cpu_addr, dev->d_rps0.dma_handle },
        { NULL, 0 }
    }, *p;

    DEB_EE(("dev:%p\n",dev));

    dev->ext->detach(dev);
    /* Zero the PCI drvdata after use. */
    pci_set_drvdata(pdev, NULL);

    /* shut down all video dma transfers */
    saa7146_write(dev, MC1, 0x00ff0000);

    /* disable all irqs, release irq-routine */
    saa7146_write(dev, IER, 0);

    free_irq(pdev->irq, dev);

    for (p = dev_map; p->addr; p++)
        pci_free_consistent(pdev, SAA7146_RPS_MEM, p->addr, p->dma);

    iounmap(dev->mem);
    pci_release_region(pdev, 0);
    list_del(&dev->item);
    pci_disable_device(pdev);
    kfree(dev);

    saa7146_num--;
}
Beispiel #18
0
static int ttpci_budget_debiread_nolock(struct budget *budget, u32 config,
		int addr, int count, int nobusyloop)
{
	struct saa7146_dev *saa = budget->dev;
	int result;

	result = saa7146_wait_for_debi_done(saa, nobusyloop);
	if (result < 0)
		return result;

	saa7146_write(saa, DEBI_COMMAND, (count << 17) | 0x10000 | (addr & 0xffff));
	saa7146_write(saa, DEBI_CONFIG, config);
	saa7146_write(saa, DEBI_PAGE, 0);
	saa7146_write(saa, MC2, (2 << 16) | 2);

	result = saa7146_wait_for_debi_done(saa, nobusyloop);
	if (result < 0)
		return result;

	result = saa7146_read(saa, DEBI_AD);
	result &= (0xffffffffUL >> ((4 - count) * 8));
	return result;
}
int saa7146_s_ctrl(struct v4l2_ctrl *ctrl)
{
	struct saa7146_dev *dev = container_of(ctrl->handler,
				struct saa7146_dev, ctrl_handler);
	struct saa7146_vv *vv = dev->vv_data;
	u32 val;

	switch (ctrl->id) {
	case V4L2_CID_BRIGHTNESS:
		val = saa7146_read(dev, BCS_CTRL);
		val &= 0x00ffffff;
		val |= (ctrl->val << 24);
		saa7146_write(dev, BCS_CTRL, val);
		saa7146_write(dev, MC2, MASK_22 | MASK_06);
		break;

	case V4L2_CID_CONTRAST:
		val = saa7146_read(dev, BCS_CTRL);
		val &= 0xff00ffff;
		val |= (ctrl->val << 16);
		saa7146_write(dev, BCS_CTRL, val);
		saa7146_write(dev, MC2, MASK_22 | MASK_06);
		break;

	case V4L2_CID_SATURATION:
		val = saa7146_read(dev, BCS_CTRL);
		val &= 0xffffff00;
		val |= (ctrl->val << 0);
		saa7146_write(dev, BCS_CTRL, val);
		saa7146_write(dev, MC2, MASK_22 | MASK_06);
		break;

	case V4L2_CID_HFLIP:
		/* fixme: we can support changing VFLIP and HFLIP here... */
		if ((vv->video_status & STATUS_CAPTURE))
			return -EBUSY;
		vv->hflip = ctrl->val;
		break;

	case V4L2_CID_VFLIP:
		if ((vv->video_status & STATUS_CAPTURE))
			return -EBUSY;
		vv->vflip = ctrl->val;
		break;

	default:
		return -EINVAL;
	}

	if ((vv->video_status & STATUS_OVERLAY) != 0) { /* CHECK: && (vv->video_fh == fh)) */
		struct saa7146_fh *fh = vv->video_fh;

		saa7146_stop_preview(fh);
		saa7146_start_preview(fh);
	}
	return 0;
}
Beispiel #20
0
int ttpci_budget_init(struct budget *budget, struct saa7146_dev *dev,
		      struct saa7146_pci_extension_data *info,
		      struct module *owner, short *adapter_nums)
{
	int ret = 0;
	struct budget_info *bi = info->ext_priv;
	int max_bufsize;
	int height_mask;

	memset(budget, 0, sizeof(struct budget));

	dprintk(2, "dev: %p, budget: %p\n", dev, budget);

	budget->card = bi;
	budget->dev = (struct saa7146_dev *) dev;

	switch(budget->card->type) {
	case BUDGET_FS_ACTIVY:
		budget->buffer_width = TS_WIDTH_ACTIVY;
		max_bufsize = TS_MAX_BUFSIZE_K_ACTIVY;
		height_mask = TS_HEIGHT_MASK_ACTIVY;
		break;

	case BUDGET_KNC1C:
	case BUDGET_KNC1CP:
	case BUDGET_CIN1200C:
	case BUDGET_KNC1C_MK3:
	case BUDGET_KNC1C_TDA10024:
	case BUDGET_KNC1CP_MK3:
	case BUDGET_CIN1200C_MK3:
		budget->buffer_width = TS_WIDTH_DVBC;
		max_bufsize = TS_MAX_BUFSIZE_K_DVBC;
		height_mask = TS_HEIGHT_MASK_DVBC;
		break;

	default:
		budget->buffer_width = TS_WIDTH;
		max_bufsize = TS_MAX_BUFSIZE_K;
		height_mask = TS_HEIGHT_MASK;
	}

	if (dma_buffer_size < TS_MIN_BUFSIZE_K)
		dma_buffer_size = TS_MIN_BUFSIZE_K;
	else if (dma_buffer_size > max_bufsize)
		dma_buffer_size = max_bufsize;

	budget->buffer_height = dma_buffer_size * 1024 / budget->buffer_width;
	if (budget->buffer_height > 0xfff) {
		budget->buffer_height /= 2;
		budget->buffer_height &= height_mask;
		budget->buffer_size = 2 * budget->buffer_height * budget->buffer_width;
	} else {
		budget->buffer_height &= height_mask;
		budget->buffer_size = budget->buffer_height * budget->buffer_width;
	}
	budget->buffer_warning_threshold = budget->buffer_size * 80/100;
	budget->buffer_warnings = 0;
	budget->buffer_warning_time = jiffies;

	dprintk(2, "%s: buffer type = %s, width = %d, height = %d\n",
		budget->dev->name,
		budget->buffer_size > budget->buffer_width * budget->buffer_height ? "odd/even" : "single",
		budget->buffer_width, budget->buffer_height);
	printk("%s: dma buffer size %u\n", budget->dev->name, budget->buffer_size);

	ret = dvb_register_adapter(&budget->dvb_adapter, budget->card->name,
				   owner, &budget->dev->pci->dev, adapter_nums);
	if (ret < 0)
		return ret;

	/* set dd1 stream a & b */
	saa7146_write(dev, DD1_STREAM_B, 0x00000000);
	saa7146_write(dev, MC2, (MASK_09 | MASK_25));
	saa7146_write(dev, MC2, (MASK_10 | MASK_26));
	saa7146_write(dev, DD1_INIT, 0x02000000);
	saa7146_write(dev, MC2, (MASK_09 | MASK_25 | MASK_10 | MASK_26));

	if (bi->type != BUDGET_FS_ACTIVY)
		budget->video_port = BUDGET_VIDEO_PORTB;
	else
		budget->video_port = BUDGET_VIDEO_PORTA;
	spin_lock_init(&budget->feedlock);
	spin_lock_init(&budget->debilock);

	/* the Siemens DVB needs this if you want to have the i2c chips
	   get recognized before the main driver is loaded */
	if (bi->type != BUDGET_FS_ACTIVY)
		saa7146_write(dev, GPIO_CTRL, 0x500000);	/* GPIO 3 = 1 */

	strlcpy(budget->i2c_adap.name, budget->card->name, sizeof(budget->i2c_adap.name));

	saa7146_i2c_adapter_prepare(dev, &budget->i2c_adap, SAA7146_I2C_BUS_BIT_RATE_120);
	strcpy(budget->i2c_adap.name, budget->card->name);

	if (i2c_add_adapter(&budget->i2c_adap) < 0) {
		ret = -ENOMEM;
		goto err_dvb_unregister;
	}

	ttpci_eeprom_parse_mac(&budget->i2c_adap, budget->dvb_adapter.proposed_mac);

	budget->grabbing = saa7146_vmalloc_build_pgtable(dev->pci, budget->buffer_size, &budget->pt);
	if (NULL == budget->grabbing) {
		ret = -ENOMEM;
		goto err_del_i2c;
	}

	saa7146_write(dev, PCI_BT_V1, 0x001c0000);
	/* upload all */
	saa7146_write(dev, GPIO_CTRL, 0x000000);

	tasklet_init(&budget->vpe_tasklet, vpeirq, (unsigned long) budget);

	/* frontend power on */
	if (bi->type != BUDGET_FS_ACTIVY)
		saa7146_setgpio(dev, 2, SAA7146_GPIO_OUTHI);

	if ((ret = budget_register(budget)) == 0)
		return 0; /* Everything OK */

	/* An error occurred, cleanup resources */
	saa7146_vfree_destroy_pgtable(dev->pci, budget->grabbing, &budget->pt);

err_del_i2c:
	i2c_del_adapter(&budget->i2c_adap);

err_dvb_unregister:
	dvb_unregister_adapter(&budget->dvb_adapter);

	return ret;
}
static int mxb_init_done(struct saa7146_dev* dev)
{
    struct mxb* mxb = (struct mxb*)dev->ext_priv;
    struct i2c_msg msg;
    struct tuner_setup tun_setup;
    v4l2_std_id std = V4L2_STD_PAL_BG;

    int i = 0, err = 0;


    saa7111a_call(mxb, core, s_std, std);


    i = 0;
    saa7111a_call(mxb, video, s_routing, SAA7115_COMPOSITE0,
                  SAA7111_FMT_CCIR, 0);


    tun_setup.mode_mask = T_ANALOG_TV;
    tun_setup.addr = ADDR_UNSET;
    tun_setup.type = TUNER_PHILIPS_PAL;
    tuner_call(mxb, tuner, s_type_addr, &tun_setup);

    mxb->cur_freq.tuner = 0;
    mxb->cur_freq.type = V4L2_TUNER_ANALOG_TV;
    mxb->cur_freq.frequency = freq;
    tuner_call(mxb, tuner, s_frequency, &mxb->cur_freq);


    tuner_call(mxb, core, s_std, std);


    tea6420_route_line(mxb, 6);
    tea6420_route_cd(mxb, 6);


    tea6415c_call(mxb, video, s_routing, 3, 17, 0);


    tea6415c_call(mxb, video, s_routing, 3, 13, 0);


    mxb->cur_input = 0;
    mxb->cur_mute = 1;

    mxb->cur_mode = V4L2_TUNER_MODE_STEREO;

    msg.addr = 0x1b;
    msg.flags = 0;
    msg.len = mxb_saa7740_init[0].length;
    msg.buf = &mxb_saa7740_init[0].data[0];

    err = i2c_transfer(&mxb->i2c_adapter, &msg, 1);
    if (err == 1) {
        extension.flags &= ~SAA7146_USE_I2C_IRQ;
        for (i = 1; ; i++) {
            if (-1 == mxb_saa7740_init[i].length)
                break;

            msg.len = mxb_saa7740_init[i].length;
            msg.buf = &mxb_saa7740_init[i].data[0];
            err = i2c_transfer(&mxb->i2c_adapter, &msg, 1);
            if (err != 1) {
                DEB_D("failed to initialize 'sound arena module'\n");
                goto err;
            }
        }
        pr_info("'sound arena module' detected\n");
    }
err:




    saa7146_set_hps_source_and_sync(dev, input_port_selection[mxb->cur_input].hps_source,
                                    input_port_selection[mxb->cur_input].hps_sync);



    saa7146_write(dev, DD1_STREAM_B,	0x00000000);
    saa7146_write(dev, DD1_INIT,		0x02000200);
    saa7146_write(dev, MC2, (MASK_09 | MASK_25 | MASK_10 | MASK_26));

    return 0;
}
static int set_control(struct saa7146_fh *fh, struct v4l2_control *c)
{
	struct saa7146_dev *dev = fh->dev;
	struct saa7146_vv *vv = dev->vv_data;

	const struct v4l2_queryctrl* ctrl;

	ctrl = ctrl_by_id(c->id);
	if (NULL == ctrl) {
		DEB_D(("unknown control %d\n",c->id));
		return -EINVAL;
	}

	down(&dev->lock);

	switch (ctrl->type) {
	case V4L2_CTRL_TYPE_BOOLEAN:
	case V4L2_CTRL_TYPE_MENU:
	case V4L2_CTRL_TYPE_INTEGER:
		if (c->value < ctrl->minimum)
			c->value = ctrl->minimum;
		if (c->value > ctrl->maximum)
			c->value = ctrl->maximum;
		break;
	default:
		/* nothing */;
	};

	switch (c->id) {
	case V4L2_CID_BRIGHTNESS: {
		u32 value = saa7146_read(dev, BCS_CTRL);
		value &= 0x00ffffff;
		value |= (c->value << 24);
		saa7146_write(dev, BCS_CTRL, value);
		saa7146_write(dev, MC2, MASK_22 | MASK_06 );
		break;
	}
	case V4L2_CID_CONTRAST: {
		u32 value = saa7146_read(dev, BCS_CTRL);
		value &= 0xff00ffff;
		value |= (c->value << 16);
		saa7146_write(dev, BCS_CTRL, value);
		saa7146_write(dev, MC2, MASK_22 | MASK_06 );
		break;
	}
	case V4L2_CID_SATURATION: {
		u32 value = saa7146_read(dev, BCS_CTRL);
		value &= 0xffffff00;
		value |= (c->value << 0);
		saa7146_write(dev, BCS_CTRL, value);
		saa7146_write(dev, MC2, MASK_22 | MASK_06 );
		break;
	}
	case V4L2_CID_HFLIP:
		/* fixme: we can support changing VFLIP and HFLIP here... */
		if (IS_CAPTURE_ACTIVE(fh) != 0) {
			DEB_D(("V4L2_CID_HFLIP while active capture.\n"));
			up(&dev->lock);
			return -EINVAL;
		}
		vv->hflip = c->value;
		break;
	case V4L2_CID_VFLIP:
		if (IS_CAPTURE_ACTIVE(fh) != 0) {
			DEB_D(("V4L2_CID_VFLIP while active capture.\n"));
			up(&dev->lock);
			return -EINVAL;
		}
		vv->vflip = c->value;
		break;
	default: {
		return -EINVAL;
	}
	}
	up(&dev->lock);

	if (IS_OVERLAY_ACTIVE(fh) != 0) {
		saa7146_stop_preview(fh);
		saa7146_start_preview(fh);
	}
	return 0;
}
Beispiel #23
0
static int vbi_workaround(struct saa7146_dev *dev)
{
	struct saa7146_vv *vv = dev->vv_data;

	u32          *cpu;
	dma_addr_t   dma_addr;

	int count = 0;
	int i;

	DECLARE_WAITQUEUE(wait, current);

	DEB_VBI("dev:%p\n", dev);

	/* once again, a bug in the saa7146: the brs acquisition
	   is buggy and especially the BXO-counter does not work
	   as specified. there is this workaround, but please
	   don't let me explain it. ;-) */

	cpu = pci_alloc_consistent(dev->pci, 4096, &dma_addr);
	if (NULL == cpu)
		return -ENOMEM;

	/* setup some basic programming, just for the workaround */
	saa7146_write(dev, BASE_EVEN3,	dma_addr);
	saa7146_write(dev, BASE_ODD3,	dma_addr+vbi_pixel_to_capture);
	saa7146_write(dev, PROT_ADDR3,	dma_addr+4096);
	saa7146_write(dev, PITCH3,	vbi_pixel_to_capture);
	saa7146_write(dev, BASE_PAGE3,	0x0);
	saa7146_write(dev, NUM_LINE_BYTE3, (2<<16)|((vbi_pixel_to_capture)<<0));
	saa7146_write(dev, MC2, MASK_04|MASK_20);

	/* load brs-control register */
	WRITE_RPS1(CMD_WR_REG | (1 << 8) | (BRS_CTRL/4));
	/* BXO = 1h, BRS to outbound */
	WRITE_RPS1(0xc000008c);
	/* wait for vbi_a or vbi_b*/
	if ( 0 != (SAA7146_USE_PORT_B_FOR_VBI & dev->ext_vv_data->flags)) {
		DEB_D("...using port b\n");
		WRITE_RPS1(CMD_PAUSE | CMD_OAN | CMD_SIG1 | CMD_E_FID_B);
		WRITE_RPS1(CMD_PAUSE | CMD_OAN | CMD_SIG1 | CMD_O_FID_B);
/*
		WRITE_RPS1(CMD_PAUSE | MASK_09);
*/
	} else {
		DEB_D("...using port a\n");
		WRITE_RPS1(CMD_PAUSE | MASK_10);
	}
	/* upload brs */
	WRITE_RPS1(CMD_UPLOAD | MASK_08);
	/* load brs-control register */
	WRITE_RPS1(CMD_WR_REG | (1 << 8) | (BRS_CTRL/4));
	/* BYO = 1, BXO = NQBIL (=1728 for PAL, for NTSC this is 858*2) - NumByte3 (=1440) = 288 */
	WRITE_RPS1(((1728-(vbi_pixel_to_capture)) << 7) | MASK_19);
	/* wait for brs_done */
	WRITE_RPS1(CMD_PAUSE | MASK_08);
	/* upload brs */
	WRITE_RPS1(CMD_UPLOAD | MASK_08);
	/* load video-dma3 NumLines3 and NumBytes3 */
	WRITE_RPS1(CMD_WR_REG | (1 << 8) | (NUM_LINE_BYTE3/4));
	/* dev->vbi_count*2 lines, 720 pixel (= 1440 Bytes) */
	WRITE_RPS1((2 << 16) | (vbi_pixel_to_capture));
	/* load brs-control register */
	WRITE_RPS1(CMD_WR_REG | (1 << 8) | (BRS_CTRL/4));
	/* Set BRS right: note: this is an experimental value for BXO (=> PAL!) */
	WRITE_RPS1((540 << 7) | (5 << 19));  // 5 == vbi_start
	/* wait for brs_done */
	WRITE_RPS1(CMD_PAUSE | MASK_08);
	/* upload brs and video-dma3*/
	WRITE_RPS1(CMD_UPLOAD | MASK_08 | MASK_04);
	/* load mc2 register: enable dma3 */
	WRITE_RPS1(CMD_WR_REG | (1 << 8) | (MC1/4));
	WRITE_RPS1(MASK_20 | MASK_04);
	/* generate interrupt */
	WRITE_RPS1(CMD_INTERRUPT);
	/* stop rps1 */
	WRITE_RPS1(CMD_STOP);

	/* we have to do the workaround twice to be sure that
	   everything is ok */
	for(i = 0; i < 2; i++) {

		/* indicate to the irq handler that we do the workaround */
		saa7146_write(dev, MC2, MASK_31|MASK_15);

		saa7146_write(dev, NUM_LINE_BYTE3, (1<<16)|(2<<0));
		saa7146_write(dev, MC2, MASK_04|MASK_20);

		/* enable rps1 irqs */
		SAA7146_IER_ENABLE(dev,MASK_28);

		/* prepare to wait to be woken up by the irq-handler */
		add_wait_queue(&vv->vbi_wq, &wait);
		current->state = TASK_INTERRUPTIBLE;

		/* start rps1 to enable workaround */
		saa7146_write(dev, RPS_ADDR1, dev->d_rps1.dma_handle);
		saa7146_write(dev, MC1, (MASK_13 | MASK_29));

		schedule();

		DEB_VBI("brs bug workaround %d/1\n", i);

		remove_wait_queue(&vv->vbi_wq, &wait);
		current->state = TASK_RUNNING;

		/* disable rps1 irqs */
		SAA7146_IER_DISABLE(dev,MASK_28);

		/* stop video-dma3 */
		saa7146_write(dev, MC1, MASK_20);

		if(signal_pending(current)) {

			DEB_VBI("aborted (rps:0x%08x)\n",
				saa7146_read(dev, RPS_ADDR1));

			/* stop rps1 for sure */
			saa7146_write(dev, MC1, MASK_29);

			pci_free_consistent(dev->pci, 4096, cpu, dma_addr);
			return -EINTR;
		}
	}

	pci_free_consistent(dev->pci, 4096, cpu, dma_addr);
	return 0;
}
static int start_ts_capture(struct budget *budget)
{
	struct saa7146_dev *dev = budget->dev;

	dprintk(2, "budget: %p\n", budget);

	if (!budget->feeding || !budget->fe_synced)
		return 0;

	saa7146_write(dev, MC1, MASK_20);	

	memset(budget->grabbing, 0x00, budget->buffer_size);

	saa7146_write(dev, PCI_BT_V1, 0x001c0000 | (saa7146_read(dev, PCI_BT_V1) & ~0x001f0000));

	budget->ttbp = 0;


	switch(budget->card->type) {
	case BUDGET_FS_ACTIVY:
		saa7146_write(dev, DD1_INIT, 0x04000000);
		saa7146_write(dev, MC2, (MASK_09 | MASK_25));
		saa7146_write(dev, BRS_CTRL, 0x00000000);
		break;
	case BUDGET_PATCH:
		saa7146_write(dev, DD1_INIT, 0x00000200);
		saa7146_write(dev, MC2, (MASK_10 | MASK_26));
		saa7146_write(dev, BRS_CTRL, 0x60000000);
		break;
	case BUDGET_CIN1200C_MK3:
	case BUDGET_KNC1C_MK3:
	case BUDGET_KNC1C_TDA10024:
	case BUDGET_KNC1CP_MK3:
		if (budget->video_port == BUDGET_VIDEO_PORTA) {
			saa7146_write(dev, DD1_INIT, 0x06000200);
			saa7146_write(dev, MC2, (MASK_09 | MASK_25 | MASK_10 | MASK_26));
			saa7146_write(dev, BRS_CTRL, 0x00000000);
		} else {
			saa7146_write(dev, DD1_INIT, 0x00000600);
			saa7146_write(dev, MC2, (MASK_09 | MASK_25 | MASK_10 | MASK_26));
			saa7146_write(dev, BRS_CTRL, 0x60000000);
		}
		break;
	default:
		if (budget->video_port == BUDGET_VIDEO_PORTA) {
			saa7146_write(dev, DD1_INIT, 0x06000200);
			saa7146_write(dev, MC2, (MASK_09 | MASK_25 | MASK_10 | MASK_26));
			saa7146_write(dev, BRS_CTRL, 0x00000000);
		} else {
			saa7146_write(dev, DD1_INIT, 0x02000600);
			saa7146_write(dev, MC2, (MASK_09 | MASK_25 | MASK_10 | MASK_26));
			saa7146_write(dev, BRS_CTRL, 0x60000000);
		}
	}

	saa7146_write(dev, MC2, (MASK_08 | MASK_24));
	mdelay(10);

	saa7146_write(dev, BASE_ODD3, 0);
	if (budget->buffer_size > budget->buffer_height * budget->buffer_width) {
		
		saa7146_write(dev, BASE_EVEN3, budget->buffer_height * budget->buffer_width);
	} else {
		
		saa7146_write(dev, BASE_EVEN3, 0);
	}
	saa7146_write(dev, PROT_ADDR3, budget->buffer_size);
	saa7146_write(dev, BASE_PAGE3, budget->pt.dma | ME1 | 0x90);

	saa7146_write(dev, PITCH3, budget->buffer_width);
	saa7146_write(dev, NUM_LINE_BYTE3,
			(budget->buffer_height << 16) | budget->buffer_width);

	saa7146_write(dev, MC2, (MASK_04 | MASK_20));

	SAA7146_ISR_CLEAR(budget->dev, MASK_10);	
	SAA7146_IER_ENABLE(budget->dev, MASK_10);	
	saa7146_write(dev, MC1, (MASK_04 | MASK_20));	

	return 0;
}
Beispiel #25
0
/* fixme: add vbi stuff here */
static int dpc_probe(struct saa7146_dev* dev)
{
	struct dpc* dpc = NULL;

	dpc = kzalloc(sizeof(struct dpc), GFP_KERNEL);
	if( NULL == dpc ) {
		printk("dpc_v4l2.o: dpc_probe: not enough kernel memory.\n");
		return -ENOMEM;
	}

	/* FIXME: enable i2c-port pins, video-port-pins
	   video port pins should be enabled here ?! */
	saa7146_write(dev, MC1, (MASK_08 | MASK_24 | MASK_10 | MASK_26));

	dpc->i2c_adapter = (struct i2c_adapter) {
		.class = I2C_CLASS_TV_ANALOG,
		.name = "dpc7146",
	};
	saa7146_i2c_adapter_prepare(dev, &dpc->i2c_adapter, SAA7146_I2C_BUS_BIT_RATE_480);
	if(i2c_add_adapter(&dpc->i2c_adapter) < 0) {
		DEB_S(("cannot register i2c-device. skipping.\n"));
		kfree(dpc);
		return -EFAULT;
	}

	/* loop through all i2c-devices on the bus and look who is there */
	device_for_each_child(&dpc->i2c_adapter.dev, dpc, dpc_check_clients);

	/* check if all devices are present */
	if (!dpc->saa7111a) {
		DEB_D(("dpc_v4l2.o: dpc_attach failed for this device.\n"));
		i2c_del_adapter(&dpc->i2c_adapter);
		kfree(dpc);
		return -ENODEV;
	}

	/* all devices are present, probe was successful */
	DEB_D(("dpc_v4l2.o: dpc_probe succeeded for this device.\n"));

	/* we store the pointer in our private data field */
	dev->ext_priv = dpc;

	return 0;
}

/* bring hardware to a sane state. this has to be done, just in case someone
   wants to capture from this device before it has been properly initialized.
   the capture engine would badly fail, because no valid signal arrives on the
   saa7146, thus leading to timeouts and stuff. */
static int dpc_init_done(struct saa7146_dev* dev)
{
	struct dpc* dpc = (struct dpc*)dev->ext_priv;

	DEB_D(("dpc_v4l2.o: dpc_init_done called.\n"));

	/* initialize the helper ics to useful values */
	i2c_smbus_write_byte_data(dpc->saa7111a, 0x00, 0x11);

	i2c_smbus_write_byte_data(dpc->saa7111a, 0x02, 0xc0);
	i2c_smbus_write_byte_data(dpc->saa7111a, 0x03, 0x30);
	i2c_smbus_write_byte_data(dpc->saa7111a, 0x04, 0x00);
	i2c_smbus_write_byte_data(dpc->saa7111a, 0x05, 0x00);
	i2c_smbus_write_byte_data(dpc->saa7111a, 0x06, 0xde);
	i2c_smbus_write_byte_data(dpc->saa7111a, 0x07, 0xad);
	i2c_smbus_write_byte_data(dpc->saa7111a, 0x08, 0xa8);
	i2c_smbus_write_byte_data(dpc->saa7111a, 0x09, 0x00);
	i2c_smbus_write_byte_data(dpc->saa7111a, 0x0a, 0x80);
	i2c_smbus_write_byte_data(dpc->saa7111a, 0x0b, 0x47);
	i2c_smbus_write_byte_data(dpc->saa7111a, 0x0c, 0x40);
	i2c_smbus_write_byte_data(dpc->saa7111a, 0x0d, 0x00);
	i2c_smbus_write_byte_data(dpc->saa7111a, 0x0e, 0x03);

	i2c_smbus_write_byte_data(dpc->saa7111a, 0x10, 0xd0);
	i2c_smbus_write_byte_data(dpc->saa7111a, 0x11, 0x1c);
	i2c_smbus_write_byte_data(dpc->saa7111a, 0x12, 0xc1);
	i2c_smbus_write_byte_data(dpc->saa7111a, 0x13, 0x30);

	i2c_smbus_write_byte_data(dpc->saa7111a, 0x1f, 0x81);

	return 0;
}

static struct saa7146_ext_vv vv_data;

/* this function only gets called when the probing was successful */
static int dpc_attach(struct saa7146_dev* dev, struct saa7146_pci_extension_data *info)
{
	struct dpc* dpc = (struct dpc*)dev->ext_priv;

	DEB_D(("dpc_v4l2.o: dpc_attach called.\n"));

	/* checking for i2c-devices can be omitted here, because we
	   already did this in "dpc_vl42_probe" */

	saa7146_vv_init(dev,&vv_data);
	if( 0 != saa7146_register_device(&dpc->video_dev, dev, "dpc", VFL_TYPE_GRABBER)) {
		ERR(("cannot register capture v4l2 device. skipping.\n"));
		return -1;
	}

	/* initialization stuff (vbi) (only for revision > 0 and for extensions which want it)*/
	if( 0 != DPC_BOARD_CAN_DO_VBI(dev)) {
		if( 0 != saa7146_register_device(&dpc->vbi_dev, dev, "dpc", VFL_TYPE_VBI)) {
			ERR(("cannot register vbi v4l2 device. skipping.\n"));
		}
	}

	i2c_use_client(dpc->saa7111a);

	printk("dpc: found 'dpc7146 demonstration board'-%d.\n",dpc_num);
	dpc_num++;

	/* the rest */
	dpc->cur_input = 0;
	dpc_init_done(dev);

	return 0;
}

static int dpc_detach(struct saa7146_dev* dev)
{
	struct dpc* dpc = (struct dpc*)dev->ext_priv;

	DEB_EE(("dev:%p\n",dev));

	i2c_release_client(dpc->saa7111a);

	saa7146_unregister_device(&dpc->video_dev,dev);
	if( 0 != DPC_BOARD_CAN_DO_VBI(dev)) {
		saa7146_unregister_device(&dpc->vbi_dev,dev);
	}
	saa7146_vv_release(dev);

	dpc_num--;

	i2c_del_adapter(&dpc->i2c_adapter);
	kfree(dpc);
	return 0;
}

#ifdef axa
int dpc_vbi_bypass(struct saa7146_dev* dev)
{
	struct dpc* dpc = (struct dpc*)dev->ext_priv;

	int i = 1;

	/* switch bypass in saa7111a */
	if ( 0 != dpc->saa7111a->driver->command(dpc->saa7111a,SAA711X_VBI_BYPASS, &i)) {
		printk("dpc_v4l2.o: VBI_BYPASS: could not address saa7111a.\n");
		return -1;
	}

	return 0;
}
#endif

static int dpc_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
{
	struct saa7146_dev *dev = fh->dev;
	struct dpc* dpc = (struct dpc*)dev->ext_priv;
/*
	struct saa7146_vv *vv = dev->vv_data;
*/
	switch(cmd)
	{
	case VIDIOC_ENUMINPUT:
	{
		struct v4l2_input *i = arg;
		DEB_EE(("VIDIOC_ENUMINPUT %d.\n",i->index));

		if( i->index < 0 || i->index >= DPC_INPUTS) {
			return -EINVAL;
		}

		memcpy(i, &dpc_inputs[i->index], sizeof(struct v4l2_input));

		DEB_D(("dpc_v4l2.o: v4l2_ioctl: VIDIOC_ENUMINPUT %d.\n",i->index));
		return 0;
	}
	case VIDIOC_G_INPUT:
	{
		int *input = (int *)arg;
		*input = dpc->cur_input;

		DEB_D(("dpc_v4l2.o: VIDIOC_G_INPUT: %d\n",*input));
		return 0;
	}
	case VIDIOC_S_INPUT:
	{
		int	input = *(int *)arg;

		if (input < 0 || input >= DPC_INPUTS) {
			return -EINVAL;
		}

		dpc->cur_input = input;

		/* fixme: switch input here, switch audio, too! */
//		saa7146_set_hps_source_and_sync(dev, input_port_selection[input].hps_source, input_port_selection[input].hps_sync);
		printk("dpc_v4l2.o: VIDIOC_S_INPUT: fixme switch input.\n");

		return 0;
	}
	default:
/*
		DEB_D(("dpc_v4l2.o: v4l2_ioctl does not handle this ioctl.\n"));
*/
		return -ENOIOCTLCMD;
	}
	return 0;
}

static int std_callback(struct saa7146_dev* dev, struct saa7146_standard *std)
{
	return 0;
}

static struct saa7146_standard standard[] = {
	{
		.name	= "PAL", 	.id	= V4L2_STD_PAL,
		.v_offset	= 0x17,	.v_field 	= 288,
		.h_offset	= 0x14,	.h_pixels 	= 680,
		.v_max_out	= 576,	.h_max_out	= 768,
	}, {
		.name	= "NTSC", 	.id	= V4L2_STD_NTSC,
Beispiel #26
0
static int mxb_probe(struct saa7146_dev* dev)
{
    struct mxb* mxb = NULL;
    int result;

    result = request_module("saa7115");
    if (result < 0) {
        printk("mxb: saa7111 i2c module not available.\n");
        return -ENODEV;
    }
    result = request_module("tea6420");
    if (result < 0) {
        printk("mxb: tea6420 i2c module not available.\n");
        return -ENODEV;
    }
    result = request_module("tea6415c");
    if (result < 0) {
        printk("mxb: tea6415c i2c module not available.\n");
        return -ENODEV;
    }
    result = request_module("tda9840");
    if (result < 0) {
        printk("mxb: tda9840 i2c module not available.\n");
        return -ENODEV;
    }
    result = request_module("tuner");
    if (result < 0) {
        printk("mxb: tuner i2c module not available.\n");
        return -ENODEV;
    }

    mxb = kzalloc(sizeof(struct mxb), GFP_KERNEL);
    if( NULL == mxb ) {
        DEB_D(("not enough kernel memory.\n"));
        return -ENOMEM;
    }

    mxb->i2c_adapter = (struct i2c_adapter) {
        .class = I2C_CLASS_TV_ANALOG,
    };

    snprintf(mxb->i2c_adapter.name, sizeof(mxb->i2c_adapter.name), "mxb%d", mxb_num);

    saa7146_i2c_adapter_prepare(dev, &mxb->i2c_adapter, SAA7146_I2C_BUS_BIT_RATE_480);
    if(i2c_add_adapter(&mxb->i2c_adapter) < 0) {
        DEB_S(("cannot register i2c-device. skipping.\n"));
        kfree(mxb);
        return -EFAULT;
    }

    /* loop through all i2c-devices on the bus and look who is there */
    device_for_each_child(&mxb->i2c_adapter.dev, mxb, mxb_check_clients);

    /* check if all devices are present */
    if (!mxb->tea6420_1 || !mxb->tea6420_2 || !mxb->tea6415c ||
            !mxb->tda9840 || !mxb->saa7111a || !mxb->tuner) {
        printk("mxb: did not find all i2c devices. aborting\n");
        i2c_del_adapter(&mxb->i2c_adapter);
        kfree(mxb);
        return -ENODEV;
    }

    /* all devices are present, probe was successful */

    /* we store the pointer in our private data field */
    dev->ext_priv = mxb;

    return 0;
}

/* some init data for the saa7740, the so-called 'sound arena module'.
   there are no specs available, so we simply use some init values */
static struct {
    int	length;
    char	data[9];
} mxb_saa7740_init[] = {
    { 3, { 0x80, 0x00, 0x00 } },{ 3, { 0x80, 0x89, 0x00 } },
    { 3, { 0x80, 0xb0, 0x0a } },{ 3, { 0x00, 0x00, 0x00 } },
    { 3, { 0x49, 0x00, 0x00 } },{ 3, { 0x4a, 0x00, 0x00 } },
    { 3, { 0x4b, 0x00, 0x00 } },{ 3, { 0x4c, 0x00, 0x00 } },
    { 3, { 0x4d, 0x00, 0x00 } },{ 3, { 0x4e, 0x00, 0x00 } },
    { 3, { 0x4f, 0x00, 0x00 } },{ 3, { 0x50, 0x00, 0x00 } },
    { 3, { 0x51, 0x00, 0x00 } },{ 3, { 0x52, 0x00, 0x00 } },
    { 3, { 0x53, 0x00, 0x00 } },{ 3, { 0x54, 0x00, 0x00 } },
    { 3, { 0x55, 0x00, 0x00 } },{ 3, { 0x56, 0x00, 0x00 } },
    { 3, { 0x57, 0x00, 0x00 } },{ 3, { 0x58, 0x00, 0x00 } },
    { 3, { 0x59, 0x00, 0x00 } },{ 3, { 0x5a, 0x00, 0x00 } },
    { 3, { 0x5b, 0x00, 0x00 } },{ 3, { 0x5c, 0x00, 0x00 } },
    { 3, { 0x5d, 0x00, 0x00 } },{ 3, { 0x5e, 0x00, 0x00 } },
    { 3, { 0x5f, 0x00, 0x00 } },{ 3, { 0x60, 0x00, 0x00 } },
    { 3, { 0x61, 0x00, 0x00 } },{ 3, { 0x62, 0x00, 0x00 } },
    { 3, { 0x63, 0x00, 0x00 } },{ 3, { 0x64, 0x00, 0x00 } },
    { 3, { 0x65, 0x00, 0x00 } },{ 3, { 0x66, 0x00, 0x00 } },
    { 3, { 0x67, 0x00, 0x00 } },{ 3, { 0x68, 0x00, 0x00 } },
    { 3, { 0x69, 0x00, 0x00 } },{ 3, { 0x6a, 0x00, 0x00 } },
    { 3, { 0x6b, 0x00, 0x00 } },{ 3, { 0x6c, 0x00, 0x00 } },
    { 3, { 0x6d, 0x00, 0x00 } },{ 3, { 0x6e, 0x00, 0x00 } },
    { 3, { 0x6f, 0x00, 0x00 } },{ 3, { 0x70, 0x00, 0x00 } },
    { 3, { 0x71, 0x00, 0x00 } },{ 3, { 0x72, 0x00, 0x00 } },
    { 3, { 0x73, 0x00, 0x00 } },{ 3, { 0x74, 0x00, 0x00 } },
    { 3, { 0x75, 0x00, 0x00 } },{ 3, { 0x76, 0x00, 0x00 } },
    { 3, { 0x77, 0x00, 0x00 } },{ 3, { 0x41, 0x00, 0x42 } },
    { 3, { 0x42, 0x10, 0x42 } },{ 3, { 0x43, 0x20, 0x42 } },
    { 3, { 0x44, 0x30, 0x42 } },{ 3, { 0x45, 0x00, 0x01 } },
    { 3, { 0x46, 0x00, 0x01 } },{ 3, { 0x47, 0x00, 0x01 } },
    { 3, { 0x48, 0x00, 0x01 } },
    { 9, { 0x01, 0x03, 0xc5, 0x5c, 0x7a, 0x85, 0x01, 0x00, 0x54 } },
    { 9, { 0x21, 0x03, 0xc5, 0x5c, 0x7a, 0x85, 0x01, 0x00, 0x54 } },
    { 9, { 0x09, 0x0b, 0xb4, 0x6b, 0x74, 0x85, 0x95, 0x00, 0x34 } },
    { 9, { 0x29, 0x0b, 0xb4, 0x6b, 0x74, 0x85, 0x95, 0x00, 0x34 } },
    { 9, { 0x11, 0x17, 0x43, 0x62, 0x68, 0x89, 0xd1, 0xff, 0xb0 } },
    { 9, { 0x31, 0x17, 0x43, 0x62, 0x68, 0x89, 0xd1, 0xff, 0xb0 } },
    { 9, { 0x19, 0x20, 0x62, 0x51, 0x5a, 0x95, 0x19, 0x01, 0x50 } },
    { 9, { 0x39, 0x20, 0x62, 0x51, 0x5a, 0x95, 0x19, 0x01, 0x50 } },
    { 9, { 0x05, 0x3e, 0xd2, 0x69, 0x4e, 0x9a, 0x51, 0x00, 0xf0 } },
    { 9, { 0x25, 0x3e, 0xd2, 0x69, 0x4e, 0x9a, 0x51, 0x00, 0xf0 } },
    { 9, { 0x0d, 0x3d, 0xa1, 0x40, 0x7d, 0x9f, 0x29, 0xfe, 0x14 } },
    { 9, { 0x2d, 0x3d, 0xa1, 0x40, 0x7d, 0x9f, 0x29, 0xfe, 0x14 } },
    { 9, { 0x15, 0x73, 0xa1, 0x50, 0x5d, 0xa6, 0xf5, 0xfe, 0x38 } },
    { 9, { 0x35, 0x73, 0xa1, 0x50, 0x5d, 0xa6, 0xf5, 0xfe, 0x38 } },
    { 9, { 0x1d, 0xed, 0xd0, 0x68, 0x29, 0xb4, 0xe1, 0x00, 0xb8 } },
    { 9, { 0x3d, 0xed, 0xd0, 0x68, 0x29, 0xb4, 0xe1, 0x00, 0xb8 } },
    { 3, { 0x80, 0xb3, 0x0a } },
    {-1, { 0 } }
};

/* bring hardware to a sane state. this has to be done, just in case someone
   wants to capture from this device before it has been properly initialized.
   the capture engine would badly fail, because no valid signal arrives on the
   saa7146, thus leading to timeouts and stuff. */
static int mxb_init_done(struct saa7146_dev* dev)
{
    struct mxb* mxb = (struct mxb*)dev->ext_priv;
    struct i2c_msg msg;
    struct tuner_setup tun_setup;
    v4l2_std_id std = V4L2_STD_PAL_BG;
    struct v4l2_routing route;

    int i = 0, err = 0;
    struct tea6415c_multiplex vm;

    /* select video mode in saa7111a */
    mxb->saa7111a->driver->command(mxb->saa7111a, VIDIOC_S_STD, &std);

    /* select tuner-output on saa7111a */
    i = 0;
    route.input = SAA7115_COMPOSITE0;
    route.output = SAA7111_FMT_CCIR | SAA7111_VBI_BYPASS;
    mxb->saa7111a->driver->command(mxb->saa7111a, VIDIOC_INT_S_VIDEO_ROUTING, &route);

    /* select a tuner type */
    tun_setup.mode_mask = T_ANALOG_TV;
    tun_setup.addr = ADDR_UNSET;
    tun_setup.type = TUNER_PHILIPS_PAL;
    mxb->tuner->driver->command(mxb->tuner, TUNER_SET_TYPE_ADDR, &tun_setup);
    /* tune in some frequency on tuner */
    mxb->cur_freq.tuner = 0;
    mxb->cur_freq.type = V4L2_TUNER_ANALOG_TV;
    mxb->cur_freq.frequency = freq;
    mxb->tuner->driver->command(mxb->tuner, VIDIOC_S_FREQUENCY,
                                &mxb->cur_freq);

    /* set a default video standard */
    mxb->tuner->driver->command(mxb->tuner, VIDIOC_S_STD, &std);

    /* mute audio on tea6420s */
    mxb->tea6420_1->driver->command(mxb->tea6420_1, TEA6420_SWITCH, &TEA6420_line[6][0]);
    mxb->tea6420_2->driver->command(mxb->tea6420_2, TEA6420_SWITCH, &TEA6420_line[6][1]);
    mxb->tea6420_1->driver->command(mxb->tea6420_1, TEA6420_SWITCH, &TEA6420_cd[6][0]);
    mxb->tea6420_2->driver->command(mxb->tea6420_2, TEA6420_SWITCH, &TEA6420_cd[6][1]);

    /* switch to tuner-channel on tea6415c*/
    vm.out = 17;
    vm.in  = 3;
    mxb->tea6415c->driver->command(mxb->tea6415c, TEA6415C_SWITCH, &vm);

    /* select tuner-output on multicable on tea6415c*/
    vm.in  = 3;
    vm.out = 13;
    mxb->tea6415c->driver->command(mxb->tea6415c, TEA6415C_SWITCH, &vm);

    /* the rest for mxb */
    mxb->cur_input = 0;
    mxb->cur_mute = 1;

    mxb->cur_mode = V4L2_TUNER_MODE_STEREO;

    /* check if the saa7740 (aka 'sound arena module') is present
       on the mxb. if so, we must initialize it. due to lack of
       informations about the saa7740, the values were reverse
       engineered. */
    msg.addr = 0x1b;
    msg.flags = 0;
    msg.len = mxb_saa7740_init[0].length;
    msg.buf = &mxb_saa7740_init[0].data[0];

    err = i2c_transfer(&mxb->i2c_adapter, &msg, 1);
    if (err == 1) {
        /* the sound arena module is a pos, that's probably the reason
           philips refuses to hand out a datasheet for the saa7740...
           it seems to screw up the i2c bus, so we disable fast irq
           based i2c transactions here and rely on the slow and safe
           polling method ... */
        extension.flags &= ~SAA7146_USE_I2C_IRQ;
        for (i = 1; ; i++) {
            if (-1 == mxb_saa7740_init[i].length)
                break;

            msg.len = mxb_saa7740_init[i].length;
            msg.buf = &mxb_saa7740_init[i].data[0];
            err = i2c_transfer(&mxb->i2c_adapter, &msg, 1);
            if (err != 1) {
                DEB_D(("failed to initialize 'sound arena module'.\n"));
                goto err;
            }
        }
        INFO(("'sound arena module' detected.\n"));
    }
err:
    /* the rest for saa7146: you should definitely set some basic values
       for the input-port handling of the saa7146. */

    /* ext->saa has been filled by the core driver */

    /* some stuff is done via variables */
    saa7146_set_hps_source_and_sync(dev, input_port_selection[mxb->cur_input].hps_source,
                                    input_port_selection[mxb->cur_input].hps_sync);

    /* some stuff is done via direct write to the registers */

    /* this is ugly, but because of the fact that this is completely
       hardware dependend, it should be done directly... */
    saa7146_write(dev, DD1_STREAM_B,	0x00000000);
    saa7146_write(dev, DD1_INIT,		0x02000200);
    saa7146_write(dev, MC2, (MASK_09 | MASK_25 | MASK_10 | MASK_26));

    return 0;
}

/* interrupt-handler. this gets called when irq_mask is != 0.
   it must clear the interrupt-bits in irq_mask it has handled */
/*
void mxb_irq_bh(struct saa7146_dev* dev, u32* irq_mask)
{
	struct mxb* mxb = (struct mxb*)dev->ext_priv;
}
*/

static struct saa7146_ext_vv vv_data;

/* this function only gets called when the probing was successful */
static int mxb_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_data *info)
{
    struct mxb *mxb = (struct mxb *)dev->ext_priv;

    DEB_EE(("dev:%p\n", dev));

    /* checking for i2c-devices can be omitted here, because we
       already did this in "mxb_vl42_probe" */

    saa7146_vv_init(dev, &vv_data);
    if (saa7146_register_device(&mxb->video_dev, dev, "mxb", VFL_TYPE_GRABBER)) {
        ERR(("cannot register capture v4l2 device. skipping.\n"));
        return -1;
    }

    /* initialization stuff (vbi) (only for revision > 0 and for extensions which want it)*/
    if (MXB_BOARD_CAN_DO_VBI(dev)) {
        if (saa7146_register_device(&mxb->vbi_dev, dev, "mxb", VFL_TYPE_VBI)) {
            ERR(("cannot register vbi v4l2 device. skipping.\n"));
        }
    }

    i2c_use_client(mxb->tea6420_1);
    i2c_use_client(mxb->tea6420_2);
    i2c_use_client(mxb->tea6415c);
    i2c_use_client(mxb->tda9840);
    i2c_use_client(mxb->saa7111a);
    i2c_use_client(mxb->tuner);

    printk("mxb: found Multimedia eXtension Board #%d.\n", mxb_num);

    mxb_num++;
    mxb_init_done(dev);
    return 0;
}

static int mxb_detach(struct saa7146_dev *dev)
{
    struct mxb *mxb = (struct mxb *)dev->ext_priv;

    DEB_EE(("dev:%p\n", dev));

    i2c_release_client(mxb->tea6420_1);
    i2c_release_client(mxb->tea6420_2);
    i2c_release_client(mxb->tea6415c);
    i2c_release_client(mxb->tda9840);
    i2c_release_client(mxb->saa7111a);
    i2c_release_client(mxb->tuner);

    saa7146_unregister_device(&mxb->video_dev,dev);
    if (MXB_BOARD_CAN_DO_VBI(dev))
        saa7146_unregister_device(&mxb->vbi_dev, dev);
    saa7146_vv_release(dev);

    mxb_num--;

    i2c_del_adapter(&mxb->i2c_adapter);
    kfree(mxb);

    return 0;
}

static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
{
    struct saa7146_dev *dev = fh->dev;
    struct mxb *mxb = (struct mxb *)dev->ext_priv;
    struct saa7146_vv *vv = dev->vv_data;

    switch(cmd) {
    case VIDIOC_ENUMINPUT:
    {
        struct v4l2_input *i = arg;

        DEB_EE(("VIDIOC_ENUMINPUT %d.\n",i->index));
        if (i->index < 0 || i->index >= MXB_INPUTS)
            return -EINVAL;
        memcpy(i, &mxb_inputs[i->index], sizeof(struct v4l2_input));
        return 0;
    }
    /* the saa7146 provides some controls (brightness, contrast, saturation)
       which gets registered *after* this function. because of this we have
       to return with a value != 0 even if the function succeded.. */
    case VIDIOC_QUERYCTRL:
    {
        struct v4l2_queryctrl *qc = arg;
        int i;

        for (i = MAXCONTROLS - 1; i >= 0; i--) {
            if (mxb_controls[i].id == qc->id) {
                *qc = mxb_controls[i];
                DEB_D(("VIDIOC_QUERYCTRL %d.\n", qc->id));
                return 0;
            }
        }
        return -EAGAIN;
    }
    case VIDIOC_G_CTRL:
    {
        struct v4l2_control *vc = arg;
        int i;

        for (i = MAXCONTROLS - 1; i >= 0; i--) {
            if (mxb_controls[i].id == vc->id)
                break;
        }

        if (i < 0)
            return -EAGAIN;

        if (vc->id == V4L2_CID_AUDIO_MUTE) {
            vc->value = mxb->cur_mute;
            DEB_D(("VIDIOC_G_CTRL V4L2_CID_AUDIO_MUTE:%d.\n", vc->value));
            return 0;
        }

        DEB_EE(("VIDIOC_G_CTRL V4L2_CID_AUDIO_MUTE:%d.\n", vc->value));
        return 0;
    }

    case VIDIOC_S_CTRL:
    {
        struct v4l2_control *vc = arg;
        int i = 0;

        for (i = MAXCONTROLS - 1; i >= 0; i--) {
            if (mxb_controls[i].id == vc->id)
                break;
        }

        if (i < 0)
            return -EAGAIN;

        if (vc->id == V4L2_CID_AUDIO_MUTE) {
            mxb->cur_mute = vc->value;
            if (!vc->value) {
                /* switch the audio-source */
                mxb->tea6420_1->driver->command(mxb->tea6420_1, TEA6420_SWITCH,
                                                &TEA6420_line[video_audio_connect[mxb->cur_input]][0]);
                mxb->tea6420_2->driver->command(mxb->tea6420_2, TEA6420_SWITCH,
                                                &TEA6420_line[video_audio_connect[mxb->cur_input]][1]);
            } else {
                mxb->tea6420_1->driver->command(mxb->tea6420_1, TEA6420_SWITCH,
                                                &TEA6420_line[6][0]);
                mxb->tea6420_2->driver->command(mxb->tea6420_2, TEA6420_SWITCH,
                                                &TEA6420_line[6][1]);
            }
            DEB_EE(("VIDIOC_S_CTRL, V4L2_CID_AUDIO_MUTE: %d.\n", vc->value));
        }
        return 0;
    }
    case VIDIOC_G_INPUT:
    {
        int *input = (int *)arg;
        *input = mxb->cur_input;

        DEB_EE(("VIDIOC_G_INPUT %d.\n", *input));
        return 0;
    }
    case VIDIOC_S_INPUT:
    {
        int input = *(int *)arg;
        struct tea6415c_multiplex vm;
        struct v4l2_routing route;
        int i = 0;

        DEB_EE(("VIDIOC_S_INPUT %d.\n", input));

        if (input < 0 || input >= MXB_INPUTS)
            return -EINVAL;

        mxb->cur_input = input;

        saa7146_set_hps_source_and_sync(dev, input_port_selection[input].hps_source,
                                        input_port_selection[input].hps_sync);

        /* prepare switching of tea6415c and saa7111a;
           have a look at the 'background'-file for further informations  */
        switch (input) {
        case TUNER:
            i = SAA7115_COMPOSITE0;
            vm.in  = 3;
            vm.out = 17;

            if (mxb->tea6415c->driver->command(mxb->tea6415c, TEA6415C_SWITCH, &vm)) {
                printk(KERN_ERR "VIDIOC_S_INPUT: could not address tea6415c #1\n");
                return -EFAULT;
            }
            /* connect tuner-output always to multicable */
            vm.in  = 3;
            vm.out = 13;
            break;
        case AUX3_YC:
            /* nothing to be done here. aux3_yc is
               directly connected to the saa711a */
            i = SAA7115_SVIDEO1;
            break;
        case AUX3:
            /* nothing to be done here. aux3 is
               directly connected to the saa711a */
            i = SAA7115_COMPOSITE1;
            break;
        case AUX1:
            i = SAA7115_COMPOSITE0;
            vm.in  = 1;
            vm.out = 17;
            break;
        }

        /* switch video in tea6415c only if necessary */
        switch (input) {
        case TUNER:
        case AUX1:
            if (mxb->tea6415c->driver->command(mxb->tea6415c, TEA6415C_SWITCH, &vm)) {
                printk(KERN_ERR "VIDIOC_S_INPUT: could not address tea6415c #3\n");
                return -EFAULT;
            }
            break;
        default:
            break;
        }

        /* switch video in saa7111a */
        route.input = i;
        route.output = 0;
        if (mxb->saa7111a->driver->command(mxb->saa7111a, VIDIOC_INT_S_VIDEO_ROUTING, &route))
            printk("VIDIOC_S_INPUT: could not address saa7111a #1.\n");

        /* switch the audio-source only if necessary */
        if( 0 == mxb->cur_mute ) {
            mxb->tea6420_1->driver->command(mxb->tea6420_1, TEA6420_SWITCH,
                                            &TEA6420_line[video_audio_connect[input]][0]);
            mxb->tea6420_2->driver->command(mxb->tea6420_2, TEA6420_SWITCH,
                                            &TEA6420_line[video_audio_connect[input]][1]);
        }

        return 0;
    }
    case VIDIOC_G_TUNER:
    {
        struct v4l2_tuner *t = arg;

        if (t->index) {
            DEB_D(("VIDIOC_G_TUNER: channel %d does not have a tuner attached.\n", t->index));
            return -EINVAL;
        }

        DEB_EE(("VIDIOC_G_TUNER: %d\n", t->index));

        memset(t, 0, sizeof(*t));
        i2c_clients_command(&mxb->i2c_adapter, cmd, arg);

        strlcpy(t->name, "TV Tuner", sizeof(t->name));
        t->type = V4L2_TUNER_ANALOG_TV;
        t->capability = V4L2_TUNER_CAP_NORM | V4L2_TUNER_CAP_STEREO | \
                        V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2 | V4L2_TUNER_CAP_SAP;
        t->audmode = mxb->cur_mode;
        return 0;
    }
    case VIDIOC_S_TUNER:
    {
        struct v4l2_tuner *t = arg;

        if (t->index) {
            DEB_D(("VIDIOC_S_TUNER: channel %d does not have a tuner attached.\n",t->index));
            return -EINVAL;
        }

        mxb->cur_mode = t->audmode;
        i2c_clients_command(&mxb->i2c_adapter, cmd, arg);
        return 0;
    }
    case VIDIOC_G_FREQUENCY:
    {
        struct v4l2_frequency *f = arg;

        if (mxb->cur_input) {
            DEB_D(("VIDIOC_G_FREQ: channel %d does not have a tuner!\n",
                   mxb->cur_input));
            return -EINVAL;
        }

        *f = mxb->cur_freq;

        DEB_EE(("VIDIOC_G_FREQ: freq:0x%08x.\n", mxb->cur_freq.frequency));
        return 0;
    }
    case VIDIOC_S_FREQUENCY:
    {
        struct v4l2_frequency *f = arg;

        if (f->tuner)
            return -EINVAL;

        if (V4L2_TUNER_ANALOG_TV != f->type)
            return -EINVAL;

        if (mxb->cur_input) {
            DEB_D(("VIDIOC_S_FREQ: channel %d does not have a tuner!\n", mxb->cur_input));
            return -EINVAL;
        }

        mxb->cur_freq = *f;
        DEB_EE(("VIDIOC_S_FREQUENCY: freq:0x%08x.\n", mxb->cur_freq.frequency));

        /* tune in desired frequency */
        mxb->tuner->driver->command(mxb->tuner, VIDIOC_S_FREQUENCY, &mxb->cur_freq);

        /* hack: changing the frequency should invalidate the vbi-counter (=> alevt) */
        spin_lock(&dev->slock);
        vv->vbi_fieldcount = 0;
        spin_unlock(&dev->slock);

        return 0;
    }
    case MXB_S_AUDIO_CD:
    {
        int i = *(int*)arg;

        if (i < 0 || i >= MXB_AUDIOS) {
            DEB_D(("illegal argument to MXB_S_AUDIO_CD: i:%d.\n",i));
            return -EINVAL;
        }

        DEB_EE(("MXB_S_AUDIO_CD: i:%d.\n",i));

        mxb->tea6420_1->driver->command(mxb->tea6420_1,TEA6420_SWITCH, &TEA6420_cd[i][0]);
        mxb->tea6420_2->driver->command(mxb->tea6420_2,TEA6420_SWITCH, &TEA6420_cd[i][1]);

        return 0;
    }
    case MXB_S_AUDIO_LINE:
    {
        int i = *(int*)arg;

        if (i < 0 || i >= MXB_AUDIOS) {
            DEB_D(("illegal argument to MXB_S_AUDIO_LINE: i:%d.\n",i));
            return -EINVAL;
        }

        DEB_EE(("MXB_S_AUDIO_LINE: i:%d.\n",i));
        mxb->tea6420_1->driver->command(mxb->tea6420_1,TEA6420_SWITCH, &TEA6420_line[i][0]);
        mxb->tea6420_2->driver->command(mxb->tea6420_2,TEA6420_SWITCH, &TEA6420_line[i][1]);

        return 0;
    }
    case VIDIOC_G_AUDIO:
    {
        struct v4l2_audio *a = arg;

        if (a->index < 0 || a->index > MXB_INPUTS) {
            DEB_D(("VIDIOC_G_AUDIO %d out of range.\n", a->index));
            return -EINVAL;
        }

        DEB_EE(("VIDIOC_G_AUDIO %d.\n", a->index));
        memcpy(a, &mxb_audios[video_audio_connect[mxb->cur_input]], sizeof(struct v4l2_audio));

        return 0;
    }
    case VIDIOC_S_AUDIO:
    {
        struct v4l2_audio *a = arg;

        DEB_D(("VIDIOC_S_AUDIO %d.\n", a->index));
        return 0;
    }
#ifdef CONFIG_VIDEO_ADV_DEBUG
    case VIDIOC_DBG_S_REGISTER:
    case VIDIOC_DBG_G_REGISTER:
        i2c_clients_command(&mxb->i2c_adapter, cmd, arg);
        return 0;
#endif
    default:
        /*
        		DEB2(printk("does not handle this ioctl.\n"));
        */
        return -ENOIOCTLCMD;
    }
    return 0;
}

static int std_callback(struct saa7146_dev *dev, struct saa7146_standard *standard)
{
    struct mxb *mxb = (struct mxb *)dev->ext_priv;
    int zero = 0;
    int one = 1;

    if (V4L2_STD_PAL_I == standard->id) {
        v4l2_std_id std = V4L2_STD_PAL_I;

        DEB_D(("VIDIOC_S_STD: setting mxb for PAL_I.\n"));
        /* set the 7146 gpio register -- I don't know what this does exactly */
        saa7146_write(dev, GPIO_CTRL, 0x00404050);
        /* unset the 7111 gpio register -- I don't know what this does exactly */
        mxb->saa7111a->driver->command(mxb->saa7111a, VIDIOC_INT_S_GPIO, &zero);
        mxb->tuner->driver->command(mxb->tuner, VIDIOC_S_STD, &std);
    } else {
        v4l2_std_id std = V4L2_STD_PAL_BG;

        DEB_D(("VIDIOC_S_STD: setting mxb for PAL/NTSC/SECAM.\n"));
        /* set the 7146 gpio register -- I don't know what this does exactly */
        saa7146_write(dev, GPIO_CTRL, 0x00404050);
        /* set the 7111 gpio register -- I don't know what this does exactly */
        mxb->saa7111a->driver->command(mxb->saa7111a, VIDIOC_INT_S_GPIO, &one);
        mxb->tuner->driver->command(mxb->tuner, VIDIOC_S_STD, &std);
    }
    return 0;
}

static struct saa7146_standard standard[] = {
    {
        .name	= "PAL-BG", 	.id	= V4L2_STD_PAL_BG,
        .v_offset	= 0x17,	.v_field 	= 288,
        .h_offset	= 0x14,	.h_pixels 	= 680,
        .v_max_out	= 576,	.h_max_out	= 768,
    }, {
        .name	= "PAL-I", 	.id	= V4L2_STD_PAL_I,
Beispiel #27
0
static int start_ts_capture(struct budget *budget)
{
	struct saa7146_dev *dev = budget->dev;

	dprintk(2, "budget: %p\n", budget);

	if (!budget->feeding || !budget->fe_synced)
		return 0;

	saa7146_write(dev, MC1, MASK_20);	// DMA3 off

	memset(budget->grabbing, 0x00, budget->buffer_size);

	saa7146_write(dev, PCI_BT_V1, 0x001c0000 | (saa7146_read(dev, PCI_BT_V1) & ~0x001f0000));

	budget->ttbp = 0;

	/*
	 *  Signal path on the Activy:
	 *
	 *  tuner -> SAA7146 port A -> SAA7146 BRS -> SAA7146 DMA3 -> memory
	 *
	 *  Since the tuner feeds 204 bytes packets into the SAA7146,
	 *  DMA3 is configured to strip the trailing 16 FEC bytes:
	 *      Pitch: 188, NumBytes3: 188, NumLines3: 1024
	 */

	switch(budget->card->type) {
	case BUDGET_FS_ACTIVY:
		saa7146_write(dev, DD1_INIT, 0x04000000);
		saa7146_write(dev, MC2, (MASK_09 | MASK_25));
		saa7146_write(dev, BRS_CTRL, 0x00000000);
		break;
	case BUDGET_PATCH:
		saa7146_write(dev, DD1_INIT, 0x00000200);
		saa7146_write(dev, MC2, (MASK_10 | MASK_26));
		saa7146_write(dev, BRS_CTRL, 0x60000000);
		break;
	case BUDGET_CIN1200C_MK3:
	case BUDGET_KNC1C_MK3:
	case BUDGET_KNC1C_TDA10024:
	case BUDGET_KNC1CP_MK3:
		if (budget->video_port == BUDGET_VIDEO_PORTA) {
			saa7146_write(dev, DD1_INIT, 0x06000200);
			saa7146_write(dev, MC2, (MASK_09 | MASK_25 | MASK_10 | MASK_26));
			saa7146_write(dev, BRS_CTRL, 0x00000000);
		} else {
			saa7146_write(dev, DD1_INIT, 0x00000600);
			saa7146_write(dev, MC2, (MASK_09 | MASK_25 | MASK_10 | MASK_26));
			saa7146_write(dev, BRS_CTRL, 0x60000000);
		}
		break;
	default:
		if (budget->video_port == BUDGET_VIDEO_PORTA) {
			saa7146_write(dev, DD1_INIT, 0x06000200);
			saa7146_write(dev, MC2, (MASK_09 | MASK_25 | MASK_10 | MASK_26));
			saa7146_write(dev, BRS_CTRL, 0x00000000);
		} else {
			saa7146_write(dev, DD1_INIT, 0x02000600);
			saa7146_write(dev, MC2, (MASK_09 | MASK_25 | MASK_10 | MASK_26));
			saa7146_write(dev, BRS_CTRL, 0x60000000);
		}
	}

	saa7146_write(dev, MC2, (MASK_08 | MASK_24));
	mdelay(10);

	saa7146_write(dev, BASE_ODD3, 0);
	if (budget->buffer_size > budget->buffer_height * budget->buffer_width) {
		// using odd/even buffers
		saa7146_write(dev, BASE_EVEN3, budget->buffer_height * budget->buffer_width);
	} else {
		// using a single buffer
		saa7146_write(dev, BASE_EVEN3, 0);
	}
	saa7146_write(dev, PROT_ADDR3, budget->buffer_size);
	saa7146_write(dev, BASE_PAGE3, budget->pt.dma | ME1 | 0x90);

	saa7146_write(dev, PITCH3, budget->buffer_width);
	saa7146_write(dev, NUM_LINE_BYTE3,
			(budget->buffer_height << 16) | budget->buffer_width);

	saa7146_write(dev, MC2, (MASK_04 | MASK_20));

	SAA7146_ISR_CLEAR(budget->dev, MASK_10);	/* VPE */
	SAA7146_IER_ENABLE(budget->dev, MASK_10);	/* VPE */
	saa7146_write(dev, MC1, (MASK_04 | MASK_20));	/* DMA3 on */

	return 0;
}
static int saa7146_init_one(struct pci_dev *pci, const struct pci_device_id *ent)
{
	struct saa7146_pci_extension_data *pci_ext = (struct saa7146_pci_extension_data *)ent->driver_data;
	struct saa7146_extension *ext = pci_ext->ext;
	struct saa7146_dev *dev;
	int err = -ENOMEM;

	
	dev = kzalloc(sizeof(struct saa7146_dev), GFP_KERNEL);
	if (!dev) {
		ERR("out of memory\n");
		goto out;
	}

	DEB_EE("pci:%p\n", pci);

	err = pci_enable_device(pci);
	if (err < 0) {
		ERR("pci_enable_device() failed\n");
		goto err_free;
	}

	
	pci_set_master(pci);

	dev->pci = pci;

	
	dev->revision = pci->revision;

	

	err = pci_request_region(pci, 0, "saa7146");
	if (err < 0)
		goto err_disable;

	dev->mem = ioremap(pci_resource_start(pci, 0),
			   pci_resource_len(pci, 0));
	if (!dev->mem) {
		ERR("ioremap() failed\n");
		err = -ENODEV;
		goto err_release;
	}


	
	saa7146_write(dev, IER, 0);

	
	saa7146_write(dev, MC1, 0x30ff0000);

	
	saa7146_write(dev, MC2, 0xf8000000);

	
	err = request_irq(pci->irq, interrupt_hw, IRQF_SHARED | IRQF_DISABLED,
			  dev->name, dev);
	if (err < 0) {
		ERR("request_irq() failed\n");
		goto err_unmap;
	}

	err = -ENOMEM;

	
	dev->d_rps0.cpu_addr = pci_alloc_consistent(pci, SAA7146_RPS_MEM,
						    &dev->d_rps0.dma_handle);
	if (!dev->d_rps0.cpu_addr)
		goto err_free_irq;
	memset(dev->d_rps0.cpu_addr, 0x0, SAA7146_RPS_MEM);

	dev->d_rps1.cpu_addr = pci_alloc_consistent(pci, SAA7146_RPS_MEM,
						    &dev->d_rps1.dma_handle);
	if (!dev->d_rps1.cpu_addr)
		goto err_free_rps0;
	memset(dev->d_rps1.cpu_addr, 0x0, SAA7146_RPS_MEM);

	dev->d_i2c.cpu_addr = pci_alloc_consistent(pci, SAA7146_RPS_MEM,
						   &dev->d_i2c.dma_handle);
	if (!dev->d_i2c.cpu_addr)
		goto err_free_rps1;
	memset(dev->d_i2c.cpu_addr, 0x0, SAA7146_RPS_MEM);

	

	
	sprintf(dev->name, "saa7146 (%d)", saa7146_num);

	pr_info("found saa7146 @ mem %p (revision %d, irq %d) (0x%04x,0x%04x)\n",
		dev->mem, dev->revision, pci->irq,
		pci->subsystem_vendor, pci->subsystem_device);
	dev->ext = ext;

	mutex_init(&dev->v4l2_lock);
	spin_lock_init(&dev->int_slock);
	spin_lock_init(&dev->slock);

	mutex_init(&dev->i2c_lock);

	dev->module = THIS_MODULE;
	init_waitqueue_head(&dev->i2c_wq);

	
	saa7146_write(dev, PCI_BT_V1, 0x1c00101f);

	

	err = -ENODEV;

	if (ext->probe && ext->probe(dev)) {
		DEB_D("ext->probe() failed for %p. skipping device.\n", dev);
		goto err_free_i2c;
	}

	if (ext->attach(dev, pci_ext)) {
		DEB_D("ext->attach() failed for %p. skipping device.\n", dev);
		goto err_free_i2c;
	}
	pci_set_drvdata(pci, &dev->v4l2_dev);

	INIT_LIST_HEAD(&dev->item);
	list_add_tail(&dev->item,&saa7146_devices);
	saa7146_num++;

	err = 0;
out:
	return err;

err_free_i2c:
	pci_free_consistent(pci, SAA7146_RPS_MEM, dev->d_i2c.cpu_addr,
			    dev->d_i2c.dma_handle);
err_free_rps1:
	pci_free_consistent(pci, SAA7146_RPS_MEM, dev->d_rps1.cpu_addr,
			    dev->d_rps1.dma_handle);
err_free_rps0:
	pci_free_consistent(pci, SAA7146_RPS_MEM, dev->d_rps0.cpu_addr,
			    dev->d_rps0.dma_handle);
err_free_irq:
	free_irq(pci->irq, (void *)dev);
err_unmap:
	iounmap(dev->mem);
err_release:
	pci_release_region(pci, 0);
err_disable:
	pci_disable_device(pci);
err_free:
	kfree(dev);
	goto out;
}
Beispiel #29
0
static int saa7146_init_one(struct pci_dev *pci, const struct pci_device_id *ent)
{
    struct saa7146_pci_extension_data *pci_ext = (struct saa7146_pci_extension_data *)ent->driver_data;
    struct saa7146_extension *ext = pci_ext->ext;
    struct saa7146_dev *dev;
    int err = -ENOMEM;

    /* clear out mem for sure */
    dev = kzalloc(sizeof(struct saa7146_dev), GFP_KERNEL);
    if (!dev) {
        ERR(("out of memory.\n"));
        goto out;
    }

    DEB_EE(("pci:%p\n",pci));

    err = pci_enable_device(pci);
    if (err < 0) {
        ERR(("pci_enable_device() failed.\n"));
        goto err_free;
    }

    /* enable bus-mastering */
    pci_set_master(pci);

    dev->pci = pci;

    /* get chip-revision; this is needed to enable bug-fixes */
    err = pci_read_config_dword(pci, PCI_CLASS_REVISION, &dev->revision);
    if (err < 0) {
        ERR(("pci_read_config_dword() failed.\n"));
        goto err_disable;
    }
    dev->revision &= 0xf;

    /* remap the memory from virtual to physical address */

    err = pci_request_region(pci, 0, "saa7146");
    if (err < 0)
        goto err_disable;

    dev->mem = ioremap(pci_resource_start(pci, 0),
                       pci_resource_len(pci, 0));
    if (!dev->mem) {
        ERR(("ioremap() failed.\n"));
        err = -ENODEV;
        goto err_release;
    }

    /* we don't do a master reset here anymore, it screws up
       some boards that don't have an i2c-eeprom for configuration
       values */
    /*
    	saa7146_write(dev, MC1, MASK_31);
    */

    /* disable all irqs */
    saa7146_write(dev, IER, 0);

    /* shut down all dma transfers and rps tasks */
    saa7146_write(dev, MC1, 0x30ff0000);

    /* clear out any rps-signals pending */
    saa7146_write(dev, MC2, 0xf8000000);

    /* request an interrupt for the saa7146 */
    err = request_irq(pci->irq, interrupt_hw, IRQF_SHARED | IRQF_DISABLED,
                      dev->name, dev);
    if (err < 0) {
        ERR(("request_irq() failed.\n"));
        goto err_unmap;
    }

    err = -ENOMEM;

    /* get memory for various stuff */
    dev->d_rps0.cpu_addr = pci_alloc_consistent(pci, SAA7146_RPS_MEM,
                           &dev->d_rps0.dma_handle);
    if (!dev->d_rps0.cpu_addr)
        goto err_free_irq;
    memset(dev->d_rps0.cpu_addr, 0x0, SAA7146_RPS_MEM);

    dev->d_rps1.cpu_addr = pci_alloc_consistent(pci, SAA7146_RPS_MEM,
                           &dev->d_rps1.dma_handle);
    if (!dev->d_rps1.cpu_addr)
        goto err_free_rps0;
    memset(dev->d_rps1.cpu_addr, 0x0, SAA7146_RPS_MEM);

    dev->d_i2c.cpu_addr = pci_alloc_consistent(pci, SAA7146_RPS_MEM,
                          &dev->d_i2c.dma_handle);
    if (!dev->d_i2c.cpu_addr)
        goto err_free_rps1;
    memset(dev->d_i2c.cpu_addr, 0x0, SAA7146_RPS_MEM);

    /* the rest + print status message */

    /* create a nice device name */
    sprintf(dev->name, "saa7146 (%d)", saa7146_num);

    INFO(("found saa7146 @ mem %p (revision %d, irq %d) (0x%04x,0x%04x).\n", dev->mem, dev->revision, pci->irq, pci->subsystem_vendor, pci->subsystem_device));
    dev->ext = ext;

    mutex_init(&dev->lock);
    spin_lock_init(&dev->int_slock);
    spin_lock_init(&dev->slock);

    mutex_init(&dev->i2c_lock);

    dev->module = THIS_MODULE;
    init_waitqueue_head(&dev->i2c_wq);

    /* set some sane pci arbitrition values */
    saa7146_write(dev, PCI_BT_V1, 0x1c00101f);

    /* TODO: use the status code of the callback */

    err = -ENODEV;

    if (ext->probe && ext->probe(dev)) {
        DEB_D(("ext->probe() failed for %p. skipping device.\n",dev));
        goto err_free_i2c;
    }

    if (ext->attach(dev, pci_ext)) {
        DEB_D(("ext->attach() failed for %p. skipping device.\n",dev));
        goto err_free_i2c;
    }
    /* V4L extensions will set the pci drvdata to the v4l2_device in the
       attach() above. So for those cards that do not use V4L we have to
       set it explicitly. */
    pci_set_drvdata(pci, &dev->v4l2_dev);

    INIT_LIST_HEAD(&dev->item);
    list_add_tail(&dev->item,&saa7146_devices);
    saa7146_num++;

    err = 0;
out:
    return err;

err_free_i2c:
    pci_free_consistent(pci, SAA7146_RPS_MEM, dev->d_i2c.cpu_addr,
                        dev->d_i2c.dma_handle);
err_free_rps1:
    pci_free_consistent(pci, SAA7146_RPS_MEM, dev->d_rps1.cpu_addr,
                        dev->d_rps1.dma_handle);
err_free_rps0:
    pci_free_consistent(pci, SAA7146_RPS_MEM, dev->d_rps0.cpu_addr,
                        dev->d_rps0.dma_handle);
err_free_irq:
    free_irq(pci->irq, (void *)dev);
err_unmap:
    iounmap(dev->mem);
err_release:
    pci_release_region(pci, 0);
err_disable:
    pci_disable_device(pci);
err_free:
    kfree(dev);
    goto out;
}
Beispiel #30
0
/* bring hardware to a sane state. this has to be done, just in case someone
   wants to capture from this device before it has been properly initialized.
   the capture engine would badly fail, because no valid signal arrives on the
   saa7146, thus leading to timeouts and stuff. */
static int mxb_init_done(struct saa7146_dev* dev)
{
	struct mxb* mxb = (struct mxb*)dev->ext_priv;
	struct i2c_msg msg;
	struct tuner_setup tun_setup;
	v4l2_std_id std = V4L2_STD_PAL_BG;

	int i = 0, err = 0;

	/* select video mode in saa7111a */
	saa7111a_call(mxb, core, s_std, std);

	/* select tuner-output on saa7111a */
	i = 0;
	saa7111a_call(mxb, video, s_routing, SAA7115_COMPOSITE0,
		SAA7111_FMT_CCIR, 0);

	/* select a tuner type */
	tun_setup.mode_mask = T_ANALOG_TV;
	tun_setup.addr = ADDR_UNSET;
	tun_setup.type = TUNER_PHILIPS_PAL;
	tuner_call(mxb, tuner, s_type_addr, &tun_setup);
	/* tune in some frequency on tuner */
	mxb->cur_freq.tuner = 0;
	mxb->cur_freq.type = V4L2_TUNER_ANALOG_TV;
	mxb->cur_freq.frequency = freq;
	tuner_call(mxb, tuner, s_frequency, &mxb->cur_freq);

	/* set a default video standard */
	tuner_call(mxb, core, s_std, std);

	/* mute audio on tea6420s */
	tea6420_route_line(mxb, 6);
	tea6420_route_cd(mxb, 6);

	/* switch to tuner-channel on tea6415c */
	tea6415c_call(mxb, video, s_routing, 3, 17, 0);

	/* select tuner-output on multicable on tea6415c */
	tea6415c_call(mxb, video, s_routing, 3, 13, 0);

	/* the rest for mxb */
	mxb->cur_input = 0;
	mxb->cur_mute = 1;

	mxb->cur_mode = V4L2_TUNER_MODE_STEREO;

	/* check if the saa7740 (aka 'sound arena module') is present
	   on the mxb. if so, we must initialize it. due to lack of
	   informations about the saa7740, the values were reverse
	   engineered. */
	msg.addr = 0x1b;
	msg.flags = 0;
	msg.len = mxb_saa7740_init[0].length;
	msg.buf = &mxb_saa7740_init[0].data[0];

	err = i2c_transfer(&mxb->i2c_adapter, &msg, 1);
	if (err == 1) {
		/* the sound arena module is a pos, that's probably the reason
		   philips refuses to hand out a datasheet for the saa7740...
		   it seems to screw up the i2c bus, so we disable fast irq
		   based i2c transactions here and rely on the slow and safe
		   polling method ... */
		extension.flags &= ~SAA7146_USE_I2C_IRQ;
		for (i = 1; ; i++) {
			if (-1 == mxb_saa7740_init[i].length)
				break;

			msg.len = mxb_saa7740_init[i].length;
			msg.buf = &mxb_saa7740_init[i].data[0];
			err = i2c_transfer(&mxb->i2c_adapter, &msg, 1);
			if (err != 1) {
				DEB_D(("failed to initialize 'sound arena module'.\n"));
				goto err;
			}
		}
		INFO(("'sound arena module' detected.\n"));
	}
err:
	/* the rest for saa7146: you should definitely set some basic values
	   for the input-port handling of the saa7146. */

	/* ext->saa has been filled by the core driver */

	/* some stuff is done via variables */
	saa7146_set_hps_source_and_sync(dev, input_port_selection[mxb->cur_input].hps_source,
			input_port_selection[mxb->cur_input].hps_sync);

	/* some stuff is done via direct write to the registers */

	/* this is ugly, but because of the fact that this is completely
	   hardware dependend, it should be done directly... */
	saa7146_write(dev, DD1_STREAM_B,	0x00000000);
	saa7146_write(dev, DD1_INIT,		0x02000200);
	saa7146_write(dev, MC2, (MASK_09 | MASK_25 | MASK_10 | MASK_26));

	return 0;
}