📄 mxb.c
字号:
/* select tuner-output on saa7111a */ i = 0; mxb->saa7111a->driver->command(mxb->saa7111a,DECODER_SET_INPUT, &i); /* enable vbi bypass */ i = 1; mxb->saa7111a->driver->command(mxb->saa7111a,DECODER_SET_VBI_BYPASS, &i); /* 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); /* 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; mxb->tda9840->driver->command(mxb->tda9840, TDA9840_SWITCH, &mxb->cur_mode); /* 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]; if( 1 == (err = i2c_transfer(&mxb->i2c_adapter, &msg, 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]; if( 1 != (err = i2c_transfer(&mxb->i2c_adapter, &msg, 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( 0 != 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( 0 != MXB_BOARD_CAN_DO_VBI(dev)) { if( 0 != 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( 0 != 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; } switch (vc->id ) { case 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; } switch (vc->id ) { case V4L2_CID_AUDIO_MUTE: { mxb->cur_mute = vc->value; if( 0 == 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)); break; } } 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; int i = 0; DEB_EE(("VIDIOC_S_INPUT %d.\n",input)); if (input < 0 || input >= MXB_INPUTS) { return -EINVAL; } /* fixme: locke das setzen des inputs mit hilfe des mutexes down(&dev->lock); video_mux(dev,*i); up(&dev->lock); */ /* fixme: check if streaming capture if ( 0 != dev->streaming ) { DEB_D(("VIDIOC_S_INPUT illegal while streaming.\n")); return -EPERM; } */ 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 = 0; vm.in = 3; vm.out = 17; if ( 0 != mxb->tea6415c->driver->command(mxb->tea6415c,TEA6415C_SWITCH, &vm)) { printk("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 = 5; break; } case AUX3: { /* nothing to be done here. aux3 is directly connected to the saa711a */ i = 1; break; } case AUX1: { i = 0; vm.in = 1; vm.out = 17; break; } } /* switch video in tea6415c only if necessary */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -