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 <linux/videodev2.h> /* kernel radio structs */
17 #include <linux/mutex.h>
18 #include <linux/version.h> /* for KERNEL_VERSION MACRO */
19 #include <linux/io.h> /* outb, outb_p */
20 #include <media/v4l2-device.h>
21 #include <media/v4l2-ioctl.h>
23 MODULE_AUTHOR("Ben Pfaff");
24 MODULE_DESCRIPTION("A driver for the RadioTrack II radio card.");
25 MODULE_LICENSE("GPL");
27 #ifndef CONFIG_RADIO_RTRACK2_PORT
28 #define CONFIG_RADIO_RTRACK2_PORT -1
31 static int io = CONFIG_RADIO_RTRACK2_PORT;
32 static int radio_nr = -1;
34 module_param(io, int, 0);
35 MODULE_PARM_DESC(io, "I/O address of the RadioTrack card (0x20c or 0x30c)");
36 module_param(radio_nr, int, 0);
38 #define RADIO_VERSION KERNEL_VERSION(0, 0, 2)
42 struct v4l2_device v4l2_dev;
43 struct video_device vdev;
45 unsigned long curfreq;
50 static struct rtrack2 rtrack2_card;
55 static void rt_mute(struct rtrack2 *dev)
59 mutex_lock(&dev->lock);
61 mutex_unlock(&dev->lock);
65 static void rt_unmute(struct rtrack2 *dev)
69 mutex_lock(&dev->lock);
71 mutex_unlock(&dev->lock);
75 static void zero(struct rtrack2 *dev)
82 static void one(struct rtrack2 *dev)
89 static int rt_setfreq(struct rtrack2 *dev, unsigned long freq)
93 mutex_lock(&dev->lock);
95 freq = freq / 200 + 856;
97 outb_p(0xc8, dev->io);
98 outb_p(0xc9, dev->io);
99 outb_p(0xc9, dev->io);
101 for (i = 0; i < 10; i++)
104 for (i = 14; i >= 0; i--)
110 outb_p(0xc8, dev->io);
114 mutex_unlock(&dev->lock);
118 static int vidioc_querycap(struct file *file, void *priv,
119 struct v4l2_capability *v)
121 strlcpy(v->driver, "radio-rtrack2", sizeof(v->driver));
122 strlcpy(v->card, "RadioTrack II", sizeof(v->card));
123 strlcpy(v->bus_info, "ISA", sizeof(v->bus_info));
124 v->version = RADIO_VERSION;
125 v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
129 static int vidioc_s_tuner(struct file *file, void *priv,
130 struct v4l2_tuner *v)
132 return v->index ? -EINVAL : 0;
135 static int rt_getsigstr(struct rtrack2 *dev)
139 mutex_lock(&dev->lock);
140 if (inb(dev->io) & 2) /* bit set = no signal present */
142 mutex_unlock(&dev->lock);
146 static int vidioc_g_tuner(struct file *file, void *priv,
147 struct v4l2_tuner *v)
149 struct rtrack2 *rt = video_drvdata(file);
154 strlcpy(v->name, "FM", sizeof(v->name));
155 v->type = V4L2_TUNER_RADIO;
156 v->rangelow = 88 * 16000;
157 v->rangehigh = 108 * 16000;
158 v->rxsubchans = V4L2_TUNER_SUB_MONO;
159 v->capability = V4L2_TUNER_CAP_LOW;
160 v->audmode = V4L2_TUNER_MODE_MONO;
161 v->signal = 0xFFFF * rt_getsigstr(rt);
165 static int vidioc_s_frequency(struct file *file, void *priv,
166 struct v4l2_frequency *f)
168 struct rtrack2 *rt = video_drvdata(file);
170 rt_setfreq(rt, f->frequency);
174 static int vidioc_g_frequency(struct file *file, void *priv,
175 struct v4l2_frequency *f)
177 struct rtrack2 *rt = video_drvdata(file);
179 f->type = V4L2_TUNER_RADIO;
180 f->frequency = rt->curfreq;
184 static int vidioc_queryctrl(struct file *file, void *priv,
185 struct v4l2_queryctrl *qc)
188 case V4L2_CID_AUDIO_MUTE:
189 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
190 case V4L2_CID_AUDIO_VOLUME:
191 return v4l2_ctrl_query_fill(qc, 0, 65535, 65535, 65535);
196 static int vidioc_g_ctrl(struct file *file, void *priv,
197 struct v4l2_control *ctrl)
199 struct rtrack2 *rt = video_drvdata(file);
202 case V4L2_CID_AUDIO_MUTE:
203 ctrl->value = rt->muted;
205 case V4L2_CID_AUDIO_VOLUME:
215 static int vidioc_s_ctrl(struct file *file, void *priv,
216 struct v4l2_control *ctrl)
218 struct rtrack2 *rt = video_drvdata(file);
221 case V4L2_CID_AUDIO_MUTE:
227 case V4L2_CID_AUDIO_VOLUME:
237 static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
243 static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
245 return i ? -EINVAL : 0;
248 static int vidioc_g_audio(struct file *file, void *priv,
249 struct v4l2_audio *a)
252 strlcpy(a->name, "Radio", sizeof(a->name));
253 a->capability = V4L2_AUDCAP_STEREO;
257 static int vidioc_s_audio(struct file *file, void *priv,
258 struct v4l2_audio *a)
260 return a->index ? -EINVAL : 0;
263 static int rtrack2_open(struct file *file)
268 static int rtrack2_release(struct file *file)
273 static const struct v4l2_file_operations rtrack2_fops = {
274 .owner = THIS_MODULE,
275 .open = rtrack2_open,
276 .release = rtrack2_release,
277 .ioctl = video_ioctl2,
280 static const struct v4l2_ioctl_ops rtrack2_ioctl_ops = {
281 .vidioc_querycap = vidioc_querycap,
282 .vidioc_g_tuner = vidioc_g_tuner,
283 .vidioc_s_tuner = vidioc_s_tuner,
284 .vidioc_g_frequency = vidioc_g_frequency,
285 .vidioc_s_frequency = vidioc_s_frequency,
286 .vidioc_queryctrl = vidioc_queryctrl,
287 .vidioc_g_ctrl = vidioc_g_ctrl,
288 .vidioc_s_ctrl = vidioc_s_ctrl,
289 .vidioc_g_audio = vidioc_g_audio,
290 .vidioc_s_audio = vidioc_s_audio,
291 .vidioc_g_input = vidioc_g_input,
292 .vidioc_s_input = vidioc_s_input,
295 static int __init rtrack2_init(void)
297 struct rtrack2 *dev = &rtrack2_card;
298 struct v4l2_device *v4l2_dev = &dev->v4l2_dev;
301 strlcpy(v4l2_dev->name, "rtrack2", sizeof(v4l2_dev->name));
304 v4l2_err(v4l2_dev, "You must set an I/O address with io=0x20c or io=0x30c\n");
307 if (!request_region(dev->io, 4, "rtrack2")) {
308 v4l2_err(v4l2_dev, "port 0x%x already in use\n", dev->io);
312 res = v4l2_device_register(NULL, v4l2_dev);
314 release_region(dev->io, 4);
315 v4l2_err(v4l2_dev, "Could not register v4l2_device\n");
319 strlcpy(dev->vdev.name, v4l2_dev->name, sizeof(dev->vdev.name));
320 dev->vdev.v4l2_dev = v4l2_dev;
321 dev->vdev.fops = &rtrack2_fops;
322 dev->vdev.ioctl_ops = &rtrack2_ioctl_ops;
323 dev->vdev.release = video_device_release_empty;
324 video_set_drvdata(&dev->vdev, dev);
326 mutex_init(&dev->lock);
327 if (video_register_device(&dev->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
328 v4l2_device_unregister(v4l2_dev);
329 release_region(dev->io, 4);
333 v4l2_info(v4l2_dev, "AIMSlab Radiotrack II card driver.\n");
335 /* mute card - prevents noisy bootups */
342 static void __exit rtrack2_exit(void)
344 struct rtrack2 *dev = &rtrack2_card;
346 video_unregister_device(&dev->vdev);
347 v4l2_device_unregister(&dev->v4l2_dev);
348 release_region(dev->io, 4);
351 module_init(rtrack2_init);
352 module_exit(rtrack2_exit);