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@lxorguk.ukuu.org.uk>
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 <media/v4l2-ioctl.h>
21 #include <linux/spinlock.h>
23 #include <linux/version.h> /* for KERNEL_VERSION MACRO */
24 #define RADIO_VERSION KERNEL_VERSION(0,0,2)
26 static struct v4l2_queryctrl radio_qctrl[] = {
28 .id = V4L2_CID_AUDIO_MUTE,
33 .type = V4L2_CTRL_TYPE_BOOLEAN,
35 .id = V4L2_CID_AUDIO_VOLUME,
40 .default_value = 0xff,
41 .type = V4L2_CTRL_TYPE_INTEGER,
45 #ifndef CONFIG_RADIO_RTRACK2_PORT
46 #define CONFIG_RADIO_RTRACK2_PORT -1
49 static int io = CONFIG_RADIO_RTRACK2_PORT;
50 static int radio_nr = -1;
51 static spinlock_t lock;
57 unsigned long curfreq;
64 static void rt_mute(struct rt_device *dev)
74 static void rt_unmute(struct rt_device *dev)
84 static void zero(void)
98 static int rt_setfreq(struct rt_device *dev, unsigned long freq)
102 freq = freq / 200 + 856;
110 for (i = 0; i < 10; i++)
113 for (i = 14; i >= 0; i--)
127 static int vidioc_querycap(struct file *file, void *priv,
128 struct v4l2_capability *v)
130 strlcpy(v->driver, "radio-rtrack2", sizeof(v->driver));
131 strlcpy(v->card, "RadioTrack II", sizeof(v->card));
132 sprintf(v->bus_info, "ISA");
133 v->version = RADIO_VERSION;
134 v->capabilities = V4L2_CAP_TUNER;
138 static int vidioc_s_tuner(struct file *file, void *priv,
139 struct v4l2_tuner *v)
147 static int rt_getsigstr(struct rt_device *dev)
149 if (inb(io) & 2) /* bit set = no signal present */
151 return 1; /* signal present */
154 static int vidioc_g_tuner(struct file *file, void *priv,
155 struct v4l2_tuner *v)
157 struct rt_device *rt = video_drvdata(file);
162 strcpy(v->name, "FM");
163 v->type = V4L2_TUNER_RADIO;
164 v->rangelow = (88*16000);
165 v->rangehigh = (108*16000);
166 v->rxsubchans = V4L2_TUNER_SUB_MONO;
167 v->capability = V4L2_TUNER_CAP_LOW;
168 v->audmode = V4L2_TUNER_MODE_MONO;
169 v->signal = 0xFFFF*rt_getsigstr(rt);
173 static int vidioc_s_frequency(struct file *file, void *priv,
174 struct v4l2_frequency *f)
176 struct rt_device *rt = video_drvdata(file);
178 rt->curfreq = f->frequency;
179 rt_setfreq(rt, rt->curfreq);
183 static int vidioc_g_frequency(struct file *file, void *priv,
184 struct v4l2_frequency *f)
186 struct rt_device *rt = video_drvdata(file);
188 f->type = V4L2_TUNER_RADIO;
189 f->frequency = rt->curfreq;
193 static int vidioc_queryctrl(struct file *file, void *priv,
194 struct v4l2_queryctrl *qc)
198 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) {
199 if (qc->id && qc->id == radio_qctrl[i].id) {
200 memcpy(qc, &(radio_qctrl[i]),
208 static int vidioc_g_ctrl(struct file *file, void *priv,
209 struct v4l2_control *ctrl)
211 struct rt_device *rt = video_drvdata(file);
214 case V4L2_CID_AUDIO_MUTE:
215 ctrl->value = rt->muted;
217 case V4L2_CID_AUDIO_VOLUME:
227 static int vidioc_s_ctrl(struct file *file, void *priv,
228 struct v4l2_control *ctrl)
230 struct rt_device *rt = video_drvdata(file);
233 case V4L2_CID_AUDIO_MUTE:
239 case V4L2_CID_AUDIO_VOLUME:
249 static int vidioc_g_audio(struct file *file, void *priv,
250 struct v4l2_audio *a)
255 strcpy(a->name, "Radio");
256 a->capability = V4L2_AUDCAP_STEREO;
260 static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
266 static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
273 static int vidioc_s_audio(struct file *file, void *priv,
274 struct v4l2_audio *a)
281 static struct rt_device rtrack2_unit;
283 static int rtrack2_exclusive_open(struct inode *inode, struct file *file)
285 return test_and_set_bit(0, &rtrack2_unit.in_use) ? -EBUSY : 0;
288 static int rtrack2_exclusive_release(struct inode *inode, struct file *file)
290 clear_bit(0, &rtrack2_unit.in_use);
294 static const struct file_operations rtrack2_fops = {
295 .owner = THIS_MODULE,
296 .open = rtrack2_exclusive_open,
297 .release = rtrack2_exclusive_release,
298 .ioctl = video_ioctl2,
300 .compat_ioctl = v4l_compat_ioctl32,
305 static const struct v4l2_ioctl_ops rtrack2_ioctl_ops = {
306 .vidioc_querycap = vidioc_querycap,
307 .vidioc_g_tuner = vidioc_g_tuner,
308 .vidioc_s_tuner = vidioc_s_tuner,
309 .vidioc_g_frequency = vidioc_g_frequency,
310 .vidioc_s_frequency = vidioc_s_frequency,
311 .vidioc_queryctrl = vidioc_queryctrl,
312 .vidioc_g_ctrl = vidioc_g_ctrl,
313 .vidioc_s_ctrl = vidioc_s_ctrl,
314 .vidioc_g_audio = vidioc_g_audio,
315 .vidioc_s_audio = vidioc_s_audio,
316 .vidioc_g_input = vidioc_g_input,
317 .vidioc_s_input = vidioc_s_input,
320 static struct video_device rtrack2_radio = {
321 .name = "RadioTrack II radio",
322 .fops = &rtrack2_fops,
323 .ioctl_ops = &rtrack2_ioctl_ops,
324 .release = video_device_release_empty,
327 static int __init rtrack2_init(void)
331 printk(KERN_ERR "You must set an I/O address with io=0x20c or io=0x30c\n");
334 if (!request_region(io, 4, "rtrack2"))
336 printk(KERN_ERR "rtrack2: port 0x%x already in use\n", io);
340 video_set_drvdata(&rtrack2_radio, &rtrack2_unit);
342 spin_lock_init(&lock);
343 if (video_register_device(&rtrack2_radio, VFL_TYPE_RADIO, radio_nr) < 0) {
344 release_region(io, 4);
348 printk(KERN_INFO "AIMSlab Radiotrack II card driver.\n");
350 /* mute card - prevents noisy bootups */
352 rtrack2_unit.muted = 1;
357 MODULE_AUTHOR("Ben Pfaff");
358 MODULE_DESCRIPTION("A driver for the RadioTrack II radio card.");
359 MODULE_LICENSE("GPL");
361 module_param(io, int, 0);
362 MODULE_PARM_DESC(io, "I/O address of the RadioTrack card (0x20c or 0x30c)");
363 module_param(radio_nr, int, 0);
365 static void __exit rtrack2_cleanup_module(void)
367 video_unregister_device(&rtrack2_radio);
368 release_region(io,4);
371 module_init(rtrack2_init);
372 module_exit(rtrack2_cleanup_module);
376 compile-command: "mmake"