📄 radio-cadet.c
字号:
if(rdsstat==0) { spin_lock(&cadet_io_lock); rdsstat=1; outb(0x80,io); /* Select RDS fifo */ spin_unlock(&cadet_io_lock); init_timer(&readtimer); readtimer.function=cadet_handler; readtimer.data=(unsigned long)0; readtimer.expires=jiffies+msecs_to_jiffies(50); add_timer(&readtimer); } if(rdsin==rdsout) { if (file->f_flags & O_NONBLOCK) return -EWOULDBLOCK; interruptible_sleep_on(&read_queue); } while( i<count && rdsin!=rdsout) readbuf[i++]=rdsbuf[rdsout++]; if (copy_to_user(data,readbuf,i)) return -EFAULT; return i;}static int vidioc_querycap(struct file *file, void *priv, struct v4l2_capability *v){ v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_READWRITE; v->version = CADET_VERSION; strcpy(v->driver, "ADS Cadet"); strcpy(v->card, "ADS Cadet"); return 0;}static int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *v){ v->type = V4L2_TUNER_RADIO; switch (v->index) { case 0: strcpy(v->name, "FM"); v->capability = V4L2_TUNER_CAP_STEREO; v->rangelow = 1400; /* 87.5 MHz */ v->rangehigh = 1728; /* 108.0 MHz */ v->rxsubchans=cadet_getstereo(); switch (v->rxsubchans){ case V4L2_TUNER_SUB_MONO: v->audmode = V4L2_TUNER_MODE_MONO; break; case V4L2_TUNER_SUB_STEREO: v->audmode = V4L2_TUNER_MODE_STEREO; break; default: ; } break; case 1: strcpy(v->name, "AM"); v->capability = V4L2_TUNER_CAP_LOW; v->rangelow = 8320; /* 520 kHz */ v->rangehigh = 26400; /* 1650 kHz */ v->rxsubchans = V4L2_TUNER_SUB_MONO; v->audmode = V4L2_TUNER_MODE_MONO; break; default: return -EINVAL; } v->signal = sigstrength; /* We might need to modify scaling of this */ return 0;}static int vidioc_s_tuner(struct file *file, void *priv, struct v4l2_tuner *v){ if((v->index != 0)&&(v->index != 1)) return -EINVAL; curtuner = v->index; return 0;}static int vidioc_g_frequency(struct file *file, void *priv, struct v4l2_frequency *f){ f->tuner = curtuner; f->type = V4L2_TUNER_RADIO; f->frequency = cadet_getfreq(); return 0;}static int vidioc_s_frequency(struct file *file, void *priv, struct v4l2_frequency *f){ if (f->type != V4L2_TUNER_RADIO) return -EINVAL; if((curtuner==0)&&((f->frequency<1400)||(f->frequency>1728))) return -EINVAL; if((curtuner==1)&&((f->frequency<8320)||(f->frequency>26400))) return -EINVAL; cadet_setfreq(f->frequency); return 0;}static int vidioc_queryctrl(struct file *file, void *priv, struct v4l2_queryctrl *qc){ int i; for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) { if (qc->id && qc->id == radio_qctrl[i].id) { memcpy(qc, &(radio_qctrl[i]), sizeof(*qc)); return 0; } } return -EINVAL;}static int vidioc_g_ctrl(struct file *file, void *priv, struct v4l2_control *ctrl){ switch (ctrl->id){ case V4L2_CID_AUDIO_MUTE: /* TODO: Handle this correctly */ ctrl->value = (cadet_getvol() == 0); break; case V4L2_CID_AUDIO_VOLUME: ctrl->value = cadet_getvol(); break; default: return -EINVAL; } return 0;}static int vidioc_s_ctrl(struct file *file, void *priv, struct v4l2_control *ctrl){ switch (ctrl->id){ case V4L2_CID_AUDIO_MUTE: /* TODO: Handle this correctly */ if (ctrl->value) cadet_setvol(0); else cadet_setvol(0xffff); break; case V4L2_CID_AUDIO_VOLUME: cadet_setvol(ctrl->value); break; default: return -EINVAL; } return 0;}static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a){ if (a->index > 1) return -EINVAL; strcpy(a->name, "Radio"); a->capability = V4L2_AUDCAP_STEREO; return 0;}static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i){ *i = 0; return 0;}static int vidioc_s_input(struct file *filp, void *priv, unsigned int i){ if (i != 0) return -EINVAL; return 0;}static int vidioc_s_audio(struct file *file, void *priv, struct v4l2_audio *a){ if (a->index != 0) return -EINVAL; return 0;}static intcadet_open(struct inode *inode, struct file *file){ users++; if (1 == users) init_waitqueue_head(&read_queue); return 0;}static intcadet_release(struct inode *inode, struct file *file){ users--; if (0 == users){ del_timer_sync(&readtimer); rdsstat=0; } return 0;}static unsigned intcadet_poll(struct file *file, struct poll_table_struct *wait){ poll_wait(file,&read_queue,wait); if(rdsin != rdsout) return POLLIN | POLLRDNORM; return 0;}static const struct file_operations cadet_fops = { .owner = THIS_MODULE, .open = cadet_open, .release = cadet_release, .read = cadet_read, .ioctl = video_ioctl2, .poll = cadet_poll,#ifdef CONFIG_COMPAT .compat_ioctl = v4l_compat_ioctl32,#endif .llseek = no_llseek,};static const struct v4l2_ioctl_ops cadet_ioctl_ops = { .vidioc_querycap = vidioc_querycap, .vidioc_g_tuner = vidioc_g_tuner, .vidioc_s_tuner = vidioc_s_tuner, .vidioc_g_frequency = vidioc_g_frequency, .vidioc_s_frequency = vidioc_s_frequency, .vidioc_queryctrl = vidioc_queryctrl, .vidioc_g_ctrl = vidioc_g_ctrl, .vidioc_s_ctrl = vidioc_s_ctrl, .vidioc_g_audio = vidioc_g_audio, .vidioc_s_audio = vidioc_s_audio, .vidioc_g_input = vidioc_g_input, .vidioc_s_input = vidioc_s_input,};static struct video_device cadet_radio = { .name = "Cadet radio", .fops = &cadet_fops, .ioctl_ops = &cadet_ioctl_ops, .release = video_device_release_empty,};#ifdef CONFIG_PNPstatic struct pnp_device_id cadet_pnp_devices[] = { /* ADS Cadet AM/FM Radio Card */ {.id = "MSM0c24", .driver_data = 0}, {.id = ""}};MODULE_DEVICE_TABLE(pnp, cadet_pnp_devices);static int cadet_pnp_probe(struct pnp_dev * dev, const struct pnp_device_id *dev_id){ if (!dev) return -ENODEV; /* only support one device */ if (io > 0) return -EBUSY; if (!pnp_port_valid(dev, 0)) { return -ENODEV; } io = pnp_port_start(dev, 0); printk ("radio-cadet: PnP reports device at %#x\n", io); return io;}static struct pnp_driver cadet_pnp_driver = { .name = "radio-cadet", .id_table = cadet_pnp_devices, .probe = cadet_pnp_probe, .remove = NULL,};#elsestatic struct pnp_driver cadet_pnp_driver;#endifstatic int cadet_probe(void){ static int iovals[8]={0x330,0x332,0x334,0x336,0x338,0x33a,0x33c,0x33e}; int i; for(i=0;i<8;i++) { io=iovals[i]; if (request_region(io, 2, "cadet-probe")) { cadet_setfreq(1410); if(cadet_getfreq()==1410) { release_region(io, 2); return io; } release_region(io, 2); } } return -1;}/* * io should only be set if the user has used something like * isapnp (the userspace program) to initialize this card for us */static int __init cadet_init(void){ spin_lock_init(&cadet_io_lock); /* * If a probe was requested then probe ISAPnP first (safest) */ if (io < 0) pnp_register_driver(&cadet_pnp_driver); /* * If that fails then probe unsafely if probe is requested */ if(io < 0) io = cadet_probe (); /* * Else we bail out */ if(io < 0) {#ifdef MODULE printk(KERN_ERR "You must set an I/O address with io=0x???\n");#endif goto fail; } if (!request_region(io,2,"cadet")) goto fail; if (video_register_device(&cadet_radio, VFL_TYPE_RADIO, radio_nr) < 0) { release_region(io,2); goto fail; } printk(KERN_INFO "ADS Cadet Radio Card at 0x%x\n",io); return 0;fail: pnp_unregister_driver(&cadet_pnp_driver); return -1;}MODULE_AUTHOR("Fred Gleason, Russell Kroll, Quay Lu, Donald Song, Jason Lewis, Scott McGrath, William McGrath");MODULE_DESCRIPTION("A driver for the ADS Cadet AM/FM/RDS radio card.");MODULE_LICENSE("GPL");module_param(io, int, 0);MODULE_PARM_DESC(io, "I/O address of Cadet card (0x330,0x332,0x334,0x336,0x338,0x33a,0x33c,0x33e)");module_param(radio_nr, int, 0);static void __exit cadet_cleanup_module(void){ video_unregister_device(&cadet_radio); release_region(io,2); pnp_unregister_driver(&cadet_pnp_driver);}module_init(cadet_init);module_exit(cadet_cleanup_module);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -