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 <linux/uaccess.h> /* copy to/from user */
21 #include <media/v4l2-device.h>
22 #include <media/v4l2-ioctl.h>
24 MODULE_AUTHOR("Ben Pfaff");
25 MODULE_DESCRIPTION("A driver for the RadioTrack II radio card.");
26 MODULE_LICENSE("GPL");
28 #ifndef CONFIG_RADIO_RTRACK2_PORT
29 #define CONFIG_RADIO_RTRACK2_PORT -1
32 static int io = CONFIG_RADIO_RTRACK2_PORT;
33 static int radio_nr = -1;
35 module_param(io, int, 0);
36 MODULE_PARM_DESC(io, "I/O address of the RadioTrack card (0x20c or 0x30c)");
37 module_param(radio_nr, int, 0);
39 #define RADIO_VERSION KERNEL_VERSION(0, 0, 2)
43 struct v4l2_device v4l2_dev;
44 struct video_device vdev;
46 unsigned long curfreq;
51 static struct rtrack2 rtrack2_card;
56 static void rt_mute(struct rtrack2 *dev)
60 mutex_lock(&dev->lock);
62 mutex_unlock(&dev->lock);
63 mutex_unlock(&dev->lock);
67 static void rt_unmute(struct rtrack2 *dev)
71 mutex_lock(&dev->lock);
73 mutex_unlock(&dev->lock);
77 static void zero(struct rtrack2 *dev)
84 static void one(struct rtrack2 *dev)
91 static int rt_setfreq(struct rtrack2 *dev, unsigned long freq)
95 mutex_lock(&dev->lock);
97 freq = freq / 200 + 856;
99 outb_p(0xc8, dev->io);
100 outb_p(0xc9, dev->io);
101 outb_p(0xc9, dev->io);
103 for (i = 0; i < 10; i++)
106 for (i = 14; i >= 0; i--)
112 outb_p(0xc8, dev->io);
116 mutex_unlock(&dev->lock);
120 static int vidioc_querycap(struct file *file, void *priv,
121 struct v4l2_capability *v)
123 strlcpy(v->driver, "radio-rtrack2", sizeof(v->driver));
124 strlcpy(v->card, "RadioTrack II", sizeof(v->card));
125 strlcpy(v->bus_info, "ISA", sizeof(v->bus_info));
126 v->version = RADIO_VERSION;
127 v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
131 static int vidioc_s_tuner(struct file *file, void *priv,
132 struct v4l2_tuner *v)
134 return v->index ? -EINVAL : 0;
137 static int rt_getsigstr(struct rtrack2 *dev)
141 mutex_lock(&dev->lock);
142 if (inb(dev->io) & 2) /* bit set = no signal present */
144 mutex_unlock(&dev->lock);
148 static int vidioc_g_tuner(struct file *file, void *priv,
149 struct v4l2_tuner *v)
151 struct rtrack2 *rt = video_drvdata(file);
156 strlcpy(v->name, "FM", sizeof(v->name));
157 v->type = V4L2_TUNER_RADIO;
158 v->rangelow = 88 * 16000;
159 v->rangehigh = 108 * 16000;
160 v->rxsubchans = V4L2_TUNER_SUB_MONO;
161 v->capability = V4L2_TUNER_CAP_LOW;
162 v->audmode = V4L2_TUNER_MODE_MONO;
163 v->signal = 0xFFFF * rt_getsigstr(rt);
167 static int vidioc_s_frequency(struct file *file, void *priv,
168 struct v4l2_frequency *f)
170 struct rtrack2 *rt = video_drvdata(file);
172 rt_setfreq(rt, f->frequency);
176 static int vidioc_g_frequency(struct file *file, void *priv,
177 struct v4l2_frequency *f)
179 struct rtrack2 *rt = video_drvdata(file);
181 f->type = V4L2_TUNER_RADIO;
182 f->frequency = rt->curfreq;
186 static int vidioc_queryctrl(struct file *file, void *priv,
187 struct v4l2_queryctrl *qc)
190 case V4L2_CID_AUDIO_MUTE:
191 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
192 case V4L2_CID_AUDIO_VOLUME:
193 return v4l2_ctrl_query_fill(qc, 0, 65535, 65535, 65535);
198 static int vidioc_g_ctrl(struct file *file, void *priv,
199 struct v4l2_control *ctrl)
201 struct rtrack2 *rt = video_drvdata(file);
204 case V4L2_CID_AUDIO_MUTE:
205 ctrl->value = rt->muted;
207 case V4L2_CID_AUDIO_VOLUME:
217 static int vidioc_s_ctrl(struct file *file, void *priv,
218 struct v4l2_control *ctrl)
220 struct rtrack2 *rt = video_drvdata(file);
223 case V4L2_CID_AUDIO_MUTE:
229 case V4L2_CID_AUDIO_VOLUME:
239 static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
245 static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
247 return i ? -EINVAL : 0;
250 static int vidioc_g_audio(struct file *file, void *priv,
251 struct v4l2_audio *a)
254 strlcpy(a->name, "Radio", sizeof(a->name));
255 a->capability = V4L2_AUDCAP_STEREO;
259 static int vidioc_s_audio(struct file *file, void *priv,
260 struct v4l2_audio *a)
262 return a->index ? -EINVAL : 0;
265 static int rtrack2_open(struct file *file)
270 static int rtrack2_release(struct file *file)
275 static const struct v4l2_file_operations rtrack2_fops = {
276 .owner = THIS_MODULE,
277 .open = rtrack2_open,
278 .release = rtrack2_release,
279 .ioctl = video_ioctl2,
282 static const struct v4l2_ioctl_ops rtrack2_ioctl_ops = {
283 .vidioc_querycap = vidioc_querycap,
284 .vidioc_g_tuner = vidioc_g_tuner,
285 .vidioc_s_tuner = vidioc_s_tuner,
286 .vidioc_g_frequency = vidioc_g_frequency,
287 .vidioc_s_frequency = vidioc_s_frequency,
288 .vidioc_queryctrl = vidioc_queryctrl,
289 .vidioc_g_ctrl = vidioc_g_ctrl,
290 .vidioc_s_ctrl = vidioc_s_ctrl,
291 .vidioc_g_audio = vidioc_g_audio,
292 .vidioc_s_audio = vidioc_s_audio,
293 .vidioc_g_input = vidioc_g_input,
294 .vidioc_s_input = vidioc_s_input,
297 static int __init rtrack2_init(void)
299 struct rtrack2 *dev = &rtrack2_card;
300 struct v4l2_device *v4l2_dev = &dev->v4l2_dev;
303 strlcpy(v4l2_dev->name, "rtrack2", sizeof(v4l2_dev->name));
306 v4l2_err(v4l2_dev, "You must set an I/O address with io=0x20c or io=0x30c\n");
309 if (!request_region(dev->io, 4, "rtrack2")) {
310 v4l2_err(v4l2_dev, "port 0x%x already in use\n", dev->io);
314 res = v4l2_device_register(NULL, v4l2_dev);
316 release_region(dev->io, 4);
317 v4l2_err(v4l2_dev, "Could not register v4l2_device\n");
321 strlcpy(dev->vdev.name, v4l2_dev->name, sizeof(dev->vdev.name));
322 dev->vdev.v4l2_dev = v4l2_dev;
323 dev->vdev.fops = &rtrack2_fops;
324 dev->vdev.ioctl_ops = &rtrack2_ioctl_ops;
325 dev->vdev.release = video_device_release_empty;
326 video_set_drvdata(&dev->vdev, dev);
328 mutex_init(&dev->lock);
329 if (video_register_device(&dev->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
330 v4l2_device_unregister(v4l2_dev);
331 release_region(dev->io, 4);
335 v4l2_info(v4l2_dev, "AIMSlab Radiotrack II card driver.\n");
337 /* mute card - prevents noisy bootups */
344 static void __exit rtrack2_exit(void)
346 struct rtrack2 *dev = &rtrack2_card;
348 video_unregister_device(&dev->vdev);
349 v4l2_device_unregister(&dev->v4l2_dev);
350 release_region(dev->io, 4);
353 module_init(rtrack2_init);
354 module_exit(rtrack2_exit);