1 /* zoltrix radio plus driver for Linux radio support
2 * (c) 1998 C. van Schaik <carl@leg.uct.ac.za>
5 * Due to the inconsistency in reading from the signal flags
6 * it is difficult to get an accurate tuned signal.
8 * It seems that the card is not linear to 0 volume. It cuts off
9 * at a low volume, and it is not possible (at least I have not found)
10 * to get fine volume control over the low volume range.
12 * Some code derived from code by Romolo Manfredini
15 * 1999-05-06 - (C. van Schaik)
16 * - Make signal strength and stereo scans
17 * kinder to cpu while in delay
18 * 1999-01-05 - (C. van Schaik)
19 * - Changed tuning to 1/160Mhz accuracy
20 * - Added stereo support
21 * (card defaults to stereo)
22 * (can explicitly force mono on the card)
23 * (can detect if station is in stereo)
24 * - Added unmute function
25 * - Reworked ioctl functions
26 * 2002-07-15 - Fix Stereo typo
29 #include <linux/module.h> /* Modules */
30 #include <linux/init.h> /* Initdata */
31 #include <linux/ioport.h> /* request_region */
32 #include <linux/delay.h> /* udelay, msleep */
33 #include <asm/io.h> /* outb, outb_p */
34 #include <asm/uaccess.h> /* copy to/from user */
35 #include <linux/videodev.h> /* kernel radio structs */
36 #include <media/v4l2-common.h>
37 #include <linux/config.h> /* CONFIG_RADIO_ZOLTRIX_PORT */
39 #ifndef CONFIG_RADIO_ZOLTRIX_PORT
40 #define CONFIG_RADIO_ZOLTRIX_PORT -1
43 static int io = CONFIG_RADIO_ZOLTRIX_PORT;
44 static int radio_nr = -1;
49 unsigned long curfreq;
55 static int zol_setvol(struct zol_device *dev, int vol)
61 mutex_lock(&dev->lock);
65 inb(io + 3); /* Zoltrix needs to be read to confirm */
66 mutex_unlock(&dev->lock);
70 outb(dev->curvol-1, io);
73 mutex_unlock(&dev->lock);
77 static void zol_mute(struct zol_device *dev)
80 mutex_lock(&dev->lock);
83 inb(io + 3); /* Zoltrix needs to be read to confirm */
84 mutex_unlock(&dev->lock);
87 static void zol_unmute(struct zol_device *dev)
90 zol_setvol(dev, dev->curvol);
93 static int zol_setfreq(struct zol_device *dev, unsigned long freq)
95 /* tunes the radio to the desired frequency */
96 unsigned long long bitmask, f, m;
97 unsigned int stereo = dev->stereo;
102 m = (freq / 160 - 8800) * 2;
103 f = (unsigned long long) m + 0x4d1c;
105 bitmask = 0xc480402c10080000ull;
108 mutex_lock(&dev->lock);
112 inb(io + 3); /* Zoltrix needs to be read to confirm */
117 bitmask = (bitmask ^ ((f & 0xff) << 47) ^ ((f & 0xff00) << 30) ^ ( stereo << 31));
119 if ((bitmask & 0x8000000000000000ull) != 0) {
136 /* termination sequence */
153 mutex_unlock(&dev->lock);
157 zol_setvol(dev, dev->curvol);
162 /* Get signal strength */
164 static int zol_getsigstr(struct zol_device *dev)
168 mutex_lock(&dev->lock);
169 outb(0x00, io); /* This stuff I found to do nothing */
170 outb(dev->curvol, io);
177 mutex_unlock(&dev->lock);
182 if ((a == 0xcf) || (a == 0xdf) /* I found this out by playing */
183 || (a == 0xef)) /* with a binary scanner on the card io */
188 static int zol_is_stereo (struct zol_device *dev)
192 mutex_lock(&dev->lock);
195 outb(dev->curvol, io);
202 mutex_unlock(&dev->lock);
204 if ((x1 == x2) && (x1 == 0xcf))
209 static int zol_do_ioctl(struct inode *inode, struct file *file,
210 unsigned int cmd, void *arg)
212 struct video_device *dev = video_devdata(file);
213 struct zol_device *zol = dev->priv;
218 struct video_capability *v = arg;
220 memset(v,0,sizeof(*v));
221 v->type = VID_TYPE_TUNER;
222 v->channels = 1 + zol->stereo;
224 strcpy(v->name, "Zoltrix Radio");
229 struct video_tuner *v = arg;
232 strcpy(v->name, "FM");
233 v->rangelow = (int) (88.0 * 16000);
234 v->rangehigh = (int) (108.0 * 16000);
235 v->flags = zol_is_stereo(zol)
236 ? VIDEO_TUNER_STEREO_ON : 0;
237 v->flags |= VIDEO_TUNER_LOW;
238 v->mode = VIDEO_MODE_AUTO;
239 v->signal = 0xFFFF * zol_getsigstr(zol);
244 struct video_tuner *v = arg;
247 /* Only 1 tuner so no setting needed ! */
252 unsigned long *freq = arg;
253 *freq = zol->curfreq;
258 unsigned long *freq = arg;
259 zol->curfreq = *freq;
260 zol_setfreq(zol, zol->curfreq);
265 struct video_audio *v = arg;
266 memset(v, 0, sizeof(*v));
267 v->flags |= VIDEO_AUDIO_MUTABLE | VIDEO_AUDIO_VOLUME;
268 v->mode |= zol_is_stereo(zol)
269 ? VIDEO_SOUND_STEREO : VIDEO_SOUND_MONO;
270 v->volume = zol->curvol * 4096;
272 strcpy(v->name, "Zoltrix Radio");
277 struct video_audio *v = arg;
281 if (v->flags & VIDEO_AUDIO_MUTE)
285 zol_setvol(zol, v->volume / 4096);
288 if (v->mode & VIDEO_SOUND_STEREO) {
290 zol_setfreq(zol, zol->curfreq);
292 if (v->mode & VIDEO_SOUND_MONO) {
294 zol_setfreq(zol, zol->curfreq);
303 static int zol_ioctl(struct inode *inode, struct file *file,
304 unsigned int cmd, unsigned long arg)
306 return video_usercopy(inode, file, cmd, arg, zol_do_ioctl);
309 static struct zol_device zoltrix_unit;
311 static struct file_operations zoltrix_fops =
313 .owner = THIS_MODULE,
314 .open = video_exclusive_open,
315 .release = video_exclusive_release,
317 .compat_ioctl = v4l_compat_ioctl32,
321 static struct video_device zoltrix_radio =
323 .owner = THIS_MODULE,
324 .name = "Zoltrix Radio Plus",
325 .type = VID_TYPE_TUNER,
326 .hardware = VID_HARDWARE_ZOLTRIX,
327 .fops = &zoltrix_fops,
330 static int __init zoltrix_init(void)
333 printk(KERN_ERR "You must set an I/O address with io=0x???\n");
336 if ((io != 0x20c) && (io != 0x30c)) {
337 printk(KERN_ERR "zoltrix: invalid port, try 0x20c or 0x30c\n");
341 zoltrix_radio.priv = &zoltrix_unit;
342 if (!request_region(io, 2, "zoltrix")) {
343 printk(KERN_ERR "zoltrix: port 0x%x already in use\n", io);
347 if (video_register_device(&zoltrix_radio, VFL_TYPE_RADIO, radio_nr) == -1)
349 release_region(io, 2);
352 printk(KERN_INFO "Zoltrix Radio Plus card driver.\n");
354 mutex_init(&zoltrix_unit.lock);
356 /* mute card - prevents noisy bootups */
358 /* this ensures that the volume is all the way down */
365 zoltrix_unit.curvol = 0;
366 zoltrix_unit.stereo = 1;
371 MODULE_AUTHOR("C.van Schaik");
372 MODULE_DESCRIPTION("A driver for the Zoltrix Radio Plus.");
373 MODULE_LICENSE("GPL");
375 module_param(io, int, 0);
376 MODULE_PARM_DESC(io, "I/O address of the Zoltrix Radio Plus (0x20c or 0x30c)");
377 module_param(radio_nr, int, 0);
379 static void __exit zoltrix_cleanup_module(void)
381 video_unregister_device(&zoltrix_radio);
382 release_region(io, 2);
385 module_init(zoltrix_init);
386 module_exit(zoltrix_cleanup_module);