1 /* RadioTrack II driver for Linux radio support (C) 1998 Ben Pfaff
3 * Based on RadioTrack I/RadioReveal (C) 1997 M. Kirkwood
4 * Converted to new API by Alan Cox <Alan.Cox@linux.org>
5 * Various bugfixes and enhancements by Russell Kroll <rkroll@exploits.org>
7 * TODO: Allow for more than one of these foolish entities :-)
9 * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
12 #include <linux/module.h> /* Modules */
13 #include <linux/init.h> /* Initdata */
14 #include <linux/ioport.h> /* request_region */
15 #include <linux/delay.h> /* udelay */
16 #include <asm/io.h> /* outb, outb_p */
17 #include <asm/uaccess.h> /* copy to/from user */
18 #include <linux/videodev2.h> /* kernel radio structs */
19 #include <media/v4l2-common.h>
20 #include <linux/spinlock.h>
22 #include <linux/version.h> /* for KERNEL_VERSION MACRO */
23 #define RADIO_VERSION KERNEL_VERSION(0,0,2)
25 static struct v4l2_queryctrl radio_qctrl[] = {
27 .id = V4L2_CID_AUDIO_MUTE,
32 .type = V4L2_CTRL_TYPE_BOOLEAN,
34 .id = V4L2_CID_AUDIO_VOLUME,
39 .default_value = 0xff,
40 .type = V4L2_CTRL_TYPE_INTEGER,
44 #ifndef CONFIG_RADIO_RTRACK2_PORT
45 #define CONFIG_RADIO_RTRACK2_PORT -1
48 static int io = CONFIG_RADIO_RTRACK2_PORT;
49 static int radio_nr = -1;
50 static spinlock_t lock;
55 unsigned long curfreq;
62 static void rt_mute(struct rt_device *dev)
72 static void rt_unmute(struct rt_device *dev)
82 static void zero(void)
96 static int rt_setfreq(struct rt_device *dev, unsigned long freq)
100 freq = freq / 200 + 856;
108 for (i = 0; i < 10; i++)
111 for (i = 14; i >= 0; i--)
125 static int rt_getsigstr(struct rt_device *dev)
127 if (inb(io) & 2) /* bit set = no signal present */
129 return 1; /* signal present */
132 static int rt_do_ioctl(struct inode *inode, struct file *file,
133 unsigned int cmd, void *arg)
135 struct video_device *dev = video_devdata(file);
136 struct rt_device *rt=dev->priv;
140 case VIDIOC_QUERYCAP:
142 struct v4l2_capability *v = arg;
143 memset(v,0,sizeof(*v));
144 strlcpy(v->driver, "radio-rtrack2", sizeof (v->driver));
145 strlcpy(v->card, "RadioTrack II", sizeof (v->card));
146 sprintf(v->bus_info,"ISA");
147 v->version = RADIO_VERSION;
148 v->capabilities = V4L2_CAP_TUNER;
154 struct v4l2_tuner *v = arg;
159 memset(v,0,sizeof(*v));
160 strcpy(v->name, "FM");
161 v->type = V4L2_TUNER_RADIO;
163 v->rangelow=(88*16000);
164 v->rangehigh=(108*16000);
165 v->rxsubchans =V4L2_TUNER_SUB_MONO;
166 v->capability=V4L2_TUNER_CAP_LOW;
167 v->audmode = V4L2_TUNER_MODE_MONO;
168 v->signal=0xFFFF*rt_getsigstr(rt);
174 struct v4l2_tuner *v = arg;
181 case VIDIOC_S_FREQUENCY:
183 struct v4l2_frequency *f = arg;
185 rt->curfreq = f->frequency;
186 rt_setfreq(rt, rt->curfreq);
189 case VIDIOC_G_FREQUENCY:
191 struct v4l2_frequency *f = arg;
193 f->type = V4L2_TUNER_RADIO;
194 f->frequency = rt->curfreq;
198 case VIDIOC_QUERYCTRL:
200 struct v4l2_queryctrl *qc = arg;
203 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) {
204 if (qc->id && qc->id == radio_qctrl[i].id) {
205 memcpy(qc, &(radio_qctrl[i]),
214 struct v4l2_control *ctrl= arg;
217 case V4L2_CID_AUDIO_MUTE:
218 ctrl->value=rt->muted;
220 case V4L2_CID_AUDIO_VOLUME:
231 struct v4l2_control *ctrl= arg;
234 case V4L2_CID_AUDIO_MUTE:
241 case V4L2_CID_AUDIO_VOLUME:
252 return v4l_compat_translate_ioctl(inode,file,cmd,arg,
257 static int rt_ioctl(struct inode *inode, struct file *file,
258 unsigned int cmd, unsigned long arg)
260 return video_usercopy(inode, file, cmd, arg, rt_do_ioctl);
263 static struct rt_device rtrack2_unit;
265 static const struct file_operations rtrack2_fops = {
266 .owner = THIS_MODULE,
267 .open = video_exclusive_open,
268 .release = video_exclusive_release,
270 .compat_ioctl = v4l_compat_ioctl32,
274 static struct video_device rtrack2_radio=
276 .owner = THIS_MODULE,
277 .name = "RadioTrack II radio",
278 .type = VID_TYPE_TUNER,
280 .fops = &rtrack2_fops,
283 static int __init rtrack2_init(void)
287 printk(KERN_ERR "You must set an I/O address with io=0x20c or io=0x30c\n");
290 if (!request_region(io, 4, "rtrack2"))
292 printk(KERN_ERR "rtrack2: port 0x%x already in use\n", io);
296 rtrack2_radio.priv=&rtrack2_unit;
298 spin_lock_init(&lock);
299 if(video_register_device(&rtrack2_radio, VFL_TYPE_RADIO, radio_nr)==-1)
301 release_region(io, 4);
305 printk(KERN_INFO "AIMSlab Radiotrack II card driver.\n");
307 /* mute card - prevents noisy bootups */
309 rtrack2_unit.muted = 1;
314 MODULE_AUTHOR("Ben Pfaff");
315 MODULE_DESCRIPTION("A driver for the RadioTrack II radio card.");
316 MODULE_LICENSE("GPL");
318 module_param(io, int, 0);
319 MODULE_PARM_DESC(io, "I/O address of the RadioTrack card (0x20c or 0x30c)");
320 module_param(radio_nr, int, 0);
322 static void __exit rtrack2_cleanup_module(void)
324 video_unregister_device(&rtrack2_radio);
325 release_region(io,4);
328 module_init(rtrack2_init);
329 module_exit(rtrack2_cleanup_module);
333 compile-command: "mmake"